@oh-my-pi/pi-tui 18.11.3 → 18.12.1

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 (58) hide show
  1. package/CHANGELOG.md +37 -93
  2. package/README.md +36 -0
  3. package/dist/types/chat/advisor-message.d.ts +4 -1
  4. package/dist/types/chat/messages.d.ts +3 -1
  5. package/dist/types/chrome/diff.d.ts +2 -3
  6. package/dist/types/render/hanging-wrap.d.ts +2 -0
  7. package/dist/types/render/render-utils.d.ts +9 -1
  8. package/dist/types/status-line/types.d.ts +3 -0
  9. package/dist/types/terminal-capabilities.d.ts +8 -1
  10. package/dist/types/terminal-multiplexer.d.ts +6 -0
  11. package/dist/types/theme/theme.d.ts +11 -0
  12. package/dist/types/tmux.d.ts +9 -0
  13. package/dist/types/tools/ast-edit.d.ts +2 -2
  14. package/dist/types/tools/ast-grep.d.ts +2 -2
  15. package/dist/types/tools/edit.d.ts +2 -0
  16. package/dist/types/tools/eval.d.ts +51 -7
  17. package/dist/types/tools/find.d.ts +14 -4
  18. package/dist/types/tools/glob.d.ts +3 -3
  19. package/dist/types/tools/grep.d.ts +2 -2
  20. package/dist/types/tools/grouped-file-output.d.ts +3 -3
  21. package/dist/types/tools/read.d.ts +14 -6
  22. package/dist/types/tools/write.d.ts +2 -0
  23. package/package.json +9 -9
  24. package/src/chat/advisor-message.ts +77 -24
  25. package/src/chat/assistant-message.ts +3 -1
  26. package/src/chat/messages.ts +4 -1
  27. package/src/chat/read-tool-group.ts +19 -11
  28. package/src/chat/tool-execution.ts +23 -6
  29. package/src/chrome/diff.ts +4 -9
  30. package/src/components/image.ts +31 -14
  31. package/src/render/hanging-wrap.ts +28 -1
  32. package/src/render/render-utils.ts +16 -2
  33. package/src/status-line/component.ts +1 -0
  34. package/src/status-line/segments.ts +4 -3
  35. package/src/status-line/types.ts +1 -0
  36. package/src/terminal-capabilities.ts +33 -3
  37. package/src/terminal-multiplexer.ts +14 -0
  38. package/src/terminal.ts +11 -2
  39. package/src/theme/theme.ts +46 -14
  40. package/src/tmux.ts +37 -1
  41. package/src/tools/ast-edit.ts +30 -7
  42. package/src/tools/ast-grep.ts +25 -6
  43. package/src/tools/debug.ts +2 -1
  44. package/src/tools/default-renderer.ts +3 -2
  45. package/src/tools/edit.ts +80 -19
  46. package/src/tools/eval.ts +132 -132
  47. package/src/tools/find.ts +71 -18
  48. package/src/tools/glob.ts +51 -17
  49. package/src/tools/grep.ts +94 -13
  50. package/src/tools/grouped-file-output.ts +6 -5
  51. package/src/tools/lsp.ts +23 -18
  52. package/src/tools/mcp.ts +2 -2
  53. package/src/tools/read.ts +55 -25
  54. package/src/tools/task.ts +9 -7
  55. package/src/tools/web-search.ts +2 -1
  56. package/src/tools/write.ts +22 -8
  57. package/src/tools/yield.ts +2 -2
  58. package/src/tui.ts +36 -0
@@ -1,6 +1,6 @@
1
1
  import type { SummaryResult } from "@oh-my-pi/pi-natives";
2
2
  import type { Component } from "../tui.js";
3
- import type { NativeToolView, RenderResultOptions, ToolActivityContext, ToolActivitySummary } from "./renderer.js";
3
+ import type { RenderResultContextOptions, NativeToolView, RenderResultOptions, ToolActivityContext, ToolActivitySummary } from "./renderer.js";
4
4
  import type { NativeNode } from "../native/node.js";
5
5
  import type { Theme } from "../theme/theme.js";
6
6
  import type { OutputMeta } from "./output-meta.js";
