@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
|
@@ -15,7 +15,7 @@ import { homedir } from "node:os";
|
|
|
15
15
|
import { createRequire } from "node:module";
|
|
16
16
|
import { dirname, join } from "node:path";
|
|
17
17
|
import { ZERO_USAGE, mapUsage } from "./partial-builder.js";
|
|
18
|
-
import { attachExternalResultsToToolBlocks, buildFinalAssistantContent, extractToolResultsFromSdkUserMessage, handleClaudeCodePartialStreamEvent, } from "./turn-assembler.js";
|
|
18
|
+
import { attachExternalResultsToToolBlocks, buildFinalAssistantContent, extractToolResultsFromSdkUserMessage, handleClaudeCodePartialStreamEvent, shouldSuppressDuplicateToolUnavailableBlock, } from "./turn-assembler.js";
|
|
19
19
|
import { buildWorkflowMcpServers, getRequiredWorkflowToolsForAutoUnit, resolveWorkflowMcpProjectRoot, } from "../gsd/workflow-mcp.js";
|
|
20
20
|
import { resolveWorkflowQuestionToolSurface } from "../gsd/question-transport.js";
|
|
21
21
|
import { buildProjectGsdMcpServers, ensureProjectWorkflowMcpConfig } from "../gsd/mcp-project-config.js";
|
|
@@ -24,10 +24,13 @@ import { markToolStart, markToolEnd } from "../gsd/auto.js";
|
|
|
24
24
|
import { markInteractiveElicitationStart, markInteractiveElicitationEnd, } from "../gsd/auto-tool-tracking.js";
|
|
25
25
|
import { discoverBrowserMcpServerName, discoverMcpServers, discoverMcpServerNames, discoverUserMcpServerNames, discoverWorkflowMcpServerName, computeMcpDisallowedTools, } from "../gsd/mcp-filter.js";
|
|
26
26
|
import { RUN_UAT_CLAUDE_NATIVE_TOOL_NAMES, RUN_UAT_FORBIDDEN_TOOL_NAMES, RUN_UAT_WORKFLOW_TOOL_NAMES, resolveToolPresentationPlan } from "../gsd/tool-presentation-plan.js";
|
|
27
|
-
import {
|
|
27
|
+
import { getUnitToolSurfaceContract } from "../gsd/unit-tool-contracts.js";
|
|
28
|
+
import { awaitWorkflowMcpToolRegistration, getToolSurfaceReadinessError, POST_PREFLIGHT_READINESS_RETRY_DELAYS_MS, POST_PREFLIGHT_SDK_SETTLE_MS, TOOL_SURFACE_NOT_READY, } from "../gsd/tool-surface-readiness.js";
|
|
29
|
+
import { beginWorkflowMcpSdkSession, endWorkflowMcpSdkSession, } from "../gsd/workflow-mcp-readiness-cache.js";
|
|
30
|
+
import { getGuidedUnitContext } from "../gsd/guided-unit-context.js";
|
|
28
31
|
import { hasBrowserContractPrefix } from "../shared/browser-contract.js";
|
|
29
32
|
import { showInterviewRound } from "../shared/tui.js";
|
|
30
|
-
export { buildFinalAssistantContent, extractToolResultsFromSdkUserMessage, handleClaudeCodePartialStreamEvent, mergePendingToolCalls, } from "./turn-assembler.js";
|
|
33
|
+
export { buildFinalAssistantContent, extractToolResultsFromSdkUserMessage, handleClaudeCodePartialStreamEvent, mergePendingToolCalls, shouldSuppressDuplicateToolUnavailableBlock, } from "./turn-assembler.js";
|
|
31
34
|
export function serverToolUseToToolCallLike(block) {
|
|
32
35
|
const argumentsValue = block.input && typeof block.input === "object" && !Array.isArray(block.input)
|
|
33
36
|
? block.input
|
|
@@ -179,13 +182,18 @@ const GSD_PHASE_PATTERNS = [
|
|
|
179
182
|
["reassess-roadmap", /\b(?:UNIT:\s*Reassess Roadmap|reassess-roadmap)\b/i],
|
|
180
183
|
["complete-slice", /\b(?:UNIT:\s*Complete Slice|complete-slice)\b/i],
|
|
181
184
|
["replan-slice", /\b(?:UNIT:\s*Replan Slice|replan-slice)\b/i],
|
|
185
|
+
["refine-slice", /\b(?:UNIT:\s*Refine Slice|refine-slice)\b/i],
|
|
182
186
|
["plan-slice", /\b(?:UNIT:\s*Plan Slice|plan-slice|gsd_plan_slice)\b/i],
|
|
183
187
|
["plan-milestone", /\b(?:UNIT:\s*Plan Milestone|plan-milestone|gsd_plan_milestone)\b/i],
|
|
184
188
|
["execute-task", /\b(?:UNIT:\s*Execute Task|execute-task|execute-task-simple|reactive-execute)\b/i],
|
|
185
189
|
["gate-evaluate", /\b(?:UNIT:\s*Gate Evaluate|gate-evaluate|gsd_save_gate_result)\b/i],
|
|
186
190
|
["research-milestone", /\b(?:UNIT:\s*Research Milestone|research-milestone)\b/i],
|
|
187
191
|
["research-slice", /\b(?:UNIT:\s*Research Slice|research-slice)\b/i],
|
|
192
|
+
["research-decision", /\b(?:research decision|research-decision)\b/i],
|
|
188
193
|
["discuss-milestone", /\b(?:Discuss milestone|discuss-milestone)\b/i],
|
|
194
|
+
["discuss-slice", /\b(?:Discuss slice|discuss-slice)\b/i],
|
|
195
|
+
["discuss-project", /\b(?:discuss-project|Discuss project)\b/i],
|
|
196
|
+
["discuss-requirements", /\b(?:discuss-requirements|Discuss requirements)\b/i],
|
|
189
197
|
];
|
|
190
198
|
export function inferGsdPhaseFromContext(context) {
|
|
191
199
|
const text = [
|
|
@@ -198,6 +206,24 @@ export function inferGsdPhaseFromContext(context) {
|
|
|
198
206
|
}
|
|
199
207
|
return undefined;
|
|
200
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Resolve the GSD unit phase for Claude Code SDK sessions. Guided-flow
|
|
211
|
+
* dispatch records the authoritative unit type before the turn is queued;
|
|
212
|
+
* prefer that over regex inference from prompt text.
|
|
213
|
+
*/
|
|
214
|
+
export function resolveGsdPhaseForSdk(context, projectRoot) {
|
|
215
|
+
const resolvedRoot = resolveWorkflowMcpProjectRoot(projectRoot);
|
|
216
|
+
const guided = getGuidedUnitContext(resolvedRoot)
|
|
217
|
+
?? getGuidedUnitContext(projectRoot)
|
|
218
|
+
?? getGuidedUnitContext();
|
|
219
|
+
if (guided?.unitType) {
|
|
220
|
+
const guidedRoot = resolveWorkflowMcpProjectRoot(guided.basePath);
|
|
221
|
+
if (guidedRoot === resolvedRoot) {
|
|
222
|
+
return guided.unitType;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return inferGsdPhaseFromContext(context);
|
|
226
|
+
}
|
|
201
227
|
/**
|
|
202
228
|
* Build a full conversational prompt from GSD's context messages.
|
|
203
229
|
*
|
|
@@ -223,10 +249,15 @@ export function buildPromptFromContext(context, toolContext = {}) {
|
|
|
223
249
|
const workflowToolLine = toolContext.workflowMcpServerName
|
|
224
250
|
? "- GSD workflow tools (gsd_exec, gsd_slice_complete, gsd_task_complete, gsd_plan_slice, gsd_save_gate_result, etc.) " +
|
|
225
251
|
`are MCP tools — call them as mcp__${toolContext.workflowMcpServerName}__<tool_name> ` +
|
|
226
|
-
`(e.g. mcp__${toolContext.workflowMcpServerName}__gsd_exec, mcp__${toolContext.workflowMcpServerName}__gsd_save_gate_result)\n`
|
|
252
|
+
`(e.g. mcp__${toolContext.workflowMcpServerName}__gsd_exec, mcp__${toolContext.workflowMcpServerName}__gsd_save_gate_result)\n` +
|
|
253
|
+
`- Structured user input: call mcp__${toolContext.workflowMcpServerName}__ask_user_questions. ` +
|
|
254
|
+
"Do not call bare ask_user_questions. Do not call native AskUserQuestion.\n"
|
|
227
255
|
: "- GSD workflow MCP tools are unavailable in this Claude Code run.\n";
|
|
228
256
|
const toolSearchLine = toolContext.workflowMcpServerName
|
|
229
|
-
? "- ToolSearch is
|
|
257
|
+
? "- ToolSearch is available only for Claude Code deferred workflow MCP hydration. " +
|
|
258
|
+
`If mcp__${toolContext.workflowMcpServerName}__<tool_name> is missing or Claude Code reports the server is still connecting, ` +
|
|
259
|
+
`use ToolSearch with select:mcp__${toolContext.workflowMcpServerName}__<tool_name> or the base tool name, then call the returned MCP tool directly. ` +
|
|
260
|
+
"Do not use ToolSearch for browser_* tools or general discovery.\n"
|
|
230
261
|
: "- ToolSearch is NOT available — never use it to discover tools\n";
|
|
231
262
|
const browserToolLine = toolContext.browserMcpServerName
|
|
232
263
|
? "- Browser verification uses gsd-browser MCP by default — call browser tools as " +
|
|
@@ -320,9 +351,11 @@ export function buildSdkQueryPrompt(context, textPrompt = buildPromptFromContext
|
|
|
320
351
|
message: { role: "user", content },
|
|
321
352
|
parent_tool_use_id: null,
|
|
322
353
|
};
|
|
323
|
-
return
|
|
324
|
-
|
|
325
|
-
|
|
354
|
+
return {
|
|
355
|
+
async *[Symbol.asyncIterator]() {
|
|
356
|
+
yield sdkMessage;
|
|
357
|
+
},
|
|
358
|
+
};
|
|
326
359
|
}
|
|
327
360
|
// ---------------------------------------------------------------------------
|
|
328
361
|
// Error helper
|
|
@@ -341,6 +374,40 @@ function makeErrorMessage(model, errorMsg) {
|
|
|
341
374
|
timestamp: Date.now(),
|
|
342
375
|
};
|
|
343
376
|
}
|
|
377
|
+
export function buildWorkflowMcpReadinessProgressMessage(input) {
|
|
378
|
+
const { unitType, workflowServerName, stage } = input;
|
|
379
|
+
if (stage === "preflight") {
|
|
380
|
+
return `Starting ${workflowServerName} MCP for ${unitType}; waiting for workflow tools to register...`;
|
|
381
|
+
}
|
|
382
|
+
const attempt = input.attempt === undefined ? "" : ` attempt ${input.attempt}`;
|
|
383
|
+
const delay = input.delayMs === undefined ? "" : ` Retrying in ${formatReadinessDelay(input.delayMs)}.`;
|
|
384
|
+
return `Still waiting for ${workflowServerName} MCP tools for ${unitType}${attempt}.${delay}`;
|
|
385
|
+
}
|
|
386
|
+
function formatReadinessDelay(delayMs) {
|
|
387
|
+
if (delayMs < 1_000)
|
|
388
|
+
return `${delayMs}ms`;
|
|
389
|
+
const seconds = delayMs / 1_000;
|
|
390
|
+
return Number.isInteger(seconds) ? `${seconds}s` : `${seconds.toFixed(1)}s`;
|
|
391
|
+
}
|
|
392
|
+
export function pushWorkflowMcpReadinessProgressEvent(input) {
|
|
393
|
+
const { stream, partial, state, message } = input;
|
|
394
|
+
if (!message)
|
|
395
|
+
return;
|
|
396
|
+
let contentIndex = state.contentIndex;
|
|
397
|
+
const existing = contentIndex === undefined ? undefined : partial.content[contentIndex];
|
|
398
|
+
if (contentIndex === undefined || existing?.type !== "text") {
|
|
399
|
+
contentIndex = partial.content.length;
|
|
400
|
+
state.contentIndex = contentIndex;
|
|
401
|
+
partial.content.push({ type: "text", text: "" });
|
|
402
|
+
stream.push({ type: "text_start", contentIndex, partial });
|
|
403
|
+
}
|
|
404
|
+
const block = partial.content[contentIndex];
|
|
405
|
+
if (block.type !== "text")
|
|
406
|
+
return;
|
|
407
|
+
const delta = block.text.length === 0 ? message : `\n${message}`;
|
|
408
|
+
block.text += delta;
|
|
409
|
+
stream.push({ type: "text_delta", contentIndex, delta, partial });
|
|
410
|
+
}
|
|
344
411
|
export function isClaudeCodeAbortErrorMessage(message) {
|
|
345
412
|
if (!message)
|
|
346
413
|
return false;
|
|
@@ -1354,11 +1421,13 @@ function resolveProjectMcpServerConfigs(projectRoot, serverNames, fallbackServer
|
|
|
1354
1421
|
function resolveExactWorkflowMcpToolsForPhase(gsdPhase, workflowServerName, workflowExplicitlyBlocked) {
|
|
1355
1422
|
if (!gsdPhase || !workflowServerName || workflowExplicitlyBlocked)
|
|
1356
1423
|
return [];
|
|
1357
|
-
const
|
|
1424
|
+
const requestedTools = gsdPhase === "run-uat"
|
|
1358
1425
|
? [...RUN_UAT_WORKFLOW_TOOL_NAMES]
|
|
1359
|
-
:
|
|
1360
|
-
|
|
1361
|
-
|
|
1426
|
+
: [
|
|
1427
|
+
...(getUnitToolSurfaceContract(gsdPhase)?.allowedGsdTools ?? []),
|
|
1428
|
+
...getRequiredWorkflowToolsForAutoUnit(gsdPhase),
|
|
1429
|
+
];
|
|
1430
|
+
const requestedToolNames = [...new Set(requestedTools.filter((toolName) => toolName.startsWith("gsd_") || toolName === "ask_user_questions"))];
|
|
1362
1431
|
if (requestedToolNames.length === 0)
|
|
1363
1432
|
return [];
|
|
1364
1433
|
return resolveToolPresentationPlan({
|
|
@@ -1368,6 +1437,25 @@ function resolveExactWorkflowMcpToolsForPhase(gsdPhase, workflowServerName, work
|
|
|
1368
1437
|
requestedToolNames,
|
|
1369
1438
|
}).presentedToolNames;
|
|
1370
1439
|
}
|
|
1440
|
+
function resolveClaudeNativeToolsForPhase(gsdPhase) {
|
|
1441
|
+
const standardClaudeTools = [
|
|
1442
|
+
"Read",
|
|
1443
|
+
"Write",
|
|
1444
|
+
"Edit",
|
|
1445
|
+
"Glob",
|
|
1446
|
+
"Grep",
|
|
1447
|
+
"Bash",
|
|
1448
|
+
"Agent",
|
|
1449
|
+
"WebFetch",
|
|
1450
|
+
"WebSearch",
|
|
1451
|
+
];
|
|
1452
|
+
if (!gsdPhase)
|
|
1453
|
+
return standardClaudeTools;
|
|
1454
|
+
if (gsdPhase === "run-uat" || gsdPhase === "complete-slice") {
|
|
1455
|
+
return [...RUN_UAT_CLAUDE_NATIVE_TOOL_NAMES];
|
|
1456
|
+
}
|
|
1457
|
+
return standardClaudeTools;
|
|
1458
|
+
}
|
|
1371
1459
|
export function autoInitClaudeCodeWorkflowMcp(cwd) {
|
|
1372
1460
|
const projectRoot = resolveWorkflowMcpProjectRoot(cwd);
|
|
1373
1461
|
try {
|
|
@@ -1379,6 +1467,51 @@ export function autoInitClaudeCodeWorkflowMcp(cwd) {
|
|
|
1379
1467
|
}
|
|
1380
1468
|
}
|
|
1381
1469
|
}
|
|
1470
|
+
export function resolveClaudeCodeToolSurfaceReadinessError(input) {
|
|
1471
|
+
const error = getToolSurfaceReadinessError(input);
|
|
1472
|
+
if (error
|
|
1473
|
+
&& input.allowPendingToolSearchHydration
|
|
1474
|
+
&& input.workflowServerName
|
|
1475
|
+
&& input.observation.mcpServers.some((server) => server.name === input.workflowServerName && server.status === "pending")) {
|
|
1476
|
+
return Promise.resolve(null);
|
|
1477
|
+
}
|
|
1478
|
+
return Promise.resolve(error);
|
|
1479
|
+
}
|
|
1480
|
+
export { awaitWorkflowMcpToolRegistration } from "../gsd/tool-surface-readiness.js";
|
|
1481
|
+
const TOOL_SURFACE_READINESS_RETRY_DELAYS_MS = [500, 1_000, 2_000, 4_000, 8_000, 15_000, 15_000, 15_000];
|
|
1482
|
+
export function shouldRetryClaudeCodeToolSurfaceReadiness(error) {
|
|
1483
|
+
if (!error)
|
|
1484
|
+
return false;
|
|
1485
|
+
return error.includes(TOOL_SURFACE_NOT_READY) && !/\bterminal\b/i.test(error);
|
|
1486
|
+
}
|
|
1487
|
+
export function resolveClaudeCodeToolSurfaceReadinessRetryDelayMs(error, attempt, preflightVerified = false) {
|
|
1488
|
+
if (!shouldRetryClaudeCodeToolSurfaceReadiness(error))
|
|
1489
|
+
return null;
|
|
1490
|
+
const delays = preflightVerified
|
|
1491
|
+
? POST_PREFLIGHT_READINESS_RETRY_DELAYS_MS
|
|
1492
|
+
: TOOL_SURFACE_READINESS_RETRY_DELAYS_MS;
|
|
1493
|
+
return delays[attempt] ?? null;
|
|
1494
|
+
}
|
|
1495
|
+
function makeAbortError() {
|
|
1496
|
+
const error = new Error("AbortError: The operation was aborted");
|
|
1497
|
+
error.name = "AbortError";
|
|
1498
|
+
return error;
|
|
1499
|
+
}
|
|
1500
|
+
function delay(ms, signal) {
|
|
1501
|
+
if (signal?.aborted)
|
|
1502
|
+
return Promise.reject(makeAbortError());
|
|
1503
|
+
return new Promise((resolve, reject) => {
|
|
1504
|
+
const timeout = setTimeout(() => {
|
|
1505
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1506
|
+
resolve();
|
|
1507
|
+
}, ms);
|
|
1508
|
+
const onAbort = () => {
|
|
1509
|
+
clearTimeout(timeout);
|
|
1510
|
+
reject(makeAbortError());
|
|
1511
|
+
};
|
|
1512
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1382
1515
|
/**
|
|
1383
1516
|
* Build the options object passed to the Claude Agent SDK's `query()` call.
|
|
1384
1517
|
*
|
|
@@ -1510,34 +1643,27 @@ export function buildSdkOptions(modelId, prompt, overrides, extraOptions = {}) {
|
|
|
1510
1643
|
`mcp__${workflowServerName}__gsd_save_gate_result`,
|
|
1511
1644
|
]
|
|
1512
1645
|
: [];
|
|
1646
|
+
const allowToolSearchForWorkflowMcp = workflowMcpTools.length > 0 || exactWorkflowMcpTools.length > 0;
|
|
1513
1647
|
const disallowedTools = [...new Set([
|
|
1514
|
-
"ToolSearch",
|
|
1648
|
+
...(allowToolSearchForWorkflowMcp ? [] : ["ToolSearch"]),
|
|
1649
|
+
...(gsdPhase ? ["Skill"] : []),
|
|
1515
1650
|
...(workflowMcpTools.length > 0 || exactWorkflowMcpTools.length > 0 ? ["AskUserQuestion"] : []),
|
|
1516
1651
|
...questionToolSurface.disallowedTools,
|
|
1517
1652
|
...runUatDisallowedTools,
|
|
1518
1653
|
...extraDisallowedTools,
|
|
1519
1654
|
])];
|
|
1520
|
-
const
|
|
1521
|
-
"Read",
|
|
1522
|
-
"Write",
|
|
1523
|
-
"Edit",
|
|
1524
|
-
"Glob",
|
|
1525
|
-
"Grep",
|
|
1526
|
-
"Bash",
|
|
1527
|
-
"Agent",
|
|
1528
|
-
"WebFetch",
|
|
1529
|
-
"WebSearch",
|
|
1530
|
-
];
|
|
1655
|
+
const nativeTools = resolveClaudeNativeToolsForPhase(gsdPhase);
|
|
1531
1656
|
const allowedTools = gsdPhase === "run-uat"
|
|
1532
1657
|
? [
|
|
1533
|
-
...
|
|
1658
|
+
...nativeTools,
|
|
1534
1659
|
...(exactWorkflowMcpTools.length > 0 ? exactWorkflowMcpTools : []),
|
|
1535
1660
|
...allowedBrowserMcpTools,
|
|
1536
1661
|
]
|
|
1537
1662
|
: [
|
|
1538
|
-
...
|
|
1663
|
+
...nativeTools,
|
|
1539
1664
|
...exactWorkflowMcpTools,
|
|
1540
|
-
...(workflowMcpTools.length > 0 ? workflowMcpTools : [
|
|
1665
|
+
...(!gsdPhase && workflowMcpTools.length > 0 ? workflowMcpTools : []),
|
|
1666
|
+
...(workflowMcpTools.length === 0 && exactWorkflowMcpTools.length === 0 ? ["AskUserQuestion"] : []),
|
|
1541
1667
|
...allowedBrowserMcpTools,
|
|
1542
1668
|
];
|
|
1543
1669
|
const supportsAdaptive = modelSupportsAdaptiveThinking(modelId);
|
|
@@ -1594,33 +1720,33 @@ export function streamViaClaudeCode(model, context, options) {
|
|
|
1594
1720
|
void pumpSdkMessages(model, context, options, stream);
|
|
1595
1721
|
return stream;
|
|
1596
1722
|
}
|
|
1723
|
+
function createSdkAttemptMessageState() {
|
|
1724
|
+
return {
|
|
1725
|
+
builder: null,
|
|
1726
|
+
intermediateToolBlocks: [],
|
|
1727
|
+
toolResultsById: new Map(),
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1597
1730
|
/** Async pump that drives the Claude Agent SDK's async-iterable message stream and pushes events into `stream`. */
|
|
1598
1731
|
async function pumpSdkMessages(model, context, options, stream) {
|
|
1599
1732
|
const modelId = model.id;
|
|
1600
|
-
let builder = null;
|
|
1601
1733
|
/** Track the last text content seen across all assistant turns for the final message. */
|
|
1602
1734
|
let lastTextContent = "";
|
|
1603
1735
|
let lastThinkingContent = "";
|
|
1604
|
-
/** Collect tool blocks from intermediate SDK turns for tool execution rendering. */
|
|
1605
|
-
const intermediateToolBlocks = [];
|
|
1606
|
-
/** Preserve real external tool results from Claude Code's synthetic user messages. */
|
|
1607
|
-
const toolResultsById = new Map();
|
|
1608
1736
|
try {
|
|
1609
|
-
// Dynamic import — the SDK is an optional dependency.
|
|
1610
|
-
const sdkModule = "@anthropic-ai/claude-agent-sdk";
|
|
1611
|
-
const sdk = (await import(/* webpackIgnore: true */ sdkModule));
|
|
1612
|
-
// Bridge GSD's AbortSignal to SDK's AbortController
|
|
1613
|
-
const controller = new AbortController();
|
|
1614
|
-
if (options?.signal) {
|
|
1615
|
-
options.signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
1616
|
-
}
|
|
1617
1737
|
const permissionMode = await resolveClaudePermissionMode();
|
|
1618
|
-
const
|
|
1619
|
-
const
|
|
1620
|
-
const
|
|
1738
|
+
const claudeOptions = options;
|
|
1739
|
+
const uiContext = claudeOptions?.extensionUIContext;
|
|
1740
|
+
const onExternalToolCall = claudeOptions?.onExternalToolCall;
|
|
1741
|
+
const onExternalToolResult = claudeOptions?.onExternalToolResult;
|
|
1742
|
+
const sdkQueryForTest = claudeOptions?._sdkQueryForTest;
|
|
1743
|
+
const query = sdkQueryForTest ??
|
|
1744
|
+
// Dynamic import — the SDK is an optional dependency.
|
|
1745
|
+
(await import(/* webpackIgnore: true */ "@anthropic-ai/claude-agent-sdk")).query;
|
|
1621
1746
|
const cwd = resolveClaudeCodeCwd(options);
|
|
1747
|
+
const projectRoot = resolveWorkflowMcpProjectRoot(cwd);
|
|
1622
1748
|
autoInitClaudeCodeWorkflowMcp(cwd);
|
|
1623
|
-
const gsdPhase =
|
|
1749
|
+
const gsdPhase = resolveGsdPhaseForSdk(context, projectRoot);
|
|
1624
1750
|
const canUseToolHandler = createClaudeCodeCanUseToolHandler(uiContext);
|
|
1625
1751
|
// When no UI is available (headless / auto-mode), auto-approve all
|
|
1626
1752
|
// tool requests. This replaces the old bypassPermissions workaround.
|
|
@@ -1638,18 +1764,13 @@ async function pumpSdkMessages(model, context, options, stream) {
|
|
|
1638
1764
|
: {}),
|
|
1639
1765
|
});
|
|
1640
1766
|
const workflowMcpServerName = workflowMcpServerNameFromAllowedTools(sdkOpts.allowedTools);
|
|
1767
|
+
const allowPendingToolSearchHydration = Boolean(workflowMcpServerName && gsdPhase)
|
|
1768
|
+
&& !sdkOpts.disallowedTools?.includes("ToolSearch");
|
|
1641
1769
|
const prompt = buildPromptFromContext(context, {
|
|
1642
1770
|
workflowMcpServerName,
|
|
1643
1771
|
browserMcpServerName: browserMcpServerNameFromAllowedTools(sdkOpts.allowedTools),
|
|
1644
1772
|
});
|
|
1645
1773
|
const queryPrompt = buildSdkQueryPrompt(context, prompt);
|
|
1646
|
-
const queryResult = sdk.query({
|
|
1647
|
-
prompt: queryPrompt,
|
|
1648
|
-
options: {
|
|
1649
|
-
...sdkOpts,
|
|
1650
|
-
abortController: controller,
|
|
1651
|
-
},
|
|
1652
|
-
});
|
|
1653
1774
|
// Emit start with an empty partial
|
|
1654
1775
|
const initialPartial = {
|
|
1655
1776
|
role: "assistant",
|
|
@@ -1662,192 +1783,303 @@ async function pumpSdkMessages(model, context, options, stream) {
|
|
|
1662
1783
|
timestamp: Date.now(),
|
|
1663
1784
|
};
|
|
1664
1785
|
stream.push({ type: "start", partial: initialPartial });
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1786
|
+
const readinessProgressState = {};
|
|
1787
|
+
const trackWorkflowMcpSdk = Boolean(workflowMcpServerName && gsdPhase);
|
|
1788
|
+
if (trackWorkflowMcpSdk)
|
|
1789
|
+
beginWorkflowMcpSdkSession();
|
|
1790
|
+
try {
|
|
1791
|
+
let workflowMcpPreflightVerified = false;
|
|
1792
|
+
const shouldRunWorkflowMcpPreflight = workflowMcpServerName && gsdPhase && !claudeOptions?._skipWorkflowMcpPreflightForTest;
|
|
1793
|
+
if (shouldRunWorkflowMcpPreflight) {
|
|
1794
|
+
try {
|
|
1795
|
+
const progressMessage = buildWorkflowMcpReadinessProgressMessage({
|
|
1796
|
+
unitType: gsdPhase,
|
|
1797
|
+
workflowServerName: workflowMcpServerName,
|
|
1798
|
+
stage: "preflight",
|
|
1799
|
+
});
|
|
1800
|
+
pushWorkflowMcpReadinessProgressEvent({
|
|
1801
|
+
stream,
|
|
1802
|
+
partial: initialPartial,
|
|
1803
|
+
state: readinessProgressState,
|
|
1804
|
+
message: progressMessage,
|
|
1805
|
+
});
|
|
1806
|
+
uiContext?.setStatus?.("gsd-step", progressMessage);
|
|
1807
|
+
const preflightError = await awaitWorkflowMcpToolRegistration({
|
|
1808
|
+
unitType: gsdPhase,
|
|
1809
|
+
workflowServerName: workflowMcpServerName,
|
|
1810
|
+
projectRoot,
|
|
1811
|
+
signal: options?.signal,
|
|
1812
|
+
});
|
|
1813
|
+
if (preflightError) {
|
|
1814
|
+
stream.push({
|
|
1815
|
+
type: "error",
|
|
1816
|
+
reason: "error",
|
|
1817
|
+
error: makeErrorMessage(modelId, preflightError),
|
|
1693
1818
|
});
|
|
1694
|
-
|
|
1695
|
-
|
|
1819
|
+
return;
|
|
1820
|
+
}
|
|
1821
|
+
workflowMcpPreflightVerified = true;
|
|
1822
|
+
}
|
|
1823
|
+
finally {
|
|
1824
|
+
uiContext?.setStatus?.("gsd-step", "");
|
|
1825
|
+
}
|
|
1826
|
+
if (workflowMcpPreflightVerified) {
|
|
1827
|
+
await delay(POST_PREFLIGHT_SDK_SETTLE_MS, options?.signal);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
sdkAttemptLoop: for (let readinessAttempt = 0;; readinessAttempt++) {
|
|
1831
|
+
let { builder, intermediateToolBlocks, toolResultsById } = createSdkAttemptMessageState();
|
|
1832
|
+
const controller = new AbortController();
|
|
1833
|
+
const forwardAbort = () => controller.abort();
|
|
1834
|
+
if (options?.signal) {
|
|
1835
|
+
options.signal.addEventListener("abort", forwardAbort, { once: true });
|
|
1836
|
+
}
|
|
1837
|
+
const queryResult = query({
|
|
1838
|
+
prompt: queryPrompt,
|
|
1839
|
+
options: {
|
|
1840
|
+
...sdkOpts,
|
|
1841
|
+
abortController: controller,
|
|
1842
|
+
},
|
|
1843
|
+
});
|
|
1844
|
+
try {
|
|
1845
|
+
for await (const msg of queryResult) {
|
|
1846
|
+
if (options?.signal?.aborted) {
|
|
1847
|
+
// User-initiated cancel — emit an aborted error so the agent
|
|
1848
|
+
// loop classifies this as a deliberate stop, not a transient
|
|
1849
|
+
// provider failure that should be retried.
|
|
1696
1850
|
stream.push({
|
|
1697
1851
|
type: "error",
|
|
1698
|
-
reason: "
|
|
1699
|
-
error:
|
|
1852
|
+
reason: "aborted",
|
|
1853
|
+
error: makeAbortedMessage(modelId, lastTextContent),
|
|
1700
1854
|
});
|
|
1701
1855
|
return;
|
|
1702
1856
|
}
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1857
|
+
switch (msg.type) {
|
|
1858
|
+
// -- Init --
|
|
1859
|
+
case "system": {
|
|
1860
|
+
// Tool Surface Readiness gate: the init message is the first (and
|
|
1861
|
+
// only) point where the session reports its live tool surface and
|
|
1862
|
+
// MCP server statuses. If the workflow server failed or has not
|
|
1863
|
+
// registered this Unit's required tools, abort before the first
|
|
1864
|
+
// model turn with a transient, recovery-classifiable error
|
|
1865
|
+
// (tool-unavailable → retry) instead of letting the model hit
|
|
1866
|
+
// "No such tool available" mid-Unit and improvise around it.
|
|
1867
|
+
const init = msg;
|
|
1868
|
+
if (init.subtype === "init") {
|
|
1869
|
+
const readinessError = await resolveClaudeCodeToolSurfaceReadinessError({
|
|
1870
|
+
unitType: gsdPhase,
|
|
1871
|
+
workflowServerName: workflowMcpServerName,
|
|
1872
|
+
projectRoot,
|
|
1873
|
+
observation: { tools: init.tools ?? [], mcpServers: init.mcp_servers ?? [] },
|
|
1874
|
+
allowPendingToolSearchHydration,
|
|
1875
|
+
});
|
|
1876
|
+
if (readinessError) {
|
|
1877
|
+
const retryDelayMs = resolveClaudeCodeToolSurfaceReadinessRetryDelayMs(readinessError, readinessAttempt, workflowMcpPreflightVerified);
|
|
1878
|
+
if (retryDelayMs !== null && !options?.signal?.aborted) {
|
|
1879
|
+
controller.abort();
|
|
1880
|
+
const progressMessage = buildWorkflowMcpReadinessProgressMessage({
|
|
1881
|
+
unitType: gsdPhase ?? "workflow unit",
|
|
1882
|
+
workflowServerName: workflowMcpServerName ?? "workflow",
|
|
1883
|
+
stage: "retry",
|
|
1884
|
+
attempt: readinessAttempt + 1,
|
|
1885
|
+
delayMs: retryDelayMs,
|
|
1886
|
+
});
|
|
1887
|
+
pushWorkflowMcpReadinessProgressEvent({
|
|
1888
|
+
stream,
|
|
1889
|
+
partial: initialPartial,
|
|
1890
|
+
state: readinessProgressState,
|
|
1891
|
+
message: progressMessage,
|
|
1892
|
+
});
|
|
1893
|
+
uiContext?.setStatus?.("gsd-step", progressMessage);
|
|
1894
|
+
await delay(retryDelayMs, options?.signal);
|
|
1895
|
+
uiContext?.setStatus?.("gsd-step", "");
|
|
1896
|
+
continue sdkAttemptLoop;
|
|
1897
|
+
}
|
|
1898
|
+
controller.abort();
|
|
1899
|
+
stream.push({
|
|
1900
|
+
type: "error",
|
|
1901
|
+
reason: "error",
|
|
1902
|
+
error: makeErrorMessage(modelId, readinessError),
|
|
1903
|
+
});
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1723
1906
|
}
|
|
1907
|
+
break;
|
|
1724
1908
|
}
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
for (const block of builder.message.content) {
|
|
1748
|
-
if (block.type === "text" && block.text) {
|
|
1749
|
-
lastTextContent = block.text;
|
|
1750
|
-
}
|
|
1751
|
-
else if (block.type === "thinking" && block.thinking) {
|
|
1752
|
-
lastThinkingContent = block.thinking;
|
|
1909
|
+
// -- Streaming partial messages --
|
|
1910
|
+
case "stream_event": {
|
|
1911
|
+
const partial = msg;
|
|
1912
|
+
const event = partial.event;
|
|
1913
|
+
const result = handleClaudeCodePartialStreamEvent(builder, event, modelId);
|
|
1914
|
+
builder = result.builder;
|
|
1915
|
+
const assistantEvent = result.assistantEvent;
|
|
1916
|
+
if (assistantEvent) {
|
|
1917
|
+
stream.push(assistantEvent);
|
|
1918
|
+
if (assistantEvent.type === "toolcall_start") {
|
|
1919
|
+
const toolBlock = assistantEvent.partial.content[assistantEvent.contentIndex];
|
|
1920
|
+
if (toolBlock?.type === "toolCall") {
|
|
1921
|
+
try {
|
|
1922
|
+
await onExternalToolCall?.(toolBlock);
|
|
1923
|
+
}
|
|
1924
|
+
catch (error) {
|
|
1925
|
+
console.warn("[claude-code] onExternalToolCall callback failed:", error);
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
break;
|
|
1753
1931
|
}
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1932
|
+
// -- Complete assistant message (non-streaming fallback) --
|
|
1933
|
+
case "assistant": {
|
|
1934
|
+
const sdkAssistant = msg;
|
|
1935
|
+
// Capture text content from complete messages
|
|
1936
|
+
for (const block of sdkAssistant.message.content) {
|
|
1937
|
+
if (block.type === "text") {
|
|
1938
|
+
lastTextContent = block.text;
|
|
1939
|
+
}
|
|
1940
|
+
else if (block.type === "thinking") {
|
|
1941
|
+
lastThinkingContent = block.thinking;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
break;
|
|
1757
1945
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
const contentIndex = builder.message.content.indexOf(block);
|
|
1775
|
-
if (contentIndex < 0)
|
|
1776
|
-
continue;
|
|
1777
|
-
// Push synthetic completion events with result attached so the
|
|
1778
|
-
// chat-controller can update pending ToolExecutionComponents.
|
|
1779
|
-
if (block.type === "toolCall") {
|
|
1780
|
-
try {
|
|
1781
|
-
await onExternalToolResult?.({
|
|
1782
|
-
toolCall: block,
|
|
1783
|
-
result: extResult,
|
|
1784
|
-
});
|
|
1946
|
+
// -- User message (synthetic tool result — signals turn boundary) --
|
|
1947
|
+
case "user": {
|
|
1948
|
+
// Capture content from the completed turn before resetting
|
|
1949
|
+
if (builder) {
|
|
1950
|
+
for (const block of builder.message.content) {
|
|
1951
|
+
if (block.type === "text" && block.text) {
|
|
1952
|
+
lastTextContent = block.text;
|
|
1953
|
+
}
|
|
1954
|
+
else if (block.type === "thinking" && block.thinking) {
|
|
1955
|
+
lastThinkingContent = block.thinking;
|
|
1956
|
+
}
|
|
1957
|
+
else if (block.type === "toolCall" || block.type === "serverToolUse") {
|
|
1958
|
+
// Collect tool blocks for externalToolExecution rendering
|
|
1959
|
+
intermediateToolBlocks.push(block);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1785
1962
|
}
|
|
1786
|
-
|
|
1787
|
-
|
|
1963
|
+
// Extract tool results from the SDK's synthetic user message
|
|
1964
|
+
// and attach to corresponding tool call blocks immediately.
|
|
1965
|
+
for (const { toolUseId, result } of extractToolResultsFromSdkUserMessage(msg)) {
|
|
1966
|
+
toolResultsById.set(toolUseId, result);
|
|
1788
1967
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1968
|
+
attachExternalResultsToToolBlocks(intermediateToolBlocks, toolResultsById);
|
|
1969
|
+
// Push a synthetic toolcall_end for each tool call from this turn
|
|
1970
|
+
// so the TUI can render tool results in real-time during the SDK
|
|
1971
|
+
// session instead of waiting until the entire session completes.
|
|
1972
|
+
if (builder) {
|
|
1973
|
+
for (const block of builder.message.content) {
|
|
1974
|
+
const extResult = block.externalResult;
|
|
1975
|
+
if (!extResult)
|
|
1976
|
+
continue;
|
|
1977
|
+
const contentIndex = builder.message.content.indexOf(block);
|
|
1978
|
+
if (contentIndex < 0)
|
|
1979
|
+
continue;
|
|
1980
|
+
const suppressDuplicateUnavailable = shouldSuppressDuplicateToolUnavailableBlock(block, builder.message.content);
|
|
1981
|
+
// Push synthetic completion events with result attached so the
|
|
1982
|
+
// chat-controller can update pending ToolExecutionComponents.
|
|
1983
|
+
if (block.type === "toolCall") {
|
|
1984
|
+
if (suppressDuplicateUnavailable) {
|
|
1985
|
+
delete block.externalResult;
|
|
1986
|
+
stream.push({
|
|
1987
|
+
type: "toolcall_end",
|
|
1988
|
+
contentIndex,
|
|
1989
|
+
toolCall: block,
|
|
1990
|
+
partial: builder.message,
|
|
1991
|
+
});
|
|
1992
|
+
block.externalResult = extResult;
|
|
1993
|
+
continue;
|
|
1994
|
+
}
|
|
1995
|
+
try {
|
|
1996
|
+
await onExternalToolResult?.({
|
|
1997
|
+
toolCall: block,
|
|
1998
|
+
result: extResult,
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
catch (error) {
|
|
2002
|
+
console.warn("[claude-code] onExternalToolResult callback failed:", error);
|
|
2003
|
+
}
|
|
2004
|
+
stream.push({
|
|
2005
|
+
type: "toolcall_end",
|
|
2006
|
+
contentIndex,
|
|
2007
|
+
toolCall: block,
|
|
2008
|
+
partial: builder.message,
|
|
2009
|
+
});
|
|
2010
|
+
}
|
|
2011
|
+
else if (block.type === "serverToolUse") {
|
|
2012
|
+
try {
|
|
2013
|
+
await onExternalToolResult?.({
|
|
2014
|
+
toolCall: serverToolUseToToolCallLike(block),
|
|
2015
|
+
result: extResult,
|
|
2016
|
+
});
|
|
2017
|
+
}
|
|
2018
|
+
catch (error) {
|
|
2019
|
+
console.warn("[claude-code] onExternalToolResult callback failed:", error);
|
|
2020
|
+
}
|
|
2021
|
+
stream.push({
|
|
2022
|
+
type: "server_tool_use",
|
|
2023
|
+
contentIndex,
|
|
2024
|
+
partial: builder.message,
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
builder = null;
|
|
2030
|
+
break;
|
|
1795
2031
|
}
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
2032
|
+
// -- Result (terminal) --
|
|
2033
|
+
case "result": {
|
|
2034
|
+
const result = msg;
|
|
2035
|
+
const finalContent = buildFinalAssistantContent({
|
|
2036
|
+
intermediateToolBlocks,
|
|
2037
|
+
pendingContent: builder?.message.content,
|
|
2038
|
+
toolResultsById,
|
|
2039
|
+
lastThinkingContent,
|
|
2040
|
+
lastTextContent,
|
|
2041
|
+
fallbackResultText: result.subtype === "success" && result.result ? result.result : undefined,
|
|
2042
|
+
});
|
|
2043
|
+
const finalMessage = {
|
|
2044
|
+
role: "assistant",
|
|
2045
|
+
content: finalContent,
|
|
2046
|
+
api: "anthropic-messages",
|
|
2047
|
+
provider: "claude-code",
|
|
2048
|
+
model: modelId,
|
|
2049
|
+
usage: mapUsage(result.usage, result.total_cost_usd),
|
|
2050
|
+
stopReason: result.is_error ? "error" : "stop",
|
|
2051
|
+
timestamp: Date.now(),
|
|
2052
|
+
};
|
|
2053
|
+
if (result.is_error) {
|
|
2054
|
+
finalMessage.errorMessage = getResultErrorMessage(result);
|
|
2055
|
+
stream.push({ type: "error", reason: "error", error: finalMessage });
|
|
1802
2056
|
}
|
|
1803
|
-
|
|
1804
|
-
|
|
2057
|
+
else {
|
|
2058
|
+
stream.push({ type: "done", reason: "stop", message: finalMessage });
|
|
1805
2059
|
}
|
|
1806
|
-
|
|
1807
|
-
type: "server_tool_use",
|
|
1808
|
-
contentIndex,
|
|
1809
|
-
partial: builder.message,
|
|
1810
|
-
});
|
|
2060
|
+
return;
|
|
1811
2061
|
}
|
|
2062
|
+
default:
|
|
2063
|
+
break;
|
|
1812
2064
|
}
|
|
1813
2065
|
}
|
|
1814
|
-
builder = null;
|
|
1815
|
-
break;
|
|
1816
2066
|
}
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
const result = msg;
|
|
1820
|
-
const finalContent = buildFinalAssistantContent({
|
|
1821
|
-
intermediateToolBlocks,
|
|
1822
|
-
pendingContent: builder?.message.content,
|
|
1823
|
-
toolResultsById,
|
|
1824
|
-
lastThinkingContent,
|
|
1825
|
-
lastTextContent,
|
|
1826
|
-
fallbackResultText: result.subtype === "success" && result.result ? result.result : undefined,
|
|
1827
|
-
});
|
|
1828
|
-
const finalMessage = {
|
|
1829
|
-
role: "assistant",
|
|
1830
|
-
content: finalContent,
|
|
1831
|
-
api: "anthropic-messages",
|
|
1832
|
-
provider: "claude-code",
|
|
1833
|
-
model: modelId,
|
|
1834
|
-
usage: mapUsage(result.usage, result.total_cost_usd),
|
|
1835
|
-
stopReason: result.is_error ? "error" : "stop",
|
|
1836
|
-
timestamp: Date.now(),
|
|
1837
|
-
};
|
|
1838
|
-
if (result.is_error) {
|
|
1839
|
-
finalMessage.errorMessage = getResultErrorMessage(result);
|
|
1840
|
-
stream.push({ type: "error", reason: "error", error: finalMessage });
|
|
1841
|
-
}
|
|
1842
|
-
else {
|
|
1843
|
-
stream.push({ type: "done", reason: "stop", message: finalMessage });
|
|
1844
|
-
}
|
|
1845
|
-
return;
|
|
2067
|
+
finally {
|
|
2068
|
+
options?.signal?.removeEventListener("abort", forwardAbort);
|
|
1846
2069
|
}
|
|
1847
|
-
|
|
1848
|
-
|
|
2070
|
+
// The SDK stream ended without a terminal `result` message and
|
|
2071
|
+
// without a readiness retry (the only restart path, via
|
|
2072
|
+
// `continue sdkAttemptLoop`). Break out so the post-loop
|
|
2073
|
+
// exhaustion handler emits a transient stream-exhausted error,
|
|
2074
|
+
// instead of silently starting another SDK session and looping
|
|
2075
|
+
// forever.
|
|
2076
|
+
break sdkAttemptLoop;
|
|
1849
2077
|
}
|
|
1850
2078
|
}
|
|
2079
|
+
finally {
|
|
2080
|
+
if (trackWorkflowMcpSdk)
|
|
2081
|
+
endWorkflowMcpSdkSession();
|
|
2082
|
+
}
|
|
1851
2083
|
// Generator exhaustion without a terminal result is a stream interruption,
|
|
1852
2084
|
// not a successful completion. Emitting an error lets GSD classify it as a
|
|
1853
2085
|
// transient provider failure instead of advancing auto-mode state.
|