@ashx-j/lunr-dev 0.2.40-dev.55.1 → 0.2.40-dev.59.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/lunr-browser.d.ts +1 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.js +1 -1
- 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/builtin-extensions/pi-subagents/src/tui/communication.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js +1 -1
- package/dist/cli/config-selector.js +1 -1
- package/dist/cli/startup-ui.js +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/credential-files.d.ts +3 -2
- package/dist/core/credential-files.js +10 -4
- package/dist/core/export-html/index.js +1 -1
- package/dist/core/export-html/tool-renderer.d.ts +1 -1
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/types.d.ts +1 -1
- package/dist/core/permissions.d.ts +6 -0
- package/dist/core/permissions.js +6 -0
- package/dist/core/resource-loader.d.ts +1 -1
- package/dist/core/resource-loader.js +1 -1
- package/dist/{modes/interactive → core}/theme/theme.d.ts +1 -1
- package/dist/{modes/interactive → core}/theme/theme.js +4 -4
- package/dist/core/tool-call-hooks.js +3 -2
- package/dist/gateway/agent-bridge.js +1 -1
- package/dist/gateway/setup.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/main.js +1 -1
- package/dist/modes/interactive/chat-history.js +1 -1
- package/dist/modes/interactive/components/assistant-message.js +1 -1
- package/dist/modes/interactive/components/bash-execution.js +1 -1
- package/dist/modes/interactive/components/boot-screen.js +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +1 -1
- package/dist/modes/interactive/components/config-selector.js +1 -1
- package/dist/modes/interactive/components/context-view.js +1 -1
- package/dist/modes/interactive/components/copyable-text.js +1 -1
- package/dist/modes/interactive/components/custom-entry.js +1 -1
- package/dist/modes/interactive/components/custom-message.js +1 -1
- package/dist/modes/interactive/components/diff.js +1 -1
- package/dist/modes/interactive/components/dynamic-border.js +1 -1
- package/dist/modes/interactive/components/extension-editor.js +1 -1
- package/dist/modes/interactive/components/extension-input.js +1 -1
- package/dist/modes/interactive/components/extension-selector.js +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/injected-prompt-message.js +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +1 -1
- package/dist/modes/interactive/components/login-dialog.js +1 -1
- package/dist/modes/interactive/components/model-selector.js +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +1 -1
- package/dist/modes/interactive/components/onboarding.js +1 -1
- package/dist/modes/interactive/components/plan-message.js +1 -1
- package/dist/modes/interactive/components/processes-selector.js +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +1 -1
- package/dist/modes/interactive/components/session-selector.js +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +1 -1
- package/dist/modes/interactive/components/settings-selector.js +1 -1
- package/dist/modes/interactive/components/show-images-selector.js +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +1 -1
- package/dist/modes/interactive/components/status-indicator.js +1 -1
- package/dist/modes/interactive/components/theme-selector.js +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +1 -1
- package/dist/modes/interactive/components/thinking-tail.js +1 -1
- package/dist/modes/interactive/components/tool-execution.js +1 -1
- package/dist/modes/interactive/components/tree-selector.js +1 -1
- package/dist/modes/interactive/components/trust-selector.js +1 -1
- package/dist/modes/interactive/components/usage-view.js +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +1 -1
- package/dist/modes/interactive/components/user-message.js +1 -1
- package/dist/modes/interactive/extension-dialogs.d.ts +1 -1
- package/dist/modes/interactive/extension-dialogs.js +1 -1
- package/dist/modes/interactive/extension-widgets.d.ts +1 -1
- package/dist/modes/interactive/extension-widgets.js +1 -1
- package/dist/modes/interactive/help-commands.js +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/loaded-resources.js +1 -1
- package/dist/modes/interactive/login-flow.js +1 -1
- package/dist/modes/interactive/session-exit.js +1 -1
- package/dist/modes/interactive/session-naming.js +1 -1
- package/dist/modes/interactive/settings-screen.js +1 -1
- package/dist/modes/interactive/theme/theme-controller.d.ts +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +1 -1
- package/dist/modes/interactive/tool-renderers/bash.js +1 -1
- package/dist/modes/interactive/tool-renderers/read.js +1 -1
- package/dist/modes/interactive/tool-renderers/render-utils.d.ts +1 -1
- package/dist/modes/interactive/tool-renderers/write.js +1 -1
- package/dist/modes/interactive/usage-commands.js +1 -1
- package/dist/modes/rpc/rpc-mode.js +1 -1
- 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-UOVUJAX2.js} +8 -8
- package/dist/node-runtime/{builtin-extensions-YJ7F6GND.js → builtin-extensions-JNJRND4E.js} +3 -3
- package/dist/node-runtime/{chunk-GPNTGRL2.js → chunk-3RR3PVJB.js} +2 -2
- package/dist/node-runtime/{chunk-HVXDYQNN.js → chunk-6DVUDNS7.js} +2 -2
- package/dist/node-runtime/{chunk-5F7VOA34.js → chunk-AW6PDL4D.js} +1 -1
- package/dist/node-runtime/{chunk-VP2H4TI5.js → chunk-BJIF7GMV.js} +3 -3
- package/dist/node-runtime/{chunk-5HVA5ECB.js → chunk-BQROL43X.js} +17 -17
- package/dist/node-runtime/{chunk-BNNBTBXY.js → chunk-EJMB4PAV.js} +3 -3
- package/dist/node-runtime/{chunk-G3PARFR4.js → chunk-FCINT2KC.js} +7 -7
- package/dist/node-runtime/{chunk-KURXPCGO.js → chunk-FNS42TPZ.js} +3 -3
- package/dist/node-runtime/{chunk-N574FRFF.js → chunk-GAWWLIGY.js} +3 -3
- package/dist/node-runtime/{chunk-27QDDTTV.js → chunk-HYOPEHDE.js} +2 -2
- package/dist/node-runtime/{chunk-5JVP2JX4.js → chunk-JARNU4J4.js} +3 -3
- package/dist/node-runtime/{chunk-ITHKNPG4.js → chunk-JZK2WJ7U.js} +1 -1
- package/dist/node-runtime/{chunk-PLBYKAZC.js → chunk-KETNCBTB.js} +2 -2
- package/dist/node-runtime/{chunk-KTCZH72R.js → chunk-LGRRFSE7.js} +3 -2
- package/dist/node-runtime/{chunk-OXFD2OMR.js → chunk-LY6VVOF4.js} +3 -3
- package/dist/node-runtime/{chunk-DJB7P2V7.js → chunk-MEDBJXCC.js} +1 -1
- package/dist/node-runtime/{chunk-SV42POA3.js → chunk-PGWSMQ4K.js} +1 -1
- package/dist/node-runtime/{chunk-7LCR56AK.js → chunk-QDQAKIVU.js} +1 -1
- package/dist/node-runtime/{chunk-GNT2AURO.js → chunk-QP4I6GEW.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-U2LTTIWZ.js → chunk-RXG6DWO2.js} +1 -1
- package/dist/node-runtime/{chunk-ITVBE3HR.js → chunk-S46QLY2F.js} +10 -9
- package/dist/node-runtime/{chunk-CDILDA4F.js → chunk-U7MTVVT3.js} +2 -2
- package/dist/node-runtime/{chunk-MNYG5WLT.js → chunk-WBLSU6YV.js} +3 -3
- package/dist/node-runtime/{chunk-7LNPTBQJ.js → chunk-XPKOWSYN.js} +6 -2
- package/dist/node-runtime/{chunk-4ZEDT3YW.js → chunk-XXGJ7Z3C.js} +11 -11
- package/dist/node-runtime/{chunk-3UQ7ZNLI.js → chunk-Y7DFMHY5.js} +8 -8
- package/dist/node-runtime/{chunk-2ZI6Q6JG.js → chunk-YFXGOLZ6.js} +1 -1
- package/dist/node-runtime/cli-runtime.js +1 -1
- package/dist/node-runtime/{command-H52R5R2G.js → command-6GJNLXGD.js} +3 -3
- package/dist/node-runtime/{commands-CV2JUYHM.js → commands-2UG5F4VT.js} +6 -6
- package/dist/node-runtime/{commands-7EETGZ7V.js → commands-GSZWAQJW.js} +5 -5
- package/dist/node-runtime/{direct-tool-executor-DNZ2MS6Z.js → direct-tool-executor-WJLVHH7U.js} +6 -6
- package/dist/node-runtime/{export-html-7TEMZLK2.js → export-html-SW3CIZRJ.js} +1 -1
- package/dist/node-runtime/{extension-input-MNEKUZDZ.js → extension-input-DFQ76UJG.js} +4 -4
- package/dist/node-runtime/{extension-selector-6WJHCCQI.js → extension-selector-MWHCRWHQ.js} +4 -4
- package/dist/node-runtime/{gateway-OHPDCOOB.js → gateway-UDWVYEGX.js} +8 -8
- package/dist/node-runtime/{goal-PJ2NLX6M.js → goal-CVGA3XFI.js} +1 -1
- package/dist/node-runtime/index.js +22 -22
- package/dist/node-runtime/{init-G23PFPKF.js → init-P3RQ6EFK.js} +5 -5
- package/dist/node-runtime/{install-cli-4LUSDUPO.js → install-cli-YIIFVCFM.js} +1 -1
- package/dist/node-runtime/{interactive-mode-7GX3UJFX.js → interactive-mode-VCPSTUAW.js} +16 -16
- package/dist/node-runtime/{interactive-view-TUYWWEUV.js → interactive-view-GDP6M6UP.js} +6 -6
- package/dist/node-runtime/{lunr-cron-SV2EXYKV.js → lunr-cron-3VI5CLK3.js} +6 -6
- package/dist/node-runtime/main.js +17 -17
- package/dist/node-runtime/{mobile-commands-JQJU35OT.js → mobile-commands-HQXEYAF6.js} +5 -5
- package/dist/node-runtime/{package-manager-cli-FICMQY2Q.js → package-manager-cli-B6G22R6O.js} +9 -9
- package/dist/node-runtime/{pi-mcp-adapter-NKAL5CFR.js → pi-mcp-adapter-2OP5BBC6.js} +8 -8
- package/dist/node-runtime/{pi-prompt-template-model-63LFES2U.js → pi-prompt-template-model-UL2T2HLL.js} +2 -2
- package/dist/node-runtime/{pi-subagents-WS6OU5MG.js → pi-subagents-YVVMY4B4.js} +8 -8
- package/dist/node-runtime/{print-mode-Y363FXY4.js → print-mode-M52NLHKG.js} +9 -9
- package/dist/node-runtime/{proxy-modes-EEYRUGQL.js → proxy-modes-RD2PQ6UH.js} +6 -6
- package/dist/node-runtime/rpc-entry.js +17 -17
- package/dist/node-runtime/{rpc-mode-ENVT7AXW.js → rpc-mode-WAHP6U73.js} +4 -4
- package/dist/node-runtime/{session-selector-AF6V7DP6.js → session-selector-JABBEHK5.js} +4 -4
- package/dist/node-runtime/{setup-OHLYSWTW.js → setup-7IC2PQIB.js} +6 -6
- 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/dist/node-runtime/{theme-AY3J7JHP.js → theme-MVESIOLX.js} +1 -1
- package/dist/node-runtime/{tool-renderers-4RDKHPPB.js → tool-renderers-KL5EPAMN.js} +3 -3
- package/dist/startup/interactive-view.js +1 -1
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Text } from "@ashx-j/lunr-tui";
|
|
2
2
|
import type { ExtensionAPI, ToolRenderContext } from "../core/extensions/types.ts";
|
|
3
3
|
import { type BrowserInput } from "../core/browser/schema.ts";
|
|
4
|
-
import type { Theme } from "../
|
|
4
|
+
import type { Theme } from "../core/theme/theme.ts";
|
|
5
5
|
export type BrowserActivityState = "pending" | "success" | "error";
|
|
6
6
|
export declare function describeBrowserActivity(input: BrowserInput, state: BrowserActivityState): string;
|
|
7
7
|
export declare function renderBrowserActivity(args: BrowserInput, theme: Theme, context: ToolRenderContext<unknown, BrowserInput>): Text;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// the barrel re-exports main.ts which imports this extension (cycle).
|
|
3
3
|
import { defineTool } from "../../../core/extensions/types.js";
|
|
4
4
|
import { isCronFire } from "../../../core/cron/fire-guard.js";
|
|
5
|
-
import { getMarkdownTheme } from "../../../
|
|
5
|
+
import { getMarkdownTheme } from "../../../core/theme/theme.js";
|
|
6
6
|
import { Type } from "typebox";
|
|
7
7
|
import { Container, Markdown, Text } from "@ashx-j/lunr-tui";
|
|
8
8
|
import { currentTokenTotal } from "./accounting.js";
|
|
@@ -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
|