@xzzpig/pi-subagents 0.24.2 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -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-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/{chunk-RU522D5W.js → chunk-FQPV4O6C.js} +183 -28
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-CYY5UMJU.js → chunk-IXCEOEJT.js} +411 -249
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-224WMDIV.js → chunk-JUYNN63E.js} +350 -123
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-XWWUDWUW.js → chunk-KRNBJPZ2.js} +670 -400
- 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-JEA2ZKUA.js → chunk-MMJQMPOK.js} +37 -165
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-4UH4WS4G.js → chunk-SNDCIJMK.js} +23 -12
- package/bundle/{chunk-O4D5PBVI.js → chunk-TM2K53NX.js} +3 -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-BQ2OAB4Q.js → chunk-WWDUNXSE.js} +67 -30
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- 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 +68 -84
- package/src/runs/foreground/fork-tool-result-handler.d.ts +60 -0
- package/src/runs/foreground/fork-tool-result-handler.js +83 -0
- 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 +64 -0
- package/src/shared/fleet-transcript-reader.js +376 -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-native-transcript.js +1 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -57
- package/src/tui/fleet-transcript.js +4 -370
- 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
|
@@ -13,13 +13,16 @@ import { reconcileAsyncRun } from "./stale-run-reconciler.js";
|
|
|
13
13
|
import { resultFilePath, resultPayloadPathForIndexedRun } from "./result-files.js";
|
|
14
14
|
import { canScanAsyncRunPrefix, MIN_SAFE_ASYNC_RUN_PREFIX_LENGTH } from "./run-id-query.js";
|
|
15
15
|
import { parallelHandoffPath, resolveRetainedWorktreeCwd } from "../shared/parallel-handoff.js";
|
|
16
|
-
import { normalizeWorktreeBaseRef } from "../shared/worktree.js";
|
|
16
|
+
import { findListedWorktreeAgentCwd, findListedWorktreeOnBranch, isComparablePathInside, normalizeWorktreeBaseRef } from "../shared/worktree.js";
|
|
17
17
|
import { intersectThinkingCeilings, parseThinkingLevel } from "../../shared/thinking-ceiling.js";
|
|
18
18
|
import { assertWorkflowGraphHostSteps } from "../shared/host-step-status.js";
|
|
19
19
|
import { validateSandboxProfileName } from "../../shared/sandbox-profile.js";
|
|
20
20
|
import { validatePermissionProfileName } from "../../shared/permission-profile.js";
|
|
21
21
|
import { validateIntercomBridgeConfig } from "../../intercom/intercom-bridge.js";
|
|
22
22
|
import { validateModelResponseAliases } from "../../shared/model-response-aliases.js";
|
|
23
|
+
import { readWorkflowLaunchRecord } from "../../workflows/workflow-launch-record.js";
|
|
24
|
+
import { recoveryDescriptorPath } from "../shared/run-launch-folder.js";
|
|
25
|
+
import { missingForkCopyNote } from "../../shared/artifacts.js";
|
|
23
26
|
function getErrorMessage(error) {
|
|
24
27
|
return error instanceof Error ? error.message : String(error);
|
|
25
28
|
}
|
|
@@ -265,6 +268,7 @@ function normalizeRecoveryAcceptance(value, descriptorPath) {
|
|
|
265
268
|
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${errors.join(" ")}`);
|
|
266
269
|
return value;
|
|
267
270
|
}
|
|
271
|
+
/** A workflow-mode target has a ceiling only when its parent-owned launch record exists (resolveAsyncResumeTarget). */
|
|
268
272
|
export function asyncReviveRequiresRecoveryDescriptor(target) {
|
|
269
273
|
if (target.recoveryDescriptor)
|
|
270
274
|
return false;
|
|
@@ -277,10 +281,8 @@ function resumeTargetMode(status, result) {
|
|
|
277
281
|
return result.mode;
|
|
278
282
|
return undefined;
|
|
279
283
|
}
|
|
280
|
-
export function readAsyncRecoveryDescriptor(
|
|
281
|
-
|
|
282
|
-
return undefined;
|
|
283
|
-
const descriptorPath = path.join(asyncDir, "recovery-descriptor.json");
|
|
284
|
+
export function readAsyncRecoveryDescriptor(runsRoot, runId) {
|
|
285
|
+
const descriptorPath = recoveryDescriptorPath(runsRoot, runId);
|
|
284
286
|
if (!fs.existsSync(descriptorPath))
|
|
285
287
|
return undefined;
|
|
286
288
|
let value;
|
|
@@ -298,7 +300,7 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
298
300
|
"subagentOnlyExtensions", "mcpDirectTools", "excludeTools", "mutationTools", "systemPrompt", "systemPromptMode", "inheritProjectContext", "inheritGlobalContext", "inheritSkills", "skills",
|
|
299
301
|
"skillPath", "agentFilePath", "memory", "outputPath", "outputMode", "structuredOutputSchema", "acceptance", "sessionDir", "artifactConfig",
|
|
300
302
|
"artifactsDir", "maxOutput", "controlConfig", "context", "intercomBridge", "absoluteDeadlineAt", "initialTurnBudget", "initialToolBudget", "maxSubagentDepth", "share", "capabilityCeiling",
|
|
301
|
-
"launchResolvedExtensions", "runFanoutBudget", "lane", "baseRef", "launcher",
|
|
303
|
+
"launchResolvedExtensions", "runFanoutBudget", "lane", "baseRef", "launcher", "requiredLauncher", "sessionId", "managedWorktree",
|
|
302
304
|
"extensionBindings",
|
|
303
305
|
"requiredExtensions",
|
|
304
306
|
]);
|
|
@@ -313,8 +315,16 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
313
315
|
}
|
|
314
316
|
if (parsed.version !== 1)
|
|
315
317
|
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': version must be 1.`);
|
|
316
|
-
if (parsed.launcher !== undefined && (typeof parsed.launcher !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(parsed.launcher)))
|
|
317
|
-
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': launcher must be a launcher name.`);
|
|
318
|
+
if (parsed.launcher !== undefined && parsed.launcher !== null && (typeof parsed.launcher !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(parsed.launcher)))
|
|
319
|
+
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': launcher must be a launcher name or null.`);
|
|
320
|
+
if (parsed.requiredLauncher !== undefined) {
|
|
321
|
+
const required = parsed.requiredLauncher;
|
|
322
|
+
if (!required || typeof required !== "object" || Array.isArray(required) || Object.keys(required).some((key) => key !== "name" && key !== "definitionDigest")
|
|
323
|
+
|| typeof required.name !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(required.name)
|
|
324
|
+
|| typeof required.definitionDigest !== "string" || !/^[0-9a-f]{64}$/.test(required.definitionDigest)) {
|
|
325
|
+
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': requiredLauncher must be { name, definitionDigest }.`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
318
328
|
try {
|
|
319
329
|
parsed.runFanoutBudget = validateRunFanoutBudgetDescriptor(parsed.runFanoutBudget);
|
|
320
330
|
}
|
|
@@ -386,7 +396,14 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
386
396
|
}
|
|
387
397
|
if (parsed.systemPrompt !== undefined && typeof parsed.systemPrompt !== "string")
|
|
388
398
|
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': systemPrompt must be a string.`);
|
|
389
|
-
|
|
399
|
+
if (parsed.managedWorktree !== undefined) {
|
|
400
|
+
const worktree = parsed.managedWorktree;
|
|
401
|
+
const valid = !!worktree && typeof worktree === "object" && !Array.isArray(worktree) && ((worktree.provider === "native" && typeof worktree.cwd === "string" && path.isAbsolute(worktree.cwd) && Object.keys(worktree).length === 2)
|
|
402
|
+
|| (worktree.provider === "worktrunk" && typeof worktree.branch === "string" && !!worktree.branch.trim() && Object.keys(worktree).length === 2));
|
|
403
|
+
if (!valid)
|
|
404
|
+
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': managedWorktree is invalid.`);
|
|
405
|
+
}
|
|
406
|
+
for (const field of ["sessionId", "launchContractDigest", "sessionFile", "model", "modelProvider", "thinking", "agentFilePath", "outputPath", "sessionDir", "artifactsDir"]) {
|
|
390
407
|
if (parsed[field] !== undefined && (typeof parsed[field] !== "string" || !parsed[field].trim()))
|
|
391
408
|
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${field} must be a non-empty string.`);
|
|
392
409
|
}
|
|
@@ -477,12 +494,33 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
477
494
|
// object crosses the persisted JSON boundary into the recovery descriptor type.
|
|
478
495
|
return parsed;
|
|
479
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* handoff.json sits in the run directory, so its worktree cwd must be the one the launch chose: the
|
|
499
|
+
* native path the parent computed, or a worktree git itself lists on the requested Worktrunk branch.
|
|
500
|
+
*/
|
|
501
|
+
function assertLaunchedWorktreeCwd(runId, launchCwd, launched, handoffCwd) {
|
|
502
|
+
const listed = launched.provider === "native" ? undefined : findListedWorktreeOnBranch(launchCwd, launched.branch);
|
|
503
|
+
const matches = launched.provider === "native"
|
|
504
|
+
? isComparablePathInside(launched.cwd, handoffCwd) && isComparablePathInside(handoffCwd, launched.cwd)
|
|
505
|
+
: listed !== undefined && isComparablePathInside(listed, handoffCwd);
|
|
506
|
+
if (!matches)
|
|
507
|
+
throw new Error(`Async run '${runId}' managed worktree ${handoffCwd} is not the worktree its launch created.`);
|
|
508
|
+
return handoffCwd;
|
|
509
|
+
}
|
|
510
|
+
/** A run launched in a worktree resumes in it, never in the source checkout, even when handoff.json is missing. */
|
|
511
|
+
function launchedWorktreeCwdWithoutHandoff(runId, launchCwd, launched) {
|
|
512
|
+
const cwd = launched.provider === "native" ? launched.cwd : findListedWorktreeAgentCwd(launchCwd, launched.branch);
|
|
513
|
+
if (cwd === undefined || !fs.statSync(cwd, { throwIfNoEntry: false })?.isDirectory()) {
|
|
514
|
+
throw new Error(`Async run '${runId}' ran in a managed worktree (${launched.provider === "native" ? launched.cwd : `branch ${launched.branch}`}) that no longer exists; it cannot resume in the source checkout.`);
|
|
515
|
+
}
|
|
516
|
+
return cwd;
|
|
517
|
+
}
|
|
480
518
|
function validateResumeSessionFile(runId, sessionFile) {
|
|
481
519
|
if (path.extname(sessionFile) !== ".jsonl")
|
|
482
520
|
throw new Error(`Async run '${runId}' session file must be a .jsonl file: ${sessionFile}`);
|
|
483
521
|
const resolved = path.resolve(sessionFile);
|
|
484
522
|
if (!fs.existsSync(resolved))
|
|
485
|
-
throw new Error(`Async run '${runId}' session file does not exist: ${sessionFile}`);
|
|
523
|
+
throw new Error(`Async run '${runId}' session file does not exist: ${sessionFile}${missingForkCopyNote(resolved)}`);
|
|
486
524
|
return resolved;
|
|
487
525
|
}
|
|
488
526
|
function validateResumeCwd(runId, cwd) {
|
|
@@ -507,20 +545,40 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
507
545
|
const requested = params.id ?? params.runId;
|
|
508
546
|
throw new Error(requested ? `Async run not found for '${requested}'.` : "Async run not found. Provide id or dir.");
|
|
509
547
|
}
|
|
548
|
+
// A run directory is always named for its run, so a status file naming another run is refused, and
|
|
549
|
+
// before reconciling: its repair publishes a result under the status file's run id.
|
|
550
|
+
if (location.asyncDir) {
|
|
551
|
+
let recordedRunId;
|
|
552
|
+
try {
|
|
553
|
+
recordedRunId = JSON.parse(fs.readFileSync(path.join(location.asyncDir, "status.json"), "utf-8")).runId;
|
|
554
|
+
}
|
|
555
|
+
catch { /* missing or unreadable: validateStatusForResume reports it */ }
|
|
556
|
+
if (typeof recordedRunId === "string" && recordedRunId !== path.basename(location.asyncDir))
|
|
557
|
+
throw new Error(`Async run '${path.basename(location.asyncDir)}' has a status file for a different run '${recordedRunId}'.`);
|
|
558
|
+
}
|
|
510
559
|
const reconciliation = location.asyncDir
|
|
511
560
|
? reconcileAsyncRun(location.asyncDir, { resultsDir, kill: deps.kill, now: deps.now })
|
|
512
561
|
: undefined;
|
|
513
562
|
const status = reconciliation?.status ?? null;
|
|
514
563
|
validateStatusForResume(status, location.asyncDir ? path.join(location.asyncDir, "status.json") : "status.json");
|
|
515
|
-
|
|
564
|
+
// Records are trusted only for a run folder directly under the runs root: `dir` may name a
|
|
565
|
+
// runs-shaped tree a run built inside its own folder.
|
|
566
|
+
const directRunFolder = location.asyncDir !== null && path.dirname(location.asyncDir) === path.resolve(asyncDirRoot);
|
|
567
|
+
const recoveryDescriptor = directRunFolder ? readAsyncRecoveryDescriptor(asyncDirRoot, path.basename(location.asyncDir)) : undefined;
|
|
516
568
|
const result = location.resultPath ? readResultFile(location.resultPath) : undefined;
|
|
517
|
-
const runId =
|
|
518
|
-
|
|
519
|
-
|
|
569
|
+
const runId = location.asyncDir ? path.basename(location.asyncDir) : result?.runId ?? result?.id ?? location.resolvedId ?? "unknown";
|
|
570
|
+
// Only a single run writes a recovery descriptor. When one exists, the run's identity (agent,
|
|
571
|
+
// session, cwd, model, ceilings) comes from it alone: status.json and the shared results directory
|
|
572
|
+
// are writable by a run behind a runner launcher.
|
|
573
|
+
const mode = recoveryDescriptor ? "single" : resumeTargetMode(status, result);
|
|
574
|
+
const notOwned = recoveryDescriptor
|
|
575
|
+
? !ownsRun(options.sessionId, recoveryDescriptor.sessionId)
|
|
576
|
+
: (status && !ownsRun(options.sessionId, status.sessionId)) || (result && !ownsRun(options.sessionId, result.sessionId));
|
|
577
|
+
if (options.sessionId && notOwned) {
|
|
520
578
|
throw new Error(`Async run '${runId}' was not found in the active session.`);
|
|
521
579
|
}
|
|
522
580
|
if (recoveryDescriptor && recoveryDescriptor.sourceRunId !== runId)
|
|
523
|
-
throw new Error(`Async run '${runId}' has a recovery descriptor for a different source run.`);
|
|
581
|
+
throw new Error(`Async run '${runId}' has a recovery descriptor for a different source run '${recoveryDescriptor.sourceRunId}'.`);
|
|
524
582
|
const state = status?.state ?? (result ? resultState(result) : undefined);
|
|
525
583
|
if (!state)
|
|
526
584
|
throw new Error(`Status file not found for async run '${runId}'.`);
|
|
@@ -539,18 +597,18 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
539
597
|
throw new Error(`Async run '${runId}' has ${stepCount} children. Index ${requestedIndex} is out of range.`);
|
|
540
598
|
const selectedStep = statusSteps[requestedIndex];
|
|
541
599
|
if (selectedStep?.status === "running") {
|
|
542
|
-
const capabilityCeiling = intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selectedStep.capabilityCeiling);
|
|
600
|
+
const capabilityCeiling = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selectedStep.capabilityCeiling);
|
|
543
601
|
return {
|
|
544
602
|
kind: "live",
|
|
545
603
|
runId,
|
|
546
604
|
asyncDir: location.asyncDir ?? undefined,
|
|
547
605
|
state,
|
|
548
606
|
...(mode ? { mode } : {}),
|
|
549
|
-
agent: selectedStep.agent,
|
|
607
|
+
agent: recoveryDescriptor?.agent ?? selectedStep.agent,
|
|
550
608
|
...(selectedStep.sessionName ?? result?.results?.[requestedIndex]?.sessionName ? { sessionName: selectedStep.sessionName ?? result?.results?.[requestedIndex]?.sessionName } : {}),
|
|
551
609
|
index: requestedIndex,
|
|
552
610
|
cwd: status?.cwd ?? result?.cwd,
|
|
553
|
-
sessionFile: selectedStep.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
611
|
+
sessionFile: recoveryDescriptor ? recoveryDescriptor.sessionFile : selectedStep.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
554
612
|
model: selectedStep.model,
|
|
555
613
|
thinking: selectedStep.thinking,
|
|
556
614
|
sandbox: selectedStep.sandbox ?? result?.results?.[requestedIndex]?.sandbox ?? result?.sandbox ?? recoveryDescriptor?.sandbox,
|
|
@@ -576,18 +634,18 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
576
634
|
if (!selected) {
|
|
577
635
|
throw new Error(`Async run '${runId}' has ${running.length} running children. Provide index to choose one.`);
|
|
578
636
|
}
|
|
579
|
-
const capabilityCeiling = intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selected.step.capabilityCeiling);
|
|
637
|
+
const capabilityCeiling = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selected.step.capabilityCeiling);
|
|
580
638
|
return {
|
|
581
639
|
kind: "live",
|
|
582
640
|
runId,
|
|
583
641
|
asyncDir: location.asyncDir ?? undefined,
|
|
584
642
|
state,
|
|
585
643
|
...(mode ? { mode } : {}),
|
|
586
|
-
agent: selected.step.agent,
|
|
644
|
+
agent: recoveryDescriptor?.agent ?? selected.step.agent,
|
|
587
645
|
...(selected.step.sessionName ?? result?.results?.[selected.index]?.sessionName ? { sessionName: selected.step.sessionName ?? result?.results?.[selected.index]?.sessionName } : {}),
|
|
588
646
|
index: selected.index,
|
|
589
647
|
cwd: status?.cwd ?? result?.cwd,
|
|
590
|
-
sessionFile: selected.step.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
648
|
+
sessionFile: recoveryDescriptor ? recoveryDescriptor.sessionFile : selected.step.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
591
649
|
model: selected.step.model,
|
|
592
650
|
thinking: selected.step.thinking,
|
|
593
651
|
sandbox: selected.step.sandbox ?? result?.results?.[selected.index]?.sandbox ?? result?.sandbox ?? recoveryDescriptor?.sandbox,
|
|
@@ -613,27 +671,41 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
613
671
|
if (selectedStatusStep?.status === "stopped" || selectedStatusStep?.stopped === true) {
|
|
614
672
|
throw new Error(`Async run '${runId}' child ${index} was stopped and cannot be resumed. Start a new run instead.`);
|
|
615
673
|
}
|
|
616
|
-
const agent = selectedStatusStep?.agent ?? resultSteps[index]?.agent ?? result?.agent;
|
|
674
|
+
const agent = recoveryDescriptor ? recoveryDescriptor.agent : selectedStatusStep?.agent ?? resultSteps[index]?.agent ?? result?.agent;
|
|
617
675
|
if (!agent)
|
|
618
676
|
throw new Error(`Could not determine child agent for async run '${runId}'.`);
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
677
|
+
const sessionFile = recoveryDescriptor
|
|
678
|
+
? recoveryDescriptor.sessionFile
|
|
679
|
+
: statusSteps[index]?.sessionFile
|
|
680
|
+
?? resultSteps[index]?.sessionFile
|
|
681
|
+
?? (stepCount === 1 ? status?.sessionFile ?? result?.sessionFile : undefined);
|
|
624
682
|
if (!sessionFile && requireSessionFile)
|
|
625
683
|
throw new Error(`Async run '${runId}' child ${index} does not have a persisted session file to resume from.`);
|
|
626
684
|
const resolvedSessionFile = sessionFile ? validateResumeSessionFile(runId, sessionFile) : undefined;
|
|
627
|
-
const stepModel = statusSteps[index]?.launchModel ?? statusSteps[index]?.model ?? resultSteps[index]?.model ?? (stepCount === 1 ? result?.model : undefined);
|
|
628
|
-
const stepThinking = statusSteps[index]?.thinking ?? resultSteps[index]?.thinking ?? (stepCount === 1 ? result?.thinking : undefined);
|
|
629
|
-
const thinkingCeiling =
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
685
|
+
const stepModel = recoveryDescriptor ? recoveryDescriptor.model : statusSteps[index]?.launchModel ?? statusSteps[index]?.model ?? resultSteps[index]?.model ?? (stepCount === 1 ? result?.model : undefined);
|
|
686
|
+
const stepThinking = recoveryDescriptor ? recoveryDescriptor.thinking : statusSteps[index]?.thinking ?? resultSteps[index]?.thinking ?? (stepCount === 1 ? result?.thinking : undefined);
|
|
687
|
+
const thinkingCeiling = recoveryDescriptor ? recoveryDescriptor.thinkingCeiling : statusSteps[index]?.thinkingCeiling;
|
|
688
|
+
// A workflow's admission ceiling comes only from the parent-owned launch record of its run directory:
|
|
689
|
+
// a run behind a launcher can write its own status.json (including a directory nested in it) and the
|
|
690
|
+
// shared results directory. Without a record there is no ceiling, so a revive without a recovery
|
|
691
|
+
// descriptor is refused.
|
|
692
|
+
const workflowLaunch = mode === "workflow" && directRunFolder
|
|
693
|
+
? readWorkflowLaunchRecord(asyncDirRoot, runId)
|
|
694
|
+
: undefined;
|
|
695
|
+
const capabilityCeiling = recoveryDescriptor
|
|
696
|
+
? recoveryDescriptor.capabilityCeiling
|
|
697
|
+
: mode === "workflow"
|
|
698
|
+
? (workflowLaunch?.ok ? workflowLaunch.record.admissionCapabilityCeiling : undefined)
|
|
699
|
+
: intersectSubagentCapabilityCeilings(status?.capabilityCeiling, statusSteps[index]?.capabilityCeiling, result?.capabilityCeiling, resultSteps[index]?.capabilityCeiling);
|
|
700
|
+
const handoffWorktreeCwd = location.asyncDir && (!recoveryDescriptor || recoveryDescriptor.managedWorktree)
|
|
634
701
|
? resolveRetainedWorktreeCwd(parallelHandoffPath(location.asyncDir), runId, index, statusSteps[index]?.worktreePath)
|
|
635
702
|
: undefined;
|
|
636
|
-
const
|
|
703
|
+
const managedWorktreeCwd = recoveryDescriptor?.managedWorktree
|
|
704
|
+
? handoffWorktreeCwd
|
|
705
|
+
? assertLaunchedWorktreeCwd(runId, recoveryDescriptor.cwd, recoveryDescriptor.managedWorktree, handoffWorktreeCwd)
|
|
706
|
+
: launchedWorktreeCwdWithoutHandoff(runId, recoveryDescriptor.cwd, recoveryDescriptor.managedWorktree)
|
|
707
|
+
: handoffWorktreeCwd;
|
|
708
|
+
const resumeCwd = validateResumeCwd(runId, managedWorktreeCwd ?? (recoveryDescriptor ? recoveryDescriptor.cwd : status?.cwd ?? result?.cwd));
|
|
637
709
|
return {
|
|
638
710
|
kind: "revive",
|
|
639
711
|
runId,
|
|
@@ -650,9 +722,10 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
650
722
|
...(stepThinking ? { thinking: stepThinking } : {}),
|
|
651
723
|
sandbox: statusSteps[index]?.sandbox ?? resultSteps[index]?.sandbox ?? result?.sandbox ?? recoveryDescriptor?.sandbox,
|
|
652
724
|
permissionProfile: statusSteps[index]?.permissionProfile ?? resultSteps[index]?.permissionProfile ?? result?.permissionProfile ?? recoveryDescriptor?.permissionProfile,
|
|
653
|
-
launchContractDigest: statusSteps[index]?.launchContractDigest ?? resultSteps[index]?.launchContractDigest ?? result?.launchContractDigest
|
|
654
|
-
|
|
655
|
-
...(statusSteps[index]?.
|
|
725
|
+
launchContractDigest: recoveryDescriptor ? recoveryDescriptor.launchContractDigest : statusSteps[index]?.launchContractDigest ?? resultSteps[index]?.launchContractDigest ?? result?.launchContractDigest,
|
|
726
|
+
// External runners write no recovery descriptor.
|
|
727
|
+
...(!recoveryDescriptor && statusSteps[index]?.runner ? { runner: statusSteps[index].runner } : {}),
|
|
728
|
+
...(!recoveryDescriptor && statusSteps[index]?.externalJob ? { externalJob: statusSteps[index].externalJob } : {}),
|
|
656
729
|
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
657
730
|
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
658
731
|
...(recoveryDescriptor ? { recoveryDescriptor } : {}),
|
|
@@ -687,8 +760,9 @@ export function applySteeringRecoveryAgentConfig(agentConfig, descriptor) {
|
|
|
687
760
|
output: descriptor.outputPath,
|
|
688
761
|
toolBudget: descriptor.initialToolBudget,
|
|
689
762
|
maxSubagentDepth: descriptor.maxSubagentDepth,
|
|
690
|
-
//
|
|
691
|
-
launcher
|
|
763
|
+
// A recorded launcher, or a recorded null (ran unwrapped), wins over the current agent file.
|
|
764
|
+
// A missing field says nothing, so the run never loses the agent file's launcher.
|
|
765
|
+
launcher: descriptor.launcher === undefined ? agentConfig.launcher : descriptor.launcher ?? undefined,
|
|
692
766
|
};
|
|
693
767
|
}
|
|
694
768
|
export function buildRevivedAsyncTask(target, message) {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
-
export declare const ASYNC_RETENTION_DAYS = 30;
|
|
3
2
|
export declare const ASYNC_RETENTION_BATCH_SIZE = 100;
|
|
4
3
|
export declare const ASYNC_RETENTION_DELAY_MS = 60000;
|
|
5
|
-
export declare const ASYNC_RETENTION_TOMBSTONE_GRACE_MS: number;
|
|
6
4
|
export declare const RESUMABLE_RETENTION_DAYS = 90;
|
|
7
5
|
export interface AsyncRetentionOptions {
|
|
8
6
|
asyncDirRoot: string;
|
|
@@ -11,10 +11,11 @@ import { REVIVAL_ORIGIN_FILE } from "../../workflows/workflow-revival.js";
|
|
|
11
11
|
import { ACTIVE_RUN_INDEX_DIR } from "./active-run-index.js";
|
|
12
12
|
import { encodeIndexSegment } from "./index-segment.js";
|
|
13
13
|
import { reconcileAsyncRun } from "./stale-run-reconciler.js";
|
|
14
|
-
|
|
14
|
+
import { recoveryDescriptorPath, runLaunchDir } from "../shared/run-launch-folder.js";
|
|
15
|
+
const ASYNC_RETENTION_DAYS = 30;
|
|
15
16
|
export const ASYNC_RETENTION_BATCH_SIZE = 100;
|
|
16
17
|
export const ASYNC_RETENTION_DELAY_MS = 60_000;
|
|
17
|
-
|
|
18
|
+
const ASYNC_RETENTION_TOMBSTONE_GRACE_MS = 24 * 60 * 60 * 1000;
|
|
18
19
|
// A run or result whose session file still exists can be resumed, so it is kept this long
|
|
19
20
|
// instead of ASYNC_RETENTION_DAYS. Session files outlive run dirs, so without a ceiling it is kept forever.
|
|
20
21
|
export const RESUMABLE_RETENTION_DAYS = 90;
|
|
@@ -108,7 +109,8 @@ function hasResumableContract(runDir, status) {
|
|
|
108
109
|
const statusSessionFiles = [status.sessionFile, ...(status.steps ?? []).map((step) => step.sessionFile)];
|
|
109
110
|
if (statusSessionFiles.some(existingRegularFile))
|
|
110
111
|
return true;
|
|
111
|
-
|
|
112
|
+
// runDir may be a tombstone; the launch folder is keyed by the run id.
|
|
113
|
+
const descriptorPath = recoveryDescriptorPath(path.dirname(runDir), status.runId);
|
|
112
114
|
if (!fs.existsSync(descriptorPath))
|
|
113
115
|
return false;
|
|
114
116
|
const descriptor = readJson(descriptorPath);
|
|
@@ -298,9 +300,15 @@ async function computeProcessStartIdentity(pid) {
|
|
|
298
300
|
if (process.platform === "win32") {
|
|
299
301
|
// PowerShell takes ~0.5 s to start; a synchronous spawn would freeze the TUI.
|
|
300
302
|
const started = await new Promise((resolve) => {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
303
|
+
// Node throws instead of calling back when the executable cannot be spawned at all (spawn UNKNOWN when policy blocks PowerShell).
|
|
304
|
+
try {
|
|
305
|
+
execFile("powershell.exe", ["-NoProfile", "-Command", `(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CreationDate`], { encoding: "utf-8", windowsHide: true, timeout: 5_000 }, (error, stdout) => {
|
|
306
|
+
resolve(error ? "" : stdout.trim());
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
resolve("");
|
|
311
|
+
}
|
|
304
312
|
});
|
|
305
313
|
return started ? `win:${started}` : undefined;
|
|
306
314
|
}
|
|
@@ -804,6 +812,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
804
812
|
}
|
|
805
813
|
mutationStateChanged = true;
|
|
806
814
|
fs.rmSync(runDir, { recursive: true });
|
|
815
|
+
fs.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
|
|
807
816
|
removeRunTombstoneMarker(maintenanceRoot, status.runId);
|
|
808
817
|
result.reapedTombstones += 1;
|
|
809
818
|
deletedIds.push(`run-tombstone:${status.runId}`);
|
|
@@ -835,6 +844,8 @@ export async function cleanupAsyncRetention(options) {
|
|
|
835
844
|
continue;
|
|
836
845
|
}
|
|
837
846
|
fs.rmSync(tombstone, { recursive: true });
|
|
847
|
+
// Retention never deletes a workflow run, so this removes only a single run's recovery descriptor.
|
|
848
|
+
fs.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
|
|
838
849
|
removeRunTombstoneMarker(maintenanceRoot, status.runId);
|
|
839
850
|
result.deletedRuns += 1;
|
|
840
851
|
deletedIds.push(`run:${status.runId}`);
|
|
@@ -248,6 +248,8 @@ function statusToSummary(asyncDir, status, nestedWarnings = [], nestedRoute) {
|
|
|
248
248
|
...(step.currentPath ? { currentPath: step.currentPath } : {}),
|
|
249
249
|
...(step.recentTools ? { recentTools: step.recentTools.map((tool) => ({ ...tool })) } : {}),
|
|
250
250
|
...(step.recentOutput ? { recentOutput: [...step.recentOutput] } : {}),
|
|
251
|
+
...(step.progressText ? { progressText: step.progressText } : {}),
|
|
252
|
+
...(step.progressUpdatedAt !== undefined ? { progressUpdatedAt: step.progressUpdatedAt } : {}),
|
|
251
253
|
...(step.turnCount !== undefined ? { turnCount: step.turnCount } : {}),
|
|
252
254
|
...(step.toolCount !== undefined ? { toolCount: step.toolCount } : {}),
|
|
253
255
|
...(step.steering ? { steering: step.steering } : {}),
|
|
@@ -566,6 +568,8 @@ function formatStepLine(step) {
|
|
|
566
568
|
parts.push(modelThinking);
|
|
567
569
|
if (step.durationMs !== undefined)
|
|
568
570
|
parts.push(formatDuration(step.durationMs));
|
|
571
|
+
if (step.progressText && step.status === "running")
|
|
572
|
+
parts.push(`progress: ${step.progressText}`);
|
|
569
573
|
if (step.tokens)
|
|
570
574
|
parts.push(`${formatTokens(step.tokens.total)} tok`);
|
|
571
575
|
if (step.lane)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { listAsyncRuns } from "./async-status.js";
|
|
2
2
|
import { backgroundWorkForSession, waitForSubagents, waitRunScopes } from "./subagent-wait.js";
|
|
3
|
+
import { waitToolName } from "../../shared/wait-tool-name.js";
|
|
3
4
|
export const DEFAULT_AUTO_DRAIN_TIMEOUT_MS = 30 * 60 * 1000;
|
|
4
5
|
function resultText(value) {
|
|
5
6
|
return value.content.map((part) => part.type === "text" ? part.text : "").join(" ").trim();
|
|
@@ -55,7 +56,7 @@ export async function drainOutstandingWork(deps, observation) {
|
|
|
55
56
|
hasPendingSupervisorRequest: deps.hasPendingSupervisorRequest,
|
|
56
57
|
});
|
|
57
58
|
if (waitResult.isError) {
|
|
58
|
-
throw new Error(`Auto-drain failed for session '${sessionId}': ${resultText(waitResult) ||
|
|
59
|
+
throw new Error(`Auto-drain failed for session '${sessionId}': ${resultText(waitResult) || `${waitToolName()} returned an error without details`}.`);
|
|
59
60
|
}
|
|
60
61
|
if (waitResult.details.wait?.reason === "supervisor_request")
|
|
61
62
|
break;
|
|
@@ -4,9 +4,7 @@ import type { RecordedPid } from "./stale-run-reconciler.ts";
|
|
|
4
4
|
* different boot id cannot still be running. Undefined when the platform has none.
|
|
5
5
|
*/
|
|
6
6
|
export declare function currentBootId(): string | undefined;
|
|
7
|
-
/** This process as a recorded pid, without the fields the platform does not have. */
|
|
8
7
|
export declare function currentRecordedPid(): RecordedPid;
|
|
9
|
-
/**
|
|
8
|
+
/** Runners take Pi's value from their config. */
|
|
10
9
|
export declare function primeBootId(value: string | undefined): void;
|
|
11
|
-
/** Clears the cache so the next read calls `nextReader` (default: the OS reader). */
|
|
12
10
|
export declare function resetBootIdForTesting(nextReader?: () => string | undefined): void;
|
|
@@ -30,17 +30,15 @@ export function currentBootId() {
|
|
|
30
30
|
runtime[BOOT_ID_KEY] = { value };
|
|
31
31
|
return value;
|
|
32
32
|
}
|
|
33
|
-
/** This process as a recorded pid, without the fields the platform does not have. */
|
|
34
33
|
export function currentRecordedPid() {
|
|
35
34
|
const pidNamespaceScope = currentPidNamespaceScope();
|
|
36
35
|
const bootId = currentBootId();
|
|
37
36
|
return { pid: process.pid, ...(pidNamespaceScope ? { pidNamespaceScope } : {}), ...(bootId ? { bootId } : {}) };
|
|
38
37
|
}
|
|
39
|
-
/**
|
|
38
|
+
/** Runners take Pi's value from their config. */
|
|
40
39
|
export function primeBootId(value) {
|
|
41
40
|
runtime[BOOT_ID_KEY] = { value };
|
|
42
41
|
}
|
|
43
|
-
/** Clears the cache so the next read calls `nextReader` (default: the OS reader). */
|
|
44
42
|
export function resetBootIdForTesting(nextReader) {
|
|
45
43
|
reader = nextReader ?? readBootIdFromOs;
|
|
46
44
|
delete runtime[BOOT_ID_KEY];
|
|
@@ -36,7 +36,7 @@ export interface CompletionBatcherOptions<T> {
|
|
|
36
36
|
now?: () => number;
|
|
37
37
|
}
|
|
38
38
|
export interface CompletionBatcher<T> {
|
|
39
|
-
/**
|
|
39
|
+
/** Emits immediately when batching is disabled. */
|
|
40
40
|
push(item: T): void;
|
|
41
41
|
/** Emit any held items immediately as a single group. */
|
|
42
42
|
flush(): void;
|
|
@@ -44,8 +44,7 @@ export interface CompletionBatcher<T> {
|
|
|
44
44
|
dispose(): T[];
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* timers for reload/shutdown without emitting.
|
|
47
|
+
* The batcher is single-use per registration: it holds at most one open group.
|
|
48
|
+
* `flush` forces emission; `dispose` tears down timers for reload/shutdown without emitting.
|
|
50
49
|
*/
|
|
51
50
|
export declare function createCompletionBatcher<T>(options: CompletionBatcherOptions<T>): CompletionBatcher<T>;
|
|
@@ -50,9 +50,8 @@ function unrefHandle(handle) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* timers for reload/shutdown without emitting.
|
|
53
|
+
* The batcher is single-use per registration: it holds at most one open group.
|
|
54
|
+
* `flush` forces emission; `dispose` tears down timers for reload/shutdown without emitting.
|
|
56
55
|
*/
|
|
57
56
|
export function createCompletionBatcher(options) {
|
|
58
57
|
const timers = options.timers ?? defaultTimers;
|
|
@@ -63,17 +63,11 @@ export interface CommandRequest {
|
|
|
63
63
|
}
|
|
64
64
|
export declare function requestAsyncCommand(dir: string, request: CommandRequest): void;
|
|
65
65
|
export declare const MAX_STEER_QUEUE_SIZE = 20;
|
|
66
|
-
/** Control inbox directory inside an async run dir. */
|
|
67
66
|
export declare function controlInboxDir(asyncDir: string): string;
|
|
68
|
-
/** Path of the portable interrupt request file. */
|
|
69
67
|
export declare function interruptRequestPath(asyncDir: string): string;
|
|
70
|
-
/** Path of the portable timeout request file. */
|
|
71
68
|
export declare function timeoutRequestPath(asyncDir: string): string;
|
|
72
|
-
/** Path of the portable manual stop request file. */
|
|
73
69
|
export declare function stopRequestPath(asyncDir: string): string;
|
|
74
|
-
/** Directory of parent-to-runner stop requests. */
|
|
75
70
|
export declare function stopRequestsDir(asyncDir: string): string;
|
|
76
|
-
/** Directory of parent-to-runner steering requests. */
|
|
77
71
|
export declare function steerRequestsDir(asyncDir: string): string;
|
|
78
72
|
export declare function steerInboxClosedPath(asyncDir: string): string;
|
|
79
73
|
export declare function stopInboxClosedPath(asyncDir: string): string;
|
|
@@ -82,27 +82,21 @@ const STOP_INBOX_CLOSED_FILE = "stop-inbox-closed.json";
|
|
|
82
82
|
const STOP_INBOX_CLOSED_MESSAGE = "Runner stop inbox is closed. Retry stop after runner shutdown is observed.";
|
|
83
83
|
const MAX_STEER_MESSAGE_BYTES = 128 * 1024;
|
|
84
84
|
const MAX_STEER_REQUEST_ID_LENGTH = 256;
|
|
85
|
-
/** Control inbox directory inside an async run dir. */
|
|
86
85
|
export function controlInboxDir(asyncDir) {
|
|
87
86
|
return path.join(asyncDir, "control");
|
|
88
87
|
}
|
|
89
|
-
/** Path of the portable interrupt request file. */
|
|
90
88
|
export function interruptRequestPath(asyncDir) {
|
|
91
89
|
return path.join(controlInboxDir(asyncDir), "interrupt.json");
|
|
92
90
|
}
|
|
93
|
-
/** Path of the portable timeout request file. */
|
|
94
91
|
export function timeoutRequestPath(asyncDir) {
|
|
95
92
|
return path.join(controlInboxDir(asyncDir), "timeout.json");
|
|
96
93
|
}
|
|
97
|
-
/** Path of the portable manual stop request file. */
|
|
98
94
|
export function stopRequestPath(asyncDir) {
|
|
99
95
|
return path.join(controlInboxDir(asyncDir), "stop.json");
|
|
100
96
|
}
|
|
101
|
-
/** Directory of parent-to-runner stop requests. */
|
|
102
97
|
export function stopRequestsDir(asyncDir) {
|
|
103
98
|
return path.join(controlInboxDir(asyncDir), STOP_REQUESTS_DIR);
|
|
104
99
|
}
|
|
105
|
-
/** Directory of parent-to-runner steering requests. */
|
|
106
100
|
export function steerRequestsDir(asyncDir) {
|
|
107
101
|
return path.join(controlInboxDir(asyncDir), STEER_REQUESTS_DIR);
|
|
108
102
|
}
|
|
@@ -9,6 +9,7 @@ import { formatNestedRunStatusLines } from "../shared/nested-render.js";
|
|
|
9
9
|
import { contextModeLabel, summarizeContextModes } from "../shared/context-mode.js";
|
|
10
10
|
import { formatAsyncRunOutputPath, formatAsyncRunProgressLabel, listAsyncRuns } from "./async-status.js";
|
|
11
11
|
import { isTrustedRecordedSessionFile } from "../../shared/session-file-trust.js";
|
|
12
|
+
import { waitToolName } from "../../shared/wait-tool-name.js";
|
|
12
13
|
const DEFAULT_TRANSCRIPT_LINES = 80;
|
|
13
14
|
const MAX_TRANSCRIPT_LINES = 500;
|
|
14
15
|
const TRANSCRIPT_TAIL_BYTES = 256 * 1024;
|
|
@@ -299,7 +300,7 @@ function formatDetachedForegroundFleetLines(runs) {
|
|
|
299
300
|
const childSummary = detachedChildren.map((child) => `${fleetChildDisplayName(child)} #${child.index}`).join(", ");
|
|
300
301
|
lines.push(`- ${run.runId} | detached | ${run.mode}${childSummary ? ` | ${childSummary}` : ""}`);
|
|
301
302
|
lines.push(` status: subagent({ action: "status", id: "${run.runId}" })`);
|
|
302
|
-
lines.push(` recovery: reply to the supervisor request first, then wait with
|
|
303
|
+
lines.push(` recovery: reply to the supervisor request first, then wait with ${waitToolName()}({ id: "${run.runId}" }); do not resume or launch a replacement while any child remains detached.`);
|
|
303
304
|
}
|
|
304
305
|
return lines;
|
|
305
306
|
}
|
|
@@ -467,8 +468,6 @@ function appendKnownArtifacts(lines, input) {
|
|
|
467
468
|
lines.push(` ${artifact}`);
|
|
468
469
|
}
|
|
469
470
|
/**
|
|
470
|
-
* Sanitizes each assembled line independently.
|
|
471
|
-
*
|
|
472
471
|
* Sanitizing the joined response would let a single binary fragment in child
|
|
473
472
|
* output collapse the whole transcript, including run state, artifact paths, and
|
|
474
473
|
* warnings, into the binary placeholder. Per-line sanitization keeps that damage
|