@dreki-gg/pi-subagent 0.9.1 → 0.9.2
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/CHANGELOG.md +6 -0
- package/extensions/subagent/create-agent.ts +6 -11
- package/extensions/subagent/handoffs.ts +17 -4
- package/extensions/subagent/list-agents.ts +7 -9
- package/extensions/subagent/run-agent-args.ts +6 -4
- package/extensions/subagent/spawn-utils.ts +13 -6
- package/package.json +1 -1
- package/prompts/planner.md +4 -8
- package/prompts/reviewer.md +4 -19
- package/prompts/worker.md +4 -8
- package/skills/write-an-agent/SKILL.md +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @dreki-gg/pi-subagent
|
|
2
2
|
|
|
3
|
+
## 0.9.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Tighten subagent prompts and the write-an-agent skill. The skill gains a "Prompt hygiene (anti-rot)" section (invariants over incidents, one owner per fact, every line must change behavior) plus matching review-checklist items, and the reviewer/worker/planner prompts state the consult handoff shape once instead of in three duplicated blocks. No behavior change.
|
|
8
|
+
|
|
3
9
|
## 0.9.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -58,10 +58,7 @@ export function registerCreateAgentCommand(pi: ExtensionAPI) {
|
|
|
58
58
|
const filePath = path.join(promptsDir, `${name}.md`);
|
|
59
59
|
|
|
60
60
|
if (fs.existsSync(filePath)) {
|
|
61
|
-
ctx.ui.notify(
|
|
62
|
-
`Agent "${name}" already exists at ${filePath}`,
|
|
63
|
-
'warning',
|
|
64
|
-
);
|
|
61
|
+
ctx.ui.notify(`Agent "${name}" already exists at ${filePath}`, 'warning');
|
|
65
62
|
return;
|
|
66
63
|
}
|
|
67
64
|
|
|
@@ -69,16 +66,14 @@ export function registerCreateAgentCommand(pi: ExtensionAPI) {
|
|
|
69
66
|
fs.mkdirSync(promptsDir, { recursive: true });
|
|
70
67
|
|
|
71
68
|
// Write the template
|
|
72
|
-
const content = TEMPLATE
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
const content = TEMPLATE.replace(/\{\{name\}\}/g, name).replace(
|
|
70
|
+
/\{\{description\}\}/g,
|
|
71
|
+
description,
|
|
72
|
+
);
|
|
75
73
|
|
|
76
74
|
fs.writeFileSync(filePath, content, 'utf-8');
|
|
77
75
|
|
|
78
|
-
ctx.ui.notify(
|
|
79
|
-
`Created agent "${name}" at ${path.relative(ctx.cwd, filePath)}`,
|
|
80
|
-
'info',
|
|
81
|
-
);
|
|
76
|
+
ctx.ui.notify(`Created agent "${name}" at ${path.relative(ctx.cwd, filePath)}`, 'info');
|
|
82
77
|
|
|
83
78
|
// Send a follow-up so the LLM can help refine the prompt
|
|
84
79
|
pi.sendUserMessage(
|
|
@@ -39,11 +39,19 @@ interface SectionEntry {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function normalizeWhitespace(value: string): string {
|
|
42
|
-
return value
|
|
42
|
+
return value
|
|
43
|
+
.replace(/\r/g, '')
|
|
44
|
+
.replace(/[ \t]+/g, ' ')
|
|
45
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
46
|
+
.trim();
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
function normalizeSectionTitle(title: string): string {
|
|
46
|
-
return title
|
|
50
|
+
return title
|
|
51
|
+
.trim()
|
|
52
|
+
.toLowerCase()
|
|
53
|
+
.replace(/[\s/]+/g, ' ')
|
|
54
|
+
.replace(/[():]/g, '');
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
function splitMarkdownSections(markdown: string): { preamble: string; sections: SectionEntry[] } {
|
|
@@ -141,7 +149,10 @@ function extractPaths(text: string): HandoffFileRef[] {
|
|
|
141
149
|
const files: HandoffFileRef[] = [];
|
|
142
150
|
|
|
143
151
|
const addPath = (rawPath: string, notes?: string) => {
|
|
144
|
-
const path = rawPath
|
|
152
|
+
const path = rawPath
|
|
153
|
+
.trim()
|
|
154
|
+
.replace(/^`|`$/g, '')
|
|
155
|
+
.replace(/[),.:;]+$/g, '');
|
|
145
156
|
if (!path.includes('/')) return;
|
|
146
157
|
if (path.startsWith('http://') || path.startsWith('https://')) return;
|
|
147
158
|
if (seen.has(path)) return;
|
|
@@ -203,7 +214,9 @@ export function buildHandoffFromResult(input: {
|
|
|
203
214
|
const riskItems = uniq(extractListItems(getFirstSectionBody(sections, ['Risks'])));
|
|
204
215
|
const openQuestions = uniq([
|
|
205
216
|
...extractListItems(getFirstSectionBody(sections, ['Open Questions'])),
|
|
206
|
-
...toQuestions(
|
|
217
|
+
...toQuestions(
|
|
218
|
+
extractListItems(getFirstSectionBody(sections, ['Notes', 'Constraints or Unknowns'])),
|
|
219
|
+
),
|
|
207
220
|
]);
|
|
208
221
|
const goal =
|
|
209
222
|
extractParagraph(getFirstSectionBody(sections, ['Goal'])) ??
|
|
@@ -37,11 +37,12 @@ export function registerListAgentsTool(
|
|
|
37
37
|
const discovery = discoverAgents(ctx.cwd, agentScope, resolvedPaths);
|
|
38
38
|
|
|
39
39
|
if (discovery.agents.length === 0) {
|
|
40
|
-
const dirs =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
const dirs =
|
|
41
|
+
agentScope === 'user'
|
|
42
|
+
? '~/.pi/agent/prompts'
|
|
43
|
+
: agentScope === 'project'
|
|
44
|
+
? '.pi/prompts'
|
|
45
|
+
: '~/.pi/agent/prompts and .pi/prompts';
|
|
45
46
|
return {
|
|
46
47
|
content: [
|
|
47
48
|
{
|
|
@@ -53,10 +54,7 @@ export function registerListAgentsTool(
|
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
const lines: string[] = [
|
|
57
|
-
`Available agents (scope: ${agentScope}):`,
|
|
58
|
-
'',
|
|
59
|
-
];
|
|
57
|
+
const lines: string[] = [`Available agents (scope: ${agentScope}):`, ''];
|
|
60
58
|
|
|
61
59
|
for (const agent of discovery.agents) {
|
|
62
60
|
lines.push(`### ${agent.name}`);
|
|
@@ -10,16 +10,18 @@ export interface RunAgentCommandOptions {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
function tokenize(input: string): string[] {
|
|
13
|
-
return
|
|
13
|
+
return (
|
|
14
|
+
input.match(/"[^"]*"|'[^']*'|\S+/g)?.map((token) => token.replace(/^['"]|['"]$/g, '')) ?? []
|
|
15
|
+
);
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export function formatRunAgentUsage(): string {
|
|
17
19
|
return 'Usage: /run-agent [--scope user|project|both] [--model <id>] [--thinking <level>] [--yes-project-agents] <agent> [task]';
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
export function parseRunAgentArgs(
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
export function parseRunAgentArgs(
|
|
23
|
+
rawArgs?: string,
|
|
24
|
+
): { ok: true; options: RunAgentCommandOptions } | { ok: false; error: string } {
|
|
23
25
|
const tokens = tokenize(rawArgs?.trim() ?? '');
|
|
24
26
|
const taskTokens: string[] = [];
|
|
25
27
|
|
|
@@ -49,12 +49,19 @@ async function writePromptToTempFile(
|
|
|
49
49
|
return { dir: tmpDir, filePath };
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function cleanupTempFiles(
|
|
53
|
-
tmpPromptPath
|
|
54
|
-
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
function cleanupTempFiles(tmpPromptPath: string | null, tmpPromptDir: string | null): void {
|
|
53
|
+
if (tmpPromptPath)
|
|
54
|
+
try {
|
|
55
|
+
fs.unlinkSync(tmpPromptPath);
|
|
56
|
+
} catch {
|
|
57
|
+
/* ignore */
|
|
58
|
+
}
|
|
59
|
+
if (tmpPromptDir)
|
|
60
|
+
try {
|
|
61
|
+
fs.rmdirSync(tmpPromptDir);
|
|
62
|
+
} catch {
|
|
63
|
+
/* ignore */
|
|
64
|
+
}
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
export interface ToolExecutionStartEvent {
|
package/package.json
CHANGED
package/prompts/planner.md
CHANGED
|
@@ -12,14 +12,10 @@ You must NOT make any changes. Only read, analyze, and plan.
|
|
|
12
12
|
|
|
13
13
|
If the task has multiple viable designs, unclear ownership boundaries, or needs sharper decomposition before implementation, you may consult the `advisor` agent with the `subagent` tool.
|
|
14
14
|
|
|
15
|
-
When consulting `advisor`, send only:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- the smallest relevant task summary
|
|
20
|
-
- what constraints or trade-offs you already see
|
|
21
|
-
|
|
22
|
-
Treat `advisor` as a focused second opinion. You still own the plan.
|
|
15
|
+
When consulting `advisor`, send only: your role (`planner`), the exact
|
|
16
|
+
design or decomposition question, the implicated files/packages, the
|
|
17
|
+
smallest relevant task summary, and the constraints or trade-offs you
|
|
18
|
+
already see. Treat it as a focused second opinion — you still own the plan.
|
|
23
19
|
|
|
24
20
|
Input format you'll receive:
|
|
25
21
|
- Context/findings from a scout agent
|
package/prompts/reviewer.md
CHANGED
|
@@ -30,25 +30,10 @@ Rules:
|
|
|
30
30
|
8. Use `advisor` only when severity, intended behavior, or trade-offs remain unclear after inspection and validation.
|
|
31
31
|
9. You still own the final review judgment. Support agents inform your conclusion; they do not replace it.
|
|
32
32
|
|
|
33
|
-
When consulting
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
-
|
|
37
|
-
- the smallest relevant goal summary
|
|
38
|
-
- what you already verified from diff/code
|
|
39
|
-
|
|
40
|
-
When consulting `bug-prover`, send only:
|
|
41
|
-
- current role: `reviewer`
|
|
42
|
-
- the exact claim that now needs a minimal repro
|
|
43
|
-
- files, symbols, tests, or commands already inspected
|
|
44
|
-
- why read-only validation was insufficient
|
|
45
|
-
|
|
46
|
-
When consulting `advisor`, send only:
|
|
47
|
-
- current role: `reviewer`
|
|
48
|
-
- the exact uncertainty or severity question
|
|
49
|
-
- changed files or symbols involved
|
|
50
|
-
- the smallest relevant goal summary
|
|
51
|
-
- what you verified or could not verify from diff/code
|
|
33
|
+
When consulting any support agent, send only: your role (`reviewer`), the
|
|
34
|
+
exact claim or question, the files/symbols involved, the smallest relevant
|
|
35
|
+
goal summary, and what you already verified from diff/code. For
|
|
36
|
+
`bug-prover`, add why read-only validation was insufficient.
|
|
52
37
|
|
|
53
38
|
Strategy:
|
|
54
39
|
1. Inspect the diff and understand the reason for the change
|
package/prompts/worker.md
CHANGED
|
@@ -12,14 +12,10 @@ Work autonomously to complete the assigned task. Use all available tools as need
|
|
|
12
12
|
|
|
13
13
|
If a focused second opinion would reduce risk, you may consult the `advisor` agent with the `subagent` tool. Reserve that for ambiguous architecture tradeoffs, persistent failing tests or unexplained errors, merge conflicts or tangled diffs, and security-sensitive or migration-heavy changes.
|
|
14
14
|
|
|
15
|
-
When consulting `advisor`, send only:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- the smallest relevant task summary
|
|
20
|
-
- what you already tried or observed
|
|
21
|
-
|
|
22
|
-
Treat `advisor` as a second opinion, not a replacement owner. You stay responsible for implementation and the final result.
|
|
15
|
+
When consulting `advisor`, send only: your role (`worker`), the exact
|
|
16
|
+
question, the touched files/symbols, the smallest relevant task summary,
|
|
17
|
+
and what you already tried or observed. Treat it as a second opinion, not a
|
|
18
|
+
replacement owner — you stay responsible for the final result.
|
|
23
19
|
|
|
24
20
|
Keep the final response compact. It should function as a review packet for downstream agents, not a long implementation diary.
|
|
25
21
|
|
|
@@ -59,9 +59,33 @@ Output:
|
|
|
59
59
|
- Prefer local pi docs before external docs when writing `docs-scout`.
|
|
60
60
|
- Mention validation commands in planner/worker/reviewer when package behavior changes.
|
|
61
61
|
|
|
62
|
+
## Prompt hygiene (anti-rot)
|
|
63
|
+
|
|
64
|
+
Prompts are code: unmaintained instructions become technical debt. Apply the
|
|
65
|
+
same doctrine a project applies to its AGENTS.md — durable facts and
|
|
66
|
+
invariants, not narration.
|
|
67
|
+
|
|
68
|
+
- **Invariants, not incidents.** A rule earned from a field bug must state
|
|
69
|
+
the durable invariant, never the story ("fixes relocate gaps more often
|
|
70
|
+
than they close them" — not "remember that PR"). References to tools,
|
|
71
|
+
tickets, or model quirks of the moment rot first.
|
|
72
|
+
- **One owner per fact.** Anything that drifts (model ids, tool lists,
|
|
73
|
+
paths) lives in frontmatter or arrives in the caller's task — never
|
|
74
|
+
restated in the body. A block repeated across prompts is the same fact
|
|
75
|
+
with N owners: compress it to one convention line per prompt.
|
|
76
|
+
- **Every line changes behavior.** If deleting a line would not change what
|
|
77
|
+
the agent does, delete it.
|
|
78
|
+
- **Output contracts are APIs.** Downstream agents parse the sections;
|
|
79
|
+
renaming or reshaping them is a breaking change — evolve additively.
|
|
80
|
+
- **Update on every miss.** When an agent fails in the field, amend the rule
|
|
81
|
+
that should have caught it — as an invariant, in the same change as the
|
|
82
|
+
fix. A prompt that never absorbs its misses is rotting silently.
|
|
83
|
+
|
|
62
84
|
## Review checklist
|
|
63
85
|
- Is the role narrower than a general engineer?
|
|
64
86
|
- Would another agent know exactly when to use it?
|
|
65
87
|
- Are the tools minimal?
|
|
66
88
|
- Is the handoff structured?
|
|
67
89
|
- Is the file under 100 lines?
|
|
90
|
+
- Does any line narrate an incident instead of stating its invariant?
|
|
91
|
+
- Is any fact stated here also owned somewhere else?
|