@@ -40,6 +40,11 @@ export interface ReadToolDetails {
40
40
  fileSize?: number;
41
41
  /** Full source line count when the read reached EOF and the count is exact. */
42
42
  totalLines?: number;
43
+ /**
44
+ * Whether the text's rows carry line-number prefixes (`N:` hashline, `N|` line numbers). Set where a
45
+ * file read is formatted; a raw read sets `false`. Snapcompact reads it to tell a `12:` prefix from content.
46
+ */
47
+ rowPrefixes?: boolean;
43
48
  /** Raw text + start line for user-visible TUI rendering, set when content is text-like.
44
49
  * Mirrors the same lines the model receives but without hashline/line-number prefixes,
45
50
  * so the TUI can render the file content with its own gutter without re-parsing the formatted text. */
@@ -55,7 +60,10 @@ export interface ReadToolDetails {
55
60
  };
56
61
  /** Number of unresolved git conflicts surfaced by this read (TUI uses for inline `⚠ N` badge). */
57
62
  conflictCount?: number;
58
- /** Paths recovered from a delimited read argument; used only by the TUI to render one call as multiple read rows. */
63
+ /**
64
+ * Paths recovered from a delimited read argument. The TUI renders one call as multiple read rows; snapcompact
65
+ * keeps such a composite result as text.
66
+ */
59
67
  displayReadTargets?: string[];
60
68
  /**
61
69
  * Resolved filesystem link target for each {@link displayReadTargets} entry, aligned by index; `null` when a
@@ -113,7 +121,7 @@ export declare function pendingFileLinkPath(inputPath: string): string;
113
121
  * target when the structured `resolvedPath` isn't set (the common plain-file and
114
122
  * image reads only record the path in `meta.source`). URL/internal sources are
115
123
  * not fs paths, so only `type: "path"` qualifies. */
116
- export declare function readSourceFsPath(details: ReadToolDetails | undefined): string | undefined;
124
+ export declare function readSourceFsPath(details: unknown): string | undefined;
117
125
  /**
118
126
  * Whether a read result renders as a Markdown preview rather than numbered source:
119
127
  * the read tool tagged it `text/markdown` (`read.renderMarkdown`, or a protocol
@@ -128,7 +136,7 @@ export declare function readResultIsMarkdown(details: ReadToolDetails | undefine
128
136
  * block; runs split with `…` between) when they cover every line, else count
129
137
  * up from `start`.
130
138
  */
131
- export declare function readContentCode(content: string, start: number, numbers: readonly (number | null)[] | undefined, lang: string | undefined): NativeNode[];
139
+ export declare function readContentCode(content: string, start: number, numbers: readonly (number | null)[] | undefined, path: string | undefined): NativeNode[];
132
140
  /** Render file, image, and URL reads in the transcript. */
133
141
  export declare const readToolRenderer: {
134
142
  activitySummary(args: unknown, _context: ToolActivityContext): ToolActivitySummary;
@@ -140,7 +148,7 @@ export declare const readToolRenderer: {
140
148
  }>;
141
149
  details?: ReadToolDetails;
142
150
  isError?: boolean;
143
- }, options: RenderResultOptions, uiTheme: Theme, args?: ReadRenderArgs): Component;
151
+ }, options: RenderResultContextOptions, uiTheme: Theme, args?: ReadRenderArgs): Component;
144
152
  describeCall(args: ReadRenderArgs): NativeToolView;
145
153
  /**
146
154
  * Inline (§7.3 read): the head names the file and range; the content
@@ -154,7 +162,7 @@ export declare const readToolRenderer: {
154
162
  }>;
155
163
  details?: ReadToolDetails;
156
164
  isError?: boolean;
157
- }, options: RenderResultOptions, args?: ReadRenderArgs): NativeToolView;
165
+ }, options: RenderResultContextOptions, args?: ReadRenderArgs): NativeToolView;
158
166
  mergeCallAndResult: true;
159
167
  };
160
168
  /** Inclusive line range describing one elided span in a structural summary. */
