pi-subagents 0.87.0 → 0.88.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-3CVOAS77.js → chunk-2DIEL4WG.js} +2 -2
- package/bundle/{chunk-PGU4TZV3.js → chunk-3DT5X2QC.js} +406 -447
- package/bundle/{chunk-SIAQXPJ4.js → chunk-3MFYKBKI.js} +18 -6
- package/bundle/{chunk-AIL46SZU.js → chunk-47GJDBIK.js} +6 -4
- package/bundle/{chunk-ESWW6XSX.js → chunk-47ZN7NKR.js} +1 -1
- package/bundle/{chunk-C3KWLXDH.js → chunk-4MVDMA5C.js} +9 -1
- package/bundle/{chunk-DGTZKYIE.js → chunk-4PM6RDE5.js} +42 -29
- package/bundle/{chunk-EYGBK6CE.js → chunk-4UGWHREQ.js} +45 -15
- package/bundle/{chunk-HDICKROY.js → chunk-6EUQPQY7.js} +31 -14
- package/bundle/{chunk-LFKMM3UH.js → chunk-6OWNDN7R.js} +2 -2
- package/bundle/{chunk-M2VBGET6.js → chunk-6PR44R7E.js} +7 -2
- package/bundle/{chunk-OOE3R7IQ.js → chunk-CKLZ5FGU.js} +2 -2
- package/bundle/{chunk-W52LJANO.js → chunk-CYKNHFXB.js} +1 -1
- package/bundle/{chunk-6O7YH2QV.js → chunk-GDR2ILWY.js} +1 -1
- package/bundle/{chunk-2D2DQGC2.js → chunk-IZEKQEY4.js} +9 -9
- package/bundle/{chunk-C5QWQSSM.js → chunk-KXW62VBU.js} +1 -1
- package/bundle/{chunk-BFF6YDK6.js → chunk-L4YY2TOE.js} +1 -1
- package/bundle/{chunk-JLDQ6YUR.js → chunk-MTPICU4A.js} +11 -11
- package/bundle/{chunk-YEXKJJVS.js → chunk-PJSOS2Q4.js} +4 -4
- package/bundle/{chunk-2NY5PCKQ.js → chunk-RHYVKQQL.js} +4 -4
- package/bundle/{chunk-XV7RTWTS.js → chunk-SVIXQDIV.js} +20 -5
- package/bundle/{chunk-OTLDAYEQ.js → chunk-UVDLJXL6.js} +14 -5
- package/bundle/{chunk-VFUFOZBU.js → chunk-W6HIYD2Z.js} +1 -1
- package/bundle/{chunk-OZCPYJEY.js → chunk-XAOHLFJO.js} +118 -42
- package/bundle/{chunk-USRX7QXD.js → chunk-XIA5GSEU.js} +2 -2
- package/bundle/chunk-YDZ7BZD5.js +523 -0
- package/bundle/{chunk-LZKVUWIY.js → chunk-YZPVALSQ.js} +30 -5
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +1 -1
- package/docs/configuration.md +7 -3
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +4 -1
- package/package.json +2 -2
- package/skills/pi-subagents/SKILL.md +8 -2
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +12 -4
- package/src/agents/agents.d.ts +1 -0
- package/src/agents/agents.js +2 -2
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +6 -0
- package/src/extension/index.js +4 -3
- package/src/extension/schemas.d.ts +2 -0
- package/src/extension/schemas.js +1 -0
- package/src/extension/tool-activation.js +20 -3
- package/src/runs/background/async-resume.js +2 -1
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +11 -5
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- package/src/runs/background/run-child-session.d.ts +2 -2
- package/src/runs/background/run-child-session.js +4 -7
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +0 -2
- package/src/runs/background/subagent-runner.js +73 -58
- package/src/runs/foreground/async-steering-action.js +24 -9
- package/src/runs/foreground/execution.js +32 -15
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +1 -8
- package/src/runs/foreground/subagent-executor.js +6 -15
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- package/src/runs/shared/child-session.js +21 -3
- package/src/runs/shared/mcp-config-sources.d.ts +2 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -2
- package/src/runs/shared/mcp-direct-tool-allowlist.js +21 -11
- package/src/runs/shared/subagent-prompt-runtime.js +14 -2
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- package/src/shared/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +107 -9
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- package/src/shared/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +9 -0
- package/src/shared/utils.d.ts +3 -1
- package/src/shared/utils.js +4 -0
- package/src/tui/render.js +33 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +2 -1
- package/src/workflows/workflow-script-worker.js +3 -1
- package/bundle/chunk-XSDYTXHF.js +0 -242
|
@@ -5,9 +5,10 @@ import { alignForkedSessionCwd } from "../../shared/fork-session-cwd.js";
|
|
|
5
5
|
import { buildEffectiveSystemPrompt } from "../shared/effective-system-prompt.js";
|
|
6
6
|
import { ensureArtifactsDir, formatOutputArtifactContent, getArtifactPaths, writeArtifact, writeMetadata, } from "../../shared/artifacts.js";
|
|
7
7
|
import { createChildTranscriptWriter } from "../../shared/child-transcript.js";
|
|
8
|
+
import { extractReportedProgress } from "../../shared/reported-progress.js";
|
|
8
9
|
import { DEFAULT_MAX_OUTPUT, INTERCOM_DETACH_REQUEST_EVENT, INTERCOM_DETACH_RESPONSE_EVENT, truncateOutput, } from "../../shared/types.js";
|
|
9
10
|
import { DEFAULT_CONTROL_CONFIG, buildControlEvent, claimControlNotification, deriveActivityState, shouldEmitOpenToolAttention, shouldNotifyControlEvent, } from "../shared/subagent-control.js";
|
|
10
|
-
import { getFinalOutput, findLatestSessionFile, detectSubagentError, hasEmptyTerminalAssistantResponse, formatEmptyTerminalAssistantResponseError, extractToolArgsPreview, assistantMessageError, extractTextFromContent, MAX_STREAMED_RECENT_TOOLS, boundStreamedRecentTools, boundStreamedRecentOutput, boundStreamedToolCalls, } from "../../shared/utils.js";
|
|
11
|
+
import { getFinalOutput, findLatestSessionFile, detectSubagentError, hasEmptyTerminalAssistantResponse, formatEmptyTerminalAssistantResponseError, getTerminalAssistantStopReason, TRUNCATED_RESPONSE_ERROR, extractToolArgsPreview, assistantMessageError, extractTextFromContent, MAX_STREAMED_RECENT_TOOLS, boundStreamedRecentTools, boundStreamedRecentOutput, boundStreamedToolCalls, } from "../../shared/utils.js";
|
|
11
12
|
import { resolveSkillsWithFallback } from "../../agents/skills.js";
|
|
12
13
|
import { createPartialOutputTracker, formatPartialOutput } from "../shared/partial-output.js";
|
|
13
14
|
import { effectiveToolTimeoutMs, formatToolTimeoutMessage, resolveToolTimeoutMs, toolTimeoutCallKey, toolTimeoutFromEnv } from "../shared/tool-timeout.js";
|
|
@@ -44,6 +45,7 @@ import { childSessionFactory, childSessionHasQueuedMessages, projectChildSession
|
|
|
44
45
|
import { reconcileAttemptUsage } from "../shared/usage-reconciliation.js";
|
|
45
46
|
import { clearProviderRetry, observeProviderDiagnostics, snapshotProviderDiagnostics } from "../../shared/provider-diagnostics.js";
|
|
46
47
|
import { isRexLocalMachine } from "../shared/rex-machine.js";
|
|
48
|
+
import { pauseForSupervisorWait, startPausableTimer } from "../shared/supervisor-wait-timer.js";
|
|
47
49
|
const artifactOutputByResult = new WeakMap();
|
|
48
50
|
const acceptanceOutputByResult = new WeakMap();
|
|
49
51
|
function emptyUsage() {
|
|
@@ -205,6 +207,8 @@ function captureStructuredDelegationProgressState(progress, result) {
|
|
|
205
207
|
recentOutput: [...progress.recentOutput],
|
|
206
208
|
recentTools: progress.recentTools.slice(-MAX_STREAMED_RECENT_TOOLS).map(({ tool, args }) => ({ tool, args })),
|
|
207
209
|
activityState: progress.activityState,
|
|
210
|
+
progressText: progress.progressText,
|
|
211
|
+
progressUpdatedAt: progress.progressUpdatedAt,
|
|
208
212
|
model: progress.model ?? result.model,
|
|
209
213
|
toolCount: progress.toolCount,
|
|
210
214
|
tokens: progress.tokens,
|
|
@@ -217,6 +221,8 @@ function structuredDelegationProgressChanged(previous, progress, result) {
|
|
|
217
221
|
|| previous.currentTool !== progress.currentTool
|
|
218
222
|
|| previous.currentToolArgs !== progress.currentToolArgs
|
|
219
223
|
|| previous.activityState !== progress.activityState
|
|
224
|
+
|| previous.progressText !== progress.progressText
|
|
225
|
+
|| previous.progressUpdatedAt !== progress.progressUpdatedAt
|
|
220
226
|
|| previous.model !== (progress.model ?? result.model)
|
|
221
227
|
|| previous.toolCount !== progress.toolCount
|
|
222
228
|
|| previous.tokens !== progress.tokens
|
|
@@ -243,6 +249,7 @@ function isCompleteUsageCounter(value) {
|
|
|
243
249
|
}
|
|
244
250
|
const STOPPED_BEFORE_COMPLETION_ERROR = "Subagent stopped before completion.";
|
|
245
251
|
const AFTER_COMPACTION_SETTLEMENT = Symbol("afterCompactionSettlement");
|
|
252
|
+
const REMAINING_TIMEOUT_MS = Symbol("remainingTimeoutMs");
|
|
246
253
|
async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared) {
|
|
247
254
|
const effectiveThinking = options.thinkingOverride ?? agent.thinking;
|
|
248
255
|
const modelArg = applyThinkingSuffix(model, effectiveThinking, options.thinkingOverride !== undefined);
|
|
@@ -447,6 +454,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
447
454
|
let toolAvailabilityError;
|
|
448
455
|
let abortedBySignal = options.signal?.aborted === true;
|
|
449
456
|
let afterCompactionSettlement = false;
|
|
457
|
+
let remainingTimeoutMs;
|
|
450
458
|
if (options.workflowChildPermitLaunch) {
|
|
451
459
|
const permitError = consumeWorkflowChildPermit(options.workflowChildPermitLaunch.permit, {
|
|
452
460
|
workflowRunId: options.workflowChildPermitLaunch.workflowRunId,
|
|
@@ -486,7 +494,8 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
486
494
|
let timeoutHardFinishTimer;
|
|
487
495
|
const clearTimeoutTimers = () => {
|
|
488
496
|
if (timeoutTimer) {
|
|
489
|
-
|
|
497
|
+
remainingTimeoutMs = timeoutTimer.remainingMs();
|
|
498
|
+
timeoutTimer.clear();
|
|
490
499
|
timeoutTimer = undefined;
|
|
491
500
|
}
|
|
492
501
|
if (timeoutHardFinishTimer) {
|
|
@@ -1020,6 +1029,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1020
1029
|
progress.durationMs = now - startTime;
|
|
1021
1030
|
progress.lastActivityAt = now;
|
|
1022
1031
|
updateActivityState(now);
|
|
1032
|
+
pauseForSupervisorWait(timeoutTimer, evt);
|
|
1023
1033
|
if (evt.type === "tool_execution_start") {
|
|
1024
1034
|
const toolArgs = evt.args && typeof evt.args === "object" && !Array.isArray(evt.args)
|
|
1025
1035
|
? evt.args
|
|
@@ -1039,7 +1049,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1039
1049
|
result.toolBudget = toolBudgetState(options.toolBudget, progress.toolCount, result.toolBudget?.blockedTool);
|
|
1040
1050
|
}
|
|
1041
1051
|
const mutates = isMutatingTool(evt.toolName, toolArgs, agent.mutationTools);
|
|
1042
|
-
pendingToolResult = { tool: evt.toolName ?? "tool", path: activeTool?.path, mutates, startedAt: now };
|
|
1052
|
+
pendingToolResult = { tool: evt.toolName ?? "tool", path: activeTool?.path, mutates, startedAt: now, progressText: extractReportedProgress(evt.toolName ?? "", evt.args) };
|
|
1043
1053
|
if (typeof evt.toolCallId === "string" && evt.toolCallId)
|
|
1044
1054
|
pendingToolResultsByCallId.set(evt.toolCallId, pendingToolResult);
|
|
1045
1055
|
fireUpdate();
|
|
@@ -1140,6 +1150,10 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1140
1150
|
result.toolBudget = toolBudgetState(options.toolBudget, Math.max(progress.toolCount, options.toolBudget.hard + 1), blockedTool);
|
|
1141
1151
|
}
|
|
1142
1152
|
appendRecentOutput(progress, resultText.split("\n").slice(-10));
|
|
1153
|
+
if (evt.message.isError !== true && resultToolName === toolSnapshot?.tool && toolSnapshot?.progressText) {
|
|
1154
|
+
progress.progressText = toolSnapshot.progressText;
|
|
1155
|
+
progress.progressUpdatedAt = now;
|
|
1156
|
+
}
|
|
1143
1157
|
// A budget block has its own signal; it is not a failing mutation.
|
|
1144
1158
|
if (toolSnapshot?.mutates && !budgetBlocked && didMutatingToolFail(evt.message)) {
|
|
1145
1159
|
recordMutatingFailure(mutatingFailures, {
|
|
@@ -1180,7 +1194,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1180
1194
|
activityTimer.unref?.();
|
|
1181
1195
|
}
|
|
1182
1196
|
if (attemptTimeout) {
|
|
1183
|
-
timeoutTimer =
|
|
1197
|
+
timeoutTimer = startPausableTimer(attemptTimeout.remainingMs, () => {
|
|
1184
1198
|
if (sessionSettled || lifecycleFinished || interruptedByControl || result.timedOut)
|
|
1185
1199
|
return;
|
|
1186
1200
|
result.timedOut = true;
|
|
@@ -1199,8 +1213,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1199
1213
|
settle(undefined, true);
|
|
1200
1214
|
}, 4000);
|
|
1201
1215
|
timeoutHardFinishTimer.unref?.();
|
|
1202
|
-
}
|
|
1203
|
-
timeoutTimer.unref?.();
|
|
1216
|
+
});
|
|
1204
1217
|
}
|
|
1205
1218
|
let toolTimeoutSequence = 0;
|
|
1206
1219
|
const activeToolTimeouts = new Map();
|
|
@@ -1240,7 +1253,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1240
1253
|
const terminateForToolTimeout = (message) => {
|
|
1241
1254
|
if (sessionSettled || lifecycleFinished || interruptedByControl || result.timedOut)
|
|
1242
1255
|
return;
|
|
1243
|
-
|
|
1256
|
+
timeoutTimer?.clear();
|
|
1244
1257
|
result.timedOut = true;
|
|
1245
1258
|
timeoutCause = message;
|
|
1246
1259
|
result.error = message;
|
|
@@ -1261,10 +1274,6 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1261
1274
|
const timeoutForTool = effectiveToolTimeoutMs(event.toolName, options.toolTimeoutMs);
|
|
1262
1275
|
if (timeoutForTool === undefined)
|
|
1263
1276
|
return;
|
|
1264
|
-
const elapsed = Date.now() - startTime;
|
|
1265
|
-
const runRemaining = attemptTimeout ? Math.max(0, attemptTimeout.remainingMs - elapsed) : undefined;
|
|
1266
|
-
if (runRemaining !== undefined && timeoutForTool >= runRemaining)
|
|
1267
|
-
return;
|
|
1268
1277
|
const key = toolTimeoutCallKey(event, ++toolTimeoutSequence);
|
|
1269
1278
|
const toolName = event.toolName;
|
|
1270
1279
|
const timer = setTimeout(() => {
|
|
@@ -1413,14 +1422,14 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1413
1422
|
const steer = created.steer.bind(created);
|
|
1414
1423
|
const followUp = created.followUp.bind(created);
|
|
1415
1424
|
created.steer = async (text) => {
|
|
1425
|
+
await steer(text);
|
|
1416
1426
|
if (cleanTerminalAssistantStopReceived || agentSettledReceived)
|
|
1417
1427
|
queuedDrainHold = true;
|
|
1418
|
-
return steer(text);
|
|
1419
1428
|
};
|
|
1420
1429
|
created.followUp = async (text) => {
|
|
1430
|
+
await followUp(text);
|
|
1421
1431
|
if (cleanTerminalAssistantStopReceived || agentSettledReceived)
|
|
1422
1432
|
queuedDrainHold = true;
|
|
1423
|
-
return followUp(text);
|
|
1424
1433
|
};
|
|
1425
1434
|
created.detached = detached;
|
|
1426
1435
|
unsubscribe = created.subscribe((event) => processEvent(event));
|
|
@@ -1469,9 +1478,9 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1469
1478
|
result.exitCode = exitCode;
|
|
1470
1479
|
result.providerDiagnostics = clearProviderRetry(result.providerDiagnostics);
|
|
1471
1480
|
progress.providerDiagnostics = result.providerDiagnostics;
|
|
1472
|
-
if (afterCompactionSettlement)
|
|
1481
|
+
if (afterCompactionSettlement)
|
|
1473
1482
|
result[AFTER_COMPACTION_SETTLEMENT] = true;
|
|
1474
|
-
|
|
1483
|
+
result[REMAINING_TIMEOUT_MS] = remainingTimeoutMs;
|
|
1475
1484
|
if (interruptedByControl) {
|
|
1476
1485
|
result.exitCode = 0;
|
|
1477
1486
|
result.interrupted = true;
|
|
@@ -1546,6 +1555,10 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1546
1555
|
? `${errInfo.errorType} failed (exit ${errInfo.exitCode}): ${errInfo.details}`
|
|
1547
1556
|
: `${errInfo.errorType} failed with exit code ${errInfo.exitCode}`;
|
|
1548
1557
|
}
|
|
1558
|
+
else if (!validatedStructuredOutput && getTerminalAssistantStopReason(messages) === "length") {
|
|
1559
|
+
result.exitCode = 1;
|
|
1560
|
+
result.error = TRUNCATED_RESPONSE_ERROR;
|
|
1561
|
+
}
|
|
1549
1562
|
}
|
|
1550
1563
|
progress.status = result.exitCode === 0 ? "completed" : "failed";
|
|
1551
1564
|
progress.durationMs = Date.now() - startTime;
|
|
@@ -1945,6 +1958,10 @@ async function runSyncCompletionInner(runtimeCwd, agents, agentName, task, optio
|
|
|
1945
1958
|
});
|
|
1946
1959
|
if (recovery.action === "resume") {
|
|
1947
1960
|
recoveryPrompt = recovery.prompt;
|
|
1961
|
+
// The retry gets the budget the first attempt left, so that attempt's supervisor waits stay uncounted.
|
|
1962
|
+
const remainingMs = attemptResult[REMAINING_TIMEOUT_MS];
|
|
1963
|
+
if (remainingMs !== undefined)
|
|
1964
|
+
attemptOptions.deadlineAt = Date.now() + remainingMs;
|
|
1948
1965
|
attemptNotes.push("[abort-recovery] compaction abort after useful progress; resuming the retained child session once on the same model.");
|
|
1949
1966
|
continue;
|
|
1950
1967
|
}
|
|
@@ -49,6 +49,7 @@ export async function rewritePromptWithGuidance(input) {
|
|
|
49
49
|
});
|
|
50
50
|
const ctxThinking = input.ctx.getThinkingLevel?.();
|
|
51
51
|
const agent = new Agent({
|
|
52
|
+
sessionId,
|
|
52
53
|
initialState: {
|
|
53
54
|
systemPrompt: [
|
|
54
55
|
"Rewrite one subagent authored task from Prompt Audit context.",
|
|
@@ -59,6 +59,7 @@ export interface SubagentParamsLike {
|
|
|
59
59
|
agent?: string;
|
|
60
60
|
task?: string;
|
|
61
61
|
capabilities?: boolean;
|
|
62
|
+
search?: string;
|
|
62
63
|
extensionBindings?: ExtensionBindings;
|
|
63
64
|
/** Retained async child run id. Valid only on workflow runs.run items. */
|
|
64
65
|
resume?: string;
|
|
@@ -214,14 +215,6 @@ export declare function shouldSuppressRoutineResultIntercom(input: {
|
|
|
214
215
|
}): boolean;
|
|
215
216
|
export declare const DEFAULT_FOREGROUND_TIMEOUT_MS: number;
|
|
216
217
|
export { DEFAULT_ASYNC_TIMEOUT_MS };
|
|
217
|
-
/**
|
|
218
|
-
* Resolve the optional global default runtime deadline from extension config
|
|
219
|
-
* (`config.timeoutMs`). Returns undefined for unset or invalid values so callers
|
|
220
|
-
* fall back to the built-in defaults. "Invalid" covers non-positive-integer
|
|
221
|
-
* values and values above `MAX_TIMER_DELAY_MS`; the latter would overflow the
|
|
222
|
-
* Node.js timer and expire the run almost immediately instead of running long.
|
|
223
|
-
*/
|
|
224
|
-
export declare function resolveConfigDefaultTimeoutMs(raw: unknown): number | undefined;
|
|
225
218
|
export declare function resolveForegroundTimeout(params: SubagentParamsLike, defaultTimeoutMs?: number): {
|
|
226
219
|
timeoutMs?: number;
|
|
227
220
|
error?: string;
|
|
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { discoverAgents, findBlockingAgentDiagnostic, formatAvailableAgentLines, formatUnknownAgentError, resolveAgentName, suggestAgentName, unknownAgentDiagnosticContext } from "../../agents/agents.js";
|
|
5
|
-
import { getArtifactsDir, getProjectArtifactPackagingWarning, getProjectSubagentsDir } from "../../shared/artifacts.js";
|
|
5
|
+
import { getArtifactsDir, getProjectArtifactPackagingWarning, getProjectSubagentsDir, missingForkCopyNote } from "../../shared/artifacts.js";
|
|
6
6
|
import { writeAtomicJson } from "../../shared/atomic-json.js";
|
|
7
7
|
import { createCapacityResilientJsonWriter } from "../../shared/capacity-resilient-json.js";
|
|
8
8
|
import { reportSessionWarning } from "../../shared/session-warnings.js";
|
|
@@ -44,6 +44,7 @@ import { createPrunedForkSessionWriter } from "../../shared/pruned-fork.js";
|
|
|
44
44
|
import { resolveCurrentSessionId } from "../../shared/session-identity.js";
|
|
45
45
|
import { currentCompletionOwnerId } from "../../shared/completion-owner.js";
|
|
46
46
|
import { SUBAGENT_ASYNC_COMPLETE_EVENT } from "../../shared/types.js";
|
|
47
|
+
import { resolveConfigDefaultTimeoutMs } from "../../extension/config.js";
|
|
47
48
|
import { applyIntercomBridgeToAgent, INTERCOM_BRIDGE_MARKER, resolveIntercomBridge, resolveIntercomSessionTarget, resolveSubagentIntercomTarget } from "../../intercom/intercom-bridge.js";
|
|
48
49
|
import { formatControlIntercomMessage, formatControlNoticeMessage, resolveControlConfig, shouldNotifyControlEvent } from "../shared/subagent-control.js";
|
|
49
50
|
import { formatSpawnBudget, getSpawnBudgetSnapshot, grantSpawnBudget, preflightSpawnBudget, preflightSpawnBudgetGrant, reserveSpawnBudget } from "../shared/spawn-budget.js";
|
|
@@ -702,7 +703,7 @@ function resolveForegroundResumeTarget(params, state, options = {}) {
|
|
|
702
703
|
throw new Error(`Foreground run '${run.runId}' child ${index} session file must be a .jsonl file: ${child.sessionFile}`);
|
|
703
704
|
const sessionFile = path.resolve(child.sessionFile);
|
|
704
705
|
if (!fs.existsSync(sessionFile))
|
|
705
|
-
throw new Error(`Foreground run '${run.runId}' child ${index} session file does not exist: ${child.sessionFile}`);
|
|
706
|
+
throw new Error(`Foreground run '${run.runId}' child ${index} session file does not exist: ${child.sessionFile}${missingForkCopyNote(sessionFile)}`);
|
|
706
707
|
return {
|
|
707
708
|
runId: run.runId,
|
|
708
709
|
mode: run.mode,
|
|
@@ -1190,7 +1191,7 @@ function validateNestedSessionFile(run, trustedSessionRoots, resolveSource, visi
|
|
|
1190
1191
|
if (!path.isAbsolute(sessionFile))
|
|
1191
1192
|
throw new Error(`Nested run '${run.id}' session file must be absolute: ${sessionFile}`);
|
|
1192
1193
|
if (!fs.existsSync(resolved))
|
|
1193
|
-
throw new Error(`Nested run '${run.id}' session file does not exist: ${sessionFile}`);
|
|
1194
|
+
throw new Error(`Nested run '${run.id}' session file does not exist: ${sessionFile}${missingForkCopyNote(resolved)}`);
|
|
1194
1195
|
const stat = fs.lstatSync(resolved);
|
|
1195
1196
|
if (!stat.isFile() || stat.isSymbolicLink())
|
|
1196
1197
|
throw new Error(`Nested run '${run.id}' session file is not a regular file: ${sessionFile}`);
|
|
@@ -2712,18 +2713,6 @@ function timerDelayOverflowError(name, value) {
|
|
|
2712
2713
|
? `${name} must be a positive integer no larger than ${MAX_TIMER_DELAY_MS}.`
|
|
2713
2714
|
: undefined;
|
|
2714
2715
|
}
|
|
2715
|
-
/**
|
|
2716
|
-
* Resolve the optional global default runtime deadline from extension config
|
|
2717
|
-
* (`config.timeoutMs`). Returns undefined for unset or invalid values so callers
|
|
2718
|
-
* fall back to the built-in defaults. "Invalid" covers non-positive-integer
|
|
2719
|
-
* values and values above `MAX_TIMER_DELAY_MS`; the latter would overflow the
|
|
2720
|
-
* Node.js timer and expire the run almost immediately instead of running long.
|
|
2721
|
-
*/
|
|
2722
|
-
export function resolveConfigDefaultTimeoutMs(raw) {
|
|
2723
|
-
if (typeof raw !== "number" || !Number.isInteger(raw) || raw <= 0 || raw > MAX_TIMER_DELAY_MS)
|
|
2724
|
-
return undefined;
|
|
2725
|
-
return raw;
|
|
2726
|
-
}
|
|
2727
2716
|
export function resolveForegroundTimeout(params, defaultTimeoutMs) {
|
|
2728
2717
|
const rawTimeout = params.timeoutMs;
|
|
2729
2718
|
const rawMaxRuntime = params.maxRuntimeMs;
|
|
@@ -6013,6 +6002,8 @@ export function createSubagentExecutor(deps) {
|
|
|
6013
6002
|
step.currentToolArgs = progress.currentToolArgs;
|
|
6014
6003
|
step.currentToolStartedAt = progress.currentToolStartedAt;
|
|
6015
6004
|
step.currentPath = progress.currentPath;
|
|
6005
|
+
step.progressText = progress.progressText;
|
|
6006
|
+
step.progressUpdatedAt = progress.progressUpdatedAt;
|
|
6016
6007
|
step.recentTools = progress.recentTools.map((tool) => ({ ...tool }));
|
|
6017
6008
|
step.recentOutput = [...progress.recentOutput];
|
|
6018
6009
|
step.turnCount = progress.turnCount;
|
|
@@ -33,6 +33,8 @@ export interface AsyncStatusSnapshotNode {
|
|
|
33
33
|
updatedAt?: number;
|
|
34
34
|
endedAt?: number;
|
|
35
35
|
activity?: AsyncStatusSnapshotActivity;
|
|
36
|
+
progressText?: string;
|
|
37
|
+
progressUpdatedAt?: number;
|
|
36
38
|
/** Step nodes only: the agent the child runs as, and the model and thinking level it reports. */
|
|
37
39
|
agent?: string;
|
|
38
40
|
model?: string;
|
|
@@ -137,6 +137,8 @@ function projectStep(step, index, depth, ctx) {
|
|
|
137
137
|
const activity = activityFor(step, ctx);
|
|
138
138
|
const { id, label } = stepIdentity(step, index, ctx);
|
|
139
139
|
const agent = publicOptionalText(step.agent, ctx.caps.maxStringLength);
|
|
140
|
+
const progressText = publicOptionalText(step.progressText, ctx.caps.maxStringLength);
|
|
141
|
+
const progressUpdatedAt = publicTime(step.progressUpdatedAt);
|
|
140
142
|
const node = {
|
|
141
143
|
id,
|
|
142
144
|
kind: "step",
|
|
@@ -146,6 +148,8 @@ function projectStep(step, index, depth, ctx) {
|
|
|
146
148
|
...(updatedAt !== undefined ? { updatedAt } : {}),
|
|
147
149
|
...(terminalState(state) && endedAt !== undefined ? { endedAt } : {}),
|
|
148
150
|
...(activity ? { activity } : {}),
|
|
151
|
+
...(progressText ? { progressText } : {}),
|
|
152
|
+
...(progressUpdatedAt !== undefined ? { progressUpdatedAt } : {}),
|
|
149
153
|
};
|
|
150
154
|
if (agent)
|
|
151
155
|
node.agent = agent;
|
|
@@ -302,6 +306,12 @@ function projectMaterializedStep(step, index, child, depth, ctx, childrenByParen
|
|
|
302
306
|
const selfActivity = selfStep ? activityFor(selfStep, ctx) : undefined;
|
|
303
307
|
const activity = laneActivity || selfActivity || live.activity ? { ...laneActivity, ...selfActivity, ...live.activity } : undefined;
|
|
304
308
|
const node = { ...live, id, kind: "step", label };
|
|
309
|
+
const progressText = publicOptionalText(selfStep?.progressText ?? step.progressText, ctx.caps.maxStringLength);
|
|
310
|
+
const progressUpdatedAt = publicTime(selfStep?.progressUpdatedAt ?? step.progressUpdatedAt);
|
|
311
|
+
if (progressText)
|
|
312
|
+
node.progressText = progressText;
|
|
313
|
+
if (progressUpdatedAt !== undefined)
|
|
314
|
+
node.progressUpdatedAt = progressUpdatedAt;
|
|
305
315
|
const agent = publicOptionalText(selfStep?.agent || step.agent, ctx.caps.maxStringLength);
|
|
306
316
|
if (agent)
|
|
307
317
|
node.agent = agent;
|
|
@@ -22,6 +22,7 @@ import { cleanupSessionResources, registerSessionResourceCleanup } from "@earend
|
|
|
22
22
|
import { CHILD_COMMAND_TOOL, createChildCommandRuntime } from "./child-commands.js";
|
|
23
23
|
import { supervisorChannelDir } from "./child-tool-plan.js";
|
|
24
24
|
import { pinChildCacheRetention } from "../../shared/child-cache-retention.js";
|
|
25
|
+
import { parseAcceptanceReport } from "./acceptance.js";
|
|
25
26
|
import { getAgentDir, PI_CODING_AGENT_PACKAGE_ROOT_ENV } from "../../shared/utils.js";
|
|
26
27
|
import { resolvePackageSubpath } from "../background/runner-aliases.js";
|
|
27
28
|
import { PI_CODING_AGENT_PACKAGE, resolveHostPiPackageRoot } from "./pi-spawn.js";
|
|
@@ -655,12 +656,29 @@ export function createDefaultChildSessionFactory(options = {}) {
|
|
|
655
656
|
mcpWaits.delete(cancel);
|
|
656
657
|
}
|
|
657
658
|
}
|
|
659
|
+
let reportCompleted = false;
|
|
660
|
+
const guidanceClosed = "Child completed its acceptance report; resume it for further guidance.";
|
|
661
|
+
const assertAcceptsGuidance = () => { if (reportCompleted)
|
|
662
|
+
throw new Error(guidanceClosed); };
|
|
663
|
+
const rejectQueuedGuidance = () => { session.clearQueue(); throw new Error(guidanceClosed); };
|
|
658
664
|
const child = {
|
|
659
|
-
subscribe: (listener) => session.subscribe((event) =>
|
|
665
|
+
subscribe: (listener) => session.subscribe((event) => {
|
|
666
|
+
if (event.type === "message_end" && event.message.role === "assistant" && event.message.stopReason === "stop") {
|
|
667
|
+
const text = event.message.content.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
668
|
+
const report = parseAcceptanceReport(text);
|
|
669
|
+
if (report.report || report.malformed) {
|
|
670
|
+
reportCompleted = true;
|
|
671
|
+
session.clearQueue();
|
|
672
|
+
session.agent.steer = rejectQueuedGuidance;
|
|
673
|
+
session.agent.followUp = rejectQueuedGuidance;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
listener(event);
|
|
677
|
+
}),
|
|
660
678
|
prompt: (text) => session.prompt(text),
|
|
661
679
|
...(commands ? { finishCommands: () => commands.finish() } : {}),
|
|
662
|
-
steer: async (text) => { await session.steer(text); },
|
|
663
|
-
followUp: async (text) => { await session.followUp(text); },
|
|
680
|
+
steer: async (text) => { assertAcceptsGuidance(); await session.steer(text); },
|
|
681
|
+
followUp: async (text) => { assertAcceptsGuidance(); await session.followUp(text); },
|
|
664
682
|
abort: () => session.abort(),
|
|
665
683
|
hasQueuedMessages: () => session.agent?.hasQueuedMessages?.() === true,
|
|
666
684
|
dispose: () => {
|
|
@@ -28,6 +28,8 @@ export interface McpServerDefinition {
|
|
|
28
28
|
pluginDataDir?: string;
|
|
29
29
|
literalEnv?: boolean;
|
|
30
30
|
inheritEnv?: boolean;
|
|
31
|
+
/** Only literal true disables a server, matching pi-mcp-adapter. */
|
|
32
|
+
disabled?: boolean;
|
|
31
33
|
}
|
|
32
34
|
export declare function isMcpServerDefinition(value: unknown): value is McpServerDefinition;
|
|
33
35
|
export declare function loadPackageMcpServers(cwd: string): Record<string, McpServerDefinition>;
|
|
@@ -73,7 +73,6 @@ export interface McpDirectToolResolution {
|
|
|
73
73
|
builtin?: true;
|
|
74
74
|
}
|
|
75
75
|
export declare function resolveMcpDirectToolResolution(mcpDirectTools: string[] | undefined, cwd?: string, runtimeSnapshotHost?: McpRuntimeSnapshotHost, configOverride?: McpConfig): McpDirectToolResolution;
|
|
76
|
-
export declare function resolveMcpDirectToolSelections(mcpDirectTools: string[] | undefined, cwd?: string, runtimeSnapshotHost?: McpRuntimeSnapshotHost): ResolvedMcpDirectToolSelection[];
|
|
77
76
|
export declare function formatUnresolvedBuiltinMcpSelectors(agentName: string | undefined, selectors: readonly string[]): string;
|
|
78
77
|
/**
|
|
79
78
|
* Selected servers that only an extension registered, which a child without ambient extensions
|
|
@@ -81,5 +80,4 @@ export declare function formatUnresolvedBuiltinMcpSelectors(agentName: string |
|
|
|
81
80
|
* the project file is read only when the project is trusted.
|
|
82
81
|
*/
|
|
83
82
|
export declare function extensionOnlyMcpServers(selections: readonly ResolvedMcpDirectToolSelection[], host: McpRuntimeSnapshotHost, cwd: string, projectTrusted: boolean): string[];
|
|
84
|
-
export declare function resolveMcpDirectToolNames(mcpDirectTools: string[] | undefined, cwd?: string): string[];
|
|
85
83
|
export declare function computeMcpServerHash(definition: ServerEntry): string;
|
|
@@ -38,21 +38,26 @@ export function resolveMcpDirectToolResolution(mcpDirectTools, cwd = process.cwd
|
|
|
38
38
|
const resolvedConfig = Object.keys(runtimeServers).length > 0
|
|
39
39
|
? mergeConfigs(config, { mcpServers: runtimeServers })
|
|
40
40
|
: config;
|
|
41
|
-
|
|
41
|
+
const enabledSelectors = selectors.filter((selector) => resolvedConfig.mcpServers[selector.split("/", 1)[0]]?.disabled !== true);
|
|
42
|
+
validateSelectedServerDefinitions(resolvedConfig, enabledSelectors);
|
|
42
43
|
const runtime = Object.keys(runtimeServers).length > 0
|
|
43
44
|
? { mcpConfig: resolvedConfig, runtimeServerNames: Object.keys(runtimeServers) }
|
|
44
45
|
: {};
|
|
46
|
+
if (enabledSelectors.length === 0)
|
|
47
|
+
return { selections: [], unresolvedSelectors: [], ...runtime };
|
|
45
48
|
const cache = loadMetadataCache();
|
|
46
49
|
if (!cache)
|
|
47
|
-
return { selections: [], unresolvedSelectors:
|
|
50
|
+
return { selections: [], unresolvedSelectors: enabledSelectors, ...runtime };
|
|
48
51
|
const validMetadata = {};
|
|
49
52
|
for (const [serverName, definition] of Object.entries(resolvedConfig.mcpServers)) {
|
|
53
|
+
if (definition.disabled === true)
|
|
54
|
+
continue;
|
|
50
55
|
const serverCache = cache.servers[serverName];
|
|
51
56
|
if (isServerCacheValid(serverCache, definition))
|
|
52
57
|
validMetadata[serverName] = serverCache;
|
|
53
58
|
}
|
|
54
59
|
const grant = planMcpDirectToolGrant({
|
|
55
|
-
selectors,
|
|
60
|
+
selectors: enabledSelectors,
|
|
56
61
|
servers: resolvedConfig.mcpServers,
|
|
57
62
|
metadata: validMetadata,
|
|
58
63
|
toolPrefix: resolvedConfig.settings?.toolPrefix,
|
|
@@ -63,9 +68,6 @@ export function resolveMcpDirectToolResolution(mcpDirectTools, cwd = process.cwd
|
|
|
63
68
|
...runtime,
|
|
64
69
|
};
|
|
65
70
|
}
|
|
66
|
-
export function resolveMcpDirectToolSelections(mcpDirectTools, cwd = process.cwd(), runtimeSnapshotHost) {
|
|
67
|
-
return resolveMcpDirectToolResolution(mcpDirectTools, cwd, runtimeSnapshotHost).selections;
|
|
68
|
-
}
|
|
69
71
|
/**
|
|
70
72
|
* pi-mcp-adapter keeps priority whenever it is loaded. 2.x registers /mcp, so Pi does not load its
|
|
71
73
|
* built-in MCP. 3.x always registers /mcp-adapter and leaves /mcp to the built-in MCP.
|
|
@@ -301,11 +303,22 @@ function parseSettings(value) {
|
|
|
301
303
|
function mergeConfigs(base, next) {
|
|
302
304
|
const imports = [...(base.imports ?? []), ...(next.imports ?? [])];
|
|
303
305
|
return {
|
|
304
|
-
mcpServers:
|
|
306
|
+
mcpServers: mergeServerDefinitions(base.mcpServers, next.mcpServers),
|
|
305
307
|
imports: imports.length ? [...new Set(imports)] : undefined,
|
|
306
308
|
settings: next.settings ? { ...base.settings, ...next.settings } : base.settings,
|
|
307
309
|
};
|
|
308
310
|
}
|
|
311
|
+
function mergeServerDefinitions(base, next) {
|
|
312
|
+
const servers = { ...base };
|
|
313
|
+
for (const [name, definition] of Object.entries(next)) {
|
|
314
|
+
const previous = base[name];
|
|
315
|
+
if (previous && Object.keys(definition).every((key) => key === "disabled"))
|
|
316
|
+
servers[name] = { ...previous, ...definition };
|
|
317
|
+
else
|
|
318
|
+
servers[name] = previous?.disabled === undefined ? definition : { disabled: previous.disabled, ...definition };
|
|
319
|
+
}
|
|
320
|
+
return servers;
|
|
321
|
+
}
|
|
309
322
|
function expandImports(config, cwd) {
|
|
310
323
|
if (!config.imports?.length)
|
|
311
324
|
return config;
|
|
@@ -329,7 +342,7 @@ function expandImports(config, cwd) {
|
|
|
329
342
|
return {
|
|
330
343
|
imports: config.imports,
|
|
331
344
|
settings: config.settings,
|
|
332
|
-
mcpServers:
|
|
345
|
+
mcpServers: mergeServerDefinitions(importedServers, config.mcpServers),
|
|
333
346
|
};
|
|
334
347
|
}
|
|
335
348
|
function resolveImportPath(importKind, cwd) {
|
|
@@ -349,9 +362,6 @@ function extractServers(config, kind) {
|
|
|
349
362
|
: obj.mcpServers;
|
|
350
363
|
return parseServerEntries(servers);
|
|
351
364
|
}
|
|
352
|
-
export function resolveMcpDirectToolNames(mcpDirectTools, cwd = process.cwd()) {
|
|
353
|
-
return resolveMcpDirectToolSelections(mcpDirectTools, cwd).map((selection) => selection.name);
|
|
354
|
-
}
|
|
355
365
|
function validateSelectedServerDefinitions(config, selectors) {
|
|
356
366
|
const { servers, tools } = parseMcpDirectToolSelectors(selectors);
|
|
357
367
|
for (const serverName of new Set([...servers, ...tools.keys()])) {
|
|
@@ -298,11 +298,19 @@ export function modelBefore(messages, forkedAt) {
|
|
|
298
298
|
* parent's prompt, so its own versions of these sections are not repeated in its task message.
|
|
299
299
|
*/
|
|
300
300
|
const LOADOUT_SECTIONS = new Set(["tools", "rules", "docs", "skills", "advertised_subagents", "mcp_servers", "project_context"]);
|
|
301
|
+
/** The `<project_instructions path="…">` blocks Pi writes into a `project_context` section, by path. */
|
|
302
|
+
function projectInstructionBlocks(section) {
|
|
303
|
+
const blocks = new Map();
|
|
304
|
+
for (const match of (section ?? "").matchAll(/<project_instructions\s+path=(["'])(.*?)\1\s*>[\s\S]*?<\/project_instructions>/gi))
|
|
305
|
+
blocks.set(match[2], match[0]);
|
|
306
|
+
return blocks;
|
|
307
|
+
}
|
|
301
308
|
/**
|
|
302
309
|
* The child's own instructions, which a fork sends in its task message instead of its system
|
|
303
310
|
* prompt: the text its own system messages (`own`) add, the sections it changed except the loadout
|
|
304
|
-
* ones, the
|
|
305
|
-
*
|
|
311
|
+
* ones, the project instruction files the parent's prompt lacks (a child that works in another
|
|
312
|
+
* folder has that folder's AGENTS.md), the tools it can call, and its boundary. `parent` is the
|
|
313
|
+
* inherited system messages and `child` the whole request.
|
|
306
314
|
*/
|
|
307
315
|
function forkInstructions(input) {
|
|
308
316
|
const parent = getCurrentSystemMessage(input.parent);
|
|
@@ -318,6 +326,10 @@ function forkInstructions(input) {
|
|
|
318
326
|
if (!LOADOUT_SECTIONS.has(name) && value && parent?.sections?.[name] !== value)
|
|
319
327
|
parts.push(value);
|
|
320
328
|
}
|
|
329
|
+
const parentFiles = projectInstructionBlocks(parent?.sections?.project_context);
|
|
330
|
+
const missingFiles = [...projectInstructionBlocks(child?.sections?.project_context)].filter(([filePath]) => !parentFiles.has(filePath)).map(([, block]) => block);
|
|
331
|
+
if (missingFiles.length > 0)
|
|
332
|
+
parts.push(["Project instructions for your working folder, which the parent's prompt does not include:", ...missingFiles].join("\n\n"));
|
|
321
333
|
if (input.boundary)
|
|
322
334
|
parts.push(input.boundary);
|
|
323
335
|
return `<subagent_instructions>\n${parts.join("\n\n")}\n</subagent_instructions>`;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** A child making one of these calls is blocked on its supervisor's reply, not working. */
|
|
2
|
+
export declare function isBlockingSupervisorTool(toolName: string | undefined, args: unknown): boolean;
|
|
3
|
+
/** A one-shot timer whose countdown stops while any key holds it paused. */
|
|
4
|
+
export interface PausableTimer {
|
|
5
|
+
pause(key: string): void;
|
|
6
|
+
resume(key: string): void;
|
|
7
|
+
remainingMs(): number;
|
|
8
|
+
clear(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function startPausableTimer(delayMs: number, onFire: () => void): PausableTimer;
|
|
11
|
+
export declare function pauseForSupervisorWait(timer: PausableTimer | undefined, event: {
|
|
12
|
+
type?: string;
|
|
13
|
+
toolCallId?: unknown;
|
|
14
|
+
toolName?: string;
|
|
15
|
+
args?: unknown;
|
|
16
|
+
}): void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** A child making one of these calls is blocked on its supervisor's reply, not working. */
|
|
2
|
+
export function isBlockingSupervisorTool(toolName, args) {
|
|
3
|
+
if (!args || typeof args !== "object")
|
|
4
|
+
return false;
|
|
5
|
+
const call = args;
|
|
6
|
+
if (toolName === "contact_supervisor")
|
|
7
|
+
return call.reason === "need_decision" || call.reason === "interview_request";
|
|
8
|
+
return toolName === "intercom" && call.action === "ask";
|
|
9
|
+
}
|
|
10
|
+
export function startPausableTimer(delayMs, onFire) {
|
|
11
|
+
let remaining = Math.max(0, delayMs);
|
|
12
|
+
// Monotonic clock: a system clock change must not shorten or extend the budget.
|
|
13
|
+
let runningSince;
|
|
14
|
+
let timer;
|
|
15
|
+
let done = false;
|
|
16
|
+
const pausedBy = new Set();
|
|
17
|
+
const remainingMs = () => runningSince === undefined ? remaining : Math.max(0, remaining - (performance.now() - runningSince));
|
|
18
|
+
const run = () => {
|
|
19
|
+
runningSince = performance.now();
|
|
20
|
+
timer = setTimeout(() => {
|
|
21
|
+
done = true;
|
|
22
|
+
runningSince = undefined;
|
|
23
|
+
remaining = 0;
|
|
24
|
+
onFire();
|
|
25
|
+
}, remaining);
|
|
26
|
+
timer.unref?.();
|
|
27
|
+
};
|
|
28
|
+
const stop = () => {
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
remaining = remainingMs();
|
|
31
|
+
runningSince = undefined;
|
|
32
|
+
};
|
|
33
|
+
run();
|
|
34
|
+
return {
|
|
35
|
+
pause(key) {
|
|
36
|
+
if (done)
|
|
37
|
+
return;
|
|
38
|
+
if (pausedBy.size === 0)
|
|
39
|
+
stop();
|
|
40
|
+
pausedBy.add(key);
|
|
41
|
+
},
|
|
42
|
+
resume(key) {
|
|
43
|
+
if (done || !pausedBy.delete(key) || pausedBy.size > 0)
|
|
44
|
+
return;
|
|
45
|
+
run();
|
|
46
|
+
},
|
|
47
|
+
remainingMs,
|
|
48
|
+
clear() {
|
|
49
|
+
done = true;
|
|
50
|
+
stop();
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function pauseForSupervisorWait(timer, event) {
|
|
55
|
+
if (!timer || typeof event.toolCallId !== "string")
|
|
56
|
+
return;
|
|
57
|
+
if (event.type === "tool_execution_start" && isBlockingSupervisorTool(event.toolName, event.args))
|
|
58
|
+
timer.pause(event.toolCallId);
|
|
59
|
+
else if (event.type === "tool_execution_end")
|
|
60
|
+
timer.resume(event.toolCallId);
|
|
61
|
+
}
|
|
@@ -20,3 +20,4 @@ export declare function writeMetadata(filePath: string, metadata: object): void;
|
|
|
20
20
|
export declare function appendJsonl(filePath: string, line: string): void;
|
|
21
21
|
export declare function cleanupOldArtifacts(dir: string, maxAgeDays: number): void;
|
|
22
22
|
export declare function cleanupAllArtifactDirs(maxAgeDays: number): void;
|
|
23
|
+
export declare function missingForkCopyNote(sessionFile: string): string;
|