@xzzpig/pi-subagents 0.4.1 → 0.5.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 +175 -0
- package/README.md +4 -0
- package/agents/oracle.md +3 -1
- package/agents/reviewer.md +1 -0
- package/agents/scout.md +2 -2
- package/agents/worker.md +2 -1
- package/async-retention-discovery-worker.mjs +180 -0
- package/docs/agents.md +41 -3
- package/docs/configuration.md +41 -13
- package/docs/extension-api.md +65 -2
- package/docs/models.md +2 -0
- package/docs/observability.md +41 -5
- package/docs/tool-reference.md +38 -39
- package/docs/workflows.md +173 -3
- package/package.json +14 -10
- package/prompts/council.md +48 -0
- package/skills/council-mode/SKILL.md +230 -0
- package/skills/pi-subagents/SKILL.md +8 -4
- package/skills/pi-subagents/references/constraints-and-recipes.md +13 -6
- package/skills/pi-subagents/references/execution-controls.md +40 -15
- package/skills/pi-subagents/references/management-authoring-rpc.md +3 -3
- package/skills/pi-subagents/references/multi-lane-orchestration.md +39 -0
- package/skills/pi-subagents/references/prompting-and-roles.md +4 -2
- package/src/agents/agent-management.ts +471 -377
- package/src/agents/agent-serializer.ts +2 -0
- package/src/agents/agents.ts +186 -44
- package/src/agents/builtin-names.ts +9 -0
- package/src/agents/runtime-agent-registry.ts +418 -0
- package/src/agents/skills.ts +1 -1
- package/src/api/agent-management.ts +9 -0
- package/src/api/agents.ts +7 -0
- package/src/api/external-job-provider.ts +186 -0
- package/src/api/preflight.ts +45 -13
- package/src/api/shared-types.ts +2 -0
- package/src/extension/config.ts +6 -3
- package/src/extension/doctor.ts +4 -6
- package/src/extension/fanout-child.ts +2 -2
- package/src/extension/index.ts +183 -90
- package/src/extension/public-execution.ts +31 -2
- package/src/extension/rpc.ts +41 -1
- package/src/extension/schemas.ts +17 -37
- package/src/extension/tool-description.ts +35 -24
- package/src/inspectors/herdr/actions.ts +2 -2
- package/src/inspectors/herdr/inspector-runner.ts +2 -1
- package/src/inspectors/herdr/project-panes.ts +2 -2
- package/src/intercom/native-supervisor-channel.ts +32 -10
- package/src/missions/lifecycle.ts +6 -1
- package/src/missions/store.ts +4 -9
- package/src/missions/workflow-state.ts +2 -2
- package/src/profiles/profiles.ts +3 -1
- package/src/runs/background/active-run-index.ts +31 -8
- package/src/runs/background/async-execution.ts +70 -41
- package/src/runs/background/async-job-tracker.ts +24 -7
- package/src/runs/background/async-resume.ts +49 -16
- package/src/runs/background/async-retention.ts +886 -0
- package/src/runs/background/async-status-snapshot.ts +14 -5
- package/src/runs/background/async-status.ts +39 -53
- package/src/runs/background/auto-drain.ts +1 -0
- package/src/runs/background/chain-append.ts +3 -33
- package/src/runs/background/completion-dedupe.ts +5 -1
- package/src/runs/background/completion-replay.ts +22 -12
- package/src/runs/background/control-channel.ts +14 -68
- package/src/runs/background/fleet-view.ts +68 -19
- package/src/runs/background/index-segment.ts +59 -0
- package/src/runs/background/inspect-rpc.ts +443 -0
- package/src/runs/background/notify.ts +31 -5
- package/src/runs/background/result-files.ts +158 -90
- package/src/runs/background/result-watcher.ts +124 -20
- package/src/runs/background/resume-guidance.ts +8 -5
- package/src/runs/background/retained-children.ts +13 -3
- package/src/runs/background/run-id-query.ts +7 -0
- package/src/runs/background/run-id-resolver.ts +11 -9
- package/src/runs/background/run-status.ts +27 -18
- package/src/runs/background/scheduled-runs.ts +24 -4
- package/src/runs/background/stale-run-reconciler.ts +6 -3
- package/src/runs/background/steering.ts +11 -1
- package/src/runs/background/subagent-runner.ts +260 -144
- package/src/runs/background/subagent-wait.ts +17 -13
- package/src/runs/background/terminal-run-index.ts +138 -0
- package/src/runs/background/wait-completions.ts +21 -4
- package/src/runs/background/wait-subscriptions.ts +81 -2
- package/src/runs/background/wait-tool.ts +1 -0
- package/src/runs/foreground/async-steering-action.ts +21 -14
- package/src/runs/foreground/execution.ts +104 -71
- package/src/runs/foreground/subagent-executor.ts +816 -1593
- package/src/runs/foreground/workflow-detach-reconcile.ts +262 -0
- package/src/runs/foreground/workflow-foreground-steering.ts +6 -5
- package/src/runs/shared/acceptance.ts +48 -5
- package/src/runs/shared/chain-outputs.ts +1 -3
- package/src/runs/shared/external-job-bridge.ts +444 -0
- package/src/runs/shared/external-job-runner.ts +286 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +14 -0
- package/src/runs/shared/model-exclusions.ts +242 -0
- package/src/runs/shared/model-fallback.ts +153 -40
- package/src/runs/shared/orca-progress-tabs.ts +84 -22
- package/src/runs/shared/parallel-handoff.ts +46 -4
- package/src/runs/shared/parallel-utils.ts +4 -15
- package/src/runs/shared/permissions.ts +5 -1
- package/src/runs/shared/pi-args.ts +8 -1
- package/src/runs/shared/session-lease.ts +0 -6
- package/src/runs/shared/subagent-control.ts +51 -7
- package/src/runs/shared/subagent-prompt-runtime.ts +12 -6
- package/src/runs/shared/workflow-graph.ts +1 -23
- package/src/runs/shared/worktree.ts +14 -2
- package/src/shared/atomic-json.ts +22 -2
- package/src/shared/capacity-resilient-json.ts +102 -0
- package/src/shared/completion-owner.ts +14 -0
- package/src/shared/file-system-retry.ts +49 -1
- package/src/shared/fork-context.ts +59 -1
- package/src/shared/model-info.ts +20 -0
- package/src/shared/prompt-resources.ts +0 -40
- package/src/shared/settings.ts +5 -29
- package/src/shared/types.ts +106 -26
- package/src/shared/utils.ts +8 -0
- package/src/shared/watch-strategy.ts +10 -0
- package/src/slash/slash-bridge.ts +2 -1
- package/src/slash/slash-commands.ts +47 -7
- package/src/slash/slash-live-state.ts +3 -3
- package/src/tui/fleet-status.ts +86 -1
- package/src/tui/fleet.ts +117 -16
- package/src/tui/render.ts +73 -3
- package/src/watchdog/change-signature.ts +1 -1
- package/src/watchdog/lsp-diagnostics.ts +1 -0
- package/src/workflows/chat-progress.ts +2 -2
- package/src/workflows/scripted-workflow.ts +320 -79
- package/src/workflows/workflow-receipt.ts +140 -0
- package/src/runs/foreground/chain-clarify.ts +0 -1354
- package/src/runs/foreground/chain-execution.ts +0 -1581
|
@@ -74,6 +74,7 @@ import {
|
|
|
74
74
|
buildModelCandidates,
|
|
75
75
|
formatModelAttemptNote,
|
|
76
76
|
isRetryableModelFailure,
|
|
77
|
+
recordRetryableModelFailure,
|
|
77
78
|
} from "../shared/model-fallback.ts";
|
|
78
79
|
import {
|
|
79
80
|
SUBAGENT_STARTUP_RETRY_DELAYS_MS,
|
|
@@ -700,6 +701,11 @@ async function runSingleAttempt(
|
|
|
700
701
|
|
|
701
702
|
let activeLongRunningNotified = false;
|
|
702
703
|
let pendingToolResult: { tool: string; path?: string; mutates: boolean; startedAt?: number } | undefined;
|
|
704
|
+
// Pi host versions may represent one tool result as either a dedicated
|
|
705
|
+
// tool_result_end event or a message_end whose message role is toolResult.
|
|
706
|
+
// Remember correlated ids so normalizing both forms cannot duplicate output.
|
|
707
|
+
const handledToolResultIds = new Set<string>();
|
|
708
|
+
const MAX_HANDLED_TOOL_RESULT_IDS = 1024;
|
|
703
709
|
type ActiveToolCall = { key: string; tool: string; args: string; startedAt: number; path?: string };
|
|
704
710
|
let activeToolSequence = 0;
|
|
705
711
|
const activeToolCalls = new Map<string, ActiveToolCall>();
|
|
@@ -783,6 +789,7 @@ async function runSingleAttempt(
|
|
|
783
789
|
currentToolDurationMs: input.currentToolDurationMs ?? currentToolDurationMs(now),
|
|
784
790
|
currentPath: input.currentPath ?? progress.currentPath,
|
|
785
791
|
recentFailureSummary: input.recentFailureSummary,
|
|
792
|
+
taskPreview: task,
|
|
786
793
|
});
|
|
787
794
|
emitControlEvent(event);
|
|
788
795
|
return previous !== "needs_attention";
|
|
@@ -809,6 +816,7 @@ async function runSingleAttempt(
|
|
|
809
816
|
currentToolDurationMs: currentToolDurationMs(now),
|
|
810
817
|
currentPath: progress.currentPath,
|
|
811
818
|
elapsedMs: now - startTime,
|
|
819
|
+
taskPreview: task,
|
|
812
820
|
}));
|
|
813
821
|
return true;
|
|
814
822
|
};
|
|
@@ -870,6 +878,7 @@ async function runSingleAttempt(
|
|
|
870
878
|
startedAt: startTime,
|
|
871
879
|
lastActivityAt: progress.lastActivityAt,
|
|
872
880
|
currentTool: progress.currentTool,
|
|
881
|
+
thinking: resolvedThinking,
|
|
873
882
|
now,
|
|
874
883
|
});
|
|
875
884
|
if (idleState === "needs_attention") {
|
|
@@ -919,6 +928,53 @@ async function runSingleAttempt(
|
|
|
919
928
|
emitUpdateSnapshot(output || "(running...)");
|
|
920
929
|
};
|
|
921
930
|
|
|
931
|
+
const toolResultCallId = (message: Message): string | undefined => {
|
|
932
|
+
const value = (message as { toolCallId?: unknown }).toolCallId;
|
|
933
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
const handleToolResult = (message: Message, now: number): void => {
|
|
937
|
+
const callId = toolResultCallId(message);
|
|
938
|
+
if (callId) {
|
|
939
|
+
if (handledToolResultIds.has(callId)) return;
|
|
940
|
+
if (handledToolResultIds.size >= MAX_HANDLED_TOOL_RESULT_IDS) {
|
|
941
|
+
const oldest = handledToolResultIds.values().next().value;
|
|
942
|
+
if (typeof oldest === "string") handledToolResultIds.delete(oldest);
|
|
943
|
+
}
|
|
944
|
+
handledToolResultIds.add(callId);
|
|
945
|
+
}
|
|
946
|
+
result.messages!.push(message);
|
|
947
|
+
const resultText = extractTextFromContent(message.content);
|
|
948
|
+
if (options.toolBudget && pendingToolResult && resultText.includes("Tool budget hard limit reached")) {
|
|
949
|
+
result.toolBudgetBlocked = true;
|
|
950
|
+
result.toolBudget = toolBudgetState(options.toolBudget, progress.toolCount, pendingToolResult.tool);
|
|
951
|
+
}
|
|
952
|
+
appendRecentOutput(progress, resultText.split("\n").slice(-10));
|
|
953
|
+
const toolSnapshot = pendingToolResult;
|
|
954
|
+
pendingToolResult = undefined;
|
|
955
|
+
if (toolSnapshot?.mutates && didMutatingToolFail(resultText)) {
|
|
956
|
+
recordMutatingFailure(mutatingFailures, {
|
|
957
|
+
tool: toolSnapshot.tool,
|
|
958
|
+
path: toolSnapshot.path,
|
|
959
|
+
error: resultText.split("\n").find((line) => line.trim())?.trim().slice(0, 180) ?? "mutating tool failed",
|
|
960
|
+
ts: now,
|
|
961
|
+
}, mutatingFailureWindowMs);
|
|
962
|
+
if (shouldEscalateMutatingFailures(mutatingFailures, controlConfig.failedToolAttemptsBeforeAttention)) {
|
|
963
|
+
emitNeedsAttention(now, {
|
|
964
|
+
message: `${agent.name} needs attention after repeated mutating tool failures`,
|
|
965
|
+
reason: "tool_failures",
|
|
966
|
+
currentTool: toolSnapshot.tool,
|
|
967
|
+
currentPath: toolSnapshot.path,
|
|
968
|
+
currentToolDurationMs: toolSnapshot.startedAt ? Math.max(0, now - toolSnapshot.startedAt) : undefined,
|
|
969
|
+
recentFailureSummary: summarizeRecentMutatingFailures(mutatingFailures),
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
} else if (toolSnapshot?.mutates) {
|
|
973
|
+
resetMutatingFailureState(mutatingFailures);
|
|
974
|
+
}
|
|
975
|
+
fireUpdate();
|
|
976
|
+
};
|
|
977
|
+
|
|
922
978
|
const rawStdoutTail = createBoundedByteTail();
|
|
923
979
|
const processLine = (line: string) => {
|
|
924
980
|
if (!line.trim()) return;
|
|
@@ -1003,80 +1059,55 @@ async function runSingleAttempt(
|
|
|
1003
1059
|
}
|
|
1004
1060
|
|
|
1005
1061
|
if (evt.type === "message_end" && evt.message) {
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
result.usage.
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1062
|
+
if (evt.message.role === "toolResult") {
|
|
1063
|
+
handleToolResult(evt.message, now);
|
|
1064
|
+
} else {
|
|
1065
|
+
result.messages!.push(evt.message);
|
|
1066
|
+
if (evt.message.role === "assistant") {
|
|
1067
|
+
result.usage.turns++;
|
|
1068
|
+
progress.turnCount = result.usage.turns;
|
|
1069
|
+
const stopReason = (evt.message as { stopReason?: string }).stopReason;
|
|
1070
|
+
const toolCalls = Array.isArray(evt.message.content)
|
|
1071
|
+
? evt.message.content.filter((part) => (part as { type?: string }).type === "toolCall")
|
|
1072
|
+
: [];
|
|
1073
|
+
const hasToolCall = toolCalls.length > 0;
|
|
1074
|
+
const terminalAssistantStop = stopReason === "stop" && !hasToolCall;
|
|
1075
|
+
const terminalStructuredOutputCall = Boolean(options.structuredOutput)
|
|
1076
|
+
&& toolCalls.length === 1
|
|
1077
|
+
&& (toolCalls[0] as { name?: string }).name === "structured_output";
|
|
1078
|
+
updateTurnBudget(result.usage.turns, terminalAssistantStop || terminalStructuredOutputCall, hasToolCall || Boolean(progress.currentTool));
|
|
1079
|
+
const u = evt.message.usage;
|
|
1080
|
+
if (u) {
|
|
1081
|
+
result.usage.input += u.input || 0;
|
|
1082
|
+
result.usage.output += u.output || 0;
|
|
1083
|
+
result.usage.cacheRead += u.cacheRead || 0;
|
|
1084
|
+
result.usage.cacheWrite += u.cacheWrite || 0;
|
|
1085
|
+
result.usage.cost += u.cost?.total || 0;
|
|
1086
|
+
progress.tokens = result.usage.input + result.usage.output;
|
|
1087
|
+
progress.inputTokens = result.usage.input;
|
|
1088
|
+
progress.outputTokens = result.usage.output;
|
|
1089
|
+
}
|
|
1090
|
+
if (evt.message.model) {
|
|
1091
|
+
progress.model = evt.message.model;
|
|
1092
|
+
if (!result.model) result.model = evt.message.model;
|
|
1093
|
+
}
|
|
1094
|
+
if (evt.message.errorMessage) assistantError = evt.message.errorMessage;
|
|
1095
|
+
const assistantText = extractTextFromContent(evt.message.content);
|
|
1096
|
+
appendRecentOutput(progress, assistantText.split("\n").slice(-10));
|
|
1097
|
+
// Final assistant message: start the exit drain window.
|
|
1098
|
+
if (terminalAssistantStop) {
|
|
1099
|
+
if (!evt.message.errorMessage && assistantText.trim()) assistantError = undefined;
|
|
1100
|
+
cleanTerminalAssistantStopReceived ||= !evt.message.errorMessage;
|
|
1101
|
+
applyChildLifecycle(projectChildLifecycle(evt, true));
|
|
1102
|
+
}
|
|
1043
1103
|
}
|
|
1104
|
+
updateActivityState(now);
|
|
1105
|
+
fireUpdate();
|
|
1044
1106
|
}
|
|
1045
|
-
updateActivityState(now);
|
|
1046
|
-
fireUpdate();
|
|
1047
1107
|
}
|
|
1048
1108
|
|
|
1049
1109
|
if (evt.type === "tool_result_end" && evt.message) {
|
|
1050
|
-
|
|
1051
|
-
const resultText = extractTextFromContent(evt.message.content);
|
|
1052
|
-
if (options.toolBudget && pendingToolResult && resultText.includes("Tool budget hard limit reached")) {
|
|
1053
|
-
result.toolBudgetBlocked = true;
|
|
1054
|
-
result.toolBudget = toolBudgetState(options.toolBudget, progress.toolCount, pendingToolResult.tool);
|
|
1055
|
-
}
|
|
1056
|
-
appendRecentOutput(progress, resultText.split("\n").slice(-10));
|
|
1057
|
-
const toolSnapshot = pendingToolResult;
|
|
1058
|
-
pendingToolResult = undefined;
|
|
1059
|
-
if (toolSnapshot?.mutates && didMutatingToolFail(resultText)) {
|
|
1060
|
-
recordMutatingFailure(mutatingFailures, {
|
|
1061
|
-
tool: toolSnapshot.tool,
|
|
1062
|
-
path: toolSnapshot.path,
|
|
1063
|
-
error: resultText.split("\n").find((line) => line.trim())?.trim().slice(0, 180) ?? "mutating tool failed",
|
|
1064
|
-
ts: now,
|
|
1065
|
-
}, mutatingFailureWindowMs);
|
|
1066
|
-
if (shouldEscalateMutatingFailures(mutatingFailures, controlConfig.failedToolAttemptsBeforeAttention)) {
|
|
1067
|
-
emitNeedsAttention(now, {
|
|
1068
|
-
message: `${agent.name} needs attention after repeated mutating tool failures`,
|
|
1069
|
-
reason: "tool_failures",
|
|
1070
|
-
currentTool: toolSnapshot.tool,
|
|
1071
|
-
currentPath: toolSnapshot.path,
|
|
1072
|
-
currentToolDurationMs: toolSnapshot.startedAt ? Math.max(0, now - toolSnapshot.startedAt) : undefined,
|
|
1073
|
-
recentFailureSummary: summarizeRecentMutatingFailures(mutatingFailures),
|
|
1074
|
-
});
|
|
1075
|
-
}
|
|
1076
|
-
} else if (toolSnapshot?.mutates) {
|
|
1077
|
-
resetMutatingFailureState(mutatingFailures);
|
|
1078
|
-
}
|
|
1079
|
-
fireUpdate();
|
|
1110
|
+
handleToolResult(evt.message, now);
|
|
1080
1111
|
}
|
|
1081
1112
|
};
|
|
1082
1113
|
|
|
@@ -1671,7 +1702,7 @@ async function runSyncCompletionInner(
|
|
|
1671
1702
|
agent.fallbackModels,
|
|
1672
1703
|
options.availableModels,
|
|
1673
1704
|
options.preferredModelProvider,
|
|
1674
|
-
{ scope: options.modelScope },
|
|
1705
|
+
{ scope: options.modelScope, primaryModelFromParent: options.modelOverrideFromParent },
|
|
1675
1706
|
);
|
|
1676
1707
|
const attemptedModels: string[] = [];
|
|
1677
1708
|
const modelAttempts: ModelAttempt[] = [];
|
|
@@ -1858,7 +1889,9 @@ async function runSyncCompletionInner(
|
|
|
1858
1889
|
attempt.error = startupError;
|
|
1859
1890
|
break modelAttemptsLoop;
|
|
1860
1891
|
}
|
|
1861
|
-
|
|
1892
|
+
const retryableModelFailure = isRetryableModelFailure(result.error);
|
|
1893
|
+
if (retryableModelFailure) recordRetryableModelFailure(result.model ?? candidate, result.error);
|
|
1894
|
+
if (!retryableModelFailure || modelIndex === modelsToTry.length - 1) break modelAttemptsLoop;
|
|
1862
1895
|
attemptNotes.push(formatModelAttemptNote(attempt, modelsToTry[modelIndex + 1]));
|
|
1863
1896
|
break;
|
|
1864
1897
|
}
|