@thegitai/cli 1.0.0-preview.9 → 1.0.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.
- package/LICENSE +1 -1
- package/README.md +301 -15
- package/dist/bin/ai.js +139 -111
- package/dist/bin/browser-host.js +284 -0
- package/dist/src/agent-mode.js +33 -7
- package/dist/src/api/auth.js +8 -2
- package/dist/src/api/browser-login.js +77 -34
- package/dist/src/api/chat.js +702 -173
- package/dist/src/api/contracts.js +55 -1
- package/dist/src/api/default-host.js +1 -0
- package/dist/src/api/http.js +168 -8
- package/dist/src/api/models.js +75 -10
- package/dist/src/api/startup-handshake.js +36 -0
- package/dist/src/api/turn-recovery.js +189 -0
- package/dist/src/background-jobs.js +14 -4
- package/dist/src/browser/bridge.js +268 -0
- package/dist/src/browser/chrome-profiles.js +73 -0
- package/dist/src/browser/framing.js +42 -0
- package/dist/src/browser/native-host.js +219 -0
- package/dist/src/browser/protocol.js +46 -0
- package/dist/src/browser/session-bridge.js +130 -0
- package/dist/src/cli-args.js +19 -5
- package/dist/src/client-environment.js +2 -0
- package/dist/src/core/clipboard.js +8 -14
- package/dist/src/core/image-limits.js +56 -0
- package/dist/src/core/image-path-extractor.js +70 -3
- package/dist/src/core/session-image-store.js +271 -0
- package/dist/src/edit-journal.js +33 -2
- package/dist/src/executor.js +26 -4
- package/dist/src/help-text.js +152 -41
- package/dist/src/install-id.js +32 -0
- package/dist/src/job-follow-up.js +40 -0
- package/dist/src/mcp-client.js +335 -0
- package/dist/src/mcp-command.js +176 -0
- package/dist/src/mcp-config.js +123 -0
- package/dist/src/mcp-sdk.js +3 -0
- package/dist/src/mcp-types.js +26 -0
- package/dist/src/patcher.js +46 -4
- package/dist/src/permissions.js +301 -0
- package/dist/src/preferences.js +39 -0
- package/dist/src/project-key.js +11 -0
- package/dist/src/project-model-preferences.js +74 -0
- package/dist/src/quota-notice.js +62 -0
- package/dist/src/reasoning-effort.js +27 -0
- package/dist/src/scratch-dir.js +6 -2
- package/dist/src/session-context.js +11 -0
- package/dist/src/session-safety.js +0 -12
- package/dist/src/session-store.js +76 -10
- package/dist/src/session.js +14 -4
- package/dist/src/signin.js +58 -0
- package/dist/src/skills/discovery.js +280 -0
- package/dist/src/skills/frontmatter.js +192 -0
- package/dist/src/skills/install.js +394 -0
- package/dist/src/skills/types.js +43 -0
- package/dist/src/skills-command.js +71 -0
- package/dist/src/todo-list.js +16 -9
- package/dist/src/tool-executor.js +42 -51
- package/dist/src/tools/browser.js +928 -0
- package/dist/src/tools/delete-file.js +21 -5
- package/dist/src/tools/index.js +34 -10
- package/dist/src/tools/patch-file.js +14 -29
- package/dist/src/tools/read-file.js +7 -1
- package/dist/src/tools/read-image-file.js +85 -0
- package/dist/src/tools/replace-document-text.js +28 -18
- package/dist/src/tools/restore-checkpoint.js +1 -2
- package/dist/src/tools/run-command.js +14 -71
- package/dist/src/tools/run-node-script.js +13 -82
- package/dist/src/tools/save-generated-image.js +120 -0
- package/dist/src/tools/shell-diagnostics.js +248 -72
- package/dist/src/tools/str-replace.js +14 -29
- package/dist/src/tools/undo-edit.js +2 -7
- package/dist/src/tools/use-skill.js +38 -0
- package/dist/src/tools/write-file.js +69 -14
- package/dist/src/ui/repl.js +1141 -299
- package/dist/src/ui/slash-commands.js +140 -0
- package/dist/src/ui/tui/attention.js +25 -0
- package/dist/src/ui/tui/bridge.js +38 -5
- package/dist/src/ui/tui/build-frame.js +858 -303
- package/dist/src/ui/tui/composer-layout.js +76 -0
- package/dist/src/ui/tui/desktop-notification.js +118 -0
- package/dist/src/ui/tui/markdown-render.js +21 -11
- package/dist/src/ui/tui/model-label.js +13 -0
- package/dist/src/ui/tui/shell-input.js +266 -61
- package/dist/src/ui/tui/shortcuts.js +61 -0
- package/dist/src/ui/tui/terminal-theme.js +28 -0
- package/dist/src/ui/tui/text.js +31 -6
- package/dist/src/ui/tui/user-input.js +593 -0
- package/dist/src/update-check.js +205 -0
- package/dist/src/usage-notice.js +52 -0
- package/dist/src/usage.js +25 -2
- package/dist/src/utils.js +4 -0
- package/dist/src/version.js +52 -2
- package/dist/vendor/mcp/LICENSES.txt +414 -0
- package/dist/vendor/mcp/client.cjs +82 -0
- package/package.json +22 -9
- package/dist/src/project-index.js +0 -233
- package/dist/src/tools/code-intel.js +0 -472
- package/dist/src/tools/find-symbol.js +0 -70
- package/dist/src/tools/hover-symbol.js +0 -95
- package/dist/src/tools/list-symbols.js +0 -55
- package/dist/src/tools/search-code.js +0 -37
- 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 {
|
|
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,27 @@ 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
|
+
}
|
|
12
41
|
function composerIsEmpty(state) {
|
|
13
42
|
return (!state.input &&
|
|
14
43
|
state.cursor === 0 &&
|
|
@@ -25,11 +54,14 @@ function shouldShowCommandPalette(state) {
|
|
|
25
54
|
state.exiting ||
|
|
26
55
|
state.jobsPickerOpen ||
|
|
27
56
|
state.modelPickerOpen ||
|
|
28
|
-
state.resumePickerOpen
|
|
57
|
+
state.resumePickerOpen ||
|
|
58
|
+
state.skillsPickerOpen) {
|
|
29
59
|
return false;
|
|
30
60
|
}
|
|
31
61
|
const token = getInputCommandToken(state.input);
|
|
32
|
-
|
|
62
|
+
if (!token.startsWith('/') || state.input.includes(' '))
|
|
63
|
+
return false;
|
|
64
|
+
return getSlashCommandSuggestions(state.input).length > 0;
|
|
33
65
|
}
|
|
34
66
|
function insertPastedText(store, handlers, text) {
|
|
35
67
|
const current = store.getState();
|
|
@@ -72,6 +104,7 @@ function pasteTextFromClipboard(store, handlers) {
|
|
|
72
104
|
current.jobsPickerOpen ||
|
|
73
105
|
current.modelPickerOpen ||
|
|
74
106
|
current.resumePickerOpen ||
|
|
107
|
+
current.skillsPickerOpen ||
|
|
75
108
|
current.sudoPrompt) {
|
|
76
109
|
return;
|
|
77
110
|
}
|
|
@@ -79,12 +112,47 @@ function pasteTextFromClipboard(store, handlers) {
|
|
|
79
112
|
if (!text) {
|
|
80
113
|
store.update((state) => ({
|
|
81
114
|
...state,
|
|
82
|
-
|
|
115
|
+
transientStatus: 'Clipboard has no text to paste',
|
|
83
116
|
}));
|
|
84
117
|
return;
|
|
85
118
|
}
|
|
86
119
|
insertPastedText(store, handlers, text);
|
|
87
120
|
}
|
|
121
|
+
function scrollTranscript(store, handlers, delta) {
|
|
122
|
+
if (delta === 0)
|
|
123
|
+
return;
|
|
124
|
+
store.update((current) => {
|
|
125
|
+
const limit = handlers.getTranscriptScrollLimit?.() ??
|
|
126
|
+
current.transcript.reduce((total, entry) => total + 2 + (entry.body ? entry.body.split('\n').length : 0), 0);
|
|
127
|
+
const next = current.transcriptScrollOffset + delta;
|
|
128
|
+
return {
|
|
129
|
+
...current,
|
|
130
|
+
transcriptScrollOffset: Math.max(0, Math.min(next, limit)),
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function scrollTranscriptTo(store, handlers, offset) {
|
|
135
|
+
store.update((current) => {
|
|
136
|
+
const limit = handlers.getTranscriptScrollLimit?.() ??
|
|
137
|
+
current.transcript.reduce((total, entry) => total + 2 + (entry.body ? entry.body.split('\n').length : 0), 0);
|
|
138
|
+
return {
|
|
139
|
+
...current,
|
|
140
|
+
transcriptScrollOffset: Math.max(0, Math.min(Math.trunc(offset), limit)),
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function scrollApprovalPreview(store, handlers, delta) {
|
|
145
|
+
if (delta === 0)
|
|
146
|
+
return;
|
|
147
|
+
store.update((current) => {
|
|
148
|
+
const limit = handlers.getApprovalScrollLimit?.() ?? 0;
|
|
149
|
+
const next = (current.approvalScrollOffset ?? 0) + delta;
|
|
150
|
+
return {
|
|
151
|
+
...current,
|
|
152
|
+
approvalScrollOffset: Math.max(0, Math.min(next, limit)),
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
}
|
|
88
156
|
function filterResumeSessionsLocal(sessions, filter, serverModels) {
|
|
89
157
|
const q = filter.trim().toLowerCase();
|
|
90
158
|
if (!q)
|
|
@@ -99,6 +167,12 @@ function filterResumeSessionsLocal(sessions, filter, serverModels) {
|
|
|
99
167
|
}
|
|
100
168
|
export function handleShellKeyEvent(store, handlers, event) {
|
|
101
169
|
if (event.kind === 'paste') {
|
|
170
|
+
if (applyUserInputPromptEvent(store, handlers, {
|
|
171
|
+
kind: 'paste',
|
|
172
|
+
text: event.text,
|
|
173
|
+
})) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
102
176
|
insertPastedText(store, handlers, event.text);
|
|
103
177
|
return;
|
|
104
178
|
}
|
|
@@ -121,22 +195,22 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
121
195
|
return;
|
|
122
196
|
}
|
|
123
197
|
if (event.kind === 'contextMenu') {
|
|
198
|
+
if (store.getState().userInputPrompt) {
|
|
199
|
+
const text = (handlers.readClipboardText ?? readClipboardText)();
|
|
200
|
+
if (text) {
|
|
201
|
+
applyUserInputPromptEvent(store, handlers, { kind: 'paste', text });
|
|
202
|
+
}
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
124
205
|
pasteTextFromClipboard(store, handlers);
|
|
125
206
|
return;
|
|
126
207
|
}
|
|
127
208
|
if (event.kind === 'transcriptScroll') {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const next = current.transcriptScrollOffset + delta;
|
|
134
|
-
return {
|
|
135
|
-
...current,
|
|
136
|
-
transcriptScrollOffset: Math.max(0, Math.min(next, limit)),
|
|
137
|
-
};
|
|
138
|
-
});
|
|
139
|
-
}
|
|
209
|
+
scrollTranscript(store, handlers, Math.trunc(event.deltaLines));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (event.kind === 'transcriptScrollTo') {
|
|
213
|
+
scrollTranscriptTo(store, handlers, Number(event.offset ?? 0));
|
|
140
214
|
return;
|
|
141
215
|
}
|
|
142
216
|
if (event.kind !== 'key')
|
|
@@ -153,6 +227,10 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
153
227
|
}
|
|
154
228
|
};
|
|
155
229
|
if (key.ctrl && key.input === 'c') {
|
|
230
|
+
if (state.userInputPrompt) {
|
|
231
|
+
handlers.onCtrlC?.();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
156
234
|
if (state.sudoPrompt) {
|
|
157
235
|
handlers.onSudoPasswordInput({ kind: 'cancel' });
|
|
158
236
|
return;
|
|
@@ -185,6 +263,10 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
185
263
|
handlers.onRequestExit();
|
|
186
264
|
return;
|
|
187
265
|
}
|
|
266
|
+
if (state.userInputPrompt &&
|
|
267
|
+
applyUserInputPromptEvent(store, handlers, key)) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
188
270
|
if (state.sudoPrompt) {
|
|
189
271
|
if (key.escape) {
|
|
190
272
|
handlers.onSudoPasswordInput({ kind: 'cancel' });
|
|
@@ -208,24 +290,32 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
208
290
|
return;
|
|
209
291
|
}
|
|
210
292
|
if (state.approvalPrompt) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
293
|
+
if (key.pageUp || key.pageDown) {
|
|
294
|
+
const delta = key.pageUp ? -APPROVAL_PREVIEW_PAGE_ROWS : APPROVAL_PREVIEW_PAGE_ROWS;
|
|
295
|
+
if (key.shift) {
|
|
296
|
+
scrollTranscript(store, handlers, key.pageUp ? 8 : -8);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
scrollApprovalPreview(store, handlers, delta);
|
|
300
|
+
}
|
|
218
301
|
return;
|
|
219
302
|
}
|
|
220
303
|
if (key.upArrow || key.downArrow) {
|
|
221
304
|
store.update((current) => ({
|
|
222
305
|
...current,
|
|
223
|
-
approvalCursor: getNextApprovalCursor(current.approvalCursor, key.upArrow ? -1 : 1),
|
|
306
|
+
approvalCursor: getNextApprovalCursor(current.approvalCursor, key.upArrow ? -1 : 1, current.approvalPrompt?.options?.length ?? 0),
|
|
224
307
|
}));
|
|
225
308
|
return;
|
|
226
309
|
}
|
|
310
|
+
if (approvalIsGuarded(state)) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (key.escape) {
|
|
314
|
+
void handlers.onResolveApproval(-1);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
227
317
|
if (key.returnKey) {
|
|
228
|
-
void handlers.onResolveApproval(
|
|
318
|
+
void handlers.onResolveApproval(state.approvalCursor);
|
|
229
319
|
}
|
|
230
320
|
return;
|
|
231
321
|
}
|
|
@@ -233,24 +323,18 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
233
323
|
return;
|
|
234
324
|
}
|
|
235
325
|
if (key.pageUp || key.pageDown) {
|
|
236
|
-
store.
|
|
237
|
-
const transcriptLines = handlers.getTranscriptScrollLimit?.() ??
|
|
238
|
-
current.transcript.reduce((total, entry) => total + 2 + (entry.body ? entry.body.split('\n').length : 0), 0);
|
|
239
|
-
const next = current.transcriptScrollOffset + (key.pageUp ? 8 : -8);
|
|
240
|
-
return {
|
|
241
|
-
...current,
|
|
242
|
-
transcriptScrollOffset: Math.max(0, Math.min(next, transcriptLines)),
|
|
243
|
-
};
|
|
244
|
-
});
|
|
326
|
+
scrollTranscript(store, handlers, key.pageUp ? 8 : -8);
|
|
245
327
|
return;
|
|
246
328
|
}
|
|
247
329
|
if (state.jobsPickerOpen) {
|
|
248
|
-
if (key.escape) {
|
|
330
|
+
if (key.escape || (key.ctrl && key.input === 'b' && !key.meta && !key.shift)) {
|
|
331
|
+
handlers.onLiveFrameShapeChange();
|
|
249
332
|
store.update((current) => ({
|
|
250
333
|
...current,
|
|
251
334
|
jobsPickerExpandedId: null,
|
|
252
335
|
jobsPickerOpen: false,
|
|
253
|
-
|
|
336
|
+
jobsPickerReturnStatus: null,
|
|
337
|
+
status: current.jobsPickerReturnStatus ?? 'Ready',
|
|
254
338
|
}));
|
|
255
339
|
return;
|
|
256
340
|
}
|
|
@@ -290,6 +374,23 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
290
374
|
});
|
|
291
375
|
return;
|
|
292
376
|
}
|
|
377
|
+
if (key.leftArrow || key.rightArrow) {
|
|
378
|
+
store.update((current) => {
|
|
379
|
+
const options = buildModelPickerOptions(Number(current.currentModelId ?? 0), current.serverModels ?? []);
|
|
380
|
+
const model = options[current.modelPickerIndex];
|
|
381
|
+
if (!model || model.disabled || model.group === 'auto')
|
|
382
|
+
return current;
|
|
383
|
+
const efforts = current.modelPickerEfforts ?? {};
|
|
384
|
+
return {
|
|
385
|
+
...current,
|
|
386
|
+
modelPickerEfforts: {
|
|
387
|
+
...efforts,
|
|
388
|
+
[String(model.publicId)]: cycleReasoningEffort(projectModelEffort(efforts, model.publicId), key.leftArrow ? -1 : 1),
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
});
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
293
394
|
if (key.returnKey) {
|
|
294
395
|
void handlers.onSelectModel();
|
|
295
396
|
}
|
|
@@ -338,6 +439,58 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
338
439
|
}
|
|
339
440
|
return;
|
|
340
441
|
}
|
|
442
|
+
if (state.skillsPickerOpen) {
|
|
443
|
+
if (key.escape) {
|
|
444
|
+
handlers.onLiveFrameShapeChange();
|
|
445
|
+
store.update((current) => ({ ...current, skillsPickerOpen: false }));
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (key.upArrow || key.downArrow) {
|
|
449
|
+
store.update((current) => {
|
|
450
|
+
const count = (current.skillsPickerItems ?? []).length;
|
|
451
|
+
const next = (current.skillsPickerIndex ?? 0) + (key.upArrow ? -1 : 1);
|
|
452
|
+
return { ...current, skillsPickerIndex: Math.max(0, Math.min(next, count - 1)) };
|
|
453
|
+
});
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (key.returnKey) {
|
|
457
|
+
const item = (state.skillsPickerItems ?? [])[state.skillsPickerIndex ?? 0];
|
|
458
|
+
if (!item?.usable)
|
|
459
|
+
return;
|
|
460
|
+
const input = `/${item.name} `;
|
|
461
|
+
handlers.onLiveFrameShapeChange();
|
|
462
|
+
store.update((current) => ({
|
|
463
|
+
...current,
|
|
464
|
+
commandCursor: 0,
|
|
465
|
+
cursor: input.length,
|
|
466
|
+
input,
|
|
467
|
+
skillsPickerOpen: false,
|
|
468
|
+
}));
|
|
469
|
+
}
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (state.shortcutsOpen) {
|
|
473
|
+
if (key.escape || key.returnKey || key.input === '?' || key.input === 'q') {
|
|
474
|
+
handlers.onLiveFrameShapeChange();
|
|
475
|
+
store.update((current) => ({ ...current, shortcutsOpen: false }));
|
|
476
|
+
}
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (key.ctrl && key.input === 'b' && !key.meta && !key.shift) {
|
|
480
|
+
if ((state.backgroundJobs ?? []).length > 0) {
|
|
481
|
+
handlers.onOpenJobsPicker();
|
|
482
|
+
}
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (key.ctrl && key.input === 'g' && !key.meta && !key.shift) {
|
|
486
|
+
handlers.onToggleNotifications?.();
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (key.input === '?' && !key.ctrl && !key.meta && shortcutsPanelAvailable(state)) {
|
|
490
|
+
handlers.onLiveFrameShapeChange();
|
|
491
|
+
store.update((current) => ({ ...current, shortcutsOpen: true }));
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
341
494
|
if (key.escape) {
|
|
342
495
|
if (state.busy) {
|
|
343
496
|
if (state.queuedMessage) {
|
|
@@ -366,9 +519,22 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
366
519
|
return;
|
|
367
520
|
}
|
|
368
521
|
if (key.tab && key.shift) {
|
|
522
|
+
if (state.busy) {
|
|
523
|
+
handlers.onAgentModeChangeBlocked?.();
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
369
526
|
handlers.onCycleAgentMode();
|
|
370
527
|
return;
|
|
371
528
|
}
|
|
529
|
+
if (state.busy && state.queuedMessage) {
|
|
530
|
+
if (key.returnKey) {
|
|
531
|
+
void handlers.onFireQueuedMessage?.();
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
if (!key.upArrow && !isClipboardImagePasteKey(key)) {
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
372
538
|
if (commandPaletteActive && (key.upArrow || key.downArrow)) {
|
|
373
539
|
store.update((current) => ({
|
|
374
540
|
...current,
|
|
@@ -377,7 +543,7 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
377
543
|
return;
|
|
378
544
|
}
|
|
379
545
|
if (key.upArrow) {
|
|
380
|
-
if (state.busy && state.
|
|
546
|
+
if (state.busy && state.queuedMessage) {
|
|
381
547
|
handlers.onLiveFrameShapeChange();
|
|
382
548
|
store.update((current) => {
|
|
383
549
|
const queued = current.queuedMessage;
|
|
@@ -396,9 +562,13 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
396
562
|
});
|
|
397
563
|
return;
|
|
398
564
|
}
|
|
399
|
-
|
|
565
|
+
const nextCursor = moveComposerCursorVertically(state.input, state.cursor, handlers.getComposerInputWidth?.() ?? Number.POSITIVE_INFINITY, -1);
|
|
566
|
+
if (nextCursor === null && state.busy)
|
|
400
567
|
return;
|
|
401
568
|
store.update((current) => {
|
|
569
|
+
if (nextCursor !== null) {
|
|
570
|
+
return { ...current, commandCursor: 0, cursor: nextCursor };
|
|
571
|
+
}
|
|
402
572
|
const next = navigatePromptHistory(current, 'previous');
|
|
403
573
|
prepareForComposerInputChange(current, next.input);
|
|
404
574
|
return next;
|
|
@@ -406,9 +576,13 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
406
576
|
return;
|
|
407
577
|
}
|
|
408
578
|
if (key.downArrow) {
|
|
409
|
-
|
|
579
|
+
const nextCursor = moveComposerCursorVertically(state.input, state.cursor, handlers.getComposerInputWidth?.() ?? Number.POSITIVE_INFINITY, 1);
|
|
580
|
+
if (nextCursor === null && state.busy)
|
|
410
581
|
return;
|
|
411
582
|
store.update((current) => {
|
|
583
|
+
if (nextCursor !== null) {
|
|
584
|
+
return { ...current, commandCursor: 0, cursor: nextCursor };
|
|
585
|
+
}
|
|
412
586
|
const next = navigatePromptHistory(current, 'next');
|
|
413
587
|
prepareForComposerInputChange(current, next.input);
|
|
414
588
|
return next;
|
|
@@ -428,10 +602,10 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
428
602
|
}
|
|
429
603
|
if (key.returnKey) {
|
|
430
604
|
const token = getInputCommandToken(state.input);
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
605
|
+
const suggestion = commandSuggestions[Math.min(state.commandCursor, commandSuggestions.length - 1)];
|
|
606
|
+
if (commandPaletteActive &&
|
|
607
|
+
suggestion &&
|
|
608
|
+
!slashCommandMatchesToken(suggestion, token)) {
|
|
435
609
|
store.update((current) => {
|
|
436
610
|
const nextInput = applySlashCommandSuggestion(current.input, suggestion);
|
|
437
611
|
prepareForComposerInputChange(current, nextInput.input);
|
|
@@ -496,12 +670,16 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
496
670
|
}
|
|
497
671
|
if (isClipboardImagePasteKey(key)) {
|
|
498
672
|
const current = store.getState();
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
673
|
+
const target = current.queuedMessage
|
|
674
|
+
? {
|
|
675
|
+
body: current.queuedMessage.body,
|
|
676
|
+
attachments: current.queuedMessage.imageAttachments,
|
|
677
|
+
}
|
|
678
|
+
: { body: current.input, attachments: current.imageAttachments };
|
|
679
|
+
const liveAttachments = target.attachments.filter((attachment) => target.body.includes(`[Image #${attachment.index}]`));
|
|
680
|
+
if (liveAttachments.length >= MAX_IMAGES_PER_MESSAGE) {
|
|
503
681
|
store.appendEntry({
|
|
504
|
-
body:
|
|
682
|
+
body: `Maximum of ${MAX_IMAGES_PER_MESSAGE} images per message. Send the current message first.`,
|
|
505
683
|
kind: 'error',
|
|
506
684
|
title: 'Image',
|
|
507
685
|
});
|
|
@@ -509,22 +687,49 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
509
687
|
}
|
|
510
688
|
try {
|
|
511
689
|
const clipResult = readClipboardImage();
|
|
690
|
+
if (totalAttachmentBytes(liveAttachments) +
|
|
691
|
+
approximateBase64DecodedBytes(clipResult.base64Data) >
|
|
692
|
+
MAX_TOTAL_IMAGE_BYTES_PER_MESSAGE) {
|
|
693
|
+
store.appendEntry({
|
|
694
|
+
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.`,
|
|
695
|
+
kind: 'error',
|
|
696
|
+
title: 'Image',
|
|
697
|
+
});
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
512
700
|
const idx = liveAttachments.length === 0
|
|
513
701
|
? 1
|
|
514
702
|
: Math.max(...liveAttachments.map((attachment) => attachment.index)) + 1;
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
703
|
+
const cached = tryCacheAttachmentBytes({
|
|
704
|
+
base64Data: clipResult.base64Data,
|
|
705
|
+
mimeType: clipResult.mimeType,
|
|
706
|
+
});
|
|
707
|
+
const attachment = {
|
|
708
|
+
index: cached?.index ?? idx,
|
|
709
|
+
mimeType: clipResult.mimeType,
|
|
710
|
+
base64Data: clipResult.base64Data,
|
|
711
|
+
source: 'clipboard',
|
|
712
|
+
...(cached ? { cachePath: cached.cachePath } : {}),
|
|
713
|
+
};
|
|
714
|
+
const marker = attachment.index;
|
|
715
|
+
store.update((shellState) => {
|
|
716
|
+
const nextAttachments = [...liveAttachments, attachment];
|
|
717
|
+
if (shellState.queuedMessage) {
|
|
718
|
+
return {
|
|
719
|
+
...shellState,
|
|
720
|
+
queuedMessage: {
|
|
721
|
+
...shellState.queuedMessage,
|
|
722
|
+
body: `${shellState.queuedMessage.body} [Image #${marker}]`.trim(),
|
|
723
|
+
imageAttachments: nextAttachments,
|
|
724
|
+
},
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
return {
|
|
728
|
+
...shellState,
|
|
729
|
+
imageAttachments: nextAttachments,
|
|
730
|
+
...insertAtCursor(shellState, `[Image #${marker}] `),
|
|
731
|
+
};
|
|
732
|
+
});
|
|
528
733
|
}
|
|
529
734
|
catch (error) {
|
|
530
735
|
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
|
+
}
|
package/dist/src/ui/tui/text.js
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
|
-
const CSI_PATTERN =
|
|
2
|
-
const OSC_PATTERN =
|
|
3
|
-
const
|
|
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
|
-
|
|
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
|
|
180
|
+
for (const rawLine of expandTabs(text).split('\n')) {
|
|
156
181
|
let current = '';
|
|
157
182
|
const flush = () => {
|
|
158
183
|
out.push(current);
|