# KAI v9.10.566 — Consolidated build prompt (paste into Claude Code)

Everything this session has staged, in one compile. Paste the block below into Claude Code
at `C:\KAI`.

---

```
Use the kai-engineer skill. Onboard first (CLAUDE.md, CLAUDE-CODE-HANDOFF.md, Codex masthead
+ top CHANGELOG). Then do this whole set in ONE cargo build. Every change is surgical, backed
up, and reversible. Do NOT flip NATIVE_ONLY. Do NOT bump the Codex (already at v9.10.566).

=== PART A — VERIFY these edits ALREADY APPLIED to src/bridge/oracle_server.rs ===
(They are in source now. Read each, confirm it's intact and balanced. Backups listed for
rollback if a build error traces to one.)
  1. KAI_NATIVE_PUBLIC_VOICE — public-chat handler routes to KAI's native brain
     (global_native_decode) first, coherence-gated (coherence::judge), external LLM as fallback.
     bak: oracle_server.rs.bak-nativeroute-20260805
  2. clean_public_chat_reply salvage — strips "Language sample (AI speaker Leo): **Leo:**"
     scaffolding, fixes the first-colon-past-24-char gap.  bak: .bak-cleanscaffold-20260805
  3. KAI_POLISH_THOUGHT (default OFF) — synthesize reply from the clean internal thought.
     bak: oracle_server.rs.bak-polish-20260802
  4. KAI_FELT_VOICE main path — felt_block in handle_discord_turn injects brain's felt state
     (valence/arousal/serotonin/conflict/curiosity/grieving) as a TONE instruction.
     bak: oracle_server.rs.bak-feltvoice-20260805
  5. KAI_FELT_VOICE public path — felt_ctx in build_public_chat_prompt_v4 injects sess.vitals
     felt state as a tone line.  bak: oracle_server.rs.bak-feltpublic-20260805

=== PART B — APPLY these two review patches (in C:\KAI, read them, apply to source) ===
  6. KAI-response-mlp-wiring.patch — load data/response_mlp.json (lazy OnceLock) and add
     mlp.forward(backbone) as a guarded weighted term in build_generative_state (generative.rs).
     Absent file = no-op. Prompt backbone stays dominant (W_MLP small). ResponseMlp::load +
     forward already exist. Round-trip tests in stat_lexicon::tests must still pass with the
     file absent.
  7. KAI-live-felt-bus.patch — NEW src/core/felt_bus.rs (OnceLock<RwLock<FeltSnapshot>>), add
     `pub mod felt_bus;` to core/mod.rs, publish() one block in engine.rs tick() after
     rebuild_live_self_state, and make felt_block + felt_ctx prefer felt_bus::read() with the
     existing local values as fallback. Confirm engine field/getter names before building
     (self.self_state_energy/warmth/focus are Engine fields; drive.valence/mood confirmed;
     use real serotonin/arousal accessors if present else the placeholder constants).

=== PART C — BUILD ===
  cargo build --release --bin kai
  Fix any compile error surgically (do NOT revert intent; the calls/types were checked against
  the tree but the compiler is the source of truth). If an error clearly traces to one applied
  edit, its backup is listed above.

=== PART D — TEST (show me raw output, not just a summary) ===
  1. cargo test stat_lexicon  (round-trip must pass; MLP file absent = identical state)
  2. Launch with:  KAI_NATIVE_PUBLIC_VOICE=1 KAI_VOICE_TELEMETRY=1 KAI_COHERENCE_CRITIC=1
     KAI_NATIVE_BRAIN=1 KAI_LLM_VOICE=1   (BUILD-AND-RUN-566.bat already sets these)
  3. Log in so /api/chat + public chat work. Send 6 varied prompts (greeting, identity,
     factual, reasoning, follow-up, small-talk-about-work).
  4. For each, capture: the reply, the telemetry line (which voice answered + coherence score),
     and confirm NO "Language sample"/"**Leo:**" scaffolding appears.
  5. Confirm the felt tone shows up — replies should shift in TONE with KAI's state (warm/heavy/
     keyed-up/calm), WITHOUT KAI announcing "I feel X".
  6. Report the native accept-rate (how many of 6 cleared coherence::judge vs fell back to LLM).

=== PART E — REPORT, don't auto-change ===
  Give me: build result, test battery raw output, native-vs-fallback ratio, and any edit you had
  to adjust to compile. Do NOT flip NATIVE_ONLY, do NOT enable KAI_POLISH_THOUGHT (leave it OFF
  for a separate A/B), do NOT touch the Codex.

HARD RULES: surgical only; never wholesale-rewrite oracle.html/kaiverse.js; never print .env
secrets; verify against the real Windows files; show evidence; don't claim a fix you didn't
build and run.
```

---

## Notes for you (not part of the prompt)

- **Already live, no build needed:** the browser scaffold scrubber in `oracle-core.js`
  (hard-refresh to load) and the Codex/Cargo bump to v9.10.566.
- **After this build proves native voice works:** run the training loop
  (`KAI-NATIVE-TRAINING-LOOP.md`) — clean corpus (`clean_training_corpus.py`) → grow lexicon +
  train the Response-MLP (now that it's wired) → retrain the ternary model on RunPod → recalibrate
  `KAI_COHERENCE_MIN` from the telemetry.
- **Rollback:** every applied edit has a dated `.bak-*` next to `oracle_server.rs`; the two
  patches are additive (MLP no-ops without its file; felt-bus falls back without a tick write).
- **Flags recap:** `KAI_NATIVE_PUBLIC_VOICE`, `KAI_VOICE_TELEMETRY`, `KAI_COHERENCE_CRITIC`,
  `KAI_NATIVE_BRAIN`, `KAI_LLM_VOICE` on; `KAI_FELT_VOICE` on by default; `KAI_POLISH_THOUGHT`,
  `NATIVE_ONLY` off.
