@andorra-labs/code 0.1.8 → 0.1.10

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 (187) hide show
  1. package/THIRD_PARTY_NOTICES.md +2 -1
  2. package/dist/src/account-presentation.d.ts +11 -0
  3. package/dist/src/account-presentation.js +29 -2
  4. package/dist/src/agent-execution.js +57 -4
  5. package/dist/src/agent-mcp.d.ts +12 -0
  6. package/dist/src/agent-mcp.js +81 -2
  7. package/dist/src/app-server/protocol.d.ts +120 -1
  8. package/dist/src/app-server/protocol.js +8 -1
  9. package/dist/src/app-server/reasoning.d.ts +0 -8
  10. package/dist/src/app-server/reasoning.js +15 -28
  11. package/dist/src/app-server.d.ts +32 -0
  12. package/dist/src/app-server.js +214 -21
  13. package/dist/src/auth/AuthManager.d.ts +15 -0
  14. package/dist/src/auth/AuthManager.js +66 -7
  15. package/dist/src/auth/index.d.ts +1 -1
  16. package/dist/src/auth/index.js +1 -1
  17. package/dist/src/auth/store.d.ts +17 -1
  18. package/dist/src/auth/store.js +25 -2
  19. package/dist/src/browser-runner.js +1 -2
  20. package/dist/src/browser-server.js +10 -2
  21. package/dist/src/browser-session.js +6 -2
  22. package/dist/src/browser-stealth.d.ts +29 -0
  23. package/dist/src/browser-stealth.js +166 -0
  24. package/dist/src/browser-ui/app.js +123 -28
  25. package/dist/src/browser-ui/icons/chevron-right.svg +8 -0
  26. package/dist/src/browser-ui/index.html +8 -8
  27. package/dist/src/browser-ui/style.css +199 -171
  28. package/dist/src/browser-ui/tokens.css +198 -0
  29. package/dist/src/browser-view.d.ts +57 -9
  30. package/dist/src/browser-view.js +187 -36
  31. package/dist/src/cli.js +31 -9
  32. package/dist/src/coding-tools.js +9 -5
  33. package/dist/src/command-screens.js +4 -4
  34. package/dist/src/commands.d.ts +1 -1
  35. package/dist/src/commands.js +3 -2
  36. package/dist/src/completion-gates.d.ts +35 -0
  37. package/dist/src/completion-gates.js +25 -0
  38. package/dist/src/completion.d.ts +7 -1
  39. package/dist/src/completion.js +37 -4
  40. package/dist/src/config.d.ts +1 -1
  41. package/dist/src/config.js +2 -2
  42. package/dist/src/context-budget.d.ts +11 -0
  43. package/dist/src/context-budget.js +13 -0
  44. package/dist/src/decision/DecisionEngine.d.ts +5 -1
  45. package/dist/src/decision/DecisionManager.d.ts +1 -0
  46. package/dist/src/decision/DecisionManager.js +14 -3
  47. package/dist/src/decision/FactContinuations.d.ts +6 -0
  48. package/dist/src/decision/FactContinuations.js +9 -1
  49. package/dist/src/decision/FactServiceGate.js +1 -1
  50. package/dist/src/decision/checks.js +1 -1
  51. package/dist/src/decision/hostedSkills.d.ts +37 -0
  52. package/dist/src/decision/hostedSkills.js +64 -0
  53. package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +10 -2
  54. package/dist/src/decision/providers/AndorraDecisionProvider.js +121 -10
  55. package/dist/src/default-graph.d.ts +11 -0
  56. package/dist/src/default-graph.js +20 -0
  57. package/dist/src/duration.d.ts +13 -2
  58. package/dist/src/duration.js +27 -3
  59. package/dist/src/file-diff.d.ts +105 -0
  60. package/dist/src/file-diff.js +244 -0
  61. package/dist/src/graph-manager-chat.d.ts +302 -0
  62. package/dist/src/graph-manager-chat.js +940 -0
  63. package/dist/src/graph-runner.js +6 -0
  64. package/dist/src/graph-server.d.ts +9 -0
  65. package/dist/src/graph-server.js +171 -20
  66. package/dist/src/graph-studio-features.js +2 -2
  67. package/dist/src/graph-sync.js +5 -2
  68. package/dist/src/graph-ui/app.js +369 -183
  69. package/dist/src/graph-ui/controls.css +55 -32
  70. package/dist/src/graph-ui/controls.js +85 -9
  71. package/dist/src/graph-ui/edge-router.js +114 -13
  72. package/dist/src/graph-ui/embed.js +32 -17
  73. package/dist/src/graph-ui/icons.js +1 -0
  74. package/dist/src/graph-ui/index.html +4 -4
  75. package/dist/src/graph-ui/library.css +4 -10
  76. package/dist/src/graph-ui/manager-markdown.js +155 -0
  77. package/dist/src/graph-ui/manager-state.js +191 -0
  78. package/dist/src/graph-ui/manager.css +161 -0
  79. package/dist/src/graph-ui/manager.js +700 -0
  80. package/dist/src/graph-ui/skill-picker.js +6 -6
  81. package/dist/src/graph-ui/studio-canvas.js +17 -15
  82. package/dist/src/graph-ui/studio.css +24 -23
  83. package/dist/src/graph-ui/studio.js +69 -48
  84. package/dist/src/graph-ui/style.css +128 -93
  85. package/dist/src/graph-ui/theme.js +2 -2
  86. package/dist/src/graph-ui/tokens.css +217 -151
  87. package/dist/src/graphs.d.ts +76 -2
  88. package/dist/src/graphs.js +172 -9
  89. package/dist/src/hardened-runtime.js +8 -2
  90. package/dist/src/mcp.d.ts +75 -0
  91. package/dist/src/mcp.js +240 -8
  92. package/dist/src/membership-errors.d.ts +14 -0
  93. package/dist/src/membership-errors.js +24 -1
  94. package/dist/src/membership.d.ts +20 -0
  95. package/dist/src/membership.js +45 -16
  96. package/dist/src/palette.d.ts +25 -8
  97. package/dist/src/palette.js +26 -8
  98. package/dist/src/provider-engine.d.ts +4 -4
  99. package/dist/src/provider-engine.js +39 -22
  100. package/dist/src/provider-keys.d.ts +5 -1
  101. package/dist/src/provider-keys.js +7 -3
  102. package/dist/src/provider-settings.d.ts +4 -1
  103. package/dist/src/provider-settings.js +46 -5
  104. package/dist/src/providers.d.ts +24 -0
  105. package/dist/src/providers.js +47 -2
  106. package/dist/src/qa/guidance.d.ts +26 -0
  107. package/dist/src/qa/guidance.js +46 -0
  108. package/dist/src/qa/index.d.ts +1 -8
  109. package/dist/src/qa/index.js +1 -16
  110. package/dist/src/qa/profile/QaProfile.d.ts +5 -1
  111. package/dist/src/qa/profile/QaProfile.js +6 -2
  112. package/dist/src/qa/runtime/ProcessManager.d.ts +20 -2
  113. package/dist/src/qa/runtime/ProcessManager.js +69 -13
  114. package/dist/src/qa/tools.d.ts +19 -1
  115. package/dist/src/qa/tools.js +20 -145
  116. package/dist/src/react-runtime.d.ts +11 -0
  117. package/dist/src/react-runtime.js +203 -53
  118. package/dist/src/remote/engine-pool.js +21 -6
  119. package/dist/src/run-progress.d.ts +6 -0
  120. package/dist/src/run-progress.js +7 -0
  121. package/dist/src/runtime.d.ts +8 -0
  122. package/dist/src/screen-selection.d.ts +38 -0
  123. package/dist/src/screen-selection.js +103 -0
  124. package/dist/src/session-changes.d.ts +117 -0
  125. package/dist/src/session-changes.js +796 -0
  126. package/dist/src/session-skills.d.ts +75 -0
  127. package/dist/src/session-skills.js +151 -0
  128. package/dist/src/side-panel.d.ts +1 -1
  129. package/dist/src/side-panel.js +6 -12
  130. package/dist/src/skill-commands.js +1 -1
  131. package/dist/src/skills/bundled/control-browser/SKILL.md +9 -1
  132. package/dist/src/skills/bundled/graph-manager/SKILL.md +8 -0
  133. package/dist/src/skills/bundled/provenance.json +3 -3
  134. package/dist/src/skills/bundled/web-gui-tester/SKILL.md +1 -1
  135. package/dist/src/stall-recovery.d.ts +33 -0
  136. package/dist/src/stall-recovery.js +83 -0
  137. package/dist/src/subagent-run.js +1 -2
  138. package/dist/src/telemetry/schema.d.ts +1 -1
  139. package/dist/src/telemetry/schema.js +1 -2
  140. package/dist/src/terminal-ui.d.ts +66 -22
  141. package/dist/src/terminal-ui.js +327 -92
  142. package/dist/src/tool-diff-stats.d.ts +9 -0
  143. package/dist/src/tool-diff-stats.js +20 -0
  144. package/dist/src/tool-names.d.ts +1 -1
  145. package/dist/src/tool-result-filter.js +1 -1
  146. package/dist/src/tools.js +26 -2
  147. package/dist/src/transcript.d.ts +11 -0
  148. package/dist/src/transcript.js +23 -3
  149. package/dist/src/types.d.ts +24 -4
  150. package/dist/src/usage-analytics.d.ts +7 -0
  151. package/dist/src/usage-analytics.js +55 -15
  152. package/docs/concepts/README.md +1 -1
  153. package/docs/concepts/limits.md +9 -0
  154. package/docs/guides/desktop-app.md +1 -1
  155. package/docs/guides/graph-builder.md +16 -1
  156. package/docs/guides/tui.md +9 -9
  157. package/docs/reference/slash-commands.md +2 -1
  158. package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +203 -0
  159. package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +79 -0
  160. package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +182 -0
  161. package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +156 -0
  162. package/package.json +1 -1
  163. package/tests/chat-side-panel-test-plan.md +1 -1
  164. package/dist/src/qa/api/http-runner.d.ts +0 -3
  165. package/dist/src/qa/api/http-runner.js +0 -47
  166. package/dist/src/qa/git/ChangeDetector.d.ts +0 -26
  167. package/dist/src/qa/git/ChangeDetector.js +0 -177
  168. package/dist/src/qa/git/DiffReviewer.d.ts +0 -28
  169. package/dist/src/qa/git/DiffReviewer.js +0 -115
  170. package/dist/src/qa/orchestrator/ChangeClassifier.d.ts +0 -14
  171. package/dist/src/qa/orchestrator/ChangeClassifier.js +0 -28
  172. package/dist/src/qa/orchestrator/MergeGate.d.ts +0 -14
  173. package/dist/src/qa/orchestrator/MergeGate.js +0 -40
  174. package/dist/src/qa/orchestrator/QaOrchestrator.d.ts +0 -79
  175. package/dist/src/qa/orchestrator/QaOrchestrator.js +0 -373
  176. package/dist/src/qa/runners/CommandRunner.d.ts +0 -22
  177. package/dist/src/qa/runners/CommandRunner.js +0 -96
  178. package/dist/src/qa/runners/TestRunner.d.ts +0 -21
  179. package/dist/src/qa/runners/TestRunner.js +0 -66
  180. package/dist/src/qa/runtime/RuntimeSmoke.d.ts +0 -11
  181. package/dist/src/qa/runtime/RuntimeSmoke.js +0 -78
  182. package/dist/src/qa/runtime-detect.d.ts +0 -10
  183. package/dist/src/qa/runtime-detect.js +0 -72
  184. package/dist/src/qa/security/DependencyScanner.d.ts +0 -19
  185. package/dist/src/qa/security/DependencyScanner.js +0 -167
  186. package/dist/src/qa/security/SecretScanner.d.ts +0 -3
  187. package/dist/src/qa/security/SecretScanner.js +0 -55
