{"version":3,"file":"manifest.cjs","names":["z","FRAMEWORK_OWNED_SYNC_FILES","AGENT_SYNC_GLOBS","relative","join","existsSync","readFileSync","createHash","SHARED_DEP_SPECS","shareConfigFor","fileURLToPath","satisfiesConstraint","fetchRegistryKeyOrNull","fetchParentConfig","getExtendsRef","parseBosRef","Context","Layer"],"sources":["../../../src/services/platform/manifest.ts"],"sourcesContent":["/**\n * The platform release manifest (ADR 0034) — one module, the whole release\n * contract: schema, composer, inventory, registry slot, resolution, and the\n * compat check. One composer feeds both publish homes (FastKV pointer slot +\n * in-image staging); the image digest is deliberately absent — it derives from\n * the tags at deploy preflight. The homes' one known divergence is the compat\n * floor: publisher-side (previous release) in FastKV, own version — failing\n * closed — in the image, which cannot read the registry inside the build.\n */\nimport { createHash } from \"node:crypto\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join, relative } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { Context, Layer } from \"effect\";\nimport {\n  SHARED_DEP_SPECS,\n  type SharedDependencyConfig,\n  shareConfigFor,\n} from \"every-plugin/shared-deps-spec\";\nimport { glob } from \"glob\";\nimport { z } from \"zod\";\nimport { getExtendsRef, parseBosRef } from \"../../utils/bos-ref\";\nimport { satisfiesConstraint } from \"../federation/service\";\nimport { fetchRegistryKeyOrNull } from \"../registry/fastkv\";\nimport { fetchParentConfig } from \"../resolution/init-source\";\nimport { AGENT_SYNC_GLOBS, FRAMEWORK_OWNED_SYNC_FILES } from \"../scaffold/ownership\";\n\nexport const PlatformReleaseManifestSchema = z.object({\n  schemaVersion: z.literal(1),\n  kind: z.literal(\"everything-dev/platform-manifest\"),\n  frameworkVersion: z.string().min(1),\n  everyPluginVersion: z.string().min(1),\n  /** The serving build's repo HEAD (full sha) — omitted when the compose\n   * context has no git (regression image builds, build-arg-less builds). */\n  gitSha: z.string().min(7).optional(),\n  image: z.object({\n    ref: z.string().min(1),\n    tags: z.array(z.string().min(1)),\n  }),\n  catalog: z.record(z.string(), z.string()),\n  sharedDeps: z.record(\n    z.string(),\n    z.object({\n      version: z.string(),\n      requiredVersion: z.union([z.string(), z.boolean()]),\n      singleton: z.boolean(),\n      eager: z.boolean(),\n      strictVersion: z.boolean(),\n      shareScope: z.string(),\n    }),\n  ),\n  templateInventory: z.array(\n    z.object({\n      path: z.string(),\n      sha256: z.string().regex(/^[0-9a-f]{64}$/),\n    }),\n  ),\n  compat: z.object({ minChild: z.string().min(1) }),\n});\nexport type PlatformReleaseManifest = z.infer<typeof PlatformReleaseManifestSchema>;\n\nexport interface TemplateInventoryEntry {\n  path: string;\n  sha256: string;\n}\n\nexport function getPlatformManifestKey(accountId: string, gatewayId: string): string {\n  return `apps/${accountId}/${gatewayId}/platform.json`;\n}\n\n/**\n * The template-source file set a release inventory hashes: the ownership\n * inventory's static paths, the agent-sync globs, and the per-plugin template\n * scaffolding (`plugins/_template/*` — the sources of the per-plugin sync\n * patterns). Files absent from the release source are skipped, mirroring\n * sync's transitional tolerance.\n */\nconst TEMPLATE_SCAFFOLD_SOURCES = [\n  \"plugins/_template/rspack.config.js\",\n  \"plugins/_template/tsconfig.json\",\n  \"plugins/_template/tests/types.d.ts\",\n];\n\nfunction templateSourcePaths(sourceDir: string): string[] {\n  const paths = new Set<string>([...FRAMEWORK_OWNED_SYNC_FILES, ...TEMPLATE_SCAFFOLD_SOURCES]);\n  for (const match of glob.sync(AGENT_SYNC_GLOBS, {\n    cwd: sourceDir,\n    nodir: true,\n    dot: true,\n    ignore: [\"**/node_modules/**\", \"**/.git/**\", \"**/dist/**\", \"**/.bos/**\"],\n  })) {\n    paths.add(relative(sourceDir, join(sourceDir, match)));\n  }\n  return [...paths].sort();\n}\n\nexport function computeTemplateInventory(sourceDir: string): TemplateInventoryEntry[] {\n  const inventory: TemplateInventoryEntry[] = [];\n  for (const relativeFilePath of templateSourcePaths(sourceDir)) {\n    const fullPath = join(sourceDir, relativeFilePath);\n    if (!existsSync(fullPath)) continue;\n    try {\n      const content = readFileSync(fullPath);\n      inventory.push({\n        path: relativeFilePath,\n        sha256: createHash(\"sha256\").update(content).digest(\"hex\"),\n      });\n    } catch {\n      // unreadable at compose time → not part of the release inventory\n    }\n  }\n  return inventory.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));\n}\n\nexport function composeSharedDepsFromCatalog(\n  catalog: Record<string, string>,\n): Record<string, SharedDependencyConfig> {\n  const deps: Record<string, SharedDependencyConfig> = {};\n  for (const spec of SHARED_DEP_SPECS) {\n    const version = catalog[spec.name];\n    if (!version) continue;\n    deps[spec.name] = { version, ...shareConfigFor(spec, version) };\n  }\n  return deps;\n}\n\nexport interface ComposePlatformReleaseManifestInputs {\n  frameworkVersion: string;\n  everyPluginVersion: string;\n  gitSha?: string;\n  imageRef: string;\n  catalog: Record<string, string>;\n  templateInventory: TemplateInventoryEntry[];\n  compatMinChild: string;\n}\n\nexport function composePlatformReleaseManifest(\n  inputs: ComposePlatformReleaseManifestInputs,\n): PlatformReleaseManifest {\n  // The manifest carries only the derivable tag — the exact version tag the\n  // tag scheme pushes for semver releases (ADR 0021). Sha-tags are git facts\n  // an image build cannot see; derivation (`ref@v<version>` → digest) keys off\n  // the version tag so both publish homes stay byte-identical without any\n  // build-context plumbing.\n  const semver = parseSemver(inputs.frameworkVersion.trim());\n  const tags = semver\n    ? [\n        `v${semver.major}.${semver.minor}.${semver.patch}${semver.prerelease ? `-${semver.prerelease}` : \"\"}`,\n      ]\n    : [];\n  return PlatformReleaseManifestSchema.parse({\n    schemaVersion: 1,\n    kind: \"everything-dev/platform-manifest\",\n    frameworkVersion: inputs.frameworkVersion,\n    everyPluginVersion: inputs.everyPluginVersion,\n    ...(inputs.gitSha ? { gitSha: inputs.gitSha } : {}),\n    image: { ref: inputs.imageRef, tags },\n    catalog: inputs.catalog,\n    sharedDeps: composeSharedDepsFromCatalog(inputs.catalog),\n    templateInventory: inputs.templateInventory,\n    compat: { minChild: inputs.compatMinChild },\n  });\n}\n\n/** The one serializer for both publish homes — byte-identical by construction. */\nexport function serializePlatformReleaseManifest(manifest: PlatformReleaseManifest): string {\n  return JSON.stringify(manifest);\n}\n\n/**\n * The in-image copy (ADR 0034 pt 1): generated inside the docker build at\n * `packages/everything-dev/dist/platform-manifest.json`. Resolved relative to\n * this module — the compiled layout is `<pkg>/dist/services/platform/manifest.mjs`\n * (two directory levels up = `<pkg>/dist/`), the source layout is\n * `<pkg>/src/services/platform/manifest.ts` (four levels up = the pnpm parent\n * dir, then `<pkg>/dist/`). Both candidates are tried; absent or unparsable →\n * null.\n */\nexport function readInImagePlatformManifest(): PlatformReleaseManifest | null {\n  const moduleFile = fileURLToPath(import.meta.url);\n  const candidates = [\n    join(moduleFile, \"..\", \"..\", \"platform-manifest.json\"),\n    join(moduleFile, \"..\", \"..\", \"..\", \"..\", \"dist\", \"platform-manifest.json\"),\n  ];\n  for (const path of candidates) {\n    try {\n      return PlatformReleaseManifestSchema.parse(JSON.parse(readFileSync(path, \"utf-8\")));\n    } catch {\n      // try the next layout candidate\n    }\n  }\n  return null;\n}\n\nfunction parseSemver(\n  version: string,\n): { major: number; minor: number; patch: number; prerelease?: string } | null {\n  const match = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(version.trim());\n  if (!match) return null;\n  return {\n    major: Number(match[1]),\n    minor: Number(match[2]),\n    patch: Number(match[3]),\n    ...(match[4] ? { prerelease: match[4] } : {}),\n  };\n}\n\nfunction compareSemver(a: string, b: string): number {\n  const left = parseSemver(a);\n  const right = parseSemver(b);\n  if (!left || !right) return a === b ? 0 : a < b ? -1 : 1;\n  if (left.major !== right.major) return left.major - right.major;\n  if (left.minor !== right.minor) return left.minor - right.minor;\n  return left.patch - right.patch;\n}\n\nexport interface PlatformCompatSubject {\n  /** The child's recorded platform pin / installed framework version. */\n  platformVersion?: string;\n  catalog: Record<string, string>;\n}\n\nexport interface PlatformCompatViolation {\n  kind: \"minChild\" | \"shared-dep\";\n  name?: string;\n  message: string;\n}\n\n/**\n * The additive compat gate (ADR 0034 pt 5): the child's framework version must\n * sit inside the release's compat window, and strict singletons must agree\n * exactly with the release's pins. A sibling of the federation check — never\n * a relaxation of it.\n */\nexport function checkPlatformCompat(\n  manifest: PlatformReleaseManifest,\n  subject: PlatformCompatSubject,\n): PlatformCompatViolation[] {\n  const violations: PlatformCompatViolation[] = [];\n\n  if (subject.platformVersion) {\n    if (compareSemver(subject.platformVersion, manifest.compat.minChild) < 0) {\n      violations.push({\n        kind: \"minChild\",\n        message: `platform ${subject.platformVersion} is older than this release's compat floor ${manifest.compat.minChild}`,\n      });\n    }\n    if (compareSemver(subject.platformVersion, manifest.frameworkVersion) > 0) {\n      violations.push({\n        kind: \"minChild\",\n        message: `platform ${subject.platformVersion} is newer than this release ${manifest.frameworkVersion}`,\n      });\n    }\n  }\n\n  for (const [name, pin] of Object.entries(manifest.sharedDeps)) {\n    const childVersion = subject.catalog[name];\n    if (pin.strictVersion) {\n      if (!childVersion) {\n        violations.push({\n          kind: \"shared-dep\",\n          name,\n          message: `strict singleton \"${name}\" is missing from the child catalog (release pins ${pin.version})`,\n        });\n        continue;\n      }\n      if (childVersion !== pin.version) {\n        violations.push({\n          kind: \"shared-dep\",\n          name,\n          message: `strict singleton \"${name}\" is ${childVersion}, the release pins ${pin.version}`,\n        });\n      }\n      continue;\n    }\n    if (typeof pin.requiredVersion === \"string\" && childVersion) {\n      if (!satisfiesConstraint(childVersion, pin.requiredVersion)) {\n        violations.push({\n          kind: \"shared-dep\",\n          name,\n          message: `\"${name}\" is ${childVersion}, which does not satisfy the release range ${pin.requiredVersion}`,\n        });\n      }\n    }\n  }\n\n  return violations;\n}\n\n/**\n * Resolution (ADR 0034 pt 3): one authored `platform` pin in, one resolved\n * manifest out. Absent pin = latest via extends (nearest chain manifest);\n * explicit pins match exactly or fail loud. The `.bos/platform-manifest.json`\n * cache carries offline dev; network failure with no usable cache → null\n * (today's behavior). All I/O is injectable — the test seam.\n */\nexport interface ResolvedPlatformManifest {\n  manifest: PlatformReleaseManifest;\n  source: { account: string; gateway: string };\n  fromCache: boolean;\n}\n\nexport interface PlatformManifestCache {\n  schemaVersion: 1;\n  kind: \"everything-dev/platform-manifest-cache\";\n  resolvedAt: string;\n  source: { account: string; gateway: string };\n  manifest: PlatformReleaseManifest;\n}\n\n/**\n * How long a cached resolution may stand in for a live fetch. The cache\n * exists for offline dev; without a freshness bound a registry outage (or a\n * stale cache written before the parent's latest publish) silently serves a\n * months-old release manifest — pins derive from it and the mismatch can\n * take an hour to diagnose. Past the TTL the cache is refused: pin-less\n * resolution degrades to \"no manifest\", pinned resolution fails loud with\n * the pin-not-found error.\n */\nexport const PLATFORM_MANIFEST_CACHE_TTL_MS = 24 * 60 * 60_000;\n\nexport interface ResolvePlatformManifestOptions {\n  configDir: string;\n  localConfig: Record<string, unknown>;\n  fetchManifest?: (account: string, gateway: string) => Promise<PlatformReleaseManifest | null>;\n  fetchParent?: (account: string, gateway: string) => Promise<Record<string, unknown> | null>;\n  cacheRead?: () => PlatformManifestCache | null;\n  cacheWrite?: (cached: PlatformManifestCache) => void;\n  /** injectable clock for the cache-freshness check (test seam) */\n  now?: () => number;\n  /** injectable freshness bound (test seam); defaults to {@link PLATFORM_MANIFEST_CACHE_TTL_MS} */\n  cacheTtlMs?: number;\n}\n\nconst CACHE_DIR = \".bos\";\nconst CACHE_FILE = \"platform-manifest.json\";\n\n/**\n * A cached resolution stands in for a live fetch only while it is fresh:\n * `resolvedAt` inside the TTL, and parseable (a cache with an unparseable\n * timestamp is treated as stale — never trusted).\n */\nfunction isFresh(cached: PlatformManifestCache, opts: ResolvePlatformManifestOptions): boolean {\n  const now = (opts.now ?? Date.now)();\n  const ttl = opts.cacheTtlMs ?? PLATFORM_MANIFEST_CACHE_TTL_MS;\n  const resolvedAt = Date.parse(cached.resolvedAt);\n  if (Number.isNaN(resolvedAt)) return false;\n  return now - resolvedAt <= ttl;\n}\n\nfunction defaultCachePath(configDir: string): string {\n  return join(configDir, CACHE_DIR, CACHE_FILE);\n}\n\nfunction defaultCacheRead(configDir: string): PlatformManifestCache | null {\n  try {\n    const raw = JSON.parse(\n      readFileSync(defaultCachePath(configDir), \"utf-8\"),\n    ) as PlatformManifestCache;\n    return raw?.kind === \"everything-dev/platform-manifest-cache\" ? raw : null;\n  } catch {\n    return null;\n  }\n}\n\nfunction defaultCacheWrite(configDir: string, cached: PlatformManifestCache): void {\n  try {\n    mkdirSync(join(configDir, CACHE_DIR), { recursive: true });\n    writeFileSync(defaultCachePath(configDir), `${JSON.stringify(cached, null, 2)}\\n`);\n  } catch {\n    // cache writes never fail the resolution\n  }\n}\n\nfunction defaultFetchManifest(\n  account: string,\n  gateway: string,\n): Promise<PlatformReleaseManifest | null> {\n  return (async () => {\n    const raw = await fetchRegistryKeyOrNull<unknown>(account, gateway, \"platform.json\");\n    if (!raw) return null;\n    return PlatformReleaseManifestSchema.parse(raw);\n  })();\n}\n\nfunction defaultFetchParent(\n  account: string,\n  gateway: string,\n): Promise<Record<string, unknown> | null> {\n  return fetchParentConfig(account, gateway)\n    .then((config) => config as Record<string, unknown>)\n    .catch(() => null);\n}\n\nexport interface ExtendsChainNode {\n  account: string;\n  gateway: string;\n}\n\nexport interface ExtendsChainWalk {\n  /** child → root, nearest first — `chain[0]` is the local extends target */\n  chain: ExtendsChainNode[];\n  /** the most rootward `repository` seen — parent configs override the child's */\n  repository?: string;\n  /** set when the walk revisits a node — a pathological extends chain */\n  circularAt?: string;\n}\n\n/**\n * The ONE extends-chain walk (child → root via FastKV parent configs): both\n * `resolvePlatformManifest` and the upgrade source resolution used to carry\n * their own `fetchParentConfig` loops; this is the shared implementation.\n * A fetch failure (throw or null) stops the walk — the chain gathered so far\n * is still returned.\n */\nexport async function walkExtendsChain(input: {\n  localConfig: Record<string, unknown>;\n  localRepository?: string;\n  fetchParent?: (account: string, gateway: string) => Promise<Record<string, unknown> | null>;\n}): Promise<ExtendsChainWalk> {\n  const fetchParent = input.fetchParent ?? defaultFetchParent;\n  const chain: ExtendsChainNode[] = [];\n  let repository = input.localRepository;\n\n  const startsRef = getExtendsRef(input.localConfig);\n  let cursor: ExtendsChainNode | null =\n    typeof startsRef === \"string\" && startsRef.startsWith(\"bos://\")\n      ? (parseBosRef(startsRef) ?? null)\n      : null;\n  const visited = new Set<string>();\n  let circularAt: string | undefined;\n\n  while (cursor) {\n    const ref = `bos://${cursor.account}/${cursor.gateway}`;\n    if (visited.has(ref)) {\n      circularAt = ref;\n      break;\n    }\n    visited.add(ref);\n    chain.push(cursor);\n\n    const parentConfig = await fetchParent(cursor.account, cursor.gateway);\n    if (!parentConfig) break;\n    if (typeof parentConfig.repository === \"string\" && parentConfig.repository) {\n      repository = parentConfig.repository;\n    }\n    const nextRef = getExtendsRef(parentConfig);\n    cursor =\n      typeof nextRef === \"string\" && nextRef.startsWith(\"bos://\")\n        ? (parseBosRef(nextRef) ?? null)\n        : null;\n  }\n\n  return {\n    chain,\n    ...(repository !== undefined ? { repository } : {}),\n    ...(circularAt ? { circularAt } : {}),\n  };\n}\n\nexport async function resolvePlatformManifest(\n  opts: ResolvePlatformManifestOptions,\n): Promise<ResolvedPlatformManifest | null> {\n  const fetchManifest =\n    opts.fetchManifest ?? ((a: string, g: string) => defaultFetchManifest(a, g));\n  const cacheRead = opts.cacheRead ?? (() => defaultCacheRead(opts.configDir));\n  const cacheWrite = opts.cacheWrite ?? ((cached) => defaultCacheWrite(opts.configDir, cached));\n\n  const { chain } = await walkExtendsChain({\n    localConfig: opts.localConfig,\n    ...(opts.fetchParent ? { fetchParent: opts.fetchParent } : {}),\n  });\n\n  const writeCache = (\n    manifest: PlatformReleaseManifest,\n    source: { account: string; gateway: string },\n  ) => {\n    const cached: PlatformManifestCache = {\n      schemaVersion: 1,\n      kind: \"everything-dev/platform-manifest-cache\",\n      resolvedAt: new Date().toISOString(),\n      source,\n      manifest,\n    };\n    cacheWrite(cached);\n    return { manifest, source, fromCache: false };\n  };\n\n  const pin = typeof opts.localConfig.platform === \"string\" ? opts.localConfig.platform : undefined;\n\n  for (const node of chain) {\n    const manifest = await fetchManifest(node.account, node.gateway);\n    if (!manifest) continue;\n    if (!pin) return writeCache(manifest, node);\n    if (manifest.frameworkVersion === pin) return writeCache(manifest, node);\n  }\n\n  const cached = cacheRead();\n  if (cached && (!pin || cached.manifest.frameworkVersion === pin) && isFresh(cached, opts)) {\n    return { manifest: cached.manifest, source: cached.source, fromCache: true };\n  }\n\n  if (pin) {\n    throw new Error(\n      `platform pin ${pin} not found in the extends chain${chain.length > 0 ? ` (${chain.map((n) => `bos://${n.account}/${n.gateway}`).join(\" → \")})` : \"\"} — publish the release or clear the pin`,\n    );\n  }\n  return null;\n}\n\n/**\n * The platform release manifest as a Context.Service: the same \"module is\n * the implementation, the tag is the seam\" shape as FastKVRegistryService —\n * CLI handlers `yield*` the tag; pure and standalone callers keep using the\n * plain functions. Tests provide `Layer.succeed` fakes instead of module\n * mocks.\n */\nexport class PlatformManifestService extends Context.Service<\n  PlatformManifestService,\n  {\n    resolvePlatformManifest: typeof resolvePlatformManifest;\n    composePlatformReleaseManifest: typeof composePlatformReleaseManifest;\n    checkPlatformCompat: typeof checkPlatformCompat;\n    readInImagePlatformManifest: typeof readInImagePlatformManifest;\n  }\n>()(\"everything-dev/platform/manifest\") {\n  static readonly Live = Layer.succeed(\n    this,\n    this.of({\n      resolvePlatformManifest,\n      composePlatformReleaseManifest,\n      checkPlatformCompat,\n      readInImagePlatformManifest,\n    }),\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,gCAAgCA,MAAE,OAAO;CACpD,eAAeA,MAAE,QAAQ,CAAC;CAC1B,MAAMA,MAAE,QAAQ,kCAAkC;CAClD,kBAAkBA,MAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAClC,oBAAoBA,MAAE,OAAO,CAAC,CAAC,IAAI,CAAC;;;CAGpC,QAAQA,MAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;CACnC,OAAOA,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