@thegitai/cli 1.0.0-preview.8 → 1.0.0

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