pi-mono/apps/p2/plugins/coding-tools/tui.ts
Mario Zechner 49b88055b1 p2: code mode's calls and the tools' TUI cards come from their plugins
Web: the core keeps nested calls only as Durable shows them (`ToolView.calls`: live
`pi.live.nestedTools` slots, then the last list seen). A tool's contribution reads the rest:
`ToolActivity.nestedCalls(tool)` (code mode: its result's `details.calls`, live internal tools by
their script name, in plugins/codemode/nested.ts), `repeated(count, failed)` for an entry of
identical repeated calls ("N runs"; without it, the repeated tool's own summary), and a nested call's
`CallInput` (bash, PowerShell, terminal: a command line; without it, JSON) instead of core's
`args.command` guess. `isInterruptedError` moves to `@p2/app/v1`.

TUI: the built-in renderers move to the plugins' TUI facets (coding-tools: read, bash, edit, write,
grep, find, ls; powershell; codemode); the shell card stays a shared building block
(`createShellRenderers`). `ToolRenderers.nestedCalls` reads a call's calls for the card and for
resolvers such as quiet-tools (`resolveToolRenderers` keeps the registry's). `transcriptComponent`
takes the renderers to draw with; tests use `test/fixtures/tui-tools.ts`.

Behaviour and look unchanged.

(cherry picked from commit 00afdddbb6eb3dcb5207cac6ca8e496607ab1b61)
2026-11-07 00:28:50 +01:00

22 lines
784 B
TypeScript

// The coding tools' TUI facet: their cards in the transcript, as pi draws them (cards.ts; bash with the shared shell
// card).
import { contribute, defineFacet } from "@p2/app/v1";
import { createShellRenderers, TuiToolRenderers } from "@p2/app/v1/tui";
import { editRenderers, findRenderers, grepRenderers, lsRenderers, readRenderers, writeRenderers } from "./cards.ts";
/** The coding tools' cards, by tool name. */
export const codingToolRenderers = {
read: readRenderers,
bash: createShellRenderers("$"),
edit: editRenderers,
write: writeRenderers,
grep: grepRenderers,
find: findRenderers,
ls: lsRenderers,
};
export default defineFacet((host) => {
contribute(host, "p2.tui-coding-tools", (self) => {
self.contribute(TuiToolRenderers, codingToolRenderers);
});
});