@andorra-labs/code 0.1.9 → 0.1.11

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 (212) hide show
  1. package/README.md +28 -208
  2. package/THIRD_PARTY_NOTICES.md +15 -0
  3. package/dist/src/agent-execution.js +56 -0
  4. package/dist/src/app-server/protocol.d.ts +109 -1
  5. package/dist/src/app-server/protocol.js +8 -1
  6. package/dist/src/app-server.d.ts +59 -1
  7. package/dist/src/app-server.js +418 -63
  8. package/dist/src/auth/index.d.ts +1 -1
  9. package/dist/src/auth/index.js +1 -1
  10. package/dist/src/auth/store.d.ts +17 -1
  11. package/dist/src/auth/store.js +25 -2
  12. package/dist/src/automation-service.js +1 -1
  13. package/dist/src/browser-session.d.ts +8 -0
  14. package/dist/src/browser-session.js +27 -1
  15. package/dist/src/browser-ui/app.js +255 -33
  16. package/dist/src/browser-ui/index.html +9 -9
  17. package/dist/src/browser-ui/style.css +110 -65
  18. package/dist/src/browser-ui/tokens.css +27 -26
  19. package/dist/src/cli.js +10 -5
  20. package/dist/src/coding-tools.d.ts +24 -0
  21. package/dist/src/coding-tools.js +71 -8
  22. package/dist/src/command-screens.js +1 -1
  23. package/dist/src/commands.d.ts +1 -1
  24. package/dist/src/commands.js +2 -2
  25. package/dist/src/completion-gates.d.ts +42 -7
  26. package/dist/src/completion-gates.js +55 -9
  27. package/dist/src/completion.d.ts +9 -1
  28. package/dist/src/completion.js +20 -2
  29. package/dist/src/dashboard-view.js +2 -2
  30. package/dist/src/deadline.js +4 -0
  31. package/dist/src/decision/checks.js +1 -1
  32. package/dist/src/file-diff.d.ts +105 -0
  33. package/dist/src/file-diff.js +244 -0
  34. package/dist/src/graph-manager-chat.js +4 -4
  35. package/dist/src/graph-runner.js +39 -2
  36. package/dist/src/graph-sync.d.ts +8 -0
  37. package/dist/src/graph-sync.js +54 -3
  38. package/dist/src/graph-tool.js +1 -1
  39. package/dist/src/graph-ui/app.js +303 -129
  40. package/dist/src/graph-ui/controls.css +43 -22
  41. package/dist/src/graph-ui/controls.js +31 -1
  42. package/dist/src/graph-ui/embed.js +56 -7
  43. package/dist/src/graph-ui/icons.js +5 -0
  44. package/dist/src/graph-ui/index.html +3 -3
  45. package/dist/src/graph-ui/manager-state.js +2 -2
  46. package/dist/src/graph-ui/manager.css +19 -18
  47. package/dist/src/graph-ui/manager.js +5 -5
  48. package/dist/src/graph-ui/skill-picker.js +5 -5
  49. package/dist/src/graph-ui/studio-canvas.js +16 -16
  50. package/dist/src/graph-ui/studio.css +18 -15
  51. package/dist/src/graph-ui/studio.js +99 -42
  52. package/dist/src/graph-ui/style.css +125 -80
  53. package/dist/src/graph-ui/theme.js +2 -2
  54. package/dist/src/graph-ui/tokens.css +33 -29
  55. package/dist/src/graphs.d.ts +10 -3
  56. package/dist/src/graphs.js +15 -4
  57. package/dist/src/mcp.d.ts +75 -0
  58. package/dist/src/mcp.js +240 -8
  59. package/dist/src/membership-errors.d.ts +7 -1
  60. package/dist/src/membership-errors.js +9 -3
  61. package/dist/src/provider-keys.d.ts +5 -1
  62. package/dist/src/provider-keys.js +7 -3
  63. package/dist/src/provider-settings.d.ts +4 -1
  64. package/dist/src/provider-settings.js +46 -5
  65. package/dist/src/pull-requests.d.ts +42 -6
  66. package/dist/src/pull-requests.js +11 -3
  67. package/dist/src/qa/guidance.js +6 -19
  68. package/dist/src/qa/index.d.ts +0 -2
  69. package/dist/src/qa/index.js +0 -2
  70. package/dist/src/qa/profile/QaProfile.d.ts +5 -1
  71. package/dist/src/qa/profile/QaProfile.js +6 -2
  72. package/dist/src/qa/tools.d.ts +19 -1
  73. package/dist/src/qa/tools.js +20 -145
  74. package/dist/src/react-runtime.js +134 -16
  75. package/dist/src/read-document-doc.d.ts +20 -0
  76. package/dist/src/read-document-doc.js +524 -0
  77. package/dist/src/read-document-docx.d.ts +21 -0
  78. package/dist/src/read-document-docx.js +584 -0
  79. package/dist/src/read-document-text.d.ts +29 -0
  80. package/dist/src/read-document-text.js +67 -0
  81. package/dist/src/read-document-tool.d.ts +48 -0
  82. package/dist/src/read-document-tool.js +162 -0
  83. package/dist/src/read-document.d.ts +78 -0
  84. package/dist/src/read-document.js +353 -0
  85. package/dist/src/read-image.d.ts +29 -2
  86. package/dist/src/read-image.js +42 -17
  87. package/dist/src/remote/engine-pool.js +18 -6
  88. package/dist/src/runtime.d.ts +19 -0
  89. package/dist/src/runtime.js +10 -1
  90. package/dist/src/screen-selection.d.ts +38 -0
  91. package/dist/src/screen-selection.js +103 -0
  92. package/dist/src/session-changes.d.ts +122 -0
  93. package/dist/src/session-changes.js +804 -0
  94. package/dist/src/side-panel.d.ts +6 -1
  95. package/dist/src/side-panel.js +12 -10
  96. package/dist/src/skills/bundled/create-skill/SKILL.md +1 -1
  97. package/dist/src/skills/bundled/diagram/SKILL.md +1 -1
  98. package/dist/src/skills/bundled/graph-manager/SKILL.md +37 -3
  99. package/dist/src/skills/bundled/graph-manager/patterns.md +27 -0
  100. package/dist/src/skills/bundled/provenance.json +4 -4
  101. package/dist/src/skills/runtime-skills.js +3 -3
  102. package/dist/src/stall-recovery.d.ts +15 -0
  103. package/dist/src/stall-recovery.js +17 -0
  104. package/dist/src/telemetry/schema.d.ts +1 -1
  105. package/dist/src/telemetry/schema.js +1 -2
  106. package/dist/src/terminal-ui.d.ts +64 -20
  107. package/dist/src/terminal-ui.js +312 -82
  108. package/dist/src/time-limit.d.ts +53 -0
  109. package/dist/src/time-limit.js +79 -0
  110. package/dist/src/tool-diff-stats.d.ts +9 -0
  111. package/dist/src/tool-diff-stats.js +20 -0
  112. package/dist/src/tool-names.d.ts +1 -1
  113. package/dist/src/tool-result-filter.js +1 -1
  114. package/dist/src/tools.js +118 -9
  115. package/dist/src/transcript.d.ts +11 -0
  116. package/dist/src/transcript.js +15 -3
  117. package/dist/src/types.d.ts +12 -0
  118. package/dist/src/usage-analytics.d.ts +3 -1
  119. package/dist/src/usage-analytics.js +16 -2
  120. package/package.json +6 -26
  121. package/dist/src/qa/api/http-runner.d.ts +0 -3
  122. package/dist/src/qa/api/http-runner.js +0 -47
  123. package/dist/src/qa/git/ChangeDetector.d.ts +0 -26
  124. package/dist/src/qa/git/ChangeDetector.js +0 -177
  125. package/dist/src/qa/git/DiffReviewer.d.ts +0 -28
  126. package/dist/src/qa/git/DiffReviewer.js +0 -115
  127. package/dist/src/qa/orchestrator/ChangeClassifier.d.ts +0 -14
  128. package/dist/src/qa/orchestrator/ChangeClassifier.js +0 -28
  129. package/dist/src/qa/orchestrator/MergeGate.d.ts +0 -14
  130. package/dist/src/qa/orchestrator/MergeGate.js +0 -40
  131. package/dist/src/qa/orchestrator/QaOrchestrator.d.ts +0 -79
  132. package/dist/src/qa/orchestrator/QaOrchestrator.js +0 -373
  133. package/dist/src/qa/runners/CommandRunner.d.ts +0 -22
  134. package/dist/src/qa/runners/CommandRunner.js +0 -96
  135. package/dist/src/qa/runners/TestRunner.d.ts +0 -21
  136. package/dist/src/qa/runners/TestRunner.js +0 -66
  137. package/dist/src/qa/runtime/RuntimeSmoke.d.ts +0 -11
  138. package/dist/src/qa/runtime/RuntimeSmoke.js +0 -78
  139. package/dist/src/qa/runtime-detect.d.ts +0 -10
  140. package/dist/src/qa/runtime-detect.js +0 -72
  141. package/dist/src/qa/security/DependencyScanner.d.ts +0 -19
  142. package/dist/src/qa/security/DependencyScanner.js +0 -167
  143. package/dist/src/qa/security/SecretScanner.d.ts +0 -3
  144. package/dist/src/qa/security/SecretScanner.js +0 -55
  145. package/docs/README.md +0 -36
  146. package/docs/agents/README.md +0 -62
  147. package/docs/agents/install-for-agents.md +0 -56
  148. package/docs/agents/mcp-server.md +0 -212
  149. package/docs/agents/subagent-mode.md +0 -149
  150. package/docs/concepts/README.md +0 -47
  151. package/docs/concepts/jev-actionable-routing.md +0 -113
  152. package/docs/concepts/jev-decision-thresholds.md +0 -412
  153. package/docs/concepts/jev-efficiency.md +0 -217
  154. package/docs/concepts/jev-eval-2026-11-01.md +0 -78
  155. package/docs/concepts/limits.md +0 -52
  156. package/docs/concepts/memory.md +0 -10
  157. package/docs/concepts/security.md +0 -50
  158. package/docs/concepts/workspace-instructions.md +0 -29
  159. package/docs/getting-started/README.md +0 -82
  160. package/docs/getting-started/accounts.md +0 -78
  161. package/docs/getting-started/configure-providers.md +0 -132
  162. package/docs/guides/README.md +0 -13
  163. package/docs/guides/browser.md +0 -39
  164. package/docs/guides/desktop-app.md +0 -414
  165. package/docs/guides/extensions.md +0 -102
  166. package/docs/guides/graph-builder.md +0 -116
  167. package/docs/guides/headless.md +0 -46
  168. package/docs/guides/tui.md +0 -75
  169. package/docs/guides/update.md +0 -70
  170. package/docs/guides/web-search.md +0 -51
  171. package/docs/guides/windows-code-signing.md +0 -319
  172. package/docs/llms.txt +0 -45
  173. package/docs/reference/README.md +0 -7
  174. package/docs/reference/cli.md +0 -76
  175. package/docs/reference/config.md +0 -91
  176. package/docs/reference/slash-commands.md +0 -59
  177. package/docs/superpowers/plans/2026-11-01-claude-console-sign-in.md +0 -111
  178. package/docs/superpowers/plans/2026-11-01-jev-node-opt-in.md +0 -910
  179. package/docs/superpowers/plans/2026-11-02-workflow-pane.md +0 -398
  180. package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +0 -125
  181. package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +0 -295
  182. package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +0 -203
  183. package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +0 -79
  184. package/docs/superpowers/specs/2026-10-31-work-line-summary-design.md +0 -50
  185. package/docs/superpowers/specs/2026-11-01-claude-console-sign-in-design.md +0 -176
  186. package/docs/superpowers/specs/2026-11-01-jev-node-opt-in-design.md +0 -164
  187. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +0 -111
  188. package/docs/superpowers/specs/2026-11-02-workflow-pane-design.md +0 -130
  189. package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +0 -206
  190. package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +0 -291
  191. package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +0 -182
  192. package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +0 -156
  193. package/scripts/jev-efficiency-eval.mjs +0 -187
  194. package/scripts/jev-efficiency-live.mjs +0 -193
  195. package/scripts/zcode-engine-replay.mjs +0 -223
  196. package/tests/agent-centric-mcp-test-plan.md +0 -208
  197. package/tests/analytics-settings-test-plan.md +0 -165
  198. package/tests/browser-cli-smoke.mjs +0 -276
  199. package/tests/browser-test-plan.md +0 -280
  200. package/tests/chat-side-panel-test-plan.md +0 -309
  201. package/tests/decision-engine-test-plan.md +0 -163
  202. package/tests/default-active-jev-test-plan.md +0 -85
  203. package/tests/harness-extensions-test-plan.md +0 -113
  204. package/tests/jev-all-decisions-test-plan.md +0 -156
  205. package/tests/jev-efficiency/criteria.json +0 -158
  206. package/tests/jev-efficiency/workloads.mjs +0 -242
  207. package/tests/jev-efficiency-test-plan.md +0 -198
  208. package/tests/permissions-sandbox-probe.mjs +0 -74
  209. package/tests/permissions-test-plan.md +0 -191
  210. package/tests/product-telemetry-test-plan.md +0 -536
  211. package/tests/thinking-stream-preview-test-plan.md +0 -136
  212. package/tests/zcode-react-engine-test-plan.md +0 -396
