aegiscode 3.1.7 → 3.1.10

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.
Files changed (206) hide show
  1. package/README.md +23 -15
  2. package/dist/main.js +555 -556
  3. package/package.json +4 -2
  4. package/src/agent/Agent.ts +903 -0
  5. package/src/agent/SimpleAgent.ts +48 -0
  6. package/src/agent/index.ts +54 -0
  7. package/src/agent/orchestrator/AppBuilder.ts +443 -0
  8. package/src/agent/orchestrator/CouncilAgent.ts +310 -0
  9. package/src/agent/orchestrator/DiscussionRoom.ts +462 -0
  10. package/src/agent/orchestrator/OrchestratorAgent.ts +637 -0
  11. package/src/agent/orchestrator/index.ts +38 -0
  12. package/src/agent/orchestrator/utils.ts +397 -0
  13. package/src/agent/pricing.ts +115 -0
  14. package/src/agent/router.ts +74 -0
  15. package/src/agent/routerStats.ts +121 -0
  16. package/src/agent/types.ts +318 -0
  17. package/src/auth/login.ts +383 -0
  18. package/src/cli/config.ts +189 -0
  19. package/src/cli/index.ts +17 -0
  20. package/src/cli/middleware.ts +119 -0
  21. package/src/cli/types.ts +75 -0
  22. package/src/config/ConfigManager.ts +587 -0
  23. package/src/config/index.ts +7 -0
  24. package/src/config/types.ts +584 -0
  25. package/src/context/CompactionService.ts +300 -0
  26. package/src/context/ContextManager.ts +450 -0
  27. package/src/context/FileAnalyzer.ts +267 -0
  28. package/src/context/TokenCounter.ts +265 -0
  29. package/src/context/index.ts +27 -0
  30. package/src/context/storage/CacheStore.ts +176 -0
  31. package/src/context/storage/JSONLStore.ts +201 -0
  32. package/src/context/storage/MemoryStore.ts +205 -0
  33. package/src/context/storage/PersistentStore.ts +327 -0
  34. package/src/context/storage/index.ts +9 -0
  35. package/src/context/storage/pathUtils.ts +114 -0
  36. package/src/context/test.ts +309 -0
  37. package/src/context/types.ts +268 -0
  38. package/src/hooks/HookExecutor.ts +434 -0
  39. package/src/hooks/HookManager.ts +596 -0
  40. package/src/hooks/HookService.ts +269 -0
  41. package/src/hooks/Matcher.ts +157 -0
  42. package/src/hooks/index.ts +63 -0
  43. package/src/hooks/types.ts +424 -0
  44. package/src/main.tsx +596 -0
  45. package/src/mcp/HealthMonitor.ts +150 -0
  46. package/src/mcp/McpClient.ts +491 -0
  47. package/src/mcp/McpRegistry.ts +321 -0
  48. package/src/mcp/createMcpTool.ts +251 -0
  49. package/src/mcp/index.ts +15 -0
  50. package/src/mcp/server.ts +334 -0
  51. package/src/mcp/test-server.ts +88 -0
  52. package/src/mcp/test.ts +372 -0
  53. package/src/mcp/types.ts +247 -0
  54. package/src/memory/AgentMemoryBus.ts +432 -0
  55. package/src/memory/CloudSync.ts +99 -0
  56. package/src/memory/DriveSync.ts +106 -0
  57. package/src/memory/SharedMemory.ts +951 -0
  58. package/src/memory/index.ts +14 -0
  59. package/src/memory/machineFingerprint.ts +40 -0
  60. package/src/orchestrator/SubAgentMetadata.ts +136 -0
  61. package/src/prompts/builder.ts +213 -0
  62. package/src/prompts/default.ts +144 -0
  63. package/src/prompts/index.ts +16 -0
  64. package/src/prompts/plan.ts +64 -0
  65. package/src/prompts/test.ts +78 -0
  66. package/src/services/AnthropicChatService.ts +341 -0
  67. package/src/services/ChatService.ts +347 -0
  68. package/src/services/ClaudeCliChatService.ts +256 -0
  69. package/src/services/CloudSync.ts +168 -0
  70. package/src/services/CostLedger.ts +211 -0
  71. package/src/services/Heartbeat.ts +135 -0
  72. package/src/services/LearningCollector.ts +291 -0
  73. package/src/services/OllamaInstaller.ts +342 -0
  74. package/src/services/VersionChecker.ts +445 -0
  75. package/src/services/index.ts +57 -0
  76. package/src/services/streaming/OpenAIEventAdapter.ts +126 -0
  77. package/src/services/streaming/RenderingProfile.ts +90 -0
  78. package/src/services/streaming/StreamEventParser.ts +181 -0
  79. package/src/services/streaming/ThrottledRenderer.ts +139 -0
  80. package/src/services/streaming/TranscriptBuffer.ts +574 -0
  81. package/src/services/streaming/eventStatusMap.ts +52 -0
  82. package/src/services/streaming/index.ts +46 -0
  83. package/src/services/streaming/renderFormatting.ts +79 -0
  84. package/src/services/streaming/types.ts +234 -0
  85. package/src/skills/SkillLoader.ts +126 -0
  86. package/src/skills/SkillRegistry.ts +366 -0
  87. package/src/skills/index.ts +48 -0
  88. package/src/skills/types.ts +146 -0
  89. package/src/slash-commands/billing.ts +70 -0
  90. package/src/slash-commands/build.ts +413 -0
  91. package/src/slash-commands/builtinCommands.ts +2733 -0
  92. package/src/slash-commands/clone.ts +242 -0
  93. package/src/slash-commands/council.ts +125 -0
  94. package/src/slash-commands/custom/CustomCommandExecutor.ts +143 -0
  95. package/src/slash-commands/custom/CustomCommandLoader.ts +251 -0
  96. package/src/slash-commands/custom/CustomCommandRegistry.ts +144 -0
  97. package/src/slash-commands/custom/index.ts +7 -0
  98. package/src/slash-commands/debate.ts +254 -0
  99. package/src/slash-commands/gmail.ts +105 -0
  100. package/src/slash-commands/index.ts +388 -0
  101. package/src/slash-commands/mcpCommand.ts +205 -0
  102. package/src/slash-commands/types.ts +201 -0
  103. package/src/store/index.ts +76 -0
  104. package/src/store/selectors.ts +246 -0
  105. package/src/store/slices/appSlice.ts +205 -0
  106. package/src/store/slices/commandSlice.ts +115 -0
  107. package/src/store/slices/configSlice.ts +46 -0
  108. package/src/store/slices/focusSlice.ts +64 -0
  109. package/src/store/slices/index.ts +9 -0
  110. package/src/store/slices/sessionSlice.ts +424 -0
  111. package/src/store/streaming-buffer.ts +425 -0
  112. package/src/store/test.ts +296 -0
  113. package/src/store/types.ts +274 -0
  114. package/src/store/vanilla.ts +186 -0
  115. package/src/tools/builtin/bash.ts +236 -0
  116. package/src/tools/builtin/council.ts +105 -0
  117. package/src/tools/builtin/edit.ts +213 -0
  118. package/src/tools/builtin/glob.ts +136 -0
  119. package/src/tools/builtin/grep.ts +263 -0
  120. package/src/tools/builtin/index.ts +61 -0
  121. package/src/tools/builtin/memory.ts +66 -0
  122. package/src/tools/builtin/read.ts +168 -0
  123. package/src/tools/builtin/skill.ts +97 -0
  124. package/src/tools/builtin/snapshot.ts +40 -0
  125. package/src/tools/builtin/task.ts +106 -0
  126. package/src/tools/builtin/write.ts +134 -0
  127. package/src/tools/createTool.ts +221 -0
  128. package/src/tools/execution/ExecutionPipeline.ts +263 -0
  129. package/src/tools/execution/index.ts +40 -0
  130. package/src/tools/execution/stages/CacheStage.ts +131 -0
  131. package/src/tools/execution/stages/ConfirmationStage.ts +203 -0
  132. package/src/tools/execution/stages/DiscoveryStage.ts +46 -0
  133. package/src/tools/execution/stages/ExecutionStage.ts +48 -0
  134. package/src/tools/execution/stages/FormattingStage.ts +44 -0
  135. package/src/tools/execution/stages/HookStage.ts +72 -0
  136. package/src/tools/execution/stages/PermissionStage.ts +287 -0
  137. package/src/tools/execution/stages/PostHookStage.ts +71 -0
  138. package/src/tools/execution/stages/index.ts +12 -0
  139. package/src/tools/execution/test.ts +266 -0
  140. package/src/tools/execution/types.ts +273 -0
  141. package/src/tools/index.ts +81 -0
  142. package/src/tools/registry.ts +304 -0
  143. package/src/tools/schemas.ts +109 -0
  144. package/src/tools/test.ts +220 -0
  145. package/src/tools/types.ts +175 -0
  146. package/src/tools/validation/PermissionChecker.ts +242 -0
  147. package/src/tools/validation/SensitiveFileDetector.ts +210 -0
  148. package/src/tools/validation/index.ts +11 -0
  149. package/src/ui/App.tsx +166 -0
  150. package/src/ui/components/AegisInterface.tsx +484 -0
  151. package/src/ui/components/common/ChatSearch.tsx +150 -0
  152. package/src/ui/components/common/ErrorBoundary.tsx +82 -0
  153. package/src/ui/components/common/ExitMessage.tsx +120 -0
  154. package/src/ui/components/common/LoadingIndicator.tsx +49 -0
  155. package/src/ui/components/common/index.ts +6 -0
  156. package/src/ui/components/dialog/ConfirmationPrompt.tsx +208 -0
  157. package/src/ui/components/dialog/InteractiveSelector.tsx +149 -0
  158. package/src/ui/components/dialog/SetupWizard.tsx +297 -0
  159. package/src/ui/components/dialog/UpdatePrompt.tsx +155 -0
  160. package/src/ui/components/dialog/index.ts +8 -0
  161. package/src/ui/components/index.ts +28 -0
  162. package/src/ui/components/input/CommandSuggestions.tsx +139 -0
  163. package/src/ui/components/input/CustomTextInput.tsx +220 -0
  164. package/src/ui/components/input/InputArea.tsx +361 -0
  165. package/src/ui/components/input/PromptSuggestions.tsx +66 -0
  166. package/src/ui/components/input/index.ts +6 -0
  167. package/src/ui/components/layout/ChatStatusBar.tsx +90 -0
  168. package/src/ui/components/layout/ContextBar.tsx +79 -0
  169. package/src/ui/components/layout/MessageArea.tsx +96 -0
  170. package/src/ui/components/layout/MessageList.tsx +647 -0
  171. package/src/ui/components/layout/MessageSeparator.tsx +26 -0
  172. package/src/ui/components/layout/WelcomeMessage.tsx +93 -0
  173. package/src/ui/components/layout/index.ts +7 -0
  174. package/src/ui/components/markdown/CodeHighlighter.tsx +292 -0
  175. package/src/ui/components/markdown/MessageRenderer.tsx +1211 -0
  176. package/src/ui/components/markdown/index.ts +8 -0
  177. package/src/ui/components/markdown/parser.ts +336 -0
  178. package/src/ui/components/markdown/types.ts +66 -0
  179. package/src/ui/focus/FocusManager.ts +137 -0
  180. package/src/ui/focus/index.ts +13 -0
  181. package/src/ui/focus/types.ts +54 -0
  182. package/src/ui/focus/useFocus.ts +75 -0
  183. package/src/ui/hooks/index.ts +11 -0
  184. package/src/ui/hooks/useAgent.ts +284 -0
  185. package/src/ui/hooks/useCommandHistory.ts +87 -0
  186. package/src/ui/hooks/useCommandProcessor.ts +443 -0
  187. package/src/ui/hooks/useConfirmation.ts +99 -0
  188. package/src/ui/hooks/useCtrlCHandler.ts +100 -0
  189. package/src/ui/hooks/useInputBuffer.ts +122 -0
  190. package/src/ui/hooks/useTerminalSize.ts +68 -0
  191. package/src/ui/hooks/useTerminalWidth.ts +5 -0
  192. package/src/ui/hooks/useWindowedList.ts +118 -0
  193. package/src/ui/render-debugger.ts +621 -0
  194. package/src/ui/test.ts +189 -0
  195. package/src/ui/themes/ThemeManager.ts +332 -0
  196. package/src/ui/themes/aegisTheme.ts +87 -0
  197. package/src/ui/themes/darkTheme.ts +87 -0
  198. package/src/ui/themes/defaultTheme.ts +85 -0
  199. package/src/ui/themes/index.ts +10 -0
  200. package/src/ui/themes/lightTheme.ts +89 -0
  201. package/src/ui/themes/popularThemes.ts +187 -0
  202. package/src/ui/themes/types.ts +130 -0
  203. package/src/utils/clipboard.ts +48 -0
  204. package/src/utils/debug.ts +43 -0
  205. package/src/utils/environment.ts +68 -0
  206. package/src/utils/index.ts +10 -0
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Markdown 组件导出
3
+ */
4
+
5
+ export * from './types.js';
6
+ export { parseMarkdown, stripMarkdown } from './parser.js';
7
+ export { MessageRenderer } from './MessageRenderer.js';
8
+ export { CodeHighlighter } from './CodeHighlighter.js';
@@ -0,0 +1,336 @@
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
+ }
@@ -0,0 +1,66 @@
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
+ }
@@ -0,0 +1,137 @@
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();
@@ -0,0 +1,13 @@
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';
@@ -0,0 +1,54 @@
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
+ }
@@ -0,0 +1,75 @@
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
+ };
@@ -0,0 +1,11 @@
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';