@abacus-ai/cli 1.106.25008 → 2.0.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/.oxlintrc.json +8 -0
  2. package/dist/index.mjs +12823 -0
  3. package/package.json +7 -39
  4. package/resources/abacus.ico +0 -0
  5. package/resources/entitlements.plist +9 -0
  6. package/src/__e2e__/README.md +196 -0
  7. package/src/__e2e__/agent-interactions.e2e.test.tsx +61 -0
  8. package/src/__e2e__/cli-commands.e2e.test.tsx +77 -0
  9. package/src/__e2e__/conversation-throttle.e2e.test.ts +453 -0
  10. package/src/__e2e__/conversation.e2e.test.tsx +56 -0
  11. package/src/__e2e__/diff-preview.e2e.test.tsx +3399 -0
  12. package/src/__e2e__/file-creation.e2e.test.tsx +149 -0
  13. package/src/__e2e__/helpers/test-helpers.ts +449 -0
  14. package/src/__e2e__/keyboard-navigation.e2e.test.tsx +34 -0
  15. package/src/__e2e__/llm-models.e2e.test.ts +402 -0
  16. package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +71 -0
  17. package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +167 -0
  18. package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +185 -0
  19. package/src/__e2e__/repl.e2e.test.tsx +78 -0
  20. package/src/__e2e__/shell-compatibility.e2e.test.tsx +76 -0
  21. package/src/__e2e__/theme-mcp.e2e.test.tsx +98 -0
  22. package/src/__e2e__/tool-permissions.e2e.test.tsx +66 -0
  23. package/src/args.ts +22 -0
  24. package/src/components/__tests__/react-compiler.test.tsx +78 -0
  25. package/src/components/__tests__/status-indicator.test.tsx +403 -0
  26. package/src/components/composer/__tests__/bash-runner.test.tsx +263 -0
  27. package/src/components/composer/agent-mode-indicator.tsx +63 -0
  28. package/src/components/composer/bash-runner.tsx +54 -0
  29. package/src/components/composer/commands/default-commands.tsx +615 -0
  30. package/src/components/composer/commands/handler.tsx +59 -0
  31. package/src/components/composer/commands/picker.tsx +273 -0
  32. package/src/components/composer/commands/registry.ts +233 -0
  33. package/src/components/composer/commands/types.ts +33 -0
  34. package/src/components/composer/context.tsx +88 -0
  35. package/src/components/composer/file-mention-picker.tsx +83 -0
  36. package/src/components/composer/help.tsx +44 -0
  37. package/src/components/composer/index.tsx +1007 -0
  38. package/src/components/composer/mentions.ts +57 -0
  39. package/src/components/composer/message-queue.tsx +70 -0
  40. package/src/components/composer/mode-panel.tsx +35 -0
  41. package/src/components/composer/modes/__tests__/bash-handler.test.tsx +755 -0
  42. package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +1108 -0
  43. package/src/components/composer/modes/bash-handler.tsx +132 -0
  44. package/src/components/composer/modes/bash-renderer.tsx +175 -0
  45. package/src/components/composer/modes/default-handlers.tsx +33 -0
  46. package/src/components/composer/modes/index.ts +41 -0
  47. package/src/components/composer/modes/types.ts +21 -0
  48. package/src/components/composer/persistent-shell.ts +283 -0
  49. package/src/components/composer/process.ts +65 -0
  50. package/src/components/composer/types.ts +9 -0
  51. package/src/components/composer/use-mention-search.ts +68 -0
  52. package/src/components/error-boundry.tsx +60 -0
  53. package/src/components/exit-message.tsx +29 -0
  54. package/src/components/expanded-view.tsx +74 -0
  55. package/src/components/file-completion.tsx +127 -0
  56. package/src/components/header.tsx +47 -0
  57. package/src/components/logo.tsx +37 -0
  58. package/src/components/segments.tsx +356 -0
  59. package/src/components/status-indicator.tsx +306 -0
  60. package/src/components/tool-group-summary.tsx +263 -0
  61. package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +319 -0
  62. package/src/components/tool-permissions/diff-preview.tsx +359 -0
  63. package/src/components/tool-permissions/index.ts +5 -0
  64. package/src/components/tool-permissions/permission-options.tsx +401 -0
  65. package/src/components/tool-permissions/permission-preview-header.tsx +57 -0
  66. package/src/components/tool-permissions/tool-permission-ui.tsx +420 -0
  67. package/src/components/tools/agent/ask-user-question.tsx +107 -0
  68. package/src/components/tools/agent/enter-plan-mode.tsx +55 -0
  69. package/src/components/tools/agent/exit-plan-mode.tsx +83 -0
  70. package/src/components/tools/agent/handoff-to-main.tsx +27 -0
  71. package/src/components/tools/agent/subagent.tsx +37 -0
  72. package/src/components/tools/agent/todo-write.tsx +104 -0
  73. package/src/components/tools/browser/close-tab.tsx +58 -0
  74. package/src/components/tools/browser/computer.tsx +70 -0
  75. package/src/components/tools/browser/get-interactive-elements.tsx +54 -0
  76. package/src/components/tools/browser/get-tab-content.tsx +51 -0
  77. package/src/components/tools/browser/navigate-to.tsx +59 -0
  78. package/src/components/tools/browser/new-tab.tsx +60 -0
  79. package/src/components/tools/browser/perform-action.tsx +63 -0
  80. package/src/components/tools/browser/refresh-tab.tsx +43 -0
  81. package/src/components/tools/browser/switch-tab.tsx +58 -0
  82. package/src/components/tools/filesystem/delete-file.tsx +104 -0
  83. package/src/components/tools/filesystem/edit.tsx +220 -0
  84. package/src/components/tools/filesystem/list-dir.tsx +78 -0
  85. package/src/components/tools/filesystem/read-file.tsx +180 -0
  86. package/src/components/tools/filesystem/upload-image.tsx +76 -0
  87. package/src/components/tools/ide/ide-diagnostics.tsx +62 -0
  88. package/src/components/tools/index.ts +91 -0
  89. package/src/components/tools/mcp/mcp-tool.tsx +158 -0
  90. package/src/components/tools/search/fetch-url.tsx +73 -0
  91. package/src/components/tools/search/file-search.tsx +78 -0
  92. package/src/components/tools/search/grep.tsx +90 -0
  93. package/src/components/tools/search/semantic-search.tsx +66 -0
  94. package/src/components/tools/search/web-search.tsx +71 -0
  95. package/src/components/tools/shared/index.tsx +48 -0
  96. package/src/components/tools/shared/zod-coercion.ts +35 -0
  97. package/src/components/tools/terminal/bash-tool-output.tsx +188 -0
  98. package/src/components/tools/terminal/get-terminal-output.tsx +91 -0
  99. package/src/components/tools/terminal/run-in-terminal.tsx +131 -0
  100. package/src/components/tools/types.ts +16 -0
  101. package/src/components/tools.tsx +68 -0
  102. package/src/components/ui/__tests__/divider.test.tsx +61 -0
  103. package/src/components/ui/__tests__/gradient.test.tsx +125 -0
  104. package/src/components/ui/__tests__/input.test.tsx +166 -0
  105. package/src/components/ui/__tests__/select.test.tsx +273 -0
  106. package/src/components/ui/__tests__/shimmer.test.tsx +99 -0
  107. package/src/components/ui/blinking-indicator.tsx +27 -0
  108. package/src/components/ui/divider.tsx +162 -0
  109. package/src/components/ui/gradient.tsx +56 -0
  110. package/src/components/ui/input.tsx +228 -0
  111. package/src/components/ui/select.tsx +151 -0
  112. package/src/components/ui/shimmer.tsx +76 -0
  113. package/src/context/agent-mode.tsx +95 -0
  114. package/src/context/extension-file.tsx +136 -0
  115. package/src/context/network-activity.tsx +45 -0
  116. package/src/context/notification.tsx +62 -0
  117. package/src/context/shell-size.tsx +49 -0
  118. package/src/context/shell-title.tsx +38 -0
  119. package/src/entrypoints/print-mode.ts +312 -0
  120. package/src/entrypoints/repl.tsx +389 -0
  121. package/src/hooks/use-agent.ts +15 -0
  122. package/src/hooks/use-api-client.ts +1 -0
  123. package/src/hooks/use-available-height.ts +8 -0
  124. package/src/hooks/use-cleanup.ts +29 -0
  125. package/src/hooks/use-interrupt-manager.ts +242 -0
  126. package/src/hooks/use-models.ts +22 -0
  127. package/src/index.ts +217 -0
  128. package/src/lib/__tests__/ansi.test.ts +255 -0
  129. package/src/lib/__tests__/cli.test.ts +122 -0
  130. package/src/lib/__tests__/commands.test.ts +325 -0
  131. package/src/lib/__tests__/constants.test.ts +15 -0
  132. package/src/lib/__tests__/focusables.test.ts +25 -0
  133. package/src/lib/__tests__/fs.test.ts +231 -0
  134. package/src/lib/__tests__/markdown.test.tsx +348 -0
  135. package/src/lib/__tests__/mcpCommandHandler.test.ts +173 -0
  136. package/src/lib/__tests__/mcpManagement.test.ts +38 -0
  137. package/src/lib/__tests__/path-paste.test.ts +144 -0
  138. package/src/lib/__tests__/path.test.ts +300 -0
  139. package/src/lib/__tests__/queries.test.ts +39 -0
  140. package/src/lib/__tests__/standaloneMcpService.test.ts +71 -0
  141. package/src/lib/__tests__/text-buffer.test.ts +328 -0
  142. package/src/lib/__tests__/text-utils.test.ts +32 -0
  143. package/src/lib/__tests__/timing.test.ts +78 -0
  144. package/src/lib/__tests__/utils.test.ts +238 -0
  145. package/src/lib/__tests__/vim-buffer-actions.test.ts +154 -0
  146. package/src/lib/ansi.ts +150 -0
  147. package/src/lib/cli-push-server.ts +112 -0
  148. package/src/lib/cli.ts +44 -0
  149. package/src/lib/clipboard.ts +226 -0
  150. package/src/lib/command-utils.ts +93 -0
  151. package/src/lib/commands.ts +270 -0
  152. package/src/lib/constants.ts +3 -0
  153. package/src/lib/extension-connection.ts +181 -0
  154. package/src/lib/focusables.ts +7 -0
  155. package/src/lib/fs.ts +533 -0
  156. package/src/lib/markdown/code-block.tsx +63 -0
  157. package/src/lib/markdown/index.ts +4 -0
  158. package/src/lib/markdown/link.tsx +19 -0
  159. package/src/lib/markdown/markdown.tsx +372 -0
  160. package/src/lib/markdown/types.ts +15 -0
  161. package/src/lib/mcpCommandHandler.ts +121 -0
  162. package/src/lib/mcpManagement.ts +44 -0
  163. package/src/lib/path-paste.ts +185 -0
  164. package/src/lib/path.ts +179 -0
  165. package/src/lib/queries.ts +15 -0
  166. package/src/lib/standaloneMcpService.ts +688 -0
  167. package/src/lib/status-utils.ts +237 -0
  168. package/src/lib/test-utils.tsx +72 -0
  169. package/src/lib/text-buffer.ts +2415 -0
  170. package/src/lib/text-utils.ts +272 -0
  171. package/src/lib/timing.ts +63 -0
  172. package/src/lib/types.ts +295 -0
  173. package/src/lib/utils.ts +182 -0
  174. package/src/lib/vim-buffer-actions.ts +732 -0
  175. package/src/providers/agent.tsx +1063 -0
  176. package/src/providers/api-client.tsx +43 -0
  177. package/src/services/logger.ts +85 -0
  178. package/src/terminal/detection.ts +187 -0
  179. package/src/terminal/exit.ts +279 -0
  180. package/src/terminal/notification.ts +83 -0
  181. package/src/terminal/progress.ts +201 -0
  182. package/src/terminal/setup.ts +797 -0
  183. package/src/terminal/types.ts +51 -0
  184. package/src/theme/context.tsx +57 -0
  185. package/src/theme/index.ts +4 -0
  186. package/src/theme/themed.tsx +35 -0
  187. package/src/theme/themes.json +546 -0
  188. package/src/theme/types.ts +110 -0
  189. package/src/tools/types.ts +59 -0
  190. package/src/tools/utils/__tests__/zod-coercion.test.ts +33 -0
  191. package/src/tools/utils/tool-ui-components.tsx +649 -0
  192. package/src/tools/utils/zod-coercion.ts +35 -0
  193. package/tsconfig.json +16 -0
  194. package/tsconfig.node.json +29 -0
  195. package/tsconfig.test.json +27 -0
  196. package/tsdown.config.ts +17 -0
  197. package/vitest.config.ts +76 -0
  198. package/README.md +0 -28
  199. package/dist/index.js +0 -26
