@oh-my-pi/pi-tui 18.14.1 → 18.14.2

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 (46) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/types/charts/table-data.d.ts +4 -2
  3. package/dist/types/chat/transcript-render-helpers.d.ts +3 -3
  4. package/dist/types/native/describe.d.ts +4 -2
  5. package/dist/types/native/overlay.d.ts +42 -2
  6. package/dist/types/native/state.d.ts +4 -0
  7. package/dist/types/prompt/composer.d.ts +13 -5
  8. package/dist/types/render/render-utils.d.ts +2 -0
  9. package/dist/types/theme/theme.d.ts +1 -1
  10. package/dist/types/theme/tui-adapters.d.ts +2 -0
  11. package/dist/types/thinking.d.ts +8 -6
  12. package/dist/types/tools/ast-grep.d.ts +2 -0
  13. package/dist/types/tools/eval.d.ts +2 -0
  14. package/dist/types/tools/find.d.ts +1 -1
  15. package/dist/types/tools/grouped-file-output.d.ts +24 -11
  16. package/dist/types/tools/read.d.ts +4 -4
  17. package/dist/types/tools/task.d.ts +2 -2
  18. package/package.json +9 -9
  19. package/src/apps/git/git-tui.ts +10 -17
  20. package/src/apps/git/sidebar.ts +21 -35
  21. package/src/apps/ps-top.ts +4 -12
  22. package/src/charts/chart-plan.ts +0 -29
  23. package/src/charts/table-data.ts +55 -6
  24. package/src/chat/transcript-render-helpers.ts +18 -16
  25. package/src/native/backend.ts +7 -3
  26. package/src/native/describe.ts +9 -4
  27. package/src/native/overlay.ts +124 -16
  28. package/src/native/state.ts +25 -5
  29. package/src/overlays/extensions/extension-dashboard.ts +7 -8
  30. package/src/overlays/login-dialog.ts +8 -26
  31. package/src/overlays/tree-selector.ts +64 -18
  32. package/src/overlays/usage-dashboard.ts +2 -4
  33. package/src/prompt/composer.ts +17 -5
  34. package/src/render/render-utils.ts +2 -0
  35. package/src/theme/theme-class.ts +12 -3
  36. package/src/theme/theme.ts +1 -0
  37. package/src/theme/tui-adapters.ts +8 -3
  38. package/src/thinking.ts +17 -11
  39. package/src/tools/ast-grep.ts +10 -2
  40. package/src/tools/eval.ts +2 -0
  41. package/src/tools/find.ts +7 -2
  42. package/src/tools/grep.ts +8 -2
  43. package/src/tools/grouped-file-output.ts +172 -47
  44. package/src/tools/lsp.ts +158 -8
  45. package/src/tools/read.ts +6 -5
  46. package/src/tools/task.ts +2 -2
@@ -2,8 +2,11 @@ import * as path from "node:path";
2
2
 
3
3
  import { buildPathTree, isUrlLikePath, type PathTreeInput, walkPathTree } from "@oh-my-pi/pi-utils";
4
4
  import type { TspTone } from "@oh-my-pi/pi-wire";
5
- import { code, col, keyed, span, text } from "../native/describe";
5
+ import { code, col, keyed } from "../native/describe";
6
6
  import type { NativeNode } from "../native/node";
7
+ import { getLanguageFromPath } from "../lang-from-path";
8
+ import { replaceTabs } from "../render/render-utils";
9
+ import { highlightCode, isHighlightLanguage, type Theme, type ThemeColor } from "../theme/theme";
7
10
  import { formatHashlineHeader } from "./hashline-format";
8
11
  import { fileRow } from "./native-view";
9
12
 
@@ -266,6 +269,135 @@ export function groupLineIndicesByBlank(rawLines: readonly string[]): number[][]
266
269
  return groups;
267
270
  }
268
271
 
