@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.
- package/README.md +229 -7
- package/dist/bin/ai.js +140 -111
- package/dist/bin/browser-host.js +265 -0
- package/dist/src/agent-mode.js +32 -7
- package/dist/src/api/auth.js +8 -2
- package/dist/src/api/browser-login.js +147 -35
- package/dist/src/api/chat.js +691 -166
- package/dist/src/api/contracts.js +55 -1
- package/dist/src/api/default-host.js +1 -0
- package/dist/src/api/http.js +139 -8
- package/dist/src/api/models.js +34 -9
- package/dist/src/api/startup-handshake.js +36 -0
- package/dist/src/api/turn-recovery.js +189 -0
- package/dist/src/background-jobs.js +8 -2
- package/dist/src/browser/bridge.js +262 -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 +7 -13
- 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 +246 -0
- package/dist/src/edit-journal.js +33 -2
- package/dist/src/executor.js +25 -3
- package/dist/src/help-text.js +128 -22
- 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 +43 -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 +35 -0
- package/dist/src/reasoning-effort.js +27 -0
- package/dist/src/session-safety.js +0 -12
- package/dist/src/session-store.js +123 -30
- package/dist/src/session.js +20 -4
- package/dist/src/signin.js +58 -0
- package/dist/src/tool-executor.js +23 -49
- package/dist/src/tools/browser.js +641 -0
- package/dist/src/tools/delete-file.js +20 -4
- package/dist/src/tools/index.js +32 -10
- package/dist/src/tools/patch-file.js +12 -26
- package/dist/src/tools/read-file.js +5 -0
- 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 +0 -1
- package/dist/src/tools/run-command.js +14 -71
- package/dist/src/tools/run-node-script.js +12 -81
- package/dist/src/tools/save-generated-image.js +120 -0
- package/dist/src/tools/str-replace.js +12 -26
- package/dist/src/tools/undo-edit.js +1 -6
- package/dist/src/tools/write-file.js +67 -11
- package/dist/src/ui/prompt-history-store.js +1 -1
- package/dist/src/ui/repl.js +1017 -299
- package/dist/src/ui/slash-commands.js +122 -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 +807 -270
- 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 +275 -73
- 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 +5 -2
- package/dist/src/utils.js +13 -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,8 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { fitModelLabel } from './model-label.js';
|
|
2
|
+
import { projectModelEffort } from '../../project-model-preferences.js';
|
|
3
|
+
import { REASONING_EFFORTS, REASONING_EFFORT_LABELS, REASONING_EFFORT_DESCRIPTIONS } from '../../reasoning-effort.js';
|
|
4
|
+
import { agentModeColor, agentModeLabelTiers, agentModeShortLabel, } from '../../agent-mode.js';
|
|
5
|
+
import { singleLinePreview, truncate } from '../../utils.js';
|
|
6
|
+
import { buildModelPickerOptions, formatClientTokenUsage } from '../repl.js';
|
|
7
|
+
import { getHiddenSlashCommandCount, getSlashCommandSuggestions, } from '../slash-commands.js';
|
|
4
8
|
import { renderFormattedBodyLines, renderPreformattedBodyLines, } from './markdown-render.js';
|
|
5
|
-
import { displayWidth, line, plainLine, sliceToWidth, span, wrapText, } from './text.js';
|
|
9
|
+
import { displayWidth, line, padToWidth, plainLine, sliceToWidth, span, wrapText, } from './text.js';
|
|
10
|
+
import { isDarkTerminalBackground, mutedColor, mutedStyle } from './terminal-theme.js';
|
|
11
|
+
import { buildShortcutGroups, shortcutsPanelAvailable, } from './shortcuts.js';
|
|
12
|
+
import { buildUserInputOverlayLines, } from './user-input.js';
|
|
13
|
+
import { composerPromptLabel, frameContentWidth, splitComposerInput, } from './composer-layout.js';
|
|
6
14
|
const WORKING_CLOCK_ICON = '◷';
|
|
7
15
|
const BRAILLE_SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴'];
|
|
8
16
|
const TODO_PANEL_MAX_ROWS = 12;
|
|
@@ -10,12 +18,41 @@ const TODO_IN_PROGRESS_COLOR = 'ansi256(214)';
|
|
|
10
18
|
const COMMAND_PREVIEW_LINES = 10;
|
|
11
19
|
const WORKING_TOOL_PREVIEW_ROWS = 3;
|
|
12
20
|
const TRANSCRIPT_DIFF_PREVIEW_LINES = 24;
|
|
21
|
+
const APPROVAL_PREVIEW_MAX_ROWS = 20;
|
|
22
|
+
const APPROVAL_PREVIEW_MIN_ROWS = 4;
|
|
23
|
+
const APPROVAL_OVERLAY_CHROME_ROWS = 11;
|
|
24
|
+
const APPROVAL_PADDING_CHROME_ROWS = 4;
|
|
25
|
+
const APPROVAL_PADDING_MIN_ROWS = 30;
|
|
26
|
+
const APPROVAL_SCROLLBAR_COLUMNS = 2;
|
|
27
|
+
const APPROVAL_ACCENT_COLOR = 'cyan';
|
|
28
|
+
const SUDO_PASSWORD_ASSURANCE = 'The model never sees this. Your password goes straight to sudo on this ' +
|
|
29
|
+
'computer, then is discarded — never sent to our servers, saved, or logged.';
|
|
30
|
+
const SUDO_ASSURANCE_COLOR = 'ansi256(248)';
|
|
31
|
+
const APPROVAL_SCROLL_STATUS_COLOR = 'ansi256(248)';
|
|
32
|
+
const APPROVAL_SCROLLBAR_THUMB = '█';
|
|
33
|
+
const APPROVAL_SCROLLBAR_TRACK = '░';
|
|
13
34
|
const THINKING_NOTE_PREVIEW_ROWS = 3;
|
|
14
35
|
const COMPOSER_INPUT_MAX_ROWS = 6;
|
|
15
|
-
const
|
|
36
|
+
const FOOTER_HINT_MIN_GAP = 2;
|
|
37
|
+
const FOOTER_HELP_HINT = '? for shortcuts';
|
|
38
|
+
const FOOTER_CANCEL_HINT = 'esc cancels turn';
|
|
39
|
+
const FOOTER_NOTIFICATIONS_ON = 'Notifications ON';
|
|
40
|
+
const FOOTER_NOTIFICATIONS_OFF = 'Notifications OFF';
|
|
41
|
+
export function footerNotificationHint(status) {
|
|
42
|
+
const text = String(status ?? '').trim();
|
|
43
|
+
if (text === 'Notifications on')
|
|
44
|
+
return FOOTER_NOTIFICATIONS_ON;
|
|
45
|
+
if (text === 'Notifications off')
|
|
46
|
+
return FOOTER_NOTIFICATIONS_OFF;
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
const FOOTER_CYCLE_HINT = ' (shift+tab to cycle)';
|
|
16
50
|
const OVERLAY_PANEL_MAX_WIDTH = 86;
|
|
51
|
+
const USER_INPUT_PANEL_MAX_WIDTH = 120;
|
|
17
52
|
const OVERLAY_PANEL_MARGIN_LINES = 2;
|
|
53
|
+
const OVERLAY_PANEL_MARGIN_MIN_ROWS = 30;
|
|
18
54
|
const OVERLAY_BORDER_COLOR = 'yellow';
|
|
55
|
+
const USER_INPUT_BORDER_COLOR = 'cyan';
|
|
19
56
|
const OVERLAY_WARNING_COLOR = 'ansi256(208)';
|
|
20
57
|
const MODEL_PICKER_PANEL_MAX_WIDTH = 144;
|
|
21
58
|
const MODEL_PICKER_PANEL_MARGIN_LINES = 2;
|
|
@@ -23,75 +60,74 @@ const MODEL_PICKER_BORDER_COLOR = 'cyan';
|
|
|
23
60
|
const MODEL_PICKER_ACCENT_COLOR = 'cyan';
|
|
24
61
|
const MODEL_PICKER_HIGHLIGHT_BG = 'ansi256(87)';
|
|
25
62
|
const MODEL_PICKER_META_INDENT = ' ';
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const captureCursor = () => {
|
|
34
|
-
if (capturedCursor)
|
|
35
|
-
return;
|
|
36
|
-
const current = rows[rows.length - 1] ?? '';
|
|
37
|
-
if (current.length >= safeWidth) {
|
|
38
|
-
rows.push('');
|
|
39
|
-
cursorRow = rows.length - 1;
|
|
40
|
-
cursorCol = 0;
|
|
63
|
+
const COMPOSER_MARKER_PATTERN = /\[Image #\d+\]|\[Pasted Text: [^\]\n]*\]/g;
|
|
64
|
+
function composerMarkerMask(text) {
|
|
65
|
+
const mask = new Array(text.length).fill(false);
|
|
66
|
+
for (const match of text.matchAll(COMPOSER_MARKER_PATTERN)) {
|
|
67
|
+
const start = match.index ?? 0;
|
|
68
|
+
for (let offset = start; offset < start + match[0].length; offset += 1) {
|
|
69
|
+
mask[offset] = true;
|
|
41
70
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
71
|
+
}
|
|
72
|
+
return mask;
|
|
73
|
+
}
|
|
74
|
+
function composerRowSpans(text, mask, cursorCol) {
|
|
75
|
+
const spans = [];
|
|
76
|
+
const push = (value, marker, cursor) => {
|
|
77
|
+
if (!value)
|
|
78
|
+
return;
|
|
79
|
+
spans.push(span(value, {
|
|
80
|
+
...(marker ? { color: 'cyan' } : {}),
|
|
81
|
+
...(cursor ? { inverse: true } : {}),
|
|
82
|
+
}));
|
|
47
83
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
if (char === '\r')
|
|
59
|
-
continue;
|
|
60
|
-
if (char === '\n') {
|
|
61
|
-
rows.push('');
|
|
62
|
-
continue;
|
|
84
|
+
let cut = 0;
|
|
85
|
+
const flushTo = (end) => {
|
|
86
|
+
while (cut < end) {
|
|
87
|
+
const marker = mask[cut] ?? false;
|
|
88
|
+
let runEnd = cut + 1;
|
|
89
|
+
while (runEnd < end && (mask[runEnd] ?? false) === marker)
|
|
90
|
+
runEnd += 1;
|
|
91
|
+
push(text.slice(cut, runEnd), marker, false);
|
|
92
|
+
cut = runEnd;
|
|
63
93
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
94
|
+
};
|
|
95
|
+
if (cursorCol === null) {
|
|
96
|
+
flushTo(text.length);
|
|
97
|
+
return spans;
|
|
68
98
|
}
|
|
69
|
-
|
|
99
|
+
flushTo(Math.min(cursorCol, text.length));
|
|
100
|
+
push(text[cursorCol] ?? ' ', mask[cursorCol] ?? false, true);
|
|
101
|
+
cut = Math.min(cursorCol + 1, text.length);
|
|
102
|
+
flushTo(text.length);
|
|
103
|
+
return spans;
|
|
70
104
|
}
|
|
71
105
|
function buildComposerInputLines(input, cursor, promptLabel, placeholder, width) {
|
|
72
106
|
if (!input) {
|
|
73
107
|
return [
|
|
74
|
-
line(span(promptLabel, { color: 'cyan' }), span(' ', { inverse: true }), span(placeholder, { color:
|
|
108
|
+
line(span(promptLabel, { color: 'cyan' }), span(' ', { inverse: true }), span(placeholder, { color: mutedColor() })),
|
|
75
109
|
];
|
|
76
110
|
}
|
|
77
111
|
const labelWidth = promptLabel.length;
|
|
78
112
|
const inputWidth = Math.max(1, width - labelWidth);
|
|
79
113
|
const { cursorCol, cursorRow, rows } = splitComposerInput(input, cursor, inputWidth);
|
|
80
114
|
const firstRow = Math.min(Math.max(cursorRow - COMPOSER_INPUT_MAX_ROWS + 1, 0), Math.max(rows.length - COMPOSER_INPUT_MAX_ROWS, 0));
|
|
115
|
+
const rowOffsets = [];
|
|
116
|
+
let consumed = 0;
|
|
117
|
+
for (const row of rows) {
|
|
118
|
+
rowOffsets.push(consumed);
|
|
119
|
+
consumed += row.length;
|
|
120
|
+
}
|
|
121
|
+
const mask = composerMarkerMask(rows.join(''));
|
|
81
122
|
return rows
|
|
82
123
|
.slice(firstRow, firstRow + COMPOSER_INPUT_MAX_ROWS)
|
|
83
124
|
.map((text, index) => {
|
|
84
125
|
const absoluteRow = firstRow + index;
|
|
126
|
+
const rowStart = rowOffsets[absoluteRow] ?? 0;
|
|
85
127
|
const label = index === 0
|
|
86
128
|
? span(promptLabel, { color: 'cyan' })
|
|
87
129
|
: span(' '.repeat(labelWidth));
|
|
88
|
-
|
|
89
|
-
return line(label, span(text));
|
|
90
|
-
}
|
|
91
|
-
const before = text.slice(0, cursorCol);
|
|
92
|
-
const cursorChar = text[cursorCol] ?? ' ';
|
|
93
|
-
const after = text.slice(cursorCol + 1);
|
|
94
|
-
return line(label, span(before), span(cursorChar, { inverse: true }), span(after));
|
|
130
|
+
return line(label, ...composerRowSpans(text, mask.slice(rowStart, rowStart + text.length), absoluteRow === cursorRow ? cursorCol : null));
|
|
95
131
|
});
|
|
96
132
|
}
|
|
97
133
|
function getEntryColor(kind) {
|
|
@@ -157,61 +193,13 @@ export function formatPromptDirectoryLabel(projectRoot, homeDir = process.env.HO
|
|
|
157
193
|
export function formatPromptSessionIdLabel(showSessionId, sessionId) {
|
|
158
194
|
return showSessionId ? String(sessionId ?? '').trim() : '';
|
|
159
195
|
}
|
|
160
|
-
|
|
161
|
-
{ command: '/help', description: 'Show available chat commands' },
|
|
162
|
-
{ command: '/usage', description: 'Show account usage percentage and reset times' },
|
|
163
|
-
{ command: '/model', description: 'Switch the active model' },
|
|
164
|
-
{ command: '/resume', description: 'Open the session picker to resume a previous session' },
|
|
165
|
-
{ command: '/jobs', description: 'Background jobs: pick to view output or kill' },
|
|
166
|
-
{ command: '/clear', description: 'Clear conversation history' },
|
|
167
|
-
{ command: '/exit', description: 'Quit the current session' },
|
|
168
|
-
];
|
|
169
|
-
function buildModelPickerOptions(currentModelId, serverModels) {
|
|
170
|
-
return serverModels.map((model) => ({
|
|
171
|
-
id: model.id,
|
|
172
|
-
label: model.label,
|
|
173
|
-
publicId: model.id,
|
|
174
|
-
costRating: model.costRating,
|
|
175
|
-
current: model.id === currentModelId,
|
|
176
|
-
disabled: false,
|
|
177
|
-
note: model.description,
|
|
178
|
-
}));
|
|
179
|
-
}
|
|
180
|
-
function getInputCommandToken(input) {
|
|
181
|
-
const trimmed = String(input ?? '').trimStart();
|
|
182
|
-
const match = trimmed.match(/^\/[^\s]*/);
|
|
183
|
-
const token = match?.[0] ?? '';
|
|
184
|
-
if (token.indexOf('/', 1) !== -1)
|
|
185
|
-
return '';
|
|
186
|
-
return token;
|
|
187
|
-
}
|
|
188
|
-
function scoreSlashCommand(option, token) {
|
|
189
|
-
if (option.command === token)
|
|
190
|
-
return 0;
|
|
191
|
-
if (option.command.startsWith(token))
|
|
192
|
-
return 1;
|
|
193
|
-
if (option.command.includes(token.slice(1)))
|
|
194
|
-
return 2;
|
|
195
|
-
if (option.description.toLowerCase().includes(token.slice(1)))
|
|
196
|
-
return 3;
|
|
197
|
-
return 4;
|
|
198
|
-
}
|
|
199
|
-
export function getSlashCommandSuggestions(input) {
|
|
200
|
-
const token = getInputCommandToken(input).toLowerCase();
|
|
201
|
-
if (!token)
|
|
202
|
-
return [];
|
|
203
|
-
const ranked = [...CLIENT_SLASH_COMMANDS].sort((a, b) => {
|
|
204
|
-
const scoreDiff = scoreSlashCommand(a, token) - scoreSlashCommand(b, token);
|
|
205
|
-
if (scoreDiff !== 0)
|
|
206
|
-
return scoreDiff;
|
|
207
|
-
return a.command.localeCompare(b.command);
|
|
208
|
-
});
|
|
209
|
-
const matches = ranked.filter((option) => scoreSlashCommand(option, token) < 4);
|
|
210
|
-
return (matches.length ? matches : ranked).slice(0, 5);
|
|
211
|
-
}
|
|
196
|
+
export { getSlashCommandSuggestions };
|
|
212
197
|
function formatModelLabel(modelId, serverModels) {
|
|
213
198
|
return serverModels.find((model) => model.id === modelId)?.label ?? 'Unknown model';
|
|
214
199
|
}
|
|
200
|
+
function pickerModelLabel(modelId, serverModels) {
|
|
201
|
+
return formatModelLabel(modelId, serverModels).replace(/\s*\([^)]*\)\s*$/, '');
|
|
202
|
+
}
|
|
215
203
|
function filterResumeSessions(sessions, filter, serverModels) {
|
|
216
204
|
const q = filter.trim().toLowerCase();
|
|
217
205
|
if (!q)
|
|
@@ -235,26 +223,90 @@ function formatRelativeTime(isoDate) {
|
|
|
235
223
|
return `${hours}h ago`;
|
|
236
224
|
return `${Math.floor(hours / 24)}d ago`;
|
|
237
225
|
}
|
|
238
|
-
|
|
226
|
+
const TODO_IN_PROGRESS_FRAMES = [
|
|
227
|
+
'\u25CB',
|
|
228
|
+
'\u25D4',
|
|
229
|
+
'\u25D1',
|
|
230
|
+
'\u25D5',
|
|
231
|
+
'\u25CF',
|
|
232
|
+
];
|
|
233
|
+
const TODO_IN_PROGRESS_STATIC_GLYPH = '\u25D1';
|
|
234
|
+
export const TODO_IN_PROGRESS_STEP_MS = 1_500;
|
|
235
|
+
export function todoProgressTick(nowMs) {
|
|
236
|
+
return Math.floor(nowMs / TODO_IN_PROGRESS_STEP_MS);
|
|
237
|
+
}
|
|
238
|
+
function todoInProgressGlyph(progressTick) {
|
|
239
|
+
if (progressTick === null)
|
|
240
|
+
return TODO_IN_PROGRESS_STATIC_GLYPH;
|
|
241
|
+
const index = ((progressTick % TODO_IN_PROGRESS_FRAMES.length) +
|
|
242
|
+
TODO_IN_PROGRESS_FRAMES.length) %
|
|
243
|
+
TODO_IN_PROGRESS_FRAMES.length;
|
|
244
|
+
return TODO_IN_PROGRESS_FRAMES[index];
|
|
245
|
+
}
|
|
246
|
+
function todoItemLine(item, width, progressTick = null) {
|
|
239
247
|
const text = fitLine(item.text, Math.max(8, width - 5));
|
|
240
248
|
if (item.status === 'completed') {
|
|
241
|
-
return line(span(' ✔ ', { color: 'green' }), span(text,
|
|
249
|
+
return line(span(' ✔ ', { color: 'green' }), span(text, mutedStyle()));
|
|
242
250
|
}
|
|
243
251
|
if (item.status === 'in_progress') {
|
|
244
|
-
return line(span(
|
|
252
|
+
return line(span(` ${todoInProgressGlyph(progressTick)} `, {
|
|
253
|
+
color: TODO_IN_PROGRESS_COLOR,
|
|
254
|
+
}), span(text, { color: TODO_IN_PROGRESS_COLOR, bold: true }));
|
|
255
|
+
}
|
|
256
|
+
return line(span(' ○ ', { color: mutedColor() }), isDarkTerminalBackground()
|
|
257
|
+
? span(text, { color: mutedColor() })
|
|
258
|
+
: span(text));
|
|
259
|
+
}
|
|
260
|
+
const TURN_MESSAGE_PANEL_MAX_ROWS = 6;
|
|
261
|
+
const TURN_MESSAGE_LABEL = {
|
|
262
|
+
queued: 'queued',
|
|
263
|
+
sending: 'Processing . . .',
|
|
264
|
+
delivered: 'delivered',
|
|
265
|
+
};
|
|
266
|
+
function turnMessageLine(message, width, progressTick) {
|
|
267
|
+
const DECORATION = 6;
|
|
268
|
+
const budget = Math.max(1, width - DECORATION);
|
|
269
|
+
const preferredLabel = Math.max(...Object.values(TURN_MESSAGE_LABEL).map((value) => displayWidth(value)));
|
|
270
|
+
const labelWidth = Math.min(Math.max(1, Math.floor(budget / 2)), Math.max(preferredLabel, displayWidth(message.note ?? '')));
|
|
271
|
+
const label = fitLine(message.note ?? TURN_MESSAGE_LABEL[message.state], labelWidth);
|
|
272
|
+
const textWidth = Math.max(1, budget - labelWidth);
|
|
273
|
+
const text = padToWidth(fitLine(`"${message.text}"`, textWidth), textWidth);
|
|
274
|
+
if (message.state === 'delivered') {
|
|
275
|
+
return line(span(' ● ', { color: 'green' }), span(text, { color: 'gray', dim: true }), span(` ${label}`, { color: 'green' }));
|
|
276
|
+
}
|
|
277
|
+
if (message.state === 'sending') {
|
|
278
|
+
return line(span(` ${todoInProgressGlyph(progressTick)} `, {
|
|
279
|
+
color: TODO_IN_PROGRESS_COLOR,
|
|
280
|
+
}), span(text, { color: TODO_IN_PROGRESS_COLOR, bold: true }), span(` ${label}`, { color: TODO_IN_PROGRESS_COLOR }));
|
|
245
281
|
}
|
|
246
|
-
return line(span(' ○ ', { color: '
|
|
282
|
+
return line(span(' ○ ', { color: 'cyan' }), span(text, { color: 'cyan' }), span(` ${label}`, { color: 'gray' }));
|
|
283
|
+
}
|
|
284
|
+
export function buildTurnMessageLines(messages, width, progressTick = null) {
|
|
285
|
+
if (messages.length === 0)
|
|
286
|
+
return [];
|
|
287
|
+
const lines = [
|
|
288
|
+
line(span('Your messages', { color: 'cyan', bold: true })),
|
|
289
|
+
];
|
|
290
|
+
const visible = messages.slice(-(TURN_MESSAGE_PANEL_MAX_ROWS - 1));
|
|
291
|
+
const hidden = messages.length - visible.length;
|
|
292
|
+
if (hidden > 0) {
|
|
293
|
+
lines.push(line(span(` ● ${hidden} earlier`, { color: 'gray', dim: true })));
|
|
294
|
+
}
|
|
295
|
+
for (const message of visible) {
|
|
296
|
+
lines.push(turnMessageLine(message, width, progressTick));
|
|
297
|
+
}
|
|
298
|
+
return lines;
|
|
247
299
|
}
|
|
248
300
|
export function formatTodoProgress(items) {
|
|
249
301
|
const done = items.filter((item) => item.status === 'completed').length;
|
|
250
302
|
return `${done}/${items.length} done`;
|
|
251
303
|
}
|
|
252
|
-
export function renderTodoListLines(items, width, { header = false } = {}) {
|
|
304
|
+
export function renderTodoListLines(items, width, { header = false, progressTick = null } = {}) {
|
|
253
305
|
if (items.length === 0)
|
|
254
306
|
return [];
|
|
255
307
|
const lines = [];
|
|
256
308
|
if (header) {
|
|
257
|
-
lines.push(line(span('To-dos', { color: 'cyan', bold: true }), span(` · ${formatTodoProgress(items)}`, { color:
|
|
309
|
+
lines.push(line(span('To-dos', { color: 'cyan', bold: true }), span(` · ${formatTodoProgress(items)}`, { color: mutedColor() })));
|
|
258
310
|
}
|
|
259
311
|
const itemRowBudget = TODO_PANEL_MAX_ROWS - (header ? 1 : 0);
|
|
260
312
|
let collapsedDone = 0;
|
|
@@ -268,19 +320,16 @@ export function renderTodoListLines(items, width, { header = false } = {}) {
|
|
|
268
320
|
collapsedDone = Math.min(over, leadingDone);
|
|
269
321
|
}
|
|
270
322
|
if (collapsedDone > 0) {
|
|
271
|
-
lines.push(line(span(' ✔ ', { color: 'green' }), span(`${collapsedDone} completed`,
|
|
323
|
+
lines.push(line(span(' ✔ ', { color: 'green' }), span(`${collapsedDone} completed`, mutedStyle())));
|
|
272
324
|
}
|
|
273
325
|
const remaining = items.slice(collapsedDone);
|
|
274
326
|
const budget = itemRowBudget - (collapsedDone > 0 ? 1 : 0);
|
|
275
327
|
const visible = remaining.length > budget ? remaining.slice(0, budget - 1) : remaining;
|
|
276
328
|
for (const item of visible) {
|
|
277
|
-
lines.push(todoItemLine(item, width));
|
|
329
|
+
lines.push(todoItemLine(item, width, progressTick));
|
|
278
330
|
}
|
|
279
331
|
if (remaining.length > visible.length) {
|
|
280
|
-
lines.push(plainLine(` … +${remaining.length - visible.length} more`,
|
|
281
|
-
color: 'gray',
|
|
282
|
-
dim: true,
|
|
283
|
-
}));
|
|
332
|
+
lines.push(plainLine(` … +${remaining.length - visible.length} more`, mutedStyle()));
|
|
284
333
|
}
|
|
285
334
|
return lines;
|
|
286
335
|
}
|
|
@@ -293,20 +342,45 @@ export function renderTranscriptEntryLines(entry, width) {
|
|
|
293
342
|
? renderPreformattedBodyLines(entry.body, width, entry.kind)
|
|
294
343
|
: renderFormattedBodyLines(entry.body, width, entry.kind)));
|
|
295
344
|
if (entry.diffPreview) {
|
|
296
|
-
lines.push(
|
|
297
|
-
for (const diffLine of entry.diffPreview.lines.slice(0, TRANSCRIPT_DIFF_PREVIEW_LINES)) {
|
|
298
|
-
lines.push(line(span(`${diffLinePrefix(diffLine.kind)} `, { color: diffLineColor(diffLine.kind) }), span(fitLine(diffLine.content || ' ', width - 4), {
|
|
299
|
-
color: diffLineColor(diffLine.kind),
|
|
300
|
-
})));
|
|
301
|
-
}
|
|
345
|
+
lines.push(...renderDiffPreviewLines(entry.diffPreview, width));
|
|
302
346
|
}
|
|
303
347
|
if (entry.todoList && entry.todoList.length > 0) {
|
|
304
348
|
lines.push(...renderTodoListLines(entry.todoList, width));
|
|
305
349
|
}
|
|
306
350
|
return lines;
|
|
307
351
|
}
|
|
352
|
+
const transcriptEntryLineCache = new WeakMap();
|
|
353
|
+
const MAX_CACHED_TRANSCRIPT_WIDTHS = 2;
|
|
354
|
+
function cachedTranscriptEntryLines(entry, width) {
|
|
355
|
+
let byWidth = transcriptEntryLineCache.get(entry);
|
|
356
|
+
if (!byWidth) {
|
|
357
|
+
byWidth = new Map();
|
|
358
|
+
transcriptEntryLineCache.set(entry, byWidth);
|
|
359
|
+
}
|
|
360
|
+
const cached = byWidth.get(width);
|
|
361
|
+
if (cached)
|
|
362
|
+
return cached;
|
|
363
|
+
const lines = renderTranscriptEntryLines(entry, width);
|
|
364
|
+
if (byWidth.size >= MAX_CACHED_TRANSCRIPT_WIDTHS) {
|
|
365
|
+
const oldest = byWidth.keys().next().value;
|
|
366
|
+
if (oldest !== undefined)
|
|
367
|
+
byWidth.delete(oldest);
|
|
368
|
+
}
|
|
369
|
+
byWidth.set(width, lines);
|
|
370
|
+
return lines;
|
|
371
|
+
}
|
|
372
|
+
function renderDiffPreviewLines(preview, width, maxDiffLines = TRANSCRIPT_DIFF_PREVIEW_LINES) {
|
|
373
|
+
return [
|
|
374
|
+
plainLine(` Added ${preview.added} line${preview.added === 1 ? '' : 's'}, removed ${preview.removed} line${preview.removed === 1 ? '' : 's'}`, { color: 'gray' }),
|
|
375
|
+
...preview.lines.slice(0, maxDiffLines).map((diffLine) => line(span(`${diffLinePrefix(diffLine.kind)} `, {
|
|
376
|
+
color: diffLineColor(diffLine.kind),
|
|
377
|
+
}), span(fitLine(diffLine.content || ' ', width - 4), {
|
|
378
|
+
color: diffLineColor(diffLine.kind),
|
|
379
|
+
}))),
|
|
380
|
+
];
|
|
381
|
+
}
|
|
308
382
|
function tokenUsageLines(usage) {
|
|
309
|
-
const match = usage.match(/^Session tokens • in ([^•]+) • out ([^•]+)(?: • think ([^•]+))? • cache ([^•]+)(?: • write ([^•]+))
|
|
383
|
+
const match = usage.match(/^Session tokens • in ([^•]+) • out ([^•]+)(?: • think ([^•]+))? • cache ([^•]+)(?: • write ([^•]+))?$/);
|
|
310
384
|
if (!match) {
|
|
311
385
|
return [plainLine(usage, { color: 'cyan' })];
|
|
312
386
|
}
|
|
@@ -324,15 +398,16 @@ function tokenUsageLines(usage) {
|
|
|
324
398
|
if (match[5]) {
|
|
325
399
|
spans.push(span(' Write ', { color: 'gray' }), span(match[5].trim(), { color: 'yellow' }));
|
|
326
400
|
}
|
|
327
|
-
if (match[6]) {
|
|
328
|
-
spans.push(span(' Index ', { color: 'gray' }), span(match[6].trim(), { color: 'blue' }));
|
|
329
|
-
}
|
|
330
401
|
return [line(...spans)];
|
|
331
402
|
}
|
|
403
|
+
export const AGENT_MODE_LOCKED_STATUS = 'Mode locked while the agent is working';
|
|
332
404
|
function footerTransientStatus(status) {
|
|
333
405
|
const text = String(status ?? '').trim();
|
|
334
406
|
if (!text)
|
|
335
407
|
return null;
|
|
408
|
+
if (text === AGENT_MODE_LOCKED_STATUS) {
|
|
409
|
+
return { color: 'yellow', text, icon: '!' };
|
|
410
|
+
}
|
|
336
411
|
if (text === 'Copied selection' || text === 'Copied link') {
|
|
337
412
|
return { color: 'green', text, icon: '✓' };
|
|
338
413
|
}
|
|
@@ -349,10 +424,11 @@ function backgroundJobIndicatorSpans(state) {
|
|
|
349
424
|
if (runningCount === 0)
|
|
350
425
|
return [];
|
|
351
426
|
const noun = runningCount === 1 ? 'shell' : 'shells';
|
|
427
|
+
const hint = state.busy ? ' · ctrl+b' : ' · /jobs';
|
|
352
428
|
return [
|
|
353
429
|
span(' ', { color: 'gray', dim: true }),
|
|
354
430
|
span(`● ${runningCount} ${noun} running`, { color: 'green', bold: true }),
|
|
355
|
-
span(
|
|
431
|
+
span(hint, { color: 'gray', dim: true }),
|
|
356
432
|
];
|
|
357
433
|
}
|
|
358
434
|
function todoIndicatorSpans(state) {
|
|
@@ -372,9 +448,47 @@ function todoIndicatorSpans(state) {
|
|
|
372
448
|
}),
|
|
373
449
|
];
|
|
374
450
|
}
|
|
375
|
-
function
|
|
451
|
+
function composerFooterRightHints(state) {
|
|
452
|
+
const cancelHint = state.busy && !state.queuedMessage && !state.userInputPrompt
|
|
453
|
+
? FOOTER_CANCEL_HINT
|
|
454
|
+
: '';
|
|
455
|
+
const helpHint = shortcutsPanelAvailable(state) ? FOOTER_HELP_HINT : '';
|
|
456
|
+
const notifyHint = footerNotificationHint(state.transientStatus);
|
|
457
|
+
const join = (...parts) => parts.filter(Boolean).join(' · ');
|
|
458
|
+
const tiers = [];
|
|
459
|
+
if (notifyHint) {
|
|
460
|
+
tiers.push(join(cancelHint, notifyHint, helpHint));
|
|
461
|
+
tiers.push(join(notifyHint, helpHint));
|
|
462
|
+
tiers.push(join(cancelHint, notifyHint));
|
|
463
|
+
tiers.push(notifyHint);
|
|
464
|
+
}
|
|
465
|
+
if (cancelHint && helpHint)
|
|
466
|
+
tiers.push(`${cancelHint} · ${helpHint}`);
|
|
467
|
+
if (cancelHint)
|
|
468
|
+
tiers.push(cancelHint);
|
|
469
|
+
if (helpHint)
|
|
470
|
+
tiers.push(helpHint);
|
|
471
|
+
tiers.push('');
|
|
472
|
+
return tiers.filter((tier, index) => tiers.indexOf(tier) === index);
|
|
473
|
+
}
|
|
474
|
+
export function fitComposerFooterRow({ modeLabels, modeLabelFallback, cycleHint, rightHints, leadWidth, tailWidth, contentWidth, }) {
|
|
475
|
+
const candidates = rightHints.flatMap((rightHint) => (cycleHint ? [cycleHint, ''] : ['']).flatMap((cycle) => modeLabels.map((modeLabel) => ({ modeLabel, cycleHint: cycle, rightHint }))));
|
|
476
|
+
const hasTail = (rightHint) => Boolean(rightHint) || tailWidth > 0;
|
|
477
|
+
const rowWidth = (choice, gap) => leadWidth +
|
|
478
|
+
displayWidth(choice.modeLabel) +
|
|
479
|
+
displayWidth(choice.cycleHint) +
|
|
480
|
+
(hasTail(choice.rightHint) ? gap : 0) +
|
|
481
|
+
displayWidth(choice.rightHint) +
|
|
482
|
+
tailWidth;
|
|
483
|
+
const chosen = candidates.find((choice) => rowWidth(choice, FOOTER_HINT_MIN_GAP) <= contentWidth) ?? { modeLabel: modeLabelFallback, cycleHint: '', rightHint: '' };
|
|
484
|
+
const gap = hasTail(chosen.rightHint)
|
|
485
|
+
? Math.max(FOOTER_HINT_MIN_GAP, contentWidth - rowWidth(chosen, 0))
|
|
486
|
+
: 0;
|
|
487
|
+
return { ...chosen, gap };
|
|
488
|
+
}
|
|
489
|
+
function composerFooterLines(state, contentWidth) {
|
|
376
490
|
const visibleSessionId = formatPromptSessionIdLabel(state.showSessionId, state.sessionId);
|
|
377
|
-
const transientStatus = footerTransientStatus(state.
|
|
491
|
+
const transientStatus = footerTransientStatus(state.transientStatus ?? null);
|
|
378
492
|
const lines = [
|
|
379
493
|
line(span('TheGitAI', { color: 'cyan', bold: true }), span(' • ', { color: 'gray', dim: true }), span(formatPromptDirectoryLabel(state.projectRoot), { color: 'cyan' }), ...(transientStatus
|
|
380
494
|
? [
|
|
@@ -392,11 +506,6 @@ function composerFooterLines(state) {
|
|
|
392
506
|
? [span(` ${visibleSessionId}`, { color: 'gray', dim: true })]
|
|
393
507
|
: []), ...backgroundJobIndicatorSpans(state), ...todoIndicatorSpans(state)),
|
|
394
508
|
plainLine(''),
|
|
395
|
-
plainLine(formatModelLabel(state.currentModelId, state.serverModels), {
|
|
396
|
-
color: 'cyan',
|
|
397
|
-
dim: true,
|
|
398
|
-
}),
|
|
399
|
-
plainLine(''),
|
|
400
509
|
];
|
|
401
510
|
if (state.exitConfirmUntil != null) {
|
|
402
511
|
lines.push(plainLine(state.status || 'Press Ctrl+C again to quit.', {
|
|
@@ -405,28 +514,63 @@ function composerFooterLines(state) {
|
|
|
405
514
|
}));
|
|
406
515
|
return lines;
|
|
407
516
|
}
|
|
408
|
-
const helperText = state.busy
|
|
409
|
-
? state.queuedMessage
|
|
410
|
-
? 'Enter re-queues • ↑ edit queued • Esc cancels queued'
|
|
411
|
-
: 'Enter queues • Esc / Ctrl+C cancel turn'
|
|
412
|
-
: process.platform === 'win32'
|
|
413
|
-
? 'Enter sends • Shift+Tab mode • Alt+V image • Esc cancel turn • Ctrl+C quits'
|
|
414
|
-
: process.platform === 'darwin'
|
|
415
|
-
? 'Enter sends • Shift+Tab mode • Ctrl+V image • Esc cancel turn • Ctrl+C quits'
|
|
416
|
-
: 'Enter sends • Shift+Tab mode • Ctrl+V image • Esc cancel turn • Ctrl+C quits';
|
|
417
|
-
const agentLabel = agentModeLabel(state.agentMode).padEnd(AGENT_MODE_LABEL_WIDTH);
|
|
418
517
|
const tokenUsageText = state.tokenUsage || formatClientTokenUsage(null);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
lines.push(line(...footerSpans));
|
|
518
|
+
lines.push(...composerFooterModeLines(state, contentWidth, formatModelLabel(state.currentModelId, state.serverModels), tokenUsageText
|
|
519
|
+
? displayWidth(tokenUsageText) + FOOTER_USAGE_SEPARATOR.length
|
|
520
|
+
: 0, tokenUsageText
|
|
521
|
+
? [
|
|
522
|
+
span(FOOTER_USAGE_SEPARATOR, mutedStyle()),
|
|
523
|
+
span(tokenUsageText, { color: 'cyan' }),
|
|
524
|
+
]
|
|
525
|
+
: []));
|
|
428
526
|
return lines;
|
|
429
527
|
}
|
|
528
|
+
function composerFooterModeLines(state, contentWidth, modelLabel, usageWidth, usageSpans) {
|
|
529
|
+
const effort = REASONING_EFFORT_LABELS[state.reasoningEffort ?? 'default'];
|
|
530
|
+
const onAuto = state.serverModels.some((model) => model.id === state.currentModelId && model.auto);
|
|
531
|
+
const effortText = onAuto ? '' : ` · ${effort} effort`;
|
|
532
|
+
const modeLabels = agentModeLabelTiers(state.agentMode).map((label) => `Mode: ${label}`);
|
|
533
|
+
const modeWidth = displayWidth(modeLabels[0]);
|
|
534
|
+
const separateUsage = usageWidth > 0 && modeWidth + usageWidth > contentWidth;
|
|
535
|
+
const tailWidth = separateUsage ? 0 : usageWidth;
|
|
536
|
+
const canCancel = state.busy && !state.queuedMessage && !state.userInputPrompt;
|
|
537
|
+
const feedbackHints = [canCancel ? FOOTER_CANCEL_HINT : '', footerNotificationHint(state.transientStatus)].filter(Boolean);
|
|
538
|
+
const feedback = feedbackHints.join(' · ');
|
|
539
|
+
const feedbackWidth = feedback ? displayWidth(feedback) + FOOTER_HINT_MIN_GAP : 0;
|
|
540
|
+
const combined = displayWidth(modelLabel + effortText) + FOOTER_MODEL_SEPARATOR.length + modeWidth + tailWidth + feedbackWidth <= contentWidth;
|
|
541
|
+
const modelText = combined ? modelLabel : fitModelLabel(modelLabel, contentWidth - displayWidth(effortText));
|
|
542
|
+
const modelSpans = [
|
|
543
|
+
span(modelText, { color: 'cyan' }),
|
|
544
|
+
span(effortText, { bold: true }),
|
|
545
|
+
];
|
|
546
|
+
const row = fitComposerFooterRow({
|
|
547
|
+
modeLabels,
|
|
548
|
+
modeLabelFallback: `Mode: ${agentModeShortLabel(state.agentMode)}`,
|
|
549
|
+
cycleHint: state.busy ? '' : FOOTER_CYCLE_HINT,
|
|
550
|
+
rightHints: composerFooterRightHints(state),
|
|
551
|
+
leadWidth: combined ? displayWidth(modelLabel + effortText) + FOOTER_MODEL_SEPARATOR.length : 0,
|
|
552
|
+
tailWidth,
|
|
553
|
+
contentWidth,
|
|
554
|
+
});
|
|
555
|
+
const remainingHints = feedbackHints.filter((hint) => !row.rightHint.includes(hint));
|
|
556
|
+
const remainingFeedback = remainingHints.join(' · ');
|
|
557
|
+
const feedbackLines = !remainingFeedback ? []
|
|
558
|
+
: displayWidth(remainingFeedback) <= contentWidth ? [remainingFeedback]
|
|
559
|
+
: remainingHints.flatMap((hint) => wrapText(hint, contentWidth));
|
|
560
|
+
const footerMuted = mutedStyle();
|
|
561
|
+
const modeLine = line(...(combined ? [...modelSpans, span(FOOTER_MODEL_SEPARATOR, footerMuted)] : []), span(row.modeLabel, {
|
|
562
|
+
color: agentModeColor(state.agentMode),
|
|
563
|
+
bold: state.agentMode === 'auto-accept',
|
|
564
|
+
}), ...(row.cycleHint ? [span(row.cycleHint, footerMuted)] : []), ...(row.gap ? [span(' '.repeat(row.gap), footerMuted)] : []), ...(row.rightHint ? [span(row.rightHint, footerMuted)] : []), ...(separateUsage ? [] : usageSpans));
|
|
565
|
+
return [
|
|
566
|
+
...(combined ? [] : [line(...modelSpans)]),
|
|
567
|
+
modeLine,
|
|
568
|
+
...feedbackLines.map((text) => plainLine(text, footerMuted)),
|
|
569
|
+
...(separateUsage ? wrapText(usageSpans.slice(1).map((part) => part.text).join(''), contentWidth).map((text) => plainLine(text, { color: 'cyan' })) : []),
|
|
570
|
+
];
|
|
571
|
+
}
|
|
572
|
+
const FOOTER_USAGE_SEPARATOR = ' ';
|
|
573
|
+
const FOOTER_MODEL_SEPARATOR = ' ';
|
|
430
574
|
export function formatJobElapsed(elapsedMs) {
|
|
431
575
|
const totalSeconds = Math.max(0, Math.floor(elapsedMs / 1000));
|
|
432
576
|
if (totalSeconds < 60)
|
|
@@ -468,15 +612,29 @@ function jobStatusDescriptor(job, nowMs) {
|
|
|
468
612
|
? { glyph: '✓', color: 'green', text: `exited (0) · ran ${ran}` }
|
|
469
613
|
: { glyph: '✖', color: 'red', text: `exited (${job.exitCode ?? 1}) · ran ${ran}` };
|
|
470
614
|
}
|
|
471
|
-
|
|
615
|
+
const JOBS_PICKER_CHROME_ROWS = 2;
|
|
616
|
+
const JOBS_PICKER_MIN_ROWS = 8;
|
|
617
|
+
function buildJobsPickerLines(state, width, height, nowMs) {
|
|
472
618
|
const jobs = state.backgroundJobs ?? [];
|
|
619
|
+
const bodyBudget = Math.max(1, height - JOBS_PICKER_CHROME_ROWS);
|
|
473
620
|
const lines = [
|
|
474
621
|
plainLine('Background jobs', { color: 'cyan', bold: true }),
|
|
475
622
|
];
|
|
476
623
|
if (jobs.length === 0) {
|
|
477
624
|
lines.push(plainLine('No background jobs in this session.', { color: 'gray' }));
|
|
478
625
|
}
|
|
479
|
-
|
|
626
|
+
let start = 0;
|
|
627
|
+
let visible = jobs;
|
|
628
|
+
if (jobs.length > bodyBudget) {
|
|
629
|
+
start = Math.min(Math.max(0, state.jobsPickerIndex - Math.floor(bodyBudget / 2)), jobs.length - bodyBudget);
|
|
630
|
+
visible = jobs.slice(start, start + bodyBudget);
|
|
631
|
+
if (start > 0) {
|
|
632
|
+
lines.push(plainLine(` … ${start} newer`, { color: 'gray', dim: true }));
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
const detailBudget = Math.max(0, bodyBudget - visible.length - (start > 0 ? 1 : 0));
|
|
636
|
+
for (const [offset, job] of visible.entries()) {
|
|
637
|
+
const index = start + offset;
|
|
480
638
|
const selected = index === state.jobsPickerIndex;
|
|
481
639
|
const expanded = state.jobsPickerExpandedId === job.id;
|
|
482
640
|
const { glyph, color, text } = jobStatusDescriptor(job, nowMs);
|
|
@@ -485,10 +643,11 @@ function buildJobsPickerLines(state, width, nowMs) {
|
|
|
485
643
|
bold: selected,
|
|
486
644
|
}), span(` ${text}`, { color: 'gray' })));
|
|
487
645
|
if (expanded) {
|
|
488
|
-
const
|
|
646
|
+
const allDetail = (job.detailLines ?? []).length
|
|
489
647
|
? job.detailLines ?? []
|
|
490
648
|
: backgroundJobPreviewLines(job, 3);
|
|
491
|
-
|
|
649
|
+
const detailLines = allDetail.slice(-detailBudget);
|
|
650
|
+
if (detailBudget > 0 && detailLines.length === 0) {
|
|
492
651
|
lines.push(plainLine(' (no output captured)', { color: 'gray' }));
|
|
493
652
|
}
|
|
494
653
|
else {
|
|
@@ -501,22 +660,71 @@ function buildJobsPickerLines(state, width, nowMs) {
|
|
|
501
660
|
}
|
|
502
661
|
}
|
|
503
662
|
}
|
|
663
|
+
const remaining = jobs.length - (start + visible.length);
|
|
664
|
+
if (remaining > 0) {
|
|
665
|
+
lines.push(plainLine(` … ${remaining} older`, { color: 'gray', dim: true }));
|
|
666
|
+
}
|
|
504
667
|
lines.push(plainLine('↑/↓ move enter expand/collapse k kill esc close', {
|
|
505
668
|
color: 'gray',
|
|
506
669
|
}));
|
|
507
670
|
return lines;
|
|
508
671
|
}
|
|
672
|
+
export const THINKING_FALLBACK_PHRASES = [
|
|
673
|
+
'Working out where to start...',
|
|
674
|
+
'Deciding what comes first...',
|
|
675
|
+
'Lining up the pieces...',
|
|
676
|
+
'Untangling the details...',
|
|
677
|
+
'Deciding what not to touch...',
|
|
678
|
+
'Checking what this would break...',
|
|
679
|
+
'Choosing the smaller change...',
|
|
680
|
+
'Picking the least clever option...',
|
|
681
|
+
'Resisting the obvious answer...',
|
|
682
|
+
'Trying the boring explanation first...',
|
|
683
|
+
'Checking whether the assumption holds...',
|
|
684
|
+
'Asking what would have to be true...',
|
|
685
|
+
'Reading it the way the machine would...',
|
|
686
|
+
'Testing the story against the code...',
|
|
687
|
+
'Working out what actually changed...',
|
|
688
|
+
'Finding the smallest thing that explains it...',
|
|
689
|
+
'Looking for the part that is not settled yet...',
|
|
690
|
+
'Making sure this is the simple version...',
|
|
691
|
+
];
|
|
692
|
+
export function pickThinkingFallbackPhrase() {
|
|
693
|
+
const index = Math.floor(Math.random() * THINKING_FALLBACK_PHRASES.length);
|
|
694
|
+
return THINKING_FALLBACK_PHRASES[index];
|
|
695
|
+
}
|
|
696
|
+
function withProgressEllipsis(title) {
|
|
697
|
+
const text = title.trim();
|
|
698
|
+
if (!text)
|
|
699
|
+
return text;
|
|
700
|
+
return /(?:\.\.\.|…)$/.test(text) ? text : `${text}...`;
|
|
701
|
+
}
|
|
509
702
|
function thinkingHeaderLine(spinnerFrame, title, width) {
|
|
510
703
|
const spinner = `${BRAILLE_SPINNER_FRAMES[spinnerFrame % BRAILLE_SPINNER_FRAMES.length]} `;
|
|
511
|
-
const
|
|
512
|
-
|
|
704
|
+
const decorated = withProgressEllipsis(title);
|
|
705
|
+
const fittedTitle = decorated
|
|
706
|
+
? fitLine(decorated, Math.max(8, width - spinner.length - 'Thinking'.length - 3))
|
|
513
707
|
: '';
|
|
514
708
|
return line(span(spinner, { color: 'green' }), span('Thinking', { color: 'green', bold: true }), ...(fittedTitle ? [span(` · ${fittedTitle}`, { color: 'ansi256(248)' })] : []));
|
|
515
709
|
}
|
|
516
710
|
function thinkingNoteLine(note, width) {
|
|
517
711
|
return line(span('│ ', { color: 'green' }), span(fitLine(note, Math.max(8, width - 3)), { color: 'ansi256(248)' }));
|
|
518
712
|
}
|
|
519
|
-
function
|
|
713
|
+
function buildRecoveryStatusLines(status, width) {
|
|
714
|
+
const [label = '', ...rest] = status.split(' · ');
|
|
715
|
+
const detail = rest.join(' · ');
|
|
716
|
+
const labelSpan = span(fitLine(label, Math.max(1, width - 2)), { color: 'yellow', bold: true });
|
|
717
|
+
if (!detail)
|
|
718
|
+
return [line(span('● ', { color: 'yellow' }), labelSpan)];
|
|
719
|
+
if (displayWidth(`● ${label} · ${detail}`) <= width) {
|
|
720
|
+
return [line(span('● ', { color: 'yellow' }), labelSpan, span(` · ${detail}`))];
|
|
721
|
+
}
|
|
722
|
+
return [
|
|
723
|
+
line(span('● ', { color: 'yellow' }), labelSpan),
|
|
724
|
+
...wrapText(detail, Math.max(1, width - 2)).map((row) => plainLine(` ${row}`)),
|
|
725
|
+
];
|
|
726
|
+
}
|
|
727
|
+
function buildLiveLines(state, width, spinnerFrame, elapsedSeconds, nowMs) {
|
|
520
728
|
if (!state.busy)
|
|
521
729
|
return [];
|
|
522
730
|
const lines = [plainLine('')];
|
|
@@ -546,11 +754,26 @@ function buildLiveLines(state, width, spinnerFrame, elapsedSeconds) {
|
|
|
546
754
|
}
|
|
547
755
|
lines.push(plainLine(''));
|
|
548
756
|
}
|
|
549
|
-
lines.push(plainLine(
|
|
757
|
+
lines.push(plainLine(buildWorkingClockLine(state, elapsedSeconds), { color: 'yellow' }));
|
|
758
|
+
if (state.recoveryStatus) {
|
|
759
|
+
lines.push(...buildRecoveryStatusLines(state.recoveryStatus, width));
|
|
760
|
+
}
|
|
761
|
+
if (state.usageNotice) {
|
|
762
|
+
lines.push(plainLine(''));
|
|
763
|
+
lines.push(...renderTranscriptEntryLines(state.usageNotice, width));
|
|
764
|
+
}
|
|
765
|
+
const turnMessages = state.turnMessages ?? [];
|
|
766
|
+
if (turnMessages.length > 0) {
|
|
767
|
+
lines.push(plainLine(''));
|
|
768
|
+
lines.push(...buildTurnMessageLines(turnMessages, width, todoProgressTick(nowMs)));
|
|
769
|
+
}
|
|
550
770
|
const todos = state.todos ?? [];
|
|
551
771
|
if (todos.length > 0) {
|
|
552
772
|
lines.push(plainLine(''));
|
|
553
|
-
lines.push(...renderTodoListLines(todos, width, {
|
|
773
|
+
lines.push(...renderTodoListLines(todos, width, {
|
|
774
|
+
header: true,
|
|
775
|
+
progressTick: todoProgressTick(nowMs),
|
|
776
|
+
}));
|
|
554
777
|
}
|
|
555
778
|
const visibleTitle = state.thinkingTitle.trim();
|
|
556
779
|
const visibleNotes = state.thinkingNotes.filter(Boolean);
|
|
@@ -560,11 +783,12 @@ function buildLiveLines(state, width, spinnerFrame, elapsedSeconds) {
|
|
|
560
783
|
const minimalText = visibleTitle && visibleTitle !== 'Thinking'
|
|
561
784
|
? visibleTitle
|
|
562
785
|
: (visibleNotes[visibleNotes.length - 1] ?? '');
|
|
563
|
-
lines.push(thinkingHeaderLine(spinnerFrame, minimalText, width));
|
|
786
|
+
lines.push(thinkingHeaderLine(spinnerFrame, minimalText || THINKING_FALLBACK_PHRASES[0], width));
|
|
564
787
|
}
|
|
565
788
|
else {
|
|
566
|
-
|
|
567
|
-
|
|
789
|
+
const headerTitle = visibleTitle && visibleTitle !== 'Thinking' ? visibleTitle : '';
|
|
790
|
+
lines.push(thinkingHeaderLine(spinnerFrame, headerTitle || THINKING_FALLBACK_PHRASES[0], width));
|
|
791
|
+
for (const note of visibleNotes.slice(0, THINKING_NOTE_PREVIEW_ROWS)) {
|
|
568
792
|
lines.push(thinkingNoteLine(note, width));
|
|
569
793
|
}
|
|
570
794
|
}
|
|
@@ -579,10 +803,24 @@ function overlayPanelLine(row, width, color) {
|
|
|
579
803
|
const padding = Math.max(0, width - lineCharCount(row));
|
|
580
804
|
return line(span('│ ', { color }), ...row.spans, span(' '.repeat(padding)), span(' │', { color }));
|
|
581
805
|
}
|
|
582
|
-
function
|
|
583
|
-
|
|
806
|
+
function overlayPanelMarginLineCount(height) {
|
|
807
|
+
return height < OVERLAY_PANEL_MARGIN_MIN_ROWS
|
|
808
|
+
? 0
|
|
809
|
+
: OVERLAY_PANEL_MARGIN_LINES;
|
|
810
|
+
}
|
|
811
|
+
function overlayPanelContentBudget(height) {
|
|
812
|
+
if (!Number.isFinite(height)) {
|
|
813
|
+
return Number.POSITIVE_INFINITY;
|
|
814
|
+
}
|
|
815
|
+
const margins = overlayPanelMarginLineCount(height) * 2;
|
|
816
|
+
return Math.max(1, Math.floor(height) - margins - 2);
|
|
817
|
+
}
|
|
818
|
+
function buildOverlayPanel(rows, width, color, height = Number.POSITIVE_INFINITY, maxWidth = OVERLAY_PANEL_MAX_WIDTH) {
|
|
819
|
+
const panelWidth = Math.max(24, Math.min(width, maxWidth));
|
|
584
820
|
const innerWidth = Math.max(1, panelWidth - 4);
|
|
585
|
-
const margin = Array.from({
|
|
821
|
+
const margin = Array.from({
|
|
822
|
+
length: overlayPanelMarginLineCount(height),
|
|
823
|
+
}, () => plainLine(''));
|
|
586
824
|
return [
|
|
587
825
|
...margin,
|
|
588
826
|
plainLine(`╭${'─'.repeat(panelWidth - 2)}╮`, { color }),
|
|
@@ -592,7 +830,7 @@ function buildOverlayPanel(rows, width, color) {
|
|
|
592
830
|
];
|
|
593
831
|
}
|
|
594
832
|
function padSpansToInnerWidth(spans, innerWidth, fill) {
|
|
595
|
-
const used = spans.reduce((total, part) => total +
|
|
833
|
+
const used = spans.reduce((total, part) => total + displayWidth(part.text), 0);
|
|
596
834
|
const pad = Math.max(0, innerWidth - used);
|
|
597
835
|
if (pad === 0)
|
|
598
836
|
return spans;
|
|
@@ -602,9 +840,9 @@ function modelPickerPanelSideLine(content, innerWidth) {
|
|
|
602
840
|
return overlayPanelLine(content, innerWidth, MODEL_PICKER_BORDER_COLOR);
|
|
603
841
|
}
|
|
604
842
|
const MODEL_PICKER_COST_WIDTH = 6;
|
|
605
|
-
const
|
|
606
|
-
const
|
|
607
|
-
const
|
|
843
|
+
const MODEL_PICKER_MODEL_MIN_WIDTH = 42;
|
|
844
|
+
const MODEL_PICKER_MODEL_MAX_WIDTH = 54;
|
|
845
|
+
const MODEL_PICKER_COLUMN_GAP = ' ';
|
|
608
846
|
const MODEL_PICKER_WIDE_MIN_WIDTH = 78;
|
|
609
847
|
function modelPickerTopBorder(panelWidth) {
|
|
610
848
|
const fullTitle = ' TheGitAI - Model Selection ';
|
|
@@ -628,51 +866,55 @@ function modelPickerCostText(rating) {
|
|
|
628
866
|
const steps = Math.max(1, Math.min(3, Math.round(rating)));
|
|
629
867
|
return '$'.repeat(steps);
|
|
630
868
|
}
|
|
869
|
+
function modelPickerModelWidth(innerWidth) {
|
|
870
|
+
return Math.min(MODEL_PICKER_MODEL_MAX_WIDTH, Math.max(MODEL_PICKER_MODEL_MIN_WIDTH, innerWidth - MODEL_PICKER_COST_WIDTH - MODEL_PICKER_COLUMN_GAP.length * 2 - 18));
|
|
871
|
+
}
|
|
631
872
|
function modelPickerNotesWidth(innerWidth) {
|
|
632
873
|
return Math.max(18, innerWidth -
|
|
633
|
-
|
|
634
|
-
MODEL_PICKER_MODEL_WIDTH -
|
|
874
|
+
modelPickerModelWidth(innerWidth) -
|
|
635
875
|
MODEL_PICKER_COST_WIDTH -
|
|
636
|
-
|
|
876
|
+
MODEL_PICKER_COLUMN_GAP.length * 2);
|
|
637
877
|
}
|
|
638
|
-
function modelPickerModelSpans(option, selected, width, showCurrentTag, labelStyle, selectedStyle) {
|
|
878
|
+
function modelPickerModelSpans(option, selected, effort, width, showCurrentTag, labelStyle, selectedStyle) {
|
|
639
879
|
const tag = option.current && showCurrentTag ? ' (current)' : '';
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
880
|
+
const effortText = option.group === 'auto' || effort === 'default'
|
|
881
|
+
? ''
|
|
882
|
+
: ` · ${REASONING_EFFORT_LABELS[effort]}`;
|
|
883
|
+
const nameWidth = Math.max(1, width - displayWidth(tag + effortText) - 2);
|
|
884
|
+
const label = `${selected ? '▶ ' : ' '}${fitModelLabel(option.label, nameWidth)}`;
|
|
885
|
+
const used = displayWidth(label + effortText + tag);
|
|
643
886
|
return [
|
|
644
887
|
span(label, { ...labelStyle, ...selectedStyle }),
|
|
888
|
+
span(effortText, { color: mutedColor(), bold: selected, ...selectedStyle }),
|
|
645
889
|
span(tag, { color: 'gray', ...selectedStyle }),
|
|
646
890
|
span(' '.repeat(Math.max(0, width - used)), selectedStyle),
|
|
647
891
|
];
|
|
648
892
|
}
|
|
649
|
-
function modelPickerItemLines(option, selected, innerWidth) {
|
|
893
|
+
function modelPickerItemLines(option, selected, effort, innerWidth) {
|
|
650
894
|
const selectedStyle = selected ? { bgColor: MODEL_PICKER_HIGHLIGHT_BG } : {};
|
|
651
895
|
const labelStyle = option.disabled
|
|
652
896
|
? { color: 'gray' }
|
|
653
897
|
: selected
|
|
654
898
|
? { color: 'cyan', bold: true }
|
|
655
899
|
: {};
|
|
656
|
-
const numberCell = modelPickerCell(String(option.publicId), MODEL_PICKER_NUMBER_WIDTH, { color: 'cyan', bold: selected, ...selectedStyle });
|
|
657
900
|
const cost = modelPickerCostText(option.costRating);
|
|
658
901
|
if (innerWidth < MODEL_PICKER_WIDE_MIN_WIDTH) {
|
|
659
|
-
const
|
|
902
|
+
const costWidth = 3;
|
|
903
|
+
const modelWidth = Math.max(12, innerWidth - costWidth - 2);
|
|
660
904
|
const row = [
|
|
661
|
-
|
|
662
|
-
...modelPickerModelSpans(option, selected, modelWidth, false, labelStyle, selectedStyle),
|
|
905
|
+
...modelPickerModelSpans(option, selected, effort, modelWidth, false, labelStyle, selectedStyle),
|
|
663
906
|
span(' ', selectedStyle),
|
|
664
|
-
modelPickerCell(cost,
|
|
907
|
+
modelPickerCell(cost, costWidth, selectedStyle),
|
|
665
908
|
];
|
|
666
909
|
return [
|
|
667
910
|
modelPickerPanelSideLine(line(...padSpansToInnerWidth(row, innerWidth, selectedStyle)), innerWidth),
|
|
668
911
|
];
|
|
669
912
|
}
|
|
670
913
|
const row = [
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
span(MODEL_PICKER_SEPARATOR, { color: 'gray', ...selectedStyle }),
|
|
914
|
+
...modelPickerModelSpans(option, selected, effort, modelPickerModelWidth(innerWidth), true, labelStyle, selectedStyle),
|
|
915
|
+
span(MODEL_PICKER_COLUMN_GAP, selectedStyle),
|
|
674
916
|
modelPickerCell(cost, MODEL_PICKER_COST_WIDTH, selectedStyle),
|
|
675
|
-
span(
|
|
917
|
+
span(MODEL_PICKER_COLUMN_GAP, selectedStyle),
|
|
676
918
|
modelPickerCell(option.note, modelPickerNotesWidth(innerWidth), {
|
|
677
919
|
color: 'gray',
|
|
678
920
|
...selectedStyle,
|
|
@@ -682,39 +924,146 @@ function modelPickerItemLines(option, selected, innerWidth) {
|
|
|
682
924
|
modelPickerPanelSideLine(line(...padSpansToInnerWidth(row, innerWidth, selectedStyle)), innerWidth),
|
|
683
925
|
];
|
|
684
926
|
}
|
|
685
|
-
function
|
|
927
|
+
function modelPickerHeadingLine(title, innerWidth, withColumns) {
|
|
686
928
|
const heading = { color: MODEL_PICKER_ACCENT_COLOR, bold: true };
|
|
687
|
-
if (innerWidth < MODEL_PICKER_WIDE_MIN_WIDTH) {
|
|
688
|
-
return line(modelPickerCell(
|
|
929
|
+
if (!withColumns || innerWidth < MODEL_PICKER_WIDE_MIN_WIDTH) {
|
|
930
|
+
return line(modelPickerCell(title, Math.max(1, innerWidth), heading));
|
|
931
|
+
}
|
|
932
|
+
const muted = { color: 'gray' };
|
|
933
|
+
return line(modelPickerCell(title, modelPickerModelWidth(innerWidth), heading), span(MODEL_PICKER_COLUMN_GAP), modelPickerCell('Cost', MODEL_PICKER_COST_WIDTH, muted), span(MODEL_PICKER_COLUMN_GAP), modelPickerCell('Notes', modelPickerNotesWidth(innerWidth), muted));
|
|
934
|
+
}
|
|
935
|
+
function modelPickerDisplayRows(options) {
|
|
936
|
+
const rows = [];
|
|
937
|
+
const autoIndexes = options.flatMap((option, index) => (option.group === 'auto' ? [index] : []));
|
|
938
|
+
const modelIndexes = options.flatMap((option, index) => (option.group === 'models' ? [index] : []));
|
|
939
|
+
if (autoIndexes.length) {
|
|
940
|
+
rows.push({ kind: 'heading', title: 'Auto', withColumns: true });
|
|
941
|
+
rows.push(...autoIndexes.map((index) => ({ kind: 'option', index })));
|
|
689
942
|
}
|
|
690
|
-
|
|
943
|
+
if (modelIndexes.length) {
|
|
944
|
+
if (rows.length)
|
|
945
|
+
rows.push({ kind: 'gap' });
|
|
946
|
+
rows.push({ kind: 'heading', title: 'Models', withColumns: rows.length === 0 });
|
|
947
|
+
rows.push(...modelIndexes.map((index) => ({ kind: 'option', index })));
|
|
948
|
+
}
|
|
949
|
+
return rows;
|
|
691
950
|
}
|
|
692
|
-
function buildModelPickerPanel(options, selectedIndex, width, availableHeight) {
|
|
951
|
+
function buildModelPickerPanel(options, selectedIndex, width, availableHeight, efforts = {}) {
|
|
693
952
|
const panelWidth = Math.max(28, Math.min(width, MODEL_PICKER_PANEL_MAX_WIDTH));
|
|
694
953
|
const innerWidth = Math.max(1, panelWidth - 4);
|
|
695
|
-
const
|
|
696
|
-
const
|
|
697
|
-
const
|
|
698
|
-
const
|
|
954
|
+
const rows = modelPickerDisplayRows(options);
|
|
955
|
+
const showEffortDetails = rows.length + 8 <= availableHeight;
|
|
956
|
+
const fixedLineCount = showEffortDetails ? 8 : 5;
|
|
957
|
+
const visibleCount = Math.min(rows.length, Math.max(1, availableHeight - fixedLineCount));
|
|
958
|
+
const selectedRow = Math.max(0, rows.findIndex((row) => row.kind === 'option' && row.index === selectedIndex));
|
|
959
|
+
const firstVisible = Math.max(0, Math.min(selectedRow - visibleCount + 1, rows.length - visibleCount));
|
|
960
|
+
const visibleRows = rows.slice(firstVisible, firstVisible + visibleCount);
|
|
961
|
+
const bodyLineCount = visibleRows.length + fixedLineCount;
|
|
699
962
|
const marginLineCount = Math.max(0, Math.min(MODEL_PICKER_PANEL_MARGIN_LINES, Math.floor((availableHeight - bodyLineCount) / 2)));
|
|
700
963
|
const margin = Array.from({ length: marginLineCount }, () => plainLine(''));
|
|
701
|
-
const body = [
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
body.push(...modelPickerItemLines(option, index === selectedIndex, innerWidth));
|
|
708
|
-
if (useRowSpacing && index < options.length - 1) {
|
|
964
|
+
const body = [modelPickerTopBorder(panelWidth)];
|
|
965
|
+
for (const row of visibleRows) {
|
|
966
|
+
if (row.kind === 'heading') {
|
|
967
|
+
body.push(modelPickerPanelSideLine(modelPickerHeadingLine(row.title, innerWidth, row.withColumns), innerWidth));
|
|
968
|
+
}
|
|
969
|
+
else if (row.kind === 'gap') {
|
|
709
970
|
body.push(modelPickerPanelSideLine(plainLine(''), innerWidth));
|
|
710
971
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
972
|
+
else {
|
|
973
|
+
const option = options[row.index];
|
|
974
|
+
body.push(...modelPickerItemLines(option, row.index === selectedIndex, projectModelEffort(efforts, option.publicId), innerWidth));
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
const selected = options[selectedIndex];
|
|
978
|
+
const selectedEffort = projectModelEffort(efforts, selected?.publicId ?? 0);
|
|
979
|
+
const autoSelected = selected?.group === 'auto';
|
|
980
|
+
const effortChoices = REASONING_EFFORTS.map((effort) => effort === selectedEffort ? `[${REASONING_EFFORT_LABELS[effort]}]` : REASONING_EFFORT_LABELS[effort]).join(' ');
|
|
981
|
+
const fullEffort = autoSelected ? 'Reasoning effort: Auto Adjusted' : `Reasoning effort: ${effortChoices}`;
|
|
982
|
+
const effortText = [...fullEffort].length <= innerWidth
|
|
983
|
+
? fullEffort
|
|
984
|
+
: autoSelected
|
|
985
|
+
? 'Effort: Auto Adjusted'
|
|
986
|
+
: `Effort: ${REASONING_EFFORT_LABELS[selectedEffort]} ←/→`;
|
|
987
|
+
const effortDescription = autoSelected
|
|
988
|
+
? 'Auto picks the model and its reasoning effort for each session.'
|
|
989
|
+
: REASONING_EFFORT_DESCRIPTIONS[selectedEffort];
|
|
990
|
+
const fullHint = autoSelected
|
|
991
|
+
? '↑/↓ model • Enter select • Esc cancel'
|
|
992
|
+
: '↑/↓ model • ←/→ effort • Enter select/save • Esc cancel';
|
|
993
|
+
const compactHint = autoSelected ? '↑↓ · Enter · Esc' : '↑↓ · ←→ · Enter · Esc';
|
|
714
994
|
const hint = [...fullHint].length <= innerWidth ? fullHint : compactHint;
|
|
715
|
-
body.push(modelPickerDivider(panelWidth), modelPickerPanelSideLine(plainLine(fitLine(
|
|
995
|
+
body.push(modelPickerDivider(panelWidth), modelPickerPanelSideLine(plainLine(fitLine(effortText, innerWidth), { color: 'cyan', bold: true }), innerWidth), ...(showEffortDetails ? [
|
|
996
|
+
modelPickerPanelSideLine(plainLine(''), innerWidth),
|
|
997
|
+
modelPickerPanelSideLine(plainLine(fitLine(effortDescription, innerWidth), { color: 'gray' }), innerWidth),
|
|
998
|
+
modelPickerPanelSideLine(plainLine(''), innerWidth),
|
|
999
|
+
] : []), modelPickerPanelSideLine(plainLine(fitLine(hint, innerWidth), { color: 'gray' }), innerWidth), plainLine(`╰${'─'.repeat(panelWidth - 2)}╯`, { color: MODEL_PICKER_BORDER_COLOR }));
|
|
716
1000
|
return [...margin, ...body, ...margin];
|
|
717
1001
|
}
|
|
1002
|
+
const SHORTCUTS_PANEL_MAX_WIDTH = 96;
|
|
1003
|
+
const SHORTCUTS_KEY_COLUMN_MIN = 10;
|
|
1004
|
+
function shortcutsTopBorder(panelWidth) {
|
|
1005
|
+
const fullTitle = ' TheGitAI - Keyboard & mouse ';
|
|
1006
|
+
const compactTitle = ' Shortcuts ';
|
|
1007
|
+
const title = panelWidth >= fullTitle.length + 4 ? fullTitle : compactTitle;
|
|
1008
|
+
const available = Math.max(0, panelWidth - 2 - [...title].length);
|
|
1009
|
+
const left = Math.floor(available / 2);
|
|
1010
|
+
const right = available - left;
|
|
1011
|
+
return line(span(`╭${'─'.repeat(left)}`, { color: MODEL_PICKER_BORDER_COLOR }), span(title, { color: MODEL_PICKER_ACCENT_COLOR, bold: true }), span(`${'─'.repeat(right)}╮`, { color: MODEL_PICKER_BORDER_COLOR }));
|
|
1012
|
+
}
|
|
1013
|
+
export function buildShortcutsPanel(groups, width, availableHeight) {
|
|
1014
|
+
const panelWidth = Math.max(28, Math.min(width, SHORTCUTS_PANEL_MAX_WIDTH));
|
|
1015
|
+
const innerWidth = Math.max(1, panelWidth - 4);
|
|
1016
|
+
const keyWidth = Math.max(SHORTCUTS_KEY_COLUMN_MIN, ...groups.flatMap((group) => group.rows.map((row) => displayWidth(row.keys))));
|
|
1017
|
+
const side = (row) => overlayPanelLine(row, innerWidth, MODEL_PICKER_BORDER_COLOR);
|
|
1018
|
+
const groupLines = (group, spaced) => [
|
|
1019
|
+
...(spaced ? [side(plainLine(''))] : []),
|
|
1020
|
+
side(plainLine(fitLine(group.title, innerWidth), {
|
|
1021
|
+
color: MODEL_PICKER_ACCENT_COLOR,
|
|
1022
|
+
bold: true,
|
|
1023
|
+
})),
|
|
1024
|
+
...group.rows.map((row) => side(line(span(` ${row.keys}${' '.repeat(Math.max(0, keyWidth - displayWidth(row.keys)))} `, { bold: true }), span(fitLine(row.description, Math.max(1, innerWidth - keyWidth - 4)), { color: 'gray' })))),
|
|
1025
|
+
];
|
|
1026
|
+
const chromeRows = 4;
|
|
1027
|
+
const budget = Math.max(1, availableHeight - chromeRows);
|
|
1028
|
+
const spacedBody = groups.flatMap((group, index) => groupLines(group, index > 0));
|
|
1029
|
+
const plainBody = groups.flatMap((group) => groupLines(group, false));
|
|
1030
|
+
let body = spacedBody;
|
|
1031
|
+
let hidden = 0;
|
|
1032
|
+
if (spacedBody.length > budget) {
|
|
1033
|
+
body = plainBody;
|
|
1034
|
+
if (plainBody.length > budget) {
|
|
1035
|
+
body = [];
|
|
1036
|
+
hidden = groups.reduce((total, group) => total + group.rows.length, 0);
|
|
1037
|
+
for (const group of groups) {
|
|
1038
|
+
const whole = groupLines(group, false);
|
|
1039
|
+
if (body.length + whole.length <= budget) {
|
|
1040
|
+
body = [...body, ...whole];
|
|
1041
|
+
hidden -= group.rows.length;
|
|
1042
|
+
continue;
|
|
1043
|
+
}
|
|
1044
|
+
const room = budget - body.length - 1;
|
|
1045
|
+
if (room >= 1) {
|
|
1046
|
+
const kept = group.rows.slice(0, room);
|
|
1047
|
+
body = [...body, ...groupLines({ ...group, rows: kept }, false)];
|
|
1048
|
+
hidden -= kept.length;
|
|
1049
|
+
}
|
|
1050
|
+
break;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
const hint = hidden > 0 ? `esc close • ${hidden} more in /help` : 'esc close';
|
|
1055
|
+
return [
|
|
1056
|
+
shortcutsTopBorder(panelWidth),
|
|
1057
|
+
...body,
|
|
1058
|
+
plainLine(`├${'─'.repeat(panelWidth - 2)}┤`, {
|
|
1059
|
+
color: MODEL_PICKER_BORDER_COLOR,
|
|
1060
|
+
}),
|
|
1061
|
+
side(plainLine(fitLine(hint, innerWidth), { color: 'gray' })),
|
|
1062
|
+
plainLine(`╰${'─'.repeat(panelWidth - 2)}╯`, {
|
|
1063
|
+
color: MODEL_PICKER_BORDER_COLOR,
|
|
1064
|
+
}),
|
|
1065
|
+
];
|
|
1066
|
+
}
|
|
718
1067
|
function commandPaletteTopBorder(panelWidth) {
|
|
719
1068
|
const prefix = '╭─ Commands ';
|
|
720
1069
|
const suffix = '╮';
|
|
@@ -760,7 +1109,7 @@ function commandPaletteItemLines(option, selected, innerWidth) {
|
|
|
760
1109
|
modelPickerPanelSideLine(line(span(`${MODEL_PICKER_META_INDENT}${option.description}`, { color: 'gray' })), innerWidth),
|
|
761
1110
|
];
|
|
762
1111
|
}
|
|
763
|
-
function buildCommandPalettePanel(suggestions, selectedIndex, width) {
|
|
1112
|
+
function buildCommandPalettePanel(suggestions, selectedIndex, hiddenCount, width) {
|
|
764
1113
|
const panelWidth = Math.max(28, Math.min(width, MODEL_PICKER_PANEL_MAX_WIDTH));
|
|
765
1114
|
const innerWidth = Math.max(1, panelWidth - 4);
|
|
766
1115
|
const margin = Array.from({ length: MODEL_PICKER_PANEL_MARGIN_LINES }, () => plainLine(''));
|
|
@@ -779,13 +1128,117 @@ function buildCommandPalettePanel(suggestions, selectedIndex, width) {
|
|
|
779
1128
|
body.push(commandPaletteSeparatorLine(innerWidth));
|
|
780
1129
|
}
|
|
781
1130
|
});
|
|
1131
|
+
if (hiddenCount > 0) {
|
|
1132
|
+
body.push(commandPaletteSeparatorLine(innerWidth), modelPickerPanelSideLine(plainLine(` ${hiddenCount} more • keep typing to narrow`, {
|
|
1133
|
+
color: 'gray',
|
|
1134
|
+
dim: true,
|
|
1135
|
+
}), innerWidth));
|
|
1136
|
+
}
|
|
782
1137
|
body.push(modelPickerPanelSideLine(plainLine(''), innerWidth), modelPickerPanelSideLine(line(span('─'.repeat(innerWidth), { color: MODEL_PICKER_BORDER_COLOR })), innerWidth), modelPickerPanelSideLine(plainLine('↑/↓ choose • Tab or Enter accept • Esc cancel', { color: 'gray' }), innerWidth), plainLine(`╰${'─'.repeat(panelWidth - 2)}╯`, { color: MODEL_PICKER_BORDER_COLOR }));
|
|
783
1138
|
return [...margin, ...body, ...margin];
|
|
784
1139
|
}
|
|
1140
|
+
export function formatElapsedClock(elapsedSeconds) {
|
|
1141
|
+
if (elapsedSeconds < 60)
|
|
1142
|
+
return `${elapsedSeconds}s`;
|
|
1143
|
+
return `${Math.floor(elapsedSeconds / 60)}m ${String(elapsedSeconds % 60).padStart(2, '0')}s`;
|
|
1144
|
+
}
|
|
1145
|
+
export function buildWorkingClockLine(state, elapsedSeconds) {
|
|
1146
|
+
const elapsed = formatElapsedClock(elapsedSeconds);
|
|
1147
|
+
if (state.busyPausedAt != null) {
|
|
1148
|
+
return `${WORKING_CLOCK_ICON} Paused · ${elapsed} · waiting for your response`;
|
|
1149
|
+
}
|
|
1150
|
+
const label = state.generatingImage
|
|
1151
|
+
? 'Generating image'
|
|
1152
|
+
: state.analyzingImages > 0
|
|
1153
|
+
? state.analyzingImages > 1
|
|
1154
|
+
? 'Analyzing images'
|
|
1155
|
+
: 'Analyzing image'
|
|
1156
|
+
: 'Working';
|
|
1157
|
+
return `${WORKING_CLOCK_ICON} ${label} · ${elapsed}`;
|
|
1158
|
+
}
|
|
1159
|
+
export function approvalPanelInnerWidth(width) {
|
|
1160
|
+
return Math.max(1, Math.max(24, Math.min(width, OVERLAY_PANEL_MAX_WIDTH)) - 4);
|
|
1161
|
+
}
|
|
1162
|
+
export function userInputPanelInnerWidth(width) {
|
|
1163
|
+
return Math.max(1, Math.max(24, Math.min(width, USER_INPUT_PANEL_MAX_WIDTH)) - 4);
|
|
1164
|
+
}
|
|
1165
|
+
export function approvalPaddingEnabled(height) {
|
|
1166
|
+
return height >= APPROVAL_PADDING_MIN_ROWS;
|
|
1167
|
+
}
|
|
1168
|
+
export function approvalPreviewBudget(height) {
|
|
1169
|
+
const chrome = APPROVAL_OVERLAY_CHROME_ROWS +
|
|
1170
|
+
(approvalPaddingEnabled(height) ? APPROVAL_PADDING_CHROME_ROWS : 0);
|
|
1171
|
+
return Math.max(APPROVAL_PREVIEW_MIN_ROWS, Math.min(APPROVAL_PREVIEW_MAX_ROWS, Math.floor(height / 2) - chrome));
|
|
1172
|
+
}
|
|
1173
|
+
export function approvalPreviewRows(prompt, innerWidth) {
|
|
1174
|
+
const previewWidth = Math.max(8, innerWidth - APPROVAL_SCROLLBAR_COLUMNS);
|
|
1175
|
+
if (prompt.diffPreview) {
|
|
1176
|
+
return renderDiffPreviewLines(prompt.diffPreview, previewWidth, prompt.diffPreview.lines.length);
|
|
1177
|
+
}
|
|
1178
|
+
return wrapText(prompt.body, previewWidth).map((text) => plainLine(text, { color: OVERLAY_BORDER_COLOR }));
|
|
1179
|
+
}
|
|
1180
|
+
export function approvalScrollLimit(prompt, width, height) {
|
|
1181
|
+
if (!prompt)
|
|
1182
|
+
return 0;
|
|
1183
|
+
return Math.max(0, approvalPreviewRows(prompt, approvalPanelInnerWidth(width)).length -
|
|
1184
|
+
approvalPreviewBudget(height));
|
|
1185
|
+
}
|
|
1186
|
+
function approvalScrollbarGlyphs(totalRows, visibleRows, offset) {
|
|
1187
|
+
const thumbRows = Math.max(1, Math.min(visibleRows, Math.round((visibleRows * visibleRows) / totalRows)));
|
|
1188
|
+
const maxOffset = totalRows - visibleRows;
|
|
1189
|
+
const thumbTop = maxOffset <= 0
|
|
1190
|
+
? 0
|
|
1191
|
+
: Math.round((offset / maxOffset) * (visibleRows - thumbRows));
|
|
1192
|
+
return Array.from({ length: visibleRows }, (_, index) => index >= thumbTop && index < thumbTop + thumbRows
|
|
1193
|
+
? APPROVAL_SCROLLBAR_THUMB
|
|
1194
|
+
: APPROVAL_SCROLLBAR_TRACK);
|
|
1195
|
+
}
|
|
1196
|
+
function withScrollbarGlyph(target, glyph, column) {
|
|
1197
|
+
const padding = Math.max(1, column - lineCharCount(target));
|
|
1198
|
+
return {
|
|
1199
|
+
spans: [
|
|
1200
|
+
...target.spans,
|
|
1201
|
+
span(' '.repeat(padding)),
|
|
1202
|
+
span(glyph, {
|
|
1203
|
+
color: 'gray',
|
|
1204
|
+
dim: glyph === APPROVAL_SCROLLBAR_TRACK,
|
|
1205
|
+
}),
|
|
1206
|
+
],
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
|
+
export function buildApprovalPreviewWindow(prompt, innerWidth, height, requestedOffset) {
|
|
1210
|
+
const rows = approvalPreviewRows(prompt, innerWidth);
|
|
1211
|
+
const budget = approvalPreviewBudget(height);
|
|
1212
|
+
if (rows.length <= budget) {
|
|
1213
|
+
return {
|
|
1214
|
+
firstVisibleRow: rows.length === 0 ? 0 : 1,
|
|
1215
|
+
lastVisibleRow: rows.length,
|
|
1216
|
+
lines: rows,
|
|
1217
|
+
offset: 0,
|
|
1218
|
+
totalRows: rows.length,
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
const offset = Math.max(0, Math.min(requestedOffset, rows.length - budget));
|
|
1222
|
+
const visible = rows.slice(offset, offset + budget);
|
|
1223
|
+
const glyphs = approvalScrollbarGlyphs(rows.length, budget, offset);
|
|
1224
|
+
return {
|
|
1225
|
+
firstVisibleRow: offset + 1,
|
|
1226
|
+
lastVisibleRow: offset + visible.length,
|
|
1227
|
+
lines: visible.map((target, index) => withScrollbarGlyph(target, glyphs[index], innerWidth - 1)),
|
|
1228
|
+
offset,
|
|
1229
|
+
totalRows: rows.length,
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
export function approvalScrollStatusLine(window) {
|
|
1233
|
+
return `lines ${window.firstVisibleRow}–${window.lastVisibleRow} of ${window.totalRows} · PgUp/PgDn scrolls`;
|
|
1234
|
+
}
|
|
1235
|
+
export function rightAlignedLine(text, width, style = {}) {
|
|
1236
|
+
return plainLine(`${' '.repeat(Math.max(0, width - displayWidth(text)))}${text}`, style);
|
|
1237
|
+
}
|
|
785
1238
|
function buildOverlayLines(state, width, height, nowMs) {
|
|
786
1239
|
const lines = [];
|
|
787
1240
|
const panelWidth = Math.max(24, Math.min(width, OVERLAY_PANEL_MAX_WIDTH));
|
|
788
|
-
const innerWidth =
|
|
1241
|
+
const innerWidth = approvalPanelInnerWidth(width);
|
|
789
1242
|
if (state.sudoPrompt) {
|
|
790
1243
|
const prompt = state.sudoPrompt;
|
|
791
1244
|
const passwordWidth = Math.max(0, innerWidth - 11);
|
|
@@ -805,75 +1258,120 @@ function buildOverlayLines(state, width, height, nowMs) {
|
|
|
805
1258
|
: line(span(' '), span(text, { color: OVERLAY_BORDER_COLOR })));
|
|
806
1259
|
});
|
|
807
1260
|
lines.push(plainLine(''));
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
}
|
|
1261
|
+
lines.push(...wrapText(SUDO_PASSWORD_ASSURANCE, innerWidth).map((text) => plainLine(text, { color: SUDO_ASSURANCE_COLOR })));
|
|
1262
|
+
lines.push(plainLine(''));
|
|
811
1263
|
lines.push(line(span('Password: ', { color: 'cyan', bold: true }), span('•'.repeat(Math.min(prompt.passwordLength, passwordWidth)), {
|
|
812
1264
|
color: 'cyan',
|
|
813
1265
|
}), span(' ', { inverse: true })));
|
|
814
1266
|
lines.push(plainLine('Press Enter to submit, Escape to cancel', { color: 'gray' }));
|
|
815
|
-
return buildOverlayPanel(lines, width, OVERLAY_BORDER_COLOR);
|
|
1267
|
+
return buildOverlayPanel(lines, width, OVERLAY_BORDER_COLOR, height);
|
|
1268
|
+
}
|
|
1269
|
+
if (state.userInputPrompt) {
|
|
1270
|
+
if (height < 3) {
|
|
1271
|
+
return [];
|
|
1272
|
+
}
|
|
1273
|
+
return buildOverlayPanel(buildUserInputOverlayLines(state.userInputPrompt, userInputPanelInnerWidth(width), overlayPanelContentBudget(height)), width, USER_INPUT_BORDER_COLOR, height, USER_INPUT_PANEL_MAX_WIDTH);
|
|
816
1274
|
}
|
|
817
1275
|
if (state.approvalPrompt) {
|
|
818
1276
|
const prompt = state.approvalPrompt;
|
|
1277
|
+
const padded = approvalPaddingEnabled(height);
|
|
819
1278
|
lines.push(plainLine(prompt.title, {
|
|
820
|
-
color:
|
|
1279
|
+
color: APPROVAL_ACCENT_COLOR,
|
|
821
1280
|
bold: true,
|
|
822
1281
|
}));
|
|
1282
|
+
if (padded)
|
|
1283
|
+
lines.push(plainLine(''));
|
|
823
1284
|
if (prompt.diffPreview && prompt.filePath) {
|
|
824
1285
|
lines.push(line(span('● ', { color: 'green' }), span('Update(', { bold: true }), span(prompt.filePath, { color: 'cyan', bold: true }), span(')', { bold: true })));
|
|
825
|
-
lines.push(...renderTranscriptEntryLines({
|
|
826
|
-
body: '',
|
|
827
|
-
diffPreview: prompt.diffPreview,
|
|
828
|
-
kind: 'diff',
|
|
829
|
-
title: '',
|
|
830
|
-
}, innerWidth));
|
|
831
1286
|
}
|
|
832
|
-
|
|
833
|
-
|
|
1287
|
+
const previewWindow = buildApprovalPreviewWindow(prompt, innerWidth, height, state.approvalScrollOffset ?? 0);
|
|
1288
|
+
lines.push(...previewWindow.lines);
|
|
1289
|
+
if (padded)
|
|
1290
|
+
lines.push(plainLine(''));
|
|
1291
|
+
if (previewWindow.totalRows > previewWindow.lines.length) {
|
|
1292
|
+
lines.push(rightAlignedLine(approvalScrollStatusLine(previewWindow), innerWidth, {
|
|
1293
|
+
color: APPROVAL_SCROLL_STATUS_COLOR,
|
|
1294
|
+
}));
|
|
1295
|
+
if (padded)
|
|
1296
|
+
lines.push(plainLine(''));
|
|
834
1297
|
}
|
|
835
|
-
const options = [
|
|
836
|
-
|
|
837
|
-
{ value: 'a', label: 'Approve all remaining actions', color: 'cyan' },
|
|
838
|
-
{ value: 'n', label: 'Deny', color: 'red' },
|
|
839
|
-
];
|
|
840
|
-
options.forEach((option, index) => {
|
|
1298
|
+
const options = (prompt.options ?? []).map((option) => option.label);
|
|
1299
|
+
options.forEach((label, index) => {
|
|
841
1300
|
const selected = index === state.approvalCursor;
|
|
842
1301
|
lines.push(line(span(selected ? '› ' : ' ', {
|
|
843
|
-
color: selected ?
|
|
844
|
-
}), span(
|
|
845
|
-
color: selected ?
|
|
846
|
-
bold:
|
|
847
|
-
}), span(` ${option.label}`, {
|
|
848
|
-
color: selected ? OVERLAY_BORDER_COLOR : undefined,
|
|
1302
|
+
color: selected ? APPROVAL_ACCENT_COLOR : 'gray',
|
|
1303
|
+
}), span(label, {
|
|
1304
|
+
color: selected ? APPROVAL_ACCENT_COLOR : undefined,
|
|
1305
|
+
bold: selected,
|
|
849
1306
|
})));
|
|
850
1307
|
});
|
|
851
|
-
|
|
1308
|
+
if (padded)
|
|
1309
|
+
lines.push(plainLine(''));
|
|
1310
|
+
lines.push(plainLine('↑/↓ moves • Enter confirms • Esc denies', {
|
|
852
1311
|
color: 'gray',
|
|
853
1312
|
}));
|
|
854
|
-
return buildOverlayPanel(lines, width, OVERLAY_BORDER_COLOR);
|
|
1313
|
+
return buildOverlayPanel(lines, width, OVERLAY_BORDER_COLOR, height);
|
|
1314
|
+
}
|
|
1315
|
+
if (state.shortcutsOpen) {
|
|
1316
|
+
lines.push(...buildShortcutsPanel(buildShortcutGroups(), width, height));
|
|
855
1317
|
}
|
|
856
1318
|
if (state.modelPickerOpen) {
|
|
857
1319
|
const options = buildModelPickerOptions(state.currentModelId, state.serverModels);
|
|
858
|
-
lines.push(...buildModelPickerPanel(options, state.modelPickerIndex, width, height));
|
|
1320
|
+
lines.push(...buildModelPickerPanel(options, state.modelPickerIndex, width, height, state.modelPickerEfforts));
|
|
859
1321
|
}
|
|
860
1322
|
if (state.jobsPickerOpen) {
|
|
861
|
-
lines.push(...buildJobsPickerLines(state, width, nowMs));
|
|
1323
|
+
lines.push(...buildJobsPickerLines(state, width, height, nowMs));
|
|
862
1324
|
}
|
|
863
1325
|
if (state.resumePickerOpen) {
|
|
864
1326
|
const filtered = filterResumeSessions(state.resumePickerSessions, state.resumePickerFilter, state.serverModels);
|
|
1327
|
+
const pickerWidth = Math.max(20, width - 2);
|
|
1328
|
+
const divider = () => plainLine('─'.repeat(pickerWidth), { color: 'gray', dim: true });
|
|
865
1329
|
lines.push(plainLine('Resume a previous session', { color: 'cyan', bold: true }));
|
|
866
1330
|
lines.push(line(span('Search: ', { color: 'gray' }), span(state.resumePickerFilter, {}), span('█', { color: 'gray' })));
|
|
867
|
-
|
|
1331
|
+
lines.push(divider());
|
|
1332
|
+
const maxCards = Math.max(2, Math.min(filtered.length, Math.floor((height - 10) / 3)));
|
|
1333
|
+
let start = 0;
|
|
1334
|
+
if (filtered.length > maxCards) {
|
|
1335
|
+
start = Math.min(Math.max(0, state.resumePickerIndex - Math.floor(maxCards / 2)), filtered.length - maxCards);
|
|
1336
|
+
}
|
|
1337
|
+
const visible = filtered.slice(start, start + maxCards);
|
|
1338
|
+
if (start > 0) {
|
|
1339
|
+
lines.push(plainLine(` … ${start} newer`, { color: 'gray', dim: true }));
|
|
1340
|
+
}
|
|
1341
|
+
for (const [offset, session] of visible.entries()) {
|
|
1342
|
+
const index = start + offset;
|
|
868
1343
|
const selected = index === state.resumePickerIndex;
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
1344
|
+
const prompt = singleLinePreview(session.lastUserMessage, pickerWidth) ||
|
|
1345
|
+
session.name ||
|
|
1346
|
+
`Session ${session.id}`;
|
|
1347
|
+
lines.push(line(span(selected ? '› ' : ' ', { color: 'cyan' }), span(fitLine(prompt, Math.max(10, pickerWidth - 2)), selected
|
|
1348
|
+
? { color: 'cyan', bold: true }
|
|
1349
|
+
: session.lastUserMessage
|
|
1350
|
+
? {}
|
|
1351
|
+
: { color: 'gray', dim: true })));
|
|
1352
|
+
const meta = [
|
|
1353
|
+
formatRelativeTime(session.updatedAt),
|
|
1354
|
+
pickerModelLabel(session.modelId, state.serverModels),
|
|
1355
|
+
session.branch ?? null,
|
|
1356
|
+
]
|
|
1357
|
+
.filter(Boolean)
|
|
1358
|
+
.join(' · ');
|
|
1359
|
+
lines.push(line(span(' '), span(fitLine(meta, Math.max(10, pickerWidth - 4)), {
|
|
1360
|
+
color: selected ? 'cyan' : 'gray',
|
|
1361
|
+
dim: !selected,
|
|
1362
|
+
})));
|
|
1363
|
+
if (offset < visible.length - 1)
|
|
1364
|
+
lines.push(plainLine(''));
|
|
1365
|
+
}
|
|
1366
|
+
const remaining = filtered.length - (start + visible.length);
|
|
1367
|
+
if (remaining > 0) {
|
|
1368
|
+
lines.push(plainLine(` … ${remaining} older`, { color: 'gray', dim: true }));
|
|
872
1369
|
}
|
|
873
1370
|
if (filtered.length === 0) {
|
|
874
1371
|
lines.push(plainLine('No sessions match.', { color: 'gray' }));
|
|
875
1372
|
}
|
|
876
|
-
lines.push(
|
|
1373
|
+
lines.push(divider());
|
|
1374
|
+
lines.push(plainLine('↑/↓ move · enter resume · esc start new · ctrl+c quit', {
|
|
877
1375
|
color: 'gray',
|
|
878
1376
|
}));
|
|
879
1377
|
}
|
|
@@ -885,13 +1383,22 @@ function buildOverlayLines(state, width, height, nowMs) {
|
|
|
885
1383
|
state.input.trimStart().startsWith('/') &&
|
|
886
1384
|
!state.input.includes(' ') &&
|
|
887
1385
|
suggestions.length > 0) {
|
|
888
|
-
lines.push(...buildCommandPalettePanel(suggestions, state.commandCursor, width));
|
|
1386
|
+
lines.push(...buildCommandPalettePanel(suggestions, state.commandCursor, getHiddenSlashCommandCount(state.input), width));
|
|
889
1387
|
}
|
|
890
1388
|
return lines;
|
|
891
1389
|
}
|
|
892
1390
|
function countSectionLines(sections) {
|
|
893
1391
|
return sections.reduce((sum, section) => sum + section.lines.length, 0);
|
|
894
1392
|
}
|
|
1393
|
+
export function userInputViewportForFrame(state, cols, rows, spinnerFrame, elapsedSeconds, nowMs = 0) {
|
|
1394
|
+
const contentWidth = frameContentWidth(cols);
|
|
1395
|
+
const liveRows = buildLiveLines(state, contentWidth, spinnerFrame, elapsedSeconds, nowMs).length;
|
|
1396
|
+
const overlayHeight = Math.max(0, rows - liveRows - composerFooterLines(state, contentWidth).length);
|
|
1397
|
+
return {
|
|
1398
|
+
width: userInputPanelInnerWidth(contentWidth),
|
|
1399
|
+
maxRows: overlayPanelContentBudget(overlayHeight),
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
895
1402
|
function sliceTranscriptLines(lines, maxLines, scrollOffset) {
|
|
896
1403
|
if (maxLines <= 0 || lines.length <= maxLines) {
|
|
897
1404
|
return lines;
|
|
@@ -902,33 +1409,43 @@ function sliceTranscriptLines(lines, maxLines, scrollOffset) {
|
|
|
902
1409
|
return lines.slice(start, start + maxLines);
|
|
903
1410
|
}
|
|
904
1411
|
export function buildTuiFrame(state, cols, rows, spinnerFrame, elapsedSeconds, nowMs = 0) {
|
|
905
|
-
const contentWidth =
|
|
1412
|
+
const contentWidth = frameContentWidth(cols);
|
|
906
1413
|
const gutter = Math.max(Math.floor((cols - contentWidth) / 2), 0);
|
|
907
|
-
const
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
1414
|
+
const buildTranscriptLines = (wrapWidth) => {
|
|
1415
|
+
const blocks = state.transcript.map((entry) => cachedTranscriptEntryLines(entry, wrapWidth));
|
|
1416
|
+
const lines = [];
|
|
1417
|
+
blocks.forEach((block, index) => {
|
|
1418
|
+
if (index > 0) {
|
|
1419
|
+
lines.push(plainLine(''));
|
|
1420
|
+
}
|
|
1421
|
+
lines.push(...block);
|
|
1422
|
+
});
|
|
1423
|
+
return lines;
|
|
1424
|
+
};
|
|
1425
|
+
let transcriptLines = buildTranscriptLines(contentWidth);
|
|
915
1426
|
const sections = [];
|
|
916
|
-
const liveLines = buildLiveLines(state, contentWidth, spinnerFrame, elapsedSeconds);
|
|
1427
|
+
const liveLines = buildLiveLines(state, contentWidth, spinnerFrame, elapsedSeconds, nowMs);
|
|
917
1428
|
if (liveLines.length > 0) {
|
|
918
1429
|
sections.push({ kind: 'live', lines: liveLines });
|
|
919
1430
|
}
|
|
920
|
-
const overlayActive = Boolean(state.approvalPrompt || state.sudoPrompt);
|
|
921
|
-
if (!state.resumePickerOpen &&
|
|
1431
|
+
const overlayActive = Boolean(state.approvalPrompt || state.sudoPrompt || state.userInputPrompt);
|
|
1432
|
+
if (!state.resumePickerOpen &&
|
|
1433
|
+
!state.modelPickerOpen &&
|
|
1434
|
+
!state.jobsPickerOpen &&
|
|
1435
|
+
!state.shortcutsOpen &&
|
|
1436
|
+
!overlayActive) {
|
|
922
1437
|
const composerLines = [];
|
|
923
|
-
if (state.
|
|
924
|
-
|
|
1438
|
+
if (state.busy && state.status === 'Starting a new conversation...') {
|
|
1439
|
+
composerLines.push(line(span('Starting a new conversation…', { color: 'gray', dim: true })));
|
|
1440
|
+
}
|
|
1441
|
+
else if (state.queuedMessage) {
|
|
925
1442
|
const imageCount = state.queuedMessage.imageAttachments.length;
|
|
926
|
-
composerLines.push(line(span(
|
|
927
|
-
?
|
|
928
|
-
:
|
|
1443
|
+
composerLines.push(line(span('Queued', { color: 'cyan', bold: true }), span(' Enter', { color: 'cyan', bold: true }), span(imageCount > 0
|
|
1444
|
+
? ' sends it with the next prompt'
|
|
1445
|
+
: ' sends it to the agent now', { color: 'gray' }), span(' · ↑', { color: 'cyan', bold: true }), span(' edit', { color: 'gray' }), span(' · Esc', { color: 'cyan', bold: true }), span(' discard', { color: 'gray' })));
|
|
929
1446
|
}
|
|
930
1447
|
else {
|
|
931
|
-
const promptLabel = state
|
|
1448
|
+
const promptLabel = composerPromptLabel(state);
|
|
932
1449
|
const placeholder = state.busy
|
|
933
1450
|
? 'Type to queue the next message'
|
|
934
1451
|
: 'Type a request or /help';
|
|
@@ -936,17 +1453,37 @@ export function buildTuiFrame(state, cols, rows, spinnerFrame, elapsedSeconds, n
|
|
|
936
1453
|
}
|
|
937
1454
|
sections.push({
|
|
938
1455
|
kind: 'composer',
|
|
939
|
-
lines: [...composerLines, plainLine(''), ...composerFooterLines(state)],
|
|
1456
|
+
lines: [...composerLines, plainLine(''), ...composerFooterLines(state, contentWidth)],
|
|
940
1457
|
});
|
|
941
1458
|
}
|
|
942
|
-
|
|
1459
|
+
if (state.userInputPrompt) {
|
|
1460
|
+
sections.push({
|
|
1461
|
+
kind: 'busyFooter',
|
|
1462
|
+
lines: composerFooterLines(state, contentWidth),
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
const overlayHeight = state.userInputPrompt
|
|
1466
|
+
? Math.max(0, rows - countSectionLines(sections))
|
|
1467
|
+
: state.jobsPickerOpen || state.shortcutsOpen || state.modelPickerOpen
|
|
1468
|
+
? Math.max(Math.min(rows, JOBS_PICKER_MIN_ROWS), rows - countSectionLines(sections))
|
|
1469
|
+
: rows;
|
|
1470
|
+
const overlayLines = buildOverlayLines(state, contentWidth, overlayHeight, nowMs);
|
|
943
1471
|
if (overlayLines.length > 0) {
|
|
944
1472
|
sections.push({ kind: 'overlay', lines: overlayLines });
|
|
945
1473
|
}
|
|
946
1474
|
const reservedLines = countSectionLines(sections.filter((section) => section.kind !== 'transcript'));
|
|
947
|
-
const composerReserve = state.resumePickerOpen
|
|
1475
|
+
const composerReserve = state.resumePickerOpen ||
|
|
1476
|
+
state.approvalPrompt ||
|
|
1477
|
+
state.sudoPrompt ||
|
|
1478
|
+
state.userInputPrompt
|
|
1479
|
+
? 0
|
|
1480
|
+
: 4;
|
|
948
1481
|
const transcriptBudget = Math.max(1, rows - reservedLines - composerReserve - 1);
|
|
949
|
-
|
|
1482
|
+
let transcriptScrollLimit = Math.max(0, transcriptLines.length - transcriptBudget);
|
|
1483
|
+
if (transcriptScrollLimit > 0 && contentWidth > 2) {
|
|
1484
|
+
transcriptLines = buildTranscriptLines(contentWidth - 2);
|
|
1485
|
+
transcriptScrollLimit = Math.max(0, transcriptLines.length - transcriptBudget);
|
|
1486
|
+
}
|
|
950
1487
|
const transcriptScrollOffset = Math.min(Math.max(state.transcriptScrollOffset, 0), transcriptScrollLimit);
|
|
951
1488
|
sections.unshift({
|
|
952
1489
|
kind: 'transcript',
|