Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278/** TUI component renderers for Advisor tool and custom messages. @module */
import type { AgentToolResult, Theme,} from '@earendil-works/pi-coding-agent';import { type Component, Text,} from '@earendil-works/pi-tui';import type { ReadonlyDeep, } from 'type-fest';import type { ForeignHostCapability, } from '@monochromatic-dev/ownership-marker-foreign-borrowed/ts';import { fallbackDetails, isAdvisorDetails, renderAdvisorSummary,} from './rendering-summary.ts';import { renderAdvisorOperationSummary, } from './rendering-operation.ts';import type { AdvisorDetails, AdvisorToolParams,} from './types.ts';
//region Types
/** Runtime Advisor result shape accepted from successful or thrown tool execution. */type AdvisorRenderableResult = { /** Tool content returned or synthesized by Pi. */ readonly content: AgentToolResult<unknown>['content']; /** Structured success details, absent or malformed after thrown errors. */ readonly details?: unknown;};
//endregion Types
//region Public renderers
/** Render an Advisor tool call row. @param args - tool parameters @param theme - current pi theme @returns TUI component @mutates theme - theme methods can update Pi host styling caches @example ```typescript renderAdvisorCall({ args: {}, theme }); ``` */export function renderAdvisorCall( { args, theme, }: { readonly args: AdvisorToolParams; readonly theme: ForeignHostCapability<Theme>; },): Component { /** Requested target displayed before execution resolves. */ const target = args.model ?? 'default scoped model'; /** Styled tool title. */ const title = theme.fg( 'toolTitle', theme.bold('advisor',), ); /** Styled action label. */ const action = theme.fg( 'accent', 'Consulting advisor', ); /** Styled target model label. */ const targetText = theme.fg( 'dim', target, ); /** Styled focused-question indicator. */ const questionText = args.question === undefined ? '' : theme.fg( 'dim', ' with question', ); return new Text( `${title} ${action} ${targetText}${questionText}`, 0, 0, );}
/** Render an Advisor tool result. @param result - Advisor tool result @param expanded - whether result is expanded @param theme - current pi theme @returns TUI component @mutates theme - theme methods can update Pi host styling caches @example ```typescript renderAdvisorResult({ result, expanded: false, theme }); ``` */export function renderAdvisorResult( { result, expanded, isPartial = false, theme, }: { readonly result: ReadonlyDeep<AdvisorRenderableResult>; readonly expanded: boolean; readonly isPartial?: boolean; readonly theme: ForeignHostCapability<Theme>; },): Component { /** Text block returned to primary model. */ const text = result.content[0] ?.type === 'text' ? result.content[0] .text : '(advisor returned no text)'; if (isPartial) return new Text( theme.fg( 'dim', text, ), 0, 0, ); /** Operation metadata replaces partial progress with every attempt's terminal state. */ const operationSummary = renderAdvisorOperationSummary({ details: result.details, text, expanded, theme, },); if ((typeof operationSummary) === 'string') return new Text( operationSummary, 0, 0, ); if (!isAdvisorDetails(result.details,)) { return new Text( theme.fg( 'error', text, ), 0, 0, ); } return new Text( renderAdvisorSummary({ text, details: result.details, expanded, theme, },), 0, 0, );}
/** Render a manual `/advisor` custom message. @param message - custom message payload @param expanded - whether message is expanded @param theme - current pi theme @returns TUI component @mutates theme - theme methods can update Pi host styling caches @example ```typescript renderAdvisorMessage({ message, expanded: true, theme }); ``` */export function renderAdvisorMessage( { message, expanded, theme, }: { readonly message: { readonly content: unknown; readonly details?: unknown; }; readonly expanded: boolean; readonly theme: ForeignHostCapability<Theme>; },): Component { /** Message text from custom message content. */ const text = (typeof message.content) === 'string' ? message.content : '(advisor returned no text)'; /** Manual reviews use the same operation summary as tool reviews. */ const operationSummary = renderAdvisorOperationSummary({ details: message.details, text, expanded, theme, },); if ((typeof operationSummary) === 'string') return new Text( operationSummary, 0, 0, ); /** Structured details when present. */ const details = isAdvisorDetails(message.details,) ? message.details : fallbackDetails(); return new Text( renderAdvisorSummary({ text, details, expanded, theme, },), 0, 0, );}
export { firstAdvisoryLine, renderAdvisorSummary,} from './rendering-summary.ts';
//endregion Public renderers