pi-subagents 0.85.0 → 0.87.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 +48 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-O7CPL6H4.js → chunk-2D2DQGC2.js} +9 -9
- package/bundle/{chunk-KZ34KQQH.js → chunk-2NY5PCKQ.js} +11 -5
- package/bundle/{chunk-PVIVCDG2.js → chunk-3CVOAS77.js} +2 -2
- package/bundle/{chunk-N7B2KD74.js → chunk-6O7YH2QV.js} +1 -1
- package/bundle/{chunk-IQIWF2VX.js → chunk-AIL46SZU.js} +8 -6
- package/bundle/{chunk-H2NLFTC5.js → chunk-BFF6YDK6.js} +1 -1
- package/bundle/{chunk-UX4SCV5N.js → chunk-C3KWLXDH.js} +159 -98
- package/bundle/{chunk-GCSLVFCX.js → chunk-C5QWQSSM.js} +1 -1
- package/bundle/{chunk-3UZ5FVVJ.js → chunk-DGTZKYIE.js} +39 -34
- package/bundle/{chunk-KDMFBYFM.js → chunk-ESWW6XSX.js} +1 -1
- package/bundle/{chunk-WOVMHDES.js → chunk-EYGBK6CE.js} +194 -94
- package/bundle/{chunk-CS4O36CZ.js → chunk-HDICKROY.js} +5 -5
- package/bundle/{chunk-DV2NCNPR.js → chunk-JLDQ6YUR.js} +12 -12
- package/bundle/{chunk-RQAUNAWG.js → chunk-LFKMM3UH.js} +2 -2
- package/bundle/{chunk-L2ENOFVZ.js → chunk-LZKVUWIY.js} +66 -26
- package/bundle/{chunk-RV5OGHLO.js → chunk-M2VBGET6.js} +2 -2
- package/bundle/{chunk-HFTBF7SG.js → chunk-OOE3R7IQ.js} +1 -1
- package/bundle/{chunk-JNXT3MPI.js → chunk-OTLDAYEQ.js} +5 -5
- package/bundle/{chunk-JWYG26RE.js → chunk-OZCPYJEY.js} +80 -37
- package/bundle/{chunk-LGMILZNE.js → chunk-PGU4TZV3.js} +79 -32
- package/bundle/{chunk-KEY3UQMQ.js → chunk-SIAQXPJ4.js} +6 -8
- package/bundle/{chunk-QO75KJBT.js → chunk-USRX7QXD.js} +2 -2
- package/bundle/{chunk-7MAE3DJV.js → chunk-VFUFOZBU.js} +1 -1
- package/bundle/{chunk-NF7IEKBH.js → chunk-W2BZS6UC.js} +27 -13
- package/bundle/{chunk-T5V5BRCL.js → chunk-W52LJANO.js} +1 -1
- package/bundle/{chunk-PHZP3KHB.js → chunk-XSDYTXHF.js} +18 -11
- package/bundle/{chunk-LTPH2DXH.js → chunk-XV7RTWTS.js} +3 -3
- package/bundle/{chunk-JO67XSKD.js → chunk-YEXKJJVS.js} +12 -7
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +9 -3
- package/docs/configuration.md +14 -6
- package/docs/extension-api.md +2 -0
- package/docs/models.md +6 -2
- package/docs/tool-reference.md +3 -0
- package/package.json +1 -1
- package/skills/pi-subagents/SKILL.md +7 -4
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.js +10 -6
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.js +37 -12
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/index.js +4 -2
- package/src/extension/schemas.d.ts +2 -0
- package/src/extension/schemas.js +1 -0
- package/src/extension/tool-activation.js +10 -1
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +8 -8
- package/src/runs/background/async-execution.d.ts +2 -1
- package/src/runs/background/async-execution.js +4 -2
- package/src/runs/background/run-status.js +5 -4
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/subagent-runner.js +6 -6
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +1 -0
- package/src/runs/foreground/subagent-executor.js +51 -8
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/child-session.d.ts +5 -4
- package/src/runs/shared/child-session.js +43 -33
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/herdr-placed-run.js +3 -2
- package/src/runs/shared/mcp-config-sources.d.ts +2 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.js +5 -6
- package/src/runs/shared/model-resolution.d.ts +19 -4
- package/src/runs/shared/model-resolution.js +50 -51
- package/src/runs/shared/structured-output.js +10 -3
- package/src/shared/artifacts.js +25 -13
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/types.d.ts +71 -48
- package/src/tui/render.js +83 -22
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/review.js +2 -2
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +103 -39
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +1 -1
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +3 -1
package/src/tui/render.js
CHANGED
|
@@ -245,6 +245,33 @@ export function compactTaskText(task, label) {
|
|
|
245
245
|
return undefined;
|
|
246
246
|
return previewDisplayText(normalized, COMPACT_TASK_MAX_CHARS);
|
|
247
247
|
}
|
|
248
|
+
const EXPANDED_TASK_MAX_LINES = 8;
|
|
249
|
+
/** Runs on every spinner frame, so the task is cut to what the line cap can show before any sanitizing or wrapping. */
|
|
250
|
+
function expandedTaskLines(task, label, width) {
|
|
251
|
+
const taskText = task?.trim();
|
|
252
|
+
if (!taskText || taskText === PROMPT_REDACTED || width <= 0)
|
|
253
|
+
return undefined;
|
|
254
|
+
const shown = truncateDisplayText(taskText, EXPANDED_TASK_MAX_LINES * width);
|
|
255
|
+
const labelText = label?.trim() && label.trim() !== PROMPT_REDACTED ? sanitizeDisplayText(label) : "";
|
|
256
|
+
const head = labelText && labelText !== sanitizeDisplayText(shown) ? `${labelText} — ` : "";
|
|
257
|
+
const lines = [];
|
|
258
|
+
for (const rawLine of `task: ${head}${shown}`.split("\n")) {
|
|
259
|
+
const content = sanitizeDisplayText(rawLine);
|
|
260
|
+
if (!content) {
|
|
261
|
+
if (lines.length > 0 && lines[lines.length - 1] !== "")
|
|
262
|
+
lines.push("");
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
const indent = rawLine.match(/^[ \t]*/)[0].replace(/\t/g, " ").slice(0, Math.floor(width / 2));
|
|
266
|
+
for (const part of wrapPlainText(content, width - indent.length))
|
|
267
|
+
lines.push(`${indent}${part}`);
|
|
268
|
+
if (lines.length > EXPANDED_TASK_MAX_LINES)
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
if (lines.length <= EXPANDED_TASK_MAX_LINES && shown.length === taskText.length)
|
|
272
|
+
return lines;
|
|
273
|
+
return [...lines.slice(0, EXPANDED_TASK_MAX_LINES), "…"];
|
|
274
|
+
}
|
|
248
275
|
const LANE_VALUE_MAX_CHARS = 48;
|
|
249
276
|
function boundedLaneValue(value, maxChars = LANE_VALUE_MAX_CHARS) {
|
|
250
277
|
if (!value?.trim() || value.trim() === PROMPT_REDACTED)
|
|
@@ -1543,7 +1570,7 @@ function widgetStepActivity(step, snapshotNow) {
|
|
|
1543
1570
|
return activity;
|
|
1544
1571
|
return facts.join(" · ");
|
|
1545
1572
|
}
|
|
1546
|
-
function widgetChainDetails(job, theme, expanded = false, width = getTermWidth(), frame) {
|
|
1573
|
+
function widgetChainDetails(job, theme, expanded = false, width = getTermWidth(), frame, fullTask = false) {
|
|
1547
1574
|
if (!job.steps?.length)
|
|
1548
1575
|
return [];
|
|
1549
1576
|
const total = job.chainStepCount ?? job.steps.length;
|
|
@@ -1551,7 +1578,7 @@ function widgetChainDetails(job, theme, expanded = false, width = getTermWidth()
|
|
|
1551
1578
|
for (const span of buildAsyncChainStepSpans(total, job.steps.length, job.parallelGroups)) {
|
|
1552
1579
|
const steps = job.steps.slice(span.start, span.start + span.count);
|
|
1553
1580
|
if (span.isParallel) {
|
|
1554
|
-
lines.push(...parallelWidgetGroupDetails(job, theme, { steps, total: span.count, stepIndex: span.stepIndex, chainTotal: total }, expanded, width, frame, false));
|
|
1581
|
+
lines.push(...parallelWidgetGroupDetails(job, theme, { steps, total: span.count, stepIndex: span.stepIndex, chainTotal: total }, expanded, width, frame, false, fullTask));
|
|
1555
1582
|
continue;
|
|
1556
1583
|
}
|
|
1557
1584
|
const step = steps[0];
|
|
@@ -1559,20 +1586,26 @@ function widgetChainDetails(job, theme, expanded = false, width = getTermWidth()
|
|
|
1559
1586
|
lines.push(` ${theme.fg("dim", `◦ Step ${span.stepIndex + 1}/${total}: pending`)}`);
|
|
1560
1587
|
continue;
|
|
1561
1588
|
}
|
|
1562
|
-
lines.push(...foregroundStyleWidgetStepLines(job, theme, step, "Step", span.stepIndex + 1, total, expanded, width, frame));
|
|
1589
|
+
lines.push(...foregroundStyleWidgetStepLines(job, theme, step, "Step", span.stepIndex + 1, total, expanded, width, frame, { fullTask }));
|
|
1563
1590
|
}
|
|
1564
1591
|
return lines;
|
|
1565
1592
|
}
|
|
1566
|
-
function widgetParallelAgentDetails(job, theme, expanded = false, width = getTermWidth(), frame) {
|
|
1593
|
+
function widgetParallelAgentDetails(job, theme, expanded = false, width = getTermWidth(), frame, fullTask = false) {
|
|
1567
1594
|
if (!job.steps?.length)
|
|
1568
1595
|
return [];
|
|
1596
|
+
// Multi-job cards prefix every line with a 4-column tree continuation after this returns.
|
|
1597
|
+
const taskLines = (step, indent) => expanded && fullTask && step.status === "running"
|
|
1598
|
+
? (expandedTaskLines(step.description, step.label, width - indent.length - 4) ?? []).map((line) => `${indent}${theme.fg("dim", line)}`)
|
|
1599
|
+
: [];
|
|
1600
|
+
if (job.mode === "single")
|
|
1601
|
+
return job.steps.flatMap((step) => taskLines(step, " "));
|
|
1569
1602
|
if (job.mode !== "parallel" && job.mode !== "chain")
|
|
1570
1603
|
return [];
|
|
1571
1604
|
if (job.mode === "chain" && !job.activeParallelGroup && job.parallelGroups?.length)
|
|
1572
|
-
return widgetChainDetails(job, theme, expanded, width, frame);
|
|
1605
|
+
return widgetChainDetails(job, theme, expanded, width, frame, fullTask);
|
|
1573
1606
|
const group = activeParallelWidgetGroup(job);
|
|
1574
1607
|
if (group)
|
|
1575
|
-
return parallelWidgetGroupDetails(job, theme, group, expanded, width, frame, Boolean(job.activeParallelGroup));
|
|
1608
|
+
return parallelWidgetGroupDetails(job, theme, group, expanded, width, frame, Boolean(job.activeParallelGroup), fullTask);
|
|
1576
1609
|
const total = job.stepsTotal ?? job.steps.length;
|
|
1577
1610
|
const lines = [];
|
|
1578
1611
|
for (const [index, step] of job.steps.entries()) {
|
|
@@ -1584,6 +1617,7 @@ function widgetParallelAgentDetails(job, theme, expanded = false, width = getTer
|
|
|
1584
1617
|
const display = step.sessionName?.trim() || (label ? `${label} (${step.agent})` : step.agent);
|
|
1585
1618
|
const thinking = childThinkingLevel(step);
|
|
1586
1619
|
lines.push(` ${theme.fg("dim", `${marker} ${widgetStepGlyph(step.status, theme, widgetStepRunningSeed(step, index), frame, thinking)} ${itemTitle} ${index + 1}/${total}: ${display} · ${widgetStepStatus(step.status, theme, thinking)}${modelDisplay}${activity ? ` · ${activity}` : ""}`)}`);
|
|
1620
|
+
lines.push(...taskLines(step, " "));
|
|
1587
1621
|
const lane = projectAsyncLane(job, step);
|
|
1588
1622
|
if (lane)
|
|
1589
1623
|
lines.push(...formatLaneProjectionLines(lane, theme, " "));
|
|
@@ -1731,7 +1765,7 @@ function parallelWidgetGroupHeader(group, theme, frame) {
|
|
|
1731
1765
|
: "parallel group";
|
|
1732
1766
|
return ` ${widgetStepGlyph(status, theme, widgetStepsRunningSeed(group.steps), frame)} ${themeBold(theme, label)} ${theme.fg("dim", "·")} ${theme.fg("dim", formatParallelOutcome(group.steps, group.total))}`;
|
|
1733
1767
|
}
|
|
1734
|
-
function parallelWidgetGroupDetails(job, theme, group, expanded, width, frame, prioritizeActive) {
|
|
1768
|
+
function parallelWidgetGroupDetails(job, theme, group, expanded, width, frame, prioritizeActive, fullTask = false) {
|
|
1735
1769
|
const lines = [parallelWidgetGroupHeader(group, theme, frame)];
|
|
1736
1770
|
const rows = parallelWidgetStepRows(group.steps, group.total, prioritizeActive);
|
|
1737
1771
|
for (const [rowIndex, row] of rows.entries()) {
|
|
@@ -1742,6 +1776,7 @@ function parallelWidgetGroupDetails(job, theme, group, expanded, width, frame, p
|
|
|
1742
1776
|
detailIndent: " ",
|
|
1743
1777
|
rowMarker: marker,
|
|
1744
1778
|
includeCurrentPath: true,
|
|
1779
|
+
fullTask,
|
|
1745
1780
|
}));
|
|
1746
1781
|
}
|
|
1747
1782
|
for (let index = rows.length; index < group.total; index++) {
|
|
@@ -2232,7 +2267,9 @@ function formatNestedWidgetLines(children, theme, width, expanded, snapshotNow,
|
|
|
2232
2267
|
append(children, 0, "");
|
|
2233
2268
|
return lines.map((line) => truncLine(line, width));
|
|
2234
2269
|
}
|
|
2235
|
-
function foregroundStyleWidgetStepLines(job, theme, step, itemTitle, index, total, expanded, width, frame,
|
|
2270
|
+
function foregroundStyleWidgetStepLines(job, theme, step, itemTitle, index, total, expanded, width, frame,
|
|
2271
|
+
/** `fullTask`: the widget has exactly one running child, so an expanded row may spend lines on its whole task. */
|
|
2272
|
+
options) {
|
|
2236
2273
|
const rowIndent = options?.rowIndent ?? " ";
|
|
2237
2274
|
const detailIndent = options?.detailIndent ?? " ";
|
|
2238
2275
|
const thinking = childThinkingLevel(step);
|
|
@@ -2251,7 +2288,11 @@ function foregroundStyleWidgetStepLines(job, theme, step, itemTitle, index, tota
|
|
|
2251
2288
|
const lane = projectAsyncLane(job, step);
|
|
2252
2289
|
if (lane)
|
|
2253
2290
|
lines.push(...formatLaneProjectionLines(lane, theme, detailIndent));
|
|
2254
|
-
|
|
2291
|
+
// Multi-job cards prefix every line with a 4-column tree continuation after this returns.
|
|
2292
|
+
const fullTask = expanded && options?.fullTask && step.status === "running" ? expandedTaskLines(step.description, step.label, width - detailIndent.length - 4) : undefined;
|
|
2293
|
+
const task = fullTask ? undefined : collapseDetails ? stepTaskSummary(step, displayName) : compactTaskText(step.description, step.label);
|
|
2294
|
+
for (const line of fullTask ?? [])
|
|
2295
|
+
lines.push(`${detailIndent}${theme.fg("dim", line)}`);
|
|
2255
2296
|
if (task)
|
|
2256
2297
|
lines.push(`${detailIndent}${theme.fg("dim", `task: ${task}`)}`);
|
|
2257
2298
|
const activity = widgetStepActivityLine(step, width, expanded, job.updatedAt);
|
|
@@ -2314,7 +2355,7 @@ function hostStepWidgetLines(job, theme, indent) {
|
|
|
2314
2355
|
lines.push(`${indent}${theme.fg("dim", `… +${rows.length - visible.length} host steps hidden`)}`);
|
|
2315
2356
|
return lines;
|
|
2316
2357
|
}
|
|
2317
|
-
function foregroundStyleWidgetDetails(job, theme, expanded, width, frame, projection = buildWorkflowWidgetProjection(job)) {
|
|
2358
|
+
function foregroundStyleWidgetDetails(job, theme, expanded, width, frame, projection = buildWorkflowWidgetProjection(job), fullTask = false) {
|
|
2318
2359
|
const steps = projection.steps.filter((step) => !projection.materializedKeys?.has(step.workflowKey ?? "") && !projection.materializedKeys?.has(step.runId ?? ""));
|
|
2319
2360
|
const checklist = widgetChecklistWithoutMaterializedChildren(projection);
|
|
2320
2361
|
if (!expanded && job.mode === "workflow") {
|
|
@@ -2332,14 +2373,14 @@ function foregroundStyleWidgetDetails(job, theme, expanded, width, frame, projec
|
|
|
2332
2373
|
];
|
|
2333
2374
|
}
|
|
2334
2375
|
if (job.mode === "chain" && !job.activeParallelGroup && job.parallelGroups?.length)
|
|
2335
|
-
return widgetChainDetails(job, theme, expanded, width, frame);
|
|
2376
|
+
return widgetChainDetails(job, theme, expanded, width, frame, fullTask);
|
|
2336
2377
|
const lines = [
|
|
2337
2378
|
...(expanded ? workflowPreflightLines(job) : []),
|
|
2338
2379
|
...workflowChecklistWidgetLines(checklist, theme, " ", expanded, frame, { includeItemErrors: !expanded, liveWidget: true }),
|
|
2339
2380
|
];
|
|
2340
2381
|
const group = activeParallelWidgetGroup(job);
|
|
2341
2382
|
if (group) {
|
|
2342
|
-
lines.push(...parallelWidgetGroupDetails(job, theme, group, expanded, width, frame, Boolean(job.activeParallelGroup)));
|
|
2383
|
+
lines.push(...parallelWidgetGroupDetails(job, theme, group, expanded, width, frame, Boolean(job.activeParallelGroup), fullTask));
|
|
2343
2384
|
}
|
|
2344
2385
|
else {
|
|
2345
2386
|
const { stageProgress, plannedKeys } = projection;
|
|
@@ -2356,7 +2397,7 @@ function foregroundStyleWidgetDetails(job, theme, expanded, width, frame, projec
|
|
|
2356
2397
|
const itemTitle = isPlannedStage ? "Stage" : "Step";
|
|
2357
2398
|
const displayIndex = isPlannedStage ? (step.index ?? index) + 1 : plannedKeys ? ++extraStepIndex : index + 1;
|
|
2358
2399
|
const displayTotal = isPlannedStage ? stageTotal : extraStepCount;
|
|
2359
|
-
lines.push(...foregroundStyleWidgetStepLines(job, theme, step, itemTitle, displayIndex, displayTotal, expanded, width, frame));
|
|
2400
|
+
lines.push(...foregroundStyleWidgetStepLines(job, theme, step, itemTitle, displayIndex, displayTotal, expanded, width, frame, { fullTask }));
|
|
2360
2401
|
}
|
|
2361
2402
|
}
|
|
2362
2403
|
lines.push(...hostStepWidgetLines(job, theme, " "));
|
|
@@ -2368,7 +2409,7 @@ function foregroundStyleWidgetDetails(job, theme, expanded, width, frame, projec
|
|
|
2368
2409
|
return lines;
|
|
2369
2410
|
}
|
|
2370
2411
|
/** `reservedLines` are lines the caller renders after these, such as materialized workflow children. */
|
|
2371
|
-
function buildSingleWidgetLines(job, theme, width, expanded, frame, projection = buildWorkflowWidgetProjection(job), reservedLines = 0) {
|
|
2412
|
+
function buildSingleWidgetLines(job, theme, width, expanded, frame, projection = buildWorkflowWidgetProjection(job), reservedLines = 0, fullTask = false) {
|
|
2372
2413
|
if ((!expanded || projection.inlineFleetCovered) && job.mode === "workflow")
|
|
2373
2414
|
return [compactWorkflowHeaderLine(job, theme, width), ...compactWorkflowWidgetBodyLines(job, theme, frame, projection, widgetLineBudget(expanded) - 1 - reservedLines)].map((line) => truncLine(line, width));
|
|
2374
2415
|
const stats = widgetStats(job, theme, projection, !expanded);
|
|
@@ -2385,7 +2426,7 @@ function buildSingleWidgetLines(job, theme, width, expanded, frame, projection =
|
|
|
2385
2426
|
return [
|
|
2386
2427
|
`${theme.fg("toolTitle", themeBold(theme, title))} ${theme.fg("dim", "· background")}`,
|
|
2387
2428
|
...(collapseDetails ? [] : [summary]),
|
|
2388
|
-
...foregroundStyleWidgetDetails(job, theme, expanded, width, frame, projection),
|
|
2429
|
+
...foregroundStyleWidgetDetails(job, theme, expanded, width, frame, projection, fullTask),
|
|
2389
2430
|
].map((line) => truncLine(line, width));
|
|
2390
2431
|
}
|
|
2391
2432
|
function compactSingleWidgetLines(job, theme, width, frame, projection = buildWorkflowWidgetProjection(job)) {
|
|
@@ -2817,7 +2858,7 @@ function widgetChecklistWithoutMaterializedChildren(projection) {
|
|
|
2817
2858
|
return checklist;
|
|
2818
2859
|
return { ...checklist, phases: checklist.phases.map((phase) => ({ ...phase, items: phase.items.filter((item) => !materializedKeys.has(item.key)) })) };
|
|
2819
2860
|
}
|
|
2820
|
-
function materializedWidgetChildLines(job, theme, width, expanded, frame, projectionFor) {
|
|
2861
|
+
function materializedWidgetChildLines(job, theme, width, expanded, frame, projectionFor, fullTask = false) {
|
|
2821
2862
|
const { children, inlineFleetCovered } = projectionFor(job);
|
|
2822
2863
|
if (inlineFleetCovered || !children?.length)
|
|
2823
2864
|
return [];
|
|
@@ -2829,9 +2870,9 @@ function materializedWidgetChildLines(job, theme, width, expanded, frame, projec
|
|
|
2829
2870
|
const identity = child.workflowKey ?? child.asyncId;
|
|
2830
2871
|
const stats = widgetStats(child, theme, projection, !expanded);
|
|
2831
2872
|
lines.push(` ${last ? "└─" : "├─"} ${theme.bold(identity)} ${widgetStatusGlyph(child, theme, frame)} ${themeBold(theme, widgetJobName(child))}${contextModeBadge(theme, child.context)}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`);
|
|
2832
|
-
for (const detail of foregroundStyleWidgetDetails(child, theme, expanded, Math.max(0, width - 6), frame, projection))
|
|
2873
|
+
for (const detail of foregroundStyleWidgetDetails(child, theme, expanded, Math.max(0, width - 6), frame, projection, fullTask))
|
|
2833
2874
|
lines.push(` ${last ? " " : "│ "}${detail}`);
|
|
2834
|
-
for (const detail of materializedWidgetChildLines(child, theme, Math.max(0, width - 4), expanded, frame, projectionFor))
|
|
2875
|
+
for (const detail of materializedWidgetChildLines(child, theme, Math.max(0, width - 4), expanded, frame, projectionFor, fullTask))
|
|
2835
2876
|
lines.push(` ${detail}`);
|
|
2836
2877
|
}
|
|
2837
2878
|
if (shown.length < children.length)
|
|
@@ -2934,12 +2975,32 @@ function buildWidgetComponent(jobs, ui, initiallyCollapsed = false, layout) {
|
|
|
2934
2975
|
return component;
|
|
2935
2976
|
};
|
|
2936
2977
|
}
|
|
2978
|
+
/** Running children the widget shows, counted the way it renders them: a workflow step that has
|
|
2979
|
+
* its own child job is that job's row, so it counts once. */
|
|
2980
|
+
function runningWidgetChildCount(jobs, projectionFor) {
|
|
2981
|
+
let running = 0;
|
|
2982
|
+
for (const job of jobs) {
|
|
2983
|
+
const { steps, materializedKeys, children } = projectionFor(job);
|
|
2984
|
+
if (!steps.length && job.status === "running")
|
|
2985
|
+
running++;
|
|
2986
|
+
for (const step of steps) {
|
|
2987
|
+
if (step.status === "running" && !materializedKeys?.has(step.workflowKey ?? "") && !materializedKeys?.has(step.runId ?? ""))
|
|
2988
|
+
running++;
|
|
2989
|
+
}
|
|
2990
|
+
if (children?.length)
|
|
2991
|
+
running += runningWidgetChildCount(children, projectionFor);
|
|
2992
|
+
}
|
|
2993
|
+
return running;
|
|
2994
|
+
}
|
|
2937
2995
|
function buildWidgetLinesWithProjection(jobs, theme, width = getTermWidth(), expanded = false, frame, projectionFor = workflowWidgetProjectionLookup()) {
|
|
2938
2996
|
if (jobs.length === 0)
|
|
2939
2997
|
return [];
|
|
2998
|
+
// Expanded rows show a whole task only while exactly one child runs in the whole widget; with
|
|
2999
|
+
// more, the extra lines would push other running children past the widget's line budget.
|
|
3000
|
+
const fullTask = expanded && runningWidgetChildCount(jobs, projectionFor) === 1;
|
|
2940
3001
|
if (jobs.length === 1) {
|
|
2941
|
-
const childLines = materializedWidgetChildLines(jobs[0], theme, width, expanded, frame, projectionFor).map((line) => truncLine(line, width));
|
|
2942
|
-
return [...buildSingleWidgetLines(jobs[0], theme, width, expanded, frame, projectionFor(jobs[0]), childLines.length), ...childLines];
|
|
3002
|
+
const childLines = materializedWidgetChildLines(jobs[0], theme, width, expanded, frame, projectionFor, fullTask).map((line) => truncLine(line, width));
|
|
3003
|
+
return [...buildSingleWidgetLines(jobs[0], theme, width, expanded, frame, projectionFor(jobs[0]), childLines.length, fullTask), ...childLines];
|
|
2943
3004
|
}
|
|
2944
3005
|
const running = jobs.filter((job) => job.status === "running");
|
|
2945
3006
|
const queued = jobs.filter((job) => job.status === "queued");
|
|
@@ -2965,14 +3026,14 @@ function buildWidgetLinesWithProjection(jobs, theme, width = getTermWidth(), exp
|
|
|
2965
3026
|
` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
|
|
2966
3027
|
...widgetLaneDetailLines(job, theme, projection),
|
|
2967
3028
|
...workflowChecklistWidgetLines(widgetChecklistWithoutMaterializedChildren(projection), theme, " ", expanded, frame, { includeItemErrors: !expanded || !job.steps?.length, liveWidget: true }),
|
|
2968
|
-
...widgetParallelAgentDetails(job, theme, expanded, width, frame),
|
|
3029
|
+
...widgetParallelAgentDetails(job, theme, expanded, width, frame, fullTask),
|
|
2969
3030
|
];
|
|
2970
3031
|
const item = [
|
|
2971
3032
|
compactWorkflow
|
|
2972
3033
|
? compactWorkflowHeaderLine(job, theme, width)
|
|
2973
3034
|
: `${widgetStatusGlyph(job, theme, frame)} ${themeBold(theme, widgetJobName(job))}${contextModeBadge(theme, job.context)}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`,
|
|
2974
3035
|
...details,
|
|
2975
|
-
...materializedWidgetChildLines(job, theme, width, expanded, frame, projectionFor),
|
|
3036
|
+
...materializedWidgetChildLines(job, theme, width, expanded, frame, projectionFor, fullTask),
|
|
2976
3037
|
];
|
|
2977
3038
|
items.push(item);
|
|
2978
3039
|
if (compactWorkflow)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeModelSegment, resolveModelCandidate } from "../runs/shared/model-resolution.js";
|
|
1
|
+
import { knownModelProviders, normalizeModelSegment, resolveModelCandidate } from "../runs/shared/model-resolution.js";
|
|
2
2
|
import { getSupportedThinkingLevels, splitKnownThinkingSuffix, THINKING_LEVELS, toModelInfo, } from "../shared/model-info.js";
|
|
3
3
|
export const STRONG_WATCHDOG_THINKING = "high";
|
|
4
4
|
const STRONG_WATCHDOG_MODELS = {
|
|
@@ -53,7 +53,7 @@ export function resolveWatchdogModelInput(ctx, rawModel) {
|
|
|
53
53
|
throw new Error("Watchdog model must be a non-empty provider/model value.");
|
|
54
54
|
const availableModels = modelRegistryEntries(ctx);
|
|
55
55
|
const preferredProvider = typeof ctx.model?.provider === "string" ? ctx.model.provider : undefined;
|
|
56
|
-
const resolved = resolveModelCandidate(trimmed, availableModels, preferredProvider) ?? trimmed;
|
|
56
|
+
const resolved = resolveModelCandidate(trimmed, availableModels, preferredProvider, knownModelProviders(ctx.modelRegistry)) ?? trimmed;
|
|
57
57
|
const { baseModel, thinkingSuffix } = splitKnownThinkingSuffix(resolved);
|
|
58
58
|
const named = splitProviderModel(baseModel);
|
|
59
59
|
if (!named)
|
package/src/watchdog/review.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Agent } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { createReadOnlyTools, convertToLlm } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { Type } from "typebox";
|
|
4
|
-
import { resolveModelCandidate } from "../runs/shared/model-resolution.js";
|
|
4
|
+
import { knownModelProviders, resolveModelCandidate } from "../runs/shared/model-resolution.js";
|
|
5
5
|
import { agentStreamOptions } from "../shared/agent-stream-options.js";
|
|
6
6
|
import { opencodeSessionHeaders } from "../shared/opencode-session-headers.js";
|
|
7
7
|
import { resolveEffectiveThinking, splitKnownThinkingSuffix, THINKING_LEVELS, toModelInfo } from "../shared/model-info.js";
|
|
@@ -54,7 +54,7 @@ function resolveReviewThinking(input) {
|
|
|
54
54
|
function resolveConfiguredModel(ctx, rawModel) {
|
|
55
55
|
const availableModels = ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
56
56
|
const preferredProvider = typeof ctx.model?.provider === "string" ? ctx.model.provider : undefined;
|
|
57
|
-
const resolved = resolveModelCandidate(rawModel, availableModels, preferredProvider);
|
|
57
|
+
const resolved = resolveModelCandidate(rawModel, availableModels, preferredProvider, knownModelProviders(ctx.modelRegistry));
|
|
58
58
|
if (!resolved) {
|
|
59
59
|
throw new Error(`Configured watchdog model '${rawModel}' did not match exactly one authenticated available model. Use provider/model or configure credentials for the intended provider.`);
|
|
60
60
|
}
|
|
@@ -184,6 +184,8 @@ export interface RunWorkflowScriptOptions {
|
|
|
184
184
|
set: (key: string, value: unknown) => void | Promise<void>;
|
|
185
185
|
};
|
|
186
186
|
registerStopChild?: (stop: ((key: string, message?: string) => boolean) | undefined) => void;
|
|
187
|
+
/** Drain: stop children that have not started, refuse new launches, and call `onDrained` once every started child has a result. Returns the started-child count. */
|
|
188
|
+
registerDrain?: (drain: ((onDrained: () => void) => number) | undefined) => void;
|
|
187
189
|
onTrace?: (trace: WorkflowScriptTraceEntry[]) => void;
|
|
188
190
|
onLanePlan?: (lanes: WorkflowLanePlan[]) => void;
|
|
189
191
|
onEmit?: (emits: unknown[]) => void;
|
|
@@ -20,6 +20,7 @@ function validGitRef(ref) {
|
|
|
20
20
|
}
|
|
21
21
|
const requireFromPackage = createRequire(import.meta.url);
|
|
22
22
|
const WORKFLOW_ASSEMBLY_FLUSH_TIMEOUT_MS = 5_000;
|
|
23
|
+
const WORKFLOW_DRAIN_CHILD_MESSAGE = "Workflow draining; child not started.";
|
|
23
24
|
function isWorkflowScriptFailureKind(value) {
|
|
24
25
|
return value === "validation" || value === "script" || value === "child" || value === "return-serialization" || value === "timeout" || value === "detached-child" || value === "runtime";
|
|
25
26
|
}
|
|
@@ -718,29 +719,63 @@ function directObjectPropertyValue(node, name) {
|
|
|
718
719
|
}
|
|
719
720
|
return value;
|
|
720
721
|
}
|
|
721
|
-
function
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
722
|
+
function arrayElements(node) {
|
|
723
|
+
return astNode(node) && node.type === "ArrayExpression" && Array.isArray(node.elements) ? node.elements : [];
|
|
724
|
+
}
|
|
725
|
+
/** The final definition of `name` in an object literal; undefined when a later spread or unknown key may overwrite it. */
|
|
726
|
+
function finalStaticProperty(node, name) {
|
|
727
|
+
if (node.type !== "ObjectExpression" || !Array.isArray(node.properties))
|
|
728
|
+
return undefined;
|
|
729
|
+
for (let index = node.properties.length - 1; index >= 0; index--) {
|
|
730
|
+
const property = node.properties[index];
|
|
727
731
|
if (!astNode(property) || property.type !== "Property")
|
|
728
|
-
return
|
|
732
|
+
return undefined;
|
|
729
733
|
const key = staticPropertyKey(property);
|
|
730
734
|
if (key === undefined)
|
|
731
|
-
return
|
|
732
|
-
if (key
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
}
|
|
735
|
+
return undefined;
|
|
736
|
+
if (key === name)
|
|
737
|
+
return property;
|
|
738
|
+
}
|
|
739
|
+
return undefined;
|
|
740
|
+
}
|
|
741
|
+
function validateStaticBaseRef(params, owner) {
|
|
742
|
+
const property = finalStaticProperty(params, "baseRef");
|
|
743
|
+
if (property?.kind !== "init" || !astNode(property.value))
|
|
741
744
|
return [];
|
|
745
|
+
const valueNode = property.value;
|
|
746
|
+
const value = literalString(valueNode);
|
|
747
|
+
return (value !== undefined || valueNode.type === "Literal") && !validGitRef(value)
|
|
748
|
+
? [{ message: `${owner} ${BASE_REF_VALIDATION_ERROR}`, ...nodeLocation(valueNode) }]
|
|
749
|
+
: [];
|
|
750
|
+
}
|
|
751
|
+
// Same text as validateLaneSpecs in workflow-script-worker.cjs; a test compares the two.
|
|
752
|
+
const LANE_RETAINED_RESUME_ERROR = "cannot resume a retained run id in runs.lanes; use runs.run(key, { resume: id }) outside lanes, or start the lane with an agent stage and use resume: \"previous\" later.";
|
|
753
|
+
// A spread or unknown computed key on the lane can replace `stages`.
|
|
754
|
+
function staticLane(lane) {
|
|
755
|
+
return astNode(lane) && lane.type === "ObjectExpression" && Array.isArray(lane.properties)
|
|
756
|
+
&& lane.properties.every((property) => astNode(property) && property.type === "Property" && staticPropertyKey(property) !== undefined);
|
|
757
|
+
}
|
|
758
|
+
/** The launch-time first-stage resume rule, for lanes written out as literals. */
|
|
759
|
+
function validateStaticLaneResumes(call) {
|
|
760
|
+
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
761
|
+
const lanes = arrayElements(args[0]);
|
|
762
|
+
const errors = [];
|
|
763
|
+
for (let laneIndex = 0; laneIndex < lanes.length; laneIndex++) {
|
|
764
|
+
const lane = lanes[laneIndex];
|
|
765
|
+
// A spread shifts every later lane index the runtime reports.
|
|
766
|
+
if (astNode(lane) && lane.type === "SpreadElement")
|
|
767
|
+
break;
|
|
768
|
+
if (!staticLane(lane))
|
|
769
|
+
continue;
|
|
770
|
+
const first = arrayElements(directObjectPropertyValue(lane, "stages"))[0];
|
|
771
|
+
if (!astNode(first))
|
|
772
|
+
continue;
|
|
773
|
+
const property = finalStaticProperty(first, "resume");
|
|
774
|
+
const resume = property?.kind === "init" ? literalString(property.value) : undefined;
|
|
775
|
+
if (resume !== undefined && resume !== "previous")
|
|
776
|
+
errors.push({ message: `runs.lanes lane ${laneIndex} stage 0 ${LANE_RETAINED_RESUME_ERROR}`, ...nodeLocation(first) });
|
|
742
777
|
}
|
|
743
|
-
return
|
|
778
|
+
return errors;
|
|
744
779
|
}
|
|
745
780
|
// Children with their own cwd, agentScope, or resume resolve agents elsewhere, and a
|
|
746
781
|
// spread or computed key can replace `agent`; leave those to launch-time resolution.
|
|
@@ -761,16 +796,12 @@ function staticChildAgentNode(params) {
|
|
|
761
796
|
}
|
|
762
797
|
function validateStaticChildAgents(call, agentNameError) {
|
|
763
798
|
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
764
|
-
const elements = (node) => astNode(node) && node.type === "ArrayExpression" && Array.isArray(node.elements) ? node.elements : [];
|
|
765
|
-
// A spread or unknown computed key on the lane can replace `stages`.
|
|
766
|
-
const staticLane = (lane) => astNode(lane) && lane.type === "ObjectExpression" && Array.isArray(lane.properties)
|
|
767
|
-
&& lane.properties.every((property) => astNode(property) && property.type === "Property" && staticPropertyKey(property) !== undefined);
|
|
768
799
|
const children = directRunsCall(call, "run")
|
|
769
800
|
? [{ owner: "runs.run", params: args[1] }]
|
|
770
801
|
: directRunsCall(call, "all")
|
|
771
|
-
?
|
|
802
|
+
? arrayElements(args[0]).map((params) => ({ owner: "runs.all item", params }))
|
|
772
803
|
: directRunsCall(call, "lanes")
|
|
773
|
-
?
|
|
804
|
+
? arrayElements(args[0]).flatMap((lane) => staticLane(lane) ? arrayElements(directObjectPropertyValue(lane, "stages")).map((params) => ({ owner: "runs.lanes stage", params })) : [])
|
|
774
805
|
: [];
|
|
775
806
|
const errors = [];
|
|
776
807
|
for (const child of children) {
|
|
@@ -784,8 +815,7 @@ function validateStaticChildAgents(call, agentNameError) {
|
|
|
784
815
|
}
|
|
785
816
|
function directRunsAllKeys(call) {
|
|
786
817
|
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
787
|
-
|
|
788
|
-
return items.flatMap((item) => {
|
|
818
|
+
return arrayElements(args[0]).flatMap((item) => {
|
|
789
819
|
if (!astNode(item))
|
|
790
820
|
return [];
|
|
791
821
|
const keyNode = directObjectPropertyValue(item, "key");
|
|
@@ -1021,18 +1051,18 @@ export function validateWorkflowScript(script, options = {}) {
|
|
|
1021
1051
|
errors.push({ message: `${subject}; every runs.all item needs a stable key, for example runs.all([{ key: "review", agent, task }]).`, ...nodeLocation(item.node) });
|
|
1022
1052
|
}
|
|
1023
1053
|
const args = Array.isArray(node.arguments) ? node.arguments : [];
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1054
|
+
for (const item of arrayElements(args[0]))
|
|
1055
|
+
if (astNode(item)) {
|
|
1056
|
+
errors.push(...validateStaticBaseRef(item, "runs.all item"));
|
|
1057
|
+
const message = definitelyNonJson(item);
|
|
1058
|
+
if (message)
|
|
1059
|
+
errors.push({ message: `runs.all item params are invalid: ${message}.`, ...nodeLocation(item) });
|
|
1060
|
+
}
|
|
1033
1061
|
}
|
|
1034
1062
|
if (directRunsCall(node, "host"))
|
|
1035
1063
|
errors.push(...validateStaticHostCall(node));
|
|
1064
|
+
if (directRunsCall(node, "lanes") && !runsRebound)
|
|
1065
|
+
errors.push(...validateStaticLaneResumes(node));
|
|
1036
1066
|
if (agentNameError)
|
|
1037
1067
|
errors.push(...validateStaticChildAgents(node, agentNameError));
|
|
1038
1068
|
const boundaryValue = node.type === "CallExpression" && astNode(node.callee) && node.callee.type === "Identifier" && node.callee.name === "emit" && Array.isArray(node.arguments) && astNode(node.arguments[0])
|
|
@@ -1068,7 +1098,7 @@ export function validateWorkflowScript(script, options = {}) {
|
|
|
1068
1098
|
if (keys.size === 0)
|
|
1069
1099
|
continue;
|
|
1070
1100
|
const args = Array.isArray(declaration.init.argument.arguments) ? declaration.init.argument.arguments : [];
|
|
1071
|
-
const itemCount =
|
|
1101
|
+
const itemCount = arrayElements(args[0]).length;
|
|
1072
1102
|
const arrayResultShape = Array.from({ length: itemCount });
|
|
1073
1103
|
for (const later of laterStatements) {
|
|
1074
1104
|
walkAstWithoutShadowedIdentifier(later, name, (node) => {
|
|
@@ -1243,6 +1273,10 @@ export async function runWorkflowScript(options) {
|
|
|
1243
1273
|
let acceptanceRecoveryBarrier;
|
|
1244
1274
|
let settled = false;
|
|
1245
1275
|
let finishing = false;
|
|
1276
|
+
let draining = false;
|
|
1277
|
+
let onDrained;
|
|
1278
|
+
// Keys past the concurrency semaphore: a drain lets these finish and stops the rest.
|
|
1279
|
+
const acquiredLaunches = new Set();
|
|
1246
1280
|
let assemblyAbortRequested = false;
|
|
1247
1281
|
let assemblyFlushTimer;
|
|
1248
1282
|
let abortError;
|
|
@@ -1293,6 +1327,13 @@ export async function runWorkflowScript(options) {
|
|
|
1293
1327
|
if (isAcceptanceMetadataRecovery(result))
|
|
1294
1328
|
acceptanceRecoveryBarrier = { key };
|
|
1295
1329
|
};
|
|
1330
|
+
const drainIfIdle = () => {
|
|
1331
|
+
if (!onDrained || [...launches.keys()].some((key) => !children.has(key)))
|
|
1332
|
+
return;
|
|
1333
|
+
const done = onDrained;
|
|
1334
|
+
onDrained = undefined;
|
|
1335
|
+
done();
|
|
1336
|
+
};
|
|
1296
1337
|
const stopChild = (key, message = `Workflow child '${key}' stopped.`) => {
|
|
1297
1338
|
if (!launches.has(key) || children.has(key))
|
|
1298
1339
|
return false;
|
|
@@ -1311,8 +1352,21 @@ export async function runWorkflowScript(options) {
|
|
|
1311
1352
|
error: message,
|
|
1312
1353
|
});
|
|
1313
1354
|
traceChanged();
|
|
1355
|
+
drainIfIdle();
|
|
1314
1356
|
return true;
|
|
1315
1357
|
};
|
|
1358
|
+
const drain = (done) => {
|
|
1359
|
+
if (!draining) {
|
|
1360
|
+
draining = true;
|
|
1361
|
+
onDrained = done;
|
|
1362
|
+
}
|
|
1363
|
+
for (const key of launches.keys())
|
|
1364
|
+
if (!acquiredLaunches.has(key))
|
|
1365
|
+
stopChild(key, WORKFLOW_DRAIN_CHILD_MESSAGE);
|
|
1366
|
+
const started = [...launches.keys()].filter((key) => !children.has(key)).length;
|
|
1367
|
+
drainIfIdle();
|
|
1368
|
+
return started;
|
|
1369
|
+
};
|
|
1316
1370
|
const notifyChildSettled = (key, result) => {
|
|
1317
1371
|
if (result.state === "running" || !options.onChildSettled || !options.workflowRunId)
|
|
1318
1372
|
return;
|
|
@@ -1341,6 +1395,7 @@ export async function runWorkflowScript(options) {
|
|
|
1341
1395
|
}
|
|
1342
1396
|
};
|
|
1343
1397
|
options.registerStopChild?.(stopChild);
|
|
1398
|
+
options.registerDrain?.(drain);
|
|
1344
1399
|
return await new Promise((resolve, reject) => {
|
|
1345
1400
|
const finish = (outcome) => {
|
|
1346
1401
|
if (settled || finishing)
|
|
@@ -1356,6 +1411,7 @@ export async function runWorkflowScript(options) {
|
|
|
1356
1411
|
return;
|
|
1357
1412
|
settled = true;
|
|
1358
1413
|
options.registerStopChild?.(undefined);
|
|
1414
|
+
options.registerDrain?.(undefined);
|
|
1359
1415
|
if (timer)
|
|
1360
1416
|
clearTimeout(timer);
|
|
1361
1417
|
options.signal?.removeEventListener("abort", onAbort);
|
|
@@ -1518,7 +1574,8 @@ export async function runWorkflowScript(options) {
|
|
|
1518
1574
|
return finish({ error: abortError ?? new Error("Workflow context was replaced or reloaded.") });
|
|
1519
1575
|
const respond = (promise, responsePath, onBoundaryError) => {
|
|
1520
1576
|
void promise.then((value) => {
|
|
1521
|
-
|
|
1577
|
+
// While draining, the script gets no answers: a refusal it throws on would abort the started children.
|
|
1578
|
+
if (settled || draining)
|
|
1522
1579
|
return;
|
|
1523
1580
|
const normalized = responsePath ? omitNonJsonWorkflowResultMetadata(value) : omitUndefinedWorkflowValues(value);
|
|
1524
1581
|
if (!responsePath) {
|
|
@@ -1534,7 +1591,7 @@ export async function runWorkflowScript(options) {
|
|
|
1534
1591
|
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)}` });
|
|
1535
1592
|
}
|
|
1536
1593
|
}, (error) => {
|
|
1537
|
-
if (!settled) {
|
|
1594
|
+
if (!settled && !draining) {
|
|
1538
1595
|
const errorKind = error instanceof Error ? error.workflowErrorKind : undefined;
|
|
1539
1596
|
worker.postMessage({ type: "response", callId: message.callId, ok: false, error: error instanceof Error ? error.message : String(error), ...(isWorkflowScriptFailureKind(errorKind) ? { errorKind } : {}) });
|
|
1540
1597
|
}
|
|
@@ -1633,6 +1690,8 @@ export async function runWorkflowScript(options) {
|
|
|
1633
1690
|
}
|
|
1634
1691
|
if (acceptanceRecoveryBarrier)
|
|
1635
1692
|
return respond(Promise.reject(new Error(recoveryBarrierMessage(acceptanceRecoveryBarrier.key, `runs.host('${key}')`))));
|
|
1693
|
+
if (draining)
|
|
1694
|
+
return respond(Promise.reject(new Error(`runs.host('${key}') refused: the workflow is draining.`)));
|
|
1636
1695
|
if (!options.host)
|
|
1637
1696
|
return respond(Promise.reject(new Error("runs.host is unavailable in this host context.")));
|
|
1638
1697
|
if (hostCalls.size >= HOST_STEP_MAX_COUNT)
|
|
@@ -1780,7 +1839,7 @@ export async function runWorkflowScript(options) {
|
|
|
1780
1839
|
return true;
|
|
1781
1840
|
});
|
|
1782
1841
|
admission = Promise.resolve().then(() => {
|
|
1783
|
-
if (settled || finishing)
|
|
1842
|
+
if (settled || finishing || draining)
|
|
1784
1843
|
return;
|
|
1785
1844
|
for (const call of calls)
|
|
1786
1845
|
assertRecoveryBarrierAllowsRun(call.key, call.params);
|
|
@@ -1791,6 +1850,8 @@ export async function runWorkflowScript(options) {
|
|
|
1791
1850
|
}
|
|
1792
1851
|
let resolvedResumeLineage;
|
|
1793
1852
|
const promise = admission.then(async () => {
|
|
1853
|
+
if (draining)
|
|
1854
|
+
stopChild(key, WORKFLOW_DRAIN_CHILD_MESSAGE);
|
|
1794
1855
|
if (settled || finishing || stoppedLaunches.has(key)) {
|
|
1795
1856
|
const reason = childController.signal.reason;
|
|
1796
1857
|
const text = children.get(key)?.error ?? (reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.");
|
|
@@ -1836,6 +1897,7 @@ export async function runWorkflowScript(options) {
|
|
|
1836
1897
|
const text = children.get(key)?.error ?? (reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.");
|
|
1837
1898
|
return stoppedChildResult(key, text);
|
|
1838
1899
|
}
|
|
1900
|
+
acquiredLaunches.add(key);
|
|
1839
1901
|
const result = await options.launch(key, launchParams, childSignal, { admitted: true, batch: batch !== undefined });
|
|
1840
1902
|
const autoResumeParams = setupAbortResumeParams(params, result, childSignal);
|
|
1841
1903
|
if (!autoResumeParams)
|
|
@@ -1870,6 +1932,7 @@ export async function runWorkflowScript(options) {
|
|
|
1870
1932
|
trace.push(settledEntry);
|
|
1871
1933
|
traceChanged();
|
|
1872
1934
|
notifyChildSettled(key, normalized);
|
|
1935
|
+
drainIfIdle();
|
|
1873
1936
|
return normalized;
|
|
1874
1937
|
}, (error) => {
|
|
1875
1938
|
const text = error instanceof Error ? error.message : String(error);
|
|
@@ -1881,6 +1944,7 @@ export async function runWorkflowScript(options) {
|
|
|
1881
1944
|
trace.push({ operation: "run", key, state: "failed", durationMs: Date.now() - startedAt, ...workflowStringMetadata(params), ...(generatedLaneKey ? { generatedLaneKey } : {}), error: text });
|
|
1882
1945
|
traceChanged();
|
|
1883
1946
|
notifyChildSettled(key, failure);
|
|
1947
|
+
drainIfIdle();
|
|
1884
1948
|
return failure;
|
|
1885
1949
|
});
|
|
1886
1950
|
launches.set(key, { fingerprint, promise, observed: callObserved, ...(generatedLaneKey ? { generatedLaneKey } : {}) });
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* and never becomes code. Scripts run on the ordinary workflow runtime.
|
|
5
5
|
*/
|
|
6
6
|
export type StructuredWorkflowKind = "tasks" | "chain";
|
|
7
|
-
|
|
7
|
+
/** Recovery advice per rejected field, so a retry keeps the caller's intent instead of dropping the field. */
|
|
8
|
+
export declare function unsupportedChildFieldAdvice(fields: readonly string[], scripts: boolean): string;
|
|
8
9
|
export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
9
|
-
/** Validate exact data shapes and expand them into a package-owned workflow script. */
|
|
10
|
-
export declare function buildStructuredWorkflowScript(kind: StructuredWorkflowKind, steps: unknown, originalTask: string | undefined): string;
|
|
10
|
+
/** Validate exact data shapes and expand them into a package-owned workflow script. `scripts` is true only for the named `parallel` workflow; top-level tasks and chain exist only when workflow scripts are disabled. */
|
|
11
|
+
export declare function buildStructuredWorkflowScript(kind: StructuredWorkflowKind, steps: unknown, originalTask: string | undefined, scripts: boolean): string;
|