{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/cli/commands/compat/index.ts"],"sourcesContent":["import path from 'node:path';\n\nimport { loadDomains } from '@agimon-ai/doompi-config/domains';\nimport { loadMajorModesConfig } from '@agimon-ai/doompi-config/majorModes';\nimport {\n  createHarnessTelemetry,\n  HARNESS_EVENT,\n  type HarnessTelemetry,\n} from '@agimon-ai/doompi-core/runtime-log-sink-telemetry';\n\nimport { findRepositoryRoot } from '../../../composition/repository';\nimport { wantsHelp } from '../../router';\nimport { buildCompatibilityContext } from './context';\nimport { compatHelp } from './help';\nimport { isCompatibilityProvider, parseCompatibilityArgs, parseCompatibilityProvider } from './options';\nimport { launchCompatibility } from './providers';\n\nconst COMPAT_COMMAND = 'compat';\nconst HARNESS_ROOT_ENV = 'DOOMPI_ROOT';\n\n/** Launches a non-Pi frontend with the doom-pi matrix resolved for that run. */\nexport async function runCompatibility(\n  args: string[],\n  environment: NodeJS.ProcessEnv = process.env,\n  currentDirectory = process.cwd(),\n  telemetry: HarnessTelemetry = createHarnessTelemetry(),\n): Promise<number> {\n  // Only when no provider was named. Once one is, every remaining argument\n  // belongs to that frontend, so `compat claude --help` is Claude's help.\n  if (!isCompatibilityProvider(args[1]) && wantsHelp(args.slice(1))) {\n    process.stdout.write(compatHelp());\n    return 0;\n  }\n  const provider = parseCompatibilityProvider(args[1]);\n  const inheritedRoot = environment[HARNESS_ROOT_ENV];\n  const repoRoot = inheritedRoot ? path.resolve(inheritedRoot) : findRepositoryRoot(currentDirectory);\n  const parsed = parseCompatibilityArgs(\n    args.slice(2),\n    environment,\n    currentDirectory,\n    loadMajorModesConfig(repoRoot).defaultMajorMode,\n    loadDomains(repoRoot).defaultDomains,\n  );\n  const startedAt = Date.now();\n\n  // Compatibility launches shell out to a third-party CLI and to state-sync\n  // scripts, so most of what can go wrong here is invisible to Pi entirely.\n  return telemetry.runInSpan(\n    'doom_pi.compatibility',\n    { 'harness.provider': provider, 'harness.mode': 'compatibility' },\n    async () => {\n      const context = await buildCompatibilityContext({ repoRoot, provider, ...parsed.options });\n      try {\n        const exitCode = await launchCompatibility(context);\n        void telemetry.recordEvent(HARNESS_EVENT.launchCompleted, {\n          'harness.provider': provider,\n          'harness.exit_code': exitCode,\n          'harness.duration_ms': Date.now() - startedAt,\n        });\n        return exitCode;\n      } catch (error) {\n        await telemetry.recordError(HARNESS_EVENT.compatibilityLaunchFailed, error, {\n          'harness.provider': provider,\n          'harness.duration_ms': Date.now() - startedAt,\n        });\n        throw error;\n      } finally {\n        await context.cleanup();\n      }\n    },\n  );\n}\n\n/** Compatibility API. Executables call the command function directly. */\nexport class CompatibilityCommand {\n  readonly name = COMPAT_COMMAND;\n  private readonly telemetry: HarnessTelemetry;\n\n  // Not a constructor parameter property: the launcher scripts run this file\n  // straight from source under Node's strip-only TypeScript mode, which\n  // rejects them.\n  constructor(telemetry: HarnessTelemetry = createHarnessTelemetry()) {\n    this.telemetry = telemetry;\n  }\n\n  matches(args: string[]): boolean {\n    return args[0] === this.name;\n  }\n\n  async execute(\n    args: string[],\n    environment: NodeJS.ProcessEnv = process.env,\n    currentDirectory = process.cwd(),\n  ): Promise<number> {\n    return runCompatibility(args, environment, currentDirectory, this.telemetry);\n  }\n}\n"],"mappings":";;;;;;;;;;;AAiBA,MAAM,iBAAiB;AACvB,MAAM,mBAAmB;;AAGzB,eAAsB,iBACpB,MACA,cAAiC,QAAQ,KACzC,mBAAmB,QAAQ,IAAI,GAC/B,YAA8B,uBAAuB,GACpC;CAGjB,IAAI,CAAC,wBAAwB,KAAK,EAAE,KAAK,UAAU,KAAK,MAAM,CAAC,CAAC,GAAG;EACjE,QAAQ,OAAO,MAAM,WAAW,CAAC;EACjC,OAAO;CACT;CACA,MAAM,WAAW,2BAA2B,KAAK,EAAE;CACnD,MAAM,gBAAgB,YAAY;CAClC,MAAM,WAAW,gBAAgB,KAAK,QAAQ,aAAa,IAAI,mBAAmB,gBAAgB;CAClG,MAAM,SAAS,uBACb,KAAK,MAAM,CAAC,GACZ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