@xzzpig/pi-subagents 0.24.2 → 0.25.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 +22 -0
- package/bundle/agent-management.js +4 -4
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/chunk-34TUUBRN.js +1107 -0
- package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
- package/bundle/{chunk-XWWUDWUW.js → chunk-5YEOWNSD.js} +371 -135
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-4UH4WS4G.js → chunk-6MNRKUHY.js} +23 -12
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-CYY5UMJU.js → chunk-IJWITCC6.js} +411 -249
- package/bundle/{chunk-RU522D5W.js → chunk-IKFKH5EL.js} +369 -50
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-JEA2ZKUA.js → chunk-IUDEI6FJ.js} +35 -200
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-224WMDIV.js → chunk-KCJFGKVK.js} +350 -123
- package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
- package/bundle/chunk-LYKG4FKH.js +523 -0
- package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-BQ2OAB4Q.js → chunk-OSVXFWPG.js} +67 -30
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
- package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
- package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/{chunk-O4D5PBVI.js → chunk-YWXILP5N.js} +3 -2
- 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 +27 -6
- package/docs/configuration.md +20 -8
- package/docs/extension-api.md +18 -1
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +7 -1
- package/docs/workflows.md +30 -2
- package/package.json +2 -2
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +46 -18
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +2 -3
- package/src/agents/agents.js +46 -20
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +13 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +51 -37
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +12 -3
- package/src/extension/schemas.js +7 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +55 -15
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +7 -10
- package/src/runs/background/async-execution.js +66 -29
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +114 -40
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +17 -6
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +2 -3
- package/src/runs/background/run-child-session.js +5 -8
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +2 -6
- package/src/runs/background/subagent-runner.js +88 -70
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/async-steering-action.js +24 -9
- 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.d.ts +0 -3
- package/src/runs/foreground/execution.js +56 -24
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +5 -10
- package/src/runs/foreground/subagent-executor.js +164 -49
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +6 -5
- package/src/runs/shared/child-session.js +85 -38
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- 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/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +51 -24
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +20 -5
- package/src/runs/shared/model-resolution.js +55 -50
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +18 -4
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +108 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +3 -15
- package/src/shared/utils.js +4 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +194 -68
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +344 -59
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- 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 +3 -3
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +13 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +81 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
- package/bundle/chunk-U4ODUYAG.js +0 -235
|
@@ -4,8 +4,8 @@ import { writePrivateAtomicJson } from "../../shared/atomic-json.js";
|
|
|
4
4
|
import { readStatus } from "../../shared/utils.js";
|
|
5
5
|
import { previewDisplayText } from "../../shared/display-text.js";
|
|
6
6
|
import { redactSecretValues } from "../shared/permissions.js";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const MAX_STEERING_REQUESTS = 20;
|
|
8
|
+
const STEERING_MESSAGE_PREVIEW_LIMIT = 160;
|
|
9
9
|
export function steeringMessagePreview(message) {
|
|
10
10
|
return previewDisplayText(redactSecretValues(message), STEERING_MESSAGE_PREVIEW_LIMIT);
|
|
11
11
|
}
|
|
@@ -44,7 +44,7 @@ export function recordSteeringRequest(status, input) {
|
|
|
44
44
|
requestedAt: input.requestedAt,
|
|
45
45
|
...(input.source ? { source: input.source } : {}),
|
|
46
46
|
messagePreview: steeringMessagePreview(input.message),
|
|
47
|
-
targets: input.targets.map((target) => ({ index: target.index, state: target.state, ...(target.reason ? { reason: target.reason } : {}) })),
|
|
47
|
+
targets: input.targets.map((target) => ({ index: target.index, state: target.state, ...(target.reason ? { reason: target.reason } : {}), ...(target.failureKind ? { failureKind: target.failureKind } : {}) })),
|
|
48
48
|
};
|
|
49
49
|
status.requested++;
|
|
50
50
|
status.lastRequestedAt = input.requestedAt;
|
|
@@ -70,6 +70,10 @@ export function updateSteeringTarget(status, requestId, index, state, now, field
|
|
|
70
70
|
const target = request?.targets.find((candidate) => candidate.index === index);
|
|
71
71
|
if (!target)
|
|
72
72
|
return undefined;
|
|
73
|
+
if (state !== "failed")
|
|
74
|
+
delete target.failureKind;
|
|
75
|
+
else if (fields.failureKind)
|
|
76
|
+
target.failureKind = fields.failureKind;
|
|
73
77
|
if (state === "late" && target.state === "recovered") {
|
|
74
78
|
if (target.lateDeliveredAt === undefined) {
|
|
75
79
|
target.lateDeliveredAt = now;
|
|
@@ -120,7 +124,7 @@ export function updateSteeringTarget(status, requestId, index, state, now, field
|
|
|
120
124
|
incrementStateCount(status, state);
|
|
121
125
|
return target;
|
|
122
126
|
}
|
|
123
|
-
|
|
127
|
+
function findSteeringRequest(status, requestId) {
|
|
124
128
|
return status.recent.find((request) => request.id === requestId);
|
|
125
129
|
}
|
|
126
130
|
export function actionResultFromSteeringStatus(status, sourceRunId, requestId, replacementRunId) {
|
|
@@ -133,6 +137,7 @@ export function actionResultFromSteeringStatus(status, sourceRunId, requestId, r
|
|
|
133
137
|
...(target.deliveredAt !== undefined ? { deliveredAt: target.deliveredAt } : {}),
|
|
134
138
|
...(target.lateDeliveredAt !== undefined ? { lateDeliveredAt: target.lateDeliveredAt } : {}),
|
|
135
139
|
...(target.reason ? { reason: target.reason } : {}),
|
|
140
|
+
...(target.failureKind ? { failureKind: target.failureKind } : {}),
|
|
136
141
|
...(target.replacementRunId ? { replacementRunId: target.replacementRunId } : {}),
|
|
137
142
|
}));
|
|
138
143
|
const states = targets.map((target) => target.state);
|
|
@@ -151,7 +156,7 @@ export function actionResultFromSteeringStatus(status, sourceRunId, requestId, r
|
|
|
151
156
|
const deliveryStatus = states.length > 0 && states.every((candidate) => candidate === "delivered" || candidate === "recovered") ? "delivered" : "queued";
|
|
152
157
|
return { requestId, state, deliveryStatus, sourceRunId, ...(effectiveReplacementRunId ? { replacementRunId: effectiveReplacementRunId } : {}), targets };
|
|
153
158
|
}
|
|
154
|
-
|
|
159
|
+
function steeringActionIsTerminal(result) {
|
|
155
160
|
return (result?.targets.length ?? 0) > 0 && result?.targets.every((target) => target.state === "queued" || target.state === "delivered") === true
|
|
156
161
|
|| result?.state === "delivered" || result?.state === "scheduled" || result?.state === "partial" || result?.state === "recovered" || result?.state === "failed";
|
|
157
162
|
}
|
|
@@ -204,7 +209,7 @@ export function claimSteeringRecovery(asyncDir, input) {
|
|
|
204
209
|
}
|
|
205
210
|
return { claimPath, markerPath };
|
|
206
211
|
}
|
|
207
|
-
|
|
212
|
+
function readSteeringStatus(asyncDir) {
|
|
208
213
|
return readStatus(asyncDir)?.steering;
|
|
209
214
|
}
|
|
210
215
|
export function remainingSteeringRecoveryLimits(descriptor, status, now = Date.now()) {
|
|
@@ -70,9 +70,10 @@ export interface SubagentRunConfig {
|
|
|
70
70
|
revivalLeaseToken?: string;
|
|
71
71
|
/** Global cap on simultaneously-running subagent tasks within this run. */
|
|
72
72
|
globalConcurrencyLimit?: number;
|
|
73
|
+
/** The parent's config.waitTool.name, when not bg_wait; this process and its children use it. */
|
|
74
|
+
waitToolName?: string;
|
|
73
75
|
capabilityCeiling?: ResolvedSubagentCapabilityCeiling;
|
|
74
76
|
runFanoutBudget?: RunFanoutBudgetDescriptor;
|
|
75
|
-
/** Builtin tool names the host runtime provides; used to intersect agent-declared tools. */
|
|
76
77
|
launchContractDigest?: string;
|
|
77
78
|
launchResolvedExtensions?: LaunchResolvedChildExtensions;
|
|
78
79
|
runtimeAcknowledgedExtensions?: RuntimeAcknowledgedChildExtensions;
|
|
@@ -119,7 +120,6 @@ interface StepResult {
|
|
|
119
120
|
nativeMachine?: import("../../shared/types.ts").SingleResult["nativeMachine"];
|
|
120
121
|
thinking?: string;
|
|
121
122
|
requestedModel?: string;
|
|
122
|
-
/** True when the dispatch failed because the input exceeded the model's context window. */
|
|
123
123
|
contextOverflow?: boolean;
|
|
124
124
|
totalCost?: CostSummary;
|
|
125
125
|
artifactPaths?: ArtifactPaths;
|
|
@@ -144,7 +144,6 @@ interface StepResult {
|
|
|
144
144
|
externalProcess?: ExternalProcessStatus;
|
|
145
145
|
externalJob?: ExternalJobStatus;
|
|
146
146
|
}
|
|
147
|
-
/** Context for running a single step */
|
|
148
147
|
interface SingleStepContext {
|
|
149
148
|
previousOutput: string;
|
|
150
149
|
outputs?: ChainOutputMap;
|
|
@@ -160,7 +159,6 @@ interface SingleStepContext {
|
|
|
160
159
|
outputFile: string;
|
|
161
160
|
transcriptPath?: string;
|
|
162
161
|
piPackageRoot?: string;
|
|
163
|
-
/** Factory the runner creates this step's child session through. */
|
|
164
162
|
childSessions: ChildSessionFactory;
|
|
165
163
|
/** The launching executor's own child runtime; nested route, depth, and ceilings come from here. */
|
|
166
164
|
inheritedChildRuntime?: InheritedChildRuntime;
|
|
@@ -178,8 +176,6 @@ interface SingleStepContext {
|
|
|
178
176
|
stopMessage?: string;
|
|
179
177
|
/** Resolved configured hard per-tool-call timeout (ms); fast tools still have a default when undefined. */
|
|
180
178
|
toolTimeoutMs?: number;
|
|
181
|
-
/** Effective step deadline (Date.now() + effective timeout) when a run budget exists. */
|
|
182
|
-
deadlineAt?: number;
|
|
183
179
|
childIntercomTarget?: string;
|
|
184
180
|
orchestratorIntercomTarget?: string;
|
|
185
181
|
nestedRoute?: NestedRouteInfo;
|
|
@@ -13,6 +13,7 @@ import { performance } from "node:perf_hooks";
|
|
|
13
13
|
import { pathToFileURL } from "node:url";
|
|
14
14
|
import { installRunnerHttpDispatcher } from "./runner-http-dispatcher.js";
|
|
15
15
|
import { writeAtomicJson } from "../../shared/atomic-json.js";
|
|
16
|
+
import { extractReportedProgress } from "../../shared/reported-progress.js";
|
|
16
17
|
import { withResultRunLease, writeAsyncResultFile, writePendingAsyncResultFile } from "./result-files.js";
|
|
17
18
|
import { createFileCoalescer } from "../../shared/file-coalescer.js";
|
|
18
19
|
import { createCapacityResilientJsonWriter } from "../../shared/capacity-resilient-json.js";
|
|
@@ -34,6 +35,7 @@ import { retainsChildCommand } from "../shared/child-commands.js";
|
|
|
34
35
|
import { buildRunnerChildLaunch } from "./runner-child-launch.js";
|
|
35
36
|
import { normalizeExtensionBindings } from "../shared/extension-bindings.js";
|
|
36
37
|
import { runChildSession } from "./run-child-session.js";
|
|
38
|
+
import { isBlockingSupervisorTool, pauseForSupervisorWait, startPausableTimer } from "../shared/supervisor-wait-timer.js";
|
|
37
39
|
import { loadRunnerChildSessionFactory } from "./runner-child-sessions.js";
|
|
38
40
|
import { SUBAGENT_CHILD_ENV, SUBAGENT_RUNNER_PID_ENV } from "../shared/child-runtime-config.js";
|
|
39
41
|
import { deriveChildSessionName } from "../../shared/child-session-name.js";
|
|
@@ -51,7 +53,7 @@ import { processTerminalPath, writeProcessTerminalCandidate } from "./process-te
|
|
|
51
53
|
import { persistRunnerStartupFailure } from "./runner-startup-failure.js";
|
|
52
54
|
import { currentRecordedPid } from "./boot-id.js";
|
|
53
55
|
import { createSteeringStatus, recordSteeringRequest, steeringStatus, terminalSteeringNoticeState, unconsumedSteerReason, updateSteeringTarget } from "./steering.js";
|
|
54
|
-
import { PROMPT_REDACTED, SUBAGENT_STOPPED_MESSAGE, SUBAGENT_TIMED_OUT_MESSAGE, detectSubagentError, extractTextFromContent, extractToolArgsPreview, formatEmptyTerminalAssistantResponseError, getAgentDir, hasEmptyTerminalAssistantResponse, readStatus } from "../../shared/utils.js";
|
|
56
|
+
import { PROMPT_REDACTED, SUBAGENT_STOPPED_MESSAGE, SUBAGENT_TIMED_OUT_MESSAGE, TRUNCATED_RESPONSE_ERROR, detectSubagentError, extractTextFromContent, extractToolArgsPreview, formatEmptyTerminalAssistantResponseError, getAgentDir, getTerminalAssistantStopReason, hasEmptyTerminalAssistantResponse, readStatus } from "../../shared/utils.js";
|
|
55
57
|
import { planAbortRecovery } from "../shared/abort-recovery.js";
|
|
56
58
|
import { createMutatingFailureState, didMutatingToolFail, isMutatingTool, nextLongRunningTrigger, recordMutatingFailure, resetMutatingFailureState, resolveCurrentPath, shouldEscalateMutatingFailures, summarizeRecentMutatingFailures, } from "../shared/long-running-guard.js";
|
|
57
59
|
import { parseSessionTokens } from "../../shared/session-tokens.js";
|
|
@@ -83,6 +85,7 @@ import { isRexLocalMachine } from "../shared/rex-machine.js";
|
|
|
83
85
|
import { HerdrExternalNeedsAttentionError, createHerdrExternalAdapter, prepareInternalHerdrExternalAdapter } from "../shared/herdr-external-adapters.js";
|
|
84
86
|
import { runExternalJob } from "../shared/external-job-runner.js";
|
|
85
87
|
import { createOrcaProgressTab } from "../shared/orca-progress-tabs.js";
|
|
88
|
+
import { setWaitToolName } from "../../shared/wait-tool-name.js";
|
|
86
89
|
import { acceptChildWatchdogEvent, applyChildWatchdogMessage, isChildWatchdogStatusEvent, resolveChildWatchdogConfig, } from "../../watchdog/child-status.js";
|
|
87
90
|
const INTERCOM_DETACH_RECEIPT = "Detached for intercom coordination before task completion.";
|
|
88
91
|
// This process hosts child sessions. An ambient copy of pi-subagents loaded
|
|
@@ -189,15 +192,6 @@ function appendDiagnosticJsonl(filePath, line, droppedEventType) {
|
|
|
189
192
|
}
|
|
190
193
|
state.diagnosticsTruncated = true;
|
|
191
194
|
}
|
|
192
|
-
function isBlockingSupervisorTool(toolName, args) {
|
|
193
|
-
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
194
|
-
return false;
|
|
195
|
-
if (toolName === "contact_supervisor") {
|
|
196
|
-
const reason = args.reason;
|
|
197
|
-
return reason === "need_decision" || reason === "interview_request";
|
|
198
|
-
}
|
|
199
|
-
return toolName === "intercom" && args.action === "ask";
|
|
200
|
-
}
|
|
201
195
|
function findLatestSessionFile(sessionDir) {
|
|
202
196
|
try {
|
|
203
197
|
const files = fs
|
|
@@ -781,7 +775,8 @@ export async function runSingleStepInner(step, ctx) {
|
|
|
781
775
|
});
|
|
782
776
|
}
|
|
783
777
|
const effectiveCwd = step.cwd ?? ctx.cwd;
|
|
784
|
-
|
|
778
|
+
// A placed child's cwd is a directory on its machine; only machine 'local' shares this disk.
|
|
779
|
+
const cwdError = step.machine && !isRexLocalMachine(step.machine) ? undefined : preflightLaunchCwd(step.requestedCwd ?? effectiveCwd, effectiveCwd);
|
|
785
780
|
if (cwdError)
|
|
786
781
|
return { agent: step.agent, output: cwdError, error: cwdError, exitCode: 1, context: step.context };
|
|
787
782
|
if (step.context === "fork" && step.sessionFile && fs.existsSync(step.sessionFile)) {
|
|
@@ -801,7 +796,7 @@ export async function runSingleStepInner(step, ctx) {
|
|
|
801
796
|
let actualLaunchContractDigest = step.launchContractDigest;
|
|
802
797
|
// A machine 'local' child edits this disk, so its local Git evidence is authoritative, as for an unplaced run.
|
|
803
798
|
const mutationSnapshot = step.machine && !isRexLocalMachine(step.machine) ? { source: "tracked-files", trackedOnly: true, cwd: step.cwd ?? ctx.cwd, dirtyFiles: [], fingerprints: {}, unavailable: "Local Git evidence is not authoritative for a pane-native remote run." } : snapshotTrackedMutations(step.cwd ?? ctx.cwd);
|
|
804
|
-
let finalMutationEvidence = collectTrackedMutationEvidence(mutationSnapshot, step.cwd ?? ctx.cwd);
|
|
799
|
+
let finalMutationEvidence = await collectTrackedMutationEvidence(mutationSnapshot, step.cwd ?? ctx.cwd);
|
|
805
800
|
let contextOverflow = false;
|
|
806
801
|
let launchWarningsEmitted = false;
|
|
807
802
|
const aggregateUsage = emptyUsage();
|
|
@@ -947,7 +942,6 @@ export async function runSingleStepInner(step, ctx) {
|
|
|
947
942
|
onContextWindow: (contextLimit) => ctx.onAttemptStart?.({ ...attemptModel, contextLimit }),
|
|
948
943
|
transcriptWriter,
|
|
949
944
|
toolTimeoutMs: ctx.toolTimeoutMs,
|
|
950
|
-
runDeadlineAt: ctx.deadlineAt,
|
|
951
945
|
expectedModelForVerification,
|
|
952
946
|
modelVerificationRegistry: step.modelVerificationRegistry,
|
|
953
947
|
modelResponseAliases: step.modelResponseAliases,
|
|
@@ -1023,8 +1017,12 @@ export async function runSingleStepInner(step, ctx) {
|
|
|
1023
1017
|
&& (!hiddenError?.hasError || hasEmptyTerminalAssistantResponse(run.messages))
|
|
1024
1018
|
? formatEmptyTerminalAssistantResponseError(run.messages)
|
|
1025
1019
|
: undefined;
|
|
1020
|
+
// Earlier errors in the chains below win, so only the hidden-error gate needs restating.
|
|
1021
|
+
const truncatedResponseError = hiddenError && !hiddenError.hasError && !validatedStructuredOutput && getTerminalAssistantStopReason(run.messages) === "length"
|
|
1022
|
+
? TRUNCATED_RESPONSE_ERROR
|
|
1023
|
+
: undefined;
|
|
1026
1024
|
const remoteGitChanged = run.nativeMachine?.initialGit && run.nativeMachine.finalGit ? run.nativeMachine.initialGit.head !== run.nativeMachine.finalGit.head || run.nativeMachine.initialGit.dirty !== run.nativeMachine.finalGit.dirty : undefined;
|
|
1027
|
-
const mutationEvidence = run.nativeMachine && !isRexLocalMachine(step.machine) ? { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: remoteGitChanged === true, ...(remoteGitChanged === undefined ? { unavailable: "Remote Git before/after evidence was incomplete." } : {}) } : collectTrackedMutationEvidence(mutationSnapshot, step.cwd ?? ctx.cwd);
|
|
1025
|
+
const mutationEvidence = run.nativeMachine && !isRexLocalMachine(step.machine) ? { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: remoteGitChanged === true, ...(remoteGitChanged === undefined ? { unavailable: "Remote Git before/after evidence was incomplete." } : {}) } : await collectTrackedMutationEvidence(mutationSnapshot, step.cwd ?? ctx.cwd);
|
|
1028
1026
|
finalMutationEvidence = mutationEvidence;
|
|
1029
1027
|
const mutationAttemptObserved = run.observedMutationAttempt === true || mutationEvidence.attemptedMutation === true;
|
|
1030
1028
|
// Validated structured output is persistable file content even when the final text is only
|
|
@@ -1040,7 +1038,7 @@ export async function runSingleStepInner(step, ctx) {
|
|
|
1040
1038
|
finalRequiredOutputMissing = requiredOutput?.missing;
|
|
1041
1039
|
const missingRequiredOutputError = terminalDiagnosticsEligible ? formatRequiredOutputError(requiredOutput) : undefined;
|
|
1042
1040
|
const missingRequiredOutputAfterMutation = Boolean(missingRequiredOutputError) && (mutationAttemptObserved || Boolean(mutationEvidence.changedFiles.length));
|
|
1043
|
-
const effectiveExitCode = toolAvailabilityError || midToolExitError || structuredError || emptyOutputError || missingRequiredOutputError
|
|
1041
|
+
const effectiveExitCode = toolAvailabilityError || midToolExitError || structuredError || truncatedResponseError || emptyOutputError || missingRequiredOutputError
|
|
1044
1042
|
? 1
|
|
1045
1043
|
: hiddenError?.hasError
|
|
1046
1044
|
? (hiddenError.exitCode ?? 1)
|
|
@@ -1052,6 +1050,7 @@ export async function runSingleStepInner(step, ctx) {
|
|
|
1052
1050
|
?? structuredError
|
|
1053
1051
|
?? run.error
|
|
1054
1052
|
?? emptyOutputError
|
|
1053
|
+
?? truncatedResponseError
|
|
1055
1054
|
?? (missingRequiredOutputAfterMutation ? missingRequiredOutputError : undefined)
|
|
1056
1055
|
?? (hiddenError?.hasError
|
|
1057
1056
|
? hiddenError.details
|
|
@@ -1302,9 +1301,9 @@ async function runSingleStep(step, ctx) {
|
|
|
1302
1301
|
ctx.orcaProgressTab?.section({ agent: step.agent, index: ctx.flatIndex, count: ctx.flatStepCount });
|
|
1303
1302
|
return runSingleStepInner(step, ctx);
|
|
1304
1303
|
}
|
|
1305
|
-
function externalRunnerStatus(runner) {
|
|
1304
|
+
function externalRunnerStatus(runner, machine) {
|
|
1306
1305
|
if (runner?.type === "external-cli") {
|
|
1307
|
-
return resolveExternalCliRunnerStatus(runner);
|
|
1306
|
+
return resolveExternalCliRunnerStatus(machine?.provider === "herdr" ? { ...runner, machine } : runner);
|
|
1308
1307
|
}
|
|
1309
1308
|
if (runner?.type === "external-job") {
|
|
1310
1309
|
return {
|
|
@@ -1480,17 +1479,12 @@ function combinedAbortSignal(signals) {
|
|
|
1480
1479
|
}
|
|
1481
1480
|
return controller.signal;
|
|
1482
1481
|
}
|
|
1483
|
-
async function runSingleStepWithTimeout(step, ctx,
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
const parentRemainingMs = parentDeadlineAt === undefined ? undefined : Math.max(0, parentDeadlineAt - Date.now());
|
|
1490
|
-
const timeoutMs = parentRemainingMs === undefined ? step.timeoutMs : Math.min(step.timeoutMs, parentRemainingMs);
|
|
1491
|
-
const timeoutMessage = parentRemainingMs !== undefined && parentRemainingMs <= step.timeoutMs
|
|
1492
|
-
? ctx.timeoutMessage
|
|
1493
|
-
: `Subagent timed out after ${step.timeoutMs}ms.`;
|
|
1482
|
+
async function runSingleStepWithTimeout(step, ctx, runRemainingMs) {
|
|
1483
|
+
const runRemainingAtStart = runRemainingMs();
|
|
1484
|
+
// When the run deadline comes first, the run timer ends this child; it also pauses for a sibling's supervisor wait.
|
|
1485
|
+
if (step.timeoutMs === undefined || (runRemainingAtStart !== undefined && runRemainingAtStart <= step.timeoutMs)) {
|
|
1486
|
+
return runSingleStep(step, ctx);
|
|
1487
|
+
}
|
|
1494
1488
|
const timeoutController = new AbortController();
|
|
1495
1489
|
let timeoutAction;
|
|
1496
1490
|
let timeoutTriggered = false;
|
|
@@ -1507,24 +1501,28 @@ async function runSingleStepWithTimeout(step, ctx, parentDeadlineAt) {
|
|
|
1507
1501
|
if (action && timeoutTriggered)
|
|
1508
1502
|
action();
|
|
1509
1503
|
};
|
|
1510
|
-
const timer =
|
|
1511
|
-
timer.unref?.();
|
|
1504
|
+
const timer = startPausableTimer(step.timeoutMs, triggerTimeout);
|
|
1512
1505
|
try {
|
|
1513
1506
|
return await runSingleStep(step, {
|
|
1514
1507
|
...ctx,
|
|
1515
1508
|
registerTimeout,
|
|
1516
|
-
|
|
1509
|
+
onChildEvent: (event) => {
|
|
1510
|
+
pauseForSupervisorWait(timer, event);
|
|
1511
|
+
ctx.onChildEvent?.(event);
|
|
1512
|
+
},
|
|
1517
1513
|
timeoutSignal: combinedAbortSignal([ctx.timeoutSignal, timeoutController.signal]),
|
|
1518
|
-
timeoutMessage
|
|
1514
|
+
timeoutMessage: `Subagent timed out after ${step.timeoutMs}ms.`,
|
|
1519
1515
|
});
|
|
1520
1516
|
}
|
|
1521
1517
|
finally {
|
|
1522
|
-
|
|
1518
|
+
timer.clear();
|
|
1523
1519
|
ctx.registerTimeout?.(undefined);
|
|
1524
1520
|
}
|
|
1525
1521
|
}
|
|
1526
1522
|
export async function runSubagent(config, childSessions) {
|
|
1527
1523
|
const { id, steps, resultPath, cwd, placeholder, taskIndex, totalTasks, maxOutput, artifactsDir, artifactConfig } = config;
|
|
1524
|
+
if (config.waitToolName)
|
|
1525
|
+
setWaitToolName(config.waitToolName);
|
|
1528
1526
|
const globalSemaphore = new Semaphore(config.globalConcurrencyLimit ?? DEFAULT_GLOBAL_CONCURRENCY_LIMIT);
|
|
1529
1527
|
let previousOutput = "";
|
|
1530
1528
|
const outputs = {};
|
|
@@ -1551,6 +1549,13 @@ export async function runSubagent(config, childSessions) {
|
|
|
1551
1549
|
let activityTimer;
|
|
1552
1550
|
let timeoutTimer;
|
|
1553
1551
|
let checkpointTimer;
|
|
1552
|
+
// The run deadline moves later by the time its children spent blocked on a supervisor reply.
|
|
1553
|
+
const runRemainingMs = () => timeoutTimer?.remainingMs();
|
|
1554
|
+
const runDeadlineAt = () => {
|
|
1555
|
+
const remainingMs = runRemainingMs();
|
|
1556
|
+
return remainingMs === undefined ? undefined : Date.now() + remainingMs;
|
|
1557
|
+
};
|
|
1558
|
+
const runDeadlineExpired = () => runRemainingMs() === 0;
|
|
1554
1559
|
let timedOut = false;
|
|
1555
1560
|
let stopped = false;
|
|
1556
1561
|
let usageBudgetExceeded = false;
|
|
@@ -1580,7 +1585,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
1580
1585
|
agent: task.agent,
|
|
1581
1586
|
...(task.lane ? { lane: task.lane } : config.lane ? { lane: config.lane } : {}),
|
|
1582
1587
|
...(taskSessionName ? { sessionName: taskSessionName } : {}),
|
|
1583
|
-
...(externalRunnerStatus(task.runner) ? { runner: externalRunnerStatus(task.runner) } : {}),
|
|
1588
|
+
...(externalRunnerStatus(task.runner, task.machine) ? { runner: externalRunnerStatus(task.runner, task.machine) } : {}),
|
|
1584
1589
|
...(statusStepDescription(task.task) ? { description: statusStepDescription(task.task) } : {}),
|
|
1585
1590
|
...(task.context ? { context: task.context } : {}),
|
|
1586
1591
|
phase: task.phase,
|
|
@@ -1612,7 +1617,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
1612
1617
|
parallelGroups.push({ start: flatStepCount, count: 1, stepIndex });
|
|
1613
1618
|
initialStatusSteps.push(omitUndefinedProperties({
|
|
1614
1619
|
agent: `expand:${step.parallel.agent}`,
|
|
1615
|
-
...(externalRunnerStatus(step.parallel.runner) ? { runner: externalRunnerStatus(step.parallel.runner) } : {}),
|
|
1620
|
+
...(externalRunnerStatus(step.parallel.runner, step.parallel.machine) ? { runner: externalRunnerStatus(step.parallel.runner, step.parallel.machine) } : {}),
|
|
1616
1621
|
...(step.parallel.context ? { context: step.parallel.context } : {}),
|
|
1617
1622
|
phase: step.phase ?? step.parallel.phase,
|
|
1618
1623
|
label: step.label ?? step.parallel.label ?? `Dynamic fanout (${step.collect.as})`,
|
|
@@ -1638,7 +1643,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
1638
1643
|
agent: step.agent,
|
|
1639
1644
|
...(step.lane ? { lane: step.lane } : config.lane ? { lane: config.lane } : {}),
|
|
1640
1645
|
...(stepSessionName ? { sessionName: stepSessionName } : {}),
|
|
1641
|
-
...(externalRunnerStatus(step.runner) ? { runner: externalRunnerStatus(step.runner) } : {}),
|
|
1646
|
+
...(externalRunnerStatus(step.runner, step.machine) ? { runner: externalRunnerStatus(step.runner, step.machine) } : {}),
|
|
1642
1647
|
...(statusStepDescription(step.task) ? { description: statusStepDescription(step.task) } : {}),
|
|
1643
1648
|
...(step.context ? { context: step.context } : {}),
|
|
1644
1649
|
phase: step.phase,
|
|
@@ -2669,9 +2674,11 @@ export async function runSubagent(config, childSessions) {
|
|
|
2669
2674
|
const target = request?.targets.find((candidate) => candidate.index === index);
|
|
2670
2675
|
if (!request || !target)
|
|
2671
2676
|
return;
|
|
2672
|
-
if (target.state === "delivered" || target.state === "late"
|
|
2677
|
+
if (target.state === "delivered" || target.state === "late")
|
|
2678
|
+
return;
|
|
2679
|
+
if (target.state === "failed" && !(target.failureKind === "unconsumed" && delivery.failureKind === "rejected"))
|
|
2673
2680
|
return;
|
|
2674
|
-
if (target.state === delivery.state)
|
|
2681
|
+
if (target.state === delivery.state && target.failureKind === delivery.failureKind)
|
|
2675
2682
|
return;
|
|
2676
2683
|
const late = fs.existsSync(steeringMarkerPath(requestId));
|
|
2677
2684
|
const now = Date.now();
|
|
@@ -2685,7 +2692,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
2685
2692
|
}
|
|
2686
2693
|
else {
|
|
2687
2694
|
markSteeringAttention(index);
|
|
2688
|
-
updateSteeringLifecycleTarget(requestId, index, "failed", now, { reason: delivery.message });
|
|
2695
|
+
updateSteeringLifecycleTarget(requestId, index, "failed", now, { reason: delivery.message, failureKind: delivery.failureKind ?? "rejected" });
|
|
2689
2696
|
emitSteeringEvent("subagent.steer.failed", { type: "steer", id: requestId, ts: now, message: delivery.message }, index, { reason: delivery.message });
|
|
2690
2697
|
}
|
|
2691
2698
|
emitTerminalSteeringNotice(requestId, `Steering failed for run ${id}: ${delivery.message}`);
|
|
@@ -2726,9 +2733,19 @@ export async function runSubagent(config, childSessions) {
|
|
|
2726
2733
|
statusPayload.lastUpdate = now;
|
|
2727
2734
|
writeStatusPayload();
|
|
2728
2735
|
};
|
|
2729
|
-
//
|
|
2736
|
+
// Keyed by step, so a step that ends mid-ask never leaves the run timers paused.
|
|
2737
|
+
const pauseRunTimers = (flatIndex) => {
|
|
2738
|
+
timeoutTimer?.pause(String(flatIndex));
|
|
2739
|
+
checkpointTimer?.pause(String(flatIndex));
|
|
2740
|
+
};
|
|
2741
|
+
const resumeRunTimers = (flatIndex) => {
|
|
2742
|
+
timeoutTimer?.resume(String(flatIndex));
|
|
2743
|
+
checkpointTimer?.resume(String(flatIndex));
|
|
2744
|
+
};
|
|
2745
|
+
// The sequential and both parallel paths share it.
|
|
2730
2746
|
const recordStepResult = (fi, singleResult, startedAt, endedAt, recordLaunchContractDigest = false) => {
|
|
2731
2747
|
const step = requiredStatusStep(statusPayload, fi);
|
|
2748
|
+
resumeRunTimers(fi);
|
|
2732
2749
|
const childStopped = singleResult.stopped === true;
|
|
2733
2750
|
const childInterrupted = singleResult.interrupted === true;
|
|
2734
2751
|
step.status = stopped || childStopped ? "stopped" : timedOut ? "failed" : childInterrupted ? "paused" : singleResult.execution?.status === "partial" ? "partial" : singleResult.exitCode === 0 ? "complete" : "failed";
|
|
@@ -2776,7 +2793,6 @@ export async function runSubagent(config, childSessions) {
|
|
|
2776
2793
|
if (singleResult.capabilityAudit)
|
|
2777
2794
|
statusPayload.capabilityAudit = singleResult.capabilityAudit;
|
|
2778
2795
|
};
|
|
2779
|
-
// Adds a parallel child's cost to the in-flight usage ledger.
|
|
2780
2796
|
const addParallelUsageCost = (totalCost) => {
|
|
2781
2797
|
if (!totalCost)
|
|
2782
2798
|
return;
|
|
@@ -2833,7 +2849,9 @@ export async function runSubagent(config, childSessions) {
|
|
|
2833
2849
|
statusPayload.toolBudget = step.toolBudget;
|
|
2834
2850
|
}
|
|
2835
2851
|
recordActiveToolCall(flatIndex, { toolCallId: event.toolCallId, toolName: event.toolName }, { argsPreview, currentPath, blocksSupervisor, now });
|
|
2836
|
-
|
|
2852
|
+
if (blocksSupervisor)
|
|
2853
|
+
pauseRunTimers(flatIndex);
|
|
2854
|
+
const pending = omitUndefinedProperties({ tool: event.toolName, path: currentPath, mutates, startedAt: now, progressText: extractReportedProgress(event.toolName, event.args) });
|
|
2837
2855
|
pendingToolResults[flatIndex] = pending;
|
|
2838
2856
|
const startedCallId = event.toolCallId;
|
|
2839
2857
|
if (typeof startedCallId === "string" && startedCallId)
|
|
@@ -2876,6 +2894,8 @@ export async function runSubagent(config, childSessions) {
|
|
|
2876
2894
|
const supervisorPreviousActivity = supervisorAttentionSteps.get(flatIndex);
|
|
2877
2895
|
const stillBlockingSupervisor = [...(activeToolCalls[flatIndex]?.values() ?? [])].some((active) => active.blocksSupervisor);
|
|
2878
2896
|
const clearedSupervisorAttention = endedTool?.blocksSupervisor && !stillBlockingSupervisor ? supervisorAttentionSteps.delete(flatIndex) : false;
|
|
2897
|
+
if (!stillBlockingSupervisor)
|
|
2898
|
+
resumeRunTimers(flatIndex);
|
|
2879
2899
|
if (clearedSupervisorAttention && step.activityState === "needs_attention") {
|
|
2880
2900
|
setOptionalProperty(step, "activityState", supervisorPreviousActivity);
|
|
2881
2901
|
syncAggregateActivityState();
|
|
@@ -2894,6 +2914,10 @@ export async function runSubagent(config, childSessions) {
|
|
|
2894
2914
|
pendingToolResults[flatIndex] = undefined;
|
|
2895
2915
|
const resultText = extractTextFromContent(event.message.content);
|
|
2896
2916
|
const resultToolName = event.message.toolName;
|
|
2917
|
+
if (event.message.isError !== true && resultToolName === toolSnapshot?.tool && toolSnapshot?.progressText) {
|
|
2918
|
+
step.progressText = toolSnapshot.progressText;
|
|
2919
|
+
step.progressUpdatedAt = now;
|
|
2920
|
+
}
|
|
2897
2921
|
const blockedTool = (typeof resultToolName === "string" && resultToolName.length > 0 ? resultToolName : undefined) ?? toolSnapshot?.tool;
|
|
2898
2922
|
const configuredToolBudget = flatSteps[flatIndex]?.toolBudget;
|
|
2899
2923
|
const budgetBlocked = configuredToolBudget !== undefined && isToolBudgetBlockedMessage(configuredToolBudget, resultText, blockedTool);
|
|
@@ -3138,7 +3162,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
3138
3162
|
source: "async", cwd, stepIndex, flatStartIndex, setup, diffs: [], results: [], cleanup,
|
|
3139
3163
|
});
|
|
3140
3164
|
writeStatusPayload();
|
|
3141
|
-
},
|
|
3165
|
+
}, runDeadlineAt());
|
|
3142
3166
|
const interruptRunner = () => {
|
|
3143
3167
|
consumeInterruptRequest(asyncDir);
|
|
3144
3168
|
if (interrupted || statusPayload.state !== "running")
|
|
@@ -3266,23 +3290,22 @@ export async function runSubagent(config, childSessions) {
|
|
|
3266
3290
|
});
|
|
3267
3291
|
if (config.deadlineAt !== undefined) {
|
|
3268
3292
|
const remainingMs = Math.max(0, config.deadlineAt - Date.now());
|
|
3269
|
-
|
|
3270
|
-
timeoutTimer
|
|
3293
|
+
const runTimer = startPausableTimer(remainingMs, timeoutRunner);
|
|
3294
|
+
timeoutTimer = runTimer;
|
|
3271
3295
|
// Route the pre-deadline checkpoint like any external steer so its lifecycle records the receipt.
|
|
3272
3296
|
const checkpointBeforeDeadlineMs = config.checkpointBeforeDeadlineMs;
|
|
3273
3297
|
const checkpointDelayMs = checkpointBeforeDeadlineMs === undefined || !Number.isInteger(checkpointBeforeDeadlineMs) || checkpointBeforeDeadlineMs <= 0
|
|
3274
3298
|
? undefined
|
|
3275
3299
|
: remainingMs - checkpointBeforeDeadlineMs;
|
|
3276
3300
|
if (checkpointDelayMs !== undefined && checkpointDelayMs >= 1_000) {
|
|
3277
|
-
|
|
3278
|
-
checkpointTimer = setTimeout(() => {
|
|
3301
|
+
checkpointTimer = startPausableTimer(checkpointDelayMs, () => {
|
|
3279
3302
|
checkpointTimer = undefined;
|
|
3280
3303
|
if (timedOut || stopped || interrupted)
|
|
3281
3304
|
return;
|
|
3282
3305
|
if (!statusPayload.steps.some((step) => step.status === "running"))
|
|
3283
3306
|
return;
|
|
3284
3307
|
const now = Date.now();
|
|
3285
|
-
const seconds = Math.round(
|
|
3308
|
+
const seconds = Math.round(runTimer.remainingMs() / 1000);
|
|
3286
3309
|
deliverSteerRequest({
|
|
3287
3310
|
type: "steer",
|
|
3288
3311
|
id: `deadline-checkpoint-${now}`,
|
|
@@ -3291,8 +3314,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
3291
3314
|
source: "deadline-checkpoint",
|
|
3292
3315
|
message: `Deadline checkpoint from the runner: this run is killed in about ${seconds} seconds. Finish the current tool call only, then stop and reply with a handoff: changed files, build/test state, remaining work, and commit/PR state. Do not start new work.`,
|
|
3293
3316
|
});
|
|
3294
|
-
}
|
|
3295
|
-
checkpointTimer.unref?.();
|
|
3317
|
+
});
|
|
3296
3318
|
}
|
|
3297
3319
|
}
|
|
3298
3320
|
appendJsonl(eventsPath, JSON.stringify({
|
|
@@ -3446,7 +3468,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
3446
3468
|
? path.join(path.dirname(step.parallel.outputPath), `dynamic-${stepIndex}`, `${itemIndex}-${step.parallel.agent}`, path.basename(step.parallel.outputPath))
|
|
3447
3469
|
: step.parallel.outputPath;
|
|
3448
3470
|
const taskText = task.task ?? step.parallel.task;
|
|
3449
|
-
const materializedTask = step.parallel.namespaceOutputPath ? injectSingleOutputInstruction(taskText, outputPath, step.parallel) : taskText;
|
|
3471
|
+
const materializedTask = step.parallel.namespaceOutputPath ? injectSingleOutputInstruction(taskText, outputPath, step.parallel, step.parallel.machine) : taskText;
|
|
3450
3472
|
const sessionName = deriveChildSessionName({ agent: step.parallel.agent, task: taskText, label: task.label ?? step.parallel.label });
|
|
3451
3473
|
return omitUndefinedProperties({
|
|
3452
3474
|
...step.parallel,
|
|
@@ -3479,7 +3501,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
3479
3501
|
return omitUndefinedProperties({
|
|
3480
3502
|
agent: task.agent,
|
|
3481
3503
|
...(task.sessionName ? { sessionName: task.sessionName } : {}),
|
|
3482
|
-
...(externalRunnerStatus(task.runner) ? { runner: externalRunnerStatus(task.runner) } : {}),
|
|
3504
|
+
...(externalRunnerStatus(task.runner, task.machine) ? { runner: externalRunnerStatus(task.runner, task.machine) } : {}),
|
|
3483
3505
|
...(statusStepDescription(task.task) ? { description: statusStepDescription(task.task) } : {}),
|
|
3484
3506
|
...(task.context ? { context: task.context } : {}),
|
|
3485
3507
|
...(task.phase ?? step.phase ? { phase: task.phase ?? step.phase } : {}),
|
|
@@ -3637,7 +3659,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
3637
3659
|
usageBudgetExhausted: continuationUsageBudgetExhausted,
|
|
3638
3660
|
usageBudget: config.usageBudget,
|
|
3639
3661
|
orcaProgressTab,
|
|
3640
|
-
}),
|
|
3662
|
+
}), runRemainingMs);
|
|
3641
3663
|
const taskEndTime = Date.now();
|
|
3642
3664
|
const childInterrupted = singleResult.interrupted === true;
|
|
3643
3665
|
const childStopped = singleResult.stopped === true;
|
|
@@ -3830,7 +3852,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
3830
3852
|
try {
|
|
3831
3853
|
worktreeSetup = await createWorktrees(cwd, `${id}-s${stepIndex}`, group.parallel.length, omitUndefinedProperties({
|
|
3832
3854
|
signal: setupSignal,
|
|
3833
|
-
deadlineAt:
|
|
3855
|
+
deadlineAt: runDeadlineAt(),
|
|
3834
3856
|
agents: group.parallel.map((task) => task.agent),
|
|
3835
3857
|
labels: group.parallel.map((task) => task.lane?.key ?? config.workflowKey ?? task.outputName ?? task.label),
|
|
3836
3858
|
tasks: group.parallel.map((task) => task.task),
|
|
@@ -3863,7 +3885,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
3863
3885
|
writeStatusPayload();
|
|
3864
3886
|
},
|
|
3865
3887
|
}));
|
|
3866
|
-
if (
|
|
3888
|
+
if (runDeadlineExpired())
|
|
3867
3889
|
timeoutRunner();
|
|
3868
3890
|
if (setupSignal.aborted)
|
|
3869
3891
|
throw new Error(stopped ? stopMessage : timedOut ? timeoutMessage ?? SUBAGENT_TIMED_OUT_MESSAGE : "Subagent paused during worktree setup.");
|
|
@@ -3871,7 +3893,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
3871
3893
|
catch (error) {
|
|
3872
3894
|
if (worktreeSetup)
|
|
3873
3895
|
await cleanupRemainingWorktree(worktreeSetup, stepIndex, groupStartFlatIndex);
|
|
3874
|
-
if (
|
|
3896
|
+
if (runDeadlineExpired())
|
|
3875
3897
|
timeoutRunner();
|
|
3876
3898
|
const setupError = error instanceof Error ? error.message : String(error);
|
|
3877
3899
|
if (error instanceof WorktreeSetupError)
|
|
@@ -4018,7 +4040,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
4018
4040
|
usageBudgetExhausted: continuationUsageBudgetExhausted,
|
|
4019
4041
|
usageBudget: config.usageBudget,
|
|
4020
4042
|
orcaProgressTab,
|
|
4021
|
-
}),
|
|
4043
|
+
}), runRemainingMs);
|
|
4022
4044
|
if (task.sessionFile) {
|
|
4023
4045
|
latestSessionFile = task.sessionFile;
|
|
4024
4046
|
}
|
|
@@ -4235,7 +4257,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
4235
4257
|
try {
|
|
4236
4258
|
singleWorktreeSetup = await createWorktrees(cwd, `${id}-s${stepIndex}`, 1, omitUndefinedProperties({
|
|
4237
4259
|
signal: setupSignal,
|
|
4238
|
-
deadlineAt:
|
|
4260
|
+
deadlineAt: runDeadlineAt(),
|
|
4239
4261
|
agents: [seqStep.agent],
|
|
4240
4262
|
labels: [seqStep.lane?.key ?? config.workflowKey ?? seqStep.outputName ?? seqStep.label],
|
|
4241
4263
|
tasks: [seqStep.task],
|
|
@@ -4274,7 +4296,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
4274
4296
|
catch (error) {
|
|
4275
4297
|
if (error instanceof WorktreeSetupError)
|
|
4276
4298
|
publishSetupUnknown(error.snapshot);
|
|
4277
|
-
if (
|
|
4299
|
+
if (runDeadlineExpired())
|
|
4278
4300
|
timeoutRunner();
|
|
4279
4301
|
const message = error instanceof Error ? error.message : String(error);
|
|
4280
4302
|
if (childStopRequests.has(flatIndex))
|
|
@@ -4295,7 +4317,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
4295
4317
|
break;
|
|
4296
4318
|
}
|
|
4297
4319
|
}
|
|
4298
|
-
if (singleWorktreeSetup &&
|
|
4320
|
+
if (singleWorktreeSetup && runDeadlineExpired())
|
|
4299
4321
|
timeoutRunner();
|
|
4300
4322
|
if (singleWorktreeSetup && (timedOut || stopped || interrupted || childStopRequests.has(flatIndex))) {
|
|
4301
4323
|
await cleanupRemainingWorktree(singleWorktreeSetup, stepIndex, flatIndex);
|
|
@@ -4371,7 +4393,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
4371
4393
|
usageBudgetExhausted: continuationUsageBudgetExhausted,
|
|
4372
4394
|
usageBudget: config.usageBudget,
|
|
4373
4395
|
orcaProgressTab,
|
|
4374
|
-
}),
|
|
4396
|
+
}), runRemainingMs);
|
|
4375
4397
|
}
|
|
4376
4398
|
catch (error) {
|
|
4377
4399
|
if (singleWorktreeSetup)
|
|
@@ -4640,14 +4662,10 @@ export async function runSubagent(config, childSessions) {
|
|
|
4640
4662
|
clearInterval(activityTimer);
|
|
4641
4663
|
activityTimer = undefined;
|
|
4642
4664
|
}
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
if (checkpointTimer) {
|
|
4648
|
-
clearTimeout(checkpointTimer);
|
|
4649
|
-
checkpointTimer = undefined;
|
|
4650
|
-
}
|
|
4665
|
+
timeoutTimer?.clear();
|
|
4666
|
+
timeoutTimer = undefined;
|
|
4667
|
+
checkpointTimer?.clear();
|
|
4668
|
+
checkpointTimer = undefined;
|
|
4651
4669
|
if (!timedOut && !stopped && !interrupted && config.timeoutMs !== undefined && timeoutMessage !== undefined && results.some((result) => result.timedOut === true && result.error?.startsWith(timeoutMessage))) {
|
|
4652
4670
|
timedOut = true;
|
|
4653
4671
|
}
|
|
@@ -4686,7 +4704,7 @@ export async function runSubagent(config, childSessions) {
|
|
|
4686
4704
|
continue;
|
|
4687
4705
|
changed = true;
|
|
4688
4706
|
const reason = target.state === "queued" ? unconsumedSteerReason() : "child terminated before steering delivery";
|
|
4689
|
-
updateSteeringLifecycleTarget(request.id, target.index, "failed", Date.now(), { reason });
|
|
4707
|
+
updateSteeringLifecycleTarget(request.id, target.index, "failed", Date.now(), { reason, failureKind: "unconsumed" });
|
|
4690
4708
|
markSteeringAttention(target.index);
|
|
4691
4709
|
emitSteeringEvent("subagent.steer.failed", { type: "steer", id: request.id, ts: request.requestedAt, message: reason }, target.index, { reason });
|
|
4692
4710
|
}
|