/** * OpenCode-style tool rows: one line per call, details on expand (ctrl+o). * * 󰧮 Read src/app.ts 120 lines * 󰏫 Edit src/app.ts +12 -3 * 󰆍 pnpm test exit 0 · 2.1s * 󰍉 Grep "TODO" in src 14 matches * * The rows are drawn by a renderer resolver (`pi.registerToolRenderer`), which chooses how calls to * a tool are drawn without touching the tool: pi's own definitions for read, bash, edit, write, * grep, find and ls, with their settings and the active tool set, stay as they are. Tools that * belong to other extensions are drawn the same way when that extension registered a row spec for * them (`registerToolRows` in api.ts); chassis knows no tool but pi's built-in ones by name. * * Everything shown comes from tool arguments and results, which a file, a web page or a model can * influence, so each piece of text is cleaned of escape sequences and control characters before it * is drawn (sanitize.ts). */ import { type ExtensionAPI, type Theme } from "@earendil-works/pi-coding-agent"; import { type Component } from "@earendil-works/pi-tui"; import { type ToolRowSpec } from "./api.ts"; import { type IconLike, type IconName } from "./icons.ts"; /** The icon name per tool (icons.ts has the glyph for each set, one cell wide). */ export declare const TOOL_ICONS: { readonly read: "toolRead"; readonly write: "toolWrite"; readonly edit: "toolEdit"; readonly bash: "toolBash"; readonly grep: "toolGrep"; readonly find: "toolFind"; readonly ls: "toolLs"; }; /** * How a tool row is drawn: * plain one unshaded line, the icon and text with a dim summary * block a shaded, padded block holding the command and its output * bar a shaded one-liner with unshaded output beneath it */ export type RowShape = "plain" | "block" | "bar"; /** * The one rule for a row's shape, used for every stage of a call so it never changes shape without * a reason: a call is a plain line until it has output to show or has failed, then a block for the * rest of its life. Tools without a block look (no peek and no live view) are plain, or a bar once * they have a body or an error, as before. */ export declare function rowShape(opts: { blockTool: boolean; hasBody: boolean; isError: boolean; expanded: boolean; sawBody: boolean; }): RowShape; /** Lines in a file's text: a final newline ends the last line, it does not start another. */ export declare function countLines(text: unknown): number; /** What a renderer knows beyond the result: its shared state and how long the call ran. */ interface RenderExtra { isError: boolean; /** Seconds from the first partial result to the last, when the renderer saw both. */ seconds?: number; } /** How one tool is drawn. Exported for tests. */ export interface Spec { /** An icon name (see TOOL_ICONS); the glyph is looked up when the row is drawn. */ icon?: IconName; /** A glyph supplied by another extension, already cleaned (see `fromRowSpec`). Wins over `icon`. */ iconLike?: IconLike; title: string; describe: (args: any, cwd: string, theme: Theme) => string; summarize: (result: any, args: any, theme: Theme, isError: boolean, extra?: RenderExtra) => string; expand?: (result: any, args: any, theme: Theme, extra?: RenderExtra) => string[]; /** * Body lines while the call is still running, from the partial result so far. Return undefined * for nothing yet. `expanded` is whether the row was opened with ctrl+o. */ live?: (partial: any, theme: Theme, expanded: boolean) => string[] | undefined; /** * Body lines left under a finished row while it is collapsed (the last lines of output, and a * hint for opening the rest). Return undefined for none. Rows with a peek draw as a shaded block. */ peek?: (result: any, args: any, theme: Theme, extra?: RenderExtra) => string[] | undefined; } /** Exported for tests. */ export declare const SPECS: Record; /** Exported for tests: the renderers for one tool spec. */ export declare function makeRenderers(spec: Spec, getCwd: () => string): { /** * Call row: shown until the first result arrives. pi renders call then result into the same * shell on every update, so renderResult hides the call row (shared via context.state). */ renderCall(args: any, theme: Theme, context: any): Component; renderResult(result: any, options: { expanded: boolean; isPartial: boolean; }, theme: Theme, context: any): Component; }; /** * An internal spec for a row spec another extension registered. Everything the spec returns is * cleaned here, so the row code below never sees raw text from outside. Exported for tests. */ export declare function fromRowSpec(row: ToolRowSpec): Spec; /** * Draw the built-in tools with chassis's rows, and any other tool whose extension registered a row * spec (`registerToolRows`). A resolver answers for these * names and passes every other tool to `next()`, so pi keeps the tool definitions, their settings * (shell prefix, shell path, image resizing) and which tools are active; only the drawing changes. * The resolver wins over a tool's own renderers. Chassis's own specs win over a registered spec of * the same name. The registered specs are looked up when a call first appears, so load order does * not matter. A spec that has failed on several finished calls is skipped and the tool is drawn by * its own renderers, shell included. */ export declare function installToolRenderers(pi: ExtensionAPI): void; export {};