{"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli-args.ts","../src/cli.ts"],"sourcesContent":["const passthroughFirstArgs = new Set([\"search\", \"search-image\", \"read\", \"providers\", \"mcp\"]);\n\nconst helpOrVersionFlags = new Set([\"-h\", \"--help\", \"-v\", \"--version\"]);\n\nexport function normalizeMainArgs(rawArgs: readonly string[]): string[] {\n  const [firstArg] = rawArgs;\n\n  if (!firstArg) {\n    return [...rawArgs];\n  }\n\n  if (passthroughFirstArgs.has(firstArg) || helpOrVersionFlags.has(firstArg)) {\n    return [...rawArgs];\n  }\n\n  return [\"search\", ...rawArgs];\n}\n","#!/usr/bin/env node\n\nimport { type ArgsDef, type CommandDef, defineCommand, runMain } from \"citty\";\nimport { normalizeMainArgs } from \"./cli-args.ts\";\nimport { WebError } from \"./core/errors.ts\";\nimport { version } from \"./version.ts\";\n\n/**\n * Loads a subcommand and turns a `WebError` its handler did not translate, a spent key, a bad\n * token, a bad date, into one line on stderr and exit code 1. Anything else keeps citty's stack.\n * @param load - Imports the command module.\n * @returns {Promise<CommandDef<T>>} The command, its `run` guarded.\n */\nasync function command<T extends ArgsDef>(\n  load: () => Promise<{ readonly default: CommandDef<T> }>,\n): Promise<CommandDef<T>> {\n  const loaded = (await load()).default;\n  const run = loaded.run;\n  if (run === undefined) return loaded;\n  return {\n    ...loaded,\n    async run(context) {\n      try {\n        await run(context);\n      } catch (error) {\n        if (!(error instanceof WebError)) throw error;\n        await reportError(error.message);\n        process.exitCode = 1;\n      }\n    },\n  };\n}\n\n/**\n * Prints one failure line the way the commands print their own, loading the reporter only now so\n * `web --version` stays light.\n * @param message - Failure text, sanitized before it reaches the terminal.\n */\nasync function reportError(message: string): Promise<void> {\n  const [{ consola }, { sanitizeTerminalText }] = await Promise.all([\n    import(\"consola\"),\n    import(\"./tui.ts\"),\n  ]);\n  consola.error(sanitizeTerminalText(message, 2048));\n}\n\nconst main = defineCommand({\n  meta: {\n    name: \"web\",\n    version,\n    description: \"Unified web search and read provider for agents and CLI\",\n  },\n  subCommands: {\n    search: () => command(() => import(\"./commands/search.ts\")),\n    \"search-image\": () => command(() => import(\"./commands/search-image.ts\")),\n    read: () => command(() => import(\"./commands/read.ts\")),\n    providers: () => command(() => import(\"./commands/providers.ts\")),\n    mcp: () => command(() => import(\"./commands/mcp.ts\")),\n  },\n});\n\nawait runMain(main, { rawArgs: [...normalizeMainArgs(process.argv.slice(2))] });\n"],"mappings":";;;;;AAAA,MAAM,uCAAuB,IAAI,IAAI;CAAC;CAAU;CAAgB;CAAQ;CAAa;AAAK,CAAC;AAE3F,MAAM,qCAAqB,IAAI,IAAI;CAAC;CAAM;CAAU;CAAM;AAAW,CAAC;AAEtE,SAAgB,kBAAkB,SAAsC;CACtE,MAAM,CAAC,YAAY;CAEnB,IAAI,CAAC,UACH,OAAO,CAAC,GAAG,OAAO;CAGpB,IAAI,qBAAqB,IAAI,QAAQ,KAAK,mBAAmB,IAAI,QAAQ,GACvE,OAAO,CAAC,GAAG,OAAO;CAGpB,OAAO,CAAC,UAAU,GAAG,OAAO;AAC9B;;;;;;;;;ACHA,eAAe,QACb,MACwB;CACxB,MAAM,UAAU,MAAM,KAAK,EAAA,CAAG;CAC9B,MAAM,MAAM,OAAO;CACnB,IAAI,QAAQ,KAAA,GAAW,OAAO;CAC9B,OAAO;EACL,GAAG;EACH,MAAM,IAAI,SAAS;GACjB,IAAI;IACF,MAAM,IAAI,OAAO;GACnB,SAAS,OAAO;IACd,IAAI,EAAE,iBAAiB,WAAW,MAAM;IACxC,MAAM,YAAY,MAAM,OAAO;IAC/B,QAAQ,WAAW;GACrB;EACF;CACF;AACF;;;;;;AAOA,eAAe,YAAY,SAAgC;CACzD,MAAM,CAAC,EAAE,WAAW,EAAE,0BAA0B,MAAM,QAAQ,IAAI,CAChE,OAAO,YACP,OAAO,qBACT,CAAC;CACD,QAAQ,MAAM,qBAAqB,SAAS,IAAI,CAAC;AACnD;AAEA,MAAM,OAAO,cAAc;CACzB,MAAM;EACJ,MAAM;E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