pi-herdr-subagents-lite 0.11.2 → 0.12.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 +20 -1
- package/README.md +58 -110
- package/README.zh-CN.md +67 -119
- package/package.json +1 -1
- package/src/config/index.ts +22 -83
- package/src/config/paths.ts +18 -0
- package/src/config/reader.ts +106 -0
- package/src/config/types.ts +26 -0
- package/src/extension/child.ts +46 -0
- package/src/extension/deliver.ts +37 -0
- package/src/extension/index.ts +18 -135
- package/src/extension/main.ts +74 -0
- package/src/extension/types.ts +39 -0
- package/src/herdr/endpoint.ts +8 -0
- package/src/herdr/index.ts +133 -29
- package/src/herdr/parse.ts +31 -0
- package/src/herdr/socket.ts +122 -0
- package/src/herdr/types.ts +54 -0
- package/src/index.ts +13 -8
- package/src/run/args.ts +62 -0
- package/src/run/batch.ts +24 -0
- package/src/run/child-result.ts +69 -0
- package/src/run/errors.ts +7 -22
- package/src/run/index.ts +90 -75
- package/src/run/interrupt.ts +63 -0
- package/src/run/pane.ts +79 -19
- package/src/run/paths.ts +18 -23
- package/src/run/prune.ts +16 -21
- package/src/run/result.ts +56 -33
- package/src/run/rules.ts +56 -0
- package/src/run/settle.ts +32 -65
- package/src/run/spawn.ts +131 -0
- package/src/run/state.ts +68 -55
- package/src/run/steer.ts +50 -0
- package/src/run/stop.ts +45 -0
- package/src/run/watch.ts +68 -94
- package/src/tool/index.ts +33 -22
- package/src/tool/input.ts +66 -0
- package/src/tool/schema.ts +70 -16
- package/src/tool/text.ts +9 -16
- package/src/config/schema.ts +0 -146
- package/src/error/index.ts +0 -3
- package/src/extension/report.ts +0 -43
- package/src/extension/shutdown.ts +0 -47
- package/src/herdr/agent.ts +0 -68
- package/src/herdr/cli.ts +0 -120
- package/src/herdr/pane.ts +0 -90
- package/src/inbox/index.ts +0 -69
- package/src/inbox/pump.ts +0 -18
- package/src/profile/examples.ts +0 -17
- package/src/profile/fields.ts +0 -91
- package/src/profile/frontmatter.ts +0 -68
- package/src/profile/index.ts +0 -5
- package/src/profile/layers.ts +0 -140
- package/src/profile/seed.ts +0 -21
- package/src/profile/skills.ts +0 -25
- package/src/run/aggregate.ts +0 -74
- package/src/run/artifact.ts +0 -19
- package/src/run/close.ts +0 -73
- package/src/run/find.ts +0 -13
- package/src/run/naming.ts +0 -38
- package/src/run/resolve.ts +0 -34
- package/src/run/resume.ts +0 -117
- package/src/run/retry.ts +0 -70
- package/src/run/send.ts +0 -79
- package/src/run/slot.ts +0 -10
- package/src/run/spawn-args.ts +0 -62
- package/src/run/start.ts +0 -97
- package/src/run/truncate.ts +0 -5
- package/src/session-file/index.ts +0 -28
- package/src/session-file/jsonl.ts +0 -51
- package/src/session-file/tail.ts +0 -33
- package/src/tool/errors.ts +0 -22
- package/src/tool/message.ts +0 -36
- package/src/turn/classify.ts +0 -125
- package/src/turn/index.ts +0 -11
- package/src/turn/store.ts +0 -112
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
本文件记录用户可见变更;未发版的小节标「未发布」。更细的过程见 git log。破坏性变更标 **BREAKING**。0.5.2 及更早的变更见旧仓 `setwhite/pi-herdr-subagents-lite` 的 tag `v0.3.0`–`v0.5.2`。
|
|
4
|
+
|
|
5
|
+
## 0.12.1 — 2026-11-28
|
|
6
|
+
|
|
7
|
+
- 无运行时变更:0.12.0 的 npm 产物取自拆分前的提交,CHANGELOG 还标着「未发布」。本版按最终提交重发,差别只在内部文件拆分。
|
|
8
|
+
|
|
9
|
+
## 0.12.0 — 2026-11-28
|
|
10
|
+
|
|
11
|
+
按 [v2 契约](docs/specs/0002_v2_architecture_spec.md) 重写,模块只剩 `config` / `herdr` / `run` / `tool` / `extension`。
|
|
12
|
+
|
|
13
|
+
- **BREAKING**:工具动作改为 `spawn` / `steer` / `inspect` / `stop`,参数是 `id` 而非 `name` / `profile`。老写法 `run` / `send` 不再存在。
|
|
14
|
+
- **BREAKING**:删掉 profile 模块。不再有 `profiles/*.md`、全局与项目两层查找、`auto-exit`、`system-prompt`、示例落盘。子代理的身份改由 `spawn` 参数与 `PI_SUBAGENT_*` 决定。
|
|
15
|
+
- **BREAKING**:删掉 `herdrBin`、`maxResultChars`、`closeOnFailure`、`inboxPollMs`、`livenessPollMs`、`prompts` 六个配置键,出现即加载失败。新增 `summaryMaxChars`(默认 2000)、`interruptGraceMs`(默认 3000)。
|
|
16
|
+
- herdr 改走本地 Socket 的 NDJSON 接口,不再起 `herdr` CLI 子进程。唯一的轮询是启动就绪:100ms 查一次 `agent.get`,30 秒预算(DEC-0073)。
|
|
17
|
+
- 完成通知改成每条 run 一个 `agent.wait` 长请求,不用 `events.subscribe`(DEC-0071)。完成判定只认 `result.json` 的 `seq` 递增。
|
|
18
|
+
- 新增 `worktree: true`:给可并发的写任务单独 checkout,失败自动回滚 worktree。
|
|
19
|
+
- 新增配置 `excludeTools`(默认 `["ask"]`):子代理启动时按它拼 `--exclude-tools`,空数组不传该参数,元素支持 `mcp__*` 这类模式。
|
|
20
|
+
- 子代理不注册 `ask`:提问用 `request_input` 写进 `result.json`,不在子 pane 弹对话框。待答问题另存 `questions.json`,提问后的续写回合不会把它盖成完成(DEC-0072)。
|
|
21
|
+
- 新增真机 e2e:`pnpm test:e2e` 自起隔离 herdr session,覆盖 pane 中途被关、提问闭环、运行中转向三条链路,不进 `pnpm check`。
|
|
22
|
+
- 修:真机上 `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
23
|
|
|
5
24
|
## 0.11.2 — 2026-11-25
|
|
6
25
|
|
package/README.md
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# pi-herdr-subagents-lite
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|
|
|
5
5
|
English | [简体中文](README.zh-CN.md)
|
|
6
6
|
|
|
7
|
-
|
|
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
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
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
|
-
|
|
27
|
+
Do not pass `-l`: it writes project settings only, so a child started elsewhere never loads the package.
|
|
26
28
|
|
|
27
|
-
|
|
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
|
-
|
|
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
|
|
39
|
+
// Default true. false = no subagent tool.
|
|
56
40
|
"enabled": true,
|
|
57
|
-
// Default "subagent". Must match ^[a-z][a-z0-9_]{0,31}$.
|
|
41
|
+
// Default "subagent". Must match ^[a-z][a-z0-9_]{0,31}$.
|
|
58
42
|
"toolName": "subagent",
|
|
59
|
-
// Default "
|
|
60
|
-
"
|
|
61
|
-
// Default 16, range 1
|
|
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
|
|
64
|
-
"
|
|
65
|
-
// Default 500, range 0
|
|
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
|
|
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
|
|
70
|
-
"
|
|
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
|
-
|
|
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
|
-
|
|
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":"
|
|
67
|
+
{"action":"spawn","id":"alpha","objective":"Read README.md and answer with its first heading."}
|
|
105
68
|
```
|
|
106
69
|
|
|
107
|
-
The call returns `{"
|
|
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":"
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
124
|
-
# model: provider/model
|
|
125
|
-
thinking: low
|
|
82
|
+
### spawn parameters
|
|
126
83
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
93
|
+
Error codes: `invalid_id`, `duplicate_id`, `unknown_id`, `max_concurrent`, `not_ready`, `cancelled`, `spawn_failed`, `steer_failed`, `not_in_herdr`.
|
|
151
94
|
|
|
152
|
-
|
|
95
|
+
### Where files land
|
|
153
96
|
|
|
154
|
-
|
|
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) |
|
|
164
|
-
| [modem-dev/pi-herdr-subagents](https://github.com/modem-dev/pi-herdr-subagents) | herdr launch and lifecycle
|
|
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
|
-
|
|
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/
|
|
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
|
-

|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[English](README.md) | 简体中文
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
每个子代理是一个独立的 pi 进程,跑在自己的 herdr tab 里。只有一个工具、四个动作:`spawn`、`steer`、`inspect`、`stop`。结果稍后作为消息回来。契约见 [spec 0002](docs/specs/0002_v2_architecture_spec.md)。
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## 特性
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
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
|
-
|
|
27
|
+
不要加 `-l`:它只写项目设置,在别处启动的子进程就不会加载本包。
|
|
26
28
|
|
|
27
|
-
|
|
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
|
-
|
|
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}
|
|
41
|
+
// 默认 "subagent"。须匹配 ^[a-z][a-z0-9_]{0,31}$。
|
|
58
42
|
"toolName": "subagent",
|
|
59
|
-
// 默认 "
|
|
60
|
-
"
|
|
61
|
-
// 默认 16
|
|
43
|
+
// 默认 ["ask"],逗号拼进 --exclude-tools,[] 表示不传该参数。可写 "mcp__*" 这类模式。
|
|
44
|
+
"excludeTools": ["ask"],
|
|
45
|
+
// 默认 16,范围 1..64。到上限时 spawn 与 steer 返回 max_concurrent。
|
|
62
46
|
"maxConcurrent": 16,
|
|
63
|
-
// 默认
|
|
64
|
-
"
|
|
65
|
-
// 默认 500,范围 0
|
|
47
|
+
// 默认 2000,范围 200..100000 字符。超出落 output.md。
|
|
48
|
+
"summaryMaxChars": 2000,
|
|
49
|
+
// 默认 500,范围 0..10000 毫秒。0 = 每条结果立即投递。
|
|
66
50
|
"aggregateWindowMs": 500,
|
|
67
|
-
// 默认
|
|
51
|
+
// 默认 3000,范围 100..60000 毫秒。esc 后这么久还没 idle 就关 pane 重开。
|
|
52
|
+
"interruptGraceMs": 3000,
|
|
53
|
+
// 默认 ["quit", "reload"]。可选值:new、resume、fork、quit、reload。
|
|
68
54
|
"closeChildrenOn": ["quit", "reload"],
|
|
69
|
-
// 默认
|
|
70
|
-
"
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
未知键、类型不对或枚举值非法都会让扩展加载失败:pi 打出 `invalid config <路径>: <字段>: unknown key` 后退出。越界的数字夹到边界,不报错。
|
|
60
|
+
严格 JSON,加载时读一次。未知键、类型不对或数值越界都会在加载时中止扩展,并一次性报出所有问题。
|
|
96
61
|
|
|
97
62
|
## 用法
|
|
98
63
|
|
|
99
|
-
|
|
100
|
-
2. 写一个 profile(见下一节)。frontmatter 的 `name` 就是 `run` 的寻址名。
|
|
101
|
-
3. 让模型调用工具:
|
|
64
|
+
在 herdr pane 里启动 `pi`,让模型调用工具:
|
|
102
65
|
|
|
103
66
|
```json
|
|
104
|
-
{"action":"
|
|
67
|
+
{"action":"spawn","id":"alpha","objective":"读 README.md,回答它的一级标题。"}
|
|
105
68
|
```
|
|
106
69
|
|
|
107
|
-
|
|
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":"
|
|
73
|
+
{"action":"steer","id":"alpha","message":"再看一下 Windows 分支。"}
|
|
74
|
+
{"action":"inspect","id":"alpha"}
|
|
75
|
+
{"action":"stop","id":"alpha"}
|
|
111
76
|
```
|
|
112
77
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
78
|
+
- `steer` 对运行中的子代理先发 `esc` 打断当前回合,等它 idle 后再投递消息。
|
|
79
|
+
- `inspect` 是唯一的进度查询面。不主动往上下文里塞状态。
|
|
80
|
+
- `stop` 幂等,并关掉 pane。
|
|
116
81
|
|
|
117
|
-
|
|
118
|
-
---
|
|
119
|
-
# run 的寻址名。文件名不参与查找
|
|
120
|
-
name: explore
|
|
121
|
-
description: 只读调研:读代码、回答问题,不改动任何文件
|
|
82
|
+
### spawn 参数
|
|
122
83
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
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
|
-
|
|
139
|
-
auto-exit: true
|
|
95
|
+
### 文件位置
|
|
140
96
|
|
|
141
|
-
|
|
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
|
-
|
|
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
|
-
|
|
108
|
+
## 测试
|
|
153
109
|
|
|
154
110
|
```bash
|
|
155
|
-
|
|
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/
|
|
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
|
-
##
|
|
129
|
+
## 许可
|
|
182
130
|
|
|
183
131
|
MIT,见 [LICENSE](LICENSE)。
|