pi-subagents 0.89.0 → 0.89.2
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 +35 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-TGABNSG5.js → chunk-2UCFLUE4.js} +64 -12
- package/bundle/{chunk-7W2IQFP4.js → chunk-464OJSDP.js} +4 -4
- package/bundle/{chunk-ETDE2VYK.js → chunk-4KQW5R6U.js} +2 -2
- package/bundle/{chunk-JRO2CU4D.js → chunk-5TXWZB73.js} +1 -1
- package/bundle/{chunk-7J4ZXMY7.js → chunk-72334PEI.js} +6 -4
- package/bundle/{chunk-CHEABMO2.js → chunk-76WVWEFE.js} +33 -24
- package/bundle/{chunk-S77ZKDLS.js → chunk-77VQEATI.js} +1 -1
- package/bundle/{chunk-HZDLR73C.js → chunk-AHGJSJYY.js} +4 -3
- package/bundle/{chunk-4ALRHKGE.js → chunk-DGLXVN3F.js} +1 -1
- package/bundle/{chunk-SLLZJ5EC.js → chunk-DHY5TY2Y.js} +237 -199
- package/bundle/{chunk-2I6YN6ET.js → chunk-DYBRIEIF.js} +8 -8
- package/bundle/{chunk-NQ26PJSQ.js → chunk-FF5K5HQU.js} +11 -6
- package/bundle/{chunk-HSHLPYCQ.js → chunk-FO2GIU5F.js} +27 -18
- package/bundle/{chunk-JFACGAJT.js → chunk-JEYG7CNC.js} +8 -4
- package/bundle/{chunk-X5ZOTDHO.js → chunk-KA4MKMYT.js} +11 -11
- package/bundle/{chunk-GHJ6BH5U.js → chunk-LWH7IGI3.js} +8 -0
- package/bundle/{chunk-AZW4HXNU.js → chunk-ME4IS3Y3.js} +99 -30
- package/bundle/{chunk-UQT2EQ4U.js → chunk-Q4VH72JI.js} +2 -2
- package/bundle/{chunk-443LPCRI.js → chunk-RHKIP45B.js} +6 -6
- package/bundle/{chunk-PPPAEFRA.js → chunk-ROJH7KPK.js} +2 -2
- package/bundle/{chunk-WW6GQBBS.js → chunk-SRCMJY4F.js} +4 -4
- package/bundle/{chunk-KOLLMZ2X.js → chunk-SWGB2P5J.js} +1 -1
- package/bundle/{chunk-ZSCIHMUI.js → chunk-TXC7WIPL.js} +3 -2
- package/bundle/{chunk-6JD4XCA4.js → chunk-U753SUBC.js} +14 -6
- package/bundle/{chunk-YX7R55CR.js → chunk-UBPAMRVL.js} +12 -12
- package/bundle/{chunk-A3INCQ6Z.js → chunk-UUW7P6KJ.js} +1 -1
- package/bundle/{chunk-EPMRDKQT.js → chunk-VEEUXJDO.js} +1 -1
- package/bundle/{chunk-NONHDYXE.js → chunk-YJIU5WF4.js} +1 -1
- 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 +4 -4
- package/docs/agents.md +2 -2
- package/docs/observability.md +3 -1
- package/docs/watchdog.md +3 -2
- package/package.json +1 -1
- package/src/api/preflight.d.ts +1 -0
- package/src/api/preflight.js +2 -1
- package/src/extension/herdr-pi-bridge.js +1 -1
- package/src/inspectors/herdr/project-panes.d.ts +2 -0
- package/src/inspectors/herdr/project-panes.js +7 -1
- package/src/inspectors/shell-command.d.ts +2 -1
- package/src/inspectors/shell-command.js +7 -5
- package/src/runs/background/active-async-capacity.js +2 -1
- package/src/runs/background/active-run-index.d.ts +1 -0
- package/src/runs/background/active-run-index.js +3 -0
- package/src/runs/background/async-execution.d.ts +2 -0
- package/src/runs/background/async-execution.js +3 -2
- package/src/runs/background/async-job-tracker.js +85 -9
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +8 -3
- package/src/runs/background/process-terminal.d.ts +6 -0
- package/src/runs/background/process-terminal.js +34 -2
- package/src/runs/background/run-status.js +2 -1
- package/src/runs/background/stale-run-reconciler.d.ts +8 -0
- package/src/runs/background/stale-run-reconciler.js +38 -8
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +4 -4
- package/src/runs/foreground/execution.js +2 -2
- package/src/runs/foreground/subagent-executor.d.ts +2 -0
- package/src/runs/foreground/subagent-executor.js +10 -1
- package/src/runs/shared/herdr-machine.js +3 -1
- package/src/runs/shared/herdr-pane-host.js +10 -2
- package/src/runs/shared/mcp-config-sources.d.ts +1 -0
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.js +1 -0
- package/src/runs/shared/subagent-prompt-runtime.js +6 -5
- package/src/shared/types.d.ts +2 -0
- package/src/shared/utils.d.ts +2 -0
- package/src/shared/utils.js +9 -0
- package/src/tui/fleet-transcript.js +21 -9
- package/src/watchdog/runtime.d.ts +4 -0
- package/src/watchdog/runtime.js +50 -12
- package/src/watchdog/turn-delta.d.ts +2 -0
- package/src/watchdog/turn-delta.js +21 -0
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
PROJECT_SUBAGENTS_RELATIVE_DIR,
|
|
6
6
|
canonicalSessionId,
|
|
7
7
|
inspectSessionLease
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-77VQEATI.js";
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_FILE_SYSTEM_RETRY_DELAYS_MS,
|
|
11
11
|
DEFAULT_GLOBAL_CONCURRENCY_LIMIT,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
withFileLease,
|
|
28
28
|
writeAtomicJson,
|
|
29
29
|
writePrivateAtomicJson
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-LWH7IGI3.js";
|
|
31
31
|
import {
|
|
32
32
|
DIRS,
|
|
33
33
|
SUBAGENT_LIFECYCLE_ARTIFACT_VERSION,
|
|
@@ -301,6 +301,9 @@ function removeEmptyAncestors(start, stop) {
|
|
|
301
301
|
function isActiveAsyncState(state) {
|
|
302
302
|
return state === "queued" || state === "running";
|
|
303
303
|
}
|
|
304
|
+
function isTerminalAsyncState(state) {
|
|
305
|
+
return state !== "queued" && state !== "running" && state !== "paused";
|
|
306
|
+
}
|
|
304
307
|
function releaseToolCallAliases(asyncDir) {
|
|
305
308
|
const root = path3.join(indexDir(path3.dirname(asyncDir)), TOOL_CALL_INDEX_DIR2);
|
|
306
309
|
let entries;
|
|
@@ -474,6 +477,9 @@ import * as path5 from "node:path";
|
|
|
474
477
|
function processTerminalPath(asyncDir) {
|
|
475
478
|
return path5.join(asyncDir, "process-terminal.json");
|
|
476
479
|
}
|
|
480
|
+
function unobservedRunnerExitPath(asyncDir) {
|
|
481
|
+
return path5.join(asyncDir, "process-terminal-unobserved.json");
|
|
482
|
+
}
|
|
477
483
|
function errorMessage(error) {
|
|
478
484
|
return error instanceof Error ? error.message : String(error);
|
|
479
485
|
}
|
|
@@ -536,11 +542,27 @@ function sanitizeProcessTerminal(value, fallback, label = "status") {
|
|
|
536
542
|
return unknownProof(fallback.runId ?? label, fallback.runnerProcessInstanceId ?? "unknown", "proof-write-failed", errorMessage(error));
|
|
537
543
|
}
|
|
538
544
|
}
|
|
545
|
+
function readUnobservedRunnerExit(asyncDir, pending) {
|
|
546
|
+
const filePath = unobservedRunnerExitPath(asyncDir);
|
|
547
|
+
let raw;
|
|
548
|
+
try {
|
|
549
|
+
raw = JSON.parse(fs4.readFileSync(filePath, "utf-8"));
|
|
550
|
+
} catch (error) {
|
|
551
|
+
if (error.code === "ENOENT") return void 0;
|
|
552
|
+
throw error;
|
|
553
|
+
}
|
|
554
|
+
if (isRecord(raw) && (raw.runId !== pending.runId || raw.runnerProcessInstanceId !== pending.runnerProcessInstanceId)) return void 0;
|
|
555
|
+
validateProof(raw, filePath);
|
|
556
|
+
const proof = raw;
|
|
557
|
+
if (proof.state !== "unknown" || proof.reason !== "observer-unavailable") throw new Error(`Invalid unobserved runner exit in '${asyncDir}'.`);
|
|
558
|
+
return proof;
|
|
559
|
+
}
|
|
539
560
|
function readProcessTerminal(asyncDir, fallback) {
|
|
540
561
|
try {
|
|
541
562
|
const raw = JSON.parse(fs4.readFileSync(processTerminalPath(asyncDir), "utf-8"));
|
|
542
563
|
validateProof(raw, asyncDir, fallback);
|
|
543
|
-
|
|
564
|
+
const proof = raw;
|
|
565
|
+
return proof.state === "pending" ? readUnobservedRunnerExit(asyncDir, proof) ?? proof : proof;
|
|
544
566
|
} catch (error) {
|
|
545
567
|
if (error.code === "ENOENT") return void 0;
|
|
546
568
|
return unknownProof(fallback?.runId ?? path5.basename(asyncDir), fallback?.runnerProcessInstanceId ?? "unknown", "proof-write-failed", errorMessage(error));
|
|
@@ -583,7 +605,7 @@ function finalizeProcessTerminal(asyncDir, runId, runnerClose) {
|
|
|
583
605
|
const existing = readProcessTerminal(asyncDir, { runId, runnerProcessInstanceId: runnerClose.processInstanceId });
|
|
584
606
|
if (existing && fs4.existsSync(processTerminalPath(asyncDir))) {
|
|
585
607
|
if (existing.state === "observed" && existing.runId === runId && existing.runnerProcessInstanceId === runnerClose.processInstanceId) return existing;
|
|
586
|
-
if (existing.state === "unknown") {
|
|
608
|
+
if (existing.state === "unknown" && existing.reason !== "observer-unavailable") {
|
|
587
609
|
if (existing.instances?.length || existing.reason === "proof-write-failed") return existing;
|
|
588
610
|
const withExit = { ...existing, instances: [{ kind: "runner", ...runnerClose }] };
|
|
589
611
|
try {
|
|
@@ -5494,8 +5516,8 @@ function currentRecordedPid() {
|
|
|
5494
5516
|
}
|
|
5495
5517
|
|
|
5496
5518
|
// src/runs/background/stale-run-reconciler.ts
|
|
5497
|
-
import * as
|
|
5498
|
-
import * as
|
|
5519
|
+
import * as fs14 from "node:fs";
|
|
5520
|
+
import * as path13 from "node:path";
|
|
5499
5521
|
|
|
5500
5522
|
// src/runs/background/parallel-groups.ts
|
|
5501
5523
|
function isValidParallelGroup(group, stepCount, chainStepCount) {
|
|
@@ -5535,111 +5557,26 @@ function isReusableWorkflowStopCause(cause) {
|
|
|
5535
5557
|
return cause === WORKFLOW_STOP_CAUSE_RUNTIME_REPLACED || cause === WORKFLOW_STOP_CAUSE_OWNER_EXITED;
|
|
5536
5558
|
}
|
|
5537
5559
|
|
|
5538
|
-
// src/runs/background/workflow-terminal-proof.ts
|
|
5539
|
-
import * as fs14 from "node:fs";
|
|
5540
|
-
import * as path13 from "node:path";
|
|
5541
|
-
var TERMINAL_WORKFLOW_STATES = /* @__PURE__ */ new Set(["completed", "failed", "stopped"]);
|
|
5542
|
-
function isTerminalAsyncState(state) {
|
|
5543
|
-
return state !== "queued" && state !== "running" && state !== "paused";
|
|
5544
|
-
}
|
|
5545
|
-
function readWorkflowChildRunModel(workflowAsyncDir, step) {
|
|
5546
|
-
if (step.async !== true || typeof step.runId !== "string" || path13.basename(step.runId) !== step.runId) return void 0;
|
|
5547
|
-
try {
|
|
5548
|
-
const child = readStatus(path13.join(path13.dirname(workflowAsyncDir), step.runId));
|
|
5549
|
-
const first = Array.isArray(child?.steps) ? child.steps[0] : void 0;
|
|
5550
|
-
const model = typeof first?.model === "string" && first.model ? first.model : void 0;
|
|
5551
|
-
const thinking = typeof first?.thinking === "string" && first.thinking ? first.thinking : void 0;
|
|
5552
|
-
return model || thinking ? { model, thinking } : void 0;
|
|
5553
|
-
} catch {
|
|
5554
|
-
return void 0;
|
|
5555
|
-
}
|
|
5556
|
-
}
|
|
5557
|
-
function withWorkflowChildRunModel(workflowAsyncDir, child) {
|
|
5558
|
-
if (child.model && child.thinking) return child;
|
|
5559
|
-
const reported = readWorkflowChildRunModel(workflowAsyncDir, { async: true, runId: child.runId });
|
|
5560
|
-
const model = child.model ?? reported?.model;
|
|
5561
|
-
const thinking = child.thinking ?? reported?.thinking;
|
|
5562
|
-
return { ...child, ...model ? { model } : {}, ...thinking ? { thinking } : {} };
|
|
5563
|
-
}
|
|
5564
|
-
function readWorkflowChildProcessEvidence(workflowAsyncDir, steps) {
|
|
5565
|
-
if (!steps) return { state: "unknown", reason: "workflow child roster is missing" };
|
|
5566
|
-
const children = [];
|
|
5567
|
-
for (const step of steps) {
|
|
5568
|
-
const child = readWorkflowChildEvidence(workflowAsyncDir, step);
|
|
5569
|
-
if (!child) continue;
|
|
5570
|
-
if (child.state !== "resolved") return { state: child.state, reason: child.reason };
|
|
5571
|
-
children.push(child.proof);
|
|
5572
|
-
}
|
|
5573
|
-
return { state: "observed", children };
|
|
5574
|
-
}
|
|
5575
|
-
function launchFailedBeforeRunner(step, childDir) {
|
|
5576
|
-
if (step.status !== "failed" || !step.error) return false;
|
|
5577
|
-
return !childDir || !["process-terminal.json", "runner-startup.json"].some((file) => fs14.existsSync(path13.join(childDir, file)));
|
|
5578
|
-
}
|
|
5579
|
-
function readWorkflowChildEvidence(workflowAsyncDir, step) {
|
|
5580
|
-
const label = step.workflowKey ?? step.agent;
|
|
5581
|
-
if (typeof step.async !== "boolean") return { state: "unknown", reason: `workflow child ${label} is missing async classification` };
|
|
5582
|
-
if (!step.async) return void 0;
|
|
5583
|
-
if (!step.runId || path13.basename(step.runId) !== step.runId) return { state: "unknown", reason: `async workflow child ${label} is missing run id` };
|
|
5584
|
-
const childDir = path13.join(path13.dirname(workflowAsyncDir), step.runId);
|
|
5585
|
-
if (!fs14.existsSync(childDir)) return launchFailedBeforeRunner(step) ? void 0 : { state: "unknown", reason: `async workflow child ${label} directory is missing` };
|
|
5586
|
-
const childStatus = readStatus(childDir);
|
|
5587
|
-
if (!childStatus) return launchFailedBeforeRunner(step, childDir) ? void 0 : { state: "unknown", reason: `async workflow child ${label} status is missing or unreadable` };
|
|
5588
|
-
if (!isTerminalAsyncState(childStatus.state)) return { state: "pending", reason: `async workflow child ${label} is still ${childStatus.state}` };
|
|
5589
|
-
const recorded = childStatus.processTerminal;
|
|
5590
|
-
if (!recorded?.runnerProcessInstanceId) return { state: "unknown", reason: `async workflow child ${label} has no runner process identity` };
|
|
5591
|
-
if (recorded.state === "not-started" && recorded.runId === step.runId && typeof childStatus.error === "string" && childStatus.error) {
|
|
5592
|
-
return { state: "resolved", proof: recorded };
|
|
5593
|
-
}
|
|
5594
|
-
const proof = readProcessTerminal(childDir, { runId: step.runId, runnerProcessInstanceId: recorded.runnerProcessInstanceId });
|
|
5595
|
-
if (proof?.state !== "observed" || proof.runId !== step.runId) {
|
|
5596
|
-
const proofState = proof?.state ?? "missing";
|
|
5597
|
-
const bound = childStatus.runId === step.runId && typeof recorded.runnerProcessInstanceId === "string";
|
|
5598
|
-
return {
|
|
5599
|
-
state: !proof || proof.state === "pending" ? "pending" : "unknown",
|
|
5600
|
-
reason: `async workflow child ${label} process-terminal proof is ${proofState}`,
|
|
5601
|
-
...bound ? { unresolvedProof: { status: childStatus, proofState } } : {}
|
|
5602
|
-
};
|
|
5603
|
-
}
|
|
5604
|
-
return { state: "resolved", proof };
|
|
5605
|
-
}
|
|
5606
|
-
function unresolved(runId, state, dispatchClosed, reason) {
|
|
5607
|
-
return { version: 1, kind: "workflow", runId, state, dispatchClosed, reason };
|
|
5608
|
-
}
|
|
5609
|
-
function readWorkflowTerminalProof(asyncDir, steps, summary, hostCommandCount, closedAt) {
|
|
5610
|
-
const runId = summary.workflowRunId;
|
|
5611
|
-
if (!summary.inventoryComplete || !TERMINAL_WORKFLOW_STATES.has(summary.workflowState)) {
|
|
5612
|
-
return unresolved(runId, "pending", false, "Workflow dispatch is still open.");
|
|
5613
|
-
}
|
|
5614
|
-
if (hostCommandCount > 0) {
|
|
5615
|
-
return unresolved(runId, "unknown", true, "Workflow host commands have no process-terminal proof.");
|
|
5616
|
-
}
|
|
5617
|
-
const evidence = readWorkflowChildProcessEvidence(asyncDir, steps);
|
|
5618
|
-
if (evidence.state !== "observed") return unresolved(runId, evidence.state, true, evidence.reason);
|
|
5619
|
-
const observedAt = Math.max(closedAt, ...evidence.children.map((child) => child.state === "observed" ? child.observedAt : 0));
|
|
5620
|
-
return { version: 1, kind: "workflow", runId, state: "observed", dispatchClosed: true, observedAt, children: evidence.children };
|
|
5621
|
-
}
|
|
5622
|
-
|
|
5623
5560
|
// src/runs/background/stale-run-reconciler.ts
|
|
5624
5561
|
function getErrorMessage(error) {
|
|
5625
5562
|
return error instanceof Error ? error.message : String(error);
|
|
5626
5563
|
}
|
|
5627
5564
|
function readRunnerStartupDiagnostics(asyncDir) {
|
|
5628
|
-
const stderrPath =
|
|
5565
|
+
const stderrPath = path13.join(asyncDir, "runner.stderr.log");
|
|
5629
5566
|
const maxBytes = 64 * 1024;
|
|
5630
5567
|
let content;
|
|
5631
5568
|
try {
|
|
5632
|
-
const stat =
|
|
5569
|
+
const stat = fs14.statSync(stderrPath);
|
|
5633
5570
|
if (stat.size <= 0) return void 0;
|
|
5634
|
-
const fd =
|
|
5571
|
+
const fd = fs14.openSync(stderrPath, "r");
|
|
5635
5572
|
try {
|
|
5636
5573
|
const bytesToRead = Math.min(stat.size, maxBytes);
|
|
5637
5574
|
const start = Math.max(0, stat.size - bytesToRead);
|
|
5638
5575
|
const buffer = Buffer.alloc(bytesToRead);
|
|
5639
|
-
|
|
5576
|
+
fs14.readSync(fd, buffer, 0, bytesToRead, start);
|
|
5640
5577
|
content = buffer.toString("utf-8").trim();
|
|
5641
5578
|
} finally {
|
|
5642
|
-
|
|
5579
|
+
fs14.closeSync(fd);
|
|
5643
5580
|
}
|
|
5644
5581
|
} catch {
|
|
5645
5582
|
return void 0;
|
|
@@ -5654,15 +5591,15 @@ function isNotFoundError(error) {
|
|
|
5654
5591
|
}
|
|
5655
5592
|
function appendJsonlBestEffort(filePath, payload) {
|
|
5656
5593
|
try {
|
|
5657
|
-
|
|
5658
|
-
|
|
5594
|
+
fs14.mkdirSync(path13.dirname(filePath), { recursive: true });
|
|
5595
|
+
fs14.appendFileSync(filePath, `${JSON.stringify(payload)}
|
|
5659
5596
|
`, "utf-8");
|
|
5660
5597
|
} catch {
|
|
5661
5598
|
}
|
|
5662
5599
|
}
|
|
5663
5600
|
function regularFileExists(filePath) {
|
|
5664
5601
|
try {
|
|
5665
|
-
return
|
|
5602
|
+
return fs14.statSync(filePath).isFile();
|
|
5666
5603
|
} catch (error) {
|
|
5667
5604
|
if (isNotFoundError(error)) return false;
|
|
5668
5605
|
throw error;
|
|
@@ -5670,7 +5607,7 @@ function regularFileExists(filePath) {
|
|
|
5670
5607
|
}
|
|
5671
5608
|
function readResultRepairData(resultPath) {
|
|
5672
5609
|
try {
|
|
5673
|
-
const data = JSON.parse(
|
|
5610
|
+
const data = JSON.parse(fs14.readFileSync(resultPath, "utf-8"));
|
|
5674
5611
|
if (data.error !== void 0 && typeof data.error !== "string") throw new Error(`Invalid async result file '${resultPath}': error must be a string.`);
|
|
5675
5612
|
const state = data.success ? "complete" : data.state === "stopped" ? "stopped" : data.state === "rejected" ? "rejected" : data.state === "partial" ? "partial" : data.state === "paused" || data.exitCode === 0 ? "paused" : "failed";
|
|
5676
5613
|
const results = Array.isArray(data.results) ? data.results.map((entry, index) => {
|
|
@@ -5744,7 +5681,7 @@ function buildStartedStatus(asyncDir, startedRun, now) {
|
|
|
5744
5681
|
const chainStepCount = startedRun.chainStepCount;
|
|
5745
5682
|
const parallelGroups = chainStepCount !== void 0 ? normalizeParallelGroups(startedRun.parallelGroups, agents.length, chainStepCount) : [];
|
|
5746
5683
|
return {
|
|
5747
|
-
runId: startedRun.runId ||
|
|
5684
|
+
runId: startedRun.runId || path13.basename(asyncDir),
|
|
5748
5685
|
...startedRun.sessionId ? { sessionId: startedRun.sessionId } : {},
|
|
5749
5686
|
...startedRun.completionOwnerId ? { completionOwnerId: startedRun.completionOwnerId } : {},
|
|
5750
5687
|
mode: startedRun.mode ?? "single",
|
|
@@ -5766,8 +5703,8 @@ function buildStartedStatus(asyncDir, startedRun, now) {
|
|
|
5766
5703
|
}
|
|
5767
5704
|
function settledWorkflowChildStatus(asyncDir, workflowRunId, step, now) {
|
|
5768
5705
|
const childRunId = step.runId;
|
|
5769
|
-
if (step.async !== true || step.parentWorkflowRunId !== workflowRunId || !childRunId || childRunId === workflowRunId || childRunId !==
|
|
5770
|
-
const child = readStatus(
|
|
5706
|
+
if (step.async !== true || step.parentWorkflowRunId !== workflowRunId || !childRunId || childRunId === workflowRunId || childRunId !== path13.basename(childRunId) || childRunId === "." || childRunId === "..") return void 0;
|
|
5707
|
+
const child = readStatus(path13.join(path13.dirname(asyncDir), childRunId));
|
|
5771
5708
|
if (!child || child.runId !== childRunId || child.parentWorkflowRunId !== workflowRunId || !isTerminalAsyncState(child.state)) return void 0;
|
|
5772
5709
|
if (step.workflowKey !== void 0 && child.workflowKey !== step.workflowKey) return void 0;
|
|
5773
5710
|
const state = child.state;
|
|
@@ -5788,7 +5725,7 @@ function settledWorkflowChildStatus(asyncDir, workflowRunId, step, now) {
|
|
|
5788
5725
|
return settled;
|
|
5789
5726
|
}
|
|
5790
5727
|
function buildFailedRepair(status, asyncDir, now, reason, ownerExited = false, adoptCompletionOwnerId) {
|
|
5791
|
-
const runId = status.runId ||
|
|
5728
|
+
const runId = status.runId || path13.basename(asyncDir);
|
|
5792
5729
|
const pid = typeof status.pid === "number" ? status.pid : "unknown";
|
|
5793
5730
|
const exitedWorkflow = ownerExited && status.mode === "workflow" ? status.workflow : void 0;
|
|
5794
5731
|
const completionOwnerId = exitedWorkflow ? adoptCompletionOwnerId || OWNING_SESSION_COMPLETION_OWNER : status.completionOwnerId;
|
|
@@ -5875,9 +5812,9 @@ ${diagnostics}` : baseMessage;
|
|
|
5875
5812
|
function writeFailedRepair(asyncDir, status, resultPath, now, reason, ownerExited = false, adoptCompletionOwnerId) {
|
|
5876
5813
|
const repair = buildFailedRepair(status, asyncDir, now, reason, ownerExited, adoptCompletionOwnerId);
|
|
5877
5814
|
if (repair.result.sessionId) writeAsyncResultFile(resultPath, repair.result);
|
|
5878
|
-
writeAtomicJson(
|
|
5815
|
+
writeAtomicJson(path13.join(asyncDir, "status.json"), repair.status);
|
|
5879
5816
|
updateActiveRunIndex(asyncDir, repair.status.state, repair.status.toolCallId);
|
|
5880
|
-
appendJsonlBestEffort(
|
|
5817
|
+
appendJsonlBestEffort(path13.join(asyncDir, "events.jsonl"), {
|
|
5881
5818
|
type: "subagent.run.repaired_stale",
|
|
5882
5819
|
ts: now,
|
|
5883
5820
|
runId: repair.status.runId,
|
|
@@ -5905,7 +5842,7 @@ function reconcileNestedAsyncDescendants(route, options = {}) {
|
|
|
5905
5842
|
if (!asyncDir) continue;
|
|
5906
5843
|
const result = reconcileAsyncRun(asyncDir, {
|
|
5907
5844
|
...options,
|
|
5908
|
-
resultsDir:
|
|
5845
|
+
resultsDir: path13.join(options.resultsDir ?? DIRS.results, "nested", route.rootRunId)
|
|
5909
5846
|
});
|
|
5910
5847
|
const status = result.status;
|
|
5911
5848
|
if (!status) continue;
|
|
@@ -5933,7 +5870,7 @@ function checkPidLiveness(pid, kill = process.kill, probeZombie = false) {
|
|
|
5933
5870
|
kill(pid, 0);
|
|
5934
5871
|
if (probeZombie && process.platform === "linux") {
|
|
5935
5872
|
try {
|
|
5936
|
-
const stat =
|
|
5873
|
+
const stat = fs14.readFileSync(`/proc/${pid}/stat`, "utf-8");
|
|
5937
5874
|
const closeParen = stat.lastIndexOf(") ");
|
|
5938
5875
|
if (closeParen >= 0 && stat[closeParen + 2] === "Z") return "dead";
|
|
5939
5876
|
} catch {
|
|
@@ -5960,6 +5897,25 @@ function checkRecordedPidLiveness(recorded, observation = { observedScope: curre
|
|
|
5960
5897
|
const liveness = observation.probe ? observation.probe(recorded.pid) : checkPidLiveness(recorded.pid, observation.kill, scopeVerified);
|
|
5961
5898
|
return liveness === "dead" && scopeMismatch ? "unknown" : liveness;
|
|
5962
5899
|
}
|
|
5900
|
+
function settleUnobservedRunnerExit(asyncDir, status, observation = { observedScope: currentPidNamespaceScope(), observedBootId: currentBootId() }) {
|
|
5901
|
+
const runnerProcessInstanceId = status.processTerminal?.runnerProcessInstanceId;
|
|
5902
|
+
if (!terminal2(status.state) || status.mode === "workflow" || status.processTerminal?.state !== "pending" || !runnerProcessInstanceId) return;
|
|
5903
|
+
if (typeof status.pid !== "number" || status.pidNamespaceScope !== observation.observedScope) return;
|
|
5904
|
+
if (readProcessTerminal(asyncDir, { runId: status.runId, runnerProcessInstanceId })?.state !== "pending") return;
|
|
5905
|
+
if (checkRecordedPidLiveness({ pid: status.pid, pidNamespaceScope: status.pidNamespaceScope, bootId: status.bootId }, observation) !== "dead") return;
|
|
5906
|
+
try {
|
|
5907
|
+
const proof = {
|
|
5908
|
+
version: 1,
|
|
5909
|
+
state: "unknown",
|
|
5910
|
+
runId: status.runId,
|
|
5911
|
+
runnerProcessInstanceId,
|
|
5912
|
+
reason: "observer-unavailable",
|
|
5913
|
+
diagnostic: `Runner PID ${status.pid} is gone and no Pi recorded its exit.`
|
|
5914
|
+
};
|
|
5915
|
+
writeAtomicJson(unobservedRunnerExitPath(asyncDir), proof);
|
|
5916
|
+
} catch {
|
|
5917
|
+
}
|
|
5918
|
+
}
|
|
5963
5919
|
function reconcileAsyncRun(asyncDir, options = {}, observeStatus) {
|
|
5964
5920
|
const now = options.now?.() ?? Date.now();
|
|
5965
5921
|
const status = readStatus(asyncDir);
|
|
@@ -5967,25 +5923,23 @@ function reconcileAsyncRun(asyncDir, options = {}, observeStatus) {
|
|
|
5967
5923
|
const startedStatus = !status && options.startedRun ? buildStartedStatus(asyncDir, options.startedRun, now) : void 0;
|
|
5968
5924
|
const effectiveStatus = status ?? startedStatus;
|
|
5969
5925
|
if (!effectiveStatus) return { status: null, repaired: false };
|
|
5970
|
-
assertWorkflowGraphHostSteps(effectiveStatus.workflowGraph,
|
|
5971
|
-
const statusPath =
|
|
5926
|
+
assertWorkflowGraphHostSteps(effectiveStatus.workflowGraph, path13.join(asyncDir, "status.json"), effectiveStatus.runId);
|
|
5927
|
+
const statusPath = path13.join(asyncDir, "status.json");
|
|
5972
5928
|
for (const [index, step] of (effectiveStatus.steps ?? []).entries()) {
|
|
5973
5929
|
const stepRecord = step;
|
|
5974
5930
|
if (stepRecord.model !== void 0 && typeof stepRecord.model !== "string") throw new Error(`Invalid async status file '${statusPath}': steps[${index}].model must be a string.`);
|
|
5975
5931
|
if (stepRecord.thinking !== void 0 && typeof stepRecord.thinking !== "string") throw new Error(`Invalid async status file '${statusPath}': steps[${index}].thinking must be a string.`);
|
|
5976
5932
|
}
|
|
5977
|
-
const runId = effectiveStatus.runId ||
|
|
5933
|
+
const runId = effectiveStatus.runId || path13.basename(asyncDir);
|
|
5978
5934
|
const resultsDir = options.resultsDir ?? DIRS.results;
|
|
5979
5935
|
const resultPath = resultFilePath(resultsDir, runId);
|
|
5980
5936
|
const existingResultPath = effectiveStatus.sessionId ? resultPayloadPathForSessionRun(resultsDir, effectiveStatus.sessionId, runId) ?? (regularFileExists(resultPath) ? resultPath : void 0) : regularFileExists(resultPath) ? resultPath : void 0;
|
|
5981
5937
|
const staleAfterMs = options.staleAlivePidMs ?? 24 * 60 * 60 * 1e3;
|
|
5982
5938
|
const lastUpdate = effectiveStatus.lastUpdate ?? effectiveStatus.startedAt;
|
|
5983
5939
|
const observedScope = options.pidNamespaceScope ? options.pidNamespaceScope() : currentPidNamespaceScope();
|
|
5984
|
-
const
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
observedBootId: options.bootId ? options.bootId() : currentBootId()
|
|
5988
|
-
});
|
|
5940
|
+
const observation = { kill: options.kill, observedScope, observedBootId: options.bootId ? options.bootId() : currentBootId() };
|
|
5941
|
+
const runnerLiveness = (pid) => checkRecordedPidLiveness({ pid, pidNamespaceScope: effectiveStatus.pidNamespaceScope, bootId: effectiveStatus.bootId }, observation);
|
|
5942
|
+
if (status) settleUnobservedRunnerExit(asyncDir, status, observation);
|
|
5989
5943
|
if (existingResultPath) {
|
|
5990
5944
|
const runnerStillFinishing = effectiveStatus.state === "running" && effectiveStatus.mode !== "workflow" && typeof effectiveStatus.pid === "number" && effectiveStatus.pidNamespaceScope === observedScope && now - lastUpdate <= staleAfterMs && runnerLiveness(effectiveStatus.pid) === "alive";
|
|
5991
5945
|
const terminalStatus = (effectiveStatus.state === "running" || effectiveStatus.state === "queued") && !runnerStillFinishing ? terminalStatusFromResult(effectiveStatus, existingResultPath, now) : void 0;
|
|
@@ -6258,13 +6212,13 @@ async function runSetupCommand(command, args, options) {
|
|
|
6258
6212
|
}
|
|
6259
6213
|
|
|
6260
6214
|
// src/runs/shared/worktree.ts
|
|
6261
|
-
import * as
|
|
6215
|
+
import * as fs15 from "node:fs";
|
|
6262
6216
|
import * as os2 from "node:os";
|
|
6263
|
-
import * as
|
|
6217
|
+
import * as path14 from "node:path";
|
|
6264
6218
|
var DEFAULT_WORKTREE_PROVIDER = "auto";
|
|
6265
6219
|
var DEFAULT_WORKTREE_BASE_REF = "HEAD";
|
|
6266
6220
|
var DEFAULT_WORKTREE_BRANCH_PREFIX = "pi-subagents/";
|
|
6267
|
-
var WORKTREE_AGENT_CWD_PLACEHOLDER =
|
|
6221
|
+
var WORKTREE_AGENT_CWD_PLACEHOLDER = path14.join(path14.parse(process.cwd()).root, "__pi_subagents_worktree_cwd__");
|
|
6268
6222
|
var WORKTREE_NAMING_COMPONENT_MAX_BYTES = 96;
|
|
6269
6223
|
var WORKTREE_NAMING_LABEL_MAX_BYTES = 256;
|
|
6270
6224
|
var WORKTREE_NAMING_BRANCH_MAX_BYTES = 256;
|
|
@@ -6398,7 +6352,7 @@ function findListedWorktreeAgentCwd(repoCwd, branch) {
|
|
|
6398
6352
|
const worktree = findListedWorktreeOnBranch(repoCwd, branch);
|
|
6399
6353
|
if (!worktree) return void 0;
|
|
6400
6354
|
const cwdRelative = resolveRepoCwdRelative(repoCwd);
|
|
6401
|
-
return cwdRelative ?
|
|
6355
|
+
return cwdRelative ? path14.join(worktree, cwdRelative) : worktree;
|
|
6402
6356
|
}
|
|
6403
6357
|
function isComparablePathInside(parent, child) {
|
|
6404
6358
|
return isPathInside(normalizeComparableCwd(parent), normalizeComparableCwd(child));
|
|
@@ -6412,11 +6366,11 @@ function currentWorktreePatch(worktreePath, baseCommit) {
|
|
|
6412
6366
|
assertWorktreeMutationAllowed();
|
|
6413
6367
|
let tempDir;
|
|
6414
6368
|
try {
|
|
6415
|
-
tempDir =
|
|
6369
|
+
tempDir = fs15.mkdtempSync(path14.join(os2.tmpdir(), "pi-worktree-index-"));
|
|
6416
6370
|
} catch (error) {
|
|
6417
6371
|
return { error: error instanceof Error ? error.message : String(error) };
|
|
6418
6372
|
}
|
|
6419
|
-
const env = { GIT_INDEX_FILE:
|
|
6373
|
+
const env = { GIT_INDEX_FILE: path14.join(tempDir, "index") };
|
|
6420
6374
|
try {
|
|
6421
6375
|
const readTree = runGit(worktreePath, ["read-tree", "HEAD"], env);
|
|
6422
6376
|
if (readTree.status !== 0) return { error: readTree.stderr.trim() || readTree.stdout.trim() || "git read-tree failed" };
|
|
@@ -6427,7 +6381,7 @@ function currentWorktreePatch(worktreePath, baseCommit) {
|
|
|
6427
6381
|
return { patch: diff.stdout };
|
|
6428
6382
|
} finally {
|
|
6429
6383
|
try {
|
|
6430
|
-
|
|
6384
|
+
fs15.rmSync(tempDir, { recursive: true, force: true });
|
|
6431
6385
|
} catch {
|
|
6432
6386
|
}
|
|
6433
6387
|
}
|
|
@@ -6437,7 +6391,7 @@ function validateWorktreePatchRepresentsCurrentWorktree(worktreePath, baseCommit
|
|
|
6437
6391
|
if (validationError) return validationError;
|
|
6438
6392
|
let capturedPatch;
|
|
6439
6393
|
try {
|
|
6440
|
-
capturedPatch =
|
|
6394
|
+
capturedPatch = fs15.readFileSync(patchPath, "utf-8");
|
|
6441
6395
|
} catch (error) {
|
|
6442
6396
|
return error instanceof Error ? error.message : String(error);
|
|
6443
6397
|
}
|
|
@@ -6475,7 +6429,7 @@ async function preflightWorktreeSource(cwd, options = {}) {
|
|
|
6475
6429
|
async function resolveRepoState(tx, cwd, requestedBaseRef) {
|
|
6476
6430
|
const toplevel = await probeWorktreeSource(tx, cwd);
|
|
6477
6431
|
const rawPrefix = (await tx.gitChecked(cwd, ["rev-parse", "--show-prefix"])).trim();
|
|
6478
|
-
const cwdRelative = rawPrefix ?
|
|
6432
|
+
const cwdRelative = rawPrefix ? path14.normalize(rawPrefix.replace(/[\\/]+$/, "")) : "";
|
|
6479
6433
|
const baseRef = normalizeWorktreeBaseRef(requestedBaseRef) ?? DEFAULT_WORKTREE_BASE_REF;
|
|
6480
6434
|
let baseCommit;
|
|
6481
6435
|
try {
|
|
@@ -6489,22 +6443,22 @@ async function resolveRepoState(tx, cwd, requestedBaseRef) {
|
|
|
6489
6443
|
return { toplevel, cwdRelative, baseCommit };
|
|
6490
6444
|
}
|
|
6491
6445
|
function normalizeComparableCwd(cwd) {
|
|
6492
|
-
const resolved2 =
|
|
6446
|
+
const resolved2 = path14.resolve(cwd);
|
|
6493
6447
|
let existing = resolved2;
|
|
6494
6448
|
const missingSegments = [];
|
|
6495
6449
|
while (true) {
|
|
6496
6450
|
try {
|
|
6497
6451
|
let realpath;
|
|
6498
6452
|
try {
|
|
6499
|
-
realpath =
|
|
6453
|
+
realpath = fs15.realpathSync.native(existing);
|
|
6500
6454
|
} catch {
|
|
6501
|
-
realpath =
|
|
6455
|
+
realpath = fs15.realpathSync(existing);
|
|
6502
6456
|
}
|
|
6503
|
-
return
|
|
6457
|
+
return path14.join(realpath, ...missingSegments.reverse());
|
|
6504
6458
|
} catch {
|
|
6505
|
-
const parent =
|
|
6459
|
+
const parent = path14.dirname(existing);
|
|
6506
6460
|
if (parent === existing) return resolved2;
|
|
6507
|
-
missingSegments.push(
|
|
6461
|
+
missingSegments.push(path14.basename(existing));
|
|
6508
6462
|
existing = parent;
|
|
6509
6463
|
}
|
|
6510
6464
|
}
|
|
@@ -6598,7 +6552,7 @@ function hasConfiguredWorktreeBaseDir(baseDir) {
|
|
|
6598
6552
|
return baseDir !== void 0 ? true : (process.env.PI_SUBAGENTS_WORKTREE_DIR?.trim().length ?? 0) > 0;
|
|
6599
6553
|
}
|
|
6600
6554
|
function isInsidePiExtensionsDirectory(targetPath) {
|
|
6601
|
-
const extensionsDir = normalizeComparableCwd(
|
|
6555
|
+
const extensionsDir = normalizeComparableCwd(path14.join(getAgentDir(), "extensions"));
|
|
6602
6556
|
return isPathInside(extensionsDir, normalizeComparableCwd(targetPath));
|
|
6603
6557
|
}
|
|
6604
6558
|
function runWorktrunk(args, cwd) {
|
|
@@ -6680,49 +6634,49 @@ function resolveWorktreeDedicatedRoot(configuredBaseDir, repoRoot, relocateExten
|
|
|
6680
6634
|
const rawBaseDir = configuredBaseDir ?? process.env.PI_SUBAGENTS_WORKTREE_DIR;
|
|
6681
6635
|
let expanded;
|
|
6682
6636
|
if (rawBaseDir === void 0 || configuredBaseDir === void 0 && !rawBaseDir.trim()) {
|
|
6683
|
-
expanded = relocateExtensionRepo && isInsidePiExtensionsDirectory(repoRoot) ?
|
|
6637
|
+
expanded = relocateExtensionRepo && isInsidePiExtensionsDirectory(repoRoot) ? path14.join(getAgentDir(), "worktrees") : path14.join(path14.dirname(repoRoot), "worktrees");
|
|
6684
6638
|
} else {
|
|
6685
6639
|
const trimmed = rawBaseDir.trim();
|
|
6686
6640
|
if (!trimmed) throw new Error("worktree base directory cannot be empty");
|
|
6687
|
-
const candidate = trimmed.startsWith("~/") ?
|
|
6688
|
-
expanded =
|
|
6641
|
+
const candidate = trimmed.startsWith("~/") ? path14.join(os2.homedir(), trimmed.slice(2)) : trimmed;
|
|
6642
|
+
expanded = path14.isAbsolute(candidate) ? candidate : path14.resolve(repoRoot, candidate);
|
|
6689
6643
|
}
|
|
6690
|
-
const extensionsDir = normalizeComparableCwd(
|
|
6644
|
+
const extensionsDir = normalizeComparableCwd(path14.join(getAgentDir(), "extensions"));
|
|
6691
6645
|
if (isPathInside(extensionsDir, normalizeComparableCwd(expanded))) {
|
|
6692
6646
|
throw new Error(`worktree base directory cannot be inside Pi extensions directory: ${extensionsDir}. Choose a directory outside it.`);
|
|
6693
6647
|
}
|
|
6694
6648
|
return expanded;
|
|
6695
6649
|
}
|
|
6696
6650
|
function buildNativeProjectPath(dedicatedRoot, repoRoot) {
|
|
6697
|
-
return
|
|
6651
|
+
return path14.join(dedicatedRoot, path14.basename(repoRoot));
|
|
6698
6652
|
}
|
|
6699
6653
|
function ensureProjectWorktreeDir(dedicatedRoot, repoRoot) {
|
|
6700
6654
|
try {
|
|
6701
|
-
|
|
6655
|
+
fs15.mkdirSync(buildNativeProjectPath(dedicatedRoot, repoRoot), { recursive: true });
|
|
6702
6656
|
} catch (error) {
|
|
6703
6657
|
const message = error instanceof Error ? error.message : String(error);
|
|
6704
6658
|
throw new Error(`failed to create worktree base directory ${dedicatedRoot}: ${message}`);
|
|
6705
6659
|
}
|
|
6706
6660
|
}
|
|
6707
6661
|
function buildNativeWorktreePath(dedicatedRoot, repoRoot, runId, index) {
|
|
6708
|
-
return
|
|
6662
|
+
return path14.join(buildNativeProjectPath(dedicatedRoot, repoRoot), `pi-worktree-${sanitizeWorktreePathComponent(runId, 120)}-${index}`);
|
|
6709
6663
|
}
|
|
6710
6664
|
function isPathInside(parent, child) {
|
|
6711
|
-
const relative4 =
|
|
6665
|
+
const relative4 = path14.relative(parent, child);
|
|
6712
6666
|
if (!relative4 || relative4 === ".") return true;
|
|
6713
|
-
return relative4 !== ".." && !relative4.startsWith(`..${
|
|
6667
|
+
return relative4 !== ".." && !relative4.startsWith(`..${path14.sep}`) && !path14.isAbsolute(relative4);
|
|
6714
6668
|
}
|
|
6715
6669
|
function isStrictChildPath(parent, child) {
|
|
6716
|
-
const relative4 =
|
|
6717
|
-
return Boolean(relative4) && relative4 !== "." && relative4 !== ".." && !relative4.startsWith(`..${
|
|
6670
|
+
const relative4 = path14.relative(parent, child);
|
|
6671
|
+
return Boolean(relative4) && relative4 !== "." && relative4 !== ".." && !relative4.startsWith(`..${path14.sep}`) && !path14.isAbsolute(relative4);
|
|
6718
6672
|
}
|
|
6719
6673
|
function assertSafeWorktreeLocation(worktreePath, repoRoot, dedicatedRoot) {
|
|
6720
6674
|
const resolvedLeaf = normalizeComparableCwd(worktreePath);
|
|
6721
6675
|
const resolvedRepoRoot = normalizeComparableCwd(repoRoot);
|
|
6722
6676
|
const projectDir = normalizeComparableCwd(buildNativeProjectPath(dedicatedRoot, repoRoot));
|
|
6723
|
-
const repoParent = normalizeComparableCwd(
|
|
6724
|
-
const leafParent = normalizeComparableCwd(
|
|
6725
|
-
const extensionsDir = normalizeComparableCwd(
|
|
6677
|
+
const repoParent = normalizeComparableCwd(path14.dirname(resolvedRepoRoot));
|
|
6678
|
+
const leafParent = normalizeComparableCwd(path14.dirname(resolvedLeaf));
|
|
6679
|
+
const extensionsDir = normalizeComparableCwd(path14.join(getAgentDir(), "extensions"));
|
|
6726
6680
|
if (isPathInside(extensionsDir, projectDir) || isPathInside(extensionsDir, resolvedLeaf)) {
|
|
6727
6681
|
throw new Error(`worktree path cannot be inside Pi extensions directory: ${extensionsDir}. Choose a directory outside it.`);
|
|
6728
6682
|
}
|
|
@@ -6742,7 +6696,7 @@ function resolveRepoCwdRelative(cwd) {
|
|
|
6742
6696
|
throw new Error("worktree isolation requires a git repository");
|
|
6743
6697
|
}
|
|
6744
6698
|
const rawPrefix = runGitChecked(cwd, ["rev-parse", "--show-prefix"]).trim();
|
|
6745
|
-
const normalizedPrefix = rawPrefix ?
|
|
6699
|
+
const normalizedPrefix = rawPrefix ? path14.normalize(rawPrefix.replace(/[\\/]+$/, "")) : "";
|
|
6746
6700
|
return normalizedPrefix === "." ? "" : normalizedPrefix;
|
|
6747
6701
|
}
|
|
6748
6702
|
function resolveExpectedWorktreeAgentCwd(cwd, runId, index, baseDir) {
|
|
@@ -6751,14 +6705,14 @@ function resolveExpectedWorktreeAgentCwd(cwd, runId, index, baseDir) {
|
|
|
6751
6705
|
const dedicatedRoot = resolveWorktreeDedicatedRoot(baseDir, repoRoot);
|
|
6752
6706
|
const worktreePath = buildNativeWorktreePath(dedicatedRoot, repoRoot, runId, index);
|
|
6753
6707
|
assertSafeWorktreeLocation(worktreePath, repoRoot, dedicatedRoot);
|
|
6754
|
-
return cwdRelative ?
|
|
6708
|
+
return cwdRelative ? path14.join(worktreePath, cwdRelative) : worktreePath;
|
|
6755
6709
|
}
|
|
6756
6710
|
function linkNodeModulesIfPresent(toplevel, worktreePath) {
|
|
6757
|
-
const nodeModulesPath =
|
|
6758
|
-
const nodeModulesLinkPath =
|
|
6711
|
+
const nodeModulesPath = path14.join(toplevel, "node_modules");
|
|
6712
|
+
const nodeModulesLinkPath = path14.join(worktreePath, "node_modules");
|
|
6759
6713
|
const hasDirectoryEntry = (candidate) => {
|
|
6760
6714
|
try {
|
|
6761
|
-
|
|
6715
|
+
fs15.lstatSync(candidate);
|
|
6762
6716
|
return true;
|
|
6763
6717
|
} catch (error) {
|
|
6764
6718
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") return false;
|
|
@@ -6769,14 +6723,14 @@ function linkNodeModulesIfPresent(toplevel, worktreePath) {
|
|
|
6769
6723
|
if (hasDirectoryEntry(nodeModulesLinkPath)) return false;
|
|
6770
6724
|
let sourceRealPath;
|
|
6771
6725
|
try {
|
|
6772
|
-
if (!
|
|
6773
|
-
sourceRealPath =
|
|
6726
|
+
if (!fs15.statSync(nodeModulesPath).isDirectory()) throw new Error("source node_modules is not a directory");
|
|
6727
|
+
sourceRealPath = fs15.realpathSync.native(nodeModulesPath);
|
|
6774
6728
|
} catch (error) {
|
|
6775
6729
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") return false;
|
|
6776
6730
|
throw error;
|
|
6777
6731
|
}
|
|
6778
|
-
|
|
6779
|
-
if (!
|
|
6732
|
+
fs15.symlinkSync(nodeModulesPath, nodeModulesLinkPath, process.platform === "win32" ? "junction" : "dir");
|
|
6733
|
+
if (!fs15.lstatSync(nodeModulesLinkPath).isSymbolicLink() || fs15.realpathSync.native(nodeModulesLinkPath) !== sourceRealPath) {
|
|
6780
6734
|
throw new Error("created link does not resolve to the source node_modules");
|
|
6781
6735
|
}
|
|
6782
6736
|
return true;
|
|
@@ -6801,19 +6755,19 @@ function resolveWorktreeSetupHook(repoRoot, config) {
|
|
|
6801
6755
|
if (!hookPath) {
|
|
6802
6756
|
throw new Error("worktree setup hook path cannot be empty");
|
|
6803
6757
|
}
|
|
6804
|
-
const expandedHookPath = hookPath.startsWith("~/") ?
|
|
6758
|
+
const expandedHookPath = hookPath.startsWith("~/") ? path14.join(os2.homedir(), hookPath.slice(2)) : hookPath;
|
|
6805
6759
|
let resolvedPath;
|
|
6806
|
-
if (
|
|
6760
|
+
if (path14.isAbsolute(expandedHookPath)) {
|
|
6807
6761
|
resolvedPath = expandedHookPath;
|
|
6808
6762
|
} else if (expandedHookPath.includes("/") || expandedHookPath.includes("\\")) {
|
|
6809
|
-
resolvedPath =
|
|
6763
|
+
resolvedPath = path14.resolve(repoRoot, expandedHookPath);
|
|
6810
6764
|
} else {
|
|
6811
6765
|
throw new Error("worktree setup hook must be an absolute path or a repo-relative path");
|
|
6812
6766
|
}
|
|
6813
|
-
if (!
|
|
6767
|
+
if (!fs15.existsSync(resolvedPath)) {
|
|
6814
6768
|
throw new Error(`worktree setup hook not found: ${resolvedPath}`);
|
|
6815
6769
|
}
|
|
6816
|
-
if (
|
|
6770
|
+
if (fs15.statSync(resolvedPath).isDirectory()) {
|
|
6817
6771
|
throw new Error(`worktree setup hook must be a file, got directory: ${resolvedPath}`);
|
|
6818
6772
|
}
|
|
6819
6773
|
return {
|
|
@@ -6824,16 +6778,16 @@ function resolveWorktreeSetupHook(repoRoot, config) {
|
|
|
6824
6778
|
function normalizeSyntheticPath(worktreePath, rawPath) {
|
|
6825
6779
|
const trimmed = rawPath.trim();
|
|
6826
6780
|
if (!trimmed) throw new Error("synthetic path cannot be empty");
|
|
6827
|
-
if (
|
|
6828
|
-
const resolved2 =
|
|
6829
|
-
const relative4 =
|
|
6781
|
+
if (path14.isAbsolute(trimmed)) throw new Error(`synthetic path must be relative: ${rawPath}`);
|
|
6782
|
+
const resolved2 = path14.resolve(worktreePath, trimmed);
|
|
6783
|
+
const relative4 = path14.relative(worktreePath, resolved2);
|
|
6830
6784
|
if (!relative4 || relative4 === ".") {
|
|
6831
6785
|
throw new Error(`synthetic path cannot target the worktree root: ${rawPath}`);
|
|
6832
6786
|
}
|
|
6833
|
-
if (relative4 === ".." || relative4.startsWith(`..${
|
|
6787
|
+
if (relative4 === ".." || relative4.startsWith(`..${path14.sep}`) || path14.isAbsolute(relative4)) {
|
|
6834
6788
|
throw new Error(`synthetic path escapes the worktree root: ${rawPath}`);
|
|
6835
6789
|
}
|
|
6836
|
-
return
|
|
6790
|
+
return path14.normalize(relative4);
|
|
6837
6791
|
}
|
|
6838
6792
|
function parseWorktreeSetupHookOutput(rawStdout) {
|
|
6839
6793
|
const trimmed = rawStdout.trim();
|
|
@@ -6887,7 +6841,7 @@ async function runWorktreeSetupHook(tx, hook, input) {
|
|
|
6887
6841
|
}
|
|
6888
6842
|
}
|
|
6889
6843
|
async function finalizeCreatedWorktree(tx, toplevel, cwdRelative, runId, baseCommit, setupHook, agent, worktree) {
|
|
6890
|
-
const agentCwd = cwdRelative ?
|
|
6844
|
+
const agentCwd = cwdRelative ? path14.join(worktree.path, cwdRelative) : worktree.path;
|
|
6891
6845
|
tx.check();
|
|
6892
6846
|
const nodeModulesLinked = linkNodeModulesIfPresent(toplevel, worktree.path);
|
|
6893
6847
|
const syntheticPaths = nodeModulesLinked ? ["node_modules"] : [];
|
|
@@ -6914,7 +6868,7 @@ async function createNativeWorktree(tx, toplevel, cwdRelative, runId, index, bas
|
|
|
6914
6868
|
const branch = await tx.git(toplevel, ["show-ref", "--verify", "--quiet", `refs/heads/${naming.requestedBranch}`], [0, 1]);
|
|
6915
6869
|
let pathExists = false;
|
|
6916
6870
|
try {
|
|
6917
|
-
|
|
6871
|
+
fs15.lstatSync(worktreePath);
|
|
6918
6872
|
pathExists = true;
|
|
6919
6873
|
} catch (error) {
|
|
6920
6874
|
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") throw error;
|
|
@@ -6922,7 +6876,7 @@ async function createNativeWorktree(tx, toplevel, cwdRelative, runId, index, bas
|
|
|
6922
6876
|
if (branch.status !== 1 || pathExists) throw new Error(`worktree path or branch already exists: ${worktreePath}, ${naming.requestedBranch}`);
|
|
6923
6877
|
tx.attempt(index, naming.requestedBranch, worktreePath);
|
|
6924
6878
|
ensureProjectWorktreeDir(dedicatedRoot, toplevel);
|
|
6925
|
-
const recordedBaseDir = normalizeComparableCwd(
|
|
6879
|
+
const recordedBaseDir = normalizeComparableCwd(path14.dirname(worktreePath));
|
|
6926
6880
|
await tx.git(toplevel, ["worktree", "add", worktreePath, "-b", naming.requestedBranch, baseCommit]);
|
|
6927
6881
|
const worktree = {
|
|
6928
6882
|
path: worktreePath,
|
|
@@ -6962,11 +6916,11 @@ async function createWorktrunkWorktree(tx, toplevel, cwdRelative, runId, index,
|
|
|
6962
6916
|
if (output.action !== "created" || output.created_branch !== true || output.branch !== naming.requestedBranch || output.base_branch !== baseCommit) {
|
|
6963
6917
|
throw new Error("Worktrunk provisioning returned inconsistent creation metadata");
|
|
6964
6918
|
}
|
|
6965
|
-
if (typeof output.path !== "string" || !
|
|
6966
|
-
const worktreePathCandidate =
|
|
6919
|
+
if (typeof output.path !== "string" || !path14.isAbsolute(output.path)) throw new Error("Worktrunk provisioning returned a non-absolute worktree path");
|
|
6920
|
+
const worktreePathCandidate = path14.resolve(output.path);
|
|
6967
6921
|
let stat;
|
|
6968
6922
|
try {
|
|
6969
|
-
stat =
|
|
6923
|
+
stat = fs15.lstatSync(worktreePathCandidate);
|
|
6970
6924
|
} catch (error) {
|
|
6971
6925
|
throw new Error(`Worktrunk provisioning returned a missing worktree path: ${worktreePathCandidate}`, { cause: error instanceof Error ? error : void 0 });
|
|
6972
6926
|
}
|
|
@@ -6975,8 +6929,8 @@ async function createWorktrunkWorktree(tx, toplevel, cwdRelative, runId, index,
|
|
|
6975
6929
|
if (worktreePath === normalizeComparableCwd(toplevel)) throw new Error("Worktrunk provisioning returned the source checkout path");
|
|
6976
6930
|
const sourceCommonDirRaw = (await tx.gitChecked(toplevel, ["rev-parse", "--git-common-dir"])).trim();
|
|
6977
6931
|
const returnedCommonDirRaw = (await tx.gitChecked(worktreePath, ["rev-parse", "--git-common-dir"])).trim();
|
|
6978
|
-
const sourceCommonDir = normalizeComparableCwd(
|
|
6979
|
-
const returnedCommonDir = normalizeComparableCwd(
|
|
6932
|
+
const sourceCommonDir = normalizeComparableCwd(path14.isAbsolute(sourceCommonDirRaw) ? sourceCommonDirRaw : path14.resolve(toplevel, sourceCommonDirRaw));
|
|
6933
|
+
const returnedCommonDir = normalizeComparableCwd(path14.isAbsolute(returnedCommonDirRaw) ? returnedCommonDirRaw : path14.resolve(worktreePath, returnedCommonDirRaw));
|
|
6980
6934
|
if (returnedCommonDir !== sourceCommonDir) throw new Error("Worktrunk provisioning returned a worktree for a different repository");
|
|
6981
6935
|
const returnedBranch = (await tx.gitChecked(worktreePath, ["symbolic-ref", "--quiet", "--short", "HEAD"])).trim();
|
|
6982
6936
|
if (returnedBranch !== naming.requestedBranch) throw new Error("Worktrunk provisioning returned a worktree on a different branch");
|
|
@@ -6984,8 +6938,8 @@ async function createWorktrunkWorktree(tx, toplevel, cwdRelative, runId, index,
|
|
|
6984
6938
|
if (returnedHead !== baseCommit) throw new Error("Worktrunk provisioning returned a worktree at a different base commit");
|
|
6985
6939
|
const worktree = {
|
|
6986
6940
|
path: worktreePath,
|
|
6987
|
-
recordedBaseDir: normalizeComparableCwd(
|
|
6988
|
-
agentCwd: cwdRelative ?
|
|
6941
|
+
recordedBaseDir: normalizeComparableCwd(path14.dirname(worktreePath)),
|
|
6942
|
+
agentCwd: cwdRelative ? path14.join(worktreePath, cwdRelative) : worktreePath,
|
|
6989
6943
|
branch: naming.requestedBranch,
|
|
6990
6944
|
index,
|
|
6991
6945
|
nodeModulesLinked: false,
|
|
@@ -7002,28 +6956,28 @@ async function createWorktrunkWorktree(tx, toplevel, cwdRelative, runId, index,
|
|
|
7002
6956
|
}
|
|
7003
6957
|
function removeSyntheticPath(worktree, syntheticPath) {
|
|
7004
6958
|
assertWorktreeMutationAllowed();
|
|
7005
|
-
const resolved2 =
|
|
7006
|
-
const relative4 =
|
|
7007
|
-
if (!relative4 || relative4 === "." || relative4 === ".." || relative4.startsWith(`..${
|
|
6959
|
+
const resolved2 = path14.resolve(worktree.path, syntheticPath);
|
|
6960
|
+
const relative4 = path14.relative(worktree.path, resolved2);
|
|
6961
|
+
if (!relative4 || relative4 === "." || relative4 === ".." || relative4.startsWith(`..${path14.sep}`) || path14.isAbsolute(relative4)) {
|
|
7008
6962
|
return;
|
|
7009
6963
|
}
|
|
7010
6964
|
let stat;
|
|
7011
6965
|
try {
|
|
7012
|
-
stat =
|
|
6966
|
+
stat = fs15.lstatSync(resolved2);
|
|
7013
6967
|
} catch (error) {
|
|
7014
6968
|
const code = error && typeof error === "object" && "code" in error ? error.code : void 0;
|
|
7015
6969
|
if (code === "ENOENT") return;
|
|
7016
6970
|
throw error;
|
|
7017
6971
|
}
|
|
7018
6972
|
if (stat.isSymbolicLink()) {
|
|
7019
|
-
|
|
6973
|
+
fs15.unlinkSync(resolved2);
|
|
7020
6974
|
return;
|
|
7021
6975
|
}
|
|
7022
6976
|
if (stat.isDirectory()) {
|
|
7023
|
-
|
|
6977
|
+
fs15.rmSync(resolved2, { recursive: true, force: true });
|
|
7024
6978
|
return;
|
|
7025
6979
|
}
|
|
7026
|
-
|
|
6980
|
+
fs15.rmSync(resolved2, { force: true });
|
|
7027
6981
|
}
|
|
7028
6982
|
function removeSyntheticPathsBeforeDiff(worktree) {
|
|
7029
6983
|
if (worktree.syntheticPaths.length === 0) return;
|
|
@@ -7067,7 +7021,7 @@ function captureWorktreeDiff(setup, worktree, agent, patchPath) {
|
|
|
7067
7021
|
const diffStat = runGitChecked(worktree.path, ["diff", "--cached", ...MACHINE_DIFF_OPTIONS, "--stat", setup.baseCommit]).trim();
|
|
7068
7022
|
const patch = runGitChecked(worktree.path, ["diff", "--cached", ...MACHINE_PATCH_OPTIONS, setup.baseCommit]);
|
|
7069
7023
|
const numstat = runGitChecked(worktree.path, ["diff", "--cached", ...MACHINE_DIFF_OPTIONS, "--numstat", setup.baseCommit]);
|
|
7070
|
-
|
|
7024
|
+
fs15.writeFileSync(patchPath, patch, "utf-8");
|
|
7071
7025
|
if (!patch.trim()) {
|
|
7072
7026
|
return emptyDiff(worktree.index, agent, worktree.branch, patchPath);
|
|
7073
7027
|
}
|
|
@@ -7087,18 +7041,18 @@ function captureWorktreeDiff(setup, worktree, agent, patchPath) {
|
|
|
7087
7041
|
}
|
|
7088
7042
|
function writeEmptyPatch(patchPath) {
|
|
7089
7043
|
try {
|
|
7090
|
-
|
|
7044
|
+
fs15.writeFileSync(patchPath, "", "utf-8");
|
|
7091
7045
|
} catch {
|
|
7092
7046
|
}
|
|
7093
7047
|
}
|
|
7094
7048
|
function handoffRecordsPatch(manifestPath, patchPath) {
|
|
7095
|
-
if (!manifestPath || !
|
|
7049
|
+
if (!manifestPath || !fs15.existsSync(manifestPath)) return false;
|
|
7096
7050
|
try {
|
|
7097
|
-
const manifest = JSON.parse(
|
|
7051
|
+
const manifest = JSON.parse(fs15.readFileSync(manifestPath, "utf-8"));
|
|
7098
7052
|
if (manifest.version !== 1 || !Array.isArray(manifest.groups)) return false;
|
|
7099
|
-
const resolvedPatchPath =
|
|
7053
|
+
const resolvedPatchPath = path14.resolve(patchPath);
|
|
7100
7054
|
return manifest.groups.some((group) => Array.isArray(group.children) && group.children.some(
|
|
7101
|
-
(child) => child.patch?.error === void 0 && typeof child.patch?.path === "string" &&
|
|
7055
|
+
(child) => child.patch?.error === void 0 && typeof child.patch?.path === "string" && path14.resolve(child.patch.path) === resolvedPatchPath
|
|
7102
7056
|
));
|
|
7103
7057
|
} catch {
|
|
7104
7058
|
return false;
|
|
@@ -7152,9 +7106,9 @@ function cleanupSingleWorktree(setup, worktree, intent) {
|
|
|
7152
7106
|
const captured = (intent.capturedDiffs ?? setup.capturedDiffs)?.find((diff) => diff.index === worktree.index);
|
|
7153
7107
|
let patchValidationError;
|
|
7154
7108
|
let patchCaptured = false;
|
|
7155
|
-
if (captured !== void 0 && captured.error === void 0 &&
|
|
7109
|
+
if (captured !== void 0 && captured.error === void 0 && fs15.existsSync(captured.patchPath) && handoffRecordsPatch(intent.handoffManifestPath, captured.patchPath)) {
|
|
7156
7110
|
try {
|
|
7157
|
-
if (
|
|
7111
|
+
if (fs15.statSync(captured.patchPath).size > 0) {
|
|
7158
7112
|
patchValidationError = validateWorktreePatchRepresentsCurrentWorktree(worktree.path, setup.baseCommit, captured.patchPath);
|
|
7159
7113
|
patchCaptured = patchValidationError === void 0;
|
|
7160
7114
|
}
|
|
@@ -7303,7 +7257,7 @@ async function compensateSetup(tx) {
|
|
|
7303
7257
|
throw new Error(tx.progress.unknown);
|
|
7304
7258
|
}
|
|
7305
7259
|
await git(["worktree", "remove", "--force", attempt.path]);
|
|
7306
|
-
} else if (
|
|
7260
|
+
} else if (fs15.existsSync(attempt.path)) {
|
|
7307
7261
|
tx.unknown("Unregistered partial allocation retained");
|
|
7308
7262
|
throw new Error(tx.progress.unknown);
|
|
7309
7263
|
}
|
|
@@ -7423,7 +7377,7 @@ async function createWorktrees(cwd, runId, count, options = {}) {
|
|
|
7423
7377
|
function diffWorktrees(setup, agents, diffsDir) {
|
|
7424
7378
|
assertWorktreeMutationAllowed();
|
|
7425
7379
|
try {
|
|
7426
|
-
|
|
7380
|
+
fs15.mkdirSync(diffsDir, { recursive: true });
|
|
7427
7381
|
} catch {
|
|
7428
7382
|
return [];
|
|
7429
7383
|
}
|
|
@@ -7431,7 +7385,7 @@ function diffWorktrees(setup, agents, diffsDir) {
|
|
|
7431
7385
|
for (let index = 0; index < setup.worktrees.length; index++) {
|
|
7432
7386
|
const worktree = setup.worktrees[index];
|
|
7433
7387
|
const agent = agents[index] ?? `task-${index + 1}`;
|
|
7434
|
-
const patchPath =
|
|
7388
|
+
const patchPath = path14.join(diffsDir, `task-${index}-${safePatchAgentName(agent)}.patch`);
|
|
7435
7389
|
try {
|
|
7436
7390
|
diffs.push(captureWorktreeDiff(setup, worktree, agent, patchPath));
|
|
7437
7391
|
} catch (error) {
|
|
@@ -7481,11 +7435,94 @@ function formatWorktreeDiffSummary(diffs) {
|
|
|
7481
7435
|
}
|
|
7482
7436
|
lines.push("");
|
|
7483
7437
|
}
|
|
7484
|
-
const patchesDir =
|
|
7438
|
+
const patchesDir = path14.dirname(changed[0].patchPath);
|
|
7485
7439
|
lines.push(`Full patches: ${patchesDir}`);
|
|
7486
7440
|
return lines.join("\n").trimEnd();
|
|
7487
7441
|
}
|
|
7488
7442
|
|
|
7443
|
+
// src/runs/background/workflow-terminal-proof.ts
|
|
7444
|
+
import * as fs16 from "node:fs";
|
|
7445
|
+
import * as path15 from "node:path";
|
|
7446
|
+
var TERMINAL_WORKFLOW_STATES = /* @__PURE__ */ new Set(["completed", "failed", "stopped"]);
|
|
7447
|
+
function readWorkflowChildRunModel(workflowAsyncDir, step) {
|
|
7448
|
+
if (step.async !== true || typeof step.runId !== "string" || path15.basename(step.runId) !== step.runId) return void 0;
|
|
7449
|
+
try {
|
|
7450
|
+
const child = readStatus(path15.join(path15.dirname(workflowAsyncDir), step.runId));
|
|
7451
|
+
const first = Array.isArray(child?.steps) ? child.steps[0] : void 0;
|
|
7452
|
+
const model = typeof first?.model === "string" && first.model ? first.model : void 0;
|
|
7453
|
+
const thinking = typeof first?.thinking === "string" && first.thinking ? first.thinking : void 0;
|
|
7454
|
+
return model || thinking ? { model, thinking } : void 0;
|
|
7455
|
+
} catch {
|
|
7456
|
+
return void 0;
|
|
7457
|
+
}
|
|
7458
|
+
}
|
|
7459
|
+
function withWorkflowChildRunModel(workflowAsyncDir, child) {
|
|
7460
|
+
if (child.model && child.thinking) return child;
|
|
7461
|
+
const reported = readWorkflowChildRunModel(workflowAsyncDir, { async: true, runId: child.runId });
|
|
7462
|
+
const model = child.model ?? reported?.model;
|
|
7463
|
+
const thinking = child.thinking ?? reported?.thinking;
|
|
7464
|
+
return { ...child, ...model ? { model } : {}, ...thinking ? { thinking } : {} };
|
|
7465
|
+
}
|
|
7466
|
+
function readWorkflowChildProcessEvidence(workflowAsyncDir, steps) {
|
|
7467
|
+
if (!steps) return { state: "unknown", reason: "workflow child roster is missing" };
|
|
7468
|
+
const children = [];
|
|
7469
|
+
for (const step of steps) {
|
|
7470
|
+
const child = readWorkflowChildEvidence(workflowAsyncDir, step);
|
|
7471
|
+
if (!child) continue;
|
|
7472
|
+
if (child.state !== "resolved") return { state: child.state, reason: child.reason };
|
|
7473
|
+
children.push(child.proof);
|
|
7474
|
+
}
|
|
7475
|
+
return { state: "observed", children };
|
|
7476
|
+
}
|
|
7477
|
+
function launchFailedBeforeRunner(step, childDir) {
|
|
7478
|
+
if (step.status !== "failed" || !step.error) return false;
|
|
7479
|
+
return !childDir || !["process-terminal.json", "runner-startup.json"].some((file) => fs16.existsSync(path15.join(childDir, file)));
|
|
7480
|
+
}
|
|
7481
|
+
function readWorkflowChildEvidence(workflowAsyncDir, step) {
|
|
7482
|
+
const label = step.workflowKey ?? step.agent;
|
|
7483
|
+
if (typeof step.async !== "boolean") return { state: "unknown", reason: `workflow child ${label} is missing async classification` };
|
|
7484
|
+
if (!step.async) return void 0;
|
|
7485
|
+
if (!step.runId || path15.basename(step.runId) !== step.runId) return { state: "unknown", reason: `async workflow child ${label} is missing run id` };
|
|
7486
|
+
const childDir = path15.join(path15.dirname(workflowAsyncDir), step.runId);
|
|
7487
|
+
if (!fs16.existsSync(childDir)) return launchFailedBeforeRunner(step) ? void 0 : { state: "unknown", reason: `async workflow child ${label} directory is missing` };
|
|
7488
|
+
const childStatus = readStatus(childDir);
|
|
7489
|
+
if (!childStatus) return launchFailedBeforeRunner(step, childDir) ? void 0 : { state: "unknown", reason: `async workflow child ${label} status is missing or unreadable` };
|
|
7490
|
+
if (!isTerminalAsyncState(childStatus.state)) return { state: "pending", reason: `async workflow child ${label} is still ${childStatus.state}` };
|
|
7491
|
+
const recorded = childStatus.processTerminal;
|
|
7492
|
+
if (!recorded?.runnerProcessInstanceId) return { state: "unknown", reason: `async workflow child ${label} has no runner process identity` };
|
|
7493
|
+
if (recorded.state === "not-started" && recorded.runId === step.runId && typeof childStatus.error === "string" && childStatus.error) {
|
|
7494
|
+
return { state: "resolved", proof: recorded };
|
|
7495
|
+
}
|
|
7496
|
+
settleUnobservedRunnerExit(childDir, childStatus);
|
|
7497
|
+
const proof = readProcessTerminal(childDir, { runId: step.runId, runnerProcessInstanceId: recorded.runnerProcessInstanceId });
|
|
7498
|
+
if (proof?.state !== "observed" || proof.runId !== step.runId) {
|
|
7499
|
+
const proofState = proof?.state ?? "missing";
|
|
7500
|
+
const bound = childStatus.runId === step.runId && typeof recorded.runnerProcessInstanceId === "string";
|
|
7501
|
+
return {
|
|
7502
|
+
state: !proof || proof.state === "pending" ? "pending" : "unknown",
|
|
7503
|
+
reason: `async workflow child ${label} process-terminal proof is ${proofState}${proof?.state === "unknown" && proof.reason ? ` (${proof.reason})` : ""}`,
|
|
7504
|
+
...bound ? { unresolvedProof: { status: childStatus, proofState } } : {}
|
|
7505
|
+
};
|
|
7506
|
+
}
|
|
7507
|
+
return { state: "resolved", proof };
|
|
7508
|
+
}
|
|
7509
|
+
function unresolved(runId, state, dispatchClosed, reason) {
|
|
7510
|
+
return { version: 1, kind: "workflow", runId, state, dispatchClosed, reason };
|
|
7511
|
+
}
|
|
7512
|
+
function readWorkflowTerminalProof(asyncDir, steps, summary, hostCommandCount, closedAt) {
|
|
7513
|
+
const runId = summary.workflowRunId;
|
|
7514
|
+
if (!summary.inventoryComplete || !TERMINAL_WORKFLOW_STATES.has(summary.workflowState)) {
|
|
7515
|
+
return unresolved(runId, "pending", false, "Workflow dispatch is still open.");
|
|
7516
|
+
}
|
|
7517
|
+
if (hostCommandCount > 0) {
|
|
7518
|
+
return unresolved(runId, "unknown", true, "Workflow host commands have no process-terminal proof.");
|
|
7519
|
+
}
|
|
7520
|
+
const evidence = readWorkflowChildProcessEvidence(asyncDir, steps);
|
|
7521
|
+
if (evidence.state !== "observed") return unresolved(runId, evidence.state, true, evidence.reason);
|
|
7522
|
+
const observedAt = Math.max(closedAt, ...evidence.children.map((child) => child.state === "observed" ? child.observedAt : 0));
|
|
7523
|
+
return { version: 1, kind: "workflow", runId, state: "observed", dispatchClosed: true, observedAt, children: evidence.children };
|
|
7524
|
+
}
|
|
7525
|
+
|
|
7489
7526
|
// src/shared/model-response-aliases.ts
|
|
7490
7527
|
function validateModelResponseAliases(value, label = "config.modelResponseAliases") {
|
|
7491
7528
|
if (value === void 0) return;
|
|
@@ -7510,6 +7547,7 @@ export {
|
|
|
7510
7547
|
ACTIVE_RUN_INDEX_DIR,
|
|
7511
7548
|
DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS,
|
|
7512
7549
|
isActiveAsyncState,
|
|
7550
|
+
isTerminalAsyncState,
|
|
7513
7551
|
releaseActiveRunIndex,
|
|
7514
7552
|
updateActiveRunIndex,
|
|
7515
7553
|
activeRunMarkerAgeMs,
|
|
@@ -7518,6 +7556,7 @@ export {
|
|
|
7518
7556
|
processTerminalCandidatePath,
|
|
7519
7557
|
readProcessTerminalCandidate,
|
|
7520
7558
|
processTerminalPath,
|
|
7559
|
+
unobservedRunnerExitPath,
|
|
7521
7560
|
initializeProcessTerminal,
|
|
7522
7561
|
sanitizeProcessTerminal,
|
|
7523
7562
|
readProcessTerminal,
|
|
@@ -7626,16 +7665,15 @@ export {
|
|
|
7626
7665
|
WORKFLOW_STOP_CAUSE_RUNTIME_REPLACED,
|
|
7627
7666
|
WORKFLOW_STOP_CAUSE_OWNER_EXITED,
|
|
7628
7667
|
isReusableWorkflowStopCause,
|
|
7629
|
-
isTerminalAsyncState,
|
|
7630
|
-
withWorkflowChildRunModel,
|
|
7631
|
-
readWorkflowChildProcessEvidence,
|
|
7632
|
-
readWorkflowChildEvidence,
|
|
7633
|
-
readWorkflowTerminalProof,
|
|
7634
7668
|
reconcileNestedAsyncDescendants,
|
|
7635
7669
|
checkPidLiveness,
|
|
7636
7670
|
isRecordedPid,
|
|
7637
7671
|
checkRecordedPidLiveness,
|
|
7638
7672
|
reconcileAsyncRun,
|
|
7673
|
+
withWorkflowChildRunModel,
|
|
7674
|
+
readWorkflowChildProcessEvidence,
|
|
7675
|
+
readWorkflowChildEvidence,
|
|
7676
|
+
readWorkflowTerminalProof,
|
|
7639
7677
|
resolveAuthorityDecision,
|
|
7640
7678
|
validateAuthorityPolicy,
|
|
7641
7679
|
WORKTREE_AGENT_CWD_PLACEHOLDER,
|