mirror of
https://github.com/garrytan/gbrain.git
synced 2026-08-14 08:53:22 +00:00
docs/architecture/brains-and-sources.md promises `gbrain query "X" --brain media-team` runs against the team's DB, and brain-resolver.ts implements the full 6-tier chain — but nothing ever called the resolver from the CLI dispatch path. `--brain <id>` was silently ignored and every command ran against the host brain: confident wrong answers, the silent-wrong-results class (#1712 / #3524 shape, brain axis). - parseGlobalFlags strips `--brain <id>` / `--brain=<id>` (exact match; `--brain-*` per-command flags pass through). Missing/malformed value throws at parse time — never a silent fallback. - connectEngine (the single choke point every local command routes through) resolves the documented chain — flag > GBRAIN_BRAIN_ID > .gbrain-mount > mount-path-prefix > 'host' — and routes non-host ids through BrainRegistry.getBrain: unknown id throws UnknownBrainError; postgres mounts get a per-instance pool; no auto-migrations against a mount (schema is the publisher's job); AI gateway stays on the host config. - makeContext stamps ctx.brainId from the resolved id — module state, never op params, so an untrusted MCP caller has no path to name a brain. - Thin-client installs refuse an explicit --brain loudly (mirror of the --source refusal); ambient tiers are ignored, matching the source axis. - childGlobalFlags propagates --brain=<id> so gbrain child subprocesses stay on the parent's brain (env/dotfile tiers self-propagate already). Tests: test/brain-flag-routing.serial.test.ts spawns the real CLI against two seeded PGLite brains — routing, unknown-id hard error, and env tier all fail behaviorally on an unfixed tree (verified against origin/master); plus fail-closed pins that no op exposes a brain param and neither context builder reads one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>