@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,797 @@
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
+ }