@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,104 @@
1
+ import type { ParsedToolResult } from "@codellm/agent";
2
+
3
+ import { View, Text } from "@codellm/jar";
4
+ import React from "react";
5
+ import { z } from "zod";
6
+
7
+ import type { ToolDef, ToolStatus } from "../types.js";
8
+
9
+ import { ToolHeader, ToolResult, truncatePath, snakeToCamel } from "../shared/index.js";
10
+
11
+ const DeleteFileToolParams = z.object({
12
+ targetFile: z.string(),
13
+ explanation: z.string().optional(),
14
+ });
15
+
16
+ export const deleteFileTool: ToolDef = {
17
+ displayName: "Delete",
18
+
19
+ getHeaderParams(input: Record<string, unknown>): string {
20
+ try {
21
+ const targetFile = (input?.targetFile || input?.target_file || "[unknown]") as string;
22
+ return truncatePath(targetFile);
23
+ } catch {
24
+ return "[unknown]";
25
+ }
26
+ },
27
+
28
+ renderUI(
29
+ rawInput: Record<string, unknown>,
30
+ status: ToolStatus,
31
+ parsedResult?: ParsedToolResult,
32
+ ): React.ReactElement {
33
+ const parseResult = DeleteFileToolParams.safeParse(snakeToCamel(rawInput));
34
+ if (!parseResult.success) {
35
+ return (
36
+ <View flexDirection="column">
37
+ <ToolHeader name="Delete" params="" status="error" />
38
+ <ToolResult color="red">Invalid params</ToolResult>
39
+ </View>
40
+ );
41
+ }
42
+ const params = parseResult.data;
43
+ const { targetFile } = params;
44
+ const displayParams = truncatePath(targetFile);
45
+
46
+ if (status === "interrupted") {
47
+ return (
48
+ <View flexDirection="column">
49
+ <ToolHeader name="Delete" params={displayParams} status="interrupted" />
50
+ <ToolResult color="yellow">Interrupted · What should I do instead?</ToolResult>
51
+ </View>
52
+ );
53
+ }
54
+
55
+ if (status === "rejected") {
56
+ if (parsedResult?.userNote) {
57
+ return (
58
+ <View flexDirection="column">
59
+ <ToolHeader name="Delete" params={displayParams} status="rejected" />
60
+ <ToolResult color="yellow">
61
+ Rejected · <Text italic>"{parsedResult.userNote}"</Text>
62
+ </ToolResult>
63
+ </View>
64
+ );
65
+ }
66
+ return (
67
+ <View flexDirection="column">
68
+ <ToolHeader name="Delete" params={displayParams} status="rejected" />
69
+ <ToolResult color="yellow">Rejected</ToolResult>
70
+ </View>
71
+ );
72
+ }
73
+
74
+ if (status === "error") {
75
+ return (
76
+ <View flexDirection="column">
77
+ <ToolHeader name="Delete" params={displayParams} status="error" />
78
+ <ToolResult color="red">Error deleting file</ToolResult>
79
+ </View>
80
+ );
81
+ }
82
+
83
+ const isExecuting = !parsedResult && (status === "executing" || status === "pending");
84
+
85
+ if (isExecuting) {
86
+ return <ToolHeader name="Delete" params={displayParams} status="pending" showSpinner />;
87
+ }
88
+
89
+ if (!parsedResult) {
90
+ return (
91
+ <View flexDirection="column">
92
+ <ToolHeader name="Delete" params={displayParams} status="pending" />
93
+ </View>
94
+ );
95
+ }
96
+
97
+ return (
98
+ <View flexDirection="column">
99
+ <ToolHeader name="Delete" params={displayParams} status="success" />
100
+ <ToolResult>Deleted</ToolResult>
101
+ </View>
102
+ );
103
+ },
104
+ };
@@ -0,0 +1,220 @@
1
+ import type { EditParsedData, ParsedToolResult, ToolDisplayData } from "@codellm/agent";
2
+
3
+ import { View, Text, useFocus, useInput } from "@codellm/jar";
4
+ import React, { useState } from "react";
5
+ import { z } from "zod";
6
+
7
+ import type { ToolDef, ToolStatus } from "../types.js";
8
+
9
+ import { DiffPreview } from "../../tool-permissions/diff-preview.js";
10
+ import {
11
+ ToolHeader,
12
+ ToolResult,
13
+ PreviewContent,
14
+ truncatePath,
15
+ CodePreview,
16
+ snakeToCamel,
17
+ } from "../shared/index.js";
18
+ import { coerceOptionalBoolean } from "../shared/zod-coercion.js";
19
+
20
+ const EditToolParams = z.object({
21
+ targetFile: z.string(),
22
+ codeEdit: z.string(),
23
+ overwriteFile: coerceOptionalBoolean,
24
+ instructions: z.string().optional(),
25
+ startLine: z
26
+ .union([z.number(), z.string(), z.null(), z.undefined()])
27
+ .optional()
28
+ .transform((val) => {
29
+ if (val === null || val === undefined) return undefined;
30
+ const num = Number(val);
31
+ return isNaN(num) ? undefined : num;
32
+ }),
33
+ endLine: z
34
+ .union([z.number(), z.string(), z.null(), z.undefined()])
35
+ .optional()
36
+ .transform((val) => {
37
+ if (val === null || val === undefined) return undefined;
38
+ const num = Number(val);
39
+ return isNaN(num) ? undefined : num;
40
+ }),
41
+ explanation: z.string().optional(),
42
+ });
43
+
44
+ const EDIT_MAX_LINES_COLLAPSED = 15;
45
+ const EDIT_MAX_LINES_EXPANDED = 100;
46
+
47
+ function EditToolUI({
48
+ rawInput,
49
+ status,
50
+ parsedResult,
51
+ toolDisplayData,
52
+ }: {
53
+ rawInput: Record<string, unknown>;
54
+ status: ToolStatus;
55
+ parsedResult?: ParsedToolResult<EditParsedData>;
56
+ toolDisplayData?: ToolDisplayData;
57
+ }) {
58
+ const [isExpanded, setIsExpanded] = useState(false);
59
+ const hasResult =
60
+ parsedResult != null && (status === "success" || parsedResult.phase === "skipped");
61
+
62
+ const { isFocused } = useFocus({
63
+ id: `edit-tool-${(rawInput?.targetFile || rawInput?.target_file || "unknown") as string}`,
64
+ isActive: hasResult,
65
+ });
66
+
67
+ useInput(
68
+ (input, key) => {
69
+ if (isFocused && key.ctrl && input === "o") {
70
+ setIsExpanded((prev) => !prev);
71
+ }
72
+ },
73
+ { isActive: isFocused && hasResult },
74
+ );
75
+
76
+ const parseResult = EditToolParams.safeParse(snakeToCamel(rawInput));
77
+ if (!parseResult.success) {
78
+ return (
79
+ <View flexDirection="column">
80
+ <ToolHeader name="Edit" params="" status="error" />
81
+ <ToolResult color="red">Invalid params</ToolResult>
82
+ </View>
83
+ );
84
+ }
85
+ const params = parseResult.data;
86
+
87
+ const targetFile = parsedResult?.data.targetFile ?? params.targetFile;
88
+
89
+ const isExecuting = !parsedResult && (status === "executing" || status === "pending");
90
+ const displayPath = truncatePath(targetFile);
91
+
92
+ // Resolve display data — prefer toolDisplayData side-channel
93
+ const isPlanFile = toolDisplayData?.isPlanFile ?? false;
94
+ const isNewFile = parsedResult?.data.isNewFile ?? toolDisplayData?.isNewFile ?? false;
95
+ const operation = isNewFile ? "Create" : "Update";
96
+
97
+ // Plan file edits: no diff shown
98
+ if (isPlanFile && status === "success") {
99
+ return (
100
+ <View flexDirection="column">
101
+ <ToolHeader name={operation} params={displayPath} status="success" />
102
+ <ToolResult>Updated plan</ToolResult>
103
+ </View>
104
+ );
105
+ }
106
+
107
+ if (status === "interrupted") {
108
+ return (
109
+ <View flexDirection="column">
110
+ <ToolHeader name={operation} params={displayPath} status="interrupted" />
111
+ <ToolResult color="yellow">Interrupted · What should I do instead?</ToolResult>
112
+ </View>
113
+ );
114
+ }
115
+
116
+ if (status === "rejected") {
117
+ const origContent = toolDisplayData?.originalContent ?? "";
118
+ const newCont = toolDisplayData?.newContent ?? "";
119
+ const interruptMessage = parsedResult?.userNote ? (
120
+ <ToolResult color="yellow">
121
+ Rejected · <Text italic>"{parsedResult.userNote}"</Text>
122
+ </ToolResult>
123
+ ) : (
124
+ <ToolResult color="yellow">Rejected</ToolResult>
125
+ );
126
+ return (
127
+ <View flexDirection="column">
128
+ <ToolHeader name={operation} params={displayPath} status="rejected" />
129
+ {!isPlanFile && origContent && newCont && (
130
+ <PreviewContent>
131
+ <DiffPreview
132
+ filePath={targetFile}
133
+ originalContent={origContent}
134
+ newContent={newCont}
135
+ dimmed
136
+ />
137
+ </PreviewContent>
138
+ )}
139
+ {interruptMessage}
140
+ </View>
141
+ );
142
+ }
143
+
144
+ if (isExecuting) {
145
+ return <ToolHeader name={operation} params={displayPath} status="pending" showSpinner />;
146
+ }
147
+
148
+ if (!parsedResult) {
149
+ return (
150
+ <View flexDirection="column">
151
+ <ToolHeader name={operation} params={displayPath} status="pending" />
152
+ </View>
153
+ );
154
+ }
155
+
156
+ const isNoChanges = parsedResult.phase === "skipped";
157
+ const resultText = parsedResult.summary ?? "Updated";
158
+
159
+ // Content for diff preview — ONLY from toolDisplayData (EditTool.format() strips it)
160
+ const originalContent = toolDisplayData?.originalContent;
161
+ const finalContent = toolDisplayData?.finalContent ?? toolDisplayData?.newContent;
162
+
163
+ return (
164
+ <View flexDirection="column">
165
+ <ToolHeader
166
+ name={operation}
167
+ params={displayPath}
168
+ status={isNoChanges ? "rejected" : "success"}
169
+ />
170
+ <ToolResult color={isNoChanges ? "yellow" : undefined}>{resultText}</ToolResult>
171
+
172
+ {!isNoChanges && originalContent !== undefined && finalContent !== undefined && (
173
+ <PreviewContent>
174
+ {isNewFile ? (
175
+ <CodePreview
176
+ filePath={targetFile}
177
+ content={finalContent}
178
+ maxLines={isExpanded ? EDIT_MAX_LINES_EXPANDED : EDIT_MAX_LINES_COLLAPSED}
179
+ />
180
+ ) : (
181
+ <DiffPreview
182
+ filePath={targetFile}
183
+ originalContent={originalContent}
184
+ newContent={finalContent}
185
+ />
186
+ )}
187
+ </PreviewContent>
188
+ )}
189
+ </View>
190
+ );
191
+ }
192
+
193
+ export const editTool: ToolDef<EditParsedData> = {
194
+ displayName: "Edit",
195
+
196
+ getHeaderParams(input: Record<string, unknown>): string {
197
+ try {
198
+ const targetFile = (input?.targetFile || input?.target_file || "[unknown]") as string;
199
+ return truncatePath(targetFile);
200
+ } catch {
201
+ return "[unknown]";
202
+ }
203
+ },
204
+
205
+ renderUI(
206
+ rawInput: Record<string, unknown>,
207
+ status: ToolStatus,
208
+ parsedResult,
209
+ displayData,
210
+ ): React.ReactElement {
211
+ return (
212
+ <EditToolUI
213
+ rawInput={rawInput}
214
+ status={status}
215
+ parsedResult={parsedResult}
216
+ toolDisplayData={displayData}
217
+ />
218
+ );
219
+ },
220
+ };
@@ -0,0 +1,78 @@
1
+ import type { ParsedToolResult } from "@codellm/agent";
2
+
3
+ import { View } from "@codellm/jar";
4
+ import React from "react";
5
+ import { z } from "zod";
6
+
7
+ import type { ToolDef, ToolStatus } from "../types.js";
8
+
9
+ import { ToolHeader, ToolResult, truncatePath, snakeToCamel } from "../shared/index.js";
10
+
11
+ const ListDirToolParams = z.object({
12
+ relativeWorkspacePath: z.string().optional(),
13
+ explanation: z.string().optional(),
14
+ });
15
+
16
+ export const listDirTool: ToolDef = {
17
+ displayName: "ListDir",
18
+
19
+ getHeaderParams(input: Record<string, unknown>): string {
20
+ try {
21
+ const path = (input?.relativeWorkspacePath ||
22
+ input?.relative_workspace_path ||
23
+ ".") as string;
24
+ return truncatePath(path);
25
+ } catch {
26
+ return "[unknown]";
27
+ }
28
+ },
29
+
30
+ renderUI(
31
+ rawInput: Record<string, unknown>,
32
+ status: ToolStatus,
33
+ parsedResult?: ParsedToolResult,
34
+ ): React.ReactElement {
35
+ const parseResult = ListDirToolParams.safeParse(snakeToCamel(rawInput));
36
+ if (!parseResult.success) {
37
+ return (
38
+ <View flexDirection="column">
39
+ <ToolHeader name="LS" params="" status="error" />
40
+ <ToolResult color="red">Invalid params</ToolResult>
41
+ </View>
42
+ );
43
+ }
44
+ const params = parseResult.data;
45
+ const path = params.relativeWorkspacePath || ".";
46
+ const displayParams = truncatePath(path);
47
+
48
+ if (status === "error") {
49
+ return (
50
+ <View flexDirection="column">
51
+ <ToolHeader name="List" params={displayParams} status="error" />
52
+ <ToolResult color="red">Error listing directory</ToolResult>
53
+ </View>
54
+ );
55
+ }
56
+
57
+ const isExecuting = !parsedResult && (status === "executing" || status === "pending");
58
+
59
+ if (isExecuting) {
60
+ return <ToolHeader name="LS" params={displayParams} status="pending" showSpinner />;
61
+ }
62
+
63
+ if (!parsedResult) {
64
+ return (
65
+ <View flexDirection="column">
66
+ <ToolHeader name="LS" params={displayParams} status="pending" />
67
+ </View>
68
+ );
69
+ }
70
+
71
+ return (
72
+ <View flexDirection="column">
73
+ <ToolHeader name="LS" params={displayParams} status="success" />
74
+ <ToolResult>{parsedResult.summary}</ToolResult>
75
+ </View>
76
+ );
77
+ },
78
+ };
@@ -0,0 +1,180 @@
1
+ import type { ReadFileParsedData } from "@codellm/agent";
2
+
3
+ import { View, useFocus, useInput } from "@codellm/jar";
4
+ import React, { useState } from "react";
5
+ import { z } from "zod";
6
+
7
+ import type { ToolDef, ToolStatus } from "../types.js";
8
+
9
+ import {
10
+ ToolHeader,
11
+ ToolResult,
12
+ PreviewContent,
13
+ CodePreview,
14
+ truncatePath,
15
+ snakeToCamel,
16
+ } from "../shared/index.js";
17
+ import { coerceOptionalBoolean, coerceOptionalNumber } from "../shared/zod-coercion.js";
18
+
19
+ const MAX_LINES_COLLAPSED = 4;
20
+ const MAX_LINES_EXPANDED = 100;
21
+
22
+ const ReadFileToolParams = z.object({
23
+ targetFile: z.string(),
24
+ startLineOneIndexed: coerceOptionalNumber,
25
+ endLineOneIndexed: coerceOptionalNumber,
26
+ startLine: coerceOptionalNumber,
27
+ endLine: coerceOptionalNumber,
28
+ shouldReadEntireFile: coerceOptionalBoolean,
29
+ explanation: z.string().optional(),
30
+ });
31
+
32
+ export const readFileTool: ToolDef<ReadFileParsedData> = {
33
+ displayName: "Read",
34
+
35
+ getHeaderParams(input: Record<string, unknown>): string {
36
+ try {
37
+ const targetFile = (input?.targetFile || input?.target_file || "[unknown]") as string;
38
+ const displayPath = truncatePath(targetFile);
39
+
40
+ const startLine =
41
+ input?.startLineOneIndexed ||
42
+ input?.start_line_one_indexed ||
43
+ input?.startLine ||
44
+ input?.start_line;
45
+ const endLine =
46
+ input?.endLineOneIndexed ||
47
+ input?.end_line_one_indexed ||
48
+ input?.endLine ||
49
+ input?.end_line;
50
+
51
+ if (startLine !== undefined && endLine !== undefined) {
52
+ return `${displayPath}:${startLine}-${endLine}`;
53
+ }
54
+ return displayPath;
55
+ } catch {
56
+ return "[unknown]";
57
+ }
58
+ },
59
+
60
+ renderUI(
61
+ rawInput: Record<string, unknown>,
62
+ status: ToolStatus,
63
+ parsedResult,
64
+ ): React.ReactElement {
65
+ const parseResult = ReadFileToolParams.safeParse(snakeToCamel(rawInput));
66
+ if (!parseResult.success) {
67
+ return (
68
+ <View flexDirection="column">
69
+ <ToolHeader name="Read" params="" status="error" />
70
+ <ToolResult color="red">Invalid params</ToolResult>
71
+ </View>
72
+ );
73
+ }
74
+ const params = parseResult.data;
75
+ const { targetFile, startLineOneIndexed, endLineOneIndexed } = params;
76
+
77
+ if (!targetFile || typeof targetFile !== "string") {
78
+ return (
79
+ <View flexDirection="column">
80
+ <ToolHeader name="Read" params="[invalid file path]" status="error" />
81
+ <ToolResult color="red">Error: Invalid file path parameter</ToolResult>
82
+ </View>
83
+ );
84
+ }
85
+
86
+ const isExecuting = !parsedResult && (status === "executing" || status === "pending");
87
+ const filePath = truncatePath(targetFile);
88
+ const paramStartLine = startLineOneIndexed ?? params.startLine;
89
+ const endLine = endLineOneIndexed ?? params.endLine;
90
+
91
+ let displayParams = filePath;
92
+ if (paramStartLine !== undefined && endLine !== undefined) {
93
+ displayParams = `${filePath}:${paramStartLine}-${endLine}`;
94
+ }
95
+
96
+ if (isExecuting) {
97
+ return <ToolHeader name="Read" params={displayParams} status="pending" showSpinner />;
98
+ }
99
+
100
+ if (status === "error") {
101
+ return (
102
+ <View flexDirection="column">
103
+ <ToolHeader name="Read" params={displayParams} status="error" />
104
+ <ToolResult color="red">Error reading file</ToolResult>
105
+ </View>
106
+ );
107
+ }
108
+
109
+ if (!parsedResult) {
110
+ return (
111
+ <View flexDirection="column">
112
+ <ToolHeader name="Read" params={displayParams} status="pending" />
113
+ </View>
114
+ );
115
+ }
116
+
117
+ // Content comes clean from parsedResult.data (prefixes stripped by SDK parse())
118
+ const content = parsedResult.data.content ?? "";
119
+ const startLine = parsedResult.data.startLine ?? paramStartLine ?? 1;
120
+ const lineCount = parsedResult.data.lineCount ?? content.split("\n").length;
121
+
122
+ return (
123
+ <ReadFileResult
124
+ displayParams={displayParams}
125
+ content={content}
126
+ filePath={targetFile}
127
+ startLine={startLine}
128
+ lineCount={lineCount}
129
+ />
130
+ );
131
+ },
132
+ };
133
+
134
+ function ReadFileResult({
135
+ displayParams,
136
+ content,
137
+ filePath,
138
+ startLine,
139
+ lineCount,
140
+ }: {
141
+ displayParams: string;
142
+ content: string;
143
+ filePath: string;
144
+ startLine: number;
145
+ lineCount: number;
146
+ }) {
147
+ const [isExpanded, setIsExpanded] = useState(false);
148
+ const totalLines = content.split("\n").length;
149
+ const maxLines = isExpanded ? MAX_LINES_EXPANDED : MAX_LINES_COLLAPSED;
150
+ const canExpand = totalLines > MAX_LINES_COLLAPSED;
151
+
152
+ const { isFocused } = useFocus({
153
+ id: `read-file-${filePath}`,
154
+ isActive: canExpand,
155
+ });
156
+
157
+ useInput(
158
+ (input, key) => {
159
+ if (isFocused && key.ctrl && input === "o") {
160
+ setIsExpanded((prev) => !prev);
161
+ }
162
+ },
163
+ { isActive: isFocused && canExpand },
164
+ );
165
+
166
+ return (
167
+ <View flexDirection="column">
168
+ <ToolHeader name="Read" params={displayParams} status="success" />
169
+ <ToolResult>Read {lineCount} lines</ToolResult>
170
+ <PreviewContent>
171
+ <CodePreview
172
+ content={content}
173
+ filePath={filePath}
174
+ startLine={startLine}
175
+ maxLines={maxLines}
176
+ />
177
+ </PreviewContent>
178
+ </View>
179
+ );
180
+ }
@@ -0,0 +1,76 @@
1
+ import type { ParsedToolResult } from "@codellm/agent";
2
+
3
+ import { View } from "@codellm/jar";
4
+ import React from "react";
5
+ import { z } from "zod";
6
+
7
+ import type { ToolDef, ToolStatus } from "../types.js";
8
+
9
+ import { ToolHeader, ToolResult, truncatePath, snakeToCamel } from "../shared/index.js";
10
+
11
+ const UploadImageToolParams = z.object({
12
+ targetFile: z.string(),
13
+ explanation: z.string().optional(),
14
+ });
15
+
16
+ export const uploadImageTool: ToolDef = {
17
+ displayName: "Upload",
18
+
19
+ getHeaderParams(input: Record<string, unknown>): string {
20
+ try {
21
+ const targetFile = (input?.targetFile || input?.target_file || "[unknown]") as string;
22
+ return truncatePath(targetFile);
23
+ } catch {
24
+ return "[unknown]";
25
+ }
26
+ },
27
+
28
+ renderUI(
29
+ rawInput: Record<string, unknown>,
30
+ status: ToolStatus,
31
+ parsedResult?: ParsedToolResult,
32
+ ): React.ReactElement {
33
+ const parseResult = UploadImageToolParams.safeParse(snakeToCamel(rawInput));
34
+ if (!parseResult.success) {
35
+ return (
36
+ <View flexDirection="column">
37
+ <ToolHeader name="Upload" params="" status="error" />
38
+ <ToolResult color="red">Invalid params</ToolResult>
39
+ </View>
40
+ );
41
+ }
42
+ const params = parseResult.data;
43
+ const { targetFile } = params;
44
+ const displayParams = truncatePath(targetFile);
45
+
46
+ const isExecuting = !parsedResult && (status === "executing" || status === "pending");
47
+
48
+ if (isExecuting) {
49
+ return <ToolHeader name="Upload" params={displayParams} status="pending" showSpinner />;
50
+ }
51
+
52
+ if (!parsedResult) {
53
+ return (
54
+ <View flexDirection="column">
55
+ <ToolHeader name="Upload" params={displayParams} status="pending" />
56
+ </View>
57
+ );
58
+ }
59
+
60
+ if (parsedResult.phase === "error") {
61
+ return (
62
+ <View flexDirection="column">
63
+ <ToolHeader name="Upload" params={displayParams} status="error" />
64
+ <ToolResult color="red">{parsedResult.errorMessage ?? "Error executing tool"}</ToolResult>
65
+ </View>
66
+ );
67
+ }
68
+
69
+ return (
70
+ <View flexDirection="column">
71
+ <ToolHeader name="Upload" params={displayParams} status="success" />
72
+ <ToolResult>{parsedResult.summary}</ToolResult>
73
+ </View>
74
+ );
75
+ },
76
+ };