{"version":3,"sources":["../src/guid.ts","../src/plugin-asset.ts","../src/scriptable-pack-relative-import.ts","../src/scriptable-pack-wire.ts","../src/scriptable-pack-worker.ts"],"names":["failure","resolve","extname"],"mappings":";;;;;;;;;;;AAuBiB,KAAA,CAAM,IAAA,CAAK,EAAE,MAAA,EAAQ,KAAI,EAAG,CAAC,CAAA,EAAG,CAAA,KAAM,EAAE,QAAA,CAAS,EAAE,EAAE,QAAA,CAAS,CAAA,EAAG,GAAG,CAAC;AAQtF,IAAM,OAAA,GAAU,iEAAA;AAST,SAAS,uBAAuB,KAAA,EAAiC;AACtE,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,OAAA,CAAQ,KAAK,KAAK,CAAA;AACxD;;;AClBA,SAAS,OAAA,CAAQ,MAAc,MAAA,EAAmC;AAChE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,uBAAA;AAAA,IACN,QAAA,EACE,wFAAA;AAAA,IACF,IAAA,EAAM,+DAAA;AAAA,IACN,MAAA,EAAQ,EAAE,IAAA,EAAM,MAAA;AAAO,GACzB;AACF;AAEA,SAAS,OAAO,KAAA,EAAkD;AAChE,EAAA,OACE,KAAA,KAAU,IAAA,IACV,OAAO,KAAA,KAAU,aAChB,MAAA,CAAO,cAAA,CAAe,KAAK,CAAA,KAAM,MAAA,CAAO,SAAA,IAAa,MAAA,CAAO,cAAA,CAAe,KAAK,CAAA,KAAM,IAAA,CAAA;AAE3F;AAEA,SAAS,eAAA,CAAgB,OAAgB,IAAA,EAA6C;AACpF,EAAA,IAAI,CAAC,MAAA,CAAO,KAAK,GAAG,OAAO,OAAA,CAAQ,MAAM,oCAAoC,CAAA;AAC7E,EAAA,IAAI,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,CAAE,IAAA,CAAK,CAAC,GAAA,KAAQ,GAAA,KAAQ,WAAA,IAAe,GAAA,KAAQ,QAAQ,CAAA,EAAG;AAC7E,IAAA,OAAO,OAAA,CAAQ,MAAM,gCAAgC,CAAA;A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A,CAAK,EAAA,CAAG,SAAA,EAAW,CAAC,OAAA,KAAqB;AACvC,EAAA,KAAK,cAAc,OAAO,CAAA;AAC5B,CAAC,CAAA;AAED,IAAI,CAAC,QAAA,IAAY,UAAA,KAAe,MAAA,IAAa,gBAAgB,MAAA,EAAW;AACtE,EAAA,IAAI;AACF,IAAA,MAAM,cAAA,CAAe;AAAA,MACnB,UAAA;AAAA,MACA,WAAA;AAAA,MACA,GAAI,eAAA,KAAoB,KAAA,CAAA,GAAY,EAAC,GAAI,EAAE,SAAS,eAAA;AAAgB,KACrE,CAAA;AAAA,EACH,SAAS,KAAA,EAAO;AACd,IAAA,IAAA,CAAK,WAAA,CAAY,EAAE,IAAA,EAAM,YAAA,EAAc,OAAO,OAAA,CAAQ,KAAK,GAAG,CAAA;AAAA,EAChE;AACF","file":"scriptable-pack-worker.mjs","sourcesContent":["import { uuidv7obj } from 'uuidv7';\nimport { PackError } from './errors.js';\nimport { uuidV5 } from './uuid-v5.js';\n\n/**\n * 16-byte UUID branded ABI. Prevents assignment from plain Uint8Array or string.\n * Brand field mirrors the declaration in @forgeax/engine-types for cross-package\n * structural compatibility (both use __guidBrand: 'AssetGuid').\n */\nexport type AssetGuid = Uint8Array & { readonly __guidBrand: 'AssetGuid' };\n\n/** Pack-level identity. It is intentionally not assignable to AssetGuid. */\nexport type PackageId = Uint8Array & { readonly __packageIdBrand: 'PackageId' };\n\n/** Minimal Result alias for this module (structurally compatible with ScanResult). */\nexport type GuidResult<T, E> =\n  | { readonly ok: true; readonly value: T }\n  | { readonly ok: false; readonly error: E };\n\nfunction brand(bytes: Uint8Array): AssetGuid {\n  return bytes as AssetGuid;\n}\n\nconst HEX_BYTE = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));\n\nfunction bytesToDashForm(bytes: Uint8Array): string {\n  const h = HEX_BYTE;\n  // biome-ignore lint/style/noNonNullAssertion: length guaranteed 16\n  return `${h[bytes[0]!]}${h[bytes[1]!]}${h[bytes[2]!]}${h[bytes[3]!]}-${h[bytes[4]!]}${h[bytes[5]!]}-${h[bytes[6]!]}${h[bytes[7]!]}-${h[bytes[8]!]}${h[bytes[9]!]}-${h[bytes[10]!]}${h[bytes[11]!]}${h[bytes[12]!]}${h[bytes[13]!]}${h[bytes[14]!]}${h[bytes[15]!]}`;\n}\n\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\n/** Stable author-owned output identity. Paths and payloads are not identity inputs. */\nexport const PACK_SOURCE_KEY_RE = /^[a-z0-9][a-z0-9._-]*(\\/[a-z0-9][a-z0-9._-]*)*$/;\n\nexport function isValidPackSourceKey(value: unknown): value is string {\n  return typeof value === 'string' && PACK_SOURCE_KEY_RE.test(value);\n}\n\nexport function isValidAssetGuidString(value: unknown): value is string {\n  return typeof value === 'string' && UUID_RE.test(value);\n}\n\nfunction dashFormToBytes(dashForm: string): Uint8Array {\n  const hex = dashForm.replace(/-/g, '');\n  const bytes = new Uint8Array(16);\n  for (let i = 0; i < 16; i++) {\n    bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n  }\n  return bytes;\n}\n\nfunction randomUuidBytes(): Uint8Array {\n  const uuid = uuidv7obj();\n  const bytes = new Uint8Array(16);\n  bytes.set(uuid.bytes);\n  return bytes;\n}\n\nfunction packageId(value: Uint8Array): PackageId {\n  return value as PackageId;\n}\n\n/** Utilities for the pack-level UUID identity. */\nexport const PackageId = {\n  parse(dashForm: string): GuidResult<PackageId, PackError> {\n    const parsed = AssetGuid.parse(dashForm);\n    return parsed.ok ? { ok: true, value: packageId(parsed.value) } : parsed;\n  },\n  format(value: PackageId): string {\n    return bytesToDashForm(value);\n  },\n  random(): PackageId {\n    return packageId(randomUuidBytes());\n  },\n} as const;\n\nfunction derivedGuid(namespace: PackageId, sourceKey: string): AssetGuid {\n  if (!(namespace instanceof Uint8Array) || namespace.byteLength !== 16) {\n    throw new TypeError('AssetGuid.derive requires a 16-byte PackageId');\n  }\n  if (!isValidPackSourceKey(sourceKey)) {\n    const error = new TypeError(\n      `AssetGuid.derive received invalid sourceKey ${JSON.stringify(sourceKey)}`,\n    ) as TypeError & { readonly code?: string };\n    Object.defineProperty(error, 'code', { value: 'pack-source-key-invalid' });\n    throw error;\n  }\n  return brand(uuidV5(namespace, sourceKey));\n}\n\n/**\n * Utilities for the AssetGuid branded 16-byte UUID type.\n * Declare the type via `import type { AssetGuid } from '@forgeax/engine-pack/guid'`\n * or `import type { AssetGuid } from '@forgeax/engine-types'`.\n */\nexport const AssetGuid = {\n  /**\n   * Parse a 36-char RFC 4122 dash-form UUID string into an AssetGuid.\n   * Returns Ok(AssetGuid) on success or Err(PackError) with code 'pack-guid-malformed' on failure.\n   * Never throws for expected failures (requirements §4.2 / §14 / charter proposition 4).\n   */\n  parse(dashForm: string): GuidResult<AssetGuid, PackError> {\n    if (!isValidAssetGuidString(dashForm)) {\n      return {\n        ok: false,\n        error: new PackError({\n          code: 'pack-guid-malformed',\n          expected: '36-char RFC 4122 dash-form UUID',\n          hint: 'use AssetGuid.random() or a UUIDv7 generator; all GUID fields must be 36-char RFC 4122 dash-form',\n          detail: {\n            raw: dashForm,\n            reason: 'expected 36-char RFC 4122 dash-form UUID',\n          },\n        }),\n      };\n    }\n    return { ok: true, value: brand(dashFormToBytes(dashForm)) };\n  },\n\n  /**\n   * Format an AssetGuid as a 36-char RFC 4122 lowercase dash-form string.\n   */\n  format(guid: AssetGuid): string {\n    return bytesToDashForm(guid);\n  },\n\n  /**\n   * Test byte-by-byte equality between two AssetGuids.\n   */\n  equals(a: AssetGuid, b: AssetGuid): boolean {\n    for (let i = 0; i < 16; i++) {\n      if (a[i] !== b[i]) return false;\n    }\n    return true;\n  },\n\n  /**\n   * Mint a new time-ordered UUIDv7 as an AssetGuid.\n   * Works in both Node.js and browser environments.\n   */\n  random(): AssetGuid {\n    return brand(randomUuidBytes());\n  },\n\n  /** Derive the stable UUIDv5 projection for one Pack subject and sourceKey. */\n  derive(namespace: PackageId, sourceKey: string): AssetGuid {\n    return derivedGuid(namespace, sourceKey);\n  },\n} as const;\n","import { isToolCommandContract, type ToolCommandContract } from '@forgeax/engine-tool-runtime';\nimport type { PluginAsset, PluginConfigValue, Result } from '@forgeax/engine-types';\nimport { err, ok } from '@forgeax/engine-types';\nimport { isValidAssetGuidString } from './guid.js';\n\nexport interface PluginModuleReference {\n  readonly specifier: string;\n  readonly export?: string;\n}\n\nexport interface PluginAssetSource {\n  readonly kind: 'plugin';\n  readonly module: PluginModuleReference;\n  readonly config?: PluginConfigValue;\n  readonly toolContract?: PluginModuleReference | ToolCommandContract;\n}\n\nexport interface PluginSourceError {\n  readonly code: 'plugin-source-invalid';\n  readonly expected: string;\n  readonly hint: string;\n  readonly detail: { readonly path: string; readonly reason: string };\n}\n\nfunction invalid(path: string, reason: string): PluginSourceError {\n  return {\n    code: 'plugin-source-invalid',\n    expected:\n      'a static module reference and a finite JSON configuration with explicit $asset markers',\n    hint: 'repair this Pack output before rebuilding its program closure',\n    detail: { path, reason },\n  };\n}\n\nfunction record(value: unknown): value is Record<string, unknown> {\n  return (\n    value !== null &&\n    typeof value === 'object' &&\n    (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)\n  );\n}\n\nfunction moduleReference(value: unknown, path: string): PluginSourceError | undefined {\n  if (!record(value)) return invalid(path, 'expected a module reference object');\n  if (Object.keys(value).some((key) => key !== 'specifier' && key !== 'export')) {\n    return invalid(path, 'unknown module reference field');\n  }\n  if (\n    typeof value.specifier !== 'string' ||\n    !value.specifier.trim() ||\n    /[\\0\\r\\n]/.test(value.specifier) ||\n    value.specifier.startsWith('/') ||\n    /^[a-zA-Z]:/.test(value.specifier)\n  ) {\n    return invalid(`${path}.specifier`, 'expected a relative path or package specifier');\n  }\n  if (value.export !== undefined && (typeof value.export !== 'string' || !value.export)) {\n    return invalid(`${path}.export`, 'expected a non-empty export name');\n  }\n  return undefined;\n}\n\nfunction configTree(\n  value: unknown,\n  path: string,\n  refs: Set<string> | undefined,\n  ancestors: Set<object>,\n): Result<PluginConfigValue, PluginSourceError> {\n  if (value === null || typeof value === 'boolean' || typeof value === 'string') return ok(value);\n  if (typeof value === 'number' && Number.isFinite(value)) return ok(value);\n  if (!Array.isArray(value) && !record(value))\n    return err(invalid(path, 'expected finite JSON data'));\n  if (ancestors.has(value)) return err(invalid(path, 'cyclic configuration'));\n  ancestors.add(value);\n  try {\n    if (Array.isArray(value)) {\n      const result: PluginConfigValue[] = [];\n      for (let index = 0; index < value.length; index++) {\n        const child = configTree(value[index], `${path}[${index}]`, refs, ancestors);\n        if (!child.ok) return child;\n        result.push(child.value);\n      }\n      if (\n        Reflect.ownKeys(value).some(\n          (key) => typeof key === 'symbol' || (key !== 'length' && !/^(0|[1-9][0-9]*)$/.test(key)),\n        )\n      ) {\n        return err(invalid(path, 'array has non-JSON properties'));\n      }\n      return ok(result);\n    }\n    const output: Record<string, PluginConfigValue> = {};\n    const keys = Reflect.ownKeys(value);\n    if (refs !== undefined && Object.hasOwn(value, '$asset')) {\n      if (\n        keys.length !== 1 ||\n        typeof value.$asset !== 'string' ||\n        !isValidAssetGuidString(value.$asset) ||\n        value.$asset !== value.$asset.toLowerCase()\n      ) {\n        return err(invalid(path, '$asset must be the sole field and contain a canonical UUID'));\n      }\n      refs.add(value.$asset);\n      return ok(value.$asset);\n    }\n    for (const key of keys) {\n      if (typeof key !== 'string') return err(invalid(path, 'symbol property is not JSON'));\n      const descriptor = Object.getOwnPropertyDescriptor(value, key);\n      if (!descriptor?.enumerable || !('value' in descriptor)) {\n        return err(invalid(`${path}.${key}`, 'accessors and hidden fields are not JSON'));\n      }\n      const child = configTree(descriptor.value, `${path}.${key}`, refs, ancestors);\n      if (!child.ok) return child;\n      // Preserve JSON data keys such as __proto__ without invoking inherited setters.\n      Object.defineProperty(output, key, {\n        value: child.value,\n        enumerable: true,\n        configurable: true,\n        writable: true,\n      });\n    }\n    return ok(output);\n  } finally {\n    ancestors.delete(value);\n  }\n}\n\nexport function lowerPluginConfig(value: unknown): Result<\n  {\n    readonly config: PluginConfigValue;\n    readonly refs: readonly string[];\n  },\n  PluginSourceError\n> {\n  const refs = new Set<string>();\n  const result = configTree(value, '$.config', refs, new Set());\n  return result.ok ? ok({ config: result.value, refs: [...refs].sort() }) : result;\n}\n\nexport function validatePluginAssetSource(\n  value: unknown,\n): Result<PluginAssetSource, PluginSourceError> {\n  if (!record(value) || value.kind !== 'plugin') return err(invalid('$', 'expected plugin source'));\n  if (\n    Object.keys(value).some((key) => !['kind', 'module', 'config', 'toolContract'].includes(key))\n  ) {\n    return err(invalid('$', 'unknown plugin source field'));\n  }\n  const moduleError = moduleReference(value.module, '$.module');\n  if (moduleError) return err(moduleError);\n  if (value.toolContract !== undefined && !isToolCommandContract(value.toolContract)) {\n    const contractError = moduleReference(value.toolContract, '$.toolContract');\n    if (contractError) return err(contractError);\n  }\n  if (Object.hasOwn(value, 'config')) {\n    const config = lowerPluginConfig(value.config);\n    if (!config.ok) return config;\n  }\n  return ok(value as unknown as PluginAssetSource);\n}\n\n/** Pure executor-reference lowering shared by static delivery and runtime source admission. */\nexport function lowerPluginToolContract(\n  contract: ToolCommandContract,\n  resolve: (module: PluginModuleReference) => string,\n): Result<ToolCommandContract, PluginSourceError> {\n  if (!isToolCommandContract(contract))\n    return err(invalid('$.toolContract', 'expected a pure tool command contract'));\n  try {\n    const commands = structuredClone(contract.commands).map(\n      ({ executor, exportName, ...command }) => {\n        if (executor === undefined) return command;\n        const reference = {\n          specifier: executor,\n          ...(exportName === undefined ? {} : { export: exportName }),\n        };\n        const error = moduleReference(reference, '$.toolContract.executor');\n        if (error) throw new TypeError(error.detail.reason);\n        const program = resolve(reference);\n        if (typeof program !== 'string' || !program.length)\n          throw new TypeError(`missing executor program ${executor}`);\n        return { ...command, executor: program };\n      },\n    );\n    return ok({ schemaVersion: '1.0.0', commands });\n  } catch (cause) {\n    return err(invalid('$.toolContract', cause instanceof Error ? cause.message : String(cause)));\n  }\n}\n\nexport function validatePluginAsset(value: unknown): Result<PluginAsset, PluginSourceError> {\n  if (\n    !record(value) ||\n    value.kind !== 'plugin' ||\n    typeof value.program !== 'string' ||\n    !value.program\n  ) {\n    return err(invalid('$', 'expected a cooked plugin definition with a program key'));\n  }\n  if (Object.keys(value).some((key) => !['kind', 'program', 'config'].includes(key))) {\n    return err(invalid('$', 'unknown cooked plugin field'));\n  }\n  if (Object.hasOwn(value, 'config')) {\n    const config = configTree(value.config, '$.config', undefined, new Set());\n    if (!config.ok) return config;\n  }\n  return ok(value as unknown as PluginAsset);\n}\n","import { dirname, extname, resolve } from 'node:path';\n\nexport const SCRIPTABLE_SOURCE_EXTENSIONS = [\n  '.ts',\n  '.tsx',\n  '.mts',\n  '.cts',\n  '.js',\n  '.mjs',\n  '.cjs',\n] as const;\n\n/** Keep execution and source inventory on the same first-existing-file search. */\nexport function relativeScriptableImportCandidates(\n  importer: string,\n  specifier: string,\n): readonly string[] {\n  if (!specifier.startsWith('.')) return [];\n  const raw = resolve(dirname(importer), specifier);\n  const extension = extname(raw);\n  const stem = raw.slice(0, raw.length - extension.length);\n  const substitutions =\n    extension === '.js'\n      ? [`${stem}.ts`, `${stem}.tsx`]\n      : extension === '.mjs'\n        ? [`${stem}.mts`]\n        : extension === '.cjs'\n          ? [`${stem}.cts`]\n          : [];\n  if (\n    extension === '.json' ||\n    SCRIPTABLE_SOURCE_EXTENSIONS.includes(\n      extension as (typeof SCRIPTABLE_SOURCE_EXTENSIONS)[number],\n    )\n  ) {\n    return [...substitutions, raw];\n  }\n  return [\n    raw,\n    ...SCRIPTABLE_SOURCE_EXTENSIONS.map((suffix) => `${raw}${suffix}`),\n    ...SCRIPTABLE_SOURCE_EXTENSIONS.map((suffix) => resolve(raw, `index${suffix}`)),\n  ];\n}\n","import type { PackParameterList, ScriptablePackDefinition } from './pack-authoring.js';\n\nconst definitionFields = [\n  'schemaVersion',\n  'packageId',\n  'name',\n  'parameters',\n  'sceneComponents',\n  'runtime',\n  'build',\n] as const satisfies readonly (keyof ScriptablePackDefinition<PackParameterList>)[];\nconst declaredFields = new Set<string>(definitionFields);\n\n/** Admission and worker projection use the same authored vocabulary. */\nexport function isScriptablePackField(name: string): boolean {\n  return declaredFields.has(name);\n}\n\nexport interface StructuredFailure {\n  readonly name?: unknown;\n  readonly code?: unknown;\n  readonly expected?: unknown;\n  readonly actual?: unknown;\n  readonly hint?: unknown;\n  readonly detail?: unknown;\n  readonly message?: unknown;\n}\n\n/** Preserve structured diagnostics across either direction of the worker port. */\nexport function projectFailure(value: object): StructuredFailure {\n  const failure = value as Record<string, unknown>;\n  return {\n    name: failure.name,\n    code: failure.code,\n    expected: failure.expected,\n    actual: failure.actual,\n    hint: failure.hint,\n    detail: failure.detail,\n    message: failure.message,\n  };\n}\n","import { createHash } from 'node:crypto';\nimport { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs';\nimport { extname, join, resolve } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { parentPort, workerData } from 'node:worker_threads';\nimport ts from 'typescript';\nimport { validatePluginAssetSource } from './plugin-asset.js';\nimport {\n  relativeScriptableImportCandidates,\n  SCRIPTABLE_SOURCE_EXTENSIONS,\n} from './scriptable-pack-relative-import.js';\nimport { isScriptablePackField, projectFailure } from './scriptable-pack-wire.js';\n\nif (parentPort === null) throw new Error('ScriptablePack worker requires a parent port');\n\nconst port = parentPort;\nconst workerMode = workerData as {\n  readonly mode?: 'single' | 'reusable';\n  readonly sourcePath?: string;\n  readonly compileRoot?: string;\n  readonly sources?: Readonly<Record<string, string>>;\n};\nconst reusable = workerMode.mode === 'reusable';\nlet sourcePath = workerMode.sourcePath;\nlet compileRoot = workerMode.compileRoot;\nlet capturedSources = workerMode.sources;\ntype LoadedDefinition = {\n  readonly schemaVersion?: unknown;\n  readonly packageId?: unknown;\n  readonly name?: unknown;\n  readonly parameters?: unknown;\n  readonly sceneComponents?: unknown;\n  readonly runtime?: unknown;\n  readonly build?: unknown;\n};\n// Forward undeclared fields so the main-thread validator refuses them exactly\n// as it refuses the same module loaded in-process; a value that cannot cross\n// the port is replaced by its type name.\nfunction undeclaredFields(value: object): Record<string, unknown> {\n  const fields: Record<string, unknown> = {};\n  for (const [key, field] of Object.entries(value)) {\n    if (isScriptablePackField(key)) continue;\n    try {\n      fields[key] = structuredClone(field);\n    } catch {\n      fields[key] = typeof field;\n    }\n  }\n  return fields;\n}\nlet definition: LoadedDefinition | undefined;\nlet nextReadId = 0;\nconst reads = new Map<number, (value: unknown) => void>();\n\nfunction failure(error: unknown): unknown {\n  if (error === null || typeof error !== 'object') return error;\n  return projectFailure(error);\n}\n\nfunction serializableSceneComponents(value: unknown): unknown {\n  if (!Array.isArray(value)) return undefined;\n  return value.map((component) => {\n    const candidate = component as { readonly name?: unknown; readonly fields?: unknown };\n    const fields =\n      candidate.fields !== null &&\n      typeof candidate.fields === 'object' &&\n      !Array.isArray(candidate.fields)\n        ? Object.fromEntries(\n            Object.entries(candidate.fields as Record<string, unknown>).map(([name, field]) => [\n              name,\n              typeof field === 'string' ? field : (field as { readonly type?: unknown })?.type,\n            ]),\n          )\n        : undefined;\n    return { name: candidate.name, fields };\n  });\n}\n\nfunction resolveRelativeImport(importer: string, specifier: string): string | undefined {\n  return relativeScriptableImportCandidates(importer, specifier).find((candidate) =>\n    capturedSources === undefined || !Object.hasOwn(capturedSources, importer)\n      ? existsSync(candidate) && statSync(candidate).isFile()\n      : Object.hasOwn(capturedSources, candidate),\n  );\n}\n\nfunction outputName(path: string): string {\n  const digest = createHash('sha256').update(path).digest('hex').slice(0, 20);\n  return `${digest}.mjs`;\n}\n\nfunction resolveBareImport(importer: string, specifier: string): string | undefined {\n  const resolver = (\n    import.meta as ImportMeta & {\n      readonly resolve?: (specifier: string, parent?: string) => string;\n    }\n  ).resolve;\n  if (resolver === undefined) return undefined;\n  // Resolve consumer dependencies from the source file first, then resolve\n  // Engine self-references from this worker's package. A compiled source\n  // closure lives in /tmp, so using only its path makes\n  // @forgeax/engine-pack/source disappear from Node's lookup ancestry.\n  for (const parent of [pathToFileURL(importer).href, import.meta.url]) {\n    try {\n      const resolved = resolver(specifier, parent);\n      if (resolved.startsWith('file:')) return fileURLToPath(resolved);\n    } catch {\n      // Try the loader package before treating the import as unavailable.\n    }\n  }\n  return undefined;\n}\n\nfunction resolvedModuleSpecifier(\n  target: string,\n  sources: ReadonlyMap<string, string>,\n  loadId?: number,\n): string {\n  if (sources.has(target)) {\n    return `./${outputName(target)}${loadId === undefined ? '' : `?load=${loadId}`}`;\n  }\n  return pathToFileURL(target).href;\n}\n\n/**\n * Node 22 does not execute `.ts` modules. Compile the trusted local module\n * closure into one disposable ESM directory before importing it. Bare package\n * imports are resolved by Node from the original source module and rewritten\n * to their canonical file URL; relative imports are rewritten to the compiled\n * closure by identity. This keeps unrelated nested node_modules directories\n * (for example Vite's cache) from changing package resolution.\n */\nfunction compileModuleClosure(entryPath: string, outputRoot: string, loadId?: number): string {\n  const pending = [resolve(entryPath)];\n  const sources = new Map<string, string>();\n  const imports = new Map<string, ReadonlyMap<string, string>>();\n  while (pending.length > 0) {\n    const path = pending.pop();\n    if (path === undefined || sources.has(path)) continue;\n    const source = capturedSources?.[path] ?? readFileSync(path, 'utf8');\n    const resolvedImports = new Map<string, string>();\n    const collectRuntimeImports: ts.TransformerFactory<ts.SourceFile> = () => (sourceFile) => {\n      const visit = (node: ts.Node): void => {\n        const specifier =\n          (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) &&\n          node.moduleSpecifier !== undefined &&\n          ts.isStringLiteral(node.moduleSpecifier)\n            ? node.moduleSpecifier.text\n            : ts.isCallExpression(node) &&\n                node.expression.kind === ts.SyntaxKind.ImportKeyword &&\n                node.arguments.length === 1 &&\n                node.arguments[0] !== undefined &&\n                ts.isStringLiteral(node.arguments[0])\n              ? node.arguments[0].text\n              : undefined;\n        if (specifier !== undefined) {\n          const target = specifier.startsWith('.')\n            ? resolveRelativeImport(path, specifier)\n            : resolveBareImport(path, specifier);\n          if (target !== undefined) {\n            resolvedImports.set(specifier, target);\n            if (specifier.startsWith('.') || /\\.(?:ts|tsx|mts|cts)$/.test(target)) {\n              pending.push(target);\n            }\n          }\n        }\n        ts.forEachChild(node, visit);\n      };\n      visit(sourceFile);\n      return sourceFile;\n    };\n    // Collect surviving dependencies after type erasure. Captured author\n    // source remains the inventory authority, including type-only files.\n    const transpiled = ts.transpileModule(source, {\n      fileName: path,\n      compilerOptions: {\n        target: ts.ScriptTarget.ES2022,\n        module: ts.ModuleKind.ESNext,\n        moduleResolution: ts.ModuleResolutionKind.Bundler,\n        isolatedModules: true,\n        sourceMap: false,\n      },\n      transformers: { after: [collectRuntimeImports] },\n      reportDiagnostics: true,\n    });\n    const errors =\n      transpiled.diagnostics?.filter(\n        (diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error,\n      ) ?? [];\n    if (errors.length > 0) {\n      throw new Error(\n        `ScriptablePack TypeScript transpile failed for ${path}: ${errors\n          .map((diagnostic) => {\n            const position = diagnostic.file?.getLineAndCharacterOfPosition(diagnostic.start ?? 0);\n            const location =\n              position === undefined\n                ? path\n                : `${path}:${position.line + 1}:${position.character + 1}`;\n            return `${location}: ${ts.flattenDiagnosticMessageText(diagnostic.messageText, '\\n')}`;\n          })\n          .join('; ')}`,\n      );\n    }\n    sources.set(path, transpiled.outputText);\n    imports.set(path, resolvedImports);\n  }\n\n  // Final membership keeps bare and relative aliases of one compiled file on\n  // the same module instance. Reparse emitted JS without another transpile.\n  const printer = ts.createPrinter();\n  for (const [path, source] of sources) {\n    const replacements = imports.get(path) ?? new Map<string, string>();\n    if (replacements.size === 0) {\n      writeFileSync(join(outputRoot, outputName(path)), source);\n      continue;\n    }\n    const rewriteRuntimeImports: ts.TransformerFactory<ts.SourceFile> = (context) => {\n      const visit: ts.Visitor = (node) => {\n        if (\n          (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) &&\n          node.moduleSpecifier !== undefined &&\n          ts.isStringLiteral(node.moduleSpecifier)\n        ) {\n          const target = replacements.get(node.moduleSpecifier.text);\n          if (target !== undefined) {\n            const rewrittenSpecifier = ts.factory.createStringLiteral(\n              resolvedModuleSpecifier(target, sources, loadId),\n            );\n            return ts.isImportDeclaration(node)\n              ? ts.factory.updateImportDeclaration(\n                  node,\n                  node.modifiers,\n                  node.importClause,\n                  rewrittenSpecifier,\n                  node.attributes,\n                )\n              : ts.factory.updateExportDeclaration(\n                  node,\n                  node.modifiers,\n                  node.isTypeOnly,\n                  node.exportClause,\n                  rewrittenSpecifier,\n                  node.attributes,\n                );\n          }\n        }\n        if (\n          ts.isCallExpression(node) &&\n          node.expression.kind === ts.SyntaxKind.ImportKeyword &&\n          node.arguments.length === 1 &&\n          node.arguments[0] !== undefined &&\n          ts.isStringLiteral(node.arguments[0])\n        ) {\n          const target = replacements.get(node.arguments[0].text);\n          if (target !== undefined) {\n            return ts.factory.updateCallExpression(node, node.expression, node.typeArguments, [\n              ts.factory.createStringLiteral(resolvedModuleSpecifier(target, sources, loadId)),\n            ]);\n          }\n        }\n        return ts.visitEachChild(node, visit, context);\n      };\n      return (sourceFile) => ts.visitNode(sourceFile, visit) as ts.SourceFile;\n    };\n    const transformed = ts.transform(\n      ts.createSourceFile(path, source, ts.ScriptTarget.ES2022, true, ts.ScriptKind.JS),\n      [rewriteRuntimeImports],\n    );\n    try {\n      const rewritten = transformed.transformed[0];\n      if (rewritten === undefined) throw new Error(`ScriptablePack rewrite failed for ${path}`);\n      writeFileSync(join(outputRoot, outputName(path)), printer.printFile(rewritten));\n    } finally {\n      transformed.dispose();\n    }\n  }\n  return join(outputRoot, outputName(resolve(entryPath)));\n}\n\nasync function loadDefinition(task: {\n  readonly sourcePath: string;\n  readonly compileRoot: string;\n  readonly loadId?: number;\n  readonly sources?: Readonly<Record<string, string>>;\n}): Promise<void> {\n  sourcePath = task.sourcePath;\n  compileRoot = task.compileRoot;\n  capturedSources = task.sources;\n  definition = undefined;\n  reads.clear();\n  const executablePath = SCRIPTABLE_SOURCE_EXTENSIONS.includes(\n    extname(task.sourcePath) as (typeof SCRIPTABLE_SOURCE_EXTENSIONS)[number],\n  )\n    ? compileModuleClosure(task.sourcePath, task.compileRoot, task.loadId)\n    : task.sourcePath;\n  const loaded = (await import(\n    `${pathToFileURL(executablePath).href}${reusable ? `?load=${task.loadId ?? 0}` : ''}`\n  )) as {\n    readonly default?: unknown;\n  };\n  definition = loaded.default as LoadedDefinition | undefined;\n  port.postMessage({\n    kind: 'loaded',\n    ...(task.loadId === undefined ? {} : { loadId: task.loadId }),\n    definition:\n      definition === undefined\n        ? undefined\n        : {\n            schemaVersion: definition.schemaVersion,\n            packageId: definition.packageId,\n            ...(definition.name === undefined ? {} : { name: definition.name }),\n            ...(definition.parameters === undefined ? {} : { parameters: definition.parameters }),\n            ...(definition.runtime === undefined ? {} : { runtime: definition.runtime }),\n            ...(definition.sceneComponents === undefined\n              ? {}\n              : { sceneComponents: serializableSceneComponents(definition.sceneComponents) }),\n            ...undeclaredFields(definition),\n          },\n  });\n}\n\nasync function handleMessage(message: unknown): Promise<void> {\n  if (message === null || typeof message !== 'object') return;\n  const value = message as Record<string, unknown>;\n  if (value.kind === 'asset-result' && typeof value.readId === 'number') {\n    reads.get(value.readId)?.(value.result);\n    reads.delete(value.readId);\n    return;\n  }\n  if (\n    reusable &&\n    value.kind === 'load' &&\n    typeof value.sourcePath === 'string' &&\n    typeof value.compileRoot === 'string' &&\n    typeof value.loadId === 'number'\n  ) {\n    try {\n      await loadDefinition({\n        sourcePath: value.sourcePath,\n        compileRoot: value.compileRoot,\n        loadId: value.loadId,\n        ...(value.sources === undefined\n          ? {}\n          : { sources: value.sources as Record<string, string> }),\n      });\n    } catch (error) {\n      port.postMessage({ kind: 'load-threw', loadId: value.loadId, error: failure(error) });\n    }\n    return;\n  }\n  if (value.kind !== 'build' || typeof value.buildId !== 'number') return;\n  if (typeof definition?.build !== 'function') {\n    port.postMessage({\n      kind: 'build-result',\n      buildId: value.buildId,\n      result: { ok: false, error: { message: 'default export has no build function' } },\n    });\n    return;\n  }\n  try {\n    const context =\n      value.context !== null && typeof value.context === 'object'\n        ? (value.context as { readonly packageId?: unknown; readonly values?: unknown })\n        : undefined;\n    const buildContext = {\n      ...(Array.isArray(context?.packageId)\n        ? { packageId: new Uint8Array(context.packageId as number[]) }\n        : {}),\n      ...(context?.values !== undefined ? { values: context.values } : {}),\n      readByGuid(guid: Uint8Array): Promise<unknown> {\n        const readId = nextReadId++;\n        port.postMessage({ kind: 'asset-read', buildId: value.buildId, readId, guid });\n        return new Promise((resolve) => reads.set(readId, resolve));\n      },\n    };\n    const result = await definition.build(buildContext);\n    if (\n      result !== null &&\n      typeof result === 'object' &&\n      'ok' in result &&\n      result.ok &&\n      'value' in result &&\n      result.value !== null &&\n      typeof result.value === 'object'\n    ) {\n      for (const output of Object.values(result.value)) {\n        if (\n          output !== null &&\n          typeof output === 'object' &&\n          'kind' in output &&\n          output.kind === 'plugin'\n        ) {\n          const validated = validatePluginAssetSource(output);\n          if (!validated.ok) throw validated.error;\n        }\n      }\n    }\n    port.postMessage({\n      kind: 'build-result',\n      buildId: value.buildId,\n      result:\n        result !== null && typeof result === 'object' && 'ok' in result && !result.ok\n          ? { ...result, error: failure(result.error) }\n          : result,\n    });\n  } catch (error) {\n    port.postMessage({ kind: 'build-threw', buildId: value.buildId, error: failure(error) });\n  }\n}\n\nport.on('message', (message: unknown) => {\n  void handleMessage(message);\n});\n\nif (!reusable && sourcePath !== undefined && compileRoot !== undefined) {\n  try {\n    await loadDefinition({\n      sourcePath,\n      compileRoot,\n      ...(capturedSources === undefined ? {} : { sources: capturedSources }),\n    });\n  } catch (error) {\n    port.postMessage({ kind: 'load-threw', error: failure(error) });\n  }\n}\n"]}