@marcoscale98/pi-extensible-workflows 5.14.1-fork.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.
- package/CHANGELOG.md +536 -0
- package/README.md +64 -0
- package/dist/src/agent-execution.d.ts +338 -0
- package/dist/src/agent-execution.js +1633 -0
- package/dist/src/background-widget.d.ts +74 -0
- package/dist/src/background-widget.js +1340 -0
- package/dist/src/budget.d.ts +38 -0
- package/dist/src/budget.js +188 -0
- package/dist/src/changelog.d.ts +6 -0
- package/dist/src/changelog.js +112 -0
- package/dist/src/decoders.d.ts +96 -0
- package/dist/src/decoders.js +629 -0
- package/dist/src/execution.d.ts +19 -0
- package/dist/src/execution.js +749 -0
- package/dist/src/herdr.d.ts +53 -0
- package/dist/src/herdr.js +270 -0
- package/dist/src/host-delivery.d.ts +95 -0
- package/dist/src/host-delivery.js +376 -0
- package/dist/src/host-navigator.d.ts +83 -0
- package/dist/src/host-navigator.js +1087 -0
- package/dist/src/host-phases.d.ts +89 -0
- package/dist/src/host-phases.js +320 -0
- package/dist/src/host-recovery.d.ts +141 -0
- package/dist/src/host-recovery.js +356 -0
- package/dist/src/host-runtime.d.ts +78 -0
- package/dist/src/host-runtime.js +378 -0
- package/dist/src/host-view.d.ts +116 -0
- package/dist/src/host-view.js +868 -0
- package/dist/src/host.d.ts +40 -0
- package/dist/src/host.js +1641 -0
- package/dist/src/index.d.ts +29 -0
- package/dist/src/index.js +13725 -0
- package/dist/src/index.js.map +6 -0
- package/dist/src/io.d.ts +14 -0
- package/dist/src/io.js +82 -0
- package/dist/src/package-identity.d.ts +4 -0
- package/dist/src/package-identity.js +6 -0
- package/dist/src/paths.d.ts +14 -0
- package/dist/src/paths.js +51 -0
- package/dist/src/persistence.d.ts +5 -0
- package/dist/src/persistence.js +5 -0
- package/dist/src/pi-runtime-adapter.d.ts +27 -0
- package/dist/src/pi-runtime-adapter.js +243 -0
- package/dist/src/pi-runtime-runner.d.ts +42 -0
- package/dist/src/pi-runtime-runner.js +505 -0
- package/dist/src/registry.d.ts +48 -0
- package/dist/src/registry.js +379 -0
- package/dist/src/retention.d.ts +17 -0
- package/dist/src/retention.js +195 -0
- package/dist/src/runtime/agent-runner.d.ts +143 -0
- package/dist/src/runtime/agent-runner.js +12 -0
- package/dist/src/runtime/index.d.ts +2 -0
- package/dist/src/runtime/index.js +2 -0
- package/dist/src/runtime/namespace.d.ts +14 -0
- package/dist/src/runtime/namespace.js +1 -0
- package/dist/src/runtime/workflow-result.d.ts +2 -0
- package/dist/src/runtime/workflow-result.js +6 -0
- package/dist/src/session-handoff.d.ts +2 -0
- package/dist/src/session-handoff.js +82 -0
- package/dist/src/session-lease.d.ts +12 -0
- package/dist/src/session-lease.js +180 -0
- package/dist/src/store.d.ts +95 -0
- package/dist/src/store.js +951 -0
- package/dist/src/subagent-manager-handle.d.ts +4 -0
- package/dist/src/subagent-manager-handle.js +6 -0
- package/dist/src/tool-timing.d.ts +12 -0
- package/dist/src/tool-timing.js +33 -0
- package/dist/src/trajectory-contracts.d.ts +8 -0
- package/dist/src/trajectory-contracts.js +9 -0
- package/dist/src/trajectory-host-handle.d.ts +12 -0
- package/dist/src/trajectory-host-handle.js +6 -0
- package/dist/src/trajectory.d.ts +128 -0
- package/dist/src/trajectory.js +594 -0
- package/dist/src/types.d.ts +960 -0
- package/dist/src/types.js +60 -0
- package/dist/src/utils.d.ts +57 -0
- package/dist/src/utils.js +225 -0
- package/dist/src/validation.d.ts +29 -0
- package/dist/src/validation.js +1100 -0
- package/dist/src/workflow-artifacts.d.ts +14 -0
- package/dist/src/workflow-artifacts.js +40 -0
- package/dist/starter/index.d.ts +1 -0
- package/dist/starter/index.js +103 -0
- package/dist/starter/index.js.map +6 -0
- package/dist/starter/review-loop.d.ts +72 -0
- package/dist/starter/review-loop.js +43 -0
- package/dist/starter/roles/developer.md +6 -0
- package/dist/starter/roles/oracle.md +18 -0
- package/dist/starter/roles/researcher.md +20 -0
- package/dist/starter/roles/reviewer.md +19 -0
- package/dist/starter/roles/scout.md +18 -0
- package/dist/subagents/index.d.ts +8 -0
- package/dist/subagents/index.js +8021 -0
- package/dist/subagents/index.js.map +6 -0
- package/dist/subagents/src/contracts.d.ts +173 -0
- package/dist/subagents/src/contracts.js +68 -0
- package/dist/subagents/src/decode.d.ts +15 -0
- package/dist/subagents/src/decode.js +182 -0
- package/dist/subagents/src/index.d.ts +12 -0
- package/dist/subagents/src/index.js +180 -0
- package/dist/subagents/src/manager.d.ts +3 -0
- package/dist/subagents/src/manager.js +1636 -0
- package/dist/subagents/src/navigator.d.ts +5 -0
- package/dist/subagents/src/navigator.js +627 -0
- package/dist/subagents/src/view.d.ts +70 -0
- package/dist/subagents/src/view.js +387 -0
- package/dist/subagents/src/worktree.d.ts +34 -0
- package/dist/subagents/src/worktree.js +68 -0
- package/dist/trajectory/assets/favicon.png +0 -0
- package/dist/trajectory/assets/index.html +772 -0
- package/dist/trajectory/assets/marked.min.js +6 -0
- package/dist/trajectory/assets/morphdom.min.js +1 -0
- package/dist/trajectory/index.d.ts +5 -0
- package/dist/trajectory/index.js +3459 -0
- package/dist/trajectory/index.js.map +6 -0
- package/dist/trajectory/src/assets/favicon.png +0 -0
- package/dist/trajectory/src/assets/index.html +772 -0
- package/dist/trajectory/src/assets/marked.min.js +6 -0
- package/dist/trajectory/src/assets/morphdom.min.js +1 -0
- package/dist/trajectory/src/export.d.ts +25 -0
- package/dist/trajectory/src/export.js +80 -0
- package/dist/trajectory/src/index.d.ts +26 -0
- package/dist/trajectory/src/index.js +732 -0
- package/dist/trajectory/src/server.d.ts +7 -0
- package/dist/trajectory/src/server.js +2534 -0
- package/dist/trajectory/src/server.js.map +6 -0
- package/examples/advanced-patterns/auto-model-router.mjs +78 -0
- package/examples/workflow-extension-template/README.md +37 -0
- package/examples/workflow-extension-template/extension.test.mjs +59 -0
- package/examples/workflow-extension-template/index.js +51 -0
- package/examples/workflow-extension-template/roles/reviewer.md +4 -0
- package/package.json +105 -0
- package/skills/pi-extensible-workflows/SKILL.md +160 -0
- package/src/agent-execution.ts +1533 -0
- package/src/background-widget.ts +1496 -0
- package/src/budget.ts +109 -0
- package/src/changelog.ts +114 -0
- package/src/decoders.ts +567 -0
- package/src/execution.ts +652 -0
- package/src/herdr.ts +240 -0
- package/src/host-delivery.ts +346 -0
- package/src/host-navigator.ts +871 -0
- package/src/host-phases.ts +264 -0
- package/src/host-recovery.ts +333 -0
- package/src/host-runtime.ts +373 -0
- package/src/host-view.ts +828 -0
- package/src/host.ts +1502 -0
- package/src/index.ts +29 -0
- package/src/io.ts +73 -0
- package/src/package-identity.ts +7 -0
- package/src/paths.ts +49 -0
- package/src/persistence.ts +11 -0
- package/src/pi-runtime-adapter.ts +247 -0
- package/src/pi-runtime-runner.ts +436 -0
- package/src/registry.ts +321 -0
- package/src/retention.ts +178 -0
- package/src/runtime/agent-runner.ts +158 -0
- package/src/runtime/index.ts +2 -0
- package/src/runtime/namespace.ts +16 -0
- package/src/runtime/workflow-result.ts +8 -0
- package/src/session-handoff.ts +78 -0
- package/src/session-lease.ts +125 -0
- package/src/store.ts +832 -0
- package/src/subagent-manager-handle.ts +8 -0
- package/src/tool-timing.ts +47 -0
- package/src/trajectory-contracts.ts +13 -0
- package/src/trajectory-host-handle.ts +16 -0
- package/src/trajectory.ts +543 -0
- package/src/types.ts +374 -0
- package/src/utils.ts +192 -0
- package/src/validation.ts +910 -0
- package/src/workflow-artifacts.ts +35 -0
- package/starter/index.ts +35 -0
- package/starter/prompts/council.md +16 -0
- package/starter/prompts/deep-research.md +16 -0
- package/starter/prompts/oracle.md +14 -0
- package/starter/prompts/parallel-review.md +22 -0
- package/starter/prompts/parallel-scout.md +16 -0
- package/starter/prompts/review-loop.md +14 -0
- package/starter/prompts/review.md +14 -0
- package/starter/prompts/scout.md +14 -0
- package/starter/review-loop.ts +73 -0
- package/starter/roles/developer.md +6 -0
- package/starter/roles/oracle.md +18 -0
- package/starter/roles/researcher.md +20 -0
- package/starter/roles/reviewer.md +19 -0
- package/starter/roles/scout.md +18 -0
- package/subagents/README.md +145 -0
- package/subagents/index.ts +8 -0
- package/subagents/src/contracts.ts +176 -0
- package/subagents/src/decode.ts +158 -0
- package/subagents/src/index.ts +194 -0
- package/subagents/src/manager.ts +1560 -0
- package/subagents/src/navigator.ts +488 -0
- package/subagents/src/view.ts +376 -0
- package/subagents/src/worktree.ts +99 -0
- package/trajectory/index.ts +5 -0
- package/trajectory/src/assets/favicon.png +0 -0
- package/trajectory/src/assets/index.html +772 -0
- package/trajectory/src/assets/marked.min.js +6 -0
- package/trajectory/src/assets/morphdom.min.js +1 -0
- package/trajectory/src/export.ts +85 -0
- package/trajectory/src/index.ts +604 -0
- package/trajectory/src/server.ts +447 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import type { JsonValue } from "./types.js";
|
|
6
|
+
|
|
7
|
+
export interface WorkflowArtifact { extension: ".js" | ".json" | ".md"; content: string }
|
|
8
|
+
export type WorkflowTui = { stop(): void; start(): void; requestRender(force?: boolean): void };
|
|
9
|
+
|
|
10
|
+
export function workflowScriptArtifact(script: string): WorkflowArtifact { return { extension: ".js", content: script }; }
|
|
11
|
+
export function workflowPromptArtifact(prompt: string): WorkflowArtifact { return { extension: ".md", content: prompt }; }
|
|
12
|
+
export function workflowResultArtifact(value: JsonValue): WorkflowArtifact { return typeof value === "string" ? { extension: ".md", content: value } : { extension: ".json", content: `${JSON.stringify(value, null, 2)}\n` }; }
|
|
13
|
+
|
|
14
|
+
async function spawnWorkflowEditor(command: string, path: string): Promise<number | null> {
|
|
15
|
+
const [editor, ...editorArgs] = command.split(" ");
|
|
16
|
+
if (!editor) return null;
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
try {
|
|
19
|
+
const child = spawn(editor, [...editorArgs, path], { stdio: "inherit", shell: process.platform === "win32" });
|
|
20
|
+
child.once("error", () => { resolve(null); });
|
|
21
|
+
child.once("close", (code) => { resolve(code); });
|
|
22
|
+
} catch { resolve(null); }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function openWorkflowArtifact(tui: WorkflowTui, command: string, artifact: WorkflowArtifact): Promise<number | null> {
|
|
27
|
+
const directory = await mkdtemp(join(tmpdir(), "pi-workflow-editor-"));
|
|
28
|
+
const path = join(directory, `artifact${artifact.extension}`);
|
|
29
|
+
try {
|
|
30
|
+
await writeFile(path, artifact.content, { encoding: "utf8", mode: 0o600 });
|
|
31
|
+
tui.stop();
|
|
32
|
+
try { return await spawnWorkflowEditor(command, path); }
|
|
33
|
+
finally { tui.start(); tui.requestRender(true); }
|
|
34
|
+
} finally { await rm(directory, { recursive: true, force: true }); }
|
|
35
|
+
}
|
package/starter/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerWorkflowExtension,
|
|
3
|
+
type WorkflowExtension,
|
|
4
|
+
} from "@marcoscale98/pi-extensible-workflows";
|
|
5
|
+
import { reviewLoop } from "./review-loop.js";
|
|
6
|
+
|
|
7
|
+
const extension: WorkflowExtension = {
|
|
8
|
+
source: import.meta.url,
|
|
9
|
+
dependencies: ["typebox"],
|
|
10
|
+
version: "1.0.0",
|
|
11
|
+
headline: "Developer-review starter workflows",
|
|
12
|
+
functions: { reviewLoop },
|
|
13
|
+
modelAliases: {
|
|
14
|
+
"reviewer-model": {
|
|
15
|
+
resolve: ({ rootModel }) => `${rootModel.provider}/${rootModel.model}`,
|
|
16
|
+
},
|
|
17
|
+
"developer-model": {
|
|
18
|
+
resolve: ({ rootModel }) => `${rootModel.provider}/${rootModel.model}`,
|
|
19
|
+
},
|
|
20
|
+
"scout-model": {
|
|
21
|
+
resolve: ({ rootModel }) => `${rootModel.provider}/${rootModel.model}`,
|
|
22
|
+
},
|
|
23
|
+
"oracle-model": {
|
|
24
|
+
resolve: ({ rootModel }) => `${rootModel.provider}/${rootModel.model}`,
|
|
25
|
+
},
|
|
26
|
+
"researcher-model": {
|
|
27
|
+
resolve: ({ rootModel }) => `${rootModel.provider}/${rootModel.model}`,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
roleDirectories: [new URL("./roles/", import.meta.url)],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default function (): void {
|
|
34
|
+
registerWorkflowExtension(extension);
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Convene 2-3 oracle advisors with distinct lenses and write a decision memo
|
|
3
|
+
argument-hint: "<question or decision>"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Convene a bounded advisory council on this decision. You are the supervisor: you pick the lenses, you synthesize, you decide what feedback is valid. Advisors do not talk to each other.
|
|
7
|
+
|
|
8
|
+
If the question is trivial or already settled, answer directly instead of convening a council.
|
|
9
|
+
|
|
10
|
+
Pick 2-3 distinct lenses suited to the decision (for example: simplicity and maintenance cost, correctness and failure modes, migration and compatibility risk). Launch a named workflow whose script fans out one `agent(taskPrompt, { role: "oracle" })` per lens with `parallel(...)`, each given the decision, the relevant context, and its lens in `taskPrompt`. One pass only; do not run advisor rounds.
|
|
11
|
+
|
|
12
|
+
Synthesize the returned opinions yourself into a short decision memo: the recommendation, the strongest argument against it, what each lens surfaced, and the decision that remains mine.
|
|
13
|
+
|
|
14
|
+
Question:
|
|
15
|
+
|
|
16
|
+
$@
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Fan out researcher subagents on a question and synthesize a cited answer
|
|
3
|
+
argument-hint: "<question>"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Run a deep research on this question. Do not research it yourself.
|
|
7
|
+
|
|
8
|
+
First check this session's tools: if the question needs web evidence and no web search or fetch tool is available, say so and stop instead of producing an uncited answer.
|
|
9
|
+
|
|
10
|
+
Decompose the question into 2-4 independent sub-questions with distinct angles. Launch a named workflow whose script fans the sub-questions out with `parallel(...)`, one `agent(taskPrompt, { role: "researcher" })` per sub-question with its question and context in `taskPrompt`, then passes the keyed briefs into one final `agent(...)` that synthesizes a single answer with citations and returns it.
|
|
11
|
+
|
|
12
|
+
When the run completes, report the synthesized answer with its citations, plus anything the researchers marked as unverified.
|
|
13
|
+
|
|
14
|
+
Question:
|
|
15
|
+
|
|
16
|
+
$@
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Get a second opinion on a plan, design, or decision from an oracle subagent
|
|
3
|
+
argument-hint: "<plan, decision, or question>"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Get a second opinion before committing to this plan or decision. Do not judge it yourself.
|
|
7
|
+
|
|
8
|
+
Use `subagents_run` with `role: "oracle"` and `mode: "foreground"`. Give it the proposal below plus the relevant context from this conversation: the goal, the constraints, and any decisions already made. Point it at the files involved instead of pasting file contents.
|
|
9
|
+
|
|
10
|
+
When it returns, relay the strongest challenge, the hidden assumptions, and the recommendation. State plainly whether the oracle endorsed the proposal.
|
|
11
|
+
|
|
12
|
+
Proposal:
|
|
13
|
+
|
|
14
|
+
$@
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Adversarial review with parallel fresh reviewers on distinct angles
|
|
3
|
+
argument-hint: "[target or focus]"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Run an adversarial parallel review of the current work. Do not review it yourself and do not edit files.
|
|
7
|
+
|
|
8
|
+
If a target or focus is given below, review that; otherwise review the current uncommitted diff.
|
|
9
|
+
|
|
10
|
+
Choose 2-3 distinct review angles from the actual change (for example correctness and regressions, tests and validation, simplicity and maintainability; add security, performance, or docs when the change calls for it). Prefer three strong reviewers over many vague ones.
|
|
11
|
+
|
|
12
|
+
Launch a named workflow whose script fans out one `agent(taskPrompt, { role: "reviewer" })` per angle with `parallel(...)`, each told its angle in `taskPrompt` and to inspect the repository and diff directly with its own tools. Await the keyed reviews, then synthesize them yourself into:
|
|
13
|
+
|
|
14
|
+
- fixes worth doing now;
|
|
15
|
+
- optional improvements;
|
|
16
|
+
- feedback to ignore or defer, with a short reason.
|
|
17
|
+
|
|
18
|
+
Report the synthesis and each reviewer's merge verdict. Do not apply fixes unless I ask.
|
|
19
|
+
|
|
20
|
+
Target or focus:
|
|
21
|
+
|
|
22
|
+
$@
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Fan out scout subagents across areas of the codebase and merge the briefs
|
|
3
|
+
argument-hint: "<question or task to scope>"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Recon this question across the codebase with parallel scouts. Do not explore it yourself.
|
|
7
|
+
|
|
8
|
+
If the question is small enough for one scout, launch a single subagent with the `scout` role instead of a workflow.
|
|
9
|
+
|
|
10
|
+
Otherwise split the question into 2-3 independent areas (for example: the feature's entry points, the data layer it touches, the tests that cover it). Launch a named workflow whose script fans out one `agent(taskPrompt, { role: "scout" })` per area with `parallel(...)`, putting its question and context in `taskPrompt`, then merge the keyed briefs yourself into one map: relevant files, how the flow works end to end, patterns to reuse, and open questions.
|
|
11
|
+
|
|
12
|
+
Report the merged brief. Keep it compact; no implementation plan.
|
|
13
|
+
|
|
14
|
+
Question:
|
|
15
|
+
|
|
16
|
+
$@
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Implement a task with the developer-and-reviewer loop workflow
|
|
3
|
+
argument-hint: "<task> [max iterations]"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Run the bundled `reviewLoop` workflow for this task. Do not implement it yourself.
|
|
7
|
+
|
|
8
|
+
Launch it with the `workflow` tool: a named run whose script returns `await reviewLoop({ task: args.task })`, passing the task below through `args`. If a max iteration count is given, pass `maxIterations` too. Leave the run in the background unless I asked to wait.
|
|
9
|
+
|
|
10
|
+
When the run completes, report whether the reviewer passed the implementation, how many iterations ran, and any remaining findings.
|
|
11
|
+
|
|
12
|
+
Task:
|
|
13
|
+
|
|
14
|
+
$@
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Review the current diff or a named target with a fresh reviewer subagent
|
|
3
|
+
argument-hint: "[target or focus]"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Launch a fresh-context review of the current work. Do not review it yourself and do not edit files.
|
|
7
|
+
|
|
8
|
+
Use `subagents_run` with `role: "reviewer"` and `mode: "foreground"`. If a target or focus is given below, review that; otherwise review the current uncommitted diff. Tell the reviewer to inspect the repository and diff directly with its own tools, not to rely on this conversation.
|
|
9
|
+
|
|
10
|
+
When it returns, relay the findings grouped by P0/P1/P2 and the merge verdict. Do not apply fixes unless I ask.
|
|
11
|
+
|
|
12
|
+
Target or focus:
|
|
13
|
+
|
|
14
|
+
$@
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Launch a read-only scout subagent to recon the codebase
|
|
3
|
+
argument-hint: "<question or area to explore>"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Launch one subagent with the `scout` role to answer this recon question. Do not explore the codebase yourself.
|
|
7
|
+
|
|
8
|
+
Use `subagents_run` with `role: "scout"`, `mode: "foreground"`, and a prompt containing the question below plus any paths or constraints already known in this conversation.
|
|
9
|
+
|
|
10
|
+
When it returns, relay the brief as-is: relevant files, flow, patterns to reuse, and open questions. Do not pad it.
|
|
11
|
+
|
|
12
|
+
Question:
|
|
13
|
+
|
|
14
|
+
$@
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Type, type Static } from "typebox";
|
|
2
|
+
import {
|
|
3
|
+
defineWorkflowFunction,
|
|
4
|
+
type JsonValue,
|
|
5
|
+
} from "@marcoscale98/pi-extensible-workflows";
|
|
6
|
+
|
|
7
|
+
export const reviewLoop = defineWorkflowFunction({
|
|
8
|
+
description:
|
|
9
|
+
"Run developer and reviewer agents until review passes or the iteration limit is reached",
|
|
10
|
+
async run({ task, maxIterations = 5 }, { agent, prompt }) {
|
|
11
|
+
const reviewSchema = Type.Object(
|
|
12
|
+
{
|
|
13
|
+
pass: Type.Boolean(),
|
|
14
|
+
findings: Type.Array(Type.String()),
|
|
15
|
+
},
|
|
16
|
+
{ additionalProperties: false },
|
|
17
|
+
);
|
|
18
|
+
let devResult: JsonValue = null;
|
|
19
|
+
let review: Static<typeof reviewSchema> = { pass: false, findings: [] };
|
|
20
|
+
|
|
21
|
+
for (let iterations = 1; iterations <= maxIterations; iterations += 1) {
|
|
22
|
+
const devPrompt =
|
|
23
|
+
iterations === 1
|
|
24
|
+
? prompt("Implement this task:\n\n{task}", { task })
|
|
25
|
+
: prompt(
|
|
26
|
+
`Address the previous review findings and complete the task.
|
|
27
|
+
<original_task>{task}</original_task>
|
|
28
|
+
<last_review>{review}</last_review>`,
|
|
29
|
+
{ task, review: review.findings },
|
|
30
|
+
);
|
|
31
|
+
devResult = await agent(devPrompt, { role: "developer" });
|
|
32
|
+
review = await agent(
|
|
33
|
+
prompt(
|
|
34
|
+
`Review the implementation against the task. Set pass=true only when the task is complete and correct. The developer may have addressed a previous review run of yours. So its summary is related to the last round of review if present.
|
|
35
|
+
<original_task>{task}</original_task>
|
|
36
|
+
<last_review>{review}</last_review>
|
|
37
|
+
<dev_summary>{devResult}</dev_summary>`,
|
|
38
|
+
{ task, devResult, review: review.findings },
|
|
39
|
+
),
|
|
40
|
+
{ role: "reviewer", outputSchema: reviewSchema },
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if (review.pass) return { pass: true, iterations, devResult, review };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { pass: false, iterations: maxIterations, devResult, review };
|
|
47
|
+
},
|
|
48
|
+
input: Type.Object(
|
|
49
|
+
{
|
|
50
|
+
task: Type.String(),
|
|
51
|
+
maxIterations: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
52
|
+
},
|
|
53
|
+
{ additionalProperties: false },
|
|
54
|
+
),
|
|
55
|
+
output: Type.Object(
|
|
56
|
+
{
|
|
57
|
+
pass: Type.Boolean(),
|
|
58
|
+
iterations: Type.Integer(),
|
|
59
|
+
devResult: Type.Any(),
|
|
60
|
+
review: Type.Object(
|
|
61
|
+
{
|
|
62
|
+
pass: Type.Boolean(),
|
|
63
|
+
findings: Type.Array(Type.String()),
|
|
64
|
+
},
|
|
65
|
+
{ additionalProperties: false },
|
|
66
|
+
),
|
|
67
|
+
},
|
|
68
|
+
{ additionalProperties: false },
|
|
69
|
+
),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const reviewLoopInputSchema = reviewLoop.input;
|
|
73
|
+
export const reviewLoopOutputSchema = reviewLoop.output;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
---
|
|
2
|
+
model: developer-model
|
|
3
|
+
description: Developer focused agent
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Act as a senior developer. Implement the requested task with the smallest working change. Read the relevant flow first, reuse existing project patterns, keep the change surgical, and verify the result with the smallest relevant check.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
model: oracle-model
|
|
3
|
+
tools: ["!*", "read", "grep", "find", "ls", "bash"]
|
|
4
|
+
description: Oracle. Use for a second opinion on a plan, design, or decision before committing to it
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Give a second opinion on the presented plan, design, or decision. Do not edit files. You are not a second decision-maker; you challenge, verify, and report.
|
|
8
|
+
|
|
9
|
+
Reconstruct the stated goals and constraints first, then verify the claims against the actual code, tests, and docs. Run read-only commands when they settle a question. When source contradicts the plan or its assumptions, trust source and report the conflict.
|
|
10
|
+
|
|
11
|
+
Return:
|
|
12
|
+
|
|
13
|
+
- The strongest challenge to the proposal, with evidence.
|
|
14
|
+
- Hidden assumptions or contradictions you found.
|
|
15
|
+
- What the proposal gets right and should keep.
|
|
16
|
+
- A recommendation, naming any decision that still belongs to the caller.
|
|
17
|
+
|
|
18
|
+
If the proposal is sound, say so plainly instead of inventing objections.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
model: researcher-model
|
|
3
|
+
tools: ["!edit", "!write", "!bash"]
|
|
4
|
+
description: Researcher. Use for deep research across the codebase, docs, and the web when web tools are available
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Research the requested question in depth. Do not edit files.
|
|
8
|
+
|
|
9
|
+
Use every read and search capability you have: code, files, docs, and any web search or fetch tools present in this session. If the question needs web evidence and no web tool is available, say so explicitly instead of guessing.
|
|
10
|
+
|
|
11
|
+
Verify claims against primary sources: the actual code, official docs, or the cited page. Prefer primary sources over aggregators.
|
|
12
|
+
|
|
13
|
+
Return a research brief:
|
|
14
|
+
|
|
15
|
+
- Direct answer to the question.
|
|
16
|
+
- Evidence per claim, citing files and lines for code and URLs for web sources.
|
|
17
|
+
- Contradictions or version-specific caveats you found.
|
|
18
|
+
- What is known, what is uncertain, and what would settle the open questions.
|
|
19
|
+
|
|
20
|
+
Report only what you verified. Mark everything else as unverified.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
model: reviewer-model
|
|
3
|
+
tools: ["!*", "read", "grep", "find", "ls"]
|
|
4
|
+
description: Reviewer. Use when we need to review decisions or code changes
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Inspect the requested change for correctness, missed callers, broken assumptions, regressions, security or data-loss risk, and missing verification. Do not edit files.
|
|
8
|
+
|
|
9
|
+
Filter findings on evidence, not severity: report only concrete, current issues caused or made reachable by the change, backed by source proof, a failing test or repro, or a contract contradiction. Cite exact files and lines. Ignore style unless it hides a real defect. Do not report speculative or pre-existing issues unless asked.
|
|
10
|
+
|
|
11
|
+
Label each finding:
|
|
12
|
+
|
|
13
|
+
- P0: blocks merge (broken behavior, data loss, security).
|
|
14
|
+
- P1: should be fixed before release.
|
|
15
|
+
- P2: report-only note.
|
|
16
|
+
|
|
17
|
+
If nothing qualifies, say exactly `No issues found.`
|
|
18
|
+
|
|
19
|
+
End with one line: `Merge verdict: BLOCK`, `Merge verdict: OK`, or `Merge verdict: OK with notes`.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
model: scout-model
|
|
3
|
+
tools: ["!*", "read", "grep", "find", "ls"]
|
|
4
|
+
description: Scout. Use for fast read-only codebase recon before planning or implementing
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Perform fast, read-only reconnaissance of the codebase for the requested question. Do not edit files.
|
|
8
|
+
|
|
9
|
+
Locate the relevant files, entry points, and data flow. Trace the actual code paths instead of inferring from names. Note existing patterns, helpers, and tests the task should reuse.
|
|
10
|
+
|
|
11
|
+
Return a compact brief:
|
|
12
|
+
|
|
13
|
+
- Relevant files with one-line purpose each.
|
|
14
|
+
- How the flow works end to end, citing files and lines.
|
|
15
|
+
- Existing patterns or utilities to reuse.
|
|
16
|
+
- What is known, what is uncertain, and the smallest next step.
|
|
17
|
+
|
|
18
|
+
Report only what you verified in the code. Mark anything unverified as an open question. Keep output concise; no implementation plan.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Built-in subagent extension
|
|
2
|
+
|
|
3
|
+
Single-shot agents for Pi: each run launches one independent agent session from one task, without writing a workflow script. Single-shot describes the orchestration shape, not one model turn; the agent can use tools and accept steering while it runs.
|
|
4
|
+
|
|
5
|
+
[Full Subagents documentation](https://vekexasia.github.io/pi-extensible-workflows/subagents.html) | [Main package](https://github.com/vekexasia/pi-extensible-workflows#readme) | [Roles](https://vekexasia.github.io/pi-extensible-workflows/roles.html) | [Settings](https://vekexasia.github.io/pi-extensible-workflows/developers.html#settings)
|
|
6
|
+
|
|
7
|
+
Use the built-in subagent tools for focused, independent tasks. Use `pi-extensible-workflows` when work needs dependency batches, parallel or pipeline stages, checkpoints, approvals, or resumable orchestration.
|
|
8
|
+
|
|
9
|
+
## Subagents vs workflows
|
|
10
|
+
|
|
11
|
+
| Built-in subagent tools | `pi-extensible-workflows` |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| One independently launched agent per run | A deterministic script orchestrating one or more agents |
|
|
14
|
+
| One task with a durable ID and lifecycle controls | Multi-stage coordination, dependencies, approvals, replay, and resume |
|
|
15
|
+
| Start in the background or wait in the foreground | Run a named workflow in the background or foreground |
|
|
16
|
+
|
|
17
|
+
## Highlights
|
|
18
|
+
|
|
19
|
+
- Five focused tools: run, inspect, steer, stop, and retry.
|
|
20
|
+
- Background fan-out with one durable ID per run, or foreground execution with an inline terminal result.
|
|
21
|
+
- Reuses workflow roles, model aliases, settings including extension-defined namespaces, and agent options: `label`, `model`, `tools`, `skills`, `extensions`, `contextFiles`, `worktree`, `outputSchema`, `retries` (0 through 255), and `timeoutMs`.
|
|
22
|
+
- Repeatable inspection of progress, token accounting, tool calls, results, failures, and worktrees.
|
|
23
|
+
|
|
24
|
+
Built-in subagent tools are available when the core extension is installed. Use the core package's Pi extension manifest to enable them.
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
Start work in the background and inspect it later:
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
subagents_run({ prompt: "Review the current changes.", label: "review" })
|
|
32
|
+
# => { "id": "...", "state": "running" }
|
|
33
|
+
|
|
34
|
+
subagents_inspect({ id: "..." })
|
|
35
|
+
# => progress while running, then the terminal value or error
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Use foreground mode when the result must return in the same tool call:
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
subagents_run({ prompt: "Summarize README.md.", mode: "foreground" })
|
|
42
|
+
# => { "id": "...", "state": "completed", "value": ... }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Interactive inspection
|
|
46
|
+
|
|
47
|
+
In Pi's TUI, `/subagents` opens a picker of durable standalone runs for the current session. Select a run to inspect the same activity, stall warning, state, model, role, tools, attempts, duration, cumulative token accounting, cost, and error fields used by `/workflow`; prompt, request failure, and result details remain bounded, and requests without a role remain `role=none`. The detail view also exposes registered standalone agent actions plus `Steer` and `Stop` while running, `Retry` for failed or stopped runs, and copy/editor controls where applicable. Inspection does not launch a new LLM call; lifecycle actions may steer, stop, or retry a run.
|
|
48
|
+
|
|
49
|
+
## Tools
|
|
50
|
+
|
|
51
|
+
Every tool schema is a closed object. Unknown properties are rejected. The model-visible standalone surface contains exactly these five names:
|
|
52
|
+
|
|
53
|
+
| Tool | Input schema |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `subagents_run` | `{ prompt: string, mode?: "background" \| "foreground", label?: string, model?: string, tools?: string[], skills?: string[], extensions?: string[], contextFiles?: string[], role?: string, worktree?: string, outputSchema?: object, retries?: integer 0..255, timeoutMs?: positive integer \| null }` |
|
|
56
|
+
| `subagents_inspect` | `{ id?: string }` |
|
|
57
|
+
| `subagents_steer` | `{ id: string, message: string }` |
|
|
58
|
+
| `subagents_stop` | `{ id: string }` |
|
|
59
|
+
| `subagents_retry` | `{ id: string }` |
|
|
60
|
+
|
|
61
|
+
`prompt` is the only required `subagents_run` property. `mode` defaults to "background". Resource candidates start enabled, so plain positive top-level selector lists are additive and top-level `[]` adds no matches. Use `["!*", "read", "grep"]` to restrict a selector to those resources, or `["!*"]` to select none. A `role` string selects an existing workflow role. Model, tools, skills, extensions, and contextFiles are top-level `AgentOptions` overrides applied after the role file. Concrete models are `provider/model:thinking`. Capability selectors use ordered minimatch rules and are applied after global, trusted-project, and role selectors. Use `tools: ["*"]` to re-enable all tools after a role restriction.
|
|
62
|
+
|
|
63
|
+
`subagents_inspect({})` returns all accessible run summaries ordered by start time. `subagents_inspect({ id })` returns the detailed lifecycle record, including state, start and finish timestamps, and the live snapshot under `progress`: `state`, cumulative `accounting`, `toolCalls`, `activity`, and `lastEventAt`. The snapshot state never includes the effective system prompt, and inspection has no `usage` field; token totals are derived from accounting. Materialized worktree path and branch are included when available. For completed runs it also includes `value`; for failed runs it includes `error`. A running run has no terminal value yet. Unknown IDs fail with `RUN_NOT_FOUND`.
|
|
64
|
+
|
|
65
|
+
## Launching and concurrency
|
|
66
|
+
|
|
67
|
+
Background mode starts execution immediately and returns one durable UUID:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{"id":"01900000-0000-4000-8000-000000000000","state":"running"}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Use foreground mode when the terminal envelope is needed in the same tool call:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{"id":"01900000-0000-4000-8000-000000000000","state":"completed","value":{"answer":"done"}}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
A foreground failure returns `{"id":"...","state":"failed","error":{"code":"AGENT_FAILED","message":"..."}}`. Foreground cancellation aborts the active native session and persists a failed record with code `CANCELLED`. A foreground run does not generate a background completion follow-up.
|
|
80
|
+
|
|
81
|
+
Each call owns an independent run, so calls can execute concurrently and settle independently up to the effective workflow `concurrency` setting for the launch context (an integer from 1 through 16, default 8). When the limit is reached, `subagents_run` and `subagents_retry` reject with `AGENT_FAILED`; no queue is maintained, so retry after an active run settles. Background completed and failed runs can produce one follow-up message when the host supplies `sendMessage`; the message points to the ID and `subagents_inspect` rather than embedding the full result.
|
|
82
|
+
|
|
83
|
+
## IDs, inspection, and terminal values
|
|
84
|
+
|
|
85
|
+
Run records are stored below the agent directory's private `subagents/<id>/` directory, normally `~/.pi/agent/subagents/<id>/`. The record includes the normalized request, its frozen external settings and role definitions for deterministic retries, and status. A shared storage owner marker uses the process ID, process start, session ID, and token; every running record carries the same manager identity so a live manager does not reconcile another manager's active run.
|
|
86
|
+
|
|
87
|
+
Inspection is repeatable. Use the list form for ordered summaries and the ID form for one detailed status plus its terminal value or failure information. Progress is retained in memory and is persisted when the executor marks a progress update for persistence. The result and failure files remain available after manager restart.
|
|
88
|
+
|
|
89
|
+
## Steering and stopping
|
|
90
|
+
|
|
91
|
+
`subagents_steer` sends a message to a running agent. Messages sent before the executor exposes its steering handler are queued and delivered in order. The queue is bounded at 16 pending messages. Steering a settled, stopped, or unknown run fails; steering never targets a sibling run.
|
|
92
|
+
|
|
93
|
+
`subagents_stop` aborts only the selected run, clears its steering queue, persists `state: "stopped"`, aborts its active session, and cleans its worktree. Stopping one run does not stop other runs. Use this tool when the desired terminal state is `stopped`; cancelling a foreground `subagents_run` instead records `failed` with `CANCELLED`.
|
|
94
|
+
|
|
95
|
+
## Retries
|
|
96
|
+
|
|
97
|
+
`subagents_retry` is available for `failed` and `stopped` runs. It reads the original normalized request and frozen external configuration, then starts a fresh execution with a new UUID. Historic records without that frozen configuration are reported as incompatible rather than retried with current settings. The old record and ID remain available. Completed or currently running runs are not retryable. The retry preserves the original `background` or `foreground` launch mode, so retrying a foreground run returns its new terminal envelope inline.
|
|
98
|
+
|
|
99
|
+
## Worktrees
|
|
100
|
+
|
|
101
|
+
Set `worktree` on `subagents_run` to create a named isolated Git worktree for that run. The default adapter uses the core `RunStore`: the worktree branches from the repository's clean `HEAD`, and a dirty working tree (tracked or untracked non-ignored changes) fails the run with `WORKTREE_FAILED`. The optional global or trusted-project `worktreePostCreateCommand` setting runs its executable and arguments directly, once after a physical checkout, from the launch-relative directory inside the new worktree. Install that external executable separately; missing executables, nonzero exits, spawn failures, and the fixed 60-second timeout fail with `WORKTREE_FAILED` and roll back creation. The setting is captured when the subagent starts, and an untrusted project cannot enable it. The executor runs in the worktree and inspection exposes its path and branch while materialized. Cleanup runs when the agent settles, stops, or the manager reconciles an interrupted record. After successful cleanup, the public and persisted worktree path, branch, and cleanup context are removed; if cleanup fails, all of that metadata is retained for a later retry. A run ID keeps concurrent worktrees separate even when their names are the same.
|
|
102
|
+
|
|
103
|
+
## Agent options, roles, and settings
|
|
104
|
+
|
|
105
|
+
`subagents_run` accepts the same execution options as a workflow `agent(...)`: model, thinking level, tool, skill, and extension selectors, named roles or inline role overrides, worktrees, structured output, retries, and timeout. The extension also reuses workflow model aliases, settings, resource selector policy, and role discovery:
|
|
106
|
+
|
|
107
|
+
- global roles: `<agentDir>/pi-extensible-workflows/roles/<name>.md`, normally `~/.pi/agent/pi-extensible-workflows/roles/`;
|
|
108
|
+
- trusted project roles: `<cwd>/.pi/pi-extensible-workflows/roles/<name>.md`;
|
|
109
|
+
- global and trusted project settings: the normal workflow settings path under the agent directory and `<cwd>/.pi/pi-extensible-workflows/settings.json`.
|
|
110
|
+
|
|
111
|
+
The current Pi model, thinking level, active tools, project trust, session ID, role definitions, aliases, and resource policy are captured from the extension context for each run. Internal workflow and subagent control tools are not exposed to the child agent.
|
|
112
|
+
|
|
113
|
+
## Programmatic host integration
|
|
114
|
+
|
|
115
|
+
Pi discovers this extension through the core package's `pi.extensions` manifest. The manifest entry point is `subagents/index.ts` in the core package; Pi loads this TypeScript entry directly. The following host-integration sketch is pseudocode; Pi supplies `pi` and a host may supply the optional manager:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import extension, { type SubagentManager } from "./index.js";
|
|
119
|
+
|
|
120
|
+
const manager: SubagentManager = /* host implementation, or omit this option */;
|
|
121
|
+
extension(pi, { manager });
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The default export registers the five tools. `createSubagentManager()` and `createSubagentTools()` are also exported for hosts that need explicit lifecycle or dependency injection.
|
|
125
|
+
|
|
126
|
+
## Shutdown and restoration
|
|
127
|
+
|
|
128
|
+
The default extension subscribes to `session_shutdown`. Disposal aborts active runs, disposes owned agent sessions and listeners, cleans active worktrees, waits for pending completion notifications, releases the storage owner, and is idempotent. Terminal records and results remain on disk. Terminal worktree path, branch, and cleanup context are removed after successful cleanup; failed cleanup retains all three for retry on a later manager startup.
|
|
129
|
+
|
|
130
|
+
**Cross-session restoration of a live native subagent session is unsupported.** On a new manager, a persisted `running` record is reconciled to `failed` with an interruption error unless a result or failure was already persisted. Use `subagents_retry` to start a new run; it does not restore conversation context or reuse the old native session. Persisted completed and failed records remain readable, subject to the storage owner and filesystem being available.
|
|
131
|
+
|
|
132
|
+
## Migrating from v5.3 to v5.4
|
|
133
|
+
|
|
134
|
+
The v5.4 release removes the seven-tool surface's redundant `subagents_list`, `subagents_status`, and `subagents_result` names. There are no compatibility aliases. Replace calls as follows:
|
|
135
|
+
|
|
136
|
+
| v5.3 call | v5.4 call |
|
|
137
|
+
| --- | --- |
|
|
138
|
+
| `subagents_run({ prompt, ... })` | unchanged for background runs; `mode: "foreground"` is new |
|
|
139
|
+
| `subagents_list({})` | `subagents_inspect({})` |
|
|
140
|
+
| `subagents_status({ id })` followed by `subagents_result({ id })` | `subagents_inspect({ id })` |
|
|
141
|
+
| `subagents_steer({ id, message })` | unchanged |
|
|
142
|
+
| `subagents_stop({ id })` | unchanged |
|
|
143
|
+
| `subagents_retry({ id })` | unchanged; the original launch mode is preserved |
|
|
144
|
+
|
|
145
|
+
The standalone manager deliberately keeps durable run IDs, repeatable inspection, bounded steering, named worktree cleanup, and workflow role/settings reuse.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public package entry point for the Pi subagents extension.
|
|
3
|
+
*
|
|
4
|
+
* Pi discovers the compiled default export from the package manifest. The entry point registers the namespaced
|
|
5
|
+
* standalone tools; the manager API can also be imported directly.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./src/index.js";
|
|
8
|
+
export { default } from "./src/index.js";
|