@linxiraos/pi-tui 1.4.7 → 1.4.9

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 (172) hide show
  1. package/CHANGELOG.md +28 -109
  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/status-line/startup.d.ts +0 -15
  33. package/dist/types/terminal-capabilities.d.ts +1 -1
  34. package/dist/types/theme/symbols.d.ts +3 -1
  35. package/dist/types/theme/theme-class.d.ts +1 -0
  36. package/dist/types/theme/theme.d.ts +1 -1
  37. package/dist/types/theme/tui-adapters.d.ts +2 -0
  38. package/dist/types/thinking.d.ts +8 -6
  39. package/dist/types/tools/ast-grep.d.ts +2 -0
  40. package/dist/types/tools/eval.d.ts +2 -0
  41. package/dist/types/tools/find.d.ts +1 -1
  42. package/dist/types/tools/grouped-file-output.d.ts +100 -19
  43. package/dist/types/tools/hashline-format.d.ts +5 -0
  44. package/dist/types/tools/native-view.d.ts +2 -0
  45. package/dist/types/tools/output-meta.d.ts +27 -0
  46. package/dist/types/tools/read.d.ts +14 -4
  47. package/dist/types/tools/task.d.ts +4 -3
  48. package/dist/types/tools/wait.d.ts +2 -0
  49. package/dist/types/tui.d.ts +12 -0
  50. package/dist/types/utils.d.ts +4 -0
  51. package/package.json +9 -9
  52. package/src/app-keybindings.d.ts +5 -0
  53. package/src/app-keybindings.ts +5 -0
  54. package/src/apps/git/git-tui.ts +10 -17
  55. package/src/apps/git/sidebar.ts +21 -35
  56. package/src/apps/ps-top.ts +4 -12
  57. package/src/charts/chart-plan.ts +0 -29
  58. package/src/charts/table-data.d.ts +4 -2
  59. package/src/charts/table-data.ts +55 -6
  60. package/src/chat/bash-execution.d.ts +4 -1
  61. package/src/chat/bash-execution.ts +20 -9
  62. package/src/chat/chat-transcript-builder.ts +5 -2
  63. package/src/chat/eval-execution.d.ts +2 -0
  64. package/src/chat/eval-execution.ts +14 -7
  65. package/src/chat/execution-shared.d.ts +14 -8
  66. package/src/chat/execution-shared.ts +39 -18
  67. package/src/chat/figure-markdown.d.ts +2 -0
  68. package/src/chat/figure-markdown.ts +6 -4
  69. package/src/chat/read-tool-group.ts +56 -36
  70. package/src/chat/svg-figure.d.ts +5 -0
  71. package/src/chat/svg-figure.ts +55 -16
  72. package/src/chat/table-chart.d.ts +2 -0
  73. package/src/chat/table-chart.ts +19 -2
  74. package/src/chat/transcript-render-helpers.d.ts +11 -3
  75. package/src/chat/transcript-render-helpers.ts +70 -22
  76. package/src/chrome/dynamic-border.d.ts +6 -0
  77. package/src/chrome/dynamic-border.ts +28 -2
  78. package/src/chrome/transcript-status.d.ts +2 -2
  79. package/src/chrome/transcript-status.ts +5 -3
  80. package/src/components/editor.d.ts +15 -6
  81. package/src/components/editor.ts +123 -24
  82. package/src/components/image.d.ts +6 -0
  83. package/src/components/image.ts +13 -0
  84. package/src/components/key-value-list.ts +9 -9
  85. package/src/components/loader.d.ts +2 -0
  86. package/src/components/loader.ts +7 -0
  87. package/src/components/section.ts +1 -9
  88. package/src/components/table.ts +1 -9
  89. package/src/keybinding-matchers.d.ts +7 -0
  90. package/src/keybinding-matchers.ts +13 -0
  91. package/src/native/backend.ts +7 -3
  92. package/src/native/describe.d.ts +4 -2
  93. package/src/native/describe.ts +9 -4
  94. package/src/native/node.d.ts +2 -3
  95. package/src/native/node.ts +2 -3
  96. package/src/native/overlay.d.ts +42 -2
  97. package/src/native/overlay.ts +124 -16
  98. package/src/native/state.d.ts +4 -0
  99. package/src/native/state.ts +25 -5
  100. package/src/overlays/btw-history-panel.ts +106 -14
  101. package/src/overlays/btw-history.ts +65 -0
  102. package/src/overlays/btw-inject.ts +91 -0
  103. package/src/overlays/btw-panel.ts +53 -12
  104. package/src/overlays/extensions/extension-dashboard.ts +7 -8
  105. package/src/overlays/hook-editor.ts +6 -0
  106. package/src/overlays/jobs-panel.ts +82 -22
  107. package/src/overlays/login-dialog.ts +8 -26
  108. package/src/overlays/model-browser.ts +69 -10
  109. package/src/overlays/session-selector.ts +25 -5
  110. package/src/overlays/settings-defs.ts +2 -2
  111. package/src/overlays/tree-selector.ts +83 -27
  112. package/src/overlays/usage-dashboard.ts +4 -6
  113. package/src/prompt/composer.ts +17 -5
  114. package/src/render/code-cell.ts +1 -1
  115. package/src/render/file-list.ts +4 -7
  116. package/src/render/render-utils.d.ts +23 -1
  117. package/src/render/render-utils.ts +38 -6
  118. package/src/setup/scenes/glyph.ts +1 -1
  119. package/src/status-line/startup.ts +36 -70
  120. package/src/terminal-capabilities.d.ts +1 -1
  121. package/src/terminal-capabilities.ts +5 -0
  122. package/src/theme/symbols.d.ts +3 -1
  123. package/src/theme/symbols.ts +16 -9
  124. package/src/theme/theme-class.d.ts +1 -0
  125. package/src/theme/theme-class.ts +15 -3
  126. package/src/theme/theme.d.ts +1 -1
  127. package/src/theme/theme.ts +1 -0
  128. package/src/theme/tui-adapters.d.ts +2 -0
  129. package/src/theme/tui-adapters.ts +8 -3
  130. package/src/thinking.d.ts +8 -6
  131. package/src/thinking.ts +17 -11
  132. package/src/tmux.ts +1 -0
  133. package/src/tools/agent-tree.ts +13 -11
  134. package/src/tools/ask.ts +24 -37
  135. package/src/tools/ast-edit.ts +48 -93
  136. package/src/tools/ast-grep.d.ts +2 -0
  137. package/src/tools/ast-grep.ts +31 -67
  138. package/src/tools/bash.ts +7 -0
  139. package/src/tools/default-renderer.ts +1 -1
  140. package/src/tools/edit.ts +50 -43
  141. package/src/tools/eval.d.ts +2 -0
  142. package/src/tools/eval.ts +2 -0
  143. package/src/tools/fetch.ts +2 -1
  144. package/src/tools/find.d.ts +1 -1
  145. package/src/tools/find.ts +13 -5
  146. package/src/tools/github.ts +14 -46
  147. package/src/tools/glob.ts +2 -1
  148. package/src/tools/grep.ts +47 -277
  149. package/src/tools/grouped-file-output.d.ts +100 -19
  150. package/src/tools/grouped-file-output.ts +414 -103
  151. package/src/tools/hashline-format.d.ts +5 -0
  152. package/src/tools/hashline-format.ts +5 -0
  153. package/src/tools/json-tree.ts +1 -5
  154. package/src/tools/lsp.ts +210 -32
  155. package/src/tools/native-view.d.ts +2 -0
  156. package/src/tools/native-view.ts +11 -5
  157. package/src/tools/output-meta.d.ts +27 -0
  158. package/src/tools/output-meta.ts +68 -4
  159. package/src/tools/proc-render.ts +3 -3
  160. package/src/tools/read.d.ts +14 -4
  161. package/src/tools/read.ts +20 -5
  162. package/src/tools/task.d.ts +4 -3
  163. package/src/tools/task.ts +41 -81
  164. package/src/tools/vibe.ts +4 -4
  165. package/src/tools/wait.d.ts +2 -0
  166. package/src/tools/wait.ts +8 -5
  167. package/src/tools/write.ts +17 -27
  168. package/src/tools/yield.ts +1 -1
  169. package/src/tui.d.ts +12 -0
  170. package/src/tui.ts +91 -9
  171. package/src/utils.d.ts +4 -0
  172. package/src/utils.ts +10 -0
