@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.
- package/dist/index.mjs +450 -422
- package/package.json +4 -1
- package/.oxlintrc.json +0 -8
- package/resources/abacus.ico +0 -0
- package/resources/entitlements.plist +0 -9
- package/src/__e2e__/README.md +0 -196
- package/src/__e2e__/agent-interactions.e2e.test.tsx +0 -61
- package/src/__e2e__/cli-commands.e2e.test.tsx +0 -77
- package/src/__e2e__/conversation-throttle.e2e.test.ts +0 -453
- package/src/__e2e__/conversation.e2e.test.tsx +0 -56
- package/src/__e2e__/diff-preview.e2e.test.tsx +0 -3399
- package/src/__e2e__/file-creation.e2e.test.tsx +0 -149
- package/src/__e2e__/helpers/test-helpers.ts +0 -449
- package/src/__e2e__/keyboard-navigation.e2e.test.tsx +0 -34
- package/src/__e2e__/llm-models.e2e.test.ts +0 -402
- package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +0 -71
- package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +0 -167
- package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +0 -185
- package/src/__e2e__/repl.e2e.test.tsx +0 -78
- package/src/__e2e__/shell-compatibility.e2e.test.tsx +0 -76
- package/src/__e2e__/theme-mcp.e2e.test.tsx +0 -98
- package/src/__e2e__/tool-permissions.e2e.test.tsx +0 -66
- package/src/args.ts +0 -22
- package/src/components/__tests__/react-compiler.test.tsx +0 -78
- package/src/components/__tests__/status-indicator.test.tsx +0 -403
- package/src/components/composer/__tests__/bash-runner.test.tsx +0 -263
- package/src/components/composer/agent-mode-indicator.tsx +0 -63
- package/src/components/composer/bash-runner.tsx +0 -54
- package/src/components/composer/commands/default-commands.tsx +0 -615
- package/src/components/composer/commands/handler.tsx +0 -59
- package/src/components/composer/commands/picker.tsx +0 -273
- package/src/components/composer/commands/registry.ts +0 -233
- package/src/components/composer/commands/types.ts +0 -33
- package/src/components/composer/context.tsx +0 -88
- package/src/components/composer/file-mention-picker.tsx +0 -83
- package/src/components/composer/help.tsx +0 -44
- package/src/components/composer/index.tsx +0 -1007
- package/src/components/composer/mentions.ts +0 -57
- package/src/components/composer/message-queue.tsx +0 -70
- package/src/components/composer/mode-panel.tsx +0 -35
- package/src/components/composer/modes/__tests__/bash-handler.test.tsx +0 -755
- package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +0 -1108
- package/src/components/composer/modes/bash-handler.tsx +0 -132
- package/src/components/composer/modes/bash-renderer.tsx +0 -175
- package/src/components/composer/modes/default-handlers.tsx +0 -33
- package/src/components/composer/modes/index.ts +0 -41
- package/src/components/composer/modes/types.ts +0 -21
- package/src/components/composer/persistent-shell.ts +0 -283
- package/src/components/composer/process.ts +0 -65
- package/src/components/composer/types.ts +0 -9
- package/src/components/composer/use-mention-search.ts +0 -68
- package/src/components/error-boundry.tsx +0 -60
- package/src/components/exit-message.tsx +0 -29
- package/src/components/expanded-view.tsx +0 -74
- package/src/components/file-completion.tsx +0 -127
- package/src/components/header.tsx +0 -47
- package/src/components/logo.tsx +0 -37
- package/src/components/segments.tsx +0 -356
- package/src/components/status-indicator.tsx +0 -306
- package/src/components/tool-group-summary.tsx +0 -263
- package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +0 -319
- package/src/components/tool-permissions/diff-preview.tsx +0 -359
- package/src/components/tool-permissions/index.ts +0 -5
- package/src/components/tool-permissions/permission-options.tsx +0 -401
- package/src/components/tool-permissions/permission-preview-header.tsx +0 -57
- package/src/components/tool-permissions/tool-permission-ui.tsx +0 -420
- package/src/components/tools/agent/ask-user-question.tsx +0 -107
- package/src/components/tools/agent/enter-plan-mode.tsx +0 -55
- package/src/components/tools/agent/exit-plan-mode.tsx +0 -83
- package/src/components/tools/agent/handoff-to-main.tsx +0 -27
- package/src/components/tools/agent/subagent.tsx +0 -37
- package/src/components/tools/agent/todo-write.tsx +0 -104
- package/src/components/tools/browser/close-tab.tsx +0 -58
- package/src/components/tools/browser/computer.tsx +0 -70
- package/src/components/tools/browser/get-interactive-elements.tsx +0 -54
- package/src/components/tools/browser/get-tab-content.tsx +0 -51
- package/src/components/tools/browser/navigate-to.tsx +0 -59
- package/src/components/tools/browser/new-tab.tsx +0 -60
- package/src/components/tools/browser/perform-action.tsx +0 -63
- package/src/components/tools/browser/refresh-tab.tsx +0 -43
- package/src/components/tools/browser/switch-tab.tsx +0 -58
- package/src/components/tools/filesystem/delete-file.tsx +0 -104
- package/src/components/tools/filesystem/edit.tsx +0 -220
- package/src/components/tools/filesystem/list-dir.tsx +0 -78
- package/src/components/tools/filesystem/read-file.tsx +0 -180
- package/src/components/tools/filesystem/upload-image.tsx +0 -76
- package/src/components/tools/ide/ide-diagnostics.tsx +0 -62
- package/src/components/tools/index.ts +0 -91
- package/src/components/tools/mcp/mcp-tool.tsx +0 -158
- package/src/components/tools/search/fetch-url.tsx +0 -73
- package/src/components/tools/search/file-search.tsx +0 -78
- package/src/components/tools/search/grep.tsx +0 -90
- package/src/components/tools/search/semantic-search.tsx +0 -66
- package/src/components/tools/search/web-search.tsx +0 -71
- package/src/components/tools/shared/index.tsx +0 -48
- package/src/components/tools/shared/zod-coercion.ts +0 -35
- package/src/components/tools/terminal/bash-tool-output.tsx +0 -188
- package/src/components/tools/terminal/get-terminal-output.tsx +0 -91
- package/src/components/tools/terminal/run-in-terminal.tsx +0 -131
- package/src/components/tools/types.ts +0 -16
- package/src/components/tools.tsx +0 -68
- package/src/components/ui/__tests__/divider.test.tsx +0 -61
- package/src/components/ui/__tests__/gradient.test.tsx +0 -125
- package/src/components/ui/__tests__/input.test.tsx +0 -166
- package/src/components/ui/__tests__/select.test.tsx +0 -273
- package/src/components/ui/__tests__/shimmer.test.tsx +0 -99
- package/src/components/ui/blinking-indicator.tsx +0 -27
- package/src/components/ui/divider.tsx +0 -162
- package/src/components/ui/gradient.tsx +0 -56
- package/src/components/ui/input.tsx +0 -228
- package/src/components/ui/select.tsx +0 -151
- package/src/components/ui/shimmer.tsx +0 -76
- package/src/context/agent-mode.tsx +0 -95
- package/src/context/extension-file.tsx +0 -136
- package/src/context/network-activity.tsx +0 -45
- package/src/context/notification.tsx +0 -62
- package/src/context/shell-size.tsx +0 -49
- package/src/context/shell-title.tsx +0 -38
- package/src/entrypoints/print-mode.ts +0 -312
- package/src/entrypoints/repl.tsx +0 -389
- package/src/hooks/use-agent.ts +0 -15
- package/src/hooks/use-api-client.ts +0 -1
- package/src/hooks/use-available-height.ts +0 -8
- package/src/hooks/use-cleanup.ts +0 -29
- package/src/hooks/use-interrupt-manager.ts +0 -242
- package/src/hooks/use-models.ts +0 -22
- package/src/index.ts +0 -217
- package/src/lib/__tests__/ansi.test.ts +0 -255
- package/src/lib/__tests__/cli.test.ts +0 -122
- package/src/lib/__tests__/commands.test.ts +0 -325
- package/src/lib/__tests__/constants.test.ts +0 -15
- package/src/lib/__tests__/focusables.test.ts +0 -25
- package/src/lib/__tests__/fs.test.ts +0 -231
- package/src/lib/__tests__/markdown.test.tsx +0 -348
- package/src/lib/__tests__/mcpCommandHandler.test.ts +0 -173
- package/src/lib/__tests__/mcpManagement.test.ts +0 -38
- package/src/lib/__tests__/path-paste.test.ts +0 -144
- package/src/lib/__tests__/path.test.ts +0 -300
- package/src/lib/__tests__/queries.test.ts +0 -39
- package/src/lib/__tests__/standaloneMcpService.test.ts +0 -71
- package/src/lib/__tests__/text-buffer.test.ts +0 -328
- package/src/lib/__tests__/text-utils.test.ts +0 -32
- package/src/lib/__tests__/timing.test.ts +0 -78
- package/src/lib/__tests__/utils.test.ts +0 -238
- package/src/lib/__tests__/vim-buffer-actions.test.ts +0 -154
- package/src/lib/ansi.ts +0 -150
- package/src/lib/cli-push-server.ts +0 -112
- package/src/lib/cli.ts +0 -44
- package/src/lib/clipboard.ts +0 -226
- package/src/lib/command-utils.ts +0 -93
- package/src/lib/commands.ts +0 -270
- package/src/lib/constants.ts +0 -3
- package/src/lib/extension-connection.ts +0 -181
- package/src/lib/focusables.ts +0 -7
- package/src/lib/fs.ts +0 -533
- package/src/lib/markdown/code-block.tsx +0 -63
- package/src/lib/markdown/index.ts +0 -4
- package/src/lib/markdown/link.tsx +0 -19
- package/src/lib/markdown/markdown.tsx +0 -372
- package/src/lib/markdown/types.ts +0 -15
- package/src/lib/mcpCommandHandler.ts +0 -121
- package/src/lib/mcpManagement.ts +0 -44
- package/src/lib/path-paste.ts +0 -185
- package/src/lib/path.ts +0 -179
- package/src/lib/queries.ts +0 -15
- package/src/lib/standaloneMcpService.ts +0 -688
- package/src/lib/status-utils.ts +0 -237
- package/src/lib/test-utils.tsx +0 -72
- package/src/lib/text-buffer.ts +0 -2415
- package/src/lib/text-utils.ts +0 -272
- package/src/lib/timing.ts +0 -63
- package/src/lib/types.ts +0 -295
- package/src/lib/utils.ts +0 -182
- package/src/lib/vim-buffer-actions.ts +0 -732
- package/src/providers/agent.tsx +0 -1063
- package/src/providers/api-client.tsx +0 -43
- package/src/services/logger.ts +0 -85
- package/src/terminal/detection.ts +0 -187
- package/src/terminal/exit.ts +0 -279
- package/src/terminal/notification.ts +0 -83
- package/src/terminal/progress.ts +0 -201
- package/src/terminal/setup.ts +0 -797
- package/src/terminal/types.ts +0 -51
- package/src/theme/context.tsx +0 -57
- package/src/theme/index.ts +0 -4
- package/src/theme/themed.tsx +0 -35
- package/src/theme/themes.json +0 -546
- package/src/theme/types.ts +0 -110
- package/src/tools/types.ts +0 -59
- package/src/tools/utils/__tests__/zod-coercion.test.ts +0 -33
- package/src/tools/utils/tool-ui-components.tsx +0 -649
- package/src/tools/utils/zod-coercion.ts +0 -35
- package/tsconfig.json +0 -16
- package/tsconfig.node.json +0 -29
- package/tsconfig.test.json +0 -27
- package/tsdown.config.ts +0 -17
- 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";
|