@davidorex/pi-workflows 0.2.0 → 0.3.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 +7 -4
- package/README.md +12 -2
- package/agents/architecture-designer.agent.yaml +58 -0
- package/agents/architecture-inferrer.agent.yaml +60 -0
- package/agents/gap-identifier.agent.yaml +66 -0
- package/agents/handoff-writer.agent.yaml +64 -0
- package/agents/plan-creator.agent.yaml +63 -0
- package/agents/project-definer.agent.yaml +53 -0
- package/agents/project-inferrer.agent.yaml +63 -0
- package/agents/requirements-gatherer.agent.yaml +58 -0
- package/dist/agent-spec.d.ts +27 -0
- package/dist/agent-spec.d.ts.map +1 -0
- package/dist/agent-spec.js +112 -0
- package/dist/agent-spec.js.map +1 -0
- package/dist/checkpoint.d.ts +50 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +109 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/completion.d.ts +18 -0
- package/dist/completion.d.ts.map +1 -0
- package/dist/completion.js +58 -0
- package/dist/completion.js.map +1 -0
- package/dist/dag.d.ts +56 -0
- package/dist/dag.d.ts.map +1 -0
- package/dist/dag.js +178 -0
- package/dist/dag.js.map +1 -0
- package/dist/dispatch.d.ts +35 -0
- package/dist/dispatch.d.ts.map +1 -0
- package/dist/dispatch.js +311 -0
- package/dist/dispatch.js.map +1 -0
- package/dist/expression.d.ts +64 -0
- package/dist/expression.d.ts.map +1 -0
- package/dist/expression.js +294 -0
- package/dist/expression.js.map +1 -0
- package/dist/format.d.ts +19 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +42 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +724 -0
- package/dist/index.js.map +1 -0
- package/dist/output.d.ts +12 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +59 -0
- package/dist/output.js.map +1 -0
- package/dist/state.d.ts +66 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +227 -0
- package/dist/state.js.map +1 -0
- package/dist/step-agent.d.ts +35 -0
- package/dist/step-agent.d.ts.map +1 -0
- package/dist/step-agent.js +171 -0
- package/dist/step-agent.js.map +1 -0
- package/dist/step-command.d.ts +21 -0
- package/dist/step-command.d.ts.map +1 -0
- package/dist/step-command.js +150 -0
- package/dist/step-command.js.map +1 -0
- package/dist/step-foreach.d.ts +33 -0
- package/dist/step-foreach.d.ts.map +1 -0
- package/dist/step-foreach.js +112 -0
- package/dist/step-foreach.js.map +1 -0
- package/dist/step-gate.d.ts +18 -0
- package/dist/step-gate.d.ts.map +1 -0
- package/dist/step-gate.js +137 -0
- package/dist/step-gate.js.map +1 -0
- package/dist/step-loop.d.ts +32 -0
- package/dist/step-loop.d.ts.map +1 -0
- package/dist/step-loop.js +278 -0
- package/dist/step-loop.js.map +1 -0
- package/dist/step-monitor.d.ts +56 -0
- package/dist/step-monitor.d.ts.map +1 -0
- package/dist/step-monitor.js +317 -0
- package/dist/step-monitor.js.map +1 -0
- package/dist/step-parallel.d.ts +43 -0
- package/dist/step-parallel.d.ts.map +1 -0
- package/dist/step-parallel.js +122 -0
- package/dist/step-parallel.js.map +1 -0
- package/{src/step-pause.ts → dist/step-pause.d.ts} +3 -13
- package/dist/step-pause.d.ts.map +1 -0
- package/dist/step-pause.js +22 -0
- package/dist/step-pause.js.map +1 -0
- package/dist/step-shared.d.ts +63 -0
- package/dist/step-shared.d.ts.map +1 -0
- package/dist/step-shared.js +136 -0
- package/dist/step-shared.js.map +1 -0
- package/dist/step-transform.d.ts +11 -0
- package/dist/step-transform.d.ts.map +1 -0
- package/dist/step-transform.js +41 -0
- package/dist/step-transform.js.map +1 -0
- package/dist/template.d.ts +51 -0
- package/dist/template.d.ts.map +1 -0
- package/{src/template.ts → dist/template.js} +32 -38
- package/dist/template.js.map +1 -0
- package/dist/test-helpers.d.ts +17 -0
- package/dist/test-helpers.d.ts.map +1 -0
- package/dist/test-helpers.js +46 -0
- package/dist/test-helpers.js.map +1 -0
- package/dist/tui.d.ts +47 -0
- package/dist/tui.d.ts.map +1 -0
- package/dist/tui.js +143 -0
- package/dist/tui.js.map +1 -0
- package/dist/types.d.ts +165 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/workflow-discovery.d.ts +23 -0
- package/dist/workflow-discovery.d.ts.map +1 -0
- package/dist/workflow-discovery.js +103 -0
- package/dist/workflow-discovery.js.map +1 -0
- package/dist/workflow-executor.d.ts +50 -0
- package/dist/workflow-executor.d.ts.map +1 -0
- package/dist/workflow-executor.js +738 -0
- package/dist/workflow-executor.js.map +1 -0
- package/dist/workflow-sdk.d.ts +44 -0
- package/dist/workflow-sdk.d.ts.map +1 -0
- package/dist/workflow-sdk.js +457 -0
- package/dist/workflow-sdk.js.map +1 -0
- package/dist/workflow-spec.d.ts +33 -0
- package/dist/workflow-spec.d.ts.map +1 -0
- package/dist/workflow-spec.js +476 -0
- package/dist/workflow-spec.js.map +1 -0
- package/dist/workflows-dir.d.ts +3 -0
- package/dist/workflows-dir.d.ts.map +1 -0
- package/{src/workflows-dir.ts → dist/workflows-dir.js} +1 -0
- package/dist/workflows-dir.js.map +1 -0
- package/package.json +53 -38
- package/schemas/decomposition-specs.schema.json +48 -48
- package/schemas/execution-results.schema.json +48 -48
- package/schemas/investigation-findings.schema.json +43 -43
- package/schemas/pattern-analysis.schema.json +41 -41
- package/schemas/phase.schema.json +48 -0
- package/schemas/plan-breakdown.schema.json +20 -20
- package/schemas/quality-analysis.schema.json +33 -33
- package/schemas/research-findings.schema.json +42 -42
- package/schemas/structure-analysis.schema.json +40 -40
- package/schemas/synthesis.schema.json +31 -31
- package/schemas/verifier-output.schema.json +94 -94
- package/skill-narrative.md +107 -0
- package/skills/pi-workflows/SKILL.md +185 -0
- package/skills/pi-workflows/references/bundled-resources.md +87 -0
- package/templates/architecture-designer/task.md +117 -0
- package/templates/architecture-inferrer/task.md +61 -0
- package/templates/gap-identifier/task.md +103 -0
- package/templates/handoff-writer/task.md +91 -0
- package/templates/plan-creator/task.md +143 -0
- package/templates/project-definer/task.md +67 -0
- package/templates/project-inferrer/task.md +56 -0
- package/templates/requirements-gatherer/task.md +90 -0
- package/workflows/analyze-existing-project.workflow.yaml +94 -0
- package/workflows/create-handoff.workflow.yaml +66 -0
- package/workflows/create-phase.workflow.yaml +1 -1
- package/workflows/do-gap.workflow.yaml +4 -4
- package/workflows/fix-audit.workflow.yaml +1 -1
- package/workflows/gap-to-phase.workflow.yaml +1 -1
- package/workflows/init-new-project.workflow.yaml +81 -0
- package/workflows/plan-from-requirements.workflow.yaml +59 -0
- package/workflows/self-implement.workflow.yaml +3 -3
- package/workflows/typed-analysis.workflow.yaml +4 -4
- package/src/agent-spec.test.ts +0 -289
- package/src/agent-spec.ts +0 -122
- package/src/block-validation.test.ts +0 -350
- package/src/checkpoint.test.ts +0 -237
- package/src/checkpoint.ts +0 -140
- package/src/completion.test.ts +0 -143
- package/src/completion.ts +0 -68
- package/src/dag.test.ts +0 -350
- package/src/dag.ts +0 -219
- package/src/dispatch.test.ts +0 -475
- package/src/dispatch.ts +0 -353
- package/src/expression.test.ts +0 -353
- package/src/expression.ts +0 -332
- package/src/format.test.ts +0 -80
- package/src/format.ts +0 -41
- package/src/graduated-failure.test.ts +0 -556
- package/src/index.test.ts +0 -114
- package/src/index.ts +0 -516
- package/src/loop.test.ts +0 -551
- package/src/output.test.ts +0 -213
- package/src/output.ts +0 -70
- package/src/parallel-integration.test.ts +0 -175
- package/src/resume.test.ts +0 -192
- package/src/state.test.ts +0 -192
- package/src/state.ts +0 -254
- package/src/step-agent.test.ts +0 -327
- package/src/step-agent.ts +0 -178
- package/src/step-command.test.ts +0 -330
- package/src/step-command.ts +0 -132
- package/src/step-foreach.test.ts +0 -647
- package/src/step-foreach.ts +0 -148
- package/src/step-gate.test.ts +0 -185
- package/src/step-gate.ts +0 -116
- package/src/step-loop.test.ts +0 -626
- package/src/step-loop.ts +0 -323
- package/src/step-parallel.test.ts +0 -475
- package/src/step-parallel.ts +0 -168
- package/src/step-pause.test.ts +0 -30
- package/src/step-shared.test.ts +0 -355
- package/src/step-shared.ts +0 -157
- package/src/step-transform.test.ts +0 -155
- package/src/step-transform.ts +0 -47
- package/src/template-integration.test.ts +0 -72
- package/src/template.test.ts +0 -162
- package/src/test-helpers.ts +0 -51
- package/src/tui.test.ts +0 -355
- package/src/tui.ts +0 -182
- package/src/types.ts +0 -195
- package/src/verifier-schema.test.ts +0 -226
- package/src/workflow-discovery.test.ts +0 -105
- package/src/workflow-discovery.ts +0 -114
- package/src/workflow-executor.test.ts +0 -1532
- package/src/workflow-executor.ts +0 -810
- package/src/workflow-sdk.test.ts +0 -238
- package/src/workflow-sdk.ts +0 -262
- package/src/workflow-spec.test.ts +0 -576
- package/src/workflow-spec.ts +0 -471
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate step executor — runs a shell command and passes/fails based on exit code.
|
|
3
|
+
*/
|
|
4
|
+
import { persistStepOutput } from "./output.js";
|
|
5
|
+
import { SIGKILL_GRACE_MS, zeroUsage } from "./step-shared.js";
|
|
6
|
+
/**
|
|
7
|
+
* Execute a gate step: runs a shell command, passes/fails based on exit code.
|
|
8
|
+
*
|
|
9
|
+
* The gate's check command is expected to already have ${{ }} expressions resolved
|
|
10
|
+
* before being passed here.
|
|
11
|
+
*/
|
|
12
|
+
export async function executeGate(gate, stepName, options) {
|
|
13
|
+
const startTime = Date.now();
|
|
14
|
+
try {
|
|
15
|
+
const { spawn } = await import("node:child_process");
|
|
16
|
+
const output = await new Promise((resolve, reject) => {
|
|
17
|
+
const proc = spawn("sh", ["-c", gate.check], {
|
|
18
|
+
cwd: options.cwd,
|
|
19
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
20
|
+
detached: true,
|
|
21
|
+
});
|
|
22
|
+
let stdout = "";
|
|
23
|
+
let stderr = "";
|
|
24
|
+
let settled = false;
|
|
25
|
+
proc.stdout.on("data", (d) => {
|
|
26
|
+
stdout += d.toString();
|
|
27
|
+
});
|
|
28
|
+
proc.stderr.on("data", (d) => {
|
|
29
|
+
stderr += d.toString();
|
|
30
|
+
});
|
|
31
|
+
// Kill the entire process group (sh + children like sleep)
|
|
32
|
+
const killProc = () => {
|
|
33
|
+
if (!proc.pid)
|
|
34
|
+
return;
|
|
35
|
+
try {
|
|
36
|
+
process.kill(-proc.pid, "SIGTERM");
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
/* already dead */
|
|
40
|
+
}
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
if (!proc.pid)
|
|
43
|
+
return;
|
|
44
|
+
try {
|
|
45
|
+
process.kill(-proc.pid, "SIGKILL");
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
/* already dead */
|
|
49
|
+
}
|
|
50
|
+
}, SIGKILL_GRACE_MS);
|
|
51
|
+
};
|
|
52
|
+
// Handle abort signal (from parallel cancellation or timeout)
|
|
53
|
+
const onAbort = () => {
|
|
54
|
+
killProc();
|
|
55
|
+
};
|
|
56
|
+
if (options.signal) {
|
|
57
|
+
if (options.signal.aborted) {
|
|
58
|
+
killProc();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Handle step-level timeout
|
|
65
|
+
let timeoutId;
|
|
66
|
+
if (options.timeoutMs) {
|
|
67
|
+
timeoutId = setTimeout(() => {
|
|
68
|
+
killProc();
|
|
69
|
+
}, options.timeoutMs);
|
|
70
|
+
}
|
|
71
|
+
proc.on("close", (code) => {
|
|
72
|
+
if (settled)
|
|
73
|
+
return;
|
|
74
|
+
settled = true;
|
|
75
|
+
if (timeoutId)
|
|
76
|
+
clearTimeout(timeoutId);
|
|
77
|
+
if (options.signal)
|
|
78
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
79
|
+
if (code === 0) {
|
|
80
|
+
resolve(stdout);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const err = new Error(`Process exited with code ${code}`);
|
|
84
|
+
err.status = code;
|
|
85
|
+
err.stdout = stdout;
|
|
86
|
+
err.stderr = stderr;
|
|
87
|
+
reject(err);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
proc.on("error", (err) => {
|
|
91
|
+
if (settled)
|
|
92
|
+
return;
|
|
93
|
+
settled = true;
|
|
94
|
+
if (timeoutId)
|
|
95
|
+
clearTimeout(timeoutId);
|
|
96
|
+
if (options.signal)
|
|
97
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
98
|
+
reject(err);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
const gateOutput = { passed: true, exitCode: 0, output: output.trim() };
|
|
102
|
+
const result = {
|
|
103
|
+
step: stepName,
|
|
104
|
+
agent: "gate",
|
|
105
|
+
status: "completed",
|
|
106
|
+
textOutput: output.trim(),
|
|
107
|
+
output: gateOutput,
|
|
108
|
+
usage: zeroUsage(),
|
|
109
|
+
durationMs: Date.now() - startTime,
|
|
110
|
+
};
|
|
111
|
+
if (options.runDir) {
|
|
112
|
+
result.outputPath = persistStepOutput(options.runDir, stepName, gateOutput, undefined, options.outputPath);
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
const execErr = err;
|
|
118
|
+
const exitCode = execErr.status ?? 1;
|
|
119
|
+
const stderr = execErr.stderr?.trim() ?? "";
|
|
120
|
+
const stdout = execErr.stdout?.trim() ?? "";
|
|
121
|
+
const gateOutput = { passed: false, exitCode, output: stderr || stdout };
|
|
122
|
+
const result = {
|
|
123
|
+
step: stepName,
|
|
124
|
+
agent: "gate",
|
|
125
|
+
status: "completed",
|
|
126
|
+
textOutput: stderr || stdout,
|
|
127
|
+
output: gateOutput,
|
|
128
|
+
usage: zeroUsage(),
|
|
129
|
+
durationMs: Date.now() - startTime,
|
|
130
|
+
};
|
|
131
|
+
if (options.runDir) {
|
|
132
|
+
result.outputPath = persistStepOutput(options.runDir, stepName, gateOutput, undefined, options.outputPath);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=step-gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-gate.js","sourceRoot":"","sources":["../src/step-gate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG/D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,IAAc,EACd,QAAgB,EAChB,OAAwG;IAExG,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,IAAI,CAAC;QACJ,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;QACrD,MAAM,MAAM,GAAG,MAAM,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;gBAC5C,GAAG,EAAE,OAAO,CAAC,GAAG;gBAChB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;gBACjC,QAAQ,EAAE,IAAI;aACd,CAAC,CAAC;YAEH,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAS,EAAE,EAAE;gBACpC,MAAM,IAAI,CAAC,CAAC,QAAQ,EA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pB,MAAM,CAAC,UAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAC5G,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type nunjucks from "nunjucks";
|
|
2
|
+
import type { AgentSpec, ExecutionState, LoopSpec, StepResult, StepSpec, WorkflowSpec } from "./types.js";
|
|
3
|
+
/** Options for executeLoop, including callback-injected dispatch to avoid circular imports. */
|
|
4
|
+
export interface LoopExecuteOptions {
|
|
5
|
+
ctx: any;
|
|
6
|
+
pi: any;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
loadAgent: (name: string) => AgentSpec;
|
|
9
|
+
dispatchAgent: (stepSpec: StepSpec, agentSpec: AgentSpec, prompt: string, opts: {
|
|
10
|
+
cwd: string;
|
|
11
|
+
sessionLogDir: string;
|
|
12
|
+
stepName: string;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}) => Promise<StepResult>;
|
|
15
|
+
runDir: string;
|
|
16
|
+
spec: WorkflowSpec;
|
|
17
|
+
templateEnv?: nunjucks.Environment;
|
|
18
|
+
outputPath?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Execute a loop step: runs sub-steps repeatedly until a gate breaks,
|
|
22
|
+
* max attempts is reached, or a step fails.
|
|
23
|
+
*
|
|
24
|
+
* Loop sub-steps can be agent, gate, or transform steps.
|
|
25
|
+
* Gates inside loops support onPass: "break" (stop looping on success)
|
|
26
|
+
* and onFail: "continue" (retry on failure, the default inside loops).
|
|
27
|
+
*
|
|
28
|
+
* The loop scope provides ${{ loop.iteration }}, ${{ loop.maxAttempts }},
|
|
29
|
+
* and ${{ loop.priorAttempts }} for expression resolution inside sub-steps.
|
|
30
|
+
*/
|
|
31
|
+
export declare function executeLoop(loopSpec: LoopSpec, stepName: string, state: ExecutionState, options: LoopExecuteOptions): Promise<StepResult>;
|
|
32
|
+
//# sourceMappingURL=step-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-loop.d.ts","sourceRoot":"","sources":["../src/step-loop.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAMrC,OAAO,KAAK,EACX,SAAS,EACT,cAAc,EAEd,QAAQ,EACR,UAAU,EACV,QAAQ,EAER,YAAY,EACZ,MAAM,YAAY,CAAC;AAEpB,+FAA+F;AAC/F,MAAM,WAAW,kBAAkB;IAClC,GAAG,EAAE,GAAG,CAAC;IACT,EAAE,EAAE,GAAG,CAAC;IACR,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC;IACvC,aAAa,EAAE,CACd,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,KAChF,OAAO,CAAC,UAAU,CAAC,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAChC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,UAAU,CAAC,CAiRrB"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop step executor — runs sub-steps repeatedly until a gate breaks,
|
|
3
|
+
* max attempts is reached, or a step fails.
|
|
4
|
+
*/
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { evaluateCondition, resolveExpressions } from "./expression.js";
|
|
7
|
+
import { persistStepOutput } from "./output.js";
|
|
8
|
+
import { executeGate } from "./step-gate.js";
|
|
9
|
+
import { addUsage, buildPrompt, compileAgentSpec, DEFAULT_MAX_ATTEMPTS, zeroUsage } from "./step-shared.js";
|
|
10
|
+
import { executeTransform } from "./step-transform.js";
|
|
11
|
+
/**
|
|
12
|
+
* Execute a loop step: runs sub-steps repeatedly until a gate breaks,
|
|
13
|
+
* max attempts is reached, or a step fails.
|
|
14
|
+
*
|
|
15
|
+
* Loop sub-steps can be agent, gate, or transform steps.
|
|
16
|
+
* Gates inside loops support onPass: "break" (stop looping on success)
|
|
17
|
+
* and onFail: "continue" (retry on failure, the default inside loops).
|
|
18
|
+
*
|
|
19
|
+
* The loop scope provides ${{ loop.iteration }}, ${{ loop.maxAttempts }},
|
|
20
|
+
* and ${{ loop.priorAttempts }} for expression resolution inside sub-steps.
|
|
21
|
+
*/
|
|
22
|
+
export async function executeLoop(loopSpec, stepName, state, options) {
|
|
23
|
+
const { ctx, signal, loadAgent, dispatchAgent, runDir } = options;
|
|
24
|
+
const startTime = Date.now();
|
|
25
|
+
// Resolve maxAttempts (may be a ${{ }} expression)
|
|
26
|
+
const scope = { input: state.input, steps: state.steps };
|
|
27
|
+
let maxAttempts;
|
|
28
|
+
if (loopSpec.attempts) {
|
|
29
|
+
const resolved = resolveExpressions(loopSpec.attempts, scope);
|
|
30
|
+
maxAttempts = Number(resolved);
|
|
31
|
+
if (isNaN(maxAttempts) || maxAttempts < 1)
|
|
32
|
+
maxAttempts = loopSpec.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
maxAttempts = loopSpec.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
|
|
36
|
+
}
|
|
37
|
+
const allAttempts = [];
|
|
38
|
+
let loopStatus = "failed"; // assume failure until break
|
|
39
|
+
let lastIterationSteps = {};
|
|
40
|
+
for (let iteration = 0; iteration < maxAttempts; iteration++) {
|
|
41
|
+
// Check cancellation
|
|
42
|
+
if (signal?.aborted)
|
|
43
|
+
break;
|
|
44
|
+
const iterationSteps = {};
|
|
45
|
+
let shouldBreak = false;
|
|
46
|
+
let iterationFailed = false;
|
|
47
|
+
// Execute sub-steps sequentially
|
|
48
|
+
const subStepEntries = Object.entries(loopSpec.steps);
|
|
49
|
+
for (const [subName, subSpec] of subStepEntries) {
|
|
50
|
+
if (signal?.aborted)
|
|
51
|
+
break;
|
|
52
|
+
// Build scope with loop context
|
|
53
|
+
const subScope = {
|
|
54
|
+
input: state.input,
|
|
55
|
+
steps: { ...state.steps, ...iterationSteps }, // see prior sub-steps in this iteration
|
|
56
|
+
loop: {
|
|
57
|
+
iteration,
|
|
58
|
+
maxAttempts,
|
|
59
|
+
priorAttempts: allAttempts,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
// Handle `when` conditional
|
|
63
|
+
if (subSpec.when) {
|
|
64
|
+
const condExpr = subSpec.when.replace(/^\$\{\{\s*/, "").replace(/\s*\}\}$/, "");
|
|
65
|
+
if (!evaluateCondition(condExpr, subScope)) {
|
|
66
|
+
iterationSteps[subName] = {
|
|
67
|
+
step: subName,
|
|
68
|
+
agent: subSpec.agent ?? "skipped",
|
|
69
|
+
status: "skipped",
|
|
70
|
+
usage: zeroUsage(),
|
|
71
|
+
durationMs: 0,
|
|
72
|
+
};
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Execute sub-step based on type
|
|
77
|
+
let result;
|
|
78
|
+
if (subSpec.gate) {
|
|
79
|
+
const resolvedCheck = String(resolveExpressions(subSpec.gate.check, subScope));
|
|
80
|
+
result = await executeGate({ ...subSpec.gate, check: resolvedCheck }, subName, { cwd: ctx.cwd, signal });
|
|
81
|
+
// Handle gate pass/fail with break/continue
|
|
82
|
+
const passed = result.output?.passed;
|
|
83
|
+
if (passed && subSpec.gate.onPass === "break") {
|
|
84
|
+
iterationSteps[subName] = result;
|
|
85
|
+
shouldBreak = true;
|
|
86
|
+
loopStatus = "completed";
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (!passed) {
|
|
90
|
+
if (subSpec.gate.onFail === "break") {
|
|
91
|
+
iterationSteps[subName] = result;
|
|
92
|
+
shouldBreak = true;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (subSpec.gate.onFail === "fail") {
|
|
96
|
+
// Explicitly set to "fail" — stop the loop
|
|
97
|
+
result.status = "failed";
|
|
98
|
+
iterationSteps[subName] = result;
|
|
99
|
+
iterationFailed = true;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
// Default inside loops is "continue" — proceed to next sub-step
|
|
103
|
+
// (or end iteration, triggering retry)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (subSpec.transform) {
|
|
107
|
+
result = executeTransform(subSpec.transform, subName, subScope);
|
|
108
|
+
if (result.status === "failed") {
|
|
109
|
+
iterationSteps[subName] = result;
|
|
110
|
+
iterationFailed = true;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (subSpec.agent) {
|
|
115
|
+
// Resolve input, load agent, dispatch
|
|
116
|
+
let resolvedInput;
|
|
117
|
+
try {
|
|
118
|
+
resolvedInput = resolveExpressions(subSpec.input ?? {}, subScope);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
iterationSteps[subName] = {
|
|
122
|
+
step: subName,
|
|
123
|
+
agent: subSpec.agent,
|
|
124
|
+
status: "failed",
|
|
125
|
+
usage: zeroUsage(),
|
|
126
|
+
durationMs: 0,
|
|
127
|
+
error: err instanceof Error ? err.message : String(err),
|
|
128
|
+
};
|
|
129
|
+
iterationFailed = true;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
let agentSpec;
|
|
133
|
+
try {
|
|
134
|
+
agentSpec = loadAgent(subSpec.agent);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
iterationSteps[subName] = {
|
|
138
|
+
step: subName,
|
|
139
|
+
agent: subSpec.agent,
|
|
140
|
+
status: "failed",
|
|
141
|
+
usage: zeroUsage(),
|
|
142
|
+
durationMs: 0,
|
|
143
|
+
error: err instanceof Error ? err.message : String(err),
|
|
144
|
+
};
|
|
145
|
+
iterationFailed = true;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
agentSpec = compileAgentSpec(agentSpec, resolvedInput, options.templateEnv);
|
|
149
|
+
const prompt = buildPrompt(subSpec, agentSpec, resolvedInput, runDir, `${stepName}-${iteration}-${subName}`);
|
|
150
|
+
result = await dispatchAgent(subSpec, agentSpec, prompt, {
|
|
151
|
+
cwd: ctx.cwd,
|
|
152
|
+
sessionLogDir: path.join(runDir, "sessions"),
|
|
153
|
+
stepName: `${stepName}-${iteration}-${subName}`,
|
|
154
|
+
signal,
|
|
155
|
+
});
|
|
156
|
+
if (result.status === "failed") {
|
|
157
|
+
iterationSteps[subName] = result;
|
|
158
|
+
iterationFailed = true;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
continue; // unknown step type, skip
|
|
164
|
+
}
|
|
165
|
+
iterationSteps[subName] = result;
|
|
166
|
+
}
|
|
167
|
+
// Record this iteration
|
|
168
|
+
lastIterationSteps = iterationSteps;
|
|
169
|
+
allAttempts.push({ iteration, steps: iterationSteps });
|
|
170
|
+
if (shouldBreak)
|
|
171
|
+
break;
|
|
172
|
+
if (iterationFailed) {
|
|
173
|
+
// Agent step failed within loop — stop the loop (not just the iteration)
|
|
174
|
+
loopStatus = "failed";
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
// End of iteration without break — loop continues to next iteration
|
|
178
|
+
}
|
|
179
|
+
// If loop exhausted without break or failure, run onExhausted
|
|
180
|
+
if (loopStatus !== "completed" && loopSpec.onExhausted) {
|
|
181
|
+
const exhaustedScope = {
|
|
182
|
+
input: state.input,
|
|
183
|
+
steps: state.steps,
|
|
184
|
+
loop: {
|
|
185
|
+
iteration: allAttempts.length,
|
|
186
|
+
maxAttempts,
|
|
187
|
+
priorAttempts: allAttempts,
|
|
188
|
+
allAttempts,
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
let resolvedInput;
|
|
192
|
+
let exhaustedError;
|
|
193
|
+
try {
|
|
194
|
+
resolvedInput = resolveExpressions(loopSpec.onExhausted.input ?? {}, exhaustedScope);
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
exhaustedError = err instanceof Error ? err.message : String(err);
|
|
198
|
+
// Still proceed with onExhausted — let the agent run with empty input
|
|
199
|
+
// but record the expression error so it's visible in the result
|
|
200
|
+
}
|
|
201
|
+
if (loopSpec.onExhausted.agent) {
|
|
202
|
+
let agentSpec;
|
|
203
|
+
try {
|
|
204
|
+
agentSpec = loadAgent(loopSpec.onExhausted.agent);
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
lastIterationSteps["_exhausted"] = {
|
|
208
|
+
step: `${stepName}-exhausted`,
|
|
209
|
+
agent: loopSpec.onExhausted.agent,
|
|
210
|
+
status: "failed",
|
|
211
|
+
usage: zeroUsage(),
|
|
212
|
+
durationMs: 0,
|
|
213
|
+
error: err instanceof Error ? err.message : String(err),
|
|
214
|
+
};
|
|
215
|
+
agentSpec = null;
|
|
216
|
+
}
|
|
217
|
+
if (agentSpec) {
|
|
218
|
+
const prompt = buildPrompt(loopSpec.onExhausted, agentSpec, resolvedInput, runDir, `${stepName}-exhausted`);
|
|
219
|
+
const exhaustedResult = await dispatchAgent(loopSpec.onExhausted, agentSpec, prompt, {
|
|
220
|
+
cwd: ctx.cwd,
|
|
221
|
+
sessionLogDir: path.join(runDir, "sessions"),
|
|
222
|
+
stepName: `${stepName}-exhausted`,
|
|
223
|
+
signal,
|
|
224
|
+
});
|
|
225
|
+
if (exhaustedResult && exhaustedError) {
|
|
226
|
+
exhaustedResult.error = `Expression error in onExhausted input: ${exhaustedError}. Agent ran with empty input.`;
|
|
227
|
+
}
|
|
228
|
+
// Include exhausted result in the loop's output
|
|
229
|
+
lastIterationSteps["_exhausted"] = exhaustedResult;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (!loopSpec.onExhausted.agent && exhaustedError) {
|
|
233
|
+
lastIterationSteps["_exhausted"] = {
|
|
234
|
+
step: `${stepName}-exhausted`,
|
|
235
|
+
agent: "exhausted",
|
|
236
|
+
status: "failed",
|
|
237
|
+
usage: zeroUsage(),
|
|
238
|
+
durationMs: 0,
|
|
239
|
+
error: `Expression error in onExhausted input: ${exhaustedError}`,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// Aggregate usage across all iterations
|
|
244
|
+
const totalUsage = zeroUsage();
|
|
245
|
+
for (const attempt of allAttempts) {
|
|
246
|
+
for (const result of Object.values(attempt.steps)) {
|
|
247
|
+
addUsage(totalUsage, result.usage);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const loopOutput = {
|
|
251
|
+
iterations: allAttempts.length,
|
|
252
|
+
maxAttempts,
|
|
253
|
+
attempts: allAttempts,
|
|
254
|
+
lastIteration: lastIterationSteps,
|
|
255
|
+
};
|
|
256
|
+
const loopTextOutput = `Loop '${stepName}': ${allAttempts.length}/${maxAttempts} iterations, status: ${loopStatus}`;
|
|
257
|
+
const result = {
|
|
258
|
+
step: stepName,
|
|
259
|
+
agent: "loop",
|
|
260
|
+
status: loopStatus,
|
|
261
|
+
output: loopOutput,
|
|
262
|
+
textOutput: loopTextOutput,
|
|
263
|
+
usage: totalUsage,
|
|
264
|
+
durationMs: Date.now() - startTime,
|
|
265
|
+
};
|
|
266
|
+
// Propagate truncation from any sub-step
|
|
267
|
+
const anyTruncated = allAttempts.some((a) => Object.values(a.steps).some((s) => s.truncated));
|
|
268
|
+
if (anyTruncated) {
|
|
269
|
+
result.truncated = true;
|
|
270
|
+
result.warnings = [
|
|
271
|
+
...(result.warnings ?? []),
|
|
272
|
+
"One or more loop sub-steps had truncated stdout — usage totals may undercount.",
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
result.outputPath = persistStepOutput(runDir, stepName, loopOutput, loopTextOutput, options.outputPath);
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=step-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-loop.js","sourceRoot":"","sources":["../src/step-loop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5G,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AA8BvD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,QAAkB,EAClB,QAAgB,EAChB,KAAqB,EACrB,OAA2B;IAE3B,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAClE,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,mDAAmD;IACnD,MAAM,KAAK,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACzD,IAAI,WAAmB,CAAC;IACxB,IAAI,QAAQ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I,YAAY,EAAE,CAAC;QAClB,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC;QACxB,MAAM,CAAC,QAAQ,GAAG;YACjB,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;YAC1B,gFAAgF;SAChF,CAAC;IACH,CAAC;IAED,MAAM,CAAC,UAAU,GAAG,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACxG,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Monitor step executor — runs a monitor's classification as a workflow
|
|
3
|
+
* verification gate. Lightweight: reads monitor spec, loads patterns,
|
|
4
|
+
* renders prompt (Nunjucks or inline), calls LLM, parses verdict.
|
|
5
|
+
*
|
|
6
|
+
* Does NOT depend on pi-behavior-monitors — implements just enough to
|
|
7
|
+
* classify. No event handling, steering, ceiling, or escalation.
|
|
8
|
+
*/
|
|
9
|
+
import type { ExtensionContext } from "@mariozechner/pi-coding-agent";
|
|
10
|
+
import type { StepResult } from "./types.js";
|
|
11
|
+
interface MonitorSpec {
|
|
12
|
+
name: string;
|
|
13
|
+
classify: {
|
|
14
|
+
model: string;
|
|
15
|
+
context: string[];
|
|
16
|
+
prompt: string;
|
|
17
|
+
promptTemplate?: string;
|
|
18
|
+
};
|
|
19
|
+
patterns: {
|
|
20
|
+
path: string;
|
|
21
|
+
};
|
|
22
|
+
instructions?: {
|
|
23
|
+
path: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Find a monitor spec by name. Searches:
|
|
28
|
+
* 1. .pi/monitors/ (project)
|
|
29
|
+
* 2. ~/.pi/agent/monitors/ (user)
|
|
30
|
+
* 3. pi-behavior-monitors examples (if installed as peer)
|
|
31
|
+
*/
|
|
32
|
+
export declare function findMonitorSpec(monitorName: string, cwd: string): {
|
|
33
|
+
spec: MonitorSpec;
|
|
34
|
+
dir: string;
|
|
35
|
+
} | null;
|
|
36
|
+
export interface MonitorStepOptions {
|
|
37
|
+
cwd: string;
|
|
38
|
+
ctx: ExtensionContext;
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
runDir?: string;
|
|
41
|
+
outputPath?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Execute a monitor step: discover monitor, render prompt, classify, return verdict.
|
|
45
|
+
*
|
|
46
|
+
* - CLEAN → status: "completed", output: { verdict: "clean" }
|
|
47
|
+
* - FLAG → status: "failed", output: { verdict: "flag", description }
|
|
48
|
+
* - NEW → status: "failed", output: { verdict: "new", pattern, description }
|
|
49
|
+
*/
|
|
50
|
+
export declare function executeMonitor(monitorName: string, stepName: string, input: Record<string, unknown>, options: MonitorStepOptions): Promise<StepResult>;
|
|
51
|
+
/**
|
|
52
|
+
* List all discoverable monitor names for validation.
|
|
53
|
+
*/
|
|
54
|
+
export declare function availableMonitors(cwd: string): string[];
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=step-monitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-monitor.d.ts","sourceRoot":"","sources":["../src/step-monitor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAItE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI7C,UAAU,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACT,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,cAAc,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;KACb,CAAC;IACF,YAAY,CAAC,EAAE;QACd,IAAI,EAAE,MAAM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