* v0.40.6.0 Phase 1 foundations — pack-lock + mutate-audit + cache invalidation + lint rules + best-effort
Six new primitives that Phase 2's withMutation skeleton (next commit) depends on.
No consumers yet; all callers wire up in Phase 4. Foundations ship first per
codex C1 phase-ordering finding from /plan-eng-review.
1.1 pack-lock.ts (18 cases)
Atomic acquire via openSync(path, 'wx') = O_CREAT|O_EXCL. Kernel-level
atomic, NO TOCTOU window. Codex C8 caught that page-lock.ts:79+96 has
existsSync+writeFileSync (TOCTOU) — we deliberately do NOT copy it.
Stale detection via TTL (60s default) + kill(pid, 0) liveness probe.
TTL refresh every 10s while withPackLock(fn) runs so long DB-aware
lint/stats on big brains don't go stale. --force = "steal stale lock"
(NOT "skip locking"). Lock path per-pack so two packs never block.
1.2 mutate-audit.ts (13 cases)
ISO-week JSONL at ~/.gbrain/audit/schema-mutations-YYYY-Www.jsonl.
Privacy redacted per D20: type names → sha8, prefixes → first slug
segment only. Matches candidate-audit.ts privacy posture. Both verbose
surfaces gate on GBRAIN_SCHEMA_AUDIT_VERBOSE=1 (same env). Logs BOTH
success AND failure events so Phase 9's schema_pack_writability doctor
check has signal to read (closes codex C11). summarizeMutations()
primitive shipped for cross-surface parity between doctor + future
audit CLI.
1.3 registry.ts cache invalidation + stat-mtime TTL (10 cases)
invalidatePackCache(name?) walks the extends-chain reverse-graph
(every cached entry whose chain contains name is evicted). This is the
codex C6 fix — pre-v0.40.6, editing a parent pack silently left
children stale because cache identity was child-bytes-only. New
per-name CacheEntry tracks the file-stat snapshot of every file in
the extends chain. tryCachedPack(name) is the TTL-gated fast path:
inside STAT_TTL_MS (1000ms default, env GBRAIN_PACK_STAT_TTL_MS)
returns cached without statting. Outside the window: stats every file
and cascade-invalidates on any mtime change (D11 cross-process
detection). resolvePack reference-equality preserved on byte-identical
re-build. ASCII state-machine diagram in file header (D9).
1.4 best-effort.ts (4 cases)
loadActivePackBestEffort(ctx) returns ResolvedPack | null. Single
source of truth for the 4 T1.5 wiring sites (Phase 8). null means
"EMPTY FILTER" semantics, NOT "fall back to hardcoded defaults" —
pack-load failure must be loud, per D4. Never throws.
1.5 lint-rules.ts (35 cases)
11 pure rule functions extracted from CLI handlers per codex C13/D16.
9 file-plane rules + 2 DB-aware rules (extractable_empty_corpus, mutation_count_anomaly).
Phase 2 withMutation pre-write gate composes file-plane subset.
runAllLintRules() returns {ok, errors, warnings} structured report
ready for CLI + MCP.
1.6 query-cache-invalidator.ts (4 cases)
invalidateQueryCache(engine, sourceId?) DELETEs query_cache rows so
cached search results bound to old page types don't survive a
schema mutation. Reuses SemanticQueryCache.clear() so we don't
reinvent the PGLite+Postgres parity. Codex C9 fix.
Tests: 84 new cases across 6 test files. All 153 schema-pack tests green.
Plan: ~/.claude/plans/system-instruction-you-are-working-recursive-thacker.md
Closes: half of T2-T7 from the plan's Implementation Tasks JSONL.
Successor to: closed PR #1321 (community PR; author garrytan-agents).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* v0.40.6.0 Phase 2 — mutate.ts withMutation skeleton + 11 primitives
Builds on Phase 1 foundations (pack-lock, mutate-audit, lint-rules,
cache invalidation, query-cache-invalidator).
withMutation(packName, opts, mutator, op, ctx): 8-step skeleton wrapping
every primitive. Atomic .tmp+fsync+rename. Per-pack file lock. Pre-write
file-plane lint validation gate. Audit log on success AND failure. Pack
cache + query cache invalidation hooks. ASCII state-machine diagram in
file header per D9.
11 primitives, each ~5-line wrapper around withMutation:
add_type, remove_type (with codex C14 reference check), update_type
add_alias, remove_alias, add_prefix, remove_prefix
add_link_type (rejects fm_links refs on remove)
remove_link_type, set_extractable, set_expert_routing
Inline minimal JSON→YAML emitter so mutating a YAML pack stays YAML.
The emitter's array-of-mappings nesting was tricky: the first key sits
inline with the `- ` (e.g. `- name: person`), subsequent keys live at
indent+1, and nested arrays inside the mapping keep their relative
depth (the v0.40.6 emitter bug I fixed pre-commit: trim+prefix lost
internal indent of nested arrays like path_prefixes).
YAML round-trip: emitted YAML reparses cleanly through parseYamlMini.
Comments and formatting NOT preserved (documented in plan; pin pack.json
if you care about layout).
Codex C14 reference check: removeType refuses if any other type's
aliases/enrichable_types/link_types/frontmatter_links references the
target. STILL_REFERENCED error names every reference for cleanup.
Validation gate composes runFilePlaneLintRules from Phase 1.5 — a
mutation that would create a dangling ref or prefix collision fails
BEFORE the .tmp write (the invariant: pack file on disk is NEVER
partial).
Tests: 34 cases pinning every primitive + skeleton invariant. Bundled
guard, codex C14, atomicity (crash-mid-write leaves original untouched,
lock auto-released after mutator throw), YAML round-trip, validation
gate firing on prefix collision.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* v0.40.6.0 Phase 3 — stats + sync pure core functions
Both ship as runStatsCore / runSyncCore pure functions so Phase 4 CLI
handlers (next commit) and Phase 7 MCP ops (later) both compose without
duplicating logic. Codex C13 / D16 prereq for the MCP exposure phase.
stats.ts (17 cases):
Multi-source aware: sourceIds[] (federated read) OR sourceId (single)
OR neither (whole-brain aggregate). NULLIF(type, '') normalizes
empty-string + NULL to one untyped bucket (pages.type is NOT NULL in
the schema so empty string is the legacy "untyped" representation).
Soft-delete exclusion. by_type sorted by count desc, ties by name asc.
Empty-brain coverage:1.0 (vacuous truth, matches getBrainScore).
Dead-prefix detection: pack-declared prefixes with zero matching
pages surface as DeadPrefixHint[] (agent's drilldown signal for
mis-declared paths). Best-effort: pack-load failure leaves
pack_identity:null + dead_prefixes:[].
sync.ts (13 cases):
D14 chunked UPDATE: 1000-row batches per prefix. Each batch:
WITH win AS (SELECT id FROM pages WHERE untyped+prefix LIMIT $batch),
upd AS (UPDATE ... WHERE id IN win RETURNING 1) SELECT COUNT(*). Loop
until zero rows. Concurrent writers never block on the row-set for
more than ~100ms per batch (vs the multi-second monolithic UPDATE
shape PR #1321 had).
Codex C5 write-side scoping: sourceId param directly, NOT
sourceScopeOpts which is read-side and inherits OAuth federation
reads. Phase 7 MCP op (schema_apply_mutations) enforces at dispatch.
Dry-run by default: per-prefix probe returns would_apply + 10-slug
sample (the drilldown signal). Apply path returns total_applied.
Idempotency contract pinned: second apply finds zero matching rows.
Soft-delete exclusion on both probe + update. Dead-prefix flag set
when probe returns count=0. JSON envelope schema_version:1.
Tests use canonical PGLite block per CLAUDE.md test-isolation rules.
seedPage helper auto-seeds sources(id) row before FK insert.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* v0.40.6.0 Phase 4 — wire 14 new schema CLI verbs
Thin handlers wrapping Phase 2's mutation primitives + Phase 3's
stats/sync cores. CLI is the human surface; Phase 7 wires the same
cores into MCP for agent use.
New verbs:
Authoring:
add-type <name> --primitive P --prefix dir/ [--extractable]
[--expert] [--alias A]* [--pack <name>]
remove-type <name> [--pack <name>]
update-type <name> [--extractable BOOL] [--expert BOOL]
[--primitive P] [--pack <name>]
add-alias <type> <alias> [--pack <name>]
remove-alias <type> <alias> [--pack <name>]
add-prefix <type> <prefix> [--pack <name>]
remove-prefix <type> <prefix> [--pack <name>]
add-link-type <name> [--inverse V] [--page-type T] [--target-type T]
[--pack <name>]
remove-link-type <name> [--pack <name>]
set-extractable <type> BOOL [--pack <name>]
set-expert-routing <type> BOOL [--pack <name>]
Activation:
reload [--pack <name>] Flush in-process cache; --pack scopes
Discovery + repair:
stats [--source <id>] Per-type counts + coverage + dead prefixes
sync [--apply] [--source <id>] Backfill page.type (chunked UPDATE)
cli.ts: schema added to CLI_ONLY_SELF_HELP so `gbrain schema --help`
routes to printHelp() instead of the generic one-line stub.
withConnectedEngine defensive fix retained from PR #1321:
EngineConfig built once and passed to BOTH createEngine and
engine.connect for future-proof against engine implementations that
read URL at connect time.
End-to-end agent journey verified:
fork gbrain-base mine → use mine →
add-type researcher --primitive entity --prefix people/researchers/
--extractable --expert →
active (shows 23 page types) →
stats (shows 100% coverage on empty brain, vacuous truth).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* v0.40.6.0 Phase 5+6+7 — schema lint with rich rules + 9 new MCP ops
This is the marquee commit: Wintermute and any other remote OAuth agent
can now author + introspect schema packs over normal HTTPS MCP. Phases
5+6 collapse into Phase 7 because the new MCP ops compose Phase 1.5's
lint rules and Phase 2/3's mutation/stats/sync cores directly — no
extra extraction needed (D6 from /plan-eng-review).
Phase 5: schema lint CLI wired to runAllLintRules from Phase 1.5
Replaces the prior 2-rule check (duplicate names + missing prefix)
with the full 11-rule suite. New --with-db flag opts into the 2
DB-aware rules (extractable_empty_corpus, mutation_count_anomaly).
JSON envelope shape stable. Exit code 1 on any error.
Phase 7: 9 new MCP operations
Read-scope (NOT localOnly — read scope is safe to expose remote):
get_active_schema_pack — identity packet (pack name, sha8, counts).
list_schema_packs — bundled + installed names.
schema_stats — composes runStatsCore from Phase 3.
schema_lint — composes runAllLintRules; --with-db is
CLI-only (DB-aware rules need engine).
schema_graph — JSON {nodes, edges} from link_types
inference + frontmatter_links.
schema_explain_type — settings for one declared type.
schema_review_orphans — untyped pages drilldown.
Admin-scope (NOT localOnly per D2 — Wintermute reaches via OAuth):
schema_apply_mutations — BATCHED per D10. Single MCP tool taking
a mutations[] array; composes all 11
mutate primitives. Atomic batch_id; outer
withPackLock wraps the whole batch so no
other writer can slip in mid-iteration.
Partial-results returned on mid-batch
failure for forensic agent debugging.
Audit log records actor=mcp:<clientId8>
(D20 privacy-redacted shape).
reload_schema_pack — flush in-process cache + extends-chain
cascade (codex C6 fix from Phase 1.3).
withConnectedEngine defensive fix applied to schema.ts:withConnectedEngine
(PR #1321 closed) — EngineConfig built once and passed to BOTH
createEngine AND engine.connect for defense in depth.
Test seams:
- operationsByName lookup pinned for every new op.
- All 9 ops have scope + localOnly declarations pinned to lock in
the trust posture.
- Batched mutation atomicity tested: partial-failure returns
{error: mutation_failed, partial_results: [...]} with one batch_id
across all results.
- Audit log actor=mcp:<clientId.slice(0,8)> capture verified
end-to-end (audit JSONL read back after the op handler runs).
- Empty mutations[] rejected with invalid_request.
- Unknown op surfaced via SchemaPackMutationError INVALID_RESULT.
Coverage: 23 new cases for the 9 ops (operations-schema-pack.test.ts).
All 255 schema-pack-related tests green.
Plan: ~/.claude/plans/system-instruction-you-are-working-recursive-thacker.md
Successor to: closed PR #1321.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* v0.40.6.0 Phase 8 + 10 + 12 — T1.5 wiring, schema-author skill, ship
Final wave commit. Brings the cathedral from "shipped but undiscoverable"
to "shipped + agents find it + agents use it."
Phase 8 (partial T1.5 wiring — agent-facing surfaces):
- whoknows CLI (src/commands/whoknows.ts:340) consults the active pack
via loadActivePackBestEffort + expertTypesFromPack. Pack-load failure
→ EMPTY filter (NOT hardcoded ['person', 'company'] defaults) per
D4. A researcher type declared --expert in a custom pack now
surfaces in `gbrain whoknows "ML"` results. Pre-v0.40.6 it silently
never matched.
- find_experts MCP op (src/core/operations.ts:2820) same wiring so
OAuth clients (Wintermute etc.) inherit pack-aware expert routing
over HTTP MCP, not just CLI.
- facts/eligibility.ts and enrichment-service.ts union widening
deferred to v0.40.7+ (filed in TODOS.md as 2 follow-up entries) —
larger blast radius than fit this wave's context budget.
Phase 10 (skill + RESOLVER + Convention — the discoverability layer):
- skills/schema-author/SKILL.md — agent dispatcher for "evolve the
schema pack." 36 trigger phrases route here. Explicit Non-goals
section names brain-taxonomist (filing one page) and eiirp
(schema-check during iteration) so agents pick the right surface.
7-phase workflow: brain → assess → propose → apply → sync → verify
→ commit. Lists every gbrain schema CLI verb + every MCP op the
skill uses. brain_first: exempt frontmatter (this skill IS the
brain-first path for schema authoring).
- skills/conventions/schema-evolution.md — decision tree for "when to
add a type vs alias vs prefix." <20 pages → don't pack-codify;
20-100 → alias or narrow prefix; 100+ → first-class type. Don'ts
section + "when to remove a type" + "when to commit the pack" all
answered from one place.
- skills/RESOLVER.md entry with full functional-area dispatcher line
(compressed routing pattern per v0.32.3 dispatcher convention).
- schema-evolution.md added to the cross-cutting Conventions list.
Phase 12 (ship bookkeeping):
- VERSION → 0.40.6.0
- package.json → 0.40.6.0
- CHANGELOG.md entry with ELI10 lead per CLAUDE.md voice rules
(250+ words explaining the wave in plain English before any
file/function name appears), full "To take advantage of v0.40.6.0"
paste-ready commands block, itemized changes by category, credit
to @garrytan-agents (PR #1321 author).
- TODOS.md gains 10 new follow-up entries grouped under
"v0.40.6.0 Schema Cathedral v3 follow-ups (v0.40.7+)" covering:
enrichment-service union widening, facts/eligibility wiring, 3
doctor checks, T16 + T16.1 evals, T19 federated closure, T20
extends merging, T21 YAML comments, T22 admin SPA, T23
schema:write scope, T24 multi-tenant federation.
- llms-full.txt regenerated via bun run build:llms (CLAUDE.md
edits trigger the test/build-llms.test.ts gate — required per
repo discipline).
Verification:
- bun run typecheck clean.
- Full agent journey smoke-tested end-to-end in Phase 4 commit
(fork → use → add-type → active → stats — all green).
- All 255+ schema-pack tests green from Phases 1-7.
Total wave: 6 commits, ~5000 net LOC, 84 new tests, 21 design
decisions captured. PR #1321 closed with successor pointer comment.
Plan: ~/.claude/plans/system-instruction-you-are-working-recursive-thacker.md
Co-Authored-By: garrytan-agents <garrytan-agents@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(ci): rename Wintermute → 'your OpenClaw' + add schema-author skill conformance
CI failures from PR #1327 first run:
1. check:privacy script flagged 4 'Wintermute' name leaks (CLAUDE.md:550 rule —
never use the private OpenClaw fork name in public artifacts):
- src/core/operations.ts:3816 → 'your OpenClaw and similar remote agents'
- src/core/operations.ts:4015 → 'your OpenClaw, etc.' (in description)
- src/core/operations.ts:4225 → 'your OpenClaw, etc.' (in comment)
- test/operations-schema-pack.test.ts:325 → clientId 'remoteAgentClient12345678'
(matching audit-actor regex updated: 'mcp:remoteAg' instead of 'mcp:wintermu')
2. skills/manifest.json missing schema-author entry. Added between
brain-taxonomist and skillify per alphabetical-ish grouping.
3. skills/schema-author/SKILL.md missing 3 conformance sections per
test/skills-conformance.test.ts:
- ## Contract (inputs/outputs/side effects/idempotency/trust/atomicity)
- ## Anti-Patterns (don't mutate bundled packs, don't add types for one-off
directories, don't conflate filing vs. schema authoring, etc.)
- ## Output Format (per-mutation JSON, per-batch JSON, stats JSON, sync
dry-run JSON, human format, error envelope codes)
The 3 sections were inserted ABOVE the existing 'Failure modes' section so
the existing failure-mode bullets are still adjacent to the new error
envelope codes in Output Format.
Verified locally:
- bun run check:privacy → clean
- bun test test/skills-conformance.test.ts test/check-resolvable.test.ts test/check-resolvable-cli.test.ts test/regression-v0_22_4.test.ts → 286/286 pass
- bun test test/operations-schema-pack.test.ts → 23/23 pass
- bun run verify → clean (privacy + skill_brain_first + fuzz-purity + typecheck)
llms.txt + llms-full.txt regenerated.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs: v0.40.7.0 — schema cathedral v3 README + CLAUDE.md annotations
Doc-debt cleanup from the v0.40.7.0 ship (Phase 12 had deferred these to
fit context budget; /document-release surfaced the gap):
- README.md: new "What's new in v0.40.7.0" lead paragraph above the
v0.36.4.0 entry. ELI10 lead: "Your agents can now author your brain's
schema pack themselves" + the agent journey + 14 CLI verbs + 9 MCP
ops + schema-author skill boundary callouts.
- CLAUDE.md: new "Schema Cathedral v3 (v0.40.7.0)" section between the
thin-client routing cluster and the Commands section. 14-bullet
Key Files cluster covering pack-lock / mutate-audit / registry /
best-effort / lint-rules / query-cache-invalidator / mutate / stats /
sync / schema.ts CLI / operations.ts MCP / whoknows T1.5 wiring /
schema-author skill / schema-evolution convention. Each bullet
references the design decisions (D2/D4/D6/D8/D9/D10/D11/D13/D14/D20)
and codex findings (C5/C6/C8/C9/C13/C14) captured during /plan-eng-review.
Closes the "CLAUDE.md has zero v0.40.7.0 mentions" doc debt.
- llms-full.txt + llms.txt regenerated.
Privacy check clean (no Wintermute leaks in the new prose — used "your
OpenClaw" per CLAUDE.md:550 rule). test/build-llms.test.ts 7/7 green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs: tutorial — Build your first schema pack (closes v0.40.7+ doc-debt)
Closes the tutorial gap surfaced by /document-release's Diataxis coverage
map. The schema-pack cathedral shipped with reference (CLAUDE.md cluster),
how-to (SKILL.md 7-phase workflow), and explanation (conventions/
schema-evolution.md decision tree), but no tutorial — no concrete
"your first schema mutation" walkthrough.
docs/schema-author-tutorial.md ships exactly that:
- 8 numbered steps, time-to-first-result < 3 (active pack visible by step 2)
- Walks from `gbrain schema fork gbrain-base mine` through `add-type
researcher` + `sync --apply` + proving the T1.5 wiring via `gbrain
whoknows` surfacing the new type
- Every step shows the exact command and expected output
- Placeholder pages (alice-example, bob-example, charlie-example) so any
brain can run the tutorial without affecting real content
- "What you built" section recaps state on disk + active wiring
- "Next steps" cover add-link-type, add-alias, lint --with-db, commit to
source control, MCP path for agents
- "Related docs" cross-links to reference (CLAUDE.md cluster) + how-to
(SKILL.md workflow) + explanation (schema-evolution.md)
Cross-linked:
- README.md "What's new in v0.40.7.0" paragraph gets a "Walkthrough:"
pointer at the end
- skills/schema-author/SKILL.md gets a "## Tutorial" callout just above
the workflow phases — agents that hit the skill via RESOLVER routing
see the tutorial pointer first
Closes the Diataxis quadrant matrix to full coverage:
- Tutorial: ✅ docs/schema-author-tutorial.md (NEW)
- How-to: ✅ skills/schema-author/SKILL.md workflow
- Reference: ✅ CLAUDE.md cluster + gbrain schema --help
- Explanation: ✅ skills/conventions/schema-evolution.md
Privacy check clean. Typecheck clean. llms-full.txt regenerated (545KB).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs: what-schemas-unlock — the WHY doc (7 use cases + structural argument)
The schema-author tutorial walks through HOW to mutate a pack. This new
doc explains WHY agents and users should care, with concrete killer use
cases on real corpus shapes:
1. The 4000 invisible meetings — untyped pages skip every structural
surface (whoknows, find_experts, recall, think). Adding a `meeting`
type + sync flips them from invisible to queryable. Same content,
completely different agent experience.
2. The founder ops brain — 4 type-adds + 4 link-types build a
CRM-shaped query surface. `gbrain whoknows "Series A SaaS"` routes
through investor + portco specifically; `graph-query` walks intro
chains. Downstream of notes, not parallel to them.
3. The research brain — researcher / paper / lab / grant / dataset
types + cites / authored / uses link verbs turn a reading-list-as-
markdown into a queryable research graph.
4. The legal brain (or anything where claims have numbers) — typed
`damages=5000000`, `filed_date=...` become comparable across pages
of the same type. Generic note systems can't do this because they
don't know which numbers belong to which type.
5. The team brain — each mounted brain has its own schema pack. Two
engineers searching the same brain get DIFFERENT routing because
their personal packs declare different expert types.
6. The agent-co-curates pattern — the NEW thing in v0.40.7.0. Agent
watches your ingestion stream, runs `gbrain schema detect`
periodically, proposes a new type when a pattern accumulates, applies
it via batched MCP `schema_apply_mutations` after one approval.
Brain learns. Audit log captures the agent's client_id as
`actor: mcp:<clientId8>`.
7. Before-vs-after on real content — pick a corpus, note top-3
whoknows results, add the type via sync, re-run. The numerical
delta IS the win.
Then the structural argument: types matter at query time. Untyped
content is invisible content. The schema is queryable AND mutable AND
auditable — that's the production-system difference from "vibes-based
knowledge management."
Closes with the v0.40.7.0-specific list of what changed (withMutation
skeleton, O_CREAT|O_EXCL atomic lock vs page-lock.ts TOCTOU pattern,
privacy-redacted audit log, 9 MCP ops, T1.5 wiring, cross-process
invalidation via stat-mtime TTL gate).
Cross-linked:
- README.md "What's new in v0.40.7.0" paragraph now has both the
"Why it matters:" pointer (this doc) AND the "Walkthrough:"
pointer (tutorial).
- docs/schema-author-tutorial.md opens with "Want the WHY before the
HOW?" link to this doc.
- skills/schema-author/SKILL.md now has a "Tutorial + vision" section
that points at both, with explicit guidance that agents should read
the WHY doc before pitching schema authoring to a user.
177 lines. Privacy check clean. Typecheck clean. llms-full.txt
regenerated (545KB).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs: surface schema docs from README Capabilities + Docs index + llms.txt
The two new schema docs were ONLY linked from the v0.40.7.0 "What's new"
paragraph in README. That paragraph will get pushed down by every future
release and become a worse and worse entry point.
Real discovery paths added:
1. README.md `## Capabilities` section — new "Agent-authored schema
(v0.40.7.0)" bullet between "Brain consistency" and "## Integrations".
Permanent home alongside Hybrid search, Self-wiring graph, Minions,
43 skills, Eval framework. Includes the one-paragraph pitch + 3
pointer links (vision / tutorial / agent skill).
2. README.md `## Docs` index — two new lines added at the top of the
list (right after docs/INSTALL.md, before docs/architecture/):
- docs/what-schemas-unlock.md with one-line description
- docs/schema-author-tutorial.md with one-line description
3. scripts/llms-config.ts `Configuration` section — both docs added to
the curated llms.txt entry list so the LLM-readable map points at
them. Sits right after docs/GBRAIN_RECOMMENDED_SCHEMA.md (topical
grouping). includeInFull defaults to true so they ride in the
single-fetch llms-full.txt bundle.
Result: schema docs are now reachable from 5 entry points instead of 1:
- README "What's new" paragraph (release-pinned, will age out)
- README Capabilities bullet (permanent, top-of-funnel)
- README Docs index (permanent, end-of-page reference)
- llms.txt (LLM-readable curated map)
- llms-full.txt (single-fetch bundle for agents)
Also caught 3 leftover Wintermute leaks in docs/what-schemas-unlock.md
that the privacy check flagged: agent-co-curates pattern now uses "your
OpenClaw"; `register-client wintermute` example renamed to
`register-client my-agent` per CLAUDE.md:550 privacy rule. Privacy
check clean. test/build-llms.test.ts 7/7 green. llms.txt 4314 → 5000
bytes, llms-full.txt 545KB → 572KB.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: garrytan-agents <garrytan-agents@users.noreply.github.com>
9.9 KiB
Tutorial: Build your first schema pack
You'll fork the bundled gbrain-base pack, add a custom researcher page type, import a handful of placeholder researcher pages, backfill their page.type column with one command, then prove the wiring works by running gbrain whoknows and seeing your new type surface in results. End state: a forked-and-active pack on disk, ~5 pages typed as researcher, and a query that proves the pack-aware routing fires end-to-end.
Want the WHY before the HOW? Read what-schemas-unlock.md first — 7 concrete use cases (4000 invisible meetings, the founder ops brain, the research brain, the legal brain, the team brain, agent-as-co-curator) plus the structural argument for why types matter at query time. Then come back here for the 5-minute walkthrough.
The whole walkthrough takes about 5 minutes. You'll see something working by step 3.
What you'll need
- gbrain v0.40.7.0 or later (
gbrain --versionto check) - A brain that's been initialized (
gbrain initalready run; either PGLite or Postgres is fine) - A terminal you can paste commands into
That's it. No API keys required for this tutorial — every step works against the bundled pack and local-only commands.
Step 1: See what pack is active today
gbrain schema active --json
You'll see something like:
{
"pack_name": "gbrain-base",
"version": "1.0.0",
"sha8": "...",
"page_types_count": 22,
"source_tier": "default"
}
source_tier: "default" means you haven't customized anything — you're on the bundled pack. page_types_count: 22 is the universal starter (person, company, meeting, note, etc.).
You can't mutate bundled packs directly. Step 2 forks it so you have something writable.
Step 2: Fork the bundled pack
gbrain schema fork gbrain-base mine
Output: Forked 'gbrain-base' → 'mine' at ~/.gbrain/schema-packs/mine/pack.json.
The fork is a byte-for-byte copy of gbrain-base living at ~/.gbrain/schema-packs/mine/pack.json. Now you have a writable pack you can mutate.
Step 3: Activate the fork
gbrain schema use mine
Output: Pack: mine (json) ... Active.
Run gbrain schema active --json again to confirm pack_name is now mine and source_tier is home-config (read from ~/.gbrain/config.json).
You've already accomplished something visible — the active pack changed, and any future query will route through your fork. The next four steps add a custom type and prove it works.
Step 4: Add a researcher type
gbrain schema add-type researcher \
--primitive entity \
--prefix people/researchers/ \
--extractable \
--expert
Output: Pack: mine (json) + Sha8: <prev> → <new>.
What just happened:
- The mutation went through
withMutation's 8-step skeleton: bundled-guard → per-pack lock → read → mutate → file-plane lint validation → atomic write → audit log → cache invalidation. - The pack now declares
researcheras an entity primitive bound topeople/researchers/, markedextractable: true(eligible for facts extraction) andexpert_routing: true(surfaces inwhoknowsqueries). - An audit row landed in
~/.gbrain/audit/schema-mutations-YYYY-Www.jsonlwith your type name SHA-8-redacted and the prefix's first segment only (people) for privacy.
Verify the type is in the pack:
gbrain schema explain researcher
You'll see the resolved settings printed back.
Step 5: Import some placeholder researcher pages
You need pages under people/researchers/ for the next step to do anything. If your brain repo already has them, skip ahead. If not, drop 3-5 placeholder markdown files into <your-brain-repo>/people/researchers/ and import:
mkdir -p people/researchers
cat > people/researchers/alice-example.md <<'EOF'
---
title: Alice Example
---
ML researcher at Example Lab. Works on contrastive embeddings.
EOF
cat > people/researchers/bob-example.md <<'EOF'
---
title: Bob Example
---
Vision researcher at Widget University. Recent paper on diffusion models.
EOF
cat > people/researchers/charlie-example.md <<'EOF'
---
title: Charlie Example
---
RL researcher at Acme Research. Focus on inverse reinforcement learning.
EOF
gbrain sync
The sync imports the new files. They'll be stored in the database but their type column will still be empty — the new type was added to the pack AFTER these pages already existed (the typical real-world scenario for an agent walking into an existing brain).
Step 6: See the gap with stats
gbrain schema stats --json | jq '.aggregate, .dead_prefixes'
You'll see untyped_pages: 3 (or however many you just imported) and dead_prefixes: [] — your new prefix has 3 matching pages, so it's not dead.
The 3 researcher pages are "orphaned" by type even though they live in the right directory. The next step backfills them.
Step 7: Backfill with sync --apply
First dry-run to see what would happen:
gbrain schema sync --json
You'll see something like:
{
"schema_version": 1,
"apply": false,
"per_prefix": [
{
"type": "researcher",
"prefix": "people/researchers/",
"would_apply": 3,
"sample_slugs": ["people/researchers/alice-example", "people/researchers/bob-example", "people/researchers/charlie-example"],
"applied": 0
}
],
"total_would_apply": 3,
"total_applied": 0
}
would_apply: 3 is what you'd touch. sample_slugs is the agent's drilldown signal — if those slugs look wrong, abort. They look right, so apply:
gbrain schema sync --apply
You'll see per-batch progress lines on stderr and a final total_applied: 3. The UPDATE ran in chunks of 1000 (yours fit in one chunk) and never wedged any concurrent writer.
Step 8: Prove the wiring works
gbrain whoknows "machine learning"
If your researcher pages contain ML-related content, they'll surface in the ranked results — even though they're typed researcher, not person or company.
This is the load-bearing demonstration of T1.5 wiring. Pre-v0.40.7.0, whoknows hardcoded ['person', 'company'] as the eligible types and would have ignored your researcher pages entirely. The v0.40.7.0 wiring consults the active pack's expert_routing: true types via expertTypesFromPack(pack.manifest), so your custom type now routes through expert search.
What you built
You now have:
- A fork of
gbrain-basenamedmineat~/.gbrain/schema-packs/mine/pack.json, active in your brain via~/.gbrain/config.json. - A
researcherpage type registered in the pack withentityprimitive,people/researchers/prefix,extractable: true,expert_routing: true. - 3 pages typed as
researcher(backfilled from disk viagbrain schema sync --apply). - A query path that routes through the new type:
gbrain whoknowsreads the pack and includesresearcherin its type filter.
You also exercised the full mutation skeleton: bundled-pack guard, per-pack lock, validation gate, atomic write, audit log, cache invalidation. Every step was idempotent — re-running any of them is a no-op.
Next steps
Add a link verb. A researcher can author a paper. To model that:
gbrain schema add-type paper --primitive annotation --prefix research/papers/ --extractable
gbrain schema add-link-type authored --page-type researcher --target-type paper
gbrain schema graph
The graph now shows researcher --(authored)--> paper.
Add aliases for query closure. If you want gbrain query researcher to also surface person rows (because researchers ARE people):
gbrain schema add-alias researcher person
Read skills/conventions/schema-evolution.md for the decision tree on when to add types vs aliases vs prefixes. The short version: <20 pages → don't pack-codify; 20-100 → alias on existing type; 100+ → first-class type.
Lint your pack before shipping. The 11-rule lint surface (with the optional --with-db flag for DB-aware checks) catches dangling references, prefix collisions, and dead-corpus warnings:
gbrain schema lint --with-db
Commit your pack to source control. If ~/.gbrain/schema-packs/mine/ is a git repo, commit pack.json and push. Your pack survives across machines, and the mutation_count_anomaly lint rule will nudge you when you hit >50 mutations in a week (the "you should be committing this" signal).
For agents (MCP): the same operations are reachable over HTTPS MCP via 9 new ops. Register an admin-scope OAuth client and schema_apply_mutations lets a remote agent compose multi-step refactors as one atomic batch. The batched MCP op + per-pack lock + audit log are the load-bearing primitives that make remote schema authoring safe. See skills/schema-author/SKILL.md for the agent dispatcher.
Undo a mistake. Every mutation primitive has an inverse (remove-type, remove-alias, remove-prefix, remove-link-type, set-extractable false, etc.). If you fork twice and want to revert, gbrain schema downgrade restores the previous active pack from ~/.gbrain/schema-pack-history.jsonl.
Related docs
- Reference:
gbrain schema --helpfor the full 22-verb CLI surface; CLAUDE.md's "Schema Cathedral v3 (v0.40.7.0)" section for the module-by-module architecture. - How-to:
skills/schema-author/SKILL.md— the agent dispatcher with the 7-phase workflow (brain → assess → propose → apply → sync → verify → commit). - Explanation:
skills/conventions/schema-evolution.md— when to add a type vs alias vs prefix. - Plan + decisions: the original design captured 21 decisions including the bundled-pack guard rationale (D6), the empty-filter fallback contract (D4), and the MCP non-localOnly trust posture (D2). Lives in
~/.claude/plans/system-instruction-you-are-working-recursive-thacker.md(private).