pi-herdr-subagents-lite 0.5.2 → 0.7.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.
- package/README.md +101 -87
- package/README.zh-CN.md +108 -94
- package/package.json +15 -7
- package/src/profile/examples.ts +8 -12
- package/src/profile/seed.ts +12 -9
package/README.md
CHANGED
|
@@ -1,57 +1,118 @@
|
|
|
1
1
|
# pi-herdr-subagents-lite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[简体中文](README.zh-CN.md) | **English**
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Behavior is defined by the [v1 contract](docs/specs/0001-v1-contract.md). Project docs are in Chinese.
|
|
5
|
+
The extension runs subagents as separate pi processes in herdr panes. One tool has two actions: `run` starts a subagent, and `send` continues a subagent. Results come back asynchronously. The behavior follows the [v1 contract](docs/specs/0001-v1-contract.md).
|
|
8
6
|
|
|
9
7
|
## Features
|
|
10
8
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
9
|
+
- A subagent is a separate process. A human can take over its pane. If the subagent cwd equals the parent cwd, the subagent opens a tab in the same workspace. Otherwise the subagent opens a new workspace.
|
|
10
|
+
- Profiles have two layers: Markdown with frontmatter. One layer is global. One layer is per project.
|
|
11
|
+
- Results are async and merged. `run` returns at once. Each finished turn reports one `subagent_result`. Results inside `aggregateWindowMs` merge into one result. Oversize results go to an artifact file.
|
|
12
|
+
- Questions stay with the human. A child prompt only emits `herdr:blocked`. Nothing reaches the parent. The human answers in the child pane.
|
|
13
|
+
- Nesting is off by default. The extension is not a sandbox. If the profile does not name this tool, child tool sets drop this tool.
|
|
16
14
|
|
|
17
|
-
##
|
|
15
|
+
## Install
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
```bash
|
|
18
|
+
pi install npm:pi-herdr-subagents-lite # npm
|
|
19
|
+
pi install /path/to/pi-herdr-subagents-lite # local checkout
|
|
20
|
+
pi -e /path/to/pi-herdr-subagents-lite/src/index.ts # this process only
|
|
21
|
+
```
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
The old repository moved into this monorepo. Install from npm.
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
Do not pass `-l`. `-l` writes project settings only, so children started in another workspace never load the package. `pi -e` is single-process too.
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
Tested with herdr `0.9.5` and pi `1.4.0`, Node `>= 22.19`. The parent must run inside a herdr pane. Otherwise calls fail with `not_in_herdr`. Upgrade with `pi update --extensions`. Remove with `pi remove <source>`.
|
|
28
|
+
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
One global file holds the configuration: `<agent-dir>/pi-herdr-subagents-lite/config.json`. `<agent-dir>` defaults to `~/.pi/agent`. `PI_CODING_AGENT_DIR` sets `<agent-dir>`. The extension does not read a project config.
|
|
32
|
+
|
|
33
|
+
Defaults and clamp boundaries: `src/config/index.ts` and `test/config/config.test.ts`. Key meaning: [contract §1](docs/specs/0001-v1-contract.md#1-配置).
|
|
34
|
+
|
|
35
|
+
### Minimal config
|
|
36
|
+
|
|
37
|
+
A missing file means all defaults. To change one value, write only that value:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"maxConcurrent": 4
|
|
42
|
+
}
|
|
30
43
|
```
|
|
31
44
|
|
|
32
|
-
|
|
45
|
+
### Full configuration
|
|
33
46
|
|
|
34
|
-
|
|
47
|
+
The block below lists every key. Each value is the default.
|
|
35
48
|
|
|
36
|
-
|
|
49
|
+
```jsonc
|
|
50
|
+
{
|
|
51
|
+
// Default true. false = no subagent tool for the model. The bridge has its own switch.
|
|
52
|
+
"enabled": true,
|
|
53
|
+
// Default "subagent". Must match ^[a-z][a-z0-9_]{0,31}$. The name prefixes each guideline line.
|
|
54
|
+
"toolName": "subagent",
|
|
55
|
+
// Default "herdr". A plain name resolves from PATH; an absolute path pins a version.
|
|
56
|
+
"herdrBin": "herdr",
|
|
57
|
+
// Default 16, range 1 and up. At the limit run returns max_concurrent. A child with auto-exit: false keeps its slot after it settles.
|
|
58
|
+
"maxConcurrent": 16,
|
|
59
|
+
// Default 16384, range 1024 to 1048576. A longer text goes to an artifact file. The message keeps a truncated head and the path.
|
|
60
|
+
"maxResultChars": 16384,
|
|
61
|
+
// Default 500, range 0 to 10000 milliseconds. 0 = deliver each result at once. A larger value merges more results.
|
|
62
|
+
"aggregateWindowMs": 500,
|
|
63
|
+
// Default empty = never close. Values: new, resume, fork, quit, reload. A listed reason closes the child tabs on parent shutdown.
|
|
64
|
+
"closeChildrenOn": [],
|
|
65
|
+
// Default 250, range 50 to 5000 milliseconds. A larger value wakes less often and delivers later.
|
|
66
|
+
"inboxPollMs": 250,
|
|
67
|
+
// Default 1000, range 100 to 60000 milliseconds. Use while a child works or blocks, or within 30 s of run or send.
|
|
68
|
+
"pollIntervalMs": 1000,
|
|
69
|
+
// Default 8000, range 100 to 60000 milliseconds. Use when every live child only waits for send. A larger value notices a dead pane later.
|
|
70
|
+
"idlePollIntervalMs": 8000,
|
|
71
|
+
// Tool text overrides. Each key defaults to unset, which keeps the built-in text shown below.
|
|
72
|
+
"prompts": {
|
|
73
|
+
// Replaces the built-in description.
|
|
74
|
+
"description": "Run subagents and send them messages.",
|
|
75
|
+
// The one-line entry in Available tools. Empty = keep the tool out of that list.
|
|
76
|
+
"snippet": "",
|
|
77
|
+
// Replaces the built-in guideline lines. Keep {{profiles}} to list the profiles.
|
|
78
|
+
"guidelines": [
|
|
79
|
+
"The parent handles user interaction, cross-task synthesis, and decisions; subagents execute.",
|
|
80
|
+
"run only starts; it does not wait. The result arrives later as a message.",
|
|
81
|
+
"send only delivers; no state tracking.",
|
|
82
|
+
"Available profiles:\n{{profiles}}"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
// Turn pi prompt events into herdr:blocked events.
|
|
86
|
+
"bridge": {
|
|
87
|
+
// Default true. false = no herdr:blocked events.
|
|
88
|
+
"enabled": true,
|
|
89
|
+
// Default all five. Prompt kinds that count as blocked: custom, select, confirm, input, editor.
|
|
90
|
+
"blockedOn": ["custom", "select", "confirm", "input", "editor"]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The file is strict JSON and the extension reads it once, so delete the comments and restart pi after a change. 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.
|
|
96
|
+
|
|
97
|
+
## Usage
|
|
37
98
|
|
|
38
99
|
1. Start `pi` in a herdr pane.
|
|
39
|
-
2. Write a profile (next section)
|
|
100
|
+
2. Write a profile (next section). `run` takes the frontmatter `name` of the profile.
|
|
40
101
|
3. Ask the model to call the tool:
|
|
41
102
|
|
|
42
103
|
```json
|
|
43
104
|
{"action":"run","profile":"explore","task":"Read README.md and answer with its first heading."}
|
|
44
105
|
```
|
|
45
106
|
|
|
46
|
-
|
|
107
|
+
The call returns `{"state":"running",...}`. The subagent runs in its own tab. A `[subagent explore-1] done` message arrives later. Do not wait for the message in the same turn. Continue that child with:
|
|
47
108
|
|
|
48
109
|
```json
|
|
49
110
|
{"action":"send","name":"explore-1","message":"Also check the Windows branch."}
|
|
50
111
|
```
|
|
51
112
|
|
|
52
|
-
|
|
113
|
+
### Profile
|
|
53
114
|
|
|
54
|
-
Global profiles live in `<agent-dir>/pi-herdr-subagents-lite/profiles/*.md
|
|
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. If a project profile and a global profile share a `name`, the project profile wins.
|
|
55
116
|
|
|
56
117
|
```markdown
|
|
57
118
|
---
|
|
@@ -63,7 +124,7 @@ description: "Read-only research: read code, answer questions, change nothing"
|
|
|
63
124
|
# model: provider/model
|
|
64
125
|
thinking: low
|
|
65
126
|
|
|
66
|
-
# Plain names = strict allowlist
|
|
127
|
+
# Plain names = strict allowlist. +name / -name adjusts the default set. Never mix both
|
|
67
128
|
# Omitted = pi defaults minus this tool (nesting off); "" = empty allowlist
|
|
68
129
|
tools: read, bash
|
|
69
130
|
|
|
@@ -74,7 +135,7 @@ skills: ""
|
|
|
74
135
|
# task: body is the task text, no identity file
|
|
75
136
|
system-prompt: append
|
|
76
137
|
|
|
77
|
-
# Shut down and close the tab when settled
|
|
138
|
+
# Shut down and close the tab when settled. It waits while a prompt is open or the inbox has messages
|
|
78
139
|
auto-exit: true
|
|
79
140
|
|
|
80
141
|
# true = hidden from the guidelines; an explicit run still works
|
|
@@ -84,52 +145,15 @@ disable-model-invocation: false
|
|
|
84
145
|
You are a read-only explorer. Answer with file paths and line numbers.
|
|
85
146
|
```
|
|
86
147
|
|
|
87
|
-
Error codes: [contract section 2](docs/specs/0001-v1-contract.md#2-profile). Defaults: `src/profile/frontmatter.ts` and `test/profile/`. A file without `name
|
|
148
|
+
Error codes: [contract section 2](docs/specs/0001-v1-contract.md#2-profile). Defaults: `src/profile/frontmatter.ts` and `test/profile/`. A file without `name` or with an invalid field stays out of the list. The extension rejects all duplicate names in one layer. `run` returns `profile_invalid` with the file, the field and the reason.
|
|
88
149
|
|
|
89
|
-
|
|
150
|
+
The extension ships a bundled example. The file name and the `name` of the example are both `worker`. Loading reads `profiles/*.md` only. On every load the extension makes `profiles/examples/` match the bundled examples: it rewrites the bundled files and deletes extra files. So copy the example one level up:
|
|
90
151
|
|
|
91
152
|
```bash
|
|
92
|
-
cd <agent-dir>/pi-herdr-subagents-lite/profiles && cp examples/
|
|
153
|
+
cd <agent-dir>/pi-herdr-subagents-lite/profiles && cp examples/worker.md worker.md
|
|
93
154
|
```
|
|
94
155
|
|
|
95
|
-
##
|
|
96
|
-
|
|
97
|
-
One global file: `<agent-dir>/pi-herdr-subagents-lite/config.json`. `<agent-dir>` defaults to `~/.pi/agent` and follows `PI_CODING_AGENT_DIR`. Project config is not read.
|
|
98
|
-
|
|
99
|
-
Defaults and clamp boundaries: `src/config/index.ts`, `test/config/config.test.ts`. Key meaning: [contract §1](docs/specs/0001-v1-contract.md#1-配置).
|
|
100
|
-
|
|
101
|
-
### Minimal config
|
|
102
|
-
|
|
103
|
-
A missing file means all defaults. To change one value, write only that value:
|
|
104
|
-
|
|
105
|
-
```json
|
|
106
|
-
{
|
|
107
|
-
"maxConcurrent": 4
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Keys
|
|
112
|
-
|
|
113
|
-
| Key | Meaning |
|
|
114
|
-
|---|---|
|
|
115
|
-
| `enabled` | Gates tool registration only; the bridge has its own switch |
|
|
116
|
-
| `toolName` | Name the model sees; `^[a-z][a-z0-9_]{0,31}$` |
|
|
117
|
-
| `herdrBin` | herdr executable; a plain name resolves from PATH, an absolute path pins a version |
|
|
118
|
-
| `maxConcurrent` | Live children per parent session; an `auto-exit: false` child keeps its slot after settling |
|
|
119
|
-
| `maxResultChars` | Per-result character limit; beyond it the full text goes to an artifact and the message keeps a truncated head plus the path |
|
|
120
|
-
| `aggregateWindowMs` | Merge window in milliseconds; 0 = deliver each result at once |
|
|
121
|
-
| `closeChildrenOn` | Parent shutdown reasons that close its child tabs: `new` / `resume` / `fork` / `quit` / `reload`; empty = never |
|
|
122
|
-
| `inboxPollMs` | Child inbox polling interval |
|
|
123
|
-
| `pollIntervalMs` | Parent `agent list` interval while a child is working or blocked, or within 30 s of `run` / `send` |
|
|
124
|
-
| `idlePollIntervalMs` | Parent interval when every live child only waits for `send`; it bounds how late a vanished pane is noticed (a killed child whose pane lives is fixed at 10 s) |
|
|
125
|
-
| `prompts` | Tool text overrides: `description`, `snippet`, `guidelines`; omitted keys keep the built-in text; `snippet: ""` hides the tool from Available tools; keep `{{profiles}}` to list profiles |
|
|
126
|
-
| `bridge` | `enabled` turns pi prompt events into `herdr:blocked`; `blockedOn` lists the prompt kinds that count as blocked |
|
|
127
|
-
|
|
128
|
-
Strict JSON: an unknown key, a wrong type or a bad enum makes the extension fail to load, and pi exits naming the field. Out-of-range numbers clamp to the boundary. The config is read once, so restart pi after editing.
|
|
129
|
-
|
|
130
|
-
## Reference projects
|
|
131
|
-
|
|
132
|
-
The design is based on these projects. Thank you.
|
|
156
|
+
## Credits
|
|
133
157
|
|
|
134
158
|
| Project | Borrowed |
|
|
135
159
|
|---|---|
|
|
@@ -138,27 +162,17 @@ The design is based on these projects. Thank you.
|
|
|
138
162
|
| [modem-dev/pi-herdr-subagents](https://github.com/modem-dev/pi-herdr-subagents) | herdr launch and lifecycle; derived end states |
|
|
139
163
|
| [purboo/pi-durable-subagents](https://github.com/purboo/pi-durable-subagents) | Async delivery, idempotency, report-once results |
|
|
140
164
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
- [ARCHITECTURE](docs/ARCHITECTURE.md): module boundaries, dependency direction, test seams
|
|
144
|
-
- [GLOSSARY](docs/GLOSSARY.md): the only source for terms
|
|
145
|
-
- [Modules](docs/modules/): usage and trade-offs per module
|
|
165
|
+
Thank you for the code.
|
|
146
166
|
|
|
147
|
-
##
|
|
148
|
-
|
|
149
|
-
```bash
|
|
150
|
-
pnpm install # dependencies
|
|
151
|
-
pnpm check # the four checks below
|
|
152
|
-
pnpm test # unit tests (vitest)
|
|
153
|
-
pnpm lint # biome
|
|
154
|
-
pnpm typecheck # tsc --noEmit
|
|
155
|
-
pnpm check:imports # dependency direction, per docs/ARCHITECTURE.md
|
|
156
|
-
pnpm test:e2e # real herdr plus real pi children, not part of pnpm check
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Run `git config core.hooksPath .githooks` once to run `pnpm check` on every commit.
|
|
167
|
+
## Docs
|
|
160
168
|
|
|
161
|
-
|
|
169
|
+
| Document | Content |
|
|
170
|
+
|---|---|
|
|
171
|
+
| [docs/specs/0001-v1-contract.md](docs/specs/0001-v1-contract.md) | The v1 contract |
|
|
172
|
+
| [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | Module boundaries, dependency direction, test seams |
|
|
173
|
+
| [docs/modules/](docs/modules/) | Usage and trade-offs per module |
|
|
174
|
+
| [docs/GLOSSARY.md](docs/GLOSSARY.md) | The only source for terms |
|
|
175
|
+
| [CHANGELOG.md](CHANGELOG.md) | Release notes |
|
|
162
176
|
|
|
163
177
|
## License
|
|
164
178
|
|
package/README.zh-CN.md
CHANGED
|
@@ -1,61 +1,122 @@
|
|
|
1
1
|
# pi-herdr-subagents-lite
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
**[简体中文](README.zh-CN.md)** | [English](README.md)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
行为以 [v1 契约](docs/specs/0001-v1-contract.md) 为准。
|
|
5
|
+
本扩展让子代理作为独立 pi 进程,跑在 herdr pane 里。一个工具有两个 action:`run` 起子代理,`send` 续聊。结果异步回投。行为以 [v1 契约](docs/specs/0001-v1-contract.md) 为准。
|
|
8
6
|
|
|
9
7
|
## 功能
|
|
10
8
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
9
|
+
- 独立进程,可人工接管。每个子代理是 herdr pane 里的独立 pi 进程。子代理的 cwd 与父相同时,它在同一个 workspace 新开 tab。cwd 不同时,它新建 workspace。
|
|
10
|
+
- 两层 profile:Markdown + frontmatter。全局一层,项目一层。
|
|
11
|
+
- 结果异步,可合并。`run` 立即返回。每次收工投一条 `subagent_result`。落在 `aggregateWindowMs` 内的结果合并成一条。超长结果落 artifact 文件。
|
|
12
|
+
- 反问留在人这边。子代理弹对话框只发 `herdr:blocked`。父侧收不到这个消息。人在子 pane 里回答。
|
|
13
|
+
- 默认不嵌套,也不是沙箱。子代理的工具集默认去掉本工具。只有 profile 点名,才授予本工具。
|
|
16
14
|
|
|
17
|
-
##
|
|
15
|
+
## 安装
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
```bash
|
|
18
|
+
pi install npm:pi-herdr-subagents-lite # npm
|
|
19
|
+
pi install /path/to/pi-herdr-subagents-lite # 本地源码
|
|
20
|
+
pi -e /path/to/pi-herdr-subagents-lite/src/index.ts # 只对当前进程生效
|
|
21
|
+
```
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
旧仓已并入 monorepo。请用 npm 安装。
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
不要加 `-l`。`-l` 只写项目设置,在别的 workspace 里起的子代理就加载不到。`pi -e` 同样是单进程。
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
在 herdr `0.9.5` 与 pi `1.4.0` 上测过,Node `>= 22.19`。父会话必须在 herdr pane 里。不在时返回 `not_in_herdr`。升级用 `pi update --extensions`。卸载用 `pi remove <source>`。
|
|
28
|
+
|
|
29
|
+
## 配置
|
|
30
|
+
|
|
31
|
+
只有一个全局文件:`<agent-dir>/pi-herdr-subagents-lite/config.json`。`<agent-dir>` 默认 `~/.pi/agent`,跟随 `PI_CODING_AGENT_DIR`。扩展不读项目级配置。
|
|
32
|
+
|
|
33
|
+
默认值与 clamp 边界见 `src/config/index.ts` 与 `test/config/config.test.ts`。键与语义见[契约 §1](docs/specs/0001-v1-contract.md#1-配置)。
|
|
34
|
+
|
|
35
|
+
### 最小配置
|
|
36
|
+
|
|
37
|
+
文件不存在时,全部用默认值。只改一项,就只写这一项:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"maxConcurrent": 4
|
|
42
|
+
}
|
|
30
43
|
```
|
|
31
44
|
|
|
32
|
-
|
|
45
|
+
### 完整配置
|
|
33
46
|
|
|
34
|
-
|
|
47
|
+
下面这份列出全部键。每个取值就是默认值。
|
|
35
48
|
|
|
36
|
-
|
|
49
|
+
```jsonc
|
|
50
|
+
{
|
|
51
|
+
// 默认 true。false = 模型看不到本工具。bridge 有独立开关。
|
|
52
|
+
"enabled": true,
|
|
53
|
+
// 默认 "subagent"。须匹配 ^[a-z][a-z0-9_]{0,31}$。它会作为每条 guideline 的前缀。
|
|
54
|
+
"toolName": "subagent",
|
|
55
|
+
// 默认 "herdr"。裸名从 PATH 解析。绝对路径锁定版本。
|
|
56
|
+
"herdrBin": "herdr",
|
|
57
|
+
// 默认 16,下限 1。到上限时 run 返回 max_concurrent。auto-exit: false 的子代理收工后仍占槽。
|
|
58
|
+
"maxConcurrent": 16,
|
|
59
|
+
// 默认 16384,范围 1024 到 1048576。超上限时全文落 artifact 文件。消息里留截断的头和路径。
|
|
60
|
+
"maxResultChars": 16384,
|
|
61
|
+
// 默认 500,范围 0 到 10000,单位毫秒。0 = 逐条立即投递。调大合并更多结果。
|
|
62
|
+
"aggregateWindowMs": 500,
|
|
63
|
+
// 默认空 = 从不关。取值:new、resume、fork、quit、reload。列出的原因会在父会话退出时关掉子 tab。
|
|
64
|
+
"closeChildrenOn": [],
|
|
65
|
+
// 默认 250,范围 50 到 5000,单位毫秒。调大省唤醒,投递变慢。
|
|
66
|
+
"inboxPollMs": 250,
|
|
67
|
+
// 默认 1000,范围 100 到 60000,单位毫秒。子代理在 working 或 blocked 时用它,刚 run / send 的 30 秒内也用它。
|
|
68
|
+
"pollIntervalMs": 1000,
|
|
69
|
+
// 默认 8000,范围 100 到 60000,单位毫秒。所有 live 子代理都只在等 send 时用它。调大后,发现 pane 消失更晚。
|
|
70
|
+
"idlePollIntervalMs": 8000,
|
|
71
|
+
// 工具文案覆盖。每个键默认未设置,用下面这份内置文案。
|
|
72
|
+
"prompts": {
|
|
73
|
+
// 替换内置描述。
|
|
74
|
+
"description": "Run subagents and send them messages.",
|
|
75
|
+
// Available tools 里的那一行。空 = 不出现在该列表。
|
|
76
|
+
"snippet": "",
|
|
77
|
+
// 替换内置 guideline 各行。保留 {{profiles}} 才会列出 profile。
|
|
78
|
+
"guidelines": [
|
|
79
|
+
"The parent handles user interaction, cross-task synthesis, and decisions; subagents execute.",
|
|
80
|
+
"run only starts; it does not wait. The result arrives later as a message.",
|
|
81
|
+
"send only delivers; no state tracking.",
|
|
82
|
+
"Available profiles:\n{{profiles}}"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
// 把 pi 对话框事件转成 herdr:blocked 事件。
|
|
86
|
+
"bridge": {
|
|
87
|
+
// 默认 true。false = 不发 herdr:blocked。
|
|
88
|
+
"enabled": true,
|
|
89
|
+
// 默认全五种。算作 blocked 的对话框类型:custom、select、confirm、input、editor。
|
|
90
|
+
"blockedOn": ["custom", "select", "confirm", "input", "editor"]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
文件必须是严格 JSON。扩展只读一次,所以保存前删掉注释,改完重启 pi。未知键、类型不对或枚举值非法都会让扩展加载失败:pi 打出 `invalid config <路径>: <字段>: unknown key` 后退出。超范围的数字会被夹到边界,不报错。
|
|
96
|
+
|
|
97
|
+
## 用法
|
|
37
98
|
|
|
38
99
|
1. 在 herdr pane 里启动 `pi`。
|
|
39
|
-
2. 写一个 profile
|
|
100
|
+
2. 写一个 profile(下一节)。frontmatter 的 `name` 就是 `run` 的寻址名。
|
|
40
101
|
3. 让模型调用工具:
|
|
41
102
|
|
|
42
103
|
```json
|
|
43
104
|
{"action":"run","profile":"explore","task":"读 README.md,回答它的第一个标题。"}
|
|
44
105
|
```
|
|
45
106
|
|
|
46
|
-
|
|
107
|
+
工具返回 `{"state":"running",...}`。子代理在自己的 tab 里跑。稍后收到 `[subagent explore-1] done` 消息。不要在同一轮里等结果。续聊那个子代理:
|
|
47
108
|
|
|
48
109
|
```json
|
|
49
110
|
{"action":"send","name":"explore-1","message":"也看一下 Windows 那条分支。"}
|
|
50
111
|
```
|
|
51
112
|
|
|
52
|
-
|
|
113
|
+
### Profile
|
|
53
114
|
|
|
54
|
-
全局 profile 在 `<agent-dir>/pi-herdr-subagents-lite/profiles/*.md
|
|
115
|
+
全局 profile 在 `<agent-dir>/pi-herdr-subagents-lite/profiles/*.md`。项目 profile 在 `.pi/pi-herdr-subagents-lite/profiles/*.md`,项目受信任后才读。`name` 相同时,项目覆盖全局。
|
|
55
116
|
|
|
56
117
|
```markdown
|
|
57
118
|
---
|
|
58
|
-
# run
|
|
119
|
+
# run 的寻址名。文件名不参与查找
|
|
59
120
|
name: explore
|
|
60
121
|
description: 只读调研:读代码、回答问题,不改动任何文件
|
|
61
122
|
|
|
@@ -63,103 +124,56 @@ description: 只读调研:读代码、回答问题,不改动任何文件
|
|
|
63
124
|
# model: provider/model
|
|
64
125
|
thinking: low
|
|
65
126
|
|
|
66
|
-
# 纯名字 =
|
|
67
|
-
# 省略 = pi
|
|
127
|
+
# 纯名字 = 严格白名单。+名字 / -名字 在默认集上增删,两者不能混用
|
|
128
|
+
# 省略 = pi 默认集去掉本工具(不嵌套)。"" = 空白名单
|
|
68
129
|
tools: read, bash
|
|
69
130
|
|
|
70
|
-
# 省略 = 由 pi
|
|
131
|
+
# 省略 = 由 pi 发现。"" = 不加载。列表 = 只加载列出的
|
|
71
132
|
skills: ""
|
|
72
133
|
|
|
73
134
|
# append / replace:正文追加到或替换系统提示
|
|
74
135
|
# task:正文就是任务文本,不写身份文件
|
|
75
136
|
system-prompt: append
|
|
76
137
|
|
|
77
|
-
# 收工后自行退出并关掉 tab
|
|
138
|
+
# 收工后自行退出并关掉 tab。有打开的对话框或 inbox 待投递时会等
|
|
78
139
|
auto-exit: true
|
|
79
140
|
|
|
80
|
-
# true = 不出现在 guidelines 的 profile
|
|
141
|
+
# true = 不出现在 guidelines 的 profile 列表里。显式 run 仍然可用
|
|
81
142
|
disable-model-invocation: false
|
|
82
143
|
---
|
|
83
144
|
|
|
84
|
-
|
|
145
|
+
你是一名只读探索者。回答时给出文件路径与行号。
|
|
85
146
|
```
|
|
86
147
|
|
|
87
|
-
错误码见
|
|
148
|
+
错误码见[契约 §2](docs/specs/0001-v1-contract.md#2-profile)。默认值见 `src/profile/frontmatter.ts` 与 `test/profile/`。没写 `name` 的文件、字段非法的文件与同层同名的文件都不进列表。对它调用 `run`,返回 `profile_invalid`,带文件、字段与原因。
|
|
88
149
|
|
|
89
|
-
扩展自带一个示例 profile
|
|
150
|
+
扩展自带一个示例 profile。文件名和 `name` 都是 `worker`。加载只读 `profiles/*.md`。每次加载都把 `profiles/examples/` 对齐到扩展自带的示例:重写自带文件,删掉多余文件。所以复制一份到上一层即可:
|
|
90
151
|
|
|
91
152
|
```bash
|
|
92
|
-
cd <agent-dir>/pi-herdr-subagents-lite/profiles && cp examples/
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## 配置
|
|
96
|
-
|
|
97
|
-
只有一个全局文件:`<agent-dir>/pi-herdr-subagents-lite/config.json`。`<agent-dir>` 默认 `~/.pi/agent`,跟随 `PI_CODING_AGENT_DIR`。项目级配置不读。
|
|
98
|
-
|
|
99
|
-
默认值与 clamp 边界:`src/config/index.ts`、`test/config/config.test.ts`。键与语义:[契约 §1](docs/specs/0001-v1-contract.md#1-配置)。
|
|
100
|
-
|
|
101
|
-
### 最小配置
|
|
102
|
-
|
|
103
|
-
文件不存在就全用默认值。只改一项,就只写这一项:
|
|
104
|
-
|
|
105
|
-
```json
|
|
106
|
-
{
|
|
107
|
-
"maxConcurrent": 4
|
|
108
|
-
}
|
|
153
|
+
cd <agent-dir>/pi-herdr-subagents-lite/profiles && cp examples/worker.md worker.md
|
|
109
154
|
```
|
|
110
155
|
|
|
111
|
-
### 键
|
|
112
|
-
|
|
113
|
-
| 键 | 含义 |
|
|
114
|
-
|---|---|
|
|
115
|
-
| `enabled` | 只管工具注册;bridge 有自己的开关 |
|
|
116
|
-
| `toolName` | 模型看到的工具名;`^[a-z][a-z0-9_]{0,31}$` |
|
|
117
|
-
| `herdrBin` | herdr 可执行文件;裸名从 PATH 解析,绝对路径锁定版本 |
|
|
118
|
-
| `maxConcurrent` | 每个父会话并存的子代理数;`auto-exit: false` 的子代理收工后仍占槽 |
|
|
119
|
-
| `maxResultChars` | 单条结果字符上限;超了全文落 artifact,消息里留截断的头和路径 |
|
|
120
|
-
| `aggregateWindowMs` | 合并窗口,毫秒;0 = 逐条立即投递 |
|
|
121
|
-
| `closeChildrenOn` | 父会话以这些原因退出时关掉子 tab:`new` / `resume` / `fork` / `quit` / `reload`;空 = 从不关 |
|
|
122
|
-
| `inboxPollMs` | 子侧 inbox 轮询间隔 |
|
|
123
|
-
| `pollIntervalMs` | 父侧 `agent list` 间隔;有子代理在 working 或 blocked,或刚 `run` / `send` 的 30 秒内用 |
|
|
124
|
-
| `idlePollIntervalMs` | 所有 live 子代理都只是在等 `send` 时的间隔;它决定 pane 消失最晚多久被发现(pane 还在、进程被杀的那类固定 10 秒) |
|
|
125
|
-
| `prompts` | 覆盖工具文案:`description`、`snippet`、`guidelines`;省略的键用内置文案;`snippet: ""` 让工具从 Available tools 消失;保留 `{{profiles}}` 才会列出 profile |
|
|
126
|
-
| `bridge` | `enabled` 把 pi 对话框事件转成 `herdr:blocked`;`blockedOn` 列出算 blocked 的对话框类型 |
|
|
127
|
-
|
|
128
|
-
必须是严格 JSON:未知键、类型不对、枚举非法都会让扩展加载失败,pi 报出字段名退出。超范围的数字会被夹到边界,不报错。配置只读一次,改完重启 pi。
|
|
129
|
-
|
|
130
156
|
## 参考项目
|
|
131
157
|
|
|
132
|
-
设计参考了这些项目,感谢作者。
|
|
133
|
-
|
|
134
158
|
| 项目 | 借鉴内容 |
|
|
135
159
|
|---|---|
|
|
136
160
|
| [earendil-works/pi](https://github.com/earendil-works/pi) | 扩展 API、包布局、官方示例 |
|
|
137
|
-
| [fyang93/pi-herdr-subagents](https://github.com/fyang93/pi-herdr-subagents) | profile
|
|
138
|
-
| [modem-dev/pi-herdr-subagents](https://github.com/modem-dev/pi-herdr-subagents) | herdr
|
|
161
|
+
| [fyang93/pi-herdr-subagents](https://github.com/fyang93/pi-herdr-subagents) | profile 字段形状。隔离 herdr session 的集成测试 |
|
|
162
|
+
| [modem-dev/pi-herdr-subagents](https://github.com/modem-dev/pi-herdr-subagents) | herdr 启动与生命周期。终态归类 |
|
|
139
163
|
| [purboo/pi-durable-subagents](https://github.com/purboo/pi-durable-subagents) | 异步投递、幂等、只上报一次 |
|
|
140
164
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
- [ARCHITECTURE](docs/ARCHITECTURE.md):模块边界、依赖方向、测试 seam
|
|
144
|
-
- [GLOSSARY](docs/GLOSSARY.md):术语唯一来源
|
|
145
|
-
- [模块](docs/modules/):各模块的用法与取舍
|
|
165
|
+
感谢这些项目的代码。
|
|
146
166
|
|
|
147
|
-
##
|
|
148
|
-
|
|
149
|
-
```bash
|
|
150
|
-
pnpm install # 装依赖
|
|
151
|
-
pnpm check # 下面四项
|
|
152
|
-
pnpm test # 单测(vitest)
|
|
153
|
-
pnpm lint # biome
|
|
154
|
-
pnpm typecheck # tsc --noEmit
|
|
155
|
-
pnpm check:imports # 依赖方向,按 docs/ARCHITECTURE.md 校验
|
|
156
|
-
pnpm test:e2e # 真 herdr + 真 pi 子进程,不在 pnpm check 里
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
跑一次 `git config core.hooksPath .githooks`,之后每次提交都会跑 `pnpm check`。
|
|
167
|
+
## 文档
|
|
160
168
|
|
|
161
|
-
|
|
169
|
+
| 文档 | 内容 |
|
|
170
|
+
|---|---|
|
|
171
|
+
| [docs/specs/0001-v1-contract.md](docs/specs/0001-v1-contract.md) | v1 契约 |
|
|
172
|
+
| [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | 模块边界、依赖方向、测试 seam |
|
|
173
|
+
| [docs/modules/](docs/modules/) | 各模块的用法与取舍 |
|
|
174
|
+
| [docs/GLOSSARY.md](docs/GLOSSARY.md) | 术语唯一来源 |
|
|
175
|
+
| [CHANGELOG.md](CHANGELOG.md) | 发布记录 |
|
|
162
176
|
|
|
163
|
-
##
|
|
177
|
+
## License
|
|
164
178
|
|
|
165
179
|
MIT,见 [LICENSE](LICENSE)。
|
package/package.json
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-herdr-subagents-lite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Run pi subagents in herdr panes.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "setwhite",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/setwhite/pi-
|
|
10
|
+
"url": "git+https://github.com/setwhite/pi-extensions.git",
|
|
11
|
+
"directory": "packages/pi-herdr-subagents-lite"
|
|
11
12
|
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
|
|
13
|
+
"keywords": [
|
|
14
|
+
"pi-package",
|
|
15
|
+
"pi-extension",
|
|
16
|
+
"herdr",
|
|
17
|
+
"subagent"
|
|
18
|
+
],
|
|
19
|
+
"files": [
|
|
20
|
+
"src"
|
|
21
|
+
],
|
|
14
22
|
"packageManager": "pnpm@12.3.4",
|
|
15
23
|
"engines": {
|
|
16
24
|
"node": ">=22.19.0"
|
|
@@ -22,11 +30,11 @@
|
|
|
22
30
|
},
|
|
23
31
|
"scripts": {
|
|
24
32
|
"lint": "biome check --error-on-warnings .",
|
|
25
|
-
"
|
|
33
|
+
"lint:fix": "biome check --write .",
|
|
34
|
+
"check:imports": "node ../../scripts/check-imports.mjs",
|
|
26
35
|
"typecheck": "tsc --noEmit",
|
|
27
36
|
"test": "vitest run",
|
|
28
|
-
"test:e2e": "vitest run --config vitest.e2e.config.ts"
|
|
29
|
-
"check": "pnpm lint && pnpm check:imports && pnpm typecheck && pnpm test"
|
|
37
|
+
"test:e2e": "vitest run --config vitest.e2e.config.ts"
|
|
30
38
|
},
|
|
31
39
|
"peerDependencies": {
|
|
32
40
|
"@earendil-works/pi-coding-agent": "*",
|
package/src/profile/examples.ts
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
export const EXAMPLE_PROFILE_FILE = "
|
|
1
|
+
export const EXAMPLE_PROFILE_FILE = "worker.md";
|
|
2
2
|
|
|
3
3
|
export const EXAMPLE_PROFILE = `---
|
|
4
|
-
# Copy this file to profiles/
|
|
5
|
-
name:
|
|
6
|
-
description:
|
|
4
|
+
# Copy this file to profiles/worker.md to use it.
|
|
5
|
+
name: worker
|
|
6
|
+
description: General purpose.
|
|
7
7
|
# model: provider/model
|
|
8
8
|
# thinking: low
|
|
9
9
|
tools: -subagent
|
|
10
|
-
skills: []
|
|
10
|
+
# skills: []
|
|
11
11
|
system-prompt: append
|
|
12
|
-
auto-exit:
|
|
12
|
+
auto-exit: true
|
|
13
13
|
disable-model-invocation: false
|
|
14
14
|
---
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- Change only files in that domain.
|
|
18
|
-
- Read the code yourself. Do not ask the parent for context.
|
|
19
|
-
- Report what changed, what is left, and what blocks you.
|
|
20
|
-
- Stop if only the user can decide. Report the question.
|
|
15
|
+
- Stop when the task needs a design decision. Report what you need; the parent answers. Do not guess.
|
|
16
|
+
- Report concisely what changed, what is left, and what blocks you.
|
|
21
17
|
`;
|
package/src/profile/seed.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
1
|
+
import { mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
3
|
import { errorText } from "../error/index.ts";
|
|
4
4
|
import { EXAMPLE_PROFILE, EXAMPLE_PROFILE_FILE } from "./examples.ts";
|
|
5
5
|
|
|
6
6
|
export function seedExampleProfile(profilesDir: string): void {
|
|
7
|
-
const
|
|
7
|
+
const dir = join(profilesDir, "examples");
|
|
8
8
|
try {
|
|
9
|
-
mkdirSync(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
mkdirSync(dir, { recursive: true });
|
|
10
|
+
// 示例目录是分发物,不是用户数据:每次加载都与包内一致,旧示例过期比丢改动更糟(DEC-0057)。
|
|
11
|
+
writeFileSync(join(dir, EXAMPLE_PROFILE_FILE), EXAMPLE_PROFILE);
|
|
12
|
+
for (const entry of readdirSync(dir)) {
|
|
13
|
+
if (entry !== EXAMPLE_PROFILE_FILE) {
|
|
14
|
+
rmSync(join(dir, entry), { recursive: true, force: true });
|
|
15
|
+
}
|
|
14
16
|
}
|
|
17
|
+
} catch (error) {
|
|
15
18
|
// 示例是可选文件;写不成不能阻止扩展加载。
|
|
16
|
-
process.emitWarning(`pi-herdr-subagents-lite: could not write ${
|
|
19
|
+
process.emitWarning(`pi-herdr-subagents-lite: could not write ${dir}: ${errorText(error)}`);
|
|
17
20
|
}
|
|
18
21
|
}
|