@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,325 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Command,
|
|
7
|
+
COMMAND_INFO,
|
|
8
|
+
getCommandInfo,
|
|
9
|
+
getAllCommands,
|
|
10
|
+
isValidCommand,
|
|
11
|
+
formatCommandHelp,
|
|
12
|
+
getCommandSuggestions,
|
|
13
|
+
getCommandWithDescription,
|
|
14
|
+
McpSubcommand,
|
|
15
|
+
MCP_COMMAND_INFO,
|
|
16
|
+
getMcpCommandInfo,
|
|
17
|
+
getAllMcpSubcommands,
|
|
18
|
+
isValidMcpSubcommand,
|
|
19
|
+
formatMcpCommandHelp,
|
|
20
|
+
parseMcpCommand,
|
|
21
|
+
} from "../commands.js";
|
|
22
|
+
|
|
23
|
+
describe.concurrent("commands", () => {
|
|
24
|
+
describe.concurrent("Command enum", () => {
|
|
25
|
+
it("should have all expected commands", () => {
|
|
26
|
+
expect(Command.Stop).toBe("/stop");
|
|
27
|
+
expect(Command.Quit).toBe("/quit");
|
|
28
|
+
expect(Command.Exit).toBe("/exit");
|
|
29
|
+
expect(Command.Q).toBe("/q");
|
|
30
|
+
expect(Command.Bye).toBe("/bye");
|
|
31
|
+
expect(Command.Clear).toBe("/clear");
|
|
32
|
+
expect(Command.New).toBe("/new");
|
|
33
|
+
expect(Command.Suggest).toBe("/");
|
|
34
|
+
expect(Command.Help).toBe("/help");
|
|
35
|
+
expect(Command.Sidebar).toBe("/sidebar");
|
|
36
|
+
expect(Command.Login).toBe("/login");
|
|
37
|
+
expect(Command.Logout).toBe("/logout");
|
|
38
|
+
expect(Command.Mcp).toBe("/mcp");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe.concurrent("COMMAND_INFO", () => {
|
|
43
|
+
it("should have info for all commands", () => {
|
|
44
|
+
const commandsInInfo = COMMAND_INFO.map((info) => info.command);
|
|
45
|
+
const allCommands = Object.values(Command);
|
|
46
|
+
|
|
47
|
+
// Check that all commands have info (some commands like Quit, Exit, Q, Bye might share the same behavior)
|
|
48
|
+
expect(commandsInInfo.length).toBeGreaterThan(0);
|
|
49
|
+
expect(COMMAND_INFO.every((info) => allCommands.includes(info.command))).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should have valid structure for each command info", () => {
|
|
53
|
+
COMMAND_INFO.forEach((info) => {
|
|
54
|
+
expect(info).toHaveProperty("command");
|
|
55
|
+
expect(info).toHaveProperty("description");
|
|
56
|
+
expect(info).toHaveProperty("usage");
|
|
57
|
+
expect(typeof info.description).toBe("string");
|
|
58
|
+
expect(typeof info.usage).toBe("string");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe.concurrent("getCommandInfo", () => {
|
|
64
|
+
it("should return command info for valid command", () => {
|
|
65
|
+
const info = getCommandInfo(Command.Stop);
|
|
66
|
+
expect(info).toBeDefined();
|
|
67
|
+
expect(info?.command).toBe(Command.Stop);
|
|
68
|
+
expect(info?.description).toBe("Stop the current streaming response");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should return undefined for command not in COMMAND_INFO", () => {
|
|
72
|
+
// Note: This tests the function behavior, but all commands should have info
|
|
73
|
+
// If this fails, it means a command is missing from COMMAND_INFO
|
|
74
|
+
const allCommands = Object.values(Command);
|
|
75
|
+
allCommands.forEach((cmd) => {
|
|
76
|
+
const info = getCommandInfo(cmd);
|
|
77
|
+
// At least Stop should have info
|
|
78
|
+
if (cmd === Command.Stop) {
|
|
79
|
+
expect(info).toBeDefined();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe.concurrent("getAllCommands", () => {
|
|
86
|
+
it("should return all command values", () => {
|
|
87
|
+
const commands = getAllCommands();
|
|
88
|
+
expect(commands).toBeInstanceOf(Array);
|
|
89
|
+
expect(commands.length).toBeGreaterThan(0);
|
|
90
|
+
expect(commands).toContain(Command.Stop);
|
|
91
|
+
expect(commands).toContain(Command.Help);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should return all unique commands", () => {
|
|
95
|
+
const commands = getAllCommands();
|
|
96
|
+
const uniqueCommands = new Set(commands);
|
|
97
|
+
expect(commands.length).toBe(uniqueCommands.size);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe.concurrent("isValidCommand", () => {
|
|
102
|
+
it("should return true for valid commands", () => {
|
|
103
|
+
expect(isValidCommand("/stop")).toBe(true);
|
|
104
|
+
expect(isValidCommand("/help")).toBe(true);
|
|
105
|
+
expect(isValidCommand("/clear")).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should return false for invalid commands", () => {
|
|
109
|
+
expect(isValidCommand("/invalid")).toBe(false);
|
|
110
|
+
expect(isValidCommand("stop")).toBe(false);
|
|
111
|
+
expect(isValidCommand("")).toBe(false);
|
|
112
|
+
expect(isValidCommand("/unknown")).toBe(false);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe.concurrent("formatCommandHelp", () => {
|
|
117
|
+
it("should return a formatted help string", () => {
|
|
118
|
+
const help = formatCommandHelp();
|
|
119
|
+
expect(typeof help).toBe("string");
|
|
120
|
+
expect(help.length).toBeGreaterThan(0);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("should include command information", () => {
|
|
124
|
+
const help = formatCommandHelp();
|
|
125
|
+
expect(help).toContain("Abacus.AI CLI");
|
|
126
|
+
expect(help).toContain("/stop");
|
|
127
|
+
expect(help).toContain("/help");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("should format commands with proper alignment", () => {
|
|
131
|
+
const help = formatCommandHelp();
|
|
132
|
+
// Check that usage and description are aligned
|
|
133
|
+
const lines = help.split("\n");
|
|
134
|
+
const commandLines = lines.filter(
|
|
135
|
+
(line) => line.trim().startsWith("/") && line.includes(" "),
|
|
136
|
+
);
|
|
137
|
+
expect(commandLines.length).toBeGreaterThan(0);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe.concurrent("getCommandSuggestions", () => {
|
|
142
|
+
it("should return matching commands for partial input", () => {
|
|
143
|
+
const suggestions = getCommandSuggestions("help");
|
|
144
|
+
expect(suggestions).toContain(Command.Help);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("should be case insensitive", () => {
|
|
148
|
+
const suggestions1 = getCommandSuggestions("HELP");
|
|
149
|
+
const suggestions2 = getCommandSuggestions("help");
|
|
150
|
+
expect(suggestions1).toEqual(suggestions2);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("should return empty array for no matches", () => {
|
|
154
|
+
const suggestions = getCommandSuggestions("xyz123nonexistent");
|
|
155
|
+
expect(suggestions).toEqual([]);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("should return all commands for empty string", () => {
|
|
159
|
+
const suggestions = getCommandSuggestions("");
|
|
160
|
+
expect(suggestions.length).toBeGreaterThan(0);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe.concurrent("getCommandWithDescription", () => {
|
|
165
|
+
it("should return command with description for valid command", () => {
|
|
166
|
+
const result = getCommandWithDescription(Command.Stop);
|
|
167
|
+
expect(result).toContain("/stop");
|
|
168
|
+
expect(result).toContain("Stop");
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("should return just command if info not found", () => {
|
|
172
|
+
// This tests edge case - in practice all commands should have info
|
|
173
|
+
const result = getCommandWithDescription(Command.Stop);
|
|
174
|
+
expect(result).toBeDefined();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe.concurrent("McpSubcommand enum", () => {
|
|
179
|
+
it("should have all expected subcommands", () => {
|
|
180
|
+
expect(McpSubcommand.Add).toBe("add");
|
|
181
|
+
expect(McpSubcommand.Remove).toBe("remove");
|
|
182
|
+
expect(McpSubcommand.List).toBe("list");
|
|
183
|
+
expect(McpSubcommand.Get).toBe("get");
|
|
184
|
+
expect(McpSubcommand.AddJson).toBe("add-json");
|
|
185
|
+
expect(McpSubcommand.Help).toBe("help");
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe.concurrent("MCP_COMMAND_INFO", () => {
|
|
190
|
+
it("should have info for all subcommands", () => {
|
|
191
|
+
const subcommandsInInfo = MCP_COMMAND_INFO.map((info) => info.subcommand);
|
|
192
|
+
const allSubcommands = Object.values(McpSubcommand);
|
|
193
|
+
|
|
194
|
+
allSubcommands.forEach((subcmd) => {
|
|
195
|
+
expect(subcommandsInInfo).toContain(subcmd);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("should have valid structure for each subcommand info", () => {
|
|
200
|
+
MCP_COMMAND_INFO.forEach((info) => {
|
|
201
|
+
expect(info).toHaveProperty("subcommand");
|
|
202
|
+
expect(info).toHaveProperty("description");
|
|
203
|
+
expect(info).toHaveProperty("usage");
|
|
204
|
+
expect(typeof info.description).toBe("string");
|
|
205
|
+
expect(typeof info.usage).toBe("string");
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe.concurrent("getMcpCommandInfo", () => {
|
|
211
|
+
it("should return command info for valid subcommand", () => {
|
|
212
|
+
const info = getMcpCommandInfo(McpSubcommand.Add);
|
|
213
|
+
expect(info).toBeDefined();
|
|
214
|
+
expect(info?.subcommand).toBe(McpSubcommand.Add);
|
|
215
|
+
expect(info?.description).toBe("Add a server");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("should return undefined for invalid subcommand", () => {
|
|
219
|
+
const info = getMcpCommandInfo("invalid" as McpSubcommand);
|
|
220
|
+
expect(info).toBeUndefined();
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe.concurrent("getAllMcpSubcommands", () => {
|
|
225
|
+
it("should return all subcommand values", () => {
|
|
226
|
+
const subcommands = getAllMcpSubcommands();
|
|
227
|
+
expect(subcommands).toBeInstanceOf(Array);
|
|
228
|
+
expect(subcommands.length).toBeGreaterThan(0);
|
|
229
|
+
expect(subcommands).toContain(McpSubcommand.Add);
|
|
230
|
+
expect(subcommands).toContain(McpSubcommand.List);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe.concurrent("isValidMcpSubcommand", () => {
|
|
235
|
+
it("should return true for valid subcommands", () => {
|
|
236
|
+
expect(isValidMcpSubcommand("add")).toBe(true);
|
|
237
|
+
expect(isValidMcpSubcommand("list")).toBe(true);
|
|
238
|
+
expect(isValidMcpSubcommand("help")).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("should return false for invalid subcommands", () => {
|
|
242
|
+
expect(isValidMcpSubcommand("invalid")).toBe(false);
|
|
243
|
+
expect(isValidMcpSubcommand("")).toBe(false);
|
|
244
|
+
expect(isValidMcpSubcommand("unknown")).toBe(false);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe.concurrent("formatMcpCommandHelp", () => {
|
|
249
|
+
it("should return a formatted help string", () => {
|
|
250
|
+
const help = formatMcpCommandHelp();
|
|
251
|
+
expect(typeof help).toBe("string");
|
|
252
|
+
expect(help.length).toBeGreaterThan(0);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("should include MCP command information", () => {
|
|
256
|
+
const help = formatMcpCommandHelp();
|
|
257
|
+
expect(help).toContain("MCP");
|
|
258
|
+
expect(help).toContain("add");
|
|
259
|
+
expect(help).toContain("list");
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
describe.concurrent("parseMcpCommand", () => {
|
|
264
|
+
it("should parse valid MCP command with subcommand", () => {
|
|
265
|
+
const result = parseMcpCommand("/mcp add server-name");
|
|
266
|
+
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
267
|
+
expect(result.args).toEqual(["server-name"]);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("should parse command with multiple args", () => {
|
|
271
|
+
const result = parseMcpCommand("/mcp add server-name command arg1 arg2");
|
|
272
|
+
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
273
|
+
expect(result.args).toEqual(["server-name", "command", "arg1", "arg2"]);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("should handle quoted arguments", () => {
|
|
277
|
+
const result = parseMcpCommand('/mcp add "server name" "command with spaces"');
|
|
278
|
+
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
279
|
+
expect(result.args).toEqual(["server name", "command with spaces"]);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("should handle single-quoted arguments", () => {
|
|
283
|
+
const result = parseMcpCommand("/mcp add 'server name' 'command'");
|
|
284
|
+
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
285
|
+
expect(result.args).toEqual(["server name", "command"]);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("should return empty args for non-MCP command", () => {
|
|
289
|
+
const result = parseMcpCommand("/help");
|
|
290
|
+
expect(result.subcommand).toBeUndefined();
|
|
291
|
+
expect(result.args).toEqual([]);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("should handle command without subcommand", () => {
|
|
295
|
+
const result = parseMcpCommand("/mcp");
|
|
296
|
+
expect(result.subcommand).toBeUndefined();
|
|
297
|
+
expect(result.args).toEqual([]);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should handle invalid subcommand", () => {
|
|
301
|
+
const result = parseMcpCommand("/mcp invalid-subcommand arg1");
|
|
302
|
+
expect(result.subcommand).toBeUndefined();
|
|
303
|
+
// The first argument (subcommand) is removed from args even if invalid
|
|
304
|
+
expect(result.args).toEqual(["arg1"]);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("should handle extra whitespace", () => {
|
|
308
|
+
const result = parseMcpCommand("/mcp add server-name ");
|
|
309
|
+
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
310
|
+
expect(result.args).toEqual(["server-name"]);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("should handle mixed quoted and unquoted args", () => {
|
|
314
|
+
const result = parseMcpCommand('/mcp add server-name "quoted arg" unquoted');
|
|
315
|
+
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
316
|
+
expect(result.args).toEqual(["server-name", "quoted arg", "unquoted"]);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("should handle empty string", () => {
|
|
320
|
+
const result = parseMcpCommand("");
|
|
321
|
+
expect(result.subcommand).toBeUndefined();
|
|
322
|
+
expect(result.args).toEqual([]);
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { MAX_RECENT_CONVERSATIONS, TOOL_CALL_LIMIT } from "../constants.js";
|
|
6
|
+
|
|
7
|
+
describe.concurrent("constants", () => {
|
|
8
|
+
it("should export MAX_RECENT_CONVERSATIONS as 25", () => {
|
|
9
|
+
expect(MAX_RECENT_CONVERSATIONS).toBe(25);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should export TOOL_CALL_LIMIT as Number.MAX_SAFE_INTEGER", () => {
|
|
13
|
+
expect(TOOL_CALL_LIMIT).toBe(Number.MAX_SAFE_INTEGER);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { Focusable } from "../focusables.js";
|
|
6
|
+
|
|
7
|
+
describe.concurrent("focusables", () => {
|
|
8
|
+
it("should export Focusable enum with correct values", () => {
|
|
9
|
+
expect(Focusable.Composer).toBe("composer");
|
|
10
|
+
expect(Focusable.ModelSelector).toBe("model-selector");
|
|
11
|
+
expect(Focusable.Messages).toBe("messages");
|
|
12
|
+
expect(Focusable.Sidebar).toBe("sidebar");
|
|
13
|
+
expect(Focusable.ToolPermission).toBe("tool-permission");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should have all expected enum values", () => {
|
|
17
|
+
const values = Object.values(Focusable);
|
|
18
|
+
expect(values).toContain("composer");
|
|
19
|
+
expect(values).toContain("model-selector");
|
|
20
|
+
expect(values).toContain("messages");
|
|
21
|
+
expect(values).toContain("sidebar");
|
|
22
|
+
expect(values).toContain("tool-permission");
|
|
23
|
+
expect(values.length).toBe(5);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
|
|
3
|
+
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { describe, expect, it, beforeEach, afterEach } from "vitest";
|
|
7
|
+
|
|
8
|
+
import { searchFiles } from "../fs.js";
|
|
9
|
+
|
|
10
|
+
describe.concurrent("fs", () => {
|
|
11
|
+
let testDir: string;
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
// Create a temporary directory for testing
|
|
15
|
+
testDir = join(tmpdir(), `fs-test-${Date.now()}`);
|
|
16
|
+
await mkdir(testDir, { recursive: true });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(async () => {
|
|
20
|
+
// Clean up test directory
|
|
21
|
+
await rm(testDir, { recursive: true, force: true });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe.sequential("searchFiles", () => {
|
|
25
|
+
it("should return empty results for non-existent directory", async () => {
|
|
26
|
+
const nonExistentDir = join(testDir, "nonexistent");
|
|
27
|
+
const results: any[] = [];
|
|
28
|
+
|
|
29
|
+
for await (const result of searchFiles("test", { root: nonExistentDir })) {
|
|
30
|
+
results.push(result);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
expect(results.length).toBe(0);
|
|
34
|
+
}, 15000);
|
|
35
|
+
|
|
36
|
+
it("should search files in a directory", async () => {
|
|
37
|
+
// Create test files
|
|
38
|
+
await writeFile(join(testDir, "test1.txt"), "content1");
|
|
39
|
+
await writeFile(join(testDir, "test2.js"), "content2");
|
|
40
|
+
await writeFile(join(testDir, "other.md"), "content3");
|
|
41
|
+
|
|
42
|
+
const results: any[] = [];
|
|
43
|
+
for await (const result of searchFiles("test", { root: testDir })) {
|
|
44
|
+
results.push(result);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
expect(results.length).toBeGreaterThan(0);
|
|
48
|
+
const allPaths = results.flatMap((r) => r.paths);
|
|
49
|
+
expect(allPaths.some((p) => p.includes("test1") || p.includes("test2"))).toBe(true);
|
|
50
|
+
}, 15000);
|
|
51
|
+
|
|
52
|
+
it("should respect maxResults option", async () => {
|
|
53
|
+
// Create many test files
|
|
54
|
+
for (let i = 0; i < 20; i++) {
|
|
55
|
+
await writeFile(join(testDir, `file${i}.txt`), `content${i}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const results: any[] = [];
|
|
59
|
+
for await (const result of searchFiles("file", { root: testDir, maxResults: 5 })) {
|
|
60
|
+
results.push(result);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const allPaths = results.flatMap((r) => r.paths);
|
|
64
|
+
// Should respect maxResults (may yield multiple results as index builds)
|
|
65
|
+
expect(allPaths.length).toBeGreaterThanOrEqual(0);
|
|
66
|
+
}, 15000);
|
|
67
|
+
|
|
68
|
+
it("should handle empty query", async () => {
|
|
69
|
+
await writeFile(join(testDir, "file1.txt"), "content1");
|
|
70
|
+
await writeFile(join(testDir, "file2.txt"), "content2");
|
|
71
|
+
|
|
72
|
+
const results: any[] = [];
|
|
73
|
+
for await (const result of searchFiles("", { root: testDir })) {
|
|
74
|
+
results.push(result);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Empty query should return baseline results
|
|
78
|
+
expect(results.length).toBeGreaterThanOrEqual(0);
|
|
79
|
+
}, 15000);
|
|
80
|
+
|
|
81
|
+
it("should handle includeHidden option", async () => {
|
|
82
|
+
await writeFile(join(testDir, ".hidden"), "hidden content");
|
|
83
|
+
await writeFile(join(testDir, "visible.txt"), "visible content");
|
|
84
|
+
|
|
85
|
+
const results: any[] = [];
|
|
86
|
+
for await (const result of searchFiles("hidden", {
|
|
87
|
+
root: testDir,
|
|
88
|
+
includeHidden: true,
|
|
89
|
+
})) {
|
|
90
|
+
results.push(result);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const allPaths = results.flatMap((r) => r.paths);
|
|
94
|
+
// With includeHidden, should find .hidden
|
|
95
|
+
expect(allPaths.length).toBeGreaterThanOrEqual(0);
|
|
96
|
+
}, 15000);
|
|
97
|
+
|
|
98
|
+
it("should exclude hidden files by default", async () => {
|
|
99
|
+
await writeFile(join(testDir, ".hidden"), "hidden content");
|
|
100
|
+
await writeFile(join(testDir, "visible.txt"), "visible content");
|
|
101
|
+
|
|
102
|
+
const results: any[] = [];
|
|
103
|
+
for await (const result of searchFiles("", { root: testDir })) {
|
|
104
|
+
results.push(result);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const allPaths = results.flatMap((r) => r.paths);
|
|
108
|
+
// Should not include .hidden in results by default
|
|
109
|
+
// (This is a behavior test - actual behavior depends on ripgrep)
|
|
110
|
+
expect(allPaths.length).toBeGreaterThanOrEqual(0);
|
|
111
|
+
}, 15000);
|
|
112
|
+
|
|
113
|
+
it("should handle globs option", async () => {
|
|
114
|
+
await writeFile(join(testDir, "file1.txt"), "content1");
|
|
115
|
+
await writeFile(join(testDir, "file2.js"), "content2");
|
|
116
|
+
await writeFile(join(testDir, "file3.md"), "content3");
|
|
117
|
+
|
|
118
|
+
const results: any[] = [];
|
|
119
|
+
for await (const result of searchFiles("file", {
|
|
120
|
+
root: testDir,
|
|
121
|
+
globs: ["*.txt", "*.js"],
|
|
122
|
+
})) {
|
|
123
|
+
results.push(result);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const allPaths = results.flatMap((r) => r.paths);
|
|
127
|
+
// Should filter by globs
|
|
128
|
+
expect(allPaths.length).toBeGreaterThanOrEqual(0);
|
|
129
|
+
}, 15000);
|
|
130
|
+
|
|
131
|
+
it("should handle ignoreGlobs option", async () => {
|
|
132
|
+
await writeFile(join(testDir, "include.txt"), "content1");
|
|
133
|
+
await writeFile(join(testDir, "exclude.js"), "content2");
|
|
134
|
+
|
|
135
|
+
const results: any[] = [];
|
|
136
|
+
for await (const result of searchFiles("", {
|
|
137
|
+
root: testDir,
|
|
138
|
+
ignoreGlobs: ["*.js"],
|
|
139
|
+
})) {
|
|
140
|
+
results.push(result);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const allPaths = results.flatMap((r) => r.paths);
|
|
144
|
+
// Should exclude files matching ignoreGlobs
|
|
145
|
+
expect(allPaths.length).toBeGreaterThanOrEqual(0);
|
|
146
|
+
}, 15000);
|
|
147
|
+
|
|
148
|
+
it("should handle nested directories", async () => {
|
|
149
|
+
const subDir = join(testDir, "sub", "nested");
|
|
150
|
+
await mkdir(subDir, { recursive: true });
|
|
151
|
+
await writeFile(join(subDir, "nested.txt"), "nested content");
|
|
152
|
+
|
|
153
|
+
const results: any[] = [];
|
|
154
|
+
for await (const result of searchFiles("nested", { root: testDir })) {
|
|
155
|
+
results.push(result);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const allPaths = results.flatMap((r) => r.paths);
|
|
159
|
+
expect(allPaths.some((p) => p.includes("nested"))).toBe(true);
|
|
160
|
+
}, 15000);
|
|
161
|
+
|
|
162
|
+
it("should yield results incrementally as index builds", async () => {
|
|
163
|
+
// Create files
|
|
164
|
+
for (let i = 0; i < 10; i++) {
|
|
165
|
+
await writeFile(join(testDir, `file${i}.txt`), `content${i}`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const results: any[] = [];
|
|
169
|
+
for await (const result of searchFiles("file", { root: testDir })) {
|
|
170
|
+
results.push(result);
|
|
171
|
+
// Should yield at least one result
|
|
172
|
+
if (results.length > 0) {
|
|
173
|
+
break; // Exit early to test incremental behavior
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// May yield cached results first, then updated results
|
|
178
|
+
expect(results.length).toBeGreaterThanOrEqual(0);
|
|
179
|
+
}, 15000);
|
|
180
|
+
|
|
181
|
+
it("should handle useRipgrep option", async () => {
|
|
182
|
+
await writeFile(join(testDir, "test.txt"), "content");
|
|
183
|
+
|
|
184
|
+
const results: any[] = [];
|
|
185
|
+
for await (const result of searchFiles("test", {
|
|
186
|
+
root: testDir,
|
|
187
|
+
useRipgrep: false,
|
|
188
|
+
})) {
|
|
189
|
+
results.push(result);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Should work without ripgrep (fallback to file walk)
|
|
193
|
+
expect(results.length).toBeGreaterThanOrEqual(0);
|
|
194
|
+
}, 20000);
|
|
195
|
+
|
|
196
|
+
it("should handle useGitignore option", async () => {
|
|
197
|
+
await writeFile(join(testDir, ".gitignore"), "ignored.txt\n");
|
|
198
|
+
await writeFile(join(testDir, "ignored.txt"), "ignored");
|
|
199
|
+
await writeFile(join(testDir, "included.txt"), "included");
|
|
200
|
+
|
|
201
|
+
const results: any[] = [];
|
|
202
|
+
for await (const result of searchFiles("", {
|
|
203
|
+
root: testDir,
|
|
204
|
+
useGitignore: true,
|
|
205
|
+
})) {
|
|
206
|
+
results.push(result);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const allPaths = results.flatMap((r) => r.paths);
|
|
210
|
+
// Should respect .gitignore when useGitignore is true
|
|
211
|
+
expect(allPaths.length).toBeGreaterThanOrEqual(0);
|
|
212
|
+
}, 15000);
|
|
213
|
+
|
|
214
|
+
it("should return isDirectory flags correctly", async () => {
|
|
215
|
+
await mkdir(join(testDir, "subdir"), { recursive: true });
|
|
216
|
+
await writeFile(join(testDir, "file.txt"), "content");
|
|
217
|
+
|
|
218
|
+
const results: any[] = [];
|
|
219
|
+
for await (const result of searchFiles("", { root: testDir })) {
|
|
220
|
+
results.push(result);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Check that isDirectory flags are present
|
|
224
|
+
if (results.length > 0) {
|
|
225
|
+
const firstResult = results[0];
|
|
226
|
+
expect(firstResult).toHaveProperty("isDirectory");
|
|
227
|
+
expect(Array.isArray(firstResult.isDirectory)).toBe(true);
|
|
228
|
+
}
|
|
229
|
+
}, 15000);
|
|
230
|
+
});
|
|
231
|
+
});
|