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.0 KB · 74 lines typescript
Raw Blame History
1/**2 * KHAELOR3 * File: src/tui/commands.ts4 * Description: The single command registry — one source powers keys, slash commands, and the universal palette (TUI_DESIGN §4.2).5 *6 * Author: Simon-Pierre Boucher7 * Contact: contact@spboucher.ai8 */910import type { PaletteItem } from "./composer/palette.js";1112export interface CommandDef {13  /** Stable id, e.g. `diff.show`. */14  id: string;15  /** Palette title, e.g. `View diff`. */16  title: string;17  /** Slash form, e.g. `/diff`. */18  slash?: string;19  /** Bound key, shown in the universal palette, e.g. `d`. */20  key?: string;21  /** Short description for the slash palette. */22  description?: string;23  run(): void;24}2526/**27 * All bindings are declared here with name/title/key, so every palette lists28 * them and a future rebinding config gets them for free — users never need29 * to memorize commands.30 */31export class CommandRegistry {32  private readonly commands = new Map<string, CommandDef>();3334  register(def: CommandDef): void {35    this.commands.set(def.id, def);36  }3738  find(id: string): CommandDef | null {39    return this.commands.get(id) ?? null;40  }4142  bySlash(slash: string): CommandDef | null {43    for (const def of this.commands.values()) {44      if (def.slash === slash) return def;45    }46    return null;47  }4849  list(): CommandDef[] {50    return [...this.commands.values()];51  }5253  /** Slash-palette items: `/name  description`. */54  slashItems(): PaletteItem[] {55    return this.list()56      .filter((d) => d.slash !== undefined)57      .map((d) => {58        const item: PaletteItem = { id: d.id, label: d.slash as string };59        if (d.description !== undefined) item.detail = d.description;60        return item;61      });62  }6364  /** Universal-palette items: `Title  /slash  key`. */65  paletteItems(): PaletteItem[] {66    return this.list().map((d) => {67      const item: PaletteItem = { id: d.id, label: d.title };68      if (d.slash !== undefined) item.detail = d.slash;69      if (d.key !== undefined) item.keyHint = d.key;70      return item;71    });72  }73}74