pi-herdr-subagents-lite 0.11.2 → 0.12.0

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 (72) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/README.md +58 -110
  3. package/README.zh-CN.md +67 -119
  4. package/package.json +1 -1
  5. package/src/config/index.ts +146 -65
  6. package/src/extension/child.ts +46 -0
  7. package/src/extension/deliver.ts +37 -0
  8. package/src/extension/index.ts +18 -135
  9. package/src/extension/main.ts +74 -0
  10. package/src/extension/types.ts +39 -0
  11. package/src/herdr/endpoint.ts +8 -0
  12. package/src/herdr/index.ts +209 -32
  13. package/src/herdr/socket.ts +122 -0
  14. package/src/index.ts +13 -8
  15. package/src/run/args.ts +62 -0
  16. package/src/run/batch.ts +24 -0
  17. package/src/run/child-result.ts +69 -0
  18. package/src/run/errors.ts +7 -22
  19. package/src/run/index.ts +90 -75
  20. package/src/run/interrupt.ts +63 -0
  21. package/src/run/pane.ts +79 -19
  22. package/src/run/paths.ts +18 -23
  23. package/src/run/prune.ts +16 -21
  24. package/src/run/result.ts +56 -33
  25. package/src/run/rules.ts +56 -0
  26. package/src/run/settle.ts +32 -65
  27. package/src/run/spawn.ts +131 -0
  28. package/src/run/state.ts +68 -55
  29. package/src/run/steer.ts +50 -0
  30. package/src/run/stop.ts +45 -0
  31. package/src/run/watch.ts +68 -94
  32. package/src/tool/index.ts +33 -22
  33. package/src/tool/input.ts +66 -0
  34. package/src/tool/schema.ts +70 -16
  35. package/src/tool/text.ts +9 -16
  36. package/src/config/schema.ts +0 -146
  37. package/src/error/index.ts +0 -3
  38. package/src/extension/report.ts +0 -43
  39. package/src/extension/shutdown.ts +0 -47
  40. package/src/herdr/agent.ts +0 -68
  41. package/src/herdr/cli.ts +0 -120
  42. package/src/herdr/pane.ts +0 -90
  43. package/src/inbox/index.ts +0 -69
  44. package/src/inbox/pump.ts +0 -18
  45. package/src/profile/examples.ts +0 -17
  46. package/src/profile/fields.ts +0 -91
  47. package/src/profile/frontmatter.ts +0 -68
  48. package/src/profile/index.ts +0 -5
  49. package/src/profile/layers.ts +0 -140
  50. package/src/profile/seed.ts +0 -21
  51. package/src/profile/skills.ts +0 -25
  52. package/src/run/aggregate.ts +0 -74
  53. package/src/run/artifact.ts +0 -19
  54. package/src/run/close.ts +0 -73
  55. package/src/run/find.ts +0 -13
  56. package/src/run/naming.ts +0 -38
  57. package/src/run/resolve.ts +0 -34
  58. package/src/run/resume.ts +0 -117
  59. package/src/run/retry.ts +0 -70
  60. package/src/run/send.ts +0 -79
  61. package/src/run/slot.ts +0 -10
  62. package/src/run/spawn-args.ts +0 -62
  63. package/src/run/start.ts +0 -97
  64. package/src/run/truncate.ts +0 -5
  65. package/src/session-file/index.ts +0 -28
  66. package/src/session-file/jsonl.ts +0 -51
  67. package/src/session-file/tail.ts +0 -33
  68. package/src/tool/errors.ts +0 -22
  69. package/src/tool/message.ts +0 -36
  70. package/src/turn/classify.ts +0 -125
  71. package/src/turn/index.ts +0 -11
  72. package/src/turn/store.ts +0 -112
package/CHANGELOG.md CHANGED
@@ -1,6 +1,21 @@
1
1
  # CHANGELOG
2
2
 
