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
package/README.md ADDED
@@ -0,0 +1,239 @@
1
+ # Immune-Brain
2
+
3
+ > Deterministic workflow & quality engine for [Pi](https://github.com/badlogic/pi) — turn vague ideas into shipped code with planning, execution, QA, and review.
4
+
5
+ **Language:** **English** | [中文](./README.zh-CN.md)
6
+
7
+ ---
8
+
9
+ ## What Is This?
10
+
11
+ Immune-Brain adds a structured engineering workflow on top of Pi:
12
+
13
+ - **You describe what you want** in natural language — the agent figures out whether to clarify, plan, or execute.
14
+ - **Plans become trackable tasks** (`TaskIntent` + `TaskRecord`) so progress survives across sessions, not just chat history.
15
+ - **Quality is enforced by code, not promises** — automated QA and isolated review must pass before a task is marked done.
16
+
17
+ Pi remains the only host. It can use any model provider (Anthropic / OpenAI / Google) — Immune-Brain works on top of whichever you configure in Pi.
18
+
19
+ ---
20
+
21
+ ## Table of Contents
22
+
23
+ - [Installation](#installation)
24
+ - [Quick Start](#quick-start)
25
+ - [How to Use](#how-to-use)
26
+ - [The 5 Skills](#the-5-skills)
27
+ - [Lifecycle](#lifecycle)
28
+ - [Configuration](#configuration)
29
+ - [Project Layout](#project-layout)
30
+ - [FAQ](#faq)
31
+ - [Development](#development)
32
+
33
+ ---
34
+
35
+ ## Installation
36
+
37
+ **Prerequisites:** [Pi](https://github.com/badlogic/pi) installed, Node.js 20+, `bun` for tests.
38
+
39
+ This repo is a Pi package — Pi discovers Skills and extensions from `package.json`:
40
+
41
+ ```json
42
+ // package.json → pi.skills / pi.extensions
43
+ "pi": {
44
+ "skills": ["./plugins/immune-brain/skills"],
45
+ "extensions": ["./plugins/immune-brain/.pi-extension"]
46
+ }
47
+ ```
48
+
49
+ No extra server config is needed. Installing the package via Pi makes all 5 Skills available automatically. Verify with:
50
+
51
+ ```bash
52
+ bun test # run all tests
53
+ mise run check-plugin # verify package structure
54
+ mise run check-dist-sync # verify generated docs are in sync
55
+ ```
56
+
57
+ ---
58
+
59
+ ## Quick Start
60
+
61
+ **1. Describe the change you want** — just talk to Pi in natural language:
62
+
63
+ > "Add dark mode to the settings page"
64
+
65
+ Pi routes it automatically: vague requests go to clarification, clear requests go to planning.
66
+
67
+ **2. Confirm the plan** — Planner writes a `TaskIntent` (scope, risk, acceptance checks). Review it, then confirm enrollment in the TUI dialog (required for all risk levels). No writes happen before you confirm.
68
+
69
+ **3. Let it run** — `imm-loop` executes the plan, runs QA, and triggers review. Stage your owned files when prompted:
70
+
71
+ ```bash
72
+ git add -- <file-owned-by-task> <another-file>
73
+ ```
74
+
75
+ QA and review run as foreground tools and report back to the host. When the tool returns `phase=done`, the task is complete.
76
+
77
+ ---
78
+
79
+ ## How to Use
80
+
81
+ You rarely need to remember skill names — **just describe your intent**:
82
+
83
+ | Your situation | What to say / do | What happens |
84
+ |---|---|---|
85
+ | Idea is fuzzy, needs scoping | "Help me think through a notification system" | → `imm-brainstorm` clarifies questions, no code changes |
86
+ | Goal is clear, needs a plan | "Plan the dark-mode feature" or let Pi route there | → `imm-planner` writes `TaskIntent` + specs in `docs/plans/` |
87
+ | Plan is approved, ready to build | "Start building" / `imm-loop` | → Executor builds, QA verifies, Review checks |
88
+ | PR needs fixes after review | `imm-pr-fix` on that PR | → Standalone repair, no new managed task |
89
+ | Docs are stale after changes | `imm-doc-prune` with manifest | → Prunes only approved stale docs |
90
+
91
+ > **Rule:** Managed work (brainstorm → plan → loop) starts only from explicit `imm-brainstorm`, `imm-planner`, or `imm-loop`. Ordinary Q&A or read-only requests stay host-native and never enroll a task.
92
+
93
+ ---
94
+
95
+ ## The 5 Skills
96
+
97
+ | Skill | Type | When to use | What it does |
98
+ |---|---|---|---|
99
+ | `imm-brainstorm` | Managed entry | Requirements are ambiguous | Frames the problem, surfaces open questions, no code edits |
100
+ | `imm-planner` | Managed entry | Goal is clear | Authors / revises `TaskIntent` and specs; does not enroll or build |
101
+ | `imm-loop` | Managed coordinator | Plan is validated | Drives execution → QA → Review → completion via foreground tools |
102
+ | `imm-pr-fix` | Standalone | CI failed / review comments on a PR | Repairs one PR in place, no managed authority |
103
+ | `imm-doc-prune` | Standalone | Stale current docs | Deletes only the hash-approved manifest entries |
104
+
105
+ Internal roles (Executor, QA, Review, Compounder) are dispatched by `imm-loop` — you never invoke them directly.
106
+
107
+ **Recommended default:** let natural-language routing pick brainstorm vs. planner for you. Explicitly invoke a skill only when you want to force that phase.
108
+
109
+ ---
110
+
111
+ ## Lifecycle
112
+
113
+ ```
114
+ You: natural language request
115
+
116
+ ├─── vague ──→ imm-brainstorm (clarify, no edits)
117
+
118
+ └─── clear ──→ imm-planner ──→ TaskIntent (Git-tracked)
119
+
120
+ TUI confirm (enrollment)
121
+
122
+ imm-loop
123
+ ├── Executor (edits inside scope)
124
+ ├── QA (deterministic checks must pass)
125
+ ├── Review (material/critical: isolated subagent)
126
+ └── done
127
+ ```
128
+
129
+ Key invariants:
130
+
131
+ - **One active step at a time**, edits only inside that step's boundary.
132
+ - **Scope (`scope_hint`) is frozen at enrollment** — out-of-scope files are ignored.
133
+ - **Evidence before closure** — QA is the only authority that can close a step.
134
+ - **Advisory never implements**, execution never self-approves.
135
+
136
+ ---
137
+
138
+ ## Configuration
139
+
140
+ Immune-Brain has **no separate config file**. Preferences live in `AGENTS.md` (repo root or `~/.pi/agent/AGENTS.md`):
141
+
142
+ ```md
143
+ ## Immune-Brain Preferences
144
+
145
+ - Initiative carrier default: github # or: local
146
+ ```
147
+
148
+ | Preference | Options | Default | Notes |
149
+ |---|---|---|---|
150
+ | Reply language | any natural language | repo `AGENTS.md` | Machine contracts / paths stay literal |
151
+ | Initiative carrier | `local` / `github` | `github` | Only matters when a proposal splits across multiple TaskIntents |
152
+ | Advisory subagents | allowed / solo | allowed | Respects Pi host policy + explicit user instruction |
153
+
154
+ Precedence: **current message > repo `AGENTS.md` > `~/.pi/agent/AGENTS.md` > skill default**.
155
+
156
+ See [`docs/reference/immune-brain-config.md`](docs/reference/immune-brain-config.md) for details.
157
+
158
+ ---
159
+
160
+ ## Project Layout
161
+
162
+ ```text
163
+ package.json # Pi package manifest (skills + extensions)
164
+ plugins/immune-brain/
165
+ ├── .pi-extension/ # Pi TUI + Kernel authority extension
166
+ ├── skills/ # 5 public Skills (trigger shims)
167
+ ├── dist/ # Built skill contracts & references
168
+ ├── runtime/ # Bun + TypeScript runtime & Kernel
169
+ └── bin/ # CLI wrappers (→ runtime/v4_runtime.ts)
170
+
171
+ .imm/ # Task state (worktree-local, git-ignored)
172
+ docs/plans/ # Active TaskIntents (*.intent.json)
173
+ docs/specs/ # Living specs (updated in place)
174
+ ```
175
+
176
+ - `.imm/state/` — active work; `.imm/audit/<task-id>/` — settled evidence (tracked).
177
+ - `docs/plans/*.intent.json` must be **Git-tracked** before enrollment.
178
+ - `CONTEXT.md` is vocabulary / navigation only — not a runtime state source.
179
+
180
+ ---
181
+
182
+ ## FAQ
183
+
184
+ **Do I need to learn all 5 skills?** No. Just describe what you want — Pi routes to the right skill. Learn `imm-planner` and `imm-loop` first; the other two are occasional.
185
+
186
+ **What if I interrupt or close Pi mid-task?** State is on disk (`.imm/` + TaskIntent). Re-enter `imm-loop` to resume — the Kernel projection is authoritative.
187
+
188
+ **Why does enrollment show a TUI dialog?** All risk levels (`routine`/`material`/`critical`) require explicit confirmation. It binds the staged digest so you see exactly what will be tracked.
189
+
190
+ **QA failed — what now?** QA returns `rework` or `replan_required`. `imm-loop` routes back to the executor or to `imm-planner` for scope changes. No manual reset needed.
191
+
192
+ **Can I use it outside Pi?** No — Pi is the only supported host.
193
+
194
+ ---
195
+
196
+ ## Release
197
+
198
+ This repo uses [Changesets](https://github.com/changesets/changesets) for versioning and publishing.
199
+
200
+ | Task | Command |
201
+ |------|---------|
202
+ | Add a changeset | `bunx changeset` — pick bump (patch/minor/major) and write summary |
203
+ | Bump version | `bun run changeset:version` — updates `package.json` + `CHANGELOG.md` |
204
+ | Publish (local) | `bun run changeset:publish` — publishes to npm (needs `NPM_TOKEN` or `npm login`) |
205
+
206
+ **Automated flow (recommended):**
207
+ 1. Push changesets to `main` → workflow opens a “Version Packages” PR.
208
+ 2. Merge that PR → workflow publishes to npm, creates GitHub Release, and tags `immune-brain-vX.Y.Z`.
209
+
210
+ Setup: add `NPM_TOKEN` (npm access token with publish permission) to GitHub repo secrets. Workflow is `.github/workflows/release.yml` using `changesets/action@v1`.
211
+
212
+ **Initial publish (2.8.1):**
213
+ ```bash
214
+ npm publish --access public # one-time, requires npm login / NPM_TOKEN
215
+ # or
216
+ bun run changeset:publish
217
+ ```
218
+ The package is scoped `@immune-brain/agent-skills` — `publishConfig.access=public` is already set. After initial publish, all future releases go through changesets.
219
+
220
+ See `CHANGELOG.md` and `.changeset/config.json` (changelog: `@changesets/changelog-github`, repo: `dereknex/immune-brain`).
221
+
222
+ ---
223
+
224
+ ## Development
225
+
226
+ For contributors working on Immune-Brain itself:
227
+
228
+ ```bash
229
+ bun test # full test suite (canonical check is bun test, not tsc)
230
+ mise run check-plugin # plugin structure + version
231
+ mise run check-dist-sync # generated dist docs sync
232
+ ```
233
+
234
+ - Runtime is `runtime/v4_runtime.ts` (Bun + TypeScript). Python under `scripts/` is reference-only.
235
+ - Production CLI: `plugins/immune-brain/bin/imm-kernel` — see [`plugins/immune-brain/README.md`](plugins/immune-brain/README.md) for the full command table.
236
+
237
+ ---
238
+
239
+ *License: MIT*
@@ -0,0 +1,239 @@
1
+ # Immune-Brain
2
+
3
+ > 面向 [Pi](https://github.com/badlogic/pi) 的确定性工程工作流与质量保障引擎 — 把模糊想法变成可交付代码,覆盖规划、执行、QA 与审查。
4
+
5
+ **语言:** [English](./README.md) | **中文**
6
+
7
+ ---
8
+
9
+ ## 这是什么?
10
+
11
+ Immune-Brain 在 Pi 之上提供结构化的工程工作流:
12
+
13
+ - **你用自然语言描述需求**,Agent 自动判断是先澄清、先规划,还是直接执行。
14
+ - **计划变为可追踪的任务**(`TaskIntent` + `TaskRecord`),进度落盘持久化,不依赖对话历史。
15
+ - **质量由代码强制保障** — 自动化 QA 与隔离式 Review 必须通过,任务才会完成。
16
+
17
+ Pi 是唯一支持的宿主,可配置任意模型 Provider(Anthropic / OpenAI / Google),Immune-Brain 在其之上工作。
18
+
19
+ ---
20
+
21
+ ## 目录
22
+
23
+ - [安装](#安装)
24
+ - [快速开始](#快速开始)
25
+ - [如何使用](#如何使用)
26
+ - [5 个 Skills](#5-个-skills)
27
+ - [生命周期](#生命周期)
28
+ - [配置](#配置)
29
+ - [项目结构](#项目结构)
30
+ - [常见问题](#常见问题)
31
+ - [开发者指南](#开发者指南)
32
+
33
+ ---
34
+
35
+ ## 安装
36
+
37
+ **前置要求:** 已安装 [Pi](https://github.com/badlogic/pi)、Node.js 20+、`bun`(用于测试)。
38
+
39
+ 本仓库是一个 Pi Package,Pi 通过 `package.json` 自动发现 Skills 与扩展:
40
+
41
+ ```json
42
+ // package.json → pi.skills / pi.extensions
43
+ "pi": {
44
+ "skills": ["./plugins/immune-brain/skills"],
45
+ "extensions": ["./plugins/immune-brain/.pi-extension"]
46
+ }
47
+ ```
48
+
49
+ 无需额外 server 配置,通过 Pi 安装本 package 后 5 个 Skill 即自动可用。验证:
50
+
51
+ ```bash
52
+ bun test # 全量测试
53
+ mise run check-plugin # 校验插件结构
54
+ mise run check-dist-sync # 校验生成文档同步
55
+ ```
56
+
57
+ ---
58
+
59
+ ## 快速开始
60
+
61
+ **1. 用自然语言描述你要做的改动:**
62
+
63
+ > "给设置页加上深色模式"
64
+
65
+ Pi 会自动路由:需求模糊走澄清,目标明确走规划。
66
+
67
+ **2. 确认计划** — Planner 会在 `docs/plans/` 生成 `TaskIntent`(范围、风险等级、验收条件)。检查无误后在 TUI 弹窗中确认 Enrollment(所有风险等级都需要确认,确认前零写入)。
68
+
69
+ **3. 开始执行** — `imm-loop` 按计划执行、跑 QA、触发 Review。按提示暂存任务拥有的文件:
70
+
71
+ ```bash
72
+ git add -- <任务拥有的文件> <另一个文件>
73
+ ```
74
+
75
+ QA 与 Review 以 foreground Tool 形式运行并回传结果,返回 `phase=done` 即完成。
76
+
77
+ ---
78
+
79
+ ## 如何使用
80
+
81
+ 大多数情况下**无需记忆 Skill 名称**,直接描述意图即可:
82
+
83
+ | 你的情况 | 你说什么 / 做什么 | 会发生什么 |
84
+ |---|---|---|
85
+ | 想法模糊,需要收敛 | "帮我梳理一下通知系统的方案" | → `imm-brainstorm` 提问澄清,不改代码 |
86
+ | 目标明确,需要计划 | "规划一下深色模式功能" 或让 Pi 自动路由 | → `imm-planner` 产出 `TaskIntent` + spec |
87
+ | 计划已确认,准备开干 | "开始构建" / `imm-loop` | → Executor 构建 → QA 验证 → Review 审查 |
88
+ | PR 被评论 / CI 挂了 | 对该 PR 使用 `imm-pr-fix` | → 独立修复,不创建新 managed 任务 |
89
+ | 文档过时需要清理 | `imm-doc-prune` + manifest | → 仅删除已审批的过时文档 |
90
+
91
+ > **规则:** Managed 工作流(brainstorm → plan → loop)仅由显式的 `imm-brainstorm`、`imm-planner`、`imm-loop` 启动。普通问答、只读解释不会 Enrollment。
92
+
93
+ ---
94
+
95
+ ## 5 个 Skills
96
+
97
+ | Skill | 类型 | 何时使用 | 职责 |
98
+ |---|---|---|---|
99
+ | `imm-brainstorm` | Managed 入口 | 需求存在实质歧义 | 框架化问题、提出开放问题,不做实现 |
100
+ | `imm-planner` | Managed 入口 | 目标清晰 | 编写/修订 `TaskIntent` 与 spec,不负责 Enrollment 与构建 |
101
+ | `imm-loop` | Managed 协调器 | 计划已验证 | 通过 foreground Tools 协调 执行 → QA → Review → 收尾 |
102
+ | `imm-pr-fix` | 独立 | PR 需修复 | 原地修复单个 PR,不触及 managed authority |
103
+ | `imm-doc-prune` | 独立 | 清理过时文档 | 仅删除哈希绑定的 manifest 条目 |
104
+
105
+ Executor、QA、Review、Compounder 等为 `imm-loop` 内部调度的角色,无需手动调用。
106
+
107
+ **推荐默认:** 让自然语言路由自动选择 brainstorm 还是 planner,仅在想强制进入某阶段时才显式调用 Skill。
108
+
109
+ ---
110
+
111
+ ## 生命周期
112
+
113
+ ```
114
+ 你:自然语言请求
115
+
116
+ ├── 模糊 ──→ imm-brainstorm(澄清,不改代码)
117
+
118
+ └── 明确 ──→ imm-planner ──→ TaskIntent(Git-tracked)
119
+
120
+ TUI 确认(enrollment)
121
+
122
+ imm-loop
123
+ ├── Executor(仅在 scope 内编辑)
124
+ ├── QA(确定性检查必须通过)
125
+ ├── Review(material/critical:隔离 subagent)
126
+ └── done
127
+ ```
128
+
129
+ 核心不变量:
130
+
131
+ - **一次仅一个活跃步骤**,编辑仅在步骤边界内。
132
+ - **范围(`scope_hint`)在 enrollment 时冻结**,范围外文件被忽略。
133
+ - **先记录证据再关闭** — 只有 QA 能关闭步骤。
134
+ - **Advisory 不实现,执行不自审。**
135
+
136
+ ---
137
+
138
+ ## 配置
139
+
140
+ Immune-Brain **没有独立配置文件**,偏好设置写在 `AGENTS.md`(仓库根目录或 `~/.pi/agent/AGENTS.md`):
141
+
142
+ ```md
143
+ ## Immune-Brain Preferences
144
+
145
+ - Initiative carrier default: github # 或 local
146
+ ```
147
+
148
+ | 偏好 | 选项 | 默认 | 说明 |
149
+ |---|---|---|---|
150
+ | 回复语言 | 任意自然语言 | 仓库 `AGENTS.md` | 机器契约/路径/标识符保持原文 |
151
+ | Initiative 载体 | `local` / `github` | `github` | 仅当提案拆分为多个 TaskIntent 时生效 |
152
+ | Advisory subagent | 允许 / 单人 | 允许 | 受 Pi host 策略与用户显式指令约束 |
153
+
154
+ 优先级:**当前消息 > 仓库 `AGENTS.md` > `~/.pi/agent/AGENTS.md` > Skill 默认值**。
155
+
156
+ 详见 [`docs/reference/immune-brain-config.md`](docs/reference/immune-brain-config.md)。
157
+
158
+ ---
159
+
160
+ ## 项目结构
161
+
162
+ ```text
163
+ package.json # Pi package manifest(skills + extensions)
164
+ plugins/immune-brain/
165
+ ├── .pi-extension/ # Pi TUI + Kernel 扩展
166
+ ├── skills/ # 5 个公开 Skills(触发 shim)
167
+ ├── dist/ # 构建后的 skill 契约与参考文档
168
+ ├── runtime/ # Bun + TypeScript 运行时与 Kernel
169
+ └── bin/ # CLI wrappers(→ runtime/v4_runtime.ts)
170
+
171
+ .imm/ # 任务状态(worktree-local,git-ignored)
172
+ docs/plans/ # 活跃 TaskIntents(*.intent.json)
173
+ docs/specs/ # Living specs(原地更新)
174
+ ```
175
+
176
+ - `.imm/state/` — 活跃任务;`.imm/audit/<task-id>/` — 已结算证据(tracked)。
177
+ - `docs/plans/*.intent.json` 必须在 enrollment 前 **Git-tracked**。
178
+ - `CONTEXT.md` 仅作词汇与导航,不作为运行时状态来源。
179
+
180
+ ---
181
+
182
+ ## 常见问题
183
+
184
+ **需要记住所有 Skill 吗?** 不需要,直接描述需求即可,Pi 会自动路由。先掌握 `imm-planner` 和 `imm-loop`,另外两个按需使用。
185
+
186
+ **中途关闭 Pi 会怎样?** 状态已落盘(`.imm/` + TaskIntent),重新进入 `imm-loop` 即可恢复,以 Kernel projection 为准。
187
+
188
+ **为什么 enrollment 要弹窗确认?** 所有风险等级(`routine`/`material`/`critical`)都需要显式确认,弹窗绑定 staged digest,让你清楚看到将被追踪的内容。
189
+
190
+ **QA 失败怎么办?** QA 返回 `rework` 或 `replan_required`,`imm-loop` 会自动路由回 Executor 或 `imm-planner` 调整范围,无需手动重置。
191
+
192
+ **可以在 Pi 之外使用吗?** 不可以,Pi 是唯一支持的宿主。
193
+
194
+ ---
195
+
196
+ ## 发布
197
+
198
+ 本仓库使用 [Changesets](https://github.com/changesets/changesets) 管理版本与发布。
199
+
200
+ | 任务 | 命令 |
201
+ |------|------|
202
+ | 创建 changeset | `bunx changeset` — 选择 bump 类型(patch/minor/major)并填写说明 |
203
+ | 升级版本 | `bun run changeset:version` — 更新 `package.json` + `CHANGELOG.md` |
204
+ | 本地发布 | `bun run changeset:publish` — 发布到 npm(需 `NPM_TOKEN` 或 `npm login`) |
205
+
206
+ **自动化流程(推荐):**
207
+ 1. 推送 changeset 到 `main` → workflow 自动创建 “Version Packages” PR。
208
+ 2. 合并该 PR → workflow 发布到 npm、创建 GitHub Release,并打 tag `immune-brain-vX.Y.Z`。
209
+
210
+ 配置:在 GitHub 仓库 Secrets 中添加 `NPM_TOKEN`(有发布权限的 npm token)。Workflow 为 `.github/workflows/release.yml`,基于 `changesets/action@v1`。
211
+
212
+ **首次发布(2.8.1):**
213
+ ```bash
214
+ npm publish --access public # 首次发布,需 npm login / NPM_TOKEN
215
+ # 或
216
+ bun run changeset:publish
217
+ ```
218
+ 包名为 scoped `@immune-brain/agent-skills`,已配置 `publishConfig.access=public`。首次发布后,后续所有版本均通过 changesets 管理。
219
+
220
+ 详见 `CHANGELOG.md` 与 `.changeset/config.json`(changelog: `@changesets/changelog-github`,repo: `dereknex/immune-brain`)。
221
+
222
+ ---
223
+
224
+ ## 开发者指南
225
+
226
+ 面向 Immune-Brain 本身的贡献者:
227
+
228
+ ```bash
229
+ bun test # 全量测试(以 bun test 为准,非 tsc)
230
+ mise run check-plugin # 插件结构 + 版本校验
231
+ mise run check-dist-sync # 生成的 dist 文档同步校验
232
+ ```
233
+
234
+ - 运行时为 `runtime/v4_runtime.ts`(Bun + TypeScript),`scripts/` 下的 Python 仅为历史参考。
235
+ - 生产 CLI:`plugins/immune-brain/bin/imm-kernel`,完整命令表见 [`plugins/immune-brain/README.md`](plugins/immune-brain/README.md)。
236
+
237
+ ---
238
+
239
+ *License: MIT*
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "immune-brain",
3
+ "version": "2.8.2",
4
+ "description": "Immune-Brain agent skill system",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org/"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/dereknex/immune-brain.git"
12
+ },
13
+ "homepage": "https://github.com/dereknex/immune-brain#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/dereknex/immune-brain/issues"
16
+ },
17
+ "author": "Immune-Brain Team",
18
+ "license": "MIT",
19
+ "keywords": [
20
+ "pi-package"
21
+ ],
22
+ "pi": {
23
+ "skills": [
24
+ "./plugins/immune-brain/skills"
25
+ ],
26
+ "extensions": [
27
+ "./plugins/immune-brain/.pi-extension"
28
+ ]
29
+ },
30
+ "scripts": {
31
+ "changeset": "changeset",
32
+ "changeset:version": "changeset version",
33
+ "changeset:publish": "changeset publish",
34
+ "release": "bun run changeset:publish"
35
+ },
36
+ "devDependencies": {
37
+ "@changesets/changelog-github": "^0.5.2",
38
+ "@changesets/cli": "^2.29.8",
39
+ "zod": "^4.1.8"
40
+ },
41
+ "peerDependencies": {
42
+ "@earendil-works/pi-coding-agent": "*",
43
+ "@earendil-works/pi-tui": "*",
44
+ "typebox": "*"
45
+ },
46
+ "imports": {
47
+ "#kernel/enrollment_authority": "./plugins/immune-brain/runtime/kernel/enrollment_authority.ts",
48
+ "#kernel/pi_canary_prepare": "./plugins/immune-brain/runtime/kernel/pi_canary_prepare.ts",
49
+ "#kernel/canary_eligibility": "./plugins/immune-brain/runtime/kernel/canary_eligibility.ts",
50
+ "#kernel/enrollment": "./plugins/immune-brain/runtime/kernel/enrollment.ts",
51
+ "#kernel/authority_port": "./plugins/immune-brain/runtime/kernel/authority_port.ts",
52
+ "#kernel/canary_application": "./plugins/immune-brain/runtime/kernel/canary_application.ts",
53
+ "#kernel/backend_claim": "./plugins/immune-brain/runtime/kernel/backend_claim.ts",
54
+ "#kernel/storage": "./plugins/immune-brain/runtime/kernel/storage.ts",
55
+ "#kernel/intent": "./plugins/immune-brain/runtime/kernel/intent.ts",
56
+ "#kernel/reducer": "./plugins/immune-brain/runtime/kernel/reducer.ts"
57
+ },
58
+ "exports": {
59
+ ".": "./README.md",
60
+ "./package.json": "./package.json",
61
+ "./dist/*": "./plugins/immune-brain/dist/*",
62
+ "./skills/*": "./plugins/immune-brain/skills/*",
63
+ "./extensions/*": "./plugins/immune-brain/.pi-extension/*"
64
+ },
65
+ "files": [
66
+ "plugins/immune-brain/.pi-extension",
67
+ "plugins/immune-brain/runtime/v4_runtime.ts",
68
+ "plugins/immune-brain/runtime/plan_core.ts",
69
+ "plugins/immune-brain/runtime/commands/kernel.ts",
70
+ "plugins/immune-brain/runtime/kernel",
71
+ "plugins/immune-brain/runtime/canonical_json.ts",
72
+ "plugins/immune-brain/runtime/workspace_scope.ts",
73
+ "plugins/immune-brain/runtime/authority_commit_receipts.ts",
74
+ "plugins/immune-brain/runtime/managed_task_routing_policy.ts",
75
+ "plugins/immune-brain/runtime/github_issue_tracker.ts",
76
+ "plugins/immune-brain/runtime/verification_descriptor.ts",
77
+ "plugins/immune-brain/runtime/role_prompt_bridge.ts",
78
+ "plugins/immune-brain/runtime/loop_contract.ts",
79
+ "plugins/immune-brain/runtime/prompts",
80
+ "plugins/immune-brain/skills",
81
+ "plugins/immune-brain/dist",
82
+ "plugins/immune-brain/bin"
83
+ ]
84
+ }