Multi-source brains
A single modusbrain database can hold multiple knowledge repos. Each one is asource: a logical brain-within-the-brain with its own slug
namespace, its own sync state, and its own federation policy. The rest
of this guide walks the three canonical scenarios.
The three scenarios
1. Unified knowledge recall (wiki + gstack)
You have a personal wiki and agstack checkout. Both belong to you,
both are knowledge you want your agent to recall across. When you ask
“what did I learn about X?” you want the best hit whether it lives in
the wiki or in a gstack plan.
2. Purpose-separated brains (team-media + personal-list)
You run two completely different content pipelines on the same backend. Team Media covers portfolio news and founder profiles. Shubham’s List is personal writing. You explicitly DON’T want them mixed in search — company portfolio content leaking into essay searches is a bug, not a feature.default source
(your main brain). Searching from inside ~/team-media returns only team-
media hits. Searching from inside ~/writing returns only personal-list.
Federation is opt-in, not leaked.
To search across them explicitly on demand:
3. Mixed (wiki federated + sessions isolated)
Your main wiki is federated with a few trusted sources. Your session transcripts (coming in v0.18) land in a separate isolated source so they don’t dominate every search result.Resolution priority
When any command needs to pick a source, modusbrain walks this list (highest first):- Explicit
--source <id>flag. MODUSBRAIN_SOURCEenvironment variable..modusbrain-sourcedotfile in CWD or any ancestor directory.- A registered source whose
local_pathcontains the CWD (longest prefix wins for nested checkouts). - The brain-level default set via
modusbrain sources default <id>. - The seeded
defaultsource.
~/.gstack/plans/ on a brain that pinned gstack to
~/.gstack via .modusbrain-source, modusbrain put-page implicitly writes to
the gstack source. Outside any registered directory with no env/dotfile
set, it writes to the default.
Federation flag
Every source row storesconfig.federated: boolean in its JSONB config.
The seeded
default source is federated=true so pre-v0.17 brains
behave exactly as before — every page appears in search.
Flip later with modusbrain sources federate <id> / unfederate <id>.
Commands
Full subcommand reference:Citation format for agents
When agents receive multi-source results they MUST cite pages in[source-id:slug] form. Example:
You told me about the distillation protocol — see [wiki:topics/ai] and [gstack:plans/multi-repo] for where this came from.The citation key is
sources.id (immutable). Renaming a source via
modusbrain sources rename changes the display name only; existing
citations keep working.
Writing to a specific source
Durability: keep a brain repo in sync (auto-harden)
A long-lived agent that writes to a knowledge-wiki git repo needs three things to never lose work: pull before it edits, push every write, and not go stale while it sits idle.modusbrain sources harden installs all of that,
idempotently. The moment you add a brain repo with a token, it runs
automatically:
- Pull-first, conflict-safe. Every pull is a divergence-safe rebase. A dirty working tree is skipped (your in-progress edits are never touched); a rebase conflict is aborted cleanly and flagged for attention, never left half-applied.
- Push is never deferred.
scripts/brain-commit-push.sh "<msg>" <path>commits and pushes atomically and refuses to report success without a confirmed push. The post-commit hook is a best-effort background fallback; the helper is the guarantee. - No silent staleness. A 30-minute background pull keeps an idle session current. It runs DB-free, so it never contends with a live brain for the PGLite single-writer lock.
--no-cron skips the scheduled pull, --no-verify skips the push
probe, --dry-run reports what would change, --json emits a machine
report, --all hardens every source with a remote (same-account only).
--no-harden on sources add opts out of auto-harden.
Security: the push automation is installed locally per machine (never
committed into the repo), the token is wired per-repo (an existing
credential helper is reused when present), and it never appears in the repo,
the remote URL, logs, or the JSON report. For a self-hosted git server
reachable only over a filesystem path, set MODUSBRAIN_GIT_ALLOW_FILE_TRANSPORT=1
(default is HTTPS-only).
Upgrading an existing brain
modusbrain upgrade runs the v16 + v17 migrations automatically. Your
existing pages all move under source_id='default'. Behavior is
unchanged until you add a second source.
To add one:
Not in v0.18.0
- Session transcript ingest (
.jsonl, raised size cap, session PageType) — v0.18. - Per-source retention/TTL (
modusbrain sources prune) — v0.18. - ACL enforcement via caller-identity — v0.17.1.
modusbrain sources import-from-github <url>one-shot bootstrap — patch release after the core plumbing stabilizes.
sources primitive shipped here.