@@ -132,10 +132,15 @@ export function elapsed(age: number, stopped?: boolean): NativeNode {
132
132
  }
133
133
 
134
134
  /**
135
- * Keycap for one key id (`"ctrl+o"` → keys `["ctrl", "o"]`); the terminal
136
- * draws platform glyphs. A literal `+` key survives (`"+"`, `"ctrl++"`).
135
+ * The key names of one key id (`"ctrl+o"` → `["ctrl", "o"]`), as `kbd` and
136
+ * `button` `keys` take them. A literal `+` key survives (`"+"`, `"ctrl++"`).
137
137
  */
138
- export function kbd(key: string, nodeKey?: string): NativeNode {
138
+ export function keyNames(key: string): string[] {
139
139
  const keys = key === "+" ? ["+"] : key.endsWith("++") ? [...key.slice(0, -2).split("+"), "+"] : key.split("+");
140
- return node("kbd", { keys: keys.filter(part => part.length > 0) }, undefined, nodeKey);
140
+ return keys.filter(part => part.length > 0);
141
+ }
142
+
143
+ /** Keycap for one key id ({@link keyNames}); the terminal draws platform glyphs. */
144
+ export function kbd(key: string, nodeKey?: string): NativeNode {
145
+ return node("kbd", { keys: keyNames(key) }, undefined, nodeKey);
141
146
  }
@@ -10,9 +10,8 @@
10
10
  * reference contract as `render()`). A component without `describe` becomes a
11
11
  * `rows` fallback node rendered through `render(cx.cols)`.
12
12
  *
13
- * See `packages/wire/src/tsp.ts` for the wire vocabulary and
14
- * the Tern SDK's Surface Protocol reference (`docs/sdk/src/protocol` in the
15
- * Stencil repository, https://docs.stencil.so/tern/protocol/) for the spec.
13
+ * See `packages/wire/src/tsp.ts` for the wire vocabulary; the normative spec is
14
+ * the Tern Surface Protocol.
16
15
  */
17
16
  import type { TspEvent, TspKind, TspProps, TspScrollBy, TspSpan } from "@linxiraos/pi-wire";
18
17
  import type { Component } from "../tui";
@@ -10,9 +10,8 @@
10
10
  * reference contract as `render()`). A component without `describe` becomes a
11
11
  * `rows` fallback node rendered through `render(cx.cols)`.
