@thegitai/cli 1.0.0-preview.10 → 1.0.0-preview.12

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.
@@ -1,6 +1,6 @@
1
1
  import { drainBackgroundJobNotifications } from '../background-jobs.js';
2
2
  import { createPromptCheckpoint, sanitizeSessionSafetyForServer, } from '../session-safety.js';
3
- import { applySessionSnapshot, snapshotFromSession, } from '../session-store.js';
3
+ import { applySessionSnapshot, saveSessionState, snapshotFromSession, } from '../session-store.js';
4
4
  import { executeLocalToolCall } from '../tool-executor.js';
5
5
  import { createTraceContext, normalizeServerUrl, readErrorResponse, } from './http.js';
6
6
  import { collectClientEnvironment } from '../client-environment.js';
@@ -18,11 +18,13 @@ export class ChatTurnFailedError extends Error {
18
18
  category;
19
19
  retryable;
20
20
  traceId;
21
- constructor(message, category = 'unknown_error', retryable = false, traceId = '') {
21
+ partialSnapshot;
22
+ constructor(message, category = 'unknown_error', retryable = false, traceId = '', partialSnapshot) {
22
23
  super(traceId ? `${message}\nTrace ID: ${traceId}` : message);
23
24
  this.category = category;
24
25
  this.retryable = retryable;
25
26
  this.traceId = traceId;
27
+ this.partialSnapshot = partialSnapshot;
26
28
  }
27
29
  }
28
30
  export function isTurnCancelledError(error) {
@@ -102,6 +104,12 @@ export function preserveCancelledTurnInput(session, input) {
102
104
  userInput: text,
103
105
  });
104
106
  }
107
+ function appendTurnFailureMarker(session, category) {
108
+ session.history.push({
109
+ role: 'model',
110
+ parts: [{ text: formatTurnFailureMarker(category) }],
111
+ });
112
+ }
105
113
  function preserveFailedTurnInput(session, input, category) {
106
114
  const text = input.trim();
107
115
  if (!text)
@@ -112,10 +120,7 @@ function preserveFailedTurnInput(session, input, category) {
112
120
  kind: 'turnStart',
113
121
  userInput: text,
114
122
  });
115
- session.history.push({
116
- role: 'model',
117
- parts: [{ text: formatTurnFailureMarker(category) }],
118
- });
123
+ appendTurnFailureMarker(session, category);
119
124
  }
