@abacus-ai/cli 1.106.25007 → 2.0.0-canary.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.
Files changed (200) hide show
  1. package/.oxlintrc.json +8 -0
  2. package/dist/index.mjs +12603 -0
  3. package/package.json +7 -39
  4. package/resources/abacus.ico +0 -0
  5. package/resources/entitlements.plist +9 -0
  6. package/src/__e2e__/README.md +196 -0
  7. package/src/__e2e__/agent-interactions.e2e.test.tsx +61 -0
  8. package/src/__e2e__/cli-commands.e2e.test.tsx +77 -0
  9. package/src/__e2e__/conversation-throttle.e2e.test.ts +453 -0
  10. package/src/__e2e__/conversation.e2e.test.tsx +56 -0
  11. package/src/__e2e__/diff-preview.e2e.test.tsx +3399 -0
  12. package/src/__e2e__/file-creation.e2e.test.tsx +149 -0
  13. package/src/__e2e__/helpers/test-helpers.ts +450 -0
  14. package/src/__e2e__/keyboard-navigation.e2e.test.tsx +34 -0
  15. package/src/__e2e__/llm-models.e2e.test.ts +402 -0
  16. package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +71 -0
  17. package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +167 -0
  18. package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +185 -0
  19. package/src/__e2e__/repl.e2e.test.tsx +78 -0
  20. package/src/__e2e__/shell-compatibility.e2e.test.tsx +76 -0
  21. package/src/__e2e__/theme-mcp.e2e.test.tsx +98 -0
  22. package/src/__e2e__/tool-permissions.e2e.test.tsx +66 -0
  23. package/src/args.ts +22 -0
  24. package/src/components/__tests__/react-compiler.test.tsx +78 -0
  25. package/src/components/__tests__/status-indicator.test.tsx +403 -0
  26. package/src/components/composer/__tests__/bash-runner.test.tsx +263 -0
  27. package/src/components/composer/agent-mode-indicator.tsx +63 -0
  28. package/src/components/composer/bash-runner.tsx +54 -0
  29. package/src/components/composer/commands/default-commands.tsx +615 -0
  30. package/src/components/composer/commands/handler.tsx +59 -0
  31. package/src/components/composer/commands/picker.tsx +273 -0
  32. package/src/components/composer/commands/registry.ts +233 -0
  33. package/src/components/composer/commands/types.ts +33 -0
  34. package/src/components/composer/context.tsx +88 -0
  35. package/src/components/composer/file-mention-picker.tsx +83 -0
  36. package/src/components/composer/help.tsx +44 -0
  37. package/src/components/composer/index.tsx +1006 -0
  38. package/src/components/composer/mentions.ts +57 -0
  39. package/src/components/composer/message-queue.tsx +70 -0
  40. package/src/components/composer/mode-panel.tsx +35 -0
  41. package/src/components/composer/modes/__tests__/bash-handler.test.tsx +755 -0
  42. package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +1108 -0
  43. package/src/components/composer/modes/bash-handler.tsx +132 -0
  44. package/src/components/composer/modes/bash-renderer.tsx +175 -0
  45. package/src/components/composer/modes/default-handlers.tsx +33 -0
  46. package/src/components/composer/modes/index.ts +41 -0
  47. package/src/components/composer/modes/types.ts +21 -0
  48. package/src/components/composer/persistent-shell.ts +283 -0
  49. package/src/components/composer/process.ts +65 -0
  50. package/src/components/composer/types.ts +9 -0
  51. package/src/components/composer/use-mention-search.ts +68 -0
  52. package/src/components/error-boundry.tsx +60 -0
  53. package/src/components/exit-message.tsx +29 -0
  54. package/src/components/expanded-view.tsx +74 -0
  55. package/src/components/file-completion.tsx +127 -0
  56. package/src/components/header.tsx +47 -0
  57. package/src/components/logo.tsx +37 -0
  58. package/src/components/segments.tsx +356 -0
  59. package/src/components/status-indicator.tsx +306 -0
  60. package/src/components/tool-group-summary.tsx +263 -0
  61. package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +312 -0
  62. package/src/components/tool-permissions/diff-preview.tsx +355 -0
  63. package/src/components/tool-permissions/index.ts +5 -0
  64. package/src/components/tool-permissions/permission-options.tsx +375 -0
  65. package/src/components/tool-permissions/permission-preview-header.tsx +57 -0
  66. package/src/components/tool-permissions/tool-permission-ui.tsx +398 -0
  67. package/src/components/tools/agent/ask-user-question.tsx +101 -0
  68. package/src/components/tools/agent/enter-plan-mode.tsx +49 -0
  69. package/src/components/tools/agent/exit-plan-mode.tsx +75 -0
  70. package/src/components/tools/agent/handoff-to-main.tsx +27 -0
  71. package/src/components/tools/agent/subagent.tsx +37 -0
  72. package/src/components/tools/agent/todo-write.tsx +104 -0
  73. package/src/components/tools/browser/close-tab.tsx +58 -0
  74. package/src/components/tools/browser/computer.tsx +70 -0
  75. package/src/components/tools/browser/get-interactive-elements.tsx +54 -0
  76. package/src/components/tools/browser/get-tab-content.tsx +51 -0
  77. package/src/components/tools/browser/navigate-to.tsx +59 -0
  78. package/src/components/tools/browser/new-tab.tsx +60 -0
  79. package/src/components/tools/browser/perform-action.tsx +63 -0
  80. package/src/components/tools/browser/refresh-tab.tsx +43 -0
  81. package/src/components/tools/browser/switch-tab.tsx +58 -0
  82. package/src/components/tools/filesystem/delete-file.tsx +104 -0
  83. package/src/components/tools/filesystem/edit.tsx +220 -0
  84. package/src/components/tools/filesystem/list-dir.tsx +78 -0
  85. package/src/components/tools/filesystem/read-file.tsx +180 -0
  86. package/src/components/tools/filesystem/upload-image.tsx +76 -0
  87. package/src/components/tools/ide/ide-diagnostics.tsx +62 -0
  88. package/src/components/tools/index.ts +91 -0
  89. package/src/components/tools/mcp/mcp-tool.tsx +158 -0
  90. package/src/components/tools/search/fetch-url.tsx +73 -0
  91. package/src/components/tools/search/file-search.tsx +78 -0
  92. package/src/components/tools/search/grep.tsx +90 -0
  93. package/src/components/tools/search/semantic-search.tsx +66 -0
  94. package/src/components/tools/search/web-search.tsx +71 -0
  95. package/src/components/tools/shared/index.tsx +48 -0
  96. package/src/components/tools/shared/zod-coercion.ts +35 -0
  97. package/src/components/tools/terminal/bash-tool-output.tsx +174 -0
  98. package/src/components/tools/terminal/get-terminal-output.tsx +85 -0
  99. package/src/components/tools/terminal/run-in-terminal.tsx +106 -0
  100. package/src/components/tools/types.ts +16 -0
  101. package/src/components/tools.tsx +66 -0
  102. package/src/components/ui/__tests__/divider.test.tsx +61 -0
  103. package/src/components/ui/__tests__/gradient.test.tsx +125 -0
  104. package/src/components/ui/__tests__/input.test.tsx +166 -0
  105. package/src/components/ui/__tests__/select.test.tsx +273 -0
  106. package/src/components/ui/__tests__/shimmer.test.tsx +99 -0
  107. package/src/components/ui/blinking-indicator.tsx +25 -0
  108. package/src/components/ui/divider.tsx +162 -0
  109. package/src/components/ui/gradient.tsx +56 -0
  110. package/src/components/ui/input.tsx +228 -0
  111. package/src/components/ui/select.tsx +151 -0
  112. package/src/components/ui/shimmer.tsx +84 -0
  113. package/src/context/agent-mode.tsx +95 -0
  114. package/src/context/extension-file.tsx +136 -0
  115. package/src/context/network-activity.tsx +45 -0
  116. package/src/context/notification.tsx +62 -0
  117. package/src/context/shell-size.tsx +49 -0
  118. package/src/context/shell-title.tsx +38 -0
  119. package/src/entrypoints/print-mode.ts +312 -0
  120. package/src/entrypoints/repl.tsx +401 -0
  121. package/src/hooks/use-agent.ts +15 -0
  122. package/src/hooks/use-api-client.ts +1 -0
  123. package/src/hooks/use-available-height.ts +8 -0
  124. package/src/hooks/use-cleanup.ts +29 -0
  125. package/src/hooks/use-interrupt-manager.ts +242 -0
  126. package/src/hooks/use-models.ts +22 -0
  127. package/src/index.ts +217 -0
  128. package/src/lib/__tests__/ansi.test.ts +255 -0
  129. package/src/lib/__tests__/cli.test.ts +122 -0
  130. package/src/lib/__tests__/commands.test.ts +325 -0
  131. package/src/lib/__tests__/constants.test.ts +15 -0
  132. package/src/lib/__tests__/focusables.test.ts +25 -0
  133. package/src/lib/__tests__/fs.test.ts +231 -0
  134. package/src/lib/__tests__/markdown.test.tsx +348 -0
  135. package/src/lib/__tests__/mcpCommandHandler.test.ts +173 -0
  136. package/src/lib/__tests__/mcpManagement.test.ts +38 -0
  137. package/src/lib/__tests__/path-paste.test.ts +144 -0
  138. package/src/lib/__tests__/path.test.ts +300 -0
  139. package/src/lib/__tests__/queries.test.ts +39 -0
  140. package/src/lib/__tests__/standaloneMcpService.test.ts +71 -0
  141. package/src/lib/__tests__/text-buffer.test.ts +328 -0
  142. package/src/lib/__tests__/text-utils.test.ts +32 -0
  143. package/src/lib/__tests__/timing.test.ts +78 -0
  144. package/src/lib/__tests__/utils.test.ts +238 -0
  145. package/src/lib/__tests__/vim-buffer-actions.test.ts +154 -0
  146. package/src/lib/ansi.ts +150 -0
  147. package/src/lib/cli-push-server.ts +112 -0
  148. package/src/lib/cli.ts +44 -0
  149. package/src/lib/clipboard.ts +226 -0
  150. package/src/lib/command-utils.ts +93 -0
  151. package/src/lib/commands.ts +270 -0
  152. package/src/lib/constants.ts +3 -0
  153. package/src/lib/extension-connection.ts +181 -0
  154. package/src/lib/focusables.ts +7 -0
  155. package/src/lib/fs.ts +533 -0
  156. package/src/lib/markdown/code-block.tsx +63 -0
  157. package/src/lib/markdown/index.ts +4 -0
  158. package/src/lib/markdown/link.tsx +19 -0
  159. package/src/lib/markdown/markdown.tsx +372 -0
  160. package/src/lib/markdown/types.ts +15 -0
  161. package/src/lib/mcpCommandHandler.ts +121 -0
  162. package/src/lib/mcpManagement.ts +44 -0
  163. package/src/lib/path-paste.ts +185 -0
  164. package/src/lib/path.ts +179 -0
  165. package/src/lib/queries.ts +15 -0
  166. package/src/lib/standaloneMcpService.ts +688 -0
  167. package/src/lib/status-utils.ts +237 -0
  168. package/src/lib/test-utils.tsx +72 -0
  169. package/src/lib/text-buffer.ts +2415 -0
  170. package/src/lib/text-utils.ts +272 -0
  171. package/src/lib/timing.ts +63 -0
  172. package/src/lib/types.ts +295 -0
  173. package/src/lib/utils.ts +182 -0
  174. package/src/lib/vim-buffer-actions.ts +732 -0
  175. package/src/providers/agent.tsx +1075 -0
  176. package/src/providers/api-client.tsx +43 -0
  177. package/src/services/logger.ts +85 -0
  178. package/src/terminal/detection.ts +187 -0
  179. package/src/terminal/exit.ts +279 -0
  180. package/src/terminal/notification.ts +83 -0
  181. package/src/terminal/progress.ts +201 -0
  182. package/src/terminal/setup.ts +797 -0
  183. package/src/terminal/suspend.ts +58 -0
  184. package/src/terminal/types.ts +51 -0
  185. package/src/theme/context.tsx +57 -0
  186. package/src/theme/index.ts +4 -0
  187. package/src/theme/themed.tsx +35 -0
  188. package/src/theme/themes.json +546 -0
  189. package/src/theme/types.ts +110 -0
  190. package/src/tools/types.ts +59 -0
  191. package/src/tools/utils/__tests__/zod-coercion.test.ts +33 -0
  192. package/src/tools/utils/tool-ui-components.tsx +631 -0
  193. package/src/tools/utils/zod-coercion.ts +35 -0
  194. package/tsconfig.json +11 -0
  195. package/tsconfig.node.json +29 -0
  196. package/tsconfig.test.json +27 -0
  197. package/tsdown.config.ts +17 -0
  198. package/vitest.config.ts +76 -0
  199. package/README.md +0 -28
  200. package/dist/index.js +0 -26