12
12
  *
13
- * See `packages/wire/src/tsp.ts` for the wire vocabulary and
14
- * the Tern SDK's Surface Protocol reference (`docs/sdk/src/protocol` in the
15
- * Stencil repository, https://docs.stencil.so/tern/protocol/) for the spec.
13
+ * See `packages/wire/src/tsp.ts` for the wire vocabulary; the normative spec is
14
+ * the Tern Surface Protocol.
16
15
  */
17
16
  import type { TspEvent, TspKind, TspProps, TspScrollBy, TspSpan } from "@linxiraos/pi-wire";
18
17
  import type { Component } from "../tui";
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Overlay chrome for `describe()`: root cards, key-hint footers, selectable
3
- * lists and annotation callouts.
2
+ * Overlay chrome for `describe()`: root cards, key-hint footers, buttons and
3
+ * segmented controls, selectable lists and annotation callouts.
4
4
  *
5
5
  * The overlay frame itself (glass, ring, placement) is the terminal's: the
6
6
  * engine wraps every overlay-stack component in an `overlay` node. An overlay
@@ -53,11 +53,23 @@ export interface ActionButtonOptions {
53
53
  readonly title?: string;
54
54
  /** Target of an `open` action (URL or `file://` path). */
55
55
  readonly href?: string;
56
+ /** Why the action can't run now: the button dims and a click sends nothing. */
57
+ readonly disabled?: string;
58
+ /** The button's work is running: a spinner leads the label. */
59
+ readonly busy?: boolean;
60
+ /** Icon beside the label (before it on a `button` node, after it on a row). */
61
+ readonly icon?: string;
56
62
  }
57
63
  /**
58
64
  * A native button (role `zeta.btn`): a label plus an optional keycap. A click
59
65
  * sends `act` back as an `action` event (or runs a terminal-local `open`/`copy`),
60
66
  * which the component routes to the same code path as the key.
67
+ *
68
+ * A terminal that draws the `button` kind ({@link nativeButtons}) gets one
69
+ * (tone `accent` → variant `primary`, `error` → `danger`, `disabled` with its
70
+ * reason as the tooltip); older ones get the row their stylesheets draw by
71
+ * role. Both keep the role and tone the omp sheets' context rules key on; a
72
+ * disabled button's tone is `muted`.
61
73
  */
62
74
  export declare function actionButton(label: string, act: string, options?: ActionButtonOptions): NativeNode;
63
75
  /**
@@ -65,6 +77,34 @@ export declare function actionButton(label: string, act: string, options?: Actio
65
77
  * `act` (default `close`), which the component routes to its Esc path.
66
78
  */
67
79
  export declare function escCloseButton(act?: string, key?: string): NativeNode;
80
+ /** Options of an {@link iconButton}. */
81
+ export interface IconButtonOptions {
82
+ /** Sibling identity key; unkeyed buttons take their position. */
83
+ readonly key?: string;
84
+ /** Accessible name; defaults to the title. */
85
+ readonly aria?: string;
86
+ /** A toggle that is on (role `zeta.app.ibtn.set`). */
87
+ readonly on?: boolean;
88
+ }
89
+ /**
90
+ * A quiet icon-only button (role `zeta.app.ibtn`, the kit's icon button) for an
91
+ * app head or toolbar: a `button` node where the terminal draws one
92
+ * ({@link nativeButtons}), else an `icon` with a click action.
93
+ */
94
+ export declare function iconButton(name: string, act: string, title: string, options?: IconButtonOptions): NativeNode;
95
+ /**
96
+ * A quiet text button (role `zeta.app.qbtn`, the kit's quiet button) for a
97
+ * section head or toolbar, keyed by its action: a small quiet `button` where
98
+ * the terminal draws one ({@link nativeButtons}), else a row.
99
+ */
100
+ export declare function quietButton(label: string, act: string, title: string): NativeNode;
101
+ /**
102
+ * A segmented control: `tabs` drawn as a well with a raised thumb on the
103
+ * active tab. A terminal that draws the `button` kind ({@link nativeButtons})
104
+ * draws `variant: "segmented"` too; older ones restyle the tabs by role
105
+ * (`zeta.app.seg`) or parent.
106
+ */
107
+ export declare function segmentedTabs(p: TspProps<"tabs">, key: string): NativeNode;
68
108
  /** A row of {@link actionButton}s (role `zeta.actions`); `null` entries become the spacer that end-aligns what follows. */
69
109
  export declare function actionBar(buttons: readonly (NativeNode | null)[], key?: string): NativeNode;
70
110
  /** Spans of an annotation callout: a dim `label:` then the note. */
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Overlay chrome for `describe()`: root cards, key-hint footers, selectable
3
- * lists and annotation callouts.
2
+ * Overlay chrome for `describe()`: root cards, key-hint footers, buttons and
3
+ * segmented controls, selectable lists and annotation callouts.
4
4
  *
5
5
  * The overlay frame itself (glass, ring, placement) is the terminal's: the
6
6
  * engine wraps every overlay-stack component in an `overlay` node. An overlay
@@ -9,8 +9,9 @@
9
9
  import type { TspProps, TspSpan, TspText } from "@linxiraos/pi-wire";
10
10
  import { formatTooltipKey, type KeyName } from "../key-hint-format";
11
11
  import { getKeybindings, type Keybinding } from "../keybindings";
