pi-subagents 0.84.0 → 0.85.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 +62 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-235AWJUQ.js → chunk-3UZ5FVVJ.js} +310 -101
- package/bundle/{chunk-F4ASL6OV.js → chunk-7MAE3DJV.js} +1 -1
- package/bundle/{chunk-4E7BKDTX.js → chunk-CS4O36CZ.js} +11 -156
- package/bundle/{chunk-VQVVHSY6.js → chunk-DV2NCNPR.js} +22 -11
- package/bundle/{chunk-G2Z6ZH26.js → chunk-GCSLVFCX.js} +1 -1
- package/bundle/{chunk-2S4K53MV.js → chunk-H2NLFTC5.js} +1 -1
- package/bundle/{chunk-NKQ6JNAS.js → chunk-HFTBF7SG.js} +2 -1
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-7BWGNDNK.js → chunk-IQIWF2VX.js} +190 -1177
- package/bundle/{chunk-XDQORLZ5.js → chunk-JNXT3MPI.js} +15 -6
- package/bundle/{chunk-J5YL7LYR.js → chunk-JO67XSKD.js} +59 -27
- package/bundle/{chunk-JG4QKI5M.js → chunk-JWYG26RE.js} +209 -93
- package/bundle/{chunk-C5P5CHYK.js → chunk-KDMFBYFM.js} +1 -1
- package/bundle/{chunk-V2BZYLEP.js → chunk-KEY3UQMQ.js} +7 -2
- package/bundle/{chunk-NENDSQUY.js → chunk-KZ34KQQH.js} +9 -6
- package/bundle/{chunk-AKOIVLA5.js → chunk-L2ENOFVZ.js} +76 -58
- package/bundle/{chunk-CGN2TVE7.js → chunk-LGMILZNE.js} +322 -18
- package/bundle/{chunk-L3WFKBEI.js → chunk-LTPH2DXH.js} +247 -153
- package/bundle/{chunk-2D52JFLF.js → chunk-N7B2KD74.js} +41 -117
- package/bundle/{chunk-PV63UFUR.js → chunk-O7CPL6H4.js} +183 -28
- package/bundle/{chunk-D3JAFGMO.js → chunk-PHZP3KHB.js} +1 -1
- package/bundle/{chunk-2DHZTCOL.js → chunk-PVIVCDG2.js} +2 -2
- package/bundle/{chunk-LFDBD4PW.js → chunk-QO75KJBT.js} +2 -2
- package/bundle/{chunk-SSG7IEP5.js → chunk-RQAUNAWG.js} +2 -2
- package/bundle/{chunk-PALJGGYC.js → chunk-RV5OGHLO.js} +6 -3
- package/bundle/chunk-T5V5BRCL.js +1067 -0
- package/bundle/{chunk-LNRJCP2Y.js → chunk-UX4SCV5N.js} +337 -207
- package/bundle/{chunk-DZDETGRJ.js → chunk-WOVMHDES.js} +231 -182
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +17 -2
- package/docs/configuration.md +2 -2
- package/docs/extension-api.md +16 -1
- package/docs/workflows.md +30 -2
- package/package.json +1 -1
- package/src/agents/agent-management.js +27 -11
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agents.d.ts +1 -3
- package/src/agents/agents.js +7 -6
- 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/extension/config.js +7 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +43 -32
- 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 +8 -3
- package/src/extension/schemas.js +5 -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 +25 -11
- package/src/extension/tool-description.js +6 -0
- 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 +5 -9
- package/src/runs/background/async-execution.js +62 -27
- 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 +112 -39
- package/src/runs/background/async-retention.js +6 -1
- 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 +0 -1
- package/src/runs/background/run-child-session.js +1 -1
- package/src/runs/background/run-status.js +4 -3
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/subagent-runner.d.ts +2 -4
- package/src/runs/background/subagent-runner.js +9 -6
- 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-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/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +17 -9
- package/src/runs/foreground/subagent-executor.d.ts +3 -2
- package/src/runs/foreground/subagent-executor.js +107 -26
- 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 +1 -1
- package/src/runs/shared/child-session.js +21 -2
- 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-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 +48 -22
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- 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 +2 -2
- package/src/runs/shared/model-resolution.js +7 -1
- 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 +30 -2
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +4 -2
- 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/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/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/types.d.ts +28 -11
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +0 -14
- package/src/shared/utils.js +0 -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-transcript.d.ts +1 -44
- package/src/tui/fleet-transcript.js +1 -327
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +81 -47
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.js +241 -20
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-resume-claim.js +2 -2
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +11 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +79 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ownerSessionIds,
|
|
3
|
+
ownsRun
|
|
4
|
+
} from "./chunk-HXRB42AF.js";
|
|
1
5
|
import {
|
|
2
6
|
ACTIVE_RUN_INDEX_DIR,
|
|
3
7
|
DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS,
|
|
@@ -15,12 +19,15 @@ import {
|
|
|
15
19
|
attachRootChildrenToSteps,
|
|
16
20
|
buildNestedRouteIndex,
|
|
17
21
|
cleanupWorktrees,
|
|
22
|
+
findListedWorktreeAgentCwd,
|
|
23
|
+
findListedWorktreeOnBranch,
|
|
18
24
|
findNestedRouteForRootId,
|
|
19
25
|
flatToLogicalStepIndex,
|
|
20
26
|
hashedSegment,
|
|
21
27
|
hostStepReportName,
|
|
22
28
|
hostStepVerdictLabel,
|
|
23
29
|
isActiveAsyncState,
|
|
30
|
+
isComparablePathInside,
|
|
24
31
|
normalizeParallelGroups,
|
|
25
32
|
normalizeWorktreeBaseRef,
|
|
26
33
|
parseHostStepNode,
|
|
@@ -39,10 +46,10 @@ import {
|
|
|
39
46
|
validateModelResponseAliases,
|
|
40
47
|
withWorkflowChildRunModel,
|
|
41
48
|
withWorktreeTransaction
|
|
42
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-LGMILZNE.js";
|
|
43
50
|
import {
|
|
44
51
|
validateIntercomBridgeConfig
|
|
45
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-KDMFBYFM.js";
|
|
46
53
|
import {
|
|
47
54
|
stableJsonDigest
|
|
48
55
|
} from "./chunk-7F6RKT6W.js";
|
|
@@ -73,7 +80,7 @@ import {
|
|
|
73
80
|
validateToolBudgetConfig,
|
|
74
81
|
waitForFileSystemRetry,
|
|
75
82
|
writeAtomicJson
|
|
76
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-UX4SCV5N.js";
|
|
77
84
|
import {
|
|
78
85
|
DIRS,
|
|
79
86
|
RUNNER_LAUNCHER_NAME_PATTERN,
|
|
@@ -90,48 +97,6 @@ import {
|
|
|
90
97
|
parseSubagentCapabilityCeiling
|
|
91
98
|
} from "./chunk-QXASAHIA.js";
|
|
92
99
|
|
|
93
|
-
// src/shared/session-succession.ts
|
|
94
|
-
var SUCCESSION_KEY = /* @__PURE__ */ Symbol.for("pi-subagents.session-succession");
|
|
95
|
-
var MAX_INHERITED_SESSIONS = 8;
|
|
96
|
-
var MAX_RECORDED_SESSIONS = 64;
|
|
97
|
-
function successions() {
|
|
98
|
-
const runtime = globalThis;
|
|
99
|
-
runtime[SUCCESSION_KEY] ??= /* @__PURE__ */ new Map();
|
|
100
|
-
return runtime[SUCCESSION_KEY];
|
|
101
|
-
}
|
|
102
|
-
function recordSessionReplacement(sessionId, previousSessionId) {
|
|
103
|
-
const chain = [.../* @__PURE__ */ new Set([previousSessionId, ...successions().get(previousSessionId) ?? []])].filter((id) => id !== sessionId);
|
|
104
|
-
successions().delete(sessionId);
|
|
105
|
-
successions().set(sessionId, chain.slice(0, MAX_INHERITED_SESSIONS));
|
|
106
|
-
while (successions().size > MAX_RECORDED_SESSIONS) successions().delete(successions().keys().next().value);
|
|
107
|
-
}
|
|
108
|
-
function inheritedSessionIds(sessionId) {
|
|
109
|
-
return successions().get(sessionId) ?? [];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/shared/extension-context.ts
|
|
113
|
-
var MODEL_ONLY_TOOL = { exposure: "model-only" };
|
|
114
|
-
function isStaleExtensionContextError(error) {
|
|
115
|
-
return error instanceof Error && /extension ctx is stale|extension context no longer active|stale after session replacement or reload/i.test(error.message);
|
|
116
|
-
}
|
|
117
|
-
function canRenderComponents(ctx) {
|
|
118
|
-
return ctx.mode === "tui" || process.env.PI_SUBAGENTS_COMPONENT_UI === "1";
|
|
119
|
-
}
|
|
120
|
-
function isUnboundExtensionRuntimeError(error) {
|
|
121
|
-
return error instanceof Error && /extension runtime not initialized/i.test(error.message);
|
|
122
|
-
}
|
|
123
|
-
function withCachedUiContext(ctx, onStale, run) {
|
|
124
|
-
if (!ctx) return void 0;
|
|
125
|
-
try {
|
|
126
|
-
if (!ctx.hasUI) return void 0;
|
|
127
|
-
return run(ctx);
|
|
128
|
-
} catch (error) {
|
|
129
|
-
if (!isStaleExtensionContextError(error)) throw error;
|
|
130
|
-
onStale();
|
|
131
|
-
return void 0;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
100
|
// src/shared/status-format.ts
|
|
136
101
|
function formatActivityAge(ms) {
|
|
137
102
|
if (ms < 1e3) return "now";
|
|
@@ -746,56 +711,56 @@ function isPlainObject(value) {
|
|
|
746
711
|
const prototype = Object.getPrototypeOf(value);
|
|
747
712
|
return prototype === Object.prototype || prototype === null;
|
|
748
713
|
}
|
|
749
|
-
function assertPlainObject(value,
|
|
750
|
-
if (!isPlainObject(value)) throw new Error(`${
|
|
751
|
-
if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`${
|
|
714
|
+
function assertPlainObject(value, path9) {
|
|
715
|
+
if (!isPlainObject(value)) throw new Error(`${path9} must be a plain JSON object.`);
|
|
716
|
+
if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`${path9} must not contain symbol keys.`);
|
|
752
717
|
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
753
|
-
if (!descriptor.enumerable || !("value" in descriptor)) throw new Error(`${
|
|
718
|
+
if (!descriptor.enumerable || !("value" in descriptor)) throw new Error(`${path9}.${key} must be an enumerable data property.`);
|
|
754
719
|
}
|
|
755
720
|
}
|
|
756
|
-
function assertKnownFields(value, allowed,
|
|
721
|
+
function assertKnownFields(value, allowed, path9) {
|
|
757
722
|
for (const key of Object.keys(value)) {
|
|
758
|
-
if (!allowed.has(key)) throw new Error(`${
|
|
723
|
+
if (!allowed.has(key)) throw new Error(`${path9} contains unsupported field '${key}'.`);
|
|
759
724
|
}
|
|
760
725
|
}
|
|
761
|
-
function normalizeDisplayString(value,
|
|
762
|
-
if (typeof value !== "string") throw new Error(`${
|
|
726
|
+
function normalizeDisplayString(value, path9) {
|
|
727
|
+
if (typeof value !== "string") throw new Error(`${path9} must be a string.`);
|
|
763
728
|
const normalized = value.replace(/[\u0000-\u001f\u007f]/g, " ").replace(/\s+/g, " ").trim();
|
|
764
|
-
if (!normalized) throw new Error(`${
|
|
729
|
+
if (!normalized) throw new Error(`${path9} must be a non-empty string.`);
|
|
765
730
|
if (normalized.length > WORKFLOW_PREFLIGHT_MAX_STRING_LENGTH) {
|
|
766
|
-
throw new Error(`${
|
|
731
|
+
throw new Error(`${path9} exceeds the maximum length of ${WORKFLOW_PREFLIGHT_MAX_STRING_LENGTH}.`);
|
|
767
732
|
}
|
|
768
733
|
return normalized;
|
|
769
734
|
}
|
|
770
735
|
function normalizeLane(value, index) {
|
|
771
|
-
const
|
|
772
|
-
assertPlainObject(value,
|
|
773
|
-
assertKnownFields(value, LANE_FIELDS,
|
|
774
|
-
const key = normalizeDisplayString(value.key, `${
|
|
775
|
-
if (!WORKFLOW_KEY_PATTERN.test(key)) throw new Error(`${
|
|
736
|
+
const path9 = `preflight.lanes[${index}]`;
|
|
737
|
+
assertPlainObject(value, path9);
|
|
738
|
+
assertKnownFields(value, LANE_FIELDS, path9);
|
|
739
|
+
const key = normalizeDisplayString(value.key, `${path9}.key`);
|
|
740
|
+
if (!WORKFLOW_KEY_PATTERN.test(key)) throw new Error(`${path9}.key must be 1-128 characters using letters, numbers, '.', '_' or '-', and start with a letter or number.`);
|
|
776
741
|
let mode;
|
|
777
742
|
if (value.mode !== void 0) {
|
|
778
743
|
if (typeof value.mode !== "string" || !PREFLIGHT_MODES.has(value.mode)) {
|
|
779
|
-
throw new Error(`${
|
|
744
|
+
throw new Error(`${path9}.mode must be one of: mutation, review, scout, gate.`);
|
|
780
745
|
}
|
|
781
746
|
mode = value.mode;
|
|
782
747
|
}
|
|
783
748
|
let claims;
|
|
784
749
|
if (value.claims !== void 0) {
|
|
785
|
-
if (!Array.isArray(value.claims)) throw new Error(`${
|
|
786
|
-
if (value.claims.length > WORKFLOW_PREFLIGHT_MAX_CLAIMS) throw new Error(`${
|
|
787
|
-
claims = value.claims.map((claim, claimIndex) => normalizeDisplayString(claim, `${
|
|
750
|
+
if (!Array.isArray(value.claims)) throw new Error(`${path9}.claims must be an array of strings.`);
|
|
751
|
+
if (value.claims.length > WORKFLOW_PREFLIGHT_MAX_CLAIMS) throw new Error(`${path9}.claims supports at most ${WORKFLOW_PREFLIGHT_MAX_CLAIMS} entries.`);
|
|
752
|
+
claims = value.claims.map((claim, claimIndex) => normalizeDisplayString(claim, `${path9}.claims[${claimIndex}]`));
|
|
788
753
|
for (let claimIndex = 0; claimIndex < value.claims.length; claimIndex += 1) {
|
|
789
|
-
if (!Object.prototype.hasOwnProperty.call(value.claims, claimIndex)) throw new Error(`${
|
|
754
|
+
if (!Object.prototype.hasOwnProperty.call(value.claims, claimIndex)) throw new Error(`${path9}.claims must not contain sparse arrays.`);
|
|
790
755
|
}
|
|
791
756
|
}
|
|
792
757
|
return {
|
|
793
758
|
key,
|
|
794
759
|
...mode ? { mode } : {},
|
|
795
|
-
...value.decision !== void 0 ? { decision: normalizeDisplayString(value.decision, `${
|
|
760
|
+
...value.decision !== void 0 ? { decision: normalizeDisplayString(value.decision, `${path9}.decision`) } : {},
|
|
796
761
|
...claims ? { claims } : {},
|
|
797
|
-
...value.expectedOutput !== void 0 ? { expectedOutput: normalizeDisplayString(value.expectedOutput, `${
|
|
798
|
-
...value.independence !== void 0 ? { independence: normalizeDisplayString(value.independence, `${
|
|
762
|
+
...value.expectedOutput !== void 0 ? { expectedOutput: normalizeDisplayString(value.expectedOutput, `${path9}.expectedOutput`) } : {},
|
|
763
|
+
...value.independence !== void 0 ? { independence: normalizeDisplayString(value.independence, `${path9}.independence`) } : {}
|
|
799
764
|
};
|
|
800
765
|
}
|
|
801
766
|
function normalizeWorkflowPreflight(input) {
|
|
@@ -1668,11 +1633,12 @@ function projectAsyncStatusSnapshot(jobs, options = {}) {
|
|
|
1668
1633
|
}
|
|
1669
1634
|
|
|
1670
1635
|
// src/runs/shared/mutation-evidence.ts
|
|
1671
|
-
import { execFileSync } from "node:child_process";
|
|
1636
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
1672
1637
|
import { createHash } from "node:crypto";
|
|
1673
1638
|
import * as fs2 from "node:fs";
|
|
1674
1639
|
import * as os from "node:os";
|
|
1675
1640
|
import * as path2 from "node:path";
|
|
1641
|
+
import { promisify } from "node:util";
|
|
1676
1642
|
var MAX_TRACKED_PATHS = 500;
|
|
1677
1643
|
var MAX_HASH_BYTES = 1024 * 1024;
|
|
1678
1644
|
var MAX_TIMEOUT_FILES = 20;
|
|
@@ -1682,6 +1648,27 @@ function gitArguments(args) {
|
|
|
1682
1648
|
function gitOutput(cwd, args, maxBuffer = MAX_HASH_BYTES) {
|
|
1683
1649
|
return execFileSync("git", gitArguments(args), { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer, windowsHide: true });
|
|
1684
1650
|
}
|
|
1651
|
+
var execFileAsync = promisify(execFile);
|
|
1652
|
+
async function gitOutputAsync(cwd, args) {
|
|
1653
|
+
return (await execFileAsync("git", gitArguments(args), { cwd, encoding: "utf-8", maxBuffer: MAX_HASH_BYTES, windowsHide: true })).stdout;
|
|
1654
|
+
}
|
|
1655
|
+
async function hashFileAsync(diffPath) {
|
|
1656
|
+
const hash = createHash("sha256");
|
|
1657
|
+
const fd = fs2.openSync(diffPath, "r");
|
|
1658
|
+
try {
|
|
1659
|
+
const buffer = Buffer.alloc(64 * 1024);
|
|
1660
|
+
let chunks = 0;
|
|
1661
|
+
for (; ; ) {
|
|
1662
|
+
const bytesRead = fs2.readSync(fd, buffer, 0, buffer.length, null);
|
|
1663
|
+
if (bytesRead === 0) break;
|
|
1664
|
+
hash.update(bytesRead === buffer.length ? buffer : buffer.subarray(0, bytesRead));
|
|
1665
|
+
if (++chunks % 32 === 0) await new Promise((resolve5) => setImmediate(resolve5));
|
|
1666
|
+
}
|
|
1667
|
+
} finally {
|
|
1668
|
+
fs2.closeSync(fd);
|
|
1669
|
+
}
|
|
1670
|
+
return hash.digest("hex");
|
|
1671
|
+
}
|
|
1685
1672
|
function splitNul(output) {
|
|
1686
1673
|
return output.split("\0").filter((part) => part.length > 0);
|
|
1687
1674
|
}
|
|
@@ -1707,8 +1694,9 @@ function hashLargeDiff(cwd, relativePath) {
|
|
|
1707
1694
|
fs2.rmSync(tempDir, { recursive: true, force: true });
|
|
1708
1695
|
}
|
|
1709
1696
|
}
|
|
1710
|
-
|
|
1711
|
-
|
|
1697
|
+
var CHANGED_FILES_ARGS = ["diff", "--no-ext-diff", "--name-only", "-z", "HEAD", "--"];
|
|
1698
|
+
function changedTrackedFiles(nameOnlyOutput) {
|
|
1699
|
+
const paths = splitNul(nameOnlyOutput);
|
|
1712
1700
|
return { paths: paths.slice(0, MAX_TRACKED_PATHS), truncated: paths.length > MAX_TRACKED_PATHS };
|
|
1713
1701
|
}
|
|
1714
1702
|
function fingerprintPath(cwd, relativePath) {
|
|
@@ -1725,7 +1713,7 @@ function sameFingerprint(left, right) {
|
|
|
1725
1713
|
}
|
|
1726
1714
|
function snapshotTrackedMutations(cwd) {
|
|
1727
1715
|
try {
|
|
1728
|
-
const changed =
|
|
1716
|
+
const changed = changedTrackedFiles(gitOutput(cwd, CHANGED_FILES_ARGS));
|
|
1729
1717
|
const fingerprints = {};
|
|
1730
1718
|
for (const file of changed.paths) fingerprints[file] = fingerprintPath(cwd, file);
|
|
1731
1719
|
return { source: "tracked-files", trackedOnly: true, cwd, dirtyFiles: changed.paths, fingerprints, truncated: changed.truncated };
|
|
@@ -1733,12 +1721,27 @@ function snapshotTrackedMutations(cwd) {
|
|
|
1733
1721
|
return { source: "tracked-files", trackedOnly: true, cwd, dirtyFiles: [], fingerprints: {}, unavailable: error instanceof Error ? error.message : String(error) };
|
|
1734
1722
|
}
|
|
1735
1723
|
}
|
|
1736
|
-
function
|
|
1724
|
+
async function fingerprintPathAsync(cwd, relativePath) {
|
|
1725
|
+
try {
|
|
1726
|
+
const diff = await gitOutputAsync(cwd, ["diff", "--no-ext-diff", "--binary", "HEAD", "--", relativePath]);
|
|
1727
|
+
return { kind: "diff", digest: createHash("sha256").update(diff).digest("hex") };
|
|
1728
|
+
} catch {
|
|
1729
|
+
const tempDir = fs2.mkdtempSync(path2.join(os.tmpdir(), "pi-mutation-evidence-"));
|
|
1730
|
+
try {
|
|
1731
|
+
const diffPath = path2.join(tempDir, "diff.bin");
|
|
1732
|
+
await gitOutputAsync(cwd, ["diff", "--no-ext-diff", "--binary", `--output=${diffPath}`, "HEAD", "--", relativePath]);
|
|
1733
|
+
return { kind: "diff", digest: await hashFileAsync(diffPath) };
|
|
1734
|
+
} finally {
|
|
1735
|
+
fs2.rmSync(tempDir, { recursive: true, force: true });
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
async function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
|
|
1737
1740
|
if (snapshot.unavailable) {
|
|
1738
1741
|
return { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: false, unavailable: snapshot.unavailable };
|
|
1739
1742
|
}
|
|
1740
1743
|
try {
|
|
1741
|
-
const current =
|
|
1744
|
+
const current = changedTrackedFiles(await gitOutputAsync(cwd, CHANGED_FILES_ARGS));
|
|
1742
1745
|
const startDirty = new Set(snapshot.dirtyFiles);
|
|
1743
1746
|
const candidates = /* @__PURE__ */ new Set([...snapshot.dirtyFiles, ...current.paths]);
|
|
1744
1747
|
const changedFiles = [];
|
|
@@ -1747,7 +1750,7 @@ function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
|
|
|
1747
1750
|
if (!snapshot.truncated) changedFiles.push(file);
|
|
1748
1751
|
continue;
|
|
1749
1752
|
}
|
|
1750
|
-
if (!sameFingerprint(snapshot.fingerprints[file],
|
|
1753
|
+
if (!sameFingerprint(snapshot.fingerprints[file], await fingerprintPathAsync(cwd, file))) changedFiles.push(file);
|
|
1751
1754
|
}
|
|
1752
1755
|
changedFiles.sort();
|
|
1753
1756
|
return {
|
|
@@ -2116,14 +2119,6 @@ function formatWorkflowChecklistText(projection, indent = "", options = {}) {
|
|
|
2116
2119
|
return lines;
|
|
2117
2120
|
}
|
|
2118
2121
|
|
|
2119
|
-
// src/runs/shared/run-ownership.ts
|
|
2120
|
-
function ownerSessionIds(sessionId) {
|
|
2121
|
-
return /* @__PURE__ */ new Set([sessionId, ...inheritedSessionIds(sessionId)]);
|
|
2122
|
-
}
|
|
2123
|
-
function ownsRun(currentSessionId, runSessionId) {
|
|
2124
|
-
return currentSessionId ? ownerSessionIds(currentSessionId).has(runSessionId) : false;
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
2122
|
// src/runs/background/async-status.ts
|
|
2128
2123
|
function getErrorMessage(error) {
|
|
2129
2124
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -3400,9 +3395,74 @@ function discardPreservedWorktreesUnlocked(manifestPath, authorization) {
|
|
|
3400
3395
|
return { manifest, text: lines.join("\n") };
|
|
3401
3396
|
}
|
|
3402
3397
|
|
|
3403
|
-
// src/
|
|
3398
|
+
// src/workflows/workflow-launch-record.ts
|
|
3404
3399
|
import * as fs6 from "node:fs";
|
|
3400
|
+
import * as path7 from "node:path";
|
|
3401
|
+
|
|
3402
|
+
// src/runs/shared/run-launch-folder.ts
|
|
3405
3403
|
import * as path6 from "node:path";
|
|
3404
|
+
function runLaunchDir(runsRoot, runId) {
|
|
3405
|
+
if (!runId || runId !== path6.basename(runId) || runId === "." || runId === "..") throw new Error(`Invalid run id for a launch folder: '${runId}'.`);
|
|
3406
|
+
if (path6.basename(path6.dirname(runsRoot)) === "nested-subagent-runs") return path6.join(runsRoot, ".launches", runId);
|
|
3407
|
+
return path6.join(path6.dirname(runsRoot), "async-subagent-launches", runId);
|
|
3408
|
+
}
|
|
3409
|
+
function recoveryDescriptorPath(runsRoot, runId) {
|
|
3410
|
+
return path6.join(runLaunchDir(runsRoot, runId), "recovery-descriptor.json");
|
|
3411
|
+
}
|
|
3412
|
+
|
|
3413
|
+
// src/workflows/workflow-launch-record.ts
|
|
3414
|
+
var WORKFLOW_LAUNCH_RECORD_FILE = "launch.json";
|
|
3415
|
+
function launchRecordPath(asyncDirRoot, runId) {
|
|
3416
|
+
return path7.join(runLaunchDir(asyncDirRoot, runId), WORKFLOW_LAUNCH_RECORD_FILE);
|
|
3417
|
+
}
|
|
3418
|
+
function writeWorkflowLaunchRecord(asyncDirRoot, runId, record) {
|
|
3419
|
+
writeAtomicJson(launchRecordPath(asyncDirRoot, runId), record);
|
|
3420
|
+
}
|
|
3421
|
+
function isPlainObject2(value) {
|
|
3422
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3423
|
+
}
|
|
3424
|
+
function invalid(error) {
|
|
3425
|
+
return { ok: false, missing: false, error };
|
|
3426
|
+
}
|
|
3427
|
+
function readWorkflowLaunchRecord(asyncDirRoot, runId) {
|
|
3428
|
+
let text2;
|
|
3429
|
+
try {
|
|
3430
|
+
text2 = fs6.readFileSync(launchRecordPath(asyncDirRoot, runId), "utf-8");
|
|
3431
|
+
} catch (error) {
|
|
3432
|
+
if (error.code === "ENOENT") return { ok: false, missing: true, error: "launch.json is missing" };
|
|
3433
|
+
return invalid(`could not be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
3434
|
+
}
|
|
3435
|
+
let value;
|
|
3436
|
+
try {
|
|
3437
|
+
value = JSON.parse(text2);
|
|
3438
|
+
} catch (error) {
|
|
3439
|
+
return invalid(`not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
3440
|
+
}
|
|
3441
|
+
if (!isPlainObject2(value)) return invalid("not a JSON object");
|
|
3442
|
+
if (value.version !== 2) return invalid("version must be 2");
|
|
3443
|
+
if (typeof value.scriptDigest !== "string" || !value.scriptDigest) return invalid("scriptDigest must be a non-empty string");
|
|
3444
|
+
if (typeof value.sessionId !== "string" || !value.sessionId) return invalid("sessionId must be a non-empty string");
|
|
3445
|
+
let admissionCapabilityCeiling;
|
|
3446
|
+
try {
|
|
3447
|
+
if (value.admissionCapabilityCeiling !== void 0) admissionCapabilityCeiling = parseSubagentCapabilityCeiling(value.admissionCapabilityCeiling, "admissionCapabilityCeiling");
|
|
3448
|
+
} catch (error) {
|
|
3449
|
+
return invalid(error instanceof Error ? error.message : String(error));
|
|
3450
|
+
}
|
|
3451
|
+
const owner = {
|
|
3452
|
+
version: 2,
|
|
3453
|
+
scriptDigest: value.scriptDigest,
|
|
3454
|
+
sessionId: value.sessionId,
|
|
3455
|
+
...admissionCapabilityCeiling ? { admissionCapabilityCeiling } : {}
|
|
3456
|
+
};
|
|
3457
|
+
if (value.source === "structured" || value.source === "internal") return { ok: true, record: { ...owner, source: value.source } };
|
|
3458
|
+
if (value.source !== "script" && value.source !== "resource") return invalid('source must be "script", "resource", "structured", or "internal"');
|
|
3459
|
+
if (!isPlainObject2(value.params)) return invalid("params must be an object");
|
|
3460
|
+
return { ok: true, record: { ...owner, source: value.source, params: value.params } };
|
|
3461
|
+
}
|
|
3462
|
+
|
|
3463
|
+
// src/runs/background/async-resume.ts
|
|
3464
|
+
import * as fs7 from "node:fs";
|
|
3465
|
+
import * as path8 from "node:path";
|
|
3406
3466
|
function getErrorMessage2(error) {
|
|
3407
3467
|
return error instanceof Error ? error.message : String(error);
|
|
3408
3468
|
}
|
|
@@ -3462,7 +3522,7 @@ function validateResultFile(value, resultPath) {
|
|
|
3462
3522
|
function readResultFile(resultPath) {
|
|
3463
3523
|
let raw;
|
|
3464
3524
|
try {
|
|
3465
|
-
raw =
|
|
3525
|
+
raw = fs7.readFileSync(resultPath, "utf-8");
|
|
3466
3526
|
} catch (error) {
|
|
3467
3527
|
throw new Error(`Failed to read async result file '${resultPath}': ${getErrorMessage2(error)}`, {
|
|
3468
3528
|
cause: error instanceof Error ? error : void 0
|
|
@@ -3482,43 +3542,43 @@ function readResultFile(resultPath) {
|
|
|
3482
3542
|
function assertRunId(value, field) {
|
|
3483
3543
|
if (value === void 0) return void 0;
|
|
3484
3544
|
if (value.trim() === "") throw new Error(`${field} must not be empty.`);
|
|
3485
|
-
if (
|
|
3545
|
+
if (path8.isAbsolute(value) || /[\\/]/.test(value) || value.includes("..")) {
|
|
3486
3546
|
throw new Error(`${field} must be an async run id or prefix, not a path.`);
|
|
3487
3547
|
}
|
|
3488
3548
|
return value;
|
|
3489
3549
|
}
|
|
3490
3550
|
function assertInsideRoot(root, target, label) {
|
|
3491
|
-
const rootPath =
|
|
3492
|
-
const targetPath =
|
|
3493
|
-
const relative3 =
|
|
3494
|
-
if (relative3 === "" || !relative3.startsWith("..") && !
|
|
3551
|
+
const rootPath = path8.resolve(root);
|
|
3552
|
+
const targetPath = path8.resolve(target);
|
|
3553
|
+
const relative3 = path8.relative(rootPath, targetPath);
|
|
3554
|
+
if (relative3 === "" || !relative3.startsWith("..") && !path8.isAbsolute(relative3)) return;
|
|
3495
3555
|
throw new Error(`${label} must be inside ${rootPath}.`);
|
|
3496
3556
|
}
|
|
3497
3557
|
function prefixedRunIds(dir, prefix, suffix = "") {
|
|
3498
|
-
if (!
|
|
3499
|
-
return
|
|
3558
|
+
if (!fs7.existsSync(dir)) return [];
|
|
3559
|
+
return fs7.readdirSync(dir).filter((entry) => entry.startsWith(prefix) && (!suffix || entry.endsWith(suffix))).map((entry) => suffix ? entry.slice(0, -suffix.length) : entry).sort();
|
|
3500
3560
|
}
|
|
3501
3561
|
function exactResultPath(resultsDir, runId) {
|
|
3502
3562
|
const indexed = resultPayloadPathForIndexedRun(resultsDir, runId);
|
|
3503
3563
|
if (indexed) return indexed;
|
|
3504
3564
|
const resultPath = resultFilePath(resultsDir, runId);
|
|
3505
3565
|
assertInsideRoot(resultsDir, resultPath, "Async result file");
|
|
3506
|
-
return
|
|
3566
|
+
return fs7.existsSync(resultPath) ? resultPath : null;
|
|
3507
3567
|
}
|
|
3508
3568
|
function findAsyncRunPrefixMatches(prefix, asyncDirRoot, resultsDir) {
|
|
3509
3569
|
const requestedId = assertRunId(prefix, "id");
|
|
3510
3570
|
if (!requestedId) return [];
|
|
3511
3571
|
if (!canScanAsyncRunPrefix(requestedId)) return [];
|
|
3512
|
-
const asyncRoot =
|
|
3513
|
-
const resultRoot =
|
|
3572
|
+
const asyncRoot = path8.resolve(asyncDirRoot);
|
|
3573
|
+
const resultRoot = path8.resolve(resultsDir);
|
|
3514
3574
|
const matchingIds = prefixedRunIds(asyncRoot, requestedId).sort();
|
|
3515
3575
|
return matchingIds.map((id) => {
|
|
3516
|
-
const asyncDir =
|
|
3576
|
+
const asyncDir = path8.join(asyncRoot, id);
|
|
3517
3577
|
assertInsideRoot(asyncRoot, asyncDir, "Async run directory");
|
|
3518
3578
|
return {
|
|
3519
3579
|
id,
|
|
3520
3580
|
location: {
|
|
3521
|
-
asyncDir:
|
|
3581
|
+
asyncDir: fs7.existsSync(asyncDir) ? asyncDir : null,
|
|
3522
3582
|
resultPath: exactResultPath(resultRoot, id),
|
|
3523
3583
|
resolvedId: id
|
|
3524
3584
|
}
|
|
@@ -3526,25 +3586,25 @@ function findAsyncRunPrefixMatches(prefix, asyncDirRoot, resultsDir) {
|
|
|
3526
3586
|
});
|
|
3527
3587
|
}
|
|
3528
3588
|
function resolveAsyncRunLocation(params, asyncDirRoot, resultsDir) {
|
|
3529
|
-
const asyncRoot =
|
|
3530
|
-
const resultRoot =
|
|
3589
|
+
const asyncRoot = path8.resolve(asyncDirRoot);
|
|
3590
|
+
const resultRoot = path8.resolve(resultsDir);
|
|
3531
3591
|
const requestedId = assertRunId(params.id, "id") ?? assertRunId(params.runId, "runId");
|
|
3532
3592
|
if (params.dir) {
|
|
3533
|
-
const asyncDir =
|
|
3593
|
+
const asyncDir = path8.resolve(params.dir);
|
|
3534
3594
|
assertInsideRoot(asyncRoot, asyncDir, "Async run directory");
|
|
3535
|
-
const resolvedId = requestedId ??
|
|
3536
|
-
if (requestedId && requestedId !==
|
|
3537
|
-
throw new Error(`Async run id '${requestedId}' does not match directory '${
|
|
3595
|
+
const resolvedId = requestedId ?? path8.basename(asyncDir);
|
|
3596
|
+
if (requestedId && requestedId !== path8.basename(asyncDir)) {
|
|
3597
|
+
throw new Error(`Async run id '${requestedId}' does not match directory '${path8.basename(asyncDir)}'.`);
|
|
3538
3598
|
}
|
|
3539
3599
|
return { asyncDir, resultPath: exactResultPath(resultRoot, resolvedId), resolvedId };
|
|
3540
3600
|
}
|
|
3541
3601
|
if (!requestedId) return { asyncDir: null, resultPath: null };
|
|
3542
|
-
const directAsyncDir =
|
|
3602
|
+
const directAsyncDir = path8.join(asyncRoot, requestedId);
|
|
3543
3603
|
assertInsideRoot(asyncRoot, directAsyncDir, "Async run directory");
|
|
3544
3604
|
const directResultPath = exactResultPath(resultRoot, requestedId);
|
|
3545
|
-
if (
|
|
3605
|
+
if (fs7.existsSync(directAsyncDir) || directResultPath) {
|
|
3546
3606
|
return {
|
|
3547
|
-
asyncDir:
|
|
3607
|
+
asyncDir: fs7.existsSync(directAsyncDir) ? directAsyncDir : null,
|
|
3548
3608
|
resultPath: directResultPath,
|
|
3549
3609
|
resolvedId: requestedId
|
|
3550
3610
|
};
|
|
@@ -3606,13 +3666,12 @@ function resumeTargetMode(status, result) {
|
|
|
3606
3666
|
if (result?.mode === "single" || result?.mode === "parallel" || result?.mode === "chain" || result?.mode === "workflow") return result.mode;
|
|
3607
3667
|
return void 0;
|
|
3608
3668
|
}
|
|
3609
|
-
function readAsyncRecoveryDescriptor(
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
if (!fs6.existsSync(descriptorPath)) return void 0;
|
|
3669
|
+
function readAsyncRecoveryDescriptor(runsRoot, runId) {
|
|
3670
|
+
const descriptorPath = recoveryDescriptorPath(runsRoot, runId);
|
|
3671
|
+
if (!fs7.existsSync(descriptorPath)) return void 0;
|
|
3613
3672
|
let value;
|
|
3614
3673
|
try {
|
|
3615
|
-
value = JSON.parse(
|
|
3674
|
+
value = JSON.parse(fs7.readFileSync(descriptorPath, "utf-8"));
|
|
3616
3675
|
} catch (error) {
|
|
3617
3676
|
throw new Error(`Failed to parse async recovery descriptor '${descriptorPath}': ${getErrorMessage2(error)}`, { cause: error instanceof Error ? error : void 0 });
|
|
3618
3677
|
}
|
|
@@ -3673,6 +3732,9 @@ function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
3673
3732
|
"lane",
|
|
3674
3733
|
"baseRef",
|
|
3675
3734
|
"launcher",
|
|
3735
|
+
"requiredLauncher",
|
|
3736
|
+
"sessionId",
|
|
3737
|
+
"managedWorktree",
|
|
3676
3738
|
"extensionBindings",
|
|
3677
3739
|
"requiredExtensions"
|
|
3678
3740
|
]);
|
|
@@ -3684,7 +3746,13 @@ function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
3684
3746
|
if (typeof parsed[field] !== "string" || !parsed[field].trim()) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${field} must be a non-empty string.`);
|
|
3685
3747
|
}
|
|
3686
3748
|
if (parsed.version !== 1) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': version must be 1.`);
|
|
3687
|
-
if (parsed.launcher !== void 0 && (typeof parsed.launcher !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(parsed.launcher))) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': launcher must be a launcher name.`);
|
|
3749
|
+
if (parsed.launcher !== void 0 && parsed.launcher !== null && (typeof parsed.launcher !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(parsed.launcher))) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': launcher must be a launcher name or null.`);
|
|
3750
|
+
if (parsed.requiredLauncher !== void 0) {
|
|
3751
|
+
const required = parsed.requiredLauncher;
|
|
3752
|
+
if (!required || typeof required !== "object" || Array.isArray(required) || Object.keys(required).some((key) => key !== "name" && key !== "definitionDigest") || typeof required.name !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(required.name) || typeof required.definitionDigest !== "string" || !/^[0-9a-f]{64}$/.test(required.definitionDigest)) {
|
|
3753
|
+
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': requiredLauncher must be { name, definitionDigest }.`);
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3688
3756
|
try {
|
|
3689
3757
|
parsed.runFanoutBudget = validateRunFanoutBudgetDescriptor(parsed.runFanoutBudget);
|
|
3690
3758
|
} catch (error) {
|
|
@@ -3733,7 +3801,12 @@ function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
3733
3801
|
if (item !== void 0 && (!Array.isArray(item) || item.some((entry) => typeof entry !== "string" || !entry.trim()))) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${field} must contain non-empty strings.`);
|
|
3734
3802
|
}
|
|
3735
3803
|
if (parsed.systemPrompt !== void 0 && typeof parsed.systemPrompt !== "string") throw new Error(`Invalid async recovery descriptor '${descriptorPath}': systemPrompt must be a string.`);
|
|
3736
|
-
|
|
3804
|
+
if (parsed.managedWorktree !== void 0) {
|
|
3805
|
+
const worktree = parsed.managedWorktree;
|
|
3806
|
+
const valid = !!worktree && typeof worktree === "object" && !Array.isArray(worktree) && (worktree.provider === "native" && typeof worktree.cwd === "string" && path8.isAbsolute(worktree.cwd) && Object.keys(worktree).length === 2 || worktree.provider === "worktrunk" && typeof worktree.branch === "string" && !!worktree.branch.trim() && Object.keys(worktree).length === 2);
|
|
3807
|
+
if (!valid) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': managedWorktree is invalid.`);
|
|
3808
|
+
}
|
|
3809
|
+
for (const field of ["sessionId", "launchContractDigest", "sessionFile", "model", "modelProvider", "thinking", "agentFilePath", "outputPath", "sessionDir", "artifactsDir"]) {
|
|
3737
3810
|
if (parsed[field] !== void 0 && (typeof parsed[field] !== "string" || !parsed[field].trim())) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${field} must be a non-empty string.`);
|
|
3738
3811
|
}
|
|
3739
3812
|
if (parsed.baseRef !== void 0) {
|
|
@@ -3794,17 +3867,30 @@ function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
3794
3867
|
if (parsed.acceptance !== void 0) parsed.acceptance = normalizeRecoveryAcceptance(parsed.acceptance, descriptorPath);
|
|
3795
3868
|
return parsed;
|
|
3796
3869
|
}
|
|
3870
|
+
function assertLaunchedWorktreeCwd(runId, launchCwd, launched, handoffCwd) {
|
|
3871
|
+
const listed = launched.provider === "native" ? void 0 : findListedWorktreeOnBranch(launchCwd, launched.branch);
|
|
3872
|
+
const matches = launched.provider === "native" ? isComparablePathInside(launched.cwd, handoffCwd) && isComparablePathInside(handoffCwd, launched.cwd) : listed !== void 0 && isComparablePathInside(listed, handoffCwd);
|
|
3873
|
+
if (!matches) throw new Error(`Async run '${runId}' managed worktree ${handoffCwd} is not the worktree its launch created.`);
|
|
3874
|
+
return handoffCwd;
|
|
3875
|
+
}
|
|
3876
|
+
function launchedWorktreeCwdWithoutHandoff(runId, launchCwd, launched) {
|
|
3877
|
+
const cwd = launched.provider === "native" ? launched.cwd : findListedWorktreeAgentCwd(launchCwd, launched.branch);
|
|
3878
|
+
if (cwd === void 0 || !fs7.statSync(cwd, { throwIfNoEntry: false })?.isDirectory()) {
|
|
3879
|
+
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.`);
|
|
3880
|
+
}
|
|
3881
|
+
return cwd;
|
|
3882
|
+
}
|
|
3797
3883
|
function validateResumeSessionFile(runId, sessionFile) {
|
|
3798
|
-
if (
|
|
3799
|
-
const resolved =
|
|
3800
|
-
if (!
|
|
3884
|
+
if (path8.extname(sessionFile) !== ".jsonl") throw new Error(`Async run '${runId}' session file must be a .jsonl file: ${sessionFile}`);
|
|
3885
|
+
const resolved = path8.resolve(sessionFile);
|
|
3886
|
+
if (!fs7.existsSync(resolved)) throw new Error(`Async run '${runId}' session file does not exist: ${sessionFile}`);
|
|
3801
3887
|
return resolved;
|
|
3802
3888
|
}
|
|
3803
3889
|
function validateResumeCwd(runId, cwd) {
|
|
3804
3890
|
if (!cwd) return void 0;
|
|
3805
|
-
const resolved =
|
|
3891
|
+
const resolved = path8.resolve(cwd);
|
|
3806
3892
|
try {
|
|
3807
|
-
if (!
|
|
3893
|
+
if (!fs7.statSync(resolved).isDirectory()) throw new Error("path is not a directory");
|
|
3808
3894
|
} catch (error) {
|
|
3809
3895
|
throw new Error(`Async run '${runId}' required cwd does not exist: ${cwd}`, { cause: error instanceof Error ? error : void 0 });
|
|
3810
3896
|
}
|
|
@@ -3819,17 +3905,27 @@ function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
3819
3905
|
const requested = params.id ?? params.runId;
|
|
3820
3906
|
throw new Error(requested ? `Async run not found for '${requested}'.` : "Async run not found. Provide id or dir.");
|
|
3821
3907
|
}
|
|
3908
|
+
if (location.asyncDir) {
|
|
3909
|
+
let recordedRunId;
|
|
3910
|
+
try {
|
|
3911
|
+
recordedRunId = JSON.parse(fs7.readFileSync(path8.join(location.asyncDir, "status.json"), "utf-8")).runId;
|
|
3912
|
+
} catch {
|
|
3913
|
+
}
|
|
3914
|
+
if (typeof recordedRunId === "string" && recordedRunId !== path8.basename(location.asyncDir)) throw new Error(`Async run '${path8.basename(location.asyncDir)}' has a status file for a different run '${recordedRunId}'.`);
|
|
3915
|
+
}
|
|
3822
3916
|
const reconciliation = location.asyncDir ? reconcileAsyncRun(location.asyncDir, { resultsDir, kill: deps.kill, now: deps.now }) : void 0;
|
|
3823
3917
|
const status = reconciliation?.status ?? null;
|
|
3824
|
-
validateStatusForResume(status, location.asyncDir ?
|
|
3825
|
-
const
|
|
3918
|
+
validateStatusForResume(status, location.asyncDir ? path8.join(location.asyncDir, "status.json") : "status.json");
|
|
3919
|
+
const directRunFolder = location.asyncDir !== null && path8.dirname(location.asyncDir) === path8.resolve(asyncDirRoot);
|
|
3920
|
+
const recoveryDescriptor = directRunFolder ? readAsyncRecoveryDescriptor(asyncDirRoot, path8.basename(location.asyncDir)) : void 0;
|
|
3826
3921
|
const result = location.resultPath ? readResultFile(location.resultPath) : void 0;
|
|
3827
|
-
const runId =
|
|
3828
|
-
const mode = resumeTargetMode(status, result);
|
|
3829
|
-
|
|
3922
|
+
const runId = location.asyncDir ? path8.basename(location.asyncDir) : result?.runId ?? result?.id ?? location.resolvedId ?? "unknown";
|
|
3923
|
+
const mode = recoveryDescriptor ? "single" : resumeTargetMode(status, result);
|
|
3924
|
+
const notOwned = recoveryDescriptor ? !ownsRun(options.sessionId, recoveryDescriptor.sessionId) : status && !ownsRun(options.sessionId, status.sessionId) || result && !ownsRun(options.sessionId, result.sessionId);
|
|
3925
|
+
if (options.sessionId && notOwned) {
|
|
3830
3926
|
throw new Error(`Async run '${runId}' was not found in the active session.`);
|
|
3831
3927
|
}
|
|
3832
|
-
if (recoveryDescriptor && recoveryDescriptor.sourceRunId !== runId) throw new Error(`Async run '${runId}' has a recovery descriptor for a different source run.`);
|
|
3928
|
+
if (recoveryDescriptor && recoveryDescriptor.sourceRunId !== runId) throw new Error(`Async run '${runId}' has a recovery descriptor for a different source run '${recoveryDescriptor.sourceRunId}'.`);
|
|
3833
3929
|
const state = status?.state ?? (result ? resultState(result) : void 0);
|
|
3834
3930
|
if (!state) throw new Error(`Status file not found for async run '${runId}'.`);
|
|
3835
3931
|
if (state === "stopped") throw new Error(`Async run '${runId}' was stopped and cannot be resumed. Start a new run instead.`);
|
|
@@ -3844,18 +3940,18 @@ function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
3844
3940
|
if (requestedIndex < 0 || requestedIndex >= stepCount) throw new Error(`Async run '${runId}' has ${stepCount} children. Index ${requestedIndex} is out of range.`);
|
|
3845
3941
|
const selectedStep = statusSteps[requestedIndex];
|
|
3846
3942
|
if (selectedStep?.status === "running") {
|
|
3847
|
-
const capabilityCeiling2 = intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selectedStep.capabilityCeiling);
|
|
3943
|
+
const capabilityCeiling2 = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selectedStep.capabilityCeiling);
|
|
3848
3944
|
return {
|
|
3849
3945
|
kind: "live",
|
|
3850
3946
|
runId,
|
|
3851
3947
|
asyncDir: location.asyncDir ?? void 0,
|
|
3852
3948
|
state,
|
|
3853
3949
|
...mode ? { mode } : {},
|
|
3854
|
-
agent: selectedStep.agent,
|
|
3950
|
+
agent: recoveryDescriptor?.agent ?? selectedStep.agent,
|
|
3855
3951
|
...selectedStep.sessionName ?? result?.results?.[requestedIndex]?.sessionName ? { sessionName: selectedStep.sessionName ?? result?.results?.[requestedIndex]?.sessionName } : {},
|
|
3856
3952
|
index: requestedIndex,
|
|
3857
3953
|
cwd: status?.cwd ?? result?.cwd,
|
|
3858
|
-
sessionFile: selectedStep.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
3954
|
+
sessionFile: recoveryDescriptor ? recoveryDescriptor.sessionFile : selectedStep.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
3859
3955
|
model: selectedStep.model,
|
|
3860
3956
|
thinking: selectedStep.thinking,
|
|
3861
3957
|
launchContractDigest: selectedStep.launchContractDigest ?? result?.results?.[requestedIndex]?.launchContractDigest ?? result?.launchContractDigest ?? recoveryDescriptor?.launchContractDigest,
|
|
@@ -3874,18 +3970,18 @@ function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
3874
3970
|
if (!selected) {
|
|
3875
3971
|
throw new Error(`Async run '${runId}' has ${running.length} running children. Provide index to choose one.`);
|
|
3876
3972
|
}
|
|
3877
|
-
const capabilityCeiling2 = intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selected.step.capabilityCeiling);
|
|
3973
|
+
const capabilityCeiling2 = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selected.step.capabilityCeiling);
|
|
3878
3974
|
return {
|
|
3879
3975
|
kind: "live",
|
|
3880
3976
|
runId,
|
|
3881
3977
|
asyncDir: location.asyncDir ?? void 0,
|
|
3882
3978
|
state,
|
|
3883
3979
|
...mode ? { mode } : {},
|
|
3884
|
-
agent: selected.step.agent,
|
|
3980
|
+
agent: recoveryDescriptor?.agent ?? selected.step.agent,
|
|
3885
3981
|
...selected.step.sessionName ?? result?.results?.[selected.index]?.sessionName ? { sessionName: selected.step.sessionName ?? result?.results?.[selected.index]?.sessionName } : {},
|
|
3886
3982
|
index: selected.index,
|
|
3887
3983
|
cwd: status?.cwd ?? result?.cwd,
|
|
3888
|
-
sessionFile: selected.step.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
3984
|
+
sessionFile: recoveryDescriptor ? recoveryDescriptor.sessionFile : selected.step.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
3889
3985
|
model: selected.step.model,
|
|
3890
3986
|
thinking: selected.step.thinking,
|
|
3891
3987
|
launchContractDigest: selected.step.launchContractDigest ?? result?.results?.[selected.index]?.launchContractDigest ?? result?.launchContractDigest ?? recoveryDescriptor?.launchContractDigest,
|
|
@@ -3907,18 +4003,19 @@ function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
3907
4003
|
if (selectedStatusStep?.status === "stopped" || selectedStatusStep?.stopped === true) {
|
|
3908
4004
|
throw new Error(`Async run '${runId}' child ${index} was stopped and cannot be resumed. Start a new run instead.`);
|
|
3909
4005
|
}
|
|
3910
|
-
const agent = selectedStatusStep?.agent ?? resultSteps[index]?.agent ?? result?.agent;
|
|
4006
|
+
const agent = recoveryDescriptor ? recoveryDescriptor.agent : selectedStatusStep?.agent ?? resultSteps[index]?.agent ?? result?.agent;
|
|
3911
4007
|
if (!agent) throw new Error(`Could not determine child agent for async run '${runId}'.`);
|
|
3912
|
-
|
|
3913
|
-
const sessionFile = statusSteps[index]?.sessionFile ?? resultSteps[index]?.sessionFile ?? (stepCount === 1 ? status?.sessionFile ?? result?.sessionFile : void 0);
|
|
4008
|
+
const sessionFile = recoveryDescriptor ? recoveryDescriptor.sessionFile : statusSteps[index]?.sessionFile ?? resultSteps[index]?.sessionFile ?? (stepCount === 1 ? status?.sessionFile ?? result?.sessionFile : void 0);
|
|
3914
4009
|
if (!sessionFile && requireSessionFile) throw new Error(`Async run '${runId}' child ${index} does not have a persisted session file to resume from.`);
|
|
3915
4010
|
const resolvedSessionFile = sessionFile ? validateResumeSessionFile(runId, sessionFile) : void 0;
|
|
3916
|
-
const stepModel = statusSteps[index]?.launchModel ?? statusSteps[index]?.model ?? resultSteps[index]?.model ?? (stepCount === 1 ? result?.model : void 0);
|
|
3917
|
-
const stepThinking = statusSteps[index]?.thinking ?? resultSteps[index]?.thinking ?? (stepCount === 1 ? result?.thinking : void 0);
|
|
3918
|
-
const thinkingCeiling =
|
|
3919
|
-
const
|
|
3920
|
-
const
|
|
3921
|
-
const
|
|
4011
|
+
const stepModel = recoveryDescriptor ? recoveryDescriptor.model : statusSteps[index]?.launchModel ?? statusSteps[index]?.model ?? resultSteps[index]?.model ?? (stepCount === 1 ? result?.model : void 0);
|
|
4012
|
+
const stepThinking = recoveryDescriptor ? recoveryDescriptor.thinking : statusSteps[index]?.thinking ?? resultSteps[index]?.thinking ?? (stepCount === 1 ? result?.thinking : void 0);
|
|
4013
|
+
const thinkingCeiling = recoveryDescriptor ? recoveryDescriptor.thinkingCeiling : statusSteps[index]?.thinkingCeiling;
|
|
4014
|
+
const workflowLaunch = mode === "workflow" && directRunFolder ? readWorkflowLaunchRecord(asyncDirRoot, runId) : void 0;
|
|
4015
|
+
const capabilityCeiling = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : mode === "workflow" ? workflowLaunch?.ok ? workflowLaunch.record.admissionCapabilityCeiling : void 0 : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, statusSteps[index]?.capabilityCeiling, result?.capabilityCeiling, resultSteps[index]?.capabilityCeiling);
|
|
4016
|
+
const handoffWorktreeCwd = location.asyncDir && (!recoveryDescriptor || recoveryDescriptor.managedWorktree) ? resolveRetainedWorktreeCwd(parallelHandoffPath(location.asyncDir), runId, index, statusSteps[index]?.worktreePath) : void 0;
|
|
4017
|
+
const managedWorktreeCwd = recoveryDescriptor?.managedWorktree ? handoffWorktreeCwd ? assertLaunchedWorktreeCwd(runId, recoveryDescriptor.cwd, recoveryDescriptor.managedWorktree, handoffWorktreeCwd) : launchedWorktreeCwdWithoutHandoff(runId, recoveryDescriptor.cwd, recoveryDescriptor.managedWorktree) : handoffWorktreeCwd;
|
|
4018
|
+
const resumeCwd = validateResumeCwd(runId, managedWorktreeCwd ?? (recoveryDescriptor ? recoveryDescriptor.cwd : status?.cwd ?? result?.cwd));
|
|
3922
4019
|
return {
|
|
3923
4020
|
kind: "revive",
|
|
3924
4021
|
runId,
|
|
@@ -3933,9 +4030,10 @@ function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
3933
4030
|
...resolvedSessionFile ? { sessionFile: resolvedSessionFile } : {},
|
|
3934
4031
|
...stepModel ? { model: stepModel } : {},
|
|
3935
4032
|
...stepThinking ? { thinking: stepThinking } : {},
|
|
3936
|
-
launchContractDigest: statusSteps[index]?.launchContractDigest ?? resultSteps[index]?.launchContractDigest ?? result?.launchContractDigest
|
|
3937
|
-
|
|
3938
|
-
|
|
4033
|
+
launchContractDigest: recoveryDescriptor ? recoveryDescriptor.launchContractDigest : statusSteps[index]?.launchContractDigest ?? resultSteps[index]?.launchContractDigest ?? result?.launchContractDigest,
|
|
4034
|
+
// External runners write no recovery descriptor.
|
|
4035
|
+
...!recoveryDescriptor && statusSteps[index]?.runner ? { runner: statusSteps[index].runner } : {},
|
|
4036
|
+
...!recoveryDescriptor && statusSteps[index]?.externalJob ? { externalJob: statusSteps[index].externalJob } : {},
|
|
3939
4037
|
...capabilityCeiling ? { capabilityCeiling } : {},
|
|
3940
4038
|
...thinkingCeiling ? { thinkingCeiling } : {},
|
|
3941
4039
|
...recoveryDescriptor ? { recoveryDescriptor } : {}
|
|
@@ -3968,8 +4066,9 @@ function applySteeringRecoveryAgentConfig(agentConfig, descriptor) {
|
|
|
3968
4066
|
output: descriptor.outputPath,
|
|
3969
4067
|
toolBudget: descriptor.initialToolBudget,
|
|
3970
4068
|
maxSubagentDepth: descriptor.maxSubagentDepth,
|
|
3971
|
-
//
|
|
3972
|
-
launcher
|
|
4069
|
+
// A recorded launcher, or a recorded null (ran unwrapped), wins over the current agent file.
|
|
4070
|
+
// A missing field says nothing, so the run never loses the agent file's launcher.
|
|
4071
|
+
launcher: descriptor.launcher === void 0 ? agentConfig.launcher : descriptor.launcher ?? void 0
|
|
3973
4072
|
};
|
|
3974
4073
|
}
|
|
3975
4074
|
function buildRevivedAsyncTask(target, message) {
|
|
@@ -4008,15 +4107,6 @@ function opencodeSessionHeaders(model, sessionId) {
|
|
|
4008
4107
|
}
|
|
4009
4108
|
|
|
4010
4109
|
export {
|
|
4011
|
-
recordSessionReplacement,
|
|
4012
|
-
inheritedSessionIds,
|
|
4013
|
-
ownerSessionIds,
|
|
4014
|
-
ownsRun,
|
|
4015
|
-
MODEL_ONLY_TOOL,
|
|
4016
|
-
isStaleExtensionContextError,
|
|
4017
|
-
canRenderComponents,
|
|
4018
|
-
isUnboundExtensionRuntimeError,
|
|
4019
|
-
withCachedUiContext,
|
|
4020
4110
|
agentStreamOptions,
|
|
4021
4111
|
opencodeSessionHeaders,
|
|
4022
4112
|
formatActivityLabel,
|
|
@@ -4090,6 +4180,10 @@ export {
|
|
|
4090
4180
|
formatParallelHandoffReference,
|
|
4091
4181
|
formatParallelHandoffError,
|
|
4092
4182
|
discardPreservedWorktrees,
|
|
4183
|
+
runLaunchDir,
|
|
4184
|
+
recoveryDescriptorPath,
|
|
4185
|
+
writeWorkflowLaunchRecord,
|
|
4186
|
+
readWorkflowLaunchRecord,
|
|
4093
4187
|
findAsyncRunPrefixMatches,
|
|
4094
4188
|
resolveAsyncRunLocation,
|
|
4095
4189
|
asyncReviveRequiresRecoveryDescriptor,
|