export type ComputerCommand = | 'help' | 'status' | 'apps' | 'permissions' | 'observe' | 'interactive' | 'takeover' | 'resume' | 'cancel' | 'stop' | 'audit'; export type ComputerCommandParseResult = | { matched: false } | { matched: true; command?: ComputerCommand; invalid: boolean }; export function parseComputerCommand(input: string): ComputerCommandParseResult { const trimmed = input.trim(); // 裸 `/computer` = status,与 `/advisor` 的既有约定一致(裸命令查状态)。 // 用户敲这个命令最常见的意图是「现在能不能用」,而不是「有哪些子命令」; // status 的输出里带一句 `/computer help` 就够指路了。 if (trimmed === '/computer') { return { matched: true, command: 'status', invalid: false }; } if (!/^\/computer(?:\s|$)/.test(trimmed)) return { matched: false }; const match = /^\/computer\s+(help|status|apps|permissions|observe|interactive|takeover|resume|cancel|stop|audit)$/.exec(trimmed); if (!match) return { matched: true, invalid: true }; return { matched: true, command: match[1] as ComputerCommand, invalid: false, }; }