@thegitai/cli 1.0.0-preview.9 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +301 -15
  3. package/dist/bin/ai.js +139 -111
  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 +77 -34
  8. package/dist/src/api/chat.js +702 -173
  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 +75 -10
  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 +14 -4
  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 +271 -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/scratch-dir.js +6 -2
  46. package/dist/src/session-context.js +11 -0
  47. package/dist/src/session-safety.js +0 -12
  48. package/dist/src/session-store.js +76 -10
  49. package/dist/src/session.js +14 -4
  50. package/dist/src/signin.js +58 -0
  51. package/dist/src/skills/discovery.js +280 -0
  52. package/dist/src/skills/frontmatter.js +192 -0
  53. package/dist/src/skills/install.js +394 -0
  54. package/dist/src/skills/types.js +43 -0
  55. package/dist/src/skills-command.js +71 -0
  56. package/dist/src/todo-list.js +16 -9
  57. package/dist/src/tool-executor.js +42 -51
  58. package/dist/src/tools/browser.js +928 -0
  59. package/dist/src/tools/delete-file.js +21 -5
  60. package/dist/src/tools/index.js +34 -10
  61. package/dist/src/tools/patch-file.js +14 -29
  62. package/dist/src/tools/read-file.js +7 -1
  63. package/dist/src/tools/read-image-file.js +85 -0
  64. package/dist/src/tools/replace-document-text.js +28 -18
  65. package/dist/src/tools/restore-checkpoint.js +1 -2
  66. package/dist/src/tools/run-command.js +14 -71
  67. package/dist/src/tools/run-node-script.js +13 -82
  68. package/dist/src/tools/save-generated-image.js +120 -0
  69. package/dist/src/tools/shell-diagnostics.js +248 -72
  70. package/dist/src/tools/str-replace.js +14 -29
  71. package/dist/src/tools/undo-edit.js +2 -7
  72. package/dist/src/tools/use-skill.js +38 -0
  73. package/dist/src/tools/write-file.js +69 -14
  74. package/dist/src/ui/repl.js +1141 -299
  75. package/dist/src/ui/slash-commands.js +140 -0
  76. package/dist/src/ui/tui/attention.js +25 -0
  77. package/dist/src/ui/tui/bridge.js +38 -5
  78. package/dist/src/ui/tui/build-frame.js +858 -303
  79. package/dist/src/ui/tui/composer-layout.js +76 -0
  80. package/dist/src/ui/tui/desktop-notification.js +118 -0
  81. package/dist/src/ui/tui/markdown-render.js +21 -11
  82. package/dist/src/ui/tui/model-label.js +13 -0
  83. package/dist/src/ui/tui/shell-input.js +266 -61
  84. package/dist/src/ui/tui/shortcuts.js +61 -0
  85. package/dist/src/ui/tui/terminal-theme.js +28 -0
  86. package/dist/src/ui/tui/text.js +31 -6
  87. package/dist/src/ui/tui/user-input.js +593 -0
  88. package/dist/src/update-check.js +205 -0
  89. package/dist/src/usage-notice.js +52 -0
  90. package/dist/src/usage.js +25 -2
  91. package/dist/src/utils.js +4 -0
  92. package/dist/src/version.js +52 -2
  93. package/dist/vendor/mcp/LICENSES.txt +414 -0
  94. package/dist/vendor/mcp/client.cjs +82 -0
  95. package/package.json +22 -9
  96. package/dist/src/project-index.js +0 -233
  97. package/dist/src/tools/code-intel.js +0 -472
  98. package/dist/src/tools/find-symbol.js +0 -70
  99. package/dist/src/tools/hover-symbol.js +0 -95
  100. package/dist/src/tools/list-symbols.js +0 -55
  101. package/dist/src/tools/search-code.js +0 -37
  102. package/dist/src/tools/signature-help.js +0 -118
@@ -1,8 +1,17 @@
1
- import { agentModeLabel } from '../../agent-mode.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';
2
5
  import { singleLinePreview, truncate } from '../../utils.js';
3
- import { formatClientTokenUsage } from '../repl.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,58 +194,7 @@ 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
  }
@@ -238,26 +224,90 @@ function formatRelativeTime(isoDate) {
238
224
  return `${hours}h ago`;
239
225
  return `${Math.floor(hours / 24)}d ago`;
240
226
  }
241
- 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) {
242
248
  const text = fitLine(item.text, Math.max(8, width - 5));
243
249
  if (item.status === 'completed') {
244
- return line(span(' ✔ ', { color: 'green' }), span(text, { color: 'gray', dim: true }));
250
+ return line(span(' ✔ ', { color: 'green' }), span(text, mutedStyle()));
245
251
  }
246
252
  if (item.status === 'in_progress') {
247
- 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 }));
248
256
  }
249
- 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;
250
300
  }
251
301
  export function formatTodoProgress(items) {
252
302
  const done = items.filter((item) => item.status === 'completed').length;
253
303
  return `${done}/${items.length} done`;
254
304
  }
