@ashx-j/lunr-dev 0.2.40-dev.54.2 → 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/builtin-extensions/pi-subagents/src/runs/foreground/async-run-control.d.ts +19 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/async-run-control.js +331 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution-input.d.ts +37 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution-input.js +321 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/executor-types.d.ts +124 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/executor-types.js +2 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/foreground-notifications.d.ts +17 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/foreground-notifications.js +98 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/foreground-run-registry.d.ts +40 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/foreground-run-registry.js +172 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/fork-policy.d.ts +14 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/fork-policy.js +161 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/nested-run-control.d.ts +46 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/nested-run-control.js +195 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/parallel-run.d.ts +10 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/parallel-run.js +537 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts +5 -81
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +26 -1763
- package/dist/builtin-extensions/pi-subagents/src/shared/settings.d.ts +1 -1
- 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-VQHK3YKF.js → builtin-extensions-RZS4SMIS.js} +3 -3
- package/dist/node-runtime/{chunk-UZMXBZQT.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-YDY7A2WB.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-VIYDTWDK.js → chunk-U7MTVVT3.js} +606 -604
- package/dist/node-runtime/{chunk-MFDTF25H.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-SRDEBPUR.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-AMEMDTUT.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-OMQBN3UK.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-36KOL5SV.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-D42G55F5.js → subagent-executor-RTGKJ35C.js} +1924 -1901
- 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,172 @@
|
|
|
1
|
+
import { getSingleResultOutput } from "../../shared/utils.js";
|
|
2
|
+
import { resolveSubagentResultStatus } from "../../intercom/result-intercom.js";
|
|
3
|
+
import { updateForegroundNestedProjection } from "../shared/nested-events.js";
|
|
4
|
+
import { formatNestedRunStatusLines } from "../shared/nested-render.js";
|
|
5
|
+
import { SUBAGENT_FOREGROUND_COMPLETE_EVENT } from "../../shared/types.js";
|
|
6
|
+
export function getForegroundControl(state, runId) {
|
|
7
|
+
if (runId)
|
|
8
|
+
return state.foregroundControls.get(runId);
|
|
9
|
+
if (state.lastForegroundControlId) {
|
|
10
|
+
const latest = state.foregroundControls.get(state.lastForegroundControlId);
|
|
11
|
+
if (latest)
|
|
12
|
+
return latest;
|
|
13
|
+
}
|
|
14
|
+
let newest;
|
|
15
|
+
for (const control of state.foregroundControls.values()) {
|
|
16
|
+
if (!newest || control.updatedAt > newest.updatedAt)
|
|
17
|
+
newest = control;
|
|
18
|
+
}
|
|
19
|
+
return newest;
|
|
20
|
+
}
|
|
21
|
+
function formatForegroundActivity(control) {
|
|
22
|
+
const facts = [];
|
|
23
|
+
if (control.currentTool && control.currentToolStartedAt)
|
|
24
|
+
facts.push(`tool ${control.currentTool} for ${Math.floor(Math.max(0, Date.now() - control.currentToolStartedAt) / 1000)}s`);
|
|
25
|
+
else if (control.currentTool)
|
|
26
|
+
facts.push(`tool ${control.currentTool}`);
|
|
27
|
+
if (control.currentPath)
|
|
28
|
+
facts.push(`path ${control.currentPath}`);
|
|
29
|
+
if (control.turnCount !== undefined)
|
|
30
|
+
facts.push(`${control.turnCount} turns`);
|
|
31
|
+
if (control.tokens !== undefined)
|
|
32
|
+
facts.push(`${control.tokens} tokens`);
|
|
33
|
+
if (control.toolCount !== undefined)
|
|
34
|
+
facts.push(`${control.toolCount} tools`);
|
|
35
|
+
if (!control.lastActivityAt) {
|
|
36
|
+
if (control.currentActivityState === "needs_attention")
|
|
37
|
+
return ["needs attention", ...facts].join(" | ");
|
|
38
|
+
if (control.currentActivityState === "active_long_running")
|
|
39
|
+
return ["active but long-running", ...facts].join(" | ");
|
|
40
|
+
return facts.length ? facts.join(" | ") : undefined;
|
|
41
|
+
}
|
|
42
|
+
const seconds = Math.floor(Math.max(0, Date.now() - control.lastActivityAt) / 1000);
|
|
43
|
+
if (control.currentActivityState === "needs_attention")
|
|
44
|
+
return [`no activity for ${seconds}s`, ...facts].join(" | ");
|
|
45
|
+
if (control.currentActivityState === "active_long_running")
|
|
46
|
+
return [`active but long-running; last activity ${seconds}s ago`, ...facts].join(" | ");
|
|
47
|
+
return [`active ${seconds}s ago`, ...facts].join(" | ");
|
|
48
|
+
}
|
|
49
|
+
export function foregroundStatusResult(control) {
|
|
50
|
+
let nestedWarning;
|
|
51
|
+
try {
|
|
52
|
+
updateForegroundNestedProjection(control);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
nestedWarning = `Nested status unavailable: ${error instanceof Error ? error.message : String(error)}`;
|
|
56
|
+
}
|
|
57
|
+
const activity = formatForegroundActivity(control);
|
|
58
|
+
const lines = [
|
|
59
|
+
`Run: ${control.runId}`,
|
|
60
|
+
"State: running",
|
|
61
|
+
`Mode: ${control.mode}`,
|
|
62
|
+
control.currentAgent ? `Current: ${control.currentAgent}${control.currentIndex !== undefined ? ` step ${control.currentIndex + 1}` : ""}` : undefined,
|
|
63
|
+
activity ? `Activity: ${activity}` : undefined,
|
|
64
|
+
].filter((line) => Boolean(line));
|
|
65
|
+
lines.push(...formatNestedRunStatusLines(control.nestedChildren, { indent: "", commandHints: true, maxLines: 20 }));
|
|
66
|
+
if (nestedWarning)
|
|
67
|
+
lines.push(`Warning: ${nestedWarning}`);
|
|
68
|
+
return { content: [{ type: "text", text: lines.join("\n") }], details: { mode: "management", results: [] } };
|
|
69
|
+
}
|
|
70
|
+
function trimRememberedForegroundRuns(state) {
|
|
71
|
+
if (!state.foregroundRuns)
|
|
72
|
+
return;
|
|
73
|
+
while (state.foregroundRuns.size > 50) {
|
|
74
|
+
const oldestTerminal = [...state.foregroundRuns.values()]
|
|
75
|
+
.filter((run) => !run.children.some((child) => child.status === "detached"))
|
|
76
|
+
.sort((left, right) => left.updatedAt - right.updatedAt)[0];
|
|
77
|
+
if (!oldestTerminal)
|
|
78
|
+
break;
|
|
79
|
+
state.foregroundRuns.delete(oldestTerminal.runId);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function rememberForegroundRun(state, input) {
|
|
83
|
+
state.foregroundRuns ??= new Map();
|
|
84
|
+
const previous = state.foregroundRuns.get(input.runId);
|
|
85
|
+
const updatedAt = Date.now();
|
|
86
|
+
state.foregroundRuns.set(input.runId, {
|
|
87
|
+
runId: input.runId,
|
|
88
|
+
mode: input.mode,
|
|
89
|
+
cwd: input.cwd,
|
|
90
|
+
...(input.sessionId ? { sessionId: input.sessionId } : {}),
|
|
91
|
+
updatedAt,
|
|
92
|
+
children: input.results.map((result, index) => {
|
|
93
|
+
const child = {
|
|
94
|
+
agent: result.agent,
|
|
95
|
+
index,
|
|
96
|
+
status: resolveSubagentResultStatus({ exitCode: result.exitCode, interrupted: result.interrupted, detached: result.detached }),
|
|
97
|
+
updatedAt,
|
|
98
|
+
...(result.exitCode !== undefined ? { exitCode: result.exitCode } : {}),
|
|
99
|
+
...(result.error ? { error: result.error } : {}),
|
|
100
|
+
...(result.finalOutput ? { finalOutput: result.finalOutput } : {}),
|
|
101
|
+
...(result.outputMode ? { outputMode: result.outputMode } : {}),
|
|
102
|
+
...(result.savedOutputPath ? { savedOutputPath: result.savedOutputPath } : {}),
|
|
103
|
+
...(result.outputSaveError ? { outputSaveError: result.outputSaveError } : {}),
|
|
104
|
+
...(result.sessionFile ? { sessionFile: result.sessionFile } : {}),
|
|
105
|
+
...(result.artifactPaths ? { artifactPaths: result.artifactPaths } : {}),
|
|
106
|
+
...(result.transcriptPath ? { transcriptPath: result.transcriptPath } : {}),
|
|
107
|
+
...(result.transcriptError ? { transcriptError: result.transcriptError } : {}),
|
|
108
|
+
...(result.detachedReason ? { detachedReason: result.detachedReason } : {}),
|
|
109
|
+
...(result.acceptance ? { acceptance: result.acceptance } : {}),
|
|
110
|
+
};
|
|
111
|
+
const recovered = previous?.children[index];
|
|
112
|
+
return child.status === "detached" && recovered && recovered.status !== "detached" ? recovered : child;
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
trimRememberedForegroundRuns(state);
|
|
116
|
+
}
|
|
117
|
+
export function updateRememberedForegroundChild(state, input) {
|
|
118
|
+
state.foregroundRuns ??= new Map();
|
|
119
|
+
const updatedAt = Date.now();
|
|
120
|
+
let run = state.foregroundRuns.get(input.runId);
|
|
121
|
+
if (!run) {
|
|
122
|
+
run = { runId: input.runId, mode: input.mode, cwd: input.cwd, ...(input.sessionId ? { sessionId: input.sessionId } : {}), updatedAt, children: [] };
|
|
123
|
+
state.foregroundRuns.set(input.runId, run);
|
|
124
|
+
}
|
|
125
|
+
run.updatedAt = updatedAt;
|
|
126
|
+
const child = run.children[input.index] ?? { agent: input.result.agent, index: input.index, status: "detached" };
|
|
127
|
+
run.children[input.index] = {
|
|
128
|
+
...child,
|
|
129
|
+
agent: input.result.agent,
|
|
130
|
+
index: input.index,
|
|
131
|
+
status: input.result.acceptance?.status === "rejected"
|
|
132
|
+
? "failed"
|
|
133
|
+
: resolveSubagentResultStatus({ exitCode: input.result.exitCode, interrupted: input.result.interrupted, detached: false }),
|
|
134
|
+
updatedAt,
|
|
135
|
+
...(input.result.exitCode !== undefined ? { exitCode: input.result.exitCode } : {}),
|
|
136
|
+
...(input.result.error ? { error: input.result.error } : {}),
|
|
137
|
+
...(input.result.finalOutput ? { finalOutput: input.result.finalOutput } : {}),
|
|
138
|
+
outputMode: input.result.outputMode,
|
|
139
|
+
savedOutputPath: input.result.savedOutputPath,
|
|
140
|
+
outputSaveError: input.result.outputSaveError,
|
|
141
|
+
...(input.result.sessionFile ? { sessionFile: input.result.sessionFile } : {}),
|
|
142
|
+
...(input.result.artifactPaths ? { artifactPaths: input.result.artifactPaths } : {}),
|
|
143
|
+
...(input.result.transcriptPath ? { transcriptPath: input.result.transcriptPath } : {}),
|
|
144
|
+
...(input.result.transcriptError ? { transcriptError: input.result.transcriptError } : {}),
|
|
145
|
+
...(input.result.detachedReason ? { detachedReason: input.result.detachedReason } : {}),
|
|
146
|
+
...(input.result.acceptance ? { acceptance: input.result.acceptance } : {}),
|
|
147
|
+
};
|
|
148
|
+
trimRememberedForegroundRuns(state);
|
|
149
|
+
const output = getSingleResultOutput(input.result).trim();
|
|
150
|
+
const success = input.result.exitCode === 0 && input.result.acceptance?.status !== "rejected";
|
|
151
|
+
const summary = !success && input.result.error
|
|
152
|
+
? `${input.result.error}${output ? `\n\nOutput:\n${output}` : ""}`
|
|
153
|
+
: output || input.result.error || "Detached child exited without final output.";
|
|
154
|
+
input.events.emit(SUBAGENT_FOREGROUND_COMPLETE_EVENT, {
|
|
155
|
+
id: `${input.runId}:${input.index}`,
|
|
156
|
+
runId: input.runId,
|
|
157
|
+
source: "foreground",
|
|
158
|
+
mode: input.mode,
|
|
159
|
+
agent: input.result.agent,
|
|
160
|
+
success,
|
|
161
|
+
summary,
|
|
162
|
+
exitCode: input.result.exitCode,
|
|
163
|
+
state: success ? "complete" : "failed",
|
|
164
|
+
timestamp: updatedAt,
|
|
165
|
+
cwd: input.cwd,
|
|
166
|
+
sessionFile: input.result.sessionFile,
|
|
167
|
+
sessionId: input.sessionId,
|
|
168
|
+
taskIndex: input.index,
|
|
169
|
+
results: [{ childId: input.result.childId, agent: input.result.agent, sessionFile: input.result.sessionFile, usage: input.result.usage, usageRequests: input.result.usageRequests, success, output: summary }],
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=foreground-run-registry.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AgentToolResult } from "@ashx-j/lunr-agent";
|
|
2
|
+
import { type MaterializedChainStep } from "../../shared/settings.ts";
|
|
3
|
+
import { type Details, type ChildRuntimeConfig } from "../../shared/types.ts";
|
|
4
|
+
import type { SubagentParamsLike, AgentDefaultContextPolicy, ForkSessionFileForTask, ForkThinkingOverrideForTask, MaterializedParams } from "./executor-types.ts";
|
|
5
|
+
export declare function resolveAgentDefaultContextPolicy<P extends SubagentParamsLike>(params: P): AgentDefaultContextPolicy<P>;
|
|
6
|
+
export declare function resolveExplicitContextPolicy<P extends SubagentParamsLike>(params: P): AgentDefaultContextPolicy<P>;
|
|
7
|
+
export declare function shouldForkAgent(contextPolicy: AgentDefaultContextPolicy, agentName: string): boolean;
|
|
8
|
+
export declare function withForkContext(result: AgentToolResult<Details>, context: SubagentParamsLike["context"]): AgentToolResult<Details>;
|
|
9
|
+
export declare function withForkThinkingNotes(result: AgentToolResult<Details>, downgrades: Map<number, string>): AgentToolResult<Details>;
|
|
10
|
+
export declare function collectChainSessionFiles(chain: MaterializedChainStep[], sessionFileForTask: ForkSessionFileForTask, dynamicFanoutMaxItems?: number): (string | undefined)[];
|
|
11
|
+
export declare function collectChainThinkingOverrides(chain: MaterializedChainStep[], thinkingOverrideForTask: ForkThinkingOverrideForTask, dynamicFanoutMaxItems?: number): (ChildRuntimeConfig["thinking"] | undefined)[];
|
|
12
|
+
export declare function wrapChainTasksForFork(chain: MaterializedChainStep[], contextPolicy: AgentDefaultContextPolicy): MaterializedChainStep[];
|
|
13
|
+
export declare function preflightForkSessionsForStaticTasks(params: MaterializedParams, contextPolicy: AgentDefaultContextPolicy, sessionFileForTask: ForkSessionFileForTask, dynamicFanoutMaxItems?: number): void;
|
|
14
|
+
//# sourceMappingURL=fork-policy.d.ts.map
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { isParallelStep, isDynamicParallelStep } from "../../shared/settings.js";
|
|
2
|
+
import { lunrContextPolicy } from "../../shared/lunr-child-context.js";
|
|
3
|
+
import { wrapForkTask } from "../../shared/types.js";
|
|
4
|
+
export function resolveAgentDefaultContextPolicy(params) {
|
|
5
|
+
// lunr: hide fork from the model; force every child to fresh. Fork internals stay.
|
|
6
|
+
return lunrContextPolicy(params);
|
|
7
|
+
}
|
|
8
|
+
export function resolveExplicitContextPolicy(params) {
|
|
9
|
+
// lunr: `context: "fork"` from the model is coerced to fresh.
|
|
10
|
+
return lunrContextPolicy(params);
|
|
11
|
+
}
|
|
12
|
+
export function shouldForkAgent(contextPolicy, agentName) {
|
|
13
|
+
return contextPolicy.contextForAgent(agentName) === "fork";
|
|
14
|
+
}
|
|
15
|
+
export function withForkContext(result, context) {
|
|
16
|
+
if (context !== "fork" || !result.details)
|
|
17
|
+
return result;
|
|
18
|
+
return {
|
|
19
|
+
...result,
|
|
20
|
+
details: {
|
|
21
|
+
...result.details,
|
|
22
|
+
context: "fork",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function withForkThinkingNotes(result, downgrades) {
|
|
27
|
+
if (downgrades.size === 0)
|
|
28
|
+
return result;
|
|
29
|
+
const children = [...downgrades.entries()]
|
|
30
|
+
.sort(([a], [b]) => a - b)
|
|
31
|
+
.map(([index, agent]) => `${agent} (child ${index})`)
|
|
32
|
+
.join(", ");
|
|
33
|
+
const note = `Note: fork context forced thinking off for ${children}. The forked transcript contained signed Anthropic thinking blocks that were sanitized, and Anthropic children cannot resume such a transcript with thinking enabled. Use context: "fresh" when an Anthropic child needs thinking.`;
|
|
34
|
+
return { ...result, content: [...result.content, { type: "text", text: note }] };
|
|
35
|
+
}
|
|
36
|
+
export function collectChainSessionFiles(chain, sessionFileForTask, dynamicFanoutMaxItems) {
|
|
37
|
+
const sessionFiles = [];
|
|
38
|
+
let flatIndex = 0;
|
|
39
|
+
for (const step of chain) {
|
|
40
|
+
if (isParallelStep(step)) {
|
|
41
|
+
for (const task of step.parallel) {
|
|
42
|
+
sessionFiles.push(sessionFileForTask(task.agent, flatIndex, task.model));
|
|
43
|
+
flatIndex++;
|
|
44
|
+
}
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (isDynamicParallelStep(step)) {
|
|
48
|
+
const maxItems = step.expand.maxItems ?? dynamicFanoutMaxItems ?? 0;
|
|
49
|
+
for (let itemIndex = 0; itemIndex < maxItems; itemIndex++) {
|
|
50
|
+
sessionFiles.push(sessionFileForTask(step.parallel.agent, flatIndex, step.parallel.model));
|
|
51
|
+
flatIndex++;
|
|
52
|
+
}
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const sequential = step;
|
|
56
|
+
sessionFiles.push(sessionFileForTask(sequential.agent, flatIndex, sequential.model));
|
|
57
|
+
flatIndex++;
|
|
58
|
+
}
|
|
59
|
+
return sessionFiles;
|
|
60
|
+
}
|
|
61
|
+
export function collectChainThinkingOverrides(chain, thinkingOverrideForTask, dynamicFanoutMaxItems) {
|
|
62
|
+
const thinkingOverrides = [];
|
|
63
|
+
let flatIndex = 0;
|
|
64
|
+
for (const step of chain) {
|
|
65
|
+
if (isParallelStep(step)) {
|
|
66
|
+
for (const task of step.parallel) {
|
|
67
|
+
thinkingOverrides.push(thinkingOverrideForTask(task.agent, flatIndex, task.model));
|
|
68
|
+
flatIndex++;
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (isDynamicParallelStep(step)) {
|
|
73
|
+
const maxItems = step.expand.maxItems ?? dynamicFanoutMaxItems ?? 0;
|
|
74
|
+
for (let itemIndex = 0; itemIndex < maxItems; itemIndex++) {
|
|
75
|
+
thinkingOverrides.push(thinkingOverrideForTask(step.parallel.agent, flatIndex, step.parallel.model));
|
|
76
|
+
flatIndex++;
|
|
77
|
+
}
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const sequential = step;
|
|
81
|
+
thinkingOverrides.push(thinkingOverrideForTask(sequential.agent, flatIndex, sequential.model));
|
|
82
|
+
flatIndex++;
|
|
83
|
+
}
|
|
84
|
+
return thinkingOverrides;
|
|
85
|
+
}
|
|
86
|
+
export function wrapChainTasksForFork(chain, contextPolicy) {
|
|
87
|
+
return chain.map((step, stepIndex) => {
|
|
88
|
+
if (isParallelStep(step)) {
|
|
89
|
+
return {
|
|
90
|
+
...step,
|
|
91
|
+
parallel: step.parallel.map((task) => ({
|
|
92
|
+
...task,
|
|
93
|
+
task: shouldForkAgent(contextPolicy, task.agent)
|
|
94
|
+
? wrapForkTask(task.task ?? "{previous}")
|
|
95
|
+
: task.task,
|
|
96
|
+
})),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (isDynamicParallelStep(step)) {
|
|
100
|
+
return {
|
|
101
|
+
...step,
|
|
102
|
+
parallel: {
|
|
103
|
+
...step.parallel,
|
|
104
|
+
task: shouldForkAgent(contextPolicy, step.parallel.agent)
|
|
105
|
+
? wrapForkTask(step.parallel.task ?? "{previous}")
|
|
106
|
+
: step.parallel.task,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const sequential = step;
|
|
111
|
+
return {
|
|
112
|
+
...sequential,
|
|
113
|
+
task: shouldForkAgent(contextPolicy, sequential.agent)
|
|
114
|
+
? wrapForkTask(sequential.task ?? (stepIndex === 0 ? "{task}" : "{previous}"))
|
|
115
|
+
: sequential.task,
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
export function preflightForkSessionsForStaticTasks(params, contextPolicy, sessionFileForTask, dynamicFanoutMaxItems) {
|
|
120
|
+
if (!contextPolicy.usesFork)
|
|
121
|
+
return;
|
|
122
|
+
if (params.agent) {
|
|
123
|
+
if (shouldForkAgent(contextPolicy, params.agent))
|
|
124
|
+
sessionFileForTask(params.agent, 0, params.model);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (params.tasks) {
|
|
128
|
+
params.tasks.forEach((task, index) => {
|
|
129
|
+
if (shouldForkAgent(contextPolicy, task.agent))
|
|
130
|
+
sessionFileForTask(task.agent, index, task.model);
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!params.chain?.length)
|
|
135
|
+
return;
|
|
136
|
+
let flatIndex = 0;
|
|
137
|
+
for (const step of params.chain) {
|
|
138
|
+
if (isParallelStep(step)) {
|
|
139
|
+
for (const task of step.parallel) {
|
|
140
|
+
if (shouldForkAgent(contextPolicy, task.agent))
|
|
141
|
+
sessionFileForTask(task.agent, flatIndex, task.model);
|
|
142
|
+
flatIndex++;
|
|
143
|
+
}
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (isDynamicParallelStep(step)) {
|
|
147
|
+
const maxItems = step.expand.maxItems ?? dynamicFanoutMaxItems ?? 0;
|
|
148
|
+
if (shouldForkAgent(contextPolicy, step.parallel.agent)) {
|
|
149
|
+
for (let itemIndex = 0; itemIndex < maxItems; itemIndex++)
|
|
150
|
+
sessionFileForTask(step.parallel.agent, flatIndex + itemIndex, step.parallel.model);
|
|
151
|
+
}
|
|
152
|
+
flatIndex += maxItems;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const sequential = step;
|
|
156
|
+
if (shouldForkAgent(contextPolicy, sequential.agent))
|
|
157
|
+
sessionFileForTask(sequential.agent, flatIndex, sequential.model);
|
|
158
|
+
flatIndex++;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=fork-policy.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AgentToolResult } from "@ashx-j/lunr-agent";
|
|
2
|
+
import { type NestedRunResolutionScope } from "../shared/nested-events.ts";
|
|
3
|
+
import type { ResolvedSubagentRunId } from "../background/run-id-resolver.ts";
|
|
4
|
+
import { type Details } from "../../shared/types.ts";
|
|
5
|
+
import type { ExecutorDeps } from "./executor-types.ts";
|
|
6
|
+
export declare function nestedResolutionScopeForExecutor(deps: ExecutorDeps): NestedRunResolutionScope | undefined;
|
|
7
|
+
export type NoRecordedChildConfig = {
|
|
8
|
+
childId?: undefined;
|
|
9
|
+
description?: undefined;
|
|
10
|
+
permissions?: undefined;
|
|
11
|
+
model?: undefined;
|
|
12
|
+
thinking?: undefined;
|
|
13
|
+
modelSelection?: undefined;
|
|
14
|
+
};
|
|
15
|
+
export type NestedResumeSourceTarget = {
|
|
16
|
+
kind: "revive";
|
|
17
|
+
source: "nested";
|
|
18
|
+
runId: string;
|
|
19
|
+
state: "complete" | "failed" | "paused" | "stopped";
|
|
20
|
+
agent: string;
|
|
21
|
+
index: number;
|
|
22
|
+
intercomTarget: string;
|
|
23
|
+
cwd?: string;
|
|
24
|
+
sessionFile: string;
|
|
25
|
+
} & NoRecordedChildConfig;
|
|
26
|
+
export declare function resolveNestedResumeTarget(match: ResolvedSubagentRunId & {
|
|
27
|
+
kind: "nested";
|
|
28
|
+
}, trustedSessionRoots: string[]): NestedResumeSourceTarget;
|
|
29
|
+
export declare function interruptNestedRun(target: ResolvedSubagentRunId & {
|
|
30
|
+
kind: "nested";
|
|
31
|
+
}): Promise<AgentToolResult<Details>>;
|
|
32
|
+
export declare function resumeLiveNestedRun(input: {
|
|
33
|
+
target: ResolvedSubagentRunId & {
|
|
34
|
+
kind: "nested";
|
|
35
|
+
};
|
|
36
|
+
message: string;
|
|
37
|
+
}): Promise<AgentToolResult<Details>>;
|
|
38
|
+
export declare function steerNestedRun(input: {
|
|
39
|
+
target: ResolvedSubagentRunId & {
|
|
40
|
+
kind: "nested";
|
|
41
|
+
};
|
|
42
|
+
message: string;
|
|
43
|
+
index?: number;
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
}): Promise<AgentToolResult<Details>>;
|
|
46
|
+
//# sourceMappingURL=nested-run-control.d.ts.map
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// Resolves, interrupts, resumes and steers nested runs: async runs started by a subagent child.
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { resolveSubagentIntercomTarget } from "../../intercom/intercom-bridge.js";
|
|
6
|
+
import { deliverInterruptRequest, requestAsyncSteer } from "../background/control-channel.js";
|
|
7
|
+
import { waitForSteeringAction } from "../background/steering.js";
|
|
8
|
+
import { reconcileAsyncRun } from "../background/stale-run-reconciler.js";
|
|
9
|
+
import { resolveInheritedNestedRouteFromEnv, resolveNestedParentAddressFromEnv, resolveNestedAsyncDir, readNestedControlResults, writeNestedControlRequest } from "../shared/nested-events.js";
|
|
10
|
+
import { RESULTS_DIR } from "../../shared/types.js";
|
|
11
|
+
export function nestedResolutionScopeForExecutor(deps) {
|
|
12
|
+
if (deps.allowMutatingManagementActions !== false)
|
|
13
|
+
return undefined;
|
|
14
|
+
const route = resolveInheritedNestedRouteFromEnv();
|
|
15
|
+
const address = route ? resolveNestedParentAddressFromEnv() : undefined;
|
|
16
|
+
return {
|
|
17
|
+
routes: route ? [route] : [],
|
|
18
|
+
...(address ? { descendantOf: { parentRunId: address.parentRunId, ...(address.parentStepIndex !== undefined ? { parentStepIndex: address.parentStepIndex } : {}) } } : {}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function nestedRunSessionFile(run) {
|
|
22
|
+
return run.sessionFile ?? (run.steps?.length === 1 ? run.steps[0]?.sessionFile : undefined);
|
|
23
|
+
}
|
|
24
|
+
function nestedRunAgent(run) {
|
|
25
|
+
return run.agent ?? run.agents?.[0] ?? (run.steps?.length === 1 ? run.steps[0]?.agent : undefined);
|
|
26
|
+
}
|
|
27
|
+
function pathWithin(base, candidate) {
|
|
28
|
+
const resolvedBase = path.resolve(base);
|
|
29
|
+
const resolvedCandidate = path.resolve(candidate);
|
|
30
|
+
return resolvedCandidate === resolvedBase || resolvedCandidate.startsWith(`${resolvedBase}${path.sep}`);
|
|
31
|
+
}
|
|
32
|
+
function validateNestedSessionFile(run, trustedSessionRoots) {
|
|
33
|
+
const sessionFile = nestedRunSessionFile(run);
|
|
34
|
+
if (!sessionFile)
|
|
35
|
+
throw new Error(`Nested run '${run.id}' does not have a persisted session file to resume from.`);
|
|
36
|
+
if (path.extname(sessionFile) !== ".jsonl")
|
|
37
|
+
throw new Error(`Nested run '${run.id}' session file must be a .jsonl file: ${sessionFile}`);
|
|
38
|
+
const resolved = path.resolve(sessionFile);
|
|
39
|
+
if (!path.isAbsolute(sessionFile))
|
|
40
|
+
throw new Error(`Nested run '${run.id}' session file must be absolute: ${sessionFile}`);
|
|
41
|
+
if (!fs.existsSync(resolved))
|
|
42
|
+
throw new Error(`Nested run '${run.id}' session file does not exist: ${sessionFile}`);
|
|
43
|
+
const stat = fs.lstatSync(resolved);
|
|
44
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
45
|
+
throw new Error(`Nested run '${run.id}' session file is not a regular file: ${sessionFile}`);
|
|
46
|
+
const realSessionFile = fs.realpathSync(resolved);
|
|
47
|
+
const trustedRoots = trustedSessionRoots
|
|
48
|
+
.filter((root) => fs.existsSync(root))
|
|
49
|
+
.map((root) => fs.realpathSync(root));
|
|
50
|
+
if (!trustedRoots.some((root) => pathWithin(root, realSessionFile))) {
|
|
51
|
+
throw new Error(`Nested run '${run.id}' session file is outside trusted nested session roots: ${sessionFile}`);
|
|
52
|
+
}
|
|
53
|
+
if (!realSessionFile.split(path.sep).includes(run.id)) {
|
|
54
|
+
throw new Error(`Nested run '${run.id}' session file is not under that nested run's session directory: ${sessionFile}`);
|
|
55
|
+
}
|
|
56
|
+
return realSessionFile;
|
|
57
|
+
}
|
|
58
|
+
export function resolveNestedResumeTarget(match, trustedSessionRoots) {
|
|
59
|
+
const run = match.match.run;
|
|
60
|
+
if (run.state === "running" || run.state === "queued")
|
|
61
|
+
throw new Error(`Nested run '${run.id}' is live; route the follow-up to the owner process instead.`);
|
|
62
|
+
const agent = nestedRunAgent(run);
|
|
63
|
+
if (!agent)
|
|
64
|
+
throw new Error(`Could not determine child agent for nested run '${run.id}'.`);
|
|
65
|
+
const state = run.state === "complete" || run.state === "failed" || run.state === "paused" || run.state === "stopped" ? run.state : "failed";
|
|
66
|
+
const asyncDir = resolveNestedAsyncDir(match.match.rootRunId, run);
|
|
67
|
+
return {
|
|
68
|
+
kind: "revive",
|
|
69
|
+
source: "nested",
|
|
70
|
+
runId: run.id,
|
|
71
|
+
state,
|
|
72
|
+
agent,
|
|
73
|
+
index: 0,
|
|
74
|
+
intercomTarget: resolveSubagentIntercomTarget(run.id, agent, 0),
|
|
75
|
+
cwd: asyncDir ? path.dirname(asyncDir) : undefined,
|
|
76
|
+
sessionFile: validateNestedSessionFile(run, trustedSessionRoots),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function waitForNestedControlResult(target, requestId, timeoutMs = 1_000) {
|
|
80
|
+
const deadline = Date.now() + timeoutMs;
|
|
81
|
+
while (Date.now() < deadline) {
|
|
82
|
+
const result = readNestedControlResults(target.match.route).find((candidate) => candidate.requestId === requestId && candidate.targetRunId === target.match.run.id);
|
|
83
|
+
if (result)
|
|
84
|
+
return result;
|
|
85
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
async function sendNestedControlRequest(target, action, message) {
|
|
90
|
+
const requestId = randomUUID();
|
|
91
|
+
writeNestedControlRequest(target.match.route, {
|
|
92
|
+
ts: Date.now(),
|
|
93
|
+
requestId,
|
|
94
|
+
targetRunId: target.match.run.id,
|
|
95
|
+
action,
|
|
96
|
+
...(message ? { message } : {}),
|
|
97
|
+
});
|
|
98
|
+
return waitForNestedControlResult(target, requestId);
|
|
99
|
+
}
|
|
100
|
+
function directNestedAsyncInterrupt(target) {
|
|
101
|
+
const run = target.match.run;
|
|
102
|
+
const asyncDir = resolveNestedAsyncDir(target.match.rootRunId, run);
|
|
103
|
+
if (!asyncDir)
|
|
104
|
+
return undefined;
|
|
105
|
+
const status = reconcileAsyncRun(asyncDir, { resultsDir: path.join(RESULTS_DIR, "nested", target.match.rootRunId) }).status;
|
|
106
|
+
const pid = typeof status?.pid === "number" && status.pid > 0 ? status.pid : run.pid;
|
|
107
|
+
if (!status || status.state !== "running" || typeof pid !== "number" || pid <= 0)
|
|
108
|
+
return undefined;
|
|
109
|
+
try {
|
|
110
|
+
deliverInterruptRequest({ asyncDir, pid, source: "nested-interrupt" });
|
|
111
|
+
return { content: [{ type: "text", text: `Interrupt requested for nested async run ${run.id}.` }], details: { mode: "management", results: [] } };
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
115
|
+
return { content: [{ type: "text", text: `Failed to interrupt nested async run ${run.id}: ${message}` }], isError: true, details: { mode: "management", results: [] } };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async function directNestedAsyncSteer(input) {
|
|
119
|
+
const run = input.target.match.run;
|
|
120
|
+
const asyncDir = resolveNestedAsyncDir(input.target.match.rootRunId, run);
|
|
121
|
+
if (!asyncDir)
|
|
122
|
+
return undefined;
|
|
123
|
+
const status = reconcileAsyncRun(asyncDir, { resultsDir: path.join(RESULTS_DIR, "nested", input.target.match.rootRunId) }).status;
|
|
124
|
+
if (!status || (status.state !== "running" && status.state !== "queued"))
|
|
125
|
+
return undefined;
|
|
126
|
+
const steps = status.steps ?? [];
|
|
127
|
+
if (input.index !== undefined) {
|
|
128
|
+
if (input.index < 0 || input.index >= steps.length)
|
|
129
|
+
return { content: [{ type: "text", text: `Nested async run ${run.id} has ${steps.length} children. Index ${input.index} is out of range.` }], isError: true, details: { mode: "management", results: [] } };
|
|
130
|
+
const step = steps[input.index];
|
|
131
|
+
if (step && step.status !== "running" && step.status !== "pending")
|
|
132
|
+
return { content: [{ type: "text", text: `Nested async run ${run.id} child ${input.index} is ${step.status} and cannot be steered.` }], isError: true, details: { mode: "management", results: [] } };
|
|
133
|
+
}
|
|
134
|
+
const runningIndexes = steps
|
|
135
|
+
.map((step, index) => step.status === "running" ? index : undefined)
|
|
136
|
+
.filter((index) => index !== undefined);
|
|
137
|
+
const effectiveTargetIndex = input.index ?? (status.mode === "single" && runningIndexes.length === 0 && steps[0]?.status === "pending" ? 0 : undefined);
|
|
138
|
+
const targetIndexes = effectiveTargetIndex !== undefined ? [effectiveTargetIndex] : runningIndexes;
|
|
139
|
+
if (targetIndexes.length === 0)
|
|
140
|
+
return { content: [{ type: "text", text: `Nested async run ${run.id} has no running child to steer.` }], isError: true, details: { mode: "management", results: [] } };
|
|
141
|
+
const requestId = randomUUID();
|
|
142
|
+
try {
|
|
143
|
+
requestAsyncSteer(asyncDir, {
|
|
144
|
+
message: input.message,
|
|
145
|
+
...(effectiveTargetIndex !== undefined ? { targetIndex: effectiveTargetIndex } : { targetIndexes }),
|
|
146
|
+
source: "nested-steer",
|
|
147
|
+
id: requestId,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return { content: [{ type: "text", text: `Failed to queue steering for nested async run ${run.id}: ${error instanceof Error ? error.message : String(error)}` }], isError: true, details: { mode: "management", results: [] } };
|
|
152
|
+
}
|
|
153
|
+
const targets = targetIndexes.map((index) => ({ index, state: steps[index]?.status === "pending" ? "scheduled" : "pending" }));
|
|
154
|
+
if (targets.every((target) => target.state === "scheduled")) {
|
|
155
|
+
const scheduled = { requestId, state: "scheduled", sourceRunId: run.id, targets };
|
|
156
|
+
return { content: [{ type: "text", text: `Steering scheduled for nested async run ${run.id} (request ${requestId}).` }], details: { mode: "management", results: [], steering: scheduled } };
|
|
157
|
+
}
|
|
158
|
+
const waited = await waitForSteeringAction({ asyncDir, sourceRunId: run.id, requestId, timeoutMs: 3_000, signal: input.signal });
|
|
159
|
+
const result = waited ?? { requestId, state: "pending", sourceRunId: run.id, targets };
|
|
160
|
+
const stateText = result.state === "delivered" ? "delivered" : result.state === "failed" ? "failed" : result.state === "partial" ? "partial" : "pending";
|
|
161
|
+
return { content: [{ type: "text", text: `Steering ${stateText} for nested async run ${run.id} (request ${requestId}).` }], ...(result.state === "failed" || result.state === "partial" ? { isError: true } : {}), details: { mode: "management", results: [], steering: result } };
|
|
162
|
+
}
|
|
163
|
+
export async function interruptNestedRun(target) {
|
|
164
|
+
const run = target.match.run;
|
|
165
|
+
if (run.state === "complete")
|
|
166
|
+
return { content: [{ type: "text", text: `Nested run ${run.id} is already complete and cannot be interrupted.` }], isError: true, details: { mode: "management", results: [] } };
|
|
167
|
+
if (run.state === "failed")
|
|
168
|
+
return { content: [{ type: "text", text: `Nested run ${run.id} has failed and cannot be interrupted.` }], isError: true, details: { mode: "management", results: [] } };
|
|
169
|
+
if (run.state === "paused")
|
|
170
|
+
return { content: [{ type: "text", text: `Nested run ${run.id} is already paused.` }], isError: true, details: { mode: "management", results: [] } };
|
|
171
|
+
const result = await sendNestedControlRequest(target, "interrupt");
|
|
172
|
+
if (result)
|
|
173
|
+
return { content: [{ type: "text", text: result.message }], isError: result.ok ? undefined : true, details: { mode: "management", results: [] } };
|
|
174
|
+
const direct = directNestedAsyncInterrupt(target);
|
|
175
|
+
if (direct)
|
|
176
|
+
return direct;
|
|
177
|
+
return { content: [{ type: "text", text: `Nested run ${run.id} owner is not reachable and no safe direct async interrupt fallback is available.` }], isError: true, details: { mode: "management", results: [] } };
|
|
178
|
+
}
|
|
179
|
+
export async function resumeLiveNestedRun(input) {
|
|
180
|
+
const run = input.target.match.run;
|
|
181
|
+
const result = await sendNestedControlRequest(input.target, "resume", input.message);
|
|
182
|
+
if (result)
|
|
183
|
+
return { content: [{ type: "text", text: result.message }], isError: result.ok ? undefined : true, details: { mode: "management", results: [] } };
|
|
184
|
+
return { content: [{ type: "text", text: `Nested run ${run.id} appears live but its owner route is not reachable. Wait for completion, then retry action='resume'.` }], isError: true, details: { mode: "management", results: [] } };
|
|
185
|
+
}
|
|
186
|
+
export async function steerNestedRun(input) {
|
|
187
|
+
const run = input.target.match.run;
|
|
188
|
+
if (run.state !== "running" && run.state !== "queued")
|
|
189
|
+
return { content: [{ type: "text", text: `Nested run ${run.id} is ${run.state} and cannot be steered.` }], isError: true, details: { mode: "management", results: [] } };
|
|
190
|
+
const direct = await directNestedAsyncSteer(input);
|
|
191
|
+
if (direct)
|
|
192
|
+
return direct;
|
|
193
|
+
return { content: [{ type: "text", text: `Nested run ${run.id} is not a live async Pi child session with a steering inbox. action='steer' cannot target foreground nested runs.` }], isError: true, details: { mode: "management", results: [] } };
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=nested-run-control.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AgentToolResult } from "@ashx-j/lunr-agent";
|
|
2
|
+
import { type Details } from "../../shared/types.ts";
|
|
3
|
+
import type { ExecutionContextData, ExecutorDeps } from "./executor-types.ts";
|
|
4
|
+
export declare function buildParallelModeError(message: string): AgentToolResult<Details>;
|
|
5
|
+
export declare function buildParallelWorktreeTaskCwdError(tasks: ReadonlyArray<{
|
|
6
|
+
agent: string;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
}>, sharedCwd: string): string | undefined;
|
|
9
|
+
export declare function runParallelPath(data: ExecutionContextData, deps: ExecutorDeps): Promise<AgentToolResult<Details>>;
|
|
10
|
+
//# sourceMappingURL=parallel-run.d.ts.map
|