// src/platform/types.ts import { join } from "node:path"; import { homedir } from "node:os"; // ── Path Resolution ──────────────────────────────────────── export interface PlatformPaths { /** The dot-directory name: ".omp" */ dotDir: string; /** For user-visible messages and LLM prompts */ dotDirDisplay: string; /** Resolve project-local: paths.project(cwd, "plans") → "/.omp/supipowers/plans" */ project(cwd: string, ...segments: string[]): string; /** Resolve global: paths.global("config.json") → "~/.omp/supipowers/config.json" */ global(...segments: string[]): string; /** Resolve agent-level: paths.agent("extensions") → "~/.omp/agent/extensions" */ agent(...segments: string[]): string; } export function createPaths(dotDir: string): PlatformPaths { return { dotDir, dotDirDisplay: dotDir, project: (cwd: string, ...segments: string[]) => join(cwd, dotDir, "supipowers", ...segments), global: (...segments: string[]) => join(homedir(), dotDir, "supipowers", ...segments), agent: (...segments: string[]) => join(homedir(), dotDir, "agent", ...segments), }; } // ── Capabilities ─────────────────────────────────────────── export interface PlatformCapabilities { agentSessions: boolean; compactionHooks: boolean; customWidgets: boolean; registerTool: boolean; activeToolFiltering: boolean; } // ── Agent Sessions ───────────────────────────────────────── export interface AgentSessionOptions { cwd?: string; taskDepth?: number; parentTaskPrefix?: string; model?: string; thinkingLevel?: string | null; systemPrompt?: string[]; agentId?: string; agentDisplayName?: string; [key: string]: unknown; } export interface AgentSession { subscribe(handler: (event: any) => void): () => void; prompt(text: string, opts?: { expandPromptTemplates?: boolean }): Promise; state: { messages: any[] }; dispose(): Promise; } // ── Exec ─────────────────────────────────────────────────── export interface ExecOptions { cwd?: string; timeout?: number; env?: Record; } export interface ExecResult { stdout: string; stderr: string; code: number; killed?: boolean; } // ── Messages ─────────────────────────────────────────────── export interface SendMessageOptions { deliverAs?: "steer" | "followUp" | "nextTurn"; triggerTurn?: boolean; } // ── Commands ─────────────────────────────────────────────── export interface CommandInfo { name: string; description?: string; source?: string; handler?: (args: string | undefined, ctx: any) => void | Promise; } // ── Context ──────────────────────────────────────────────── export interface PlatformContext { cwd: string; hasUI: boolean; ui: PlatformUI; } export interface PlatformUI { select(title: string, options: any[], opts?: any): Promise; notify(message: string, type?: "info" | "warning" | "error"): void; input(label: string, opts?: any): Promise; confirm?(title: string, message: string): Promise; setWidget?(name: string, content: any): void; setStatus?(key: string, text: string | undefined): void; /** Show a custom TUI component with keyboard focus. Returns the value passed to done(). */ custom?( factory: (tui: any, theme: any, keybindings: any, done: (result: T) => void) => (any & { dispose?(): void }) | Promise, options?: { overlay?: boolean }, ): Promise; } // ── Platform ─────────────────────────────────────────────── export interface Platform { name: "omp"; // Commands registerCommand(name: string, opts: any): void; getCommands(): CommandInfo[]; // Events on(event: string, handler: (...args: any[]) => any): void; // Execution exec(cmd: string, args: string[], opts?: ExecOptions): Promise; sendMessage(content: any, opts?: SendMessageOptions): void; sendUserMessage(text: string): void; // Introspection getActiveTools(): string[]; getAllTools?(): string[]; // Tool registration registerTool?(definition: any): void; setActiveTools?(names: string[]): Promise; // Rendering registerMessageRenderer(type: string, renderer: any): void; // Model access setModel?(model: any): Promise; setThinkingLevel?(level: string, persist?: boolean): void; getCurrentModel?(): string; getModelForRole?(role: string): string | null; // Agent Sessions createAgentSession(opts: AgentSessionOptions): Promise; // Paths paths: PlatformPaths; // Capabilities capabilities: PlatformCapabilities; }