@linxiraos/pi-tui 1.4.7 → 1.4.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 (181) hide show
  1. package/CHANGELOG.md +154 -231
  2. package/README.md +7 -1
  3. package/dist/types/app-keybindings.d.ts +5 -0
  4. package/dist/types/charts/table-data.d.ts +4 -2
  5. package/dist/types/chat/bash-execution.d.ts +4 -1
  6. package/dist/types/chat/eval-execution.d.ts +2 -0
  7. package/dist/types/chat/execution-shared.d.ts +14 -8
  8. package/dist/types/chat/figure-markdown.d.ts +2 -0
  9. package/dist/types/chat/svg-figure.d.ts +5 -0
  10. package/dist/types/chat/table-chart.d.ts +2 -0
  11. package/dist/types/chat/transcript-render-helpers.d.ts +11 -3
  12. package/dist/types/chrome/dynamic-border.d.ts +6 -0
  13. package/dist/types/chrome/transcript-status.d.ts +2 -2
  14. package/dist/types/components/editor.d.ts +15 -6
  15. package/dist/types/components/image.d.ts +6 -0
  16. package/dist/types/components/loader.d.ts +2 -0
  17. package/dist/types/keybinding-matchers.d.ts +7 -0
  18. package/dist/types/native/describe.d.ts +4 -2
  19. package/dist/types/native/node.d.ts +2 -3
  20. package/dist/types/native/overlay.d.ts +42 -2
  21. package/dist/types/native/state.d.ts +4 -0
  22. package/dist/types/overlays/btw-history-panel.d.ts +15 -0
  23. package/dist/types/overlays/btw-history.d.ts +24 -0
  24. package/dist/types/overlays/btw-inject.d.ts +22 -0
  25. package/dist/types/overlays/btw-panel.d.ts +7 -0
  26. package/dist/types/overlays/hook-editor.d.ts +2 -0
  27. package/dist/types/overlays/jobs-panel.d.ts +4 -0
  28. package/dist/types/overlays/model-browser.d.ts +1 -1
  29. package/dist/types/overlays/session-selector.d.ts +11 -2
  30. package/dist/types/prompt/composer.d.ts +13 -5
  31. package/dist/types/render/render-utils.d.ts +23 -1
  32. package/dist/types/setup/scenes/language.d.ts +3 -0
  33. package/dist/types/setup/scenes/types.d.ts +5 -0
  34. package/dist/types/setup/setup-version.d.ts +1 -1
  35. package/dist/types/setup/wizard.d.ts +1 -1
  36. package/dist/types/status-line/startup.d.ts +0 -15
  37. package/dist/types/terminal-capabilities.d.ts +1 -1
  38. package/dist/types/theme/symbols.d.ts +3 -1
  39. package/dist/types/theme/theme-class.d.ts +1 -0
  40. package/dist/types/theme/theme.d.ts +1 -1
  41. package/dist/types/theme/tui-adapters.d.ts +2 -0
  42. package/dist/types/thinking.d.ts +8 -6
  43. package/dist/types/tools/ast-grep.d.ts +2 -0
  44. package/dist/types/tools/eval.d.ts +2 -0
  45. package/dist/types/tools/find.d.ts +1 -1
  46. package/dist/types/tools/grouped-file-output.d.ts +100 -19
  47. package/dist/types/tools/hashline-format.d.ts +5 -0
  48. package/dist/types/tools/native-view.d.ts +2 -0
  49. package/dist/types/tools/output-meta.d.ts +27 -0
  50. package/dist/types/tools/read.d.ts +14 -4
  51. package/dist/types/tools/task.d.ts +4 -3
  52. package/dist/types/tools/wait.d.ts +2 -0
  53. package/dist/types/tui.d.ts +12 -0
  54. package/dist/types/utils.d.ts +4 -0
  55. package/package.json +9 -9
  56. package/src/app-keybindings.d.ts +5 -0
  57. package/src/app-keybindings.ts +5 -0
  58. package/src/apps/git/git-tui.ts +10 -17
  59. package/src/apps/git/sidebar.ts +21 -35
  60. package/src/apps/ps-top.ts +4 -12
  61. package/src/charts/chart-plan.ts +0 -29
  62. package/src/charts/table-data.d.ts +4 -2
  63. package/src/charts/table-data.ts +55 -6
  64. package/src/chat/bash-execution.d.ts +4 -1
  65. package/src/chat/bash-execution.ts +20 -9
  66. package/src/chat/chat-transcript-builder.ts +5 -2
  67. package/src/chat/eval-execution.d.ts +2 -0
  68. package/src/chat/eval-execution.ts +14 -7
  69. package/src/chat/execution-shared.d.ts +14 -8
  70. package/src/chat/execution-shared.ts +39 -18
  71. package/src/chat/figure-markdown.d.ts +2 -0
  72. package/src/chat/figure-markdown.ts +6 -4
  73. package/src/chat/read-tool-group.ts +56 -36
  74. package/src/chat/svg-figure.d.ts +5 -0
  75. package/src/chat/svg-figure.ts +55 -16
  76. package/src/chat/table-chart.d.ts +2 -0
  77. package/src/chat/table-chart.ts +19 -2
  78. package/src/chat/transcript-render-helpers.d.ts +11 -3
  79. package/src/chat/transcript-render-helpers.ts +70 -22
  80. package/src/chrome/dynamic-border.d.ts +6 -0
  81. package/src/chrome/dynamic-border.ts +28 -2
  82. package/src/chrome/transcript-status.d.ts +2 -2
  83. package/src/chrome/transcript-status.ts +5 -3
  84. package/src/components/editor.d.ts +15 -6
  85. package/src/components/editor.ts +123 -24
  86. package/src/components/image.d.ts +6 -0
  87. package/src/components/image.ts +13 -0
  88. package/src/components/key-value-list.ts +9 -9
  89. package/src/components/loader.d.ts +2 -0
  90. package/src/components/loader.ts +7 -0
  91. package/src/components/section.ts +1 -9
  92. package/src/components/table.ts +1 -9
  93. package/src/keybinding-matchers.d.ts +7 -0
  94. package/src/keybinding-matchers.ts +13 -0
  95. package/src/native/backend.ts +7 -3
  96. package/src/native/describe.d.ts +4 -2
  97. package/src/native/describe.ts +9 -4
  98. package/src/native/node.d.ts +2 -3
  99. package/src/native/node.ts +2 -3
  100. package/src/native/overlay.d.ts +42 -2
  101. package/src/native/overlay.ts +124 -16
  102. package/src/native/state.d.ts +4 -0
  103. package/src/native/state.ts +25 -5
  104. package/src/overlays/btw-history-panel.ts +106 -14
  105. package/src/overlays/btw-history.ts +65 -0
  106. package/src/overlays/btw-inject.ts +91 -0
  107. package/src/overlays/btw-panel.ts +53 -12
  108. package/src/overlays/extensions/extension-dashboard.ts +7 -8
  109. package/src/overlays/hook-editor.ts +6 -0
  110. package/src/overlays/jobs-panel.ts +82 -22
  111. package/src/overlays/login-dialog.ts +8 -26
  112. package/src/overlays/model-browser.ts +69 -10
  113. package/src/overlays/session-selector.ts +25 -5
  114. package/src/overlays/settings-defs.ts +2 -2
  115. package/src/overlays/settings-selector.ts +113 -11
  116. package/src/overlays/tree-selector.ts +83 -27
  117. package/src/overlays/usage-dashboard.ts +4 -6
  118. package/src/prompt/composer.ts +17 -5
  119. package/src/render/code-cell.ts +1 -1
  120. package/src/render/file-list.ts +4 -7
  121. package/src/render/render-utils.d.ts +23 -1
  122. package/src/render/render-utils.ts +38 -6
  123. package/src/setup/scenes/glyph.ts +1 -1
  124. package/src/setup/scenes/language.ts +122 -0
  125. package/src/setup/scenes/types.ts +6 -0
  126. package/src/setup/setup-version.ts +1 -1
  127. package/src/setup/wizard.ts +2 -0
  128. package/src/status-line/startup.ts +36 -70
  129. package/src/terminal-capabilities.d.ts +1 -1
  130. package/src/terminal-capabilities.ts +5 -0
  131. package/src/theme/symbols.d.ts +3 -1
  132. package/src/theme/symbols.ts +16 -9
  133. package/src/theme/theme-class.d.ts +1 -0
  134. package/src/theme/theme-class.ts +15 -3
  135. package/src/theme/theme.d.ts +1 -1
  136. package/src/theme/theme.ts +1 -0
  137. package/src/theme/tui-adapters.d.ts +2 -0
  138. package/src/theme/tui-adapters.ts +8 -3
  139. package/src/thinking.d.ts +8 -6
  140. package/src/thinking.ts +17 -11
  141. package/src/tmux.ts +1 -0
  142. package/src/tools/agent-tree.ts +13 -11
  143. package/src/tools/ask.ts +24 -37
  144. package/src/tools/ast-edit.ts +48 -93
  145. package/src/tools/ast-grep.d.ts +2 -0
  146. package/src/tools/ast-grep.ts +31 -67
  147. package/src/tools/bash.ts +7 -0
  148. package/src/tools/default-renderer.ts +1 -1
  149. package/src/tools/edit.ts +50 -43
  150. package/src/tools/eval.d.ts +2 -0
  151. package/src/tools/eval.ts +2 -0
  152. package/src/tools/fetch.ts +2 -1
  153. package/src/tools/find.d.ts +1 -1
  154. package/src/tools/find.ts +13 -5
  155. package/src/tools/github.ts +14 -46
  156. package/src/tools/glob.ts +2 -1
  157. package/src/tools/grep.ts +47 -277
  158. package/src/tools/grouped-file-output.d.ts +100 -19
  159. package/src/tools/grouped-file-output.ts +414 -103
  160. package/src/tools/hashline-format.d.ts +5 -0
  161. package/src/tools/hashline-format.ts +5 -0
  162. package/src/tools/json-tree.ts +1 -5
  163. package/src/tools/lsp.ts +210 -32
  164. package/src/tools/native-view.d.ts +2 -0
  165. package/src/tools/native-view.ts +11 -5
  166. package/src/tools/output-meta.d.ts +27 -0
  167. package/src/tools/output-meta.ts +68 -4
  168. package/src/tools/proc-render.ts +3 -3
  169. package/src/tools/read.d.ts +14 -4
  170. package/src/tools/read.ts +20 -5
  171. package/src/tools/task.d.ts +4 -3
  172. package/src/tools/task.ts +41 -81
  173. package/src/tools/vibe.ts +4 -4
  174. package/src/tools/wait.d.ts +2 -0
  175. package/src/tools/wait.ts +8 -5
  176. package/src/tools/write.ts +17 -27
  177. package/src/tools/yield.ts +1 -1
  178. package/src/tui.d.ts +12 -0
  179. package/src/tui.ts +91 -9
  180. package/src/utils.d.ts +4 -0
  181. package/src/utils.ts +10 -0
