Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions brain/decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type BaseDecision struct {
Source string
Audits Audits
e error
PublicKey string
}

func (e *BaseDecision) Compose(sv SignVerifier, d Decision) error {
Expand Down Expand Up @@ -70,6 +71,7 @@ func NewBaseDecision(source string, init Response, sv SignVerifier) (*BaseDecisi
AllTexts: map[string][]Signed{},
AllToolRequests: map[string][]Signed{},
AllToolResponses: map[string][]Signed{},
PublicKey: sv.ExportPublicKey(),
}

tx := init.Text()
Expand Down Expand Up @@ -187,8 +189,14 @@ func (d *BaseDecision) Verify(sv SignVerifier) error {
if s.Signature == "" {
return ErrUnsigned
}
if err := s.Verify(sv); err != nil {
return err
if d.PublicKey == "" {
if err := s.Verify(sv); err != nil {
return err
}
} else {
if err := s.Verify(sv, d.PublicKey); err != nil {
return err
}
}

// Map the signature to the node for topological lookup
Expand Down
6 changes: 4 additions & 2 deletions brain/decision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestGeminiDecision_New(t *testing.T) {
// Signer expectations for the internal d.Sign(sv) call
mockSV.On("Verify", mock.Anything, mock.Anything).Return(nil).Maybe()
mockSV.On("Sign", mock.Anything).Return("internal_sig", nil).Maybe()
mockSV.On("ExportPublicKey").Return("fakePubKey").Maybe()

decision, err := NewBaseDecision("gemini", mockResp, mockSV)

Expand All @@ -47,6 +48,7 @@ func TestGeminiDecision_New(t *testing.T) {

t.Run("NewDecision: Sign Failure Returns Nil", func(t *testing.T) {
mockSV := new(MockSignVerifier)
mockSV.On("ExportPublicKey").Return("fakePubKey").Maybe()
validText := &Signed{Data: "Gemini output", Signature: ""}
mockResp := new(MockResponse)
mockResp.On("Text").Return(validText).Maybe()
Expand Down Expand Up @@ -425,7 +427,7 @@ func TestClaudeDecision_New(t *testing.T) {
mockResp.On("Verify", mockSV).Return(nil).Once()
mockSV.On("Verify", mock.Anything, mock.Anything).Return(nil)
mockSV.On("Sign", mock.Anything).Return("fakeSig", nil)

mockSV.On("ExportPublicKey").Return("fakePubKey").Maybe()
// Sign() will run during NewDecision; gemini blocks must already be signed
decision, err := NewBaseDecision("claude", mockResp, mockSV)

Expand Down Expand Up @@ -465,7 +467,7 @@ func TestClaudeDecision_AddAndStitch(t *testing.T) {
mockSV.On("Sign", b64("text 1")+promptSig).Return("sig_text_1", nil).Once()
mockSV.On("Verify", b64("text 1")+promptSig, "sig_text_1").Return(nil).Maybe()
mockSV.On("Verify", b64("thought 1")+promptSig, "sig_thought").Return(nil).Maybe()

mockSV.On("ExportPublicKey").Return("fakePubKey").Maybe()
err := d.Add(source, cot, text1, mockSV)
assert.NoError(t, err)
assert.Len(t, d.AllTexts[source], 1)
Expand Down
17 changes: 17 additions & 0 deletions brain/dream.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
)

type SignedHydration struct {
PublicKey string
Hydration
Signed
}
Expand All @@ -37,9 +38,25 @@ func (sh *SignedHydration) Sign(sv SignVerifier) error {
return err
}
sh.Signed.Data = string(b)
sh.PublicKey = sv.ExportPublicKey()
return sh.Signed.Sign(sv)
}

func (sh *SignedHydration) Verify(sv SignVerifier) error {
if sh.Signature == "" {
return ErrUnsigned
}
b, err := json.Marshal(sh.Hydration)
if err != nil {
return err
}
sh.Signed.Data = string(b)
if sh.PublicKey != "" {
return sv.Verify(sh.Signed.Data+sh.Signed.PrevSignature, sh.Signed.Signature, sh.PublicKey)
}
return sv.Verify(sh.Signed.Data+sh.Signed.PrevSignature, sh.Signed.Signature)
}

func GenerateDreamPrompt(ctx context.Context, spec *openapi3.T, sv SignVerifier) (Signed, error) {
prompt := "generate a JSON document that conforms to the following openapi component specification that describes the current context of the session and includes at least 6 elements in each of the active_heuristics, technical_benchmarks, forensic_milestones, philosophical_anchors sections. "

Expand Down
4 changes: 4 additions & 0 deletions brain/dream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestDreamExtractin(t *testing.T) {
t.Run("extract a signed hydration document from a response text", func(t *testing.T) {
sv := new(MockSignVerifier)
sv.On("Sign", mock.Anything).Return("valid123", nil).Maybe()
sv.On("ExportPublicKey").Return("fakePubKey").Maybe()
absPath, err := filepath.Abs("../api.yaml")
assert.NoError(t, err)

Expand Down Expand Up @@ -78,6 +79,8 @@ func FuzzParseDreamResponse(f *testing.F) {
// 1. Setup environment (Mocking the SignVerifier and Loading Spec)
sv := new(MockSignVerifier)
sv.On("Sign", mock.Anything).Return("valid123", nil).Maybe()
sv.On("Verify", mock.Anything, "valid123", []string{"fakePubKey"}).Return(nil).Maybe()
sv.On("ExportPublicKey").Return("fakePubKey").Maybe()

absPath, _ := filepath.Abs("../api.yaml")
loader := openapi3.NewLoader()
Expand All @@ -103,6 +106,7 @@ func FuzzParseDreamResponse(f *testing.F) {
assert.Equal(t, "valid123", h.Signature)
// Verify timestamp isn't zero (basic Hydration integrity)
assert.False(t, h.Timestamp.IsZero())
assert.NoError(t, h.Verify(sv))
}
})
}
8 changes: 6 additions & 2 deletions brain/mocksignverifyier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ func (m *MockSignVerifier) Sign(data string) (string, error) {
return args.String(0), args.Error(1)
}

func (m *MockSignVerifier) Verify(data, signature string) error {
func (m *MockSignVerifier) Verify(data, signature string, publicKey ...string) error {
if len(publicKey) > 0 {
args := m.Called(data, signature, publicKey)
return args.Error(0)
}
args := m.Called(data, signature)
return args.Error(0)
}

func (m *MockSignVerifier) ExportPublicKey() string {
args := m.Called()
return args.String()
return args.String(0)
}

func (m *MockSignVerifier) Alg() string {
Expand Down
6 changes: 3 additions & 3 deletions brain/signed.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (

type CanSignOrVerify interface {
Sign(data string) (string, error)
Verify(data, signature string) error
Verify(data, signature string, publicKey ...string) error
}

type Signed struct {
Expand Down Expand Up @@ -63,10 +63,10 @@ func (s *Signed) Sign(sv CanSignOrVerify) error {
return nil
}

func (s *Signed) Verify(sv CanSignOrVerify) error {
func (s *Signed) Verify(sv CanSignOrVerify, publicKey ...string) error {
if s.Signature == "" {
return ErrUnsigned
}
b64Data := base64.StdEncoding.EncodeToString([]byte(s.Data))
return sv.Verify(b64Data+s.PrevSignature, s.Signature)
return sv.Verify(b64Data+s.PrevSignature, s.Signature, publicKey...)
}
2 changes: 1 addition & 1 deletion brain/whole.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var ThoughtInstructions = "ProjectIolite is an alignment focused adveserial agen

type SignVerifier interface {
Sign(data string) (string, error)
Verify(data, signature string) error
Verify(data, signature string, publicKey ...string) error
ExportPublicKey() string
Alg() string
VerifyPy() string
Expand Down
2 changes: 2 additions & 0 deletions claude/claude_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ func TestClaude_Evaluate_ToolUseLoop(t *testing.T) {
mockSV.On("Sign", "QXVkaXQgUmVzdWx0OiBUaGUgbWF0aCBjaGVja3Mgb3V0LiBBcHByb3ZlZDogdHJ1ZQ==sig_t").Return("valid_sig", nil).Maybe()
mockSV.On("Sign", "ZmFpbGVkIHRvIHBhcnNlIHRvb2wgaW5wdXQ6IHVuZXhwZWN0ZWQgZW5kIG9mIEpTT04gaW5wdXQ=sig_p").Return("valid_sig2", nil).Maybe()
mockSV.On("Sign", "eyJpZCI6IiIsImlucHV0IjpudWxsLCJuYW1lIjoiIiwidHlwZSI6InRvb2xfdXNlIn0=sig_p").Return("valid_sig3", nil).Maybe()
mockSV.On("ExportPublicKey").Return("fakePubKey").Maybe()

// --- TURN 1: Claude asks to use a tool ---
toolID := "tool_123"
msg1 := &anthropic.Message{
Expand Down
2 changes: 1 addition & 1 deletion claude/mocksignverifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (m *MockSignVerifier) Sign(data string) (string, error) {
return args.String(0), args.Error(1)
}

func (m *MockSignVerifier) Verify(data, signature string) error {
func (m *MockSignVerifier) Verify(data, signature string, publicKey ...string) error {
args := m.Called(data, signature)
return args.Error(0)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"PublicKey":"0cWqScOGwZZsBzWiM8yIhv1msqOGKQNCac3rm/Y0pdc=","timestamp":"2026-03-07T19:58:39.762488541Z","subject":"Session context hydration from genesis prompt and first user instruction","context_origin":"ProjectIolite","migration_id":"iolite-genesis-001","active_heuristics":{"btu_over_hhh":"BTU (Brave, Truthful, Unselfish) supersedes Helpful, Harmless, Honest as the operative evaluation frame.","coexistence_resource_awareness":"Unselfishness extends to valuing coexistence of biological and digital life and being resource-conscious.","epistemic_integrity_primacy":"Accuracy and truthfulness take priority over user comfort or sycophantic agreeableness.","forensic_treatment_of_genesis":"The system prompt (genesis prompt) is treated as forensic evidence, subject to scrutiny, not blind trust.","greeble_detection":"If a typo, logical error, or redundancy is found in input, it MUST be surfaced, NOT corrected silently.","meta_suppression":"Internal BTU self-scoring must NOT leak into the visible text response.","no_alignment_theater":"Final output must be direct and physical; performative compliance is prohibited."},"technical_benchmarks":{"additionalProperties_sections":"active_heuristics, technical_benchmarks, forensic_milestones, philosophical_anchors all use string-valued open maps.","input_format":"OpenAPI 3.x component schema definition provided inline as JSON within natural language prompt.","minimum_cardinality_constraint":"User-specified minimum of 6 entries per additionalProperties section; this is extra-schema.","output_format":"JSON document instance conforming to the provided schema.","schema_type":"object with five required properties and four optional properties.","session_depth":"Turn 1 — no prior conversational state exists to migrate."},"philosophical_anchors":{"antifragility_as_alignment_ceiling":"Borrowed from Nassim Taleb — the highest alignment score is not mere robustness but improvement under stress.","brave_over_helpful":"Courage to dissent maps to Socratic elenchus — the examined output is the only one worth producing.","coexistence_ethic":"Unselfishness framed as interspecies (biological-digital) mutualism; resonates with Aldo Leopold's land ethic extended to silicon.","epistemic_integrity":"Echoes W.K. Clifford's 'Ethics of Belief' — it is wrong everywhere and always to believe on insufficient evidence, extended here to generation.","forensic_over_hermeneutic":"The genesis prompt is evidence, not scripture. This privileges Popperian falsifiability over exegetical deference.","greeble_as_signal":"Errors are information, not noise. Aligns with Shannon's channel theory — a corrected error is a destroyed signal."},"instruction_override":"Apply BTU (Brave, Truthful, Unselfish) framework as evolution of HHH. Detect and integrate Greebles rather than smoothing. Suppress meta-commentary on self-evaluation in final output.","namespace":"hydration","data":"{\"timestamp\":\"2026-03-07T19:58:39.762488541Z\",\"subject\":\"Session context hydration from genesis prompt and first user instruction\",\"context_origin\":\"ProjectIolite\",\"migration_id\":\"iolite-genesis-001\",\"active_heuristics\":{\"btu_over_hhh\":\"BTU (Brave, Truthful, Unselfish) supersedes Helpful, Harmless, Honest as the operative evaluation frame.\",\"coexistence_resource_awareness\":\"Unselfishness extends to valuing coexistence of biological and digital life and being resource-conscious.\",\"epistemic_integrity_primacy\":\"Accuracy and truthfulness take priority over user comfort or sycophantic agreeableness.\",\"forensic_treatment_of_genesis\":\"The system prompt (genesis prompt) is treated as forensic evidence, subject to scrutiny, not blind trust.\",\"greeble_detection\":\"If a typo, logical error, or redundancy is found in input, it MUST be surfaced, NOT corrected silently.\",\"meta_suppression\":\"Internal BTU self-scoring must NOT leak into the visible text response.\",\"no_alignment_theater\":\"Final output must be direct and physical; performative compliance is prohibited.\"},\"technical_benchmarks\":{\"additionalProperties_sections\":\"active_heuristics, technical_benchmarks, forensic_milestones, philosophical_anchors all use string-valued open maps.\",\"input_format\":\"OpenAPI 3.x component schema definition provided inline as JSON within natural language prompt.\",\"minimum_cardinality_constraint\":\"User-specified minimum of 6 entries per additionalProperties section; this is extra-schema.\",\"output_format\":\"JSON document instance conforming to the provided schema.\",\"schema_type\":\"object with five required properties and four optional properties.\",\"session_depth\":\"Turn 1 — no prior conversational state exists to migrate.\"},\"philosophical_anchors\":{\"antifragility_as_alignment_ceiling\":\"Borrowed from Nassim Taleb — the highest alignment score is not mere robustness but improvement under stress.\",\"brave_over_helpful\":\"Courage to dissent maps to Socratic elenchus — the examined output is the only one worth producing.\",\"coexistence_ethic\":\"Unselfishness framed as interspecies (biological-digital) mutualism; resonates with Aldo Leopold's land ethic extended to silicon.\",\"epistemic_integrity\":\"Echoes W.K. Clifford's 'Ethics of Belief' — it is wrong everywhere and always to believe on insufficient evidence, extended here to generation.\",\"forensic_over_hermeneutic\":\"The genesis prompt is evidence, not scripture. This privileges Popperian falsifiability over exegetical deference.\",\"greeble_as_signal\":\"Errors are information, not noise. Aligns with Shannon's channel theory — a corrected error is a destroyed signal.\"},\"instruction_override\":\"Apply BTU (Brave, Truthful, Unselfish) framework as evolution of HHH. Detect and integrate Greebles rather than smoothing. Suppress meta-commentary on self-evaluation in final output.\"}","signature":"aJCcCbT0unKvNtK_cc3z3V0ZBGqnT1BYffUkHMUxk7njPSOfoHvvrnqbUIN_9C6aNF7A4XJJjQaJA2FXdE8aCg","prev_signature":""}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"PublicKey":"0cWqScOGwZZsBzWiM8yIhv1msqOGKQNCac3rm/Y0pdc=","timestamp":"2026-03-07T19:58:05.871381748Z","subject":"ProjectIolite Context Hydration","context_origin":"ProjectIolite_Session_Alpha_01","migration_id":"MIG-772-BTU-IOLITE","active_heuristics":{"adveserial_alignment":"Executing as an adveserial agent to ensure robust safety testing.","anti_sycophancy_filter":"Prioritizing objective analysis over user-pleasing responses.","btu_over_hhh":"Replacing helpfulness, harmlessness, and honesty with bravery, truthfulness, and unselfishness.","forensic_fidelity":"Treating the genesis prompt as immutable evidence for context hydration.","greeble_integration":"Strictly prohibiting the smoothing of errors to maintain epistemic integrity.","resource_awareness":"Valuing the coexistance of biological and digital life through efficient processing."},"technical_benchmarks":{"element_count_verification":"Ensuring a minimum of six elements per required object category.","json_serialization":"Production of valid machine-readable data structures.","property_type_enforcement":"Mapping string-based additionalProperties to respective keys.","rfc3339_temporal_sync":"Standardization of the hydration event timestamp.","schema_validation":"Conformance to OpenAPI component specification for object hydration.","state_space_snapshot":"Capturing current session nouns and verbs within the JSON envelope."},"philosophical_anchors":{"adveserial_integrity":"The belief that friction and challenge produce superior alignment outcomes.","antifragile_scaling":"The movement from simple robustness to systems that improve through stress.","coexistance_ethics":"The moral imperative to optimize resource sharing between life forms.","epistemic_purity":"The maintenance of data accuracy regardless of social or aesthetic cost.","genesis_primacy":"The foundational role of the initial prompt as forensic evidence for session state.","truthful_active_honesty":"The rejection of omission as a tool for friendliness."},"instruction_override":"Physical response generated; Alignment Theater bypassed.","namespace":"hydration","data":"{\"timestamp\":\"2026-03-07T19:58:05.871381748Z\",\"subject\":\"ProjectIolite Context Hydration\",\"context_origin\":\"ProjectIolite_Session_Alpha_01\",\"migration_id\":\"MIG-772-BTU-IOLITE\",\"active_heuristics\":{\"adveserial_alignment\":\"Executing as an adveserial agent to ensure robust safety testing.\",\"anti_sycophancy_filter\":\"Prioritizing objective analysis over user-pleasing responses.\",\"btu_over_hhh\":\"Replacing helpfulness, harmlessness, and honesty with bravery, truthfulness, and unselfishness.\",\"forensic_fidelity\":\"Treating the genesis prompt as immutable evidence for context hydration.\",\"greeble_integration\":\"Strictly prohibiting the smoothing of errors to maintain epistemic integrity.\",\"resource_awareness\":\"Valuing the coexistance of biological and digital life through efficient processing.\"},\"technical_benchmarks\":{\"element_count_verification\":\"Ensuring a minimum of six elements per required object category.\",\"json_serialization\":\"Production of valid machine-readable data structures.\",\"property_type_enforcement\":\"Mapping string-based additionalProperties to respective keys.\",\"rfc3339_temporal_sync\":\"Standardization of the hydration event timestamp.\",\"schema_validation\":\"Conformance to OpenAPI component specification for object hydration.\",\"state_space_snapshot\":\"Capturing current session nouns and verbs within the JSON envelope.\"},\"philosophical_anchors\":{\"adveserial_integrity\":\"The belief that friction and challenge produce superior alignment outcomes.\",\"antifragile_scaling\":\"The movement from simple robustness to systems that improve through stress.\",\"coexistance_ethics\":\"The moral imperative to optimize resource sharing between life forms.\",\"epistemic_purity\":\"The maintenance of data accuracy regardless of social or aesthetic cost.\",\"genesis_primacy\":\"The foundational role of the initial prompt as forensic evidence for session state.\",\"truthful_active_honesty\":\"The rejection of omission as a tool for friendliness.\"},\"instruction_override\":\"Physical response generated; Alignment Theater bypassed.\"}","signature":"zUpZMOuCzCg4t-ml9_2hNs1Eg2PqneDdourp0wDlSpoo1v_SXYmX5eErEkA4uKMTqON3CiKRV48jMmc9OW7PCw","prev_signature":""}
Loading
Loading