@linxiraos/pi-tui 1.4.11 → 1.4.13

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 (265) hide show
  1. package/CHANGELOG.md +30 -233
  2. package/README.md +4 -1
  3. package/THIRD-PARTY-NOTICES.txt +4 -5
  4. package/dist/types/apps/shell-visualizer.d.ts +24 -0
  5. package/dist/types/autocomplete.d.ts +20 -0
  6. package/dist/types/chat/cache-invalidation-marker.d.ts +15 -7
  7. package/dist/types/chat/chat-transcript-builder.d.ts +5 -3
  8. package/dist/types/chat/display-preferences.d.ts +2 -0
  9. package/dist/types/chat/extension-types.d.ts +72 -1
  10. package/dist/types/chat/image-loading.d.ts +2 -2
  11. package/dist/types/chat/messages.d.ts +2 -3
  12. package/dist/types/chat/read-tool-group.d.ts +15 -2
  13. package/dist/types/chat/skill-message.d.ts +1 -0
  14. package/dist/types/chat/spotlight.d.ts +203 -0
  15. package/dist/types/chat/tool-execution.d.ts +26 -5
  16. package/dist/types/chat/transcript-actions.d.ts +11 -0
  17. package/dist/types/chat/transcript-browser.d.ts +9 -0
  18. package/dist/types/chat/transcript-presentation.d.ts +164 -0
  19. package/dist/types/chat/ttsr-notification.d.ts +2 -0
  20. package/dist/types/chrome/message-frame.d.ts +2 -0
  21. package/dist/types/chrome/transcript-container.d.ts +27 -6
  22. package/dist/types/components/loader.d.ts +0 -2
  23. package/dist/types/components/markdown.d.ts +11 -1
  24. package/dist/types/components/settings-list.d.ts +12 -2
  25. package/dist/types/frame-rate.d.ts +18 -0
  26. package/dist/types/hotkeys-markdown.d.ts +2 -0
  27. package/dist/types/index.d.ts +3 -0
  28. package/dist/types/keybinding-matchers.d.ts +4 -1
  29. package/dist/types/kitty-graphics.d.ts +1 -1
  30. package/dist/types/motion-effects.d.ts +10 -0
  31. package/dist/types/native/encode.d.ts +2 -0
  32. package/dist/types/native/measure.d.ts +10 -0
  33. package/dist/types/native/overlay.d.ts +1 -1
  34. package/dist/types/native/quiet.d.ts +5 -0
  35. package/dist/types/native/reconcile.d.ts +6 -1
  36. package/dist/types/native/spans.d.ts +6 -0
  37. package/dist/types/native/state.d.ts +4 -0
  38. package/dist/types/overlays/agent-hub.d.ts +6 -0
  39. package/dist/types/overlays/link-browser.d.ts +55 -0
  40. package/dist/types/overlays/running-subagent-badge.d.ts +1 -4
  41. package/dist/types/overlays/spotlight-sheet.d.ts +36 -0
  42. package/dist/types/prompt/composer-attachments.d.ts +5 -2
  43. package/dist/types/prompt/composer-cache.d.ts +7 -2
  44. package/dist/types/prompt/composer.d.ts +6 -11
  45. package/dist/types/prompt/custom-editor.d.ts +8 -2
  46. package/dist/types/prompt/gradient-highlight.d.ts +2 -2
  47. package/dist/types/prompt/magic-keywords.d.ts +2 -0
  48. package/dist/types/prompt/model-mention-autocomplete.d.ts +9 -7
  49. package/dist/types/prompt/model-mention-syntax.d.ts +6 -0
  50. package/dist/types/prompt/prompt-action-autocomplete.d.ts +2 -1
  51. package/dist/types/prompt/welcome.d.ts +19 -0
  52. package/dist/types/render/extension-links.d.ts +0 -6
  53. package/dist/types/render/index.d.ts +1 -0
  54. package/dist/types/render/link-hints.d.ts +78 -0
  55. package/dist/types/render/render-utils.d.ts +0 -2
  56. package/dist/types/setup/scenes/types.d.ts +8 -0
  57. package/dist/types/setup/scenes/updates.d.ts +6 -0
  58. package/dist/types/setup/wizard.d.ts +7 -2
  59. package/dist/types/spinner-clock.d.ts +34 -0
  60. package/dist/types/status-line/component.d.ts +8 -4
  61. package/dist/types/status-line/host.d.ts +62 -0
  62. package/dist/types/status-line/index.d.ts +1 -0
  63. package/dist/types/status-line/prompt-cache.d.ts +14 -0
  64. package/dist/types/status-line/schema.d.ts +1 -1
  65. package/dist/types/status-line/startup.d.ts +6 -0
  66. package/dist/types/status-line/types.d.ts +8 -21
  67. package/dist/types/theme/schema.d.ts +28 -1
  68. package/dist/types/theme/symbols.d.ts +1 -1
  69. package/dist/types/theme/theme-class.d.ts +12 -2
  70. package/dist/types/theme/theme.d.ts +1 -1
  71. package/dist/types/theme/tui-adapters.d.ts +7 -0
  72. package/dist/types/thinking.d.ts +12 -0
  73. package/dist/types/tools/ask.d.ts +1 -1
  74. package/dist/types/tools/bash.d.ts +21 -0
  75. package/dist/types/tools/find.d.ts +9 -1
  76. package/dist/types/tools/grep.d.ts +2 -1
  77. package/dist/types/tools/grouped-file-output.d.ts +17 -0
  78. package/dist/types/tools/job-widget.d.ts +2 -2
  79. package/dist/types/tools/lsp.d.ts +4 -2
  80. package/dist/types/tools/native-view.d.ts +4 -0
  81. package/dist/types/tools/renderer.d.ts +9 -1
  82. package/dist/types/tools/shell-trace.d.ts +10 -0
  83. package/dist/types/tools/shell-viz-render.d.ts +6 -0
  84. package/dist/types/tools/shell-viz.d.ts +16 -0
  85. package/dist/types/tools/wait.d.ts +2 -2
  86. package/dist/types/tools/web-search-types.d.ts +1 -0
  87. package/dist/types/tools/write.d.ts +2 -0
  88. package/dist/types/tui.d.ts +15 -1
  89. package/package.json +15 -11
  90. package/src/apps/shell-visualizer.d.ts +24 -0
  91. package/src/apps/shell-visualizer.ts +167 -0
  92. package/src/autocomplete.d.ts +20 -0
  93. package/src/autocomplete.ts +14 -0
  94. package/src/chat/assistant-message.ts +11 -6
  95. package/src/chat/cache-invalidation-marker.d.ts +15 -7
  96. package/src/chat/cache-invalidation-marker.ts +18 -9
  97. package/src/chat/chat-transcript-builder.d.ts +5 -3
  98. package/src/chat/chat-transcript-builder.ts +16 -12
  99. package/src/chat/display-preferences.d.ts +2 -0
  100. package/src/chat/display-preferences.ts +3 -0
  101. package/src/chat/extension-types.d.ts +72 -1
  102. package/src/chat/extension-types.ts +74 -1
  103. package/src/chat/image-loading.d.ts +2 -2
  104. package/src/chat/image-loading.ts +2 -2
  105. package/src/chat/messages.d.ts +2 -3
  106. package/src/chat/messages.ts +3 -8
  107. package/src/chat/read-tool-group.d.ts +15 -2
  108. package/src/chat/read-tool-group.ts +201 -41
  109. package/src/chat/skill-message.d.ts +1 -0
  110. package/src/chat/skill-message.ts +4 -0
  111. package/src/chat/spotlight.d.ts +203 -0
  112. package/src/chat/spotlight.ts +460 -0
  113. package/src/chat/tool-execution.d.ts +26 -5
  114. package/src/chat/tool-execution.ts +360 -38
  115. package/src/chat/transcript-actions.d.ts +11 -0
  116. package/src/chat/transcript-actions.ts +13 -1
  117. package/src/chat/transcript-browser.d.ts +9 -0
  118. package/src/chat/transcript-browser.ts +18 -0
  119. package/src/chat/transcript-presentation.d.ts +164 -0
  120. package/src/chat/transcript-presentation.ts +642 -0
  121. package/src/chat/ttsr-notification.d.ts +25 -0
  122. package/src/chat/ttsr-notification.ts +5 -0
  123. package/src/chrome/message-frame.d.ts +2 -0
  124. package/src/chrome/message-frame.ts +7 -0
  125. package/src/chrome/message-notice.d.ts +58 -0
  126. package/src/chrome/transcript-container.d.ts +27 -6
  127. package/src/chrome/transcript-container.ts +317 -66
  128. package/src/components/editor.ts +25 -1
  129. package/src/components/loader.d.ts +0 -2
  130. package/src/components/loader.ts +30 -18
  131. package/src/components/markdown.d.ts +11 -1
  132. package/src/components/markdown.ts +41 -16
  133. package/src/components/settings-list.d.ts +12 -2
  134. package/src/components/settings-list.ts +29 -13
  135. package/src/frame-rate.d.ts +18 -0
  136. package/src/frame-rate.ts +36 -0
  137. package/src/hotkeys-markdown.ts +9 -2
  138. package/src/index.d.ts +3 -0
  139. package/src/index.ts +3 -0
  140. package/src/keybinding-matchers.d.ts +4 -1
  141. package/src/keybinding-matchers.ts +13 -12
  142. package/src/kitty-graphics.d.ts +1 -1
  143. package/src/kitty-graphics.ts +3 -2
  144. package/src/motion-effects.d.ts +10 -0
  145. package/src/motion-effects.ts +27 -0
  146. package/src/native/backend.ts +66 -7
  147. package/src/native/encode.d.ts +2 -0
  148. package/src/native/encode.ts +2 -0
  149. package/src/native/measure.d.ts +10 -0
  150. package/src/native/measure.ts +185 -0
  151. package/src/native/overlay.d.ts +1 -1
  152. package/src/native/overlay.ts +1 -1
  153. package/src/native/quiet.d.ts +5 -0
  154. package/src/native/quiet.ts +105 -0
  155. package/src/native/reconcile.d.ts +6 -1
  156. package/src/native/reconcile.ts +16 -10
  157. package/src/native/spans.d.ts +6 -0
  158. package/src/native/spans.ts +40 -0
  159. package/src/native/state.d.ts +4 -0
  160. package/src/native/state.ts +18 -0
  161. package/src/overlays/agent-hub.ts +15 -2
  162. package/src/overlays/ask-dialog.ts +1 -0
  163. package/src/overlays/btw-history-panel.ts +73 -6
  164. package/src/overlays/link-browser.ts +295 -0
  165. package/src/overlays/running-subagent-badge.ts +2 -9
  166. package/src/overlays/settings-defs.ts +1 -1
  167. package/src/overlays/settings-selector.ts +17 -3
  168. package/src/overlays/spotlight-sheet.ts +478 -0
  169. package/src/overlays/usage-dashboard.ts +6 -5
  170. package/src/prompt/composer-attachments.d.ts +5 -2
  171. package/src/prompt/composer-attachments.ts +6 -6
  172. package/src/prompt/composer-cache.ts +17 -16
  173. package/src/prompt/composer.ts +30 -123
  174. package/src/prompt/custom-editor.ts +17 -13
  175. package/src/prompt/gradient-highlight.d.ts +2 -2
  176. package/src/prompt/gradient-highlight.ts +5 -4
  177. package/src/prompt/magic-keywords.d.ts +2 -0
  178. package/src/prompt/magic-keywords.ts +4 -1
  179. package/src/prompt/model-mention-autocomplete.ts +73 -20
  180. package/src/prompt/model-mention-syntax.d.ts +6 -0
  181. package/src/prompt/model-mention-syntax.ts +9 -0
  182. package/src/prompt/prompt-action-autocomplete.ts +49 -33
  183. package/src/prompt/tips.txt +1 -0
  184. package/src/prompt/welcome.ts +104 -2
  185. package/src/render/extension-links.d.ts +0 -6
  186. package/src/render/extension-links.ts +0 -20
  187. package/src/render/index.d.ts +1 -0
  188. package/src/render/index.ts +1 -0
  189. package/src/render/link-hints.d.ts +78 -0
  190. package/src/render/link-hints.ts +299 -0
  191. package/src/render/render-utils.d.ts +0 -2
  192. package/src/render/render-utils.ts +0 -5
  193. package/src/setup/scenes/glyph.ts +1 -1
  194. package/src/setup/scenes/types.ts +8 -0
  195. package/src/setup/scenes/updates.ts +116 -0
  196. package/src/setup/wizard.ts +19 -8
  197. package/src/spinner-clock.d.ts +34 -0
  198. package/src/spinner-clock.ts +79 -0
  199. package/src/status-line/component.ts +145 -53
  200. package/src/status-line/host.ts +51 -0
  201. package/src/status-line/index.ts +1 -0
  202. package/src/status-line/presets.ts +3 -1
  203. package/src/status-line/prompt-cache.ts +154 -0
  204. package/src/status-line/schema.ts +1 -1
  205. package/src/status-line/segments.ts +33 -22
  206. package/src/status-line/startup.ts +22 -4
  207. package/src/status-line/types.ts +8 -22
  208. package/src/stdin-buffer.ts +89 -46
  209. package/src/terminal-capabilities.ts +3 -3
  210. package/src/terminal.ts +1 -8
  211. package/src/theme/loader.ts +3 -2
  212. package/src/theme/schema.d.ts +28 -1
  213. package/src/theme/schema.ts +30 -1
  214. package/src/theme/symbols.d.ts +1 -1
  215. package/src/theme/symbols.ts +15 -3
  216. package/src/theme/theme-class.d.ts +12 -2
  217. package/src/theme/theme-class.ts +23 -0
  218. package/src/theme/theme-schema.json +1 -1
  219. package/src/theme/theme.d.ts +1 -1
  220. package/src/theme/theme.ts +3 -7
  221. package/src/theme/tui-adapters.d.ts +7 -0
  222. package/src/theme/tui-adapters.ts +33 -1
  223. package/src/thinking.d.ts +12 -0
  224. package/src/thinking.ts +31 -0
  225. package/src/tools/ask.d.ts +1 -1
  226. package/src/tools/ask.ts +99 -38
  227. package/src/tools/ast-edit.ts +51 -32
  228. package/src/tools/ast-grep.ts +31 -19
  229. package/src/tools/bash.d.ts +21 -0
  230. package/src/tools/bash.ts +166 -24
  231. package/src/tools/find.d.ts +9 -1
  232. package/src/tools/find.ts +23 -2
  233. package/src/tools/grep.d.ts +2 -1
  234. package/src/tools/grep.ts +52 -36
  235. package/src/tools/grouped-file-output.d.ts +17 -0
  236. package/src/tools/grouped-file-output.ts +20 -2
  237. package/src/tools/job-widget.d.ts +2 -2
  238. package/src/tools/job-widget.ts +2 -2
  239. package/src/tools/lsp.d.ts +4 -2
  240. package/src/tools/lsp.ts +537 -642
  241. package/src/tools/native-view.d.ts +4 -0
  242. package/src/tools/native-view.ts +8 -2
  243. package/src/tools/renderer.d.ts +9 -1
  244. package/src/tools/renderer.ts +9 -1
  245. package/src/tools/shell-trace.d.ts +10 -0
  246. package/src/tools/shell-trace.ts +80 -0
  247. package/src/tools/shell-viz-render.d.ts +6 -0
  248. package/src/tools/shell-viz-render.ts +156 -0
  249. package/src/tools/shell-viz.d.ts +16 -0
  250. package/src/tools/shell-viz.ts +181 -0
  251. package/src/tools/streaming-output.ts +18 -8
  252. package/src/tools/wait.d.ts +2 -2
  253. package/src/tools/wait.ts +39 -34
  254. package/src/tools/web-search-types.d.ts +1 -0
  255. package/src/tools/web-search-types.ts +1 -0
  256. package/src/tools/write.d.ts +2 -0
  257. package/src/tools/write.ts +2 -0
  258. package/src/tui.d.ts +15 -1
  259. package/src/tui.ts +63 -6
  260. package/src/windows-input-mode.ts +7 -1
  261. package/dist/types/chat/collab-prompt-message.d.ts +0 -14
  262. package/dist/types/chrome/collab-qrcode.d.ts +0 -35
  263. package/src/chat/collab-prompt-message.d.ts +0 -14
  264. package/src/chat/collab-prompt-message.ts +0 -46
  265. package/src/chrome/collab-qrcode.ts +0 -99
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Keyboard link hints: tags drawn over the extension link labels ({@link extensionLinkLabels}) on
3
+ * the rows a surface shows, so typing a tag picks its link. The composer tags the live viewport;
4
+ * the fullscreen link browser tags the transcript rows it scrolls to.
5
+ */
6
+ import { theme } from "../theme/theme";
7
+ import { sliceByColumn, visibleWidth } from "../utils";
8
+ import { compositeLineAt } from "./composite";
9
+ import { type ExtensionLinkLabel, extensionLinkLabels } from "./extension-links";
10
+
11
+ /** Hint tag letters, home row first: what a tag falls back to after its label's own letters. */
12
+ const LINK_HINT_ALPHABET = "asdfghjklqwertyuiopzxcvbnm";
13
+ /** Most tags one session holds: every two-letter tag. Links past it stay untagged. */
14
+ const MAX_TAGS = LINK_HINT_ALPHABET.length * LINK_HINT_ALPHABET.length;
15
+
16
+ /** An extension link label drawn on a shown row: what a click or hint tag lands on. */
17
+ export interface ViewportLink {
18
+ readonly url: string;
19
+ /** Shown row the label is drawn on (its first row, for a label wrapped across rows). */
20
+ readonly row: number;
21
+ /** First cell of the label's part on that row. */
22
+ readonly start: number;
23
+ }
24
+
25
+ /** A label {@link viewportLinkTargets} found: where it is drawn, its marker id and its text. */
26
+ export interface ViewportLinkTarget extends ViewportLink {
27
+ /** The label's marker id ({@link ExtensionLinkLabel.id}). */
28
+ readonly id: string;
29
+ /** The label's text, across every shown row it wraps to; its tag prefers these letters. */
30
+ readonly text: string;
31
+ /** Where each shown row's part of the label starts, top to bottom; the first is `row`/`start`. */
32
+ readonly parts: readonly { readonly row: number; readonly start: number }[];
33
+ }
34
+
35
+ /** An extension link label tagged for picking by keyboard. */
36
+ interface LinkHint {
37
+ readonly tag: string;
38
+ readonly link: ViewportLinkTarget;
39
+ /**
40
+ * The row each shown row part of the label is on in the whole content (shown row plus origin):
41
+ * with the part's first cell, marker id and URL, what tells the label apart across repaints;
42
+ * see {@link LinkHints.update}.
43
+ */
44
+ readonly rows: readonly number[];
45
+ }
46
+
47
+ /** What tells one row part of a label apart across repaints. */
48
+ function partKey(row: number, start: number, link: ViewportLinkTarget): string {
49
+ return `${row}\0${start}\0${link.id}\0${link.url}`;
50
+ }
51
+
52
+ /**
53
+ * The extension link labels drawn on `rows`, top to bottom, a wrapped label once at its first row:
54
+ * a row's first label continues the previous row's last label when that has the same marker id
55
+ * and ends its row.
56
+ */
57
+ export function viewportLinkTargets(rows: readonly string[]): ViewportLinkTarget[] {
58
+ const targets: {
59
+ url: string;
60
+ row: number;
61
+ start: number;
62
+ id: string;
63
+ text: string;
64
+ parts: { row: number; start: number }[];
65
+ }[] = [];
66
+ let previous: ExtensionLinkLabel | undefined;
67
+ for (let row = 0; row < rows.length; row++) {
68
+ const line = rows[row]!;
69
+ const labels = extensionLinkLabels(line);
70
+ for (const [index, label] of labels.entries()) {
71
+ const text = Bun.stripANSI(sliceByColumn(line, label.start, label.end - label.start));
72
+ const continued = targets.at(-1);
73
+ if (index === 0 && previous?.endsRow && previous.id === label.id && continued) {
74
+ continued.text += text;
75
+ continued.parts.push({ row, start: label.start });
76
+ continue;
77
+ }
78
+ targets.push({
79
+ url: label.url,
80
+ row,
81
+ start: label.start,
82
+ id: label.id,
83
+ text,
84
+ parts: [{ row, start: label.start }],
85
+ });
86
+ }
87
+ previous = labels.at(-1);
88
+ }
89
+ return targets;
90
+ }
91
+
92
+ /** The letters a label's tag tries, in order: the label's own (its first one first), then the alphabet. */
93
+ function tagLetters(text: string): string[] {
94
+ const letters = new Set<string>();
95
+ for (const char of text.toLowerCase()) if (char >= "a" && char <= "z") letters.add(char);
96
+ for (const char of LINK_HINT_ALPHABET) letters.add(char);
97
+ return [...letters];
98
+ }
99
+
100
+ /**
101
+ * The first tag for a label reading `text` that keeps `used` prefix-free: a single letter that is
102
+ * no tag and starts none, else two letters whose first is no single-letter tag; `undefined` when
103
+ * none is left. With `twoLetters`, only two-letter tags are tried.
104
+ */
105
+ function pickTag(text: string, used: ReadonlySet<string>, twoLetters = false): string | undefined {
106
+ const letters = tagLetters(text);
107
+ if (!twoLetters) {
108
+ const firsts = new Set<string>();
109
+ for (const tag of used) firsts.add(tag[0]!);
110
+ const single = letters.find(letter => !firsts.has(letter));
111
+ if (single !== undefined) return single;
112
+ }
113
+ for (const first of letters) {
114
+ if (used.has(first)) continue;
115
+ for (const second of letters) if (!used.has(`${first}${second}`)) return `${first}${second}`;
116
+ }
117
+ return undefined;
118
+ }
119
+
120
+ /**
121
+ * The tags of one hint session and the letters typed so far. A tag is drawn over the first cell of
122
+ * its label, so it prefers the letters it covers: the label's first letter, then its others, then
123
+ * the home row. Tags never prefix one another.
124
+ */
125
+ export class LinkHints {
126
+ #hints: LinkHint[] | undefined;
127
+ #typed = "";
128
+
129
+ /** Whether labels have been tagged since construction. */
130
+ get tagged(): boolean {
131
+ return this.#hints !== undefined;
132
+ }
133
+
134
+ /** Tag every label `rows` draw afresh and forget the letters typed; returns how many were tagged. */
135
+ assign(rows: readonly string[]): number {
136
+ this.#hints = undefined;
137
+ this.#typed = "";
138
+ this.update(rows);
139
+ return this.#hints!.length;
140
+ }
141
+
142
+ /**
143
+ * Keep the tags while `rows` still draw the tagged labels first, in the same order and columns
144
+ * (they may sit on other rows, and links may be added after them), following them to the rows
145
+ * they are on now. Returns false, keeping nothing to pick, when they no longer are.
146
+ */
147
+ follow(rows: readonly string[]): boolean {
148
+ const hints = this.#hints;
149
+ if (hints === undefined) return false;
150
+ const targets = viewportLinkTargets(rows);
151
+ const unchanged =
152
+ targets.length >= hints.length &&
153
+ hints.every(({ link }, index) => link.url === targets[index]!.url && link.start === targets[index]!.start);
154
+ if (!unchanged) {
155
+ this.#hints = [];
156
+ return false;
157
+ }
158
+ this.#hints = hints.map(({ tag, rows: partRows }, index) => ({ tag, rows: partRows, link: targets[index]! }));
159
+ return true;
160
+ }
161
+
162
+ /**
163
+ * Tag what `rows` draw now, keeping each label's tag while it stays in view: tags of labels no
164
+ * longer drawn are dropped and only newly drawn labels get one, top to bottom. A label is the
165
+ * same across repaints when one of its row parts is: that part's row (shown row plus `origin`,
166
+ * so a scrolling surface passes the row its first shown row has in the whole content), first
167
+ * cell, marker id and URL; marker ids alone repeat across replies. Matching any part keeps a
168
+ * wrapped label's tag while only some of its rows stay in view.
169
+ *
170
+ * The one time existing tags change: a new label finds no tag that keeps the set prefix-free
171
+ * (every letter is already a single-letter tag, say a 27th label joins 26). Then every label is
172
+ * tagged afresh with two letters, and the letters typed are forgotten.
173
+ */
174
+ update(rows: readonly string[], origin = 0): void {
175
+ const kept = new Map<string, string>();
176
+ for (const { link, rows: partRows, tag } of this.#hints ?? []) {
177
+ for (const [index, part] of link.parts.slice(0, partRows.length).entries()) {
178
+ kept.set(partKey(partRows[index]!, part.start, link), tag);
179
+ }
180
+ }
181
+ const targets = viewportLinkTargets(rows).map(link => {
182
+ const partRows = link.parts.map(part => part.row + origin);
183
+ return {
184
+ link,
185
+ rows: partRows,
186
+ keys: link.parts.map((part, index) => partKey(partRows[index]!, part.start, link)),
187
+ };
188
+ });
189
+ const used = new Set<string>();
190
+ const tags = targets.map(({ keys }) => {
191
+ const tag = keys.map(key => kept.get(key)).find(found => found !== undefined && !used.has(found));
192
+ if (tag !== undefined) used.add(tag);
193
+ return tag;
194
+ });
195
+ let hints: LinkHint[] = [];
196
+ let exhausted = false;
197
+ for (const [index, { link, rows: partRows }] of targets.entries()) {
198
+ let tag = tags[index];
199
+ if (tag === undefined) {
200
+ // Past the cap a label stays untagged.
201
+ if (used.size >= MAX_TAGS) continue;
202
+ tag = pickTag(link.text, used);
203
+ if (tag === undefined) {
204
+ exhausted = true;
205
+ break;
206
+ }
207
+ used.add(tag);
208
+ }
209
+ hints.push({ tag, link, rows: partRows });
210
+ }
211
+ if (exhausted) {
212
+ hints = [];
213
+ used.clear();
214
+ for (const { link, rows: partRows } of targets.slice(0, MAX_TAGS)) {
215
+ // Two letters each leave 676 prefix-free tags, so one is always left.
216
+ const tag = pickTag(link.text, used, true)!;
217
+ used.add(tag);
218
+ hints.push({ tag, link, rows: partRows });
219
+ }
220
+ this.#typed = "";
221
+ }
222
+ this.#hints = hints;
223
+ if (!hints.some(({ tag }) => tag.startsWith(this.#typed))) this.#typed = "";
224
+ }
225
+
226
+ /**
227
+ * The content moved under the tags, as when a reply above some labels is redrawn taller or
228
+ * shorter: `move` maps the row a label was last drawn on in the whole content to the row it is
229
+ * on now, so the next {@link update} finds it there with its tag.
230
+ */
231
+ moveRows(move: (row: number) => number): void {
232
+ if (this.#hints) this.#hints = this.#hints.map(hint => ({ ...hint, rows: hint.rows.map(move) }));
233
+ }
234
+
235
+ /** Whether some row holds more tag cells than `width`, so its tags could not all be read side by side. */
236
+ crowded(width: number): boolean {
237
+ const cells = new Map<number, number>();
238
+ for (const { tag, link } of this.#hints ?? []) cells.set(link.row, (cells.get(link.row) ?? 0) + tag.length);
239
+ for (const count of cells.values()) if (count > width) return true;
240
+ return false;
241
+ }
242
+
243
+ /**
244
+ * Type one letter of a tag. Returns the link whose whole tag is now typed, `true` while the
245
+ * letters still lead to several tags, and `false` when none starts with them. A pick or a miss
246
+ * forgets the letters typed.
247
+ */
248
+ type(letter: string): ViewportLink | boolean {
249
+ const typed = this.#typed + letter.toLowerCase();
250
+ const matching = (this.#hints ?? []).filter(hint => hint.tag.startsWith(typed));
251
+ const picked = matching.length === 1 && matching[0]!.tag === typed ? matching[0]!.link : undefined;
252
+ if (matching.length === 0 || picked !== undefined) {
253
+ this.#typed = "";
254
+ return picked === undefined ? false : { url: picked.url, row: picked.row, start: picked.start };
255
+ }
256
+ this.#typed = typed;
257
+ return true;
258
+ }
259
+
260
+ /**
261
+ * Draw every tag the typed letters still lead to over the start of its label, within the first
262
+ * `width` cells of each row (cells past it, such as a scrollbar, are kept). Tags on one row never
263
+ * overlap: one that would land on an earlier tag moves right, and tags that would run past
264
+ * `width` move left, so each stays readable as long as the row has room for them all.
265
+ */
266
+ paint(rows: readonly string[], width: number): string[] {
267
+ const painted = [...rows];
268
+ const byRow = new Map<number, { tag: string; col: number }[]>();
269
+ for (const { tag, link } of this.#hints ?? []) {
270
+ if (rows[link.row] === undefined || !tag.startsWith(this.#typed)) continue;
271
+ let row = byRow.get(link.row);
272
+ if (!row) byRow.set(link.row, (row = []));
273
+ row.push({ tag, col: link.start });
274
+ }
275
+ for (const [index, tags] of byRow) {
276
+ tags.sort((a, b) => a.col - b.col);
277
+ let free = 0;
278
+ for (const placed of tags) {
279
+ placed.col = Math.max(placed.col, free);
280
+ free = placed.col + placed.tag.length;
281
+ }
282
+ let limit = width;
283
+ for (let i = tags.length - 1; i >= 0; i--) {
284
+ const placed = tags[i]!;
285
+ placed.col = Math.max(0, Math.min(placed.col, limit - placed.tag.length));
286
+ limit = placed.col;
287
+ }
288
+ let line = painted[index]!;
289
+ const lineWidth = Math.max(width, visibleWidth(line));
290
+ for (const { tag, col } of tags) {
291
+ // Raw SGR like the hover highlight: chalk's inverse/bold drop out when it detects no color.
292
+ const styled = `\x1b[1;7m${theme.fg("accent", tag)}\x1b[22;27m`;
293
+ line = compositeLineAt(line, styled, col, tag.length, lineWidth);
294
+ }
295
+ painted[index] = line;
296
+ }
297
+ return painted;
298
+ }
299
+ }
@@ -167,8 +167,6 @@ export declare function capPreviewLines(lines: string[], theme: Theme, options?:
167
167
  prefix?: string;
168
168
  expandHint?: boolean;
169
169
  }): string[];
170
- /** Join metadata with the theme separator and muted styling. */
171
- export declare function formatMeta(meta: string[], theme: Theme): string;
172
170
  /**
173
171
  * Split multi-line tool text into TUI-safe display lines.
174
172
  * Splits CRLF/LF, collapses stray `\r` progress overwrites to the final
@@ -388,11 +388,6 @@ export function capPreviewLines(
388
388
  return [`${options.prefix ?? ""}${theme.fg("dim", marker)}`, ...visible];
389
389
  }
390
390
 
391
- /** Join metadata with the theme separator and muted styling. */
392
- export function formatMeta(meta: string[], theme: Theme): string {
393
- return meta.length > 0 ? ` ${theme.fg("muted", meta.join(theme.sep.dot))}` : "";
394
- }
395
-
396
391
  function sanitizeErrorText(message: string | undefined): string {
397
392
  const clean = (message ?? "").replace(/^Error:\s*/, "").trim();
398
393
  return clean ? replaceTabs(truncateToWidth(clean, TRUNCATE_LENGTHS.LINE)) : "Unknown error";
@@ -21,7 +21,7 @@ const GLYPH_LABELS: Readonly<Record<SymbolPreset, string>> = {
21
21
  const GLYPH_SAMPLES: Readonly<Record<SymbolPreset, string>> = {
22
22
  nerd: "   󰉋 ",
23
23
  unicode: "✔ ✖ 📁 ⬢ ╭─╮ ├─ • ⠋ →",
24
- ascii: "[+] [-] > + [D] +-+ |-- * ->",
24
+ ascii: "[+] [-] > + [D] +-+ |- * ->",
25
25
  };
26
26
 
27
27
  /** One picker row per preset; the description column shows live sample glyphs instead of prose. */
@@ -32,6 +32,8 @@ export interface SetupHost extends SetupUiHost {
32
32
  readonly disabledProviders: readonly string[];
33
33
  /** Effective UI/settings language; the onboarding language scene starts here. */
34
34
  readonly language: SetupLanguage;
35
+ /** Whether background self-update (`update.auto`) is on. */
36
+ readonly autoUpdate: boolean;
35
37
  readonly authStorage: AuthStorage;
36
38
  readonly modelSource: ModelBrowserSource;
37
39
  /** Available and catalog models of every kind; role chips resolve over all of them, rows list chat models. */
@@ -44,6 +46,12 @@ export interface SetupHost extends SetupUiHost {
44
46
  saveLanguage(language: SetupLanguage): Promise<void> | void;
45
47
  saveColorBlindMode(enabled: boolean): void;
46
48
  saveTheme(mode: "dark" | "light", name: string): void;
49
+ /**
50
+ * Whether this omp can install its own updates; false where something else
51
+ * owns them: Tern (which updates its omp itself), Nix, a source checkout.
52
+ */
53
+ canAutoUpdate(): Promise<boolean>;
54
+ saveAutoUpdate(enabled: boolean): Promise<void>;
47
55
  captureBrowserSession(request: OAuthBrowserSessionRequest, signal?: AbortSignal): Promise<string>;
48
56
  openInBrowser(url: string): void;
49
57
  markComplete(version: number): Promise<void>;
@@ -0,0 +1,116 @@
1
+ import { type SgrMouseEvent } from "../../mouse";
2
+ import { type SelectItem, SelectList } from "../../components/select-list";
3
+ import { Text } from "../../components/text";
4
+ import { WizardStep } from "../../components/wizard-step";
5
+ import { getSelectListTheme, theme } from "../../theme/theme";
6
+ import { col, span, text } from "../../native/describe";
7
+ import type { NativeNode } from "../../native/node";
8
+ import { Memo } from "../../native/memo";
9
+ import type { SetupScene, SetupSceneController, SetupSceneHost } from "./types";
10
+
11
+ const INTRO =
12
+ "Updates install through whatever installed omp: the standalone binary, Homebrew, mise, bun, or npm. Change this later in /settings.";
13
+
14
+ const UPDATE_ITEMS: readonly SelectItem[] = [
15
+ {
16
+ value: "auto",
17
+ label: "1 Update automatically",
18
+ description: "Installs in the background; the next launch runs it",
19
+ },
20
+ {
21
+ value: "notify",
22
+ label: "2 Notify me",
23
+ description: "Show a notice on startup; run zetacode update yourself",
24
+ },
25
+ ];
26
+
27
+ class UpdatesSceneController implements SetupSceneController {
28
+ title = "Keep omp up to date";
29
+ subtitle = "Choose how new releases reach you.";
30
+ #selectList: SelectList;
31
+ #committing = false;
32
+ #step: WizardStep | undefined;
33
+ #native = new Memo();
34
+
35
+ readonly #host: SetupSceneHost;
36
+
37
+ constructor(host: SetupSceneHost) {
38
+ this.#host = host;
39
+ this.#selectList = new SelectList(UPDATE_ITEMS, UPDATE_ITEMS.length, getSelectListTheme());
40
+ this.#selectList.setSelectedIndex(host.ctx.autoUpdate ? 0 : 1);
41
+ this.#selectList.onSelect = item => {
42
+ void this.#commit(item.value === "auto");
43
+ };
44
+ // Esc skips the scene; the configured setting stays untouched.
45
+ this.#selectList.onCancel = () => host.finish("skipped");
46
+ }
47
+
48
+ invalidate(): void {
49
+ this.#native.clear();
50
+ if (this.#step) this.#step.invalidate();
51
+ else this.#selectList.invalidate();
52
+ }
53
+
54
+ handleInput(data: string): void {
55
+ if (this.#committing) return;
56
+ const quickIndex = data === "1" || data === "2" ? Number(data) - 1 : -1;
57
+ if (quickIndex >= 0) {
58
+ this.#selectList.setSelectedIndex(quickIndex);
59
+ this.#host.requestRender();
60
+ return;
61
+ }
62
+ if (this.#step) this.#step.handleInput(data);
63
+ else this.#selectList.handleInput(data);
64
+ }
65
+
66
+ routeMouse(event: SgrMouseEvent, line: number, col: number): void {
67
+ if (this.#committing) return;
68
+ this.#step?.routeMouse(event, line, col);
69
+ }
70
+
71
+ render(width: number, maxLines?: number): readonly string[] {
72
+ this.#step ??= new WizardStep({
73
+ kind: "choice",
74
+ intro: new Text(theme.fg("muted", INTRO), 0, 0),
75
+ content: this.#selectList,
76
+ minContentLines: UPDATE_ITEMS.length,
77
+ fitContent: () => {
78
+ this.#selectList.setMaxVisible(UPDATE_ITEMS.length);
79
+ },
80
+ });
81
+ this.#step.setMaxHeight(maxLines);
82
+ return this.#step.render(width);
83
+ }
84
+
85
+ describe(): NativeNode {
86
+ return this.#native.get([this.#selectList], () =>
87
+ col([text([span(INTRO, "muted")], { wrap: "word" }), this.#selectList], {
88
+ gap: "sm",
89
+ role: "zeta.setup.updates",
90
+ }),
91
+ );
92
+ }
93
+
94
+ async #commit(enabled: boolean): Promise<void> {
95
+ if (this.#committing) return;
96
+ this.#committing = true;
97
+ try {
98
+ await this.#host.ctx.saveAutoUpdate(enabled);
99
+ } finally {
100
+ this.#host.finish("done");
101
+ }
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Opt in to background self-update (`update.auto`). Skipped where omp cannot
107
+ * update itself, notably under Tern, which keeps its omp current on its own.
108
+ */
109
+ export const updatesSetupScene: SetupScene = {
110
+ id: "auto-update",
111
+ title: "Keep omp up to date",
112
+ step: "Updates",
113
+ minVersion: 3,
114
+ shouldRun: ctx => ctx.canAutoUpdate(),
115
+ mount: host => new UpdatesSceneController(host),
116
+ };
@@ -6,6 +6,7 @@ import { languageSetupScene } from "./scenes/language";
6
6
  import { modelSetupScene } from "./scenes/model";
7
7
  import { providersSetupScene } from "./scenes/sign-in";
8
8
  import { themeSetupScene } from "./scenes/theme";
9
+ import { updatesSetupScene } from "./scenes/updates";
9
10
  import type { SetupScene } from "./scenes/types";
10
11
  import { SetupWizardComponent, setupSceneApplies } from "./wizard-overlay";
11
12
 
@@ -22,6 +23,7 @@ export const ALL_SCENES = [
22
23
  glyphSetupScene,
23
24
  composerSetupScene,
24
25
  themeSetupScene,
26
+ updatesSetupScene,
25
27
  ] as const satisfies readonly SetupScene[];
26
28
 
27
29
  /** Environment and invocation gates for onboarding scene selection. */
@@ -39,20 +41,29 @@ function setupSkipEnvEnabled(value: string | undefined): boolean {
39
41
  return normalized !== "" && normalized !== "0" && normalized !== "false" && normalized !== "no";
40
42
  }
41
43
 
42
- /** Select scenes newer than the stored version, honoring hard environment gates. */
44
+ /**
45
+ * Whether this launch may show onboarding at all: a TTY and, unless forced,
46
+ * not resuming, not skipped by `OMP_SKIP_SETUP` or `startup.setupWizard`.
47
+ */
48
+ export function setupWizardAllowed(options: SetupSceneSelectionOptions = {}): boolean {
49
+ const isTTY = options.isTTY ?? (process.stdin.isTTY && process.stdout.isTTY);
50
+ if (!isTTY) return false;
51
+ if (options.force) return true;
52
+ return (
53
+ !options.resuming &&
54
+ !setupSkipEnvEnabled(options.skipEnv ?? Bun.env.OMP_SKIP_SETUP) &&
55
+ options.setupWizardEnabled !== false
56
+ );
57
+ }
58
+
59
+ /** Select scenes newer than the stored version, honoring hard environment gates ({@link setupWizardAllowed}). */
43
60
  export async function selectSetupScenes(
44
61
  storedVersion: number,
45
62
  scenes: readonly SetupScene[],
46
63
  ctx?: SetupHost,
47
64
  options: SetupSceneSelectionOptions = {},
48
65
  ): Promise<SetupScene[]> {
49
- const isTTY = options.isTTY ?? (process.stdin.isTTY && process.stdout.isTTY);
50
- if (!isTTY) return [];
51
- if (!options.force) {
52
- if (options.resuming) return [];
53
- if (setupSkipEnvEnabled(options.skipEnv ?? Bun.env.OMP_SKIP_SETUP)) return [];
54
- if (options.setupWizardEnabled === false) return [];
55
- }
66
+ if (!setupWizardAllowed(options)) return [];
56
67
 
57
68
  const selected: SetupScene[] = [];
58
69
  for (const scene of scenes) {
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The shared spinner clock (`tui.spinnerInterval`): one period and one phase for every spinner the
3
+ * TUI draws and for the host's terminal-title spinner. Dependency-free: the host's flag table
4
+ * imports it during CLI bootstrap.
5
+ */
6
+ /** Default spinner period, in milliseconds (the historical cadence). */
7
+ export declare const DEFAULT_SPINNER_INTERVAL_MS = 80;
8
+ /** Interval value for a static spinner: frame 0 is drawn and no spinner timer runs. */
9
+ export declare const SPINNER_INTERVAL_STATIC = 0;
10
+ /** The live spinner period in milliseconds; {@link SPINNER_INTERVAL_STATIC} when spinners are still. */
11
+ export declare function spinnerInterval(): number;
12
+ /** Whether spinners advance at all. */
13
+ export declare function spinnerAnimated(): boolean;
14
+ /** Set the period for every spinner; callers pass a value {@link parseSpinnerInterval} accepted. */
15
+ export declare function setSpinnerInterval(next: number): void;
16
+ /** Observe period changes, for timers that would otherwise stay parked; returns the unsubscribe. */
17
+ export declare function onSpinnerIntervalChange(listener: () => void): () => void;
18
+ /**
19
+ * Glyph index on the shared clock, or frame 0 when spinners are static. Every spinner reads
20
+ * wall-clock time, so they share a phase as well as a period.
21
+ */
22
+ export declare function sharedSpinnerFrame(frameCount: number, now?: number): number;
23
+ /**
24
+ * Milliseconds until the next multiple of `periodMs` on the wall clock. Timers armed from this fire
25
+ * together whoever owns them, so N spinners cost one frame per period instead of N.
26
+ */
27
+ export declare function spinnerTickDelay(periodMs: number, now?: number): number;
28
+ /**
29
+ * Canonicalize a configured spinner interval: 0 (static) or an integer ≥ 50. Numeric strings are
30
+ * accepted so one parser serves the CLI flag, the environment variable, and the setting.
31
+ *
32
+ * @throws Error on a non-numeric, negative, fractional, or too-small value.
33
+ */
34
+ export declare function parseSpinnerInterval(value: unknown): number;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The shared spinner clock (`tui.spinnerInterval`): one period and one phase for every spinner the
3
+ * TUI draws and for the host's terminal-title spinner. Dependency-free: the host's flag table
4
+ * imports it during CLI bootstrap.
5
+ */
6
+
7
+ /** Default spinner period, in milliseconds (the historical cadence). */
8
+ export const DEFAULT_SPINNER_INTERVAL_MS = 80;
9
+ /** Interval value for a static spinner: frame 0 is drawn and no spinner timer runs. */
10
+ export const SPINNER_INTERVAL_STATIC = 0;
11
+ const SPINNER_INTERVAL_MIN_MS = 50;
12
+
13
+ let intervalMs = DEFAULT_SPINNER_INTERVAL_MS;
14
+ const listeners = new Set<() => void>();
15
+
16
+ /** The live spinner period in milliseconds; {@link SPINNER_INTERVAL_STATIC} when spinners are still. */
17
+ export function spinnerInterval(): number {
18
+ return intervalMs;
19
+ }
20
+
21
+ /** Whether spinners advance at all. */
22
+ export function spinnerAnimated(): boolean {
23
+ return intervalMs !== SPINNER_INTERVAL_STATIC;
24
+ }
25
+
26
+ /** Set the period for every spinner; callers pass a value {@link parseSpinnerInterval} accepted. */
27
+ export function setSpinnerInterval(next: number): void {
28
+ if (next === intervalMs) return;
29
+ intervalMs = next;
30
+ for (const listener of listeners) listener();
31
+ }
32
+
33
+ /** Observe period changes, for timers that would otherwise stay parked; returns the unsubscribe. */
34
+ export function onSpinnerIntervalChange(listener: () => void): () => void {
35
+ listeners.add(listener);
36
+ return () => {
37
+ listeners.delete(listener);
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Glyph index on the shared clock, or frame 0 when spinners are static. Every spinner reads
43
+ * wall-clock time, so they share a phase as well as a period.
44
+ */
45
+ export function sharedSpinnerFrame(frameCount: number, now: number = Date.now()): number {
46
+ if (frameCount <= 0 || intervalMs === SPINNER_INTERVAL_STATIC) return 0;
47
+ return Math.floor(now / intervalMs) % frameCount;
48
+ }
49
+
50
+ /**
51
+ * Milliseconds until the next multiple of `periodMs` on the wall clock. Timers armed from this fire
52
+ * together whoever owns them, so N spinners cost one frame per period instead of N.
53
+ */
54
+ export function spinnerTickDelay(periodMs: number, now: number = Date.now()): number {
55
+ // Slack for float residue at an exact boundary (100 ms is three periods of 1000/30, but
56
+ // `100 % (1000/30)` reads as a full period), which would otherwise shorten the wait to 1 ms.
57
+ const periods = Math.floor(now / periodMs + 1e-6);
58
+ return Math.max(1, Math.ceil((periods + 1) * periodMs - now));
59
+ }
60
+
61
+ /**
62
+ * Canonicalize a configured spinner interval: 0 (static) or an integer ≥ 50. Numeric strings are
63
+ * accepted so one parser serves the CLI flag, the environment variable, and the setting.
64
+ *
65
+ * @throws Error on a non-numeric, negative, fractional, or too-small value.
66
+ */
67
+ export function parseSpinnerInterval(value: unknown): number {
68
+ const n = typeof value === "string" ? Number(value.trim() || Number.NaN) : value;
69
+ if (
70
+ typeof n === "number" &&
71
+ Number.isInteger(n) &&
72
+ (n === SPINNER_INTERVAL_STATIC || n >= SPINNER_INTERVAL_MIN_MS)
73
+ ) {
74
+ return n;
75
+ }
76
+ throw new Error(
77
+ `Spinner interval must be ${SPINNER_INTERVAL_STATIC} (static) or a whole number of milliseconds ≥ ${SPINNER_INTERVAL_MIN_MS}, got ${JSON.stringify(value)}.`,
78
+ );
79
+ }