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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/dist/index.mjs +450 -422
  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 -449
  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 -1007
  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 -319
  62. package/src/components/tool-permissions/diff-preview.tsx +0 -359
  63. package/src/components/tool-permissions/index.ts +0 -5
  64. package/src/components/tool-permissions/permission-options.tsx +0 -401
  65. package/src/components/tool-permissions/permission-preview-header.tsx +0 -57
  66. package/src/components/tool-permissions/tool-permission-ui.tsx +0 -420
  67. package/src/components/tools/agent/ask-user-question.tsx +0 -107
  68. package/src/components/tools/agent/enter-plan-mode.tsx +0 -55
  69. package/src/components/tools/agent/exit-plan-mode.tsx +0 -83
  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 -188
  98. package/src/components/tools/terminal/get-terminal-output.tsx +0 -91
  99. package/src/components/tools/terminal/run-in-terminal.tsx +0 -131
  100. package/src/components/tools/types.ts +0 -16
  101. package/src/components/tools.tsx +0 -68
  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 -27
  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 -76
  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 -389
  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 -1063
  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/types.ts +0 -51
  184. package/src/theme/context.tsx +0 -57
  185. package/src/theme/index.ts +0 -4
  186. package/src/theme/themed.tsx +0 -35
  187. package/src/theme/themes.json +0 -546
  188. package/src/theme/types.ts +0 -110
  189. package/src/tools/types.ts +0 -59
  190. package/src/tools/utils/__tests__/zod-coercion.test.ts +0 -33
  191. package/src/tools/utils/tool-ui-components.tsx +0 -649
  192. package/src/tools/utils/zod-coercion.ts +0 -35
  193. package/tsconfig.json +0 -16
  194. package/tsconfig.node.json +0 -29
  195. package/tsconfig.test.json +0 -27
  196. package/tsdown.config.ts +0 -17
  197. package/vitest.config.ts +0 -76