@@ -73,6 +73,8 @@ interface WriteStreamingPreviewStateCarrier {
73
73
  /** Render context for the write tool: resolves an `xd://`-mounted tool so its live renderer drives device dispatch previews. */
74
74
  export interface WriteRenderContext {
75
75
  resolveXdevMounted?: (name: string) => XdevMountedRenderer | undefined;
76
+ /** Original result metadata used only for filesystem link targets. */
77
+ rawDetails?: unknown;
76
78
  }
77
79
  /** Render file writes and delegated tool-device calls. */
78
80
  export declare const writeToolRenderer: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/pi-tui",
4
- "version": "18.11.3",
4
+ "version": "18.12.1",
5
5
  "description": "Terminal User Interface library with differential rendering for efficient text-based applications",
6
6
  "homepage": "https://omp.sh",
7
7
  "author": {
@@ -41,14 +41,14 @@
41
41
  "gen:glyphs": "bun scripts/gen-glyphs.ts"
42
42
  },
43
43
  "dependencies": {
44
- "@oh-my-pi/omptype": "18.11.3",
45
- "@oh-my-pi/pi-agent-core": "18.11.3",
46
- "@oh-my-pi/pi-ai": "18.11.3",
47
- "@oh-my-pi/pi-catalog": "18.11.3",
48
- "@oh-my-pi/pi-natives": "18.11.3",
49
- "@oh-my-pi/pi-utils": "18.11.3",
50
- "@oh-my-pi/pi-wire": "18.11.3",
51
- "@oh-my-pi/snapcompact": "18.11.3"
44
+ "@oh-my-pi/omptype": "18.12.1",
45
+ "@oh-my-pi/pi-agent-core": "18.12.1",
46
+ "@oh-my-pi/pi-ai": "18.12.1",
47
+ "@oh-my-pi/pi-catalog": "18.12.1",
48
+ "@oh-my-pi/pi-natives": "18.12.1",
49
+ "@oh-my-pi/pi-utils": "18.12.1",
50
+ "@oh-my-pi/pi-wire": "18.12.1",
51
+ "@oh-my-pi/snapcompact": "18.12.1"
52
52
  },
53
53
  "devDependencies": {
54
54
  "kitty-vt-wasm": "^0.2.0"
@@ -4,9 +4,9 @@ import { visibleWidth } from "../utils";
4
4
  import type { AdvisorMessageDetails, AdvisorNote, AdvisorSeverity } from "./messages";
5
5
  import { formatBadge, replaceTabs, type ToolUIColor, wrapTextWithAnsi } from "../render/render-utils";
6
6
  import { Ellipsis, truncateToWidth } from "../render";
7
- import { getThemeEpoch, type Theme } from "../theme";
8
- import type { TspSpan } from "@oh-my-pi/pi-wire";
9
- import { card, span, text } from "../native/describe";
7
+ import type { Theme } from "../theme";
8
+ import type { TspSpan, TspTone } from "@oh-my-pi/pi-wire";
9
+ import { card, node, span, text } from "../native/describe";
10
10
  import { type NativeNode, type NativeUiEvent, rootToggleExpanded } from "../native/node";
11
11
  import { plainText } from "../native/spans";
12
12
  import { Memo } from "../native/memo";
@@ -111,13 +111,16 @@ class AdvisorNotes implements Component {
111
111
  }
112
112
  }
113
113
 
114
+ /** The advisor a note came from; undefined for the implicit single ("default") advisor, which goes unlabeled. */
115
+ function sourceOf(entry: AdvisorNote): string | undefined {
116
+ return entry.advisor && entry.advisor !== "default" ? entry.advisor : undefined;
117
+ }
118
+
114
119
  /** Wrapped, truncated rail rows for a single note; shared by both branches. */
115
120
  function renderAdvisorNote(entry: AdvisorNote, width: number, uiTheme: Theme): string[] {
116
121
  const badge = entry.severity ? `${formatBadge(entry.severity, severityColor(entry.severity), uiTheme)} ` : "";
117
- // Multi-advisor: attribute the note to its source. The implicit
118
- // single ("default") advisor renders unlabeled, as before.
119
- const who =
120
- entry.advisor && entry.advisor !== "default" ? `${uiTheme.fg("dim", `[${replaceTabs(entry.advisor)}]`)} ` : "";
122
+ const source = sourceOf(entry);
123
+ const who = source ? `${uiTheme.fg("dim", `[${replaceTabs(source)}]`)} ` : "";
121
124
  const age = entry.turnsAgo !== undefined ? `${uiTheme.fg("dim", `T-${entry.turnsAgo}`)} ` : "";
122
125
  const railGlyph = uiTheme.symbol("advisor.rail");
123
126
  const rail = uiTheme.fg(severityColor(entry.severity), railGlyph);
@@ -145,16 +148,47 @@ function renderAdvisorNote(entry: AdvisorNote, width: number, uiTheme: Theme): s
145
148
  );
146
149
  }
147
150
 
