@oh-my-pi/pi-tui 18.14.0 → 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 (58) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +6 -0
  3. package/dist/types/charts/table-data.d.ts +4 -2
  4. package/dist/types/chat/figure-markdown.d.ts +2 -0
  5. package/dist/types/chat/svg-figure.d.ts +5 -0
  6. package/dist/types/chat/table-chart.d.ts +2 -0
  7. package/dist/types/chat/transcript-render-helpers.d.ts +3 -3
  8. package/dist/types/components/image.d.ts +6 -0
  9. package/dist/types/native/describe.d.ts +4 -2
  10. package/dist/types/native/overlay.d.ts +42 -2
  11. package/dist/types/native/state.d.ts +4 -0
  12. package/dist/types/overlays/btw-history-panel.d.ts +2 -0
  13. package/dist/types/prompt/composer.d.ts +13 -5
  14. package/dist/types/render/render-utils.d.ts +2 -0
  15. package/dist/types/theme/theme.d.ts +1 -1
  16. package/dist/types/theme/tui-adapters.d.ts +2 -0
  17. package/dist/types/thinking.d.ts +8 -6
  18. package/dist/types/tools/ast-grep.d.ts +2 -0
  19. package/dist/types/tools/eval.d.ts +2 -0
  20. package/dist/types/tools/find.d.ts +1 -1
  21. package/dist/types/tools/grouped-file-output.d.ts +24 -11
  22. package/dist/types/tools/read.d.ts +4 -4
  23. package/dist/types/tools/task.d.ts +2 -2
  24. package/package.json +9 -9
  25. package/src/apps/git/git-tui.ts +10 -17
  26. package/src/apps/git/sidebar.ts +21 -35
  27. package/src/apps/ps-top.ts +4 -12
  28. package/src/charts/chart-plan.ts +0 -29
  29. package/src/charts/table-data.ts +55 -6
  30. package/src/chat/figure-markdown.ts +6 -4
  31. package/src/chat/svg-figure.ts +55 -16
  32. package/src/chat/table-chart.ts +19 -2
  33. package/src/chat/transcript-render-helpers.ts +18 -16
  34. package/src/components/image.ts +13 -0
  35. package/src/native/backend.ts +7 -3
  36. package/src/native/describe.ts +9 -4
  37. package/src/native/overlay.ts +124 -16
  38. package/src/native/state.ts +25 -5
  39. package/src/overlays/btw-history-panel.ts +8 -0
  40. package/src/overlays/extensions/extension-dashboard.ts +7 -8
  41. package/src/overlays/jobs-panel.ts +38 -4
  42. package/src/overlays/login-dialog.ts +8 -26
  43. package/src/overlays/tree-selector.ts +81 -27
  44. package/src/overlays/usage-dashboard.ts +2 -4
  45. package/src/prompt/composer.ts +17 -5
  46. package/src/render/render-utils.ts +2 -0
  47. package/src/theme/theme-class.ts +12 -3
  48. package/src/theme/theme.ts +1 -0
  49. package/src/theme/tui-adapters.ts +8 -3
  50. package/src/thinking.ts +17 -11
  51. package/src/tools/ast-grep.ts +10 -2
  52. package/src/tools/eval.ts +2 -0
  53. package/src/tools/find.ts +7 -2
  54. package/src/tools/grep.ts +8 -2
  55. package/src/tools/grouped-file-output.ts +172 -47
  56. package/src/tools/lsp.ts +158 -8
  57. package/src/tools/read.ts +6 -5
  58. package/src/tools/task.ts +2 -2
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;