12
- import { card, kbd, list, node, row, span, text } from "./describe";
12
+ import { card, kbd, keyNames, list, node, row, span, text } from "./describe";
13
13
  import type { NativeChild, NativeNode } from "./node";
14
+ import { nativeButtons } from "./state";
14
15
 
15
16
  /** Below this many columns a centered sheet fills the pane instead of floating with margins. */
16
17
  export const NARROW_SHEET_COLS = 100;
@@ -96,29 +97,68 @@ export interface ActionButtonOptions {
96
97
  readonly title?: string;
97
98
  /** Target of an `open` action (URL or `file://` path). */
98
99
  readonly href?: string;
100
+ /** Why the action can't run now: the button dims and a click sends nothing. */
101
+ readonly disabled?: string;
102
+ /** The button's work is running: a spinner leads the label. */
103
+ readonly busy?: boolean;
104
+ /** Icon beside the label (before it on a `button` node, after it on a row). */
105
+ readonly icon?: string;
99
106
  }
100
107
 
101
108
  /**
102
109
  * A native button (role `zeta.btn`): a label plus an optional keycap. A click
103
110
  * sends `act` back as an `action` event (or runs a terminal-local `open`/`copy`),
104
111
  * which the component routes to the same code path as the key.
112
+ *
113
+ * A terminal that draws the `button` kind ({@link nativeButtons}) gets one
114
+ * (tone `accent` → variant `primary`, `error` → `danger`, `disabled` with its
115
+ * reason as the tooltip); older ones get the row their stylesheets draw by
116
+ * role. Both keep the role and tone the omp sheets' context rules key on; a
117
+ * disabled button's tone is `muted`.
105
118
  */
106
119
  export function actionButton(label: string, act: string, options: ActionButtonOptions = {}): NativeNode {
107
- const children: NativeChild[] = [text(label)];
108
- if (options.keys) children.push(kbd(options.keys));
120
+ const { keys, href, disabled, busy, icon } = options;
121
+ const title = options.title ?? (keys ? `${label} ${formatTooltipKey(keys)}` : label);
122
+ const tone = disabled === undefined ? options.tone : "muted";
123
+ const key = options.key ?? act;
124
+ if (nativeButtons()) {
125
+ return node(
126
+ "button",
127
+ {
128
+ role: "zeta.btn",
129
+ text: label,
130
+ actions: { click: act },
131
+ title,
132
+ ...(keys ? { keys: keyNames(keys) } : {}),
133
+ ...(icon ? { icon } : {}),
134
+ ...(tone === "accent" ? { variant: "primary" } : tone === "error" ? { variant: "danger" } : {}),
135
+ ...(tone ? { tone } : {}),
136
+ ...(disabled !== undefined ? { disabled: disabled || true } : {}),
137
+ ...(busy ? { busy } : {}),
138
+ ...(href ? { href } : {}),
139
+ },
140
+ undefined,
141
+ key,
142
+ );
143
+ }
144
+ const children: NativeChild[] = [];
145
+ if (busy) children.push(node("spinner", { style: "dots" }));
146
+ children.push(text(label));
147
+ if (icon) children.push(node("icon", { name: icon }, undefined, "icon"));
148
+ if (keys) children.push(kbd(keys));
109
149
  return node(
110
150
  "row",
111
151
  {
112
152
  role: "zeta.btn",
113
153
  gap: "xs",
114
154
  align: "center",
115
- actions: { click: act },
116
- title: options.title ?? (options.keys ? `${label} ${formatTooltipKey(options.keys)}` : label),
117
- ...(options.tone ? { tone: options.tone } : {}),
118
- ...(options.href ? { href: options.href } : {}),
155
+ ...(disabled === undefined ? { actions: { click: act } } : {}),
156
+ title,
157
+ ...(tone ? { tone } : {}),
158
+ ...(href ? { href } : {}),
119
159
  },
120
160
  children,
121
- options.key ?? act,
161
+ key,
122
162
  );
123
163
  }
124
164
 
