@oh-my-pi/pi-tui 18.12.3 → 18.12.4
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 +27 -48
- package/dist/types/render/output-block.d.ts +2 -0
- package/dist/types/render/tool-card.d.ts +2 -0
- package/dist/types/terminal-capabilities.d.ts +5 -0
- package/dist/types/tools/bash.d.ts +2 -0
- package/dist/types/tools/default-renderer.d.ts +3 -0
- package/dist/types/tools/eval.d.ts +9 -8
- package/dist/types/tools/json-tree.d.ts +2 -0
- package/dist/types/tools/line-ranges.d.ts +8 -1
- package/dist/types/tools/mcp.d.ts +23 -0
- package/dist/types/tools/read.d.ts +8 -2
- package/dist/types/tools/renderer.d.ts +8 -2
- package/dist/types/tools/result-card.d.ts +1 -1
- package/package.json +9 -9
- package/src/chat/tool-execution.ts +35 -0
- package/src/chrome/transcript-container.ts +85 -12
- package/src/components/markdown.ts +11 -3
- package/src/native/backend.ts +25 -5
- package/src/overlays/jobs-panel.ts +14 -2
- package/src/render/output-block.ts +25 -12
- package/src/render/tool-card.ts +6 -0
- package/src/terminal-capabilities.ts +39 -2
- package/src/tools/bash.ts +25 -9
- package/src/tools/default-renderer.ts +54 -17
- package/src/tools/eval.ts +32 -14
- package/src/tools/find.ts +4 -5
- package/src/tools/glob.ts +4 -6
- package/src/tools/grep.ts +4 -6
- package/src/tools/json-tree.ts +8 -0
- package/src/tools/line-ranges.ts +23 -13
- package/src/tools/mcp.ts +44 -1
- package/src/tools/read.ts +64 -21
- package/src/tools/renderer.ts +8 -2
- package/src/tools/result-card.ts +1 -2
- package/src/tools/wait.ts +208 -123
package/src/tools/find.ts
CHANGED
|
@@ -256,7 +256,7 @@ export const findToolRenderer = {
|
|
|
256
256
|
},
|
|
257
257
|
uiTheme,
|
|
258
258
|
);
|
|
259
|
-
return new Text(text,
|
|
259
|
+
return new Text(text, 0, 0);
|
|
260
260
|
},
|
|
261
261
|
|
|
262
262
|
renderResult(
|
|
@@ -269,7 +269,7 @@ export const findToolRenderer = {
|
|
|
269
269
|
const text = result.content?.find(c => c.type === "text")?.text ?? "";
|
|
270
270
|
|
|
271
271
|
if (result.isError) {
|
|
272
|
-
return new Text(formatErrorMessage(text || "Unknown error", uiTheme),
|
|
272
|
+
return new Text(formatErrorMessage(text || "Unknown error", uiTheme), 0, 0);
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
// Streaming progress: the tool reports the phase it is in.
|
|
@@ -285,7 +285,7 @@ export const findToolRenderer = {
|
|
|
285
285
|
},
|
|
286
286
|
uiTheme,
|
|
287
287
|
);
|
|
288
|
-
return new Text(header,
|
|
288
|
+
return new Text(header, 0, 0);
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
const { hits, stats, threshold } = details;
|
|
@@ -317,7 +317,7 @@ export const findToolRenderer = {
|
|
|
317
317
|
: "No relevant passages found";
|
|
318
318
|
const lines = [header, formatEmptyMessage(empty, uiTheme)];
|
|
319
319
|
for (const failure of stats.failures) lines.push(uiTheme.fg("warning", failure));
|
|
320
|
-
return new Text(lines.join("\n"),
|
|
320
|
+
return new Text(lines.join("\n"), 0, 0);
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
const header = renderStatusLine(
|
|
@@ -359,7 +359,6 @@ export const findToolRenderer = {
|
|
|
359
359
|
}
|
|
360
360
|
return [header, ...hitLines, ...extra].map(line => truncateToWidth(line, width, Ellipsis.Omit));
|
|
361
361
|
},
|
|
362
|
-
{ paddingX: 1 },
|
|
363
362
|
);
|
|
364
363
|
},
|
|
365
364
|
describeCall(args: FindRenderArgs): NativeToolView {
|
package/src/tools/glob.ts
CHANGED
|
@@ -151,7 +151,7 @@ export const globToolRenderer = {
|
|
|
151
151
|
},
|
|
152
152
|
uiTheme,
|
|
153
153
|
);
|
|
154
|
-
return new Text(text,
|
|
154
|
+
return new Text(text, 0, 0);
|
|
155
155
|
},
|
|
156
156
|
|
|
157
157
|
renderResult(
|
|
@@ -165,7 +165,7 @@ export const globToolRenderer = {
|
|
|
165
165
|
|
|
166
166
|
if (result.isError || details?.error) {
|
|
167
167
|
const errorText = details?.error || result.content?.find(c => c.type === "text")?.text || "Unknown error";
|
|
168
|
-
return new Text(formatErrorMessage(errorText, uiTheme),
|
|
168
|
+
return new Text(formatErrorMessage(errorText, uiTheme), 0, 0);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
const hasDetailedData = details?.fileCount !== undefined;
|
|
@@ -178,7 +178,7 @@ export const globToolRenderer = {
|
|
|
178
178
|
textContent.includes("No files found") ||
|
|
179
179
|
textContent.trim() === ""
|
|
180
180
|
) {
|
|
181
|
-
return new Text(formatEmptyMessage("No files found", uiTheme),
|
|
181
|
+
return new Text(formatEmptyMessage("No files found", uiTheme), 0, 0);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
const lines = textContent.split("\n").filter(l => l.trim());
|
|
@@ -207,7 +207,6 @@ export const globToolRenderer = {
|
|
|
207
207
|
);
|
|
208
208
|
return [header, ...listLines].map(l => truncateToWidth(l, width, Ellipsis.Omit));
|
|
209
209
|
},
|
|
210
|
-
{ paddingX: 1 },
|
|
211
210
|
);
|
|
212
211
|
}
|
|
213
212
|
|
|
@@ -244,7 +243,7 @@ export const globToolRenderer = {
|
|
|
244
243
|
);
|
|
245
244
|
const lines = [header, formatEmptyMessage(emptyLabel, uiTheme)];
|
|
246
245
|
if (missingNote) lines.push(missingNote);
|
|
247
|
-
return new Text(lines.join("\n"),
|
|
246
|
+
return new Text(lines.join("\n"), 0, 0);
|
|
248
247
|
}
|
|
249
248
|
const meta: string[] = [formatCount("file", fileCount)];
|
|
250
249
|
if (details?.scopePath) meta.push(`in ${details.scopePath}`);
|
|
@@ -298,7 +297,6 @@ export const globToolRenderer = {
|
|
|
298
297
|
);
|
|
299
298
|
return [header, ...fileLines, ...extraLines].map(l => truncateToWidth(l, width, Ellipsis.Omit));
|
|
300
299
|
},
|
|
301
|
-
{ paddingX: 1 },
|
|
302
300
|
);
|
|
303
301
|
},
|
|
304
302
|
describeCall(args: GlobRenderArgs): NativeToolView {
|
package/src/tools/grep.ts
CHANGED
|
@@ -364,7 +364,7 @@ export const grepToolRenderer = {
|
|
|
364
364
|
{ icon: "pending", title: "Grep", titleColor: "toolTitle", description: args.pattern || "?", meta },
|
|
365
365
|
uiTheme,
|
|
366
366
|
);
|
|
367
|
-
return new Text(text,
|
|
367
|
+
return new Text(text, 0, 0);
|
|
368
368
|
},
|
|
369
369
|
|
|
370
370
|
renderResult(
|
|
@@ -377,7 +377,7 @@ export const grepToolRenderer = {
|
|
|
377
377
|
|
|
378
378
|
if (result.isError || details?.error) {
|
|
379
379
|
const errorText = details?.error || result.content?.find(c => c.type === "text")?.text || "Unknown error";
|
|
380
|
-
return new Text(formatErrorMessage(errorText, uiTheme),
|
|
380
|
+
return new Text(formatErrorMessage(errorText, uiTheme), 0, 0);
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
const hasDetailedData = details?.matchCount !== undefined || details?.fileCount !== undefined;
|
|
@@ -385,7 +385,7 @@ export const grepToolRenderer = {
|
|
|
385
385
|
if (!hasDetailedData) {
|
|
386
386
|
const textContent = result.details?.displayContent ?? result.content?.find(c => c.type === "text")?.text;
|
|
387
387
|
if (!textContent || textContent === "No matches found") {
|
|
388
|
-
return new Text(formatEmptyMessage("No matches found", uiTheme),
|
|
388
|
+
return new Text(formatEmptyMessage("No matches found", uiTheme), 0, 0);
|
|
389
389
|
}
|
|
390
390
|
const lines = textContent.split("\n").filter(line => line.trim() !== "");
|
|
391
391
|
const description = args?.pattern ?? undefined;
|
|
@@ -415,7 +415,6 @@ export const grepToolRenderer = {
|
|
|
415
415
|
);
|
|
416
416
|
return [header, ...listLines].map(l => truncateToWidth(l, width, Ellipsis.Omit));
|
|
417
417
|
},
|
|
418
|
-
{ paddingX: 1 },
|
|
419
418
|
);
|
|
420
419
|
}
|
|
421
420
|
const linkTargets = grepLinkTargets(details, options.renderContext?.rawDetails);
|
|
@@ -442,7 +441,7 @@ export const grepToolRenderer = {
|
|
|
442
441
|
);
|
|
443
442
|
const lines = [header, formatEmptyMessage("No matches found", uiTheme)];
|
|
444
443
|
if (missingNote) lines.push(missingNote);
|
|
445
|
-
return new Text(lines.join("\n"),
|
|
444
|
+
return new Text(lines.join("\n"), 0, 0);
|
|
446
445
|
}
|
|
447
446
|
|
|
448
447
|
const summaryParts = [formatCount("match", matchCount), formatCount("file", fileCount)];
|
|
@@ -500,7 +499,6 @@ export const grepToolRenderer = {
|
|
|
500
499
|
);
|
|
501
500
|
return [header, ...matchLines, ...extraLines].map(l => truncateToWidth(l, width, Ellipsis.Omit));
|
|
502
501
|
},
|
|
503
|
-
{ paddingX: 1 },
|
|
504
502
|
);
|
|
505
503
|
},
|
|
506
504
|
describeCall(args: GrepRenderArgs): NativeToolView {
|
package/src/tools/json-tree.ts
CHANGED
|
@@ -402,6 +402,8 @@ export interface JsonTreeDescribeOptions {
|
|
|
402
402
|
openDepth?: number;
|
|
403
403
|
/** Root object keys omitted. Defaults to internal tool argument metadata. */
|
|
404
404
|
hiddenRootKeys?: readonly string[];
|
|
405
|
+
/** Called after the tree is built if a depth, node or scalar cap left part of the value out. */
|
|
406
|
+
onTruncated?: () => void;
|
|
405
407
|
}
|
|
406
408
|
|
|
407
409
|
type JsonEntry = readonly [key: string, value: unknown];
|
|
@@ -438,6 +440,7 @@ export function describeJsonTree(value: unknown, options: JsonTreeDescribeOption
|
|
|
438
440
|
const maxScalarLen = Math.max(1, options.maxScalarLen ?? JSON_TREE_SCALAR_LEN_EXPANDED);
|
|
439
441
|
const openDepth = options.openDepth ?? JSON_TREE_MAX_DEPTH_COLLAPSED;
|
|
440
442
|
let budget = Math.max(1, options.maxNodes ?? JSON_TREE_MAX_LINES_EXPANDED);
|
|
443
|
+
let truncated = false;
|
|
441
444
|
let nextId = 0;
|
|
442
445
|
const leaf = (label: readonly TspSpan[]): TspTreeNode => ({ id: `${nextId++}`, label });
|
|
443
446
|
|
|
@@ -445,6 +448,7 @@ export function describeJsonTree(value: unknown, options: JsonTreeDescribeOption
|
|
|
445
448
|
const out: TspTreeNode[] = [];
|
|
446
449
|
for (let index = 0; index < entries.length; index++) {
|
|
447
450
|
if (budget <= 0) {
|
|
451
|
+
truncated = true;
|
|
448
452
|
out.push(leaf([span(`… ${entries.length - index} more`, "dim")]));
|
|
449
453
|
break;
|
|
450
454
|
}
|
|
@@ -463,17 +467,20 @@ export function describeJsonTree(value: unknown, options: JsonTreeDescribeOption
|
|
|
463
467
|
const size = Array.isArray(entry) ? `[${entry.length}]` : `{${entries.length}}`;
|
|
464
468
|
const label = keySpans.length > 0 ? [...keySpans, span(` ${size}`, "dim")] : [span(size, "dim")];
|
|
465
469
|
if (entries.length === 0) return { id, label };
|
|
470
|
+
if (depth >= maxDepth) truncated = true;
|
|
466
471
|
const children = depth >= maxDepth ? [leaf([span("…", "dim")])] : describeEntries(entries, depth + 1);
|
|
467
472
|
return { id, label, open: depth < openDepth, children };
|
|
468
473
|
}
|
|
469
474
|
const prefix = keySpans.length > 0 ? [...keySpans, span(": ", "muted")] : [];
|
|
470
475
|
if (typeof entry === "string") {
|
|
471
476
|
const lines = plainText(entry).split("\n");
|
|
477
|
+
if (lines.some(line => line.length > maxScalarLen)) truncated = true;
|
|
472
478
|
const first = clipScalar(lines[0], maxScalarLen);
|
|
473
479
|
if (lines.length === 1) return { id, label: [...prefix, span(`"${first}"`, "syntaxString")] };
|
|
474
480
|
const children: TspTreeNode[] = [];
|
|
475
481
|
for (let index = 0; index < lines.length; index++) {
|
|
476
482
|
if (budget <= 0) {
|
|
483
|
+
truncated = true;
|
|
477
484
|
children.push(leaf([span(`… ${lines.length - index} more lines`, "dim")]));
|
|
478
485
|
break;
|
|
479
486
|
}
|
|
@@ -499,5 +506,6 @@ export function describeJsonTree(value: unknown, options: JsonTreeDescribeOption
|
|
|
499
506
|
} else {
|
|
500
507
|
nodes = [describeValue(undefined, value, 0)];
|
|
501
508
|
}
|
|
509
|
+
if (truncated) options.onTruncated?.();
|
|
502
510
|
return node("tree", { nodes });
|
|
503
511
|
}
|
package/src/tools/line-ranges.ts
CHANGED
|
@@ -49,16 +49,19 @@ function parseChunk(sel: string, pinBare: boolean): LineRange | null {
|
|
|
49
49
|
return { startLine: rawStart, endLine: rawEnd };
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/** What a bare `N` selects in a one-chunk list: lines `N` onward (`:50`), or the single line `N`. */
|
|
53
|
+
export type BareLineMode = "onward" | "single";
|
|
54
|
+
|
|
52
55
|
/**
|
|
53
56
|
* Parse a comma-separated list of line ranges (e.g. `5-16,960-973` or `19,59`). Returns
|
|
54
57
|
* the ranges in ascending order with overlapping/adjacent ranges merged so
|
|
55
58
|
* downstream consumers can stream the file in a single forward pass per range.
|
|
56
59
|
*/
|
|
57
|
-
export function parseLineRanges(sel: string): [LineRange, ...LineRange[]] | null {
|
|
60
|
+
export function parseLineRanges(sel: string, bare: BareLineMode = "onward"): [LineRange, ...LineRange[]] | null {
|
|
58
61
|
const chunks = sel.split(",");
|
|
59
|
-
// A lone `:50` means "from line 50". Inside a comma list,
|
|
60
|
-
// that one line; otherwise `:19,59` collapses to "from 19 through EOF".
|
|
61
|
-
const pinBare = chunks.length > 1;
|
|
62
|
+
// A lone `:50` means "from line 50" unless `bare` pins it. Inside a comma list,
|
|
63
|
+
// a bare number is that one line; otherwise `:19,59` collapses to "from 19 through EOF".
|
|
64
|
+
const pinBare = bare === "single" || chunks.length > 1;
|
|
62
65
|
const parsed: LineRange[] = [];
|
|
63
66
|
for (const chunk of chunks) {
|
|
64
67
|
const range = parseChunk(chunk, pinBare);
|
|
@@ -66,14 +69,19 @@ export function parseLineRanges(sel: string): [LineRange, ...LineRange[]] | null
|
|
|
66
69
|
parsed.push(range);
|
|
67
70
|
}
|
|
68
71
|
if (parsed.length === 0) return null;
|
|
69
|
-
parsed
|
|
72
|
+
return mergeLineRanges(parsed);
|
|
73
|
+
}
|
|
70
74
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Sort non-empty `ranges` by start line and merge the ones that overlap or touch;
|
|
77
|
+
* an open-ended range (`endLine` undefined) reaches EOF and absorbs every later one.
|
|
78
|
+
*/
|
|
79
|
+
export function mergeLineRanges(ranges: readonly LineRange[]): [LineRange, ...LineRange[]] {
|
|
80
|
+
const [first, ...rest] = [...ranges].sort((a, b) => a.startLine - b.startLine);
|
|
81
|
+
const merged: [LineRange, ...LineRange[]] = [first];
|
|
82
|
+
for (const current of rest) {
|
|
74
83
|
const last = merged[merged.length - 1];
|
|
75
|
-
|
|
76
|
-
if (last.endLine === undefined) continue;
|
|
84
|
+
if (last.endLine === undefined) break;
|
|
77
85
|
// Merge when current starts within (or immediately after) the last range.
|
|
78
86
|
if (current.startLine <= last.endLine + 1) {
|
|
79
87
|
if (current.endLine === undefined || current.endLine > last.endLine) {
|
|
@@ -83,7 +91,7 @@ export function parseLineRanges(sel: string): [LineRange, ...LineRange[]] | null
|
|
|
83
91
|
}
|
|
84
92
|
merged.push(current);
|
|
85
93
|
}
|
|
86
|
-
return merged
|
|
94
|
+
return merged;
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
/**
|
|
@@ -98,10 +106,12 @@ export function parseLineRanges(sel: string): [LineRange, ...LineRange[]] | null
|
|
|
98
106
|
*/
|
|
99
107
|
export function selectorLineRanges(sel: string | undefined): [LineRange, ...LineRange[]] | undefined {
|
|
100
108
|
if (!sel) return undefined;
|
|
101
|
-
|
|
109
|
+
const chunks = sel.split(":");
|
|
110
|
+
const bare = chunks.some(chunk => chunk.toLowerCase() === "raw") ? "single" : "onward";
|
|
111
|
+
for (const chunk of chunks) {
|
|
102
112
|
const lower = chunk.toLowerCase();
|
|
103
113
|
if (lower === "raw" || lower === "conflicts") continue;
|
|
104
|
-
const ranges = parseLineRanges(chunk);
|
|
114
|
+
const ranges = parseLineRanges(chunk, bare);
|
|
105
115
|
if (ranges) return ranges;
|
|
106
116
|
}
|
|
107
117
|
return undefined;
|
package/src/tools/mcp.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { type Component, Markdown } from "../index";
|
|
8
8
|
|
|
9
9
|
import type { NativeToolHead, NativeToolView, RenderResultOptions } from "./renderer";
|
|
10
|
+
import { isRecord, sanitizeText } from "@oh-my-pi/pi-utils";
|
|
10
11
|
import { INTENT_FIELD } from "@oh-my-pi/pi-wire";
|
|
11
12
|
import { ansi, md } from "../native/describe";
|
|
12
13
|
import type { NativeChild } from "../native/node";
|
|
@@ -26,7 +27,8 @@ import {
|
|
|
26
27
|
renderJsonTreeLines,
|
|
27
28
|
} from "./json-tree";
|
|
28
29
|
import { formatStyledTruncationWarning, stripOutputNotice } from "./output-meta";
|
|
29
|
-
import { clipCollapsed, formatExpandHint } from "../render/render-utils";
|
|
30
|
+
import { clipCollapsed, flattenLine, formatExpandHint, shortenEmbeddedPaths } from "../render/render-utils";
|
|
31
|
+
import { truncateToWidth, visibleWidth } from "../utils";
|
|
30
32
|
import { formatOutputPaneLines, styleToolOutputLine } from "../render/output-pane";
|
|
31
33
|
import type { StatusLineOptions } from "../render/status-line";
|
|
32
34
|
import { plainToolCard, type ToolCardPhase } from "../render/tool-card";
|
|
@@ -388,6 +390,45 @@ export interface MCPResourceContent {
|
|
|
388
390
|
/** Supported MCP result content blocks retained in display metadata. */
|
|
389
391
|
export type MCPContent = MCPTextContent | MCPImageContent | MCPResourceContent;
|
|
390
392
|
|
|
393
|
+
/** Server-reported progress of an in-flight MCP request. */
|
|
394
|
+
export interface MCPProgress {
|
|
395
|
+
progress: number;
|
|
396
|
+
total?: number;
|
|
397
|
+
message?: string;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Read MCP progress fields from an untrusted record: `progress` must be a
|
|
402
|
+
* finite number; `total` is kept only when finite and `message` only when a
|
|
403
|
+
* string. Shared by the transports, the Eval bridge, and the status renderer.
|
|
404
|
+
*/
|
|
405
|
+
export function parseMCPProgress(value: unknown): MCPProgress | undefined {
|
|
406
|
+
if (!isRecord(value) || typeof value.progress !== "number" || !Number.isFinite(value.progress)) return undefined;
|
|
407
|
+
const progress: MCPProgress = { progress: value.progress };
|
|
408
|
+
if (typeof value.total === "number" && Number.isFinite(value.total)) progress.total = value.total;
|
|
409
|
+
if (typeof value.message === "string") progress.message = value.message;
|
|
410
|
+
return progress;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* One-line display text for MCP progress, at most `maxWidth` cells: the
|
|
415
|
+
* message, with `progress/total` when the server reports a total. The bare
|
|
416
|
+
* progress value appears only when there is no message: without a total it is
|
|
417
|
+
* an opaque counter, not a percentage. Home paths in the message show as `~`,
|
|
418
|
+
* and a long message is cut before the count, so the count stays visible.
|
|
419
|
+
* Every progress display (tool card and both Eval status renderers) uses it.
|
|
420
|
+
*/
|
|
421
|
+
export function formatMCPProgress(progress: MCPProgress, maxWidth = 200): string {
|
|
422
|
+
const message =
|
|
423
|
+
progress.message === undefined ? "" : shortenEmbeddedPaths(flattenLine(sanitizeText(progress.message)));
|
|
424
|
+
const amount = progress.total === undefined ? `${progress.progress}` : `${progress.progress}/${progress.total}`;
|
|
425
|
+
if (!message) return truncateToWidth(amount, maxWidth);
|
|
426
|
+
if (progress.total === undefined) return truncateToWidth(message, maxWidth);
|
|
427
|
+
const suffix = ` (${amount})`;
|
|
428
|
+
const messageWidth = maxWidth - visibleWidth(suffix);
|
|
429
|
+
return messageWidth > 0 ? `${truncateToWidth(message, messageWidth)}${suffix}` : truncateToWidth(amount, maxWidth);
|
|
430
|
+
}
|
|
431
|
+
|
|
391
432
|
/** MCP result details shared by renderers and programmatic tool consumers. */
|
|
392
433
|
export interface MCPToolDetails {
|
|
393
434
|
/** Server name */
|
|
@@ -406,6 +447,8 @@ export interface MCPToolDetails {
|
|
|
406
447
|
provider?: string;
|
|
407
448
|
/** Provider display name (e.g., "Claude Code", "MCP Config") */
|
|
408
449
|
providerName?: string;
|
|
450
|
+
/** Latest progress of a running call; present only on partial updates. */
|
|
451
|
+
progress?: MCPProgress;
|
|
409
452
|
/** Structured output metadata (set by the spill wrapper when output is truncated to an artifact). */
|
|
410
453
|
meta?: OutputMeta;
|
|
411
454
|
}
|
package/src/tools/read.ts
CHANGED
|
@@ -104,11 +104,13 @@ export interface ReadToolDetails {
|
|
|
104
104
|
// Parsing also recognizes incomplete counts to explain their errors; path splitting
|
|
105
105
|
// only peels complete selectors (not a trailing `+` or `L`).
|
|
106
106
|
const RANGE_SELECTOR_CHUNK = `${LINE_RANGE_CHUNK_SOURCE}(?<=[\\d.-])`;
|
|
107
|
-
const RANGE_LIST_SRC = `${RANGE_SELECTOR_CHUNK}(?:,${RANGE_SELECTOR_CHUNK})*`;
|
|
108
107
|
// A tail selector: `-N` reads the last N lines. Keep in sync with TAIL_SELECTOR_RE.
|
|
109
108
|
const TAIL_CHUNK_SRC = String.raw`-\d+`;
|
|
110
|
-
|
|
111
|
-
const
|
|
109
|
+
// A comma list may mix ranges and tails (`1-12,-15`); a lone tail is a one-chunk list.
|
|
110
|
+
const LIST_CHUNK_SRC = `(?:${RANGE_SELECTOR_CHUNK}|${TAIL_CHUNK_SRC})`;
|
|
111
|
+
const RANGE_LIST_SRC = `${LIST_CHUNK_SRC}(?:,${LIST_CHUNK_SRC})*`;
|
|
112
|
+
const FILE_LINE_RANGE_RE = new RegExp(`^(?:${RANGE_LIST_SRC}|raw|conflicts|img)$`, "i");
|
|
113
|
+
const FILE_LINE_RANGE_ONLY_RE = new RegExp(`^(?:${RANGE_LIST_SRC})$`, "i");
|
|
112
114
|
const FILE_RAW_ONLY_RE = /^raw$/i;
|
|
113
115
|
// Permissive selector chunk for internal URLs — accepts well-formed selectors
|
|
114
116
|
// plus common malformed shapes (e.g. `:-N-M`) so the read tool peels the entire
|
|
@@ -117,8 +119,33 @@ const INTERNAL_URL_SELECTOR_PART_RE = new RegExp(
|
|
|
117
119
|
String.raw`^(?:raw|conflicts|img|${RANGE_LIST_SRC}|-\d+(?:[-+]\d+)?)$`,
|
|
118
120
|
"i",
|
|
119
121
|
);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Fold the list chunks that repeat the selector colon after a comma (`a:1-30,:-30`)
|
|
125
|
+
* into the `list` that follows them, so the pair reads as `a:1-30,-30`. Only
|
|
126
|
+
* colons at or after `minColon` count. Each chunk is tested once.
|
|
127
|
+
*/
|
|
128
|
+
function foldRepeatedListColons(basePath: string, list: string, minColon: number): { basePath: string; list: string } {
|
|
129
|
+
const chunks = [list];
|
|
130
|
+
while (basePath.endsWith(",")) {
|
|
131
|
+
const colon = basePath.lastIndexOf(":");
|
|
132
|
+
const chunk = basePath.slice(colon + 1, -1);
|
|
133
|
+
if (colon < minColon || !FILE_LINE_RANGE_ONLY_RE.test(chunk)) break;
|
|
134
|
+
chunks.push(chunk);
|
|
135
|
+
basePath = basePath.slice(0, colon);
|
|
136
|
+
}
|
|
137
|
+
return { basePath, list: chunks.reverse().join(",") };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Split a filesystem path from its trailing read selector. `foldListColons: false`
|
|
142
|
+
* keeps a colon repeated inside a list as part of the path (`a:1-30,:-30` peels
|
|
143
|
+
* only `:-30`), for callers checking whether that shorter split names a real file.
|
|
144
|
+
*/
|
|
145
|
+
export function splitPathAndSel(
|
|
146
|
+
rawPath: string,
|
|
147
|
+
options?: { foldListColons?: boolean },
|
|
148
|
+
): { path: string; sel?: string } {
|
|
122
149
|
const colon = rawPath.lastIndexOf(":");
|
|
123
150
|
if (colon <= 0) return { path: rawPath };
|
|
124
151
|
|
|
@@ -126,25 +153,33 @@ export function splitPathAndSel(rawPath: string): { path: string; sel?: string }
|
|
|
126
153
|
if (!FILE_LINE_RANGE_RE.test(candidate)) return { path: rawPath };
|
|
127
154
|
|
|
128
155
|
let basePath = rawPath.slice(0, colon);
|
|
129
|
-
let sel = candidate;
|
|
130
|
-
|
|
131
156
|
// Allow a compound trailing selector: `path:1-50:raw`, `path:raw:1-50`, or
|
|
132
|
-
// `path:raw:-60`. The two chunks must be one line
|
|
133
|
-
// `raw`, in either order.
|
|
134
|
-
|
|
135
|
-
|
|
157
|
+
// `path:raw:-60`. The two chunks must be one line list (ranges and tails)
|
|
158
|
+
// plus one `raw`, in either order.
|
|
159
|
+
let list: string | undefined;
|
|
160
|
+
let rawSuffix = "";
|
|
161
|
+
if (FILE_LINE_RANGE_ONLY_RE.test(candidate)) {
|
|
162
|
+
list = candidate;
|
|
163
|
+
} else if (FILE_RAW_ONLY_RE.test(candidate)) {
|
|
164
|
+
const innerColon = basePath.lastIndexOf(":");
|
|
136
165
|
const innerCandidate = basePath.slice(innerColon + 1);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const outerIsRange = FILE_LINE_RANGE_ONLY_RE.test(candidate);
|
|
141
|
-
if ((innerIsRaw && outerIsRange) || (innerIsRange && outerIsRaw)) {
|
|
142
|
-
sel = `${innerCandidate}:${candidate}`;
|
|
166
|
+
if (innerColon > 0 && FILE_LINE_RANGE_ONLY_RE.test(innerCandidate)) {
|
|
167
|
+
list = innerCandidate;
|
|
168
|
+
rawSuffix = `:${candidate}`;
|
|
143
169
|
basePath = basePath.slice(0, innerColon);
|
|
144
170
|
}
|
|
145
171
|
}
|
|
172
|
+
if (list === undefined) return { path: basePath, sel: candidate };
|
|
146
173
|
|
|
147
|
-
|
|
174
|
+
if (options?.foldListColons !== false) ({ basePath, list } = foldRepeatedListColons(basePath, list, 1));
|
|
175
|
+
if (!rawSuffix) {
|
|
176
|
+
const innerColon = basePath.lastIndexOf(":");
|
|
177
|
+
const innerCandidate = basePath.slice(innerColon + 1);
|
|
178
|
+
if (innerColon > 0 && FILE_RAW_ONLY_RE.test(innerCandidate)) {
|
|
179
|
+
return { path: basePath.slice(0, innerColon), sel: `${innerCandidate}:${list}` };
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return { path: basePath, sel: `${list}${rawSuffix}` };
|
|
148
183
|
}
|
|
149
184
|
|
|
150
185
|
/**
|
|
@@ -189,9 +224,17 @@ export function splitInternalUrlSel(
|
|
|
189
224
|
// Stop before crossing into the scheme separator `://`.
|
|
190
225
|
if (colon < schemeEnd) break;
|
|
191
226
|
const tail = path.slice(colon + 1);
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
227
|
+
if (INTERNAL_URL_SELECTOR_PART_RE.test(tail)) {
|
|
228
|
+
chunks.unshift(tail);
|
|
229
|
+
path = path.slice(0, colon);
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
// `artifact://7:1-30,:-30`: a list chunk ending in a comma joins the list peeled after it.
|
|
233
|
+
if (chunks.length === 0 || !FILE_LINE_RANGE_ONLY_RE.test(chunks[0])) break;
|
|
234
|
+
const folded = foldRepeatedListColons(path, chunks[0], schemeEnd);
|
|
235
|
+
if (folded.basePath === path) break;
|
|
236
|
+
chunks[0] = folded.list;
|
|
237
|
+
path = folded.basePath;
|
|
195
238
|
}
|
|
196
239
|
if (chunks.length === 0) return { path: rawPath };
|
|
197
240
|
return { path, sel: chunks.join(":") };
|
package/src/tools/renderer.ts
CHANGED
|
@@ -28,8 +28,9 @@ export interface RenderResultOptions {
|
|
|
28
28
|
executionStarted?: boolean;
|
|
29
29
|
/**
|
|
30
30
|
* Milliseconds since this call began executing (`tool_execution_start`),
|
|
31
|
-
* or its total once settled; undefined before it starts.
|
|
32
|
-
*
|
|
31
|
+
* or its total once settled; undefined before it starts. The terminal
|
|
32
|
+
* transcript's options object computes it on read, so a render-time read
|
|
33
|
+
* is live while the block's spinner ticks.
|
|
33
34
|
*/
|
|
34
35
|
elapsedMs?: number;
|
|
35
36
|
/** The call was abandoned without a final result (turn aborted, sealed). Native describe hooks only. */
|
|
@@ -195,6 +196,11 @@ export interface ToolRenderer<TArgs = unknown, TDetails = unknown> {
|
|
|
195
196
|
* `options.spinnerFrame`.
|
|
196
197
|
*/
|
|
197
198
|
animatedPartialResult?: boolean | ((args: TArgs) => boolean);
|
|
199
|
+
/**
|
|
200
|
+
* Repaint the block once a second while its call executes, for renderers
|
|
201
|
+
* that show live `options.elapsedMs` without consuming the spinner frame.
|
|
202
|
+
*/
|
|
203
|
+
tickElapsed?: boolean;
|
|
198
204
|
/**
|
|
199
205
|
* Whether replacing a pending call render with the first result requires a
|
|
200
206
|
* full viewport repaint. Use for merged renderers whose pending rows can be
|
package/src/tools/result-card.ts
CHANGED
|
@@ -23,7 +23,7 @@ export function safe(value: string): string {
|
|
|
23
23
|
return replaceTabs(value).replace(/\r/g, "");
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/**
|
|
26
|
+
/** Card whose lines are sanitized and truncated, re-rendered when the expanded state flips. */
|
|
27
27
|
export function card(lines: (width: number, expanded: boolean) => string[], options: RenderResultOptions): Component {
|
|
28
28
|
return createCachedComponent(
|
|
29
29
|
() => Boolean(options.expanded),
|
|
@@ -31,6 +31,5 @@ export function card(lines: (width: number, expanded: boolean) => string[], opti
|
|
|
31
31
|
lines(width, expanded)
|
|
32
32
|
.flatMap(line => line.split("\n"))
|
|
33
33
|
.map(line => truncateToWidth(safe(line), width, Ellipsis.Unicode)),
|
|
34
|
-
{ paddingX: 1 },
|
|
35
34
|
);
|
|
36
35
|
}
|