/** * agent-widget.ts — Persistent widget showing running/completed agents above the editor. * * Displays a tree of agents with animated spinners, live stats, and activity descriptions. * Uses the callback form of setWidget for themed rendering. */ import { type TUI } from "@earendil-works/pi-tui"; import type { AgentManager } from "../agent-manager.js"; import type { SubagentType, ThinkingLevel } from "../types.js"; /** Braille spinner frames for animated running indicator. */ export declare const SPINNER: string[]; /** Statuses that indicate an error/non-success outcome (used for linger behavior and icon rendering). */ export declare const ERROR_STATUSES: Set; export interface Theme { fg(color: string, text: string): string; bold(text: string): string; } interface WidgetRenderer { render(): string[]; invalidate(): void; } export interface UICtx { setStatus(key: string, text: string | undefined): void; setWidget(key: string, content: undefined | ((tui: TUI, theme: Theme) => WidgetRenderer), options?: { placement?: "aboveEditor" | "belowEditor"; }): void; } /** Per-agent live activity state. */ export interface AgentActivity { activeTools: Map; toolUses: number; tokens: string; responseText: string; session?: { getSessionStats(): { tokens: { total: number; }; }; }; /** Current turn count. */ turnCount: number; /** Effective max turns for this agent (undefined = unlimited). */ maxTurns?: number; } /** Metadata attached to Agent tool results for custom rendering. */ export interface AgentDetails { displayName: string; description: string; subagentType: string; toolUses: number; tokens: string; durationMs: number; status: "queued" | "running" | "completed" | "steered" | "aborted" | "stopped" | "error" | "background"; /** Human-readable description of what the agent is currently doing. */ activity?: string; /** Current spinner frame index (for animated running indicator). */ spinnerFrame?: number; /** Short resolved model name for display (e.g. "haiku", "sonnet"). */ modelName?: string; /** Effective explicit thinking level for display. */ thinkingLevel?: ThinkingLevel; /** Notable config tags (e.g. ["isolated"]). */ tags?: string[]; /** Non-fatal warnings produced while preparing or running the agent. */ warnings?: string[]; /** Current turn count. */ turnCount?: number; /** Effective max turns (undefined = unlimited). */ maxTurns?: number; agentId?: string; error?: string; } /** Format a token count compactly: "33.8k token", "1.2M token". */ export declare function formatTokens(count: number): string; /** Format turn count with optional max limit: "⟳5≤30" or "⟳5". */ export declare function formatTurns(turnCount: number, maxTurns?: number | null): string; /** Format milliseconds as human-readable duration. */ export declare function formatMs(ms: number): string; /** Format duration from start/completed timestamps. */ export declare function formatDuration(startedAt: number, completedAt?: number): string; export declare function formatAgentConfigTag(modelName?: string, thinkingLevel?: ThinkingLevel): string | undefined; /** Get display name for any agent type (built-in or custom). */ export declare function getDisplayName(type: SubagentType): string; /** Short label for prompt mode: "twin" for append, nothing for replace (the default). */ export declare function getPromptModeLabel(type: SubagentType): string | undefined; /** Build a human-readable activity string from currently-running tools or response text. */ export declare function describeActivity(activeTools: Map, responseText?: string): string; export declare class AgentWidget { private uiCtx; private widgetFrame; private widgetInterval; /** Tracks how many turns each finished agent has survived. Key: agent ID, Value: turns since finished. */ private readonly finishedTurnAge; /** How many extra turns errors/aborted agents linger (completed agents clear after 1 turn). */ private static readonly ERROR_LINGER_TURNS; /** Whether the widget callback is currently registered with the TUI. */ private widgetRegistered; /** Cached TUI reference from widget factory callback, used for requestRender(). */ private tui; /** Last status bar text, used to avoid redundant setStatus calls. */ private lastStatusText; private readonly manager; private readonly agentActivity; constructor(manager: AgentManager, agentActivity: Map); /** Set the UI context (grabbed from first tool execution). */ setUICtx(ctx: UICtx): void; /** * Called on each new turn (tool_execution_start). * Ages finished agents and clears those that have lingered long enough. */ onTurnStart(): void; /** Ensure the widget update timer is running. */ ensureTimer(): void; /** Check if a finished agent should still be shown in the widget. */ private shouldShowFinished; /** Record an agent as finished (call when agent completes). */ markFinished(agentId: string): void; /** Render a finished agent line. */ private renderFinishedLine; /** * Render the widget content. Called from the registered widget's render() callback, * reading live state each time instead of capturing it in a closure. */ private renderWidget; /** Force an immediate widget update. */ update(): void; dispose(): void; } export {};