@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/edit.ts CHANGED
@@ -198,6 +198,8 @@ export interface EditRenderContext {
198
198
  editStreamingFallback?: string;
199
199
  /** Function to render diff text with syntax highlighting */
200
200
  renderDiff?: (diffText: string, options?: { filePath?: string }) => string;
201
+ /** Unsanitized result metadata, used only for filesystem link targets. */
202
+ rawDetails?: unknown;
201
203
  }
202
204
 
203
205
  /**
@@ -297,7 +299,7 @@ function truncateEditTitlePath(displayPath: string, maxWidth: number | undefined
297
299
  }
298
300
 
299
301
  function formatEditTitlePath(pathValue: string, maxWidth?: number): string {
300
- return truncateEditTitlePath(replaceTabs(shortenPath(pathValue)), maxWidth);
302
+ return truncateEditTitlePath(replaceTabs(shortenPath(sanitizeText(pathValue))), maxWidth);
301
303
  }
302
304
 
303
305
  function formatEditPathDisplay(
@@ -357,6 +359,7 @@ function renderEditHeader(
357
359
  rename?: string;
358
360
  firstChangedLine?: number;
359
361
  linkPath?: string;
362
+ renameLinkPath?: string;
360
363
  statsSuffix?: string;
361
364
  extraSuffix?: string;
362
365
  title?: string;
@@ -367,6 +370,7 @@ function renderEditHeader(
367
370
  rename: options.rename,
368
371
  firstChangedLine: options.firstChangedLine,
369
372
  linkPath: options.linkPath,
373
+ renameLinkPath: options.renameLinkPath,
370
374
  };
371
375
  const formatted = formatEditDescription(options.rawPath, uiTheme, descriptionOptions);
372
376
  const suffix = `${options.statsSuffix ?? ""}${options.extraSuffix ?? ""}`;
@@ -402,7 +406,14 @@ function renderEditHeader(
402
406
  */
