@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,642 @@
1
+ /**
2
+ * Extension transcript presenters (`pi.registerTranscriptPresenter`). The host installs them with
3
+ * {@link setTranscriptPresenters}; each presentable block draws from its
4
+ * {@link TranscriptPresentationState}.
5
+ */
6
+ import type { TspProps, TspSpan, TspText } from "@linxiraos/pi-wire";
7
+ import { type Component, Container, ownDescription } from "../tui";
8
+ import { theme } from "../theme";
9
+ import { truncateToWidth } from "../render";
10
+ import { card, col, node, span, text, withHidden } from "../native/describe";
11
+ import { type DescribeContext, type NativeNode, type NativeUiEvent, rootToggleExpanded } from "../native/node";
12
+ import { Memo } from "../native/memo";
13
+ import { plainLine, plainText, spansLine } from "../native/spans";
14
+ import type { AnimationFrame, CompactTranscriptBlock } from "../chrome/transcript-container";
15
+ import type { DaemonSnapshot } from "../tools/daemon";
16
+ import type { TranscriptBlock, TranscriptPresentation, TranscriptPresenter } from "./extension-types";
17
+ import type { LateDiagnosticsFile } from "./late-diagnostics-message";
18
+ import {
19
+ type AdvisorMessageDetails,
20
+ type BashExecutionMessage,
21
+ type CustomMessage,
22
+ type HookMessage,
23
+ LAUNCH_COMPLETION_MESSAGE_TYPE,
24
+ LSP_LATE_DIAGNOSTIC_MESSAGE_TYPE,
25
+ type PythonExecutionMessage,
26
+ SKILL_PROMPT_MESSAGE_TYPE,
27
+ type SkillPromptDetails,
28
+ } from "./messages";
29
+
30
+ /** A block's presentation once every presenter has answered. */
31
+ export type ResolvedPresentation =
32
+ | { readonly mode: "full" }
33
+ | { readonly mode: "hidden" }
34
+ | { readonly mode: "compact"; readonly label?: TspText; readonly rows: readonly TspText[] };
35
+
36
+ export type CompactPresentation = Extract<ResolvedPresentation, { mode: "compact" }>;
37
+
38
+ const FULL: ResolvedPresentation = { mode: "full" };
39
+ const HIDDEN: ResolvedPresentation = { mode: "hidden" };
40
+ const COMPACT: ResolvedPresentation = { mode: "compact", rows: [] };
41
+
42
+ let presenters: readonly TranscriptPresenter[] = [];
43
+ const changeListeners = new Set<() => void>();
44
+
45
+ /**
46
+ * Install the presenters the transcript draws with, in extension load order; true when the set
47
+ * changed. They are called as given: the installer guards them (the extension runner reports a
48
+ * throw or an unknown answer, and answers `"full"` instead).
49
+ */
50
+ export function setTranscriptPresenters(next: readonly TranscriptPresenter[]): boolean {
51
+ const changed =
52
+ next.length !== presenters.length || next.some((presenter, index) => presenter !== presenters[index]);
53
+ presenters = next;
54
+ return changed;
55
+ }
56
+
57
+ /** An extension registered or disposed a presenter; the host installs the set again and refreshes. */
58
+ export function notifyTranscriptPresentersChanged(): void {
59
+ for (const listener of changeListeners) listener();
60
+ }
61
+
62
+ /** Call `listener` on {@link notifyTranscriptPresentersChanged}; returns the unsubscribe. */
63
+ export function onTranscriptPresentersChanged(listener: () => void): () => void {
64
+ changeListeners.add(listener);
65
+ return () => changeListeners.delete(listener);
66
+ }
67
+
68
+ const redrawListeners = new Set<(owner: Component) => void>();
69
+
70
+ /**
71
+ * Call `listener` when a block draws a presentation other than the one it last drew, outside a
72
+ * refresh (a late result, say): the host replays the scrollback when that block has rows in it.
73
+ * Returns the unsubscribe.
74
+ */
75
+ export function onTranscriptPresentationRedrawn(listener: (owner: Component) => void): () => void {
76
+ redrawListeners.add(listener);
77
+ return () => redrawListeners.delete(listener);
78
+ }
79
+
80
+ function isTspText(value: unknown): value is TspText {
81
+ return (
82
+ typeof value === "string" ||
83
+ (Array.isArray(value) &&
84
+ value.every(part => typeof part === "object" && part !== null && typeof part.t === "string"))
85
+ );
86
+ }
87
+
88
+ /** Presenter text as one sanitized line: ANSI and control characters stripped, tabs expanded, breaks as spaces. */
89
+ function singleLine(value: TspText): TspText {
90
+ if (typeof value === "string") return plainText(value).replace(/[\r\n]+/g, " ");
91
+ return value.flatMap(part => {
92
+ const t = plainText(part.t).replace(/[\r\n]+/g, " ");
93
+ return t ? [{ ...part, t }] : [];
94
+ });
95
+ }
96
+
97
+ /** `value` copied to plain data when it is {@link TspText}, else `undefined`. */
98
+ function copyTspText(value: unknown): TspText | undefined {
99
+ if (typeof value === "string") return value;
100
+ if (!Array.isArray(value)) return undefined;
101
+ const parts: unknown[] = value.map(part => (typeof part === "object" && part !== null ? { ...part } : part));
102
+ return isTspText(parts) ? parts : undefined;
103
+ }
104
+
105
+ /**
106
+ * A presenter's answer as plain data when it is a {@link TranscriptPresentation}; `null` for
107
+ * anything else (a misspelt mode, the Promise of an async presenter, a `compact` that is not a
108
+ * plain object), which draws the block in full. It reads every field the transcript uses once,
109
+ * so a throwing getter or Proxy in the answer throws here, inside the caller's guard, and never
110
+ * while drawing. Labels and rows that are not `TspText` are dropped.
111
+ */
112
+ export function readTranscriptPresentation(answer: unknown): TranscriptPresentation | null {
113
+ if (answer === undefined || answer === "full" || answer === "hidden" || answer === "compact") return answer;
114
+ if (typeof answer !== "object" || answer === null || !("compact" in answer)) return null;
115
+ const { compact } = answer;
116
+ if (typeof compact !== "object" || compact === null) return null;
117
+ const prototype = Object.getPrototypeOf(compact);
118
+ if (prototype !== Object.prototype && prototype !== null) return null;
119
+ const label = "label" in compact ? compact.label : undefined;
120
+ const rows = "rows" in compact ? compact.rows : undefined;
121
+ return {
122
+ compact: {
123
+ label: copyTspText(label),
124
+ rows: Array.isArray(rows) ? rows.map(copyTspText).filter(row => row !== undefined) : undefined,
125
+ },
126
+ };
127
+ }
128
+
129
+ /** `undefined` when the presenter defers. The answer is plain data (see {@link readTranscriptPresentation}). */
130
+ function normalize(answer: TranscriptPresentation): ResolvedPresentation | undefined {
131
+ if (answer === undefined) return undefined;
132
+ if (answer === "full") return FULL;
133
+ if (answer === "hidden") return HIDDEN;
134
+ if (answer === "compact") return COMPACT;
135
+ const { label, rows = [] } = answer.compact;
136
+ return { mode: "compact", label: label === undefined ? undefined : singleLine(label), rows: rows.map(singleLine) };
137
+ }
138
+
139
+ /** The first answer other than `undefined` wins. */
140
+ function resolve(block: TranscriptBlock): ResolvedPresentation {
141
+ for (const presenter of presenters) {
142
+ const answer = normalize(presenter(block));
143
+ if (answer !== undefined) return answer;
144
+ }
145
+ return FULL;
146
+ }
147
+
148
+ function sameText(a: TspText | undefined, b: TspText | undefined): boolean {
149
+ if (a === b) return true;
150
+ if (typeof a !== "object" || typeof b !== "object" || a.length !== b.length) return false;
151
+ return a.every((part, index) => {
152
+ const other = b[index]!;
153
+ return part.t === other.t && part.s === other.s && part.fx === other.fx && part.href === other.href;
154
+ });
155
+ }
156
+
157
+ function samePresentation(a: ResolvedPresentation, b: ResolvedPresentation): boolean {
158
+ if (a.mode !== b.mode) return false;
159
+ if (a.mode !== "compact" || b.mode !== "compact") return true;
160
+ return (
161
+ sameText(a.label, b.label) &&
162
+ a.rows.length === b.rows.length &&
163
+ a.rows.every((row, index) => sameText(row, b.rows[index]))
164
+ );
165
+ }
166
+
167
+ /**
168
+ * One block's presentation, resolved lazily after {@link markStale}. The resolved object keeps
169
+ * its identity while the answer is the same, so it can sit in render memo keys.
170
+ */
171
+ export class TranscriptPresentationState {
172
+ readonly #snapshot: () => TranscriptBlock | undefined;
173
+ readonly #expanded: () => boolean;
174
+ #current: ResolvedPresentation = FULL;
175
+ #stale = true;
176
+ /** What the block's last render or description drew; `undefined` before the first. */
177
+ #drawn: ResolvedPresentation | undefined;
178
+ /** Whether that drawing was the user's expansion rather than the presenters' answer. */
179
+ #drawnExpanded = false;
180
+ /** The answer changed while the block was still partial; reported once it settles. */
181
+ #changedWhilePartial = false;
182
+ readonly #owner: Component | undefined;
183
+
184
+ /**
185
+ * `snapshot` is the block presenters see (`undefined`: always full); `expanded` tells whether
186
+ * the user expanded it, which always draws it in full. `owner` is the transcript block it draws
187
+ * ({@link onTranscriptPresentationRedrawn} names it).
188
+ */
189
+ constructor(snapshot: () => TranscriptBlock | undefined, expanded: () => boolean, owner?: Component) {
190
+ this.#snapshot = snapshot;
191
+ this.#expanded = expanded;
192
+ this.#owner = owner;
193
+ }
194
+
195
+ /** The block's data changed: ask again before the next draw. */
196
+ markStale(): void {
197
+ this.#stale = true;
198
+ }
199
+
200
+ /** What the block draws now. */
201
+ get shown(): ResolvedPresentation {
202
+ if (this.#expanded()) return FULL;
203
+ if (this.#stale) {
204
+ this.#stale = false;
205
+ const block = presenters.length === 0 ? undefined : this.#snapshot();
206
+ const next = block === undefined ? FULL : resolve(block);
207
+ if (!samePresentation(next, this.#current)) this.#current = next;
208
+ }
209
+ return this.#current;
210
+ }
211
+
212
+ /** The last answer {@link shown} resolved, without asking the presenters again. */
213
+ get resolved(): ResolvedPresentation {
214
+ return this.#expanded() ? FULL : this.#current;
215
+ }
216
+
217
+ /** {@link shown}, for the block's render or description: what {@link refresh} compares against. */
218
+ draw(): ResolvedPresentation {
219
+ const previous = this.#drawn;
220
+ const expanded = this.#expanded();
221
+ const next = this.shown;
222
+ this.#report(previous !== undefined && next !== previous && !expanded && !this.#drawnExpanded);
223
+ this.#drawn = next;
224
+ this.#drawnExpanded = expanded;
225
+ return next;
226
+ }
227
+
228
+ /**
229
+ * The block's data changed where nothing may draw it again (rows retired to scrollback): ask now,
230
+ * and report an answer other than the drawn one as {@link draw} would. What was drawn stays the
231
+ * baseline until the block draws again.
232
+ */
233
+ recheck(): void {
234
+ const drawn = this.#drawn;
235
+ if (drawn === undefined || this.#drawnExpanded || this.#expanded()) return;
236
+ this.#report(this.shown !== drawn);
237
+ }
238
+
239
+ /** Tell the redraw listeners about a change, once the block is no longer partial. */
240
+ #report(changed: boolean): void {
241
+ if ((!changed && !this.#changedWhilePartial) || !this.#owner) return;
242
+ const block = this.#snapshot();
243
+ if (block?.type === "toolCall" && block.isPartial) {
244
+ this.#changedWhilePartial = true;
245
+ return;
246
+ }
247
+ this.#changedWhilePartial = false;
248
+ for (const listener of redrawListeners) listener(this.#owner);
249
+ }
250
+
251
+ /**
252
+ * Ask again now when `ids` selects this block (every block when `undefined`); true when the
253
+ * answer differs from what the block last drew. A block in terminal scrollback is not drawn
254
+ * again, so a change its data made since (a late result) still counts. A change it reports is
255
+ * the caller's to redraw, so the next draw does not report it again.
256
+ */
257
+ refresh(ids?: ReadonlySet<string>): boolean {
258
+ if (ids !== undefined) {
259
+ const block = this.#snapshot();
260
+ if (block === undefined || !ids.has(block.id)) return false;
261
+ }
262
+ this.#stale = true;
263
+ const next = this.shown;
264
+ if (this.#drawn === undefined || next === this.#drawn) return false;
265
+ this.#drawn = next;
266
+ this.#drawnExpanded = this.#expanded();
267
+ this.#changedWhilePartial = false;
268
+ return true;
269
+ }
270
+ }
271
+
272
+ /** A transcript block whose display presenters choose. */
273
+ export interface TranscriptPresentable {
274
+ /**
275
+ * Ask again for the parts whose id is in `ids` (all when `undefined`); true when the drawing
276
+ * changed. True obliges the caller to redraw the block (and replay scrollback holding its rows):
277
+ * the change is not reported again.
278
+ */
279
+ refreshTranscriptPresentation(ids?: ReadonlySet<string>): boolean;
280
+ }
281
+
282
+ export function isTranscriptPresentable(component: Component): component is Component & TranscriptPresentable {
283
+ return typeof (component as Partial<TranscriptPresentable>).refreshTranscriptPresentation === "function";
284
+ }
285
+
286
+ /**
287
+ * A compact block's terminal rows: `• <head>` (the presenter's `label` replacing `head`), then one
288
+ * indented row per presenter row. Plain strings arrive sanitized (see `normalize`) and keep their
289
+ * spacing; span arrays are styled.
290
+ */
291
+ export function compactRows(
292
+ head: string,
293
+ presentation: CompactPresentation,
294
+ width: number,
295
+ glyph: string = theme.fg("dim", "•"),
296
+ ): string[] {
297
+ const { label } = presentation;
298
+ const shown = label === undefined ? head : typeof label === "string" ? label : spansLine(label);
299
+ const rows = [truncateToWidth(`${glyph} ${shown}`, width)];
300
+ for (const row of presentation.rows) {
301
+ rows.push(truncateToWidth(` ${typeof row === "string" ? row : spansLine(row)}`, width));
302
+ }
303
+ return rows;
304
+ }
305
+
306
+ /** omp's own one-row head: the bold title, then a muted detail (raw input, sanitized to one line). */
307
+ export function compactHead(title: string, detail?: string): string {
308
+ const shown = detail === undefined ? undefined : plainLine(detail);
309
+ return `${theme.fg("toolTitle", theme.bold(plainLine(title)))}${shown ? theme.fg("muted", ` ${shown}`) : ""}`;
310
+ }
311
+
312
+ /** The presenter's rows as ONE text node, so a `preview` of that many lines shows all of them. */
313
+ function compactRowsNode(rows: readonly TspText[]): NativeNode {
314
+ const spans = rows.flatMap((row, index) => {
315
+ const parts = typeof row === "string" ? [span(row)] : row.map(part => ({ ...part }));
316
+ return index === 0 ? parts : [span("\n"), ...parts];
317
+ });
318
+ return text(spans, { wrap: "none" });
319
+ }
320
+
321
+ /** How a block names itself in a compact native card when its full drawing is not a `tool` node. */
322
+ export interface CompactNativeHead {
323
+ readonly role: string;
324
+ readonly title: string;
325
+ readonly target?: TspText;
326
+ }
327
+
328
+ /**
329
+ * A block's native drawing under `presentation`. Hidden stays mounted through the `hidden` prop.
330
+ * Compact folds a `tool` node to one inline, collapsed row (its toggle asks for the full block);
331
+ * any other drawing becomes the body of a collapsed card headed by `head`.
332
+ */
333
+ export function presentNative(
334
+ full: NativeNode,
335
+ presentation: ResolvedPresentation,
336
+ head: CompactNativeHead,
337
+ ): NativeNode {
338
+ if (presentation.mode === "full") return full;
339
+ if (presentation.mode === "hidden") return withHidden(full, true);
340
+ const rows = presentation.rows;
341
+ if (full.k !== "tool" || full.p === undefined) {
342
+ // The head's own target can be raw call input (a bash command): sanitized like a label.
343
+ const own = head.target;
344
+ const target =
345
+ presentation.label ??
346
+ (own === undefined ? undefined : typeof own === "string" ? plainLine(own) || undefined : singleLine(own));
347
+ const spans: TspSpan[] = [span(plainLine(head.title), "toolTitle strong")];
348
+ if (target !== undefined)
349
+ spans.push(span(" "), ...(typeof target === "string" ? [span(target, "muted")] : target));
350
+ return card(
351
+ {
352
+ role: head.role,
353
+ head: spans,
354
+ collapsible: true,
355
+ collapsed: true,
356
+ preview: rows.length > 0 ? { lines: rows.length } : undefined,
357
+ },
358
+ rows.length > 0 ? [compactRowsNode(rows)] : [full],
359
+ );
360
+ }
361
+ const body = rows.length > 0 ? [compactRowsNode(rows)] : (full.c ?? []);
362
+ const props = full.p;
363
+ const label = presentation.label;
364
+ return {
365
+ ...full,
366
+ p: {
367
+ ...props,
368
+ target: label ?? props.target,
369
+ targetKind: label !== undefined ? "text" : props.targetKind,
370
+ frame: "inline",
371
+ // Toggleable even with no body: opening it is the only way back to the full drawing.
372
+ collapsible: true,
373
+ collapsed: true,
374
+ preview: rows.length > 0 ? { lines: rows.length } : "none",
375
+ } satisfies TspProps<"tool">,
376
+ c: body,
377
+ };
378
+ }
379
+
380
+ type WrappedTranscriptBlock = Exclude<TranscriptBlock, { type: "toolCall" }>;
381
+
382
+ /** The `message` block of a session message: its id is the decimal `timestamp`. */
383
+ export function messageBlock(
384
+ message: CustomMessage | HookMessage | BashExecutionMessage | PythonExecutionMessage,
385
+ ): WrappedTranscriptBlock {
386
+ // A legacy `hookMessage` is a custom message under its old role name.
387
+ const shown = message.role === "hookMessage" ? { ...message, role: "custom" as const } : message;
388
+ return { type: "message", id: String(message.timestamp), message: shown };
389
+ }
390
+
391
+ let nextEventBlockId = 0;
392
+ /** A process-unique id for an `event` block. */
393
+ export function eventBlockId(kind: string): string {
394
+ return `${kind}:${++nextEventBlockId}`;
395
+ }
396
+
397
+ /** How a compact block names itself: the terminal row after its glyph, and the native row. */
398
+ interface BlockHead extends CompactNativeHead {
399
+ readonly terminal: string;
400
+ readonly glyph?: string;
401
+ /** Kind name for the native row's icon and role styles. */
402
+ readonly name: string;
403
+ readonly target?: string;
404
+ }
405
+
406
+ function countOf(count: number, noun: string): string {
407
+ return `${count} ${noun}${count === 1 ? "" : "s"}`;
408
+ }
409
+
410
+ function plainHead(name: string, role: string, title: string, target?: string): BlockHead {
411
+ // The native head and the tool row it folds into show the target as is: sanitize it like `compactHead` does.
412
+ const shown = target === undefined ? undefined : plainLine(target);
413
+ return { terminal: compactHead(title, target), name, role, title: plainLine(title), target: shown };
414
+ }
415
+
416
+ /** omp's own one-row summary of a wrapped block, from the block presenters see. */
417
+ function blockHead(block: WrappedTranscriptBlock): BlockHead {
418
+ if (block.type === "event") {
419
+ const { event } = block;
420
+ if (event.type === "ttsr_triggered") {
421
+ return plainHead("ttsr", "zeta.notice.ttsr", "Rule", event.rules.map(rule => rule.name).join(", "));
422
+ }
423
+ const reminder = `${countOf(event.todos.length, "incomplete todo")} - reminder ${event.attempt}/${event.maxAttempts}`;
424
+ return plainHead("todo", "zeta.notice.todo", "Todos", reminder);
425
+ }
426
+ const { message } = block;
427
+ if (message.role !== "custom") {
428
+ const bash = message.role === "bashExecution";
429
+ const source = plainLine((bash ? message.command : message.code).split("\n", 1)[0] ?? "");
430
+ const color = message.excludeFromContext ? "dim" : bash ? "bashMode" : "pythonMode";
431
+ let terminal = theme.fg(color, theme.bold(`${bash ? "$" : ">>>"} ${source}`));
432
+ if (message.cancelled) terminal += theme.fg("muted", " cancelled");
433
+ else if (message.exitCode !== undefined && message.exitCode !== 0) {
434
+ terminal += theme.fg("error", ` exit ${message.exitCode}`);
435
+ }
436
+ return bash
437
+ ? { terminal, name: "bash", role: "zeta.bash", title: "Bash", target: source }
438
+ : { terminal, name: "eval", role: "zeta.eval", title: "Python", target: source };
439
+ }
440
+ switch (message.customType) {
441
+ case "advisor": {
442
+ const notes = (message.details as AdvisorMessageDetails | undefined)?.notes ?? [];
443
+ const blockers = notes.filter(note => note.severity === "blocker").length;
444
+ const tally = `${countOf(notes.length, "note")}${blockers > 0 ? ` · ${countOf(blockers, "blocker")}` : ""}`;
445
+ return plainHead("advisor", "zeta.advisor", "Advisor", tally);
446
+ }
447
+ case SKILL_PROMPT_MESSAGE_TYPE: {
448
+ const name = (message.details as SkillPromptDetails | undefined)?.name?.trim() || "unknown";
449
+ return plainHead("skill", "zeta.skill", "Skill", name);
450
+ }
451
+ case LSP_LATE_DIAGNOSTIC_MESSAGE_TYPE: {
452
+ const files = (message.details as { files?: LateDiagnosticsFile[] } | undefined)?.files ?? [];
453
+ const count = files.reduce((sum, file) => sum + (file.messages?.length ?? 0), 0);
454
+ const summary = files.flatMap(file => (file.summary ? [file.summary] : [])).join(", ");
455
+ const errored = files.some(file => file.errored);
456
+ return {
457
+ ...plainHead(
458
+ "diagnostics",
459
+ "zeta.diagnostics.late",
460
+ "Late diagnostics",
461
+ `${countOf(count, "diagnostic")}${summary ? ` · ${summary}` : ""}`,
462
+ ),
463
+ glyph: theme.fg(errored ? "error" : "warning", errored ? theme.status.error : theme.status.warning),
464
+ };
465
+ }
466
+ case "async-result": {
467
+ const details = message.details as { jobId?: string; jobs?: { jobId?: string }[] } | undefined;
468
+ const jobs = details?.jobs?.length ? details.jobs : [details ?? {}];
469
+ const ids = jobs.map(job => job.jobId ?? "unknown").join(", ");
470
+ const title = jobs.length === 1 ? "Background job completed" : `${jobs.length} background jobs completed`;
471
+ return { ...plainHead("job", "zeta.activity", title, ids), glyph: theme.fg("success", theme.status.success) };
472
+ }
473
+ case LAUNCH_COMPLETION_MESSAGE_TYPE: {
474
+ const daemons = (message.details as { daemons?: DaemonSnapshot[] } | undefined)?.daemons ?? [];
475
+ const failed = daemons.some(
476
+ daemon => daemon.state === "failed" || (daemon.exitCode !== undefined && daemon.exitCode !== 0),
477
+ );
478
+ const names = daemons.map(daemon => daemon.name).join(", ");
479
+ const title = failed ? "Supervised process failed" : "Supervised process completed";
480
+ return {
481
+ ...plainHead(
482
+ "process",
483
+ "zeta.activity",
484
+ title,
485
+ names || (typeof message.content === "string" ? message.content : undefined),
486
+ ),
487
+ glyph: failed ? theme.fg("error", theme.status.error) : theme.fg("success", theme.status.success),
488
+ };
489
+ }
490
+ }
491
+ return plainHead("message", "zeta.custom", message.customType);
492
+ }
493
+
494
+ /** Transcript hooks a wrapped component may have; the wrapper forwards the ones it has. */
495
+ interface WrappedComponent extends Component, CompactTranscriptBlock {
496
+ setExpanded?(expanded: boolean): void;
497
+ /**
498
+ * Whether the user expanded it, including through a nested disclosure no root toggle reports
499
+ * (the skill's `prompt`). True forces the block full, so it must default to false.
500
+ */
501
+ isExpanded?(): boolean;
502
+ setToolActivityVisible?(visible: boolean): void;
503
+ isTranscriptBlockFinalized?(): boolean;
504
+ setTranscriptAllocation?(rows: number, frame: AnimationFrame): void;
505
+ }
506
+
507
+ /**
508
+ * A non-tool transcript block (advisor, skill, late diagnostics, `!`/`$` run, background job,
509
+ * supervised process, TTSR, todo reminder) with the presenters' answer applied around the
510
+ * component that draws it. In full it draws and describes as `inner` does; expansion, native
511
+ * events, tool-activity visibility and finalization reach `inner`.
512
+ */
513
+ export class PresentedBlock<T extends WrappedComponent = WrappedComponent>
514
+ extends Container
515
+ implements TranscriptPresentable
516
+ {
517
+ readonly inner: T;
518
+ #block: WrappedTranscriptBlock;
519
+ #head: BlockHead | undefined;
520
+ readonly #presentation: TranscriptPresentationState;
521
+ readonly #native = new Memo();
522
+ #expanded = false;
523
+ #toolActivityVisible = true;
524
+ #allocation = Number.POSITIVE_INFINITY;
525
+ /** Only where `inner` has it: the transcript container detects tool activity by its presence. */
526
+ readonly setToolActivityVisible?: (visible: boolean) => void;
527
+
528
+ constructor(inner: T, block: WrappedTranscriptBlock) {
529
+ super();
530
+ this.inner = inner;
531
+ this.#block = block;
532
+ this.#presentation = new TranscriptPresentationState(
533
+ () => this.#block,
534
+ () => this.#expanded || this.inner.isExpanded?.() === true,
535
+ this,
536
+ );
537
+ this.addChild(inner);
538
+ const setVisible = inner.setToolActivityVisible?.bind(inner);
539
+ if (setVisible) {
540
+ this.setToolActivityVisible = visible => {
541
+ this.#toolActivityVisible = visible;
542
+ setVisible(visible);
543
+ };
544
+ }
545
+ }
546
+
547
+ get block(): WrappedTranscriptBlock {
548
+ return this.#block;
549
+ }
550
+
551
+ /**
552
+ * The block's data changed (a `!`/`$` run was recorded, TTSR rules merged in). A block already
553
+ * in scrollback is not drawn again, so a changed answer is reported now for a one-time replay.
554
+ */
555
+ setBlock(block: WrappedTranscriptBlock): void {
556
+ this.#block = block;
557
+ this.#head = undefined;
558
+ this.#presentation.markStale();
559
+ this.#presentation.recheck();
560
+ }
561
+
562
+ setExpanded(expanded: boolean): void {
563
+ this.#expanded = expanded;
564
+ this.inner.setExpanded?.(expanded);
565
+ }
566
+
567
+ /** The compact row's toggle, or `inner`'s own root toggle, expands the block. */
568
+ handleNativeEvent(event: NativeUiEvent): void {
569
+ const expanded = rootToggleExpanded(event);
570
+ if (expanded !== undefined) this.#expanded = expanded;
571
+ this.inner.handleNativeEvent?.(event);
572
+ }
573
+
574
+ refreshTranscriptPresentation(ids?: ReadonlySet<string>): boolean {
575
+ return this.#presentation.refresh(ids);
576
+ }
577
+
578
+ isTranscriptBlockFinalized(): boolean {
579
+ return this.inner.isTranscriptBlockFinalized?.() ?? true;
580
+ }
581
+
582
+ /** A squeezed compact block keeps its head and as many rows as fit; in full, `inner` decides. */
583
+ setTranscriptAllocation(rows: number, frame: AnimationFrame): void {
584
+ this.#allocation = Math.max(0, Math.trunc(rows));
585
+ this.inner.setTranscriptAllocation?.(rows, frame);
586
+ }
587
+
588
+ /** Compact while drawn as compact rows; in full, as compact as `inner` says. */
589
+ isTranscriptBlockCompact(): boolean {
590
+ const mode = this.#presentation.shown.mode;
591
+ if (mode === "full") return this.inner.isTranscriptBlockCompact?.() === true;
592
+ return mode === "compact" && this.#toolActivityVisible && this.#allocation > 0;
593
+ }
594
+
595
+ /** The cached head row carries theme colours and glyphs. */
596
+ override invalidate(): void {
597
+ this.#head = undefined;
598
+ super.invalidate();
599
+ }
600
+
601
+ override render(width: number): readonly string[] {
602
+ const shown = this.#presentation.draw();
603
+ if (shown.mode === "full") return super.render(width);
604
+ if (shown.mode === "hidden" || !this.#toolActivityVisible || this.#allocation === 0) return [];
605
+ const head = (this.#head ??= blockHead(this.#block));
606
+ return compactRows(head.terminal, shown, width, head.glyph).slice(0, this.#allocation);
607
+ }
608
+
609
+ override describe(cx: DescribeContext): NativeNode | null {
610
+ const shown = this.#presentation.draw();
611
+ // An inner that draws as rows stays a child component, so the reconciler renders it as rows.
612
+ const inner = ownDescription(this.inner, cx) ?? super.describe(cx);
613
+ if (shown.mode === "full") return inner;
614
+ const dataFirst = cx.supports("tool");
615
+ const full = inner ?? col([]);
616
+ return this.#native.get([full, shown, dataFirst, this.#toolActivityVisible, this.#block], () => {
617
+ const head = (this.#head ??= blockHead(this.#block));
618
+ let own = full;
619
+ if (full.k === "tool" && full.p !== undefined) {
620
+ // Already a tool row (a `!`/`$` run): it keeps its status and exit code, and its
621
+ // compact row names the command its full card shows in the body.
622
+ if (full.p.target === undefined)
623
+ own = { ...full, p: { ...full.p, target: head.target, targetKind: "text" } };
624
+ } else if (dataFirst) {
625
+ // A terminal that draws `tool` nodes folds the block into an inline tool row.
626
+ own = node(
627
+ "tool",
628
+ {
629
+ role: head.role,
630
+ name: head.name,
631
+ title: head.title,
632
+ target: head.target,
633
+ targetKind: "text",
634
+ status: "done",
635
+ },
636
+ [full],
637
+ );
638
+ }
639
+ return withHidden(presentNative(own, shown, head), !this.#toolActivityVisible);
640
+ });
641
+ }
642
+ }
@@ -0,0 +1,25 @@
1
+ import { Container } from "../tui";
2
+ /** Rule fields shown in rewind notifications. */
3
+ export interface NotificationRule {
4
+ name: string;
5
+ description?: string;
6
+ content?: string;
7
+ }
8
+ /**
9
+ * Component that renders a TTSR (Time Traveling Stream Rules) notification.
10
+ * Shows when a rule violation is detected and the stream is being rewound.
11
+ * One block can carry several rules: a single event may match multiple rules,
12
+ * and consecutive notifications merge into the previous block via
13
+ * {@link addRules} while it is still the live transcript tail.
14
+ */
15
+ export declare class TtsrNotificationComponent extends Container {
16
+ #private;
17
+ constructor(rules: NotificationRule[]);
18
+ setToolActivityVisible(visible: boolean): void;
19
+ /** A snapshot: {@link addRules} grows the block's own list in place. */
20
+ get rules(): readonly NotificationRule[];
21
+ /** Merge additional rules into this block (deduped by rule name). */
22
+ addRules(rules: NotificationRule[]): void;
23
+ setExpanded(expanded: boolean): void;
24
+ isExpanded(): boolean;
25
+ }
@@ -46,6 +46,11 @@ export class TtsrNotificationComponent extends Container {
46
46
  this.#notice.setToolActivityVisible(visible);
47
47
  }
48
48
 
49
+ /** A snapshot: {@link addRules} grows the block's own list in place. */
50
+ get rules(): readonly NotificationRule[] {
51
+ return [...this.#rules];
52
+ }
53
+
49
54
  /** Merge additional rules into this block (deduped by rule name). */
50
55
  addRules(rules: NotificationRule[]): void {
51
56
  let changed = false;
@@ -59,4 +59,6 @@ export declare class FramedMessageComponent<M extends FramedMessage> extends Con
59
59
  */
60
60
  describe(): NativeNode;
61
61
  handleNativeEvent(event: NativeUiEvent): void;
62
+ /** Packs with neighboring compact blocks while the extension renderer's component reports compact rows. */
63
+ isTranscriptBlockCompact(): boolean;
62
64
  }