{"version":3,"file":"cli.cjs","names":["agentId","resolveFormat","findDefaultFile","resolve","AGENT_FILES","join","parseArgs","existsSync","readInput","parseJson","convert","writeJsonFile","ConvertError","validateApi","checkApi","sync"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * agent-perms CLI — convert, validate, check, and sync cross-agent permission policies.\n *\n * All flags, no positionals. Format names resolve to default config file locations.\n * Use \"-\" for stdin/stdout.\n *\n * Exit codes: 0 = success, 1 = error, 2 = validation failure.\n */\n\nimport { parseArgs } from \"node:util\";\nimport { resolve, join } from \"node:path\";\nimport { existsSync } from \"node:fs\";\nimport {\n  convert,\n  validate as validateApi,\n  check as checkApi,\n  resolveFormat,\n  ConvertError,\n  type Format,\n} from \"./api.ts\";\nimport { agentId } from \"./compat/codecs.ts\";\nimport { sync } from \"./sync.ts\";\nimport {\n  AGENT_FILES,\n  findDefaultFile,\n  readInput,\n  parseJson,\n  writeJsonFile,\n} from \"./agent-files.ts\";\n\nconst AGENTS = agentId.options;\ntype Agent = (typeof AGENTS)[number];\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction error(message: string): never {\n  process.stderr.write(`error: ${message}\\n`);\n  process.exit(1);\n}\n\nfunction isAgent(value: string): value is Agent {\n  for (const agent of AGENTS) {\n    if (agent === value) return true;\n  }\n  return false;\n}\n\n// ---------------------------------------------------------------------------\n// Resolution helpers\n// ---------------------------------------------------------------------------\n\n/** Resolve a spec to an input file path. Format name → walk up, file path → direct, \"-\" → stdin. */\nfunction resolveInputSpec(spec: string | undefined): string | undefined {\n  if (spec === undefined || spec === \"-\") return undefined;\n  const format = resolveFormat(spec);\n  if (format) return findDefaultFile(format, process.cwd());\n  return resolve(spec);\n}\n\n/** Resolve a spec to an output file path. Format name → cwd, file path → direct, \"-\" → stdout. */\nfunction resolveOutputSpec(spec: string | undefined): string | undefined {\n  if (spec === undefined || spec === \"-\") return undefined;\n  const format = resolveFormat(spec);\n  if (format) {\n    const fileName = AGENT_FILES[format].name;\n    return resolve(join(process.cwd(), fileName));\n  }\n  return resolve(spec);\n}\nfunction firstString(\n  ...values: (string | boolean | undefined)[]\n): string | undefined {\n  for (const v of values) {\n    if (typeof v === \"string\") return v;\n  }\n  return undefined;\n}\n\nfunction allStrings(\n  ...values: ((string | boolean | undefined)[] | undefined)[]\n): string[] {\n  const result: string[] = [];\n  for (const arr of values) {\n    if (arr === undefined) continue;\n    for (const v of arr) {\n      if (typeof v === \"string\") result.push(v);\n    }\n  }\n  return result;\n}\n\n// ---------------------------------------------------------------------------\n// convert\n// ---------------------------------------------------------------------------\n\nasync function convertCommand(args: string[]): Promise<void> {\n  const { values } = parseArgs({\n    args,\n    options: {\n      from: { type: \"string\", short: \"f\" },\n      to: { type: \"string\", short: \"t\" },\n      input: { type: \"string\" },\n      in: { type: \"string\" },\n      output: { type: \"string\", short: \"o\" },\n      out: { type: \"string\" },\n      compact: { type: \"boolean\", short: \"c\" },\n      verbose: { type: \"boolean\", short: \"v\" },\n    },\n    strict: true,\n  });\n\n  // Merge aliases: --input/--in → --from\n  const fromSpec = firstString(values.from, values.input, values.in);\n  // --to is always the target format/file\n  const toSpec = values.to;\n  // --output/--out overrides destination (--to might set it too)\n  const outputSpec = firstString(values.output, values.out);\n  if (toSpec === undefined) error(\"--to is required\");\n\n  // Resolve input: format name finds file, file path reads directly, omitted = stdin\n  const inputPath = resolveInputSpec(fromSpec);\n  let fromFormat: Format | undefined;\n  if (fromSpec !== undefined && fromSpec !== \"-\") {\n    fromFormat = resolveFormat(fromSpec);\n    // If not a known format name and not an existing file, it's an unknown format\n    if (\n      fromFormat === undefined &&\n      inputPath !== undefined &&\n      !existsSync(inputPath)\n    ) {\n      error(\n        `unknown --from format: ${fromSpec}. Use an agent name, a config file path, or \"-\" for stdin`,\n      );\n    }\n  }\n\n  // Resolve output: format name → default file, file path → directly, \"-\" = stdout\n  const toFormat = resolveFormat(toSpec);\n  if (!toFormat) {\n    error(\n      `unknown --to format: ${toSpec}. Use an agent name (claude-code, codex, kiro, opencode, crush, canonical), a config file path, or \"-\" for stdout`,\n    );\n  }\n  const outputPath = outputSpec\n    ? resolveOutputSpec(outputSpec)\n    : resolveOutputSpec(toSpec);\n\n  // No need to validate --from — auto-detect handles unknown file paths\n\n  const source = inputPath ?? \"stdin\";\n  const raw = await readInput(inputPath);\n  const parsed = parseJson(raw, source);\n  if (!parsed.ok) error(parsed.error);\n  const json = parsed.value;\n\n  try {\n    const result = convert(fromFormat, toFormat, json);\n\n    const indent = values.compact ? undefined : 2;\n    const jsonStr = JSON.stringify(result.output, null, indent) + \"\\n\";\n\n    if (outputPath) {\n      await writeJsonFile(outputPath, jsonStr);\n    } else {\n      process.stdout.write(jsonStr);\n    }\n\n    if (values.verbose) {\n      const dest = outputPath ?? \"stdout\";\n      process.stderr.write(\n        `Decoded ${result.from} → canonical (${String(result.ruleCount)} rules), encoded → ${toFormat}, wrote ${dest}\\n`,\n      );\n    }\n  } catch (e) {\n    if (e instanceof ConvertError) {\n      process.stderr.write(`error: ${e.message}\\n`);\n      for (const err of e.errors) {\n        process.stderr.write(`  ${err.path}: ${err.message}\\n`);\n      }\n      process.exit(2);\n    }\n    const message = e instanceof Error ? e.message : String(e);\n    error(message);\n  }\n}\n\n// ---------------------------------------------------------------------------\n// validate\n// ---------------------------------------------------------------------------\n\nasync function validateCommand(args: string[]): Promise<void> {\n  const { values } = parseArgs({\n    args,\n    options: {\n      input: { type: \"string\", short: \"i\" },\n      in: { type: \"string\" },\n    },\n    strict: true,\n  });\n\n  const inputSpec = firstString(values.input, values.in);\n  const inputPath = resolveInputSpec(inputSpec);\n  const source = inputPath ?? \"stdin\";\n\n  const raw = await readInput(inputPath);\n  const parsed = parseJson(raw, source);\n  if (!parsed.ok) error(parsed.error);\n  const json = parsed.value;\n\n  const result = validateApi(json);\n  if (result.valid) {\n    process.stdout.write(\"valid\\n\");\n    return;\n  }\n\n  process.stderr.write(\"validation errors:\\n\");\n  for (const err of result.errors) {\n    process.stderr.write(`  ${err.path}: ${err.message}\\n`);\n  }\n  process.exit(2);\n}\n\n// ---------------------------------------------------------------------------\n// check\n// ---------------------------------------------------------------------------\n\nasync function checkCommand(args: string[]): Promise<void> {\n  const { values } = parseArgs({\n    args,\n    options: {\n      tool: { type: \"string\" },\n      input: { type: \"string\" },\n      \"policy-file\": { type: \"string\" },\n      cwd: { type: \"string\" },\n      branch: { type: \"string\" },\n    },\n    strict: true,\n  });\n\n  if (!values.tool) error(\"--tool is required\");\n  if (values.input === undefined) error(\"--input is required\");\n\n  const inputPath = resolveInputSpec(values[\"policy-file\"]);\n  const source = inputPath ?? \"stdin\";\n\n  const raw = await readInput(inputPath);\n  const parsed = parseJson(raw, source);\n  if (!parsed.ok) error(parsed.error);\n  const json = parsed.value;\n\n  try {\n    const ctx: { cwd?: string; branch?: string } = {};\n    if (values.cwd !== undefined) ctx.cwd = values.cwd;\n    if (values.branch !== undefined) ctx.branch = values.branch;\n    const result = checkApi(values.tool, values.input, json, ctx);\n    process.stdout.write(`${result.decision}\\n`);\n    process.exit(result.decision === \"deny\" ? 1 : 0);\n  } catch (e) {\n    if (e instanceof ConvertError) {\n      process.stderr.write(`error: ${e.message}\\n`);\n      for (const err of e.errors) {\n        process.stderr.write(`  ${err.path}: ${err.message}\\n`);\n      }\n      process.exit(2);\n    }\n    const message = e instanceof Error ? e.message : String(e);\n    error(message);\n  }\n}\n\n// ---------------------------------------------------------------------------\n// sync\n// ---------------------------------------------------------------------------\n\nasync function syncCommand(args: string[]): Promise<void> {\n  const { values } = parseArgs({\n    args,\n    options: {\n      \"working-dir\": { type: \"string\", short: \"d\" },\n      up: { type: \"string\", default: \"all\", short: \"u\" },\n      with: { type: \"string\", multiple: true, short: \"w\" },\n      without: { type: \"string\", multiple: true, short: \"x\" },\n      include: { type: \"string\", multiple: true },\n      exclude: { type: \"string\", multiple: true },\n      yes: { type: \"boolean\", short: \"y\" },\n      \"dry-run\": { type: \"boolean\" },\n      create: { type: \"boolean\", short: \"c\" },\n      verbose: { type: \"boolean\", short: \"v\" },\n      backup: { type: \"boolean\", short: \"b\" },\n    },\n    strict: true,\n  });\n\n  // Parse --up value\n  let up: number;\n  if (values.up === \"all\") {\n    up = Infinity;\n  } else {\n    up = Number(values.up);\n    if (!Number.isInteger(up) || up < 0) {\n      error(\"--up must be a non-negative integer or 'all'\");\n    }\n  }\n\n  // Merge --with and --include (aliases)\n  const withRaw = allStrings(values.with, values.include);\n  // Merge --without and --exclude (aliases)\n  const withoutRaw = allStrings(values.without, values.exclude);\n\n  if (withRaw.length > 0 && withoutRaw.length > 0) {\n    error(\"--with and --without are mutually exclusive\");\n  }\n\n  // Validate agent names\n  const withAgents: Agent[] = [];\n  for (const w of withRaw) {\n    if (w === \"canonical\") continue;\n    if (!isAgent(w))\n      error(\n        `unknown agent: ${w}. Valid: ${[...AGENTS, \"canonical\"].join(\", \")}`,\n      );\n    withAgents.push(w);\n  }\n\n  const withoutAgents: Agent[] = [];\n  for (const w of withoutRaw) {\n    if (w === \"canonical\") continue;\n    if (!isAgent(w))\n      error(\n        `unknown agent: ${w}. Valid: ${[...AGENTS, \"canonical\"].join(\", \")}`,\n      );\n    withoutAgents.push(w);\n  }\n\n  const cwd = values[\"working-dir\"]\n    ? resolve(values[\"working-dir\"])\n    : process.cwd();\n\n  await sync({\n    cwd,\n    up,\n    with: withAgents,\n    without: withoutAgents,\n    yes: values.yes ?? false,\n    dryRun: values[\"dry-run\"] ?? false,\n    create: values.create ?? false,\n    verbose: values.verbose ?? false,\n    backup: values.backup ?? false,\n  });\n}\n\n// ---------------------------------------------------------------------------\n// Main\n// ---------------------------------------------------------------------------\n\nfunction usage(stream: \"stdout\" | \"stderr\"): void {\n  const target = stream === \"stdout\" ? process.stdout : process.stderr;\n  target.write(`agent-perms — cross-agent permission policy tool\n\nUsage:\n  agent-perms convert [--from <spec>] --to <spec>\n  agent-perms validate [--input <spec>]\n  agent-perms check --tool <name> --input <cmd> [--policy-file <spec>]\n  agent-perms sync\n\nSpecs: agent name, config file path, or \"-\" for stdin/stdout.\n\n  Format names resolve to default config files:\n    claude-code  →  .claude/settings.json\n    canonical    →  .agents/permissions.json\n    opencode     →  opencode.json\n    kiro         →  .kiro/permissions.json\n    codex        →  codex.toml\n    crush        →  .crush.json\n\nCommands:\n  convert   Convert between agent formats\n  validate  Validate a policy file\n  check     Evaluate a tool call against a policy\n  sync      Detect, merge, and write agent configs (bidirectional)\n\nConvert flags:\n  -f, --from, --input, --in <spec>   Source (format, file, or \"-\" for stdin)\n  -t, --to, --output, --out <spec>   Target (format, file, or \"-\" for stdout)\n  -c, --compact                      Output compact JSON\n  -v, --verbose                      Show decode/encode summary on stderr\n\nValidate flags:\n  -i, --input, --in <spec>           Policy file (format, file, or \"-\" for stdin)\n\nCheck flags:\n  --tool <name>                      Tool name (required)\n  --input <cmd>                      Tool input string (required)\n  --policy-file <spec>               Policy file (format, file, or \"-\" for stdin)\n  --cwd, --branch                    Evaluation context\n\nSync flags:\n  -d, --working-dir <path>           Starting directory (default: cwd)\n  -u, --up <n|all>                   Ascend n parent directories (default: all)\n  -w, --with <agent>                 Only sync these agents (repeatable)\n  -x, --without <agent>              Sync all except these agents (repeatable)\n  -y, --yes                          Apply without prompting\n  --dry-run                          Show changes only, never write\n  -c, --create                       Create config files that don't exist\n  -v, --verbose                      Show rule provenance\n  -b, --backup                       Write .bak files before overwriting\n\nExamples:\n  agent-perms convert --from claude-code --to canonical\n  agent-perms convert --from .claude/settings.json --to crush\n  agent-perms convert --from claude-code --to -\n  cat settings.json | agent-perms convert --from - --to canonical --output -\n  agent-perms validate --input canonical\n  agent-perms validate --input .agents/permissions.json\n  agent-perms check --tool Bash --input \"git status\" --policy-file canonical\n  agent-perms sync\n  agent-perms sync -y\n  agent-perms sync --dry-run\n  agent-perms sync -w claude-code -w opencode\n  agent-perms sync -x codex\n  agent-perms sync -w claude-code --create\n`);\n}\n\nasync function main(): Promise<void> {\n  // If invoked as agent-perms-mcp, route directly to MCP server\n  const binName = process.argv[1]?.split(\"/\").pop() ?? \"\";\n  if (binName === \"agent-perms-mcp\") {\n    await import(\"./mcp.ts\");\n    return;\n  }\n\n  const args = process.argv.slice(2);\n  const command = args[0];\n\n  switch (command) {\n    case \"convert\":\n      await convertCommand(args.slice(1));\n      break;\n    case \"validate\":\n      await validateCommand(args.slice(1));\n      break;\n    case \"check\":\n      await checkCommand(args.slice(1));\n      break;\n    case \"sync\":\n      await syncCommand(args.slice(1));\n      break;\n    case \"mcp\":\n      await import(\"./mcp.ts\");\n      break;\n    case \"--help\":\n    case \"-h\":\n      // An explicit help request is a successful invocation: usage on stdout, exit 0.\n      usage(\"stdout\");\n      return;\n    default:\n      if (command) {\n        process.stderr.write(`unknown command: ${command}\\n\\n`);\n      }\n      usage(\"stderr\");\n      process.exit(1);\n  }\n}\n\nmain().catch((e: unknown) => {\n  process.stderr.write(\n    `fatal: ${e instanceof Error ? e.message : String(e)}\\n`,\n  );\n  process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,MAAM,SAASA,8BAAQ;AAOvB,SAAS,MAAM,SAAwB;CACrC,QAAQ,OAAO,MAAM,UAAU,QAAQ,GAAG;CAC1C,QAAQ,KAAK,CAAC;AAChB;AAEA,SAAS,QAAQ,OAA+B;CAC9C,KAAK,MAAM,SAAS,QAClB,IAAI,UAAU,OAAO,OAAO;CAE9B,OAAO;AACT;;AAOA,SAAS,iBAAiB,MAA8C;CACtE,IAAI,SAAS,UAAa,SAAS,KAAK,OAAO;CAC/C,MAAM,SAASC,kCAAc,IAAI;CACjC,IAAI,QAAQ,OAAOC,oCAAgB,QAAQ,QAAQ,IAAI,CAAC;CACxD,WAAOC,mBAAQ,IAAI;AACrB;;AAGA,SAAS,kBAAkB,MAA8C;CACvE,IAAI,SAAS,UAAa,SAAS,KAAK,OAAO;CAC/C,MAAM,SAASF,kCAAc,IAAI;CACjC,IAAI,QAAQ;EACV,MAAM,WAAWG,gCAAY,OAAO,CAAC;EACrC,WAAOD,uBA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