@opengsd/gsd-pi 1.2.0-dev.9ad8ae33 → 1.2.0-dev.a6376d75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-model-override.d.ts +15 -0
- package/dist/cli-model-override.js +21 -0
- package/dist/cli.js +1 -18
- package/dist/loader.js +6 -4
- package/dist/register-agent-bundles.d.ts +11 -2
- package/dist/register-agent-bundles.js +18 -4
- package/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/extensions/ask-user-questions.js +3 -2
- package/dist/resources/extensions/claude-code-cli/stream-adapter.js +447 -215
- package/dist/resources/extensions/claude-code-cli/turn-assembler.js +33 -1
- package/dist/resources/extensions/gsd/auto/closeout.js +215 -0
- package/dist/resources/extensions/gsd/auto/dispatch-history.js +21 -6
- package/dist/resources/extensions/gsd/auto/dispatch.js +365 -0
- package/dist/resources/extensions/gsd/auto/finalize.js +347 -0
- package/dist/resources/extensions/gsd/auto/loop.js +4 -1
- package/dist/resources/extensions/gsd/auto/milestone-lease-reclaim.js +56 -0
- package/dist/resources/extensions/gsd/auto/orchestrator.js +85 -15
- package/dist/resources/extensions/gsd/auto/phase-helpers.js +146 -0
- package/dist/resources/extensions/gsd/auto/phases.js +17 -2372
- package/dist/resources/extensions/gsd/auto/pre-dispatch.js +534 -0
- package/dist/resources/extensions/gsd/auto/unit-phase.js +694 -0
- package/dist/resources/extensions/gsd/auto/workflow-unit-dispatch.js +1 -1
- package/dist/resources/extensions/gsd/auto/worktree-safety-phase.js +125 -0
- package/dist/resources/extensions/gsd/auto-worktree.js +1 -1
- package/dist/resources/extensions/gsd/auto.js +15 -1
- package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +37 -7
- package/dist/resources/extensions/gsd/commands-mcp-status.js +2 -2
- package/dist/resources/extensions/gsd/commands-workflow-templates.js +9 -2
- package/dist/resources/extensions/gsd/db/queries.js +30 -0
- package/dist/resources/extensions/gsd/doctor-environment.js +256 -125
- package/dist/resources/extensions/gsd/guided-flow.js +88 -2
- package/dist/resources/extensions/gsd/health-widget.js +87 -28
- package/dist/resources/extensions/gsd/mcp-bridge.js +10 -0
- package/dist/resources/extensions/gsd/milestone-settlement.js +2 -2
- package/dist/resources/extensions/gsd/notifications.js +12 -7
- package/dist/resources/extensions/gsd/prompts/complete-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/execute-task.md +2 -1
- package/dist/resources/extensions/gsd/prompts/run-uat.md +2 -0
- package/dist/resources/extensions/gsd/prompts/workflow-start.md +2 -1
- package/dist/resources/extensions/gsd/skill-activation.js +3 -6
- package/dist/resources/extensions/gsd/state.js +6 -2
- package/dist/resources/extensions/gsd/tool-surface-readiness.js +83 -31
- package/dist/resources/extensions/gsd/tools/complete-task.js +62 -0
- package/dist/resources/extensions/gsd/unit-context-composer.js +1 -1
- package/dist/resources/extensions/gsd/unit-registry.js +34 -4
- package/dist/resources/extensions/gsd/workflow-mcp-auto-prep.js +2 -0
- package/dist/resources/extensions/gsd/workflow-mcp-readiness-cache.js +105 -0
- package/dist/resources/extensions/gsd/worktree-safety.js +28 -26
- package/dist/resources/extensions/mcp-client/manager.js +6 -1
- package/dist/runtime-checks.d.ts +10 -0
- package/dist/runtime-checks.js +27 -0
- package/dist/tsconfig.extensions.tsbuildinfo +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +8 -8
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +8 -8
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/package.json +2 -2
- package/packages/cloud-mcp-gateway/package.json +2 -2
- package/packages/contracts/package.json +1 -1
- package/packages/daemon/package.json +4 -4
- package/packages/gsd-agent-core/dist/sdk.d.ts.map +1 -1
- package/packages/gsd-agent-core/dist/sdk.js +6 -4
- package/packages/gsd-agent-core/dist/sdk.js.map +1 -1
- package/packages/gsd-agent-core/package.json +5 -5
- package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.d.ts +2 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.js +10 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts +8 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js +50 -6
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/transcript-design.d.ts +2 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/components/transcript-design.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/transcript-design.js +34 -5
- package/packages/gsd-agent-modes/dist/modes/interactive/components/transcript-design.js.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js +12 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-selectors-settings.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-selectors-settings.js +4 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-selectors-settings.js.map +1 -1
- package/packages/gsd-agent-modes/package.json +7 -7
- package/packages/mcp-server/README.md +12 -3
- package/packages/mcp-server/dist/cli-runner.d.ts +40 -0
- package/packages/mcp-server/dist/cli-runner.d.ts.map +1 -0
- package/packages/mcp-server/dist/cli-runner.js +137 -0
- package/packages/mcp-server/dist/cli-runner.js.map +1 -0
- package/packages/mcp-server/dist/cli.js +2 -58
- package/packages/mcp-server/dist/cli.js.map +1 -1
- package/packages/mcp-server/dist/pid-registry.d.ts +46 -0
- package/packages/mcp-server/dist/pid-registry.d.ts.map +1 -0
- package/packages/mcp-server/dist/pid-registry.js +452 -0
- package/packages/mcp-server/dist/pid-registry.js.map +1 -0
- package/packages/mcp-server/dist/probe-mode.d.ts +4 -0
- package/packages/mcp-server/dist/probe-mode.d.ts.map +1 -0
- package/packages/mcp-server/dist/probe-mode.js +10 -0
- package/packages/mcp-server/dist/probe-mode.js.map +1 -0
- package/packages/mcp-server/dist/stdio-watchdog.d.ts +8 -0
- package/packages/mcp-server/dist/stdio-watchdog.d.ts.map +1 -0
- package/packages/mcp-server/dist/stdio-watchdog.js +40 -0
- package/packages/mcp-server/dist/stdio-watchdog.js.map +1 -0
- package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
- package/packages/mcp-server/dist/workflow-tools.js +62 -43
- package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
- package/packages/mcp-server/package.json +5 -5
- package/packages/native/package.json +1 -1
- package/packages/pi-agent-core/dist/agent-loop.js +43 -2
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/package.json +1 -1
- package/packages/pi-ai/package.json +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +3 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.js +11 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/theme/theme.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/theme/theme.js +45 -17
- package/packages/pi-coding-agent/dist/theme/theme.js.map +1 -1
- package/packages/pi-coding-agent/package.json +7 -7
- package/packages/pi-tui/dist/index.d.ts +1 -1
- package/packages/pi-tui/dist/index.d.ts.map +1 -1
- package/packages/pi-tui/dist/index.js +1 -1
- package/packages/pi-tui/dist/index.js.map +1 -1
- package/packages/pi-tui/dist/terminal-image.d.ts +33 -0
- package/packages/pi-tui/dist/terminal-image.d.ts.map +1 -1
- package/packages/pi-tui/dist/terminal-image.js +54 -2
- package/packages/pi-tui/dist/terminal-image.js.map +1 -1
- package/packages/pi-tui/dist/tui.d.ts +8 -0
- package/packages/pi-tui/dist/tui.d.ts.map +1 -1
- package/packages/pi-tui/dist/tui.js +63 -18
- package/packages/pi-tui/dist/tui.js.map +1 -1
- package/packages/pi-tui/dist/utils.d.ts.map +1 -1
- package/packages/pi-tui/dist/utils.js +110 -36
- package/packages/pi-tui/dist/utils.js.map +1 -1
- package/packages/pi-tui/package.json +2 -2
- package/packages/rpc-client/package.json +2 -2
- package/pkg/dist/theme/theme.d.ts.map +1 -1
- package/pkg/dist/theme/theme.js +45 -17
- package/pkg/dist/theme/theme.js.map +1 -1
- package/pkg/package.json +1 -1
- package/src/resources/extensions/ask-user-questions.ts +7 -2
- package/src/resources/extensions/claude-code-cli/stream-adapter.ts +531 -226
- package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +672 -7
- package/src/resources/extensions/claude-code-cli/turn-assembler.ts +38 -1
- package/src/resources/extensions/gsd/auto/closeout.ts +309 -0
- package/src/resources/extensions/gsd/auto/dispatch-history.ts +22 -6
- package/src/resources/extensions/gsd/auto/dispatch.ts +449 -0
- package/src/resources/extensions/gsd/auto/finalize.ts +445 -0
- package/src/resources/extensions/gsd/auto/loop.ts +4 -1
- package/src/resources/extensions/gsd/auto/milestone-lease-reclaim.ts +74 -0
- package/src/resources/extensions/gsd/auto/orchestrator.ts +95 -15
- package/src/resources/extensions/gsd/auto/phase-helpers.ts +199 -0
- package/src/resources/extensions/gsd/auto/phases.ts +58 -3061
- package/src/resources/extensions/gsd/auto/pre-dispatch.ts +704 -0
- package/src/resources/extensions/gsd/auto/unit-phase.ts +910 -0
- package/src/resources/extensions/gsd/auto/workflow-unit-dispatch.ts +1 -1
- package/src/resources/extensions/gsd/auto/worktree-safety-phase.ts +149 -0
- package/src/resources/extensions/gsd/auto-worktree.ts +1 -1
- package/src/resources/extensions/gsd/auto.ts +20 -1
- package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +56 -6
- package/src/resources/extensions/gsd/commands-mcp-status.ts +2 -2
- package/src/resources/extensions/gsd/commands-workflow-templates.ts +11 -4
- package/src/resources/extensions/gsd/db/queries.ts +29 -0
- package/src/resources/extensions/gsd/doctor-environment.ts +267 -142
- package/src/resources/extensions/gsd/guided-flow.ts +128 -2
- package/src/resources/extensions/gsd/health-widget.ts +91 -27
- package/src/resources/extensions/gsd/mcp-bridge.ts +39 -0
- package/src/resources/extensions/gsd/milestone-settlement.ts +2 -2
- package/src/resources/extensions/gsd/notifications.ts +13 -6
- package/src/resources/extensions/gsd/prompts/complete-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/execute-task.md +2 -1
- package/src/resources/extensions/gsd/prompts/run-uat.md +2 -0
- package/src/resources/extensions/gsd/prompts/workflow-start.md +2 -1
- package/src/resources/extensions/gsd/skill-activation.ts +3 -6
- package/src/resources/extensions/gsd/state.ts +7 -1
- package/src/resources/extensions/gsd/tests/auto-abort-pause-regression.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/auto-blocked-remediation-message.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +206 -22
- package/src/resources/extensions/gsd/tests/auto-orchestrator.test.ts +76 -12
- package/src/resources/extensions/gsd/tests/auto-pause-double-entry-guard.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/auto-paused-ui-cleanup.test.ts +77 -1
- package/src/resources/extensions/gsd/tests/auto-phases-lifecycle.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/auto-unit-closeout.test.ts +169 -1
- package/src/resources/extensions/gsd/tests/complete-task.test.ts +141 -5
- package/src/resources/extensions/gsd/tests/deep-project-auto-loop.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/derive-state-helpers.test.ts +36 -0
- package/src/resources/extensions/gsd/tests/dispatch-history.test.ts +55 -0
- package/src/resources/extensions/gsd/tests/dist-redirect.mjs +8 -0
- package/src/resources/extensions/gsd/tests/engine-interfaces-contract.test.ts +117 -91
- package/src/resources/extensions/gsd/tests/ensure-db-open.test.ts +113 -0
- package/src/resources/extensions/gsd/tests/guided-dispatch-root.test.ts +16 -0
- package/src/resources/extensions/gsd/tests/integration/auto-worktree.test.ts +15 -0
- package/src/resources/extensions/gsd/tests/integration/doctor-environment-async.test.ts +104 -0
- package/src/resources/extensions/gsd/tests/integration/run-uat.test.ts +18 -0
- package/src/resources/extensions/gsd/tests/journal-integration.test.ts +47 -16
- package/src/resources/extensions/gsd/tests/mcp-readiness-preflight.test.ts +205 -0
- package/src/resources/extensions/gsd/tests/mcp-status.test.ts +6 -5
- package/src/resources/extensions/gsd/tests/milestone-merge-stash-restore.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/milestone-report-path.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/milestone-settlement.test.ts +92 -0
- package/src/resources/extensions/gsd/tests/milestone-transition-state-rebuild.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/notifications.test.ts +64 -9
- package/src/resources/extensions/gsd/tests/parallel-skill-prompt-integration.test.ts +2 -2
- package/src/resources/extensions/gsd/tests/parsers-legacy-importers.test.ts +5 -0
- package/src/resources/extensions/gsd/tests/phases-merge-error-stops-auto.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/phases-terminal-complete-idempotent.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/plan-gate-failed-doctor-heal-hint.test.ts +3 -3
- package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +10 -2
- package/src/resources/extensions/gsd/tests/provider-errors.test.ts +2 -4
- package/src/resources/extensions/gsd/tests/remote-notification-from-desktop.test.ts +31 -81
- package/src/resources/extensions/gsd/tests/runtime-invariant-modules.test.ts +7 -1
- package/src/resources/extensions/gsd/tests/skill-activation.test.ts +20 -17
- package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +7 -3
- package/src/resources/extensions/gsd/tests/stop-auto-race-null-unit.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/token-tool-gating.test.ts +4 -2
- package/src/resources/extensions/gsd/tests/tool-surface-readiness.test.ts +184 -10
- package/src/resources/extensions/gsd/tests/uok-plan-v2-wiring.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/workflow-mcp-readiness-cache.test.ts +119 -0
- package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +65 -2
- package/src/resources/extensions/gsd/tests/workflow-phase-contract-matrix.test.ts +332 -0
- package/src/resources/extensions/gsd/tests/workflow-templates.test.ts +92 -0
- package/src/resources/extensions/gsd/tests/worktree-health-dispatch.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-project-root-degrade.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-safety-phase.test.ts +100 -0
- package/src/resources/extensions/gsd/tests/worktree-safety.test.ts +72 -0
- package/src/resources/extensions/gsd/tool-surface-readiness.ts +126 -19
- package/src/resources/extensions/gsd/tools/complete-task.ts +87 -0
- package/src/resources/extensions/gsd/unit-context-composer.ts +1 -1
- package/src/resources/extensions/gsd/unit-registry.ts +34 -4
- package/src/resources/extensions/gsd/workflow-mcp-auto-prep.ts +2 -0
- package/src/resources/extensions/gsd/workflow-mcp-readiness-cache.ts +150 -0
- package/src/resources/extensions/gsd/worktree-safety.ts +41 -39
- package/src/resources/extensions/mcp-client/manager.ts +7 -1
- /package/dist/web/standalone/.next/static/{FBNo5cT_chy7YNoAQsU3o → xyMkEaICFHJoa98VgJyzY}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{FBNo5cT_chy7YNoAQsU3o → xyMkEaICFHJoa98VgJyzY}/_ssgManifest.js +0 -0
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
buildFinalAssistantContent,
|
|
33
33
|
extractToolResultsFromSdkUserMessage,
|
|
34
34
|
handleClaudeCodePartialStreamEvent,
|
|
35
|
+
shouldSuppressDuplicateToolUnavailableBlock,
|
|
35
36
|
} from "./turn-assembler.js";
|
|
36
37
|
import type {
|
|
37
38
|
ExternalToolResultPayload,
|
|
@@ -59,7 +60,20 @@ import {
|
|
|
59
60
|
computeMcpDisallowedTools,
|
|
60
61
|
} from "../gsd/mcp-filter.js";
|
|
61
62
|
import { RUN_UAT_CLAUDE_NATIVE_TOOL_NAMES, RUN_UAT_FORBIDDEN_TOOL_NAMES, RUN_UAT_WORKFLOW_TOOL_NAMES, resolveToolPresentationPlan } from "../gsd/tool-presentation-plan.js";
|
|
62
|
-
import {
|
|
63
|
+
import { getUnitToolSurfaceContract } from "../gsd/unit-tool-contracts.js";
|
|
64
|
+
import {
|
|
65
|
+
awaitWorkflowMcpToolRegistration,
|
|
66
|
+
getToolSurfaceReadinessError,
|
|
67
|
+
POST_PREFLIGHT_READINESS_RETRY_DELAYS_MS,
|
|
68
|
+
POST_PREFLIGHT_SDK_SETTLE_MS,
|
|
69
|
+
TOOL_SURFACE_NOT_READY,
|
|
70
|
+
type LiveToolSurfaceObservation,
|
|
71
|
+
} from "../gsd/tool-surface-readiness.js";
|
|
72
|
+
import {
|
|
73
|
+
beginWorkflowMcpSdkSession,
|
|
74
|
+
endWorkflowMcpSdkSession,
|
|
75
|
+
} from "../gsd/workflow-mcp-readiness-cache.js";
|
|
76
|
+
import { getGuidedUnitContext } from "../gsd/guided-unit-context.js";
|
|
63
77
|
import { hasBrowserContractPrefix } from "../shared/browser-contract.js";
|
|
64
78
|
import { showInterviewRound, type Question, type RoundResult } from "../shared/tui.js";
|
|
65
79
|
import type {
|
|
@@ -75,6 +89,7 @@ export {
|
|
|
75
89
|
extractToolResultsFromSdkUserMessage,
|
|
76
90
|
handleClaudeCodePartialStreamEvent,
|
|
77
91
|
mergePendingToolCalls,
|
|
92
|
+
shouldSuppressDuplicateToolUnavailableBlock,
|
|
78
93
|
} from "./turn-assembler.js";
|
|
79
94
|
export type {
|
|
80
95
|
ExternalToolResultContentBlock,
|
|
@@ -92,6 +107,11 @@ interface ClaudeCodeStreamOptions extends SimpleStreamOptions {
|
|
|
92
107
|
extensionUIContext?: ExtensionUIContext;
|
|
93
108
|
onExternalToolCall?: (toolCall: ToolCall) => Promise<void> | void;
|
|
94
109
|
onExternalToolResult?: (event: { toolCall: ToolCall; result: ExternalToolResultPayload }) => Promise<void> | void;
|
|
110
|
+
_sdkQueryForTest?: (args: {
|
|
111
|
+
prompt: string | AsyncIterable<unknown>;
|
|
112
|
+
options?: Record<string, unknown>;
|
|
113
|
+
}) => AsyncIterable<SDKMessage>;
|
|
114
|
+
_skipWorkflowMcpPreflightForTest?: boolean;
|
|
95
115
|
}
|
|
96
116
|
|
|
97
117
|
export function serverToolUseToToolCallLike(block: {
|
|
@@ -352,13 +372,18 @@ const GSD_PHASE_PATTERNS: Array<[string, RegExp]> = [
|
|
|
352
372
|
["reassess-roadmap", /\b(?:UNIT:\s*Reassess Roadmap|reassess-roadmap)\b/i],
|
|
353
373
|
["complete-slice", /\b(?:UNIT:\s*Complete Slice|complete-slice)\b/i],
|
|
354
374
|
["replan-slice", /\b(?:UNIT:\s*Replan Slice|replan-slice)\b/i],
|
|
375
|
+
["refine-slice", /\b(?:UNIT:\s*Refine Slice|refine-slice)\b/i],
|
|
355
376
|
["plan-slice", /\b(?:UNIT:\s*Plan Slice|plan-slice|gsd_plan_slice)\b/i],
|
|
356
377
|
["plan-milestone", /\b(?:UNIT:\s*Plan Milestone|plan-milestone|gsd_plan_milestone)\b/i],
|
|
357
378
|
["execute-task", /\b(?:UNIT:\s*Execute Task|execute-task|execute-task-simple|reactive-execute)\b/i],
|
|
358
379
|
["gate-evaluate", /\b(?:UNIT:\s*Gate Evaluate|gate-evaluate|gsd_save_gate_result)\b/i],
|
|
359
380
|
["research-milestone", /\b(?:UNIT:\s*Research Milestone|research-milestone)\b/i],
|
|
360
381
|
["research-slice", /\b(?:UNIT:\s*Research Slice|research-slice)\b/i],
|
|
382
|
+
["research-decision", /\b(?:research decision|research-decision)\b/i],
|
|
361
383
|
["discuss-milestone", /\b(?:Discuss milestone|discuss-milestone)\b/i],
|
|
384
|
+
["discuss-slice", /\b(?:Discuss slice|discuss-slice)\b/i],
|
|
385
|
+
["discuss-project", /\b(?:discuss-project|Discuss project)\b/i],
|
|
386
|
+
["discuss-requirements", /\b(?:discuss-requirements|Discuss requirements)\b/i],
|
|
362
387
|
];
|
|
363
388
|
|
|
364
389
|
export function inferGsdPhaseFromContext(context: Context): string | undefined {
|
|
@@ -372,6 +397,26 @@ export function inferGsdPhaseFromContext(context: Context): string | undefined {
|
|
|
372
397
|
return undefined;
|
|
373
398
|
}
|
|
374
399
|
|
|
400
|
+
/**
|
|
401
|
+
* Resolve the GSD unit phase for Claude Code SDK sessions. Guided-flow
|
|
402
|
+
* dispatch records the authoritative unit type before the turn is queued;
|
|
403
|
+
* prefer that over regex inference from prompt text.
|
|
404
|
+
*/
|
|
405
|
+
export function resolveGsdPhaseForSdk(context: Context, projectRoot: string): string | undefined {
|
|
406
|
+
const resolvedRoot = resolveWorkflowMcpProjectRoot(projectRoot);
|
|
407
|
+
const guided =
|
|
408
|
+
getGuidedUnitContext(resolvedRoot)
|
|
409
|
+
?? getGuidedUnitContext(projectRoot)
|
|
410
|
+
?? getGuidedUnitContext();
|
|
411
|
+
if (guided?.unitType) {
|
|
412
|
+
const guidedRoot = resolveWorkflowMcpProjectRoot(guided.basePath);
|
|
413
|
+
if (guidedRoot === resolvedRoot) {
|
|
414
|
+
return guided.unitType;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return inferGsdPhaseFromContext(context);
|
|
418
|
+
}
|
|
419
|
+
|
|
375
420
|
/**
|
|
376
421
|
* Build a full conversational prompt from GSD's context messages.
|
|
377
422
|
*
|
|
@@ -397,10 +442,15 @@ export function buildPromptFromContext(context: Context, toolContext: PromptTool
|
|
|
397
442
|
const workflowToolLine = toolContext.workflowMcpServerName
|
|
398
443
|
? "- GSD workflow tools (gsd_exec, gsd_slice_complete, gsd_task_complete, gsd_plan_slice, gsd_save_gate_result, etc.) " +
|
|
399
444
|
`are MCP tools — call them as mcp__${toolContext.workflowMcpServerName}__<tool_name> ` +
|
|
400
|
-
`(e.g. mcp__${toolContext.workflowMcpServerName}__gsd_exec, mcp__${toolContext.workflowMcpServerName}__gsd_save_gate_result)\n`
|
|
445
|
+
`(e.g. mcp__${toolContext.workflowMcpServerName}__gsd_exec, mcp__${toolContext.workflowMcpServerName}__gsd_save_gate_result)\n` +
|
|
446
|
+
`- Structured user input: call mcp__${toolContext.workflowMcpServerName}__ask_user_questions. ` +
|
|
447
|
+
"Do not call bare ask_user_questions. Do not call native AskUserQuestion.\n"
|
|
401
448
|
: "- GSD workflow MCP tools are unavailable in this Claude Code run.\n";
|
|
402
449
|
const toolSearchLine = toolContext.workflowMcpServerName
|
|
403
|
-
? "- ToolSearch is
|
|
450
|
+
? "- ToolSearch is available only for Claude Code deferred workflow MCP hydration. " +
|
|
451
|
+
`If mcp__${toolContext.workflowMcpServerName}__<tool_name> is missing or Claude Code reports the server is still connecting, ` +
|
|
452
|
+
`use ToolSearch with select:mcp__${toolContext.workflowMcpServerName}__<tool_name> or the base tool name, then call the returned MCP tool directly. ` +
|
|
453
|
+
"Do not use ToolSearch for browser_* tools or general discovery.\n"
|
|
404
454
|
: "- ToolSearch is NOT available — never use it to discover tools\n";
|
|
405
455
|
const browserToolLine = toolContext.browserMcpServerName
|
|
406
456
|
? "- Browser verification uses gsd-browser MCP by default — call browser tools as " +
|
|
@@ -511,9 +561,11 @@ export function buildSdkQueryPrompt(
|
|
|
511
561
|
parent_tool_use_id: null,
|
|
512
562
|
};
|
|
513
563
|
|
|
514
|
-
return
|
|
515
|
-
|
|
516
|
-
|
|
564
|
+
return {
|
|
565
|
+
async *[Symbol.asyncIterator]() {
|
|
566
|
+
yield sdkMessage;
|
|
567
|
+
},
|
|
568
|
+
};
|
|
517
569
|
}
|
|
518
570
|
|
|
519
571
|
// ---------------------------------------------------------------------------
|
|
@@ -535,6 +587,59 @@ function makeErrorMessage(model: string, errorMsg: string): AssistantMessage {
|
|
|
535
587
|
};
|
|
536
588
|
}
|
|
537
589
|
|
|
590
|
+
export interface WorkflowMcpReadinessProgressState {
|
|
591
|
+
contentIndex?: number;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
export function buildWorkflowMcpReadinessProgressMessage(input: {
|
|
595
|
+
unitType: string;
|
|
596
|
+
workflowServerName: string;
|
|
597
|
+
stage: "preflight" | "retry";
|
|
598
|
+
attempt?: number;
|
|
599
|
+
delayMs?: number;
|
|
600
|
+
}): string {
|
|
601
|
+
const { unitType, workflowServerName, stage } = input;
|
|
602
|
+
if (stage === "preflight") {
|
|
603
|
+
return `Starting ${workflowServerName} MCP for ${unitType}; waiting for workflow tools to register...`;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const attempt = input.attempt === undefined ? "" : ` attempt ${input.attempt}`;
|
|
607
|
+
const delay = input.delayMs === undefined ? "" : ` Retrying in ${formatReadinessDelay(input.delayMs)}.`;
|
|
608
|
+
return `Still waiting for ${workflowServerName} MCP tools for ${unitType}${attempt}.${delay}`;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function formatReadinessDelay(delayMs: number): string {
|
|
612
|
+
if (delayMs < 1_000) return `${delayMs}ms`;
|
|
613
|
+
const seconds = delayMs / 1_000;
|
|
614
|
+
return Number.isInteger(seconds) ? `${seconds}s` : `${seconds.toFixed(1)}s`;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
export function pushWorkflowMcpReadinessProgressEvent(input: {
|
|
618
|
+
stream: Pick<AssistantMessageEventStream, "push">;
|
|
619
|
+
partial: AssistantMessage;
|
|
620
|
+
state: WorkflowMcpReadinessProgressState;
|
|
621
|
+
message: string;
|
|
622
|
+
}): void {
|
|
623
|
+
const { stream, partial, state, message } = input;
|
|
624
|
+
if (!message) return;
|
|
625
|
+
|
|
626
|
+
let contentIndex = state.contentIndex;
|
|
627
|
+
const existing = contentIndex === undefined ? undefined : partial.content[contentIndex];
|
|
628
|
+
if (contentIndex === undefined || existing?.type !== "text") {
|
|
629
|
+
contentIndex = partial.content.length;
|
|
630
|
+
state.contentIndex = contentIndex;
|
|
631
|
+
partial.content.push({ type: "text", text: "" });
|
|
632
|
+
stream.push({ type: "text_start", contentIndex, partial });
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
const block = partial.content[contentIndex];
|
|
636
|
+
if (block.type !== "text") return;
|
|
637
|
+
|
|
638
|
+
const delta = block.text.length === 0 ? message : `\n${message}`;
|
|
639
|
+
block.text += delta;
|
|
640
|
+
stream.push({ type: "text_delta", contentIndex, delta, partial });
|
|
641
|
+
}
|
|
642
|
+
|
|
538
643
|
export function isClaudeCodeAbortErrorMessage(message: string | undefined | null): boolean {
|
|
539
644
|
if (!message) return false;
|
|
540
645
|
return /\b(?:claude code process aborted by user|request aborted by user|process aborted by user|aborterror)\b/i.test(message);
|
|
@@ -1663,11 +1768,15 @@ function resolveExactWorkflowMcpToolsForPhase(
|
|
|
1663
1768
|
workflowExplicitlyBlocked: boolean,
|
|
1664
1769
|
): string[] {
|
|
1665
1770
|
if (!gsdPhase || !workflowServerName || workflowExplicitlyBlocked) return [];
|
|
1666
|
-
const
|
|
1771
|
+
const requestedTools = gsdPhase === "run-uat"
|
|
1667
1772
|
? [...RUN_UAT_WORKFLOW_TOOL_NAMES]
|
|
1668
|
-
:
|
|
1669
|
-
|
|
1670
|
-
|
|
1773
|
+
: [
|
|
1774
|
+
...(getUnitToolSurfaceContract(gsdPhase)?.allowedGsdTools ?? []),
|
|
1775
|
+
...getRequiredWorkflowToolsForAutoUnit(gsdPhase),
|
|
1776
|
+
];
|
|
1777
|
+
const requestedToolNames = [...new Set(
|
|
1778
|
+
requestedTools.filter((toolName) => toolName.startsWith("gsd_") || toolName === "ask_user_questions"),
|
|
1779
|
+
)];
|
|
1671
1780
|
if (requestedToolNames.length === 0) return [];
|
|
1672
1781
|
return resolveToolPresentationPlan({
|
|
1673
1782
|
phase: gsdPhase,
|
|
@@ -1677,6 +1786,25 @@ function resolveExactWorkflowMcpToolsForPhase(
|
|
|
1677
1786
|
}).presentedToolNames;
|
|
1678
1787
|
}
|
|
1679
1788
|
|
|
1789
|
+
function resolveClaudeNativeToolsForPhase(gsdPhase: string | undefined): string[] {
|
|
1790
|
+
const standardClaudeTools = [
|
|
1791
|
+
"Read",
|
|
1792
|
+
"Write",
|
|
1793
|
+
"Edit",
|
|
1794
|
+
"Glob",
|
|
1795
|
+
"Grep",
|
|
1796
|
+
"Bash",
|
|
1797
|
+
"Agent",
|
|
1798
|
+
"WebFetch",
|
|
1799
|
+
"WebSearch",
|
|
1800
|
+
];
|
|
1801
|
+
if (!gsdPhase) return standardClaudeTools;
|
|
1802
|
+
if (gsdPhase === "run-uat" || gsdPhase === "complete-slice") {
|
|
1803
|
+
return [...RUN_UAT_CLAUDE_NATIVE_TOOL_NAMES];
|
|
1804
|
+
}
|
|
1805
|
+
return standardClaudeTools;
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1680
1808
|
export function autoInitClaudeCodeWorkflowMcp(cwd: string): void {
|
|
1681
1809
|
const projectRoot = resolveWorkflowMcpProjectRoot(cwd);
|
|
1682
1810
|
try {
|
|
@@ -1690,6 +1818,70 @@ export function autoInitClaudeCodeWorkflowMcp(cwd: string): void {
|
|
|
1690
1818
|
}
|
|
1691
1819
|
}
|
|
1692
1820
|
|
|
1821
|
+
export function resolveClaudeCodeToolSurfaceReadinessError(input: {
|
|
1822
|
+
unitType: string | undefined;
|
|
1823
|
+
workflowServerName: string | undefined;
|
|
1824
|
+
observation: LiveToolSurfaceObservation;
|
|
1825
|
+
projectRoot?: string | undefined;
|
|
1826
|
+
allowPendingToolSearchHydration?: boolean | undefined;
|
|
1827
|
+
}): Promise<string | null> {
|
|
1828
|
+
const error = getToolSurfaceReadinessError(input);
|
|
1829
|
+
if (
|
|
1830
|
+
error
|
|
1831
|
+
&& input.allowPendingToolSearchHydration
|
|
1832
|
+
&& input.workflowServerName
|
|
1833
|
+
&& input.observation.mcpServers.some(
|
|
1834
|
+
(server) => server.name === input.workflowServerName && server.status === "pending",
|
|
1835
|
+
)
|
|
1836
|
+
) {
|
|
1837
|
+
return Promise.resolve(null);
|
|
1838
|
+
}
|
|
1839
|
+
return Promise.resolve(error);
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
export { awaitWorkflowMcpToolRegistration } from "../gsd/tool-surface-readiness.js";
|
|
1843
|
+
|
|
1844
|
+
const TOOL_SURFACE_READINESS_RETRY_DELAYS_MS = [500, 1_000, 2_000, 4_000, 8_000, 15_000, 15_000, 15_000] as const;
|
|
1845
|
+
|
|
1846
|
+
export function shouldRetryClaudeCodeToolSurfaceReadiness(error: string | null): boolean {
|
|
1847
|
+
if (!error) return false;
|
|
1848
|
+
return error.includes(TOOL_SURFACE_NOT_READY) && !/\bterminal\b/i.test(error);
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
export function resolveClaudeCodeToolSurfaceReadinessRetryDelayMs(
|
|
1852
|
+
error: string | null,
|
|
1853
|
+
attempt: number,
|
|
1854
|
+
preflightVerified = false,
|
|
1855
|
+
): number | null {
|
|
1856
|
+
if (!shouldRetryClaudeCodeToolSurfaceReadiness(error)) return null;
|
|
1857
|
+
const delays = preflightVerified
|
|
1858
|
+
? POST_PREFLIGHT_READINESS_RETRY_DELAYS_MS
|
|
1859
|
+
: TOOL_SURFACE_READINESS_RETRY_DELAYS_MS;
|
|
1860
|
+
return delays[attempt] ?? null;
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
function makeAbortError(): Error {
|
|
1864
|
+
const error = new Error("AbortError: The operation was aborted");
|
|
1865
|
+
error.name = "AbortError";
|
|
1866
|
+
return error;
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
function delay(ms: number, signal?: AbortSignal): Promise<void> {
|
|
1870
|
+
if (signal?.aborted) return Promise.reject(makeAbortError());
|
|
1871
|
+
|
|
1872
|
+
return new Promise((resolve, reject) => {
|
|
1873
|
+
const timeout = setTimeout(() => {
|
|
1874
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1875
|
+
resolve();
|
|
1876
|
+
}, ms);
|
|
1877
|
+
const onAbort = (): void => {
|
|
1878
|
+
clearTimeout(timeout);
|
|
1879
|
+
reject(makeAbortError());
|
|
1880
|
+
};
|
|
1881
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1693
1885
|
/**
|
|
1694
1886
|
* Build the options object passed to the Claude Agent SDK's `query()` call.
|
|
1695
1887
|
*
|
|
@@ -1840,34 +2032,27 @@ export function buildSdkOptions(
|
|
|
1840
2032
|
`mcp__${workflowServerName}__gsd_save_gate_result`,
|
|
1841
2033
|
]
|
|
1842
2034
|
: [];
|
|
2035
|
+
const allowToolSearchForWorkflowMcp = workflowMcpTools.length > 0 || exactWorkflowMcpTools.length > 0;
|
|
1843
2036
|
const disallowedTools: string[] = [...new Set([
|
|
1844
|
-
"ToolSearch",
|
|
2037
|
+
...(allowToolSearchForWorkflowMcp ? [] : ["ToolSearch"]),
|
|
2038
|
+
...(gsdPhase ? ["Skill"] : []),
|
|
1845
2039
|
...(workflowMcpTools.length > 0 || exactWorkflowMcpTools.length > 0 ? ["AskUserQuestion"] : []),
|
|
1846
2040
|
...questionToolSurface.disallowedTools,
|
|
1847
2041
|
...runUatDisallowedTools,
|
|
1848
2042
|
...extraDisallowedTools,
|
|
1849
2043
|
])];
|
|
1850
|
-
const
|
|
1851
|
-
"Read",
|
|
1852
|
-
"Write",
|
|
1853
|
-
"Edit",
|
|
1854
|
-
"Glob",
|
|
1855
|
-
"Grep",
|
|
1856
|
-
"Bash",
|
|
1857
|
-
"Agent",
|
|
1858
|
-
"WebFetch",
|
|
1859
|
-
"WebSearch",
|
|
1860
|
-
];
|
|
2044
|
+
const nativeTools = resolveClaudeNativeToolsForPhase(gsdPhase);
|
|
1861
2045
|
const allowedTools = gsdPhase === "run-uat"
|
|
1862
2046
|
? [
|
|
1863
|
-
...
|
|
2047
|
+
...nativeTools,
|
|
1864
2048
|
...(exactWorkflowMcpTools.length > 0 ? exactWorkflowMcpTools : []),
|
|
1865
2049
|
...allowedBrowserMcpTools,
|
|
1866
2050
|
]
|
|
1867
2051
|
: [
|
|
1868
|
-
...
|
|
2052
|
+
...nativeTools,
|
|
1869
2053
|
...exactWorkflowMcpTools,
|
|
1870
|
-
...(workflowMcpTools.length > 0 ? workflowMcpTools : [
|
|
2054
|
+
...(!gsdPhase && workflowMcpTools.length > 0 ? workflowMcpTools : []),
|
|
2055
|
+
...(workflowMcpTools.length === 0 && exactWorkflowMcpTools.length === 0 ? ["AskUserQuestion"] : []),
|
|
1871
2056
|
...allowedBrowserMcpTools,
|
|
1872
2057
|
];
|
|
1873
2058
|
const supportsAdaptive = modelSupportsAdaptiveThinking(modelId);
|
|
@@ -1938,6 +2123,20 @@ export function streamViaClaudeCode(
|
|
|
1938
2123
|
return stream;
|
|
1939
2124
|
}
|
|
1940
2125
|
|
|
2126
|
+
interface SdkAttemptMessageState {
|
|
2127
|
+
builder: PartialMessageBuilder | null;
|
|
2128
|
+
intermediateToolBlocks: AssistantMessage["content"];
|
|
2129
|
+
toolResultsById: Map<string, ExternalToolResultPayload>;
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
function createSdkAttemptMessageState(): SdkAttemptMessageState {
|
|
2133
|
+
return {
|
|
2134
|
+
builder: null,
|
|
2135
|
+
intermediateToolBlocks: [],
|
|
2136
|
+
toolResultsById: new Map<string, ExternalToolResultPayload>(),
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
|
|
1941
2140
|
/** Async pump that drives the Claude Agent SDK's async-iterable message stream and pushes events into `stream`. */
|
|
1942
2141
|
async function pumpSdkMessages(
|
|
1943
2142
|
model: Model<any>,
|
|
@@ -1946,38 +2145,30 @@ async function pumpSdkMessages(
|
|
|
1946
2145
|
stream: AssistantMessageEventStream,
|
|
1947
2146
|
): Promise<void> {
|
|
1948
2147
|
const modelId = model.id;
|
|
1949
|
-
let builder: PartialMessageBuilder | null = null;
|
|
1950
2148
|
/** Track the last text content seen across all assistant turns for the final message. */
|
|
1951
2149
|
let lastTextContent = "";
|
|
1952
2150
|
let lastThinkingContent = "";
|
|
1953
|
-
/** Collect tool blocks from intermediate SDK turns for tool execution rendering. */
|
|
1954
|
-
const intermediateToolBlocks: AssistantMessage["content"] = [];
|
|
1955
|
-
/** Preserve real external tool results from Claude Code's synthetic user messages. */
|
|
1956
|
-
const toolResultsById = new Map<string, ExternalToolResultPayload>();
|
|
1957
2151
|
|
|
1958
2152
|
try {
|
|
1959
|
-
// Dynamic import — the SDK is an optional dependency.
|
|
1960
|
-
const sdkModule = "@anthropic-ai/claude-agent-sdk";
|
|
1961
|
-
const sdk = (await import(/* webpackIgnore: true */ sdkModule)) as {
|
|
1962
|
-
query: (args: {
|
|
1963
|
-
prompt: string | AsyncIterable<unknown>;
|
|
1964
|
-
options?: Record<string, unknown>;
|
|
1965
|
-
}) => AsyncIterable<SDKMessage>;
|
|
1966
|
-
};
|
|
1967
|
-
|
|
1968
|
-
// Bridge GSD's AbortSignal to SDK's AbortController
|
|
1969
|
-
const controller = new AbortController();
|
|
1970
|
-
if (options?.signal) {
|
|
1971
|
-
options.signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
1972
|
-
}
|
|
1973
|
-
|
|
1974
2153
|
const permissionMode = await resolveClaudePermissionMode();
|
|
1975
|
-
const
|
|
1976
|
-
const
|
|
1977
|
-
const
|
|
2154
|
+
const claudeOptions = options as ClaudeCodeStreamOptions | undefined;
|
|
2155
|
+
const uiContext = claudeOptions?.extensionUIContext;
|
|
2156
|
+
const onExternalToolCall = claudeOptions?.onExternalToolCall;
|
|
2157
|
+
const onExternalToolResult = claudeOptions?.onExternalToolResult;
|
|
2158
|
+
const sdkQueryForTest = claudeOptions?._sdkQueryForTest;
|
|
2159
|
+
const query = sdkQueryForTest ?? (
|
|
2160
|
+
// Dynamic import — the SDK is an optional dependency.
|
|
2161
|
+
(await import(/* webpackIgnore: true */ "@anthropic-ai/claude-agent-sdk")) as {
|
|
2162
|
+
query: (args: {
|
|
2163
|
+
prompt: string | AsyncIterable<unknown>;
|
|
2164
|
+
options?: Record<string, unknown>;
|
|
2165
|
+
}) => AsyncIterable<SDKMessage>;
|
|
2166
|
+
}
|
|
2167
|
+
).query;
|
|
1978
2168
|
const cwd = resolveClaudeCodeCwd(options);
|
|
2169
|
+
const projectRoot = resolveWorkflowMcpProjectRoot(cwd);
|
|
1979
2170
|
autoInitClaudeCodeWorkflowMcp(cwd);
|
|
1980
|
-
const gsdPhase =
|
|
2171
|
+
const gsdPhase = resolveGsdPhaseForSdk(context, projectRoot);
|
|
1981
2172
|
const canUseToolHandler = createClaudeCodeCanUseToolHandler(uiContext);
|
|
1982
2173
|
// When no UI is available (headless / auto-mode), auto-approve all
|
|
1983
2174
|
// tool requests. This replaces the old bypassPermissions workaround.
|
|
@@ -2001,20 +2192,15 @@ async function pumpSdkMessages(
|
|
|
2001
2192
|
},
|
|
2002
2193
|
);
|
|
2003
2194
|
const workflowMcpServerName = workflowMcpServerNameFromAllowedTools(sdkOpts.allowedTools);
|
|
2195
|
+
const allowPendingToolSearchHydration =
|
|
2196
|
+
Boolean(workflowMcpServerName && gsdPhase)
|
|
2197
|
+
&& !(sdkOpts.disallowedTools as string[] | undefined)?.includes("ToolSearch");
|
|
2004
2198
|
const prompt = buildPromptFromContext(context, {
|
|
2005
2199
|
workflowMcpServerName,
|
|
2006
2200
|
browserMcpServerName: browserMcpServerNameFromAllowedTools(sdkOpts.allowedTools),
|
|
2007
2201
|
});
|
|
2008
2202
|
const queryPrompt = buildSdkQueryPrompt(context, prompt);
|
|
2009
2203
|
|
|
2010
|
-
const queryResult = sdk.query({
|
|
2011
|
-
prompt: queryPrompt,
|
|
2012
|
-
options: {
|
|
2013
|
-
...sdkOpts,
|
|
2014
|
-
abortController: controller,
|
|
2015
|
-
},
|
|
2016
|
-
});
|
|
2017
|
-
|
|
2018
2204
|
// Emit start with an empty partial
|
|
2019
2205
|
const initialPartial: AssistantMessage = {
|
|
2020
2206
|
role: "assistant",
|
|
@@ -2027,201 +2213,320 @@ async function pumpSdkMessages(
|
|
|
2027
2213
|
timestamp: Date.now(),
|
|
2028
2214
|
};
|
|
2029
2215
|
stream.push({ type: "start", partial: initialPartial });
|
|
2216
|
+
const readinessProgressState: WorkflowMcpReadinessProgressState = {};
|
|
2030
2217
|
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2218
|
+
const trackWorkflowMcpSdk = Boolean(workflowMcpServerName && gsdPhase);
|
|
2219
|
+
if (trackWorkflowMcpSdk) beginWorkflowMcpSdkSession();
|
|
2220
|
+
try {
|
|
2221
|
+
let workflowMcpPreflightVerified = false;
|
|
2222
|
+
const shouldRunWorkflowMcpPreflight =
|
|
2223
|
+
workflowMcpServerName && gsdPhase && !claudeOptions?._skipWorkflowMcpPreflightForTest;
|
|
2224
|
+
if (shouldRunWorkflowMcpPreflight) {
|
|
2225
|
+
try {
|
|
2226
|
+
const progressMessage = buildWorkflowMcpReadinessProgressMessage({
|
|
2227
|
+
unitType: gsdPhase,
|
|
2228
|
+
workflowServerName: workflowMcpServerName,
|
|
2229
|
+
stage: "preflight",
|
|
2230
|
+
});
|
|
2231
|
+
pushWorkflowMcpReadinessProgressEvent({
|
|
2232
|
+
stream,
|
|
2233
|
+
partial: initialPartial,
|
|
2234
|
+
state: readinessProgressState,
|
|
2235
|
+
message: progressMessage,
|
|
2236
|
+
});
|
|
2237
|
+
uiContext?.setStatus?.("gsd-step", progressMessage);
|
|
2238
|
+
const preflightError = await awaitWorkflowMcpToolRegistration({
|
|
2239
|
+
unitType: gsdPhase,
|
|
2240
|
+
workflowServerName: workflowMcpServerName,
|
|
2241
|
+
projectRoot,
|
|
2242
|
+
signal: options?.signal,
|
|
2243
|
+
});
|
|
2244
|
+
if (preflightError) {
|
|
2245
|
+
stream.push({
|
|
2246
|
+
type: "error",
|
|
2247
|
+
reason: "error",
|
|
2248
|
+
error: makeErrorMessage(modelId, preflightError),
|
|
2249
|
+
});
|
|
2250
|
+
return;
|
|
2251
|
+
}
|
|
2252
|
+
workflowMcpPreflightVerified = true;
|
|
2253
|
+
} finally {
|
|
2254
|
+
uiContext?.setStatus?.("gsd-step", "");
|
|
2255
|
+
}
|
|
2256
|
+
if (workflowMcpPreflightVerified) {
|
|
2257
|
+
await delay(POST_PREFLIGHT_SDK_SETTLE_MS, options?.signal);
|
|
2258
|
+
}
|
|
2042
2259
|
}
|
|
2043
2260
|
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
}
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2261
|
+
sdkAttemptLoop:
|
|
2262
|
+
for (let readinessAttempt = 0; ; readinessAttempt++) {
|
|
2263
|
+
let { builder, intermediateToolBlocks, toolResultsById } = createSdkAttemptMessageState();
|
|
2264
|
+
const controller = new AbortController();
|
|
2265
|
+
const forwardAbort = (): void => controller.abort();
|
|
2266
|
+
if (options?.signal) {
|
|
2267
|
+
options.signal.addEventListener("abort", forwardAbort, { once: true });
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
const queryResult = query({
|
|
2271
|
+
prompt: queryPrompt,
|
|
2272
|
+
options: {
|
|
2273
|
+
...sdkOpts,
|
|
2274
|
+
abortController: controller,
|
|
2275
|
+
},
|
|
2276
|
+
});
|
|
2277
|
+
|
|
2278
|
+
try {
|
|
2279
|
+
for await (const msg of queryResult as AsyncIterable<SDKMessage>) {
|
|
2280
|
+
if (options?.signal?.aborted) {
|
|
2281
|
+
// User-initiated cancel — emit an aborted error so the agent
|
|
2282
|
+
// loop classifies this as a deliberate stop, not a transient
|
|
2283
|
+
// provider failure that should be retried.
|
|
2284
|
+
stream.push({
|
|
2285
|
+
type: "error",
|
|
2286
|
+
reason: "aborted",
|
|
2287
|
+
error: makeAbortedMessage(modelId, lastTextContent),
|
|
2064
2288
|
});
|
|
2065
|
-
|
|
2066
|
-
controller.abort();
|
|
2067
|
-
stream.push({
|
|
2068
|
-
type: "error",
|
|
2069
|
-
reason: "error",
|
|
2070
|
-
error: makeErrorMessage(modelId, readinessError),
|
|
2071
|
-
});
|
|
2072
|
-
return;
|
|
2073
|
-
}
|
|
2289
|
+
return;
|
|
2074
2290
|
}
|
|
2075
|
-
break;
|
|
2076
|
-
}
|
|
2077
2291
|
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2292
|
+
switch (msg.type) {
|
|
2293
|
+
// -- Init --
|
|
2294
|
+
case "system": {
|
|
2295
|
+
// Tool Surface Readiness gate: the init message is the first (and
|
|
2296
|
+
// only) point where the session reports its live tool surface and
|
|
2297
|
+
// MCP server statuses. If the workflow server failed or has not
|
|
2298
|
+
// registered this Unit's required tools, abort before the first
|
|
2299
|
+
// model turn with a transient, recovery-classifiable error
|
|
2300
|
+
// (tool-unavailable → retry) instead of letting the model hit
|
|
2301
|
+
// "No such tool available" mid-Unit and improvise around it.
|
|
2302
|
+
const init = msg as unknown as {
|
|
2303
|
+
subtype?: string;
|
|
2304
|
+
tools?: string[];
|
|
2305
|
+
mcp_servers?: { name: string; status: string }[];
|
|
2306
|
+
};
|
|
2307
|
+
if (init.subtype === "init") {
|
|
2308
|
+
const readinessError = await resolveClaudeCodeToolSurfaceReadinessError({
|
|
2309
|
+
unitType: gsdPhase,
|
|
2310
|
+
workflowServerName: workflowMcpServerName,
|
|
2311
|
+
projectRoot,
|
|
2312
|
+
observation: { tools: init.tools ?? [], mcpServers: init.mcp_servers ?? [] },
|
|
2313
|
+
allowPendingToolSearchHydration,
|
|
2314
|
+
});
|
|
2315
|
+
if (readinessError) {
|
|
2316
|
+
const retryDelayMs = resolveClaudeCodeToolSurfaceReadinessRetryDelayMs(
|
|
2317
|
+
readinessError,
|
|
2318
|
+
readinessAttempt,
|
|
2319
|
+
workflowMcpPreflightVerified,
|
|
2320
|
+
);
|
|
2321
|
+
if (retryDelayMs !== null && !options?.signal?.aborted) {
|
|
2322
|
+
controller.abort();
|
|
2323
|
+
const progressMessage = buildWorkflowMcpReadinessProgressMessage({
|
|
2324
|
+
unitType: gsdPhase ?? "workflow unit",
|
|
2325
|
+
workflowServerName: workflowMcpServerName ?? "workflow",
|
|
2326
|
+
stage: "retry",
|
|
2327
|
+
attempt: readinessAttempt + 1,
|
|
2328
|
+
delayMs: retryDelayMs,
|
|
2329
|
+
});
|
|
2330
|
+
pushWorkflowMcpReadinessProgressEvent({
|
|
2331
|
+
stream,
|
|
2332
|
+
partial: initialPartial,
|
|
2333
|
+
state: readinessProgressState,
|
|
2334
|
+
message: progressMessage,
|
|
2335
|
+
});
|
|
2336
|
+
uiContext?.setStatus?.("gsd-step", progressMessage);
|
|
2337
|
+
await delay(retryDelayMs, options?.signal);
|
|
2338
|
+
uiContext?.setStatus?.("gsd-step", "");
|
|
2339
|
+
continue sdkAttemptLoop;
|
|
2340
|
+
}
|
|
2341
|
+
controller.abort();
|
|
2342
|
+
stream.push({
|
|
2343
|
+
type: "error",
|
|
2344
|
+
reason: "error",
|
|
2345
|
+
error: makeErrorMessage(modelId, readinessError),
|
|
2346
|
+
});
|
|
2347
|
+
return;
|
|
2096
2348
|
}
|
|
2097
2349
|
}
|
|
2350
|
+
break;
|
|
2098
2351
|
}
|
|
2099
|
-
}
|
|
2100
|
-
break;
|
|
2101
|
-
}
|
|
2102
2352
|
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2353
|
+
// -- Streaming partial messages --
|
|
2354
|
+
case "stream_event": {
|
|
2355
|
+
const partial = msg as SDKPartialAssistantMessage;
|
|
2356
|
+
|
|
2357
|
+
const event = partial.event;
|
|
2358
|
+
|
|
2359
|
+
const result = handleClaudeCodePartialStreamEvent(builder, event, modelId);
|
|
2360
|
+
builder = result.builder;
|
|
2361
|
+
const assistantEvent = result.assistantEvent;
|
|
2362
|
+
if (assistantEvent) {
|
|
2363
|
+
stream.push(assistantEvent);
|
|
2364
|
+
if (assistantEvent.type === "toolcall_start") {
|
|
2365
|
+
const toolBlock = assistantEvent.partial.content[assistantEvent.contentIndex];
|
|
2366
|
+
if (toolBlock?.type === "toolCall") {
|
|
2367
|
+
try {
|
|
2368
|
+
await onExternalToolCall?.(toolBlock);
|
|
2369
|
+
} catch (error) {
|
|
2370
|
+
console.warn("[claude-code] onExternalToolCall callback failed:", error);
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
break;
|
|
2113
2376
|
}
|
|
2114
|
-
}
|
|
2115
|
-
break;
|
|
2116
|
-
}
|
|
2117
2377
|
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
intermediateToolBlocks.push(block);
|
|
2378
|
+
// -- Complete assistant message (non-streaming fallback) --
|
|
2379
|
+
case "assistant": {
|
|
2380
|
+
const sdkAssistant = msg as SDKAssistantMessage;
|
|
2381
|
+
|
|
2382
|
+
// Capture text content from complete messages
|
|
2383
|
+
for (const block of sdkAssistant.message.content) {
|
|
2384
|
+
if (block.type === "text") {
|
|
2385
|
+
lastTextContent = block.text;
|
|
2386
|
+
} else if (block.type === "thinking") {
|
|
2387
|
+
lastThinkingContent = block.thinking;
|
|
2388
|
+
}
|
|
2130
2389
|
}
|
|
2390
|
+
break;
|
|
2131
2391
|
}
|
|
2132
|
-
}
|
|
2133
2392
|
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
if (!extResult) continue;
|
|
2148
|
-
const contentIndex = builder.message.content.indexOf(block);
|
|
2149
|
-
if (contentIndex < 0) continue;
|
|
2150
|
-
// Push synthetic completion events with result attached so the
|
|
2151
|
-
// chat-controller can update pending ToolExecutionComponents.
|
|
2152
|
-
if (block.type === "toolCall") {
|
|
2153
|
-
try {
|
|
2154
|
-
await onExternalToolResult?.({
|
|
2155
|
-
toolCall: block,
|
|
2156
|
-
result: extResult,
|
|
2157
|
-
});
|
|
2158
|
-
} catch (error) {
|
|
2159
|
-
console.warn("[claude-code] onExternalToolResult callback failed:", error);
|
|
2393
|
+
// -- User message (synthetic tool result — signals turn boundary) --
|
|
2394
|
+
case "user": {
|
|
2395
|
+
// Capture content from the completed turn before resetting
|
|
2396
|
+
if (builder) {
|
|
2397
|
+
for (const block of builder.message.content) {
|
|
2398
|
+
if (block.type === "text" && block.text) {
|
|
2399
|
+
lastTextContent = block.text;
|
|
2400
|
+
} else if (block.type === "thinking" && block.thinking) {
|
|
2401
|
+
lastThinkingContent = block.thinking;
|
|
2402
|
+
} else if (block.type === "toolCall" || block.type === "serverToolUse") {
|
|
2403
|
+
// Collect tool blocks for externalToolExecution rendering
|
|
2404
|
+
intermediateToolBlocks.push(block);
|
|
2405
|
+
}
|
|
2160
2406
|
}
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
}
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
// Extract tool results from the SDK's synthetic user message
|
|
2410
|
+
// and attach to corresponding tool call blocks immediately.
|
|
2411
|
+
for (const { toolUseId, result } of extractToolResultsFromSdkUserMessage(msg as SDKUserMessage)) {
|
|
2412
|
+
toolResultsById.set(toolUseId, result);
|
|
2413
|
+
}
|
|
2414
|
+
attachExternalResultsToToolBlocks(intermediateToolBlocks, toolResultsById);
|
|
2415
|
+
|
|
2416
|
+
// Push a synthetic toolcall_end for each tool call from this turn
|
|
2417
|
+
// so the TUI can render tool results in real-time during the SDK
|
|
2418
|
+
// session instead of waiting until the entire session completes.
|
|
2419
|
+
if (builder) {
|
|
2420
|
+
for (const block of builder.message.content) {
|
|
2421
|
+
const extResult = (block as ToolCallWithExternalResult).externalResult;
|
|
2422
|
+
if (!extResult) continue;
|
|
2423
|
+
const contentIndex = builder.message.content.indexOf(block);
|
|
2424
|
+
if (contentIndex < 0) continue;
|
|
2425
|
+
const suppressDuplicateUnavailable = shouldSuppressDuplicateToolUnavailableBlock(
|
|
2426
|
+
block,
|
|
2427
|
+
builder.message.content,
|
|
2428
|
+
);
|
|
2429
|
+
// Push synthetic completion events with result attached so the
|
|
2430
|
+
// chat-controller can update pending ToolExecutionComponents.
|
|
2431
|
+
if (block.type === "toolCall") {
|
|
2432
|
+
if (suppressDuplicateUnavailable) {
|
|
2433
|
+
delete (block as ToolCallWithExternalResult).externalResult;
|
|
2434
|
+
stream.push({
|
|
2435
|
+
type: "toolcall_end",
|
|
2436
|
+
contentIndex,
|
|
2437
|
+
toolCall: block,
|
|
2438
|
+
partial: builder.message,
|
|
2439
|
+
});
|
|
2440
|
+
(block as ToolCallWithExternalResult).externalResult = extResult;
|
|
2441
|
+
continue;
|
|
2442
|
+
}
|
|
2443
|
+
try {
|
|
2444
|
+
await onExternalToolResult?.({
|
|
2445
|
+
toolCall: block,
|
|
2446
|
+
result: extResult,
|
|
2447
|
+
});
|
|
2448
|
+
} catch (error) {
|
|
2449
|
+
console.warn("[claude-code] onExternalToolResult callback failed:", error);
|
|
2450
|
+
}
|
|
2451
|
+
stream.push({
|
|
2452
|
+
type: "toolcall_end",
|
|
2453
|
+
contentIndex,
|
|
2454
|
+
toolCall: block,
|
|
2455
|
+
partial: builder.message,
|
|
2456
|
+
});
|
|
2457
|
+
} else if (block.type === "serverToolUse") {
|
|
2458
|
+
try {
|
|
2459
|
+
await onExternalToolResult?.({
|
|
2460
|
+
toolCall: serverToolUseToToolCallLike(block),
|
|
2461
|
+
result: extResult,
|
|
2462
|
+
});
|
|
2463
|
+
} catch (error) {
|
|
2464
|
+
console.warn("[claude-code] onExternalToolResult callback failed:", error);
|
|
2465
|
+
}
|
|
2466
|
+
stream.push({
|
|
2467
|
+
type: "server_tool_use",
|
|
2468
|
+
contentIndex,
|
|
2469
|
+
partial: builder.message,
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2175
2472
|
}
|
|
2176
|
-
stream.push({
|
|
2177
|
-
type: "server_tool_use",
|
|
2178
|
-
contentIndex,
|
|
2179
|
-
partial: builder.message,
|
|
2180
|
-
});
|
|
2181
2473
|
}
|
|
2474
|
+
|
|
2475
|
+
builder = null;
|
|
2476
|
+
break;
|
|
2182
2477
|
}
|
|
2183
|
-
}
|
|
2184
2478
|
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2479
|
+
// -- Result (terminal) --
|
|
2480
|
+
case "result": {
|
|
2481
|
+
const result = msg as SDKResultMessage;
|
|
2482
|
+
const finalContent = buildFinalAssistantContent({
|
|
2483
|
+
intermediateToolBlocks,
|
|
2484
|
+
pendingContent: builder?.message.content,
|
|
2485
|
+
toolResultsById,
|
|
2486
|
+
lastThinkingContent,
|
|
2487
|
+
lastTextContent,
|
|
2488
|
+
fallbackResultText:
|
|
2489
|
+
result.subtype === "success" && result.result ? result.result : undefined,
|
|
2490
|
+
});
|
|
2188
2491
|
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
result.subtype === "success" && result.result ? result.result : undefined,
|
|
2200
|
-
});
|
|
2492
|
+
const finalMessage: AssistantMessage = {
|
|
2493
|
+
role: "assistant",
|
|
2494
|
+
content: finalContent,
|
|
2495
|
+
api: "anthropic-messages",
|
|
2496
|
+
provider: "claude-code",
|
|
2497
|
+
model: modelId,
|
|
2498
|
+
usage: mapUsage(result.usage, result.total_cost_usd),
|
|
2499
|
+
stopReason: result.is_error ? "error" : "stop",
|
|
2500
|
+
timestamp: Date.now(),
|
|
2501
|
+
};
|
|
2201
2502
|
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
if (result.is_error) {
|
|
2214
|
-
finalMessage.errorMessage = getResultErrorMessage(result);
|
|
2215
|
-
stream.push({ type: "error", reason: "error", error: finalMessage });
|
|
2216
|
-
} else {
|
|
2217
|
-
stream.push({ type: "done", reason: "stop", message: finalMessage });
|
|
2503
|
+
if (result.is_error) {
|
|
2504
|
+
finalMessage.errorMessage = getResultErrorMessage(result);
|
|
2505
|
+
stream.push({ type: "error", reason: "error", error: finalMessage });
|
|
2506
|
+
} else {
|
|
2507
|
+
stream.push({ type: "done", reason: "stop", message: finalMessage });
|
|
2508
|
+
}
|
|
2509
|
+
return;
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
default:
|
|
2513
|
+
break;
|
|
2218
2514
|
}
|
|
2219
|
-
|
|
2515
|
+
}
|
|
2516
|
+
} finally {
|
|
2517
|
+
options?.signal?.removeEventListener("abort", forwardAbort);
|
|
2220
2518
|
}
|
|
2221
2519
|
|
|
2222
|
-
|
|
2223
|
-
|
|
2520
|
+
// The SDK stream ended without a terminal `result` message and
|
|
2521
|
+
// without a readiness retry (the only restart path, via
|
|
2522
|
+
// `continue sdkAttemptLoop`). Break out so the post-loop
|
|
2523
|
+
// exhaustion handler emits a transient stream-exhausted error,
|
|
2524
|
+
// instead of silently starting another SDK session and looping
|
|
2525
|
+
// forever.
|
|
2526
|
+
break sdkAttemptLoop;
|
|
2224
2527
|
}
|
|
2528
|
+
} finally {
|
|
2529
|
+
if (trackWorkflowMcpSdk) endWorkflowMcpSdkSession();
|
|
2225
2530
|
}
|
|
2226
2531
|
|
|
2227
2532
|
// Generator exhaustion without a terminal result is a stream interruption,
|