@abacus-ai/cli 2.0.0-canary.0 → 2.0.0-canary.10

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 (198) hide show
  1. package/dist/index.mjs +825 -577
  2. package/package.json +4 -1
  3. package/.oxlintrc.json +0 -8
  4. package/resources/abacus.ico +0 -0
  5. package/resources/entitlements.plist +0 -9
  6. package/src/__e2e__/README.md +0 -196
  7. package/src/__e2e__/agent-interactions.e2e.test.tsx +0 -61
  8. package/src/__e2e__/cli-commands.e2e.test.tsx +0 -77
  9. package/src/__e2e__/conversation-throttle.e2e.test.ts +0 -453
  10. package/src/__e2e__/conversation.e2e.test.tsx +0 -56
  11. package/src/__e2e__/diff-preview.e2e.test.tsx +0 -3399
  12. package/src/__e2e__/file-creation.e2e.test.tsx +0 -149
  13. package/src/__e2e__/helpers/test-helpers.ts +0 -450
  14. package/src/__e2e__/keyboard-navigation.e2e.test.tsx +0 -34
  15. package/src/__e2e__/llm-models.e2e.test.ts +0 -402
  16. package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +0 -71
  17. package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +0 -167
  18. package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +0 -185
  19. package/src/__e2e__/repl.e2e.test.tsx +0 -78
  20. package/src/__e2e__/shell-compatibility.e2e.test.tsx +0 -76
  21. package/src/__e2e__/theme-mcp.e2e.test.tsx +0 -98
  22. package/src/__e2e__/tool-permissions.e2e.test.tsx +0 -66
  23. package/src/args.ts +0 -22
  24. package/src/components/__tests__/react-compiler.test.tsx +0 -78
  25. package/src/components/__tests__/status-indicator.test.tsx +0 -403
  26. package/src/components/composer/__tests__/bash-runner.test.tsx +0 -263
  27. package/src/components/composer/agent-mode-indicator.tsx +0 -63
  28. package/src/components/composer/bash-runner.tsx +0 -54
  29. package/src/components/composer/commands/default-commands.tsx +0 -615
  30. package/src/components/composer/commands/handler.tsx +0 -59
  31. package/src/components/composer/commands/picker.tsx +0 -273
  32. package/src/components/composer/commands/registry.ts +0 -233
  33. package/src/components/composer/commands/types.ts +0 -33
  34. package/src/components/composer/context.tsx +0 -88
  35. package/src/components/composer/file-mention-picker.tsx +0 -83
  36. package/src/components/composer/help.tsx +0 -44
  37. package/src/components/composer/index.tsx +0 -1006
  38. package/src/components/composer/mentions.ts +0 -57
  39. package/src/components/composer/message-queue.tsx +0 -70
  40. package/src/components/composer/mode-panel.tsx +0 -35
  41. package/src/components/composer/modes/__tests__/bash-handler.test.tsx +0 -755
  42. package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +0 -1108
  43. package/src/components/composer/modes/bash-handler.tsx +0 -132
  44. package/src/components/composer/modes/bash-renderer.tsx +0 -175
  45. package/src/components/composer/modes/default-handlers.tsx +0 -33
  46. package/src/components/composer/modes/index.ts +0 -41
  47. package/src/components/composer/modes/types.ts +0 -21
  48. package/src/components/composer/persistent-shell.ts +0 -283
  49. package/src/components/composer/process.ts +0 -65
  50. package/src/components/composer/types.ts +0 -9
  51. package/src/components/composer/use-mention-search.ts +0 -68
  52. package/src/components/error-boundry.tsx +0 -60
  53. package/src/components/exit-message.tsx +0 -29
  54. package/src/components/expanded-view.tsx +0 -74
  55. package/src/components/file-completion.tsx +0 -127
  56. package/src/components/header.tsx +0 -47
  57. package/src/components/logo.tsx +0 -37
  58. package/src/components/segments.tsx +0 -356
  59. package/src/components/status-indicator.tsx +0 -306
  60. package/src/components/tool-group-summary.tsx +0 -263
  61. package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +0 -312
  62. package/src/components/tool-permissions/diff-preview.tsx +0 -355
  63. package/src/components/tool-permissions/index.ts +0 -5
  64. package/src/components/tool-permissions/permission-options.tsx +0 -375
  65. package/src/components/tool-permissions/permission-preview-header.tsx +0 -57
  66. package/src/components/tool-permissions/tool-permission-ui.tsx +0 -398
  67. package/src/components/tools/agent/ask-user-question.tsx +0 -101
  68. package/src/components/tools/agent/enter-plan-mode.tsx +0 -49
  69. package/src/components/tools/agent/exit-plan-mode.tsx +0 -75
  70. package/src/components/tools/agent/handoff-to-main.tsx +0 -27
  71. package/src/components/tools/agent/subagent.tsx +0 -37
  72. package/src/components/tools/agent/todo-write.tsx +0 -104
  73. package/src/components/tools/browser/close-tab.tsx +0 -58
  74. package/src/components/tools/browser/computer.tsx +0 -70
  75. package/src/components/tools/browser/get-interactive-elements.tsx +0 -54
  76. package/src/components/tools/browser/get-tab-content.tsx +0 -51
  77. package/src/components/tools/browser/navigate-to.tsx +0 -59
  78. package/src/components/tools/browser/new-tab.tsx +0 -60
  79. package/src/components/tools/browser/perform-action.tsx +0 -63
  80. package/src/components/tools/browser/refresh-tab.tsx +0 -43
  81. package/src/components/tools/browser/switch-tab.tsx +0 -58
  82. package/src/components/tools/filesystem/delete-file.tsx +0 -104
  83. package/src/components/tools/filesystem/edit.tsx +0 -220
  84. package/src/components/tools/filesystem/list-dir.tsx +0 -78
  85. package/src/components/tools/filesystem/read-file.tsx +0 -180
  86. package/src/components/tools/filesystem/upload-image.tsx +0 -76
  87. package/src/components/tools/ide/ide-diagnostics.tsx +0 -62
  88. package/src/components/tools/index.ts +0 -91
  89. package/src/components/tools/mcp/mcp-tool.tsx +0 -158
  90. package/src/components/tools/search/fetch-url.tsx +0 -73
  91. package/src/components/tools/search/file-search.tsx +0 -78
  92. package/src/components/tools/search/grep.tsx +0 -90
  93. package/src/components/tools/search/semantic-search.tsx +0 -66
  94. package/src/components/tools/search/web-search.tsx +0 -71
  95. package/src/components/tools/shared/index.tsx +0 -48
  96. package/src/components/tools/shared/zod-coercion.ts +0 -35
  97. package/src/components/tools/terminal/bash-tool-output.tsx +0 -174
  98. package/src/components/tools/terminal/get-terminal-output.tsx +0 -85
  99. package/src/components/tools/terminal/run-in-terminal.tsx +0 -106
  100. package/src/components/tools/types.ts +0 -16
  101. package/src/components/tools.tsx +0 -66
  102. package/src/components/ui/__tests__/divider.test.tsx +0 -61
  103. package/src/components/ui/__tests__/gradient.test.tsx +0 -125
  104. package/src/components/ui/__tests__/input.test.tsx +0 -166
  105. package/src/components/ui/__tests__/select.test.tsx +0 -273
  106. package/src/components/ui/__tests__/shimmer.test.tsx +0 -99
  107. package/src/components/ui/blinking-indicator.tsx +0 -25
  108. package/src/components/ui/divider.tsx +0 -162
  109. package/src/components/ui/gradient.tsx +0 -56
  110. package/src/components/ui/input.tsx +0 -228
  111. package/src/components/ui/select.tsx +0 -151
  112. package/src/components/ui/shimmer.tsx +0 -84
  113. package/src/context/agent-mode.tsx +0 -95
  114. package/src/context/extension-file.tsx +0 -136
  115. package/src/context/network-activity.tsx +0 -45
  116. package/src/context/notification.tsx +0 -62
  117. package/src/context/shell-size.tsx +0 -49
  118. package/src/context/shell-title.tsx +0 -38
  119. package/src/entrypoints/print-mode.ts +0 -312
  120. package/src/entrypoints/repl.tsx +0 -401
  121. package/src/hooks/use-agent.ts +0 -15
  122. package/src/hooks/use-api-client.ts +0 -1
  123. package/src/hooks/use-available-height.ts +0 -8
  124. package/src/hooks/use-cleanup.ts +0 -29
  125. package/src/hooks/use-interrupt-manager.ts +0 -242
  126. package/src/hooks/use-models.ts +0 -22
  127. package/src/index.ts +0 -217
  128. package/src/lib/__tests__/ansi.test.ts +0 -255
  129. package/src/lib/__tests__/cli.test.ts +0 -122
  130. package/src/lib/__tests__/commands.test.ts +0 -325
  131. package/src/lib/__tests__/constants.test.ts +0 -15
  132. package/src/lib/__tests__/focusables.test.ts +0 -25
  133. package/src/lib/__tests__/fs.test.ts +0 -231
  134. package/src/lib/__tests__/markdown.test.tsx +0 -348
  135. package/src/lib/__tests__/mcpCommandHandler.test.ts +0 -173
  136. package/src/lib/__tests__/mcpManagement.test.ts +0 -38
  137. package/src/lib/__tests__/path-paste.test.ts +0 -144
  138. package/src/lib/__tests__/path.test.ts +0 -300
  139. package/src/lib/__tests__/queries.test.ts +0 -39
  140. package/src/lib/__tests__/standaloneMcpService.test.ts +0 -71
  141. package/src/lib/__tests__/text-buffer.test.ts +0 -328
  142. package/src/lib/__tests__/text-utils.test.ts +0 -32
  143. package/src/lib/__tests__/timing.test.ts +0 -78
  144. package/src/lib/__tests__/utils.test.ts +0 -238
  145. package/src/lib/__tests__/vim-buffer-actions.test.ts +0 -154
  146. package/src/lib/ansi.ts +0 -150
  147. package/src/lib/cli-push-server.ts +0 -112
  148. package/src/lib/cli.ts +0 -44
  149. package/src/lib/clipboard.ts +0 -226
  150. package/src/lib/command-utils.ts +0 -93
  151. package/src/lib/commands.ts +0 -270
  152. package/src/lib/constants.ts +0 -3
  153. package/src/lib/extension-connection.ts +0 -181
  154. package/src/lib/focusables.ts +0 -7
  155. package/src/lib/fs.ts +0 -533
  156. package/src/lib/markdown/code-block.tsx +0 -63
  157. package/src/lib/markdown/index.ts +0 -4
  158. package/src/lib/markdown/link.tsx +0 -19
  159. package/src/lib/markdown/markdown.tsx +0 -372
  160. package/src/lib/markdown/types.ts +0 -15
  161. package/src/lib/mcpCommandHandler.ts +0 -121
  162. package/src/lib/mcpManagement.ts +0 -44
  163. package/src/lib/path-paste.ts +0 -185
  164. package/src/lib/path.ts +0 -179
  165. package/src/lib/queries.ts +0 -15
  166. package/src/lib/standaloneMcpService.ts +0 -688
  167. package/src/lib/status-utils.ts +0 -237
  168. package/src/lib/test-utils.tsx +0 -72
  169. package/src/lib/text-buffer.ts +0 -2415
  170. package/src/lib/text-utils.ts +0 -272
  171. package/src/lib/timing.ts +0 -63
  172. package/src/lib/types.ts +0 -295
  173. package/src/lib/utils.ts +0 -182
  174. package/src/lib/vim-buffer-actions.ts +0 -732
  175. package/src/providers/agent.tsx +0 -1075
  176. package/src/providers/api-client.tsx +0 -43
  177. package/src/services/logger.ts +0 -85
  178. package/src/terminal/detection.ts +0 -187
  179. package/src/terminal/exit.ts +0 -279
  180. package/src/terminal/notification.ts +0 -83
  181. package/src/terminal/progress.ts +0 -201
  182. package/src/terminal/setup.ts +0 -797
  183. package/src/terminal/suspend.ts +0 -58
  184. package/src/terminal/types.ts +0 -51
  185. package/src/theme/context.tsx +0 -57
  186. package/src/theme/index.ts +0 -4
  187. package/src/theme/themed.tsx +0 -35
  188. package/src/theme/themes.json +0 -546
  189. package/src/theme/types.ts +0 -110
  190. package/src/tools/types.ts +0 -59
  191. package/src/tools/utils/__tests__/zod-coercion.test.ts +0 -33
  192. package/src/tools/utils/tool-ui-components.tsx +0 -631
  193. package/src/tools/utils/zod-coercion.ts +0 -35
  194. package/tsconfig.json +0 -11
  195. package/tsconfig.node.json +0 -29
  196. package/tsconfig.test.json +0 -27
  197. package/tsdown.config.ts +0 -17
  198. package/vitest.config.ts +0 -76
