@narumitw/pi-subagents 0.1.10 → 0.1.12
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 +132 -59
- package/package.json +11 -5
- package/src/agents.ts +1 -1
- package/src/subagents.ts +9 -5
package/README.md
CHANGED
|
@@ -1,90 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🧑🤝🧑 pi-subagents — Isolated Subagents for the Pi Coding Agent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@narumitw/pi-subagents) [](https://pi.dev) [](./LICENSE)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`@narumitw/pi-subagents` is a native [Pi coding agent](https://pi.dev) extension that adds a `subagent` tool for delegating work to specialized agents running in isolated Pi subprocesses.
|
|
6
|
+
|
|
7
|
+
Use it to split research, planning, implementation, and review work across focused workers while keeping each subprocess context, tools, and prompt boundary separate from the main conversation.
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- Registers a `subagent` tool for single-agent, parallel, fan-in, and chained delegation.
|
|
12
|
+
- Runs workers as isolated `pi --mode json -p --no-session` subprocesses.
|
|
13
|
+
- Supports built-in `scout`, `planner`, `reviewer`, and `worker` agents.
|
|
14
|
+
- Loads custom user agents from `~/.pi/agent/agents/*.md`.
|
|
15
|
+
- Optionally loads project agents from `.pi/agents/*.md` with confirmation.
|
|
16
|
+
- Supports per-task `cwd`, hard subprocess `timeoutMs`, abort propagation, and streaming progress.
|
|
17
|
+
- Returns complete worker output in tool details and a concise result for the main agent.
|
|
18
|
+
|
|
19
|
+
## 📦 Install
|
|
6
20
|
|
|
7
21
|
```bash
|
|
8
22
|
pi install npm:@narumitw/pi-subagents
|
|
9
23
|
```
|
|
10
24
|
|
|
11
|
-
Try
|
|
25
|
+
Try without installing permanently:
|
|
12
26
|
|
|
13
27
|
```bash
|
|
14
|
-
pi -e
|
|
28
|
+
pi -e npm:@narumitw/pi-subagents
|
|
15
29
|
```
|
|
16
30
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
A `subagent` tool with three execution modes:
|
|
20
|
-
|
|
21
|
-
- **single**: run one `{ agent, task }`
|
|
22
|
-
- **parallel**: run multiple `{ agent, task }` jobs with bounded concurrency
|
|
23
|
-
- **parallel + aggregator**: run parallel jobs, then fan their complete outputs into one follow-up agent
|
|
24
|
-
- **chain**: run sequential steps, passing prior output with `{previous}`
|
|
25
|
-
|
|
26
|
-
The design borrows from Pi/Claude-style subagents: each worker has its own system prompt, tool boundary, optional model, subprocess context window, streaming progress, abort propagation, hard subprocess timeout, complete final output in tool details, and summarized sidechain result.
|
|
27
|
-
|
|
28
|
-
## Built-in agents
|
|
31
|
+
Try this package locally from the repository root:
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
| --- | --- | --- |
|
|
34
|
-
| `scout` | Read-only codebase reconnaissance | `read`, `grep`, `find`, `ls`, `bash` |
|
|
35
|
-
| `planner` | Grounded implementation plans | `read`, `grep`, `find`, `ls` |
|
|
36
|
-
| `reviewer` | Independent review and verification | `read`, `grep`, `find`, `ls`, `bash` |
|
|
37
|
-
| `worker` | General-purpose implementation | Pi default tools |
|
|
38
|
-
| `general`, `general-purpose` | Aliases for `worker` | Pi default tools |
|
|
39
|
-
|
|
40
|
-
Built-in agents intentionally inherit the active/default Pi model instead of forcing a model alias; this keeps subprocesses usable across provider setups.
|
|
41
|
-
|
|
42
|
-
## Custom agents
|
|
43
|
-
|
|
44
|
-
Create markdown files in:
|
|
45
|
-
|
|
46
|
-
- `~/.pi/agent/agents/*.md` for user agents
|
|
47
|
-
- `.pi/agents/*.md` for project agents
|
|
33
|
+
```bash
|
|
34
|
+
pi -e ./extensions/pi-subagents
|
|
35
|
+
```
|
|
48
36
|
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
name: api-reviewer
|
|
52
|
-
description: Review API changes for compatibility and tests
|
|
53
|
-
tools: read, grep, find, ls, bash
|
|
54
|
-
model: sonnet
|
|
55
|
-
---
|
|
37
|
+
## 🛠️ Pi tool
|
|
56
38
|
|
|
57
|
-
|
|
58
|
-
test coverage, and migration risks. Report PASS/FAIL/PARTIAL with evidence.
|
|
59
|
-
```
|
|
39
|
+
`pi-subagents` registers one tool:
|
|
60
40
|
|
|
61
|
-
|
|
41
|
+
- `subagent` — delegate work to one or more specialized agents.
|
|
62
42
|
|
|
63
|
-
|
|
43
|
+
Execution modes:
|
|
64
44
|
|
|
65
|
-
|
|
45
|
+
- **single** — run one `{ agent, task }` job.
|
|
46
|
+
- **parallel** — run multiple `{ agent, task }` jobs independently.
|
|
47
|
+
- **parallel + aggregator** — run parallel jobs, then pass all outputs into one fan-in agent.
|
|
48
|
+
- **chain** — run sequential steps, passing prior output with `{previous}`.
|
|
66
49
|
|
|
67
|
-
##
|
|
50
|
+
## 🚀 Examples
|
|
68
51
|
|
|
69
|
-
|
|
52
|
+
Run one read-only reconnaissance agent:
|
|
70
53
|
|
|
71
54
|
```json
|
|
72
|
-
{
|
|
55
|
+
{
|
|
56
|
+
"agent": "scout",
|
|
57
|
+
"task": "Find the statusline extension entry points"
|
|
58
|
+
}
|
|
73
59
|
```
|
|
74
60
|
|
|
75
|
-
|
|
61
|
+
Run multiple agents in parallel:
|
|
76
62
|
|
|
77
63
|
```json
|
|
78
64
|
{
|
|
79
65
|
"tasks": [
|
|
80
|
-
{
|
|
81
|
-
|
|
66
|
+
{
|
|
67
|
+
"agent": "scout",
|
|
68
|
+
"task": "Map package metadata files",
|
|
69
|
+
"timeoutMs": 30000
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"agent": "reviewer",
|
|
73
|
+
"task": "Review TypeScript config consistency"
|
|
74
|
+
}
|
|
82
75
|
],
|
|
83
76
|
"timeoutMs": 120000
|
|
84
77
|
}
|
|
85
78
|
```
|
|
86
79
|
|
|
87
|
-
|
|
80
|
+
Run parallel workers, then aggregate their results:
|
|
88
81
|
|
|
89
82
|
```json
|
|
90
83
|
{
|
|
@@ -99,17 +92,97 @@ Parallel with fan-in aggregation:
|
|
|
99
92
|
}
|
|
100
93
|
```
|
|
101
94
|
|
|
102
|
-
|
|
95
|
+
Run a chain where each step receives the previous output:
|
|
103
96
|
|
|
104
97
|
```json
|
|
105
98
|
{
|
|
106
99
|
"chain": [
|
|
107
100
|
{ "agent": "scout", "task": "Find subagent-related code" },
|
|
108
|
-
{
|
|
101
|
+
{
|
|
102
|
+
"agent": "planner",
|
|
103
|
+
"task": "Using this context, plan the extension: {previous}"
|
|
104
|
+
}
|
|
109
105
|
]
|
|
110
106
|
}
|
|
111
107
|
```
|
|
112
108
|
|
|
113
|
-
##
|
|
109
|
+
## 🤖 Built-in agents
|
|
110
|
+
|
|
111
|
+
Built-in agents are available without setup and can be overridden by user or project agents with the same name.
|
|
112
|
+
|
|
113
|
+
| Agent | Purpose | Tools |
|
|
114
|
+
| --- | --- | --- |
|
|
115
|
+
| `scout` | Read-only codebase reconnaissance. | `read`, `grep`, `find`, `ls`, `bash` |
|
|
116
|
+
| `planner` | Grounded implementation plans. | `read`, `grep`, `find`, `ls` |
|
|
117
|
+
| `reviewer` | Independent review and verification. | `read`, `grep`, `find`, `ls`, `bash` |
|
|
118
|
+
| `worker` | General-purpose implementation. | Pi default tools |
|
|
119
|
+
| `general`, `general-purpose` | Aliases for `worker`. | Pi default tools |
|
|
120
|
+
|
|
121
|
+
Built-in agents inherit the active/default Pi model instead of forcing a provider-specific model alias, which keeps subprocesses usable across different Pi setups.
|
|
122
|
+
|
|
123
|
+
## 🧩 Custom agents
|
|
124
|
+
|
|
125
|
+
Create markdown agent definitions in either location:
|
|
126
|
+
|
|
127
|
+
- `~/.pi/agent/agents/*.md` for user agents.
|
|
128
|
+
- `.pi/agents/*.md` for project-local agents.
|
|
129
|
+
|
|
130
|
+
Example:
|
|
131
|
+
|
|
132
|
+
```markdown
|
|
133
|
+
---
|
|
134
|
+
name: api-reviewer
|
|
135
|
+
description: Review API changes for compatibility and tests
|
|
136
|
+
tools: read, grep, find, ls, bash
|
|
137
|
+
model: sonnet
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
You are an API review subagent. Do not edit files. Check compatibility,
|
|
141
|
+
test coverage, and migration risks. Report PASS/FAIL/PARTIAL with evidence.
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
By default, `subagent` loads user agents only. Set `agentScope` to `"project"` or `"both"` to load project-local agents. Interactive sessions ask for confirmation before using project agents unless `confirmProjectAgents` is disabled.
|
|
145
|
+
|
|
146
|
+
## ⏱️ Runtime limits
|
|
147
|
+
|
|
148
|
+
Each subprocess has a hard timeout to avoid runaway workers.
|
|
149
|
+
|
|
150
|
+
- Set `timeoutMs` on the top-level call to apply a default for all jobs.
|
|
151
|
+
- Set `timeoutMs` on a task, chain step, or aggregator to override it locally.
|
|
152
|
+
- If omitted, the default is `PI_SUBAGENT_TIMEOUT_MS`, or `600000` milliseconds (10 minutes) when unset.
|
|
153
|
+
|
|
154
|
+
On timeout, the extension sends `SIGTERM`, escalates to `SIGKILL` after a short grace period, and returns any partial messages or stderr collected so far.
|
|
155
|
+
|
|
156
|
+
## 🔒 Safety notes
|
|
157
|
+
|
|
158
|
+
Subagents are separate Pi processes and may use the tools allowed by their agent definition. Treat project-local agent prompts like executable project configuration: only enable them in trusted repositories.
|
|
159
|
+
|
|
160
|
+
## 🗂️ Package layout
|
|
161
|
+
|
|
162
|
+
```txt
|
|
163
|
+
extensions/pi-subagents/
|
|
164
|
+
├── src/
|
|
165
|
+
│ └── subagents.ts
|
|
166
|
+
├── README.md
|
|
167
|
+
├── LICENSE
|
|
168
|
+
├── tsconfig.json
|
|
169
|
+
└── package.json
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The package exposes its Pi extension through `package.json`:
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"pi": {
|
|
177
|
+
"extensions": ["./src/subagents.ts"]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## 🔎 Keywords
|
|
183
|
+
|
|
184
|
+
Pi extension, Pi coding agent, subagents, agent delegation, parallel agents, fan-in aggregation, chained agents, isolated subprocesses, AI coding workflow, TypeScript Pi package.
|
|
185
|
+
|
|
186
|
+
## 📄 License
|
|
114
187
|
|
|
115
|
-
|
|
188
|
+
MIT. See [`LICENSE`](./LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-subagents",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Pi extension for delegating work to specialized isolated subagents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,14 +29,20 @@
|
|
|
29
29
|
"typecheck": "tsc --noEmit"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@mariozechner/pi-agent-core": "0.73.0",
|
|
33
|
-
"@mariozechner/pi-ai": "0.73.0",
|
|
34
|
-
"@mariozechner/pi-coding-agent": "0.73.0",
|
|
35
|
-
"@mariozechner/pi-tui": "0.73.0",
|
|
36
32
|
"typebox": "^1.1.37"
|
|
37
33
|
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@earendil-works/pi-agent-core": "*",
|
|
36
|
+
"@earendil-works/pi-ai": "*",
|
|
37
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
38
|
+
"@earendil-works/pi-tui": "*"
|
|
39
|
+
},
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"@biomejs/biome": "2.4.14",
|
|
42
|
+
"@earendil-works/pi-agent-core": "0.74.0",
|
|
43
|
+
"@earendil-works/pi-ai": "0.74.0",
|
|
44
|
+
"@earendil-works/pi-coding-agent": "0.74.0",
|
|
45
|
+
"@earendil-works/pi-tui": "0.74.0",
|
|
40
46
|
"typescript": "6.0.3"
|
|
41
47
|
},
|
|
42
48
|
"repository": {
|
package/src/agents.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
6
|
import * as path from "node:path";
|
|
7
|
-
import { getAgentDir, parseFrontmatter } from "@
|
|
7
|
+
import { getAgentDir, parseFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
|
|
9
9
|
export type AgentScope = "user" | "project" | "both";
|
|
10
10
|
|
package/src/subagents.ts
CHANGED
|
@@ -16,11 +16,15 @@ import { spawn } from "node:child_process";
|
|
|
16
16
|
import * as fs from "node:fs";
|
|
17
17
|
import * as os from "node:os";
|
|
18
18
|
import * as path from "node:path";
|
|
19
|
-
import type { AgentToolResult } from "@
|
|
20
|
-
import type { Message } from "@
|
|
21
|
-
import { StringEnum } from "@
|
|
22
|
-
import {
|
|
23
|
-
|
|
19
|
+
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
20
|
+
import type { Message } from "@earendil-works/pi-ai";
|
|
21
|
+
import { StringEnum } from "@earendil-works/pi-ai";
|
|
22
|
+
import {
|
|
23
|
+
type ExtensionAPI,
|
|
24
|
+
getMarkdownTheme,
|
|
25
|
+
withFileMutationQueue,
|
|
26
|
+
} from "@earendil-works/pi-coding-agent";
|
|
27
|
+
import { Container, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
|
|
24
28
|
import { Type } from "typebox";
|
|
25
29
|
import { type AgentConfig, type AgentScope, type AgentSource, discoverAgents } from "./agents.js";
|
|
26
30
|
|