# KAI BRAIN — GATE-1 WIRING ROADMAP (the path to a fully-driven brain)

_Built 2026-09-20 from the live oracle source. This is the concrete "how we actually wire him up" doc. Companion to `KAI-BRAIN-PASS2-PLAN.md` (strategy) and the two trackers._

## The core realisation

GATE-1 is **not greenfield, and the design is already proven in the codebase.** The oracle/production process has no `Engine`, but it does not need one (a second Engine is the double-lattice trap). Instead it already runs modules through **three live drivers**, each mounting cheap module instances over the **shared, already-open `universe` + `synaptic_layer`** — the House Pattern. Two dormant modules have already been moved onto the live path this way and shipped:

- **VTA** → mounted into the inner-mind ring (v9.16.30, PASS-2 #5).
- **PredictiveEngine** → mounted into the heartbeat (P5a), flag-gated `[config flag]` (default off → byte-identical when off).

So "wire the 35 dormant modules" = **keep doing that**, module by module, into the right driver, each behind the same safety pattern. This roadmap assigns every dormant module to a driver and gives the order.

---

## The three live drivers (where wiring hooks in)

| Driver | Fn (oracle_server.rs) | Cadence | Already mounts | What belongs here |
|--------|-----------------------|---------|----------------|-------------------|
| **Inner-mind ring** | `run_inner_mind_loop` @7552 | ~30 s | DMN, amygdala, dopamine, VTA, thalamus | autonomous cognition: mind-wandering, rehearsal, salience, memory refresh, topic selection |
| **Heartbeat** | `run_heartbeat_loop` @7010 | ~5 s | Drive+oscillator (reduced affect), PredictiveEngine (flag-gated) | slow homeostasis / vitals: hormones, circadian, felt state, consolidation, plasticity |
| **Reply path** | `handle_kai_turn` @3719, `handle_oracle_os_turn` @2108, `handle_public_chat_turn` @1890, `handle_discord_turn` @2852 | per turn | LexSem (ipc), language helpers, coherence, grammar stack | per-turn cognition that shapes THE ANSWER: executive gating, reactivity, comprehension, social read |

**The heartbeat's own comment names its known gaps:** it "omits amygdala arousal, serotonin, and language tone, which the full interactive engine factors into valence but which don't exist in this process." That is a to-do list written by the code itself.

---

## The proven template (copy the VTA #5 pattern)

To mount a module into the **ring** (`run_inner_mind_loop`):
1. Construct once before the loop: `let mut X = crate::cognition::x::XType::new();` (cheap constructor, no lattice — same type `Engine` holds).
2. Inside the pass, drive it from what the ring already computes (topic, hit_pairs, association surprise) and **write its effect to the shared layer**, not a struct field (#40's rule: lattice-written state survives the path split; struct state dies at it).
3. Route any telemetry through the existing `activity`/print path.
4. Gate anything behavioural behind an env flag defaulting to today's behaviour, per P5a.

To mount into the **heartbeat**: same, but drive from the vitals tick; keep it bounded (two indexed reads max, never near the 5 s budget), `if let Ok(..)` on locks (skip a poisoned lock, never panic).

To wire a **reply-path** module: consume its output at the point the reply is assembled (the `generate_*` / gate sites), behind a flag, and verify the reply is unchanged when the flag is off.

**Every edit compiles on the owner's side (`cargo build --release`) before it counts** — these are live-path Rust edits; nothing here is "done" until it builds.

---

## Module → driver assignment (the 35 dormant, ordered by leverage × safety)

### RING (autonomous cognition) — extends the established #5 pattern, lowest risk

| Order | Module | Drive from → write to | Why the ring | Risk |
|-------|--------|------------------------|--------------|------|
| R1 | **#11 serotonin** | assoc-mean / mood baseline → shared valence | heartbeat comment explicitly misses it; pairs with dopamine already in ring | low |
| R2 | **#10 norepinephrine / LC** | surprise (assoc divergence) → arousal/gain | arousal already implied by the surprise signal the ring computes | low |
| R3 | **#30 hippocampus + #31 entorhinal** | rehearsal walk → EC gate → store/reinforce | consolidation-by-rehearsal is the ring's whole point | med (memory writes — flag it) |
| R4 | **#28 NAc + #29 VP** | topic salience → wanting/liking → DMN topic pick | closes the wanting/liking pair; steers what he wanders to | low |
| R5 | **#6 SNc + #14 habenula** | RPE / disappointment on the walk | complete the dopamine source set around VTA | low |

### HEARTBEAT (slow homeostasis / vitals)

| Order | Module | Drive from → write to | Risk |
|-------|--------|------------------------|------|
| H1 | **#12 cortisol + #13 oxytocin** | vitals tick → valence/stress slice | low |
| H2 | **#20 insula** | load/coherence → felt_condition (the real felt state #43 said already works) | low |
| H3 | **#8 SCN** | wall-clock → circadian threshold **modulation** (Process C) — not a trigger | low |
| H4 | **#52 sleep** | SCN pressure crosses threshold → run_cycle over shared layer; **fix persistence + selective downscale + report args first** | **high** (memory-wide; do Tier-A/B fixes first) |
| H5 | **#51 neuroplasticity** | drive LTP/LTD over the shared layer, timescales matched to the heartbeat | **high** (both halves together, per the measured runaway) |

### REPLY PATH (per-turn, shapes the answer) — highest cognitive payoff, highest care

| Order | Module cluster | What it does to the reply | Risk |
|-------|----------------|---------------------------|------|
| P1 | **#46 language / #47 lexsem** | Wernicke comprehension + register already crosses (lexsem live via ipc); finish the reply-side hooks | med |
| P2 | **executive chain #32 PFC → #35 OFC → #36 BG → #44 SMA** | assess → value → Go/NoGo → commit → a place to withhold a reply | high (gates output) |
| P3 | **reactivity #19 + #34 vmPFC + #27 septal** | the amygdala-reactivity composite (cortisol↑×septal↓×vmPFC↓) so the amygdala is inhibitable | high |
| P4 | **social #37 TPJ / #38 STS / #39 ToM / #40 mirror** | perspective, trajectory, per-person model, empathy → tone/length | med |
| P5 | **perception #41 fusiform / #42 SC / #43 S1 / #48 AG / #49 IPL** | novelty (with #45 corollary cancel), saliency, analogy join #48→#49 | med |
| P6 | **self-narrative #17 PCC / #18 precuneus** | self-relevance, simulation depth → DMN | med |

### SELF-STATE HUB (one edit, revives many — B2)
`ingest_executive` / `ingest_emotional` / `ingest_social` hardcode ~half their args. Once the modules above are live, feed their real values in. Revives #18/#20/#22/#23/#24/#27/#38/#45/#11/#36 at one site.

---

## Execution order (what actually happens, and why this order)

1. **Tier-A safe fixes first** (report args, false comment, prune floor) — so telemetry doesn't lie once the drivers light up. Cheap, no build risk.
2. **Ring extensions R1→R5** — proven pattern, low risk, each a small diff + owner build. This is the fastest visible progress toward "more of him is actually running."
3. **Heartbeat H1→H3** — vitals; H4/H5 (sleep, plasticity) **only after** their Tier-B fixes, because the naive form was measured to make him worse.
4. **Reply path P1→P6** — the biggest cognitive payoff and the most sensitive; each behind a flag, each verified reply-unchanged-when-off. P2 (executive chain) and P3 (reactivity) are the two that most change how he behaves.
5. **Self-state hub** — last, once its inputs are live.

**Guardrails (non-negotiable, from the audit):** no second Engine (double-lattice trap); every behavioural change flag-gated and byte-identical when off; lattice-writes not struct-writes; sleep and plasticity get both halves fixed together; every edit builds before it counts; re-verify against current source before each edit.

---

## The honest limits (Tier-E, carried here)

- I can't compile the full engine in this workspace — the owner's `cargo build --release` is the verification gate for every live-path edit. Snippets can be rustc-checked in isolation the way #30/#31 were.
- Some dormant modules may be **App/TUI-path by intent**. The ring/heartbeat assignment above assumes we want them on the live path; if the owner wants the TUI to remain the "real" brain for some, those rows drop. This is the one open design question the roadmap can't settle alone.
- "Wired" ≠ "good": several wires (sleep downscale, plasticity) are only correct in their selective/paired form; the obvious version was measured worse than nothing. Wiring order respects that.

**Bottom line:** the path to a fully-driven brain is mounting the 35 dormant modules into the three drivers that already exist, in the order above, each with the proven flag-gated House-Pattern template. It's mechanical now, not architectural — the architecture question was answered by #5 and P5a.