3
- 本文件记录已发布版本的用户可见变更。更细的过程见 git log。破坏性变更标 **BREAKING**。0.5.2 及更早的变更见旧仓 `setwhite/pi-herdr-subagents-lite` 的 tag `v0.3.0`–`v0.5.2`。
3
+ 本文件记录用户可见变更;未发版的小节标「未发布」。更细的过程见 git log。破坏性变更标 **BREAKING**。0.5.2 及更早的变更见旧仓 `setwhite/pi-herdr-subagents-lite` 的 tag `v0.3.0`–`v0.5.2`。
4
+
5
+ ## 0.12.0 — 未发布
6
+
7
+ 按 [v2 契约](docs/specs/0002_v2_architecture_spec.md) 重写,模块只剩 `config` / `herdr` / `run` / `tool` / `extension`。
8
+
9
+ - **BREAKING**:工具动作改为 `spawn` / `steer` / `inspect` / `stop`,参数是 `id` 而非 `name` / `profile`。老写法 `run` / `send` 不再存在。
10
+ - **BREAKING**:删掉 profile 模块。不再有 `profiles/*.md`、全局与项目两层查找、`auto-exit`、`system-prompt`、示例落盘。子代理的身份改由 `spawn` 参数与 `PI_SUBAGENT_*` 决定。
11
+ - **BREAKING**:删掉 `herdrBin`、`maxResultChars`、`closeOnFailure`、`inboxPollMs`、`livenessPollMs`、`prompts` 六个配置键,出现即加载失败。新增 `summaryMaxChars`(默认 2000)、`interruptGraceMs`(默认 3000)。
12
+ - herdr 改走本地 Socket 的 NDJSON 接口,不再起 `herdr` CLI 子进程。唯一的轮询是启动就绪:100ms 查一次 `agent.get`,30 秒预算(DEC-0073)。
13
+ - 完成通知改成每条 run 一个 `agent.wait` 长请求,不用 `events.subscribe`(DEC-0071)。完成判定只认 `result.json` 的 `seq` 递增。
14
+ - 新增 `worktree: true`:给可并发的写任务单独 checkout,失败自动回滚 worktree。
15
+ - 新增配置 `excludeTools`(默认 `["ask"]`):子代理启动时按它拼 `--exclude-tools`,空数组不传该参数,元素支持 `mcp__*` 这类模式。
16
+ - 子代理不注册 `ask`:提问用 `request_input` 写进 `result.json`,不在子 pane 弹对话框。待答问题另存 `questions.json`,提问后的续写回合不会把它盖成完成(DEC-0072)。
17
+ - 新增真机 e2e:`pnpm test:e2e` 自起隔离 herdr session,覆盖 pane 中途被关、提问闭环、运行中转向三条链路,不进 `pnpm check`。
18
+ - 修:真机上 `spawn` 必然 30 秒超时 `spawn_failed: agent_not_ready`。herdr 0.9.5 只在 `agent.get` 里推进托管 agent 的启动状态(`agent.list` 与 `agent.prompt` 都不推进),现在先轮询到 `interactive_ready` 再 prompt(DEC-0073)。e2e 的临时 agent dir 也装上 herdr 的 pi 集成,跑的和真机同一条上报路径。
4
19
 
5
20
  ## 0.11.2 — 2026-11-25
6
21
 
package/README.md CHANGED
@@ -1,18 +1,20 @@
1
1
  # pi-herdr-subagents-lite
2
2
 
