immune-brain 5.0.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +223 -12
  2. package/README.zh-CN.md +228 -11
  3. package/package.json +2 -1
  4. package/plugins/immune-brain/.claude-plugin/plugin.json +1 -1
  5. package/plugins/immune-brain/.pi-extension/imm-canary-work.ts +18 -5
  6. package/plugins/immune-brain/.pi-extension/imm-unattended-batch.ts +189 -3
  7. package/plugins/immune-brain/.pi-extension/pi-canary-assurance-progression.ts +66 -3
  8. package/plugins/immune-brain/agents/immune-brain-reviewer.md +11 -1
  9. package/plugins/immune-brain/dist/claude/mcp-server.mjs +1885 -149
  10. package/plugins/immune-brain/dist/docs/reference/immune-brain-config.md +27 -0
  11. package/plugins/immune-brain/dist/docs/reference/subagent-dispatch-protocol.md +8 -6
  12. package/plugins/immune-brain/dist/imm-planner.md +4 -1
  13. package/plugins/immune-brain/dist/imm-run.md +198 -3
  14. package/plugins/immune-brain/dist/role-prompts/code-review.md +10 -0
  15. package/plugins/immune-brain/dist/role-prompts/lane-steward.md +44 -0
  16. package/plugins/immune-brain/runtime/assurance/coordinator.ts +22 -4
  17. package/plugins/immune-brain/runtime/assurance/review_mediation.ts +107 -0
  18. package/plugins/immune-brain/runtime/assurance/verdict_authority.ts +3 -0
  19. package/plugins/immune-brain/runtime/claude/interaction.ts +16 -0
  20. package/plugins/immune-brain/runtime/claude/kernel_ports.ts +105 -58
  21. package/plugins/immune-brain/runtime/claude/mcp_server.ts +89 -16
  22. package/plugins/immune-brain/runtime/claude/role_agents.ts +4 -3
  23. package/plugins/immune-brain/runtime/kernel/assurance_projection.ts +4 -1
  24. package/plugins/immune-brain/runtime/kernel/canary_application.ts +9 -2
  25. package/plugins/immune-brain/runtime/kernel/completion.ts +24 -1
  26. package/plugins/immune-brain/runtime/kernel/reducer.ts +15 -2
  27. package/plugins/immune-brain/runtime/kernel/spec_binding.ts +6 -0
  28. package/plugins/immune-brain/runtime/kernel/storage.ts +20 -4
  29. package/plugins/immune-brain/runtime/kernel/storage_paths.ts +33 -3
  30. package/plugins/immune-brain/runtime/kernel/types.ts +7 -0
  31. package/plugins/immune-brain/runtime/kernel/validation.ts +13 -2
  32. package/plugins/immune-brain/runtime/local_initiative.ts +94 -0
  33. package/plugins/immune-brain/runtime/loop_contract.ts +55 -2
  34. package/plugins/immune-brain/runtime/plugin_version.ts +1 -1
  35. package/plugins/immune-brain/runtime/prompts/code-review.md +10 -0
  36. package/plugins/immune-brain/runtime/prompts/lane-steward.md +44 -0
  37. package/plugins/immune-brain/runtime/role_prompt_bridge.ts +16 -3
  38. package/plugins/immune-brain/runtime/unattended/batch_disposition.ts +222 -0
  39. package/plugins/immune-brain/runtime/unattended/batch_integration.ts +387 -0
  40. package/plugins/immune-brain/runtime/unattended/batch_kernel_port.ts +2 -2
  41. package/plugins/immune-brain/runtime/unattended/batch_lanes.ts +946 -0
  42. package/plugins/immune-brain/runtime/unattended/batch_plan.ts +36 -11
  43. package/plugins/immune-brain/runtime/unattended/batch_preflight.ts +48 -33
  44. package/plugins/immune-brain/runtime/unattended/batch_reasons.ts +13 -1
  45. package/plugins/immune-brain/runtime/unattended/batch_runner.ts +22 -1
  46. package/plugins/immune-brain/runtime/unattended/batch_schedule.ts +162 -0
  47. package/plugins/immune-brain/runtime/unattended/batch_state.ts +398 -12
  48. package/plugins/immune-brain/runtime/unattended/types.ts +21 -2
  49. package/plugins/immune-brain/skills/imm-run/SKILL.md +4 -0
