gaunt-sloth 2.0.0-beta.9 → 2.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 (118) hide show
  1. package/.gsloth.review-discovery.md +19 -0
  2. package/cli.js +49 -0
  3. package/dist/cli.js +42 -7
  4. package/dist/cli.js.map +1 -1
  5. package/dist/commands/adkEvalRunner.d.ts +7 -6
  6. package/dist/commands/adkEvalRunner.js +3 -3
  7. package/dist/commands/adkEvalRunner.js.map +1 -1
  8. package/dist/commands/agUiEvalRunner.d.ts +4 -4
  9. package/dist/commands/agUiEvalRunner.js +8 -7
  10. package/dist/commands/agUiEvalRunner.js.map +1 -1
  11. package/dist/commands/askCommand.d.ts +15 -2
  12. package/dist/commands/askCommand.js +75 -32
  13. package/dist/commands/askCommand.js.map +1 -1
  14. package/dist/commands/batchCommand.d.ts +6 -2
  15. package/dist/commands/batchCommand.js +13 -7
  16. package/dist/commands/batchCommand.js.map +1 -1
  17. package/dist/commands/chatCommand.js.map +1 -1
  18. package/dist/commands/codeCommand.js.map +1 -1
  19. package/dist/commands/commandIntrospection.d.ts +1 -1
  20. package/dist/commands/commandIntrospection.js +6 -3
  21. package/dist/commands/commandIntrospection.js.map +1 -1
  22. package/dist/commands/configCommand.d.ts +1 -1
  23. package/dist/commands/configCommand.js +1 -1
  24. package/dist/commands/configSetup.d.ts +1 -1
  25. package/dist/commands/discoveryConfigSchemaAgreement.d.ts +45 -0
  26. package/dist/commands/discoveryConfigSchemaAgreement.js +2 -0
  27. package/dist/commands/discoveryConfigSchemaAgreement.js.map +1 -0
  28. package/dist/commands/evalCommand.d.ts +27 -1
  29. package/dist/commands/evalCommand.js +156 -13
  30. package/dist/commands/evalCommand.js.map +1 -1
  31. package/dist/commands/execCommand.d.ts +15 -3
  32. package/dist/commands/execCommand.js +123 -51
  33. package/dist/commands/execCommand.js.map +1 -1
  34. package/dist/commands/firstRunDialog.d.ts +3 -3
  35. package/dist/commands/firstRunDialog.js +2 -2
  36. package/dist/commands/getCommand.js +10 -1
  37. package/dist/commands/getCommand.js.map +1 -1
  38. package/dist/commands/historyCommand.d.ts +16 -8
  39. package/dist/commands/historyCommand.js +190 -72
  40. package/dist/commands/historyCommand.js.map +1 -1
  41. package/dist/commands/insightsCommand.d.ts +4 -2
  42. package/dist/commands/insightsCommand.js +10 -7
  43. package/dist/commands/insightsCommand.js.map +1 -1
  44. package/dist/commands/prCommand.js +45 -16
  45. package/dist/commands/prCommand.js.map +1 -1
  46. package/dist/commands/prDiscovery.d.ts +24 -25
  47. package/dist/commands/prDiscovery.js +55 -132
  48. package/dist/commands/prDiscovery.js.map +1 -1
  49. package/dist/commands/requirementsDiscovery.d.ts +82 -0
  50. package/dist/commands/requirementsDiscovery.js +127 -0
  51. package/dist/commands/requirementsDiscovery.js.map +1 -0
  52. package/dist/commands/resumeOption.d.ts +19 -9
  53. package/dist/commands/resumeOption.js +29 -17
  54. package/dist/commands/resumeOption.js.map +1 -1
  55. package/dist/commands/reviewCommand.js +75 -8
  56. package/dist/commands/reviewCommand.js.map +1 -1
  57. package/dist/commands/reviewDiscovery.d.ts +96 -0
  58. package/dist/commands/reviewDiscovery.js +180 -0
  59. package/dist/commands/reviewDiscovery.js.map +1 -0
  60. package/dist/commands/singleShotResume.d.ts +19 -0
  61. package/dist/commands/singleShotResume.js +37 -0
  62. package/dist/commands/singleShotResume.js.map +1 -0
  63. package/dist/tui/approvalBridges.d.ts +86 -0
  64. package/dist/tui/approvalBridges.js +147 -0
  65. package/dist/tui/approvalBridges.js.map +1 -0
  66. package/dist/tui/components/App.js +278 -29
  67. package/dist/tui/components/App.js.map +1 -1
  68. package/dist/tui/components/DebugPanel.d.ts +6 -3
  69. package/dist/tui/components/DebugPanel.js +32 -10
  70. package/dist/tui/components/DebugPanel.js.map +1 -1
  71. package/dist/tui/components/FetchProgress.d.ts +1 -1
  72. package/dist/tui/components/LaunchBanner.d.ts +4 -3
  73. package/dist/tui/components/LaunchBanner.js +8 -6
  74. package/dist/tui/components/LaunchBanner.js.map +1 -1
  75. package/dist/tui/components/LiveTurn.d.ts +15 -9
  76. package/dist/tui/components/LiveTurn.js +15 -14
  77. package/dist/tui/components/LiveTurn.js.map +1 -1
  78. package/dist/tui/components/PromptInput.d.ts +2 -2
  79. package/dist/tui/components/PromptInput.js +11 -6
  80. package/dist/tui/components/PromptInput.js.map +1 -1
  81. package/dist/tui/components/ResumePicker.d.ts +69 -0
  82. package/dist/tui/components/ResumePicker.js +93 -0
  83. package/dist/tui/components/ResumePicker.js.map +1 -0
  84. package/dist/tui/components/SelectList.d.ts +1 -1
  85. package/dist/tui/components/SelectList.js +1 -1
  86. package/dist/tui/components/SlashCommandMenu.d.ts +1 -1
  87. package/dist/tui/components/SlashCommandMenu.js +1 -1
  88. package/dist/tui/components/StatusBar.d.ts +27 -1
  89. package/dist/tui/components/StatusBar.js +13 -2
  90. package/dist/tui/components/StatusBar.js.map +1 -1
  91. package/dist/tui/debugRender.d.ts +26 -3
  92. package/dist/tui/debugRender.js +233 -2
  93. package/dist/tui/debugRender.js.map +1 -1
  94. package/dist/tui/fixtureAgent.d.ts +2 -2
  95. package/dist/tui/fixtureAgent.js +2 -2
  96. package/dist/tui/keyBindings.js +7 -1
  97. package/dist/tui/keyBindings.js.map +1 -1
  98. package/dist/tui/keyGuards.d.ts +1 -1
  99. package/dist/tui/keyGuards.js +1 -1
  100. package/dist/tui/ruleWidth.d.ts +1 -1
  101. package/dist/tui/ruleWidth.js +1 -1
  102. package/dist/tui/selectCancelled.d.ts +1 -1
  103. package/dist/tui/selectCancelled.js +1 -1
  104. package/dist/tui/transcriptWindow.js +7 -1
  105. package/dist/tui/transcriptWindow.js.map +1 -1
  106. package/dist/tui/tuiSessionModule.js +91 -192
  107. package/dist/tui/tuiSessionModule.js.map +1 -1
  108. package/dist/tui/types.d.ts +79 -19
  109. package/dist/tui/useMouse.d.ts +1 -1
  110. package/dist/tui/useMouse.js +1 -1
  111. package/dist/tui/useSlothAnimation.d.ts +1 -1
  112. package/dist/tui/viewModel.d.ts +64 -12
  113. package/dist/tui/viewModel.js +38 -11
  114. package/dist/tui/viewModel.js.map +1 -1
  115. package/dist/utils/configErrorGuard.d.ts +11 -3
  116. package/dist/utils/configErrorGuard.js +11 -3
  117. package/dist/utils/configErrorGuard.js.map +1 -1
  118. package/package.json +19 -19
