{"version":3,"file":"sync.mjs","names":["computeHash","parseYaml","isPlainObjectFromMerge"],"sources":["../../src/cli/sync.ts"],"sourcesContent":["import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport { glob } from \"glob\";\nimport { parse as parseYaml } from \"yaml\";\nimport { loadAppDescriptorConfig } from \"../config\";\nimport type { SyncOptions, SyncResult } from \"../contract\";\nimport { materializeViaLayer } from \"../infra/materializer\";\nimport {\n  isPlainObject as isPlainObjectFromMerge,\n  mergeBosConfigWithTemplate,\n  resolveExtendsRef,\n} from \"../merge\";\nimport { openResolution } from \"../resolution/session\";\nimport { syncResolvedSharedDeps } from \"../shared-deps\";\nimport { computeSnapshotHash as computeHash } from \"../utils/snapshot-hash\";\nimport { findWorkspaceRoot } from \"../workspace\";\nimport {\n  buildChildAgentsMd,\n  buildChildRootScripts,\n  extractSkillsBlock,\n  personalizeConfig,\n  resolveSourceDir,\n  runPnpmInstall,\n  runTypesGen,\n} from \"./init\";\nimport { readSnapshot, writeSnapshot } from \"./snapshot\";\n\nconst FRAMEWORK_OWNED_SYNC_FILES = new Set([\n  \".env.example\",\n  \".gitignore\",\n  \"biome.json\",\n  \"bos.config.json\",\n  \"package.json\",\n  \".changeset/config.json\",\n  \".changeset/README.md\",\n  \".github/workflows/ci.yml\",\n  \".github/workflows/deploy.yml\",\n  \".github/workflows/staging.yml\",\n  \".github/workflows/release.yml\",\n  \"railway.toml\",\n  \"ui/package.json\",\n  \"ui/postcss.config.mjs\",\n  \"ui/tsconfig.json\",\n  \"api/package.json\",\n  \"api/plugin.dev.ts\",\n  \"api/rspack.config.js\",\n  \"api/tsconfig.json\",\n  \"api/src/lib/context.ts\",\n  \"api/drizzle.config.ts\",\n  \"api/src/db/index.ts\",\n  \"api/src/db/layer.ts\",\n  \"api/src/db/migrate.ts\",\n  \"api/src/global.d.ts\",\n  \"api/tests/types.d.ts\",\n]);\n\n/**\n * Files the scaffold previously sync-owned but has retired (ADR 0023) — the\n * generated `.gen` bootstrap stubs replaced them. During sync: a local copy\n * whose hash still matches the sync snapshot is deleted silently; a\n * hand-modified (or never-snapshotted) copy is backed up, then deleted. The\n * app's authored ui files (router.tsx, app.ts, lib, routes, components) are\n * NOT retired — they leave the sync list as app-owned files, untouched.\n */\nexport const RETIRED_SYNC_FILES = new Set([\n  \"ui/src/entry.ts\",\n  \"ui/src/globals.d.ts\",\n  \"ui/src/hydrate.tsx\",\n  \"ui/src/router.server.tsx\",\n  \"ui/src/compose.ts\",\n]);\n\ntype PackageJson = Record<string, unknown>;\n\nconst AGENT_SYNC_GLOBS = [\".agents/skills/**\", \"docs/agents/**\", \"skills-lock.json\"];\n\nexport function isFrameworkOwnedSyncFile(filePath: string): boolean {\n  if (FRAMEWORK_OWNED_SYNC_FILES.has(filePath)) return true;\n  if (\n    filePath.startsWith(\".agents/skills/\") ||\n    filePath.startsWith(\"docs/agents/\") ||\n    filePath === \"skills-lock.json\"\n  )\n    return true;\n  // lib/auth.ts is NOT sync-owned since #207: the middleware factory lives in\n  // everything-dev/api (framework home); projects import it, they don't own a copy.\n  if (/^plugins\\/[^/]+\\/src\\/lib\\/context\\.ts$/.test(filePath)) return true;\n  if (/^plugins\\/[^/]+\\/src\\/db\\/(index|layer|migrate)\\.ts$/.test(filePath)) return true;\n  if (/^plugins\\/[^/]+\\/rspack\\.config\\.js$/.test(filePath)) return true;\n  if (/^plugins\\/[^/]+\\/drizzle\\.config\\.ts$/.test(filePath)) return true;\n  if (/^plugins\\/[^/]+\\/src\\/global\\.d\\.ts$/.test(filePath)) return true;\n  if (/^plugins\\/[^/]+\\/tests\\/types\\.d\\.ts$/.test(filePath)) return true;\n  if (/^plugins\\/[^/]+\\/tsconfig\\.json$/.test(filePath)) return true;\n  if (/^plugins\\/[^/]+\\/tsconfig\\.contract\\.json$/.test(filePath)) return true;\n  return false;\n}\n\nfunction computeLocalHash(projectDir: string, filePath: string): string | null {\n  const fullPath = join(projectDir, filePath);\n  if (!existsSync(fullPath)) return null;\n  try {\n    const content = readFileSync(fullPath);\n    return computeHash(content);\n  } catch {\n    return null;\n  }\n}\n\nfunction backupFiles(projectDir: string, filePaths: string[]): string | null {\n  const filesToBackup = filePaths.filter((f) => existsSync(join(projectDir, f)));\n  if (filesToBackup.length === 0) return null;\n\n  const timestamp = new Date().toISOString().replace(/[:.]/g, \"-\");\n  const backupDir = join(projectDir, \".bos\", \"sync-backup\", timestamp);\n\n  for (const filePath of filesToBackup) {\n    const src = join(projectDir, filePath);\n    const dest = join(backupDir, filePath);\n    mkdirSync(dirname(dest), { recursive: true });\n    copyFileSync(src, dest);\n  }\n\n  return backupDir;\n}\n\nexport interface RetiredSyncFilesResult {\n  /** unmodified stub copies — deleted (in a real run) */\n  retired: string[];\n  /** hand-modified or never-snapshotted stub copies — backed up, then deleted */\n  retiredConflicted: string[];\n  backupDir: string | null;\n}\n\n/**\n * Migrate a child off the retired bootstrap stub files (ADR 0023): unmodified\n * copies are deleted silently, hand-modified copies are backed up first. In\n * dry-run the actions are reported without touching the tree.\n */\nexport function retireSyncedFiles(\n  projectDir: string,\n  snapshotFiles: Record<string, string>,\n  opts: { dryRun: boolean },\n): RetiredSyncFilesResult {\n  const retired: string[] = [];\n  const retiredConflicted: string[] = [];\n\n  for (const destPath of RETIRED_SYNC_FILES) {\n    const localHash = computeLocalHash(projectDir, destPath);\n    if (localHash === null) continue;\n    if (localHash === snapshotFiles[destPath]) {\n      retired.push(destPath);\n    } else {\n      retiredConflicted.push(destPath);\n    }\n  }\n\n  if (opts.dryRun || (retired.length === 0 && retiredConflicted.length === 0)) {\n    return { retired, retiredConflicted, backupDir: null };\n  }\n\n  const backupDir = backupFiles(projectDir, retiredConflicted);\n  for (const destPath of [...retired, ...retiredConflicted]) {\n    rmSync(join(projectDir, destPath));\n  }\n  return { retired, retiredConflicted, backupDir };\n}\n\nfunction mergeStringMaps(\n  local: Record<string, string> | undefined,\n  template: Record<string, string> | undefined,\n): Record<string, string> | undefined {\n  if (!local && !template) return undefined;\n\n  const merged: Record<string, string> = { ...local };\n  for (const [name, value] of Object.entries(template ?? {})) {\n    merged[name] = value;\n  }\n\n  return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction mergeWorkspacePackages(local: unknown, template: unknown): string[] | undefined {\n  const localPackages = Array.isArray(local) ? local : [];\n  const templatePackages = Array.isArray(template) ? template : [];\n  if (localPackages.length === 0 && templatePackages.length === 0) return undefined;\n\n  const ordered = new Set<string>();\n  for (const entry of templatePackages) {\n    if (typeof entry === \"string\" && entry.length > 0) ordered.add(entry);\n  }\n  for (const entry of localPackages) {\n    if (typeof entry === \"string\" && entry.length > 0) ordered.add(entry);\n  }\n\n  const hasPluginEntry = [...ordered].some((e) => e.startsWith(\"plugins/\") && e !== \"plugins/*\");\n  if (hasPluginEntry) {\n    for (const entry of ordered) {\n      if (entry.startsWith(\"plugins/\") && entry !== \"plugins/*\") {\n        ordered.delete(entry);\n      }\n    }\n    ordered.add(\"plugins/*\");\n  }\n\n  return ordered.size > 0 ? [...ordered] : undefined;\n}\n\nexport function mergePackageJson(\n  filePath: string,\n  local: PackageJson,\n  template: PackageJson,\n  childScripts?: Record<string, string>,\n): PackageJson {\n  const merged: PackageJson = { ...local, ...template };\n\n  if (filePath === \"package.json\") {\n    for (const key of [\"name\", \"private\", \"version\"] as const) {\n      if (key in local) {\n        merged[key] = local[key];\n      }\n    }\n  } else if (\"version\" in local) {\n    merged.version = local.version;\n  }\n\n  for (const depField of [\n    \"dependencies\",\n    \"devDependencies\",\n    \"peerDependencies\",\n    \"overrides\",\n  ] as const) {\n    const localDeps = local[depField] as Record<string, string> | undefined;\n    const templateDeps = template[depField] as Record<string, string> | undefined;\n\n    const mergedDeps = mergeStringMaps(localDeps, templateDeps);\n    if (mergedDeps) {\n      merged[depField] = mergedDeps;\n    } else {\n      delete merged[depField];\n    }\n  }\n\n  if (\n    (local.scripts && typeof local.scripts === \"object\") ||\n    (template.scripts && typeof template.scripts === \"object\") ||\n    childScripts\n  ) {\n    const mergedScripts = mergeStringMaps(\n      local.scripts as Record<string, string> | undefined,\n      filePath === \"package.json\" && childScripts\n        ? childScripts\n        : (template.scripts as Record<string, string> | undefined),\n    );\n    if (mergedScripts) {\n      merged.scripts = mergedScripts;\n    } else {\n      delete merged.scripts;\n    }\n  }\n\n  if (\n    (local.workspaces && typeof local.workspaces === \"object\") ||\n    (template.workspaces && typeof template.workspaces === \"object\")\n  ) {\n    const localWorkspaces = (local.workspaces ?? {}) as {\n      packages?: string[];\n      catalog?: Record<string, string>;\n    };\n    const templateWorkspaces = (template.workspaces ?? {}) as {\n      packages?: string[];\n      catalog?: Record<string, string>;\n    };\n\n    const mergedWorkspaces: { packages?: string[]; catalog?: Record<string, string> } = {\n      ...localWorkspaces,\n      ...templateWorkspaces,\n    };\n\n    const mergedPackages = mergeWorkspacePackages(\n      localWorkspaces.packages,\n      templateWorkspaces.packages,\n    );\n    if (mergedPackages) {\n      mergedWorkspaces.packages = mergedPackages;\n    } else {\n      delete mergedWorkspaces.packages;\n    }\n\n    const mergedCatalog = mergeStringMaps(localWorkspaces.catalog, templateWorkspaces.catalog);\n    if (mergedCatalog) {\n      mergedWorkspaces.catalog = mergedCatalog;\n    } else {\n      delete mergedWorkspaces.catalog;\n    }\n\n    if (Object.keys(mergedWorkspaces).length > 0) {\n      merged.workspaces = mergedWorkspaces;\n    } else {\n      delete merged.workspaces;\n    }\n  }\n\n  return merged;\n}\n\nfunction toSourcePath(sourceDir: string, destPath: string): string | null {\n  if (destPath.startsWith(\".github/\")) {\n    const templatePath = destPath.replace(/^\\.github\\//, \".github/templates/\");\n    if (existsSync(join(sourceDir, templatePath))) {\n      return templatePath;\n    }\n  }\n\n  const directPath = join(sourceDir, destPath);\n  if (existsSync(directPath)) {\n    return destPath;\n  }\n\n  return null;\n}\n\nfunction buildSyncedFileContent(\n  sourceDir: string,\n  projectDir: string,\n  filePath: string,\n  explicitDestPath?: string,\n  childScripts?: Record<string, string>,\n): string | Uint8Array {\n  const src = join(sourceDir, filePath);\n  const destPath =\n    explicitDestPath ??\n    (filePath.startsWith(\".github/templates/\")\n      ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n      : filePath);\n  const dest = join(projectDir, destPath);\n\n  if (filePath.endsWith(\"bos.config.json\")) {\n    const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n    const templateContent = readFileSync(src, \"utf-8\");\n\n    if (localContent) {\n      const local = JSON.parse(localContent) as Record<string, unknown>;\n      const template = JSON.parse(templateContent) as Record<string, unknown>;\n      const merged = mergeBosConfigWithTemplate(local, template);\n      return `${JSON.stringify(merged, null, 2)}\\n`;\n    }\n  }\n\n  if (filePath.endsWith(\"package.json\")) {\n    const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n    const templateContent = readFileSync(src, \"utf-8\");\n\n    if (localContent) {\n      const local = JSON.parse(localContent) as Record<string, unknown>;\n      const template = JSON.parse(templateContent) as Record<string, unknown>;\n      const merged = mergePackageJson(destPath, local, template, childScripts);\n      return `${JSON.stringify(merged, null, 2)}\\n`;\n    }\n  }\n\n  return readFileSync(src);\n}\n\nfunction writeSyncedFile(\n  sourceDir: string,\n  projectDir: string,\n  filePath: string,\n  explicitDestPath?: string,\n  childScripts?: Record<string, string>,\n): void {\n  const destPath =\n    explicitDestPath ??\n    (filePath.startsWith(\".github/templates/\")\n      ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n      : filePath);\n  const dest = join(projectDir, destPath);\n  mkdirSync(dirname(dest), { recursive: true });\n  writeFileSync(\n    dest,\n    buildSyncedFileContent(sourceDir, projectDir, filePath, destPath, childScripts),\n  );\n}\n\nasync function getSelectedChildPlugins(\n  projectDir: string,\n  localConfig: Record<string, unknown>,\n): Promise<string[]> {\n  if (!localConfig.plugins || typeof localConfig.plugins !== \"object\") {\n    return [];\n  }\n\n  const pluginDirs = new Set(\n    (\n      await glob(\"plugins/*/package.json\", {\n        cwd: projectDir,\n        nodir: true,\n        dot: false,\n        absolute: false,\n      })\n    )\n      .map((file) => file.match(/^plugins\\/([^/]+)\\/package\\.json$/)?.[1])\n      .filter((key): key is string => Boolean(key)),\n  );\n\n  const selected: string[] = [];\n  for (const [pluginKey, rawEntry] of Object.entries(\n    localConfig.plugins as Record<string, unknown>,\n  )) {\n    if (typeof rawEntry === \"string\") {\n      if (!rawEntry.startsWith(\"local:\")) {\n        selected.push(pluginKey);\n        continue;\n      }\n\n      const localPath = join(projectDir, rawEntry.slice(\"local:\".length).trim());\n      if (existsSync(localPath) || pluginDirs.has(pluginKey)) {\n        selected.push(pluginKey);\n      }\n      continue;\n    }\n\n    if (!rawEntry || typeof rawEntry !== \"object\") {\n      selected.push(pluginKey);\n      continue;\n    }\n\n    const entry = rawEntry as Record<string, unknown>;\n    const development = typeof entry.development === \"string\" ? entry.development : undefined;\n    if (!development?.startsWith(\"local:\")) {\n      selected.push(pluginKey);\n      continue;\n    }\n\n    const localPath = join(projectDir, development.slice(\"local:\".length).trim());\n    if (existsSync(localPath) || pluginDirs.has(pluginKey)) {\n      selected.push(pluginKey);\n    }\n  }\n\n  return selected;\n}\n\nfunction hasPluginsWorkspace(projectDir: string): boolean {\n  const root = findWorkspaceRoot(projectDir);\n  if (!root) return false;\n  const rel = relative(root.dir, projectDir);\n  const baseDir = rel.startsWith(\"..\") || rel === \"\" ? root.dir : projectDir;\n  for (const manifest of [\"pnpm-workspace.yaml\", \"package.json\"]) {\n    const manifestPath = join(baseDir, manifest);\n    if (!existsSync(manifestPath)) continue;\n    try {\n      const content = readFileSync(manifestPath, \"utf-8\");\n      const packages =\n        manifest === \"pnpm-workspace.yaml\"\n          ? (parseYaml(content) as { packages?: unknown } | null)?.packages\n          : (\n              JSON.parse(content) as {\n                workspaces?: { packages?: string[] } | string[];\n              }\n            ).workspaces;\n      const globs: string[] = Array.isArray(packages)\n        ? packages\n        : Array.isArray((packages as { packages?: string[] })?.packages)\n          ? ((packages as { packages?: string[] }).packages ?? [])\n          : [];\n      if (globs.includes(\"plugins/*\")) return true;\n    } catch {\n      return false;\n    }\n  }\n  return false;\n}\n\nexport async function syncTemplate(projectDir: string, options: SyncOptions): Promise<SyncResult> {\n  // Sync reads the user's authored config — the raw bos.config.json, or the\n  // materialized bos.app.ts descriptor for TS-form children — not the\n  // resolved config: it needs the user's explicit local settings (their\n  // extends ref, selected plugins, etc.). The resolved config is the merged\n  // result and would include inherited parent values that the user didn't\n  // explicitly choose, which would break sync filtering.\n  const tsFormChild = existsSync(join(projectDir, \"bos.app.ts\"));\n  const localConfig = (\n    tsFormChild\n      ? await loadAppDescriptorConfig(join(projectDir, \"bos.app.ts\"))\n      : JSON.parse(readFileSync(join(projectDir, \"bos.config.json\"), \"utf-8\"))\n  ) as Record<string, unknown>;\n\n  let extendsRef: string | undefined;\n  if (typeof localConfig.extends === \"string\") {\n    extendsRef = localConfig.extends;\n  } else if (isPlainObjectFromMerge(localConfig.extends)) {\n    extendsRef = resolveExtendsRef(localConfig.extends as Record<string, string>, \"production\");\n  }\n  if (!extendsRef?.startsWith(\"bos://\")) {\n    return {\n      status: \"error\",\n      updated: [],\n      skipped: [],\n      added: [],\n      conflicted: [],\n      error: \"No extends field found in bos.config.json — cannot determine parent\",\n    };\n  }\n\n  const extendsMatch = extendsRef.match(/^bos:\\/\\/([^/]+)\\/(.+)$/);\n  if (!extendsMatch) {\n    return {\n      status: \"error\",\n      updated: [],\n      skipped: [],\n      added: [],\n      conflicted: [],\n      error: `Invalid extends reference: ${extendsRef}`,\n    };\n  }\n\n  const extendsAccount = extendsMatch[1];\n  const extendsGateway = extendsMatch[2];\n\n  const { sourceDir, cleanup } = await resolveSourceDir({\n    extendsAccount,\n    extendsGateway,\n  });\n\n  try {\n    const childPlugins = await getSelectedChildPlugins(projectDir, localConfig);\n    const withUi = existsSync(join(projectDir, \"ui\", \"package.json\"));\n    const withApi = existsSync(join(projectDir, \"api\", \"package.json\"));\n    const withHost = existsSync(join(projectDir, \"host\", \"package.json\"));\n    const withPlugins = childPlugins.length > 0 || hasPluginsWorkspace(projectDir);\n\n    const childScripts = buildChildRootScripts({\n      ui: withUi,\n      api: withApi,\n      host: withHost,\n      plugins: withPlugins,\n    });\n\n    const destToSource = new Map<string, string>();\n    // TS-form children author bos.app.ts — the parent's JSON config must\n    // never sync into them.\n    const tsFormChild = !existsSync(join(projectDir, \"bos.config.json\"));\n    for (const destPath of FRAMEWORK_OWNED_SYNC_FILES) {\n      if (destPath === \"bos.config.json\" && tsFormChild) continue;\n      if (destPath.startsWith(\"ui/\") && !withUi) continue;\n      if (destPath.startsWith(\"api/\") && !withApi) continue;\n      if (destPath.startsWith(\"host/\") && !withHost) continue;\n      const sourcePath = toSourcePath(sourceDir, destPath);\n      if (!sourcePath) continue;\n      destToSource.set(destPath, sourcePath);\n    }\n\n    for (const destPath of await glob(AGENT_SYNC_GLOBS, {\n      cwd: sourceDir,\n      nodir: true,\n      dot: true,\n      absolute: false,\n      ignore: [\"**/node_modules/**\", \"**/.git/**\", \"**/dist/**\", \"**/.bos/**\"],\n    })) {\n      destToSource.set(destPath, destPath);\n    }\n\n    // Sync api/src/lib/{auth,context}.ts into each plugin's src/lib/\n    for (const pluginKey of childPlugins) {\n      if (!existsSync(join(projectDir, \"plugins\", pluginKey, \"src\"))) continue;\n      for (const libFile of [\"auth.ts\", \"context.ts\"]) {\n        const sourceFile = `api/src/lib/${libFile}`;\n        if (!existsSync(join(sourceDir, sourceFile))) continue;\n        destToSource.set(`plugins/${pluginKey}/src/lib/${libFile}`, sourceFile);\n      }\n    }\n\n    // Sync api/src/global.d.ts into each plugin's src/\n    for (const pluginKey of childPlugins) {\n      if (!existsSync(join(projectDir, \"plugins\", pluginKey, \"src\"))) continue;\n      const sourceFile = \"api/src/global.d.ts\";\n      if (!existsSync(join(sourceDir, sourceFile))) continue;\n      destToSource.set(`plugins/${pluginKey}/src/global.d.ts`, sourceFile);\n    }\n\n    // Sync tests/types.d.ts into each plugin's tests/\n    for (const pluginKey of childPlugins) {\n      if (!existsSync(join(projectDir, \"plugins\", pluginKey))) continue;\n      const sourceFile = \"plugins/_template/tests/types.d.ts\";\n      if (!existsSync(join(sourceDir, sourceFile))) continue;\n      destToSource.set(`plugins/${pluginKey}/tests/types.d.ts`, sourceFile);\n    }\n\n    // Sync api/src/db/{index,layer,migrate}.ts into each plugin's src/db/\n    for (const pluginKey of childPlugins) {\n      if (!existsSync(join(projectDir, \"plugins\", pluginKey, \"src\", \"db\"))) continue;\n      for (const dbFile of [\"index.ts\", \"layer.ts\", \"migrate.ts\"]) {\n        const sourceFile = `api/src/db/${dbFile}`;\n        if (!existsSync(join(sourceDir, sourceFile))) continue;\n        destToSource.set(`plugins/${pluginKey}/src/db/${dbFile}`, sourceFile);\n      }\n    }\n\n    // Sync rspack.config.js from the template into each plugin\n    for (const pluginKey of childPlugins) {\n      if (!existsSync(join(projectDir, \"plugins\", pluginKey))) continue;\n      const sourceFile = \"plugins/_template/rspack.config.js\";\n      if (!existsSync(join(sourceDir, sourceFile))) continue;\n      destToSource.set(`plugins/${pluginKey}/rspack.config.js`, sourceFile);\n    }\n\n    // Sync drizzle.config.ts from api into each DB-enabled plugin\n    for (const pluginKey of childPlugins) {\n      if (!existsSync(join(projectDir, \"plugins\", pluginKey, \"src\", \"db\"))) continue;\n      const sourceFile = \"api/drizzle.config.ts\";\n      if (!existsSync(join(sourceDir, sourceFile))) continue;\n      destToSource.set(`plugins/${pluginKey}/drizzle.config.ts`, sourceFile);\n    }\n\n    // Sync tsconfig from the template into each plugin\n    for (const pluginKey of childPlugins) {\n      if (!existsSync(join(projectDir, \"plugins\", pluginKey))) continue;\n      const sourceFile = \"plugins/_template/tsconfig.json\";\n      if (!existsSync(join(sourceDir, sourceFile))) continue;\n      destToSource.set(`plugins/${pluginKey}/tsconfig.json`, sourceFile);\n    }\n\n    const updated: string[] = [];\n    const skipped: string[] = [];\n    const added: string[] = [];\n    const conflicted: string[] = [];\n\n    const snapshot = await readSnapshot(projectDir);\n    const snapshotFiles = snapshot?.files ?? {};\n\n    for (const [destPath, filePath] of destToSource.entries()) {\n      if (!existsSync(join(sourceDir, filePath))) {\n        // The template no longer ships this file — it was retired from the\n        // scaffold. Leave the local copy untouched rather than crashing the\n        // sync (the old-CLI + new-template transitional combo).\n        skipped.push(destPath);\n        continue;\n      }\n      const localHash = computeLocalHash(projectDir, destPath);\n      const sourceHash = computeHash(\n        buildSyncedFileContent(sourceDir, projectDir, filePath, undefined, childScripts),\n      );\n\n      if (localHash === null) {\n        added.push(destPath);\n        continue;\n      }\n\n      if (localHash === sourceHash) {\n        skipped.push(destPath);\n        continue;\n      }\n\n      const snapshotHash = snapshotFiles[destPath];\n      if (!snapshotHash) {\n        updated.push(destPath);\n        continue;\n      }\n\n      if (localHash === snapshotHash) {\n        updated.push(destPath);\n        continue;\n      }\n\n      if (sourceHash === snapshotHash) {\n        skipped.push(destPath);\n        continue;\n      }\n\n      conflicted.push(destPath);\n    }\n\n    const account = (localConfig.account as string) || extendsAccount;\n    const domain = (localConfig.domain as string) || extendsGateway;\n    const overrides: Array<\"ui\" | \"api\" | \"host\" | \"plugins\"> = [];\n    if (withUi) overrides.push(\"ui\");\n    if (withApi) overrides.push(\"api\");\n    if (withHost) overrides.push(\"host\");\n    if (withPlugins) overrides.push(\"plugins\");\n\n    if (options.dryRun) {\n      const agentsMdSourcePath = toSourcePath(sourceDir, \"AGENTS.md\");\n      if (agentsMdSourcePath) {\n        const agentsMdSourceContent = readFileSync(join(sourceDir, agentsMdSourcePath), \"utf-8\");\n        const skillsBlock = extractSkillsBlock(agentsMdSourceContent);\n        if (skillsBlock) {\n          const expectedContent = buildChildAgentsMd(skillsBlock, {\n            overrides,\n            plugins: childPlugins,\n          });\n          const expectedHash = computeHash(expectedContent);\n          const agentsMdLocalHash = computeLocalHash(projectDir, \"AGENTS.md\");\n          if (agentsMdLocalHash !== expectedHash) {\n            updated.push(\"AGENTS.md\");\n          }\n        }\n      }\n\n      const retirement = retireSyncedFiles(projectDir, snapshotFiles, { dryRun: true });\n\n      return {\n        status: \"dry-run\",\n        updated,\n        skipped,\n        added,\n        conflicted,\n        retired: retirement.retired,\n        retiredConflicted: retirement.retiredConflicted,\n      };\n    }\n\n    // Migrate the child off the retired bootstrap stubs (ADR 0023) before any\n    // writes — a retired file is never in destToSource, so its snapshot entry\n    // drops out at the next writeSnapshot.\n    const retirement = retireSyncedFiles(projectDir, snapshotFiles, { dryRun: false });\n\n    const filesToWrite = [...updated, ...added, ...conflicted];\n\n    let backupDir: string | undefined = retirement.backupDir ?? undefined;\n    if (filesToWrite.length > 0) {\n      backupDir = backupFiles(projectDir, filesToWrite) ?? backupDir;\n\n      for (const destPath of filesToWrite) {\n        const sourcePath = destToSource.get(destPath) ?? destPath;\n        writeSyncedFile(sourceDir, projectDir, sourcePath, destPath, childScripts);\n      }\n    }\n\n    await personalizeConfig(projectDir, {\n      extendsAccount,\n      extendsGateway,\n      account,\n      domain,\n      overrides,\n      plugins: childPlugins,\n      workspaceOpts: { sourceDir },\n      mode: \"sync\",\n      existingConfig: localConfig,\n    });\n\n    await syncResolvedSharedDeps({\n      configDir: projectDir,\n      hostMode: \"local\",\n    });\n\n    const syncedConfig = await openResolution({ cwd: projectDir });\n    if (syncedConfig?.runtime) {\n      await materializeViaLayer(projectDir, syncedConfig.runtime!);\n    }\n\n    const newSnapshotFiles: Record<string, string> = {};\n    for (const destPath of destToSource.keys()) {\n      const hash = computeLocalHash(projectDir, destPath);\n      if (hash) {\n        newSnapshotFiles[destPath] = hash;\n      }\n    }\n\n    const agentsMdSourcePath = toSourcePath(sourceDir, \"AGENTS.md\");\n    if (agentsMdSourcePath) {\n      const agentsMdSourceContent = readFileSync(join(sourceDir, agentsMdSourcePath), \"utf-8\");\n      const skillsBlock = extractSkillsBlock(agentsMdSourceContent);\n      if (skillsBlock) {\n        const expectedContent = buildChildAgentsMd(skillsBlock, {\n          overrides,\n          plugins: childPlugins,\n        });\n        const expectedHash = computeHash(expectedContent);\n\n        const agentsMdLocalHash = computeLocalHash(projectDir, \"AGENTS.md\");\n        if (agentsMdLocalHash !== expectedHash) {\n          writeFileSync(join(projectDir, \"AGENTS.md\"), expectedContent);\n          updated.push(\"AGENTS.md\");\n        }\n\n        newSnapshotFiles[\"AGENTS.md\"] = expectedHash;\n      }\n    }\n\n    await writeSnapshot(projectDir, {\n      parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n      files: newSnapshotFiles,\n    });\n\n    if (!options.noInstall) {\n      await runPnpmInstall(findWorkspaceRoot(projectDir)?.dir ?? projectDir);\n      await runTypesGen(projectDir);\n    }\n\n    return {\n      status: \"synced\",\n      updated,\n      skipped,\n      added,\n      conflicted,\n      retired: retirement.retired,\n      retiredConflicted: retirement.retiredConflicted,\n      retiredBackupDir: retirement.backupDir ?? undefined,\n      backupDir,\n    };\n  } finally {\n    await cleanup();\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAM,6CAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;AAUD,MAAa,qCAAqB,IAAI,IAAI;CACxC;CACA;CACA;CACA;CACA;AACF,CAAC;AAID,MAAM,mBAAmB;CAAC;CAAqB;CAAkB;AAAkB;AAEnF,SAAgB,yBAAyB,UAA2B;CAClE,IAAI,2BAA2B,IAAI,QAAQ,GAAG,OAAO;CACrD,IACE,SAAS,WAAW,iBAAiB,KACrC,SAAS,WAAW,cAAc,KAClC,aAAa,oBAEb,OAAO;CAGT,IAAI,0CAA0C,KAAK,QAAQ,GAAG,OAAO;CACrE,IAAI,uDAAuD,KAAK,QAAQ,GAAG,OAAO;CAClF,IAAI,uCAAuC,KAAK,QAAQ,GAAG,OAAO;CAClE,IAAI,wCAAwC,KAAK,QAAQ,GAAG,OAAO;CACnE,IAAI,uCAAuC,KAAK,QAAQ,GAAG,OAAO;CAClE,IA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