@@ -8,9 +8,10 @@ import { DashboardMetrics } from './dashboard.js';
8
8
  import { dashboardRows } from './dashboard-view.js';
9
9
  import { transcriptColor } from './transcript.js';
10
10
  import { ToolCallClock, toolHeaderRows } from './tool-call-clock.js';
11
- import { formatDuration } from './duration.js';
11
+ import { formatDuration, formatHms } from './duration.js';
12
12
  import { PagedTranscript } from './paged-transcript.js';
13
- import { accentSgr, ATTACHMENT_TOKEN, DIM, FAINT, GRAY, SKILL_CHIP, STATUS, SUBTLE, WHITE } from './palette.js';
13
+ import { emptySelection, highlightRow, selectedSpan, selectedText, wordAt } from './screen-selection.js';
14
+ import { accentSgr, ATTACHMENT_TOKEN, ATTENTION, DIM, FAINT, GRAY, SKILL_CHIP, SUBTLE, WHITE } from './palette.js';
14
15
  import { isCustomGraph, panelRowText, panelWidth, PANEL_MIN_COLUMNS, PANEL_MIN_ROWS, sidePanelRows } from './side-panel.js';
15
16
  import { TokenRateMeter } from './token-rate.js';
16
17
  import { attachmentLabel, droppedPaths, formatBytes, isLargePaste, MAX_ATTACHMENTS } from './attachments.js';
@@ -33,7 +34,7 @@ const SKILL_TOKEN = String.fromCodePoint(0x10FFFD);
33
34
  const composerGraphemes = (text) => graphemes(text).flatMap(part => isToken(part) && part.length > 2 ? [part.slice(0, 2), part.slice(2)] : [part]);
34
35
  const clean = (text) => stripVTControlCharacters(text).replace(/\r\n?/g, '\n').replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/g, '').replace(/[\u{100000}-\u{10FFFF}]/gu, '').replace(/\t/g, ' ');
35
36
  const oneLine = (text) => clean(text).replace(/\n/g, ' ');
36
- const commands = ['/model', '/providers', '/subagent', '/reasoning', '/graph', '/codegraph', '/dashboard', '/browser', '/attach', '/skills', '/plugins', '/mcp', '/usage', '/permissions', '/yolo', '/jev', '/feedback', '/tools', '/session', '/status', '/clear', '/compact', '/help', '/login', '/logout', '/auth status', '/auth logout', '/exit', '/quit'];
37
+ const commands = ['/model', '/providers', '/subagent', '/reasoning', '/graph', '/codegraph', '/dashboard', '/browser', '/attach', '/skills', '/skill', '/plugins', '/mcp', '/usage', '/permissions', '/yolo', '/jev', '/feedback', '/tools', '/session', '/status', '/clear', '/compact', '/help', '/login', '/logout', '/auth status', '/auth logout', '/exit', '/quit'];
37
38
  /**
38
39
  * The arguments the popup offers once a command and a space are typed. The read-only choice comes
39
40
  * first wherever there is one, so a second Enter on a freshly opened list reports rather than
@@ -47,6 +48,7 @@ const argumentCompletions = {
47
48
  '/codegraph': ['/codegraph status', '/codegraph enable', '/codegraph disable', '/codegraph rebuild', '/codegraph enable --global', '/codegraph disable --global'],
48
49
  '/attach': [],
49
50
  '/logout': ['/logout codex'],
51
+ '/skill': ['/skill off', '/skill on', '/skill remove'],
50
52
  };
51
53
  /**
52
54
  * Commands that do nothing useful bare. Enter or Tab on one fills in the command and a space and
@@ -55,7 +57,10 @@ const argumentCompletions = {
55
57
  const argumentRequired = new Set(['/jev', '/feedback', '/yolo', '/reasoning', '/codegraph', '/attach']);
56
58
  const completionOptions = (query, skills = []) => {
57
59
  const command = /^(\/\S+)\s/.exec(query)?.[1];
58
- return (command === undefined ? [...commands, ...skills] : argumentCompletions[command] ?? []).filter(option => option.startsWith(query));
60
+ // A command typed in full is offered first, so `/skill` runs itself rather than `/skills`, which
61
+ // a shorter prefix such as `/sk` still reaches first.
62
+ return (command === undefined ? [...commands, ...skills] : argumentCompletions[command] ?? []).filter(option => option.startsWith(query))
63
+ .sort((a, b) => Number(b === query) - Number(a === query));
59
64
  };
60
65
  /**
61
66
  * Whether the composer text is a command name, or a command with arguments, that the popup completes.
@@ -83,6 +88,7 @@ const commandDescriptions = {
83
88
  '/model': 'Choose a model', '/providers': 'Choose or edit providers',
84
89
  '/subagent': 'Choose the provider and model external hosts run Andorra with',
85
90
  '/reasoning': 'Choose thinking effort', '/dashboard': 'Toggle live dashboard / transcript',
91
+ '/skill': 'Show the active skill', '/skill off': 'Pause the active skill', '/skill on': 'Resume the active skill', '/skill remove': 'End the active skill',
86
92
  '/skills': 'Manage and install skills', '/plugins': 'Manage and install plugins',
87
93
  '/mcp': 'Manage MCP servers',
88
94
  '/jev': 'Turn Jev on or off for nodes that enable it', '/jev on': 'Enable Jev', '/jev off': 'Disable Jev', '/jev status': 'Show saved Jev setting',
@@ -139,6 +145,19 @@ const MAX_INPUT = 65_536;
139
145
  */
