@dreki-gg/pi-subagent 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.fallowrc.json +6 -0
  2. package/CHANGELOG.md +37 -0
  3. package/README.md +82 -70
  4. package/docs/orchestration-principles.md +132 -0
  5. package/docs/plans/01_structured-handoffs-and-synthesis.plan.md +376 -0
  6. package/docs/plans/02_clean-context-review-loop.plan.md +240 -0
  7. package/docs/plans/03_parallel-recon-single-writer-docs.plan.md +199 -0
  8. package/docs/plans/04_manager-workflow.plan.md +248 -0
  9. package/docs/plans/05_advisor-routing.plan.md +244 -0
  10. package/extensions/subagent/agent-result-utils.ts +12 -0
  11. package/extensions/subagent/agent-runner-types.ts +23 -0
  12. package/extensions/subagent/agent-runner.ts +90 -0
  13. package/extensions/subagent/agents.ts +31 -77
  14. package/extensions/subagent/handoffs.ts +273 -0
  15. package/extensions/subagent/index.ts +359 -581
  16. package/extensions/subagent/run-agent-args.ts +90 -0
  17. package/extensions/subagent/{delegate-executor.ts → spawn-utils.ts} +64 -87
  18. package/extensions/subagent/synthesis.ts +1 -51
  19. package/package.json +7 -10
  20. package/prompts/advisor.md +37 -0
  21. package/prompts/bug-prover.md +42 -0
  22. package/{agents → prompts}/docs-scout.md +2 -2
  23. package/prompts/manager.md +52 -0
  24. package/{agents → prompts}/planner.md +16 -1
  25. package/prompts/reviewer.md +93 -0
  26. package/{agents → prompts}/scout.md +5 -1
  27. package/prompts/validator.md +42 -0
  28. package/prompts/worker.md +61 -0
  29. package/skills/spawn-subagents/SKILL.md +80 -8
  30. package/skills/write-an-agent/SKILL.md +5 -5
  31. package/agents/reviewer.md +0 -37
  32. package/agents/worker.md +0 -26
  33. package/extensions/subagent/delegate-args.ts +0 -145
  34. package/extensions/subagent/delegate-types.ts +0 -62
  35. package/extensions/subagent/delegate-ui.ts +0 -132
  36. package/extensions/subagent/workflows.ts +0 -150
  37. package/prompts/implement-and-review.md +0 -10
  38. package/prompts/implement.md +0 -10
  39. package/prompts/scout-and-plan.md +0 -9
  40. /package/{agents → prompts}/ux-designer.md +0 -0
