This document contains the detailed architecture content moved from README.md: knowledge-layer design, routing engine, reviewer pipeline, integration contracts, and extractor extension points.
RepoBrain separates durable memory from routing preferences and session-only hints:
| Layer | Location | Purpose |
|---|---|---|
| Durable repo knowledge | .brain/{decisions,gotchas,conventions,patterns,...}/ |
Auditable, long-lived project knowledge shared through Git |
| Routing preference | .brain/preferences/ |
Reusable prefer/avoid policy for skills/workflows |
| Session profile | .brain/runtime/session-profile.json |
Local, temporary constraints for the current session |
Session profile is merged after stored preferences and can override ordinary preference weight, but does not override hard blocked/suppress outcomes or static required skill constraints.
Routing is deterministic and local. Main composition:
static_memory_policy_input + preference_policy_input + optional session_policy_input + task_context_input -> routing_engine -> invocation_plan
Priority (high -> low):
- blocked / explicit suppress
- static
required_skills - session profile routing
- negative preference (
avoid) - positive preference (
prefer) - static recommended skills
- optional/fallback signals
Routing output includes:
matched_memoriesresolved_skillsconflictsinvocation_plan(required,prefer_first,optional_fallback,suppress,blocked,human_review)- optional
routing_explanation path_source(explicit,git_diff, ornone)
brain route and brain start package:
- compact context from
brain inject - task-aware plan from
brain suggest-skills --format json - adapter-safe JSON contract with
display_modeandwarnings
display_mode:
silent-ok: no escalationneeds-review: blocked/human review/required-vs-suppress conflict present
RepoBrain keeps a stable core with thin adapters.
Core responsibilities:
- schema and storage
- deterministic review/dedupe/supersede decisions
- context injection and routing computation
Adapter responsibilities:
- translate RepoBrain output to agent-specific instructions
- invoke
brain captureon phase-completion triggers - keep candidate-first write behavior
- never write directly into
.brain/bypassing core checks
Shared lifecycle contract:
- first conversation in session (
brain startor fallbackbrain inject) - fresh conversation later in same session (
brain conversation-start, which can choosestart,inject, orskip) - task-known routing (
brain suggest-skills) - phase-completion detection (
brain capture) - session-end extraction suggestion/candidate
- failure reinforcement path
Signal tiers:
- Strong: explicit done/move-on semantics, pass-after-fail test changes, large diff scope
- Context-dependent: submodule completion, recurring bug fix, multi-file refactor with enough content-value evidence
- Weak (excluded): short acknowledgements without substantive change context
Signals boost capture confidence; they are not a direct forced should_extract=true.
brain extract and candidate decisions use a layered deterministic reviewer:
- comparability filtering (
type, status, scope) - evidence vector construction (identity/scope/text overlap/replacement/recency/lineage)
- internal relation classification:
duplicateadditive_updatefull_replacementpossible_splitambiguous_overlap
- public decision mapping:
acceptmergesupersedereject
This prevents unsafe automatic merges in ambiguous multi-target overlaps.
When enabled (autoApproveSafeCandidates: true), auto-promotion requires all checks:
- reviewer decision
acceptwithnovel_memory - memory type is not
working - no temporary-only signals
- no merge/supersede/reject conflict signals
Everything else stays for manual brain review and brain approve.
Built-in local extractor stages:
preprocess -> chunk -> candidate detection -> type classification -> field completion -> quality scoring -> prescreen dedupe -> deterministic review
External extractor extension:
- set
BRAIN_EXTRACTOR_COMMAND - RepoBrain sends prompt over
stdin - extractor returns strict JSON over
stdoutin{ "memories": [...] } - invalid output/failure falls back to local heuristic pipeline
Failure detector contract (detectFailures) follows the same local process style and expects structured JSON events.
RepoBrain can ingest local routing events:
skill_followedskill_ignoredskill_rejected_by_userworkflow_too_heavyworkflow_successworkflow_failurerouting_conflict_escalated
Design is conservative:
- negative signals default to candidate
avoidpreferences - strong conflicts surface as
pending_review - reminders are queued via reinforce pending queue
- CLI reference:
docs/cli-reference.md - Schema details:
docs/schema.md - Workflow modes:
docs/workflow-modes.md - Temporal semantics:
docs/temporal-semantics.md