@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
@@ -31,6 +31,10 @@ export declare function fileDiffSection(file: {
31
31
  * it), the path with a dim directory and a strong name (cut in the middle),
32
32
  * a quiet `range` suffix (`:13-36`), then an optional count `chip` and a
33
33
  * muted `detail`.
34
+ *
35
+ * A URL is one target, not a directory and a name: its last `/` does not
36
+ * separate a dim parent from a strong basename, and the whole visible text
37
+ * carries the link so a click anywhere on the URL opens it.
34
38
  */
35
39
  export declare function fileRow(filePath: string, p?: {
36
40
  range?: string;
@@ -65,6 +65,10 @@ export function fileDiffSection(
65
65
  * it), the path with a dim directory and a strong name (cut in the middle),
66
66
  * a quiet `range` suffix (`:13-36`), then an optional count `chip` and a
67
67
  * muted `detail`.
68
+ *
69
+ * A URL is one target, not a directory and a name: its last `/` does not
70
+ * separate a dim parent from a strong basename, and the whole visible text
71
+ * carries the link so a click anywhere on the URL opens it.
68
72
  */
69
73
  export function fileRow(
70
74
  filePath: string,
@@ -81,10 +85,12 @@ export function fileRow(
81
85
  } = {},
82
86
  ): NativeNode {
83
87
  const isDir = filePath.endsWith("/");
84
- const cut = pathNameStart(filePath);
88
+ const url = urlHref(filePath);
89
+ const cut = url === undefined ? pathNameStart(filePath) : 0;
90
+ const href = p.href ?? url;
85
91
  const spans: TspSpan[] = [];
86
92
  if (cut > 0) spans.push(span(filePath.slice(0, cut), "dim"));
87
- spans.push(span(filePath.slice(cut) || "…", "strong", p.href ? { href: p.href } : undefined));
93
+ spans.push(span(filePath.slice(cut) || "…", "strong", href ? { href } : undefined));
88
94
  if (p.range) spans.push(span(p.range, "muted"));
89
95
  const children: NativeChild[] = [
90
96
  p.lead ?? node("icon", { name: p.icon ?? (isDir ? "folder" : "file"), tone: p.tone }),
@@ -3,7 +3,7 @@
3
3
  * transcript components. Built-in renderers live beside this file; the
4
4
  * coding-agent tools implement the matching `*Details` payloads.
5
5
  */
6
- import type { TspPreview, TspText, TspTone, TspToolProps } from "@linxiraos/pi-wire";
6
+ import type { ShellTrace, ShellVizPresentation, TspPreview, TspText, TspTone, TspToolProps } from "@linxiraos/pi-wire";
7
7
  import type { NativeChild } from "../native/node";
8
8
  import type { Component } from "../tui";
9
9
  import type { Theme } from "../theme/theme";
@@ -38,6 +38,14 @@ export interface RenderResultOptions {
38
38
  media?: boolean;
39
39
  /** The native host draws raw JSON values (`cx.supports("json")`). Native describe hooks only. */
40
40
  json?: boolean;
41
+ /** The native host draws a live shell trace (`cx.supports("shell")`). Native describe hooks only. */
42
+ shell?: boolean;
43
+ /** Native semantic presentation, decoded and cached by the tool component. */
44
+ shellPresentation?: ShellVizPresentation;
45
+ /** Validated immutable trace associated with shellPresentation. */
46
+ shellTrace?: ShellTrace;
47
+ /** Explicit seeks/resets change this epoch; ordinary playback ticks do not. */
48
+ shellReplayEpoch?: number;
41
49
  }
42
50
  /** Render options for a result, plus the tool-specific context the transcript threads through. */
43
51
  export type RenderResultContextOptions = RenderResultOptions & {
@@ -3,7 +3,7 @@
3
3
  * transcript components. Built-in renderers live beside this file; the
4
4
  * coding-agent tools implement the matching `*Details` payloads.
5
5
  */
6
- import type { TspPreview, TspText, TspTone, TspToolProps } from "@linxiraos/pi-wire";
6
+ import type { ShellTrace, ShellVizPresentation, TspPreview, TspText, TspTone, TspToolProps } from "@linxiraos/pi-wire";
7
7
  import type { NativeChild } from "../native/node";
8
8
  import type { Component } from "../tui";
9
9
  import type { Theme } from "../theme/theme";
@@ -39,6 +39,14 @@ export interface RenderResultOptions {
39
39
  media?: boolean;
40
40
  /** The native host draws raw JSON values (`cx.supports("json")`). Native describe hooks only. */
41
41
  json?: boolean;
42
+ /** The native host draws a live shell trace (`cx.supports("shell")`). Native describe hooks only. */
43
+ shell?: boolean;
44
+ /** Native semantic presentation, decoded and cached by the tool component. */
45
+ shellPresentation?: ShellVizPresentation;
46
+ /** Validated immutable trace associated with shellPresentation. */
47
+ shellTrace?: ShellTrace;
48
+ /** Explicit seeks/resets change this epoch; ordinary playback ticks do not. */
49
+ shellReplayEpoch?: number;
42
50
  }
43
51
 
44
52
  /** Render options for a result, plus the tool-specific context the transcript threads through. */
@@ -0,0 +1,10 @@
1
+ import type { ShellVizLayer, ShellVizPreferences, ShellVizView } from "@linxiraos/pi-wire";
2
+ import type { NativeUiEvent } from "../native/node";
3
+ /** Canonical ordered views used by the inspector and native event adapter. */
4
+ export declare const SHELL_VIZ_VIEWS: readonly ShellVizView[];
5
+ /** Canonical toggleable semantic layers. */
6
+ export declare const SHELL_VIZ_LAYERS: readonly ShellVizLayer[];
7
+ /** Normalize action/change/selection events to the shared action vocabulary. */
8
+ export declare function shellVizEventAction(event: NativeUiEvent, preferences: ShellVizPreferences): string | undefined;
9
+ /** Apply shared actions; node keys remain opaque and playback values remain numeric. */
10
+ export declare function changeShellVizPreferences(preferences: ShellVizPreferences, action: string, length: number): ShellVizPreferences;
@@ -0,0 +1,80 @@
1
+ import type { ShellVizLayer, ShellVizPreferences, ShellVizView } from "@linxiraos/pi-wire";
2
+ import type { NativeUiEvent } from "../native/node";
3
+ import { isShellVizNode } from "./shell-viz";
4
+
5
+ /** Canonical ordered views used by the inspector and native event adapter. */
6
+ export const SHELL_VIZ_VIEWS: readonly ShellVizView[] = ["raw", "pseudo"];
7
+ /** Canonical toggleable semantic layers. */
8
+ export const SHELL_VIZ_LAYERS: readonly ShellVizLayer[] = ["color", "inline", "idioms", "effects", "unwrap"];
9
+
10
+ /** Normalize action/change/selection events to the shared action vocabulary. */
11
+ export function shellVizEventAction(event: NativeUiEvent, preferences: ShellVizPreferences): string | undefined {
12
+ if (event.type === "action") return event.act === "shell-viz" ? event.value : undefined;
13
+ if (event.type === "select") return event.item.startsWith("select:") ? event.item : `select:${event.item}`;
14
+ if (event.type !== "change") return undefined;
15
+ const { item, value } = event;
16
+ if ((item === "select" || item === "expand") && isShellVizNode(value)) return `${item}:${value}`;
17
+ if (typeof value === "string" && value.includes(":")) return value;
18
+ if (item === "shell-viz" && typeof value === "string") return value;
19
+ if (item === "split" && typeof value === "boolean") return value === preferences.split ? undefined : "split";
20
+ const layer = SHELL_VIZ_LAYERS.find(layer => item === layer || item === `layer:${layer}`);
21
+ if (layer && typeof value === "boolean") return value === preferences.layers[layer] ? undefined : `layer:${layer}`;
22
+ if (item.startsWith("view:") && value === true) return item;
23
+ if (item === "cursor" || item === "seek") return `seek:${String(value)}`;
24
+ return `${item}:${String(value)}`;
25
+ }
26
+
27
+ /** Apply shared actions; node keys remain opaque and playback values remain numeric. */
28
+ export function changeShellVizPreferences(
29
+ preferences: ShellVizPreferences,
30
+ action: string,
31
+ length: number,
32
+ ): ShellVizPreferences {
33
+ const next = { ...preferences, layers: { ...preferences.layers }, expandedNodes: [...preferences.expandedNodes] };
34
+ if (action.startsWith("view:")) {
35
+ const view = SHELL_VIZ_VIEWS.find(item => action === `view:${item}`);
36
+ if (view) next.view = view;
37
+ } else if (action.startsWith("layer:")) {
38
+ const layer = SHELL_VIZ_LAYERS.find(item => action === `layer:${item}`);
39
+ if (layer) next.layers[layer] = !next.layers[layer];
40
+ } else if (action === "split") next.split = !next.split;
41
+ else if (action === "play") {
42
+ next.playing = length > 0;
43
+ if (next.cursor === undefined || next.cursor >= length) next.cursor = 0;
44
+ } else if (action === "pause") next.playing = false;
45
+ else if (action === "step") {
46
+ next.playing = false;
47
+ next.cursor = Math.min(length, (next.cursor ?? length) + 1);
48
+ } else if (action === "reset") {
49
+ next.playing = false;
50
+ next.cursor = 0;
51
+ } else if (action === "live") {
52
+ next.playing = false;
53
+ delete next.cursor;
54
+ } else if (action.startsWith("select:") || action.startsWith("expand:")) {
55
+ const separator = action.indexOf(":");
56
+ const key = action.slice(separator + 1);
57
+ if (!isShellVizNode(key)) return preferences;
58
+ if (action.startsWith("select:")) next.selectedNode = key;
59
+ else
60
+ next.expandedNodes = next.expandedNodes.includes(key)
61
+ ? next.expandedNodes.filter(node => node !== key)
62
+ : [...next.expandedNodes, key];
63
+ } else {
64
+ const match = /^(speed|seek):([0-9]+(?:\.[0-9]+)?)$/.exec(action);
65
+ if (!match) return preferences;
66
+ const value = Number(match[2]);
67
+ if (!Number.isFinite(value)) return preferences;
68
+ if (match[1] === "speed") {
69
+ if (![0.5, 1, 2, 4].includes(value)) return preferences;
70
+ next.speed = value;
71
+ } else {
72
+ if (!Number.isSafeInteger(value)) return preferences;
73
+ if (match[1] === "seek") {
74
+ next.cursor = Math.max(0, Math.min(length, value));
75
+ next.playing = false;
76
+ }
77
+ }
78
+ }
79
+ return next;
80
+ }
@@ -0,0 +1,6 @@
1
+ import type { ShellVizPresentation } from "@linxiraos/pi-wire";
2
+ import type { Theme } from "../theme/theme";
3
+ /** Sanitize untrusted shell source, values and outputs before applying terminal styling. */
4
+ export declare function shellVizText(text: string): string;
5
+ /** Render the canonical presentation; transcript cards and focused inspector share this path. */
6
+ export declare function renderShellVisualization(presentation: ShellVizPresentation, theme: Theme, width: number, includeOutput?: boolean): string[];
@@ -0,0 +1,156 @@
1
+ import type { ShellVizPresentation, ShellVizRow, ShellVizSegment } from "@linxiraos/pi-wire";
2
+ import { sanitizeText } from "@linxiraos/pi-utils";
3
+ import { replaceTabs } from "../render/render-utils";
4
+ import type { Theme, ThemeColor } from "../theme/theme";
5
+ import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "../utils";
6
+
7
+ /** Sanitize untrusted shell source, values and outputs before applying terminal styling. */
8
+ export function shellVizText(text: string): string {
9
+ return replaceTabs(sanitizeText(text)).replace(/[\r\n]/g, " ");
10
+ }
11
+
12
+ function color(style: string | undefined): ThemeColor {
13
+ const tokens = style?.split(" ") ?? [];
14
+ if (tokens.includes("comment")) return "syntaxComment";
15
+ if (tokens.includes("kw")) return "syntaxKeyword";
16
+ if (tokens.includes("var") || tokens.includes("secret")) return "syntaxVariable";
17
+ if (tokens.includes("str") || tokens.includes("path")) return "syntaxString";
18
+ if (tokens.includes("num")) return "syntaxNumber";
19
+ if (tokens.includes("op")) return "syntaxOperator";
20
+ if (tokens.includes("cmd") || tokens.includes("fn")) return "syntaxFunction";
21
+ if (tokens.includes("chip") || tokens.includes("badge")) return "accent";
22
+ return "text";
23
+ }
24
+
25
+ function segmentText(
26
+ segment: ShellVizSegment,
27
+ row: ShellVizRow,
28
+ presentation: ShellVizPresentation,
29
+ theme: Theme,
30
+ ): string {
31
+ const text = shellVizText(segment.text);
32
+ const inactive =
33
+ (presentation.running && !(segment.active ?? row.active)) || (segment.state ?? row.state) === "skipped";
34
+ const tokens = segment.style?.split(" ") ?? [];
35
+ const semantic = tokens.some(token => ["chip", "badge", "secret"].includes(token));
36
+ const styled = presentation.preferences.layers.color || semantic ? theme.fg(color(segment.style), text) : text;
37
+ const emphasized = inactive
38
+ ? theme.faint(styled)
39
+ : segment.active && presentation.running
40
+ ? theme.bold(styled)
41
+ : styled;
42
+ return emphasized;
43
+ }
44
+
45
+ function rowText(row: ShellVizRow, presentation: ShellVizPresentation, theme: Theme, width: number): string {
46
+ const selected =
47
+ presentation.preferences.selectedNode !== undefined &&
48
+ (row.node === presentation.preferences.selectedNode ||
49
+ row.segments.some(segment => segment.node === presentation.preferences.selectedNode));
50
+ const failures = new Set<string>();
51
+ const rowFailedInSegments = row.segments.some(segment => segment.state === "fail");
52
+ const muted = presentation.running && !row.active;
53
+ const failedStatement =
54
+ row.state === "fail" && !rowFailedInSegments && row.role !== "head" && row.role !== "mid" && row.role !== "tail";
55
+ const gutter = failedStatement
56
+ ? theme.fg("error", "×")
57
+ : presentation.running && row.active
58
+ ? theme.fg("accent", "▶")
59
+ : selected
60
+ ? theme.fg("accent", "›")
61
+ : " ";
62
+ const effects = presentation.preferences.layers.effects
63
+ ? row.effects.map(item => shellVizText(item.glyph)).join("")
64
+ : "";
65
+ const effect = muted ? theme.faint(effects) : effects;
66
+ const indent = " ".repeat(Math.min(row.depth, Math.max(0, Math.floor(width / 4))));
67
+ const body = row.segments
68
+ .map(segment => {
69
+ const execution = segment.executionNode ?? segment.node ?? row.node;
70
+ const failed = segment.state === "fail" && execution !== undefined && !failures.has(execution);
71
+ if (failed && execution !== undefined) failures.add(execution);
72
+ const mark = failed ? theme.fg("error", "× ") : "";
73
+ return `${muted ? theme.faint(mark) : mark}${segmentText(segment, row, presentation, theme)}`;
74
+ })
75
+ .join("");
76
+ const meta = row.meta ? ` ${theme.fg(row.state === "fail" ? "error" : "dim", shellVizText(row.meta))}` : "";
77
+ const annotations = (row.annotations ?? [])
78
+ .map(variable => {
79
+ const shortened =
80
+ variable.fullLength !== undefined && variable.fullLength > Buffer.byteLength(variable.value, "utf8");
81
+ const name = theme.fg("syntaxVariable", shellVizText(variable.name));
82
+ const value = theme.fg("syntaxString", shellVizText(JSON.stringify(variable.value)) + (shortened ? "…" : ""));
83
+ const annotation = `${name} ${theme.fg("muted", "=")} ${value}`;
84
+ return muted ? theme.faint(annotation) : annotation;
85
+ })
86
+ .join(theme.fg("muted", " · "));
87
+ return `${gutter} ${indent}${effect ? `${effect} ` : ""}${body}${meta}${annotations ? ` ${theme.fg("muted", "‹")} ${annotations} ${theme.fg("muted", "›")}` : ""}`;
88
+ }
89
+
90
+ function rowLines(row: ShellVizRow, presentation: ShellVizPresentation, theme: Theme, width: number): string[] {
91
+ return wrapTextWithAnsi(rowText(row, presentation, theme, width), Math.max(1, width));
92
+ }
93
+
94
+ function joinPanes(left: string[], right: string[], width: number, separator: string): string[] {
95
+ const pane = Math.max(1, Math.floor((width - visibleWidth(separator)) / 2));
96
+ return Array.from({ length: Math.max(left.length, right.length) }, (_, index) => {
97
+ const first = truncateToWidth(left[index] ?? "", pane);
98
+ return truncateToWidth(
99
+ `${first}${" ".repeat(Math.max(0, pane - visibleWidth(first)))}${separator}${right[index] ?? ""}`,
100
+ width,
101
+ );
102
+ });
103
+ }
104
+
105
+ /** Render the canonical presentation; transcript cards and focused inspector share this path. */
106
+ export function renderShellVisualization(
107
+ presentation: ShellVizPresentation,
108
+ theme: Theme,
109
+ width: number,
110
+ includeOutput = true,
111
+ ): string[] {
112
+ width = Math.max(1, Math.floor(width));
113
+ const lines: string[] = [];
114
+ if (presentation.message) lines.push(theme.fg("dim", shellVizText(presentation.message)));
115
+ if (presentation.preferences.split && presentation.preferences.view !== "raw") {
116
+ if (width >= 90) {
117
+ const pane = Math.floor((width - 3) / 2);
118
+ lines.push(
119
+ ...joinPanes(
120
+ [
121
+ theme.fg("dim", "Original"),
122
+ ...presentation.original.flatMap(row => rowLines(row, presentation, theme, pane)),
123
+ ],
124
+ [
125
+ theme.fg("dim", "Pseudo"),
126
+ ...presentation.rows.flatMap(row => rowLines(row, presentation, theme, pane)),
127
+ ],
128
+ width,
129
+ " │ ",
130
+ ),
131
+ );
132
+ } else {
133
+ lines.push(
134
+ theme.fg("dim", "Split stacked (terminal too narrow for side-by-side)"),
135
+ theme.fg("dim", "Original"),
136
+ );
137
+ lines.push(
138
+ ...presentation.original.flatMap(row => rowLines(row, presentation, theme, width)),
139
+ theme.fg("dim", "Pseudo"),
140
+ ...presentation.rows.flatMap(row => rowLines(row, presentation, theme, width)),
141
+ );
142
+ }
143
+ } else lines.push(...presentation.rows.flatMap(row => rowLines(row, presentation, theme, width)));
144
+ if (includeOutput && presentation.output) {
145
+ lines.push(
146
+ theme.fg("dim", "Output"),
147
+ ...presentation.output
148
+ .trimEnd()
149
+ .split("\n")
150
+ .flatMap(line => wrapTextWithAnsi(shellVizText(line), width)),
151
+ );
152
+ }
153
+ if (presentation.timeline.trimmed)
154
+ lines.push(theme.fg("warning", "Replay history/output trimmed to retained limits"));
155
+ return lines.map(line => truncateToWidth(line, width));
156
+ }
@@ -0,0 +1,16 @@
1
+ import { RunTrace, ShellVisualization } from "@linxiraos/pi-natives";
2
+ import type { ShellTrace, ShellVizPreferences, ShellVizPresentation } from "@linxiraos/pi-wire";
3
+ /** Native live-run or restored-trace owner; the UI never holds shell syntax. */
4
+ export type ShellVisualizationSource = RunTrace | ShellVisualization;
5
+ /** Bind the immutable snapshot before publishing it; live paints borrow the actual run. */
6
+ export declare function attachShellTrace(snapshot: ShellTrace, trace: RunTrace): void;
7
+ /** Historical traces restore their canonical native archive only once per snapshot. */
8
+ export declare function shellVisualization(snapshot: ShellTrace): ShellVisualizationSource;
9
+ /** Python-like Pseudo, all layers enabled, one pane, live, paused, normal speed. */
10
+ export declare function defaultShellVizPreferences(): ShellVizPreferences;
11
+ /** Render through native ownership; an explicit replay cursor never uses the normal output sink. */
12
+ export declare function readShellPresentation(source: ShellVisualizationSource, preferences: ShellVizPreferences, snapshot?: ShellTrace, output?: string): ShellVizPresentation;
13
+ /** Node keys are opaque; validation must never invent or reinterpret engine identity. */
14
+ export declare function isShellVizNode(value: unknown): value is string;
15
+ /** Decode semantic display data, never shell syntax or execution state. */
16
+ export declare function decodeShellPresentation(json: string): ShellVizPresentation;
@@ -0,0 +1,181 @@
1
+ import { RunTrace, ShellVisualization, type ShellVizOptions } from "@linxiraos/pi-natives";
2
+ import type {
3
+ ShellTrace,
4
+ ShellVizPreferences,
5
+ ShellVizPresentation,
6
+ ShellVizRow,
7
+ ShellVizSegment,
8
+ ShellVizWatch,
9
+ } from "@linxiraos/pi-wire";
10
+
11
+ /** Native live-run or restored-trace owner; the UI never holds shell syntax. */
12
+ export type ShellVisualizationSource = RunTrace | ShellVisualization;
13
+ const visualizations = new WeakMap<ShellTrace, ShellVisualizationSource>();
14
+
15
+ /** Bind the immutable snapshot before publishing it; live paints borrow the actual run. */
16
+ export function attachShellTrace(snapshot: ShellTrace, trace: RunTrace): void {
17
+ visualizations.set(snapshot, trace);
18
+ }
19
+
20
+ /** Historical traces restore their canonical native archive only once per snapshot. */
21
+ export function shellVisualization(snapshot: ShellTrace): ShellVisualizationSource {
22
+ let visualization = visualizations.get(snapshot);
23
+ if (!visualization) {
24
+ visualization = new ShellVisualization(JSON.stringify(snapshot));
25
+ visualizations.set(snapshot, visualization);
26
+ }
27
+ return visualization;
28
+ }
29
+
30
+ /** Python-like Pseudo, all layers enabled, one pane, live, paused, normal speed. */
31
+ export function defaultShellVizPreferences(): ShellVizPreferences {
32
+ return {
33
+ view: "pseudo",
34
+ layers: { color: true, inline: true, idioms: true, effects: true, unwrap: true },
35
+ split: false,
36
+ playing: false,
37
+ speed: 1,
38
+ expandedNodes: [],
39
+ };
40
+ }
41
+
42
+ /** Render through native ownership; an explicit replay cursor never uses the normal output sink. */
43
+ export function readShellPresentation(
44
+ source: ShellVisualizationSource,
45
+ preferences: ShellVizPreferences,
46
+ snapshot?: ShellTrace,
47
+ output?: string,
48
+ ): ShellVizPresentation {
49
+ const options: ShellVizOptions = {
50
+ ...preferences,
51
+ cursorSeq: preferences.cursor === undefined ? undefined : snapshot?.history?.[preferences.cursor - 1]?.seq,
52
+ };
53
+ const presentation = decodeShellPresentation(source.present(options));
54
+ if (preferences.cursor === undefined && output !== undefined) presentation.output = output;
55
+ return presentation;
56
+ }
57
+
58
+ function record(value: unknown): value is Record<string, unknown> {
59
+ return typeof value === "object" && value !== null && !Array.isArray(value);
60
+ }
61
+ function finite(value: unknown): value is number {
62
+ return typeof value === "number" && Number.isFinite(value);
63
+ }
64
+ function string(value: unknown): value is string {
65
+ return typeof value === "string";
66
+ }
67
+ function boolean(value: unknown): value is boolean {
68
+ return typeof value === "boolean";
69
+ }
70
+ /** Node keys are opaque; validation must never invent or reinterpret engine identity. */
71
+ export function isShellVizNode(value: unknown): value is string {
72
+ return typeof value === "string" && /^(0|[1-9][0-9]*):(0|[1-9][0-9]*):(0|[1-9][0-9]*)$/.test(value);
73
+ }
74
+ function optional(value: Record<string, unknown>, key: string, valid: (value: unknown) => boolean): boolean {
75
+ return value[key] === undefined || valid(value[key]);
76
+ }
77
+ function range(value: unknown): boolean {
78
+ return Array.isArray(value) && value.length === 2 && value.every(finite) && value[0] >= 0 && value[1] >= value[0];
79
+ }
80
+ function state(value: unknown): boolean {
81
+ return value === "pending" || value === "running" || value === "ok" || value === "fail" || value === "skipped";
82
+ }
83
+ function preferences(value: unknown): value is ShellVizPreferences {
84
+ if (!record(value) || !record(value.layers)) return false;
85
+ const layers = value.layers;
86
+ return (
87
+ (value.view === "raw" || value.view === "pseudo") &&
88
+ ["color", "inline", "idioms", "effects", "unwrap"].every(key => boolean(layers[key])) &&
89
+ boolean(value.split) &&
90
+ boolean(value.playing) &&
91
+ finite(value.speed) &&
92
+ optional(value, "cursor", finite) &&
93
+ optional(value, "selectedNode", isShellVizNode) &&
94
+ Array.isArray(value.expandedNodes) &&
95
+ value.expandedNodes.every(isShellVizNode)
96
+ );
97
+ }
98
+ function watch(value: unknown): value is ShellVizWatch {
99
+ return (
100
+ record(value) &&
101
+ string(value.name) &&
102
+ string(value.value) &&
103
+ optional(value, "fullLength", finite) &&
104
+ optional(value, "scope", string) &&
105
+ optional(value, "scopeId", string) &&
106
+ optional(value, "node", isShellVizNode) &&
107
+ optional(value, "range", range) &&
108
+ optional(value, "setterSeq", finite)
109
+ );
110
+ }
111
+ function segment(value: unknown): value is ShellVizSegment {
112
+ return (
113
+ record(value) &&
114
+ string(value.text) &&
115
+ optional(value, "active", boolean) &&
116
+ optional(value, "state", state) &&
117
+ optional(value, "executedAtNs", finite) &&
118
+ optional(value, "executionSeq", finite) &&
119
+ optional(value, "style", string) &&
120
+ optional(value, "node", isShellVizNode) &&
121
+ optional(value, "executionNode", isShellVizNode) &&
122
+ optional(value, "range", range) &&
123
+ optional(value, "tip", string) &&
124
+ optional(value, "expanded", string) &&
125
+ optional(value, "language", string)
126
+ );
127
+ }
128
+ function row(value: unknown): value is ShellVizRow {
129
+ return (
130
+ record(value) &&
131
+ string(value.id) &&
132
+ finite(value.depth) &&
133
+ optional(value, "node", isShellVizNode) &&
134
+ optional(value, "range", range) &&
135
+ optional(value, "active", boolean) &&
136
+ optional(value, "state", state) &&
137
+ optional(value, "role", role => ["stmt", "head", "mid", "tail", "raw", "document"].includes(String(role))) &&
138
+ Array.isArray(value.segments) &&
139
+ value.segments.every(segment) &&
140
+ Array.isArray(value.effects) &&
141
+ value.effects.every(
142
+ effect =>
143
+ record(effect) &&
144
+ ["network", "write", "destructive", "secret", "privilege", "background"].includes(String(effect.kind)) &&
145
+ string(effect.glyph) &&
146
+ string(effect.label) &&
147
+ string(effect.why),
148
+ ) &&
149
+ optional(value, "executedAtNs", finite) &&
150
+ optional(value, "executionSeq", finite) &&
151
+ optional(value, "meta", string) &&
152
+ optional(value, "detail", string) &&
153
+ optional(value, "annotations", annotations => Array.isArray(annotations) && annotations.every(watch))
154
+ );
155
+ }
156
+ function presentation(value: unknown): value is ShellVizPresentation {
157
+ if (!record(value) || !record(value.timeline)) return false;
158
+ const timeline = value.timeline;
159
+ return (
160
+ preferences(value.preferences) &&
161
+ Array.isArray(value.rows) &&
162
+ value.rows.every(row) &&
163
+ Array.isArray(value.original) &&
164
+ value.original.every(row) &&
165
+ string(value.output) &&
166
+ optional(value, "running", boolean) &&
167
+ boolean(value.executing) &&
168
+ Array.isArray(value.watches) &&
169
+ value.watches.every(watch) &&
170
+ ["length", "cursor", "elapsedNs", "durationNs"].every(key => finite(timeline[key])) &&
171
+ optional(timeline, "trimmed", boolean) &&
172
+ optional(value, "message", string)
173
+ );
174
+ }
175
+
176
+ /** Decode semantic display data, never shell syntax or execution state. */
177
+ export function decodeShellPresentation(json: string): ShellVizPresentation {
178
+ const value: unknown = JSON.parse(json);
179
+ if (!presentation(value)) throw new Error("Native shell returned an invalid visualization presentation");
180
+ return value;
181
+ }
@@ -1612,17 +1612,27 @@ export class OutputSink {
1612
1612
  const effectiveTotalBytes = Math.max(0, this.#totalBytes - this.#columnDroppedBytes);
1613
1613
 
1614
1614
  if (headBytes > 0 && effectiveTotalBytes > headBytes + tailBytes) {
1615
- // Middle was elided. Emit head + marker + tail.
1616
- const elidedBytes = Math.max(0, effectiveTotalBytes - headBytes - tailBytes);
1617
- const elidedLines = Math.max(0, totalLines - headLines - tailLines);
1615
+ // Middle was elided. Emit head + marker + tail, each window cut back to whole lines (a window that is one
1616
+ // line fragment stays as is): a line split at the marker reads as two lines, and the counts below would
1617
+ // no longer name the source lines shown.
1618
+ const headCut = this.#head.endsWith("\n") ? -1 : this.#head.lastIndexOf("\n");
1619
+ const head = headCut >= 0 ? this.#head.slice(0, headCut + 1) : this.#head;
1620
+ const tailCut = tailBuf.indexOf("\n");
1621
+ const tail = tailCut >= 0 && tailCut < tailBuf.length - 1 ? tailBuf.slice(tailCut + 1) : tailBuf;
1622
+ const keptHeadBytes = head === this.#head ? headBytes : Buffer.byteLength(head, "utf-8");
1623
+ const keptTailBytes = tail === tailBuf ? tailBytes : Buffer.byteLength(tail, "utf-8");
1624
+ const keptHeadLines = head === this.#head ? headLines : countNewlines(head);
1625
+ const keptTailLines = tail === tailBuf ? tailLines : countNewlines(tail) + 1;
1626
+ const elidedBytes = Math.max(0, effectiveTotalBytes - keptHeadBytes - keptTailBytes);
1627
+ const elidedLines = Math.max(0, totalLines - keptHeadLines - keptTailLines);
1618
1628
  const marker = formatMiddleElisionMarker(elidedLines, elidedBytes);
1619
1629
  const markerBytes = Buffer.byteLength(marker, "utf-8");
1620
- const headSep = this.#head.endsWith("\n") ? "" : "\n";
1621
- const tailSep = tailBuf.startsWith("\n") ? "" : "\n";
1630
+ const headSep = head.endsWith("\n") ? "" : "\n";
1631
+ const tailSep = tail.startsWith("\n") ? "" : "\n";
1622
1632
  return {
1623
- body: `${this.#head}${headSep}${marker}${tailSep}${tailBuf}`,
1624
- outputBytes: headBytes + markerBytes + tailBytes + headSep.length + tailSep.length,
1625
- outputLines: headLines + 1 + tailLines,
1633
+ body: `${head}${headSep}${marker}${tailSep}${tail}`,
1634
+ outputBytes: keptHeadBytes + markerBytes + keptTailBytes + headSep.length + tailSep.length,
1635
+ outputLines: keptHeadLines + 1 + keptTailLines,
1626
1636
  elidedBytes,
1627
1637
  elidedLines,
1628
1638
  };
@@ -106,8 +106,8 @@ export interface CoordinationDetails {
106
106
  from?: string;
107
107
  to?: string;
108
108
  receipts?: IrcDeliveryReceipt[];
109
- /** Message consumed by `wait`. */
110
- waited?: IrcMessage | null;
109
+ /** Messages consumed by `wait`, oldest first. */
110
+ waited?: IrcMessage[];
111
111
  jobs?: JobSnapshot[];
112
112
  cancelled?: {
113
113
  id: string;