@@ -0,0 +1,631 @@
1
+ import { View, Text } from "@codellm/jar";
2
+ import { renderMermaidAscii } from "beautiful-mermaid";
3
+ import { highlight, supportsLanguage } from "cli-highlight";
4
+ import { structuredPatch } from "diff";
5
+ import { extname } from "path";
6
+ import React, { useEffect, useState, useMemo, createContext, use } from "react";
7
+
8
+ import type { ToolStatus } from "../types.js";
9
+
10
+ import { useTheme } from "../../theme/index.js";
11
+
12
+ /**
13
+ * Context for the currently pending tool call ID (awaiting permission).
14
+ * Provided at top level; consumed by ToolHeader to suppress blinking.
15
+ */
16
+ export const PendingToolCallIdContext = createContext<string | null>(null);
17
+
18
+ /**
19
+ * Diff line type for condensed diff preview
20
+ */
21
+ export interface CondensedDiffLine {
22
+ type: "added" | "removed" | "unchanged";
23
+ content: string;
24
+ lineNumber: number;
25
+ }
26
+
27
+ /**
28
+ * Format bytes for display
29
+ */
30
+ export function formatBytes(bytes: number): string {
31
+ if (bytes < 1024) {
32
+ return `${bytes}B`;
33
+ }
34
+ if (bytes < 1024 * 1024) {
35
+ return `${(bytes / 1024).toFixed(1)}KB`;
36
+ }
37
+ return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
38
+ }
39
+
40
+ /**
41
+ * Format duration in milliseconds for display
42
+ */
43
+ export function formatDuration(ms: number): string {
44
+ if (ms < 1000) {
45
+ return `${ms}ms`;
46
+ }
47
+ return `${(ms / 1000).toFixed(1)}s`;
48
+ }
49
+
50
+ /**
51
+ * Truncate long file paths for display
52
+ */
53
+ export function truncatePath(path: string, maxLen: number = 50): string {
54
+ if (path.length <= maxLen) {
55
+ return path;
56
+ }
57
+ const parts = path.split("/");
58
+ if (parts.length === 1) {
59
+ return path.length > maxLen ? `...${path.slice(-maxLen + 3)}` : path;
60
+ }
61
+ const filename = parts[parts.length - 1];
62
+ const remaining = maxLen - filename.length - 3;
63
+ if (remaining < 0) {
64
+ return `...${filename.slice(-maxLen + 3)}`;
65
+ }
66
+ const prefix = parts.slice(0, -1).join("/");
67
+ if (prefix.length <= remaining) {
68
+ return path;
69
+ }
70
+ return `...${prefix.slice(-remaining)}/${filename}`;
71
+ }
72
+
73
+ /**
74
+ * Get color for tool status
75
+ */
76
+ export function getStatusColor(status: ToolStatus): string {
77
+ switch (status) {
78
+ case "success":
79
+ return "green";
80
+ case "error":
81
+ return "red";
82
+ case "rejected":
83
+ case "interrupted":
84
+ return "yellow";
85
+ case "pending":
86
+ case "executing":
87
+ default:
88
+ return "white";
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Blinking dot animation for pending status - grey fade effect
94
+ */
95
+ export function BlinkingDot() {
96
+ const [visible, setVisible] = useState(true);
97
+
98
+ useEffect(() => {
99
+ const interval = setInterval(() => {
100
+ setVisible((prev) => !prev);
101
+ }, 500);
102
+
103
+ return () => clearInterval(interval);
104
+ }, []);
105
+
106
+ return (
107
+ <Text color="gray" dimColor={!visible}>
108
+
109
+ </Text>
110
+ );
111
+ }
112
+
113
+ /**
114
+ * Tool header component - displays tool name, params, and status
115
+ */
116
+ export interface ToolHeaderProps {
117
+ name: string;
118
+ params?: string;
119
+ status?: ToolStatus;
120
+ showSpinner?: boolean;
121
+ /** When true, shows a static yellow ◌ instead of blinking dot (permission wait state) */
122
+ isAwaitingPermission?: boolean;
123
+ /** Tool call ID — used to check against PendingToolCallIdContext for auto awaiting-permission detection */
124
+ toolCallId?: string;
125
+ }
126
+
127
+ export function ToolHeader({
128
+ name,
129
+ params,
130
+ status = "pending",
131
+ showSpinner,
132
+ isAwaitingPermission,
133
+ toolCallId,
134
+ }: ToolHeaderProps) {
135
+ const color = getStatusColor(status);
136
+ const isPending = status === "pending" || status === "executing";
137
+
138
+ // Auto-detect awaiting permission via context:
139
+ // When a tool call ID matches the pending permission, or when showSpinner is true
140
+ // and there's any pending permission (only one at a time), show static indicator.
141
+ const pendingToolCallId = use(PendingToolCallIdContext);
142
+ const awaiting =
143
+ isAwaitingPermission ??
144
+ (pendingToolCallId != null &&
145
+ ((toolCallId != null && toolCallId === pendingToolCallId) ||
146
+ (toolCallId == null && showSpinner)));
147
+
148
+ let indicator: React.ReactNode;
149
+ if (awaiting) {
150
+ indicator = <Text color="yellow">◌</Text>;
151
+ } else if (showSpinner) {
152
+ indicator = <BlinkingDot />;
153
+ } else {
154
+ indicator = <Text color={color}>⏺</Text>;
155
+ }
156
+
157
+ return (
158
+ <View flexDirection="row" alignItems="center" gap={1}>
159
+ {indicator}
160
+ <Text color="cyan">{name}</Text>
161
+ {params && <Text dimColor>({params})</Text>}
162
+ {isPending && <Text dimColor>...</Text>}
163
+ </View>
164
+ );
165
+ }
166
+
167
+ /**
168
+ * Tool result component - displays tool output with indentation
169
+ */
170
+ export interface ToolResultProps {
171
+ children: React.ReactNode;
172
+ color?: string;
173
+ indent?: number;
174
+ }
175
+
176
+ export function ToolResult({ children, color = "gray", indent = 2 }: ToolResultProps) {
177
+ return (
178
+ <View marginLeft={indent} flexDirection="row" alignItems="flex-start" gap={1}>
179
+ <Text color={color} dimColor>
180
+
181
+ </Text>
182
+ <Text color={color} dimColor>
183
+ {children}
184
+ </Text>
185
+ </View>
186
+ );
187
+ }
188
+
189
+ /**
190
+ * Wrapper for preview content areas (diffs, code blocks, terminal output).
191
+ * Provides consistent indentation below the result line.
192
+ */
193
+ export interface PreviewContentProps {
194
+ children: React.ReactNode;
195
+ indent?: number;
196
+ }
197
+
198
+ export function PreviewContent({ children, indent = 4 }: PreviewContentProps) {
199
+ return (
200
+ <View flexDirection="column" paddingLeft={indent}>
201
+ {children}
202
+ </View>
203
+ );
204
+ }
205
+
206
+ /**
207
+ * Parse tool result from JSON string
208
+ */
209
+ export function parseToolResult(content: string): any {
210
+ try {
211
+ const parsed = JSON.parse(content);
212
+ if (typeof parsed !== "object" || parsed === null) {
213
+ return { output: content, type: "text" };
214
+ }
215
+ return parsed;
216
+ } catch {
217
+ const jsonMatch = content.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
218
+ if (jsonMatch && jsonMatch[1]) {
219
+ try {
220
+ const parsed = JSON.parse(jsonMatch[1].trim());
221
+ if (typeof parsed !== "object" || parsed === null) {
222
+ return { output: jsonMatch[1].trim(), type: "text" };
223
+ }
224
+ return parsed;
225
+ } catch {
226
+ return { output: jsonMatch[1].trim(), type: "text" };
227
+ }
228
+ }
229
+ return { output: content, type: "text" };
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Compute expected final content after edit operation
235
+ * Used for diff preview
236
+ */
237
+ export function computeExpectedFinalContentForDiff(
238
+ currentContent: string,
239
+ codeEdit: string,
240
+ overwriteFile: boolean,
241
+ startLine?: number,
242
+ endLine?: number,
243
+ instructions?: string,
244
+ ): string {
245
+ if (overwriteFile) {
246
+ return codeEdit;
247
+ }
248
+
249
+ if (startLine !== undefined && endLine !== undefined) {
250
+ const lines = currentContent.split("\n");
251
+ const totalLines = lines.length;
252
+ const validStartLine = Math.max(1, Math.min(startLine, totalLines));
253
+ const validEndLine = Math.max(validStartLine, Math.min(endLine, totalLines));
254
+
255
+ const beforeLines = lines.slice(0, validStartLine - 1);
256
+ const afterLines = lines.slice(validEndLine);
257
+ const newLines = codeEdit.split("\n");
258
+
259
+ return [...beforeLines, ...newLines, ...afterLines].join("\n");
260
+ }
261
+
262
+ if (instructions) {
263
+ return currentContent + "\n" + codeEdit;
264
+ }
265
+
266
+ const codeEditLines = codeEdit.split("\n");
267
+ const currentLines = currentContent.split("\n");
268
+
269
+ if (codeEditLines.length >= currentLines.length * 0.8) {
270
+ return codeEdit;
271
+ }
272
+
273
+ if (currentContent.includes(codeEdit)) {
274
+ return currentContent;
275
+ }
276
+
277
+ return currentContent + "\n" + codeEdit;
278
+ }
279
+
280
+ /**
281
+ * Wrap long lines for terminal display
282
+ */
283
+ export function wrapLine(content: string, maxWidth: number, lineNumberWidth: number): string[] {
284
+ if (!content) return [""];
285
+
286
+ // Account for line number, gutter (` - ` or ` + `), and some margin
287
+ const availableWidth = maxWidth - lineNumberWidth - 4 - 2; // 4 for gutter, 2 for margins
288
+
289
+ if (content.length <= availableWidth) {
290
+ return [content];
291
+ }
292
+
293
+ const wrapped: string[] = [];
294
+ let remaining = content;
295
+
296
+ while (remaining.length > 0) {
297
+ if (remaining.length <= availableWidth) {
298
+ wrapped.push(remaining);
299
+ break;
300
+ }
301
+
302
+ // Try to break at a space near the limit
303
+ let breakPoint = remaining.lastIndexOf(" ", availableWidth);
304
+ if (breakPoint === -1 || breakPoint < availableWidth * 0.5) {
305
+ breakPoint = availableWidth;
306
+ }
307
+
308
+ wrapped.push(remaining.slice(0, breakPoint));
309
+ remaining = remaining.slice(breakPoint).trimStart();
310
+ }
311
+
312
+ return wrapped;
313
+ }
314
+
315
+ /**
316
+ * Get language from file extension for syntax highlighting
317
+ */
318
+ function getLanguageFromPath(filePath: string): string | undefined {
319
+ const ext = extname(filePath).toLowerCase().slice(1);
320
+ const langMap: Record<string, string> = {
321
+ ts: "typescript",
322
+ tsx: "typescript",
323
+ js: "javascript",
324
+ jsx: "javascript",
325
+ py: "python",
326
+ rb: "ruby",
327
+ rs: "rust",
328
+ go: "go",
329
+ java: "java",
330
+ c: "c",
331
+ cpp: "cpp",
332
+ h: "c",
333
+ hpp: "cpp",
334
+ cs: "csharp",
335
+ php: "php",
336
+ swift: "swift",
337
+ kt: "kotlin",
338
+ scala: "scala",
339
+ sh: "bash",
340
+ bash: "bash",
341
+ zsh: "bash",
342
+ json: "json",
343
+ yaml: "yaml",
344
+ yml: "yaml",
345
+ xml: "xml",
346
+ html: "html",
347
+ css: "css",
348
+ scss: "scss",
349
+ less: "less",
350
+ sql: "sql",
351
+ md: "markdown",
352
+ markdown: "markdown",
353
+ txt: "plaintext",
354
+ mmd: "mermaid",
355
+ mermaid: "mermaid",
356
+ };
357
+ return langMap[ext];
358
+ }
359
+
360
+ /**
361
+ * Try to render mermaid diagram as ASCII art
362
+ * Returns null if parsing fails
363
+ */
364
+ function tryRenderMermaid(content: string): string | null {
365
+ try {
366
+ return renderMermaidAscii(content);
367
+ } catch {
368
+ return null;
369
+ }
370
+ }
371
+
372
+ /**
373
+ * Code preview component for new files
374
+ * Shows syntax-highlighted code block with line numbers
375
+ */
376
+ export interface CodePreviewProps {
377
+ content: string;
378
+ filePath?: string;
379
+ /** First line number to display (1-based). Defaults to 1. */
380
+ startLine?: number;
381
+ maxLines?: number;
382
+ dimmed?: boolean;
383
+ }
384
+
385
+ export function CodePreview({
386
+ content,
387
+ filePath,
388
+ startLine = 1,
389
+ maxLines = 4,
390
+ dimmed = false,
391
+ }: CodePreviewProps) {
392
+ const { displayContent, totalLines, hasMore, displayLineCount } = useMemo(() => {
393
+ const allLines = content.split("\n");
394
+ const total = allLines.length;
395
+ const lines = allLines.slice(0, maxLines);
396
+ return {
397
+ displayContent: lines.join("\n"),
398
+ displayLineCount: lines.length,
399
+ totalLines: total,
400
+ hasMore: total > maxLines,
401
+ };
402
+ }, [content, maxLines]);
403
+
404
+ const highlightedContent = useMemo(() => {
405
+ if (!displayContent) return displayContent;
406
+
407
+ const language = filePath ? getLanguageFromPath(filePath) : undefined;
408
+
409
+ // Try to render mermaid diagrams as ASCII art
410
+ if (language === "mermaid") {
411
+ const mermaidOutput = tryRenderMermaid(content);
412
+ if (mermaidOutput !== null) {
413
+ return mermaidOutput;
414
+ }
415
+ // If mermaid parsing fails, fall through to regular rendering
416
+ }
417
+
418
+ if (language && supportsLanguage(language)) {
419
+ try {
420
+ return highlight(displayContent, { language });
421
+ } catch {
422
+ // Fallback to plain text
423
+ }
424
+ }
425
+ return displayContent;
426
+ }, [displayContent, filePath, content]);
427
+
428
+ if (!displayContent) {
429
+ return null;
430
+ }
431
+
432
+ const lastLineNum = startLine + totalLines - 1;
433
+ const maxLineNumWidth = lastLineNum.toString().length;
434
+ const lines = highlightedContent.split("\n");
435
+
436
+ return (
437
+ <View flexDirection="column">
438
+ {lines.map((line, idx) => {
439
+ const lineNum = startLine + idx;
440
+ const paddedNum = String(lineNum).padStart(maxLineNumWidth, " ");
441
+ return (
442
+ <Text key={idx} dimColor={dimmed}>
443
+ <Text dimColor>{paddedNum} │ </Text>
444
+ {line}
445
+ </Text>
446
+ );
447
+ })}
448
+ {hasMore && <Text dimColor> ... {totalLines - displayLineCount} more lines</Text>}
449
+ </View>
450
+ );
451
+ }
452
+
453
+ /**
454
+ * Highlight full file content and return per-line highlighted strings.
455
+ * Highlights the whole file (not per-line) to preserve multi-line syntax context.
456
+ * Returns plain split lines if language is unsupported or highlight throws.
457
+ */
458
+ export function highlightLines(content: string, filePath: string): string[] {
459
+ const language = getLanguageFromPath(filePath);
460
+ if (language && language !== "mermaid" && supportsLanguage(language)) {
461
+ try {
462
+ return highlight(content, { language }).split("\n");
463
+ } catch {}
464
+ }
465
+ return content.split("\n");
466
+ }
467
+
468
+ /**
469
+ * Condensed diff preview component
470
+ * Shows a limited number of changed lines with context
471
+ */
472
+ export interface CondensedDiffPreviewProps {
473
+ originalContent: string;
474
+ newContent: string;
475
+ filePath?: string;
476
+ maxLines?: number;
477
+ dimmed?: boolean;
478
+ }
479
+
480
+ export function CondensedDiffPreview({
481
+ originalContent,
482
+ newContent,
483
+ filePath,
484
+ maxLines = 4,
485
+ dimmed = false,
486
+ }: CondensedDiffPreviewProps) {
487
+ const { colors } = useTheme();
488
+
489
+ const { diffLines, addedCount, removedCount, highlightedOrigLines, highlightedNewLines } =
490
+ useMemo(() => {
491
+ const hlOrig = filePath ? highlightLines(originalContent, filePath) : null;
492
+ const hlNew = filePath ? highlightLines(newContent, filePath) : null;
493
+
494
+ const patch = structuredPatch(
495
+ "file",
496
+ "file",
497
+ originalContent,
498
+ newContent,
499
+ undefined,
500
+ undefined,
501
+ { context: 1 },
502
+ );
503
+ const lines: CondensedDiffLine[] = [];
504
+ let added = 0;
505
+ let removed = 0;
506
+
507
+ for (const hunk of patch.hunks) {
508
+ let oldLineNum = hunk.oldStart;
509
+ let newLineNum = hunk.newStart;
510
+
511
+ for (const line of hunk.lines) {
512
+ if (lines.length >= maxLines) break;
513
+
514
+ const prefix = line[0];
515
+ const content = line.slice(1);
516
+
517
+ if (prefix === "+") {
518
+ lines.push({ type: "added", content, lineNumber: newLineNum++ });
519
+ added++;
520
+ } else if (prefix === "-") {
521
+ lines.push({ type: "removed", content, lineNumber: oldLineNum++ });
522
+ removed++;
523
+ } else {
524
+ lines.push({ type: "unchanged", content, lineNumber: oldLineNum });
525
+ oldLineNum++;
526
+ newLineNum++;
527
+ }
528
+ }
529
+ if (lines.length >= maxLines) break;
530
+ }
531
+
532
+ return {
533
+ diffLines: lines.slice(0, maxLines),
534
+ addedCount: added,
535
+ removedCount: removed,
536
+ highlightedOrigLines: hlOrig,
537
+ highlightedNewLines: hlNew,
538
+ };
539
+ }, [originalContent, newContent, filePath, maxLines]);
540
+
541
+ if (diffLines.length === 0) {
542
+ return null;
543
+ }
544
+
545
+ const maxLineNumWidth = Math.max(...diffLines.map((l) => l.lineNumber)).toString().length;
546
+
547
+ // Build summary text
548
+ const summaryParts = [];
549
+ if (addedCount > 0) summaryParts.push(`+${addedCount}`);
550
+ if (removedCount > 0) summaryParts.push(`-${removedCount}`);
551
+ const summary = summaryParts.join(" ");
552
+
553
+ return (
554
+ <View flexDirection="column" paddingLeft={1}>
555
+ {summary && (
556
+ <View marginBottom={0}>
557
+ <Text dimColor>{summary} lines</Text>
558
+ </View>
559
+ )}
560
+ {diffLines.map((line, idx) => {
561
+ const paddedNum = String(line.lineNumber).padStart(maxLineNumWidth, " ");
562
+ // Pick syntax-highlighted content when available
563
+ const hlContent =
564
+ line.type === "removed"
565
+ ? (highlightedOrigLines?.[line.lineNumber - 1] ?? line.content)
566
+ : line.type === "added"
567
+ ? (highlightedNewLines?.[line.lineNumber - 1] ?? line.content)
568
+ : (highlightedOrigLines?.[line.lineNumber - 1] ?? line.content);
569
+
570
+ if (line.type === "removed") {
571
+ return (
572
+ <View key={idx} flexDirection="row" backgroundColor={colors.diffRemoved}>
573
+ <Text
574
+ backgroundColor={colors.diffRemoved}
575
+ color={colors.diffRemovedText}
576
+ dimColor={dimmed}
577
+ >
578
+ {paddedNum} -{" "}
579
+ </Text>
580
+ <View flexShrink={1}>
581
+ <Text
582
+ backgroundColor={colors.diffRemoved}
583
+ color={colors.diffRemovedText}
584
+ dimColor={dimmed}
585
+ wrap="wrap"
586
+ >
587
+ {hlContent}
588
+ </Text>
589
+ </View>
590
+ </View>
591
+ );
592
+ }
593
+
594
+ if (line.type === "added") {
595
+ return (
596
+ <View key={idx} flexDirection="row" backgroundColor={colors.diffAdded}>
597
+ <Text
598
+ backgroundColor={colors.diffAdded}
599
+ color={colors.diffAddedText}
600
+ dimColor={dimmed}
601
+ >
602
+ {paddedNum} +{" "}
603
+ </Text>
604
+ <View flexShrink={1}>
605
+ <Text
606
+ backgroundColor={colors.diffAdded}
607
+ color={colors.diffAddedText}
608
+ dimColor={dimmed}
609
+ wrap="wrap"
610
+ >
611
+ {hlContent}
612
+ </Text>
613
+ </View>
614
+ </View>
615
+ );
616
+ }
617
+
618
+ return (
619
+ <View key={idx} flexDirection="row">
620
+ <Text dimColor>{paddedNum} </Text>
621
+ <View flexShrink={1}>
622
+ <Text dimColor wrap="wrap">
623
+ {hlContent}
624
+ </Text>
625
+ </View>
626
+ </View>
627
+ );
628
+ })}
629
+ </View>
630
+ );
631
+ }
@@ -0,0 +1,35 @@
1
+ import { z } from "zod";
2
+
3
+ function normalizeNumberInput(value: unknown): unknown {
4
+ if (typeof value !== "string") {
5
+ return value;
6
+ }
7
+
8
+ const trimmed = value.trim();
9
+ if (!trimmed) {
10
+ return Number.NaN;
11
+ }
12
+
13
+ return Number(trimmed);
14
+ }
15
+
16
+ function normalizeBooleanInput(value: unknown): unknown {
17
+ if (typeof value !== "string") {
18
+ return value;
19
+ }
20
+
21
+ const normalized = value.trim().toLowerCase();
22
+ if (["true", "1", "yes", "y"].includes(normalized)) {
23
+ return true;
24
+ }
25
+ if (["false", "0", "no", "n"].includes(normalized)) {
26
+ return false;
27
+ }
28
+
29
+ return value;
30
+ }
31
+
32
+ export const coerceNumber = z.preprocess(normalizeNumberInput, z.number());
33
+ export const coerceOptionalNumber = z.preprocess(normalizeNumberInput, z.number().optional());
34
+ export const coerceBoolean = z.preprocess(normalizeBooleanInput, z.boolean());
35
+ export const coerceOptionalBoolean = z.preprocess(normalizeBooleanInput, z.boolean().optional());
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ {
5
+ "path": "./tsconfig.node.json"
6
+ },
7
+ {
8
+ "path": "./tsconfig.test.json"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "$schema": "https://www.schemastore.org/tsconfig",
3
+ "extends": ["@codellm/configs/ts/node.json", "@codellm/configs/ts/relaxed.json"],
4
+ "compilerOptions": {
5
+ "moduleDetection": "auto",
6
+ "outDir": "./dist",
7
+ "noEmit": true,
8
+ "allowImportingTsExtensions": true,
9
+ "incremental": true,
10
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
11
+ "jsx": "react-jsx",
12
+ "types": ["node"],
13
+ "paths": {
14
+ "@/package.json": ["./package.json"]
15
+ }
16
+ },
17
+ "include": ["src", "plugins", "tsdown.config.ts"],
18
+ "exclude": [
19
+ "src/**/*.test.ts",
20
+ "src/**/*.e2e.test.ts",
21
+ "src/**/*.test.tsx",
22
+ "src/**/*.e2e.test.tsx",
23
+ "src/**/*.spec.ts",
24
+ "src/**/*.e2e.spec.ts",
25
+ "src/**/*.spec.tsx",
26
+ "src/**/*.e2e.spec.tsx",
27
+ "src/__e2e__/**/*"
28
+ ]
29
+ }