pi-subagents 0.72.0 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/docs/agents.md +1 -1
- package/docs/standalone-background.md +1 -1
- package/docs/tool-reference.md +1 -1
- package/docs/workflows.md +5 -1
- package/package.json +1 -1
- package/src/extension/index.d.ts.map +1 -1
- package/src/extension/index.js +2 -0
- package/src/extension/index.js.map +1 -1
- package/src/extension/tool-activation.js +1 -1
- package/src/extension/tool-activation.js.map +1 -1
- package/src/runs/background/run-status.d.ts.map +1 -1
- package/src/runs/background/run-status.js +1 -0
- package/src/runs/background/run-status.js.map +1 -1
- package/src/runs/foreground/subagent-executor.d.ts.map +1 -1
- package/src/runs/foreground/subagent-executor.js +142 -64
- package/src/runs/foreground/subagent-executor.js.map +1 -1
- package/src/runs/shared/async-status-projection.d.ts +3 -0
- package/src/runs/shared/async-status-projection.d.ts.map +1 -1
- package/src/runs/shared/async-status-projection.js +3 -0
- package/src/runs/shared/async-status-projection.js.map +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts.map +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.js +11 -12
- package/src/runs/shared/mcp-direct-tool-allowlist.js.map +1 -1
- package/src/shared/extension-context.d.ts +2 -0
- package/src/shared/extension-context.d.ts.map +1 -1
- package/src/shared/extension-context.js +4 -0
- package/src/shared/extension-context.js.map +1 -1
- package/src/shared/model-info.d.ts +4 -0
- package/src/shared/model-info.d.ts.map +1 -1
- package/src/shared/model-info.js +9 -0
- package/src/shared/model-info.js.map +1 -1
- package/src/shared/types.d.ts +2 -0
- package/src/shared/types.d.ts.map +1 -1
- package/src/shared/types.js.map +1 -1
- package/src/tui/fleet-status.d.ts.map +1 -1
- package/src/tui/fleet-status.js +12 -6
- package/src/tui/fleet-status.js.map +1 -1
- package/src/tui/fleet.d.ts.map +1 -1
- package/src/tui/fleet.js +12 -1
- package/src/tui/fleet.js.map +1 -1
- package/src/tui/render.d.ts.map +1 -1
- package/src/tui/render.js +54 -34
- package/src/tui/render.js.map +1 -1
- package/src/tui/running-tone.d.ts +11 -0
- package/src/tui/running-tone.d.ts.map +1 -0
- package/src/tui/running-tone.js +23 -0
- package/src/tui/running-tone.js.map +1 -0
- package/src/workflows/scripted-workflow.d.ts +6 -4
- package/src/workflows/scripted-workflow.d.ts.map +1 -1
- package/src/workflows/scripted-workflow.js +100 -35
- package/src/workflows/scripted-workflow.js.map +1 -1
- package/src/workflows/workflow-checklist.d.ts +4 -0
- package/src/workflows/workflow-checklist.d.ts.map +1 -1
- package/src/workflows/workflow-checklist.js +3 -0
- package/src/workflows/workflow-checklist.js.map +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { ThinkingLevel } from "../shared/model-info.ts";
|
|
3
|
+
type Theme = Pick<ExtensionContext["ui"]["theme"], "fg" | "getThinkingBorderColor">;
|
|
4
|
+
/** Registers where the main session's current thinking level is read; glyphs that stand for several children take its color. */
|
|
5
|
+
export declare function setMainThinkingLevelSource(source: () => ThinkingLevel | undefined): void;
|
|
6
|
+
/** Reads the main session's level through `read`; a stale or not-yet-bound Pi runtime has no level to show. */
|
|
7
|
+
export declare function readMainThinkingLevel(read: () => ThinkingLevel): ThinkingLevel | undefined;
|
|
8
|
+
/** The running tone of a glyph: Pi's prompt-box color for the recorded level of the one child it stands for, else for the main session's current level, else accent. */
|
|
9
|
+
export declare function runningTone(theme: Theme, childLevel?: ThinkingLevel): (text: string) => string;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=running-tone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"running-tone.d.ts","sourceRoot":"","sources":["../../../src/tui/running-tone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG7D,KAAK,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,GAAG,wBAAwB,CAAC,CAAC;AAIpF,gIAAgI;AAChI,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,aAAa,GAAG,SAAS,GAAG,IAAI,CAExF;AAED,+GAA+G;AAC/G,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,aAAa,GAAG,aAAa,GAAG,SAAS,CAO1F;AAED,wKAAwK;AACxK,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,EAAE,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAG9F"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isStaleExtensionContextError, isUnboundExtensionRuntimeError } from "../shared/extension-context.js";
|
|
2
|
+
let mainThinkingLevelSource = () => undefined;
|
|
3
|
+
/** Registers where the main session's current thinking level is read; glyphs that stand for several children take its color. */
|
|
4
|
+
export function setMainThinkingLevelSource(source) {
|
|
5
|
+
mainThinkingLevelSource = source;
|
|
6
|
+
}
|
|
7
|
+
/** Reads the main session's level through `read`; a stale or not-yet-bound Pi runtime has no level to show. */
|
|
8
|
+
export function readMainThinkingLevel(read) {
|
|
9
|
+
try {
|
|
10
|
+
return read();
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
if (isStaleExtensionContextError(error) || isUnboundExtensionRuntimeError(error))
|
|
14
|
+
return undefined;
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** The running tone of a glyph: Pi's prompt-box color for the recorded level of the one child it stands for, else for the main session's current level, else accent. */
|
|
19
|
+
export function runningTone(theme, childLevel) {
|
|
20
|
+
const level = childLevel ?? mainThinkingLevelSource();
|
|
21
|
+
return level ? theme.getThinkingBorderColor(level) : (text) => theme.fg("accent", text);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=running-tone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"running-tone.js","sourceRoot":"","sources":["../../../src/tui/running-tone.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAI9G,IAAI,uBAAuB,GAAoC,GAAG,EAAE,CAAC,SAAS,CAAC;AAE/E,gIAAgI;AAChI,MAAM,UAAU,0BAA0B,CAAC,MAAuC;IACjF,uBAAuB,GAAG,MAAM,CAAC;AAClC,CAAC;AAED,+GAA+G;AAC/G,MAAM,UAAU,qBAAqB,CAAC,IAAyB;IAC9D,IAAI,CAAC;QACJ,OAAO,IAAI,EAAE,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,4BAA4B,CAAC,KAAK,CAAC,IAAI,8BAA8B,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QACnG,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC;AAED,wKAAwK;AACxK,MAAM,UAAU,WAAW,CAAC,KAAY,EAAE,UAA0B;IACnE,MAAM,KAAK,GAAG,UAAU,IAAI,uBAAuB,EAAE,CAAC;IACtD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACzF,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { AcceptanceRecoveryMetadata, HostStepNode, SingleResult } from "../shared/types.ts";
|
|
1
|
+
import type { AcceptanceRecoveryMetadata, HostStepNode, SingleResult, WorkflowScriptFailureKind } from "../shared/types.ts";
|
|
2
2
|
import { type WorkflowHostCommandParams, type WorkflowHostCommandResult } from "./host-command.ts";
|
|
3
3
|
export interface WorkflowScriptValidationError {
|
|
4
4
|
message: string;
|
|
5
5
|
line?: number;
|
|
6
6
|
column?: number;
|
|
7
|
-
kind?: "spawn-budget";
|
|
7
|
+
kind?: "spawn-budget" | "agent";
|
|
8
8
|
}
|
|
9
9
|
export interface WorkflowScriptValidationWarning {
|
|
10
10
|
message: string;
|
|
@@ -17,6 +17,8 @@ export interface WorkflowScriptValidationResult {
|
|
|
17
17
|
}
|
|
18
18
|
export interface WorkflowScriptValidationOptions {
|
|
19
19
|
maxSubagentSpawnsPerRun?: number;
|
|
20
|
+
/** Returns why launch-time resolution would reject this literal child agent name. */
|
|
21
|
+
agentNameError?: (name: string) => string | undefined;
|
|
20
22
|
}
|
|
21
23
|
export interface WorkflowScriptChildResult {
|
|
22
24
|
key: string;
|
|
@@ -127,8 +129,8 @@ export interface WorkflowScriptResult {
|
|
|
127
129
|
}
|
|
128
130
|
export declare class WorkflowScriptError extends Error {
|
|
129
131
|
readonly partial: Omit<WorkflowScriptResult, "value">;
|
|
130
|
-
readonly errorKind?:
|
|
131
|
-
constructor(message: string, partial: Omit<WorkflowScriptResult, "value">, errorKind?:
|
|
132
|
+
readonly errorKind?: WorkflowScriptFailureKind;
|
|
133
|
+
constructor(message: string, partial: Omit<WorkflowScriptResult, "value">, errorKind?: WorkflowScriptFailureKind, options?: ErrorOptions);
|
|
132
134
|
}
|
|
133
135
|
export type WorkflowChildSettledOutcome = "completed" | "failed" | "paused" | "stopped";
|
|
134
136
|
export interface WorkflowChildSettledNotification {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripted-workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/scripted-workflow.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,0BAA0B,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"scripted-workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/scripted-workflow.ts"],"names":[],"m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AED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAU/F;AAWD,MAAM,WAAW,wBAAwB;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,oFAAoF;AACpF,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,wBAAwB,GAAG,SAAS,CAgBzG;AAkYD,4FAA4F;AAC5F,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,+BAAoC,GAAG,8BAA8B,CA4GpI;AAiED,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAonBxG"}
|
|
@@ -45,6 +45,7 @@ let topLevelWorkflowPromise;
|
|
|
45
45
|
let suppressNativePromiseConsumption = 0;
|
|
46
46
|
const activeNativePromises = [];
|
|
47
47
|
const pending = new Map();
|
|
48
|
+
const workflowErrorKinds = new WeakMap();
|
|
48
49
|
const runKeyPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
49
50
|
function validGitRef(ref) {
|
|
50
51
|
if (typeof ref !== "string" || !ref || ref === "@" || new TextEncoder().encode(ref).length > 1024 || ref.startsWith("/") || ref.endsWith("/") || ref.includes("//") || ref.includes("..") || ref.includes("@{")) return false;
|
|
@@ -848,6 +849,15 @@ function isSyntaxError(error) {
|
|
|
848
849
|
return error instanceof SyntaxError || error?.name === "SyntaxError";
|
|
849
850
|
}
|
|
850
851
|
|
|
852
|
+
function postWorkflowError(error) {
|
|
853
|
+
// Pre-run syntax and portability errors are tagged "validation" where the script is compiled;
|
|
854
|
+
// anything reaching here was thrown while the script ran, including a runtime SyntaxError.
|
|
855
|
+
const taggedKind = error && (typeof error === "object" || typeof error === "function") ? workflowErrorKinds.get(error) : undefined;
|
|
856
|
+
parentPort.postMessage({ type: "error", error: isSyntaxError(error) ? formatWorkflowScriptSyntaxError(error) : formatWorkflowScriptError(error), errorKind: taggedKind ?? "script" });
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
process.on("unhandledRejection", postWorkflowError);
|
|
860
|
+
|
|
851
861
|
const NESTED_ASYNC_WORKFLOW_ERROR = "workflowScript validation failed before child launch; no children launched. workflowScript does not support nested async functions. Use top-level await, plain helper functions that return runs.run(...), or explicit Promise chains so workflows stay portable across Node and Bun. Parallel plus sequential rewrite: const a = runs.run(\"a\", { agent: \"worker\", task: \"A\" }); const writer = await runs.run(\"writer\", { agent: \"worker\", task: \"Write\" }); const review = await runs.run(\"review\", { agent: \"reviewer\", task: writer.output }); const [aResult] = await Promise.all([a]); return { a: aResult.output, issue: { writerRunId: writer.runId, reviewRunId: review.runId } };";
|
|
852
862
|
const AST_SCALAR_KEYS = new Set(["type", "start", "end"]);
|
|
853
863
|
|
|
@@ -964,7 +974,7 @@ parentPort.on("message", async (message) => {
|
|
|
964
974
|
if (message.ok) entry.resolve(message.value);
|
|
965
975
|
else {
|
|
966
976
|
const error = new Error(message.error);
|
|
967
|
-
if (message.errorKind === "
|
|
977
|
+
if (message.errorKind === "child" || message.errorKind === "detached-child") workflowErrorKinds.set(error, message.errorKind);
|
|
968
978
|
entry.reject(error);
|
|
969
979
|
}
|
|
970
980
|
return;
|
|
@@ -983,7 +993,7 @@ parentPort.on("message", async (message) => {
|
|
|
983
993
|
assertPortableWorkflowScript(message.script);
|
|
984
994
|
compiled = new vm.Script("(async () => {\n" + message.script + "\n})()", { filename: "workflow-script.js" });
|
|
985
995
|
} catch (error) {
|
|
986
|
-
parentPort.postMessage({ type: "error", error: isSyntaxError(error) ? formatWorkflowScriptSyntaxError(error) : formatWorkflowScriptError(error) });
|
|
996
|
+
parentPort.postMessage({ type: "error", errorKind: "validation", error: isSyntaxError(error) ? formatWorkflowScriptSyntaxError(error) : formatWorkflowScriptError(error) });
|
|
987
997
|
return;
|
|
988
998
|
}
|
|
989
999
|
const nativePromisePrototype = vm.runInContext("(async () => {})().constructor.prototype", context);
|
|
@@ -1047,20 +1057,26 @@ parentPort.on("message", async (message) => {
|
|
|
1047
1057
|
try {
|
|
1048
1058
|
assertJsonValue(persistedValue, "return");
|
|
1049
1059
|
} catch (error) {
|
|
1050
|
-
parentPort.postMessage({ type: "error", errorPhase: "return-serialization", error: formatWorkflowScriptError(error) });
|
|
1060
|
+
parentPort.postMessage({ type: "error", errorKind: "return-serialization", errorPhase: "return-serialization", error: formatWorkflowScriptError(error) });
|
|
1051
1061
|
return;
|
|
1052
1062
|
}
|
|
1053
1063
|
parentPort.postMessage({ type: "complete", value: persistedValue });
|
|
1054
1064
|
} catch (error) {
|
|
1055
|
-
|
|
1065
|
+
postWorkflowError(error);
|
|
1056
1066
|
}
|
|
1057
1067
|
});
|
|
1058
1068
|
`;
|
|
1069
|
+
function isWorkflowScriptFailureKind(value) {
|
|
1070
|
+
return value === "validation" || value === "script" || value === "child" || value === "return-serialization" || value === "timeout" || value === "detached-child" || value === "runtime";
|
|
1071
|
+
}
|
|
1072
|
+
function taggedWorkflowError(message, kind) {
|
|
1073
|
+
return Object.assign(new Error(message), { workflowErrorKind: kind });
|
|
1074
|
+
}
|
|
1059
1075
|
export class WorkflowScriptError extends Error {
|
|
1060
1076
|
partial;
|
|
1061
1077
|
errorKind;
|
|
1062
|
-
constructor(message, partial, errorKind) {
|
|
1063
|
-
super(message);
|
|
1078
|
+
constructor(message, partial, errorKind, options) {
|
|
1079
|
+
super(message, options);
|
|
1064
1080
|
this.name = "WorkflowScriptError";
|
|
1065
1081
|
this.partial = partial;
|
|
1066
1082
|
this.errorKind = errorKind;
|
|
@@ -1293,7 +1309,10 @@ export function formatWorkflowJsonPreview(value, maxLength) {
|
|
|
1293
1309
|
try {
|
|
1294
1310
|
assertWorkflowJsonValue(value);
|
|
1295
1311
|
const serialized = JSON.stringify(value);
|
|
1296
|
-
|
|
1312
|
+
if (typeof serialized !== "string")
|
|
1313
|
+
return undefined;
|
|
1314
|
+
// Serialized JSON never ends in "…", so the suffix always means the preview was cut.
|
|
1315
|
+
return serialized.length > maxLength ? `${serialized.slice(0, maxLength)}…` : serialized;
|
|
1297
1316
|
}
|
|
1298
1317
|
catch {
|
|
1299
1318
|
return undefined;
|
|
@@ -1591,6 +1610,46 @@ function validateStaticBaseRef(params, owner) {
|
|
|
1591
1610
|
}
|
|
1592
1611
|
return [];
|
|
1593
1612
|
}
|
|
1613
|
+
// Children with their own cwd, agentScope, or resume resolve agents elsewhere, and a
|
|
1614
|
+
// spread or computed key can replace `agent`; leave those to launch-time resolution.
|
|
1615
|
+
function staticChildAgentNode(params) {
|
|
1616
|
+
if (!astNode(params) || params.type !== "ObjectExpression" || !Array.isArray(params.properties))
|
|
1617
|
+
return undefined;
|
|
1618
|
+
let agent;
|
|
1619
|
+
for (const property of params.properties) {
|
|
1620
|
+
if (!astNode(property) || property.type !== "Property")
|
|
1621
|
+
return undefined;
|
|
1622
|
+
const key = staticPropertyKey(property);
|
|
1623
|
+
if (key === undefined || key === "cwd" || key === "agentScope" || key === "resume")
|
|
1624
|
+
return undefined;
|
|
1625
|
+
if (key === "agent")
|
|
1626
|
+
agent = property.kind === "init" && astNode(property.value) ? property.value : undefined;
|
|
1627
|
+
}
|
|
1628
|
+
return literalString(agent) === undefined ? undefined : agent;
|
|
1629
|
+
}
|
|
1630
|
+
function validateStaticChildAgents(call, agentNameError) {
|
|
1631
|
+
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
1632
|
+
const elements = (node) => astNode(node) && node.type === "ArrayExpression" && Array.isArray(node.elements) ? node.elements : [];
|
|
1633
|
+
// A spread or unknown computed key on the lane can replace `stages`.
|
|
1634
|
+
const staticLane = (lane) => astNode(lane) && lane.type === "ObjectExpression" && Array.isArray(lane.properties)
|
|
1635
|
+
&& lane.properties.every((property) => astNode(property) && property.type === "Property" && staticPropertyKey(property) !== undefined);
|
|
1636
|
+
const children = directRunsCall(call, "run")
|
|
1637
|
+
? [{ owner: "runs.run", params: args[1] }]
|
|
1638
|
+
: directRunsCall(call, "all")
|
|
1639
|
+
? elements(args[0]).map((params) => ({ owner: "runs.all item", params }))
|
|
1640
|
+
: directRunsCall(call, "lanes")
|
|
1641
|
+
? elements(args[0]).flatMap((lane) => staticLane(lane) ? elements(directObjectPropertyValue(lane, "stages")).map((params) => ({ owner: "runs.lanes stage", params })) : [])
|
|
1642
|
+
: [];
|
|
1643
|
+
const errors = [];
|
|
1644
|
+
for (const child of children) {
|
|
1645
|
+
const agentNode = staticChildAgentNode(child.params);
|
|
1646
|
+
const agentName = literalString(agentNode);
|
|
1647
|
+
const error = agentName === undefined ? undefined : agentNameError(agentName);
|
|
1648
|
+
if (agentNode && error)
|
|
1649
|
+
errors.push({ kind: "agent", message: `${child.owner}: ${error}`, ...nodeLocation(agentNode) });
|
|
1650
|
+
}
|
|
1651
|
+
return errors;
|
|
1652
|
+
}
|
|
1594
1653
|
function directRunsAllKeys(call) {
|
|
1595
1654
|
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
1596
1655
|
const items = astNode(args[0]) && args[0].type === "ArrayExpression" && Array.isArray(args[0].elements) ? args[0].elements : [];
|
|
@@ -1755,6 +1814,8 @@ export function validateWorkflowScript(script, options = {}) {
|
|
|
1755
1814
|
? root.body[0].expression.callee
|
|
1756
1815
|
: undefined;
|
|
1757
1816
|
const workflowBody = wrapper && astNode(wrapper.body) ? wrapper.body : root;
|
|
1817
|
+
// A rebound `runs` may not be the workflow API, so its calls prove nothing about child launches.
|
|
1818
|
+
const agentNameError = options.agentNameError && !invalidatesRunsBinding(workflowBody) ? options.agentNameError : undefined;
|
|
1758
1819
|
walkAst(workflowBody, (node) => {
|
|
1759
1820
|
if (node !== wrapper && node.async === true && (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression")) {
|
|
1760
1821
|
errors.push({ message: "workflowScript does not support nested async functions. Use top-level await, plain helper functions that return runs.run(...), or explicit Promise chains.", ...nodeLocation(node) });
|
|
@@ -1789,6 +1850,8 @@ export function validateWorkflowScript(script, options = {}) {
|
|
|
1789
1850
|
}
|
|
1790
1851
|
if (directRunsCall(node, "host"))
|
|
1791
1852
|
errors.push(...validateStaticHostCall(node));
|
|
1853
|
+
if (agentNameError)
|
|
1854
|
+
errors.push(...validateStaticChildAgents(node, agentNameError));
|
|
1792
1855
|
const boundaryValue = node.type === "CallExpression" && astNode(node.callee) && node.callee.type === "Identifier" && node.callee.name === "emit" && Array.isArray(node.arguments) && astNode(node.arguments[0])
|
|
1793
1856
|
? node.arguments[0]
|
|
1794
1857
|
: node.type === "CallExpression" && astNode(node.callee) && node.callee.type === "MemberExpression" && astNode(node.callee.object) && node.callee.object.type === "Identifier" && node.callee.object.name === "state" && astNode(node.callee.property) && node.callee.property.type === "Identifier" && node.callee.property.name === "set" && Array.isArray(node.arguments) && astNode(node.arguments[1])
|
|
@@ -1926,12 +1989,13 @@ function setupAbortResumeParams(params, result, signal) {
|
|
|
1926
1989
|
return resumeParams;
|
|
1927
1990
|
}
|
|
1928
1991
|
export async function runWorkflowScript(options) {
|
|
1992
|
+
const emptyPartial = () => ({ emits: [], console: [], trace: [], children: [] });
|
|
1929
1993
|
if (!options.script.trim())
|
|
1930
|
-
throw new
|
|
1994
|
+
throw new WorkflowScriptError("workflowScript must not be empty.", emptyPartial(), "validation");
|
|
1931
1995
|
if (options.timeoutMs !== undefined && (!Number.isInteger(options.timeoutMs) || options.timeoutMs < 1))
|
|
1932
|
-
throw new
|
|
1996
|
+
throw new WorkflowScriptError("workflow script timeout must be a positive integer.", emptyPartial(), "runtime");
|
|
1933
1997
|
if (options.globalConcurrencyLimit !== undefined && (!Number.isSafeInteger(options.globalConcurrencyLimit) || options.globalConcurrencyLimit < 1)) {
|
|
1934
|
-
throw new
|
|
1998
|
+
throw new WorkflowScriptError("workflow script global concurrency limit must be a positive integer.", emptyPartial(), "runtime");
|
|
1935
1999
|
}
|
|
1936
2000
|
const launchSemaphore = new Semaphore(options.globalConcurrencyLimit ?? DEFAULT_GLOBAL_CONCURRENCY_LIMIT);
|
|
1937
2001
|
if (options.processCwd !== undefined) {
|
|
@@ -1942,7 +2006,7 @@ export async function runWorkflowScript(options) {
|
|
|
1942
2006
|
catch (error) {
|
|
1943
2007
|
const code = typeof error === "object" && error !== null && "code" in error ? error.code : undefined;
|
|
1944
2008
|
if (code !== "ENOENT")
|
|
1945
|
-
throw new
|
|
2009
|
+
throw new WorkflowScriptError("Workflow current cwd could not be validated.", emptyPartial(), "runtime", { cause: error });
|
|
1946
2010
|
staleCwd = true;
|
|
1947
2011
|
}
|
|
1948
2012
|
try {
|
|
@@ -1960,7 +2024,7 @@ export async function runWorkflowScript(options) {
|
|
|
1960
2024
|
}
|
|
1961
2025
|
catch (error) {
|
|
1962
2026
|
const detail = error instanceof Error ? error.message : String(error);
|
|
1963
|
-
throw new
|
|
2027
|
+
throw new WorkflowScriptError(`Workflow process cwd is unavailable: ${options.processCwd}: ${detail}`, emptyPartial(), "runtime", { cause: error });
|
|
1964
2028
|
}
|
|
1965
2029
|
}
|
|
1966
2030
|
let acornPath;
|
|
@@ -1968,9 +2032,15 @@ export async function runWorkflowScript(options) {
|
|
|
1968
2032
|
acornPath = resolveWorkflowParserEntry();
|
|
1969
2033
|
}
|
|
1970
2034
|
catch (error) {
|
|
1971
|
-
throw new
|
|
2035
|
+
throw new WorkflowScriptError("Workflow parser dependency 'acorn' is unavailable from pi-subagents. Reinstall pi-subagents dependencies before launching workflowScript.", emptyPartial(), "runtime", { cause: error });
|
|
2036
|
+
}
|
|
2037
|
+
let worker;
|
|
2038
|
+
try {
|
|
2039
|
+
worker = new Worker(WORKER_SOURCE, { eval: true, workerData: { acornPath } });
|
|
2040
|
+
}
|
|
2041
|
+
catch (error) {
|
|
2042
|
+
throw new WorkflowScriptError(`Workflow worker could not start: ${error instanceof Error ? error.message : String(error)}`, emptyPartial(), "runtime", { cause: error });
|
|
1972
2043
|
}
|
|
1973
|
-
const worker = new Worker(WORKER_SOURCE, { eval: true, workerData: { acornPath } });
|
|
1974
2044
|
const emits = [];
|
|
1975
2045
|
const consoleEntries = [];
|
|
1976
2046
|
const trace = [];
|
|
@@ -2117,10 +2187,11 @@ export async function runWorkflowScript(options) {
|
|
|
2117
2187
|
return unobservedHosts.length > 0 ? new Error(`workflowScript completed with unawaited runs.host call(s): ${unobservedHosts.map((key) => `'${key}'`).join(", ")}. Await or return each call.`) : undefined;
|
|
2118
2188
|
})()
|
|
2119
2189
|
: undefined;
|
|
2190
|
+
// Stops and reloads end through the abort paths untagged: they are not failures.
|
|
2120
2191
|
if ("error" in outcome)
|
|
2121
|
-
reject(new WorkflowScriptError(outcome.error.message, partial(), outcome.error.workflowErrorKind
|
|
2192
|
+
reject(new WorkflowScriptError(outcome.error.message, partial(), isWorkflowScriptFailureKind(outcome.error.workflowErrorKind) ? outcome.error.workflowErrorKind : undefined));
|
|
2122
2193
|
else if (completionError)
|
|
2123
|
-
reject(new WorkflowScriptError(completionError.message, partial()));
|
|
2194
|
+
reject(new WorkflowScriptError(completionError.message, partial(), "validation"));
|
|
2124
2195
|
else
|
|
2125
2196
|
resolve({ value: outcome.value, ...partial() });
|
|
2126
2197
|
});
|
|
@@ -2143,7 +2214,7 @@ export async function runWorkflowScript(options) {
|
|
|
2143
2214
|
}
|
|
2144
2215
|
catch (callbackError) {
|
|
2145
2216
|
const callbackMessage = callbackError instanceof Error ? callbackError.message : String(callbackError);
|
|
2146
|
-
return finish({ error:
|
|
2217
|
+
return finish({ error: taggedWorkflowError(`Workflow assembly flush eligibility failed: ${callbackMessage}`, "runtime") });
|
|
2147
2218
|
}
|
|
2148
2219
|
if (mayFlushAssembly && allChildrenSettled) {
|
|
2149
2220
|
// A reloaded async workflow may already be past its last child launch.
|
|
@@ -2176,17 +2247,15 @@ export async function runWorkflowScript(options) {
|
|
|
2176
2247
|
const timer = options.timeoutMs === undefined
|
|
2177
2248
|
? undefined
|
|
2178
2249
|
: setTimeout(() => {
|
|
2179
|
-
|
|
2180
|
-
error.workflowErrorKind = "timeout";
|
|
2181
|
-
finish({ error });
|
|
2250
|
+
finish({ error: taggedWorkflowError(`Workflow script timed out after ${options.timeoutMs}ms.`, "timeout") });
|
|
2182
2251
|
}, options.timeoutMs);
|
|
2183
2252
|
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
2184
2253
|
if (options.signal?.aborted)
|
|
2185
2254
|
return onAbort();
|
|
2186
|
-
worker.on("error", (error) => finish({ error:
|
|
2255
|
+
worker.on("error", (error) => finish({ error: taggedWorkflowError(`Workflow worker failed: ${error instanceof Error ? error.message : String(error)}`, "runtime") }));
|
|
2187
2256
|
worker.on("exit", (code) => {
|
|
2188
2257
|
if (!settled && code !== 0)
|
|
2189
|
-
finish({ error:
|
|
2258
|
+
finish({ error: taggedWorkflowError(`Workflow worker exited with code ${code}.`, "runtime") });
|
|
2190
2259
|
});
|
|
2191
2260
|
worker.on("message", (message) => {
|
|
2192
2261
|
if (settled)
|
|
@@ -2200,7 +2269,7 @@ export async function runWorkflowScript(options) {
|
|
|
2200
2269
|
assertWorkflowJsonValue(message.value, "emit");
|
|
2201
2270
|
}
|
|
2202
2271
|
catch (error) {
|
|
2203
|
-
finish({ error:
|
|
2272
|
+
finish({ error: taggedWorkflowError(`Workflow emit could not be persisted: ${error instanceof Error ? error.message : String(error)}`, "runtime") });
|
|
2204
2273
|
return;
|
|
2205
2274
|
}
|
|
2206
2275
|
emits.push(message.value);
|
|
@@ -2209,7 +2278,7 @@ export async function runWorkflowScript(options) {
|
|
|
2209
2278
|
}
|
|
2210
2279
|
catch (error) {
|
|
2211
2280
|
emits.pop();
|
|
2212
|
-
finish({ error:
|
|
2281
|
+
finish({ error: taggedWorkflowError(`Workflow emit could not be persisted: ${error instanceof Error ? error.message : String(error)}`, "runtime") });
|
|
2213
2282
|
}
|
|
2214
2283
|
return;
|
|
2215
2284
|
}
|
|
@@ -2224,17 +2293,14 @@ export async function runWorkflowScript(options) {
|
|
|
2224
2293
|
assertWorkflowJsonValue(message.value, "return");
|
|
2225
2294
|
}
|
|
2226
2295
|
catch (error) {
|
|
2227
|
-
return finish({ error:
|
|
2296
|
+
return finish({ error: taggedWorkflowError(`Workflow return could not be persisted: ${error instanceof Error ? error.message : String(error)}`, "return-serialization") });
|
|
2228
2297
|
}
|
|
2229
2298
|
return finish({ value: message.value });
|
|
2230
2299
|
}
|
|
2231
2300
|
if (message.type === "error") {
|
|
2232
2301
|
const rawError = typeof message.error === "string" ? message.error : "Workflow script failed.";
|
|
2233
2302
|
const text = message.errorPhase === "return-serialization" ? `${rawError}${workflowReturnRecoveryHint(partial().children)}` : rawError;
|
|
2234
|
-
|
|
2235
|
-
if (message.errorKind === "detached-child")
|
|
2236
|
-
workflowError.workflowErrorKind = "detached-child";
|
|
2237
|
-
return finish({ error: workflowError });
|
|
2303
|
+
return finish({ error: isWorkflowScriptFailureKind(message.errorKind) ? taggedWorkflowError(text, message.errorKind) : new Error(text) });
|
|
2238
2304
|
}
|
|
2239
2305
|
if (message.type === "callObserved" && typeof message.callId === "number") {
|
|
2240
2306
|
const key = typeof message.key === "string" ? message.key : undefined;
|
|
@@ -2283,8 +2349,10 @@ export async function runWorkflowScript(options) {
|
|
|
2283
2349
|
worker.postMessage({ type: "response", callId: message.callId, ok: false, error: `${responsePath} must contain only JSON data before it can be returned from workflowScript. Return a plain projection such as { runId, ok, output }. ${error instanceof Error ? error.message : String(error)}` });
|
|
2284
2350
|
}
|
|
2285
2351
|
}, (error) => {
|
|
2286
|
-
if (!settled)
|
|
2287
|
-
|
|
2352
|
+
if (!settled) {
|
|
2353
|
+
const errorKind = error instanceof Error ? error.workflowErrorKind : undefined;
|
|
2354
|
+
worker.postMessage({ type: "response", callId: message.callId, ok: false, error: error instanceof Error ? error.message : String(error), ...(isWorkflowScriptFailureKind(errorKind) ? { errorKind } : {}) });
|
|
2355
|
+
}
|
|
2288
2356
|
});
|
|
2289
2357
|
};
|
|
2290
2358
|
if (message.method === "state.get" || message.method === "state.set") {
|
|
@@ -2443,10 +2511,7 @@ export async function runWorkflowScript(options) {
|
|
|
2443
2511
|
const recoverableAcceptanceMetadata = result.recovery?.status === "available-for-review"
|
|
2444
2512
|
&& result.recovery.reason === "acceptance-metadata-rejected";
|
|
2445
2513
|
if (!result.ok && result.state !== "running" && !result.stopped && !recoverableAcceptanceMetadata) {
|
|
2446
|
-
|
|
2447
|
-
if (result.detached)
|
|
2448
|
-
childError.workflowErrorKind = "detached-child";
|
|
2449
|
-
throw childError;
|
|
2514
|
+
throw taggedWorkflowError(`Run '${key}' ${result.detached ? "detached" : "failed"}: ${result.error ?? result.output}`, result.detached ? "detached-child" : "child");
|
|
2450
2515
|
}
|
|
2451
2516
|
return result;
|
|
2452
2517
|
});
|