@@ -0,0 +1,226 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { copyFileSync, existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
3
+ import path from "node:path";
4
+
5
+ // ── macOS screenshot detection ────────────────────────────────────────────
6
+
7
+ const MACOS_TEMP_SCREENSHOT_PATTERN =
8
+ /\/var\/folders\/.*\/T\/TemporaryItems\/.*screencaptureui.*\//i;
9
+ const SCREENSHOTS_DIR = ".abacusai/screenshots";
10
+
11
+ export function isMacOSTempScreenshot(filePath: string): boolean {
12
+ return MACOS_TEMP_SCREENSHOT_PATTERN.test(filePath);
13
+ }
14
+
15
+ export function copyTempScreenshotToProject(tempPath: string): string | null {
16
+ try {
17
+ const unescaped = tempPath.replace(/\\ /g, " ");
18
+ const cleaned = stripFileProtocol(unescaped);
19
+
20
+ if (!existsSync(cleaned)) {
21
+ return null;
22
+ }
23
+
24
+ const screenshotsDir = path.resolve(process.cwd(), SCREENSHOTS_DIR);
25
+ if (!existsSync(screenshotsDir)) {
26
+ mkdirSync(screenshotsDir, { recursive: true });
27
+ }
28
+
29
+ const filename = path.basename(cleaned);
30
+ const destPath = path.join(screenshotsDir, filename);
31
+
32
+ copyFileSync(cleaned, destPath);
33
+ return destPath;
34
+ } catch {
35
+ return null;
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Strips the file:// protocol prefix from a path if present.
41
+ * Also percent-decodes URI-encoded characters (e.g. %20 → space).
42
+ */
43
+ export function stripFileProtocol(text: string): string {
44
+ if (text.startsWith("file://")) {
45
+ try {
46
+ return decodeURIComponent(text.slice("file://".length));
47
+ } catch {
48
+ return text.slice("file://".length);
49
+ }
50
+ }
51
+ return text;
52
+ }
53
+
54
+ // ── Linux clipboard tool detection ───────────────────────────────────────
55
+
56
+ let linuxClipboardTool: "wl-paste" | "xclip" | null | undefined;
57
+
58
+ function detectLinuxClipboardTool(): "wl-paste" | "xclip" | null {
59
+ if (linuxClipboardTool !== undefined) return linuxClipboardTool;
60
+ try {
61
+ execFileSync("which", ["wl-paste"], { stdio: "ignore" });
62
+ linuxClipboardTool = "wl-paste";
63
+ return "wl-paste";
64
+ } catch {
65
+ // not found
66
+ }
67
+ try {
68
+ execFileSync("which", ["xclip"], { stdio: "ignore" });
69
+ linuxClipboardTool = "xclip";
70
+ return "xclip";
71
+ } catch {
72
+ // not found
73
+ }
74
+ linuxClipboardTool = null;
75
+ return null;
76
+ }
77
+
78
+ // ── Clipboard image detection ─────────────────────────────────────────────
79
+
80
+ export async function clipboardHasImage(): Promise<boolean> {
81
+ try {
82
+ if (process.platform === "darwin") {
83
+ const result = execFileSync("osascript", ["-e", "clipboard info"], {
84
+ encoding: "utf8",
85
+ timeout: 2000,
86
+ });
87
+ return /PNGf|JPEG|TIFF|GIF/i.test(result);
88
+ }
89
+ if (process.platform === "win32") {
90
+ const result = execFileSync(
91
+ "powershell",
92
+ [
93
+ "-NoProfile",
94
+ "-Command",
95
+ "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Clipboard]::ContainsImage()",
96
+ ],
97
+ { encoding: "utf8", timeout: 2000 },
98
+ );
99
+ return result.trim().toLowerCase() === "true";
100
+ }
101
+ // Linux
102
+ const tool = detectLinuxClipboardTool();
103
+ if (tool === "wl-paste") {
104
+ const result = execFileSync("wl-paste", ["--list-types"], {
105
+ encoding: "utf8",
106
+ timeout: 2000,
107
+ });
108
+ return result.includes("image/");
109
+ }
110
+ if (tool === "xclip") {
111
+ const result = execFileSync("xclip", ["-selection", "clipboard", "-t", "TARGETS", "-o"], {
112
+ encoding: "utf8",
113
+ timeout: 2000,
114
+ });
115
+ return result.includes("image/");
116
+ }
117
+ } catch {
118
+ // ignore — clipboard tools may not be available
119
+ }
120
+ return false;
121
+ }
122
+
123
+ // ── Save clipboard image to disk ──────────────────────────────────────────
124
+
125
+ export async function saveClipboardImage(cwd: string): Promise<string | null> {
126
+ try {
127
+ const screenshotsDir = path.resolve(cwd, SCREENSHOTS_DIR);
128
+ if (!existsSync(screenshotsDir)) {
129
+ mkdirSync(screenshotsDir, { recursive: true });
130
+ }
131
+
132
+ const timestamp = Date.now();
133
+ const destPath = path.join(screenshotsDir, `clipboard-${timestamp}.png`);
134
+
135
+ if (process.platform === "darwin") {
136
+ // Try PNG first, then JPEG
137
+ const script = `
138
+ set destFile to "${destPath}"
139
+ try
140
+ set imgData to (clipboard info for «class PNGf»)
141
+ set fileRef to open for access POSIX file destFile with write permission
142
+ set eof of fileRef to 0
143
+ write (clipboard as «class PNGf») to fileRef
144
+ close access fileRef
145
+ on error
146
+ try
147
+ set imgData to (clipboard info for «class JPEG»)
148
+ set fileRef to open for access POSIX file destFile with write permission
149
+ set eof of fileRef to 0
150
+ write (clipboard as «class JPEG») to fileRef
151
+ close access fileRef
152
+ end try
153
+ end try
154
+ `;
155
+ execFileSync("osascript", ["-e", script], { timeout: 5000 });
156
+ } else if (process.platform === "win32") {
157
+ execFileSync(
158
+ "powershell",
159
+ [
160
+ "-NoProfile",
161
+ "-Command",
162
+ `Add-Type -Assembly System.Windows.Forms; [System.Windows.Forms.Clipboard]::GetImage().Save("${destPath}", [System.Drawing.Imaging.ImageFormat]::Png)`,
163
+ ],
164
+ { timeout: 5000 },
165
+ );
166
+ } else {
167
+ const tool = detectLinuxClipboardTool();
168
+ if (tool === "wl-paste") {
169
+ const imgData = execFileSync("wl-paste", ["--no-newline", "--type", "image/png"], {
170
+ timeout: 5000,
171
+ });
172
+ writeFileSync(destPath, imgData);
173
+ } else if (tool === "xclip") {
174
+ const imgData = execFileSync(
175
+ "xclip",
176
+ ["-selection", "clipboard", "-t", "image/png", "-o"],
177
+ { timeout: 5000 },
178
+ );
179
+ writeFileSync(destPath, imgData);
180
+ } else {
181
+ return null;
182
+ }
183
+ }
184
+
185
+ // Verify file exists and has content (prevents empty-file false positives)
186
+ try {
187
+ const stat = statSync(destPath);
188
+ if (stat.size === 0) return null;
189
+ } catch {
190
+ return null;
191
+ }
192
+
193
+ return destPath;
194
+ } catch {
195
+ return null;
196
+ }
197
+ }
198
+
199
+ // ── Read clipboard text ───────────────────────────────────────────────────
200
+
201
+ export async function readClipboardText(): Promise<string | null> {
202
+ try {
203
+ if (process.platform === "darwin") {
204
+ return execFileSync("pbpaste", { encoding: "utf8", timeout: 2000 });
205
+ }
206
+ if (process.platform === "win32") {
207
+ return execFileSync("powershell", ["-NoProfile", "-Command", "Get-Clipboard"], {
208
+ encoding: "utf8",
209
+ timeout: 2000,
210
+ });
211
+ }
212
+ const tool = detectLinuxClipboardTool();
213
+ if (tool === "wl-paste") {
214
+ return execFileSync("wl-paste", ["--no-newline"], { encoding: "utf8", timeout: 2000 });
215
+ }
216
+ if (tool === "xclip") {
217
+ return execFileSync("xclip", ["-selection", "clipboard", "-o"], {
218
+ encoding: "utf8",
219
+ timeout: 2000,
220
+ });
221
+ }
222
+ } catch {
223
+ // ignore
224
+ }
225
+ return null;
226
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Extracts the command type from a terminal command string
3
+ * Returns more specific types for common commands with subcommands
4
+ * Examples:
5
+ * "pwd" -> "pwd"
6
+ * "cd /home" -> "cd"
7
+ * "npm install" -> "npm install"
8
+ * "npm run build" -> "npm run"
9
+ * "git status" -> "git status"
10
+ * "git commit -m" -> "git commit"
11
+ * "docker ps" -> "docker ps"
12
+ * "ls -la" -> "ls"
13
+ */
14
+ export const getCommandType = (command: string): string | null => {
15
+ if (!command || typeof command !== "string") {
16
+ return null;
17
+ }
18
+
19
+ // Trim the command and extract the first word
20
+ const trimmedCommand = command.trim();
21
+ if (!trimmedCommand) {
22
+ return null;
23
+ }
24
+
25
+ // Split by whitespace and get parts
26
+ let parts = trimmedCommand.split(/\s+/);
27
+
28
+ // Remove leading 'sudo' if present
29
+ if (parts[0] === "sudo" && parts.length > 1) {
30
+ parts = parts.slice(1);
31
+ }
32
+
33
+ const baseCommand = parts[0];
34
+ const subCommand = parts.length > 1 ? parts[1] : null;
35
+
36
+ // Define commands that should include their subcommand for more specific matching
37
+ // Format: { command: [list of subcommands to be specific about] }
38
+ const specificSubcommands: Record<string, string[]> = {
39
+ npm: ["install", "run", "start", "test", "build", "publish", "update", "uninstall", "ci"],
40
+ yarn: ["install", "add", "remove", "run", "start", "test", "build", "publish"],
41
+ pnpm: ["install", "add", "remove", "run", "start", "test", "build"],
42
+ git: [
43
+ "clone",
44
+ "pull",
45
+ "push",
46
+ "commit",
47
+ "add",
48
+ "status",
49
+ "checkout",
50
+ "branch",
51
+ "merge",
52
+ "rebase",
53
+ "fetch",
54
+ "diff",
55
+ "log",
56
+ "stash",
57
+ ],
58
+ docker: [
59
+ "build",
60
+ "run",
61
+ "ps",
62
+ "stop",
63
+ "start",
64
+ "pull",
65
+ "push",
66
+ "images",
67
+ "rm",
68
+ "exec",
69
+ "logs",
70
+ "compose",
71
+ ],
72
+ kubectl: ["get", "apply", "delete", "describe", "logs", "exec", "create", "scale"],
73
+ cargo: ["build", "run", "test", "check", "clean", "install", "update", "publish"],
74
+ pip: ["install", "uninstall", "list", "show", "freeze", "search"],
75
+ brew: ["install", "uninstall", "update", "upgrade", "list", "search", "info"],
76
+ apt: ["install", "remove", "update", "upgrade", "search", "show"],
77
+ "apt-get": ["install", "remove", "update", "upgrade", "purge"],
78
+ yum: ["install", "remove", "update", "search", "info"],
79
+ systemctl: ["start", "stop", "restart", "enable", "disable", "status"],
80
+ make: ["build", "clean", "install", "test"],
81
+ };
82
+
83
+ // Check if this command should have a specific subcommand
84
+ if (subCommand && specificSubcommands[baseCommand]) {
85
+ const validSubcommands = specificSubcommands[baseCommand];
86
+ if (validSubcommands.includes(subCommand)) {
87
+ return `${baseCommand} ${subCommand}`;
88
+ }
89
+ }
90
+
91
+ // For all other cases, return just the base command
92
+ return baseCommand;
93
+ };
@@ -0,0 +1,270 @@
1
+ export enum Command {
2
+ Stop = "/stop",
3
+ Quit = "/quit",
4
+ Exit = "/exit",
5
+ Q = "/q",
6
+ Bye = "/bye",
7
+ Clear = "/clear",
8
+ New = "/new",
9
+ Suggest = "/",
10
+ Help = "/help",
11
+ Sidebar = "/sidebar",
12
+ Login = "/login",
13
+ Logout = "/logout",
14
+ Mcp = "/mcp",
15
+ }
16
+
17
+ export interface CommandInfo {
18
+ command: Command;
19
+ description: string;
20
+ usage: string;
21
+ }
22
+
23
+ export const COMMAND_INFO: CommandInfo[] = [
24
+ {
25
+ command: Command.Stop,
26
+ description: "Stop the current streaming response",
27
+ usage: "/stop",
28
+ },
29
+ {
30
+ command: Command.Quit,
31
+ description: "Exit the application",
32
+ usage: "/exit",
33
+ },
34
+ {
35
+ command: Command.Clear,
36
+ description: "Clear conversation history and free up context",
37
+ usage: "/clear",
38
+ },
39
+ {
40
+ command: Command.New,
41
+ description: "Start a new conversation",
42
+ usage: "/new",
43
+ },
44
+ {
45
+ command: Command.Suggest,
46
+ description: "Show available commands and hints",
47
+ usage: "/",
48
+ },
49
+ {
50
+ command: Command.Help,
51
+ description: "Show commands and functionalities",
52
+ usage: "/help",
53
+ },
54
+ {
55
+ command: Command.Sidebar,
56
+ description: "Toggle sidebar visibility",
57
+ usage: "/sidebar",
58
+ },
59
+ {
60
+ command: Command.Login,
61
+ description: "Log in to AbacusAI with email (device code flow)",
62
+ usage: "/login <email>",
63
+ },
64
+ {
65
+ command: Command.Logout,
66
+ description: "Log out of AbacusAI",
67
+ usage: "/logout",
68
+ },
69
+ {
70
+ command: Command.Mcp,
71
+ description: "Manage MCP servers",
72
+ usage: "/mcp [command] [options]",
73
+ },
74
+ ];
75
+
76
+ export const getCommandInfo = (command: Command): CommandInfo | undefined => {
77
+ return COMMAND_INFO.find((info) => info.command === command);
78
+ };
79
+
80
+ export const getAllCommands = (): Command[] => {
81
+ return Object.values(Command);
82
+ };
83
+
84
+ export const isValidCommand = (input: string): boolean => {
85
+ return Object.values(Command).includes(input as Command);
86
+ };
87
+
88
+ export const formatCommandHelp = (): string => {
89
+ const maxUsageLength = Math.max(...COMMAND_INFO.map((info) => info.usage.length));
90
+
91
+ return [
92
+ "Abacus.AI CLI",
93
+ "",
94
+ "Abacus.AI CLI has read access to files in the current directory and can run commands and edit files with your permission.",
95
+ "",
96
+ "Use npx -y @abacus-ai/cli@latest to run latest version of abacusai interactive mode directly from your terminal",
97
+ "",
98
+ "Usage Modes:",
99
+ "• REPL: abacusai (interactive session)",
100
+ '• Non-interactive: abacusai -p "question"',
101
+ "",
102
+ "Run abacusai --help for all command line options",
103
+ "",
104
+ "For first time users, use /login to authenticate to Abacus.AI CLI",
105
+ "",
106
+ "Common Tasks:",
107
+ "• Ask questions about your codebase > How does agent.py work?",
108
+ "• Edit files > Update code.ts to...",
109
+ "• Fix errors > cargo build",
110
+ "• Run commands > /help",
111
+ "• Run bash commands > wc",
112
+ "",
113
+ "Interactive Mode Commands:",
114
+ "",
115
+ ...COMMAND_INFO.map((info) => ` ${info.usage.padEnd(maxUsageLength + 2)} ${info.description}`),
116
+ "",
117
+ "Type any command and press Enter to execute.",
118
+ ].join("\n");
119
+ };
120
+
121
+ export const getCommandSuggestions = (input: string): Command[] => {
122
+ return Object.values(Command).filter((cmd) => cmd.toLowerCase().includes(input.toLowerCase()));
123
+ };
124
+
125
+ export const getCommandWithDescription = (command: Command): string => {
126
+ const info = getCommandInfo(command);
127
+ return info ? `${command} - ${info.description}` : command;
128
+ };
129
+
130
+ // MCP subcommands
131
+ export enum McpSubcommand {
132
+ Add = "add",
133
+ Remove = "remove",
134
+ List = "list",
135
+ Get = "get",
136
+ AddJson = "add-json",
137
+ Help = "help",
138
+ }
139
+
140
+ export interface McpCommandInfo {
141
+ subcommand: McpSubcommand;
142
+ description: string;
143
+ usage: string;
144
+ }
145
+
146
+ export const MCP_COMMAND_INFO: McpCommandInfo[] = [
147
+ {
148
+ subcommand: McpSubcommand.Add,
149
+ description: "Add a server",
150
+ usage: "/mcp add <name> <commandOrUrl> [args...]",
151
+ },
152
+ {
153
+ subcommand: McpSubcommand.Remove,
154
+ description: "Remove an MCP server",
155
+ usage: "/mcp remove <name>",
156
+ },
157
+ {
158
+ subcommand: McpSubcommand.List,
159
+ description: "List configured MCP servers",
160
+ usage: "/mcp list",
161
+ },
162
+ {
163
+ subcommand: McpSubcommand.Get,
164
+ description: "Get details about an MCP server",
165
+ usage: "/mcp get <name>",
166
+ },
167
+ {
168
+ subcommand: McpSubcommand.AddJson,
169
+ description: "Add an MCP server (stdio or SSE) with a JSON string",
170
+ usage: "/mcp add-json <name> <json>",
171
+ },
172
+ {
173
+ subcommand: McpSubcommand.Help,
174
+ description: "Display help for MCP commands",
175
+ usage: "/mcp help [command]",
176
+ },
177
+ ];
178
+
179
+ export const getMcpCommandInfo = (subcommand: McpSubcommand): McpCommandInfo | undefined => {
180
+ return MCP_COMMAND_INFO.find((info) => info.subcommand === subcommand);
181
+ };
182
+
183
+ export const getAllMcpSubcommands = (): McpSubcommand[] => {
184
+ return Object.values(McpSubcommand);
185
+ };
186
+
187
+ export const isValidMcpSubcommand = (input: string): boolean => {
188
+ return Object.values(McpSubcommand).includes(input as McpSubcommand);
189
+ };
190
+
191
+ export const formatMcpCommandHelp = (): string => {
192
+ const maxUsageLength = Math.max(...MCP_COMMAND_INFO.map((info) => info.usage.length));
193
+
194
+ return [
195
+ "📡 MCP (Model Context Protocol) Commands:",
196
+ "",
197
+ ...MCP_COMMAND_INFO.map(
198
+ (info) => ` ${info.usage.padEnd(maxUsageLength + 2)} ${info.description}`,
199
+ ),
200
+ "",
201
+ "💡 TUI Features:",
202
+ " - Full MCP server management from command line",
203
+ " - All commands work independently in TUI",
204
+ " - Direct file-based configuration access",
205
+ "",
206
+ ].join("\n");
207
+ };
208
+
209
+ export const parseMcpCommand = (input: string): { subcommand?: McpSubcommand; args: string[] } => {
210
+ const trimmed = input.trim();
211
+ if (!trimmed.startsWith("/mcp")) {
212
+ return { args: [] };
213
+ }
214
+
215
+ // Parse arguments respecting quoted strings
216
+ const args: string[] = [];
217
+ let current = "";
218
+ let inQuotes = false;
219
+ let quoteChar = "";
220
+ let i = 4; // Skip '/mcp'
221
+
222
+ // Skip whitespace after /mcp
223
+ while (i < trimmed.length && /\s/.test(trimmed[i])) {
224
+ i++;
225
+ }
226
+
227
+ while (i < trimmed.length) {
228
+ const char = trimmed[i];
229
+
230
+ if (!inQuotes && /\s/.test(char)) {
231
+ // End of current argument
232
+ if (current) {
233
+ args.push(current);
234
+ current = "";
235
+ }
236
+ // Skip whitespace
237
+ while (i < trimmed.length && /\s/.test(trimmed[i])) {
238
+ i++;
239
+ }
240
+ continue;
241
+ }
242
+ if (!inQuotes && (char === '"' || char === "'")) {
243
+ // Start of quoted string
244
+ inQuotes = true;
245
+ quoteChar = char;
246
+ } else if (inQuotes && char === quoteChar) {
247
+ // End of quoted string
248
+ inQuotes = false;
249
+ quoteChar = "";
250
+ } else {
251
+ // Regular character
252
+ current += char;
253
+ }
254
+
255
+ i++;
256
+ }
257
+
258
+ // Add final argument if any
259
+ if (current) {
260
+ args.push(current);
261
+ }
262
+
263
+ const subcommandStr = args[0];
264
+ const subcommand = isValidMcpSubcommand(subcommandStr)
265
+ ? (subcommandStr as McpSubcommand)
266
+ : undefined;
267
+ const commandArgs = args.slice(1);
268
+
269
+ return { subcommand, args: commandArgs };
270
+ };
@@ -0,0 +1,3 @@
1
+ // Maximum number of recent conversations to display in the sidebar and related components
2
+ export const MAX_RECENT_CONVERSATIONS = 25;
3
+ export const TOOL_CALL_LIMIT = Number.MAX_SAFE_INTEGER; // Disabling tool call limit for CLI TODO (raj): Consider adding it back and separating the permissions flow