Implementation:1broseidon Ketch pi render
| Knowledge Sources | |
|---|---|
| Domains | Agent_Integration, TUI |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
The pi output rendering helpers: UI-only projections that never mutate tool content/details, render remote content as inert Text (not Markdown), strip terminal control sequences and bidi overrides, and bound both call and result displays independently of the model response size.
Description
`plugins/pi/extensions/render.ts` is the render layer for the pi ketch_* tool adapters (Implementation:1broseidon_Ketch_pi_ketch_tools). It is strictly UI-only: the model keeps the complete CLI response; rendering is a lossy projection for the terminal. safeText strips ANSI/OSC/DCS sequences, C0/C1 controls, and invisible bidi overrides (U+202A–U+202E, U+2066–U+2069) so a hostile page cannot inject terminal control sequences into the TUI. preview collapses whitespace and truncates with an ellipsis.
callSummary builds a one-line call display from the surface and args (query/url, plus options like `backend=… · limit=… · scrape`), bounded at 260 chars. resultSummary builds a compact result display: it detects the row shape (`results`/`pages`/`tags`/`libraries` arrays, or a single object), previews at most 4 rows with `+N more`, counts errors/warnings, and reports `stopped` reason — all bounded independently of the model response size. fullDetails preserves the original text (including warnings) and shows the full structured response once, without truncation, on expand. The renderers factory wires `renderCall` and `renderResult` for one surface.
Usage
Imported by `ketch.ts`; called by the pi TUI when rendering a ketch_* tool call or result. Never mutates content; only projects it.
Code Reference
Source Location
- Repository: ketch
- File: plugins/pi/extensions/render.ts
- Lines: 1-148
Signature
export type Surface = "search" | "code" | "docs" | "scrape" | "crawl" | "tag";
export function safeText(value: unknown): string
export function preview(value: unknown, limit?: number): string
export function callSummary(surface: Surface, args: unknown): string
export function resultSummary(surface: Surface, result: DisplayResult, isError?: boolean): string[]
export function fullDetails(result: DisplayResult): string
export function renderers(surface: Surface): ToolRenderers
Import
import { renderers, safeText, preview, callSummary, resultSummary, fullDetails } from "./render";
import type { Surface } from "./render";
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| surface | Surface | Yes | One of search/code/docs/scrape/crawl/tag |
| args | unknown | `callSummary` yes | Pi tool arguments object |
| result | DisplayResult | `resultSummary`/`fullDetails` yes | {content, details, isError} |
| isError | boolean | No | Renders "Failed" + bounded error text |
Outputs
| Name | Type | Description |
|---|---|---|
| safeText returns | string | Control-sequence-free text |
| resultSummary returns | string[] | Bounded lines (≤4 rows, +N more, errors, warnings) |
| renderers returns | ToolRenderers | {renderCall, renderResult} for the surface |
Usage Examples
Render a call summary
const summary = callSummary("search", { query: "ripgrep", limit: 5, backend: "brave" });
// "ripgrep · backend=brave · limit=5" (bounded at 260 chars)
Render a result (bounded)
const lines = resultSummary("search", result);
// ["3 results", "1. Title · host", " snippet…", "+2 more"]