@linxiraos/pi-tui 1.4.7 → 1.4.9
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.
- package/CHANGELOG.md +28 -109
- package/README.md +7 -1
- package/dist/types/app-keybindings.d.ts +5 -0
- package/dist/types/charts/table-data.d.ts +4 -2
- package/dist/types/chat/bash-execution.d.ts +4 -1
- package/dist/types/chat/eval-execution.d.ts +2 -0
- package/dist/types/chat/execution-shared.d.ts +14 -8
- package/dist/types/chat/figure-markdown.d.ts +2 -0
- package/dist/types/chat/svg-figure.d.ts +5 -0
- package/dist/types/chat/table-chart.d.ts +2 -0
- package/dist/types/chat/transcript-render-helpers.d.ts +11 -3
- package/dist/types/chrome/dynamic-border.d.ts +6 -0
- package/dist/types/chrome/transcript-status.d.ts +2 -2
- package/dist/types/components/editor.d.ts +15 -6
- package/dist/types/components/image.d.ts +6 -0
- package/dist/types/components/loader.d.ts +2 -0
- package/dist/types/keybinding-matchers.d.ts +7 -0
- package/dist/types/native/describe.d.ts +4 -2
- package/dist/types/native/node.d.ts +2 -3
- package/dist/types/native/overlay.d.ts +42 -2
- package/dist/types/native/state.d.ts +4 -0
- package/dist/types/overlays/btw-history-panel.d.ts +15 -0
- package/dist/types/overlays/btw-history.d.ts +24 -0
- package/dist/types/overlays/btw-inject.d.ts +22 -0
- package/dist/types/overlays/btw-panel.d.ts +7 -0
- package/dist/types/overlays/hook-editor.d.ts +2 -0
- package/dist/types/overlays/jobs-panel.d.ts +4 -0
- package/dist/types/overlays/model-browser.d.ts +1 -1
- package/dist/types/overlays/session-selector.d.ts +11 -2
- package/dist/types/prompt/composer.d.ts +13 -5
- package/dist/types/render/render-utils.d.ts +23 -1
- package/dist/types/status-line/startup.d.ts +0 -15
- package/dist/types/terminal-capabilities.d.ts +1 -1
- package/dist/types/theme/symbols.d.ts +3 -1
- package/dist/types/theme/theme-class.d.ts +1 -0
- package/dist/types/theme/theme.d.ts +1 -1
- package/dist/types/theme/tui-adapters.d.ts +2 -0
- package/dist/types/thinking.d.ts +8 -6
- package/dist/types/tools/ast-grep.d.ts +2 -0
- package/dist/types/tools/eval.d.ts +2 -0
- package/dist/types/tools/find.d.ts +1 -1
- package/dist/types/tools/grouped-file-output.d.ts +100 -19
- package/dist/types/tools/hashline-format.d.ts +5 -0
- package/dist/types/tools/native-view.d.ts +2 -0
- package/dist/types/tools/output-meta.d.ts +27 -0
- package/dist/types/tools/read.d.ts +14 -4
- package/dist/types/tools/task.d.ts +4 -3
- package/dist/types/tools/wait.d.ts +2 -0
- package/dist/types/tui.d.ts +12 -0
- package/dist/types/utils.d.ts +4 -0
- package/package.json +9 -9
- package/src/app-keybindings.d.ts +5 -0
- package/src/app-keybindings.ts +5 -0
- package/src/apps/git/git-tui.ts +10 -17
- package/src/apps/git/sidebar.ts +21 -35
- package/src/apps/ps-top.ts +4 -12
- package/src/charts/chart-plan.ts +0 -29
- package/src/charts/table-data.d.ts +4 -2
- package/src/charts/table-data.ts +55 -6
- package/src/chat/bash-execution.d.ts +4 -1
- package/src/chat/bash-execution.ts +20 -9
- package/src/chat/chat-transcript-builder.ts +5 -2
- package/src/chat/eval-execution.d.ts +2 -0
- package/src/chat/eval-execution.ts +14 -7
- package/src/chat/execution-shared.d.ts +14 -8
- package/src/chat/execution-shared.ts +39 -18
- package/src/chat/figure-markdown.d.ts +2 -0
- package/src/chat/figure-markdown.ts +6 -4
- package/src/chat/read-tool-group.ts +56 -36
- package/src/chat/svg-figure.d.ts +5 -0
- package/src/chat/svg-figure.ts +55 -16
- package/src/chat/table-chart.d.ts +2 -0
- package/src/chat/table-chart.ts +19 -2
- package/src/chat/transcript-render-helpers.d.ts +11 -3
- package/src/chat/transcript-render-helpers.ts +70 -22
- package/src/chrome/dynamic-border.d.ts +6 -0
- package/src/chrome/dynamic-border.ts +28 -2
- package/src/chrome/transcript-status.d.ts +2 -2
- package/src/chrome/transcript-status.ts +5 -3
- package/src/components/editor.d.ts +15 -6
- package/src/components/editor.ts +123 -24
- package/src/components/image.d.ts +6 -0
- package/src/components/image.ts +13 -0
- package/src/components/key-value-list.ts +9 -9
- package/src/components/loader.d.ts +2 -0
- package/src/components/loader.ts +7 -0
- package/src/components/section.ts +1 -9
- package/src/components/table.ts +1 -9
- package/src/keybinding-matchers.d.ts +7 -0
- package/src/keybinding-matchers.ts +13 -0
- package/src/native/backend.ts +7 -3
- package/src/native/describe.d.ts +4 -2
- package/src/native/describe.ts +9 -4
- package/src/native/node.d.ts +2 -3
- package/src/native/node.ts +2 -3
- package/src/native/overlay.d.ts +42 -2
- package/src/native/overlay.ts +124 -16
- package/src/native/state.d.ts +4 -0
- package/src/native/state.ts +25 -5
- package/src/overlays/btw-history-panel.ts +106 -14
- package/src/overlays/btw-history.ts +65 -0
- package/src/overlays/btw-inject.ts +91 -0
- package/src/overlays/btw-panel.ts +53 -12
- package/src/overlays/extensions/extension-dashboard.ts +7 -8
- package/src/overlays/hook-editor.ts +6 -0
- package/src/overlays/jobs-panel.ts +82 -22
- package/src/overlays/login-dialog.ts +8 -26
- package/src/overlays/model-browser.ts +69 -10
- package/src/overlays/session-selector.ts +25 -5
- package/src/overlays/settings-defs.ts +2 -2
- package/src/overlays/tree-selector.ts +83 -27
- package/src/overlays/usage-dashboard.ts +4 -6
- package/src/prompt/composer.ts +17 -5
- package/src/render/code-cell.ts +1 -1
- package/src/render/file-list.ts +4 -7
- package/src/render/render-utils.d.ts +23 -1
- package/src/render/render-utils.ts +38 -6
- package/src/setup/scenes/glyph.ts +1 -1
- package/src/status-line/startup.ts +36 -70
- package/src/terminal-capabilities.d.ts +1 -1
- package/src/terminal-capabilities.ts +5 -0
- package/src/theme/symbols.d.ts +3 -1
- package/src/theme/symbols.ts +16 -9
- package/src/theme/theme-class.d.ts +1 -0
- package/src/theme/theme-class.ts +15 -3
- package/src/theme/theme.d.ts +1 -1
- package/src/theme/theme.ts +1 -0
- package/src/theme/tui-adapters.d.ts +2 -0
- package/src/theme/tui-adapters.ts +8 -3
- package/src/thinking.d.ts +8 -6
- package/src/thinking.ts +17 -11
- package/src/tmux.ts +1 -0
- package/src/tools/agent-tree.ts +13 -11
- package/src/tools/ask.ts +24 -37
- package/src/tools/ast-edit.ts +48 -93
- package/src/tools/ast-grep.d.ts +2 -0
- package/src/tools/ast-grep.ts +31 -67
- package/src/tools/bash.ts +7 -0
- package/src/tools/default-renderer.ts +1 -1
- package/src/tools/edit.ts +50 -43
- package/src/tools/eval.d.ts +2 -0
- package/src/tools/eval.ts +2 -0
- package/src/tools/fetch.ts +2 -1
- package/src/tools/find.d.ts +1 -1
- package/src/tools/find.ts +13 -5
- package/src/tools/github.ts +14 -46
- package/src/tools/glob.ts +2 -1
- package/src/tools/grep.ts +47 -277
- package/src/tools/grouped-file-output.d.ts +100 -19
- package/src/tools/grouped-file-output.ts +414 -103
- package/src/tools/hashline-format.d.ts +5 -0
- package/src/tools/hashline-format.ts +5 -0
- package/src/tools/json-tree.ts +1 -5
- package/src/tools/lsp.ts +210 -32
- package/src/tools/native-view.d.ts +2 -0
- package/src/tools/native-view.ts +11 -5
- package/src/tools/output-meta.d.ts +27 -0
- package/src/tools/output-meta.ts +68 -4
- package/src/tools/proc-render.ts +3 -3
- package/src/tools/read.d.ts +14 -4
- package/src/tools/read.ts +20 -5
- package/src/tools/task.d.ts +4 -3
- package/src/tools/task.ts +41 -81
- package/src/tools/vibe.ts +4 -4
- package/src/tools/wait.d.ts +2 -0
- package/src/tools/wait.ts +8 -5
- package/src/tools/write.ts +17 -27
- package/src/tools/yield.ts +1 -1
- package/src/tui.d.ts +12 -0
- package/src/tui.ts +91 -9
- package/src/utils.d.ts +4 -0
- package/src/utils.ts +10 -0
package/src/tools/lsp.ts
CHANGED
|
@@ -12,12 +12,15 @@ 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
|
+
formatStyledPath,
|
|
23
|
+
PREVIEW_LIMITS,
|
|
21
24
|
type ParsedDiagnostic,
|
|
22
25
|
parseDiagnosticMessage,
|
|
23
26
|
replaceTabs,
|
|
@@ -34,8 +37,8 @@ import { ansi, code, col, compact, keyed, md, node, row, span, text } from "../n
|
|
|
34
37
|
import type { NativeNode } from "../native/node";
|
|
35
38
|
import { OwnerMemo } from "../native/memo";
|
|
36
39
|
import { plainText } from "../native/spans";
|
|
37
|
-
import { walkGroupedOutput } from "./grouped-file-output";
|
|
38
|
-
import { diagnosticGlyph, fileHref, fileRow, inlineErrorView } from "./native-view";
|
|
40
|
+
import { numberedCode, walkGroupedOutput } from "./grouped-file-output";
|
|
41
|
+
import { diagnosticGlyph, displayPath, fileHref, fileRow, inlineErrorView } from "./native-view";
|
|
39
42
|
import { activeThemeSymbol } from "../theme/active-symbols";
|
|
40
43
|
|
|
41
44
|
/** Display arguments for an LSP tool request. */
|
|
@@ -168,6 +171,26 @@ export function renderCall(args: LspParams, _options: RenderResultOptions, theme
|
|
|
168
171
|
/** A diagnostics status line for a file no server reported on in time: unverified, never "No issues". */
|
|
169
172
|
const UNREPORTED_LINE_RE = /\bno diagnostics report yet\b/;
|
|
170
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Whether a line is one of the LSP tool's per-file status rows (`<glyph> <path>: …`).
|
|
176
|
+
* Only a row's start counts: response text such as source or hover content can hold
|
|
177
|
+
* the same characters (ASCII `[-]`).
|
|
178
|
+
*/
|
|
179
|
+
function isStatusRow(line: string, glyph: string): boolean {
|
|
180
|
+
return line.startsWith(`${glyph} `);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Whether a result holds a status row drawn with `glyph`. Only the diagnostics action
|
|
185
|
+
* writes status rows; any other action's text is the server's (a `request` response
|
|
186
|
+
* verbatim), so a glyph there is content even at a line start. A result whose action
|
|
187
|
+
* is unknown keeps the inference.
|
|
188
|
+
*/
|
|
189
|
+
function hasStatusRow(action: string | undefined, lines: readonly string[], glyph: string): boolean {
|
|
190
|
+
if (action !== undefined && action !== "diagnostics") return false;
|
|
191
|
+
return lines.some(line => isStatusRow(line, glyph));
|
|
192
|
+
}
|
|
193
|
+
|
|
171
194
|
/**
|
|
172
195
|
* Render LSP tool result with intelligent formatting based on result type.
|
|
173
196
|
* Detects hover, diagnostics, references, symbols, etc. and formats accordingly.
|
|
@@ -188,20 +211,23 @@ export function renderResult(
|
|
|
188
211
|
const text = content.text;
|
|
189
212
|
const lines = text.split("\n");
|
|
190
213
|
|
|
191
|
-
// Static type detection (result content doesn't change between renders)
|
|
192
|
-
|
|
214
|
+
// Static type detection (result content doesn't change between renders). Locations are
|
|
215
|
+
// anchored at the response's first line, so they win over checks a source snippet could trip.
|
|
216
|
+
const locations = parseLspLocations(lines);
|
|
217
|
+
const codeBlockMatch = locations ? null : text.match(/```(\w*)\n([\s\S]*?)```/);
|
|
193
218
|
const errorMatch = text.match(/(\d+)\s+error\(s\)/);
|
|
194
219
|
const warningMatch = text.match(/(\d+)\s+warning\(s\)/);
|
|
195
220
|
const refMatch = text.match(/(\d+)\s+reference\(s\)/);
|
|
196
221
|
const symbolsMatch = text.match(/Symbols in (.+):/);
|
|
197
|
-
const hasStatusError = text.includes(theme.status.error);
|
|
198
222
|
const unreportedCount = lines.filter(line => UNREPORTED_LINE_RE.test(line)).length;
|
|
199
223
|
|
|
200
224
|
// Static request info
|
|
201
225
|
const request = args ?? result.details?.request;
|
|
226
|
+
const action = request?.action ?? result.details?.action;
|
|
227
|
+
const hasStatusError = hasStatusRow(action, lines, theme.status.error);
|
|
202
228
|
const requestLines: string[] = [];
|
|
203
229
|
if (request?.file) {
|
|
204
|
-
requestLines.push(
|
|
230
|
+
requestLines.push(formatStyledPath(request.file, theme));
|
|
205
231
|
}
|
|
206
232
|
if (request?.line !== undefined) {
|
|
207
233
|
requestLines.push(theme.fg("dim", `line ${request.line}`));
|
|
@@ -217,6 +243,13 @@ export function renderResult(
|
|
|
217
243
|
// and render it once per expanded state instead of on every spinner frame.
|
|
218
244
|
const bodies: Array<LspResultBody | undefined> = [undefined, undefined];
|
|
219
245
|
const renderBody = (expanded: boolean): LspResultBody => {
|
|
246
|
+
if (locations) {
|
|
247
|
+
return {
|
|
248
|
+
label: "Locations",
|
|
249
|
+
state: locations.count > 0 ? "success" : "warning",
|
|
250
|
+
bodyLines: renderLocations(locations, expanded, theme),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
220
253
|
if (codeBlockMatch) {
|
|
221
254
|
return {
|
|
222
255
|
label: "Hover",
|
|
@@ -250,7 +283,7 @@ export function renderResult(
|
|
|
250
283
|
bodyLines: [`${theme.styledSymbol("tool.lsp", "accent")} ${theme.fg("dim", "OK")}`],
|
|
251
284
|
};
|
|
252
285
|
}
|
|
253
|
-
return { label: "Response", state: "success", bodyLines: renderGeneric(text, lines, expanded, theme) };
|
|
286
|
+
return { label: "Response", state: "success", bodyLines: renderGeneric(text, lines, action, expanded, theme) };
|
|
254
287
|
};
|
|
255
288
|
|
|
256
289
|
return framedToolCard(theme, ({ contentWidth }) => {
|
|
@@ -273,6 +306,7 @@ export function renderResult(
|
|
|
273
306
|
|
|
274
307
|
// Hover code hangs under its rail; expanded rows hang under their tree
|
|
275
308
|
// connector or guide rails so Ctrl+O reveals full text instead of clipping.
|
|
309
|
+
// Collapsed source lines stop at the card's edge, one row each under their rail.
|
|
276
310
|
const rail = ` ${theme.fg("mdCodeBlockBorder", theme.boxRound.vertical)} `;
|
|
277
311
|
const contentLines = codeBlockMatch
|
|
278
312
|
? bodyLines.flatMap(line =>
|
|
@@ -280,7 +314,9 @@ export function renderResult(
|
|
|
280
314
|
)
|
|
281
315
|
: expanded
|
|
282
316
|
? bodyLines.flatMap(line => wrapGuidedLine(line, contentWidth, theme))
|
|
283
|
-
:
|
|
317
|
+
: locations
|
|
318
|
+
? clipCollapsedLocations(bodyLines, contentWidth, locations, theme)
|
|
319
|
+
: bodyLines;
|
|
284
320
|
return {
|
|
285
321
|
header,
|
|
286
322
|
phase: isPartial ? "partial" : state,
|
|
@@ -372,10 +408,16 @@ function renderHover(
|
|
|
372
408
|
// Diagnostics Rendering
|
|
373
409
|
// =============================================================================
|
|
374
410
|
|
|
411
|
+
/** A diagnostic's location: the muted file-type icon, the styled path and the muted `:line:col`. */
|
|
375
412
|
function formatDiagnosticLocation(file: string, line: number, col: number, theme: Theme): string {
|
|
376
413
|
const lang = getLanguageFromPath(file);
|
|
377
414
|
const icon = theme.fg("muted", theme.getLangIcon(lang));
|
|
378
|
-
return `${icon} ${file}
|
|
415
|
+
return `${icon} ${formatStyledPath(file, theme)}${theme.fg("muted", `:${line}:${col}`)}`;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** The `[severity]` tag in its severity's color: the path no longer carries it. */
|
|
419
|
+
function formatSeverityTag(severity: ParsedDiagnostic["severity"], theme: Theme): string {
|
|
420
|
+
return theme.fg(severityToColor(severity), `[${severity}]`);
|
|
379
421
|
}
|
|
380
422
|
|
|
381
423
|
/**
|
|
@@ -405,7 +447,7 @@ function renderDiagnostics(
|
|
|
405
447
|
if (unreportedLines.length > 0) meta.push(formatCount("unverified file", unreportedLines.length));
|
|
406
448
|
if (meta.length === 0) meta.push("No issues");
|
|
407
449
|
|
|
408
|
-
const diagLines = lines.filter(l => l
|
|
450
|
+
const diagLines = lines.filter(l => isStatusRow(l, theme.status.error) || /:\d+:\d+/.test(l));
|
|
409
451
|
const parsedDiagnostics = diagLines
|
|
410
452
|
.map(line => parseDiagnosticMessage(line.trim()))
|
|
411
453
|
.filter((diag): diag is ParsedDiagnostic => diag !== null);
|
|
@@ -429,12 +471,8 @@ function renderDiagnostics(
|
|
|
429
471
|
output += `\n ${theme.fg("dim", branch)} ${theme.fg("muted", item.raw)}`;
|
|
430
472
|
continue;
|
|
431
473
|
}
|
|
432
|
-
const severityColor = severityToColor(item.severity);
|
|
433
474
|
const location = formatDiagnosticLocation(item.filePath, item.line, item.col, theme);
|
|
434
|
-
output += `\n ${theme.fg("dim", branch)} ${
|
|
435
|
-
"dim",
|
|
436
|
-
`[${item.severity}]`,
|
|
437
|
-
)}`;
|
|
475
|
+
output += `\n ${theme.fg("dim", branch)} ${location} ${formatSeverityTag(item.severity, theme)}`;
|
|
438
476
|
const message = formatDiagnosticMessage(item);
|
|
439
477
|
if (message) {
|
|
440
478
|
output += `\n ${theme.fg("dim", detailPrefix)}${theme.fg("muted", message)}`;
|
|
@@ -459,13 +497,12 @@ function renderDiagnostics(
|
|
|
459
497
|
output += `\n ${theme.fg("dim", branch)} ${theme.fg("muted", item.raw)}`;
|
|
460
498
|
continue;
|
|
461
499
|
}
|
|
462
|
-
const severityColor = severityToColor(item.severity);
|
|
463
500
|
const location = formatDiagnosticLocation(item.filePath, item.line, item.col, theme);
|
|
464
501
|
const diagnosticMessage = formatDiagnosticMessage(item);
|
|
465
502
|
const message = diagnosticMessage
|
|
466
503
|
? ` ${theme.fg("muted", truncateToWidth(diagnosticMessage, TRUNCATE_LENGTHS.CONTENT))}`
|
|
467
504
|
: "";
|
|
468
|
-
output += `\n ${theme.fg("dim", branch)} ${
|
|
505
|
+
output += `\n ${theme.fg("dim", branch)} ${location} ${formatSeverityTag(item.severity, theme)}${message}`;
|
|
469
506
|
}
|
|
470
507
|
if (remaining > 0) {
|
|
471
508
|
output += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg("muted", `… ${remaining} more`)}`;
|
|
@@ -515,7 +552,7 @@ function renderReferences(refMatch: RegExpMatchArray, lines: string[], expanded:
|
|
|
515
552
|
const fileCont = isLastFile ? " " : `${theme.tree.vertical} `;
|
|
516
553
|
|
|
517
554
|
const fileMeta = `${locs.length} reference${locs.length !== 1 ? "s" : ""}`;
|
|
518
|
-
output += `\n ${theme.fg("dim", fileBranch)} ${
|
|
555
|
+
output += `\n ${theme.fg("dim", fileBranch)} ${formatStyledPath(file, theme)} ${theme.fg("dim", fileMeta)}`;
|
|
519
556
|
|
|
520
557
|
if (maxLocsPerFile > 0) {
|
|
521
558
|
const locsToShow = locs.slice(0, maxLocsPerFile);
|
|
@@ -529,10 +566,8 @@ function renderReferences(refMatch: RegExpMatchArray, lines: string[], expanded:
|
|
|
529
566
|
`line ${line}, col ${col}`,
|
|
530
567
|
)}`;
|
|
531
568
|
if (expanded) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
`at ${file}:${line}:${col}`,
|
|
535
|
-
)}`;
|
|
569
|
+
const at = `${theme.fg("muted", "at ")}${formatStyledPath(file, theme)}${theme.fg("muted", `:${line}:${col}`)}`;
|
|
570
|
+
output += `\n ${theme.fg("dim", fileCont)}${theme.fg("dim", locCont)}${at}`;
|
|
536
571
|
}
|
|
537
572
|
}
|
|
538
573
|
if (locs.length > maxLocsPerFile) {
|
|
@@ -557,6 +592,109 @@ function renderReferences(refMatch: RegExpMatchArray, lines: string[], expanded:
|
|
|
557
592
|
return (expanded ? renderGrouped(files.length, Number.POSITIVE_INFINITY) : renderGrouped(3, 1)).split("\n");
|
|
558
593
|
}
|
|
559
594
|
|
|
595
|
+
// =============================================================================
|
|
596
|
+
// Locations Rendering
|
|
597
|
+
// =============================================================================
|
|
598
|
+
|
|
599
|
+
/** One location of a definition-style response, with its numbered source context. */
|
|
600
|
+
interface LspLocation {
|
|
601
|
+
file: string;
|
|
602
|
+
line: number;
|
|
603
|
+
col: number;
|
|
604
|
+
/** Source lines around the location; the location's own line is `mark`ed. */
|
|
605
|
+
context: { n: number; text: string; mark: boolean }[];
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/** A definition, type definition or implementation response. */
|
|
609
|
+
interface LspLocations {
|
|
610
|
+
/** `definition`, `type definition` or `implementation`. */
|
|
611
|
+
noun: string;
|
|
612
|
+
count: number;
|
|
613
|
+
locations: LspLocation[];
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const LOCATIONS_HEADER_RE = /^Found (\d+) (definition|type definition|implementation)\(s\):$/;
|
|
617
|
+
/**
|
|
618
|
+
* ` file:line:col`, the path from column 2 on (it may itself start with whitespace). Context rows are
|
|
619
|
+
* ` N: source`; a row matching both is context of the current location.
|
|
620
|
+
*/
|
|
621
|
+
const LOCATION_RE = /^ {2}(.+):(\d+):(\d+)$/;
|
|
622
|
+
const LOCATION_CONTEXT_RE = /^ {4}(\d+): ?(.*)$/;
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Parse a `Found N definition(s):` response (also type definitions and
|
|
626
|
+
* implementations): ` file:line:col` rows, each followed by its
|
|
627
|
+
* ` N: source` context lines.
|
|
628
|
+
*/
|
|
629
|
+
function parseLspLocations(lines: readonly string[]): LspLocations | undefined {
|
|
630
|
+
const header = LOCATIONS_HEADER_RE.exec(lines[0] ?? "");
|
|
631
|
+
if (!header) return undefined;
|
|
632
|
+
const locations: LspLocation[] = [];
|
|
633
|
+
for (const line of lines.slice(1)) {
|
|
634
|
+
const current = locations.at(-1);
|
|
635
|
+
const context = current ? LOCATION_CONTEXT_RE.exec(line) : null;
|
|
636
|
+
if (current && context) {
|
|
637
|
+
const n = Number(context[1]);
|
|
638
|
+
current.context.push({ n, text: context[2].trimEnd(), mark: n === current.line });
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
const location = LOCATION_RE.exec(line);
|
|
642
|
+
if (location) {
|
|
643
|
+
const [, file, lineNumber, column] = location;
|
|
644
|
+
locations.push({ file, line: Number(lineNumber), col: Number(column), context: [] });
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return { noun: header[2], count: Number(header[1]), locations };
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Render definitions, type definitions and implementations: each
|
|
652
|
+
* `file:line:col` over its source context, the location's line marked like a
|
|
653
|
+
* grep match.
|
|
654
|
+
*/
|
|
655
|
+
function renderLocations(parsed: LspLocations, expanded: boolean, theme: Theme): string[] {
|
|
656
|
+
const { noun, count, locations } = parsed;
|
|
657
|
+
const shown = expanded ? locations : locations.slice(0, PREVIEW_LIMITS.LOCATIONS_COLLAPSED);
|
|
658
|
+
const hidden = locations.length - shown.length;
|
|
659
|
+
const icon = count > 0 ? theme.styledSymbol("tool.lsp", "accent") : theme.styledSymbol("status.warning", "warning");
|
|
660
|
+
const rows = [
|
|
661
|
+
`${icon} ${theme.fg("dim", formatCount(noun, count))}${formatExpandHint(theme, expanded, hidden > 0)}`,
|
|
662
|
+
];
|
|
663
|
+
|
|
664
|
+
shown.forEach((location, index) => {
|
|
665
|
+
const isLast = index === shown.length - 1 && hidden === 0;
|
|
666
|
+
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
667
|
+
const rail = isLast ? " " : `${theme.tree.vertical} `;
|
|
668
|
+
const position = theme.fg("muted", `:${location.line}:${location.col}`);
|
|
669
|
+
const file = formatStyledPath(replaceTabs(shortenPath(location.file)), theme);
|
|
670
|
+
rows.push(` ${theme.fg("dim", branch)} ${file}${position}`);
|
|
671
|
+
|
|
672
|
+
const numberWidth = location.context.reduce((width, line) => Math.max(width, String(line.n).length), 0);
|
|
673
|
+
for (const line of location.context) {
|
|
674
|
+
const frame = formatCodeFrameLine(line.mark ? "*" : "", line.n, replaceTabs(line.text), numberWidth);
|
|
675
|
+
rows.push(` ${theme.fg("dim", rail)}${theme.fg("toolOutput", frame)}`);
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
if (hidden > 0) {
|
|
680
|
+
rows.push(` ${theme.fg("dim", theme.tree.last)} ${theme.fg("muted", formatMoreItems(hidden, noun))}`);
|
|
681
|
+
}
|
|
682
|
+
return rows;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Collapsed location rows stop at the card's edge. When that clips a row and no hidden location already
|
|
687
|
+
* advertises Ctrl+O, the header gets the expand hint: the expanded view wraps the full text.
|
|
688
|
+
*/
|
|
689
|
+
function clipCollapsedLocations(rows: string[], width: number, parsed: LspLocations, theme: Theme): string[] {
|
|
690
|
+
const clipped = rows.map(row => truncateToWidth(row, width));
|
|
691
|
+
const hinted = parsed.locations.length > PREVIEW_LIMITS.LOCATIONS_COLLAPSED;
|
|
692
|
+
if (!hinted && clipped.some((row, index) => row !== rows[index])) {
|
|
693
|
+
clipped[0] = truncateToWidth(`${rows[0]}${formatExpandHint(theme, false, true)}`, width);
|
|
694
|
+
}
|
|
695
|
+
return clipped;
|
|
696
|
+
}
|
|
697
|
+
|
|
560
698
|
// =============================================================================
|
|
561
699
|
// Symbols Rendering
|
|
562
700
|
// =============================================================================
|
|
@@ -615,6 +753,13 @@ function renderSymbols(symbolsMatch: RegExpMatchArray, lines: string[], expanded
|
|
|
615
753
|
};
|
|
616
754
|
|
|
617
755
|
const topLevelCount = symbols.filter(s => s.indent === 0).length;
|
|
756
|
+
// The glyph keeps the accent; the name and signature read as code in the file's language.
|
|
757
|
+
const lang = getLanguageFromPath(fileName);
|
|
758
|
+
const symbolName = (name: string): string => {
|
|
759
|
+
const plain = replaceTabs(name);
|
|
760
|
+
if (!isHighlightLanguage(lang)) return theme.fg("accent", plain);
|
|
761
|
+
return highlightThemeCode(plain, lang, theme)[0] ?? plain;
|
|
762
|
+
};
|
|
618
763
|
|
|
619
764
|
if (expanded) {
|
|
620
765
|
let output = `${icon} ${theme.fg("dim", `in ${fileName}`)}`;
|
|
@@ -626,7 +771,7 @@ function renderSymbols(symbolsMatch: RegExpMatchArray, lines: string[], expanded
|
|
|
626
771
|
const symIsLast = isLast[i];
|
|
627
772
|
const branch = symIsLast ? theme.tree.last : theme.tree.branch;
|
|
628
773
|
const detailPrefix = symIsLast ? " " : `${theme.tree.vertical} `;
|
|
629
|
-
output += `\n${prefix}${theme.fg("dim", branch)} ${theme.fg("accent", sym.icon)} ${
|
|
774
|
+
output += `\n${prefix}${theme.fg("dim", branch)} ${theme.fg("accent", sym.icon)} ${symbolName(sym.name)}`;
|
|
630
775
|
output += `\n${prefix}${theme.fg("dim", detailPrefix)}${theme.fg("muted", `line ${sym.line}`)}`;
|
|
631
776
|
}
|
|
632
777
|
return output.split("\n");
|
|
@@ -641,7 +786,7 @@ function renderSymbols(symbolsMatch: RegExpMatchArray, lines: string[], expanded
|
|
|
641
786
|
const sym = topLevel[i];
|
|
642
787
|
const isLast = i === topLevel.length - 1 && topLevelCount <= 3;
|
|
643
788
|
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
644
|
-
output += `\n ${theme.fg("dim", branch)} ${theme.fg("accent", sym.icon)} ${
|
|
789
|
+
output += `\n ${theme.fg("dim", branch)} ${theme.fg("accent", sym.icon)} ${symbolName(sym.name)} ${theme.fg(
|
|
645
790
|
"muted",
|
|
646
791
|
`line ${sym.line}`,
|
|
647
792
|
)}`;
|
|
@@ -660,9 +805,15 @@ function renderSymbols(symbolsMatch: RegExpMatchArray, lines: string[], expanded
|
|
|
660
805
|
/**
|
|
661
806
|
* Generic fallback rendering for unknown result types.
|
|
662
807
|
*/
|
|
663
|
-
function renderGeneric(
|
|
664
|
-
|
|
665
|
-
|
|
808
|
+
function renderGeneric(
|
|
809
|
+
text: string,
|
|
810
|
+
lines: string[],
|
|
811
|
+
action: string | undefined,
|
|
812
|
+
expanded: boolean,
|
|
813
|
+
theme: Theme,
|
|
814
|
+
): string[] {
|
|
815
|
+
const hasError = text.includes("Error:") || hasStatusRow(action, lines, theme.status.error);
|
|
816
|
+
const hasSuccess = hasStatusRow(action, lines, theme.status.success) || text.includes("Applied");
|
|
666
817
|
|
|
667
818
|
const icon =
|
|
668
819
|
hasError && !hasSuccess
|
|
@@ -806,7 +957,7 @@ interface LspDiagnosticsParse {
|
|
|
806
957
|
|
|
807
958
|
const DIAGNOSTIC_AT_RE = /^\d+:\d+\s+\[/;
|
|
808
959
|
const DIAGNOSTICS_SUMMARY_RE = /^\d+ \w+\(s\)(?:, \d+ \w+\(s\))*:?$/;
|
|
809
|
-
/** A per-file status line's leading status glyph (`✘`, `⚠`, a Nerd Font glyph, ASCII `[
|
|
960
|
+
/** A per-file status line's leading status glyph (`✘`, `⚠`, a Nerd Font glyph, ASCII `[-]`). */
|
|
810
961
|
const STATUS_GLYPH_RE = /^(?:\[[^\]\s]*\]|[^\p{L}\p{N}\s./~\\]+)\s+/u;
|
|
811
962
|
/** Per-file summaries (`✗ a.ts: 2 error(s)`, `✓ a.ts: no issues`) repeat what the rows and head count. */
|
|
812
963
|
const FILE_SUMMARY_RE = /: (?:no issues|\d+ \w+\(s\)(?:, \d+ \w+\(s\))*)$/;
|
|
@@ -999,15 +1150,42 @@ function describeLspSymbols(lines: string[]): NativeNode | undefined {
|
|
|
999
1150
|
return roots.length > 0 ? node("tree", { nodes: roots }) : undefined;
|
|
1000
1151
|
}
|
|
1001
1152
|
|
|
1153
|
+
/** Definition-style locations: a file row with `:line:col`, then the numbered source context. */
|
|
1154
|
+
function describeLspLocations(
|
|
1155
|
+
request: Partial<LspParams> | undefined,
|
|
1156
|
+
fallbackAction: string,
|
|
1157
|
+
parsed: LspLocations,
|
|
1158
|
+
): NativeToolView {
|
|
1159
|
+
const body = parsed.locations.map(location => {
|
|
1160
|
+
const file = plainText(location.file);
|
|
1161
|
+
const context = location.context.map(line => ({ ...line, text: plainText(line.text) }));
|
|
1162
|
+
const range = `:${location.line}:${location.col}`;
|
|
1163
|
+
const code = numberedCode(context, { path: file });
|
|
1164
|
+
const header = fileRow(displayPath(file), { range, title: file });
|
|
1165
|
+
return keyed(col(code ? [header, code] : [header], { gap: "xs" }), `${file}${range}`);
|
|
1166
|
+
});
|
|
1167
|
+
return {
|
|
1168
|
+
tool: lspNativeHead(request, fallbackAction, [formatCount(parsed.noun, parsed.count)]),
|
|
1169
|
+
tone: parsed.count > 0 ? undefined : "warning",
|
|
1170
|
+
inline: true,
|
|
1171
|
+
body: body.length > 0 ? body : undefined,
|
|
1172
|
+
preview: { lines: PREVIEW_LIMITS.COLLAPSED_ITEMS },
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1002
1176
|
function describeLspResult(result: ToolRenderResult<LspToolDetails>, args: LspParams | undefined): NativeToolView {
|
|
1003
1177
|
const request = args ?? result.details?.request;
|
|
1004
1178
|
const fallbackAction = result.details?.action ?? "request";
|
|
1179
|
+
const action = request?.action ?? result.details?.action;
|
|
1005
1180
|
const content = result.content?.[0];
|
|
1006
1181
|
const text = content?.type === "text" ? (content.text ?? "") : "";
|
|
1007
1182
|
if (result.isError) return inlineErrorView(lspNativeHead(request, fallbackAction), text || "LSP request failed");
|
|
1008
1183
|
if (!text) return { tool: lspNativeHead(request, fallbackAction, ["No result"]), tone: "warning", inline: true };
|
|
1009
1184
|
|
|
1010
1185
|
const lines = text.split("\n");
|
|
1186
|
+
const locations = parseLspLocations(lines);
|
|
1187
|
+
if (locations) return describeLspLocations(request, fallbackAction, locations);
|
|
1188
|
+
|
|
1011
1189
|
const statusError = activeThemeSymbol("status.error");
|
|
1012
1190
|
const refMatch = text.match(/(\d+)\s+reference\(s\)/);
|
|
1013
1191
|
const symbolsMatch = text.match(/Symbols in (.+):/);
|
|
@@ -1017,7 +1195,7 @@ function describeLspResult(result: ToolRenderResult<LspToolDetails>, args: LspPa
|
|
|
1017
1195
|
}
|
|
1018
1196
|
if (
|
|
1019
1197
|
/\d+\s+(?:error|warning)\(s\)/.test(text) ||
|
|
1020
|
-
|
|
1198
|
+
hasStatusRow(action, lines, statusError) ||
|
|
1021
1199
|
(request?.action ?? fallbackAction) === "diagnostics"
|
|
1022
1200
|
) {
|
|
1023
1201
|
return describeLspDiagnostics(request, fallbackAction, lines);
|
|
@@ -1042,8 +1220,8 @@ function describeLspResult(result: ToolRenderResult<LspToolDetails>, args: LspPa
|
|
|
1042
1220
|
preview: { lines: 8 },
|
|
1043
1221
|
};
|
|
1044
1222
|
}
|
|
1045
|
-
const hasError = text.includes("Error:") ||
|
|
1046
|
-
const hasSuccess =
|
|
1223
|
+
const hasError = text.includes("Error:") || hasStatusRow(action, lines, statusError);
|
|
1224
|
+
const hasSuccess = hasStatusRow(action, lines, activeThemeSymbol("status.success")) || text.includes("Applied");
|
|
1047
1225
|
return {
|
|
1048
1226
|
tool: lspNativeHead(request, fallbackAction),
|
|
1049
1227
|
tone: hasError && !hasSuccess ? "error" : undefined,
|
|
@@ -8,6 +8,8 @@ import type { NativeToolHead, NativeToolView, ToolRenderResult } from "./rendere
|
|
|
8
8
|
export declare function displayPath(filePath: string): string;
|
|
9
9
|
/** Configured file link for a head's path target, when the path is absolute. */
|
|
10
10
|
export declare function fileHref(filePath: string | undefined): string | undefined;
|
|
11
|
+
/** Link for a head target that is a web URL (`www.` gains `https://`), else undefined. */
|
|
12
|
+
export declare function urlHref(target: string | undefined): string | undefined;
|
|
11
13
|
/** Diff stats as one head `meta` string, `+8 −1` (U+2212 minus), or undefined when nothing changed. */
|
|
12
14
|
export declare function diffStatsMeta(added: number, removed: number): string | undefined;
|
|
13
15
|
/**
|
package/src/tools/native-view.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { TspSpan, TspText, TspTone } from "@linxiraos/pi-wire";
|
|
|
8
8
|
import { ansi, code, compact, keyed, node, row, span, text } from "../native/describe";
|
|
9
9
|
import type { NativeChild, NativeNode } from "../native/node";
|
|
10
10
|
import { tryFileUri } from "../render/hyperlink";
|
|
11
|
-
import { type ParsedDiagnostic, parseDiagnosticMessage, shortenPath } from "../render/render-utils";
|
|
11
|
+
import { type ParsedDiagnostic, parseDiagnosticMessage, pathNameStart, shortenPath } from "../render/render-utils";
|
|
12
12
|
import { plainText } from "../native/spans";
|
|
13
13
|
import type { FileDiagnosticsResult } from "./lsp";
|
|
14
14
|
import { formatArtifactErrorNotice, formatTruncationMetaNotice, type OutputMeta } from "./output-meta";
|
|
@@ -28,6 +28,13 @@ export function fileHref(filePath: string | undefined): string | undefined {
|
|
|
28
28
|
return filePath && path.isAbsolute(filePath) ? tryFileUri(filePath) : undefined;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/** Link for a head target that is a web URL (`www.` gains `https://`), else undefined. */
|
|
32
|
+
export function urlHref(target: string | undefined): string | undefined {
|
|
33
|
+
if (!target) return undefined;
|
|
34
|
+
const candidate = /^www\./i.test(target) ? `https://${target}` : target;
|
|
35
|
+
return /^https?:\/\/\S+$/i.test(candidate) ? candidate : undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
/** Diff stats as one head `meta` string, `+8 −1` (U+2212 minus), or undefined when nothing changed. */
|
|
32
39
|
export function diffStatsMeta(added: number, removed: number): string | undefined {
|
|
33
40
|
const parts: string[] = [];
|
|
@@ -74,11 +81,10 @@ export function fileRow(
|
|
|
74
81
|
} = {},
|
|
75
82
|
): NativeNode {
|
|
76
83
|
const isDir = filePath.endsWith("/");
|
|
77
|
-
const
|
|
78
|
-
const cut = bare.lastIndexOf("/") + 1;
|
|
84
|
+
const cut = pathNameStart(filePath);
|
|
79
85
|
const spans: TspSpan[] = [];
|
|
80
|
-
if (cut > 0) spans.push(span(
|
|
81
|
-
spans.push(span(
|
|
86
|
+
if (cut > 0) spans.push(span(filePath.slice(0, cut), "dim"));
|
|
87
|
+
spans.push(span(filePath.slice(cut) || "…", "strong", p.href ? { href: p.href } : undefined));
|
|
82
88
|
if (p.range) spans.push(span(p.range, "muted"));
|
|
83
89
|
const children: NativeChild[] = [
|
|
84
90
|
p.lead ?? node("icon", { name: p.icon ?? (isDir ? "folder" : "file"), tone: p.tone }),
|
|
@@ -100,8 +100,21 @@ export interface LimitsMeta {
|
|
|
100
100
|
last: number;
|
|
101
101
|
};
|
|
102
102
|
selectorBase?: string;
|
|
103
|
+
/** The first cut line exceeds what one `:raw` read returns; that read stops at this many bytes. */
|
|
104
|
+
rawByteCap?: number;
|
|
103
105
|
};
|
|
104
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* The bash minimizer rewrote this output: `filter` is the native filter label
|
|
109
|
+
* (`chain` for a minimized `&&`/`;` chain), the byte counts are the raw capture
|
|
110
|
+
* and the minimized text, and `artifactId` holds the raw capture.
|
|
111
|
+
*/
|
|
112
|
+
export interface MinimizedMeta {
|
|
113
|
+
filter: string;
|
|
114
|
+
inputBytes: number;
|
|
115
|
+
outputBytes: number;
|
|
116
|
+
artifactId: string;
|
|
117
|
+
}
|
|
105
118
|
/**
|
|
106
119
|
* Structured metadata for tool outputs.
|
|
107
120
|
*/
|
|
@@ -114,6 +127,7 @@ export interface OutputMeta {
|
|
|
114
127
|
pagedSource?: true;
|
|
115
128
|
diagnostics?: DiagnosticMeta;
|
|
116
129
|
limits?: LimitsMeta;
|
|
130
|
+
minimized?: MinimizedMeta;
|
|
117
131
|
}
|
|
118
132
|
/**
|
|
119
133
|
* Reformat pre-formatted diagnostic messages into a multi-level, prefix-folded
|
|
@@ -136,6 +150,13 @@ export declare function stripRawOutputArtifactNotice(text: string): {
|
|
|
136
150
|
text: string;
|
|
137
151
|
artifactId?: string;
|
|
138
152
|
};
|
|
153
|
+
/** Whether `line` is the column-cap notice {@link formatOutputNotice} emits (`[Some lines truncated to 768 chars…]`). */
|
|
154
|
+
export declare function isColumnTruncationNotice(line: string): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Whether the bracketed notice `line` carries the column-cap clause: alone, or after the parts
|
|
157
|
+
* {@link formatOutputNotice} joins before it (`[Showing lines 1-4 of 5. … Some lines truncated to 768 chars…]`).
|
|
158
|
+
*/
|
|
159
|
+
export declare function hasColumnTruncationClause(line: string): boolean;
|
|
139
160
|
/** Remove a trailing generated output notice when metadata is unavailable. */
|
|
140
161
|
export declare function stripGeneratedOutputNotice(text: string): string;
|
|
141
162
|
/** Format truncation ranges and recovery hints. */
|
|
@@ -147,6 +168,12 @@ export declare function formatTruncationMetaNotice(truncation: TruncationMeta, s
|
|
|
147
168
|
export declare function formatStyledArtifactReference(artifactId: string, theme: Theme): string;
|
|
148
169
|
/** Describe an incomplete artifact capture. */
|
|
149
170
|
export declare function formatArtifactErrorNotice(error: OutputArtifactError): string;
|
|
171
|
+
/**
|
|
172
|
+
* `git 120.4KB → 3.2KB`: the minimizer filter that ran and the bytes it took the output from and to.
|
|
173
|
+
* Native labels are short words; a rehydrated session or extension may carry any text, so the label
|
|
174
|
+
* is sanitized to one plain line, its home paths shortened to `~`, and width-bounded.
|
|
175
|
+
*/
|
|
176
|
+
export declare function formatMinimizedMeta(minimized: MinimizedMeta): string;
|
|
150
177
|
/**
|
|
151
178
|
* Format notices from OutputMeta for LLM consumption.
|
|
152
179
|
* Returns empty string if no notices needed.
|
package/src/tools/output-meta.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { Theme } from "../theme/theme";
|
|
2
|
-
import {
|
|
2
|
+
import { sanitizeText } from "@linxiraos/pi-utils";
|
|
3
|
+
import {
|
|
4
|
+
flattenLine,
|
|
5
|
+
formatBytes,
|
|
6
|
+
shortenEmbeddedPaths,
|
|
7
|
+
TRUNCATE_LENGTHS,
|
|
8
|
+
truncateToWidth,
|
|
9
|
+
wrapBrackets,
|
|
10
|
+
} from "../render/render-utils";
|
|
3
11
|
import type { OutputArtifactError } from "./streaming-output";
|
|
4
12
|
import { formatGroupedFiles } from "./grouped-file-output";
|
|
5
13
|
|
|
@@ -76,9 +84,23 @@ export interface LimitsMeta {
|
|
|
76
84
|
artifactElidedBytes?: number;
|
|
77
85
|
lines?: { first: number; last: number };
|
|
78
86
|
selectorBase?: string;
|
|
87
|
+
/** The first cut line exceeds what one `:raw` read returns; that read stops at this many bytes. */
|
|
88
|
+
rawByteCap?: number;
|
|
79
89
|
};
|
|
80
90
|
}
|
|
81
91
|
|
|
92
|
+
/**
|
|
93
|
+
* The bash minimizer rewrote this output: `filter` is the native filter label
|
|
94
|
+
* (`chain` for a minimized `&&`/`;` chain), the byte counts are the raw capture
|
|
95
|
+
* and the minimized text, and `artifactId` holds the raw capture.
|
|
96
|
+
*/
|
|
97
|
+
export interface MinimizedMeta {
|
|
98
|
+
filter: string;
|
|
99
|
+
inputBytes: number;
|
|
100
|
+
outputBytes: number;
|
|
101
|
+
artifactId: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
82
104
|
/**
|
|
83
105
|
* Structured metadata for tool outputs.
|
|
84
106
|
*/
|
|
@@ -91,6 +113,7 @@ export interface OutputMeta {
|
|
|
91
113
|
pagedSource?: true;
|
|
92
114
|
diagnostics?: DiagnosticMeta;
|
|
93
115
|
limits?: LimitsMeta;
|
|
116
|
+
minimized?: MinimizedMeta;
|
|
94
117
|
}
|
|
95
118
|
|
|
96
119
|
// Regex: split on the first `:digits:digits` boundary to separate path from the rest
|
|
@@ -202,6 +225,33 @@ export function stripRawOutputArtifactNotice(text: string): { text: string; arti
|
|
|
202
225
|
return artifactId === undefined ? { text } : { text: stripped, artifactId };
|
|
203
226
|
}
|
|
204
227
|
|
|
228
|
+
/** The column-cap clause {@link formatOutputNotice} puts in a notice, alone or after other parts. */
|
|
229
|
+
const COLUMN_TRUNCATION_CLAUSE = "Some lines truncated to ";
|
|
230
|
+
/**
|
|
231
|
+
* The rest of the clause as {@link formatOutputNotice} writes it: the cap as JavaScript prints a
|
|
232
|
+
* finite number (the setting takes any, `768.5` included), its unit, then a `. ` suffix or the bracket.
|
|
233
|
+
*/
|
|
234
|
+
const COLUMN_TRUNCATION_TAIL = String.raw`-?\d+(?:\.\d+)?(?:e[+-]\d+)? (?:chars|bytes)(?:\. .*)?\]$`;
|
|
235
|
+
const COLUMN_TRUNCATION_NOTICE = new RegExp(String.raw`^\[${COLUMN_TRUNCATION_CLAUSE}${COLUMN_TRUNCATION_TAIL}`, "u");
|
|
236
|
+
const COLUMN_TRUNCATION_IN_NOTICE = new RegExp(
|
|
237
|
+
String.raw`^\[.*\. ${COLUMN_TRUNCATION_CLAUSE}${COLUMN_TRUNCATION_TAIL}`,
|
|
238
|
+
"u",
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
/** Whether `line` is the column-cap notice {@link formatOutputNotice} emits (`[Some lines truncated to 768 chars…]`). */
|
|
242
|
+
export function isColumnTruncationNotice(line: string): boolean {
|
|
243
|
+
return COLUMN_TRUNCATION_NOTICE.test(line.trim());
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Whether the bracketed notice `line` carries the column-cap clause: alone, or after the parts
|
|
248
|
+
* {@link formatOutputNotice} joins before it (`[Showing lines 1-4 of 5. … Some lines truncated to 768 chars…]`).
|
|
249
|
+
*/
|
|
250
|
+
export function hasColumnTruncationClause(line: string): boolean {
|
|
251
|
+
const trimmed = line.trim();
|
|
252
|
+
return COLUMN_TRUNCATION_NOTICE.test(trimmed) || COLUMN_TRUNCATION_IN_NOTICE.test(trimmed);
|
|
253
|
+
}
|
|
254
|
+
|
|
205
255
|
function isGeneratedOutputNoticeLine(line: string): boolean {
|
|
206
256
|
if (!line.startsWith("[") || !line.endsWith("]")) return false;
|
|
207
257
|
const body = line.slice(1, -1);
|
|
@@ -209,7 +259,7 @@ function isGeneratedOutputNoticeLine(line: string): boolean {
|
|
|
209
259
|
body.startsWith("Showing ") ||
|
|
210
260
|
/^\d+ matches limit reached\. Use limit=\d+ for more/u.test(body) ||
|
|
211
261
|
/^\d+ results limit reached(?:\.|$)/u.test(body) ||
|
|
212
|
-
|
|
262
|
+
isColumnTruncationNotice(line)
|
|
213
263
|
);
|
|
214
264
|
}
|
|
215
265
|
|
|
@@ -297,6 +347,17 @@ export function formatArtifactErrorNotice(error: OutputArtifactError): string {
|
|
|
297
347
|
return `Full output was not saved completely (artifact ${error} failed)`;
|
|
298
348
|
}
|
|
299
349
|
|
|
350
|
+
/**
|
|
351
|
+
* `git 120.4KB → 3.2KB`: the minimizer filter that ran and the bytes it took the output from and to.
|
|
352
|
+
* Native labels are short words; a rehydrated session or extension may carry any text, so the label
|
|
353
|
+
* is sanitized to one plain line, its home paths shortened to `~`, and width-bounded.
|
|
354
|
+
*/
|
|
355
|
+
export function formatMinimizedMeta(minimized: MinimizedMeta): string {
|
|
356
|
+
const label = shortenEmbeddedPaths(flattenLine(sanitizeText(minimized.filter)));
|
|
357
|
+
const filter = truncateToWidth(label, TRUNCATE_LENGTHS.SHORT);
|
|
358
|
+
return `${filter} ${formatBytes(minimized.inputBytes)} → ${formatBytes(minimized.outputBytes)}`;
|
|
359
|
+
}
|
|
360
|
+
|
|
300
361
|
/**
|
|
301
362
|
* Format notices from OutputMeta for LLM consumption.
|
|
302
363
|
* Returns empty string if no notices needed.
|
|
@@ -340,14 +401,17 @@ export function formatOutputNotice(meta: OutputMeta | undefined): string {
|
|
|
340
401
|
// notices always read "chars", so default missing units to it. Otherwise
|
|
341
402
|
// a resumed legacy session renders "… 768 undefined" and stripOutputNotice
|
|
342
403
|
// stops matching the persisted "… 768 chars" text.
|
|
343
|
-
let columnNotice =
|
|
404
|
+
let columnNotice = `${COLUMN_TRUNCATION_CLAUSE}${c.maxColumn} ${c.unit ?? "chars"}`;
|
|
344
405
|
// An artifact cut to a head/tail sample renumbers its lines, so only a complete one names a line.
|
|
345
406
|
const selectorBase =
|
|
346
407
|
c.selectorBase ?? (c.artifactId != null && !c.artifactElidedBytes ? `artifact://${c.artifactId}` : undefined);
|
|
347
408
|
if (c.lines && selectorBase !== undefined) {
|
|
348
409
|
// One line per selector: a span of cut lines can exceed what one read returns.
|
|
349
410
|
const { first, last } = c.lines;
|
|
350
|
-
columnNotice +=
|
|
411
|
+
columnNotice +=
|
|
412
|
+
c.rawByteCap === undefined
|
|
413
|
+
? `. Use ${selectorBase}:raw:${first}-${first} to read line ${first} whole`
|
|
414
|
+
: `. Use ${selectorBase}:raw:${first}-${first} to read line ${first} uncut, byte-capped at ${formatBytes(c.rawByteCap)}`;
|
|
351
415
|
if (last > first) columnNotice += `; cut lines run to line ${last}, each read the same way`;
|
|
352
416
|
} else if (c.artifactId != null) {
|
|
353
417
|
columnNotice += `. ${formatFullOutputReference(c.artifactId, c.artifactElidedBytes)}`;
|