@xzzpig/pi-subagents 0.18.0 → 0.20.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 +129 -0
- package/README.md +1 -1
- package/docs/agents.md +32 -16
- package/docs/configuration.md +76 -9
- package/docs/extension-api.md +6 -5
- package/docs/missions.md +28 -14
- package/docs/models.md +8 -4
- package/docs/observability.md +10 -5
- package/docs/standalone-background.md +1 -1
- package/docs/tool-reference.md +90 -88
- package/docs/workflows.md +171 -173
- package/node_modules/@xzzpig/pi-components/package.json +4 -4
- package/package.json +6 -6
- package/prompts/review-loop.md +1 -1
- package/skills/council-mode/SKILL.md +1 -1
- package/skills/pi-subagents/SKILL.md +12 -5
- package/skills/pi-subagents/references/constraints-and-recipes.md +3 -3
- package/skills/pi-subagents/references/execution-controls.md +68 -67
- package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
- package/skills/pi-subagents/references/multi-lane-orchestration.md +1 -1
- package/skills/pi-subagents/references/prompting-and-roles.md +45 -48
- package/src/agents/advertised-agent-prompt.ts +21 -41
- package/src/agents/agent-management.ts +2 -2
- package/src/agents/agents.ts +66 -3
- package/src/api/preflight.ts +109 -63
- package/src/extension/config.ts +15 -4
- package/src/extension/control-notices.ts +3 -0
- package/src/extension/doctor.ts +1 -0
- package/src/extension/fanout-child.ts +12 -3
- package/src/extension/herdr-pi-bridge.ts +2 -0
- package/src/extension/index.ts +90 -174
- package/src/extension/public-execution.ts +72 -35
- package/src/extension/reply-workflow-script.ts +58 -0
- package/src/extension/rpc.ts +29 -10
- package/src/extension/schemas.ts +40 -135
- package/src/extension/tool-activation.ts +57 -108
- package/src/extension/tool-description.ts +62 -27
- package/src/extension/upgrade-notice.ts +40 -0
- package/src/integrations/herdr-status.ts +19 -3
- package/src/intercom/native-supervisor-channel.ts +4 -1
- package/src/missions/goal-driver.ts +44 -31
- package/src/missions/store.ts +10 -1
- package/src/profiles/profiles.ts +5 -2
- package/src/runs/background/async-execution.ts +146 -59
- package/src/runs/background/async-job-tracker.ts +66 -24
- package/src/runs/background/async-retention.ts +46 -16
- package/src/runs/background/await-async-run.ts +78 -0
- package/src/runs/background/chain-root-attachment.ts +4 -4
- package/src/runs/background/control-channel.ts +61 -2
- package/src/runs/background/notify.ts +5 -0
- package/src/runs/background/run-child-session.ts +17 -7
- package/src/runs/background/run-status.ts +6 -0
- package/src/runs/background/runner-aliases.ts +37 -6
- package/src/runs/background/runner-child-launch.ts +3 -0
- package/src/runs/background/scheduled-runs.ts +33 -18
- package/src/runs/background/stale-run-reconciler.ts +13 -2
- package/src/runs/background/subagent-runner.ts +58 -5
- package/src/runs/foreground/async-stop-action.ts +17 -3
- package/src/runs/foreground/command-action.ts +41 -0
- package/src/runs/foreground/execution.ts +145 -131
- package/src/runs/foreground/subagent-executor.ts +546 -296
- package/src/runs/shared/async-status-projection.ts +5 -0
- package/src/runs/shared/child-commands.ts +228 -0
- package/src/runs/shared/child-launch.ts +15 -2
- package/src/runs/shared/child-session.ts +184 -24
- package/src/runs/shared/child-tool-plan.ts +16 -4
- package/src/runs/shared/claude-code-adapter.ts +157 -2
- package/src/runs/shared/dynamic-fanout.ts +2 -2
- package/src/runs/shared/external-cli-preflight.ts +54 -6
- package/src/runs/shared/external-cli-runner.ts +5 -1
- package/src/runs/shared/mcp-config-sources.ts +2 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +104 -11
- package/src/runs/shared/model-resolution.ts +38 -10
- package/src/runs/shared/model-scope.ts +28 -9
- package/src/runs/shared/nested-events.ts +55 -55
- package/src/runs/shared/parallel-utils.ts +4 -0
- package/src/runs/shared/pi-spawn.ts +7 -95
- package/src/runs/shared/run-history.ts +87 -0
- package/src/runs/shared/subagent-control.ts +32 -17
- package/src/runs/shared/subagent-prompt-runtime.ts +14 -6
- package/src/runs/shared/worktree.ts +1 -1
- package/src/shared/disabled-features.ts +123 -0
- package/src/shared/extension-context.ts +13 -0
- package/src/shared/model-info.ts +9 -0
- package/src/shared/required-child-extensions.ts +39 -5
- package/src/shared/settings.ts +1 -1
- package/src/shared/types.ts +27 -1
- package/src/slash/prompt-template-bridge.ts +2 -2
- package/src/slash/slash-commands.ts +10 -5
- package/src/slash/subagent-cost.ts +9 -5
- package/src/slash/subagents-admin.ts +24 -24
- package/src/tui/fleet-status.ts +14 -6
- package/src/tui/fleet.ts +14 -2
- package/src/tui/render.ts +117 -56
- package/src/tui/running-tone.ts +28 -0
- package/src/watchdog/diff-tool.ts +23 -9
- package/src/watchdog/register-child.ts +3 -3
- package/src/watchdog/register-main.ts +3 -3
- package/src/watchdog/review.ts +2 -2
- package/src/watchdog/turn-delta.ts +1 -1
- package/src/workflows/chat-progress.ts +2 -2
- package/src/workflows/scripted-workflow.ts +117 -37
- package/src/workflows/structured-workflow-scripts.ts +177 -0
- package/src/workflows/workflow-checklist.ts +6 -0
- package/src/workflows/workflow-receipt.ts +10 -4
- package/src/workflows/workflow-resources.ts +44 -16
- package/src/workflows/workflow-reuse.ts +120 -0
- package/src/workflows/workflow-revival.ts +123 -0
|
@@ -158,7 +158,7 @@ function persistSingleResultMetadata(input: {
|
|
|
158
158
|
toolCount: target.progressSummary?.toolCount,
|
|
159
159
|
error: target.error,
|
|
160
160
|
agentContract: target.agentContract,
|
|
161
|
-
sandbox: target.sandbox,
|
|
161
|
+
sandbox: target.sandbox,
|
|
162
162
|
launchContractDigest: target.launchContractDigest,
|
|
163
163
|
launchResolvedExtensions: target.launchResolvedExtensions,
|
|
164
164
|
runtimeAcknowledgedExtensions: target.runtimeAcknowledgedExtensions,
|
|
@@ -380,8 +380,8 @@ async function runSingleAttempt(
|
|
|
380
380
|
})
|
|
381
381
|
: undefined;
|
|
382
382
|
const permissionRules = resolvePermissionRules(options.permissions, agent.permissions);
|
|
383
|
-
const sandbox = options.sandbox ?? agent.sandbox;
|
|
384
|
-
const permissionProfile = options.permissionProfile ?? agent.permissionProfile;
|
|
383
|
+
const sandbox = options.sandbox ?? agent.sandbox;
|
|
384
|
+
const permissionProfile = options.permissionProfile ?? agent.permissionProfile;
|
|
385
385
|
const permissionAuditPath = permissionRules && options.artifactsDir
|
|
386
386
|
? path.join(options.artifactsDir, "permission-audit", `${options.runId}-${options.index ?? 0}.jsonl`)
|
|
387
387
|
: undefined;
|
|
@@ -426,10 +426,10 @@ const permissionProfile = options.permissionProfile ?? agent.permissionProfile;
|
|
|
426
426
|
toolBudget: options.toolBudget,
|
|
427
427
|
permissionRules,
|
|
428
428
|
permissionAuditPath,
|
|
429
|
-
sandbox,
|
|
430
|
-
permissionProfile,
|
|
431
|
-
projectTrusted: options.projectTrusted,
|
|
432
|
-
trustedProjectCwd: options.trustedProjectCwd,
|
|
429
|
+
sandbox,
|
|
430
|
+
permissionProfile,
|
|
431
|
+
projectTrusted: options.projectTrusted,
|
|
432
|
+
trustedProjectCwd: options.trustedProjectCwd,
|
|
433
433
|
childWatchdog,
|
|
434
434
|
// registerChildWatchdog returns before reading the sink when no watchdog exists.
|
|
435
435
|
watchdogStatus: childWatchdog ? (event) => onWatchdogStatus?.(event) : undefined,
|
|
@@ -458,12 +458,12 @@ trustedProjectCwd: options.trustedProjectCwd,
|
|
|
458
458
|
...(fast !== undefined ? { fast } : {}),
|
|
459
459
|
...(resolvedThinking ? { thinking: resolvedThinking } : {}),
|
|
460
460
|
systemPrompt: effectiveSystemPrompt,
|
|
461
|
-
systemPromptMode: agent.systemPromptMode,
|
|
462
|
-
inheritProjectContext: agent.inheritProjectContext,
|
|
463
|
-
inheritGlobalContext: agent.inheritGlobalContext,
|
|
464
|
-
inheritSkills: agent.inheritSkills,
|
|
465
|
-
sandbox,
|
|
466
|
-
permissionProfile,
|
|
461
|
+
systemPromptMode: agent.systemPromptMode,
|
|
462
|
+
inheritProjectContext: agent.inheritProjectContext,
|
|
463
|
+
inheritGlobalContext: agent.inheritGlobalContext,
|
|
464
|
+
inheritSkills: agent.inheritSkills,
|
|
465
|
+
sandbox,
|
|
466
|
+
permissionProfile,
|
|
467
467
|
skills: shared.resolvedSkillNames ?? [],
|
|
468
468
|
toolPlan,
|
|
469
469
|
...(options.outputPath ? { outputPath: options.outputPath } : {}),
|
|
@@ -477,8 +477,8 @@ permissionProfile,
|
|
|
477
477
|
task: shared.originalTask ?? task,
|
|
478
478
|
...(childSessionName ? { sessionName: childSessionName } : {}),
|
|
479
479
|
...(options.agentContract ? { agentContract: options.agentContract } : {}),
|
|
480
|
-
...(sandbox ? { sandbox } : {}),
|
|
481
|
-
...(permissionProfile ? { permissionProfile } : {}),
|
|
480
|
+
...(sandbox ? { sandbox } : {}),
|
|
481
|
+
...(permissionProfile ? { permissionProfile } : {}),
|
|
482
482
|
launchContractDigest,
|
|
483
483
|
launchResolvedExtensions,
|
|
484
484
|
exitCode: 0,
|
|
@@ -787,7 +787,13 @@ permissionProfile,
|
|
|
787
787
|
// JSONL artifact flush is best effort.
|
|
788
788
|
});
|
|
789
789
|
// Report the run only after the child's extensions have shut down.
|
|
790
|
-
void Promise.resolve().then(
|
|
790
|
+
void Promise.resolve().then(async () => {
|
|
791
|
+
if (code === 0 && !result.interrupted && !result.timedOut && !result.stopped && !abortedBySignal) {
|
|
792
|
+
try { await session?.finishCommands?.(); }
|
|
793
|
+
catch (error) { result.error = error instanceof Error ? error.message : String(error); code = 1; }
|
|
794
|
+
}
|
|
795
|
+
await session?.dispose();
|
|
796
|
+
}).catch(() => undefined).then(() => {
|
|
791
797
|
resolve(code);
|
|
792
798
|
});
|
|
793
799
|
};
|
|
@@ -801,12 +807,12 @@ permissionProfile,
|
|
|
801
807
|
|
|
802
808
|
let activeLongRunningNotified = false;
|
|
803
809
|
let pendingToolResult: { tool: string; path?: string; mutates: boolean; startedAt?: number } | undefined;
|
|
804
|
-
// Pi host versions may represent one tool result as either a dedicated
|
|
805
|
-
// tool_result_end event or a message_end whose message role is toolResult.
|
|
806
|
-
// Remember correlated ids so normalizing both forms cannot duplicate output.
|
|
807
|
-
const handledToolResultIds = new Set<string>();
|
|
808
|
-
const MAX_HANDLED_TOOL_RESULT_IDS = 1024;
|
|
809
|
-
type ActiveToolCall = { key: string; tool: string; args: string; startedAt: number; path?: string };
|
|
810
|
+
// Pi host versions may represent one tool result as either a dedicated
|
|
811
|
+
// tool_result_end event or a message_end whose message role is toolResult.
|
|
812
|
+
// Remember correlated ids so normalizing both forms cannot duplicate output.
|
|
813
|
+
const handledToolResultIds = new Set<string>();
|
|
814
|
+
const MAX_HANDLED_TOOL_RESULT_IDS = 1024;
|
|
815
|
+
type ActiveToolCall = { attentionEmitted?: boolean; key: string; tool: string; args: string; startedAt: number; path?: string };
|
|
810
816
|
let activeToolSequence = 0;
|
|
811
817
|
const activeToolCalls = new Map<string, ActiveToolCall>();
|
|
812
818
|
const activeToolKeysByName = new Map<string, string[]>();
|
|
@@ -862,12 +868,12 @@ const MAX_HANDLED_TOOL_RESULT_IDS = 1024;
|
|
|
862
868
|
return key ? removeActiveToolCallKey(key) : undefined;
|
|
863
869
|
};
|
|
864
870
|
const openToolAttentionTarget = (now: number): ActiveToolCall | undefined => [...activeToolCalls.values()]
|
|
865
|
-
.filter((active) => shouldEmitOpenToolAttention({ config: controlConfig, currentTool: active.tool, currentToolStartedAt: active.startedAt, now }))
|
|
871
|
+
.filter((active) => !active.attentionEmitted && shouldEmitOpenToolAttention({ config: controlConfig, currentTool: active.tool, currentToolStartedAt: active.startedAt, now }))
|
|
866
872
|
.sort((left, right) => left.startedAt - right.startedAt)[0];
|
|
867
873
|
const mutatingFailures = createMutatingFailureState();
|
|
868
874
|
const mutatingFailureWindowMs = 5 * 60_000;
|
|
869
875
|
const currentToolDurationMs = (now: number) => progress.currentToolStartedAt ? Math.max(0, now - progress.currentToolStartedAt) : undefined;
|
|
870
|
-
const emitNeedsAttention = (now: number, input: { message?: string; reason?: ControlEvent["reason"]; recentFailureSummary?: string; currentTool?: string; currentPath?: string; currentToolDurationMs?: number } = {}): boolean => {
|
|
876
|
+
const emitNeedsAttention = (now: number, input: { message?: string; reason?: ControlEvent["reason"]; recentFailureSummary?: string; currentTool?: string; toolCallId?: string; currentPath?: string; currentToolDurationMs?: number } = {}): boolean => {
|
|
871
877
|
if (!controlConfig.enabled) return false;
|
|
872
878
|
const previous = progress.activityState;
|
|
873
879
|
progress.activityState = "needs_attention";
|
|
@@ -886,13 +892,14 @@ const MAX_HANDLED_TOOL_RESULT_IDS = 1024;
|
|
|
886
892
|
tokens: progress.tokens,
|
|
887
893
|
toolCount: progress.toolCount,
|
|
888
894
|
currentTool: input.currentTool ?? progress.currentTool,
|
|
895
|
+
toolCallId: input.toolCallId,
|
|
889
896
|
currentToolDurationMs: input.currentToolDurationMs ?? currentToolDurationMs(now),
|
|
890
897
|
currentPath: input.currentPath ?? progress.currentPath,
|
|
891
898
|
recentFailureSummary: input.recentFailureSummary,
|
|
892
899
|
taskPreview: task,
|
|
893
900
|
});
|
|
894
901
|
emitControlEvent(event);
|
|
895
|
-
return previous !== "needs_attention";
|
|
902
|
+
return previous !== "needs_attention" || input.reason === "tool_open_threshold";
|
|
896
903
|
};
|
|
897
904
|
const emitActiveLongRunning = (now: number, reason: ControlEvent["reason"]): boolean => {
|
|
898
905
|
if (!controlConfig.enabled || activeLongRunningNotified || progress.activityState === "needs_attention") return false;
|
|
@@ -934,13 +941,15 @@ const MAX_HANDLED_TOOL_RESULT_IDS = 1024;
|
|
|
934
941
|
if (idleState === "needs_attention") {
|
|
935
942
|
return progress.activityState === "needs_attention" ? false : emitNeedsAttention(now);
|
|
936
943
|
}
|
|
937
|
-
const toolAttentionTarget =
|
|
944
|
+
const toolAttentionTarget = openToolAttentionTarget(now);
|
|
938
945
|
if (toolAttentionTarget) {
|
|
946
|
+
toolAttentionTarget.attentionEmitted = true;
|
|
939
947
|
const durationMs = Math.max(0, now - toolAttentionTarget.startedAt);
|
|
940
948
|
return emitNeedsAttention(now, {
|
|
941
949
|
message: `${agent.name} has had tool '${toolAttentionTarget.tool}' open for ${Math.floor(durationMs / 1000)}s`,
|
|
942
950
|
reason: "tool_open_threshold",
|
|
943
951
|
currentTool: toolAttentionTarget.tool,
|
|
952
|
+
toolCallId: toolAttentionTarget.key.startsWith("id:") ? toolAttentionTarget.key.slice(3) : undefined,
|
|
944
953
|
currentPath: toolAttentionTarget.path,
|
|
945
954
|
currentToolDurationMs: durationMs,
|
|
946
955
|
});
|
|
@@ -983,68 +992,71 @@ const MAX_HANDLED_TOOL_RESULT_IDS = 1024;
|
|
|
983
992
|
emitUpdateSnapshot(output || "(running...)");
|
|
984
993
|
};
|
|
985
994
|
|
|
986
|
-
// Fork: shared, id-deduplicated tool-result completion. Pi hosts may
|
|
987
|
-
// deliver the same result either as a tool_result_end event or as a
|
|
988
|
-
// message_end whose message role is toolResult; both funnel through here
|
|
989
|
-
// so one result updates budget, output, and mutating-failure state once.
|
|
990
|
-
const handleToolResult = (message: Message, completion: { toolCallId?: unknown; toolName?: unknown }, now: number): void => {
|
|
991
|
-
const rawCallId = completion.toolCallId ?? (message as { toolCallId?: unknown }).toolCallId;
|
|
992
|
-
const callId = typeof rawCallId === "string" && rawCallId.length > 0 ? rawCallId : undefined;
|
|
993
|
-
if (callId) {
|
|
994
|
-
if (handledToolResultIds.has(callId)) return;
|
|
995
|
-
if (handledToolResultIds.size >= MAX_HANDLED_TOOL_RESULT_IDS) {
|
|
996
|
-
const oldest = handledToolResultIds.values().next().value;
|
|
997
|
-
if (typeof oldest === "string") handledToolResultIds.delete(oldest);
|
|
998
|
-
}
|
|
999
|
-
handledToolResultIds.add(callId);
|
|
1000
|
-
}
|
|
1001
|
-
result.messages!.push(message);
|
|
1002
|
-
const resultText = extractTextFromContent(message.content);
|
|
1003
|
-
// The result event's own tool name is authoritative; the single pending slot can
|
|
1004
|
-
// describe a different, overlapping call and serves only as a fallback.
|
|
1005
|
-
const blockedTool = (typeof completion.toolName === "string" && completion.toolName.length > 0
|
|
1006
|
-
? completion.toolName
|
|
1007
|
-
: undefined) ?? pendingToolResult?.tool;
|
|
1008
|
-
if (options.toolBudget && isToolBudgetBlockedMessage(options.toolBudget, resultText, blockedTool)) {
|
|
1009
|
-
result.toolBudgetBlocked = true;
|
|
1010
|
-
result.toolBudget = toolBudgetState(
|
|
1011
|
-
options.toolBudget,
|
|
1012
|
-
Math.max(progress.toolCount, options.toolBudget.hard + 1),
|
|
1013
|
-
blockedTool,
|
|
1014
|
-
);
|
|
1015
|
-
}
|
|
1016
|
-
appendRecentOutput(progress, resultText.split("\n").slice(-10));
|
|
1017
|
-
const toolSnapshot = pendingToolResult;
|
|
1018
|
-
pendingToolResult = undefined;
|
|
1019
|
-
if (toolSnapshot?.mutates && didMutatingToolFail(resultText)) {
|
|
1020
|
-
recordMutatingFailure(mutatingFailures, {
|
|
1021
|
-
tool: toolSnapshot.tool,
|
|
1022
|
-
path: toolSnapshot.path,
|
|
1023
|
-
error: resultText.split("\n").find((line) => line.trim())?.trim().slice(0, 180) ?? "mutating tool failed",
|
|
1024
|
-
ts: now,
|
|
1025
|
-
}, mutatingFailureWindowMs);
|
|
1026
|
-
if (shouldEscalateMutatingFailures(mutatingFailures, controlConfig.failedToolAttemptsBeforeAttention)) {
|
|
1027
|
-
emitNeedsAttention(now, {
|
|
1028
|
-
message: `${agent.name} needs attention after repeated mutating tool failures`,
|
|
1029
|
-
reason: "tool_failures",
|
|
1030
|
-
currentTool: toolSnapshot.tool,
|
|
1031
|
-
currentPath: toolSnapshot.path,
|
|
1032
|
-
currentToolDurationMs: toolSnapshot.startedAt ? Math.max(0, now - toolSnapshot.startedAt) : undefined,
|
|
1033
|
-
recentFailureSummary: summarizeRecentMutatingFailures(mutatingFailures),
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
} else if (toolSnapshot?.mutates) {
|
|
1037
|
-
resetMutatingFailureState(mutatingFailures);
|
|
1038
|
-
}
|
|
1039
|
-
fireUpdate();
|
|
1040
|
-
};
|
|
995
|
+
// Fork: shared, id-deduplicated tool-result completion. Pi hosts may
|
|
996
|
+
// deliver the same result either as a tool_result_end event or as a
|
|
997
|
+
// message_end whose message role is toolResult; both funnel through here
|
|
998
|
+
// so one result updates budget, output, and mutating-failure state once.
|
|
999
|
+
const handleToolResult = (message: Message, completion: { toolCallId?: unknown; toolName?: unknown }, now: number): void => {
|
|
1000
|
+
const rawCallId = completion.toolCallId ?? (message as { toolCallId?: unknown }).toolCallId;
|
|
1001
|
+
const callId = typeof rawCallId === "string" && rawCallId.length > 0 ? rawCallId : undefined;
|
|
1002
|
+
if (callId) {
|
|
1003
|
+
if (handledToolResultIds.has(callId)) return;
|
|
1004
|
+
if (handledToolResultIds.size >= MAX_HANDLED_TOOL_RESULT_IDS) {
|
|
1005
|
+
const oldest = handledToolResultIds.values().next().value;
|
|
1006
|
+
if (typeof oldest === "string") handledToolResultIds.delete(oldest);
|
|
1007
|
+
}
|
|
1008
|
+
handledToolResultIds.add(callId);
|
|
1009
|
+
}
|
|
1010
|
+
result.messages!.push(message);
|
|
1011
|
+
const resultText = extractTextFromContent(message.content);
|
|
1012
|
+
// The result event's own tool name is authoritative; the single pending slot can
|
|
1013
|
+
// describe a different, overlapping call and serves only as a fallback.
|
|
1014
|
+
const blockedTool = (typeof completion.toolName === "string" && completion.toolName.length > 0
|
|
1015
|
+
? completion.toolName
|
|
1016
|
+
: undefined) ?? pendingToolResult?.tool;
|
|
1017
|
+
if (options.toolBudget && isToolBudgetBlockedMessage(options.toolBudget, resultText, blockedTool)) {
|
|
1018
|
+
result.toolBudgetBlocked = true;
|
|
1019
|
+
result.toolBudget = toolBudgetState(
|
|
1020
|
+
options.toolBudget,
|
|
1021
|
+
Math.max(progress.toolCount, options.toolBudget.hard + 1),
|
|
1022
|
+
blockedTool,
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
appendRecentOutput(progress, resultText.split("\n").slice(-10));
|
|
1026
|
+
const toolSnapshot = pendingToolResult;
|
|
1027
|
+
pendingToolResult = undefined;
|
|
1028
|
+
if (toolSnapshot?.mutates && didMutatingToolFail(resultText)) {
|
|
1029
|
+
recordMutatingFailure(mutatingFailures, {
|
|
1030
|
+
tool: toolSnapshot.tool,
|
|
1031
|
+
path: toolSnapshot.path,
|
|
1032
|
+
error: resultText.split("\n").find((line) => line.trim())?.trim().slice(0, 180) ?? "mutating tool failed",
|
|
1033
|
+
ts: now,
|
|
1034
|
+
}, mutatingFailureWindowMs);
|
|
1035
|
+
if (shouldEscalateMutatingFailures(mutatingFailures, controlConfig.failedToolAttemptsBeforeAttention)) {
|
|
1036
|
+
emitNeedsAttention(now, {
|
|
1037
|
+
message: `${agent.name} needs attention after repeated mutating tool failures`,
|
|
1038
|
+
reason: "tool_failures",
|
|
1039
|
+
currentTool: toolSnapshot.tool,
|
|
1040
|
+
currentPath: toolSnapshot.path,
|
|
1041
|
+
currentToolDurationMs: toolSnapshot.startedAt ? Math.max(0, now - toolSnapshot.startedAt) : undefined,
|
|
1042
|
+
recentFailureSummary: summarizeRecentMutatingFailures(mutatingFailures),
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
} else if (toolSnapshot?.mutates) {
|
|
1046
|
+
resetMutatingFailureState(mutatingFailures);
|
|
1047
|
+
}
|
|
1048
|
+
fireUpdate();
|
|
1049
|
+
};
|
|
1041
1050
|
|
|
1042
1051
|
const processEvent = (evt: ChildSessionEvent & { message?: Message; toolName?: string; toolCallId?: string; args?: unknown; willRetry?: unknown }) => {
|
|
1043
1052
|
if (lifecycleFinished) return;
|
|
1044
1053
|
jsonlWriter.writeLine(JSON.stringify(projectChildSessionEventForJson(evt)));
|
|
1045
1054
|
shared.transcriptWriter?.writeChildEvent(evt);
|
|
1046
1055
|
shared.orcaProgressTab?.event(evt);
|
|
1047
|
-
if (evt.type === "compaction_start")
|
|
1056
|
+
if (evt.type === "compaction_start") {
|
|
1057
|
+
compactionStartedReceived = true;
|
|
1058
|
+
if (agentSettledReceived) afterCompactionSettlement = true;
|
|
1059
|
+
}
|
|
1048
1060
|
if (evt.type === "compaction_end" && evt.willRetry === true) {
|
|
1049
1061
|
compactionStartedReceived = false;
|
|
1050
1062
|
afterCompactionSettlement = false;
|
|
@@ -1141,11 +1153,11 @@ fireUpdate();
|
|
|
1141
1153
|
}
|
|
1142
1154
|
|
|
1143
1155
|
if (evt.type === "message_end" && evt.message) {
|
|
1144
|
-
if (evt.message.role === "toolResult") {
|
|
1145
|
-
// Fork: hosts that deliver tool results as message_end instead of
|
|
1146
|
-
// tool_result_end reach the same deduplicated completion path.
|
|
1147
|
-
handleToolResult(evt.message, evt, now);
|
|
1148
|
-
} else {
|
|
1156
|
+
if (evt.message.role === "toolResult") {
|
|
1157
|
+
// Fork: hosts that deliver tool results as message_end instead of
|
|
1158
|
+
// tool_result_end reach the same deduplicated completion path.
|
|
1159
|
+
handleToolResult(evt.message, evt, now);
|
|
1160
|
+
} else {
|
|
1149
1161
|
result.messages!.push(evt.message);
|
|
1150
1162
|
if (childWatchdog) {
|
|
1151
1163
|
const next = applyChildWatchdogMessage(childWatchdogState, evt.message);
|
|
@@ -1176,36 +1188,36 @@ handleToolResult(evt.message, evt, now);
|
|
|
1176
1188
|
progress.windowPeak = Math.max(progress.windowPeak ?? 0, window);
|
|
1177
1189
|
}
|
|
1178
1190
|
projectCompleteUsage();
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1191
|
+
if (evt.message.model) {
|
|
1192
|
+
progress.model = evt.message.model;
|
|
1193
|
+
if (!result.model) result.model = evt.message.model;
|
|
1194
|
+
if (expectedModelForVerification && !hasToolCall) {
|
|
1195
|
+
const modelVerificationError = formatSubagentModelVerificationError(expectedModelForVerification, evt.message.model, options.availableModels, options.modelResponseAliases, session?.virtualModelId);
|
|
1196
|
+
if (modelVerificationError && !result.error) result.error = modelVerificationError;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
if (evt.message.errorMessage) assistantError = evt.message.errorMessage;
|
|
1200
|
+
else if (hasToolCall && evt.message.stopReason === "toolUse") {
|
|
1201
|
+
// A recovered request can finish via a terminating tool, without a text stop.
|
|
1202
|
+
assistantError = undefined;
|
|
1203
|
+
}
|
|
1204
|
+
const assistantText = extractTextFromContent(evt.message.content);
|
|
1205
|
+
appendRecentOutput(progress, assistantText.split("\n").slice(-10));
|
|
1206
|
+
// Final assistant message: start the settle drain window.
|
|
1207
|
+
if (terminalAssistantStop) {
|
|
1208
|
+
if (!evt.message.errorMessage && assistantText.trim()) assistantError = undefined;
|
|
1209
|
+
cleanTerminalAssistantStopReceived ||= !evt.message.errorMessage;
|
|
1210
|
+
clearAllToolTimeouts();
|
|
1211
|
+
activeToolCalls.clear();
|
|
1212
|
+
activeToolKeysByName.clear();
|
|
1213
|
+
refreshCurrentTool();
|
|
1214
|
+
applyChildLifecycle(projectChildLifecycle(evt, true, childLifecycleState));
|
|
1185
1215
|
}
|
|
1186
1216
|
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
// A recovered request can finish via a terminating tool, without a text stop.
|
|
1190
|
-
assistantError = undefined;
|
|
1191
|
-
}
|
|
1192
|
-
const assistantText = extractTextFromContent(evt.message.content);
|
|
1193
|
-
appendRecentOutput(progress, assistantText.split("\n").slice(-10));
|
|
1194
|
-
// Final assistant message: start the settle drain window.
|
|
1195
|
-
if (terminalAssistantStop) {
|
|
1196
|
-
if (!evt.message.errorMessage && assistantText.trim()) assistantError = undefined;
|
|
1197
|
-
cleanTerminalAssistantStopReceived ||= !evt.message.errorMessage;
|
|
1198
|
-
clearAllToolTimeouts();
|
|
1199
|
-
activeToolCalls.clear();
|
|
1200
|
-
activeToolKeysByName.clear();
|
|
1201
|
-
refreshCurrentTool();
|
|
1202
|
-
applyChildLifecycle(projectChildLifecycle(evt, true, childLifecycleState));
|
|
1203
|
-
}
|
|
1217
|
+
updateActivityState(now);
|
|
1218
|
+
fireUpdate();
|
|
1204
1219
|
}
|
|
1205
|
-
updateActivityState(now);
|
|
1206
|
-
fireUpdate();
|
|
1207
1220
|
}
|
|
1208
|
-
}
|
|
1209
1221
|
|
|
1210
1222
|
if (evt.type === "tool_result_end" && evt.message) {
|
|
1211
1223
|
const toolResultCompletion = {
|
|
@@ -1222,16 +1234,16 @@ handleToolResult(evt.message, evt, now);
|
|
|
1222
1234
|
});
|
|
1223
1235
|
refreshCurrentTool();
|
|
1224
1236
|
}
|
|
1225
|
-
// Fork: the shared, id-deduplicated tail (message push, budget,
|
|
1226
|
-
// mutating-failure tracking, output) lives in handleToolResult; hosts
|
|
1227
|
-
// may deliver the same result via message_end(role=toolResult).
|
|
1228
|
-
handleToolResult(evt.message, evt, now);
|
|
1237
|
+
// Fork: the shared, id-deduplicated tail (message push, budget,
|
|
1238
|
+
// mutating-failure tracking, output) lives in handleToolResult; hosts
|
|
1239
|
+
// may deliver the same result via message_end(role=toolResult).
|
|
1240
|
+
handleToolResult(evt.message, evt, now);
|
|
1229
1241
|
}
|
|
1230
1242
|
};
|
|
1231
|
-
// SAFETY: this callback is only ever invoked with child-watchdog status events
|
|
1232
|
-
// (declared as ChildWatchdogStatusEvent above); those carry the session-event
|
|
1233
|
-
// fields `processEvent` needs, and `processEvent` re-validates the shape with
|
|
1234
|
-
// `isChildWatchdogStatusEvent` before touching watchdog-specific fields.
|
|
1243
|
+
// SAFETY: this callback is only ever invoked with child-watchdog status events
|
|
1244
|
+
// (declared as ChildWatchdogStatusEvent above); those carry the session-event
|
|
1245
|
+
// fields `processEvent` needs, and `processEvent` re-validates the shape with
|
|
1246
|
+
// `isChildWatchdogStatusEvent` before touching watchdog-specific fields.
|
|
1235
1247
|
onWatchdogStatus = (event) => processEvent(event as unknown as Parameters<typeof processEvent>[0]);
|
|
1236
1248
|
|
|
1237
1249
|
fireUpdate();
|
|
@@ -1364,6 +1376,8 @@ handleToolResult(evt.message, evt, now);
|
|
|
1364
1376
|
if (!closeError && (abortedBySignal || session?.shutDown) && !result.interrupted && !result.timedOut) {
|
|
1365
1377
|
closeError = session?.shutDown ? "Subagent stopped because the parent session shut down." : STOPPED_BEFORE_COMPLETION_ERROR;
|
|
1366
1378
|
}
|
|
1379
|
+
// A workflow child ended by the workflow's abort signal was stopped, not failed.
|
|
1380
|
+
if (options.abortedAsStopped && abortedBySignal && !session?.shutDown && !result.interrupted && !result.timedOut) result.stopped = true;
|
|
1367
1381
|
if (!closeError && forced && !forcedDrainAfterFinalSuccess) {
|
|
1368
1382
|
closeError = "Subagent session did not settle after it was aborted.";
|
|
1369
1383
|
}
|
|
@@ -1534,17 +1548,17 @@ handleToolResult(evt.message, evt, now);
|
|
|
1534
1548
|
&& hasEmptyTerminalAssistantResponse(messages)
|
|
1535
1549
|
&& (progress.toolCount > 0 || Boolean(finalText?.trim()));
|
|
1536
1550
|
if ((missingOutput || terminalEmptyAfterUsefulWork) && (!errInfo.hasError || hasEmptyTerminalAssistantResponse(messages))) {
|
|
1537
|
-
// A startup guard can block the first turn, which leaves no message to
|
|
1538
|
-
// inspect. Prefer the reason the blocked child published.
|
|
1539
|
-
const sandboxDiagnostic = readSandboxStartupDiagnostic(launch.sandboxDiagnosticsPath);
|
|
1551
|
+
// A startup guard can block the first turn, which leaves no message to
|
|
1552
|
+
// inspect. Prefer the reason the blocked child published.
|
|
1553
|
+
const sandboxDiagnostic = readSandboxStartupDiagnostic(launch.sandboxDiagnosticsPath);
|
|
1540
1554
|
result.exitCode = 1;
|
|
1541
|
-
if (sandboxDiagnostic) {
|
|
1542
|
-
result.error = sandboxDiagnostic.reason;
|
|
1543
|
-
result.startupBlocked = true;
|
|
1544
|
-
clearSandboxStartupDiagnostic(launch.sandboxDiagnosticsPath);
|
|
1545
|
-
} else {
|
|
1546
|
-
|
|
1547
|
-
}
|
|
1555
|
+
if (sandboxDiagnostic) {
|
|
1556
|
+
result.error = sandboxDiagnostic.reason;
|
|
1557
|
+
result.startupBlocked = true;
|
|
1558
|
+
clearSandboxStartupDiagnostic(launch.sandboxDiagnosticsPath);
|
|
1559
|
+
} else {
|
|
1560
|
+
result.error = formatEmptyTerminalAssistantResponseError(messages);
|
|
1561
|
+
}
|
|
1548
1562
|
} else if (errInfo.hasError) {
|
|
1549
1563
|
result.exitCode = errInfo.exitCode ?? 1;
|
|
1550
1564
|
result.error = errInfo.details
|