@oh-my-pi/pi-tui 18.11.2 → 18.12.0

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 (61) hide show
  1. package/CHANGELOG.md +37 -100
  2. package/README.md +36 -0
  3. package/dist/types/components/markdown.d.ts +4 -3
  4. package/dist/types/overlays/approval-dialog.d.ts +25 -15
  5. package/dist/types/overlays/model-picker.d.ts +2 -0
  6. package/dist/types/overlays/session-selector.d.ts +2 -0
  7. package/dist/types/prompt/internal-url-autocomplete.d.ts +1 -0
  8. package/dist/types/render/hanging-wrap.d.ts +2 -0
  9. package/dist/types/render/render-utils.d.ts +9 -1
  10. package/dist/types/status-line/types.d.ts +3 -0
  11. package/dist/types/terminal-capabilities.d.ts +8 -1
  12. package/dist/types/terminal-multiplexer.d.ts +6 -0
  13. package/dist/types/theme/symbols.d.ts +1 -1
  14. package/dist/types/theme/theme.d.ts +11 -0
  15. package/dist/types/tools/ast-edit.d.ts +2 -2
  16. package/dist/types/tools/ast-grep.d.ts +2 -2
  17. package/dist/types/tools/edit.d.ts +2 -0
  18. package/dist/types/tools/find.d.ts +14 -4
  19. package/dist/types/tools/glob.d.ts +3 -3
  20. package/dist/types/tools/grep.d.ts +2 -2
  21. package/dist/types/tools/read.d.ts +13 -5
  22. package/dist/types/tools/task.d.ts +8 -0
  23. package/dist/types/tools/write.d.ts +2 -0
  24. package/package.json +9 -9
  25. package/src/chat/assistant-message.ts +3 -1
  26. package/src/chat/read-tool-group.ts +17 -9
  27. package/src/chat/tool-execution.ts +23 -6
  28. package/src/components/image.ts +31 -14
  29. package/src/components/markdown.ts +74 -5
  30. package/src/overlays/approval-dialog.ts +104 -36
  31. package/src/overlays/model-picker.ts +58 -21
  32. package/src/overlays/session-selector.ts +14 -9
  33. package/src/prompt/internal-url-autocomplete.ts +1 -0
  34. package/src/render/hanging-wrap.ts +28 -1
  35. package/src/render/render-utils.ts +16 -2
  36. package/src/status-line/component.ts +1 -0
  37. package/src/status-line/segments.ts +16 -5
  38. package/src/status-line/types.ts +1 -0
  39. package/src/terminal-capabilities.ts +35 -21
  40. package/src/terminal-multiplexer.ts +14 -0
  41. package/src/terminal.ts +11 -2
  42. package/src/theme/symbols.ts +1 -0
  43. package/src/theme/theme-class.ts +1 -0
  44. package/src/theme/theme.ts +46 -14
  45. package/src/tmux.ts +7 -1
  46. package/src/tools/ast-edit.ts +28 -4
  47. package/src/tools/ast-grep.ts +24 -4
  48. package/src/tools/debug.ts +2 -1
  49. package/src/tools/default-renderer.ts +3 -2
  50. package/src/tools/edit.ts +77 -16
  51. package/src/tools/find.ts +65 -15
  52. package/src/tools/glob.ts +51 -17
  53. package/src/tools/grep.ts +94 -11
  54. package/src/tools/lsp.ts +23 -18
  55. package/src/tools/mcp.ts +2 -2
  56. package/src/tools/read.ts +52 -22
  57. package/src/tools/task.ts +17 -7
  58. package/src/tools/web-search.ts +2 -1
  59. package/src/tools/write.ts +17 -5
  60. package/src/tools/yield.ts +2 -2
  61. package/src/tui.ts +36 -0
package/src/tools/grep.ts CHANGED
@@ -1,6 +1,14 @@
1
+ import * as path from "node:path";
2
+ import { isRecord, sanitizeText } from "@oh-my-pi/pi-utils";
1
3
  import type { Component } from "../tui";
2
4
  import { Text } from "../components/text";
3
- import type { NativeToolHead, NativeToolView, RenderResultOptions, ToolRenderer } from "./renderer";
5
+ import type {
6
+ NativeToolHead,
7
+ NativeToolView,
8
+ RenderResultContextOptions,
9
+ RenderResultOptions,
10
+ ToolRenderer,
11
+ } from "./renderer";
4
12
  import { getLanguageFromPath } from "../lang-from-path";
5
13
  import { compact } from "../native/describe";
6
14
  import type { NativeChild } from "../native/node";
@@ -88,12 +96,84 @@ const NATIVE_COLLAPSED_FILES = 2;
88
96
 
89
97
  const SEARCH_CODE_FRAME_LINE_RE = /^\s*\*?(\d+)│/;
90
98
 
