@ashx-j/lunr-dev 0.2.40-dev.54.2 → 0.2.40-dev.55.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.
Files changed (36) hide show
  1. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/async-run-control.d.ts +19 -0
  2. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/async-run-control.js +331 -0
  3. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution-input.d.ts +37 -0
  4. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution-input.js +321 -0
  5. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/executor-types.d.ts +124 -0
  6. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/executor-types.js +2 -0
  7. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/foreground-notifications.d.ts +17 -0
  8. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/foreground-notifications.js +98 -0
  9. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/foreground-run-registry.d.ts +40 -0
  10. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/foreground-run-registry.js +172 -0
  11. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/fork-policy.d.ts +14 -0
  12. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/fork-policy.js +161 -0
  13. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/nested-run-control.d.ts +46 -0
  14. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/nested-run-control.js +195 -0
  15. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/parallel-run.d.ts +10 -0
  16. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/parallel-run.js +537 -0
  17. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts +5 -81
  18. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +26 -1763
  19. package/dist/builtin-extensions/pi-subagents/src/shared/settings.d.ts +1 -1
  20. package/dist/node-runtime/{builtin-extensions-VQHK3YKF.js → builtin-extensions-YJ7F6GND.js} +1 -1
  21. package/dist/node-runtime/{chunk-YDY7A2WB.js → chunk-3UQ7ZNLI.js} +2 -2
  22. package/dist/node-runtime/{chunk-UZMXBZQT.js → chunk-5HVA5ECB.js} +3 -3
  23. package/dist/node-runtime/{chunk-VIYDTWDK.js → chunk-CDILDA4F.js} +604 -602
  24. package/dist/node-runtime/{chunk-MFDTF25H.js → chunk-G3PARFR4.js} +2 -2
  25. package/dist/node-runtime/{command-SRDEBPUR.js → command-H52R5R2G.js} +1 -1
  26. package/dist/node-runtime/{gateway-AMEMDTUT.js → gateway-OHPDCOOB.js} +1 -1
  27. package/dist/node-runtime/index.js +2 -2
  28. package/dist/node-runtime/{lunr-cron-OMQBN3UK.js → lunr-cron-SV2EXYKV.js} +1 -1
  29. package/dist/node-runtime/main.js +2 -2
  30. package/dist/node-runtime/{pi-subagents-36KOL5SV.js → pi-subagents-WS6OU5MG.js} +2 -2
  31. package/dist/node-runtime/rpc-entry.js +2 -2
  32. package/dist/node-runtime/{subagent-executor-D42G55F5.js → subagent-executor-LPVOWPMG.js} +1920 -1897
  33. package/install-lock/package-lock.json +24 -24
  34. package/install-lock/package.json +2 -2
  35. package/npm-shrinkwrap.json +12 -12
  36. package/package.json +4 -4
