@thegitai/cli 1.0.0-preview.6 → 1.0.0-preview.60

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 (90) hide show
  1. package/README.md +229 -7
  2. package/dist/bin/ai.js +140 -111
  3. package/dist/bin/browser-host.js +265 -0
  4. package/dist/src/agent-mode.js +32 -7
  5. package/dist/src/api/auth.js +8 -2
  6. package/dist/src/api/browser-login.js +147 -35
  7. package/dist/src/api/chat.js +691 -166
  8. package/dist/src/api/contracts.js +55 -1
  9. package/dist/src/api/default-host.js +1 -0
  10. package/dist/src/api/http.js +139 -8
  11. package/dist/src/api/models.js +34 -9
  12. package/dist/src/api/startup-handshake.js +36 -0
  13. package/dist/src/api/turn-recovery.js +189 -0
  14. package/dist/src/background-jobs.js +8 -2
  15. package/dist/src/browser/bridge.js +262 -0
  16. package/dist/src/browser/framing.js +42 -0
  17. package/dist/src/browser/native-host.js +219 -0
  18. package/dist/src/browser/protocol.js +46 -0
  19. package/dist/src/browser/session-bridge.js +130 -0
  20. package/dist/src/cli-args.js +19 -5
  21. package/dist/src/client-environment.js +2 -0
  22. package/dist/src/core/clipboard.js +7 -13
  23. package/dist/src/core/image-limits.js +56 -0
  24. package/dist/src/core/image-path-extractor.js +70 -3
  25. package/dist/src/core/session-image-store.js +246 -0
  26. package/dist/src/edit-journal.js +33 -2
  27. package/dist/src/executor.js +25 -3
  28. package/dist/src/help-text.js +128 -22
  29. package/dist/src/job-follow-up.js +40 -0
  30. package/dist/src/mcp-client.js +335 -0
  31. package/dist/src/mcp-command.js +176 -0
  32. package/dist/src/mcp-config.js +123 -0
  33. package/dist/src/mcp-sdk.js +3 -0
  34. package/dist/src/mcp-types.js +26 -0
  35. package/dist/src/patcher.js +43 -4
  36. package/dist/src/permissions.js +301 -0
  37. package/dist/src/preferences.js +39 -0
  38. package/dist/src/project-key.js +11 -0
  39. package/dist/src/project-model-preferences.js +74 -0
  40. package/dist/src/quota-notice.js +35 -0
  41. package/dist/src/reasoning-effort.js +27 -0
  42. package/dist/src/session-safety.js +0 -12
  43. package/dist/src/session-store.js +123 -30
  44. package/dist/src/session.js +20 -4
  45. package/dist/src/signin.js +58 -0
  46. package/dist/src/tool-executor.js +23 -49
  47. package/dist/src/tools/browser.js +641 -0
  48. package/dist/src/tools/delete-file.js +20 -4
  49. package/dist/src/tools/index.js +32 -10
  50. package/dist/src/tools/patch-file.js +12 -26
  51. package/dist/src/tools/read-file.js +5 -0
  52. package/dist/src/tools/read-image-file.js +85 -0
  53. package/dist/src/tools/replace-document-text.js +28 -18
  54. package/dist/src/tools/restore-checkpoint.js +0 -1
  55. package/dist/src/tools/run-command.js +14 -71
  56. package/dist/src/tools/run-node-script.js +12 -81
  57. package/dist/src/tools/save-generated-image.js +120 -0
  58. package/dist/src/tools/str-replace.js +12 -26
  59. package/dist/src/tools/undo-edit.js +1 -6
  60. package/dist/src/tools/write-file.js +67 -11
  61. package/dist/src/ui/prompt-history-store.js +1 -1
  62. package/dist/src/ui/repl.js +1017 -299
  63. package/dist/src/ui/slash-commands.js +122 -0
  64. package/dist/src/ui/tui/attention.js +25 -0
  65. package/dist/src/ui/tui/bridge.js +38 -5
  66. package/dist/src/ui/tui/build-frame.js +807 -270
  67. package/dist/src/ui/tui/composer-layout.js +76 -0
  68. package/dist/src/ui/tui/desktop-notification.js +118 -0
  69. package/dist/src/ui/tui/markdown-render.js +21 -11
  70. package/dist/src/ui/tui/model-label.js +13 -0
  71. package/dist/src/ui/tui/shell-input.js +275 -73
  72. package/dist/src/ui/tui/shortcuts.js +61 -0
  73. package/dist/src/ui/tui/terminal-theme.js +28 -0
  74. package/dist/src/ui/tui/text.js +31 -6
  75. package/dist/src/ui/tui/user-input.js +593 -0
  76. package/dist/src/update-check.js +205 -0
  77. package/dist/src/usage-notice.js +52 -0
  78. package/dist/src/usage.js +5 -2
  79. package/dist/src/utils.js +13 -0
  80. package/dist/src/version.js +52 -2
  81. package/dist/vendor/mcp/LICENSES.txt +414 -0
  82. package/dist/vendor/mcp/client.cjs +82 -0
  83. package/package.json +22 -9
  84. package/dist/src/project-index.js +0 -233
  85. package/dist/src/tools/code-intel.js +0 -472
  86. package/dist/src/tools/find-symbol.js +0 -70
  87. package/dist/src/tools/hover-symbol.js +0 -95
  88. package/dist/src/tools/list-symbols.js +0 -55
  89. package/dist/src/tools/search-code.js +0 -37
  90. package/dist/src/tools/signature-help.js +0 -118
