{"version":3,"file":"router.mjs","names":[],"sources":["../../src/cli/router.ts"],"sourcesContent":["/**\n * Top-level argv routing for the `doompi` binary.\n *\n * Deliberately tiny and dependency-free. It answers two questions before any\n * command module loads: which subcommand was named, and whether this run only\n * wants help or a version. Everything else, including the harness options and\n * the Pi passthrough, stays with `parseHarnessArgs`, which already knows the\n * harness vocabulary and forwards what it does not own.\n */\n\n/** Subcommands that parse their own arguments instead of passing them to Pi. */\nexport const KNOWN_COMMANDS = [\n  'init',\n  'sync',\n  'api-export',\n  'compat',\n  'doctor',\n  'history-export',\n  'history-import',\n] as const;\n\nexport type KnownCommand = (typeof KNOWN_COMMANDS)[number];\n\nconst HELP_FLAGS = ['--help', '-h'];\nconst VERSION_FLAGS = ['--version', '-v'];\n/** Everything after this belongs to a provider or to Pi, never to doompi. */\nconst PASSTHROUGH_SEPARATOR = '--';\n\n/**\n * The named subcommand, or undefined when this run is a Pi invocation.\n *\n * Reads argv[0] only. A token later in the line is a flag value or prompt text,\n * never a command, so scanning further would let `doompi --profile sync` look\n * like a sync.\n */\nexport function routeCommand(args: readonly string[]): KnownCommand | undefined {\n  const first = args[0];\n  return first !== undefined && (KNOWN_COMMANDS as readonly string[]).includes(first)\n    ? (first as KnownCommand)\n    : undefined;\n}\n\n/**\n * Whether this run asks for help or a version, before the passthrough boundary.\n *\n * The scan stops at the first bare `--` so a provider's own `--help` reaches\n * the provider rather than printing doompi's help and exiting.\n */\nexport function informationalRequest(args: readonly string[]): 'help' | 'version' | undefined {\n  for (const argument of args) {\n    if (argument === PASSTHROUGH_SEPARATOR) return undefined;\n    if (HELP_FLAGS.includes(argument)) return 'help';\n    if (VERSION_FLAGS.includes(argument)) return 'version';\n  }\n  return undefined;\n}\n\n/** Convenience for a subcommand that only needs to know whether to print help. */\nexport function wantsHelp(args: readonly string[]): boolean {\n  return informationalRequest(args) === 'help';\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,MAAM,aAAa,CAAC,UAAU,IAAI;AAClC,MAAM,gBAAgB,CAAC,aAAa,IAAI;;AAExC,MAAM,wBAAwB;;;;;;;;AAS9B,SAAgB,aAAa,MAAmD;CAC9E,MAAM,QAAQ,KAAK;CACnB,OAAO,UAAU,KAAA,KAAc,eAAqC,SAAS,KAAK,IAC7E,QACD,KAAA;AACN;;;;;;;AAQA,SAAgB,qBAAqB,MAAyD;CAC5F,KAAK,MAAM,YAAY,MAAM;EAC3B,IAAI,aAAa,uBAAuB,OAAO,KAAA;EAC/C,IAAI,WAAW,SAAS,QAAQ,GAAG,OAAO;EAC1C,IAAI,cAAc,SAAS,QAAQ,GAAG,OAAO;CAC/C;AAEF;;AAGA,SAAgB,UAAU,MAAkC;CAC1D,OAAO,qBAAqB,IAAI,MAAM;AACxC"}