91
- function searchScopeMeta(details: GrepToolDetails | undefined): string | undefined {
99
+ function searchScopeMeta(details: GrepToolDetails | undefined, searchPath?: string): string | undefined {
92
100
  if (!details?.scopePath) return undefined;
93
- const label = details.searchPath ? fileHyperlink(details.searchPath, details.scopePath) : details.scopePath;
101
+ const label = searchPath ? fileHyperlink(searchPath, details.scopePath) : details.scopePath;
94
102
  return `in ${label}`;
95
103
  }
96
104
 
105
+ function isStringArray(value: unknown): value is string[] {
106
+ return Array.isArray(value) && value.every((item: unknown) => typeof item === "string");
107
+ }
108
+
109
+ function isStringRecord(value: unknown): value is Record<string, string> {
110
+ if (!isRecord(value)) return false;
111
+ for (const key in value) {
112
+ if (typeof value[key] !== "string") return false;
113
+ }
114
+ return true;
115
+ }
116
+
117
+ function samePath(filePath: string): string {
118
+ return filePath;
119
+ }
120
+
121
+ /** Keep only path metadata from the original details; display text always comes from sanitized details. */
122
+ function grepLinkTargets(details: GrepToolDetails | undefined, rawDetails: unknown) {
123
+ if (details === rawDetails) {
124
+ return {
125
+ target: samePath,
126
+ searchPath: details?.searchPath,
127
+ fileScope: details?.searchPath,
128
+ displayTargets: details?.displayTargets,
129
+ };
130
+ }
131
+ const raw = typeof rawDetails === "object" && rawDetails !== null ? rawDetails : {};
132
+ const rawCwd = "cwd" in raw && typeof raw.cwd === "string" ? raw.cwd : undefined;
133
+ const rawSearchPath = "searchPath" in raw && typeof raw.searchPath === "string" ? raw.searchPath : undefined;
134
+ const rawFiles = "files" in raw && isStringArray(raw.files) ? raw.files : undefined;
135
+ const rawDisplayTargets =
136
+ "displayTargets" in raw && isStringRecord(raw.displayTargets) ? raw.displayTargets : undefined;
137
+ let displayTargets = details?.displayTargets;
138
+ if (rawDisplayTargets) {
139
+ displayTargets = {};
140
+ for (const label in rawDisplayTargets) {
141
+ displayTargets[sanitizeText(label)] = rawDisplayTargets[label]!;
142
+ }
143
+ }
144
+
145
+ const pathTargets = new Map<string, string>();
146
+ const displayBase = details?.cwd ?? details?.searchPath;
147
+ const rawBase = rawCwd ?? rawSearchPath ?? displayBase;
148
+ if (displayBase && rawBase && rawFiles && details?.files) {
149
+ for (let index = 0; index < Math.min(details.files.length, rawFiles.length); index++) {
150
+ const displayFile = path.resolve(displayBase, details.files[index]!);
151
+ const rawFile = path.resolve(rawBase, rawFiles[index]!);
152
+ pathTargets.set(displayFile, rawFile);
153
+ // Folded directory headers must retain the original path as well.
154
+ let displayDir = path.dirname(displayFile);
155
+ let rawDir = path.dirname(rawFile);
156
+ while (displayDir !== path.dirname(displayDir) && rawDir !== path.dirname(rawDir)) {
157
+ pathTargets.set(displayDir, rawDir);
158
+ displayDir = path.dirname(displayDir);
159
+ rawDir = path.dirname(rawDir);
160
+ }
161
+ }
162
+ }
163
+ const target = (displayPath: string): string => {
164
+ const known = pathTargets.get(displayPath);
165
+ if (known) return known;
166
+ if (rawCwd && details?.cwd) return path.resolve(rawCwd, path.relative(details.cwd, displayPath));
167
+ return displayPath;
168
+ };
169
+ return {
170
+ target,
171
+ searchPath: rawSearchPath ?? details?.searchPath,
172
+ fileScope: rawSearchPath ?? details?.searchPath,
173
+ displayTargets,
174
+ };
175
+ }
176
+
97
177
  function linkUrlLikeSearchHeader(
98
178
  raw: string,
99
179
  styled: string,
@@ -133,6 +213,7 @@ function createSearchLineStyler(
133
213
  fileScope: string | undefined,
134
214
  uiTheme: Theme,
135
215
  displayTargets: Record<string, string> | undefined,
216
+ target: (displayPath: string) => string,
136
217
  ): (index: number) => string {
137
218
  const contexts = classifyGroupedLines(lines, headerBase, fileScope);
138
219
  // `classifyGroupedLines` can't resolve internal URLs (TUI-only), so track the
@@ -167,7 +248,7 @@ function createSearchLineStyler(
167
248
  let styled: string;
168
249
  if (ctx.kind === "dir") {
169
250
  const accent = uiTheme.fg("accent", line);
170
- styled = ctx.headerPath ? fileHyperlink(ctx.headerPath, accent) : accent;
251
+ styled = ctx.headerPath ? fileHyperlink(target(ctx.headerPath), accent) : accent;
171
252
  } else if (ctx.kind === "file") {
172
253
  const raw = urlRaw[index];
173
254
  if (raw !== undefined) {
@@ -175,12 +256,12 @@ function createSearchLineStyler(
175
256
  } else {
176
257
  // Root-level files keep the bright accent; nested file headers are dimmed.
177
258
  const tinted = uiTheme.fg(ctx.depth === 1 ? "accent" : "dim", line);
178
- styled = ctx.headerPath ? fileHyperlink(ctx.headerPath, tinted) : tinted;
259
+ styled = ctx.headerPath ? fileHyperlink(target(ctx.headerPath), tinted) : tinted;
179
260
  }
180
261
  } else {
181
262
  const tinted = uiTheme.fg("toolOutput", line);
182
263
  const lineNumber = parseSearchDisplayLineNumber(line);
183
- const filePath = ctx.filePath ?? urlFiles[index];
264
+ const filePath = ctx.filePath ? target(ctx.filePath) : urlFiles[index];
184
265
  styled = filePath && lineNumber !== undefined ? fileHyperlink(filePath, tinted, { line: lineNumber }) : tinted;
185
266
  }
186
267
  styledLines[index] = styled;
@@ -289,7 +370,7 @@ export const grepToolRenderer = {
289
370
 
290
371
  renderResult(
291
372
  result: { content: Array<{ type: string; text?: string }>; details?: GrepToolDetails; isError?: boolean },
292
- options: RenderResultOptions,
373
+ options: RenderResultContextOptions,
293
374
  uiTheme: Theme,
294
375
  args?: GrepRenderArgs,
295
376
  ): Component {
@@ -338,6 +419,7 @@ export const grepToolRenderer = {
338
419
  { paddingX: 1 },
339
420
  );
340
421
  }
422
+ const linkTargets = grepLinkTargets(details, options.renderContext?.rawDetails);
341
423
 
342
424
  const matchCount = details?.matchCount ?? 0;
343
425
  const fileCount = details?.fileCount ?? 0;
@@ -353,7 +435,7 @@ export const grepToolRenderer = {
353
435
 
354
436
  if (matchCount === 0) {
355
437
  const meta = ["0 matches"];
356
- const scopeMeta = searchScopeMeta(details);
438
+ const scopeMeta = searchScopeMeta(details, linkTargets.searchPath);
357
439
  if (scopeMeta) meta.push(scopeMeta);
358
440
  const header = renderStatusLine(
359
441
  { icon: "warning", title: "Grep", titleColor: "toolTitle", description: args?.pattern, meta },
@@ -366,7 +448,7 @@ export const grepToolRenderer = {
366
448
 
367
449
  const summaryParts = [formatCount("match", matchCount), formatCount("file", fileCount)];
368
450
  const meta = [...summaryParts];
369
- const scopeMeta = searchScopeMeta(details);
451
+ const scopeMeta = searchScopeMeta(details, linkTargets.searchPath);
370
452
  if (scopeMeta) meta.push(scopeMeta);
371
453
  if (truncated) meta.push(uiTheme.fg("warning", "truncated"));
372
454
  const description = args?.pattern ?? undefined;
@@ -391,9 +473,10 @@ export const grepToolRenderer = {
391
473
  const styleLine = createSearchLineStyler(
392
474
  allLines,
393
475
  details?.cwd ?? details?.searchPath,
394
- details?.searchPath,
476
+ linkTargets.fileScope,
395
477
  uiTheme,
396
- details?.displayTargets,
478
+ linkTargets.displayTargets,
479
+ linkTargets.target,
397
480
  );
398
481
  const matchGroups = groupLineIndicesByBlank(allLines);
399
482
 
package/src/tools/lsp.ts CHANGED
@@ -28,7 +28,8 @@ import {
28
28
  } from "../render/render-utils";
29
29
  import { renderStatusLine } from "../render";
30
30
  import { framedToolCard } from "../render/tool-card";
31
- import { wrapPrefixedLine } from "../render/hanging-wrap";
31
+ import { wrapGuidedLine, wrapPrefixedLine } from "../render/hanging-wrap";
32
+ import { visibleWidth } from "../utils";
32
33
  import { ansi, code, col, compact, keyed, md, node, row, span, text } from "../native/describe";
33
34
  import type { NativeNode } from "../native/node";
34
35
  import { OwnerMemo } from "../native/memo";
@@ -264,12 +265,16 @@ export function renderResult(
264
265
  : formatStatusIcon(isPartial ? "running" : "error", theme, spinnerFrame);
265
266
  const header = `${icon} LSP ${actionLabel}`;
266
267
 
268
+ // Hover code hangs under its rail; expanded rows hang under their tree
269
+ // connector or guide rails so Ctrl+O reveals full text instead of clipping.
267
270
  const rail = ` ${theme.fg("mdCodeBlockBorder", theme.boxRound.vertical)} `;
268
271
  const contentLines = codeBlockMatch
269
272
  ? bodyLines.flatMap(line =>
270
273
  line.startsWith(rail) ? wrapPrefixedLine(rail, rail, line.slice(rail.length), contentWidth) : [line],
271
274
  )
272
- : bodyLines;
275
+ : expanded
276
+ ? bodyLines.flatMap(line => wrapGuidedLine(line, contentWidth, theme))
277
+ : bodyLines;
273
278
  return {
274
279
  header,
275
280
  phase: isPartial ? "partial" : state,
@@ -420,10 +425,7 @@ function renderDiagnostics(
420
425
  )}`;
421
426
  const message = formatDiagnosticMessage(item);
422
427
  if (message) {
423
- output += `\n ${theme.fg("dim", detailPrefix)}${theme.fg(
424
- "muted",
425
- truncateToWidth(message, TRUNCATE_LENGTHS.LINE),
426
- )}`;
428
+ output += `\n ${theme.fg("dim", detailPrefix)}${theme.fg("muted", message)}`;
427
429
  }
428
430
  }
429
431
  return output.split("\n");
@@ -434,7 +436,10 @@ function renderDiagnostics(
434
436
  parsedDiagnostics.length > 0 ? parsedDiagnostics.slice(0, 3) : fallbackDiagnostics.slice(0, 3);
435
437
  const remaining =
436
438
  (parsedDiagnostics.length > 0 ? parsedDiagnostics.length : fallbackDiagnostics.length) - previewItems.length;
437
- const expandHint = formatExpandHint(theme, expanded, remaining > 0);
439
+ const clipped = previewItems.some(
440
+ item => !("raw" in item) && visibleWidth(formatDiagnosticMessage(item)) > TRUNCATE_LENGTHS.CONTENT,
441
+ );
442
+ const expandHint = formatExpandHint(theme, expanded, remaining > 0 || clipped);
438
443
  let output = `${icon} ${theme.fg("dim", meta.join(theme.sep.dot))}${expandHint}`;
439
444
  for (let i = 0; i < previewItems.length; i++) {
440
445
  const item = previewItems[i];
@@ -486,8 +491,9 @@ function renderReferences(refMatch: RegExpMatchArray, lines: string[], expanded:
486
491
 
487
492
  const files = Array.from(byFile.keys());
488
493
 
489
- const renderGrouped = (maxFiles: number, maxLocsPerFile: number, showHint: boolean): string => {
490
- const expandHint = formatExpandHint(theme, undefined, showHint);
494
+ const renderGrouped = (maxFiles: number, maxLocsPerFile: number): string => {
495
+ const hidden = files.length > maxFiles || files.some(file => byFile.get(file)!.length > maxLocsPerFile);
496
+ const expandHint = formatExpandHint(theme, expanded, hidden);
491
497
  let output = `${icon} ${theme.fg("dim", `${refCount} found`)}${expandHint}`;
492
498
 
493
499
  const filesToShow = files.slice(0, maxFiles);
@@ -513,10 +519,9 @@ function renderReferences(refMatch: RegExpMatchArray, lines: string[], expanded:
513
519
  `line ${line}, col ${col}`,
514
520
  )}`;
515
521
  if (expanded) {
516
- const context = `at ${file}:${line}:${col}`;
517
522
  output += `\n ${theme.fg("dim", fileCont)}${theme.fg("dim", locCont)}${theme.fg(
518
523
  "muted",
519
- truncateToWidth(context, TRUNCATE_LENGTHS.LINE),
524
+ `at ${file}:${line}:${col}`,
520
525
  )}`;
521
526
  }
522
527
  }
@@ -539,11 +544,7 @@ function renderReferences(refMatch: RegExpMatchArray, lines: string[], expanded:
539
544
  return output;
540
545
  };
541
546
 
542
- if (expanded) {
543
- return renderGrouped(files.length, 3, false).split("\n");
544
- }
545
-
546
- return renderGrouped(3, 1, true).split("\n");
547
+ return (expanded ? renderGrouped(files.length, Number.POSITIVE_INFINITY) : renderGrouped(3, 1)).split("\n");
547
548
  }
548
549
 
549
550
  // =============================================================================
@@ -665,13 +666,17 @@ function renderGeneric(text: string, lines: string[], expanded: boolean, theme:
665
666
  for (let i = 0; i < lines.length; i++) {
666
667
  const isLast = i === lines.length - 1;
667
668
  const branch = isLast ? theme.tree.last : theme.tree.branch;
668
- output += `\n ${theme.fg("dim", branch)} ${truncateToWidth(replaceTabs(lines[i]), TRUNCATE_LENGTHS.CONTENT)}`;
669
+ output += `\n ${theme.fg("dim", branch)} ${replaceTabs(lines[i])}`;
669
670
  }
670
671
  return output.split("\n");
671
672
  }
672
673
 
673
674
  const firstLine = lines[0] || "No output";
674
- const expandHint = formatExpandHint(theme, expanded, lines.length > 1);
675
+ const expandHint = formatExpandHint(
676
+ theme,
677
+ expanded,
678
+ lines.length > 1 || visibleWidth(firstLine) > TRUNCATE_LENGTHS.TITLE,
679
+ );
675
680
  let output = `${icon} ${theme.fg("dim", truncateToWidth(firstLine, TRUNCATE_LENGTHS.TITLE))}${expandHint}`;
676
681
 
677
682
  if (lines.length > 1) {
package/src/tools/mcp.ts CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  renderJsonTreeLines,
27
27
  } from "./json-tree";
28
28
  import { formatStyledTruncationWarning, stripOutputNotice } from "./output-meta";
29
- import { formatExpandHint, truncateToWidth } from "../render/render-utils";
29
+ import { clipCollapsed, formatExpandHint } from "../render/render-utils";
30
30
  import { formatOutputPaneLines, styleToolOutputLine } from "../render/output-pane";
31
31
  import type { StatusLineOptions } from "../render/status-line";
32
32
  import { plainToolCard, type ToolCardPhase } from "../render/tool-card";
@@ -267,7 +267,7 @@ export function renderMCPResult(
267
267
  expanded,
268
268
  collapsedMaxLines: 4,
269
269
  expandedMaxLines: 12,
270
- styleLine: line => truncateToWidth(styleToolOutputLine(line, theme), contentWidth),
270
+ styleLine: line => clipCollapsed(styleToolOutputLine(line, theme), contentWidth, expanded),
271
271
  showExpandHintWhenUncapped: true,
272
272
  },
273
273
  theme,
package/src/tools/read.ts CHANGED
@@ -4,10 +4,12 @@ import { LINE_RANGE_CHUNK_SOURCE, parseLineRanges } from "./line-ranges";
4
4
  import * as os from "node:os";
5
5
  import * as path from "node:path";
6
6
  import { parseArchivePathCandidates } from "@oh-my-pi/pi-utils/ar";
7
+ import { isRecord, sanitizeText } from "@oh-my-pi/pi-utils";
7
8
  import type { Component } from "../tui";
8
9
  import { Text } from "../components/text";
9
10
  import type {
10
11
  NativeToolHead,
12
+ RenderResultContextOptions,
11
13
  NativeToolView,
12
14
  RenderResultOptions,
13
15
  ToolActivityContext,
@@ -15,7 +17,7 @@ import type {
15
17
  ToolRenderer,
16
18
  } from "./renderer";
17
19
  import { ansi, compact, md } from "../native/describe";
18
- import { base64ImageNode, nativeMediaNode } from "../native/blobs";
20
+ import { base64ImageNode, nativeMediaNode, readMediaPath } from "../native/blobs";
19
21
  import type { NativeChild, NativeNode } from "../native/node";
20
22
  import { fileHref, footnoteText, inlineErrorView, resultText } from "./native-view";
21
23
  import { numberedCode } from "./grouped-file-output";
@@ -71,6 +73,11 @@ export interface ReadToolDetails {
71
73
  fileSize?: number;
72
74
  /** Full source line count when the read reached EOF and the count is exact. */
73
75
  totalLines?: number;
76
+ /**
77
+ * Whether the text's rows carry line-number prefixes (`N:` hashline, `N|` line numbers). Set where a
78
+ * file read is formatted; a raw read sets `false`. Snapcompact reads it to tell a `12:` prefix from content.
79
+ */
80
+ rowPrefixes?: boolean;
74
81
  /** Raw text + start line for user-visible TUI rendering, set when content is text-like.
75
82
  * Mirrors the same lines the model receives but without hashline/line-number prefixes,
76
83
  * so the TUI can render the file content with its own gutter without re-parsing the formatted text. */
@@ -82,7 +89,10 @@ export interface ReadToolDetails {
82
89
  summary?: { lines: number; elidedSpans: number; elidedLines: number };
83
90
  /** Number of unresolved git conflicts surfaced by this read (TUI uses for inline `⚠ N` badge). */
84
91
  conflictCount?: number;
85
- /** Paths recovered from a delimited read argument; used only by the TUI to render one call as multiple read rows. */
92
+ /**
93
+ * Paths recovered from a delimited read argument. The TUI renders one call as multiple read rows; snapcompact
94
+ * keeps such a composite result as text.
95
+ */
86
96
  displayReadTargets?: string[];
87
97
  /**
88
98
  * Resolved filesystem link target for each {@link displayReadTargets} entry, aligned by index; `null` when a
@@ -302,9 +312,17 @@ function firstReadSelectorLine(sel: string | undefined): number | undefined {
302
312
  * target when the structured `resolvedPath` isn't set (the common plain-file and
303
313
  * image reads only record the path in `meta.source`). URL/internal sources are
304
314
  * not fs paths, so only `type: "path"` qualifies. */
305
- export function readSourceFsPath(details: ReadToolDetails | undefined): string | undefined {
306
- const source = details?.meta?.source;
307
- return source?.type === "path" && typeof source.value === "string" ? source.value : undefined;
315
+ export function readSourceFsPath(details: unknown): string | undefined {
316
+ if (!isRecord(details) || !isRecord(details.meta) || !isRecord(details.meta.source)) return undefined;
317
+ const source = details.meta.source;
318
+ return source.type === "path" && typeof source.value === "string" ? source.value : undefined;
319
+ }
320
+
321
+ function readLinkTarget(details: unknown): string | undefined {
322
+ if (!isRecord(details)) return undefined;
323
+ if (typeof details.resolvedPath === "string") return details.resolvedPath;
324
+ if (typeof details.displayTarget === "string") return details.displayTarget;
325
+ return readSourceFsPath(details);
308
326
  }
309
327
 
310
328
  function formatReadPathLink(
@@ -320,9 +338,11 @@ function formatReadPathLink(
320
338
  const split = splitReadRenderPath(rawPath);
321
339
  const basePath = split.path || rawPath;
322
340
  const selectorSuffix = split.sel ? `:${split.sel}` : "";
323
- const plainDisplayPath = options.suffixResolution
324
- ? shortenPath(options.suffixResolution.to)
325
- : shortenPath(basePath || options.resolvedPath || options.fallbackLabel || rawPath);
341
+ const plainDisplayPath = sanitizeText(
342
+ options.suffixResolution
343
+ ? shortenPath(options.suffixResolution.to)
344
+ : shortenPath(basePath || options.resolvedPath || options.fallbackLabel || rawPath),
345
+ );
326
346
  // Calls render before the tool has resolved a filesystem target. Preserve
327
347
  // protocol resources as plain text, but resolve direct relative file paths
328
348
  // so terminals receive an explicit file: link rather than guessing HTTPS.
@@ -358,7 +378,12 @@ export function readResultIsMarkdown(details: ReadToolDetails | undefined, args:
358
378
  * target (shortened, plus the selector / legacy offset range), a `file://`
359
379
  * link when the fs path is known, and a suffix correction as meta.
360
380
  */
361
- function readNativeHead(rawPath: string, args: ReadRenderArgs | undefined, details?: ReadToolDetails): NativeToolHead {
381
+ function readNativeHead(
382
+ rawPath: string,
383
+ args: ReadRenderArgs | undefined,
384
+ details?: ReadToolDetails,
385
+ linkPath?: string,
386
+ ): NativeToolHead {
362
387
  const split = splitReadRenderPath(rawPath);
363
388
  const suffix = details?.suffixResolution;
364
389
  let target = suffix ? shortenPath(suffix.to) : shortenPath(split.path || rawPath);
@@ -377,9 +402,9 @@ function readNativeHead(rawPath: string, args: ReadRenderArgs | undefined, detai
377
402
  const conflicts = details?.conflictCount ?? 0;
378
403
  return {
379
404
  title: "Read",
380
- target: target || "…",
405
+ target: sanitizeText(target) || "…",
381
406
  targetKind: "path",
382
- href: fileHref(details?.resolvedPath ?? details?.displayTarget ?? readSourceFsPath(details)),
407
+ href: fileHref(linkPath ?? details?.resolvedPath ?? details?.displayTarget ?? readSourceFsPath(details)),
383
408
  meta,
384
409
  badges:
385
410
  conflicts > 0 ? [{ text: `${conflicts} conflict${conflicts === 1 ? "" : "s"}`, tone: "warning" }] : undefined,
@@ -454,7 +479,7 @@ export const readToolRenderer = {
454
479
  typeof input?.file_path === "string" ? input.file_path : typeof input?.path === "string" ? input.path : "";
455
480
  const routed = readUrlCard(rawPath);
456
481
  if (routed) return { label: routed.card.label, detail: routed.target || routed.card.rootDetail };
457
- return { label: "Read", detail: shortenPath(rawPath) };
482
+ return { label: "Read", detail: sanitizeText(shortenPath(rawPath)) };
458
483
  },
459
484
  renderCall(args: ReadRenderArgs, _options: RenderResultOptions, uiTheme: Theme): Component {
460
485
  const rawPath =
@@ -481,10 +506,11 @@ export const readToolRenderer = {
481
506
 
482
507
  renderResult(
483
508
  result: { content: Array<{ type: string; text?: string }>; details?: ReadToolDetails; isError?: boolean },
484
- options: RenderResultOptions,
509
+ options: RenderResultContextOptions,
485
510
  uiTheme: Theme,
486
511
  args?: ReadRenderArgs,
487
512
  ): Component {
513
+ const linkPath = readLinkTarget(options.renderContext?.rawDetails);
488
514
  const urlDetails = result.details as ReadUrlToolDetails | undefined;
489
515
  const baseRawPathForKind =
490
516
  typeof args?.file_path === "string" ? args.file_path : typeof args?.path === "string" ? args.path : "";
@@ -511,8 +537,8 @@ export const readToolRenderer = {
511
537
  const filePath =
512
538
  formatReadPathLink(rawPath, {
513
539
  offset: args?.offset,
514
- sourcePath: result.details?.displayTarget ?? readSourceFsPath(result.details),
515
- }) || shortenPath(rawPath);
540
+ sourcePath: linkPath ?? result.details?.displayTarget ?? readSourceFsPath(result.details),
541
+ }) || sanitizeText(shortenPath(rawPath));
516
542
  let title = filePath ? `Read ${filePath}` : "Read";
517
543
  if (args?.offset !== undefined || args?.limit !== undefined) {
518
544
  const startLine = args.offset ?? 1;
@@ -544,7 +570,9 @@ export const readToolRenderer = {
544
570
  const truncation = details?.meta?.truncation;
545
571
  const fallback = details?.truncation;
546
572
  if (details?.resolvedPath) {
547
- warningLines.push(uiTheme.fg("dim", wrapBrackets(`Resolved path: ${details.resolvedPath}`, uiTheme)));
573
+ warningLines.push(
574
+ uiTheme.fg("dim", wrapBrackets(`Resolved path: ${shortenPath(details.resolvedPath)}`, uiTheme)),
575
+ );
548
576
  }
549
577
  if (truncation) {
550
578
  if (fallback?.firstLineExceedsLimit) {
@@ -562,7 +590,7 @@ export const readToolRenderer = {
562
590
  if (imageContent) {
563
591
  const suffix = details?.suffixResolution;
564
592
  const displayPath = formatReadPathLink(rawPath, {
565
- resolvedPath: details?.resolvedPath,
593
+ resolvedPath: linkPath ?? details?.resolvedPath,
566
594
  sourcePath: details?.displayTarget ?? readSourceFsPath(details),
567
595
  suffixResolution: suffix,
568
596
  fallbackLabel: "image",
@@ -594,7 +622,7 @@ export const readToolRenderer = {
594
622
  // reads only record the absolute path in meta.source, so fall back to that
595
623
  // to keep the title clickable.
596
624
  const displayPath = formatReadPathLink(rawPath, {
597
- resolvedPath: details?.resolvedPath,
625
+ resolvedPath: linkPath ?? details?.resolvedPath,
598
626
  sourcePath: details?.displayTarget ?? readSourceFsPath(details),
599
627
  suffixResolution: suffix,
600
628
  offset: args?.offset,
@@ -676,9 +704,10 @@ export const readToolRenderer = {
676
704
  */
677
705
  describeResult(
678
706
  result: { content: Array<{ type: string; text?: string }>; details?: ReadToolDetails; isError?: boolean },
679
- options: RenderResultOptions,
707
+ options: RenderResultContextOptions,
680
708
  args?: ReadRenderArgs,
681
709
  ): NativeToolView {
710
+ const linkPath = readLinkTarget(options.renderContext?.rawDetails);
682
711
  const details = result.details;
683
712
  const rawPath = readRawPath(args);
684
713
  const routed = readUrlCard(rawPath, details);
@@ -694,11 +723,11 @@ export const readToolRenderer = {
694
723
 
695
724
  if (result.isError) {
696
725
  const message = (resultText(result) || "Unknown error").replace(/^Error:\s*/, "");
697
- return inlineErrorView(readNativeHead(rawPath, args, details), message);
726
+ return inlineErrorView(readNativeHead(rawPath, args, details, linkPath), message);
698
727
  }
699
728
 
700
729
  const suffix = details?.suffixResolution;
701
- const head = readNativeHead(rawPath, args, details);
730
+ const head = readNativeHead(rawPath, args, details, linkPath);
702
731
  const truncation = details?.meta?.truncation;
703
732
  const fallback = details?.truncation;
704
733
  const firstLineTooLong = truncation !== undefined && fallback?.firstLineExceedsLimit === true;
@@ -713,7 +742,8 @@ export const readToolRenderer = {
713
742
 
714
743
  const contentText = details?.displayContent?.text ?? stripOutputNotice(resultText(result), details?.meta);
715
744
  // A file Tern's media viewer shows (image, model, PDF, video, audio): the host loads it by path.
716
- const media = options.media && details?.mediaPath ? nativeMediaNode(details.mediaPath, "media") : undefined;
745
+ const mediaPath = readMediaPath(options.renderContext?.rawDetails) ?? details?.mediaPath;
746
+ const media = options.media && mediaPath ? nativeMediaNode(mediaPath, "media") : undefined;
717
747
  const imageBlock = result.content?.find(isImageBlock);
718
748
  if (imageBlock) {
719
749
  const detailText = contentText.trim();
package/src/tools/task.ts CHANGED
@@ -31,6 +31,8 @@ import {
31
31
  isFeedModelBadgeEnabled,
32
32
  pluralize,
33
33
  previewLine,
34
+ clipCollapsed,
35
+ flattenLine,
34
36
  previewWindowRows,
35
37
  replaceTabs,
36
38
  shortenEmbeddedPaths,
@@ -351,7 +353,7 @@ function renderOutputSection(
351
353
  lines.push(
352
354
  `${continuePrefix} ${theme.fg("warning", theme.status.warning)} ${theme.fg(
353
355
  "dim",
354
- truncateToWidth(sanitizeText(warning), 80),
356
+ clipCollapsed(sanitizeText(warning), 80, expanded),
355
357
  )}`,
356
358
  );
357
359
 
@@ -395,7 +397,7 @@ function renderOutputSection(
395
397
  const outputLines = trimmedOutput.split("\n");
396
398
  const previewCount = expanded ? maxExpanded : maxCollapsed;
397
399
  for (const line of outputLines.slice(0, previewCount)) {
398
- lines.push(`${continuePrefix} ${theme.fg("dim", truncateToWidth(replaceTabs(line), 70))}`);
400
+ lines.push(`${continuePrefix} ${theme.fg("dim", clipCollapsed(replaceTabs(line), 70, expanded))}`);
399
401
  }
400
402
 
401
403
  if (outputLines.length > previewCount) {
@@ -448,7 +450,7 @@ function renderOutputSection(
448
450
  const outputLines = trimmedOutput.split("\n");
449
451
  const previewCount = expanded ? maxExpanded : maxCollapsed;
450
452
  for (const line of outputLines.slice(0, previewCount)) {
451
- lines.push(`${continuePrefix} ${theme.fg("dim", truncateToWidth(replaceTabs(line), 70))}`);
453
+ lines.push(`${continuePrefix} ${theme.fg("dim", clipCollapsed(replaceTabs(line), 70, expanded))}`);
452
454
  }
453
455
 
454
456
  if (outputLines.length > previewCount) {
@@ -472,7 +474,7 @@ function renderTaskSection(
472
474
  lines.push(`${continuePrefix}${theme.fg("dim", "Task")}`);
473
475
  const taskLines = trimmed.split("\n");
474
476
  for (const line of taskLines.slice(0, maxExpanded)) {
475
- lines.push(`${continuePrefix} ${theme.fg("dim", truncateToWidth(replaceTabs(line), 70))}`);
477
+ lines.push(`${continuePrefix} ${theme.fg("dim", replaceTabs(line))}`);
476
478
  }
477
479
  if (taskLines.length > maxExpanded) {
478
480
  lines.push(`${continuePrefix} ${theme.fg("dim", formatMoreItems(taskLines.length - maxExpanded, "line"))}`);
@@ -1123,7 +1125,7 @@ function renderAgentResult(
1123
1125
  lines.push(
1124
1126
  `${continuePrefix}${theme.fg("error", theme.status.aborted)} ${theme.fg(
1125
1127
  "dim",
1126
- previewLine(sanitizeText(result.abortReason), 80),
1128
+ clipCollapsed(flattenLine(sanitizeText(result.abortReason)), 80, expanded),
1127
1129
  )}`,
1128
1130
  );
1129
1131
  }
@@ -1215,7 +1217,7 @@ function renderAgentResult(
1215
1217
  lines.push(
1216
1218
  `${continuePrefix}${theme.fg("warning", theme.status.warning)} ${theme.fg(
1217
1219
  "dim",
1218
- truncateToWidth(sanitizeText(missingCompleteWarning), 80),
1220
+ clipCollapsed(sanitizeText(missingCompleteWarning), 80, expanded),
1219
1221
  )}`,
1220
1222
  );
1221
1223
  }
@@ -1255,7 +1257,7 @@ function renderAgentResult(
1255
1257
  // Error message
1256
1258
  if (result.error && (!success || mergeFailed) && (!aborted || result.error !== result.abortReason)) {
1257
1259
  lines.push(
1258
- `${continuePrefix}${theme.fg(mergeFailed ? "warning" : "error", previewLine(sanitizeText(result.error), 70))}`,
1260
+ `${continuePrefix}${theme.fg(mergeFailed ? "warning" : "error", clipCollapsed(flattenLine(sanitizeText(result.error)), 70, expanded))}`,
1259
1261
  );
1260
1262
  }
1261
1263
 
@@ -2204,6 +2206,10 @@ export interface TaskItem {
2204
2206
  name?: string;
2205
2207
  /** Agent type to run this item (e.g. "scout"). Defaults to the spawn policy's default agent. */
2206
2208
  agent?: string;
2209
+ /** Historical source session selected by the bundled consult agent. */
2210
+ sourceSession?: string;
2211
+ /** Optional model selector override for the historical source session. */
2212
+ model?: string | string[];
2207
2213
  /** The work; required by the schema. */
2208
2214
  task?: string;
2209
2215
  /** How open-ended the work is; required by the schema and the child's sole `auto` thinking classification input. */
@@ -2231,6 +2237,10 @@ export interface TaskParams {
2231
2237
  name?: string;
2232
2238
  /** Agent type to spawn (flat form); omitted values resolve from the session spawn policy. */
2233
2239
  agent?: string;
2240
+ /** Historical source session selected by the bundled consult agent. */
2241
+ sourceSession?: string;
2242
+ /** Optional model selector override for the historical source session. */
2243
+ model?: string | string[];
2234
2244
  /** The work (flat form). */
2235
2245
  task?: string;
2236
2246
  /** How open-ended the work is (flat form); see {@link TaskItem.solutionSpace}. */
@@ -19,6 +19,7 @@ import {
19
19
  PREVIEW_LIMITS,
20
20
  replaceTabs,
21
21
  truncateToWidth,
22
+ clipCollapsed,
22
23
  } from "../render/render-utils";
23
24
  import { renderStatusLine, renderTreeList, urlHyperlink } from "../render";
24
25
  import { framedToolCard } from "../render/tool-card";
@@ -34,7 +35,7 @@ const MAX_COLLAPSED_ITEMS = PREVIEW_LIMITS.COLLAPSED_ITEMS;
34
35
  function renderFallbackText(contentText: string, expanded: boolean, theme: Theme): Component {
35
36
  const lines = contentText.split("\n").filter(line => line.trim());
36
37
  const maxLines = expanded ? lines.length : 6;
37
- const displayLines = lines.slice(0, maxLines).map(line => truncateToWidth(line.trim(), 110));
38
+ const displayLines = lines.slice(0, maxLines).map(line => clipCollapsed(line.trim(), 110, expanded));
38
39
  const remaining = lines.length - displayLines.length;
39
40
 
40
41
  const headerIcon = formatStatusIcon("warning", theme);