@@ -10,6 +10,7 @@ import { transcriptColor } from './transcript.js';
10
10
  import { ToolCallClock, toolHeaderRows } from './tool-call-clock.js';
11
11
  import { formatDuration, formatHms } from './duration.js';
12
12
  import { PagedTranscript } from './paged-transcript.js';
13
+ import { emptySelection, highlightRow, selectedSpan, selectedText, wordAt } from './screen-selection.js';
13
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';
@@ -144,6 +145,19 @@ const MAX_INPUT = 65_536;
144
145
  */
145
146
  const PASTE_ACCUMULATE_LIMIT = 1_048_576;
146
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
+ };
147
161
  /** Rows an echoed prompt may occupy before the tail is replaced by an omission marker. */
148
162
  const MAX_PROMPT_ROWS = 200;
149
163
  /** Long submitted prompts collapse in chat history until the user expands them with Ctrl+O. */
@@ -376,9 +390,9 @@ export class TerminalUI extends EventEmitter {
376
390
  nodeModels = new Map();
377
391
  toggleDashboard() { this.dashboard = !this.dashboard; this.scroll = 0; this.scheduleRender(); }
378
392
  /** Start of a run: open the dashboard's run window. */
379
- 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(); }
380
394
  /** End of a run: close the dashboard's run window. */
