@caupulican/pi-adaptative 0.80.22 → 0.80.23
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 +22 -0
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +28 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +10 -76
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +16 -7
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/exec.d.ts +20 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +52 -19
- package/dist/core/exec.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +6 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +33 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +2 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/message-retention.d.ts +26 -0
- package/dist/core/message-retention.d.ts.map +1 -0
- package/dist/core/message-retention.js +95 -0
- package/dist/core/message-retention.js.map +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +14 -6
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +4 -1
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/session-manager.d.ts +3 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +45 -9
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +12 -0
- package/dist/core/skills.js.map +1 -1
- package/dist/core/tools/git-filter.d.ts +9 -1
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js +94 -8
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/read.d.ts +31 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +164 -33
- package/dist/core/tools/read.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +37 -4
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +54 -18
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/jsonl.d.ts +0 -7
- package/dist/modes/rpc/jsonl.d.ts.map +1 -1
- package/dist/modes/rpc/jsonl.js +17 -0
- package/dist/modes/rpc/jsonl.js.map +1 -1
- package/dist/utils/safe-write-stream.d.ts +10 -0
- package/dist/utils/safe-write-stream.d.ts.map +1 -0
- package/dist/utils/safe-write-stream.js +16 -0
- package/dist/utils/safe-write-stream.js.map +1 -0
- package/dist/utils/sleep.d.ts +3 -1
- package/dist/utils/sleep.d.ts.map +1 -1
- package/dist/utils/sleep.js +10 -4
- package/dist/utils/sleep.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
package/dist/core/tools/read.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { basename, dirname, isAbsolute, relative, resolve as resolvePath, sep } from "node:path";
|
|
2
|
+
import { StringDecoder } from "node:string_decoder";
|
|
2
3
|
import { Text } from "@caupulican/pi-tui";
|
|
3
4
|
import { constants } from "fs";
|
|
4
|
-
import { access as fsAccess, readFile as fsReadFile } from "fs/promises";
|
|
5
|
+
import { access as fsAccess, open as fsOpen, readFile as fsReadFile, stat as fsStat } from "fs/promises";
|
|
5
6
|
import { Type } from "typebox";
|
|
6
7
|
import { getReadmePath } from "../../config.js";
|
|
7
8
|
import { keyHint, keyText } from "../../modes/interactive/components/keybinding-hints.js";
|
|
@@ -31,11 +32,78 @@ const COMPACT_RESOURCE_FILE_NAMES = new Set([
|
|
|
31
32
|
"GEMINI.md",
|
|
32
33
|
"GEMINI.MD",
|
|
33
34
|
]);
|
|
35
|
+
const SLICE_SCAN_CHUNK_BYTES = 1024 * 1024;
|
|
36
|
+
async function scanLines(absolutePath, onLine) {
|
|
37
|
+
const handle = await fsOpen(absolutePath, "r");
|
|
38
|
+
try {
|
|
39
|
+
const decoder = new StringDecoder("utf8");
|
|
40
|
+
const buffer = Buffer.allocUnsafe(SLICE_SCAN_CHUNK_BYTES);
|
|
41
|
+
let pending = "";
|
|
42
|
+
let index = 0;
|
|
43
|
+
while (true) {
|
|
44
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, null);
|
|
45
|
+
if (bytesRead === 0)
|
|
46
|
+
break;
|
|
47
|
+
pending += decoder.write(buffer.subarray(0, bytesRead));
|
|
48
|
+
let lineStart = 0;
|
|
49
|
+
let newlineIndex = pending.indexOf("\n", lineStart);
|
|
50
|
+
while (newlineIndex !== -1) {
|
|
51
|
+
if (!onLine(pending.slice(lineStart, newlineIndex), index++))
|
|
52
|
+
return;
|
|
53
|
+
lineStart = newlineIndex + 1;
|
|
54
|
+
newlineIndex = pending.indexOf("\n", lineStart);
|
|
55
|
+
}
|
|
56
|
+
pending = pending.slice(lineStart);
|
|
57
|
+
}
|
|
58
|
+
pending += decoder.end();
|
|
59
|
+
onLine(pending, index);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
await handle.close();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function readLocalLineSlice(absolutePath, options) {
|
|
66
|
+
const lines = [];
|
|
67
|
+
let collectedChars = 0;
|
|
68
|
+
let sawMore = false;
|
|
69
|
+
await scanLines(absolutePath, (text, index) => {
|
|
70
|
+
if (text === undefined)
|
|
71
|
+
return false;
|
|
72
|
+
if (index < options.startLine)
|
|
73
|
+
return true;
|
|
74
|
+
if (lines.length >= options.maxLines || collectedChars > options.maxChars) {
|
|
75
|
+
sawMore = true;
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
lines.push({ text, originalIndex: index + 1 });
|
|
79
|
+
collectedChars += text.length;
|
|
80
|
+
return true;
|
|
81
|
+
});
|
|
82
|
+
return { lines, reachedEnd: !sawMore };
|
|
83
|
+
}
|
|
84
|
+
async function countLocalLines(absolutePath) {
|
|
85
|
+
let count = 0;
|
|
86
|
+
await scanLines(absolutePath, () => {
|
|
87
|
+
count++;
|
|
88
|
+
return true;
|
|
89
|
+
});
|
|
90
|
+
return count;
|
|
91
|
+
}
|
|
34
92
|
const defaultReadOperations = {
|
|
35
93
|
readFile: (path) => fsReadFile(path),
|
|
36
94
|
access: (path) => fsAccess(path, constants.R_OK),
|
|
37
95
|
detectImageMimeType: detectSupportedImageMimeTypeFromFile,
|
|
96
|
+
stat: async (path) => ({ size: (await fsStat(path)).size }),
|
|
97
|
+
readLineSlice: readLocalLineSlice,
|
|
98
|
+
countLines: countLocalLines,
|
|
38
99
|
};
|
|
100
|
+
// Loading a whole file before truncation lets a single giant file spike the heap
|
|
101
|
+
// to its full size. Beyond these budgets, text reads stream line slices (every
|
|
102
|
+
// region stays reachable in batches — lossless). The image budget is deliberately
|
|
103
|
+
// far above any real screenshot/photo so quality-degrading workarounds are never
|
|
104
|
+
// needed in practice; it only guards against pathological files.
|
|
105
|
+
const DEFAULT_MAX_TEXT_READ_BYTES = 16 * 1024 * 1024;
|
|
106
|
+
const DEFAULT_MAX_IMAGE_READ_BYTES = 128 * 1024 * 1024;
|
|
39
107
|
function formatReadLineRange(args, theme) {
|
|
40
108
|
if (args?.offset === undefined && args?.limit === undefined)
|
|
41
109
|
return "";
|
|
@@ -142,6 +210,8 @@ function formatReadResult(args, result, options, theme, showImages, _cwd, isErro
|
|
|
142
210
|
export function createReadToolDefinition(cwd, options) {
|
|
143
211
|
const autoResizeImages = options?.autoResizeImages ?? true;
|
|
144
212
|
const ops = options?.operations ?? defaultReadOperations;
|
|
213
|
+
const maxTextReadBytes = options?.maxTextReadBytes ?? DEFAULT_MAX_TEXT_READ_BYTES;
|
|
214
|
+
const maxImageReadBytes = options?.maxImageReadBytes ?? DEFAULT_MAX_IMAGE_READ_BYTES;
|
|
145
215
|
return {
|
|
146
216
|
name: "read",
|
|
147
217
|
label: "read",
|
|
@@ -174,7 +244,23 @@ export function createReadToolDefinition(cwd, options) {
|
|
|
174
244
|
let content;
|
|
175
245
|
let details;
|
|
176
246
|
const nonVisionImageNote = getNonVisionImageNote(ctx?.model);
|
|
247
|
+
const fileSize = ops.stat ? (await ops.stat(absolutePath)).size : undefined;
|
|
248
|
+
if (aborted)
|
|
249
|
+
return;
|
|
177
250
|
if (mimeType) {
|
|
251
|
+
if (fileSize !== undefined && fileSize > maxImageReadBytes) {
|
|
252
|
+
signal?.removeEventListener("abort", onAbort);
|
|
253
|
+
resolve({
|
|
254
|
+
content: [
|
|
255
|
+
{
|
|
256
|
+
type: "text",
|
|
257
|
+
text: `Image file is ${formatSize(fileSize)} (${formatSize(maxImageReadBytes)} inline decode limit). Downscale it first, e.g. with bash (ImageMagick: magick "${path}" -resize 2000x2000 /tmp/preview.png) and read the result.`,
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
details: undefined,
|
|
261
|
+
});
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
178
264
|
// Read image as binary.
|
|
179
265
|
const buffer = await ops.readFile(absolutePath);
|
|
180
266
|
if (autoResizeImages) {
|
|
@@ -210,33 +296,73 @@ export function createReadToolDefinition(cwd, options) {
|
|
|
210
296
|
}
|
|
211
297
|
}
|
|
212
298
|
else {
|
|
213
|
-
// Read text content.
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
const allLines = textContent.split("\n");
|
|
217
|
-
const totalFileLines = allLines.length;
|
|
218
|
-
// Apply offset/tail if specified. Convert from 1-indexed input to 0-indexed array access.
|
|
299
|
+
// Read text content. Oversized files are streamed as line slices so
|
|
300
|
+
// any region stays reachable in batches without loading the whole file.
|
|
301
|
+
const useSlicedRead = fileSize !== undefined && fileSize > maxTextReadBytes && ops.readLineSlice !== undefined;
|
|
219
302
|
let startLine = 0;
|
|
220
303
|
let userLimitedLines = limit;
|
|
221
|
-
|
|
222
|
-
|
|
304
|
+
let totalFileLines;
|
|
305
|
+
let moreContentRemains = false;
|
|
306
|
+
let textContentForJsonCheck;
|
|
307
|
+
let slicedLines;
|
|
308
|
+
if (useSlicedRead && ops.readLineSlice) {
|
|
309
|
+
if (offset !== undefined) {
|
|
310
|
+
startLine = Math.max(0, offset - 1);
|
|
311
|
+
}
|
|
312
|
+
else if (tail !== undefined) {
|
|
313
|
+
const counted = ops.countLines ? await ops.countLines(absolutePath) : undefined;
|
|
314
|
+
if (counted !== undefined) {
|
|
315
|
+
totalFileLines = counted;
|
|
316
|
+
startLine = Math.max(0, counted - tail);
|
|
317
|
+
}
|
|
318
|
+
if (limit === undefined) {
|
|
319
|
+
userLimitedLines = tail;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const slice = await ops.readLineSlice(absolutePath, {
|
|
323
|
+
startLine,
|
|
324
|
+
maxLines: userLimitedLines ?? DEFAULT_MAX_LINES,
|
|
325
|
+
maxChars: DEFAULT_MAX_BYTES * 4,
|
|
326
|
+
});
|
|
327
|
+
if (slice.lines.length === 0 && startLine > 0) {
|
|
328
|
+
throw new Error(`Offset ${startLine + 1} is beyond end of file`);
|
|
329
|
+
}
|
|
330
|
+
slicedLines = slice.lines;
|
|
331
|
+
moreContentRemains = !slice.reachedEnd;
|
|
223
332
|
}
|
|
224
|
-
else
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
333
|
+
else {
|
|
334
|
+
const buffer = await ops.readFile(absolutePath);
|
|
335
|
+
const textContent = buffer.toString("utf-8");
|
|
336
|
+
textContentForJsonCheck = textContent;
|
|
337
|
+
const allLines = textContent.split("\n");
|
|
338
|
+
totalFileLines = allLines.length;
|
|
339
|
+
// Apply offset/tail if specified. Convert from 1-indexed input to 0-indexed array access.
|
|
340
|
+
if (offset !== undefined) {
|
|
341
|
+
startLine = Math.max(0, offset - 1);
|
|
228
342
|
}
|
|
343
|
+
else if (tail !== undefined) {
|
|
344
|
+
startLine = Math.max(0, totalFileLines - tail);
|
|
345
|
+
if (limit === undefined) {
|
|
346
|
+
userLimitedLines = tail;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
// Check if offset is out of bounds.
|
|
350
|
+
if (startLine >= allLines.length && allLines.length > 0) {
|
|
351
|
+
throw new Error(`Offset ${startLine + 1} is beyond end of file (${allLines.length} lines total)`);
|
|
352
|
+
}
|
|
353
|
+
slicedLines =
|
|
354
|
+
userLimitedLines !== undefined
|
|
355
|
+
? allLines
|
|
356
|
+
.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))
|
|
357
|
+
.slice(startLine, startLine + userLimitedLines)
|
|
358
|
+
: allLines
|
|
359
|
+
.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))
|
|
360
|
+
.slice(startLine);
|
|
361
|
+
moreContentRemains =
|
|
362
|
+
userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length;
|
|
229
363
|
}
|
|
230
364
|
const startLineDisplay = startLine + 1;
|
|
231
|
-
|
|
232
|
-
if (startLine >= allLines.length && allLines.length > 0) {
|
|
233
|
-
throw new Error(`Offset ${startLine + 1} is beyond end of file (${allLines.length} lines total)`);
|
|
234
|
-
}
|
|
235
|
-
let slicedLines = userLimitedLines !== undefined
|
|
236
|
-
? allLines
|
|
237
|
-
.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))
|
|
238
|
-
.slice(startLine, startLine + userLimitedLines)
|
|
239
|
-
: allLines.map((line, idx) => ({ text: line, originalIndex: idx + 1 })).slice(startLine);
|
|
365
|
+
const firstSelectedLineText = slicedLines[0]?.text ?? "";
|
|
240
366
|
// Safe text filtering
|
|
241
367
|
let canFilter = true;
|
|
242
368
|
if (mimeType) {
|
|
@@ -257,9 +383,9 @@ export function createReadToolDefinition(cwd, options) {
|
|
|
257
383
|
if (unsafeExtensions.some((ext) => fileNameLower.endsWith(ext))) {
|
|
258
384
|
canFilter = false;
|
|
259
385
|
}
|
|
260
|
-
else {
|
|
386
|
+
else if (textContentForJsonCheck !== undefined) {
|
|
261
387
|
try {
|
|
262
|
-
JSON.parse(
|
|
388
|
+
JSON.parse(textContentForJsonCheck);
|
|
263
389
|
canFilter = false;
|
|
264
390
|
}
|
|
265
391
|
catch { }
|
|
@@ -316,9 +442,12 @@ export function createReadToolDefinition(cwd, options) {
|
|
|
316
442
|
// Apply truncation, respecting both line and byte limits.
|
|
317
443
|
const truncation = truncateHead(selectedContent);
|
|
318
444
|
let outputText;
|
|
445
|
+
const totalDisplay = totalFileLines !== undefined
|
|
446
|
+
? String(totalFileLines)
|
|
447
|
+
: `a ${fileSize !== undefined ? formatSize(fileSize) : "large"} file`;
|
|
319
448
|
if (truncation.firstLineExceedsLimit) {
|
|
320
449
|
// First line alone exceeds the byte limit. Point the model at a bash fallback.
|
|
321
|
-
const firstLineSize = formatSize(Buffer.byteLength(
|
|
450
|
+
const firstLineSize = formatSize(Buffer.byteLength(firstSelectedLineText, "utf-8"));
|
|
322
451
|
outputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;
|
|
323
452
|
details = { truncation };
|
|
324
453
|
}
|
|
@@ -328,21 +457,23 @@ export function createReadToolDefinition(cwd, options) {
|
|
|
328
457
|
const nextOffset = endLineDisplay + 1;
|
|
329
458
|
outputText = truncation.content;
|
|
330
459
|
if (truncation.truncatedBy === "lines") {
|
|
331
|
-
outputText += `\n\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${
|
|
460
|
+
outputText += `\n\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay}. Use offset=${nextOffset} to continue.]`;
|
|
332
461
|
}
|
|
333
462
|
else {
|
|
334
|
-
outputText += `\n\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${
|
|
463
|
+
outputText += `\n\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;
|
|
335
464
|
}
|
|
336
465
|
details = { truncation };
|
|
337
466
|
}
|
|
338
|
-
else if (
|
|
339
|
-
//
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
|
|
467
|
+
else if (moreContentRemains) {
|
|
468
|
+
// More content exists beyond this slice; hand the model a continuation pointer.
|
|
469
|
+
const nextOffset = startLine + slicedLines.length + 1;
|
|
470
|
+
const remaining = totalFileLines !== undefined && userLimitedLines !== undefined
|
|
471
|
+
? `${totalFileLines - (startLine + userLimitedLines)} more lines in file`
|
|
472
|
+
: "More content remains";
|
|
473
|
+
outputText = `${truncation.content}\n\n[${remaining}. Use offset=${nextOffset} to continue.]`;
|
|
343
474
|
}
|
|
344
475
|
else {
|
|
345
|
-
// No truncation and no remaining
|
|
476
|
+
// No truncation and no remaining content.
|
|
346
477
|
outputText = truncation.content;
|
|
347
478
|
}
|
|
348
479
|
content = [{ type: "text", text: outputText }];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGjG,OAAO,EA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,IAAI,CAAC;QAAA,CACZ;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB,EAAgC;IACpG,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAClE","sourcesContent":["import { basename, dirname, isAbsolute, relative, resolve as resolvePath, sep } from \"node:path\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport type { Api, ImageContent, Model, TextContent } from \"@caupulican/pi-ai\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { getReadmePath } from \"../../config.ts\";\nimport { keyHint, keyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { resolveReadPathAsync, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n\tlineNumbers: Type.Optional(Type.Boolean({ description: \"Include line numbers in the output\" })),\n\ttail: Type.Optional(Type.Number({ description: \"Number of lines to read from the end of the file\" })),\n\tfilter: Type.Optional(\n\t\tType.Union([Type.Literal(\"none\"), Type.Literal(\"minimal\"), Type.Literal(\"aggressive\")], {\n\t\t\tdescription: \"Safe text filtering level (none, minimal, aggressive)\",\n\t\t}),\n\t),\n});\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\ninterface CompactReadClassification {\n\tkind: \"docs\" | \"resource\" | \"skill\";\n\tlabel: string;\n}\n\nconst COMPACT_RESOURCE_FILE_NAMES = new Set([\n\t\"AGENTS.md\",\n\t\"AGENTS.MD\",\n\t\"CLAUDE.md\",\n\t\"CLAUDE.MD\",\n\t\"GEMINI.md\",\n\t\"GEMINI.MD\",\n]);\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n};\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n}\n\ntype ReadRenderArgs = { path?: string; file_path?: string; offset?: number; limit?: number };\n\nfunction formatReadLineRange(args: ReadRenderArgs | undefined, theme: Theme): string {\n\tif (args?.offset === undefined && args?.limit === undefined) return \"\";\n\tconst startLine = args.offset ?? 1;\n\tconst endLine = args.limit !== undefined ? startLine + args.limit - 1 : \"\";\n\treturn theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n}\n\nfunction formatReadCall(args: ReadRenderArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}${formatReadLineRange(args, theme)}`;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nfunction toPosixPath(filePath: string): string {\n\treturn filePath.split(sep).join(\"/\");\n}\n\nfunction getPiDocsClassification(absolutePath: string): CompactReadClassification | undefined {\n\tconst packageRoot = dirname(getReadmePath());\n\tconst relativePath = relative(resolvePath(packageRoot), resolvePath(absolutePath));\n\tif (\n\t\trelativePath === \"\" ||\n\t\trelativePath === \"..\" ||\n\t\trelativePath.startsWith(`..${sep}`) ||\n\t\tisAbsolute(relativePath)\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst label = toPosixPath(relativePath);\n\tif (label === \"README.md\" || label.startsWith(\"docs/\") || label.startsWith(\"examples/\")) {\n\t\treturn { kind: \"docs\", label };\n\t}\n\treturn undefined;\n}\n\nfunction getCompactReadClassification(\n\targs: ReadRenderArgs | undefined,\n\tcwd: string,\n): CompactReadClassification | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tif (!rawPath) return undefined;\n\n\tconst absolutePath = resolveToCwd(rawPath, cwd);\n\tconst fileName = basename(absolutePath);\n\tif (fileName === \"SKILL.md\") {\n\t\treturn { kind: \"skill\", label: basename(dirname(absolutePath)) || fileName };\n\t}\n\n\tconst docsClassification = getPiDocsClassification(absolutePath);\n\tif (docsClassification) return docsClassification;\n\n\tif (COMPACT_RESOURCE_FILE_NAMES.has(fileName)) {\n\t\treturn { kind: \"resource\", label: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd) };\n\t}\n\n\treturn undefined;\n}\n\nfunction formatCompactReadCall(\n\tclassification: CompactReadClassification,\n\targs: ReadRenderArgs | undefined,\n\ttheme: Theme,\n): string {\n\tconst expandHint = theme.fg(\"dim\", ` (${keyText(\"app.tools.expand\")} to expand)`);\n\tif (classification.kind === \"skill\") {\n\t\treturn (\n\t\t\ttheme.fg(\"customMessageLabel\", `\\x1b[1m[skill]\\x1b[22m `) +\n\t\t\ttheme.fg(\"customMessageText\", classification.label) +\n\t\t\tformatReadLineRange(args, theme) +\n\t\t\texpandHint\n\t\t);\n\t}\n\n\treturn (\n\t\ttheme.fg(\"toolTitle\", theme.bold(`read ${classification.kind}`)) +\n\t\t\" \" +\n\t\ttheme.fg(\"accent\", classification.label) +\n\t\tformatReadLineRange(args, theme) +\n\t\texpandHint\n\t);\n}\n\nfunction formatReadResult(\n\targs: ReadRenderArgs | undefined,\n\tresult: { content: (TextContent | ImageContent)[]; details?: ReadToolDetails },\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tshowImages: boolean,\n\t_cwd: string,\n\tisError: boolean,\n): string {\n\tif (!options.expanded && !isError) {\n\t\treturn \"\";\n\t}\n\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result, showImages);\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tif (truncation?.truncated) {\n\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;\n\t\t} else {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;\n\t\t}\n\t}\n\treturn text;\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{\n\t\t\t\tpath,\n\t\t\t\toffset,\n\t\t\t\tlimit,\n\t\t\t\tlineNumbers,\n\t\t\t\ttail,\n\t\t\t\tfilter,\n\t\t\t}: {\n\t\t\t\tpath: string;\n\t\t\t\toffset?: number;\n\t\t\t\tlimit?: number;\n\t\t\t\tlineNumbers?: boolean;\n\t\t\t\ttail?: number;\n\t\t\t\tfilter?: \"none\" | \"minimal\" | \"aggressive\";\n\t\t\t},\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, cwd);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tif (autoResizeImages) {\n\t\t\t\t\t\t\t\t\t// Resize image if needed before sending it back to the model.\n\t\t\t\t\t\t\t\t\tconst resized = await resizeImage(buffer, mimeType);\n\t\t\t\t\t\t\t\t\tif (!resized) {\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n[Image omitted: could not be resized below the inline image size limit.]`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst dimensionNote = formatDimensionNote(resized);\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${resized.mimeType}]`;\n\t\t\t\t\t\t\t\t\t\tif (dimensionNote) textNote += `\\n${dimensionNote}`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: resized.data, mimeType: resized.mimeType },\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: buffer.toString(\"base64\"), mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\tconst totalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t// Apply offset/tail if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\tlet startLine = 0;\n\t\t\t\t\t\t\t\tlet userLimitedLines = limit;\n\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, totalFileLines - tail);\n\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\tif (startLine >= allLines.length && allLines.length > 0) {\n\t\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t\t`Offset ${startLine + 1} is beyond end of file (${allLines.length} lines total)`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tlet slicedLines =\n\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t? allLines\n\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine, startLine + userLimitedLines)\n\t\t\t\t\t\t\t\t\t\t: allLines.map((line, idx) => ({ text: line, originalIndex: idx + 1 })).slice(startLine);\n\n\t\t\t\t\t\t\t\t// Safe text filtering\n\t\t\t\t\t\t\t\tlet canFilter = true;\n\t\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst fileNameLower = path.toLowerCase();\n\t\t\t\t\t\t\t\t\tconst unsafeExtensions = [\n\t\t\t\t\t\t\t\t\t\t\".json\",\n\t\t\t\t\t\t\t\t\t\t\".jsonl\",\n\t\t\t\t\t\t\t\t\t\t\".yml\",\n\t\t\t\t\t\t\t\t\t\t\".yaml\",\n\t\t\t\t\t\t\t\t\t\t\".toml\",\n\t\t\t\t\t\t\t\t\t\t\".xml\",\n\t\t\t\t\t\t\t\t\t\t\".csv\",\n\t\t\t\t\t\t\t\t\t\t\".tsv\",\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\tif (unsafeExtensions.some((ext) => fileNameLower.endsWith(ext))) {\n\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tJSON.parse(textContent);\n\t\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t\t} catch {}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (canFilter && filter && filter !== \"none\") {\n\t\t\t\t\t\t\t\t\tconst filtered: typeof slicedLines = [];\n\t\t\t\t\t\t\t\t\tif (filter === \"minimal\") {\n\t\t\t\t\t\t\t\t\t\tlet consecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmed === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank++;\n\t\t\t\t\t\t\t\t\t\t\t\tif (consecutiveBlank <= 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: \"\", originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twhile (filtered.length > 0 && filtered[filtered.length - 1].text === \"\") {\n\t\t\t\t\t\t\t\t\t\t\tfiltered.pop();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} else if (filter === \"aggressive\") {\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tconst trimmedStart = trimmed.trimStart();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmedStart === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"//\") ||\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"#\") ||\n\t\t\t\t\t\t\t\t\t\t\t\t(trimmedStart.startsWith(\"/*\") && trimmedStart.endsWith(\"*/\"))\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// If filtering would empty a non-empty list, keep original\n\t\t\t\t\t\t\t\t\tconst isOriginalNotEmpty = slicedLines.some((item) => item.text.trim().length > 0);\n\t\t\t\t\t\t\t\t\tconst isFilteredEmpty = filtered.every((item) => item.text.trim().length === 0);\n\t\t\t\t\t\t\t\t\tif (isOriginalNotEmpty && isFilteredEmpty) {\n\t\t\t\t\t\t\t\t\t\t// Fallback to slicedLines\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tslicedLines = filtered;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst finalLines = slicedLines.map((item) =>\n\t\t\t\t\t\t\t\t\tlineNumbers ? `${item.originalIndex}: ${item.text}` : item.text,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst selectedContent = finalLines.join(\"\\n\");\n\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(allLines[startLine], \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\t\t\t\t\t\t// User-specified limit stopped early, but the file still has more content.\n\t\t\t\t\t\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining user-limited content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined;\n\t\t\ttext.setText(\n\t\t\t\tclassification\n\t\t\t\t\t? formatCompactReadCall(classification, args, theme)\n\t\t\t\t\t: formatReadCall(args, theme, context.cwd),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(\n\t\t\t\tformatReadResult(context.args, result, options, theme, context.showImages, context.cwd, context.isError),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,IAAI,IAAI,MAAM,EAAE,QAAQ,IAAI,UAAU,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AACzG,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAc,MAAM,wCAAwC,CAAC;AACxG,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,oCAAoC,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE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AAAA,CAClE","sourcesContent":["import { basename, dirname, isAbsolute, relative, resolve as resolvePath, sep } from \"node:path\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport type { Api, ImageContent, Model, TextContent } from \"@caupulican/pi-ai\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, open as fsOpen, readFile as fsReadFile, stat as fsStat } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { getReadmePath } from \"../../config.ts\";\nimport { keyHint, keyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { resolveReadPathAsync, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n\tlineNumbers: Type.Optional(Type.Boolean({ description: \"Include line numbers in the output\" })),\n\ttail: Type.Optional(Type.Number({ description: \"Number of lines to read from the end of the file\" })),\n\tfilter: Type.Optional(\n\t\tType.Union([Type.Literal(\"none\"), Type.Literal(\"minimal\"), Type.Literal(\"aggressive\")], {\n\t\t\tdescription: \"Safe text filtering level (none, minimal, aggressive)\",\n\t\t}),\n\t),\n});\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\ninterface CompactReadClassification {\n\tkind: \"docs\" | \"resource\" | \"skill\";\n\tlabel: string;\n}\n\nconst COMPACT_RESOURCE_FILE_NAMES = new Set([\n\t\"AGENTS.md\",\n\t\"AGENTS.MD\",\n\t\"CLAUDE.md\",\n\t\"CLAUDE.MD\",\n\t\"GEMINI.md\",\n\t\"GEMINI.MD\",\n]);\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n\t/** File size in bytes, used to decide between whole-file and sliced reads. */\n\tstat?: (absolutePath: string) => Promise<{ size: number }>;\n\t/**\n\t * Stream a slice of lines out of the file with bounded memory. Any region of an\n\t * arbitrarily large file stays reachable in batches via offset continuation.\n\t */\n\treadLineSlice?: (absolutePath: string, options: LineSliceOptions) => Promise<LineSlice>;\n\t/** Count lines by streaming (bounded memory); used to resolve tail reads on oversized files. */\n\tcountLines?: (absolutePath: string) => Promise<number>;\n}\n\nexport interface LineSliceOptions {\n\t/** 0-based line to start collecting at. */\n\tstartLine: number;\n\t/** Maximum number of lines to collect. */\n\tmaxLines: number;\n\t/** Maximum total characters to collect across lines. */\n\tmaxChars: number;\n}\n\nexport interface LineSlice {\n\tlines: { text: string; originalIndex: number }[];\n\t/** True when the end of the file was reached while collecting. */\n\treachedEnd: boolean;\n}\n\nconst SLICE_SCAN_CHUNK_BYTES = 1024 * 1024;\n\nasync function scanLines(\n\tabsolutePath: string,\n\tonLine: (text: string | undefined, index: number) => boolean,\n): Promise<void> {\n\tconst handle = await fsOpen(absolutePath, \"r\");\n\ttry {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tconst buffer = Buffer.allocUnsafe(SLICE_SCAN_CHUNK_BYTES);\n\t\tlet pending = \"\";\n\t\tlet index = 0;\n\t\twhile (true) {\n\t\t\tconst { bytesRead } = await handle.read(buffer, 0, buffer.length, null);\n\t\t\tif (bytesRead === 0) break;\n\t\t\tpending += decoder.write(buffer.subarray(0, bytesRead));\n\t\t\tlet lineStart = 0;\n\t\t\tlet newlineIndex = pending.indexOf(\"\\n\", lineStart);\n\t\t\twhile (newlineIndex !== -1) {\n\t\t\t\tif (!onLine(pending.slice(lineStart, newlineIndex), index++)) return;\n\t\t\t\tlineStart = newlineIndex + 1;\n\t\t\t\tnewlineIndex = pending.indexOf(\"\\n\", lineStart);\n\t\t\t}\n\t\t\tpending = pending.slice(lineStart);\n\t\t}\n\t\tpending += decoder.end();\n\t\tonLine(pending, index);\n\t} finally {\n\t\tawait handle.close();\n\t}\n}\n\nasync function readLocalLineSlice(absolutePath: string, options: LineSliceOptions): Promise<LineSlice> {\n\tconst lines: { text: string; originalIndex: number }[] = [];\n\tlet collectedChars = 0;\n\tlet sawMore = false;\n\tawait scanLines(absolutePath, (text, index) => {\n\t\tif (text === undefined) return false;\n\t\tif (index < options.startLine) return true;\n\t\tif (lines.length >= options.maxLines || collectedChars > options.maxChars) {\n\t\t\tsawMore = true;\n\t\t\treturn false;\n\t\t}\n\t\tlines.push({ text, originalIndex: index + 1 });\n\t\tcollectedChars += text.length;\n\t\treturn true;\n\t});\n\treturn { lines, reachedEnd: !sawMore };\n}\n\nasync function countLocalLines(absolutePath: string): Promise<number> {\n\tlet count = 0;\n\tawait scanLines(absolutePath, () => {\n\t\tcount++;\n\t\treturn true;\n\t});\n\treturn count;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n\tstat: async (path) => ({ size: (await fsStat(path)).size }),\n\treadLineSlice: readLocalLineSlice,\n\tcountLines: countLocalLines,\n};\n\n// Loading a whole file before truncation lets a single giant file spike the heap\n// to its full size. Beyond these budgets, text reads stream line slices (every\n// region stays reachable in batches — lossless). The image budget is deliberately\n// far above any real screenshot/photo so quality-degrading workarounds are never\n// needed in practice; it only guards against pathological files.\nconst DEFAULT_MAX_TEXT_READ_BYTES = 16 * 1024 * 1024;\nconst DEFAULT_MAX_IMAGE_READ_BYTES = 128 * 1024 * 1024;\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n\t/** Whole-file load budget for text reads; larger files stream line slices instead. Default 16 MiB. */\n\tmaxTextReadBytes?: number;\n\t/** Pathology guard for image reads; larger images return downscale guidance. Default 128 MiB. */\n\tmaxImageReadBytes?: number;\n}\n\ntype ReadRenderArgs = { path?: string; file_path?: string; offset?: number; limit?: number };\n\nfunction formatReadLineRange(args: ReadRenderArgs | undefined, theme: Theme): string {\n\tif (args?.offset === undefined && args?.limit === undefined) return \"\";\n\tconst startLine = args.offset ?? 1;\n\tconst endLine = args.limit !== undefined ? startLine + args.limit - 1 : \"\";\n\treturn theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n}\n\nfunction formatReadCall(args: ReadRenderArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}${formatReadLineRange(args, theme)}`;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nfunction toPosixPath(filePath: string): string {\n\treturn filePath.split(sep).join(\"/\");\n}\n\nfunction getPiDocsClassification(absolutePath: string): CompactReadClassification | undefined {\n\tconst packageRoot = dirname(getReadmePath());\n\tconst relativePath = relative(resolvePath(packageRoot), resolvePath(absolutePath));\n\tif (\n\t\trelativePath === \"\" ||\n\t\trelativePath === \"..\" ||\n\t\trelativePath.startsWith(`..${sep}`) ||\n\t\tisAbsolute(relativePath)\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst label = toPosixPath(relativePath);\n\tif (label === \"README.md\" || label.startsWith(\"docs/\") || label.startsWith(\"examples/\")) {\n\t\treturn { kind: \"docs\", label };\n\t}\n\treturn undefined;\n}\n\nfunction getCompactReadClassification(\n\targs: ReadRenderArgs | undefined,\n\tcwd: string,\n): CompactReadClassification | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tif (!rawPath) return undefined;\n\n\tconst absolutePath = resolveToCwd(rawPath, cwd);\n\tconst fileName = basename(absolutePath);\n\tif (fileName === \"SKILL.md\") {\n\t\treturn { kind: \"skill\", label: basename(dirname(absolutePath)) || fileName };\n\t}\n\n\tconst docsClassification = getPiDocsClassification(absolutePath);\n\tif (docsClassification) return docsClassification;\n\n\tif (COMPACT_RESOURCE_FILE_NAMES.has(fileName)) {\n\t\treturn { kind: \"resource\", label: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd) };\n\t}\n\n\treturn undefined;\n}\n\nfunction formatCompactReadCall(\n\tclassification: CompactReadClassification,\n\targs: ReadRenderArgs | undefined,\n\ttheme: Theme,\n): string {\n\tconst expandHint = theme.fg(\"dim\", ` (${keyText(\"app.tools.expand\")} to expand)`);\n\tif (classification.kind === \"skill\") {\n\t\treturn (\n\t\t\ttheme.fg(\"customMessageLabel\", `\\x1b[1m[skill]\\x1b[22m `) +\n\t\t\ttheme.fg(\"customMessageText\", classification.label) +\n\t\t\tformatReadLineRange(args, theme) +\n\t\t\texpandHint\n\t\t);\n\t}\n\n\treturn (\n\t\ttheme.fg(\"toolTitle\", theme.bold(`read ${classification.kind}`)) +\n\t\t\" \" +\n\t\ttheme.fg(\"accent\", classification.label) +\n\t\tformatReadLineRange(args, theme) +\n\t\texpandHint\n\t);\n}\n\nfunction formatReadResult(\n\targs: ReadRenderArgs | undefined,\n\tresult: { content: (TextContent | ImageContent)[]; details?: ReadToolDetails },\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tshowImages: boolean,\n\t_cwd: string,\n\tisError: boolean,\n): string {\n\tif (!options.expanded && !isError) {\n\t\treturn \"\";\n\t}\n\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result, showImages);\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tif (truncation?.truncated) {\n\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;\n\t\t} else {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;\n\t\t}\n\t}\n\treturn text;\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\tconst maxTextReadBytes = options?.maxTextReadBytes ?? DEFAULT_MAX_TEXT_READ_BYTES;\n\tconst maxImageReadBytes = options?.maxImageReadBytes ?? DEFAULT_MAX_IMAGE_READ_BYTES;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{\n\t\t\t\tpath,\n\t\t\t\toffset,\n\t\t\t\tlimit,\n\t\t\t\tlineNumbers,\n\t\t\t\ttail,\n\t\t\t\tfilter,\n\t\t\t}: {\n\t\t\t\tpath: string;\n\t\t\t\toffset?: number;\n\t\t\t\tlimit?: number;\n\t\t\t\tlineNumbers?: boolean;\n\t\t\t\ttail?: number;\n\t\t\t\tfilter?: \"none\" | \"minimal\" | \"aggressive\";\n\t\t\t},\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, cwd);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tconst fileSize = ops.stat ? (await ops.stat(absolutePath)).size : undefined;\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\tif (fileSize !== undefined && fileSize > maxImageReadBytes) {\n\t\t\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\t\t\t\ttext: `Image file is ${formatSize(fileSize)} (${formatSize(maxImageReadBytes)} inline decode limit). Downscale it first, e.g. with bash (ImageMagick: magick \"${path}\" -resize 2000x2000 /tmp/preview.png) and read the result.`,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tif (autoResizeImages) {\n\t\t\t\t\t\t\t\t\t// Resize image if needed before sending it back to the model.\n\t\t\t\t\t\t\t\t\tconst resized = await resizeImage(buffer, mimeType);\n\t\t\t\t\t\t\t\t\tif (!resized) {\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n[Image omitted: could not be resized below the inline image size limit.]`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst dimensionNote = formatDimensionNote(resized);\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${resized.mimeType}]`;\n\t\t\t\t\t\t\t\t\t\tif (dimensionNote) textNote += `\\n${dimensionNote}`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: resized.data, mimeType: resized.mimeType },\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: buffer.toString(\"base64\"), mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content. Oversized files are streamed as line slices so\n\t\t\t\t\t\t\t\t// any region stays reachable in batches without loading the whole file.\n\t\t\t\t\t\t\t\tconst useSlicedRead =\n\t\t\t\t\t\t\t\t\tfileSize !== undefined && fileSize > maxTextReadBytes && ops.readLineSlice !== undefined;\n\t\t\t\t\t\t\t\tlet startLine = 0;\n\t\t\t\t\t\t\t\tlet userLimitedLines = limit;\n\t\t\t\t\t\t\t\tlet totalFileLines: number | undefined;\n\t\t\t\t\t\t\t\tlet moreContentRemains = false;\n\t\t\t\t\t\t\t\tlet textContentForJsonCheck: string | undefined;\n\t\t\t\t\t\t\t\tlet slicedLines: { text: string; originalIndex: number }[];\n\t\t\t\t\t\t\t\tif (useSlicedRead && ops.readLineSlice) {\n\t\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\t\tconst counted = ops.countLines ? await ops.countLines(absolutePath) : undefined;\n\t\t\t\t\t\t\t\t\t\tif (counted !== undefined) {\n\t\t\t\t\t\t\t\t\t\t\ttotalFileLines = counted;\n\t\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, counted - tail);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst slice = await ops.readLineSlice(absolutePath, {\n\t\t\t\t\t\t\t\t\t\tstartLine,\n\t\t\t\t\t\t\t\t\t\tmaxLines: userLimitedLines ?? DEFAULT_MAX_LINES,\n\t\t\t\t\t\t\t\t\t\tmaxChars: DEFAULT_MAX_BYTES * 4,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tif (slice.lines.length === 0 && startLine > 0) {\n\t\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${startLine + 1} is beyond end of file`);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tslicedLines = slice.lines;\n\t\t\t\t\t\t\t\t\tmoreContentRemains = !slice.reachedEnd;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\t\ttextContentForJsonCheck = textContent;\n\t\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\t\ttotalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t\t// Apply offset/tail if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, totalFileLines - tail);\n\t\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\t\tif (startLine >= allLines.length && allLines.length > 0) {\n\t\t\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t\t\t`Offset ${startLine + 1} is beyond end of file (${allLines.length} lines total)`,\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tslicedLines =\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t\t? allLines\n\t\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine, startLine + userLimitedLines)\n\t\t\t\t\t\t\t\t\t\t\t: allLines\n\t\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine);\n\t\t\t\t\t\t\t\t\tmoreContentRemains =\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined && startLine + userLimitedLines < allLines.length;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\tconst firstSelectedLineText = slicedLines[0]?.text ?? \"\";\n\n\t\t\t\t\t\t\t\t// Safe text filtering\n\t\t\t\t\t\t\t\tlet canFilter = true;\n\t\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst fileNameLower = path.toLowerCase();\n\t\t\t\t\t\t\t\t\tconst unsafeExtensions = [\n\t\t\t\t\t\t\t\t\t\t\".json\",\n\t\t\t\t\t\t\t\t\t\t\".jsonl\",\n\t\t\t\t\t\t\t\t\t\t\".yml\",\n\t\t\t\t\t\t\t\t\t\t\".yaml\",\n\t\t\t\t\t\t\t\t\t\t\".toml\",\n\t\t\t\t\t\t\t\t\t\t\".xml\",\n\t\t\t\t\t\t\t\t\t\t\".csv\",\n\t\t\t\t\t\t\t\t\t\t\".tsv\",\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\tif (unsafeExtensions.some((ext) => fileNameLower.endsWith(ext))) {\n\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t} else if (textContentForJsonCheck !== undefined) {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tJSON.parse(textContentForJsonCheck);\n\t\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t\t} catch {}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (canFilter && filter && filter !== \"none\") {\n\t\t\t\t\t\t\t\t\tconst filtered: typeof slicedLines = [];\n\t\t\t\t\t\t\t\t\tif (filter === \"minimal\") {\n\t\t\t\t\t\t\t\t\t\tlet consecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmed === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank++;\n\t\t\t\t\t\t\t\t\t\t\t\tif (consecutiveBlank <= 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: \"\", originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twhile (filtered.length > 0 && filtered[filtered.length - 1].text === \"\") {\n\t\t\t\t\t\t\t\t\t\t\tfiltered.pop();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} else if (filter === \"aggressive\") {\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tconst trimmedStart = trimmed.trimStart();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmedStart === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"//\") ||\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"#\") ||\n\t\t\t\t\t\t\t\t\t\t\t\t(trimmedStart.startsWith(\"/*\") && trimmedStart.endsWith(\"*/\"))\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// If filtering would empty a non-empty list, keep original\n\t\t\t\t\t\t\t\t\tconst isOriginalNotEmpty = slicedLines.some((item) => item.text.trim().length > 0);\n\t\t\t\t\t\t\t\t\tconst isFilteredEmpty = filtered.every((item) => item.text.trim().length === 0);\n\t\t\t\t\t\t\t\t\tif (isOriginalNotEmpty && isFilteredEmpty) {\n\t\t\t\t\t\t\t\t\t\t// Fallback to slicedLines\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tslicedLines = filtered;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst finalLines = slicedLines.map((item) =>\n\t\t\t\t\t\t\t\t\tlineNumbers ? `${item.originalIndex}: ${item.text}` : item.text,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst selectedContent = finalLines.join(\"\\n\");\n\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tconst totalDisplay =\n\t\t\t\t\t\t\t\t\ttotalFileLines !== undefined\n\t\t\t\t\t\t\t\t\t\t? String(totalFileLines)\n\t\t\t\t\t\t\t\t\t\t: `a ${fileSize !== undefined ? formatSize(fileSize) : \"large\"} file`;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(firstSelectedLineText, \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (moreContentRemains) {\n\t\t\t\t\t\t\t\t\t// More content exists beyond this slice; hand the model a continuation pointer.\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + slicedLines.length + 1;\n\t\t\t\t\t\t\t\t\tconst remaining =\n\t\t\t\t\t\t\t\t\t\ttotalFileLines !== undefined && userLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t\t? `${totalFileLines - (startLine + userLimitedLines)} more lines in file`\n\t\t\t\t\t\t\t\t\t\t\t: \"More content remains\";\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined;\n\t\t\ttext.setText(\n\t\t\t\tclassification\n\t\t\t\t\t? formatCompactReadCall(classification, args, theme)\n\t\t\t\t\t: formatReadCall(args, theme, context.cwd),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(\n\t\t\t\tformatReadResult(context.args, result, options, theme, context.showImages, context.cwd, context.isError),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-execution.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/tool-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAAwC,KAAK,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACpH,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,mCAAmC,CAAC;AAI3F,OAAO,EAAE,KAAK,OAAO,EAAS,MAAM,mBAAmB,CAAC;AAGxD,MAAM,WAAW,oBAAoB;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,mBAAmB,CAAY;IACvC,OAAO,CAAC,qBAAqB,CAAC,CAAY;IAC1C,OAAO,CAAC,uBAAuB,CAAC,CAAY;IAC5C,OAAO,CAAC,aAAa,CAAW;IAChC,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,cAAc,CAAC,CAA2B;IAClD,OAAO,CAAC,qBAAqB,CAAC,CAA2B;IACzD,SAAS,EAAE,MA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M,CAAA;SAAE,CAAC,CAAC;QAClF,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,OAAO,EAAE,OAAO,CAAC;KACjB,EACD,SAAS,UAAQ,GACf,IAAI,CAKN;IAED,OAAO,CAAC,0BAA0B;IAuBlC,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAGnC;IAED,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAGjC;IAED,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAGtC;IAED,kBAAkB,IAAI,OAAO,CAI5B;IAEQ,UAAU,IAAI,IAAI,CAG1B;IAED,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAazC;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAKvC;IAED,OAAO,CAAC,aAAa;IAwGrB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,mBAAmB;CAe3B","sourcesContent":["import { Box, type Component, Container, getCapabilities, Image, Spacer, Text, type TUI } from \"@caupulican/pi-tui\";\nimport type { ToolDefinition, ToolRenderContext } from \"../../../core/extensions/types.ts\";\nimport { createAllToolDefinitions, type ToolName } from \"../../../core/tools/index.ts\";\nimport { getTextOutput as getRenderedTextOutput } from \"../../../core/tools/render-utils.ts\";\nimport { convertToPng } from \"../../../utils/image-convert.ts\";\nimport { type ThemeBg, theme } from \"../theme/theme.ts\";\nimport { renderTitleBadge, titleBadge } from \"./tool-title.ts\";\n\nexport interface ToolExecutionOptions {\n\tshowImages?: boolean;\n\timageWidthCells?: number;\n}\n\nexport class ToolExecutionComponent extends Container {\n\tprivate contentBox: Box;\n\tprivate contentText: Text;\n\tprivate selfRenderContainer: Container;\n\tprivate callRendererComponent?: Component;\n\tprivate resultRendererComponent?: Component;\n\tprivate rendererState: any = {};\n\tprivate imageComponents: Image[] = [];\n\tprivate imageSpacers: Spacer[] = [];\n\tprivate toolName: string;\n\tprivate toolCallId: string;\n\tprivate args: any;\n\tprivate expanded = false;\n\tprivate showImages: boolean;\n\tprivate imageWidthCells: number;\n\tprivate isPartial = true;\n\tprivate toolDefinition?: ToolDefinition<any, any>;\n\tprivate builtInToolDefinition?: ToolDefinition<any, any>;\n\ttoolGroup: string | undefined;\n\tprivate ui: TUI;\n\tprivate cwd: string;\n\tprivate executionStarted = false;\n\tprivate argsComplete = false;\n\tprivate result?: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tisError: boolean;\n\t\tdetails?: any;\n\t};\n\tprivate convertedImages: Map<number, { data: string; mimeType: string }> = new Map();\n\tprivate hideComponent = false;\n\n\tconstructor(\n\t\ttoolName: string,\n\t\ttoolCallId: string,\n\t\targs: any,\n\t\toptions: ToolExecutionOptions = {},\n\t\ttoolDefinition: ToolDefinition<any, any> | undefined,\n\t\tui: TUI,\n\t\tcwd: string,\n\t) {\n\t\tsuper();\n\t\tthis.toolName = toolName;\n\t\tthis.toolCallId = toolCallId;\n\t\tthis.args = args;\n\t\tthis.toolDefinition = toolDefinition;\n\t\tthis.builtInToolDefinition = createAllToolDefinitions(cwd)[toolName as ToolName];\n\t\tthis.toolGroup = this.resolveToolGroup();\n\t\tthis.showImages = options.showImages ?? true;\n\t\tthis.imageWidthCells = options.imageWidthCells ?? 60;\n\t\tthis.ui = ui;\n\t\tthis.cwd = cwd;\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Always create all shell variants. contentBox is used for default renderer-based composition.\n\t\t// selfRenderContainer is used when the tool renders its own framing.\n\t\t// contentText is reserved for generic fallback rendering when no tool definition exists.\n\t\tthis.contentBox = new Box(1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\t\tthis.contentText = new Text(\"\", 1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\t\tthis.selfRenderContainer = new Container();\n\n\t\tif (this.hasRendererDefinition()) {\n\t\t\tthis.addChild(this.getRenderShell() === \"self\" ? this.selfRenderContainer : this.contentBox);\n\t\t} else {\n\t\t\tthis.addChild(this.contentText);\n\t\t}\n\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate getCallRenderer(): ToolDefinition<any, any>[\"renderCall\"] | undefined {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderCall;\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderCall;\n\t\t}\n\t\treturn this.toolDefinition.renderCall ?? this.builtInToolDefinition.renderCall;\n\t}\n\n\tprivate getResultRenderer(): ToolDefinition<any, any>[\"renderResult\"] | undefined {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderResult;\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderResult;\n\t\t}\n\t\treturn this.toolDefinition.renderResult ?? this.builtInToolDefinition.renderResult;\n\t}\n\n\tprivate hasRendererDefinition(): boolean {\n\t\treturn this.builtInToolDefinition !== undefined || this.toolDefinition !== undefined;\n\t}\n\n\tprivate getRenderShell(): \"default\" | \"self\" {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderShell ?? \"default\";\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderShell ?? \"default\";\n\t\t}\n\t\treturn this.toolDefinition.renderShell ?? this.builtInToolDefinition.renderShell ?? \"default\";\n\t}\n\n\tprivate resolveToolGroup(): string | undefined {\n\t\tconst configuredGroup = this.toolDefinition?.toolGroup ?? this.builtInToolDefinition?.toolGroup;\n\t\tif (configuredGroup !== undefined) {\n\t\t\tconst trimmed = configuredGroup.trim();\n\t\t\treturn trimmed || undefined;\n\t\t}\n\t\tconst defaultGroup = this.toolName.trim();\n\t\treturn defaultGroup || undefined;\n\t}\n\n\tprivate getRenderContext(lastComponent: Component | undefined, toolGroupSummary = false): ToolRenderContext {\n\t\treturn {\n\t\t\targs: this.args,\n\t\t\ttoolCallId: this.toolCallId,\n\t\t\tinvalidate: () => {\n\t\t\t\tthis.invalidate();\n\t\t\t\tthis.ui.requestRender();\n\t\t\t},\n\t\t\tlastComponent,\n\t\t\tstate: this.rendererState,\n\t\t\tcwd: this.cwd,\n\t\t\texecutionStarted: this.executionStarted,\n\t\t\targsComplete: this.argsComplete,\n\t\t\tisPartial: this.isPartial,\n\t\t\texpanded: this.expanded,\n\t\t\tshowImages: this.showImages,\n\t\t\tisError: this.result?.isError ?? false,\n\t\t\ttoolGroupSummary,\n\t\t};\n\t}\n\n\tprivate humanizeToolName(name: string): string {\n\t\tconst words = name\n\t\t\t.replace(/[_-]+/g, \" \")\n\t\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n\t\t\t.trim()\n\t\t\t.split(/\\s+/)\n\t\t\t.filter(Boolean);\n\t\tif (words.length === 0) return name;\n\t\treturn words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(\" \");\n\t}\n\n\tprivate getDisplayLabel(): string {\n\t\tconst label = (this.toolDefinition?.label ?? this.builtInToolDefinition?.label)?.trim();\n\t\tif (this.builtInToolDefinition) return label || this.toolName;\n\t\tif (!label || label === this.toolName) return this.humanizeToolName(this.toolName);\n\t\treturn label;\n\t}\n\n\tresetInvocation(\n\t\ttoolName: string,\n\t\ttoolCallId: string,\n\t\targs: any,\n\t\ttoolDefinition: ToolDefinition<any, any> | undefined,\n\t): void {\n\t\tthis.toolName = toolName;\n\t\tthis.toolCallId = toolCallId;\n\t\tthis.args = args;\n\t\tthis.toolDefinition = toolDefinition;\n\t\tthis.builtInToolDefinition = createAllToolDefinitions(this.cwd)[toolName as ToolName];\n\t\tthis.toolGroup = this.resolveToolGroup();\n\t\tthis.executionStarted = false;\n\t\tthis.argsComplete = false;\n\t\tthis.isPartial = true;\n\t\tthis.result = undefined;\n\t\tthis.callRendererComponent = undefined;\n\t\tthis.resultRendererComponent = undefined;\n\t\tthis.rendererState = {};\n\t\tthis.convertedImages.clear();\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate titleBadgeStatus(): \"pending\" | \"running\" | \"success\" | \"error\" {\n\t\tif (this.result?.isError) return \"error\";\n\t\tif (this.isPartial) return this.executionStarted ? \"running\" : \"pending\";\n\t\treturn \"success\";\n\t}\n\n\tprivate createCallFallback(): Component {\n\t\treturn titleBadge(theme, {\n\t\t\tlabel: this.getDisplayLabel(),\n\t\t\tstatus: this.titleBadgeStatus(),\n\t\t});\n\t}\n\n\tprivate createResultFallback(): Component | undefined {\n\t\tconst output = this.getTextOutput();\n\t\tif (!output) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn new Text(theme.fg(\"toolOutput\", output), 0, 0);\n\t}\n\n\tupdateArgs(args: any): void {\n\t\tthis.args = args;\n\t\tthis.updateDisplay();\n\t}\n\n\tmarkExecutionStarted(): void {\n\t\tthis.executionStarted = true;\n\t\tthis.updateDisplay();\n\t\tthis.ui.requestRender();\n\t}\n\n\tsetArgsComplete(): void {\n\t\tthis.argsComplete = true;\n\t\tthis.updateDisplay();\n\t\tthis.ui.requestRender();\n\t}\n\n\tupdateResult(\n\t\tresult: {\n\t\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\t\tdetails?: any;\n\t\t\tisError: boolean;\n\t\t},\n\t\tisPartial = false,\n\t): void {\n\t\tthis.result = result;\n\t\tthis.isPartial = isPartial;\n\t\tthis.updateDisplay();\n\t\tthis.maybeConvertImagesForKitty();\n\t}\n\n\tprivate maybeConvertImagesForKitty(): void {\n\t\tconst caps = getCapabilities();\n\t\tif (caps.images !== \"kitty\") return;\n\t\tif (!this.result) return;\n\n\t\tconst imageBlocks = this.result.content.filter((c) => c.type === \"image\");\n\t\tfor (let i = 0; i < imageBlocks.length; i++) {\n\t\t\tconst img = imageBlocks[i];\n\t\t\tif (!img.data || !img.mimeType) continue;\n\t\t\tif (img.mimeType === \"image/png\") continue;\n\t\t\tif (this.convertedImages.has(i)) continue;\n\n\t\t\tconst index = i;\n\t\t\tconvertToPng(img.data, img.mimeType).then((converted) => {\n\t\t\t\tif (converted) {\n\t\t\t\t\tthis.convertedImages.set(index, converted);\n\t\t\t\t\tthis.updateDisplay();\n\t\t\t\t\tthis.ui.requestRender();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetShowImages(show: boolean): void {\n\t\tthis.showImages = show;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetImageWidthCells(width: number): void {\n\t\tthis.imageWidthCells = Math.max(1, Math.floor(width));\n\t\tthis.updateDisplay();\n\t}\n\n\tgetBackgroundColor(): ThemeBg {\n\t\tif (this.isPartial) return \"toolPendingBg\";\n\t\tif (this.result?.isError) return \"toolErrorBg\";\n\t\treturn \"toolSuccessBg\";\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tthis.updateDisplay();\n\t}\n\n\trenderCallSummary(width: number): string[] {\n\t\tconst callRenderer = this.getCallRenderer();\n\t\tlet component: Component;\n\t\tif (!callRenderer) {\n\t\t\tcomponent = this.createCallFallback();\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tcomponent = callRenderer(this.args, theme, this.getRenderContext(undefined, true));\n\t\t\t} catch {\n\t\t\t\tcomponent = this.createCallFallback();\n\t\t\t}\n\t\t}\n\t\treturn component.render(width);\n\t}\n\n\toverride render(width: number): string[] {\n\t\tif (this.hideComponent) {\n\t\t\treturn [];\n\t\t}\n\t\treturn super.render(width);\n\t}\n\n\tprivate updateDisplay(): void {\n\t\tconst bgFn = (text: string) => theme.bg(this.getBackgroundColor(), text);\n\n\t\tlet hasContent = false;\n\t\tthis.hideComponent = false;\n\t\tif (this.hasRendererDefinition()) {\n\t\t\tconst renderContainer = this.getRenderShell() === \"self\" ? this.selfRenderContainer : this.contentBox;\n\t\t\tif (renderContainer instanceof Box) {\n\t\t\t\trenderContainer.setBgFn(bgFn);\n\t\t\t}\n\t\t\trenderContainer.clear();\n\n\t\t\tconst callRenderer = this.getCallRenderer();\n\t\t\tif (!callRenderer) {\n\t\t\t\trenderContainer.addChild(this.createCallFallback());\n\t\t\t\thasContent = true;\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tconst component = callRenderer(this.args, theme, this.getRenderContext(this.callRendererComponent));\n\t\t\t\t\tthis.callRendererComponent = component;\n\t\t\t\t\trenderContainer.addChild(component);\n\t\t\t\t\thasContent = true;\n\t\t\t\t} catch {\n\t\t\t\t\tthis.callRendererComponent = undefined;\n\t\t\t\t\trenderContainer.addChild(this.createCallFallback());\n\t\t\t\t\thasContent = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst resultRenderer = this.getResultRenderer();\n\t\t\t\tif (!resultRenderer) {\n\t\t\t\t\tconst component = this.createResultFallback();\n\t\t\t\t\tif (component) {\n\t\t\t\t\t\trenderContainer.addChild(component);\n\t\t\t\t\t\thasContent = true;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst component = resultRenderer(\n\t\t\t\t\t\t\t{ content: this.result.content as any, details: this.result.details },\n\t\t\t\t\t\t\t{ expanded: this.expanded, isPartial: this.isPartial },\n\t\t\t\t\t\t\ttheme,\n\t\t\t\t\t\t\tthis.getRenderContext(this.resultRendererComponent),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.resultRendererComponent = component;\n\t\t\t\t\t\trenderContainer.addChild(component);\n\t\t\t\t\t\thasContent = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tthis.resultRendererComponent = undefined;\n\t\t\t\t\t\tconst component = this.createResultFallback();\n\t\t\t\t\t\tif (component) {\n\t\t\t\t\t\t\trenderContainer.addChild(component);\n\t\t\t\t\t\t\thasContent = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t\thasContent = true;\n\t\t}\n\n\t\tfor (const img of this.imageComponents) {\n\t\t\tthis.removeChild(img);\n\t\t}\n\t\tthis.imageComponents = [];\n\t\tfor (const spacer of this.imageSpacers) {\n\t\t\tthis.removeChild(spacer);\n\t\t}\n\t\tthis.imageSpacers = [];\n\n\t\tif (this.result) {\n\t\t\tconst imageBlocks = this.result.content.filter((c) => c.type === \"image\");\n\t\t\tconst caps = getCapabilities();\n\t\t\tfor (let i = 0; i < imageBlocks.length; i++) {\n\t\t\t\tconst img = imageBlocks[i];\n\t\t\t\tif (caps.images && this.showImages && img.data && img.mimeType) {\n\t\t\t\t\tconst converted = this.convertedImages.get(i);\n\t\t\t\t\tconst imageData = converted?.data ?? img.data;\n\t\t\t\t\tconst imageMimeType = converted?.mimeType ?? img.mimeType;\n\t\t\t\t\tif (caps.images === \"kitty\" && imageMimeType !== \"image/png\") continue;\n\n\t\t\t\t\tconst spacer = new Spacer(1);\n\t\t\t\t\tthis.addChild(spacer);\n\t\t\t\t\tthis.imageSpacers.push(spacer);\n\t\t\t\t\tconst imageComponent = new Image(\n\t\t\t\t\t\timageData,\n\t\t\t\t\t\timageMimeType,\n\t\t\t\t\t\t{ fallbackColor: (s: string) => theme.fg(\"toolOutput\", s) },\n\t\t\t\t\t\t{ maxWidthCells: this.imageWidthCells },\n\t\t\t\t\t);\n\t\t\t\t\tthis.imageComponents.push(imageComponent);\n\t\t\t\t\tthis.addChild(imageComponent);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (this.hasRendererDefinition() && !hasContent && this.imageComponents.length === 0) {\n\t\t\tthis.hideComponent = true;\n\t\t}\n\t}\n\n\tprivate getTextOutput(): string {\n\t\treturn getRenderedTextOutput(this.result, this.showImages);\n\t}\n\n\tprivate formatToolExecution(): string {\n\t\tlet text = renderTitleBadge(theme, {\n\t\t\tlabel: this.getDisplayLabel(),\n\t\t\tstatus: this.titleBadgeStatus(),\n\t\t});\n\t\tconst content = JSON.stringify(this.args, null, 2);\n\t\tif (content) {\n\t\t\ttext += `\\n\\n${content}`;\n\t\t}\n\t\tconst output = this.getTextOutput();\n\t\tif (output) {\n\t\t\ttext += `\\n${output}`;\n\t\t}\n\t\treturn text;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool-execution.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/tool-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAAwC,KAAK,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACpH,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,mCAAmC,CAAC;AAM3F,OAAO,EAAE,KAAK,OAAO,EAAS,MAAM,mBAAmB,CAAC;AAGxD,MAAM,WAAW,oBAAoB;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAeD,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,mBAAmB,CAAY;IACvC,OAAO,CAAC,qBAAqB,CAAC,CAAY;IAC1C,OAAO,CAAC,uBAAuB,CAAC,CAAY;IAC5C,OAAO,CAAC,aAAa,CAAW;IAChC,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,cAAc,CAAC,CAA2B;IAClD,OAAO,CAAC,qBAAqB,CAAC,CAA2B;IACzD,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,CAAC,EAAE,CAAM;IAChB,OAAO,CAAC,G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,EAAE,OAAO,CAAC;KACjB,EACD,SAAS,UAAQ,GACf,IAAI,CASN;IAED,OAAO,CAAC,0BAA0B;IAuBlC,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAGnC;IAED,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAGjC;IAED,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAGtC;IAED,kBAAkB,IAAI,OAAO,CAI5B;IAEQ,UAAU,IAAI,IAAI,CAG1B;IAED,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAazC;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAKvC;IAED,OAAO,CAAC,aAAa;IAwGrB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,mBAAmB;CAsB3B","sourcesContent":["import { Box, type Component, Container, getCapabilities, Image, Spacer, Text, type TUI } from \"@caupulican/pi-tui\";\nimport type { ToolDefinition, ToolRenderContext } from \"../../../core/extensions/types.ts\";\nimport { compactRetainedDetails, MAX_TUI_RETAINED_DETAILS_BYTES } from \"../../../core/message-retention.ts\";\nimport { createAllToolDefinitions, type ToolName } from \"../../../core/tools/index.ts\";\nimport { getTextOutput as getRenderedTextOutput } from \"../../../core/tools/render-utils.ts\";\nimport { truncateHead } from \"../../../core/tools/truncate.ts\";\nimport { convertToPng } from \"../../../utils/image-convert.ts\";\nimport { type ThemeBg, theme } from \"../theme/theme.ts\";\nimport { renderTitleBadge, titleBadge } from \"./tool-title.ts\";\n\nexport interface ToolExecutionOptions {\n\tshowImages?: boolean;\n\timageWidthCells?: number;\n}\n\n// Components only use built-in definitions for display (renderers, grouping), so one\n// toolset per cwd is shared instead of allocating a full toolset per scrollback component.\nconst builtInDefinitionsByCwd = new Map<string, ReturnType<typeof createAllToolDefinitions>>();\n\nfunction getBuiltInToolDefinitions(cwd: string): ReturnType<typeof createAllToolDefinitions> {\n\tlet definitions = builtInDefinitionsByCwd.get(cwd);\n\tif (!definitions) {\n\t\tdefinitions = createAllToolDefinitions(cwd);\n\t\tbuiltInDefinitionsByCwd.set(cwd, definitions);\n\t}\n\treturn definitions;\n}\n\nexport class ToolExecutionComponent extends Container {\n\tprivate contentBox: Box;\n\tprivate contentText: Text;\n\tprivate selfRenderContainer: Container;\n\tprivate callRendererComponent?: Component;\n\tprivate resultRendererComponent?: Component;\n\tprivate rendererState: any = {};\n\tprivate imageComponents: Image[] = [];\n\tprivate imageSpacers: Spacer[] = [];\n\tprivate toolName: string;\n\tprivate toolCallId: string;\n\tprivate args: any;\n\tprivate expanded = false;\n\tprivate showImages: boolean;\n\tprivate imageWidthCells: number;\n\tprivate isPartial = true;\n\tprivate toolDefinition?: ToolDefinition<any, any>;\n\tprivate builtInToolDefinition?: ToolDefinition<any, any>;\n\ttoolGroup: string | undefined;\n\tprivate ui: TUI;\n\tprivate cwd: string;\n\tprivate executionStarted = false;\n\tprivate argsComplete = false;\n\tprivate result?: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tisError: boolean;\n\t\tdetails?: any;\n\t};\n\tprivate convertedImages: Map<number, { data: string; mimeType: string }> = new Map();\n\tprivate hideComponent = false;\n\n\tconstructor(\n\t\ttoolName: string,\n\t\ttoolCallId: string,\n\t\targs: any,\n\t\toptions: ToolExecutionOptions = {},\n\t\ttoolDefinition: ToolDefinition<any, any> | undefined,\n\t\tui: TUI,\n\t\tcwd: string,\n\t) {\n\t\tsuper();\n\t\tthis.toolName = toolName;\n\t\tthis.toolCallId = toolCallId;\n\t\tthis.args = args;\n\t\tthis.toolDefinition = toolDefinition;\n\t\tthis.builtInToolDefinition = getBuiltInToolDefinitions(cwd)[toolName as ToolName];\n\t\tthis.toolGroup = this.resolveToolGroup();\n\t\tthis.showImages = options.showImages ?? true;\n\t\tthis.imageWidthCells = options.imageWidthCells ?? 60;\n\t\tthis.ui = ui;\n\t\tthis.cwd = cwd;\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Always create all shell variants. contentBox is used for default renderer-based composition.\n\t\t// selfRenderContainer is used when the tool renders its own framing.\n\t\t// contentText is reserved for generic fallback rendering when no tool definition exists.\n\t\tthis.contentBox = new Box(1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\t\tthis.contentText = new Text(\"\", 1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\t\tthis.selfRenderContainer = new Container();\n\n\t\tif (this.hasRendererDefinition()) {\n\t\t\tthis.addChild(this.getRenderShell() === \"self\" ? this.selfRenderContainer : this.contentBox);\n\t\t} else {\n\t\t\tthis.addChild(this.contentText);\n\t\t}\n\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate getCallRenderer(): ToolDefinition<any, any>[\"renderCall\"] | undefined {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderCall;\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderCall;\n\t\t}\n\t\treturn this.toolDefinition.renderCall ?? this.builtInToolDefinition.renderCall;\n\t}\n\n\tprivate getResultRenderer(): ToolDefinition<any, any>[\"renderResult\"] | undefined {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderResult;\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderResult;\n\t\t}\n\t\treturn this.toolDefinition.renderResult ?? this.builtInToolDefinition.renderResult;\n\t}\n\n\tprivate hasRendererDefinition(): boolean {\n\t\treturn this.builtInToolDefinition !== undefined || this.toolDefinition !== undefined;\n\t}\n\n\tprivate getRenderShell(): \"default\" | \"self\" {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderShell ?? \"default\";\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderShell ?? \"default\";\n\t\t}\n\t\treturn this.toolDefinition.renderShell ?? this.builtInToolDefinition.renderShell ?? \"default\";\n\t}\n\n\tprivate resolveToolGroup(): string | undefined {\n\t\tconst configuredGroup = this.toolDefinition?.toolGroup ?? this.builtInToolDefinition?.toolGroup;\n\t\tif (configuredGroup !== undefined) {\n\t\t\tconst trimmed = configuredGroup.trim();\n\t\t\treturn trimmed || undefined;\n\t\t}\n\t\tconst defaultGroup = this.toolName.trim();\n\t\treturn defaultGroup || undefined;\n\t}\n\n\tprivate getRenderContext(lastComponent: Component | undefined, toolGroupSummary = false): ToolRenderContext {\n\t\treturn {\n\t\t\targs: this.args,\n\t\t\ttoolCallId: this.toolCallId,\n\t\t\tinvalidate: () => {\n\t\t\t\tthis.invalidate();\n\t\t\t\tthis.ui.requestRender();\n\t\t\t},\n\t\t\tlastComponent,\n\t\t\tstate: this.rendererState,\n\t\t\tcwd: this.cwd,\n\t\t\texecutionStarted: this.executionStarted,\n\t\t\targsComplete: this.argsComplete,\n\t\t\tisPartial: this.isPartial,\n\t\t\texpanded: this.expanded,\n\t\t\tshowImages: this.showImages,\n\t\t\tisError: this.result?.isError ?? false,\n\t\t\ttoolGroupSummary,\n\t\t};\n\t}\n\n\tprivate humanizeToolName(name: string): string {\n\t\tconst words = name\n\t\t\t.replace(/[_-]+/g, \" \")\n\t\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n\t\t\t.trim()\n\t\t\t.split(/\\s+/)\n\t\t\t.filter(Boolean);\n\t\tif (words.length === 0) return name;\n\t\treturn words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(\" \");\n\t}\n\n\tprivate getDisplayLabel(): string {\n\t\tconst label = (this.toolDefinition?.label ?? this.builtInToolDefinition?.label)?.trim();\n\t\tif (this.builtInToolDefinition) return label || this.toolName;\n\t\tif (!label || label === this.toolName) return this.humanizeToolName(this.toolName);\n\t\treturn label;\n\t}\n\n\tresetInvocation(\n\t\ttoolName: string,\n\t\ttoolCallId: string,\n\t\targs: any,\n\t\ttoolDefinition: ToolDefinition<any, any> | undefined,\n\t): void {\n\t\tthis.toolName = toolName;\n\t\tthis.toolCallId = toolCallId;\n\t\tthis.args = args;\n\t\tthis.toolDefinition = toolDefinition;\n\t\tthis.builtInToolDefinition = getBuiltInToolDefinitions(this.cwd)[toolName as ToolName];\n\t\tthis.toolGroup = this.resolveToolGroup();\n\t\tthis.executionStarted = false;\n\t\tthis.argsComplete = false;\n\t\tthis.isPartial = true;\n\t\tthis.result = undefined;\n\t\tthis.callRendererComponent = undefined;\n\t\tthis.resultRendererComponent = undefined;\n\t\tthis.rendererState = {};\n\t\tthis.convertedImages.clear();\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate titleBadgeStatus(): \"pending\" | \"running\" | \"success\" | \"error\" {\n\t\tif (this.result?.isError) return \"error\";\n\t\tif (this.isPartial) return this.executionStarted ? \"running\" : \"pending\";\n\t\treturn \"success\";\n\t}\n\n\tprivate createCallFallback(): Component {\n\t\treturn titleBadge(theme, {\n\t\t\tlabel: this.getDisplayLabel(),\n\t\t\tstatus: this.titleBadgeStatus(),\n\t\t});\n\t}\n\n\tprivate createResultFallback(): Component | undefined {\n\t\tconst output = this.getTextOutput();\n\t\tif (!output) {\n\t\t\treturn undefined;\n\t\t}\n\t\t// The fallback also serves results whose custom renderer threw; without a\n\t\t// display bound, a renderer bug degrades into dumping the full payload.\n\t\tconst truncation = truncateHead(output);\n\t\tif (!truncation.truncated) {\n\t\t\treturn new Text(theme.fg(\"toolOutput\", output), 0, 0);\n\t\t}\n\t\tconst note = theme.fg(\n\t\t\t\"dim\",\n\t\t\t`[output truncated for display: showing ${truncation.outputLines} lines; the full result is retained in the conversation]`,\n\t\t);\n\t\treturn new Text(`${theme.fg(\"toolOutput\", truncation.content)}\\n${note}`, 0, 0);\n\t}\n\n\tupdateArgs(args: any): void {\n\t\tthis.args = args;\n\t\tthis.updateDisplay();\n\t}\n\n\tmarkExecutionStarted(): void {\n\t\tthis.executionStarted = true;\n\t\tthis.updateDisplay();\n\t\tthis.ui.requestRender();\n\t}\n\n\tsetArgsComplete(): void {\n\t\tthis.argsComplete = true;\n\t\tthis.updateDisplay();\n\t\tthis.ui.requestRender();\n\t}\n\n\tupdateResult(\n\t\tresult: {\n\t\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\t\tdetails?: any;\n\t\t\tisError: boolean;\n\t\t},\n\t\tisPartial = false,\n\t): void {\n\t\t// Final results live in the chat scrollback for the rest of the process.\n\t\t// Oversized details would pin large payloads per tool call, so retain the\n\t\t// same compacted form a resumed session would see.\n\t\tif (!isPartial) compactRetainedDetails(result, MAX_TUI_RETAINED_DETAILS_BYTES);\n\t\tthis.result = result;\n\t\tthis.isPartial = isPartial;\n\t\tthis.updateDisplay();\n\t\tthis.maybeConvertImagesForKitty();\n\t}\n\n\tprivate maybeConvertImagesForKitty(): void {\n\t\tconst caps = getCapabilities();\n\t\tif (caps.images !== \"kitty\") return;\n\t\tif (!this.result) return;\n\n\t\tconst imageBlocks = this.result.content.filter((c) => c.type === \"image\");\n\t\tfor (let i = 0; i < imageBlocks.length; i++) {\n\t\t\tconst img = imageBlocks[i];\n\t\t\tif (!img.data || !img.mimeType) continue;\n\t\t\tif (img.mimeType === \"image/png\") continue;\n\t\t\tif (this.convertedImages.has(i)) continue;\n\n\t\t\tconst index = i;\n\t\t\tconvertToPng(img.data, img.mimeType).then((converted) => {\n\t\t\t\tif (converted) {\n\t\t\t\t\tthis.convertedImages.set(index, converted);\n\t\t\t\t\tthis.updateDisplay();\n\t\t\t\t\tthis.ui.requestRender();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetShowImages(show: boolean): void {\n\t\tthis.showImages = show;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetImageWidthCells(width: number): void {\n\t\tthis.imageWidthCells = Math.max(1, Math.floor(width));\n\t\tthis.updateDisplay();\n\t}\n\n\tgetBackgroundColor(): ThemeBg {\n\t\tif (this.isPartial) return \"toolPendingBg\";\n\t\tif (this.result?.isError) return \"toolErrorBg\";\n\t\treturn \"toolSuccessBg\";\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tthis.updateDisplay();\n\t}\n\n\trenderCallSummary(width: number): string[] {\n\t\tconst callRenderer = this.getCallRenderer();\n\t\tlet component: Component;\n\t\tif (!callRenderer) {\n\t\t\tcomponent = this.createCallFallback();\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tcomponent = callRenderer(this.args, theme, this.getRenderContext(undefined, true));\n\t\t\t} catch {\n\t\t\t\tcomponent = this.createCallFallback();\n\t\t\t}\n\t\t}\n\t\treturn component.render(width);\n\t}\n\n\toverride render(width: number): string[] {\n\t\tif (this.hideComponent) {\n\t\t\treturn [];\n\t\t}\n\t\treturn super.render(width);\n\t}\n\n\tprivate updateDisplay(): void {\n\t\tconst bgFn = (text: string) => theme.bg(this.getBackgroundColor(), text);\n\n\t\tlet hasContent = false;\n\t\tthis.hideComponent = false;\n\t\tif (this.hasRendererDefinition()) {\n\t\t\tconst renderContainer = this.getRenderShell() === \"self\" ? this.selfRenderContainer : this.contentBox;\n\t\t\tif (renderContainer instanceof Box) {\n\t\t\t\trenderContainer.setBgFn(bgFn);\n\t\t\t}\n\t\t\trenderContainer.clear();\n\n\t\t\tconst callRenderer = this.getCallRenderer();\n\t\t\tif (!callRenderer) {\n\t\t\t\trenderContainer.addChild(this.createCallFallback());\n\t\t\t\thasContent = true;\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tconst component = callRenderer(this.args, theme, this.getRenderContext(this.callRendererComponent));\n\t\t\t\t\tthis.callRendererComponent = component;\n\t\t\t\t\trenderContainer.addChild(component);\n\t\t\t\t\thasContent = true;\n\t\t\t\t} catch {\n\t\t\t\t\tthis.callRendererComponent = undefined;\n\t\t\t\t\trenderContainer.addChild(this.createCallFallback());\n\t\t\t\t\thasContent = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst resultRenderer = this.getResultRenderer();\n\t\t\t\tif (!resultRenderer) {\n\t\t\t\t\tconst component = this.createResultFallback();\n\t\t\t\t\tif (component) {\n\t\t\t\t\t\trenderContainer.addChild(component);\n\t\t\t\t\t\thasContent = true;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst component = resultRenderer(\n\t\t\t\t\t\t\t{ content: this.result.content as any, details: this.result.details },\n\t\t\t\t\t\t\t{ expanded: this.expanded, isPartial: this.isPartial },\n\t\t\t\t\t\t\ttheme,\n\t\t\t\t\t\t\tthis.getRenderContext(this.resultRendererComponent),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.resultRendererComponent = component;\n\t\t\t\t\t\trenderContainer.addChild(component);\n\t\t\t\t\t\thasContent = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tthis.resultRendererComponent = undefined;\n\t\t\t\t\t\tconst component = this.createResultFallback();\n\t\t\t\t\t\tif (component) {\n\t\t\t\t\t\t\trenderContainer.addChild(component);\n\t\t\t\t\t\t\thasContent = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t\thasContent = true;\n\t\t}\n\n\t\tfor (const img of this.imageComponents) {\n\t\t\tthis.removeChild(img);\n\t\t}\n\t\tthis.imageComponents = [];\n\t\tfor (const spacer of this.imageSpacers) {\n\t\t\tthis.removeChild(spacer);\n\t\t}\n\t\tthis.imageSpacers = [];\n\n\t\tif (this.result) {\n\t\t\tconst imageBlocks = this.result.content.filter((c) => c.type === \"image\");\n\t\t\tconst caps = getCapabilities();\n\t\t\tfor (let i = 0; i < imageBlocks.length; i++) {\n\t\t\t\tconst img = imageBlocks[i];\n\t\t\t\tif (caps.images && this.showImages && img.data && img.mimeType) {\n\t\t\t\t\tconst converted = this.convertedImages.get(i);\n\t\t\t\t\tconst imageData = converted?.data ?? img.data;\n\t\t\t\t\tconst imageMimeType = converted?.mimeType ?? img.mimeType;\n\t\t\t\t\tif (caps.images === \"kitty\" && imageMimeType !== \"image/png\") continue;\n\n\t\t\t\t\tconst spacer = new Spacer(1);\n\t\t\t\t\tthis.addChild(spacer);\n\t\t\t\t\tthis.imageSpacers.push(spacer);\n\t\t\t\t\tconst imageComponent = new Image(\n\t\t\t\t\t\timageData,\n\t\t\t\t\t\timageMimeType,\n\t\t\t\t\t\t{ fallbackColor: (s: string) => theme.fg(\"toolOutput\", s) },\n\t\t\t\t\t\t{ maxWidthCells: this.imageWidthCells },\n\t\t\t\t\t);\n\t\t\t\t\tthis.imageComponents.push(imageComponent);\n\t\t\t\t\tthis.addChild(imageComponent);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (this.hasRendererDefinition() && !hasContent && this.imageComponents.length === 0) {\n\t\t\tthis.hideComponent = true;\n\t\t}\n\t}\n\n\tprivate getTextOutput(): string {\n\t\treturn getRenderedTextOutput(this.result, this.showImages);\n\t}\n\n\tprivate formatToolExecution(): string {\n\t\tlet text = renderTitleBadge(theme, {\n\t\t\tlabel: this.getDisplayLabel(),\n\t\t\tstatus: this.titleBadgeStatus(),\n\t\t});\n\t\tconst content = JSON.stringify(this.args, null, 2);\n\t\tif (content) {\n\t\t\ttext += `\\n\\n${content}`;\n\t\t}\n\t\tconst output = this.getTextOutput();\n\t\tif (output) {\n\t\t\t// Same display bound as createResultFallback: unknown tools must not\n\t\t\t// dump arbitrarily large payloads into the scrollback.\n\t\t\tconst truncation = truncateHead(output);\n\t\t\tif (truncation.truncated) {\n\t\t\t\ttext += `\\n${truncation.content}\\n${theme.fg(\"dim\", `[output truncated for display: showing ${truncation.outputLines} lines; the full result is retained in the conversation]`)}`;\n\t\t\t} else {\n\t\t\t\ttext += `\\n${output}`;\n\t\t\t}\n\t\t}\n\t\treturn text;\n\t}\n}\n"]}
|