@clanker-code/pi-subagents 0.10.5
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/.plans/PLAN-next-changes.md +183 -0
- package/.plans/README.md +14 -0
- package/AGENTS.md +31 -0
- package/CHANGELOG.md +583 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +21 -0
- package/README.md +630 -0
- package/RELEASE.md +39 -0
- package/dist/abort-resend.d.ts +35 -0
- package/dist/abort-resend.js +71 -0
- package/dist/agent-details.d.ts +17 -0
- package/dist/agent-details.js +22 -0
- package/dist/agent-manager.d.ts +132 -0
- package/dist/agent-manager.js +493 -0
- package/dist/agent-runner.d.ts +165 -0
- package/dist/agent-runner.js +732 -0
- package/dist/agent-tool-description.d.ts +9 -0
- package/dist/agent-tool-description.js +147 -0
- package/dist/agent-types.d.ts +60 -0
- package/dist/agent-types.js +157 -0
- package/dist/context.d.ts +12 -0
- package/dist/context.js +56 -0
- package/dist/cross-extension-rpc.d.ts +46 -0
- package/dist/cross-extension-rpc.js +76 -0
- package/dist/custom-agents.d.ts +14 -0
- package/dist/custom-agents.js +149 -0
- package/dist/default-agents.d.ts +7 -0
- package/dist/default-agents.js +119 -0
- package/dist/enabled-models.d.ts +49 -0
- package/dist/enabled-models.js +145 -0
- package/dist/env.d.ts +6 -0
- package/dist/env.js +28 -0
- package/dist/group-join.d.ts +32 -0
- package/dist/group-join.js +116 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +1918 -0
- package/dist/invocation-config.d.ts +25 -0
- package/dist/invocation-config.js +19 -0
- package/dist/memory.d.ts +49 -0
- package/dist/memory.js +151 -0
- package/dist/model-resolver.d.ts +19 -0
- package/dist/model-resolver.js +62 -0
- package/dist/notifications.d.ts +6 -0
- package/dist/notifications.js +107 -0
- package/dist/output-file.d.ts +24 -0
- package/dist/output-file.js +86 -0
- package/dist/peek.d.ts +37 -0
- package/dist/peek.js +121 -0
- package/dist/prompts.d.ts +40 -0
- package/dist/prompts.js +95 -0
- package/dist/schedule-store.d.ts +38 -0
- package/dist/schedule-store.js +155 -0
- package/dist/schedule.d.ts +109 -0
- package/dist/schedule.js +338 -0
- package/dist/settings.d.ts +135 -0
- package/dist/settings.js +168 -0
- package/dist/skill-loader.d.ts +24 -0
- package/dist/skill-loader.js +93 -0
- package/dist/status-note.d.ts +13 -0
- package/dist/status-note.js +24 -0
- package/dist/types.d.ts +184 -0
- package/dist/types.js +7 -0
- package/dist/ui/agent-tool-rendering.d.ts +34 -0
- package/dist/ui/agent-tool-rendering.js +154 -0
- package/dist/ui/agent-widget-tree.d.ts +33 -0
- package/dist/ui/agent-widget-tree.js +130 -0
- package/dist/ui/agent-widget.d.ts +156 -0
- package/dist/ui/agent-widget.js +408 -0
- package/dist/ui/conversation-viewer.d.ts +47 -0
- package/dist/ui/conversation-viewer.js +290 -0
- package/dist/ui/menu-select.d.ts +20 -0
- package/dist/ui/menu-select.js +46 -0
- package/dist/ui/schedule-menu.d.ts +16 -0
- package/dist/ui/schedule-menu.js +99 -0
- package/dist/ui/viewer-keys.d.ts +20 -0
- package/dist/ui/viewer-keys.js +17 -0
- package/dist/usage.d.ts +50 -0
- package/dist/usage.js +49 -0
- package/dist/wait.d.ts +10 -0
- package/dist/wait.js +37 -0
- package/dist/worktree.d.ts +45 -0
- package/dist/worktree.js +160 -0
- package/docs/design/default-extension-tool-exposure.md +56 -0
- package/docs/superpowers/plans/2026-06-19-recursive-subagent-widget.md +600 -0
- package/docs/superpowers/specs/2026-06-19-recursive-subagent-widget-design.md +189 -0
- package/examples/agent-tool-description.md +45 -0
- package/package.json +56 -0
- package/reviews/proposal-structured-output-schema.md +135 -0
- package/reviews/recursive-subagent-widget-preview-rev2.png +0 -0
- package/reviews/recursive-subagent-widget-preview.html +137 -0
- package/reviews/recursive-subagent-widget-preview.png +0 -0
- package/reviews/subagent-features-comparison.md +350 -0
- package/src/abort-resend.ts +75 -0
- package/src/agent-details.ts +31 -0
- package/src/agent-manager.ts +596 -0
- package/src/agent-runner.ts +872 -0
- package/src/agent-tool-description.ts +163 -0
- package/src/agent-types.ts +189 -0
- package/src/context.ts +58 -0
- package/src/cross-extension-rpc.ts +122 -0
- package/src/custom-agents.ts +160 -0
- package/src/default-agents.ts +123 -0
- package/src/enabled-models.ts +180 -0
- package/src/env.ts +33 -0
- package/src/group-join.ts +141 -0
- package/src/index.ts +2115 -0
- package/src/invocation-config.ts +42 -0
- package/src/memory.ts +165 -0
- package/src/model-resolver.ts +81 -0
- package/src/notifications.ts +120 -0
- package/src/output-file.ts +96 -0
- package/src/peek.ts +155 -0
- package/src/prompts.ts +129 -0
- package/src/schedule-store.ts +153 -0
- package/src/schedule.ts +365 -0
- package/src/settings.ts +289 -0
- package/src/skill-loader.ts +102 -0
- package/src/status-note.ts +25 -0
- package/src/types.ts +195 -0
- package/src/ui/agent-tool-rendering.ts +175 -0
- package/src/ui/agent-widget-tree.ts +169 -0
- package/src/ui/agent-widget.ts +497 -0
- package/src/ui/conversation-viewer.ts +297 -0
- package/src/ui/menu-select.ts +68 -0
- package/src/ui/schedule-menu.ts +105 -0
- package/src/ui/viewer-keys.ts +39 -0
- package/src/usage.ts +60 -0
- package/src/wait.ts +44 -0
- package/src/worktree.ts +191 -0
- package/vitest.config.ts +25 -0
package/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tintinweb
|
|
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.md
ADDED
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
# @clanker-code/pi-subagents
|
|
2
|
+
|
|
3
|
+
A [pi](https://pi.dev) extension that brings **Claude Code-style autonomous sub-agents** to pi. Spawn specialized agents that run in isolated background sessions — each with its own tools, system prompt, model, and thinking level. Steer them mid-run, resume completed sessions, and define your own custom agent types.
|
|
4
|
+
|
|
5
|
+
This package is a fork of [`@tintinweb/pi-subagents`](https://github.com/tintinweb/pi-subagents).
|
|
6
|
+
|
|
7
|
+
> **Status:** Early release.
|
|
8
|
+
|
|
9
|
+
<img width="600" alt="pi-subagents screenshot" src="https://github.com/clankercode/pi-subagents/raw/master/media/screenshot.png" />
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
https://github.com/user-attachments/assets/8685261b-9338-4fea-8dfe-1c590d5df543
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## About This Fork
|
|
16
|
+
|
|
17
|
+
`@clanker-code/pi-subagents` is a pseudo-fork of the upstream [`tintinweb/pi-subagents`](https://github.com/tintinweb/pi-subagents) project. It keeps the same core toolset but may diverge in features, defaults, and packaging.
|
|
18
|
+
|
|
19
|
+
### Fork-specific differences
|
|
20
|
+
|
|
21
|
+
- **Packaging under `@clanker-code`** — published from this fork, not the upstream namespace.
|
|
22
|
+
- **Completion notifications include full-output guidance** — every notification carries final output preview plus an explicit `get_subagent_result <id>` instruction and transcript path, so the parent can retrieve the full log directly from the notification.
|
|
23
|
+
- Additional fork-specific changes are listed in the [CHANGELOG](./CHANGELOG.md).
|
|
24
|
+
|
|
25
|
+
Upstream changes are reviewed for cherry-picking when practical; otherwise they are reimplemented to fit this fork.
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- **Claude Code look & feel** — same tool names, calling conventions, and UI patterns (`Agent`, `get_subagent_result`, `steer_subagent`) — feels native
|
|
30
|
+
- **Parallel background agents** — spawn multiple agents that run concurrently with automatic queuing (configurable concurrency limit, default 4). Each agent notifies individually on completion (async join; configurable to smart/group for consolidated notifications)
|
|
31
|
+
- **Live widget UI** — persistent above-editor widget with animated spinners, live tool activity, token counts, and colored status icons
|
|
32
|
+
- **Conversation viewer** — select any agent in `/agents` to open a live-scrolling overlay of its full conversation (auto-follows new content, scroll up to pause). Stop a still-running agent from here by pressing `x` (then `x` again to confirm) — works for background agents too
|
|
33
|
+
- **Custom agent types** — define agents in `.pi/agents/<name>.md` with YAML frontmatter: custom system prompts, model selection, thinking levels, tool restrictions
|
|
34
|
+
- **Mid-run steering** — inject messages into running agents to redirect their work without restarting
|
|
35
|
+
- **Session resume** — pick up where an agent left off, preserving full conversation context
|
|
36
|
+
- **Graceful turn limits** — agents get a "wrap up" warning before hard abort, producing clean partial results instead of cut-off output
|
|
37
|
+
- **Case-insensitive agent types** — `"explore"`, `"Explore"`, `"EXPLORE"` all work. Unknown types fall back to general-purpose with a note
|
|
38
|
+
- **Fuzzy model selection** — specify models by name (`"haiku"`, `"sonnet"`) instead of full IDs, with automatic filtering to only available/configured models
|
|
39
|
+
- **Context inheritance** — optionally fork the parent conversation into a sub-agent so it knows what's been discussed
|
|
40
|
+
- **Persistent agent memory** — three scopes (project, local, user) with automatic read-only fallback for agents without write tools
|
|
41
|
+
- **Git worktree isolation** — run agents in isolated repo copies; changes auto-committed to branches on completion
|
|
42
|
+
- **Skill preloading** — inject named skills into agent system prompts, discovered from `.pi/skills/`, `.agents/skills/`, and global locations (Pi-standard `<name>/SKILL.md` directory layout supported)
|
|
43
|
+
- **Tool denylist** — block specific tools via `disallowed_tools` frontmatter
|
|
44
|
+
- **Styled completion notifications** — background agent results render as themed, compact notification boxes (icon, stats, result preview) instead of raw XML. Expandable to show full output. Group completions render each agent individually
|
|
45
|
+
- **Event bus** — lifecycle events (`subagents:created`, `started`, `completed`, `failed`, `steered`, `compacted`) emitted via `pi.events`, enabling other extensions to react to sub-agent activity
|
|
46
|
+
- **Cross-extension RPC** — other pi extensions can spawn and stop subagents via the `pi.events` event bus (`subagents:rpc:ping`, `subagents:rpc:spawn`, `subagents:rpc:stop`). Standardized reply envelopes with protocol versioning. Emits `subagents:ready` on load
|
|
47
|
+
- **Schedule subagents** — pass `schedule` to the `Agent` tool to fire on cron / interval / one-shot. Session-scoped jobs with PID-locked persistence; results land via the same steering-style `subagent-notification` path as manual background completions; manage via `/agents → Scheduled jobs`
|
|
48
|
+
- **Model scope enforcement** — opt-in validation that subagent model choices stay within your pi `enabledModels` allowlist (sourced from `/scoped-models`, with both global and project-local pi settings honored). Caller-supplied out-of-scope → hard error to orchestrator; frontmatter-pinned out-of-scope → warning + runs anyway (frontmatter authoritative). Toggle via `/agents → Settings → Scope models`
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pi install npm:@clanker-code/pi-subagents
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Or load directly for development:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pi -e ./src/index.ts
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
The parent agent spawns sub-agents using the `Agent` tool:
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
Agent({
|
|
68
|
+
subagent_type: "Explore",
|
|
69
|
+
prompt: "Find all files that handle authentication",
|
|
70
|
+
description: "Find auth files",
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Agent calls always run in the background. The tool returns an ID immediately, and the parent agent receives an automatic completion notification when the subagent finishes.
|
|
75
|
+
|
|
76
|
+
### Scheduling
|
|
77
|
+
|
|
78
|
+
Add a `schedule` field to register the agent to fire later instead of running now:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
Agent({
|
|
82
|
+
subagent_type: "Explore",
|
|
83
|
+
prompt: "Look at recent commits and summarize what changed since last week",
|
|
84
|
+
description: "Weekly commit review",
|
|
85
|
+
schedule: "0 0 9 * * 1", // 9am every Monday (6-field cron)
|
|
86
|
+
})
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Schedule formats:
|
|
90
|
+
|
|
91
|
+
- **Cron** — 6-field (`second minute hour day-of-month month day-of-week`), e.g. `"0 0 9 * * 1"` for 9am every Monday, `"0 */15 * * * *"` for every 15 minutes.
|
|
92
|
+
- **Interval** — `"5m"`, `"1h"`, `"30s"`, `"2d"`. Fires repeatedly at that interval.
|
|
93
|
+
- **One-shot relative** — `"+10m"`, `"+2h"`, `"+1d"`. Fires once at that future time.
|
|
94
|
+
- **One-shot absolute** — full ISO timestamp, e.g. `"2026-12-25T09:00:00.000Z"`.
|
|
95
|
+
|
|
96
|
+
When a schedule fires, the spawn runs in background and its completion notification arrives in the conversation through the same steering-style `subagent-notification` path as a manually-spawned background agent — your parent agent reasons about the result the same way.
|
|
97
|
+
|
|
98
|
+
Schedules are **session-scoped**: they reset on `/new` and restore on `/resume`. List and cancel via `/agents → Scheduled jobs` (creation is the `Agent` tool's job — there is no parallel manual-create wizard). Storage at `<cwd>/.pi/subagent-schedules/<sessionId>.json` with PID-based file locking for cross-instance safety.
|
|
99
|
+
|
|
100
|
+
**Disable the feature entirely**: `/agents → Settings → Scheduling → disabled` removes `schedule` from the `Agent` tool spec (no LLM-context cost), hides the menu entry, and stops any active scheduler. The schema-level removal takes effect on the next pi session; the runtime kill is immediate. Re-enable from the same menu.
|
|
101
|
+
|
|
102
|
+
Restrictions:
|
|
103
|
+
- `schedule` cannot be combined with `inherit_context` (no parent conversation exists at fire time) or `resume` (schedules create fresh agents).
|
|
104
|
+
- Scheduled fires use the same always-background spawn path as manual `Agent` calls.
|
|
105
|
+
- Scheduled fires bypass the `maxConcurrent` queue so a 5-minute interval cannot be deferred behind long-running manual agents.
|
|
106
|
+
- **Headless `pi -p` doesn't wait for scheduled subagents.**
|
|
107
|
+
|
|
108
|
+
## UI
|
|
109
|
+
|
|
110
|
+
The extension renders a persistent widget above the editor showing all active agents:
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
● Agents
|
|
114
|
+
├─ ⠹ Agent Refactor auth module · ↻5≤30 · 5 tool uses · 33.8k token (62%) · 12.3s
|
|
115
|
+
│ ⎿ editing 2 files…
|
|
116
|
+
├─ ⠹ Explore Find auth files · ↻3 · 3 tool uses · 12.4k token (8%) · 4.1s
|
|
117
|
+
│ ⎿ searching…
|
|
118
|
+
├─ ⠹ Agent Long-running task · ↻42 · 38 tool uses · 91.0k token (84% · ⇊2) · 2m17s
|
|
119
|
+
│ ⎿ reading…
|
|
120
|
+
└─ 2 queued
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The token field is annotated with two optional signals inside parens:
|
|
124
|
+
- **`NN%`** — context-window utilization (color-coded: <70% dim, 70–85% warning, ≥85% error). Omitted when the model has no declared `contextWindow`, or briefly right after compaction.
|
|
125
|
+
- **`⇊N`** — number of times the session has compacted, when > 0. Stays dim; the percent's color carries urgency.
|
|
126
|
+
|
|
127
|
+
Individual agent results render Claude Code-style in the conversation:
|
|
128
|
+
|
|
129
|
+
| State | Example |
|
|
130
|
+
|-------|---------|
|
|
131
|
+
| **Running** | `⠹ ↻3≤30 · 3 tool uses · 12.4k token (8%)` / `⎿ searching, reading 3 files…` |
|
|
132
|
+
| **Completed** | `✓ ↻8 · 5 tool uses · 33.8k token (62%) · 12.3s` / `⎿ Done` |
|
|
133
|
+
| **Wrapped up** | `✓ ↻50≤50 · 50 tool uses · 89.1k token (84% · ⇊2) · 45.2s` / `⎿ Wrapped up (turn limit)` |
|
|
134
|
+
| **Stopped** | `■ ↻3 · 3 tool uses · 12.4k token (8%)` / `⎿ Stopped` |
|
|
135
|
+
| **Error** | `✗ ↻3 · 3 tool uses · 12.4k token (8%)` / `⎿ Error: timeout` |
|
|
136
|
+
| **Aborted** | `✗ ↻55≤50 · 55 tool uses · 102.3k token (95% · ⇊3)` / `⎿ Aborted (max turns exceeded)` |
|
|
137
|
+
|
|
138
|
+
Completed results can be expanded (ctrl+o in pi) to show the full agent output inline.
|
|
139
|
+
|
|
140
|
+
Background agent completion notifications render as styled boxes:
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
✓ Find auth files completed
|
|
144
|
+
↻3 · 3 tool uses · 12.4k token · 4.1s
|
|
145
|
+
⎿ Found 5 files related to authentication...
|
|
146
|
+
transcript: .pi/output/agent-abc123.jsonl
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Group completions render each agent as a separate block. The LLM receives structured `<task-notification>` XML for parsing, while the user sees the themed visual.
|
|
150
|
+
|
|
151
|
+
## Default Agent Types
|
|
152
|
+
|
|
153
|
+
| Type | Tools | Model | Prompt Mode | Description |
|
|
154
|
+
|------|-------|-------|-------------|-------------|
|
|
155
|
+
| `general-purpose` | all 7 | inherit | `append` (parent twin) | Inherits the parent's full system prompt — same rules, CLAUDE.md, project conventions |
|
|
156
|
+
| `Explore` | read, bash, grep, find, ls | haiku (falls back to inherit) | `replace` (standalone) | Fast codebase exploration (read-only) |
|
|
157
|
+
| `Plan` | read, bash, grep, find, ls | inherit | `replace` (standalone) | Software architect for implementation planning (read-only) |
|
|
158
|
+
|
|
159
|
+
The `general-purpose` agent is a **parent twin** — it receives the parent's entire system prompt plus a sub-agent context bridge, so it follows the same rules the parent does. Explore and Plan use standalone prompts tailored to their read-only roles.
|
|
160
|
+
|
|
161
|
+
Default agents can be **ejected** (`/agents` → select agent → Eject) to export them as `.md` files for customization, **overridden** by creating a `.md` file with the same name (e.g. `.pi/agents/general-purpose.md`), or **disabled** per-project with `enabled: false` frontmatter.
|
|
162
|
+
|
|
163
|
+
## Custom Agents
|
|
164
|
+
|
|
165
|
+
Define custom agent types by creating `.md` files. The filename becomes the agent type name. Any name is allowed — using a default agent's name overrides it.
|
|
166
|
+
|
|
167
|
+
Agents are discovered from two locations (higher priority wins):
|
|
168
|
+
|
|
169
|
+
| Priority | Location | Scope |
|
|
170
|
+
|----------|----------|-------|
|
|
171
|
+
| 1 (highest) | `.pi/agents/<name>.md` | Project — per-repo agents |
|
|
172
|
+
| 2 | `$PI_CODING_AGENT_DIR/agents/<name>.md` (default `~/.pi/agent/agents/<name>.md`) | Global — available everywhere |
|
|
173
|
+
|
|
174
|
+
Project-level agents override global ones with the same name, so you can customize a global agent for a specific project. The global location follows the upstream `PI_CODING_AGENT_DIR` env var — set it to relocate all pi-coding-agent state (agents, skills, settings) to a custom directory.
|
|
175
|
+
|
|
176
|
+
### Example: `.pi/agents/auditor.md`
|
|
177
|
+
|
|
178
|
+
```markdown
|
|
179
|
+
---
|
|
180
|
+
description: Security Code Reviewer
|
|
181
|
+
tools: read, grep, find, bash
|
|
182
|
+
model: anthropic/claude-opus-4-6
|
|
183
|
+
thinking: high
|
|
184
|
+
max_turns: 30
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
You are a security auditor. Review code for vulnerabilities including:
|
|
188
|
+
- Injection flaws (SQL, command, XSS)
|
|
189
|
+
- Authentication and authorization issues
|
|
190
|
+
- Sensitive data exposure
|
|
191
|
+
- Insecure configurations
|
|
192
|
+
|
|
193
|
+
Report findings with file paths, line numbers, severity, and remediation advice.
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Then spawn it like any built-in type:
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
Agent({ subagent_type: "auditor", prompt: "Review the auth module", description: "Security audit" })
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Frontmatter Fields
|
|
203
|
+
|
|
204
|
+
All fields are optional — sensible defaults for everything.
|
|
205
|
+
|
|
206
|
+
| Field | Default | Description |
|
|
207
|
+
|-------|---------|-------------|
|
|
208
|
+
| `description` | filename | Agent description shown in tool listings |
|
|
209
|
+
| `display_name` | — | Display name for UI (e.g. widget, agent list) |
|
|
210
|
+
| `tools` | all 7 | Which tools the agent can call. Built-in names (`read, grep, …`), `*` / `all` (all built-ins), `none`, and `ext:<extension>` / `ext:<extension>/<tool>` selectors for extension tools. See [Tool & extension scoping](#tool--extension-scoping) below |
|
|
211
|
+
| `extensions` | `true` | Which extensions to load for the agent. `true` (all defaults), `false` (none), or an explicit list: `[mcp, "/abs/path.ts", "*"]`. See [Tool & extension scoping](#tool--extension-scoping) below |
|
|
212
|
+
| `exclude_extensions` | — | Extension denylist applied after `extensions:` — exclude wins. Plain names only (case-insensitive), no paths or `*`. Useful with `extensions: true` to drop one extension (e.g. `pi-notify`) |
|
|
213
|
+
| `skills` | `true` | Inherit skills from parent. Can be a comma-separated list of skill names to preload (see [Skill Preloading](#skill-preloading) for discovery locations) |
|
|
214
|
+
| `memory` | — | Persistent agent memory scope: `project`, `local`, or `user`. Auto-detects read-only agents |
|
|
215
|
+
| `disallowed_tools` | — | Comma-separated tools to deny even if extensions provide them |
|
|
216
|
+
| `isolation` | — | Set to `worktree` to run in an isolated git worktree |
|
|
217
|
+
| `model` | inherit parent | Model — `provider/modelId` or fuzzy name (`"haiku"`, `"sonnet"`) |
|
|
218
|
+
| `thinking` | inherit | off, minimal, low, medium, high, xhigh |
|
|
219
|
+
| `max_turns` | unlimited | Max agentic turns before graceful shutdown. `0` or omit for unlimited |
|
|
220
|
+
| `prompt_mode` | `replace` | `replace`: body is the full system prompt (no AGENTS.md / CLAUDE.md inheritance). `append`: body appended to parent's prompt (agent acts as a "parent twin" — inherits parent's AGENTS.md / CLAUDE.md) |
|
|
221
|
+
| `inherit_context` | `false` | Fork parent conversation into agent |
|
|
222
|
+
| `isolated` | `false` | Hermetic specialist mode: forces `extensions: false` + `skills: false` + drops `ext:` selectors. Only built-in tools. Distinct from `isolation: worktree` (filesystem) |
|
|
223
|
+
| `enabled` | `true` | Set to `false` to disable an agent (useful for hiding a default agent per-project) |
|
|
224
|
+
|
|
225
|
+
Frontmatter is authoritative. If an agent file sets `model`, `thinking`, `max_turns`, `inherit_context`, `isolated`, or `isolation`, those values are locked for that agent. `Agent` tool parameters only fill fields the agent config leaves unspecified.
|
|
226
|
+
|
|
227
|
+
### Tool & extension scoping
|
|
228
|
+
|
|
229
|
+
`extensions:` decides **which extensions load**, `tools:` decides **which tools surface to the LLM**. They compose:
|
|
230
|
+
|
|
231
|
+
```yaml
|
|
232
|
+
# Default (both omitted): all extensions load, all 7 built-ins surface
|
|
233
|
+
|
|
234
|
+
tools: read, grep, find # narrow to listed built-ins; extensions still load
|
|
235
|
+
tools: "*" # all 7 built-ins (alias: `all`)
|
|
236
|
+
tools: none # zero built-ins (alias: `""`)
|
|
237
|
+
tools: "*, ext:mcp/search" # built-ins plus one extension tool
|
|
238
|
+
|
|
239
|
+
extensions: false # no extensions load
|
|
240
|
+
extensions: [mcp] # only mcp loads
|
|
241
|
+
extensions: ["*", "/abs/foo.ts"] # all defaults plus one path-loaded extension
|
|
242
|
+
|
|
243
|
+
exclude_extensions: pi-notify # everything except pi-notify (with extensions: true)
|
|
244
|
+
|
|
245
|
+
# Specialist: load one extension, expose only one of its tools, keep built-ins
|
|
246
|
+
extensions: [mcp]
|
|
247
|
+
tools: "*, ext:mcp/search"
|
|
248
|
+
|
|
249
|
+
isolated: true # hermetic: built-ins only, no extensions/skills/context
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
A few rules the examples don't make obvious:
|
|
253
|
+
|
|
254
|
+
- `extensions:` is the sole loading authority. `ext:foo` in `tools:` narrows what surfaces; it can't load `foo` on its own. Mismatches fire `extension-error:…` warnings.
|
|
255
|
+
- Any `ext:` entry flips extension tools to an explicit allowlist — unnamed extensions still load (handlers fire) but expose no tools. So `tools: "*, ext:mcp/search"` exposes only `search` from `mcp`, nothing from any other extension.
|
|
256
|
+
- `pi-c2c` is the one built-in exception to that opt-in flip: when it is loaded for a non-isolated subagent, all of its tools surface automatically so the child can register and message its parent without `tools: ext:pi-c2c`. `isolated: true`, `extensions: false`, `exclude_extensions: pi-c2c`, and `disallowed_tools` still suppress it.
|
|
257
|
+
- Extension names match case-insensitively (`[Mcp]` = `[mcp]`); tool names in `ext:foo/bar` stay case-sensitive.
|
|
258
|
+
- Plain `tools:` typos fail loudly: `tools: reed, grep` fires `tools-error:…` instead of silently producing an under-tooled agent.
|
|
259
|
+
- `exclude_extensions:` wins over `extensions:` and over `ext:` selectors — an excluded extension never loads and a `tools: ext:` entry can't pull it back. Plain names only (no paths, no `*`); a name matching nothing fires an `extension-error:…` warning.
|
|
260
|
+
- `exclude_extensions:` is **not a sandbox**: excluded extensions' factory code still executes once during loading — exclusion suppresses their handlers and tools, not their load-time side effects. Don't rely on it to contain an untrusted extension.
|
|
261
|
+
- Array and string forms are equivalent: `[a, b]` == `"a, b"`.
|
|
262
|
+
|
|
263
|
+
## Tools
|
|
264
|
+
|
|
265
|
+
### `Agent`
|
|
266
|
+
|
|
267
|
+
Launch a sub-agent.
|
|
268
|
+
|
|
269
|
+
| Parameter | Type | Required | Description |
|
|
270
|
+
|-----------|------|----------|-------------|
|
|
271
|
+
| `prompt` | string | yes | The task for the agent |
|
|
272
|
+
| `description` | string | yes | Short 3-5 word summary (shown in UI) |
|
|
273
|
+
| `subagent_type` | string | yes | Agent type (built-in or custom) |
|
|
274
|
+
| `model` | string | no | Model — `provider/modelId` or fuzzy name (`"haiku"`, `"sonnet"`) |
|
|
275
|
+
| `thinking` | string | no | Thinking level: off, minimal, low, medium, high, xhigh |
|
|
276
|
+
| `max_turns` | number | no | Max agentic turns. Omit for unlimited (default) |
|
|
277
|
+
| `resume` | string | no | Agent ID to resume a previous session |
|
|
278
|
+
| `isolated` | boolean | no | No extension/MCP tools |
|
|
279
|
+
| `isolation` | `"worktree"` | no | Run in an isolated git worktree |
|
|
280
|
+
| `inherit_context` | boolean | no | Fork parent conversation into agent |
|
|
281
|
+
|
|
282
|
+
All `Agent` calls run in the background. Completion notifications are delivered automatically; use `get_subagent_result` only when you explicitly need to check status or fetch a full result.
|
|
283
|
+
|
|
284
|
+
### `get_subagent_result`
|
|
285
|
+
|
|
286
|
+
Check status and retrieve results from a background agent.
|
|
287
|
+
|
|
288
|
+
| Parameter | Type | Required | Description |
|
|
289
|
+
|-----------|------|----------|-------------|
|
|
290
|
+
| `agent_id` | string | yes | Agent ID to check |
|
|
291
|
+
| `wait` | boolean | no | Wait for completion |
|
|
292
|
+
| `verbose` | boolean | no | Include full conversation log |
|
|
293
|
+
|
|
294
|
+
### `steer_subagent`
|
|
295
|
+
|
|
296
|
+
Send a steering message to a running agent. The message interrupts after the current tool execution.
|
|
297
|
+
|
|
298
|
+
| Parameter | Type | Required | Description |
|
|
299
|
+
|-----------|------|----------|-------------|
|
|
300
|
+
| `agent_id` | string | yes | Agent ID to steer |
|
|
301
|
+
| `message` | string | yes | Message to inject into agent conversation |
|
|
302
|
+
|
|
303
|
+
## Commands
|
|
304
|
+
|
|
305
|
+
| Command | Description |
|
|
306
|
+
|---------|-------------|
|
|
307
|
+
| `/agents` | Interactive agent management menu |
|
|
308
|
+
|
|
309
|
+
The `/agents` command opens an interactive menu:
|
|
310
|
+
|
|
311
|
+
```
|
|
312
|
+
Running agents (2) — 1 running, 1 done ← only shown when agents exist
|
|
313
|
+
Agent types (6) ← unified list: defaults + custom
|
|
314
|
+
Create new agent ← manual wizard or AI-generated
|
|
315
|
+
Settings ← max concurrency, max turns, grace turns, join mode
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
- **Running agents** — select one to open its live conversation viewer. While it's still running, press `x` (then `x` again to confirm) to stop/abort it. A stopped agent reports its partial output flagged as incomplete, not as a completion.
|
|
319
|
+
- **Agent types** — unified list with source indicators: `•` (project), `◦` (global), `✕` (disabled). Select an agent to manage it:
|
|
320
|
+
- **Default agents** (no override): Eject (export as `.md`), Disable
|
|
321
|
+
- **Default agents** (ejected/overridden): Edit, Disable, Reset to default, Delete
|
|
322
|
+
- **Custom agents**: Edit, Disable, Delete
|
|
323
|
+
- **Disabled agents**: Enable, Edit, Delete
|
|
324
|
+
- **Eject** — writes the embedded default config as a `.md` file to project or personal location, so you can customize it
|
|
325
|
+
- **Disable/Enable** — toggle agent availability. Disabled agents stay visible in the list (marked `✕`) and can be re-enabled
|
|
326
|
+
- **Create new agent** — choose project/personal location, then manual wizard (step-by-step prompts for name, tools, model, thinking, system prompt) or AI-generated (describe what the agent should do and a sub-agent writes the `.md` file). Any name is allowed, including default agent names (overrides them)
|
|
327
|
+
- **Settings** — configure max concurrency, default max turns, grace turns, and join mode at runtime
|
|
328
|
+
|
|
329
|
+
## Keyboard Shortcuts
|
|
330
|
+
|
|
331
|
+
| Key | Action |
|
|
332
|
+
|---|---|
|
|
333
|
+
| **`F9`** | **Abort + resend** — aborts the current turn AND auto-sends any queued message(s) as the next turn (instead of `Esc`, which dumps the queue back into the editor for manual re-submit). Change the key under `/agents → Settings → Abort+resend key` (e.g. `f8`, `shift+escape`), or via the `PI_ABORT_RESEND_KEY` env var. Applies next session. |
|
|
334
|
+
|
|
335
|
+
## Graceful Max Turns
|
|
336
|
+
|
|
337
|
+
Instead of hard-aborting at the turn limit, agents get a graceful shutdown:
|
|
338
|
+
|
|
339
|
+
1. At `max_turns` — steering message: *"Wrap up immediately — provide your final answer now."*
|
|
340
|
+
2. Up to 5 grace turns to finish cleanly
|
|
341
|
+
3. Hard abort only after the grace period
|
|
342
|
+
|
|
343
|
+
| Status | Meaning | Icon |
|
|
344
|
+
|--------|---------|------|
|
|
345
|
+
| `completed` | Finished naturally | `✓` green |
|
|
346
|
+
| `steered` | Hit limit, wrapped up in time | `✓` yellow |
|
|
347
|
+
| `aborted` | Grace period exceeded | `✗` red |
|
|
348
|
+
| `stopped` | User-initiated abort | `■` dim |
|
|
349
|
+
|
|
350
|
+
## Concurrency
|
|
351
|
+
|
|
352
|
+
Background agents are subject to a configurable concurrency limit (default: 4). Excess agents are automatically queued and start as running agents complete. The widget shows queued agents as a collapsed count.
|
|
353
|
+
|
|
354
|
+
All manual `Agent` calls enter the background queue. Scheduled fires bypass the `maxConcurrent` queue so recurring jobs cannot be deferred behind long-running manual agents.
|
|
355
|
+
|
|
356
|
+
## Join Strategies
|
|
357
|
+
|
|
358
|
+
When background agents complete, they notify the main agent. The **join mode** controls how these notifications are delivered. It applies only to background agents.
|
|
359
|
+
|
|
360
|
+
| Mode | Behavior |
|
|
361
|
+
|------|----------|
|
|
362
|
+
| `smart` | 2+ background agents spawned in the same turn are auto-grouped into a single consolidated notification. Solo agents notify individually. |
|
|
363
|
+
| `async` (default) | Each agent sends its own notification on completion. Best when results need incremental processing — fits the all-background, peek/wait model. |
|
|
364
|
+
| `group` | Force grouping even when spawning a single agent. Useful when you know more agents will follow. |
|
|
365
|
+
|
|
366
|
+
**Timeout behavior:** When agents are grouped, a 30-second timeout starts after the first agent completes. If not all agents finish in time, a partial notification is sent with completed results and remaining agents continue with a shorter 15-second re-batch window for stragglers.
|
|
367
|
+
|
|
368
|
+
**Configuration:**
|
|
369
|
+
- Configure join mode in `/agents` → Settings → Join mode
|
|
370
|
+
|
|
371
|
+
## Model Scope
|
|
372
|
+
|
|
373
|
+
**Opt-in:** off by default. Enable via `/agents → Settings → Scope models`.
|
|
374
|
+
|
|
375
|
+
When on, each subagent spawn's effective model is validated against pi's own `enabledModels` list (configured via pi's `/scoped-models` UI). pi-subagents reads that list; it doesn't manage it. Both of pi's settings files are honored: global `~/.pi/agent/settings.json` and project-local `<cwd>/.pi/settings.json`. **Project overrides global** — mirrors pi's `SettingsManager` deep-merge, so a tighter per-project scope (hand-edited into the project settings) is respected.
|
|
376
|
+
|
|
377
|
+
**Out-of-scope handling depends on source:**
|
|
378
|
+
|
|
379
|
+
| Model source | Out-of-scope behavior |
|
|
380
|
+
|---|---|
|
|
381
|
+
| Caller-supplied via `Agent({ model: "..." })` | Hard error returned to the orchestrator, listing allowed models |
|
|
382
|
+
| Pinned in agent frontmatter | Warning toast + the pinned model runs (frontmatter is authoritative) |
|
|
383
|
+
| Parent-inherited (neither set) | Warning toast + parent's model runs |
|
|
384
|
+
|
|
385
|
+
**Design:** `scopeModels` is a guardrail against the orchestrator picking unexpected models at runtime, not a hard policy against user-level config. The "frontmatter is authoritative" guarantee from v0.5.1 still holds for `model:` — caller params can't override frontmatter, and frontmatter pins run even when out of scope (with a visible warning).
|
|
386
|
+
|
|
387
|
+
**Pattern format:** only exact `provider/modelId` entries are honored (e.g. `anthropic/claude-haiku-4-5-20251001`). Glob patterns (`*sonnet*`), bare model IDs, and `:thinking` suffixes — which pi itself supports — are silently dropped here. pi's `/scoped-models` picker writes exact entries, so the limitation is invisible if you configure scope through the UI. Hand-edited globs produce an empty allowed set (scope check becomes a no-op).
|
|
388
|
+
|
|
389
|
+
**No-op safety:** if `enabledModels` is missing or empty in pi's settings, scope check skips entirely — no false positives, no spurious errors.
|
|
390
|
+
|
|
391
|
+
## Persistent Settings
|
|
392
|
+
|
|
393
|
+
Runtime tuning values set via `/agents` → Settings (max concurrency, default max turns, grace turns, default join mode, scheduling on/off, scope models on/off, disable defaults on/off, tool description full/compact/custom) persist across pi restarts. Two files, merged on load:
|
|
394
|
+
|
|
395
|
+
- **Global:** `~/.pi/agent/subagents.json` — your machine-wide defaults. Edit by hand; the `/agents` menu never writes here.
|
|
396
|
+
- **Project:** `<cwd>/.pi/subagents.json` — per-project overrides. Written by `/agents` → Settings.
|
|
397
|
+
|
|
398
|
+
**Precedence:** project overrides global on any field present in both. Missing fields fall back to the hardcoded defaults (max concurrency `4`, default max turns unlimited, grace turns `5`, join mode `async`, defaults enabled).
|
|
399
|
+
|
|
400
|
+
**Disable defaults** (`disableDefaultAgents`, default `false`): when on, the three built-in agents (general-purpose, Explore, Plan) are not registered — only your `.pi/agents/*.md` agents are advertised and spawnable. User-defined agents are unaffected, including ones that override a default by name. The Agent tool's type list updates on the next pi session (the tool schema is registered at startup).
|
|
401
|
+
|
|
402
|
+
**Tool description** (`toolDescriptionMode`, default `"full"`): which Agent tool description the LLM sees. `"full"` is the rich Claude Code-style prompt (~1,400 tokens with the default agents); `"compact"` is ~75% smaller — one-line agent type list, terse usage notes — for small/local models where tool-spec tokens are expensive. Per-option details stay in the parameter descriptions in every mode (the parameter schema is never customizable). Applies on the next pi session.
|
|
403
|
+
|
|
404
|
+
`"custom"` registers your own description from `<cwd>/.pi/agent-tool-description.md` (project) or `<agentDir>/agent-tool-description.md` (global; project wins). The file is read once at tool registration, so edits also apply on the next pi session. Dynamic parts stay live via placeholders — a static agent list would go stale the moment you add a custom agent:
|
|
405
|
+
|
|
406
|
+
```markdown
|
|
407
|
+
Launch an autonomous agent. Available types:
|
|
408
|
+
{{typeList}}
|
|
409
|
+
|
|
410
|
+
Custom agents live in .pi/agents/ or {{agentDir}}/agents/.
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Placeholders: `{{typeList}}` (full per-agent descriptions), `{{compactTypeList}}` (first sentence each), `{{agentDir}}`, `{{currentDepth}}`, `{{maxDepth}}`, `{{recursiveGuideline}}`, `{{scheduleGuideline}}` (expands with its own leading newline + `- ` bullet when scheduling is on — place it directly after your last rule line; empty when scheduling is off). Unknown placeholders are left verbatim with a stderr warning; a missing or empty file falls back to `"full"` with a warning. Note the usual trust umbrella: a project-level file shapes the orchestrator's prompt, same as project agents and extensions do.
|
|
414
|
+
|
|
415
|
+
**Starting point:** copy [`examples/agent-tool-description.md`](examples/agent-tool-description.md) — it reproduces the default full description exactly (a CI test keeps it in sync), so you can trim from a known-good baseline instead of writing from scratch.
|
|
416
|
+
|
|
417
|
+
**Example — global defaults for a beefy machine:**
|
|
418
|
+
|
|
419
|
+
```bash
|
|
420
|
+
mkdir -p ~/.pi/agent
|
|
421
|
+
cat > ~/.pi/agent/subagents.json <<'EOF'
|
|
422
|
+
{
|
|
423
|
+
"maxConcurrent": 16,
|
|
424
|
+
"graceTurns": 10
|
|
425
|
+
}
|
|
426
|
+
EOF
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
Every project now starts with concurrency 16 and grace 10, without ever touching the menu. Individual projects can still override via `/agents` → Settings.
|
|
430
|
+
|
|
431
|
+
**Failure behavior:** missing file is silent; malformed JSON logs a `[pi-subagents] Ignoring malformed settings at …` warning to stderr; invalid/out-of-range field values are dropped per-field; write failures downgrade the `/agents` toast to a warning with `(session only; failed to persist)`.
|
|
432
|
+
|
|
433
|
+
## Events
|
|
434
|
+
|
|
435
|
+
Agent lifecycle events are emitted via `pi.events.emit()` so other extensions can react:
|
|
436
|
+
|
|
437
|
+
| Event | When | Key fields |
|
|
438
|
+
|-------|------|------------|
|
|
439
|
+
| `subagents:created` | Background agent registered | `id`, `type`, `description`, `isBackground`, `depth`, `parentAgentId` |
|
|
440
|
+
| `subagents:started` | Agent transitions to running (including queued→running) | `id`, `type`, `description`, `depth`, `parentAgentId` |
|
|
441
|
+
| `subagents:completed` | Agent finished successfully | `id`, `type`, `durationMs`, `tokens` (lifetime `{ input, output, total }`), `toolUses`, `result`, `depth`, `parentAgentId` |
|
|
442
|
+
| `subagents:failed` | Agent errored, stopped, or aborted | same as completed + `error`, `status` |
|
|
443
|
+
| `subagents:steered` | Steering message sent | `id`, `message` |
|
|
444
|
+
| `subagents:compacted` | Agent's session successfully compacted | `id`, `type`, `description`, `reason` (`"manual"` / `"threshold"` / `"overflow"`), `tokensBefore`, `compactionCount`, `depth`, `parentAgentId` |
|
|
445
|
+
| `subagents:scheduled` | Schedule lifecycle change | `{ type: "added" \| "removed" \| "updated" \| "fired" \| "error", … }` (job/agentId/error fields per type) |
|
|
446
|
+
| `subagents:scheduler_ready` | Scheduler bound to session, enabled jobs armed | `sessionId`, `jobCount` |
|
|
447
|
+
| `subagents:ready` | Extension loaded and RPC handlers registered | — |
|
|
448
|
+
| `subagents:settings_loaded` | Persisted settings applied at extension init | `settings` (merged global + project) |
|
|
449
|
+
| `subagents:settings_changed` | `/agents` → Settings mutation was applied | `settings`, `persisted` (`boolean` — `false` on write failure) |
|
|
450
|
+
|
|
451
|
+
`depth` is the recursive subagent depth for the agent that emitted the event. `parentAgentId` is present when that agent was spawned by another subagent. `tokens.total` = `input + output + cacheWrite`. `cacheRead` is excluded — each turn's `cacheRead` is the cumulative cached prefix re-read on that one API call, so summing per-message would over-count it. Use `contextUsage.percent` (surfaced as `(NN%)` in the widget) for current context size.
|
|
452
|
+
|
|
453
|
+
## Cross-Extension RPC
|
|
454
|
+
|
|
455
|
+
Other pi extensions can spawn and stop subagents programmatically via the `pi.events` event bus, without importing this package directly.
|
|
456
|
+
|
|
457
|
+
All RPC replies use a standardized envelope: `{ success: true, data?: T }` on success, `{ success: false, error: string }` on failure.
|
|
458
|
+
|
|
459
|
+
### Discovery
|
|
460
|
+
|
|
461
|
+
Listen for `subagents:ready` to know when RPC handlers are available:
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
pi.events.on("subagents:ready", () => {
|
|
465
|
+
// RPC handlers are registered — safe to call ping/spawn/stop
|
|
466
|
+
});
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Ping
|
|
470
|
+
|
|
471
|
+
Check if the subagents extension is loaded and get the protocol version:
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
const requestId = crypto.randomUUID();
|
|
475
|
+
const unsub = pi.events.on(`subagents:rpc:ping:reply:${requestId}`, (reply) => {
|
|
476
|
+
unsub();
|
|
477
|
+
if (reply.success) console.log("Protocol version:", reply.data.version);
|
|
478
|
+
});
|
|
479
|
+
pi.events.emit("subagents:rpc:ping", { requestId });
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Spawn
|
|
483
|
+
|
|
484
|
+
Spawn a subagent and receive its ID:
|
|
485
|
+
|
|
486
|
+
```typescript
|
|
487
|
+
const requestId = crypto.randomUUID();
|
|
488
|
+
const unsub = pi.events.on(`subagents:rpc:spawn:reply:${requestId}`, (reply) => {
|
|
489
|
+
unsub();
|
|
490
|
+
if (!reply.success) {
|
|
491
|
+
console.error("Spawn failed:", reply.error);
|
|
492
|
+
} else {
|
|
493
|
+
console.log("Agent ID:", reply.data.id);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
pi.events.emit("subagents:rpc:spawn", {
|
|
497
|
+
requestId,
|
|
498
|
+
type: "general-purpose",
|
|
499
|
+
prompt: "Do something useful",
|
|
500
|
+
options: { description: "My task" },
|
|
501
|
+
});
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
`options.model` accepts either a `Model` object (e.g. `ctx.model`) or a `"provider/modelId"` string — strings are resolved against `ctx.modelRegistry` at the RPC boundary, so cross-extension callers can forward serializable values without losing auth context.
|
|
505
|
+
|
|
506
|
+
`options.cwd` (absolute path to an existing directory — anything else returns an error envelope; `null` means unset) runs the agent in a different working directory than the parent session. Its tools operate there and the prompt's environment block describes it, but **`.pi` config still loads from the parent session's project** — the target directory's `.pi` extensions never execute, and its agents/skills/settings are not picked up. Combined with `isolation: "worktree"`, the worktree is created *from* the target directory's repo, the agent works at the equivalent subdirectory inside the copy (a monorepo-package cwd stays scoped to that package), and the resulting `pi-agent-*` branch lands in that repo — the completion message names it. On session end, worktree registrations are pruned in every repo that received one; only a hard crash can leave a stale entry (then: `git worktree prune` in the target repo). Agents with `memory:` keep reading/writing the parent project's memory.
|
|
507
|
+
|
|
508
|
+
### Stop
|
|
509
|
+
|
|
510
|
+
Stop a running agent by ID:
|
|
511
|
+
|
|
512
|
+
```typescript
|
|
513
|
+
const requestId = crypto.randomUUID();
|
|
514
|
+
const unsub = pi.events.on(`subagents:rpc:stop:reply:${requestId}`, (reply) => {
|
|
515
|
+
unsub();
|
|
516
|
+
if (!reply.success) console.error("Stop failed:", reply.error);
|
|
517
|
+
});
|
|
518
|
+
pi.events.emit("subagents:rpc:stop", { requestId, agentId: "agent-id-here" });
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
Reply channels are scoped per `requestId`, so concurrent requests don't interfere.
|
|
522
|
+
|
|
523
|
+
## Persistent Agent Memory
|
|
524
|
+
|
|
525
|
+
Agents can have persistent memory across sessions. Set `memory` in frontmatter to enable:
|
|
526
|
+
|
|
527
|
+
```yaml
|
|
528
|
+
---
|
|
529
|
+
memory: project # project | local | user
|
|
530
|
+
---
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
| Scope | Location | Use case |
|
|
534
|
+
|-------|----------|----------|
|
|
535
|
+
| `project` | `.pi/agent-memory/<name>/` | Shared across the team (committed) |
|
|
536
|
+
| `local` | `.pi/agent-memory-local/<name>/` | Machine-specific (gitignored) |
|
|
537
|
+
| `user` | `~/.pi/agent-memory/<name>/` | Global personal memory |
|
|
538
|
+
|
|
539
|
+
Memory uses a `MEMORY.md` index file and individual memory files with frontmatter. Agents with write tools get full read-write access. **Read-only agents** (no `write`/`edit` tools) automatically get read-only memory — they can consume memories written by other agents but cannot modify them. This prevents unintended tool escalation.
|
|
540
|
+
|
|
541
|
+
The `disallowed_tools` field is respected when determining write capability — an agent with `tools: write` + `disallowed_tools: write` correctly gets read-only memory.
|
|
542
|
+
|
|
543
|
+
## Worktree Isolation
|
|
544
|
+
|
|
545
|
+
Set `isolation: worktree` to run an agent in a temporary git worktree:
|
|
546
|
+
|
|
547
|
+
```
|
|
548
|
+
Agent({ subagent_type: "refactor", prompt: "...", isolation: "worktree" })
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
The agent gets a full, isolated copy of the repository. On completion:
|
|
552
|
+
- **No changes:** worktree is cleaned up automatically
|
|
553
|
+
- **Changes made:** changes are committed to a new branch (`pi-agent-<id>`) and returned in the result
|
|
554
|
+
- **Agent committed its own work:** the branch is created at the agent's HEAD, preserving its commits (uncommitted leftovers are committed on top first)
|
|
555
|
+
|
|
556
|
+
The automatic preservation commit uses `--no-verify`, so local pre-commit hooks can't block it — the commit is local-only and never pushed, and pre-push/server-side hooks still apply.
|
|
557
|
+
|
|
558
|
+
If the worktree cannot be created (not a git repo, no commits, or `git worktree add` fails), the `Agent` tool returns a clear error instead of running unisolated — `isolation: "worktree"` is a strict guarantee, not a hint. Initialize git and commit at least once, or omit `isolation`.
|
|
559
|
+
|
|
560
|
+
## Skill Preloading
|
|
561
|
+
|
|
562
|
+
Skills can be preloaded by name and injected into the agent's system prompt:
|
|
563
|
+
|
|
564
|
+
```yaml
|
|
565
|
+
---
|
|
566
|
+
skills: api-conventions, error-handling
|
|
567
|
+
---
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
**Discovery roots** (checked in this order, first match wins):
|
|
571
|
+
|
|
572
|
+
| Scope | Path | Source |
|
|
573
|
+
|---|---|---|
|
|
574
|
+
| Project | `<cwd>/.pi/skills/` | Pi-standard |
|
|
575
|
+
| Project | `<cwd>/.agents/skills/` | [Agent Skills spec](https://agentskills.io/integrate-skills) |
|
|
576
|
+
| User | `$PI_CODING_AGENT_DIR/skills/` (default `~/.pi/agent/skills/`) | Pi-standard |
|
|
577
|
+
| User | `~/.agents/skills/` | [Agent Skills spec](https://agentskills.io/integrate-skills) |
|
|
578
|
+
| User | `~/.pi/skills/` | Legacy (pre-Pi) |
|
|
579
|
+
|
|
580
|
+
**Per root, a skill named `foo` resolves to the first of:**
|
|
581
|
+
|
|
582
|
+
- `<root>/foo.md` — flat file at the top level
|
|
583
|
+
- `<root>/foo/SKILL.md` — directory skill (top-level)
|
|
584
|
+
- `<root>/*/.../foo/SKILL.md` — directory skill, found by recursive descent
|
|
585
|
+
|
|
586
|
+
Recursion skips dotfile directories and `node_modules`. A directory that itself contains a `SKILL.md` is treated as a single skill — we don't descend into it. Traversal is byte-order sorted for deterministic resolution across filesystems.
|
|
587
|
+
|
|
588
|
+
**Security:** symlinks are rejected at every layer (root, flat file, skill directory, `SKILL.md` inside a skill directory) — intentional deviation from Pi, which follows symlinks. Skill names with path-traversal characters (`..`, `/`, `\`, spaces, leading dot, >128 chars) are rejected.
|
|
589
|
+
|
|
590
|
+
## Tool Denylist
|
|
591
|
+
|
|
592
|
+
Block specific tools from an agent even if extensions provide them:
|
|
593
|
+
|
|
594
|
+
```yaml
|
|
595
|
+
---
|
|
596
|
+
tools: read, bash, grep, write
|
|
597
|
+
disallowed_tools: write, edit
|
|
598
|
+
---
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
This is useful for creating agents that inherit extension tools but should not have write access.
|
|
602
|
+
|
|
603
|
+
## Architecture
|
|
604
|
+
|
|
605
|
+
```
|
|
606
|
+
src/
|
|
607
|
+
index.ts # Extension entry: tool/command registration, rendering
|
|
608
|
+
types.ts # Type definitions (AgentConfig, AgentRecord, etc.)
|
|
609
|
+
default-agents.ts # Embedded default agent configs (general-purpose, Explore, Plan)
|
|
610
|
+
agent-types.ts # Unified agent registry (defaults + user), tool name resolution
|
|
611
|
+
agent-runner.ts # Session creation, execution, graceful max_turns, steer/resume
|
|
612
|
+
agent-manager.ts # Agent lifecycle, concurrency queue, completion notifications
|
|
613
|
+
cross-extension-rpc.ts # RPC handlers for cross-extension spawn/ping via pi.events
|
|
614
|
+
group-join.ts # Group join manager: batched completion notifications with timeout
|
|
615
|
+
custom-agents.ts # Load user-defined agents from .pi/agents/*.md
|
|
616
|
+
memory.ts # Persistent agent memory (resolve, read, build prompt blocks)
|
|
617
|
+
skill-loader.ts # Preload skills (Pi-standard + Agent Skills spec layouts)
|
|
618
|
+
output-file.ts # Streaming output file transcripts for agent sessions
|
|
619
|
+
worktree.ts # Git worktree isolation (create, cleanup, prune)
|
|
620
|
+
prompts.ts # Config-driven system prompt builder
|
|
621
|
+
context.ts # Parent conversation context for inherit_context
|
|
622
|
+
env.ts # Environment detection (git, platform)
|
|
623
|
+
ui/
|
|
624
|
+
agent-widget.ts # Persistent widget: spinners, activity, status icons, theming
|
|
625
|
+
conversation-viewer.ts # Live conversation overlay for viewing agent sessions
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
## License
|
|
629
|
+
|
|
630
|
+
MIT — forked from [tintinweb](https://github.com/tintinweb/pi-subagents), maintained by [clankercode](https://github.com/clankercode)
|