3
- ![pi-herdr-subagents-lite: subagent run starts worker-2 in its own herdr tab and returns at once with {state: running, name: Worker-2}](https://raw.githubusercontent.com/setwhite/pi-extensions/main/packages/pi-herdr-subagents-lite/assets/cover.png)
3
+ ![pi-herdr-subagents-lite: a subagent spawns into its own herdr tab and the tool returns at once](https://raw.githubusercontent.com/setwhite/pi-extensions/main/packages/pi-herdr-subagents-lite/assets/cover.png)
4
4
 
5
5
  English | [简体中文](README.zh-CN.md)
6
6
 
7
- The extension runs each subagent as a separate pi process in its own herdr pane. The tool has two actions: `run` starts a subagent, `send` delivers a follow-up message. Results come back asynchronously. Behavior follows the [v1 contract](docs/specs/0001-v1-contract.md).
7
+ Run each subagent as a separate pi process in its own herdr tab. One tool, four actions: `spawn`, `steer`, `inspect`, `stop`. Results arrive later as messages. The contract is [spec 0002](docs/specs/0002_v2_architecture_spec.md).
8
8
 
9
9
  ## Features
10
10
 
11
- - A subagent is a separate process, and a human can take over its pane. When the child cwd matches the parent cwd, it opens a tab in the same workspace. Otherwise it opens a new workspace.
12
- - Profiles have two layers, global and per project, each a Markdown file with frontmatter.
13
- - `run` returns at once. Each finished turn reports one `subagent_result`. Results inside `aggregateWindowMs` merge into one message, and an oversize result goes to an artifact file.
14
- - Questions stay with the human. A dialog in the child pane never reaches the parent, and the human answers there. Reporting `blocked` to herdr belongs to the extension that opens the dialog (DEC-0070).
15
- - Nesting is off by default, and the extension is no sandbox. Unless the profile names this tool, a child tool set drops it.
11
+ - A subagent is a separate pi process in a herdr tab, so a human can take the pane over at any time.
12
+ - `spawn` returns at once. When the child settles, its answer arrives as one `followUp` message. Settlements inside `aggregateWindowMs` merge into one message, and an oversize answer spills to `output.md`.
13
+ - Depth is capped at one. A child registers only `request_input`; it cannot spawn grandchildren.
14
+ - A child's question is recorded in `result.json`, never shown as a dialog in its pane. The parent either answers with `steer` or batches several children's questions into one `ask` call for you.
15
+ - `worktree: true` gives a child its own checkout, so parallel writers never fight over the repository.
16
+ - Zero UI rendering and zero per-turn context injection: the main session's prefix cache stays intact.
17
+ - It talks to herdr over the local Socket, not through CLI subprocesses. The only polling is startup readiness: `agent.get` every 100ms until `interactive_ready`, capped at 30s (DEC-0073).
16
18
 
17
19
  ## Install
18
20
 
@@ -22,149 +24,95 @@ pi install /path/to/pi-herdr-subagents-lite # local checkout
22
24
  pi -e /path/to/pi-herdr-subagents-lite/src/index.ts # this process only
23
25
  ```
24
26
 
25
- The old repository moved into this monorepo, so install from npm.
27
+ Do not pass `-l`: it writes project settings only, so a child started elsewhere never loads the package.
26
28
 
27
- Do not pass `-l`. `-l` writes project settings only, so a child started in another workspace never loads the package. `pi -e` applies to the current process only.
28
-
29
- Requires Node `>= 22.19`. Tested with herdr `0.9.5` and pi `1.4.0`. The parent must run inside a herdr pane; otherwise calls fail with `not_in_herdr`.
29
+ Requires Node `>= 22.19`. Tested with herdr `0.9.5` and pi `1.6.1`. The parent must run inside a herdr pane, otherwise the tool returns `not_in_herdr`.
30
30
 
31
31
  Upgrade with `pi update --extensions`, remove with `pi remove <source>`.
32
32
 
33
33
  ## Configuration
34
34
 
35
- The extension reads one global file: `<agent-dir>/pi-herdr-subagents-lite/config.json`. `<agent-dir>` defaults to `~/.pi/agent` and follows `PI_CODING_AGENT_DIR`. There is no project config.
36
-
37
- Keys and their meaning: [contract §1](docs/specs/0001-v1-contract.md#1-配置). Defaults and clamp bounds: `src/config/index.ts` and `test/config/config.test.ts`.
38
-
39
- ### Minimal config
40
-
41
- A missing file means all defaults. To change one value, write only that value:
42
-
43
- ```json
44
- {
45
- "maxConcurrent": 4
46
- }
47
- ```
48
-
49
- ### Full configuration
50
-
51
- Every key follows, and each value is the default.
35
+ One global file: `<agent-dir>/pi-herdr-subagents-lite/config.json`. `<agent-dir>` defaults to `~/.pi/agent` and follows `PI_CODING_AGENT_DIR`. There is no project config. A missing file means all defaults.
52
36
 
53
37
  ```jsonc
54
38
  {
55
- // Default true. false = no subagent tool for the model.
39
+ // Default true. false = no subagent tool.
56
40
  "enabled": true,
57
- // Default "subagent". Must match ^[a-z][a-z0-9_]{0,31}$. The name prefixes each guideline line.
41
+ // Default "subagent". Must match ^[a-z][a-z0-9_]{0,31}$.
58
42
  "toolName": "subagent",
59
- // Default "herdr". A plain name resolves from PATH; an absolute path pins a version.
60
- "herdrBin": "herdr",
61
- // Default 16, range 1 and up. At the limit run returns max_concurrent. Only a running turn holds a slot.
43
+ // Default ["ask"]. Comma-joined into --exclude-tools; [] sends no flag. Patterns like "mcp__*" work.
44
+ "excludeTools": ["ask"],
45
+ // Default 16, range 1..64. At the limit spawn and steer return max_concurrent.
62
46
  "maxConcurrent": 16,
63
- // Default 16384, range 1024 to 1048576. A longer text goes to an artifact file. The message keeps a truncated head and the path.
64
- "maxResultChars": 16384,
65
- // Default 500, range 0 to 10000 milliseconds. 0 = deliver each result at once. A larger value merges more results.
47
+ // Default 2000, range 200..100000 characters. A longer answer spills to output.md.
48
+ "summaryMaxChars": 2000,
49
+ // Default 500, range 0..10000 ms. 0 = deliver each result at once.
66
50
  "aggregateWindowMs": 500,
67
- // Default ["quit", "reload"]. Values: new, resume, fork, quit, reload. A listed reason closes the child panes on parent shutdown.
51
+ // Default 3000, range 100..60000 ms. No idle after esc within this window = close the pane and reopen it.
52
+ "interruptGraceMs": 3000,
53
+ // Default ["quit", "reload"]. Values: new, resume, fork, quit, reload.
68
54
  "closeChildrenOn": ["quit", "reload"],
69
- // Default false. true = close the pane after a failed or interrupted turn. false keeps it so send can resume.
70
- "closeOnFailure": false,
71
- // Default 250, range 50 to 5000 milliseconds. A larger value wakes less often and delivers later.
72
- "inboxPollMs": 250,
73
- // Default 15000, range 1000 to 300000 milliseconds. How often a running child is checked for liveness. Three absences in a row mark it lost.
74
- "livenessPollMs": 15000,
75
- // Default 2592000000 (30 days), range 0 to 31536000000 milliseconds. Run files older than this are deleted at session start. 0 = never.
76
- "runRetentionMs": 2592000000,
77
- // Tool text overrides. Each key defaults to unset, which keeps the built-in text shown below.
78
- "prompts": {
79
- // Replaces the built-in description.
80
- "description": "Use run when a task is self-contained and long-running. Use send to pass information to a subagent.",
81
- // The one-line entry in Available tools. Empty = keep the tool out of that list.
82
- "snippet": "",
83
- // Replaces the built-in guideline lines. Keep {{profiles}} to list the profiles.
84
- "guidelines": [
85
- "run only starts; it does not wait. The result arrives later as a message.",
86
- "send only delivers; no state tracking.",
87
- "Available profiles:\n{{profiles}}"
88
- ]
89
- }
55
+ // Default 2592000000 (30 days), range 0..31536000000 ms. 0 = never prune.
56
+ "runRetentionMs": 2592000000
90
57
  }
91
58
  ```
92
59
 
93
- The file must be strict JSON, and the extension reads it once at load. Delete the comments and restart pi after a change.
94
-
95
- An unknown key, a wrong type or an unknown enum value stops the extension at load: pi prints `invalid config <path>: <field>: unknown key` and exits. A number outside its range clamps to the boundary without an error.
60
+ Strict JSON, read once at load. An unknown key, a wrong type or an out-of-range number stops the extension at load with one message naming every problem.
96
61
 
97
62
  ## Usage
98
63
 
99
- 1. Start `pi` in a herdr pane.
100
- 2. Write a profile (see the next section). `run` takes the profile frontmatter `name`.
101
- 3. Ask the model to call the tool:
64
+ Start `pi` in a herdr pane, then let the model call the tool:
102
65
 
103
66
  ```json
104
- {"action":"run","profile":"explore","task":"Read README.md and answer with its first heading."}
67
+ {"action":"spawn","id":"alpha","objective":"Read README.md and answer with its first heading."}
105
68
  ```
106
69
 
107
- The call returns `{"state":"running",...}`. The subagent runs in its own tab, and a `[subagent explore-1] done` message arrives later. Do not wait for it in the same turn. Deliver a follow-up with:
70
+ The call returns at once with `{"id":"alpha","status":"running","paneId":"w3:p2","sessionFile":"<agent-dir>/pi-herdr-subagents-lite/runs/alpha/session.jsonl"}`. Later a `[subagent alpha] done` message arrives. Do not wait for it in the same turn.
108
71
 
109
72
  ```json
110
- {"action":"send","name":"explore-1","message":"Also check the Windows branch."}
73
+ {"action":"steer","id":"alpha","message":"Also check the Windows branch."}
74
+ {"action":"inspect","id":"alpha"}
75
+ {"action":"stop","id":"alpha"}
111
76
  ```
112
77
 
113
- ### Profile
114
-
115
- Global profiles live in `<agent-dir>/pi-herdr-subagents-lite/profiles/*.md`. Project profiles live in `.pi/pi-herdr-subagents-lite/profiles/*.md` and load once the project is trusted. A project profile wins over a global profile with the same `name`.
116
-
117
- ```markdown
118
- ---
119
- # Key run takes; the file name is not used
120
- name: explore
121
- description: "Read-only research: read code, answer questions, change nothing"
78
+ - `steer` on a running child interrupts its current turn with `esc`, waits for idle, then sends the message.
79
+ - `inspect` is the only progress query. It injects nothing into context until you ask.
80
+ - `stop` is idempotent and closes the pane.
122
81
 
123
- # Omit to inherit from the parent
124
- # model: provider/model
125
- thinking: low
82
+ ### spawn parameters
126
83
 
127
- # Plain names = strict allowlist. +name / -name adjusts the default set. Never mix both
128
- # Omitted = pi defaults minus this tool (nesting off); "" = empty allowlist
129
- tools: read, bash
130
-
131
- # Omitted = pi discovery; "" = no skills; a list = only those
132
- skills: ""
133
-
134
- # append / replace: body is appended to or replaces the system prompt
135
- # task: body is the task text, no identity file
136
- system-prompt: append
137
-
138
- # Close the pane after this run's done turn. Leave it false to keep the child resumable with send
139
- auto-exit: true
140
-
141
- # true = hidden from the guidelines; an explicit run still works
142
- disable-model-invocation: false
143
- ---
144
-
145
- You are a read-only explorer. Answer with file paths and line numbers.
146
- ```
147
-
148
- Error codes: [contract section 2](docs/specs/0001-v1-contract.md#2-profile). Defaults: `src/profile/frontmatter.ts` and `test/profile/`.
84
+ | Field | Meaning |
85
+ |---|---|
86
+ | `id` | `^[a-z][a-z0-9_-]{0,31}$`, unique per parent session. It is also the herdr agent name and the run directory name. |
87
+ | `objective` | The task text. |
88
+ | `context` | Optional background, appended as a `# Context` section. |
89
+ | `cwd` | Optional working directory. `~` expands. |
90
+ | `worktree` | `true` = create a worktree and run there. |
91
+ | `tools` `skills` `model` `thinking` | Passed straight to the child's `pi` argv. |
149
92
 
150
- A profile stays out of the list when it has no `name`, an invalid or unknown field, or a duplicate name in its layer. `run` on it returns `profile_invalid` with the file, the field and the reason.
93
+ Error codes: `invalid_id`, `duplicate_id`, `unknown_id`, `max_concurrent`, `not_ready`, `cancelled`, `spawn_failed`, `steer_failed`, `not_in_herdr`.
151
94
 
152
- The extension ships one example, with file name and `name` both `worker`. Loading reads `profiles/*.md` only, and on every load it makes `profiles/examples/` match the bundled example: it rewrites the bundled files and deletes extra ones. So copy the example one level up:
95
+ ### Where files land
153
96
 
154
- ```bash
155
- cd <agent-dir>/pi-herdr-subagents-lite/profiles && cp examples/worker.md worker.md
156
- ```
97
+ `<agent-dir>/pi-herdr-subagents-lite/runs/<id>/` holds `session.jsonl`, `result.json` and, when the answer is long, `output.md`. Directories older than `runRetentionMs` are pruned at session start.
157
98
 
158
99
  ## Credits
159
100
 
160
101
  | Project | Borrowed |
161
102
  |---|---|
162
103
  | [earendil-works/pi](https://github.com/earendil-works/pi) | Extension API, package layout, official examples |
163
- | [fyang93/pi-herdr-subagents](https://github.com/fyang93/pi-herdr-subagents) | Profile field shapes; integration tests on an isolated herdr session |
164
- | [modem-dev/pi-herdr-subagents](https://github.com/modem-dev/pi-herdr-subagents) | herdr launch and lifecycle; derived end states |
104
+ | [fyang93/pi-herdr-subagents](https://github.com/fyang93/pi-herdr-subagents) | Integration tests on an isolated herdr session |
105
+ | [modem-dev/pi-herdr-subagents](https://github.com/modem-dev/pi-herdr-subagents) | herdr launch and lifecycle |
165
106
  | [purboo/pi-durable-subagents](https://github.com/purboo/pi-durable-subagents) | Async delivery, idempotency, report-once results |
166
107
 
167
- This extension builds on these projects. Thanks to their authors.
108
+ ## Tests
109
+
110
+ ```bash
111
+ pnpm check # lint + import graph + tsc + unit tests
112
+ pnpm test:e2e # real machine: isolated herdr session + temp agent dir; needs herdr, pi and auth.json
113
+ ```
114
+
115
+ `test:e2e` stays out of `pnpm check`. The whole suite is skipped when `herdr`, `pi` or `~/.pi/agent/auth.json` is missing; `PI_E2E_KEEP=1` keeps the temp directory and `PI_E2E_MODEL` overrides the child model.
168
116
 
169
117
  ## Docs
170
118
 
@@ -174,7 +122,7 @@ This extension builds on these projects. Thanks to their authors.
174
122
  | [GLOSSARY](docs/GLOSSARY.md) | The only source for terms |
175
123
  | [Modules](docs/modules/) | Usage and trade-offs per module |
176
124
  | [Decisions](docs/decisions/) | One file per decision |
177
- | [Spec](docs/specs/0001-v1-contract.md) | The v1 contract |
125
+ | [Spec](docs/specs/0002_v2_architecture_spec.md) | The v2 contract |
178
126
  | [Research](docs/research/) | Measurements of herdr and pi |
179
127
  | [CHANGELOG.md](CHANGELOG.md) | Release notes |
180
128
 
package/README.zh-CN.md CHANGED
@@ -1,183 +1,131 @@
1
1
  # pi-herdr-subagents-lite
2
2
 
3
- ![pi-herdr-subagents-lite:subagent 的 run 在独立 herdr 标签页里起了 worker-2,立即返回 {state: running, name: Worker-2}](https://raw.githubusercontent.com/setwhite/pi-extensions/main/packages/pi-herdr-subagents-lite/assets/cover.png)
3
+ ![pi-herdr-subagents-lite:子代理开在自己的 herdr tab 里,工具立即返回](https://raw.githubusercontent.com/setwhite/pi-extensions/main/packages/pi-herdr-subagents-lite/assets/cover.png)
4
4
 
5
- 简体中文 | [English](README.md)
5
+ [English](README.md) | 简体中文
6
6
 
7
- 本扩展把子代理跑成独立的 pi 进程,一个子代理占一个 herdr pane。工具有两个 action:`run` 起子代理,`send` 投递后续消息。结果异步回投。行为以 [v1 契约](docs/specs/0001-v1-contract.md) 为准。
7
+ 每个子代理是一个独立的 pi 进程,跑在自己的 herdr tab 里。只有一个工具、四个动作:`spawn`、`steer`、`inspect`、`stop`。结果稍后作为消息回来。契约见 [spec 0002](docs/specs/0002_v2_architecture_spec.md)。
8
8
 
9
- ## 功能
9
+ ## 特性
10
10
 
11
- - 子代理是独立进程,人可以接管它的 pane。cwd 与父会话相同时,它在同一 workspace 新开 tab;不同则新建 workspace。
12
- - profile 两层:全局一层,项目一层,都是 Markdown 加 frontmatter。
13
- - `run` 立即返回。每个回合结束投一条 `subagent_result`,落在 `aggregateWindowMs` 内的合并成一条,超长的落 artifact 文件。
14
- - 反问留在子 pane。子代理弹对话框,父会话收不到,人在子 pane 里回答。向 herdr 上报 `blocked` 归开对话框的扩展(DEC-0070)。
15
- - 默认不嵌套,也不是沙箱。profile 不点名,子代理的工具集就没有本工具。
11
+ - 子代理是独立 pi 进程,跑在 herdr tab 里,人随时可以接管那个 pane。
12
+ - `spawn` 立即返回。子代理结算后答案作为一条 `followUp` 消息回来。`aggregateWindowMs` 内的多条结算合并成一条,超长答案落到 `output.md`。
13
+ - 深度上限为 1。子代理只注册 `request_input`,不能再派生子代理。
14
+ - 子代理的提问写进 `result.json`,不在自己 pane 里弹对话框。主代理要么用 `steer` 回答,要么把几个子代理的问题合并成一次 `ask` 问你。
15
+ - `worktree: true` 给子代理独立 checkout,并行写代码不会互相踩。
16
+ - 零 UI 渲染、零每轮上下文注入:主会话前缀 KV Cache 保持完整。
17
+ - 走 herdr 本地 Socket,不起 CLI 子进程。唯一的轮询是启动就绪:100ms 查一次 `agent.get` 到 `interactive_ready`,预算 30 秒(DEC-0073)。
16
18
 
17
19
  ## 安装
18
20
 
19
21
  ```bash
20
22
  pi install npm:pi-herdr-subagents-lite # npm
21
- pi install /path/to/pi-herdr-subagents-lite # 本地源码
22
- pi -e /path/to/pi-herdr-subagents-lite/src/index.ts # 只对当前进程生效
23
+ pi install /path/to/pi-herdr-subagents-lite # 本地检出
24
+ pi -e /path/to/pi-herdr-subagents-lite/src/index.ts # 只对本次进程生效
23
25
  ```
24
26
 
25
- 旧仓已并入 monorepo,请从 npm 装。
27
+ 不要加 `-l`:它只写项目设置,在别处启动的子进程就不会加载本包。
26
28
 
27
- 不要加 `-l`。`-l` 只写项目设置,别的 workspace 里起的子代理就加载不到。`pi -e` 同样只对当前进程生效。
28
-
29
- 要求 Node `>= 22.19`。在 herdr `0.9.5` 与 pi `1.4.0` 上测过。父会话必须跑在 herdr pane 里,否则工具返回 `not_in_herdr`。
29
+ 需要 Node `>= 22.19`。已在 herdr `0.9.5` 与 pi `1.6.1` 上验证。父代理必须在 herdr pane 里运行,否则工具返回 `not_in_herdr`。
30
30
 
31
31
  升级用 `pi update --extensions`,卸载用 `pi remove <source>`。
32
32
 
33
33
  ## 配置
34
34
 
35
- 全局只有一个文件:`<agent-dir>/pi-herdr-subagents-lite/config.json`。`<agent-dir>` 默认 `~/.pi/agent`,跟随 `PI_CODING_AGENT_DIR`。扩展不读项目级配置。
36
-
37
- 键与语义见[契约 §1](docs/specs/0001-v1-contract.md#1-配置)。默认值与 clamp 边界见 `src/config/index.ts` 与 `test/config/config.test.ts`。
38
-
39
- ### 最小配置
40
-
41
- 文件不存在时全部取默认值。只改一项,就只写这一项:
42
-
43
- ```json
44
- {
45
- "maxConcurrent": 4
46
- }
47
- ```
48
-
49
- ### 完整配置
50
-
51
- 下面列出全部键,每个取值就是默认值。
35
+ 只有一个全局文件:`<agent-dir>/pi-herdr-subagents-lite/config.json`。`<agent-dir>` 默认 `~/.pi/agent`,跟随 `PI_CODING_AGENT_DIR`。没有项目配置。文件不存在即全默认值。
52
36
 
53
37
  ```jsonc
54
38
  {
55
- // 默认 true。false = 模型看不到本工具。
39
+ // 默认 true。false = 不注册子代理工具。
56
40
  "enabled": true,
57
- // 默认 "subagent"。须匹配 ^[a-z][a-z0-9_]{0,31}$。它会作为每条 guideline 的前缀。
41
+ // 默认 "subagent"。须匹配 ^[a-z][a-z0-9_]{0,31}$。
58
42
  "toolName": "subagent",
59
- // 默认 "herdr"。裸名从 PATH 解析。绝对路径锁定版本。
60
- "herdrBin": "herdr",
61
- // 默认 16,下限 1。到上限时 run 返回 max_concurrent。只有进行中的回合占槽。
43
+ // 默认 ["ask"],逗号拼进 --exclude-tools,[] 表示不传该参数。可写 "mcp__*" 这类模式。
44
+ "excludeTools": ["ask"],
45
+ // 默认 16,范围 1..64。到上限时 spawn 与 steer 返回 max_concurrent。
62
46
  "maxConcurrent": 16,
63
- // 默认 16384,范围 1024 到 1048576。超上限时全文落 artifact 文件。消息里留截断的头和路径。
64
- "maxResultChars": 16384,
65
- // 默认 500,范围 0 到 10000,单位毫秒。0 = 逐条立即投递。调大合并更多结果。
47
+ // 默认 2000,范围 200..100000 字符。超出落 output.md。
48
+ "summaryMaxChars": 2000,
49
+ // 默认 500,范围 0..10000 毫秒。0 = 每条结果立即投递。
66
50
  "aggregateWindowMs": 500,
67
- // 默认 ["quit", "reload"]。取值:new、resume、fork、quit、reload。列出的原因会在父会话退出时关掉子 pane。
51
+ // 默认 3000,范围 100..60000 毫秒。esc 后这么久还没 idle 就关 pane 重开。
52
+ "interruptGraceMs": 3000,
53
+ // 默认 ["quit", "reload"]。可选值:new、resume、fork、quit、reload。
68
54
  "closeChildrenOn": ["quit", "reload"],
69
- // 默认 false。true = 失败或中断的回合结束后关 pane。false 留着,send 可以续。
70
- "closeOnFailure": false,
71
- // 默认 250,范围 50 到 5000,单位毫秒。调大省唤醒,投递变慢。
72
- "inboxPollMs": 250,
73
- // 默认 15000,范围 1000 到 300000,单位毫秒。多久查一次进行中的子代理还活着没有。连续三次缺席判为失去联系。
74
- "livenessPollMs": 15000,
75
- // 默认 2592000000(30 天),范围 0 到 31536000000,单位毫秒。超过保留期的 run 附属文件在会话启动时删除。0 = 永不清理。
76
- "runRetentionMs": 2592000000,
77
- // 工具文案覆盖。每个键默认未设置,用下面这份内置文案。
78
- "prompts": {
79
- // 替换内置描述。
80
- "description": "Use run when a task is self-contained and long-running. Use send to pass information to a subagent.",
81
- // Available tools 里的那一行。空 = 不出现在该列表。
82
- "snippet": "",
83
- // 替换内置 guideline 各行。保留 {{profiles}} 才会列出 profile。
84
- "guidelines": [
85
- "run only starts; it does not wait. The result arrives later as a message.",
86
- "send only delivers; no state tracking.",
87
- "Available profiles:\n{{profiles}}"
88
- ]
89
- }
55
+ // 默认 2592000000(30 天),范围 0..31536000000 毫秒。0 = 不清理。
56
+ "runRetentionMs": 2592000000
90
57
  }
91
58
  ```
92
59
 
93
- 文件必须是严格 JSON,扩展只在加载时读一次。改完删掉注释,重启 pi。
94
-
95
- 未知键、类型不对或枚举值非法都会让扩展加载失败:pi 打出 `invalid config <路径>: <字段>: unknown key` 后退出。越界的数字夹到边界,不报错。
60
+ 严格 JSON,加载时读一次。未知键、类型不对或数值越界都会在加载时中止扩展,并一次性报出所有问题。
96
61
 
97
62
  ## 用法
98
63
 
99
- 1. 在 herdr pane 里启动 `pi`。
100
- 2. 写一个 profile(见下一节)。frontmatter 的 `name` 就是 `run` 的寻址名。
101
- 3. 让模型调用工具:
64
+ 在 herdr pane 里启动 `pi`,让模型调用工具:
102
65
 
103
66
  ```json
104
- {"action":"run","profile":"explore","task":"读 README.md,回答它的第一个标题。"}
67
+ {"action":"spawn","id":"alpha","objective":"读 README.md,回答它的一级标题。"}
105
68
  ```
106
69
 
107
- 工具返回 `{"state":"running",...}`。子代理在自己的 tab 里跑,稍后收到 `[subagent explore-1] done`。不要在同一轮里等结果。之后向它投递消息:
70
+ 调用立即返回 `{"id":"alpha","status":"running","paneId":"w3:p2","sessionFile":"<agent-dir>/pi-herdr-subagents-lite/runs/alpha/session.jsonl"}`。稍后会收到 `[subagent alpha] done` 消息,不要在同一个回合里等它。
108
71
 
109
72
  ```json
110
- {"action":"send","name":"explore-1","message":"也看一下 Windows 那条分支。"}
73
+ {"action":"steer","id":"alpha","message":"再看一下 Windows 分支。"}
74
+ {"action":"inspect","id":"alpha"}
75
+ {"action":"stop","id":"alpha"}
111
76
  ```
112
77
 
113
- ### Profile
114
-
115
- 全局 profile 放 `<agent-dir>/pi-herdr-subagents-lite/profiles/*.md`。项目 profile 放 `.pi/pi-herdr-subagents-lite/profiles/*.md`,项目受信后才读。同名时项目覆盖全局。
78
+ - `steer` 对运行中的子代理先发 `esc` 打断当前回合,等它 idle 后再投递消息。
79
+ - `inspect` 是唯一的进度查询面。不主动往上下文里塞状态。
80
+ - `stop` 幂等,并关掉 pane。
116
81
 
117
- ```markdown
118
- ---
119
- # run 的寻址名。文件名不参与查找
120
- name: explore
121
- description: 只读调研:读代码、回答问题,不改动任何文件
82
+ ### spawn 参数
122
83
 
123
- # 省略即继承父会话
124
- # model: provider/model
125
- thinking: low
126
-
127
- # 纯名字 = 严格白名单。+名字 / -名字 在默认集上增删,两者不能混用
128
- # 省略 = pi 默认集去掉本工具(不嵌套)。"" = 空白名单
129
- tools: read, bash
130
-
131
- # 省略 = 由 pi 发现。"" = 不加载。列表 = 只加载列出的
132
- skills: ""
84
+ | 字段 | 含义 |
85
+ |---|---|
86
+ | `id` | `^[a-z][a-z0-9_-]{0,31}$`,父会话内唯一。同时是 herdr agent 名与 run 目录名。 |
87
+ | `objective` | 任务正文。 |
88
+ | `context` | 可选背景,作为 `# Context` 段追加。 |
89
+ | `cwd` | 可选工作目录,支持 `~`。 |
90
+ | `worktree` | `true` = 建 worktree 并在其中运行。 |
91
+ | `tools` `skills` `model` `thinking` | 直接透传给子进程的 `pi` 参数。 |
133
92
 
134
- # append / replace:正文追加到或替换系统提示
135
- # task:正文就是任务文本,不写身份文件
136
- system-prompt: append
93
+ 错误码:`invalid_id`、`duplicate_id`、`unknown_id`、`max_concurrent`、`not_ready`、`cancelled`、`spawn_failed`、`steer_failed`、`not_in_herdr`。
137
94
 
138
- # 这个 run 的 done 回合结束后关掉 pane。false 则留着,send 还能续
139
- auto-exit: true
95
+ ### 文件位置
140
96
 
141
- # true = 不出现在 guidelines 的 profile 列表里。显式 run 仍然可用
142
- disable-model-invocation: false
143
- ---
97
+ `<agent-dir>/pi-herdr-subagents-lite/runs/<id>/` 下放 `session.jsonl`、`result.json`,答案过长时还有 `output.md`。超过 `runRetentionMs` 的目录在会话启动时清理。
144
98
 
145
- 你是一名只读探索者。回答时给出文件路径与行号。
146
- ```
147
-
148
- 错误码见[契约 §2](docs/specs/0001-v1-contract.md#2-profile)。默认值见 `src/profile/frontmatter.ts` 与 `test/profile/`。
99
+ ## 参考项目
149
100
 
150
- 没写 `name`、字段非法、字段名不认识、同层同名的 profile 都不进列表。`run` 点到它时返回 `profile_invalid`,带文件、字段与原因。
101
+ | 项目 | 借用内容 |
102
+ |---|---|
103
+ | [earendil-works/pi](https://github.com/earendil-works/pi) | 扩展 API、包布局、官方示例 |
104
+ | [fyang93/pi-herdr-subagents](https://github.com/fyang93/pi-herdr-subagents) | 隔离 herdr session 上的集成测试 |
105
+ | [modem-dev/pi-herdr-subagents](https://github.com/modem-dev/pi-herdr-subagents) | herdr 启动与生命周期 |
106
+ | [purboo/pi-durable-subagents](https://github.com/purboo/pi-durable-subagents) | 异步投递、幂等、只上报一次的结果 |
151
107
 
152
- 扩展自带一个示例,文件名和 `name` 都是 `worker`。加载只读 `profiles/*.md`,同时把 `profiles/examples/` 对齐到包内示例:重写自带文件,删掉多余文件。所以把示例复制到上一层:
108
+ ## 测试
153
109
 
154
110
  ```bash
155
- cd <agent-dir>/pi-herdr-subagents-lite/profiles && cp examples/worker.md worker.md
111
+ pnpm check # lint + 依赖图 + tsc + 单测
112
+ pnpm test:e2e # 真机:隔离 herdr session + 临时 agent dir,需要 herdr、pi 与 auth.json
156
113
  ```
157
114
 
158
- ## 参考项目
159
-
160
- | 项目 | 借鉴内容 |
161
- |---|---|
162
- | [earendil-works/pi](https://github.com/earendil-works/pi) | 扩展 API、包布局、官方示例 |
163
- | [fyang93/pi-herdr-subagents](https://github.com/fyang93/pi-herdr-subagents) | profile 字段形状;隔离 herdr session 的集成测试 |
164
- | [modem-dev/pi-herdr-subagents](https://github.com/modem-dev/pi-herdr-subagents) | herdr 启动与生命周期;终态归类 |
165
- | [purboo/pi-durable-subagents](https://github.com/purboo/pi-durable-subagents) | 异步投递、幂等、只上报一次 |
166
-
167
- 本扩展建在这些项目之上。谢谢各位作者。
115
+ `test:e2e` 不进 `pnpm check`。缺 `herdr`、`pi` 或 `~/.pi/agent/auth.json` 时整组跳过;`PI_E2E_KEEP=1` 保留临时目录,`PI_E2E_MODEL` 换子代理模型。
168
116
 
169
117
  ## 文档
170
118
 
171
119
  | 文档 | 内容 |
172
120
  |---|---|
173
121
  | [ARCHITECTURE](docs/ARCHITECTURE.md) | 模块边界、依赖方向、测试 seam |
174
- | [GLOSSARY](docs/GLOSSARY.md) | 术语唯一来源 |
175
- | [Modules](docs/modules/) | 各模块的用法与取舍 |
122
+ | [GLOSSARY](docs/GLOSSARY.md) | 术语的唯一来源 |
123
+ | [Modules](docs/modules/) | 各模块用法与取舍 |
176
124
  | [Decisions](docs/decisions/) | 一条决策一份文件 |
177
- | [Spec](docs/specs/0001-v1-contract.md) | v1 契约 |
125
+ | [Spec](docs/specs/0002_v2_architecture_spec.md) | v2 契约 |
178
126
  | [Research](docs/research/) | herdr 与 pi 的实测记录 |
179
- | [CHANGELOG.md](CHANGELOG.md) | 发布记录 |
127
+ | [CHANGELOG.md](CHANGELOG.md) | 版本说明 |
180
128
 
181
- ## License
129
+ ## 许可
182
130
 
183
131
  MIT,见 [LICENSE](LICENSE)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-herdr-subagents-lite",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "description": "Run pi subagents in herdr panes.",
5
5
  "type": "module",
6
6
  "license": "MIT",