403
407
  function renderInlineEditRow(
404
408
  uiTheme: Theme,
405
- opts: { op?: Operation; rename?: string; rawPath: string; linkPath?: string; pending: boolean },
409
+ opts: {
410
+ op?: Operation;
411
+ rename?: string;
412
+ rawPath: string;
413
+ linkPath?: string;
414
+ renameLinkPath?: string;
415
+ pending: boolean;
416
+ },
406
417
  ): Component {
407
418
  const isDelete = opts.op === "delete";
408
419
  return new WidthAwareText(
@@ -417,6 +428,7 @@ function renderInlineEditRow(
417
428
  rawPath: opts.rawPath,
418
429
  rename: opts.rename,
419
430
  linkPath: opts.linkPath,
431
+ renameLinkPath: opts.renameLinkPath,
420
432
  }),
421
433
  0,
422
434
  0,
@@ -1248,8 +1260,18 @@ export const editToolRenderer = {
1248
1260
  let added = 0;
1249
1261
  let removed = 0;
1250
1262
  // Files are borderless sections inside the one tool frame.
1251
- const body: NativeChild[] = perFileResults.map(fileResult => {
1252
- const file = editFileParts({ content: [], details: fileResult, isError: fileResult.isError }, options);
1263
+ const body: NativeChild[] = perFileResults.map((fileResult, index) => {
1264
+ const rawDetails = options.renderContext?.rawDetails;
1265
+ const rawPerFile =
1266
+ rawDetails && typeof rawDetails === "object" && "perFileResults" in rawDetails
1267
+ ? rawDetails.perFileResults
1268
+ : undefined;
1269
+ const file = editFileParts(
1270
+ { content: [], details: fileResult, isError: fileResult.isError },
1271
+ options,
1272
+ undefined,
1273
+ Array.isArray(rawPerFile) ? rawPerFile[index] : undefined,
1274
+ );
1253
1275
  added += file.added;
1254
1276
  removed += file.removed;
1255
1277
  return fileDiffSection(file, file.body, {
@@ -1322,13 +1344,13 @@ function editToolHead(facts: EditHeadFacts): NativeToolHead {
1322
1344
  const multi = (facts.files ?? 0) > 1;
1323
1345
  const meta = compact([
1324
1346
  diffStatsMeta(facts.added, facts.removed),
1325
- !multi && facts.rename ? `→ ${displayPath(facts.rename)}` : undefined,
1347
+ !multi && facts.rename ? `→ ${displayPath(sanitizeText(facts.rename))}` : undefined,
1326
1348
  ]);
1327
1349
  const badge = facts.diagnostics && diagnosticsBadge(facts.diagnostics);
1328
1350
  const target = multi
1329
1351
  ? `${facts.files} files`
1330
1352
  : facts.path
1331
- ? `${displayPath(facts.path)}${facts.line ? `:${facts.line}` : ""}`
1353
+ ? `${displayPath(sanitizeText(facts.path))}${facts.line ? `:${facts.line}` : ""}`
1332
1354
  : undefined;
1333
1355
  return {
1334
1356
  title: multi ? "Edit" : getOperationTitle(facts.op),
@@ -1355,6 +1377,15 @@ interface EditFileParts extends Omit<EditHeadFacts, "diagnostics"> {
1355
1377
  body: NativeChild[];
1356
1378
  }
1357
1379
 
1380
+ /** Raw metadata paths are reserved for link targets; visible content comes from sanitized details. */
1381
+ function rawEditPaths(value: unknown): { path?: string; sourcePath?: string } {
1382
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return {};
1383
+ return {
1384
+ path: "path" in value && typeof value.path === "string" ? value.path : undefined,
1385
+ sourcePath: "sourcePath" in value && typeof value.sourcePath === "string" ? value.sourcePath : undefined,
1386
+ };
1387
+ }
1388
+
1358
1389
  function editFileParts(
1359
1390
  result: {
1360
1391
  content: Array<{ type: string; text?: string }>;
@@ -1363,8 +1394,10 @@ function editFileParts(
1363
1394
  },
1364
1395
  options: RenderResultOptions & { renderContext?: EditRenderContext },
1365
1396
  args?: EditRenderArgs,
1397
+ rawFileDetails?: unknown,
1366
1398
  ): EditFileParts {
1367
1399
  const details = result.details;
1400
+ const rawPaths = rawEditPaths(rawFileDetails ?? options.renderContext?.rawDetails);
1368
1401
  const isError = result.isError ?? (details && "isError" in details ? details.isError : false) ?? false;
1369
1402
  const firstEdit = Array.isArray(args?.edits) ? args.edits[0] : undefined;
1370
1403
  const firstHashlineInputEntry = getHashlineInputRenderSummary(args ?? {}, options.renderContext?.editMode)
@@ -1391,7 +1424,7 @@ function editFileParts(
1391
1424
  const firstChangedLine =
1392
1425
  (editDiffPreview && "firstChangedLine" in editDiffPreview ? editDiffPreview.firstChangedLine : undefined) ||
1393
1426
  (details && !isError ? details.firstChangedLine : undefined);
1394
- const shownPath = displayPath(detailPath ?? rawPath);
1427
+ const shownPath = displayPath(sanitizeText(detailPath ?? rawPath));
1395
1428
  const body: NativeChild[] = [];
1396
1429
  if (isError) {
1397
1430
  const displayErrorText = details && "displayErrorText" in details ? details.displayErrorText : undefined;
@@ -1410,10 +1443,10 @@ function editFileParts(
1410
1443
  const stats = diffText ? getDiffStats(diffText) : undefined;
1411
1444
  return {
1412
1445
  op,
1413
- path: rawPath,
1446
+ path: sanitizeText(rawPath),
1414
1447
  line: firstChangedLine,
1415
- rename,
1416
- resolvedPath: detailPath,
1448
+ rename: rename === undefined ? undefined : sanitizeText(rename),
1449
+ resolvedPath: rawPaths.path ?? detailPath,
1417
1450
  added: stats?.added ?? 0,
1418
1451
  removed: stats?.removed ?? 0,
1419
1452
  isError: Boolean(isError),
@@ -1433,6 +1466,7 @@ function renderSingleFileResult(
1433
1466
  args?: EditRenderArgs,
1434
1467
  ): Component {
1435
1468
  const details = result.details;
1469
+ const rawPaths = rawEditPaths(options.renderContext?.rawDetails);
1436
1470
  const isError = result.isError ?? (details && "isError" in details ? details.isError : false);
1437
1471
  const edits = Array.isArray(args?.edits) ? args.edits : undefined;
1438
1472
  const firstEdit = edits?.[0];
@@ -1467,8 +1501,17 @@ function renderSingleFileResult(
1467
1501
  // container. Errors, no-ops, creates, move-with-edits, and anything with
1468
1502
  // diagnostics keep the framed block below.
1469
1503
  if (!isError && !details?.diff && !details?.diagnostics && (op === "delete" || rename)) {
1470
- const linkPath = details && "path" in details ? details.path : undefined;
1471
- return renderInlineEditRow(uiTheme, { op, rename, rawPath, linkPath, pending: false });
1504
+ const linkPath = rename
1505
+ ? (rawPaths.sourcePath ?? moveSource ?? rawPaths.path ?? detailPath)
1506
+ : (rawPaths.path ?? detailPath);
1507
+ return renderInlineEditRow(uiTheme, {
1508
+ op,
1509
+ rename,
1510
+ rawPath,
1511
+ linkPath,
1512
+ renameLinkPath: rename ? (rawPaths.path ?? detailPath) : undefined,
1513
+ pending: false,
1514
+ });
1472
1515
  }
1473
1516
 
1474
1517
  const renderFallbackDiff = (diffText: string, diffOptions?: { filePath?: string }): string =>
@@ -1499,7 +1542,9 @@ function renderSingleFileResult(
1499
1542
  const firstChangedLine =
1500
1543
  (editDiffPreview && "firstChangedLine" in editDiffPreview ? editDiffPreview.firstChangedLine : undefined) ||
1501
1544
  (details && !isError ? details.firstChangedLine : undefined);
1502
- const linkPath = details && "path" in details ? details.path : undefined;
1545
+ const linkPath = rename
1546
+ ? (rawPaths.sourcePath ?? moveSource ?? rawPaths.path ?? detailPath)
1547
+ : (rawPaths.path ?? detailPath);
1503
1548
 
1504
1549
  // Change stats ride inline on the header bar next to the path.
1505
1550
  const previewDiff = editDiffPreview && !("error" in editDiffPreview) ? editDiffPreview.diff : undefined;
@@ -1517,6 +1562,7 @@ function renderSingleFileResult(
1517
1562
  rename,
1518
1563
  firstChangedLine,
1519
1564
  linkPath,
1565
+ renameLinkPath: rename ? (rawPaths.path ?? detailPath) : undefined,
1520
1566
  statsSuffix,
1521
1567
  });
1522
1568
  const innerWidth = Math.max(1, width - 2);
@@ -1541,7 +1587,11 @@ function renderSingleFileResult(
1541
1587
  // (Delete / `src → dst`); only a true no-op needs an explanatory
1542
1588
  // body so an empty card isn't mistaken for a stalled edit.
1543
1589
  if (op !== "delete" && op !== "create" && !rename) {
1544
- const noChangePath = linkPath ? shortenPath(linkPath) : rawPath ? shortenPath(rawPath) : "";
1590
+ const noChangePath = detailPath
1591
+ ? shortenPath(detailPath)
1592
+ : rawPath
1593
+ ? shortenPath(sanitizeText(rawPath))
1594
+ : "";
1545
1595
  body = uiTheme.fg("dim", `No changes were made${noChangePath ? ` to ${noChangePath}` : ""}.`);
1546
1596
  }
1547
1597
  } else if (editDiffPreview) {
@@ -1593,8 +1643,19 @@ function renderMultiFileResult(
1593
1643
  options: RenderResultOptions & { renderContext?: EditRenderContext },
1594
1644
  uiTheme: Theme,
1595
1645
  ): Component {
1596
- const fileComponents = perFileResults.map(fileResult =>
1597
- renderSingleFileResult({ content: [], details: fileResult, isError: fileResult.isError }, options, uiTheme),
1646
+ const rawDetails = options.renderContext?.rawDetails;
1647
+ const rawPerFile =
1648
+ rawDetails && typeof rawDetails === "object" && "perFileResults" in rawDetails
1649
+ ? rawDetails.perFileResults
1650
+ : undefined;
1651
+ const fileComponents = perFileResults.map((fileResult, index) =>
1652
+ renderSingleFileResult(
1653
+ { content: [], details: fileResult, isError: fileResult.isError },
1654
+ Array.isArray(rawPerFile)
1655
+ ? { ...options, renderContext: { ...options.renderContext, rawDetails: rawPerFile[index] } }
1656
+ : options,
1657
+ uiTheme,
1658
+ ),
1598
1659
  );
1599
1660
  const remaining = Math.max(0, totalFiles - perFileResults.length);
1600
1661
 
package/src/tools/find.ts CHANGED
@@ -27,7 +27,13 @@ import {
27
27
  import type { Theme, ThemeColor } from "../theme/theme";
28
28
  import type { Component } from "../tui";
29
29
  import type { OutputMeta } from "./output-meta";
30
- import type { NativeToolHead, NativeToolView, RenderResultOptions, ToolRenderer } from "./renderer";
30
+ import type {
31
+ NativeToolHead,
32
+ NativeToolView,
33
+ RenderResultContextOptions,
34
+ RenderResultOptions,
35
+ ToolRenderer,
36
+ } from "./renderer";
31
37
  import type { TspTone } from "@oh-my-pi/pi-wire";
32
38
  import { code, col, compact, keyed, node, span, text } from "../native/describe";
33
39
  import type { NativeChild, NativeNode } from "../native/node";
@@ -57,12 +63,22 @@ export interface FindHit {
57
63
  truncated: boolean;
58
64
  }
59
65
 
66
+ /**
67
+ * How much of a search the judge actually covered. `unavailable`: every judge
68
+ * request failed, so an empty result is not evidence of absence. `partial`:
69
+ * some requests failed. `complete`: none failed (or none were needed).
70
+ */
71
+ export type FindCoverage = "complete" | "partial" | "unavailable";
72
+
60
73
  /** Search accounting reported alongside the hits. */
61
74
  export interface FindStats {
62
75
  /** Eligible files under the root. */
63
76
  listed: number;
64
77
  requests: number;
65
- errors: number;
78
+ /** Judge requests that failed outright; decides {@link FindCoverage}. */
79
+ failed: number;
80
+ /** Questions a successful response left without a usable answer. */
81
+ unanswered: number;
66
82
  /** Entries judged by name. */
67
83
  judged: number;
68
84
  /** Files whose content was read and sent. */
@@ -87,6 +103,7 @@ export interface FindToolDetails {
87
103
  /** Verified-passage probability at or above which a file is a hit. */
88
104
  threshold: number;
89
105
  hits: FindHit[];
106
+ coverage: FindCoverage;
90
107
  stats: FindStats;
91
108
  elapsedMs: number;
92
109
  /** Session cwd; hit paths are relative to it. */
@@ -129,13 +146,32 @@ function gauge(p: number, theme: Theme): string {
129
146
  });
130
147
  }
131
148
 
132
- function renderHit(hit: FindHit, rangeLimit: number, cwd: string | undefined, theme: Theme): string[] {
149
+ /** Raw metadata is used only for file link targets, never for displayed text. */
150
+ function findLinkTargets(details: FindToolDetails, rawDetails: unknown) {
151
+ const raw = rawDetails !== null && typeof rawDetails === "object" ? rawDetails : undefined;
152
+ const cwd = raw && "cwd" in raw && typeof raw.cwd === "string" ? raw.cwd : details.cwd;
153
+ const rawHits: unknown[] = raw && "hits" in raw && Array.isArray(raw.hits) ? raw.hits : [];
154
+ return {
155
+ cwd,
156
+ rel(hit: FindHit, index: number): string {
157
+ const candidate = rawHits[index];
158
+ return candidate !== null &&
159
+ typeof candidate === "object" &&
160
+ "rel" in candidate &&
161
+ typeof candidate.rel === "string"
162
+ ? candidate.rel
163
+ : hit.rel;
164
+ },
165
+ };
166
+ }
167
+
168
+ function renderHit(hit: FindHit, rangeLimit: number, cwd: string | undefined, rawRel: string, theme: Theme): string[] {
133
169
  // `scheme://` hits (e.g. virtual docs) are not files under `cwd`: link the
134
170
  // URL itself instead of joining it onto a filesystem base.
135
171
  const isUrlHit = splitUrlScheme(hit.rel) !== undefined;
136
172
  const link = (text: string, line?: number): string => {
137
173
  if (isUrlHit) return uriHyperlink(line === undefined ? hit.rel : `${hit.rel}:${line}`, text);
138
- const absPath = cwd === undefined ? undefined : path.join(cwd, hit.rel);
174
+ const absPath = cwd === undefined ? undefined : path.join(cwd, rawRel);
139
175
  return absPath === undefined ? text : fileHyperlink(absPath, text, { line });
140
176
  };
141
177
  const coverage = hit.truncated ? `${hit.linesSeen} lines judged, partial` : `${hit.linesSeen} lines judged`;
@@ -161,7 +197,7 @@ function scoreTone(p: number): TspTone {
161
197
  * One hit (§7.3 find): a 22px row of the score bar, the path and `12 lines
162
198
  * judged`, then its strongest ranges as numbered `code` (no path header).
163
199
  */
164
- function describeHit(hit: FindHit, rangeLimit: number, cwd: string | undefined): NativeNode {
200
+ function describeHit(hit: FindHit, rangeLimit: number, cwd: string | undefined, rawRel: string): NativeNode {
165
201
  const ranges = [...hit.ranges].sort((a, b) => b.p - a.p || a.start - b.start).slice(0, rangeLimit);
166
202
  const tone = scoreTone(hit.contentScore);
167
203
  const score = hit.contentScore.toFixed(2);
@@ -175,7 +211,7 @@ function describeHit(hit: FindHit, rangeLimit: number, cwd: string | undefined):
175
211
  "muted",
176
212
  ),
177
213
  ],
178
- href: isUrlHit || cwd === undefined ? undefined : fileHref(path.join(cwd, hit.rel)),
214
+ href: isUrlHit || cwd === undefined ? undefined : fileHref(path.join(cwd, rawRel)),
179
215
  key: "hit",
180
216
  });
181
217
  const lang = getLanguageFromPath(hit.rel);
@@ -222,7 +258,7 @@ export const findToolRenderer = {
222
258
 
223
259
  renderResult(
224
260
  result: { content: Array<{ type: string; text?: string }>; details?: FindToolDetails; isError?: boolean },
225
- options: RenderResultOptions,
261
+ options: RenderResultContextOptions,
226
262
  uiTheme: Theme,
227
263
  args?: FindRenderArgs,
228
264
  ): Component {
@@ -250,6 +286,7 @@ export const findToolRenderer = {
250
286
  }
251
287
 
252
288
  const { hits, stats, threshold } = details;
289
+ const linkTargets = findLinkTargets(details, options.renderContext?.rawDetails);
253
290
  const description = quoteQuery(details.query);
254
291
  const scope = details.scopePath === undefined ? [] : [`in ${details.scopePath}`];
255
292
  const meta = [
@@ -261,16 +298,21 @@ export const findToolRenderer = {
261
298
  `$${stats.cost.toFixed(4)}`,
262
299
  formatDuration(details.elapsedMs),
263
300
  ];
264
- if (stats.errors > 0) meta.push(uiTheme.fg("warning", `${stats.errors} failed`));
301
+ const failed = stats.failed > 0 ? `${stats.failed}/${stats.requests} requests failed` : undefined;
302
+ if (failed) meta.push(uiTheme.fg("warning", failed));
265
303
 
266
304
  if (hits.length === 0) {
267
305
  const emptyMeta = ["0 hits", ...scope, `$${stats.cost.toFixed(4)}`, formatDuration(details.elapsedMs)];
268
- if (stats.errors > 0) emptyMeta.push(uiTheme.fg("warning", `${stats.errors} failed`));
306
+ if (failed) emptyMeta.push(uiTheme.fg("warning", failed));
269
307
  const header = renderStatusLine(
270
308
  { icon: "warning", title: "Find", titleColor: "toolTitle", description, meta: emptyMeta },
271
309
  uiTheme,
272
310
  );
273
- const lines = [header, formatEmptyMessage("No relevant passages found", uiTheme)];
311
+ const empty =
312
+ details.coverage === "partial"
313
+ ? "No relevant passages found in the judged files"
314
+ : "No relevant passages found";
315
+ const lines = [header, formatEmptyMessage(empty, uiTheme)];
274
316
  for (const failure of stats.failures) lines.push(uiTheme.fg("warning", failure));
275
317
  return new Text(lines.join("\n"), 1, 0);
276
318
  }
@@ -296,8 +338,14 @@ export const findToolRenderer = {
296
338
  maxCollapsed: COLLAPSED_HITS,
297
339
  maxCollapsedLines: PREVIEW_LIMITS.EXPANDED_LINES,
298
340
  itemType: "hit",
299
- renderItem: hit =>
300
- renderHit(hit, expanded ? RANGES_EXPANDED : RANGES_COLLAPSED, details.cwd, uiTheme),
341
+ renderItem: (hit, context) =>
342
+ renderHit(
343
+ hit,
344
+ expanded ? RANGES_EXPANDED : RANGES_COLLAPSED,
345
+ linkTargets.cwd,
346
+ linkTargets.rel(hit, context.index),
347
+ uiTheme,
348
+ ),
301
349
  },
302
350
  uiTheme,
303
351
  );
@@ -329,7 +377,7 @@ export const findToolRenderer = {
329
377
  */
330
378
  describeResult(
331
379
  result: { content: Array<{ type: string; text?: string }>; details?: FindToolDetails; isError?: boolean },
332
- options: RenderResultOptions,
380
+ options: RenderResultContextOptions,
333
381
  args?: FindRenderArgs,
334
382
  ): NativeToolView {
335
383
  const details = result.details;
@@ -343,8 +391,10 @@ export const findToolRenderer = {
343
391
  };
344
392
  }
345
393
  const { hits, stats, threshold } = details;
394
+ const linkTargets = findLinkTargets(details, options.renderContext?.rawDetails);
346
395
  const scope = details.scopePath === undefined ? undefined : `in ${details.scopePath}`;
347
- const failed = stats.errors > 0 ? [span(`${stats.errors} failed`, "warning")] : undefined;
396
+ const failed =
397
+ stats.failed > 0 ? [span(`${stats.failed}/${stats.requests} requests failed`, "warning")] : undefined;
348
398
  const accounting = [
349
399
  `${stats.filesRead} files read`,
350
400
  `τ ${threshold.toFixed(2)}`,
@@ -382,7 +432,7 @@ export const findToolRenderer = {
382
432
  ),
383
433
  inline: true,
384
434
  body: compact<NativeChild>([
385
- ...shown.map(hit => describeHit(hit, rangeLimit, details.cwd)),
435
+ ...shown.map((hit, index) => describeHit(hit, rangeLimit, linkTargets.cwd, linkTargets.rel(hit, index))),
386
436
  ...failures,
387
437
  foot,
388
438
  ]),
package/src/tools/glob.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import type { Component } from "../tui";
2
2
  import { Text } from "../components/text";
3
- import type { NativeToolHead, NativeToolView, RenderResultOptions, ToolRenderer } from "./renderer";
3
+ import type {
4
+ NativeToolHead,
5
+ NativeToolView,
6
+ RenderResultContextOptions,
7
+ RenderResultOptions,
8
+ ToolRenderer,
9
+ } from "./renderer";
4
10
  import { col, compact, keyed, node, row, span, text } from "../native/describe";
5
11
  import type { NativeChild, NativeNode } from "../native/node";
6
12
  import { fileHref, fileRow, footnoteText, inlineErrorView, resultText } from "./native-view";
@@ -68,13 +74,33 @@ const NATIVE_LIST_MAX = 6;
68
74
  /** Collapsed clamp: the whole ≤ 6-row list, or about six rows of chips. */
69
75
  const NATIVE_PREVIEW_LINES = 8;
70
76
 
71
- /**
72
- * Native glob files: 22px path rows when there are few, else a wrap of
73
- * chips (glyph and name, the full path in the tooltip). Paths link when the
74
- * search `cwd` is known.
75
- */
76
- function describeGlobFiles(files: readonly string[], cwd: string | undefined): NativeNode {
77
- const links = files.map(file => (cwd && !file.endsWith("/") ? fileHref(path.resolve(cwd, file)) : undefined));
77
+ /** Use original filesystem paths for existing links, never for displayed labels or extra links. */
78
+ function globLinkPaths(
79
+ details: GlobToolDetails | undefined,
80
+ rawDetails: unknown,
81
+ ): { cwd: string | undefined; files: readonly unknown[] } {
82
+ const raw = rawDetails && typeof rawDetails === "object" ? rawDetails : undefined;
83
+ const rawCwd = raw && "cwd" in raw && typeof raw.cwd === "string" ? raw.cwd : undefined;
84
+ const rawFiles = raw && "files" in raw && Array.isArray(raw.files) ? raw.files : undefined;
85
+ const files = details?.files ?? [];
86
+ return {
87
+ cwd: details?.cwd ? (rawCwd ?? details.cwd) : undefined,
88
+ files: rawFiles?.length === files.length ? rawFiles : files,
89
+ };
90
+ }
91
+
92
+ /** Native glob files: path rows when few, otherwise wrapped chips; links require a known cwd. */
93
+ function describeGlobFiles(
94
+ files: readonly string[],
95
+ cwd: string | undefined,
96
+ rawFiles: readonly unknown[] = files,
97
+ ): NativeNode {
98
+ const links = files.map((file, i) => {
99
+ const rawFile = rawFiles[i];
100
+ return cwd && !file.endsWith("/")
101
+ ? fileHref(path.resolve(cwd, typeof rawFile === "string" ? rawFile : file))
102
+ : undefined;
103
+ });
78
104
  if (files.length <= NATIVE_LIST_MAX) {
79
105
  return col(
80
106
  files.map((file, i) => fileRow(file, { href: links[i] })),
@@ -130,11 +156,12 @@ export const globToolRenderer = {
130
156
 
131
157
  renderResult(
132
158
  result: { content: Array<{ type: string; text?: string }>; details?: GlobToolDetails; isError?: boolean },
133
- options: RenderResultOptions,
159
+ options: RenderResultContextOptions,
134
160
  uiTheme: Theme,
135
161
  args?: GlobRenderArgs,
136
162
  ): Component {
137
163
  const details = result.details;
164
+ const linkPaths = globLinkPaths(details, options.renderContext?.rawDetails);
138
165
 
139
166
  if (result.isError || details?.error) {
140
167
  const errorText = details?.error || result.content?.find(c => c.type === "text")?.text || "Unknown error";
@@ -249,14 +276,20 @@ export const globToolRenderer = {
249
276
  return createCachedComponent(
250
277
  () => options.expanded,
251
278
  width => {
252
- const cwd = details?.cwd;
279
+ const cwd = linkPaths.cwd;
253
280
  const fileLines = renderFileList(
254
281
  {
255
- files: files.map(entry => ({
256
- path: entry,
257
- isDirectory: entry.endsWith("/"),
258
- absPath: cwd && !entry.endsWith("/") ? path.resolve(cwd, entry) : undefined,
259
- })),
282
+ files: files.map((entry, index) => {
283
+ const rawFile = linkPaths.files[index];
284
+ return {
285
+ path: entry,
286
+ isDirectory: entry.endsWith("/"),
287
+ absPath:
288
+ cwd && !entry.endsWith("/")
289
+ ? path.resolve(cwd, typeof rawFile === "string" ? rawFile : entry)
290
+ : undefined,
291
+ };
292
+ }),
260
293
  expanded: options.expanded,
261
294
  maxCollapsed: PREVIEW_LIMITS.COLLAPSED_ITEMS,
262
295
  hyperlinkFn: fileHyperlink,
@@ -278,10 +311,11 @@ export const globToolRenderer = {
278
311
  */
279
312
  describeResult(
280
313
  result: { content: Array<{ type: string; text?: string }>; details?: GlobToolDetails; isError?: boolean },
281
- _options: RenderResultOptions,
314
+ options: RenderResultContextOptions,
282
315
  args?: GlobRenderArgs,
283
316
  ): NativeToolView {
284
317
  const details = result.details;
318
+ const linkPaths = globLinkPaths(details, options.renderContext?.rawDetails);
285
319
  if (result.isError || details?.error) {
286
320
  return inlineErrorView(globNativeHead(args), details?.error || resultText(result) || "Unknown error");
287
321
  }
@@ -335,7 +369,7 @@ export const globToolRenderer = {
335
369
  : head,
336
370
  inline: true,
337
371
  body: compact<NativeChild>([
338
- describeGlobFiles(details.files ?? [], details.cwd),
372
+ describeGlobFiles(details.files ?? [], linkPaths.cwd, linkPaths.files),
339
373
  footnoteText(compact([reasons.length > 0 && `truncated: ${reasons.join(", ")}`, missingNote])),
340
374
  ]),
341
375
  preview: { lines: NATIVE_PREVIEW_LINES },