import type { Theme } from "@earendil-works/pi-coding-agent"; export type BuiltinStyleName = "claude" | "stream" | "nord" | "glow"; export type StyleName = BuiltinStyleName | "custom" | "off"; export interface CustomStyleConfig { prefix?: string; suffix?: string; separator?: string; brackets?: [string, string]; inverse?: boolean; padName?: boolean; showTokens?: boolean; showCost?: boolean; glyphs?: { success?: string; warning?: string; error?: string; accent?: string; }; } export const COMMON_NAMES: Record = { plannotator: "plan", "plannotator-review": "plan", "pi-mcp-adapter": "mcp", "subagent-slash": "subagent", "subagent-slash-text": "subagent", "pi-wechat-assistant": "wechat", "wechat-assistant": "wechat", "pi-control-chrome": "chrome", chrome: "chrome", toolflow: "toolflow", anchor: "anchor", "pi-anchor": "anchor", lingual: "lingual", "pi-lingual": "lingual", }; export const SPINNERS = ["◐", "◓", "◑", "◒"] as const; export const BUILTIN_PRESETS: Record = { claude: { separator: " · ", glyphs: { success: "●", warning: "○", error: "▲", accent: "◆", }, }, stream: { separator: " ❯ ", glyphs: { success: "✓", warning: "◌", error: "✗", accent: "❯", }, }, nord: { brackets: ["‹", "›"], separator: " ", glyphs: { success: "◆", warning: "◌", error: "▲", accent: "◈", }, }, glow: { inverse: true, separator: " ", }, }; export const VALID_STYLES: readonly StyleName[] = [ "claude", "stream", "nord", "glow", "custom", "off", ]; /** Retired preset names migrated cleanly when reading older settings.json files. */ export const STYLE_ALIASES: Record = { linear: "stream", minimal: "stream", powerline: "nord", glass: "nord", tokyo: "nord", matrix: "nord", openai: "claude", gemini: "claude", }; export const OFF_STYLES = new Set(["off", "default", "none", "raw", "vanilla", "disable", "disabled"]); const NAME_SUFFIX_PATTERN = /-(extension|plugin|assistant|adapter|slash-text|slash|text|widget)$/gi; const DIMMABLE_SEPARATOR_GLYPHS = ["·", "│", "⁝", "❯", "»"]; export function normalizeExtensionName(rawKey: string): string { const lower = rawKey.toLowerCase().trim(); if (!lower) return "ext"; if (COMMON_NAMES[lower]) return COMMON_NAMES[lower]; let short = lower; const lastSlash = short.lastIndexOf("/"); if (lastSlash !== -1) short = short.slice(lastSlash + 1); if (COMMON_NAMES[short]) return COMMON_NAMES[short]; short = short.replace(/^pi-/, "").replace(NAME_SUFFIX_PATTERN, ""); return COMMON_NAMES[short] || short || lower; } export function resolveSeparator(preset: CustomStyleConfig): string { if (typeof preset.separator === "string" && preset.separator) return preset.separator; return preset.brackets || preset.inverse ? " " : " · "; } export function styleSeparator(sep: string, theme: Pick | null | undefined): string { const canDim = Boolean(theme && typeof theme.fg === "function"); const isGlyph = DIMMABLE_SEPARATOR_GLYPHS.some((glyph) => sep.includes(glyph)); return canDim && isGlyph ? theme!.fg("dim", sep) : sep; } export function resolveStyleKey(raw: string | undefined): string { const key = (raw || "").toLowerCase().trim(); if (!key) return "claude"; if (OFF_STYLES.has(key)) return "off"; return STYLE_ALIASES[key] || key; } export function getPreset( style: string, customCfg?: CustomStyleConfig, fallback: BuiltinStyleName = "claude" ): CustomStyleConfig { const key = resolveStyleKey(style); if (key === "custom") return customCfg || {}; if (key in BUILTIN_PRESETS) return BUILTIN_PRESETS[key as BuiltinStyleName]; return BUILTIN_PRESETS[fallback]; }