pi-claude-supervisor 0.5.2 → 0.5.3
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.
- package/CHANGELOG.md +12 -1
- package/README.cn.md +45 -36
- package/README.md +70 -41
- package/docs/architecture.md +65 -38
- package/docs/automation-hardening-plan.md +23 -22
- package/docs/autonomy-target.md +127 -0
- package/docs/engineering-plan.md +136 -138
- package/docs/implementation-review.md +29 -14
- package/docs/independent-review.md +23 -18
- package/docs/releasing.md +7 -2
- package/docs/testing.md +36 -22
- package/package.json +1 -1
- package/src/acceptance.ts +16 -0
- package/src/config.ts +31 -0
- package/src/decision-session-store.ts +19 -1
- package/src/decision-worker.ts +46 -18
- package/src/index.ts +37 -48
- package/src/notifications.ts +29 -11
- package/src/policy.ts +196 -21
- package/src/reviewer.ts +26 -1
- package/src/state.ts +7 -6
- package/src/supervisor.ts +329 -119
- package/src/types.ts +23 -0
- package/src/verifier.ts +88 -6
- package/src/worker/environment.ts +169 -0
- package/src/worker/process-adapter.ts +15 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# 自动化稳定性与生命周期加固计划
|
|
2
2
|
|
|
3
|
-
> 计划状态:Phase A–D
|
|
4
|
-
> 基线:`v0.5.
|
|
3
|
+
> 计划状态:Phase A–D、真实可编辑 repair/reacceptance、exact-head 独立只读 Review、受保护发布和本地无人值守闭环已完成;远程 push/main merge 仍是独立边界。
|
|
4
|
+
> 基线:`v0.5.2` / `eefc7bc`
|
|
5
5
|
> 真实验证:Claude Code `2.1.270`
|
|
6
6
|
> 记录日期:2026-09-14
|
|
7
7
|
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
-> argv/execFile 验收
|
|
16
16
|
-> 独立只读 Reviewer
|
|
17
17
|
-> P1/P2 阻塞发现
|
|
18
|
-
-> fail-closed /
|
|
18
|
+
-> fail-closed / parked non-publishable candidate
|
|
19
19
|
-> Worker、Pi、lease 清理
|
|
20
20
|
```
|
|
21
21
|
|
|
@@ -141,15 +141,17 @@ diff: (none)
|
|
|
141
141
|
- `repairableSession` 与 `persistentSession` 已分离;JSONL 仅支持当前进程内 repair,tmux 才声明持久恢复。
|
|
142
142
|
- `verifying` 的 stop/shutdown 使用统一 cleanup/finalize 路径,人工 stop 优先于验收结果,cleanup 不确定时保留恢复记录。
|
|
143
143
|
- paused Worker 不消耗 no-output watchdog;resume 重建 no-output 基准,但不重置累计 deadline。
|
|
144
|
-
- Reviewer evidence
|
|
145
|
-
- Acceptance 子进程、证据收集和 Reviewer 共享 abort signal;Pi UI 可看到 startup、Worker heartbeat、acceptance、review、repair 和
|
|
146
|
-
- 自动模式启动前检查运行目录、cwd、Worker
|
|
147
|
-
-
|
|
144
|
+
- Reviewer evidence 使用任务 baseline-relative diff、baseline 后 commit summaries、受限 untracked regular-file 内容、路径组件/symlink 门禁,并对 incomplete/truncated fail-closed。
|
|
145
|
+
- Acceptance 子进程、证据收集和 Reviewer 共享 abort signal;Pi UI 可看到 startup、Worker heartbeat、acceptance、review、repair 和 candidate/decision phases。
|
|
146
|
+
- 自动模式启动前检查运行目录、cwd、Worker 可执行文件、transport 依赖和 required cgroup;显式
|
|
147
|
+
`process-pipe` 和 `tmux` 不再进入自动模式,后者保留为手动 PTY transport。
|
|
148
|
+
- Reviewer/Decision Worker 只解析 assistant message 边界的最终文本;permission pending 会在自动响应后清除,候选状态不会被错误解除;扩大的 exec buffer 避免普通大测试报告被误判为命令失败。
|
|
148
149
|
|
|
149
|
-
|
|
150
|
+
本轮已完成:
|
|
150
151
|
|
|
151
|
-
-
|
|
152
|
-
-
|
|
152
|
+
- 普通本地命令和权限不再进入同步人工审批;Decision Worker 的无效输出、API 错误、Reviewer 失败、P0/P1、重复 finding、证据不完整和预算耗尽会进入 `blocked` 候选。
|
|
153
|
+
- TaskSpec 和环境变量提供 unattended/local-commit/Decision retry 控制;Worker 可在本地修改、测试、修复并提交,push、merge、发布和破坏性边界仍硬拒绝并写入审计。
|
|
154
|
+
- replay、候选通知和 baseline-relative commit evidence 覆盖正常完成、修复、歧义和挂起;保持独立 Review、保护 CI、Release Please 和 provenance 发布边界。
|
|
153
155
|
|
|
154
156
|
## 4. 实施顺序
|
|
155
157
|
|
|
@@ -157,23 +159,23 @@ diff: (none)
|
|
|
157
159
|
|
|
158
160
|
1. 增加 `repairableSession` capability。
|
|
159
161
|
2. JSONL 在当前 Supervisor 生命周期内支持 repair,仍不声明跨重启恢复。
|
|
160
|
-
3. 重构 repair/finalize/
|
|
162
|
+
3. 重构 repair/finalize/candidate 分支,保证终态转换和 Decision Worker closure 幂等。
|
|
161
163
|
4. `verifying` 支持 stop/shutdown,保留 cleanup 不确定时的 lease。
|
|
162
164
|
5. 增加真实非持久 adapter 和 stop-from-verifying 测试。
|
|
163
165
|
|
|
164
166
|
### Phase B:watchdog 与证据完整性
|
|
165
167
|
|
|
166
168
|
1. paused no-output 时钟暂停,resume 重建基准。
|
|
167
|
-
2. HEAD-relative diff 覆盖 staged/unstaged tracked
|
|
169
|
+
2. 记录任务开始时的 HEAD;baseline-relative diff 覆盖 committed/staged/unstaged tracked 修改,并记录 baseline 后 commits。
|
|
168
170
|
3. 安全收集 untracked regular-file evidence,防 symlink 和路径逃逸。
|
|
169
|
-
4. evidence truncation/incomplete
|
|
171
|
+
4. evidence truncation/incomplete 生成不可发布候选并自动挂起,不能自动 `pass`。
|
|
170
172
|
|
|
171
173
|
### Phase C:自动化协议和运行前保护
|
|
172
174
|
|
|
173
175
|
1. Reviewer/Decision Worker 按 assistant message 边界解析最终响应,不拼接所有工具回合文字。
|
|
174
176
|
2. 自动模式启动前执行 transport、Claude、cgroup、state/lease 目录 preflight。
|
|
175
177
|
3. 区分 Worker heartbeat、验收、Reviewer、repair 阶段,并提高实时可观测性。
|
|
176
|
-
4. 修复自动 permission 响应后的 stale pending request
|
|
178
|
+
4. 修复自动 permission 响应后的 stale pending request,并使本地决策不会依赖同步 human gate。
|
|
177
179
|
5. 清理 Pi extension 自己安装的 signal handler,避免与 Pi `session_shutdown` 竞争。
|
|
178
180
|
|
|
179
181
|
### Phase D:回归、真实演练和发布门禁
|
|
@@ -181,23 +183,22 @@ diff: (none)
|
|
|
181
183
|
1. 扩展 acceptance/replay/capability 矩阵。
|
|
182
184
|
2. 在临时 worktree 中使用真实 Claude 做一次受控 repair/reacceptance;禁止触碰主仓库。
|
|
183
185
|
3. 运行 `npm run check`、Pi/npm smoke、build 和真实只读 review。
|
|
184
|
-
4. 只有独立 Reviewer `pass`、所有检查通过、cleanup/lease
|
|
185
|
-
决定是否提交、合并或发布。
|
|
186
|
+
4. 只有独立 Reviewer `pass`、所有检查通过、cleanup/lease 证据完整后,才生成可交付本地候选;远程 push 和 main/integration merge 仍必须经过独立边界。
|
|
186
187
|
|
|
187
188
|
## 5. 验收矩阵
|
|
188
189
|
|
|
189
190
|
| 场景 | 预期 |
|
|
190
191
|
|---|---|
|
|
191
192
|
| JSONL Worker alive + P2 revise | 发送一次 bounded repair,重新验收 |
|
|
192
|
-
| JSONL Worker 已退出 + 验收失败 | 不抛非法 transition,记录 `verification_failed
|
|
193
|
-
| Reviewer `human` + Worker alive |
|
|
194
|
-
| Reviewer `human` + Worker 已退出 | 完成 cleanup、关闭 Decision Worker、保留 recoverable record |
|
|
193
|
+
| JSONL Worker 已退出 + 验收失败 | 不抛非法 transition,记录 `verification_failed`,生成不可发布候选 |
|
|
194
|
+
| Reviewer `human` + Worker alive | 不自动完成;按预算修复或挂起 `blocked` 候选,不要求人工在线 |
|
|
195
|
+
| Reviewer `human` + Worker 已退出 | 完成 cleanup、关闭 Decision Worker、保留 recoverable/parked record |
|
|
195
196
|
| `stop()` from `verifying` | `stopped`、cleanup confirmed 后释放 lease |
|
|
196
197
|
| shutdown from `verifying` | 不泄漏 Worker、Decision Worker 或 cwd lease |
|
|
197
198
|
| pause 超过 no-output timeout | 仍保持 paused |
|
|
198
199
|
| resume 后无输出 | 从 resume 时刻重新计算 timeout |
|
|
199
200
|
| staged + untracked 修改 | Reviewer evidence 包含两者 |
|
|
200
|
-
| evidence 截断/不可验证 | Reviewer
|
|
201
|
+
| evidence 截断/不可验证 | Reviewer 只能阻止 `pass`,候选自动挂起 |
|
|
201
202
|
| malformed/multi-message model output | 不误判为 pass/action |
|
|
202
203
|
| preflight 失败 | Claude 尚未启动前 fail-closed |
|
|
203
204
|
|
|
@@ -206,6 +207,6 @@ diff: (none)
|
|
|
206
207
|
- Reviewer 继续只允许 `read`、`grep`、`find`、`ls`。
|
|
207
208
|
- 验收命令继续使用 argv 和 `execFile`,不经过 shell 拼接。
|
|
208
209
|
- 不伪造 Claude `--resume`;`resumeSession` 仍然是明确能力声明。
|
|
209
|
-
-
|
|
210
|
+
- Worker 不得远程 push 或 merge 到 main/integration;发布仍走独立受保护 workflow。
|
|
210
211
|
- 不允许多 Worker 共享同一可写 worktree。
|
|
211
|
-
- P0/P1、重复 finding、超时、API 错误、无效输出和不完整证据继续 fail-closed
|
|
212
|
+
- P0/P1、重复 finding、超时、API 错误、无效输出和不完整证据继续 fail-closed,并自动生成不可发布/挂起候选,而不是要求同步人工响应。
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Confirmed autonomy target
|
|
2
|
+
|
|
3
|
+
> Owner-confirmed product requirement: local development is fully unattended; code entering a remote repository or the main/integration branch must cross an independent boundary.
|
|
4
|
+
|
|
5
|
+
This document is authoritative for the autonomy direction. Earlier planning text that treats a
|
|
6
|
+
human as a synchronous approval step for ordinary local development is historical conservative
|
|
7
|
+
baseline text and must not be used to add a new gate to the local development loop.
|
|
8
|
+
|
|
9
|
+
## 1. Target operating model
|
|
10
|
+
|
|
11
|
+
Once a task has been started with its task specification, the local development loop may run
|
|
12
|
+
without a human watching it:
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
Worker edits and runs local commands
|
|
16
|
+
-> acceptance checks
|
|
17
|
+
-> independent Reviewer
|
|
18
|
+
-> bounded repair/reacceptance
|
|
19
|
+
-> local commit/candidate artifact
|
|
20
|
+
-> independent remote/main integration boundary
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The Supervisor may continue, answer, repair, test, review and commit locally. A human is not a
|
|
24
|
+
synchronous dependency for ordinary progress, routine ambiguity, or a normal failed test.
|
|
25
|
+
|
|
26
|
+
The system must still provide a kill switch, bounded execution, cleanup verification and a
|
|
27
|
+
complete audit trail. These are reliability and containment mechanisms, not requests for a human
|
|
28
|
+
to approve every development action. Automatic mode also records and revalidates a full existing
|
|
29
|
+
repository baseline, captures the startup HEAD and requires that exact HEAD again at
|
|
30
|
+
final pre-spawn, requires a non-protected branch and a pinned operator-owned direct Claude
|
|
31
|
+
JSONL Worker, and by default requires a local commit before a candidate is deliverable.
|
|
32
|
+
|
|
33
|
+
## 2. Hard authority boundary
|
|
34
|
+
|
|
35
|
+
Automatic Worker supervision uses the structured JSONL transport; the interactive tmux transport
|
|
36
|
+
remains manual-only because it has no equivalent permission-response boundary. The Worker and local
|
|
37
|
+
automation do **not** receive authority or credentials for:
|
|
38
|
+
|
|
39
|
+
- pushing code to a remote repository;
|
|
40
|
+
- merging into `main` or another protected integration branch;
|
|
41
|
+
- starting automatic candidate work directly on a protected integration branch; repositories with a
|
|
42
|
+
branch use a non-protected local branch for unattended work;
|
|
43
|
+
- inheriting Git/GitHub/package credential helpers or explicitly selected remote credentials in
|
|
44
|
+
automatic mode.
|
|
45
|
+
|
|
46
|
+
A completed local task is a candidate until it passes the independent boundary. That boundary may
|
|
47
|
+
be a later read-only review, CI policy, a maintainer action, or an explicit shutdown/rejection.
|
|
48
|
+
The Worker must not be able to bypass it through a prompt, a local decision, or a model response.
|
|
49
|
+
|
|
50
|
+
This is the required authority boundary. Automatic mode admits only the bare direct Claude
|
|
51
|
+
command name and pins its operator-owned resolved executable because its fail-closed Claude Code
|
|
52
|
+
sandbox is part of the supported boundary; explicit paths and arbitrary custom executables must
|
|
53
|
+
use manual mode or an independently hardened integration. No additional
|
|
54
|
+
synchronous human-approval boundary should be invented for local editing, local tests, local
|
|
55
|
+
commits, or local repair unless the task owner explicitly configures one.
|
|
56
|
+
|
|
57
|
+
## 3. Unattended decision behavior
|
|
58
|
+
|
|
59
|
+
The Decision Worker should resolve ordinary development decisions from the task specification,
|
|
60
|
+
repository evidence and configured task policy, and record its assumptions and actions. It should
|
|
61
|
+
not turn every uncertainty into an interactive human prompt.
|
|
62
|
+
|
|
63
|
+
If the system cannot safely reach a candidate, it may automatically retry within the configured
|
|
64
|
+
budget, mark the task blocked/failed, preserve the worktree and evidence, or park it for later
|
|
65
|
+
inspection. “Parked for later inspection” is not the same as requiring a human to be online before
|
|
66
|
+
other tasks can proceed.
|
|
67
|
+
|
|
68
|
+
A task that reaches `blocked`, `review_pending` or `candidate_failed` must not be pushed or merged.
|
|
69
|
+
The same rule applies to a ready local candidate until the independent remote/main boundary accepts it.
|
|
70
|
+
It may be resumed, repaired or discarded later without weakening the remote/main boundary.
|
|
71
|
+
|
|
72
|
+
## 4. Acceptance and independent review
|
|
73
|
+
|
|
74
|
+
Acceptance and Reviewer remain automatic parts of the local loop:
|
|
75
|
+
|
|
76
|
+
- run all required checks;
|
|
77
|
+
- collect complete baseline-relative status, commit and untracked evidence;
|
|
78
|
+
- run the independent read-only Reviewer;
|
|
79
|
+
- apply bounded repair rounds;
|
|
80
|
+
- re-run acceptance and Review;
|
|
81
|
+
- produce a candidate with its evidence and assumptions.
|
|
82
|
+
|
|
83
|
+
Reviewer findings are first an automatic repair input. Exhausted budgets, incomplete evidence,
|
|
84
|
+
invalid output, duplicate findings or an unresolved finding produce a non-publishable
|
|
85
|
+
candidate/parked task; they do not by themselves require a synchronous takeover notification.
|
|
86
|
+
|
|
87
|
+
## 5. Notifications and shutdown
|
|
88
|
+
|
|
89
|
+
Progress, assumptions, failures and candidate readiness must be recorded in the event log. Live
|
|
90
|
+
notifications are optional delivery policy, not the local development control protocol.
|
|
91
|
+
|
|
92
|
+
Immediate shutdown remains appropriate for technical containment failures such as an unverified
|
|
93
|
+
Worker cleanup boundary, corrupted control state or an explicit operator kill. The system should
|
|
94
|
+
stop or park safely and retain evidence; it must not silently grant remote or main-branch access.
|
|
95
|
+
|
|
96
|
+
## 6. Current implementation
|
|
97
|
+
|
|
98
|
+
Automatic mode implements the local loop: policy decisions allow ordinary local development,
|
|
99
|
+
`AskUserQuestion` is converted to a denied interactive permission, the Decision Worker can
|
|
100
|
+
continue/redirect/answer/repair, acceptance and independent Review run without a human callback,
|
|
101
|
+
and unresolved situations become `blocked` candidates. The default task autonomy is unattended, requires a local commit, and permits two bounded
|
|
102
|
+
Decision Worker request retries. Automatic startup rejects non-Git/detached/bare/protected
|
|
103
|
+
repository states, malformed baselines, startup-HEAD races, non-JSONL transports and
|
|
104
|
+
non-Claude or untrusted executable identities before Worker startup. The resolved
|
|
105
|
+
executable identity is persisted with the Decision Worker recovery record and must match
|
|
106
|
+
again during recovery.
|
|
107
|
+
|
|
108
|
+
Legacy `humanRequired`, takeover and approval fields remain for compatibility and explicit operator
|
|
109
|
+
control. They are not entered by ordinary uncertainty, and a legacy approval object cannot override
|
|
110
|
+
the deterministic remote push/main merge denial. The existing independent Review and protected
|
|
111
|
+
CI/release paths remain the final external checks. Built-in automatic Claude workers request a fail-closed Claude Code Bash sandbox with no
|
|
112
|
+
outbound domains; automatic command policy and credential filtering remain defense in depth.
|
|
113
|
+
Full host-level sandboxing for custom Worker integrations is separate hardening work.
|
|
114
|
+
|
|
115
|
+
## 7. Explicit non-goals of this target
|
|
116
|
+
|
|
117
|
+
This target does not authorize:
|
|
118
|
+
|
|
119
|
+
- remote push from the Worker;
|
|
120
|
+
- merge into `main` from the Worker;
|
|
121
|
+
- bypassing the independent integration boundary;
|
|
122
|
+
- silently treating incomplete evidence as success;
|
|
123
|
+
- claiming that a failed or parked task completed.
|
|
124
|
+
|
|
125
|
+
Coordinated multi-Worker scheduling, OS sandboxing and broader CLI compatibility remain separate
|
|
126
|
+
engineering milestones. They must not be used to add synchronous human approval to the local
|
|
127
|
+
development loop.
|