pi-claude-supervisor 0.3.0 → 0.4.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.
package/CHANGELOG.md CHANGED
@@ -2,12 +2,31 @@
2
2
 
3
3
  All notable changes to this project will be documented here.
4
4
 
5
+ ## [0.4.1](https://github.com/btnalit/pi-claude-supervisor/compare/v0.4.0...v0.4.1) (2026-09-14)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * reconcile detached tmux leases and validate prompts ([d20262c](https://github.com/btnalit/pi-claude-supervisor/commit/d20262c8481ca761a48f7dc2b877951173d4681e))
11
+
12
+ ## [0.4.0](https://github.com/btnalit/pi-claude-supervisor/compare/v0.3.0...v0.4.0) (2026-09-13)
13
+
14
+
15
+ ### Features
16
+
17
+ * add cross-process cwd leases and cancellable startup ([#17](https://github.com/btnalit/pi-claude-supervisor/issues/17)) ([448cbdb](https://github.com/btnalit/pi-claude-supervisor/commit/448cbdb4c6b5dd02b9ea07ba660d3689b7e2ace8))
18
+
5
19
  ## [0.3.0](https://github.com/btnalit/pi-claude-supervisor/compare/v0.2.2...v0.3.0) (2026-09-13)
6
20
 
7
21
 
8
22
  ### Features
9
23
 
10
24
  * add safe tmux Claude worker transport ([1706153](https://github.com/btnalit/pi-claude-supervisor/commit/1706153289f9a6f7f9f59b2763ed98d061b79204))
25
+ * add cross-process canonical cwd leases and identity-bound tmux handoff
26
+ * make startup cancellation scoped per start and shutdown cleanup fail closed
27
+ * add cgroup-v2 required/auto/off policies with verified fallback cleanup
28
+ * harden owned/adopted tmux lifecycle, pane identity validation, and restart re-adoption
29
+ * validate real Claude Code 2.1.270 tmux multi-turn, pause/resume, and re-adoption behavior
11
30
 
12
31
  ## [0.2.2](https://github.com/btnalit/pi-claude-supervisor/compare/v0.2.1...v0.2.2) (2026-09-12)
13
32
 
@@ -47,7 +66,7 @@ All notable changes to this project will be documented here.
47
66
  - Bounded output capture, stdin-write timeout, process-group cleanup retry and stop preemption.
48
67
  - Linux cgroup-v2 descendant cleanup, including a `setsid()` regression fixture, with required/auto modes.
49
68
  - Lifecycle event retry/order preservation, output restoration after log failure and shutdown cleanup retries.
50
- - Claude CLI 2.1.268 permission allow/deny and SIGTERM/SIGINT transport spike evidence.
69
+ - Historical Claude CLI 2.1.268 permission allow/deny and SIGTERM/SIGINT transport spike evidence; current release validation uses Claude CLI 2.1.270.
51
70
  - Event-driven JSONL `control_request`/`result`/exit events, permission responses, persistent Pi Decision Worker automation, bounded duplicate/turn handling, and outbound human-intervention webhooks.
52
71
  - Long-task defaults are now 100 automatic turns, 4 hours wall time and 20 minutes without output; Decision Worker API failures alert human operators directly instead of attempting an LLM fallback.
53
72
  - Automatic Decision Worker sessions now persist as Pi JSONL with a 0600 task registry. Unclean Pi restarts expose explicit `/supervise recover <task-id>` recovery; Claude work is not silently duplicated.
@@ -55,5 +74,5 @@ All notable changes to this project will be documented here.
55
74
 
56
75
  ### Limitations
57
76
 
58
- - tmux/PTY screen state is not Claude JSONL: trust, permission and ambiguous TUI states require human handling. Cross-version Claude CLI permission/session semantics remain outside the pinned compatibility claim. The installed 2.1.268 CLI is covered by local permission and signal spikes, while the cgroup startup-attachment window remains.
77
+ - tmux/PTY screen state is not Claude JSONL: trust, permission and ambiguous TUI states require human handling. Cross-version Claude CLI permission/session semantics remain outside the pinned compatibility claim. Historical permission and signal spikes use 2.1.268; current tmux validation uses 2.1.270, while the cgroup startup-attachment window remains.
59
78
  - No automatic merge, deployment, release or publication is implemented.
package/README.cn.md CHANGED
@@ -42,9 +42,9 @@ export PI_CLAUDE_SUPERVISOR_HUMAN_WEBHOOK_FORMAT=generic
42
42
  # export PI_CLAUDE_SUPERVISOR_HUMAN_WEBHOOK_SECRET='shared-secret'
43
43
  ```
44
44
 
45
- 自动模式会强制使用 `claude-jsonl`,通过 `result`、`control_request` 和进程
46
- `exit` 事件唤醒 Decision Worker;不会依赖 `/supervise poll` 轮询。本版本固定按已验证设备的
47
- Claude CLI `2.1.268` 运行,跨版本兼容性不在本轮范围内。
45
+ 自动模式默认使用 `claude-jsonl`,通过 `result`、`control_request` 和进程
46
+ `exit` 事件唤醒 Decision Worker;显式选择 tmux 时仍使用屏幕交互,不使用 JSONL 权限协议,也不会依赖 `/supervise poll` 轮询。本版本固定按已验证设备的
47
+ Claude CLI `2.1.270` 运行,跨版本兼容性不在本轮范围内。
48
48
 
49
49
  然后在 Pi 中使用:
50
50
 
@@ -108,7 +108,9 @@ export PI_CLAUDE_SUPERVISOR_WORKER='claude --permission-mode plan'
108
108
  /supervise adopt-tmux <tmux-session-name> <task description>
109
109
  ```
110
110
 
111
- 接管会检查 cwd、pane 中的进程,并拒绝已有其他输出 pipe 的 pane;但不宣称拥有该 session。对被接管的 session,
111
+ 接管会检查 cwd、pane 中的进程,并拒绝已有其他输出 pipe 的 pane;但不宣称拥有该 session。owned session 使用自动生成的私有 tmux socket,
112
+ 请保存 `start` 输出的完整 `attach=...` 命令。Pi 重启后重新接管时,先把该命令中的 socket 路径设置到
113
+ `PI_CLAUDE_SUPERVISOR_TMUX_SOCKET`;只有默认 server 才能只使用 session 名称。对被接管的 session,
112
114
  `/supervise stop` 和 Pi 关闭只会断开监督,不会杀掉你的 tmux 窗口;需要关闭时请由你执行
113
115
  `tmux kill-session`。`/supervise takeover <task-id>` 会暂停 Decision Worker 自动发送,只有
114
116
  `/supervise resume-auto <task-id>` 才恢复。
package/README.md CHANGED
@@ -104,6 +104,7 @@ For an interactive Claude Code window, opt in to the tmux transport:
104
104
  ```bash
105
105
  export PI_CLAUDE_SUPERVISOR_TRANSPORT=tmux
106
106
  export PI_CLAUDE_SUPERVISOR_WORKER='claude --permission-mode plan'
107
+ # tmux does not support cgroup required mode; use cgroup mode auto/off.
107
108
  # Optional automatic Decision Worker (manual mode is the default):
108
109
  # export PI_CLAUDE_SUPERVISOR_MODE=auto
109
110
  # Optional, only when adopting a non-default tmux server:
@@ -126,11 +127,16 @@ the task:
126
127
  ```
127
128
 
128
129
  Adoption checks the session's working directory and pane command, and refuses a
129
- pane that already has another output pipe. It does not claim ownership: `/supervise stop` and Pi shutdown detach supervision rather
130
- than killing the user's tmux session. Use `tmux kill-session` yourself when the
131
- adopted window should be closed. `/supervise takeover <task-id>` disables
132
- automatic Decision Worker messages; resume them only with
133
- `/supervise resume-auto <task-id>`.
130
+ pane that already has another output pipe. Owned sessions use a generated
131
+ private tmux socket, so preserve the complete `attach=...` command printed by
132
+ `start`. When re-adopting after a Pi restart, set
133
+ `PI_CLAUDE_SUPERVISOR_TMUX_SOCKET` to the socket path from that command before
134
+ running `adopt-tmux`; the session name alone is sufficient only for the default
135
+ server. Adoption does not claim ownership: `/supervise stop` and Pi shutdown
136
+ detach supervision rather than killing the user's tmux session. Use `tmux
137
+ kill-session` yourself when the adopted window should be closed.
138
+ `/supervise takeover <task-id>` disables automatic Decision Worker messages;
139
+ resume them only with `/supervise resume-auto <task-id>`.
134
140
 
135
141
  PTY screen text is not Claude JSONL. Permission dialogs, trust prompts and
136
142
  ambiguous TUI states are escalated to a human; tmux mode must not be treated as
@@ -39,8 +39,9 @@ are also awaited during Pi shutdown.
39
39
 
40
40
  This is a control-boundary fixture and headless transport. It does not emulate a
41
41
  terminal. Manual compatibility mode remains `process-pipe`; automatic mode
42
- (`PI_CLAUDE_SUPERVISOR_MODE=auto`) forces Claude JSONL and uses the CLI contract
43
- validated by the fixed-version spike.
42
+ (`PI_CLAUDE_SUPERVISOR_MODE=auto`) defaults to Claude JSONL and uses the CLI
43
+ contract validated by the fixed-version spike; an explicit tmux transport remains
44
+ screen-based.
44
45
 
45
46
  A worker exit automatically triggers cleanup, and terminal status waits for
46
47
  that cleanup to be confirmed (or reports a cleanup error). On Linux the adapter
@@ -62,11 +63,14 @@ signals.
62
63
  ## tmux/PTY transport
63
64
 
64
65
  `TmuxWorkerAdapter` is an explicit second transport, selected with
65
- `PI_CLAUDE_SUPERVISOR_TRANSPORT=tmux`. An owned worker gets a private tmux
66
- server/socket and a launcher file containing only the validated command, args and
67
- cwd. The worker environment is supplied to the tmux server through the same
68
- least-privilege environment builder; environment credentials are not copied into
69
- the launcher file; credential-shaped command arguments are rejected.
66
+ `PI_CLAUDE_SUPERVISOR_TRANSPORT=tmux`. Because tmux has no equivalent cgroup
67
+ containment boundary, `PI_CLAUDE_SUPERVISOR_CGROUP_MODE=required` is rejected
68
+ with this transport; use `auto`/`off` only when the tmux boundary is acceptable.
69
+ An owned worker gets a private tmux server/socket and executes the validated Claude command directly in the pane,
70
+ so its pane identity remains re-adoptable after a Pi restart. The worker
71
+ environment is supplied to the tmux server through the same least-privilege
72
+ environment builder; credentials are not copied into a file; credential-shaped
73
+ command arguments are rejected.
70
74
  `load-buffer`, bracketed `paste-buffer` and `send-keys Enter` provide the input
71
75
  boundary without interpolating a task into a shell command. C0/C1 terminal
72
76
  control bytes are rejected; CRLF is normalized to a newline.
@@ -114,6 +118,37 @@ lifecycle event append fails after the state transition, it remains pending and
114
118
  is retried before the next lifecycle operation; output events restore their
115
119
  chunks for a lossless retry.
116
120
 
121
+ ### Cross-process cwd leases and startup cancellation
122
+
123
+ Every start and explicit recovery acquires an atomic lease in the shared lease
124
+ registry before spawning Claude. The default registry is
125
+ `~/.pi/agent/claude-supervisor/cwd-leases`; `PI_CLAUDE_SUPERVISOR_CWD_LEASE_DIR`
126
+ may point all Pi processes at an alternate shared directory. Canonical paths
127
+ conflict with both their parents and descendants, and the registry lock
128
+ serializes acquisition across independent Pi processes. A lease is released
129
+ only after the adapter confirms the worker and its descendant cleanup; an
130
+ unconfirmed lease left by a crashed Pi is intentionally retained and requires
131
+ operator verification/manual cleanup rather than unsafe automatic reclamation.
132
+ An explicitly adopted tmux session may hand off an existing lease only after
133
+ its owner identity is no longer live and its canonical cwd, tmux session/socket,
134
+ pane id, pane PID/start time, and pane command all match; ordinary starts
135
+ cannot consume another task's lease. If post-start worker identity registration
136
+ fails, owned workers are stopped before the lease is released; cleanup failure
137
+ retains both the worker and lease fail-closed. Explicit `stop` cleans owned tmux
138
+ sessions, while Pi shutdown detaches persistent sessions so they remain explicitly
139
+ re-adoptable. A detached adopted session retains its lease while the verified pane
140
+ is alive; the extension periodically rechecks released sessions and removes the
141
+ lease only after the pane is confirmed gone. If that check fails, the lease is
142
+ retained rather than allowing a cwd overlap.
143
+
144
+ Startup owns an `AbortController` and passes its signal to the adapter. A stop
145
+ or shutdown request aborts the controller and calls the adapter's out-of-band
146
+ startup cleanup without waiting behind the serialized start operation. Each
147
+ startup carries an opaque token, so cancelling one concurrent session cannot
148
+ abort another. Process and tmux adapters terminate or detach their startup
149
+ work, and the Supervisor rechecks cancellation before reporting `running`; a cancelled startup becomes
150
+ `stopped` and never reports a worker that was not cleanup-verified.
151
+
117
152
  ## Event log
118
153
 
119
154
  Events are JSONL with a monotonic sequence number, timestamp, task ID and worker
package/docs/releasing.md CHANGED
@@ -104,7 +104,8 @@ Major updates remain separate for explicit review. There is no blanket auto-merg
104
104
  A maintainer can retry an existing stable release from Actions:
105
105
 
106
106
  ```bash
107
- gh workflow run release.yml --ref main -f tag=v0.1.1
107
+ TAG=v0.3.0
108
+ gh workflow run release.yml --ref main -f tag="$TAG"
108
109
  ```
109
110
 
110
111
  The workflow verifies that the release tag is stable and belongs to `main`, then
package/docs/testing.md CHANGED
@@ -49,8 +49,11 @@ non-sensitive prompt, and prints protocol metadata rather than raw model output.
49
49
  It must not be added to the normal CI gate because authentication is an owner
50
50
  controlled prerequisite.
51
51
 
52
- The current fixtures validate one prompt, multiple turns, session resume,
52
+ The historical fixtures validate one prompt, multiple turns, session resume,
53
53
  permission allow/deny and SIGTERM/SIGINT behavior with Claude Code 2.1.268.
54
+ The current release validation uses Claude Code 2.1.270 at
55
+ `/home/yancao/.local/share/mise/installs/claude/2.1.270/claude`, including real
56
+ owned tmux turns, pause/resume, and restart re-adoption.
54
57
  The adapter regression suite also verifies event subscription, parsed
55
58
  `permission_request` events, and the exact nested `control_response` envelope.
56
59
  The automation spike additionally exercises a real Pi SDK Decision Worker with
@@ -70,10 +73,24 @@ npm run spike:signals
70
73
  npm run spike:automation
71
74
  SPIKE_AUTOMATION_PERMISSION=1 npm run spike:automation
72
75
  SPIKE_AUTOMATION_QUESTION=1 npm run spike:automation
76
+ PI_CLAUDE_SUPERVISOR_REAL_CLAUDE_PATH=/home/yancao/.local/share/mise/installs/claude/2.1.270/claude \
77
+ PI_CLAUDE_SUPERVISOR_REAL_CLAUDE=1 npm run spike:tmux
78
+ PI_CLAUDE_SUPERVISOR_REAL_CLAUDE_PATH=/home/yancao/.local/share/mise/installs/claude/2.1.270/claude \
79
+ PI_CLAUDE_SUPERVISOR_REAL_CLAUDE=1 npm run spike:tmux-interactive
73
80
  ```
74
81
 
75
- For this release, pin and record Claude Code `2.1.268` and its resolved
76
- executable path. Record:
82
+ The tmux spike is gated, authenticated, and excluded from normal CI. It uses
83
+ plan mode with a fixed `opus` model, records only protocol metadata, and
84
+ verifies three real Claude turns, exact screen-result markers, pause/resume,
85
+ automation enabled with human takeover, direct human PTY input, owned detach,
86
+ and identity-bound restart re-adoption. The interactive spike uses a fresh temporary
87
+ cwd to verify Claude's trust prompt, a real Bash permission prompt, an allow-once
88
+ response, and an exact result marker; it also records metadata only.
89
+
90
+ For each release, pin and record the validated Claude Code version, resolved
91
+ executable path, and model. The spikes reject an unpinned/mismatched executable
92
+ version. For this release the validated version is `2.1.270` with model `opus`.
93
+ Record:
77
94
 
78
95
  1. exact version and resolved executable path;
79
96
  2. license and source revision;
@@ -86,22 +103,26 @@ executable path. Record:
86
103
  A passing worker task is not sufficient. The independent verifier must repeat the
87
104
  relevant checks from a clean host perspective.
88
105
 
89
- Automatic mode is enabled with `PI_CLAUDE_SUPERVISOR_MODE=auto`; it forces JSONL
90
- and routes `result`, permission, and process-exit events to the persistent Pi
91
- Decision Worker. `process-pipe` remains the manual compatibility mode. Human
106
+ Automatic mode is enabled with `PI_CLAUDE_SUPERVISOR_MODE=auto`; it defaults to
107
+ JSONL and routes `result`, permission, and process-exit events to the persistent
108
+ Pi Decision Worker. An explicit `PI_CLAUDE_SUPERVISOR_TRANSPORT=tmux` selection
109
+ remains screen-based and does not use the JSONL permission protocol. `process-pipe` remains the manual compatibility mode. Human
92
110
  escalation is outbound-only through `PI_CLAUDE_SUPERVISOR_HUMAN_WEBHOOK_URL`;
93
111
  approval callbacks are deliberately not accepted without a separately
94
112
  authenticated endpoint.
95
113
 
96
114
  The tmux transport is selected with `PI_CLAUDE_SUPERVISOR_TRANSPORT=tmux`. Before
97
- release, manually verify: private-socket attach, multi-line paste, prompt
98
- stability while Claude is busy, trust/permission dialog takeover, duplicate
99
- send prevention, pane replacement refusal, pause/resume, owned-session stop,
100
- adopted-session detach/re-adoption, bounded shutdown, and Pi shutdown without
101
- closing an attached window. Use `--permission-mode plan`
102
- and read-only tools for live Claude checks. Do not run JSONL and tmux control
103
- against the same Claude process, and do not treat `capture-pane` text as a
104
- structured permission response.
115
+ release, verify: private-socket attach, multi-line paste, prompt stability while
116
+ Claude is busy, trust/permission dialog takeover, duplicate send prevention, pane
117
+ replacement refusal, pause/resume, owned-session stop, adopted-session
118
+ detach/re-adoption, bounded shutdown, and Pi shutdown without closing an
119
+ attached window. The two gated real-Claude spikes above cover the trust prompt,
120
+ permission prompt, exact output, human takeover, and adopted detach paths. Use
121
+ `--permission-mode plan` and read-only tools for ordinary live Claude checks;
122
+ the interactive spike is restricted to one harmless `rm -f` in a disposable
123
+ fresh directory. Do not run JSONL and tmux control against the same Claude
124
+ process, and do not treat `capture-pane` text as a structured permission
125
+ response.
105
126
 
106
127
  ## Failure injection
107
128
 
@@ -8,7 +8,7 @@ without exposing credentials or allowing repository changes.
8
8
  ## Environment
9
9
 
10
10
  - Node: `v26.8.1` (declared package minimum remains `>=22.19`)
11
- - Claude Code: `2.1.268`
11
+ - Claude Code: `2.1.268` (historical headless probe; current release validation uses `2.1.270`)
12
12
  - Executable: resolved through `PATH` as `claude`
13
13
  - Working directory: `/home/yancao/Work`
14
14
  - Session persistence: disabled for the stateless fixture; enabled for the separate resume fixture
@@ -56,7 +56,7 @@ existing default remains generic `process-pipe`.
56
56
 
57
57
  ## Required follow-up
58
58
 
59
- Additional evidence was collected with Claude Code `2.1.268` using
59
+ Historical permission evidence was collected with Claude Code `2.1.268` using
60
60
  `--permission-prompt-tool stdio --permission-mode default --tools Bash`:
61
61
 
62
62
  - The CLI emitted `control_request` with `request.subtype=can_use_tool`,
@@ -72,7 +72,7 @@ Additional evidence was collected with Claude Code `2.1.268` using
72
72
  decision at the wrong envelope level is rejected as an invalid permission
73
73
  result.
74
74
 
75
- The exact signal fixture also passed for `2.1.268`: after `system/init`, a group
75
+ The exact signal fixture also passed for historical version `2.1.268`: after `system/init`, a group
76
76
  `SIGTERM` produced exit code `143` with no terminal result; group `SIGINT`
77
77
  produced exit code `0` and a terminal result with `terminal_reason=
78
78
  "aborted_streaming"` and `is_error=true`. The new adapter cgroup-v2 fixture
@@ -87,8 +87,8 @@ npm run spike:signals
87
87
  ```
88
88
 
89
89
  Remaining evidence is malformed/duplicate CLI input, no secret leakage in
90
- captured events, and the cgroup startup-attachment window. Release scope is
91
- pinned to Claude Code `2.1.268` on the validated device; cross-version
92
- portability is explicitly out of scope for this iteration. The adapter-level
93
- lifecycle track is now **GO** for the installed CLI and host; atomic OS process
94
- containment remains follow-up work.
90
+ captured events, and the cgroup startup-attachment window. The current release
91
+ also passed a real Claude Code `2.1.270` tmux validation: owned multi-turn
92
+ interaction, pause/resume, explicit detach, and identity-bound restart
93
+ re-adoption. The adapter-level lifecycle track is now **GO** for the installed
94
+ CLI and host; atomic OS process containment remains follow-up work.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-claude-supervisor",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "A policy-gated Pi supervisor for observing and verifying Claude Code workers.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -56,6 +56,8 @@
56
56
  "test:install": "node scripts/test-install.mjs",
57
57
  "test:pi": "node scripts/test-pi.mjs",
58
58
  "spike:transport": "node scripts/spike-claude-transport.mjs",
59
+ "spike:tmux": "node scripts/spike-claude-tmux.mjs",
60
+ "spike:tmux-interactive": "node scripts/spike-claude-tmux-interactive.mjs",
59
61
  "spike:permissions": "node scripts/spike-claude-permissions.mjs",
60
62
  "spike:signals": "node scripts/spike-claude-signals.mjs",
61
63
  "spike:automation": "node scripts/spike-claude-automation.mjs",
package/src/config.ts CHANGED
@@ -7,9 +7,11 @@ const allowed = new Set([
7
7
  "PI_CLAUDE_SUPERVISOR_MODE",
8
8
  "PI_CLAUDE_SUPERVISOR_AUTOMATION",
9
9
  "PI_CLAUDE_SUPERVISOR_TRANSPORT",
10
+ "PI_CLAUDE_SUPERVISOR_CGROUP_MODE",
10
11
  "PI_CLAUDE_SUPERVISOR_TMUX_SOCKET",
11
12
  "PI_CLAUDE_SUPERVISOR_WORKER",
12
13
  "PI_CLAUDE_SUPERVISOR_STATE_DIR",
14
+ "PI_CLAUDE_SUPERVISOR_CWD_LEASE_DIR",
13
15
  "PI_CLAUDE_SUPERVISOR_WORKER_ENV",
14
16
  "PI_CLAUDE_SUPERVISOR_HUMAN_WEBHOOK_URL",
15
17
  "PI_CLAUDE_SUPERVISOR_HUMAN_WEBHOOK_FORMAT",