@mseep/claudian 2.0.25
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.local.example +2 -0
- package/.github/workflows/ci.yml +59 -0
- package/.github/workflows/claude-code-review.yml +57 -0
- package/.github/workflows/claude.yml +50 -0
- package/.github/workflows/duplicate-issues.yml +22 -0
- package/.github/workflows/release.yml +73 -0
- package/.github/workflows/stale.yml +21 -0
- package/.node-version +1 -0
- package/AGENTS.md +3 -0
- package/CLAUDE.md +80 -0
- package/LICENSE +21 -0
- package/README.md +190 -0
- package/assets/Preview.png +0 -0
- package/assets/sponsors/MOMA.png +0 -0
- package/bun.lock +1618 -0
- package/esbuild.config.mjs +195 -0
- package/eslint.config.mjs +143 -0
- package/jest.config.js +41 -0
- package/main.js +104915 -0
- package/manifest.json +10 -0
- package/package.json +65 -0
- package/scripts/build-css.mjs +119 -0
- package/scripts/build.mjs +19 -0
- package/scripts/postinstall.mjs +25 -0
- package/scripts/rendererSafeUnref.js +205 -0
- package/scripts/run-jest.js +19 -0
- package/scripts/sync-version.js +16 -0
- package/src/app/settings/ClaudianSettingsStorage.ts +435 -0
- package/src/app/settings/defaultSettings.ts +54 -0
- package/src/app/storage/SharedStorageService.ts +106 -0
- package/src/core/CLAUDE.md +84 -0
- package/src/core/auxiliary/AuxQueryRunner.ts +11 -0
- package/src/core/auxiliary/QueryBackedInlineEditService.ts +73 -0
- package/src/core/auxiliary/QueryBackedInstructionRefineService.ts +78 -0
- package/src/core/auxiliary/QueryBackedTitleGenerationService.ts +90 -0
- package/src/core/bootstrap/SessionStorage.ts +179 -0
- package/src/core/bootstrap/StoragePaths.ts +7 -0
- package/src/core/bootstrap/storage.ts +20 -0
- package/src/core/commands/builtInCommands.ts +141 -0
- package/src/core/mcp/McpConfigParser.ts +102 -0
- package/src/core/mcp/McpServerManager.ts +119 -0
- package/src/core/mcp/McpTester.ts +310 -0
- package/src/core/prompt/inlineEdit.ts +252 -0
- package/src/core/prompt/instructionRefine.ts +72 -0
- package/src/core/prompt/mainAgent.ts +213 -0
- package/src/core/prompt/titleGeneration.ts +44 -0
- package/src/core/providers/ProviderRegistry.ts +253 -0
- package/src/core/providers/ProviderSettingsCoordinator.ts +434 -0
- package/src/core/providers/ProviderWorkspaceRegistry.ts +119 -0
- package/src/core/providers/commands/ProviderCommandCatalog.ts +21 -0
- package/src/core/providers/commands/ProviderCommandEntry.ts +33 -0
- package/src/core/providers/commands/hiddenCommands.ts +74 -0
- package/src/core/providers/modelRouting.ts +17 -0
- package/src/core/providers/modelSelection.ts +72 -0
- package/src/core/providers/providerConfig.ts +34 -0
- package/src/core/providers/providerEnvironment.ts +364 -0
- package/src/core/providers/types.ts +544 -0
- package/src/core/runtime/ChatRuntime.ts +66 -0
- package/src/core/runtime/QueuedTurn.ts +97 -0
- package/src/core/runtime/types.ts +118 -0
- package/src/core/security/ApprovalManager.ts +142 -0
- package/src/core/storage/HomeFileAdapter.ts +75 -0
- package/src/core/storage/VaultFileAdapter.ts +132 -0
- package/src/core/tools/todo.ts +65 -0
- package/src/core/tools/toolIcons.ts +80 -0
- package/src/core/tools/toolInput.ts +119 -0
- package/src/core/tools/toolNames.ts +149 -0
- package/src/core/tools/toolResultContent.ts +26 -0
- package/src/core/types/agent.ts +28 -0
- package/src/core/types/chat.ts +177 -0
- package/src/core/types/diff.ts +31 -0
- package/src/core/types/index.ts +78 -0
- package/src/core/types/mcp.ts +97 -0
- package/src/core/types/plugins.ts +9 -0
- package/src/core/types/provider.ts +1 -0
- package/src/core/types/settings.ts +152 -0
- package/src/core/types/tools.ts +80 -0
- package/src/features/chat/CLAUDE.md +136 -0
- package/src/features/chat/ClaudianView.ts +762 -0
- package/src/features/chat/constants.ts +114 -0
- package/src/features/chat/controllers/BrowserSelectionController.ts +295 -0
- package/src/features/chat/controllers/CanvasSelectionController.ts +142 -0
- package/src/features/chat/controllers/ConversationController.ts +1103 -0
- package/src/features/chat/controllers/InputController.ts +1707 -0
- package/src/features/chat/controllers/NavigationController.ts +209 -0
- package/src/features/chat/controllers/SelectionController.ts +430 -0
- package/src/features/chat/controllers/StreamController.ts +1560 -0
- package/src/features/chat/controllers/contextRowVisibility.ts +18 -0
- package/src/features/chat/rendering/DiffRenderer.ts +134 -0
- package/src/features/chat/rendering/InlineAskUserQuestion.ts +702 -0
- package/src/features/chat/rendering/InlineExitPlanMode.ts +263 -0
- package/src/features/chat/rendering/InlinePlanApproval.ts +183 -0
- package/src/features/chat/rendering/MessageRenderer.ts +907 -0
- package/src/features/chat/rendering/SubagentRenderer.ts +678 -0
- package/src/features/chat/rendering/ThinkingBlockRenderer.ts +126 -0
- package/src/features/chat/rendering/TodoListRenderer.ts +5 -0
- package/src/features/chat/rendering/ToolCallRenderer.ts +1161 -0
- package/src/features/chat/rendering/WriteEditRenderer.ts +232 -0
- package/src/features/chat/rendering/collapsible.ts +101 -0
- package/src/features/chat/rendering/subagentLifecycleResolution.ts +25 -0
- package/src/features/chat/rendering/todoUtils.ts +29 -0
- package/src/features/chat/rewind.ts +31 -0
- package/src/features/chat/services/BangBashService.ts +56 -0
- package/src/features/chat/services/SubagentManager.ts +1107 -0
- package/src/features/chat/state/ChatState.ts +436 -0
- package/src/features/chat/state/types.ts +138 -0
- package/src/features/chat/tabs/Tab.ts +1886 -0
- package/src/features/chat/tabs/TabBar.ts +179 -0
- package/src/features/chat/tabs/TabManager.ts +1021 -0
- package/src/features/chat/tabs/providerResolution.ts +34 -0
- package/src/features/chat/tabs/types.ts +287 -0
- package/src/features/chat/ui/BangBashModeManager.ts +121 -0
- package/src/features/chat/ui/FileContext.ts +385 -0
- package/src/features/chat/ui/ImageContext.ts +366 -0
- package/src/features/chat/ui/InputToolbar.ts +1244 -0
- package/src/features/chat/ui/InstructionModeManager.ts +158 -0
- package/src/features/chat/ui/NavigationSidebar.ts +126 -0
- package/src/features/chat/ui/StatusPanel.ts +589 -0
- package/src/features/chat/ui/file-context/state/FileContextState.ts +83 -0
- package/src/features/chat/ui/file-context/view/FileChipsView.ts +70 -0
- package/src/features/chat/ui/textareaResize.ts +47 -0
- package/src/features/chat/utils/usageInfo.ts +26 -0
- package/src/features/inline-edit/ui/InlineEditModal.ts +895 -0
- package/src/features/inline-edit/ui/inlineEditMarkdownPreview.ts +55 -0
- package/src/features/settings/ClaudianSettings.ts +672 -0
- package/src/features/settings/keyboardNavigation.ts +60 -0
- package/src/features/settings/ui/EnvSnippetManager.ts +430 -0
- package/src/features/settings/ui/EnvironmentSettingsSection.ts +85 -0
- package/src/features/settings/ui/McpServerModal.ts +335 -0
- package/src/features/settings/ui/McpSettingsManager.ts +400 -0
- package/src/features/settings/ui/McpTestModal.ts +346 -0
- package/src/i18n/constants.ts +58 -0
- package/src/i18n/i18n.ts +140 -0
- package/src/i18n/locales/de.json +322 -0
- package/src/i18n/locales/en.json +322 -0
- package/src/i18n/locales/es.json +322 -0
- package/src/i18n/locales/fr.json +322 -0
- package/src/i18n/locales/ja.json +322 -0
- package/src/i18n/locales/ko.json +322 -0
- package/src/i18n/locales/pt.json +322 -0
- package/src/i18n/locales/ru.json +322 -0
- package/src/i18n/locales/zh-CN.json +322 -0
- package/src/i18n/locales/zh-TW.json +322 -0
- package/src/i18n/types.ts +248 -0
- package/src/main.ts +772 -0
- package/src/providers/acp/AcpClientConnection.ts +361 -0
- package/src/providers/acp/AcpJsonRpcTransport.ts +427 -0
- package/src/providers/acp/AcpSessionConfig.ts +139 -0
- package/src/providers/acp/AcpSessionUpdateNormalizer.ts +371 -0
- package/src/providers/acp/AcpSubprocess.ts +155 -0
- package/src/providers/acp/AcpToolStreamAdapter.ts +132 -0
- package/src/providers/acp/buildAcpUsageInfo.ts +41 -0
- package/src/providers/acp/index.ts +9 -0
- package/src/providers/acp/methodNames.ts +50 -0
- package/src/providers/acp/types.ts +566 -0
- package/src/providers/claude/CLAUDE.md +78 -0
- package/src/providers/claude/agents/AgentManager.ts +225 -0
- package/src/providers/claude/agents/AgentStorage.ts +101 -0
- package/src/providers/claude/app/ClaudeWorkspaceServices.ts +90 -0
- package/src/providers/claude/auxiliary/ClaudeInlineEditService.ts +122 -0
- package/src/providers/claude/auxiliary/ClaudeInstructionRefineService.ts +90 -0
- package/src/providers/claude/auxiliary/ClaudeTitleGenerationService.ts +129 -0
- package/src/providers/claude/auxiliary/extractAssistantText.ts +28 -0
- package/src/providers/claude/capabilities.ts +17 -0
- package/src/providers/claude/cli/findClaudeCLIPath.ts +261 -0
- package/src/providers/claude/commands/ClaudeCommandCatalog.ts +149 -0
- package/src/providers/claude/commands/probeRuntimeCommands.ts +86 -0
- package/src/providers/claude/env/ClaudeSettingsReconciler.ts +90 -0
- package/src/providers/claude/env/claudeModelEnv.ts +86 -0
- package/src/providers/claude/history/ClaudeConversationHistoryService.ts +446 -0
- package/src/providers/claude/history/ClaudeHistoryStore.ts +170 -0
- package/src/providers/claude/history/sdkAsyncSubagent.ts +92 -0
- package/src/providers/claude/history/sdkBranchFilter.ts +271 -0
- package/src/providers/claude/history/sdkHistoryTypes.ts +61 -0
- package/src/providers/claude/history/sdkMessageParsing.ts +413 -0
- package/src/providers/claude/history/sdkSessionPaths.ts +98 -0
- package/src/providers/claude/history/sdkSubagentSidecar.ts +261 -0
- package/src/providers/claude/hooks/SubagentHooks.ts +31 -0
- package/src/providers/claude/modelLabels.ts +77 -0
- package/src/providers/claude/modelOptions.ts +113 -0
- package/src/providers/claude/modelSelection.ts +17 -0
- package/src/providers/claude/plugins/PluginManager.ts +194 -0
- package/src/providers/claude/prompt/ClaudeTurnEncoder.ts +46 -0
- package/src/providers/claude/registration.ts +39 -0
- package/src/providers/claude/runtime/ClaudeApprovalHandler.ts +153 -0
- package/src/providers/claude/runtime/ClaudeChatRuntime.ts +1812 -0
- package/src/providers/claude/runtime/ClaudeCliResolver.ts +94 -0
- package/src/providers/claude/runtime/ClaudeDynamicUpdates.ts +164 -0
- package/src/providers/claude/runtime/ClaudeMessageChannel.ts +209 -0
- package/src/providers/claude/runtime/ClaudeQueryOptionsBuilder.ts +315 -0
- package/src/providers/claude/runtime/ClaudeRewindService.ts +220 -0
- package/src/providers/claude/runtime/ClaudeSessionManager.ts +92 -0
- package/src/providers/claude/runtime/ClaudeTaskResultInterpreter.ts +172 -0
- package/src/providers/claude/runtime/ClaudeUserMessageFactory.ts +83 -0
- package/src/providers/claude/runtime/claudeColdStartQuery.ts +152 -0
- package/src/providers/claude/runtime/customSpawn.ts +87 -0
- package/src/providers/claude/runtime/types.ts +134 -0
- package/src/providers/claude/sdk/messages.ts +17 -0
- package/src/providers/claude/sdk/toolResultContent.ts +4 -0
- package/src/providers/claude/sdk/typeGuards.ts +14 -0
- package/src/providers/claude/sdk/types.ts +15 -0
- package/src/providers/claude/security/ClaudePermissionUpdates.ts +44 -0
- package/src/providers/claude/settings.ts +138 -0
- package/src/providers/claude/storage/AgentVaultStorage.ts +101 -0
- package/src/providers/claude/storage/CCSettingsStorage.ts +153 -0
- package/src/providers/claude/storage/ClaudianSettingsStorage.ts +6 -0
- package/src/providers/claude/storage/McpStorage.ts +139 -0
- package/src/providers/claude/storage/SessionStorage.ts +5 -0
- package/src/providers/claude/storage/SkillStorage.ts +61 -0
- package/src/providers/claude/storage/SlashCommandStorage.ts +96 -0
- package/src/providers/claude/storage/StorageService.ts +185 -0
- package/src/providers/claude/stream/toolInputStreamState.ts +318 -0
- package/src/providers/claude/stream/transformClaudeMessage.ts +586 -0
- package/src/providers/claude/types/agent.ts +2 -0
- package/src/providers/claude/types/models.ts +168 -0
- package/src/providers/claude/types/plugins.ts +14 -0
- package/src/providers/claude/types/providerState.ts +16 -0
- package/src/providers/claude/types/settings.ts +98 -0
- package/src/providers/claude/ui/AgentSettings.ts +389 -0
- package/src/providers/claude/ui/ClaudeChatUIConfig.ts +113 -0
- package/src/providers/claude/ui/ClaudeSettingsTab.ts +407 -0
- package/src/providers/claude/ui/PluginSettingsManager.ts +149 -0
- package/src/providers/claude/ui/SlashCommandSettings.ts +527 -0
- package/src/providers/codex/CLAUDE.md +64 -0
- package/src/providers/codex/agents/CodexAgentMentionProvider.ts +33 -0
- package/src/providers/codex/app/CodexWorkspaceServices.ts +76 -0
- package/src/providers/codex/auxiliary/CodexInlineEditService.ts +9 -0
- package/src/providers/codex/auxiliary/CodexInstructionRefineService.ts +9 -0
- package/src/providers/codex/auxiliary/CodexTaskResultInterpreter.ts +29 -0
- package/src/providers/codex/auxiliary/CodexTitleGenerationService.ts +22 -0
- package/src/providers/codex/capabilities.ts +16 -0
- package/src/providers/codex/commands/CodexSkillCatalog.ts +180 -0
- package/src/providers/codex/env/CodexSettingsReconciler.ts +68 -0
- package/src/providers/codex/history/CodexConversationHistoryService.ts +212 -0
- package/src/providers/codex/history/CodexHistoryStore.ts +1672 -0
- package/src/providers/codex/modelOptions.ts +99 -0
- package/src/providers/codex/modelSelection.ts +17 -0
- package/src/providers/codex/normalization/codexSubagentNormalization.ts +227 -0
- package/src/providers/codex/normalization/codexToolNormalization.ts +390 -0
- package/src/providers/codex/prompt/encodeCodexTurn.ts +57 -0
- package/src/providers/codex/registration.ts +29 -0
- package/src/providers/codex/runtime/CodexAppServerProcess.ts +105 -0
- package/src/providers/codex/runtime/CodexAuxQueryRunner.ts +180 -0
- package/src/providers/codex/runtime/CodexBinaryLocator.ts +49 -0
- package/src/providers/codex/runtime/CodexChatRuntime.ts +1296 -0
- package/src/providers/codex/runtime/CodexCliResolver.ts +65 -0
- package/src/providers/codex/runtime/CodexExecutionTargetResolver.ts +104 -0
- package/src/providers/codex/runtime/CodexLaunchSpecBuilder.ts +85 -0
- package/src/providers/codex/runtime/CodexNotificationRouter.ts +1033 -0
- package/src/providers/codex/runtime/CodexPathMapper.ts +155 -0
- package/src/providers/codex/runtime/CodexRpcTransport.ts +171 -0
- package/src/providers/codex/runtime/CodexRuntimeContext.ts +109 -0
- package/src/providers/codex/runtime/CodexServerRequestRouter.ts +331 -0
- package/src/providers/codex/runtime/CodexSessionFileTail.ts +792 -0
- package/src/providers/codex/runtime/CodexSessionManager.ts +39 -0
- package/src/providers/codex/runtime/codexAppServerSupport.ts +58 -0
- package/src/providers/codex/runtime/codexAppServerTypes.ts +705 -0
- package/src/providers/codex/runtime/codexLaunchTypes.ts +30 -0
- package/src/providers/codex/settings.ts +236 -0
- package/src/providers/codex/skills/CodexSkillListingService.ts +173 -0
- package/src/providers/codex/storage/CodexSkillStorage.ts +250 -0
- package/src/providers/codex/storage/CodexSubagentStorage.ts +212 -0
- package/src/providers/codex/types/index.ts +16 -0
- package/src/providers/codex/types/models.ts +46 -0
- package/src/providers/codex/types/subagent.ts +23 -0
- package/src/providers/codex/ui/CodexChatUIConfig.ts +128 -0
- package/src/providers/codex/ui/CodexSettingsTab.ts +432 -0
- package/src/providers/codex/ui/CodexSkillSettings.ts +275 -0
- package/src/providers/codex/ui/CodexSubagentSettings.ts +400 -0
- package/src/providers/defaultProviderConfigs.ts +14 -0
- package/src/providers/index.ts +30 -0
- package/src/providers/opencode/agents/OpencodeAgentMentionProvider.ts +42 -0
- package/src/providers/opencode/app/OpencodeRuntimeCommandLoader.ts +67 -0
- package/src/providers/opencode/app/OpencodeWorkspaceServices.ts +55 -0
- package/src/providers/opencode/auxiliary/OpencodeInlineEditService.ts +13 -0
- package/src/providers/opencode/auxiliary/OpencodeInstructionRefineService.ts +12 -0
- package/src/providers/opencode/auxiliary/OpencodeTaskResultInterpreter.ts +29 -0
- package/src/providers/opencode/auxiliary/OpencodeTitleGenerationService.ts +27 -0
- package/src/providers/opencode/capabilities.ts +16 -0
- package/src/providers/opencode/commands/OpencodeCommandCatalog.ts +92 -0
- package/src/providers/opencode/discoveryState.ts +135 -0
- package/src/providers/opencode/env/OpencodeSettingsReconciler.ts +178 -0
- package/src/providers/opencode/history/OpencodeConversationHistoryService.ts +84 -0
- package/src/providers/opencode/history/OpencodeHistoryStore.ts +472 -0
- package/src/providers/opencode/history/OpencodeSqliteReader.ts +284 -0
- package/src/providers/opencode/internal/compareCollections.ts +72 -0
- package/src/providers/opencode/internal/providerProjection.ts +15 -0
- package/src/providers/opencode/models.ts +378 -0
- package/src/providers/opencode/modes.ts +150 -0
- package/src/providers/opencode/normalization/opencodeToolNormalization.ts +406 -0
- package/src/providers/opencode/registration.ts +27 -0
- package/src/providers/opencode/runtime/OpencodeAuxQueryRunner.ts +436 -0
- package/src/providers/opencode/runtime/OpencodeChatRuntime.ts +1603 -0
- package/src/providers/opencode/runtime/OpencodeCliResolver.ts +57 -0
- package/src/providers/opencode/runtime/OpencodeLaunchArtifacts.ts +231 -0
- package/src/providers/opencode/runtime/OpencodePaths.ts +113 -0
- package/src/providers/opencode/runtime/OpencodeRuntimeEnvironment.ts +18 -0
- package/src/providers/opencode/runtime/buildOpencodePrompt.ts +66 -0
- package/src/providers/opencode/settings.ts +427 -0
- package/src/providers/opencode/storage/OpencodeAgentStorage.ts +346 -0
- package/src/providers/opencode/types/agent.ts +37 -0
- package/src/providers/opencode/types/index.ts +9 -0
- package/src/providers/opencode/ui/OpencodeAgentSettings.ts +579 -0
- package/src/providers/opencode/ui/OpencodeChatUIConfig.ts +316 -0
- package/src/providers/opencode/ui/OpencodeSettingsTab.ts +674 -0
- package/src/providers/pi/app/PiRuntimeCommandLoader.ts +57 -0
- package/src/providers/pi/app/PiWorkspaceServices.ts +39 -0
- package/src/providers/pi/auxiliary/PiInlineEditService.ts +9 -0
- package/src/providers/pi/auxiliary/PiInstructionRefineService.ts +9 -0
- package/src/providers/pi/auxiliary/PiTaskResultInterpreter.ts +29 -0
- package/src/providers/pi/auxiliary/PiTitleGenerationService.ts +19 -0
- package/src/providers/pi/capabilities.ts +16 -0
- package/src/providers/pi/commands/PiCommandCatalog.ts +92 -0
- package/src/providers/pi/env/PiSettingsReconciler.ts +180 -0
- package/src/providers/pi/history/PiConversationHistoryService.ts +123 -0
- package/src/providers/pi/history/PiHistoryStore.ts +664 -0
- package/src/providers/pi/internal/compareCollections.ts +4 -0
- package/src/providers/pi/internal/providerProjection.ts +18 -0
- package/src/providers/pi/models.ts +302 -0
- package/src/providers/pi/normalizations/piEventNormalization.ts +211 -0
- package/src/providers/pi/normalizations/piToolNormalization.ts +97 -0
- package/src/providers/pi/registration.ts +30 -0
- package/src/providers/pi/runtime/PiAuxQueryRunner.ts +216 -0
- package/src/providers/pi/runtime/PiChatRuntime.ts +1064 -0
- package/src/providers/pi/runtime/PiCliResolver.ts +53 -0
- package/src/providers/pi/runtime/PiExtensionUiBridge.ts +161 -0
- package/src/providers/pi/runtime/PiJsonl.ts +71 -0
- package/src/providers/pi/runtime/PiLaunchSpec.ts +70 -0
- package/src/providers/pi/runtime/PiModelDiscoveryService.ts +92 -0
- package/src/providers/pi/runtime/PiRpcPayloads.ts +18 -0
- package/src/providers/pi/runtime/PiRpcTransport.ts +243 -0
- package/src/providers/pi/runtime/PiSubprocess.ts +159 -0
- package/src/providers/pi/runtime/buildPiPrompt.ts +62 -0
- package/src/providers/pi/runtime/buildPiUsageInfo.ts +69 -0
- package/src/providers/pi/settings.ts +468 -0
- package/src/providers/pi/types.ts +64 -0
- package/src/providers/pi/ui/ObsidianPiExtensionUiRenderer.ts +251 -0
- package/src/providers/pi/ui/PiChatUIConfig.ts +265 -0
- package/src/providers/pi/ui/PiExtensionUiRenderer.ts +12 -0
- package/src/providers/pi/ui/PiSettingsTab.ts +642 -0
- package/src/shared/components/ResumeSessionDropdown.ts +185 -0
- package/src/shared/components/SelectableDropdown.ts +140 -0
- package/src/shared/components/SelectionHighlight.ts +77 -0
- package/src/shared/components/SlashCommandDropdown.ts +421 -0
- package/src/shared/icons.ts +180 -0
- package/src/shared/mention/MentionDropdownController.ts +627 -0
- package/src/shared/mention/VaultMentionCache.ts +106 -0
- package/src/shared/mention/VaultMentionDataProvider.ts +51 -0
- package/src/shared/mention/types.ts +67 -0
- package/src/shared/modals/ConfirmModal.ts +60 -0
- package/src/shared/modals/ForkTargetModal.ts +47 -0
- package/src/shared/modals/InstructionConfirmModal.ts +281 -0
- package/src/style/CLAUDE.md +49 -0
- package/src/style/accessibility.css +40 -0
- package/src/style/base/animations.css +44 -0
- package/src/style/base/container.css +20 -0
- package/src/style/base/variables.css +46 -0
- package/src/style/base/visibility.css +15 -0
- package/src/style/components/code.css +97 -0
- package/src/style/components/context-footer.css +76 -0
- package/src/style/components/header.css +27 -0
- package/src/style/components/history.css +221 -0
- package/src/style/components/input.css +312 -0
- package/src/style/components/messages.css +262 -0
- package/src/style/components/nav-sidebar.css +58 -0
- package/src/style/components/status-panel.css +202 -0
- package/src/style/components/subagent.css +248 -0
- package/src/style/components/tabs.css +112 -0
- package/src/style/components/thinking.css +88 -0
- package/src/style/components/toolcalls.css +278 -0
- package/src/style/features/ask-user-question.css +315 -0
- package/src/style/features/diff.css +197 -0
- package/src/style/features/file-context.css +188 -0
- package/src/style/features/file-link.css +22 -0
- package/src/style/features/image-context.css +179 -0
- package/src/style/features/image-embed.css +40 -0
- package/src/style/features/image-modal.css +52 -0
- package/src/style/features/inline-edit.css +278 -0
- package/src/style/features/plan-mode.css +103 -0
- package/src/style/features/resume-session.css +119 -0
- package/src/style/features/slash-commands.css +91 -0
- package/src/style/index.css +63 -0
- package/src/style/modals/fork-target.css +21 -0
- package/src/style/modals/instruction.css +161 -0
- package/src/style/modals/mcp-modal.css +241 -0
- package/src/style/settings/agent-settings.css +2 -0
- package/src/style/settings/base.css +300 -0
- package/src/style/settings/env-snippets.css +366 -0
- package/src/style/settings/mcp-settings.css +211 -0
- package/src/style/settings/plugin-settings.css +164 -0
- package/src/style/settings/provider-model-picker.css +367 -0
- package/src/style/settings/slash-settings.css +16 -0
- package/src/style/toolbar/external-context.css +177 -0
- package/src/style/toolbar/mcp-selector.css +176 -0
- package/src/style/toolbar/mode-selector.css +19 -0
- package/src/style/toolbar/model-selector.css +99 -0
- package/src/style/toolbar/permission-toggle.css +56 -0
- package/src/style/toolbar/service-tier-toggle.css +39 -0
- package/src/style/toolbar/thinking-selector.css +83 -0
- package/src/types/smol-toml.d.ts +4 -0
- package/src/utils/agent.ts +50 -0
- package/src/utils/animationFrame.ts +46 -0
- package/src/utils/browser.ts +46 -0
- package/src/utils/canvas.ts +14 -0
- package/src/utils/cliBinaryLocator.ts +97 -0
- package/src/utils/context.ts +117 -0
- package/src/utils/contextMentionResolver.ts +154 -0
- package/src/utils/date.ts +31 -0
- package/src/utils/diff.ts +384 -0
- package/src/utils/editor.ts +104 -0
- package/src/utils/electronCompat.ts +53 -0
- package/src/utils/env.ts +465 -0
- package/src/utils/externalContext.ts +143 -0
- package/src/utils/externalContextScanner.ts +135 -0
- package/src/utils/fileLink.ts +263 -0
- package/src/utils/frontmatter.ts +194 -0
- package/src/utils/imageEmbed.ts +139 -0
- package/src/utils/inlineEdit.ts +22 -0
- package/src/utils/interrupt.ts +23 -0
- package/src/utils/markdown.ts +25 -0
- package/src/utils/markdownMath.ts +130 -0
- package/src/utils/mcp.ts +96 -0
- package/src/utils/obsidianCompat.ts +23 -0
- package/src/utils/path.ts +342 -0
- package/src/utils/session.ts +240 -0
- package/src/utils/slashCommand.ts +152 -0
- package/src/utils/subagentJsonl.ts +52 -0
- package/src/utils/windowsCmdShim.ts +98 -0
- package/tests/__mocks__/claude-agent-sdk.ts +317 -0
- package/tests/__mocks__/codex-sdk.ts +88 -0
- package/tests/__mocks__/obsidian.ts +434 -0
- package/tests/helpers/mockElement.ts +403 -0
- package/tests/helpers/sdkMessages.ts +291 -0
- package/tests/integration/core/agent/ClaudianService.test.ts +1845 -0
- package/tests/integration/core/mcp/mcp.test.ts +905 -0
- package/tests/integration/features/chat/imagePersistence.test.ts +38 -0
- package/tests/integration/main.test.ts +1701 -0
- package/tests/setupWindow.ts +26 -0
- package/tests/tsconfig.json +7 -0
- package/tests/unit/core/commands/builtInCommands.test.ts +239 -0
- package/tests/unit/core/mcp/McpServerManager.test.ts +405 -0
- package/tests/unit/core/mcp/McpTester.test.ts +282 -0
- package/tests/unit/core/mcp/createNodeFetch.test.ts +188 -0
- package/tests/unit/core/providers/ProviderRegistry.test.ts +275 -0
- package/tests/unit/core/providers/ProviderSettingsCoordinator.test.ts +490 -0
- package/tests/unit/core/providers/ProviderWorkspaceRegistry.test.ts +84 -0
- package/tests/unit/core/providers/modelRouting.test.ts +91 -0
- package/tests/unit/core/providers/modelSelection.test.ts +155 -0
- package/tests/unit/core/providers/providerEnvironment.test.ts +162 -0
- package/tests/unit/core/providers/tabLifecycle.test.ts +217 -0
- package/tests/unit/core/security/ApprovalManager.test.ts +152 -0
- package/tests/unit/core/storage/VaultFileAdapter.test.ts +535 -0
- package/tests/unit/core/tools/todo.test.ts +227 -0
- package/tests/unit/core/tools/toolIcons.test.ts +75 -0
- package/tests/unit/core/tools/toolInput.test.ts +350 -0
- package/tests/unit/core/tools/toolNames.test.ts +464 -0
- package/tests/unit/core/types/mcp.test.ts +115 -0
- package/tests/unit/features/chat/ClaudianView.test.ts +404 -0
- package/tests/unit/features/chat/controllers/BrowserSelectionController.test.ts +179 -0
- package/tests/unit/features/chat/controllers/CanvasSelectionController.test.ts +216 -0
- package/tests/unit/features/chat/controllers/ConversationController.test.ts +2764 -0
- package/tests/unit/features/chat/controllers/InputController.test.ts +3188 -0
- package/tests/unit/features/chat/controllers/NavigationController.test.ts +640 -0
- package/tests/unit/features/chat/controllers/SelectionController.test.ts +695 -0
- package/tests/unit/features/chat/controllers/StreamController.test.ts +2534 -0
- package/tests/unit/features/chat/controllers/contextRowVisibility.test.ts +46 -0
- package/tests/unit/features/chat/controllers/index.test.ts +16 -0
- package/tests/unit/features/chat/rendering/DiffRenderer.test.ts +355 -0
- package/tests/unit/features/chat/rendering/InlineAskUserQuestion.test.ts +1035 -0
- package/tests/unit/features/chat/rendering/InlineExitPlanMode.test.ts +191 -0
- package/tests/unit/features/chat/rendering/InlinePlanApproval.test.ts +126 -0
- package/tests/unit/features/chat/rendering/MessageRenderer.test.ts +2004 -0
- package/tests/unit/features/chat/rendering/SubagentRenderer.test.ts +917 -0
- package/tests/unit/features/chat/rendering/ThinkingBlockRenderer.test.ts +124 -0
- package/tests/unit/features/chat/rendering/TodoListRenderer.test.ts +173 -0
- package/tests/unit/features/chat/rendering/ToolCallRenderer.test.ts +909 -0
- package/tests/unit/features/chat/rendering/WriteEditRenderer.test.ts +474 -0
- package/tests/unit/features/chat/rendering/collapsible.test.ts +158 -0
- package/tests/unit/features/chat/rendering/todoUtils.test.ts +105 -0
- package/tests/unit/features/chat/rewind.test.ts +56 -0
- package/tests/unit/features/chat/services/BangBashService.test.ts +142 -0
- package/tests/unit/features/chat/services/InstructionRefineService.test.ts +371 -0
- package/tests/unit/features/chat/services/SubagentManager.test.ts +1759 -0
- package/tests/unit/features/chat/services/TitleGenerationService.test.ts +480 -0
- package/tests/unit/features/chat/state/ChatState.test.ts +581 -0
- package/tests/unit/features/chat/tabs/Tab.test.ts +4287 -0
- package/tests/unit/features/chat/tabs/TabBar.test.ts +357 -0
- package/tests/unit/features/chat/tabs/TabManager.test.ts +2962 -0
- package/tests/unit/features/chat/tabs/index.test.ts +11 -0
- package/tests/unit/features/chat/ui/BangBashModeManager.test.ts +321 -0
- package/tests/unit/features/chat/ui/ExternalContextSelector.test.ts +555 -0
- package/tests/unit/features/chat/ui/FileContextManager.test.ts +876 -0
- package/tests/unit/features/chat/ui/ImageContext.test.ts +777 -0
- package/tests/unit/features/chat/ui/InputToolbar.test.ts +1139 -0
- package/tests/unit/features/chat/ui/InstructionModeManager.test.ts +243 -0
- package/tests/unit/features/chat/ui/NavigationSidebar.test.ts +570 -0
- package/tests/unit/features/chat/ui/StatusPanel.test.ts +953 -0
- package/tests/unit/features/chat/ui/file-context/state/FileContextState.test.ts +155 -0
- package/tests/unit/features/chat/ui/textareaResize.test.ts +102 -0
- package/tests/unit/features/chat/utils/usageInfo.test.ts +56 -0
- package/tests/unit/features/inline-edit/InlineEditService.test.ts +1199 -0
- package/tests/unit/features/inline-edit/ui/InlineEditModal.openAndWait.test.ts +1482 -0
- package/tests/unit/features/inline-edit/ui/InlineEditModal.test.ts +495 -0
- package/tests/unit/features/inline-edit/ui/inlineEditMarkdownPreview.test.ts +92 -0
- package/tests/unit/features/settings/AgentSettings.test.ts +82 -0
- package/tests/unit/features/settings/keyboardNavigation.test.ts +73 -0
- package/tests/unit/features/settings/ui/CodexSkillSettings.test.ts +294 -0
- package/tests/unit/features/settings/ui/CodexSubagentSettings.test.ts +207 -0
- package/tests/unit/i18n/constants.test.ts +43 -0
- package/tests/unit/i18n/i18n.test.ts +244 -0
- package/tests/unit/i18n/locales.test.ts +134 -0
- package/tests/unit/providers/acp/AcpClientConnection.test.ts +248 -0
- package/tests/unit/providers/acp/AcpJsonRpcTransport.test.ts +186 -0
- package/tests/unit/providers/acp/AcpSessionConfig.test.ts +247 -0
- package/tests/unit/providers/acp/AcpSessionUpdateNormalizer.test.ts +145 -0
- package/tests/unit/providers/acp/AcpSubprocess.test.ts +105 -0
- package/tests/unit/providers/acp/buildAcpUsageInfo.test.ts +51 -0
- package/tests/unit/providers/claude/agents/AgentManager.test.ts +590 -0
- package/tests/unit/providers/claude/agents/AgentStorage.test.ts +434 -0
- package/tests/unit/providers/claude/agents/index.test.ts +10 -0
- package/tests/unit/providers/claude/commands/ClaudeCommandCatalog.test.ts +396 -0
- package/tests/unit/providers/claude/commands/probeRuntimeCommands.test.ts +92 -0
- package/tests/unit/providers/claude/env/ClaudeSettingsReconciler.test.ts +57 -0
- package/tests/unit/providers/claude/env/claudeModelEnv.test.ts +228 -0
- package/tests/unit/providers/claude/hooks/SubagentHooks.test.ts +83 -0
- package/tests/unit/providers/claude/plugins/PluginManager.test.ts +832 -0
- package/tests/unit/providers/claude/plugins/index.test.ts +7 -0
- package/tests/unit/providers/claude/prompt/ClaudeTurnEncoder.test.ts +145 -0
- package/tests/unit/providers/claude/prompt/instructionRefine.test.ts +185 -0
- package/tests/unit/providers/claude/prompt/systemPrompt.test.ts +163 -0
- package/tests/unit/providers/claude/prompt/titleGeneration.test.ts +20 -0
- package/tests/unit/providers/claude/runtime/ClaudeTaskResultInterpreter.test.ts +28 -0
- package/tests/unit/providers/claude/runtime/ClaudianService.test.ts +3796 -0
- package/tests/unit/providers/claude/runtime/MessageChannel.test.ts +421 -0
- package/tests/unit/providers/claude/runtime/QueryOptionsBuilder.test.ts +775 -0
- package/tests/unit/providers/claude/runtime/SessionManager.test.ts +182 -0
- package/tests/unit/providers/claude/runtime/claudeColdStartQuery.test.ts +331 -0
- package/tests/unit/providers/claude/runtime/customSpawn.test.ts +374 -0
- package/tests/unit/providers/claude/runtime/index.test.ts +13 -0
- package/tests/unit/providers/claude/runtime/types.test.ts +190 -0
- package/tests/unit/providers/claude/sdk/typeGuards.test.ts +50 -0
- package/tests/unit/providers/claude/security/ClaudePermissionUpdates.test.ts +198 -0
- package/tests/unit/providers/claude/storage/AgentVaultStorage.test.ts +413 -0
- package/tests/unit/providers/claude/storage/CCSettingsStorage.test.ts +408 -0
- package/tests/unit/providers/claude/storage/ClaudianSettingsStorage.test.ts +653 -0
- package/tests/unit/providers/claude/storage/McpStorage.test.ts +619 -0
- package/tests/unit/providers/claude/storage/SessionStorage.test.ts +680 -0
- package/tests/unit/providers/claude/storage/SkillStorage.test.ts +275 -0
- package/tests/unit/providers/claude/storage/SlashCommandStorage.test.ts +612 -0
- package/tests/unit/providers/claude/storage/storage.test.ts +360 -0
- package/tests/unit/providers/claude/storage/storageService.convenience.test.ts +447 -0
- package/tests/unit/providers/claude/stream/transformSDKMessage.test.ts +1729 -0
- package/tests/unit/providers/claude/types/types.test.ts +726 -0
- package/tests/unit/providers/claude/ui/ClaudeChatUIConfig.test.ts +173 -0
- package/tests/unit/providers/claude/ui/ClaudeSettingsTab.test.ts +466 -0
- package/tests/unit/providers/codex/agents/CodexAgentMentionProvider.test.ts +89 -0
- package/tests/unit/providers/codex/auxiliary/CodexInstructionRefineService.test.ts +81 -0
- package/tests/unit/providers/codex/capabilities.test.ts +39 -0
- package/tests/unit/providers/codex/commands/CodexSkillCatalog.test.ts +413 -0
- package/tests/unit/providers/codex/env/CodexSettingsReconciler.test.ts +106 -0
- package/tests/unit/providers/codex/fixtures/codex-session-abort.jsonl +9 -0
- package/tests/unit/providers/codex/fixtures/codex-session-agent-lifecycle.jsonl +12 -0
- package/tests/unit/providers/codex/fixtures/codex-session-persisted-tools.jsonl +15 -0
- package/tests/unit/providers/codex/fixtures/codex-session-simple.jsonl +10 -0
- package/tests/unit/providers/codex/fixtures/codex-session-tools.jsonl +12 -0
- package/tests/unit/providers/codex/fixtures/codex-session-websearch-persisted.jsonl +3 -0
- package/tests/unit/providers/codex/fixtures/codex-session-websearch.jsonl +7 -0
- package/tests/unit/providers/codex/history/CodexConversationHistoryService.test.ts +690 -0
- package/tests/unit/providers/codex/history/CodexHistoryStore.test.ts +2202 -0
- package/tests/unit/providers/codex/normalization/codexSubagentNormalization.test.ts +81 -0
- package/tests/unit/providers/codex/normalization/codexToolNormalization.test.ts +322 -0
- package/tests/unit/providers/codex/prompt/encodeCodexTurn.test.ts +168 -0
- package/tests/unit/providers/codex/runtime/CodexAppServerProcess.test.ts +255 -0
- package/tests/unit/providers/codex/runtime/CodexAuxQueryRunner.test.ts +130 -0
- package/tests/unit/providers/codex/runtime/CodexBinaryLocator.test.ts +90 -0
- package/tests/unit/providers/codex/runtime/CodexChatRuntime.test.ts +2445 -0
- package/tests/unit/providers/codex/runtime/CodexCliResolver.test.ts +103 -0
- package/tests/unit/providers/codex/runtime/CodexExecutionTargetResolver.test.ts +105 -0
- package/tests/unit/providers/codex/runtime/CodexLaunchSpecBuilder.test.ts +150 -0
- package/tests/unit/providers/codex/runtime/CodexNotificationRouter.test.ts +1248 -0
- package/tests/unit/providers/codex/runtime/CodexPathMapper.test.ts +51 -0
- package/tests/unit/providers/codex/runtime/CodexRpcTransport.test.ts +220 -0
- package/tests/unit/providers/codex/runtime/CodexRuntimeContext.test.ts +107 -0
- package/tests/unit/providers/codex/runtime/CodexServerRequestRouter.test.ts +537 -0
- package/tests/unit/providers/codex/runtime/CodexSessionFileTail.test.ts +1305 -0
- package/tests/unit/providers/codex/runtime/CodexSessionManager.test.ts +82 -0
- package/tests/unit/providers/codex/runtime/codexAppServerTypes.test.ts +336 -0
- package/tests/unit/providers/codex/settings.test.ts +189 -0
- package/tests/unit/providers/codex/skills/CodexSkillListingService.test.ts +178 -0
- package/tests/unit/providers/codex/storage/CodexSkillStorage.test.ts +342 -0
- package/tests/unit/providers/codex/storage/CodexSubagentStorage.test.ts +376 -0
- package/tests/unit/providers/codex/ui/CodexChatUIConfig.test.ts +211 -0
- package/tests/unit/providers/codex/ui/CodexSettingsTab.test.ts +578 -0
- package/tests/unit/providers/defaultProviderConfigs.test.ts +18 -0
- package/tests/unit/providers/opencode/OpencodeAuxQueryRunner.test.ts +355 -0
- package/tests/unit/providers/opencode/OpencodeChatRuntime.test.ts +808 -0
- package/tests/unit/providers/opencode/OpencodeCliResolver.test.ts +93 -0
- package/tests/unit/providers/opencode/OpencodeCommandCatalog.test.ts +75 -0
- package/tests/unit/providers/opencode/OpencodeConversationHistoryService.test.ts +103 -0
- package/tests/unit/providers/opencode/OpencodeHistoryStore.test.ts +418 -0
- package/tests/unit/providers/opencode/OpencodeLaunchArtifacts.test.ts +268 -0
- package/tests/unit/providers/opencode/OpencodePaths.test.ts +35 -0
- package/tests/unit/providers/opencode/OpencodeRuntimeCommandLoader.test.ts +129 -0
- package/tests/unit/providers/opencode/OpencodeSettingsReconciler.test.ts +96 -0
- package/tests/unit/providers/opencode/OpencodeSettingsTab.test.ts +649 -0
- package/tests/unit/providers/opencode/OpencodeSqliteReader.test.ts +185 -0
- package/tests/unit/providers/opencode/agents/OpencodeAgentMentionProvider.test.ts +56 -0
- package/tests/unit/providers/opencode/buildOpencodePrompt.test.ts +87 -0
- package/tests/unit/providers/opencode/capabilities.test.ts +39 -0
- package/tests/unit/providers/opencode/models.test.ts +273 -0
- package/tests/unit/providers/opencode/modes.test.ts +151 -0
- package/tests/unit/providers/opencode/opencodeToolNormalization.test.ts +197 -0
- package/tests/unit/providers/opencode/settings.test.ts +469 -0
- package/tests/unit/providers/opencode/storage/OpencodeAgentStorage.test.ts +377 -0
- package/tests/unit/providers/opencode/ui/OpencodeAgentSettings.test.ts +91 -0
- package/tests/unit/providers/pi/PiRuntimeCommandLoader.test.ts +149 -0
- package/tests/unit/providers/pi/capabilities.test.ts +20 -0
- package/tests/unit/providers/pi/commands/PiCommandCatalog.test.ts +69 -0
- package/tests/unit/providers/pi/env/PiSettingsReconciler.test.ts +61 -0
- package/tests/unit/providers/pi/history/PiConversationHistoryService.test.ts +147 -0
- package/tests/unit/providers/pi/history/PiHistoryStore.test.ts +523 -0
- package/tests/unit/providers/pi/models.test.ts +96 -0
- package/tests/unit/providers/pi/registration.test.ts +54 -0
- package/tests/unit/providers/pi/runtime/PiAuxQueryRunner.test.ts +172 -0
- package/tests/unit/providers/pi/runtime/PiChatRuntime.test.ts +830 -0
- package/tests/unit/providers/pi/runtime/PiCliResolver.test.ts +105 -0
- package/tests/unit/providers/pi/runtime/PiEventNormalization.test.ts +147 -0
- package/tests/unit/providers/pi/runtime/PiExtensionUiBridge.test.ts +98 -0
- package/tests/unit/providers/pi/runtime/PiJsonl.test.ts +42 -0
- package/tests/unit/providers/pi/runtime/PiLaunchSpec.test.ts +92 -0
- package/tests/unit/providers/pi/runtime/PiModelDiscoveryService.test.ts +135 -0
- package/tests/unit/providers/pi/runtime/PiRpcPayloads.test.ts +15 -0
- package/tests/unit/providers/pi/runtime/PiRpcTransport.test.ts +116 -0
- package/tests/unit/providers/pi/runtime/PiSubprocess.test.ts +151 -0
- package/tests/unit/providers/pi/runtime/buildPiPrompt.test.ts +84 -0
- package/tests/unit/providers/pi/runtime/buildPiUsageInfo.test.ts +69 -0
- package/tests/unit/providers/pi/settings.test.ts +253 -0
- package/tests/unit/providers/pi/ui/PiChatUIConfig.test.ts +161 -0
- package/tests/unit/providers/pi/ui/PiSettingsTab.test.ts +492 -0
- package/tests/unit/scripts/rendererSafeUnref.test.ts +101 -0
- package/tests/unit/shared/components/ResumeSessionDropdown.test.ts +356 -0
- package/tests/unit/shared/components/SelectableDropdown.test.ts +406 -0
- package/tests/unit/shared/components/SlashCommandDropdown.provider.test.ts +354 -0
- package/tests/unit/shared/components/SlashCommandDropdown.test.ts +508 -0
- package/tests/unit/shared/icons.test.ts +56 -0
- package/tests/unit/shared/index.test.ts +46 -0
- package/tests/unit/shared/mention/MentionDropdownController.test.ts +823 -0
- package/tests/unit/shared/mention/VaultFileCache.test.ts +195 -0
- package/tests/unit/shared/mention/VaultFolderCache.test.ts +143 -0
- package/tests/unit/shared/mention/VaultMentionDataProvider.test.ts +87 -0
- package/tests/unit/shared/modals/ConfirmModal.test.ts +111 -0
- package/tests/unit/shared/modals/ForkTargetModal.test.ts +101 -0
- package/tests/unit/shared/modals/InstructionConfirmModal.test.ts +305 -0
- package/tests/unit/utils/agent.test.ts +395 -0
- package/tests/unit/utils/animationFrame.test.ts +59 -0
- package/tests/unit/utils/browser.test.ts +73 -0
- package/tests/unit/utils/canvas.test.ts +54 -0
- package/tests/unit/utils/claudeCli.test.ts +294 -0
- package/tests/unit/utils/cliBinaryLocator.test.ts +33 -0
- package/tests/unit/utils/context.test.ts +288 -0
- package/tests/unit/utils/contextMentionResolver.test.ts +270 -0
- package/tests/unit/utils/date.test.ts +80 -0
- package/tests/unit/utils/diff.test.ts +291 -0
- package/tests/unit/utils/editor.test.ts +249 -0
- package/tests/unit/utils/electronCompat.test.ts +87 -0
- package/tests/unit/utils/env.test.ts +1240 -0
- package/tests/unit/utils/externalContext.test.ts +336 -0
- package/tests/unit/utils/externalContextScanner.test.ts +186 -0
- package/tests/unit/utils/fileLink.dom.test.ts +273 -0
- package/tests/unit/utils/fileLink.handler.test.ts +64 -0
- package/tests/unit/utils/fileLink.test.ts +233 -0
- package/tests/unit/utils/frontmatter.test.ts +434 -0
- package/tests/unit/utils/imageEmbed.test.ts +407 -0
- package/tests/unit/utils/inlineEdit.test.ts +63 -0
- package/tests/unit/utils/interrupt.test.ts +73 -0
- package/tests/unit/utils/markdown.test.ts +35 -0
- package/tests/unit/utils/markdownMath.test.ts +54 -0
- package/tests/unit/utils/mcp.test.ts +256 -0
- package/tests/unit/utils/obsidianCompat.test.ts +18 -0
- package/tests/unit/utils/path.test.ts +677 -0
- package/tests/unit/utils/sdkSession.test.ts +2359 -0
- package/tests/unit/utils/session.test.ts +971 -0
- package/tests/unit/utils/slashCommand.test.ts +778 -0
- package/tests/unit/utils/utils.test.ts +809 -0
- package/tsconfig.jest.json +8 -0
- package/tsconfig.json +26 -0
- package/versions.json +4 -0
|
@@ -0,0 +1,907 @@
|
|
|
1
|
+
import type { App, Component } from 'obsidian';
|
|
2
|
+
import { MarkdownRenderer, Menu, Notice, setIcon } from 'obsidian';
|
|
3
|
+
|
|
4
|
+
import { DEFAULT_CHAT_PROVIDER_ID, type ProviderCapabilities } from '../../../core/providers/types';
|
|
5
|
+
import type { ChatRewindMode } from '../../../core/runtime/types';
|
|
6
|
+
import {
|
|
7
|
+
isSubagentToolName,
|
|
8
|
+
isWriteEditTool,
|
|
9
|
+
TOOL_AGENT_OUTPUT,
|
|
10
|
+
TOOL_APPLY_PATCH,
|
|
11
|
+
TOOL_WRITE_STDIN,
|
|
12
|
+
} from '../../../core/tools/toolNames';
|
|
13
|
+
import { extractToolResultContent } from '../../../core/tools/toolResultContent';
|
|
14
|
+
import type { ChatMessage, ImageAttachment, SubagentInfo, ToolCallInfo } from '../../../core/types';
|
|
15
|
+
import { t } from '../../../i18n/i18n';
|
|
16
|
+
import type ClaudianPlugin from '../../../main';
|
|
17
|
+
import { extractUserDisplayContent } from '../../../utils/context';
|
|
18
|
+
import { formatDurationMmSs } from '../../../utils/date';
|
|
19
|
+
import { processFileLinks, registerFileLinkHandler } from '../../../utils/fileLink';
|
|
20
|
+
import { replaceImageEmbedsWithHtml } from '../../../utils/imageEmbed';
|
|
21
|
+
import { escapeMathDelimitersForStreaming } from '../../../utils/markdownMath';
|
|
22
|
+
import { findRewindContext } from '../rewind';
|
|
23
|
+
import { resolveSubagentLifecycleAdapter } from './subagentLifecycleResolution';
|
|
24
|
+
import {
|
|
25
|
+
renderStoredAsyncSubagent,
|
|
26
|
+
renderStoredSubagent,
|
|
27
|
+
} from './SubagentRenderer';
|
|
28
|
+
import { renderStoredThinkingBlock } from './ThinkingBlockRenderer';
|
|
29
|
+
import { renderStoredToolCall } from './ToolCallRenderer';
|
|
30
|
+
import { renderStoredWriteEdit } from './WriteEditRenderer';
|
|
31
|
+
|
|
32
|
+
export interface RenderContentOptions {
|
|
33
|
+
deferMath?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type RenderContentFn = (
|
|
37
|
+
el: HTMLElement,
|
|
38
|
+
markdown: string,
|
|
39
|
+
options?: RenderContentOptions
|
|
40
|
+
) => Promise<void>;
|
|
41
|
+
|
|
42
|
+
function runRendererAction(action: () => Promise<void>): void {
|
|
43
|
+
void action().catch(() => {
|
|
44
|
+
// UI actions already surface expected failures locally.
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class MessageRenderer {
|
|
49
|
+
private app: App;
|
|
50
|
+
private plugin: ClaudianPlugin;
|
|
51
|
+
private component: Component;
|
|
52
|
+
private messagesEl: HTMLElement;
|
|
53
|
+
private rewindCallback?: (messageId: string, mode?: ChatRewindMode) => Promise<void>;
|
|
54
|
+
private getCapabilities: () => ProviderCapabilities;
|
|
55
|
+
private forkCallback?: (messageId: string) => Promise<void>;
|
|
56
|
+
private liveMessageEls = new Map<string, HTMLElement>();
|
|
57
|
+
|
|
58
|
+
constructor(
|
|
59
|
+
plugin: ClaudianPlugin,
|
|
60
|
+
component: Component,
|
|
61
|
+
messagesEl: HTMLElement,
|
|
62
|
+
rewindCallback?: (messageId: string, mode?: ChatRewindMode) => Promise<void>,
|
|
63
|
+
forkCallback?: (messageId: string) => Promise<void>,
|
|
64
|
+
getCapabilities?: () => ProviderCapabilities,
|
|
65
|
+
) {
|
|
66
|
+
this.app = plugin.app;
|
|
67
|
+
this.plugin = plugin;
|
|
68
|
+
this.component = component;
|
|
69
|
+
this.messagesEl = messagesEl;
|
|
70
|
+
this.rewindCallback = rewindCallback;
|
|
71
|
+
this.forkCallback = forkCallback;
|
|
72
|
+
this.getCapabilities = getCapabilities ?? (() => ({
|
|
73
|
+
providerId: DEFAULT_CHAT_PROVIDER_ID,
|
|
74
|
+
supportsPersistentRuntime: false,
|
|
75
|
+
supportsNativeHistory: false,
|
|
76
|
+
supportsPlanMode: false,
|
|
77
|
+
supportsRewind: false,
|
|
78
|
+
supportsFork: false,
|
|
79
|
+
supportsProviderCommands: false,
|
|
80
|
+
supportsImageAttachments: false,
|
|
81
|
+
supportsInstructionMode: false,
|
|
82
|
+
supportsMcpTools: false,
|
|
83
|
+
supportsTurnSteer: false,
|
|
84
|
+
reasoningControl: 'none' as const,
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
// Register delegated click handler for file links
|
|
88
|
+
registerFileLinkHandler(this.app, this.messagesEl, this.component);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Sets the messages container element. */
|
|
92
|
+
setMessagesEl(el: HTMLElement): void {
|
|
93
|
+
this.messagesEl = el;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private getSubagentLifecycleAdapter(toolName?: string) {
|
|
97
|
+
return resolveSubagentLifecycleAdapter(this.getCapabilities().providerId, toolName);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private shouldExpandFileEditsByDefault(): boolean {
|
|
101
|
+
return this.plugin.settings?.expandFileEditsByDefault === true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private getUserMessageTextToShow(msg: ChatMessage): string {
|
|
105
|
+
return msg.displayContent ?? extractUserDisplayContent(msg.content) ?? msg.content;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ============================================
|
|
109
|
+
// Streaming Message Rendering
|
|
110
|
+
// ============================================
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Adds a new message to the chat during streaming.
|
|
114
|
+
* Returns the message element for content updates.
|
|
115
|
+
*/
|
|
116
|
+
addMessage(msg: ChatMessage): HTMLElement {
|
|
117
|
+
// Render images above message bubble for user messages
|
|
118
|
+
if (msg.role === 'user' && msg.images && msg.images.length > 0) {
|
|
119
|
+
this.renderMessageImages(this.messagesEl, msg.images);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Skip empty bubble for image-only messages
|
|
123
|
+
if (msg.role === 'user') {
|
|
124
|
+
const textToShow = this.getUserMessageTextToShow(msg);
|
|
125
|
+
if (!textToShow) {
|
|
126
|
+
this.scrollToBottom();
|
|
127
|
+
const lastChild = this.messagesEl.lastElementChild as HTMLElement;
|
|
128
|
+
return lastChild ?? this.messagesEl;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const msgEl = this.messagesEl.createDiv({
|
|
133
|
+
cls: `claudian-message claudian-message-${msg.role}`,
|
|
134
|
+
attr: {
|
|
135
|
+
'data-message-id': msg.id,
|
|
136
|
+
'data-role': msg.role,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const contentEl = msgEl.createDiv({ cls: 'claudian-message-content', attr: { dir: 'auto' } });
|
|
141
|
+
|
|
142
|
+
if (msg.role === 'user') {
|
|
143
|
+
const textToShow = this.getUserMessageTextToShow(msg);
|
|
144
|
+
if (textToShow) {
|
|
145
|
+
const textEl = contentEl.createDiv({ cls: 'claudian-text-block' });
|
|
146
|
+
void this.renderContent(textEl, textToShow);
|
|
147
|
+
this.addUserCopyButton(msgEl, textToShow);
|
|
148
|
+
}
|
|
149
|
+
if (this.rewindCallback || this.forkCallback) {
|
|
150
|
+
this.liveMessageEls.set(msg.id, msgEl);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this.scrollToBottom();
|
|
155
|
+
return msgEl;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
updateLiveUserMessage(msg: ChatMessage): void {
|
|
159
|
+
if (msg.role !== 'user') {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const msgEl = this.liveMessageEls.get(msg.id)
|
|
164
|
+
?? this.messagesEl.querySelector<HTMLElement>(`[data-message-id="${msg.id}"]`);
|
|
165
|
+
if (!msgEl) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const contentEl = msgEl.querySelector<HTMLElement>('.claudian-message-content');
|
|
170
|
+
if (!contentEl) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
contentEl.empty();
|
|
175
|
+
|
|
176
|
+
const textToShow = this.getUserMessageTextToShow(msg);
|
|
177
|
+
if (textToShow) {
|
|
178
|
+
const textEl = contentEl.createDiv({ cls: 'claudian-text-block' });
|
|
179
|
+
void this.renderContent(textEl, textToShow);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const toolbar = msgEl.querySelector<HTMLElement>('.claudian-user-msg-actions');
|
|
183
|
+
if (toolbar) {
|
|
184
|
+
toolbar.querySelectorAll('.claudian-user-msg-copy-btn').forEach((el) => el.remove());
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (textToShow) {
|
|
188
|
+
this.addUserCopyButton(msgEl, textToShow);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
removeMessage(messageId: string): void {
|
|
193
|
+
const msgEl = this.liveMessageEls.get(messageId)
|
|
194
|
+
?? this.messagesEl.querySelector<HTMLElement>(`[data-message-id="${messageId}"]`);
|
|
195
|
+
if (!msgEl) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
msgEl.remove();
|
|
200
|
+
this.liveMessageEls.delete(messageId);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ============================================
|
|
204
|
+
// Stored Message Rendering (Batch/Replay)
|
|
205
|
+
// ============================================
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Renders all messages for conversation load/switch.
|
|
209
|
+
* @param messages Array of messages to render
|
|
210
|
+
* @param getGreeting Function to get greeting text
|
|
211
|
+
* @returns The newly created welcome element
|
|
212
|
+
*/
|
|
213
|
+
renderMessages(
|
|
214
|
+
messages: ChatMessage[],
|
|
215
|
+
getGreeting: () => string
|
|
216
|
+
): HTMLElement {
|
|
217
|
+
this.messagesEl.empty();
|
|
218
|
+
this.liveMessageEls.clear();
|
|
219
|
+
|
|
220
|
+
// Recreate welcome element after clearing
|
|
221
|
+
const newWelcomeEl = this.messagesEl.createDiv({ cls: 'claudian-welcome' });
|
|
222
|
+
newWelcomeEl.createDiv({ cls: 'claudian-welcome-greeting', text: getGreeting() });
|
|
223
|
+
|
|
224
|
+
for (let i = 0; i < messages.length; i++) {
|
|
225
|
+
this.renderStoredMessage(messages[i], messages, i);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
this.scrollToBottom();
|
|
229
|
+
return newWelcomeEl;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
renderStoredMessage(msg: ChatMessage, allMessages?: ChatMessage[], index?: number): void {
|
|
233
|
+
// Bare interrupt marker: user-role interrupts (Claude bracket markers) always render
|
|
234
|
+
// as a standalone indicator. Assistant-role interrupts (Codex partial responses)
|
|
235
|
+
// only use the bare marker when there's no content to preserve.
|
|
236
|
+
if (msg.isInterrupt && (msg.role === 'user' || !this.hasVisibleContent(msg))) {
|
|
237
|
+
this.renderInterruptMessage();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Skip rebuilt context messages (history sent to SDK on session reset)
|
|
242
|
+
// These are internal context for the AI, not actual user messages to display
|
|
243
|
+
if (msg.isRebuiltContext) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Render images above bubble for user messages
|
|
248
|
+
if (msg.role === 'user' && msg.images && msg.images.length > 0) {
|
|
249
|
+
this.renderMessageImages(this.messagesEl, msg.images);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Skip empty bubble for image-only messages
|
|
253
|
+
if (msg.role === 'user') {
|
|
254
|
+
const textToShow = this.getUserMessageTextToShow(msg);
|
|
255
|
+
if (!textToShow) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (msg.role === 'assistant' && !this.hasVisibleContent(msg)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const msgEl = this.messagesEl.createDiv({
|
|
264
|
+
cls: `claudian-message claudian-message-${msg.role}`,
|
|
265
|
+
attr: {
|
|
266
|
+
'data-message-id': msg.id,
|
|
267
|
+
'data-role': msg.role,
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const contentEl = msgEl.createDiv({ cls: 'claudian-message-content', attr: { dir: 'auto' } });
|
|
272
|
+
|
|
273
|
+
if (msg.role === 'user') {
|
|
274
|
+
const textToShow = this.getUserMessageTextToShow(msg);
|
|
275
|
+
if (textToShow) {
|
|
276
|
+
const textEl = contentEl.createDiv({ cls: 'claudian-text-block' });
|
|
277
|
+
void this.renderContent(textEl, textToShow);
|
|
278
|
+
this.addUserCopyButton(msgEl, textToShow);
|
|
279
|
+
}
|
|
280
|
+
if (msg.userMessageId && this.isRewindEligible(allMessages, index)) {
|
|
281
|
+
if (this.rewindCallback) {
|
|
282
|
+
this.addRewindButton(msgEl, msg.id);
|
|
283
|
+
}
|
|
284
|
+
if (this.forkCallback) {
|
|
285
|
+
this.addForkButton(msgEl, msg.id);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} else if (msg.role === 'assistant') {
|
|
289
|
+
this.renderAssistantContent(msg, contentEl);
|
|
290
|
+
if (msg.isInterrupt) {
|
|
291
|
+
this.appendInterruptIndicator(contentEl);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private hasVisibleContent(msg: ChatMessage): boolean {
|
|
297
|
+
if (msg.content && msg.content.trim().length > 0) return true;
|
|
298
|
+
if (msg.contentBlocks && msg.contentBlocks.length > 0) {
|
|
299
|
+
for (const block of msg.contentBlocks) {
|
|
300
|
+
if (block.type === 'thinking' && block.content.trim().length > 0) return true;
|
|
301
|
+
if (block.type === 'text' && block.content.trim().length > 0) return true;
|
|
302
|
+
if (block.type === 'context_compacted') return true;
|
|
303
|
+
if (block.type === 'subagent') return true;
|
|
304
|
+
if (block.type === 'tool_use') {
|
|
305
|
+
const toolCall = msg.toolCalls?.find(tc => tc.id === block.toolId);
|
|
306
|
+
if (toolCall && this.shouldRenderToolCall(toolCall)) return true;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (msg.toolCalls?.some(toolCall => this.shouldRenderToolCall(toolCall))) return true;
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private isRewindEligible(allMessages?: ChatMessage[], index?: number): boolean {
|
|
315
|
+
if (!allMessages || index === undefined) return false;
|
|
316
|
+
const ctx = findRewindContext(allMessages, index);
|
|
317
|
+
return !!ctx.prevAssistantUuid && ctx.hasResponse;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private renderInterruptMessage(): void {
|
|
321
|
+
const msgEl = this.messagesEl.createDiv({ cls: 'claudian-message claudian-message-assistant' });
|
|
322
|
+
const contentEl = msgEl.createDiv({ cls: 'claudian-message-content', attr: { dir: 'auto' } });
|
|
323
|
+
this.appendInterruptIndicator(contentEl);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private appendInterruptIndicator(contentEl: HTMLElement): void {
|
|
327
|
+
const textEl = contentEl.createDiv({ cls: 'claudian-text-block' });
|
|
328
|
+
textEl.createSpan({ cls: 'claudian-interrupted', text: 'Interrupted' });
|
|
329
|
+
textEl.appendText(' ');
|
|
330
|
+
textEl.createSpan({
|
|
331
|
+
cls: 'claudian-interrupted-hint',
|
|
332
|
+
text: '\u00B7 What should Claudian do instead?',
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Renders assistant message content (content blocks or fallback).
|
|
338
|
+
*/
|
|
339
|
+
private renderAssistantContent(msg: ChatMessage, contentEl: HTMLElement): void {
|
|
340
|
+
if (msg.contentBlocks && msg.contentBlocks.length > 0) {
|
|
341
|
+
const renderedToolIds = new Set<string>();
|
|
342
|
+
for (const block of msg.contentBlocks) {
|
|
343
|
+
if (block.type === 'thinking') {
|
|
344
|
+
renderStoredThinkingBlock(
|
|
345
|
+
contentEl,
|
|
346
|
+
block.content,
|
|
347
|
+
block.durationSeconds,
|
|
348
|
+
(el, md) => this.renderContent(el, md)
|
|
349
|
+
);
|
|
350
|
+
} else if (block.type === 'text') {
|
|
351
|
+
// Skip empty or whitespace-only text blocks to avoid extra gaps
|
|
352
|
+
if (!block.content || !block.content.trim()) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const textEl = contentEl.createDiv({ cls: 'claudian-text-block' });
|
|
356
|
+
void this.renderContent(textEl, block.content);
|
|
357
|
+
this.addTextCopyButton(textEl, block.content);
|
|
358
|
+
} else if (block.type === 'tool_use') {
|
|
359
|
+
const toolCall = msg.toolCalls?.find(tc => tc.id === block.toolId);
|
|
360
|
+
if (toolCall) {
|
|
361
|
+
this.renderToolCall(contentEl, toolCall, msg);
|
|
362
|
+
renderedToolIds.add(toolCall.id);
|
|
363
|
+
}
|
|
364
|
+
} else if (block.type === 'context_compacted') {
|
|
365
|
+
const boundaryEl = contentEl.createDiv({ cls: 'claudian-compact-boundary' });
|
|
366
|
+
boundaryEl.createSpan({ cls: 'claudian-compact-boundary-label', text: 'Conversation compacted' });
|
|
367
|
+
} else if (block.type === 'subagent') {
|
|
368
|
+
const taskToolCall = msg.toolCalls?.find(
|
|
369
|
+
tc => tc.id === block.subagentId && isSubagentToolName(tc.name)
|
|
370
|
+
);
|
|
371
|
+
if (!taskToolCall) continue;
|
|
372
|
+
|
|
373
|
+
this.renderTaskSubagent(contentEl, taskToolCall, block.mode);
|
|
374
|
+
renderedToolIds.add(taskToolCall.id);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Defensive fallback: preserve tool visibility when contentBlocks/toolCalls drift on reload.
|
|
379
|
+
if (msg.toolCalls && msg.toolCalls.length > 0) {
|
|
380
|
+
for (const toolCall of msg.toolCalls) {
|
|
381
|
+
if (renderedToolIds.has(toolCall.id)) continue;
|
|
382
|
+
this.renderToolCall(contentEl, toolCall, msg);
|
|
383
|
+
renderedToolIds.add(toolCall.id);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
} else {
|
|
387
|
+
// Fallback for old conversations without contentBlocks
|
|
388
|
+
if (msg.content) {
|
|
389
|
+
const textEl = contentEl.createDiv({ cls: 'claudian-text-block' });
|
|
390
|
+
void this.renderContent(textEl, msg.content);
|
|
391
|
+
this.addTextCopyButton(textEl, msg.content);
|
|
392
|
+
}
|
|
393
|
+
if (msg.toolCalls) {
|
|
394
|
+
for (const toolCall of msg.toolCalls) {
|
|
395
|
+
this.renderToolCall(contentEl, toolCall, msg);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Render response duration footer (skip when message contains a compaction boundary)
|
|
401
|
+
const hasCompactBoundary = msg.contentBlocks?.some(b => b.type === 'context_compacted');
|
|
402
|
+
if (msg.durationSeconds && msg.durationSeconds > 0 && !hasCompactBoundary) {
|
|
403
|
+
const flavorWord = msg.durationFlavorWord || 'Baked';
|
|
404
|
+
const footerEl = contentEl.createDiv({ cls: 'claudian-response-footer' });
|
|
405
|
+
footerEl.createSpan({
|
|
406
|
+
text: `* ${flavorWord} for ${formatDurationMmSs(msg.durationSeconds)}`,
|
|
407
|
+
cls: 'claudian-baked-duration',
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Renders a tool call with special handling for Write/Edit, Agent (subagent),
|
|
414
|
+
* and Codex collab agent lifecycle tools.
|
|
415
|
+
*/
|
|
416
|
+
private renderToolCall(contentEl: HTMLElement, toolCall: ToolCallInfo, msg?: ChatMessage): void {
|
|
417
|
+
if (!this.shouldRenderToolCall(toolCall)) return;
|
|
418
|
+
const subagentLifecycleAdapter = this.getSubagentLifecycleAdapter(toolCall.name);
|
|
419
|
+
|
|
420
|
+
if (isWriteEditTool(toolCall.name)) {
|
|
421
|
+
renderStoredWriteEdit(contentEl, toolCall, {
|
|
422
|
+
initiallyExpanded: this.shouldExpandFileEditsByDefault(),
|
|
423
|
+
});
|
|
424
|
+
} else if (isSubagentToolName(toolCall.name)) {
|
|
425
|
+
this.renderTaskSubagent(contentEl, toolCall);
|
|
426
|
+
} else if (subagentLifecycleAdapter?.isSpawnTool(toolCall.name) && msg) {
|
|
427
|
+
this.renderProviderLifecycleSubagent(contentEl, toolCall, msg);
|
|
428
|
+
} else {
|
|
429
|
+
renderStoredToolCall(contentEl, toolCall, {
|
|
430
|
+
initiallyExpanded: toolCall.name === TOOL_APPLY_PATCH && this.shouldExpandFileEditsByDefault(),
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
private shouldRenderToolCall(toolCall: ToolCallInfo): boolean {
|
|
436
|
+
if (toolCall.name === TOOL_AGENT_OUTPUT) return false;
|
|
437
|
+
if (toolCall.name === TOOL_WRITE_STDIN && this.isSilentWriteStdinTool(toolCall)) return false;
|
|
438
|
+
if (toolCall.name === 'custom_tool_call_output') return false;
|
|
439
|
+
|
|
440
|
+
const subagentLifecycleAdapter = this.getSubagentLifecycleAdapter(toolCall.name);
|
|
441
|
+
if (subagentLifecycleAdapter?.isHiddenTool(toolCall.name)) return false;
|
|
442
|
+
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
private isSilentWriteStdinTool(toolCall: ToolCallInfo): boolean {
|
|
447
|
+
return typeof toolCall.input.chars !== 'string' || toolCall.input.chars.length === 0;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
private renderTaskSubagent(
|
|
451
|
+
contentEl: HTMLElement,
|
|
452
|
+
toolCall: ToolCallInfo,
|
|
453
|
+
modeHint?: 'sync' | 'async'
|
|
454
|
+
): void {
|
|
455
|
+
const subagentInfo = this.resolveTaskSubagent(toolCall, modeHint);
|
|
456
|
+
if (subagentInfo.mode === 'async') {
|
|
457
|
+
renderStoredAsyncSubagent(contentEl, subagentInfo);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
renderStoredSubagent(contentEl, subagentInfo);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Consolidates provider lifecycle tools (spawn + wait/close)
|
|
465
|
+
* into a single subagent block with prompt and result.
|
|
466
|
+
*/
|
|
467
|
+
private renderProviderLifecycleSubagent(
|
|
468
|
+
contentEl: HTMLElement,
|
|
469
|
+
spawnToolCall: ToolCallInfo,
|
|
470
|
+
msg: ChatMessage,
|
|
471
|
+
): void {
|
|
472
|
+
const subagentLifecycleAdapter = this.getSubagentLifecycleAdapter(spawnToolCall.name);
|
|
473
|
+
if (!subagentLifecycleAdapter) {
|
|
474
|
+
renderStoredToolCall(contentEl, spawnToolCall);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const subagentInfo = subagentLifecycleAdapter.buildSubagentInfo(
|
|
479
|
+
spawnToolCall,
|
|
480
|
+
msg.toolCalls ?? [],
|
|
481
|
+
);
|
|
482
|
+
renderStoredSubagent(contentEl, subagentInfo);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
private resolveTaskSubagent(toolCall: ToolCallInfo, modeHint?: 'sync' | 'async'): SubagentInfo {
|
|
486
|
+
if (toolCall.subagent) {
|
|
487
|
+
if (!modeHint || toolCall.subagent.mode === modeHint) {
|
|
488
|
+
return toolCall.subagent;
|
|
489
|
+
}
|
|
490
|
+
return {
|
|
491
|
+
...toolCall.subagent,
|
|
492
|
+
mode: modeHint,
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const description = (toolCall.input?.description as string) || 'Subagent task';
|
|
497
|
+
const prompt = (toolCall.input?.prompt as string) || '';
|
|
498
|
+
const mode = modeHint ?? (toolCall.input?.run_in_background === true ? 'async' : 'sync');
|
|
499
|
+
|
|
500
|
+
if (mode !== 'async') {
|
|
501
|
+
return {
|
|
502
|
+
id: toolCall.id,
|
|
503
|
+
description,
|
|
504
|
+
prompt,
|
|
505
|
+
status: this.mapToolStatusToSubagentStatus(toolCall.status),
|
|
506
|
+
toolCalls: [],
|
|
507
|
+
isExpanded: false,
|
|
508
|
+
result: toolCall.result,
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const asyncStatus = this.inferAsyncStatusFromTaskTool(toolCall);
|
|
513
|
+
return {
|
|
514
|
+
id: toolCall.id,
|
|
515
|
+
description,
|
|
516
|
+
prompt,
|
|
517
|
+
mode: 'async',
|
|
518
|
+
status: asyncStatus,
|
|
519
|
+
asyncStatus,
|
|
520
|
+
toolCalls: [],
|
|
521
|
+
isExpanded: false,
|
|
522
|
+
result: toolCall.result,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
private mapToolStatusToSubagentStatus(
|
|
527
|
+
status: ToolCallInfo['status']
|
|
528
|
+
): 'completed' | 'error' | 'running' {
|
|
529
|
+
switch (status) {
|
|
530
|
+
case 'completed':
|
|
531
|
+
return 'completed';
|
|
532
|
+
case 'error':
|
|
533
|
+
case 'blocked':
|
|
534
|
+
return 'error';
|
|
535
|
+
default:
|
|
536
|
+
return 'running';
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
private inferAsyncStatusFromTaskTool(toolCall: ToolCallInfo): 'running' | 'completed' | 'error' {
|
|
541
|
+
if (toolCall.status === 'error' || toolCall.status === 'blocked') return 'error';
|
|
542
|
+
if (toolCall.status === 'running') return 'running';
|
|
543
|
+
|
|
544
|
+
const lowerResult = extractToolResultContent(toolCall.result, { fallbackIndent: 2 }).toLowerCase();
|
|
545
|
+
if (
|
|
546
|
+
lowerResult.includes('not_ready') ||
|
|
547
|
+
lowerResult.includes('not ready') ||
|
|
548
|
+
lowerResult.includes('"status":"running"') ||
|
|
549
|
+
lowerResult.includes('"status":"pending"') ||
|
|
550
|
+
lowerResult.includes('"retrieval_status":"running"') ||
|
|
551
|
+
lowerResult.includes('"retrieval_status":"not_ready"')
|
|
552
|
+
) {
|
|
553
|
+
return 'running';
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
return 'completed';
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// ============================================
|
|
560
|
+
// Image Rendering
|
|
561
|
+
// ============================================
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Renders image attachments above a message.
|
|
565
|
+
*/
|
|
566
|
+
renderMessageImages(containerEl: HTMLElement, images: ImageAttachment[]): void {
|
|
567
|
+
const imagesEl = containerEl.createDiv({ cls: 'claudian-message-images' });
|
|
568
|
+
|
|
569
|
+
for (const image of images) {
|
|
570
|
+
const imageWrapper = imagesEl.createDiv({ cls: 'claudian-message-image' });
|
|
571
|
+
const imgEl = imageWrapper.createEl('img', {
|
|
572
|
+
attr: {
|
|
573
|
+
alt: image.name,
|
|
574
|
+
},
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
void this.setImageSrc(imgEl, image);
|
|
578
|
+
|
|
579
|
+
// Click to view full size
|
|
580
|
+
imgEl.addEventListener('click', () => {
|
|
581
|
+
void this.showFullImage(image);
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Shows full-size image in modal overlay.
|
|
588
|
+
*/
|
|
589
|
+
showFullImage(image: ImageAttachment): void {
|
|
590
|
+
const dataUri = `data:${image.mediaType};base64,${image.data}`;
|
|
591
|
+
|
|
592
|
+
const ownerDocument = this.messagesEl.ownerDocument ?? window.document;
|
|
593
|
+
const overlay = ownerDocument.body.createDiv({ cls: 'claudian-image-modal-overlay' });
|
|
594
|
+
const modal = overlay.createDiv({ cls: 'claudian-image-modal' });
|
|
595
|
+
|
|
596
|
+
modal.createEl('img', {
|
|
597
|
+
attr: {
|
|
598
|
+
src: dataUri,
|
|
599
|
+
alt: image.name,
|
|
600
|
+
},
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
const closeBtn = modal.createDiv({ cls: 'claudian-image-modal-close' });
|
|
604
|
+
closeBtn.setText('\u00D7');
|
|
605
|
+
|
|
606
|
+
const handleEsc = (e: KeyboardEvent) => {
|
|
607
|
+
if (e.key === 'Escape') {
|
|
608
|
+
close();
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
const close = () => {
|
|
613
|
+
ownerDocument.removeEventListener('keydown', handleEsc);
|
|
614
|
+
overlay.remove();
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
closeBtn.addEventListener('click', close);
|
|
618
|
+
overlay.addEventListener('click', (e) => {
|
|
619
|
+
if (e.target === overlay) close();
|
|
620
|
+
});
|
|
621
|
+
ownerDocument.addEventListener('keydown', handleEsc);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Sets image src from attachment data.
|
|
626
|
+
*/
|
|
627
|
+
setImageSrc(imgEl: HTMLImageElement, image: ImageAttachment): void {
|
|
628
|
+
const dataUri = `data:${image.mediaType};base64,${image.data}`;
|
|
629
|
+
imgEl.setAttribute('src', dataUri);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// ============================================
|
|
633
|
+
// Content Rendering
|
|
634
|
+
// ============================================
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Renders markdown content with code block enhancements.
|
|
638
|
+
*/
|
|
639
|
+
async renderContent(
|
|
640
|
+
el: HTMLElement,
|
|
641
|
+
markdown: string,
|
|
642
|
+
options?: RenderContentOptions
|
|
643
|
+
): Promise<void> {
|
|
644
|
+
el.empty();
|
|
645
|
+
|
|
646
|
+
try {
|
|
647
|
+
const renderMarkdown = options?.deferMath
|
|
648
|
+
? escapeMathDelimitersForStreaming(markdown)
|
|
649
|
+
: markdown;
|
|
650
|
+
// Normalize embeds before MarkdownRenderer consumes them.
|
|
651
|
+
const processedMarkdown = replaceImageEmbedsWithHtml(
|
|
652
|
+
renderMarkdown,
|
|
653
|
+
this.app,
|
|
654
|
+
{ mediaFolder: this.plugin.settings.mediaFolder }
|
|
655
|
+
);
|
|
656
|
+
await MarkdownRenderer.render(
|
|
657
|
+
this.app,
|
|
658
|
+
processedMarkdown,
|
|
659
|
+
el,
|
|
660
|
+
'',
|
|
661
|
+
this.component
|
|
662
|
+
);
|
|
663
|
+
|
|
664
|
+
// Wrap pre elements and move buttons outside scroll area
|
|
665
|
+
el.querySelectorAll('pre').forEach((pre) => {
|
|
666
|
+
// Skip if already wrapped
|
|
667
|
+
if (pre.parentElement?.classList.contains('claudian-code-wrapper')) return;
|
|
668
|
+
|
|
669
|
+
// Create wrapper
|
|
670
|
+
const wrapper = createEl('div', { cls: 'claudian-code-wrapper' });
|
|
671
|
+
pre.parentElement?.insertBefore(wrapper, pre);
|
|
672
|
+
wrapper.appendChild(pre);
|
|
673
|
+
|
|
674
|
+
// Check for language class and add label
|
|
675
|
+
const code = pre.querySelector('code[class*="language-"]');
|
|
676
|
+
if (code) {
|
|
677
|
+
const match = code.className.match(/language-(\w+)/);
|
|
678
|
+
if (match) {
|
|
679
|
+
wrapper.classList.add('has-language');
|
|
680
|
+
const label = createEl('span', {
|
|
681
|
+
cls: 'claudian-code-lang-label',
|
|
682
|
+
text: match[1],
|
|
683
|
+
});
|
|
684
|
+
wrapper.appendChild(label);
|
|
685
|
+
label.addEventListener('click', () => {
|
|
686
|
+
runRendererAction(async () => {
|
|
687
|
+
const originalLabel = match[1];
|
|
688
|
+
if (!originalLabel) return;
|
|
689
|
+
|
|
690
|
+
try {
|
|
691
|
+
await navigator.clipboard.writeText(code.textContent || '');
|
|
692
|
+
label.setText('Copied!');
|
|
693
|
+
window.setTimeout(() => label.setText(originalLabel), 1500);
|
|
694
|
+
} catch {
|
|
695
|
+
// Clipboard API may fail in non-secure contexts
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// Move Obsidian's copy button outside pre into wrapper
|
|
703
|
+
const copyBtn = pre.querySelector('.copy-code-button');
|
|
704
|
+
if (copyBtn) {
|
|
705
|
+
wrapper.appendChild(copyBtn);
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
// Process wikilinks only when the source can contain them; the DOM pass is expensive.
|
|
710
|
+
if (processedMarkdown.includes('[[')) {
|
|
711
|
+
processFileLinks(this.app, el);
|
|
712
|
+
}
|
|
713
|
+
} catch {
|
|
714
|
+
el.createDiv({
|
|
715
|
+
cls: 'claudian-render-error',
|
|
716
|
+
text: 'Failed to render message content.',
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// ============================================
|
|
722
|
+
// Copy Button
|
|
723
|
+
// ============================================
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Adds a copy button to a text block.
|
|
727
|
+
* Button shows clipboard icon on hover, changes to "copied!" on click.
|
|
728
|
+
* @param textEl The rendered text element
|
|
729
|
+
* @param markdown The original markdown content to copy
|
|
730
|
+
*/
|
|
731
|
+
addTextCopyButton(textEl: HTMLElement, markdown: string): void {
|
|
732
|
+
const copyBtn = textEl.createSpan({ cls: 'claudian-text-copy-btn' });
|
|
733
|
+
setIcon(copyBtn, 'copy');
|
|
734
|
+
|
|
735
|
+
let feedbackTimeout: number | null = null;
|
|
736
|
+
|
|
737
|
+
copyBtn.addEventListener('click', (e) => {
|
|
738
|
+
e.stopPropagation();
|
|
739
|
+
runRendererAction(async () => {
|
|
740
|
+
|
|
741
|
+
try {
|
|
742
|
+
await navigator.clipboard.writeText(markdown);
|
|
743
|
+
} catch {
|
|
744
|
+
// Clipboard API may fail in non-secure contexts
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// Clear any pending timeout from rapid clicks
|
|
749
|
+
if (feedbackTimeout) {
|
|
750
|
+
window.clearTimeout(feedbackTimeout);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// Show "copied!" feedback
|
|
754
|
+
copyBtn.empty();
|
|
755
|
+
copyBtn.setText('Copied!');
|
|
756
|
+
copyBtn.classList.add('copied');
|
|
757
|
+
|
|
758
|
+
feedbackTimeout = window.setTimeout(() => {
|
|
759
|
+
copyBtn.empty();
|
|
760
|
+
setIcon(copyBtn, 'copy');
|
|
761
|
+
copyBtn.classList.remove('copied');
|
|
762
|
+
feedbackTimeout = null;
|
|
763
|
+
}, 1500);
|
|
764
|
+
});
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
refreshActionButtons(msg: ChatMessage, allMessages?: ChatMessage[], index?: number): void {
|
|
769
|
+
if (!msg.userMessageId) return;
|
|
770
|
+
if (!this.isRewindEligible(allMessages, index)) return;
|
|
771
|
+
const msgEl = this.liveMessageEls.get(msg.id);
|
|
772
|
+
if (!msgEl) return;
|
|
773
|
+
|
|
774
|
+
if (this.rewindCallback && !msgEl.querySelector('.claudian-message-rewind-btn')) {
|
|
775
|
+
this.addRewindButton(msgEl, msg.id);
|
|
776
|
+
}
|
|
777
|
+
if (this.forkCallback && !msgEl.querySelector('.claudian-message-fork-btn')) {
|
|
778
|
+
this.addForkButton(msgEl, msg.id);
|
|
779
|
+
}
|
|
780
|
+
this.cleanupLiveMessageEl(msg.id, msgEl);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
private cleanupLiveMessageEl(msgId: string, msgEl: HTMLElement): void {
|
|
784
|
+
const needsRewind = this.rewindCallback && !msgEl.querySelector('.claudian-message-rewind-btn');
|
|
785
|
+
const needsFork = this.forkCallback && !msgEl.querySelector('.claudian-message-fork-btn');
|
|
786
|
+
if (!needsRewind && !needsFork) {
|
|
787
|
+
this.liveMessageEls.delete(msgId);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
private getOrCreateActionsToolbar(msgEl: HTMLElement): HTMLElement {
|
|
792
|
+
const existing = msgEl.querySelector<HTMLElement>('.claudian-user-msg-actions');
|
|
793
|
+
if (existing) return existing;
|
|
794
|
+
return msgEl.createDiv({ cls: 'claudian-user-msg-actions' });
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
private addUserCopyButton(msgEl: HTMLElement, content: string): void {
|
|
798
|
+
const toolbar = this.getOrCreateActionsToolbar(msgEl);
|
|
799
|
+
const copyBtn = toolbar.createSpan({ cls: 'claudian-user-msg-copy-btn' });
|
|
800
|
+
setIcon(copyBtn, 'copy');
|
|
801
|
+
copyBtn.setAttribute('aria-label', 'Copy message');
|
|
802
|
+
|
|
803
|
+
let feedbackTimeout: number | null = null;
|
|
804
|
+
|
|
805
|
+
copyBtn.addEventListener('click', (e) => {
|
|
806
|
+
e.stopPropagation();
|
|
807
|
+
runRendererAction(async () => {
|
|
808
|
+
try {
|
|
809
|
+
await navigator.clipboard.writeText(content);
|
|
810
|
+
} catch {
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
if (feedbackTimeout) window.clearTimeout(feedbackTimeout);
|
|
814
|
+
copyBtn.empty();
|
|
815
|
+
copyBtn.setText('Copied!');
|
|
816
|
+
copyBtn.classList.add('copied');
|
|
817
|
+
feedbackTimeout = window.setTimeout(() => {
|
|
818
|
+
copyBtn.empty();
|
|
819
|
+
setIcon(copyBtn, 'copy');
|
|
820
|
+
copyBtn.classList.remove('copied');
|
|
821
|
+
feedbackTimeout = null;
|
|
822
|
+
}, 1500);
|
|
823
|
+
});
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
private addRewindButton(msgEl: HTMLElement, messageId: string): void {
|
|
828
|
+
if (!this.getCapabilities().supportsRewind) return;
|
|
829
|
+
const toolbar = this.getOrCreateActionsToolbar(msgEl);
|
|
830
|
+
const btn = toolbar.createSpan({ cls: 'claudian-message-rewind-btn' });
|
|
831
|
+
if (toolbar.firstChild !== btn) toolbar.insertBefore(btn, toolbar.firstChild);
|
|
832
|
+
setIcon(btn, 'rotate-ccw');
|
|
833
|
+
btn.setAttribute('aria-label', t('chat.rewind.ariaLabel'));
|
|
834
|
+
btn.addEventListener('click', (e) => {
|
|
835
|
+
e.stopPropagation();
|
|
836
|
+
this.showRewindMenu(e, messageId);
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
private showRewindMenu(event: MouseEvent, messageId: string): void {
|
|
841
|
+
const menu = new Menu();
|
|
842
|
+
this.addRewindMenuItem(menu, messageId, 'conversation');
|
|
843
|
+
this.addRewindMenuItem(menu, messageId, 'code-and-conversation');
|
|
844
|
+
menu.showAtMouseEvent(event);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
private addRewindMenuItem(menu: Menu, messageId: string, mode: ChatRewindMode): void {
|
|
848
|
+
menu.addItem((item) => {
|
|
849
|
+
item
|
|
850
|
+
.setTitle(
|
|
851
|
+
mode === 'conversation'
|
|
852
|
+
? t('chat.rewind.menuConversationOnly')
|
|
853
|
+
: t('chat.rewind.menuCodeAndConversation')
|
|
854
|
+
)
|
|
855
|
+
.setIcon(mode === 'conversation' ? 'message-square' : 'rotate-ccw')
|
|
856
|
+
.onClick(() => {
|
|
857
|
+
runRendererAction(async () => {
|
|
858
|
+
try {
|
|
859
|
+
await this.rewindCallback?.(messageId, mode);
|
|
860
|
+
} catch (err) {
|
|
861
|
+
new Notice(t('chat.rewind.failed', { error: err instanceof Error ? err.message : 'Unknown error' }));
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
});
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
private addForkButton(msgEl: HTMLElement, messageId: string): void {
|
|
869
|
+
if (!this.getCapabilities().supportsFork) return;
|
|
870
|
+
const toolbar = this.getOrCreateActionsToolbar(msgEl);
|
|
871
|
+
const btn = toolbar.createSpan({ cls: 'claudian-message-fork-btn' });
|
|
872
|
+
if (toolbar.firstChild !== btn) toolbar.insertBefore(btn, toolbar.firstChild);
|
|
873
|
+
setIcon(btn, 'git-fork');
|
|
874
|
+
btn.setAttribute('aria-label', t('chat.fork.ariaLabel'));
|
|
875
|
+
btn.addEventListener('click', (e) => {
|
|
876
|
+
e.stopPropagation();
|
|
877
|
+
runRendererAction(async () => {
|
|
878
|
+
try {
|
|
879
|
+
await this.forkCallback?.(messageId);
|
|
880
|
+
} catch (err) {
|
|
881
|
+
new Notice(t('chat.fork.failed', { error: err instanceof Error ? err.message : 'Unknown error' }));
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// ============================================
|
|
888
|
+
// Utilities
|
|
889
|
+
// ============================================
|
|
890
|
+
|
|
891
|
+
/** Scrolls messages container to bottom. */
|
|
892
|
+
scrollToBottom(): void {
|
|
893
|
+
this.messagesEl.scrollTop = this.messagesEl.scrollHeight;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/** Scrolls to bottom if already near bottom (within threshold). */
|
|
897
|
+
scrollToBottomIfNeeded(threshold = 100): void {
|
|
898
|
+
const { scrollTop, scrollHeight, clientHeight } = this.messagesEl;
|
|
899
|
+
const isNearBottom = scrollHeight - scrollTop - clientHeight < threshold;
|
|
900
|
+
if (isNearBottom) {
|
|
901
|
+
window.requestAnimationFrame(() => {
|
|
902
|
+
this.messagesEl.scrollTop = this.messagesEl.scrollHeight;
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
}
|