@abacus-ai/cli 2.0.0-canary.1 → 2.0.0-canary.3

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 (197) hide show
  1. package/dist/index.mjs +450 -422
  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 -449
  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 -1007
  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 -319
  62. package/src/components/tool-permissions/diff-preview.tsx +0 -359
  63. package/src/components/tool-permissions/index.ts +0 -5
  64. package/src/components/tool-permissions/permission-options.tsx +0 -401
  65. package/src/components/tool-permissions/permission-preview-header.tsx +0 -57
  66. package/src/components/tool-permissions/tool-permission-ui.tsx +0 -420
  67. package/src/components/tools/agent/ask-user-question.tsx +0 -107
  68. package/src/components/tools/agent/enter-plan-mode.tsx +0 -55
  69. package/src/components/tools/agent/exit-plan-mode.tsx +0 -83
  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 -188
  98. package/src/components/tools/terminal/get-terminal-output.tsx +0 -91
  99. package/src/components/tools/terminal/run-in-terminal.tsx +0 -131
  100. package/src/components/tools/types.ts +0 -16
  101. package/src/components/tools.tsx +0 -68
  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 -27
  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 -76
  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 -389
  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 -1063
  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/types.ts +0 -51
  184. package/src/theme/context.tsx +0 -57
  185. package/src/theme/index.ts +0 -4
  186. package/src/theme/themed.tsx +0 -35
  187. package/src/theme/themes.json +0 -546
  188. package/src/theme/types.ts +0 -110
  189. package/src/tools/types.ts +0 -59
  190. package/src/tools/utils/__tests__/zod-coercion.test.ts +0 -33
  191. package/src/tools/utils/tool-ui-components.tsx +0 -649
  192. package/src/tools/utils/zod-coercion.ts +0 -35
  193. package/tsconfig.json +0 -16
  194. package/tsconfig.node.json +0 -29
  195. package/tsconfig.test.json +0 -27
  196. package/tsdown.config.ts +0 -17
  197. package/vitest.config.ts +0 -76
