import type { ExtensionContext } from "@mariozechner/pi-coding-agent"; import type { ClaudeCommand, ClaudeSkill } from "./types.js"; export interface WidgetState { loaded: boolean; commands: ClaudeCommand[]; skills: ClaudeSkill[]; collisions: Map; } /** * Update the claude-compat status widget. The widget is removed entirely * when there is nothing to report; otherwise it shows command/skill counts * and any collision warnings, or a dim "unloaded" hint when disabled. */ export function updateWidget(ctx: ExtensionContext, state: WidgetState): void { if (!ctx.hasUI) return; if (!state.loaded) { ctx.ui.setWidget("claude-compat", (_tui, theme) => { return { dispose() {}, invalidate() {}, render(_width: number): string[] { const label = theme.fg("dim", "claude-compat unloaded"); const hint = theme.fg("dim", " /claude-load"); return [` ${label}${hint}`]; }, }; }); return; } const totalItems = state.commands.length + state.skills.length; if (totalItems === 0 && state.collisions.size === 0) { ctx.ui.setWidget("claude-compat", undefined); return; } ctx.ui.setWidget("claude-compat", (_tui, theme) => { return { dispose() {}, invalidate() {}, render(_width: number): string[] { const parts: string[] = []; if (state.commands.length > 0) { const prefix = theme.fg("accent", "⚡"); const cmdCount = theme.fg( "muted", `${state.commands.length} cmd${state.commands.length === 1 ? "" : "s"}`, ); parts.push(`${prefix}${cmdCount}`); } if (state.skills.length > 0) { const skillPrefix = theme.fg("accent", "🛠"); const skillCount = theme.fg( "muted", `${state.skills.length} skill${state.skills.length === 1 ? "" : "s"}`, ); parts.push(`${skillPrefix}${skillCount}`); } if (state.collisions.size > 0) { const warnPrefix = theme.fg("warning", "⚠"); const warnCount = theme.fg( "muted", `${state.collisions.size} conflict${state.collisions.size === 1 ? "" : "s"}`, ); parts.push(`${warnPrefix}${warnCount}`); } if (parts.length === 0) return [""]; const sep = theme.fg("dim", " │ "); return [` ${parts.join(sep)}`]; }, }; }); }