@@ -1,6 +1,14 @@
1
+ import { projectModelEffort } from '../../project-model-preferences.js';
2
+ import { cycleReasoningEffort } from '../../reasoning-effort.js';
3
+ import { shortcutsPanelAvailable } from './shortcuts.js';
4
+ import { moveComposerCursorVertically } from './composer-layout.js';
1
5
  import { readClipboardImage, readClipboardText } from '../../core/clipboard.js';
2
- import { applySlashCommandSuggestion, buildModelPickerOptions, deleteAtCursor, deleteBeforeCursor, getApprovalChoiceForCursor, getInputCommandToken, getNextApprovalCursor, getNextModelPickerIndex, getSlashCommandSuggestions, insertAtCursor, isExactSlashCommandToken, navigatePromptHistory, resolveApprovalChoiceFromInput, shouldRemountLiveFrameForComposerInputChange, } from '../repl.js';
6
+ import { MAX_IMAGES_PER_MESSAGE, MAX_TOTAL_IMAGE_BYTES_PER_MESSAGE, approximateBase64DecodedBytes, totalAttachmentBytes, } from '../../core/image-limits.js';
7
+ import { tryCacheAttachmentBytes } from '../../core/session-image-store.js';
8
+ import { applySlashCommandSuggestion, buildModelPickerOptions, deleteAtCursor, deleteBeforeCursor, getInputCommandToken, getNextApprovalCursor, getNextModelPickerIndex, getSlashCommandSuggestions, insertAtCursor, navigatePromptHistory, shouldRemountLiveFrameForComposerInputChange, slashCommandMatchesToken, } from '../repl.js';
3
9
  import { buildPastePlaceholder, shouldCollapsePaste, } from '../paste-collapse.js';