@@ -1,649 +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
- /** When set, syntax-highlight params using this language via cli-highlight */
126
- paramsLanguage?: string;
127
- }
128
-
129
- export function ToolHeader({
130
- name,
131
- params,
132
- status = "pending",
133
- showSpinner,
134
- isAwaitingPermission,
135
- toolCallId,
136
- paramsLanguage,
137
- }: ToolHeaderProps) {
138
- const color = getStatusColor(status);
139
-
140
- // Auto-detect awaiting permission via context:
141
- // When a tool call ID matches the pending permission, or when showSpinner is true
142
- // and there's any pending permission (only one at a time), show static indicator.
143
- const pendingToolCallId = use(PendingToolCallIdContext);
144
- const awaiting =
145
- isAwaitingPermission ??
146
- (pendingToolCallId != null &&
147
- ((toolCallId != null && toolCallId === pendingToolCallId) ||
148
- (toolCallId == null && showSpinner)));
149
-
150
- let indicator: React.ReactNode;
151
- if (awaiting) {
152
- indicator = <Text color="yellow">◌</Text>;
153
- } else if (showSpinner) {
154
- indicator = <BlinkingDot />;
155
- } else {
156
- indicator = <Text color={color}>⏺</Text>;
157
- }
158
-
159
- let paramsContent: React.ReactNode = null;
160
- if (params) {
161
- let highlighted = params;
162
- if (paramsLanguage && supportsLanguage(paramsLanguage)) {
163
- try {
164
- highlighted = highlight(params, { language: paramsLanguage });
165
- } catch {
166
- // fallback to plain text
167
- }
168
- }
169
- paramsContent = paramsLanguage ? (
170
- <Text>({highlighted})</Text>
171
- ) : (
172
- <Text dimColor>({params})</Text>
173
- );
174
- }
175
-
176
- return (
177
- <View flexDirection="row" alignItems="center" gap={1}>
178
- {indicator}
179
- <Text color="cyan">{name}</Text>
180
- {paramsContent}
181
- </View>
182
- );
183
- }
184
-
185
- /**
186
- * Tool result component - displays tool output with indentation
187
- */
188
- export interface ToolResultProps {
189
- children: React.ReactNode;
190
- color?: string;
191
- indent?: number;
192
- }
193
-
194
- export function ToolResult({ children, color = "gray", indent = 2 }: ToolResultProps) {
195
- return (
196
- <View marginLeft={indent} flexDirection="row" alignItems="flex-start" gap={1}>
197
- <Text color={color} dimColor>
198
-
199
- </Text>
200
- <Text color={color} dimColor>
201
- {children}
202
- </Text>
203
- </View>
204
- );
205
- }
206
-
207
- /**
208
- * Wrapper for preview content areas (diffs, code blocks, terminal output).
209
- * Provides consistent indentation below the result line.
210
- */
211
- export interface PreviewContentProps {
212
- children: React.ReactNode;
213
- indent?: number;
214
- }
215
-
216
- export function PreviewContent({ children, indent = 4 }: PreviewContentProps) {
217
- return (
218
- <View flexDirection="column" paddingLeft={indent}>
219
- {children}
220
- </View>
221
- );
222
- }
223
-
224
- /**
225
- * Parse tool result from JSON string
226
- */
227
- export function parseToolResult(content: string): any {
228
- try {
229
- const parsed = JSON.parse(content);
230
- if (typeof parsed !== "object" || parsed === null) {
231
- return { output: content, type: "text" };
232
- }
233
- return parsed;
234
- } catch {
235
- const jsonMatch = content.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
236
- if (jsonMatch && jsonMatch[1]) {
237
- try {
238
- const parsed = JSON.parse(jsonMatch[1].trim());
239
- if (typeof parsed !== "object" || parsed === null) {
240
- return { output: jsonMatch[1].trim(), type: "text" };
241
- }
242
- return parsed;
243
- } catch {
244
- return { output: jsonMatch[1].trim(), type: "text" };
245
- }
246
- }
247
- return { output: content, type: "text" };
248
- }
249
- }
250
-
251
- /**
252
- * Compute expected final content after edit operation
253
- * Used for diff preview
254
- */
255
- export function computeExpectedFinalContentForDiff(
256
- currentContent: string,
257
- codeEdit: string,
258
- overwriteFile: boolean,
259
- startLine?: number,
260
- endLine?: number,
261
- instructions?: string,
262
- ): string {
263
- if (overwriteFile) {
264
- return codeEdit;
265
- }
266
-
267
- if (startLine !== undefined && endLine !== undefined) {
268
- const lines = currentContent.split("\n");
269
- const totalLines = lines.length;
270
- const validStartLine = Math.max(1, Math.min(startLine, totalLines));
271
- const validEndLine = Math.max(validStartLine, Math.min(endLine, totalLines));
272
-
273
- const beforeLines = lines.slice(0, validStartLine - 1);
274
- const afterLines = lines.slice(validEndLine);
275
- const newLines = codeEdit.split("\n");
276
-
277
- return [...beforeLines, ...newLines, ...afterLines].join("\n");
278
- }
279
-
280
- if (instructions) {
281
- return currentContent + "\n" + codeEdit;
282
- }
283
-
284
- const codeEditLines = codeEdit.split("\n");
285
- const currentLines = currentContent.split("\n");
286
-
287
- if (codeEditLines.length >= currentLines.length * 0.8) {
288
- return codeEdit;
289
- }
290
-
291
- if (currentContent.includes(codeEdit)) {
292
- return currentContent;
293
- }
294
-
295
- return currentContent + "\n" + codeEdit;
296
- }
297
-
298
- /**
299
- * Wrap long lines for terminal display
300
- */
301
- export function wrapLine(content: string, maxWidth: number, lineNumberWidth: number): string[] {
302
- if (!content) return [""];
303
-
304
- // Account for line number, gutter (` - ` or ` + `), and some margin
305
- const availableWidth = maxWidth - lineNumberWidth - 4 - 2; // 4 for gutter, 2 for margins
306
-
307
- if (content.length <= availableWidth) {
308
- return [content];
309
- }
310
-
311
- const wrapped: string[] = [];
312
- let remaining = content;
313
-
314
- while (remaining.length > 0) {
315
- if (remaining.length <= availableWidth) {
316
- wrapped.push(remaining);
317
- break;
318
- }
319
-
320
- // Try to break at a space near the limit
321
- let breakPoint = remaining.lastIndexOf(" ", availableWidth);
322
- if (breakPoint === -1 || breakPoint < availableWidth * 0.5) {
323
- breakPoint = availableWidth;
324
- }
325
-
326
- wrapped.push(remaining.slice(0, breakPoint));
327
- remaining = remaining.slice(breakPoint).trimStart();
328
- }
329
-
330
- return wrapped;
331
- }
332
-
333
- /**
334
- * Get language from file extension for syntax highlighting
335
- */
336
- function getLanguageFromPath(filePath: string): string | undefined {
337
- const ext = extname(filePath).toLowerCase().slice(1);
338
- const langMap: Record<string, string> = {
339
- ts: "typescript",
340
- tsx: "typescript",
341
- js: "javascript",
342
- jsx: "javascript",
343
- py: "python",
344
- rb: "ruby",
345
- rs: "rust",
346
- go: "go",
347
- java: "java",
348
- c: "c",
349
- cpp: "cpp",
350
- h: "c",
351
- hpp: "cpp",
352
- cs: "csharp",
353
- php: "php",
354
- swift: "swift",
355
- kt: "kotlin",
356
- scala: "scala",
357
- sh: "bash",
358
- bash: "bash",
359
- zsh: "bash",
360
- json: "json",
361
- yaml: "yaml",
362
- yml: "yaml",
363
- xml: "xml",
364
- html: "html",
365
- css: "css",
366
- scss: "scss",
367
- less: "less",
368
- sql: "sql",
369
- md: "markdown",
370
- markdown: "markdown",
371
- txt: "plaintext",
372
- mmd: "mermaid",
373
- mermaid: "mermaid",
374
- };
375
- return langMap[ext];
376
- }
377
-
378
- /**
379
- * Try to render mermaid diagram as ASCII art
380
- * Returns null if parsing fails
381
- */
382
- function tryRenderMermaid(content: string): string | null {
383
- try {
384
- return renderMermaidAscii(content);
385
- } catch {
386
- return null;
387
- }
388
- }
389
-
390
- /**
391
- * Code preview component for new files
392
- * Shows syntax-highlighted code block with line numbers
393
- */
394
- export interface CodePreviewProps {
395
- content: string;
396
- filePath?: string;
397
- /** First line number to display (1-based). Defaults to 1. */
398
- startLine?: number;
399
- maxLines?: number;
400
- dimmed?: boolean;
401
- }
402
-
403
- export function CodePreview({
404
- content,
405
- filePath,
406
- startLine = 1,
407
- maxLines = 4,
408
- dimmed = false,
409
- }: CodePreviewProps) {
410
- const { displayContent, totalLines, hasMore, displayLineCount } = useMemo(() => {
411
- const allLines = content.split("\n");
412
- const total = allLines.length;
413
- const lines = allLines.slice(0, maxLines);
414
- return {
415
- displayContent: lines.join("\n"),
416
- displayLineCount: lines.length,
417
- totalLines: total,
418
- hasMore: total > maxLines,
419
- };
420
- }, [content, maxLines]);
421
-
422
- const highlightedContent = useMemo(() => {
423
- if (!displayContent) return displayContent;
424
-
425
- const language = filePath ? getLanguageFromPath(filePath) : undefined;
426
-
427
- // Try to render mermaid diagrams as ASCII art
428
- if (language === "mermaid") {
429
- const mermaidOutput = tryRenderMermaid(content);
430
- if (mermaidOutput !== null) {
431
- return mermaidOutput;
432
- }
433
- // If mermaid parsing fails, fall through to regular rendering
434
- }
435
-
436
- if (language && supportsLanguage(language)) {
437
- try {
438
- return highlight(displayContent, { language });
439
- } catch {
440
- // Fallback to plain text
441
- }
442
- }
443
- return displayContent;
444
- }, [displayContent, filePath, content]);
445
-
446
- if (!displayContent) {
447
- return null;
448
- }
449
-
450
- const lastLineNum = startLine + totalLines - 1;
451
- const maxLineNumWidth = lastLineNum.toString().length;
452
- const lines = highlightedContent.split("\n");
453
-
454
- return (
455
- <View flexDirection="column">
456
- {lines.map((line, idx) => {
457
- const lineNum = startLine + idx;
458
- const paddedNum = String(lineNum).padStart(maxLineNumWidth, " ");
459
- return (
460
- <Text key={idx} dimColor={dimmed}>
461
- <Text dimColor>{paddedNum} │ </Text>
462
- {line}
463
- </Text>
464
- );
465
- })}
466
- {hasMore && <Text dimColor> ... {totalLines - displayLineCount} more lines</Text>}
467
- </View>
468
- );
469
- }
470
-
471
- /**
472
- * Highlight full file content and return per-line highlighted strings.
473
- * Highlights the whole file (not per-line) to preserve multi-line syntax context.
474
- * Returns plain split lines if language is unsupported or highlight throws.
475
- */
476
- export function highlightLines(content: string, filePath: string): string[] {
477
- const language = getLanguageFromPath(filePath);
478
- if (language && language !== "mermaid" && supportsLanguage(language)) {
479
- try {
480
- return highlight(content, { language }).split("\n");
481
- } catch {}
482
- }
483
- return content.split("\n");
484
- }
485
-
486
- /**
487
- * Condensed diff preview component
488
- * Shows a limited number of changed lines with context
489
- */
490
- export interface CondensedDiffPreviewProps {
491
- originalContent: string;
492
- newContent: string;
493
- filePath?: string;
494
- maxLines?: number;
495
- dimmed?: boolean;
496
- }
497
-
498
- export function CondensedDiffPreview({
499
- originalContent,
500
- newContent,
501
- filePath,
502
- maxLines = 4,
503
- dimmed = false,
504
- }: CondensedDiffPreviewProps) {
505
- const { colors } = useTheme();
506
-
507
- const { diffLines, addedCount, removedCount, highlightedOrigLines, highlightedNewLines } =
508
- useMemo(() => {
509
- const hlOrig = filePath ? highlightLines(originalContent, filePath) : null;
510
- const hlNew = filePath ? highlightLines(newContent, filePath) : null;
511
-
512
- const patch = structuredPatch(
513
- "file",
514
- "file",
515
- originalContent,
516
- newContent,
517
- undefined,
518
- undefined,
519
- { context: 1 },
520
- );
521
- const lines: CondensedDiffLine[] = [];
522
- let added = 0;
523
- let removed = 0;
524
-
525
- for (const hunk of patch.hunks) {
526
- let oldLineNum = hunk.oldStart;
527
- let newLineNum = hunk.newStart;
528
-
529
- for (const line of hunk.lines) {
530
- if (lines.length >= maxLines) break;
531
-
532
- const prefix = line[0];
533
- const content = line.slice(1);
534
-
535
- if (prefix === "+") {
536
- lines.push({ type: "added", content, lineNumber: newLineNum++ });
537
- added++;
538
- } else if (prefix === "-") {
539
- lines.push({ type: "removed", content, lineNumber: oldLineNum++ });
540
- removed++;
541
- } else {
542
- lines.push({ type: "unchanged", content, lineNumber: oldLineNum });
543
- oldLineNum++;
544
- newLineNum++;
545
- }
546
- }
547
- if (lines.length >= maxLines) break;
548
- }
549
-
550
- return {
551
- diffLines: lines.slice(0, maxLines),
552
- addedCount: added,
553
- removedCount: removed,
554
- highlightedOrigLines: hlOrig,
555
- highlightedNewLines: hlNew,
556
- };
557
- }, [originalContent, newContent, filePath, maxLines]);
558
-
559
- if (diffLines.length === 0) {
560
- return null;
561
- }
562
-
563
- const maxLineNumWidth = Math.max(...diffLines.map((l) => l.lineNumber)).toString().length;
564
-
565
- // Build summary text
566
- const summaryParts = [];
567
- if (addedCount > 0) summaryParts.push(`+${addedCount}`);
568
- if (removedCount > 0) summaryParts.push(`-${removedCount}`);
569
- const summary = summaryParts.join(" ");
570
-
571
- return (
572
- <View flexDirection="column" paddingLeft={1}>
573
- {summary && (
574
- <View marginBottom={0}>
575
- <Text dimColor>{summary} lines</Text>
576
- </View>
577
- )}
578
- {diffLines.map((line, idx) => {
579
- const paddedNum = String(line.lineNumber).padStart(maxLineNumWidth, " ");
580
- // Pick syntax-highlighted content when available
581
- const hlContent =
582
- line.type === "removed"
583
- ? (highlightedOrigLines?.[line.lineNumber - 1] ?? line.content)
584
- : line.type === "added"
585
- ? (highlightedNewLines?.[line.lineNumber - 1] ?? line.content)
586
- : (highlightedOrigLines?.[line.lineNumber - 1] ?? line.content);
587
-
588
- if (line.type === "removed") {
589
- return (
590
- <View key={idx} flexDirection="row" backgroundColor={colors.diffRemoved}>
591
- <Text
592
- backgroundColor={colors.diffRemoved}
593
- color={colors.diffRemovedText}
594
- dimColor={dimmed}
595
- >
596
- {paddedNum} -{" "}
597
- </Text>
598
- <View flexShrink={1}>
599
- <Text
600
- backgroundColor={colors.diffRemoved}
601
- color={colors.diffRemovedText}
602
- dimColor={dimmed}
603
- wrap="wrap"
604
- >
605
- {hlContent}
606
- </Text>
607
- </View>
608
- </View>
609
- );
610
- }
611
-
612
- if (line.type === "added") {
613
- return (
614
- <View key={idx} flexDirection="row" backgroundColor={colors.diffAdded}>
615
- <Text
616
- backgroundColor={colors.diffAdded}
617
- color={colors.diffAddedText}
618
- dimColor={dimmed}
619
- >
620
- {paddedNum} +{" "}
621
- </Text>
622
- <View flexShrink={1}>
623
- <Text
624
- backgroundColor={colors.diffAdded}
625
- color={colors.diffAddedText}
626
- dimColor={dimmed}
627
- wrap="wrap"
628
- >
629
- {hlContent}
630
- </Text>
631
- </View>
632
- </View>
633
- );
634
- }
635
-
636
- return (
637
- <View key={idx} flexDirection="row">
638
- <Text dimColor>{paddedNum} </Text>
639
- <View flexShrink={1}>
640
- <Text dimColor wrap="wrap">
641
- {hlContent}
642
- </Text>
643
- </View>
644
- </View>
645
- );
646
- })}
647
- </View>
648
- );
649
- }
@@ -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,16 +0,0 @@
1
- {
2
- "files": [],
3
- "references": [
4
- {
5
- "path": "./tsconfig.node.json"
6
- },
7
- {
8
- "path": "./tsconfig.test.json"
9
- }
10
- ],
11
- "compilerOptions": {
12
- "paths": {
13
- "@/package.json": ["./package.json"]
14
- }
15
- }
16
- }