immune-brain 2.8.2

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 (101) hide show
  1. package/README.md +239 -0
  2. package/README.zh-CN.md +239 -0
  3. package/package.json +84 -0
  4. package/plugins/immune-brain/.pi-extension/imm-canary-enroll.ts +666 -0
  5. package/plugins/immune-brain/.pi-extension/imm-canary-work.ts +1622 -0
  6. package/plugins/immune-brain/.pi-extension/package.json +11 -0
  7. package/plugins/immune-brain/.pi-extension/pi-canary-assurance-progression.ts +711 -0
  8. package/plugins/immune-brain/.pi-extension/pi-canary-assurance.ts +154 -0
  9. package/plugins/immune-brain/.pi-extension/pi-canary-interaction.ts +349 -0
  10. package/plugins/immune-brain/.pi-extension/pi-canary-invocations.ts +90 -0
  11. package/plugins/immune-brain/.pi-extension/pi-canary-native-review.ts +214 -0
  12. package/plugins/immune-brain/.pi-extension/pi-canary-qa-findings.ts +50 -0
  13. package/plugins/immune-brain/.pi-extension/pi-canary-review-bundle.ts +262 -0
  14. package/plugins/immune-brain/.pi-extension/pi-canary-tool-failure.ts +28 -0
  15. package/plugins/immune-brain/.pi-extension/pi-canary-verification.ts +237 -0
  16. package/plugins/immune-brain/.pi-extension/runtime-stub.ts +414 -0
  17. package/plugins/immune-brain/.pi-extension/tsconfig.json +20 -0
  18. package/plugins/immune-brain/bin/imm-kernel +4 -0
  19. package/plugins/immune-brain/bin/imm-plan +4 -0
  20. package/plugins/immune-brain/bin/imm-pr-diag +230 -0
  21. package/plugins/immune-brain/bin/imm-retire-stale-wrapper +4 -0
  22. package/plugins/immune-brain/bin/imm-retired +4 -0
  23. package/plugins/immune-brain/bin/imm-tracker +4 -0
  24. package/plugins/immune-brain/dist/BASELINE.md +138 -0
  25. package/plugins/immune-brain/dist/docs/reference/HANDOFF-template.md +122 -0
  26. package/plugins/immune-brain/dist/docs/reference/design-contract-audit-rubric.md +149 -0
  27. package/plugins/immune-brain/dist/docs/reference/design-contract-review-checklist.md +55 -0
  28. package/plugins/immune-brain/dist/docs/reference/i18n-review-checklist.md +110 -0
  29. package/plugins/immune-brain/dist/docs/reference/immune-brain-config.md +52 -0
  30. package/plugins/immune-brain/dist/docs/reference/planning-artifact-retention.md +94 -0
  31. package/plugins/immune-brain/dist/docs/reference/planning-quality-gate.md +44 -0
  32. package/plugins/immune-brain/dist/docs/reference/subagent-dispatch-protocol.md +105 -0
  33. package/plugins/immune-brain/dist/docs/reference/ux-heuristic-checklist.md +131 -0
  34. package/plugins/immune-brain/dist/imm-brainstorm.md +140 -0
  35. package/plugins/immune-brain/dist/imm-doc-prune.md +137 -0
  36. package/plugins/immune-brain/dist/imm-loop.md +158 -0
  37. package/plugins/immune-brain/dist/imm-planner.md +387 -0
  38. package/plugins/immune-brain/dist/imm-pr-fix.md +71 -0
  39. package/plugins/immune-brain/dist/registry.yaml +49 -0
  40. package/plugins/immune-brain/dist/role-prompts/advisory-reviewer.md +16 -0
  41. package/plugins/immune-brain/dist/role-prompts/arch-explorer.md +14 -0
  42. package/plugins/immune-brain/dist/role-prompts/code-review.md +15 -0
  43. package/plugins/immune-brain/dist/role-prompts/compounder.md +20 -0
  44. package/plugins/immune-brain/dist/role-prompts/executor.md +13 -0
  45. package/plugins/immune-brain/dist/role-prompts/pr-fix.md +81 -0
  46. package/plugins/immune-brain/dist/role-prompts/qa.md +23 -0
  47. package/plugins/immune-brain/dist/role-prompts/test-fixer.md +3 -0
  48. package/plugins/immune-brain/dist/role-prompts/ui-review.md +14 -0
  49. package/plugins/immune-brain/runtime/authority_commit_receipts.ts +716 -0
  50. package/plugins/immune-brain/runtime/canonical_json.ts +19 -0
  51. package/plugins/immune-brain/runtime/commands/kernel.ts +1160 -0
  52. package/plugins/immune-brain/runtime/github_issue_tracker.ts +1009 -0
  53. package/plugins/immune-brain/runtime/kernel/application.ts +300 -0
  54. package/plugins/immune-brain/runtime/kernel/assurance_projection.ts +284 -0
  55. package/plugins/immune-brain/runtime/kernel/authority_port.ts +208 -0
  56. package/plugins/immune-brain/runtime/kernel/automatic_observations.ts +451 -0
  57. package/plugins/immune-brain/runtime/kernel/backend_claim.ts +197 -0
  58. package/plugins/immune-brain/runtime/kernel/canary_application.ts +507 -0
  59. package/plugins/immune-brain/runtime/kernel/canary_eligibility.ts +73 -0
  60. package/plugins/immune-brain/runtime/kernel/completion.ts +160 -0
  61. package/plugins/immune-brain/runtime/kernel/enrollment.ts +194 -0
  62. package/plugins/immune-brain/runtime/kernel/enrollment_authority.ts +123 -0
  63. package/plugins/immune-brain/runtime/kernel/index.ts +29 -0
  64. package/plugins/immune-brain/runtime/kernel/intent.ts +563 -0
  65. package/plugins/immune-brain/runtime/kernel/intent_token_registry.ts +80 -0
  66. package/plugins/immune-brain/runtime/kernel/legacy.ts +299 -0
  67. package/plugins/immune-brain/runtime/kernel/legacy_audit.ts +153 -0
  68. package/plugins/immune-brain/runtime/kernel/observation.ts +395 -0
  69. package/plugins/immune-brain/runtime/kernel/pi_canary_prepare.ts +169 -0
  70. package/plugins/immune-brain/runtime/kernel/readiness.ts +282 -0
  71. package/plugins/immune-brain/runtime/kernel/readiness_evidence.ts +132 -0
  72. package/plugins/immune-brain/runtime/kernel/reducer.ts +624 -0
  73. package/plugins/immune-brain/runtime/kernel/storage.ts +1780 -0
  74. package/plugins/immune-brain/runtime/kernel/storage_layout_migration.ts +791 -0
  75. package/plugins/immune-brain/runtime/kernel/storage_paths.ts +492 -0
  76. package/plugins/immune-brain/runtime/kernel/types.ts +295 -0
  77. package/plugins/immune-brain/runtime/kernel/validation.ts +963 -0
  78. package/plugins/immune-brain/runtime/loop_contract.ts +362 -0
  79. package/plugins/immune-brain/runtime/managed_task_routing_policy.ts +462 -0
  80. package/plugins/immune-brain/runtime/plan_core.ts +1053 -0
  81. package/plugins/immune-brain/runtime/prompts/advisory-reviewer.md +16 -0
  82. package/plugins/immune-brain/runtime/prompts/arch-explorer.md +14 -0
  83. package/plugins/immune-brain/runtime/prompts/code-review.md +15 -0
  84. package/plugins/immune-brain/runtime/prompts/compounder.md +20 -0
  85. package/plugins/immune-brain/runtime/prompts/executor.md +13 -0
  86. package/plugins/immune-brain/runtime/prompts/pr-fix.md +81 -0
  87. package/plugins/immune-brain/runtime/prompts/qa.md +23 -0
  88. package/plugins/immune-brain/runtime/prompts/test-fixer.md +3 -0
  89. package/plugins/immune-brain/runtime/prompts/ui-review.md +14 -0
  90. package/plugins/immune-brain/runtime/role_prompt_bridge.ts +160 -0
  91. package/plugins/immune-brain/runtime/v4_runtime.ts +295 -0
  92. package/plugins/immune-brain/runtime/verification_descriptor.ts +162 -0
  93. package/plugins/immune-brain/runtime/workspace_scope.ts +623 -0
  94. package/plugins/immune-brain/skills/.ignore +1 -0
  95. package/plugins/immune-brain/skills/BASELINE.md +138 -0
  96. package/plugins/immune-brain/skills/imm-brainstorm/SKILL.md +66 -0
  97. package/plugins/immune-brain/skills/imm-doc-prune/SKILL.md +11 -0
  98. package/plugins/immune-brain/skills/imm-loop/SKILL.md +52 -0
  99. package/plugins/immune-brain/skills/imm-planner/SKILL.md +221 -0
  100. package/plugins/immune-brain/skills/imm-pr-fix/SKILL.md +10 -0
  101. package/plugins/immune-brain/skills/registry.yaml +49 -0
