/** * Shared utilities and constants for tool renderers. * * Provides consistent formatting, truncation, and display patterns across all * tool renderers to ensure a unified TUI experience. */ import type { ToolCallContext } from "@oh-my-pi/pi-agent-core"; import type { Ellipsis } from "@oh-my-pi/pi-natives"; import type { Component } from "@oh-my-pi/pi-tui"; import type { Theme } from "../modes/theme/theme"; import { type ResizedImage } from "../utils/image-resize"; export { Ellipsis } from "@oh-my-pi/pi-natives"; export { replaceTabs, truncateToWidth, wrapTextWithAnsi } from "@oh-my-pi/pi-tui"; /** Resolve inline image dimension caps from settings and viewport. */ export declare function resolveImageOptions(): { maxWidthCells: number; maxHeightCells?: number; }; /** Preview limits for collapsed/expanded views */ export declare const PREVIEW_LIMITS: { /** Lines shown in collapsed view */ readonly COLLAPSED_LINES: 3; /** Lines shown in expanded view */ readonly EXPANDED_LINES: 12; /** Items (files, results) shown in collapsed view */ readonly COLLAPSED_ITEMS: 8; /** Output preview lines in collapsed view */ readonly OUTPUT_COLLAPSED: 3; /** Output preview lines in expanded view */ readonly OUTPUT_EXPANDED: 10; /** Max hunks shown when collapsed (edit tool) */ readonly DIFF_COLLAPSED_HUNKS: 8; /** Max diff lines shown when collapsed (edit tool) */ readonly DIFF_COLLAPSED_LINES: 40; }; /** Truncation lengths for different content types */ export declare const TRUNCATE_LENGTHS: { /** Short titles, labels */ readonly TITLE: 60; /** Medium-length content (messages, previews) */ readonly CONTENT: 80; /** Longer content (code, explanations) */ readonly LONG: 100; /** Full line content */ readonly LINE: 110; /** Very short (task previews, badges) */ readonly SHORT: 40; }; /** Standard expand hint text */ export declare const EXPAND_HINT = "(Ctrl+O for more)"; /** * Get first N lines of text as preview, with each line truncated. */ export declare function getPreviewLines(text: string, maxLines: number, maxLineLen: number, ellipsis?: Ellipsis): string[]; /** * Extract domain from URL, stripping www. prefix. */ export declare function getDomain(url: string): string; export { formatAge, formatBytes, formatCount, formatDuration, pluralize } from "@oh-my-pi/pi-utils"; /** * Get the appropriate status icon with color for a given state. * Standardizes status icon usage across all renderers. */ export declare function formatStatusIcon(status: ToolUIStatus, theme: Theme, spinnerFrame?: number): string; /** * Format the expand hint with proper theming. * Returns empty string if already expanded or there is nothing more to show. */ export declare function formatExpandHint(theme: Theme, expanded?: boolean, hasMore?: boolean): string; /** * Format a badge like [done] or [failed] with brackets and color. */ export declare function formatBadge(label: string, color: ToolUIColor, theme: Theme): string; /** * Build a "more items" suffix line for truncated lists. * Uses consistent wording pattern. */ export declare function formatMoreItems(remaining: number, itemType: string): string; export declare function formatMeta(meta: string[], theme: Theme): string; export declare function formatErrorMessage(message: string | undefined, theme: Theme): string; export declare function formatEmptyMessage(message: string, theme: Theme): string; export type CodeFrameMarker = "" | " " | "*" | "+" | "-" | ">"; export declare function formatCodeFrameLine(marker: CodeFrameMarker, lineNumber: string | number, content: string, lineNumberWidth: number): string; export type ToolUIStatus = "success" | "error" | "warning" | "info" | "pending" | "running" | "aborted"; export type ToolUIColor = "success" | "error" | "warning" | "accent" | "muted"; export interface ToolUITitleOptions { bold?: boolean; } export declare function formatTitle(label: string, theme: Theme, options?: ToolUITitleOptions): string; export declare function formatDiagnostics(diag: { errored: boolean; summary: string; messages: string[]; }, expanded: boolean, theme: Theme, getLangIcon: (filePath: string) => string): string; export interface DiffStats { added: number; removed: number; hunks: number; lines: number; } export declare function getDiffStats(diffText: string): DiffStats; export declare function formatDiffStats(added: number, removed: number, hunks: number, theme: Theme): string; export declare function truncateDiffByHunk(diffText: string, maxHunks: number, maxLines: number): { text: string; hiddenHunks: number; hiddenLines: number; }; export declare function shortenPath(filePath: string, homeDir?: string): string; export declare function formatToolWorkingDirectory(workdir: string | undefined, projectDir: string): string | undefined; export declare function formatScreenshot(opts: { saveFullRes: boolean; savedMimeType: string; savedByteLength: number; dest: string; resized: ResizedImage; }): string[]; export declare function wrapBrackets(text: string, theme: Theme): string; export declare const PARSE_ERRORS_LIMIT = 20; export declare function dedupeParseErrors(errors: string[] | undefined): string[]; export declare function formatParseErrors(errors: string[], total?: number): string[]; /** * Cap an upstream parse-error list to {@link PARSE_ERRORS_LIMIT} unique entries, * preserving the original deduplicated total. Use this at the source so tool * details never carry thousands of per-file parse errors into traces or * renderers. */ export declare function capParseErrors(errors: string[] | undefined, limit?: number): { errors: string[]; total: number; }; /** * Group `rawLines` by blank-line separators, mirroring the historical search / * ast-grep / ast-edit renderer behavior: if any blank line is present, splits on * runs of blank lines; otherwise collapses non-empty lines into a single group. */ export declare function splitGroupsByBlankLine(rawLines: string[]): string[][]; /** * Standard width+expand keyed render cache used by every search-style tool * renderer. `compute` re-runs only when the cache key changes; the returned * Component is the canonical `{ render, invalidate }` pair. */ export declare function createCachedComponent(getExpanded: () => boolean, compute: (width: number, expanded: boolean) => string[]): Component; /** * Append the indented bullet list of parse errors (capped at * {@link PARSE_ERRORS_LIMIT}) to `lines`, with an overflow summary line if the * total exceeds the cap. No-op when `parseErrors` is empty. */ export declare function appendParseErrorsBulletList(lines: string[], parseErrors: readonly string[] | undefined, theme: Theme, total?: number): void; /** * Human-readable summary string for the parse-issues count, capped by * {@link PARSE_ERRORS_LIMIT}. */ export declare function formatParseErrorsCountLabel(parseErrors: readonly string[], total?: number): string; export interface LspBatchRequest { id: string; flush: boolean; } export declare function getLspBatchRequest(toolCall: ToolCallContext | undefined): LspBatchRequest | undefined;