UNPKG

@earendil-works/pi-coding-agent

Version:

Coding agent CLI with read, bash, edit, write tools and session management

64 lines • 2.83 kB
/** * Presentation for the find tool. * * Renderers live apart from the implementation so a process that only displays tool output does not * load the execution path or its typebox parameter schema. `find.ts` spreads these into its * definition, so the tool's public shape is unchanged. */ import { Text } from "@earendil-works/pi-tui"; import { keyHint } from "../../../modes/interactive/components/keybinding-hints.js"; import { getTextOutput, invalidArgText, shortenPath, str } from "../render-utils.js"; import { DEFAULT_MAX_BYTES, formatSize } from "../truncate.js"; function formatFindCall(args, theme) { const pattern = str(args?.pattern); const rawPath = str(args?.path); const path = rawPath !== null ? shortenPath(rawPath || ".") : null; const limit = args?.limit; const invalidArg = invalidArgText(theme); let text = theme.fg("toolTitle", theme.bold("find")) + " " + (pattern === null ? invalidArg : theme.fg("accent", pattern || "")) + theme.fg("toolOutput", ` in ${path === null ? invalidArg : path}`); if (limit !== undefined) { text += theme.fg("toolOutput", ` (limit ${limit})`); } return text; } function formatFindResult(result, options, theme, showImages) { const output = getTextOutput(result, showImages).trim(); let text = ""; if (output) { const lines = output.split("\n"); const maxLines = options.expanded ? lines.length : 20; const displayLines = lines.slice(0, maxLines); const remaining = lines.length - maxLines; text += `\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`; if (remaining > 0) { text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")}${theme.fg("muted", ")")}`; } } const resultLimit = result.details?.resultLimitReached; const truncation = result.details?.truncation; if (resultLimit || truncation?.truncated) { const warnings = []; if (resultLimit) warnings.push(`${resultLimit} results limit`); if (truncation?.truncated) warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`); text += `\n${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`; } return text; } export const findRenderers = { renderCall(args, theme, context) { const text = context.lastComponent ?? new Text("", 0, 0); text.setText(formatFindCall(args, theme)); return text; }, renderResult(result, options, theme, context) { const text = context.lastComponent ?? new Text("", 0, 0); text.setText(formatFindResult(result, options, theme, context.showImages)); return text; }, }; //# sourceMappingURL=find.js.map