148
- /** Native spans for one note: severity badge, advisor attribution, then the note text. */
149
- function advisorNoteSpans(entry: AdvisorNote): TspSpan[] {
151
+ /** A note's rank in the native callout: its severity, `note` when it has none. */
152
+ type AdvisorRank = AdvisorSeverity | "note";
153
+
154
+ /** Ranks worst first: the callout wears the worst rank among its notes. */
155
+ const RANKS: readonly AdvisorRank[] = ["blocker", "concern", "nit", "note"];
156
+
157
+ /** Each rank's native look, GitHub-alert style: card/icon tone, Tern icon name, label and its span style. */
158
+ const RANK_LOOK: Record<AdvisorRank, { tone: TspTone; icon: string; label: string; style: string }> = {
159
+ blocker: { tone: "error", icon: "octagon-alert", label: "Blocker", style: "error strong" },
160
+ concern: { tone: "warning", icon: "warn", label: "Concern", style: "warning strong" },
161
+ nit: { tone: "neutral", icon: "lightbulb", label: "Nit", style: "strong" },
162
+ note: { tone: "neutral", icon: "info", label: "Note", style: "strong" },
163
+ };
164
+
165
+ function rankOf(entry: AdvisorNote): AdvisorRank {
166
+ return entry.severity ?? "note";
167
+ }
168
+
169
+ /** The callout's title: one note's rank (`Concern`), else a tally worst first (`1 blocker · 2 concerns`). */
170
+ function tallySpans(notes: readonly AdvisorNote[]): TspSpan[] {
171
+ if (notes.length === 1) {
172
+ const { label, style } = RANK_LOOK[rankOf(notes[0]!)];
173
+ return [span(label, style)];
174
+ }
150
175
  const spans: TspSpan[] = [];
151
- if (entry.severity)
152
- spans.push(span(entry.severity.toUpperCase(), `${severityColor(entry.severity)} strong`), span(" "));
153
- if (entry.advisor && entry.advisor !== "default") spans.push(span(`[${entry.advisor}] `, "dim"));
154
- spans.push(span(plainText(entry.note), "customMessageText"));
176
+ for (const rank of RANKS) {
177
+ const count = notes.filter(entry => rankOf(entry) === rank).length;
178
+ if (count === 0) continue;
179
+ if (spans.length > 0) spans.push(span(" · ", "dim"));
180
+ spans.push(span(`${count} ${rank}${count === 1 ? "" : "s"}`, RANK_LOOK[rank].style));
181
+ }
155
182
  return spans;
156
183
  }
157
184
 
185
+ /** Native spans for one note: its advisor when the callout mixes several, then the text. */
186
+ function noteSpans(entry: AdvisorNote, attribute: boolean): TspSpan[] {
187
+ const who = attribute ? sourceOf(entry) : undefined;
188
+ const body = span(plainText(entry.note));
189
+ return who ? [span(`${who} · `, "dim"), body] : [body];
190
+ }
191
+
158
192
  /** The advisor card: shared by the controlled expansion getter and native toggles. */
159
193
  export interface AdvisorMessageCard extends Component {
160
194
  /** Transcript-wide expansion (`Ctrl+O`); clears a toggle made in the terminal. */
@@ -168,6 +202,9 @@ export interface AdvisorMessageCard extends Component {
168
202
  * output (whose `thinkingText` color equals `toolOutput` in most themes):
169
203
  * a bold `customMessageLabel` header tag (skill-card convention), a heavy
170
204
  * rail tinted per-note severity, and the note body on the default text color.
205
+ * Natively it is a callout tinted by its worst note: that severity's icon and
206
+ * the tally head it, the advisor's name ends the head, and with several notes
207
+ * each leads with its own severity icon.
171
208
  *
172
209
  * `getExpanded` owns expansion; a native toggle overrides it for this card
173
210
  * until the next transcript-wide change.
@@ -193,24 +230,40 @@ export function createAdvisorMessageCard(
193
230
  };
194
231
  const nativeMemo = new Memo();
195
232
  const describeCard = (isExpanded: boolean): NativeNode => {
196
- const head: TspSpan[] = [
197
- span(`${uiTheme.status.info} Advisor`, "customMessageLabel strong"),
198
- span(` ${notes.length} ${notes.length === 1 ? "note" : "notes"}`, "dim"),
199
- ];
200
- if (blockers > 0) head.push(span(`${uiTheme.sep.dot}${blockers} blocker${blockers === 1 ? "" : "s"}`, "error"));
201
- const body = notes.map((entry, index) =>
202
- text(advisorNoteSpans(entry), { wrap: "word", role: "omp.advisor.note", key: `n${index}` }),
233
+ const look = RANK_LOOK[RANKS.find(rank => notes.some(entry => rankOf(entry) === rank)) ?? "note"];
234
+ const sources = new Set(notes.map(sourceOf));
235
+ const [sole] = sources;
236
+ const head = node(
237
+ "row",
238
+ { gap: "sm", align: "center", role: "omp.advisor.head" },
239
+ [
240
+ node("icon", { name: look.icon, tone: look.tone }),
241
+ text(tallySpans(notes), { grow: 1 }),
242
+ text([span(sources.size === 1 && sole ? sole : "Advisor", "dim")], { role: "omp.advisor.source" }),
243
+ ],
244
+ "head",
203
245
  );
246
+ const attribute = sources.size > 1;
247
+ const body = notes.map((entry, index) => {
248
+ const spans = noteSpans(entry, attribute);
249
+ if (notes.length === 1) return text(spans, { wrap: "word", role: "omp.advisor.note", key: `n${index}` });
250
+ const { tone, icon, label } = RANK_LOOK[rankOf(entry)];
251
+ return node(
252
+ "row",
253
+ { gap: "sm", align: "start", role: "omp.advisor.note", tone },
254
+ [node("icon", { name: icon, tone, aria: label }), text(spans, { wrap: "word", grow: 1, shrink: 1 })],
255
+ `n${index}`,
256
+ );
257
+ });
204
258
  return card(
205
259
  {
206
260
  role: "omp.advisor",
207
- tone: blockers > 0 ? "error" : "info",
208
- head,
261
+ tone: look.tone,
209
262
  collapsible: notes.length > COLLAPSED_NOTES,
210
263
  collapsed: notes.length > COLLAPSED_NOTES ? !isExpanded : undefined,
211
264
  preview: notes.length > COLLAPSED_NOTES ? "auto" : undefined,
212
265
  },
213
- body,
266
+ [head, ...body],
214
267
  );
215
268
  };
216
269
 
@@ -231,7 +284,7 @@ export function createAdvisorMessageCard(
231
284
  },
232
285
  describe(): NativeNode {
233
286
  const isExpanded = expanded();
234
- return nativeMemo.get([isExpanded, getThemeEpoch()], () => describeCard(isExpanded));
287
+ return nativeMemo.get([isExpanded], () => describeCard(isExpanded));
235
288
  },
236
289
  setExpanded(value: boolean): void {
237
290
  lastGlobal = value;
@@ -1,4 +1,5 @@
1
1
  import type { AssistantMessage, ImageContent, TextContent } from "@oh-my-pi/pi-ai";
2
+ import { presentNarrationAsAnswer } from "@oh-my-pi/pi-ai/utils/narration";
2
3
  import { type Component, Container } from "../tui";
3
4
  import { Image, type ImageBudget } from "../components/image";
4
5
  import { ImageProtocol, TERMINAL } from "../terminal-capabilities";
@@ -1803,7 +1804,8 @@ export class AssistantMessageComponent extends Container {
1803
1804
  this.#lastUpdateTransient = opts?.transient === true;
1804
1805
  // Everything below renders the display form; #lastMessage keeps the
1805
1806
  // verbatim message so re-renders re-derive the reaction deterministically.
1806
- message = this.#displayMessage(message, this.#lastUpdateTransient);
1807
+ // Narration the provider returned as thinking renders as answer text.
1808
+ message = this.#displayMessage(presentNarrationAsAnswer(message), this.#lastUpdateTransient);
1807
1809
  this.#displayedMessage = message;
1808
1810
 
1809
1811
  // Streaming-speed gauge: only a live, in-flight render of the single
@@ -286,7 +286,10 @@ export function isUserTurnInitiator(message: CustomMessage): boolean {
286
286
  );
287
287
  }
288
288
 
289
- export type AdvisorSeverity = "nit" | "concern" | "blocker";
289
+ /** Advisor note severities, weakest first; ranks severity thresholds such as `advisor.continueSeverity`. */
290
+ export const ADVISOR_SEVERITIES = ["nit", "concern", "blocker"] as const;
291
+
292
+ export type AdvisorSeverity = (typeof ADVISOR_SEVERITIES)[number];
290
293
 
291
294
  /** One queued advice note. */
292
295
  export interface AdvisorNote {
@@ -22,7 +22,7 @@ import { canonicalizeMessage } from "./thinking-display";
22
22
  import { internalUrlSchemeSpec, splitUrlScheme } from "../tools/url-scheme-host";
23
23
  import type { ToolExecutionHandle } from "./tool-execution";
24
24
  import { formatUsageRow } from "../overlays/usage-row";
25
- import { formatCount } from "@oh-my-pi/pi-utils";
25
+ import { formatCount, sanitizeText, sanitizeTextDeep } from "@oh-my-pi/pi-utils";
26
26
  import type { TspCardStatus, TspSpan, TspText } from "@oh-my-pi/pi-wire";
27
27
  import type { NativeToolHead } from "../tools/renderer";
28
28
  import { card, code, keyed, md, node, span, text, withHidden } from "../native/describe";
@@ -188,9 +188,12 @@ const READ_STATUS_RANK: Record<ReadEntry["status"], number> = {
188
188
  error: 3,
189
189
  };
190
190
 
191
- function getDisplayReadTargets(details: ReadToolDetails | undefined): ReadDisplayPathSpec[] | undefined {
191
+ function getDisplayReadTargets(
192
+ details: ReadToolDetails | undefined,
193
+ rawDetails: ReadToolDetails | undefined,
194
+ ): ReadDisplayPathSpec[] | undefined {
192
195
  if (!Array.isArray(details?.displayReadTargets)) return undefined;
193
- const links = Array.isArray(details.displayReadTargetLinks) ? details.displayReadTargetLinks : undefined;
196
+ const links = Array.isArray(rawDetails?.displayReadTargetLinks) ? rawDetails.displayReadTargetLinks : undefined;
194
197
  const targets: ReadDisplayPathSpec[] = [];
195
198
  details.displayReadTargets.forEach((raw, index) => {
196
199
  if (typeof raw !== "string") return;
@@ -437,12 +440,14 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
437
440
  if (!toolCallId) return;
438
441
  const rawPath =
439
442
  typeof args.file_path === "string" ? args.file_path : typeof args.path === "string" ? args.path : "";
443
+ const displayPath = sanitizeText(rawPath);
440
444
  const entry: ReadEntry = this.#entries.get(toolCallId) ?? {
441
445
  toolCallId,
442
- path: rawPath,
446
+ path: displayPath,
443
447
  status: "pending",
444
448
  };
445
- entry.path = rawPath;
449
+ entry.path = displayPath;
450
+ entry.linkPath = path.isAbsolute(rawPath) ? rawPath : undefined;
446
451
  entry.raw = args.raw === true;
447
452
  this.#entries.set(toolCallId, entry);
448
453
  this.#updateDisplay();
@@ -484,12 +489,15 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
484
489
  if (!entry) return;
485
490
  if (isPartial) return;
486
491
  this.#blockVersion++;
487
- const details = result.details as ReadToolDetails | undefined;
492
+ // `details` can contain raw file text and filesystem paths. Keep the
493
+ // latter for links while only the sanitized copy supplies display labels.
494
+ const rawDetails = result.details as ReadToolDetails | undefined;
495
+ const details = sanitizeTextDeep(rawDetails) as ReadToolDetails | undefined;
488
496
  const suffixResolution = getSuffixResolution(details);
489
- const displayPaths = getDisplayReadTargets(details);
490
- entry.linkPath = readResultLinkPath(details);
497
+ const displayPaths = getDisplayReadTargets(details, rawDetails);
498
+ entry.linkPath = readResultLinkPath(rawDetails) ?? entry.linkPath;
491
499
  if (suffixResolution) {
492
- entry.path = displayPathWithSuffixResolution(entry.path, suffixResolution);
500
+ entry.path = sanitizeText(displayPathWithSuffixResolution(entry.path, suffixResolution));
493
501
  entry.correctedFrom = suffixResolution.from;
494
502
  entry.displayPaths = undefined;
495
503
  } else {
@@ -753,7 +761,7 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
753
761
  lines.slice(0, shown).join("\n"),
754
762
  entry.codeStartLine ?? firstSelectorLine(split.sel) ?? 1,
755
763
  entry.codeLineNumbers?.slice(0, shown),
756
- getLanguageFromPath(split.path),
764
+ split.path,
757
765
  );
758
766
  const hidden = lines.length - shown;
759
767
  if (hidden > 0) {
@@ -828,7 +836,7 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
828
836
  previewsMarkdown(entry)
829
837
  ? md(entry.contentText ?? "")
830
838
  : code(entry.contentText ?? "", {
831
- lang: getLanguageFromPath(split.path),
839
+ path: split.path,
832
840
  start: entry.codeStartLine,
833
841
  numbers: true,
834
842
  wrap: true,
@@ -8,7 +8,7 @@ import { Text } from "../components/text";
8
8
  import { getImageDimensions, ImageProtocol, imageFallback, TERMINAL } from "../terminal-capabilities";
9
9
  import { type Component, Container, type TUI } from "../tui";
10
10
  import { truncateToWidth } from "../utils";
11
- import { getProjectDir, isRecord, logger, sanitizeText } from "@oh-my-pi/pi-utils";
11
+ import { getProjectDir, isRecord, logger, sanitizeText, sanitizeTextDeep } from "@oh-my-pi/pi-utils";
12
12
  import type { Theme } from "../theme/theme";
13
13
  import { ensureThemeSync, getThemeEpoch, theme } from "../theme/theme";
14
14
  import {
@@ -420,6 +420,8 @@ export class ToolExecutionComponent extends Container {
420
420
  isError?: boolean;
421
421
  details?: unknown;
422
422
  };
423
+ // Machine paths remain verbatim; only #result.details is handed to display renderers.
424
+ #rawDetails: unknown;
423
425
  // Edit preview state
424
426
  #editMode?: EditMode;
425
427
  #editDiffPreview?: PerFileDiffPreview[];
@@ -632,7 +634,11 @@ export class ToolExecutionComponent extends Container {
632
634
  const partialResultPainted = this.#partialResultShapePainted;
633
635
  this.#firstResultViewportRepaintShapePainted = false;
634
636
  this.#partialResultShapePainted = false;
635
- this.#result = result;
637
+ this.#rawDetails = result.details;
638
+ // Renderers receive sanitized details for display; raw paths are available
639
+ // separately for links and media through the built-in render context.
640
+ const details = sanitizeTextDeep(result.details);
641
+ this.#result = details === result.details ? result : { ...result, details };
636
642
  this.#resultVersion++;
637
643
  this.#blockVersion++;
638
644
  this.#isPartial = isPartial;
@@ -1251,7 +1257,7 @@ export class ToolExecutionComponent extends Container {
1251
1257
  #nativeResultImages(body: readonly NativeChild[] | undefined): NativeNode[] {
1252
1258
  if (!this.#result || !this.#showImages) return [];
1253
1259
  const shown = shownMedia(body);
1254
- const mediaPath = readMediaPath(this.#result.details);
1260
+ const mediaPath = readMediaPath(this.#rawDetails);
1255
1261
  if (mediaPath && shown.paths.has(mediaPath)) return [];
1256
1262
  const images: NativeNode[] = [];
1257
1263
  this.#getAllImageBlocks().forEach((image, index) => {
@@ -1558,6 +1564,10 @@ export class ToolExecutionComponent extends Container {
1558
1564
  this.#contentBox.clear();
1559
1565
 
1560
1566
  const renderContext = this.#buildRenderContext();
1567
+ const rawPerFileResults =
1568
+ isRecord(this.#rawDetails) && Array.isArray(this.#rawDetails.perFileResults)
1569
+ ? this.#rawDetails.perFileResults
1570
+ : undefined;
1561
1571
  this.#renderState.renderContext = renderContext;
1562
1572
 
1563
1573
  for (let i = 0; i < perFileResults.length; i++) {
@@ -1569,9 +1579,13 @@ export class ToolExecutionComponent extends Container {
1569
1579
  }
1570
1580
  const fileBox = new Box(0, 0);
1571
1581
  try {
1582
+ const fileOptions = {
1583
+ ...this.#renderState,
1584
+ renderContext: { ...renderContext, rawDetails: rawPerFileResults?.[i] },
1585
+ };
1572
1586
  const resultComponent = renderer.renderResult(
1573
1587
  { content: [], details: fileResult, isError: fileResult.isError },
1574
- this.#renderState,
1588
+ fileOptions,
1575
1589
  theme,
1576
1590
  );
1577
1591
  if (resultComponent) {
@@ -1695,7 +1709,7 @@ export class ToolExecutionComponent extends Container {
1695
1709
 
1696
1710
  if (this.#result) {
1697
1711
  const imageBlocks = this.#getAllImageBlocks();
1698
- const sourcePath = readMediaPath(this.#result.details);
1712
+ const sourcePath = readMediaPath(this.#rawDetails);
1699
1713
 
1700
1714
  for (let i = 0; i < imageBlocks.length; i++) {
1701
1715
  const img = imageBlocks[i];
@@ -1802,6 +1816,9 @@ export class ToolExecutionComponent extends Container {
1802
1816
  return Math.max(1, Math.min(maxSeconds, value));
1803
1817
  };
1804
1818
 
1819
+ if (this.#renderer && !this.#tool?.renderResult && this.#rawDetails !== undefined) {
1820
+ context.rawDetails = this.#rawDetails;
1821
+ }
1805
1822
  if (this.#toolName === "bash") {
1806
1823
  // Bash needs render context even before a result exists. The renderer uses the pending-call args
1807
1824
  // plus this context to keep the inline command preview visible while tool-call JSON is still streaming.
@@ -1882,7 +1899,7 @@ export class ToolExecutionComponent extends Container {
1882
1899
  const dims = img.data ? (getImageDimensions(img.data, mimeType) ?? undefined) : undefined;
1883
1900
  const placeholder = imageFallback(mimeType, dims);
1884
1901
  return img.data
1885
- ? linkedImageText(placeholder, { data: img.data, mimeType }, readMediaPath(this.#result?.details))
1902
+ ? linkedImageText(placeholder, { data: img.data, mimeType }, readMediaPath(this.#rawDetails))
1886
1903
  : placeholder;
1887
1904
  })
1888
1905
  .join("\n");
@@ -2,7 +2,7 @@ import { diffWords } from "@oh-my-pi/pi-natives";
2
2
  import { DEFAULT_TAB_WIDTH, sanitizeText } from "@oh-my-pi/pi-utils";
3
3
  import type { TspDiffHunk, TspProps } from "@oh-my-pi/pi-wire";
4
4
  import { theme as activeTheme, getLanguageFromPath, highlightCode, type Theme } from "../theme/index";
5
- import { type CodeFrameMarker, formatCodeFrameLine, replaceTabs, shortenPath } from "../render/render-utils";
5
+ import { type CodeFrameMarker, formatCodeFrameLine, replaceTabs } from "../render/render-utils";
6
6
  import { node } from "../native/describe";
7
7
  import type { NativeNode } from "../native/node";
8
8
  /** SGR dim on / normal intensity — additive, preserves fg/bg colors. */
@@ -106,9 +106,9 @@ function renderIntraLineDiff(
106
106
  * becomes one hunk; the terminal draws gutters, word emphasis and highlighting.
107
107
  * Removed rows carry old line numbers, added rows new ones and context rows
108
108
  * old ones, so the other side is derived from the running line delta.
109
+ * Tern picks the grammar from `path`.
109
110
  */
110
- export function nativeDiff(diffText: string, options: { filePath?: string } & TspProps<"diff"> = {}): NativeNode {
111
- const { filePath, ...props } = options;
111
+ export function nativeDiff(diffText: string, props: TspProps<"diff"> = {}): NativeNode {
112
112
  const hunks: TspDiffHunk[] = [];
113
113
  let lines: string[] = [];
114
114
  let oldStart = 0;
@@ -148,12 +148,7 @@ export function nativeDiff(diffText: string, options: { filePath?: string } & Ts
148
148
  lines.push(`${parsed.prefix}${parsed.content}`);
149
149
  }
150
150
  close();
151
- return node("diff", {
152
- ...props,
153
- hunks,
154
- path: props.path ?? (filePath ? shortenPath(filePath) : undefined),
155
- lang: props.lang ?? (filePath ? getLanguageFromPath(filePath) : undefined),
156
- });
151
+ return node("diff", { ...props, hunks });
157
152
  }
158
153
 
159
154
  export interface RenderDiffOptions {
@@ -4,6 +4,7 @@ import {
4
4
  encodeSixelNow,
5
5
  getCellDimensions,
6
6
  getImageDimensions,
7
+ getTerminalBackgroundColor,
7
8
  type ImageDimensions,
8
9
  ImageProtocol,
9
10
  imageFallback,
@@ -41,6 +42,13 @@ export interface ImageOptions {
41
42
  requestRender?: () => void;
42
43
  }
43
44
 
45
+ interface SixelEncode {
46
+ widthPx: number;
47
+ heightPx: number;
48
+ backgroundRgb: number;
49
+ sequence?: string | null;
50
+ }
51
+
44
52
  /** Renders in progress whose rows are bound for native scrollback. */
45
53
  let scrollbackRenderDepth = 0;
46
54
 
@@ -655,6 +663,7 @@ export class Image implements Component {
655
663
  #cachedImageProtocol: typeof TERMINAL.imageProtocol = null;
656
664
  #cachedCellWidthPx = 0;
657
665
  #cachedCellHeightPx = 0;
666
+ #cachedSixelBackground: number | undefined;
658
667
  #cachedKittyUnicodePlaceholders = false;
659
668
  #cachedLinked = false;
660
669
  // Tallest graphic placement this image has rendered. The text fallback
@@ -663,8 +672,8 @@ export class Image implements Component {
663
672
  #renderedGraphicRows = 0;
664
673
  /** Described node and the link policy it was built under (an `off` switch drops its `href`). */
665
674
  #native?: { linked: boolean; node: NativeNode };
666
- /** Newest SIXEL encode: its target size and, once settled, the sequence (`null` on failure). */
667
- #sixel?: { widthPx: number; heightPx: number; sequence?: string | null };
675
+ /** Newest SIXEL encode: target size, compositing background, and settled sequence. */
676
+ #sixel?: SixelEncode;
668
677
 
669
678
  constructor(
670
679
  base64Data: string,
@@ -704,33 +713,38 @@ export class Image implements Component {
704
713
  }
705
714
 
706
715
  /**
707
- * SIXEL sequence for a target size. A new size starts the encode off the JS
716
+ * SIXEL sequence for a target size and background. A change starts the encode off the JS
708
717
  * thread and answers `undefined` until it settles; the settled encode
709
718
  * invalidates the cached lines and requests a repaint. A render bound for
710
719
  * scrollback cannot wait, so it encodes synchronously.
711
720
  */
712
- #sixelSequence(widthPx: number, heightPx: number): string | null | undefined {
721
+ #sixelSequence(widthPx: number, heightPx: number, backgroundRgb: number): string | null | undefined {
713
722
  const current = this.#sixel;
714
- const sameSize = current !== undefined && current.widthPx === widthPx && current.heightPx === heightPx;
715
- if (sameSize && current.sequence !== undefined) return current.sequence;
723
+ const sameInput =
724
+ current !== undefined &&
725
+ current.widthPx === widthPx &&
726
+ current.heightPx === heightPx &&
727
+ current.backgroundRgb === backgroundRgb;
728
+ if (sameInput && current.sequence !== undefined) return current.sequence;
716
729
  if (scrollbackRenderDepth > 0) {
717
730
  // Replacing the entry makes a still-pending async encode settle as stale.
718
- const sequence = encodeSixelNow(this.#base64Data, widthPx, heightPx);
719
- this.#sixel = { widthPx, heightPx, sequence };
731
+ const sequence = encodeSixelNow(this.#base64Data, widthPx, heightPx, backgroundRgb);
732
+ this.#sixel = { widthPx, heightPx, backgroundRgb, sequence };
720
733
  return sequence;
721
734
  }
722
- if (sameSize) return undefined;
723
- const request: { widthPx: number; heightPx: number; sequence?: string | null } = { widthPx, heightPx };
735
+ if (sameInput) return undefined;
736
+ const request: SixelEncode = { widthPx, heightPx, backgroundRgb };
724
737
  this.#sixel = request;
725
738
  const settle = (sequence: string | null): void => {
726
739
  request.sequence = sequence;
727
- if (this.#sixel !== request) return;
740
+ if (this.#sixel !== request || getTerminalBackgroundColor() !== backgroundRgb) return;
728
741
  this.invalidate();
729
742
  if (this.#options.requestRender) this.#options.requestRender();
730
743
  else this.#budget?.requestRender();
731
744
  };
732
- encodeSixelAsync(new Uint8Array(Buffer.from(this.#base64Data, "base64")), widthPx, heightPx).then(settle, () =>
733
- settle(null),
745
+ encodeSixelAsync(new Uint8Array(Buffer.from(this.#base64Data, "base64")), widthPx, heightPx, backgroundRgb).then(
746
+ settle,
747
+ () => settle(null),
734
748
  );
735
749
  return undefined;
736
750
  }
@@ -768,6 +782,7 @@ export class Image implements Component {
768
782
  const hasProtocol = imageProtocol != null;
769
783
  const cellDimensions = getCellDimensions();
770
784
  const kittyUnicodePlaceholders = getKittyGraphics().unicodePlaceholders;
785
+ const sixelBackground = imageProtocol === ImageProtocol.Sixel ? getTerminalBackgroundColor() : undefined;
771
786
  // observe() must run on every pass — even a cache hit — so the image keeps
772
787
  // its display-order slot in the budget. Only graphics-capable frames count
773
788
  // toward (and are demoted by) the budget; without a protocol every image is
@@ -789,6 +804,7 @@ export class Image implements Component {
789
804
  this.#cachedImageProtocol === imageProtocol &&
790
805
  this.#cachedCellWidthPx === cellDimensions.widthPx &&
791
806
  this.#cachedCellHeightPx === cellDimensions.heightPx &&
807
+ this.#cachedSixelBackground === sixelBackground &&
792
808
  this.#cachedKittyUnicodePlaceholders === kittyUnicodePlaceholders &&
793
809
  // The text fallback embeds a link only under an enabled hyperlink policy.
794
810
  this.#cachedLinked === linked &&
@@ -813,7 +829,7 @@ export class Image implements Component {
813
829
  maxHeightCells: this.#options.maxHeightCells,
814
830
  imageId: this.#imageId,
815
831
  includeTransmit: needsTransmit,
816
- sixel: (widthPx, heightPx) => this.#sixelSequence(widthPx, heightPx),
832
+ sixel: (widthPx, heightPx) => this.#sixelSequence(widthPx, heightPx, sixelBackground!),
817
833
  });
818
834
 
819
835
  if (result?.transmit && this.#imageId != null && this.#budget !== undefined) {
@@ -861,6 +877,7 @@ export class Image implements Component {
861
877
  this.#cachedImageProtocol = imageProtocol;
862
878
  this.#cachedCellWidthPx = cellDimensions.widthPx;
863
879
  this.#cachedCellHeightPx = cellDimensions.heightPx;
880
+ this.#cachedSixelBackground = sixelBackground;
864
881
  this.#cachedKittyUnicodePlaceholders = kittyUnicodePlaceholders;
865
882
  this.#cachedLinked = linked;
866
883