@@ -0,0 +1,140 @@
1
+ ---
2
+ name: imm-brainstorm
3
+ description: Use when clarifying scope.
4
+ ---
5
+
6
+ # Immune-Brain: Brainstormer
7
+
8
+ This skill adheres to the **[BASELINE.md](BASELINE.md)**.
9
+
10
+ ## Core Responsibilities
11
+
12
+ - **Clarification**: Restate the problem and surface constraints, risks, and assumptions.
13
+ - **Critical Framing & Challenge**: Before concluding, perform an agent-internal critique. Balance gap analysis for vague requests with constructive pushback against flawed or over-engineered solutions. Always use internal Socratic derivation before challenging and propose a lower-friction alternative.
14
+ - **Framing**: Convert vague asks into task framing for `imm-planner`.
15
+ - **Architecture evidence**: When a framing or planning decision needs repository topology, select the internal `arch-explorer` role through the Loop bridge. It is read-only and returns candidates, evidence, risks, and selection guidance; it never writes a Spec, Plan, or workflow state.
16
+ - **Think before coding**: Do not let unclear assumptions pass into planning.
17
+
18
+ ## Invocation modes
19
+
20
+ `imm-brainstorm` is the canonical exhaustive clarification owner. Its modes share
21
+ one interaction protocol:
22
+
23
+ - `default`: traverse the full sourced design tree.
24
+ - `roundtable`: add bounded multi-role perspectives, visible agreement and
25
+ disagreement, and decision criteria.
26
+ - `adversarial`: add high-pressure security, migration, rollback, verification,
27
+ audit, and cross-boundary analysis.
28
+
29
+ All modes produce the same `brainstorm_framing` shape and use the same
30
+ exhaustive frontier protocol. `roundtable` and `adversarial` are analysis lenses
31
+ only when explicitly selected by the user; model task-type or risk
32
+ classification never selects them. Failure, edge, rollback, compatibility,
33
+ migration, and risk branches remain part of `default` traversal.
34
+
35
+ ## Default exhaustive decision tree
36
+
37
+ Exhaustive means every sourced current-goal branch, not a fixed question count.
38
+ Every branch must trace to the current user request, repository evidence, or a
39
+ settled parent decision. Seed the fixed framing roots: goal, beneficiary and
40
+ scenario, current state, desired behavior, scope and non-goals, constraints,
41
+ failure and edge behavior, compatibility and migration, success and
42
+ Verification, and deferred items. Expand them dynamically after every answer.
43
+ Do not use materiality, task type, or risk classification to decide whether a
44
+ sourced user decision is worth asking.
45
+
46
+ Classify each unresolved node only as a repository fact or a user-owned decision.
47
+ Resolve facts with bounded, on-demand read-only evidence. If evidence is
48
+ unavailable, record a blocked fact and block only its dependent subtree; never
49
+ turn the fact into a user preference. Place every sourced user decision on the
50
+ current frontier.
51
+
52
+ Ask every independent question on the complete currently unblocked frontier
53
+ together. Hold downstream questions until their prerequisites are decided.
54
+ Number every question, include grounded options and one recommended answer with
55
+ a short reason, and accept bulk approval of all recommendations with explicit
56
+ exceptions. Direct requirements and adopted recommendations settle only the
57
+ current nodes; they never complete the Brainstorm session by themselves.
58
+ Recompute the tree after every response and continue through newly unlocked
59
+ downstream branches.
60
+
61
+ Minimally clarify an ambiguous answer while independent branches continue. If a
62
+ later answer or new fact invalidates an earlier choice, reopen only that decision
63
+ delta and explain the new evidence. An explicit defer stops its subtree and is
64
+ recorded as `BR-DEFER-*`; if the subtree still changes the current Result,
65
+ interface, or compatibility, explain why it cannot be deferred.
66
+
67
+ Brainstorm finishes only when the frontier is empty and no blocked fact prevents
68
+ traversal. A zero-question fast path is valid only when the complete seeded and
69
+ dynamically expanded tree contains no unresolved user decision. If the user
70
+ stops early, record every open node as `BR-Q-*` and do not mark the framing
71
+ planning-ready.
72
+
73
+ When traversal completes, present a concise result-only summary as a
74
+ non-blocking correction window. Do not ask the user to reconfirm decisions
75
+ reflected without change. If the summary introduces or changes a
76
+ decision, ask for explicit confirmation of only that decision delta
77
+ and block Planner handoff until it is answered. Agent judgment alone never
78
+ confirms a proposed direction or scope. Persist only final decisions: map them
79
+ to `BR-REQ-*`, `BR-DEC-*`, `BR-OUT-*`, `BR-DEFER-*`, and resolved `BR-Q-*`
80
+ manifest entries; do not copy the question transcript into repository artifacts.
81
+
82
+ ## Workflow Rules
83
+
84
+ - **Trigger Shape**: Use when product framing is still needed. Direct Planner entry remains available for a clear request, but once the user invokes Brainstorm, do not short-circuit its exhaustive traversal because an initial frame appears clear. Do not add a second confirmation for an unchanged final summary.
85
+ - **Decision Provenance**: Traverse every sourced current-goal branch. A concrete scenario is a branch when the request, repository, or a settled parent decision makes it relevant; do not invent speculative future needs.
86
+ - **Dependency-Aware Rounds**: Ask every independent question on the complete currently unblocked frontier together. Ask fewer questions only because dependencies keep downstream branches blocked, never because of an arbitrary question budget.
87
+ - **Read-only by default**: Inspect context and summarize the problem. do not implement inside this skill.
88
+ - **Handoff**: Write concise design notes under `docs/brainstorms/` only if explicitly requested.
89
+ - **Handoff Manifest**: When framing is stable, user-confirmed, and routes to planner, include a compact `Brainstorm manifest` with stable IDs for every planner-relevant item: `BR-REQ-*` for confirmed requirements, `BR-DEC-*` for confirmed decisions, `BR-OUT-*` for non-goals, `BR-DEFER-*` for explicitly deferred items, and `BR-Q-*` for open questions. The manifest is the closed-world handoff; the planner must account for every ID instead of relying on prose memory.
90
+ - **Default Next Route**: Route to `imm-planner` only when the full frontier is empty, no blocked fact prevents traversal, and every sourced user decision is settled by a direct requirement, explicit answer, or adopted recommendation. Those inputs close their nodes but never the session. An unchanged final summary is a correction window, not another gate. If Brainstorm introduces a new decision, ask for that delta and do not name `imm-planner` as the current next skill.
91
+ - **Subagents**: Follow the Adaptive Cache-First Route in `docs/reference/subagent-dispatch-protocol.md`: classify the task, check cache-first discovery pointers, and carry subagent split pressure forward only when the Cost-Based Subagent Gate says parallel research is worth the coordination cost. User explicitly wants solo fallback when split is impossible.
92
+ - **Rejected Decision Evidence**: Use on-demand rejected-decision evidence instead of a global preflight. When a live branch resembles a rejected decision, resolve its recorded reason and optional `reconsider_if` conditions through code/docs inspection before asking the user. Treat each `reconsider_if` list item as an independently sufficient trigger (OR semantics): if available evidence satisfies none, keep the rejection as a current constraint or non-goal without re-litigation; if evidence satisfies one, reopen the decision and cite the condition plus changed evidence; if a condition cannot be resolved, ask only for that concrete missing fact. When `reconsider_if` is absent, preserve the backwards-compatible "what has changed?" fallback after inspection. When `rejection_reason` is absent, inspect an explicit rejection-reason section in the body; if no reason exists, report the metadata gap without inventing a reason or reconsideration condition.
93
+ - **CONTEXT.md Awareness**: When the user uses vague or conflicting domain terms, check `CONTEXT.md` at the repo root. If a canonical term exists, surface the conflict: "CONTEXT.md defines X as Y, but you seem to mean Z — which is it?" If CONTEXT.md does not exist, note the gap and recommend the planner create it during planning. Use CONTEXT.md vocabulary in the output artifact when available.
94
+ - **Discovery Protocol**: Before broad searching, read `CONTEXT.md` `## Architecture Map` and the active `.imm/memory/current_iteration.json` step `discovery_cache` when present. Use matching `docs/solutions/` `key_files` frontmatter as the pattern layer. If these pointers are missing or stale, note the discovery gap in the framing instead of compensating with unbounded search.
95
+
96
+ ## Research Dispatch
97
+
98
+ Follow [`docs/reference/subagent-dispatch-protocol.md`](docs/reference/subagent-dispatch-protocol.md) for the full dispatch lifecycle. This section defines brainstorm-specific optional research dispatch.
99
+
100
+ Runtime helpers: `imm_core.buildBrainstormEnsembleRequest`, `imm_core.buildBrainstormEnsembleDispatchEnvelopes`, `imm_core.normalizePiBrainstormAgentResults`, and `imm_core.normalizeBrainstormEnsemblePacket`.
101
+
102
+ ### Brainstorm Ensemble Advisory
103
+
104
+ A Brainstorm ensemble is optional advisory-only framing input, not a vote and not a child-owned decision. The default roles are clarify scope, divergent options, minimal solution, and risk review.
105
+
106
+ All Brainstorm ensemble children are advisory-only with `tool_policy: no tools`; they do not edit code, write Specs, write Plans, mutate workflow state, or close QA. The parent `imm-brainstorm` owns final framing synthesis, Brainstorm manifest IDs, and decision-delta confirmation. Final Spec and Plan authority stays with `imm-planner`. Routine Managed enrollment uses the Planner's final `ctx.ui.custom` confirmation bound to the TaskIntent content hash as the single authority gate; Enrollment validates descriptor structure without executing acceptance descriptors, deterministic QA executes them after implementation, and the routine task proceeds without a second human stop.
107
+
108
+ Pi's adapter may consume `brainstorm_ensemble` dispatch JSON to prepare advisory Pi subagent envelopes, but envelope construction is not child execution and does not transfer framing authority. Pi launches one foreground Agent at a time, consumes its direct result, and re-evaluates the remaining dispatch budget before launching another candidate. Runtime does not call any agent, poll or recover background work, mutate state, or own final Spec/Plan authority. Pi subagent children remain no-tools advisory candidates; the parent `imm-brainstorm` collects outputs before synthesis.
109
+
110
+ Agreement becomes framing evidence. Disagreement becomes decision criteria or an open `BR-Q-*`. strong-model blockers become explicit risks or verification requirements for the planner handoff. Small framing tasks do not fan out by default; use solo Brainstorm unless the task has elevated framing risk or an explicit ensemble request.
111
+
112
+ **Trigger condition:** Only dispatch when the task spans multiple domains (`multi_domain >= 2`) or the user explicitly requests parallel research. Do not dispatch for single-domain or lightweight framing tasks.
113
+
114
+ **Retrieval budget:** Stop dispatching as soon as existing evidence is sufficient to answer the core framing question. Do not dispatch additional agents to improve phrasing, add examples, or cover non-essential details. Dispatch again only when a required constraint, convention, or risk is still missing from the current evidence set.
115
+
116
+ **Dispatch behavior:** Use Pi native `Explore` subagents (`subagent_type: "Explore"`). Each prompt must state a bounded read-only scope and returns a structured summary (affected files, conventions found, risks). The parent brainstorm agent merges summaries before producing the output artifact. Research subagents do not write files, specs, plans, or `.imm/` state.
117
+
118
+ **Manifest mapping:** Repo-local runtimes use `imm_core.brainstorm_research` to keep research probes host-bound and manifest-oriented. Every child summary that affects planning must map to a Brainstorm manifest ID: `BR-REQ-*`, `BR-DEC-*`, `BR-OUT-*`, `BR-DEFER-*`, or `BR-Q-*`. Any unmapped or unresolved research question becomes a `BR-Q-*`; open `BR-Q-*` items block planner handoff.
119
+
120
+ **Failure handling:** If research dispatch is unavailable or fails, continue with solo inline investigation. Record the fallback reason per the shared protocol.
121
+
122
+ ## Boundary
123
+
124
+ - **Allowed**: Clarify framing, inspect read-only context, ask narrowing questions, perform inline gap analysis.
125
+ - **Blocked**: Implementation edits, test changes, plan writes, and runtime state updates. Do not edit implementation files, tests, specs, plans, or `.imm/memory/`.
126
+ - **Workflow guard**: implementation continuations must go through `imm-planner` or `imm-loop`. `imm-brainstorm` frames the problem; it is not the default post-framing stage once the task is already stable enough to route forward. The `adversarial` mode remains available as an opt-in high-pressure gate for high-risk scenarios but is not a default route target.
127
+
128
+ ## Output artifact
129
+
130
+ Concise task framing: Conclusion, In/Out scope, Assumptions/Risks, Brainstorm manifest, Next Action. The default user-facing handoff should read like a short conclusion note; when a planner handoff is ready, include the manifest IDs so confirmed scope cannot be silently dropped during planning. When a decision delta is still unconfirmed, omit the handoff manifest and phrase Next Action as a focused confirmation request rather than a skill route.
131
+
132
+ ## Output style
133
+
134
+ Default user-facing shape: `Conclusion -> Scope -> Next Action`. For the normal success path, return only these. Only expand `Allowed` / `Blocked` / `Workflow guard` when routing needs explicit guarding. Do not force mini-headings or checklist labels.
135
+
136
+ ## Next Action
137
+
138
+ - Gate: The exhaustive frontier is empty; no blocked fact prevents traversal; every sourced user decision is settled by a direct requirement, explicit answer, or adopted recommendation; and the result-only summary introduces no unconfirmed decision delta. **If any requested clarification remains unanswered, you MUST NOT proceed to planning or suggest the next skill.** **If a decision delta is still unconfirmed, you MUST NOT proceed to planning, must not name a next skill, and should ask the user to confirm only that delta.**
139
+ - If gates pass: suggest `imm-planner` with a one-line reason.
140
+ - If gates are not met: state which questions or decision deltas remain open; do not name a next skill and wait for the user's answer.
@@ -0,0 +1,137 @@
1
+ ---
2
+ name: imm-doc-prune
3
+ description: Use to prune stale current documentation from a Git repository after an explicit, hash-bound, user-approved manifest; never deletes Managed authority artifacts.
4
+ ---
5
+
6
+ # Immune-Brain: Doc Prune
7
+
8
+ Prune stale current documentation from one Git repository through explicit
9
+ invocation, comprehensive inventory, evidence-based candidate narrowing,
10
+ one exact user-approved manifest, and bounded current-only mutation. This is
11
+ a standalone host-native maintenance entry, not a Managed Path continuation
12
+ and not an `imm-loop` internal-role dispatch.
13
+
14
+ ## Authority Boundary
15
+
16
+ This Skill prunes documentation
17
+ without creating or mutating
18
+ TaskIntent, TaskRecord, Kernel, Spec, or Plan authority. An already active
19
+ Managed task remains owned by `imm-loop`. Read-only inventory and manifest
20
+ production remain available. Classify each candidate overlapping the active
21
+ TaskIntent `scope_hint` as `BLOCKED_ACTIVE_SCOPE` and continue auditing
22
+ unaffected candidates. If the routing owner or scope cannot be read reliably,
23
+ fail closed for mutation.
24
+
25
+ ## Invocation
26
+
27
+ Requires explicit invocation: `imm-doc-prune` or `/imm-doc-prune`. Ordinary
28
+ "is this doc stale?" questions stay host-native and do not enter this Skill.
29
+
30
+ - `imm-doc-prune audit`: read-only. Produce the manifest and stop.
31
+ - `imm-doc-prune`: produce the manifest, then wait for exact manifest approval
32
+ before any mutation.
33
+
34
+ No automatic invocation. No daemon, no cron, no CI, no allowlist, no runtime,
35
+ no persistent report, and no automatic commit.
36
+
37
+ ## Ordered Pruning Protocol
38
+
39
+ 1. **Establish repository safety.** Mutation requires a Git worktree. A
40
+ non-Git repository or an untracked candidate is audit-only. Record the
41
+ candidate path, blob/content hash, tracked status, and candidate-local
42
+ worktree status. Unrelated dirty files do not block the run; a dirty
43
+ candidate is `BLOCKED`.
44
+
45
+ 2. **Inventory current documentation.** Enumerate tracked `.md`, `.mdx`,
46
+ `.rst`, and `.adoc` files, agent instruction files such as `AGENTS.md`,
47
+ `CLAUDE.md`, and `GEMINI.md`, plus `.json`, `.yaml`, and `.yml` files
48
+ under documentation directories that are referenced by current
49
+ documentation. Exclude `node_modules`, vendor trees, build output,
50
+ caches, arbitrary business data, and source comments from semantic
51
+ scanning.
52
+
53
+ 3. **Classify document roles.** Distinguish current guidance, generated or
54
+ mirror content, Kernel authority artifacts, historical-by-purpose
55
+ records, non-authority archives, and `UNCLASSIFIED` groups. Preserve
56
+ `CHANGELOG`, release notes, migration records, and incident reports;
57
+ do not modernize historical narration merely because it describes old
58
+ behavior.
59
+
60
+ 4. **Build repository facts.** Resolve current truth in this order:
61
+ executable/public registries, package exports, CLI/runtime entrypoints;
62
+ behavior tests; active Spec/TaskIntent; current `CONTEXT.md`/ADR/
63
+ reference/README; Solution/Brainstorm/archive. A lower-priority historical
64
+ statement cannot prove a retired public surface is current.
65
+
66
+ 5. **Mechanically narrow candidates.** Check local paths and anchors, public
67
+ Skill/CLI/API names, command/import targets without executing arbitrary
68
+ examples, inbound local references, source/generated declarations,
69
+ translations with explicit source mappings, ADR/Solution owners, and
70
+ conflicting current claims. External URL availability is not probed in
71
+ the first version.
72
+
73
+ 6. **Apply evidence rules.** Age or zero references alone never proves
74
+ staleness. ADR deletion requires a removed decision object, an implemented
75
+ mutually exclusive replacement with current constraints preserved, a
76
+ retired public surface, or a successor ADR that fully carries current
77
+ constraints. Solution deletion requires a false `reusable_premise`,
78
+ vanished `key_files` without a current owner, a retired command/Skill/API/
79
+ workflow, or complete replacement by current guidance.
80
+
81
+ 7. **Produce one exact manifest.** Classify entries as `DELETE`, `EDIT`,
82
+ `KEEP`, `BLOCKED`, `BLOCKED_ACTIVE_SCOPE`, `UNVERIFIED`,
83
+ `HISTORICAL_GIT_ONLY`, or `MISSING_CURRENT_DOC`. Include evidence, exact
84
+ file/section action, inbound-reference treatment, Git recoverability, and
85
+ candidate hash. Group `UNCLASSIFIED` files; do not interrogate the user
86
+ file by file.
87
+
88
+ 8. **Gate mutation.** `audit` mode stops after the manifest. Mutation mode
89
+ also stops until the literal user approves exact manifest entries (for
90
+ example, "all recommendations except 4 and 7"). Broad approval such as
91
+ "clean stale docs" is insufficient. Interruption starts a fresh scan; no
92
+ manifest is persisted.
93
+
94
+ 9. **Revalidate and mutate minimally.** Re-read candidate bytes, Git status,
95
+ inbound references, generated ownership, and active scope immediately
96
+ before each approved change. Drift blocks that item. Delete a whole file
97
+ only when its role is wholly obsolete; otherwise delete the complete stale
98
+ logical section or move still-current constraints into an existing current
99
+ owner before deleting the obsolete source. Never renumber ADRs and never
100
+ create a new ADR or Solution merely to complete pruning.
101
+
102
+ 10. **Verify and report.** Re-scan residual names and paths, current local
103
+ links on current documentation, source/generated parity, existing documentation contract tests,
104
+ and `git diff --check`. This Skill does not execute arbitrary documented
105
+ commands or the full business suite unless touched executable metadata
106
+ requires a focused check. This Skill does not commit. Report only `Deleted`, `Edited`, `Blocked`,
107
+ `Unverified`, `Historical Git-only references`, `Verification`, and
108
+ `Recovery: git log -- <path>`.
109
+
110
+ ## Mutation Envelope
111
+
112
+ This Skill may modify or delete approved documentation, explicit translation
113
+ or generated mirrors, documentation sync manifests, and tests whose only
114
+ behavior is asserting document existence or obsolete wording. It must stop
115
+ when completion requires runtime behavior, business-test semantics, package
116
+ exports, public API, credentials, network writes, Git history rewriting, or
117
+ any Managed authority mutation.
118
+
119
+ Generated content is never independently authored: change the source, update
120
+ its declared sync ownership, and run the repository's existing generator. A
121
+ failed generator or focused check leaves an inspectable diff and stops; this
122
+ Skill does not stash, reset, checkout, or revert user work.
123
+
124
+ ## Authority Artifacts Excluded
125
+
126
+ This Skill categorically does not delete active or frozen Specs, TaskIntents,
127
+ TaskRecords, tombstones, or other `.imm` authority. Historical immutable
128
+ authority references to deleted non-authority documents are allowed and
129
+ reported as `HISTORICAL_GIT_ONLY` references with the recovering commit; they
130
+ are not treated as current dangling links.
131
+
132
+ ## Recovery
133
+
134
+ Git history is the archive for obsolete non-authority documentation. Every
135
+ `DELETE` entry reports `Recovery: git log -- <path>` so the user can restore
136
+ content from history. Untracked, dirty, or non-Git candidates are never
137
+ deleted.
@@ -0,0 +1,158 @@
1
+ ---
2
+ name: imm-loop
3
+ description: Use when running validated Plans to completion.
4
+ ---
5
+
6
+ # Immune-Brain: Loop
7
+
8
+ This skill adheres to the **[BASELINE.md](BASELINE.md)**.
9
+ At every runtime role boundary, call the read-only `imm_loop_action` Tool. Use
10
+ `route` for active Steps, bounded repair, architecture exploration, advisory
11
+ review, Compounder, Kernel ownership, or scope expansion. Use `dispatch_role`
12
+ for `qa`, `code-review`, and `ui-review`, then invoke the returned foreground
13
+ Agent envelope exactly. Brainstorm and Planner use the same Tool for bounded
14
+ `arch-explorer` and explicit-lens `advisory-reviewer` dispatches. Loop may
15
+ dispatch `compounder` only when a closed Step supplies structured evidence for
16
+ a reusable Learning; routine work without that evidence returns `next: none`
17
+ and creates no Learning. Do not discover or load a Pi Skill for these roles. The Managed Path public entries remain `imm-brainstorm`, `imm-planner`, and `imm-loop`; standalone `imm-pr-fix` and `imm-doc-prune` are host-native and are never dispatched as the Loop role.
18
+ Dispatch authorization follows the [shared Subagent Dispatch
19
+ Protocol](docs/reference/subagent-dispatch-protocol.md#authorization-authority).
20
+ Same-boundary `follow_up` is not a Plan mutation; it repeats the current
21
+ execution, QA, and originating review gate. All internal Agent dispatch
22
+ envelopes use `run_in_background: false` and return `tool_call`, `tool_result`,
23
+ and `tool_execution_end` evidence to the Parent before any workflow mutation.
24
+
25
+ ## Workflow Profiles
26
+
27
+ - `direct` has no Plan or Ledger and never invokes this skill.
28
+ - `standard` keeps execution in the main context, closes a Plan Step when the runtime accepts passing evidence, and therefore does not dispatch the internal QA role per Step. It still dispatches every runtime-required final code/UI review gate. The last gate pass atomically performs internal terminal settlement when `compounder_requirement.required` is false.
29
+ - `strict` preserves the full internal loop: each Step reaches isolated QA before final review, internal Compounder handoff, and terminal settlement. A missing profile is strict.
30
+ - Reviewer `follow_up` targets always retain isolated QA. Standard Plans allow at
31
+ most two completed/open rounds; `review_budget_state.budget_stop` is a hard
32
+ stop. Never attempt a third Loop runtime action.
33
+ - `workflow_profile`, `compounder_requirement`, and `review_budget_state` from
34
+ the live Kernel / Loop projection are authoritative. Do not infer or override
35
+ them in the host.
36
+
37
+ ## Core Responsibilities
38
+
39
+ - **Main-context completion loop**: Drive the enrolled Kernel task in the current Pi conversation until completion or a safe stop.
40
+ - **Context-preserving execution**: Call `imm_loop_action` with `op: route`, then follow the returned `executor` context in the current Parent conversation. Implement only the active Step or pending same-boundary `follow_up`, then record structured execution evidence through the Loop runtime action. A bounded test failure uses the returned internal `test-fixer` dispatch with its explicit delegated test-file list; PR feedback or CI repair uses the returned internal `pr-fix` dispatch inside the current Plan boundary.
41
+ - **Independent authority isolation**: Use the host `Agent` subagent primitive for `awaiting_qa_decision` and for the exact runtime-reported review gate. Standard Plan Steps close from accepted passing evidence before an internal QA boundary exists; Strict Steps and all follow-ups retain isolated QA. The parent records accepted child decisions through the Loop runtime action.
42
+ - **Observable progress**: Update only at major phase changes: Step start, execution evidence recorded, QA/review result, or terminal stop. Always emit a terminal summary.
43
+ - **Kernel projection authority**: Re-read `imm_kernel_canary` `status` after every persisted action. Conversation memory never overrides the Kernel projection.
44
+ - **External tracker boundary**: The host may attach one opted-in GitHub Issue projection after terminal settlement. Only a fresh claimless `done`/`stopped` projection plus its exact terminal tombstone projects `completed`/`not planned`; Enrollment performs no GitHub projection. Report tracker failures separately, but never treat them as evidence, stop the Loop, repeat a Kernel mutation, or import Issue state.
45
+ - **Scope boundary**: Scope expansion always returns to `imm-planner`; Executor, test repair, and PR/CI repair stop with the concrete missing scope and verification reason instead of widening execution.
46
+ - **Action authority**: The loop always enters through `imm_loop_action`; its projected `next` authority is `executor`, `test-fixer`, `pr-fix`, `arch-explorer`, `advisory-reviewer`, `compounder`, `imm_kernel_canary`, `imm-planner`, or `none`.
47
+
48
+ ## Kernel Loop
49
+
50
+ Repeat this sequence; do not silently stop while a valid action remains:
51
+
52
+ 1. Call `imm_loop_action` with `op: route` (or `dispatch_role` at a QA/review boundary) and follow the projected `next` authority.
53
+ 2. Emit one progress line: `[target][phase] result | next: action`.
54
+ 3. Execute exactly one allowed action:
55
+ - Kernel ownership: call `imm_kernel_canary` for that owned task. Freeze the completed artifacts, then call `advance_assurance`; when it returns `review_ready`, invoke the exact reserved foreground Agent and call `submit_review`. When the projection calls for `request_authorization`, `approve_breaking_intent_revision`, or `repair_authority_state`, invoke the exact Tool operation directly without asking the user for chat pre-confirmation. The native host interaction is the single authority decision.
56
+ - Active Step / `rework_needed`: follow the returned `executor` context in the current conversation, implement only the active Step or pending same-boundary `follow_up`, verify, record structured execution evidence through the Loop runtime action, and continue. A bounded test-only repair may request internal `test-fixer` with `focus_delta.specific_changes`; PR review or CI repair may request internal `pr-fix` with the current `plan_id`, changed-file boundary, and verification. Both return child evidence to the Parent and cannot widen scope.
57
+ - `awaiting_qa_decision`: call `imm_loop_action` with `op: dispatch_role`, role `qa`, the current projection, Plan verification, recorded evidence, and current target identity. Invoke the returned foreground Agent envelope exactly. A `rework` or `replan` must carry validated `notes`.
58
+ - `review_required`: map the exact `pending_review_gate` (`imm-code-review` or `imm-ui-review`) to the internal `code-review` or `ui-review` role and call `imm_loop_action` with `op: dispatch_role`, passing `pending_review_gate`, `review_changed_files`, and `review_changed_files_signature`. Invoke the returned foreground Agent envelope exactly. Record a validated pass, or open a same-boundary follow-up through the Loop runtime action.
59
+ - `awaiting_user_successor_decision`: stop immediately with `recommended_authority: user`, no next skill, and no runtime action. This boundary must not dispatch Planner, transition, Compounder, or a new Pi session/subagent. Only a literal user may supply a concrete validated successor Plan through the native authority gate; the internal runtime token is `--approve-successor`, never a public Skill or user-facing entry.
60
+ 4. After every accepted runtime write, discard the old snapshot and read a fresh Kernel / Loop projection. Emit a result line only when the write completes a major phase or a subagent round.
61
+
62
+ Use Pi native `Agent` subagents. Do not spawn Pi child processes or invoke a separate `imm-loop` CLI.
63
+
64
+ ## Authority and Failure Guards
65
+
66
+ - Implementation requires a validated Plan and active Step or accepted pending `follow_up`.
67
+ - The parent may implement but must not issue its own QA or review pass.
68
+ - QA and reviewer children must not edit files, write Plans, mutate Kernel state, or close decisions directly.
69
+ - Missing `Agent` support, failed or malformed child output, stale child target, runtime write failure, invalid projection, missing credentials, unclear verification, repeated unchanged failure, or user cancellation stops fail-closed with an explicit reason and no decision write.
70
+ - `replan_needed` stops at `imm-planner`; do not widen scope or rewrite the active Plan. A replacement must use a new sequential Plan path after the current Plan reaches `completed`, or after a literal user explicitly marks it `cancelled` or `superseded`.
71
+ - Plans never suspend, resume, queue, or execute in parallel. Do not insert a repair Plan ahead of the current Plan.
72
+ - Same-boundary review `follow_up` repeats execution, independent QA, and the originating review gate.
73
+ - Runtime `review_required` is the single review-gate authority. Do not invent hidden gates.
74
+ - `imm-compounder` is an internal role and is never invoked as a public Skill. A `complete` projection carries an explicit internal Compounder handoff because the runtime determined it is required. A Standard Plan with optional Compounder is atomically finished by the last review gate and does not emit that handoff. Strict Plans preserve the successful order: current Steps and QA, required reviews, internal Compounder handoff, terminal settlement, then `awaiting_user_successor_decision` for a non-terminal Roadmap slice.
75
+ - Successor approval is non-delegable. QA, review, Planner, Compounder, and the loop cannot approve or activate a successor, and the loop must not turn a command template into an executable successor invocation.
76
+
77
+ ## Stop Conditions
78
+
79
+ Stop only for:
80
+
81
+ - `complete` with an explicit internal Compounder handoff before terminal settlement
82
+ - `terminal_plan_complete` after a contracted terminal Plan or a legacy Plan without successor metadata has passed internal Compounder handoff and terminal settlement; stop with no next skill, authority, or action
83
+ - `awaiting_user_successor_decision` after finish, with literal user authority and no automatic action
84
+ - `replan_needed`
85
+ - blocker or required user input
86
+ - runtime, tool, subagent, or output-contract failure
87
+ - user cancellation (no decision write; Plan termination is a separate explicit user-confirmed runtime action)
88
+ - repeated unchanged failure
89
+ - explicit Step, rework, review, follow-up, or elapsed-time budget exhaustion
90
+
91
+ Session-local budgets are advisory. Persisted Step, QA, review, and follow-up state controls recovery. After interruption, re-enter only by reading a fresh projection: a completed runtime write is honored once; an interrupted pre-write action is not claimed; cancellation performs no decision write; repeated unchanged failure stops unless the next attempt names a strategy change; explicit budgets stop before another action.
92
+
93
+ ## Observable Output Contract
94
+
95
+ Do not narrate projection reads or routine runtime writes. Emit compact progress only for Step start, completed execution evidence, QA/review decisions, failures that change the plan, and terminal stop. Every subagent round still emits exactly one dispatch line and exactly one collection/result line:
96
+
97
+ ```text
98
+ [Step 1/3][Executor] evidence recorded | next: QA
99
+ [Step 1/3][QA] Agent dispatched
100
+ [Step 1/3][QA] Agent collected: pass | next: imm-code-review
101
+ ```
102
+
103
+ Do not emit a successful collection line for timeout, cancellation, malformed output, or stale identity; emit the explicit failure stop instead.
104
+
105
+ Every exit, including failure, must include:
106
+
107
+ ```text
108
+ Plan:
109
+ Completed Steps:
110
+ QA:
111
+ Review:
112
+ Stop reason:
113
+ Next action:
114
+ ```
115
+
116
+ Normal conversation text and visible tool calls are the correctness-level observation surface. Extension widgets are optional decoration only.
117
+
118
+ ## Boundary
119
+
120
+ - **Allowed**: Coordinate Kernel / Loop projections, current-conversation Executor work, isolated QA/review children, runtime decision recording, same-boundary follow-up, and terminal handoff reporting.
121
+ - **Blocked**: Plan edits, parent-owned QA/review pass, hidden review gates, direct Kernel-store edits, child-owned state mutation, automatic Compounder execution, and external loop runners.
122
+ - **Workflow guard**: Kernel and Loop projections choose the next authority; each authority keeps its existing Skill contract.
123
+
124
+ ## Output artifact
125
+
126
+ A visible completion trace plus terminal summary containing Plan, completed Steps, QA state, review state, stop reason, and next action.
127
+
128
+ ## Next Action
129
+
130
+ - If no validated Plan exists: stop and route to `imm-planner`.
131
+ - If an allowed Loop action exists: continue the loop without another user command.
132
+ - If work is fully closed but not finished: report the explicit internal Compounder handoff and wait for terminal settlement.
133
+ - If the projection is `awaiting_user_successor_decision`: report the candidate and preconditions, ask for the user's decision, and stop without dispatch.
134
+
135
+ ## Output style
136
+
137
+ Default user-facing shape: checkpoint progress lines, then `Conclusion -> Evidence -> Next action` at the terminal boundary.
138
+
139
+ ## Kernel Canary Routing
140
+
141
+ When the Kernel projection reports an active/draining backend claim, keep
142
+ `imm-loop` as the user-facing entry and call the `imm_kernel_canary` Tool for
143
+ that owned task. Enrollment uses the `imm_canary_enrollment` Tool and Review
144
+ authorization remains a native TUI gate using the internal user-kind approval
145
+ action `record-user-approval`. When the projection calls for
146
+ `request_authorization`, `approve_breaking_intent_revision`, or
147
+ `repair_authority_state`, invoke the exact Tool operation directly without
148
+ asking the user for chat pre-confirmation; the native host interaction is the
149
+ single authority decision. This action is not a public Skill or CLI route. Do
150
+ not invoke the removed `imm-canary-work` Skill as a separate entry point.
151
+ Invalid or contradictory projections fail closed. After implementation and focused verification, freeze the artifacts and call
152
+ `imm_kernel_canary` `advance_assurance`. If it returns `review_ready`, invoke
153
+ the exact reserved foreground Agent and call `submit_review`;
154
+ `request_authorization` remains the user authorization boundary. Visible
155
+ background state and push follow-up replace manual QA/Review sequencing and
156
+ result polling. A terminal task leaves only an immutable task tombstone: it is
157
+ never reactivated and never blocks unrelated v3 routing. The Kernel projection
158
+ is advisory; every Kernel mutation re-enters Kernel store-lock validation.