255
- export function renderTodoListLines(items, width, { header = false } = {}) {
305
+ export function renderTodoListLines(items, width, { header = false, progressTick = null } = {}) {
256
306
  if (items.length === 0)
257
307
  return [];
258
308
  const lines = [];
259
309
  if (header) {
260
- 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() })));
261
311
  }
262
312
  const itemRowBudget = TODO_PANEL_MAX_ROWS - (header ? 1 : 0);
263
313
  let collapsedDone = 0;
@@ -271,19 +321,16 @@ export function renderTodoListLines(items, width, { header = false } = {}) {
271
321
  collapsedDone = Math.min(over, leadingDone);
272
322
  }
273
323
  if (collapsedDone > 0) {
274
- lines.push(line(span(' ✔ ', { color: 'green' }), span(`${collapsedDone} completed`, { color: 'gray', dim: true })));
324
+ lines.push(line(span(' ✔ ', { color: 'green' }), span(`${collapsedDone} completed`, mutedStyle())));
275
325
  }
276
326
  const remaining = items.slice(collapsedDone);
277
327
  const budget = itemRowBudget - (collapsedDone > 0 ? 1 : 0);
278
328
  const visible = remaining.length > budget ? remaining.slice(0, budget - 1) : remaining;
279
329
  for (const item of visible) {
280
- lines.push(todoItemLine(item, width));
330
+ lines.push(todoItemLine(item, width, progressTick));
281
331
  }
282
332
  if (remaining.length > visible.length) {
283
- lines.push(plainLine(` … +${remaining.length - visible.length} more`, {
284
- color: 'gray',
285
- dim: true,
286
- }));
333
+ lines.push(plainLine(` … +${remaining.length - visible.length} more`, mutedStyle()));
287
334
  }
288
335
  return lines;
289
336
  }
@@ -296,20 +343,45 @@ export function renderTranscriptEntryLines(entry, width) {
296
343
  ? renderPreformattedBodyLines(entry.body, width, entry.kind)
297
344
  : renderFormattedBodyLines(entry.body, width, entry.kind)));
298
345
  if (entry.diffPreview) {
299
- 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' }));
300
- for (const diffLine of entry.diffPreview.lines.slice(0, TRANSCRIPT_DIFF_PREVIEW_LINES)) {
301
- lines.push(line(span(`${diffLinePrefix(diffLine.kind)} `, { color: diffLineColor(diffLine.kind) }), span(fitLine(diffLine.content || ' ', width - 4), {
302
- color: diffLineColor(diffLine.kind),
303
- })));
304
- }
346
+ lines.push(...renderDiffPreviewLines(entry.diffPreview, width));
305
347
  }
306
348
  if (entry.todoList && entry.todoList.length > 0) {
307
349
  lines.push(...renderTodoListLines(entry.todoList, width));
308
350
  }
309
351
  return lines;
310
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
+ }
311
383
  function tokenUsageLines(usage) {
312
- const match = usage.match(/^Session tokens • in ([^•]+) • out ([^•]+)(?: • think ([^•]+))? • cache ([^•]+)(?: • write ([^•]+))?(?: • index ([^•]+))?$/);
384
+ const match = usage.match(/^Session tokens • in ([^•]+) • out ([^•]+)(?: • think ([^•]+))? • cache ([^•]+)(?: • write ([^•]+))?$/);
313
385
  if (!match) {
314
386
  return [plainLine(usage, { color: 'cyan' })];
315
387
  }
@@ -327,15 +399,16 @@ function tokenUsageLines(usage) {
327
399
  if (match[5]) {
328
400
  spans.push(span(' Write ', { color: 'gray' }), span(match[5].trim(), { color: 'yellow' }));
329
401
  }
330
- if (match[6]) {
331
- spans.push(span(' Index ', { color: 'gray' }), span(match[6].trim(), { color: 'blue' }));
332
- }
333
402
  return [line(...spans)];
334
403
  }
404
+ export const AGENT_MODE_LOCKED_STATUS = 'Mode locked while the agent is working';
335
405
  function footerTransientStatus(status) {
336
406
  const text = String(status ?? '').trim();
337
407
  if (!text)
338
408
  return null;
409
+ if (text === AGENT_MODE_LOCKED_STATUS) {
410
+ return { color: 'yellow', text, icon: '!' };
411
+ }
339
412
  if (text === 'Copied selection' || text === 'Copied link') {
340
413
  return { color: 'green', text, icon: '✓' };
341
414
  }
@@ -352,10 +425,11 @@ function backgroundJobIndicatorSpans(state) {
352
425
  if (runningCount === 0)
353
426
  return [];
354
427
  const noun = runningCount === 1 ? 'shell' : 'shells';
428
+ const hint = state.busy ? ' · ctrl+b' : ' · /jobs';
355
429
  return [
356
430
  span(' ', { color: 'gray', dim: true }),
357
431
  span(`● ${runningCount} ${noun} running`, { color: 'green', bold: true }),
358
- span(' · /jobs', { color: 'gray', dim: true }),
432
+ span(hint, { color: 'gray', dim: true }),
359
433
  ];
360
434
  }
361
435
  function todoIndicatorSpans(state) {
@@ -375,11 +449,56 @@ function todoIndicatorSpans(state) {
375
449
  }),
376
450
  ];
377
451
  }