272
+ // =============================================================================
273
+ // Code frames highlighted in their file's language (TUI renderers)
274
+ // =============================================================================
275
+
276
+ /** A code-frame row split after its rule: the gutter (match marker, line number, rule) and the source line. */
277
+ interface CodeFrameRow {
278
+ gutter: string;
279
+ source: string;
280
+ }
281
+
282
+ /**
283
+ * Draw the code-frame rows of consecutive source lines: each gutter in
284
+ * `color`, the sources highlighted in `lang` as one run, so a multi-line
285
+ * string or comment keeps its colors. Without a language the sources take
286
+ * `color` too.
287
+ */
288
+ function renderCodeFrameRun(
289
+ rows: readonly CodeFrameRow[],
290
+ lang: string | undefined,
291
+ color: ThemeColor,
292
+ theme: Theme,
293
+ ): string[] {
294
+ const sources = rows.map(row => replaceTabs(row.source));
295
+ const highlighted = isHighlightLanguage(lang) ? highlightCode(sources.join("\n"), lang, theme) : undefined;
296
+ return rows.map((row, index) => {
297
+ const source = highlighted?.[index] ?? theme.fg(color, sources[index]!);
298
+ return `${theme.fg(color, row.gutter)}${source}`;
299
+ });
300
+ }
301
+
302
+ /** A numbered code-frame row of search output, with its line number. */
303
+ interface NumberedCodeFrame {
304
+ row: CodeFrameRow;
305
+ n: number;
306
+ }
307
+
308
+ function parseNumberedCodeFrame(line: string): NumberedCodeFrame | undefined {
309
+ const match = GROUPED_NUMBERED_LINE_RE.exec(line);
310
+ if (!match) return undefined;
311
+ const source = match[3]!;
312
+ return { row: { gutter: line.slice(0, line.length - source.length), source }, n: Number(match[2]) };
313
+ }
314
+
315
+ /** The file a grouped file header names, without its suffix and hashline tag: `## a.ts#3f2a (2)` → `a.ts`. */
316
+ function groupedHeaderName(line: string): string {
317
+ const rest = GROUPED_HEADER_RE.exec(line)?.[2]?.trimEnd() ?? "";
318
+ return rest.replace(HEADER_SUFFIX_RE, "").replace(HEADER_HASH_TAG_RE, "");
319
+ }
320
+
321
+ /**
322
+ * Source rows highlighted together. A run longer than this (a huge AST match) highlights chunk by chunk as rows
323
+ * are requested, so a collapsed view never tokenizes source it hides; a string or comment spanning a chunk
324
+ * boundary loses its continuation there.
325
+ */
326
+ const CODE_FRAME_CHUNK_ROWS = 64;
327
+
328
+ /**
329
+ * Styled code-frame rows of grouped search output, highlighted in each owning
330
+ * file's language (`lang` overrides it when the highlighter knows it). A run of
331
+ * consecutive line numbers in one file highlights together on its first
332
+ * request; a gap row, a jump in line numbers or another file starts a new run.
333
+ * Rows without a numbered code frame (headers, gap rows, notes) return
334
+ * undefined, for the caller to style.
335
+ */
336
+ export function createCodeFrameStyler(
337
+ lines: readonly string[],
338
+ contexts: readonly GroupedLineContext[],
339
+ color: ThemeColor,
340
+ theme: Theme,
341
+ lang?: string,
342
+ ): (index: number) => string | undefined {
343
+ // Each body row's language: the override, else its owning file's, from the resolved path or its header's name.
344
+ const langOverride = isHighlightLanguage(lang) ? lang : undefined;
345
+ const langs: (string | undefined)[] = [];
346
+ let headerLang: string | undefined;
347
+ for (let index = 0; index < lines.length; index++) {
348
+ const ctx = contexts[index]!;
349
+ if (ctx.kind === "content") {
350
+ langs.push(langOverride ?? (ctx.filePath ? getLanguageFromPath(ctx.filePath) : headerLang));
351
+ continue;
352
+ }
353
+ headerLang = ctx.kind === "file" ? getLanguageFromPath(groupedHeaderName(lines[index]!)) : undefined;
354
+ langs.push(undefined);
355
+ }
356
+
357
+ const frames: (NumberedCodeFrame | null)[] = [];
358
+ const frameAt = (index: number): NumberedCodeFrame | null => {
359
+ let frame = frames[index];
360
+ if (frame === undefined) {
361
+ frame = contexts[index]!.kind === "content" ? (parseNumberedCodeFrame(lines[index]!) ?? null) : null;
362
+ frames[index] = frame;
363
+ }
364
+ return frame;
365
+ };
366
+ // Whether the row at `index` continues the run of the row above it.
367
+ const continuesRun = (index: number): boolean => {
368
+ if (index <= 0 || langs[index] !== langs[index - 1]) return false;
369
+ const frame = frameAt(index);
370
+ const above = frameAt(index - 1);
371
+ return frame !== null && above !== null && frame.n === above.n + 1;
372
+ };
373
+ // First row of each row's run, memoized so walking back through a long run happens once.
374
+ const runStarts: number[] = [];
375
+ const runStartOf = (index: number): number => {
376
+ let row = index;
377
+ while (runStarts[row] === undefined && continuesRun(row)) row--;
378
+ const start = runStarts[row] ?? row;
379
+ for (let filled = row; filled <= index; filled++) runStarts[filled] = start;
380
+ return start;
381
+ };
382
+
383
+ const styled: string[] = [];
384
+ return index => {
385
+ if (frameAt(index) === null) return undefined;
386
+ const cached = styled[index];
387
+ if (cached !== undefined) return cached;
388
+ const runStart = runStartOf(index);
389
+ const start = runStart + Math.floor((index - runStart) / CODE_FRAME_CHUNK_ROWS) * CODE_FRAME_CHUNK_ROWS;
390
+ let end = index + 1;
391
+ while (end < start + CODE_FRAME_CHUNK_ROWS && end < lines.length && continuesRun(end)) end++;
392
+ const chunkRows: CodeFrameRow[] = [];
393
+ for (let row = start; row < end; row++) chunkRows.push(frameAt(row)!.row);
394
+ renderCodeFrameRun(chunkRows, langs[index], color, theme).forEach((row, offset) => {
395
+ styled[start + offset] = row;
396
+ });
397
+ return styled[index];
398
+ };
399
+ }
400
+
269
401
  // =============================================================================
