// src/cli/commands/registry.ts // Registry of available CLI commands type CommandHandler = (args: string[]) => Promise | string; interface Command { desc: string; handler: CommandHandler; hidden?: boolean; // Hidden commands don't show in autocomplete but still work } export const commands: Record = { "/model": { desc: "Switch model", handler: () => { return "Opening model selector..."; }, }, "/stream": { desc: "Toggle token streaming on/off", hidden: true, handler: () => { // Handled specially in App.tsx for live toggling return "Toggling token streaming..."; }, }, "/exit": { desc: "Exit this session", handler: () => { // Handled specially in App.tsx return "Exiting..."; }, }, "/clear": { desc: "Clear conversation history", handler: () => { // Handled specially in App.tsx to access client and agent ID return "Clearing messages..."; }, }, "/compact": { desc: "Summarize conversation history (compaction)", hidden: true, handler: () => { // Handled specially in App.tsx to access client and agent ID return "Compacting conversation..."; }, }, "/logout": { desc: "Clear credentials and exit", handler: () => { // Handled specially in App.tsx to access settings manager return "Clearing credentials..."; }, }, "/rename": { desc: "Rename the current agent (/rename )", handler: () => { // Handled specially in App.tsx to access agent ID and client return "Renaming agent..."; }, }, "/description": { desc: "Update the current agent's description (/description )", handler: () => { // Handled specially in App.tsx to access agent ID and client return "Updating description..."; }, }, "/link": { desc: "Attach all Letta Code tools to agent (deprecated, use /toolset instead)", hidden: true, handler: () => { // Handled specially in App.tsx to access agent ID and client return "Linking tools..."; }, }, "/unlink": { desc: "Remove all Letta Code tools from agent (deprecated, use /toolset instead)", hidden: true, handler: () => { // Handled specially in App.tsx to access agent ID and client return "Unlinking tools..."; }, }, "/toolset": { desc: "Switch toolset (replaces /link and /unlink)", handler: () => { // Handled specially in App.tsx to access agent ID and client return "Opening toolset selector..."; }, }, "/system": { desc: "Switch system prompt", handler: () => { // Handled specially in App.tsx to open system prompt selector return "Opening system prompt selector..."; }, }, "/download": { desc: "Download AgentFile (.af)", handler: () => { // Handled specially in App.tsx to access agent ID and client return "Downloading agent file..."; }, }, "/bg": { desc: "Show background shell processes", handler: () => { // Handled specially in App.tsx to show background processes return "Showing background processes..."; }, }, "/init": { desc: "Initialize agent memory for this project", handler: () => { // Handled specially in App.tsx to send initialization prompt return "Initializing memory..."; }, }, "/skill": { desc: "Enter skill creation mode (/skill [description])", handler: () => { // Handled specially in App.tsx to trigger skill-creation workflow return "Starting skill creation..."; }, }, "/remember": { desc: "Remember something from the conversation (/remember [instructions])", handler: () => { // Handled specially in App.tsx to trigger memory update return "Processing memory request..."; }, }, "/resume": { desc: "Browse and switch to another agent", handler: () => { // Handled specially in App.tsx to show agent selector return "Opening agent selector..."; }, }, "/search": { desc: "Search messages across all agents", handler: () => { // Handled specially in App.tsx to show message search return "Opening message search..."; }, }, "/pin": { desc: "Pin current agent globally, or use -l for local only", handler: () => { // Handled specially in App.tsx return "Pinning agent..."; }, }, "/unpin": { desc: "Unpin current agent globally, or use -l for local only", handler: () => { // Handled specially in App.tsx return "Unpinning agent..."; }, }, "/pinned": { desc: "Show pinned agents", handler: () => { // Handled specially in App.tsx to open pinned agents selector return "Opening pinned agents..."; }, }, "/subagents": { desc: "Manage custom subagents", handler: () => { // Handled specially in App.tsx to open SubagentManager component return "Opening subagent manager..."; }, }, "/feedback": { desc: "Send feedback to the Letta team", handler: () => { // Handled specially in App.tsx to send feedback request return "Sending feedback..."; }, }, "/memory": { desc: "View agent memory blocks", handler: () => { // Handled specially in App.tsx to open memory viewer return "Opening memory viewer..."; }, }, "/usage": { desc: "Show session usage statistics and balance", handler: () => { // Handled specially in App.tsx to display usage stats return "Fetching usage statistics..."; }, }, "/help": { desc: "Show available commands", handler: () => { // Handled specially in App.tsx to open help dialog return "Opening help..."; }, }, }; /** * Execute a command and return the result */ export async function executeCommand( input: string, ): Promise<{ success: boolean; output: string }> { const [command, ...args] = input.trim().split(/\s+/); if (!command) { return { success: false, output: "No command found", }; } const handler = commands[command]; if (!handler) { return { success: false, output: `Unknown command: ${command}`, }; } try { const output = await handler.handler(args); return { success: true, output }; } catch (error) { return { success: false, output: `Error executing ${command}: ${error instanceof Error ? error.message : String(error)}`, }; } }