@leing2021/super-pi 0.21.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -357
  3. package/THIRD-PARTY-NOTICES.md +35 -0
  4. package/extensions/subagent/__tests__/async-job-tracker.test.ts +21 -0
  5. package/extensions/subagent/__tests__/execution-activity.test.ts +15 -0
  6. package/extensions/subagent/__tests__/parallel-render-stress.test.ts +82 -0
  7. package/extensions/subagent/__tests__/render-dedup.test.ts +98 -0
  8. package/extensions/subagent/__tests__/render-widget.test.ts +28 -0
  9. package/extensions/subagent/__tests__/throttle.test.ts +90 -0
  10. package/extensions/subagent/agent-management.ts +596 -0
  11. package/extensions/subagent/agent-manager-chain-detail.ts +163 -0
  12. package/extensions/subagent/agent-manager-detail.ts +232 -0
  13. package/extensions/subagent/agent-manager-edit.ts +391 -0
  14. package/extensions/subagent/agent-manager-list.ts +279 -0
  15. package/extensions/subagent/agent-manager-parallel.ts +305 -0
  16. package/extensions/subagent/agent-manager.ts +706 -0
  17. package/extensions/subagent/agent-scope.ts +9 -0
  18. package/extensions/subagent/agent-selection.ts +26 -0
  19. package/extensions/subagent/agent-serializer.ts +124 -0
  20. package/extensions/subagent/agent-templates.ts +63 -0
  21. package/extensions/subagent/agents/context-builder.md +37 -0
  22. package/extensions/subagent/agents/delegate.md +9 -0
  23. package/extensions/subagent/agents/oracle.md +73 -0
  24. package/extensions/subagent/agents/planner.md +52 -0
  25. package/extensions/subagent/agents/researcher.md +50 -0
  26. package/extensions/subagent/agents/reviewer.md +38 -0
  27. package/extensions/subagent/agents/scout.md +48 -0
  28. package/extensions/subagent/agents/worker.md +52 -0
  29. package/extensions/subagent/agents.ts +762 -0
  30. package/extensions/subagent/artifacts.ts +101 -0
  31. package/extensions/subagent/async-execution.ts +521 -0
  32. package/extensions/subagent/async-job-tracker.ts +240 -0
  33. package/extensions/subagent/async-status.ts +242 -0
  34. package/extensions/subagent/chain-clarify.ts +1365 -0
  35. package/extensions/subagent/chain-execution.ts +854 -0
  36. package/extensions/subagent/chain-serializer.ts +127 -0
  37. package/extensions/subagent/completion-dedupe.ts +66 -0
  38. package/extensions/subagent/doctor.ts +201 -0
  39. package/extensions/subagent/execution.ts +748 -0
  40. package/extensions/subagent/file-coalescer.ts +43 -0
  41. package/extensions/subagent/fork-context.ts +64 -0
  42. package/extensions/subagent/formatters.ts +123 -0
  43. package/extensions/subagent/frontmatter.ts +32 -0
  44. package/extensions/subagent/index.ts +586 -0
  45. package/extensions/subagent/intercom-bridge.ts +241 -0
  46. package/extensions/subagent/jsonl-writer.ts +84 -0
  47. package/extensions/subagent/model-fallback.ts +109 -0
  48. package/extensions/subagent/notify.ts +111 -0
  49. package/extensions/subagent/parallel-utils.ts +109 -0
  50. package/extensions/subagent/pi-args.ts +139 -0
  51. package/extensions/subagent/pi-spawn.ts +101 -0
  52. package/extensions/subagent/post-exit-stdio-guard.ts +88 -0
  53. package/extensions/subagent/prompt-template-bridge.ts +400 -0
  54. package/extensions/subagent/prompts/gather-context-and-clarify.md +13 -0
  55. package/extensions/subagent/prompts/parallel-cleanup.md +42 -0
  56. package/extensions/subagent/prompts/parallel-research.md +50 -0
  57. package/extensions/subagent/prompts/parallel-review.md +40 -0
  58. package/extensions/subagent/render-helpers.ts +83 -0
  59. package/extensions/subagent/render.ts +908 -0
  60. package/extensions/subagent/result-intercom.ts +238 -0
  61. package/extensions/subagent/result-watcher.ts +172 -0
  62. package/extensions/subagent/run-history.ts +58 -0
  63. package/extensions/subagent/run-status.ts +137 -0
  64. package/extensions/subagent/schemas.ts +165 -0
  65. package/extensions/subagent/session-tokens.ts +51 -0
  66. package/extensions/subagent/settings.ts +368 -0
  67. package/extensions/subagent/single-output.ts +98 -0
  68. package/extensions/subagent/skills.ts +627 -0
  69. package/extensions/subagent/slash-bridge.ts +177 -0
  70. package/extensions/subagent/slash-commands.ts +304 -0
  71. package/extensions/subagent/slash-live-state.ts +295 -0
  72. package/extensions/subagent/subagent-control.ts +151 -0
  73. package/extensions/subagent/subagent-executor.ts +1915 -0
  74. package/extensions/subagent/subagent-prompt-runtime.ts +76 -0
  75. package/extensions/subagent/subagent-runner.ts +1471 -0
  76. package/extensions/subagent/subagents-status.ts +473 -0
  77. package/extensions/subagent/text-editor.ts +273 -0
  78. package/extensions/subagent/throttle.ts +77 -0
  79. package/extensions/subagent/top-level-async.ts +16 -0
  80. package/extensions/subagent/types.ts +624 -0
  81. package/extensions/subagent/utils.ts +457 -0
  82. package/extensions/subagent/worktree.ts +580 -0
  83. package/extensions/super-pi-extension/index.ts +2 -55
  84. package/package.json +14 -6
  85. package/skills/pi-subagents/SKILL.md +566 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leing2021/super-pi",
