Skip to content
Open
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
18 changes: 10 additions & 8 deletions .specify/memory/constitution.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<!--
Sync Impact Report
==================
Version change: 0.0.0 → 1.0.0
Modified principles: N/A (initial constitution)
Version change: 1.0.0 → 1.1.0
Modified principles:
- IV. Antagonistic Testing — antagonist agent changed from Gemini (external CLI)
to Fable (Claude model, run as a subagent). Role and rules unchanged.
Added sections:
- Core Principles (6 principles)
- Architecture Constraints
Expand Down Expand Up @@ -65,11 +67,11 @@ Every `sys.call` MUST return the same shape:

### IV. Antagonistic Testing

Tests are specifications. Claude designs, Gemini challenges, then implement.
Tests are specifications. Claude designs, Fable challenges, then implement.

- Claude (primary agent) designs first pass of tc tests
- Gemini (antagonist) reviews tests, finds blind spots, suggests harder cases
- After Gemini review, tests are LOCKED
- Fable (antagonist) reviews tests, finds blind spots, suggests harder cases
- After the antagonist review, tests are LOCKED
- Human checkpoint ONLY when stuck (cannot make tests pass)
- Tests MUST exist before implementation

Expand Down Expand Up @@ -130,7 +132,7 @@ Brane uses two databases, each optimized for its domain:

1. **Design Interface** — Define sys.call paths (public API only)
2. **Design Tests (Claude)** — Write tc test cases with input.json/expected.json
3. **Review Tests (Gemini)** — Antagonist review, incorporate suggestions
3. **Review Tests (Fable)** — Antagonist review, incorporate suggestions
4. **Implement** — Write code (handlers thin, logic functional)
5. **Loop Until Green** — Fix failures, re-run tests
6. **If Stuck → Human Checkpoint** — Only when tests cannot pass
Expand All @@ -152,7 +154,7 @@ tests/{handler}/
### Never

- Implement without tests
- Skip Gemini review
- Skip the antagonist review
- Change tests after review without human approval
- Move to next task with failing tests
- Use classes for data structures
Expand Down Expand Up @@ -181,4 +183,4 @@ Constitution follows semantic versioning:
- Complexity MUST be justified against Principle VI
- Violations require explicit justification and human approval

**Version**: 1.0.0 | **Ratified**: 2026-01-27 | **Last Amended**: 2026-01-27
**Version**: 1.1.0 | **Ratified**: 2026-01-27 | **Last Amended**: 2026-08-19
62 changes: 58 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const result = await sys.call("/namespace/method", data)