package/src/tui.ts CHANGED
@@ -86,6 +86,15 @@ const LINE_FIT_SOURCE_WIDTH_MULTIPLIER = 64;
86
86
  // Zeta sidebar: the main area never composes narrower than this, even when a
87
87
  // gutter reservation is active — narrow terminals ignore the reservation.
88
88
  const MIN_MAIN_AREA_COLUMNS = 64;
89
+ // Zeta sidebar snapshot: the gutter column's semantic description travels
90
+ // out-of-band as an APC (`ESC _ zeta;sidebar; <base64 JSON> ESC \`) so a native
91
+ // GUI draws the same column from one frame's data. Unknown APCs are dropped by
92
+ // every terminal emulator, so the ANSI gutter stays the visible fallback.
93
+ const SIDEBAR_APC_PREFIX = "\x1b_zeta;sidebar;";
94
+ const SIDEBAR_APC_SUFFIX = "\x1b\\";
95
+ // Bound the payload per frame: a pathological snapshot falls back to the ANSI
96
+ // gutter instead of stalling the terminal's parser on a huge escape sequence.
97
+ const SIDEBAR_APC_MAX = 64 * 1024;
89
98
  // Hide the hardware cursor before each paint/move write. Ghostty-style bar
90
99
  // cursors can otherwise leave visual afterimages while the TUI repaints the