@@ -127,12 +167,80 @@ export function actionButton(label: string, act: string, options: ActionButtonOp
127
167
  * `act` (default `close`), which the component routes to its Esc path.
128
168
  */
129
169
  export function escCloseButton(act = "close", key = "esc-close"): NativeNode {
130
- return node(
131
- "row",
132
- { role: "zeta.btn", align: "center", actions: { click: act }, title: `Close ${formatTooltipKey("escape")}` },
133
- [kbd("escape")],
134
- key,
135
- );
170
+ const title = `Close ${formatTooltipKey("escape")}`;
171
+ if (nativeButtons()) {
172
+ return node(
173
+ "button",
174
+ { role: "zeta.btn", keys: ["escape"], actions: { click: act }, title, aria: "Close" },
175
+ undefined,
176
+ key,
177
+ );
178
+ }
179
+ return node("row", { role: "zeta.btn", align: "center", actions: { click: act }, title }, [kbd("escape")], key);
180
+ }
181
+
182
+ /** Options of an {@link iconButton}. */
183
+ export interface IconButtonOptions {
184
+ /** Sibling identity key; unkeyed buttons take their position. */
185
+ readonly key?: string;
186
+ /** Accessible name; defaults to the title. */
187
+ readonly aria?: string;
188
+ /** A toggle that is on (role `zeta.app.ibtn.set`). */
189
+ readonly on?: boolean;
190
+ }
191
+
192
+ /**
193
+ * A quiet icon-only button (role `zeta.app.ibtn`, the kit's icon button) for an
194
+ * app head or toolbar: a `button` node where the terminal draws one
195
+ * ({@link nativeButtons}), else an `icon` with a click action.
196
+ */
197
+ export function iconButton(name: string, act: string, title: string, options: IconButtonOptions = {}): NativeNode {
198
+ const role = options.on ? "zeta.app.ibtn.set" : "zeta.app.ibtn";
199
+ const aria = options.aria ?? title;
200
+ if (nativeButtons()) {
201
+ return node(
202
+ "button",
203
+ {
204
+ role,
205
+ variant: "quiet",
206
+ icon: name,
207
+ title,
208
+ aria,
209
+ actions: { click: act },
210
+ ...(options.on ? { on: true } : {}),
211
+ },
212
+ undefined,
213
+ options.key,
214
+ );
215
+ }
216
+ return node("icon", { name, role, title, aria, actions: { click: act } }, undefined, options.key);
217
+ }
218
+
219
+ /**
220
+ * A quiet text button (role `zeta.app.qbtn`, the kit's quiet button) for a
221
+ * section head or toolbar, keyed by its action: a small quiet `button` where
222
+ * the terminal draws one ({@link nativeButtons}), else a row.
223
+ */
224
+ export function quietButton(label: string, act: string, title: string): NativeNode {
225
+ if (nativeButtons()) {
226
+ return node(
227
+ "button",
228
+ { role: "zeta.app.qbtn", variant: "quiet", size: "sm", text: label, actions: { click: act }, title },
229
+ undefined,
230
+ act,
231
+ );
232
+ }
233
+ return node("row", { role: "zeta.app.qbtn", actions: { click: act }, title }, [text(label)], act);
234
+ }
235
+
236
+ /**
237
+ * A segmented control: `tabs` drawn as a well with a raised thumb on the
238
+ * active tab. A terminal that draws the `button` kind ({@link nativeButtons})
239
+ * draws `variant: "segmented"` too; older ones restyle the tabs by role
240
+ * (`zeta.app.seg`) or parent.
241
+ */
242
+ export function segmentedTabs(p: TspProps<"tabs">, key: string): NativeNode {
243
+ return node("tabs", nativeButtons() ? { ...p, variant: "segmented" } : p, undefined, key);
136
244
  }
137
245
 
138
246
  /** A row of {@link actionButton}s (role `zeta.actions`); `null` entries become the spacer that end-aligns what follows. */
@@ -2,5 +2,9 @@
2
2
  export declare function isNativeRendering(): boolean;
3
3
  /** Called by the native backend on surface open and close. */
4
4
  export declare function setNativeRendering(on: boolean): void;
5
+ /** Whether omp's buttons go out as `button` nodes (see {@link setNativeButtons}). */
6
+ export declare function nativeButtons(): boolean;
7
+ /** Called by the native backend when it adopts a `hello` reply and when it stops. */
8
+ export declare function setNativeButtons(on: boolean): void;
5
9
  /** Call `listener` whenever native rendering starts or stops; returns the unsubscribe. */
6
10
  export declare function onNativeRenderingChange(listener: (on: boolean) => void): () => void;
@@ -1,10 +1,11 @@
1
1
  /**
2
- * Process-wide flag: a Tern Surface Protocol backend is rendering.
2
+ * Process-wide native rendering state, set only by the native backend.
3
3
  *
4
- * Components that animate by re-rendering on a timer (spinners, shimmer,
5
- * thinking frames, countdowns) check it and skip scheduling, because the
6
- * terminal clocks motion from the described nodes. Set only by the native
7
- * backend when a surface opens and cleared when it closes.
4
+ * Whether a Tern Surface Protocol backend is rendering: components that
5
+ * animate by re-rendering on a timer (spinners, shimmer, thinking frames,
6
+ * countdowns) check it and skip scheduling, because the terminal clocks
7
+ * motion from the described nodes. Set when a surface opens and cleared when
8
+ * it closes.
8
9
  */
9
10
  let active = false;
10
11
  const listeners = new Set<(on: boolean) => void>();
@@ -21,6 +22,25 @@ export function setNativeRendering(on: boolean): void {
21
22
  for (const listener of listeners) listener(on);
22
23
  }
23
24
 
25
+ /**
26
+ * Whether the live terminal draws the `button` kind (its `hello` lists it),
27
+ * and with it `tabs` `variant: "segmented"`. The button builders
28
+ * (`native/overlay.ts`) read it; older Terns get the `row` buttons they style
29
+ * by role. Set only by the native backend from the `hello` it adopts; false
30
+ * while no surface is live.
31
+ */
32
+ let buttons = false;
33
+
34
+ /** Whether omp's buttons go out as `button` nodes (see {@link setNativeButtons}). */
35
+ export function nativeButtons(): boolean {
36
+ return buttons;
37
+ }
38
+
39
+ /** Called by the native backend when it adopts a `hello` reply and when it stops. */
40
+ export function setNativeButtons(on: boolean): void {
41
+ buttons = on;
42
+ }
43
+
24
44
  /** Call `listener` whenever native rendering starts or stops; returns the unsubscribe. */
25
45
  export function onNativeRenderingChange(listener: (on: boolean) => void): () => void {
26
46
  listeners.add(listener);
@@ -18,7 +18,10 @@ import {
18
18
  getBtwLatestTurn,
19
19
  getBtwTopicLabel,
20
20
  getBtwTurns,
21
+ type BtwInjectParts,
22
+ splitBtwInject,
21
23
  } from "./btw-history";
24
+ import { BtwInjectAnswer, type BtwInjectState, describeBtwInjectAnswer } from "./btw-inject";
22
25
  import { compactImageMarkers, formatVisionMarker } from "../prompt/composer-attachments";
23
26
  import { extractImagePastePathsFromText } from "../prompt/custom-editor";
24
27
  import { BracketedPasteHandler } from "../bracketed-paste";
@@ -29,6 +32,8 @@ import {
29
32
  matchesSelectPageDown,
30
33
  matchesSelectPageUp,
31
34
  matchesSelectUp,
35
+ appBtwInjectKey,
36
+ matchesAppBtwInject,
32
37
  } from "../keybinding-matchers";
33
38
  import type { SpaceHoldHandler } from "../space-hold";
34
39
  import { sanitizeErrorLine } from "../chrome/error-block";
@@ -77,6 +82,25 @@ interface BtwHistoryPanelOptions {
77
82
  * first. For a host with no inline panel to fall back to (Tern).
78
83
  */
79
84
  escapeHides?: boolean;
85
+ /** `btw.inject` hooks, given only while it is on for this view. */
86
+ inject?: BtwHistoryInject;
87
+ }
88
+
89
+ interface BtwHistoryInject {
90
+ /**
91
+ * How a finished turn's closed `<inject>` block shows: apart from its prose while pending or
92
+ * sent, plain text when `undefined`. A streaming turn always shows its block.
93
+ */
94
+ state: (record: BtwHistoryRecord, turnIndex: number) => BtwInjectState | undefined;
95
+ /** Whether the inject key may send the record's latest block now. */
96
+ canSend: (record: BtwHistoryRecord) => boolean;
97
+ send: (record: BtwHistoryRecord) => void;
98
+ }
99
+
100
+ /** A turn's `<inject>` block as displayed apart from its prose. */
101
+ interface InjectBlock {
102
+ parts: BtwInjectParts;
103
+ state: BtwInjectState;
80
104
  }
81
105
 
82
106
  interface FollowUpComposer {
@@ -95,6 +119,8 @@ interface RenderedTurn {
95
119
  turn: BtwHistoryTurn;
96
120
  question: Markdown;
97
121
  answer: Markdown;
122
+ /** How the answer's `<inject>` block showed; `undefined` when it rendered as plain text. */
123
+ block: BtwInjectState | undefined;
98
124
  lines: readonly string[];
99
125
  width: number;
100
126
  }
@@ -110,6 +136,8 @@ interface BtwHistoryNativeMemo {
110
136
  followUpPending: boolean;
111
137
  canFollowUp: boolean;
112
138
  copied: boolean;
139
+ canInject: boolean;
140
+ latestInject: BtwInjectState | undefined;
113
141
  scroll: NativeScroll | undefined;
114
142
  node: NativeNode;
115
143
  }
@@ -150,6 +178,7 @@ export class BtwHistoryPanel implements Component, Focusable {
150
178
  #listScroll = 0;
151
179
  #listHeight = 1;
152
180
  #focused = false;
181
+ #useTerminalCursor = false;
153
182
  #composer: FollowUpComposer | undefined;
154
183
  readonly #pasteHandler = new BracketedPasteHandler();
155
184
  #followUpPending = false;
@@ -225,6 +254,12 @@ export class BtwHistoryPanel implements Component, Focusable {
225
254
  this.#focused = value;
226
255
  }
227
256
 
257
+ /** Keep the follow-up input's cursor mode aligned so the hardware cursor (and IME preedit) lands on its caret. */
258
+ setUseTerminalCursor(useTerminalCursor: boolean): void {
259
+ this.#useTerminalCursor = useTerminalCursor;
260
+ this.#composer?.input.setUseTerminalCursor(useTerminalCursor);
261
+ }
262
+
228
263
  update(records: readonly BtwHistoryRecord[]): void {
229
264
  this.#records = records;
230
265
  this.#detailDirty = true;
@@ -329,6 +364,7 @@ export class BtwHistoryPanel implements Component, Focusable {
329
364
  const input = new Input();
330
365
  input.prompt = theme.fg("accent", "Follow up: ");
331
366
  input.placeholder = "Ask about this answer…";
367
+ input.setUseTerminalCursor(this.#useTerminalCursor);
332
368
  if (this.#options.spaceHoldKeys !== undefined) input.spaceHold.keys = this.#options.spaceHoldKeys;
333
369
  input.spaceHold.handler = this.#options.spaceHold?.(input);
334
370
  const composer: FollowUpComposer = {
@@ -504,6 +540,10 @@ export class BtwHistoryPanel implements Component, Focusable {
504
540
  if (record && getBtwCopyText(record) !== undefined) this.#options.onCopy(record);
505
541
  return;
506
542
  }
543
+ if (this.#options.inject && matchesAppBtwInject(data)) {
544
+ this.#sendInject(record);
545
+ return;
546
+ }
507
547
  // Legacy terminals deliver Ctrl+/ (and Ctrl+_) as US without Kitty protocol.
508
548
  if (
509
549
  matchesKey(data, "tab") ||
@@ -568,6 +608,8 @@ export class BtwHistoryPanel implements Component, Focusable {
568
608
  const composer = this.#composer;
569
609
  const canFollowUp = record !== undefined && this.#canFollowUp(record);
570
610
  const copied = record !== undefined && this.#isCopied(record);
611
+ const canInject = record !== undefined && this.#options.inject?.canSend(record) === true;
612
+ const latestInject = record && this.#options.inject?.state(record, getBtwTurns(record).length - 1);
571
613
  const memo = this.#native;
572
614
  if (
573
615
  memo?.records === this.#records &&
@@ -579,6 +621,8 @@ export class BtwHistoryPanel implements Component, Focusable {
579
621
  memo.followUpPending === this.#followUpPending &&
580
622
  memo.canFollowUp === canFollowUp &&
581
623
  memo.copied === copied &&
624
+ memo.canInject === canInject &&
625
+ memo.latestInject === latestInject &&
582
626
  memo.scroll === this.#scroll
583
627
  ) {
584
628
  return memo.node;
@@ -604,7 +648,7 @@ export class BtwHistoryPanel implements Component, Focusable {
604
648
  } else {
605
649
  children.push(this.#describeEmpty());
606
650
  }
607
- children.push(this.#describeActions(record, canFollowUp, copied));
651
+ children.push(this.#describeActions(record, canFollowUp, copied, canInject));
608
652
  // The sheet is the frame (`nativeOverlay`); its last row is the pinned footer.
609
653
  const described = col(children, { gap: "none" });
610
654
  this.#native = {
@@ -617,6 +661,8 @@ export class BtwHistoryPanel implements Component, Focusable {
617
661
  followUpPending: this.#followUpPending,
618
662
  canFollowUp,
619
663
  copied,
664
+ canInject,
665
+ latestInject,
620
666
  scroll: this.#scroll,
621
667
  node: described,
622
668
  };
@@ -633,6 +679,9 @@ export class BtwHistoryPanel implements Component, Focusable {
633
679
  case "copy-answer":
634
680
  if (record && getBtwCopyText(record) !== undefined) this.#options.onCopy(record);
635
681
  break;
682
+ case "inject":
683
+ this.#sendInject(record);
684
+ break;
636
685
  case "follow-up":
637
686
  if (record) this.openFollowUp(record.id);
638
687
  break;
@@ -690,12 +739,31 @@ export class BtwHistoryPanel implements Component, Focusable {
690
739
  /** The selected side question as a short document: the asked question titles each answer. */
691
740
  #describeThread(record: BtwHistoryRecord): NativeNode {
692
741
  const turns = getDisplayTurns(record);
693
- const children: NativeChild[] = turns.map((turn, index) => this.#describeTurn(turn, index, `turn-${index}`));
742
+ const children: NativeChild[] = turns.map((turn, index) =>
743
+ this.#describeTurn(turn, index, `turn-${index}`, this.#injectBlock(record, turn, index)),
744
+ );
694
745
  if (this.#composer) children.push(this.#describeComposer(this.#composer));
695
746
  return node("col", { role: "zeta.btw.thread" }, children, "thread");
696
747
  }
697
748
 
698
- #describeTurn(turn: BtwHistoryTurn, index: number, key: string): NativeNode {
749
+ #sendInject(record: BtwHistoryRecord | undefined): void {
750
+ const inject = this.#options.inject;
751
+ if (!record || !inject?.canSend(record)) return;
752
+ inject.send(record);
753
+ this.#detailDirty = true;
754
+ this.#options.requestRender();
755
+ }
756
+
757
+ /** The turn's `<inject>` block to show apart from its prose, if any (see {@link BtwHistoryInject.state}). */
758
+ #injectBlock(record: BtwHistoryRecord, turn: BtwHistoryTurn, index: number): InjectBlock | undefined {
759
+ const inject = this.#options.inject;
760
+ const parts = inject ? splitBtwInject(turn.answer) : undefined;
761
+ if (!inject || !parts) return undefined;
762
+ const state = turn.status === "running" ? "pending" : parts.closed ? inject.state(record, index) : undefined;
763
+ return state && { parts, state };
764
+ }
765
+
766
+ #describeTurn(turn: BtwHistoryTurn, index: number, key: string, block: InjectBlock | undefined): NativeNode {
699
767
  const meta: TspSpan[] =
700
768
  index === 0
701
769
  ? [span(this.#dateFormat.format(turn.createdAt))]
@@ -709,11 +777,12 @@ export class BtwHistoryPanel implements Component, Focusable {
709
777
  ];
710
778
  // A failed turn with no text says only why it failed.
711
779
  if (turn.answer.trim() || !turn.error) {
712
- const answer = turn.answer.trim()
713
- ? md(sanitizeDisplayText(turn.answer), { stream: turn.status === "running" })
714
- : text([span(turn.status === "running" ? "Thinking…" : "No answer text.", "dim")], {
715
- role: "zeta.btw.pending",
716
- });
780
+ const stream = turn.status === "running";
781
+ const answer = block
782
+ ? describeBtwInjectAnswer(block.parts, block.state === "sent", stream)
783
+ : turn.answer.trim()
784
+ ? md(sanitizeDisplayText(turn.answer), { stream })
785
+ : text([span(stream ? "Thinking…" : "No answer text.", "dim")], { role: "zeta.btw.pending" });
717
786
  children.push(node("col", { role: "zeta.btw.answer" }, [answer], "answer"));
718
787
  }
719
788
  if (turn.error) {
@@ -764,7 +833,12 @@ export class BtwHistoryPanel implements Component, Focusable {
764
833
  * primary action (Follow up, or Send while composing) in the corner. Keys
765
834
  * live in the buttons' tooltips.
766
835
  */
767
- #describeActions(record: BtwHistoryRecord | undefined, canFollowUp: boolean, copied: boolean): NativeNode {
836
+ #describeActions(
837
+ record: BtwHistoryRecord | undefined,
838
+ canFollowUp: boolean,
839
+ copied: boolean,
840
+ canInject: boolean,
841
+ ): NativeNode {
768
842
  if (this.#composer) {
769
843
  return actionBar([
770
844
  null,
@@ -776,6 +850,7 @@ export class BtwHistoryPanel implements Component, Focusable {
776
850
  const hides = this.#options.escapeHides === true;
777
851
  const buttons: (NativeNode | null)[] = [];
778
852
  if (running) buttons.push(actionButton("Stop answer", "stop", { keys: hides ? "x" : "escape" }));
853
+ if (canInject) buttons.push(actionButton("Inject into main", "inject", { keys: appBtwInjectKey() }));
779
854
  if (record && getBtwCopyText(record) !== undefined) {
780
855
  buttons.push(actionButton(copied ? "Copy again" : "Copy answer", "copy-answer", { keys: "c" }));
781
856
  if (copied) buttons.push(text([span("✓ Copied", "success")], { role: "zeta.btw.copied" }));
@@ -839,7 +914,12 @@ export class BtwHistoryPanel implements Component, Focusable {
839
914
  });
840
915
  }
841
916
 
842
- #renderTurn(turn: BtwHistoryTurn, cached: RenderedTurn | undefined, width: number): RenderedTurn {
917
+ #renderTurn(
918
+ turn: BtwHistoryTurn,
919
+ cached: RenderedTurn | undefined,
920
+ width: number,
921
+ block: InjectBlock | undefined,
922
+ ): RenderedTurn {
843
923
  const previous = cached?.turn;
844
924
  if (
845
925
  cached &&
@@ -848,14 +928,16 @@ export class BtwHistoryPanel implements Component, Focusable {
848
928
  turn.answer === previous?.answer &&
849
929
  turn.status === previous?.status &&
850
930
  turn.error === previous?.error &&
851
- turn.createdAt === previous?.createdAt
931
+ turn.createdAt === previous?.createdAt &&
932
+ block?.state === cached.block
852
933
  ) {
853
934
  return cached;
854
935
  }
855
936
  const question = cached?.question ?? new Markdown("", 0, 0, getMarkdownTheme());
856
937
  const answer = cached?.answer ?? new Markdown("", 0, 0, getMarkdownTheme());
857
938
  if (turn.question !== previous?.question) question.setText(sanitizeDisplayText(turn.question));
858
- if (turn.answer !== previous?.answer) answer.setText(sanitizeDisplayText(turn.answer));
939
+ // A block's state can change while the answer stays the same, so the plain text is reset on every miss.
940
+ if (!block) answer.setText(sanitizeDisplayText(turn.answer));
859
941
  const status = STATUS[turn.status];
860
942
  const lines = [
861
943
  ...wrapTextWithAnsi(
@@ -868,7 +950,8 @@ export class BtwHistoryPanel implements Component, Focusable {
868
950
  "",
869
951
  theme.bold(theme.fg("accent", "Answer")),
870
952
  ];
871
- if (turn.answer.trim()) lines.push(...answer.render(width));
953
+ if (block) lines.push(...new BtwInjectAnswer(block.parts, block.state === "sent").render(width));
954
+ else if (turn.answer.trim()) lines.push(...answer.render(width));
872
955
  else
873
956
  lines.push(
874
957
  ...wrapTextWithAnsi(
@@ -890,6 +973,7 @@ export class BtwHistoryPanel implements Component, Focusable {
890
973
  },
891
974
  question,
892
975
  answer,
976
+ block: block?.state,
893
977
  lines,
894
978
  width,
895
979
  };
@@ -907,7 +991,12 @@ export class BtwHistoryPanel implements Component, Focusable {
907
991
  if (record) {
908
992
  const turns = getDisplayTurns(record);
909
993
  for (let index = 0; index < turns.length; index++) {
910
- const cached = this.#renderTurn(turns[index]!, this.#turns[index], inner);
994
+ const cached = this.#renderTurn(
995
+ turns[index]!,
996
+ this.#turns[index],
997
+ inner,
998
+ this.#injectBlock(record, turns[index]!, index),
999
+ );
911
1000
  this.#turns[index] = cached;
912
1001
  if (index > 0) lines.push("", theme.fg("dim", theme.boxRound.horizontal.repeat(inner)), "");
913
1002
  lines.push(...cached.lines);
@@ -967,6 +1056,9 @@ export class BtwHistoryPanel implements Component, Focusable {
967
1056
  ];
968
1057
  if (!composer) {
969
1058
  if (record && this.#canFollowUp(record)) actions.push(rawKeyHint(["f", "enter"], "follow up"));
1059
+ const injectKey = appBtwInjectKey();
1060
+ if (injectKey && record && this.#options.inject?.canSend(record))
1061
+ actions.push(rawKeyHint(injectKey, "inject"));
970
1062
  if (record && getBtwCopyText(record) !== undefined) {
971
1063
  if (this.#isCopied(record))
972
1064
  actions.push(theme.fg("success", `✓ copied · ${formatKeyHint("c")} to copy again`));