@abacus-ai/cli 2.0.0-canary.0 → 2.0.0-canary.2

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 (198) hide show
  1. package/dist/index.mjs +807 -561
  2. package/package.json +4 -1
  3. package/.oxlintrc.json +0 -8
  4. package/resources/abacus.ico +0 -0
  5. package/resources/entitlements.plist +0 -9
  6. package/src/__e2e__/README.md +0 -196
  7. package/src/__e2e__/agent-interactions.e2e.test.tsx +0 -61
  8. package/src/__e2e__/cli-commands.e2e.test.tsx +0 -77
  9. package/src/__e2e__/conversation-throttle.e2e.test.ts +0 -453
  10. package/src/__e2e__/conversation.e2e.test.tsx +0 -56
  11. package/src/__e2e__/diff-preview.e2e.test.tsx +0 -3399
  12. package/src/__e2e__/file-creation.e2e.test.tsx +0 -149
  13. package/src/__e2e__/helpers/test-helpers.ts +0 -450
  14. package/src/__e2e__/keyboard-navigation.e2e.test.tsx +0 -34
  15. package/src/__e2e__/llm-models.e2e.test.ts +0 -402
  16. package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +0 -71
  17. package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +0 -167
  18. package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +0 -185
  19. package/src/__e2e__/repl.e2e.test.tsx +0 -78
  20. package/src/__e2e__/shell-compatibility.e2e.test.tsx +0 -76
  21. package/src/__e2e__/theme-mcp.e2e.test.tsx +0 -98
  22. package/src/__e2e__/tool-permissions.e2e.test.tsx +0 -66
  23. package/src/args.ts +0 -22
  24. package/src/components/__tests__/react-compiler.test.tsx +0 -78
  25. package/src/components/__tests__/status-indicator.test.tsx +0 -403
  26. package/src/components/composer/__tests__/bash-runner.test.tsx +0 -263
  27. package/src/components/composer/agent-mode-indicator.tsx +0 -63
  28. package/src/components/composer/bash-runner.tsx +0 -54
  29. package/src/components/composer/commands/default-commands.tsx +0 -615
  30. package/src/components/composer/commands/handler.tsx +0 -59
  31. package/src/components/composer/commands/picker.tsx +0 -273
  32. package/src/components/composer/commands/registry.ts +0 -233
  33. package/src/components/composer/commands/types.ts +0 -33
  34. package/src/components/composer/context.tsx +0 -88
  35. package/src/components/composer/file-mention-picker.tsx +0 -83
  36. package/src/components/composer/help.tsx +0 -44
  37. package/src/components/composer/index.tsx +0 -1006
  38. package/src/components/composer/mentions.ts +0 -57
  39. package/src/components/composer/message-queue.tsx +0 -70
  40. package/src/components/composer/mode-panel.tsx +0 -35
  41. package/src/components/composer/modes/__tests__/bash-handler.test.tsx +0 -755
  42. package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +0 -1108
  43. package/src/components/composer/modes/bash-handler.tsx +0 -132
  44. package/src/components/composer/modes/bash-renderer.tsx +0 -175
  45. package/src/components/composer/modes/default-handlers.tsx +0 -33
  46. package/src/components/composer/modes/index.ts +0 -41
  47. package/src/components/composer/modes/types.ts +0 -21
  48. package/src/components/composer/persistent-shell.ts +0 -283
  49. package/src/components/composer/process.ts +0 -65
  50. package/src/components/composer/types.ts +0 -9
  51. package/src/components/composer/use-mention-search.ts +0 -68
  52. package/src/components/error-boundry.tsx +0 -60
  53. package/src/components/exit-message.tsx +0 -29
  54. package/src/components/expanded-view.tsx +0 -74
  55. package/src/components/file-completion.tsx +0 -127
  56. package/src/components/header.tsx +0 -47
  57. package/src/components/logo.tsx +0 -37
  58. package/src/components/segments.tsx +0 -356
  59. package/src/components/status-indicator.tsx +0 -306
  60. package/src/components/tool-group-summary.tsx +0 -263
  61. package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +0 -312
  62. package/src/components/tool-permissions/diff-preview.tsx +0 -355
  63. package/src/components/tool-permissions/index.ts +0 -5
  64. package/src/components/tool-permissions/permission-options.tsx +0 -375
  65. package/src/components/tool-permissions/permission-preview-header.tsx +0 -57
  66. package/src/components/tool-permissions/tool-permission-ui.tsx +0 -398
  67. package/src/components/tools/agent/ask-user-question.tsx +0 -101
  68. package/src/components/tools/agent/enter-plan-mode.tsx +0 -49
  69. package/src/components/tools/agent/exit-plan-mode.tsx +0 -75
  70. package/src/components/tools/agent/handoff-to-main.tsx +0 -27
  71. package/src/components/tools/agent/subagent.tsx +0 -37
  72. package/src/components/tools/agent/todo-write.tsx +0 -104
  73. package/src/components/tools/browser/close-tab.tsx +0 -58
  74. package/src/components/tools/browser/computer.tsx +0 -70
  75. package/src/components/tools/browser/get-interactive-elements.tsx +0 -54
  76. package/src/components/tools/browser/get-tab-content.tsx +0 -51
  77. package/src/components/tools/browser/navigate-to.tsx +0 -59
  78. package/src/components/tools/browser/new-tab.tsx +0 -60
  79. package/src/components/tools/browser/perform-action.tsx +0 -63
  80. package/src/components/tools/browser/refresh-tab.tsx +0 -43
  81. package/src/components/tools/browser/switch-tab.tsx +0 -58
  82. package/src/components/tools/filesystem/delete-file.tsx +0 -104
  83. package/src/components/tools/filesystem/edit.tsx +0 -220
  84. package/src/components/tools/filesystem/list-dir.tsx +0 -78
  85. package/src/components/tools/filesystem/read-file.tsx +0 -180
  86. package/src/components/tools/filesystem/upload-image.tsx +0 -76
  87. package/src/components/tools/ide/ide-diagnostics.tsx +0 -62
  88. package/src/components/tools/index.ts +0 -91
  89. package/src/components/tools/mcp/mcp-tool.tsx +0 -158
  90. package/src/components/tools/search/fetch-url.tsx +0 -73
  91. package/src/components/tools/search/file-search.tsx +0 -78
  92. package/src/components/tools/search/grep.tsx +0 -90
  93. package/src/components/tools/search/semantic-search.tsx +0 -66
  94. package/src/components/tools/search/web-search.tsx +0 -71
  95. package/src/components/tools/shared/index.tsx +0 -48
  96. package/src/components/tools/shared/zod-coercion.ts +0 -35
  97. package/src/components/tools/terminal/bash-tool-output.tsx +0 -174
  98. package/src/components/tools/terminal/get-terminal-output.tsx +0 -85
  99. package/src/components/tools/terminal/run-in-terminal.tsx +0 -106
  100. package/src/components/tools/types.ts +0 -16
  101. package/src/components/tools.tsx +0 -66
  102. package/src/components/ui/__tests__/divider.test.tsx +0 -61
  103. package/src/components/ui/__tests__/gradient.test.tsx +0 -125
  104. package/src/components/ui/__tests__/input.test.tsx +0 -166
  105. package/src/components/ui/__tests__/select.test.tsx +0 -273
  106. package/src/components/ui/__tests__/shimmer.test.tsx +0 -99
  107. package/src/components/ui/blinking-indicator.tsx +0 -25
  108. package/src/components/ui/divider.tsx +0 -162
  109. package/src/components/ui/gradient.tsx +0 -56
  110. package/src/components/ui/input.tsx +0 -228
  111. package/src/components/ui/select.tsx +0 -151
  112. package/src/components/ui/shimmer.tsx +0 -84
  113. package/src/context/agent-mode.tsx +0 -95
  114. package/src/context/extension-file.tsx +0 -136
  115. package/src/context/network-activity.tsx +0 -45
  116. package/src/context/notification.tsx +0 -62
  117. package/src/context/shell-size.tsx +0 -49
  118. package/src/context/shell-title.tsx +0 -38
  119. package/src/entrypoints/print-mode.ts +0 -312
  120. package/src/entrypoints/repl.tsx +0 -401
  121. package/src/hooks/use-agent.ts +0 -15
  122. package/src/hooks/use-api-client.ts +0 -1
  123. package/src/hooks/use-available-height.ts +0 -8
  124. package/src/hooks/use-cleanup.ts +0 -29
  125. package/src/hooks/use-interrupt-manager.ts +0 -242
  126. package/src/hooks/use-models.ts +0 -22
  127. package/src/index.ts +0 -217
  128. package/src/lib/__tests__/ansi.test.ts +0 -255
  129. package/src/lib/__tests__/cli.test.ts +0 -122
  130. package/src/lib/__tests__/commands.test.ts +0 -325
  131. package/src/lib/__tests__/constants.test.ts +0 -15
  132. package/src/lib/__tests__/focusables.test.ts +0 -25
  133. package/src/lib/__tests__/fs.test.ts +0 -231
  134. package/src/lib/__tests__/markdown.test.tsx +0 -348
  135. package/src/lib/__tests__/mcpCommandHandler.test.ts +0 -173
  136. package/src/lib/__tests__/mcpManagement.test.ts +0 -38
  137. package/src/lib/__tests__/path-paste.test.ts +0 -144
  138. package/src/lib/__tests__/path.test.ts +0 -300
  139. package/src/lib/__tests__/queries.test.ts +0 -39
  140. package/src/lib/__tests__/standaloneMcpService.test.ts +0 -71
  141. package/src/lib/__tests__/text-buffer.test.ts +0 -328
  142. package/src/lib/__tests__/text-utils.test.ts +0 -32
  143. package/src/lib/__tests__/timing.test.ts +0 -78
  144. package/src/lib/__tests__/utils.test.ts +0 -238
  145. package/src/lib/__tests__/vim-buffer-actions.test.ts +0 -154
  146. package/src/lib/ansi.ts +0 -150
  147. package/src/lib/cli-push-server.ts +0 -112
  148. package/src/lib/cli.ts +0 -44
  149. package/src/lib/clipboard.ts +0 -226
  150. package/src/lib/command-utils.ts +0 -93
  151. package/src/lib/commands.ts +0 -270
  152. package/src/lib/constants.ts +0 -3
  153. package/src/lib/extension-connection.ts +0 -181
  154. package/src/lib/focusables.ts +0 -7
  155. package/src/lib/fs.ts +0 -533
  156. package/src/lib/markdown/code-block.tsx +0 -63
  157. package/src/lib/markdown/index.ts +0 -4
  158. package/src/lib/markdown/link.tsx +0 -19
  159. package/src/lib/markdown/markdown.tsx +0 -372
  160. package/src/lib/markdown/types.ts +0 -15
  161. package/src/lib/mcpCommandHandler.ts +0 -121
  162. package/src/lib/mcpManagement.ts +0 -44
  163. package/src/lib/path-paste.ts +0 -185
  164. package/src/lib/path.ts +0 -179
  165. package/src/lib/queries.ts +0 -15
  166. package/src/lib/standaloneMcpService.ts +0 -688
  167. package/src/lib/status-utils.ts +0 -237
  168. package/src/lib/test-utils.tsx +0 -72
  169. package/src/lib/text-buffer.ts +0 -2415
  170. package/src/lib/text-utils.ts +0 -272
  171. package/src/lib/timing.ts +0 -63
  172. package/src/lib/types.ts +0 -295
  173. package/src/lib/utils.ts +0 -182
  174. package/src/lib/vim-buffer-actions.ts +0 -732
  175. package/src/providers/agent.tsx +0 -1075
  176. package/src/providers/api-client.tsx +0 -43
  177. package/src/services/logger.ts +0 -85
  178. package/src/terminal/detection.ts +0 -187
  179. package/src/terminal/exit.ts +0 -279
  180. package/src/terminal/notification.ts +0 -83
  181. package/src/terminal/progress.ts +0 -201
  182. package/src/terminal/setup.ts +0 -797
  183. package/src/terminal/suspend.ts +0 -58
  184. package/src/terminal/types.ts +0 -51
  185. package/src/theme/context.tsx +0 -57
  186. package/src/theme/index.ts +0 -4
  187. package/src/theme/themed.tsx +0 -35
  188. package/src/theme/themes.json +0 -546
  189. package/src/theme/types.ts +0 -110
  190. package/src/tools/types.ts +0 -59
  191. package/src/tools/utils/__tests__/zod-coercion.test.ts +0 -33
  192. package/src/tools/utils/tool-ui-components.tsx +0 -631
  193. package/src/tools/utils/zod-coercion.ts +0 -35
  194. package/tsconfig.json +0 -11
  195. package/tsconfig.node.json +0 -29
  196. package/tsconfig.test.json +0 -27
  197. package/tsdown.config.ts +0 -17
  198. package/vitest.config.ts +0 -76
@@ -1,631 +0,0 @@
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
- }
@@ -1,35 +0,0 @@
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 DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "files": [],
3
- "references": [
4
- {
5
- "path": "./tsconfig.node.json"
6
- },
7
- {
8
- "path": "./tsconfig.test.json"
9
- }
10
- ]
11
- }
@@ -1,29 +0,0 @@
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
- }