{"version":3,"file":"upgrade-plan.mjs","names":[],"sources":["../../src/cli/upgrade-plan.ts"],"sourcesContent":["import process from \"node:process\";\nimport * as p from \"@clack/prompts\";\nimport type { UpgradeOptions } from \"../contract\";\nimport { syncTemplate } from \"../services/scaffold/sync\";\nimport { upgradeTemplate } from \"../services/scaffold/upgrade\";\nimport { colors } from \"../utils/theme\";\n\n/**\n * The interactive upgrade plan (`bos upgrade` on a TTY): show the version\n * delta and the exact files the upgrade will write, let the user toggle\n * per-file (default: overwrite all), offer the post-upgrade clean, and\n * confirm before anything lands. `--force` skips the plan and overwrites\n * everything; non-TTY runs (CI, scripts) keep the classic refuse-on-conflict\n * behavior.\n */\n\nexport interface UpgradeInteractionDecision {\n  overwrite?: string[];\n  cleanAfter?: boolean;\n}\n\n/**\n * `null` — the user explicitly declined (cancel or \"Write? no\"): nothing was\n * written, and the caller reports a cancelled result instead of exiting the\n * runtime from inside an Effect generator.\n */\nexport async function planUpgradeInteraction(\n  projectDir: string,\n  input: UpgradeOptions,\n): Promise<UpgradeInteractionDecision | null> {\n  if (input.force || input.dryRun || input.check || input.noSync || input.migrationsOnly) {\n    return {};\n  }\n  if (!process.stdout.isTTY) return {};\n\n  // Phase A — the version plan (dry-run: resolution + package deltas only).\n  const plan = await upgradeTemplate(projectDir, { ...input, dryRun: true });\n  if (plan.status !== \"dry-run\" || !plan.updatesAvailable) return {};\n\n  // Phase B — the file plan (dry-run sync against the same release).\n  const preflight = await syncTemplate(projectDir, { dryRun: true });\n  if (preflight.status === \"error\") return {};\n  const conflicted = preflight.conflicted;\n  const writable = [...preflight.updated, ...preflight.added, ...conflicted];\n  if (writable.length === 0) return {};\n\n  p.log.step(\n    `Upgrade plan — ${plan.packages\n      .filter((pkg) => pkg.from && pkg.from !== pkg.to)\n      .map((pkg) => `${pkg.name} ${pkg.from} → ${pkg.to}`)\n      .join(\", \")}`,\n  );\n  p.log.message(\n    `Release: ${plan.release?.resolved ?? \"latest\"} (${plan.release?.source ?? \"extends chain\"})`,\n  );\n  if (plan.changelogUrl) p.log.message(`Changelog: ${plan.changelogUrl}`);\n\n  const selected = await p.multiselect({\n    message: \"Files this upgrade will write (space toggles, enter confirms)\",\n    options: writable.map((file) => ({\n      value: file,\n      label: file,\n      hint: conflicted.includes(file)\n        ? \"local edits — template wins (backup kept)\"\n        : preflight.added.includes(file)\n          ? \"new file\"\n          : \"template update\",\n    })),\n    initialValues: writable,\n    required: false,\n  });\n  if (p.isCancel(selected)) {\n    p.cancel(\"Upgrade cancelled — nothing was written\");\n    return null;\n  }\n\n  const cleanAfter = await p.confirm({\n    message: \"Prune logs and caches after the upgrade (bos clean — upgrade backups kept)?\",\n    initialValue: true,\n  });\n  if (p.isCancel(cleanAfter)) {\n    p.cancel(\"Upgrade cancelled — nothing was written\");\n    return null;\n  }\n\n  const go = await p.confirm({ message: \"Write?\", initialValue: true });\n  if (p.isCancel(go) || !go) {\n    p.cancel(\"Upgrade cancelled — nothing was written\");\n    return null;\n  }\n\n  p.log.message(\n    colors.dim(\n      selected.length === writable.length\n        ? `Writing all ${writable.length} file(s)`\n        : `Writing ${selected.length} of ${writable.length} — the rest stay as your local copies`,\n    ),\n  );\n\n  // The selection always flows through — even \"all files\" — because it is\n  // also the conflict resolution: without it the train would abort on the\n  // very conflicts the user just approved overwriting.\n  return { overwrite: [...selected], cleanAfter };\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,eAAsB,uBACpB,YACA,OAC4C;CAC5C,IAAI,MAAM,SAAS,MAAM,UAAU,MAAM,SAAS,MAAM,UAAU,MAAM,gBACtE,OAAO,CAAC;CAEV,IAAI,CAAC,QAAQ,OAAO,OAAO,OAAO,CAAC;CAGnC,MAAM,OAAO,MAAM,gBAAgB,YAAY;EAAE,GAAG;EAAO,QAAQ;CAAK,CAAC;CACzE,IAAI,KAAK,WAAW,aAAa,CAAC,KAAK,kBAAkB,OAAO,CAAC;CAGjE,MAAM,YAAY,MAAM,aAAa,YAAY,EAAE,QAAQ,KAAK,CAAC;CAC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