#!/usr/bin/env node import process from "node:process"; import { runInstanceCommand } from "./cli/instance.js"; const COMMANDS = ["init", "setup", "start", "stop", "restart", "status", "logs", "doctor", "list"] as const; type Command = typeof COMMANDS[number]; async function main(argv: string[]): Promise { if (argv.length === 0 || (argv.length === 1 && ["--help", "-h"].includes(argv[0]))) { printHelp(); return 0; } const [command, ...args] = argv; const option = argv.find((arg) => arg.startsWith("-")); if (option) throw new Error(`Unknown option: ${option}`); if (!COMMANDS.includes(command as Command)) throw new Error(`Unknown command: ${command}`); if (command === "list") { if (args.length !== 0) throw new Error("list does not accept "); } else if (args.length !== 1) { throw new Error(`${command} requires exactly one `); } return runInstanceCommand(command, args); } function printHelp(): void { console.log(`gori-agent - single-Bot ACP gateway Usage: gori-agent init gori-agent setup gori-agent start gori-agent stop gori-agent restart gori-agent status gori-agent logs gori-agent doctor gori-agent list Instances root: \${GORI_AGENT_ROOT:-$HOME/.gori-agent}/instances`); } main(process.argv.slice(2)).then((code) => { if (Number.isInteger(code)) process.exitCode = code; }).catch((error) => { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; });