package/README.md CHANGED
@@ -14,7 +14,7 @@ Immune-Brain brings a structured engineering workflow to AI coding assistants (*
14
14
  - **Explicit trigger when rigor matters** — When you want engineering discipline, invoke `imm-brainstorm`, `imm-planner`, or `imm-run`.
15
15
  - **Plans become trackable tasks** (`TaskIntent` + `TaskRecord`) — Progress lives on disk (Git + `.imm/`), surviving restarts and context wipes.
16
16
  - **Quality is enforced by code, not promises** — Automated QA and isolated review subagents must pass before a task can complete.
17
- - **Ready Initiatives can run as a batch** — One confirmed batch authorization lets `imm-run` work through a published Initiative's children serially, while every child is still enrolled, QA'd, reviewed, and settled on its own.
17
+ - **Ready Initiatives can run as a batch (serial or parallel lanes)** — One confirmed batch authorization lets the batch advance published children without manual handoffs per task; supports default serial progression or opt-in parallel lanes (Git worktree physical isolation, scope-disjoint scheduling, and integration verification guards), while every child is still enrolled, QA'd, reviewed, and settled on its own.
18
18
 
19
19
  Pi and Claude Code are the supported hosts. Undeclared adapters remain unsupported. Minimum Claude Code is `2.1.236`, the lowest version verified with interactive server-initiated MCP elicitation. Current real-Host evidence is recorded in [Claude native elicitation conformance](docs/verification/claude-native-elicitation-authority-conformance.md); historical reports remain under [docs/verification/archive/](docs/verification/archive/). Either host can use the model provider you configure — Immune-Brain works on top of Kernel authority, not a vendor chat.
20
20
 
@@ -25,6 +25,8 @@ Pi and Claude Code are the supported hosts. Undeclared adapters remain unsupport
25
25
  - [Installation](#installation)
26
26
  - [Quick Start](#quick-start)
27
27
  - [How to Use](#how-to-use)
28
+ - [Recommended Workflows: Composing with mattpocock/skills](#recommended-workflows-composing-with-mattpocockskills)
29
+ - [Real-World Case Studies](#real-world-case-studies)
28
30
  - [Core Philosophy: Turn "Judgment" into "Table Lookup"](#core-philosophy-turn-judgment-into-table-lookup-harnessing-multi-model-tiers-with-determinism)
29
31
  - [The 7 Skills](#the-7-skills)
30
32
  - [Lifecycle](#lifecycle)
@@ -84,7 +86,7 @@ mise run check-dist-sync # verify generated docs are in sync
84
86
  Immune-Brain follows a **Skill-explicit** model: ordinary conversation is just standard, lightweight AI coding. The managed workflow activates **only when you explicitly invoke a skill**.
85
87
 
86
88
  **1. Call a skill when you need structured engineering**:
87
- - Fuzzy idea that needs scoping? Run `/imm-brainstorm` (or ask the agent to use `imm-brainstorm`).
89
+ - Fuzzy idea, ambiguous design, or high-stakes feature? Run `/grill-me` (from `mattpocock/skills`, recommended) for relentless Socratic design interrogation (or use built-in `/imm-brainstorm` for lightweight framing).
88
90
  - Ready to design and build? Run `/imm-planner` (or ask the agent to use `imm-planner`).
89
91
 
90
92
  *(Ordinary questions like "What does this function do?" or "Fix this typo" stay host-native — zero workflow ceremony.)*
@@ -112,11 +114,11 @@ Immune-Brain provides two clean modes: **Host-native** for daily coding, and **M
112
114
  | Your situation | What to say / do | What happens |
113
115
  |---|---|---|
114
116
  | Daily coding, quick fix, general Q&A | Normal conversation ("Fix typo in README", "Explain this function") | **Host-native**: Standard Pi / Claude Code behavior. Zero workflow overhead. |
115
- | Fuzzy idea, needs scoping & risk analysis | `/imm-brainstorm` "Help me think through webhook support" | → `imm-brainstorm` frames requirements, constraints, and risks (read-only, no code edits) |
117
+ | Fuzzy idea, needs architectural stress-testing & scoping | `/grill-me` (recommended) or `/imm-brainstorm` | → `/grill-me` interviews you through the design tree to lock decisions; `/imm-brainstorm` provides built-in read-only problem framing |
116
118
  | Clear goal, want formal plan & specs | `/imm-planner` "Plan the webhook feature" | → `imm-planner` writes `TaskIntent` + Specs with testable acceptance checks |
117
119
  | Plan confirmed, ready to build & verify | `/imm-run` | → Executor builds within scope → deterministic QA verifies → isolated Review checks → task settles |
118
120
  | Session interrupted or resuming a task | `/imm-run` | → Resumes existing task seamlessly from on-disk state (`.imm/`) |
119
- | Ready Initiative to run unattended | "Run initiative `<slug>` unattended" | → Host's `start_unattended_batch`: one native confirmation covers ordered plan digest, children run serially |
121
+ | Ready Initiative to run unattended (serial or parallel lanes) | "Run initiative `<slug>` unattended" (optionally with `--max-parallel 4` or `Lane max parallel`) | → Host's `start_unattended_batch`: one native confirmation binds the plan digest. Runs serially by default, or opt-in parallel Git worktree lanes with `max_parallel` |
120
122
  | Cross-host workflow (Claude plan + Pi code) | Run `/imm-planner` in Claude Code, switch to Pi and run `/imm-run` | → Staged Spec & TaskIntent are shared on disk; Pi confirms via native TUI and executes loop |
121
123
  | PR has review comments or failing CI | `/imm-pr-fix` on that PR | → Standalone repair: minimal scoped fix in place, no managed task created |
122
124
  | Project docs out of date | `/imm-doc-prune` | → Read-only audit; deletes only user-approved stale docs from manifest |
@@ -125,7 +127,7 @@ Immune-Brain provides two clean modes: **Host-native** for daily coding, and **M
125
127
 
126
128
  > **Core Principle: Skill-Explicit Entry**
127
129
  > - **Ordinary input stays host-native**: Natural language queries never automatically start planning or task enrollment. You choose when to turn on engineering rigor.
128
- > - **Managed work starts with explicit skills**: Use `imm-brainstorm` to clarify, `imm-planner` to plan, and `imm-run` to execute and resume.
130
+ > - **Managed work starts with explicit skills**: Use `/grill-me` (or `imm-brainstorm`) to clarify decisions, `imm-planner` to plan, and `imm-run` to execute and resume.
129
131
 
130
132
  ### Cross-Host Workflow: Plan in Claude Code, Build in Pi
131
133
 
@@ -163,6 +165,146 @@ This enables a best-of-both-worlds workflow: **leverage Claude Code's deep reaso
163
165
 
164
166
  ---
165
167
 
168
+ ## Recommended Workflows: Composing with mattpocock/skills
169
+
170
+ While Immune-Brain provides deterministic execution and quality enforcement once work begins, engineering failures frequently originate upstream: **models jump into code before the design tree is fully explored, trade-offs are evaluated, and edge cases are surfaced.**
171
+
172
+ To prevent premature implementation and scope churn, the recommended best-practice workflow combines **`mattpocock/skills`** (by Matt Pocock) upstream with **Immune-Brain** downstream:
173
+
174
+ > **The Dual-Engine Thesis**
175
+ > - **Upstream Socratic Friction (`grill-me`)**: Deliberately slows down thinking. The AI acts as a relentless interviewer, forcing explicit decisions on every branch of the design tree before any code or spec is committed.
176
+ > - **Downstream Deterministic Rigor (`imm-planner` + `imm-run`)**: Translates those decisions into tamper-proof machine contracts (`TaskIntent` + living Spec), enforces native human enrollment, freezes editable file boundaries, and verifies code via sandboxed child processes and isolated reviewer subagents.
177
+
178
+ ```text
179
+ ┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐
180
+ │ 1. Upstream Socratic Alignment (mattpocock/skills /grill-me) │
181
+ │ Role: Relentlessly interview developer down every branch of the design tree; resolve trade-offs │
182
+ └───────────────────────────────────────────────────┬────────────────────────────────────────────────────┘
183
+ │ Settled decisions & architectural consensus
184
+ ▼
185
+ ┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐
186
+ │ 2. Formal Machine Contracts (Immune-Brain /imm-planner) │
187
+ │ Role: Author living Spec & TaskIntent (.intent.json); lock scope_hint and VerificationDescriptor v2 │
188
+ └───────────────────────────────────────────────────┬────────────────────────────────────────────────────┘
189
+ │ Git-tracked contract artifacts
190
+ ▼
191
+ ┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐
192
+ │ 3. Literal Human Authority Gate (Native Host Enrollment) │
193
+ │ Role: Developer confirms scope in native TUI / MCP dialog; Kernel captures baseline & acquires CAS lock │
194
+ └───────────────────────────────────────────────────┬────────────────────────────────────────────────────┘
195
+ │ Exclusive workspace lease
196
+ ▼
197
+ ┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐
198
+ │ 4. Deterministic Assurance & Settlement (Immune-Brain /imm-run) │
199
+ │ Role: Scope-frozen Executor -> Sandboxed QA (bun test) -> Isolated Subagent Review -> CAS Settlement │
200
+ └────────────────────────────────────────────────────────────────────────────────────────────────────────┘
201
+ ```
202
+
203
+ ### Why Use `grill-me` Instead of `imm-brainstorm` for Decision Confirmation
204
+
205
+ Immune-Brain includes a built-in `imm-brainstorm` skill, but for non-trivial features, architectural pivots, and security-sensitive boundaries, **`/grill-me` is the recommended choice**:
206
+
207
+ | Dimension | Built-in `imm-brainstorm` | Upstream `/grill-me` (`mattpocock/skills`) | Recommended Synergy |
208
+ |---|---|---|---|
209
+ | **Ecosystem & Setup** | Built into Immune-Brain (zero install) | Ecosystem skill from `mattpocock/skills` (`npx skills@latest add mattpocock/skills --skill grill-me`) | Use `/grill-me` as the upstream decision partner; let Immune-Brain handle execution |
210
+ | **Interview Style** | Structured problem framing; batched questions; read-only summary | Relentless, iterative 1-by-1 Socratic grilling; explores every decision branch | `/grill-me` actively challenges developer assumptions and refuses to let ambiguities slide |
211
+ | **Exploration Discipline** | Explores codebase first, surfaces high-level goals & risks | Explores codebase first, proposes opinionated recommended answers for each branch | Eliminates "vibe coding" and locks down architectural consensus before any planning |
212
+ | **Output** | `brainstorm_framing` summary block | Fully resolved decision tree | Directly feed the settled decisions into `/imm-planner` |
213
+ | **Best Fit** | Lightweight scoping, offline setups, or simple tasks | Complex features, architectural refactors, and multi-service designs | **Recommended standard** for production engineering |
214
+
215
+ ### Setup & Installation
216
+
217
+ Install `grill-me` into your project or global agent environment using the official Skills installer:
218
+
219
+ ```bash
220
+ # Add grill-me from mattpocock/skills
221
+ npx skills@latest add mattpocock/skills --skill grill-me
222
+
223
+ # Or install the full suite
224
+ npx skills@latest add mattpocock/skills
225
+ ```
226
+
227
+ ### End-to-End Workflow: `grill-me` → `imm-planner` → `imm-run`
228
+
229
+ 1. **Step 1: Grill the Design (`/grill-me`)**
230
+ - Run `/grill-me "Add Webhook Dispatcher with retry and replay protection"`.
231
+ - The agent reads existing codebase patterns first, then interviews you across the decision tree (storage choices, idempotency strategy, backoff policies, failure modes), presenting a recommended answer for each step.
232
+ - Continue until all branches are resolved: *"Decision tree complete. Ready to plan."*
233
+ 2. **Step 2: Formalize the Plan (`/imm-planner`)**
234
+ - Run `/imm-planner "Plan the webhook dispatcher using the decisions settled in grill-me"`.
235
+ - `imm-planner` consumes the resolved choices and generates:
236
+ - **Living Spec** (`docs/specs/webhook-dispatcher.spec.md`): Pinned code coordinates, trade-offs, and negative boundaries.
237
+ - **TaskIntent** (`docs/plans/webhook-dispatcher.intent.json`): Strict `scope_hint`, risk tier (`material`), and machine-executable `VerificationDescriptor v2` checks.
238
+ 3. **Step 3: Confirm Enrollment (Native Host Gate)**
239
+ - Stage artifacts in Git (`git add docs/`).
240
+ - Run `/imm-run`. The native confirmation dialog opens (Pi TUI modal / Claude Code MCP elicitation).
241
+ - Once confirmed, Kernel atomically captures repository baseline state (`enrollment-baseline.json`) and acquires an exclusive SQLite CAS lock.
242
+ 4. **Step 4: Execute & Verify (`/imm-run`)**
243
+ - **Executor**: Edits code strictly within `scope_hint`. Physical scope escapes fail closed.
244
+ - **Deterministic QA**: Kernel executes acceptance tests (`bun test`) in a sandboxed child process, verifying authentic exit codes.
245
+ - **Isolated Review**: For `material` or `critical` tasks, a separate review subagent audits immutable Git blobs against Devil's Advocate invariants.
246
+ - **Settlement**: Kernel records tamper-proof attestations in `.imm/audit/<task-id>/` and releases the workspace lease.
247
+
248
+ ---
249
+
250
+ ## Real-World Case Studies
251
+
252
+ ### Case Study 1: Greenfield Feature Development — Multi-Tenant Webhook Dispatcher
253
+
254
+ - **Goal**: Implement a production-grade webhook dispatch system with HMAC signature verification, exponential backoff with jitter, and replay attack prevention.
255
+ - **Problem without this pipeline**: An AI agent typically starts writing files immediately, pulls in arbitrary dependencies, forgets timestamp replay bounds, leaks in-memory timers, and claims "implementation complete" without verifying HTTP timeout handling.
256
+ - **Workflow**:
257
+ 1. **Socratic Grilling (`/grill-me`)**:
258
+ - *Question 1 (Persistence)*: SQLite vs external queue? *Recommendation*: Store pending dispatches in the existing SQLite CAS table to avoid external infrastructure overhead.
259
+ - *Question 2 (Security)*: How to prevent replay attacks? *Recommendation*: Require an `X-Webhook-Timestamp` header with a 5-minute clock-skew tolerance window and HMAC-SHA256 signature.
260
+ - *Question 3 (Resilience)*: What is the backoff curve and timeout? *Recommendation*: Exponential backoff with full jitter up to 5 attempts, with a hard 10s timeout via `AbortController`.
261
+ - *Result*: All trade-offs explicitly confirmed in 3 minutes of dialogue.
262
+ 2. **Machine Contract Formulation (`/imm-planner`)**:
263
+ - Planner writes `docs/specs/webhook-dispatcher.spec.md` with explicit Negative Scope (files in `src/auth/` and `src/billing/` are forbidden).
264
+ - Generates `docs/plans/task-webhook-dispatcher.intent.json` with risk `material` and `VerificationDescriptor v2` running `bun test tests/webhook-dispatcher.test.ts`.
265
+ 3. **Native Gate Enrollment**:
266
+ - Developer inspects Git diff and confirms via Pi TUI dialog / Claude Code MCP elicitation.
267
+ 4. **Execution, QA & Review (`/imm-run`)**:
268
+ - Executor writes implementation strictly within `scope_hint`.
269
+ - Deterministic QA executes `bun test tests/webhook-dispatcher.test.ts`. Kernel verifies exit code `0`.
270
+ - Isolated Reviewer subagent inspects the Git blob `ReviewBundle`, confirming no out-of-scope edits and verifying error invariants.
271
+ - Kernel settles terminal proof into `.imm/audit/<task-id>/`.
272
+
273
+ ### Case Study 2: Critical Architectural Refactoring — CAS Storage Migration (v1 → v2)
274
+
275
+ - **Goal**: Migrate the persistence layer from legacy JSON files to an atomic SQLite CAS engine while maintaining zero-downtime rollback and legacy read-only audit inspection.
276
+ - **Problem without this pipeline**: Agents performing low-level database refactoring frequently introduce silent schema corruption, delete legacy fallback paths, and pass tests by weakening assertions.
277
+ - **Workflow**:
278
+ 1. **Socratic Grilling (`/grill-me`)**:
279
+ - *Interrogation*: "What happens to active v1 tasks during migration? Recommendation: Enforce a strict drain check (`drain_required`); refuse dual-write and abort if an active v1 task is in progress."
280
+ - *Interrogation*: "How is WAL corruption prevented during rollback? Recommendation: Use single-file transactions with OS-level file locking and immutable Git snapshots."
281
+ 2. **Planning with Enforcement Floors (`/imm-planner`)**:
282
+ - Because `runtime/kernel/storage.ts` is in `scope_hint`, Kernel automatically clamps the risk tier floor to `critical`.
283
+ - Planner pins code coordinates (`storage.ts:120`) and binds verification commands including legacy migration fixtures.
284
+ 3. **Native Enrollment**: Developer verifies the `critical` risk tier and baseline snapshot in the native host dialog.
285
+ 4. **Deterministic QA & Review (`/imm-run`)**:
286
+ - Real process verification runs the full regression test suite with authentic legacy fixtures.
287
+ - Isolated Subagent Devil's Advocate audit executes an adversarial review over immutable Git blobs, checking backward compatibility.
288
+ - Atomic settlement writes tamper-proof audit records.
289
+
290
+ ### Case Study 3: Cross-Host Collaborative Teamwork — Claude Code (Grill + Plan) + Pi (Run + QA)
291
+
292
+ - **Goal**: Maximize reasoning intelligence for architectural design while minimizing token expenditure and maximizing speed for mechanical code execution.
293
+ - **Workflow**:
294
+ 1. **Phase 1 in Claude Code (Desktop)**:
295
+ - Run `/grill-me` (from `mattpocock/skills`) to stress-test architecture with Claude's flagship reasoning model.
296
+ - Run `/imm-planner` to author line-pinned Living Specs and `TaskIntent` contracts.
297
+ - Stage artifacts (`git add docs/ && git commit -m "docs: webhook spec and plan"`).
298
+ 2. **Phase 2 in Pi (Terminal / Remote Server)**:
299
+ - Open Pi in the same repository workspace.
300
+ - Enter `/imm-run`. Pi detects the Git-staged `TaskIntent` and opens its native TUI modal for enrollment.
301
+ - Pi's Executor writes code using a cost-effective, high-throughput model (Fast/Mid Tier).
302
+ - Deterministic QA runs locally via `bun test`.
303
+ - Review passes and Kernel closes the task.
304
+ 3. **Result**: Zero context loss across hosts, full session-neutral state continuity, and ~60-70% savings on flagship reasoning tokens.
305
+
306
+ ---
307
+
166
308
  ## Core Philosophy: Turn "Judgment" into "Table Lookup", Harnessing Multi-Model Tiers with Determinism
167
309
 
168
310
  Large language models—especially lightweight, cost-effective Fast Tier models—fail in real-world software engineering not because of syntax, but because of **semantic ambiguity, scope creep, and evasive verification**.
@@ -392,7 +534,7 @@ flowchart TD
392
534
  - **Risk-Tiered Gates with Enforcement Floors**: `routine` tasks complete upon QA pass; `material` and `critical` tasks require an isolated Review subagent. Touching kernel or authority paths is forced to at least `material`.
393
535
  - **Live Refutation**: Subjective Review findings can be refuted by fresh, passing QA evidence; any new edits invalidate counterevidence and re-block the finding.
394
536
  - **Immutable Audit Trail**: Terminal task completion atomically writes signed `TaskRecord`s, Git blob `ReviewBundle`s, and QA Attestations to `.imm/audit/<task-id>/`, fully tracked in Git.
395
- - **Unattended Batch**: Serial execution driven by GitHub Issues and bound by `plan_digest`, where each child independently completes its own Enrollment → QA → Review → Commit cycle.
537
+ - **Unattended Batch & Parallel Lanes**: Progresses via GitHub Issues bound by `plan_digest`. Supports default single-branch serial execution or physical multi-Lane parallel execution; in lane mode, the Coordinator schedules scope-disjoint Git worktrees, and Integration Guard reruns deterministic descriptors on candidate commits before fast-forwarding the batch branch, preventing concurrency contamination.
396
538
 
397
539
  Key invariants:
398
540
 
@@ -407,13 +549,70 @@ Key invariants:
407
549
 
408
550
  ## Unattended Batch Runs
409
551
 
410
- When an Initiative has several ready children, you can run them as one serial batch instead of task by task.
552
+ When an Initiative contains multiple ready children, developers can run the entire batch unattended via the Host's privileged `start_unattended_batch` tool without manually driving `imm-run` for each child task.
553
+
554
+ Immune-Brain supports two batch execution modes: **Default Serial Mode** and **Parallel Batch Lanes**.
555
+
556
+ ### 1. Batch Execution Modes Overview
557
+
558
+ | Dimension | Serial Batch (Default) | Parallel Batch Lanes |
559
+ |---|---|---|
560
+ | **Activation** | Call `start_unattended_batch(slug)` directly | Pass `max_parallel` or configure `Lane max parallel: <n>` |
561
+ | **Workspace Topology** | Shared single batch branch (`imm-batch/<slug>`) | Coordinator manages batch branch; each concurrent task owns a Git worktree (`imm-lane/<task-id>`) |
562
+ | **Scheduling** | Strict sequential execution ordered by dependency layers | Scope-disjoint children execute concurrently in parallel Lanes |
563
+ | **Authority Boundaries** | Single local Authority Store advanced sequentially | Each Lane owns its own local Authority Store, running isolated with zero global CAS contention |
564
+ | **Integration** | Direct commit on batch branch after task QA/Review passes | Reconciles via Git plumbing, reruns Integration Guard descriptors, then fast-forwards batch branch |
565
+ | **Ideal For** | Small initiatives, tight file coupling, resource-constrained environments | Medium/large initiatives, decoupled modules, high-compute environments |
566
+
567
+ ### 2. Batch Authority & Invariants
568
+
569
+ - **Explicit Entry & Single Authorization:** No batch state or branch exists before calling `start_unattended_batch`; without it, `imm-run` behaves identically to single-task enrollment. The native gate (Pi TUI dialog or Claude MCP elicitation) displays the ordered child list and global `plan_digest`; this single user confirmation constitutes complete Batch Authorization.
570
+ - **Child Authority Invariance:** A batch merely bundles authorization scope without weakening engineering rigor. Every child is still individually enrolled, scope-frozen, QA-verified via authentic child processes, reviewed in isolation, and settled with its own `TaskRecord`. A batch is a scope of authorization, not a new authority layer.
571
+ - **Deterministic Boundaries:** Only runs published, non-`critical` children. Any required human decision (`needs_human`), budget/timeout interruption, or integration error halts the batch safely, marking dependent children as `skipped_blocked` rather than reordering. Runners never push, open PRs, or make arbitrary decisions.
572
+
573
+ ### 3. Parallel Batch Lanes Lifecycle & Architecture
574
+
575
+ In parallel lane mode, the Coordinator (Parent Host), `lane-steward` internal role, and Lane Executor Hosts coordinate to provide physical concurrency isolation:
576
+
577
+ ```mermaid
578
+ sequenceDiagram
579
+ participant P as Coordinator (Parent Host)
580
+ participant B as Batch Runtime
581
+ participant S as lane-steward Role
582
+ participant L as Lane Executor Host (Pi / Claude)
583
+ participant K as Lane Kernel (Isolated Store)
584
+
585
+ Note over P,B: 1. Scheduling & Scope-Disjoint Analysis
586
+ P->>B: start_unattended_batch(slug, max_parallel)
587
+ B-->>P: handoffs: provision Lane A, Lane B
588
+
589
+ Note over P,S: 2. Physical Worktree Provisioning (Provision & Admit)
590
+ P->>S: Provision worktree (branch imm-lane/..., base batch base)
591
+ S-->>P: Return isolated worktree paths
592
+ P->>B: Submit lane_offers admission check (cleanliness, branch, base)
593
+
594
+ Note over P,L: 3. Supervised Parallel Execution
595
+ B-->>P: handoffs: launch Executor A, Executor B
596
+ P->>L: Launch background session for imm-run (configurable Host/model)
597
+ L->>K: Run loop: Scope freeze -> Deterministic QA -> Review -> Settle
598
+
599
+ Note over P,B: 4. Integration Guard & Fast-Forward
600
+ L-->>P: Lane finish notification
601
+ P->>B: Coordinator reconcile tick
602
+ B->>K: Read Lane evidence & commit
603
+ B->>B: Build candidate commit + rerun Integration Guard descriptors
604
+ B->>B: Fast-forward batch branch (1 child 1 commit)
605
+ B-->>P: handoffs: release Lane A / provision Lane C
606
+ ```
607
+
608
+ #### Core Mechanisms:
609
+
610
+ 1. **Scope-Disjoint Scheduling:** The Coordinator dynamically computes dependency layers and path overlap. A child is scheduled only when its prerequisites are integrated and its `scope_hint` is provably disjoint from all in-flight Lanes. Overlapping children wait until conflicting Lanes integrate.
611
+ 2. **Supervised Host Sessions:** The Parent Host launches an independent Executor Host process for each Lane (configurable across Hosts, models, and effort tiers, such as Pi or Claude Code). The Parent is reactively notified on session completion, polling nothing. When running inside Herdr, it opens one tab per Lane and never answers trust/login dialogs on behalf of the user.
612
+ 3. **Integration Guard:** To eliminate silent semantic conflicts, settled deliveries are not blindly merged. The Coordinator constructs candidate commits via Git plumbing and reruns deterministic descriptors for both the candidate child and all sibling tasks integrated since the lane's base. Fast-forward proceeds only if all tests pass.
613
+ 4. **Fault Isolation:** If a Lane encounters a QA failure, review rejection, or integration conflict, the batch branch stays untouched (zero-write). The failing child is parked as `needs_human`, its dependents are marked `skipped_blocked`, while independent sibling Lanes proceed unaffected.
614
+ 5. **Agents Only Create:** The Parent and `lane-steward` provision Lanes and terminal tabs but never kill sessions or delete worktrees. Once integrated, the system reports safe-to-release Lanes for the developer to inspect and clean up.
411
615
 
412
- - **Entry is explicit:** the Host's privileged `start_unattended_batch` tool, taking the Initiative slug. Nothing batch-related exists until it is called — without it, `imm-run` behaves exactly like per-task enrollment and creates no batch state, branch, or authorization.
413
- - **One confirmation, one digest:** the native gate (Pi TUI dialog or Claude MCP elicitation) shows the ordered child list and the shared plan digest; that single literal-user act is the whole Batch Authorization.
414
- - **Per-child authority survives:** every child is still enrolled, frozen, QA'd, reviewed, and settled by the Kernel on its own `TaskRecord`. The batch is the scope of one authorization, never a new authority layer.
415
- - **Closeout is automatic:** when a child reaches `done` in the foreground, the same call commits it and enrolls the next child, or marks the batch `completed`, with no new gate. A parked or stopped child is never committed for you, and a failed continuation is reported beside the result with `start_unattended_batch` as the retry. A fast-forward commit you add to the batch branch is adopted; any other HEAD movement still stops the run.
416
- - **Bounds:** only published, non-`critical` children run, serially on a dedicated batch branch. The run parks when a child needs a human decision or a budget, authorization, or commit failure stops it; the budget is a child count and a QA failure limit, and nothing expires with time, and dependents of a blocked child are skipped rather than reordered. The runner never pushes, opens PRs, resolves user decisions, or creates, switches, or deletes Git worktrees.
417
616
 
418
617
  ---
419
618
 
@@ -425,6 +624,10 @@ Immune-Brain has **no separate config file**. Preferences live in your host's ag
425
624
  ## Immune-Brain Preferences
426
625
 
427
626
  - Initiative carrier default: github # or: local
627
+ - Lane max parallel: 4 # optional; enables lane mode
628
+ - Lane Executor Host: claude-code # optional; or: pi
629
+ - Lane Executor model: <model id> # optional; needs Lane Executor Host
630
+ - Lane Executor effort: high # optional; needs Lane Executor Host
428
631
  ```
429
632
 
430
633
  | Preference | Options | Default | Notes |
@@ -432,6 +635,10 @@ Immune-Brain has **no separate config file**. Preferences live in your host's ag
432
635
  | Reply language | any natural language | repo `AGENTS.md` | Machine contracts / paths stay literal |
433
636
  | Initiative carrier | `local` / `github` | none — Planner asks | Only matters when a proposal splits across multiple TaskIntents |
434
637
  | Advisory subagents | allowed / solo | allowed | Respects Pi host policy + explicit user instruction |
638
+ | Lane max parallel | integer ≥ 1 | none — batches stay serial | Passed as `max_parallel` when a batch starts; a resumed batch keeps its recorded value |
639
+ | Lane Executor Host | `claude-code` / `pi` | none — prefers the Parent's own Host type | Every Lane uses this Host, with no fallback to the other one |
640
+ | Lane Executor model | a model ID of that Host | none — the Executor Host's own default | Applies only when `Lane Executor Host` is set |
641
+ | Lane Executor effort | an effort level of that Host | none — the Executor Host's own default | Applies only when `Lane Executor Host` is set; `--effort` on Claude Code, `--thinking` on Pi |
435
642
 
436
643
  Precedence: **current message > repo agent instruction file > user-level agent instruction file > ask**. Skills read these files directly, so a preference works even when the host does not auto-load that file.
437
644
 
@@ -483,6 +690,10 @@ docs/specs/ # Living specs (updated in place)
483
690
 
484
691
  **Why are preferences kept in AGENTS.md / CLAUDE.md instead of an external config.toml?** Immune-Brain embraces host-native simplicity with zero external configuration files. Declaring preferences (such as Initiative carriers and communication instructions) in tracked agent instruction files ensures that configuration is version-controlled, visible across all collaborators, and free from environment drift.
485
692
 
693
+ **Why do you recommend `grill-me` instead of `imm-brainstorm` for complex tasks?** `imm-brainstorm` is a lightweight, built-in tool designed for quick problem framing without external dependencies. However, `grill-me` (from `mattpocock/skills`) provides an active, relentless Socratic interview that explores every branch of your design tree with opinionated recommendations. For non-trivial features, architectural refactors, or security boundaries, grilling the design with `grill-me` before passing the settled decisions to `imm-planner` produces significantly tighter specifications and prevents downstream rework.
694
+
695
+ **Do I need to install `mattpocock/skills` to use Immune-Brain?** No. Immune-Brain is completely self-contained and functions out of the box with built-in `imm-brainstorm`. Composing with `mattpocock/skills` is an optional, highly recommended power workflow for teams seeking maximal engineering discipline.
696
+
486
697
  **Which AI coding assistants are supported?** Pi and Claude Code are the supported hosts (Claude Code version >= `2.1.236`). Both hosts run on the exact same Kernel authority, assurance guarantees, and multi-skill pipeline.
487
698
 
488
699
  ---