@@ -5,6 +5,9 @@ import { foldEvents, foldSubagentEvents, initialSubagentTree, initialTurnViewMod
5
5
  import { buildRejectionMessage } from '@gaunt-sloth/core/core/shell/rejection.js';
6
6
  import { ApprovalStopError } from '@gaunt-sloth/core/core/shell/approvalStop.js';
7
7
  import { shouldAnnounceTermination } from '@gaunt-sloth/core/core/terminationNotice.js';
8
+ import { runEndReport } from '@gaunt-sloth/core/core/runRecap.js';
9
+ import { providerErrorNotice } from '@gaunt-sloth/core/core/providerErrorNotice.js';
10
+ import { readWaitNarration } from '@gaunt-sloth/core/core/waitNarration.js';
8
11
  import { attackBannerCopy, grantsRunAnyway, } from '@gaunt-sloth/core/core/shell/escalationSeverity.js';
9
12
  import { TranscriptViewport } from '#src/tui/components/TranscriptViewport.js';
10
13
  import { ApprovalPrompt } from '#src/tui/components/ApprovalPrompt.js';
@@ -22,15 +25,24 @@ import { ClearBanner } from '#src/tui/components/ClearBanner.js';
22
25
  import { LaunchBanner } from '#src/tui/components/LaunchBanner.js';
23
26
  import { MouseProvider } from '#src/tui/useMouse.js';
24
27
  import { DebugPanel, debugPanelLines, debugPanelRows, DEBUG_TABS, } from '#src/tui/components/DebugPanel.js';
28
+ import { renderApprovalDetails } from '#src/tui/debugRender.js';
25
29
  import { approvalPostureChoices, approvalsRungNotice, approvalsRefusalsNotice, approvalsStatusNotice, approvalsTrustNotice, approvalsUndenyNotice, COMPACTING_LINE, compactionFailedNotice, autocompactNotice, autocompactUnavailableNotice, compactionNotice, compactionUnavailableNotice, createCommandRegistry, dispatchSlashCommand, parseSlashCommand, toolsToggleNotice, } from '@gaunt-sloth/agent/modules/slashCommands.js';
26
- import { resumedConversationNotice, resumeFailedNotice, resumePickerNotice, resumeRefusalNotice, resumeSameConversationNotice, resumeUnavailableNotice, } from '@gaunt-sloth/agent/modules/sessionResume.js';
30
+ import { resumableConversationsNotice, resumedConversationNotice, resumeFailedNotice, resumeRefusalNotice, resumeSameConversationNotice, resumeUnavailableNotice, } from '@gaunt-sloth/agent/modules/sessionResume.js';
31
+ import { toConversationRef, } from '@gaunt-sloth/core/history/conversationRef.js';
27
32
  import { ApprovalsPicker } from '#src/tui/components/ApprovalsPicker.js';
33
+ import { ResumePicker, resumeCancelledNotice } from '#src/tui/components/ResumePicker.js';
28
34
  import { TerminalSizeProvider, useTerminalSize } from '#src/tui/useTerminalSize.js';
29
35
  import { findMatches, scrollOffsetForLine, stepMatch } from '#src/tui/debugSearch.js';
30
36
  import { useTranscriptScroll } from '#src/tui/useTranscriptScroll.js';
31
37
  import { isComposingKeystroke, WHEEL_ROWS_PER_NOTCH } from '#src/tui/transcriptScroll.js';
32
38
  import { TUI_HINT_SUFFIX, TUI_KEY_BINDINGS } from '#src/tui/keyBindings.js';
33
39
  import { isTypedText, typedText } from '#src/tui/keyGuards.js';
40
+ /**
41
+ * The empty line list a debug tab that is not on screen hands the panel. A module-level constant so
42
+ * its identity is stable across renders: a fresh `[]` each time would make the memo that clamps the
43
+ * scroll offset recompute on every render of every other tab.
44
+ */
45
+ const NO_DEBUG_LINES = [];
34
46
  /** Rows of clipping viewport in the docked debug panel (default / restored size). */
35
47
  const DEBUG_VIEWPORT_HEIGHT = 8;
36
48
  /** Rows of chrome around the debug viewport we leave for when it is maximised (panel
@@ -128,6 +140,15 @@ export function App(props) {
128
140
  const [transcript, setTranscript] = useState(seeded);
129
141
  const [live, setLive] = useState(null);
130
142
  const [running, setRunning] = useState(false);
143
+ /**
144
+ * [[EXT-92]] scope (a) — what the run is waiting on, when that is not the model answering.
145
+ *
146
+ * Held as the whole rendered sentence rather than an activity code, because the words are
147
+ * `core/waitNarration.ts`'s to choose: it is the module that reaches every surface, and a second
148
+ * spelling of the same wait on this one is the drift the exported prefix exists to prevent. The
149
+ * status bar renders it in place of its own default label, so this costs no row.
150
+ */
151
+ const [waitActivity, setWaitActivity] = useState(undefined);
131
152
  const [turnCount, setTurnCount] = useState(props.resumed?.turns.length ?? 0);
132
153
  // Subagent tree, folded from `task` tool calls on the live event stream. No backend dispatches
133
154
  // subagents in this release, so nothing fills it today; kept for GS2-25's lean primitive.
@@ -169,6 +190,11 @@ export function App(props) {
169
190
  // chrome: unlike the status notice it is never committed to the transcript, and it owns the
170
191
  // keyboard while mounted (the prompt is suspended below, as it is for a pending approval).
171
192
  const [approvalsPicker, setApprovalsPicker] = useState(null);
193
+ // GS2-112 — the open bare-`/resume` picker's candidates, or null when none is showing. Transient
194
+ // chrome on the same terms as the approvals picker above: never committed to the transcript, and
195
+ // it owns the keyboard while mounted. The list is the snapshot taken when the picker opened; a
196
+ // landed resume replaces the screen, so the picker is closed before the choice is applied.
197
+ const [resumePicker, setResumePicker] = useState(null);
172
198
  // Whether to show the post-`/clear` "history cleared" banner. Hidden again the moment the next
173
199
  // user turn starts so it doesn't linger above a fresh conversation.
174
200
  const [clearedBanner, setClearedBanner] = useState(false);
@@ -221,6 +247,14 @@ export function App(props) {
221
247
  // GS2-20 — starts past the seeded items so a later push never reuses a seeded key.
222
248
  const idRef = useRef(seeded.length);
223
249
  const runningRef = useRef(false);
250
+ /**
251
+ * [[EXT-92]] scope (e) — whether the turn now ending was ended by a throw.
252
+ *
253
+ * A ref rather than state because the only reader is the `finally` of the same async function
254
+ * the catch runs in: a `setState` would not be visible there, and the fact has to be true at the
255
+ * instant the turn is committed, not on the next render.
256
+ */
257
+ const turnErroredRef = useRef(false);
224
258
  /**
225
259
  * GS2-23 — whether a `/compact` is awaiting its summary. Read where `runningRef` is read at
226
260
  * submit, so a plain message cannot start a turn on a thread that is about to be rewritten, and
@@ -249,6 +283,22 @@ export function App(props) {
249
283
  */
250
284
  const conversationIdRef = useRef(props.conversationId);
251
285
  const turnCountRef = useRef(props.resumed?.turns.length ?? 0);
286
+ /**
287
+ * [[EXT-178]] — which conversation the outstanding recap request still belongs to.
288
+ *
289
+ * The recap is a model call launched detached at the end of a turn, so up to
290
+ * `RUN_RECAP_TIMEOUT_MS` can pass between asking and answering, and the session does not stand
291
+ * still for it: `/clear` empties the transcript the recap is describing, and a new turn can
292
+ * start and finish inside the window. Appending then puts a summary of a wiped conversation onto
293
+ * a blank screen, or files the previous turn's recap under this one.
294
+ *
295
+ * So the request carries the epoch it was made in and drops itself if the epoch has moved. It is
296
+ * bumped by exactly the three events that make a pending recap wrong: a new turn starting,
297
+ * `/clear`, and this component unmounting. It is deliberately NOT `turnCountRef`, which counts
298
+ * turns for the status bar, is incremented after the recap is launched, and is reset to 0 by
299
+ * `/clear` — a counter that goes backwards cannot be compared for staleness.
300
+ */
301
+ const recapEpochRef = useRef(0);
252
302
  // Per-turn args buffers for the subagent fold (mirrors foldSubagentTree's internal map).
253
303
  const subagentBuffersRef = useRef(new Map());
254
304
  const debugFocusedRef = useRef(false);
@@ -260,10 +310,11 @@ export function App(props) {
260
310
  // inside <PromptInput>, where it lives.
261
311
  const promptHandleRef = useRef(null);
262
312
  // TUI-C51 — the one thing about the prompt that has to outlive it: the message a command was
263
- // dispatched beside. The prompt is unmounted in four states below, and one of them (`/approvals`
264
- // opening its picker) is entered by a command dispatched FROM the prompt — so the draft is put
265
- // here, where nothing unmounts, and the prompt takes it back when it returns. It stays a slot
266
- // rather than state: nothing here renders it, and the prompt empties it as soon as it has it.
313
+ // dispatched beside. The prompt is unmounted in five states below, and two of them (`/approvals`
314
+ // and a bare `/resume` opening their pickers) are entered by a command dispatched FROM the
315
+ // prompt — so the draft is put here, where nothing unmounts, and the prompt takes it back when
316
+ // it returns. It stays a slot rather than state: nothing here renders it, and the prompt empties
317
+ // it as soon as it has it.
267
318
  const promptDraftCarryRef = useRef(null);
268
319
  // TUI-C79 — set the moment a teardown starts, so a second `quit()` can tell "leaving" from
269
320
  // "already leaving" and skip straight to the unmount. See `quit()`.
@@ -283,6 +334,18 @@ export function App(props) {
283
334
  const debugViewport = debugViewportHeight(debugMaximized, terminalRows);
284
335
  // PageUp/PageDown step tracks the live viewport so maximise pages by (almost) a full screen.
285
336
  const debugPageStep = Math.max(1, debugViewport - 1);
337
+ // [[TUI-C27]] — the Auto-mode tab's lines: the approvals gate's own record of every gated tool
338
+ // call, plus the rater config in force (already held here, since `/approvals` moves it).
339
+ //
340
+ // **Read fresh on every render while that tab is on screen, deliberately, and memoised on
341
+ // nothing.** The decision this tab exists for emits no event: a call the rater approves on its
342
+ // first rating relays nothing to any surface — the tool simply runs — so anything keyed on the
343
+ // approval, negotiation or turn signals the App already has would look live and miss exactly it.
344
+ // A pull costs one render of a capped (50-record) buffer, and only while a user is looking at
345
+ // the tab; every other tab keeps the stable empty array and pays nothing.
346
+ const debugAuto = debugVisible && debugTab === 'auto'
347
+ ? renderApprovalDetails(props.readApprovalCaptures?.() ?? [], approvals).split('\n')
348
+ : NO_DEBUG_LINES;
286
349
  // The active section's line count drives the real maximum scroll offset, so neither the page
287
350
  // step nor the arrow step can push the offset past the end (the over-scroll bug that left
288
351
  // PgUp/↑ burning through phantom offset before anything moved — TUI-C11). Single-sourced with
@@ -294,8 +357,9 @@ export function App(props) {
294
357
  toolsLines: debugTools,
295
358
  mcpLines: debugMcp,
296
359
  responseLines: debugResponse,
360
+ autoLines: debugAuto,
297
361
  activeTab: debugTab,
298
- }), [subagents, debugHistory, debugSystem, debugTools, debugMcp, debugResponse, debugTab]);
362
+ }), [subagents, debugHistory, debugSystem, debugTools, debugMcp, debugResponse, debugAuto, debugTab]);
299
363
  const debugLineCount = debugLines.length;