378
- 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) {
379
498
  const visibleSessionId = formatPromptSessionIdLabel(state.showSessionId, state.sessionId);
380
- const transientStatus = footerTransientStatus(state.status);
499
+ const transientStatus = footerTransientStatus(state.transientStatus ?? null);
381
500
  const lines = [
382
- 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
383
502
  ? [
384
503
  span(' ', { color: 'gray', dim: true }),
385
504
  span(transientStatus.text, {
@@ -395,11 +514,6 @@ function composerFooterLines(state) {
395
514
  ? [span(` ${visibleSessionId}`, { color: 'gray', dim: true })]
396
515
  : []), ...backgroundJobIndicatorSpans(state), ...todoIndicatorSpans(state)),
397
516
  plainLine(''),
398
- plainLine(formatModelLabel(state.currentModelId, state.serverModels), {
399
- color: 'cyan',
400
- dim: true,
401
- }),
402
- plainLine(''),
403
517
  ];
404
518
  if (state.exitConfirmUntil != null) {
405
519
  lines.push(plainLine(state.status || 'Press Ctrl+C again to quit.', {
@@ -408,31 +522,63 @@ function composerFooterLines(state) {
408
522
  }));
409
523
  return lines;
410
524
  }
411
- const busyHelperText = state.queuedMessage
412
- ? 'Enter re-queues • ↑ edit queued • Esc / Ctrl+C clear queued'
413
- : state.input
414
- ? 'Enter queues • Esc cancels turn • Ctrl+C clears draft'
415
- : 'Enter queues • Esc / Ctrl+C cancel turn';
416
- const helperText = state.busy
417
- ? busyHelperText
418
- : process.platform === 'win32'
419
- ? 'Enter sends • Shift+Tab mode • Alt+V image • Esc cancel turn • Ctrl+C clears / quits'
420
- : process.platform === 'darwin'
421
- ? 'Enter sends • Shift+Tab mode • Ctrl+V image • Esc cancel turn • Ctrl+C clears / quits'
422
- : 'Enter sends • Shift+Tab mode • Ctrl+V image • Esc cancel turn • Ctrl+C clears / quits';
423
- const agentLabel = agentModeLabel(state.agentMode).padEnd(AGENT_MODE_LABEL_WIDTH);
424
525
  const tokenUsageText = state.tokenUsage || formatClientTokenUsage(null);
425
- const footerSpans = [
426
- span(helperText, { color: 'gray', dim: true }),
427
- span(' '.repeat(Math.max(1, 8)), { color: 'gray', dim: true }),
428
- span(agentLabel, {
429
- color: state.agentMode === 'plan' ? 'yellow' : 'cyan',
430
- }),
431
- span(tokenUsageText, { color: 'cyan' }),
432
- ];
433
- 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
+ : []));
434
534
  return lines;
435
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 = ' ';
436
582
  export function formatJobElapsed(elapsedMs) {
437
583
  const totalSeconds = Math.max(0, Math.floor(elapsedMs / 1000));
438
584
  if (totalSeconds < 60)
@@ -474,15 +620,29 @@ function jobStatusDescriptor(job, nowMs) {
474
620
  ? { glyph: '✓', color: 'green', text: `exited (0) · ran ${ran}` }
475
621
  : { glyph: '✖', color: 'red', text: `exited (${job.exitCode ?? 1}) · ran ${ran}` };
476
622
  }
477
- 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) {
478
626
  const jobs = state.backgroundJobs ?? [];
627
+ const bodyBudget = Math.max(1, height - JOBS_PICKER_CHROME_ROWS);
479
628
  const lines = [
480
629
  plainLine('Background jobs', { color: 'cyan', bold: true }),
481
630
  ];
482
631
  if (jobs.length === 0) {
483
632
  lines.push(plainLine('No background jobs in this session.', { color: 'gray' }));
484
633
  }
485
- 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;
486
646
  const selected = index === state.jobsPickerIndex;
487
647
  const expanded = state.jobsPickerExpandedId === job.id;
488
648
  const { glyph, color, text } = jobStatusDescriptor(job, nowMs);
@@ -491,10 +651,11 @@ function buildJobsPickerLines(state, width, nowMs) {
491
651
  bold: selected,
492
652
  }), span(` ${text}`, { color: 'gray' })));
