Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1broseidon Ketch pi render

From Leeroopedia
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

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"]

Related Pages

Implements Principle

Uses Heuristic

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment