@ferris1225/pi-subagents 0.4.0 → 0.5.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/LICENSE +21 -21
- package/README-zh.md +153 -147
- package/README.md +167 -159
- package/agents/explore.md +42 -42
- package/agents/plan.md +41 -41
- package/agents/reviewer.md +45 -45
- package/agents/worker.md +44 -44
- package/package.json +54 -54
- package/src/agents.ts +157 -157
- package/src/config.ts +168 -155
- package/src/index.ts +437 -417
- package/src/models.ts +69 -0
- package/src/monitor.ts +275 -275
- package/src/prompt.ts +58 -57
- package/src/setup.ts +264 -222
- package/src/spawn.ts +473 -386
- package/src/ui.ts +231 -231
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 ferris1225
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ferris1225
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README-zh.md
CHANGED
|
@@ -1,147 +1,153 @@
|
|
|
1
|
-
# pi-subagents
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@ferris1225/pi-subagents)
|
|
4
|
-
[](https://www.npmjs.com/package/@ferris1225/pi-subagents)
|
|
5
|
-
[](./LICENSE)
|
|
6
|
-

|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
[English](./README.md) | 中文
|
|
10
|
-
|
|
11
|
-
一个聚焦的 [pi](https://pi.dev) 扩展,给主模型提供**它真的会去用**的 sub-agent:
|
|
12
|
-
`explore`、`worker`、`reviewer`(外加可选的 `plan`),每个都跑在独立的 `pi` 进程里。
|
|
13
|
-
真正的差异点不是 agent 本身,而是**主动派发注入**——让模型自己主动去委派任务,
|
|
14
|
-
于是你可以把全局 `AGENTS.md` 里那两段派发/审查规则删掉。
|
|
15
|
-
|
|
16
|
-
## 为什么选 pi-subagents?
|
|
17
|
-
|
|
18
|
-
pi 故意不内置 sub-agent。社区的补位方案分两种,但都没踩中:
|
|
19
|
-
|
|
20
|
-
- **太重** —— 9 个 agent、链式流水线、worktree 集群、到处都是 slash 命令。强大,但机器太多。
|
|
21
|
-
- **太安静** —— 只给一个 `subagent` 工具,模型**很少主动调用**,因为 pi 只把工具本身展示给主模型,
|
|
22
|
-
从不展示每个 agent 的描述。于是除非你在全局提示词里强制,否则这些 agent 一直吃灰。
|
|
23
|
-
|
|
24
|
-
`pi-subagents` 走中间路线:
|
|
25
|
-
|
|
26
|
-
| 优势 | 对你意味着什么 |
|
|
27
|
-
|------|----------------|
|
|
28
|
-
| **真的会被用** | `before_agent_start` hook 每轮把 agent 清单 + 派发/审查指令注入系统提示词,再由 tool `promptGuidelines` 和 `Use PROACTIVELY when …` 描述加强。这正是重型框架依赖的那根杠杆——我们只是把它变成默认行为。 |
|
|
29
|
-
| **体量合适** | 3 个聚焦的 agent(+1 可选),不是 9 个。没有链式/worktree/集群机器。只有 single 和 parallel 两种模式。 |
|
|
30
|
-
| **替代你的 AGENTS.md 规则** | 注入的指令是 "Sub-agent Dispatch" 和 "Review, Verification & Commit" 两段的自包含替代。装上它,然后把那两段删掉。 |
|
|
31
|
-
| **真隔离** | 每个 agent 都是独立 `pi` 进程(`--no-session`),委派出去的活绝不污染主上下文。 |
|
|
32
|
-
| **该只读就只读** | `explore`、`plan`、`reviewer` 都是只读。`reviewer` 跑在**独立**上下文,避免自我确认偏差。 |
|
|
33
|
-
| **纯选择式配置** | 不用手敲值:勾选式模块选择器 + 模糊过滤、可翻页的模型选择器。 |
|
|
34
|
-
| **合理的模型默认** | 每 agent 可单独覆盖模型;不选就**用主窗口当前 session
|
|
35
|
-
|
|
|
36
|
-
| **零运行时依赖** | 纯 pi 扩展,仅 peer 依赖,无需构建步骤。 |
|
|
37
|
-
|
|
38
|
-
## 安装
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
pi install npm:@ferris1225/pi-subagents
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
|
55
|
-
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
- `
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
1
|
+
# pi-subagents
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@ferris1225/pi-subagents)
|
|
4
|
+
[](https://www.npmjs.com/package/@ferris1225/pi-subagents)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
[English](./README.md) | 中文
|
|
10
|
+
|
|
11
|
+
一个聚焦的 [pi](https://pi.dev) 扩展,给主模型提供**它真的会去用**的 sub-agent:
|
|
12
|
+
`explore`、`worker`、`reviewer`(外加可选的 `plan`),每个都跑在独立的 `pi` 进程里。
|
|
13
|
+
真正的差异点不是 agent 本身,而是**主动派发注入**——让模型自己主动去委派任务,
|
|
14
|
+
于是你可以把全局 `AGENTS.md` 里那两段派发/审查规则删掉。
|
|
15
|
+
|
|
16
|
+
## 为什么选 pi-subagents?
|
|
17
|
+
|
|
18
|
+
pi 故意不内置 sub-agent。社区的补位方案分两种,但都没踩中:
|
|
19
|
+
|
|
20
|
+
- **太重** —— 9 个 agent、链式流水线、worktree 集群、到处都是 slash 命令。强大,但机器太多。
|
|
21
|
+
- **太安静** —— 只给一个 `subagent` 工具,模型**很少主动调用**,因为 pi 只把工具本身展示给主模型,
|
|
22
|
+
从不展示每个 agent 的描述。于是除非你在全局提示词里强制,否则这些 agent 一直吃灰。
|
|
23
|
+
|
|
24
|
+
`pi-subagents` 走中间路线:
|
|
25
|
+
|
|
26
|
+
| 优势 | 对你意味着什么 |
|
|
27
|
+
|------|----------------|
|
|
28
|
+
| **真的会被用** | `before_agent_start` hook 每轮把 agent 清单 + 派发/审查指令注入系统提示词,再由 tool `promptGuidelines` 和 `Use PROACTIVELY when …` 描述加强。这正是重型框架依赖的那根杠杆——我们只是把它变成默认行为。 |
|
|
29
|
+
| **体量合适** | 3 个聚焦的 agent(+1 可选),不是 9 个。没有链式/worktree/集群机器。只有 single 和 parallel 两种模式。 |
|
|
30
|
+
| **替代你的 AGENTS.md 规则** | 注入的指令是 "Sub-agent Dispatch" 和 "Review, Verification & Commit" 两段的自包含替代。装上它,然后把那两段删掉。 |
|
|
31
|
+
| **真隔离** | 每个 agent 都是独立 `pi` 进程(`--no-session`),委派出去的活绝不污染主上下文。 |
|
|
32
|
+
| **该只读就只读** | `explore`、`plan`、`reviewer` 都是只读。`reviewer` 跑在**独立**上下文,避免自我确认偏差。 |
|
|
33
|
+
| **纯选择式配置** | 不用手敲值:勾选式模块选择器 + 模糊过滤、可翻页的模型选择器。 |
|
|
34
|
+
| **合理的模型默认** | 每 agent 可单独覆盖模型;不选就**用主窗口当前 session 的模型**。配置中的不可用模型会自动修复并写回。 |
|
|
35
|
+
| **子代理是叶节点** | 子进程不会获得 `subagent` 工具,因此不会递归派发或无限运行。 |
|
|
36
|
+
| **零运行时依赖** | 纯 pi 扩展,仅 peer 依赖,无需构建步骤。 |
|
|
37
|
+
|
|
38
|
+
## 安装
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pi install npm:@ferris1225/pi-subagents
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
要求 pi **≥ 0.80.6**——子代理思考强度使用该版本引入的 `--thinking` 参数值。
|
|
45
|
+
|
|
46
|
+
然后运行配置向导(纯选择):
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
/subagents-setup
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Agent 一览
|
|
53
|
+
|
|
54
|
+
| Agent | 默认启用 | 工具 | 职责 |
|
|
55
|
+
|-------|:--------:|------|------|
|
|
56
|
+
| `explore` | ✅ | 只读 | 快速代码侦察;返回压缩后的发现以便交接。 |
|
|
57
|
+
| `worker` | ✅ | 全部 | 实现/修复/重构/测试一个自包含任务。**内部先规划后动手。** |
|
|
58
|
+
| `reviewer` | ✅ | 只读 | 在独立上下文做对抗式提交前审查。 |
|
|
59
|
+
| `plan` | 可选 | 只读 | 产出可人工审阅的独立实现计划。worker 本就会内部规划,所以只在你需要把计划作为独立产物时才用它。 |
|
|
60
|
+
|
|
61
|
+
每个 agent 都是一个 Markdown 文件(`agents/*.md`:YAML frontmatter + 正文作为 system prompt)。
|
|
62
|
+
想覆盖任意一个,只需把同名 `name` 的文件放进 `~/.pi/agent/agents/`(用户级)或 `.pi/agents/`(项目级)。
|
|
63
|
+
|
|
64
|
+
## 主动派发是怎么工作的
|
|
65
|
+
|
|
66
|
+
pi 从不把每个 agent 的描述展示给主模型——它只看到 `subagent` 这个工具。三根杠杆解决这一点:
|
|
67
|
+
|
|
68
|
+
1. **`before_agent_start` 注入** —— 每一轮,把启用的 agent 加上一段派发/审查指令追加进父模型系统提示词。
|
|
69
|
+
2. **tool `promptSnippet` / `promptGuidelines`** —— 在工具激活时持续强化「何时该委派」。
|
|
70
|
+
3. **`Use PROACTIVELY when …` 描述** —— 在 Claude Code agent 生态被验证过的触发措辞。
|
|
71
|
+
|
|
72
|
+
这段指令会引导出一条干净的流程:**`explore` → `worker` → `reviewer`**,独立任务并行扇出,
|
|
73
|
+
以及「信任但需验证」的交接。
|
|
74
|
+
|
|
75
|
+
## 配置
|
|
76
|
+
|
|
77
|
+
存放在 `~/.pi/agent/pi-subagents.json`(尊重 `PI_CODING_AGENT_DIR`):
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"enabledAgents": ["explore", "worker", "reviewer"],
|
|
82
|
+
"agentModels": { "explore": "anthropic/claude-haiku-4-5" },
|
|
83
|
+
"thinkingLevel": "max",
|
|
84
|
+
"proactiveInjection": true,
|
|
85
|
+
"agentScope": "user"
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- `enabledAgents` —— 哪些 agent 可被发现并注入。
|
|
90
|
+
- `agentModels` —— 每 agent 的模型覆盖(`"provider/model-id"`)。如果已保存的模型不可用,会切换到主窗口当前模型并写回此文件。
|
|
91
|
+
- `thinkingLevel` —— 子代理思考强度:`off`、`minimal`、`low`、`medium`、`high`、`xhigh` 或 `max`(默认)。
|
|
92
|
+
- `proactiveInjection` —— 开关系统提示词注入。
|
|
93
|
+
- `agentScope` —— `"user"`(默认)、`"project"` 或 `"both"`。
|
|
94
|
+
|
|
95
|
+
**每个 agent 的模型优先级**:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
可用的 agentModels[name] → 当前 session 模型 → agent frontmatter 里的默认
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
如果配置的模型不再可用,会切换到主窗口当前模型,并在下一次运行前写回配置文件。
|
|
102
|
+
|
|
103
|
+
## 使用
|
|
104
|
+
|
|
105
|
+
主模型会自己调用 `subagent`,你也可以直接要求:
|
|
106
|
+
|
|
107
|
+
```text
|
|
108
|
+
# 单个
|
|
109
|
+
用 explore sub-agent 梳理一下认证是怎么接起来的。
|
|
110
|
+
|
|
111
|
+
# 并行(独立任务)
|
|
112
|
+
用并行 sub-agent 跑这两件:探索 API 层,以及探索 DB 层。
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
工具参数形态:
|
|
116
|
+
|
|
117
|
+
```jsonc
|
|
118
|
+
// 单个
|
|
119
|
+
{ "agent": "worker", "task": "<自包含的任务简报>" }
|
|
120
|
+
// 并行
|
|
121
|
+
{ "tasks": [ { "agent": "explore", "task": "..." }, { "agent": "explore", "task": "..." } ] }
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 实时状态与通知
|
|
125
|
+
|
|
126
|
+
子代理运行期间,编辑器上方的挂件为每个运行显示一行状态(图标、agent、模型、
|
|
127
|
+
token 用量、耗时),其下缩进一行显示它正在做什么:`thinking`、`writing`、
|
|
128
|
+
`read src/index.ts`、`bash npm test`……(不会是一坨 JSON 参数)。
|
|
129
|
+
|
|
130
|
+
运行结束(成功**或**失败)时,该行立即从挂件消失,主窗口收到一条通知,
|
|
131
|
+
给出最终摘要(`✓ worker · openai/gpt-5 · ↑12.4k ↓3.1k · 47s`)。工具结果
|
|
132
|
+
本身仍是对话里的持久记录。
|
|
133
|
+
|
|
134
|
+
子代理使用配置的思考强度(默认 `--thinking max`);pi 会按目标模型实际支持
|
|
135
|
+
的级别自适应降级(`max → xhigh → high → … → off`),弱模型也能平稳运行。
|
|
136
|
+
任务内容通过 stdin 传递,只有 agent system prompt 使用短生命周期临时文件。
|
|
137
|
+
子进程输出在内存中流式处理;中止或卡住时会通过 watchdog 清理整个进程树。
|
|
138
|
+
|
|
139
|
+
## 开发
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
npm install
|
|
143
|
+
npm run check # tsc --noEmit
|
|
144
|
+
npm test # vitest
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 相关项目
|
|
148
|
+
|
|
149
|
+
- [pi-querit-search](https://www.npmjs.com/package/pi-querit-search) —— 为 pi 提供实时网络搜索与网页抓取,同一作者。
|
|
150
|
+
|
|
151
|
+
## 许可证
|
|
152
|
+
|
|
153
|
+
MIT
|