@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,273 +0,0 @@
1
- import { View, Text } from "@codellm/jar";
2
- import { memo, useCallback, useDeferredValue, useEffect, useMemo, useState } from "react";
3
-
4
- import { Select } from "../../ui/select.js";
5
- import { useComposerContext } from "../context.js";
6
- import { commandRegistry } from "./registry.js";
7
- import { CommandMatch } from "./types.js";
8
-
9
- interface CommandPickerProps {
10
- prompt: string;
11
- onAccept: () => void;
12
- onCancel: () => void;
13
- availableHeight: number;
14
- }
15
-
16
- type PickerState =
17
- | { type: "commands"; query: string }
18
- | { type: "subcommands"; query: string }
19
- | { type: "completions"; query: string }
20
- | null;
21
-
22
- export const CommandPicker = memo(
23
- ({ prompt, onAccept, onCancel, availableHeight }: CommandPickerProps) => {
24
- const { bufferRef } = useComposerContext();
25
- const [match, setMatch] = useState<CommandMatch | null>(null);
26
- const [completions, setCompletions] = useState<string[]>([]);
27
- const [isLoadingCompletions, setIsLoadingCompletions] = useState(false);
28
-
29
- const commandQuery = useMemo(() => {
30
- const trimmed = prompt.trim();
31
- if (!trimmed.startsWith("/")) {
32
- return "";
33
- }
34
- return trimmed.slice(1);
35
- }, [prompt]);
36
-
37
- const deferredCommandQuery = useDeferredValue(commandQuery);
38
- const isFiltering = commandQuery !== deferredCommandQuery;
39
-
40
- const pickerState = useMemo((): PickerState | null => {
41
- if (!match) {
42
- return { type: "commands", query: deferredCommandQuery };
43
- }
44
-
45
- if (match.needsSubcommand) {
46
- return { type: "subcommands", query: match.query };
47
- }
48
-
49
- const hasCompletionProvider =
50
- match.subcommand?.completionProvider || match.command.completionProvider;
51
- if (hasCompletionProvider) {
52
- return { type: "completions", query: match.query };
53
- }
54
-
55
- return null;
56
- }, [match, deferredCommandQuery]);
57
-
58
- useEffect(() => {
59
- const trimmed = prompt.trim();
60
- if (!trimmed.startsWith("/")) {
61
- setMatch(null);
62
- return;
63
- }
64
-
65
- const matched = commandRegistry.match(trimmed);
66
- setMatch(matched);
67
- }, [prompt]);
68
-
69
- useEffect(() => {
70
- const provider = match?.subcommand?.completionProvider || match?.command.completionProvider;
71
-
72
- if (!provider || match?.needsSubcommand) {
73
- setCompletions([]);
74
- setIsLoadingCompletions(false);
75
- return;
76
- }
77
-
78
- setIsLoadingCompletions(true);
79
- const query = match.query || "";
80
- const result = provider(query);
81
-
82
- if (result instanceof Promise) {
83
- result
84
- .then((items) => {
85
- setCompletions(items);
86
- setIsLoadingCompletions(false);
87
- })
88
- .catch(() => {
89
- setCompletions([]);
90
- setIsLoadingCompletions(false);
91
- });
92
- } else {
93
- setCompletions(result);
94
- setIsLoadingCompletions(false);
95
- }
96
- }, [match, match?.query]);
97
-
98
- const items = useMemo(() => {
99
- if (!pickerState) {
100
- return [];
101
- }
102
-
103
- if (pickerState.type === "subcommands" && match?.command.subcommands) {
104
- const subcommands = commandRegistry.searchSubcommands(match.command, pickerState.query);
105
- return subcommands.map((sub) => `${sub.id} - ${sub.description}`);
106
- }
107
-
108
- if (pickerState.type === "completions") {
109
- if (isLoadingCompletions) {
110
- return ["Loading models..."];
111
- }
112
-
113
- if (completions.length === 0) {
114
- if (match?.query.trim()) {
115
- return [`No matches for "${match.query}"`];
116
- }
117
- return ["No options available"];
118
- }
119
-
120
- return completions;
121
- }
122
-
123
- const commands = commandRegistry.search(deferredCommandQuery);
124
- return commands.map((cmd) => `${cmd.id} - ${cmd.description}`);
125
- }, [pickerState, match, completions, isLoadingCompletions, deferredCommandQuery]);
126
-
127
- const getAutocompleteText = useCallback(
128
- (item: string, idx: number): string | null => {
129
- if (!pickerState) {
130
- return null;
131
- }
132
-
133
- if (pickerState.type === "subcommands" && match?.command.subcommands) {
134
- const subcommands = commandRegistry.searchSubcommands(match.command, pickerState.query);
135
- const selectedSubcommand = subcommands[idx];
136
- if (selectedSubcommand) {
137
- return `/${match.command.id} ${selectedSubcommand.id} `;
138
- }
139
- return null;
140
- }
141
-
142
- if (pickerState.type === "completions" && match) {
143
- if (isLoadingCompletions || item.startsWith("Loading") || item.startsWith("No ")) {
144
- return null;
145
- }
146
- const baseCommand = match.subcommand
147
- ? `/${match.command.id} ${match.subcommand.id}`
148
- : `/${match.command.id}`;
149
- return `${baseCommand} ${item}`;
150
- }
151
-
152
- const commands = commandRegistry.search(deferredCommandQuery);
153
- const selectedCommand = commands[idx];
154
- if (selectedCommand) {
155
- return `/${selectedCommand.id} `;
156
- }
157
- return null;
158
- },
159
- [pickerState, match, deferredCommandQuery, isLoadingCompletions],
160
- );
161
-
162
- const handleTab = useCallback(
163
- (item: string, idx: number) => {
164
- const buffer = bufferRef.current;
165
- if (!buffer) {
166
- return;
167
- }
168
-
169
- const text = getAutocompleteText(item, idx);
170
- if (text) {
171
- buffer.setText(text);
172
- }
173
- },
174
- [bufferRef, getAutocompleteText],
175
- );
176
-
177
- const handleSubmit = useCallback(
178
- async (item: string, idx: number) => {
179
- const buffer = bufferRef.current;
180
- if (!buffer) {
181
- onAccept();
182
- return;
183
- }
184
-
185
- if (!pickerState) {
186
- return;
187
- }
188
-
189
- if (pickerState.type === "subcommands" && match?.command.subcommands) {
190
- const subcommands = commandRegistry.searchSubcommands(match.command, pickerState.query);
191
- const selectedSubcommand = subcommands[idx];
192
-
193
- if (selectedSubcommand) {
194
- if (selectedSubcommand.requiresArgument || selectedSubcommand.completionProvider) {
195
- buffer.setText(`/${match.command.id} ${selectedSubcommand.id} `);
196
- } else {
197
- await selectedSubcommand.execute([]);
198
- buffer.setText("");
199
- }
200
- onAccept();
201
- }
202
- return;
203
- }
204
-
205
- if (pickerState.type === "completions" && match) {
206
- if (isLoadingCompletions || item.startsWith("Loading") || item.startsWith("No ")) {
207
- return;
208
- }
209
-
210
- const executor = match.subcommand || match.command;
211
- if (executor.execute) {
212
- await executor.execute([item]);
213
- buffer.setText("");
214
- onAccept();
215
- }
216
- return;
217
- }
218
-
219
- const commands = commandRegistry.search(deferredCommandQuery);
220
- const selectedCommand = commands[idx];
221
-
222
- if (!selectedCommand) {
223
- return;
224
- }
225
-
226
- if (selectedCommand.subcommands && selectedCommand.subcommands.length > 0) {
227
- buffer.setText(`/${selectedCommand.id} `);
228
- onAccept();
229
- return;
230
- }
231
-
232
- if (selectedCommand.requiresArgument || selectedCommand.completionProvider) {
233
- buffer.setText(`/${selectedCommand.id} `);
234
- onAccept();
235
- return;
236
- }
237
-
238
- if (selectedCommand.execute) {
239
- await selectedCommand.execute([]);
240
- buffer.setText("");
241
- onAccept();
242
- }
243
- },
244
- [bufferRef, match, deferredCommandQuery, onAccept, pickerState, isLoadingCompletions],
245
- );
246
-
247
- if (!pickerState || items.length === 0) {
248
- return null;
249
- }
250
-
251
- const limit = Math.max(1, Math.min(10, availableHeight - 2));
252
-
253
- return (
254
- <View flexDirection="column">
255
- {isFiltering && pickerState.type === "commands" && (
256
- <Text dimColor>Filtering commands...</Text>
257
- )}
258
- <Select
259
- items={items}
260
- limit={limit}
261
- maxHeight={availableHeight}
262
- isActive
263
- showIndex
264
- showIndicators
265
- onSubmit={handleSubmit}
266
- onTab={handleTab}
267
- onCancel={onCancel}
268
- />
269
- </View>
270
- );
271
- },
272
- );
273
- CommandPicker.displayName = "CommandPicker";
@@ -1,233 +0,0 @@
1
- import { ComposerMode } from "../types.js";
2
- import { CommandDefinition, CommandMatch, SubcommandDefinition } from "./types.js";
3
-
4
- class CommandRegistry {
5
- private commands = new Map<string, CommandDefinition>();
6
-
7
- register(command: CommandDefinition): void {
8
- if (this.commands.has(command.id)) {
9
- return;
10
- }
11
- this.commands.set(command.id, command);
12
- }
13
-
14
- clear(): void {
15
- this.commands.clear();
16
- }
17
-
18
- get(id: string): CommandDefinition | undefined {
19
- return this.commands.get(id);
20
- }
21
-
22
- getAll(): CommandDefinition[] {
23
- return Array.from(this.commands.values());
24
- }
25
-
26
- private getAliasesForMode(command: CommandDefinition, mode: ComposerMode): string[] {
27
- if (!command.alias) {
28
- return [];
29
- }
30
-
31
- if (Array.isArray(command.alias)) {
32
- return command.alias;
33
- }
34
-
35
- return command.alias[mode] ?? [];
36
- }
37
-
38
- private buildCommandMatch(command: CommandDefinition, argParts: string[]): CommandMatch {
39
- if (command.subcommands && command.subcommands.length > 0) {
40
- if (argParts.length === 0) {
41
- return { command, args: "", query: "", needsSubcommand: true };
42
- }
43
-
44
- const subcommandId = argParts[0];
45
- const subcommand = command.subcommands.find((sub) => sub.id === subcommandId);
46
-
47
- if (!subcommand) {
48
- const args = argParts.join(" ");
49
- return { command, args, query: args, needsSubcommand: true };
50
- }
51
-
52
- const args = argParts.slice(1).join(" ");
53
- return { command, subcommand, args, query: args };
54
- }
55
-
56
- const args = argParts.join(" ");
57
- return { command, args, query: args };
58
- }
59
-
60
- private findCommandByAlias(aliasName: string, mode: ComposerMode): CommandDefinition | undefined {
61
- const lowerAlias = aliasName.toLowerCase();
62
- for (const command of this.commands.values()) {
63
- const aliases = this.getAliasesForMode(command, mode);
64
- if (aliases.some((a) => a.toLowerCase() === lowerAlias)) {
65
- return command;
66
- }
67
- }
68
- return undefined;
69
- }
70
-
71
- matchByAlias(input: string, mode: ComposerMode): CommandMatch | null {
72
- const parts = input.trim().split(/\s+/).filter(Boolean);
73
- if (parts.length === 0) {
74
- return null;
75
- }
76
-
77
- const [aliasName, ...argParts] = parts;
78
- const command = this.findCommandByAlias(aliasName, mode);
79
-
80
- if (!command) {
81
- return null;
82
- }
83
-
84
- const acceptsArgs =
85
- command.requiresArgument || (command.subcommands && command.subcommands.length > 0);
86
- if (!acceptsArgs && argParts.length > 0) {
87
- return null;
88
- }
89
-
90
- return this.buildCommandMatch(command, argParts);
91
- }
92
-
93
- /**
94
- * Parse arguments respecting quoted strings (single or double quotes)
95
- */
96
- private parseArgs(argsString: string): string[] {
97
- const args: string[] = [];
98
- let current = "";
99
- let inQuote: "'" | '"' | null = null;
100
- let escaped = false;
101
-
102
- for (let i = 0; i < argsString.length; i++) {
103
- const char = argsString[i];
104
-
105
- if (escaped) {
106
- current += char;
107
- escaped = false;
108
- continue;
109
- }
110
-
111
- if (char === "\\") {
112
- escaped = true;
113
- continue;
114
- }
115
-
116
- if (char === "'" || char === '"') {
117
- if (inQuote === char) {
118
- // End quote
119
- inQuote = null;
120
- } else if (inQuote === null) {
121
- // Start quote
122
- inQuote = char;
123
- } else {
124
- // Inside different quote type, treat as literal
125
- current += char;
126
- }
127
- continue;
128
- }
129
-
130
- if (char === " " && inQuote === null) {
131
- // Whitespace outside quotes = separator
132
- if (current.length > 0) {
133
- args.push(current);
134
- current = "";
135
- }
136
- continue;
137
- }
138
-
139
- current += char;
140
- }
141
-
142
- // Add final argument
143
- if (current.length > 0) {
144
- args.push(current);
145
- }
146
-
147
- return args;
148
- }
149
-
150
- async execute(match: CommandMatch): Promise<boolean> {
151
- if (match.needsSubcommand) {
152
- return false;
153
- }
154
-
155
- const args = match.args ? this.parseArgs(match.args) : [];
156
- const executor = match.subcommand || match.command;
157
-
158
- if (executor.requiresArgument && args.length === 0) {
159
- return false;
160
- }
161
-
162
- if (match.subcommand?.execute) {
163
- await match.subcommand.execute(args);
164
- return true;
165
- }
166
-
167
- if (match.command.execute) {
168
- await match.command.execute(args);
169
- return true;
170
- }
171
-
172
- return false;
173
- }
174
-
175
- match(input: string, mode?: ComposerMode): CommandMatch | null {
176
- const trimmed = input.trim();
177
-
178
- if (mode !== undefined && !trimmed.startsWith("/")) {
179
- return this.matchByAlias(trimmed, mode);
180
- }
181
-
182
- if (!trimmed.startsWith("/")) {
183
- return null;
184
- }
185
-
186
- const parts = trimmed.slice(1).split(/\s+/).filter(Boolean);
187
- if (parts.length === 0) {
188
- return null;
189
- }
190
-
191
- const [commandId, ...argParts] = parts;
192
- const command = this.commands.get(commandId);
193
-
194
- if (!command) {
195
- return null;
196
- }
197
-
198
- return this.buildCommandMatch(command, argParts);
199
- }
200
-
201
- search(query: string): CommandDefinition[] {
202
- const lowerQuery = query.toLowerCase();
203
- if (!query) {
204
- return this.getAll();
205
- }
206
-
207
- return this.getAll().filter((cmd) => {
208
- const idMatch = cmd.id.toLowerCase().includes(lowerQuery);
209
- const descMatch = cmd.description.toLowerCase().includes(lowerQuery);
210
- const usageMatch = cmd.usage.toLowerCase().includes(lowerQuery);
211
- return idMatch || descMatch || usageMatch;
212
- });
213
- }
214
-
215
- searchSubcommands(command: CommandDefinition, query: string): SubcommandDefinition[] {
216
- if (!command.subcommands) {
217
- return [];
218
- }
219
-
220
- const lowerQuery = query.toLowerCase();
221
- if (!query) {
222
- return command.subcommands;
223
- }
224
-
225
- return command.subcommands.filter((sub) => {
226
- const idMatch = sub.id.toLowerCase().includes(lowerQuery);
227
- const descMatch = sub.description.toLowerCase().includes(lowerQuery);
228
- return idMatch || descMatch;
229
- });
230
- }
231
- }
232
-
233
- export const commandRegistry = new CommandRegistry();
@@ -1,33 +0,0 @@
1
- import { ComposerMode } from "../types.js";
2
-
3
- export type CommandCompletionProvider = (query: string) => Promise<string[]> | string[];
4
-
5
- export type CommandAlias = string[] | Partial<Record<ComposerMode, string[]>>;
6
-
7
- export interface SubcommandDefinition {
8
- id: string;
9
- description: string;
10
- usage: string;
11
- requiresArgument?: boolean;
12
- completionProvider?: CommandCompletionProvider;
13
- execute: (args: string[]) => Promise<void> | void;
14
- }
15
-
16
- export interface CommandDefinition {
17
- id: string;
18
- description: string;
19
- usage: string;
20
- requiresArgument?: boolean;
21
- completionProvider?: CommandCompletionProvider;
22
- subcommands?: SubcommandDefinition[];
23
- execute?: (args: string[]) => Promise<void> | void;
24
- alias?: CommandAlias;
25
- }
26
-
27
- export interface CommandMatch {
28
- command: CommandDefinition;
29
- subcommand?: SubcommandDefinition;
30
- args: string;
31
- query: string;
32
- needsSubcommand?: boolean;
33
- }
@@ -1,88 +0,0 @@
1
- import { createContext, use, useMemo, useRef, useState } from "react";
2
-
3
- import type { TextBuffer } from "../../lib/text-buffer.js";
4
- import type { FileAttachment } from "../../lib/types.js";
5
-
6
- import { useAgent } from "../../hooks/use-agent.js";
7
- import { ComposerMode } from "./types.js";
8
-
9
- export type ComposerActivity = "idle" | "pending" | "error";
10
-
11
- type ComposerContextValue = {
12
- prompt: string;
13
- setPrompt: (v: string) => void;
14
- mode: ComposerMode;
15
- setMode: (m: ComposerMode) => void;
16
- bufferRef: React.RefObject<TextBuffer | null>;
17
- activity: ComposerActivity;
18
- setActivity: (s: ComposerActivity) => void;
19
- queuedMessages: string[];
20
- addToQueue: (message: string) => void;
21
- removeFirstFromQueue: () => void;
22
- clearQueue: () => void;
23
- attachments: FileAttachment[];
24
- setAttachments: (a: FileAttachment[]) => void;
25
- addAttachment: (a: FileAttachment) => void;
26
- clearAttachments: () => void;
27
- };
28
-
29
- const ComposerContext = createContext<ComposerContextValue | null>(null);
30
-
31
- export function useComposerContext() {
32
- const ctx = use(ComposerContext);
33
- if (!ctx) {
34
- throw new Error(`${useComposerContext.name} must be used within ${ComposerProvider.name}`);
35
- }
36
- return ctx;
37
- }
38
-
39
- export function ComposerProvider({ children }: React.PropsWithChildren) {
40
- const [prompt, setPrompt] = useState("");
41
- const [mode, setMode] = useState(ComposerMode.Prompt);
42
- const bufferRef = useRef<TextBuffer>(null);
43
- const [activity, setActivity] = useState<ComposerActivity>("idle");
44
-
45
- // Use queue from AgentContext instead of local state
46
- const { queuedMessages, addToQueue, removeFirstFromQueue, clearQueue } = useAgent();
47
- const [attachments, setAttachments] = useState<FileAttachment[]>([]);
48
-
49
- const addAttachment = (attachment: FileAttachment) => {
50
- setAttachments((prev) => [...prev, attachment]);
51
- };
52
-
53
- const clearAttachments = () => {
54
- setAttachments([]);
55
- };
56
-
57
- const value = useMemo<ComposerContextValue>(
58
- () => ({
59
- prompt,
60
- setPrompt,
61
- mode,
62
- setMode,
63
- bufferRef,
64
- activity,
65
- setActivity,
66
- queuedMessages,
67
- addToQueue,
68
- removeFirstFromQueue,
69
- clearQueue,
70
- attachments,
71
- setAttachments,
72
- addAttachment,
73
- clearAttachments,
74
- }),
75
- [
76
- prompt,
77
- mode,
78
- activity,
79
- queuedMessages,
80
- addToQueue,
81
- removeFirstFromQueue,
82
- clearQueue,
83
- attachments,
84
- ],
85
- );
86
-
87
- return <ComposerContext.Provider value={value}>{children}</ComposerContext.Provider>;
88
- }
@@ -1,83 +0,0 @@
1
- import { View, Text } from "@codellm/jar";
2
- import { memo, useCallback, useDeferredValue, useEffect, useState } from "react";
3
-
4
- import { Select } from "../ui/select.js";
5
- import { useComposerContext } from "./context.js";
6
- import { getMentionAtCursor } from "./mentions.js";
7
- import { useMentionSearch } from "./use-mention-search.js";
8
-
9
- export const FileMentionPicker = memo(
10
- ({
11
- onAccept,
12
- onCancel,
13
- availableHeight,
14
- }: {
15
- onAccept: () => void;
16
- onCancel: () => void;
17
- availableHeight: number;
18
- }) => {
19
- const { prompt, bufferRef } = useComposerContext();
20
- const [fileQuery, setFileQuery] = useState("");
21
-
22
- useEffect(() => {
23
- const buffer = bufferRef.current;
24
- if (!buffer) {
25
- setFileQuery("");
26
- return;
27
- }
28
- const mention = getMentionAtCursor(buffer.text, buffer.cursor);
29
- const newQuery = mention?.query ?? "";
30
- setFileQuery((prev) => (prev !== newQuery ? newQuery : prev));
31
- }, [bufferRef, prompt]);
32
-
33
- const deferredFileQuery = useDeferredValue(fileQuery);
34
- const { results, isDirectory } = useMentionSearch(deferredFileQuery);
35
- const isSearching = fileQuery !== deferredFileQuery;
36
-
37
- const displayResults = results.map((path, idx) => (isDirectory[idx] ? `${path}/` : path));
38
-
39
- const handleSubmit = useCallback(
40
- (item: string, idx: number) => {
41
- const buffer = bufferRef.current;
42
- if (!buffer) return onAccept();
43
- const mention = getMentionAtCursor(buffer.text, buffer.cursor);
44
- if (mention) {
45
- const actualPath = results[idx];
46
- buffer.replaceRange(
47
- mention.startRow,
48
- mention.startCol,
49
- mention.endRow,
50
- mention.endCol,
51
- `@${actualPath}${isDirectory[idx] ? "/" : ""} `,
52
- );
53
- }
54
- onAccept();
55
- },
56
- [bufferRef, onAccept, results, isDirectory],
57
- );
58
-
59
- const limit = Math.max(1, Math.min(10, availableHeight - 2));
60
-
61
- return (
62
- <View flexDirection="column">
63
- <Select
64
- items={displayResults}
65
- limit={limit}
66
- maxHeight={availableHeight}
67
- isActive
68
- showIndex
69
- showIndicators
70
- onSubmit={handleSubmit}
71
- onTab={handleSubmit}
72
- onCancel={onCancel}
73
- />
74
- {isSearching && (
75
- <View marginTop={0}>
76
- <Text dimColor>Searching...</Text>
77
- </View>
78
- )}
79
- </View>
80
- );
81
- },
82
- );
83
- FileMentionPicker.displayName = "FileMentionPicker";