3
- "version": "0.21.0",
3
+ "version": "0.22.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Pi-native Compound Engineering package for iterative development workflows",
@@ -25,6 +25,8 @@
25
25
  "skills",
26
26
  "extensions",
27
27
  "rules",
28
+ "THIRD-PARTY-NOTICES.md",
29
+ "LICENSE",
28
30
  "README.md",
29
31
  "package.json"
30
32
  ],
@@ -35,9 +37,10 @@
35
37
  "test": "bun test"
36
38
  },
37
39
  "peerDependencies": {
38
- "@mariozechner/pi-coding-agent": "*",
39
- "pi-subagents": "*",
40
- "typebox": "*"
40
+ "@mariozechner/pi-coding-agent": "*"
41
+ },
42
+ "dependencies": {
43
+ "typebox": "^1.1.24"
41
44
  },
42
45
  "devDependencies": {
43
46
  "@mariozechner/pi-coding-agent": "0.69.0",
@@ -49,10 +52,15 @@
49
52
  ],
50
53
  "extensions": [
51
54
  "./extensions",
52
- "./extensions/super-pi-extension"
55
+ "./extensions/super-pi-extension",
56
+ "./extensions/subagent"
53
57
  ],
54
58
  "agents": [
55
- "./extensions/super-pi-extension/agents"
59
+ "./extensions/super-pi-extension/agents",
60
+ "./extensions/subagent/agents"
61
+ ],
62
+ "prompts": [
63
+ "./extensions/subagent/prompts"
56
64
  ],
