@xzzpig/pi-subagents 0.7.0 → 0.8.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 +13 -4
- package/README.md +1 -1
- package/agents/reviewer.md +12 -2
- package/docs/agents.md +4 -4
- package/docs/configuration.md +6 -6
- package/docs/extension-api.md +14 -4
- package/docs/models.md +47 -6
- package/docs/observability.md +14 -3
- package/docs/tool-reference.md +21 -6
- package/docs/workflows.md +7 -1
- package/index.ts +10 -1
- package/package.json +3 -3
- package/prompts/council.md +19 -7
- package/prompts/parallel-review.md +5 -1
- package/prompts/review-loop.md +9 -5
- package/skills/council-mode/SKILL.md +50 -26
- package/skills/pi-subagents/SKILL.md +5 -1
- package/skills/pi-subagents/references/constraints-and-recipes.md +16 -1
- package/skills/pi-subagents/references/execution-controls.md +13 -4
- package/skills/pi-subagents/references/multi-lane-orchestration.md +3 -3
- package/skills/pi-subagents/references/prompting-and-roles.md +14 -7
- package/src/agents/agent-management.ts +115 -14
- package/src/agents/agent-serializer.ts +4 -2
- package/src/agents/agents.ts +226 -48
- package/src/api/external-job-provider.ts +10 -1
- package/src/api/preflight.ts +52 -19
- package/src/api/project-panes.ts +2 -0
- package/src/extension/doctor.ts +10 -0
- package/src/extension/fanout-child.ts +3 -2
- package/src/extension/index.ts +24 -4
- package/src/extension/public-execution.ts +12 -9
- package/src/extension/rpc.ts +77 -3
- package/src/extension/schemas.ts +7 -1
- package/src/extension/tool-description.ts +9 -6
- package/src/extension/tool-result.ts +19 -0
- package/src/inspectors/herdr/client.ts +3 -3
- package/src/inspectors/herdr/focus.ts +55 -0
- package/src/inspectors/herdr/project-panes.ts +228 -44
- package/src/integrations/herdr-status.ts +26 -4
- package/src/runs/background/async-execution.ts +146 -17
- package/src/runs/background/async-job-tracker.ts +33 -14
- package/src/runs/background/async-resume.ts +23 -2
- package/src/runs/background/async-retention.ts +1 -1
- package/src/runs/background/async-status.ts +10 -0
- package/src/runs/background/chain-root-attachment.ts +5 -0
- package/src/runs/background/control-channel.ts +98 -10
- package/src/runs/background/notify.ts +62 -1
- package/src/runs/background/result-watcher.ts +4 -3
- package/src/runs/background/run-status.ts +15 -1
- package/src/runs/background/stale-run-reconciler.ts +3 -0
- package/src/runs/background/subagent-runner.ts +333 -48
- package/src/runs/background/wait-completions.ts +2 -0
- package/src/runs/background/wait-tool.ts +4 -3
- package/src/runs/foreground/async-stop-action.ts +23 -2
- package/src/runs/foreground/execution.ts +148 -13
- package/src/runs/foreground/foreground-history.ts +3 -2
- package/src/runs/foreground/subagent-executor.ts +417 -50
- package/src/runs/foreground/workflow-detach-reconcile.ts +18 -6
- package/src/runs/shared/acceptance.ts +11 -5
- package/src/runs/shared/agent-contract.ts +1 -1
- package/src/runs/shared/child-identity.ts +36 -0
- package/src/runs/shared/completion-guard.ts +52 -2
- package/src/runs/shared/dynamic-fanout.ts +1 -1
- package/src/runs/shared/extension-bindings.ts +78 -0
- package/src/runs/shared/external-cli-runner.ts +2 -0
- package/src/runs/shared/external-job-bridge.ts +53 -37
- package/src/runs/shared/external-job-runner.ts +126 -23
- package/src/runs/shared/fast-mode-extension.ts +10 -0
- package/src/runs/shared/model-exclusions.ts +2 -1
- package/src/runs/shared/model-fallback.ts +48 -22
- package/src/runs/shared/model-scope.ts +106 -39
- package/src/runs/shared/mutation-evidence.ts +145 -0
- package/src/runs/shared/orca-progress-tabs.ts +71 -9
- package/src/runs/shared/parallel-utils.ts +15 -0
- package/src/runs/shared/pi-args.ts +78 -1
- package/src/runs/shared/structured-output.ts +18 -4
- package/src/runs/shared/subagent-prompt-runtime.ts +48 -15
- package/src/runs/shared/tool-availability.ts +1 -3
- package/src/shared/launch-contract.ts +12 -5
- package/src/shared/settings.ts +6 -1
- package/src/shared/thinking-ceiling.ts +52 -0
- package/src/shared/types.ts +120 -5
- package/src/tui/fleet-status.ts +66 -13
- package/src/tui/render.ts +5 -4
- package/src/watchdog/permission-arbiter.ts +59 -52
- package/src/workflows/scripted-workflow.ts +156 -12
|
@@ -150,7 +150,15 @@ function trackObservationTracker(tracker, promise, allowFutureObservations = fal
|
|
|
150
150
|
get(promiseTarget, prop) {
|
|
151
151
|
if (prop === "then") return function promiseThen(onFulfilled, onRejected) {
|
|
152
152
|
consumeTrackedObservations(tracker);
|
|
153
|
-
|
|
153
|
+
const chainTracker = { observations: tracker.observations, consumed: false, dependencies: [tracker] };
|
|
154
|
+
const wrapHandler = (handler) => typeof handler === "function"
|
|
155
|
+
? function trackedThenHandler(...args) {
|
|
156
|
+
const value = handler.apply(this, args);
|
|
157
|
+
addTrackerDependency(chainTracker, promiseObservationTracker(value));
|
|
158
|
+
return trackedPromiseTarget(value);
|
|
159
|
+
}
|
|
160
|
+
: handler;
|
|
161
|
+
return trackObservationTracker(chainTracker, promiseTarget.then(wrapHandler(onFulfilled), wrapHandler(onRejected)), true);
|
|
154
162
|
};
|
|
155
163
|
if (prop === "catch") return function promiseCatch(onRejected) {
|
|
156
164
|
consumeTrackedObservations(tracker);
|
|
@@ -242,6 +250,33 @@ function runHostCall(key, params, collectFailure, batch) {
|
|
|
242
250
|
return { key, callId, promise };
|
|
243
251
|
}
|
|
244
252
|
|
|
253
|
+
function isArrayIndexProperty(prop) {
|
|
254
|
+
if (!/^(0|[1-9]\d*)$/.test(prop)) return false;
|
|
255
|
+
const index = Number(prop);
|
|
256
|
+
return Number.isSafeInteger(index) && index >= 0 && index < 4294967295;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const runsAllResultTargets = new WeakMap();
|
|
260
|
+
|
|
261
|
+
function runsAllKeyAccessError(prop) {
|
|
262
|
+
return new Error("Cannot read runs.all result property '" + prop + "'. runs.all resolves to an ordered array, not a key map. Use results[0], array destructuring, or results.map((result) => result.output), not results." + prop + ".");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function wrapRunsAllResults(results, keys) {
|
|
266
|
+
const keySet = new Set(keys);
|
|
267
|
+
const proxy = new Proxy(results, {
|
|
268
|
+
get(target, prop, receiver) {
|
|
269
|
+
if (typeof prop !== "string") return Reflect.get(target, prop, receiver);
|
|
270
|
+
if (prop === "then" || prop === "toJSON") return undefined;
|
|
271
|
+
if (prop in target || isArrayIndexProperty(prop)) return Reflect.get(target, prop, receiver);
|
|
272
|
+
if (keySet.has(prop)) throw runsAllKeyAccessError(prop);
|
|
273
|
+
throw runsAllKeyAccessError(prop);
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
runsAllResultTargets.set(proxy, results);
|
|
277
|
+
return proxy;
|
|
278
|
+
}
|
|
279
|
+
|
|
245
280
|
function formatRef(result) {
|
|
246
281
|
if (!result || typeof result !== "object") throw new Error("runs.ref(result) requires a run result object.");
|
|
247
282
|
const parts = ["run " + (result.key || "unknown")];
|
|
@@ -249,8 +284,43 @@ function formatRef(result) {
|
|
|
249
284
|
return "[" + parts.join("; ") + "]";
|
|
250
285
|
}
|
|
251
286
|
|
|
287
|
+
function formatChildResultString(result) {
|
|
288
|
+
const output = typeof result?.output === "string" ? result.output.trim() : "";
|
|
289
|
+
return output || formatRef(result);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function decorateWorkflowChildResult(result) {
|
|
293
|
+
if (!result || typeof result !== "object" || Array.isArray(result)) return result;
|
|
294
|
+
Object.defineProperties(result, {
|
|
295
|
+
toString: { value() { return formatChildResultString(this); }, enumerable: false, configurable: true },
|
|
296
|
+
});
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
|
|
252
300
|
let runFingerprints = new Map();
|
|
253
301
|
|
|
302
|
+
function validateExtensionBindings(value, label) {
|
|
303
|
+
if (value === undefined) return;
|
|
304
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(label + " extensionBindings must be a plain JSON object.");
|
|
305
|
+
const keys = Object.keys(value);
|
|
306
|
+
if (keys.length > 16) throw new Error(label + " extensionBindings supports at most 16 namespaces.");
|
|
307
|
+
for (const key of keys) if (!/^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,62})\/[1-9][0-9]{0,8}$/.test(key)) throw new Error(label + " extensionBindings namespace '" + key + "' must use a package-like name followed by '/<positive-version>'.");
|
|
308
|
+
assertJsonValue(value, label + " extensionBindings");
|
|
309
|
+
let propertyCount = 0;
|
|
310
|
+
function visit(entry, depth) {
|
|
311
|
+
if (!entry || typeof entry !== "object") return;
|
|
312
|
+
if (depth > 16) throw new Error(label + " extensionBindings exceeds the maximum nesting depth of 16.");
|
|
313
|
+
if (Array.isArray(entry)) { for (const item of entry) visit(item, depth + 1); return; }
|
|
314
|
+
for (const child of Object.values(entry)) {
|
|
315
|
+
propertyCount++;
|
|
316
|
+
if (propertyCount > 256) throw new Error(label + " extensionBindings exceeds 256 total properties.");
|
|
317
|
+
visit(child, depth + 1);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
visit(value, 0);
|
|
321
|
+
if (new TextEncoder().encode(stableRunJson(value)).byteLength > 16384) throw new Error(label + " extensionBindings canonical JSON exceeds 16384 bytes.");
|
|
322
|
+
}
|
|
323
|
+
|
|
254
324
|
function validateRunCall(key, params, label, fingerprints) {
|
|
255
325
|
if (typeof key !== "string" || !runKeyPattern.test(key)) throw new Error(label + " has an invalid key.");
|
|
256
326
|
if (!params || typeof params !== "object" || Array.isArray(params)) throw new Error(label + " requires a params object.");
|
|
@@ -263,6 +333,7 @@ function validateRunCall(key, params, label, fingerprints) {
|
|
|
263
333
|
if (params.gate !== undefined && (typeof params.gate !== "string" || !params.gate.trim())) throw new Error(label + " gate must be a non-empty command string.");
|
|
264
334
|
if (params.gate !== undefined && params.acceptance !== undefined) throw new Error(label + " gate cannot be combined with acceptance; use one gate command or acceptance.verify.");
|
|
265
335
|
if (params.gate !== undefined && params.resume !== undefined) throw new Error(label + " gate is not supported with retained resume.");
|
|
336
|
+
if (params.extensionBindings !== undefined && params.resume !== undefined) throw new Error(label + " extensionBindings is not supported with retained resume; resume uses the original retained child binding.");
|
|
266
337
|
if (params.resume !== undefined && typeof params.resume !== "string") {
|
|
267
338
|
const reference = params.resume;
|
|
268
339
|
if (!reference || typeof reference !== "object" || Array.isArray(reference)) throw new Error(label + " resume must be a retained run id or keyed workflow receipt reference.");
|
|
@@ -275,6 +346,7 @@ function validateRunCall(key, params, label, fingerprints) {
|
|
|
275
346
|
if (typeof params.resume === "string" && !params.resume.trim()) throw new Error(label + " resume must be a non-empty retained run id.");
|
|
276
347
|
if (params.resume !== undefined && params.agent !== undefined) throw new Error(label + " resume and agent are mutually exclusive.");
|
|
277
348
|
if (params.resume !== undefined && (typeof params.task !== "string" || !params.task.trim())) throw new Error(label + " resume requires a non-empty task follow-up.");
|
|
349
|
+
validateExtensionBindings(params.extensionBindings, label);
|
|
278
350
|
assertJsonValue(params, label + " params");
|
|
279
351
|
const fingerprint = stableRunJson(params);
|
|
280
352
|
const existing = fingerprints.get(key);
|
|
@@ -285,7 +357,8 @@ function validateRunCall(key, params, label, fingerprints) {
|
|
|
285
357
|
const runs = Object.freeze({
|
|
286
358
|
run(key, params) {
|
|
287
359
|
validateRunCall(key, params, "runs.run", runFingerprints);
|
|
288
|
-
|
|
360
|
+
const launched = runHostCall(key, params, false);
|
|
361
|
+
return trackRunObservation([{ key, operation: "run", callId: launched.callId }], launched.promise.then(decorateWorkflowChildResult));
|
|
289
362
|
},
|
|
290
363
|
all(items) {
|
|
291
364
|
if (!Array.isArray(items)) throw new Error("runs.all(items) requires an array.");
|
|
@@ -302,7 +375,7 @@ const runs = Object.freeze({
|
|
|
302
375
|
runFingerprints = fingerprints;
|
|
303
376
|
const batch = { id: "batch-" + (++nextCallId), calls };
|
|
304
377
|
const launched = calls.map(({ key, params }) => runHostCall(key, params, true, batch));
|
|
305
|
-
return trackRunObservation(launched.map(({ key, callId }) => ({ key, operation: "run", callId })), Promise.all(launched.map(({ promise }) => promise)));
|
|
378
|
+
return trackRunObservation(launched.map(({ key, callId }) => ({ key, operation: "run", callId })), Promise.all(launched.map(({ promise }) => promise)).then((results) => wrapRunsAllResults(results.map(decorateWorkflowChildResult), calls.map(({ key }) => key))));
|
|
306
379
|
},
|
|
307
380
|
steer(key, message, options = {}) {
|
|
308
381
|
if (typeof key !== "string" || !runKeyPattern.test(key)) throw new Error("runs.steer has an invalid key.");
|
|
@@ -431,6 +504,31 @@ function isPlainWorkflowObject(value) {
|
|
|
431
504
|
return prototype === null || prototype === Object.prototype || prototype === contextObjectPrototype;
|
|
432
505
|
}
|
|
433
506
|
|
|
507
|
+
function unwrapRunsAllResults(value, seen = new Map()) {
|
|
508
|
+
if (value === null || typeof value !== "object") return value;
|
|
509
|
+
const runsAllTarget = runsAllResultTargets.get(value);
|
|
510
|
+
const target = runsAllTarget || value;
|
|
511
|
+
if (seen.has(target)) return seen.get(target);
|
|
512
|
+
if (Array.isArray(target)) {
|
|
513
|
+
const copy = [];
|
|
514
|
+
seen.set(target, copy);
|
|
515
|
+
let changed = !!runsAllTarget;
|
|
516
|
+
for (let index = 0; index < target.length; index++) {
|
|
517
|
+
copy[index] = unwrapRunsAllResults(target[index], seen);
|
|
518
|
+
changed ||= copy[index] !== target[index];
|
|
519
|
+
}
|
|
520
|
+
return changed ? copy : target;
|
|
521
|
+
}
|
|
522
|
+
if (!isPlainWorkflowObject(target) || Object.getOwnPropertySymbols(target).length > 0) return target;
|
|
523
|
+
let changed = false;
|
|
524
|
+
const entries = Object.entries(target).map(([key, entry]) => {
|
|
525
|
+
const unwrapped = unwrapRunsAllResults(entry, seen);
|
|
526
|
+
changed ||= unwrapped !== entry;
|
|
527
|
+
return [key, unwrapped];
|
|
528
|
+
});
|
|
529
|
+
return changed ? Object.fromEntries(entries) : target;
|
|
530
|
+
}
|
|
531
|
+
|
|
434
532
|
function omitUndefinedWorkflowValues(value, seen = new Set()) {
|
|
435
533
|
if (value === null || typeof value !== "object") return value;
|
|
436
534
|
if (seen.has(value)) return value;
|
|
@@ -459,7 +557,7 @@ parentPort.on("message", async (message) => {
|
|
|
459
557
|
}
|
|
460
558
|
if (message.type !== "start") return;
|
|
461
559
|
try {
|
|
462
|
-
const sandbox = { runs, Promise: workflowPromise, emit(value) {
|
|
560
|
+
const sandbox = { runs, Promise: workflowPromise, emit(value) { const emittedValue = unwrapRunsAllResults(value); assertJsonValue(emittedValue); parentPort.postMessage({ type: "emit", value: emittedValue }); }, console: capturedConsole };
|
|
463
561
|
if (message.stateEnabled) sandbox.state = state;
|
|
464
562
|
const context = vm.createContext(sandbox, { codeGeneration: { strings: false, wasm: false } });
|
|
465
563
|
contextObjectPrototype = vm.runInContext("Object.prototype", context);
|
|
@@ -540,12 +638,14 @@ parentPort.on("message", async (message) => {
|
|
|
540
638
|
export interface WorkflowScriptChildResult {
|
|
541
639
|
key: string;
|
|
542
640
|
ok: boolean;
|
|
641
|
+
stopped?: boolean;
|
|
543
642
|
/** Canonical child agent name when launch resolution produced one. */
|
|
544
643
|
agent?: string;
|
|
545
644
|
runId?: string;
|
|
546
645
|
output: string;
|
|
547
646
|
error?: string;
|
|
548
647
|
detached?: boolean;
|
|
648
|
+
interrupted?: boolean;
|
|
549
649
|
structuredOutput?: unknown;
|
|
550
650
|
requestedContext?: "fresh" | "fork";
|
|
551
651
|
resolvedContext?: "fresh" | "fork" | "mixed";
|
|
@@ -628,10 +728,27 @@ export interface RunWorkflowScriptOptions {
|
|
|
628
728
|
get: (key: string) => unknown | Promise<unknown>;
|
|
629
729
|
set: (key: string, value: unknown) => void | Promise<void>;
|
|
630
730
|
};
|
|
731
|
+
registerStopChild?: (stop: ((key: string, message?: string) => boolean) | undefined) => void;
|
|
631
732
|
onTrace?: (trace: WorkflowScriptTraceEntry[]) => void;
|
|
632
733
|
onEmit?: (emits: unknown[]) => void;
|
|
633
734
|
}
|
|
634
735
|
|
|
736
|
+
function combinedAbortSignal(signals: AbortSignal[]): AbortSignal {
|
|
737
|
+
const controller = new AbortController();
|
|
738
|
+
const abort = (signal: AbortSignal): void => {
|
|
739
|
+
if (controller.signal.aborted) return;
|
|
740
|
+
controller.abort(signal.reason);
|
|
741
|
+
};
|
|
742
|
+
for (const signal of signals) {
|
|
743
|
+
if (signal.aborted) {
|
|
744
|
+
abort(signal);
|
|
745
|
+
break;
|
|
746
|
+
}
|
|
747
|
+
signal.addEventListener("abort", () => abort(signal), { once: true });
|
|
748
|
+
}
|
|
749
|
+
return controller.signal;
|
|
750
|
+
}
|
|
751
|
+
|
|
635
752
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
636
753
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
637
754
|
}
|
|
@@ -795,6 +912,7 @@ export async function runWorkflowScript(options: RunWorkflowScriptOptions): Prom
|
|
|
795
912
|
const launches = new Map<string, { fingerprint: string; promise: Promise<WorkflowScriptChildResult>; observed: boolean }>();
|
|
796
913
|
const steers = new Map<number, { key: string; promise: Promise<WorkflowSteerResult>; observed: boolean }>();
|
|
797
914
|
const stoppedLaunches = new Set<string>();
|
|
915
|
+
const childStopControllers = new Map<string, AbortController>();
|
|
798
916
|
const batchAdmissions = new Map<string, Promise<void>>();
|
|
799
917
|
const observedRunCalls = new Set<number>();
|
|
800
918
|
const observedSteerCalls = new Set<number>();
|
|
@@ -818,6 +936,26 @@ export async function runWorkflowScript(options: RunWorkflowScriptOptions): Prom
|
|
|
818
936
|
console.error("Workflow onTrace callback failed:", error);
|
|
819
937
|
}
|
|
820
938
|
};
|
|
939
|
+
const stoppedChildResult = (key: string, message: string): WorkflowScriptChildResult => ({ key, ok: false, stopped: true, output: message, error: message, artifactPaths: [] });
|
|
940
|
+
const stopChild = (key: string, message = `Workflow child '${key}' stopped by user.`): boolean => {
|
|
941
|
+
if (!launches.has(key) || children.has(key)) return false;
|
|
942
|
+
stoppedLaunches.add(key);
|
|
943
|
+
children.set(key, stoppedChildResult(key, message));
|
|
944
|
+
childStopControllers.get(key)?.abort(new Error(message));
|
|
945
|
+
const started = trace.findLast((entry) => entry.operation === "run" && entry.key === key && entry.state === "started");
|
|
946
|
+
trace.push({
|
|
947
|
+
operation: "run",
|
|
948
|
+
key,
|
|
949
|
+
state: "stopped",
|
|
950
|
+
...(started?.agent ? { agent: started.agent } : {}),
|
|
951
|
+
...(started?.phase ? { phase: started.phase } : {}),
|
|
952
|
+
...(started?.label ? { label: started.label } : {}),
|
|
953
|
+
error: message,
|
|
954
|
+
});
|
|
955
|
+
traceChanged();
|
|
956
|
+
return true;
|
|
957
|
+
};
|
|
958
|
+
options.registerStopChild?.(stopChild);
|
|
821
959
|
|
|
822
960
|
return await new Promise<WorkflowScriptResult>((resolve, reject) => {
|
|
823
961
|
const finish = (outcome: { value: unknown } | { error: Error & { workflowErrorKind?: unknown } }) => {
|
|
@@ -827,6 +965,7 @@ export async function runWorkflowScript(options: RunWorkflowScriptOptions): Prom
|
|
|
827
965
|
void Promise.allSettled([...steers.values()].map(({ promise }) => promise)).then(() => {
|
|
828
966
|
if (settled) return;
|
|
829
967
|
settled = true;
|
|
968
|
+
options.registerStopChild?.(undefined);
|
|
830
969
|
if (timer) clearTimeout(timer);
|
|
831
970
|
options.signal?.removeEventListener("abort", onAbort);
|
|
832
971
|
void worker.terminate();
|
|
@@ -1061,7 +1200,7 @@ export async function runWorkflowScript(options: RunWorkflowScriptOptions): Prom
|
|
|
1061
1200
|
const deliver = (promise: Promise<WorkflowScriptChildResult>) => collectFailure
|
|
1062
1201
|
? promise
|
|
1063
1202
|
: promise.then((result) => {
|
|
1064
|
-
if (!result.ok) {
|
|
1203
|
+
if (!result.ok && !result.stopped) {
|
|
1065
1204
|
const childError = new Error(result.detached ? `Run '${key}' detached: ${result.error ?? result.output}` : `Run '${key}' failed: ${result.error ?? result.output}`) as Error & { workflowErrorKind?: "detached-child" };
|
|
1066
1205
|
if (result.detached) childError.workflowErrorKind = "detached-child";
|
|
1067
1206
|
throw childError;
|
|
@@ -1100,13 +1239,16 @@ export async function runWorkflowScript(options: RunWorkflowScriptOptions): Prom
|
|
|
1100
1239
|
const promise = admission.then(async () => {
|
|
1101
1240
|
if (settled || finishing || stoppedLaunches.has(key)) {
|
|
1102
1241
|
const reason = childController.signal.reason;
|
|
1103
|
-
const text = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.";
|
|
1104
|
-
return
|
|
1242
|
+
const text = children.get(key)?.error ?? (reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.");
|
|
1243
|
+
return stoppedChildResult(key, text);
|
|
1105
1244
|
}
|
|
1245
|
+
const childStopController = new AbortController();
|
|
1246
|
+
childStopControllers.set(key, childStopController);
|
|
1247
|
+
const childSignal = combinedAbortSignal([childController.signal, childStopController.signal]);
|
|
1106
1248
|
const resolvedResumeValue = resumeReference
|
|
1107
1249
|
? await Promise.resolve().then(() => {
|
|
1108
1250
|
if (!options.resolveResume) throw new Error("Keyed workflow receipt resume is unavailable in this host.");
|
|
1109
|
-
return options.resolveResume(resumeReference,
|
|
1251
|
+
return options.resolveResume(resumeReference, childSignal);
|
|
1110
1252
|
})
|
|
1111
1253
|
: undefined;
|
|
1112
1254
|
const resolvedResume = typeof resolvedResumeValue === "string"
|
|
@@ -1124,22 +1266,24 @@ export async function runWorkflowScript(options: RunWorkflowScriptOptions): Prom
|
|
|
1124
1266
|
if (resolvedResumeLineage.at(-1) !== resolvedResumeId) resolvedResumeLineage.push(resolvedResumeId!);
|
|
1125
1267
|
}
|
|
1126
1268
|
const launchParams = resolvedResumeId ? { ...params, resume: resolvedResumeId } : params;
|
|
1127
|
-
return options.launch(key,
|
|
1269
|
+
return options.launch(key, launchParams, childSignal, { admitted: true });
|
|
1128
1270
|
}).then((result) => {
|
|
1129
1271
|
let normalized = !result.ok && !result.error ? { ...result, error: result.output } : result;
|
|
1130
1272
|
if (resolvedResumeLineage?.length && normalized.runId) {
|
|
1131
1273
|
normalized = { ...normalized, continuation: { runIds: [...new Set([...resolvedResumeLineage, normalized.runId])] } };
|
|
1132
1274
|
}
|
|
1133
|
-
|
|
1275
|
+
childStopControllers.delete(key);
|
|
1276
|
+
if (stoppedLaunches.has(key)) return children.get(key) ?? normalized;
|
|
1134
1277
|
children.set(key, normalized);
|
|
1135
|
-
const state = normalized.ok ? "completed" : normalized.detached ? "detached" : "failed";
|
|
1278
|
+
const state = normalized.ok ? "completed" : normalized.stopped ? "stopped" : normalized.detached ? "detached" : "failed";
|
|
1136
1279
|
trace.push({ operation: "run", key, state, durationMs: Date.now() - startedAt, ...workflowStringMetadata(params), ...(normalized.agent ? { agent: normalized.agent } : {}), ...(normalized.runId ? { runId: normalized.runId } : {}), ...(!normalized.ok ? { error: normalized.error ?? normalized.output } : {}) });
|
|
1137
1280
|
traceChanged();
|
|
1138
1281
|
return normalized;
|
|
1139
1282
|
}, (error: unknown) => {
|
|
1140
1283
|
const text = error instanceof Error ? error.message : String(error);
|
|
1141
1284
|
const failure: WorkflowScriptChildResult = { key, ok: false, output: text, error: text, artifactPaths: [] };
|
|
1142
|
-
|
|
1285
|
+
childStopControllers.delete(key);
|
|
1286
|
+
if (stoppedLaunches.has(key)) return children.get(key) ?? { ...failure, stopped: true };
|
|
1143
1287
|
children.set(key, failure);
|
|
1144
1288
|
trace.push({ operation: "run", key, state: "failed", durationMs: Date.now() - startedAt, ...workflowStringMetadata(params), error: text });
|
|
1145
1289
|
traceChanged();
|