@@ -1,797 +0,0 @@
1
- import { execFile } from "node:child_process";
2
- import { randomBytes } from "node:crypto";
3
- import fs from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import process from "node:process";
7
- import { promisify } from "node:util";
8
-
9
- import type { TerminalType, TerminalSetupResult } from "./types.js";
10
-
11
- import { getTerminal, getNewlineInstructions } from "./detection.js";
12
-
13
- const SHIFT_ENTER_SEQUENCE = "\\x1b\\r";
14
- const SHIFT_ENTER_SEQUENCE_LITERAL = "\x1b\r";
15
- const execFileAsync = promisify(execFile);
16
-
17
- function createBackup(filePath: string): string | null {
18
- if (!fs.existsSync(filePath)) {
19
- return null;
20
- }
21
- const backupId = randomBytes(4).toString("hex");
22
- const backupPath = `${filePath}.${backupId}.bak`;
23
- try {
24
- fs.copyFileSync(filePath, backupPath);
25
- return backupPath;
26
- } catch {
27
- return null;
28
- }
29
- }
30
-
31
- async function setupVSCodeKeybindings(
32
- editorName: "Code" | "Cursor" | "Windsurf" | "VSCodium",
33
- ): Promise<TerminalSetupResult> {
34
- const home = os.homedir();
35
- let configDir: string;
36
-
37
- if (process.platform === "win32") {
38
- configDir = path.join(home, "AppData", "Roaming", editorName, "User");
39
- } else if (process.platform === "darwin") {
40
- configDir = path.join(home, "Library", "Application Support", editorName, "User");
41
- } else {
42
- configDir = path.join(home, ".config", editorName, "User");
43
- }
44
-
45
- const keybindingsPath = path.join(configDir, "keybindings.json");
46
-
47
- try {
48
- if (!fs.existsSync(configDir)) {
49
- fs.mkdirSync(configDir, { recursive: true });
50
- }
51
-
52
- let keybindings: Array<{
53
- key: string;
54
- command: string;
55
- args?: Record<string, string>;
56
- when?: string;
57
- }> = [];
58
-
59
- if (fs.existsSync(keybindingsPath)) {
60
- const content = fs.readFileSync(keybindingsPath, "utf-8");
61
- const backupPath = createBackup(keybindingsPath);
62
- if (!backupPath) {
63
- return {
64
- success: false,
65
- message: `Failed to backup existing ${editorName} keybindings`,
66
- };
67
- }
68
-
69
- const cleanContent = content.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
70
- try {
71
- keybindings = JSON.parse(cleanContent || "[]");
72
- } catch {
73
- keybindings = [];
74
- }
75
-
76
- const existing = keybindings.find(
77
- (kb) =>
78
- kb.key === "shift+enter" &&
79
- kb.command === "workbench.action.terminal.sendSequence" &&
80
- kb.when === "terminalFocus",
81
- );
82
-
83
- if (existing) {
84
- return {
85
- success: false,
86
- message: `Found existing ${editorName} Shift+Enter key binding. Remove it to continue.\nSee: ${keybindingsPath}`,
87
- };
88
- }
89
- }
90
-
91
- keybindings.push({
92
- key: "shift+enter",
93
- command: "workbench.action.terminal.sendSequence",
94
- args: { text: SHIFT_ENTER_SEQUENCE_LITERAL },
95
- when: "terminalFocus",
96
- });
97
-
98
- fs.writeFileSync(keybindingsPath, JSON.stringify(keybindings, null, 2), "utf-8");
99
-
100
- return {
101
- success: true,
102
- message: `Installed ${editorName} terminal Shift+Enter key binding\nSee: ${keybindingsPath}`,
103
- };
104
- } catch (error) {
105
- return {
106
- success: false,
107
- message: `Failed to install ${editorName} terminal Shift+Enter key binding: ${error instanceof Error ? error.message : String(error)}`,
108
- };
109
- }
110
- }
111
-
112
- async function exec(
113
- command: string,
114
- args: string[],
115
- ): Promise<{ stdout: string; stderr: string; code: number }> {
116
- try {
117
- const { stdout, stderr } = await execFileAsync(command, args, { encoding: "utf8" });
118
- return { stdout, stderr, code: 0 };
119
- } catch (error: unknown) {
120
- if (error && typeof error === "object" && "code" in error) {
121
- const execError = error as { stdout?: string; stderr?: string; code?: number };
122
- return {
123
- stdout: execError.stdout || "",
124
- stderr: execError.stderr || "",
125
- code: typeof execError.code === "number" ? execError.code : 1,
126
- };
127
- }
128
- return {
129
- stdout: "",
130
- stderr: error instanceof Error ? error.message : String(error),
131
- code: 1,
132
- };
133
- }
134
- }
135
-
136
- async function setupITerm2(): Promise<TerminalSetupResult> {
137
- if (process.platform !== "darwin") {
138
- return { success: false, message: "iTerm2 setup is only available on macOS" };
139
- }
140
-
141
- try {
142
- const { code } = await exec("defaults", [
143
- "write",
144
- "com.googlecode.iterm2",
145
- "GlobalKeyMap",
146
- "-dict-add",
147
- "0xd-0x20000",
148
- `<dict><key>Text</key><string>${SHIFT_ENTER_SEQUENCE_LITERAL}</string><key>Action</key><integer>12</integer></dict>`,
149
- ]);
150
-
151
- if (code !== 0) {
152
- return { success: false, message: "Failed to install iTerm2 Shift+Enter key binding" };
153
- }
154
-
155
- return {
156
- success: true,
157
- message:
158
- "Installed iTerm2 Shift+Enter key binding\nRestart iTerm2 for changes to take effect.",
159
- requiresRestart: true,
160
- };
161
- } catch (error) {
162
- return {
163
- success: false,
164
- message: `Failed to configure iTerm2: ${error instanceof Error ? error.message : String(error)}`,
165
- };
166
- }
167
- }
168
-
169
- async function setupAppleTerminal(): Promise<TerminalSetupResult> {
170
- if (process.platform !== "darwin") {
171
- return { success: false, message: "Apple Terminal setup is only available on macOS" };
172
- }
173
-
174
- const plistPath = path.join(os.homedir(), "Library", "Preferences", "com.apple.Terminal.plist");
175
- const backupPath = createBackup(plistPath);
176
-
177
- try {
178
- const { stdout: defaultProfile, code: defaultCode } = await exec("defaults", [
179
- "read",
180
- "com.apple.Terminal",
181
- "Default Window Settings",
182
- ]);
183
-
184
- if (defaultCode !== 0 || !defaultProfile.trim()) {
185
- return { success: false, message: "Failed to read default Terminal.app profile" };
186
- }
187
-
188
- const profile = defaultProfile.trim();
189
-
190
- let { code } = await exec("/usr/libexec/PlistBuddy", [
191
- "-c",
192
- `Add :'Window Settings':'${profile}':useOptionAsMetaKey bool true`,
193
- plistPath,
194
- ]);
195
-
196
- if (code !== 0) {
197
- ({ code } = await exec("/usr/libexec/PlistBuddy", [
198
- "-c",
199
- `Set :'Window Settings':'${profile}':useOptionAsMetaKey true`,
200
- plistPath,
201
- ]));
202
- }
203
-
204
- await exec("killall", ["cfprefsd"]);
205
-
206
- return {
207
- success: true,
208
- message: `Configured Terminal.app to use Option as Meta key\nOption+Enter will now insert a newline\nRestart Terminal.app for changes to take effect.`,
209
- requiresRestart: true,
210
- backupPath: backupPath || undefined,
211
- };
212
- } catch (error) {
213
- return {
214
- success: false,
215
- message: `Failed to configure Terminal.app: ${error instanceof Error ? error.message : String(error)}`,
216
- };
217
- }
218
- }
219
-
220
- async function setupGhosttyKeybindings(): Promise<TerminalSetupResult> {
221
- const configPaths: string[] = [];
222
-
223
- const xdgConfigHome = process.env.XDG_CONFIG_HOME;
224
- if (xdgConfigHome) {
225
- configPaths.push(path.join(xdgConfigHome, "ghostty", "config"));
226
- } else {
227
- configPaths.push(path.join(os.homedir(), ".config", "ghostty", "config"));
228
- }
229
-
230
- if (process.platform === "darwin") {
231
- configPaths.push(
232
- path.join(os.homedir(), "Library", "Application Support", "com.mitchellh.ghostty", "config"),
233
- );
234
- }
235
-
236
- let configPath: string | null = null;
237
- let configExists = false;
238
-
239
- for (const p of configPaths) {
240
- if (fs.existsSync(p)) {
241
- configPath = p;
242
- configExists = true;
243
- break;
244
- }
245
- }
246
-
247
- if (!configPath) {
248
- configPath = configPaths[0]!;
249
- }
250
-
251
- try {
252
- let content = "";
253
-
254
- if (configExists) {
255
- content = fs.readFileSync(configPath, "utf-8");
256
-
257
- if (content.includes("shift+enter")) {
258
- return {
259
- success: false,
260
- message: `Found existing Ghostty Shift+Enter key binding. Remove it to continue.\nSee: ${configPath}`,
261
- };
262
- }
263
-
264
- const backupPath = createBackup(configPath);
265
- if (!backupPath) {
266
- return {
267
- success: false,
268
- message: `Failed to backup existing Ghostty config`,
269
- };
270
- }
271
- } else {
272
- const configDir = path.dirname(configPath);
273
- if (!fs.existsSync(configDir)) {
274
- fs.mkdirSync(configDir, { recursive: true });
275
- }
276
- }
277
-
278
- let newContent = content;
279
- if (content && !content.endsWith("\n")) {
280
- newContent += "\n";
281
- }
282
- newContent += `keybind = shift+enter=text:${SHIFT_ENTER_SEQUENCE}\n`;
283
-
284
- fs.writeFileSync(configPath, newContent, "utf-8");
285
-
286
- return {
287
- success: true,
288
- message: `Installed Ghostty Shift+Enter key binding\nSee: ${configPath}`,
289
- requiresRestart: true,
290
- };
291
- } catch (error) {
292
- return {
293
- success: false,
294
- message: `Failed to install Ghostty Shift+Enter key binding: ${error instanceof Error ? error.message : String(error)}`,
295
- };
296
- }
297
- }
298
-
299
- async function setupWezTermKeybindings(): Promise<TerminalSetupResult> {
300
- const configPath = path.join(os.homedir(), ".wezterm.lua");
301
-
302
- try {
303
- let content = "";
304
- let configExists = false;
305
-
306
- if (fs.existsSync(configPath)) {
307
- configExists = true;
308
- content = fs.readFileSync(configPath, "utf-8");
309
-
310
- if (content.includes('mods="SHIFT"') && content.includes('key="Enter"')) {
311
- return {
312
- success: false,
313
- message: `Found existing WezTerm Shift+Enter key binding. Remove it to continue.\nSee: ${configPath}`,
314
- };
315
- }
316
-
317
- const backupPath = createBackup(configPath);
318
- if (!backupPath) {
319
- return {
320
- success: false,
321
- message: `Failed to backup existing WezTerm config`,
322
- };
323
- }
324
- }
325
-
326
- const keybinding = `{key="Enter", mods="SHIFT", action=wezterm.action{SendString="${SHIFT_ENTER_SEQUENCE}"}}`;
327
-
328
- if (!configExists) {
329
- content = `local wezterm = require 'wezterm'
330
- local config = wezterm.config_builder()
331
-
332
- config.keys = {
333
- ${keybinding},
334
- }
335
-
336
- return config
337
- `;
338
- } else {
339
- const keysMatch = content.match(/config\.keys\s*=\s*\{([^}]*)\}/s);
340
- if (keysMatch) {
341
- const existingKeys = keysMatch[1] ?? "";
342
- const newKeys = existingKeys.trim()
343
- ? `${existingKeys.trim()},\n ${keybinding},`
344
- : `\n ${keybinding},\n`;
345
- content = content.replace(/config\.keys\s*=\s*\{[^}]*\}/s, `config.keys = {${newKeys}}`);
346
- } else if (content.match(/return\s+config/s)) {
347
- content = content.replace(
348
- /return\s+config/s,
349
- `config.keys = {\n ${keybinding},\n}\n\nreturn config`,
350
- );
351
- } else {
352
- content += `\nconfig.keys = {\n ${keybinding},\n}\n`;
353
- }
354
- }
355
-
356
- fs.writeFileSync(configPath, content, "utf-8");
357
-
358
- return {
359
- success: true,
360
- message: `Installed WezTerm Shift+Enter key binding\nSee: ${configPath}`,
361
- requiresRestart: true,
362
- };
363
- } catch (error) {
364
- return {
365
- success: false,
366
- message: `Failed to install WezTerm Shift+Enter key binding: ${error instanceof Error ? error.message : String(error)}`,
367
- };
368
- }
369
- }
370
-
371
- async function setupKittyKeybindings(): Promise<TerminalSetupResult> {
372
- const configPaths: string[] = [];
373
-
374
- const xdgConfigHome = process.env.XDG_CONFIG_HOME;
375
- if (xdgConfigHome) {
376
- configPaths.push(path.join(xdgConfigHome, "kitty", "kitty.conf"));
377
- } else {
378
- configPaths.push(path.join(os.homedir(), ".config", "kitty", "kitty.conf"));
379
- }
380
-
381
- if (process.platform === "darwin") {
382
- configPaths.push(path.join(os.homedir(), "Library", "Preferences", "kitty", "kitty.conf"));
383
- }
384
-
385
- let configPath: string | null = null;
386
- let configExists = false;
387
-
388
- for (const p of configPaths) {
389
- if (fs.existsSync(p)) {
390
- configPath = p;
391
- configExists = true;
392
- break;
393
- }
394
- }
395
-
396
- if (!configPath) {
397
- configPath = configPaths[0]!;
398
- }
399
-
400
- try {
401
- let content = "";
402
-
403
- if (configExists) {
404
- content = fs.readFileSync(configPath, "utf-8");
405
-
406
- if (content.includes("shift+enter") && content.includes("send_text")) {
407
- return {
408
- success: false,
409
- message: `Found existing Kitty Shift+Enter key binding. Remove it to continue.\nSee: ${configPath}`,
410
- };
411
- }
412
-
413
- const backupPath = createBackup(configPath);
414
- if (!backupPath) {
415
- return {
416
- success: false,
417
- message: `Failed to backup existing Kitty config`,
418
- };
419
- }
420
- } else {
421
- const configDir = path.dirname(configPath);
422
- if (!fs.existsSync(configDir)) {
423
- fs.mkdirSync(configDir, { recursive: true });
424
- }
425
- }
426
-
427
- let newContent = content;
428
- if (content && !content.endsWith("\n")) {
429
- newContent += "\n";
430
- }
431
- newContent += `map shift+enter send_text all ${SHIFT_ENTER_SEQUENCE}\n`;
432
-
433
- fs.writeFileSync(configPath, newContent, "utf-8");
434
-
435
- return {
436
- success: true,
437
- message: `Installed Kitty Shift+Enter key binding\nSee: ${configPath}`,
438
- requiresRestart: true,
439
- };
440
- } catch (error) {
441
- return {
442
- success: false,
443
- message: `Failed to install Kitty Shift+Enter key binding: ${error instanceof Error ? error.message : String(error)}`,
444
- };
445
- }
446
- }
447
-
448
- async function setupAlacrittyKeybindings(): Promise<TerminalSetupResult> {
449
- const configPaths: string[] = [];
450
-
451
- const xdgConfigHome = process.env.XDG_CONFIG_HOME;
452
- if (xdgConfigHome) {
453
- configPaths.push(path.join(xdgConfigHome, "alacritty", "alacritty.toml"));
454
- configPaths.push(path.join(xdgConfigHome, "alacritty", "alacritty.yml"));
455
- } else {
456
- configPaths.push(path.join(os.homedir(), ".config", "alacritty", "alacritty.toml"));
457
- configPaths.push(path.join(os.homedir(), ".config", "alacritty", "alacritty.yml"));
458
- }
459
-
460
- if (process.platform === "darwin") {
461
- configPaths.push(path.join(os.homedir(), ".alacritty.toml"));
462
- configPaths.push(path.join(os.homedir(), ".alacritty.yml"));
463
- }
464
-
465
- let configPath: string | null = null;
466
- let configExists = false;
467
- let isToml = true;
468
-
469
- for (const p of configPaths) {
470
- if (fs.existsSync(p)) {
471
- configPath = p;
472
- configExists = true;
473
- isToml = p.endsWith(".toml");
474
- break;
475
- }
476
- }
477
-
478
- if (!configPath) {
479
- configPath = configPaths[0]!;
480
- }
481
-
482
- try {
483
- let content = "";
484
-
485
- if (configExists) {
486
- content = fs.readFileSync(configPath, "utf-8");
487
-
488
- if (content.includes("Shift") && content.includes("Return")) {
489
- return {
490
- success: false,
491
- message: `Found existing Alacritty Shift+Enter key binding. Remove it to continue.\nSee: ${configPath}`,
492
- };
493
- }
494
-
495
- const backupPath = createBackup(configPath);
496
- if (!backupPath) {
497
- return {
498
- success: false,
499
- message: `Failed to backup existing Alacritty config`,
500
- };
501
- }
502
- } else {
503
- const configDir = path.dirname(configPath);
504
- if (!fs.existsSync(configDir)) {
505
- fs.mkdirSync(configDir, { recursive: true });
506
- }
507
- }
508
-
509
- let newContent = content;
510
- if (content && !content.endsWith("\n")) {
511
- newContent += "\n";
512
- }
513
-
514
- if (isToml) {
515
- newContent += `
516
- [[keyboard.bindings]]
517
- key = "Return"
518
- mods = "Shift"
519
- chars = "${SHIFT_ENTER_SEQUENCE}"
520
- `;
521
- } else {
522
- newContent += `
523
- key_bindings:
524
- - { key: Return, mods: Shift, chars: "${SHIFT_ENTER_SEQUENCE}" }
525
- `;
526
- }
527
-
528
- fs.writeFileSync(configPath, newContent, "utf-8");
529
-
530
- return {
531
- success: true,
532
- message: `Installed Alacritty Shift+Enter key binding\nSee: ${configPath}`,
533
- requiresRestart: true,
534
- };
535
- } catch (error) {
536
- return {
537
- success: false,
538
- message: `Failed to install Alacritty Shift+Enter key binding: ${error instanceof Error ? error.message : String(error)}`,
539
- };
540
- }
541
- }
542
-
543
- export async function setupTerminal(): Promise<TerminalSetupResult> {
544
- const terminal = getTerminal();
545
-
546
- if (!terminal) {
547
- return {
548
- success: false,
549
- message: "Could not detect terminal. You can use backslash (\\) + Enter for newlines.",
550
- };
551
- }
552
-
553
- switch (terminal) {
554
- case "cursor":
555
- return setupVSCodeKeybindings("Cursor");
556
- case "windsurf":
557
- return setupVSCodeKeybindings("Windsurf");
558
- case "vscode":
559
- return setupVSCodeKeybindings("Code");
560
- case "codium":
561
- return setupVSCodeKeybindings("VSCodium");
562
- case "ghostty":
563
- return setupGhosttyKeybindings();
564
- case "iTerm.app":
565
- return setupITerm2();
566
- case "Apple_Terminal":
567
- return setupAppleTerminal();
568
- case "WezTerm":
569
- return setupWezTermKeybindings();
570
- case "kitty":
571
- return setupKittyKeybindings();
572
- case "alacritty":
573
- return setupAlacrittyKeybindings();
574
- default:
575
- return {
576
- success: false,
577
- message: `Terminal "${terminal}" is not supported for automatic setup.\n\nYou can use backslash (\\) + Enter for newlines.\n\nSupported terminals:\n- VS Code, Cursor, Windsurf, VSCodium\n- Ghostty\n- iTerm2\n- Apple Terminal\n- WezTerm\n- Kitty\n- Alacritty`,
578
- };
579
- }
580
- }
581
-
582
- export function getTerminalSetupInstructions(terminal?: TerminalType): string {
583
- const detectedTerminal = terminal || getTerminal();
584
- const newlineInstruction = getNewlineInstructions();
585
-
586
- if (!detectedTerminal || detectedTerminal === "non-interactive") {
587
- return `
588
- Could not detect your terminal.
589
-
590
- Current newline instruction: ${newlineInstruction}
591
-
592
- If you're using a supported terminal, please report this at:
593
- https://github.com/anthropics/claude-code/issues
594
- `.trim();
595
- }
596
-
597
- const instructions: Record<string, string> = {
598
- cursor: `
599
- Detected Terminal: Cursor
600
-
601
- To enable Shift+Enter for newlines in Cursor's integrated terminal:
602
-
603
- 1. Open Cursor Settings (Cmd/Ctrl + ,)
604
- 2. Search for "keybindings"
605
- 3. Click "Open Keyboard Shortcuts (JSON)"
606
- 4. Add this keybinding:
607
-
608
- {
609
- "key": "shift+enter",
610
- "command": "workbench.action.terminal.sendSequence",
611
- "args": { "text": "\\u001b\\r" },
612
- "when": "terminalFocus"
613
- }
614
-
615
- 5. Save and reload Cursor
616
-
617
- Current newline instruction: ${newlineInstruction}
618
- `,
619
- windsurf: `
620
- Detected Terminal: Windsurf
621
-
622
- To enable Shift+Enter for newlines in Windsurf's integrated terminal:
623
-
624
- 1. Open Windsurf Settings (Cmd/Ctrl + ,)
625
- 2. Search for "keybindings"
626
- 3. Click "Open Keyboard Shortcuts (JSON)"
627
- 4. Add this keybinding:
628
-
629
- {
630
- "key": "shift+enter",
631
- "command": "workbench.action.terminal.sendSequence",
632
- "args": { "text": "\\u001b\\r" },
633
- "when": "terminalFocus"
634
- }
635
-
636
- 5. Save and reload Windsurf
637
-
638
- Current newline instruction: ${newlineInstruction}
639
- `,
640
- vscode: `
641
- Detected Terminal: Visual Studio Code
642
-
643
- To enable Shift+Enter for newlines in VS Code's integrated terminal:
644
-
645
- 1. Open VS Code Settings (Cmd/Ctrl + ,)
646
- 2. Search for "keybindings"
647
- 3. Click "Open Keyboard Shortcuts (JSON)"
648
- 4. Add this keybinding:
649
-
650
- {
651
- "key": "shift+enter",
652
- "command": "workbench.action.terminal.sendSequence",
653
- "args": { "text": "\\u001b\\r" },
654
- "when": "terminalFocus"
655
- }
656
-
657
- 5. Save and reload VS Code
658
-
659
- Current newline instruction: ${newlineInstruction}
660
- `,
661
- "iTerm.app": `
662
- Detected Terminal: iTerm2
663
-
664
- To enable Shift+Enter for newlines in iTerm2:
665
-
666
- 1. Open iTerm2 Preferences (Cmd + ,)
667
- 2. Go to "Keys" → "Key Bindings"
668
- 3. Click the "+" button to add a new key binding
669
- 4. Press Shift+Enter in the "Keyboard Shortcut" field
670
- 5. Set "Action" to "Send Escape Sequence"
671
- 6. Enter "\\r" (without quotes) in the text field
672
- 7. Click OK
673
-
674
- Current newline instruction: ${newlineInstruction}
675
- `,
676
- Apple_Terminal: `
677
- Detected Terminal: Apple Terminal
678
-
679
- Apple Terminal uses Option+Enter for newlines by default.
680
-
681
- Current newline instruction: ${newlineInstruction}
682
-
683
- No additional setup required!
684
- `,
685
- ghostty: `
686
- Detected Terminal: Ghostty
687
-
688
- To enable Shift+Enter for newlines in Ghostty:
689
-
690
- 1. Open your Ghostty config file:
691
- ~/.config/ghostty/config
692
-
693
- 2. Add this line:
694
- keybind = shift+enter=text:\\x1b\\r
695
-
696
- 3. Save and reload Ghostty
697
-
698
- Current newline instruction: ${newlineInstruction}
699
- `,
700
- WezTerm: `
701
- Detected Terminal: WezTerm
702
-
703
- To enable Shift+Enter for newlines in WezTerm:
704
-
705
- 1. Open your WezTerm config file:
706
- ~/.wezterm.lua (or ~/.config/wezterm/wezterm.lua)
707
-
708
- 2. Add this configuration:
709
-
710
- config.keys = {
711
- {
712
- key = 'Enter',
713
- mods = 'SHIFT',
714
- action = wezterm.action.SendString '\\x1b\\r',
715
- },
716
- }
717
-
718
- 3. Save and reload WezTerm
719
-
720
- Current newline instruction: ${newlineInstruction}
721
- `,
722
- kitty: `
723
- Detected Terminal: Kitty
724
-
725
- To enable Shift+Enter for newlines in Kitty:
726
-
727
- 1. Open your Kitty config file:
728
- ~/.config/kitty/kitty.conf
729
-
730
- 2. Add this line:
731
- map shift+enter send_text all \\x1b\\r
732
-
733
- 3. Save and reload Kitty (Cmd/Ctrl + Shift + F5)
734
-
735
- Current newline instruction: ${newlineInstruction}
736
- `,
737
- alacritty: `
738
- Detected Terminal: Alacritty
739
-
740
- To enable Shift+Enter for newlines in Alacritty:
741
-
742
- 1. Open your Alacritty config file:
743
- ~/.config/alacritty/alacritty.yml (or alacritty.toml for newer versions)
744
-
745
- 2. Add this configuration:
746
-
747
- For YAML:
748
- key_bindings:
749
- - { key: Return, mods: Shift, chars: "\\x1b\\r" }
750
-
751
- For TOML:
752
- [[keyboard.bindings]]
753
- key = "Return"
754
- mods = "Shift"
755
- chars = "\\x1b\\r"
756
-
757
- 3. Save and reload Alacritty
758
-
759
- Current newline instruction: ${newlineInstruction}
760
- `,
761
- "windows-terminal": `
762
- Detected Terminal: Windows Terminal
763
-
764
- To enable Shift+Enter for newlines in Windows Terminal:
765
-
766
- 1. Open Windows Terminal Settings (Ctrl + ,)
767
- 2. Click "Open JSON file" in the bottom left
768
- 3. Add this to the "actions" array:
769
-
770
- {
771
- "command": { "action": "sendInput", "input": "\\u001b\\r" },
772
- "keys": "shift+enter"
773
- }
774
-
775
- 4. Save and restart Windows Terminal
776
-
777
- Current newline instruction: ${newlineInstruction}
778
- `,
779
- };
780
-
781
- const instruction = instructions[detectedTerminal];
782
- if (instruction) {
783
- return instruction.trim();
784
- }
785
-
786
- return `
787
- Detected Terminal: ${detectedTerminal}
788
-
789
- Current newline instruction: ${newlineInstruction}
790
-
791
- Terminal-specific setup instructions are not available for this terminal.
792
- You can use backslash (\\) + Enter for newlines as a fallback.
793
-
794
- If you'd like support for your terminal, please report it at:
795
- https://github.com/anthropics/claude-code/issues
796
- `.trim();
797
- }