/** * Tool calls and results, drawn the way the tool asked to be drawn. * * A tool declares its render intent through `presentCall` and `presentResult`, and * those are pure functions of the call's arguments — the harness's contract, so a * frontend may call them freely. Reading them is the difference between "a name, * its arguments, and six truncated lines" and a diff in red and green, a framed * command with its exit status, or a search grouped by file. * * A tool that declares nothing still renders: every intent is documented to * degrade to raw content, so the fallback is the sanctioned path rather than a * gap. What a frontend must never do is invent a card for a tool by name. * * Every string here came from a model or a tool, so every string is escaped * before it is returned. * @module dshline/cards */ import type { ContentBlock } from '@deepseek-ai/dsh-llm'; import type { FileDiff, FileLocation, ToolDefinition } from '@deepseek-ai/dsh-tools'; import { PendingToolCalls } from './tool-pending.ts'; /** * How much of a card to draw. * * Cycled from the keyboard, because the right amount differs by task: reviewing a * change wants every diff line, and watching a long agent run wants the titles * alone. `hidden` still draws the call, never the body — a tool call that left no * trace at all would make the transcript lie about what ran. */ export type CardDetail = 'compact' | 'full' | 'hidden'; /** The cycle order for the toggle. */ export declare const CARD_DETAIL_CYCLE: readonly CardDetail[]; /** The parts of a `tool/result` event a card needs. */ export interface ResultInput { /** The call this result answers. */ readonly callId: string; /** The model-facing result content. */ readonly content: readonly ContentBlock[]; /** Whether the call failed. */ readonly isError: boolean; /** The tool-private presentation payload, threaded verbatim from the event. */ readonly meta?: unknown; /** The harness's failure identity, when the call failed inside the runtime. */ readonly error?: { readonly code: string; readonly name: string; }; } /** * The semantic inputs of one inspectable result. * * Retaining the call's arguments and the result lets the card renderer reproduce * the SAME presentation the compact card used, at expanded detail, rather than * falling back to raw content. */ export interface InspectableToolResult { readonly kind: 'result'; /** The tool that produced the result, for its presenter lookup. */ readonly name: string; /** The call's parsed arguments, as the presenter expects them. */ readonly args: unknown; /** The call-time diff, when the tool declared one, for the proposed path. */ readonly diffs?: readonly FileDiff[]; /** The result, verbatim, from the `tool/result` event. */ readonly input: ResultInput; } /** * A pending call's own `presentCall` content, retained when drawing it elided * rows. * * `presentCall` content is committed into scrollback at call time, before any * result exists — `exit_plan_mode` is one caller, echoing its full plan back as * a generic card's content. Without this, only RESULT-side truncation was ever * reachable by Ctrl+O; call-side content that the same row budget cut was gone * the moment its card scrolled off. This closes that gap generically, for any * tool whose call declares `content`, rather than special-casing one tool name. */ export interface InspectableToolCall { readonly kind: 'call'; /** The tool that made the call, kept for parity with the result shape. */ readonly name: string; /** The call's own presented content, verbatim. */ readonly content: readonly ContentBlock[]; /** * The call's declared follow-along locations, when the view published any. * Kept beside the content because either can be the thing a call card's row * budget cut, and the inspector re-renders both. */ readonly locations?: readonly FileLocation[]; } /** Either retained shape the inspector ring holds, newest first. */ export type InspectableCard = InspectableToolResult | InspectableToolCall; /** * Draws tool cards, remembering each call until its result arrives. * * The pairing is why this holds state: `presentResult` takes the call's arguments * as well as its result, and a `tool/result` event carries only the result. The * pending fold itself is shared with the Work child observers through * {@link PendingToolCalls}, so the transcript and the live views classify a call * the same way. */ export declare class ToolCards extends PendingToolCalls { private readonly workspace; /** How much of a card to draw; the runner cycles this from the keyboard. */ detail: CardDetail; /** * Cards whose presentation elided rows, newest first and bounded — a * completed result's, or a still-pending call's own `presentCall` content. * * `offered` marks the ones Ctrl+O has already put on screen. Consumption, not * eviction, is what keeps the detail cycle reachable: the first Ctrl+O opens * the newest unseen card and the next one falls through to * `compact → full → hidden`, exactly as a single slot did. Reaching an OLDER * card is a deliberate second gesture, made from inside the overlay. */ private readonly inspectables; /** * @param lookup - resolves a tool definition as the calling agent sees it, so * the card matches the definition that actually executed. A scoped tool can * shadow a global one, and a restricted-away tool reads as absent. * @param workspace - the session workspace, which titles a terminal card whose * view left `cwd` to the frontend. */ constructor(lookup: (name: string) => ToolDefinition | undefined, workspace: string); /** * Draw a pending call. * @param call - the logged call: its id, name, and unparsed argument JSON. * @param columns - the terminal's current width. * @returns rows to write into scrollback. */ call(call: { callId: string; name: string; arguments: string; }, columns: number): string[]; /** * A call from a tool that declared no view: its name and its arguments. * @param name - the tool name. * @param args - the logged arguments string. * @param width - the framed width, for the summary's budget. * @param columns - the terminal's current width. * @returns rows to write into scrollback. */ private rawCall; /** * Draw a completed call. * @param result - the logged result, paired to its call by id. * @param columns - the terminal's current width. * @returns rows to write into scrollback. */ result(result: ResultInput, columns: number): string[]; /** * The tool calls still waiting for their results, or nothing. * * Read by the status line so a long turn says what it is doing rather than only * how long it has been doing it — the difference between a slow command and a * hung session, which `working 14m 26s` alone cannot express. * * Reported as a name AND a count because the harness runs concurrency-safe * calls in parallel: several are legitimately outstanding at once, and naming * one of them alone would say a batch of six is a single tool. `latest` is the * most recently started, which is the only ordering a `Map` of pending calls * can honestly claim — the harness publishes no per-call progress or duration, * and this must not invent either. * @returns the newest pending call's presentation title, falling back to its * tool name, and how many others are outstanding, * or undefined when nothing is. */ inFlight(): { title: string; others: number; } | undefined; /** * Retain a call whose own presentation elided rows, newest first and bounded. * * Both the presented content and the declared locations are kept, because * either can be the thing the row budget cut; the inspector re-renders the * same sections at its own budget. * @param name - the tool that made the call. * @param content - the call's presented content, when the view declared any. * @param locations - the call's follow-along locations, when the view declared any. */ private rememberInspectableCall; /** * Consume the inspect opportunity on the NEWEST retained card, if unseen. * * Only ever index 0. Searching the ring for the newest *unoffered* card would * let the outer Ctrl+O walk backwards through history one keystroke at a time: * open the newest, close without stepping, and the next Ctrl+O would open the * one before it instead of reaching the detail toggle. Older cards are * deliberately reachable only from inside the inspector * ({@link inspectableOlderThan}), which is what keeps * `compact → full → hidden` a single keystroke away — and what this method * promises the reader. * * A new truncated card — a result's, or a call's own content — unshifts onto * the front, so it re-arms this without re-offering anything already seen. * @returns the newest retained card if it has not been offered, else undefined. */ takeInspectable(): InspectableCard | undefined; /** * The retained card one step older than this one. * * This is the gesture that reaches a card scrolled past: the inspector steps * back through the ring rather than the reader losing it to the next tool * call. Marking each step offered means walking the history does not leave a * queue of cards that Ctrl+O would then re-offer one at a time. * @param item - the card currently on screen. * @returns the next older retained card, or undefined at the end. */ inspectableOlderThan(item: InspectableCard): InspectableCard | undefined; /** * The retained card one step newer than this one. * * A destination is marked offered even though it was usually already visited: * a new truncated card can arrive while the inspector is open, and a card * shown by stepping forward must not be offered again by the outer Ctrl+O * after the overlay closes. * @param item - the card currently on screen. * @returns the next newer retained card, or undefined at the front. */ inspectableNewerThan(item: InspectableCard): InspectableCard | undefined; /** * Where one retained card sits in the history, for the inspector's counter. * * Stepping is invisible without it: two cards from the same tool can present * almost identically, and an overlay that changes with no sign of having moved * reads as a redraw rather than as navigation. * @param item - the card currently on screen. * @returns its 1-based position and the retained total, or undefined. */ inspectableRank(item: InspectableCard): { position: number; total: number; } | undefined; /** * Render an inspectable card's full semantic presentation for the inspector. * * Re-runs the same presenter the compact card used, so a diff stays a diff and a * search stays grouped by file, at the full bounded budget. `rows` are exactly * the scrollable presentation rows the overlay navigates, so its counter and * the viewport stay in one coordinate system; `truncated` says the inspector's * own {@link INSPECT_ROWS} cap hid further source material, for the `of N+` * marker. * @param item - the retained semantic inputs of the card to re-render. * @param columns - the terminal's current width. * @returns the presentation rows and whether the budget hid source material. */ renderInspect(item: InspectableCard, columns: number): { rows: string[]; truncated: boolean; }; /** * Render a completed call's body at one detail level. * * Resolving the presenter here keeps the scrollback draw and the inspector on * the same code path, so an inspected result is presented exactly as its card * was, only with the budget raised. The error branch is handled by the caller, * which has no presenter and nothing worth inspecting. * @param input - the result. * @param call - the paired call, when one was seen. * @param columns - the terminal's current width. * @param detail - the detail level (compact, full, hidden, or inspect). * @returns the rows and how many source rows they were cut from. */ private renderResult; /** * A titled call row, optionally with a detail line beneath it. * @param title - the call's own title, unescaped. * @param detail - the salient input, unescaped; empty for none. Shown only at * `full`, because a view that declares one has already said what the call does * in its title — `grep`'s title names the pattern its `rawInput` repeats. * @param kind - the call category, for its icon. * @param columns - the terminal's current width. * @param locations - the files the view declared the call touches, when any. * @param content - extra content blocks the view asked to show. * @returns rows to write into scrollback. */ private genericCall; /** * A generic call's body sections — its declared locations, then its presented * content — spending ONE row budget across both. * * The detail budgets bound the body of ONE card, not each section of it: an * allowance per section would let a call that names many files and echoes much * content show roughly two compact budgets before eliding, which is how the * cap stops meaning anything. Locations come first, and the content spends * whatever they leave; each section reports what the shared budget hid from * it, and either one being cut leaves the card inspectable, so the compact * card never silently discards metadata the harness published. * * Both the scrollback card and the inspector render through here, so the * inspector reconstructs the same two sections at its own, far larger budget. * @param locations - the files the view declared the call touches, when any. * @param content - extra content blocks the view asked to show, when any. * @param columns - the terminal's current width. * @param detail - the detail level being drawn. * @returns the section rows and whether the shared budget cut either section. */ private callSections; /** * A shell command as a framed card headed by its working directory. * @param view - the terminal call view. * @param width - the framed width. * @param columns - the terminal's current width. * @returns rows to write into scrollback. */ private terminalCall; /** * A completed command: its output framed, with an exit status. * @param view - the terminal result view. * @param width - the framed width. * @param columns - the terminal's current width. * @returns rows to write into scrollback. */ private terminalResult; /** * A diff call: its title alone, because the change is drawn once, at result time. * * Declared locations are the one addition, and they are not the change: they say * where a follow-along UI would look (usually `path:line`), which the result-time * diff body does not state. * @param view - the diff call view. * @param columns - the terminal's current width. * @returns rows to write into scrollback, and whether the location budget cut any. */ private diffCall; /** * The files a call declared it touches, one bounded row each. * * The declared list is the only source: locations are never inferred from * arguments or diffs, because a tool that declared none may still have touched * files, and a row claiming it did would be the frontend inventing a fact. * * Only the rows the budget will actually draw are formatted: the declared list * can be arbitrarily long, and escaping, painting, and truncating rows the * card is about to elide is work with no output. The visible prefix is known * before any formatting, because a location is one structured row. * @param locations - the locations the call view declared, when it did. * @param columns - the terminal's current width. * @param detail - the detail level being drawn, for the elision marker. * @param budget - rows the section may draw, from the allowance the card * shares across its body sections. * @returns the rows (this section's own elision marker included, which is * chrome rather than a spent row), how many rows the allowance spent, and * how many locations the budget hid. */ private locationRows; /** * The changed lines of one or more files, added in green and removed in red. * @param diffs - the files' changes. * @param width - the framed width. * @param columns - the terminal's current width. * @returns rows to write into scrollback. */ private diffBody; /** * A search result: matches grouped by file, or a flat path list. * @param view - the search result view. * @param columns - the terminal's current width. * @returns rows to write into scrollback. */ private searchResult; /** * A file read: its lines, numbered as they are in the file. * @param view - the read result view. * @param columns - the terminal's current width. * @returns rows to write into scrollback. */ private readResult; /** * A web retrieval: a search's cited sources with its provider answer, or a * fetch's retrieval summary and body. * @param view - the web result view. * @param columns - the terminal's current width. * @param result - the logged result, for the fallback text. * @param detail - the detail level being drawn. * @returns rows to write into scrollback. */ private webResult; /** * A completed web search: the provider's answer, then its sources in the order * the harness listed them. * * Every field is read from the structured view and nothing else: a snippet is * the provider's own, never re-derived from result text, and `publishedAt` is * displayed without date parsing or reformatting — interpreting the string as * a date would claim a precision it does not carry. * @param view - the search result view. * @param columns - the terminal's current width. * @param detail - the detail level being drawn. * @returns rows to write into scrollback. */ private webSearch; /** * A completed web fetch: a retrieval summary from the structured view, then the * fetched body. * * The summary is composed from the view's own fields, never parsed back out of * the result text: the model-facing `Fetched …` envelope renders the same facts * for the model, and the view is the authoritative copy for a UI. * @param view - the fetch result view. * @param columns - the terminal's current width. * @param result - the logged result, for the body text. * @param detail - the detail level being drawn. * @returns rows to write into scrollback. */ private webFetch; /** * Raw result text, the fallback every intent degrades to. * @param text - the result text, unescaped. * @param columns - the terminal's current width. * @param isError - whether the call failed, which colours it. * @param detail - the detail level being drawn. * @param budget - rows the section may draw; defaults to the detail's own * budget. A card that spends one allowance across several sections hands * each section only what the sections before it left. * @returns rows to write into scrollback. */ private body; /** * Cut a body to a row budget. * @param rows - every row the body could show. * @param budget - rows the section may draw, from the allowance the card * shares across its body sections. * @returns the retained rows and how many were dropped. */ private limit; } //# sourceMappingURL=cards.d.ts.map