aegiscode 3.1.10 → 3.2.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/bin/aegis-cli-linux-x64 +0 -0
- package/bin/cli.js +68 -0
- package/package.json +11 -48
- package/scripts/download-binary.mjs +155 -0
- package/dist/main.js +0 -2171
- package/gui/run-gui.cjs +0 -13
- package/src/agent/Agent.ts +0 -903
- package/src/agent/SimpleAgent.ts +0 -48
- package/src/agent/index.ts +0 -54
- package/src/agent/orchestrator/AppBuilder.ts +0 -443
- package/src/agent/orchestrator/CouncilAgent.ts +0 -310
- package/src/agent/orchestrator/DiscussionRoom.ts +0 -462
- package/src/agent/orchestrator/OrchestratorAgent.ts +0 -637
- package/src/agent/orchestrator/index.ts +0 -38
- package/src/agent/orchestrator/utils.ts +0 -397
- package/src/agent/pricing.ts +0 -115
- package/src/agent/router.ts +0 -74
- package/src/agent/routerStats.ts +0 -121
- package/src/agent/types.ts +0 -318
- package/src/auth/login.ts +0 -383
- package/src/cli/config.ts +0 -189
- package/src/cli/index.ts +0 -17
- package/src/cli/middleware.ts +0 -119
- package/src/cli/types.ts +0 -75
- package/src/config/ConfigManager.ts +0 -587
- package/src/config/index.ts +0 -7
- package/src/config/types.ts +0 -584
- package/src/context/CompactionService.ts +0 -300
- package/src/context/ContextManager.ts +0 -450
- package/src/context/FileAnalyzer.ts +0 -267
- package/src/context/TokenCounter.ts +0 -265
- package/src/context/index.ts +0 -27
- package/src/context/storage/CacheStore.ts +0 -176
- package/src/context/storage/JSONLStore.ts +0 -201
- package/src/context/storage/MemoryStore.ts +0 -205
- package/src/context/storage/PersistentStore.ts +0 -327
- package/src/context/storage/index.ts +0 -9
- package/src/context/storage/pathUtils.ts +0 -114
- package/src/context/test.ts +0 -309
- package/src/context/types.ts +0 -268
- package/src/hooks/HookExecutor.ts +0 -434
- package/src/hooks/HookManager.ts +0 -596
- package/src/hooks/HookService.ts +0 -269
- package/src/hooks/Matcher.ts +0 -157
- package/src/hooks/index.ts +0 -63
- package/src/hooks/types.ts +0 -424
- package/src/main.tsx +0 -596
- package/src/mcp/HealthMonitor.ts +0 -150
- package/src/mcp/McpClient.ts +0 -491
- package/src/mcp/McpRegistry.ts +0 -321
- package/src/mcp/createMcpTool.ts +0 -251
- package/src/mcp/index.ts +0 -15
- package/src/mcp/server.ts +0 -334
- package/src/mcp/test-server.ts +0 -88
- package/src/mcp/test.ts +0 -372
- package/src/mcp/types.ts +0 -247
- package/src/memory/AgentMemoryBus.ts +0 -432
- package/src/memory/CloudSync.ts +0 -99
- package/src/memory/DriveSync.ts +0 -106
- package/src/memory/SharedMemory.ts +0 -951
- package/src/memory/index.ts +0 -14
- package/src/memory/machineFingerprint.ts +0 -40
- package/src/orchestrator/SubAgentMetadata.ts +0 -136
- package/src/prompts/builder.ts +0 -213
- package/src/prompts/default.ts +0 -144
- package/src/prompts/index.ts +0 -16
- package/src/prompts/plan.ts +0 -64
- package/src/prompts/test.ts +0 -78
- package/src/services/AnthropicChatService.ts +0 -341
- package/src/services/ChatService.ts +0 -347
- package/src/services/ClaudeCliChatService.ts +0 -256
- package/src/services/CloudSync.ts +0 -168
- package/src/services/CostLedger.ts +0 -211
- package/src/services/Heartbeat.ts +0 -135
- package/src/services/LearningCollector.ts +0 -291
- package/src/services/OllamaInstaller.ts +0 -342
- package/src/services/VersionChecker.ts +0 -445
- package/src/services/index.ts +0 -57
- package/src/services/streaming/OpenAIEventAdapter.ts +0 -126
- package/src/services/streaming/RenderingProfile.ts +0 -90
- package/src/services/streaming/StreamEventParser.ts +0 -181
- package/src/services/streaming/ThrottledRenderer.ts +0 -139
- package/src/services/streaming/TranscriptBuffer.ts +0 -574
- package/src/services/streaming/eventStatusMap.ts +0 -52
- package/src/services/streaming/index.ts +0 -46
- package/src/services/streaming/renderFormatting.ts +0 -79
- package/src/services/streaming/types.ts +0 -234
- package/src/skills/SkillLoader.ts +0 -126
- package/src/skills/SkillRegistry.ts +0 -366
- package/src/skills/index.ts +0 -48
- package/src/skills/types.ts +0 -146
- package/src/slash-commands/billing.ts +0 -70
- package/src/slash-commands/build.ts +0 -413
- package/src/slash-commands/builtinCommands.ts +0 -2733
- package/src/slash-commands/clone.ts +0 -242
- package/src/slash-commands/council.ts +0 -125
- package/src/slash-commands/custom/CustomCommandExecutor.ts +0 -143
- package/src/slash-commands/custom/CustomCommandLoader.ts +0 -251
- package/src/slash-commands/custom/CustomCommandRegistry.ts +0 -144
- package/src/slash-commands/custom/index.ts +0 -7
- package/src/slash-commands/debate.ts +0 -254
- package/src/slash-commands/gmail.ts +0 -105
- package/src/slash-commands/index.ts +0 -388
- package/src/slash-commands/mcpCommand.ts +0 -205
- package/src/slash-commands/types.ts +0 -201
- package/src/store/index.ts +0 -76
- package/src/store/selectors.ts +0 -246
- package/src/store/slices/appSlice.ts +0 -205
- package/src/store/slices/commandSlice.ts +0 -115
- package/src/store/slices/configSlice.ts +0 -46
- package/src/store/slices/focusSlice.ts +0 -64
- package/src/store/slices/index.ts +0 -9
- package/src/store/slices/sessionSlice.ts +0 -424
- package/src/store/streaming-buffer.ts +0 -425
- package/src/store/test.ts +0 -296
- package/src/store/types.ts +0 -274
- package/src/store/vanilla.ts +0 -186
- package/src/tools/builtin/bash.ts +0 -236
- package/src/tools/builtin/council.ts +0 -105
- package/src/tools/builtin/edit.ts +0 -213
- package/src/tools/builtin/glob.ts +0 -136
- package/src/tools/builtin/grep.ts +0 -263
- package/src/tools/builtin/index.ts +0 -61
- package/src/tools/builtin/memory.ts +0 -66
- package/src/tools/builtin/read.ts +0 -168
- package/src/tools/builtin/skill.ts +0 -97
- package/src/tools/builtin/snapshot.ts +0 -40
- package/src/tools/builtin/task.ts +0 -106
- package/src/tools/builtin/write.ts +0 -134
- package/src/tools/createTool.ts +0 -221
- package/src/tools/execution/ExecutionPipeline.ts +0 -263
- package/src/tools/execution/index.ts +0 -40
- package/src/tools/execution/stages/CacheStage.ts +0 -131
- package/src/tools/execution/stages/ConfirmationStage.ts +0 -203
- package/src/tools/execution/stages/DiscoveryStage.ts +0 -46
- package/src/tools/execution/stages/ExecutionStage.ts +0 -48
- package/src/tools/execution/stages/FormattingStage.ts +0 -44
- package/src/tools/execution/stages/HookStage.ts +0 -72
- package/src/tools/execution/stages/PermissionStage.ts +0 -287
- package/src/tools/execution/stages/PostHookStage.ts +0 -71
- package/src/tools/execution/stages/index.ts +0 -12
- package/src/tools/execution/test.ts +0 -266
- package/src/tools/execution/types.ts +0 -273
- package/src/tools/index.ts +0 -81
- package/src/tools/registry.ts +0 -304
- package/src/tools/schemas.ts +0 -109
- package/src/tools/test.ts +0 -220
- package/src/tools/types.ts +0 -175
- package/src/tools/validation/PermissionChecker.ts +0 -242
- package/src/tools/validation/SensitiveFileDetector.ts +0 -210
- package/src/tools/validation/index.ts +0 -11
- package/src/ui/App.tsx +0 -166
- package/src/ui/components/AegisInterface.tsx +0 -484
- package/src/ui/components/common/ChatSearch.tsx +0 -150
- package/src/ui/components/common/ErrorBoundary.tsx +0 -82
- package/src/ui/components/common/ExitMessage.tsx +0 -120
- package/src/ui/components/common/LoadingIndicator.tsx +0 -49
- package/src/ui/components/common/index.ts +0 -6
- package/src/ui/components/dialog/ConfirmationPrompt.tsx +0 -208
- package/src/ui/components/dialog/InteractiveSelector.tsx +0 -149
- package/src/ui/components/dialog/SetupWizard.tsx +0 -297
- package/src/ui/components/dialog/UpdatePrompt.tsx +0 -155
- package/src/ui/components/dialog/index.ts +0 -8
- package/src/ui/components/index.ts +0 -28
- package/src/ui/components/input/CommandSuggestions.tsx +0 -139
- package/src/ui/components/input/CustomTextInput.tsx +0 -220
- package/src/ui/components/input/InputArea.tsx +0 -361
- package/src/ui/components/input/PromptSuggestions.tsx +0 -66
- package/src/ui/components/input/index.ts +0 -6
- package/src/ui/components/layout/ChatStatusBar.tsx +0 -90
- package/src/ui/components/layout/ContextBar.tsx +0 -79
- package/src/ui/components/layout/MessageArea.tsx +0 -96
- package/src/ui/components/layout/MessageList.tsx +0 -647
- package/src/ui/components/layout/MessageSeparator.tsx +0 -26
- package/src/ui/components/layout/WelcomeMessage.tsx +0 -93
- package/src/ui/components/layout/index.ts +0 -7
- package/src/ui/components/markdown/CodeHighlighter.tsx +0 -292
- package/src/ui/components/markdown/MessageRenderer.tsx +0 -1211
- package/src/ui/components/markdown/index.ts +0 -8
- package/src/ui/components/markdown/parser.ts +0 -336
- package/src/ui/components/markdown/types.ts +0 -66
- package/src/ui/focus/FocusManager.ts +0 -137
- package/src/ui/focus/index.ts +0 -13
- package/src/ui/focus/types.ts +0 -54
- package/src/ui/focus/useFocus.ts +0 -75
- package/src/ui/hooks/index.ts +0 -11
- package/src/ui/hooks/useAgent.ts +0 -284
- package/src/ui/hooks/useCommandHistory.ts +0 -87
- package/src/ui/hooks/useCommandProcessor.ts +0 -443
- package/src/ui/hooks/useConfirmation.ts +0 -99
- package/src/ui/hooks/useCtrlCHandler.ts +0 -100
- package/src/ui/hooks/useInputBuffer.ts +0 -122
- package/src/ui/hooks/useTerminalSize.ts +0 -68
- package/src/ui/hooks/useTerminalWidth.ts +0 -5
- package/src/ui/hooks/useWindowedList.ts +0 -118
- package/src/ui/render-debugger.ts +0 -621
- package/src/ui/test.ts +0 -189
- package/src/ui/themes/ThemeManager.ts +0 -332
- package/src/ui/themes/aegisTheme.ts +0 -87
- package/src/ui/themes/darkTheme.ts +0 -87
- package/src/ui/themes/defaultTheme.ts +0 -85
- package/src/ui/themes/index.ts +0 -10
- package/src/ui/themes/lightTheme.ts +0 -89
- package/src/ui/themes/popularThemes.ts +0 -187
- package/src/ui/themes/types.ts +0 -130
- package/src/utils/clipboard.ts +0 -48
- package/src/utils/debug.ts +0 -43
- package/src/utils/environment.ts +0 -68
- package/src/utils/index.ts +0 -10
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Markdown 解析器
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { ParsedBlock, TableData } from './types.js';
|
|
8
|
-
|
|
9
|
-
/** 已知的编程语言标识列表(用于区分 language 和 file path) */
|
|
10
|
-
const KNOWN_LANGUAGES = new Set([
|
|
11
|
-
'javascript', 'js', 'typescript', 'ts', 'tsx', 'jsx',
|
|
12
|
-
'python', 'py', 'ruby', 'rb', 'go', 'rust', 'rs',
|
|
13
|
-
'java', 'kotlin', 'kt', 'scala', 'swift', 'c', 'cpp', 'h',
|
|
14
|
-
'csharp', 'cs', 'php', 'lua', 'perl', 'r', 'sql',
|
|
15
|
-
'html', 'css', 'scss', 'sass', 'less',
|
|
16
|
-
'json', 'yaml', 'yml', 'toml', 'xml', 'ini', 'env',
|
|
17
|
-
'bash', 'sh', 'zsh', 'fish', 'powershell', 'ps1',
|
|
18
|
-
'markdown', 'md', 'text', 'txt', 'plain',
|
|
19
|
-
'diff', 'patch', 'dockerfile', 'makefile', 'cmake',
|
|
20
|
-
'graphql', 'gql', 'proto', 'protobuf',
|
|
21
|
-
'vim', 'elixir', 'ex', 'erlang', 'haskell', 'hs',
|
|
22
|
-
'ocaml', 'ml', 'fsharp', 'clojure', 'lisp', 'scheme',
|
|
23
|
-
'dart', 'zig', 'nim', 'v', 'wasm', 'solidity', 'sol',
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* ```typescript → { language: 'typescript' }
|
|
31
|
-
* ```typescript:src/main.tsx → { language: 'typescript', filePath: 'src/main.tsx' }
|
|
32
|
-
* ```src/main.tsx → { language: 'typescript', filePath: 'src/main.tsx' }
|
|
33
|
-
* ```12:30:src/main.tsx → { language: undefined, filePath: 'src/main.tsx', startLine: 12 }
|
|
34
|
-
*/
|
|
35
|
-
function parseCodeBlockSpec(spec: string | null): { language?: string; filePath?: string; startLine?: number } {
|
|
36
|
-
if (!spec) return {};
|
|
37
|
-
|
|
38
|
-
// Format: startLine:endLine:filepath (e.g., 12:30:src/main.tsx)
|
|
39
|
-
const lineRefMatch = spec.match(/^(\d+):(\d+):(.+)$/);
|
|
40
|
-
if (lineRefMatch) {
|
|
41
|
-
const filePath = lineRefMatch[3];
|
|
42
|
-
const ext = filePath.split('.').pop()?.toLowerCase();
|
|
43
|
-
return {
|
|
44
|
-
language: ext && KNOWN_LANGUAGES.has(ext) ? ext : undefined,
|
|
45
|
-
filePath,
|
|
46
|
-
startLine: parseInt(lineRefMatch[1], 10),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Format: language:filepath (e.g., typescript:src/main.tsx)
|
|
51
|
-
const colonIdx = spec.indexOf(':');
|
|
52
|
-
if (colonIdx > 0) {
|
|
53
|
-
const before = spec.slice(0, colonIdx).toLowerCase();
|
|
54
|
-
const after = spec.slice(colonIdx + 1);
|
|
55
|
-
if (KNOWN_LANGUAGES.has(before) && after.length > 0) {
|
|
56
|
-
return { language: before, filePath: after };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Plain language (e.g., typescript)
|
|
61
|
-
if (KNOWN_LANGUAGES.has(spec.toLowerCase())) {
|
|
62
|
-
return { language: spec.toLowerCase() };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Might be a file path (contains / or .)
|
|
66
|
-
if (spec.includes('/') || spec.includes('.')) {
|
|
67
|
-
const ext = spec.split('.').pop()?.toLowerCase();
|
|
68
|
-
return {
|
|
69
|
-
language: ext && KNOWN_LANGUAGES.has(ext) ? ext : undefined,
|
|
70
|
-
filePath: spec,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Fallback: treat as language
|
|
75
|
-
return { language: spec };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Markdown 模式匹配
|
|
80
|
-
*/
|
|
81
|
-
const MARKDOWN_PATTERNS = {
|
|
82
|
-
codeBlock: /^(\s*)```([^\s]*?)?\s*$/,
|
|
83
|
-
heading: /^(#{1,6})\s+(.+)/,
|
|
84
|
-
ulItem: /^(\s*)([-*+])\s+(.+)/,
|
|
85
|
-
olItem: /^(\s*)(\d+)\.\s+(.+)/,
|
|
86
|
-
hr: /^[-*_]{3,}\s*$/,
|
|
87
|
-
table: /^\|(.+)\|$/,
|
|
88
|
-
tableSeparator: /^\|[\s]*:?-+:?[\s]*(\|[\s]*:?-+:?[\s]*)+\|?$/,
|
|
89
|
-
blockquote: /^>\s*(.*)$/,
|
|
90
|
-
empty: /^\s*$/,
|
|
91
|
-
} as const;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
*/
|
|
96
|
-
const INLINE_PATTERNS = {
|
|
97
|
-
bold: /\*\*(.+?)\*\*/g,
|
|
98
|
-
italic: /\*(.+?)\*/g,
|
|
99
|
-
code: /`([^`]+)`/g,
|
|
100
|
-
strikethrough: /~~(.+?)~~/g,
|
|
101
|
-
link: /\[([^\]]+)\]\(([^)]+)\)/g,
|
|
102
|
-
} as const;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
*
|
|
106
|
-
*/
|
|
107
|
-
export function parseMarkdown(content: string): ParsedBlock[] {
|
|
108
|
-
const blocks: ParsedBlock[] = [];
|
|
109
|
-
const lines = content.split(/\r?\n/);
|
|
110
|
-
|
|
111
|
-
let inCodeBlock = false;
|
|
112
|
-
let codeBlockContent: string[] = [];
|
|
113
|
-
let codeBlockSpec: ReturnType<typeof parseCodeBlockSpec> = {};
|
|
114
|
-
let codeBlockIndent = 0; // 代码块开始行的缩进
|
|
115
|
-
|
|
116
|
-
let inTable = false;
|
|
117
|
-
let tableHeaders: string[] = [];
|
|
118
|
-
let tableRows: string[][] = [];
|
|
119
|
-
let tableAlignments: ('left' | 'center' | 'right')[] = [];
|
|
120
|
-
|
|
121
|
-
for (let i = 0; i < lines.length; i++) {
|
|
122
|
-
const line = lines[i];
|
|
123
|
-
|
|
124
|
-
// ===== 代码块处
|
|
125
|
-
if (inCodeBlock) {
|
|
126
|
-
const match = line.match(MARKDOWN_PATTERNS.codeBlock);
|
|
127
|
-
if (match && match[2] === undefined) {
|
|
128
|
-
// 代码块结
|
|
129
|
-
blocks.push({
|
|
130
|
-
type: 'code',
|
|
131
|
-
content: codeBlockContent.join('\n'),
|
|
132
|
-
language: codeBlockSpec.language,
|
|
133
|
-
filePath: codeBlockSpec.filePath,
|
|
134
|
-
});
|
|
135
|
-
inCodeBlock = false;
|
|
136
|
-
codeBlockContent = [];
|
|
137
|
-
codeBlockSpec = {};
|
|
138
|
-
codeBlockIndent = 0;
|
|
139
|
-
} else {
|
|
140
|
-
// 去除代码块开始行的缩进量(处理缩进代码
|
|
141
|
-
const stripped = codeBlockIndent > 0 && line.startsWith(' '.repeat(codeBlockIndent))
|
|
142
|
-
? line.slice(codeBlockIndent)
|
|
143
|
-
: line;
|
|
144
|
-
codeBlockContent.push(stripped);
|
|
145
|
-
}
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// 检查代码块开
|
|
150
|
-
const codeMatch = line.match(MARKDOWN_PATTERNS.codeBlock);
|
|
151
|
-
if (codeMatch) {
|
|
152
|
-
// 先完成表
|
|
153
|
-
if (inTable) {
|
|
154
|
-
blocks.push(createTableBlock(tableHeaders, tableRows, tableAlignments));
|
|
155
|
-
inTable = false;
|
|
156
|
-
tableHeaders = [];
|
|
157
|
-
tableRows = [];
|
|
158
|
-
tableAlignments = [];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
inCodeBlock = true;
|
|
162
|
-
codeBlockIndent = codeMatch[1]?.length || 0; // 记录缩进
|
|
163
|
-
codeBlockSpec = parseCodeBlockSpec(codeMatch[2] || null);
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// ===== 表格处
|
|
168
|
-
if (MARKDOWN_PATTERNS.table.test(line)) {
|
|
169
|
-
const cells = parseTableRow(line);
|
|
170
|
-
|
|
171
|
-
if (!inTable) {
|
|
172
|
-
// 可能是表
|
|
173
|
-
tableHeaders = cells;
|
|
174
|
-
inTable = true;
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// 检查是否是分隔
|
|
179
|
-
if (MARKDOWN_PATTERNS.tableSeparator.test(line)) {
|
|
180
|
-
tableAlignments = parseTableAlignments(line);
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// 数据
|
|
185
|
-
tableRows.push(cells);
|
|
186
|
-
continue;
|
|
187
|
-
} else if (inTable) {
|
|
188
|
-
// 表格结
|
|
189
|
-
blocks.push(createTableBlock(tableHeaders, tableRows, tableAlignments));
|
|
190
|
-
inTable = false;
|
|
191
|
-
tableHeaders = [];
|
|
192
|
-
tableRows = [];
|
|
193
|
-
tableAlignments = [];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// ===== 空
|
|
197
|
-
if (MARKDOWN_PATTERNS.empty.test(line)) {
|
|
198
|
-
blocks.push({ type: 'empty', content: '' });
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// ===== 水平
|
|
203
|
-
if (MARKDOWN_PATTERNS.hr.test(line)) {
|
|
204
|
-
blocks.push({ type: 'hr', content: '' });
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// ===== 标
|
|
209
|
-
const headingMatch = line.match(MARKDOWN_PATTERNS.heading);
|
|
210
|
-
if (headingMatch) {
|
|
211
|
-
blocks.push({
|
|
212
|
-
type: 'heading',
|
|
213
|
-
content: headingMatch[2],
|
|
214
|
-
level: headingMatch[1].length,
|
|
215
|
-
});
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// ===== 无序列
|
|
220
|
-
const ulMatch = line.match(MARKDOWN_PATTERNS.ulItem);
|
|
221
|
-
if (ulMatch) {
|
|
222
|
-
blocks.push({
|
|
223
|
-
type: 'list',
|
|
224
|
-
content: ulMatch[3],
|
|
225
|
-
listType: 'ul',
|
|
226
|
-
marker: ulMatch[2],
|
|
227
|
-
indent: ulMatch[1].length,
|
|
228
|
-
});
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// ===== 有序列
|
|
233
|
-
const olMatch = line.match(MARKDOWN_PATTERNS.olItem);
|
|
234
|
-
if (olMatch) {
|
|
235
|
-
blocks.push({
|
|
236
|
-
type: 'list',
|
|
237
|
-
content: olMatch[3],
|
|
238
|
-
listType: 'ol',
|
|
239
|
-
marker: olMatch[2] + '.',
|
|
240
|
-
indent: olMatch[1].length,
|
|
241
|
-
});
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// ===== 引
|
|
246
|
-
const blockquoteMatch = line.match(MARKDOWN_PATTERNS.blockquote);
|
|
247
|
-
if (blockquoteMatch) {
|
|
248
|
-
blocks.push({
|
|
249
|
-
type: 'blockquote',
|
|
250
|
-
content: blockquoteMatch[1],
|
|
251
|
-
});
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// ===== 普通文
|
|
256
|
-
blocks.push({ type: 'text', content: line });
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Suppress empty code blocks during streaming — content arrives fast enough
|
|
260
|
-
// that the flash of an empty box is worse UX than a 1-frame delay.
|
|
261
|
-
if (inCodeBlock && codeBlockContent.length > 0) {
|
|
262
|
-
blocks.push({
|
|
263
|
-
type: 'code',
|
|
264
|
-
content: codeBlockContent.join('\n'),
|
|
265
|
-
language: codeBlockSpec.language,
|
|
266
|
-
filePath: codeBlockSpec.filePath,
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// 处理未结束的表
|
|
271
|
-
if (inTable && tableHeaders.length > 0) {
|
|
272
|
-
blocks.push(createTableBlock(tableHeaders, tableRows, tableAlignments));
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return blocks;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
*
|
|
280
|
-
*/
|
|
281
|
-
function parseTableRow(line: string): string[] {
|
|
282
|
-
return line
|
|
283
|
-
.slice(1, -1) // 去掉首尾
|
|
284
|
-
.split('|')
|
|
285
|
-
.map(cell => cell.trim());
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
*
|
|
290
|
-
*/
|
|
291
|
-
function parseTableAlignments(line: string): ('left' | 'center' | 'right')[] {
|
|
292
|
-
return line
|
|
293
|
-
.slice(1, -1)
|
|
294
|
-
.split('|')
|
|
295
|
-
.map(cell => {
|
|
296
|
-
const trimmed = cell.trim();
|
|
297
|
-
if (trimmed.startsWith(':') && trimmed.endsWith(':')) {
|
|
298
|
-
return 'center';
|
|
299
|
-
}
|
|
300
|
-
if (trimmed.endsWith(':')) {
|
|
301
|
-
return 'right';
|
|
302
|
-
}
|
|
303
|
-
return 'left';
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
*
|
|
309
|
-
*/
|
|
310
|
-
function createTableBlock(
|
|
311
|
-
headers: string[],
|
|
312
|
-
rows: string[][],
|
|
313
|
-
alignments: ('left' | 'center' | 'right')[]
|
|
314
|
-
): ParsedBlock {
|
|
315
|
-
return {
|
|
316
|
-
type: 'table',
|
|
317
|
-
content: '',
|
|
318
|
-
tableData: {
|
|
319
|
-
headers,
|
|
320
|
-
rows,
|
|
321
|
-
alignments: alignments.length > 0 ? alignments : headers.map(() => 'left'),
|
|
322
|
-
},
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
*
|
|
328
|
-
*/
|
|
329
|
-
export function stripMarkdown(text: string): string {
|
|
330
|
-
return text
|
|
331
|
-
.replace(/\*\*(.+?)\*\*/g, '$1') // 粗
|
|
332
|
-
.replace(/\*(.+?)\*/g, '$1') // 斜
|
|
333
|
-
.replace(/~~(.+?)~~/g, '$1') // 删除
|
|
334
|
-
.replace(/`([^`]+)`/g, '$1') // 代
|
|
335
|
-
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1'); // 链
|
|
336
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Markdown 解析器类型定义
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export type BlockType =
|
|
9
|
-
| 'text'
|
|
10
|
-
| 'code'
|
|
11
|
-
| 'heading'
|
|
12
|
-
| 'table'
|
|
13
|
-
| 'list'
|
|
14
|
-
| 'hr'
|
|
15
|
-
| 'empty'
|
|
16
|
-
| 'blockquote';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export type ListType = 'ul' | 'ol';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
26
|
-
export interface TableData {
|
|
27
|
-
headers: string[];
|
|
28
|
-
rows: string[][];
|
|
29
|
-
alignments: ('left' | 'center' | 'right')[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
export interface ParsedBlock {
|
|
36
|
-
type: BlockType;
|
|
37
|
-
content: string;
|
|
38
|
-
language?: string;
|
|
39
|
-
/** 代码块关联的文件路径 */
|
|
40
|
-
filePath?: string;
|
|
41
|
-
level?: number;
|
|
42
|
-
listType?: ListType;
|
|
43
|
-
marker?: string;
|
|
44
|
-
tableData?: TableData;
|
|
45
|
-
indent?: number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
*/
|
|
51
|
-
export type InlineFormatType =
|
|
52
|
-
| 'bold'
|
|
53
|
-
| 'italic'
|
|
54
|
-
| 'code'
|
|
55
|
-
| 'link'
|
|
56
|
-
| 'strikethrough'
|
|
57
|
-
| 'text';
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
*/
|
|
62
|
-
export interface InlineSegment {
|
|
63
|
-
type: InlineFormatType;
|
|
64
|
-
content: string;
|
|
65
|
-
url?: string;
|
|
66
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { FocusId, type FocusState, type FocusActions } from './types.js';
|
|
8
|
-
|
|
9
|
-
type FocusListener = (state: FocusState) => void;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
class FocusManagerImpl {
|
|
15
|
-
private state: FocusState = {
|
|
16
|
-
currentFocus: FocusId.MAIN_INPUT,
|
|
17
|
-
previousFocus: null,
|
|
18
|
-
focusStack: [FocusId.MAIN_INPUT],
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
private listeners: Set<FocusListener> = new Set();
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
26
|
-
getState(): FocusState {
|
|
27
|
-
return { ...this.state };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
getCurrentFocus(): FocusId {
|
|
34
|
-
return this.state.currentFocus;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
setFocus(id: FocusId): void {
|
|
41
|
-
if (this.state.currentFocus === id) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
this.state = {
|
|
46
|
-
currentFocus: id,
|
|
47
|
-
previousFocus: this.state.currentFocus,
|
|
48
|
-
focusStack: [...this.state.focusStack, id],
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
this.notify();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
pushFocus(id: FocusId): void {
|
|
58
|
-
this.state = {
|
|
59
|
-
currentFocus: id,
|
|
60
|
-
previousFocus: this.state.currentFocus,
|
|
61
|
-
focusStack: [...this.state.focusStack, id],
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
this.notify();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
*/
|
|
70
|
-
popFocus(): void {
|
|
71
|
-
if (this.state.focusStack.length <= 1) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const newStack = this.state.focusStack.slice(0, -1);
|
|
76
|
-
const previousFocus = newStack[newStack.length - 1] || FocusId.MAIN_INPUT;
|
|
77
|
-
|
|
78
|
-
this.state = {
|
|
79
|
-
currentFocus: previousFocus,
|
|
80
|
-
previousFocus: this.state.currentFocus,
|
|
81
|
-
focusStack: newStack,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
this.notify();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
*
|
|
89
|
-
*/
|
|
90
|
-
resetFocus(): void {
|
|
91
|
-
this.state = {
|
|
92
|
-
currentFocus: FocusId.MAIN_INPUT,
|
|
93
|
-
previousFocus: this.state.currentFocus,
|
|
94
|
-
focusStack: [FocusId.MAIN_INPUT],
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
this.notify();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
*/
|
|
103
|
-
subscribe(listener: FocusListener): () => void {
|
|
104
|
-
this.listeners.add(listener);
|
|
105
|
-
return () => {
|
|
106
|
-
this.listeners.delete(listener);
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
*
|
|
112
|
-
*/
|
|
113
|
-
private notify(): void {
|
|
114
|
-
const state = this.getState();
|
|
115
|
-
for (const listener of this.listeners) {
|
|
116
|
-
listener(state);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
*/
|
|
123
|
-
getActions(): FocusActions {
|
|
124
|
-
return {
|
|
125
|
-
setFocus: (id: FocusId) => this.setFocus(id),
|
|
126
|
-
popFocus: () => this.popFocus(),
|
|
127
|
-
resetFocus: () => this.resetFocus(),
|
|
128
|
-
pushFocus: (id: FocusId) => this.pushFocus(id),
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// 导出单
|
|
134
|
-
export const focusManager = new FocusManagerImpl();
|
|
135
|
-
|
|
136
|
-
// 导出操作快捷方
|
|
137
|
-
export const focusActions = focusManager.getActions();
|
package/src/ui/focus/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { FocusId, type FocusState, type FocusActions } from './types.js';
|
|
6
|
-
export { focusManager, focusActions } from './FocusManager.js';
|
|
7
|
-
export {
|
|
8
|
-
useCurrentFocus,
|
|
9
|
-
useFocusState,
|
|
10
|
-
useFocusActions,
|
|
11
|
-
useIsFocused,
|
|
12
|
-
useFocus,
|
|
13
|
-
} from './useFocus.js';
|
package/src/ui/focus/types.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
export enum FocusId {
|
|
10
|
-
/** 主输入框 */
|
|
11
|
-
MAIN_INPUT = 'main-input',
|
|
12
|
-
/** 确认对话框 */
|
|
13
|
-
CONFIRMATION_PROMPT = 'confirmation-prompt',
|
|
14
|
-
/** 主题选择器 */
|
|
15
|
-
THEME_SELECTOR = 'theme-selector',
|
|
16
|
-
/** 模型选择器 */
|
|
17
|
-
MODEL_SELECTOR = 'model-selector',
|
|
18
|
-
/** 会话选择器 */
|
|
19
|
-
SESSION_SELECTOR = 'session-selector',
|
|
20
|
-
/** 文件选择器 */
|
|
21
|
-
FILE_SELECTOR = 'file-selector',
|
|
22
|
-
/** 帮助面板 */
|
|
23
|
-
HELP_PANEL = 'help-panel',
|
|
24
|
-
/** 通用选择器 */
|
|
25
|
-
SELECTOR = 'selector',
|
|
26
|
-
/** 无焦点 */
|
|
27
|
-
NONE = 'none',
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
export interface FocusState {
|
|
34
|
-
/** 当前焦点 ID */
|
|
35
|
-
currentFocus: FocusId;
|
|
36
|
-
/** 上一个焦点 ID(用于返回) */
|
|
37
|
-
previousFocus: FocusId | null;
|
|
38
|
-
/** 焦点历史栈 */
|
|
39
|
-
focusStack: FocusId[];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
*/
|
|
45
|
-
export interface FocusActions {
|
|
46
|
-
/** 设置焦点 */
|
|
47
|
-
setFocus: (id: FocusId) => void;
|
|
48
|
-
/** 返回上一个焦点 */
|
|
49
|
-
popFocus: () => void;
|
|
50
|
-
/** 重置焦点到默认 */
|
|
51
|
-
resetFocus: () => void;
|
|
52
|
-
/** 推入焦点栈 */
|
|
53
|
-
pushFocus: (id: FocusId) => void;
|
|
54
|
-
}
|
package/src/ui/focus/useFocus.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { useState, useEffect, useCallback } from 'react';
|
|
6
|
-
import { focusManager, focusActions } from './FocusManager.js';
|
|
7
|
-
import { FocusId, type FocusState, type FocusActions } from './types.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
export const useCurrentFocus = (): FocusId => {
|
|
13
|
-
const [currentFocus, setCurrentFocus] = useState<FocusId>(
|
|
14
|
-
focusManager.getCurrentFocus()
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const unsubscribe = focusManager.subscribe((state) => {
|
|
19
|
-
setCurrentFocus(state.currentFocus);
|
|
20
|
-
});
|
|
21
|
-
return unsubscribe;
|
|
22
|
-
}, []);
|
|
23
|
-
|
|
24
|
-
return currentFocus;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
export const useFocusState = (): FocusState => {
|
|
31
|
-
const [state, setState] = useState<FocusState>(focusManager.getState());
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
const unsubscribe = focusManager.subscribe((newState) => {
|
|
35
|
-
setState(newState);
|
|
36
|
-
});
|
|
37
|
-
return unsubscribe;
|
|
38
|
-
}, []);
|
|
39
|
-
|
|
40
|
-
return state;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
45
|
-
*/
|
|
46
|
-
export const useFocusActions = (): FocusActions => {
|
|
47
|
-
return focusActions;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
52
|
-
*/
|
|
53
|
-
export const useIsFocused = (focusId: FocusId): boolean => {
|
|
54
|
-
const currentFocus = useCurrentFocus();
|
|
55
|
-
return currentFocus === focusId;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
*
|
|
60
|
-
*/
|
|
61
|
-
export const useFocus = () => {
|
|
62
|
-
const state = useFocusState();
|
|
63
|
-
const actions = useFocusActions();
|
|
64
|
-
|
|
65
|
-
const isFocused = useCallback(
|
|
66
|
-
(id: FocusId) => state.currentFocus === id,
|
|
67
|
-
[state.currentFocus]
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
...state,
|
|
72
|
-
...actions,
|
|
73
|
-
isFocused,
|
|
74
|
-
};
|
|
75
|
-
};
|
package/src/ui/hooks/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* UI Hooks 导出
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { useTerminalWidth, useTerminalHeight, useTerminalSize } from './useTerminalWidth.js';
|
|
6
|
-
export { useCommandHistory } from './useCommandHistory.js';
|
|
7
|
-
export { useInputBuffer } from './useInputBuffer.js';
|
|
8
|
-
export { useCtrlCHandler } from './useCtrlCHandler.js';
|
|
9
|
-
export { useConfirmation } from './useConfirmation.js';
|
|
10
|
-
export { useAgent } from './useAgent.js';
|
|
11
|
-
export { useCommandProcessor } from './useCommandProcessor.js';
|