package/.fallowrc.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json",
3
+ "entry": [
4
+ "extensions/subagent/index.ts"
5
+ ]
6
+ }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @dreki-gg/pi-subagent
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`3a246f3`](https://github.com/dreki-gg/pi-extensions/commit/3a246f3fd55b900ebfcfbea2eff2a7ab9f9f94cf) Thanks [@jalbarrang](https://github.com/jalbarrang)! - Refactor agent distribution from custom `pi.agents` to standard `pi.prompts`
8
+
9
+ - Rename `agents/` directory to `prompts/` to follow pi's standard resource type
10
+ - Use `pi.prompts` in package.json instead of non-standard `pi.agents`
11
+ - Remove legacy bundled-directory fallback — agent prompts are now resolved via pi's package manager
12
+ - Remove `/delegate-agents` command (unused; `/run-agent` and `subagent` tool cover all usage)
13
+ - Extract shared spawn logic into `spawn-utils.ts`, eliminating cross-file duplication between `agent-runner.ts` and `index.ts`
14
+ - Remove dead exports (`formatAgentList`, `buildSynthesisPrompt`, `SYNTHESIS_INSTRUCTION`)
15
+ - Clean up unused imports
16
+ - Maintainability score improved from 70.7 (moderate) to 90.6 (good)
17
+ - Model configuration (`model`, `thinking`, `tools` frontmatter) is unchanged
18
+
19
+ ## 0.7.0
20
+
21
+ ### Minor Changes
22
+
23
+ - [`0be7b68`](https://github.com/dreki-gg/pi-extensions/commit/0be7b6877e9874b46c756b58c99d599db623ef11) Thanks [@jalbarrang](https://github.com/jalbarrang)! - Remove the `/delegate` command from `@dreki-gg/pi-subagent`.
24
+
25
+ - keep the `subagent` tool as the primary orchestration surface
26
+ - keep `/run-agent` for direct named-agent runs
27
+ - keep `/delegate-agents` for agent management
28
+ - update docs and the `spawn-subagents` skill to point rigid multi-step flows toward prompt templates and direct `subagent` chain/parallel usage instead of `/delegate`
29
+
30
+ ### Patch Changes
31
+
32
+ - [`0be7b68`](https://github.com/dreki-gg/pi-extensions/commit/0be7b6877e9874b46c756b58c99d599db623ef11) Thanks [@jalbarrang](https://github.com/jalbarrang)! - Migrate TypeBox usage and session replacement flows for Pi 0.69 compatibility.
33
+
34
+ - switch extension imports from `@sinclair/typebox` to `typebox`
35
+ - update package peer dependencies to require `typebox`
36
+ - move subagent `/run-agent` fork-at follow-up work into `withSession` so post-fork operations use the replacement session safely
37
+ - add command argument completions for `/run-agent`, `/delegate-agents`, `/preset`, `/mode`, and `/plan`
38
+ - align local development dependencies with Pi 0.69 for typechecking and compatibility checks
39
+
3
40
  ## 0.6.0
4
41
 
5
42
  ### Minor Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @dreki-gg/pi-subagent
2
2
 
3
- Subagent tool and delegate orchestration for pi — isolated agents, parallel scouts, planning gates, and workflow presets.
3
+ Subagent tool and direct agent runs for pi — isolated agents, parallel scouts, manager workflows, and bundled prompts.
4
4
 
5
5
  ## Install
6
6
 
@@ -18,99 +18,107 @@ The `subagent` tool supports three modes:
18
18
  | Parallel | `{ tasks: [...] }` — multiple agents concurrently |
19
19
  | Chain | `{ chain: [...] }` — sequential with `{previous}` placeholder |
20
20
 
21
+ Optional overrides:
22
+ - `model` — override the agent's default model for one run, or set a default for all tasks/steps in a call
23
+ - `thinking` — override the agent's default reasoning level for one run, or set a default for all tasks/steps in a call
24
+
25
+ Notes:
26
+ - `/run-agent` provides autocomplete for `--model` and `--thinking`
27
+ - the `subagent` tool supports the same fields in its schema, but this package does not currently add custom interactive autocomplete for tool-call JSON parameters
28
+
29
+ ## Opinionated Defaults
30
+
31
+ This package is intentionally opinionated about orchestration:
32
+
33
+ - Use **parallel mode for discovery, not competing edits**.
34
+ - Prefer **one worker** and surround it with scouts, planners, and reviewers.
35
+ - Use **chain mode** when work needs ordered handoffs.
36
+ - Treat `reviewer` as a **verifier with fresh context**, not as a second writer.
37
+ - Use `advisor` for **targeted second opinions** on tricky or high-risk cases, not as a default extra hop.
38
+ - Only split implementation across multiple workers when file ownership is clearly partitioned.
39
+
40
+ A good default mental model is: **parallel readers, single writer**.
41
+
42
+ See [`docs/orchestration-principles.md`](./docs/orchestration-principles.md) for the fuller guidance.
43
+
21
44
  ## Recommended Usage
22
45
 
23
46
  In day-to-day use, the main agent should usually call the `subagent` tool from normal conversation.
24
47
 
25
- Examples:
48
+ Safe defaults:
26
49
  - "spawn a scout for the auth code"
27
50
  - "run scout and docs-scout in parallel"
28
51
  - "have planner make a plan, then worker implement it"
29
52
  - "send this to reviewer"
53
+ - "ask advisor whether this migration should be split before sending it to worker"
54
+ - "use manager for this cross-package migration"
30
55
 
31
56
  For direct user-invoked single-agent runs, use:
32
57
 
33
58
  ```text
34
59
  /run-agent worker implement the auth flow we discussed
60
+ /run-agent --model anthropic/claude-opus-4-6 --thinking high reviewer review the latest diff
35
61
  ```
36
62
 
37
- `/delegate` is optional. It exists for rigid gated workflows, plan approval, and explicit workflow control.
63
+ Autocomplete notes:
64
+ - `/run-agent --model` suggests available configured models plus models referenced by discovered agents
65
+ - `/run-agent --thinking` suggests supported reasoning levels such as `off`, `minimal`, `low`, `medium`, `high`, and `xhigh`
38
66
 
39
- ## Optional Delegate Command
40
-
41
- After a design/grill session, or when you explicitly want a guided workflow:
42
-
43
- ```
44
- /delegate
45
- ```
46
-
47
- Or with an explicit task:
48
-
49
- ```
50
- /delegate implement the auth flow we designed
51
- ```
67
+ For reusable multi-step workflows, prefer the main agent calling the `subagent` tool directly in `single` / `parallel` / `chain` mode rather than relying on canned slash workflows.
52
68
 
53
- Use project-local repo agents:
54
-
55
- ```
56
- /delegate --scope project implement the subagent refactor
57
- ```
58
-
59
- Pin a workflow and skip the project-agent confirmation prompt:
69
+ Examples:
60
70
 
61
- ```
62
- /delegate --scope project --workflow implement --yes-project-agents improve delegate execution
71
+ ```text
72
+ spawn scout and docs-scout in parallel for auth session refresh
73
+ have worker implement the questionnaire validation fix
74
+ send this diff to reviewer, and if a claim needs proof use validator or bug-prover
75
+ ask advisor whether this migration should be split before implementation
76
+ use manager for this cross-package migration
63
77
  ```
64
78
 
65
- ### How it works
79
+ Recommended pattern in practice:
80
+ - `parallel`: `scout` + `docs-scout` for repo and docs recon
81
+ - `chain`: `scout` → `planner` → `worker` for coherent implementation
82
+ - `chain`: `worker` → `reviewer`, then optionally `validator` / `bug-prover`, then `worker` for a prove-before-fix loop
83
+ - `single`: `advisor` for a focused second opinion on a hard decision, failing test loop, or high-risk change
84
+ - `single`: `manager` for multi-slice work that needs bounded delegation and synthesis
66
85
 
67
- 1. **Synthesize** extracts goal, decisions, constraints, architecture, intent from conversation
68
- 2. **Confirm** — shows synthesis for approval
69
- 3. **Pick workflow** — suggests one, you confirm or override
70
- 4. **Execute** — runs phases sequentially with parallel scouts
71
- 5. **Plan gate** — shows planner output for approval before worker runs
72
- 6. **Summary** — full phase-by-phase report with usage totals
86
+ `advisor` and `manager` are higher-level entry points built on the same `single` / `parallel` / `chain` primitives. `advisor` is for capability routing and second opinions; `manager` is for coherent delegation, not arbitrary peer-to-peer swarms. `validator` and `bug-prover` support evidence-driven review: validate a claim first, then build the smallest repro only when needed.
73
87
 
74
88
  ## Direct Agent Runs
75
89
 
76
90
  Run one agent directly from the current session:
77
91
 
78
92
  ```text
79
- /run-agent [--scope user|project|both] [--yes-project-agents] <agent> [task]
93
+ /run-agent [--scope user|project|both] [--model <id>] [--thinking <level>] [--yes-project-agents] <agent> [task]
80
94
  ```
81
95
 
82
96
  Examples:
83
97
 
84
98
  ```text
85
99
  /run-agent scout trace how auth state is loaded
100
+ /run-agent validator validate whether this suspected regression is real
101
+ /run-agent bug-prover create a minimal failing repro for the auth refresh bug
102
+ /run-agent advisor sanity-check whether this migration should be split
103
+ /run-agent manager coordinate a multi-package migration plan
86
104
  /run-agent worker implement the refactor we just planned
87
105
  /run-agent --scope project reviewer review the latest changes
88
106
  ```
89
107
 
90
108
  If the chosen agent frontmatter sets `sessionStrategy: fork-at`, the command clones the current active path into a new session before running the agent. That keeps long implementation runs isolated in their own branch while preserving the original conversation.
91
109
 
92
- ### Delegate Flags
110
+ ### `run-agent` Flags
93
111
 
94
112
  | Flag | Meaning |
95
113
  |------|---------|
96
114
  | `--scope user|project|both` | Which agent layers to use. Default: `user` |
97
- | `--workflow <id>` | Skip the picker and force a workflow |
115
+ | `--model <id>` | Override the agent model for this run |
116
+ | `--thinking <level>` | Override the default reasoning level for this run |
98
117
  | `--yes-project-agents` | Disable the confirmation prompt for project-local agents |
99
118
 
100
- ### Workflows
101
-
102
- | Workflow | Phases |
103
- |----------|--------|
104
- | Scout only | scout ∥ docs-scout |
105
- | Scout and plan | scout ∥ docs-scout → planner |
106
- | Implement | scout ∥ docs-scout → planner → worker |
107
- | Implement and review | scout ∥ docs-scout → planner → worker → reviewer |
108
- | Quick fix | worker |
109
- | Review | reviewer |
110
-
111
119
  ## Agent Definitions
112
120
 
113
- Create agent files in `~/.pi/agent/agents/` or `.pi/agents/` as markdown with YAML frontmatter:
121
+ Create agent prompt files in `~/.pi/agent/prompts/` or `.pi/prompts/` as markdown with YAML frontmatter:
114
122
 
115
123
  ```markdown
116
124
  ---
@@ -128,36 +136,40 @@ System prompt for the agent.
128
136
 
129
137
  The package ships with these agents out of the box:
130
138
 
131
- - `scout` fast codebase recon
132
- - `docs-scout` — Context7-first documentation lookup
133
- - `planner` implementation planning
134
- - `worker` general-purpose implementation (`sessionStrategy: fork-at` by default)
135
- - `reviewer` code review (`sessionStrategy: fork-at` by default)
136
- - `ux-designer` frontend UI design
137
-
138
- Resolution order is: bundled user (`~/.pi/agent/agents/`) project (`.pi/agents/`). Project agents override user and bundled agents by name.
139
+ | Agent | Purpose | Default model | Default reasoning level |
140
+ |------|---------|---------------|-------------------------|
141
+ | `scout` | Fast codebase recon | `openai/gpt-5.4-mini` | `medium` |
142
+ | `docs-scout` | Context7-first documentation lookup | `openai/gpt-5.4-mini` | `medium` |
143
+ | `planner` | Implementation planning | `openai/gpt-5.4` | `high` |
144
+ | `worker` | General-purpose implementation | `openai/gpt-5.4` | `medium` |
145
+ | `reviewer` | Code review | `openai/gpt-5.4` | `medium` |
146
+ | `validator` | Validate or falsify a specific bug or behavior claim from code, tests, and commands | `openai/gpt-5.4` | `medium` |
147
+ | `bug-prover` | Create the smallest failing repro for a suspected bug | `openai/gpt-5.4` | `medium` |
148
+ | `advisor` | Focused second-opinion consult for tricky planning, implementation, or review decisions | `openai/gpt-5.4` | `medium` |
149
+ | `manager` | Bounded orchestration for multi-slice work | `openai/gpt-5.4` | `high` |
150
+ | `ux-designer` | Frontend UI design | `anthropic/claude-opus-4-6` | `medium` |
151
+
152
+ Notes:
153
+ - `worker`, `reviewer`, `bug-prover`, and `manager` default to `sessionStrategy: fork-at`.
154
+ - "Default reasoning level" maps to the frontmatter field `thinking` and can be overridden per run.
155
+
156
+ Resolution order is: bundled → user (`~/.pi/agent/prompts/`) → project (`.pi/prompts/`). Project agents override user and bundled agents by name.
139
157
 
140
158
  Optional frontmatter:
141
- - `thinking` — reasoning effort for the spawned pi process
159
+ - `thinking` — default reasoning effort for the spawned pi process
142
160
  - `sessionStrategy: fork-at` — when used with `/run-agent`, clone the current active branch into a new session before running
143
161
 
144
- > Note: pi now supports package-shipped agents via `pi.agents` (or conventional `agents/` directories). This package publishes its bundled agents that way, while user agents in `~/.pi/agent/agents/` and project agents in `.pi/agents/` still override them by name.
145
-
146
- ### Managing Agents
147
-
148
- ```
149
- /delegate-agents # list all agents with source
150
- /delegate-agents reset scout # restore bundled version
151
- /delegate-agents reset --all # restore all bundled versions
152
- /delegate-agents edit scout # copy bundled to user dir for customization
153
- ```
162
+ > Note: pi supports package-shipped prompts via `pi.prompts` (or conventional `prompts/` directories). This package publishes its bundled agent prompts that way, while user prompts in `~/.pi/agent/prompts/` and project prompts in `.pi/prompts/` still override them by name.
154
163
 
155
164
  ## Bundled Resources
156
165
 
157
166
  ### Skill
158
167
  - `spawn-subagents` — guides the model on when/how to spawn specialized subagents conversationally
159
168
 
160
- ### Prompt Templates
161
- - `/implement` scout planner worker
162
- - `/scout-and-plan` — scout → planner
163
- - `/implement-and-review` — worker → reviewer → worker
169
+ ### No Prompt Templates by Design
170
+ This package intentionally does **not** ship canned workflow prompts.
171
+
172
+ Prefer:
173
+ - normal conversation that leads the main agent to call `subagent`
174
+ - direct `/run-agent <agent> ...` for explicit single-agent runs
175
+ - examples in this README and `docs/orchestration-principles.md` for common orchestration shapes
@@ -0,0 +1,132 @@
1
+ # Orchestration Principles
2
+
3
+ `@dreki-gg/pi-subagent` is an opinionated orchestration package.
4
+
5
+ Its default operating model is simple: use extra agents to improve reconnaissance, planning, and review, while keeping implementation coherent under one writer unless ownership is clearly partitioned.
6
+
7
+ ## Default philosophy
8
+
9
+ - Prefer **one writer, many thinkers**.
10
+ - Use **parallel mode for discovery**, not for competing edits.
11
+ - Use **chain mode for safe sequential handoffs** between scout, planner, worker, and reviewer.
12
+ - Treat `reviewer` as a **fresh-context verifier**, not as a second implementation agent.
13
+ - Reach for subagents to reduce context rot and sharpen conclusions, not to create an arbitrary swarm.
14
+
15
+ ## When to use each mode
16
+
17
+ ### `single`
18
+
19
+ Use `single` when one specialist can do the job.
20
+
21
+ Good fits:
22
+ - `scout` tracing a code path
23
+ - `docs-scout` checking framework or library docs
24
+ - `planner` producing a focused implementation plan
25
+ - `worker` implementing a bounded change
26
+ - `reviewer` performing a focused review
27
+ - `validator` confirming or falsifying a specific bug claim
28
+ - `bug-prover` creating a minimal failing repro when proof needs a new artifact
29
+
30
+ ### `parallel`
31
+
32
+ Use `parallel` when tasks are read-heavy, independent, and easy to synthesize.
33
+
34
+ Good fits:
35
+ - `scout` + `docs-scout` gathering code and docs context at the same time
36
+ - two scouts inspecting different subsystems
37
+ - multiple reviewers checking different bounded concerns
38
+
39
+ Avoid `parallel` when two agents would edit the same files, make overlapping design decisions, or race to implement the same slice.
40
+
41
+ ### `chain`
42
+
43
+ Use `chain` when a task benefits from ordered handoffs.
44
+
45
+ Good fits:
46
+ - discovery before planning
47
+ - planning before implementation
48
+ - implementation before review
49
+ - review findings before a final fix pass
50
+
51
+ Prefer compact handoffs and summaries over long transcript dumps.
52
+
53
+ ## Recommended workflows
54
+
55
+ ### Scout → planner → worker
56
+
57
+ Use this when the task is unclear or spans multiple files.
58
+
59
+ - `scout` identifies relevant code, constraints, and touched files
60
+ - `planner` turns that into a concrete implementation path
61
+ - `worker` executes with a coherent plan
62
+
63
+ ### Worker → reviewer → validator / bug-prover → worker
64
+
65
+ Use this when you want fresh-context verification before returning a result and some review claims need proof.
66
+
67
+ - `worker` makes the change
68
+ - `reviewer` checks the diff and code with a fresh lens
69
+ - `validator` confirms uncertain claims from commands, existing tests, and code
70
+ - `bug-prover` creates the smallest failing repro only when proof needs a new artifact
71
+ - `worker` applies concrete, scoped fixes after claims are evidenced
72
+
73
+ ### Scout + docs-scout in parallel
74
+
75
+ Use this when both repository context and external documentation matter.
76
+
77
+ - `scout` inspects the local codebase
78
+ - `docs-scout` checks framework, library, or API docs
79
+ - the main thread synthesizes both into one next action
80
+
81
+ ## Non-goals
82
+
83
+ This package is not trying to optimize for:
84
+
85
+ - arbitrary agent swarms
86
+ - multi-writer editing without clear file ownership
87
+ - speculative parallel implementations of the same task
88
+ - using subagents as a substitute for coherent architecture decisions
89
+ - pushing raw agent logs back into the main thread as the primary artifact
90
+
91
+ ## Examples
92
+
93
+ ### Single specialist
94
+
95
+ ```text
96
+ /run-agent scout trace how auth state is loaded
97
+ ```
98
+
99
+ ### Parallel recon
100
+
101
+ ```ts
102
+ subagent({
103
+ tasks: [
104
+ { agent: "scout", task: "Trace how auth state is loaded" },
105
+ { agent: "docs-scout", task: "Check the latest auth library session refresh docs" },
106
+ ],
107
+ })
108
+ ```
109
+
110
+ ### Plan then implement
111
+
112
+ ```ts
113
+ subagent({
114
+ chain: [
115
+ { agent: "scout", task: "Find all code relevant to auth session refresh" },
116
+ { agent: "planner", task: "Create an implementation plan for auth session refresh using {previous} as the handoff" },
117
+ { agent: "worker", task: "Implement the auth session refresh plan from {previous}" },
118
+ ],
119
+ })
120
+ ```
121
+
122
+ ### Implement and review
123
+
124
+ ```ts
125
+ subagent({
126
+ chain: [
127
+ { agent: "worker", task: "Implement questionnaire validation improvements" },
128
+ { agent: "reviewer", task: "Review the diff using {previous} as a compact handoff" },
129
+ { agent: "worker", task: "Address concrete findings from {previous}" },
130
+ ],
131
+ })
132
+ ```