493
653
  if (expanded) {
494
- const detailLines = (job.detailLines ?? []).length
654
+ const allDetail = (job.detailLines ?? []).length
495
655
  ? job.detailLines ?? []
496
656
  : backgroundJobPreviewLines(job, 3);
497
- if (detailLines.length === 0) {
657
+ const detailLines = allDetail.slice(-detailBudget);
658
+ if (detailBudget > 0 && detailLines.length === 0) {
498
659
  lines.push(plainLine(' (no output captured)', { color: 'gray' }));
499
660
  }
500
661
  else {
@@ -507,22 +668,71 @@ function buildJobsPickerLines(state, width, nowMs) {
507
668
  }
508
669
  }
509
670
  }
671
+ const remaining = jobs.length - (start + visible.length);
672
+ if (remaining > 0) {
673
+ lines.push(plainLine(` … ${remaining} older`, { color: 'gray', dim: true }));
674
+ }
510
675
  lines.push(plainLine('↑/↓ move enter expand/collapse k kill esc close', {
511
676
  color: 'gray',
512
677
  }));
513
678
  return lines;
514
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
+ }
515
710
  function thinkingHeaderLine(spinnerFrame, title, width) {
516
711
  const spinner = `${BRAILLE_SPINNER_FRAMES[spinnerFrame % BRAILLE_SPINNER_FRAMES.length]} `;
517
- const fittedTitle = title
518
- ? 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))
519
715
  : '';
520
716
  return line(span(spinner, { color: 'green' }), span('Thinking', { color: 'green', bold: true }), ...(fittedTitle ? [span(` · ${fittedTitle}`, { color: 'ansi256(248)' })] : []));
521
717
  }
522
718
  function thinkingNoteLine(note, width) {
523
719
  return line(span('│ ', { color: 'green' }), span(fitLine(note, Math.max(8, width - 3)), { color: 'ansi256(248)' }));
524
720
  }
525
- 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) {
526
736
  if (!state.busy)
527
737
  return [];
528
738
  const lines = [plainLine('')];
@@ -552,16 +762,26 @@ function buildLiveLines(state, width, spinnerFrame, elapsedSeconds) {
552
762
  }
553
763
  lines.push(plainLine(''));
554
764
  }
