SPB Git

spb/khaelor Public

KHAELOR — a terminal-native autonomous engineering agent powered by Anthropic.

TypeScript 82.9% HTML 14.9% CSS 1.1% JavaScript 0.7%
2.2 KB · 56 lines typescript
Raw Blame History
1/**2 * KHAELOR3 * File: src/tui/doctor.ts4 * Description: `khaelor --doctor-tui` — detected terminal capabilities and why, turning display bugs into self-diagnosed tickets (TUI v2 §7).5 *6 * Author: Simon-Pierre Boucher7 * Contact: contact@spboucher.ai8 */910import { detectColorDepth } from "./renderer/capabilities.js";1112export interface DoctorEnv {13  TERM?: string;14  COLORTERM?: string;15  NO_COLOR?: string;16  LANG?: string;17  LC_ALL?: string;18  TERM_PROGRAM?: string;19}2021/** Terminals known to support OSC 8 hyperlinks / OSC 52 clipboard. */22const OSC8_TERMINALS = new Set(["iTerm.app", "WezTerm", "kitty", "ghostty", "Hyper", "vscode"]);23const OSC52_TERMINALS = new Set(["iTerm.app", "WezTerm", "kitty", "ghostty", "Apple_Terminal"]);2425/** Build the --doctor-tui report: what was detected, and the reason. */26export function doctorReport(env: DoctorEnv, isTty: boolean, columns: number): string[] {27  const colorDepth = detectColorDepth(env as NodeJS.ProcessEnv, isTty);28  const utf8 = /utf-?8/i.test(env.LC_ALL ?? env.LANG ?? "");29  const program = env.TERM_PROGRAM ?? "";30  const osc8 = OSC8_TERMINALS.has(program);31  const osc52 = OSC52_TERMINALS.has(program);3233  const line = (name: string, value: string, why: string): string =>34    `   ${name.padEnd(16)} ${value.padEnd(18)} ${why}`;3536  return [37    "",38    " doctor-tui · detected capabilities",39    line("tty", String(isTty), isTty ? "stdout is a terminal" : "stdout is piped — TUI disabled"),40    line(41      "colors",42      colorDepth,43      env.NO_COLOR !== undefined44        ? "NO_COLOR is set"45        : `COLORTERM=${env.COLORTERM ?? "(unset)"} · TERM=${env.TERM ?? "(unset)"}`,46    ),47    line("unicode", utf8 ? "utf-8" : "ascii-fallback", `LANG=${env.LANG ?? "(unset)"}`),48    line("width", String(columns), columns < 100 ? "narrow layout: 2-line status bar, unified diffs" : "full layout"),49    line("osc8 links", osc8 ? "yes" : "unknown", `TERM_PROGRAM=${program || "(unset)"} — fallback: text (url)`),50    line("osc52 clipboard", osc52 ? "yes" : "unknown", "fallback: copy hint hidden"),51    "",52    "   theme: khaelis (obsidian + magma) · degradation: truecolor → 256 → 16 → mono",53    "   report display bugs with this block attached.",54  ];55}56