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