555
- const busyLabel = state.analyzingImages > 0
556
- ? state.analyzingImages > 1
557
- ? 'Analyzing images'
558
- : 'Analyzing image'
559
- : 'Working';
560
- lines.push(plainLine(`${WORKING_CLOCK_ICON} ${busyLabel} · ${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
+ }
561
778
  const todos = state.todos ?? [];
562
779
  if (todos.length > 0) {
563
780
  lines.push(plainLine(''));
564
- lines.push(...renderTodoListLines(todos, width, { header: true }));
781
+ lines.push(...renderTodoListLines(todos, width, {
782
+ header: true,
783
+ progressTick: todoProgressTick(nowMs),
784
+ }));
565
785
  }
566
786
  const visibleTitle = state.thinkingTitle.trim();
567
787
  const visibleNotes = state.thinkingNotes.filter(Boolean);
@@ -571,11 +791,12 @@ function buildLiveLines(state, width, spinnerFrame, elapsedSeconds) {
571
791
  const minimalText = visibleTitle && visibleTitle !== 'Thinking'
572
792
  ? visibleTitle
573
793
  : (visibleNotes[visibleNotes.length - 1] ?? '');
574
- lines.push(thinkingHeaderLine(spinnerFrame, minimalText, width));
794
+ lines.push(thinkingHeaderLine(spinnerFrame, minimalText || THINKING_FALLBACK_PHRASES[0], width));
575
795
  }
576
796
  else {
577
- lines.push(thinkingHeaderLine(spinnerFrame, visibleTitle, width));
578
- 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)) {
579
800
  lines.push(thinkingNoteLine(note, width));
580
801
  }
581
802
  }
@@ -590,10 +811,24 @@ function overlayPanelLine(row, width, color) {
590
811
  const padding = Math.max(0, width - lineCharCount(row));
591
812
  return line(span('│ ', { color }), ...row.spans, span(' '.repeat(padding)), span(' │', { color }));
592
813
  }
593
- function buildOverlayPanel(rows, width, color) {
594
- 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));
595
828
  const innerWidth = Math.max(1, panelWidth - 4);
596
- const margin = Array.from({ length: OVERLAY_PANEL_MARGIN_LINES }, () => plainLine(''));
829
+ const margin = Array.from({
830
+ length: overlayPanelMarginLineCount(height),
831
+ }, () => plainLine(''));
597
832
  return [
598
833
  ...margin,
599
834
  plainLine(`╭${'─'.repeat(panelWidth - 2)}╮`, { color }),
@@ -602,24 +837,25 @@ function buildOverlayPanel(rows, width, color) {
602
837
  ...margin,
603
838
  ];
604
839
  }
605
- function padSpansToInnerWidth(spans, innerWidth, fill) {
606
- 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);
607
842
  const pad = Math.max(0, innerWidth - used);
608
843
  if (pad === 0)
609
844
  return spans;
610
- return [...spans, span(' '.repeat(pad), fill)];
845
+ return [...spans, span(' '.repeat(pad))];
611
846
  }
612
847
  function modelPickerPanelSideLine(content, innerWidth) {
613
848
  return overlayPanelLine(content, innerWidth, MODEL_PICKER_BORDER_COLOR);
614
849
  }
615
850
  const MODEL_PICKER_COST_WIDTH = 6;
616
- const MODEL_PICKER_MODEL_WIDTH = 42;
617
- const MODEL_PICKER_NUMBER_WIDTH = 4;
618
- 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 = ' ';
619
854
  const MODEL_PICKER_WIDE_MIN_WIDTH = 78;
620
855
  function modelPickerTopBorder(panelWidth) {
621
- const fullTitle = ' TheGitAI - Model Selection ';
622
- const compactTitle = ' Model Selection ';
856
+ return pickerTopBorder(panelWidth, ' TheGitAI - Model Selection ', ' Model Selection ');
857
+ }
858
+ function pickerTopBorder(panelWidth, fullTitle, compactTitle) {
623
859
  const title = panelWidth >= fullTitle.length + 4 ? fullTitle : compactTitle;
624
860
  const available = Math.max(0, panelWidth - 2 - [...title].length);
625
861
  const left = Math.floor(available / 2);
@@ -639,93 +875,263 @@ function modelPickerCostText(rating) {
639
875
  const steps = Math.max(1, Math.min(3, Math.round(rating)));
640
876
  return '$'.repeat(steps);
641
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
+ }
642
881
  function modelPickerNotesWidth(innerWidth) {
643
882
  return Math.max(18, innerWidth -
644
- MODEL_PICKER_NUMBER_WIDTH -
645
- MODEL_PICKER_MODEL_WIDTH -
883
+ modelPickerModelWidth(innerWidth) -
646
884
  MODEL_PICKER_COST_WIDTH -
647
- MODEL_PICKER_SEPARATOR.length * 2);
885
+ MODEL_PICKER_COLUMN_GAP.length * 2);
648
886
  }
649
- function modelPickerModelSpans(option, selected, width, showCurrentTag, labelStyle, selectedStyle) {
887
+ function modelPickerModelSpans(option, selected, effort, width, showCurrentTag, labelStyle) {
650
888
  const tag = option.current && showCurrentTag ? ' (current)' : '';
651
- const labelWidth = Math.max(1, width - [...tag].length);
652
- const label = fitLine(`${selected ? '▶ ' : ' '}${option.label}`, labelWidth);
653
- 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;
654
896
  return [
655
- span(label, { ...labelStyle, ...selectedStyle }),
656
- span(tag, { color: 'gray', ...selectedStyle }),
657
- 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))),
658
901
  ];
659
902
  }
660
- function modelPickerItemLines(option, selected, innerWidth) {
661
- const selectedStyle = selected ? { bgColor: MODEL_PICKER_HIGHLIGHT_BG } : {};
662
- const labelStyle = option.disabled
663
- ? { color: 'gray' }
664
- : selected
665
- ? { color: 'cyan', bold: true }
666
- : {};
667
- 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 } : {});
668
906
  const cost = modelPickerCostText(option.costRating);
669
907
  if (innerWidth < MODEL_PICKER_WIDE_MIN_WIDTH) {
670
- 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);
671
910
  const row = [
672
- numberCell,
673
- ...modelPickerModelSpans(option, selected, modelWidth, false, labelStyle, selectedStyle),
674
- span(' ', selectedStyle),
675
- modelPickerCell(cost, MODEL_PICKER_COST_WIDTH, selectedStyle),
911
+ ...modelPickerModelSpans(option, selected, effort, modelWidth, false, labelStyle),
912
+ span(' '),
913
+ modelPickerCell(cost, costWidth, lockedStyle),
676
914
  ];
677
915
  return [
678
- modelPickerPanelSideLine(line(...padSpansToInnerWidth(row, innerWidth, selectedStyle)), innerWidth),
916
+ modelPickerPanelSideLine(line(...padSpansToInnerWidth(row, innerWidth)), innerWidth),
679
917
  ];
680
918
  }
681
919
  const row = [
682
- numberCell,
683
- ...modelPickerModelSpans(option, selected, MODEL_PICKER_MODEL_WIDTH, true, labelStyle, selectedStyle),
684
- span(MODEL_PICKER_SEPARATOR, { color: 'gray', ...selectedStyle }),
685
- modelPickerCell(cost, MODEL_PICKER_COST_WIDTH, selectedStyle),
686
- span(MODEL_PICKER_SEPARATOR, { color: 'gray', ...selectedStyle }),
687
- modelPickerCell(option.note, modelPickerNotesWidth(innerWidth), {
688
- color: 'gray',
689
- ...selectedStyle,
690
- }),
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' }),
691
925
  ];
692
926
  return [
693
- modelPickerPanelSideLine(line(...padSpansToInnerWidth(row, innerWidth, selectedStyle)), innerWidth),
927
+ modelPickerPanelSideLine(line(...padSpansToInnerWidth(row, innerWidth)), innerWidth),
694
928
  ];
695
929
  }
696
- function modelPickerHeaderLine(innerWidth) {
930
+ function modelPickerHeadingLine(title, innerWidth, withColumns) {
697
931
  const heading = { color: MODEL_PICKER_ACCENT_COLOR, bold: true };
698
- if (innerWidth < MODEL_PICKER_WIDE_MIN_WIDTH) {
699
- 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));
934
+ }
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));
937
+ }
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
+ }
700
955
  }
701
- 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));
956
+ return rows;
702
957
  }
703
- function buildModelPickerPanel(options, selectedIndex, width, availableHeight) {
958
+ function buildModelPickerPanel(options, selectedIndex, width, availableHeight, efforts = {}, pausedCount = 0) {
704
959
  const panelWidth = Math.max(28, Math.min(width, MODEL_PICKER_PANEL_MAX_WIDTH));
705
960
  const innerWidth = Math.max(1, panelWidth - 4);
706
- const compactBodyLineCount = options.length + 6;
707
- const spacerLineCount = Math.max(0, options.length - 1);
708
- const useRowSpacing = compactBodyLineCount + spacerLineCount <= availableHeight;
709
- 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;
710
969
  const marginLineCount = Math.max(0, Math.min(MODEL_PICKER_PANEL_MARGIN_LINES, Math.floor((availableHeight - bodyLineCount) / 2)));
711
970
  const margin = Array.from({ length: marginLineCount }, () => plainLine(''));
712
- const body = [
713
- modelPickerTopBorder(panelWidth),
714
- modelPickerPanelSideLine(modelPickerHeaderLine(innerWidth), innerWidth),
715
- modelPickerDivider(panelWidth),
716
- ];
717
- options.forEach((option, index) => {
718
- body.push(...modelPickerItemLines(option, index === selectedIndex, innerWidth));
719
- 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') {
720
977
  body.push(modelPickerPanelSideLine(plainLine(''), innerWidth));
721
978
  }
722
- });
723
- const fullHint = '↑/↓ navigate • Enter select • Esc cancel';
724
- 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';
725
1006
  const hint = [...fullHint].length <= innerWidth ? fullHint : compactHint;
726
- 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 }));
727
1016
  return [...margin, ...body, ...margin];
728
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(''));
1074
+ return [...margin, ...body, ...margin];
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
+ }
729
1135
  function commandPaletteTopBorder(panelWidth) {
730
1136
  const prefix = '╭─ Commands ';
731
1137
  const suffix = '╮';
@@ -736,31 +1142,26 @@ function commandPaletteSeparatorLine(innerWidth) {
736
1142
  return modelPickerPanelSideLine(line(span('┈'.repeat(Math.max(1, innerWidth)), { color: 'gray', dim: true })), innerWidth);
737
1143
  }
738
1144
  function commandPaletteItemLines(option, selected, innerWidth) {
739
- const highlight = { bgColor: MODEL_PICKER_HIGHLIGHT_BG };
740
1145
  if (selected) {
741
1146
  const titleSpans = padSpansToInnerWidth([
742
1147
  span('▌', {
743
1148
  color: MODEL_PICKER_ACCENT_COLOR,
744
1149
  bold: true,
745
- ...highlight,
746
1150
  }),
747
1151
  span('▶ ', {
748
1152
  color: MODEL_PICKER_ACCENT_COLOR,
749
1153
  bold: true,
750
- ...highlight,
751
1154
  }),
752
1155
  span(option.command, {
753
1156
  color: MODEL_PICKER_ACCENT_COLOR,
754
1157
  bold: true,
755
- ...highlight,
756
1158
  }),
757
- ], innerWidth, highlight);
1159
+ ], innerWidth);
758
1160
  const metaSpans = padSpansToInnerWidth([
759
- span(`${MODEL_PICKER_META_INDENT}${option.description}`, {
1161
+ span(fitLine(`${MODEL_PICKER_META_INDENT}${option.description}`, innerWidth), {
760
1162
  color: 'gray',
761
- ...highlight,
762
1163
  }),
763
- ], innerWidth, highlight);
1164
+ ], innerWidth);
764
1165
  return [
765
1166
  modelPickerPanelSideLine(line(...titleSpans), innerWidth),
766
1167
  modelPickerPanelSideLine(line(...metaSpans), innerWidth),
@@ -768,10 +1169,10 @@ function commandPaletteItemLines(option, selected, innerWidth) {
768
1169
  }
769
1170
  return [
770
1171
  modelPickerPanelSideLine(line(span(' ', { color: 'gray' }), span(option.command, { color: MODEL_PICKER_ACCENT_COLOR })), innerWidth),
771
- 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),
772
1173
  ];
773
1174
  }
774
- function buildCommandPalettePanel(suggestions, selectedIndex, width) {
1175
+ function buildCommandPalettePanel(suggestions, selectedIndex, hiddenCount, width) {
775
1176
  const panelWidth = Math.max(28, Math.min(width, MODEL_PICKER_PANEL_MAX_WIDTH));
776
1177
  const innerWidth = Math.max(1, panelWidth - 4);
777
1178
  const margin = Array.from({ length: MODEL_PICKER_PANEL_MARGIN_LINES }, () => plainLine(''));
@@ -790,13 +1191,117 @@ function buildCommandPalettePanel(suggestions, selectedIndex, width) {
790
1191
  body.push(commandPaletteSeparatorLine(innerWidth));
791
1192
  }
792
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
+ }
793
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 }));
794
1201
  return [...margin, ...body, ...margin];
795
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
+ }
796
1301
  function buildOverlayLines(state, width, height, nowMs) {
797
1302
  const lines = [];
798
1303
  const panelWidth = Math.max(24, Math.min(width, OVERLAY_PANEL_MAX_WIDTH));
799
- const innerWidth = Math.max(1, panelWidth - 4);
1304
+ const innerWidth = approvalPanelInnerWidth(width);
800
1305
  if (state.sudoPrompt) {
801
1306
  const prompt = state.sudoPrompt;
802
1307
  const passwordWidth = Math.max(0, innerWidth - 11);
@@ -816,60 +1321,72 @@ function buildOverlayLines(state, width, height, nowMs) {
816
1321
  : line(span(' '), span(text, { color: OVERLAY_BORDER_COLOR })));
817
1322
  });
818
1323
  lines.push(plainLine(''));
819
- if (prompt.prompt.trim()) {
820
- lines.push(plainLine(prompt.prompt.trim(), { color: 'gray' }));
821
- }
1324
+ lines.push(...wrapText(SUDO_PASSWORD_ASSURANCE, innerWidth).map((text) => plainLine(text, { color: SUDO_ASSURANCE_COLOR })));
1325
+ lines.push(plainLine(''));
822
1326
  lines.push(line(span('Password: ', { color: 'cyan', bold: true }), span('•'.repeat(Math.min(prompt.passwordLength, passwordWidth)), {
823
1327
  color: 'cyan',
824
1328
  }), span(' ', { inverse: true })));
825
1329
  lines.push(plainLine('Press Enter to submit, Escape to cancel', { color: 'gray' }));
826
- 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);
827
1337
  }
828
1338
  if (state.approvalPrompt) {
829
1339
  const prompt = state.approvalPrompt;
1340
+ const padded = approvalPaddingEnabled(height);
830
1341
  lines.push(plainLine(prompt.title, {
831
- color: OVERLAY_BORDER_COLOR,
1342
+ color: APPROVAL_ACCENT_COLOR,
832
1343
  bold: true,
833
1344
  }));
1345
+ if (padded)
1346
+ lines.push(plainLine(''));
834
1347
  if (prompt.diffPreview && prompt.filePath) {
835
1348
  lines.push(line(span('● ', { color: 'green' }), span('Update(', { bold: true }), span(prompt.filePath, { color: 'cyan', bold: true }), span(')', { bold: true })));
836
- lines.push(...renderTranscriptEntryLines({
837
- body: '',
838
- diffPreview: prompt.diffPreview,
839
- kind: 'diff',
840
- title: '',
841
- }, innerWidth));
842
1349
  }
843
- else {
844
- 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(''));
845
1360
  }
846
- const options = [
847
- { value: 'y', label: 'Approve once', color: 'green' },
848
- { value: 'a', label: 'Approve all remaining actions', color: 'cyan' },
849
- { value: 'n', label: 'Deny', color: 'red' },
850
- ];
851
- options.forEach((option, index) => {
1361
+ const options = (prompt.options ?? []).map((option) => option.label);
1362
+ options.forEach((label, index) => {
852
1363
  const selected = index === state.approvalCursor;
853
1364
  lines.push(line(span(selected ? '› ' : ' ', {
854
- color: selected ? OVERLAY_BORDER_COLOR : 'gray',
855
- }), span(option.value, {
856
- color: selected ? OVERLAY_BORDER_COLOR : option.color,
857
- bold: true,
858
- }), span(` ${option.label}`, {
859
- 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,
860
1369
  })));
861
1370
  });
862
- 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', {
863
1374
  color: 'gray',
864
1375
  }));
865
- 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));
866
1383
  }
867
1384
  if (state.modelPickerOpen) {
868
1385
  const options = buildModelPickerOptions(state.currentModelId, state.serverModels);
869
- lines.push(...buildModelPickerPanel(options, state.modelPickerIndex, width, height));
1386
+ lines.push(...buildModelPickerPanel(options, state.modelPickerIndex, width, height, state.modelPickerEfforts, pausedModelCount(state.serverModels)));
870
1387
  }
871
1388
  if (state.jobsPickerOpen) {
872
- lines.push(...buildJobsPickerLines(state, width, nowMs));
1389
+ lines.push(...buildJobsPickerLines(state, width, height, nowMs));
873
1390
  }
874
1391
  if (state.resumePickerOpen) {
875
1392
  const filtered = filterResumeSessions(state.resumePickerSessions, state.resumePickerFilter, state.serverModels);
@@ -928,17 +1445,27 @@ function buildOverlayLines(state, width, height, nowMs) {
928
1445
  if (!state.busy &&
929
1446
  !state.exiting &&
930
1447
  !state.modelPickerOpen &&
1448
+ !state.skillsPickerOpen &&
931
1449
  !state.resumePickerOpen &&
932
1450
  state.input.trimStart().startsWith('/') &&
933
1451
  !state.input.includes(' ') &&
934
1452
  suggestions.length > 0) {
935
- lines.push(...buildCommandPalettePanel(suggestions, state.commandCursor, width));
1453
+ lines.push(...buildCommandPalettePanel(suggestions, state.commandCursor, getHiddenSlashCommandCount(state.input), width));
936
1454
  }
937
1455
  return lines;
938
1456
  }
939
1457
  function countSectionLines(sections) {
940
1458
  return sections.reduce((sum, section) => sum + section.lines.length, 0);
941
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
+ }
942
1469
  function sliceTranscriptLines(lines, maxLines, scrollOffset) {
943
1470
  if (maxLines <= 0 || lines.length <= maxLines) {
944
1471
  return lines;
@@ -949,36 +1476,44 @@ function sliceTranscriptLines(lines, maxLines, scrollOffset) {
949
1476
  return lines.slice(start, start + maxLines);
950
1477
  }
951
1478
  export function buildTuiFrame(state, cols, rows, spinnerFrame, elapsedSeconds, nowMs = 0) {
952
- const contentWidth = Math.max(20, Math.floor(cols * 0.95) - 2);
1479
+ const contentWidth = frameContentWidth(cols);
953
1480
  const gutter = Math.max(Math.floor((cols - contentWidth) / 2), 0);
954
- const transcriptBlocks = state.transcript.map((entry) => renderTranscriptEntryLines(entry, contentWidth));
955
- const transcriptLines = [];
956
- transcriptBlocks.forEach((block, index) => {
957
- if (index > 0) {
958
- transcriptLines.push(plainLine(''));
959
- }
960
- transcriptLines.push(...block);
961
- });
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);
962
1493
  const sections = [];
963
- const liveLines = buildLiveLines(state, contentWidth, spinnerFrame, elapsedSeconds);
1494
+ const liveLines = buildLiveLines(state, contentWidth, spinnerFrame, elapsedSeconds, nowMs);
964
1495
  if (liveLines.length > 0) {
965
1496
  sections.push({ kind: 'live', lines: liveLines });
966
1497
  }
967
- const overlayActive = Boolean(state.approvalPrompt || state.sudoPrompt);
968
- 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) {
969
1505
  const composerLines = [];
970
1506
  if (state.busy && state.status === 'Starting a new conversation...') {
971
1507
  composerLines.push(line(span('Starting a new conversation…', { color: 'gray', dim: true })));
972
1508
  }
973
1509
  else if (state.queuedMessage) {
974
- const preview = truncate(state.queuedMessage.body.trim().replace(/\s+/g, ' '), 60);
975
1510
  const imageCount = state.queuedMessage.imageAttachments.length;
976
- composerLines.push(line(span(`↳ Queued · "${preview}"`, { color: 'gray', dim: true }), ...(imageCount > 0
977
- ? [span(` +${imageCount} img`, { color: 'gray', dim: true })]
978
- : []), 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' })));
979
1514
  }
980
1515
  else {
981
- const promptLabel = state.busy ? 'queue> ' : '❯ ';
1516
+ const promptLabel = composerPromptLabel(state);
982
1517
  const placeholder = state.busy
983
1518
  ? 'Type to queue the next message'
984
1519
  : 'Type a request or /help';
@@ -986,17 +1521,37 @@ export function buildTuiFrame(state, cols, rows, spinnerFrame, elapsedSeconds, n
986
1521
  }
987
1522
  sections.push({
988
1523
  kind: 'composer',
989
- 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),
990
1531
  });
991
1532
  }
992
- 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);
993
1539
  if (overlayLines.length > 0) {
994
1540
  sections.push({ kind: 'overlay', lines: overlayLines });
995
1541
  }
996
1542
  const reservedLines = countSectionLines(sections.filter((section) => section.kind !== 'transcript'));
997
- const composerReserve = state.resumePickerOpen ? 0 : 4;
1543
+ const composerReserve = state.resumePickerOpen ||
1544
+ state.approvalPrompt ||
1545
+ state.sudoPrompt ||
1546
+ state.userInputPrompt
1547
+ ? 0
1548
+ : 4;
998
1549
  const transcriptBudget = Math.max(1, rows - reservedLines - composerReserve - 1);
999
- 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
+ }
1000
1555
  const transcriptScrollOffset = Math.min(Math.max(state.transcriptScrollOffset, 0), transcriptScrollLimit);
1001
1556
  sections.unshift({
1002
1557
  kind: 'transcript',