lcclaude 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +21 -0
- package/README.en.md +333 -0
- package/README.md +333 -0
- package/bin/lcclaude.js +30 -0
- package/dist/preload.js +15 -0
- package/dist/runtime/bun-bundle-shim.js +10 -0
- package/dist/runtime/bun-wrap-shim.js +63 -0
- package/dist/src/QueryEngine.js +804 -0
- package/dist/src/Task.js +40 -0
- package/dist/src/Tool.js +33 -0
- package/dist/src/assistant/sessionHistory.js +39 -0
- package/dist/src/bootstrap/state.js +985 -0
- package/dist/src/bridge/bridgeApi.js +254 -0
- package/dist/src/bridge/bridgeConfig.js +14 -0
- package/dist/src/bridge/bridgeDebug.js +64 -0
- package/dist/src/bridge/bridgeEnabled.js +55 -0
- package/dist/src/bridge/bridgeMain.js +1547 -0
- package/dist/src/bridge/bridgeMessaging.js +249 -0
- package/dist/src/bridge/bridgePermissionCallbacks.js +7 -0
- package/dist/src/bridge/bridgePointer.js +105 -0
- package/dist/src/bridge/bridgeStatusUtil.js +81 -0
- package/dist/src/bridge/bridgeUI.js +375 -0
- package/dist/src/bridge/capacityWake.js +26 -0
- package/dist/src/bridge/codeSessionApi.js +78 -0
- package/dist/src/bridge/createSession.js +227 -0
- package/dist/src/bridge/debugUtils.js +80 -0
- package/dist/src/bridge/envLessBridgeConfig.js +61 -0
- package/dist/src/bridge/flushGate.js +32 -0
- package/dist/src/bridge/inboundAttachments.js +106 -0
- package/dist/src/bridge/inboundMessages.js +38 -0
- package/dist/src/bridge/initReplBridge.js +276 -0
- package/dist/src/bridge/jwtUtils.js +131 -0
- package/dist/src/bridge/pollConfig.js +28 -0
- package/dist/src/bridge/pollConfigDefaults.js +15 -0
- package/dist/src/bridge/remoteBridgeCore.js +511 -0
- package/dist/src/bridge/replBridge.js +1098 -0
- package/dist/src/bridge/replBridgeHandle.js +14 -0
- package/dist/src/bridge/replBridgeTransport.js +147 -0
- package/dist/src/bridge/sessionIdCompat.js +16 -0
- package/dist/src/bridge/sessionRunner.js +349 -0
- package/dist/src/bridge/trustedDevice.js +113 -0
- package/dist/src/bridge/types.js +6 -0
- package/dist/src/bridge/workSecret.js +51 -0
- package/dist/src/buddy/CompanionSprite.js +435 -0
- package/dist/src/buddy/companion.js +104 -0
- package/dist/src/buddy/prompt.js +31 -0
- package/dist/src/buddy/sprites.js +500 -0
- package/dist/src/buddy/types.js +85 -0
- package/dist/src/buddy/useBuddyNotification.js +93 -0
- package/dist/src/cli/exit.js +13 -0
- package/dist/src/cli/handlers/agents.js +55 -0
- package/dist/src/cli/handlers/auth.js +255 -0
- package/dist/src/cli/handlers/autoMode.js +117 -0
- package/dist/src/cli/handlers/mcp.js +304 -0
- package/dist/src/cli/handlers/plugins.js +538 -0
- package/dist/src/cli/handlers/util.js +119 -0
- package/dist/src/cli/ndjsonSafeStringify.js +8 -0
- package/dist/src/cli/print.js +3112 -0
- package/dist/src/cli/remoteIO.js +161 -0
- package/dist/src/cli/structuredIO.js +489 -0
- package/dist/src/cli/transports/HybridTransport.js +145 -0
- package/dist/src/cli/transports/SSETransport.js +403 -0
- package/dist/src/cli/transports/SerialBatchEventUploader.js +154 -0
- package/dist/src/cli/transports/WebSocketTransport.js +497 -0
- package/dist/src/cli/transports/WorkerStateUploader.js +69 -0
- package/dist/src/cli/transports/ccrClient.js +522 -0
- package/dist/src/cli/transports/transportUtils.js +25 -0
- package/dist/src/cli/update.js +361 -0
- package/dist/src/commands/add-dir/add-dir.js +140 -0
- package/dist/src/commands/add-dir/index.js +8 -0
- package/dist/src/commands/add-dir/validation.js +67 -0
- package/dist/src/commands/advisor.js +96 -0
- package/dist/src/commands/agents/agents.js +12 -0
- package/dist/src/commands/agents/index.js +7 -0
- package/dist/src/commands/ant-trace/index.js +1 -0
- package/dist/src/commands/autofix-pr/index.js +1 -0
- package/dist/src/commands/backfill-sessions/index.js +1 -0
- package/dist/src/commands/branch/branch.js +168 -0
- package/dist/src/commands/branch/index.js +9 -0
- package/dist/src/commands/break-cache/index.js +1 -0
- package/dist/src/commands/bridge/bridge.js +519 -0
- package/dist/src/commands/bridge/index.js +21 -0
- package/dist/src/commands/bridge-kick.js +145 -0
- package/dist/src/commands/brief.js +66 -0
- package/dist/src/commands/btw/btw.js +281 -0
- package/dist/src/commands/btw/index.js +9 -0
- package/dist/src/commands/bughunter/index.js +1 -0
- package/dist/src/commands/chrome/chrome.js +394 -0
- package/dist/src/commands/chrome/index.js +10 -0
- package/dist/src/commands/clear/caches.js +69 -0
- package/dist/src/commands/clear/clear.js +5 -0
- package/dist/src/commands/clear/conversation.js +156 -0
- package/dist/src/commands/clear/index.js +9 -0
- package/dist/src/commands/color/color.js +57 -0
- package/dist/src/commands/color/index.js +9 -0
- package/dist/src/commands/commit-push-pr.js +145 -0
- package/dist/src/commands/commit.js +83 -0
- package/dist/src/commands/compact/compact.js +161 -0
- package/dist/src/commands/compact/index.js +11 -0
- package/dist/src/commands/config/config.js +9 -0
- package/dist/src/commands/config/index.js +8 -0
- package/dist/src/commands/context/context-noninteractive.js +256 -0
- package/dist/src/commands/context/context.js +33 -0
- package/dist/src/commands/context/index.js +21 -0
- package/dist/src/commands/copy/copy.js +397 -0
- package/dist/src/commands/copy/index.js +7 -0
- package/dist/src/commands/cost/cost.js +21 -0
- package/dist/src/commands/cost/index.js +15 -0
- package/dist/src/commands/createMovedToPluginCommand.js +40 -0
- package/dist/src/commands/ctx_viz/index.js +1 -0
- package/dist/src/commands/debug-tool-call/index.js +1 -0
- package/dist/src/commands/desktop/desktop.js +7 -0
- package/dist/src/commands/desktop/index.js +22 -0
- package/dist/src/commands/diff/diff.js +10 -0
- package/dist/src/commands/diff/index.js +6 -0
- package/dist/src/commands/doctor/doctor.js +7 -0
- package/dist/src/commands/doctor/index.js +9 -0
- package/dist/src/commands/effort/effort.js +181 -0
- package/dist/src/commands/effort/index.js +11 -0
- package/dist/src/commands/env/index.js +1 -0
- package/dist/src/commands/exit/exit.js +25 -0
- package/dist/src/commands/exit/index.js +9 -0
- package/dist/src/commands/export/export.js +79 -0
- package/dist/src/commands/export/index.js +8 -0
- package/dist/src/commands/extra-usage/extra-usage-core.js +85 -0
- package/dist/src/commands/extra-usage/extra-usage-noninteractive.js +11 -0
- package/dist/src/commands/extra-usage/extra-usage.js +17 -0
- package/dist/src/commands/extra-usage/index.js +27 -0
- package/dist/src/commands/fast/fast.js +345 -0
- package/dist/src/commands/fast/index.js +23 -0
- package/dist/src/commands/feedback/feedback.js +15 -0
- package/dist/src/commands/feedback/index.js +13 -0
- package/dist/src/commands/files/files.js +13 -0
- package/dist/src/commands/files/index.js +9 -0
- package/dist/src/commands/good-claude/index.js +1 -0
- package/dist/src/commands/heapdump/heapdump.js +15 -0
- package/dist/src/commands/heapdump/index.js +9 -0
- package/dist/src/commands/help/help.js +12 -0
- package/dist/src/commands/help/index.js +7 -0
- package/dist/src/commands/hooks/hooks.js +14 -0
- package/dist/src/commands/hooks/index.js +8 -0
- package/dist/src/commands/ide/ide.js +702 -0
- package/dist/src/commands/ide/index.js +8 -0
- package/dist/src/commands/init-verifiers.js +258 -0
- package/dist/src/commands/init.js +240 -0
- package/dist/src/commands/insights.js +2212 -0
- package/dist/src/commands/install-github-app/ApiKeyStep.js +290 -0
- package/dist/src/commands/install-github-app/CheckExistingSecretStep.js +265 -0
- package/dist/src/commands/install-github-app/CheckGitHubStep.js +16 -0
- package/dist/src/commands/install-github-app/ChooseRepoStep.js +282 -0
- package/dist/src/commands/install-github-app/CreatingStep.js +87 -0
- package/dist/src/commands/install-github-app/ErrorStep.js +157 -0
- package/dist/src/commands/install-github-app/ExistingWorkflowStep.js +164 -0
- package/dist/src/commands/install-github-app/InstallAppStep.js +166 -0
- package/dist/src/commands/install-github-app/OAuthFlowStep.js +335 -0
- package/dist/src/commands/install-github-app/SuccessStep.js +173 -0
- package/dist/src/commands/install-github-app/WarningsStep.js +140 -0
- package/dist/src/commands/install-github-app/index.js +10 -0
- package/dist/src/commands/install-github-app/install-github-app.js +612 -0
- package/dist/src/commands/install-github-app/setupGitHubActions.js +223 -0
- package/dist/src/commands/install-slack-app/index.js +9 -0
- package/dist/src/commands/install-slack-app/install-slack-app.js +23 -0
- package/dist/src/commands/install.js +348 -0
- package/dist/src/commands/issue/index.js +1 -0
- package/dist/src/commands/keybindings/index.js +10 -0
- package/dist/src/commands/keybindings/keybindings.js +43 -0
- package/dist/src/commands/login/index.js +9 -0
- package/dist/src/commands/login/login.js +105 -0
- package/dist/src/commands/logout/index.js +8 -0
- package/dist/src/commands/logout/logout.js +68 -0
- package/dist/src/commands/mcp/addCommand.js +157 -0
- package/dist/src/commands/mcp/index.js +9 -0
- package/dist/src/commands/mcp/mcp.js +85 -0
- package/dist/src/commands/mcp/xaaIdpCommand.js +135 -0
- package/dist/src/commands/memory/index.js +7 -0
- package/dist/src/commands/memory/memory.js +95 -0
- package/dist/src/commands/mobile/index.js +8 -0
- package/dist/src/commands/mobile/mobile.js +324 -0
- package/dist/src/commands/mock-limits/index.js +1 -0
- package/dist/src/commands/model/index.js +14 -0
- package/dist/src/commands/model/model.js +289 -0
- package/dist/src/commands/oauth-refresh/index.js +1 -0
- package/dist/src/commands/onboarding/index.js +1 -0
- package/dist/src/commands/output-style/index.js +8 -0
- package/dist/src/commands/output-style/output-style.js +5 -0
- package/dist/src/commands/passes/index.js +20 -0
- package/dist/src/commands/passes/passes.js +23 -0
- package/dist/src/commands/perf-issue/index.js +1 -0
- package/dist/src/commands/permissions/index.js +8 -0
- package/dist/src/commands/permissions/permissions.js +11 -0
- package/dist/src/commands/plan/index.js +8 -0
- package/dist/src/commands/plan/plan.js +151 -0
- package/dist/src/commands/plugin/AddMarketplace.js +202 -0
- package/dist/src/commands/plugin/BrowseMarketplace.js +918 -0
- package/dist/src/commands/plugin/DiscoverPlugins.js +935 -0
- package/dist/src/commands/plugin/ManageMarketplaces.js +1018 -0
- package/dist/src/commands/plugin/ManagePlugins.js +2230 -0
- package/dist/src/commands/plugin/PluginErrors.js +118 -0
- package/dist/src/commands/plugin/PluginOptionsDialog.js +396 -0
- package/dist/src/commands/plugin/PluginOptionsFlow.js +80 -0
- package/dist/src/commands/plugin/PluginSettings.js +1313 -0
- package/dist/src/commands/plugin/PluginTrustWarning.js +50 -0
- package/dist/src/commands/plugin/UnifiedInstalledCell.js +749 -0
- package/dist/src/commands/plugin/ValidatePlugin.js +113 -0
- package/dist/src/commands/plugin/index.js +9 -0
- package/dist/src/commands/plugin/parseArgs.js +61 -0
- package/dist/src/commands/plugin/plugin.js +8 -0
- package/dist/src/commands/plugin/pluginDetailsHelpers.js +114 -0
- package/dist/src/commands/plugin/usePagination.js +75 -0
- package/dist/src/commands/pr_comments/index.js +49 -0
- package/dist/src/commands/privacy-settings/index.js +11 -0
- package/dist/src/commands/privacy-settings/privacy-settings.js +58 -0
- package/dist/src/commands/rate-limit-options/index.js +15 -0
- package/dist/src/commands/rate-limit-options/rate-limit-options.js +211 -0
- package/dist/src/commands/release-notes/index.js +8 -0
- package/dist/src/commands/release-notes/release-notes.js +38 -0
- package/dist/src/commands/reload-plugins/index.js +8 -0
- package/dist/src/commands/reload-plugins/reload-plugins.js +27 -0
- package/dist/src/commands/remote-env/index.js +12 -0
- package/dist/src/commands/remote-env/remote-env.js +7 -0
- package/dist/src/commands/remote-setup/api.js +121 -0
- package/dist/src/commands/remote-setup/index.js +14 -0
- package/dist/src/commands/remote-setup/remote-setup.js +173 -0
- package/dist/src/commands/rename/generateSessionName.js +51 -0
- package/dist/src/commands/rename/index.js +9 -0
- package/dist/src/commands/rename/rename.js +52 -0
- package/dist/src/commands/reset-limits/index.js +4 -0
- package/dist/src/commands/resume/index.js +9 -0
- package/dist/src/commands/resume/resume.js +281 -0
- package/dist/src/commands/review/UltrareviewOverageDialog.js +112 -0
- package/dist/src/commands/review/reviewRemote.js +193 -0
- package/dist/src/commands/review/ultrareviewCommand.js +50 -0
- package/dist/src/commands/review/ultrareviewEnabled.js +5 -0
- package/dist/src/commands/review.js +45 -0
- package/dist/src/commands/rewind/index.js +10 -0
- package/dist/src/commands/rewind/rewind.js +6 -0
- package/dist/src/commands/sandbox-toggle/index.js +35 -0
- package/dist/src/commands/sandbox-toggle/sandbox-toggle.js +61 -0
- package/dist/src/commands/security-review.js +228 -0
- package/dist/src/commands/session/index.js +13 -0
- package/dist/src/commands/session/session.js +185 -0
- package/dist/src/commands/share/index.js +1 -0
- package/dist/src/commands/skills/index.js +7 -0
- package/dist/src/commands/skills/skills.js +8 -0
- package/dist/src/commands/stats/index.js +7 -0
- package/dist/src/commands/stats/stats.js +7 -0
- package/dist/src/commands/status/index.js +8 -0
- package/dist/src/commands/status/status.js +9 -0
- package/dist/src/commands/statusline.js +20 -0
- package/dist/src/commands/stickers/index.js +8 -0
- package/dist/src/commands/stickers/stickers.js +13 -0
- package/dist/src/commands/summary/index.js +1 -0
- package/dist/src/commands/tag/index.js +9 -0
- package/dist/src/commands/tag/tag.js +250 -0
- package/dist/src/commands/tasks/index.js +8 -0
- package/dist/src/commands/tasks/tasks.js +8 -0
- package/dist/src/commands/teleport/index.js +1 -0
- package/dist/src/commands/terminalSetup/index.js +15 -0
- package/dist/src/commands/terminalSetup/terminalSetup.js +425 -0
- package/dist/src/commands/theme/index.js +7 -0
- package/dist/src/commands/theme/theme.js +58 -0
- package/dist/src/commands/thinkback/index.js +9 -0
- package/dist/src/commands/thinkback/thinkback.js +569 -0
- package/dist/src/commands/thinkback-play/index.js +11 -0
- package/dist/src/commands/thinkback-play/thinkback-play.js +31 -0
- package/dist/src/commands/ultraplan.js +361 -0
- package/dist/src/commands/upgrade/index.js +11 -0
- package/dist/src/commands/upgrade/upgrade.js +37 -0
- package/dist/src/commands/usage/index.js +7 -0
- package/dist/src/commands/usage/usage.js +9 -0
- package/dist/src/commands/version.js +15 -0
- package/dist/src/commands/vim/index.js +8 -0
- package/dist/src/commands/vim/vim.js +24 -0
- package/dist/src/commands/voice/index.js +17 -0
- package/dist/src/commands/voice/voice.js +117 -0
- package/dist/src/commands.js +476 -0
- package/dist/src/components/AgentProgressLine.js +202 -0
- package/dist/src/components/App.js +53 -0
- package/dist/src/components/ApproveApiKey.js +156 -0
- package/dist/src/components/AutoModeOptInDialog.js +154 -0
- package/dist/src/components/AutoUpdater.js +178 -0
- package/dist/src/components/AutoUpdaterWrapper.js +91 -0
- package/dist/src/components/AwsAuthStatusBox.js +119 -0
- package/dist/src/components/BaseTextInput.js +158 -0
- package/dist/src/components/BashModeProgress.js +65 -0
- package/dist/src/components/BridgeDialog.js +460 -0
- package/dist/src/components/BypassPermissionsModeDialog.js +111 -0
- package/dist/src/components/ChannelDowngradeDialog.js +114 -0
- package/dist/src/components/ClaudeCodeHint/PluginHintMenu.js +120 -0
- package/dist/src/components/ClaudeInChromeOnboarding.js +176 -0
- package/dist/src/components/ClaudeMdExternalIncludesDialog.js +172 -0
- package/dist/src/components/ClickableImageRef.js +74 -0
- package/dist/src/components/CompactSummary.js +220 -0
- package/dist/src/components/ConfigurableShortcutHint.js +33 -0
- package/dist/src/components/ConsoleOAuthFlow.js +841 -0
- package/dist/src/components/ContextSuggestions.js +85 -0
- package/dist/src/components/ContextVisualization.js +878 -0
- package/dist/src/components/CoordinatorAgentStatus.js +304 -0
- package/dist/src/components/CostThresholdDialog.js +66 -0
- package/dist/src/components/CtrlOToExpand.js +56 -0
- package/dist/src/components/CustomSelect/SelectMulti.js +246 -0
- package/dist/src/components/CustomSelect/index.js +2 -0
- package/dist/src/components/CustomSelect/option-map.js +32 -0
- package/dist/src/components/CustomSelect/select-input-option.js +558 -0
- package/dist/src/components/CustomSelect/select-option.js +39 -0
- package/dist/src/components/CustomSelect/select.js +803 -0
- package/dist/src/components/CustomSelect/use-multi-select-state.js +175 -0
- package/dist/src/components/CustomSelect/use-select-input.js +163 -0
- package/dist/src/components/CustomSelect/use-select-navigation.js +334 -0
- package/dist/src/components/CustomSelect/use-select-state.js +30 -0
- package/dist/src/components/DesktopHandoff.js +214 -0
- package/dist/src/components/DesktopUpsell/DesktopUpsellStartup.js +185 -0
- package/dist/src/components/DevBar.js +53 -0
- package/dist/src/components/DevChannelsDialog.js +128 -0
- package/dist/src/components/DiagnosticsDisplay.js +149 -0
- package/dist/src/components/EffortCallout.js +302 -0
- package/dist/src/components/EffortIndicator.js +30 -0
- package/dist/src/components/ExitFlow.js +45 -0
- package/dist/src/components/ExportDialog.js +160 -0
- package/dist/src/components/FallbackToolUseErrorMessage.js +149 -0
- package/dist/src/components/FallbackToolUseRejectedMessage.js +18 -0
- package/dist/src/components/FastIcon.js +49 -0
- package/dist/src/components/Feedback.js +589 -0
- package/dist/src/components/FeedbackSurvey/FeedbackSurvey.js +219 -0
- package/dist/src/components/FeedbackSurvey/FeedbackSurveyView.js +168 -0
- package/dist/src/components/FeedbackSurvey/TranscriptSharePrompt.js +147 -0
- package/dist/src/components/FeedbackSurvey/submitTranscriptShare.js +70 -0
- package/dist/src/components/FeedbackSurvey/useDebouncedDigitInput.js +45 -0
- package/dist/src/components/FeedbackSurvey/useFeedbackSurvey.js +242 -0
- package/dist/src/components/FeedbackSurvey/useMemorySurvey.js +188 -0
- package/dist/src/components/FeedbackSurvey/usePostCompactSurvey.js +200 -0
- package/dist/src/components/FeedbackSurvey/useSurveyState.js +81 -0
- package/dist/src/components/FileEditToolDiff.js +193 -0
- package/dist/src/components/FileEditToolUpdatedMessage.js +162 -0
- package/dist/src/components/FileEditToolUseRejectedMessage.js +215 -0
- package/dist/src/components/FilePathLink.js +33 -0
- package/dist/src/components/FullscreenLayout.js +592 -0
- package/dist/src/components/GlobalSearchDialog.js +371 -0
- package/dist/src/components/HelpV2/Commands.js +99 -0
- package/dist/src/components/HelpV2/General.js +48 -0
- package/dist/src/components/HelpV2/HelpV2.js +231 -0
- package/dist/src/components/HighlightedCode/Fallback.js +200 -0
- package/dist/src/components/HighlightedCode.js +219 -0
- package/dist/src/components/HistorySearchDialog.js +144 -0
- package/dist/src/components/IdeAutoConnectDialog.js +172 -0
- package/dist/src/components/IdeOnboardingDialog.js +249 -0
- package/dist/src/components/IdeStatusIndicator.js +68 -0
- package/dist/src/components/IdleReturnDialog.js +126 -0
- package/dist/src/components/InterruptedByUser.js +25 -0
- package/dist/src/components/InvalidConfigDialog.js +173 -0
- package/dist/src/components/InvalidSettingsDialog.js +94 -0
- package/dist/src/components/KeybindingWarnings.js +144 -0
- package/dist/src/components/LanguagePicker.js +112 -0
- package/dist/src/components/LogSelector.js +1775 -0
- package/dist/src/components/LogoV2/AnimatedAsterisk.js +49 -0
- package/dist/src/components/LogoV2/AnimatedClawd.js +105 -0
- package/dist/src/components/LogoV2/ChannelsNotice.js +334 -0
- package/dist/src/components/LogoV2/Clawd.js +285 -0
- package/dist/src/components/LogoV2/CondensedLogo.js +218 -0
- package/dist/src/components/LogoV2/EmergencyTip.js +47 -0
- package/dist/src/components/LogoV2/Feed.js +140 -0
- package/dist/src/components/LogoV2/FeedColumn.js +67 -0
- package/dist/src/components/LogoV2/GuestPassesUpsell.js +90 -0
- package/dist/src/components/LogoV2/LogoV2.js +774 -0
- package/dist/src/components/LogoV2/Opus1mMergeNotice.js +68 -0
- package/dist/src/components/LogoV2/OverageCreditUpsell.js +154 -0
- package/dist/src/components/LogoV2/VoiceModeNotice.js +75 -0
- package/dist/src/components/LogoV2/WelcomeV2.js +976 -0
- package/dist/src/components/LogoV2/feedConfigs.js +89 -0
- package/dist/src/components/LspRecommendation/LspRecommendationMenu.js +128 -0
- package/dist/src/components/MCPServerApprovalDialog.js +121 -0
- package/dist/src/components/MCPServerDesktopImportDialog.js +249 -0
- package/dist/src/components/MCPServerDialogCopy.js +24 -0
- package/dist/src/components/MCPServerMultiselectDialog.js +173 -0
- package/dist/src/components/ManagedSettingsSecurityDialog/ManagedSettingsSecurityDialog.js +199 -0
- package/dist/src/components/ManagedSettingsSecurityDialog/utils.js +75 -0
- package/dist/src/components/Markdown.js +200 -0
- package/dist/src/components/MarkdownTable.js +215 -0
- package/dist/src/components/MemoryUsageIndicator.js +33 -0
- package/dist/src/components/Message.js +638 -0
- package/dist/src/components/MessageModel.js +43 -0
- package/dist/src/components/MessageResponse.js +99 -0
- package/dist/src/components/MessageRow.js +350 -0
- package/dist/src/components/MessageSelector.js +1021 -0
- package/dist/src/components/MessageTimestamp.js +63 -0
- package/dist/src/components/Messages.js +576 -0
- package/dist/src/components/ModelPicker.js +582 -0
- package/dist/src/components/NativeAutoUpdater.js +169 -0
- package/dist/src/components/NotebookEditToolUseRejectedMessage.js +123 -0
- package/dist/src/components/OffscreenFreeze.js +21 -0
- package/dist/src/components/Onboarding.js +307 -0
- package/dist/src/components/OutputStylePicker.js +128 -0
- package/dist/src/components/PackageManagerAutoUpdater.js +116 -0
- package/dist/src/components/Passes/Passes.js +242 -0
- package/dist/src/components/PrBadge.js +119 -0
- package/dist/src/components/PressEnterToContinue.js +24 -0
- package/dist/src/components/PromptInput/HistorySearchInput.js +64 -0
- package/dist/src/components/PromptInput/IssueFlagBanner.js +6 -0
- package/dist/src/components/PromptInput/Notifications.js +343 -0
- package/dist/src/components/PromptInput/PromptInput.js +1837 -0
- package/dist/src/components/PromptInput/PromptInputFooter.js +192 -0
- package/dist/src/components/PromptInput/PromptInputFooterLeftSide.js +504 -0
- package/dist/src/components/PromptInput/PromptInputFooterSuggestions.js +296 -0
- package/dist/src/components/PromptInput/PromptInputHelpMenu.js +508 -0
- package/dist/src/components/PromptInput/PromptInputModeIndicator.js +92 -0
- package/dist/src/components/PromptInput/PromptInputQueuedCommands.js +90 -0
- package/dist/src/components/PromptInput/PromptInputStashNotice.js +30 -0
- package/dist/src/components/PromptInput/SandboxPromptFooterHint.js +80 -0
- package/dist/src/components/PromptInput/ShimmeredInput.js +157 -0
- package/dist/src/components/PromptInput/VoiceIndicator.js +138 -0
- package/dist/src/components/PromptInput/inputModes.js +24 -0
- package/dist/src/components/PromptInput/inputPaste.js +46 -0
- package/dist/src/components/PromptInput/useMaybeTruncateInput.js +36 -0
- package/dist/src/components/PromptInput/usePromptInputPlaceholder.js +39 -0
- package/dist/src/components/PromptInput/useShowFastIconHint.js +19 -0
- package/dist/src/components/PromptInput/useSwarmBanner.js +99 -0
- package/dist/src/components/PromptInput/utils.js +25 -0
- package/dist/src/components/QuickOpenDialog.js +272 -0
- package/dist/src/components/RemoteCallout.js +81 -0
- package/dist/src/components/RemoteEnvironmentDialog.js +451 -0
- package/dist/src/components/ResumeTask.js +361 -0
- package/dist/src/components/SandboxViolationExpandedView.js +134 -0
- package/dist/src/components/ScrollKeybindingHandler.js +589 -0
- package/dist/src/components/SearchBox.js +111 -0
- package/dist/src/components/SentryErrorBoundary.js +17 -0
- package/dist/src/components/SessionBackgroundHint.js +103 -0
- package/dist/src/components/SessionPreview.js +263 -0
- package/dist/src/components/Settings/Config.js +1776 -0
- package/dist/src/components/Settings/Settings.js +159 -0
- package/dist/src/components/Settings/Status.js +315 -0
- package/dist/src/components/Settings/Usage.js +503 -0
- package/dist/src/components/ShowInIDEPrompt.js +212 -0
- package/dist/src/components/SkillImprovementSurvey.js +204 -0
- package/dist/src/components/Spinner/FlashingChar.js +60 -0
- package/dist/src/components/Spinner/GlimmerMessage.js +391 -0
- package/dist/src/components/Spinner/ShimmerChar.js +30 -0
- package/dist/src/components/Spinner/SpinnerAnimationRow.js +248 -0
- package/dist/src/components/Spinner/SpinnerGlyph.js +105 -0
- package/dist/src/components/Spinner/TeammateSpinnerLine.js +243 -0
- package/dist/src/components/Spinner/TeammateSpinnerTree.js +360 -0
- package/dist/src/components/Spinner/index.js +7 -0
- package/dist/src/components/Spinner/teammateSelectHint.js +1 -0
- package/dist/src/components/Spinner/useShimmerAnimation.js +17 -0
- package/dist/src/components/Spinner/useStalledAnimation.js +47 -0
- package/dist/src/components/Spinner/utils.js +65 -0
- package/dist/src/components/Spinner.js +596 -0
- package/dist/src/components/Stats.js +1415 -0
- package/dist/src/components/StatusLine.js +264 -0
- package/dist/src/components/StatusNotices.js +50 -0
- package/dist/src/components/StructuredDiff/Fallback.js +379 -0
- package/dist/src/components/StructuredDiff/colorDiff.js +21 -0
- package/dist/src/components/StructuredDiff.js +170 -0
- package/dist/src/components/StructuredDiffList.js +30 -0
- package/dist/src/components/TagTabs.js +124 -0
- package/dist/src/components/TaskListV2.js +430 -0
- package/dist/src/components/TeammateViewHeader.js +112 -0
- package/dist/src/components/TeleportError.js +200 -0
- package/dist/src/components/TeleportProgress.js +175 -0
- package/dist/src/components/TeleportRepoMismatchDialog.js +160 -0
- package/dist/src/components/TeleportResumeWrapper.js +207 -0
- package/dist/src/components/TeleportStash.js +159 -0
- package/dist/src/components/TextInput.js +94 -0
- package/dist/src/components/ThemePicker.js +428 -0
- package/dist/src/components/ThinkingToggle.js +233 -0
- package/dist/src/components/TokenWarning.js +165 -0
- package/dist/src/components/ToolUseLoader.js +44 -0
- package/dist/src/components/TrustDialog/TrustDialog.js +337 -0
- package/dist/src/components/TrustDialog/utils.js +149 -0
- package/dist/src/components/ValidationErrorsList.js +169 -0
- package/dist/src/components/VimTextInput.js +142 -0
- package/dist/src/components/VirtualMessageList.js +745 -0
- package/dist/src/components/WorkflowMultiselectDialog.js +173 -0
- package/dist/src/components/WorktreeExitDialog.js +228 -0
- package/dist/src/components/agents/AgentDetail.js +371 -0
- package/dist/src/components/agents/AgentEditor.js +191 -0
- package/dist/src/components/agents/AgentNavigationFooter.js +28 -0
- package/dist/src/components/agents/AgentsList.js +623 -0
- package/dist/src/components/agents/AgentsMenu.js +897 -0
- package/dist/src/components/agents/ColorPicker.js +170 -0
- package/dist/src/components/agents/ModelSelector.js +79 -0
- package/dist/src/components/agents/ToolSelector.js +581 -0
- package/dist/src/components/agents/agentFileUtils.js +142 -0
- package/dist/src/components/agents/generateAgent.js +160 -0
- package/dist/src/components/agents/new-agent-creation/CreateAgentWizard.js +101 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/ColorStep.js +108 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/ConfirmStep.js +551 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/ConfirmStepWrapper.js +73 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/DescriptionStep.js +176 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/GenerateStep.js +176 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/LocationStep.js +104 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/MemoryStep.js +136 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/MethodStep.js +105 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/ModelStep.js +75 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/PromptStep.js +185 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/ToolsStep.js +81 -0
- package/dist/src/components/agents/new-agent-creation/wizard-steps/TypeStep.js +146 -0
- package/dist/src/components/agents/types.js +4 -0
- package/dist/src/components/agents/utils.js +14 -0
- package/dist/src/components/agents/validateAgent.js +66 -0
- package/dist/src/components/design-system/Byline.js +53 -0
- package/dist/src/components/design-system/Dialog.js +171 -0
- package/dist/src/components/design-system/Divider.js +107 -0
- package/dist/src/components/design-system/FuzzyPicker.js +316 -0
- package/dist/src/components/design-system/KeyboardShortcutHint.js +63 -0
- package/dist/src/components/design-system/ListItem.js +186 -0
- package/dist/src/components/design-system/LoadingState.js +72 -0
- package/dist/src/components/design-system/Pane.js +67 -0
- package/dist/src/components/design-system/ProgressBar.js +67 -0
- package/dist/src/components/design-system/Ratchet.js +83 -0
- package/dist/src/components/design-system/StatusIcon.js +60 -0
- package/dist/src/components/design-system/Tabs.js +332 -0
- package/dist/src/components/design-system/ThemeProvider.js +117 -0
- package/dist/src/components/design-system/ThemedBox.js +123 -0
- package/dist/src/components/design-system/ThemedText.js +68 -0
- package/dist/src/components/design-system/color.js +13 -0
- package/dist/src/components/diff/DiffDetailView.js +388 -0
- package/dist/src/components/diff/DiffDialog.js +489 -0
- package/dist/src/components/diff/DiffFileList.js +359 -0
- package/dist/src/components/grove/Grove.js +710 -0
- package/dist/src/components/hooks/HooksConfigMenu.js +626 -0
- package/dist/src/components/hooks/PromptDialog.js +96 -0
- package/dist/src/components/hooks/SelectEventMode.js +169 -0
- package/dist/src/components/hooks/SelectHookMode.js +127 -0
- package/dist/src/components/hooks/SelectMatcherMode.js +156 -0
- package/dist/src/components/hooks/ViewHookMode.js +275 -0
- package/dist/src/components/mcp/CapabilitiesSection.js +68 -0
- package/dist/src/components/mcp/ElicitationDialog.js +1330 -0
- package/dist/src/components/mcp/MCPAgentServerMenu.js +275 -0
- package/dist/src/components/mcp/MCPListPanel.js +671 -0
- package/dist/src/components/mcp/MCPReconnect.js +210 -0
- package/dist/src/components/mcp/MCPRemoteServerMenu.js +906 -0
- package/dist/src/components/mcp/MCPSettings.js +415 -0
- package/dist/src/components/mcp/MCPStdioServerMenu.js +276 -0
- package/dist/src/components/mcp/MCPToolDetailView.js +316 -0
- package/dist/src/components/mcp/MCPToolListView.js +169 -0
- package/dist/src/components/mcp/McpParsingWarnings.js +319 -0
- package/dist/src/components/mcp/index.js +8 -0
- package/dist/src/components/mcp/utils/reconnectHelpers.js +28 -0
- package/dist/src/components/memory/MemoryFileSelector.js +459 -0
- package/dist/src/components/memory/MemoryUpdateNotification.js +51 -0
- package/dist/src/components/messageActions.js +464 -0
- package/dist/src/components/messages/AdvisorMessage.js +202 -0
- package/dist/src/components/messages/AssistantRedactedThinkingMessage.js +34 -0
- package/dist/src/components/messages/AssistantTextMessage.js +373 -0
- package/dist/src/components/messages/AssistantThinkingMessage.js +105 -0
- package/dist/src/components/messages/AssistantToolUseMessage.js +414 -0
- package/dist/src/components/messages/AttachmentMessage.js +764 -0
- package/dist/src/components/messages/CollapsedReadSearchContent.js +651 -0
- package/dist/src/components/messages/CompactBoundaryMessage.js +27 -0
- package/dist/src/components/messages/GroupedToolUseContent.js +42 -0
- package/dist/src/components/messages/HighlightedThinkingText.js +215 -0
- package/dist/src/components/messages/HookProgressMessage.js +150 -0
- package/dist/src/components/messages/PlanApprovalMessage.js +294 -0
- package/dist/src/components/messages/RateLimitMessage.js +164 -0
- package/dist/src/components/messages/ShutdownMessage.js +180 -0
- package/dist/src/components/messages/SystemAPIErrorMessage.js +162 -0
- package/dist/src/components/messages/SystemTextMessage.js +1145 -0
- package/dist/src/components/messages/TaskAssignmentMessage.js +100 -0
- package/dist/src/components/messages/UserAgentNotificationMessage.js +89 -0
- package/dist/src/components/messages/UserBashInputMessage.js +67 -0
- package/dist/src/components/messages/UserBashOutputMessage.js +56 -0
- package/dist/src/components/messages/UserChannelMessage.js +145 -0
- package/dist/src/components/messages/UserCommandMessage.js +146 -0
- package/dist/src/components/messages/UserImageMessage.js +59 -0
- package/dist/src/components/messages/UserLocalCommandOutputMessage.js +226 -0
- package/dist/src/components/messages/UserMemoryInputMessage.js +101 -0
- package/dist/src/components/messages/UserPlanMessage.js +56 -0
- package/dist/src/components/messages/UserPromptMessage.js +54 -0
- package/dist/src/components/messages/UserResourceUpdateMessage.js +131 -0
- package/dist/src/components/messages/UserTeammateMessage.js +215 -0
- package/dist/src/components/messages/UserTextMessage.js +207 -0
- package/dist/src/components/messages/UserToolResultMessage/RejectedPlanMessage.js +46 -0
- package/dist/src/components/messages/UserToolResultMessage/RejectedToolUseMessage.js +21 -0
- package/dist/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.js +18 -0
- package/dist/src/components/messages/UserToolResultMessage/UserToolErrorMessage.js +90 -0
- package/dist/src/components/messages/UserToolResultMessage/UserToolRejectMessage.js +80 -0
- package/dist/src/components/messages/UserToolResultMessage/UserToolResultMessage.js +116 -0
- package/dist/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.js +73 -0
- package/dist/src/components/messages/UserToolResultMessage/utils.js +41 -0
- package/dist/src/components/messages/nullRenderingAttachments.js +40 -0
- package/dist/src/components/messages/teamMemCollapsed.js +160 -0
- package/dist/src/components/messages/teamMemSaved.js +9 -0
- package/dist/src/components/permissions/AskUserQuestionPermissionRequest/AskUserQuestionPermissionRequest.js +696 -0
- package/dist/src/components/permissions/AskUserQuestionPermissionRequest/PreviewBox.js +263 -0
- package/dist/src/components/permissions/AskUserQuestionPermissionRequest/PreviewQuestionView.js +384 -0
- package/dist/src/components/permissions/AskUserQuestionPermissionRequest/QuestionNavigationBar.js +228 -0
- package/dist/src/components/permissions/AskUserQuestionPermissionRequest/QuestionView.js +611 -0
- package/dist/src/components/permissions/AskUserQuestionPermissionRequest/SubmitQuestionsView.js +218 -0
- package/dist/src/components/permissions/AskUserQuestionPermissionRequest/use-multiple-choice-state.js +98 -0
- package/dist/src/components/permissions/BashPermissionRequest/BashPermissionRequest.js +458 -0
- package/dist/src/components/permissions/BashPermissionRequest/bashToolUseOptions.js +90 -0
- package/dist/src/components/permissions/ComputerUseApproval/ComputerUseApproval.js +567 -0
- package/dist/src/components/permissions/EnterPlanModePermissionRequest/EnterPlanModePermissionRequest.js +175 -0
- package/dist/src/components/permissions/ExitPlanModePermissionRequest/ExitPlanModePermissionRequest.js +728 -0
- package/dist/src/components/permissions/FallbackPermissionRequest.js +385 -0
- package/dist/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js +205 -0
- package/dist/src/components/permissions/FilePermissionDialog/FilePermissionDialog.js +188 -0
- package/dist/src/components/permissions/FilePermissionDialog/ideDiffConfig.js +13 -0
- package/dist/src/components/permissions/FilePermissionDialog/permissionOptions.js +159 -0
- package/dist/src/components/permissions/FilePermissionDialog/useFilePermissionDialog.js +129 -0
- package/dist/src/components/permissions/FilePermissionDialog/usePermissionHandler.js +100 -0
- package/dist/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js +186 -0
- package/dist/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js +110 -0
- package/dist/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js +143 -0
- package/dist/src/components/permissions/NotebookEditPermissionRequest/NotebookEditPermissionRequest.js +194 -0
- package/dist/src/components/permissions/NotebookEditPermissionRequest/NotebookEditToolDiff.js +278 -0
- package/dist/src/components/permissions/PermissionDecisionDebugInfo.js +709 -0
- package/dist/src/components/permissions/PermissionDialog.js +90 -0
- package/dist/src/components/permissions/PermissionExplanation.js +298 -0
- package/dist/src/components/permissions/PermissionPrompt.js +327 -0
- package/dist/src/components/permissions/PermissionRequest.js +164 -0
- package/dist/src/components/permissions/PermissionRequestTitle.js +85 -0
- package/dist/src/components/permissions/PermissionRuleExplanation.js +112 -0
- package/dist/src/components/permissions/PowerShellPermissionRequest/PowerShellPermissionRequest.js +263 -0
- package/dist/src/components/permissions/PowerShellPermissionRequest/powershellToolUseOptions.js +70 -0
- package/dist/src/components/permissions/SandboxPermissionRequest.js +205 -0
- package/dist/src/components/permissions/SedEditPermissionRequest/SedEditPermissionRequest.js +259 -0
- package/dist/src/components/permissions/SkillPermissionRequest/SkillPermissionRequest.js +424 -0
- package/dist/src/components/permissions/WebFetchPermissionRequest/WebFetchPermissionRequest.js +299 -0
- package/dist/src/components/permissions/WorkerBadge.js +56 -0
- package/dist/src/components/permissions/WorkerPendingPermission.js +158 -0
- package/dist/src/components/permissions/hooks.js +128 -0
- package/dist/src/components/permissions/rules/AddPermissionRules.js +203 -0
- package/dist/src/components/permissions/rules/AddWorkspaceDirectory.js +437 -0
- package/dist/src/components/permissions/rules/PermissionRuleDescription.js +101 -0
- package/dist/src/components/permissions/rules/PermissionRuleInput.js +208 -0
- package/dist/src/components/permissions/rules/PermissionRuleList.js +1382 -0
- package/dist/src/components/permissions/rules/RecentDenialsTab.js +229 -0
- package/dist/src/components/permissions/rules/RemoveWorkspaceDirectory.js +123 -0
- package/dist/src/components/permissions/rules/WorkspaceTab.js +161 -0
- package/dist/src/components/permissions/shellPermissionHelpers.js +219 -0
- package/dist/src/components/permissions/useShellPermissionFeedback.js +98 -0
- package/dist/src/components/permissions/utils.js +18 -0
- package/dist/src/components/sandbox/SandboxConfigTab.js +195 -0
- package/dist/src/components/sandbox/SandboxDependenciesTab.js +265 -0
- package/dist/src/components/sandbox/SandboxDoctorSection.js +80 -0
- package/dist/src/components/sandbox/SandboxOverridesTab.js +272 -0
- package/dist/src/components/sandbox/SandboxSettings.js +374 -0
- package/dist/src/components/shell/ExpandShellOutputContext.js +25 -0
- package/dist/src/components/shell/OutputLine.js +107 -0
- package/dist/src/components/shell/ShellProgressMessage.js +189 -0
- package/dist/src/components/shell/ShellTimeDisplay.js +78 -0
- package/dist/src/components/skills/SkillsMenu.js +310 -0
- package/dist/src/components/tasks/AsyncAgentDetailDialog.js +353 -0
- package/dist/src/components/tasks/BackgroundTask.js +428 -0
- package/dist/src/components/tasks/BackgroundTaskStatus.js +522 -0
- package/dist/src/components/tasks/BackgroundTasksDialog.js +784 -0
- package/dist/src/components/tasks/DreamDetailDialog.js +353 -0
- package/dist/src/components/tasks/InProcessTeammateDetailDialog.js +393 -0
- package/dist/src/components/tasks/RemoteSessionDetailDialog.js +1188 -0
- package/dist/src/components/tasks/RemoteSessionProgress.js +310 -0
- package/dist/src/components/tasks/ShellDetailDialog.js +511 -0
- package/dist/src/components/tasks/ShellProgress.js +93 -0
- package/dist/src/components/tasks/renderToolActivity.js +34 -0
- package/dist/src/components/tasks/taskStatusUtils.js +77 -0
- package/dist/src/components/teams/TeamStatus.js +95 -0
- package/dist/src/components/teams/TeamsDialog.js +734 -0
- package/dist/src/components/ui/OrderedList.js +74 -0
- package/dist/src/components/ui/OrderedListItem.js +53 -0
- package/dist/src/components/ui/TreeSelect.js +307 -0
- package/dist/src/components/wizard/WizardDialogLayout.js +71 -0
- package/dist/src/components/wizard/WizardNavigationFooter.js +36 -0
- package/dist/src/components/wizard/WizardProvider.js +211 -0
- package/dist/src/components/wizard/index.js +4 -0
- package/dist/src/components/wizard/useWizard.js +9 -0
- package/dist/src/constants/apiLimits.js +11 -0
- package/dist/src/constants/betas.js +28 -0
- package/dist/src/constants/common.js +16 -0
- package/dist/src/constants/cyberRiskInstruction.js +1 -0
- package/dist/src/constants/errorIds.js +1 -0
- package/dist/src/constants/figures.js +31 -0
- package/dist/src/constants/files.js +115 -0
- package/dist/src/constants/github-app.js +139 -0
- package/dist/src/constants/keys.js +4 -0
- package/dist/src/constants/messages.js +1 -0
- package/dist/src/constants/oauth.js +141 -0
- package/dist/src/constants/outputStyles.js +155 -0
- package/dist/src/constants/product.js +25 -0
- package/dist/src/constants/prompts.js +544 -0
- package/dist/src/constants/spinnerVerbs.js +201 -0
- package/dist/src/constants/system.js +46 -0
- package/dist/src/constants/systemPromptSections.js +27 -0
- package/dist/src/constants/toolLimits.js +6 -0
- package/dist/src/constants/tools.js +75 -0
- package/dist/src/constants/turnCompletionVerbs.js +10 -0
- package/dist/src/constants/xml.js +54 -0
- package/dist/src/context/QueuedMessageContext.js +57 -0
- package/dist/src/context/fpsMetrics.js +26 -0
- package/dist/src/context/mailbox.js +37 -0
- package/dist/src/context/modalContext.js +26 -0
- package/dist/src/context/notifications.js +176 -0
- package/dist/src/context/overlayContext.js +92 -0
- package/dist/src/context/promptOverlayContext.js +99 -0
- package/dist/src/context/stats.js +203 -0
- package/dist/src/context/voice.js +62 -0
- package/dist/src/context.js +119 -0
- package/dist/src/coordinator/coordinatorMode.js +323 -0
- package/dist/src/cost-tracker.js +234 -0
- package/dist/src/costHook.js +19 -0
- package/dist/src/dialogLaunchers.js +92 -0
- package/dist/src/entrypoints/agentSdkTypes.js +51 -0
- package/dist/src/entrypoints/cli.js +92 -0
- package/dist/src/entrypoints/init.js +199 -0
- package/dist/src/entrypoints/mcp.js +132 -0
- package/dist/src/entrypoints/npm-bin.js +6 -0
- package/dist/src/entrypoints/sandboxTypes.js +34 -0
- package/dist/src/entrypoints/sdk/controlSchemas.js +347 -0
- package/dist/src/entrypoints/sdk/coreSchemas.js +1019 -0
- package/dist/src/entrypoints/sdk/coreTypes.generated.js +1 -0
- package/dist/src/entrypoints/sdk/coreTypes.js +38 -0
- package/dist/src/entrypoints/sdk/runtimeTypes.js +1 -0
- package/dist/src/entrypoints/sdk/settingsTypes.generated.js +1 -0
- package/dist/src/entrypoints/sdk/toolTypes.js +1 -0
- package/dist/src/history.js +297 -0
- package/dist/src/hooks/fileSuggestions.js +460 -0
- package/dist/src/hooks/notifs/useAutoModeUnavailableNotification.js +39 -0
- package/dist/src/hooks/notifs/useCanSwitchToExistingSubscription.js +64 -0
- package/dist/src/hooks/notifs/useDeprecationWarningNotification.js +43 -0
- package/dist/src/hooks/notifs/useFastModeNotification.js +161 -0
- package/dist/src/hooks/notifs/useIDEStatusIndicator.js +187 -0
- package/dist/src/hooks/notifs/useInstallMessages.js +25 -0
- package/dist/src/hooks/notifs/useLspInitializationNotification.js +147 -0
- package/dist/src/hooks/notifs/useMcpConnectivityStatus.js +154 -0
- package/dist/src/hooks/notifs/useModelMigrationNotifications.js +45 -0
- package/dist/src/hooks/notifs/useNpmDeprecationNotification.js +24 -0
- package/dist/src/hooks/notifs/usePluginAutoupdateNotification.js +93 -0
- package/dist/src/hooks/notifs/usePluginInstallationStatus.js +143 -0
- package/dist/src/hooks/notifs/useRateLimitWarningNotification.js +118 -0
- package/dist/src/hooks/notifs/useSettingsErrors.js +67 -0
- package/dist/src/hooks/notifs/useStartupNotification.js +24 -0
- package/dist/src/hooks/notifs/useTeammateShutdownNotification.js +61 -0
- package/dist/src/hooks/renderPlaceholder.js +27 -0
- package/dist/src/hooks/toolPermission/PermissionContext.js +186 -0
- package/dist/src/hooks/toolPermission/handlers/coordinatorHandler.js +22 -0
- package/dist/src/hooks/toolPermission/handlers/interactiveHandler.js +194 -0
- package/dist/src/hooks/toolPermission/handlers/swarmWorkerHandler.js +79 -0
- package/dist/src/hooks/toolPermission/permissionLogging.js +114 -0
- package/dist/src/hooks/unifiedSuggestions.js +115 -0
- package/dist/src/hooks/useAfterFirstRender.js +12 -0
- package/dist/src/hooks/useApiKeyVerification.js +58 -0
- package/dist/src/hooks/useArrowKeyHistory.js +176 -0
- package/dist/src/hooks/useAssistantHistory.js +150 -0
- package/dist/src/hooks/useAwaySummary.js +95 -0
- package/dist/src/hooks/useBackgroundTaskNavigation.js +163 -0
- package/dist/src/hooks/useBlink.js +10 -0
- package/dist/src/hooks/useCanUseTool.js +144 -0
- package/dist/src/hooks/useCancelRequest.js +165 -0
- package/dist/src/hooks/useChromeExtensionNotification.js +55 -0
- package/dist/src/hooks/useClaudeCodeHintRecommendation.js +113 -0
- package/dist/src/hooks/useClipboardImageHint.js +45 -0
- package/dist/src/hooks/useCommandKeybindings.js +81 -0
- package/dist/src/hooks/useCommandQueue.js +8 -0
- package/dist/src/hooks/useCopyOnSelect.js +44 -0
- package/dist/src/hooks/useDeferredHookMessages.js +35 -0
- package/dist/src/hooks/useDiffData.js +62 -0
- package/dist/src/hooks/useDiffInIDE.js +197 -0
- package/dist/src/hooks/useDirectConnect.js +154 -0
- package/dist/src/hooks/useDoublePress.js +36 -0
- package/dist/src/hooks/useDynamicConfig.js +10 -0
- package/dist/src/hooks/useElapsedTime.js +12 -0
- package/dist/src/hooks/useExitOnCtrlCD.js +27 -0
- package/dist/src/hooks/useExitOnCtrlCDWithKeybindings.js +5 -0
- package/dist/src/hooks/useFileHistorySnapshotInit.js +17 -0
- package/dist/src/hooks/useGlobalKeybindings.js +132 -0
- package/dist/src/hooks/useHistorySearch.js +219 -0
- package/dist/src/hooks/useIDEIntegration.js +60 -0
- package/dist/src/hooks/useIdeAtMentioned.js +42 -0
- package/dist/src/hooks/useIdeConnectionStatus.js +18 -0
- package/dist/src/hooks/useIdeLogging.js +26 -0
- package/dist/src/hooks/useIdeSelection.js +78 -0
- package/dist/src/hooks/useInboxPoller.js +626 -0
- package/dist/src/hooks/useInputBuffer.js +69 -0
- package/dist/src/hooks/useIssueFlagBanner.js +101 -0
- package/dist/src/hooks/useLogMessages.js +47 -0
- package/dist/src/hooks/useLspPluginRecommendation.js +163 -0
- package/dist/src/hooks/useMailboxBridge.js +15 -0
- package/dist/src/hooks/useMainLoopModel.js +15 -0
- package/dist/src/hooks/useManagePlugins.js +195 -0
- package/dist/src/hooks/useMemoryUsage.js +17 -0
- package/dist/src/hooks/useMergedClients.js +11 -0
- package/dist/src/hooks/useMergedCommands.js +10 -0
- package/dist/src/hooks/useMergedTools.js +18 -0
- package/dist/src/hooks/useMinDisplayTime.js +19 -0
- package/dist/src/hooks/useNotifyAfterTimeout.js +34 -0
- package/dist/src/hooks/useOfficialMarketplaceNotification.js +50 -0
- package/dist/src/hooks/usePasteHandler.js +129 -0
- package/dist/src/hooks/usePluginRecommendationBase.js +98 -0
- package/dist/src/hooks/usePrStatus.js +77 -0
- package/dist/src/hooks/usePromptSuggestion.js +124 -0
- package/dist/src/hooks/usePromptsFromClaudeInChrome.js +60 -0
- package/dist/src/hooks/useQueueProcessor.js +29 -0
- package/dist/src/hooks/useRemoteSession.js +313 -0
- package/dist/src/hooks/useReplBridge.js +59 -0
- package/dist/src/hooks/useSSHSession.js +161 -0
- package/dist/src/hooks/useScheduledTasks.js +68 -0
- package/dist/src/hooks/useSearchInput.js +285 -0
- package/dist/src/hooks/useSessionBackgrounding.js +120 -0
- package/dist/src/hooks/useSettings.js +4 -0
- package/dist/src/hooks/useSettingsChange.js +10 -0
- package/dist/src/hooks/useSkillImprovementSurvey.js +61 -0
- package/dist/src/hooks/useSkillsChange.js +39 -0
- package/dist/src/hooks/useSwarmInitialization.js +39 -0
- package/dist/src/hooks/useSwarmPermissionPoller.js +141 -0
- package/dist/src/hooks/useTaskListWatcher.js +124 -0
- package/dist/src/hooks/useTasksV2.js +161 -0
- package/dist/src/hooks/useTeammateViewAutoExit.js +35 -0
- package/dist/src/hooks/useTeleportResume.js +75 -0
- package/dist/src/hooks/useTerminalSize.js +11 -0
- package/dist/src/hooks/useTextInput.js +353 -0
- package/dist/src/hooks/useTimeout.js +10 -0
- package/dist/src/hooks/useTurnDiffs.js +131 -0
- package/dist/src/hooks/useTypeahead.js +993 -0
- package/dist/src/hooks/useUpdateNotification.js +21 -0
- package/dist/src/hooks/useVimInput.js +210 -0
- package/dist/src/hooks/useVirtualScroll.js +282 -0
- package/dist/src/hooks/useVoice.js +675 -0
- package/dist/src/hooks/useVoiceEnabled.js +12 -0
- package/dist/src/hooks/useVoiceIntegration.js +391 -0
- package/dist/src/ink/Ansi.js +290 -0
- package/dist/src/ink/bidi.js +72 -0
- package/dist/src/ink/clearTerminal.js +42 -0
- package/dist/src/ink/colorize.js +119 -0
- package/dist/src/ink/components/AlternateScreen.js +60 -0
- package/dist/src/ink/components/App.js +375 -0
- package/dist/src/ink/components/AppContext.js +6 -0
- package/dist/src/ink/components/Box.js +181 -0
- package/dist/src/ink/components/Button.js +167 -0
- package/dist/src/ink/components/ClockContext.js +100 -0
- package/dist/src/ink/components/CursorDeclarationContext.js +3 -0
- package/dist/src/ink/components/ErrorOverview.js +152 -0
- package/dist/src/ink/components/Link.js +42 -0
- package/dist/src/ink/components/Newline.js +29 -0
- package/dist/src/ink/components/NoSelect.js +40 -0
- package/dist/src/ink/components/RawAnsi.js +36 -0
- package/dist/src/ink/components/ScrollBox.js +139 -0
- package/dist/src/ink/components/Spacer.js +16 -0
- package/dist/src/ink/components/StdinContext.js +12 -0
- package/dist/src/ink/components/TerminalFocusContext.js +43 -0
- package/dist/src/ink/components/TerminalSizeContext.js +2 -0
- package/dist/src/ink/components/Text.js +196 -0
- package/dist/src/ink/constants.js +1 -0
- package/dist/src/ink/dom.js +230 -0
- package/dist/src/ink/events/click-event.js +15 -0
- package/dist/src/ink/events/dispatcher.js +126 -0
- package/dist/src/ink/events/emitter.js +26 -0
- package/dist/src/ink/events/event-handlers.js +22 -0
- package/dist/src/ink/events/event.js +9 -0
- package/dist/src/ink/events/focus-event.js +9 -0
- package/dist/src/ink/events/input-event.js +83 -0
- package/dist/src/ink/events/keyboard-event.js +31 -0
- package/dist/src/ink/events/terminal-event.js +60 -0
- package/dist/src/ink/events/terminal-focus-event.js +9 -0
- package/dist/src/ink/focus.js +127 -0
- package/dist/src/ink/frame.js +22 -0
- package/dist/src/ink/get-max-width.js +5 -0
- package/dist/src/ink/hit-test.js +76 -0
- package/dist/src/ink/hooks/use-animation-frame.js +23 -0
- package/dist/src/ink/hooks/use-app.js +4 -0
- package/dist/src/ink/hooks/use-declared-cursor.js +27 -0
- package/dist/src/ink/hooks/use-input.js +31 -0
- package/dist/src/ink/hooks/use-interval.js +38 -0
- package/dist/src/ink/hooks/use-search-highlight.js +21 -0
- package/dist/src/ink/hooks/use-selection.js +47 -0
- package/dist/src/ink/hooks/use-stdin.js +4 -0
- package/dist/src/ink/hooks/use-tab-status.js +48 -0
- package/dist/src/ink/hooks/use-terminal-focus.js +6 -0
- package/dist/src/ink/hooks/use-terminal-title.js +17 -0
- package/dist/src/ink/hooks/use-terminal-viewport.js +40 -0
- package/dist/src/ink/ink.js +978 -0
- package/dist/src/ink/instances.js +2 -0
- package/dist/src/ink/layout/engine.js +4 -0
- package/dist/src/ink/layout/geometry.js +55 -0
- package/dist/src/ink/layout/node.js +60 -0
- package/dist/src/ink/layout/yoga.js +232 -0
- package/dist/src/ink/line-width-cache.js +14 -0
- package/dist/src/ink/log-update.js +408 -0
- package/dist/src/ink/measure-element.js +5 -0
- package/dist/src/ink/measure-text.js +30 -0
- package/dist/src/ink/node-cache.js +19 -0
- package/dist/src/ink/optimizer.js +52 -0
- package/dist/src/ink/output.js +399 -0
- package/dist/src/ink/parse-keypress.js +525 -0
- package/dist/src/ink/reconciler.js +359 -0
- package/dist/src/ink/render-border.js +110 -0
- package/dist/src/ink/render-node-to-output.js +710 -0
- package/dist/src/ink/render-to-screen.js +124 -0
- package/dist/src/ink/renderer.js +73 -0
- package/dist/src/ink/root.js +73 -0
- package/dist/src/ink/screen.js +823 -0
- package/dist/src/ink/searchHighlight.js +48 -0
- package/dist/src/ink/selection.js +507 -0
- package/dist/src/ink/squash-text-nodes.js +40 -0
- package/dist/src/ink/stringWidth.js +134 -0
- package/dist/src/ink/styles.js +279 -0
- package/dist/src/ink/supports-hyperlinks.js +29 -0
- package/dist/src/ink/tabstops.js +35 -0
- package/dist/src/ink/terminal-focus-state.js +33 -0
- package/dist/src/ink/terminal-querier.js +89 -0
- package/dist/src/ink/terminal.js +128 -0
- package/dist/src/ink/termio/ansi.js +53 -0
- package/dist/src/ink/termio/csi.js +158 -0
- package/dist/src/ink/termio/dec.js +31 -0
- package/dist/src/ink/termio/esc.js +36 -0
- package/dist/src/ink/termio/osc.js +275 -0
- package/dist/src/ink/termio/parser.js +293 -0
- package/dist/src/ink/termio/sgr.js +264 -0
- package/dist/src/ink/termio/tokenize.js +176 -0
- package/dist/src/ink/termio/types.js +33 -0
- package/dist/src/ink/termio.js +2 -0
- package/dist/src/ink/useTerminalNotification.js +61 -0
- package/dist/src/ink/warn.js +10 -0
- package/dist/src/ink/widest-line.js +15 -0
- package/dist/src/ink/wrap-text.js +50 -0
- package/dist/src/ink/wrapAnsi.js +5 -0
- package/dist/src/ink.js +55 -0
- package/dist/src/interactiveHelpers.js +231 -0
- package/dist/src/keybindings/KeybindingContext.js +170 -0
- package/dist/src/keybindings/KeybindingProviderSetup.js +225 -0
- package/dist/src/keybindings/defaultBindings.js +228 -0
- package/dist/src/keybindings/loadUserBindings.js +276 -0
- package/dist/src/keybindings/match.js +73 -0
- package/dist/src/keybindings/parser.js +152 -0
- package/dist/src/keybindings/reservedShortcuts.js +82 -0
- package/dist/src/keybindings/resolver.js +116 -0
- package/dist/src/keybindings/schema.js +143 -0
- package/dist/src/keybindings/shortcutFormat.js +24 -0
- package/dist/src/keybindings/template.js +28 -0
- package/dist/src/keybindings/useKeybinding.js +100 -0
- package/dist/src/keybindings/useShortcutDisplay.js +24 -0
- package/dist/src/keybindings/validate.js +313 -0
- package/dist/src/localRecoveryCli.js +256 -0
- package/dist/src/main.js +2489 -0
- package/dist/src/memdir/findRelevantMemories.js +76 -0
- package/dist/src/memdir/memdir.js +264 -0
- package/dist/src/memdir/memoryAge.js +24 -0
- package/dist/src/memdir/memoryScan.js +36 -0
- package/dist/src/memdir/memoryTypes.js +190 -0
- package/dist/src/memdir/paths.js +106 -0
- package/dist/src/memdir/teamMemPaths.js +133 -0
- package/dist/src/memdir/teamMemPrompts.js +87 -0
- package/dist/src/migrations/migrateAutoUpdatesToSettings.js +41 -0
- package/dist/src/migrations/migrateBypassPermissionsAcceptedToSettings.js +29 -0
- package/dist/src/migrations/migrateEnableAllProjectMcpServersToSettings.js +70 -0
- package/dist/src/migrations/migrateFennecToOpus.js +27 -0
- package/dist/src/migrations/migrateLegacyOpusToCurrent.js +30 -0
- package/dist/src/migrations/migrateOpusToOpus1m.js +23 -0
- package/dist/src/migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.js +13 -0
- package/dist/src/migrations/migrateSonnet1mToSonnet45.js +29 -0
- package/dist/src/migrations/migrateSonnet45ToSonnet46.js +41 -0
- package/dist/src/migrations/resetAutoModeOptInForDefaultOffer.js +11 -0
- package/dist/src/migrations/resetProToOpusDefault.js +42 -0
- package/dist/src/moreright/useMoreRight.js +7 -0
- package/dist/src/native-ts/color-diff/index.js +729 -0
- package/dist/src/native-ts/file-index/index.js +246 -0
- package/dist/src/native-ts/yoga-layout/enums.js +96 -0
- package/dist/src/native-ts/yoga-layout/index.js +1638 -0
- package/dist/src/outputStyles/loadOutputStylesDir.js +47 -0
- package/dist/src/plugins/builtinPlugins.js +86 -0
- package/dist/src/plugins/bundled/index.js +1 -0
- package/dist/src/projectOnboardingState.js +56 -0
- package/dist/src/query/config.js +14 -0
- package/dist/src/query/deps.js +12 -0
- package/dist/src/query/stopHooks.js +251 -0
- package/dist/src/query/tokenBudget.js +47 -0
- package/dist/src/query.js +813 -0
- package/dist/src/remote/RemoteSessionManager.js +144 -0
- package/dist/src/remote/SessionsWebSocket.js +231 -0
- package/dist/src/remote/remotePermissionBridge.js +57 -0
- package/dist/src/remote/sdkMessageAdapter.js +161 -0
- package/dist/src/replLauncher.js +15 -0
- package/dist/src/schemas/hooks.js +71 -0
- package/dist/src/screens/Doctor.js +988 -0
- package/dist/src/screens/REPL.js +3588 -0
- package/dist/src/screens/ResumeConversation.js +396 -0
- package/dist/src/server/createDirectConnectSession.js +55 -0
- package/dist/src/server/directConnectManager.js +131 -0
- package/dist/src/server/types.js +7 -0
- package/dist/src/services/AgentSummary/agentSummary.js +114 -0
- package/dist/src/services/MagicDocs/magicDocs.js +151 -0
- package/dist/src/services/MagicDocs/prompts.js +85 -0
- package/dist/src/services/PromptSuggestion/promptSuggestion.js +350 -0
- package/dist/src/services/PromptSuggestion/speculation.js +590 -0
- package/dist/src/services/SessionMemory/prompts.js +220 -0
- package/dist/src/services/SessionMemory/sessionMemory.js +277 -0
- package/dist/src/services/SessionMemory/sessionMemoryUtils.js +94 -0
- package/dist/src/services/analytics/config.js +8 -0
- package/dist/src/services/analytics/datadog.js +217 -0
- package/dist/src/services/analytics/firstPartyEventLogger.js +223 -0
- package/dist/src/services/analytics/firstPartyEventLoggingExporter.js +500 -0
- package/dist/src/services/analytics/growthbook.js +597 -0
- package/dist/src/services/analytics/index.js +56 -0
- package/dist/src/services/analytics/metadata.js +507 -0
- package/dist/src/services/analytics/sink.js +44 -0
- package/dist/src/services/analytics/sinkKillswitch.js +6 -0
- package/dist/src/services/api/adminRequests.js +40 -0
- package/dist/src/services/api/bootstrap.js +104 -0
- package/dist/src/services/api/claude.js +1851 -0
- package/dist/src/services/api/client.js +209 -0
- package/dist/src/services/api/dumpPrompts.js +145 -0
- package/dist/src/services/api/emptyUsage.js +15 -0
- package/dist/src/services/api/errorUtils.js +137 -0
- package/dist/src/services/api/errors.js +641 -0
- package/dist/src/services/api/filesApi.js +409 -0
- package/dist/src/services/api/firstTokenDate.js +42 -0
- package/dist/src/services/api/grove.js +222 -0
- package/dist/src/services/api/logging.js +478 -0
- package/dist/src/services/api/metricsOptOut.js +87 -0
- package/dist/src/services/api/overageCreditGrant.js +83 -0
- package/dist/src/services/api/promptCacheBreakDetection.js +411 -0
- package/dist/src/services/api/referral.js +178 -0
- package/dist/src/services/api/sessionIngress.js +264 -0
- package/dist/src/services/api/ultrareviewQuota.js +23 -0
- package/dist/src/services/api/usage.js +34 -0
- package/dist/src/services/api/withRetry.js +454 -0
- package/dist/src/services/autoDream/autoDream.js +197 -0
- package/dist/src/services/autoDream/config.js +9 -0
- package/dist/src/services/autoDream/consolidationLock.js +76 -0
- package/dist/src/services/autoDream/consolidationPrompt.js +61 -0
- package/dist/src/services/awaySummary.js +58 -0
- package/dist/src/services/claudeAiLimits.js +269 -0
- package/dist/src/services/claudeAiLimitsHook.js +18 -0
- package/dist/src/services/compact/apiMicrocompact.js +82 -0
- package/dist/src/services/compact/autoCompact.js +151 -0
- package/dist/src/services/compact/compact.js +957 -0
- package/dist/src/services/compact/compactWarningHook.js +5 -0
- package/dist/src/services/compact/compactWarningState.js +8 -0
- package/dist/src/services/compact/grouping.js +20 -0
- package/dist/src/services/compact/microCompact.js +265 -0
- package/dist/src/services/compact/postCompactCleanup.js +23 -0
- package/dist/src/services/compact/prompt.js +303 -0
- package/dist/src/services/compact/sessionMemoryCompact.js +316 -0
- package/dist/src/services/compact/timeBasedMCConfig.js +9 -0
- package/dist/src/services/diagnosticTracking.js +195 -0
- package/dist/src/services/extractMemories/extractMemories.js +309 -0
- package/dist/src/services/extractMemories/prompts.js +113 -0
- package/dist/src/services/internalLogging.js +53 -0
- package/dist/src/services/lsp/LSPClient.js +252 -0
- package/dist/src/services/lsp/LSPDiagnosticRegistry.js +179 -0
- package/dist/src/services/lsp/LSPServerInstance.js +245 -0
- package/dist/src/services/lsp/LSPServerManager.js +217 -0
- package/dist/src/services/lsp/config.js +38 -0
- package/dist/src/services/lsp/manager.js +132 -0
- package/dist/src/services/lsp/passiveFeedback.js +150 -0
- package/dist/src/services/mcp/InProcessTransport.js +37 -0
- package/dist/src/services/mcp/MCPConnectionManager.js +56 -0
- package/dist/src/services/mcp/SdkControlTransport.js +54 -0
- package/dist/src/services/mcp/auth.js +1419 -0
- package/dist/src/services/mcp/channelAllowlist.js +24 -0
- package/dist/src/services/mcp/channelNotification.js +118 -0
- package/dist/src/services/mcp/channelPermissions.js +89 -0
- package/dist/src/services/mcp/claudeai.js +95 -0
- package/dist/src/services/mcp/client.js +1896 -0
- package/dist/src/services/mcp/config.js +942 -0
- package/dist/src/services/mcp/elicitationHandler.js +171 -0
- package/dist/src/services/mcp/envExpansion.js +19 -0
- package/dist/src/services/mcp/headersHelper.js +64 -0
- package/dist/src/services/mcp/mcpStringUtils.js +33 -0
- package/dist/src/services/mcp/normalization.js +8 -0
- package/dist/src/services/mcp/oauthPort.js +47 -0
- package/dist/src/services/mcp/officialRegistry.js +42 -0
- package/dist/src/services/mcp/types.js +82 -0
- package/dist/src/services/mcp/useManageMCPConnections.js +536 -0
- package/dist/src/services/mcp/utils.js +284 -0
- package/dist/src/services/mcp/vscodeSdkMcp.js +55 -0
- package/dist/src/services/mcp/xaa.js +237 -0
- package/dist/src/services/mcp/xaaIdpLogin.js +286 -0
- package/dist/src/services/mcpServerApproval.js +39 -0
- package/dist/src/services/mockRateLimits.js +548 -0
- package/dist/src/services/notifier.js +112 -0
- package/dist/src/services/oauth/auth-code-listener.js +129 -0
- package/dist/src/services/oauth/client.js +341 -0
- package/dist/src/services/oauth/crypto.js +15 -0
- package/dist/src/services/oauth/getOauthProfile.js +44 -0
- package/dist/src/services/oauth/index.js +98 -0
- package/dist/src/services/plugins/PluginInstallationManager.js +111 -0
- package/dist/src/services/plugins/pluginCliCommands.js +173 -0
- package/dist/src/services/plugins/pluginOperations.js +597 -0
- package/dist/src/services/policyLimits/index.js +418 -0
- package/dist/src/services/policyLimits/types.js +5 -0
- package/dist/src/services/preventSleep.js +95 -0
- package/dist/src/services/rateLimitMessages.js +194 -0
- package/dist/src/services/rateLimitMocking.js +58 -0
- package/dist/src/services/remoteManagedSettings/index.js +368 -0
- package/dist/src/services/remoteManagedSettings/securityCheck.js +52 -0
- package/dist/src/services/remoteManagedSettings/syncCache.js +50 -0
- package/dist/src/services/remoteManagedSettings/syncCacheState.js +48 -0
- package/dist/src/services/remoteManagedSettings/types.js +7 -0
- package/dist/src/services/settingsSync/index.js +368 -0
- package/dist/src/services/settingsSync/types.js +18 -0
- package/dist/src/services/teamMemorySync/index.js +731 -0
- package/dist/src/services/teamMemorySync/secretScanner.js +210 -0
- package/dist/src/services/teamMemorySync/teamMemSecretGuard.js +4 -0
- package/dist/src/services/teamMemorySync/types.js +23 -0
- package/dist/src/services/teamMemorySync/watcher.js +197 -0
- package/dist/src/services/tips/tipHistory.js +17 -0
- package/dist/src/services/tips/tipRegistry.js +578 -0
- package/dist/src/services/tips/tipScheduler.js +37 -0
- package/dist/src/services/tokenEstimation.js +283 -0
- package/dist/src/services/toolUseSummary/toolUseSummaryGenerator.js +75 -0
- package/dist/src/services/tools/StreamingToolExecutor.js +311 -0
- package/dist/src/services/tools/toolExecution.js +1009 -0
- package/dist/src/services/tools/toolHooks.js +384 -0
- package/dist/src/services/tools/toolOrchestration.js +96 -0
- package/dist/src/services/vcr.js +233 -0
- package/dist/src/services/voice.js +315 -0
- package/dist/src/services/voiceKeyterms.js +57 -0
- package/dist/src/services/voiceStreamSTT.js +265 -0
- package/dist/src/setup.js +235 -0
- package/dist/src/skills/bundled/batch.js +114 -0
- package/dist/src/skills/bundled/claudeApi.js +149 -0
- package/dist/src/skills/bundled/claudeApiContent.js +63 -0
- package/dist/src/skills/bundled/claudeInChrome.js +31 -0
- package/dist/src/skills/bundled/debug.js +89 -0
- package/dist/src/skills/bundled/index.js +22 -0
- package/dist/src/skills/bundled/keybindings.js +303 -0
- package/dist/src/skills/bundled/loop.js +86 -0
- package/dist/src/skills/bundled/loremIpsum.js +257 -0
- package/dist/src/skills/bundled/remember.js +78 -0
- package/dist/src/skills/bundled/scheduleRemoteAgents.js +360 -0
- package/dist/src/skills/bundled/simplify.js +70 -0
- package/dist/src/skills/bundled/skillify.js +179 -0
- package/dist/src/skills/bundled/stuck.js +76 -0
- package/dist/src/skills/bundled/updateConfig.js +471 -0
- package/dist/src/skills/bundled/verify/SKILL.md.js +1 -0
- package/dist/src/skills/bundled/verify/examples/cli.md.js +1 -0
- package/dist/src/skills/bundled/verify/examples/server.md.js +1 -0
- package/dist/src/skills/bundled/verify.js +27 -0
- package/dist/src/skills/bundled/verifyContent.js +8 -0
- package/dist/src/skills/bundledSkills.js +114 -0
- package/dist/src/skills/loadSkillsDir.js +583 -0
- package/dist/src/skills/mcpSkillBuilders.js +10 -0
- package/dist/src/state/AppState.js +153 -0
- package/dist/src/state/AppStateStore.js +115 -0
- package/dist/src/state/onChangeAppState.js +94 -0
- package/dist/src/state/selectors.js +29 -0
- package/dist/src/state/store.js +21 -0
- package/dist/src/state/teammateViewHelpers.js +89 -0
- package/dist/src/tasks/DreamTask/DreamTask.js +79 -0
- package/dist/src/tasks/InProcessTeammateTask/InProcessTeammateTask.js +70 -0
- package/dist/src/tasks/InProcessTeammateTask/types.js +15 -0
- package/dist/src/tasks/LocalAgentTask/LocalAgentTask.js +444 -0
- package/dist/src/tasks/LocalMainSessionTask.js +262 -0
- package/dist/src/tasks/LocalShellTask/LocalShellTask.js +419 -0
- package/dist/src/tasks/LocalShellTask/guards.js +3 -0
- package/dist/src/tasks/LocalShellTask/killShellTasks.js +44 -0
- package/dist/src/tasks/RemoteAgentTask/RemoteAgentTask.js +550 -0
- package/dist/src/tasks/pillLabel.js +53 -0
- package/dist/src/tasks/stopTask.js +53 -0
- package/dist/src/tasks/types.js +9 -0
- package/dist/src/tasks.js +22 -0
- package/dist/src/tools/AgentTool/AgentTool.js +919 -0
- package/dist/src/tools/AgentTool/UI.js +912 -0
- package/dist/src/tools/AgentTool/agentColorManager.js +42 -0
- package/dist/src/tools/AgentTool/agentDisplay.js +45 -0
- package/dist/src/tools/AgentTool/agentMemory.js +85 -0
- package/dist/src/tools/AgentTool/agentMemorySnapshot.js +109 -0
- package/dist/src/tools/AgentTool/agentToolUtils.js +387 -0
- package/dist/src/tools/AgentTool/built-in/claudeCodeGuideAgent.js +159 -0
- package/dist/src/tools/AgentTool/built-in/exploreAgent.js +66 -0
- package/dist/src/tools/AgentTool/built-in/generalPurposeAgent.js +26 -0
- package/dist/src/tools/AgentTool/built-in/planAgent.js +81 -0
- package/dist/src/tools/AgentTool/built-in/statuslineSetup.js +140 -0
- package/dist/src/tools/AgentTool/built-in/verificationAgent.js +146 -0
- package/dist/src/tools/AgentTool/builtInAgents.js +32 -0
- package/dist/src/tools/AgentTool/constants.js +7 -0
- package/dist/src/tools/AgentTool/forkSubagent.js +108 -0
- package/dist/src/tools/AgentTool/loadAgentsDir.js +409 -0
- package/dist/src/tools/AgentTool/prompt.js +194 -0
- package/dist/src/tools/AgentTool/resumeAgent.js +169 -0
- package/dist/src/tools/AgentTool/runAgent.js +457 -0
- package/dist/src/tools/AskUserQuestionTool/AskUserQuestionTool.js +282 -0
- package/dist/src/tools/AskUserQuestionTool/prompt.js +38 -0
- package/dist/src/tools/BashTool/BashTool.js +867 -0
- package/dist/src/tools/BashTool/BashToolResultMessage.js +208 -0
- package/dist/src/tools/BashTool/UI.js +189 -0
- package/dist/src/tools/BashTool/bashCommandHelpers.js +145 -0
- package/dist/src/tools/BashTool/bashPermissions.js +1193 -0
- package/dist/src/tools/BashTool/bashSecurity.js +1464 -0
- package/dist/src/tools/BashTool/commandSemantics.js +70 -0
- package/dist/src/tools/BashTool/commentLabel.js +8 -0
- package/dist/src/tools/BashTool/destructiveCommandWarning.js +74 -0
- package/dist/src/tools/BashTool/modeValidation.js +65 -0
- package/dist/src/tools/BashTool/pathValidation.js +771 -0
- package/dist/src/tools/BashTool/prompt.js +307 -0
- package/dist/src/tools/BashTool/readOnlyValidation.js +1312 -0
- package/dist/src/tools/BashTool/sedEditParser.js +179 -0
- package/dist/src/tools/BashTool/sedValidation.js +379 -0
- package/dist/src/tools/BashTool/shouldUseSandbox.js +102 -0
- package/dist/src/tools/BashTool/toolName.js +1 -0
- package/dist/src/tools/BashTool/utils.js +145 -0
- package/dist/src/tools/BriefTool/BriefTool.js +106 -0
- package/dist/src/tools/BriefTool/UI.js +158 -0
- package/dist/src/tools/BriefTool/attachments.js +54 -0
- package/dist/src/tools/BriefTool/prompt.js +19 -0
- package/dist/src/tools/BriefTool/upload.js +37 -0
- package/dist/src/tools/ConfigTool/ConfigTool.js +304 -0
- package/dist/src/tools/ConfigTool/UI.js +76 -0
- package/dist/src/tools/ConfigTool/constants.js +1 -0
- package/dist/src/tools/ConfigTool/prompt.js +76 -0
- package/dist/src/tools/ConfigTool/supportedSettings.js +141 -0
- package/dist/src/tools/EnterPlanModeTool/EnterPlanModeTool.js +91 -0
- package/dist/src/tools/EnterPlanModeTool/UI.js +49 -0
- package/dist/src/tools/EnterPlanModeTool/constants.js +1 -0
- package/dist/src/tools/EnterPlanModeTool/prompt.js +154 -0
- package/dist/src/tools/EnterWorktreeTool/EnterWorktreeTool.js +97 -0
- package/dist/src/tools/EnterWorktreeTool/UI.js +25 -0
- package/dist/src/tools/EnterWorktreeTool/constants.js +1 -0
- package/dist/src/tools/EnterWorktreeTool/prompt.js +30 -0
- package/dist/src/tools/ExitPlanModeTool/ExitPlanModeV2Tool.js +287 -0
- package/dist/src/tools/ExitPlanModeTool/UI.js +128 -0
- package/dist/src/tools/ExitPlanModeTool/constants.js +2 -0
- package/dist/src/tools/ExitPlanModeTool/prompt.js +25 -0
- package/dist/src/tools/ExitWorktreeTool/ExitWorktreeTool.js +217 -0
- package/dist/src/tools/ExitWorktreeTool/UI.js +36 -0
- package/dist/src/tools/ExitWorktreeTool/constants.js +1 -0
- package/dist/src/tools/ExitWorktreeTool/prompt.js +32 -0
- package/dist/src/tools/FileEditTool/FileEditTool.js +447 -0
- package/dist/src/tools/FileEditTool/UI.js +289 -0
- package/dist/src/tools/FileEditTool/constants.js +4 -0
- package/dist/src/tools/FileEditTool/prompt.js +22 -0
- package/dist/src/tools/FileEditTool/types.js +37 -0
- package/dist/src/tools/FileEditTool/utils.js +411 -0
- package/dist/src/tools/FileReadTool/FileReadTool.js +759 -0
- package/dist/src/tools/FileReadTool/UI.js +232 -0
- package/dist/src/tools/FileReadTool/imageProcessor.js +34 -0
- package/dist/src/tools/FileReadTool/limits.js +28 -0
- package/dist/src/tools/FileReadTool/prompt.js +25 -0
- package/dist/src/tools/FileWriteTool/FileWriteTool.js +300 -0
- package/dist/src/tools/FileWriteTool/UI.js +460 -0
- package/dist/src/tools/FileWriteTool/prompt.js +16 -0
- package/dist/src/tools/GlobTool/GlobTool.js +155 -0
- package/dist/src/tools/GlobTool/UI.js +58 -0
- package/dist/src/tools/GlobTool/prompt.js +6 -0
- package/dist/src/tools/GrepTool/GrepTool.js +390 -0
- package/dist/src/tools/GrepTool/UI.js +254 -0
- package/dist/src/tools/GrepTool/prompt.js +16 -0
- package/dist/src/tools/LSPTool/LSPTool.js +541 -0
- package/dist/src/tools/LSPTool/UI.js +275 -0
- package/dist/src/tools/LSPTool/formatters.js +353 -0
- package/dist/src/tools/LSPTool/prompt.js +20 -0
- package/dist/src/tools/LSPTool/schemas.js +82 -0
- package/dist/src/tools/LSPTool/symbolContext.js +43 -0
- package/dist/src/tools/ListMcpResourcesTool/ListMcpResourcesTool.js +91 -0
- package/dist/src/tools/ListMcpResourcesTool/UI.js +26 -0
- package/dist/src/tools/ListMcpResourcesTool/prompt.js +18 -0
- package/dist/src/tools/MCPTool/MCPTool.js +57 -0
- package/dist/src/tools/MCPTool/UI.js +433 -0
- package/dist/src/tools/MCPTool/classifyForCollapse.js +509 -0
- package/dist/src/tools/MCPTool/prompt.js +2 -0
- package/dist/src/tools/McpAuthTool/McpAuthTool.js +139 -0
- package/dist/src/tools/NotebookEditTool/NotebookEditTool.js +364 -0
- package/dist/src/tools/NotebookEditTool/UI.js +115 -0
- package/dist/src/tools/NotebookEditTool/constants.js +1 -0
- package/dist/src/tools/NotebookEditTool/prompt.js +2 -0
- package/dist/src/tools/PowerShellTool/PowerShellTool.js +700 -0
- package/dist/src/tools/PowerShellTool/UI.js +154 -0
- package/dist/src/tools/PowerShellTool/clmTypes.js +147 -0
- package/dist/src/tools/PowerShellTool/commandSemantics.js +37 -0
- package/dist/src/tools/PowerShellTool/commonParameters.js +17 -0
- package/dist/src/tools/PowerShellTool/destructiveCommandWarning.js +70 -0
- package/dist/src/tools/PowerShellTool/gitSafety.js +102 -0
- package/dist/src/tools/PowerShellTool/modeValidation.js +203 -0
- package/dist/src/tools/PowerShellTool/pathValidation.js +1259 -0
- package/dist/src/tools/PowerShellTool/powershellPermissions.js +791 -0
- package/dist/src/tools/PowerShellTool/powershellSecurity.js +612 -0
- package/dist/src/tools/PowerShellTool/prompt.js +130 -0
- package/dist/src/tools/PowerShellTool/readOnlyValidation.js +1000 -0
- package/dist/src/tools/PowerShellTool/toolName.js +1 -0
- package/dist/src/tools/REPLTool/constants.js +27 -0
- package/dist/src/tools/REPLTool/primitiveTools.js +21 -0
- package/dist/src/tools/ReadMcpResourceTool/ReadMcpResourceTool.js +115 -0
- package/dist/src/tools/ReadMcpResourceTool/UI.js +37 -0
- package/dist/src/tools/ReadMcpResourceTool/prompt.js +15 -0
- package/dist/src/tools/RemoteTriggerTool/RemoteTriggerTool.js +138 -0
- package/dist/src/tools/RemoteTriggerTool/UI.js +28 -0
- package/dist/src/tools/RemoteTriggerTool/prompt.js +12 -0
- package/dist/src/tools/ScheduleCronTool/CronCreateTool.js +117 -0
- package/dist/src/tools/ScheduleCronTool/CronDeleteTool.js +83 -0
- package/dist/src/tools/ScheduleCronTool/CronListTool.js +77 -0
- package/dist/src/tools/ScheduleCronTool/UI.js +73 -0
- package/dist/src/tools/ScheduleCronTool/prompt.js +67 -0
- package/dist/src/tools/SendMessageTool/SendMessageTool.js +561 -0
- package/dist/src/tools/SendMessageTool/UI.js +30 -0
- package/dist/src/tools/SendMessageTool/constants.js +1 -0
- package/dist/src/tools/SendMessageTool/prompt.js +32 -0
- package/dist/src/tools/SkillTool/SkillTool.js +614 -0
- package/dist/src/tools/SkillTool/UI.js +141 -0
- package/dist/src/tools/SkillTool/constants.js +1 -0
- package/dist/src/tools/SkillTool/prompt.js +161 -0
- package/dist/src/tools/SleepTool/prompt.js +14 -0
- package/dist/src/tools/SyntheticOutputTool/SyntheticOutputTool.js +120 -0
- package/dist/src/tools/TaskCreateTool/TaskCreateTool.js +106 -0
- package/dist/src/tools/TaskCreateTool/constants.js +1 -0
- package/dist/src/tools/TaskCreateTool/prompt.js +48 -0
- package/dist/src/tools/TaskGetTool/TaskGetTool.js +110 -0
- package/dist/src/tools/TaskGetTool/constants.js +1 -0
- package/dist/src/tools/TaskGetTool/prompt.js +23 -0
- package/dist/src/tools/TaskListTool/TaskListTool.js +92 -0
- package/dist/src/tools/TaskListTool/constants.js +1 -0
- package/dist/src/tools/TaskListTool/prompt.js +38 -0
- package/dist/src/tools/TaskOutputTool/TaskOutputTool.js +688 -0
- package/dist/src/tools/TaskOutputTool/constants.js +1 -0
- package/dist/src/tools/TaskStopTool/TaskStopTool.js +97 -0
- package/dist/src/tools/TaskStopTool/UI.js +39 -0
- package/dist/src/tools/TaskStopTool/prompt.js +7 -0
- package/dist/src/tools/TaskUpdateTool/TaskUpdateTool.js +279 -0
- package/dist/src/tools/TaskUpdateTool/constants.js +1 -0
- package/dist/src/tools/TaskUpdateTool/prompt.js +76 -0
- package/dist/src/tools/TeamCreateTool/TeamCreateTool.js +161 -0
- package/dist/src/tools/TeamCreateTool/UI.js +4 -0
- package/dist/src/tools/TeamCreateTool/constants.js +1 -0
- package/dist/src/tools/TeamCreateTool/prompt.js +113 -0
- package/dist/src/tools/TeamDeleteTool/TeamDeleteTool.js +96 -0
- package/dist/src/tools/TeamDeleteTool/UI.js +14 -0
- package/dist/src/tools/TeamDeleteTool/constants.js +1 -0
- package/dist/src/tools/TeamDeleteTool/prompt.js +16 -0
- package/dist/src/tools/TodoWriteTool/TodoWriteTool.js +86 -0
- package/dist/src/tools/TodoWriteTool/constants.js +1 -0
- package/dist/src/tools/TodoWriteTool/prompt.js +181 -0
- package/dist/src/tools/ToolSearchTool/ToolSearchTool.js +266 -0
- package/dist/src/tools/ToolSearchTool/constants.js +1 -0
- package/dist/src/tools/ToolSearchTool/prompt.js +40 -0
- package/dist/src/tools/TungstenTool/TungstenLiveMonitor.js +4 -0
- package/dist/src/tools/TungstenTool/TungstenTool.js +39 -0
- package/dist/src/tools/WebFetchTool/UI.js +91 -0
- package/dist/src/tools/WebFetchTool/WebFetchTool.js +234 -0
- package/dist/src/tools/WebFetchTool/preapproved.js +122 -0
- package/dist/src/tools/WebFetchTool/prompt.js +37 -0
- package/dist/src/tools/WebFetchTool/utils.js +303 -0
- package/dist/src/tools/WebSearchTool/UI.js +109 -0
- package/dist/src/tools/WebSearchTool/WebSearchTool.js +313 -0
- package/dist/src/tools/WebSearchTool/prompt.js +32 -0
- package/dist/src/tools/WorkflowTool/constants.js +1 -0
- package/dist/src/tools/shared/gitOperationTracking.js +158 -0
- package/dist/src/tools/shared/spawnMultiAgent.js +630 -0
- package/dist/src/tools/testing/TestingPermissionTool.js +66 -0
- package/dist/src/tools/utils.js +15 -0
- package/dist/src/tools.js +184 -0
- package/dist/src/types/command.js +6 -0
- package/dist/src/types/connectorText.js +3 -0
- package/dist/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.js +525 -0
- package/dist/src/types/generated/events_mono/common/v1/auth.js +38 -0
- package/dist/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.js +112 -0
- package/dist/src/types/generated/google/protobuf/timestamp.js +33 -0
- package/dist/src/types/hooks.js +121 -0
- package/dist/src/types/ids.js +10 -0
- package/dist/src/types/logs.js +9 -0
- package/dist/src/types/permissions.js +12 -0
- package/dist/src/types/plugin.js +64 -0
- package/dist/src/types/textInputTypes.js +10 -0
- package/dist/src/upstreamproxy/relay.js +274 -0
- package/dist/src/upstreamproxy/upstreamproxy.js +161 -0
- package/dist/src/utils/CircularBuffer.js +51 -0
- package/dist/src/utils/Cursor.js +1006 -0
- package/dist/src/utils/QueryGuard.js +57 -0
- package/dist/src/utils/Shell.js +260 -0
- package/dist/src/utils/ShellCommand.js +277 -0
- package/dist/src/utils/abortController.js +31 -0
- package/dist/src/utils/activityManager.js +91 -0
- package/dist/src/utils/advisor.js +63 -0
- package/dist/src/utils/agentContext.js +36 -0
- package/dist/src/utils/agentId.js +36 -0
- package/dist/src/utils/agentSwarmsEnabled.js +17 -0
- package/dist/src/utils/agenticSessionSearch.js +194 -0
- package/dist/src/utils/analyzeContext.js +692 -0
- package/dist/src/utils/ansiToPng.js +211 -0
- package/dist/src/utils/ansiToSvg.js +171 -0
- package/dist/src/utils/api.js +435 -0
- package/dist/src/utils/apiPreconnect.js +19 -0
- package/dist/src/utils/appleTerminalBackup.js +91 -0
- package/dist/src/utils/argumentSubstitution.js +58 -0
- package/dist/src/utils/array.js +12 -0
- package/dist/src/utils/asciicast.js +149 -0
- package/dist/src/utils/attachments.js +1854 -0
- package/dist/src/utils/attribution.js +215 -0
- package/dist/src/utils/auth.js +1197 -0
- package/dist/src/utils/authFileDescriptor.js +106 -0
- package/dist/src/utils/authPortable.js +14 -0
- package/dist/src/utils/autoModeDenials.js +10 -0
- package/dist/src/utils/autoRunIssue.js +126 -0
- package/dist/src/utils/autoUpdater.js +339 -0
- package/dist/src/utils/aws.js +30 -0
- package/dist/src/utils/awsAuthStatusManager.js +55 -0
- package/dist/src/utils/background/remote/preconditions.js +134 -0
- package/dist/src/utils/background/remote/remoteSession.js +42 -0
- package/dist/src/utils/backgroundHousekeeping.js +47 -0
- package/dist/src/utils/bash/ParsedCommand.js +194 -0
- package/dist/src/utils/bash/ShellSnapshot.js +333 -0
- package/dist/src/utils/bash/ast.js +1422 -0
- package/dist/src/utils/bash/bashParser.js +3625 -0
- package/dist/src/utils/bash/bashPipeCommand.js +138 -0
- package/dist/src/utils/bash/commands.js +668 -0
- package/dist/src/utils/bash/heredoc.js +288 -0
- package/dist/src/utils/bash/parser.js +110 -0
- package/dist/src/utils/bash/prefix.js +119 -0
- package/dist/src/utils/bash/registry.js +20 -0
- package/dist/src/utils/bash/shellCompletion.js +127 -0
- package/dist/src/utils/bash/shellPrefix.js +11 -0
- package/dist/src/utils/bash/shellQuote.js +159 -0
- package/dist/src/utils/bash/shellQuoting.js +43 -0
- package/dist/src/utils/bash/specs/alias.js +11 -0
- package/dist/src/utils/bash/specs/index.js +16 -0
- package/dist/src/utils/bash/specs/nohup.js +10 -0
- package/dist/src/utils/bash/specs/pyright.js +88 -0
- package/dist/src/utils/bash/specs/sleep.js +10 -0
- package/dist/src/utils/bash/specs/srun.js +28 -0
- package/dist/src/utils/bash/specs/time.js +10 -0
- package/dist/src/utils/bash/specs/timeout.js +17 -0
- package/dist/src/utils/bash/treeSitterAnalysis.js +259 -0
- package/dist/src/utils/betas.js +199 -0
- package/dist/src/utils/billing.js +47 -0
- package/dist/src/utils/binaryCheck.js +25 -0
- package/dist/src/utils/browser.js +47 -0
- package/dist/src/utils/bufferedWriter.js +73 -0
- package/dist/src/utils/bundledMode.js +6 -0
- package/dist/src/utils/caCerts.js +47 -0
- package/dist/src/utils/caCertsConfig.js +32 -0
- package/dist/src/utils/cachePaths.js +22 -0
- package/dist/src/utils/classifierApprovals.js +61 -0
- package/dist/src/utils/classifierApprovalsHook.js +8 -0
- package/dist/src/utils/claudeCodeHints.js +83 -0
- package/dist/src/utils/claudeDesktop.js +87 -0
- package/dist/src/utils/claudeInChrome/chromeNativeHost.js +353 -0
- package/dist/src/utils/claudeInChrome/common.js +416 -0
- package/dist/src/utils/claudeInChrome/mcpServer.js +190 -0
- package/dist/src/utils/claudeInChrome/prompt.js +60 -0
- package/dist/src/utils/claudeInChrome/setup.js +239 -0
- package/dist/src/utils/claudeInChrome/setupPortable.js +133 -0
- package/dist/src/utils/claudeInChrome/toolRendering.js +224 -0
- package/dist/src/utils/claudemd.js +727 -0
- package/dist/src/utils/cleanup.js +423 -0
- package/dist/src/utils/cleanupRegistry.js +8 -0
- package/dist/src/utils/cliArgs.js +21 -0
- package/dist/src/utils/cliHighlight.js +27 -0
- package/dist/src/utils/codeIndexing.js +92 -0
- package/dist/src/utils/collapseBackgroundBashNotifications.js +58 -0
- package/dist/src/utils/collapseHookSummaries.js +38 -0
- package/dist/src/utils/collapseReadSearch.js +569 -0
- package/dist/src/utils/collapseTeammateShutdowns.js +34 -0
- package/dist/src/utils/combinedAbortSignal.js +28 -0
- package/dist/src/utils/commandLifecycle.js +7 -0
- package/dist/src/utils/commitAttribution.js +510 -0
- package/dist/src/utils/completionCache.js +126 -0
- package/dist/src/utils/computerUse/appNames.js +104 -0
- package/dist/src/utils/computerUse/cleanup.js +37 -0
- package/dist/src/utils/computerUse/common.js +25 -0
- package/dist/src/utils/computerUse/computerUseLock.js +117 -0
- package/dist/src/utils/computerUse/drainRunLoop.js +44 -0
- package/dist/src/utils/computerUse/escHotkey.js +33 -0
- package/dist/src/utils/computerUse/executor.js +303 -0
- package/dist/src/utils/computerUse/gates.js +40 -0
- package/dist/src/utils/computerUse/hostAdapter.js +48 -0
- package/dist/src/utils/computerUse/inputLoader.js +10 -0
- package/dist/src/utils/computerUse/mcpServer.js +61 -0
- package/dist/src/utils/computerUse/setup.js +25 -0
- package/dist/src/utils/computerUse/swiftLoader.js +7 -0
- package/dist/src/utils/computerUse/toolRendering.js +96 -0
- package/dist/src/utils/computerUse/wrapper.js +242 -0
- package/dist/src/utils/concurrentSessions.js +108 -0
- package/dist/src/utils/config.js +801 -0
- package/dist/src/utils/configConstants.js +11 -0
- package/dist/src/utils/contentArray.js +19 -0
- package/dist/src/utils/context.js +135 -0
- package/dist/src/utils/contextAnalysis.js +152 -0
- package/dist/src/utils/contextSuggestions.js +141 -0
- package/dist/src/utils/controlMessageCompat.js +17 -0
- package/dist/src/utils/conversationRecovery.js +278 -0
- package/dist/src/utils/cron.js +182 -0
- package/dist/src/utils/cronJitterConfig.js +22 -0
- package/dist/src/utils/cronScheduler.js +295 -0
- package/dist/src/utils/cronTasks.js +183 -0
- package/dist/src/utils/cronTasksLock.js +116 -0
- package/dist/src/utils/crossProjectResume.js +36 -0
- package/dist/src/utils/crypto.js +3 -0
- package/dist/src/utils/cwd.js +16 -0
- package/dist/src/utils/debug.js +170 -0
- package/dist/src/utils/debugFilter.js +69 -0
- package/dist/src/utils/deepLink/banner.js +52 -0
- package/dist/src/utils/deepLink/parseDeepLink.js +68 -0
- package/dist/src/utils/deepLink/protocolHandler.js +66 -0
- package/dist/src/utils/deepLink/registerProtocol.js +206 -0
- package/dist/src/utils/deepLink/terminalLauncher.js +321 -0
- package/dist/src/utils/deepLink/terminalPreference.js +26 -0
- package/dist/src/utils/desktopDeepLink.js +154 -0
- package/dist/src/utils/detectRepository.js +98 -0
- package/dist/src/utils/diagLogs.js +47 -0
- package/dist/src/utils/diff.js +92 -0
- package/dist/src/utils/directMemberMessage.js +27 -0
- package/dist/src/utils/displayTags.js +12 -0
- package/dist/src/utils/doctorContextWarnings.js +151 -0
- package/dist/src/utils/doctorDiagnostic.js +388 -0
- package/dist/src/utils/dxt/helpers.js +36 -0
- package/dist/src/utils/dxt/zip.js +112 -0
- package/dist/src/utils/earlyInput.js +98 -0
- package/dist/src/utils/editor.js +105 -0
- package/dist/src/utils/effort.js +188 -0
- package/dist/src/utils/embeddedTools.js +10 -0
- package/dist/src/utils/env.js +284 -0
- package/dist/src/utils/envDynamic.js +91 -0
- package/dist/src/utils/envUtils.js +88 -0
- package/dist/src/utils/envValidation.js +26 -0
- package/dist/src/utils/errorLogSink.js +142 -0
- package/dist/src/utils/errors.js +123 -0
- package/dist/src/utils/exampleCommands.js +133 -0
- package/dist/src/utils/execFileNoThrow.js +82 -0
- package/dist/src/utils/execFileNoThrowPortable.js +52 -0
- package/dist/src/utils/execSyncWrapper.js +16 -0
- package/dist/src/utils/exportRenderer.js +78 -0
- package/dist/src/utils/extraUsage.js +16 -0
- package/dist/src/utils/fastMode.js +331 -0
- package/dist/src/utils/file.js +318 -0
- package/dist/src/utils/fileHistory.js +662 -0
- package/dist/src/utils/fileOperationAnalytics.js +23 -0
- package/dist/src/utils/filePersistence/filePersistence.js +165 -0
- package/dist/src/utils/filePersistence/outputsScanner.js +72 -0
- package/dist/src/utils/filePersistence/types.js +3 -0
- package/dist/src/utils/fileRead.js +53 -0
- package/dist/src/utils/fileReadCache.js +54 -0
- package/dist/src/utils/fileStateCache.js +79 -0
- package/dist/src/utils/findExecutable.js +5 -0
- package/dist/src/utils/fingerprint.js +30 -0
- package/dist/src/utils/forkedAgent.js +253 -0
- package/dist/src/utils/format.js +200 -0
- package/dist/src/utils/formatBriefTimestamp.js +49 -0
- package/dist/src/utils/fpsTracker.js +32 -0
- package/dist/src/utils/frontmatterParser.js +159 -0
- package/dist/src/utils/fsOperations.js +548 -0
- package/dist/src/utils/fullscreen.js +83 -0
- package/dist/src/utils/generatedFiles.js +96 -0
- package/dist/src/utils/generators.js +60 -0
- package/dist/src/utils/genericProcessUtils.js +96 -0
- package/dist/src/utils/getWorktreePaths.js +30 -0
- package/dist/src/utils/getWorktreePathsPortable.js +14 -0
- package/dist/src/utils/ghPrStatus.js +51 -0
- package/dist/src/utils/git/gitConfigParser.js +166 -0
- package/dist/src/utils/git/gitFilesystem.js +413 -0
- package/dist/src/utils/git/gitignore.js +52 -0
- package/dist/src/utils/git.js +520 -0
- package/dist/src/utils/gitDiff.js +291 -0
- package/dist/src/utils/gitSettings.js +10 -0
- package/dist/src/utils/github/ghAuthStatus.js +15 -0
- package/dist/src/utils/githubRepoPathMapping.js +92 -0
- package/dist/src/utils/glob.js +65 -0
- package/dist/src/utils/gracefulShutdown.js +274 -0
- package/dist/src/utils/groupToolUses.js +107 -0
- package/dist/src/utils/handlePromptSubmit.js +323 -0
- package/dist/src/utils/hash.js +21 -0
- package/dist/src/utils/headlessProfiler.js +95 -0
- package/dist/src/utils/heapDumpService.js +157 -0
- package/dist/src/utils/heatmap.js +118 -0
- package/dist/src/utils/highlightMatch.js +28 -0
- package/dist/src/utils/hooks/AsyncHookRegistry.js +190 -0
- package/dist/src/utils/hooks/apiQueryHookHelper.js +67 -0
- package/dist/src/utils/hooks/execAgentHook.js +216 -0
- package/dist/src/utils/hooks/execHttpHook.js +106 -0
- package/dist/src/utils/hooks/execPromptHook.js +153 -0
- package/dist/src/utils/hooks/fileChangedWatcher.js +154 -0
- package/dist/src/utils/hooks/hookEvents.js +92 -0
- package/dist/src/utils/hooks/hookHelpers.js +43 -0
- package/dist/src/utils/hooks/hooksConfigManager.js +386 -0
- package/dist/src/utils/hooks/hooksConfigSnapshot.js +52 -0
- package/dist/src/utils/hooks/hooksSettings.js +175 -0
- package/dist/src/utils/hooks/postSamplingHooks.js +26 -0
- package/dist/src/utils/hooks/registerFrontmatterHooks.js +34 -0
- package/dist/src/utils/hooks/registerSkillHooks.js +24 -0
- package/dist/src/utils/hooks/sessionHooks.js +176 -0
- package/dist/src/utils/hooks/skillImprovement.js +200 -0
- package/dist/src/utils/hooks/ssrfGuard.js +157 -0
- package/dist/src/utils/hooks.js +2879 -0
- package/dist/src/utils/horizontalScroll.js +72 -0
- package/dist/src/utils/http.js +80 -0
- package/dist/src/utils/hyperlink.js +13 -0
- package/dist/src/utils/iTermBackup.js +46 -0
- package/dist/src/utils/ide.js +938 -0
- package/dist/src/utils/idePathConversion.js +47 -0
- package/dist/src/utils/idleTimeout.js +33 -0
- package/dist/src/utils/imagePaste.js +190 -0
- package/dist/src/utils/imageResizer.js +459 -0
- package/dist/src/utils/imageStore.js +109 -0
- package/dist/src/utils/imageValidation.js +61 -0
- package/dist/src/utils/immediateCommand.js +4 -0
- package/dist/src/utils/inProcessTeammateHelpers.js +28 -0
- package/dist/src/utils/ink.js +14 -0
- package/dist/src/utils/intl.js +61 -0
- package/dist/src/utils/jetbrains.js +130 -0
- package/dist/src/utils/json.js +182 -0
- package/dist/src/utils/jsonRead.js +4 -0
- package/dist/src/utils/keyboardShortcuts.js +8 -0
- package/dist/src/utils/lazySchema.js +4 -0
- package/dist/src/utils/listSessionsImpl.js +219 -0
- package/dist/src/utils/localInstaller.js +86 -0
- package/dist/src/utils/lockfile.js +19 -0
- package/dist/src/utils/log.js +164 -0
- package/dist/src/utils/logoV2Utils.js +192 -0
- package/dist/src/utils/mailbox.js +51 -0
- package/dist/src/utils/managedEnv.js +90 -0
- package/dist/src/utils/managedEnvConstants.js +136 -0
- package/dist/src/utils/markdown.js +216 -0
- package/dist/src/utils/markdownConfigLoader.js +293 -0
- package/dist/src/utils/mcp/dateTimeParser.js +73 -0
- package/dist/src/utils/mcp/elicitationValidation.js +208 -0
- package/dist/src/utils/mcpInstructionsDelta.js +71 -0
- package/dist/src/utils/mcpOutputStorage.js +124 -0
- package/dist/src/utils/mcpValidation.js +138 -0
- package/dist/src/utils/mcpWebSocketTransport.js +152 -0
- package/dist/src/utils/memoize.js +125 -0
- package/dist/src/utils/memory/types.js +8 -0
- package/dist/src/utils/memory/versions.js +4 -0
- package/dist/src/utils/memoryFileDetection.js +151 -0
- package/dist/src/utils/messagePredicates.js +3 -0
- package/dist/src/utils/messageQueueManager.js +267 -0
- package/dist/src/utils/messages/mappers.js +198 -0
- package/dist/src/utils/messages/systemInit.js +47 -0
- package/dist/src/utils/messages.js +3450 -0
- package/dist/src/utils/model/agent.js +91 -0
- package/dist/src/utils/model/aliases.js +16 -0
- package/dist/src/utils/model/antModels.js +23 -0
- package/dist/src/utils/model/bedrock.js +158 -0
- package/dist/src/utils/model/check1mAccess.js +49 -0
- package/dist/src/utils/model/configs.js +81 -0
- package/dist/src/utils/model/contextWindowUpgradeCheck.js +32 -0
- package/dist/src/utils/model/deprecation.js +56 -0
- package/dist/src/utils/model/model.js +377 -0
- package/dist/src/utils/model/modelAllowlist.js +91 -0
- package/dist/src/utils/model/modelCapabilities.js +97 -0
- package/dist/src/utils/model/modelOptions.js +403 -0
- package/dist/src/utils/model/modelStrings.js +112 -0
- package/dist/src/utils/model/modelSupportOverrides.js +32 -0
- package/dist/src/utils/model/providers.js +23 -0
- package/dist/src/utils/model/validateModel.js +108 -0
- package/dist/src/utils/modelCost.js +135 -0
- package/dist/src/utils/modifiers.js +22 -0
- package/dist/src/utils/mtls.js +101 -0
- package/dist/src/utils/nativeInstaller/download.js +309 -0
- package/dist/src/utils/nativeInstaller/index.js +9 -0
- package/dist/src/utils/nativeInstaller/installer.js +1104 -0
- package/dist/src/utils/nativeInstaller/packageManagers.js +174 -0
- package/dist/src/utils/nativeInstaller/pidLock.js +230 -0
- package/dist/src/utils/notebook.js +170 -0
- package/dist/src/utils/objectGroupBy.js +12 -0
- package/dist/src/utils/pasteStore.js +61 -0
- package/dist/src/utils/path.js +65 -0
- package/dist/src/utils/pdf.js +199 -0
- package/dist/src/utils/pdfUtils.js +36 -0
- package/dist/src/utils/peerAddress.js +9 -0
- package/dist/src/utils/permissions/PermissionMode.js +82 -0
- package/dist/src/utils/permissions/PermissionPromptToolResultSchema.js +62 -0
- package/dist/src/utils/permissions/PermissionResult.js +10 -0
- package/dist/src/utils/permissions/PermissionRule.js +7 -0
- package/dist/src/utils/permissions/PermissionUpdate.js +219 -0
- package/dist/src/utils/permissions/PermissionUpdateSchema.js +49 -0
- package/dist/src/utils/permissions/autoModeState.js +26 -0
- package/dist/src/utils/permissions/bashClassifier.js +29 -0
- package/dist/src/utils/permissions/bypassPermissionsKillswitch.js +69 -0
- package/dist/src/utils/permissions/classifierDecision.js +56 -0
- package/dist/src/utils/permissions/classifierShared.js +14 -0
- package/dist/src/utils/permissions/dangerousPatterns.js +44 -0
- package/dist/src/utils/permissions/denialTracking.js +28 -0
- package/dist/src/utils/permissions/filesystem.js +889 -0
- package/dist/src/utils/permissions/getNextPermissionMode.js +51 -0
- package/dist/src/utils/permissions/pathValidation.js +230 -0
- package/dist/src/utils/permissions/permissionExplainer.js +162 -0
- package/dist/src/utils/permissions/permissionRuleParser.js +90 -0
- package/dist/src/utils/permissions/permissionSetup.js +770 -0
- package/dist/src/utils/permissions/permissions.js +585 -0
- package/dist/src/utils/permissions/permissionsLoader.js +160 -0
- package/dist/src/utils/permissions/shadowedRuleDetection.js +81 -0
- package/dist/src/utils/permissions/shellRuleMatching.js +108 -0
- package/dist/src/utils/permissions/yoloClassifier.js +868 -0
- package/dist/src/utils/planModeV2.js +45 -0
- package/dist/src/utils/plans.js +232 -0
- package/dist/src/utils/platform.js +102 -0
- package/dist/src/utils/plugins/addDirPluginSettings.js +30 -0
- package/dist/src/utils/plugins/cacheUtils.js +144 -0
- package/dist/src/utils/plugins/dependencyResolver.js +118 -0
- package/dist/src/utils/plugins/fetchTelemetry.js +65 -0
- package/dist/src/utils/plugins/gitAvailability.js +18 -0
- package/dist/src/utils/plugins/headlessPluginInstall.js +92 -0
- package/dist/src/utils/plugins/hintRecommendation.js +95 -0
- package/dist/src/utils/plugins/installCounts.js +144 -0
- package/dist/src/utils/plugins/installedPluginsManager.js +645 -0
- package/dist/src/utils/plugins/loadPluginAgents.js +197 -0
- package/dist/src/utils/plugins/loadPluginCommands.js +488 -0
- package/dist/src/utils/plugins/loadPluginHooks.js +170 -0
- package/dist/src/utils/plugins/loadPluginOutputStyles.js +98 -0
- package/dist/src/utils/plugins/lspPluginIntegration.js +216 -0
- package/dist/src/utils/plugins/lspRecommendation.js +193 -0
- package/dist/src/utils/plugins/managedPlugins.js +18 -0
- package/dist/src/utils/plugins/marketplaceHelpers.js +309 -0
- package/dist/src/utils/plugins/marketplaceManager.js +1225 -0
- package/dist/src/utils/plugins/mcpPluginIntegration.js +336 -0
- package/dist/src/utils/plugins/mcpbHandler.js +487 -0
- package/dist/src/utils/plugins/officialMarketplace.js +5 -0
- package/dist/src/utils/plugins/officialMarketplaceGcs.js +118 -0
- package/dist/src/utils/plugins/officialMarketplaceStartupCheck.js +267 -0
- package/dist/src/utils/plugins/orphanedPluginFilter.js +47 -0
- package/dist/src/utils/plugins/parseMarketplaceInput.js +75 -0
- package/dist/src/utils/plugins/performStartupChecks.js +34 -0
- package/dist/src/utils/plugins/pluginAutoupdate.js +130 -0
- package/dist/src/utils/plugins/pluginBlocklist.js +66 -0
- package/dist/src/utils/plugins/pluginDirectories.js +78 -0
- package/dist/src/utils/plugins/pluginFlagging.js +122 -0
- package/dist/src/utils/plugins/pluginIdentifier.js +37 -0
- package/dist/src/utils/plugins/pluginInstallationHelpers.js +281 -0
- package/dist/src/utils/plugins/pluginLoader.js +1596 -0
- package/dist/src/utils/plugins/pluginOptionsStorage.js +162 -0
- package/dist/src/utils/plugins/pluginPolicy.js +5 -0
- package/dist/src/utils/plugins/pluginStartupCheck.js +176 -0
- package/dist/src/utils/plugins/pluginVersioning.js +53 -0
- package/dist/src/utils/plugins/reconciler.js +133 -0
- package/dist/src/utils/plugins/refresh.js +96 -0
- package/dist/src/utils/plugins/schemas.js +411 -0
- package/dist/src/utils/plugins/validatePlugin.js +573 -0
- package/dist/src/utils/plugins/walkPluginMarkdown.js +30 -0
- package/dist/src/utils/plugins/zipCache.js +211 -0
- package/dist/src/utils/plugins/zipCacheAdapters.js +93 -0
- package/dist/src/utils/powershell/dangerousCmdlets.js +97 -0
- package/dist/src/utils/powershell/parser.js +929 -0
- package/dist/src/utils/powershell/staticPrefix.js +142 -0
- package/dist/src/utils/preflightChecks.js +196 -0
- package/dist/src/utils/privacyLevel.js +21 -0
- package/dist/src/utils/process.js +42 -0
- package/dist/src/utils/processUserInput/processBashCommand.js +109 -0
- package/dist/src/utils/processUserInput/processSlashCommand.js +600 -0
- package/dist/src/utils/processUserInput/processTextPrompt.js +54 -0
- package/dist/src/utils/processUserInput/processUserInput.js +272 -0
- package/dist/src/utils/profilerBase.js +15 -0
- package/dist/src/utils/promptCategory.js +21 -0
- package/dist/src/utils/promptEditor.js +115 -0
- package/dist/src/utils/promptShellExecution.js +76 -0
- package/dist/src/utils/proxy.js +228 -0
- package/dist/src/utils/queryContext.js +83 -0
- package/dist/src/utils/queryHelpers.js +329 -0
- package/dist/src/utils/queryProfiler.js +177 -0
- package/dist/src/utils/queueProcessor.js +41 -0
- package/dist/src/utils/readEditContext.js +131 -0
- package/dist/src/utils/readFileInRange.js +212 -0
- package/dist/src/utils/releaseNotes.js +186 -0
- package/dist/src/utils/renderOptions.js +45 -0
- package/dist/src/utils/ripgrep.js +383 -0
- package/dist/src/utils/sandbox/sandbox-adapter.js +505 -0
- package/dist/src/utils/sandbox/sandbox-ui-utils.js +3 -0
- package/dist/src/utils/sanitization.js +33 -0
- package/dist/src/utils/screenshotClipboard.js +73 -0
- package/dist/src/utils/sdkEventQueue.js +36 -0
- package/dist/src/utils/secureStorage/fallbackStorage.js +45 -0
- package/dist/src/utils/secureStorage/index.js +9 -0
- package/dist/src/utils/secureStorage/keychainPrefetch.js +43 -0
- package/dist/src/utils/secureStorage/macOsKeychainHelpers.js +42 -0
- package/dist/src/utils/secureStorage/macOsKeychainStorage.js +147 -0
- package/dist/src/utils/secureStorage/plainTextStorage.js +77 -0
- package/dist/src/utils/semanticBoolean.js +4 -0
- package/dist/src/utils/semanticNumber.js +11 -0
- package/dist/src/utils/semver.js +43 -0
- package/dist/src/utils/sequential.js +30 -0
- package/dist/src/utils/sessionActivity.js +95 -0
- package/dist/src/utils/sessionEnvVars.js +13 -0
- package/dist/src/utils/sessionEnvironment.js +113 -0
- package/dist/src/utils/sessionFileAccessHooks.js +150 -0
- package/dist/src/utils/sessionIngressAuth.js +79 -0
- package/dist/src/utils/sessionRestore.js +205 -0
- package/dist/src/utils/sessionStart.js +119 -0
- package/dist/src/utils/sessionState.js +48 -0
- package/dist/src/utils/sessionStorage.js +2891 -0
- package/dist/src/utils/sessionStoragePortable.js +486 -0
- package/dist/src/utils/sessionTitle.js +89 -0
- package/dist/src/utils/sessionUrl.js +33 -0
- package/dist/src/utils/set.js +38 -0
- package/dist/src/utils/settings/allErrors.js +11 -0
- package/dist/src/utils/settings/applySettingsChange.js +40 -0
- package/dist/src/utils/settings/changeDetector.js +279 -0
- package/dist/src/utils/settings/constants.js +119 -0
- package/dist/src/utils/settings/internalWrites.js +15 -0
- package/dist/src/utils/settings/managedPath.js +19 -0
- package/dist/src/utils/settings/mdm/constants.js +33 -0
- package/dist/src/utils/settings/mdm/rawRead.js +72 -0
- package/dist/src/utils/settings/mdm/settings.js +160 -0
- package/dist/src/utils/settings/permissionValidation.js +169 -0
- package/dist/src/utils/settings/pluginOnlyPolicy.js +19 -0
- package/dist/src/utils/settings/schemaOutput.js +7 -0
- package/dist/src/utils/settings/settings.js +530 -0
- package/dist/src/utils/settings/settingsCache.js +36 -0
- package/dist/src/utils/settings/toolValidationConfig.js +58 -0
- package/dist/src/utils/settings/types.js +224 -0
- package/dist/src/utils/settings/validateEditTool.js +26 -0
- package/dist/src/utils/settings/validation.js +160 -0
- package/dist/src/utils/settings/validationTips.js +94 -0
- package/dist/src/utils/shell/bashProvider.js +123 -0
- package/dist/src/utils/shell/outputLimits.js +7 -0
- package/dist/src/utils/shell/powershellDetection.js +50 -0
- package/dist/src/utils/shell/powershellProvider.js +50 -0
- package/dist/src/utils/shell/prefix.js +183 -0
- package/dist/src/utils/shell/readOnlyCommandValidation.js +1347 -0
- package/dist/src/utils/shell/resolveDefaultShell.js +4 -0
- package/dist/src/utils/shell/shellProvider.js +2 -0
- package/dist/src/utils/shell/shellToolUtils.js +10 -0
- package/dist/src/utils/shell/specPrefix.js +152 -0
- package/dist/src/utils/shellConfig.js +88 -0
- package/dist/src/utils/sideQuery.js +108 -0
- package/dist/src/utils/sideQuestion.js +78 -0
- package/dist/src/utils/signal.js +18 -0
- package/dist/src/utils/sinks.js +6 -0
- package/dist/src/utils/skills/skillChangeDetector.js +184 -0
- package/dist/src/utils/slashCommandParsing.js +25 -0
- package/dist/src/utils/sleep.js +43 -0
- package/dist/src/utils/sliceAnsi.js +48 -0
- package/dist/src/utils/slowOperations.js +165 -0
- package/dist/src/utils/standaloneAgent.js +7 -0
- package/dist/src/utils/startupProfiler.js +106 -0
- package/dist/src/utils/staticRender.js +78 -0
- package/dist/src/utils/stats.js +598 -0
- package/dist/src/utils/statsCache.js +223 -0
- package/dist/src/utils/status.js +361 -0
- package/dist/src/utils/statusNoticeDefinitions.js +280 -0
- package/dist/src/utils/statusNoticeHelpers.js +10 -0
- package/dist/src/utils/stream.js +72 -0
- package/dist/src/utils/streamJsonStdoutGuard.js +73 -0
- package/dist/src/utils/streamlinedTransform.js +130 -0
- package/dist/src/utils/stringUtils.js +108 -0
- package/dist/src/utils/subprocessEnv.js +42 -0
- package/dist/src/utils/suggestions/commandSuggestions.js +301 -0
- package/dist/src/utils/suggestions/directoryCompletion.js +134 -0
- package/dist/src/utils/suggestions/shellHistoryCompletion.js +65 -0
- package/dist/src/utils/suggestions/skillUsageTracking.js +33 -0
- package/dist/src/utils/suggestions/slackChannelSuggestions.js +141 -0
- package/dist/src/utils/swarm/It2SetupPrompt.js +537 -0
- package/dist/src/utils/swarm/backends/ITermBackend.js +153 -0
- package/dist/src/utils/swarm/backends/InProcessBackend.js +160 -0
- package/dist/src/utils/swarm/backends/PaneBackendExecutor.js +171 -0
- package/dist/src/utils/swarm/backends/TmuxBackend.js +458 -0
- package/dist/src/utils/swarm/backends/detection.js +43 -0
- package/dist/src/utils/swarm/backends/it2Setup.js +134 -0
- package/dist/src/utils/swarm/backends/registry.js +220 -0
- package/dist/src/utils/swarm/backends/teammateModeSnapshot.js +33 -0
- package/dist/src/utils/swarm/backends/types.js +3 -0
- package/dist/src/utils/swarm/constants.js +11 -0
- package/dist/src/utils/swarm/inProcessRunner.js +818 -0
- package/dist/src/utils/swarm/leaderPermissionBridge.js +20 -0
- package/dist/src/utils/swarm/permissionSync.js +474 -0
- package/dist/src/utils/swarm/reconnection.js +55 -0
- package/dist/src/utils/swarm/spawnInProcess.js +164 -0
- package/dist/src/utils/swarm/spawnUtils.js +76 -0
- package/dist/src/utils/swarm/teamHelpers.js +320 -0
- package/dist/src/utils/swarm/teammateInit.js +65 -0
- package/dist/src/utils/swarm/teammateLayoutManager.js +40 -0
- package/dist/src/utils/swarm/teammateModel.js +5 -0
- package/dist/src/utils/swarm/teammatePromptAddendum.js +11 -0
- package/dist/src/utils/systemDirectories.js +42 -0
- package/dist/src/utils/systemPrompt.js +41 -0
- package/dist/src/utils/systemPromptType.js +3 -0
- package/dist/src/utils/systemTheme.js +61 -0
- package/dist/src/utils/taggedId.js +27 -0
- package/dist/src/utils/task/TaskOutput.js +244 -0
- package/dist/src/utils/task/diskOutput.js +267 -0
- package/dist/src/utils/task/framework.js +178 -0
- package/dist/src/utils/task/outputFormatting.js +21 -0
- package/dist/src/utils/task/sdkProgress.js +18 -0
- package/dist/src/utils/tasks.js +481 -0
- package/dist/src/utils/teamDiscovery.js +33 -0
- package/dist/src/utils/teamMemoryOps.js +40 -0
- package/dist/src/utils/teammate.js +132 -0
- package/dist/src/utils/teammateContext.js +17 -0
- package/dist/src/utils/teammateMailbox.js +541 -0
- package/dist/src/utils/telemetry/betaSessionTracing.js +255 -0
- package/dist/src/utils/telemetry/bigqueryExporter.js +162 -0
- package/dist/src/utils/telemetry/events.js +46 -0
- package/dist/src/utils/telemetry/instrumentation.js +534 -0
- package/dist/src/utils/telemetry/logger.js +26 -0
- package/dist/src/utils/telemetry/perfettoTracing.js +636 -0
- package/dist/src/utils/telemetry/pluginTelemetry.js +99 -0
- package/dist/src/utils/telemetry/sessionTracing.js +564 -0
- package/dist/src/utils/telemetry/skillLoadedEvent.js +22 -0
- package/dist/src/utils/telemetryAttributes.js +50 -0
- package/dist/src/utils/teleport/api.js +236 -0
- package/dist/src/utils/teleport/environmentSelection.js +42 -0
- package/dist/src/utils/teleport/environments.js +74 -0
- package/dist/src/utils/teleport/gitBundle.js +153 -0
- package/dist/src/utils/teleport.js +856 -0
- package/dist/src/utils/tempfile.js +7 -0
- package/dist/src/utils/terminal.js +65 -0
- package/dist/src/utils/terminalPanel.js +133 -0
- package/dist/src/utils/textHighlighting.js +109 -0
- package/dist/src/utils/theme.js +465 -0
- package/dist/src/utils/thinking.js +92 -0
- package/dist/src/utils/timeouts.js +22 -0
- package/dist/src/utils/tmuxSocket.js +216 -0
- package/dist/src/utils/todo/types.js +9 -0
- package/dist/src/utils/tokenBudget.js +54 -0
- package/dist/src/utils/tokens.js +123 -0
- package/dist/src/utils/toolErrors.js +87 -0
- package/dist/src/utils/toolPool.js +22 -0
- package/dist/src/utils/toolResultStorage.js +444 -0
- package/dist/src/utils/toolSchemaCache.js +7 -0
- package/dist/src/utils/toolSearch.js +314 -0
- package/dist/src/utils/transcriptSearch.js +143 -0
- package/dist/src/utils/treeify.js +89 -0
- package/dist/src/utils/truncate.js +113 -0
- package/dist/src/utils/ultraplan/ccrSession.js +187 -0
- package/dist/src/utils/ultraplan/keyword.js +81 -0
- package/dist/src/utils/ultraplan/prompt.txt.js +1 -0
- package/dist/src/utils/unaryLogging.js +15 -0
- package/dist/src/utils/undercover.js +57 -0
- package/dist/src/utils/user.js +111 -0
- package/dist/src/utils/userAgent.js +3 -0
- package/dist/src/utils/userPromptKeywords.js +13 -0
- package/dist/src/utils/uuid.js +11 -0
- package/dist/src/utils/warningHandler.js +74 -0
- package/dist/src/utils/which.js +50 -0
- package/dist/src/utils/windowsPaths.js +104 -0
- package/dist/src/utils/withResolvers.js +9 -0
- package/dist/src/utils/words.js +763 -0
- package/dist/src/utils/workloadContext.js +9 -0
- package/dist/src/utils/worktree.js +841 -0
- package/dist/src/utils/worktreeModeEnabled.js +3 -0
- package/dist/src/utils/xdg.js +24 -0
- package/dist/src/utils/xml.js +6 -0
- package/dist/src/utils/yaml.js +6 -0
- package/dist/src/utils/zodToJsonSchema.js +10 -0
- package/dist/src/vim/motions.js +54 -0
- package/dist/src/vim/operators.js +329 -0
- package/dist/src/vim/textObjects.js +137 -0
- package/dist/src/vim/transitions.js +324 -0
- package/dist/src/vim/types.js +60 -0
- package/dist/src/voice/voiceModeEnabled.js +18 -0
- package/dist/stubs/ant-claude-for-chrome-mcp.js +6 -0
- package/dist/stubs/color-diff-napi.js +30 -0
- package/litellm.yaml +25 -0
- package/package.json +93 -0
|
@@ -0,0 +1,3112 @@
|
|
|
1
|
+
import { readFile, stat } from "fs/promises";
|
|
2
|
+
import { dirname } from "path";
|
|
3
|
+
import {
|
|
4
|
+
downloadUserSettings,
|
|
5
|
+
redownloadUserSettings
|
|
6
|
+
} from "../services/settingsSync/index.js";
|
|
7
|
+
import { waitForRemoteManagedSettingsToLoad } from "../services/remoteManagedSettings/index.js";
|
|
8
|
+
import { StructuredIO } from "./structuredIO.js";
|
|
9
|
+
import { RemoteIO } from "./remoteIO.js";
|
|
10
|
+
import {
|
|
11
|
+
formatDescriptionWithSource,
|
|
12
|
+
getCommandName
|
|
13
|
+
} from "../commands.js";
|
|
14
|
+
import { createStreamlinedTransformer } from "../utils/streamlinedTransform.js";
|
|
15
|
+
import { installStreamJsonStdoutGuard } from "../utils/streamJsonStdoutGuard.js";
|
|
16
|
+
import { assembleToolPool, filterToolsByDenyRules } from "../tools.js";
|
|
17
|
+
import uniqBy from "lodash-es/uniqBy.js";
|
|
18
|
+
import { uniq } from "../utils/array.js";
|
|
19
|
+
import { mergeAndFilterTools } from "../utils/toolPool.js";
|
|
20
|
+
import {
|
|
21
|
+
logEvent
|
|
22
|
+
} from "../services/analytics/index.js";
|
|
23
|
+
import { getFeatureValue_CACHED_MAY_BE_STALE } from "../services/analytics/growthbook.js";
|
|
24
|
+
import { logForDebugging } from "../utils/debug.js";
|
|
25
|
+
import {
|
|
26
|
+
logForDiagnosticsNoPII,
|
|
27
|
+
withDiagnosticsTiming
|
|
28
|
+
} from "../utils/diagLogs.js";
|
|
29
|
+
import { toolMatchesName } from "../Tool.js";
|
|
30
|
+
import {
|
|
31
|
+
isBuiltInAgent,
|
|
32
|
+
parseAgentsFromJson
|
|
33
|
+
} from "../tools/AgentTool/loadAgentsDir.js";
|
|
34
|
+
import {
|
|
35
|
+
dequeue,
|
|
36
|
+
dequeueAllMatching,
|
|
37
|
+
enqueue,
|
|
38
|
+
hasCommandsInQueue,
|
|
39
|
+
peek,
|
|
40
|
+
subscribeToCommandQueue,
|
|
41
|
+
getCommandsByMaxPriority
|
|
42
|
+
} from "../utils/messageQueueManager.js";
|
|
43
|
+
import { notifyCommandLifecycle } from "../utils/commandLifecycle.js";
|
|
44
|
+
import {
|
|
45
|
+
getSessionState,
|
|
46
|
+
notifySessionStateChanged,
|
|
47
|
+
notifySessionMetadataChanged,
|
|
48
|
+
setPermissionModeChangedListener
|
|
49
|
+
} from "../utils/sessionState.js";
|
|
50
|
+
import { externalMetadataToAppState } from "../state/onChangeAppState.js";
|
|
51
|
+
import { getInMemoryErrors, logError, logMCPDebug } from "../utils/log.js";
|
|
52
|
+
import {
|
|
53
|
+
writeToStdout,
|
|
54
|
+
registerProcessOutputErrorHandlers
|
|
55
|
+
} from "../utils/process.js";
|
|
56
|
+
import { EMPTY_USAGE } from "../services/api/logging.js";
|
|
57
|
+
import {
|
|
58
|
+
loadConversationForResume
|
|
59
|
+
} from "../utils/conversationRecovery.js";
|
|
60
|
+
import {
|
|
61
|
+
ChannelMessageNotificationSchema,
|
|
62
|
+
gateChannelServer,
|
|
63
|
+
wrapChannelMessage,
|
|
64
|
+
findChannelEntry
|
|
65
|
+
} from "../services/mcp/channelNotification.js";
|
|
66
|
+
import {
|
|
67
|
+
isChannelAllowlisted,
|
|
68
|
+
isChannelsEnabled
|
|
69
|
+
} from "../services/mcp/channelAllowlist.js";
|
|
70
|
+
import { parsePluginIdentifier } from "../utils/plugins/pluginIdentifier.js";
|
|
71
|
+
import { validateUuid } from "../utils/uuid.js";
|
|
72
|
+
import { fromArray } from "../utils/generators.js";
|
|
73
|
+
import { ask } from "../QueryEngine.js";
|
|
74
|
+
import {
|
|
75
|
+
createFileStateCacheWithSizeLimit,
|
|
76
|
+
mergeFileStateCaches,
|
|
77
|
+
READ_FILE_STATE_CACHE_SIZE
|
|
78
|
+
} from "../utils/fileStateCache.js";
|
|
79
|
+
import { expandPath } from "../utils/path.js";
|
|
80
|
+
import { extractReadFilesFromMessages } from "../utils/queryHelpers.js";
|
|
81
|
+
import { registerHookEventHandler } from "../utils/hooks/hookEvents.js";
|
|
82
|
+
import { executeFilePersistence } from "../utils/filePersistence/filePersistence.js";
|
|
83
|
+
import { finalizePendingAsyncHooks } from "../utils/hooks/AsyncHookRegistry.js";
|
|
84
|
+
import {
|
|
85
|
+
gracefulShutdown,
|
|
86
|
+
gracefulShutdownSync,
|
|
87
|
+
isShuttingDown
|
|
88
|
+
} from "../utils/gracefulShutdown.js";
|
|
89
|
+
import { registerCleanup } from "../utils/cleanupRegistry.js";
|
|
90
|
+
import { createIdleTimeoutManager } from "../utils/idleTimeout.js";
|
|
91
|
+
import { cwd } from "process";
|
|
92
|
+
import { getCwd } from "../utils/cwd.js";
|
|
93
|
+
import omit from "lodash-es/omit.js";
|
|
94
|
+
import reject from "lodash-es/reject.js";
|
|
95
|
+
import { isPolicyAllowed } from "../services/policyLimits/index.js";
|
|
96
|
+
import { getRemoteSessionUrl } from "../constants/product.js";
|
|
97
|
+
import { buildBridgeConnectUrl } from "../bridge/bridgeStatusUtil.js";
|
|
98
|
+
import { extractInboundMessageFields } from "../bridge/inboundMessages.js";
|
|
99
|
+
import { resolveAndPrepend } from "../bridge/inboundAttachments.js";
|
|
100
|
+
import { hasPermissionsToUseTool } from "../utils/permissions/permissions.js";
|
|
101
|
+
import { safeParseJSON } from "../utils/json.js";
|
|
102
|
+
import {
|
|
103
|
+
outputSchema as permissionToolOutputSchema,
|
|
104
|
+
permissionPromptToolResultToPermissionDecision
|
|
105
|
+
} from "../utils/permissions/PermissionPromptToolResultSchema.js";
|
|
106
|
+
import { createAbortController } from "../utils/abortController.js";
|
|
107
|
+
import { createCombinedAbortSignal } from "../utils/combinedAbortSignal.js";
|
|
108
|
+
import { generateSessionTitle } from "../utils/sessionTitle.js";
|
|
109
|
+
import { buildSideQuestionFallbackParams } from "../utils/queryContext.js";
|
|
110
|
+
import { runSideQuestion } from "../utils/sideQuestion.js";
|
|
111
|
+
import {
|
|
112
|
+
processSessionStartHooks,
|
|
113
|
+
processSetupHooks,
|
|
114
|
+
takeInitialUserMessage
|
|
115
|
+
} from "../utils/sessionStart.js";
|
|
116
|
+
import {
|
|
117
|
+
DEFAULT_OUTPUT_STYLE_NAME,
|
|
118
|
+
getAllOutputStyles
|
|
119
|
+
} from "../constants/outputStyles.js";
|
|
120
|
+
import { TEAMMATE_MESSAGE_TAG, TICK_TAG } from "../constants/xml.js";
|
|
121
|
+
import {
|
|
122
|
+
getSettings_DEPRECATED,
|
|
123
|
+
getSettingsWithSources
|
|
124
|
+
} from "../utils/settings/settings.js";
|
|
125
|
+
import { settingsChangeDetector } from "../utils/settings/changeDetector.js";
|
|
126
|
+
import { applySettingsChange } from "../utils/settings/applySettingsChange.js";
|
|
127
|
+
import {
|
|
128
|
+
isFastModeAvailable,
|
|
129
|
+
isFastModeEnabled,
|
|
130
|
+
isFastModeSupportedByModel,
|
|
131
|
+
getFastModeState
|
|
132
|
+
} from "../utils/fastMode.js";
|
|
133
|
+
import {
|
|
134
|
+
isAutoModeGateEnabled,
|
|
135
|
+
getAutoModeUnavailableNotification,
|
|
136
|
+
getAutoModeUnavailableReason,
|
|
137
|
+
isBypassPermissionsModeDisabled,
|
|
138
|
+
transitionPermissionMode
|
|
139
|
+
} from "../utils/permissions/permissionSetup.js";
|
|
140
|
+
import {
|
|
141
|
+
tryGenerateSuggestion,
|
|
142
|
+
logSuggestionOutcome,
|
|
143
|
+
logSuggestionSuppressed
|
|
144
|
+
} from "../services/PromptSuggestion/promptSuggestion.js";
|
|
145
|
+
import { getLastCacheSafeParams } from "../utils/forkedAgent.js";
|
|
146
|
+
import { getAccountInformation } from "../utils/auth.js";
|
|
147
|
+
import { OAuthService } from "../services/oauth/index.js";
|
|
148
|
+
import { installOAuthTokens } from "./handlers/auth.js";
|
|
149
|
+
import { getAPIProvider } from "../utils/model/providers.js";
|
|
150
|
+
import { AwsAuthStatusManager } from "../utils/awsAuthStatusManager.js";
|
|
151
|
+
import {
|
|
152
|
+
registerHookCallbacks,
|
|
153
|
+
setInitJsonSchema,
|
|
154
|
+
getInitJsonSchema,
|
|
155
|
+
setSdkAgentProgressSummariesEnabled
|
|
156
|
+
} from "../bootstrap/state.js";
|
|
157
|
+
import { createSyntheticOutputTool } from "../tools/SyntheticOutputTool/SyntheticOutputTool.js";
|
|
158
|
+
import { parseSessionIdentifier } from "../utils/sessionUrl.js";
|
|
159
|
+
import {
|
|
160
|
+
hydrateRemoteSession,
|
|
161
|
+
hydrateFromCCRv2InternalEvents,
|
|
162
|
+
resetSessionFilePointer,
|
|
163
|
+
doesMessageExistInSession,
|
|
164
|
+
findUnresolvedToolUse,
|
|
165
|
+
recordAttributionSnapshot,
|
|
166
|
+
saveAgentSetting,
|
|
167
|
+
saveMode,
|
|
168
|
+
saveAiGeneratedTitle,
|
|
169
|
+
restoreSessionMetadata
|
|
170
|
+
} from "../utils/sessionStorage.js";
|
|
171
|
+
import { incrementPromptCount } from "../utils/commitAttribution.js";
|
|
172
|
+
import {
|
|
173
|
+
setupSdkMcpClients,
|
|
174
|
+
connectToServer,
|
|
175
|
+
clearServerCache,
|
|
176
|
+
fetchToolsForClient,
|
|
177
|
+
areMcpConfigsEqual,
|
|
178
|
+
reconnectMcpServerImpl
|
|
179
|
+
} from "../services/mcp/client.js";
|
|
180
|
+
import {
|
|
181
|
+
filterMcpServersByPolicy,
|
|
182
|
+
getMcpConfigByName,
|
|
183
|
+
isMcpServerDisabled,
|
|
184
|
+
setMcpServerEnabled
|
|
185
|
+
} from "../services/mcp/config.js";
|
|
186
|
+
import {
|
|
187
|
+
performMCPOAuthFlow,
|
|
188
|
+
revokeServerTokens
|
|
189
|
+
} from "../services/mcp/auth.js";
|
|
190
|
+
import {
|
|
191
|
+
runElicitationHooks,
|
|
192
|
+
runElicitationResultHooks
|
|
193
|
+
} from "../services/mcp/elicitationHandler.js";
|
|
194
|
+
import { executeNotificationHooks } from "../utils/hooks.js";
|
|
195
|
+
import {
|
|
196
|
+
ElicitRequestSchema,
|
|
197
|
+
ElicitationCompleteNotificationSchema
|
|
198
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
199
|
+
import { getMcpPrefix } from "../services/mcp/mcpStringUtils.js";
|
|
200
|
+
import {
|
|
201
|
+
commandBelongsToServer,
|
|
202
|
+
filterToolsByServer
|
|
203
|
+
} from "../services/mcp/utils.js";
|
|
204
|
+
import { setupVscodeSdkMcp } from "../services/mcp/vscodeSdkMcp.js";
|
|
205
|
+
import { getAllMcpConfigs } from "../services/mcp/config.js";
|
|
206
|
+
import {
|
|
207
|
+
isQualifiedForGrove,
|
|
208
|
+
checkGroveForNonInteractive
|
|
209
|
+
} from "../services/api/grove.js";
|
|
210
|
+
import {
|
|
211
|
+
toInternalMessages,
|
|
212
|
+
toSDKRateLimitInfo
|
|
213
|
+
} from "../utils/messages/mappers.js";
|
|
214
|
+
import { createModelSwitchBreadcrumbs } from "../utils/messages.js";
|
|
215
|
+
import { collectContextData } from "../commands/context/context-noninteractive.js";
|
|
216
|
+
import { LOCAL_COMMAND_STDOUT_TAG } from "../constants/xml.js";
|
|
217
|
+
import {
|
|
218
|
+
statusListeners
|
|
219
|
+
} from "../services/claudeAiLimits.js";
|
|
220
|
+
import {
|
|
221
|
+
getDefaultMainLoopModel,
|
|
222
|
+
getMainLoopModel,
|
|
223
|
+
modelDisplayString,
|
|
224
|
+
parseUserSpecifiedModel
|
|
225
|
+
} from "../utils/model/model.js";
|
|
226
|
+
import { getModelOptions } from "../utils/model/modelOptions.js";
|
|
227
|
+
import {
|
|
228
|
+
modelSupportsEffort,
|
|
229
|
+
modelSupportsMaxEffort,
|
|
230
|
+
EFFORT_LEVELS,
|
|
231
|
+
resolveAppliedEffort
|
|
232
|
+
} from "../utils/effort.js";
|
|
233
|
+
import { modelSupportsAdaptiveThinking } from "../utils/thinking.js";
|
|
234
|
+
import { modelSupportsAutoMode } from "../utils/betas.js";
|
|
235
|
+
import { ensureModelStringsInitialized } from "../utils/model/modelStrings.js";
|
|
236
|
+
import {
|
|
237
|
+
getSessionId,
|
|
238
|
+
setMainLoopModelOverride,
|
|
239
|
+
setMainThreadAgentType,
|
|
240
|
+
switchSession,
|
|
241
|
+
isSessionPersistenceDisabled,
|
|
242
|
+
getIsRemoteMode,
|
|
243
|
+
getFlagSettingsInline,
|
|
244
|
+
setFlagSettingsInline,
|
|
245
|
+
getMainThreadAgentType,
|
|
246
|
+
getAllowedChannels,
|
|
247
|
+
setAllowedChannels
|
|
248
|
+
} from "../bootstrap/state.js";
|
|
249
|
+
import { runWithWorkload, WORKLOAD_CRON } from "../utils/workloadContext.js";
|
|
250
|
+
import { randomUUID } from "crypto";
|
|
251
|
+
import {
|
|
252
|
+
fileHistoryRewind,
|
|
253
|
+
fileHistoryCanRestore,
|
|
254
|
+
fileHistoryEnabled,
|
|
255
|
+
fileHistoryGetDiffStats
|
|
256
|
+
} from "../utils/fileHistory.js";
|
|
257
|
+
import {
|
|
258
|
+
restoreAgentFromSession,
|
|
259
|
+
restoreSessionStateFromLog
|
|
260
|
+
} from "../utils/sessionRestore.js";
|
|
261
|
+
import { SandboxManager } from "../utils/sandbox/sandbox-adapter.js";
|
|
262
|
+
import {
|
|
263
|
+
headlessProfilerStartTurn,
|
|
264
|
+
headlessProfilerCheckpoint,
|
|
265
|
+
logHeadlessProfilerTurn
|
|
266
|
+
} from "../utils/headlessProfiler.js";
|
|
267
|
+
import {
|
|
268
|
+
startQueryProfile,
|
|
269
|
+
logQueryProfileReport
|
|
270
|
+
} from "../utils/queryProfiler.js";
|
|
271
|
+
import { asSessionId } from "../types/ids.js";
|
|
272
|
+
import { jsonStringify } from "../utils/slowOperations.js";
|
|
273
|
+
import { skillChangeDetector } from "../utils/skills/skillChangeDetector.js";
|
|
274
|
+
import { getCommands, clearCommandsCache } from "../commands.js";
|
|
275
|
+
import {
|
|
276
|
+
isBareMode,
|
|
277
|
+
isEnvTruthy,
|
|
278
|
+
isEnvDefinedFalsy
|
|
279
|
+
} from "../utils/envUtils.js";
|
|
280
|
+
import { installPluginsForHeadless } from "../utils/plugins/headlessPluginInstall.js";
|
|
281
|
+
import { refreshActivePlugins } from "../utils/plugins/refresh.js";
|
|
282
|
+
import { loadAllPluginsCacheOnly } from "../utils/plugins/pluginLoader.js";
|
|
283
|
+
import {
|
|
284
|
+
isTeamLead,
|
|
285
|
+
hasActiveInProcessTeammates,
|
|
286
|
+
hasWorkingInProcessTeammates,
|
|
287
|
+
waitForTeammatesToBecomeIdle
|
|
288
|
+
} from "../utils/teammate.js";
|
|
289
|
+
import {
|
|
290
|
+
readUnreadMessages,
|
|
291
|
+
markMessagesAsRead,
|
|
292
|
+
isShutdownApproved
|
|
293
|
+
} from "../utils/teammateMailbox.js";
|
|
294
|
+
import { removeTeammateFromTeamFile } from "../utils/swarm/teamHelpers.js";
|
|
295
|
+
import { unassignTeammateTasks } from "../utils/tasks.js";
|
|
296
|
+
import { getRunningTasks } from "../utils/task/framework.js";
|
|
297
|
+
import { isBackgroundTask } from "../tasks/types.js";
|
|
298
|
+
import { stopTask } from "../tasks/stopTask.js";
|
|
299
|
+
import { drainSdkEvents } from "../utils/sdkEventQueue.js";
|
|
300
|
+
import { initializeGrowthBook } from "../services/analytics/growthbook.js";
|
|
301
|
+
import { errorMessage, toError } from "../utils/errors.js";
|
|
302
|
+
import { sleep } from "../utils/sleep.js";
|
|
303
|
+
import { isExtractModeActive } from "../memdir/paths.js";
|
|
304
|
+
const coordinatorModeModule = null;
|
|
305
|
+
const proactiveModule = null;
|
|
306
|
+
const cronSchedulerModule = null;
|
|
307
|
+
const cronJitterConfigModule = null;
|
|
308
|
+
const cronGate = null;
|
|
309
|
+
const extractMemoriesModule = null;
|
|
310
|
+
const SHUTDOWN_TEAM_PROMPT = `<system-reminder>
|
|
311
|
+
You are running in non-interactive mode and cannot return a response to the user until your team is shut down.
|
|
312
|
+
|
|
313
|
+
You MUST shut down your team before preparing your final response:
|
|
314
|
+
1. Use requestShutdown to ask each team member to shut down gracefully
|
|
315
|
+
2. Wait for shutdown approvals
|
|
316
|
+
3. Use the cleanup operation to clean up the team
|
|
317
|
+
4. Only then provide your final response to the user
|
|
318
|
+
|
|
319
|
+
The user cannot receive your response until the team is completely shut down.
|
|
320
|
+
</system-reminder>
|
|
321
|
+
|
|
322
|
+
Shut down your team and prepare your final response for the user.`;
|
|
323
|
+
const MAX_RECEIVED_UUIDS = 1e4;
|
|
324
|
+
const receivedMessageUuids = new Set;
|
|
325
|
+
const receivedMessageUuidsOrder = [];
|
|
326
|
+
function trackReceivedMessageUuid(uuid) {
|
|
327
|
+
if (receivedMessageUuids.has(uuid)) {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
receivedMessageUuids.add(uuid);
|
|
331
|
+
receivedMessageUuidsOrder.push(uuid);
|
|
332
|
+
if (receivedMessageUuidsOrder.length > MAX_RECEIVED_UUIDS) {
|
|
333
|
+
const toEvict = receivedMessageUuidsOrder.splice(0, receivedMessageUuidsOrder.length - MAX_RECEIVED_UUIDS);
|
|
334
|
+
for (const old of toEvict) {
|
|
335
|
+
receivedMessageUuids.delete(old);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
function toBlocks(v) {
|
|
341
|
+
return typeof v === "string" ? [{ type: "text", text: v }] : v;
|
|
342
|
+
}
|
|
343
|
+
export function joinPromptValues(values) {
|
|
344
|
+
if (values.length === 1)
|
|
345
|
+
return values[0];
|
|
346
|
+
if (values.every((v) => typeof v === "string")) {
|
|
347
|
+
return values.join(`
|
|
348
|
+
`);
|
|
349
|
+
}
|
|
350
|
+
return values.flatMap(toBlocks);
|
|
351
|
+
}
|
|
352
|
+
export function canBatchWith(head, next) {
|
|
353
|
+
return next !== undefined && next.mode === "prompt" && next.workload === head.workload && next.isMeta === head.isMeta;
|
|
354
|
+
}
|
|
355
|
+
export async function runHeadless(inputPrompt, getAppState, setAppState, commands, tools, sdkMcpConfigs, agents, options) {
|
|
356
|
+
if (process.env.USER_TYPE === "ant" && isEnvTruthy(process.env.CLAUDE_CODE_EXIT_AFTER_FIRST_RENDER)) {
|
|
357
|
+
process.stderr.write(`
|
|
358
|
+
Startup time: ${Math.round(process.uptime() * 1000)}ms
|
|
359
|
+
`);
|
|
360
|
+
process.exit(0);
|
|
361
|
+
}
|
|
362
|
+
if (false) {}
|
|
363
|
+
settingsChangeDetector.subscribe((source) => {
|
|
364
|
+
applySettingsChange(source, setAppState);
|
|
365
|
+
if (isFastModeEnabled()) {
|
|
366
|
+
setAppState((prev) => {
|
|
367
|
+
const s = prev.settings;
|
|
368
|
+
const fastMode = s.fastMode === true && !s.fastModePerSessionOptIn;
|
|
369
|
+
return { ...prev, fastMode };
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
if (false) {}
|
|
374
|
+
if (typeof Bun !== "undefined") {
|
|
375
|
+
const gcTimer = setInterval(Bun.gc, 1000);
|
|
376
|
+
gcTimer.unref();
|
|
377
|
+
}
|
|
378
|
+
headlessProfilerStartTurn();
|
|
379
|
+
headlessProfilerCheckpoint("runHeadless_entry");
|
|
380
|
+
if (await isQualifiedForGrove()) {
|
|
381
|
+
await checkGroveForNonInteractive();
|
|
382
|
+
}
|
|
383
|
+
headlessProfilerCheckpoint("after_grove_check");
|
|
384
|
+
initializeGrowthBook();
|
|
385
|
+
if (options.resumeSessionAt && !options.resume) {
|
|
386
|
+
process.stderr.write(`Error: --resume-session-at requires --resume
|
|
387
|
+
`);
|
|
388
|
+
gracefulShutdownSync(1);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (options.rewindFiles && !options.resume) {
|
|
392
|
+
process.stderr.write(`Error: --rewind-files requires --resume
|
|
393
|
+
`);
|
|
394
|
+
gracefulShutdownSync(1);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (options.rewindFiles && inputPrompt) {
|
|
398
|
+
process.stderr.write(`Error: --rewind-files is a standalone operation and cannot be used with a prompt
|
|
399
|
+
`);
|
|
400
|
+
gracefulShutdownSync(1);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const structuredIO = getStructuredIO(inputPrompt, options);
|
|
404
|
+
if (options.outputFormat === "stream-json") {
|
|
405
|
+
installStreamJsonStdoutGuard();
|
|
406
|
+
}
|
|
407
|
+
const sandboxUnavailableReason = SandboxManager.getSandboxUnavailableReason();
|
|
408
|
+
if (sandboxUnavailableReason) {
|
|
409
|
+
if (SandboxManager.isSandboxRequired()) {
|
|
410
|
+
process.stderr.write(`
|
|
411
|
+
Error: sandbox required but unavailable: ${sandboxUnavailableReason}
|
|
412
|
+
` + ` sandbox.failIfUnavailable is set — refusing to start without a working sandbox.
|
|
413
|
+
|
|
414
|
+
`);
|
|
415
|
+
gracefulShutdownSync(1);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
process.stderr.write(`
|
|
419
|
+
⚠ Sandbox disabled: ${sandboxUnavailableReason}
|
|
420
|
+
` + ` Commands will run WITHOUT sandboxing. Network and filesystem restrictions will NOT be enforced.
|
|
421
|
+
|
|
422
|
+
`);
|
|
423
|
+
} else if (SandboxManager.isSandboxingEnabled()) {
|
|
424
|
+
try {
|
|
425
|
+
await SandboxManager.initialize(structuredIO.createSandboxAskCallback());
|
|
426
|
+
} catch (err) {
|
|
427
|
+
process.stderr.write(`
|
|
428
|
+
❌ Sandbox Error: ${errorMessage(err)}
|
|
429
|
+
`);
|
|
430
|
+
gracefulShutdownSync(1, "other");
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (options.outputFormat === "stream-json" && options.verbose) {
|
|
435
|
+
registerHookEventHandler((event) => {
|
|
436
|
+
const message = (() => {
|
|
437
|
+
switch (event.type) {
|
|
438
|
+
case "started":
|
|
439
|
+
return {
|
|
440
|
+
type: "system",
|
|
441
|
+
subtype: "hook_started",
|
|
442
|
+
hook_id: event.hookId,
|
|
443
|
+
hook_name: event.hookName,
|
|
444
|
+
hook_event: event.hookEvent,
|
|
445
|
+
uuid: randomUUID(),
|
|
446
|
+
session_id: getSessionId()
|
|
447
|
+
};
|
|
448
|
+
case "progress":
|
|
449
|
+
return {
|
|
450
|
+
type: "system",
|
|
451
|
+
subtype: "hook_progress",
|
|
452
|
+
hook_id: event.hookId,
|
|
453
|
+
hook_name: event.hookName,
|
|
454
|
+
hook_event: event.hookEvent,
|
|
455
|
+
stdout: event.stdout,
|
|
456
|
+
stderr: event.stderr,
|
|
457
|
+
output: event.output,
|
|
458
|
+
uuid: randomUUID(),
|
|
459
|
+
session_id: getSessionId()
|
|
460
|
+
};
|
|
461
|
+
case "response":
|
|
462
|
+
return {
|
|
463
|
+
type: "system",
|
|
464
|
+
subtype: "hook_response",
|
|
465
|
+
hook_id: event.hookId,
|
|
466
|
+
hook_name: event.hookName,
|
|
467
|
+
hook_event: event.hookEvent,
|
|
468
|
+
output: event.output,
|
|
469
|
+
stdout: event.stdout,
|
|
470
|
+
stderr: event.stderr,
|
|
471
|
+
exit_code: event.exitCode,
|
|
472
|
+
outcome: event.outcome,
|
|
473
|
+
uuid: randomUUID(),
|
|
474
|
+
session_id: getSessionId()
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
})();
|
|
478
|
+
structuredIO.write(message);
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
if (options.setupTrigger) {
|
|
482
|
+
await processSetupHooks(options.setupTrigger);
|
|
483
|
+
}
|
|
484
|
+
headlessProfilerCheckpoint("before_loadInitialMessages");
|
|
485
|
+
const appState = getAppState();
|
|
486
|
+
const {
|
|
487
|
+
messages: initialMessages,
|
|
488
|
+
turnInterruptionState,
|
|
489
|
+
agentSetting: resumedAgentSetting
|
|
490
|
+
} = await loadInitialMessages(setAppState, {
|
|
491
|
+
continue: options.continue,
|
|
492
|
+
teleport: options.teleport,
|
|
493
|
+
resume: options.resume,
|
|
494
|
+
resumeSessionAt: options.resumeSessionAt,
|
|
495
|
+
forkSession: options.forkSession,
|
|
496
|
+
outputFormat: options.outputFormat,
|
|
497
|
+
sessionStartHooksPromise: options.sessionStartHooksPromise,
|
|
498
|
+
restoredWorkerState: structuredIO.restoredWorkerState
|
|
499
|
+
});
|
|
500
|
+
const hookInitialUserMessage = takeInitialUserMessage();
|
|
501
|
+
if (hookInitialUserMessage) {
|
|
502
|
+
structuredIO.prependUserMessage(hookInitialUserMessage);
|
|
503
|
+
}
|
|
504
|
+
if (!options.agent && !getMainThreadAgentType() && resumedAgentSetting) {
|
|
505
|
+
const { agentDefinition: restoredAgent } = restoreAgentFromSession(resumedAgentSetting, undefined, { activeAgents: agents, allAgents: agents });
|
|
506
|
+
if (restoredAgent) {
|
|
507
|
+
setAppState((prev) => ({ ...prev, agent: restoredAgent.agentType }));
|
|
508
|
+
if (!options.systemPrompt && !isBuiltInAgent(restoredAgent)) {
|
|
509
|
+
const agentSystemPrompt = restoredAgent.getSystemPrompt();
|
|
510
|
+
if (agentSystemPrompt) {
|
|
511
|
+
options.systemPrompt = agentSystemPrompt;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
saveAgentSetting(restoredAgent.agentType);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (initialMessages.length === 0 && process.exitCode !== undefined) {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if (options.rewindFiles) {
|
|
521
|
+
const targetMessage = initialMessages.find((m) => m.uuid === options.rewindFiles);
|
|
522
|
+
if (!targetMessage || targetMessage.type !== "user") {
|
|
523
|
+
process.stderr.write(`Error: --rewind-files requires a user message UUID, but ${options.rewindFiles} is not a user message in this session
|
|
524
|
+
`);
|
|
525
|
+
gracefulShutdownSync(1);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const currentAppState = getAppState();
|
|
529
|
+
const result = await handleRewindFiles(options.rewindFiles, currentAppState, setAppState, false);
|
|
530
|
+
if (!result.canRewind) {
|
|
531
|
+
process.stderr.write(`Error: ${result.error || "Unexpected error"}
|
|
532
|
+
`);
|
|
533
|
+
gracefulShutdownSync(1);
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
process.stdout.write(`Files rewound to state at message ${options.rewindFiles}
|
|
537
|
+
`);
|
|
538
|
+
gracefulShutdownSync(0);
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
const hasValidResumeSessionId = typeof options.resume === "string" && (Boolean(validateUuid(options.resume)) || options.resume.endsWith(".jsonl"));
|
|
542
|
+
const isUsingSdkUrl = Boolean(options.sdkUrl);
|
|
543
|
+
if (!inputPrompt && !hasValidResumeSessionId && !isUsingSdkUrl) {
|
|
544
|
+
process.stderr.write(`Error: Input must be provided either through stdin or as a prompt argument when using --print
|
|
545
|
+
`);
|
|
546
|
+
gracefulShutdownSync(1);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (options.outputFormat === "stream-json" && !options.verbose) {
|
|
550
|
+
process.stderr.write(`Error: When using --print, --output-format=stream-json requires --verbose
|
|
551
|
+
`);
|
|
552
|
+
gracefulShutdownSync(1);
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
const allowedMcpTools = filterToolsByDenyRules(appState.mcp.tools, appState.toolPermissionContext);
|
|
556
|
+
let filteredTools = [...tools, ...allowedMcpTools];
|
|
557
|
+
const effectivePermissionPromptToolName = options.sdkUrl ? "stdio" : options.permissionPromptToolName;
|
|
558
|
+
const onPermissionPrompt = (details) => {
|
|
559
|
+
if (false) {}
|
|
560
|
+
notifySessionStateChanged("requires_action", details);
|
|
561
|
+
};
|
|
562
|
+
const canUseTool = getCanUseToolFn(effectivePermissionPromptToolName, structuredIO, () => getAppState().mcp.tools, onPermissionPrompt);
|
|
563
|
+
if (options.permissionPromptToolName) {
|
|
564
|
+
filteredTools = filteredTools.filter((tool) => !toolMatchesName(tool, options.permissionPromptToolName));
|
|
565
|
+
}
|
|
566
|
+
registerProcessOutputErrorHandlers();
|
|
567
|
+
headlessProfilerCheckpoint("after_loadInitialMessages");
|
|
568
|
+
await ensureModelStringsInitialized();
|
|
569
|
+
headlessProfilerCheckpoint("after_modelStrings");
|
|
570
|
+
const needsFullArray = options.outputFormat === "json" && options.verbose;
|
|
571
|
+
const messages = [];
|
|
572
|
+
let lastMessage;
|
|
573
|
+
const transformToStreamlined = null;
|
|
574
|
+
headlessProfilerCheckpoint("before_runHeadlessStreaming");
|
|
575
|
+
for await (const message of runHeadlessStreaming(structuredIO, appState.mcp.clients, [...commands, ...appState.mcp.commands], filteredTools, initialMessages, canUseTool, sdkMcpConfigs, getAppState, setAppState, agents, options, turnInterruptionState)) {
|
|
576
|
+
if (transformToStreamlined) {
|
|
577
|
+
const transformed = transformToStreamlined(message);
|
|
578
|
+
if (transformed) {
|
|
579
|
+
await structuredIO.write(transformed);
|
|
580
|
+
}
|
|
581
|
+
} else if (options.outputFormat === "stream-json" && options.verbose) {
|
|
582
|
+
await structuredIO.write(message);
|
|
583
|
+
}
|
|
584
|
+
if (message.type !== "control_response" && message.type !== "control_request" && message.type !== "control_cancel_request" && !(message.type === "system" && (message.subtype === "session_state_changed" || message.subtype === "task_notification" || message.subtype === "task_started" || message.subtype === "task_progress" || message.subtype === "post_turn_summary")) && message.type !== "stream_event" && message.type !== "keep_alive" && message.type !== "streamlined_text" && message.type !== "streamlined_tool_use_summary" && message.type !== "prompt_suggestion") {
|
|
585
|
+
if (needsFullArray) {
|
|
586
|
+
messages.push(message);
|
|
587
|
+
}
|
|
588
|
+
lastMessage = message;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
switch (options.outputFormat) {
|
|
592
|
+
case "json":
|
|
593
|
+
if (!lastMessage || lastMessage.type !== "result") {
|
|
594
|
+
throw new Error("No messages returned");
|
|
595
|
+
}
|
|
596
|
+
if (options.verbose) {
|
|
597
|
+
writeToStdout(jsonStringify(messages) + `
|
|
598
|
+
`);
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
writeToStdout(jsonStringify(lastMessage) + `
|
|
602
|
+
`);
|
|
603
|
+
break;
|
|
604
|
+
case "stream-json":
|
|
605
|
+
break;
|
|
606
|
+
default:
|
|
607
|
+
if (!lastMessage || lastMessage.type !== "result") {
|
|
608
|
+
throw new Error("No messages returned");
|
|
609
|
+
}
|
|
610
|
+
switch (lastMessage.subtype) {
|
|
611
|
+
case "success":
|
|
612
|
+
writeToStdout(lastMessage.result.endsWith(`
|
|
613
|
+
`) ? lastMessage.result : lastMessage.result + `
|
|
614
|
+
`);
|
|
615
|
+
break;
|
|
616
|
+
case "error_during_execution":
|
|
617
|
+
writeToStdout(`Execution error`);
|
|
618
|
+
break;
|
|
619
|
+
case "error_max_turns":
|
|
620
|
+
writeToStdout(`Error: Reached max turns (${options.maxTurns})`);
|
|
621
|
+
break;
|
|
622
|
+
case "error_max_budget_usd":
|
|
623
|
+
writeToStdout(`Error: Exceeded USD budget (${options.maxBudgetUsd})`);
|
|
624
|
+
break;
|
|
625
|
+
case "error_max_structured_output_retries":
|
|
626
|
+
writeToStdout(`Error: Failed to provide valid structured output after maximum retries`);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
logHeadlessProfilerTurn();
|
|
630
|
+
if (false) {}
|
|
631
|
+
gracefulShutdownSync(lastMessage?.type === "result" && lastMessage?.is_error ? 1 : 0);
|
|
632
|
+
}
|
|
633
|
+
function runHeadlessStreaming(structuredIO, mcpClients, commands, tools, initialMessages, canUseTool, sdkMcpConfigs, getAppState, setAppState, agents, options, turnInterruptionState) {
|
|
634
|
+
let running = false;
|
|
635
|
+
let runPhase;
|
|
636
|
+
let inputClosed = false;
|
|
637
|
+
let shutdownPromptInjected = false;
|
|
638
|
+
let heldBackResult = null;
|
|
639
|
+
let abortController;
|
|
640
|
+
const output = structuredIO.outbound;
|
|
641
|
+
const sigintHandler = () => {
|
|
642
|
+
logForDiagnosticsNoPII("info", "shutdown_signal", { signal: "SIGINT" });
|
|
643
|
+
if (abortController && !abortController.signal.aborted) {
|
|
644
|
+
abortController.abort();
|
|
645
|
+
}
|
|
646
|
+
gracefulShutdown(0);
|
|
647
|
+
};
|
|
648
|
+
process.on("SIGINT", sigintHandler);
|
|
649
|
+
registerCleanup(async () => {
|
|
650
|
+
const bg = {};
|
|
651
|
+
for (const t of getRunningTasks(getAppState())) {
|
|
652
|
+
if (isBackgroundTask(t))
|
|
653
|
+
bg[t.type] = (bg[t.type] ?? 0) + 1;
|
|
654
|
+
}
|
|
655
|
+
logForDiagnosticsNoPII("info", "run_state_at_shutdown", {
|
|
656
|
+
run_active: running,
|
|
657
|
+
run_phase: runPhase,
|
|
658
|
+
worker_status: getSessionState(),
|
|
659
|
+
internal_events_pending: structuredIO.internalEventsPending,
|
|
660
|
+
bg_tasks: bg
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
setPermissionModeChangedListener((newMode) => {
|
|
664
|
+
if (newMode === "default" || newMode === "acceptEdits" || newMode === "bypassPermissions" || newMode === "plan" || newMode === false || newMode === "dontAsk") {
|
|
665
|
+
output.enqueue({
|
|
666
|
+
type: "system",
|
|
667
|
+
subtype: "status",
|
|
668
|
+
status: null,
|
|
669
|
+
permissionMode: newMode,
|
|
670
|
+
uuid: randomUUID(),
|
|
671
|
+
session_id: getSessionId()
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
const suggestionState = {
|
|
676
|
+
abortController: null,
|
|
677
|
+
inflightPromise: null,
|
|
678
|
+
lastEmitted: null,
|
|
679
|
+
pendingSuggestion: null,
|
|
680
|
+
pendingLastEmittedEntry: null
|
|
681
|
+
};
|
|
682
|
+
let unsubscribeAuthStatus;
|
|
683
|
+
if (options.enableAuthStatus) {
|
|
684
|
+
const authStatusManager = AwsAuthStatusManager.getInstance();
|
|
685
|
+
unsubscribeAuthStatus = authStatusManager.subscribe((status) => {
|
|
686
|
+
output.enqueue({
|
|
687
|
+
type: "auth_status",
|
|
688
|
+
isAuthenticating: status.isAuthenticating,
|
|
689
|
+
output: status.output,
|
|
690
|
+
error: status.error,
|
|
691
|
+
uuid: randomUUID(),
|
|
692
|
+
session_id: getSessionId()
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
const rateLimitListener = (limits) => {
|
|
697
|
+
const rateLimitInfo = toSDKRateLimitInfo(limits);
|
|
698
|
+
if (rateLimitInfo) {
|
|
699
|
+
output.enqueue({
|
|
700
|
+
type: "rate_limit_event",
|
|
701
|
+
rate_limit_info: rateLimitInfo,
|
|
702
|
+
uuid: randomUUID(),
|
|
703
|
+
session_id: getSessionId()
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
statusListeners.add(rateLimitListener);
|
|
708
|
+
const mutableMessages = initialMessages;
|
|
709
|
+
let readFileState = extractReadFilesFromMessages(initialMessages, cwd(), READ_FILE_STATE_CACHE_SIZE);
|
|
710
|
+
const pendingSeeds = createFileStateCacheWithSizeLimit(READ_FILE_STATE_CACHE_SIZE);
|
|
711
|
+
const resumeInterruptedTurnEnv = process.env.CLAUDE_CODE_RESUME_INTERRUPTED_TURN;
|
|
712
|
+
if (turnInterruptionState && turnInterruptionState.kind !== "none" && resumeInterruptedTurnEnv) {
|
|
713
|
+
logForDebugging(`[print.ts] Auto-resuming interrupted turn (kind: ${turnInterruptionState.kind})`);
|
|
714
|
+
removeInterruptedMessage(mutableMessages, turnInterruptionState.message);
|
|
715
|
+
enqueue({
|
|
716
|
+
mode: "prompt",
|
|
717
|
+
value: turnInterruptionState.message.message.content,
|
|
718
|
+
uuid: randomUUID()
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
const modelOptions = getModelOptions();
|
|
722
|
+
const modelInfos = modelOptions.map((option) => {
|
|
723
|
+
const modelId = option.value === null ? "default" : option.value;
|
|
724
|
+
const resolvedModel = modelId === "default" ? getDefaultMainLoopModel() : parseUserSpecifiedModel(modelId);
|
|
725
|
+
const hasEffort = modelSupportsEffort(resolvedModel);
|
|
726
|
+
const hasAdaptiveThinking = modelSupportsAdaptiveThinking(resolvedModel);
|
|
727
|
+
const hasFastMode = isFastModeSupportedByModel(option.value);
|
|
728
|
+
const hasAutoMode = modelSupportsAutoMode(resolvedModel);
|
|
729
|
+
return {
|
|
730
|
+
value: modelId,
|
|
731
|
+
displayName: option.label,
|
|
732
|
+
description: option.description,
|
|
733
|
+
...hasEffort && {
|
|
734
|
+
supportsEffort: true,
|
|
735
|
+
supportedEffortLevels: modelSupportsMaxEffort(resolvedModel) ? [...EFFORT_LEVELS] : EFFORT_LEVELS.filter((l) => l !== "max")
|
|
736
|
+
},
|
|
737
|
+
...hasAdaptiveThinking && { supportsAdaptiveThinking: true },
|
|
738
|
+
...hasFastMode && { supportsFastMode: true },
|
|
739
|
+
...hasAutoMode && { supportsAutoMode: true }
|
|
740
|
+
};
|
|
741
|
+
});
|
|
742
|
+
let activeUserSpecifiedModel = options.userSpecifiedModel;
|
|
743
|
+
function injectModelSwitchBreadcrumbs(modelArg, resolvedModel) {
|
|
744
|
+
const breadcrumbs = createModelSwitchBreadcrumbs(modelArg, modelDisplayString(resolvedModel));
|
|
745
|
+
mutableMessages.push(...breadcrumbs);
|
|
746
|
+
for (const crumb of breadcrumbs) {
|
|
747
|
+
if (typeof crumb.message.content === "string" && crumb.message.content.includes(`<${LOCAL_COMMAND_STDOUT_TAG}>`)) {
|
|
748
|
+
output.enqueue({
|
|
749
|
+
type: "user",
|
|
750
|
+
message: crumb.message,
|
|
751
|
+
session_id: getSessionId(),
|
|
752
|
+
parent_tool_use_id: null,
|
|
753
|
+
uuid: crumb.uuid,
|
|
754
|
+
timestamp: crumb.timestamp,
|
|
755
|
+
isReplay: true
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
let sdkClients = [];
|
|
761
|
+
let sdkTools = [];
|
|
762
|
+
const elicitationRegistered = new Set;
|
|
763
|
+
function registerElicitationHandlers(clients) {
|
|
764
|
+
for (const connection of clients) {
|
|
765
|
+
if (connection.type !== "connected" || elicitationRegistered.has(connection.name)) {
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
if (connection.config.type === "sdk") {
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
const serverName = connection.name;
|
|
772
|
+
try {
|
|
773
|
+
connection.client.setRequestHandler(ElicitRequestSchema, async (request, extra) => {
|
|
774
|
+
logMCPDebug(serverName, `Elicitation request received in print mode: ${jsonStringify(request)}`);
|
|
775
|
+
const mode = request.params.mode === "url" ? "url" : "form";
|
|
776
|
+
logEvent("tengu_mcp_elicitation_shown", {
|
|
777
|
+
mode
|
|
778
|
+
});
|
|
779
|
+
const hookResponse = await runElicitationHooks(serverName, request.params, extra.signal);
|
|
780
|
+
if (hookResponse) {
|
|
781
|
+
logMCPDebug(serverName, `Elicitation resolved by hook: ${jsonStringify(hookResponse)}`);
|
|
782
|
+
logEvent("tengu_mcp_elicitation_response", {
|
|
783
|
+
mode,
|
|
784
|
+
action: hookResponse.action
|
|
785
|
+
});
|
|
786
|
+
return hookResponse;
|
|
787
|
+
}
|
|
788
|
+
const url = "url" in request.params ? request.params.url : undefined;
|
|
789
|
+
const requestedSchema = "requestedSchema" in request.params ? request.params.requestedSchema : undefined;
|
|
790
|
+
const elicitationId = "elicitationId" in request.params ? request.params.elicitationId : undefined;
|
|
791
|
+
const rawResult = await structuredIO.handleElicitation(serverName, request.params.message, requestedSchema, extra.signal, mode, url, elicitationId);
|
|
792
|
+
const result = await runElicitationResultHooks(serverName, rawResult, extra.signal, mode, elicitationId);
|
|
793
|
+
logEvent("tengu_mcp_elicitation_response", {
|
|
794
|
+
mode,
|
|
795
|
+
action: result.action
|
|
796
|
+
});
|
|
797
|
+
return result;
|
|
798
|
+
});
|
|
799
|
+
connection.client.setNotificationHandler(ElicitationCompleteNotificationSchema, (notification) => {
|
|
800
|
+
const { elicitationId } = notification.params;
|
|
801
|
+
logMCPDebug(serverName, `Elicitation completion notification: ${elicitationId}`);
|
|
802
|
+
executeNotificationHooks({
|
|
803
|
+
message: `MCP server "${serverName}" confirmed elicitation ${elicitationId} complete`,
|
|
804
|
+
notificationType: "elicitation_complete"
|
|
805
|
+
});
|
|
806
|
+
output.enqueue({
|
|
807
|
+
type: "system",
|
|
808
|
+
subtype: "elicitation_complete",
|
|
809
|
+
mcp_server_name: serverName,
|
|
810
|
+
elicitation_id: elicitationId,
|
|
811
|
+
uuid: randomUUID(),
|
|
812
|
+
session_id: getSessionId()
|
|
813
|
+
});
|
|
814
|
+
});
|
|
815
|
+
elicitationRegistered.add(serverName);
|
|
816
|
+
} catch {}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
async function updateSdkMcp() {
|
|
820
|
+
const currentServerNames = new Set(Object.keys(sdkMcpConfigs));
|
|
821
|
+
const connectedServerNames = new Set(sdkClients.map((c) => c.name));
|
|
822
|
+
const hasNewServers = Array.from(currentServerNames).some((name) => !connectedServerNames.has(name));
|
|
823
|
+
const hasRemovedServers = Array.from(connectedServerNames).some((name) => !currentServerNames.has(name));
|
|
824
|
+
const hasPendingSdkClients = sdkClients.some((c) => c.type === "pending");
|
|
825
|
+
const hasFailedSdkClients = sdkClients.some((c) => c.type === "failed");
|
|
826
|
+
const haveServersChanged = hasNewServers || hasRemovedServers || hasPendingSdkClients || hasFailedSdkClients;
|
|
827
|
+
if (haveServersChanged) {
|
|
828
|
+
for (const client of sdkClients) {
|
|
829
|
+
if (!currentServerNames.has(client.name)) {
|
|
830
|
+
if (client.type === "connected") {
|
|
831
|
+
await client.cleanup();
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
const sdkSetup = await setupSdkMcpClients(sdkMcpConfigs, (serverName, message) => structuredIO.sendMcpMessage(serverName, message));
|
|
836
|
+
sdkClients = sdkSetup.clients;
|
|
837
|
+
sdkTools = sdkSetup.tools;
|
|
838
|
+
const allSdkNames = uniq([...connectedServerNames, ...currentServerNames]);
|
|
839
|
+
setAppState((prev) => ({
|
|
840
|
+
...prev,
|
|
841
|
+
mcp: {
|
|
842
|
+
...prev.mcp,
|
|
843
|
+
tools: [
|
|
844
|
+
...prev.mcp.tools.filter((t) => !allSdkNames.some((name) => t.name.startsWith(getMcpPrefix(name)))),
|
|
845
|
+
...sdkTools
|
|
846
|
+
]
|
|
847
|
+
}
|
|
848
|
+
}));
|
|
849
|
+
setupVscodeSdkMcp(sdkClients);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
updateSdkMcp();
|
|
853
|
+
let dynamicMcpState = {
|
|
854
|
+
clients: [],
|
|
855
|
+
tools: [],
|
|
856
|
+
configs: {}
|
|
857
|
+
};
|
|
858
|
+
const buildAllTools = (appState) => {
|
|
859
|
+
const assembledTools = assembleToolPool(appState.toolPermissionContext, appState.mcp.tools);
|
|
860
|
+
let allTools = uniqBy(mergeAndFilterTools([...tools, ...sdkTools, ...dynamicMcpState.tools], assembledTools, appState.toolPermissionContext.mode), "name");
|
|
861
|
+
if (options.permissionPromptToolName) {
|
|
862
|
+
allTools = allTools.filter((tool) => !toolMatchesName(tool, options.permissionPromptToolName));
|
|
863
|
+
}
|
|
864
|
+
const initJsonSchema = getInitJsonSchema();
|
|
865
|
+
if (initJsonSchema && !options.jsonSchema) {
|
|
866
|
+
const syntheticOutputResult = createSyntheticOutputTool(initJsonSchema);
|
|
867
|
+
if ("tool" in syntheticOutputResult) {
|
|
868
|
+
allTools = [...allTools, syntheticOutputResult.tool];
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
return allTools;
|
|
872
|
+
};
|
|
873
|
+
let bridgeHandle = null;
|
|
874
|
+
let bridgeLastForwardedIndex = 0;
|
|
875
|
+
function forwardMessagesToBridge() {
|
|
876
|
+
if (!bridgeHandle)
|
|
877
|
+
return;
|
|
878
|
+
const startIndex = Math.min(bridgeLastForwardedIndex, mutableMessages.length);
|
|
879
|
+
const newMessages = mutableMessages.slice(startIndex).filter((m) => m.type === "user" || m.type === "assistant");
|
|
880
|
+
bridgeLastForwardedIndex = mutableMessages.length;
|
|
881
|
+
if (newMessages.length > 0) {
|
|
882
|
+
bridgeHandle.writeMessages(newMessages);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
let mcpChangesPromise = Promise.resolve({
|
|
886
|
+
response: {
|
|
887
|
+
added: [],
|
|
888
|
+
removed: [],
|
|
889
|
+
errors: {}
|
|
890
|
+
},
|
|
891
|
+
sdkServersChanged: false
|
|
892
|
+
});
|
|
893
|
+
function applyMcpServerChanges(servers) {
|
|
894
|
+
const doWork = async () => {
|
|
895
|
+
const oldSdkClientNames = new Set(sdkClients.map((c) => c.name));
|
|
896
|
+
const result = await handleMcpSetServers(servers, { configs: sdkMcpConfigs, clients: sdkClients, tools: sdkTools }, dynamicMcpState, setAppState);
|
|
897
|
+
for (const key of Object.keys(sdkMcpConfigs)) {
|
|
898
|
+
delete sdkMcpConfigs[key];
|
|
899
|
+
}
|
|
900
|
+
Object.assign(sdkMcpConfigs, result.newSdkState.configs);
|
|
901
|
+
sdkClients = result.newSdkState.clients;
|
|
902
|
+
sdkTools = result.newSdkState.tools;
|
|
903
|
+
dynamicMcpState = result.newDynamicState;
|
|
904
|
+
if (result.sdkServersChanged) {
|
|
905
|
+
const newSdkClientNames = new Set(sdkClients.map((c) => c.name));
|
|
906
|
+
const allSdkNames = uniq([...oldSdkClientNames, ...newSdkClientNames]);
|
|
907
|
+
setAppState((prev) => ({
|
|
908
|
+
...prev,
|
|
909
|
+
mcp: {
|
|
910
|
+
...prev.mcp,
|
|
911
|
+
tools: [
|
|
912
|
+
...prev.mcp.tools.filter((t) => !allSdkNames.some((name) => t.name.startsWith(getMcpPrefix(name)))),
|
|
913
|
+
...sdkTools
|
|
914
|
+
]
|
|
915
|
+
}
|
|
916
|
+
}));
|
|
917
|
+
}
|
|
918
|
+
return {
|
|
919
|
+
response: result.response,
|
|
920
|
+
sdkServersChanged: result.sdkServersChanged
|
|
921
|
+
};
|
|
922
|
+
};
|
|
923
|
+
mcpChangesPromise = mcpChangesPromise.then(doWork, doWork);
|
|
924
|
+
return mcpChangesPromise;
|
|
925
|
+
}
|
|
926
|
+
function buildMcpServerStatuses() {
|
|
927
|
+
const currentAppState = getAppState();
|
|
928
|
+
const currentMcpClients = currentAppState.mcp.clients;
|
|
929
|
+
const allMcpTools = uniqBy([...currentAppState.mcp.tools, ...dynamicMcpState.tools], "name");
|
|
930
|
+
const existingNames = new Set([
|
|
931
|
+
...currentMcpClients.map((c) => c.name),
|
|
932
|
+
...sdkClients.map((c) => c.name)
|
|
933
|
+
]);
|
|
934
|
+
return [
|
|
935
|
+
...currentMcpClients,
|
|
936
|
+
...sdkClients,
|
|
937
|
+
...dynamicMcpState.clients.filter((c) => !existingNames.has(c.name))
|
|
938
|
+
].map((connection) => {
|
|
939
|
+
let config;
|
|
940
|
+
if (connection.config.type === "sse" || connection.config.type === "http") {
|
|
941
|
+
config = {
|
|
942
|
+
type: connection.config.type,
|
|
943
|
+
url: connection.config.url,
|
|
944
|
+
headers: connection.config.headers,
|
|
945
|
+
oauth: connection.config.oauth
|
|
946
|
+
};
|
|
947
|
+
} else if (connection.config.type === "claudeai-proxy") {
|
|
948
|
+
config = {
|
|
949
|
+
type: "claudeai-proxy",
|
|
950
|
+
url: connection.config.url,
|
|
951
|
+
id: connection.config.id
|
|
952
|
+
};
|
|
953
|
+
} else if (connection.config.type === "stdio" || connection.config.type === undefined) {
|
|
954
|
+
config = {
|
|
955
|
+
type: "stdio",
|
|
956
|
+
command: connection.config.command,
|
|
957
|
+
args: connection.config.args
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
const serverTools = connection.type === "connected" ? filterToolsByServer(allMcpTools, connection.name).map((tool) => ({
|
|
961
|
+
name: tool.mcpInfo?.toolName ?? tool.name,
|
|
962
|
+
annotations: {
|
|
963
|
+
readOnly: tool.isReadOnly({}) || undefined,
|
|
964
|
+
destructive: tool.isDestructive?.({}) || undefined,
|
|
965
|
+
openWorld: tool.isOpenWorld?.({}) || undefined
|
|
966
|
+
}
|
|
967
|
+
})) : undefined;
|
|
968
|
+
let capabilities;
|
|
969
|
+
if (false) {}
|
|
970
|
+
return {
|
|
971
|
+
name: connection.name,
|
|
972
|
+
status: connection.type,
|
|
973
|
+
serverInfo: connection.type === "connected" ? connection.serverInfo : undefined,
|
|
974
|
+
error: connection.type === "failed" ? connection.error : undefined,
|
|
975
|
+
config,
|
|
976
|
+
scope: connection.config.scope,
|
|
977
|
+
tools: serverTools,
|
|
978
|
+
capabilities
|
|
979
|
+
};
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
async function installPluginsAndApplyMcpInBackground() {
|
|
983
|
+
try {
|
|
984
|
+
await Promise.all([
|
|
985
|
+
Promise.resolve(),
|
|
986
|
+
withDiagnosticsTiming("headless_managed_settings_wait", () => waitForRemoteManagedSettingsToLoad())
|
|
987
|
+
]);
|
|
988
|
+
const pluginsInstalled = await installPluginsForHeadless();
|
|
989
|
+
if (pluginsInstalled) {
|
|
990
|
+
await applyPluginMcpDiff();
|
|
991
|
+
}
|
|
992
|
+
} catch (error) {
|
|
993
|
+
logError(error);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
let pluginInstallPromise = null;
|
|
997
|
+
if (!isBareMode()) {
|
|
998
|
+
if (isEnvTruthy(process.env.CLAUDE_CODE_SYNC_PLUGIN_INSTALL)) {
|
|
999
|
+
pluginInstallPromise = installPluginsAndApplyMcpInBackground();
|
|
1000
|
+
} else {
|
|
1001
|
+
installPluginsAndApplyMcpInBackground();
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
const idleTimeout = createIdleTimeoutManager(() => !running);
|
|
1005
|
+
let currentCommands = commands;
|
|
1006
|
+
let currentAgents = agents;
|
|
1007
|
+
async function refreshPluginState() {
|
|
1008
|
+
const { agentDefinitions: freshAgentDefs } = await refreshActivePlugins(setAppState);
|
|
1009
|
+
currentCommands = await getCommands(cwd());
|
|
1010
|
+
const sdkAgents = currentAgents.filter((a) => a.source === "flagSettings");
|
|
1011
|
+
currentAgents = [...freshAgentDefs.allAgents, ...sdkAgents];
|
|
1012
|
+
}
|
|
1013
|
+
async function applyPluginMcpDiff() {
|
|
1014
|
+
const { servers: newConfigs } = await getAllMcpConfigs();
|
|
1015
|
+
const supportedConfigs = {};
|
|
1016
|
+
for (const [name, config] of Object.entries(newConfigs)) {
|
|
1017
|
+
const type = config.type;
|
|
1018
|
+
if (type === undefined || type === "stdio" || type === "sse" || type === "http" || type === "sdk") {
|
|
1019
|
+
supportedConfigs[name] = config;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
for (const [name, config] of Object.entries(sdkMcpConfigs)) {
|
|
1023
|
+
if (config.type === "sdk" && !(name in supportedConfigs)) {
|
|
1024
|
+
supportedConfigs[name] = config;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
const { response, sdkServersChanged } = await applyMcpServerChanges(supportedConfigs);
|
|
1028
|
+
if (sdkServersChanged) {
|
|
1029
|
+
updateSdkMcp();
|
|
1030
|
+
}
|
|
1031
|
+
logForDebugging(`Headless MCP refresh: added=${response.added.length}, removed=${response.removed.length}`);
|
|
1032
|
+
}
|
|
1033
|
+
const unsubscribeSkillChanges = skillChangeDetector.subscribe(() => {
|
|
1034
|
+
clearCommandsCache();
|
|
1035
|
+
getCommands(cwd()).then((newCommands) => {
|
|
1036
|
+
currentCommands = newCommands;
|
|
1037
|
+
});
|
|
1038
|
+
});
|
|
1039
|
+
const scheduleProactiveTick = undefined;
|
|
1040
|
+
subscribeToCommandQueue(() => {
|
|
1041
|
+
if (abortController && getCommandsByMaxPriority("now").length > 0) {
|
|
1042
|
+
abortController.abort("interrupt");
|
|
1043
|
+
}
|
|
1044
|
+
});
|
|
1045
|
+
const run = async () => {
|
|
1046
|
+
if (running) {
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
running = true;
|
|
1050
|
+
runPhase = undefined;
|
|
1051
|
+
notifySessionStateChanged("running");
|
|
1052
|
+
idleTimeout.stop();
|
|
1053
|
+
headlessProfilerCheckpoint("run_entry");
|
|
1054
|
+
await updateSdkMcp();
|
|
1055
|
+
headlessProfilerCheckpoint("after_updateSdkMcp");
|
|
1056
|
+
if (pluginInstallPromise) {
|
|
1057
|
+
const timeoutMs = parseInt(process.env.CLAUDE_CODE_SYNC_PLUGIN_INSTALL_TIMEOUT_MS || "", 10);
|
|
1058
|
+
if (timeoutMs > 0) {
|
|
1059
|
+
const timeout = sleep(timeoutMs).then(() => "timeout");
|
|
1060
|
+
const result = await Promise.race([pluginInstallPromise, timeout]);
|
|
1061
|
+
if (result === "timeout") {
|
|
1062
|
+
logError(new Error(`CLAUDE_CODE_SYNC_PLUGIN_INSTALL: plugin installation timed out after ${timeoutMs}ms`));
|
|
1063
|
+
logEvent("tengu_sync_plugin_install_timeout", {
|
|
1064
|
+
timeout_ms: timeoutMs
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
} else {
|
|
1068
|
+
await pluginInstallPromise;
|
|
1069
|
+
}
|
|
1070
|
+
pluginInstallPromise = null;
|
|
1071
|
+
await refreshPluginState();
|
|
1072
|
+
const { setupPluginHookHotReload } = await import("../utils/plugins/loadPluginHooks.js");
|
|
1073
|
+
setupPluginHookHotReload();
|
|
1074
|
+
}
|
|
1075
|
+
const isMainThread = (cmd) => cmd.agentId === undefined;
|
|
1076
|
+
try {
|
|
1077
|
+
let command;
|
|
1078
|
+
let waitingForAgents = false;
|
|
1079
|
+
const drainCommandQueue = async () => {
|
|
1080
|
+
while (command = dequeue(isMainThread)) {
|
|
1081
|
+
if (command.mode !== "prompt" && command.mode !== "orphaned-permission" && command.mode !== "task-notification") {
|
|
1082
|
+
throw new Error("only prompt commands are supported in streaming mode");
|
|
1083
|
+
}
|
|
1084
|
+
const batch = [command];
|
|
1085
|
+
if (command.mode === "prompt") {
|
|
1086
|
+
while (canBatchWith(command, peek(isMainThread))) {
|
|
1087
|
+
batch.push(dequeue(isMainThread));
|
|
1088
|
+
}
|
|
1089
|
+
if (batch.length > 1) {
|
|
1090
|
+
command = {
|
|
1091
|
+
...command,
|
|
1092
|
+
value: joinPromptValues(batch.map((c) => c.value)),
|
|
1093
|
+
uuid: batch.findLast((c) => c.uuid)?.uuid ?? command.uuid
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
const batchUuids = batch.map((c) => c.uuid).filter((u) => u !== undefined);
|
|
1098
|
+
if (options.replayUserMessages && batch.length > 1) {
|
|
1099
|
+
for (const c of batch) {
|
|
1100
|
+
if (c.uuid && c.uuid !== command.uuid) {
|
|
1101
|
+
output.enqueue({
|
|
1102
|
+
type: "user",
|
|
1103
|
+
message: { role: "user", content: c.value },
|
|
1104
|
+
session_id: getSessionId(),
|
|
1105
|
+
parent_tool_use_id: null,
|
|
1106
|
+
uuid: c.uuid,
|
|
1107
|
+
isReplay: true
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
const appState = getAppState();
|
|
1113
|
+
const allMcpClients = [
|
|
1114
|
+
...appState.mcp.clients,
|
|
1115
|
+
...sdkClients,
|
|
1116
|
+
...dynamicMcpState.clients
|
|
1117
|
+
];
|
|
1118
|
+
registerElicitationHandlers(allMcpClients);
|
|
1119
|
+
for (const client of allMcpClients) {
|
|
1120
|
+
reregisterChannelHandlerAfterReconnect(client);
|
|
1121
|
+
}
|
|
1122
|
+
const allTools = buildAllTools(appState);
|
|
1123
|
+
for (const uuid of batchUuids) {
|
|
1124
|
+
notifyCommandLifecycle(uuid, "started");
|
|
1125
|
+
}
|
|
1126
|
+
if (command.mode === "task-notification") {
|
|
1127
|
+
const notificationText = typeof command.value === "string" ? command.value : "";
|
|
1128
|
+
const taskIdMatch = notificationText.match(/<task-id>([^<]+)<\/task-id>/);
|
|
1129
|
+
const toolUseIdMatch = notificationText.match(/<tool-use-id>([^<]+)<\/tool-use-id>/);
|
|
1130
|
+
const outputFileMatch = notificationText.match(/<output-file>([^<]+)<\/output-file>/);
|
|
1131
|
+
const statusMatch = notificationText.match(/<status>([^<]+)<\/status>/);
|
|
1132
|
+
const summaryMatch = notificationText.match(/<summary>([^<]+)<\/summary>/);
|
|
1133
|
+
const isValidStatus = (s) => s === "completed" || s === "failed" || s === "stopped" || s === "killed";
|
|
1134
|
+
const rawStatus = statusMatch?.[1];
|
|
1135
|
+
const status = isValidStatus(rawStatus) ? rawStatus === "killed" ? "stopped" : rawStatus : "completed";
|
|
1136
|
+
const usageMatch = notificationText.match(/<usage>([\s\S]*?)<\/usage>/);
|
|
1137
|
+
const usageContent = usageMatch?.[1] ?? "";
|
|
1138
|
+
const totalTokensMatch = usageContent.match(/<total_tokens>(\d+)<\/total_tokens>/);
|
|
1139
|
+
const toolUsesMatch = usageContent.match(/<tool_uses>(\d+)<\/tool_uses>/);
|
|
1140
|
+
const durationMsMatch = usageContent.match(/<duration_ms>(\d+)<\/duration_ms>/);
|
|
1141
|
+
if (statusMatch) {
|
|
1142
|
+
output.enqueue({
|
|
1143
|
+
type: "system",
|
|
1144
|
+
subtype: "task_notification",
|
|
1145
|
+
task_id: taskIdMatch?.[1] ?? "",
|
|
1146
|
+
tool_use_id: toolUseIdMatch?.[1],
|
|
1147
|
+
status,
|
|
1148
|
+
output_file: outputFileMatch?.[1] ?? "",
|
|
1149
|
+
summary: summaryMatch?.[1] ?? "",
|
|
1150
|
+
usage: totalTokensMatch && toolUsesMatch ? {
|
|
1151
|
+
total_tokens: parseInt(totalTokensMatch[1], 10),
|
|
1152
|
+
tool_uses: parseInt(toolUsesMatch[1], 10),
|
|
1153
|
+
duration_ms: durationMsMatch ? parseInt(durationMsMatch[1], 10) : 0
|
|
1154
|
+
} : undefined,
|
|
1155
|
+
session_id: getSessionId(),
|
|
1156
|
+
uuid: randomUUID()
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
const input = command.value;
|
|
1161
|
+
if (structuredIO instanceof RemoteIO && command.mode === "prompt") {
|
|
1162
|
+
logEvent("tengu_bridge_message_received", {
|
|
1163
|
+
is_repl: false
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
suggestionState.abortController?.abort();
|
|
1167
|
+
suggestionState.abortController = null;
|
|
1168
|
+
suggestionState.pendingSuggestion = null;
|
|
1169
|
+
suggestionState.pendingLastEmittedEntry = null;
|
|
1170
|
+
if (suggestionState.lastEmitted) {
|
|
1171
|
+
if (command.mode === "prompt") {
|
|
1172
|
+
const inputText = typeof input === "string" ? input : input.find((b) => b.type === "text")?.text;
|
|
1173
|
+
if (typeof inputText === "string") {
|
|
1174
|
+
logSuggestionOutcome(suggestionState.lastEmitted.text, inputText, suggestionState.lastEmitted.emittedAt, suggestionState.lastEmitted.promptId, suggestionState.lastEmitted.generationRequestId);
|
|
1175
|
+
}
|
|
1176
|
+
suggestionState.lastEmitted = null;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
abortController = createAbortController();
|
|
1180
|
+
const turnStartTime = undefined;
|
|
1181
|
+
headlessProfilerCheckpoint("before_ask");
|
|
1182
|
+
startQueryProfile();
|
|
1183
|
+
const cmd = command;
|
|
1184
|
+
await runWithWorkload(cmd.workload ?? options.workload, async () => {
|
|
1185
|
+
for await (const message of ask({
|
|
1186
|
+
commands: uniqBy([...currentCommands, ...appState.mcp.commands], "name"),
|
|
1187
|
+
prompt: input,
|
|
1188
|
+
promptUuid: cmd.uuid,
|
|
1189
|
+
isMeta: cmd.isMeta,
|
|
1190
|
+
cwd: cwd(),
|
|
1191
|
+
tools: allTools,
|
|
1192
|
+
verbose: options.verbose,
|
|
1193
|
+
mcpClients: allMcpClients,
|
|
1194
|
+
thinkingConfig: options.thinkingConfig,
|
|
1195
|
+
maxTurns: options.maxTurns,
|
|
1196
|
+
maxBudgetUsd: options.maxBudgetUsd,
|
|
1197
|
+
taskBudget: options.taskBudget,
|
|
1198
|
+
canUseTool,
|
|
1199
|
+
userSpecifiedModel: activeUserSpecifiedModel,
|
|
1200
|
+
fallbackModel: options.fallbackModel,
|
|
1201
|
+
jsonSchema: getInitJsonSchema() ?? options.jsonSchema,
|
|
1202
|
+
mutableMessages,
|
|
1203
|
+
getReadFileCache: () => pendingSeeds.size === 0 ? readFileState : mergeFileStateCaches(readFileState, pendingSeeds),
|
|
1204
|
+
setReadFileCache: (cache) => {
|
|
1205
|
+
readFileState = cache;
|
|
1206
|
+
for (const [path, seed] of pendingSeeds.entries()) {
|
|
1207
|
+
const existing = readFileState.get(path);
|
|
1208
|
+
if (!existing || seed.timestamp > existing.timestamp) {
|
|
1209
|
+
readFileState.set(path, seed);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
pendingSeeds.clear();
|
|
1213
|
+
},
|
|
1214
|
+
customSystemPrompt: options.systemPrompt,
|
|
1215
|
+
appendSystemPrompt: options.appendSystemPrompt,
|
|
1216
|
+
getAppState,
|
|
1217
|
+
setAppState,
|
|
1218
|
+
abortController,
|
|
1219
|
+
replayUserMessages: options.replayUserMessages,
|
|
1220
|
+
includePartialMessages: options.includePartialMessages,
|
|
1221
|
+
handleElicitation: (serverName, params, elicitSignal) => structuredIO.handleElicitation(serverName, params.message, undefined, elicitSignal, params.mode, params.url, "elicitationId" in params ? params.elicitationId : undefined),
|
|
1222
|
+
agents: currentAgents,
|
|
1223
|
+
orphanedPermission: cmd.orphanedPermission,
|
|
1224
|
+
setSDKStatus: (status) => {
|
|
1225
|
+
output.enqueue({
|
|
1226
|
+
type: "system",
|
|
1227
|
+
subtype: "status",
|
|
1228
|
+
status,
|
|
1229
|
+
session_id: getSessionId(),
|
|
1230
|
+
uuid: randomUUID()
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
})) {
|
|
1234
|
+
forwardMessagesToBridge();
|
|
1235
|
+
if (message.type === "result") {
|
|
1236
|
+
for (const event of drainSdkEvents()) {
|
|
1237
|
+
output.enqueue(event);
|
|
1238
|
+
}
|
|
1239
|
+
const currentState = getAppState();
|
|
1240
|
+
if (getRunningTasks(currentState).some((t) => (t.type === "local_agent" || t.type === "local_workflow") && isBackgroundTask(t))) {
|
|
1241
|
+
heldBackResult = message;
|
|
1242
|
+
} else {
|
|
1243
|
+
heldBackResult = null;
|
|
1244
|
+
output.enqueue(message);
|
|
1245
|
+
}
|
|
1246
|
+
} else {
|
|
1247
|
+
for (const event of drainSdkEvents()) {
|
|
1248
|
+
output.enqueue(event);
|
|
1249
|
+
}
|
|
1250
|
+
output.enqueue(message);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
for (const uuid of batchUuids) {
|
|
1255
|
+
notifyCommandLifecycle(uuid, "completed");
|
|
1256
|
+
}
|
|
1257
|
+
forwardMessagesToBridge();
|
|
1258
|
+
bridgeHandle?.sendResult();
|
|
1259
|
+
if (false) {}
|
|
1260
|
+
if (options.promptSuggestions && !isEnvDefinedFalsy(process.env.CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION)) {
|
|
1261
|
+
const state = suggestionState;
|
|
1262
|
+
state.abortController?.abort();
|
|
1263
|
+
const localAbort = new AbortController;
|
|
1264
|
+
suggestionState.abortController = localAbort;
|
|
1265
|
+
const cacheSafeParams = getLastCacheSafeParams();
|
|
1266
|
+
if (!cacheSafeParams) {
|
|
1267
|
+
logSuggestionSuppressed("sdk_no_params", undefined, undefined, "sdk");
|
|
1268
|
+
} else {
|
|
1269
|
+
const ref = { promise: null };
|
|
1270
|
+
ref.promise = (async () => {
|
|
1271
|
+
try {
|
|
1272
|
+
const result = await tryGenerateSuggestion(localAbort, mutableMessages, getAppState, cacheSafeParams, "sdk");
|
|
1273
|
+
if (!result || localAbort.signal.aborted)
|
|
1274
|
+
return;
|
|
1275
|
+
const suggestionMsg = {
|
|
1276
|
+
type: "prompt_suggestion",
|
|
1277
|
+
suggestion: result.suggestion,
|
|
1278
|
+
uuid: randomUUID(),
|
|
1279
|
+
session_id: getSessionId()
|
|
1280
|
+
};
|
|
1281
|
+
const lastEmittedEntry = {
|
|
1282
|
+
text: result.suggestion,
|
|
1283
|
+
emittedAt: Date.now(),
|
|
1284
|
+
promptId: result.promptId,
|
|
1285
|
+
generationRequestId: result.generationRequestId
|
|
1286
|
+
};
|
|
1287
|
+
if (heldBackResult) {
|
|
1288
|
+
suggestionState.pendingSuggestion = suggestionMsg;
|
|
1289
|
+
suggestionState.pendingLastEmittedEntry = {
|
|
1290
|
+
text: lastEmittedEntry.text,
|
|
1291
|
+
promptId: lastEmittedEntry.promptId,
|
|
1292
|
+
generationRequestId: lastEmittedEntry.generationRequestId
|
|
1293
|
+
};
|
|
1294
|
+
} else {
|
|
1295
|
+
suggestionState.lastEmitted = lastEmittedEntry;
|
|
1296
|
+
output.enqueue(suggestionMsg);
|
|
1297
|
+
}
|
|
1298
|
+
} catch (error) {
|
|
1299
|
+
if (error instanceof Error && (error.name === "AbortError" || error.name === "APIUserAbortError")) {
|
|
1300
|
+
logSuggestionSuppressed("aborted", undefined, undefined, "sdk");
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
logError(toError(error));
|
|
1304
|
+
} finally {
|
|
1305
|
+
if (suggestionState.inflightPromise === ref.promise) {
|
|
1306
|
+
suggestionState.inflightPromise = null;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
})();
|
|
1310
|
+
suggestionState.inflightPromise = ref.promise;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
logHeadlessProfilerTurn();
|
|
1314
|
+
logQueryProfileReport();
|
|
1315
|
+
headlessProfilerStartTurn();
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
do {
|
|
1319
|
+
for (const event of drainSdkEvents()) {
|
|
1320
|
+
output.enqueue(event);
|
|
1321
|
+
}
|
|
1322
|
+
runPhase = "draining_commands";
|
|
1323
|
+
await drainCommandQueue();
|
|
1324
|
+
waitingForAgents = false;
|
|
1325
|
+
{
|
|
1326
|
+
const state = getAppState();
|
|
1327
|
+
const hasRunningBg = getRunningTasks(state).some((t) => isBackgroundTask(t) && t.type !== "in_process_teammate");
|
|
1328
|
+
const hasMainThreadQueued = peek(isMainThread) !== undefined;
|
|
1329
|
+
if (hasRunningBg || hasMainThreadQueued) {
|
|
1330
|
+
waitingForAgents = true;
|
|
1331
|
+
if (!hasMainThreadQueued) {
|
|
1332
|
+
runPhase = "waiting_for_agents";
|
|
1333
|
+
await sleep(100);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
} while (waitingForAgents);
|
|
1338
|
+
if (heldBackResult) {
|
|
1339
|
+
output.enqueue(heldBackResult);
|
|
1340
|
+
heldBackResult = null;
|
|
1341
|
+
if (suggestionState.pendingSuggestion) {
|
|
1342
|
+
output.enqueue(suggestionState.pendingSuggestion);
|
|
1343
|
+
if (suggestionState.pendingLastEmittedEntry) {
|
|
1344
|
+
suggestionState.lastEmitted = {
|
|
1345
|
+
...suggestionState.pendingLastEmittedEntry,
|
|
1346
|
+
emittedAt: Date.now()
|
|
1347
|
+
};
|
|
1348
|
+
suggestionState.pendingLastEmittedEntry = null;
|
|
1349
|
+
}
|
|
1350
|
+
suggestionState.pendingSuggestion = null;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
} catch (error) {
|
|
1354
|
+
try {
|
|
1355
|
+
await structuredIO.write({
|
|
1356
|
+
type: "result",
|
|
1357
|
+
subtype: "error_during_execution",
|
|
1358
|
+
duration_ms: 0,
|
|
1359
|
+
duration_api_ms: 0,
|
|
1360
|
+
is_error: true,
|
|
1361
|
+
num_turns: 0,
|
|
1362
|
+
stop_reason: null,
|
|
1363
|
+
session_id: getSessionId(),
|
|
1364
|
+
total_cost_usd: 0,
|
|
1365
|
+
usage: EMPTY_USAGE,
|
|
1366
|
+
modelUsage: {},
|
|
1367
|
+
permission_denials: [],
|
|
1368
|
+
uuid: randomUUID(),
|
|
1369
|
+
errors: [
|
|
1370
|
+
errorMessage(error),
|
|
1371
|
+
...getInMemoryErrors().map((_) => _.error)
|
|
1372
|
+
]
|
|
1373
|
+
});
|
|
1374
|
+
} catch {}
|
|
1375
|
+
suggestionState.abortController?.abort();
|
|
1376
|
+
gracefulShutdownSync(1);
|
|
1377
|
+
return;
|
|
1378
|
+
} finally {
|
|
1379
|
+
runPhase = "finally_flush";
|
|
1380
|
+
await structuredIO.flushInternalEvents();
|
|
1381
|
+
runPhase = "finally_post_flush";
|
|
1382
|
+
if (!isShuttingDown()) {
|
|
1383
|
+
notifySessionStateChanged("idle");
|
|
1384
|
+
for (const event of drainSdkEvents()) {
|
|
1385
|
+
output.enqueue(event);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
running = false;
|
|
1389
|
+
idleTimeout.start();
|
|
1390
|
+
}
|
|
1391
|
+
if (false) {}
|
|
1392
|
+
if (peek(isMainThread) !== undefined) {
|
|
1393
|
+
run();
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
{
|
|
1397
|
+
const currentAppState = getAppState();
|
|
1398
|
+
const teamContext = currentAppState.teamContext;
|
|
1399
|
+
if (teamContext && isTeamLead(teamContext)) {
|
|
1400
|
+
const agentName = "team-lead";
|
|
1401
|
+
const POLL_INTERVAL_MS = 500;
|
|
1402
|
+
while (true) {
|
|
1403
|
+
const refreshedState = getAppState();
|
|
1404
|
+
const hasActiveTeammates = hasActiveInProcessTeammates(refreshedState) || refreshedState.teamContext && Object.keys(refreshedState.teamContext.teammates).length > 0;
|
|
1405
|
+
if (!hasActiveTeammates) {
|
|
1406
|
+
logForDebugging("[print.ts] No more active teammates, stopping poll");
|
|
1407
|
+
break;
|
|
1408
|
+
}
|
|
1409
|
+
const unread = await readUnreadMessages(agentName, refreshedState.teamContext?.teamName);
|
|
1410
|
+
if (unread.length > 0) {
|
|
1411
|
+
logForDebugging(`[print.ts] Team-lead found ${unread.length} unread messages`);
|
|
1412
|
+
await markMessagesAsRead(agentName, refreshedState.teamContext?.teamName);
|
|
1413
|
+
const teamName = refreshedState.teamContext?.teamName;
|
|
1414
|
+
for (const m of unread) {
|
|
1415
|
+
const shutdownApproval = isShutdownApproved(m.text);
|
|
1416
|
+
if (shutdownApproval && teamName) {
|
|
1417
|
+
const teammateToRemove = shutdownApproval.from;
|
|
1418
|
+
logForDebugging(`[print.ts] Processing shutdown_approved from ${teammateToRemove}`);
|
|
1419
|
+
const teammateId = refreshedState.teamContext?.teammates ? Object.entries(refreshedState.teamContext.teammates).find(([, t]) => t.name === teammateToRemove)?.[0] : undefined;
|
|
1420
|
+
if (teammateId) {
|
|
1421
|
+
removeTeammateFromTeamFile(teamName, {
|
|
1422
|
+
agentId: teammateId,
|
|
1423
|
+
name: teammateToRemove
|
|
1424
|
+
});
|
|
1425
|
+
logForDebugging(`[print.ts] Removed ${teammateToRemove} from team file`);
|
|
1426
|
+
await unassignTeammateTasks(teamName, teammateId, teammateToRemove, "shutdown");
|
|
1427
|
+
setAppState((prev) => {
|
|
1428
|
+
if (!prev.teamContext?.teammates)
|
|
1429
|
+
return prev;
|
|
1430
|
+
if (!(teammateId in prev.teamContext.teammates))
|
|
1431
|
+
return prev;
|
|
1432
|
+
const { [teammateId]: _, ...remainingTeammates } = prev.teamContext.teammates;
|
|
1433
|
+
return {
|
|
1434
|
+
...prev,
|
|
1435
|
+
teamContext: {
|
|
1436
|
+
...prev.teamContext,
|
|
1437
|
+
teammates: remainingTeammates
|
|
1438
|
+
}
|
|
1439
|
+
};
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
const formatted = unread.map((m) => `<${TEAMMATE_MESSAGE_TAG} teammate_id="${m.from}"${m.color ? ` color="${m.color}"` : ""}>
|
|
1445
|
+
${m.text}
|
|
1446
|
+
</${TEAMMATE_MESSAGE_TAG}>`).join(`
|
|
1447
|
+
|
|
1448
|
+
`);
|
|
1449
|
+
enqueue({
|
|
1450
|
+
mode: "prompt",
|
|
1451
|
+
value: formatted,
|
|
1452
|
+
uuid: randomUUID()
|
|
1453
|
+
});
|
|
1454
|
+
run();
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
if (inputClosed && !shutdownPromptInjected) {
|
|
1458
|
+
shutdownPromptInjected = true;
|
|
1459
|
+
logForDebugging("[print.ts] Input closed with active teammates, injecting shutdown prompt");
|
|
1460
|
+
enqueue({
|
|
1461
|
+
mode: "prompt",
|
|
1462
|
+
value: SHUTDOWN_TEAM_PROMPT,
|
|
1463
|
+
uuid: randomUUID()
|
|
1464
|
+
});
|
|
1465
|
+
run();
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
await sleep(POLL_INTERVAL_MS);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
if (inputClosed) {
|
|
1473
|
+
const hasActiveSwarm = await (async () => {
|
|
1474
|
+
const currentAppState = getAppState();
|
|
1475
|
+
if (hasWorkingInProcessTeammates(currentAppState)) {
|
|
1476
|
+
await waitForTeammatesToBecomeIdle(setAppState, currentAppState);
|
|
1477
|
+
}
|
|
1478
|
+
const refreshedAppState = getAppState();
|
|
1479
|
+
const refreshedTeamContext = refreshedAppState.teamContext;
|
|
1480
|
+
const hasTeamMembersNotCleanedUp = refreshedTeamContext && Object.keys(refreshedTeamContext.teammates).length > 0;
|
|
1481
|
+
return hasTeamMembersNotCleanedUp || hasActiveInProcessTeammates(refreshedAppState);
|
|
1482
|
+
})();
|
|
1483
|
+
if (hasActiveSwarm) {
|
|
1484
|
+
enqueue({
|
|
1485
|
+
mode: "prompt",
|
|
1486
|
+
value: SHUTDOWN_TEAM_PROMPT,
|
|
1487
|
+
uuid: randomUUID()
|
|
1488
|
+
});
|
|
1489
|
+
run();
|
|
1490
|
+
} else {
|
|
1491
|
+
if (suggestionState.inflightPromise) {
|
|
1492
|
+
await Promise.race([suggestionState.inflightPromise, sleep(5000)]);
|
|
1493
|
+
}
|
|
1494
|
+
suggestionState.abortController?.abort();
|
|
1495
|
+
suggestionState.abortController = null;
|
|
1496
|
+
await finalizePendingAsyncHooks();
|
|
1497
|
+
unsubscribeSkillChanges();
|
|
1498
|
+
unsubscribeAuthStatus?.();
|
|
1499
|
+
statusListeners.delete(rateLimitListener);
|
|
1500
|
+
output.done();
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
if (false) {}
|
|
1505
|
+
let cronScheduler = null;
|
|
1506
|
+
if (false) {}
|
|
1507
|
+
const sendControlResponseSuccess = function(message, response) {
|
|
1508
|
+
output.enqueue({
|
|
1509
|
+
type: "control_response",
|
|
1510
|
+
response: {
|
|
1511
|
+
subtype: "success",
|
|
1512
|
+
request_id: message.request_id,
|
|
1513
|
+
response
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
};
|
|
1517
|
+
const sendControlResponseError = function(message, errorMessage) {
|
|
1518
|
+
output.enqueue({
|
|
1519
|
+
type: "control_response",
|
|
1520
|
+
response: {
|
|
1521
|
+
subtype: "error",
|
|
1522
|
+
request_id: message.request_id,
|
|
1523
|
+
error: errorMessage
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
};
|
|
1527
|
+
const handledOrphanedToolUseIds = new Set;
|
|
1528
|
+
structuredIO.setUnexpectedResponseCallback(async (message) => {
|
|
1529
|
+
await handleOrphanedPermissionResponse({
|
|
1530
|
+
message,
|
|
1531
|
+
setAppState,
|
|
1532
|
+
handledToolUseIds: handledOrphanedToolUseIds,
|
|
1533
|
+
onEnqueued: () => {
|
|
1534
|
+
run();
|
|
1535
|
+
}
|
|
1536
|
+
});
|
|
1537
|
+
});
|
|
1538
|
+
const activeOAuthFlows = new Map;
|
|
1539
|
+
const oauthCallbackSubmitters = new Map;
|
|
1540
|
+
const oauthManualCallbackUsed = new Set;
|
|
1541
|
+
const oauthAuthPromises = new Map;
|
|
1542
|
+
let claudeOAuth = null;
|
|
1543
|
+
(async () => {
|
|
1544
|
+
let initialized = false;
|
|
1545
|
+
logForDiagnosticsNoPII("info", "cli_message_loop_started");
|
|
1546
|
+
for await (const message of structuredIO.structuredInput) {
|
|
1547
|
+
const eventId = "uuid" in message ? message.uuid : undefined;
|
|
1548
|
+
if (eventId && message.type !== "user" && message.type !== "control_response") {
|
|
1549
|
+
notifyCommandLifecycle(eventId, "completed");
|
|
1550
|
+
}
|
|
1551
|
+
if (message.type === "control_request") {
|
|
1552
|
+
if (message.request.subtype === "interrupt") {
|
|
1553
|
+
if (false) {}
|
|
1554
|
+
if (abortController) {
|
|
1555
|
+
abortController.abort();
|
|
1556
|
+
}
|
|
1557
|
+
suggestionState.abortController?.abort();
|
|
1558
|
+
suggestionState.abortController = null;
|
|
1559
|
+
suggestionState.lastEmitted = null;
|
|
1560
|
+
suggestionState.pendingSuggestion = null;
|
|
1561
|
+
sendControlResponseSuccess(message);
|
|
1562
|
+
} else if (message.request.subtype === "end_session") {
|
|
1563
|
+
logForDebugging(`[print.ts] end_session received, reason=${message.request.reason ?? "unspecified"}`);
|
|
1564
|
+
if (abortController) {
|
|
1565
|
+
abortController.abort();
|
|
1566
|
+
}
|
|
1567
|
+
suggestionState.abortController?.abort();
|
|
1568
|
+
suggestionState.abortController = null;
|
|
1569
|
+
suggestionState.lastEmitted = null;
|
|
1570
|
+
suggestionState.pendingSuggestion = null;
|
|
1571
|
+
sendControlResponseSuccess(message);
|
|
1572
|
+
break;
|
|
1573
|
+
} else if (message.request.subtype === "initialize") {
|
|
1574
|
+
if (message.request.sdkMcpServers && message.request.sdkMcpServers.length > 0) {
|
|
1575
|
+
for (const serverName of message.request.sdkMcpServers) {
|
|
1576
|
+
sdkMcpConfigs[serverName] = {
|
|
1577
|
+
type: "sdk",
|
|
1578
|
+
name: serverName
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
await handleInitializeRequest(message.request, message.request_id, initialized, output, commands, modelInfos, structuredIO, !!options.enableAuthStatus, options, agents, getAppState);
|
|
1583
|
+
if (message.request.promptSuggestions) {
|
|
1584
|
+
setAppState((prev) => {
|
|
1585
|
+
if (prev.promptSuggestionEnabled)
|
|
1586
|
+
return prev;
|
|
1587
|
+
return { ...prev, promptSuggestionEnabled: true };
|
|
1588
|
+
});
|
|
1589
|
+
}
|
|
1590
|
+
if (message.request.agentProgressSummaries && getFeatureValue_CACHED_MAY_BE_STALE("tengu_slate_prism", true)) {
|
|
1591
|
+
setSdkAgentProgressSummariesEnabled(true);
|
|
1592
|
+
}
|
|
1593
|
+
initialized = true;
|
|
1594
|
+
if (hasCommandsInQueue()) {
|
|
1595
|
+
run();
|
|
1596
|
+
}
|
|
1597
|
+
} else if (message.request.subtype === "set_permission_mode") {
|
|
1598
|
+
const m = message.request;
|
|
1599
|
+
setAppState((prev) => ({
|
|
1600
|
+
...prev,
|
|
1601
|
+
toolPermissionContext: handleSetPermissionMode(m, message.request_id, prev.toolPermissionContext, output),
|
|
1602
|
+
isUltraplanMode: m.ultraplan ?? prev.isUltraplanMode
|
|
1603
|
+
}));
|
|
1604
|
+
} else if (message.request.subtype === "set_model") {
|
|
1605
|
+
const requestedModel = message.request.model ?? "default";
|
|
1606
|
+
const model = requestedModel === "default" ? getDefaultMainLoopModel() : requestedModel;
|
|
1607
|
+
activeUserSpecifiedModel = model;
|
|
1608
|
+
setMainLoopModelOverride(model);
|
|
1609
|
+
notifySessionMetadataChanged({ model });
|
|
1610
|
+
injectModelSwitchBreadcrumbs(requestedModel, model);
|
|
1611
|
+
sendControlResponseSuccess(message);
|
|
1612
|
+
} else if (message.request.subtype === "set_max_thinking_tokens") {
|
|
1613
|
+
if (message.request.max_thinking_tokens === null) {
|
|
1614
|
+
options.thinkingConfig = undefined;
|
|
1615
|
+
} else if (message.request.max_thinking_tokens === 0) {
|
|
1616
|
+
options.thinkingConfig = { type: "disabled" };
|
|
1617
|
+
} else {
|
|
1618
|
+
options.thinkingConfig = {
|
|
1619
|
+
type: "enabled",
|
|
1620
|
+
budgetTokens: message.request.max_thinking_tokens
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
sendControlResponseSuccess(message);
|
|
1624
|
+
} else if (message.request.subtype === "mcp_status") {
|
|
1625
|
+
sendControlResponseSuccess(message, {
|
|
1626
|
+
mcpServers: buildMcpServerStatuses()
|
|
1627
|
+
});
|
|
1628
|
+
} else if (message.request.subtype === "get_context_usage") {
|
|
1629
|
+
try {
|
|
1630
|
+
const appState = getAppState();
|
|
1631
|
+
const data = await collectContextData({
|
|
1632
|
+
messages: mutableMessages,
|
|
1633
|
+
getAppState,
|
|
1634
|
+
options: {
|
|
1635
|
+
mainLoopModel: getMainLoopModel(),
|
|
1636
|
+
tools: buildAllTools(appState),
|
|
1637
|
+
agentDefinitions: appState.agentDefinitions,
|
|
1638
|
+
customSystemPrompt: options.systemPrompt,
|
|
1639
|
+
appendSystemPrompt: options.appendSystemPrompt
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1642
|
+
sendControlResponseSuccess(message, { ...data });
|
|
1643
|
+
} catch (error) {
|
|
1644
|
+
sendControlResponseError(message, errorMessage(error));
|
|
1645
|
+
}
|
|
1646
|
+
} else if (message.request.subtype === "mcp_message") {
|
|
1647
|
+
const mcpRequest = message.request;
|
|
1648
|
+
const sdkClient = sdkClients.find((client) => client.name === mcpRequest.server_name);
|
|
1649
|
+
if (sdkClient && sdkClient.type === "connected" && sdkClient.client?.transport?.onmessage) {
|
|
1650
|
+
sdkClient.client.transport.onmessage(mcpRequest.message);
|
|
1651
|
+
}
|
|
1652
|
+
sendControlResponseSuccess(message);
|
|
1653
|
+
} else if (message.request.subtype === "rewind_files") {
|
|
1654
|
+
const appState = getAppState();
|
|
1655
|
+
const result = await handleRewindFiles(message.request.user_message_id, appState, setAppState, message.request.dry_run ?? false);
|
|
1656
|
+
if (result.canRewind || message.request.dry_run) {
|
|
1657
|
+
sendControlResponseSuccess(message, result);
|
|
1658
|
+
} else {
|
|
1659
|
+
sendControlResponseError(message, result.error ?? "Unexpected error");
|
|
1660
|
+
}
|
|
1661
|
+
} else if (message.request.subtype === "cancel_async_message") {
|
|
1662
|
+
const targetUuid = message.request.message_uuid;
|
|
1663
|
+
const removed = dequeueAllMatching((cmd) => cmd.uuid === targetUuid);
|
|
1664
|
+
sendControlResponseSuccess(message, {
|
|
1665
|
+
cancelled: removed.length > 0
|
|
1666
|
+
});
|
|
1667
|
+
} else if (message.request.subtype === "seed_read_state") {
|
|
1668
|
+
try {
|
|
1669
|
+
const normalizedPath = expandPath(message.request.path);
|
|
1670
|
+
const diskMtime = Math.floor((await stat(normalizedPath)).mtimeMs);
|
|
1671
|
+
if (diskMtime <= message.request.mtime) {
|
|
1672
|
+
const raw = await readFile(normalizedPath, "utf-8");
|
|
1673
|
+
const content = (raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw).replaceAll(`\r
|
|
1674
|
+
`, `
|
|
1675
|
+
`);
|
|
1676
|
+
pendingSeeds.set(normalizedPath, {
|
|
1677
|
+
content,
|
|
1678
|
+
timestamp: diskMtime,
|
|
1679
|
+
offset: undefined,
|
|
1680
|
+
limit: undefined
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
} catch {}
|
|
1684
|
+
sendControlResponseSuccess(message);
|
|
1685
|
+
} else if (message.request.subtype === "mcp_set_servers") {
|
|
1686
|
+
const { response, sdkServersChanged } = await applyMcpServerChanges(message.request.servers);
|
|
1687
|
+
sendControlResponseSuccess(message, response);
|
|
1688
|
+
if (sdkServersChanged) {
|
|
1689
|
+
updateSdkMcp();
|
|
1690
|
+
}
|
|
1691
|
+
} else if (message.request.subtype === "reload_plugins") {
|
|
1692
|
+
try {
|
|
1693
|
+
if (false) {}
|
|
1694
|
+
const r = await refreshActivePlugins(setAppState);
|
|
1695
|
+
const sdkAgents = currentAgents.filter((a) => a.source === "flagSettings");
|
|
1696
|
+
currentAgents = [...r.agentDefinitions.allAgents, ...sdkAgents];
|
|
1697
|
+
let plugins = [];
|
|
1698
|
+
const [cmdsR, mcpR, pluginsR] = await Promise.allSettled([
|
|
1699
|
+
getCommands(cwd()),
|
|
1700
|
+
applyPluginMcpDiff(),
|
|
1701
|
+
loadAllPluginsCacheOnly()
|
|
1702
|
+
]);
|
|
1703
|
+
if (cmdsR.status === "fulfilled") {
|
|
1704
|
+
currentCommands = cmdsR.value;
|
|
1705
|
+
} else {
|
|
1706
|
+
logError(cmdsR.reason);
|
|
1707
|
+
}
|
|
1708
|
+
if (mcpR.status === "rejected") {
|
|
1709
|
+
logError(mcpR.reason);
|
|
1710
|
+
}
|
|
1711
|
+
if (pluginsR.status === "fulfilled") {
|
|
1712
|
+
plugins = pluginsR.value.enabled.map((p) => ({
|
|
1713
|
+
name: p.name,
|
|
1714
|
+
path: p.path,
|
|
1715
|
+
source: p.source
|
|
1716
|
+
}));
|
|
1717
|
+
} else {
|
|
1718
|
+
logError(pluginsR.reason);
|
|
1719
|
+
}
|
|
1720
|
+
sendControlResponseSuccess(message, {
|
|
1721
|
+
commands: currentCommands.filter((cmd) => cmd.userInvocable !== false).map((cmd) => ({
|
|
1722
|
+
name: getCommandName(cmd),
|
|
1723
|
+
description: formatDescriptionWithSource(cmd),
|
|
1724
|
+
argumentHint: cmd.argumentHint || ""
|
|
1725
|
+
})),
|
|
1726
|
+
agents: currentAgents.map((a) => ({
|
|
1727
|
+
name: a.agentType,
|
|
1728
|
+
description: a.whenToUse,
|
|
1729
|
+
model: a.model === "inherit" ? undefined : a.model
|
|
1730
|
+
})),
|
|
1731
|
+
plugins,
|
|
1732
|
+
mcpServers: buildMcpServerStatuses(),
|
|
1733
|
+
error_count: r.error_count
|
|
1734
|
+
});
|
|
1735
|
+
} catch (error) {
|
|
1736
|
+
sendControlResponseError(message, errorMessage(error));
|
|
1737
|
+
}
|
|
1738
|
+
} else if (message.request.subtype === "mcp_reconnect") {
|
|
1739
|
+
const currentAppState = getAppState();
|
|
1740
|
+
const { serverName } = message.request;
|
|
1741
|
+
elicitationRegistered.delete(serverName);
|
|
1742
|
+
const config = getMcpConfigByName(serverName) ?? mcpClients.find((c) => c.name === serverName)?.config ?? sdkClients.find((c) => c.name === serverName)?.config ?? dynamicMcpState.clients.find((c) => c.name === serverName)?.config ?? currentAppState.mcp.clients.find((c) => c.name === serverName)?.config ?? null;
|
|
1743
|
+
if (!config) {
|
|
1744
|
+
sendControlResponseError(message, `Server not found: ${serverName}`);
|
|
1745
|
+
} else {
|
|
1746
|
+
const result = await reconnectMcpServerImpl(serverName, config);
|
|
1747
|
+
const prefix = getMcpPrefix(serverName);
|
|
1748
|
+
setAppState((prev) => ({
|
|
1749
|
+
...prev,
|
|
1750
|
+
mcp: {
|
|
1751
|
+
...prev.mcp,
|
|
1752
|
+
clients: prev.mcp.clients.map((c) => c.name === serverName ? result.client : c),
|
|
1753
|
+
tools: [
|
|
1754
|
+
...reject(prev.mcp.tools, (t) => t.name?.startsWith(prefix)),
|
|
1755
|
+
...result.tools
|
|
1756
|
+
],
|
|
1757
|
+
commands: [
|
|
1758
|
+
...reject(prev.mcp.commands, (c) => commandBelongsToServer(c, serverName)),
|
|
1759
|
+
...result.commands
|
|
1760
|
+
],
|
|
1761
|
+
resources: result.resources && result.resources.length > 0 ? { ...prev.mcp.resources, [serverName]: result.resources } : omit(prev.mcp.resources, serverName)
|
|
1762
|
+
}
|
|
1763
|
+
}));
|
|
1764
|
+
dynamicMcpState = {
|
|
1765
|
+
...dynamicMcpState,
|
|
1766
|
+
clients: [
|
|
1767
|
+
...dynamicMcpState.clients.filter((c) => c.name !== serverName),
|
|
1768
|
+
result.client
|
|
1769
|
+
],
|
|
1770
|
+
tools: [
|
|
1771
|
+
...dynamicMcpState.tools.filter((t) => !t.name?.startsWith(prefix)),
|
|
1772
|
+
...result.tools
|
|
1773
|
+
]
|
|
1774
|
+
};
|
|
1775
|
+
if (result.client.type === "connected") {
|
|
1776
|
+
registerElicitationHandlers([result.client]);
|
|
1777
|
+
reregisterChannelHandlerAfterReconnect(result.client);
|
|
1778
|
+
sendControlResponseSuccess(message);
|
|
1779
|
+
} else {
|
|
1780
|
+
const errorMessage = result.client.type === "failed" ? result.client.error ?? "Connection failed" : `Server status: ${result.client.type}`;
|
|
1781
|
+
sendControlResponseError(message, errorMessage);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
} else if (message.request.subtype === "mcp_toggle") {
|
|
1785
|
+
const currentAppState = getAppState();
|
|
1786
|
+
const { serverName, enabled } = message.request;
|
|
1787
|
+
elicitationRegistered.delete(serverName);
|
|
1788
|
+
const config = getMcpConfigByName(serverName) ?? mcpClients.find((c) => c.name === serverName)?.config ?? sdkClients.find((c) => c.name === serverName)?.config ?? dynamicMcpState.clients.find((c) => c.name === serverName)?.config ?? currentAppState.mcp.clients.find((c) => c.name === serverName)?.config ?? null;
|
|
1789
|
+
if (!config) {
|
|
1790
|
+
sendControlResponseError(message, `Server not found: ${serverName}`);
|
|
1791
|
+
} else if (!enabled) {
|
|
1792
|
+
setMcpServerEnabled(serverName, false);
|
|
1793
|
+
const client = [
|
|
1794
|
+
...mcpClients,
|
|
1795
|
+
...sdkClients,
|
|
1796
|
+
...dynamicMcpState.clients,
|
|
1797
|
+
...currentAppState.mcp.clients
|
|
1798
|
+
].find((c) => c.name === serverName);
|
|
1799
|
+
if (client && client.type === "connected") {
|
|
1800
|
+
await clearServerCache(serverName, config);
|
|
1801
|
+
}
|
|
1802
|
+
const prefix = getMcpPrefix(serverName);
|
|
1803
|
+
setAppState((prev) => ({
|
|
1804
|
+
...prev,
|
|
1805
|
+
mcp: {
|
|
1806
|
+
...prev.mcp,
|
|
1807
|
+
clients: prev.mcp.clients.map((c) => c.name === serverName ? { name: serverName, type: "disabled", config } : c),
|
|
1808
|
+
tools: reject(prev.mcp.tools, (t) => t.name?.startsWith(prefix)),
|
|
1809
|
+
commands: reject(prev.mcp.commands, (c) => commandBelongsToServer(c, serverName)),
|
|
1810
|
+
resources: omit(prev.mcp.resources, serverName)
|
|
1811
|
+
}
|
|
1812
|
+
}));
|
|
1813
|
+
sendControlResponseSuccess(message);
|
|
1814
|
+
} else {
|
|
1815
|
+
setMcpServerEnabled(serverName, true);
|
|
1816
|
+
const result = await reconnectMcpServerImpl(serverName, config);
|
|
1817
|
+
const prefix = getMcpPrefix(serverName);
|
|
1818
|
+
setAppState((prev) => ({
|
|
1819
|
+
...prev,
|
|
1820
|
+
mcp: {
|
|
1821
|
+
...prev.mcp,
|
|
1822
|
+
clients: prev.mcp.clients.map((c) => c.name === serverName ? result.client : c),
|
|
1823
|
+
tools: [
|
|
1824
|
+
...reject(prev.mcp.tools, (t) => t.name?.startsWith(prefix)),
|
|
1825
|
+
...result.tools
|
|
1826
|
+
],
|
|
1827
|
+
commands: [
|
|
1828
|
+
...reject(prev.mcp.commands, (c) => commandBelongsToServer(c, serverName)),
|
|
1829
|
+
...result.commands
|
|
1830
|
+
],
|
|
1831
|
+
resources: result.resources && result.resources.length > 0 ? { ...prev.mcp.resources, [serverName]: result.resources } : omit(prev.mcp.resources, serverName)
|
|
1832
|
+
}
|
|
1833
|
+
}));
|
|
1834
|
+
if (result.client.type === "connected") {
|
|
1835
|
+
registerElicitationHandlers([result.client]);
|
|
1836
|
+
reregisterChannelHandlerAfterReconnect(result.client);
|
|
1837
|
+
sendControlResponseSuccess(message);
|
|
1838
|
+
} else {
|
|
1839
|
+
const errorMessage = result.client.type === "failed" ? result.client.error ?? "Connection failed" : `Server status: ${result.client.type}`;
|
|
1840
|
+
sendControlResponseError(message, errorMessage);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
} else if (message.request.subtype === "channel_enable") {
|
|
1844
|
+
const currentAppState = getAppState();
|
|
1845
|
+
handleChannelEnable(message.request_id, message.request.serverName, [
|
|
1846
|
+
...currentAppState.mcp.clients,
|
|
1847
|
+
...sdkClients,
|
|
1848
|
+
...dynamicMcpState.clients
|
|
1849
|
+
], output);
|
|
1850
|
+
} else if (message.request.subtype === "mcp_authenticate") {
|
|
1851
|
+
const { serverName } = message.request;
|
|
1852
|
+
const currentAppState = getAppState();
|
|
1853
|
+
const config = getMcpConfigByName(serverName) ?? mcpClients.find((c) => c.name === serverName)?.config ?? currentAppState.mcp.clients.find((c) => c.name === serverName)?.config ?? null;
|
|
1854
|
+
if (!config) {
|
|
1855
|
+
sendControlResponseError(message, `Server not found: ${serverName}`);
|
|
1856
|
+
} else if (config.type !== "sse" && config.type !== "http") {
|
|
1857
|
+
sendControlResponseError(message, `Server type "${config.type}" does not support OAuth authentication`);
|
|
1858
|
+
} else {
|
|
1859
|
+
try {
|
|
1860
|
+
activeOAuthFlows.get(serverName)?.abort();
|
|
1861
|
+
const controller = new AbortController;
|
|
1862
|
+
activeOAuthFlows.set(serverName, controller);
|
|
1863
|
+
let resolveAuthUrl;
|
|
1864
|
+
const authUrlPromise = new Promise((resolve) => {
|
|
1865
|
+
resolveAuthUrl = resolve;
|
|
1866
|
+
});
|
|
1867
|
+
const oauthPromise = performMCPOAuthFlow(serverName, config, (url) => resolveAuthUrl(url), controller.signal, {
|
|
1868
|
+
skipBrowserOpen: true,
|
|
1869
|
+
onWaitingForCallback: (submit) => {
|
|
1870
|
+
oauthCallbackSubmitters.set(serverName, submit);
|
|
1871
|
+
}
|
|
1872
|
+
});
|
|
1873
|
+
const authUrl = await Promise.race([
|
|
1874
|
+
authUrlPromise,
|
|
1875
|
+
oauthPromise.then(() => null)
|
|
1876
|
+
]);
|
|
1877
|
+
if (authUrl) {
|
|
1878
|
+
sendControlResponseSuccess(message, {
|
|
1879
|
+
authUrl,
|
|
1880
|
+
requiresUserAction: true
|
|
1881
|
+
});
|
|
1882
|
+
} else {
|
|
1883
|
+
sendControlResponseSuccess(message, {
|
|
1884
|
+
requiresUserAction: false
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
oauthAuthPromises.set(serverName, oauthPromise);
|
|
1888
|
+
const fullFlowPromise = oauthPromise.then(async () => {
|
|
1889
|
+
if (isMcpServerDisabled(serverName)) {
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
if (oauthManualCallbackUsed.has(serverName)) {
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
const result = await reconnectMcpServerImpl(serverName, config);
|
|
1896
|
+
const prefix = getMcpPrefix(serverName);
|
|
1897
|
+
setAppState((prev) => ({
|
|
1898
|
+
...prev,
|
|
1899
|
+
mcp: {
|
|
1900
|
+
...prev.mcp,
|
|
1901
|
+
clients: prev.mcp.clients.map((c) => c.name === serverName ? result.client : c),
|
|
1902
|
+
tools: [
|
|
1903
|
+
...reject(prev.mcp.tools, (t) => t.name?.startsWith(prefix)),
|
|
1904
|
+
...result.tools
|
|
1905
|
+
],
|
|
1906
|
+
commands: [
|
|
1907
|
+
...reject(prev.mcp.commands, (c) => commandBelongsToServer(c, serverName)),
|
|
1908
|
+
...result.commands
|
|
1909
|
+
],
|
|
1910
|
+
resources: result.resources && result.resources.length > 0 ? {
|
|
1911
|
+
...prev.mcp.resources,
|
|
1912
|
+
[serverName]: result.resources
|
|
1913
|
+
} : omit(prev.mcp.resources, serverName)
|
|
1914
|
+
}
|
|
1915
|
+
}));
|
|
1916
|
+
dynamicMcpState = {
|
|
1917
|
+
...dynamicMcpState,
|
|
1918
|
+
clients: [
|
|
1919
|
+
...dynamicMcpState.clients.filter((c) => c.name !== serverName),
|
|
1920
|
+
result.client
|
|
1921
|
+
],
|
|
1922
|
+
tools: [
|
|
1923
|
+
...dynamicMcpState.tools.filter((t) => !t.name?.startsWith(prefix)),
|
|
1924
|
+
...result.tools
|
|
1925
|
+
]
|
|
1926
|
+
};
|
|
1927
|
+
}).catch((error) => {
|
|
1928
|
+
logForDebugging(`MCP OAuth failed for ${serverName}: ${error}`, { level: "error" });
|
|
1929
|
+
}).finally(() => {
|
|
1930
|
+
if (activeOAuthFlows.get(serverName) === controller) {
|
|
1931
|
+
activeOAuthFlows.delete(serverName);
|
|
1932
|
+
oauthCallbackSubmitters.delete(serverName);
|
|
1933
|
+
oauthManualCallbackUsed.delete(serverName);
|
|
1934
|
+
oauthAuthPromises.delete(serverName);
|
|
1935
|
+
}
|
|
1936
|
+
});
|
|
1937
|
+
} catch (error) {
|
|
1938
|
+
sendControlResponseError(message, errorMessage(error));
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
} else if (message.request.subtype === "mcp_oauth_callback_url") {
|
|
1942
|
+
const { serverName, callbackUrl } = message.request;
|
|
1943
|
+
const submit = oauthCallbackSubmitters.get(serverName);
|
|
1944
|
+
if (submit) {
|
|
1945
|
+
let hasCodeOrError = false;
|
|
1946
|
+
try {
|
|
1947
|
+
const parsed = new URL(callbackUrl);
|
|
1948
|
+
hasCodeOrError = parsed.searchParams.has("code") || parsed.searchParams.has("error");
|
|
1949
|
+
} catch {}
|
|
1950
|
+
if (!hasCodeOrError) {
|
|
1951
|
+
sendControlResponseError(message, "Invalid callback URL: missing authorization code. Please paste the full redirect URL including the code parameter.");
|
|
1952
|
+
} else {
|
|
1953
|
+
oauthManualCallbackUsed.add(serverName);
|
|
1954
|
+
submit(callbackUrl);
|
|
1955
|
+
const authPromise = oauthAuthPromises.get(serverName);
|
|
1956
|
+
if (authPromise) {
|
|
1957
|
+
try {
|
|
1958
|
+
await authPromise;
|
|
1959
|
+
sendControlResponseSuccess(message);
|
|
1960
|
+
} catch (error) {
|
|
1961
|
+
sendControlResponseError(message, error instanceof Error ? error.message : "OAuth authentication failed");
|
|
1962
|
+
}
|
|
1963
|
+
} else {
|
|
1964
|
+
sendControlResponseSuccess(message);
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
} else {
|
|
1968
|
+
sendControlResponseError(message, `No active OAuth flow for server: ${serverName}`);
|
|
1969
|
+
}
|
|
1970
|
+
} else if (message.request.subtype === "claude_authenticate") {
|
|
1971
|
+
const { loginWithClaudeAi } = message.request;
|
|
1972
|
+
claudeOAuth?.service.cleanup();
|
|
1973
|
+
logEvent("tengu_oauth_flow_start", {
|
|
1974
|
+
loginWithClaudeAi: loginWithClaudeAi ?? true
|
|
1975
|
+
});
|
|
1976
|
+
const service = new OAuthService;
|
|
1977
|
+
let urlResolver;
|
|
1978
|
+
const urlPromise = new Promise((resolve) => {
|
|
1979
|
+
urlResolver = resolve;
|
|
1980
|
+
});
|
|
1981
|
+
const flow = service.startOAuthFlow(async (manualUrl, automaticUrl) => {
|
|
1982
|
+
urlResolver({ manualUrl, automaticUrl });
|
|
1983
|
+
}, {
|
|
1984
|
+
loginWithClaudeAi: loginWithClaudeAi ?? true,
|
|
1985
|
+
skipBrowserOpen: true
|
|
1986
|
+
}).then(async (tokens) => {
|
|
1987
|
+
await installOAuthTokens(tokens);
|
|
1988
|
+
logEvent("tengu_oauth_success", {
|
|
1989
|
+
loginWithClaudeAi: loginWithClaudeAi ?? true
|
|
1990
|
+
});
|
|
1991
|
+
}).finally(() => {
|
|
1992
|
+
service.cleanup();
|
|
1993
|
+
if (claudeOAuth?.service === service) {
|
|
1994
|
+
claudeOAuth = null;
|
|
1995
|
+
}
|
|
1996
|
+
});
|
|
1997
|
+
claudeOAuth = { service, flow };
|
|
1998
|
+
flow.catch((err) => logForDebugging(`claude_authenticate flow ended: ${err}`, {
|
|
1999
|
+
level: "info"
|
|
2000
|
+
}));
|
|
2001
|
+
try {
|
|
2002
|
+
const { manualUrl, automaticUrl } = await Promise.race([
|
|
2003
|
+
urlPromise,
|
|
2004
|
+
flow.then(() => {
|
|
2005
|
+
throw new Error("OAuth flow completed without producing auth URLs");
|
|
2006
|
+
})
|
|
2007
|
+
]);
|
|
2008
|
+
sendControlResponseSuccess(message, {
|
|
2009
|
+
manualUrl,
|
|
2010
|
+
automaticUrl
|
|
2011
|
+
});
|
|
2012
|
+
} catch (error) {
|
|
2013
|
+
sendControlResponseError(message, errorMessage(error));
|
|
2014
|
+
}
|
|
2015
|
+
} else if (message.request.subtype === "claude_oauth_callback" || message.request.subtype === "claude_oauth_wait_for_completion") {
|
|
2016
|
+
if (!claudeOAuth) {
|
|
2017
|
+
sendControlResponseError(message, "No active claude_authenticate flow");
|
|
2018
|
+
} else {
|
|
2019
|
+
if (message.request.subtype === "claude_oauth_callback") {
|
|
2020
|
+
claudeOAuth.service.handleManualAuthCodeInput({
|
|
2021
|
+
authorizationCode: message.request.authorizationCode,
|
|
2022
|
+
state: message.request.state
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
const { flow } = claudeOAuth;
|
|
2026
|
+
flow.then(() => {
|
|
2027
|
+
const accountInfo = getAccountInformation();
|
|
2028
|
+
sendControlResponseSuccess(message, {
|
|
2029
|
+
account: {
|
|
2030
|
+
email: accountInfo?.email,
|
|
2031
|
+
organization: accountInfo?.organization,
|
|
2032
|
+
subscriptionType: accountInfo?.subscription,
|
|
2033
|
+
tokenSource: accountInfo?.tokenSource,
|
|
2034
|
+
apiKeySource: accountInfo?.apiKeySource,
|
|
2035
|
+
apiProvider: getAPIProvider()
|
|
2036
|
+
}
|
|
2037
|
+
});
|
|
2038
|
+
}, (error) => sendControlResponseError(message, errorMessage(error)));
|
|
2039
|
+
}
|
|
2040
|
+
} else if (message.request.subtype === "mcp_clear_auth") {
|
|
2041
|
+
const { serverName } = message.request;
|
|
2042
|
+
const currentAppState = getAppState();
|
|
2043
|
+
const config = getMcpConfigByName(serverName) ?? mcpClients.find((c) => c.name === serverName)?.config ?? currentAppState.mcp.clients.find((c) => c.name === serverName)?.config ?? null;
|
|
2044
|
+
if (!config) {
|
|
2045
|
+
sendControlResponseError(message, `Server not found: ${serverName}`);
|
|
2046
|
+
} else if (config.type !== "sse" && config.type !== "http") {
|
|
2047
|
+
sendControlResponseError(message, `Cannot clear auth for server type "${config.type}"`);
|
|
2048
|
+
} else {
|
|
2049
|
+
await revokeServerTokens(serverName, config);
|
|
2050
|
+
const result = await reconnectMcpServerImpl(serverName, config);
|
|
2051
|
+
const prefix = getMcpPrefix(serverName);
|
|
2052
|
+
setAppState((prev) => ({
|
|
2053
|
+
...prev,
|
|
2054
|
+
mcp: {
|
|
2055
|
+
...prev.mcp,
|
|
2056
|
+
clients: prev.mcp.clients.map((c) => c.name === serverName ? result.client : c),
|
|
2057
|
+
tools: [
|
|
2058
|
+
...reject(prev.mcp.tools, (t) => t.name?.startsWith(prefix)),
|
|
2059
|
+
...result.tools
|
|
2060
|
+
],
|
|
2061
|
+
commands: [
|
|
2062
|
+
...reject(prev.mcp.commands, (c) => commandBelongsToServer(c, serverName)),
|
|
2063
|
+
...result.commands
|
|
2064
|
+
],
|
|
2065
|
+
resources: result.resources && result.resources.length > 0 ? {
|
|
2066
|
+
...prev.mcp.resources,
|
|
2067
|
+
[serverName]: result.resources
|
|
2068
|
+
} : omit(prev.mcp.resources, serverName)
|
|
2069
|
+
}
|
|
2070
|
+
}));
|
|
2071
|
+
sendControlResponseSuccess(message, {});
|
|
2072
|
+
}
|
|
2073
|
+
} else if (message.request.subtype === "apply_flag_settings") {
|
|
2074
|
+
const prevModel = getMainLoopModel();
|
|
2075
|
+
const existing = getFlagSettingsInline() ?? {};
|
|
2076
|
+
const incoming = message.request.settings;
|
|
2077
|
+
const merged = { ...existing, ...incoming };
|
|
2078
|
+
for (const key of Object.keys(merged)) {
|
|
2079
|
+
if (merged[key] === null) {
|
|
2080
|
+
delete merged[key];
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
setFlagSettingsInline(merged);
|
|
2084
|
+
settingsChangeDetector.notifyChange("flagSettings");
|
|
2085
|
+
if ("model" in incoming) {
|
|
2086
|
+
if (incoming.model != null) {
|
|
2087
|
+
setMainLoopModelOverride(String(incoming.model));
|
|
2088
|
+
} else {
|
|
2089
|
+
setMainLoopModelOverride(undefined);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
const newModel = getMainLoopModel();
|
|
2093
|
+
if (newModel !== prevModel) {
|
|
2094
|
+
activeUserSpecifiedModel = newModel;
|
|
2095
|
+
const modelArg = incoming.model ? String(incoming.model) : "default";
|
|
2096
|
+
notifySessionMetadataChanged({ model: newModel });
|
|
2097
|
+
injectModelSwitchBreadcrumbs(modelArg, newModel);
|
|
2098
|
+
}
|
|
2099
|
+
sendControlResponseSuccess(message);
|
|
2100
|
+
} else if (message.request.subtype === "get_settings") {
|
|
2101
|
+
const currentAppState = getAppState();
|
|
2102
|
+
const model = getMainLoopModel();
|
|
2103
|
+
const effort = modelSupportsEffort(model) ? resolveAppliedEffort(model, currentAppState.effortValue) : undefined;
|
|
2104
|
+
sendControlResponseSuccess(message, {
|
|
2105
|
+
...getSettingsWithSources(),
|
|
2106
|
+
applied: {
|
|
2107
|
+
model,
|
|
2108
|
+
effort: typeof effort === "string" ? effort : null
|
|
2109
|
+
}
|
|
2110
|
+
});
|
|
2111
|
+
} else if (message.request.subtype === "stop_task") {
|
|
2112
|
+
const { task_id: taskId } = message.request;
|
|
2113
|
+
try {
|
|
2114
|
+
await stopTask(taskId, {
|
|
2115
|
+
getAppState,
|
|
2116
|
+
setAppState
|
|
2117
|
+
});
|
|
2118
|
+
sendControlResponseSuccess(message, {});
|
|
2119
|
+
} catch (error) {
|
|
2120
|
+
sendControlResponseError(message, errorMessage(error));
|
|
2121
|
+
}
|
|
2122
|
+
} else if (message.request.subtype === "generate_session_title") {
|
|
2123
|
+
const { description, persist } = message.request;
|
|
2124
|
+
const titleSignal = (abortController && !abortController.signal.aborted ? abortController : createAbortController()).signal;
|
|
2125
|
+
(async () => {
|
|
2126
|
+
try {
|
|
2127
|
+
const title = await generateSessionTitle(description, titleSignal);
|
|
2128
|
+
if (title && persist) {
|
|
2129
|
+
try {
|
|
2130
|
+
saveAiGeneratedTitle(getSessionId(), title);
|
|
2131
|
+
} catch (e) {
|
|
2132
|
+
logError(e);
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
sendControlResponseSuccess(message, { title });
|
|
2136
|
+
} catch (e) {
|
|
2137
|
+
sendControlResponseError(message, errorMessage(e));
|
|
2138
|
+
}
|
|
2139
|
+
})();
|
|
2140
|
+
} else if (message.request.subtype === "side_question") {
|
|
2141
|
+
const { question } = message.request;
|
|
2142
|
+
(async () => {
|
|
2143
|
+
try {
|
|
2144
|
+
const saved = getLastCacheSafeParams();
|
|
2145
|
+
const cacheSafeParams = saved ? {
|
|
2146
|
+
...saved,
|
|
2147
|
+
toolUseContext: {
|
|
2148
|
+
...saved.toolUseContext,
|
|
2149
|
+
abortController: createAbortController()
|
|
2150
|
+
}
|
|
2151
|
+
} : await buildSideQuestionFallbackParams({
|
|
2152
|
+
tools: buildAllTools(getAppState()),
|
|
2153
|
+
commands: currentCommands,
|
|
2154
|
+
mcpClients: [
|
|
2155
|
+
...getAppState().mcp.clients,
|
|
2156
|
+
...sdkClients,
|
|
2157
|
+
...dynamicMcpState.clients
|
|
2158
|
+
],
|
|
2159
|
+
messages: mutableMessages,
|
|
2160
|
+
readFileState,
|
|
2161
|
+
getAppState,
|
|
2162
|
+
setAppState,
|
|
2163
|
+
customSystemPrompt: options.systemPrompt,
|
|
2164
|
+
appendSystemPrompt: options.appendSystemPrompt,
|
|
2165
|
+
thinkingConfig: options.thinkingConfig,
|
|
2166
|
+
agents: currentAgents
|
|
2167
|
+
});
|
|
2168
|
+
const result = await runSideQuestion({
|
|
2169
|
+
question,
|
|
2170
|
+
cacheSafeParams
|
|
2171
|
+
});
|
|
2172
|
+
sendControlResponseSuccess(message, { response: result.response });
|
|
2173
|
+
} catch (e) {
|
|
2174
|
+
sendControlResponseError(message, errorMessage(e));
|
|
2175
|
+
}
|
|
2176
|
+
})();
|
|
2177
|
+
} else if (false) {} else if (message.request.subtype === "remote_control") {
|
|
2178
|
+
if (message.request.enabled) {
|
|
2179
|
+
if (bridgeHandle) {
|
|
2180
|
+
sendControlResponseSuccess(message, {
|
|
2181
|
+
session_url: getRemoteSessionUrl(bridgeHandle.bridgeSessionId, bridgeHandle.sessionIngressUrl),
|
|
2182
|
+
connect_url: buildBridgeConnectUrl(bridgeHandle.environmentId, bridgeHandle.sessionIngressUrl),
|
|
2183
|
+
environment_id: bridgeHandle.environmentId
|
|
2184
|
+
});
|
|
2185
|
+
} else {
|
|
2186
|
+
let bridgeFailureDetail;
|
|
2187
|
+
try {
|
|
2188
|
+
const { initReplBridge } = await import("../bridge/initReplBridge.js");
|
|
2189
|
+
const handle = await initReplBridge({
|
|
2190
|
+
onInboundMessage(msg) {
|
|
2191
|
+
const fields = extractInboundMessageFields(msg);
|
|
2192
|
+
if (!fields)
|
|
2193
|
+
return;
|
|
2194
|
+
const { content, uuid } = fields;
|
|
2195
|
+
enqueue({
|
|
2196
|
+
value: content,
|
|
2197
|
+
mode: "prompt",
|
|
2198
|
+
uuid,
|
|
2199
|
+
skipSlashCommands: true
|
|
2200
|
+
});
|
|
2201
|
+
run();
|
|
2202
|
+
},
|
|
2203
|
+
onPermissionResponse(response) {
|
|
2204
|
+
structuredIO.injectControlResponse(response);
|
|
2205
|
+
},
|
|
2206
|
+
onInterrupt() {
|
|
2207
|
+
abortController?.abort();
|
|
2208
|
+
},
|
|
2209
|
+
onSetModel(model) {
|
|
2210
|
+
const resolved = model === "default" ? getDefaultMainLoopModel() : model;
|
|
2211
|
+
activeUserSpecifiedModel = resolved;
|
|
2212
|
+
setMainLoopModelOverride(resolved);
|
|
2213
|
+
},
|
|
2214
|
+
onSetMaxThinkingTokens(maxTokens) {
|
|
2215
|
+
if (maxTokens === null) {
|
|
2216
|
+
options.thinkingConfig = undefined;
|
|
2217
|
+
} else if (maxTokens === 0) {
|
|
2218
|
+
options.thinkingConfig = { type: "disabled" };
|
|
2219
|
+
} else {
|
|
2220
|
+
options.thinkingConfig = {
|
|
2221
|
+
type: "enabled",
|
|
2222
|
+
budgetTokens: maxTokens
|
|
2223
|
+
};
|
|
2224
|
+
}
|
|
2225
|
+
},
|
|
2226
|
+
onStateChange(state, detail) {
|
|
2227
|
+
if (state === "failed") {
|
|
2228
|
+
bridgeFailureDetail = detail;
|
|
2229
|
+
}
|
|
2230
|
+
logForDebugging(`[bridge:sdk] State change: ${state}${detail ? ` — ${detail}` : ""}`);
|
|
2231
|
+
output.enqueue({
|
|
2232
|
+
type: "system",
|
|
2233
|
+
subtype: "bridge_state",
|
|
2234
|
+
state,
|
|
2235
|
+
detail,
|
|
2236
|
+
uuid: randomUUID(),
|
|
2237
|
+
session_id: getSessionId()
|
|
2238
|
+
});
|
|
2239
|
+
},
|
|
2240
|
+
initialMessages: mutableMessages.length > 0 ? mutableMessages : undefined
|
|
2241
|
+
});
|
|
2242
|
+
if (!handle) {
|
|
2243
|
+
sendControlResponseError(message, bridgeFailureDetail ?? "Remote Control initialization failed");
|
|
2244
|
+
} else {
|
|
2245
|
+
bridgeHandle = handle;
|
|
2246
|
+
bridgeLastForwardedIndex = mutableMessages.length;
|
|
2247
|
+
structuredIO.setOnControlRequestSent((request) => {
|
|
2248
|
+
handle.sendControlRequest(request);
|
|
2249
|
+
});
|
|
2250
|
+
structuredIO.setOnControlRequestResolved((requestId) => {
|
|
2251
|
+
handle.sendControlCancelRequest(requestId);
|
|
2252
|
+
});
|
|
2253
|
+
sendControlResponseSuccess(message, {
|
|
2254
|
+
session_url: getRemoteSessionUrl(handle.bridgeSessionId, handle.sessionIngressUrl),
|
|
2255
|
+
connect_url: buildBridgeConnectUrl(handle.environmentId, handle.sessionIngressUrl),
|
|
2256
|
+
environment_id: handle.environmentId
|
|
2257
|
+
});
|
|
2258
|
+
}
|
|
2259
|
+
} catch (err) {
|
|
2260
|
+
sendControlResponseError(message, errorMessage(err));
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
} else {
|
|
2264
|
+
if (bridgeHandle) {
|
|
2265
|
+
structuredIO.setOnControlRequestSent(undefined);
|
|
2266
|
+
structuredIO.setOnControlRequestResolved(undefined);
|
|
2267
|
+
await bridgeHandle.teardown();
|
|
2268
|
+
bridgeHandle = null;
|
|
2269
|
+
}
|
|
2270
|
+
sendControlResponseSuccess(message);
|
|
2271
|
+
}
|
|
2272
|
+
} else {
|
|
2273
|
+
sendControlResponseError(message, `Unsupported control request subtype: ${message.request.subtype}`);
|
|
2274
|
+
}
|
|
2275
|
+
continue;
|
|
2276
|
+
} else if (message.type === "control_response") {
|
|
2277
|
+
if (options.replayUserMessages) {
|
|
2278
|
+
output.enqueue(message);
|
|
2279
|
+
}
|
|
2280
|
+
continue;
|
|
2281
|
+
} else if (message.type === "keep_alive") {
|
|
2282
|
+
continue;
|
|
2283
|
+
} else if (message.type === "update_environment_variables") {
|
|
2284
|
+
continue;
|
|
2285
|
+
} else if (message.type === "assistant" || message.type === "system") {
|
|
2286
|
+
const internalMsgs = toInternalMessages([message]);
|
|
2287
|
+
mutableMessages.push(...internalMsgs);
|
|
2288
|
+
if (message.type === "assistant" && options.replayUserMessages) {
|
|
2289
|
+
output.enqueue(message);
|
|
2290
|
+
}
|
|
2291
|
+
continue;
|
|
2292
|
+
}
|
|
2293
|
+
if (message.type !== "user") {
|
|
2294
|
+
continue;
|
|
2295
|
+
}
|
|
2296
|
+
initialized = true;
|
|
2297
|
+
if (message.uuid) {
|
|
2298
|
+
const sessionId = getSessionId();
|
|
2299
|
+
const existsInSession = await doesMessageExistInSession(sessionId, message.uuid);
|
|
2300
|
+
if (existsInSession || receivedMessageUuids.has(message.uuid)) {
|
|
2301
|
+
logForDebugging(`Skipping duplicate user message: ${message.uuid}`);
|
|
2302
|
+
if (options.replayUserMessages) {
|
|
2303
|
+
logForDebugging(`Sending acknowledgment for duplicate user message: ${message.uuid}`);
|
|
2304
|
+
output.enqueue({
|
|
2305
|
+
type: "user",
|
|
2306
|
+
message: message.message,
|
|
2307
|
+
session_id: sessionId,
|
|
2308
|
+
parent_tool_use_id: null,
|
|
2309
|
+
uuid: message.uuid,
|
|
2310
|
+
timestamp: message.timestamp,
|
|
2311
|
+
isReplay: true
|
|
2312
|
+
});
|
|
2313
|
+
}
|
|
2314
|
+
if (existsInSession) {
|
|
2315
|
+
notifyCommandLifecycle(message.uuid, "completed");
|
|
2316
|
+
}
|
|
2317
|
+
continue;
|
|
2318
|
+
}
|
|
2319
|
+
trackReceivedMessageUuid(message.uuid);
|
|
2320
|
+
}
|
|
2321
|
+
enqueue({
|
|
2322
|
+
mode: "prompt",
|
|
2323
|
+
value: await resolveAndPrepend(message, message.message.content),
|
|
2324
|
+
uuid: message.uuid,
|
|
2325
|
+
priority: message.priority
|
|
2326
|
+
});
|
|
2327
|
+
if (false) {}
|
|
2328
|
+
run();
|
|
2329
|
+
}
|
|
2330
|
+
inputClosed = true;
|
|
2331
|
+
cronScheduler?.stop();
|
|
2332
|
+
if (!running) {
|
|
2333
|
+
if (suggestionState.inflightPromise) {
|
|
2334
|
+
await Promise.race([suggestionState.inflightPromise, sleep(5000)]);
|
|
2335
|
+
}
|
|
2336
|
+
suggestionState.abortController?.abort();
|
|
2337
|
+
suggestionState.abortController = null;
|
|
2338
|
+
await finalizePendingAsyncHooks();
|
|
2339
|
+
unsubscribeSkillChanges();
|
|
2340
|
+
unsubscribeAuthStatus?.();
|
|
2341
|
+
statusListeners.delete(rateLimitListener);
|
|
2342
|
+
output.done();
|
|
2343
|
+
}
|
|
2344
|
+
})();
|
|
2345
|
+
return output;
|
|
2346
|
+
}
|
|
2347
|
+
export function createCanUseToolWithPermissionPrompt(permissionPromptTool) {
|
|
2348
|
+
const canUseTool = async (tool, input, toolUseContext, assistantMessage, toolUseId, forceDecision) => {
|
|
2349
|
+
const mainPermissionResult = forceDecision ?? await hasPermissionsToUseTool(tool, input, toolUseContext, assistantMessage, toolUseId);
|
|
2350
|
+
if (mainPermissionResult.behavior === "allow" || mainPermissionResult.behavior === "deny") {
|
|
2351
|
+
return mainPermissionResult;
|
|
2352
|
+
}
|
|
2353
|
+
const { signal: combinedSignal, cleanup: cleanupAbortListener } = createCombinedAbortSignal(toolUseContext.abortController.signal);
|
|
2354
|
+
if (combinedSignal.aborted) {
|
|
2355
|
+
cleanupAbortListener();
|
|
2356
|
+
return {
|
|
2357
|
+
behavior: "deny",
|
|
2358
|
+
message: "Permission prompt was aborted.",
|
|
2359
|
+
decisionReason: {
|
|
2360
|
+
type: "permissionPromptTool",
|
|
2361
|
+
permissionPromptToolName: tool.name,
|
|
2362
|
+
toolResult: undefined
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2365
|
+
}
|
|
2366
|
+
const abortPromise = new Promise((resolve) => {
|
|
2367
|
+
combinedSignal.addEventListener("abort", () => resolve("aborted"), {
|
|
2368
|
+
once: true
|
|
2369
|
+
});
|
|
2370
|
+
});
|
|
2371
|
+
const toolCallPromise = permissionPromptTool.call({
|
|
2372
|
+
tool_name: tool.name,
|
|
2373
|
+
input,
|
|
2374
|
+
tool_use_id: toolUseId
|
|
2375
|
+
}, toolUseContext, canUseTool, assistantMessage);
|
|
2376
|
+
const raceResult = await Promise.race([toolCallPromise, abortPromise]);
|
|
2377
|
+
cleanupAbortListener();
|
|
2378
|
+
if (raceResult === "aborted" || combinedSignal.aborted) {
|
|
2379
|
+
return {
|
|
2380
|
+
behavior: "deny",
|
|
2381
|
+
message: "Permission prompt was aborted.",
|
|
2382
|
+
decisionReason: {
|
|
2383
|
+
type: "permissionPromptTool",
|
|
2384
|
+
permissionPromptToolName: tool.name,
|
|
2385
|
+
toolResult: undefined
|
|
2386
|
+
}
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2389
|
+
const result = raceResult;
|
|
2390
|
+
const permissionToolResultBlockParam = permissionPromptTool.mapToolResultToToolResultBlockParam(result.data, "1");
|
|
2391
|
+
if (!permissionToolResultBlockParam.content || !Array.isArray(permissionToolResultBlockParam.content) || !permissionToolResultBlockParam.content[0] || permissionToolResultBlockParam.content[0].type !== "text" || typeof permissionToolResultBlockParam.content[0].text !== "string") {
|
|
2392
|
+
throw new Error('Permission prompt tool returned an invalid result. Expected a single text block param with type="text" and a string text value.');
|
|
2393
|
+
}
|
|
2394
|
+
return permissionPromptToolResultToPermissionDecision(permissionToolOutputSchema().parse(safeParseJSON(permissionToolResultBlockParam.content[0].text)), permissionPromptTool, input, toolUseContext);
|
|
2395
|
+
};
|
|
2396
|
+
return canUseTool;
|
|
2397
|
+
}
|
|
2398
|
+
export function getCanUseToolFn(permissionPromptToolName, structuredIO, getMcpTools, onPermissionPrompt) {
|
|
2399
|
+
if (permissionPromptToolName === "stdio") {
|
|
2400
|
+
return structuredIO.createCanUseTool(onPermissionPrompt);
|
|
2401
|
+
}
|
|
2402
|
+
if (!permissionPromptToolName) {
|
|
2403
|
+
return async (tool, input, toolUseContext, assistantMessage, toolUseId, forceDecision) => forceDecision ?? await hasPermissionsToUseTool(tool, input, toolUseContext, assistantMessage, toolUseId);
|
|
2404
|
+
}
|
|
2405
|
+
let resolved = null;
|
|
2406
|
+
return async (tool, input, toolUseContext, assistantMessage, toolUseId, forceDecision) => {
|
|
2407
|
+
if (!resolved) {
|
|
2408
|
+
const mcpTools = getMcpTools();
|
|
2409
|
+
const permissionPromptTool = mcpTools.find((t) => toolMatchesName(t, permissionPromptToolName));
|
|
2410
|
+
if (!permissionPromptTool) {
|
|
2411
|
+
const error = `Error: MCP tool ${permissionPromptToolName} (passed via --permission-prompt-tool) not found. Available MCP tools: ${mcpTools.map((t) => t.name).join(", ") || "none"}`;
|
|
2412
|
+
process.stderr.write(`${error}
|
|
2413
|
+
`);
|
|
2414
|
+
gracefulShutdownSync(1);
|
|
2415
|
+
throw new Error(error);
|
|
2416
|
+
}
|
|
2417
|
+
if (!permissionPromptTool.inputJSONSchema) {
|
|
2418
|
+
const error = `Error: tool ${permissionPromptToolName} (passed via --permission-prompt-tool) must be an MCP tool`;
|
|
2419
|
+
process.stderr.write(`${error}
|
|
2420
|
+
`);
|
|
2421
|
+
gracefulShutdownSync(1);
|
|
2422
|
+
throw new Error(error);
|
|
2423
|
+
}
|
|
2424
|
+
resolved = createCanUseToolWithPermissionPrompt(permissionPromptTool);
|
|
2425
|
+
}
|
|
2426
|
+
return resolved(tool, input, toolUseContext, assistantMessage, toolUseId, forceDecision);
|
|
2427
|
+
};
|
|
2428
|
+
}
|
|
2429
|
+
async function handleInitializeRequest(request, requestId, initialized, output, commands, modelInfos, structuredIO, enableAuthStatus, options, agents, getAppState) {
|
|
2430
|
+
if (initialized) {
|
|
2431
|
+
output.enqueue({
|
|
2432
|
+
type: "control_response",
|
|
2433
|
+
response: {
|
|
2434
|
+
subtype: "error",
|
|
2435
|
+
error: "Already initialized",
|
|
2436
|
+
request_id: requestId,
|
|
2437
|
+
pending_permission_requests: structuredIO.getPendingPermissionRequests()
|
|
2438
|
+
}
|
|
2439
|
+
});
|
|
2440
|
+
return;
|
|
2441
|
+
}
|
|
2442
|
+
if (request.systemPrompt !== undefined) {
|
|
2443
|
+
options.systemPrompt = request.systemPrompt;
|
|
2444
|
+
}
|
|
2445
|
+
if (request.appendSystemPrompt !== undefined) {
|
|
2446
|
+
options.appendSystemPrompt = request.appendSystemPrompt;
|
|
2447
|
+
}
|
|
2448
|
+
if (request.promptSuggestions !== undefined) {
|
|
2449
|
+
options.promptSuggestions = request.promptSuggestions;
|
|
2450
|
+
}
|
|
2451
|
+
if (request.agents) {
|
|
2452
|
+
const stdinAgents = parseAgentsFromJson(request.agents, "flagSettings");
|
|
2453
|
+
agents.push(...stdinAgents);
|
|
2454
|
+
}
|
|
2455
|
+
if (options.agent) {
|
|
2456
|
+
const alreadyResolved = getMainThreadAgentType() === options.agent;
|
|
2457
|
+
const mainThreadAgent = agents.find((a) => a.agentType === options.agent);
|
|
2458
|
+
if (mainThreadAgent && !alreadyResolved) {
|
|
2459
|
+
setMainThreadAgentType(mainThreadAgent.agentType);
|
|
2460
|
+
if (!options.systemPrompt && !isBuiltInAgent(mainThreadAgent)) {
|
|
2461
|
+
const agentSystemPrompt = mainThreadAgent.getSystemPrompt();
|
|
2462
|
+
if (agentSystemPrompt) {
|
|
2463
|
+
options.systemPrompt = agentSystemPrompt;
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
if (!options.userSpecifiedModel && mainThreadAgent.model && mainThreadAgent.model !== "inherit") {
|
|
2467
|
+
const agentModel = parseUserSpecifiedModel(mainThreadAgent.model);
|
|
2468
|
+
setMainLoopModelOverride(agentModel);
|
|
2469
|
+
}
|
|
2470
|
+
if (mainThreadAgent.initialPrompt) {
|
|
2471
|
+
structuredIO.prependUserMessage(mainThreadAgent.initialPrompt);
|
|
2472
|
+
}
|
|
2473
|
+
} else if (mainThreadAgent?.initialPrompt) {
|
|
2474
|
+
structuredIO.prependUserMessage(mainThreadAgent.initialPrompt);
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
const settings = getSettings_DEPRECATED();
|
|
2478
|
+
const outputStyle = settings?.outputStyle || DEFAULT_OUTPUT_STYLE_NAME;
|
|
2479
|
+
const availableOutputStyles = await getAllOutputStyles(getCwd());
|
|
2480
|
+
const accountInfo = getAccountInformation();
|
|
2481
|
+
if (request.hooks) {
|
|
2482
|
+
const hooks = {};
|
|
2483
|
+
for (const [event, matchers] of Object.entries(request.hooks)) {
|
|
2484
|
+
hooks[event] = matchers.map((matcher) => {
|
|
2485
|
+
const callbacks = matcher.hookCallbackIds.map((callbackId) => {
|
|
2486
|
+
return structuredIO.createHookCallback(callbackId, matcher.timeout);
|
|
2487
|
+
});
|
|
2488
|
+
return {
|
|
2489
|
+
matcher: matcher.matcher,
|
|
2490
|
+
hooks: callbacks
|
|
2491
|
+
};
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
registerHookCallbacks(hooks);
|
|
2495
|
+
}
|
|
2496
|
+
if (request.jsonSchema) {
|
|
2497
|
+
setInitJsonSchema(request.jsonSchema);
|
|
2498
|
+
}
|
|
2499
|
+
const initResponse = {
|
|
2500
|
+
commands: commands.filter((cmd) => cmd.userInvocable !== false).map((cmd) => ({
|
|
2501
|
+
name: getCommandName(cmd),
|
|
2502
|
+
description: formatDescriptionWithSource(cmd),
|
|
2503
|
+
argumentHint: cmd.argumentHint || ""
|
|
2504
|
+
})),
|
|
2505
|
+
agents: agents.map((agent) => ({
|
|
2506
|
+
name: agent.agentType,
|
|
2507
|
+
description: agent.whenToUse,
|
|
2508
|
+
model: agent.model === "inherit" ? undefined : agent.model
|
|
2509
|
+
})),
|
|
2510
|
+
output_style: outputStyle,
|
|
2511
|
+
available_output_styles: Object.keys(availableOutputStyles),
|
|
2512
|
+
models: modelInfos,
|
|
2513
|
+
account: {
|
|
2514
|
+
email: accountInfo?.email,
|
|
2515
|
+
organization: accountInfo?.organization,
|
|
2516
|
+
subscriptionType: accountInfo?.subscription,
|
|
2517
|
+
tokenSource: accountInfo?.tokenSource,
|
|
2518
|
+
apiKeySource: accountInfo?.apiKeySource,
|
|
2519
|
+
apiProvider: getAPIProvider()
|
|
2520
|
+
},
|
|
2521
|
+
pid: process.pid
|
|
2522
|
+
};
|
|
2523
|
+
if (isFastModeEnabled() && isFastModeAvailable()) {
|
|
2524
|
+
const appState = getAppState();
|
|
2525
|
+
initResponse.fast_mode_state = getFastModeState(options.userSpecifiedModel ?? null, appState.fastMode);
|
|
2526
|
+
}
|
|
2527
|
+
output.enqueue({
|
|
2528
|
+
type: "control_response",
|
|
2529
|
+
response: {
|
|
2530
|
+
subtype: "success",
|
|
2531
|
+
request_id: requestId,
|
|
2532
|
+
response: initResponse
|
|
2533
|
+
}
|
|
2534
|
+
});
|
|
2535
|
+
if (enableAuthStatus) {
|
|
2536
|
+
const authStatusManager = AwsAuthStatusManager.getInstance();
|
|
2537
|
+
const status = authStatusManager.getStatus();
|
|
2538
|
+
if (status) {
|
|
2539
|
+
output.enqueue({
|
|
2540
|
+
type: "auth_status",
|
|
2541
|
+
isAuthenticating: status.isAuthenticating,
|
|
2542
|
+
output: status.output,
|
|
2543
|
+
error: status.error,
|
|
2544
|
+
uuid: randomUUID(),
|
|
2545
|
+
session_id: getSessionId()
|
|
2546
|
+
});
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
async function handleRewindFiles(userMessageId, appState, setAppState, dryRun) {
|
|
2551
|
+
if (!fileHistoryEnabled()) {
|
|
2552
|
+
return { canRewind: false, error: "File rewinding is not enabled." };
|
|
2553
|
+
}
|
|
2554
|
+
if (!fileHistoryCanRestore(appState.fileHistory, userMessageId)) {
|
|
2555
|
+
return {
|
|
2556
|
+
canRewind: false,
|
|
2557
|
+
error: "No file checkpoint found for this message."
|
|
2558
|
+
};
|
|
2559
|
+
}
|
|
2560
|
+
if (dryRun) {
|
|
2561
|
+
const diffStats = await fileHistoryGetDiffStats(appState.fileHistory, userMessageId);
|
|
2562
|
+
return {
|
|
2563
|
+
canRewind: true,
|
|
2564
|
+
filesChanged: diffStats?.filesChanged,
|
|
2565
|
+
insertions: diffStats?.insertions,
|
|
2566
|
+
deletions: diffStats?.deletions
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2569
|
+
try {
|
|
2570
|
+
await fileHistoryRewind((updater) => setAppState((prev) => ({
|
|
2571
|
+
...prev,
|
|
2572
|
+
fileHistory: updater(prev.fileHistory)
|
|
2573
|
+
})), userMessageId);
|
|
2574
|
+
} catch (error) {
|
|
2575
|
+
return {
|
|
2576
|
+
canRewind: false,
|
|
2577
|
+
error: `Failed to rewind: ${errorMessage(error)}`
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
return { canRewind: true };
|
|
2581
|
+
}
|
|
2582
|
+
function handleSetPermissionMode(request, requestId, toolPermissionContext, output) {
|
|
2583
|
+
if (request.mode === "bypassPermissions") {
|
|
2584
|
+
if (isBypassPermissionsModeDisabled()) {
|
|
2585
|
+
output.enqueue({
|
|
2586
|
+
type: "control_response",
|
|
2587
|
+
response: {
|
|
2588
|
+
subtype: "error",
|
|
2589
|
+
request_id: requestId,
|
|
2590
|
+
error: "Cannot set permission mode to bypassPermissions because it is disabled by settings or configuration"
|
|
2591
|
+
}
|
|
2592
|
+
});
|
|
2593
|
+
return toolPermissionContext;
|
|
2594
|
+
}
|
|
2595
|
+
if (!toolPermissionContext.isBypassPermissionsModeAvailable) {
|
|
2596
|
+
output.enqueue({
|
|
2597
|
+
type: "control_response",
|
|
2598
|
+
response: {
|
|
2599
|
+
subtype: "error",
|
|
2600
|
+
request_id: requestId,
|
|
2601
|
+
error: "Cannot set permission mode to bypassPermissions because the session was not launched with --dangerously-skip-permissions"
|
|
2602
|
+
}
|
|
2603
|
+
});
|
|
2604
|
+
return toolPermissionContext;
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
if (false) {}
|
|
2608
|
+
output.enqueue({
|
|
2609
|
+
type: "control_response",
|
|
2610
|
+
response: {
|
|
2611
|
+
subtype: "success",
|
|
2612
|
+
request_id: requestId,
|
|
2613
|
+
response: {
|
|
2614
|
+
mode: request.mode
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
});
|
|
2618
|
+
return {
|
|
2619
|
+
...transitionPermissionMode(toolPermissionContext.mode, request.mode, toolPermissionContext),
|
|
2620
|
+
mode: request.mode
|
|
2621
|
+
};
|
|
2622
|
+
}
|
|
2623
|
+
function handleChannelEnable(requestId, serverName, connectionPool, output) {
|
|
2624
|
+
const respondError = (error) => output.enqueue({
|
|
2625
|
+
type: "control_response",
|
|
2626
|
+
response: { subtype: "error", request_id: requestId, error }
|
|
2627
|
+
});
|
|
2628
|
+
if (true) {
|
|
2629
|
+
return respondError("channels feature not available in this build");
|
|
2630
|
+
}
|
|
2631
|
+
const connection = connectionPool.find((c) => c.name === serverName && c.type === "connected");
|
|
2632
|
+
if (!connection || connection.type !== "connected") {
|
|
2633
|
+
return respondError(`server ${serverName} is not connected`);
|
|
2634
|
+
}
|
|
2635
|
+
const pluginSource = connection.config.pluginSource;
|
|
2636
|
+
const parsed = pluginSource ? parsePluginIdentifier(pluginSource) : undefined;
|
|
2637
|
+
if (!parsed?.marketplace) {
|
|
2638
|
+
return respondError(`server ${serverName} is not plugin-sourced; channel_enable requires a marketplace plugin`);
|
|
2639
|
+
}
|
|
2640
|
+
const entry = {
|
|
2641
|
+
kind: "plugin",
|
|
2642
|
+
name: parsed.name,
|
|
2643
|
+
marketplace: parsed.marketplace
|
|
2644
|
+
};
|
|
2645
|
+
const prior = getAllowedChannels();
|
|
2646
|
+
const already = prior.some((e) => e.kind === "plugin" && e.name === entry.name && e.marketplace === entry.marketplace);
|
|
2647
|
+
if (!already)
|
|
2648
|
+
setAllowedChannels([...prior, entry]);
|
|
2649
|
+
const gate = gateChannelServer(serverName, connection.capabilities, pluginSource);
|
|
2650
|
+
if (gate.action === "skip") {
|
|
2651
|
+
if (!already)
|
|
2652
|
+
setAllowedChannels(prior);
|
|
2653
|
+
return respondError(gate.reason);
|
|
2654
|
+
}
|
|
2655
|
+
const pluginId = `${entry.name}@${entry.marketplace}`;
|
|
2656
|
+
logMCPDebug(serverName, "Channel notifications registered");
|
|
2657
|
+
logEvent("tengu_mcp_channel_enable", { plugin: pluginId });
|
|
2658
|
+
connection.client.setNotificationHandler(ChannelMessageNotificationSchema(), async (notification) => {
|
|
2659
|
+
const { content, meta } = notification.params;
|
|
2660
|
+
logMCPDebug(serverName, `notifications/claude/channel: ${content.slice(0, 80)}`);
|
|
2661
|
+
logEvent("tengu_mcp_channel_message", {
|
|
2662
|
+
content_length: content.length,
|
|
2663
|
+
meta_key_count: Object.keys(meta ?? {}).length,
|
|
2664
|
+
entry_kind: "plugin",
|
|
2665
|
+
is_dev: false,
|
|
2666
|
+
plugin: pluginId
|
|
2667
|
+
});
|
|
2668
|
+
enqueue({
|
|
2669
|
+
mode: "prompt",
|
|
2670
|
+
value: wrapChannelMessage(serverName, content, meta),
|
|
2671
|
+
priority: "next",
|
|
2672
|
+
isMeta: true,
|
|
2673
|
+
origin: { kind: "channel", server: serverName },
|
|
2674
|
+
skipSlashCommands: true
|
|
2675
|
+
});
|
|
2676
|
+
});
|
|
2677
|
+
output.enqueue({
|
|
2678
|
+
type: "control_response",
|
|
2679
|
+
response: {
|
|
2680
|
+
subtype: "success",
|
|
2681
|
+
request_id: requestId,
|
|
2682
|
+
response: undefined
|
|
2683
|
+
}
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
function reregisterChannelHandlerAfterReconnect(connection) {
|
|
2687
|
+
if (true)
|
|
2688
|
+
return;
|
|
2689
|
+
if (connection.type !== "connected")
|
|
2690
|
+
return;
|
|
2691
|
+
const gate = gateChannelServer(connection.name, connection.capabilities, connection.config.pluginSource);
|
|
2692
|
+
if (gate.action !== "register")
|
|
2693
|
+
return;
|
|
2694
|
+
const entry = findChannelEntry(connection.name, getAllowedChannels());
|
|
2695
|
+
const pluginId = entry?.kind === "plugin" ? `${entry.name}@${entry.marketplace}` : undefined;
|
|
2696
|
+
logMCPDebug(connection.name, "Channel notifications re-registered after reconnect");
|
|
2697
|
+
connection.client.setNotificationHandler(ChannelMessageNotificationSchema(), async (notification) => {
|
|
2698
|
+
const { content, meta } = notification.params;
|
|
2699
|
+
logMCPDebug(connection.name, `notifications/claude/channel: ${content.slice(0, 80)}`);
|
|
2700
|
+
logEvent("tengu_mcp_channel_message", {
|
|
2701
|
+
content_length: content.length,
|
|
2702
|
+
meta_key_count: Object.keys(meta ?? {}).length,
|
|
2703
|
+
entry_kind: entry?.kind,
|
|
2704
|
+
is_dev: entry?.dev ?? false,
|
|
2705
|
+
plugin: pluginId
|
|
2706
|
+
});
|
|
2707
|
+
enqueue({
|
|
2708
|
+
mode: "prompt",
|
|
2709
|
+
value: wrapChannelMessage(connection.name, content, meta),
|
|
2710
|
+
priority: "next",
|
|
2711
|
+
isMeta: true,
|
|
2712
|
+
origin: { kind: "channel", server: connection.name },
|
|
2713
|
+
skipSlashCommands: true
|
|
2714
|
+
});
|
|
2715
|
+
});
|
|
2716
|
+
}
|
|
2717
|
+
function emitLoadError(message, outputFormat) {
|
|
2718
|
+
if (outputFormat === "stream-json") {
|
|
2719
|
+
const errorResult = {
|
|
2720
|
+
type: "result",
|
|
2721
|
+
subtype: "error_during_execution",
|
|
2722
|
+
duration_ms: 0,
|
|
2723
|
+
duration_api_ms: 0,
|
|
2724
|
+
is_error: true,
|
|
2725
|
+
num_turns: 0,
|
|
2726
|
+
stop_reason: null,
|
|
2727
|
+
session_id: getSessionId(),
|
|
2728
|
+
total_cost_usd: 0,
|
|
2729
|
+
usage: EMPTY_USAGE,
|
|
2730
|
+
modelUsage: {},
|
|
2731
|
+
permission_denials: [],
|
|
2732
|
+
uuid: randomUUID(),
|
|
2733
|
+
errors: [message]
|
|
2734
|
+
};
|
|
2735
|
+
process.stdout.write(jsonStringify(errorResult) + `
|
|
2736
|
+
`);
|
|
2737
|
+
} else {
|
|
2738
|
+
process.stderr.write(message + `
|
|
2739
|
+
`);
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
export function removeInterruptedMessage(messages, interruptedUserMessage) {
|
|
2743
|
+
const idx = messages.findIndex((m) => m.uuid === interruptedUserMessage.uuid);
|
|
2744
|
+
if (idx !== -1) {
|
|
2745
|
+
messages.splice(idx, 2);
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
async function loadInitialMessages(setAppState, options) {
|
|
2749
|
+
const persistSession = !isSessionPersistenceDisabled();
|
|
2750
|
+
if (options.continue) {
|
|
2751
|
+
try {
|
|
2752
|
+
logEvent("tengu_continue_print", {});
|
|
2753
|
+
const result = await loadConversationForResume(undefined, undefined);
|
|
2754
|
+
if (result) {
|
|
2755
|
+
if (false) {}
|
|
2756
|
+
if (!options.forkSession) {
|
|
2757
|
+
if (result.sessionId) {
|
|
2758
|
+
switchSession(asSessionId(result.sessionId), result.fullPath ? dirname(result.fullPath) : null);
|
|
2759
|
+
if (persistSession) {
|
|
2760
|
+
await resetSessionFilePointer();
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
restoreSessionStateFromLog(result, setAppState);
|
|
2765
|
+
restoreSessionMetadata(options.forkSession ? { ...result, worktreeSession: undefined } : result);
|
|
2766
|
+
if (false) {}
|
|
2767
|
+
return {
|
|
2768
|
+
messages: result.messages,
|
|
2769
|
+
turnInterruptionState: result.turnInterruptionState,
|
|
2770
|
+
agentSetting: result.agentSetting
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
} catch (error) {
|
|
2774
|
+
logError(error);
|
|
2775
|
+
gracefulShutdownSync(1);
|
|
2776
|
+
return { messages: [] };
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
if (options.teleport) {
|
|
2780
|
+
try {
|
|
2781
|
+
if (!isPolicyAllowed("allow_remote_sessions")) {
|
|
2782
|
+
throw new Error("Remote sessions are disabled by your organization's policy.");
|
|
2783
|
+
}
|
|
2784
|
+
logEvent("tengu_teleport_print", {});
|
|
2785
|
+
if (typeof options.teleport !== "string") {
|
|
2786
|
+
throw new Error("No session ID provided for teleport");
|
|
2787
|
+
}
|
|
2788
|
+
const {
|
|
2789
|
+
checkOutTeleportedSessionBranch,
|
|
2790
|
+
processMessagesForTeleportResume,
|
|
2791
|
+
teleportResumeCodeSession,
|
|
2792
|
+
validateGitState
|
|
2793
|
+
} = await import("../utils/teleport.js");
|
|
2794
|
+
await validateGitState();
|
|
2795
|
+
const teleportResult = await teleportResumeCodeSession(options.teleport);
|
|
2796
|
+
const { branchError } = await checkOutTeleportedSessionBranch(teleportResult.branch);
|
|
2797
|
+
return {
|
|
2798
|
+
messages: processMessagesForTeleportResume(teleportResult.log, branchError)
|
|
2799
|
+
};
|
|
2800
|
+
} catch (error) {
|
|
2801
|
+
logError(error);
|
|
2802
|
+
gracefulShutdownSync(1);
|
|
2803
|
+
return { messages: [] };
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
if (options.resume) {
|
|
2807
|
+
try {
|
|
2808
|
+
logEvent("tengu_resume_print", {});
|
|
2809
|
+
const parsedSessionId = parseSessionIdentifier(typeof options.resume === "string" ? options.resume : "");
|
|
2810
|
+
if (!parsedSessionId) {
|
|
2811
|
+
let errorMessage = "Error: --resume requires a valid session ID when used with --print. Usage: lcclaude -p --resume <session-id>";
|
|
2812
|
+
if (typeof options.resume === "string") {
|
|
2813
|
+
errorMessage += `. Session IDs must be in UUID format (e.g., 550e8400-e29b-41d4-a716-446655440000). Provided value "${options.resume}" is not a valid UUID`;
|
|
2814
|
+
}
|
|
2815
|
+
emitLoadError(errorMessage, options.outputFormat);
|
|
2816
|
+
gracefulShutdownSync(1);
|
|
2817
|
+
return { messages: [] };
|
|
2818
|
+
}
|
|
2819
|
+
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_CCR_V2)) {
|
|
2820
|
+
const [, metadata] = await Promise.all([
|
|
2821
|
+
hydrateFromCCRv2InternalEvents(parsedSessionId.sessionId),
|
|
2822
|
+
options.restoredWorkerState
|
|
2823
|
+
]);
|
|
2824
|
+
if (metadata) {
|
|
2825
|
+
setAppState(externalMetadataToAppState(metadata));
|
|
2826
|
+
if (typeof metadata.model === "string") {
|
|
2827
|
+
setMainLoopModelOverride(metadata.model);
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
} else if (parsedSessionId.isUrl && parsedSessionId.ingressUrl && isEnvTruthy(process.env.ENABLE_SESSION_PERSISTENCE)) {
|
|
2831
|
+
await hydrateRemoteSession(parsedSessionId.sessionId, parsedSessionId.ingressUrl);
|
|
2832
|
+
}
|
|
2833
|
+
const result = await loadConversationForResume(parsedSessionId.sessionId, parsedSessionId.jsonlFile || undefined);
|
|
2834
|
+
if (!result || result.messages.length === 0) {
|
|
2835
|
+
if (parsedSessionId.isUrl || isEnvTruthy(process.env.CLAUDE_CODE_USE_CCR_V2)) {
|
|
2836
|
+
return {
|
|
2837
|
+
messages: await (options.sessionStartHooksPromise ?? processSessionStartHooks("startup"))
|
|
2838
|
+
};
|
|
2839
|
+
} else {
|
|
2840
|
+
emitLoadError(`No conversation found with session ID: ${parsedSessionId.sessionId}`, options.outputFormat);
|
|
2841
|
+
gracefulShutdownSync(1);
|
|
2842
|
+
return { messages: [] };
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
if (options.resumeSessionAt) {
|
|
2846
|
+
const index = result.messages.findIndex((m) => m.uuid === options.resumeSessionAt);
|
|
2847
|
+
if (index < 0) {
|
|
2848
|
+
emitLoadError(`No message found with message.uuid of: ${options.resumeSessionAt}`, options.outputFormat);
|
|
2849
|
+
gracefulShutdownSync(1);
|
|
2850
|
+
return { messages: [] };
|
|
2851
|
+
}
|
|
2852
|
+
result.messages = index >= 0 ? result.messages.slice(0, index + 1) : [];
|
|
2853
|
+
}
|
|
2854
|
+
if (false) {}
|
|
2855
|
+
if (!options.forkSession && result.sessionId) {
|
|
2856
|
+
switchSession(asSessionId(result.sessionId), result.fullPath ? dirname(result.fullPath) : null);
|
|
2857
|
+
if (persistSession) {
|
|
2858
|
+
await resetSessionFilePointer();
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
restoreSessionStateFromLog(result, setAppState);
|
|
2862
|
+
restoreSessionMetadata(options.forkSession ? { ...result, worktreeSession: undefined } : result);
|
|
2863
|
+
if (false) {}
|
|
2864
|
+
return {
|
|
2865
|
+
messages: result.messages,
|
|
2866
|
+
turnInterruptionState: result.turnInterruptionState,
|
|
2867
|
+
agentSetting: result.agentSetting
|
|
2868
|
+
};
|
|
2869
|
+
} catch (error) {
|
|
2870
|
+
logError(error);
|
|
2871
|
+
const errorMessage = error instanceof Error ? `Failed to resume session: ${error.message}` : "Failed to resume session with --print mode";
|
|
2872
|
+
emitLoadError(errorMessage, options.outputFormat);
|
|
2873
|
+
gracefulShutdownSync(1);
|
|
2874
|
+
return { messages: [] };
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
return {
|
|
2878
|
+
messages: await (options.sessionStartHooksPromise ?? processSessionStartHooks("startup"))
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2881
|
+
function getStructuredIO(inputPrompt, options) {
|
|
2882
|
+
let inputStream;
|
|
2883
|
+
if (typeof inputPrompt === "string") {
|
|
2884
|
+
if (inputPrompt.trim() !== "") {
|
|
2885
|
+
inputStream = fromArray([
|
|
2886
|
+
jsonStringify({
|
|
2887
|
+
type: "user",
|
|
2888
|
+
session_id: "",
|
|
2889
|
+
message: {
|
|
2890
|
+
role: "user",
|
|
2891
|
+
content: inputPrompt
|
|
2892
|
+
},
|
|
2893
|
+
parent_tool_use_id: null
|
|
2894
|
+
})
|
|
2895
|
+
]);
|
|
2896
|
+
} else {
|
|
2897
|
+
inputStream = fromArray([]);
|
|
2898
|
+
}
|
|
2899
|
+
} else {
|
|
2900
|
+
inputStream = inputPrompt;
|
|
2901
|
+
}
|
|
2902
|
+
return options.sdkUrl ? new RemoteIO(options.sdkUrl, inputStream, options.replayUserMessages) : new StructuredIO(inputStream, options.replayUserMessages);
|
|
2903
|
+
}
|
|
2904
|
+
export async function handleOrphanedPermissionResponse({
|
|
2905
|
+
message,
|
|
2906
|
+
setAppState,
|
|
2907
|
+
onEnqueued,
|
|
2908
|
+
handledToolUseIds
|
|
2909
|
+
}) {
|
|
2910
|
+
if (message.response.subtype === "success" && message.response.response?.toolUseID && typeof message.response.response.toolUseID === "string") {
|
|
2911
|
+
const permissionResult = message.response.response;
|
|
2912
|
+
const { toolUseID } = permissionResult;
|
|
2913
|
+
if (!toolUseID) {
|
|
2914
|
+
return false;
|
|
2915
|
+
}
|
|
2916
|
+
logForDebugging(`handleOrphanedPermissionResponse: received orphaned control_response for toolUseID=${toolUseID} request_id=${message.response.request_id}`);
|
|
2917
|
+
if (handledToolUseIds.has(toolUseID)) {
|
|
2918
|
+
logForDebugging(`handleOrphanedPermissionResponse: skipping duplicate orphaned permission for toolUseID=${toolUseID} (already handled)`);
|
|
2919
|
+
return false;
|
|
2920
|
+
}
|
|
2921
|
+
const assistantMessage = await findUnresolvedToolUse(toolUseID);
|
|
2922
|
+
if (!assistantMessage) {
|
|
2923
|
+
logForDebugging(`handleOrphanedPermissionResponse: no unresolved tool_use found for toolUseID=${toolUseID} (already resolved in transcript)`);
|
|
2924
|
+
return false;
|
|
2925
|
+
}
|
|
2926
|
+
handledToolUseIds.add(toolUseID);
|
|
2927
|
+
logForDebugging(`handleOrphanedPermissionResponse: enqueuing orphaned permission for toolUseID=${toolUseID} messageID=${assistantMessage.message.id}`);
|
|
2928
|
+
enqueue({
|
|
2929
|
+
mode: "orphaned-permission",
|
|
2930
|
+
value: [],
|
|
2931
|
+
orphanedPermission: {
|
|
2932
|
+
permissionResult,
|
|
2933
|
+
assistantMessage
|
|
2934
|
+
}
|
|
2935
|
+
});
|
|
2936
|
+
onEnqueued?.();
|
|
2937
|
+
return true;
|
|
2938
|
+
}
|
|
2939
|
+
return false;
|
|
2940
|
+
}
|
|
2941
|
+
function toScopedConfig(config) {
|
|
2942
|
+
return { ...config, scope: "dynamic" };
|
|
2943
|
+
}
|
|
2944
|
+
export async function handleMcpSetServers(servers, sdkState, dynamicState, setAppState) {
|
|
2945
|
+
const { allowed: allowedServers, blocked } = filterMcpServersByPolicy(servers);
|
|
2946
|
+
const policyErrors = {};
|
|
2947
|
+
for (const name of blocked) {
|
|
2948
|
+
policyErrors[name] = "Blocked by enterprise policy (allowedMcpServers/deniedMcpServers)";
|
|
2949
|
+
}
|
|
2950
|
+
const sdkServers = {};
|
|
2951
|
+
const processServers = {};
|
|
2952
|
+
for (const [name, config] of Object.entries(allowedServers)) {
|
|
2953
|
+
if (config.type === "sdk") {
|
|
2954
|
+
sdkServers[name] = config;
|
|
2955
|
+
} else {
|
|
2956
|
+
processServers[name] = config;
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2959
|
+
const currentSdkNames = new Set(Object.keys(sdkState.configs));
|
|
2960
|
+
const newSdkNames = new Set(Object.keys(sdkServers));
|
|
2961
|
+
const sdkAdded = [];
|
|
2962
|
+
const sdkRemoved = [];
|
|
2963
|
+
const newSdkConfigs = { ...sdkState.configs };
|
|
2964
|
+
let newSdkClients = [...sdkState.clients];
|
|
2965
|
+
let newSdkTools = [...sdkState.tools];
|
|
2966
|
+
for (const name of currentSdkNames) {
|
|
2967
|
+
if (!newSdkNames.has(name)) {
|
|
2968
|
+
const client = newSdkClients.find((c) => c.name === name);
|
|
2969
|
+
if (client && client.type === "connected") {
|
|
2970
|
+
await client.cleanup();
|
|
2971
|
+
}
|
|
2972
|
+
newSdkClients = newSdkClients.filter((c) => c.name !== name);
|
|
2973
|
+
const prefix = `mcp__${name}__`;
|
|
2974
|
+
newSdkTools = newSdkTools.filter((t) => !t.name.startsWith(prefix));
|
|
2975
|
+
delete newSdkConfigs[name];
|
|
2976
|
+
sdkRemoved.push(name);
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
for (const [name, config] of Object.entries(sdkServers)) {
|
|
2980
|
+
if (!currentSdkNames.has(name)) {
|
|
2981
|
+
newSdkConfigs[name] = config;
|
|
2982
|
+
const pendingClient = {
|
|
2983
|
+
type: "pending",
|
|
2984
|
+
name,
|
|
2985
|
+
config: { ...config, scope: "dynamic" }
|
|
2986
|
+
};
|
|
2987
|
+
newSdkClients = [...newSdkClients, pendingClient];
|
|
2988
|
+
sdkAdded.push(name);
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
const processResult = await reconcileMcpServers(processServers, dynamicState, setAppState);
|
|
2992
|
+
return {
|
|
2993
|
+
response: {
|
|
2994
|
+
added: [...sdkAdded, ...processResult.response.added],
|
|
2995
|
+
removed: [...sdkRemoved, ...processResult.response.removed],
|
|
2996
|
+
errors: { ...policyErrors, ...processResult.response.errors }
|
|
2997
|
+
},
|
|
2998
|
+
newSdkState: {
|
|
2999
|
+
configs: newSdkConfigs,
|
|
3000
|
+
clients: newSdkClients,
|
|
3001
|
+
tools: newSdkTools
|
|
3002
|
+
},
|
|
3003
|
+
newDynamicState: processResult.newState,
|
|
3004
|
+
sdkServersChanged: sdkAdded.length > 0 || sdkRemoved.length > 0
|
|
3005
|
+
};
|
|
3006
|
+
}
|
|
3007
|
+
export async function reconcileMcpServers(desiredConfigs, currentState, setAppState) {
|
|
3008
|
+
const currentNames = new Set(Object.keys(currentState.configs));
|
|
3009
|
+
const desiredNames = new Set(Object.keys(desiredConfigs));
|
|
3010
|
+
const toRemove = [...currentNames].filter((n) => !desiredNames.has(n));
|
|
3011
|
+
const toAdd = [...desiredNames].filter((n) => !currentNames.has(n));
|
|
3012
|
+
const toCheck = [...currentNames].filter((n) => desiredNames.has(n));
|
|
3013
|
+
const toReplace = toCheck.filter((name) => {
|
|
3014
|
+
const currentConfig = currentState.configs[name];
|
|
3015
|
+
const desiredConfigRaw = desiredConfigs[name];
|
|
3016
|
+
if (!currentConfig || !desiredConfigRaw)
|
|
3017
|
+
return true;
|
|
3018
|
+
const desiredConfig = toScopedConfig(desiredConfigRaw);
|
|
3019
|
+
return !areMcpConfigsEqual(currentConfig, desiredConfig);
|
|
3020
|
+
});
|
|
3021
|
+
const removed = [];
|
|
3022
|
+
const added = [];
|
|
3023
|
+
const errors = {};
|
|
3024
|
+
let newClients = [...currentState.clients];
|
|
3025
|
+
let newTools = [...currentState.tools];
|
|
3026
|
+
for (const name of [...toRemove, ...toReplace]) {
|
|
3027
|
+
const client = newClients.find((c) => c.name === name);
|
|
3028
|
+
const config = currentState.configs[name];
|
|
3029
|
+
if (client && config) {
|
|
3030
|
+
if (client.type === "connected") {
|
|
3031
|
+
try {
|
|
3032
|
+
await client.cleanup();
|
|
3033
|
+
} catch (e) {
|
|
3034
|
+
logError(e);
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
3037
|
+
await clearServerCache(name, config);
|
|
3038
|
+
}
|
|
3039
|
+
const prefix = `mcp__${name}__`;
|
|
3040
|
+
newTools = newTools.filter((t) => !t.name.startsWith(prefix));
|
|
3041
|
+
newClients = newClients.filter((c) => c.name !== name);
|
|
3042
|
+
if (toRemove.includes(name)) {
|
|
3043
|
+
removed.push(name);
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
for (const name of [...toAdd, ...toReplace]) {
|
|
3047
|
+
const config = desiredConfigs[name];
|
|
3048
|
+
if (!config)
|
|
3049
|
+
continue;
|
|
3050
|
+
const scopedConfig = toScopedConfig(config);
|
|
3051
|
+
if (config.type === "sdk") {
|
|
3052
|
+
added.push(name);
|
|
3053
|
+
continue;
|
|
3054
|
+
}
|
|
3055
|
+
try {
|
|
3056
|
+
const client = await connectToServer(name, scopedConfig);
|
|
3057
|
+
newClients.push(client);
|
|
3058
|
+
if (client.type === "connected") {
|
|
3059
|
+
const serverTools = await fetchToolsForClient(client);
|
|
3060
|
+
newTools.push(...serverTools);
|
|
3061
|
+
} else if (client.type === "failed") {
|
|
3062
|
+
errors[name] = client.error || "Connection failed";
|
|
3063
|
+
}
|
|
3064
|
+
added.push(name);
|
|
3065
|
+
} catch (e) {
|
|
3066
|
+
const err = toError(e);
|
|
3067
|
+
errors[name] = err.message;
|
|
3068
|
+
logError(err);
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
const newConfigs = {};
|
|
3072
|
+
for (const name of desiredNames) {
|
|
3073
|
+
const config = desiredConfigs[name];
|
|
3074
|
+
if (config) {
|
|
3075
|
+
newConfigs[name] = toScopedConfig(config);
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
const newState = {
|
|
3079
|
+
clients: newClients,
|
|
3080
|
+
tools: newTools,
|
|
3081
|
+
configs: newConfigs
|
|
3082
|
+
};
|
|
3083
|
+
setAppState((prev) => {
|
|
3084
|
+
const allDynamicServerNames = new Set([
|
|
3085
|
+
...Object.keys(currentState.configs),
|
|
3086
|
+
...Object.keys(newConfigs)
|
|
3087
|
+
]);
|
|
3088
|
+
const nonDynamicTools = prev.mcp.tools.filter((t) => {
|
|
3089
|
+
for (const serverName of allDynamicServerNames) {
|
|
3090
|
+
if (t.name.startsWith(`mcp__${serverName}__`)) {
|
|
3091
|
+
return false;
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
return true;
|
|
3095
|
+
});
|
|
3096
|
+
const nonDynamicClients = prev.mcp.clients.filter((c) => {
|
|
3097
|
+
return !allDynamicServerNames.has(c.name);
|
|
3098
|
+
});
|
|
3099
|
+
return {
|
|
3100
|
+
...prev,
|
|
3101
|
+
mcp: {
|
|
3102
|
+
...prev.mcp,
|
|
3103
|
+
tools: [...nonDynamicTools, ...newTools],
|
|
3104
|
+
clients: [...nonDynamicClients, ...newClients]
|
|
3105
|
+
}
|
|
3106
|
+
};
|
|
3107
|
+
});
|
|
3108
|
+
return {
|
|
3109
|
+
response: { added, removed, errors },
|
|
3110
|
+
newState
|
|
3111
|
+
};
|
|
3112
|
+
}
|