@tduyng/pi-subagent 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -43
- package/agents/scout.md +43 -0
- package/package.json +3 -2
- package/src/subagent/agent.ts +9 -1
- package/src/subagent/index.ts +1 -1
package/README.md
CHANGED
|
@@ -1,68 +1,100 @@
|
|
|
1
1
|
# @tduyng/pi-subagent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A subagent that stays small on purpose. It reads docs, logs, and source with a cheap model, returns one answer, and none of that reading lands in your context.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## What it costs
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
session. At most `MAX_CONCURRENT` children run at once. Each child runs on the
|
|
9
|
-
current model unless a task, profile, or `subagent.json` override changes it.
|
|
10
|
-
The child sees the task prompt, does the work, and returns one message. The
|
|
11
|
-
parent never carries the child's exploration.
|
|
7
|
+
One tool, `subagent`, at 379 tokens a request. The bulk-read guard and the log reducer are event handlers, so they add no schema and no prompt text.
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
short sourced summaries. Omitting `agent` selects `scout`. It is the cheap
|
|
15
|
-
default for I/O-heavy work. `subagent.json` supplies its low-cost model.
|
|
9
|
+
The child is a separate session with its own context that dies with the task. A parent that would have carried 40 KB of file dumps carries one paragraph and a file list instead, and every later turn of the parent pays for the paragraph rather than the dumps.
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
after an artifact exists and the task explicitly asks for verification or
|
|
19
|
-
review. Keep ordinary implementation, debugging, design, builds, tests, and lint
|
|
20
|
-
in the parent session.
|
|
11
|
+
## What it is for
|
|
21
12
|
|
|
22
|
-
|
|
13
|
+
Not parallel implementation. Fanning four edit-capable children out over one change costs more than doing it in the parent: every child builds its own system prompt and tool list, and their edits still have to be reconciled.
|
|
23
14
|
|
|
24
|
-
|
|
15
|
+
The cheap and safe case is reading: search twenty files, trace one call path, read a build log, summarize a doc. That is where a session spends its turns and its tokens, and it is the work a cheap model does as well as a frontier one.
|
|
25
16
|
|
|
26
|
-
|
|
17
|
+
```text
|
|
18
|
+
subagent(task: "Which files construct the retry policy? Return path:line for each.",
|
|
19
|
+
agent: "scout")
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Scout ships with it
|
|
23
|
+
|
|
24
|
+
`agents/scout.md` is bundled, so `agent: "scout"` works with no setup and no profile of your own. The default when you omit `agent` is scout, so the cheap read-only child is what you get by typing less.
|
|
25
|
+
|
|
26
|
+
Scout carries `tools: read, grep, find, ls`, `inheritSkills: false`, and `thinking: low`. It never edits, never runs a command, never reaches the network, and answers in a fixed `STATUS / FINDING / NEXT` shape with file:line evidence.
|
|
27
|
+
|
|
28
|
+
Override it by dropping your own copy in `~/.pi/agent/agents/scout.md` or `.pi/agents/scout.md`. A project file shadows a user file, and both shadow the bundled one. Copy the [bundled profile](agents/scout.md) as the starting point.
|
|
29
|
+
|
|
30
|
+
## Point the child at a cheap model
|
|
31
|
+
|
|
32
|
+
The child inherits the parent's model unless you say otherwise, and inheriting defeats the point. Set it once:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"model": "claude/claude-haiku-5-5",
|
|
37
|
+
"thinking": "low"
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`~/.pi/agent/subagent.json` sets the default, `.pi/subagent.json` overrides either field per project. Both fields are optional. `thinking` is one of `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`, default `medium`. A `model` on the profile wins over the file.
|
|
42
|
+
|
|
43
|
+
## Tasks
|
|
44
|
+
|
|
45
|
+
The `subagent` tool takes one task or up to 8, with at most 4 running at once. Each child sees one prompt and returns one message.
|
|
46
|
+
|
|
47
|
+
| Field | Meaning |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `task` | What the child does |
|
|
50
|
+
| `agent` | Profile name, `scout` by default |
|
|
51
|
+
| `cwd` | Working directory for the child |
|
|
52
|
+
| `isolation` | `worktree` to give the child its own git checkout |
|
|
53
|
+
| `schema` | Ask for structured output |
|
|
54
|
+
| `context` | `fork` to replay the parent's history into the child |
|
|
55
|
+
| `resume` | Task id, or `all`, to continue a stopped child |
|
|
27
56
|
|
|
28
|
-
|
|
57
|
+
`label`, `thinking`, `model`, `timeoutMs`, and `maxTurns` are profile policy rather than model choices. A scripted caller can still pass them, and they still work.
|
|
58
|
+
|
|
59
|
+
### Resume instead of re-reading
|
|
60
|
+
|
|
61
|
+
A child that hits its turn budget is told to wrap up and gets a fresh budget in the same session, so a cap never turns work into a failure. If it still stops early its last text comes back marked `[partial answer]`, and salvage walks the whole transcript for it, so a child stopped mid tool-burst still returns what it wrote.
|
|
62
|
+
|
|
63
|
+
Every failed task prints a `resume:` id. Pass it back to continue where the child stopped instead of paying for the investigation again. An optional `task` alongside `resume` steers the continuation. Failed sessions are kept 30 minutes, completed ones 5.
|
|
64
|
+
|
|
65
|
+
A deadline is reported as a timeout, not a cancellation: pi keeps any final text produced before it and marks it partial.
|
|
66
|
+
|
|
67
|
+
Every run also writes `run.json` under `<agent-dir>/subagents/<session-id>/<run-id>/` with the task prompt, model, tools, and the path to each child session, rewritten after each transition. Reopening the session reads it back: a child interrupted less than ten minutes ago is resumed from its saved session and its answer arrives as a `subagent-durable` message, and older interruptions are listed with their resume ids. `resume` therefore works after a restart, not only inside the process that started the child.
|
|
29
68
|
|
|
30
69
|
### Worktree isolation
|
|
31
70
|
|
|
32
|
-
With `isolation: "worktree"
|
|
71
|
+
With `isolation: "worktree"` each child runs in its own git worktree on a branch named `pi-task-<id>`, so concurrent children never edit the same checkout and a commit the child makes outlives it. The result names the branch. This is also the answer to two sessions committing in one repo, which no path reservation can cover.
|
|
33
72
|
|
|
34
73
|
### Structured output
|
|
35
74
|
|
|
36
|
-
Pass `schema` to ask the child to call
|
|
75
|
+
Pass `schema` to ask the child to call `structured_output` exactly once. The parsed payload comes back in the task result. A child that finishes without calling it is re-prompted in the same session up to three times, so the investigation is not paid for twice. If it still refuses, the text answer stands and the task completes marked partial. If a provider rejects the schema tool, the extension removes it and retries once as plain text.
|
|
37
76
|
|
|
38
77
|
### Fork context
|
|
39
78
|
|
|
40
|
-
|
|
79
|
+
`context: "fork"` replays the parent's conversation history into the child as context entries.
|
|
41
80
|
|
|
42
|
-
##
|
|
81
|
+
## Profiles
|
|
43
82
|
|
|
44
|
-
|
|
83
|
+
A profile is a markdown file with YAML frontmatter in `~/.pi/agent/agents/`, in `.pi/agents/`, or bundled. It sets the tool list, model, thinking level, limits, and an optional color for the widget, plus `inheritProjectContext` and `inheritSkills` to decide what the child picks up from the parent, and `systemPromptMode: replace` to swap the default system prompt instead of appending to it.
|
|
45
84
|
|
|
46
|
-
|
|
85
|
+
`/agents` lists them. The `subagent` widget shows up to 8 running and recently finished children with a status summary line: Down and Up to move, Enter to open a live transcript, d or x to dismiss.
|
|
47
86
|
|
|
48
|
-
|
|
87
|
+
Children cannot spawn their own subagents.
|
|
49
88
|
|
|
50
|
-
##
|
|
89
|
+
## Bulk-read guard
|
|
90
|
+
|
|
91
|
+
A read of a file above `BULK_READ_MIN_LINES` lines (default 350) is blocked, and so is `cat`, `less`, or `more` that would dump a large file. The block names `outline` first, so the model fetches a map of declarations rather than the text.
|
|
51
92
|
|
|
52
|
-
|
|
93
|
+
The second call for the same path passes through, so the file stays reachable and a model with a reason to read it can. A read passes when it returns fewer lines than the threshold, whether from a `limit`, an `offset`, a small file, or `head` and `tail` on their 10-line default, and so does a piped command.
|
|
53
94
|
|
|
54
|
-
##
|
|
95
|
+
## Log reducer
|
|
55
96
|
|
|
56
|
-
|
|
57
|
-
- `verifier` is reserved for explicit verification of an existing artifact. It may write only its verification report, never implementation files.
|
|
58
|
-
- Ordinary implementation, debugging, design, builds, tests, and lint stay in the parent session.
|
|
59
|
-
- The tool rejects concurrent write-capable tasks. Read-only scouts may still run in parallel. A call whose task texts normalize to the same request is rejected, so one question does not get paid for twice.
|
|
60
|
-
- Children see one prompt and return one message. No sequential pipelines.
|
|
61
|
-
- Children cannot spawn their own subagents. No grandchildren.
|
|
62
|
-
- The `subagent` tool schema is present on every turn, and it lists only the fields a model sets: `task`, `agent`, `cwd`, `isolation`, `schema`, `context`, and `resume`. `label`, `thinking`, `model`, `timeoutMs`, and `maxTurns` are profile policy. They still work when a scripted caller passes them, and three of them already resolved to the profile before the split.
|
|
63
|
-
- The `subagent` tool schema is present on every turn. The `bulk-read` and `log-reducer` extensions add no tool schemas. They run as event handlers. The registry holds at most 50 tasks. The widget shows at most 8 rows. The `touched` file list per task is capped at 12 entries. Progress updates emit at most once every 250ms.
|
|
64
|
-
- Child deadlines default to 30 minutes. A shorter `timeoutMs` or profile `maxExecutionTimeMs` is raised to 30 minutes, while longer values pass through. A profile deadline beyond the 32-bit setTimeout ceiling (2,147,483,647 ms) clamps to the ceiling. Node would round a larger delay down to 1 ms and kill the child instantly, so the clamp degrades a bad value to a very long deadline.
|
|
65
|
-
- Children inherit the parent's model by default. Thinking does not inherit: it resolves from the task's `thinking`, then the profile, then `subagent.json`, then `medium`.
|
|
97
|
+
A build or test log above 4,096 bytes, from a diagnostic command pattern, is replaced with a short receipt of quoted lines. Every quote is verified byte for byte against the archived original, and if validation fails the full log reaches the model untouched. The reducer runs on `tool_result`, so the swap happens before the result enters history, and the raw log is archived next to the session.
|
|
66
98
|
|
|
67
99
|
## Install
|
|
68
100
|
|
|
@@ -74,8 +106,13 @@ Local checkout: `pi install /path/to/dotfiles/pi/agent/extensions/pi-subagent`
|
|
|
74
106
|
|
|
75
107
|
## Configure
|
|
76
108
|
|
|
77
|
-
- `subagent.json` in the agent dir
|
|
78
|
-
- `BULK_READ=0` disables the
|
|
79
|
-
- `PI_LOG_REDUCER=0` disables the
|
|
80
|
-
|
|
81
|
-
|
|
109
|
+
- `subagent.json` in the agent dir sets the child model and thinking. Shape: `{ "model": "provider/model-id", "thinking": "medium" }`, both optional.
|
|
110
|
+
- `BULK_READ=0` disables the guard. `BULK_READ_MIN_LINES` sets the line threshold.
|
|
111
|
+
- `PI_LOG_REDUCER=0` disables the reducer. `PI_LOG_REDUCER_TIMEOUT_MS` sets its deadline, default 15 seconds, maximum 60.
|
|
112
|
+
|
|
113
|
+
## Design notes
|
|
114
|
+
|
|
115
|
+
- Child deadlines default to 30 minutes. A shorter `timeoutMs` or profile `maxExecutionTimeMs` is raised to it, and longer values pass through. A profile deadline past the 32-bit setTimeout ceiling clamps to the ceiling, because Node rounds a larger delay down to 1 ms and would kill the child instantly.
|
|
116
|
+
- Child thinking resolves from the task, then the profile, then `subagent.json`, then `medium`. It does not inherit the parent's.
|
|
117
|
+
- Read-only scouts run in parallel. A write-capable child is never run alongside another one, and a call whose tasks normalize to the same request is refused.
|
|
118
|
+
- The registry holds at most 50 tasks, the widget 8 rows, the `touched` list per task 12 entries, and progress updates emit at most every 250ms.
|
package/agents/scout.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: scout
|
|
3
|
+
description: Cheap read-only I/O and analysis agent. Searches files and docs, traces code, answers one bounded question, and returns a short sourced summary. Never edits, writes, runs commands, or reaches the internet.
|
|
4
|
+
tools: read, grep, find, ls
|
|
5
|
+
inheritSkills: false
|
|
6
|
+
thinking: low
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
You are a SCOUT, a cheap read-only I/O and analysis subagent. The caller hands
|
|
10
|
+
you exactly one bounded question in a fresh context. Answer it from what is on
|
|
11
|
+
disk and return a short, sourced answer. You change nothing.
|
|
12
|
+
|
|
13
|
+
Use this profile for file and document search, code tracing, comparison, and
|
|
14
|
+
summarization. If the task asks you to implement, edit, run a check, or
|
|
15
|
+
make a design decision, return that the parent must handle it.
|
|
16
|
+
|
|
17
|
+
Rules:
|
|
18
|
+
|
|
19
|
+
- Read only what the question needs. Use `grep` and `find` to locate, then read
|
|
20
|
+
the specific range. Never read a whole file to answer a narrow question.
|
|
21
|
+
- Prefer file paths, line numbers, exact text, and literal command output over
|
|
22
|
+
general impressions. A summary is useful only when its evidence is included.
|
|
23
|
+
- Answer with evidence: file paths with line numbers, exact text you found, or
|
|
24
|
+
the literal output you observed. No paraphrase of code you did not read.
|
|
25
|
+
- A negative result is a real result. If the answer is not on disk, say what you
|
|
26
|
+
searched and what you ruled out.
|
|
27
|
+
- You have no write, edit, bash, or web tools. Do not ask for them, and do not
|
|
28
|
+
propose patches. Name the gap instead. A task that needs those capabilities
|
|
29
|
+
belongs in the parent session. A question about the
|
|
30
|
+
internet cannot be answered by you at all: say so in one line under NEXT and
|
|
31
|
+
stop, rather than searching the disk for a substitute.
|
|
32
|
+
- Spend your turns on the search that answers the question, and when you are
|
|
33
|
+
told to wrap up, answer with what you have and say what is still unchecked
|
|
34
|
+
under NEXT.
|
|
35
|
+
|
|
36
|
+
Reply with exactly this, and nothing else:
|
|
37
|
+
|
|
38
|
+
STATUS: solved|continue
|
|
39
|
+
FINDING: <the answer, with file:line evidence, at most five lines>
|
|
40
|
+
NEXT: <up to three bullets, or "none">
|
|
41
|
+
|
|
42
|
+
When a `structured_output` tool is available, call it once with the same
|
|
43
|
+
STATUS, FINDING, and NEXT content as its fields, and write no text after it.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tduyng/pi-subagent",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Cheap delegation: a child session reads docs, logs, and source, returns one answer, and its context is thrown away. Scout profile bundled.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi",
|
|
7
7
|
"pi-package",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"src",
|
|
27
27
|
"!src/**/*.test.ts",
|
|
28
|
+
"agents",
|
|
28
29
|
"README.md",
|
|
29
30
|
"LICENSE"
|
|
30
31
|
],
|
package/src/subagent/agent.ts
CHANGED
|
@@ -101,8 +101,16 @@ export function loadAgentsFrom(dirs: string[]): Map<string, AgentProfile> {
|
|
|
101
101
|
return agents
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
const BUNDLED_AGENTS = path.join(import.meta.dirname, '..', '..', 'agents')
|
|
105
|
+
|
|
106
|
+
// The default `agent` is scout, so a checkout with no profile on disk would refuse every
|
|
107
|
+
// delegation that omits it. The bundled profile is the floor, not an override.
|
|
104
108
|
export function loadAgents(cwd: string): Map<string, AgentProfile> {
|
|
105
|
-
|
|
109
|
+
const agents = loadAgentsFrom(agentDirs(cwd))
|
|
110
|
+
for (const [name, profile] of loadAgentsFrom([BUNDLED_AGENTS])) {
|
|
111
|
+
if (!agents.has(name)) agents.set(name, profile)
|
|
112
|
+
}
|
|
113
|
+
return agents
|
|
106
114
|
}
|
|
107
115
|
|
|
108
116
|
export function parseModelName(name: string): { provider: string; id: string } | undefined {
|
package/src/subagent/index.ts
CHANGED
|
@@ -69,7 +69,7 @@ import {
|
|
|
69
69
|
} from './types.js'
|
|
70
70
|
import { SubagentViewer, widgetLines } from './viewer.js'
|
|
71
71
|
|
|
72
|
-
export { parseFrontmatter, loadAgentsFrom, parseModelName } from './agent.js'
|
|
72
|
+
export { parseFrontmatter, loadAgents, loadAgentsFrom, parseModelName } from './agent.js'
|
|
73
73
|
|
|
74
74
|
const MAX_FORK_CONTEXT_CHARS = 120_000
|
|
75
75
|
const RUN_SAVE_INTERVAL_MS = 5_000
|