270
402
  // Native (TSP) description of grouped output
271
403
  // =============================================================================
@@ -306,10 +438,10 @@ export function* walkGroupedOutput(lines: readonly string[]): Generator<GroupedO
306
438
 
307
439
  /** `*12│text`, ` 12|text`, `*12:text`: optional match marker, line number, gutter, content. */
308
440
  const GROUPED_NUMBERED_LINE_RE = /^\s*(\*?)(\d+)(?:│|[:|])(.*)$/;
309
- /** ` │...`: grep's gap between non-adjacent context runs (drawn as {@link numberedCode}'s `…` row). */
441
+ /** ` │...`: grep's gap between non-adjacent context runs (Tern draws it from the jump in {@link numberedCode}'s numbers). */
310
442
  const GROUPED_GAP_LINE_RE = /^\s*│\.\.\.$/;
311
443
 
312
- /** One source line for {@link numberedCode}: its number (`null` for an elision marker), text and match mark. */
444
+ /** One source line for {@link numberedCode}: its number (`null` for an elision marker, which adds no line), text and match mark. */
313
445
  export interface NumberedLine {
314
446
  n: number | null;
315
447
  text: string;
@@ -317,58 +449,52 @@ export interface NumberedLine {
317
449
  }
318
450
 
319
451
  /**
320
- * Numbered `code` for possibly non-contiguous source lines: one block per run
321
- * of consecutive line numbers (`start` = the run's first line, match lines
322
- * `mark`ed), with a `…` row wherever the numbers jump or an elision marker
323
- * (`n: null`) sits. `path` is the file the lines come from: Tern picks their
324
- * grammar from it and draws no header (the row or head above names the file).
325
- * `wrap` soft-wraps long lines instead of scrolling the block sideways.
452
+ * One numbered `code` block for possibly non-contiguous source lines (match
453
+ * lines `mark`ed by their line number): `start` when the numbers run on
454
+ * consecutively, else `nums` (each line's number), from whose jumps Tern draws
455
+ * the `…` gap rows in the gutter. Elision markers (`n: null`) add no line; the
456
+ * numbers jump around them. `path` is the file the lines come from: Tern picks
457
+ * their grammar from it and draws no header (the row or head above names the
458
+ * file). `wrap` soft-wraps long lines instead of scrolling the block sideways.
459
+ * `undefined` when no line is numbered.
326
460
  */
327
461
  export function numberedCode(
328
462
  lines: readonly NumberedLine[],
329
463
  opts: { path?: string; wrap?: boolean } = {},
330
- ): NativeNode[] {
331
- const out: NativeNode[] = [];
332
- let run: { start: number; text: string[]; marks: { line: number; tone: TspTone }[] } | undefined;
333
- const flush = () => {
334
- if (!run) return;
335
- // The quiet `…` row between two non-adjacent runs.
336
- if (out.length > 0) out.push(keyed(text([span("…", "dim")], { wrap: "none" }), `g${run.start}`));
337
- out.push(
338
- keyed(
339
- code(run.text.join("\n"), {
340
- start: run.start,
341
- numbers: true,
342
- path: opts.path,
343
- wrap: opts.wrap,
344
- marks: run.marks.length > 0 ? run.marks : undefined,
345
- }),
346
- `c${run.start}`,
347
- ),
348
- );
349
- run = undefined;
350
- };
464
+ ): NativeNode | undefined {
465
+ const nums: number[] = [];
466
+ const body: string[] = [];
467
+ const marks: { line: number; tone: TspTone }[] = [];
468
+ let contiguous = true;
351
469
  for (const line of lines) {
352
- if (line.n === null) {
353
- flush();
354
- continue;
355
- }
356
- if (run && run.start + run.text.length !== line.n) flush();
357
- run ??= { start: line.n, text: [], marks: [] };
358
- run.text.push(line.text);
359
- if (line.mark) run.marks.push({ line: line.n, tone: "accent" });
470
+ if (line.n === null) continue;
471
+ if (nums.length > 0 && line.n !== nums[nums.length - 1]! + 1) contiguous = false;
472
+ nums.push(line.n);
473
+ body.push(line.text);
474
+ if (line.mark) marks.push({ line: line.n, tone: "accent" });
360
475
  }
361
- flush();
362
- return out;
476
+ if (nums.length === 0) return undefined;
477
+ return keyed(
478
+ code(body.join("\n"), {
479
+ start: contiguous ? nums[0] : undefined,
480
+ nums: contiguous ? undefined : nums,
481
+ numbers: true,
482
+ path: opts.path,
483
+ wrap: opts.wrap,
484
+ marks: marks.length > 0 ? marks : undefined,
485
+ }),
486
+ `c${nums[0]}`,
487
+ );
363
488
  }
364
489
 
365
490
  /**
366
491
  * Describe grouped search output (grep / ast-grep / ast-edit display content)
367
492
  * by file (§7.3 grep): per file a 22px path row (dim dir, strong name, the
368
493
  * header's suffix or the match count as a chip), then its lines as
369
- * {@link numberedCode} with match lines marked and `…` between non-adjacent
370
- * runs. Unnumbered body lines stay plain `code`. `maxFiles` keeps only the
371
- * first files (the caller says how many were left out). `file` owns the lines
494
+ * one {@link numberedCode} block with match lines marked (gaps between
495
+ * non-adjacent runs drawn in its gutter). Unnumbered body lines stay plain
496
+ * `code`. `maxFiles` keeps only the first files (the caller says how many
497
+ * were left out). `file` owns the lines
372
498
  * before any header: a single-file search prints none, yet its lines get the
373
499
  * same file row as a directory search's.
374
500
  */
@@ -386,10 +512,9 @@ export function describeGroupedOutput(
386
512
 
387
513
  const flushLines = () => {
388
514
  const target = current?.children ?? loose;
389
- if (numbered.length > 0) {
390
- target.push(...numberedCode(numbered, { path: current?.path }));
391
- numbered = [];
392
- }
515
+ const block = numberedCode(numbered, { path: current?.path });
516
+ if (block) target.push(block);
517
+ numbered = [];
393
518
  if (plain.length > 0) {
394
519
  target.push(keyed(code(plain.join("\n")), `p${target.length}`));
395
520
  plain = [];
package/src/tools/lsp.ts CHANGED
@@ -12,12 +12,14 @@ import type { NativeToolHead, NativeToolView, RenderResultOptions, ToolRenderer,
12
12
  import type { Component } from "../tui";
13
13
  import { Text } from "../components/text";
14
14
  import { getLanguageFromPath } from "../lang-from-path";
15
- import { highlightCode as highlightThemeCode, type Theme } from "../theme/theme";
15
+ import { highlightCode as highlightThemeCode, isHighlightLanguage, type Theme } from "../theme/theme";
16
16
  import {
17
+ formatCodeFrameLine,
17
18
  formatCount,
18
19
  formatExpandHint,
19
20
  formatMoreItems,
20
21
  formatStatusIcon,
22
+ PREVIEW_LIMITS,
21
23
  type ParsedDiagnostic,
22
24
  parseDiagnosticMessage,
23
25
  replaceTabs,
@@ -34,8 +36,8 @@ import { ansi, code, col, compact, keyed, md, node, row, span, text } from "../n
34
36
  import type { NativeNode } from "../native/node";
35
37
  import { OwnerMemo } from "../native/memo";
36
38
  import { plainText } from "../native/spans";
37
- import { walkGroupedOutput } from "./grouped-file-output";
38
- import { diagnosticGlyph, fileHref, fileRow, inlineErrorView } from "./native-view";
39
+ import { numberedCode, walkGroupedOutput } from "./grouped-file-output";
40
+ import { diagnosticGlyph, displayPath, fileHref, fileRow, inlineErrorView } from "./native-view";
39
41
  import { activeThemeSymbol } from "../theme/active-symbols";
40
42
 
41
43
  /** Display arguments for an LSP tool request. */
@@ -188,8 +190,10 @@ export function renderResult(
188
190
  const text = content.text;
189
191
  const lines = text.split("\n");
190
192
 
191
- // Static type detection (result content doesn't change between renders)
192
- const codeBlockMatch = text.match(/```(\w*)\n([\s\S]*?)```/);
193
+ // Static type detection (result content doesn't change between renders). Locations are
194
+ // anchored at the response's first line, so they win over checks a source snippet could trip.
195
+ const locations = parseLspLocations(lines);
196
+ const codeBlockMatch = locations ? null : text.match(/```(\w*)\n([\s\S]*?)```/);
193
197
  const errorMatch = text.match(/(\d+)\s+error\(s\)/);
194
198
  const warningMatch = text.match(/(\d+)\s+warning\(s\)/);
195
199
  const refMatch = text.match(/(\d+)\s+reference\(s\)/);
@@ -217,6 +221,13 @@ export function renderResult(
217
221
  // and render it once per expanded state instead of on every spinner frame.
218
222
  const bodies: Array<LspResultBody | undefined> = [undefined, undefined];
219
223
  const renderBody = (expanded: boolean): LspResultBody => {
224
+ if (locations) {
225
+ return {
226
+ label: "Locations",
227
+ state: locations.count > 0 ? "success" : "warning",
228
+ bodyLines: renderLocations(locations, expanded, theme),
229
+ };
230
+ }
220
231
  if (codeBlockMatch) {
221
232
  return {
222
233
  label: "Hover",
@@ -273,6 +284,7 @@ export function renderResult(
273
284
 
274
285
  // Hover code hangs under its rail; expanded rows hang under their tree
275
286
  // connector or guide rails so Ctrl+O reveals full text instead of clipping.
287
+ // Collapsed source lines stop at the card's edge, one row each under their rail.
276
288
  const rail = ` ${theme.fg("mdCodeBlockBorder", theme.boxRound.vertical)} `;
277
289
  const contentLines = codeBlockMatch
278
290
  ? bodyLines.flatMap(line =>
@@ -280,7 +292,9 @@ export function renderResult(
280
292
  )
281
293
  : expanded
282
294
  ? bodyLines.flatMap(line => wrapGuidedLine(line, contentWidth, theme))
283
- : bodyLines;
295
+ : locations
296
+ ? clipCollapsedLocations(bodyLines, contentWidth, locations, theme)
297
+ : bodyLines;
284
298
  return {
285
299
  header,
286
300
  phase: isPartial ? "partial" : state,
@@ -557,6 +571,109 @@ function renderReferences(refMatch: RegExpMatchArray, lines: string[], expanded:
557
571
  return (expanded ? renderGrouped(files.length, Number.POSITIVE_INFINITY) : renderGrouped(3, 1)).split("\n");
558
572
  }
559
573
 
574
+ // =============================================================================
575
+ // Locations Rendering
576
+ // =============================================================================
577
+
578
+ /** One location of a definition-style response, with its numbered source context. */
579
+ interface LspLocation {
580
+ file: string;
581
+ line: number;
582
+ col: number;
583
+ /** Source lines around the location; the location's own line is `mark`ed. */
584
+ context: { n: number; text: string; mark: boolean }[];
585
+ }
586
+
587
+ /** A definition, type definition or implementation response. */
588
+ interface LspLocations {
589
+ /** `definition`, `type definition` or `implementation`. */
590
+ noun: string;
591
+ count: number;
592
+ locations: LspLocation[];
593
+ }
594
+
595
+ const LOCATIONS_HEADER_RE = /^Found (\d+) (definition|type definition|implementation)\(s\):$/;
596
+ /**
597
+ * ` file:line:col`, the path from column 2 on (it may itself start with whitespace). Context rows are
598
+ * ` N: source`; a row matching both is context of the current location.
599
+ */
600
+ const LOCATION_RE = /^ {2}(.+):(\d+):(\d+)$/;
601
+ const LOCATION_CONTEXT_RE = /^ {4}(\d+): ?(.*)$/;
602
+
603
+ /**
604
+ * Parse a `Found N definition(s):` response (also type definitions and
605
+ * implementations): ` file:line:col` rows, each followed by its
606
+ * ` N: source` context lines.
607
+ */
608
+ function parseLspLocations(lines: readonly string[]): LspLocations | undefined {
609
+ const header = LOCATIONS_HEADER_RE.exec(lines[0] ?? "");
610
+ if (!header) return undefined;
611
+ const locations: LspLocation[] = [];
612
+ for (const line of lines.slice(1)) {
613
+ const current = locations.at(-1);
614
+ const context = current ? LOCATION_CONTEXT_RE.exec(line) : null;
615
+ if (current && context) {
616
+ const n = Number(context[1]);
617
+ current.context.push({ n, text: context[2].trimEnd(), mark: n === current.line });
618
+ continue;
619
+ }
620
+ const location = LOCATION_RE.exec(line);
621
+ if (location) {
622
+ const [, file, lineNumber, column] = location;
623
+ locations.push({ file, line: Number(lineNumber), col: Number(column), context: [] });
624
+ }
625
+ }
626
+ return { noun: header[2], count: Number(header[1]), locations };
627
+ }
628
+
629
+ /**
630
+ * Render definitions, type definitions and implementations: each
631
+ * `file:line:col` over its source context, the location's line marked like a
632
+ * grep match.
633
+ */
634
+ function renderLocations(parsed: LspLocations, expanded: boolean, theme: Theme): string[] {
635
+ const { noun, count, locations } = parsed;
636
+ const shown = expanded ? locations : locations.slice(0, PREVIEW_LIMITS.LOCATIONS_COLLAPSED);
637
+ const hidden = locations.length - shown.length;
638
+ const icon = count > 0 ? theme.styledSymbol("tool.lsp", "accent") : theme.styledSymbol("status.warning", "warning");
639
+ const rows = [
640
+ `${icon} ${theme.fg("dim", formatCount(noun, count))}${formatExpandHint(theme, expanded, hidden > 0)}`,
641
+ ];
642
+
643
+ shown.forEach((location, index) => {
644
+ const isLast = index === shown.length - 1 && hidden === 0;
645
+ const branch = isLast ? theme.tree.last : theme.tree.branch;
646
+ const rail = isLast ? " " : `${theme.tree.vertical} `;
647
+ const position = theme.fg("muted", `:${location.line}:${location.col}`);
648
+ const file = theme.fg("accent", replaceTabs(shortenPath(location.file)));
649
+ rows.push(` ${theme.fg("dim", branch)} ${file}${position}`);
650
+
651
+ const numberWidth = location.context.reduce((width, line) => Math.max(width, String(line.n).length), 0);
652
+ for (const line of location.context) {
653
+ const frame = formatCodeFrameLine(line.mark ? "*" : "", line.n, replaceTabs(line.text), numberWidth);
654
+ rows.push(` ${theme.fg("dim", rail)}${theme.fg("toolOutput", frame)}`);
655
+ }
656
+ });
657
+
658
+ if (hidden > 0) {
659
+ rows.push(` ${theme.fg("dim", theme.tree.last)} ${theme.fg("muted", formatMoreItems(hidden, noun))}`);
660
+ }
661
+ return rows;
662
+ }
663
+
664
+ /**
665
+ * Collapsed location rows stop at the card's edge. When that clips a row and no hidden location already
666
+ * advertises Ctrl+O, the header gets the expand hint: the expanded view wraps the full text.
667
+ */
668
+ function clipCollapsedLocations(rows: string[], width: number, parsed: LspLocations, theme: Theme): string[] {
669
+ const clipped = rows.map(row => truncateToWidth(row, width));
670
+ const hinted = parsed.locations.length > PREVIEW_LIMITS.LOCATIONS_COLLAPSED;
671
+ if (!hinted && clipped.some((row, index) => row !== rows[index])) {
672
+ clipped[0] = truncateToWidth(`${rows[0]}${formatExpandHint(theme, false, true)}`, width);
673
+ }
674
+ return clipped;
675
+ }
676
+
560
677
  // =============================================================================
561
678
  // Symbols Rendering
562
679
  // =============================================================================
@@ -615,6 +732,13 @@ function renderSymbols(symbolsMatch: RegExpMatchArray, lines: string[], expanded
615
732
  };
616
733
 
617
734
  const topLevelCount = symbols.filter(s => s.indent === 0).length;
735
+ // The glyph keeps the accent; the name and signature read as code in the file's language.
736
+ const lang = getLanguageFromPath(fileName);
737
+ const symbolName = (name: string): string => {
738
+ const plain = replaceTabs(name);
739
+ if (!isHighlightLanguage(lang)) return theme.fg("accent", plain);
740
+ return highlightThemeCode(plain, lang, theme)[0] ?? plain;
741
+ };
618
742
 
619
743
  if (expanded) {
620
744
  let output = `${icon} ${theme.fg("dim", `in ${fileName}`)}`;
@@ -626,7 +750,7 @@ function renderSymbols(symbolsMatch: RegExpMatchArray, lines: string[], expanded
626
750
  const symIsLast = isLast[i];
627
751
  const branch = symIsLast ? theme.tree.last : theme.tree.branch;
628
752
  const detailPrefix = symIsLast ? " " : `${theme.tree.vertical} `;
629
- output += `\n${prefix}${theme.fg("dim", branch)} ${theme.fg("accent", sym.icon)} ${theme.fg("accent", sym.name)}`;
753
+ output += `\n${prefix}${theme.fg("dim", branch)} ${theme.fg("accent", sym.icon)} ${symbolName(sym.name)}`;
630
754
  output += `\n${prefix}${theme.fg("dim", detailPrefix)}${theme.fg("muted", `line ${sym.line}`)}`;
631
755
  }
632
756
  return output.split("\n");
@@ -641,7 +765,7 @@ function renderSymbols(symbolsMatch: RegExpMatchArray, lines: string[], expanded
641
765
  const sym = topLevel[i];
642
766
  const isLast = i === topLevel.length - 1 && topLevelCount <= 3;
643
767
  const branch = isLast ? theme.tree.last : theme.tree.branch;
644
- output += `\n ${theme.fg("dim", branch)} ${theme.fg("accent", sym.icon)} ${theme.fg("accent", sym.name)} ${theme.fg(
768
+ output += `\n ${theme.fg("dim", branch)} ${theme.fg("accent", sym.icon)} ${symbolName(sym.name)} ${theme.fg(
645
769
  "muted",
646
770
  `line ${sym.line}`,
647
771
  )}`;
@@ -999,6 +1123,29 @@ function describeLspSymbols(lines: string[]): NativeNode | undefined {
999
1123
  return roots.length > 0 ? node("tree", { nodes: roots }) : undefined;
1000
1124
  }
1001
1125
 
1126
+ /** Definition-style locations: a file row with `:line:col`, then the numbered source context. */
1127
+ function describeLspLocations(
1128
+ request: Partial<LspParams> | undefined,
1129
+ fallbackAction: string,
1130
+ parsed: LspLocations,
1131
+ ): NativeToolView {
1132
+ const body = parsed.locations.map(location => {
1133
+ const file = plainText(location.file);
1134
+ const context = location.context.map(line => ({ ...line, text: plainText(line.text) }));
1135
+ const range = `:${location.line}:${location.col}`;
1136
+ const code = numberedCode(context, { path: file });
1137
+ const header = fileRow(displayPath(file), { range, title: file });
1138
+ return keyed(col(code ? [header, code] : [header], { gap: "xs" }), `${file}${range}`);
1139
+ });
1140
+ return {
1141
+ tool: lspNativeHead(request, fallbackAction, [formatCount(parsed.noun, parsed.count)]),
1142
+ tone: parsed.count > 0 ? undefined : "warning",
1143
+ inline: true,
1144
+ body: body.length > 0 ? body : undefined,
1145
+ preview: { lines: PREVIEW_LIMITS.COLLAPSED_ITEMS },
1146
+ };
1147
+ }
1148
+
1002
1149
  function describeLspResult(result: ToolRenderResult<LspToolDetails>, args: LspParams | undefined): NativeToolView {
1003
1150
  const request = args ?? result.details?.request;
1004
1151
  const fallbackAction = result.details?.action ?? "request";
@@ -1008,6 +1155,9 @@ function describeLspResult(result: ToolRenderResult<LspToolDetails>, args: LspPa
1008
1155
  if (!text) return { tool: lspNativeHead(request, fallbackAction, ["No result"]), tone: "warning", inline: true };
1009
1156
 
1010
1157
  const lines = text.split("\n");
1158
+ const locations = parseLspLocations(lines);
1159
+ if (locations) return describeLspLocations(request, fallbackAction, locations);
1160
+
1011
1161
  const statusError = activeThemeSymbol("status.error");
1012
1162
  const refMatch = text.match(/(\d+)\s+reference\(s\)/);
1013
1163
  const symbolsMatch = text.match(/Symbols in (.+):/);
package/src/tools/read.ts CHANGED
@@ -466,11 +466,11 @@ function readRangeStart(rawPath: string, args: ReadRenderArgs | undefined): numb
466
466
  }
467
467
 
468
468
  /**
469
- * Read content as numbered, wrapped `code` (no path header: the head names
470
- * the file), matching the ANSI preview's hanging wrap. Numbers come from
469
+ * Read content as one numbered, wrapped `code` block (no path header: the head
470
+ * names the file), matching the ANSI preview's hanging wrap. Numbers come from
471
471
  * `lineNumbers` (`displayContent`'s per-line numbers, `null` for an elided
472
- * block; runs split with `…` between) when they cover every line, else count
473
- * up from `start`.
472
+ * block, which Tern shows as a `…` gap row where the numbers jump) when they
473
+ * cover every line, else count up from `start`.
474
474
  */
475
475
  export function readContentCode(
476
476
  content: string,
@@ -479,10 +479,11 @@ export function readContentCode(
479
479
  path: string | undefined,
480
480
  ): NativeNode[] {
481
481
  const lines = content.split("\n");
482
- return numberedCode(
482
+ const block = numberedCode(
483
483
  lines.map((text, i) => ({ n: numbers && numbers.length === lines.length ? numbers[i]! : start + i, text })),
484
484
  { path, wrap: true },
485
485
  );
486
+ return block ? [block] : [];
486
487
  }
487
488
 
488
489
  /** An image content block as the read tool emits it (base64 data + mime type). */
package/src/tools/task.ts CHANGED
@@ -2254,7 +2254,7 @@ export interface TaskItem {
2254
2254
  agent?: string;
2255
2255
  /** Historical source session selected by the bundled consult agent. */
2256
2256
  sourceSession?: string;
2257
- /** Optional model selector override for the historical source session. */
2257
+ /** Bundled seance: override for the source session's saved model. Any other agent: one exact per-call model, gated by `task.perCallModel`. */
2258
2258
  model?: string | string[];
2259
2259
  /** Inline instructions; exactly one of task or taskFile is required. */
2260
2260
  task?: string;
@@ -2286,7 +2286,7 @@ export interface TaskParams {
2286
2286
  agent?: string;
2287
2287
  /** Historical source session selected by the bundled consult agent. */
2288
2288
  sourceSession?: string;
2289
- /** Optional model selector override for the historical source session. */
2289
+ /** See {@link TaskItem.model}. */
2290
2290
  model?: string | string[];
2291
2291
  /** The work (flat form). */
2292
2292
  task?: string;