@@ -0,0 +1,19 @@
1
+ import type { AgentToolResult } from "@ashx-j/lunr-agent";
2
+ import type { ExtensionContext } from "@ashx-j/lunr-dev";
3
+ import { type SubagentState, type Details } from "../../shared/types.ts";
4
+ import type { SubagentParamsLike, ExecutorDeps } from "./executor-types.ts";
5
+ export declare function interruptAsyncRun(state: SubagentState, runId: string | undefined, kill?: (pid: number, signal?: NodeJS.Signals | 0) => boolean, location?: {
6
+ asyncDir: string | null;
7
+ resolvedId?: string;
8
+ }): AgentToolResult<Details> | null;
9
+ export declare function stopAsyncRun(state: SubagentState, runId: string | undefined, kill?: (pid: number, signal?: NodeJS.Signals | 0) => boolean, location?: {
10
+ asyncDir: string | null;
11
+ resolvedId?: string;
12
+ }): AgentToolResult<Details> | null;
13
+ export declare function appendStepToAsyncChain(input: {
14
+ params: SubagentParamsLike;
15
+ requestCwd: string;
16
+ ctx: ExtensionContext;
17
+ deps: ExecutorDeps;
18
+ }): AgentToolResult<Details>;
19
+ //# sourceMappingURL=async-run-control.d.ts.map
@@ -0,0 +1,331 @@
1
+ // Interrupt, stop and append-step for async runs that are already running.
2
+ import { randomUUID } from "node:crypto";
3
+ import * as path from "node:path";
4
+ import { snapshotParentPermissionMode } from "../../../../../core/subagent-permission-inherit.js";
5
+ import { readStatus } from "../../shared/utils.js";
6
+ import { toModelInfo } from "../../shared/model-info.js";
7
+ import { normalizeSkillInput } from "../../agents/skills.js";
8
+ import { buildAsyncRunnerSteps } from "../background/async-execution.js";
9
+ import { readPendingChainAppendRequests, runnerStepOutputNames, enqueueChainAppendRequest } from "../background/chain-append.js";
10
+ import { validateChainOutputBindingsWithContext, ChainOutputValidationError } from "../shared/chain-outputs.js";
11
+ import { validateExecutionAcceptance } from "../shared/acceptance.js";
12
+ import { resolveCurrentSessionId } from "../../shared/session-identity.js";
13
+ import { deliverInterruptRequest, deliverStopRequest } from "../background/control-channel.js";
14
+ import { reconcileAsyncRun } from "../background/stale-run-reconciler.js";
15
+ import { resolveSubagentRunId } from "../background/run-id-resolver.js";
16
+ import { resolveCurrentMaxSubagentDepth } from "../../shared/types.js";
17
+ import { internalizePromptDrivenChildren } from "./execution-input.js";
18
+ import { resolveExplicitContextPolicy, wrapChainTasksForFork } from "./fork-policy.js";
19
+ import { nestedResolutionScopeForExecutor } from "./nested-run-control.js";
20
+ function getAsyncInterruptTarget(state, runId, location) {
21
+ if (location?.asyncDir) {
22
+ return {
23
+ asyncId: location.resolvedId ?? runId ?? path.basename(location.asyncDir),
24
+ asyncDir: location.asyncDir,
25
+ };
26
+ }
27
+ if (runId) {
28
+ const direct = state.asyncJobs.get(runId);
29
+ if (direct)
30
+ return { asyncId: direct.asyncId, asyncDir: direct.asyncDir };
31
+ return undefined;
32
+ }
33
+ let newest;
34
+ for (const job of state.asyncJobs.values()) {
35
+ if (job.status !== "running")
36
+ continue;
37
+ if (!newest || (job.updatedAt ?? 0) > newest.updatedAt) {
38
+ newest = { asyncId: job.asyncId, asyncDir: job.asyncDir, updatedAt: job.updatedAt ?? 0 };
39
+ }
40
+ }
41
+ return newest ? { asyncId: newest.asyncId, asyncDir: newest.asyncDir } : undefined;
42
+ }
43
+ export function interruptAsyncRun(state, runId, kill, location) {
44
+ const target = getAsyncInterruptTarget(state, runId, location);
45
+ if (!target)
46
+ return null;
47
+ const status = reconcileAsyncRun(target.asyncDir, { kill }).status;
48
+ if (state.currentSessionId && status?.sessionId !== state.currentSessionId) {
49
+ return {
50
+ content: [{ type: "text", text: `Async run '${target.asyncId}' was not found in the active session.` }],
51
+ isError: true,
52
+ details: { mode: "management", results: [] },
53
+ };
54
+ }
55
+ if (!status || status.state !== "running" || typeof status.pid !== "number") {
56
+ return {
57
+ content: [{ type: "text", text: `No running async run with an interrupt-capable pid was found for '${runId ?? "current"}'.` }],
58
+ isError: true,
59
+ details: { mode: "management", results: [] },
60
+ };
61
+ }
62
+ try {
63
+ deliverInterruptRequest({ asyncDir: target.asyncDir, pid: status.pid, kill, source: "interrupt-action" });
64
+ const tracked = state.asyncJobs.get(target.asyncId);
65
+ if (tracked) {
66
+ tracked.activityState = undefined;
67
+ tracked.updatedAt = Date.now();
68
+ }
69
+ return {
70
+ content: [{ type: "text", text: `Interrupt requested for async run ${target.asyncId}.` }],
71
+ details: { mode: "management", results: [] },
72
+ };
73
+ }
74
+ catch (error) {
75
+ const message = error instanceof Error ? error.message : String(error);
76
+ return {
77
+ content: [{ type: "text", text: `Failed to interrupt async run ${target.asyncId}: ${message}` }],
78
+ isError: true,
79
+ details: { mode: "management", results: [] },
80
+ };
81
+ }
82
+ }
83
+ export function stopAsyncRun(state, runId, kill, location) {
84
+ const target = getAsyncInterruptTarget(state, runId, location);
85
+ if (!target)
86
+ return null;
87
+ const status = reconcileAsyncRun(target.asyncDir, { kill }).status;
88
+ if (state.currentSessionId && status?.sessionId !== state.currentSessionId) {
89
+ return {
90
+ content: [{ type: "text", text: `Async run '${target.asyncId}' was not found in the active session.` }],
91
+ isError: true,
92
+ details: { mode: "management", results: [] },
93
+ };
94
+ }
95
+ if (!status || (status.state !== "running" && status.state !== "queued")) {
96
+ return {
97
+ content: [{ type: "text", text: `No running or queued async run was found for '${runId ?? "current"}'.` }],
98
+ isError: true,
99
+ details: { mode: "management", results: [] },
100
+ };
101
+ }
102
+ try {
103
+ deliverStopRequest({ asyncDir: target.asyncDir, pid: typeof status.pid === "number" ? status.pid : undefined, kill, source: "stop-action" });
104
+ const tracked = state.asyncJobs.get(target.asyncId);
105
+ if (tracked) {
106
+ tracked.activityState = undefined;
107
+ tracked.updatedAt = Date.now();
108
+ }
109
+ return {
110
+ content: [{ type: "text", text: `Stop requested for async run ${target.asyncId}.` }],
111
+ details: { mode: "management", results: [] },
112
+ };
113
+ }
114
+ catch (error) {
115
+ const message = error instanceof Error ? error.message : String(error);
116
+ return {
117
+ content: [{ type: "text", text: `Failed to stop async run ${target.asyncId}: ${message}` }],
118
+ isError: true,
119
+ details: { mode: "management", results: [] },
120
+ };
121
+ }
122
+ }
123
+ function duplicateNames(names) {
124
+ const seen = new Set();
125
+ const duplicates = new Set();
126
+ for (const name of names) {
127
+ if (seen.has(name))
128
+ duplicates.add(name);
129
+ else
130
+ seen.add(name);
131
+ }
132
+ return [...duplicates];
133
+ }
134
+ export function appendStepToAsyncChain(input) {
135
+ const targetRunId = input.params.id ?? input.params.runId;
136
+ if (!targetRunId) {
137
+ return {
138
+ content: [{ type: "text", text: "action='append-step' requires id." }],
139
+ isError: true,
140
+ details: { mode: "management", results: [] },
141
+ };
142
+ }
143
+ if (!input.params.chain || input.params.chain.length !== 1) {
144
+ return {
145
+ content: [{ type: "text", text: "action='append-step' requires chain with exactly one step." }],
146
+ isError: true,
147
+ details: { mode: "management", results: [] },
148
+ };
149
+ }
150
+ // internalizePromptDrivenChildren would take the tasks branch and leave the chain step without its agent.
151
+ if ((input.params.tasks?.length ?? 0) > 0) {
152
+ return {
153
+ content: [{ type: "text", text: "action='append-step' takes chain only, not tasks." }],
154
+ isError: true,
155
+ details: { mode: "management", results: [] },
156
+ };
157
+ }
158
+ const acceptanceErrors = validateExecutionAcceptance(input.params);
159
+ if (acceptanceErrors.length > 0) {
160
+ return {
161
+ content: [{ type: "text", text: `Cannot append step: ${acceptanceErrors.join(" ")}` }],
162
+ isError: true,
163
+ details: { mode: "management", results: [] },
164
+ };
165
+ }
166
+ let resolved;
167
+ try {
168
+ resolved = resolveSubagentRunId(targetRunId, { state: input.deps.state, nested: nestedResolutionScopeForExecutor(input.deps) });
169
+ }
170
+ catch (error) {
171
+ const message = error instanceof Error ? error.message : String(error);
172
+ return { content: [{ type: "text", text: message }], isError: true, details: { mode: "management", results: [] } };
173
+ }
174
+ if (!resolved) {
175
+ return {
176
+ content: [{ type: "text", text: `No async chain run found for '${targetRunId}'.` }],
177
+ isError: true,
178
+ details: { mode: "management", results: [] },
179
+ };
180
+ }
181
+ if (resolved.kind !== "async" || !resolved.location.asyncDir) {
182
+ return {
183
+ content: [{ type: "text", text: `Run '${resolved.id}' is not an append-capable async chain run.` }],
184
+ isError: true,
185
+ details: { mode: "management", results: [] },
186
+ };
187
+ }
188
+ const status = readStatus(resolved.location.asyncDir);
189
+ if (!status) {
190
+ return {
191
+ content: [{ type: "text", text: `No async run status found for '${resolved.id}'.` }],
192
+ isError: true,
193
+ details: { mode: "management", results: [] },
194
+ };
195
+ }
196
+ if (status.mode !== "chain") {
197
+ return {
198
+ content: [{ type: "text", text: `Run '${resolved.id}' is ${status.mode}; only active chain runs accept appended steps.` }],
199
+ isError: true,
200
+ details: { mode: "management", results: [] },
201
+ };
202
+ }
203
+ if (status.state !== "running") {
204
+ return {
205
+ content: [{ type: "text", text: `Run '${resolved.id}' is ${status.state}; only running chain runs accept appended steps.` }],
206
+ isError: true,
207
+ details: { mode: "management", results: [] },
208
+ };
209
+ }
210
+ const stillInProgress = (status.steps ?? []).some((step) => step.status === "running" || step.status === "pending") || (status.pendingAppends ?? 0) > 0;
211
+ if (!stillInProgress) {
212
+ return {
213
+ content: [{ type: "text", text: `Run '${resolved.id}' has no running or pending chain steps left; append-step must target an in-progress chain.` }],
214
+ isError: true,
215
+ details: { mode: "management", results: [] },
216
+ };
217
+ }
218
+ const pendingAppendRequests = readPendingChainAppendRequests(resolved.location.asyncDir);
219
+ const reservedOutputNames = new Set([
220
+ ...Object.keys(status.outputs ?? {}),
221
+ ...(status.steps ?? []).map((step) => step.outputName).filter((name) => Boolean(name)),
222
+ ...pendingAppendRequests.flatMap((request) => runnerStepOutputNames(request.steps)),
223
+ ]);
224
+ try {
225
+ validateChainOutputBindingsWithContext(input.params.chain, { maxItems: input.deps.config.chain?.dynamicFanout?.maxItems }, {
226
+ priorOutputNames: reservedOutputNames,
227
+ startStepIndex: status.chainStepCount ?? status.steps?.length ?? 0,
228
+ });
229
+ }
230
+ catch (error) {
231
+ if (!(error instanceof ChainOutputValidationError))
232
+ throw error;
233
+ return {
234
+ content: [{ type: "text", text: `Cannot append step to run '${resolved.id}': ${error.message}` }],
235
+ isError: true,
236
+ details: { mode: "management", results: [] },
237
+ };
238
+ }
239
+ let appendParams;
240
+ const appendChildRunId = `${resolved.id}-append-${randomUUID().slice(0, 8)}`;
241
+ try {
242
+ appendParams = internalizePromptDrivenChildren(input.params, {
243
+ runId: appendChildRunId,
244
+ parentMode: snapshotParentPermissionMode(input.ctx.sessionManager.getSessionId() ?? undefined),
245
+ dynamicFanoutMaxItems: input.deps.config.chain?.dynamicFanout?.maxItems,
246
+ }).params;
247
+ }
248
+ catch (error) {
249
+ return {
250
+ content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
251
+ isError: true,
252
+ details: { mode: "management", results: [] },
253
+ };
254
+ }
255
+ const contextPolicy = resolveExplicitContextPolicy(appendParams);
256
+ const chainSkillInput = normalizeSkillInput(appendParams.skill);
257
+ const chainSkills = chainSkillInput === false ? [] : (chainSkillInput ?? []);
258
+ const asyncCtx = {
259
+ pi: input.deps.pi,
260
+ cwd: input.ctx.cwd,
261
+ currentSessionId: resolveCurrentSessionId(input.ctx.sessionManager),
262
+ parentSessionId: input.ctx.sessionManager.getSessionId() ?? undefined,
263
+ currentModelProvider: input.ctx.model?.provider,
264
+ currentModel: input.ctx.model,
265
+ modelScope: undefined,
266
+ };
267
+ const built = buildAsyncRunnerSteps(resolved.id, {
268
+ chain: wrapChainTasksForFork(appendParams.chain, contextPolicy),
269
+ task: appendParams.task,
270
+ resultMode: "chain",
271
+ ctx: asyncCtx,
272
+ availableModels: input.ctx.modelRegistry.getAvailable().map(toModelInfo),
273
+ cwd: status.cwd ?? input.requestCwd,
274
+ chainSkills,
275
+ dynamicFanoutMaxItems: input.deps.config.chain?.dynamicFanout?.maxItems,
276
+ maxSubagentDepth: resolveCurrentMaxSubagentDepth(input.deps.config.maxSubagentDepth),
277
+ waitToolEnabled: input.deps.waitToolEnabled,
278
+ asyncDir: resolved.location.asyncDir,
279
+ childIdRunId: appendChildRunId,
280
+ validateOutputBindings: false,
281
+ });
282
+ if ("error" in built) {
283
+ return {
284
+ content: [{ type: "text", text: built.error }],
285
+ isError: true,
286
+ details: { mode: "management", results: [] },
287
+ };
288
+ }
289
+ const appendedOutputNames = runnerStepOutputNames(built.steps);
290
+ const duplicateAppendedOutputs = duplicateNames(appendedOutputNames);
291
+ if (duplicateAppendedOutputs.length > 0) {
292
+ return {
293
+ content: [{ type: "text", text: `Cannot append step to run '${resolved.id}': duplicate output name in appended step: ${duplicateAppendedOutputs.join(", ")}.` }],
294
+ isError: true,
295
+ details: { mode: "management", results: [] },
296
+ };
297
+ }
298
+ const pendingOutputNames = new Set(pendingAppendRequests.flatMap((request) => runnerStepOutputNames(request.steps)));
299
+ const pendingDuplicateOutputs = appendedOutputNames.filter((name) => pendingOutputNames.has(name));
300
+ if (pendingDuplicateOutputs.length > 0) {
301
+ return {
302
+ content: [{ type: "text", text: `Cannot append step to run '${resolved.id}': output name already belongs to a pending append: ${pendingDuplicateOutputs.join(", ")}.` }],
303
+ isError: true,
304
+ details: { mode: "management", results: [] },
305
+ };
306
+ }
307
+ try {
308
+ const result = enqueueChainAppendRequest({
309
+ asyncDir: resolved.location.asyncDir,
310
+ runId: resolved.id,
311
+ steps: built.steps,
312
+ });
313
+ const stepText = built.steps.length === 1 ? "step" : "steps";
314
+ return {
315
+ content: [{
316
+ type: "text",
317
+ text: `Append queued for chain run ${resolved.id}: ${built.steps.length} ${stepText}. It becomes eligible after the chain's already-queued steps finish. Pending appends: ${result.pendingCount}.`,
318
+ }],
319
+ details: { mode: "management", results: [], asyncId: resolved.id, asyncDir: resolved.location.asyncDir },
320
+ };
321
+ }
322
+ catch (error) {
323
+ const message = error instanceof Error ? error.message : String(error);
324
+ return {
325
+ content: [{ type: "text", text: `Failed to append step to chain run ${resolved.id}: ${message}` }],
326
+ isError: true,
327
+ details: { mode: "management", results: [] },
328
+ };
329
+ }
330
+ }
331
+ //# sourceMappingURL=async-run-control.js.map
@@ -0,0 +1,37 @@
1
+ import type { AgentToolResult } from "@ashx-j/lunr-agent";
2
+ import type { Details, ChildRuntimeConfig, ResolvedToolBudget, ToolBudgetConfig } from "../../shared/types.ts";
3
+ import type { SubagentParamsLike, MaterializedParams } from "./executor-types.ts";
4
+ export declare function validateExecutionInput(params: SubagentParamsLike, hasChain: boolean, hasTasks: boolean, hasSingle: boolean, allowClarifyTaskPrompt: boolean): AgentToolResult<Details> | null;
5
+ export declare function validateExecutionChainBindings(params: SubagentParamsLike, dynamicFanoutMaxItems?: number): AgentToolResult<Details> | null;
6
+ export declare function buildRequestedModeError(params: SubagentParamsLike, message: string): AgentToolResult<Details>;
7
+ export declare function internalizePromptDrivenChildren(params: SubagentParamsLike, options: {
8
+ runId: string;
9
+ parentMode?: string;
10
+ dynamicFanoutMaxItems?: number;
11
+ }): {
12
+ params: MaterializedParams;
13
+ agents: ChildRuntimeConfig[];
14
+ };
15
+ export declare function resolveForegroundTimeout(params: SubagentParamsLike): {
16
+ timeoutMs?: number;
17
+ error?: string;
18
+ };
19
+ export declare function resolveToolBudget(raw: unknown, label?: string): {
20
+ toolBudget?: ResolvedToolBudget;
21
+ error?: string;
22
+ };
23
+ export declare function resolveEffectiveToolBudget(input: {
24
+ stepBudget?: ToolBudgetConfig;
25
+ runBudget?: ResolvedToolBudget;
26
+ agentBudget?: ToolBudgetConfig;
27
+ configBudget?: ToolBudgetConfig;
28
+ }): {
29
+ toolBudget?: ResolvedToolBudget;
30
+ error?: string;
31
+ };
32
+ export declare function normalizeRepeatedParallelCounts(params: SubagentParamsLike): {
33
+ params?: SubagentParamsLike;
34
+ error?: AgentToolResult<Details>;
35
+ };
36
+ export declare function toExecutionErrorResult(params: SubagentParamsLike, error: unknown): AgentToolResult<Details>;
37
+ //# sourceMappingURL=execution-input.d.ts.map