300
364
  const debugMaxOffset = Math.max(0, debugLineCount - debugViewport);
301
365
  // Match line-indices for the current query over the active tab's lines — one search, every tab
@@ -394,6 +458,8 @@ export function App(props) {
394
458
  // A new exchange supersedes the post-/clear banner; drop it so it doesn't sit above
395
459
  // the fresh conversation.
396
460
  setClearedBanner(false);
461
+ // [[EXT-178]] — and it supersedes the previous turn's recap, which may still be in flight.
462
+ recapEpochRef.current += 1;
397
463
  push({ kind: 'user', text: userInput });
398
464
  // [[TUI-C69]] §5.4 — a new user turn is a person being reached, which ENDS any negotiation
399
465
  // still standing (the runner clears its own transcript on the same event). Rounds from the
@@ -403,11 +469,21 @@ export function App(props) {
403
469
  abortRef.current = ac;
404
470
  runningRef.current = true;
405
471
  setRunning(true);
472
+ // [[EXT-92]] — both per-turn facts start clean. `turnErroredRef` (scope e) is set by the
473
+ // catch and read by the `finally`; `waitActivity` (scope a) is a label the status bar may
474
+ // still be holding from the previous turn's last wait.
475
+ turnErroredRef.current = false;
476
+ setWaitActivity(undefined);
406
477
  setLiveTurn(initialTurnViewModel());
407
478
  // Fresh args-buffer map per turn so partial `task` JSON from a prior turn never bleeds in.
408
479
  subagentBuffersRef.current = new Map();
409
480
  try {
410
481
  for await (const event of agent.runTurn(userInput, ac.signal)) {
482
+ // [[EXT-92]] scope (a) — an event arriving IS the wait ending. Clearing here rather than
483
+ // waiting for a paired "done" narration is what keeps the core signal one-way and the
484
+ // plain surface to exactly one line per wait: there is no end message to emit, so there
485
+ // is none to print. The status bar falls back to its own default label.
486
+ setWaitActivity(undefined);
411
487
  // [[TUI-C99]] — folded from the REF, not from a local: an approval answered mid-turn
412
488
  // writes the outcome onto its tool call from a keystroke, and a local carried across the
413
489
  // loop would overwrite it on the very next event the resumed run produces.
@@ -427,16 +503,43 @@ export function App(props) {
427
503
  push({ kind: 'stop', parts: err.parts });
428
504
  }
429
505
  else {
506
+ // [[EXT-92]] scope (b) — a provider error is rendered as prose here, and the raw payload
507
+ // rides along in a field this item's renderer never prints.
508
+ //
509
+ // The whole defect was on this line. `err.message` for an OpenRouter refusal is
510
+ // `Provider returned error | metadata: {…}` — upstream flattens its own structured
511
+ // metadata into the message — so the user read a JSON blob while the provider's own
512
+ // sentence, its remedy hint, and the fact that it was a SHARED pool rather than their
513
+ // quota all sat unread inside it. Nothing had been lost: the same fields are still
514
+ // objects on `err`, which is why this needed a renderer rather than a parser.
515
+ // `providerErrorNotice` returns null for the ordinary runtime errors it has nothing to
516
+ // add to, and those keep exactly the rendering they had.
517
+ const notice = providerErrorNotice(err);
430
518
  push({
431
519
  kind: 'system',
432
520
  level: 'error',
433
- text: err instanceof Error ? err.message : String(err),
521
+ text: notice?.text ?? (err instanceof Error ? err.message : String(err)),
522
+ ...(notice ? { raw: notice.raw } : {}),
434
523
  });
435
524
  }
525
+ // [[EXT-92]] scope (e) — remember that this turn was ended by the failure above, so the
526
+ // `finally` can commit it as a turn that STOPPED rather than one that finished. An
527
+ // approvals stop is deliberately excluded: it already commits its own `stop` item saying
528
+ // so in full, and marking the turn as well would state the same ending twice.
529
+ if (!(err instanceof ApprovalStopError))
530
+ turnErroredRef.current = true;
436
531
  }
437
532
  finally {
533
+ // [[EXT-92]] scope (a) — the turn is over, so nothing is being waited on. In the `finally`
534
+ // because the endings that most need it are the ones that reach neither the loop's normal
535
+ // exit nor the catch: a turn cancelled mid-rating would otherwise leave the bar naming a
536
+ // wait that no longer exists.
537
+ setWaitActivity(undefined);
438
538
  const vm = liveVmRef.current ?? initialTurnViewModel();
439
- push({ kind: 'assistant', turn: vm });
539
+ push({
540
+ kind: 'assistant',
541
+ turn: turnErroredRef.current ? { ...vm, endedInError: true } : vm,
542
+ });
440
543
  // [[EXT-159]] — and, immediately under the answer, why the turn ended when that is not
441
544
  // simply "the model finished".
442
545
  //
@@ -454,6 +557,50 @@ export function App(props) {
454
557
  const reason = agent.getTerminationReason?.() ?? null;
455
558
  if (reason && shouldAnnounceTermination(reason))
456
559
  push({ kind: 'termination', reason });
560
+ // [[EXT-158]] — and the other silence: a turn that ended cleanly with its own checklist
561
+ // still carrying work. `shouldAnnounceTermination` declines `completed`, correctly — an
562
+ // ordinary answer needs no epitaph — which is exactly why this case had nothing at all.
563
+ //
564
+ // Committed as an ordinary `notice` item rather than a transcript kind of its own. The
565
+ // termination item earns its kind by carrying the REASON value so the transcript holds
566
+ // the classification rather than a rendered line; this fact has no such closed taxonomy
567
+ // to preserve, and a new kind would buy a second row-count case and a second renderer for
568
+ // a title and three lines the generic notice already draws.
569
+ //
570
+ // [[EXT-178]] — and its successor when the user has switched the recap on. The two speak
571
+ // for the same population, so exactly one of them is drawn: `runEndReport` decides, with
572
+ // the recap already resolved, and a recap that never arrived leaves the notice standing.
573
+ //
574
+ // **Detached from the turn's teardown, and that is the whole reason it is down here.**
575
+ // A recap is a model call made after the answer is already on screen; awaiting it in this
576
+ // `finally` would keep the spinner running and the prompt away for as long as a provider
577
+ // takes to reply, which is a worse thing to do to a finished turn than a late paragraph.
578
+ // The transcript is append-only and this lands at the bottom, where the reader is. With
579
+ // the default `off` rung nothing is contacted and the notice lands as it always did.
580
+ const work = agent.getOutstandingWork?.() ?? null;
581
+ const ending = reason;
582
+ // Detached means the session can move on underneath it, so the request carries the epoch
583
+ // it was made in and says nothing if `recapEpochRef` has moved on — see that ref.
584
+ const epoch = recapEpochRef.current;
585
+ void (async () => {
586
+ try {
587
+ const recap = (await agent.requestRunRecap?.(ending)) ?? null;
588
+ if (recapEpochRef.current !== epoch)
589
+ return;
590
+ const report = runEndReport(recap, work, ending);
591
+ if (report.kind !== 'silent') {
592
+ push({
593
+ kind: 'notice',
594
+ title: report.notice.title,
595
+ lines: report.notice.lines,
596
+ tone: report.kind === 'recap' ? 'info' : 'warn',
597
+ });
598
+ }
599
+ }
600
+ catch {
601
+ /* fail-soft: explaining a turn must never be what breaks the session */
602
+ }
603
+ })();
457
604
  }
458
605
  catch {
459
606
  /* fail-soft: explaining a turn must never be what breaks the session */
@@ -715,7 +862,31 @@ export function App(props) {
715
862
  // replaces the screen: the transcript on it belonged to the conversation being left, and the
716
863
  // model is now continuing another one, so the banner and the restored turns take its place —
717
864
  // the same wipe `/clear` does, without the cleared banner, because nothing was discarded (the
718
- // conversation left keeps everything recorded under it). Bare, it lists what could be resumed.
865
+ // conversation left keeps everything recorded under it). Bare, this surface offers the picker
866
+ // below; the readline session prints the list.
867
+ //
868
+ // GS2-112 — **why the interactive picker is one branch here and not a new protocol field.**
869
+ //
870
+ // `/resume` returns `resume?: { id?: number }`, and the missing id is not an omission to be
871
+ // filled in later: the command is pure and cannot reach the store or the runner, so the no-id
872
+ // case has always meant *the surface fulfils this*, which is what every other surface already
873
+ // does with it. The Ink TUI can show a list and read arrow keys; the readline session can print
874
+ // one; a server surface has no user at a keyboard at all. Choosing is therefore the surface's
875
+ // answer to the same request, and nothing in the request needs to change for this surface to
876
+ // give a better one.
877
+ //
878
+ // The alternative was weighed and rejected rather than overlooked. A cross-package chooser — a
879
+ // new result field carrying candidates, or a `chooseConversation` callback threaded from the
880
+ // agent down into the component — would put a widget's contract in the module both surfaces
881
+ // read from, to serve one surface, and would still leave this branch deciding when to open it.
882
+ // It buys nothing: the candidates are already here (`props.listResumeCandidates`, wired in
883
+ // `tuiSessionModule`), and the id the user picks re-enters the with-id path below, which is the
884
+ // same code `--resume <id>` runs at boot. One branch, one new component, no new protocol.
885
+ //
886
+ // **The readline surface keeps the printed list deliberately.** It is not a fallback that has
887
+ // been left behind: with no Ink tree there is nothing to arrow through, and the printed ids
888
+ // remain the only way in on that surface — so `resumableConversationsNotice` stays its list
889
+ // builder, and no picker wording is allowed to leak into it (pinned by a spec).
719
890
  const applyResume = useCallback(async (id) => {
720
891
  const commit = (notice) => push({
721
892
  kind: 'notice',
@@ -724,19 +895,34 @@ export function App(props) {
724
895
  tone: notice.tone ?? 'info',
725
896
  });
726
897
  if (id === undefined) {
898
+ // A session with no store behind it cannot list anything, let alone offer it: this prop is
899
+ // wired only where history is on and a store opened, so its absence is the same "resume is
900
+ // unavailable here" the with-id path reports below.
727
901
  if (!props.listResumeCandidates) {
728
902
  commit(resumeUnavailableNotice());
729
903
  return;
730
904
  }
731
- commit(resumePickerNotice(props.listResumeCandidates()));
905
+ const candidates = props.listResumeCandidates();
906
+ // With nothing to offer, say so and open nothing. An empty <SelectList> renders a "no
907
+ // matches" line and its Enter is inert, so a picker here would be a modal the user can
908
+ // only escape from — strictly worse than the sentence, which also explains what makes a
909
+ // conversation resumable.
910
+ if (candidates.length === 0) {
911
+ commit(resumableConversationsNotice(candidates));
912
+ return;
913
+ }
914
+ setResumePicker(candidates);
732
915
  return;
733
916
  }
734
917
  if (!agent.resumeConversation) {
735
918
  commit(resumeUnavailableNotice());
736
919
  return;
737
920
  }
738
- if (id === conversationIdRef.current) {
739
- commit(resumeSameConversationNotice(id));
921
+ // The integer form can be compared before anything is looked up; a run id is resolved first,
922
+ // and the seam refuses one that names this conversation with the same notice.
923
+ const ref = toConversationRef(id);
924
+ if (ref.kind === 'id' && ref.id === conversationIdRef.current) {
925
+ commit(resumeSameConversationNotice(ref.id));
740
926
  return;
741
927
  }
742
928
  resumingRef.current = true;
@@ -1049,6 +1235,10 @@ export function App(props) {
1049
1235
  conversationId: conversationIdRef.current,
1050
1236
  toolsExpanded: toolsExpandedRef.current,
1051
1237
  debugVisible: debugVisibleRef.current,
1238
+ // TUI-C96 — this surface has the slash-command menu (<PromptInput> renders it
1239
+ // unconditionally), so the unknown-command notice may explain a shortened name by
1240
+ // pointing at it. The readline surface says false and gets the other sentence.
1241
+ hasSlashMenu: true,
1052
1242
  // TUI-C37 — undefined (not false) when this surface has no mouse layer, so `/mouse`
1053
1243
  // says it is unavailable rather than silently reporting "off".
1054
1244
  mouseEnabled: props.mouseEnabled === undefined ? undefined : mouseEnabledRef.current,
@@ -1059,6 +1249,10 @@ export function App(props) {
1059
1249
  // TUI-C19 — the actual validation warnings so `/config` renders the details the
1060
1250
  // standing advisory line points at.
1061
1251
  configWarnings: props.advisories,
1252
+ // GS2-88 — the three summaries AND the reason they may be empty, so a command with
1253
+ // nothing to show names the cause the session actually established rather than the
1254
+ // config. Both surfaces pass all four, from the one core builder.
1255
+ historyAvailability: props.historyAvailability,
1062
1256
  historySummary: props.historySummary,
1063
1257
  insightsSummary: props.insightsSummary,
1064
1258
  historySearch: props.historySearch,
@@ -1097,11 +1291,19 @@ export function App(props) {
1097
1291
  // thread intact (the LangGraph checkpointer replays it on the next turn), so the
1098
1292
  // model would still "remember" everything. Reset the agent's thread too so the
1099
1293
  // model context truly matches the now-empty transcript (TUI-C8).
1100
- agent.resetThread?.();
1294
+ //
1295
+ // [[EXT-109]] — and the agent's own record of the conversation goes with it: the
1296
+ // approvals gate's capture log is what the Auto-mode tab above and a later
1297
+ // `/debug-dump` read, and every other pane cleared here would otherwise sit beside one
1298
+ // that still quotes the user's pre-`/clear` messages.
1299
+ agent.clearConversation?.();
1101
1300
  // The status-bar turn counter is part of the conversation state we just wiped, so
1102
1301
  // reset it too — a cleared session starts back at "turns: 0".
1103
1302
  turnCountRef.current = 0;
1104
1303
  setTurnCount(0);
1304
+ // [[EXT-178]] — a recap still in flight describes the conversation just wiped, so drop
1305
+ // it rather than append a summary of nothing onto a cleared screen.
1306
+ recapEpochRef.current += 1;
1105
1307
  }
1106
1308
  if (result.toggleTools) {
1107
1309
  // Flip the fold mode and commit the notice via the shared helper (single-sourced with
@@ -1206,7 +1408,7 @@ export function App(props) {
1206
1408
  // path never registers gsloth's readline Esc handler, so Ink owns raw mode cleanly).
1207
1409
  // 3. Tab while the panel is visible and idle → focus/cycle the panel.
1208
1410
  // 4. While the panel is focused → Tab/Shift+Tab cycle sections, ↑/↓ scroll one line,
1209
- // PageUp/PageDown page-step, m maximises, Esc unfocuses.
1411
+ // PageUp/PageDown page-step, m maximises, Esc leaves the pane (restoring a maximised one).
1210
1412
  useInput((input, key) => {
1211
1413
  // [[TUI-C79]] — **Ctrl+C is this app's, not Ink's**, and it is answered here before anything
1212
1414
  // else can claim it. `render()` takes `exitOnCtrlC: false` (`tuiSessionModule.tsx`), which is
@@ -1227,13 +1429,19 @@ export function App(props) {
1227
1429
  // bare `exit` keyword all take it too).
1228
1430
  //
1229
1431
  // **The modal states are answered first, and they exit.** While an attack banner, an approval
1230
- // prompt or the approvals picker owns the keyboard, a turn IS in flight, so rung 2 would read
1231
- // "stop the turn" where the banner's own controls line says `Ctrl+C exits gth` and the user is
1232
- // looking for the way out of an irreversible action. So it exits, as the screen promises — and
1233
- // it goes through `quit()`, which resolves both bridges fail-closed on the way out rather than
1234
- // leaving the halt unanswered.
1432
+ // prompt or one of the pickers (`/approvals`, bare `/resume`) owns the keyboard, the prompt is
1433
+ // unmounted, so rung 1 has no buffer to scrap; and where that modal state was reached during a
1434
+ // turn, rung 2 would read "stop the turn" while the banner's own controls line says `Ctrl+C
1435
+ // exits gth` and the user is looking for the way out of an irreversible action. So it exits, as
1436
+ // the screen promises — and it goes through `quit()`, which resolves both bridges fail-closed
1437
+ // on the way out rather than leaving the halt unanswered.
1438
+ //
1439
+ // GS2-112 — the resume picker is in this set for coherence rather than for a case it changes
1440
+ // today: `/resume` is idle-only and the prompt is unmounted while its picker is up, so no turn
1441
+ // can be started under it and the ladder would fall to rung 3 and exit anyway. Naming it here
1442
+ // is what keeps that answer from depending on which rung happens to catch it.
1235
1443
  if (key.ctrl && input === 'c') {
1236
- if (pendingAttack || pendingApproval || approvalsPicker) {
1444
+ if (pendingAttack || pendingApproval || approvalsPicker || resumePicker) {
1237
1445
  quit();
1238
1446
  return;
1239
1447
  }
@@ -1369,11 +1577,11 @@ export function App(props) {
1369
1577
  resolveApproval('reject');
1370
1578
  return;
1371
1579
  }
1372
- // CFG-39 — while the `/approvals` picker is open it OWNS the keyboard, exactly as a pending
1373
- // approval does. <SelectList> is a useInput subscriber too and Ink runs every subscriber, so
1374
- // without this the arrow keys would also scroll the transcript and Esc would both cancel the
1375
- // picker and jump to the newest output. Returning here leaves the picker the only claimant.
1376
- if (approvalsPicker)
1580
+ // CFG-39, GS2-112 — while a picker is open it OWNS the keyboard, exactly as a pending approval
1581
+ // does. <SelectList> is a useInput subscriber too and Ink runs every subscriber, so without
1582
+ // this the arrow keys would also scroll the transcript and Esc would both cancel the picker and
1583
+ // jump to the newest output. Returning here leaves the picker the only claimant.
1584
+ if (approvalsPicker || resumePicker)
1377
1585
  return;
1378
1586
  if (key.escape && runningRef.current) {
1379
1587
  abortRef.current?.abort();
@@ -1437,7 +1645,17 @@ export function App(props) {
1437
1645
  }
1438
1646
  return;
1439
1647
  }
1440
- // Esc layering: clear an active search first (less-style), else unfocus the pane.
1648
+ // Esc layering: clear an active search first (less-style), else LEAVE the pane — and leaving
1649
+ // it drops the maximised view as well as focus, in the one press.
1650
+ //
1651
+ // TUI-C107 — focus and maximisation are one state as far as an exit is concerned, so an exit
1652
+ // that dropped only one of them left the user with nothing to press. The prompt is unmounted
1653
+ // while the pane holds focus (the render's `!debugFocused` guard), and a maximised pane takes
1654
+ // the terminal height minus DEBUG_MAX_CHROME_ROWS, so the prompt has no rows to draw in even
1655
+ // once focus is gone: dropping focus alone left the session with no visible prompt, and `m` —
1656
+ // the key that would undo the maximisation — is handled inside this focused-only branch, so
1657
+ // it no longer answered either. Same pairing, and the same reason, as the /debug toggle's
1658
+ // "focus never lingers on a hidden panel" above.
1441
1659
  if (key.escape) {
1442
1660
  if (debugSearchQueryRef.current) {
1443
1661
  clearDebugSearch();
@@ -1445,6 +1663,7 @@ export function App(props) {
1445
1663
  }
1446
1664
  setDebugFocused(false);
1447
1665
  debugFocusedRef.current = false;
1666
+ setDebugMaximized(false);
1448
1667
  return;
1449
1668
  }
1450
1669
  // `/` opens the search input (scoped to pane focus — the seam).
@@ -1588,6 +1807,12 @@ export function App(props) {
1588
1807
  };
1589
1808
  // eslint-disable-next-line react-hooks/exhaustive-deps
1590
1809
  }, []);
1810
+ // [[EXT-178]] — the third thing that invalidates a recap still in flight: this component going
1811
+ // away. A quit unmounts while a provider may still be holding the request open, and the reply
1812
+ // would then land on a session the user has left.
1813
+ useEffect(() => () => {
1814
+ recapEpochRef.current += 1;
1815
+ }, []);
1591
1816
  // Route agent status updates (warnings/errors) into the transcript instead of stdout,
1592
1817
  // which would otherwise corrupt Ink's frame. INFO/DEBUG system lines are suppressed in the
1593
1818
  // TUI: the agent's per-turn chatter (`Requested tools`, `Loaded tools`, `Workdir`, `Model`,
@@ -1598,6 +1823,17 @@ export function App(props) {
1598
1823
  if (!props.subscribeStatus)
1599
1824
  return;
1600
1825
  return props.subscribeStatus((level, message) => {
1826
+ // [[EXT-92]] scope (a) — a wait narration is INFO, and INFO is exactly what this handler
1827
+ // drops, so it is picked out BEFORE the filter and routed to the status bar instead of the
1828
+ // transcript. That is the right destination on both counts: it is a transient fact about the
1829
+ // present moment, which the transcript is the wrong shape for, and the bar is already the
1830
+ // TUI's wait renderer. Recognised by the prefix `core/waitNarration.ts` exports for this,
1831
+ // rather than by a copy of the wording here.
1832
+ const narration = readWaitNarration(message);
1833
+ if (narration !== null) {
1834
+ setWaitActivity(narration);
1835
+ return;
1836
+ }
1601
1837
  if (level === 'INFO' || level === 'DEBUG')
1602
1838
  return;
1603
1839
  if (message.trim())
@@ -1679,10 +1915,19 @@ export function App(props) {
1679
1915
  : 0) -
1680
1916
  (activeChecklist ? checklistPanelRows(activeChecklist) : 0) -
1681
1917
  negotiationPanelRows(negotiationRounds, terminalColumns);
1682
- return (_jsx(TerminalSizeProvider, { size: terminalSize, children: _jsx(MouseProvider, { subscribe: props.subscribeMouse, enabled: mouseEnabled, children: _jsxs(Box, { flexDirection: "column", height: terminalRows, children: [_jsxs(TranscriptViewport, { items: transcript, budgetRows: terminalRows, columns: terminalColumns, toolsExpanded: toolsExpanded, scroll: transcriptScroll, regionRows: transcriptRegionRows, geometry: transcriptGeometry, children: [clearedBanner ? _jsx(ClearBanner, {}) : null, showIntro && props.showLaunchBanner ? (_jsx(LaunchBanner, { model: modelDisplayName, provider: props.modelProviderType })) : null, showIntro ? _jsx(Text, { dimColor: true, children: readyMessage.trim() }) : null, live && transcript.length > 0 ? _jsx(BlankRow, {}) : null, live ? (_jsx(LiveTurn, { turn: live, toolsExpanded: toolsExpanded, streaming: true, columns: terminalColumns })) : null, pendingApproval ? (_jsxs(_Fragment, { children: [live || transcript.length > 0 ? _jsx(BlankRow, {}) : null, _jsx(ApprovalRequestPanel, { pending: pendingApproval.pending, columns: terminalColumns })] })) : null] }), _jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [debugVisible ? (_jsx(DebugPanel, { subagents: subagents, historyLines: debugHistory, systemLines: debugSystem, toolsLines: debugTools, mcpLines: debugMcp, responseLines: debugResponse, activeTab: debugTab, scrollOffset: debugScroll, focused: debugFocused, viewportHeight: debugViewport, maximized: debugMaximized, searchQuery: debugSearchQuery, searchActive: debugSearchInput, matchCount: debugMatches.length, currentMatchIndex: debugSearchCurrent, currentMatchLine: currentMatchLine })) : null, activeChecklist ? _jsx(ChecklistPanel, { items: activeChecklist }) : null, _jsx(NegotiationPanel, { rounds: negotiationRounds }), pendingAttack ? _jsx(AttackBanner, { halt: pendingAttack.halt, typed: attackTyped }) : null, pendingApproval && !pendingAttack ? (_jsx(ApprovalPrompt, { pending: pendingApproval.pending })) : null, approvalsPicker && !pendingApproval && !pendingAttack ? (_jsx(ApprovalsPicker, { choices: approvalsPicker, onSelect: (rung) => {
1918
+ return (_jsx(TerminalSizeProvider, { size: terminalSize, children: _jsx(MouseProvider, { subscribe: props.subscribeMouse, enabled: mouseEnabled, children: _jsxs(Box, { flexDirection: "column", height: terminalRows, children: [_jsxs(TranscriptViewport, { items: transcript, budgetRows: terminalRows, columns: terminalColumns, toolsExpanded: toolsExpanded, scroll: transcriptScroll, regionRows: transcriptRegionRows, geometry: transcriptGeometry, children: [clearedBanner ? _jsx(ClearBanner, {}) : null, showIntro && props.showLaunchBanner ? (_jsx(LaunchBanner, { model: modelDisplayName, provider: props.modelProviderType })) : null, showIntro ? _jsx(Text, { dimColor: true, children: readyMessage.trim() }) : null, live && transcript.length > 0 ? _jsx(BlankRow, {}) : null, live ? (_jsx(LiveTurn, { turn: live, toolsExpanded: toolsExpanded, streaming: true, columns: terminalColumns })) : null, pendingApproval ? (_jsxs(_Fragment, { children: [live || transcript.length > 0 ? _jsx(BlankRow, {}) : null, _jsx(ApprovalRequestPanel, { pending: pendingApproval.pending, columns: terminalColumns })] })) : null] }), _jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [debugVisible ? (_jsx(DebugPanel, { subagents: subagents, historyLines: debugHistory, systemLines: debugSystem, toolsLines: debugTools, mcpLines: debugMcp, responseLines: debugResponse, autoLines: debugAuto, activeTab: debugTab, scrollOffset: debugScroll, focused: debugFocused, viewportHeight: debugViewport, maximized: debugMaximized, searchQuery: debugSearchQuery, searchActive: debugSearchInput, matchCount: debugMatches.length, currentMatchIndex: debugSearchCurrent, currentMatchLine: currentMatchLine })) : null, activeChecklist ? _jsx(ChecklistPanel, { items: activeChecklist }) : null, _jsx(NegotiationPanel, { rounds: negotiationRounds }), pendingAttack ? _jsx(AttackBanner, { halt: pendingAttack.halt, typed: attackTyped }) : null, pendingApproval && !pendingAttack ? (_jsx(ApprovalPrompt, { pending: pendingApproval.pending })) : null, approvalsPicker && !pendingApproval && !pendingAttack ? (_jsx(ApprovalsPicker, { choices: approvalsPicker, onSelect: (rung) => {
1683
1919
  setApprovalsPicker(null);
1684
1920
  applyApprovalRung(rung);
1685
- }, onCancel: () => setApprovalsPicker(null) })) : null, _jsx(BlankRow, {}), _jsx(Rule, {}), _jsx(NoticeBar, { advisories: props.advisories }), _jsx(McpFailureBar, { failures: props.mcpFailures }), _jsx(StatusBar, { running: running, mode: mode, modelDisplayName: modelDisplayName,
1921
+ }, onCancel: () => setApprovalsPicker(null) })) : null, resumePicker && !approvalsPicker && !pendingApproval && !pendingAttack ? (_jsx(ResumePicker, { candidates: resumePicker, onSelect: (id) => {
1922
+ // Close BEFORE applying: a landed resume replaces the transcript and re-keys its
1923
+ // ids, and this list is a snapshot of the conversations as they were before it.
1924
+ setResumePicker(null);
1925
+ void applyResume(id);
1926
+ }, onCancel: () => {
1927
+ setResumePicker(null);
1928
+ const notice = resumeCancelledNotice();
1929
+ push({ kind: 'notice', title: notice.title, lines: notice.lines, tone: 'info' });
1930
+ } })) : null, _jsx(BlankRow, {}), _jsx(Rule, {}), _jsx(NoticeBar, { advisories: props.advisories }), _jsx(McpFailureBar, { failures: props.mcpFailures }), _jsx(StatusBar, { running: running, activity: waitActivity, mode: mode, modelDisplayName: modelDisplayName,
1686
1931
  // CFG-38 — the provider beside the model, and the live width it has to fit in: the
1687
1932
  // bar drops the provider rather than overflowing a narrow terminal.
1688
1933
  modelProviderType: props.modelProviderType, columns: terminalColumns, turnCount: turnCount, debugHint: debugVisible && !debugFocused, approvals: approvals
@@ -1690,7 +1935,11 @@ export function App(props) {
1690
1935
  rung: approvals.rung,
1691
1936
  raterProfile: approvals.rater,
1692
1937
  }
1693
- : undefined }), !debugFocused && !pendingApproval && !pendingAttack && !approvalsPicker ? (_jsxs(_Fragment, { children: [_jsx(BlankRow, {}), _jsx(PromptInput, { onSubmit: handleSubmit, commands: registry, onMenuStateChange: (active) => {
1938
+ : undefined }), !debugFocused &&
1939
+ !pendingApproval &&
1940
+ !pendingAttack &&
1941
+ !approvalsPicker &&
1942
+ !resumePicker ? (_jsxs(_Fragment, { children: [_jsx(BlankRow, {}), _jsx(PromptInput, { onSubmit: handleSubmit, commands: registry, onMenuStateChange: (active) => {
1694
1943
  slashMenuActiveRef.current = active;
1695
1944
  }, handleRef: promptHandleRef, draftCarryRef: promptDraftCarryRef, promptBlockRows: promptBlockRows }), _jsx(BlankRow, {})] })) : null, _jsx(Text, { dimColor: true, wrap: "truncate-end", children: `${exitMessage.trim()}${TUI_HINT_SUFFIX}` }), _jsx(Rule, {})] })] }) }) }));
1696
1945
  }