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,2891 @@
|
|
|
1
|
+
import { closeSync, fstatSync, openSync, readSync } from "fs";
|
|
2
|
+
import {
|
|
3
|
+
appendFile as fsAppendFile,
|
|
4
|
+
open as fsOpen,
|
|
5
|
+
mkdir,
|
|
6
|
+
readdir,
|
|
7
|
+
readFile,
|
|
8
|
+
stat,
|
|
9
|
+
unlink,
|
|
10
|
+
writeFile
|
|
11
|
+
} from "fs/promises";
|
|
12
|
+
import memoize from "lodash-es/memoize.js";
|
|
13
|
+
import { basename, dirname, join } from "path";
|
|
14
|
+
import {
|
|
15
|
+
logEvent
|
|
16
|
+
} from "../services/analytics/index.js";
|
|
17
|
+
import {
|
|
18
|
+
getOriginalCwd,
|
|
19
|
+
getPlanSlugCache,
|
|
20
|
+
getPromptId,
|
|
21
|
+
getSessionId,
|
|
22
|
+
getSessionProjectDir,
|
|
23
|
+
isSessionPersistenceDisabled,
|
|
24
|
+
switchSession
|
|
25
|
+
} from "../bootstrap/state.js";
|
|
26
|
+
import { builtInCommandNames } from "../commands.js";
|
|
27
|
+
import { COMMAND_NAME_TAG, TICK_TAG } from "../constants/xml.js";
|
|
28
|
+
import { getFeatureValue_CACHED_MAY_BE_STALE } from "../services/analytics/growthbook.js";
|
|
29
|
+
import * as sessionIngress from "../services/api/sessionIngress.js";
|
|
30
|
+
import { REPL_TOOL_NAME } from "../tools/REPLTool/constants.js";
|
|
31
|
+
import {
|
|
32
|
+
asAgentId,
|
|
33
|
+
asSessionId
|
|
34
|
+
} from "../types/ids.js";
|
|
35
|
+
import {
|
|
36
|
+
sortLogs
|
|
37
|
+
} from "../types/logs.js";
|
|
38
|
+
import { uniq } from "./array.js";
|
|
39
|
+
import { registerCleanup } from "./cleanupRegistry.js";
|
|
40
|
+
import { updateSessionName } from "./concurrentSessions.js";
|
|
41
|
+
import { getCwd } from "./cwd.js";
|
|
42
|
+
import { logForDebugging } from "./debug.js";
|
|
43
|
+
import { logForDiagnosticsNoPII } from "./diagLogs.js";
|
|
44
|
+
import { getClaudeConfigHomeDir, isEnvTruthy } from "./envUtils.js";
|
|
45
|
+
import { isFsInaccessible } from "./errors.js";
|
|
46
|
+
import { formatFileSize } from "./format.js";
|
|
47
|
+
import { getFsImplementation } from "./fsOperations.js";
|
|
48
|
+
import { getWorktreePaths } from "./getWorktreePaths.js";
|
|
49
|
+
import { getBranch } from "./git.js";
|
|
50
|
+
import { gracefulShutdownSync, isShuttingDown } from "./gracefulShutdown.js";
|
|
51
|
+
import { parseJSONL } from "./json.js";
|
|
52
|
+
import { logError } from "./log.js";
|
|
53
|
+
import { extractTag, isCompactBoundaryMessage } from "./messages.js";
|
|
54
|
+
import { sanitizePath } from "./path.js";
|
|
55
|
+
import {
|
|
56
|
+
extractJsonStringField,
|
|
57
|
+
extractLastJsonStringField,
|
|
58
|
+
LITE_READ_BUF_SIZE,
|
|
59
|
+
readHeadAndTail,
|
|
60
|
+
readTranscriptForLoad,
|
|
61
|
+
SKIP_PRECOMPACT_THRESHOLD
|
|
62
|
+
} from "./sessionStoragePortable.js";
|
|
63
|
+
import { getSettings_DEPRECATED } from "./settings/settings.js";
|
|
64
|
+
import { jsonParse, jsonStringify } from "./slowOperations.js";
|
|
65
|
+
import { validateUuid } from "./uuid.js";
|
|
66
|
+
const VERSION = typeof MACRO !== "undefined" ? MACRO.VERSION : "unknown";
|
|
67
|
+
const MAX_TOMBSTONE_REWRITE_BYTES = 50 * 1024 * 1024;
|
|
68
|
+
const SKIP_FIRST_PROMPT_PATTERN = /^(?:\s*<[a-z][\w-]*[\s>]|\[Request interrupted by user[^\]]*\])/;
|
|
69
|
+
export function isTranscriptMessage(entry) {
|
|
70
|
+
return entry.type === "user" || entry.type === "assistant" || entry.type === "attachment" || entry.type === "system";
|
|
71
|
+
}
|
|
72
|
+
export function isChainParticipant(m) {
|
|
73
|
+
return m.type !== "progress";
|
|
74
|
+
}
|
|
75
|
+
function isLegacyProgressEntry(entry) {
|
|
76
|
+
return typeof entry === "object" && entry !== null && "type" in entry && entry.type === "progress" && "uuid" in entry && typeof entry.uuid === "string";
|
|
77
|
+
}
|
|
78
|
+
const EPHEMERAL_PROGRESS_TYPES = new Set([
|
|
79
|
+
"bash_progress",
|
|
80
|
+
"powershell_progress",
|
|
81
|
+
"mcp_progress",
|
|
82
|
+
...[]
|
|
83
|
+
]);
|
|
84
|
+
export function isEphemeralToolProgress(dataType) {
|
|
85
|
+
return typeof dataType === "string" && EPHEMERAL_PROGRESS_TYPES.has(dataType);
|
|
86
|
+
}
|
|
87
|
+
export function getProjectsDir() {
|
|
88
|
+
return join(getClaudeConfigHomeDir(), "projects");
|
|
89
|
+
}
|
|
90
|
+
export function getTranscriptPath() {
|
|
91
|
+
const projectDir = getSessionProjectDir() ?? getProjectDir(getOriginalCwd());
|
|
92
|
+
return join(projectDir, `${getSessionId()}.jsonl`);
|
|
93
|
+
}
|
|
94
|
+
export function getTranscriptPathForSession(sessionId) {
|
|
95
|
+
if (sessionId === getSessionId()) {
|
|
96
|
+
return getTranscriptPath();
|
|
97
|
+
}
|
|
98
|
+
const projectDir = getProjectDir(getOriginalCwd());
|
|
99
|
+
return join(projectDir, `${sessionId}.jsonl`);
|
|
100
|
+
}
|
|
101
|
+
export const MAX_TRANSCRIPT_READ_BYTES = 50 * 1024 * 1024;
|
|
102
|
+
const agentTranscriptSubdirs = new Map;
|
|
103
|
+
export function setAgentTranscriptSubdir(agentId, subdir) {
|
|
104
|
+
agentTranscriptSubdirs.set(agentId, subdir);
|
|
105
|
+
}
|
|
106
|
+
export function clearAgentTranscriptSubdir(agentId) {
|
|
107
|
+
agentTranscriptSubdirs.delete(agentId);
|
|
108
|
+
}
|
|
109
|
+
export function getAgentTranscriptPath(agentId) {
|
|
110
|
+
const projectDir = getSessionProjectDir() ?? getProjectDir(getOriginalCwd());
|
|
111
|
+
const sessionId = getSessionId();
|
|
112
|
+
const subdir = agentTranscriptSubdirs.get(agentId);
|
|
113
|
+
const base = subdir ? join(projectDir, sessionId, "subagents", subdir) : join(projectDir, sessionId, "subagents");
|
|
114
|
+
return join(base, `agent-${agentId}.jsonl`);
|
|
115
|
+
}
|
|
116
|
+
function getAgentMetadataPath(agentId) {
|
|
117
|
+
return getAgentTranscriptPath(agentId).replace(/\.jsonl$/, ".meta.json");
|
|
118
|
+
}
|
|
119
|
+
export async function writeAgentMetadata(agentId, metadata) {
|
|
120
|
+
const path = getAgentMetadataPath(agentId);
|
|
121
|
+
await mkdir(dirname(path), { recursive: true });
|
|
122
|
+
await writeFile(path, JSON.stringify(metadata));
|
|
123
|
+
}
|
|
124
|
+
export async function readAgentMetadata(agentId) {
|
|
125
|
+
const path = getAgentMetadataPath(agentId);
|
|
126
|
+
try {
|
|
127
|
+
const raw = await readFile(path, "utf-8");
|
|
128
|
+
return JSON.parse(raw);
|
|
129
|
+
} catch (e) {
|
|
130
|
+
if (isFsInaccessible(e))
|
|
131
|
+
return null;
|
|
132
|
+
throw e;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function getRemoteAgentsDir() {
|
|
136
|
+
const projectDir = getSessionProjectDir() ?? getProjectDir(getOriginalCwd());
|
|
137
|
+
return join(projectDir, getSessionId(), "remote-agents");
|
|
138
|
+
}
|
|
139
|
+
function getRemoteAgentMetadataPath(taskId) {
|
|
140
|
+
return join(getRemoteAgentsDir(), `remote-agent-${taskId}.meta.json`);
|
|
141
|
+
}
|
|
142
|
+
export async function writeRemoteAgentMetadata(taskId, metadata) {
|
|
143
|
+
const path = getRemoteAgentMetadataPath(taskId);
|
|
144
|
+
await mkdir(dirname(path), { recursive: true });
|
|
145
|
+
await writeFile(path, JSON.stringify(metadata));
|
|
146
|
+
}
|
|
147
|
+
export async function readRemoteAgentMetadata(taskId) {
|
|
148
|
+
const path = getRemoteAgentMetadataPath(taskId);
|
|
149
|
+
try {
|
|
150
|
+
const raw = await readFile(path, "utf-8");
|
|
151
|
+
return JSON.parse(raw);
|
|
152
|
+
} catch (e) {
|
|
153
|
+
if (isFsInaccessible(e))
|
|
154
|
+
return null;
|
|
155
|
+
throw e;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export async function deleteRemoteAgentMetadata(taskId) {
|
|
159
|
+
const path = getRemoteAgentMetadataPath(taskId);
|
|
160
|
+
try {
|
|
161
|
+
await unlink(path);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
if (isFsInaccessible(e))
|
|
164
|
+
return;
|
|
165
|
+
throw e;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export async function listRemoteAgentMetadata() {
|
|
169
|
+
const dir = getRemoteAgentsDir();
|
|
170
|
+
let entries;
|
|
171
|
+
try {
|
|
172
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
173
|
+
} catch (e) {
|
|
174
|
+
if (isFsInaccessible(e))
|
|
175
|
+
return [];
|
|
176
|
+
throw e;
|
|
177
|
+
}
|
|
178
|
+
const results = [];
|
|
179
|
+
for (const entry of entries) {
|
|
180
|
+
if (!entry.isFile() || !entry.name.endsWith(".meta.json"))
|
|
181
|
+
continue;
|
|
182
|
+
try {
|
|
183
|
+
const raw = await readFile(join(dir, entry.name), "utf-8");
|
|
184
|
+
results.push(JSON.parse(raw));
|
|
185
|
+
} catch (e) {
|
|
186
|
+
logForDebugging(`listRemoteAgentMetadata: skipping ${entry.name}: ${String(e)}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return results;
|
|
190
|
+
}
|
|
191
|
+
export function sessionIdExists(sessionId) {
|
|
192
|
+
const projectDir = getProjectDir(getOriginalCwd());
|
|
193
|
+
const sessionFile = join(projectDir, `${sessionId}.jsonl`);
|
|
194
|
+
const fs = getFsImplementation();
|
|
195
|
+
try {
|
|
196
|
+
fs.statSync(sessionFile);
|
|
197
|
+
return true;
|
|
198
|
+
} catch {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
export function getNodeEnv() {
|
|
203
|
+
return "development";
|
|
204
|
+
}
|
|
205
|
+
export function getUserType() {
|
|
206
|
+
return process.env.USER_TYPE || "external";
|
|
207
|
+
}
|
|
208
|
+
function getEntrypoint() {
|
|
209
|
+
return process.env.CLAUDE_CODE_ENTRYPOINT;
|
|
210
|
+
}
|
|
211
|
+
export function isCustomTitleEnabled() {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
export const getProjectDir = memoize((projectDir) => {
|
|
215
|
+
return join(getProjectsDir(), sanitizePath(projectDir));
|
|
216
|
+
});
|
|
217
|
+
let project = null;
|
|
218
|
+
let cleanupRegistered = false;
|
|
219
|
+
function getProject() {
|
|
220
|
+
if (!project) {
|
|
221
|
+
project = new Project;
|
|
222
|
+
if (!cleanupRegistered) {
|
|
223
|
+
registerCleanup(async () => {
|
|
224
|
+
await project?.flush();
|
|
225
|
+
try {
|
|
226
|
+
project?.reAppendSessionMetadata();
|
|
227
|
+
} catch {}
|
|
228
|
+
});
|
|
229
|
+
cleanupRegistered = true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return project;
|
|
233
|
+
}
|
|
234
|
+
export function resetProjectFlushStateForTesting() {
|
|
235
|
+
project?._resetFlushState();
|
|
236
|
+
}
|
|
237
|
+
export function resetProjectForTesting() {
|
|
238
|
+
project = null;
|
|
239
|
+
}
|
|
240
|
+
export function setSessionFileForTesting(path) {
|
|
241
|
+
getProject().sessionFile = path;
|
|
242
|
+
}
|
|
243
|
+
export function setInternalEventWriter(writer) {
|
|
244
|
+
getProject().setInternalEventWriter(writer);
|
|
245
|
+
}
|
|
246
|
+
export function setInternalEventReader(reader, subagentReader) {
|
|
247
|
+
getProject().setInternalEventReader(reader);
|
|
248
|
+
getProject().setInternalSubagentEventReader(subagentReader);
|
|
249
|
+
}
|
|
250
|
+
export function setRemoteIngressUrlForTesting(url) {
|
|
251
|
+
getProject().setRemoteIngressUrl(url);
|
|
252
|
+
}
|
|
253
|
+
const REMOTE_FLUSH_INTERVAL_MS = 10;
|
|
254
|
+
|
|
255
|
+
class Project {
|
|
256
|
+
currentSessionTag;
|
|
257
|
+
currentSessionTitle;
|
|
258
|
+
currentSessionAgentName;
|
|
259
|
+
currentSessionAgentColor;
|
|
260
|
+
currentSessionLastPrompt;
|
|
261
|
+
currentSessionAgentSetting;
|
|
262
|
+
currentSessionMode;
|
|
263
|
+
currentSessionWorktree;
|
|
264
|
+
currentSessionPrNumber;
|
|
265
|
+
currentSessionPrUrl;
|
|
266
|
+
currentSessionPrRepository;
|
|
267
|
+
sessionFile = null;
|
|
268
|
+
pendingEntries = [];
|
|
269
|
+
remoteIngressUrl = null;
|
|
270
|
+
internalEventWriter = null;
|
|
271
|
+
internalEventReader = null;
|
|
272
|
+
internalSubagentEventReader = null;
|
|
273
|
+
pendingWriteCount = 0;
|
|
274
|
+
flushResolvers = [];
|
|
275
|
+
writeQueues = new Map;
|
|
276
|
+
flushTimer = null;
|
|
277
|
+
activeDrain = null;
|
|
278
|
+
FLUSH_INTERVAL_MS = 100;
|
|
279
|
+
MAX_CHUNK_BYTES = 100 * 1024 * 1024;
|
|
280
|
+
constructor() {}
|
|
281
|
+
_resetFlushState() {
|
|
282
|
+
this.pendingWriteCount = 0;
|
|
283
|
+
this.flushResolvers = [];
|
|
284
|
+
if (this.flushTimer)
|
|
285
|
+
clearTimeout(this.flushTimer);
|
|
286
|
+
this.flushTimer = null;
|
|
287
|
+
this.activeDrain = null;
|
|
288
|
+
this.writeQueues = new Map;
|
|
289
|
+
}
|
|
290
|
+
incrementPendingWrites() {
|
|
291
|
+
this.pendingWriteCount++;
|
|
292
|
+
}
|
|
293
|
+
decrementPendingWrites() {
|
|
294
|
+
this.pendingWriteCount--;
|
|
295
|
+
if (this.pendingWriteCount === 0) {
|
|
296
|
+
for (const resolve of this.flushResolvers) {
|
|
297
|
+
resolve();
|
|
298
|
+
}
|
|
299
|
+
this.flushResolvers = [];
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async trackWrite(fn) {
|
|
303
|
+
this.incrementPendingWrites();
|
|
304
|
+
try {
|
|
305
|
+
return await fn();
|
|
306
|
+
} finally {
|
|
307
|
+
this.decrementPendingWrites();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
enqueueWrite(filePath, entry) {
|
|
311
|
+
return new Promise((resolve) => {
|
|
312
|
+
let queue = this.writeQueues.get(filePath);
|
|
313
|
+
if (!queue) {
|
|
314
|
+
queue = [];
|
|
315
|
+
this.writeQueues.set(filePath, queue);
|
|
316
|
+
}
|
|
317
|
+
queue.push({ entry, resolve });
|
|
318
|
+
this.scheduleDrain();
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
scheduleDrain() {
|
|
322
|
+
if (this.flushTimer) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
this.flushTimer = setTimeout(async () => {
|
|
326
|
+
this.flushTimer = null;
|
|
327
|
+
this.activeDrain = this.drainWriteQueue();
|
|
328
|
+
await this.activeDrain;
|
|
329
|
+
this.activeDrain = null;
|
|
330
|
+
if (this.writeQueues.size > 0) {
|
|
331
|
+
this.scheduleDrain();
|
|
332
|
+
}
|
|
333
|
+
}, this.FLUSH_INTERVAL_MS);
|
|
334
|
+
}
|
|
335
|
+
async appendToFile(filePath, data) {
|
|
336
|
+
try {
|
|
337
|
+
await fsAppendFile(filePath, data, { mode: 384 });
|
|
338
|
+
} catch {
|
|
339
|
+
await mkdir(dirname(filePath), { recursive: true, mode: 448 });
|
|
340
|
+
await fsAppendFile(filePath, data, { mode: 384 });
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
async drainWriteQueue() {
|
|
344
|
+
for (const [filePath, queue] of this.writeQueues) {
|
|
345
|
+
if (queue.length === 0) {
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const batch = queue.splice(0);
|
|
349
|
+
let content = "";
|
|
350
|
+
const resolvers = [];
|
|
351
|
+
for (const { entry, resolve } of batch) {
|
|
352
|
+
const line = jsonStringify(entry) + `
|
|
353
|
+
`;
|
|
354
|
+
if (content.length + line.length >= this.MAX_CHUNK_BYTES) {
|
|
355
|
+
await this.appendToFile(filePath, content);
|
|
356
|
+
for (const r of resolvers) {
|
|
357
|
+
r();
|
|
358
|
+
}
|
|
359
|
+
resolvers.length = 0;
|
|
360
|
+
content = "";
|
|
361
|
+
}
|
|
362
|
+
content += line;
|
|
363
|
+
resolvers.push(resolve);
|
|
364
|
+
}
|
|
365
|
+
if (content.length > 0) {
|
|
366
|
+
await this.appendToFile(filePath, content);
|
|
367
|
+
for (const r of resolvers) {
|
|
368
|
+
r();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
for (const [filePath, queue] of this.writeQueues) {
|
|
373
|
+
if (queue.length === 0) {
|
|
374
|
+
this.writeQueues.delete(filePath);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
resetSessionFile() {
|
|
379
|
+
this.sessionFile = null;
|
|
380
|
+
this.pendingEntries = [];
|
|
381
|
+
}
|
|
382
|
+
reAppendSessionMetadata(skipTitleRefresh = false) {
|
|
383
|
+
if (!this.sessionFile)
|
|
384
|
+
return;
|
|
385
|
+
const sessionId = getSessionId();
|
|
386
|
+
if (!sessionId)
|
|
387
|
+
return;
|
|
388
|
+
const tail = readFileTailSync(this.sessionFile);
|
|
389
|
+
const tailLines = tail.split(`
|
|
390
|
+
`);
|
|
391
|
+
if (!skipTitleRefresh) {
|
|
392
|
+
const titleLine = tailLines.findLast((l) => l.startsWith('{"type":"custom-title"'));
|
|
393
|
+
if (titleLine) {
|
|
394
|
+
const tailTitle = extractLastJsonStringField(titleLine, "customTitle");
|
|
395
|
+
if (tailTitle !== undefined) {
|
|
396
|
+
this.currentSessionTitle = tailTitle || undefined;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
const tagLine = tailLines.findLast((l) => l.startsWith('{"type":"tag"'));
|
|
401
|
+
if (tagLine) {
|
|
402
|
+
const tailTag = extractLastJsonStringField(tagLine, "tag");
|
|
403
|
+
if (tailTag !== undefined) {
|
|
404
|
+
this.currentSessionTag = tailTag || undefined;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (this.currentSessionLastPrompt) {
|
|
408
|
+
appendEntryToFile(this.sessionFile, {
|
|
409
|
+
type: "last-prompt",
|
|
410
|
+
lastPrompt: this.currentSessionLastPrompt,
|
|
411
|
+
sessionId
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
if (this.currentSessionTitle) {
|
|
415
|
+
appendEntryToFile(this.sessionFile, {
|
|
416
|
+
type: "custom-title",
|
|
417
|
+
customTitle: this.currentSessionTitle,
|
|
418
|
+
sessionId
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
if (this.currentSessionTag) {
|
|
422
|
+
appendEntryToFile(this.sessionFile, {
|
|
423
|
+
type: "tag",
|
|
424
|
+
tag: this.currentSessionTag,
|
|
425
|
+
sessionId
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
if (this.currentSessionAgentName) {
|
|
429
|
+
appendEntryToFile(this.sessionFile, {
|
|
430
|
+
type: "agent-name",
|
|
431
|
+
agentName: this.currentSessionAgentName,
|
|
432
|
+
sessionId
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
if (this.currentSessionAgentColor) {
|
|
436
|
+
appendEntryToFile(this.sessionFile, {
|
|
437
|
+
type: "agent-color",
|
|
438
|
+
agentColor: this.currentSessionAgentColor,
|
|
439
|
+
sessionId
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
if (this.currentSessionAgentSetting) {
|
|
443
|
+
appendEntryToFile(this.sessionFile, {
|
|
444
|
+
type: "agent-setting",
|
|
445
|
+
agentSetting: this.currentSessionAgentSetting,
|
|
446
|
+
sessionId
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
if (this.currentSessionMode) {
|
|
450
|
+
appendEntryToFile(this.sessionFile, {
|
|
451
|
+
type: "mode",
|
|
452
|
+
mode: this.currentSessionMode,
|
|
453
|
+
sessionId
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
if (this.currentSessionWorktree !== undefined) {
|
|
457
|
+
appendEntryToFile(this.sessionFile, {
|
|
458
|
+
type: "worktree-state",
|
|
459
|
+
worktreeSession: this.currentSessionWorktree,
|
|
460
|
+
sessionId
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
if (this.currentSessionPrNumber !== undefined && this.currentSessionPrUrl && this.currentSessionPrRepository) {
|
|
464
|
+
appendEntryToFile(this.sessionFile, {
|
|
465
|
+
type: "pr-link",
|
|
466
|
+
sessionId,
|
|
467
|
+
prNumber: this.currentSessionPrNumber,
|
|
468
|
+
prUrl: this.currentSessionPrUrl,
|
|
469
|
+
prRepository: this.currentSessionPrRepository,
|
|
470
|
+
timestamp: new Date().toISOString()
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
async flush() {
|
|
475
|
+
if (this.flushTimer) {
|
|
476
|
+
clearTimeout(this.flushTimer);
|
|
477
|
+
this.flushTimer = null;
|
|
478
|
+
}
|
|
479
|
+
if (this.activeDrain) {
|
|
480
|
+
await this.activeDrain;
|
|
481
|
+
}
|
|
482
|
+
await this.drainWriteQueue();
|
|
483
|
+
if (this.pendingWriteCount === 0) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
return new Promise((resolve) => {
|
|
487
|
+
this.flushResolvers.push(resolve);
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
async removeMessageByUuid(targetUuid) {
|
|
491
|
+
return this.trackWrite(async () => {
|
|
492
|
+
if (this.sessionFile === null)
|
|
493
|
+
return;
|
|
494
|
+
try {
|
|
495
|
+
let fileSize = 0;
|
|
496
|
+
const fh = await fsOpen(this.sessionFile, "r+");
|
|
497
|
+
try {
|
|
498
|
+
const { size } = await fh.stat();
|
|
499
|
+
fileSize = size;
|
|
500
|
+
if (size === 0)
|
|
501
|
+
return;
|
|
502
|
+
const chunkLen = Math.min(size, LITE_READ_BUF_SIZE);
|
|
503
|
+
const tailStart = size - chunkLen;
|
|
504
|
+
const buf = Buffer.allocUnsafe(chunkLen);
|
|
505
|
+
const { bytesRead } = await fh.read(buf, 0, chunkLen, tailStart);
|
|
506
|
+
const tail = buf.subarray(0, bytesRead);
|
|
507
|
+
const needle = `"uuid":"${targetUuid}"`;
|
|
508
|
+
const matchIdx = tail.lastIndexOf(needle);
|
|
509
|
+
if (matchIdx >= 0) {
|
|
510
|
+
const prevNl = tail.lastIndexOf(10, matchIdx);
|
|
511
|
+
if (prevNl >= 0 || tailStart === 0) {
|
|
512
|
+
const lineStart = prevNl + 1;
|
|
513
|
+
const nextNl = tail.indexOf(10, matchIdx + needle.length);
|
|
514
|
+
const lineEnd = nextNl >= 0 ? nextNl + 1 : bytesRead;
|
|
515
|
+
const absLineStart = tailStart + lineStart;
|
|
516
|
+
const afterLen = bytesRead - lineEnd;
|
|
517
|
+
await fh.truncate(absLineStart);
|
|
518
|
+
if (afterLen > 0) {
|
|
519
|
+
await fh.write(tail, lineEnd, afterLen, absLineStart);
|
|
520
|
+
}
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
} finally {
|
|
525
|
+
await fh.close();
|
|
526
|
+
}
|
|
527
|
+
if (fileSize > MAX_TOMBSTONE_REWRITE_BYTES) {
|
|
528
|
+
logForDebugging(`Skipping tombstone removal: session file too large (${formatFileSize(fileSize)})`, { level: "warn" });
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
const content = await readFile(this.sessionFile, { encoding: "utf-8" });
|
|
532
|
+
const lines = content.split(`
|
|
533
|
+
`).filter((line) => {
|
|
534
|
+
if (!line.trim())
|
|
535
|
+
return true;
|
|
536
|
+
try {
|
|
537
|
+
const entry = jsonParse(line);
|
|
538
|
+
return entry.uuid !== targetUuid;
|
|
539
|
+
} catch {
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
await writeFile(this.sessionFile, lines.join(`
|
|
544
|
+
`), {
|
|
545
|
+
encoding: "utf8"
|
|
546
|
+
});
|
|
547
|
+
} catch {}
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
shouldSkipPersistence() {
|
|
551
|
+
const allowTestPersistence = isEnvTruthy(process.env.TEST_ENABLE_SESSION_PERSISTENCE);
|
|
552
|
+
return getNodeEnv() === "test" && !allowTestPersistence || getSettings_DEPRECATED()?.cleanupPeriodDays === 0 || isSessionPersistenceDisabled() || isEnvTruthy(process.env.CLAUDE_CODE_SKIP_PROMPT_HISTORY);
|
|
553
|
+
}
|
|
554
|
+
async materializeSessionFile() {
|
|
555
|
+
if (this.shouldSkipPersistence())
|
|
556
|
+
return;
|
|
557
|
+
this.ensureCurrentSessionFile();
|
|
558
|
+
this.reAppendSessionMetadata();
|
|
559
|
+
if (this.pendingEntries.length > 0) {
|
|
560
|
+
const buffered = this.pendingEntries;
|
|
561
|
+
this.pendingEntries = [];
|
|
562
|
+
for (const entry of buffered) {
|
|
563
|
+
await this.appendEntry(entry);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async insertMessageChain(messages, isSidechain = false, agentId, startingParentUuid, teamInfo) {
|
|
568
|
+
return this.trackWrite(async () => {
|
|
569
|
+
let parentUuid = startingParentUuid ?? null;
|
|
570
|
+
if (this.sessionFile === null && messages.some((m) => m.type === "user" || m.type === "assistant")) {
|
|
571
|
+
await this.materializeSessionFile();
|
|
572
|
+
}
|
|
573
|
+
let gitBranch;
|
|
574
|
+
try {
|
|
575
|
+
gitBranch = await getBranch();
|
|
576
|
+
} catch {
|
|
577
|
+
gitBranch = undefined;
|
|
578
|
+
}
|
|
579
|
+
const sessionId = getSessionId();
|
|
580
|
+
const slug = getPlanSlugCache().get(sessionId);
|
|
581
|
+
for (const message of messages) {
|
|
582
|
+
const isCompactBoundary = isCompactBoundaryMessage(message);
|
|
583
|
+
let effectiveParentUuid = parentUuid;
|
|
584
|
+
if (message.type === "user" && "sourceToolAssistantUUID" in message && message.sourceToolAssistantUUID) {
|
|
585
|
+
effectiveParentUuid = message.sourceToolAssistantUUID;
|
|
586
|
+
}
|
|
587
|
+
const transcriptMessage = {
|
|
588
|
+
parentUuid: isCompactBoundary ? null : effectiveParentUuid,
|
|
589
|
+
logicalParentUuid: isCompactBoundary ? parentUuid : undefined,
|
|
590
|
+
isSidechain,
|
|
591
|
+
teamName: teamInfo?.teamName,
|
|
592
|
+
agentName: teamInfo?.agentName,
|
|
593
|
+
promptId: message.type === "user" ? getPromptId() ?? undefined : undefined,
|
|
594
|
+
agentId,
|
|
595
|
+
...message,
|
|
596
|
+
userType: getUserType(),
|
|
597
|
+
entrypoint: getEntrypoint(),
|
|
598
|
+
cwd: getCwd(),
|
|
599
|
+
sessionId,
|
|
600
|
+
version: VERSION,
|
|
601
|
+
gitBranch,
|
|
602
|
+
slug
|
|
603
|
+
};
|
|
604
|
+
await this.appendEntry(transcriptMessage);
|
|
605
|
+
if (isChainParticipant(message)) {
|
|
606
|
+
parentUuid = message.uuid;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
if (!isSidechain) {
|
|
610
|
+
const text = getFirstMeaningfulUserMessageTextContent(messages);
|
|
611
|
+
if (text) {
|
|
612
|
+
const flat = text.replace(/\n/g, " ").trim();
|
|
613
|
+
this.currentSessionLastPrompt = flat.length > 200 ? flat.slice(0, 200).trim() + "…" : flat;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
async insertFileHistorySnapshot(messageId, snapshot, isSnapshotUpdate) {
|
|
619
|
+
return this.trackWrite(async () => {
|
|
620
|
+
const fileHistoryMessage = {
|
|
621
|
+
type: "file-history-snapshot",
|
|
622
|
+
messageId,
|
|
623
|
+
snapshot,
|
|
624
|
+
isSnapshotUpdate
|
|
625
|
+
};
|
|
626
|
+
await this.appendEntry(fileHistoryMessage);
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
async insertQueueOperation(queueOp) {
|
|
630
|
+
return this.trackWrite(async () => {
|
|
631
|
+
await this.appendEntry(queueOp);
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
async insertAttributionSnapshot(snapshot) {
|
|
635
|
+
return this.trackWrite(async () => {
|
|
636
|
+
await this.appendEntry(snapshot);
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
async insertContentReplacement(replacements, agentId) {
|
|
640
|
+
return this.trackWrite(async () => {
|
|
641
|
+
const entry = {
|
|
642
|
+
type: "content-replacement",
|
|
643
|
+
sessionId: getSessionId(),
|
|
644
|
+
agentId,
|
|
645
|
+
replacements
|
|
646
|
+
};
|
|
647
|
+
await this.appendEntry(entry);
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
async appendEntry(entry, sessionId = getSessionId()) {
|
|
651
|
+
if (this.shouldSkipPersistence()) {
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
const currentSessionId = getSessionId();
|
|
655
|
+
const isCurrentSession = sessionId === currentSessionId;
|
|
656
|
+
let sessionFile;
|
|
657
|
+
if (isCurrentSession) {
|
|
658
|
+
if (this.sessionFile === null) {
|
|
659
|
+
this.pendingEntries.push(entry);
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
sessionFile = this.sessionFile;
|
|
663
|
+
} else {
|
|
664
|
+
const existing = await this.getExistingSessionFile(sessionId);
|
|
665
|
+
if (!existing) {
|
|
666
|
+
logError(new Error(`appendEntry: session file not found for other session ${sessionId}`));
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
sessionFile = existing;
|
|
670
|
+
}
|
|
671
|
+
if (entry.type === "summary") {
|
|
672
|
+
this.enqueueWrite(sessionFile, entry);
|
|
673
|
+
} else if (entry.type === "custom-title") {
|
|
674
|
+
this.enqueueWrite(sessionFile, entry);
|
|
675
|
+
} else if (entry.type === "ai-title") {
|
|
676
|
+
this.enqueueWrite(sessionFile, entry);
|
|
677
|
+
} else if (entry.type === "last-prompt") {
|
|
678
|
+
this.enqueueWrite(sessionFile, entry);
|
|
679
|
+
} else if (entry.type === "task-summary") {
|
|
680
|
+
this.enqueueWrite(sessionFile, entry);
|
|
681
|
+
} else if (entry.type === "tag") {
|
|
682
|
+
this.enqueueWrite(sessionFile, entry);
|
|
683
|
+
} else if (entry.type === "agent-name") {
|
|
684
|
+
this.enqueueWrite(sessionFile, entry);
|
|
685
|
+
} else if (entry.type === "agent-color") {
|
|
686
|
+
this.enqueueWrite(sessionFile, entry);
|
|
687
|
+
} else if (entry.type === "agent-setting") {
|
|
688
|
+
this.enqueueWrite(sessionFile, entry);
|
|
689
|
+
} else if (entry.type === "pr-link") {
|
|
690
|
+
this.enqueueWrite(sessionFile, entry);
|
|
691
|
+
} else if (entry.type === "file-history-snapshot") {
|
|
692
|
+
this.enqueueWrite(sessionFile, entry);
|
|
693
|
+
} else if (entry.type === "attribution-snapshot") {
|
|
694
|
+
this.enqueueWrite(sessionFile, entry);
|
|
695
|
+
} else if (entry.type === "speculation-accept") {
|
|
696
|
+
this.enqueueWrite(sessionFile, entry);
|
|
697
|
+
} else if (entry.type === "mode") {
|
|
698
|
+
this.enqueueWrite(sessionFile, entry);
|
|
699
|
+
} else if (entry.type === "worktree-state") {
|
|
700
|
+
this.enqueueWrite(sessionFile, entry);
|
|
701
|
+
} else if (entry.type === "content-replacement") {
|
|
702
|
+
const targetFile = entry.agentId ? getAgentTranscriptPath(entry.agentId) : sessionFile;
|
|
703
|
+
this.enqueueWrite(targetFile, entry);
|
|
704
|
+
} else if (entry.type === "marble-origami-commit") {
|
|
705
|
+
this.enqueueWrite(sessionFile, entry);
|
|
706
|
+
} else if (entry.type === "marble-origami-snapshot") {
|
|
707
|
+
this.enqueueWrite(sessionFile, entry);
|
|
708
|
+
} else {
|
|
709
|
+
const messageSet = await getSessionMessages(sessionId);
|
|
710
|
+
if (entry.type === "queue-operation") {
|
|
711
|
+
this.enqueueWrite(sessionFile, entry);
|
|
712
|
+
} else {
|
|
713
|
+
const isAgentSidechain = entry.isSidechain && entry.agentId !== undefined;
|
|
714
|
+
const targetFile = isAgentSidechain ? getAgentTranscriptPath(asAgentId(entry.agentId)) : sessionFile;
|
|
715
|
+
const isNewUuid = !messageSet.has(entry.uuid);
|
|
716
|
+
if (isAgentSidechain || isNewUuid) {
|
|
717
|
+
this.enqueueWrite(targetFile, entry);
|
|
718
|
+
if (!isAgentSidechain) {
|
|
719
|
+
messageSet.add(entry.uuid);
|
|
720
|
+
if (isTranscriptMessage(entry)) {
|
|
721
|
+
await this.persistToRemote(sessionId, entry);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
ensureCurrentSessionFile() {
|
|
729
|
+
if (this.sessionFile === null) {
|
|
730
|
+
this.sessionFile = getTranscriptPath();
|
|
731
|
+
}
|
|
732
|
+
return this.sessionFile;
|
|
733
|
+
}
|
|
734
|
+
existingSessionFiles = new Map;
|
|
735
|
+
async getExistingSessionFile(sessionId) {
|
|
736
|
+
const cached = this.existingSessionFiles.get(sessionId);
|
|
737
|
+
if (cached)
|
|
738
|
+
return cached;
|
|
739
|
+
const targetFile = getTranscriptPathForSession(sessionId);
|
|
740
|
+
try {
|
|
741
|
+
await stat(targetFile);
|
|
742
|
+
this.existingSessionFiles.set(sessionId, targetFile);
|
|
743
|
+
return targetFile;
|
|
744
|
+
} catch (e) {
|
|
745
|
+
if (isFsInaccessible(e))
|
|
746
|
+
return null;
|
|
747
|
+
throw e;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
async persistToRemote(sessionId, entry) {
|
|
751
|
+
if (isShuttingDown()) {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
if (this.internalEventWriter) {
|
|
755
|
+
try {
|
|
756
|
+
await this.internalEventWriter("transcript", entry, {
|
|
757
|
+
...isCompactBoundaryMessage(entry) && { isCompaction: true },
|
|
758
|
+
...entry.agentId && { agentId: entry.agentId }
|
|
759
|
+
});
|
|
760
|
+
} catch {
|
|
761
|
+
logEvent("tengu_session_persistence_failed", {});
|
|
762
|
+
logForDebugging("Failed to write transcript as internal event");
|
|
763
|
+
}
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
if (!isEnvTruthy(process.env.ENABLE_SESSION_PERSISTENCE) || !this.remoteIngressUrl) {
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
const success = await sessionIngress.appendSessionLog(sessionId, entry, this.remoteIngressUrl);
|
|
770
|
+
if (!success) {
|
|
771
|
+
logEvent("tengu_session_persistence_failed", {});
|
|
772
|
+
gracefulShutdownSync(1, "other");
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
setRemoteIngressUrl(url) {
|
|
776
|
+
this.remoteIngressUrl = url;
|
|
777
|
+
logForDebugging(`Remote persistence enabled with URL: ${url}`);
|
|
778
|
+
if (url) {
|
|
779
|
+
this.FLUSH_INTERVAL_MS = REMOTE_FLUSH_INTERVAL_MS;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
setInternalEventWriter(writer) {
|
|
783
|
+
this.internalEventWriter = writer;
|
|
784
|
+
logForDebugging("CCR v2 internal event writer registered for transcript persistence");
|
|
785
|
+
this.FLUSH_INTERVAL_MS = REMOTE_FLUSH_INTERVAL_MS;
|
|
786
|
+
}
|
|
787
|
+
setInternalEventReader(reader) {
|
|
788
|
+
this.internalEventReader = reader;
|
|
789
|
+
logForDebugging("CCR v2 internal event reader registered for session resume");
|
|
790
|
+
}
|
|
791
|
+
setInternalSubagentEventReader(reader) {
|
|
792
|
+
this.internalSubagentEventReader = reader;
|
|
793
|
+
logForDebugging("CCR v2 subagent event reader registered for session resume");
|
|
794
|
+
}
|
|
795
|
+
getInternalEventReader() {
|
|
796
|
+
return this.internalEventReader;
|
|
797
|
+
}
|
|
798
|
+
getInternalSubagentEventReader() {
|
|
799
|
+
return this.internalSubagentEventReader;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
export async function recordTranscript(messages, teamInfo, startingParentUuidHint, allMessages) {
|
|
803
|
+
const cleanedMessages = cleanMessagesForLogging(messages, allMessages);
|
|
804
|
+
const sessionId = getSessionId();
|
|
805
|
+
const messageSet = await getSessionMessages(sessionId);
|
|
806
|
+
const newMessages = [];
|
|
807
|
+
let startingParentUuid = startingParentUuidHint;
|
|
808
|
+
let seenNewMessage = false;
|
|
809
|
+
for (const m of cleanedMessages) {
|
|
810
|
+
if (messageSet.has(m.uuid)) {
|
|
811
|
+
if (!seenNewMessage && isChainParticipant(m)) {
|
|
812
|
+
startingParentUuid = m.uuid;
|
|
813
|
+
}
|
|
814
|
+
} else {
|
|
815
|
+
newMessages.push(m);
|
|
816
|
+
seenNewMessage = true;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
if (newMessages.length > 0) {
|
|
820
|
+
await getProject().insertMessageChain(newMessages, false, undefined, startingParentUuid, teamInfo);
|
|
821
|
+
}
|
|
822
|
+
const lastRecorded = newMessages.findLast(isChainParticipant);
|
|
823
|
+
return lastRecorded?.uuid ?? startingParentUuid ?? null;
|
|
824
|
+
}
|
|
825
|
+
export async function recordSidechainTranscript(messages, agentId, startingParentUuid) {
|
|
826
|
+
await getProject().insertMessageChain(cleanMessagesForLogging(messages), true, agentId, startingParentUuid);
|
|
827
|
+
}
|
|
828
|
+
export async function recordQueueOperation(queueOp) {
|
|
829
|
+
await getProject().insertQueueOperation(queueOp);
|
|
830
|
+
}
|
|
831
|
+
export async function removeTranscriptMessage(targetUuid) {
|
|
832
|
+
await getProject().removeMessageByUuid(targetUuid);
|
|
833
|
+
}
|
|
834
|
+
export async function recordFileHistorySnapshot(messageId, snapshot, isSnapshotUpdate) {
|
|
835
|
+
await getProject().insertFileHistorySnapshot(messageId, snapshot, isSnapshotUpdate);
|
|
836
|
+
}
|
|
837
|
+
export async function recordAttributionSnapshot(snapshot) {
|
|
838
|
+
await getProject().insertAttributionSnapshot(snapshot);
|
|
839
|
+
}
|
|
840
|
+
export async function recordContentReplacement(replacements, agentId) {
|
|
841
|
+
await getProject().insertContentReplacement(replacements, agentId);
|
|
842
|
+
}
|
|
843
|
+
export async function resetSessionFilePointer() {
|
|
844
|
+
getProject().resetSessionFile();
|
|
845
|
+
}
|
|
846
|
+
export function adoptResumedSessionFile() {
|
|
847
|
+
const project = getProject();
|
|
848
|
+
project.sessionFile = getTranscriptPath();
|
|
849
|
+
project.reAppendSessionMetadata(true);
|
|
850
|
+
}
|
|
851
|
+
export async function recordContextCollapseCommit(commit) {
|
|
852
|
+
const sessionId = getSessionId();
|
|
853
|
+
if (!sessionId)
|
|
854
|
+
return;
|
|
855
|
+
await getProject().appendEntry({
|
|
856
|
+
type: "marble-origami-commit",
|
|
857
|
+
sessionId,
|
|
858
|
+
...commit
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
export async function recordContextCollapseSnapshot(snapshot) {
|
|
862
|
+
const sessionId = getSessionId();
|
|
863
|
+
if (!sessionId)
|
|
864
|
+
return;
|
|
865
|
+
await getProject().appendEntry({
|
|
866
|
+
type: "marble-origami-snapshot",
|
|
867
|
+
sessionId,
|
|
868
|
+
...snapshot
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
export async function flushSessionStorage() {
|
|
872
|
+
await getProject().flush();
|
|
873
|
+
}
|
|
874
|
+
export async function hydrateRemoteSession(sessionId, ingressUrl) {
|
|
875
|
+
switchSession(asSessionId(sessionId));
|
|
876
|
+
const project = getProject();
|
|
877
|
+
try {
|
|
878
|
+
const remoteLogs = await sessionIngress.getSessionLogs(sessionId, ingressUrl) || [];
|
|
879
|
+
const projectDir = getProjectDir(getOriginalCwd());
|
|
880
|
+
await mkdir(projectDir, { recursive: true, mode: 448 });
|
|
881
|
+
const sessionFile = getTranscriptPathForSession(sessionId);
|
|
882
|
+
const content = remoteLogs.map((e) => jsonStringify(e) + `
|
|
883
|
+
`).join("");
|
|
884
|
+
await writeFile(sessionFile, content, { encoding: "utf8", mode: 384 });
|
|
885
|
+
logForDebugging(`Hydrated ${remoteLogs.length} entries from remote`);
|
|
886
|
+
return remoteLogs.length > 0;
|
|
887
|
+
} catch (error) {
|
|
888
|
+
logForDebugging(`Error hydrating session from remote: ${error}`);
|
|
889
|
+
logForDiagnosticsNoPII("error", "hydrate_remote_session_fail");
|
|
890
|
+
return false;
|
|
891
|
+
} finally {
|
|
892
|
+
project.setRemoteIngressUrl(ingressUrl);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
export async function hydrateFromCCRv2InternalEvents(sessionId) {
|
|
896
|
+
const startMs = Date.now();
|
|
897
|
+
switchSession(asSessionId(sessionId));
|
|
898
|
+
const project = getProject();
|
|
899
|
+
const reader = project.getInternalEventReader();
|
|
900
|
+
if (!reader) {
|
|
901
|
+
logForDebugging("No internal event reader registered for CCR v2 resume");
|
|
902
|
+
return false;
|
|
903
|
+
}
|
|
904
|
+
try {
|
|
905
|
+
const events = await reader();
|
|
906
|
+
if (!events) {
|
|
907
|
+
logForDebugging("Failed to read internal events for resume");
|
|
908
|
+
logForDiagnosticsNoPII("error", "hydrate_ccr_v2_read_fail");
|
|
909
|
+
return false;
|
|
910
|
+
}
|
|
911
|
+
const projectDir = getProjectDir(getOriginalCwd());
|
|
912
|
+
await mkdir(projectDir, { recursive: true, mode: 448 });
|
|
913
|
+
const sessionFile = getTranscriptPathForSession(sessionId);
|
|
914
|
+
const fgContent = events.map((e) => jsonStringify(e.payload) + `
|
|
915
|
+
`).join("");
|
|
916
|
+
await writeFile(sessionFile, fgContent, { encoding: "utf8", mode: 384 });
|
|
917
|
+
logForDebugging(`Hydrated ${events.length} foreground entries from CCR v2 internal events`);
|
|
918
|
+
let subagentEventCount = 0;
|
|
919
|
+
const subagentReader = project.getInternalSubagentEventReader();
|
|
920
|
+
if (subagentReader) {
|
|
921
|
+
const subagentEvents = await subagentReader();
|
|
922
|
+
if (subagentEvents && subagentEvents.length > 0) {
|
|
923
|
+
subagentEventCount = subagentEvents.length;
|
|
924
|
+
const byAgent = new Map;
|
|
925
|
+
for (const e of subagentEvents) {
|
|
926
|
+
const agentId = e.agent_id || "";
|
|
927
|
+
if (!agentId)
|
|
928
|
+
continue;
|
|
929
|
+
let list = byAgent.get(agentId);
|
|
930
|
+
if (!list) {
|
|
931
|
+
list = [];
|
|
932
|
+
byAgent.set(agentId, list);
|
|
933
|
+
}
|
|
934
|
+
list.push(e.payload);
|
|
935
|
+
}
|
|
936
|
+
for (const [agentId, entries] of byAgent) {
|
|
937
|
+
const agentFile = getAgentTranscriptPath(asAgentId(agentId));
|
|
938
|
+
await mkdir(dirname(agentFile), { recursive: true, mode: 448 });
|
|
939
|
+
const agentContent = entries.map((p) => jsonStringify(p) + `
|
|
940
|
+
`).join("");
|
|
941
|
+
await writeFile(agentFile, agentContent, {
|
|
942
|
+
encoding: "utf8",
|
|
943
|
+
mode: 384
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
logForDebugging(`Hydrated ${subagentEvents.length} subagent entries across ${byAgent.size} agents`);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
logForDiagnosticsNoPII("info", "hydrate_ccr_v2_completed", {
|
|
950
|
+
duration_ms: Date.now() - startMs,
|
|
951
|
+
event_count: events.length,
|
|
952
|
+
subagent_event_count: subagentEventCount
|
|
953
|
+
});
|
|
954
|
+
return events.length > 0;
|
|
955
|
+
} catch (error) {
|
|
956
|
+
if (error instanceof Error && error.message === "CCRClient: Epoch mismatch (409)") {
|
|
957
|
+
throw error;
|
|
958
|
+
}
|
|
959
|
+
logForDebugging(`Error hydrating session from CCR v2: ${error}`);
|
|
960
|
+
logForDiagnosticsNoPII("error", "hydrate_ccr_v2_fail");
|
|
961
|
+
return false;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
function extractFirstPrompt(transcript) {
|
|
965
|
+
const textContent = getFirstMeaningfulUserMessageTextContent(transcript);
|
|
966
|
+
if (textContent) {
|
|
967
|
+
let result = textContent.replace(/\n/g, " ").trim();
|
|
968
|
+
if (result.length > 200) {
|
|
969
|
+
result = result.slice(0, 200).trim() + "…";
|
|
970
|
+
}
|
|
971
|
+
return result;
|
|
972
|
+
}
|
|
973
|
+
return "No prompt";
|
|
974
|
+
}
|
|
975
|
+
export function getFirstMeaningfulUserMessageTextContent(transcript) {
|
|
976
|
+
for (const msg of transcript) {
|
|
977
|
+
if (msg.type !== "user" || msg.isMeta)
|
|
978
|
+
continue;
|
|
979
|
+
if ("isCompactSummary" in msg && msg.isCompactSummary)
|
|
980
|
+
continue;
|
|
981
|
+
const content = msg.message?.content;
|
|
982
|
+
if (!content)
|
|
983
|
+
continue;
|
|
984
|
+
const texts = [];
|
|
985
|
+
if (typeof content === "string") {
|
|
986
|
+
texts.push(content);
|
|
987
|
+
} else if (Array.isArray(content)) {
|
|
988
|
+
for (const block of content) {
|
|
989
|
+
if (block.type === "text" && block.text) {
|
|
990
|
+
texts.push(block.text);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
for (const textContent of texts) {
|
|
995
|
+
if (!textContent)
|
|
996
|
+
continue;
|
|
997
|
+
const commandNameTag = extractTag(textContent, COMMAND_NAME_TAG);
|
|
998
|
+
if (commandNameTag) {
|
|
999
|
+
const commandName = commandNameTag.replace(/^\//, "");
|
|
1000
|
+
if (builtInCommandNames().has(commandName)) {
|
|
1001
|
+
continue;
|
|
1002
|
+
} else {
|
|
1003
|
+
const commandArgs = extractTag(textContent, "command-args")?.trim();
|
|
1004
|
+
if (!commandArgs) {
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
return `${commandNameTag} ${commandArgs}`;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
const bashInput = extractTag(textContent, "bash-input");
|
|
1011
|
+
if (bashInput) {
|
|
1012
|
+
return `! ${bashInput}`;
|
|
1013
|
+
}
|
|
1014
|
+
if (SKIP_FIRST_PROMPT_PATTERN.test(textContent)) {
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
return textContent;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
export function removeExtraFields(transcript) {
|
|
1023
|
+
return transcript.map((m) => {
|
|
1024
|
+
const { isSidechain, parentUuid, ...serializedMessage } = m;
|
|
1025
|
+
return serializedMessage;
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
function applyPreservedSegmentRelinks(messages) {
|
|
1029
|
+
let lastSeg;
|
|
1030
|
+
let lastSegBoundaryIdx = -1;
|
|
1031
|
+
let absoluteLastBoundaryIdx = -1;
|
|
1032
|
+
const entryIndex = new Map;
|
|
1033
|
+
let i = 0;
|
|
1034
|
+
for (const entry of messages.values()) {
|
|
1035
|
+
entryIndex.set(entry.uuid, i);
|
|
1036
|
+
if (isCompactBoundaryMessage(entry)) {
|
|
1037
|
+
absoluteLastBoundaryIdx = i;
|
|
1038
|
+
const seg = entry.compactMetadata?.preservedSegment;
|
|
1039
|
+
if (seg) {
|
|
1040
|
+
lastSeg = seg;
|
|
1041
|
+
lastSegBoundaryIdx = i;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
i++;
|
|
1045
|
+
}
|
|
1046
|
+
if (!lastSeg)
|
|
1047
|
+
return;
|
|
1048
|
+
const segIsLive = lastSegBoundaryIdx === absoluteLastBoundaryIdx;
|
|
1049
|
+
const preservedUuids = new Set;
|
|
1050
|
+
if (segIsLive) {
|
|
1051
|
+
const walkSeen = new Set;
|
|
1052
|
+
let cur = messages.get(lastSeg.tailUuid);
|
|
1053
|
+
let reachedHead = false;
|
|
1054
|
+
while (cur && !walkSeen.has(cur.uuid)) {
|
|
1055
|
+
walkSeen.add(cur.uuid);
|
|
1056
|
+
preservedUuids.add(cur.uuid);
|
|
1057
|
+
if (cur.uuid === lastSeg.headUuid) {
|
|
1058
|
+
reachedHead = true;
|
|
1059
|
+
break;
|
|
1060
|
+
}
|
|
1061
|
+
cur = cur.parentUuid ? messages.get(cur.parentUuid) : undefined;
|
|
1062
|
+
}
|
|
1063
|
+
if (!reachedHead) {
|
|
1064
|
+
logEvent("tengu_relink_walk_broken", {
|
|
1065
|
+
tailInTranscript: messages.has(lastSeg.tailUuid),
|
|
1066
|
+
headInTranscript: messages.has(lastSeg.headUuid),
|
|
1067
|
+
anchorInTranscript: messages.has(lastSeg.anchorUuid),
|
|
1068
|
+
walkSteps: walkSeen.size,
|
|
1069
|
+
transcriptSize: messages.size
|
|
1070
|
+
});
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
if (segIsLive) {
|
|
1075
|
+
const head = messages.get(lastSeg.headUuid);
|
|
1076
|
+
if (head) {
|
|
1077
|
+
messages.set(lastSeg.headUuid, {
|
|
1078
|
+
...head,
|
|
1079
|
+
parentUuid: lastSeg.anchorUuid
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
for (const [uuid, msg] of messages) {
|
|
1083
|
+
if (msg.parentUuid === lastSeg.anchorUuid && uuid !== lastSeg.headUuid) {
|
|
1084
|
+
messages.set(uuid, { ...msg, parentUuid: lastSeg.tailUuid });
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
for (const uuid of preservedUuids) {
|
|
1088
|
+
const msg = messages.get(uuid);
|
|
1089
|
+
if (msg?.type !== "assistant")
|
|
1090
|
+
continue;
|
|
1091
|
+
messages.set(uuid, {
|
|
1092
|
+
...msg,
|
|
1093
|
+
message: {
|
|
1094
|
+
...msg.message,
|
|
1095
|
+
usage: {
|
|
1096
|
+
...msg.message.usage,
|
|
1097
|
+
input_tokens: 0,
|
|
1098
|
+
output_tokens: 0,
|
|
1099
|
+
cache_creation_input_tokens: 0,
|
|
1100
|
+
cache_read_input_tokens: 0
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
const toDelete = [];
|
|
1107
|
+
for (const [uuid] of messages) {
|
|
1108
|
+
const idx = entryIndex.get(uuid);
|
|
1109
|
+
if (idx !== undefined && idx < absoluteLastBoundaryIdx && !preservedUuids.has(uuid)) {
|
|
1110
|
+
toDelete.push(uuid);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
for (const uuid of toDelete)
|
|
1114
|
+
messages.delete(uuid);
|
|
1115
|
+
}
|
|
1116
|
+
function applySnipRemovals(messages) {
|
|
1117
|
+
const toDelete = new Set;
|
|
1118
|
+
for (const entry of messages.values()) {
|
|
1119
|
+
const removedUuids = entry.snipMetadata?.removedUuids;
|
|
1120
|
+
if (!removedUuids)
|
|
1121
|
+
continue;
|
|
1122
|
+
for (const uuid of removedUuids)
|
|
1123
|
+
toDelete.add(uuid);
|
|
1124
|
+
}
|
|
1125
|
+
if (toDelete.size === 0)
|
|
1126
|
+
return;
|
|
1127
|
+
const deletedParent = new Map;
|
|
1128
|
+
let removedCount = 0;
|
|
1129
|
+
for (const uuid of toDelete) {
|
|
1130
|
+
const entry = messages.get(uuid);
|
|
1131
|
+
if (!entry)
|
|
1132
|
+
continue;
|
|
1133
|
+
deletedParent.set(uuid, entry.parentUuid);
|
|
1134
|
+
messages.delete(uuid);
|
|
1135
|
+
removedCount++;
|
|
1136
|
+
}
|
|
1137
|
+
const resolve = (start) => {
|
|
1138
|
+
const path = [];
|
|
1139
|
+
let cur = start;
|
|
1140
|
+
while (cur && toDelete.has(cur)) {
|
|
1141
|
+
path.push(cur);
|
|
1142
|
+
cur = deletedParent.get(cur);
|
|
1143
|
+
if (cur === undefined) {
|
|
1144
|
+
cur = null;
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
for (const p of path)
|
|
1149
|
+
deletedParent.set(p, cur);
|
|
1150
|
+
return cur;
|
|
1151
|
+
};
|
|
1152
|
+
let relinkedCount = 0;
|
|
1153
|
+
for (const [uuid, msg] of messages) {
|
|
1154
|
+
if (!msg.parentUuid || !toDelete.has(msg.parentUuid))
|
|
1155
|
+
continue;
|
|
1156
|
+
messages.set(uuid, { ...msg, parentUuid: resolve(msg.parentUuid) });
|
|
1157
|
+
relinkedCount++;
|
|
1158
|
+
}
|
|
1159
|
+
logEvent("tengu_snip_resume_filtered", {
|
|
1160
|
+
removed_count: removedCount,
|
|
1161
|
+
relinked_count: relinkedCount
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
function findLatestMessage(messages, predicate) {
|
|
1165
|
+
let latest;
|
|
1166
|
+
let maxTime = -1 / 0;
|
|
1167
|
+
for (const m of messages) {
|
|
1168
|
+
if (!predicate(m))
|
|
1169
|
+
continue;
|
|
1170
|
+
const t = Date.parse(m.timestamp);
|
|
1171
|
+
if (t > maxTime) {
|
|
1172
|
+
maxTime = t;
|
|
1173
|
+
latest = m;
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
return latest;
|
|
1177
|
+
}
|
|
1178
|
+
export function buildConversationChain(messages, leafMessage) {
|
|
1179
|
+
const transcript = [];
|
|
1180
|
+
const seen = new Set;
|
|
1181
|
+
let currentMsg = leafMessage;
|
|
1182
|
+
while (currentMsg) {
|
|
1183
|
+
if (seen.has(currentMsg.uuid)) {
|
|
1184
|
+
logError(new Error(`Cycle detected in parentUuid chain at message ${currentMsg.uuid}. Returning partial transcript.`));
|
|
1185
|
+
logEvent("tengu_chain_parent_cycle", {});
|
|
1186
|
+
break;
|
|
1187
|
+
}
|
|
1188
|
+
seen.add(currentMsg.uuid);
|
|
1189
|
+
transcript.push(currentMsg);
|
|
1190
|
+
currentMsg = currentMsg.parentUuid ? messages.get(currentMsg.parentUuid) : undefined;
|
|
1191
|
+
}
|
|
1192
|
+
transcript.reverse();
|
|
1193
|
+
return recoverOrphanedParallelToolResults(messages, transcript, seen);
|
|
1194
|
+
}
|
|
1195
|
+
function recoverOrphanedParallelToolResults(messages, chain, seen) {
|
|
1196
|
+
const chainAssistants = chain.filter((m) => m.type === "assistant");
|
|
1197
|
+
if (chainAssistants.length === 0)
|
|
1198
|
+
return chain;
|
|
1199
|
+
const anchorByMsgId = new Map;
|
|
1200
|
+
for (const a of chainAssistants) {
|
|
1201
|
+
if (a.message.id)
|
|
1202
|
+
anchorByMsgId.set(a.message.id, a);
|
|
1203
|
+
}
|
|
1204
|
+
const siblingsByMsgId = new Map;
|
|
1205
|
+
const toolResultsByAsst = new Map;
|
|
1206
|
+
for (const m of messages.values()) {
|
|
1207
|
+
if (m.type === "assistant" && m.message.id) {
|
|
1208
|
+
const group = siblingsByMsgId.get(m.message.id);
|
|
1209
|
+
if (group)
|
|
1210
|
+
group.push(m);
|
|
1211
|
+
else
|
|
1212
|
+
siblingsByMsgId.set(m.message.id, [m]);
|
|
1213
|
+
} else if (m.type === "user" && m.parentUuid && Array.isArray(m.message.content) && m.message.content.some((b) => b.type === "tool_result")) {
|
|
1214
|
+
const group = toolResultsByAsst.get(m.parentUuid);
|
|
1215
|
+
if (group)
|
|
1216
|
+
group.push(m);
|
|
1217
|
+
else
|
|
1218
|
+
toolResultsByAsst.set(m.parentUuid, [m]);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
const processedGroups = new Set;
|
|
1222
|
+
const inserts = new Map;
|
|
1223
|
+
let recoveredCount = 0;
|
|
1224
|
+
for (const asst of chainAssistants) {
|
|
1225
|
+
const msgId = asst.message.id;
|
|
1226
|
+
if (!msgId || processedGroups.has(msgId))
|
|
1227
|
+
continue;
|
|
1228
|
+
processedGroups.add(msgId);
|
|
1229
|
+
const group = siblingsByMsgId.get(msgId) ?? [asst];
|
|
1230
|
+
const orphanedSiblings = group.filter((s) => !seen.has(s.uuid));
|
|
1231
|
+
const orphanedTRs = [];
|
|
1232
|
+
for (const member of group) {
|
|
1233
|
+
const trs = toolResultsByAsst.get(member.uuid);
|
|
1234
|
+
if (!trs)
|
|
1235
|
+
continue;
|
|
1236
|
+
for (const tr of trs) {
|
|
1237
|
+
if (!seen.has(tr.uuid))
|
|
1238
|
+
orphanedTRs.push(tr);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
if (orphanedSiblings.length === 0 && orphanedTRs.length === 0)
|
|
1242
|
+
continue;
|
|
1243
|
+
orphanedSiblings.sort((a, b) => a.timestamp.localeCompare(b.timestamp));
|
|
1244
|
+
orphanedTRs.sort((a, b) => a.timestamp.localeCompare(b.timestamp));
|
|
1245
|
+
const anchor = anchorByMsgId.get(msgId);
|
|
1246
|
+
const recovered = [...orphanedSiblings, ...orphanedTRs];
|
|
1247
|
+
for (const r of recovered)
|
|
1248
|
+
seen.add(r.uuid);
|
|
1249
|
+
recoveredCount += recovered.length;
|
|
1250
|
+
inserts.set(anchor.uuid, recovered);
|
|
1251
|
+
}
|
|
1252
|
+
if (recoveredCount === 0)
|
|
1253
|
+
return chain;
|
|
1254
|
+
logEvent("tengu_chain_parallel_tr_recovered", {
|
|
1255
|
+
recovered_count: recoveredCount
|
|
1256
|
+
});
|
|
1257
|
+
const result = [];
|
|
1258
|
+
for (const m of chain) {
|
|
1259
|
+
result.push(m);
|
|
1260
|
+
const toInsert = inserts.get(m.uuid);
|
|
1261
|
+
if (toInsert)
|
|
1262
|
+
result.push(...toInsert);
|
|
1263
|
+
}
|
|
1264
|
+
return result;
|
|
1265
|
+
}
|
|
1266
|
+
export function checkResumeConsistency(chain) {
|
|
1267
|
+
for (let i = chain.length - 1;i >= 0; i--) {
|
|
1268
|
+
const m = chain[i];
|
|
1269
|
+
if (m.type !== "system" || m.subtype !== "turn_duration")
|
|
1270
|
+
continue;
|
|
1271
|
+
const expected = m.messageCount;
|
|
1272
|
+
if (expected === undefined)
|
|
1273
|
+
return;
|
|
1274
|
+
const actual = i;
|
|
1275
|
+
logEvent("tengu_resume_consistency_delta", {
|
|
1276
|
+
expected,
|
|
1277
|
+
actual,
|
|
1278
|
+
delta: actual - expected,
|
|
1279
|
+
chain_length: chain.length,
|
|
1280
|
+
checkpoint_age_entries: chain.length - 1 - i
|
|
1281
|
+
});
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
function buildFileHistorySnapshotChain(fileHistorySnapshots, conversation) {
|
|
1286
|
+
const snapshots = [];
|
|
1287
|
+
const indexByMessageId = new Map;
|
|
1288
|
+
for (const message of conversation) {
|
|
1289
|
+
const snapshotMessage = fileHistorySnapshots.get(message.uuid);
|
|
1290
|
+
if (!snapshotMessage) {
|
|
1291
|
+
continue;
|
|
1292
|
+
}
|
|
1293
|
+
const { snapshot, isSnapshotUpdate } = snapshotMessage;
|
|
1294
|
+
const existingIndex = isSnapshotUpdate ? indexByMessageId.get(snapshot.messageId) : undefined;
|
|
1295
|
+
if (existingIndex === undefined) {
|
|
1296
|
+
indexByMessageId.set(snapshot.messageId, snapshots.length);
|
|
1297
|
+
snapshots.push(snapshot);
|
|
1298
|
+
} else {
|
|
1299
|
+
snapshots[existingIndex] = snapshot;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
return snapshots;
|
|
1303
|
+
}
|
|
1304
|
+
function buildAttributionSnapshotChain(attributionSnapshots, _conversation) {
|
|
1305
|
+
return Array.from(attributionSnapshots.values());
|
|
1306
|
+
}
|
|
1307
|
+
export async function loadTranscriptFromFile(filePath) {
|
|
1308
|
+
if (filePath.endsWith(".jsonl")) {
|
|
1309
|
+
const {
|
|
1310
|
+
messages,
|
|
1311
|
+
summaries,
|
|
1312
|
+
customTitles,
|
|
1313
|
+
tags,
|
|
1314
|
+
fileHistorySnapshots,
|
|
1315
|
+
attributionSnapshots,
|
|
1316
|
+
contextCollapseCommits,
|
|
1317
|
+
contextCollapseSnapshot,
|
|
1318
|
+
leafUuids,
|
|
1319
|
+
contentReplacements,
|
|
1320
|
+
worktreeStates
|
|
1321
|
+
} = await loadTranscriptFile(filePath);
|
|
1322
|
+
if (messages.size === 0) {
|
|
1323
|
+
throw new Error("No messages found in JSONL file");
|
|
1324
|
+
}
|
|
1325
|
+
const leafMessage = findLatestMessage(messages.values(), (msg) => leafUuids.has(msg.uuid));
|
|
1326
|
+
if (!leafMessage) {
|
|
1327
|
+
throw new Error("No valid conversation chain found in JSONL file");
|
|
1328
|
+
}
|
|
1329
|
+
const transcript = buildConversationChain(messages, leafMessage);
|
|
1330
|
+
const summary = summaries.get(leafMessage.uuid);
|
|
1331
|
+
const customTitle = customTitles.get(leafMessage.sessionId);
|
|
1332
|
+
const tag = tags.get(leafMessage.sessionId);
|
|
1333
|
+
const sessionId = leafMessage.sessionId;
|
|
1334
|
+
return {
|
|
1335
|
+
...convertToLogOption(transcript, 0, summary, customTitle, buildFileHistorySnapshotChain(fileHistorySnapshots, transcript), tag, filePath, buildAttributionSnapshotChain(attributionSnapshots, transcript), undefined, contentReplacements.get(sessionId) ?? []),
|
|
1336
|
+
contextCollapseCommits: contextCollapseCommits.filter((e) => e.sessionId === sessionId),
|
|
1337
|
+
contextCollapseSnapshot: contextCollapseSnapshot?.sessionId === sessionId ? contextCollapseSnapshot : undefined,
|
|
1338
|
+
worktreeSession: worktreeStates.has(sessionId) ? worktreeStates.get(sessionId) : undefined
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
const content = await readFile(filePath, { encoding: "utf-8" });
|
|
1342
|
+
let parsed;
|
|
1343
|
+
try {
|
|
1344
|
+
parsed = jsonParse(content);
|
|
1345
|
+
} catch (error) {
|
|
1346
|
+
throw new Error(`Invalid JSON in transcript file: ${error}`);
|
|
1347
|
+
}
|
|
1348
|
+
let messages;
|
|
1349
|
+
if (Array.isArray(parsed)) {
|
|
1350
|
+
messages = parsed;
|
|
1351
|
+
} else if (parsed && typeof parsed === "object" && "messages" in parsed) {
|
|
1352
|
+
if (!Array.isArray(parsed.messages)) {
|
|
1353
|
+
throw new Error("Transcript messages must be an array");
|
|
1354
|
+
}
|
|
1355
|
+
messages = parsed.messages;
|
|
1356
|
+
} else {
|
|
1357
|
+
throw new Error("Transcript must be an array of messages or an object with a messages array");
|
|
1358
|
+
}
|
|
1359
|
+
return convertToLogOption(messages, 0, undefined, undefined, undefined, undefined, filePath);
|
|
1360
|
+
}
|
|
1361
|
+
function hasVisibleUserContent(message) {
|
|
1362
|
+
if (message.type !== "user")
|
|
1363
|
+
return false;
|
|
1364
|
+
if (message.isMeta)
|
|
1365
|
+
return false;
|
|
1366
|
+
const content = message.message?.content;
|
|
1367
|
+
if (!content)
|
|
1368
|
+
return false;
|
|
1369
|
+
if (typeof content === "string") {
|
|
1370
|
+
return content.trim().length > 0;
|
|
1371
|
+
}
|
|
1372
|
+
if (Array.isArray(content)) {
|
|
1373
|
+
return content.some((block) => block.type === "text" || block.type === "image" || block.type === "document");
|
|
1374
|
+
}
|
|
1375
|
+
return false;
|
|
1376
|
+
}
|
|
1377
|
+
function hasVisibleAssistantContent(message) {
|
|
1378
|
+
if (message.type !== "assistant")
|
|
1379
|
+
return false;
|
|
1380
|
+
const content = message.message?.content;
|
|
1381
|
+
if (!content || !Array.isArray(content))
|
|
1382
|
+
return false;
|
|
1383
|
+
return content.some((block) => block.type === "text" && typeof block.text === "string" && block.text.trim().length > 0);
|
|
1384
|
+
}
|
|
1385
|
+
function countVisibleMessages(transcript) {
|
|
1386
|
+
let count = 0;
|
|
1387
|
+
for (const message of transcript) {
|
|
1388
|
+
switch (message.type) {
|
|
1389
|
+
case "user":
|
|
1390
|
+
if (hasVisibleUserContent(message)) {
|
|
1391
|
+
count++;
|
|
1392
|
+
}
|
|
1393
|
+
break;
|
|
1394
|
+
case "assistant":
|
|
1395
|
+
if (hasVisibleAssistantContent(message)) {
|
|
1396
|
+
count++;
|
|
1397
|
+
}
|
|
1398
|
+
break;
|
|
1399
|
+
case "attachment":
|
|
1400
|
+
case "system":
|
|
1401
|
+
case "progress":
|
|
1402
|
+
break;
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
return count;
|
|
1406
|
+
}
|
|
1407
|
+
function convertToLogOption(transcript, value = 0, summary, customTitle, fileHistorySnapshots, tag, fullPath, attributionSnapshots, agentSetting, contentReplacements) {
|
|
1408
|
+
const lastMessage = transcript.at(-1);
|
|
1409
|
+
const firstMessage = transcript[0];
|
|
1410
|
+
const firstPrompt = extractFirstPrompt(transcript);
|
|
1411
|
+
const created = new Date(firstMessage.timestamp);
|
|
1412
|
+
const modified = new Date(lastMessage.timestamp);
|
|
1413
|
+
return {
|
|
1414
|
+
date: lastMessage.timestamp,
|
|
1415
|
+
messages: removeExtraFields(transcript),
|
|
1416
|
+
fullPath,
|
|
1417
|
+
value,
|
|
1418
|
+
created,
|
|
1419
|
+
modified,
|
|
1420
|
+
firstPrompt,
|
|
1421
|
+
messageCount: countVisibleMessages(transcript),
|
|
1422
|
+
isSidechain: firstMessage.isSidechain,
|
|
1423
|
+
teamName: firstMessage.teamName,
|
|
1424
|
+
agentName: firstMessage.agentName,
|
|
1425
|
+
agentSetting,
|
|
1426
|
+
leafUuid: lastMessage.uuid,
|
|
1427
|
+
summary,
|
|
1428
|
+
customTitle,
|
|
1429
|
+
tag,
|
|
1430
|
+
fileHistorySnapshots,
|
|
1431
|
+
attributionSnapshots,
|
|
1432
|
+
contentReplacements,
|
|
1433
|
+
gitBranch: lastMessage.gitBranch,
|
|
1434
|
+
projectPath: firstMessage.cwd
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
async function trackSessionBranchingAnalytics(logs) {
|
|
1438
|
+
const sessionIdCounts = new Map;
|
|
1439
|
+
let maxCount = 0;
|
|
1440
|
+
for (const log of logs) {
|
|
1441
|
+
const sessionId = getSessionIdFromLog(log);
|
|
1442
|
+
if (sessionId) {
|
|
1443
|
+
const newCount = (sessionIdCounts.get(sessionId) || 0) + 1;
|
|
1444
|
+
sessionIdCounts.set(sessionId, newCount);
|
|
1445
|
+
maxCount = Math.max(newCount, maxCount);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
if (maxCount <= 1) {
|
|
1449
|
+
return;
|
|
1450
|
+
}
|
|
1451
|
+
const branchCounts = Array.from(sessionIdCounts.values()).filter((c) => c > 1);
|
|
1452
|
+
const sessionsWithBranches = branchCounts.length;
|
|
1453
|
+
const totalBranches = branchCounts.reduce((sum, count) => sum + count, 0);
|
|
1454
|
+
logEvent("tengu_session_forked_branches_fetched", {
|
|
1455
|
+
total_sessions: sessionIdCounts.size,
|
|
1456
|
+
sessions_with_branches: sessionsWithBranches,
|
|
1457
|
+
max_branches_per_session: Math.max(...branchCounts),
|
|
1458
|
+
avg_branches_per_session: Math.round(totalBranches / sessionsWithBranches),
|
|
1459
|
+
total_transcript_count: logs.length
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
export async function fetchLogs(limit) {
|
|
1463
|
+
const projectDir = getProjectDir(getOriginalCwd());
|
|
1464
|
+
const logs = await getSessionFilesLite(projectDir, limit, getOriginalCwd());
|
|
1465
|
+
await trackSessionBranchingAnalytics(logs);
|
|
1466
|
+
return logs;
|
|
1467
|
+
}
|
|
1468
|
+
function appendEntryToFile(fullPath, entry) {
|
|
1469
|
+
const fs = getFsImplementation();
|
|
1470
|
+
const line = jsonStringify(entry) + `
|
|
1471
|
+
`;
|
|
1472
|
+
try {
|
|
1473
|
+
fs.appendFileSync(fullPath, line, { mode: 384 });
|
|
1474
|
+
} catch {
|
|
1475
|
+
fs.mkdirSync(dirname(fullPath), { mode: 448 });
|
|
1476
|
+
fs.appendFileSync(fullPath, line, { mode: 384 });
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
function readFileTailSync(fullPath) {
|
|
1480
|
+
let fd;
|
|
1481
|
+
try {
|
|
1482
|
+
fd = openSync(fullPath, "r");
|
|
1483
|
+
const st = fstatSync(fd);
|
|
1484
|
+
const tailOffset = Math.max(0, st.size - LITE_READ_BUF_SIZE);
|
|
1485
|
+
const buf = Buffer.allocUnsafe(Math.min(LITE_READ_BUF_SIZE, st.size - tailOffset));
|
|
1486
|
+
const bytesRead = readSync(fd, buf, 0, buf.length, tailOffset);
|
|
1487
|
+
return buf.toString("utf8", 0, bytesRead);
|
|
1488
|
+
} catch {
|
|
1489
|
+
return "";
|
|
1490
|
+
} finally {
|
|
1491
|
+
if (fd !== undefined) {
|
|
1492
|
+
try {
|
|
1493
|
+
closeSync(fd);
|
|
1494
|
+
} catch {}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
export async function saveCustomTitle(sessionId, customTitle, fullPath, source = "user") {
|
|
1499
|
+
const resolvedPath = fullPath ?? getTranscriptPathForSession(sessionId);
|
|
1500
|
+
appendEntryToFile(resolvedPath, {
|
|
1501
|
+
type: "custom-title",
|
|
1502
|
+
customTitle,
|
|
1503
|
+
sessionId
|
|
1504
|
+
});
|
|
1505
|
+
if (sessionId === getSessionId()) {
|
|
1506
|
+
getProject().currentSessionTitle = customTitle;
|
|
1507
|
+
}
|
|
1508
|
+
logEvent("tengu_session_renamed", {
|
|
1509
|
+
source
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
export function saveAiGeneratedTitle(sessionId, aiTitle) {
|
|
1513
|
+
appendEntryToFile(getTranscriptPathForSession(sessionId), {
|
|
1514
|
+
type: "ai-title",
|
|
1515
|
+
aiTitle,
|
|
1516
|
+
sessionId
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
export function saveTaskSummary(sessionId, summary) {
|
|
1520
|
+
appendEntryToFile(getTranscriptPathForSession(sessionId), {
|
|
1521
|
+
type: "task-summary",
|
|
1522
|
+
summary,
|
|
1523
|
+
sessionId,
|
|
1524
|
+
timestamp: new Date().toISOString()
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
export async function saveTag(sessionId, tag, fullPath) {
|
|
1528
|
+
const resolvedPath = fullPath ?? getTranscriptPathForSession(sessionId);
|
|
1529
|
+
appendEntryToFile(resolvedPath, { type: "tag", tag, sessionId });
|
|
1530
|
+
if (sessionId === getSessionId()) {
|
|
1531
|
+
getProject().currentSessionTag = tag;
|
|
1532
|
+
}
|
|
1533
|
+
logEvent("tengu_session_tagged", {});
|
|
1534
|
+
}
|
|
1535
|
+
export async function linkSessionToPR(sessionId, prNumber, prUrl, prRepository, fullPath) {
|
|
1536
|
+
const resolvedPath = fullPath ?? getTranscriptPathForSession(sessionId);
|
|
1537
|
+
appendEntryToFile(resolvedPath, {
|
|
1538
|
+
type: "pr-link",
|
|
1539
|
+
sessionId,
|
|
1540
|
+
prNumber,
|
|
1541
|
+
prUrl,
|
|
1542
|
+
prRepository,
|
|
1543
|
+
timestamp: new Date().toISOString()
|
|
1544
|
+
});
|
|
1545
|
+
if (sessionId === getSessionId()) {
|
|
1546
|
+
const project = getProject();
|
|
1547
|
+
project.currentSessionPrNumber = prNumber;
|
|
1548
|
+
project.currentSessionPrUrl = prUrl;
|
|
1549
|
+
project.currentSessionPrRepository = prRepository;
|
|
1550
|
+
}
|
|
1551
|
+
logEvent("tengu_session_linked_to_pr", { prNumber });
|
|
1552
|
+
}
|
|
1553
|
+
export function getCurrentSessionTag(sessionId) {
|
|
1554
|
+
if (sessionId === getSessionId()) {
|
|
1555
|
+
return getProject().currentSessionTag;
|
|
1556
|
+
}
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
export function getCurrentSessionTitle(sessionId) {
|
|
1560
|
+
if (sessionId === getSessionId()) {
|
|
1561
|
+
return getProject().currentSessionTitle;
|
|
1562
|
+
}
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
export function getCurrentSessionAgentColor() {
|
|
1566
|
+
return getProject().currentSessionAgentColor;
|
|
1567
|
+
}
|
|
1568
|
+
export function restoreSessionMetadata(meta) {
|
|
1569
|
+
const project = getProject();
|
|
1570
|
+
if (meta.customTitle)
|
|
1571
|
+
project.currentSessionTitle ??= meta.customTitle;
|
|
1572
|
+
if (meta.tag !== undefined)
|
|
1573
|
+
project.currentSessionTag = meta.tag || undefined;
|
|
1574
|
+
if (meta.agentName)
|
|
1575
|
+
project.currentSessionAgentName = meta.agentName;
|
|
1576
|
+
if (meta.agentColor)
|
|
1577
|
+
project.currentSessionAgentColor = meta.agentColor;
|
|
1578
|
+
if (meta.agentSetting)
|
|
1579
|
+
project.currentSessionAgentSetting = meta.agentSetting;
|
|
1580
|
+
if (meta.mode)
|
|
1581
|
+
project.currentSessionMode = meta.mode;
|
|
1582
|
+
if (meta.worktreeSession !== undefined)
|
|
1583
|
+
project.currentSessionWorktree = meta.worktreeSession;
|
|
1584
|
+
if (meta.prNumber !== undefined)
|
|
1585
|
+
project.currentSessionPrNumber = meta.prNumber;
|
|
1586
|
+
if (meta.prUrl)
|
|
1587
|
+
project.currentSessionPrUrl = meta.prUrl;
|
|
1588
|
+
if (meta.prRepository)
|
|
1589
|
+
project.currentSessionPrRepository = meta.prRepository;
|
|
1590
|
+
}
|
|
1591
|
+
export function clearSessionMetadata() {
|
|
1592
|
+
const project = getProject();
|
|
1593
|
+
project.currentSessionTitle = undefined;
|
|
1594
|
+
project.currentSessionTag = undefined;
|
|
1595
|
+
project.currentSessionAgentName = undefined;
|
|
1596
|
+
project.currentSessionAgentColor = undefined;
|
|
1597
|
+
project.currentSessionLastPrompt = undefined;
|
|
1598
|
+
project.currentSessionAgentSetting = undefined;
|
|
1599
|
+
project.currentSessionMode = undefined;
|
|
1600
|
+
project.currentSessionWorktree = undefined;
|
|
1601
|
+
project.currentSessionPrNumber = undefined;
|
|
1602
|
+
project.currentSessionPrUrl = undefined;
|
|
1603
|
+
project.currentSessionPrRepository = undefined;
|
|
1604
|
+
}
|
|
1605
|
+
export function reAppendSessionMetadata() {
|
|
1606
|
+
getProject().reAppendSessionMetadata();
|
|
1607
|
+
}
|
|
1608
|
+
export async function saveAgentName(sessionId, agentName, fullPath, source = "user") {
|
|
1609
|
+
const resolvedPath = fullPath ?? getTranscriptPathForSession(sessionId);
|
|
1610
|
+
appendEntryToFile(resolvedPath, { type: "agent-name", agentName, sessionId });
|
|
1611
|
+
if (sessionId === getSessionId()) {
|
|
1612
|
+
getProject().currentSessionAgentName = agentName;
|
|
1613
|
+
updateSessionName(agentName);
|
|
1614
|
+
}
|
|
1615
|
+
logEvent("tengu_agent_name_set", {
|
|
1616
|
+
source
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
export async function saveAgentColor(sessionId, agentColor, fullPath) {
|
|
1620
|
+
const resolvedPath = fullPath ?? getTranscriptPathForSession(sessionId);
|
|
1621
|
+
appendEntryToFile(resolvedPath, {
|
|
1622
|
+
type: "agent-color",
|
|
1623
|
+
agentColor,
|
|
1624
|
+
sessionId
|
|
1625
|
+
});
|
|
1626
|
+
if (sessionId === getSessionId()) {
|
|
1627
|
+
getProject().currentSessionAgentColor = agentColor;
|
|
1628
|
+
}
|
|
1629
|
+
logEvent("tengu_agent_color_set", {});
|
|
1630
|
+
}
|
|
1631
|
+
export function saveAgentSetting(agentSetting) {
|
|
1632
|
+
getProject().currentSessionAgentSetting = agentSetting;
|
|
1633
|
+
}
|
|
1634
|
+
export function cacheSessionTitle(customTitle) {
|
|
1635
|
+
getProject().currentSessionTitle = customTitle;
|
|
1636
|
+
}
|
|
1637
|
+
export function saveMode(mode) {
|
|
1638
|
+
getProject().currentSessionMode = mode;
|
|
1639
|
+
}
|
|
1640
|
+
export function saveWorktreeState(worktreeSession) {
|
|
1641
|
+
const stripped = worktreeSession ? {
|
|
1642
|
+
originalCwd: worktreeSession.originalCwd,
|
|
1643
|
+
worktreePath: worktreeSession.worktreePath,
|
|
1644
|
+
worktreeName: worktreeSession.worktreeName,
|
|
1645
|
+
worktreeBranch: worktreeSession.worktreeBranch,
|
|
1646
|
+
originalBranch: worktreeSession.originalBranch,
|
|
1647
|
+
originalHeadCommit: worktreeSession.originalHeadCommit,
|
|
1648
|
+
sessionId: worktreeSession.sessionId,
|
|
1649
|
+
tmuxSessionName: worktreeSession.tmuxSessionName,
|
|
1650
|
+
hookBased: worktreeSession.hookBased
|
|
1651
|
+
} : null;
|
|
1652
|
+
const project = getProject();
|
|
1653
|
+
project.currentSessionWorktree = stripped;
|
|
1654
|
+
if (project.sessionFile) {
|
|
1655
|
+
appendEntryToFile(project.sessionFile, {
|
|
1656
|
+
type: "worktree-state",
|
|
1657
|
+
worktreeSession: stripped,
|
|
1658
|
+
sessionId: getSessionId()
|
|
1659
|
+
});
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
export function getSessionIdFromLog(log) {
|
|
1663
|
+
if (log.sessionId) {
|
|
1664
|
+
return log.sessionId;
|
|
1665
|
+
}
|
|
1666
|
+
return log.messages[0]?.sessionId;
|
|
1667
|
+
}
|
|
1668
|
+
export function isLiteLog(log) {
|
|
1669
|
+
return log.messages.length === 0 && log.sessionId !== undefined;
|
|
1670
|
+
}
|
|
1671
|
+
export async function loadFullLog(log) {
|
|
1672
|
+
if (!isLiteLog(log)) {
|
|
1673
|
+
return log;
|
|
1674
|
+
}
|
|
1675
|
+
const sessionFile = log.fullPath;
|
|
1676
|
+
if (!sessionFile) {
|
|
1677
|
+
return log;
|
|
1678
|
+
}
|
|
1679
|
+
try {
|
|
1680
|
+
const {
|
|
1681
|
+
messages,
|
|
1682
|
+
summaries,
|
|
1683
|
+
customTitles,
|
|
1684
|
+
tags,
|
|
1685
|
+
agentNames,
|
|
1686
|
+
agentColors,
|
|
1687
|
+
agentSettings,
|
|
1688
|
+
prNumbers,
|
|
1689
|
+
prUrls,
|
|
1690
|
+
prRepositories,
|
|
1691
|
+
modes,
|
|
1692
|
+
worktreeStates,
|
|
1693
|
+
fileHistorySnapshots,
|
|
1694
|
+
attributionSnapshots,
|
|
1695
|
+
contentReplacements,
|
|
1696
|
+
contextCollapseCommits,
|
|
1697
|
+
contextCollapseSnapshot,
|
|
1698
|
+
leafUuids
|
|
1699
|
+
} = await loadTranscriptFile(sessionFile);
|
|
1700
|
+
if (messages.size === 0) {
|
|
1701
|
+
return log;
|
|
1702
|
+
}
|
|
1703
|
+
const mostRecentLeaf = findLatestMessage(messages.values(), (msg) => leafUuids.has(msg.uuid) && (msg.type === "user" || msg.type === "assistant"));
|
|
1704
|
+
if (!mostRecentLeaf) {
|
|
1705
|
+
return log;
|
|
1706
|
+
}
|
|
1707
|
+
const transcript = buildConversationChain(messages, mostRecentLeaf);
|
|
1708
|
+
const sessionId = mostRecentLeaf.sessionId;
|
|
1709
|
+
return {
|
|
1710
|
+
...log,
|
|
1711
|
+
messages: removeExtraFields(transcript),
|
|
1712
|
+
firstPrompt: extractFirstPrompt(transcript),
|
|
1713
|
+
messageCount: countVisibleMessages(transcript),
|
|
1714
|
+
summary: mostRecentLeaf ? summaries.get(mostRecentLeaf.uuid) : log.summary,
|
|
1715
|
+
customTitle: sessionId ? customTitles.get(sessionId) : log.customTitle,
|
|
1716
|
+
tag: sessionId ? tags.get(sessionId) : log.tag,
|
|
1717
|
+
agentName: sessionId ? agentNames.get(sessionId) : log.agentName,
|
|
1718
|
+
agentColor: sessionId ? agentColors.get(sessionId) : log.agentColor,
|
|
1719
|
+
agentSetting: sessionId ? agentSettings.get(sessionId) : log.agentSetting,
|
|
1720
|
+
mode: sessionId ? modes.get(sessionId) : log.mode,
|
|
1721
|
+
worktreeSession: sessionId && worktreeStates.has(sessionId) ? worktreeStates.get(sessionId) : log.worktreeSession,
|
|
1722
|
+
prNumber: sessionId ? prNumbers.get(sessionId) : log.prNumber,
|
|
1723
|
+
prUrl: sessionId ? prUrls.get(sessionId) : log.prUrl,
|
|
1724
|
+
prRepository: sessionId ? prRepositories.get(sessionId) : log.prRepository,
|
|
1725
|
+
gitBranch: mostRecentLeaf?.gitBranch ?? log.gitBranch,
|
|
1726
|
+
isSidechain: transcript[0]?.isSidechain ?? log.isSidechain,
|
|
1727
|
+
teamName: transcript[0]?.teamName ?? log.teamName,
|
|
1728
|
+
leafUuid: mostRecentLeaf?.uuid ?? log.leafUuid,
|
|
1729
|
+
fileHistorySnapshots: buildFileHistorySnapshotChain(fileHistorySnapshots, transcript),
|
|
1730
|
+
attributionSnapshots: buildAttributionSnapshotChain(attributionSnapshots, transcript),
|
|
1731
|
+
contentReplacements: sessionId ? contentReplacements.get(sessionId) ?? [] : log.contentReplacements,
|
|
1732
|
+
contextCollapseCommits: sessionId ? contextCollapseCommits.filter((e) => e.sessionId === sessionId) : undefined,
|
|
1733
|
+
contextCollapseSnapshot: sessionId && contextCollapseSnapshot?.sessionId === sessionId ? contextCollapseSnapshot : undefined
|
|
1734
|
+
};
|
|
1735
|
+
} catch {
|
|
1736
|
+
return log;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
export async function searchSessionsByCustomTitle(query, options) {
|
|
1740
|
+
const { limit, exact } = options || {};
|
|
1741
|
+
const worktreePaths = await getWorktreePaths(getOriginalCwd());
|
|
1742
|
+
const allStatLogs = await getStatOnlyLogsForWorktrees(worktreePaths);
|
|
1743
|
+
const { logs } = await enrichLogs(allStatLogs, 0, allStatLogs.length);
|
|
1744
|
+
const normalizedQuery = query.toLowerCase().trim();
|
|
1745
|
+
const matchingLogs = logs.filter((log) => {
|
|
1746
|
+
const title = log.customTitle?.toLowerCase().trim();
|
|
1747
|
+
if (!title)
|
|
1748
|
+
return false;
|
|
1749
|
+
return exact ? title === normalizedQuery : title.includes(normalizedQuery);
|
|
1750
|
+
});
|
|
1751
|
+
const sessionIdToLog = new Map;
|
|
1752
|
+
for (const log of matchingLogs) {
|
|
1753
|
+
const sessionId = getSessionIdFromLog(log);
|
|
1754
|
+
if (sessionId) {
|
|
1755
|
+
const existing = sessionIdToLog.get(sessionId);
|
|
1756
|
+
if (!existing || log.modified > existing.modified) {
|
|
1757
|
+
sessionIdToLog.set(sessionId, log);
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
const deduplicated = Array.from(sessionIdToLog.values());
|
|
1762
|
+
deduplicated.sort((a, b) => b.modified.getTime() - a.modified.getTime());
|
|
1763
|
+
if (limit) {
|
|
1764
|
+
return deduplicated.slice(0, limit);
|
|
1765
|
+
}
|
|
1766
|
+
return deduplicated;
|
|
1767
|
+
}
|
|
1768
|
+
const METADATA_TYPE_MARKERS = [
|
|
1769
|
+
'"type":"summary"',
|
|
1770
|
+
'"type":"custom-title"',
|
|
1771
|
+
'"type":"tag"',
|
|
1772
|
+
'"type":"agent-name"',
|
|
1773
|
+
'"type":"agent-color"',
|
|
1774
|
+
'"type":"agent-setting"',
|
|
1775
|
+
'"type":"mode"',
|
|
1776
|
+
'"type":"worktree-state"',
|
|
1777
|
+
'"type":"pr-link"'
|
|
1778
|
+
];
|
|
1779
|
+
const METADATA_MARKER_BUFS = METADATA_TYPE_MARKERS.map((m) => Buffer.from(m));
|
|
1780
|
+
const METADATA_PREFIX_BOUND = 25;
|
|
1781
|
+
function resolveMetadataBuf(carry, chunkBuf) {
|
|
1782
|
+
if (carry === null || carry.length === 0)
|
|
1783
|
+
return chunkBuf;
|
|
1784
|
+
if (carry.length < METADATA_PREFIX_BOUND) {
|
|
1785
|
+
return Buffer.concat([carry, chunkBuf]);
|
|
1786
|
+
}
|
|
1787
|
+
if (carry[0] === 123) {
|
|
1788
|
+
for (const m of METADATA_MARKER_BUFS) {
|
|
1789
|
+
if (carry.compare(m, 0, m.length, 1, 1 + m.length) === 0) {
|
|
1790
|
+
return Buffer.concat([carry, chunkBuf]);
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
const firstNl = chunkBuf.indexOf(10);
|
|
1795
|
+
return firstNl === -1 ? null : chunkBuf.subarray(firstNl + 1);
|
|
1796
|
+
}
|
|
1797
|
+
async function scanPreBoundaryMetadata(filePath, endOffset) {
|
|
1798
|
+
const { createReadStream } = await import("fs");
|
|
1799
|
+
const NEWLINE = 10;
|
|
1800
|
+
const stream = createReadStream(filePath, { end: endOffset - 1 });
|
|
1801
|
+
const metadataLines = [];
|
|
1802
|
+
let carry = null;
|
|
1803
|
+
for await (const chunk of stream) {
|
|
1804
|
+
const chunkBuf = chunk;
|
|
1805
|
+
const buf = resolveMetadataBuf(carry, chunkBuf);
|
|
1806
|
+
if (buf === null) {
|
|
1807
|
+
carry = null;
|
|
1808
|
+
continue;
|
|
1809
|
+
}
|
|
1810
|
+
let hasAnyMarker = false;
|
|
1811
|
+
for (const m of METADATA_MARKER_BUFS) {
|
|
1812
|
+
if (buf.includes(m)) {
|
|
1813
|
+
hasAnyMarker = true;
|
|
1814
|
+
break;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
if (hasAnyMarker) {
|
|
1818
|
+
let lineStart = 0;
|
|
1819
|
+
let nl = buf.indexOf(NEWLINE);
|
|
1820
|
+
while (nl !== -1) {
|
|
1821
|
+
for (const m of METADATA_MARKER_BUFS) {
|
|
1822
|
+
const mIdx = buf.indexOf(m, lineStart);
|
|
1823
|
+
if (mIdx !== -1 && mIdx < nl) {
|
|
1824
|
+
metadataLines.push(buf.toString("utf-8", lineStart, nl));
|
|
1825
|
+
break;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
lineStart = nl + 1;
|
|
1829
|
+
nl = buf.indexOf(NEWLINE, lineStart);
|
|
1830
|
+
}
|
|
1831
|
+
carry = buf.subarray(lineStart);
|
|
1832
|
+
} else {
|
|
1833
|
+
const lastNl = buf.lastIndexOf(NEWLINE);
|
|
1834
|
+
carry = lastNl >= 0 ? buf.subarray(lastNl + 1) : buf;
|
|
1835
|
+
}
|
|
1836
|
+
if (carry.length > 65536)
|
|
1837
|
+
carry = null;
|
|
1838
|
+
}
|
|
1839
|
+
if (carry !== null && carry.length > 0) {
|
|
1840
|
+
for (const m of METADATA_MARKER_BUFS) {
|
|
1841
|
+
if (carry.includes(m)) {
|
|
1842
|
+
metadataLines.push(carry.toString("utf-8"));
|
|
1843
|
+
break;
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
return metadataLines;
|
|
1848
|
+
}
|
|
1849
|
+
function pickDepthOneUuidCandidate(buf, lineStart, candidates) {
|
|
1850
|
+
const QUOTE = 34;
|
|
1851
|
+
const BACKSLASH = 92;
|
|
1852
|
+
const OPEN_BRACE = 123;
|
|
1853
|
+
const CLOSE_BRACE = 125;
|
|
1854
|
+
let depth = 0;
|
|
1855
|
+
let inString = false;
|
|
1856
|
+
let escapeNext = false;
|
|
1857
|
+
let ci = 0;
|
|
1858
|
+
for (let i = lineStart;ci < candidates.length; i++) {
|
|
1859
|
+
if (i === candidates[ci]) {
|
|
1860
|
+
if (depth === 1 && !inString)
|
|
1861
|
+
return candidates[ci];
|
|
1862
|
+
ci++;
|
|
1863
|
+
}
|
|
1864
|
+
const b = buf[i];
|
|
1865
|
+
if (escapeNext) {
|
|
1866
|
+
escapeNext = false;
|
|
1867
|
+
} else if (inString) {
|
|
1868
|
+
if (b === BACKSLASH)
|
|
1869
|
+
escapeNext = true;
|
|
1870
|
+
else if (b === QUOTE)
|
|
1871
|
+
inString = false;
|
|
1872
|
+
} else if (b === QUOTE)
|
|
1873
|
+
inString = true;
|
|
1874
|
+
else if (b === OPEN_BRACE)
|
|
1875
|
+
depth++;
|
|
1876
|
+
else if (b === CLOSE_BRACE)
|
|
1877
|
+
depth--;
|
|
1878
|
+
}
|
|
1879
|
+
return candidates.at(-1);
|
|
1880
|
+
}
|
|
1881
|
+
function walkChainBeforeParse(buf) {
|
|
1882
|
+
const NEWLINE = 10;
|
|
1883
|
+
const OPEN_BRACE = 123;
|
|
1884
|
+
const QUOTE = 34;
|
|
1885
|
+
const PARENT_PREFIX = Buffer.from('{"parentUuid":');
|
|
1886
|
+
const UUID_KEY = Buffer.from('"uuid":"');
|
|
1887
|
+
const SIDECHAIN_TRUE = Buffer.from('"isSidechain":true');
|
|
1888
|
+
const UUID_LEN = 36;
|
|
1889
|
+
const TS_SUFFIX = Buffer.from('","timestamp":"');
|
|
1890
|
+
const TS_SUFFIX_LEN = TS_SUFFIX.length;
|
|
1891
|
+
const PREFIX_LEN = PARENT_PREFIX.length;
|
|
1892
|
+
const KEY_LEN = UUID_KEY.length;
|
|
1893
|
+
const msgIdx = [];
|
|
1894
|
+
const metaRanges = [];
|
|
1895
|
+
const uuidToSlot = new Map;
|
|
1896
|
+
let pos = 0;
|
|
1897
|
+
const len = buf.length;
|
|
1898
|
+
while (pos < len) {
|
|
1899
|
+
const nl = buf.indexOf(NEWLINE, pos);
|
|
1900
|
+
const lineEnd = nl === -1 ? len : nl + 1;
|
|
1901
|
+
if (lineEnd - pos > PREFIX_LEN && buf[pos] === OPEN_BRACE && buf.compare(PARENT_PREFIX, 0, PREFIX_LEN, pos, pos + PREFIX_LEN) === 0) {
|
|
1902
|
+
const parentStart = buf[pos + PREFIX_LEN] === QUOTE ? pos + PREFIX_LEN + 1 : -1;
|
|
1903
|
+
let firstAny = -1;
|
|
1904
|
+
let suffix0 = -1;
|
|
1905
|
+
let suffixN;
|
|
1906
|
+
let from = pos;
|
|
1907
|
+
for (;; ) {
|
|
1908
|
+
const next = buf.indexOf(UUID_KEY, from);
|
|
1909
|
+
if (next < 0 || next >= lineEnd)
|
|
1910
|
+
break;
|
|
1911
|
+
if (firstAny < 0)
|
|
1912
|
+
firstAny = next;
|
|
1913
|
+
const after = next + KEY_LEN + UUID_LEN;
|
|
1914
|
+
if (after + TS_SUFFIX_LEN <= lineEnd && buf.compare(TS_SUFFIX, 0, TS_SUFFIX_LEN, after, after + TS_SUFFIX_LEN) === 0) {
|
|
1915
|
+
if (suffix0 < 0)
|
|
1916
|
+
suffix0 = next;
|
|
1917
|
+
else
|
|
1918
|
+
(suffixN ??= [suffix0]).push(next);
|
|
1919
|
+
}
|
|
1920
|
+
from = next + KEY_LEN;
|
|
1921
|
+
}
|
|
1922
|
+
const uk = suffixN ? pickDepthOneUuidCandidate(buf, pos, suffixN) : suffix0 >= 0 ? suffix0 : firstAny;
|
|
1923
|
+
if (uk >= 0) {
|
|
1924
|
+
const uuidStart = uk + KEY_LEN;
|
|
1925
|
+
const uuid = buf.toString("latin1", uuidStart, uuidStart + UUID_LEN);
|
|
1926
|
+
uuidToSlot.set(uuid, msgIdx.length);
|
|
1927
|
+
msgIdx.push(pos, lineEnd, parentStart);
|
|
1928
|
+
} else {
|
|
1929
|
+
metaRanges.push(pos, lineEnd);
|
|
1930
|
+
}
|
|
1931
|
+
} else {
|
|
1932
|
+
metaRanges.push(pos, lineEnd);
|
|
1933
|
+
}
|
|
1934
|
+
pos = lineEnd;
|
|
1935
|
+
}
|
|
1936
|
+
let leafSlot = -1;
|
|
1937
|
+
for (let i = msgIdx.length - 3;i >= 0; i -= 3) {
|
|
1938
|
+
const sc = buf.indexOf(SIDECHAIN_TRUE, msgIdx[i]);
|
|
1939
|
+
if (sc === -1 || sc >= msgIdx[i + 1]) {
|
|
1940
|
+
leafSlot = i;
|
|
1941
|
+
break;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
if (leafSlot < 0)
|
|
1945
|
+
return buf;
|
|
1946
|
+
const seen = new Set;
|
|
1947
|
+
const chain = new Set;
|
|
1948
|
+
let chainBytes = 0;
|
|
1949
|
+
let slot = leafSlot;
|
|
1950
|
+
while (slot !== undefined) {
|
|
1951
|
+
if (seen.has(slot))
|
|
1952
|
+
break;
|
|
1953
|
+
seen.add(slot);
|
|
1954
|
+
chain.add(msgIdx[slot]);
|
|
1955
|
+
chainBytes += msgIdx[slot + 1] - msgIdx[slot];
|
|
1956
|
+
const parentStart = msgIdx[slot + 2];
|
|
1957
|
+
if (parentStart < 0)
|
|
1958
|
+
break;
|
|
1959
|
+
const parent = buf.toString("latin1", parentStart, parentStart + UUID_LEN);
|
|
1960
|
+
slot = uuidToSlot.get(parent);
|
|
1961
|
+
}
|
|
1962
|
+
if (len - chainBytes < len >> 1)
|
|
1963
|
+
return buf;
|
|
1964
|
+
const parts = [];
|
|
1965
|
+
let m = 0;
|
|
1966
|
+
for (let i = 0;i < msgIdx.length; i += 3) {
|
|
1967
|
+
const start = msgIdx[i];
|
|
1968
|
+
while (m < metaRanges.length && metaRanges[m] < start) {
|
|
1969
|
+
parts.push(buf.subarray(metaRanges[m], metaRanges[m + 1]));
|
|
1970
|
+
m += 2;
|
|
1971
|
+
}
|
|
1972
|
+
if (chain.has(start)) {
|
|
1973
|
+
parts.push(buf.subarray(start, msgIdx[i + 1]));
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
while (m < metaRanges.length) {
|
|
1977
|
+
parts.push(buf.subarray(metaRanges[m], metaRanges[m + 1]));
|
|
1978
|
+
m += 2;
|
|
1979
|
+
}
|
|
1980
|
+
return Buffer.concat(parts);
|
|
1981
|
+
}
|
|
1982
|
+
export async function loadTranscriptFile(filePath, opts) {
|
|
1983
|
+
const messages = new Map;
|
|
1984
|
+
const summaries = new Map;
|
|
1985
|
+
const customTitles = new Map;
|
|
1986
|
+
const tags = new Map;
|
|
1987
|
+
const agentNames = new Map;
|
|
1988
|
+
const agentColors = new Map;
|
|
1989
|
+
const agentSettings = new Map;
|
|
1990
|
+
const prNumbers = new Map;
|
|
1991
|
+
const prUrls = new Map;
|
|
1992
|
+
const prRepositories = new Map;
|
|
1993
|
+
const modes = new Map;
|
|
1994
|
+
const worktreeStates = new Map;
|
|
1995
|
+
const fileHistorySnapshots = new Map;
|
|
1996
|
+
const attributionSnapshots = new Map;
|
|
1997
|
+
const contentReplacements = new Map;
|
|
1998
|
+
const agentContentReplacements = new Map;
|
|
1999
|
+
const contextCollapseCommits = [];
|
|
2000
|
+
let contextCollapseSnapshot;
|
|
2001
|
+
try {
|
|
2002
|
+
let buf = null;
|
|
2003
|
+
let metadataLines = null;
|
|
2004
|
+
let hasPreservedSegment = false;
|
|
2005
|
+
if (!isEnvTruthy(process.env.CLAUDE_CODE_DISABLE_PRECOMPACT_SKIP)) {
|
|
2006
|
+
const { size } = await stat(filePath);
|
|
2007
|
+
if (size > SKIP_PRECOMPACT_THRESHOLD) {
|
|
2008
|
+
const scan = await readTranscriptForLoad(filePath, size);
|
|
2009
|
+
buf = scan.postBoundaryBuf;
|
|
2010
|
+
hasPreservedSegment = scan.hasPreservedSegment;
|
|
2011
|
+
if (scan.boundaryStartOffset > 0) {
|
|
2012
|
+
metadataLines = await scanPreBoundaryMetadata(filePath, scan.boundaryStartOffset);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
buf ??= await readFile(filePath);
|
|
2017
|
+
if (!opts?.keepAllLeaves && !hasPreservedSegment && !isEnvTruthy(process.env.CLAUDE_CODE_DISABLE_PRECOMPACT_SKIP) && buf.length > SKIP_PRECOMPACT_THRESHOLD) {
|
|
2018
|
+
buf = walkChainBeforeParse(buf);
|
|
2019
|
+
}
|
|
2020
|
+
if (metadataLines && metadataLines.length > 0) {
|
|
2021
|
+
const metaEntries = parseJSONL(Buffer.from(metadataLines.join(`
|
|
2022
|
+
`)));
|
|
2023
|
+
for (const entry of metaEntries) {
|
|
2024
|
+
if (entry.type === "summary" && entry.leafUuid) {
|
|
2025
|
+
summaries.set(entry.leafUuid, entry.summary);
|
|
2026
|
+
} else if (entry.type === "custom-title" && entry.sessionId) {
|
|
2027
|
+
customTitles.set(entry.sessionId, entry.customTitle);
|
|
2028
|
+
} else if (entry.type === "tag" && entry.sessionId) {
|
|
2029
|
+
tags.set(entry.sessionId, entry.tag);
|
|
2030
|
+
} else if (entry.type === "agent-name" && entry.sessionId) {
|
|
2031
|
+
agentNames.set(entry.sessionId, entry.agentName);
|
|
2032
|
+
} else if (entry.type === "agent-color" && entry.sessionId) {
|
|
2033
|
+
agentColors.set(entry.sessionId, entry.agentColor);
|
|
2034
|
+
} else if (entry.type === "agent-setting" && entry.sessionId) {
|
|
2035
|
+
agentSettings.set(entry.sessionId, entry.agentSetting);
|
|
2036
|
+
} else if (entry.type === "mode" && entry.sessionId) {
|
|
2037
|
+
modes.set(entry.sessionId, entry.mode);
|
|
2038
|
+
} else if (entry.type === "worktree-state" && entry.sessionId) {
|
|
2039
|
+
worktreeStates.set(entry.sessionId, entry.worktreeSession);
|
|
2040
|
+
} else if (entry.type === "pr-link" && entry.sessionId) {
|
|
2041
|
+
prNumbers.set(entry.sessionId, entry.prNumber);
|
|
2042
|
+
prUrls.set(entry.sessionId, entry.prUrl);
|
|
2043
|
+
prRepositories.set(entry.sessionId, entry.prRepository);
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
const entries = parseJSONL(buf);
|
|
2048
|
+
const progressBridge = new Map;
|
|
2049
|
+
for (const entry of entries) {
|
|
2050
|
+
if (isLegacyProgressEntry(entry)) {
|
|
2051
|
+
const parent = entry.parentUuid;
|
|
2052
|
+
progressBridge.set(entry.uuid, parent && progressBridge.has(parent) ? progressBridge.get(parent) ?? null : parent);
|
|
2053
|
+
continue;
|
|
2054
|
+
}
|
|
2055
|
+
if (isTranscriptMessage(entry)) {
|
|
2056
|
+
if (entry.parentUuid && progressBridge.has(entry.parentUuid)) {
|
|
2057
|
+
entry.parentUuid = progressBridge.get(entry.parentUuid) ?? null;
|
|
2058
|
+
}
|
|
2059
|
+
messages.set(entry.uuid, entry);
|
|
2060
|
+
if (isCompactBoundaryMessage(entry)) {
|
|
2061
|
+
contextCollapseCommits.length = 0;
|
|
2062
|
+
contextCollapseSnapshot = undefined;
|
|
2063
|
+
}
|
|
2064
|
+
} else if (entry.type === "summary" && entry.leafUuid) {
|
|
2065
|
+
summaries.set(entry.leafUuid, entry.summary);
|
|
2066
|
+
} else if (entry.type === "custom-title" && entry.sessionId) {
|
|
2067
|
+
customTitles.set(entry.sessionId, entry.customTitle);
|
|
2068
|
+
} else if (entry.type === "tag" && entry.sessionId) {
|
|
2069
|
+
tags.set(entry.sessionId, entry.tag);
|
|
2070
|
+
} else if (entry.type === "agent-name" && entry.sessionId) {
|
|
2071
|
+
agentNames.set(entry.sessionId, entry.agentName);
|
|
2072
|
+
} else if (entry.type === "agent-color" && entry.sessionId) {
|
|
2073
|
+
agentColors.set(entry.sessionId, entry.agentColor);
|
|
2074
|
+
} else if (entry.type === "agent-setting" && entry.sessionId) {
|
|
2075
|
+
agentSettings.set(entry.sessionId, entry.agentSetting);
|
|
2076
|
+
} else if (entry.type === "mode" && entry.sessionId) {
|
|
2077
|
+
modes.set(entry.sessionId, entry.mode);
|
|
2078
|
+
} else if (entry.type === "worktree-state" && entry.sessionId) {
|
|
2079
|
+
worktreeStates.set(entry.sessionId, entry.worktreeSession);
|
|
2080
|
+
} else if (entry.type === "pr-link" && entry.sessionId) {
|
|
2081
|
+
prNumbers.set(entry.sessionId, entry.prNumber);
|
|
2082
|
+
prUrls.set(entry.sessionId, entry.prUrl);
|
|
2083
|
+
prRepositories.set(entry.sessionId, entry.prRepository);
|
|
2084
|
+
} else if (entry.type === "file-history-snapshot") {
|
|
2085
|
+
fileHistorySnapshots.set(entry.messageId, entry);
|
|
2086
|
+
} else if (entry.type === "attribution-snapshot") {
|
|
2087
|
+
attributionSnapshots.set(entry.messageId, entry);
|
|
2088
|
+
} else if (entry.type === "content-replacement") {
|
|
2089
|
+
if (entry.agentId) {
|
|
2090
|
+
const existing = agentContentReplacements.get(entry.agentId) ?? [];
|
|
2091
|
+
agentContentReplacements.set(entry.agentId, existing);
|
|
2092
|
+
existing.push(...entry.replacements);
|
|
2093
|
+
} else {
|
|
2094
|
+
const existing = contentReplacements.get(entry.sessionId) ?? [];
|
|
2095
|
+
contentReplacements.set(entry.sessionId, existing);
|
|
2096
|
+
existing.push(...entry.replacements);
|
|
2097
|
+
}
|
|
2098
|
+
} else if (entry.type === "marble-origami-commit") {
|
|
2099
|
+
contextCollapseCommits.push(entry);
|
|
2100
|
+
} else if (entry.type === "marble-origami-snapshot") {
|
|
2101
|
+
contextCollapseSnapshot = entry;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
} catch {}
|
|
2105
|
+
applyPreservedSegmentRelinks(messages);
|
|
2106
|
+
applySnipRemovals(messages);
|
|
2107
|
+
const allMessages = [...messages.values()];
|
|
2108
|
+
const parentUuids = new Set(allMessages.map((msg) => msg.parentUuid).filter((uuid) => uuid !== null));
|
|
2109
|
+
const terminalMessages = allMessages.filter((msg) => !parentUuids.has(msg.uuid));
|
|
2110
|
+
const leafUuids = new Set;
|
|
2111
|
+
let hasCycle = false;
|
|
2112
|
+
if (getFeatureValue_CACHED_MAY_BE_STALE("tengu_pebble_leaf_prune", false)) {
|
|
2113
|
+
const hasUserAssistantChild = new Set;
|
|
2114
|
+
for (const msg of allMessages) {
|
|
2115
|
+
if (msg.parentUuid && (msg.type === "user" || msg.type === "assistant")) {
|
|
2116
|
+
hasUserAssistantChild.add(msg.parentUuid);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
for (const terminal of terminalMessages) {
|
|
2120
|
+
const seen = new Set;
|
|
2121
|
+
let current = terminal;
|
|
2122
|
+
while (current) {
|
|
2123
|
+
if (seen.has(current.uuid)) {
|
|
2124
|
+
hasCycle = true;
|
|
2125
|
+
break;
|
|
2126
|
+
}
|
|
2127
|
+
seen.add(current.uuid);
|
|
2128
|
+
if (current.type === "user" || current.type === "assistant") {
|
|
2129
|
+
if (!hasUserAssistantChild.has(current.uuid)) {
|
|
2130
|
+
leafUuids.add(current.uuid);
|
|
2131
|
+
}
|
|
2132
|
+
break;
|
|
2133
|
+
}
|
|
2134
|
+
current = current.parentUuid ? messages.get(current.parentUuid) : undefined;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
} else {
|
|
2138
|
+
for (const terminal of terminalMessages) {
|
|
2139
|
+
const seen = new Set;
|
|
2140
|
+
let current = terminal;
|
|
2141
|
+
while (current) {
|
|
2142
|
+
if (seen.has(current.uuid)) {
|
|
2143
|
+
hasCycle = true;
|
|
2144
|
+
break;
|
|
2145
|
+
}
|
|
2146
|
+
seen.add(current.uuid);
|
|
2147
|
+
if (current.type === "user" || current.type === "assistant") {
|
|
2148
|
+
leafUuids.add(current.uuid);
|
|
2149
|
+
break;
|
|
2150
|
+
}
|
|
2151
|
+
current = current.parentUuid ? messages.get(current.parentUuid) : undefined;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
if (hasCycle) {
|
|
2156
|
+
logEvent("tengu_transcript_parent_cycle", {});
|
|
2157
|
+
}
|
|
2158
|
+
return {
|
|
2159
|
+
messages,
|
|
2160
|
+
summaries,
|
|
2161
|
+
customTitles,
|
|
2162
|
+
tags,
|
|
2163
|
+
agentNames,
|
|
2164
|
+
agentColors,
|
|
2165
|
+
agentSettings,
|
|
2166
|
+
prNumbers,
|
|
2167
|
+
prUrls,
|
|
2168
|
+
prRepositories,
|
|
2169
|
+
modes,
|
|
2170
|
+
worktreeStates,
|
|
2171
|
+
fileHistorySnapshots,
|
|
2172
|
+
attributionSnapshots,
|
|
2173
|
+
contentReplacements,
|
|
2174
|
+
agentContentReplacements,
|
|
2175
|
+
contextCollapseCommits,
|
|
2176
|
+
contextCollapseSnapshot,
|
|
2177
|
+
leafUuids
|
|
2178
|
+
};
|
|
2179
|
+
}
|
|
2180
|
+
async function loadSessionFile(sessionId) {
|
|
2181
|
+
const sessionFile = join(getSessionProjectDir() ?? getProjectDir(getOriginalCwd()), `${sessionId}.jsonl`);
|
|
2182
|
+
return loadTranscriptFile(sessionFile);
|
|
2183
|
+
}
|
|
2184
|
+
const getSessionMessages = memoize(async (sessionId) => {
|
|
2185
|
+
const { messages } = await loadSessionFile(sessionId);
|
|
2186
|
+
return new Set(messages.keys());
|
|
2187
|
+
}, (sessionId) => sessionId);
|
|
2188
|
+
export function clearSessionMessagesCache() {
|
|
2189
|
+
getSessionMessages.cache.clear?.();
|
|
2190
|
+
}
|
|
2191
|
+
export async function doesMessageExistInSession(sessionId, messageUuid) {
|
|
2192
|
+
const messageSet = await getSessionMessages(sessionId);
|
|
2193
|
+
return messageSet.has(messageUuid);
|
|
2194
|
+
}
|
|
2195
|
+
export async function getLastSessionLog(sessionId) {
|
|
2196
|
+
const {
|
|
2197
|
+
messages,
|
|
2198
|
+
summaries,
|
|
2199
|
+
customTitles,
|
|
2200
|
+
tags,
|
|
2201
|
+
agentSettings,
|
|
2202
|
+
worktreeStates,
|
|
2203
|
+
fileHistorySnapshots,
|
|
2204
|
+
attributionSnapshots,
|
|
2205
|
+
contentReplacements,
|
|
2206
|
+
contextCollapseCommits,
|
|
2207
|
+
contextCollapseSnapshot
|
|
2208
|
+
} = await loadSessionFile(sessionId);
|
|
2209
|
+
if (messages.size === 0)
|
|
2210
|
+
return null;
|
|
2211
|
+
if (!getSessionMessages.cache.has(sessionId)) {
|
|
2212
|
+
getSessionMessages.cache.set(sessionId, Promise.resolve(new Set(messages.keys())));
|
|
2213
|
+
}
|
|
2214
|
+
const lastMessage = findLatestMessage(messages.values(), (m) => !m.isSidechain);
|
|
2215
|
+
if (!lastMessage)
|
|
2216
|
+
return null;
|
|
2217
|
+
const transcript = buildConversationChain(messages, lastMessage);
|
|
2218
|
+
const summary = summaries.get(lastMessage.uuid);
|
|
2219
|
+
const customTitle = customTitles.get(lastMessage.sessionId);
|
|
2220
|
+
const tag = tags.get(lastMessage.sessionId);
|
|
2221
|
+
const agentSetting = agentSettings.get(sessionId);
|
|
2222
|
+
return {
|
|
2223
|
+
...convertToLogOption(transcript, 0, summary, customTitle, buildFileHistorySnapshotChain(fileHistorySnapshots, transcript), tag, getTranscriptPathForSession(sessionId), buildAttributionSnapshotChain(attributionSnapshots, transcript), agentSetting, contentReplacements.get(sessionId) ?? []),
|
|
2224
|
+
worktreeSession: worktreeStates.get(sessionId),
|
|
2225
|
+
contextCollapseCommits: contextCollapseCommits.filter((e) => e.sessionId === sessionId),
|
|
2226
|
+
contextCollapseSnapshot: contextCollapseSnapshot?.sessionId === sessionId ? contextCollapseSnapshot : undefined
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
export async function loadMessageLogs(limit) {
|
|
2230
|
+
const sessionLogs = await fetchLogs(limit);
|
|
2231
|
+
const { logs: enriched } = await enrichLogs(sessionLogs, 0, sessionLogs.length);
|
|
2232
|
+
const sorted = sortLogs(enriched);
|
|
2233
|
+
sorted.forEach((log, i) => {
|
|
2234
|
+
log.value = i;
|
|
2235
|
+
});
|
|
2236
|
+
return sorted;
|
|
2237
|
+
}
|
|
2238
|
+
export async function loadAllProjectsMessageLogs(limit, options) {
|
|
2239
|
+
if (options?.skipIndex) {
|
|
2240
|
+
return loadAllProjectsMessageLogsFull(limit);
|
|
2241
|
+
}
|
|
2242
|
+
const result = await loadAllProjectsMessageLogsProgressive(limit, options?.initialEnrichCount ?? INITIAL_ENRICH_COUNT);
|
|
2243
|
+
return result.logs;
|
|
2244
|
+
}
|
|
2245
|
+
async function loadAllProjectsMessageLogsFull(limit) {
|
|
2246
|
+
const projectsDir = getProjectsDir();
|
|
2247
|
+
let dirents;
|
|
2248
|
+
try {
|
|
2249
|
+
dirents = await readdir(projectsDir, { withFileTypes: true });
|
|
2250
|
+
} catch {
|
|
2251
|
+
return [];
|
|
2252
|
+
}
|
|
2253
|
+
const projectDirs = dirents.filter((dirent) => dirent.isDirectory()).map((dirent) => join(projectsDir, dirent.name));
|
|
2254
|
+
const logsPerProject = await Promise.all(projectDirs.map((projectDir) => getLogsWithoutIndex(projectDir, limit)));
|
|
2255
|
+
const allLogs = logsPerProject.flat();
|
|
2256
|
+
const deduped = new Map;
|
|
2257
|
+
for (const log of allLogs) {
|
|
2258
|
+
const key = `${log.sessionId ?? ""}:${log.leafUuid ?? ""}`;
|
|
2259
|
+
const existing = deduped.get(key);
|
|
2260
|
+
if (!existing || log.modified.getTime() > existing.modified.getTime()) {
|
|
2261
|
+
deduped.set(key, log);
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
const sorted = sortLogs([...deduped.values()]);
|
|
2265
|
+
sorted.forEach((log, i) => {
|
|
2266
|
+
log.value = i;
|
|
2267
|
+
});
|
|
2268
|
+
return sorted;
|
|
2269
|
+
}
|
|
2270
|
+
export async function loadAllProjectsMessageLogsProgressive(limit, initialEnrichCount = INITIAL_ENRICH_COUNT) {
|
|
2271
|
+
const projectsDir = getProjectsDir();
|
|
2272
|
+
let dirents;
|
|
2273
|
+
try {
|
|
2274
|
+
dirents = await readdir(projectsDir, { withFileTypes: true });
|
|
2275
|
+
} catch {
|
|
2276
|
+
return { logs: [], allStatLogs: [], nextIndex: 0 };
|
|
2277
|
+
}
|
|
2278
|
+
const projectDirs = dirents.filter((dirent) => dirent.isDirectory()).map((dirent) => join(projectsDir, dirent.name));
|
|
2279
|
+
const rawLogs = [];
|
|
2280
|
+
for (const projectDir of projectDirs) {
|
|
2281
|
+
rawLogs.push(...await getSessionFilesLite(projectDir, limit));
|
|
2282
|
+
}
|
|
2283
|
+
const sorted = deduplicateLogsBySessionId(rawLogs);
|
|
2284
|
+
const { logs, nextIndex } = await enrichLogs(sorted, 0, initialEnrichCount);
|
|
2285
|
+
logs.forEach((log, i) => {
|
|
2286
|
+
log.value = i;
|
|
2287
|
+
});
|
|
2288
|
+
return { logs, allStatLogs: sorted, nextIndex };
|
|
2289
|
+
}
|
|
2290
|
+
export async function loadSameRepoMessageLogs(worktreePaths, limit, initialEnrichCount = INITIAL_ENRICH_COUNT) {
|
|
2291
|
+
const result = await loadSameRepoMessageLogsProgressive(worktreePaths, limit, initialEnrichCount);
|
|
2292
|
+
return result.logs;
|
|
2293
|
+
}
|
|
2294
|
+
export async function loadSameRepoMessageLogsProgressive(worktreePaths, limit, initialEnrichCount = INITIAL_ENRICH_COUNT) {
|
|
2295
|
+
logForDebugging(`/resume: loading sessions for cwd=${getOriginalCwd()}, worktrees=[${worktreePaths.join(", ")}]`);
|
|
2296
|
+
const allStatLogs = await getStatOnlyLogsForWorktrees(worktreePaths, limit);
|
|
2297
|
+
logForDebugging(`/resume: found ${allStatLogs.length} session files on disk`);
|
|
2298
|
+
const { logs, nextIndex } = await enrichLogs(allStatLogs, 0, initialEnrichCount);
|
|
2299
|
+
logs.forEach((log, i) => {
|
|
2300
|
+
log.value = i;
|
|
2301
|
+
});
|
|
2302
|
+
return { logs, allStatLogs, nextIndex };
|
|
2303
|
+
}
|
|
2304
|
+
async function getStatOnlyLogsForWorktrees(worktreePaths, limit) {
|
|
2305
|
+
const projectsDir = getProjectsDir();
|
|
2306
|
+
if (worktreePaths.length <= 1) {
|
|
2307
|
+
const cwd = getOriginalCwd();
|
|
2308
|
+
const projectDir = getProjectDir(cwd);
|
|
2309
|
+
return getSessionFilesLite(projectDir, undefined, cwd);
|
|
2310
|
+
}
|
|
2311
|
+
const caseInsensitive = process.platform === "win32";
|
|
2312
|
+
const indexed = worktreePaths.map((wt) => {
|
|
2313
|
+
const sanitized = sanitizePath(wt);
|
|
2314
|
+
return {
|
|
2315
|
+
path: wt,
|
|
2316
|
+
prefix: caseInsensitive ? sanitized.toLowerCase() : sanitized
|
|
2317
|
+
};
|
|
2318
|
+
});
|
|
2319
|
+
indexed.sort((a, b) => b.prefix.length - a.prefix.length);
|
|
2320
|
+
const allLogs = [];
|
|
2321
|
+
const seenDirs = new Set;
|
|
2322
|
+
let allDirents;
|
|
2323
|
+
try {
|
|
2324
|
+
allDirents = await readdir(projectsDir, { withFileTypes: true });
|
|
2325
|
+
} catch (e) {
|
|
2326
|
+
logForDebugging(`Failed to read projects dir ${projectsDir}, falling back to current project: ${e}`);
|
|
2327
|
+
const projectDir = getProjectDir(getOriginalCwd());
|
|
2328
|
+
return getSessionFilesLite(projectDir, limit, getOriginalCwd());
|
|
2329
|
+
}
|
|
2330
|
+
for (const dirent of allDirents) {
|
|
2331
|
+
if (!dirent.isDirectory())
|
|
2332
|
+
continue;
|
|
2333
|
+
const dirName = caseInsensitive ? dirent.name.toLowerCase() : dirent.name;
|
|
2334
|
+
if (seenDirs.has(dirName))
|
|
2335
|
+
continue;
|
|
2336
|
+
for (const { path: wtPath, prefix } of indexed) {
|
|
2337
|
+
if (dirName === prefix || dirName.startsWith(prefix + "-")) {
|
|
2338
|
+
seenDirs.add(dirName);
|
|
2339
|
+
allLogs.push(...await getSessionFilesLite(join(projectsDir, dirent.name), undefined, wtPath));
|
|
2340
|
+
break;
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
return deduplicateLogsBySessionId(allLogs);
|
|
2345
|
+
}
|
|
2346
|
+
export async function getAgentTranscript(agentId) {
|
|
2347
|
+
const agentFile = getAgentTranscriptPath(agentId);
|
|
2348
|
+
try {
|
|
2349
|
+
const { messages, agentContentReplacements } = await loadTranscriptFile(agentFile);
|
|
2350
|
+
const agentMessages = Array.from(messages.values()).filter((msg) => msg.agentId === agentId && msg.isSidechain);
|
|
2351
|
+
if (agentMessages.length === 0) {
|
|
2352
|
+
return null;
|
|
2353
|
+
}
|
|
2354
|
+
const parentUuids = new Set(agentMessages.map((msg) => msg.parentUuid));
|
|
2355
|
+
const leafMessage = findLatestMessage(agentMessages, (msg) => !parentUuids.has(msg.uuid));
|
|
2356
|
+
if (!leafMessage) {
|
|
2357
|
+
return null;
|
|
2358
|
+
}
|
|
2359
|
+
const transcript = buildConversationChain(messages, leafMessage);
|
|
2360
|
+
const agentTranscript = transcript.filter((msg) => msg.agentId === agentId);
|
|
2361
|
+
return {
|
|
2362
|
+
messages: agentTranscript.map(({ isSidechain, parentUuid, ...msg }) => msg),
|
|
2363
|
+
contentReplacements: agentContentReplacements.get(agentId) ?? []
|
|
2364
|
+
};
|
|
2365
|
+
} catch {
|
|
2366
|
+
return null;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
export function extractAgentIdsFromMessages(messages) {
|
|
2370
|
+
const agentIds = [];
|
|
2371
|
+
for (const message of messages) {
|
|
2372
|
+
if (message.type === "progress" && message.data && typeof message.data === "object" && "type" in message.data && (message.data.type === "agent_progress" || message.data.type === "skill_progress") && "agentId" in message.data && typeof message.data.agentId === "string") {
|
|
2373
|
+
agentIds.push(message.data.agentId);
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
return uniq(agentIds);
|
|
2377
|
+
}
|
|
2378
|
+
export function extractTeammateTranscriptsFromTasks(tasks) {
|
|
2379
|
+
const transcripts = {};
|
|
2380
|
+
for (const task of Object.values(tasks)) {
|
|
2381
|
+
if (task.type === "in_process_teammate" && task.identity?.agentId && task.messages && task.messages.length > 0) {
|
|
2382
|
+
transcripts[task.identity.agentId] = task.messages;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
return transcripts;
|
|
2386
|
+
}
|
|
2387
|
+
export async function loadSubagentTranscripts(agentIds) {
|
|
2388
|
+
const results = await Promise.all(agentIds.map(async (agentId) => {
|
|
2389
|
+
try {
|
|
2390
|
+
const result = await getAgentTranscript(asAgentId(agentId));
|
|
2391
|
+
if (result && result.messages.length > 0) {
|
|
2392
|
+
return { agentId, transcript: result.messages };
|
|
2393
|
+
}
|
|
2394
|
+
return null;
|
|
2395
|
+
} catch {
|
|
2396
|
+
return null;
|
|
2397
|
+
}
|
|
2398
|
+
}));
|
|
2399
|
+
const transcripts = {};
|
|
2400
|
+
for (const result of results) {
|
|
2401
|
+
if (result) {
|
|
2402
|
+
transcripts[result.agentId] = result.transcript;
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
return transcripts;
|
|
2406
|
+
}
|
|
2407
|
+
export async function loadAllSubagentTranscriptsFromDisk() {
|
|
2408
|
+
const subagentsDir = join(getSessionProjectDir() ?? getProjectDir(getOriginalCwd()), getSessionId(), "subagents");
|
|
2409
|
+
let entries;
|
|
2410
|
+
try {
|
|
2411
|
+
entries = await readdir(subagentsDir, { withFileTypes: true });
|
|
2412
|
+
} catch {
|
|
2413
|
+
return {};
|
|
2414
|
+
}
|
|
2415
|
+
const agentIds = entries.filter((d) => d.isFile() && d.name.startsWith("agent-") && d.name.endsWith(".jsonl")).map((d) => d.name.slice("agent-".length, -".jsonl".length));
|
|
2416
|
+
return loadSubagentTranscripts(agentIds);
|
|
2417
|
+
}
|
|
2418
|
+
export function isLoggableMessage(m) {
|
|
2419
|
+
if (m.type === "progress")
|
|
2420
|
+
return false;
|
|
2421
|
+
if (m.type === "attachment" && getUserType() !== "ant") {
|
|
2422
|
+
if (m.attachment.type === "hook_additional_context" && isEnvTruthy(process.env.CLAUDE_CODE_SAVE_HOOK_ADDITIONAL_CONTEXT)) {
|
|
2423
|
+
return true;
|
|
2424
|
+
}
|
|
2425
|
+
return false;
|
|
2426
|
+
}
|
|
2427
|
+
return true;
|
|
2428
|
+
}
|
|
2429
|
+
function collectReplIds(messages) {
|
|
2430
|
+
const ids = new Set;
|
|
2431
|
+
for (const m of messages) {
|
|
2432
|
+
if (m.type === "assistant" && Array.isArray(m.message.content)) {
|
|
2433
|
+
for (const b of m.message.content) {
|
|
2434
|
+
if (b.type === "tool_use" && b.name === REPL_TOOL_NAME) {
|
|
2435
|
+
ids.add(b.id);
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
return ids;
|
|
2441
|
+
}
|
|
2442
|
+
function transformMessagesForExternalTranscript(messages, replIds) {
|
|
2443
|
+
return messages.flatMap((m) => {
|
|
2444
|
+
if (m.type === "assistant" && Array.isArray(m.message.content)) {
|
|
2445
|
+
const content = m.message.content;
|
|
2446
|
+
const hasRepl = content.some((b) => b.type === "tool_use" && b.name === REPL_TOOL_NAME);
|
|
2447
|
+
const filtered = hasRepl ? content.filter((b) => !(b.type === "tool_use" && b.name === REPL_TOOL_NAME)) : content;
|
|
2448
|
+
if (filtered.length === 0)
|
|
2449
|
+
return [];
|
|
2450
|
+
if (m.isVirtual) {
|
|
2451
|
+
const { isVirtual: _omit, ...rest } = m;
|
|
2452
|
+
return [{ ...rest, message: { ...m.message, content: filtered } }];
|
|
2453
|
+
}
|
|
2454
|
+
if (filtered !== content) {
|
|
2455
|
+
return [{ ...m, message: { ...m.message, content: filtered } }];
|
|
2456
|
+
}
|
|
2457
|
+
return [m];
|
|
2458
|
+
}
|
|
2459
|
+
if (m.type === "user" && Array.isArray(m.message.content)) {
|
|
2460
|
+
const content = m.message.content;
|
|
2461
|
+
const hasRepl = content.some((b) => b.type === "tool_result" && replIds.has(b.tool_use_id));
|
|
2462
|
+
const filtered = hasRepl ? content.filter((b) => !(b.type === "tool_result" && replIds.has(b.tool_use_id))) : content;
|
|
2463
|
+
if (filtered.length === 0)
|
|
2464
|
+
return [];
|
|
2465
|
+
if (m.isVirtual) {
|
|
2466
|
+
const { isVirtual: _omit, ...rest } = m;
|
|
2467
|
+
return [{ ...rest, message: { ...m.message, content: filtered } }];
|
|
2468
|
+
}
|
|
2469
|
+
if (filtered !== content) {
|
|
2470
|
+
return [{ ...m, message: { ...m.message, content: filtered } }];
|
|
2471
|
+
}
|
|
2472
|
+
return [m];
|
|
2473
|
+
}
|
|
2474
|
+
if ("isVirtual" in m && m.isVirtual) {
|
|
2475
|
+
const { isVirtual: _omit, ...rest } = m;
|
|
2476
|
+
return [rest];
|
|
2477
|
+
}
|
|
2478
|
+
return [m];
|
|
2479
|
+
});
|
|
2480
|
+
}
|
|
2481
|
+
export function cleanMessagesForLogging(messages, allMessages = messages) {
|
|
2482
|
+
const filtered = messages.filter(isLoggableMessage);
|
|
2483
|
+
return getUserType() !== "ant" ? transformMessagesForExternalTranscript(filtered, collectReplIds(allMessages)) : filtered;
|
|
2484
|
+
}
|
|
2485
|
+
export async function getLogByIndex(index) {
|
|
2486
|
+
const logs = await loadMessageLogs();
|
|
2487
|
+
return logs[index] || null;
|
|
2488
|
+
}
|
|
2489
|
+
export async function findUnresolvedToolUse(toolUseId) {
|
|
2490
|
+
try {
|
|
2491
|
+
const transcriptPath = getTranscriptPath();
|
|
2492
|
+
const { messages } = await loadTranscriptFile(transcriptPath);
|
|
2493
|
+
let toolUseMessage = null;
|
|
2494
|
+
for (const message of messages.values()) {
|
|
2495
|
+
if (message.type === "assistant") {
|
|
2496
|
+
const content = message.message.content;
|
|
2497
|
+
if (Array.isArray(content)) {
|
|
2498
|
+
for (const block of content) {
|
|
2499
|
+
if (block.type === "tool_use" && block.id === toolUseId) {
|
|
2500
|
+
toolUseMessage = message;
|
|
2501
|
+
break;
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
} else if (message.type === "user") {
|
|
2506
|
+
const content = message.message.content;
|
|
2507
|
+
if (Array.isArray(content)) {
|
|
2508
|
+
for (const block of content) {
|
|
2509
|
+
if (block.type === "tool_result" && block.tool_use_id === toolUseId) {
|
|
2510
|
+
return null;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
return toolUseMessage;
|
|
2517
|
+
} catch {
|
|
2518
|
+
return null;
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
export async function getSessionFilesWithMtime(projectDir) {
|
|
2522
|
+
const sessionFilesMap = new Map;
|
|
2523
|
+
let dirents;
|
|
2524
|
+
try {
|
|
2525
|
+
dirents = await readdir(projectDir, { withFileTypes: true });
|
|
2526
|
+
} catch {
|
|
2527
|
+
return sessionFilesMap;
|
|
2528
|
+
}
|
|
2529
|
+
const candidates = [];
|
|
2530
|
+
for (const dirent of dirents) {
|
|
2531
|
+
if (!dirent.isFile() || !dirent.name.endsWith(".jsonl"))
|
|
2532
|
+
continue;
|
|
2533
|
+
const sessionId = validateUuid(basename(dirent.name, ".jsonl"));
|
|
2534
|
+
if (!sessionId)
|
|
2535
|
+
continue;
|
|
2536
|
+
candidates.push({ sessionId, filePath: join(projectDir, dirent.name) });
|
|
2537
|
+
}
|
|
2538
|
+
await Promise.all(candidates.map(async ({ sessionId, filePath }) => {
|
|
2539
|
+
try {
|
|
2540
|
+
const st = await stat(filePath);
|
|
2541
|
+
sessionFilesMap.set(sessionId, {
|
|
2542
|
+
path: filePath,
|
|
2543
|
+
mtime: st.mtime.getTime(),
|
|
2544
|
+
ctime: st.birthtime.getTime(),
|
|
2545
|
+
size: st.size
|
|
2546
|
+
});
|
|
2547
|
+
} catch {
|
|
2548
|
+
logForDebugging(`Failed to stat session file: ${filePath}`);
|
|
2549
|
+
}
|
|
2550
|
+
}));
|
|
2551
|
+
return sessionFilesMap;
|
|
2552
|
+
}
|
|
2553
|
+
const INITIAL_ENRICH_COUNT = 50;
|
|
2554
|
+
export async function loadAllLogsFromSessionFile(sessionFile, projectPathOverride) {
|
|
2555
|
+
const {
|
|
2556
|
+
messages,
|
|
2557
|
+
summaries,
|
|
2558
|
+
customTitles,
|
|
2559
|
+
tags,
|
|
2560
|
+
agentNames,
|
|
2561
|
+
agentColors,
|
|
2562
|
+
agentSettings,
|
|
2563
|
+
prNumbers,
|
|
2564
|
+
prUrls,
|
|
2565
|
+
prRepositories,
|
|
2566
|
+
modes,
|
|
2567
|
+
fileHistorySnapshots,
|
|
2568
|
+
attributionSnapshots,
|
|
2569
|
+
contentReplacements,
|
|
2570
|
+
leafUuids
|
|
2571
|
+
} = await loadTranscriptFile(sessionFile, { keepAllLeaves: true });
|
|
2572
|
+
if (messages.size === 0)
|
|
2573
|
+
return [];
|
|
2574
|
+
const leafMessages = [];
|
|
2575
|
+
const childrenByParent = new Map;
|
|
2576
|
+
for (const msg of messages.values()) {
|
|
2577
|
+
if (leafUuids.has(msg.uuid)) {
|
|
2578
|
+
leafMessages.push(msg);
|
|
2579
|
+
} else if (msg.parentUuid) {
|
|
2580
|
+
const siblings = childrenByParent.get(msg.parentUuid);
|
|
2581
|
+
if (siblings) {
|
|
2582
|
+
siblings.push(msg);
|
|
2583
|
+
} else {
|
|
2584
|
+
childrenByParent.set(msg.parentUuid, [msg]);
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
const logs = [];
|
|
2589
|
+
for (const leafMessage of leafMessages) {
|
|
2590
|
+
const chain = buildConversationChain(messages, leafMessage);
|
|
2591
|
+
if (chain.length === 0)
|
|
2592
|
+
continue;
|
|
2593
|
+
const trailingMessages = childrenByParent.get(leafMessage.uuid);
|
|
2594
|
+
if (trailingMessages) {
|
|
2595
|
+
trailingMessages.sort((a, b) => a.timestamp < b.timestamp ? -1 : a.timestamp > b.timestamp ? 1 : 0);
|
|
2596
|
+
chain.push(...trailingMessages);
|
|
2597
|
+
}
|
|
2598
|
+
const firstMessage = chain[0];
|
|
2599
|
+
const sessionId = leafMessage.sessionId;
|
|
2600
|
+
logs.push({
|
|
2601
|
+
date: leafMessage.timestamp,
|
|
2602
|
+
messages: removeExtraFields(chain),
|
|
2603
|
+
fullPath: sessionFile,
|
|
2604
|
+
value: 0,
|
|
2605
|
+
created: new Date(firstMessage.timestamp),
|
|
2606
|
+
modified: new Date(leafMessage.timestamp),
|
|
2607
|
+
firstPrompt: extractFirstPrompt(chain),
|
|
2608
|
+
messageCount: countVisibleMessages(chain),
|
|
2609
|
+
isSidechain: firstMessage.isSidechain ?? false,
|
|
2610
|
+
sessionId,
|
|
2611
|
+
leafUuid: leafMessage.uuid,
|
|
2612
|
+
summary: summaries.get(leafMessage.uuid),
|
|
2613
|
+
customTitle: customTitles.get(sessionId),
|
|
2614
|
+
tag: tags.get(sessionId),
|
|
2615
|
+
agentName: agentNames.get(sessionId),
|
|
2616
|
+
agentColor: agentColors.get(sessionId),
|
|
2617
|
+
agentSetting: agentSettings.get(sessionId),
|
|
2618
|
+
mode: modes.get(sessionId),
|
|
2619
|
+
prNumber: prNumbers.get(sessionId),
|
|
2620
|
+
prUrl: prUrls.get(sessionId),
|
|
2621
|
+
prRepository: prRepositories.get(sessionId),
|
|
2622
|
+
gitBranch: leafMessage.gitBranch,
|
|
2623
|
+
projectPath: projectPathOverride ?? firstMessage.cwd,
|
|
2624
|
+
fileHistorySnapshots: buildFileHistorySnapshotChain(fileHistorySnapshots, chain),
|
|
2625
|
+
attributionSnapshots: buildAttributionSnapshotChain(attributionSnapshots, chain),
|
|
2626
|
+
contentReplacements: contentReplacements.get(sessionId) ?? []
|
|
2627
|
+
});
|
|
2628
|
+
}
|
|
2629
|
+
return logs;
|
|
2630
|
+
}
|
|
2631
|
+
async function getLogsWithoutIndex(projectDir, limit) {
|
|
2632
|
+
const sessionFilesMap = await getSessionFilesWithMtime(projectDir);
|
|
2633
|
+
if (sessionFilesMap.size === 0)
|
|
2634
|
+
return [];
|
|
2635
|
+
let filesToProcess;
|
|
2636
|
+
if (limit && sessionFilesMap.size > limit) {
|
|
2637
|
+
filesToProcess = [...sessionFilesMap.values()].sort((a, b) => b.mtime - a.mtime).slice(0, limit);
|
|
2638
|
+
} else {
|
|
2639
|
+
filesToProcess = [...sessionFilesMap.values()];
|
|
2640
|
+
}
|
|
2641
|
+
const logs = [];
|
|
2642
|
+
for (const fileInfo of filesToProcess) {
|
|
2643
|
+
try {
|
|
2644
|
+
const fileLogOptions = await loadAllLogsFromSessionFile(fileInfo.path);
|
|
2645
|
+
logs.push(...fileLogOptions);
|
|
2646
|
+
} catch {
|
|
2647
|
+
logForDebugging(`Failed to load session file: ${fileInfo.path}`);
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
return logs;
|
|
2651
|
+
}
|
|
2652
|
+
async function readLiteMetadata(filePath, fileSize, buf) {
|
|
2653
|
+
const { head, tail } = await readHeadAndTail(filePath, fileSize, buf);
|
|
2654
|
+
if (!head)
|
|
2655
|
+
return { firstPrompt: "", isSidechain: false };
|
|
2656
|
+
const isSidechain = head.includes('"isSidechain":true') || head.includes('"isSidechain": true');
|
|
2657
|
+
const projectPath = extractJsonStringField(head, "cwd");
|
|
2658
|
+
const teamName = extractJsonStringField(head, "teamName");
|
|
2659
|
+
const agentSetting = extractJsonStringField(head, "agentSetting");
|
|
2660
|
+
const firstPrompt = extractLastJsonStringField(tail, "lastPrompt") || extractFirstPromptFromChunk(head) || extractJsonStringFieldPrefix(head, "content", 200) || extractJsonStringFieldPrefix(head, "text", 200) || "";
|
|
2661
|
+
const customTitle = extractLastJsonStringField(tail, "customTitle") ?? extractLastJsonStringField(head, "customTitle") ?? extractLastJsonStringField(tail, "aiTitle") ?? extractLastJsonStringField(head, "aiTitle");
|
|
2662
|
+
const summary = extractLastJsonStringField(tail, "summary");
|
|
2663
|
+
const tag = extractLastJsonStringField(tail, "tag");
|
|
2664
|
+
const gitBranch = extractLastJsonStringField(tail, "gitBranch") ?? extractJsonStringField(head, "gitBranch");
|
|
2665
|
+
const prUrl = extractLastJsonStringField(tail, "prUrl");
|
|
2666
|
+
const prRepository = extractLastJsonStringField(tail, "prRepository");
|
|
2667
|
+
let prNumber;
|
|
2668
|
+
const prNumStr = extractLastJsonStringField(tail, "prNumber");
|
|
2669
|
+
if (prNumStr) {
|
|
2670
|
+
prNumber = parseInt(prNumStr, 10) || undefined;
|
|
2671
|
+
}
|
|
2672
|
+
if (!prNumber) {
|
|
2673
|
+
const prNumMatch = tail.lastIndexOf('"prNumber":');
|
|
2674
|
+
if (prNumMatch >= 0) {
|
|
2675
|
+
const afterColon = tail.slice(prNumMatch + 11, prNumMatch + 25);
|
|
2676
|
+
const num = parseInt(afterColon.trim(), 10);
|
|
2677
|
+
if (num > 0)
|
|
2678
|
+
prNumber = num;
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
return {
|
|
2682
|
+
firstPrompt,
|
|
2683
|
+
gitBranch,
|
|
2684
|
+
isSidechain,
|
|
2685
|
+
projectPath,
|
|
2686
|
+
teamName,
|
|
2687
|
+
customTitle,
|
|
2688
|
+
summary,
|
|
2689
|
+
tag,
|
|
2690
|
+
agentSetting,
|
|
2691
|
+
prNumber,
|
|
2692
|
+
prUrl,
|
|
2693
|
+
prRepository
|
|
2694
|
+
};
|
|
2695
|
+
}
|
|
2696
|
+
function extractFirstPromptFromChunk(chunk) {
|
|
2697
|
+
let start = 0;
|
|
2698
|
+
let hasTickMessages = false;
|
|
2699
|
+
let firstCommandFallback = "";
|
|
2700
|
+
while (start < chunk.length) {
|
|
2701
|
+
const newlineIdx = chunk.indexOf(`
|
|
2702
|
+
`, start);
|
|
2703
|
+
const line = newlineIdx >= 0 ? chunk.slice(start, newlineIdx) : chunk.slice(start);
|
|
2704
|
+
start = newlineIdx >= 0 ? newlineIdx + 1 : chunk.length;
|
|
2705
|
+
if (!line.includes('"type":"user"') && !line.includes('"type": "user"')) {
|
|
2706
|
+
continue;
|
|
2707
|
+
}
|
|
2708
|
+
if (line.includes('"tool_result"'))
|
|
2709
|
+
continue;
|
|
2710
|
+
if (line.includes('"isMeta":true') || line.includes('"isMeta": true'))
|
|
2711
|
+
continue;
|
|
2712
|
+
try {
|
|
2713
|
+
const entry = jsonParse(line);
|
|
2714
|
+
if (entry.type !== "user")
|
|
2715
|
+
continue;
|
|
2716
|
+
const message = entry.message;
|
|
2717
|
+
if (!message)
|
|
2718
|
+
continue;
|
|
2719
|
+
const content = message.content;
|
|
2720
|
+
const texts = [];
|
|
2721
|
+
if (typeof content === "string") {
|
|
2722
|
+
texts.push(content);
|
|
2723
|
+
} else if (Array.isArray(content)) {
|
|
2724
|
+
for (const block of content) {
|
|
2725
|
+
const b = block;
|
|
2726
|
+
if (b.type === "text" && typeof b.text === "string") {
|
|
2727
|
+
texts.push(b.text);
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
for (const text of texts) {
|
|
2732
|
+
if (!text)
|
|
2733
|
+
continue;
|
|
2734
|
+
let result = text.replace(/\n/g, " ").trim();
|
|
2735
|
+
const commandNameTag = extractTag(result, COMMAND_NAME_TAG);
|
|
2736
|
+
if (commandNameTag) {
|
|
2737
|
+
const name = commandNameTag.replace(/^\//, "");
|
|
2738
|
+
const commandArgs = extractTag(result, "command-args")?.trim() || "";
|
|
2739
|
+
if (builtInCommandNames().has(name) || !commandArgs) {
|
|
2740
|
+
if (!firstCommandFallback) {
|
|
2741
|
+
firstCommandFallback = commandNameTag;
|
|
2742
|
+
}
|
|
2743
|
+
continue;
|
|
2744
|
+
}
|
|
2745
|
+
return commandArgs ? `${commandNameTag} ${commandArgs}` : commandNameTag;
|
|
2746
|
+
}
|
|
2747
|
+
const bashInput = extractTag(result, "bash-input");
|
|
2748
|
+
if (bashInput)
|
|
2749
|
+
return `! ${bashInput}`;
|
|
2750
|
+
if (SKIP_FIRST_PROMPT_PATTERN.test(result)) {
|
|
2751
|
+
if (false)
|
|
2752
|
+
;
|
|
2753
|
+
continue;
|
|
2754
|
+
}
|
|
2755
|
+
if (result.length > 200) {
|
|
2756
|
+
result = result.slice(0, 200).trim() + "…";
|
|
2757
|
+
}
|
|
2758
|
+
return result;
|
|
2759
|
+
}
|
|
2760
|
+
} catch {
|
|
2761
|
+
continue;
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
if (firstCommandFallback)
|
|
2765
|
+
return firstCommandFallback;
|
|
2766
|
+
if (false)
|
|
2767
|
+
;
|
|
2768
|
+
return "";
|
|
2769
|
+
}
|
|
2770
|
+
function extractJsonStringFieldPrefix(text, key, maxLen) {
|
|
2771
|
+
const patterns = [`"${key}":"`, `"${key}": "`];
|
|
2772
|
+
for (const pattern of patterns) {
|
|
2773
|
+
const idx = text.indexOf(pattern);
|
|
2774
|
+
if (idx < 0)
|
|
2775
|
+
continue;
|
|
2776
|
+
const valueStart = idx + pattern.length;
|
|
2777
|
+
let i = valueStart;
|
|
2778
|
+
let collected = 0;
|
|
2779
|
+
while (i < text.length && collected < maxLen) {
|
|
2780
|
+
if (text[i] === "\\") {
|
|
2781
|
+
i += 2;
|
|
2782
|
+
collected++;
|
|
2783
|
+
continue;
|
|
2784
|
+
}
|
|
2785
|
+
if (text[i] === '"')
|
|
2786
|
+
break;
|
|
2787
|
+
i++;
|
|
2788
|
+
collected++;
|
|
2789
|
+
}
|
|
2790
|
+
const raw = text.slice(valueStart, i);
|
|
2791
|
+
return raw.replace(/\\n/g, " ").replace(/\\t/g, " ").trim();
|
|
2792
|
+
}
|
|
2793
|
+
return "";
|
|
2794
|
+
}
|
|
2795
|
+
function deduplicateLogsBySessionId(logs) {
|
|
2796
|
+
const deduped = new Map;
|
|
2797
|
+
for (const log of logs) {
|
|
2798
|
+
if (!log.sessionId)
|
|
2799
|
+
continue;
|
|
2800
|
+
const existing = deduped.get(log.sessionId);
|
|
2801
|
+
if (!existing || log.modified.getTime() > existing.modified.getTime()) {
|
|
2802
|
+
deduped.set(log.sessionId, log);
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
return sortLogs([...deduped.values()]).map((log, i) => ({
|
|
2806
|
+
...log,
|
|
2807
|
+
value: i
|
|
2808
|
+
}));
|
|
2809
|
+
}
|
|
2810
|
+
export async function getSessionFilesLite(projectDir, limit, projectPath) {
|
|
2811
|
+
const sessionFilesMap = await getSessionFilesWithMtime(projectDir);
|
|
2812
|
+
let entries = [...sessionFilesMap.entries()].sort((a, b) => b[1].mtime - a[1].mtime);
|
|
2813
|
+
if (limit && entries.length > limit) {
|
|
2814
|
+
entries = entries.slice(0, limit);
|
|
2815
|
+
}
|
|
2816
|
+
const logs = [];
|
|
2817
|
+
for (const [sessionId, fileInfo] of entries) {
|
|
2818
|
+
logs.push({
|
|
2819
|
+
date: new Date(fileInfo.mtime).toISOString(),
|
|
2820
|
+
messages: [],
|
|
2821
|
+
isLite: true,
|
|
2822
|
+
fullPath: fileInfo.path,
|
|
2823
|
+
value: 0,
|
|
2824
|
+
created: new Date(fileInfo.ctime),
|
|
2825
|
+
modified: new Date(fileInfo.mtime),
|
|
2826
|
+
firstPrompt: "",
|
|
2827
|
+
messageCount: 0,
|
|
2828
|
+
fileSize: fileInfo.size,
|
|
2829
|
+
isSidechain: false,
|
|
2830
|
+
sessionId,
|
|
2831
|
+
projectPath
|
|
2832
|
+
});
|
|
2833
|
+
}
|
|
2834
|
+
const sorted = sortLogs(logs);
|
|
2835
|
+
sorted.forEach((log, i) => {
|
|
2836
|
+
log.value = i;
|
|
2837
|
+
});
|
|
2838
|
+
return sorted;
|
|
2839
|
+
}
|
|
2840
|
+
async function enrichLog(log, readBuf) {
|
|
2841
|
+
if (!log.isLite || !log.fullPath)
|
|
2842
|
+
return log;
|
|
2843
|
+
const meta = await readLiteMetadata(log.fullPath, log.fileSize ?? 0, readBuf);
|
|
2844
|
+
const enriched = {
|
|
2845
|
+
...log,
|
|
2846
|
+
isLite: false,
|
|
2847
|
+
firstPrompt: meta.firstPrompt,
|
|
2848
|
+
gitBranch: meta.gitBranch,
|
|
2849
|
+
isSidechain: meta.isSidechain,
|
|
2850
|
+
teamName: meta.teamName,
|
|
2851
|
+
customTitle: meta.customTitle,
|
|
2852
|
+
summary: meta.summary,
|
|
2853
|
+
tag: meta.tag,
|
|
2854
|
+
agentSetting: meta.agentSetting,
|
|
2855
|
+
prNumber: meta.prNumber,
|
|
2856
|
+
prUrl: meta.prUrl,
|
|
2857
|
+
prRepository: meta.prRepository,
|
|
2858
|
+
projectPath: meta.projectPath ?? log.projectPath
|
|
2859
|
+
};
|
|
2860
|
+
if (!enriched.firstPrompt && !enriched.customTitle) {
|
|
2861
|
+
enriched.firstPrompt = "(session)";
|
|
2862
|
+
}
|
|
2863
|
+
if (enriched.isSidechain) {
|
|
2864
|
+
logForDebugging(`Session ${log.sessionId} filtered from /resume: isSidechain=true`);
|
|
2865
|
+
return null;
|
|
2866
|
+
}
|
|
2867
|
+
if (enriched.teamName) {
|
|
2868
|
+
logForDebugging(`Session ${log.sessionId} filtered from /resume: teamName=${enriched.teamName}`);
|
|
2869
|
+
return null;
|
|
2870
|
+
}
|
|
2871
|
+
return enriched;
|
|
2872
|
+
}
|
|
2873
|
+
export async function enrichLogs(allLogs, startIndex, count) {
|
|
2874
|
+
const result = [];
|
|
2875
|
+
const readBuf = Buffer.alloc(LITE_READ_BUF_SIZE);
|
|
2876
|
+
let i = startIndex;
|
|
2877
|
+
while (i < allLogs.length && result.length < count) {
|
|
2878
|
+
const log = allLogs[i];
|
|
2879
|
+
i++;
|
|
2880
|
+
const enriched = await enrichLog(log, readBuf);
|
|
2881
|
+
if (enriched) {
|
|
2882
|
+
result.push(enriched);
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
const scanned = i - startIndex;
|
|
2886
|
+
const filtered = scanned - result.length;
|
|
2887
|
+
if (filtered > 0) {
|
|
2888
|
+
logForDebugging(`/resume: enriched ${scanned} sessions, ${filtered} filtered out, ${result.length} visible (${allLogs.length - i} remaining on disk)`);
|
|
2889
|
+
}
|
|
2890
|
+
return { logs: result, nextIndex: i };
|
|
2891
|
+
}
|