@ashx-j/lunr-dev 0.2.40-dev.55.1 → 0.2.40-dev.58.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builtin-extensions/pi-subagents/src/runs/background/attempt-usage.d.ts +5 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/attempt-usage.js +31 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/child-stream.d.ts +65 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/child-stream.js +456 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/parallel-group-status.d.ts +42 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/parallel-group-status.js +79 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/run-log.d.ts +18 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/run-log.js +43 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/runner-event-log.d.ts +3 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/runner-event-log.js +70 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/runner-single-step.d.ts +92 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/runner-single-step.js +491 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/runner-status.d.ts +64 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/runner-status.js +26 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts +1 -115
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js +17 -1160
- package/dist/core/credential-files.d.ts +3 -2
- package/dist/core/credential-files.js +10 -4
- package/dist/core/permissions.d.ts +6 -0
- package/dist/core/permissions.js +6 -0
- package/dist/core/tool-call-hooks.js +3 -2
- package/dist/node-runtime/{acp-mode-CFYSYACH.js → acp-mode-5KZPFZBO.js} +2 -2
- package/dist/node-runtime/{agent-session-services-3ZHQJIKF.js → agent-session-services-KH5CIGC3.js} +5 -5
- package/dist/node-runtime/{builtin-extensions-YJ7F6GND.js → builtin-extensions-RZS4SMIS.js} +3 -3
- package/dist/node-runtime/{chunk-5HVA5ECB.js → chunk-AKQRASEH.js} +9 -9
- package/dist/node-runtime/{chunk-4ZEDT3YW.js → chunk-BJXBM6KD.js} +3 -3
- package/dist/node-runtime/{chunk-BNNBTBXY.js → chunk-EJMB4PAV.js} +3 -3
- package/dist/node-runtime/{chunk-HVXDYQNN.js → chunk-JI7AUY2T.js} +1 -1
- package/dist/node-runtime/{chunk-ITVBE3HR.js → chunk-JJTHGEUS.js} +5 -4
- package/dist/node-runtime/{chunk-3UQ7ZNLI.js → chunk-K24P7GMM.js} +7 -7
- package/dist/node-runtime/{chunk-KTCZH72R.js → chunk-LGRRFSE7.js} +3 -2
- package/dist/node-runtime/{chunk-7LCR56AK.js → chunk-NWYFKXP5.js} +1 -1
- package/dist/node-runtime/{chunk-SV42POA3.js → chunk-PGWSMQ4K.js} +1 -1
- package/dist/node-runtime/{chunk-YDMZHLBV.js → chunk-QX5I7QEW.js} +1 -1
- package/dist/node-runtime/{chunk-BNZXW77G.js → chunk-RXDLSXEC.js} +1 -1
- package/dist/node-runtime/{chunk-N574FRFF.js → chunk-TSZESZ6H.js} +2 -2
- package/dist/node-runtime/{chunk-CDILDA4F.js → chunk-U7MTVVT3.js} +2 -2
- package/dist/node-runtime/{chunk-G3PARFR4.js → chunk-UTZCCNFC.js} +5 -5
- package/dist/node-runtime/{chunk-U2LTTIWZ.js → chunk-WYJUGRVE.js} +1 -1
- package/dist/node-runtime/{chunk-7LNPTBQJ.js → chunk-XPKOWSYN.js} +6 -2
- package/dist/node-runtime/{chunk-2ZI6Q6JG.js → chunk-YFXGOLZ6.js} +1 -1
- package/dist/node-runtime/{command-H52R5R2G.js → command-6S6C62CX.js} +1 -1
- package/dist/node-runtime/{commands-7EETGZ7V.js → commands-GSZWAQJW.js} +5 -5
- package/dist/node-runtime/{commands-CV2JUYHM.js → commands-MM2TPV5I.js} +4 -4
- package/dist/node-runtime/{direct-tool-executor-DNZ2MS6Z.js → direct-tool-executor-WJLVHH7U.js} +6 -6
- package/dist/node-runtime/{gateway-OHPDCOOB.js → gateway-CWIWPUVC.js} +6 -6
- package/dist/node-runtime/index.js +10 -10
- package/dist/node-runtime/{init-G23PFPKF.js → init-P3RQ6EFK.js} +5 -5
- package/dist/node-runtime/{interactive-mode-7GX3UJFX.js → interactive-mode-2L5JMVKQ.js} +6 -6
- package/dist/node-runtime/{lunr-cron-SV2EXYKV.js → lunr-cron-LT3O64NO.js} +4 -4
- package/dist/node-runtime/main.js +7 -7
- package/dist/node-runtime/{mobile-commands-JQJU35OT.js → mobile-commands-PFXEWP2R.js} +3 -3
- package/dist/node-runtime/{pi-mcp-adapter-NKAL5CFR.js → pi-mcp-adapter-2OP5BBC6.js} +8 -8
- package/dist/node-runtime/{pi-subagents-WS6OU5MG.js → pi-subagents-G2T5XRAX.js} +6 -6
- package/dist/node-runtime/{print-mode-Y363FXY4.js → print-mode-S6ZUVPMU.js} +6 -6
- package/dist/node-runtime/{proxy-modes-EEYRUGQL.js → proxy-modes-RD2PQ6UH.js} +6 -6
- package/dist/node-runtime/rpc-entry.js +7 -7
- package/dist/node-runtime/{rpc-mode-ENVT7AXW.js → rpc-mode-C33WERBG.js} +3 -3
- package/dist/node-runtime/{src-Y3S2FIS5.js → src-J6FSKIFT.js} +1 -1
- package/dist/node-runtime/{subagent-executor-LPVOWPMG.js → subagent-executor-RTGKJ35C.js} +5 -5
- package/install-lock/package-lock.json +24 -24
- package/install-lock/package.json +2 -2
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Usage, ModelAttempt, TokenUsage, CostSummary } from "../../shared/types.ts";
|
|
2
|
+
export declare function emptyUsage(): Required<Usage>;
|
|
3
|
+
export declare function tokenUsageFromAttempts(attempts: ModelAttempt[] | undefined): TokenUsage | null;
|
|
4
|
+
export declare function costSummaryFromAttempts(attempts: ModelAttempt[] | undefined): CostSummary | undefined;
|
|
5
|
+
//# sourceMappingURL=attempt-usage.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { tokenUsageFromUsage } from "../../shared/session-tokens.js";
|
|
2
|
+
export function emptyUsage() {
|
|
3
|
+
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0, unknownRequests: 0, partialRequests: 0, unknownCosts: 0 };
|
|
4
|
+
}
|
|
5
|
+
export function tokenUsageFromAttempts(attempts) {
|
|
6
|
+
if (!attempts?.some((attempt) => attempt.usage))
|
|
7
|
+
return null;
|
|
8
|
+
const usage = emptyUsage();
|
|
9
|
+
for (const attempt of attempts)
|
|
10
|
+
if (attempt.usage) {
|
|
11
|
+
for (const key of Object.keys(usage))
|
|
12
|
+
usage[key] += attempt.usage[key] ?? 0;
|
|
13
|
+
}
|
|
14
|
+
return tokenUsageFromUsage(usage);
|
|
15
|
+
}
|
|
16
|
+
export function costSummaryFromAttempts(attempts) {
|
|
17
|
+
if (!attempts || attempts.length === 0)
|
|
18
|
+
return undefined;
|
|
19
|
+
let inputTokens = 0;
|
|
20
|
+
let outputTokens = 0;
|
|
21
|
+
let costUsd = 0;
|
|
22
|
+
for (const attempt of attempts) {
|
|
23
|
+
inputTokens += (attempt.usage?.input ?? 0) + (attempt.usage?.cacheRead ?? 0) + (attempt.usage?.cacheWrite ?? 0);
|
|
24
|
+
outputTokens += attempt.usage?.output ?? 0;
|
|
25
|
+
costUsd += attempt.usage?.cost ?? 0;
|
|
26
|
+
}
|
|
27
|
+
return inputTokens > 0 || outputTokens > 0 || costUsd > 0
|
|
28
|
+
? { inputTokens, outputTokens, costUsd }
|
|
29
|
+
: undefined;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=attempt-usage.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Message } from "@ashx-j/lunr-ai";
|
|
2
|
+
import type { ChildTranscriptWriter } from "../../shared/child-transcript.ts";
|
|
3
|
+
import { type Usage, type TurnBudgetState, type ToolBudgetState } from "../../shared/types.ts";
|
|
4
|
+
import { type ProtocolOutputLimit } from "../shared/child-protocol.ts";
|
|
5
|
+
import { type ChildWatchdogStateSnapshot } from "../../watchdog/child-status.ts";
|
|
6
|
+
export declare function isTerminalAssistantStop(message: Message): boolean;
|
|
7
|
+
interface ChildEventContext {
|
|
8
|
+
eventsPath: string;
|
|
9
|
+
runId: string;
|
|
10
|
+
stepIndex: number;
|
|
11
|
+
agent: string;
|
|
12
|
+
}
|
|
13
|
+
interface ChildUsage {
|
|
14
|
+
measurement?: "reported" | "partial" | "estimated" | "unknown";
|
|
15
|
+
costSource?: "reported" | "estimated" | "unknown";
|
|
16
|
+
input?: number;
|
|
17
|
+
inputTokens?: number;
|
|
18
|
+
output?: number;
|
|
19
|
+
outputTokens?: number;
|
|
20
|
+
cacheRead?: number;
|
|
21
|
+
cacheWrite?: number;
|
|
22
|
+
cost?: {
|
|
23
|
+
total?: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
type ChildMessage = Message & {
|
|
27
|
+
model?: string;
|
|
28
|
+
errorMessage?: string;
|
|
29
|
+
usage?: ChildUsage;
|
|
30
|
+
};
|
|
31
|
+
export interface ChildEvent {
|
|
32
|
+
type?: string;
|
|
33
|
+
message?: ChildMessage;
|
|
34
|
+
toolName?: string;
|
|
35
|
+
args?: Record<string, unknown>;
|
|
36
|
+
willRetry?: unknown;
|
|
37
|
+
}
|
|
38
|
+
export interface RunPiStreamingResult {
|
|
39
|
+
stderr: string;
|
|
40
|
+
exitCode: number | null;
|
|
41
|
+
messages: Message[];
|
|
42
|
+
usage: Usage;
|
|
43
|
+
model?: string;
|
|
44
|
+
error?: string;
|
|
45
|
+
protocolError?: ProtocolOutputLimit;
|
|
46
|
+
finalOutput: string;
|
|
47
|
+
interrupted?: boolean;
|
|
48
|
+
timedOut?: boolean;
|
|
49
|
+
stopped?: boolean;
|
|
50
|
+
turnBudget?: TurnBudgetState;
|
|
51
|
+
turnBudgetExceeded?: boolean;
|
|
52
|
+
wrapUpRequested?: boolean;
|
|
53
|
+
toolBudget?: ToolBudgetState;
|
|
54
|
+
toolBudgetBlocked?: boolean;
|
|
55
|
+
observedMutationAttempt?: boolean;
|
|
56
|
+
watchdog?: ChildWatchdogStateSnapshot;
|
|
57
|
+
}
|
|
58
|
+
export declare function runPiStreaming(args: string[], cwd: string, outputFile: string, env?: Record<string, string | undefined>, piPackageRoot?: string, piArgv1?: string, maxSubagentDepth?: number, childEventContext?: ChildEventContext, registerInterrupt?: (interrupt: (() => void) | undefined) => void, onChildEvent?: (event: ChildEvent) => void, transcriptWriter?: ChildTranscriptWriter, registerTimeout?: (interrupt: (() => void) | undefined) => void, timeoutMessage?: string, registerStop?: (stop: (() => void) | undefined) => void, stopMessage?: string, registerTurnBudgetAbort?: (abort: ((message: string, state?: TurnBudgetState) => void) | undefined) => void, onWriterProcess?: (writer: {
|
|
59
|
+
state: "none" | "spawning";
|
|
60
|
+
} | {
|
|
61
|
+
state: "running";
|
|
62
|
+
pid: number;
|
|
63
|
+
}) => void): Promise<RunPiStreamingResult>;
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=child-stream.d.ts.map
|
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
// Spawns one lunR child in json mode and reads its event stream into a result: messages, usage, budgets,
|
|
2
|
+
// interrupts, protocol limits and watchdog state.
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import { getPiSpawnCommand } from "../shared/pi-spawn.js";
|
|
6
|
+
import { getSubagentDepthEnv } from "../../shared/types.js";
|
|
7
|
+
import { trySignalChild, attachPostExitStdioGuard } from "../../shared/post-exit-stdio-guard.js";
|
|
8
|
+
import { extractToolArgsPreview, extractTextFromContent, getFinalOutput } from "../../shared/utils.js";
|
|
9
|
+
import { isMutatingTool } from "../shared/long-running-guard.js";
|
|
10
|
+
import { createBoundedByteTail, projectChildLifecycle, formatProtocolOutputLimit, createBoundedLineReader, MAX_CHILD_STDERR_BYTES } from "../shared/child-protocol.js";
|
|
11
|
+
import { createChildEventDecoder } from "../../../../../core/subagent-event-transport.js";
|
|
12
|
+
import { decodeChildWatchdogConfig, CHILD_WATCHDOG_CONFIG_ENV, isChildWatchdogStatusEvent, acceptChildWatchdogEvent, childWatchdogIsActive } from "../../watchdog/child-status.js";
|
|
13
|
+
import { emptyUsage } from "./attempt-usage.js";
|
|
14
|
+
import { appendDiagnosticJsonl } from "./runner-event-log.js";
|
|
15
|
+
function shouldPersistChildEvent(event) {
|
|
16
|
+
return event.type !== "message_update";
|
|
17
|
+
}
|
|
18
|
+
export function isTerminalAssistantStop(message) {
|
|
19
|
+
const stopReason = message.stopReason;
|
|
20
|
+
const hasToolCall = Array.isArray(message.content)
|
|
21
|
+
&& message.content.some((part) => part.type === "toolCall");
|
|
22
|
+
return stopReason === "stop" && !hasToolCall;
|
|
23
|
+
}
|
|
24
|
+
export function runPiStreaming(args, cwd, outputFile, env, piPackageRoot, piArgv1, maxSubagentDepth, childEventContext, registerInterrupt, onChildEvent, transcriptWriter, registerTimeout, timeoutMessage, registerStop, stopMessage, registerTurnBudgetAbort, onWriterProcess) {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
onWriterProcess?.({ state: "spawning" });
|
|
27
|
+
const outputStream = fs.createWriteStream(outputFile, { flags: "w" });
|
|
28
|
+
const spawnEnv = { ...process.env, ...(env ?? {}), ...getSubagentDepthEnv(maxSubagentDepth) };
|
|
29
|
+
const spawnSpec = getPiSpawnCommand(args, {
|
|
30
|
+
...(piPackageRoot ? { piPackageRoot } : {}),
|
|
31
|
+
...(piArgv1 ? { argv1: piArgv1 } : {}),
|
|
32
|
+
});
|
|
33
|
+
const child = spawn(spawnSpec.command, spawnSpec.args, {
|
|
34
|
+
cwd,
|
|
35
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
36
|
+
env: spawnEnv,
|
|
37
|
+
windowsHide: true,
|
|
38
|
+
});
|
|
39
|
+
const stderrTail = createBoundedByteTail();
|
|
40
|
+
const rawStdoutTail = createBoundedByteTail();
|
|
41
|
+
const messages = [];
|
|
42
|
+
const usage = emptyUsage();
|
|
43
|
+
let model;
|
|
44
|
+
let writerRegistrationError;
|
|
45
|
+
if (typeof child.pid === "number") {
|
|
46
|
+
try {
|
|
47
|
+
onWriterProcess?.({ state: "running", pid: child.pid });
|
|
48
|
+
}
|
|
49
|
+
catch (writerError) {
|
|
50
|
+
writerRegistrationError = `Failed to record revived Pi writer ownership: ${writerError instanceof Error ? writerError.message : String(writerError)}`;
|
|
51
|
+
trySignalChild(child, "SIGKILL");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let error = writerRegistrationError;
|
|
55
|
+
let assistantError;
|
|
56
|
+
let interrupted = false;
|
|
57
|
+
let timedOut = false;
|
|
58
|
+
let stopped = false;
|
|
59
|
+
let turnBudgetExceeded = false;
|
|
60
|
+
let turnBudgetMessage;
|
|
61
|
+
let turnBudget;
|
|
62
|
+
let observedMutationAttempt = false;
|
|
63
|
+
const childWatchdogConfig = decodeChildWatchdogConfig(env?.[CHILD_WATCHDOG_CONFIG_ENV]);
|
|
64
|
+
let childWatchdogState;
|
|
65
|
+
let applyChildLifecycle = (_action) => { };
|
|
66
|
+
const updateChildWatchdogState = (snapshot) => {
|
|
67
|
+
childWatchdogState = snapshot;
|
|
68
|
+
};
|
|
69
|
+
const writeOutputLine = (line) => {
|
|
70
|
+
if (!line.trim())
|
|
71
|
+
return;
|
|
72
|
+
outputStream.write(`${line}\n`);
|
|
73
|
+
};
|
|
74
|
+
const writeOutputText = (text) => {
|
|
75
|
+
for (const line of text.split("\n")) {
|
|
76
|
+
writeOutputLine(line);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const appendChildEvent = (event) => {
|
|
80
|
+
if (!childEventContext)
|
|
81
|
+
return;
|
|
82
|
+
if (!shouldPersistChildEvent(event))
|
|
83
|
+
return;
|
|
84
|
+
appendDiagnosticJsonl(childEventContext.eventsPath, JSON.stringify({
|
|
85
|
+
...event,
|
|
86
|
+
subagentSource: "child",
|
|
87
|
+
subagentRunId: childEventContext.runId,
|
|
88
|
+
subagentStepIndex: childEventContext.stepIndex,
|
|
89
|
+
subagentAgent: childEventContext.agent,
|
|
90
|
+
observedAt: Date.now(),
|
|
91
|
+
}), typeof event.type === "string" ? event.type : undefined);
|
|
92
|
+
};
|
|
93
|
+
const appendChildLine = (type, line) => {
|
|
94
|
+
appendChildEvent({ type, line });
|
|
95
|
+
if (type === "subagent.child.stdout")
|
|
96
|
+
transcriptWriter?.writeStdoutLine(line);
|
|
97
|
+
else
|
|
98
|
+
transcriptWriter?.writeStderrLine(line);
|
|
99
|
+
};
|
|
100
|
+
const decodeChildEvent = createChildEventDecoder();
|
|
101
|
+
const processStdoutLine = (line) => {
|
|
102
|
+
if (!line.trim())
|
|
103
|
+
return;
|
|
104
|
+
let event;
|
|
105
|
+
try {
|
|
106
|
+
const assembled = decodeChildEvent(line);
|
|
107
|
+
if (assembled === undefined)
|
|
108
|
+
return;
|
|
109
|
+
event = JSON.parse(assembled);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
rawStdoutTail.push(`${line}\n`);
|
|
113
|
+
writeOutputLine(line);
|
|
114
|
+
appendChildLine("subagent.child.stdout", line);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
appendChildEvent(event);
|
|
118
|
+
transcriptWriter?.writeChildEvent(event);
|
|
119
|
+
if (event.type === "agent_settled")
|
|
120
|
+
agentSettledReceived = true;
|
|
121
|
+
applyChildLifecycle(projectChildLifecycle(event));
|
|
122
|
+
if (isChildWatchdogStatusEvent(event)) {
|
|
123
|
+
if (!childWatchdogConfig)
|
|
124
|
+
return;
|
|
125
|
+
const next = acceptChildWatchdogEvent({
|
|
126
|
+
current: childWatchdogState,
|
|
127
|
+
event,
|
|
128
|
+
runId: childEventContext?.runId,
|
|
129
|
+
agent: childEventContext?.agent,
|
|
130
|
+
childIndex: childEventContext?.stepIndex,
|
|
131
|
+
});
|
|
132
|
+
if (!next)
|
|
133
|
+
return;
|
|
134
|
+
updateChildWatchdogState(next);
|
|
135
|
+
onChildEvent?.(event);
|
|
136
|
+
if (childWatchdogIsActive(next)) {
|
|
137
|
+
if (finalDrainTimer) {
|
|
138
|
+
clearTimeout(finalDrainTimer);
|
|
139
|
+
finalDrainTimer = undefined;
|
|
140
|
+
}
|
|
141
|
+
if (finalHardKillTimer) {
|
|
142
|
+
clearTimeout(finalHardKillTimer);
|
|
143
|
+
finalHardKillTimer = undefined;
|
|
144
|
+
}
|
|
145
|
+
armWatchdogTail();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
clearWatchdogTailTimer();
|
|
149
|
+
if (cleanTerminalAssistantStopReceived || agentSettledReceived)
|
|
150
|
+
startFinalDrain();
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
onChildEvent?.(event);
|
|
155
|
+
if (event.type === "tool_execution_start" && event.toolName) {
|
|
156
|
+
observedMutationAttempt = observedMutationAttempt || isMutatingTool(event.toolName, event.args);
|
|
157
|
+
const toolArgs = extractToolArgsPreview(event.args ?? {});
|
|
158
|
+
writeOutputLine(toolArgs ? `${event.toolName}: ${toolArgs}` : event.toolName);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if ((event.type === "message_end" || event.type === "tool_result_end") && event.message) {
|
|
162
|
+
messages.push(event.message);
|
|
163
|
+
const text = extractTextFromContent(event.message.content);
|
|
164
|
+
if (text)
|
|
165
|
+
writeOutputText(text);
|
|
166
|
+
if (event.type !== "message_end" || event.message.role !== "assistant")
|
|
167
|
+
return;
|
|
168
|
+
if (event.message.model)
|
|
169
|
+
model = event.message.model;
|
|
170
|
+
if (event.message.errorMessage)
|
|
171
|
+
assistantError = event.message.errorMessage;
|
|
172
|
+
const eventUsage = event.message.usage;
|
|
173
|
+
if (eventUsage) {
|
|
174
|
+
usage.turns++;
|
|
175
|
+
usage.input += eventUsage.input ?? eventUsage.inputTokens ?? 0;
|
|
176
|
+
usage.output += eventUsage.output ?? eventUsage.outputTokens ?? 0;
|
|
177
|
+
usage.cacheRead += eventUsage.cacheRead ?? 0;
|
|
178
|
+
usage.cacheWrite += eventUsage.cacheWrite ?? 0;
|
|
179
|
+
usage.cost += eventUsage.cost?.total ?? 0;
|
|
180
|
+
usage.unknownRequests += Number(eventUsage.measurement === "unknown");
|
|
181
|
+
usage.partialRequests += Number(eventUsage.measurement === "partial");
|
|
182
|
+
usage.unknownCosts += Number(eventUsage.costSource === "unknown");
|
|
183
|
+
}
|
|
184
|
+
if (isTerminalAssistantStop(event.message)) {
|
|
185
|
+
if (!event.message.errorMessage && extractTextFromContent(event.message.content).trim())
|
|
186
|
+
assistantError = undefined;
|
|
187
|
+
cleanTerminalAssistantStopReceived ||= !event.message.errorMessage;
|
|
188
|
+
applyChildLifecycle(projectChildLifecycle(event, true));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
// Guard both cases that can leave the parent waiting on `close` forever:
|
|
193
|
+
// a lingering stdio holder after `exit`, or a child that never exits.
|
|
194
|
+
const FINAL_STOP_GRACE_MS = 1000;
|
|
195
|
+
const HARD_KILL_MS = 3000;
|
|
196
|
+
const TIMEOUT_HARD_KILL_MS = 3000;
|
|
197
|
+
let childExited = false;
|
|
198
|
+
let forcedTerminationSignal = false;
|
|
199
|
+
let cleanTerminalAssistantStopReceived = false;
|
|
200
|
+
let agentSettledReceived = false;
|
|
201
|
+
let finalDrainTimer;
|
|
202
|
+
let finalHardKillTimer;
|
|
203
|
+
let watchdogTailTimer;
|
|
204
|
+
let timeoutHardKillTimer;
|
|
205
|
+
let turnBudgetTerminationTimer;
|
|
206
|
+
let turnBudgetHardKillTimer;
|
|
207
|
+
let protocolHardKillTimer;
|
|
208
|
+
let protocolError;
|
|
209
|
+
let settled = false;
|
|
210
|
+
applyChildLifecycle = (action) => {
|
|
211
|
+
if (action === "cancel-drain") {
|
|
212
|
+
if (finalDrainTimer) {
|
|
213
|
+
clearTimeout(finalDrainTimer);
|
|
214
|
+
finalDrainTimer = undefined;
|
|
215
|
+
}
|
|
216
|
+
if (finalHardKillTimer) {
|
|
217
|
+
clearTimeout(finalHardKillTimer);
|
|
218
|
+
finalHardKillTimer = undefined;
|
|
219
|
+
}
|
|
220
|
+
clearWatchdogTailTimer();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (action === "start-drain")
|
|
224
|
+
startFinalDrain();
|
|
225
|
+
};
|
|
226
|
+
const failProtocol = (limit) => {
|
|
227
|
+
if (protocolError)
|
|
228
|
+
return;
|
|
229
|
+
protocolError = limit;
|
|
230
|
+
error = formatProtocolOutputLimit(limit);
|
|
231
|
+
if (!childExited) {
|
|
232
|
+
trySignalChild(child, "SIGTERM");
|
|
233
|
+
protocolHardKillTimer = setTimeout(() => {
|
|
234
|
+
if (!settled)
|
|
235
|
+
trySignalChild(child, "SIGKILL");
|
|
236
|
+
}, 3000);
|
|
237
|
+
protocolHardKillTimer.unref?.();
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
const stdoutReader = createBoundedLineReader({ onLine: processStdoutLine, onLimit: failProtocol });
|
|
241
|
+
const stderrReader = createBoundedLineReader({
|
|
242
|
+
stream: "stderr",
|
|
243
|
+
maxPendingLineBytes: MAX_CHILD_STDERR_BYTES,
|
|
244
|
+
onLine: (line) => appendChildLine("subagent.child.stderr", line),
|
|
245
|
+
onLimit: (limit) => appendChildLine("subagent.child.stderr", formatProtocolOutputLimit(limit)),
|
|
246
|
+
});
|
|
247
|
+
const clearStdioGuard = attachPostExitStdioGuard(child, { idleMs: 2000, hardMs: 8000 });
|
|
248
|
+
child.stdout.on("data", (chunk) => stdoutReader.push(chunk));
|
|
249
|
+
child.stderr.on("data", (chunk) => {
|
|
250
|
+
stderrTail.push(chunk);
|
|
251
|
+
stderrReader.push(chunk);
|
|
252
|
+
outputStream.write(chunk);
|
|
253
|
+
});
|
|
254
|
+
registerInterrupt?.(() => {
|
|
255
|
+
if (settled || timedOut || stopped)
|
|
256
|
+
return;
|
|
257
|
+
interrupted = true;
|
|
258
|
+
if (!error)
|
|
259
|
+
error = "Interrupted. Waiting for explicit next action.";
|
|
260
|
+
trySignalChild(child, "SIGINT");
|
|
261
|
+
setTimeout(() => {
|
|
262
|
+
if (!settled && !timedOut && !stopped)
|
|
263
|
+
trySignalChild(child, "SIGTERM");
|
|
264
|
+
}, 1000).unref?.();
|
|
265
|
+
});
|
|
266
|
+
registerTimeout?.(() => {
|
|
267
|
+
if (settled || timedOut || stopped)
|
|
268
|
+
return;
|
|
269
|
+
timedOut = true;
|
|
270
|
+
interrupted = false;
|
|
271
|
+
error = timeoutMessage ?? "Subagent timed out.";
|
|
272
|
+
trySignalChild(child, "SIGTERM");
|
|
273
|
+
timeoutHardKillTimer = setTimeout(() => {
|
|
274
|
+
if (!settled)
|
|
275
|
+
trySignalChild(child, "SIGKILL");
|
|
276
|
+
}, TIMEOUT_HARD_KILL_MS);
|
|
277
|
+
timeoutHardKillTimer.unref?.();
|
|
278
|
+
});
|
|
279
|
+
registerStop?.(() => {
|
|
280
|
+
if (settled || timedOut || stopped)
|
|
281
|
+
return;
|
|
282
|
+
stopped = true;
|
|
283
|
+
interrupted = false;
|
|
284
|
+
error = stopMessage ?? "Subagent stopped by user.";
|
|
285
|
+
trySignalChild(child, "SIGTERM");
|
|
286
|
+
timeoutHardKillTimer = setTimeout(() => {
|
|
287
|
+
if (!settled)
|
|
288
|
+
trySignalChild(child, "SIGKILL");
|
|
289
|
+
}, TIMEOUT_HARD_KILL_MS);
|
|
290
|
+
timeoutHardKillTimer.unref?.();
|
|
291
|
+
});
|
|
292
|
+
registerTurnBudgetAbort?.((message, state) => {
|
|
293
|
+
if (settled || timedOut || stopped || turnBudgetExceeded)
|
|
294
|
+
return;
|
|
295
|
+
turnBudgetExceeded = true;
|
|
296
|
+
turnBudgetMessage = message;
|
|
297
|
+
turnBudget = state;
|
|
298
|
+
interrupted = false;
|
|
299
|
+
error = message;
|
|
300
|
+
trySignalChild(child, "SIGINT");
|
|
301
|
+
turnBudgetTerminationTimer = setTimeout(() => {
|
|
302
|
+
if (!settled && !timedOut && !stopped)
|
|
303
|
+
trySignalChild(child, "SIGTERM");
|
|
304
|
+
}, 1000);
|
|
305
|
+
turnBudgetTerminationTimer.unref?.();
|
|
306
|
+
turnBudgetHardKillTimer = setTimeout(() => {
|
|
307
|
+
if (!settled && !timedOut && !stopped)
|
|
308
|
+
trySignalChild(child, "SIGKILL");
|
|
309
|
+
}, 4000);
|
|
310
|
+
turnBudgetHardKillTimer.unref?.();
|
|
311
|
+
});
|
|
312
|
+
const clearDrainTimers = () => {
|
|
313
|
+
if (finalDrainTimer) {
|
|
314
|
+
clearTimeout(finalDrainTimer);
|
|
315
|
+
finalDrainTimer = undefined;
|
|
316
|
+
}
|
|
317
|
+
if (finalHardKillTimer) {
|
|
318
|
+
clearTimeout(finalHardKillTimer);
|
|
319
|
+
finalHardKillTimer = undefined;
|
|
320
|
+
}
|
|
321
|
+
clearWatchdogTailTimer();
|
|
322
|
+
if (timeoutHardKillTimer) {
|
|
323
|
+
clearTimeout(timeoutHardKillTimer);
|
|
324
|
+
timeoutHardKillTimer = undefined;
|
|
325
|
+
}
|
|
326
|
+
if (turnBudgetTerminationTimer) {
|
|
327
|
+
clearTimeout(turnBudgetTerminationTimer);
|
|
328
|
+
turnBudgetTerminationTimer = undefined;
|
|
329
|
+
}
|
|
330
|
+
if (turnBudgetHardKillTimer) {
|
|
331
|
+
clearTimeout(turnBudgetHardKillTimer);
|
|
332
|
+
turnBudgetHardKillTimer = undefined;
|
|
333
|
+
}
|
|
334
|
+
if (protocolHardKillTimer) {
|
|
335
|
+
clearTimeout(protocolHardKillTimer);
|
|
336
|
+
protocolHardKillTimer = undefined;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
function startFinalDrain() {
|
|
340
|
+
if (childWatchdogIsActive(childWatchdogState)) {
|
|
341
|
+
armWatchdogTail();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (childExited || finalDrainTimer || settled)
|
|
345
|
+
return;
|
|
346
|
+
finalDrainTimer = setTimeout(() => {
|
|
347
|
+
if (settled)
|
|
348
|
+
return;
|
|
349
|
+
const termSent = trySignalChild(child, "SIGTERM");
|
|
350
|
+
if (!termSent)
|
|
351
|
+
return;
|
|
352
|
+
forcedTerminationSignal = true;
|
|
353
|
+
if (!cleanTerminalAssistantStopReceived && !agentSettledReceived && !error && !assistantError) {
|
|
354
|
+
error = `Subagent process did not exit within ${FINAL_STOP_GRACE_MS}ms after its terminal event. Forcing termination.`;
|
|
355
|
+
}
|
|
356
|
+
finalHardKillTimer = setTimeout(() => {
|
|
357
|
+
if (settled)
|
|
358
|
+
return;
|
|
359
|
+
forcedTerminationSignal = trySignalChild(child, "SIGKILL") || forcedTerminationSignal;
|
|
360
|
+
}, HARD_KILL_MS);
|
|
361
|
+
finalHardKillTimer.unref?.();
|
|
362
|
+
}, FINAL_STOP_GRACE_MS);
|
|
363
|
+
finalDrainTimer.unref?.();
|
|
364
|
+
}
|
|
365
|
+
function clearWatchdogTailTimer() {
|
|
366
|
+
if (watchdogTailTimer) {
|
|
367
|
+
clearTimeout(watchdogTailTimer);
|
|
368
|
+
watchdogTailTimer = undefined;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function armWatchdogTail() {
|
|
372
|
+
if ((!cleanTerminalAssistantStopReceived && !agentSettledReceived) || watchdogTailTimer || settled)
|
|
373
|
+
return;
|
|
374
|
+
watchdogTailTimer = setTimeout(() => {
|
|
375
|
+
watchdogTailTimer = undefined;
|
|
376
|
+
updateChildWatchdogState({
|
|
377
|
+
phase: "stale",
|
|
378
|
+
seq: (childWatchdogState?.seq ?? 0) + 1,
|
|
379
|
+
lastUpdate: Date.now(),
|
|
380
|
+
followUpPending: false,
|
|
381
|
+
reason: "child watchdog tail timeout",
|
|
382
|
+
timedOut: true,
|
|
383
|
+
});
|
|
384
|
+
startFinalDrain();
|
|
385
|
+
}, childWatchdogConfig?.watchdogTailTimeoutMs ?? 120_000);
|
|
386
|
+
watchdogTailTimer.unref?.();
|
|
387
|
+
}
|
|
388
|
+
child.on("exit", () => {
|
|
389
|
+
childExited = true;
|
|
390
|
+
clearDrainTimers();
|
|
391
|
+
});
|
|
392
|
+
child.on("close", (exitCode, signal) => {
|
|
393
|
+
settled = true;
|
|
394
|
+
try {
|
|
395
|
+
onWriterProcess?.({ state: "none" });
|
|
396
|
+
}
|
|
397
|
+
catch {
|
|
398
|
+
// The runner still owns and releases the lease during finalization.
|
|
399
|
+
}
|
|
400
|
+
registerInterrupt?.(undefined);
|
|
401
|
+
registerTimeout?.(undefined);
|
|
402
|
+
registerStop?.(undefined);
|
|
403
|
+
registerTurnBudgetAbort?.(undefined);
|
|
404
|
+
clearDrainTimers();
|
|
405
|
+
clearStdioGuard();
|
|
406
|
+
stdoutReader.end();
|
|
407
|
+
stderrReader.end();
|
|
408
|
+
outputStream.end();
|
|
409
|
+
const stderr = stderrTail.text();
|
|
410
|
+
const finalOutput = getFinalOutput(messages) || rawStdoutTail.text().trim();
|
|
411
|
+
const finalError = error ?? assistantError;
|
|
412
|
+
const forcedDrainAfterFinalSuccess = forcedTerminationSignal && (cleanTerminalAssistantStopReceived || agentSettledReceived) && !finalError;
|
|
413
|
+
resolve({
|
|
414
|
+
stderr,
|
|
415
|
+
exitCode: timedOut || stopped ? 1 : turnBudgetExceeded ? 1 : interrupted || forcedDrainAfterFinalSuccess ? 0 : forcedTerminationSignal || signal ? (exitCode ?? 1) : exitCode,
|
|
416
|
+
messages,
|
|
417
|
+
usage,
|
|
418
|
+
model,
|
|
419
|
+
error: stopped ? (stopMessage ?? "Subagent stopped by user.") : timedOut ? (timeoutMessage ?? "Subagent timed out.") : turnBudgetExceeded ? turnBudgetMessage : interrupted || forcedDrainAfterFinalSuccess ? undefined : finalError,
|
|
420
|
+
protocolError,
|
|
421
|
+
finalOutput: (timedOut || stopped) && !finalOutput.trim() ? (stopped ? stopMessage ?? "Subagent stopped by user." : timeoutMessage ?? "Subagent timed out.") : finalOutput,
|
|
422
|
+
interrupted,
|
|
423
|
+
timedOut,
|
|
424
|
+
stopped,
|
|
425
|
+
turnBudget,
|
|
426
|
+
turnBudgetExceeded,
|
|
427
|
+
wrapUpRequested: turnBudget?.outcome === "wrap-up-requested" || turnBudgetExceeded || undefined,
|
|
428
|
+
observedMutationAttempt,
|
|
429
|
+
watchdog: childWatchdogState,
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
child.on("error", (spawnError) => {
|
|
433
|
+
settled = true;
|
|
434
|
+
try {
|
|
435
|
+
onWriterProcess?.({ state: "none" });
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
// The runner still owns and releases the lease during finalization.
|
|
439
|
+
}
|
|
440
|
+
registerInterrupt?.(undefined);
|
|
441
|
+
registerTimeout?.(undefined);
|
|
442
|
+
registerStop?.(undefined);
|
|
443
|
+
registerTurnBudgetAbort?.(undefined);
|
|
444
|
+
clearDrainTimers();
|
|
445
|
+
clearStdioGuard();
|
|
446
|
+
stdoutReader.end();
|
|
447
|
+
stderrReader.end();
|
|
448
|
+
outputStream.end();
|
|
449
|
+
const stderr = stderrTail.text();
|
|
450
|
+
const finalOutput = getFinalOutput(messages) || rawStdoutTail.text().trim();
|
|
451
|
+
const spawnErrorMessage = spawnError instanceof Error ? spawnError.message : String(spawnError);
|
|
452
|
+
resolve({ stderr, exitCode: 1, messages, usage, model, error: stopped ? (stopMessage ?? "Subagent stopped by user.") : timedOut ? (timeoutMessage ?? "Subagent timed out.") : turnBudgetExceeded ? turnBudgetMessage : error ?? assistantError ?? spawnErrorMessage, protocolError, finalOutput: (timedOut || stopped) && !finalOutput.trim() ? (stopped ? stopMessage ?? "Subagent stopped by user." : timeoutMessage ?? "Subagent timed out.") : finalOutput, timedOut, stopped, turnBudget, turnBudgetExceeded, wrapUpRequested: turnBudget?.outcome === "wrap-up-requested" || turnBudgetExceeded || undefined, observedMutationAttempt, watchdog: childWatchdogState });
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
//# sourceMappingURL=child-stream.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { BuiltRunnerStep as RunnerStep, BuiltRunnerSubagentStep as SubagentStep } from "../shared/parallel-utils.ts";
|
|
2
|
+
import { type WorktreeSetup } from "../shared/worktree.ts";
|
|
3
|
+
import type { RunnerStatusPayload, StepResult } from "./runner-status.ts";
|
|
4
|
+
export declare function markParallelGroupSetupFailure(input: {
|
|
5
|
+
statusPayload: RunnerStatusPayload;
|
|
6
|
+
results: StepResult[];
|
|
7
|
+
group: Extract<RunnerStep, {
|
|
8
|
+
parallel: SubagentStep[];
|
|
9
|
+
}>;
|
|
10
|
+
groupStartFlatIndex: number;
|
|
11
|
+
setupError: string;
|
|
12
|
+
failedAt: number;
|
|
13
|
+
statusPath: string;
|
|
14
|
+
eventsPath: string;
|
|
15
|
+
asyncDir: string;
|
|
16
|
+
runId: string;
|
|
17
|
+
stepIndex: number;
|
|
18
|
+
}): void;
|
|
19
|
+
export declare function markParallelGroupRunning(input: {
|
|
20
|
+
statusPayload: RunnerStatusPayload;
|
|
21
|
+
group: Extract<RunnerStep, {
|
|
22
|
+
parallel: SubagentStep[];
|
|
23
|
+
}>;
|
|
24
|
+
groupStartFlatIndex: number;
|
|
25
|
+
groupStartTime: number;
|
|
26
|
+
statusPath: string;
|
|
27
|
+
eventsPath: string;
|
|
28
|
+
asyncDir: string;
|
|
29
|
+
runId: string;
|
|
30
|
+
stepIndex: number;
|
|
31
|
+
}): void;
|
|
32
|
+
export declare function prepareParallelTaskRun(task: SubagentStep, cwd: string, worktreeSetup: WorktreeSetup | undefined, taskIndex: number): {
|
|
33
|
+
taskForRun: SubagentStep;
|
|
34
|
+
taskCwd: string;
|
|
35
|
+
};
|
|
36
|
+
export declare function appendParallelWorktreeSummary(previousOutput: string, worktreeSetup: WorktreeSetup | undefined, asyncDir: string, stepIndex: number, group: Extract<RunnerStep, {
|
|
37
|
+
parallel: SubagentStep[];
|
|
38
|
+
}>): string;
|
|
39
|
+
export declare function ensureParallelProgressFile(cwd: string, group: Extract<RunnerStep, {
|
|
40
|
+
parallel: SubagentStep[];
|
|
41
|
+
}>): void;
|
|
42
|
+
//# sourceMappingURL=parallel-group-status.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Status, events and progress files for a parallel group in an async run: setup failure, start, task prep and the worktree summary.
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { writeAtomicJson } from "../../shared/atomic-json.js";
|
|
4
|
+
import { diffWorktrees, formatWorktreeDiffSummary } from "../shared/worktree.js";
|
|
5
|
+
import { writeInitialProgressFile } from "../../shared/settings.js";
|
|
6
|
+
import { appendJsonl } from "./runner-event-log.js";
|
|
7
|
+
export function markParallelGroupSetupFailure(input) {
|
|
8
|
+
for (let taskIndex = 0; taskIndex < input.group.parallel.length; taskIndex++) {
|
|
9
|
+
const flatTaskIndex = input.groupStartFlatIndex + taskIndex;
|
|
10
|
+
input.statusPayload.steps[flatTaskIndex].status = "failed";
|
|
11
|
+
input.statusPayload.steps[flatTaskIndex].startedAt = input.failedAt;
|
|
12
|
+
input.statusPayload.steps[flatTaskIndex].endedAt = input.failedAt;
|
|
13
|
+
input.statusPayload.steps[flatTaskIndex].durationMs = 0;
|
|
14
|
+
input.statusPayload.steps[flatTaskIndex].exitCode = 1;
|
|
15
|
+
input.results.push({ agent: input.group.parallel[taskIndex].agent, output: input.setupError, success: false, exitCode: 1, sessionFile: input.group.parallel[taskIndex].sessionFile });
|
|
16
|
+
}
|
|
17
|
+
input.statusPayload.currentStep = input.groupStartFlatIndex;
|
|
18
|
+
input.statusPayload.lastUpdate = input.failedAt;
|
|
19
|
+
input.statusPayload.outputFile = path.join(input.asyncDir, `output-${input.groupStartFlatIndex}.log`);
|
|
20
|
+
writeAtomicJson(input.statusPath, input.statusPayload);
|
|
21
|
+
appendJsonl(input.eventsPath, JSON.stringify({
|
|
22
|
+
type: "subagent.parallel.completed",
|
|
23
|
+
ts: input.failedAt,
|
|
24
|
+
runId: input.runId,
|
|
25
|
+
stepIndex: input.stepIndex,
|
|
26
|
+
success: false,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
export function markParallelGroupRunning(input) {
|
|
30
|
+
for (let taskIndex = 0; taskIndex < input.group.parallel.length; taskIndex++) {
|
|
31
|
+
const flatTaskIndex = input.groupStartFlatIndex + taskIndex;
|
|
32
|
+
input.statusPayload.steps[flatTaskIndex].status = "pending";
|
|
33
|
+
input.statusPayload.steps[flatTaskIndex].startedAt = undefined;
|
|
34
|
+
input.statusPayload.steps[flatTaskIndex].endedAt = undefined;
|
|
35
|
+
input.statusPayload.steps[flatTaskIndex].durationMs = undefined;
|
|
36
|
+
input.statusPayload.steps[flatTaskIndex].lastActivityAt = undefined;
|
|
37
|
+
input.statusPayload.steps[flatTaskIndex].activityState = undefined;
|
|
38
|
+
input.statusPayload.steps[flatTaskIndex].error = undefined;
|
|
39
|
+
}
|
|
40
|
+
input.statusPayload.currentStep = input.groupStartFlatIndex;
|
|
41
|
+
input.statusPayload.activityState = undefined;
|
|
42
|
+
input.statusPayload.lastActivityAt = input.groupStartTime;
|
|
43
|
+
input.statusPayload.lastUpdate = input.groupStartTime;
|
|
44
|
+
input.statusPayload.outputFile = path.join(input.asyncDir, `output-${input.groupStartFlatIndex}.log`);
|
|
45
|
+
writeAtomicJson(input.statusPath, input.statusPayload);
|
|
46
|
+
appendJsonl(input.eventsPath, JSON.stringify({
|
|
47
|
+
type: "subagent.parallel.started",
|
|
48
|
+
ts: input.groupStartTime,
|
|
49
|
+
runId: input.runId,
|
|
50
|
+
stepIndex: input.stepIndex,
|
|
51
|
+
agents: input.group.parallel.map((task) => task.agent),
|
|
52
|
+
count: input.group.parallel.length,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
export function prepareParallelTaskRun(task, cwd, worktreeSetup, taskIndex) {
|
|
56
|
+
if (!worktreeSetup)
|
|
57
|
+
return { taskForRun: task, taskCwd: cwd };
|
|
58
|
+
return {
|
|
59
|
+
taskForRun: { ...task, cwd: undefined },
|
|
60
|
+
taskCwd: worktreeSetup.worktrees[taskIndex].agentCwd,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export function appendParallelWorktreeSummary(previousOutput, worktreeSetup, asyncDir, stepIndex, group) {
|
|
64
|
+
if (!worktreeSetup)
|
|
65
|
+
return previousOutput;
|
|
66
|
+
const diffsDir = path.join(asyncDir, "worktree-diffs", `step-${stepIndex}`);
|
|
67
|
+
const diffs = diffWorktrees(worktreeSetup, group.parallel.map((task) => task.agent), diffsDir);
|
|
68
|
+
const diffSummary = formatWorktreeDiffSummary(diffs);
|
|
69
|
+
if (!diffSummary)
|
|
70
|
+
return previousOutput;
|
|
71
|
+
return `${previousOutput}\n\n${diffSummary}`;
|
|
72
|
+
}
|
|
73
|
+
export function ensureParallelProgressFile(cwd, group) {
|
|
74
|
+
const progressPath = path.join(cwd, "progress.md");
|
|
75
|
+
if (!group.parallel.some((task) => task.task.includes(`Update progress at: ${progressPath}`)))
|
|
76
|
+
return;
|
|
77
|
+
writeInitialProgressFile(cwd);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=parallel-group-status.js.map
|