{"version":3,"file":"index.cjs","names":["insideSandbox","SANDBOX_HARNESS_EXPORT_SUBPATH","HARNESS_EVENT","BaseCommand"],"sources":["../../../../src/cli/commands/sandbox/index.ts"],"sourcesContent":["import { HARNESS_EVENT, type HarnessTelemetry } from '@agimon-ai/doompi-core/runtime-log-sink-telemetry';\nimport { insideSandbox, SANDBOX_HARNESS_EXPORT_SUBPATH } from '@agimon-ai/doompi-core/sandbox-harness';\n\nimport type { HarnessContext } from '../../../builders/cli/harnessContext';\nimport type { HarnessOptions } from '../../../composition/types/harness';\nimport { BaseCommand } from '../baseCommand';\n\nconst SANDBOX_MODE = 'sandbox';\n\n/**\n * Delegates a --sandbox launch to the harness a selected layer provides.\n *\n * Core stays sandbox-agnostic: it resolves the module the composition\n * declares, hands over the replayable arguments, and reports the exit code.\n */\nexport async function runSandbox(context: HarnessContext, telemetry: HarnessTelemetry): Promise<number> {\n  const { options, environment } = context;\n  if (insideSandbox(environment)) {\n    throw new Error('This session already runs inside a DoomPi sandbox; nested --sandbox is not supported.');\n  }\n\n  const [{ loadSandboxHarness, resolveSandboxHarnessEntry }, { buildSandboxForwardArgs }] = await Promise.all([\n    import('./harness'),\n    import('./args'),\n  ]);\n  const resolution = resolveSandboxHarnessEntry(context.majorModesConfig, context.selectedLayers, options.repoRoot);\n  if (!resolution) {\n    throw new Error(\n      `--sandbox needs a layer package exporting ${SANDBOX_HARNESS_EXPORT_SUBPATH} in the selected major mode; ` +\n        `add a sandbox layer to \"${options.majorMode}\" in .doom/modes.yaml.`,\n    );\n  }\n\n  const harness = await loadSandboxHarness(resolution.entry);\n  const startedAt = Date.now();\n  const result = await telemetry\n    .runInSpan(\n      'doom_pi.sandbox_session',\n      { 'harness.mode': SANDBOX_MODE, 'harness.sandbox.provider': resolution.specifier },\n      () =>\n        harness.launchSandbox({\n          repoRoot: options.repoRoot,\n          cwd: options.cwd,\n          forwardArgs: buildSandboxForwardArgs(options),\n          environment,\n          onProgress: (message) => process.stderr.write(`[doompi] sandbox: ${message}\\n`),\n        }),\n    )\n    .catch(async (error: unknown) => {\n      await telemetry.recordError(HARNESS_EVENT.launchFailed, error, {\n        'harness.mode': SANDBOX_MODE,\n        'harness.duration_ms': Date.now() - startedAt,\n      });\n      throw error;\n    });\n\n  void telemetry.recordEvent(HARNESS_EVENT.launchCompleted, {\n    'harness.exit_code': result,\n    'harness.duration_ms': Date.now() - startedAt,\n    'harness.mode': SANDBOX_MODE,\n  });\n  return result;\n}\n\n/** Compatibility API. Executables call the command function directly. */\nexport class SandboxLaunchCommand extends BaseCommand {\n  readonly name = 'sandbox-launch';\n\n  matches(options: HarnessOptions): boolean {\n    return options.sandbox;\n  }\n\n  async execute(context: HarnessContext, telemetry: HarnessTelemetry): Promise<number> {\n    return runSandbox(context, telemetry);\n  }\n}\n"],"mappings":";;;;AAOA,MAAM,eAAe;;;;;;;AAQrB,eAAsB,WAAW,SAAyB,WAA8C;CACtG,MAAM,EAAE,SAAS,gBAAgB;CACjC,KAAA,GAAIA,uCAAAA,cAAAA,CAAc,WAAW,GAC3B,MAAM,IAAI,MAAM,uFAAuF;CAGzG,MAAM,CAAC,EAAE,oBAAoB,8BAA8B,EAAE,6BAA6B,MAAM,QAAQ,IAAI,CAAA,QAAA,QAAA,CAAA,CAAA,WAAA,QAC1G,eAAA,CAAA,GAAA,QAAA,QAAA,CAAA,CAAA,WAAA,QACA,YAAA,CAAA,CACF,CAAC;CACD,MAAM,aAAa,2BAA2B,QAAQ,kBAAkB,QAAQ,gBAAgB,QAAQ,QAAQ;CAChH,IAAI,CAAC,YACH,MAAM,IAAI,MACR,6CAA6CC,uCAAAA,+BAA+B,uDAC/C,QAAQ,UAAU,uBACjD;CAGF,MAAM,UAAU,MAAM,mBAAmB,WAAW,KAAK;CACzD,MAAM,YAAY,KAAK,IAAI;CAC3B,MAAM,SAAS,MAAM,UAClB,UACC,2BACA;EAAE,gBAAgB;EAAc,4BAA4B,WAAW;CAAU,SAE/E,QAAQ,cAAc;EACpB,UAAU,QAA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