381
- finishTask() { this.runActive = false; this.updateAlternateScroll(); this.dashboardMetrics.finishTask(); this.scheduleRender(); }
395
+ finishTask() { this.runActive = false; this.dashboardMetrics.finishTask(); this.scheduleRender(); }
382
396
  resetDashboardSession(usage) { this.dashboardMetrics.resetSession(usage); this.dashboardModel = 0; this.dashboardGraphOffset = 0; this.nodeModels.clear(); this.dashboardNotices = []; this.scheduleRender(); }
383
397
  /** Clock backing the per-node speed meters; see {@link TerminalOptions.tokenClock}. */
384
398
  tokenClock;
@@ -761,19 +775,20 @@ export class TerminalUI extends EventEmitter {
761
775
  todoOffset = 0;
762
776
  todoPageSize = 0;
763
777
  scroll = 0;
764
- /** Whether a run is streaming: with no prompt pending, the wheel may scroll the transcript. */
778
+ /** Whether a run is streaming. */
765
779
  runActive = false;
766
780
  /**
767
- * Whether alternate scroll mode (?1007) is currently armed.
781
+ * The drag selection over the drawn frame, in screen cells.
768
782
  *
769
- * The app never takes mouse reporting, so the terminal keeps drag-to-select and its
770
- * clipboard in every state. In the alternate screen a terminal instead turns the wheel
771
- * into Up/Down sequences when alternate scroll is on — byte-identical to the arrow keys,
772
- * and on by default in Windows Terminal, VTE and iTerm2 — so the app arms that mode only
773
- * where Up/Down cannot recall history: while a screen is open, or while a run streams with
774
- * 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.
775
786
  */
776
- 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 = [];
777
792
  /**
778
793
  * Live reasoning preview state. `thinkingActive` marks a stream in progress; the text
779
794
  * is the bounded tail the preview renders from.
@@ -808,6 +823,17 @@ export class TerminalUI extends EventEmitter {
808
823
  completion;
809
824
  dismissedCompletion;
810
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;
811
837
  pasting = false;
812
838
  paste = '';
813
839
  pasteQuestion;
@@ -942,27 +968,29 @@ export class TerminalUI extends EventEmitter {
942
968
  this.input.on('end', this.onEnd);
943
969
  this.output.on('resize', this.onResize);
944
970
  this.input.resume();
945
- // The app never takes mouse reporting (?1000h/?1006h): the terminal keeps its own
946
- // drag-to-select and clipboard in every state, at rest and while a run streams alike, with
947
- // no modifier bypass to learn. What the wheel does is governed by alternate scroll mode
948
- // (?1007) instead. In the alternate screen a terminal with that mode on turns the wheel
949
- // into Up/Down sequences byte-identical to the arrow keys, and Windows Terminal, VTE and
950
- // iTerm2 have it on by default — which is how an uncaptured wheel once recalled the
951
- // previous prompt. The mode is therefore switched off explicitly here, and
952
- // `updateAlternateScroll` arms it only where Up/Down cannot reach history: while a
953
- // screen is open (its keys scroll or move the highlight) or while a run streams with no
954
- // question pending (Up/Down scroll the transcript, see onKey). At the resting prompt the
955
- // wheel is inert and Up/Down stay purely keyboard: input history, or cursor movement in a
956
- // draft. The collapsed long-prompt boxes open with Ctrl+O and the live reasoning preview
957
- // toggles with Ctrl+Y; neither needs a click. writeFrame only rewrites rows that changed,
958
- // so the working animation does not repaint cells under a drag selection either. Entering
959
- // 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.
960
984
  this.drawn = [];
961
985
  this.drawnSize = '';
962
986
  this.drawnCursor = '';
963
- this.output.write('\x1b[?1049h\x1b[?2004h\x1b[?25l\x1b[?1007l');
964
- this.alternateScroll = false;
965
- 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');
966
994
  this.render();
967
995
  }
968
996
  question(prompt = '', options = {}) {
@@ -996,7 +1024,6 @@ export class TerminalUI extends EventEmitter {
996
1024
  pending.abort = () => { if (this.pending !== pending)
997
1025
  return; this.finishQuestion(); reject(new DOMException('Question aborted', 'AbortError')); this.scheduleRender(); };
998
1026
  this.pending = pending;
999
- this.updateAlternateScroll();
1000
1027
  this.updateWorkingClock();
1001
1028
  pending.signal?.addEventListener('abort', pending.abort, { once: true });
1002
1029
  this.scheduleRender();
@@ -1078,7 +1105,6 @@ export class TerminalUI extends EventEmitter {
1078
1105
  modal.abort = () => { if (this.modal === modal)
1079
1106
  this.finishModal(undefined, new DOMException('Screen aborted', 'AbortError')); };
1080
1107
  this.modal = modal;
1081
- this.updateAlternateScroll();
1082
1108
  this.updateWorkingClock();
1083
1109
  modal.signal?.addEventListener('abort', modal.abort, { once: true });
1084
1110
  this.scheduleRender();
@@ -1089,7 +1115,6 @@ export class TerminalUI extends EventEmitter {
1089
1115
  if (!modal)
1090
1116
  return;
1091
1117
  this.modal = undefined;
1092
- this.updateAlternateScroll();
1093
1118
  // Only a selection that was actually made is worth docking: a cancelled list leads to no
1094
1119
  // field, and the caller returns to the conversation instead.
1095
1120
  if (modal.kind === 'select' && !error && typeof value === 'string')
@@ -1284,7 +1309,7 @@ export class TerminalUI extends EventEmitter {
1284
1309
  this.visitedNodes.clear();
1285
1310
  this.stoppedNode = undefined;
1286
1311
  }
1287
- this.status = { ...this.status, ...partial };
1312
+ this.status = { ...this.status, ...partial, ...(partial.activity !== undefined && partial.backgroundActivity === undefined ? { backgroundActivity: false } : {}) };
1288
1313
  // A run ending returns the footer to idle but does not retire the speed readout: each
1289
1314
  // node's cumulative average keeps describing the node that just ran, and it is the
1290
1315
  // baseline the next run of that node continues from.
@@ -1572,7 +1597,7 @@ export class TerminalUI extends EventEmitter {
1572
1597
  return '';
1573
1598
  }
1574
1599
  updateWorkingClock() {
1575
- if (!this.status.activity || this.status.activity === 'Ready') {
1600
+ if (!this.status.activity || this.status.activity === 'Ready' || this.status.backgroundActivity) {
1576
1601
  this.workingSince = undefined;
1577
1602
  this.workingElapsed = 0;
1578
1603
  }
@@ -1584,22 +1609,6 @@ export class TerminalUI extends EventEmitter {
1584
1609
  else
1585
1610
  this.workingSince ??= Date.now();
1586
1611
  }
1587
- /**
1588
- * Recompute whether the wheel may act: alternate scroll mode is armed while a screen is
1589
- * open, or while a run streams with no question pending, and off everywhere else.
1590
- *
1591
- * Only transitions write anything. Entering the alternate screen resets the flag first
1592
- * (`start`), because that screen begins with the mode explicitly switched off.
1593
- */
1594
- updateAlternateScroll() {
1595
- const armed = Boolean(this.modal) || (this.runActive && !this.pending);
1596
- if (armed === this.alternateScroll)
1597
- return;
1598
- this.alternateScroll = armed;
1599
- if (!this.started || this.closed)
1600
- return;
1601
- this.output.write(armed ? '\x1b[?1007h' : '\x1b[?1007l');
1602
- }
1603
1612
  close() {
1604
1613
  this.transcript.close();
1605
1614
  this.toolClock.stop();
@@ -1621,6 +1630,9 @@ export class TerminalUI extends EventEmitter {
1621
1630
  this.workingTimer = undefined;
1622
1631
  if (this.escapeTimer)
1623
1632
  clearTimeout(this.escapeTimer);
1633
+ if (this.rawTimer)
1634
+ clearTimeout(this.rawTimer);
1635
+ this.rawTimer = undefined;
1624
1636
  this.finishModal(undefined, new DOMException('Terminal closed', 'AbortError'));
1625
1637
  const pending = this.pending;
1626
1638
  this.finishQuestion();
@@ -1639,7 +1651,7 @@ export class TerminalUI extends EventEmitter {
1639
1651
  this.input.pause();
1640
1652
  this.input.unref?.();
1641
1653
  }
1642
- 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');
1643
1655
  }
1644
1656
  }
1645
1657
  this.emit('close');
@@ -1650,7 +1662,6 @@ export class TerminalUI extends EventEmitter {
1650
1662
  if (this.pending?.abort)
1651
1663
  this.pending.signal?.removeEventListener('abort', this.pending.abort);
1652
1664
  this.pending = undefined;
1653
- this.updateAlternateScroll();
1654
1665
  this.updateWorkingClock();
1655
1666
  this.value = [];
1656
1667
  this.cursor = 0;
@@ -1672,16 +1683,124 @@ export class TerminalUI extends EventEmitter {
1672
1683
  if (this.escapeTimer)
1673
1684
  clearTimeout(this.escapeTimer);
1674
1685
  this.escapeTimer = undefined;
1686
+ if (this.rawTimer)
1687
+ clearTimeout(this.rawTimer);
1688
+ this.rawTimer = undefined;
1675
1689
  this.modalInput = !!this.modal;
1676
- 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();
1677
1692
  this.consumeIncoming();
1678
1693
  };
1679
- /** 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. */
1680
1783
  consumeIncoming() {
1681
1784
  const start = '\x1b[200~', end = '\x1b[201~';
1682
1785
  while (this.incoming) {
1683
1786
  const marker = this.pasting ? end : start;
1684
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
+ }
1685
1804
  if (found >= 0) {
1686
1805
  const before = this.incoming.slice(0, found);
1687
1806
  this.incoming = this.incoming.slice(found + marker.length);
@@ -1735,10 +1854,87 @@ export class TerminalUI extends EventEmitter {
1735
1854
  return false;
1736
1855
  return this.expandedTranscript;
1737
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
+ }
1738
1935
  /**
1739
1936
  * Scroll the transcript (or the active screen). Positive `direction` scrolls up (toward
1740
- * older output), which is what an Up key means — typed, or sent by the wheel under
1741
- * alternate scroll mode.
1937
+ * older output), which is what a wheel-up report and an Up key during a run both mean.
1742
1938
  */
1743
1939
  scrollBy(direction) {
1744
1940
  if (this.modal) {
@@ -2059,6 +2255,10 @@ export class TerminalUI extends EventEmitter {
2059
2255
  }
2060
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(); }
2061
2257
  onKey = (text, key) => {
2258
+ if (this.selection) {
2259
+ this.selection = undefined;
2260
+ this.scheduleRender();
2261
+ }
2062
2262
  if (key.ctrl && key.name === 'b' && !this.modal) {
2063
2263
  this.toggleDashboard();
2064
2264
  return;
@@ -2248,10 +2448,9 @@ export class TerminalUI extends EventEmitter {
2248
2448
  return;
2249
2449
  }
2250
2450
  // While no prompt is pending — a run streaming output — there is no history to
2251
- // navigate, so Up/Down scroll the transcript, alongside Page Up/Down. This is also the
2252
- // state in which alternate scroll mode is armed (`updateAlternateScroll`), so the wheel
2253
- // arrives here as Up/Down and scrolls too. Steering keeps the composer editable, so a
2254
- // 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.
2255
2454
  if ((key.name === 'up' || key.name === 'down') && !this.pending && (!this.steering || !this.value.length)) {
2256
2455
  this.scrollBy(key.name === 'up' ? 1 : -1);
2257
2456
  return;
@@ -2479,10 +2678,9 @@ export class TerminalUI extends EventEmitter {
2479
2678
  if (this.moveRow(direction))
2480
2679
  return;
2481
2680
  const historyAt = this.pending?.history ? Math.max(0, Math.min(this.history.length, this.historyIndex + direction)) : this.historyIndex;
2482
- // The wheel never reaches this method: alternate scroll mode is off whenever a question
2483
- // is pending (`updateAlternateScroll`), so the terminal sends nothing for it. Up/Down are
2484
- // therefore purely the keyboard — cursor movement above, history recall here — and never
2485
- // 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.
2486
2684
  if (this.pending?.history) {
2487
2685
  if (this.historyIndex === this.history.length)
2488
2686
  this.draft = this.parkedDraft();
@@ -2681,7 +2879,9 @@ export class TerminalUI extends EventEmitter {
2681
2879
  * leaves the caret where it was still writes zero bytes, so the caret can ride along with
2682
2880
  * the frame without breaking the settled-frame contract.
2683
2881
  */
2684
- writeFrame(lines, cursor = '') {
2882
+ writeFrame(composed, cursor = '') {
2883
+ this.frame = composed;
2884
+ const lines = this.withSelection(composed);
2685
2885
  const size = `${this.output.columns || 80}x${this.output.rows || 24}`;
2686
2886
  const previous = this.drawnSize === size ? this.drawn : undefined;
2687
2887
  const rows = Math.max(lines.length, previous?.length ?? 0);
@@ -2746,13 +2946,13 @@ export class TerminalUI extends EventEmitter {
2746
2946
  return [
2747
2947
  clip(brand.at(-1), available),
2748
2948
  ...(viewportHeight >= 2 ? [clip(`● ${activity}`, available)] : []),
2749
- ...(viewportHeight >= 3 ? [clip(`Workflow · ${graphName}`, available)] : []),
2949
+ ...(viewportHeight >= 3 ? [clip(`Graph · ${graphName}`, available)] : []),
2750
2950
  ...(status.graphNeedsOverride && viewportHeight >= 4 ? [paint(clip(OVERRIDE_HINT, available), ATTENTION)] : []),
2751
2951
  ];
2752
2952
  return [
2753
2953
  '', ...brand, '',
2754
2954
  clip(`● ${activity}`, available),
2755
- clip(`Workflow · ${graphName}${nodeCount}`, available),
2955
+ clip(`Graph · ${graphName}${nodeCount}`, available),
2756
2956
  ...(status.graphNeedsOverride ? [paint(clip(OVERRIDE_HINT, available), ATTENTION)] : []),
2757
2957
  '',
2758
2958
  ...(viewportHeight >= 10 ? ['Describe a task to get started.'] : []),
@@ -2881,7 +3081,14 @@ export class TerminalUI extends EventEmitter {
2881
3081
  const color = isBrand ? WHITE : box ? GRAY : !diff && line.includes(this.appName) ? accentPaint() : transcriptColor(line);
2882
3082
  const allowance = Math.max(1, width - 4);
2883
3083
  const aligned = alignRight && stringWidth(line) <= allowance;
2884
- 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 }));
2885
3092
  });
2886
3093
  }
2887
3094
  transcriptRows(entry, width) {
@@ -2918,7 +3125,10 @@ export class TerminalUI extends EventEmitter {
2918
3125
  if (!this.started || this.closed)
2919
3126
  return;
2920
3127
  this.todoPageSize = 0;
2921
- 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;
2922
3132
  this.updateWorkingClock();
2923
3133
  const columns = Math.max(1, this.output.columns || 80), height = Math.max(1, this.output.rows || 24);
2924
3134
  // The token speed needs no refresh of its own: its reading is captured when a request
@@ -2994,11 +3204,11 @@ export class TerminalUI extends EventEmitter {
2994
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
2995
3205
  // Progress sections carry the same list, and one plan should not be reported twice on the
2996
3206
  // same screen. The panel is the copy that survives a wide terminal.
2997
- 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));
2998
3208
  const elapsed = this.workingElapsed + (this.workingSince === undefined ? 0 : Date.now() - this.workingSince);
2999
3209
  const seconds = Math.floor(elapsed / 1000);
3000
- 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);
3001
- 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;
3002
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));
3003
3213
  const page = this.transcript.window({ prefix, height: transcriptHeight, scroll: this.scroll,
3004
3214
  key: `${width}:${this.expandedTranscript}`, render: entry => this.transcriptRows(entry, width),
@@ -3019,13 +3229,15 @@ export class TerminalUI extends EventEmitter {
3019
3229
  const version = clip(`v${this.version}`, Math.floor(width / 3));
3020
3230
  const header = paint(pad(top, width - stringWidth(version)), DIM) + paint(version, FAINT);
3021
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';
3022
3233
  const borderLabel = label ? clip(` ${label} `, Math.max(0, width - 4)) : '';
3023
3234
  const timestamp = formatHms(seconds);
3024
3235
  const progress = this.nodeProgress();
3025
- 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));
3026
3238
  const wave = Math.floor(elapsed / 120) % 11;
3027
- const workingLine = working ? ' ' + [...workingLabel].map((character, index) => paint(character, index < 7 && Math.abs(index - wave) <= 1 ? 255 : GRAY)).join('') : '';
3028
- 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))];
3029
3241
  if (completion && popupRows) {
3030
3242
  const cardWidth = width - 4;
3031
3243
  const popupTitle = clip(' Commands · ↑↓ move · Enter runs · Tab completes ', cardWidth - 2);
@@ -3040,7 +3252,7 @@ export class TerminalUI extends EventEmitter {
3040
3252
  }
3041
3253
  lines.push(paint(' ╰' + '─'.repeat(cardWidth - 2) + '╯', GRAY));
3042
3254
  }
3043
- lines.push(paint('╭' + borderLabel + '─'.repeat(Math.max(0, width - 2 - stringWidth(borderLabel))) + '╮', GRAY));
3255
+ lines.push(topBorder);
3044
3256
  for (let index = 0; index < inputRows; index++) {
3045
3257
  if (choices) {
3046
3258
  const item = choices[firstInput + index], selected = firstInput + index === choiceIndex;
@@ -3049,7 +3261,7 @@ export class TerminalUI extends EventEmitter {
3049
3261
  continue;
3050
3262
  }
3051
3263
  const value = layout.lines[firstInput + index];
3052
- 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' : '';
3053
3265
  const span = value && selection ? selectedColumns(visibleValue, layout.positions, selection, firstInput + index) : undefined;
3054
3266
  const tokens = value ? tokenColumns(this.value, visibleValue, layout.positions, firstInput + index) : [];
3055
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));
@@ -3064,7 +3276,8 @@ export class TerminalUI extends EventEmitter {
3064
3276
  const jevWidth = Math.min(stringWidth(jev), width - 1);
3065
3277
  lines.push(paint(pad(model, Math.max(0, width - jevWidth - 2)) + (width - jevWidth > 1 ? ' ' : '') + clip(jev, jevWidth), GRAY));
3066
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}` : ''}`);
3067
- 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));
3068
3281
  const count = (value) => Number.isFinite(value) && value >= 0 ? value : 0;
3069
3282
  const compactTokens = Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 1 });
3070
3283
  const activeWindow = active.contextWindow;
@@ -3081,8 +3294,10 @@ export class TerminalUI extends EventEmitter {
3081
3294
  const measured = rate > 0 ? ` · ${compactTokens.format(rate)} tok/s` : '';
3082
3295
  const counts = `${count(status.requests)} req · ${count(status.inputTokens)} in · ${count(status.outputTokens)} out`;
3083
3296
  const usage = `${counts}${measured}${context}`;
3084
- 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}`;
3085
3299
  const footerWidth = width - 1;
3300
+ const branchLead = compactFooter ? `⎇ ${branch} · ` : '';
3086
3301
  // Under width pressure the optional tail is dropped first - the context segment, as
3087
3302
  // documented. But the cumulative counts are unbounded and can spend the whole allowance
3088
3303
  // before the speed segment even starts, clipping it mid-word (`1K to`). While a speed is
@@ -3094,7 +3309,11 @@ export class TerminalUI extends EventEmitter {
3094
3309
  const usageCap = Math.floor(footerWidth * 0.6);
3095
3310
  let usageText = usage;
3096
3311
  let usageWidth;
3097
- 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)
3098
3317
  usageWidth = stringWidth(usage);
3099
3318
  else if (measured) {
3100
3319
  usageText = [`${counts}${measured}`, `${compactCounts}${measured}`].find(candidate => stringWidth(candidate) <= usageCap) ?? compactCounts;
@@ -3102,14 +3321,25 @@ export class TerminalUI extends EventEmitter {
3102
3321
  }
3103
3322
  else
3104
3323
  usageWidth = Math.min(stringWidth(usage), usageCap);
3105
- lines.push(paint(clip(pad(approval, footerWidth - usageWidth), footerWidth - usageWidth), status.yolo ? ATTENTION : GRAY) + 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);
3106
3336
  // The caret travels through the same diff as the rows: writing it straight to the output
3107
3337
  // would put an absolute cursor move and a show-cursor sequence on the wire every 120 ms
3108
3338
  // for the whole of an interactive run (cli.ts keeps steering on), and terminals that clear
3109
3339
  // or move a selection on cursor traffic would lose a drag over an otherwise untouched
3110
3340
  // frame. As a frame input it is suppressed whenever nothing was painted and the caret has
3111
3341
  // not moved, and re-emitted whenever a row repaint hid it.
3112
- 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` : '';
3113
3343
  this.writeFrame(this.composePanel(lines, this.panelRows(panelColumns, height), panelColumns, width), caret);
3114
3344
  }
3115
3345
  }