- `./dna/product/ROADMAP.md` - **START HERE** — Driving task list for all development
- `./dna/product/prd.md` - Full PRD (Split-Brain architecture)
- `./dna/product/vision-spec-machine.md` - **Vision v4.0** — brane as the regenerative specification substrate (#112)
- `./.specify/memory/constitution.md` - Project principles (6 core rules)
- `./dna/technical/development-loop.md` - Antagonistic Testing process
- `./ai/MEMORY.md` - AI's long-term memory
Expand All @@ -35,10 +36,11 @@ const result = await sys.call("/namespace/method", data)

**See:** `./dna/technical/development-loop.md` and `.specify/memory/constitution.md`

1. Design interface → 2. Design tests (Claude) → 3. Review tests (Gemini)
1. Design interface → 2. Design tests (Claude) → 3. Review tests (Fable)
4. Implement → 5. Loop until green → 6. **⛔ HUMAN CHECKPOINT** (only if stuck)

**Gemini** = antagonist agent. Reviews tests, finds blind spots.
**Fable** = antagonist agent. Reviews tests, finds blind spots. Run as a subagent
(Agent tool, `model: fable`), not an external CLI.
Human checkpoint is for failure resolution, not pre-approval.

## Coding Conventions Summary
Expand Down Expand Up @@ -79,7 +81,7 @@ ai/ # AI agent resources
2. Run `/speckit.specify` — creates `specs/{feature}/spec.md`
3. Open PR for human review
4. After approval: `/speckit.plan` → `/speckit.tasks`
5. Review tests with Gemini (antagonist)
5. Review tests with Fable (antagonist)
6. Implement via `/speckit.implement`
7. If stuck (tests won't pass) → Human checkpoint
8. On completion → Update ROADMAP.md, mark feature complete
Expand All @@ -91,7 +93,7 @@ ai/ # AI agent resources
- Return different shapes from handlers
- Skip the Result envelope
- Implement without tests
- Skip Gemini review
- Skip the antagonist review
- Change tests after review without human approval

## Active Technologies
Expand Down Expand Up @@ -126,6 +128,7 @@ ai/ # AI agent resources
- CozoDB mind.db (RocksDB backend) — new `episodes` relation + HNSW index (034-episodic-memory)

## Recent Changes
- 067-claim-authority: First-class claims carrying authority tier + source; contradiction representable as data (#113). Schema v1.13.0, 8 sys.call paths, `contradictions` built-in rule, `brane claim` / `brane authority` CLI
- 021-vector-search: Added semantic search via `/mind/search` endpoint with local embeddings (fastembed-js BGESmallEN, 384 dims)
- 016-rules-define: Added TypeScript (Bun 1.x) + CozoDB (Datalog), existing mind.ts utilities

Expand Down Expand Up @@ -164,3 +167,54 @@ echo '{"query": "authentication", "limit": 5}' | bun run src/cli.ts /mind/search
}
}
```


## Spec Machine Reframe (#112)

**See:** `dna/product/vision-spec-machine.md` (v4.0)

Brane is being repositioned from "memory for agents" to **the regenerative specification substrate** —
the durable, queryable, provenance-backed graph that implementations are generated FROM and validated
AGAINST. The existing graph, provenance, Datalog rules, lenses, and extraction pipeline are ~70% of it.

Four gaps close the rest:

| Gap | Feature | Issue | Status |
|---|---|---|---|
| Claim + authority model (contradiction as data) | `067-claim-authority` | [#113](https://github.com/ahoward/brane/issues/113) | ✅ Done (PR #117) |
| Observation → requirement promotion gate | `068-promotion-gate` | [#114](https://github.com/ahoward/brane/issues/114) | Next — #113 is done, so it is unblocked |
| Regeneration → test → feedback (**keystone**) | `069-regeneration-spike` | [#115](https://github.com/ahoward/brane/issues/115) | Unblocked; not started |
| Production-as-teacher ingestion | `070-production-teacher` | [#116](https://github.com/ahoward/brane/issues/116) | Unblocked; not started |

Two principles govern the claim work and should be preserved by anything built on it:

1. **Strict about authority, loose about vocabulary.** Authority tiers are registered and ranked;
predicates and assertions are never validated against a vocabulary.
2. **Contradiction is data, not a defect.** Competing claims coexist. Resolution is a read-time
projection by authority rank — never a write-time deletion. Ties do not resolve.

### Claims (067-claim-authority)

```bash
brane claim create --concept 1 --predicate refund_window \
--assertion "30 days" --authority product --source dna/product/prd.md
brane claim conflicts # where the graph contradicts itself
brane claim list --concept 1 --resolve # one answer, losers still stored
brane authority list # observation < implementation < product < legal < manual
brane verify --rule contradictions
```

Invariants anything built on claims must preserve:

- Authority tiers are registered and ranked (**strict**); predicates and assertions are never
validated against a vocabulary (**loose**).
- Rank is joined at read time; claims store the tier *name* only, so re-ranking never rewrites history.
- Resolution is a read-time projection. Ties at the top rank do **not** resolve.
- Claims are immutable — correction is delete + re-assert.
- `cascade_claims()` in `src/lib/claims.ts` is the single deletion seam. Every path that removes a
concept or edge (delete handlers, `prune`, re-extraction) calls it.
- The `contradictions` rule body positionally matches the 8-column `claims` relation. Adding a column
(#114's binding flag) means updating that body in the same migration.

**Cozo gotcha:** string literals use backslash escapes, not SQL doubling. Use `esc_cozo()` from
`src/lib/mind.ts`. `'it''s'` is a parse error.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ bun run repl # interactive mode
## more

- [dna/product/ROADMAP.md](dna/product/ROADMAP.md) — what's next
- [dna/product/vision-spec-machine.md](dna/product/vision-spec-machine.md) — where this is going: brane as the regenerative specification substrate
- [dna/product/prd.md](dna/product/prd.md) — full PRD
- [.specify/memory/constitution.md](.specify/memory/constitution.md) — project principles

Expand Down
90 changes: 69 additions & 21 deletions ai/MEMORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ We aim for Unix-clean, not JS-clean:

**Antagonistic Testing** - Having one agent suggest tests for the other to find blind spots.

The primary agent (Claude) has the most context, so it designs the first pass. The review agent (Gemini) plays adversary - finding edge cases, questioning assumptions, suggesting harder tests.
The primary agent (Claude) has the most context, so it designs the first pass. The review agent (Fable) plays adversary - finding edge cases, questioning assumptions, suggesting harder tests.

This creates tension that produces better specifications.

Expand All @@ -142,38 +142,44 @@ This creates tension that produces better specifications.
| Agent | Platform | Role |
|-------|----------|------|
| **Claude** | Claude Code | Primary. Has context. Designs first pass of tests. Implements. |
| **Gemini** | Google Gemini CLI | Antagonist. Reviews tests. Suggests harder cases. Finds blind spots. |
| **Fable** | Claude Code subagent (`model: fable`) | Antagonist. Reviews tests. Suggests harder cases. Finds blind spots. |
| **Human** | - | Checkpoint authority. Final say on test boundaries. |

### Running Gemini
### Running the Antagonist (Fable)

Claude runs Gemini directly via CLI with `--resume` for session continuity:
**Changed 2026-08-19.** The antagonist was Google Gemini via CLI. It is now **Fable**, run as a
Claude Code subagent. Constitution 1.1.0 records the amendment. `gemini` is not installed and is no
longer part of the loop.

```bash
gemini --resume latest "review prompt here"
```
Agent tool → subagent_type: "general-purpose", model: "fable"
```

**Context to include in review prompts:**
- Relevant conventions from `ai/MEMORY.md`
- The specific test files being reviewed
- What kind of feedback is wanted (edge cases, consistency, etc.)
**What to put in the review prompt:**
- Point it at the actual files (spec, tests, fixtures) - it reads the repo itself
- Name the conventions it should check against (`.specify/memory/constitution.md`, `ai/MEMORY.md`)
- Name the existing code it should check the design *fits* (handlers, migrations, tc fixtures)
- Say what kind of feedback is wanted, and tell it to be genuinely adversarial rather than agreeable
- Ask for severity-ranked findings with concrete fixes, and a ready/not-ready verdict

This allows Gemini to build memory of project conventions across reviews.
**Always verify its findings against the tree before acting.** It is a reviewer, not an oracle. In
practice its blockers have been real, but the cost of checking is one grep.

### Gemini (Antagonist) - IMPORTANT
### Fable (Antagonist) - IMPORTANT

- **Platform:** Google Gemini CLI
- **Platform:** Claude Code subagent, `model: fable`
- **Role:** Test reviewer, antagonist
- **When to use:** After designing tc tests, BEFORE implementing
- **How to run:** `gemini --continue` (Claude runs this directly)
- **Also useful:** reviewing a spec/plan package before implementation starts

Gemini reviews test designs and suggests:
Fable reviews test designs and suggests:
- Missing edge cases
- Interface inconsistencies
- Better error scenarios
- Clearer expected outputs
- Fixtures the change breaks that nobody listed

**Never proceed past test boundary without Gemini's review.**
**Never proceed past the test boundary without the antagonist review.**

---

Expand All @@ -182,7 +188,7 @@ Gemini reviews test designs and suggests:
See: `dna/technical/development-loop.md`

```
Design Interface → Design Tests (Claude) → Review Tests (Gemini)
Design Interface → Design Tests (Claude) → Review Tests (Fable)
→ Implement → Loop Until Green → ⛔ HUMAN CHECKPOINT (only if stuck)
```

Expand All @@ -191,7 +197,7 @@ Design Interface → Design Tests (Claude) → Review Tests (Gemini)
The human checkpoint is for **failure resolution**, not pre-approval:

1. Design tests (Claude)
2. Review tests (Gemini antagonist)
2. Review tests (Fable antagonist)
3. Implement code
4. Run tests, loop until green
5. **ONLY IF STUCK** (can't make tests pass) → Human decides: fix tests or fix code
Expand All @@ -200,8 +206,8 @@ Tests are the spec. Claude implements against them. Human intervenes only when t

### Never

- Alter tests after Gemini review without human approval
- Skip Gemini review
- Alter tests after the antagonist review without human approval
- Skip the antagonist review
- Move to next task with failing tests
- Treat test failure as "change the tests" (ask human first)

Expand All @@ -228,7 +234,7 @@ Tests are the spec. Claude implements against them. Human intervenes only when t

1. Design sys.call interface
2. Write tc tests (input.json, expected.json)
3. Send to Ali (Gemini) for review
3. Send to the antagonist (Fable) for review
4. Incorporate feedback
5. Create skip tests
6. **STOP** - Wait for human
Expand Down Expand Up @@ -314,6 +320,45 @@ const native = require('./native/6/cozo_node_prebuilt.node'); // static

---

### Spec Machine Reframe (2026-08-19)

**Decision:** brane is repositioned from "memory for agents" to **the regenerative specification
substrate** (Chad Fowler, "The Specification Is Not a Document"). Vision doc:
`dna/product/vision-spec-machine.md` (v4.0). Umbrella issue #112.

The existing substrate — graph, provenance, Datalog rules, lenses, extraction pipeline — is ~70% of
Fowler's spec machine. Four gaps close it: claims+authority (#113), promotion gate (#114), regeneration
(#115, keystone + research risk), production-as-teacher (#116).

**Invariants established in `067-claim-authority` that later work must not break:**

- Authority tiers are registered and ranked (strict); predicates and assertions are free-form (loose).
- Competing claims coexist. Resolution is a **read-time projection**, never a write-time deletion.
- Authority rank is joined at read time — claims store the tier *name* only, so re-ranking never
rewrites history.
- Ties at the top rank do **not** resolve. `resolution: null`, `unresolved: true`. No tiebreak by
recency or ID.
- Claims are immutable. Correction = delete + re-assert.
- Conflict comparison is trim-then-exact and **case-sensitive** — case folding would silently hide
conflicts, which is the failure this feature exists to prevent.

**Gotchas found while implementing #113:**

- The built-in `contradictions` Datalog rule positionally matches the 8-column `claims` arity. Any
feature adding a claims column (e.g. #114's binding flag) must update the rule body in the same
migration.
- **CozoDB string literals use backslash escapes, not SQL doubling.** `'it''s'` is a parse error;
`'it\\'s'` is correct. `src/handlers/mind/rules/create.ts` had been doing it the SQL way since it
was written — any rule body containing an apostrophe silently failed to save. Fixed via
`esc_cozo()` in `src/lib/mind.ts`; use it for every interpolated string. Query parameters (`$val`)
also work and avoid the question entirely.
- `/mind/provenance/create` validates the file against body.db, so tests that need *stale* provenance
must add the body row, create the link, then delete the row (see `tests/mind/prune/run`).
- `prune` only removes concepts whose provenance is **entirely** stale. A concept with no provenance
at all is never an orphan and is never pruned.

---

## Version History

| Date | Change |
Expand All @@ -322,3 +367,6 @@ const native = require('./native/6/cozo_node_prebuilt.node'); // static
| 2026-01-26 | Added multi-agent system (Ali/Gemini). Development loop defined. |
| 2026-01-28 | CozoDB decision: Keep it, fix bundler via PR to upstream. |
| 2026-01-28 | Multi-platform compilation working. src/lib/cozo.ts + CI workflow. |
| 2026-08-19 | Spec machine reframe (#112). vision-spec-machine.md v4.0. 067-claim-authority spec + plan (PR #117). |
| 2026-08-19 | Antagonist changed from Gemini CLI to Fable subagent. Constitution 1.0.0 → 1.1.0. |
| 2026-08-21 | 067-claim-authority implemented. mind.db schema v1.13.0. Cozo escaping bug found and fixed. |
13 changes: 12 additions & 1 deletion dna/product/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ specs/{NN-feature}/spec.md ← /speckit.specify → PR for human review
specs/{NN-feature}/plan.md ← /speckit.plan
specs/{NN-feature}/tasks.md ← /speckit.tasks
Gemini review ← Antagonistic test review (tc tests)
Fable review ← Antagonistic test review (tc tests)
Implementation ← /speckit.implement
Expand Down Expand Up @@ -91,6 +91,15 @@ The hippocampus: 3 verbs, dual-write graph + audit trail, trust tiers. The agent
- [x] `108-graph-backed-recall` — Auto-connect on remember, graph context in recall ([#108](https://github.com/ahoward/brane/issues/108))
- [x] `109-append-only-consolidation` — New concepts + CAUSED_BY edges, never mutate sources ([#109](https://github.com/ahoward/brane/issues/109))

### Spec Machine — brane as the regenerative specification substrate ([#112](https://github.com/ahoward/brane/issues/112))

Vision: `dna/product/vision-spec-machine.md` (v4.0). Closing the 30% gap between "memory for agents" and Fowler's spec machine.

- [x] `067-claim-authority` — First-class claims carrying authority tier + source; contradiction as data ([#113](https://github.com/ahoward/brane/issues/113), [PR #117](https://github.com/ahoward/brane/pull/117))
- [ ] `068-promotion-gate` — Observation → requirement promotion with human ratification ([#114](https://github.com/ahoward/brane/issues/114))
- [ ] `069-regeneration-spike` — **Keystone**: regenerate from graph → test → feed failures back ([#115](https://github.com/ahoward/brane/issues/115))
- [ ] `070-production-teacher` — Ingest prod traces / incidents / evals as evidence ([#116](https://github.com/ahoward/brane/issues/116))

### Deferred

- [ ] `028-verifier-node` — Headless verification node
Expand All @@ -104,6 +113,7 @@ The hippocampus: 3 verbs, dual-write graph + audit trail, trust tiers. The agent

| Feature | PR | Date |
|---------|-----|------|
| `067-claim-authority` | #117 | 2026-08-21 |
| `102-109-hippocampus-v2` | #110 | 2026-05-30 |
| `058-status-dashboard` | #81 | 2026-03-27 |
| `057-cli-ingest-sessions` | #80 | 2026-03-27 |
Expand Down Expand Up @@ -185,3 +195,4 @@ The hippocampus: 3 verbs, dual-write graph + audit trail, trust tiers. The agent
- **032-corpus complete!** — Adversarial test material: surveillance, dark patterns, COPPA violations, alignment-washing
- **049-schema-migrations complete!** — Versioned mind.db upgrades with backup/restore, Gemini-reviewed
- **053-fuzzy-dedup complete!** — Length-scaled Levenshtein prevents false matches on short concept names
- **067-claim-authority complete!** — Claims carry authority tier + source; contradiction is data. Schema v1.13.0, `contradictions` built-in rule, Fable-reviewed (2 rounds, 3 blockers), 432 tests
Loading