snow-ai 0.4.15 → 0.4.17
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/bundle/cli.mjs +477445 -0
- package/bundle/sql-wasm.wasm +0 -0
- package/package.json +31 -26
- package/dist/agents/codebaseIndexAgent.d.ts +0 -102
- package/dist/agents/codebaseIndexAgent.js +0 -641
- package/dist/agents/codebaseReviewAgent.d.ts +0 -61
- package/dist/agents/codebaseReviewAgent.js +0 -301
- package/dist/agents/compactAgent.d.ts +0 -55
- package/dist/agents/compactAgent.js +0 -306
- package/dist/agents/promptOptimizeAgent.d.ts +0 -54
- package/dist/agents/promptOptimizeAgent.js +0 -268
- package/dist/agents/reviewAgent.d.ts +0 -50
- package/dist/agents/reviewAgent.js +0 -265
- package/dist/agents/summaryAgent.d.ts +0 -57
- package/dist/agents/summaryAgent.js +0 -260
- package/dist/api/anthropic.d.ts +0 -44
- package/dist/api/anthropic.js +0 -598
- package/dist/api/chat.d.ts +0 -73
- package/dist/api/chat.js +0 -386
- package/dist/api/embedding.d.ts +0 -34
- package/dist/api/embedding.js +0 -80
- package/dist/api/gemini.d.ts +0 -31
- package/dist/api/gemini.js +0 -445
- package/dist/api/models.d.ts +0 -15
- package/dist/api/models.js +0 -139
- package/dist/api/responses.d.ts +0 -38
- package/dist/api/responses.js +0 -515
- package/dist/api/systemPrompt.d.ts +0 -4
- package/dist/api/systemPrompt.js +0 -408
- package/dist/api/types.d.ts +0 -53
- package/dist/api/types.js +0 -4
- package/dist/app.d.ts +0 -8
- package/dist/app.js +0 -112
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -199
- package/dist/hooks/useAgentPicker.d.ts +0 -14
- package/dist/hooks/useAgentPicker.js +0 -119
- package/dist/hooks/useClipboard.d.ts +0 -4
- package/dist/hooks/useClipboard.js +0 -175
- package/dist/hooks/useCommandHandler.d.ts +0 -35
- package/dist/hooks/useCommandHandler.js +0 -346
- package/dist/hooks/useCommandPanel.d.ts +0 -17
- package/dist/hooks/useCommandPanel.js +0 -114
- package/dist/hooks/useConversation.d.ts +0 -49
- package/dist/hooks/useConversation.js +0 -1052
- package/dist/hooks/useFilePicker.d.ts +0 -18
- package/dist/hooks/useFilePicker.js +0 -224
- package/dist/hooks/useGlobalExit.d.ts +0 -5
- package/dist/hooks/useGlobalExit.js +0 -34
- package/dist/hooks/useGlobalNavigation.d.ts +0 -6
- package/dist/hooks/useGlobalNavigation.js +0 -17
- package/dist/hooks/useHistoryNavigation.d.ts +0 -35
- package/dist/hooks/useHistoryNavigation.js +0 -133
- package/dist/hooks/useInputBuffer.d.ts +0 -6
- package/dist/hooks/useInputBuffer.js +0 -45
- package/dist/hooks/useKeyboardInput.d.ts +0 -80
- package/dist/hooks/useKeyboardInput.js +0 -608
- package/dist/hooks/useSessionManagement.d.ts +0 -10
- package/dist/hooks/useSessionManagement.js +0 -43
- package/dist/hooks/useSessionSave.d.ts +0 -8
- package/dist/hooks/useSessionSave.js +0 -63
- package/dist/hooks/useSnapshotState.d.ts +0 -26
- package/dist/hooks/useSnapshotState.js +0 -28
- package/dist/hooks/useStreamingState.d.ts +0 -33
- package/dist/hooks/useStreamingState.js +0 -105
- package/dist/hooks/useTerminalFocus.d.ts +0 -28
- package/dist/hooks/useTerminalFocus.js +0 -87
- package/dist/hooks/useTerminalSize.d.ts +0 -4
- package/dist/hooks/useTerminalSize.js +0 -20
- package/dist/hooks/useTodoPicker.d.ts +0 -16
- package/dist/hooks/useTodoPicker.js +0 -94
- package/dist/hooks/useToolConfirmation.d.ts +0 -19
- package/dist/hooks/useToolConfirmation.js +0 -61
- package/dist/hooks/useVSCodeState.d.ts +0 -8
- package/dist/hooks/useVSCodeState.js +0 -81
- package/dist/i18n/I18nContext.d.ts +0 -14
- package/dist/i18n/I18nContext.js +0 -24
- package/dist/i18n/index.d.ts +0 -3
- package/dist/i18n/index.js +0 -2
- package/dist/i18n/lang/en.d.ts +0 -2
- package/dist/i18n/lang/en.js +0 -502
- package/dist/i18n/lang/es.d.ts +0 -2
- package/dist/i18n/lang/es.js +0 -502
- package/dist/i18n/lang/ja.d.ts +0 -2
- package/dist/i18n/lang/ja.js +0 -502
- package/dist/i18n/lang/ko.d.ts +0 -2
- package/dist/i18n/lang/ko.js +0 -502
- package/dist/i18n/lang/zh-TW.d.ts +0 -2
- package/dist/i18n/lang/zh-TW.js +0 -502
- package/dist/i18n/lang/zh.d.ts +0 -2
- package/dist/i18n/lang/zh.js +0 -502
- package/dist/i18n/translations.d.ts +0 -2
- package/dist/i18n/translations.js +0 -14
- package/dist/i18n/types.d.ts +0 -478
- package/dist/i18n/types.js +0 -1
- package/dist/mcp/aceCodeSearch.d.ts +0 -247
- package/dist/mcp/aceCodeSearch.js +0 -1058
- package/dist/mcp/bash.d.ts +0 -50
- package/dist/mcp/bash.js +0 -153
- package/dist/mcp/codebaseSearch.d.ts +0 -44
- package/dist/mcp/codebaseSearch.js +0 -275
- package/dist/mcp/filesystem.d.ts +0 -392
- package/dist/mcp/filesystem.js +0 -1445
- package/dist/mcp/ideDiagnostics.d.ts +0 -36
- package/dist/mcp/ideDiagnostics.js +0 -90
- package/dist/mcp/notebook.d.ts +0 -10
- package/dist/mcp/notebook.js +0 -367
- package/dist/mcp/subagent.d.ts +0 -37
- package/dist/mcp/subagent.js +0 -113
- package/dist/mcp/todo.d.ts +0 -46
- package/dist/mcp/todo.js +0 -511
- package/dist/mcp/types/aceCodeSearch.types.d.ts +0 -92
- package/dist/mcp/types/aceCodeSearch.types.js +0 -4
- package/dist/mcp/types/bash.types.d.ts +0 -13
- package/dist/mcp/types/bash.types.js +0 -4
- package/dist/mcp/types/filesystem.types.d.ts +0 -210
- package/dist/mcp/types/filesystem.types.js +0 -27
- package/dist/mcp/types/todo.types.d.ts +0 -27
- package/dist/mcp/types/todo.types.js +0 -4
- package/dist/mcp/types/websearch.types.d.ts +0 -30
- package/dist/mcp/types/websearch.types.js +0 -4
- package/dist/mcp/utils/aceCodeSearch/filesystem.utils.d.ts +0 -34
- package/dist/mcp/utils/aceCodeSearch/filesystem.utils.js +0 -146
- package/dist/mcp/utils/aceCodeSearch/language.utils.d.ts +0 -14
- package/dist/mcp/utils/aceCodeSearch/language.utils.js +0 -418
- package/dist/mcp/utils/aceCodeSearch/search.utils.d.ts +0 -31
- package/dist/mcp/utils/aceCodeSearch/search.utils.js +0 -136
- package/dist/mcp/utils/aceCodeSearch/symbol.utils.d.ts +0 -20
- package/dist/mcp/utils/aceCodeSearch/symbol.utils.js +0 -141
- package/dist/mcp/utils/bash/security.utils.d.ts +0 -20
- package/dist/mcp/utils/bash/security.utils.js +0 -34
- package/dist/mcp/utils/filesystem/batch-operations.utils.d.ts +0 -39
- package/dist/mcp/utils/filesystem/batch-operations.utils.js +0 -182
- package/dist/mcp/utils/filesystem/code-analysis.utils.d.ts +0 -18
- package/dist/mcp/utils/filesystem/code-analysis.utils.js +0 -165
- package/dist/mcp/utils/filesystem/match-finder.utils.d.ts +0 -16
- package/dist/mcp/utils/filesystem/match-finder.utils.js +0 -85
- package/dist/mcp/utils/filesystem/office-parser.utils.d.ts +0 -43
- package/dist/mcp/utils/filesystem/office-parser.utils.js +0 -163
- package/dist/mcp/utils/filesystem/path-fixer.utils.d.ts +0 -7
- package/dist/mcp/utils/filesystem/path-fixer.utils.js +0 -60
- package/dist/mcp/utils/filesystem/similarity.utils.d.ts +0 -22
- package/dist/mcp/utils/filesystem/similarity.utils.js +0 -75
- package/dist/mcp/utils/todo/date.utils.d.ts +0 -9
- package/dist/mcp/utils/todo/date.utils.js +0 -14
- package/dist/mcp/utils/websearch/browser.utils.d.ts +0 -8
- package/dist/mcp/utils/websearch/browser.utils.js +0 -58
- package/dist/mcp/utils/websearch/text.utils.d.ts +0 -16
- package/dist/mcp/utils/websearch/text.utils.js +0 -39
- package/dist/mcp/websearch.d.ts +0 -88
- package/dist/mcp/websearch.js +0 -375
- package/dist/test/logger-test.d.ts +0 -1
- package/dist/test/logger-test.js +0 -7
- package/dist/types/index.d.ts +0 -15
- package/dist/types/index.js +0 -1
- package/dist/ui/components/AgentPickerPanel.d.ts +0 -10
- package/dist/ui/components/AgentPickerPanel.js +0 -74
- package/dist/ui/components/ChatInput.d.ts +0 -46
- package/dist/ui/components/ChatInput.js +0 -379
- package/dist/ui/components/CommandPanel.d.ts +0 -15
- package/dist/ui/components/CommandPanel.js +0 -80
- package/dist/ui/components/DiffViewer.d.ts +0 -11
- package/dist/ui/components/DiffViewer.js +0 -178
- package/dist/ui/components/FileList.d.ts +0 -15
- package/dist/ui/components/FileList.js +0 -360
- package/dist/ui/components/FileRollbackConfirmation.d.ts +0 -8
- package/dist/ui/components/FileRollbackConfirmation.js +0 -108
- package/dist/ui/components/HelpPanel.d.ts +0 -2
- package/dist/ui/components/HelpPanel.js +0 -67
- package/dist/ui/components/MCPInfoPanel.d.ts +0 -2
- package/dist/ui/components/MCPInfoPanel.js +0 -108
- package/dist/ui/components/MCPInfoScreen.d.ts +0 -7
- package/dist/ui/components/MCPInfoScreen.js +0 -115
- package/dist/ui/components/MarkdownRenderer.d.ts +0 -6
- package/dist/ui/components/MarkdownRenderer.js +0 -70
- package/dist/ui/components/Menu.d.ts +0 -17
- package/dist/ui/components/Menu.js +0 -88
- package/dist/ui/components/MessageList.d.ts +0 -56
- package/dist/ui/components/MessageList.js +0 -97
- package/dist/ui/components/PendingMessages.d.ts +0 -13
- package/dist/ui/components/PendingMessages.js +0 -29
- package/dist/ui/components/PendingToolCalls.d.ts +0 -11
- package/dist/ui/components/PendingToolCalls.js +0 -35
- package/dist/ui/components/ScrollableSelectInput.d.ts +0 -29
- package/dist/ui/components/ScrollableSelectInput.js +0 -157
- package/dist/ui/components/SessionListPanel.d.ts +0 -7
- package/dist/ui/components/SessionListPanel.js +0 -175
- package/dist/ui/components/SessionListScreen.d.ts +0 -7
- package/dist/ui/components/SessionListScreen.js +0 -217
- package/dist/ui/components/SessionListScreenWrapper.d.ts +0 -7
- package/dist/ui/components/SessionListScreenWrapper.js +0 -14
- package/dist/ui/components/ShimmerText.d.ts +0 -9
- package/dist/ui/components/ShimmerText.js +0 -30
- package/dist/ui/components/TodoPickerPanel.d.ts +0 -14
- package/dist/ui/components/TodoPickerPanel.js +0 -119
- package/dist/ui/components/TodoTree.d.ts +0 -15
- package/dist/ui/components/TodoTree.js +0 -60
- package/dist/ui/components/ToolConfirmation.d.ts +0 -21
- package/dist/ui/components/ToolConfirmation.js +0 -204
- package/dist/ui/components/ToolResultPreview.d.ts +0 -13
- package/dist/ui/components/ToolResultPreview.js +0 -337
- package/dist/ui/components/UsagePanel.d.ts +0 -2
- package/dist/ui/components/UsagePanel.js +0 -394
- package/dist/ui/contexts/ThemeContext.d.ts +0 -13
- package/dist/ui/contexts/ThemeContext.js +0 -28
- package/dist/ui/pages/ChatScreen.d.ts +0 -6
- package/dist/ui/pages/ChatScreen.js +0 -1495
- package/dist/ui/pages/CodeBaseConfigScreen.d.ts +0 -8
- package/dist/ui/pages/CodeBaseConfigScreen.js +0 -350
- package/dist/ui/pages/ConfigScreen.d.ts +0 -8
- package/dist/ui/pages/ConfigScreen.js +0 -1101
- package/dist/ui/pages/CustomHeadersScreen.d.ts +0 -6
- package/dist/ui/pages/CustomHeadersScreen.js +0 -502
- package/dist/ui/pages/HeadlessModeScreen.d.ts +0 -7
- package/dist/ui/pages/HeadlessModeScreen.js +0 -381
- package/dist/ui/pages/LanguageSettingsScreen.d.ts +0 -7
- package/dist/ui/pages/LanguageSettingsScreen.js +0 -91
- package/dist/ui/pages/MCPConfigScreen.d.ts +0 -6
- package/dist/ui/pages/MCPConfigScreen.js +0 -55
- package/dist/ui/pages/ProxyConfigScreen.d.ts +0 -8
- package/dist/ui/pages/ProxyConfigScreen.js +0 -149
- package/dist/ui/pages/SensitiveCommandConfigScreen.d.ts +0 -7
- package/dist/ui/pages/SensitiveCommandConfigScreen.js +0 -271
- package/dist/ui/pages/SubAgentConfigScreen.d.ts +0 -9
- package/dist/ui/pages/SubAgentConfigScreen.js +0 -435
- package/dist/ui/pages/SubAgentListScreen.d.ts +0 -9
- package/dist/ui/pages/SubAgentListScreen.js +0 -131
- package/dist/ui/pages/SystemPromptConfigScreen.d.ts +0 -6
- package/dist/ui/pages/SystemPromptConfigScreen.js +0 -326
- package/dist/ui/pages/ThemeSettingsScreen.d.ts +0 -7
- package/dist/ui/pages/ThemeSettingsScreen.js +0 -106
- package/dist/ui/pages/WelcomeScreen.d.ts +0 -7
- package/dist/ui/pages/WelcomeScreen.js +0 -217
- package/dist/ui/themes/index.d.ts +0 -23
- package/dist/ui/themes/index.js +0 -140
- package/dist/utils/apiConfig.d.ts +0 -126
- package/dist/utils/apiConfig.js +0 -423
- package/dist/utils/autoCompress.d.ts +0 -15
- package/dist/utils/autoCompress.js +0 -24
- package/dist/utils/chatExporter.d.ts +0 -9
- package/dist/utils/chatExporter.js +0 -118
- package/dist/utils/checkpointManager.d.ts +0 -74
- package/dist/utils/checkpointManager.js +0 -181
- package/dist/utils/codebaseConfig.d.ts +0 -16
- package/dist/utils/codebaseConfig.js +0 -67
- package/dist/utils/codebaseDatabase.d.ts +0 -102
- package/dist/utils/codebaseDatabase.js +0 -333
- package/dist/utils/codebaseSearchEvents.d.ts +0 -16
- package/dist/utils/codebaseSearchEvents.js +0 -13
- package/dist/utils/commandExecutor.d.ts +0 -13
- package/dist/utils/commandExecutor.js +0 -26
- package/dist/utils/commands/agent.d.ts +0 -2
- package/dist/utils/commands/agent.js +0 -12
- package/dist/utils/commands/clear.d.ts +0 -2
- package/dist/utils/commands/clear.js +0 -12
- package/dist/utils/commands/compact.d.ts +0 -2
- package/dist/utils/commands/compact.js +0 -12
- package/dist/utils/commands/export.d.ts +0 -2
- package/dist/utils/commands/export.js +0 -12
- package/dist/utils/commands/help.d.ts +0 -2
- package/dist/utils/commands/help.js +0 -11
- package/dist/utils/commands/home.d.ts +0 -2
- package/dist/utils/commands/home.js +0 -34
- package/dist/utils/commands/ide.d.ts +0 -2
- package/dist/utils/commands/ide.js +0 -32
- package/dist/utils/commands/init.d.ts +0 -2
- package/dist/utils/commands/init.js +0 -93
- package/dist/utils/commands/mcp.d.ts +0 -2
- package/dist/utils/commands/mcp.js +0 -12
- package/dist/utils/commands/resume.d.ts +0 -2
- package/dist/utils/commands/resume.js +0 -12
- package/dist/utils/commands/review.d.ts +0 -2
- package/dist/utils/commands/review.js +0 -81
- package/dist/utils/commands/role.d.ts +0 -2
- package/dist/utils/commands/role.js +0 -37
- package/dist/utils/commands/todoPicker.d.ts +0 -2
- package/dist/utils/commands/todoPicker.js +0 -12
- package/dist/utils/commands/usage.d.ts +0 -2
- package/dist/utils/commands/usage.js +0 -12
- package/dist/utils/commands/yolo.d.ts +0 -2
- package/dist/utils/commands/yolo.js +0 -12
- package/dist/utils/configManager.d.ts +0 -45
- package/dist/utils/configManager.js +0 -303
- package/dist/utils/contextCompressor.d.ts +0 -16
- package/dist/utils/contextCompressor.js +0 -334
- package/dist/utils/devMode.d.ts +0 -13
- package/dist/utils/devMode.js +0 -54
- package/dist/utils/escapeHandler.d.ts +0 -79
- package/dist/utils/escapeHandler.js +0 -153
- package/dist/utils/fileDialog.d.ts +0 -9
- package/dist/utils/fileDialog.js +0 -74
- package/dist/utils/fileUtils.d.ts +0 -40
- package/dist/utils/fileUtils.js +0 -185
- package/dist/utils/historyManager.d.ts +0 -45
- package/dist/utils/historyManager.js +0 -159
- package/dist/utils/incrementalSnapshot.d.ts +0 -109
- package/dist/utils/incrementalSnapshot.js +0 -383
- package/dist/utils/index.d.ts +0 -11
- package/dist/utils/index.js +0 -18
- package/dist/utils/languageConfig.d.ts +0 -21
- package/dist/utils/languageConfig.js +0 -61
- package/dist/utils/logger.d.ts +0 -37
- package/dist/utils/logger.js +0 -122
- package/dist/utils/mcpToolsManager.d.ts +0 -52
- package/dist/utils/mcpToolsManager.js +0 -878
- package/dist/utils/messageFormatter.d.ts +0 -12
- package/dist/utils/messageFormatter.js +0 -115
- package/dist/utils/notebookManager.d.ts +0 -59
- package/dist/utils/notebookManager.js +0 -213
- package/dist/utils/patch-highlight.d.ts +0 -5
- package/dist/utils/patch-highlight.js +0 -23
- package/dist/utils/processManager.d.ts +0 -27
- package/dist/utils/processManager.js +0 -75
- package/dist/utils/proxyUtils.d.ts +0 -15
- package/dist/utils/proxyUtils.js +0 -50
- package/dist/utils/resourceMonitor.d.ts +0 -65
- package/dist/utils/resourceMonitor.js +0 -175
- package/dist/utils/retryUtils.d.ts +0 -49
- package/dist/utils/retryUtils.js +0 -303
- package/dist/utils/sensitiveCommandManager.d.ts +0 -53
- package/dist/utils/sensitiveCommandManager.js +0 -308
- package/dist/utils/sessionConverter.d.ts +0 -7
- package/dist/utils/sessionConverter.js +0 -306
- package/dist/utils/sessionManager.d.ts +0 -53
- package/dist/utils/sessionManager.js +0 -371
- package/dist/utils/subAgentConfig.d.ts +0 -50
- package/dist/utils/subAgentConfig.js +0 -221
- package/dist/utils/subAgentExecutor.d.ts +0 -40
- package/dist/utils/subAgentExecutor.js +0 -434
- package/dist/utils/terminal.d.ts +0 -5
- package/dist/utils/terminal.js +0 -13
- package/dist/utils/textBuffer.d.ts +0 -99
- package/dist/utils/textBuffer.js +0 -547
- package/dist/utils/textUtils.d.ts +0 -37
- package/dist/utils/textUtils.js +0 -102
- package/dist/utils/themeConfig.d.ts +0 -21
- package/dist/utils/themeConfig.js +0 -61
- package/dist/utils/todoPreprocessor.d.ts +0 -5
- package/dist/utils/todoPreprocessor.js +0 -18
- package/dist/utils/todoScanner.d.ts +0 -8
- package/dist/utils/todoScanner.js +0 -148
- package/dist/utils/toolDisplayConfig.d.ts +0 -16
- package/dist/utils/toolDisplayConfig.js +0 -47
- package/dist/utils/toolExecutor.d.ts +0 -37
- package/dist/utils/toolExecutor.js +0 -224
- package/dist/utils/usageLogger.d.ts +0 -11
- package/dist/utils/usageLogger.js +0 -114
- package/dist/utils/vscodeConnection.d.ts +0 -76
- package/dist/utils/vscodeConnection.js +0 -430
- package/dist/utils/workspaceSnapshot.d.ts +0 -63
- package/dist/utils/workspaceSnapshot.js +0 -300
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
import { homedir } from 'os';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
|
4
|
-
const CONFIG_DIR = join(homedir(), '.snow');
|
|
5
|
-
const SENSITIVE_COMMANDS_FILE = join(CONFIG_DIR, 'sensitive-commands.json');
|
|
6
|
-
/**
|
|
7
|
-
* 预设的常见敏感指令
|
|
8
|
-
*/
|
|
9
|
-
export const PRESET_SENSITIVE_COMMANDS = [
|
|
10
|
-
{
|
|
11
|
-
id: 'rm',
|
|
12
|
-
pattern: 'rm*',
|
|
13
|
-
description: 'Delete files or directories (rm, rm -rf, etc.)',
|
|
14
|
-
enabled: true,
|
|
15
|
-
isPreset: true,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
id: 'rmdir',
|
|
19
|
-
pattern: 'rmdir*',
|
|
20
|
-
description: 'Remove directories',
|
|
21
|
-
enabled: true,
|
|
22
|
-
isPreset: true,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
id: 'mv-to-trash',
|
|
26
|
-
pattern: 'mv * /tmp*',
|
|
27
|
-
description: 'Move files to trash/tmp (potential data loss)',
|
|
28
|
-
enabled: true,
|
|
29
|
-
isPreset: true,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: 'chmod',
|
|
33
|
-
pattern: 'chmod*',
|
|
34
|
-
description: 'Change file permissions',
|
|
35
|
-
enabled: true,
|
|
36
|
-
isPreset: true,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
id: 'chown',
|
|
40
|
-
pattern: 'chown*',
|
|
41
|
-
description: 'Change file ownership',
|
|
42
|
-
enabled: true,
|
|
43
|
-
isPreset: true,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
id: 'dd',
|
|
47
|
-
pattern: 'dd*',
|
|
48
|
-
description: 'Low-level data copy (disk operations)',
|
|
49
|
-
enabled: true,
|
|
50
|
-
isPreset: true,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: 'mkfs',
|
|
54
|
-
pattern: 'mkfs*',
|
|
55
|
-
description: 'Format filesystem',
|
|
56
|
-
enabled: true,
|
|
57
|
-
isPreset: true,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
id: 'fdisk',
|
|
61
|
-
pattern: 'fdisk*',
|
|
62
|
-
description: 'Disk partition manipulation',
|
|
63
|
-
enabled: true,
|
|
64
|
-
isPreset: true,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
id: 'killall',
|
|
68
|
-
pattern: 'killall*',
|
|
69
|
-
description: 'Kill all processes by name',
|
|
70
|
-
enabled: true,
|
|
71
|
-
isPreset: true,
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
id: 'pkill',
|
|
75
|
-
pattern: 'pkill*',
|
|
76
|
-
description: 'Kill processes by pattern',
|
|
77
|
-
enabled: true,
|
|
78
|
-
isPreset: true,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
id: 'reboot',
|
|
82
|
-
pattern: 'reboot*',
|
|
83
|
-
description: 'Reboot the system',
|
|
84
|
-
enabled: true,
|
|
85
|
-
isPreset: true,
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
id: 'shutdown',
|
|
89
|
-
pattern: 'shutdown*',
|
|
90
|
-
description: 'Shutdown the system',
|
|
91
|
-
enabled: true,
|
|
92
|
-
isPreset: true,
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
id: 'sudo',
|
|
96
|
-
pattern: 'sudo*',
|
|
97
|
-
description: 'Execute commands with superuser privileges',
|
|
98
|
-
enabled: true,
|
|
99
|
-
isPreset: true,
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
id: 'su',
|
|
103
|
-
pattern: 'su*',
|
|
104
|
-
description: 'Switch user',
|
|
105
|
-
enabled: true,
|
|
106
|
-
isPreset: true,
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
id: 'curl-post',
|
|
110
|
-
pattern: 'curl*-X POST*',
|
|
111
|
-
description: 'HTTP POST requests (potential data transmission)',
|
|
112
|
-
enabled: false,
|
|
113
|
-
isPreset: true,
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
id: 'wget',
|
|
117
|
-
pattern: 'wget*',
|
|
118
|
-
description: 'Download files from internet',
|
|
119
|
-
enabled: false,
|
|
120
|
-
isPreset: true,
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
id: 'git-push',
|
|
124
|
-
pattern: 'git push*',
|
|
125
|
-
description: 'Push code to remote repository',
|
|
126
|
-
enabled: false,
|
|
127
|
-
isPreset: true,
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
id: 'git-force-push',
|
|
131
|
-
pattern: 'git push*--force*',
|
|
132
|
-
description: 'Force push to remote repository (destructive)',
|
|
133
|
-
enabled: true,
|
|
134
|
-
isPreset: true,
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
id: 'npm-publish',
|
|
138
|
-
pattern: 'npm publish*',
|
|
139
|
-
description: 'Publish package to npm registry',
|
|
140
|
-
enabled: true,
|
|
141
|
-
isPreset: true,
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
id: 'docker-rm',
|
|
145
|
-
pattern: 'docker rm*',
|
|
146
|
-
description: 'Remove Docker containers',
|
|
147
|
-
enabled: false,
|
|
148
|
-
isPreset: true,
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
id: 'docker-rmi',
|
|
152
|
-
pattern: 'docker rmi*',
|
|
153
|
-
description: 'Remove Docker images',
|
|
154
|
-
enabled: false,
|
|
155
|
-
isPreset: true,
|
|
156
|
-
},
|
|
157
|
-
];
|
|
158
|
-
/**
|
|
159
|
-
* Ensure config directory exists
|
|
160
|
-
*/
|
|
161
|
-
function ensureConfigDirectory() {
|
|
162
|
-
if (!existsSync(CONFIG_DIR)) {
|
|
163
|
-
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Load sensitive commands configuration
|
|
168
|
-
*/
|
|
169
|
-
export function loadSensitiveCommands() {
|
|
170
|
-
ensureConfigDirectory();
|
|
171
|
-
if (!existsSync(SENSITIVE_COMMANDS_FILE)) {
|
|
172
|
-
// 首次加载,使用预设配置
|
|
173
|
-
const defaultConfig = {
|
|
174
|
-
commands: [...PRESET_SENSITIVE_COMMANDS],
|
|
175
|
-
};
|
|
176
|
-
saveSensitiveCommands(defaultConfig);
|
|
177
|
-
return defaultConfig;
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
const configData = readFileSync(SENSITIVE_COMMANDS_FILE, 'utf8');
|
|
181
|
-
const config = JSON.parse(configData);
|
|
182
|
-
// 合并预设命令(处理新增的预设命令)
|
|
183
|
-
const existingIds = new Set(config.commands.map(cmd => cmd.id));
|
|
184
|
-
const newPresets = PRESET_SENSITIVE_COMMANDS.filter(preset => !existingIds.has(preset.id));
|
|
185
|
-
if (newPresets.length > 0) {
|
|
186
|
-
config.commands = [...config.commands, ...newPresets];
|
|
187
|
-
saveSensitiveCommands(config);
|
|
188
|
-
}
|
|
189
|
-
return config;
|
|
190
|
-
}
|
|
191
|
-
catch (error) {
|
|
192
|
-
console.error('Failed to load sensitive commands config:', error);
|
|
193
|
-
return { commands: [...PRESET_SENSITIVE_COMMANDS] };
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Save sensitive commands configuration
|
|
198
|
-
*/
|
|
199
|
-
export function saveSensitiveCommands(config) {
|
|
200
|
-
ensureConfigDirectory();
|
|
201
|
-
try {
|
|
202
|
-
const configData = JSON.stringify(config, null, 2);
|
|
203
|
-
writeFileSync(SENSITIVE_COMMANDS_FILE, configData, 'utf8');
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
throw new Error(`Failed to save sensitive commands config: ${error}`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Add a custom sensitive command
|
|
211
|
-
*/
|
|
212
|
-
export function addSensitiveCommand(pattern, description) {
|
|
213
|
-
const config = loadSensitiveCommands();
|
|
214
|
-
// 生成唯一ID
|
|
215
|
-
const id = `custom-${Date.now()}-${Math.random()
|
|
216
|
-
.toString(36)
|
|
217
|
-
.substring(2, 9)}`;
|
|
218
|
-
config.commands.push({
|
|
219
|
-
id,
|
|
220
|
-
pattern,
|
|
221
|
-
description,
|
|
222
|
-
enabled: true,
|
|
223
|
-
isPreset: false,
|
|
224
|
-
});
|
|
225
|
-
saveSensitiveCommands(config);
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Remove a sensitive command
|
|
229
|
-
*/
|
|
230
|
-
export function removeSensitiveCommand(id) {
|
|
231
|
-
const config = loadSensitiveCommands();
|
|
232
|
-
config.commands = config.commands.filter(cmd => cmd.id !== id);
|
|
233
|
-
saveSensitiveCommands(config);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Update a sensitive command
|
|
237
|
-
*/
|
|
238
|
-
export function updateSensitiveCommand(id, updates) {
|
|
239
|
-
const config = loadSensitiveCommands();
|
|
240
|
-
const commandIndex = config.commands.findIndex(cmd => cmd.id === id);
|
|
241
|
-
if (commandIndex === -1) {
|
|
242
|
-
throw new Error(`Sensitive command with id "${id}" not found`);
|
|
243
|
-
}
|
|
244
|
-
const existingCommand = config.commands[commandIndex];
|
|
245
|
-
config.commands[commandIndex] = {
|
|
246
|
-
...existingCommand,
|
|
247
|
-
...updates,
|
|
248
|
-
id: existingCommand.id,
|
|
249
|
-
isPreset: existingCommand.isPreset,
|
|
250
|
-
};
|
|
251
|
-
saveSensitiveCommands(config);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Toggle a sensitive command enabled state
|
|
255
|
-
*/
|
|
256
|
-
export function toggleSensitiveCommand(id) {
|
|
257
|
-
const config = loadSensitiveCommands();
|
|
258
|
-
const command = config.commands.find(cmd => cmd.id === id);
|
|
259
|
-
if (!command) {
|
|
260
|
-
throw new Error(`Sensitive command with id "${id}" not found`);
|
|
261
|
-
}
|
|
262
|
-
command.enabled = !command.enabled;
|
|
263
|
-
saveSensitiveCommands(config);
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* 将通配符模式转换为正则表达式
|
|
267
|
-
* 支持 * 通配符
|
|
268
|
-
*/
|
|
269
|
-
function patternToRegex(pattern) {
|
|
270
|
-
// 转义特殊字符,除了 * 和空格
|
|
271
|
-
const escaped = pattern
|
|
272
|
-
.replace(/[.+?^${}()|[\]\\]/g, '\\$&')
|
|
273
|
-
.replace(/\*/g, '.*');
|
|
274
|
-
// 使用 ^ 和 $ 确保完整匹配,但允许参数
|
|
275
|
-
return new RegExp(`^${escaped}`, 'i');
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Check if a command matches any enabled sensitive pattern
|
|
279
|
-
*/
|
|
280
|
-
export function isSensitiveCommand(command) {
|
|
281
|
-
const config = loadSensitiveCommands();
|
|
282
|
-
const enabledCommands = config.commands.filter(cmd => cmd.enabled);
|
|
283
|
-
// 清理命令,移除多余的空格
|
|
284
|
-
const cleanCommand = command.trim().replace(/\s+/g, ' ');
|
|
285
|
-
for (const cmd of enabledCommands) {
|
|
286
|
-
const regex = patternToRegex(cmd.pattern);
|
|
287
|
-
if (regex.test(cleanCommand)) {
|
|
288
|
-
return { isSensitive: true, matchedCommand: cmd };
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return { isSensitive: false };
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Get all sensitive commands
|
|
295
|
-
*/
|
|
296
|
-
export function getAllSensitiveCommands() {
|
|
297
|
-
const config = loadSensitiveCommands();
|
|
298
|
-
return config.commands;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Reset to default preset commands
|
|
302
|
-
*/
|
|
303
|
-
export function resetToDefaults() {
|
|
304
|
-
const config = {
|
|
305
|
-
commands: [...PRESET_SENSITIVE_COMMANDS],
|
|
306
|
-
};
|
|
307
|
-
saveSensitiveCommands(config);
|
|
308
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ChatMessage } from '../api/chat.js';
|
|
2
|
-
import type { Message } from '../ui/components/MessageList.js';
|
|
3
|
-
/**
|
|
4
|
-
* Convert API format session messages to UI format messages
|
|
5
|
-
* Process messages in order to maintain correct sequence
|
|
6
|
-
*/
|
|
7
|
-
export declare function convertSessionMessagesToUI(sessionMessages: ChatMessage[]): Message[];
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
import { formatToolCallMessage } from './messageFormatter.js';
|
|
2
|
-
import { isToolNeedTwoStepDisplay } from './toolDisplayConfig.js';
|
|
3
|
-
/**
|
|
4
|
-
* Convert API format session messages to UI format messages
|
|
5
|
-
* Process messages in order to maintain correct sequence
|
|
6
|
-
*/
|
|
7
|
-
export function convertSessionMessagesToUI(sessionMessages) {
|
|
8
|
-
const uiMessages = [];
|
|
9
|
-
// Track which tool_calls have been processed
|
|
10
|
-
const processedToolCalls = new Set();
|
|
11
|
-
for (let i = 0; i < sessionMessages.length; i++) {
|
|
12
|
-
const msg = sessionMessages[i];
|
|
13
|
-
if (!msg)
|
|
14
|
-
continue;
|
|
15
|
-
// Skip system messages
|
|
16
|
-
if (msg.role === 'system')
|
|
17
|
-
continue;
|
|
18
|
-
// Handle sub-agent internal tool call messages
|
|
19
|
-
if (msg.subAgentInternal && msg.role === 'assistant' && msg.tool_calls) {
|
|
20
|
-
for (const toolCall of msg.tool_calls) {
|
|
21
|
-
// 只有耗时工具才创建"进行中"消息
|
|
22
|
-
if (isToolNeedTwoStepDisplay(toolCall.function.name)) {
|
|
23
|
-
const toolDisplay = formatToolCallMessage(toolCall);
|
|
24
|
-
let toolArgs;
|
|
25
|
-
try {
|
|
26
|
-
toolArgs = JSON.parse(toolCall.function.arguments);
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
toolArgs = {};
|
|
30
|
-
}
|
|
31
|
-
uiMessages.push({
|
|
32
|
-
role: 'subagent',
|
|
33
|
-
content: `\x1b[38;2;184;122;206m⚇⚡ ${toolDisplay.toolName}\x1b[0m`,
|
|
34
|
-
streaming: false,
|
|
35
|
-
toolCall: {
|
|
36
|
-
name: toolCall.function.name,
|
|
37
|
-
arguments: toolArgs,
|
|
38
|
-
},
|
|
39
|
-
// Don't include toolDisplay for sub-agent tools to avoid showing parameters
|
|
40
|
-
toolCallId: toolCall.id,
|
|
41
|
-
toolPending: false,
|
|
42
|
-
subAgentInternal: true,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
processedToolCalls.add(toolCall.id);
|
|
46
|
-
}
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
// Handle sub-agent internal tool result messages
|
|
50
|
-
if (msg.subAgentInternal && msg.role === 'tool' && msg.tool_call_id) {
|
|
51
|
-
const isError = msg.content.startsWith('Error:');
|
|
52
|
-
const statusIcon = isError ? '✗' : '✓';
|
|
53
|
-
const statusText = isError ? `\n └─ ${msg.content}` : '';
|
|
54
|
-
// Find tool name from previous assistant message
|
|
55
|
-
let toolName = 'tool';
|
|
56
|
-
let terminalResultData;
|
|
57
|
-
for (let j = i - 1; j >= 0; j--) {
|
|
58
|
-
const prevMsg = sessionMessages[j];
|
|
59
|
-
if (!prevMsg)
|
|
60
|
-
continue;
|
|
61
|
-
if (prevMsg.role === 'assistant' &&
|
|
62
|
-
prevMsg.tool_calls &&
|
|
63
|
-
prevMsg.subAgentInternal) {
|
|
64
|
-
const tc = prevMsg.tool_calls.find(t => t.id === msg.tool_call_id);
|
|
65
|
-
if (tc) {
|
|
66
|
-
toolName = tc.function.name;
|
|
67
|
-
if (toolName === 'terminal-execute' && !isError) {
|
|
68
|
-
try {
|
|
69
|
-
const resultData = JSON.parse(msg.content);
|
|
70
|
-
if (resultData.stdout !== undefined ||
|
|
71
|
-
resultData.stderr !== undefined) {
|
|
72
|
-
terminalResultData = {
|
|
73
|
-
stdout: resultData.stdout,
|
|
74
|
-
stderr: resultData.stderr,
|
|
75
|
-
exitCode: resultData.exitCode,
|
|
76
|
-
command: resultData.command,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
// Ignore parse errors
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
uiMessages.push({
|
|
89
|
-
role: 'subagent',
|
|
90
|
-
content: `\x1b[38;2;0;186;255m⚇${statusIcon} ${toolName}\x1b[0m${statusText}`,
|
|
91
|
-
streaming: false,
|
|
92
|
-
toolResult: !isError ? msg.content : undefined,
|
|
93
|
-
terminalResult: terminalResultData,
|
|
94
|
-
toolCall: terminalResultData
|
|
95
|
-
? {
|
|
96
|
-
name: toolName,
|
|
97
|
-
arguments: terminalResultData,
|
|
98
|
-
}
|
|
99
|
-
: undefined,
|
|
100
|
-
subAgentInternal: true,
|
|
101
|
-
});
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
// Handle regular assistant messages with tool_calls
|
|
105
|
-
if (msg.role === 'assistant' &&
|
|
106
|
-
msg.tool_calls &&
|
|
107
|
-
msg.tool_calls.length > 0 &&
|
|
108
|
-
!msg.subAgentInternal) {
|
|
109
|
-
// Generate parallel group ID for non-time-consuming tools
|
|
110
|
-
const hasMultipleTools = msg.tool_calls.length > 1;
|
|
111
|
-
const hasNonTimeConsumingTool = msg.tool_calls.some(tc => !isToolNeedTwoStepDisplay(tc.function.name));
|
|
112
|
-
const parallelGroupId = hasMultipleTools && hasNonTimeConsumingTool
|
|
113
|
-
? `parallel-${i}-${Math.random()}`
|
|
114
|
-
: undefined;
|
|
115
|
-
for (const toolCall of msg.tool_calls) {
|
|
116
|
-
// Skip if already processed
|
|
117
|
-
if (processedToolCalls.has(toolCall.id))
|
|
118
|
-
continue;
|
|
119
|
-
const toolDisplay = formatToolCallMessage(toolCall);
|
|
120
|
-
let toolArgs;
|
|
121
|
-
try {
|
|
122
|
-
toolArgs = JSON.parse(toolCall.function.arguments);
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
toolArgs = {};
|
|
126
|
-
}
|
|
127
|
-
// Only add "in progress" message for tools that need two-step display
|
|
128
|
-
const needTwoSteps = isToolNeedTwoStepDisplay(toolCall.function.name);
|
|
129
|
-
if (needTwoSteps) {
|
|
130
|
-
// Add tool call message (in progress)
|
|
131
|
-
uiMessages.push({
|
|
132
|
-
role: 'assistant',
|
|
133
|
-
content: `⚡ ${toolDisplay.toolName}`,
|
|
134
|
-
streaming: false,
|
|
135
|
-
toolCall: {
|
|
136
|
-
name: toolCall.function.name,
|
|
137
|
-
arguments: toolArgs,
|
|
138
|
-
},
|
|
139
|
-
toolDisplay,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
// Store parallel group info for this tool call
|
|
143
|
-
if (parallelGroupId && !needTwoSteps) {
|
|
144
|
-
processedToolCalls.add(toolCall.id);
|
|
145
|
-
// Mark this tool call with parallel group (will be used when processing tool results)
|
|
146
|
-
toolCall.parallelGroupId = parallelGroupId;
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
processedToolCalls.add(toolCall.id);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
// Handle regular tool result messages (non-subagent)
|
|
155
|
-
if (msg.role === 'tool' && msg.tool_call_id && !msg.subAgentInternal) {
|
|
156
|
-
const isError = msg.content.startsWith('Error:');
|
|
157
|
-
const isRejectedWithReply = msg.content.includes('Tool execution rejected by user:');
|
|
158
|
-
const statusIcon = isError || isRejectedWithReply ? '✗' : '✓';
|
|
159
|
-
let statusText = '';
|
|
160
|
-
if (isError) {
|
|
161
|
-
statusText = `\n └─ ${msg.content}`;
|
|
162
|
-
}
|
|
163
|
-
else if (isRejectedWithReply) {
|
|
164
|
-
// Extract rejection reason
|
|
165
|
-
const reason = msg.content.split('Tool execution rejected by user:')[1]?.trim() ||
|
|
166
|
-
'';
|
|
167
|
-
statusText = reason ? `\n └─ Rejection reason: ${reason}` : '';
|
|
168
|
-
}
|
|
169
|
-
// Find tool name and args from previous assistant message
|
|
170
|
-
let toolName = 'tool';
|
|
171
|
-
let toolArgs = {};
|
|
172
|
-
let editDiffData;
|
|
173
|
-
let terminalResultData;
|
|
174
|
-
for (let j = i - 1; j >= 0; j--) {
|
|
175
|
-
const prevMsg = sessionMessages[j];
|
|
176
|
-
if (!prevMsg)
|
|
177
|
-
continue;
|
|
178
|
-
if (prevMsg.role === 'assistant' &&
|
|
179
|
-
prevMsg.tool_calls &&
|
|
180
|
-
!prevMsg.subAgentInternal) {
|
|
181
|
-
const tc = prevMsg.tool_calls.find(t => t.id === msg.tool_call_id);
|
|
182
|
-
if (tc) {
|
|
183
|
-
toolName = tc.function.name;
|
|
184
|
-
try {
|
|
185
|
-
toolArgs = JSON.parse(tc.function.arguments);
|
|
186
|
-
}
|
|
187
|
-
catch (e) {
|
|
188
|
-
toolArgs = {};
|
|
189
|
-
}
|
|
190
|
-
// Extract edit diff data
|
|
191
|
-
if ((toolName === 'filesystem-edit' ||
|
|
192
|
-
toolName === 'filesystem-edit_search') &&
|
|
193
|
-
!isError) {
|
|
194
|
-
try {
|
|
195
|
-
const resultData = JSON.parse(msg.content);
|
|
196
|
-
// Handle single file edit
|
|
197
|
-
if (resultData.oldContent && resultData.newContent) {
|
|
198
|
-
editDiffData = {
|
|
199
|
-
oldContent: resultData.oldContent,
|
|
200
|
-
newContent: resultData.newContent,
|
|
201
|
-
filename: toolArgs.filePath,
|
|
202
|
-
completeOldContent: resultData.completeOldContent,
|
|
203
|
-
completeNewContent: resultData.completeNewContent,
|
|
204
|
-
contextStartLine: resultData.contextStartLine,
|
|
205
|
-
};
|
|
206
|
-
toolArgs.oldContent = resultData.oldContent;
|
|
207
|
-
toolArgs.newContent = resultData.newContent;
|
|
208
|
-
toolArgs.completeOldContent = resultData.completeOldContent;
|
|
209
|
-
toolArgs.completeNewContent = resultData.completeNewContent;
|
|
210
|
-
toolArgs.contextStartLine = resultData.contextStartLine;
|
|
211
|
-
}
|
|
212
|
-
// Handle batch edit
|
|
213
|
-
else if (resultData.results &&
|
|
214
|
-
Array.isArray(resultData.results)) {
|
|
215
|
-
editDiffData = {
|
|
216
|
-
batchResults: resultData.results,
|
|
217
|
-
isBatch: true,
|
|
218
|
-
};
|
|
219
|
-
toolArgs.batchResults = resultData.results;
|
|
220
|
-
toolArgs.isBatch = true;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
catch (e) {
|
|
224
|
-
// Ignore parse errors
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
// Extract terminal result data
|
|
228
|
-
if (toolName === 'terminal-execute' && !isError) {
|
|
229
|
-
try {
|
|
230
|
-
const resultData = JSON.parse(msg.content);
|
|
231
|
-
if (resultData.stdout !== undefined ||
|
|
232
|
-
resultData.stderr !== undefined) {
|
|
233
|
-
terminalResultData = {
|
|
234
|
-
stdout: resultData.stdout,
|
|
235
|
-
stderr: resultData.stderr,
|
|
236
|
-
exitCode: resultData.exitCode,
|
|
237
|
-
command: toolArgs.command,
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
catch (e) {
|
|
242
|
-
// Ignore parse errors
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
// Check if this tool result is part of a parallel group
|
|
250
|
-
let parallelGroupId;
|
|
251
|
-
for (let j = i - 1; j >= 0; j--) {
|
|
252
|
-
const prevMsg = sessionMessages[j];
|
|
253
|
-
if (!prevMsg)
|
|
254
|
-
continue;
|
|
255
|
-
if (prevMsg.role === 'assistant' &&
|
|
256
|
-
prevMsg.tool_calls &&
|
|
257
|
-
!prevMsg.subAgentInternal) {
|
|
258
|
-
const tc = prevMsg.tool_calls.find(t => t.id === msg.tool_call_id);
|
|
259
|
-
if (tc) {
|
|
260
|
-
parallelGroupId = tc.parallelGroupId;
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const isNonTimeConsuming = !isToolNeedTwoStepDisplay(toolName);
|
|
266
|
-
uiMessages.push({
|
|
267
|
-
role: 'assistant',
|
|
268
|
-
content: `${statusIcon} ${toolName}${statusText}`,
|
|
269
|
-
streaming: false,
|
|
270
|
-
toolResult: !isError ? msg.content : undefined,
|
|
271
|
-
toolCall: editDiffData || terminalResultData
|
|
272
|
-
? {
|
|
273
|
-
name: toolName,
|
|
274
|
-
arguments: toolArgs,
|
|
275
|
-
}
|
|
276
|
-
: undefined,
|
|
277
|
-
terminalResult: terminalResultData,
|
|
278
|
-
// Add toolDisplay for non-time-consuming tools
|
|
279
|
-
toolDisplay: isNonTimeConsuming && !editDiffData
|
|
280
|
-
? formatToolCallMessage({
|
|
281
|
-
id: msg.tool_call_id || '',
|
|
282
|
-
type: 'function',
|
|
283
|
-
function: {
|
|
284
|
-
name: toolName,
|
|
285
|
-
arguments: JSON.stringify(toolArgs),
|
|
286
|
-
},
|
|
287
|
-
})
|
|
288
|
-
: undefined,
|
|
289
|
-
// Mark parallel group for non-time-consuming tools
|
|
290
|
-
parallelGroup: isNonTimeConsuming && parallelGroupId ? parallelGroupId : undefined,
|
|
291
|
-
});
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
// Handle regular user and assistant messages
|
|
295
|
-
if (msg.role === 'user' || msg.role === 'assistant') {
|
|
296
|
-
uiMessages.push({
|
|
297
|
-
role: msg.role,
|
|
298
|
-
content: msg.content,
|
|
299
|
-
streaming: false,
|
|
300
|
-
images: msg.images,
|
|
301
|
-
});
|
|
302
|
-
continue;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return uiMessages;
|
|
306
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ChatMessage as APIChatMessage } from '../api/chat.js';
|
|
2
|
-
export interface ChatMessage extends APIChatMessage {
|
|
3
|
-
timestamp: number;
|
|
4
|
-
originalContent?: string;
|
|
5
|
-
}
|
|
6
|
-
export interface Session {
|
|
7
|
-
id: string;
|
|
8
|
-
title: string;
|
|
9
|
-
summary: string;
|
|
10
|
-
createdAt: number;
|
|
11
|
-
updatedAt: number;
|
|
12
|
-
messages: ChatMessage[];
|
|
13
|
-
messageCount: number;
|
|
14
|
-
}
|
|
15
|
-
export interface SessionListItem {
|
|
16
|
-
id: string;
|
|
17
|
-
title: string;
|
|
18
|
-
summary: string;
|
|
19
|
-
createdAt: number;
|
|
20
|
-
updatedAt: number;
|
|
21
|
-
messageCount: number;
|
|
22
|
-
}
|
|
23
|
-
declare class SessionManager {
|
|
24
|
-
private readonly sessionsDir;
|
|
25
|
-
private currentSession;
|
|
26
|
-
constructor();
|
|
27
|
-
private ensureSessionsDir;
|
|
28
|
-
private getSessionPath;
|
|
29
|
-
private formatDateForFolder;
|
|
30
|
-
/**
|
|
31
|
-
* Clean title by removing newlines and extra spaces
|
|
32
|
-
*/
|
|
33
|
-
private cleanTitle;
|
|
34
|
-
createNewSession(): Promise<Session>;
|
|
35
|
-
saveSession(session: Session): Promise<void>;
|
|
36
|
-
loadSession(sessionId: string): Promise<Session | null>;
|
|
37
|
-
private findSessionInDateFolders;
|
|
38
|
-
listSessions(): Promise<SessionListItem[]>;
|
|
39
|
-
private readSessionsFromDir;
|
|
40
|
-
addMessage(message: ChatMessage): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Generate AI-powered summary for the first conversation exchange
|
|
43
|
-
* This runs in the background without blocking the main flow
|
|
44
|
-
*/
|
|
45
|
-
private generateAndUpdateSummary;
|
|
46
|
-
getCurrentSession(): Session | null;
|
|
47
|
-
setCurrentSession(session: Session): void;
|
|
48
|
-
clearCurrentSession(): void;
|
|
49
|
-
deleteSession(sessionId: string): Promise<boolean>;
|
|
50
|
-
truncateMessages(messageCount: number): Promise<void>;
|
|
51
|
-
}
|
|
52
|
-
export declare const sessionManager: SessionManager;
|
|
53
|
-
export {};
|