91
100
  // row under a visible cursor. Paint writes also disable terminal autowrap:
@@ -357,6 +366,24 @@ export interface Component {
357
366
  dispose?(): void;
358
367
  }
359
368
 
369
+ /**
370
+ * A gutter component that can hand an external native renderer a semantic
371
+ * snapshot of the column it draws (see {@link TUI.setGutterComponent}). Such a
372
+ * component keeps rendering its ANSI rows — the snapshot only travels
373
+ * out-of-band — and a GUI that receives it draws the same content natively.
374
+ * Deliberately separate from {@link Component}: only a sidebar-shaped
375
+ * component describes itself for a whole external surface.
376
+ */
377
+ export interface NativeSnapshotSource {
378
+ /** JSON-serializable TSP node for an external native sidebar renderer. */
379
+ describeSnapshot(): NativeNode | null;
380
+ }
381
+
382
+ /** Whether `component` hands an out-of-band snapshot to a native renderer. */
383
+ function isSnapshotSource(component: Component): component is Component & NativeSnapshotSource {
384
+ return typeof (component as Partial<NativeSnapshotSource>).describeSnapshot === "function";
385
+ }
386
+
360
387
  /** Lets an overlay root delegate keyboard focus to components it owns. */
361
388
  export interface OverlayFocusOwner {
362
389
  /** Returns true when `component` is a focus target inside this overlay. */
@@ -929,6 +956,9 @@ export class TUI extends Container {
929
956
  // Zeta sidebar: right-hand gutter component and its last painted rows.
930
957
  #gutterComponent: Component | null = null;
931
958
  #paintedGutterRows: readonly string[] | null = null;
959
+ // Zeta sidebar snapshot: last APC payload written (`null` forces the next
960
+ // paint to write, even when the payload is the empty clear sequence).
961
+ #lastSidebarPayload: string | null = "";
932
962
  // Zeta sidebar: columns reserved for the gutter, or null for full width.
933
963
  #mainWidthOverride: number | null = null;
934
964
  #focusedComponent: Component | null = null;
@@ -1244,6 +1274,11 @@ export class TUI extends Container {
1244
1274
  if (this.#gutterComponent === component) return;
1245
1275
  this.#gutterComponent = component;
1246
1276
  this.#paintedGutterRows = null;
1277
+ // A replacement (or removed) component must never inherit the last column.
1278
+ // Force the next paint to publish its snapshot — or the clear payload — only
1279
+ // when a snapshot was actually published, so an ordinary gutter byte-stream
1280
+ // stays exactly as it was without a native renderer attached.
1281
+ if (this.#lastSidebarPayload !== "") this.#lastSidebarPayload = null;
1247
1282
  this.requestRender();
1248
1283
  }
1249
1284
 
@@ -1283,6 +1318,33 @@ export class TUI extends Container {
1283
1318
  seq += `\x1b[${restoreRow + 1};1H`;
1284
1319
  return seq;
1285
1320
  }
1321
+
1322
+ /**
1323
+ * The APC carrying this frame's sidebar snapshot (see
1324
+ * {@link NativeSnapshotSource}): `ESC _ zeta;sidebar; <base64(UTF-8 JSON)> ESC \`,
1325
+ * with an empty payload when there is no snapshot so a native renderer drops
1326
+ * the column. Returns "" while the payload is unchanged, so frames that only
1327
+ * repaint the same column write no extra bytes.
1328
+ */
1329
+ #sidebarApc(snapshot: NativeNode | null): string {
1330
+ let payload = "";
1331
+ if (snapshot !== null) {
1332
+ try {
1333
+ const json = JSON.stringify({ v: 1, node: snapshot });
1334
+ const encoded = Buffer.from(json, "utf8").toString("base64");
1335
+ // Oversized snapshots are dropped, not truncated: the ANSI gutter
1336
+ // already shows the same column.
1337
+ if (encoded.length <= SIDEBAR_APC_MAX) payload = encoded;
1338
+ } catch {
1339
+ // A component child or a property cycle cannot cross the snapshot
1340
+ // boundary; the frame falls back to the ANSI gutter.
1341
+ }
1342
+ }
1343
+ if (payload === this.#lastSidebarPayload) return "";
1344
+ this.#lastSidebarPayload = payload;
1345
+ return `${SIDEBAR_APC_PREFIX}${payload}${SIDEBAR_APC_SUFFIX}`;
1346
+ }
1347
+
1286
1348
  /** Return how settled resizes refresh native scrollback. */
1287
1349
  getResizeScrollback(): ResizeScrollbackMode {
1288
1350
  return this.#resizeScrollbackMode;
@@ -3595,16 +3657,36 @@ export class TUI extends Container {
3595
3657
  if (gutter) {
3596
3658
  const rows = gutter.render(rawWidth - mainWidth);
3597
3659
  const seq = this.#gutterPaintSequence(rows, rawWidth - mainWidth, mainWidth, viewportRows, 0);
3598
- if (seq) this.terminal.write(seq);
3660
+ // The snapshot rides the same write as the gutter paint, so both describe
3661
+ // this one frame; an APC never moves the cursor.
3662
+ let snapshot: NativeNode | null = null;
3663
+ if (isSnapshotSource(gutter)) {
3664
+ try {
3665
+ snapshot = gutter.describeSnapshot();
3666
+ } catch {
3667
+ // A throwing snapshot source must not take down the frame; the ANSI
3668
+ // gutter below already shows the column.
3669
+ snapshot = null;
3670
+ }
3671
+ }
3672
+ const apc = this.#sidebarApc(snapshot);
3673
+ if (seq || apc) this.terminal.write(seq + apc);
3599
3674
  this.#paintedGutterRows = rows;
3600
- } else if (this.#paintedGutterRows !== null) {
3601
- // Gutter removed: clear the margin column once via absolute EL per row.
3602
- const col = mainWidth + 1;
3603
- let seq = "";
3604
- for (let row = 0; row < height; row++) seq += `\x1b[${row + 1};${col}H\x1b[K`;
3605
- seq += "\x1b[H";
3606
- this.terminal.write(seq);
3607
- this.#paintedGutterRows = null;
3675
+ } else {
3676
+ // Overlay frame, no reservation, or no component: clear the native column
3677
+ // once so a GUI never keeps drawing a snapshot the ANSI frame dropped.
3678
+ const apc = this.#sidebarApc(null);
3679
+ if (this.#paintedGutterRows !== null) {
3680
+ // Gutter removed: clear the margin column once via absolute EL per row.
3681
+ const col = mainWidth + 1;
3682
+ let seq = "";
3683
+ for (let row = 0; row < height; row++) seq += `\x1b[${row + 1};${col}H\x1b[K`;
3684
+ seq += "\x1b[H";
3685
+ this.terminal.write(seq + apc);
3686
+ this.#paintedGutterRows = null;
3687
+ } else if (apc) {
3688
+ this.terminal.write(apc);
3689
+ }
3608
3690
  }
3609
3691
  }
3610
3692
  /**
package/src/utils.d.ts CHANGED
@@ -36,6 +36,10 @@ export declare function truncateToWidth(text: string, maxWidth: number, ellipsis
36
36
  export declare function wrapTextWithAnsi(text: string, width: number): string[];
37
37
  export declare function extractSegments(line: string, beforeEnd: number, afterStart: number, afterLen: number, strictAfter: boolean): ExtractSegmentsResult;
38
38
  export declare function replaceTabs(text: string): string;
39
+ /** Tabs expanded and line breaks collapsed to spaces, for text confined to one rendered row. */
40
+ export declare function singleLine(text: string): string;
41
+ /** A non-negative integer cell width; non-finite input becomes `fallback`. */
42
+ export declare function finiteWidth(width: number, fallback?: number): number;
39
43
  /**
40
44
  * Returns a string of n spaces. Uses a pre-allocated buffer for efficiency.
41
45
  */
package/src/utils.ts CHANGED
@@ -221,6 +221,16 @@ export function replaceTabs(text: string): string {
221
221
  return text.replaceAll("\t", TAB_SPACES);
222
222
  }
223
223
 
224
+ /** Tabs expanded and line breaks collapsed to spaces, for text confined to one rendered row. */
225
+ export function singleLine(text: string): string {
226
+ return replaceTabs(text).replace(/[\r\n]+/g, " ");
227
+ }
228
+
229
+ /** A non-negative integer cell width; non-finite input becomes `fallback`. */
230
+ export function finiteWidth(width: number, fallback = 0): number {
231
+ return Number.isFinite(width) ? Math.max(0, Math.trunc(width)) : fallback;
232
+ }
233
+
224
234
  /**
225
235
  * Returns a string of n spaces. Uses a pre-allocated buffer for efficiency.
226
236
  */