140
146
  const PASTE_ACCUMULATE_LIMIT = 1_048_576;
141
147
  const INPUT_BURST_MS = 40;
148
+ /** Two presses on one cell within this window select the word under it. */
149
+ const DOUBLE_CLICK_MS = 400;
150
+ /** The legacy X10 mouse report prefix: ESC [ M, followed by three payload bytes. */
151
+ const LEGACY_MOUSE = Buffer.from([0x1b, 0x5b, 0x4d]);
152
+ /** The bracketed-paste terminator, as bytes. */
153
+ const PASTE_END = Buffer.from('\x1b[201~', 'latin1');
154
+ /** How many trailing bytes of `buffer` could still grow into a `LEGACY_MOUSE` prefix. */
155
+ const legacyMousePrefixLength = (buffer) => {
156
+ for (let length = Math.min(2, buffer.length); length > 0; length--)
157
+ if (buffer.subarray(buffer.length - length).equals(LEGACY_MOUSE.subarray(0, length)))
158
+ return length;
159
+ return 0;
160
+ };
142
161
  /** Rows an echoed prompt may occupy before the tail is replaced by an omission marker. */
143
162
  const MAX_PROMPT_ROWS = 200;
144
163
  /** Long submitted prompts collapse in chat history until the user expands them with Ctrl+O. */
@@ -226,7 +245,7 @@ function selectedColumns(text, positions, [from, to], row) {
226
245
  return start < end ? [start, end] : undefined;
227
246
  }
228
247
  /**
229
- * Paint one composer row: attachment token columns in amber, and the selected column span in
248
+ * Paint one composer row: attachment token columns in bold, and the selected column span in
230
249
  * reverse video over whichever color it covers.
231
250
  */