@@ -1,22 +0,0 @@
1
- import { AbacusClient, ILLMOption } from "@codellm/api";
2
- import { useSuspenseQuery } from "@tanstack/react-query";
3
-
4
- import { QueryKey } from "../lib/queries.js";
5
-
6
- export function useModels(apiClient: AbacusClient) {
7
- return useSuspenseQuery<ILLMOption[]>({
8
- queryKey: [QueryKey.Models],
9
- queryFn: async () => {
10
- try {
11
- const response = await apiClient.listLLMModels();
12
- return response?.result ?? [];
13
- } catch {
14
- return [];
15
- }
16
- },
17
- staleTime: 5 * 60 * 1000,
18
- retry: 1,
19
- refetchOnMount: "always",
20
- refetchOnWindowFocus: false,
21
- });
22
- }
package/src/index.ts DELETED
@@ -1,217 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { AbacusClient } from "@codellm/api";
4
- export type { AbacusClient };
5
- import { AuthManager } from "@codellm/auth";
6
- import { product } from "@codellm/product";
7
- import chalk from "chalk";
8
- import { parseArgs } from "node:util";
9
-
10
- import packageJson from "@/package.json" with { type: "json" };
11
-
12
- import type { AgentArgs } from "./args.js";
13
-
14
- import { runPrintMode } from "./entrypoints/print-mode.js";
15
- import { runRepl } from "./entrypoints/repl.js";
16
- import { logger } from "./services/logger.js";
17
- import { gracefulExit } from "./terminal/exit.js";
18
-
19
- /**
20
- * Centralized error handling function
21
- */
22
- function handleError(message: string, exitCode = 1): never {
23
- console.error(chalk.red(message));
24
- gracefulExit(exitCode);
25
- throw new Error(message);
26
- }
27
-
28
- /**
29
- * Validates URL format and returns a new URL instance
30
- */
31
- function validateUrl(urlString: string): URL {
32
- try {
33
- return new URL(urlString);
34
- } catch {
35
- handleError(`Invalid ${product.envPrefix}BASE_URL: ${urlString}`);
36
- }
37
- }
38
-
39
- /**
40
- * Validates agent arguments for print mode requirements
41
- */
42
- function validatePrintModeArgs(agentArgs?: AgentArgs): void {
43
- const hasFormatFlags = agentArgs?.["output-format"] || agentArgs?.["input-format"];
44
- if (hasFormatFlags && !agentArgs?.print) {
45
- handleError("--output-format and --input-format flags can only be used with --print mode");
46
- }
47
- }
48
-
49
- /**
50
- * Reads input from stdin asynchronously
51
- */
52
- async function readStdinInput(): Promise<string> {
53
- const stdin = process.stdin;
54
-
55
- if (stdin.isTTY) {
56
- handleError(
57
- "No prompt provided and no piped input detected. Either provide a prompt or pipe input.",
58
- );
59
- }
60
-
61
- let inputData = "";
62
- for await (const chunk of stdin) {
63
- inputData += chunk;
64
- }
65
-
66
- const trimmed = inputData.trim();
67
- if (!trimmed) {
68
- handleError("No input provided");
69
- }
70
-
71
- return trimmed;
72
- }
73
-
74
- /**
75
- * Resolves the input prompt from args or stdin
76
- */
77
- async function resolveInputPrompt(agentArgs?: AgentArgs): Promise<string> {
78
- if (agentArgs?.prompt) {
79
- return agentArgs.prompt;
80
- }
81
- return readStdinInput();
82
- }
83
-
84
- /**
85
- * Configures API client with custom base URL if provided
86
- */
87
- async function configureApiClient(apiClient: AbacusClient): Promise<void> {
88
- const baseUrl = process.env[`${product.envPrefix}BASE_URL`];
89
- if (!baseUrl) {
90
- return;
91
- }
92
-
93
- validateUrl(baseUrl);
94
- apiClient.setUrl(baseUrl);
95
- apiClient.resetEndpoints();
96
- await apiClient.getApiEndpoint();
97
- }
98
-
99
- /**
100
- * Resolve --resume <id> or --continue into a conversation ID.
101
- * --resume uses the provided ID directly.
102
- * --continue fetches the most recently updated conversation from the API.
103
- */
104
- async function resolveConversationId(
105
- agentArgs: AgentArgs | undefined,
106
- apiClient: AbacusClient,
107
- ): Promise<string | undefined> {
108
- if (agentArgs?.resume) {
109
- return agentArgs.resume;
110
- }
111
- if (agentArgs?.continue) {
112
- try {
113
- const result = await apiClient.getConversationsList(product.agentType);
114
- const conversations = result?.result ?? [];
115
- const latest = conversations.sort((a, b) => {
116
- const aTime = a.lastEventCreatedAt ? new Date(a.lastEventCreatedAt).getTime() : 0;
117
- const bTime = b.lastEventCreatedAt ? new Date(b.lastEventCreatedAt).getTime() : 0;
118
- return bTime - aTime;
119
- })[0];
120
- return latest?.deploymentConversationId;
121
- } catch {
122
- // fall through — start fresh
123
- }
124
- }
125
- return undefined;
126
- }
127
-
128
- async function main(agentArgs?: AgentArgs): Promise<void> {
129
- if (agentArgs?.version) {
130
- console.log(`Abacus.AI CLI version ${packageJson.version}`);
131
- gracefulExit(0);
132
- return;
133
- }
134
-
135
- validatePrintModeArgs(agentArgs);
136
-
137
- if (agentArgs?.print) {
138
- const inputPrompt = await resolveInputPrompt(agentArgs);
139
- // For print mode the API client is created inside runPrintMode, so resolve
140
- // conversation ID there — pass raw args through.
141
- await runPrintMode({ agentArgs: { ...agentArgs, prompt: inputPrompt } });
142
- } else {
143
- const authManager = await AuthManager.create();
144
-
145
- // Auth is fully managed by AuthManager.create() — no env access needed here.
146
-
147
- const cliLogger = {
148
- error: (message: string | Error, ...args: unknown[]) => logger.error(message, ...args),
149
- debug: (...message: unknown[]) => logger.debug(...message),
150
- warn: (message: string, ...args: unknown[]) => logger.warn(message, ...args),
151
- };
152
-
153
- const apiClient = new AbacusClient(authManager, cliLogger);
154
-
155
- await configureApiClient(apiClient);
156
-
157
- // Resolve --resume / --continue into a single conversationId before dispatch.
158
- // Downstream consumers (AgentProvider) read agentArgs.conversationId — they
159
- // don't know or care how it was resolved.
160
- const conversationId = await resolveConversationId(agentArgs, apiClient);
161
- const resolvedArgs: AgentArgs = { ...agentArgs, ...(conversationId && { conversationId }) };
162
-
163
- await runRepl({
164
- apiClient,
165
- authManager,
166
- agentArgs: resolvedArgs,
167
- });
168
- }
169
- }
170
-
171
- const HELP_TEXT = `
172
- Usage: abacus [options] [prompt]
173
-
174
- Options:
175
- --help Show this help message
176
- --version Show version number
177
- --model <model> Model to use (-m)
178
- --print Print mode, non-interactive (-p)
179
- --resume <id> Resume a specific conversation by ID
180
- --continue Continue the most recent conversation (-c)
181
- --output-format <format> Output format: text (default), stream-json
182
- --auto-accept-edits Automatically accept edits
183
- --dangerously-skip-permissions Skip permission checks
184
- --plan-mode Enable plan mode
185
- `.trim();
186
-
187
- const { values, positionals } = parseArgs({
188
- options: {
189
- help: { type: "boolean", short: "h" },
190
- version: { type: "boolean", short: "v" },
191
- model: { type: "string", short: "m" },
192
- print: { type: "boolean", short: "p" },
193
- resume: { type: "string" },
194
- continue: { type: "boolean", short: "c" },
195
- "output-format": { type: "string" },
196
- "input-format": { type: "string" },
197
- "allow-editing": { type: "string" },
198
- "auto-accept-edits": { type: "boolean" },
199
- "dangerously-skip-permissions": { type: "boolean" },
200
- "plan-mode": { type: "boolean" },
201
- },
202
- allowPositionals: true,
203
- strict: true,
204
- });
205
-
206
- if (values.help) {
207
- console.log(HELP_TEXT);
208
- process.exit(0);
209
- }
210
-
211
- main({
212
- ...values,
213
- prompt: positionals.length > 0 ? positionals.join(" ") : null,
214
- }).catch((err) => {
215
- console.error(err);
216
- process.exit(1);
217
- });
@@ -1,255 +0,0 @@
1
- // @vitest-environment node
2
-
3
- import { describe, expect, it, vi } from "vitest";
4
-
5
- import {
6
- ANSI,
7
- osc9,
8
- osc777,
9
- osc99,
10
- osc9Progress,
11
- osc1337ProgressClear,
12
- osc1337ProgressState,
13
- osc1337ProgressPercent,
14
- ansiRegex,
15
- stripAnsi,
16
- } from "../ansi.js";
17
-
18
- describe.concurrent("ansi", () => {
19
- describe.concurrent("ANSI enum", () => {
20
- it("should have correct escape character", () => {
21
- expect(ANSI.ESC).toBe("\x1b");
22
- });
23
-
24
- it("should have correct bell character", () => {
25
- expect(ANSI.BEL).toBe("\x07");
26
- });
27
-
28
- it("should have correct string terminator", () => {
29
- expect(ANSI.ST).toBe("\x1b\\");
30
- });
31
-
32
- it("should construct focus reporting sequences correctly", () => {
33
- expect(ANSI.ENABLE_FOCUS_REPORTING).toBe("\x1b[?1004h");
34
- expect(ANSI.DISABLE_FOCUS_REPORTING).toBe("\x1b[?1004l");
35
- expect(ANSI.FOCUS_IN).toBe("\x1b[I");
36
- expect(ANSI.FOCUS_OUT).toBe("\x1b[O");
37
- });
38
-
39
- it("should construct cursor sequences correctly", () => {
40
- expect(ANSI.SHOW_CURSOR).toBe("\x1b[?25h");
41
- expect(ANSI.HIDE_CURSOR).toBe("\x1b[?25l");
42
- });
43
-
44
- it("should construct reset sequences correctly", () => {
45
- expect(ANSI.RESET_SGR).toBe("\x1b[0m");
46
- expect(ANSI.SOFT_RESET).toBe("\x1b[!p");
47
- expect(ANSI.HARD_RESET).toBe("\x1bc");
48
- });
49
-
50
- it("should construct paste mode sequences correctly", () => {
51
- expect(ANSI.ENABLE_BRACKETED_PASTE).toBe("\x1b[?2004h");
52
- expect(ANSI.DISABLE_BRACKETED_PASTE).toBe("\x1b[?2004l");
53
- expect(ANSI.PASTE_MODE_PREFIX).toBe("\x1b[200~");
54
- expect(ANSI.PASTE_MODE_SUFFIX).toBe("\x1b[201~");
55
- });
56
-
57
- it("should construct style sequences correctly", () => {
58
- expect(ANSI.DIM).toBe("\x1b[2m");
59
- expect(ANSI.BOLD).toBe("\x1b[1m");
60
- });
61
- });
62
-
63
- describe.concurrent("osc9", () => {
64
- it("should format OSC 9 notification correctly", () => {
65
- const result = osc9("test message");
66
- expect(result).toBe("\x1b]9;\n\ntest message\x07");
67
- });
68
-
69
- it("should handle empty message", () => {
70
- const result = osc9("");
71
- expect(result).toBe("\x1b]9;\n\n\x07");
72
- });
73
- });
74
-
75
- describe.concurrent("osc777", () => {
76
- it("should format OSC 777 notification correctly", () => {
77
- const result = osc777("Title", "Body");
78
- expect(result).toBe("\x1b]777;notify;Title;Body\x07");
79
- });
80
-
81
- it("should handle empty title and body", () => {
82
- const result = osc777("", "");
83
- expect(result).toBe("\x1b]777;notify;;\x07");
84
- });
85
- });
86
-
87
- describe.concurrent("osc99", () => {
88
- it("should format OSC 99 notification correctly", () => {
89
- // Mock Math.random to get predictable notification ID
90
- const mockRandom = vi.spyOn(Math, "random").mockReturnValue(0.1234);
91
- const result = osc99("Title", "Body");
92
-
93
- // Should contain title and body parts
94
- expect(result).toContain("]99;i=1234:d=0:p=title;Title\x1b\\");
95
- expect(result).toContain("]99;i=1234:p=body;Body\x1b\\");
96
- expect(result).toContain("]99;i=1234:d=1:a=focus;\x1b\\");
97
-
98
- mockRandom.mockRestore();
99
- });
100
- });
101
-
102
- describe.concurrent("osc9Progress", () => {
103
- it("should format progress with state 0 (hide)", () => {
104
- const result = osc9Progress(0);
105
- expect(result).toBe("\x1b]9;4;0;0\x07\x1b]9;4;0;0\x1b\\");
106
- });
107
-
108
- it("should format progress with state 1 and percentage", () => {
109
- const result = osc9Progress(1, 50);
110
- expect(result).toBe("\x1b]9;4;1;50\x07\x1b]9;4;1;50\x1b\\");
111
- });
112
-
113
- it("should clamp progress to 0-100", () => {
114
- expect(osc9Progress(1, -10)).toBe("\x1b]9;4;1;0\x07\x1b]9;4;1;0\x1b\\");
115
- expect(osc9Progress(1, 150)).toBe("\x1b]9;4;1;100\x07\x1b]9;4;1;100\x1b\\");
116
- });
117
-
118
- it("should round progress values", () => {
119
- expect(osc9Progress(1, 50.7)).toBe("\x1b]9;4;1;51\x07\x1b]9;4;1;51\x1b\\");
120
- });
121
- });
122
-
123
- describe.concurrent("osc1337ProgressClear", () => {
124
- it("should clear progress indicator", () => {
125
- const result = osc1337ProgressClear();
126
- expect(result).toBe("\x1b]1337;Progress=\x07\x1b]1337;Progress=\x1b\\");
127
- });
128
- });
129
-
130
- describe.concurrent("osc1337ProgressState", () => {
131
- it("should set progress state 0", () => {
132
- const result = osc1337ProgressState(0);
133
- expect(result).toBe("\x1b]1337;Progress=0\x07\x1b]1337;Progress=0\x1b\\");
134
- });
135
-
136
- it("should set progress state 1", () => {
137
- const result = osc1337ProgressState(1);
138
- expect(result).toBe("\x1b]1337;Progress=1\x07\x1b]1337;Progress=1\x1b\\");
139
- });
140
-
141
- it("should set progress state 2", () => {
142
- const result = osc1337ProgressState(2);
143
- expect(result).toBe("\x1b]1337;Progress=2\x07\x1b]1337;Progress=2\x1b\\");
144
- });
145
- });
146
-
147
- describe.concurrent("osc1337ProgressPercent", () => {
148
- it("should format progress with percentage only", () => {
149
- const result = osc1337ProgressPercent(50);
150
- expect(result).toBe("\x1b]1337;Progress=50\x07\x1b]1337;Progress=50\x1b\\");
151
- });
152
-
153
- it("should format progress with percentage and message", () => {
154
- const result = osc1337ProgressPercent(75, "Loading...");
155
- expect(result).toContain("]1337;Progress=75;Loading...\x07");
156
- expect(result).toContain("]1337;Progress=message=Loading...;percent=75\x07");
157
- });
158
-
159
- it("should clamp percentage to 0-100", () => {
160
- expect(osc1337ProgressPercent(-10)).toBe(
161
- "\x1b]1337;Progress=0\x07\x1b]1337;Progress=0\x1b\\",
162
- );
163
- expect(osc1337ProgressPercent(150)).toBe(
164
- "\x1b]1337;Progress=100\x07\x1b]1337;Progress=100\x1b\\",
165
- );
166
- });
167
-
168
- it("should round percentage values", () => {
169
- expect(osc1337ProgressPercent(50.7)).toBe(
170
- "\x1b]1337;Progress=51\x07\x1b]1337;Progress=51\x1b\\",
171
- );
172
- });
173
-
174
- it("should sanitize message content", () => {
175
- const result = osc1337ProgressPercent(50, "test\x1b\x07\n\r;message");
176
- // The sanitized message should not contain control chars or semicolons
177
- // (they're replaced/removed in the message part, but \x1b is still in OSC wrapper)
178
- expect(result).toContain("test :message"); // \x1b and \x07 removed, \n\r become spaces, ; becomes :
179
- // The message part should not have raw control characters
180
- const messagePart = result.match(
181
- new RegExp("Progress=\\d+;(.+?)[" + String.fromCharCode(7) + String.fromCharCode(27) + "]"),
182
- )?.[1];
183
- expect(messagePart).not.toContain("\x07");
184
- expect(messagePart).not.toContain("\n");
185
- expect(messagePart).not.toContain("\r");
186
- expect(messagePart).not.toContain(";"); // Should be replaced with :
187
- });
188
-
189
- it("should truncate long messages", () => {
190
- const longMessage = "a".repeat(200);
191
- const result = osc1337ProgressPercent(50, longMessage);
192
- // Message is truncated to 120 chars, but result includes OSC sequences
193
- // Extract the message part to verify truncation
194
- const messagePart = result.match(
195
- new RegExp("Progress=\\d+;(.+?)[" + String.fromCharCode(7) + String.fromCharCode(27) + "]"),
196
- )?.[1];
197
- expect(messagePart?.length).toBeLessThanOrEqual(120);
198
- });
199
- });
200
-
201
- describe.concurrent("ansiRegex", () => {
202
- it("should match ANSI escape sequences", () => {
203
- const regex = ansiRegex();
204
- expect("\x1b[31mtest\x1b[0m".match(regex)).toHaveLength(2);
205
- });
206
-
207
- it("should match OSC sequences", () => {
208
- const regex = ansiRegex();
209
- expect("\x1b]0;title\x07".match(regex)).toHaveLength(1);
210
- });
211
-
212
- it("should match only first occurrence when onlyFirst is true", () => {
213
- const regex = ansiRegex({ onlyFirst: true });
214
- const matches = "\x1b[31mtest\x1b[0m".match(regex);
215
- expect(matches).toHaveLength(1);
216
- });
217
-
218
- it("should match all occurrences when onlyFirst is false", () => {
219
- const regex = ansiRegex({ onlyFirst: false });
220
- const matches = "\x1b[31mtest\x1b[0m".match(regex);
221
- expect(matches).toHaveLength(2);
222
- });
223
- });
224
-
225
- describe.concurrent("stripAnsi", () => {
226
- it("should strip ANSI codes from string", () => {
227
- expect(stripAnsi("\x1b[31mtest\x1b[0m")).toBe("test");
228
- });
229
-
230
- it("should handle strings without ANSI codes", () => {
231
- expect(stripAnsi("plain text")).toBe("plain text");
232
- });
233
-
234
- it("should handle empty strings", () => {
235
- expect(stripAnsi("")).toBe("");
236
- });
237
-
238
- it("should throw error for non-string input", () => {
239
- expect(() => stripAnsi(null as unknown as string)).toThrow(
240
- "Expected a `string`, got `object`",
241
- );
242
- expect(() => stripAnsi(123 as unknown as string)).toThrow(
243
- "Expected a `string`, got `number`",
244
- );
245
- });
246
-
247
- it("should strip multiple ANSI codes", () => {
248
- expect(stripAnsi("\x1b[31mred\x1b[0m \x1b[32mgreen\x1b[0m")).toBe("red green");
249
- });
250
-
251
- it("should strip OSC sequences", () => {
252
- expect(stripAnsi("\x1b]0;title\x07")).toBe("");
253
- });
254
- });
255
- });
@@ -1,122 +0,0 @@
1
- // @vitest-environment node
2
-
3
- import { describe, expect, it } from "vitest";
4
-
5
- import { runCli } from "../cli.js";
6
-
7
- // TODO: The runCli function doesn't handle spawn errors (ENOENT).
8
- // When a non-existent command is spawned, the error is emitted asynchronously
9
- // and not caught by the generator, causing unhandled promise rejections.
10
- // Consider adding error handling to runCli to catch and handle spawn errors
11
- // (e.g., proc.on('error', ...) to yield error information or throw).
12
-
13
- describe.concurrent("cli", () => {
14
- describe.concurrent("runCli", () => {
15
- it("should yield output from stdout", async () => {
16
- const command = process.platform === "win32" ? "echo" : "echo";
17
- const args = ["hello world"];
18
- const outputs: string[] = [];
19
-
20
- for await (const output of runCli(command, args)) {
21
- outputs.push(output);
22
- }
23
-
24
- // On Unix, echo outputs to stdout; on Windows, we might need different handling
25
- // The output might include newlines, so we check if it contains our message
26
- // Should have received some output
27
- expect(outputs.length).toBeGreaterThanOrEqual(0);
28
- }, 10000);
29
-
30
- it("should yield output from stderr", async () => {
31
- // Use a command that outputs to stderr
32
- const command = process.platform === "win32" ? "cmd" : "sh";
33
- const args =
34
- process.platform === "win32" ? ["/c", "echo error >&2"] : ["-c", "echo error >&2"];
35
-
36
- const outputs: string[] = [];
37
-
38
- for await (const output of runCli(command, args)) {
39
- outputs.push(output);
40
- }
41
-
42
- // Should have received some output
43
- expect(outputs.length).toBeGreaterThanOrEqual(0);
44
- }, 10000);
45
-
46
- it("should handle commands that exit immediately", async () => {
47
- const command = process.platform === "win32" ? "echo" : "echo";
48
- const args = ["test"];
49
- const outputs: string[] = [];
50
-
51
- for await (const output of runCli(command, args)) {
52
- outputs.push(output);
53
- }
54
-
55
- // Should complete without hanging
56
- expect(true).toBe(true);
57
- }, 10000);
58
-
59
- it("should handle empty args array", async () => {
60
- const command = process.platform === "win32" ? "echo" : "echo";
61
- const args: string[] = [];
62
- const outputs: string[] = [];
63
-
64
- for await (const output of runCli(command, args)) {
65
- outputs.push(output);
66
- }
67
-
68
- // Should complete without error
69
- expect(true).toBe(true);
70
- }, 10000);
71
-
72
- it("should handle multiple output chunks", async () => {
73
- // Use a command that outputs multiple lines
74
- const command = process.platform === "win32" ? "echo" : "printf";
75
- const args =
76
- process.platform === "win32"
77
- ? ["line1\nline2\nline3"]
78
- : ["%s\n%s\n%s\n", "line1", "line2", "line3"];
79
-
80
- const outputs: string[] = [];
81
-
82
- for await (const output of runCli(command, args)) {
83
- outputs.push(output);
84
- }
85
-
86
- // Should have received output
87
- expect(outputs.length).toBeGreaterThanOrEqual(0);
88
- }, 10000);
89
-
90
- it("should terminate process on completion", async () => {
91
- const command = process.platform === "win32" ? "echo" : "echo";
92
- const args = ["test"];
93
-
94
- // This test verifies the process is cleaned up
95
- // We can't easily verify the process is killed, but we can verify
96
- // the generator completes
97
- const generator = runCli(command, args);
98
- const outputs: string[] = [];
99
-
100
- for await (const output of generator) {
101
- outputs.push(output);
102
- }
103
-
104
- // Generator should complete
105
- expect(true).toBe(true);
106
- }, 10000);
107
-
108
- it("should work with different command types", async () => {
109
- // Test with a simple command available on most systems
110
- const command = process.platform === "win32" ? "where" : "which";
111
- const args = process.platform === "win32" ? ["echo"] : ["echo"];
112
- const outputs: string[] = [];
113
-
114
- for await (const output of runCli(command, args)) {
115
- outputs.push(output);
116
- }
117
-
118
- // Should complete without error
119
- expect(true).toBe(true);
120
- }, 10000);
121
- });
122
- });