57
65
  "chains": [
58
66
  "./extensions/super-pi-extension/chains"
@@ -0,0 +1,566 @@
1
+ ---
2
+ name: pi-subagents
3
+ description: |
4
+ Delegate work to builtin or custom subagents with single-agent, chain,
5
+ parallel, async, forked-context, and intercom-coordinated workflows. Use
6
+ for advisory review, implementation handoffs, and multi-step tasks where a
7
+ single agent should stay in control while other agents contribute context,
8
+ planning, or execution.
9
+ ---
10
+
11
+ # Pi Subagents
12
+
13
+ Use this skill when you need to launch a specialized subagent, compose multiple
14
+ agents into a workflow, or create/edit agents and chains on demand.
15
+
16
+ ## When to Use
17
+
18
+ - **Advisory review**: use fresh-context `reviewer` agents for adversarial code review, or fork to `oracle` when inherited decisions and drift matter
19
+ - **Implementation handoff**: have `oracle` advise, then `worker` implement only after an approved direction
20
+ - **Recon and planning**: use `scout` or `context-builder`, then `planner`
21
+ - **Parallel exploration**: run multiple non-conflicting tasks concurrently
22
+ - **Long-running work**: launch async/background runs and inspect them later
23
+ - **Subagent control**: watch needs-attention signals and soft-interrupt only when a delegated run is genuinely blocked
24
+ - **Agent authoring**: create, update, or override agents and chains for a project
25
+
26
+ ## Tool vs Slash Commands
27
+
28
+ Agents can use the `subagent(...)` tool directly for execution, management, status, and control.
29
+ Humans often use the slash-command layer instead:
30
+
31
+ - `/run` — launch a single agent
32
+ - `/chain` — launch a chain of steps
33
+ - `/parallel` — launch top-level parallel tasks
34
+ - `/agents` — open the agents manager TUI
35
+ - `/run-chain` — launch a saved `.chain.md` workflow
36
+ - `/subagents-status` — inspect active/recent async runs
37
+ - `/subagents-doctor` — diagnose setup, discovery, async paths, and intercom bridge state
38
+
39
+ Prefer the tool when you are writing agent logic. Prefer the slash commands when
40
+ you are guiding a human through an interactive flow.
41
+
42
+ Packaged prompt shortcuts are also available for repeatable workflows:
43
+ - `/parallel-review` — fresh-context reviewers with distinct review angles, then synthesis
44
+ - `/parallel-research` — combine `researcher` and `scout` for external evidence plus local code context
45
+ - `/gather-context-and-clarify` — scout/research first, then ask the user clarifying questions with `interview`
46
+
47
+ ## Builtin Agents
48
+
49
+ Builtin agents load at the lowest priority. Project agents override user agents,
50
+ and user/project agents override builtins with the same name.
51
+
52
+ | Agent | Purpose | Model | Typical output / role |
53
+ |-------|---------|-------|------------------------|
54
+ | `scout` | Fast codebase recon | `openai-codex/gpt-5.4-mini` | Writes `context.md` handoff material |
55
+ | `planner` | Creates implementation plans | `openai-codex/gpt-5.5` | Writes `plan.md` |
56
+ | `worker` | Implementation and approved oracle handoffs | `openai-codex/gpt-5.3-codex` | Single-writer implementation with decision escalation |
57
+ | `reviewer` | Review-and-fix specialist | `openai-codex/gpt-5.5` | Can edit/fix reviewed code |
58
+ | `context-builder` | Requirements/codebase handoff builder | `openai-codex/gpt-5.5` | Writes structured context files |
59
+ | `researcher` | Web research brief generator | `openai-codex/gpt-5.5` | Writes `research.md` |
60
+ | `delegate` | Lightweight generic delegate | inherits parent model | No fixed output; generic delegated work |
61
+ | `oracle` | Decision-consistency advisory review | `openai-codex/gpt-5.5` | Advisory review, intercom coordination |
62
+
63
+ Override builtin defaults before copying full agent files when a small tweak is enough.
64
+
65
+ For one run, use inline config:
66
+
67
+ ```text
68
+ /run reviewer[model=anthropic/claude-sonnet-4] "Review this diff"
69
+ ```
70
+
71
+ For persistent tweaks, prefer `/agents`: choose the builtin, press `e`, change the model or other fields, then save a user or project override. User overrides apply everywhere. Project overrides apply only in that repo and win over user overrides.
72
+
73
+ Settings locations:
74
+ - User scope: `~/.pi/agent/settings.json`
75
+ - Project scope: `.pi/settings.json`
76
+
77
+ Direct settings example:
78
+
79
+ ```json
80
+ {
81
+ "subagents": {
82
+ "agentOverrides": {
83
+ "reviewer": {
84
+ "model": "anthropic/claude-sonnet-4",
85
+ "thinking": "high",
86
+ "fallbackModels": ["openai/gpt-5-mini"]
87
+ }
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ Useful override fields: `model`, `fallbackModels`, `thinking`,
94
+ `systemPromptMode`, `inheritProjectContext`, `inheritSkills`, `disabled`,
95
+ `skills`, `tools`, and `systemPrompt`. Create a user or project agent with the
96
+ same name only when you want a substantially different agent.
97
+
98
+ ## Discovery and Scope Rules
99
+
100
+ Agent files can live in:
101
+ - `~/.pi/agent/agents/*.md` — user scope
102
+ - `.pi/agents/*.md` — canonical project scope
103
+ - legacy `.agents/*.md` — still read for compatibility, but `.pi/agents/` wins on conflicts
104
+
105
+ Chains live in:
106
+ - `~/.pi/agent/agents/*.chain.md`
107
+ - `.pi/agents/*.chain.md`
108
+ - legacy `.agents/*.chain.md`
109
+
110
+ Precedence is:
111
+ 1. project scope
112
+ 2. user scope
113
+ 3. builtin agents
114
+
115
+ ## Running Subagents
116
+
117
+ ### Single agent
118
+
119
+ ```typescript
120
+ subagent({
121
+ agent: "oracle",
122
+ task: "Review my current direction and challenge assumptions."
123
+ })
124
+ ```
125
+
126
+ ### Forked context
127
+
128
+ ```typescript
129
+ subagent({
130
+ agent: "oracle",
131
+ task: "Review my current direction and challenge assumptions.",
132
+ context: "fork"
133
+ })
134
+ ```
135
+
136
+ `context: "fork"` creates a branched child session from the current persisted
137
+ parent session. It does **not** create a fresh minimal review context or filter
138
+ history down to only the relevant parts. Use it when you want a separate review
139
+ or execution thread that can still reference the parent session history.
140
+
141
+ ### Parallel execution
142
+
143
+ ```typescript
144
+ subagent({
145
+ tasks: [
146
+ { agent: "scout", task: "Explore the auth module" },
147
+ { agent: "reviewer", task: "Review the API client" }
148
+ ]
149
+ })
150
+ ```
151
+
152
+ Top-level parallel tasks can override per-task behavior:
153
+
154
+ ```typescript
155
+ subagent({
156
+ tasks: [
157
+ { agent: "scout", task: "Map auth", output: "auth-context.md", progress: true },
158
+ { agent: "researcher", task: "Research OAuth best practices", output: "oauth-research.md" },
159
+ { agent: "reviewer", task: "Review auth tests", model: "anthropic/claude-sonnet-4" }
160
+ ],
161
+ concurrency: 3
162
+ })
163
+ ```
164
+
165
+ Avoid duplicate output paths in parallel tasks. Concurrent children should not write to the same file.
166
+
167
+ ### Chain execution
168
+
169
+ ```typescript
170
+ subagent({
171
+ chain: [
172
+ { agent: "scout", task: "Map the auth flow and summarize key files" },
173
+ { agent: "planner", task: "Create an implementation plan from {previous}" },
174
+ { agent: "worker", task: "Implement the approved plan based on {previous}" }
175
+ ]
176
+ })
177
+ ```
178
+
179
+ Chain steps can use templated variables such as `{task}`, `{previous}`, and
180
+ `{chain_dir}`. This is the main way to pass structured summaries between steps
181
+ without forcing each step to rediscover everything.
182
+
183
+ ### Async/background
184
+
185
+ ```typescript
186
+ subagent({
187
+ agent: "worker",
188
+ task: "Run the full test suite",
189
+ async: true
190
+ })
191
+ ```
192
+
193
+ Inspect async runs with `subagent({ action: "status", id: "..." })`, `subagent({ action: "status" })` for active runs, or the `/subagents-status` slash command.
194
+
195
+ Use diagnostics when setup or child startup looks wrong:
196
+
197
+ ```typescript
198
+ subagent({ action: "doctor" })
199
+ ```
200
+
201
+ Humans can use `/subagents-doctor` for the same read-only report. It checks runtime paths, discovery counts, async support, current session context, and intercom bridge state.
202
+
203
+ ### Subagent control
204
+
205
+ Subagent control is the runtime visibility and intervention layer for delegated runs. It is separate from lifecycle status. Lifecycle status says whether a child is `queued`, `running`, `paused`, `complete`, or `failed`. Activity reporting is factual: it tracks the last observed activity time and the current tool when known. It does not pretend to know that a child is truly stuck.
206
+
207
+ Default behavior is intentionally conservative. When no activity has been observed past the configured threshold, the run emits a `needs_attention` control event. Foreground runs can push this as a `subagent:control-event` event, and async runs persist it to `events.jsonl` so the parent tracker can surface it without constant manual polling. Notification-worthy control events are also inserted into the visible transcript so both the user and the parent agent can see them, with a proactive hint plus concrete `nudge`, `status`, and `interrupt` options. Visible notifications fire once per child run and attention state.
208
+
209
+ Use soft interrupt when a child is clearly blocked or drifting and the parent needs to regain control:
210
+
211
+ ```typescript
212
+ subagent({ action: "interrupt" })
213
+ ```
214
+
215
+ Pass `id` when targeting a specific controllable run:
216
+
217
+ ```typescript
218
+ subagent({ action: "interrupt", id: "abc123" })
219
+ ```
220
+
221
+ A soft interrupt cancels the current child turn and leaves the run paused. It does not mean the delegated task succeeded or failed. After an interrupt, decide the next explicit action: resume with clearer instructions, replace the task, ask the user, or stop the workflow.
222
+
223
+ Per-run control thresholds can be overridden when a task legitimately runs without observable output for longer than usual:
224
+
225
+ ```typescript
226
+ subagent({
227
+ agent: "worker",
228
+ task: "Run the slow migration test suite",
229
+ control: {
230
+ needsAttentionAfterMs: 300000,
231
+ notifyOn: ["needs_attention"]
232
+ }
233
+ })
234
+ ```
235
+
236
+ If the run already has an active intercom bridge target, needs-attention notifications can also prepare a compact intercom ping for the orchestrator. When a child route is available, the ping tells the orchestrator which agent needs attention and includes the exact `intercom({ action: "send", to: "..." })` target for a nudge. Do not invent a target or ask the child to self-report when no bridge exists.
237
+
238
+ ## Clarify TUI
239
+
240
+ Single and parallel runs support a clarification TUI when you want to preview or
241
+ edit parameters before launch:
242
+
243
+ ```typescript
244
+ subagent({
245
+ agent: "worker",
246
+ task: "Implement feature X",
247
+ clarify: true
248
+ })
249
+ ```
250
+
251
+ Chains default to clarify mode unless you explicitly set `clarify: false`.
252
+ For programmatic background launches, use `clarify: false, async: true`.
253
+
254
+ The `/agents` manager also has launch toggles for forked context, background execution, and worktree-isolated parallel runs. Use it when guiding a human who wants to inspect or edit the launch before starting.
255
+
256
+ ## Worktree Isolation
257
+
258
+ When multiple agents might write concurrently, use worktrees instead of letting
259
+ them share one filesystem view.
260
+
261
+ ```typescript
262
+ subagent({
263
+ tasks: [
264
+ { agent: "worker", task: "Implement feature A" },
265
+ { agent: "worker", task: "Implement feature B" }
266
+ ],
267
+ worktree: true
268
+ })
269
+ ```
270
+
271
+ `worktree: true` gives each parallel task its own git worktree branched from
272
+ HEAD. This requires a clean git state and is mainly for intentionally parallel
273
+ write workflows. If you want one writer thread and several advisory agents,
274
+ prefer a single-writer pattern instead.
275
+
276
+ ## The Oracle Workflow
277
+
278
+ The intended oracle loop is:
279
+ 1. the main agent forks to `oracle`
280
+ 2. `oracle` reviews direction, drift, assumptions, and risks
281
+ 3. `oracle` can coordinate back to the orchestrator via `intercom`
282
+ 4. the main agent decides what direction to approve
283
+ 5. only then should `worker` implement
284
+
285
+ ```typescript
286
+ // Advisory review in a branched thread
287
+ subagent({
288
+ agent: "oracle",
289
+ task: "Review my current direction, challenge assumptions, and propose the best next move.",
290
+ context: "fork"
291
+ })
292
+
293
+ // Implementation only after explicit approval
294
+ subagent({
295
+ agent: "worker",
296
+ task: "Implement the approved approach: ...",
297
+ context: "fork"
298
+ })
299
+ ```
300
+
301
+ `oracle` is not a fresh-context reviewer in the Cognition article sense. It is
302
+ a forked advisory thread that inherits the parent session history and uses that
303
+ history as a baseline contract.
304
+
305
+ ## Subagent + Intercom Coordination
306
+
307
+ `pi-subagents` works without `pi-intercom`. When `pi-intercom` is installed and enabled, the intercom bridge can automatically give child agents a private coordination channel back to the parent session.
308
+
309
+ Most agents should not call `intercom` directly unless bridge instructions provide a target. Do not invent a target. Use the target from the injected bridge instructions or from a visible needs-attention notice.
310
+
311
+ Use `intercom` when:
312
+ - a subagent is blocked on a decision
313
+ - a child needs clarification instead of guessing
314
+ - a detached or async child needs to coordinate without waiting for normal tool return flow
315
+ - an advisory agent was explicitly asked to send a concise progress update
316
+
317
+ Message conventions:
318
+ - `ask` means the child needs a decision or clarification from the parent session.
319
+ - `send` means a short blocked/progress update, only when blocked or explicitly asked.
320
+ - Child-side routine completion handoffs are not expected. With the intercom bridge active, parent-side `pi-subagents` sends grouped completion results through `pi-intercom`: one grouped message per foreground parent run and one per completed async result file. Acknowledged foreground delivery returns a compact receipt with artifact/session paths; if unacknowledged, the normal full output is preserved. Grouped messages include child intercom targets and full child summaries.
321
+
322
+ If a bridge target is available, a child can ask:
323
+
324
+ ```typescript
325
+ intercom({
326
+ action: "ask",
327
+ to: "<bridge-provided-target>",
328
+ message: "Should I optimize for readability or performance here?"
329
+ })
330
+ ```
331
+
332
+ The parent replies with:
333
+
334
+ ```typescript
335
+ intercom({ action: "reply", message: "Optimize for readability." })
336
+ ```
337
+
338
+ Or inspects unresolved asks first:
339
+
340
+ ```typescript
341
+ intercom({ action: "pending" })
342
+ ```
343
+
344
+ If intercom messages do not show up, run `subagent({ action: "doctor" })` or `/subagents-doctor`.
345
+
346
+ ## Management Mode
347
+
348
+ The `subagent(...)` tool also supports management actions.
349
+
350
+ ### List available agents and chains
351
+
352
+ ```typescript
353
+ subagent({ action: "list" })
354
+ ```
355
+
356
+ ### Create an agent
357
+
358
+ ```typescript
359
+ subagent({
360
+ action: "create",
361
+ config: {
362
+ name: "my-agent",
363
+ description: "Project-specific implementation helper",
364
+ systemPrompt: "Your system prompt here.",
365
+ systemPromptMode: "replace",
366
+ model: "openai-codex/gpt-5.4",
367
+ tools: "read,grep,find,ls,bash"
368
+ }
369
+ })
370
+ ```
371
+
372
+ ### Update an agent
373
+
374
+ ```typescript
375
+ subagent({
376
+ action: "update",
377
+ agent: "my-agent",
378
+ config: {
379
+ thinking: "high"
380
+ }
381
+ })
382
+ ```
383
+
384
+ ### Delete an agent
385
+
386
+ ```typescript
387
+ subagent({ action: "delete", agent: "my-agent" })
388
+ ```
389
+
390
+ Use management actions when the system needs to create or edit subagents on
391
+ demand without dropping into raw file editing.
392
+
393
+ Management actions create or update user/project agent files. For small builtin changes such as a model swap, prefer `/agents` builtin overrides or `subagents.agentOverrides` in settings.
394
+
395
+ ## Creating and Editing Agents by File
396
+
397
+ A minimal agent file looks like this:
398
+
399
+ ```markdown
400
+ ---
401
+ name: my-agent
402
+ description: What this agent does
403
+ model: openai-codex/gpt-5.4
404
+ thinking: high
405
+ tools: read, grep, find, ls, bash
406
+ systemPromptMode: replace
407
+ inheritProjectContext: true
408
+ inheritSkills: false
409
+ ---
410
+
411
+ Your system prompt here.
412
+ ```
413
+
414
+ That is only a starting point. Common optional fields include:
415
+ - `defaultProgress`
416
+ - `defaultReads`
417
+ - `output`
418
+ - `fallbackModels`
419
+ - `maxSubagentDepth`
420
+
421
+ For many customizations, builtin overrides in settings are lower-friction than
422
+ copying a full builtin file.
423
+
424
+ ## Prompt Template Integration
425
+
426
+ The package includes prompt shortcuts for common workflows: `/parallel-review`,
427
+ `/parallel-research`, and `/gather-context-and-clarify`. Use them when the user
428
+ wants repeatable review, research, or clarification patterns.
429
+
430
+ If `pi-prompt-template-model` is installed, additional user prompt templates can delegate into
431
+ `pi-subagents`. This is useful when a slash command should always run through a
432
+ particular agent or with forked context.
433
+
434
+ ## Important Constraints
435
+
436
+ - **Forking requires a persisted parent session.** If the current session does not
437
+ have a persisted session file, forked runs fail.
438
+ - **Forked runs inherit parent history.** They are branched threads, not fresh
439
+ filtered contexts. Use fresh context for adversarial reviewers unless the user explicitly asks for forked context.
440
+ - **Default subagent nesting depth is 2.** Deeper recursive delegation is blocked
441
+ unless configured otherwise.
442
+ - **Attention signals are not lifecycle state.** `needs_attention` means no activity has been observed past the configured threshold. `paused` means the child turn was intentionally interrupted or is awaiting direction; it is not the same as `failed`.
443
+ - **Intercom asks are blocking.** A session can only maintain one pending outbound
444
+ ask wait state at a time.
445
+ - **Keep conversational authority clear.** Advisory subagents should not silently
446
+ become second decision-makers.
447
+
448
+ ## Best Practices
449
+
450
+ ### Keep writes single-threaded by default
451
+
452
+ A strong pattern is one main decision-maker plus advisory/research/review
453
+ subagents around it. Use `oracle` for advice and `worker` for the actual write path.
454
+
455
+ ### Use fork for branched advisory or execution threads
456
+
457
+ Forked runs are useful when the child should reason in a separate thread while
458
+ still inheriting the parent’s accumulated context. They are especially useful for
459
+ `oracle`, which audits inherited decisions and drift. For adversarial code review,
460
+ prefer fresh-context reviewers that inspect the repo and diff directly unless the
461
+ user explicitly requests forked context.
462
+
463
+ ### Prefer narrow tasks
464
+
465
+ Give subagents specific tasks rather than vague mandates.
466
+ `Review auth.ts for null-check gaps` works better than `Review everything`.
467
+
468
+ ### Escalate decisions upward
469
+
470
+ If a subagent encounters an unapproved product, architecture, or scope choice,
471
+ it should coordinate back via `intercom` instead of deciding alone.
472
+
473
+ ### Intervene only on clear control signals
474
+
475
+ Use subagent control proactively when a delegated run emits `needs_attention`, or when a human asks you to regain control. Do not interrupt just because a child has briefly produced no output. Silence can be normal during long tool calls, test runs, or model reasoning.
476
+
477
+ ### Name sessions meaningfully
478
+
479
+ Use `/name` so intercom targeting stays stable.
480
+
481
+ ## Common Workflows
482
+
483
+ ### Recon → Plan → Implement
484
+
485
+ ```typescript
486
+ subagent({
487
+ chain: [
488
+ { agent: "scout", task: "Map the auth flow and summarize relevant files" },
489
+ { agent: "planner", task: "Plan the migration from {previous}" },
490
+ { agent: "worker", task: "Implement the approved plan from {previous}" }
491
+ ]
492
+ })
493
+ ```
494
+
495
+ ### Review loop
496
+
497
+ ```typescript
498
+ subagent({ agent: "worker", task: "Add retry logic to the API client." })
499
+ subagent({
500
+ agent: "reviewer",
501
+ task: "Review the retry logic implementation. Inspect the repo and current diff directly. Look for edge cases and race conditions."
502
+ })
503
+ ```
504
+
505
+ ### Parallel non-conflicting analysis
506
+
507
+ ```typescript
508
+ subagent({
509
+ tasks: [
510
+ { agent: "scout", task: "Audit frontend auth flow" },
511
+ { agent: "researcher", task: "Research current retry/backoff best practices" }
512
+ ]
513
+ })
514
+ ```
515
+
516
+ ### Saved chain
517
+
518
+ ```text
519
+ /run-chain review-chain -- review this branch
520
+ ```
521
+
522
+ Use saved `.chain.md` workflows when the user wants a repeatable multi-agent flow without rewriting the chain each time.
523
+
524
+ ## Error Handling
525
+
526
+ **"Unknown agent"**
527
+ ```typescript
528
+ subagent({ action: "list" })
529
+ // Check available agents and chains, then confirm scope/precedence.
530
+ ```
531
+
532
+ **Setup, discovery, or intercom confusion**
533
+ ```typescript
534
+ subagent({ action: "doctor" })
535
+ // Check runtime paths, async support, discovery counts, current session, and intercom bridge state.
536
+ ```
537
+
538
+ **"Max subagent depth exceeded"**
539
+ ```typescript
540
+ // Flatten the workflow or raise maxSubagentDepth in config.
541
+ ```
542
+
543
+ **"Session manager did not return a session file"**
544
+ ```typescript
545
+ // Persist the current session before using context: "fork".
546
+ ```
547
+
548
+ **Intercom "Already waiting for a reply"**
549
+ ```typescript
550
+ // Resolve the current outbound ask before starting another one.
551
+ ```
552
+
553
+ **Parallel output-path conflict**
554
+ ```typescript
555
+ // Give each parallel task a distinct output path, or disable output for tasks that do not need it.
556
+ ```
557
+
558
+ **Worktree launch fails**
559
+ ```typescript
560
+ // Ensure the git working tree is clean and task cwd overrides match the shared cwd.
561
+ ```
562
+
563
+ **Child fails before starting**
564
+ ```typescript
565
+ // Inspect /subagents-status detail, artifact metadata/output logs, and run doctor. Extension loader errors usually appear in child output logs.
566
+ ```