232
251
  function composerRow(text, color, selection, tokens) {
@@ -371,9 +390,9 @@ export class TerminalUI extends EventEmitter {
371
390
  nodeModels = new Map();
372
391
  toggleDashboard() { this.dashboard = !this.dashboard; this.scroll = 0; this.scheduleRender(); }
373
392
  /** Start of a run: open the dashboard's run window. */
374
- startTask() { this.runActive = true; this.updateAlternateScroll(); this.dashboardMetrics.startTask(); this.dashboardNotices = []; this.nodeModels.clear(); this.scheduleRender(); }
393
+ startTask() { this.runActive = true; this.dashboardMetrics.startTask(); this.dashboardNotices = []; this.nodeModels.clear(); this.scheduleRender(); }
375
394
  /** End of a run: close the dashboard's run window. */
376
- finishTask() { this.runActive = false; this.updateAlternateScroll(); this.dashboardMetrics.finishTask(); this.scheduleRender(); }
395
+ finishTask() { this.runActive = false; this.dashboardMetrics.finishTask(); this.scheduleRender(); }
377
396
  resetDashboardSession(usage) { this.dashboardMetrics.resetSession(usage); this.dashboardModel = 0; this.dashboardGraphOffset = 0; this.nodeModels.clear(); this.dashboardNotices = []; this.scheduleRender(); }
378
397
  /** Clock backing the per-node speed meters; see {@link TerminalOptions.tokenClock}. */
379
398
  tokenClock;
@@ -756,19 +775,20 @@ export class TerminalUI extends EventEmitter {
756
775
  todoOffset = 0;
757
776
  todoPageSize = 0;
758
777
  scroll = 0;
759
- /** Whether a run is streaming: with no prompt pending, the wheel may scroll the transcript. */
778
+ /** Whether a run is streaming. */
760
779
  runActive = false;
761
780
  /**
762
- * Whether alternate scroll mode (?1007) is currently armed.
781
+ * The drag selection over the drawn frame, in screen cells.
763
782
  *
764
- * The app never takes mouse reporting, so the terminal keeps drag-to-select and its
765
- * clipboard in every state. In the alternate screen a terminal instead turns the wheel
766
- * into Up/Down sequences when alternate scroll is on — byte-identical to the arrow keys,
767
- * and on by default in Windows Terminal, VTE and iTerm2 — so the app arms that mode only
768
- * where Up/Down cannot recall history: while a screen is open, or while a run streams with
769
- * no question pending. At the resting prompt it is switched off and the wheel is inert.
783
+ * The app holds mouse reporting for the whole session so the wheel arrives as a wheel report
784
+ * and never as the Up/Down bytes that recall input history. Holding the mouse takes the drag
785
+ * away from the terminal, so the app draws the selection itself and copies it on release.
770
786
  */
771
- alternateScroll = false;
787
+ selection;
788
+ /** The last left press, kept to recognize a double-click on the same cell. */
789
+ lastPress;
790
+ /** The frame as composed, before the selection highlight is laid over it. */
791
+ frame = [];
772
792
  /**
773
793
  * Live reasoning preview state. `thinkingActive` marks a stream in progress; the text
774
794
  * is the bounded tail the preview renders from.
@@ -803,6 +823,17 @@ export class TerminalUI extends EventEmitter {
803
823
  completion;
804
824
  dismissedCompletion;
805
825
  incoming = '';
826
+ /**
827
+ * Raw bytes not yet decoded to `incoming`.
828
+ *
829
+ * Legacy mouse reports are framed here, on bytes, before UTF-8 decoding: their payload
830
+ * is three value-plus-32 bytes that the decoder would buffer while an incomplete
831
+ * sequence (column 192, row 128 ends in E0 A0) and collapse when the pair forms a
832
+ * valid one (column 162, row 128 encodes as C2 A0), so no string-domain measurement
833
+ * can see a report in time without risking the keystroke that follows it.
834
+ */
835
+ rawIncoming = Buffer.alloc(0);
836
+ rawTimer;
806
837
  pasting = false;
807
838
  paste = '';
808
839
  pasteQuestion;
@@ -876,7 +907,7 @@ export class TerminalUI extends EventEmitter {
876
907
  /**
877
908
  * Attachments queued in the composer draft — large pastes spooled to text, dropped file
878
909
  * paths, clipboard images. Each sits in the draft as an inline token (its `marker` code
879
- * point), drawn as an amber label and edited as one character. They ride the next submitted
910
+ * point), drawn as a bold label and edited as one character. They ride the next submitted
880
911
  * task (or the next queued steer) and are drained by the CLI, mirroring how `steered` is
881
912
  * drained at turn boundaries.
882
913
  */
@@ -937,27 +968,29 @@ export class TerminalUI extends EventEmitter {
937
968
  this.input.on('end', this.onEnd);
938
969
  this.output.on('resize', this.onResize);
939
970
  this.input.resume();
940
- // The app never takes mouse reporting (?1000h/?1006h): the terminal keeps its own
941
- // drag-to-select and clipboard in every state, at rest and while a run streams alike, with
942
- // no modifier bypass to learn. What the wheel does is governed by alternate scroll mode
943
- // (?1007) instead. In the alternate screen a terminal with that mode on turns the wheel
944
- // into Up/Down sequences byte-identical to the arrow keys, and Windows Terminal, VTE and
945
- // iTerm2 have it on by default — which is how an uncaptured wheel once recalled the
946
- // previous prompt. The mode is therefore switched off explicitly here, and
947
- // `updateAlternateScroll` arms it only where Up/Down cannot reach history: while a
948
- // screen is open (its keys scroll or move the highlight) or while a run streams with no
949
- // question pending (Up/Down scroll the transcript, see onKey). At the resting prompt the
950
- // wheel is inert and Up/Down stay purely keyboard: input history, or cursor movement in a
951
- // draft. The collapsed long-prompt boxes open with Ctrl+O and the live reasoning preview
952
- // toggles with Ctrl+Y; neither needs a click. writeFrame only rewrites rows that changed,
953
- // so the working animation does not repaint cells under a drag selection either. Entering
954
- // the alternate screen blanks it, so nothing drawn before is still there to diff.
971
+ // The app holds mouse reporting (?1002h/?1006h) from here to close(), so the wheel always
972
+ // arrives as a wheel report and scrolls the transcript: at the resting prompt, while a run
973
+ // streams and on every screen. Leaving the wheel to the terminal is not an option in the
974
+ // alternate screen. Windows Terminal, VTE and iTerm2 turn an uncaptured wheel into Up/Down
975
+ // sequences byte-identical to the arrow keys (alternate scroll mode, ?1007), which either
976
+ // recalls input history on every wheel tick or forces the arrows to give history up. With
977
+ // the mouse held, Up/Down stay purely keyboard, and ?1007 is switched off so a terminal
978
+ // that ignores the capture still sends nothing for the wheel. Button-event tracking (?1002)
979
+ // also reports the drag, which the app draws and copies itself (see `mouse`); the
980
+ // terminal's own selection stays reachable through its bypass, Shift+drag in most. Legacy
981
+ // ESC[M reports from terminals without the SGR encoding are framed in `consumeRaw`.
982
+ // writeFrame only rewrites rows that changed. Entering the alternate screen blanks it, so
983
+ // nothing drawn before is still there to diff.
955
984
  this.drawn = [];
956
985
  this.drawnSize = '';
957
986
  this.drawnCursor = '';
958
- this.output.write('\x1b[?1049h\x1b[?2004h\x1b[?25l\x1b[?1007l');
959
- this.alternateScroll = false;
960
- this.updateAlternateScroll();
987
+ // The alternate screen is left before it is entered. A session that died without closing
988
+ // (a dropped SSH connection) leaves the tab in the alternate screen, and Windows Terminal
989
+ // sizes a second alternate buffer from its main viewport, whose resize it defers until the
990
+ // alternate screen is left: after the window grew, every row of a frame drawn for the real
991
+ // width wrapped on the stale, narrower grid. Leaving first applies that deferred resize;
992
+ // where the main screen is already active the reset changes nothing.
993
+ this.output.write('\x1b[?1049l\x1b[?1049h\x1b[?2004h\x1b[?25l\x1b[?1007l\x1b[?1002h\x1b[?1006h');
961
994
  this.render();
962
995
  }
963
996
  question(prompt = '', options = {}) {
@@ -991,7 +1024,6 @@ export class TerminalUI extends EventEmitter {
991
1024
  pending.abort = () => { if (this.pending !== pending)
992
1025
  return; this.finishQuestion(); reject(new DOMException('Question aborted', 'AbortError')); this.scheduleRender(); };
993
1026
  this.pending = pending;
994
- this.updateAlternateScroll();
995
1027
  this.updateWorkingClock();
996
1028
  pending.signal?.addEventListener('abort', pending.abort, { once: true });
997
1029
  this.scheduleRender();
@@ -1073,7 +1105,6 @@ export class TerminalUI extends EventEmitter {
1073
1105
  modal.abort = () => { if (this.modal === modal)
1074
1106
  this.finishModal(undefined, new DOMException('Screen aborted', 'AbortError')); };
1075
1107
  this.modal = modal;
1076
- this.updateAlternateScroll();
1077
1108
  this.updateWorkingClock();
1078
1109
  modal.signal?.addEventListener('abort', modal.abort, { once: true });
1079
1110
  this.scheduleRender();
@@ -1084,7 +1115,6 @@ export class TerminalUI extends EventEmitter {
1084
1115
  if (!modal)
1085
1116
  return;
1086
1117
  this.modal = undefined;
1087
- this.updateAlternateScroll();
1088
1118
  // Only a selection that was actually made is worth docking: a cancelled list leads to no
1089
1119
  // field, and the caller returns to the conversation instead.
1090
1120
  if (modal.kind === 'select' && !error && typeof value === 'string')
@@ -1279,7 +1309,7 @@ export class TerminalUI extends EventEmitter {
1279
1309
  this.visitedNodes.clear();
1280
1310
  this.stoppedNode = undefined;
1281
1311
  }
1282
- this.status = { ...this.status, ...partial };
1312
+ this.status = { ...this.status, ...partial, ...(partial.activity !== undefined && partial.backgroundActivity === undefined ? { backgroundActivity: false } : {}) };
1283
1313
  // A run ending returns the footer to idle but does not retire the speed readout: each
1284
1314
  // node's cumulative average keeps describing the node that just ran, and it is the
1285
1315
  // baseline the next run of that node continues from.
@@ -1546,7 +1576,7 @@ export class TerminalUI extends EventEmitter {
1546
1576
  if (!this.thinkingActive || maxRows < 1)
1547
1577
  return [];
1548
1578
  const inner = Math.max(1, width - 4);
1549
- const stamp = seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
1579
+ const stamp = formatHms(seconds);
1550
1580
  const trace = clip(`◌ ${this.thinkingTail() || 'Thinking…'}`, inner);
1551
1581
  const controls = clip(`◌ ${stamp} · ctrl+y`, inner);
1552
1582
  const collapsed = maxRows === 1 ? [trace] : [trace, controls];
@@ -1567,7 +1597,7 @@ export class TerminalUI extends EventEmitter {
1567
1597
  return '';
1568
1598
  }
1569
1599
  updateWorkingClock() {
1570
- if (!this.status.activity || this.status.activity === 'Ready') {
1600
+ if (!this.status.activity || this.status.activity === 'Ready' || this.status.backgroundActivity) {
1571
1601
  this.workingSince = undefined;
1572
1602
  this.workingElapsed = 0;
1573
1603
  }
@@ -1579,22 +1609,6 @@ export class TerminalUI extends EventEmitter {
1579
1609
  else
1580
1610
  this.workingSince ??= Date.now();
1581
1611
  }
1582
- /**
1583
- * Recompute whether the wheel may act: alternate scroll mode is armed while a screen is
1584
- * open, or while a run streams with no question pending, and off everywhere else.
1585
- *
1586
- * Only transitions write anything. Entering the alternate screen resets the flag first
1587
- * (`start`), because that screen begins with the mode explicitly switched off.
1588
- */
1589
- updateAlternateScroll() {
1590
- const armed = Boolean(this.modal) || (this.runActive && !this.pending);
1591
- if (armed === this.alternateScroll)
1592
- return;
1593
- this.alternateScroll = armed;
1594
- if (!this.started || this.closed)
1595
- return;
1596
- this.output.write(armed ? '\x1b[?1007h' : '\x1b[?1007l');
1597
- }
1598
1612
  close() {
1599
1613
  this.transcript.close();
1600
1614
  this.toolClock.stop();
@@ -1616,6 +1630,9 @@ export class TerminalUI extends EventEmitter {
1616
1630
  this.workingTimer = undefined;
1617
1631
  if (this.escapeTimer)
1618
1632
  clearTimeout(this.escapeTimer);
1633
+ if (this.rawTimer)
1634
+ clearTimeout(this.rawTimer);
1635
+ this.rawTimer = undefined;
1619
1636
  this.finishModal(undefined, new DOMException('Terminal closed', 'AbortError'));
1620
1637
  const pending = this.pending;
1621
1638
  this.finishQuestion();
@@ -1634,7 +1651,7 @@ export class TerminalUI extends EventEmitter {
1634
1651
  this.input.pause();
1635
1652
  this.input.unref?.();
1636
1653
  }
1637
- this.output.write('\x1b[?1007h\x1b[?2004l\x1b[?25h\x1b[0m\x1b[?1049l');
1654
+ this.output.write('\x1b[?1002l\x1b[?1006l\x1b[?1007h\x1b[?2004l\x1b[?25h\x1b[0m\x1b[?1049l');
1638
1655
  }
1639
1656
  }
1640
1657
  this.emit('close');
@@ -1645,7 +1662,6 @@ export class TerminalUI extends EventEmitter {
1645
1662
  if (this.pending?.abort)
1646
1663
  this.pending.signal?.removeEventListener('abort', this.pending.abort);
1647
1664
  this.pending = undefined;
1648
- this.updateAlternateScroll();
1649
1665
  this.updateWorkingClock();
1650
1666
  this.value = [];
1651
1667
  this.cursor = 0;
@@ -1667,16 +1683,124 @@ export class TerminalUI extends EventEmitter {
1667
1683
  if (this.escapeTimer)
1668
1684
  clearTimeout(this.escapeTimer);
1669
1685
  this.escapeTimer = undefined;
1686
+ if (this.rawTimer)
1687
+ clearTimeout(this.rawTimer);
1688
+ this.rawTimer = undefined;
1670
1689
  this.modalInput = !!this.modal;
1671
- this.incoming += this.decoder.write(typeof chunk === 'string' ? Buffer.from(chunk, 'utf8') : chunk);
1690
+ this.rawIncoming = Buffer.concat([this.rawIncoming, typeof chunk === 'string' ? Buffer.from(chunk, 'utf8') : chunk]);
1691
+ this.consumeRaw();
1672
1692
  this.consumeIncoming();
1673
1693
  };
1674
- /** Drain the decoded stream: paste markers and ordinary keys. */
1694
+ /**
1695
+ * Frame legacy X10 mouse reports on the raw byte stream before UTF-8 decoding.
1696
+ *
1697
+ * A terminal with mouse tracking but without the SGR encoding of mode 1006 answers capture
1698
+ * with ESC[M plus three raw payload bytes (button, then coordinates, each offset by
1699
+ * 32). Those bytes are framed here rather than in the decoded string because decoding
1700
+ * buffers an incomplete trailing sequence and collapses a complete pair into one
1701
+ * character, so a string-domain match could only see a report late, consuming the
1702
+ * keystroke that follows it. A report split across reads holds the buffer for the
1703
+ * input burst, the same grace a lone Escape gets; a burst that elapses with an
1704
+ * incomplete prefix hands the bytes to the key parser as if they were typed. Inside a
1705
+ * bracketed paste the bytes are text, so once the decoded stream opens a paste the
1706
+ * remainder is handed over untouched.
1707
+ */
1708
+ consumeRaw() {
1709
+ while (this.rawIncoming.length) {
1710
+ const at = this.rawIncoming.indexOf(LEGACY_MOUSE);
1711
+ if (at > 0) {
1712
+ const head = this.rawIncoming.subarray(0, at);
1713
+ this.rawIncoming = this.rawIncoming.subarray(at);
1714
+ this.feedRaw(head);
1715
+ this.consumeIncoming();
1716
+ }
1717
+ if (at < 0)
1718
+ break;
1719
+ if (this.pasting) {
1720
+ // Only the paste body is text. Bytes after its terminator are framed again, so a
1721
+ // report that arrives in the same read as the end of a paste is still a report.
1722
+ const closes = this.rawIncoming.indexOf(PASTE_END);
1723
+ if (closes < 0) {
1724
+ this.feedRaw(this.rawIncoming);
1725
+ this.rawIncoming = Buffer.alloc(0);
1726
+ break;
1727
+ }
1728
+ const body = this.rawIncoming.subarray(0, closes + PASTE_END.length);
1729
+ this.rawIncoming = this.rawIncoming.subarray(closes + PASTE_END.length);
1730
+ this.feedRaw(body);
1731
+ this.consumeIncoming();
1732
+ continue;
1733
+ }
1734
+ if (this.rawIncoming.length < 6) {
1735
+ this.armRawTimer();
1736
+ return;
1737
+ }
1738
+ const button = this.rawIncoming[3] - 32, column = this.rawIncoming[4] - 32, row = this.rawIncoming[5] - 32;
1739
+ this.rawIncoming = this.rawIncoming.subarray(6);
1740
+ // The legacy encoding has no release flag: a release is reported as button 3.
1741
+ this.mouse(button, (button & 3) !== 3 || (button & 64) !== 0, column, row);
1742
+ }
1743
+ // Nothing report-shaped is pending: decode everything except a suffix that could
1744
+ // still grow into a report prefix, which waits for the next chunk or the burst.
1745
+ const hold = legacyMousePrefixLength(this.rawIncoming);
1746
+ if (this.rawIncoming.length > hold) {
1747
+ const head = this.rawIncoming.subarray(0, this.rawIncoming.length - hold);
1748
+ this.rawIncoming = this.rawIncoming.subarray(this.rawIncoming.length - hold);
1749
+ this.feedRaw(head);
1750
+ }
1751
+ if (this.rawIncoming.length)
1752
+ this.armRawTimer();
1753
+ }
1754
+ feedRaw(bytes) { if (bytes.length)
1755
+ this.incoming += this.decoder.write(bytes); }
1756
+ armRawTimer() {
1757
+ if (this.rawTimer || this.closed)
1758
+ return;
1759
+ // The burst has already done the lone-Escape disambiguation, so a flush that leaves
1760
+ // exactly an ESC resolves it as the Escape key. The surface that received the held
1761
+ // bytes is captured the way escapeTimer captures its own: if a load finished and
1762
+ // opened a modal during the window, the bytes die with the surface they belonged to
1763
+ // instead of closing or typing into the one that replaced it.
1764
+ const modal = this.modal, question = this.pending;
1765
+ this.rawTimer = setTimeout(() => {
1766
+ this.rawTimer = undefined;
1767
+ if (this.closed || this.modal !== modal || this.pending !== question) {
1768
+ this.rawIncoming = Buffer.alloc(0);
1769
+ return;
1770
+ }
1771
+ const held = this.rawIncoming;
1772
+ this.rawIncoming = Buffer.alloc(0);
1773
+ this.feedRaw(held);
1774
+ if (this.incoming === '\x1b') {
1775
+ this.incoming = '';
1776
+ this.onKey(undefined, { name: 'escape', sequence: '\x1b' });
1777
+ return;
1778
+ }
1779
+ this.consumeIncoming();
1780
+ }, INPUT_BURST_MS);
1781
+ }
1782
+ /** Drain the decoded stream: paste markers, SGR mouse reports and ordinary keys. */
1675
1783
  consumeIncoming() {
1676
1784
  const start = '\x1b[200~', end = '\x1b[201~';
1677
1785
  while (this.incoming) {
1678
1786
  const marker = this.pasting ? end : start;
1679
1787
  const found = this.incoming.indexOf(marker);
1788
+ const mouse = this.pasting ? -1 : this.incoming.indexOf('\x1b[<');
1789
+ if (mouse >= 0 && (found < 0 || mouse < found)) {
1790
+ const report = this.incoming.slice(mouse);
1791
+ const match = /^\x1b\[<(\d{1,5});(\d{1,5});(\d{1,5})([Mm])/.exec(report);
1792
+ if (match) {
1793
+ this.normalData(this.incoming.slice(0, mouse));
1794
+ this.incoming = report.slice(match[0].length);
1795
+ this.mouse(Number(match[1]), match[4] === 'M', Number(match[2]), Number(match[3]));
1796
+ continue;
1797
+ }
1798
+ if (/^\x1b\[<\d{0,5}(?:;\d{0,5}){0,2}$/.test(report)) {
1799
+ this.normalData(this.incoming.slice(0, mouse));
1800
+ this.incoming = report;
1801
+ break;
1802
+ }
1803
+ }
1680
1804
  if (found >= 0) {
1681
1805
  const before = this.incoming.slice(0, found);
1682
1806
  this.incoming = this.incoming.slice(found + marker.length);
@@ -1730,10 +1854,87 @@ export class TerminalUI extends EventEmitter {
1730
1854
  return false;
1731
1855
  return this.expandedTranscript;
1732
1856
  }
1857
+ /**
1858
+ * Act on one mouse report: the wheel scrolls, and a left drag selects text on the screen.
1859
+ *
1860
+ * The selection lives in screen cells over the frame as drawn. Releasing the button copies
1861
+ * it; the highlight stays until the next key, click or wheel tick so the reader can see what
1862
+ * was taken. A press and release on one cell selects nothing, and a second press on the same
1863
+ * cell within the double-click window takes the word under it. Other buttons are swallowed,
1864
+ * so no click reaches the composer as text.
1865
+ * @param button - the report's button code, modifiers and motion bit included.
1866
+ * @param pressed - false for a release.
1867
+ * @param column - 1-based screen column.
1868
+ * @param row - 1-based screen row.
1869
+ */
1870
+ mouse(button, pressed, column, row) {
1871
+ const base = button & ~28;
1872
+ if (base === 64 || base === 65) {
1873
+ if (!pressed)
1874
+ return;
1875
+ if (this.selection) {
1876
+ this.selection = undefined;
1877
+ this.scheduleRender();
1878
+ }
1879
+ this.scrollBy(base === 64 ? 1 : -1);
1880
+ return;
1881
+ }
1882
+ const which = base & 3, motion = (base & 32) !== 0;
1883
+ if (motion) {
1884
+ // A drag is not the first half of a double-click, even when it ends where it began.
1885
+ if (which === 0 && this.selection?.dragging) {
1886
+ this.selection.head = { row, column };
1887
+ this.lastPress = undefined;
1888
+ this.scheduleRender();
1889
+ }
1890
+ return;
1891
+ }
1892
+ if (pressed && which === 0) {
1893
+ const now = Date.now(), last = this.lastPress;
1894
+ const double = last !== undefined && last.row === row && last.column === column && now - last.at <= DOUBLE_CLICK_MS;
1895
+ this.lastPress = double ? undefined : { row, column, at: now };
1896
+ // A drag that starts in the chat column stays there, so the side panel is not copied with it.
1897
+ const chat = this.chatColumns(), limit = column <= chat ? chat : undefined;
1898
+ const word = double ? wordAt(this.frame, { row, column }) : undefined;
1899
+ this.selection = word ? { ...word, limit, dragging: false } : { anchor: { row, column }, head: { row, column }, limit, dragging: true };
1900
+ if (word)
1901
+ this.copyScreenSelection();
1902
+ this.scheduleRender();
1903
+ return;
1904
+ }
1905
+ if ((!pressed && which === 0) || which === 3) {
1906
+ const selection = this.selection;
1907
+ if (!selection?.dragging)
1908
+ return;
1909
+ // The release carries its own position: a fast drag can end past the last motion
1910
+ // report, or send no motion report at all.
1911
+ selection.head = { row, column };
1912
+ selection.dragging = false;
1913
+ if (emptySelection(selection))
1914
+ this.selection = undefined;
1915
+ else
1916
+ this.copyScreenSelection();
1917
+ this.scheduleRender();
1918
+ }
1919
+ }
1920
+ /** Copy the screen selection; over SSH only the terminal's clipboard is the reader's own. */
1921
+ copyScreenSelection() {
1922
+ if (!this.selection)
1923
+ return;
1924
+ const text = selectedText(this.frame, this.selection);
1925
+ if (text.trim())
1926
+ this.copyText(text, { terminalOnly: Boolean(process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) });
1927
+ }
1928
+ /** Lay the selection highlight over a composed frame. */
1929
+ withSelection(lines) {
1930
+ const selection = this.selection;
1931
+ if (!selection || emptySelection(selection))
1932
+ return lines;
1933
+ return lines.map((line, index) => { const span = selectedSpan(selection, index + 1); return span ? highlightRow(line, span[0], span[1]) : line; });
1934
+ }
1733
1935
  /**
1734
1936
  * Scroll the transcript (or the active screen). Positive `direction` scrolls up (toward
1735
- * older output), which is what an Up key means — typed, or sent by the wheel under
1736
- * alternate scroll mode.
1937
+ * older output), which is what a wheel-up report and an Up key during a run both mean.
1737
1938
  */
1738
1939
  scrollBy(direction) {
1739
1940
  if (this.modal) {
@@ -1944,7 +2145,7 @@ export class TerminalUI extends EventEmitter {
1944
2145
  }
1945
2146
  /** Take every queued attachment in draft order, without blocking — the CLI drains this when a task is submitted. */
1946
2147
  takeAttachments() { const queued = this.attachments.map(entry => entry.pending); this.attachments = []; this.scheduleRender(); return queued; }
1947
- /** The amber label a token draws as in the composer. */
2148
+ /** The bold label a token draws as in the composer. */
1948
2149
  tokenLabel({ seq, pending }) {
1949
2150
  if (pending.kind === 'text') {
1950
2151
  const lines = pending.content.split('\n').length;
@@ -2054,6 +2255,10 @@ export class TerminalUI extends EventEmitter {
2054
2255
  }
2055
2256
  clearDraft() { this.clipboardProbe += 1; this.value = []; this.cursor = 0; this.historyIndex = this.history.length; this.draft = ''; this.commandInput = false; this.completion = undefined; this.dismissedCompletion = undefined; this.attachments = []; this.scroll = 0; this.scheduleRender(); }
2056
2257
  onKey = (text, key) => {
2258
+ if (this.selection) {
2259
+ this.selection = undefined;
2260
+ this.scheduleRender();
2261
+ }
2057
2262
  if (key.ctrl && key.name === 'b' && !this.modal) {
2058
2263
  this.toggleDashboard();
2059
2264
  return;
@@ -2243,10 +2448,9 @@ export class TerminalUI extends EventEmitter {
2243
2448
  return;
2244
2449
  }
2245
2450
  // While no prompt is pending — a run streaming output — there is no history to
2246
- // navigate, so Up/Down scroll the transcript, alongside Page Up/Down. This is also the
2247
- // state in which alternate scroll mode is armed (`updateAlternateScroll`), so the wheel
2248
- // arrives here as Up/Down and scrolls too. Steering keeps the composer editable, so a
2249
- // draft rebinds the arrows to cursor movement inside it.
2451
+ // navigate, so Up/Down scroll the transcript, alongside Page Up/Down and the wheel.
2452
+ // Steering keeps the composer editable, so a draft rebinds the arrows to cursor movement
2453
+ // inside it.
2250
2454
  if ((key.name === 'up' || key.name === 'down') && !this.pending && (!this.steering || !this.value.length)) {
2251
2455
  this.scrollBy(key.name === 'up' ? 1 : -1);
2252
2456
  return;
@@ -2474,10 +2678,9 @@ export class TerminalUI extends EventEmitter {
2474
2678
  if (this.moveRow(direction))
2475
2679
  return;
2476
2680
  const historyAt = this.pending?.history ? Math.max(0, Math.min(this.history.length, this.historyIndex + direction)) : this.historyIndex;
2477
- // The wheel never reaches this method: alternate scroll mode is off whenever a question
2478
- // is pending (`updateAlternateScroll`), so the terminal sends nothing for it. Up/Down are
2479
- // therefore purely the keyboard — cursor movement above, history recall here — and never
2480
- // scroll, so there is no exhaustion heuristic reconciling the two gestures.
2681
+ // The wheel never reaches this method: the mouse is captured, so it arrives as a wheel
2682
+ // report (`mouse`) and never as arrow bytes. Up/Down are therefore purely the keyboard:
2683
+ // cursor movement above, history recall here.
2481
2684
  if (this.pending?.history) {
2482
2685
  if (this.historyIndex === this.history.length)
2483
2686
  this.draft = this.parkedDraft();
@@ -2676,7 +2879,9 @@ export class TerminalUI extends EventEmitter {
2676
2879
  * leaves the caret where it was still writes zero bytes, so the caret can ride along with
2677
2880
  * the frame without breaking the settled-frame contract.
2678
2881
  */
2679
- writeFrame(lines, cursor = '') {
2882
+ writeFrame(composed, cursor = '') {
2883
+ this.frame = composed;
2884
+ const lines = this.withSelection(composed);
2680
2885
  const size = `${this.output.columns || 80}x${this.output.rows || 24}`;
2681
2886
  const previous = this.drawnSize === size ? this.drawn : undefined;
2682
2887
  const rows = Math.max(lines.length, previous?.length ?? 0);
@@ -2742,13 +2947,13 @@ export class TerminalUI extends EventEmitter {
2742
2947
  clip(brand.at(-1), available),
2743
2948
  ...(viewportHeight >= 2 ? [clip(`● ${activity}`, available)] : []),
2744
2949
  ...(viewportHeight >= 3 ? [clip(`Workflow · ${graphName}`, available)] : []),
2745
- ...(status.graphNeedsOverride && viewportHeight >= 4 ? [paint(clip(OVERRIDE_HINT, available), STATUS.warn)] : []),
2950
+ ...(status.graphNeedsOverride && viewportHeight >= 4 ? [paint(clip(OVERRIDE_HINT, available), ATTENTION)] : []),
2746
2951
  ];
2747
2952
  return [
2748
2953
  '', ...brand, '',
2749
2954
  clip(`● ${activity}`, available),
2750
2955
  clip(`Workflow · ${graphName}${nodeCount}`, available),
2751
- ...(status.graphNeedsOverride ? [paint(clip(OVERRIDE_HINT, available), STATUS.warn)] : []),
2956
+ ...(status.graphNeedsOverride ? [paint(clip(OVERRIDE_HINT, available), ATTENTION)] : []),
2752
2957
  '',
2753
2958
  ...(viewportHeight >= 10 ? ['Describe a task to get started.'] : []),
2754
2959
  '',
@@ -2858,7 +3063,7 @@ export class TerminalUI extends EventEmitter {
2858
3063
  const yolo = this.status.permissions ? `Permissions: ${this.status.permissions}` : this.status.yolo ? 'Permissions: automatic approvals' : 'Permissions: ask before writes/shell';
2859
3064
  const footerWidth = width - 1;
2860
3065
  const labelWidth = Math.min(footerWidth, yolo.length + 2);
2861
- rows.push(paint(pad(yolo, labelWidth), this.status.yolo ? STATUS.warn : STATUS.ok) + paint(clip(this.activeModel().label, footerWidth - labelWidth)));
3066
+ rows.push(paint(pad(yolo, labelWidth), this.status.yolo ? ATTENTION : GRAY) + paint(clip(this.activeModel().label, footerWidth - labelWidth)));
2862
3067
  this.writeFrame(rows);
2863
3068
  }
2864
3069
  /**
@@ -2876,7 +3081,14 @@ export class TerminalUI extends EventEmitter {
2876
3081
  const color = isBrand ? WHITE : box ? GRAY : !diff && line.includes(this.appName) ? accentPaint() : transcriptColor(line);
2877
3082
  const allowance = Math.max(1, width - 4);
2878
3083
  const aligned = alignRight && stringWidth(line) <= allowance;
2879
- return wrap(line, allowance).map(text => ({ text: aligned && text ? ' '.repeat(allowance - stringWidth(text)) + text : text, color }));
3084
+ // A wrapped list item or indented line continues under its own text, not at the margin:
3085
+ // a list whose second rows start in column one reads as loose paragraphs.
3086
+ const lead = diff || box || isBrand || aligned ? undefined : /^\s*(?:(?:[•◦└]|\d{1,3}[.)])\s+)?/u.exec(line)?.[0];
3087
+ const hang = lead ? stringWidth(lead) : 0;
3088
+ const rows = lead && hang > 0 && hang <= allowance / 2 && stringWidth(line) > allowance
3089
+ ? wrap(line.slice(lead.length), allowance - hang).map((text, index) => (index ? ' '.repeat(hang) : lead) + text)
3090
+ : wrap(line, allowance);
3091
+ return rows.map(text => ({ text: aligned && text ? ' '.repeat(allowance - stringWidth(text)) + text : text, color }));
2880
3092
  });
2881
3093
  }
2882
3094
  transcriptRows(entry, width) {
@@ -2913,7 +3125,10 @@ export class TerminalUI extends EventEmitter {
2913
3125
  if (!this.started || this.closed)
2914
3126
  return;
2915
3127
  this.todoPageSize = 0;
2916
- const working = Boolean(this.status.activity && this.status.activity !== 'Ready' && this.status.activity !== 'Paused' && !this.pending && !this.modal);
3128
+ const working = Boolean(this.status.activity && this.status.activity !== 'Ready' && this.status.activity !== 'Paused' && !this.status.backgroundActivity && !this.pending && !this.modal); /* A run folds the Graph/branch row into the other two, so the composer and footer take five rows instead of seven. */
3129
+ const compactFooter = working || this.runActive;
3130
+ const footerRows = compactFooter ? 2 : 3;
3131
+ const fixedRows = 4 + footerRows;
2917
3132
  this.updateWorkingClock();
2918
3133
  const columns = Math.max(1, this.output.columns || 80), height = Math.max(1, this.output.rows || 24);
2919
3134
  // The token speed needs no refresh of its own: its reading is captured when a request
@@ -2989,11 +3204,11 @@ export class TerminalUI extends EventEmitter {
2989
3204
  const popupHeight = popupRows ? popupRows + 2 : 0; // The composer's own todo block stands down while the panel is drawn: the panel's Plan and
2990
3205
  // Progress sections carry the same list, and one plan should not be reported twice on the
2991
3206
  // same screen. The panel is the copy that survives a wide terminal.
2992
- const todoLines = this.dashboard || panelColumns ? [] : this.todoLines(Math.max(0, height - inputRows - 10 - popupHeight));
3207
+ const todoLines = this.dashboard || panelColumns ? [] : this.todoLines(Math.max(0, height - inputRows - fixedRows - 3 - popupHeight));
2993
3208
  const elapsed = this.workingElapsed + (this.workingSince === undefined ? 0 : Date.now() - this.workingSince);
2994
3209
  const seconds = Math.floor(elapsed / 1000);
2995
- const thinkingLines = this.dashboard ? [] : this.thinkingLines(width, seconds, this.thinkingActive ? Math.max(1, Math.min(THINKING_ROWS + 1, height - inputRows - 8 - popupHeight - todoLines.length)) : 0);
2996
- const transcriptHeight = height - inputRows - 8 - popupHeight - todoLines.length - Math.max(0, thinkingLines.length - 1);
3210
+ const thinkingLines = this.dashboard ? [] : this.thinkingLines(width, seconds, this.thinkingActive ? Math.max(1, Math.min(THINKING_ROWS + 1, height - inputRows - fixedRows - 1 - popupHeight - todoLines.length)) : 0);
3211
+ const transcriptHeight = height - inputRows - fixedRows - popupHeight - todoLines.length - thinkingLines.length;
2997
3212
  const prefix = [...(this.selectionCard(transcriptHeight) ?? this.welcome(width, transcriptHeight)), ...(this.transcript.diagnostics.omitted ? ['Some transcript entries are unavailable because session storage failed.'] : [])].flatMap(text => this.wrapTranscript(text, width));
2998
3213
  const page = this.transcript.window({ prefix, height: transcriptHeight, scroll: this.scroll,
2999
3214
  key: `${width}:${this.expandedTranscript}`, render: entry => this.transcriptRows(entry, width),
@@ -3014,13 +3229,15 @@ export class TerminalUI extends EventEmitter {
3014
3229
  const version = clip(`v${this.version}`, Math.floor(width / 3));
3015
3230
  const header = paint(pad(top, width - stringWidth(version)), DIM) + paint(version, FAINT);
3016
3231
  const label = choices ? this.pending?.choiceTitle || 'Choose an answer' : this.pending?.title ? this.pending.title : this.pending && !this.pending.regular ? 'Your approval' : this.pending?.conversationPrompt && this.value[0] === '/' ? 'Commands · Enter runs · Tab completes' : this.steering && status.activity && status.activity !== 'Ready' ? status.activity === 'Paused' ? 'Paused - Send direction to resume' : 'Steer this run · Enter to send' : '';
3232
+ const steerLabel = label === 'Steer this run · Enter to send';
3017
3233
  const borderLabel = label ? clip(` ${label} `, Math.max(0, width - 4)) : '';
3018
- const timestamp = seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
3234
+ const timestamp = formatHms(seconds);
3019
3235
  const progress = this.nodeProgress();
3020
- const workingLabel = clip(`Working · ${progress ? `${progress} - ` : ''}${timestamp}`, width - 2);
3236
+ const workingText = `Working · ${progress ? `${progress} - ` : ''}${timestamp}${label && !(steerLabel && !this.value.length) ? ` · ${steerLabel ? 'Enter to steer' : label}` : ''}`;
3237
+ const workingLabel = clip(workingText, Math.max(0, width - 6));
3021
3238
  const wave = Math.floor(elapsed / 120) % 11;
3022
- const workingLine = working ? ' ' + [...workingLabel].map((character, index) => paint(character, index < 7 && Math.abs(index - wave) <= 1 ? 255 : GRAY)).join('') : '';
3023
- const lines = [header, paint(clip(` ${status.account ? `Account: ${oneLine(status.account.label)} | ` : ''}${oneLine(this.workspace)}`, width), FAINT), ...visible.map(line => line.segments ? ' ' + line.segments.map(segment => paint(segment.text, segment.color ?? GRAY)).join('') : paint(' ' + clip(line.text, width - 2), line.color)), ...(thinkingLines.length ? thinkingLines.map(line => paint(' ' + pad(line, width - 4), GRAY)) : [workingLine]), ...todoLines.map(line => paint(' ' + clip(line, width - 2), GRAY))];
3239
+ const topBorder = working && workingLabel ? paint('╭ ', GRAY) + [...workingLabel].map((character, index) => paint(character, index < 7 && Math.abs(index - wave) <= 1 ? 255 : GRAY)).join('') + paint(' ' + '─'.repeat(Math.max(0, width - 4 - stringWidth(workingLabel))) + '╮', GRAY) : paint('╭' + borderLabel + '─'.repeat(Math.max(0, width - 2 - stringWidth(borderLabel))) + '╮', GRAY);
3240
+ const lines = [header, paint(clip(` ${status.account ? `Account: ${oneLine(status.account.label)} | ` : ''}${oneLine(this.workspace)}`, width), FAINT), ...visible.map(line => line.segments ? ' ' + line.segments.map(segment => paint(segment.text, segment.color ?? GRAY)).join('') : paint(' ' + clip(line.text, width - 2), line.color)), ...thinkingLines.map(line => paint(' ' + pad(line, width - 4), GRAY)), ...todoLines.map(line => paint(' ' + clip(line, width - 2), GRAY))];
3024
3241
  if (completion && popupRows) {
3025
3242
  const cardWidth = width - 4;
3026
3243
  const popupTitle = clip(' Commands · ↑↓ move · Enter runs · Tab completes ', cardWidth - 2);
@@ -3035,7 +3252,7 @@ export class TerminalUI extends EventEmitter {
3035
3252
  }
3036
3253
  lines.push(paint(' ╰' + '─'.repeat(cardWidth - 2) + '╯', GRAY));
3037
3254
  }
3038
- lines.push(paint('╭' + borderLabel + '─'.repeat(Math.max(0, width - 2 - stringWidth(borderLabel))) + '╮', GRAY));
3255
+ lines.push(topBorder);
3039
3256
  for (let index = 0; index < inputRows; index++) {
3040
3257
  if (choices) {
3041
3258
  const item = choices[firstInput + index], selected = firstInput + index === choiceIndex;
@@ -3044,7 +3261,7 @@ export class TerminalUI extends EventEmitter {
3044
3261
  continue;
3045
3262
  }
3046
3263
  const value = layout.lines[firstInput + index];
3047
- const placeholder = !this.value.length && this.pending ? this.pending.regular ? this.pending.label || 'Describe a task… / for commands' : 'Type y to approve, or n to decline' : !this.value.length ? status.activity && status.activity !== 'Ready' ? this.steering ? status.activity === 'Paused' ? 'Paused - Send direction to resume, Ctrl+C again to exit' : 'Steer this run with a message… (Ctrl+C to pause)' : 'Ctrl+C to stop' : 'Ready for your next task' : '';
3264
+ const placeholder = !this.value.length && this.pending ? this.pending.regular ? this.pending.label || 'Describe a task… / for commands' : 'Type y to approve, or n to decline' : !this.value.length ? status.activity && status.activity !== 'Ready' ? this.steering ? status.activity === 'Paused' ? 'Paused - Send direction to resume, Ctrl+C again to exit' : 'Steer this run with a message… (Ctrl+C to pause)' : status.backgroundActivity ? `${oneLine(status.activity)}…` : 'Ctrl+C to stop' : 'Ready for your next task' : '';
3048
3265
  const span = value && selection ? selectedColumns(visibleValue, layout.positions, selection, firstInput + index) : undefined;
3049
3266
  const tokens = value ? tokenColumns(this.value, visibleValue, layout.positions, firstInput + index) : [];
3050
3267
  lines.push(paint('│ ', GRAY) + (span || tokens.length ? composerRow(pad(value, width - 4), DIM, span, tokens) : paint(pad(value || placeholder, width - 4), value ? DIM : FAINT)) + paint(' │', GRAY));
@@ -3059,7 +3276,8 @@ export class TerminalUI extends EventEmitter {
3059
3276
  const jevWidth = Math.min(stringWidth(jev), width - 1);
3060
3277
  lines.push(paint(pad(model, Math.max(0, width - jevWidth - 2)) + (width - jevWidth > 1 ? ' ' : '') + clip(jev, jevWidth), GRAY));
3061
3278
  const graph = oneLine(`Graph: ${(status.graphSelection ?? (status.graph?.id === 'software-engineer' ? 'default' : status.graph?.id)) === 'default' ? 'Default' : status.graph?.name ?? 'Not selected'}${status.codeIntel ? ` · CodeGraph: ${status.codeIntel}` : ''}`);
3062
- lines.push(paint(pad(graph, width - branchWidth) + clip(`⎇ ${branch}`, branchWidth), GRAY));
3279
+ if (!compactFooter)
3280
+ lines.push(paint(pad(graph, width - branchWidth) + clip(`⎇ ${branch}`, branchWidth), GRAY));
3063
3281
  const count = (value) => Number.isFinite(value) && value >= 0 ? value : 0;
3064
3282
  const compactTokens = Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 1 });
3065
3283
  const activeWindow = active.contextWindow;
@@ -3076,8 +3294,10 @@ export class TerminalUI extends EventEmitter {
3076
3294
  const measured = rate > 0 ? ` · ${compactTokens.format(rate)} tok/s` : '';
3077
3295
  const counts = `${count(status.requests)} req · ${count(status.inputTokens)} in · ${count(status.outputTokens)} out`;
3078
3296
  const usage = `${counts}${measured}${context}`;
3079
- const approval = status.permissions ? `Permissions: ${status.permissions}` : status.yolo ? 'Permissions: automatic approvals' : 'Permissions: ask before writes/shell';
3297
+ const permission = status.permissions ?? (status.yolo ? 'automatic approvals' : 'ask before writes/shell');
3298
+ const approval = compactFooter ? `${graph} · ${permission}` : `Permissions: ${permission}`;
3080
3299
  const footerWidth = width - 1;
3300
+ const branchLead = compactFooter ? `⎇ ${branch} · ` : '';
3081
3301
  // Under width pressure the optional tail is dropped first - the context segment, as
3082
3302
  // documented. But the cumulative counts are unbounded and can spend the whole allowance
3083
3303
  // before the speed segment even starts, clipping it mid-word (`1K to`). While a speed is
@@ -3089,7 +3309,11 @@ export class TerminalUI extends EventEmitter {
3089
3309
  const usageCap = Math.floor(footerWidth * 0.6);
3090
3310
  let usageText = usage;
3091
3311
  let usageWidth;
3092
- if (stringWidth(approval) + 1 + stringWidth(usage) <= footerWidth)
3312
+ if (branchLead && stringWidth(approval) + 1 + stringWidth(branchLead + usage) <= footerWidth) {
3313
+ usageText = branchLead + usage;
3314
+ usageWidth = stringWidth(usageText);
3315
+ }
3316
+ else if (stringWidth(approval) + 1 + stringWidth(usage) <= footerWidth)
3093
3317
  usageWidth = stringWidth(usage);
3094
3318
  else if (measured) {
3095
3319
  usageText = [`${counts}${measured}`, `${compactCounts}${measured}`].find(candidate => stringWidth(candidate) <= usageCap) ?? compactCounts;
@@ -3097,14 +3321,25 @@ export class TerminalUI extends EventEmitter {
3097
3321
  }
3098
3322
  else
3099
3323
  usageWidth = Math.min(stringWidth(usage), usageCap);
3100
- lines.push(paint(clip(pad(approval, footerWidth - usageWidth), footerWidth - usageWidth), status.yolo ? STATUS.warn : STATUS.ok) + paint(clip(usageText, usageWidth), WHITE));
3324
+ // On the compact row the graph name outranks the usage readout: it lost its own row, and the
3325
+ // counts are also in the side panel and the dashboard.
3326
+ if (compactFooter) {
3327
+ usageWidth = Math.max(0, Math.min(usageWidth, footerWidth - stringWidth(`${graph} · `)));
3328
+ if (stringWidth(usageText) > usageWidth && branchLead && usageText.startsWith(branchLead))
3329
+ usageText = usageText.slice(branchLead.length);
3330
+ }
3331
+ const approvalWidth = footerWidth - usageWidth;
3332
+ const leadText = compactFooter ? clip(`${graph} · `, approvalWidth) : '';
3333
+ const restWidth = approvalWidth - stringWidth(leadText);
3334
+ const usagePart = branchLead && usageText.startsWith(branchLead) ? paint(branchLead, GRAY) + paint(usageText.slice(branchLead.length), WHITE) : paint(clip(usageText, usageWidth), WHITE);
3335
+ lines.push((leadText ? paint(leadText, GRAY) : '') + paint(clip(pad(compactFooter ? permission : approval, restWidth), restWidth), status.yolo ? ATTENTION : GRAY) + usagePart);
3101
3336
  // The caret travels through the same diff as the rows: writing it straight to the output
3102
3337
  // would put an absolute cursor move and a show-cursor sequence on the wire every 120 ms
3103
3338
  // for the whole of an interactive run (cli.ts keeps steering on), and terminals that clear
3104
3339
  // or move a selection on cursor traffic would lose a drag over an otherwise untouched
3105
3340
  // frame. As a frame input it is suppressed whenever nothing was painted and the caret has
3106
3341
  // not moved, and re-emitted whenever a row repaint hid it.
3107
- const caret = (this.pending || this.steering) && !choices ? `\x1b[${transcriptHeight + todoLines.length + popupHeight + Math.max(0, thinkingLines.length - 1) + 5 + cursor.row - firstInput};${3 + cursor.column}H\x1b[?25h` : '';
3342
+ const caret = (this.pending || this.steering) && !choices ? `\x1b[${transcriptHeight + todoLines.length + popupHeight + thinkingLines.length + 4 + cursor.row - firstInput};${3 + cursor.column}H\x1b[?25h` : '';
3108
3343
  this.writeFrame(this.composePanel(lines, this.panelRows(panelColumns, height), panelColumns, width), caret);
3109
3344
  }
3110
3345
  }