10
+ import { handleUserInputPromptEvent, } from './user-input.js';
11
+ const APPROVAL_PREVIEW_PAGE_ROWS = 3;
4
12
  function isClipboardImagePasteKey(key) {
5
13
  if (process.platform === 'win32') {
6
14
  return ((key.ctrl || key.meta) &&
@@ -9,6 +17,38 @@ function isClipboardImagePasteKey(key) {
9
17
  }
10
18
  return key.ctrl && key.input === 'v' && !key.shift && !key.meta;
11
19
  }
20
+ export const APPROVAL_INPUT_GUARD_MS = 500;
21
+ function approvalIsGuarded(state) {
22
+ const openedAt = state.approvalOpenedAt;
23
+ if (typeof openedAt !== 'number')
24
+ return false;
25
+ return Date.now() - openedAt < APPROVAL_INPUT_GUARD_MS;
26
+ }
27
+ function applyUserInputPromptEvent(store, handlers, event) {
28
+ const current = store.getState();
29
+ if (!current.userInputPrompt)
30
+ return false;
31
+ const outcome = handleUserInputPromptEvent(current.userInputPrompt, event, handlers.getUserInputViewport?.());
32
+ store.update((state) => ({
33
+ ...state,
34
+ userInputPrompt: outcome.state,
35
+ }));
36
+ if (outcome.result) {
37
+ void handlers.onResolveUserInput?.(outcome.result);
38
+ }
39
+ return true;
40
+ }
41
+ function composerIsEmpty(state) {
42
+ return (!state.input &&
43
+ state.cursor === 0 &&
44
+ state.pastedChunks.length === 0 &&
45
+ state.promptHistoryCursor === null);
46
+ }
47
+ function composerHasDiscardableDraft(state) {
48
+ if (!composerIsEmpty(state))
49
+ return true;
50
+ return !state.busy && state.imageAttachments.length > 0;
51
+ }
12
52
  function shouldShowCommandPalette(state) {
13
53
  if (state.busy ||
14
54
  state.exiting ||
@@ -18,7 +58,9 @@ function shouldShowCommandPalette(state) {
18
58
  return false;
19
59
  }
20
60
  const token = getInputCommandToken(state.input);
21
- return token.startsWith('/') && !token.includes(' ');
61
+ if (!token.startsWith('/') || state.input.includes(' '))
62
+ return false;
63
+ return getSlashCommandSuggestions(state.input).length > 0;
22
64
  }
23
65
  function insertPastedText(store, handlers, text) {
24
66
  const current = store.getState();
@@ -68,12 +110,47 @@ function pasteTextFromClipboard(store, handlers) {
68
110
  if (!text) {
69
111
  store.update((state) => ({
70
112
  ...state,
71
- status: 'Clipboard has no text to paste',
113
+ transientStatus: 'Clipboard has no text to paste',
72
114
  }));
73
115
  return;
74
116
  }
75
117
  insertPastedText(store, handlers, text);
76
118
  }
119
+ function scrollTranscript(store, handlers, delta) {
120
+ if (delta === 0)
121
+ return;
122
+ store.update((current) => {
123
+ const limit = handlers.getTranscriptScrollLimit?.() ??
124
+ current.transcript.reduce((total, entry) => total + 2 + (entry.body ? entry.body.split('\n').length : 0), 0);
125
+ const next = current.transcriptScrollOffset + delta;
126
+ return {
127
+ ...current,
128
+ transcriptScrollOffset: Math.max(0, Math.min(next, limit)),
129
+ };
130
+ });
131
+ }
132
+ function scrollTranscriptTo(store, handlers, offset) {
133
+ store.update((current) => {
134
+ const limit = handlers.getTranscriptScrollLimit?.() ??
135
+ current.transcript.reduce((total, entry) => total + 2 + (entry.body ? entry.body.split('\n').length : 0), 0);
136
+ return {
137
+ ...current,
138
+ transcriptScrollOffset: Math.max(0, Math.min(Math.trunc(offset), limit)),
139
+ };
140
+ });
141
+ }
142
+ function scrollApprovalPreview(store, handlers, delta) {
143
+ if (delta === 0)
144
+ return;
145
+ store.update((current) => {
146
+ const limit = handlers.getApprovalScrollLimit?.() ?? 0;
147
+ const next = (current.approvalScrollOffset ?? 0) + delta;
148
+ return {
149
+ ...current,
150
+ approvalScrollOffset: Math.max(0, Math.min(next, limit)),
151
+ };
152
+ });
153
+ }
77
154
  function filterResumeSessionsLocal(sessions, filter, serverModels) {
78
155
  const q = filter.trim().toLowerCase();
79
156
  if (!q)
@@ -88,6 +165,12 @@ function filterResumeSessionsLocal(sessions, filter, serverModels) {
88
165
  }
89
166
  export function handleShellKeyEvent(store, handlers, event) {
90
167
  if (event.kind === 'paste') {
168
+ if (applyUserInputPromptEvent(store, handlers, {
169
+ kind: 'paste',
170
+ text: event.text,
171
+ })) {
172
+ return;
173
+ }
91
174
  insertPastedText(store, handlers, event.text);
92
175
  return;
93
176
  }
@@ -110,33 +193,67 @@ export function handleShellKeyEvent(store, handlers, event) {
110
193
  return;
111
194
  }
112
195
  if (event.kind === 'contextMenu') {
196
+ if (store.getState().userInputPrompt) {
197
+ const text = (handlers.readClipboardText ?? readClipboardText)();
198
+ if (text) {
199
+ applyUserInputPromptEvent(store, handlers, { kind: 'paste', text });
200
+ }
201
+ return;
202
+ }
113
203
  pasteTextFromClipboard(store, handlers);
114
204
  return;
115
205
  }
116
206
  if (event.kind === 'transcriptScroll') {
117
- const delta = Math.trunc(event.deltaLines);
118
- if (delta !== 0) {
119
- store.update((current) => {
120
- const limit = handlers.getTranscriptScrollLimit?.() ??
121
- current.transcript.reduce((total, entry) => total + 2 + (entry.body ? entry.body.split('\n').length : 0), 0);
122
- const next = current.transcriptScrollOffset + delta;
123
- return {
124
- ...current,
125
- transcriptScrollOffset: Math.max(0, Math.min(next, limit)),
126
- };
127
- });
128
- }
207
+ scrollTranscript(store, handlers, Math.trunc(event.deltaLines));
208
+ return;
209
+ }
210
+ if (event.kind === 'transcriptScrollTo') {
211
+ scrollTranscriptTo(store, handlers, Number(event.offset ?? 0));
129
212
  return;
130
213
  }
131
214
  if (event.kind !== 'key')
132
215
  return;
133
216
  const key = event;
134
217
  const state = store.getState();
218
+ const commandPaletteActive = shouldShowCommandPalette(state);
219
+ const commandSuggestions = commandPaletteActive
220
+ ? getSlashCommandSuggestions(state.input)
221
+ : [];
222
+ const prepareForComposerInputChange = (current, nextInput) => {
223
+ if (shouldRemountLiveFrameForComposerInputChange(current, nextInput)) {
224
+ handlers.onLiveFrameShapeChange();
225
+ }
226
+ };
135
227
  if (key.ctrl && key.input === 'c') {
228
+ if (state.userInputPrompt) {
229
+ handlers.onCtrlC?.();
230
+ return;
231
+ }
136
232
  if (state.sudoPrompt) {
137
233
  handlers.onSudoPasswordInput({ kind: 'cancel' });
138
234
  return;
139
235
  }
236
+ if (state.queuedMessage) {
237
+ handlers.onLiveFrameShapeChange();
238
+ store.update((current) => ({ ...current, queuedMessage: null }));
239
+ return;
240
+ }
241
+ if (composerHasDiscardableDraft(state)) {
242
+ store.update((current) => {
243
+ prepareForComposerInputChange(current, '');
244
+ return {
245
+ ...current,
246
+ commandCursor: 0,
247
+ cursor: 0,
248
+ imageAttachments: current.busy ? current.imageAttachments : [],
249
+ input: '',
250
+ pastedChunks: [],
251
+ promptHistoryCursor: null,
252
+ promptHistoryDraft: '',
253
+ };
254
+ });
255
+ return;
256
+ }
140
257
  if (handlers.onCtrlC) {
141
258
  handlers.onCtrlC();
142
259
  return;
@@ -144,15 +261,10 @@ export function handleShellKeyEvent(store, handlers, event) {
144
261
  handlers.onRequestExit();
145
262
  return;
146
263
  }
147
- const commandPaletteActive = shouldShowCommandPalette(state);
148
- const commandSuggestions = commandPaletteActive
149
- ? getSlashCommandSuggestions(state.input)
150
- : [];
151
- const prepareForComposerInputChange = (current, nextInput) => {
152
- if (shouldRemountLiveFrameForComposerInputChange(current, nextInput)) {
153
- handlers.onLiveFrameShapeChange();
154
- }
155
- };
264
+ if (state.userInputPrompt &&
265
+ applyUserInputPromptEvent(store, handlers, key)) {
266
+ return;
267
+ }
156
268
  if (state.sudoPrompt) {
157
269
  if (key.escape) {
158
270
  handlers.onSudoPasswordInput({ kind: 'cancel' });
@@ -176,24 +288,32 @@ export function handleShellKeyEvent(store, handlers, event) {
176
288
  return;
177
289
  }
178
290
  if (state.approvalPrompt) {
179
- const directChoice = resolveApprovalChoiceFromInput(key.input);
180
- if (directChoice) {
181
- void handlers.onResolveApproval(directChoice);
182
- return;
183
- }
184
- if (key.escape) {
185
- void handlers.onResolveApproval('n');
291
+ if (key.pageUp || key.pageDown) {
292
+ const delta = key.pageUp ? -APPROVAL_PREVIEW_PAGE_ROWS : APPROVAL_PREVIEW_PAGE_ROWS;
293
+ if (key.shift) {
294
+ scrollTranscript(store, handlers, key.pageUp ? 8 : -8);
295
+ }
296
+ else {
297
+ scrollApprovalPreview(store, handlers, delta);
298
+ }
186
299
  return;
187
300
  }
188
301
  if (key.upArrow || key.downArrow) {
189
302
  store.update((current) => ({
190
303
  ...current,
191
- approvalCursor: getNextApprovalCursor(current.approvalCursor, key.upArrow ? -1 : 1),
304
+ approvalCursor: getNextApprovalCursor(current.approvalCursor, key.upArrow ? -1 : 1, current.approvalPrompt?.options?.length ?? 0),
192
305
  }));
193
306
  return;
194
307
  }
308
+ if (approvalIsGuarded(state)) {
309
+ return;
310
+ }
311
+ if (key.escape) {
312
+ void handlers.onResolveApproval(-1);
313
+ return;
314
+ }
195
315
  if (key.returnKey) {
196
- void handlers.onResolveApproval(getApprovalChoiceForCursor(state.approvalCursor));
316
+ void handlers.onResolveApproval(state.approvalCursor);
197
317
  }
198
318
  return;
199
319
  }
@@ -201,24 +321,18 @@ export function handleShellKeyEvent(store, handlers, event) {
201
321
  return;
202
322
  }
203
323
  if (key.pageUp || key.pageDown) {
204
- store.update((current) => {
205
- const transcriptLines = handlers.getTranscriptScrollLimit?.() ??
206
- current.transcript.reduce((total, entry) => total + 2 + (entry.body ? entry.body.split('\n').length : 0), 0);
207
- const next = current.transcriptScrollOffset + (key.pageUp ? 8 : -8);
208
- return {
209
- ...current,
210
- transcriptScrollOffset: Math.max(0, Math.min(next, transcriptLines)),
211
- };
212
- });
324
+ scrollTranscript(store, handlers, key.pageUp ? 8 : -8);
213
325
  return;
214
326
  }
215
327
  if (state.jobsPickerOpen) {
216
- if (key.escape) {
328
+ if (key.escape || (key.ctrl && key.input === 'b' && !key.meta && !key.shift)) {
329
+ handlers.onLiveFrameShapeChange();
217
330
  store.update((current) => ({
218
331
  ...current,
219
332
  jobsPickerExpandedId: null,
220
333
  jobsPickerOpen: false,
221
- status: 'Ready',
334
+ jobsPickerReturnStatus: null,
335
+ status: current.jobsPickerReturnStatus ?? 'Ready',
222
336
  }));
223
337
  return;
224
338
  }
@@ -258,6 +372,23 @@ export function handleShellKeyEvent(store, handlers, event) {
258
372
  });
259
373
  return;
260
374
  }
375
+ if (key.leftArrow || key.rightArrow) {
376
+ store.update((current) => {
377
+ const options = buildModelPickerOptions(Number(current.currentModelId ?? 0), current.serverModels ?? []);
378
+ const model = options[current.modelPickerIndex];
379
+ if (!model || model.group === 'auto')
380
+ return current;
381
+ const efforts = current.modelPickerEfforts ?? {};
382
+ return {
383
+ ...current,
384
+ modelPickerEfforts: {
385
+ ...efforts,
386
+ [String(model.publicId)]: cycleReasoningEffort(projectModelEffort(efforts, model.publicId), key.leftArrow ? -1 : 1),
387
+ },
388
+ };
389
+ });
390
+ return;
391
+ }
261
392
  if (key.returnKey) {
262
393
  void handlers.onSelectModel();
263
394
  }
@@ -306,6 +437,28 @@ export function handleShellKeyEvent(store, handlers, event) {
306
437
  }
307
438
  return;
308
439
  }
440
+ if (state.shortcutsOpen) {
441
+ if (key.escape || key.returnKey || key.input === '?' || key.input === 'q') {
442
+ handlers.onLiveFrameShapeChange();
443
+ store.update((current) => ({ ...current, shortcutsOpen: false }));
444
+ }
445
+ return;
446
+ }
447
+ if (key.ctrl && key.input === 'b' && !key.meta && !key.shift) {
448
+ if ((state.backgroundJobs ?? []).length > 0) {
449
+ handlers.onOpenJobsPicker();
450
+ }
451
+ return;
452
+ }
453
+ if (key.ctrl && key.input === 'g' && !key.meta && !key.shift) {
454
+ handlers.onToggleNotifications?.();
455
+ return;
456
+ }
457
+ if (key.input === '?' && !key.ctrl && !key.meta && shortcutsPanelAvailable(state)) {
458
+ handlers.onLiveFrameShapeChange();
459
+ store.update((current) => ({ ...current, shortcutsOpen: true }));
460
+ return;
461
+ }
309
462
  if (key.escape) {
310
463
  if (state.busy) {
311
464
  if (state.queuedMessage) {
@@ -317,10 +470,7 @@ export function handleShellKeyEvent(store, handlers, event) {
317
470
  return;
318
471
  }
319
472
  store.update((current) => {
320
- if (!current.input &&
321
- current.cursor === 0 &&
322
- current.pastedChunks.length === 0 &&
323
- current.promptHistoryCursor === null) {
473
+ if (composerIsEmpty(current)) {
324
474
  return current;
325
475
  }
326
476
  prepareForComposerInputChange(current, '');
@@ -337,9 +487,22 @@ export function handleShellKeyEvent(store, handlers, event) {
337
487
  return;
338
488
  }
339
489
  if (key.tab && key.shift) {
490
+ if (state.busy) {
491
+ handlers.onAgentModeChangeBlocked?.();
492
+ return;
493
+ }
340
494
  handlers.onCycleAgentMode();
341
495
  return;
342
496
  }
497
+ if (state.busy && state.queuedMessage) {
498
+ if (key.returnKey) {
499
+ void handlers.onFireQueuedMessage?.();
500
+ return;
501
+ }
502
+ if (!key.upArrow && !isClipboardImagePasteKey(key)) {
503
+ return;
504
+ }
505
+ }
343
506
  if (commandPaletteActive && (key.upArrow || key.downArrow)) {
344
507
  store.update((current) => ({
345
508
  ...current,
@@ -348,7 +511,7 @@ export function handleShellKeyEvent(store, handlers, event) {
348
511
  return;
349
512
  }
350
513
  if (key.upArrow) {
351
- if (state.busy && state.input.trim() === '' && state.queuedMessage) {
514
+ if (state.busy && state.queuedMessage) {
352
515
  handlers.onLiveFrameShapeChange();
353
516
  store.update((current) => {
354
517
  const queued = current.queuedMessage;
@@ -367,9 +530,13 @@ export function handleShellKeyEvent(store, handlers, event) {
367
530
  });
368
531
  return;
369
532
  }
370
- if (state.busy)
533
+ const nextCursor = moveComposerCursorVertically(state.input, state.cursor, handlers.getComposerInputWidth?.() ?? Number.POSITIVE_INFINITY, -1);
534
+ if (nextCursor === null && state.busy)
371
535
  return;
372
536
  store.update((current) => {
537
+ if (nextCursor !== null) {
538
+ return { ...current, commandCursor: 0, cursor: nextCursor };
539
+ }
373
540
  const next = navigatePromptHistory(current, 'previous');
374
541
  prepareForComposerInputChange(current, next.input);
375
542
  return next;
@@ -377,9 +544,13 @@ export function handleShellKeyEvent(store, handlers, event) {
377
544
  return;
378
545
  }
379
546
  if (key.downArrow) {
380
- if (state.busy)
547
+ const nextCursor = moveComposerCursorVertically(state.input, state.cursor, handlers.getComposerInputWidth?.() ?? Number.POSITIVE_INFINITY, 1);
548
+ if (nextCursor === null && state.busy)
381
549
  return;
382
550
  store.update((current) => {
551
+ if (nextCursor !== null) {
552
+ return { ...current, commandCursor: 0, cursor: nextCursor };
553
+ }
383
554
  const next = navigatePromptHistory(current, 'next');
384
555
  prepareForComposerInputChange(current, next.input);
385
556
  return next;
@@ -399,10 +570,10 @@ export function handleShellKeyEvent(store, handlers, event) {
399
570
  }
400
571
  if (key.returnKey) {
401
572
  const token = getInputCommandToken(state.input);
402
- if (commandPaletteActive && !isExactSlashCommandToken(token)) {
403
- const suggestion = commandSuggestions[Math.min(state.commandCursor, commandSuggestions.length - 1)];
404
- if (!suggestion)
405
- return;
573
+ const suggestion = commandSuggestions[Math.min(state.commandCursor, commandSuggestions.length - 1)];
574
+ if (commandPaletteActive &&
575
+ suggestion &&
576
+ !slashCommandMatchesToken(suggestion, token)) {
406
577
  store.update((current) => {
407
578
  const nextInput = applySlashCommandSuggestion(current.input, suggestion);
408
579
  prepareForComposerInputChange(current, nextInput.input);
@@ -467,12 +638,16 @@ export function handleShellKeyEvent(store, handlers, event) {
467
638
  }
468
639
  if (isClipboardImagePasteKey(key)) {
469
640
  const current = store.getState();
470
- if (current.busy)
471
- return;
472
- const liveAttachments = current.imageAttachments.filter((attachment) => current.input.includes(`[Image #${attachment.index}]`));
473
- if (liveAttachments.length >= 2) {
641
+ const target = current.queuedMessage
642
+ ? {
643
+ body: current.queuedMessage.body,
644
+ attachments: current.queuedMessage.imageAttachments,
645
+ }
646
+ : { body: current.input, attachments: current.imageAttachments };
647
+ const liveAttachments = target.attachments.filter((attachment) => target.body.includes(`[Image #${attachment.index}]`));
648
+ if (liveAttachments.length >= MAX_IMAGES_PER_MESSAGE) {
474
649
  store.appendEntry({
475
- body: 'Maximum of 2 images per message. Send the current message first.',
650
+ body: `Maximum of ${MAX_IMAGES_PER_MESSAGE} images per message. Send the current message first.`,
476
651
  kind: 'error',
477
652
  title: 'Image',
478
653
  });
@@ -480,22 +655,49 @@ export function handleShellKeyEvent(store, handlers, event) {
480
655
  }
481
656
  try {
482
657
  const clipResult = readClipboardImage();
658
+ if (totalAttachmentBytes(liveAttachments) +
659
+ approximateBase64DecodedBytes(clipResult.base64Data) >
660
+ MAX_TOTAL_IMAGE_BYTES_PER_MESSAGE) {
661
+ store.appendEntry({
662
+ body: `This image would put the message over the ${Math.round(MAX_TOTAL_IMAGE_BYTES_PER_MESSAGE / 1024 / 1024)}MB combined image limit. Send the current message first.`,
663
+ kind: 'error',
664
+ title: 'Image',
665
+ });
666
+ return;
667
+ }
483
668
  const idx = liveAttachments.length === 0
484
669
  ? 1
485
670
  : Math.max(...liveAttachments.map((attachment) => attachment.index)) + 1;
486
- store.update((shellState) => ({
487
- ...shellState,
488
- imageAttachments: [
489
- ...liveAttachments,
490
- {
491
- index: idx,
492
- mimeType: clipResult.mimeType,
493
- base64Data: clipResult.base64Data,
494
- source: 'clipboard',
495
- },
496
- ],
497
- ...insertAtCursor(shellState, `[Image #${idx}] `),
498
- }));
671
+ const cached = tryCacheAttachmentBytes({
672
+ base64Data: clipResult.base64Data,
673
+ mimeType: clipResult.mimeType,
674
+ });
675
+ const attachment = {
676
+ index: cached?.index ?? idx,
677
+ mimeType: clipResult.mimeType,
678
+ base64Data: clipResult.base64Data,
679
+ source: 'clipboard',
680
+ ...(cached ? { cachePath: cached.cachePath } : {}),
681
+ };
682
+ const marker = attachment.index;
683
+ store.update((shellState) => {
684
+ const nextAttachments = [...liveAttachments, attachment];
685
+ if (shellState.queuedMessage) {
686
+ return {
687
+ ...shellState,
688
+ queuedMessage: {
689
+ ...shellState.queuedMessage,
690
+ body: `${shellState.queuedMessage.body} [Image #${marker}]`.trim(),
691
+ imageAttachments: nextAttachments,
692
+ },
693
+ };
694
+ }
695
+ return {
696
+ ...shellState,
697
+ imageAttachments: nextAttachments,
698
+ ...insertAtCursor(shellState, `[Image #${marker}] `),
699
+ };
700
+ });
499
701
  }
500
702
  catch (error) {
501
703
  if (error?.code === 'NO_IMAGE') {
@@ -0,0 +1,61 @@
1
+ import { agentModeCycleSequence } from '../../agent-mode.js';
2
+ export function shortcutsPanelAvailable(state) {
3
+ return (!state.exiting &&
4
+ !state.approvalPrompt &&
5
+ !state.sudoPrompt &&
6
+ !state.userInputPrompt &&
7
+ !state.queuedMessage &&
8
+ !state.input &&
9
+ (state.cursor ?? 0) === 0 &&
10
+ (state.pastedChunks?.length ?? 0) === 0 &&
11
+ state.promptHistoryCursor == null);
12
+ }
13
+ export function buildShortcutGroups(platform = process.platform) {
14
+ const imagePaste = platform === 'win32' ? 'Alt+V' : 'Ctrl+V';
15
+ const textPaste = platform === 'darwin' ? 'Cmd+V' : 'Ctrl+Shift+V';
16
+ return [
17
+ {
18
+ title: 'Composer',
19
+ rows: [
20
+ { keys: 'Enter', description: 'Send your message' },
21
+ {
22
+ keys: 'Shift+Tab',
23
+ description: `Cycle ${agentModeCycleSequence()} (between turns)`,
24
+ },
25
+ { keys: '/', description: 'Slash commands — /help lists them all' },
26
+ { keys: '↑ / ↓', description: 'Earlier prompts' },
27
+ { keys: 'Esc', description: 'Clear the composer' },
28
+ { keys: 'Ctrl+C', description: 'Clear the composer, or quit when empty' },
29
+ { keys: 'Ctrl+G', description: 'Desktop notifications — toggle on or off' },
30
+ ],
31
+ },
32
+ {
33
+ title: 'While the agent is working',
34
+ rows: [
35
+ { keys: 'Enter', description: 'Queue a message; Enter again sends it into the turn' },
36
+ { keys: '↑', description: 'Bring a queued message back to edit it' },
37
+ { keys: 'Esc', description: 'Discard the queued message, or cancel the turn' },
38
+ { keys: 'Ctrl+C', description: 'Cancel the turn' },
39
+ { keys: 'Ctrl+B', description: 'Background jobs' },
40
+ ],
41
+ },
42
+ {
43
+ title: 'Clipboard & images',
44
+ rows: [
45
+ { keys: imagePaste, description: 'Paste a screenshot into the message' },
46
+ { keys: textPaste, description: 'Paste text (your terminal’s own shortcut)' },
47
+ { keys: 'Right-click', description: 'Paste, or copy the link under the cursor' },
48
+ ],
49
+ },
50
+ {
51
+ title: 'Transcript',
52
+ rows: [
53
+ { keys: 'PageUp / PageDown', description: 'Scroll — the mouse wheel works too' },
54
+ { keys: 'Drag', description: 'Select and copy' },
55
+ { keys: 'Double-click', description: 'Copy a word' },
56
+ { keys: 'Triple-click', description: 'Copy a whole row' },
57
+ { keys: 'Left-click', description: 'Open a link' },
58
+ ],
59
+ },
60
+ ];
61
+ }
@@ -0,0 +1,28 @@
1
+ export function isDarkTerminalBackground(env = process.env) {
2
+ const raw = String(env.COLORFGBG ?? '').trim();
3
+ if (!raw)
4
+ return false;
5
+ const parts = raw
6
+ .split(/[;:]/)
7
+ .map((part) => part.trim())
8
+ .filter(Boolean);
9
+ const bgToken = parts[parts.length - 1];
10
+ if (!bgToken)
11
+ return false;
12
+ const bg = Number(bgToken);
13
+ if (!Number.isFinite(bg))
14
+ return false;
15
+ return bg >= 0 && bg < 7;
16
+ }
17
+ export function mutedStyle(env = process.env) {
18
+ if (isDarkTerminalBackground(env)) {
19
+ return { color: 'ansi256(247)' };
20
+ }
21
+ return { color: 'gray' };
22
+ }
23
+ export function mutedColor(env = process.env) {
24
+ if (isDarkTerminalBackground(env)) {
25
+ return 'ansi256(247)';
26
+ }
27
+ return 'gray';
28
+ }
@@ -1,17 +1,42 @@
1
- const CSI_PATTERN = /\u001B\[[0-9;?]*[ -\/]*[@-~]/g;
2
- const OSC_PATTERN = /\u001B\][^\u0007\u001B]*(?:\u0007|\u001B\\)?/g;
3
- const CONTROL_CHAR_PATTERN = /[\u0000-\u0008\u000B-\u001F\u007F]/g;
1
+ const CSI_PATTERN = /(?:\u001B\[|\u009B)[0-?]*[ -\/]*[@-~]/g;
2
+ const OSC_PATTERN = /(?:\u001B\]|\u009D)[^\u0007\u001B\u009C]*(?:\u0007|\u001B\\|\u009C)?/g;
3
+ const STRING_CONTROL_PATTERN = /(?:\u001B[PX^_]|[\u0090\u0098\u009E\u009F])[^\u001B\u009C]*(?:\u001B\\|\u009C)?/g;
4
+ const ESC_PATTERN = /\u001B[ -\/]*[0-~]/g;
5
+ const CONTROL_CHAR_PATTERN = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g;
4
6
  export function stripControlCharacters(text) {
5
7
  return String(text ?? '')
6
8
  .replace(OSC_PATTERN, '')
9
+ .replace(STRING_CONTROL_PATTERN, '')
7
10
  .replace(CSI_PATTERN, '')
11
+ .replace(ESC_PATTERN, '')
8
12
  .replace(CONTROL_CHAR_PATTERN, '');
9
13
  }
14
+ export function expandTabs(text, initialColumn = 0) {
15
+ let column = initialColumn;
16
+ return stripControlCharacters(text).split(/(\t|\n)/).map((part) => {
17
+ if (part === '\n') {
18
+ column = 0;
19
+ return part;
20
+ }
21
+ if (part === '\t') {
22
+ const spaces = 8 - column % 8;
23
+ column += spaces;
24
+ return ' '.repeat(spaces);
25
+ }
26
+ column += displayWidth(part);
27
+ return part;
28
+ }).join('');
29
+ }
10
30
  export function span(text, style = {}) {
11
31
  return { text: stripControlCharacters(text), ...style };
12
32
  }
13
33
  export function line(...spans) {
14
- return { spans };
34
+ let column = 0;
35
+ return { spans: spans.map((part) => {
36
+ const text = expandTabs(part.text.replace(/\n/g, ' '), column);
37
+ column += displayWidth(text);
38
+ return { ...part, text };
39
+ }) };
15
40
  }
16
41
  export function plainLine(text, style = {}) {
17
42
  return line(span(text, style));
@@ -21,7 +46,7 @@ export function wrapText(text, width) {
21
46
  if (!text)
22
47
  return [''];
23
48
  const lines = [];
24
- for (const rawLine of text.split('\n')) {
49
+ for (const rawLine of expandTabs(text).split('\n')) {
25
50
  let remaining = rawLine;
26
51
  while (displayWidth(remaining) > safeWidth) {
27
52
  const head = sliceToWidth(remaining, safeWidth);
@@ -152,7 +177,7 @@ export function padToWidth(text, width) {
152
177
  export function wrapToWidth(text, width) {
153
178
  const limit = Math.max(1, Math.floor(width));
154
179
  const out = [];
155
- for (const rawLine of String(text ?? '').split('\n')) {
180
+ for (const rawLine of expandTabs(text).split('\n')) {
156
181
  let current = '';
157
182
  const flush = () => {
158
183
  out.push(current);