@sunub/obsidian-mcp-server 0.1.1 → 0.3.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/LICENSE +15 -0
- package/README.md +392 -153
- package/build/cli/AppContainer.d.ts +1 -0
- package/build/cli/AppContainer.js +197 -0
- package/build/cli/AppContainer.js.map +1 -0
- package/build/cli/app.js +7 -0
- package/build/cli/app.js.map +1 -0
- package/build/cli/config/SettingContext.d.ts +1 -0
- package/build/cli/config/SettingContext.js +2 -0
- package/build/cli/config/SettingContext.js.map +1 -0
- package/build/cli/config/mcpServersConfig.d.ts +18 -0
- package/build/cli/config/mcpServersConfig.js +119 -0
- package/build/cli/config/mcpServersConfig.js.map +1 -0
- package/build/cli/config/settingSchema.d.ts +180 -0
- package/build/cli/config/settingSchema.js +128 -0
- package/build/cli/config/settingSchema.js.map +1 -0
- package/build/cli/context/InputContext.d.ts +12 -0
- package/build/cli/context/InputContext.js +10 -0
- package/build/cli/context/InputContext.js.map +1 -0
- package/build/cli/context/KeypressContext.d.ts +30 -0
- package/build/cli/context/KeypressContext.js +200 -0
- package/build/cli/context/KeypressContext.js.map +1 -0
- package/build/cli/context/KeypressContext.util.d.ts +7 -0
- package/build/cli/context/KeypressContext.util.js +474 -0
- package/build/cli/context/KeypressContext.util.js.map +1 -0
- package/build/cli/hooks/useAtCompletion.d.ts +12 -0
- package/build/cli/hooks/useAtCompletion.js +5 -0
- package/build/cli/hooks/useAtCompletion.js.map +1 -0
- package/build/cli/hooks/useCommandCompletion.d.ts +59 -0
- package/build/cli/hooks/useCommandCompletion.js +344 -0
- package/build/cli/hooks/useCommandCompletion.js.map +1 -0
- package/build/cli/hooks/useCompletion.d.ts +22 -0
- package/build/cli/hooks/useCompletion.js +84 -0
- package/build/cli/hooks/useCompletion.js.map +1 -0
- package/build/cli/hooks/useDispatcher.d.ts +6 -0
- package/build/cli/hooks/useDispatcher.js +286 -0
- package/build/cli/hooks/useDispatcher.js.map +1 -0
- package/build/cli/hooks/useFocus.d.ts +2 -0
- package/build/cli/hooks/useFocus.js +3 -0
- package/build/cli/hooks/useFocus.js.map +1 -0
- package/build/cli/hooks/useInputHistory.d.ts +24 -0
- package/build/cli/hooks/useInputHistory.js +159 -0
- package/build/cli/hooks/useInputHistory.js.map +1 -0
- package/build/cli/hooks/useKeyMatchers.d.ts +17 -0
- package/build/cli/hooks/useKeyMatchers.js +13 -0
- package/build/cli/hooks/useKeyMatchers.js.map +1 -0
- package/build/cli/hooks/useKeypress.d.ts +19 -0
- package/build/cli/hooks/useKeypress.js +28 -0
- package/build/cli/hooks/useKeypress.js.map +1 -0
- package/build/cli/hooks/useLlmStream.d.ts +12 -0
- package/build/cli/hooks/useLlmStream.js +365 -0
- package/build/cli/hooks/useLlmStream.js.map +1 -0
- package/build/cli/hooks/useMcpClient.d.ts +10 -0
- package/build/cli/hooks/useMcpClient.js +100 -0
- package/build/cli/hooks/useMcpClient.js.map +1 -0
- package/build/cli/hooks/useMcpManager.d.ts +22 -0
- package/build/cli/hooks/useMcpManager.js +86 -0
- package/build/cli/hooks/useMcpManager.js.map +1 -0
- package/build/cli/hooks/usePromptCompletion.d.ts +19 -0
- package/build/cli/hooks/usePromptCompletion.js +13 -0
- package/build/cli/hooks/usePromptCompletion.js.map +1 -0
- package/build/cli/hooks/useRagContext.d.ts +6 -0
- package/build/cli/hooks/useRagContext.js +83 -0
- package/build/cli/hooks/useRagContext.js.map +1 -0
- package/build/cli/hooks/useShellCompletion.d.ts +18 -0
- package/build/cli/hooks/useShellCompletion.js +10 -0
- package/build/cli/hooks/useShellCompletion.js.map +1 -0
- package/build/cli/hooks/useSlashCompletion.d.ts +21 -0
- package/build/cli/hooks/useSlashCompletion.js +11 -0
- package/build/cli/hooks/useSlashCompletion.js.map +1 -0
- package/build/cli/hooks/useTerminalSize.d.ts +9 -0
- package/build/cli/hooks/useTerminalSize.js +26 -0
- package/build/cli/hooks/useTerminalSize.js.map +1 -0
- package/build/cli/index.js +27 -0
- package/build/cli/index.js.map +1 -0
- package/build/cli/key/keyBindings.d.ts +152 -0
- package/build/cli/key/keyBindings.js +630 -0
- package/build/cli/key/keyBindings.js.map +1 -0
- package/build/cli/key/keyMatchers.d.ts +27 -0
- package/build/cli/key/keyMatchers.js +33 -0
- package/build/cli/key/keyMatchers.js.map +1 -0
- package/build/cli/key/text-buffer-bestcase.js +2754 -0
- package/build/cli/key/text-buffer-bestcase.js.map +1 -0
- package/build/cli/key/text-buffer.js +918 -0
- package/build/cli/key/text-buffer.js.map +1 -0
- package/build/cli/reference/HistoryItemDisplay.d.ts +23 -0
- package/build/cli/reference/HistoryItemDisplay.js +63 -0
- package/build/cli/reference/HistoryItemDisplay.js.map +1 -0
- package/build/cli/reference/InputContext.d.ts +17 -0
- package/build/cli/reference/InputContext.js +16 -0
- package/build/cli/reference/InputContext.js.map +1 -0
- package/build/cli/reference/KerypressContext.d.ts +37 -0
- package/build/cli/reference/KerypressContext.js +791 -0
- package/build/cli/reference/KerypressContext.js.map +1 -0
- package/build/cli/reference/MainContent.d.ts +6 -0
- package/build/cli/reference/MainContent.js +207 -0
- package/build/cli/reference/MainContent.js.map +1 -0
- package/build/cli/reference/UIStateContext.d.ts +188 -0
- package/build/cli/reference/UIStateContext.js +16 -0
- package/build/cli/reference/UIStateContext.js.map +1 -0
- package/build/cli/reference/useGeminiStream.d.ts +42 -0
- package/build/cli/reference/useGeminiStream.js +1404 -0
- package/build/cli/reference/useGeminiStream.js.map +1 -0
- package/build/cli/services/McpClientService.d.ts +32 -0
- package/build/cli/services/McpClientService.js +123 -0
- package/build/cli/services/McpClientService.js.map +1 -0
- package/build/cli/services/McpManager.d.ts +28 -0
- package/build/cli/services/McpManager.js +146 -0
- package/build/cli/services/McpManager.js.map +1 -0
- package/build/cli/theme/builtin/no-color.js +125 -0
- package/build/cli/theme/builtin/no-color.js.map +1 -0
- package/build/cli/theme/builtin/tokyonight-dark.js +146 -0
- package/build/cli/theme/builtin/tokyonight-dark.js.map +1 -0
- package/build/cli/theme/semantic-colors.js +19 -0
- package/build/cli/theme/semantic-colors.js.map +1 -0
- package/build/cli/theme/semantic-tokens.js +77 -0
- package/build/cli/theme/semantic-tokens.js.map +1 -0
- package/build/cli/theme/theme-manager.d.ts +32 -0
- package/build/cli/theme/theme-manager.js +150 -0
- package/build/cli/theme/theme-manager.js.map +1 -0
- package/build/cli/theme/theme.js +333 -0
- package/build/cli/theme/theme.js.map +1 -0
- package/build/cli/tmp.js +27 -0
- package/build/cli/tmp.js.map +1 -0
- package/build/cli/types.d.ts +72 -0
- package/build/cli/types.js +8 -0
- package/build/cli/types.js.map +1 -0
- package/build/cli/ui/ConnectionStatus.d.ts +13 -0
- package/build/cli/ui/ConnectionStatus.js +24 -0
- package/build/cli/ui/ConnectionStatus.js.map +1 -0
- package/build/cli/ui/HelpCommands.d.ts +5 -0
- package/build/cli/ui/HelpCommands.js +11 -0
- package/build/cli/ui/HelpCommands.js.map +1 -0
- package/build/cli/ui/HistoryItemDisplay.d.ts +9 -0
- package/build/cli/ui/HistoryItemDisplay.js +38 -0
- package/build/cli/ui/HistoryItemDisplay.js.map +1 -0
- package/build/cli/ui/InputPrompt-bestcase.d.ts +63 -0
- package/build/cli/ui/InputPrompt-bestcase.js +1301 -0
- package/build/cli/ui/InputPrompt-bestcase.js.map +1 -0
- package/build/cli/ui/InputPrompt.d.ts +12 -0
- package/build/cli/ui/InputPrompt.js +145 -0
- package/build/cli/ui/InputPrompt.js.map +1 -0
- package/build/cli/ui/InputPrompt.tmp.d.ts +7 -0
- package/build/cli/ui/InputPrompt.tmp.js +215 -0
- package/build/cli/ui/InputPrompt.tmp.js.map +1 -0
- package/build/cli/ui/MainContent.d.ts +10 -0
- package/build/cli/ui/MainContent.js +24 -0
- package/build/cli/ui/MainContent.js.map +1 -0
- package/build/cli/ui/MouseContext.d.ts +1 -0
- package/build/cli/ui/MouseContext.js +2 -0
- package/build/cli/ui/MouseContext.js.map +1 -0
- package/build/cli/ui/SuggestionsDisplay.d.ts +25 -0
- package/build/cli/ui/SuggestionsDisplay.js +45 -0
- package/build/cli/ui/SuggestionsDisplay.js.map +1 -0
- package/build/cli/ui/ThinkingIndicator.d.ts +2 -0
- package/build/cli/ui/ThinkingIndicator.js +16 -0
- package/build/cli/ui/ThinkingIndicator.js.map +1 -0
- package/build/cli/ui/layout/DefaultAppLayout.d.ts +2 -0
- package/build/cli/ui/layout/DefaultAppLayout.js +6 -0
- package/build/cli/ui/layout/DefaultAppLayout.js.map +1 -0
- package/build/cli/ui/shared/ExpandableText.d.ts +14 -0
- package/build/cli/ui/shared/ExpandableText.js +19 -0
- package/build/cli/ui/shared/ExpandableText.js.map +1 -0
- package/build/cli/utils/commandUtils.d.ts +11 -0
- package/build/cli/utils/commandUtils.js +16 -0
- package/build/cli/utils/commandUtils.js.map +1 -0
- package/build/cli/utils/debugLogger.d.ts +12 -0
- package/build/cli/utils/debugLogger.js +52 -0
- package/build/cli/utils/debugLogger.js.map +1 -0
- package/build/cli/utils/historyStorage.d.ts +13 -0
- package/build/cli/utils/historyStorage.js +64 -0
- package/build/cli/utils/historyStorage.js.map +1 -0
- package/build/cli/utils/textUtil.d.ts +68 -0
- package/build/cli/utils/textUtil.js +236 -0
- package/build/cli/utils/textUtil.js.map +1 -0
- package/build/config.js +31 -5
- package/build/config.js.map +1 -0
- package/build/db.js +55 -0
- package/build/db.js.map +1 -0
- package/build/index.js +4 -4
- package/build/index.js.map +1 -0
- package/build/tools/create_document_with_properties/index.d.ts +60 -0
- package/build/tools/create_document_with_properties/index.js +6 -0
- package/build/tools/create_document_with_properties/index.js.map +1 -0
- package/build/tools/create_document_with_properties/params.d.ts +66 -0
- package/build/tools/generate_property/index.js +6 -0
- package/build/tools/generate_property/index.js.map +1 -0
- package/build/tools/index.d.ts +184 -0
- package/build/tools/organize_attachments/index.js +6 -0
- package/build/tools/organize_attachments/index.js.map +1 -0
- package/build/tools/organize_attachments/params.d.ts +122 -0
- package/build/tools/vault/index.js +16 -2
- package/build/tools/vault/index.js.map +1 -0
- package/build/tools/vault/params.d.ts +115 -0
- package/build/tools/vault/types/collect_context.d.ts +1340 -0
- package/build/tools/vault/types/list_all.d.ts +387 -0
- package/build/tools/vault/types/read_specific.d.ts +297 -0
- package/build/tools/vault/types/search.d.ts +598 -0
- package/build/tools/vault/utils/actions/collect_context.js +26 -1
- package/build/tools/vault/utils/actions/collect_context.js.map +1 -0
- package/build/tools/vault/utils/actions/index_rag.js +27 -0
- package/build/tools/vault/utils/actions/index_rag.js.map +1 -0
- package/build/tools/vault/utils/actions/list_all.js +1 -0
- package/build/tools/vault/utils/actions/list_all.js.map +1 -0
- package/build/tools/vault/utils/actions/load_memory.js +23 -13
- package/build/tools/vault/utils/actions/load_memory.js.map +1 -0
- package/build/tools/vault/utils/actions/read.js +2 -1
- package/build/tools/vault/utils/actions/read.js.map +1 -0
- package/build/tools/vault/utils/actions/search.js +2 -1
- package/build/tools/vault/utils/actions/search.js.map +1 -0
- package/build/tools/vault/utils/actions/search_semantic.js +54 -0
- package/build/tools/vault/utils/actions/search_semantic.js.map +1 -0
- package/build/tools/vault/utils/actions/stats.js +1 -0
- package/build/tools/vault/utils/actions/stats.js.map +1 -0
- package/build/tools/vault/utils/document.js +1 -0
- package/build/tools/vault/utils/document.js.map +1 -0
- package/build/tools/write_property/index.d.ts +58 -0
- package/build/tools/write_property/index.js +6 -0
- package/build/tools/write_property/index.js.map +1 -0
- package/build/utils/DirectoryWalker.d.ts +6 -0
- package/build/utils/DirectoryWalker.js +7 -0
- package/build/utils/DirectoryWalker.js.map +1 -0
- package/build/utils/Indexer.d.ts +18 -0
- package/build/utils/Indexer.js +5 -9
- package/build/utils/Indexer.js.map +1 -0
- package/build/utils/LLMClient.d.ts +37 -0
- package/build/utils/LLMClient.js +82 -0
- package/build/utils/LLMClient.js.map +1 -0
- package/build/utils/RAGIndexer.d.ts +22 -0
- package/build/utils/RAGIndexer.js +206 -0
- package/build/utils/RAGIndexer.js.map +1 -0
- package/build/utils/RerankerClient.d.ts +27 -0
- package/build/utils/RerankerClient.js +69 -0
- package/build/utils/RerankerClient.js.map +1 -0
- package/build/utils/VaultManger/VaultManager.d.ts +34 -0
- package/build/utils/VaultManger/VaultManager.js +1 -0
- package/build/utils/VaultManger/VaultManager.js.map +1 -0
- package/build/utils/VaultManger/VaultPathError.d.ts +6 -0
- package/build/utils/VaultManger/VaultPathError.js +1 -0
- package/build/utils/VaultManger/VaultPathError.js.map +1 -0
- package/build/utils/VaultManger/index.d.ts +3 -0
- package/build/utils/VaultManger/index.js +1 -0
- package/build/utils/VaultManger/index.js.map +1 -0
- package/build/utils/VaultManger/types.d.ts +16 -0
- package/build/utils/VaultManger/types.js +1 -0
- package/build/utils/VaultManger/types.js.map +1 -0
- package/build/utils/VaultWatcher.d.ts +8 -0
- package/build/utils/VaultWatcher.js +96 -0
- package/build/utils/VaultWatcher.js.map +1 -0
- package/build/utils/VectorDB.d.ts +53 -0
- package/build/utils/VectorDB.js +243 -0
- package/build/utils/VectorDB.js.map +1 -0
- package/build/utils/createToolError.d.ts +2 -0
- package/build/utils/createToolError.js +1 -0
- package/build/utils/createToolError.js.map +1 -0
- package/build/utils/getVaultManager.d.ts +2 -0
- package/build/utils/getVaultManager.js +1 -0
- package/build/utils/getVaultManager.js.map +1 -0
- package/build/utils/processor/LinkExtractor.d.ts +2 -0
- package/build/utils/processor/LinkExtractor.js +1 -0
- package/build/utils/processor/LinkExtractor.js.map +1 -0
- package/build/utils/processor/MatterParser.d.ts +2 -0
- package/build/utils/processor/MatterParser.js +12 -3
- package/build/utils/processor/MatterParser.js.map +1 -0
- package/build/utils/processor/types.d.ts +100 -0
- package/package.json +28 -7
- package/build/server.js +0 -32
- package/build/tools/create_document_with_properties/params.js +0 -32
- package/build/tools/generate_property/params.js +0 -54
- package/build/tools/index.js +0 -12
- package/build/tools/organize_attachments/params.js +0 -60
- package/build/tools/organize_attachments/utils.js +0 -65
- package/build/tools/vault/metrics.js +0 -126
- package/build/tools/vault/params.js +0 -141
- package/build/tools/vault/types/collect_context.js +0 -102
- package/build/tools/vault/types/list_all.js +0 -52
- package/build/tools/vault/types/read_specific.js +0 -40
- package/build/tools/vault/types/search.js +0 -58
- package/build/tools/vault/utils/constants.js +0 -2
- package/build/tools/vault/utils/shared.js +0 -74
- package/build/tools/vault/utils.js +0 -6
- package/build/tools/write_property/params.js +0 -51
- package/build/utils/processor/types.js +0 -27
- package/build/utils/semaphore.js +0 -25
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { Colors } from "../colors.js";
|
|
4
|
+
import { CommandKind } from "../commands/types.js";
|
|
5
|
+
import { theme } from "../theme/semantic-colors.js";
|
|
6
|
+
import { sanitizeForDisplay } from "../utils/textUtil.js";
|
|
7
|
+
import { ExpandableText, MAX_WIDTH } from "./shared/ExpandableText.js";
|
|
8
|
+
export const MAX_SUGGESTIONS_TO_SHOW = 8;
|
|
9
|
+
export { MAX_WIDTH };
|
|
10
|
+
export function SuggestionsDisplay({ suggestions, activeIndex, isLoading, width, scrollOffset, userInput, mode, expandedIndex, }) {
|
|
11
|
+
if (isLoading) {
|
|
12
|
+
return (_jsx(Box, { paddingX: 1, width: width, children: _jsx(Text, { color: "gray", children: "Loading suggestions..." }) }));
|
|
13
|
+
}
|
|
14
|
+
if (suggestions.length === 0) {
|
|
15
|
+
return null; // Don't render anything if there are no suggestions
|
|
16
|
+
}
|
|
17
|
+
// Calculate the visible slice based on scrollOffset
|
|
18
|
+
const startIndex = scrollOffset;
|
|
19
|
+
const endIndex = Math.min(scrollOffset + MAX_SUGGESTIONS_TO_SHOW, suggestions.length);
|
|
20
|
+
const visibleSuggestions = suggestions.slice(startIndex, endIndex);
|
|
21
|
+
const COMMAND_KIND_SUFFIX = {
|
|
22
|
+
[CommandKind.MCP_PROMPT]: " [MCP]",
|
|
23
|
+
[CommandKind.AGENT]: " [Agent]",
|
|
24
|
+
};
|
|
25
|
+
const getFullLabel = (s) => s.label + (s.commandKind ? (COMMAND_KIND_SUFFIX[s.commandKind] ?? "") : "");
|
|
26
|
+
const maxLabelLength = Math.max(...suggestions.map((s) => getFullLabel(s).length));
|
|
27
|
+
const commandColumnWidth = mode === "slash" ? Math.min(maxLabelLength, Math.floor(width * 0.5)) : 0;
|
|
28
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, width: width, children: [scrollOffset > 0 && _jsx(Text, { color: theme.text.primary, children: "\u25B2" }), visibleSuggestions.map((suggestion, index) => {
|
|
29
|
+
const originalIndex = startIndex + index;
|
|
30
|
+
const isActive = originalIndex === activeIndex;
|
|
31
|
+
const isExpanded = originalIndex === expandedIndex;
|
|
32
|
+
const textColor = isActive ? theme.ui.focus : theme.text.secondary;
|
|
33
|
+
const isLong = suggestion.value.length >= MAX_WIDTH;
|
|
34
|
+
const previousSectionTitle = suggestions[originalIndex - 1]?.sectionTitle;
|
|
35
|
+
const shouldRenderSectionHeader = mode === "slash" &&
|
|
36
|
+
!!suggestion.sectionTitle &&
|
|
37
|
+
suggestion.sectionTitle !== previousSectionTitle;
|
|
38
|
+
const labelElement = (_jsx(ExpandableText, { label: suggestion.value, matchedIndex: suggestion.matchedIndex, userInput: userInput, textColor: textColor, isExpanded: isExpanded }));
|
|
39
|
+
return (_jsxs(Box, { flexDirection: "column", children: [shouldRenderSectionHeader && (_jsxs(Text, { color: theme.text.secondary, children: ["-- ", suggestion.sectionTitle, " --"] })), _jsxs(Box, { flexDirection: "row", backgroundColor: isActive ? theme.background.focus : undefined, children: [_jsx(Box, { ...(mode === "slash"
|
|
40
|
+
? { width: commandColumnWidth, flexShrink: 0 }
|
|
41
|
+
: { flexShrink: 1 }), children: _jsxs(Box, { children: [labelElement, suggestion.commandKind &&
|
|
42
|
+
COMMAND_KIND_SUFFIX[suggestion.commandKind] && (_jsx(Text, { color: textColor, children: COMMAND_KIND_SUFFIX[suggestion.commandKind] }))] }) }), suggestion.description && (_jsx(Box, { flexGrow: 1, paddingLeft: 3, children: _jsx(Text, { color: textColor, wrap: "truncate", children: sanitizeForDisplay(suggestion.description, 100) }) })), isActive && isLong && (_jsx(Box, { width: 3, flexShrink: 0, children: _jsx(Text, { color: Colors.Gray, children: isExpanded ? " ← " : " → " }) }))] })] }, `${suggestion.value}-${originalIndex}`));
|
|
43
|
+
}), endIndex < suggestions.length && _jsx(Text, { color: "gray", children: "\u25BC" }), suggestions.length > MAX_SUGGESTIONS_TO_SHOW && (_jsxs(Text, { color: "gray", children: ["(", activeIndex + 1, "/", suggestions.length, ")"] }))] }));
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=SuggestionsDisplay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuggestionsDisplay.js","sourceRoot":"","sources":["../../../src/cli/ui/SuggestionsDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAuBvE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,CAAC;AAErB,MAAM,UAAU,kBAAkB,CAAC,EAClC,WAAW,EACX,WAAW,EACX,SAAS,EACT,KAAK,EACL,YAAY,EACZ,SAAS,EACT,IAAI,EACJ,aAAa,GACY;IACzB,IAAI,SAAS,EAAE,CAAC;QACf,OAAO,CACN,KAAC,GAAG,IAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,YAC7B,KAAC,IAAI,I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0,0 +1,16 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
5
|
+
const FRAME_INTERVAL_MS = 80;
|
|
6
|
+
export const ThinkingIndicator = () => {
|
|
7
|
+
const [frameIndex, setFrameIndex] = useState(0);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const timer = setInterval(() => {
|
|
10
|
+
setFrameIndex((prev) => (prev + 1) % SPINNER_FRAMES.length);
|
|
11
|
+
}, FRAME_INTERVAL_MS);
|
|
12
|
+
return () => clearInterval(timer);
|
|
13
|
+
}, []);
|
|
14
|
+
return (_jsx(Box, { paddingX: 1, marginBottom: 1, marginTop: 1, children: _jsxs(Text, { color: "cyan", children: [SPINNER_FRAMES[frameIndex], " Thinking..."] }) }));
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=ThinkingIndicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThinkingIndicator.js","sourceRoot":"","sources":["../../../src/cli/ui/ThinkingIndicator.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAC1E,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,MAAM,CAAC,MAAM,iBAAiB,GAAa,GAAG,EAAE;IAC/C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEhD,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YAC9B,aAAa,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;QAC7D,CAAC,EAAE,iBAAiB,CAAC,CAAC;QAEtB,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACN,KAAC,GAAG,IAAC,QAAQ,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,YAC9C,MAAC,IAAI,IAAC,KAAK,EAAC,MAAM,aAAE,cAAc,CAAC,UAAU,CAAC,oBAAoB,GAC7D,CACN,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultAppLayout.js","sourceRoot":"","sources":["../../../../src/cli/ui/layout/DefaultAppLayout.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1B,MAAM,CAAC,MAAM,gBAAgB,GAAa,GAAG,EAAE;IAC9C,OAAO,KAAC,GAAG,IAAC,aAAa,EAAC,QAAQ,EAAC,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,GAAQ,CAAC;AACvE,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
export declare const MAX_WIDTH = 120;
|
|
3
|
+
interface ExpandableTextProps {
|
|
4
|
+
label: string;
|
|
5
|
+
matchedIndex?: number;
|
|
6
|
+
userInput?: string;
|
|
7
|
+
textColor?: string;
|
|
8
|
+
isExpanded?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Renders a suggestion label, highlighting the matched portion if provided.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ExpandableText({ label, matchedIndex, userInput, textColor, isExpanded: _isExpanded, }: ExpandableTextProps): ReactElement;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Text } from "ink";
|
|
3
|
+
export const MAX_WIDTH = 120;
|
|
4
|
+
/**
|
|
5
|
+
* Renders a suggestion label, highlighting the matched portion if provided.
|
|
6
|
+
*/
|
|
7
|
+
export function ExpandableText({ label, matchedIndex, userInput, textColor, isExpanded: _isExpanded, }) {
|
|
8
|
+
if (matchedIndex !== undefined &&
|
|
9
|
+
matchedIndex >= 0 &&
|
|
10
|
+
userInput &&
|
|
11
|
+
userInput.length > 0) {
|
|
12
|
+
const before = label.slice(0, matchedIndex);
|
|
13
|
+
const match = label.slice(matchedIndex, matchedIndex + userInput.length);
|
|
14
|
+
const after = label.slice(matchedIndex + userInput.length);
|
|
15
|
+
return (_jsxs(Text, { color: textColor, children: [before, _jsx(Text, { bold: true, children: match }), after] }));
|
|
16
|
+
}
|
|
17
|
+
return _jsx(Text, { color: textColor, children: label });
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ExpandableText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpandableText.js","sourceRoot":"","sources":["../../../../src/cli/ui/shared/ExpandableText.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAG3B,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC;AAU7B;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,EAC9B,KAAK,EACL,YAAY,EACZ,SAAS,EACT,SAAS,EACT,UAAU,EAAE,WAAW,GACF;IACrB,IACC,YAAY,KAAK,SAAS;QAC1B,YAAY,IAAI,CAAC;QACjB,SAAS;QACT,SAAS,CAAC,MAAM,GAAG,CAAC,EACnB,CAAC;QACF,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;QAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,EAAE,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QACzE,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAC3D,OAAO,CACN,MAAC,IAAI,IAAC,KAAK,EAAE,SAAS,aACpB,MAAM,EACP,KAAC,IAAI,IAAC,IAAI,kBAAE,KAAK,GAAQ,EACxB,KAAK,IACA,CACP,CAAC;IACH,CAAC;IACD,OAAO,KAAC,IAAI,IAAC,KAAK,EAAE,SAAS,YAAG,KAAK,GAAQ,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for command parsing.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Returns true if the trimmed text begins with '/', indicating a slash command.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isSlashCommand(text: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Returns true if the trimmed text begins with '@', indicating an at-command.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isAtCommand(text: string): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for command parsing.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Returns true if the trimmed text begins with '/', indicating a slash command.
|
|
6
|
+
*/
|
|
7
|
+
export function isSlashCommand(text) {
|
|
8
|
+
return text.trimStart().startsWith("/");
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the trimmed text begins with '@', indicating an at-command.
|
|
12
|
+
*/
|
|
13
|
+
export function isAtCommand(text) {
|
|
14
|
+
return text.trimStart().startsWith("@");
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=commandUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandUtils.js","sourceRoot":"","sources":["../../../src/cli/utils/commandUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IAC1C,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare class DebugLogger {
|
|
2
|
+
private logStream;
|
|
3
|
+
constructor();
|
|
4
|
+
private writeToFile;
|
|
5
|
+
info(...args: unknown[]): void;
|
|
6
|
+
log(...args: unknown[]): void;
|
|
7
|
+
warn(...args: unknown[]): void;
|
|
8
|
+
error(...args: unknown[]): void;
|
|
9
|
+
debug(...args: unknown[]): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const debugLogger: DebugLogger;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import * as util from "node:util";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
class DebugLogger {
|
|
6
|
+
logStream;
|
|
7
|
+
constructor() {
|
|
8
|
+
const logFilePath = process.env["DEBUG_LOG_FILE"];
|
|
9
|
+
if (logFilePath) {
|
|
10
|
+
const logDir = dirname(logFilePath);
|
|
11
|
+
if (!fs.existsSync(logDir)) {
|
|
12
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
this.logStream = fs.createWriteStream(logFilePath, {
|
|
15
|
+
flags: "a",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
this.logStream?.on("error", (err) => {
|
|
19
|
+
console.error(chalk.red("[STREAM_ERROR]"), chalk.gray(util.format("Error writing to debug log stream:", err)));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
writeToFile(level, args) {
|
|
23
|
+
if (this.logStream) {
|
|
24
|
+
const message = util.format(...args);
|
|
25
|
+
const timestamp = new Date().toISOString();
|
|
26
|
+
const logEntry = `[${timestamp}] [${level}] ${message}\n`;
|
|
27
|
+
this.logStream.write(logEntry);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
info(...args) {
|
|
31
|
+
this.writeToFile("INFO", args);
|
|
32
|
+
console.info(chalk.green("[INFO]"), chalk.gray(util.format(...args)));
|
|
33
|
+
}
|
|
34
|
+
log(...args) {
|
|
35
|
+
this.writeToFile("LOG", args);
|
|
36
|
+
console.log(chalk.blue("[LOG]"), chalk.white(util.format(...args)));
|
|
37
|
+
}
|
|
38
|
+
warn(...args) {
|
|
39
|
+
this.writeToFile("WARN", args);
|
|
40
|
+
console.warn(chalk.yellow("[WARN]"), chalk.gray(util.format(...args)));
|
|
41
|
+
}
|
|
42
|
+
error(...args) {
|
|
43
|
+
this.writeToFile("ERROR", args);
|
|
44
|
+
console.error(chalk.red("[ERROR]"), chalk.gray(util.format(...args)));
|
|
45
|
+
}
|
|
46
|
+
debug(...args) {
|
|
47
|
+
this.writeToFile("DEBUG", args);
|
|
48
|
+
console.debug(chalk.magenta("[DEBUG]"), chalk.gray(util.format(...args)));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export const debugLogger = new DebugLogger();
|
|
52
|
+
//# sourceMappingURL=debugLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugLogger.js","sourceRoot":"","sources":["../../../src/cli/utils/debugLogger.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO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I,CAAC,CAAC,CAAC,CAAC;IAC3E,CAAC;CACD;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface HistoryItem {
|
|
2
|
+
text: string;
|
|
3
|
+
timestamp: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class HistoryStorage {
|
|
6
|
+
private filePath;
|
|
7
|
+
constructor(filePath?: string);
|
|
8
|
+
getPreviousUserMessages(): Promise<string[]>;
|
|
9
|
+
appendMessage(text: string): Promise<void>;
|
|
10
|
+
private getRawItems;
|
|
11
|
+
private saveItems;
|
|
12
|
+
}
|
|
13
|
+
export declare const historyStorage: HistoryStorage;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { debugLogger } from "./debugLogger.js";
|
|
5
|
+
const HISTORY_FILE_PATH = path.join(os.homedir(), ".obsidian-mcp-agent-history.json");
|
|
6
|
+
const EXPIRY_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
7
|
+
export class HistoryStorage {
|
|
8
|
+
filePath;
|
|
9
|
+
constructor(filePath = HISTORY_FILE_PATH) {
|
|
10
|
+
this.filePath = filePath;
|
|
11
|
+
}
|
|
12
|
+
async getPreviousUserMessages() {
|
|
13
|
+
try {
|
|
14
|
+
const data = await fs.readFile(this.filePath, "utf-8");
|
|
15
|
+
const parsed = JSON.parse(data);
|
|
16
|
+
const now = Date.now();
|
|
17
|
+
const validItems = parsed.filter((item) => now - item.timestamp <= EXPIRY_MS);
|
|
18
|
+
// If items were pruned, save back to file to save disk space
|
|
19
|
+
if (validItems.length < parsed.length) {
|
|
20
|
+
await this.saveItems(validItems);
|
|
21
|
+
}
|
|
22
|
+
// Return just the text values
|
|
23
|
+
return validItems.map((item) => item.text);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code !== "ENOENT") {
|
|
27
|
+
debugLogger.warn("Failed to read history storage", error);
|
|
28
|
+
}
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async appendMessage(text) {
|
|
33
|
+
try {
|
|
34
|
+
const currentMessages = await this.getRawItems();
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
// Prune old items first
|
|
37
|
+
const validItems = currentMessages.filter((item) => now - item.timestamp <= EXPIRY_MS);
|
|
38
|
+
validItems.push({ text, timestamp: now });
|
|
39
|
+
await this.saveItems(validItems);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
debugLogger.warn("Failed to append message to history storage", error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async getRawItems() {
|
|
46
|
+
try {
|
|
47
|
+
const data = await fs.readFile(this.filePath, "utf-8");
|
|
48
|
+
return JSON.parse(data);
|
|
49
|
+
}
|
|
50
|
+
catch (_error) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async saveItems(items) {
|
|
55
|
+
try {
|
|
56
|
+
await fs.writeFile(this.filePath, JSON.stringify(items, null, 2), "utf-8");
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
debugLogger.warn("Failed to save items to history storage", error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export const historyStorage = new HistoryStorage();
|
|
64
|
+
//# sourceMappingURL=historyStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"historyStorage.js","sourceRoot":"","sources":["../../../src/cli/utils/historyStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,iBAAiB,GAAG,IAAI,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
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the maximum width of a multi-line ASCII art string.
|
|
8
|
+
* @param asciiArt The ASCII art string.
|
|
9
|
+
* @returns The length of the longest line in the ASCII art.
|
|
10
|
+
*/
|
|
11
|
+
export declare const getAsciiArtWidth: (asciiArt: string) => number;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a string contains only ASCII characters (0-127).
|
|
14
|
+
*/
|
|
15
|
+
export declare function isAscii(str: string): boolean;
|
|
16
|
+
export declare function toCodePoints(str: string): string[];
|
|
17
|
+
export declare function cpLen(str: string): number;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a code point index to a UTF-16 code unit offset.
|
|
20
|
+
*/
|
|
21
|
+
export declare function cpIndexToOffset(str: string, cpIndex: number): number;
|
|
22
|
+
export declare function cpSlice(str: string, start: number, end?: number): string;
|
|
23
|
+
/**
|
|
24
|
+
* Strip characters that can break terminal rendering.
|
|
25
|
+
*
|
|
26
|
+
* This is a strict sanitization function intended for general display
|
|
27
|
+
* contexts. It strips all C1 control characters (0x80-0x9F) and VT
|
|
28
|
+
* control sequences. For list display contexts where a more lenient
|
|
29
|
+
* approach is needed (preserving C1 characters and only stripping ANSI
|
|
30
|
+
* codes and newlines/tabs), use a separate function instead.
|
|
31
|
+
*
|
|
32
|
+
* Processing order:
|
|
33
|
+
* 1. stripAnsi removes ANSI escape sequences (including 8-bit CSI 0x9B)
|
|
34
|
+
* 2. Regex strips C0, C1, BiDi, and zero-width control characters
|
|
35
|
+
* 3. stripVTControlCharacters removes any remaining VT sequences
|
|
36
|
+
*
|
|
37
|
+
* Characters stripped:
|
|
38
|
+
* - ANSI escape sequences (via strip-ansi)
|
|
39
|
+
* - VT control sequences (via Node.js util.stripVTControlCharacters)
|
|
40
|
+
* - C0 control chars (0x00-0x1F) except TAB(0x09), LF(0x0A), CR(0x0D)
|
|
41
|
+
* - C1 control chars (0x80-0x9F) that can cause display issues
|
|
42
|
+
* - BiDi control chars (U+200E, U+200F, U+202A-U+202E, U+2066-U+2069)
|
|
43
|
+
* - Zero-width chars (U+200B, U+FEFF)
|
|
44
|
+
*
|
|
45
|
+
* Characters preserved:
|
|
46
|
+
* - All printable Unicode including emojis
|
|
47
|
+
* - ZWJ (U+200D) - needed for complex emoji sequences
|
|
48
|
+
* - ZWNJ (U+200C) - preserve zero-width non-joiner
|
|
49
|
+
* - DEL (0x7F) - handled functionally by applyOperations, not a display issue
|
|
50
|
+
* - CR/LF (0x0D/0x0A) - needed for line breaks
|
|
51
|
+
* - TAB (0x09) - preserve tabs
|
|
52
|
+
*/
|
|
53
|
+
export declare function stripUnsafeCharacters(str: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Sanitize a string for display in inline UI components (e.g. Help, Suggestions).
|
|
56
|
+
* Removes ANSI codes, dangerous control characters, collapses whitespace
|
|
57
|
+
* characters into a single space, and optionally truncates.
|
|
58
|
+
*/
|
|
59
|
+
export declare function sanitizeForDisplay(str: string, maxLength?: number): string;
|
|
60
|
+
/**
|
|
61
|
+
* Normalizes escaped newline characters (e.g., "\\n") into actual newline characters.
|
|
62
|
+
*/
|
|
63
|
+
export declare function normalizeEscapedNewlines(value: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Cached version of stringWidth function for better performance
|
|
66
|
+
*/
|
|
67
|
+
export declare const getCachedStringWidth: (str: string) => number;
|
|
68
|
+
export declare function escapeAnsiCtrlCodes<T>(obj: T): T;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { stripVTControlCharacters } from "node:util";
|
|
7
|
+
import ansiRegex from "ansi-regex";
|
|
8
|
+
import { LRUCache } from "mnemonist";
|
|
9
|
+
import stringWidth from "string-width";
|
|
10
|
+
import stripAnsi from "strip-ansi";
|
|
11
|
+
import { LRU_BUFFER_PERF_CACHE_LIMIT } from "../constants.js";
|
|
12
|
+
/**
|
|
13
|
+
* Calculates the maximum width of a multi-line ASCII art string.
|
|
14
|
+
* @param asciiArt The ASCII art string.
|
|
15
|
+
* @returns The length of the longest line in the ASCII art.
|
|
16
|
+
*/
|
|
17
|
+
export const getAsciiArtWidth = (asciiArt) => {
|
|
18
|
+
if (!asciiArt) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
const lines = asciiArt.split("\n");
|
|
22
|
+
return Math.max(...lines.map((line) => line.length));
|
|
23
|
+
};
|
|
24
|
+
/*
|
|
25
|
+
* -------------------------------------------------------------------------
|
|
26
|
+
* Unicode‑aware helpers (work at the code‑point level rather than UTF‑16
|
|
27
|
+
* code units so that surrogate‑pair emoji count as one "column".)
|
|
28
|
+
* ---------------------------------------------------------------------- */
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a string contains only ASCII characters (0-127).
|
|
31
|
+
*/
|
|
32
|
+
export function isAscii(str) {
|
|
33
|
+
for (let i = 0; i < str.length; i++) {
|
|
34
|
+
if (str.charCodeAt(i) > 127) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
// Cache for code points
|
|
41
|
+
const MAX_STRING_LENGTH_TO_CACHE = 1000;
|
|
42
|
+
const codePointsCache = new LRUCache(LRU_BUFFER_PERF_CACHE_LIMIT);
|
|
43
|
+
export function toCodePoints(str) {
|
|
44
|
+
// ASCII fast path
|
|
45
|
+
if (isAscii(str)) {
|
|
46
|
+
return str.split("");
|
|
47
|
+
}
|
|
48
|
+
// Cache short strings
|
|
49
|
+
if (str.length <= MAX_STRING_LENGTH_TO_CACHE) {
|
|
50
|
+
const cached = codePointsCache.get(str);
|
|
51
|
+
if (cached !== undefined) {
|
|
52
|
+
return cached;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const result = Array.from(str);
|
|
56
|
+
// Cache result
|
|
57
|
+
if (str.length <= MAX_STRING_LENGTH_TO_CACHE) {
|
|
58
|
+
codePointsCache.set(str, result);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
export function cpLen(str) {
|
|
63
|
+
if (isAscii(str)) {
|
|
64
|
+
return str.length;
|
|
65
|
+
}
|
|
66
|
+
return toCodePoints(str).length;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Converts a code point index to a UTF-16 code unit offset.
|
|
70
|
+
*/
|
|
71
|
+
export function cpIndexToOffset(str, cpIndex) {
|
|
72
|
+
return cpSlice(str, 0, cpIndex).length;
|
|
73
|
+
}
|
|
74
|
+
export function cpSlice(str, start, end) {
|
|
75
|
+
if (isAscii(str)) {
|
|
76
|
+
return str.slice(start, end);
|
|
77
|
+
}
|
|
78
|
+
// Slice by code‑point indices and re‑join.
|
|
79
|
+
const arr = toCodePoints(str).slice(start, end);
|
|
80
|
+
return arr.join("");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Strip characters that can break terminal rendering.
|
|
84
|
+
*
|
|
85
|
+
* This is a strict sanitization function intended for general display
|
|
86
|
+
* contexts. It strips all C1 control characters (0x80-0x9F) and VT
|
|
87
|
+
* control sequences. For list display contexts where a more lenient
|
|
88
|
+
* approach is needed (preserving C1 characters and only stripping ANSI
|
|
89
|
+
* codes and newlines/tabs), use a separate function instead.
|
|
90
|
+
*
|
|
91
|
+
* Processing order:
|
|
92
|
+
* 1. stripAnsi removes ANSI escape sequences (including 8-bit CSI 0x9B)
|
|
93
|
+
* 2. Regex strips C0, C1, BiDi, and zero-width control characters
|
|
94
|
+
* 3. stripVTControlCharacters removes any remaining VT sequences
|
|
95
|
+
*
|
|
96
|
+
* Characters stripped:
|
|
97
|
+
* - ANSI escape sequences (via strip-ansi)
|
|
98
|
+
* - VT control sequences (via Node.js util.stripVTControlCharacters)
|
|
99
|
+
* - C0 control chars (0x00-0x1F) except TAB(0x09), LF(0x0A), CR(0x0D)
|
|
100
|
+
* - C1 control chars (0x80-0x9F) that can cause display issues
|
|
101
|
+
* - BiDi control chars (U+200E, U+200F, U+202A-U+202E, U+2066-U+2069)
|
|
102
|
+
* - Zero-width chars (U+200B, U+FEFF)
|
|
103
|
+
*
|
|
104
|
+
* Characters preserved:
|
|
105
|
+
* - All printable Unicode including emojis
|
|
106
|
+
* - ZWJ (U+200D) - needed for complex emoji sequences
|
|
107
|
+
* - ZWNJ (U+200C) - preserve zero-width non-joiner
|
|
108
|
+
* - DEL (0x7F) - handled functionally by applyOperations, not a display issue
|
|
109
|
+
* - CR/LF (0x0D/0x0A) - needed for line breaks
|
|
110
|
+
* - TAB (0x09) - preserve tabs
|
|
111
|
+
*/
|
|
112
|
+
export function stripUnsafeCharacters(str) {
|
|
113
|
+
const strippedAnsi = stripAnsi(str);
|
|
114
|
+
// Strip C0, C1, and other unsafe characters via regex first.
|
|
115
|
+
// This is more efficient than multiple replaces and crucially removes C1
|
|
116
|
+
// characters (e.g., 0x90 DCS) before they can be misinterpreted by
|
|
117
|
+
// stripVTControlCharacters, which could otherwise cause data loss.
|
|
118
|
+
const strippedWithRegex = strippedAnsi.replace(
|
|
119
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex:터미널 입력을 파싱하기 위한 정규식입니다.
|
|
120
|
+
/[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\x9F\u200E\u200F\u202A-\u202E\u2066-\u2069\u200B\uFEFF]/g, "");
|
|
121
|
+
// Finally, use stripVTControlCharacters for any remaining VT sequences
|
|
122
|
+
// that the regex might not cover.
|
|
123
|
+
return stripVTControlCharacters(strippedWithRegex);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Sanitize a string for display in inline UI components (e.g. Help, Suggestions).
|
|
127
|
+
* Removes ANSI codes, dangerous control characters, collapses whitespace
|
|
128
|
+
* characters into a single space, and optionally truncates.
|
|
129
|
+
*/
|
|
130
|
+
export function sanitizeForDisplay(str, maxLength) {
|
|
131
|
+
if (!str) {
|
|
132
|
+
return "";
|
|
133
|
+
}
|
|
134
|
+
let sanitized = stripUnsafeCharacters(str).replace(/\s+/g, " ");
|
|
135
|
+
if (maxLength && sanitized.length > maxLength) {
|
|
136
|
+
sanitized = `${sanitized.substring(0, maxLength - 3)}...`;
|
|
137
|
+
}
|
|
138
|
+
return sanitized;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Normalizes escaped newline characters (e.g., "\\n") into actual newline characters.
|
|
142
|
+
*/
|
|
143
|
+
export function normalizeEscapedNewlines(value) {
|
|
144
|
+
return value.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");
|
|
145
|
+
}
|
|
146
|
+
const stringWidthCache = new LRUCache(LRU_BUFFER_PERF_CACHE_LIMIT);
|
|
147
|
+
/**
|
|
148
|
+
* Cached version of stringWidth function for better performance
|
|
149
|
+
*/
|
|
150
|
+
export const getCachedStringWidth = (str) => {
|
|
151
|
+
// ASCII printable chars (32-126) have width 1.
|
|
152
|
+
// This is a very frequent path, so we use a fast numeric check.
|
|
153
|
+
if (str.length === 1) {
|
|
154
|
+
const code = str.charCodeAt(0);
|
|
155
|
+
if (code >= 0x20 && code <= 0x7e) {
|
|
156
|
+
return 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const cached = stringWidthCache.get(str);
|
|
160
|
+
if (cached !== undefined) {
|
|
161
|
+
return cached;
|
|
162
|
+
}
|
|
163
|
+
let width;
|
|
164
|
+
try {
|
|
165
|
+
width = stringWidth(str);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
// Fallback for characters that cause string-width to crash (e.g. U+0602)
|
|
169
|
+
// See: https://github.com/google-gemini/gemini-cli/issues/16418
|
|
170
|
+
width = toCodePoints(stripAnsi(str)).length;
|
|
171
|
+
}
|
|
172
|
+
stringWidthCache.set(str, width);
|
|
173
|
+
return width;
|
|
174
|
+
};
|
|
175
|
+
const regex = ansiRegex();
|
|
176
|
+
/* Recursively traverses a JSON-like structure (objects, arrays, primitives)
|
|
177
|
+
* and escapes all ANSI control characters found in any string values.
|
|
178
|
+
*
|
|
179
|
+
* This function is designed to be robust, handling deeply nested objects and
|
|
180
|
+
* arrays. It applies a regex-based replacement to all string values to
|
|
181
|
+
* safely escape control characters.
|
|
182
|
+
*
|
|
183
|
+
* To optimize performance, this function uses a "copy-on-write" strategy.
|
|
184
|
+
* It avoids allocating new objects or arrays if no nested string values
|
|
185
|
+
* required escaping, returning the original object reference in such cases.
|
|
186
|
+
*
|
|
187
|
+
* @param obj The JSON-like value (object, array, string, etc.) to traverse.
|
|
188
|
+
* @returns A new value with all nested string fields escaped, or the
|
|
189
|
+
* original `obj` reference if no changes were necessary.
|
|
190
|
+
*/
|
|
191
|
+
export function escapeAnsiCtrlCodes(obj) {
|
|
192
|
+
if (typeof obj === "string") {
|
|
193
|
+
if (obj.search(regex) === -1) {
|
|
194
|
+
return obj; // No changes return original string
|
|
195
|
+
}
|
|
196
|
+
regex.lastIndex = 0; // needed for global regex
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
198
|
+
return obj.replace(regex, (match) => JSON.stringify(match).slice(1, -1));
|
|
199
|
+
}
|
|
200
|
+
if (obj === null || typeof obj !== "object") {
|
|
201
|
+
return obj;
|
|
202
|
+
}
|
|
203
|
+
if (Array.isArray(obj)) {
|
|
204
|
+
let newArr = null;
|
|
205
|
+
for (let i = 0; i < obj.length; i++) {
|
|
206
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
207
|
+
const value = obj[i];
|
|
208
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
209
|
+
const escapedValue = escapeAnsiCtrlCodes(value);
|
|
210
|
+
if (escapedValue !== value) {
|
|
211
|
+
if (newArr === null) {
|
|
212
|
+
newArr = [...obj];
|
|
213
|
+
}
|
|
214
|
+
newArr[i] = escapedValue;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
218
|
+
return (newArr !== null ? newArr : obj);
|
|
219
|
+
}
|
|
220
|
+
let newObj = null;
|
|
221
|
+
const keys = Object.keys(obj);
|
|
222
|
+
for (const key of keys) {
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
224
|
+
const value = obj[key];
|
|
225
|
+
const escapedValue = escapeAnsiCtrlCodes(value);
|
|
226
|
+
if (escapedValue !== value) {
|
|
227
|
+
if (newObj === null) {
|
|
228
|
+
newObj = { ...obj };
|
|
229
|
+
}
|
|
230
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
231
|
+
newObj[key] = escapedValue;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return newObj !== null ? newObj : obj;
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=textUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textUtil.js","sourceRoot":"","sources":["../../../src/cli/utils/textUtil.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC5D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,OAAO,CAAC,CAAC;IACV,CAAC;IACD,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnC,OAAO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