120
125
  function historyHasToolCall(session, callId) {
121
126
  return session.history.some((entry) => (entry.parts ?? []).some((part) => String(part?.functionCall?.id ?? '') === callId));
@@ -155,7 +160,7 @@ function publicStatusMessage(data) {
155
160
  ? event.toolName
156
161
  : 'tool';
157
162
  if (event.phase === 'thinking')
158
- return 'Thinking...';
163
+ return 'Exploring options...';
159
164
  if (event.phase === 'analyzing_image') {
160
165
  return (event.imageCount ?? 1) > 1 ? 'Analyzing images...' : 'Analyzing image...';
161
166
  }
@@ -377,7 +382,7 @@ async function consumeTurnStream({ response, config, projectIndex, session, inpu
377
382
  if (event.event === 'cancelled') {
378
383
  throw new TurnCancelledError(message);
379
384
  }
380
- throw new ChatTurnFailedError(message, typeof event.data?.category === 'string' ? event.data.category : 'unknown_error', Boolean(event.data?.retryable), typeof event.data?.traceId === 'string' ? event.data.traceId : traceId);
385
+ throw new ChatTurnFailedError(message, typeof event.data?.category === 'string' ? event.data.category : 'unknown_error', Boolean(event.data?.retryable), typeof event.data?.traceId === 'string' ? event.data.traceId : traceId, event.data?.snapshot);
381
386
  }
382
387
  }
383
388
  try {
@@ -494,8 +499,19 @@ export async function sendServerUserMessage({ config, projectIndex, session, inp
494
499
  ? error
495
500
  : new TurnCancelledError();
496
501
  }
497
- session.history.length = preTurnHistoryLength;
498
- preserveFailedTurnInput(session, requestInputBase, error instanceof ChatTurnFailedError ? error.category : 'unknown_error');
502
+ const category = error instanceof ChatTurnFailedError ? error.category : 'unknown_error';
503
+ const partial = error instanceof ChatTurnFailedError ? error.partialSnapshot : undefined;
504
+ if (partial) {
505
+ applySessionSnapshot(session, partial, { preserveAgentMode: true });
506
+ }
507
+ else {
508
+ session.history.length = preTurnHistoryLength;
509
+ preserveFailedTurnInput(session, requestInputBase, category);
510
+ }
511
+ try {
512
+ saveSessionState(session, session.env);
513
+ }
514
+ catch { }
499
515
  throw error;
500
516
  }
501
517
  finally {
@@ -1,5 +1,5 @@
1
1
  import { createRatatuiBridge } from './tui/bridge.js';
2
- import { buildTuiFrame, formatJobElapsed, formatTodoProgress, renderTranscriptEntryLines, } from './tui/build-frame.js';
2
+ import { buildTuiFrame, formatJobElapsed, formatTodoProgress, pickThinkingFallbackPhrase, renderTranscriptEntryLines, THINKING_FALLBACK_PHRASES, } from './tui/build-frame.js';
3
3
  import { createTerminalTitleController } from './tui/terminal-title.js';
4
4
  import { captureTerminalWrites, releaseTerminalWrites, } from './tui/terminal-writes.js';
5
5
  export { getSlashCommandSuggestions } from './tui/build-frame.js';
@@ -1073,6 +1073,24 @@ function splitThinkingLines(text) {
1073
1073
  .map((part) => part.trim())
1074
1074
  .filter(Boolean));
1075
1075
  }
1076
+ const LIVE_STATUS_PANEL_MAX_CHARS = 72;
1077
+ const TOOL_PROGRESS_STATUS_PATTERN = /^(?:Tool:\s|Running\s\S+(?:\slocally)?\.\.\.$)/i;
1078
+ export function isToolProgressStatus(status) {
1079
+ return TOOL_PROGRESS_STATUS_PATTERN.test(String(status ?? '').trim());
1080
+ }
1081
+ function holdOrPickFallback(currentTitle) {
1082
+ return THINKING_FALLBACK_PHRASES.includes(currentTitle.trim())
1083
+ ? currentTitle
1084
+ : pickThinkingFallbackPhrase();
1085
+ }
1086
+ function liveStatusPanelTitle(status) {
1087
+ const text = String(status ?? '').trim();
1088
+ if (!text || text.includes('\n'))
1089
+ return '';
1090
+ if (isToolProgressStatus(text))
1091
+ return '';
1092
+ return text.length <= LIVE_STATUS_PANEL_MAX_CHARS ? text : '';
1093
+ }
1076
1094
  function thinkingPanelFromStatus(status) {
1077
1095
  const rawText = thinkingNoteFromStatus(status);
1078
1096
  if (!rawText)
@@ -1096,7 +1114,7 @@ function thinkingPanelFromStatus(status) {
1096
1114
  const bodyLines = rawLines.length > 1 && rawLines[0].length <= 72 ? rawLines.slice(1) : rawLines;
1097
1115
  return {
1098
1116
  title,
1099
- notes: splitThinkingLines(bodyLines.join('\n')).slice(-3),
1117
+ notes: splitThinkingLines(bodyLines.join('\n')).slice(0, 3),
1100
1118
  };
1101
1119
  }
1102
1120
  export const EXIT_CTRL_C_CONFIRM_MESSAGE = 'Press Ctrl+C again to quit.';
@@ -1332,6 +1350,36 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
1332
1350
  let exitCtrlCArmed = false;
1333
1351
  let exitCtrlCTimer = null;
1334
1352
  let transientStatusTimer = null;
1353
+ const THINKING_MIN_DWELL_MS = 3_000;
1354
+ let thinkingAppliedAt = 0;
1355
+ let pendingThinking = null;
1356
+ const applyThinking = (next) => {
1357
+ thinkingAppliedAt = Date.now();
1358
+ pendingThinking = null;
1359
+ store.update((current) => ({
1360
+ ...current,
1361
+ thinkingTitle: next.title || holdOrPickFallback(current.thinkingTitle),
1362
+ thinkingNotes: next.notes,
1363
+ }));
1364
+ };
1365
+ const queueThinkingUpdate = (next) => {
1366
+ if (Date.now() - thinkingAppliedAt >= THINKING_MIN_DWELL_MS) {
1367
+ applyThinking(next);
1368
+ return;
1369
+ }
1370
+ pendingThinking = next;
1371
+ };
1372
+ const flushPendingThinking = () => {
1373
+ if (!pendingThinking)
1374
+ return;
1375
+ if (Date.now() - thinkingAppliedAt < THINKING_MIN_DWELL_MS)
1376
+ return;
1377
+ applyThinking(pendingThinking);
1378
+ };
1379
+ const resetThinkingPacer = () => {
1380
+ thinkingAppliedAt = 0;
1381
+ pendingThinking = null;
1382
+ };
1335
1383
  const done = new Promise((resolve) => {
1336
1384
  resolveDone = resolve;
1337
1385
  });
@@ -1531,6 +1579,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
1531
1579
  dismissPendingApproval();
1532
1580
  dismissPendingSudoPassword();
1533
1581
  activeTurnGeneration += 1;
1582
+ resetThinkingPacer();
1534
1583
  activeTurnAbort?.abort();
1535
1584
  activeTurnAbort = null;
1536
1585
  cancelActiveCommand();
@@ -2328,6 +2377,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
2328
2377
  };
2329
2378
  pendingTurnEntries = [];
2330
2379
  queueTurnEntry(userEntry);
2380
+ resetThinkingPacer();
2331
2381
  store.update((current) => ({
2332
2382
  ...current,
2333
2383
  activeTurnInput: input,
@@ -2467,10 +2517,12 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
2467
2517
  store.update((current) => ({
2468
2518
  ...current,
2469
2519
  status: message,
2470
- thinkingTitle: panel?.title ?? current.thinkingTitle,
2471
- thinkingNotes: panel?.notes ?? current.thinkingNotes,
2472
2520
  tokenUsage: formatClientTokenUsage(current.busySince == null ? null : Date.now() - current.busySince, latestUsageSummary),
2473
2521
  }));
2522
+ queueThinkingUpdate({
2523
+ title: panel ? panel.title : liveStatusPanelTitle(message),
2524
+ notes: panel ? panel.notes : [],
2525
+ });
2474
2526
  };
2475
2527
  session.onContextLog = (message) => {
2476
2528
  store.update((current) => ({
@@ -2612,6 +2664,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
2612
2664
  const spinnerTimer = setInterval(() => {
2613
2665
  spinnerFrame = (spinnerFrame + 1) % 6;
2614
2666
  if (store.getState().busy) {
2667
+ flushPendingThinking();
2615
2668
  renderCurrentFrame();
2616
2669
  }
2617
2670
  }, 120);
@@ -238,13 +238,35 @@ function formatRelativeTime(isoDate) {
238
238
  return `${hours}h ago`;
239
239
  return `${Math.floor(hours / 24)}d ago`;
240
240
  }
241
- function todoItemLine(item, width) {
241
+ const TODO_IN_PROGRESS_FRAMES = [
242
+ '\u25CB',
243
+ '\u25D4',
244
+ '\u25D1',
245
+ '\u25D5',
246
+ '\u25CF',
247
+ ];
248
+ const TODO_IN_PROGRESS_STATIC_GLYPH = '\u25D1';
249
+ export const TODO_IN_PROGRESS_STEP_MS = 1_500;
250
+ export function todoProgressTick(nowMs) {
251
+ return Math.floor(nowMs / TODO_IN_PROGRESS_STEP_MS);
252
+ }
253
+ function todoInProgressGlyph(progressTick) {
254
+ if (progressTick === null)
255
+ return TODO_IN_PROGRESS_STATIC_GLYPH;
256
+ const index = ((progressTick % TODO_IN_PROGRESS_FRAMES.length) +
257
+ TODO_IN_PROGRESS_FRAMES.length) %
258
+ TODO_IN_PROGRESS_FRAMES.length;
259
+ return TODO_IN_PROGRESS_FRAMES[index];
260
+ }
261
+ function todoItemLine(item, width, progressTick = null) {
242
262
  const text = fitLine(item.text, Math.max(8, width - 5));
243
263
  if (item.status === 'completed') {
244
264
  return line(span(' ✔ ', { color: 'green' }), span(text, { color: 'gray', dim: true }));
245
265
  }
246
266
  if (item.status === 'in_progress') {
247
- return line(span(' ◐ ', { color: TODO_IN_PROGRESS_COLOR }), span(text, { color: TODO_IN_PROGRESS_COLOR, bold: true }));
267
+ return line(span(` ${todoInProgressGlyph(progressTick)} `, {
268
+ color: TODO_IN_PROGRESS_COLOR,
269
+ }), span(text, { color: TODO_IN_PROGRESS_COLOR, bold: true }));
248
270
  }
249
271
  return line(span(' ○ ', { color: 'gray' }), span(text));
250
272
  }
@@ -252,7 +274,7 @@ export function formatTodoProgress(items) {
252
274
  const done = items.filter((item) => item.status === 'completed').length;
253
275
  return `${done}/${items.length} done`;
254
276
  }
255
- export function renderTodoListLines(items, width, { header = false } = {}) {
277
+ export function renderTodoListLines(items, width, { header = false, progressTick = null } = {}) {
256
278
  if (items.length === 0)
257
279
  return [];
258
280
  const lines = [];
@@ -277,7 +299,7 @@ export function renderTodoListLines(items, width, { header = false } = {}) {
277
299
  const budget = itemRowBudget - (collapsedDone > 0 ? 1 : 0);
278
300
  const visible = remaining.length > budget ? remaining.slice(0, budget - 1) : remaining;
279
301
  for (const item of visible) {
280
- lines.push(todoItemLine(item, width));
302
+ lines.push(todoItemLine(item, width, progressTick));
281
303
  }
282
304
  if (remaining.length > visible.length) {
283
305
  lines.push(plainLine(` … +${remaining.length - visible.length} more`, {
@@ -512,17 +534,48 @@ function buildJobsPickerLines(state, width, nowMs) {
512
534
  }));
513
535
  return lines;
514
536
  }
537
+ export const THINKING_FALLBACK_PHRASES = [
538
+ 'Working out where to start...',
539
+ 'Deciding what comes first...',
540
+ 'Lining up the pieces...',
541
+ 'Untangling the details...',
542
+ 'Deciding what not to touch...',
543
+ 'Checking what this would break...',
544
+ 'Choosing the smaller change...',
545
+ 'Picking the least clever option...',
546
+ 'Resisting the obvious answer...',
547
+ 'Trying the boring explanation first...',
548
+ 'Checking whether the assumption holds...',
549
+ 'Asking what would have to be true...',
550
+ 'Reading it the way the machine would...',
551
+ 'Testing the story against the code...',
552
+ 'Working out what actually changed...',
553
+ 'Finding the smallest thing that explains it...',
554
+ 'Looking for the part that is not settled yet...',
555
+ 'Making sure this is the simple version...',
556
+ ];
557
+ export function pickThinkingFallbackPhrase() {
558
+ const index = Math.floor(Math.random() * THINKING_FALLBACK_PHRASES.length);
559
+ return THINKING_FALLBACK_PHRASES[index];
560
+ }
561
+ function withProgressEllipsis(title) {
562
+ const text = title.trim();
563
+ if (!text)
564
+ return text;
565
+ return /(?:\.\.\.|…)$/.test(text) ? text : `${text}...`;
566
+ }
515
567
  function thinkingHeaderLine(spinnerFrame, title, width) {
516
568
  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))
569
+ const decorated = withProgressEllipsis(title);
570
+ const fittedTitle = decorated
571
+ ? fitLine(decorated, Math.max(8, width - spinner.length - 'Thinking'.length - 3))
519
572
  : '';
520
573
  return line(span(spinner, { color: 'green' }), span('Thinking', { color: 'green', bold: true }), ...(fittedTitle ? [span(` · ${fittedTitle}`, { color: 'ansi256(248)' })] : []));
521
574
  }
522
575
  function thinkingNoteLine(note, width) {
523
576
  return line(span('│ ', { color: 'green' }), span(fitLine(note, Math.max(8, width - 3)), { color: 'ansi256(248)' }));
524
577
  }
525
- function buildLiveLines(state, width, spinnerFrame, elapsedSeconds) {
578
+ function buildLiveLines(state, width, spinnerFrame, elapsedSeconds, nowMs) {
526
579
  if (!state.busy)
527
580
  return [];
528
581
  const lines = [plainLine('')];
@@ -561,7 +614,10 @@ function buildLiveLines(state, width, spinnerFrame, elapsedSeconds) {
561
614
  const todos = state.todos ?? [];
562
615
  if (todos.length > 0) {
563
616
  lines.push(plainLine(''));
564
- lines.push(...renderTodoListLines(todos, width, { header: true }));
617
+ lines.push(...renderTodoListLines(todos, width, {
618
+ header: true,
619
+ progressTick: todoProgressTick(nowMs),
620
+ }));
565
621
  }
566
622
  const visibleTitle = state.thinkingTitle.trim();
567
623
  const visibleNotes = state.thinkingNotes.filter(Boolean);
@@ -571,11 +627,12 @@ function buildLiveLines(state, width, spinnerFrame, elapsedSeconds) {
571
627
  const minimalText = visibleTitle && visibleTitle !== 'Thinking'
572
628
  ? visibleTitle
573
629
  : (visibleNotes[visibleNotes.length - 1] ?? '');
574
- lines.push(thinkingHeaderLine(spinnerFrame, minimalText, width));
630
+ lines.push(thinkingHeaderLine(spinnerFrame, minimalText || THINKING_FALLBACK_PHRASES[0], width));
575
631
  }
576
632
  else {
577
- lines.push(thinkingHeaderLine(spinnerFrame, visibleTitle, width));
578
- for (const note of visibleNotes.slice(-THINKING_NOTE_PREVIEW_ROWS)) {
633
+ const headerTitle = visibleTitle && visibleTitle !== 'Thinking' ? visibleTitle : '';
634
+ lines.push(thinkingHeaderLine(spinnerFrame, headerTitle || THINKING_FALLBACK_PHRASES[0], width));
635
+ for (const note of visibleNotes.slice(0, THINKING_NOTE_PREVIEW_ROWS)) {
579
636
  lines.push(thinkingNoteLine(note, width));
580
637
  }
581
638
  }
@@ -960,7 +1017,7 @@ export function buildTuiFrame(state, cols, rows, spinnerFrame, elapsedSeconds, n
960
1017
  transcriptLines.push(...block);
961
1018
  });
962
1019
  const sections = [];
963
- const liveLines = buildLiveLines(state, contentWidth, spinnerFrame, elapsedSeconds);
1020
+ const liveLines = buildLiveLines(state, contentWidth, spinnerFrame, elapsedSeconds, nowMs);
964
1021
  if (liveLines.length > 0) {
965
1022
  sections.push({ kind: 'live', lines: liveLines });
966
1023
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thegitai/cli",
3
- "version": "1.0.0-preview.10",
3
+ "version": "1.0.0-preview.12",
4
4
  "description": "TheGitAI is an AI coding agent for your terminal. It indexes your repository, writes and edits files, runs commands, and builds features with you.",
5
5
  "keywords": [
6
6
  "ai",
@@ -37,10 +37,10 @@
37
37
  "@lydell/node-pty-linux-x64": "1.1.0",
38
38
  "@lydell/node-pty-win32-arm64": "1.1.0",
39
39
  "@lydell/node-pty-win32-x64": "1.1.0",
40
- "@thegitai/tui-darwin-arm64": "1.0.0-preview.10",
41
- "@thegitai/tui-darwin-x64": "1.0.0-preview.10",
42
- "@thegitai/tui-linux-x64": "1.0.0-preview.10",
43
- "@thegitai/tui-win32-x64": "1.0.0-preview.10",
40
+ "@thegitai/tui-darwin-arm64": "1.0.0-preview.12",
41
+ "@thegitai/tui-darwin-x64": "1.0.0-preview.12",
42
+ "@thegitai/tui-linux-x64": "1.0.0-preview.12",
43
+ "@thegitai/tui-win32-x64": "1.0.0-preview.12",
44
44
  "@vscode/ripgrep": "1.18.0"
45
45
  },
46
46
  "publishConfig": {