@tiangong-lca/foundry 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +532 -0
  3. package/docs/architecture.md +450 -0
  4. package/docs/foundry-task-contracts.md +147 -0
  5. package/docs/import-profiles/bafu/constraints.md +343 -0
  6. package/docs/import-profiles/bafu/leaf-process-classification-authoring.md +153 -0
  7. package/docs/import-profiles/bafu/profile.md +183 -0
  8. package/docs/import-profiles/uslci/constraints.md +29 -0
  9. package/docs/import-profiles/uslci/profile.md +43 -0
  10. package/docs/import-profiles/worldsteel/constraints.md +77 -0
  11. package/docs/import-profiles/worldsteel/import-coverage.md +93 -0
  12. package/docs/import-profiles/worldsteel/import-plan.md +375 -0
  13. package/docs/import-profiles/worldsteel/profile.md +78 -0
  14. package/docs/package-distribution-contract.md +287 -0
  15. package/docs/public-runtime-contract.md +218 -0
  16. package/docs/runtime-context-contract.md +138 -0
  17. package/docs/safety-policy.md +164 -0
  18. package/docs/task-authorization-contract.md +131 -0
  19. package/docs/uslci-import-runbook.md +336 -0
  20. package/docs/workspace-migration-contract.md +127 -0
  21. package/package-dist/assets/foundry-package-descriptor.json +1661 -0
  22. package/package-dist/scripts/foundry-facade.d.ts +78 -0
  23. package/package-dist/scripts/foundry-facade.js +1317 -0
  24. package/package-dist/scripts/foundry-runtime.d.ts +180 -0
  25. package/package-dist/scripts/foundry-runtime.js +190 -0
  26. package/package-dist/scripts/lib/batch-orchestration/scope-attempt-ledger.d.ts +27 -0
  27. package/package-dist/scripts/lib/batch-orchestration/scope-attempt-ledger.js +85 -0
  28. package/package-dist/scripts/lib/batch-orchestration/scope-resume-contract.d.ts +38 -0
  29. package/package-dist/scripts/lib/batch-orchestration/scope-resume-contract.js +90 -0
  30. package/package-dist/scripts/lib/bundle-row-types.d.ts +44 -0
  31. package/package-dist/scripts/lib/bundle-row-types.js +46 -0
  32. package/package-dist/scripts/lib/bundle-sample-utils.d.ts +183 -0
  33. package/package-dist/scripts/lib/bundle-sample-utils.js +526 -0
  34. package/package-dist/scripts/lib/bundle-source-context.d.ts +31 -0
  35. package/package-dist/scripts/lib/bundle-source-context.js +142 -0
  36. package/package-dist/scripts/lib/canonical-description.d.ts +12 -0
  37. package/package-dist/scripts/lib/canonical-description.js +72 -0
  38. package/package-dist/scripts/lib/canonical-support-rewrites.d.ts +127 -0
  39. package/package-dist/scripts/lib/canonical-support-rewrites.js +527 -0
  40. package/package-dist/scripts/lib/decision-owners/classification.d.ts +245 -0
  41. package/package-dist/scripts/lib/decision-owners/classification.js +754 -0
  42. package/package-dist/scripts/lib/decision-owners/identity-preflight.d.ts +333 -0
  43. package/package-dist/scripts/lib/decision-owners/identity-preflight.js +1353 -0
  44. package/package-dist/scripts/lib/decision-owners/identity-task.d.ts +130 -0
  45. package/package-dist/scripts/lib/decision-owners/identity-task.js +494 -0
  46. package/package-dist/scripts/lib/decision-owners/identity.d.ts +74 -0
  47. package/package-dist/scripts/lib/decision-owners/identity.js +443 -0
  48. package/package-dist/scripts/lib/decision-owners/location.d.ts +239 -0
  49. package/package-dist/scripts/lib/decision-owners/location.js +704 -0
  50. package/package-dist/scripts/lib/decision-task-utils.d.ts +484 -0
  51. package/package-dist/scripts/lib/decision-task-utils.js +735 -0
  52. package/package-dist/scripts/lib/finalize-owners/cli-wrappers.d.ts +52 -0
  53. package/package-dist/scripts/lib/finalize-owners/cli-wrappers.js +146 -0
  54. package/package-dist/scripts/lib/finalize-owners/commit-handoff.d.ts +79 -0
  55. package/package-dist/scripts/lib/finalize-owners/commit-handoff.js +515 -0
  56. package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +234 -0
  57. package/package-dist/scripts/lib/finalize-owners/post-authoring.js +1720 -0
  58. package/package-dist/scripts/lib/finalize-owners/post-write-closeout.d.ts +140 -0
  59. package/package-dist/scripts/lib/finalize-owners/post-write-closeout.js +656 -0
  60. package/package-dist/scripts/lib/foundry-args.d.ts +7 -0
  61. package/package-dist/scripts/lib/foundry-args.js +38 -0
  62. package/package-dist/scripts/lib/foundry-authentication-environment.d.ts +17 -0
  63. package/package-dist/scripts/lib/foundry-authentication-environment.js +55 -0
  64. package/package-dist/scripts/lib/foundry-authorization-input.d.ts +31 -0
  65. package/package-dist/scripts/lib/foundry-authorization-input.js +151 -0
  66. package/package-dist/scripts/lib/foundry-command-metadata.d.ts +32 -0
  67. package/package-dist/scripts/lib/foundry-command-metadata.js +1012 -0
  68. package/package-dist/scripts/lib/foundry-command-registry.d.ts +34 -0
  69. package/package-dist/scripts/lib/foundry-command-registry.js +241 -0
  70. package/package-dist/scripts/lib/foundry-command-spec.d.ts +1 -0
  71. package/package-dist/scripts/lib/foundry-command-spec.js +1 -0
  72. package/package-dist/scripts/lib/foundry-decision-owners.d.ts +17 -0
  73. package/package-dist/scripts/lib/foundry-decision-owners.js +68 -0
  74. package/package-dist/scripts/lib/foundry-decision-routing.d.ts +3 -0
  75. package/package-dist/scripts/lib/foundry-decision-routing.js +38 -0
  76. package/package-dist/scripts/lib/foundry-execution-admission.d.ts +33 -0
  77. package/package-dist/scripts/lib/foundry-execution-admission.js +225 -0
  78. package/package-dist/scripts/lib/foundry-execution-attempt.d.ts +11 -0
  79. package/package-dist/scripts/lib/foundry-execution-attempt.js +33 -0
  80. package/package-dist/scripts/lib/foundry-execution-context-format.d.ts +18 -0
  81. package/package-dist/scripts/lib/foundry-execution-context-format.js +83 -0
  82. package/package-dist/scripts/lib/foundry-facade-store.d.ts +25 -0
  83. package/package-dist/scripts/lib/foundry-facade-store.js +449 -0
  84. package/package-dist/scripts/lib/foundry-finalize-owners.d.ts +21 -0
  85. package/package-dist/scripts/lib/foundry-finalize-owners.js +203 -0
  86. package/package-dist/scripts/lib/foundry-identity-owners.d.ts +13 -0
  87. package/package-dist/scripts/lib/foundry-identity-owners.js +58 -0
  88. package/package-dist/scripts/lib/foundry-managed-host.d.ts +7 -0
  89. package/package-dist/scripts/lib/foundry-managed-host.js +173 -0
  90. package/package-dist/scripts/lib/foundry-migration-adoption-plan.d.ts +39 -0
  91. package/package-dist/scripts/lib/foundry-migration-adoption-plan.js +467 -0
  92. package/package-dist/scripts/lib/foundry-migration-adoption.d.ts +31 -0
  93. package/package-dist/scripts/lib/foundry-migration-adoption.js +187 -0
  94. package/package-dist/scripts/lib/foundry-migration-authority.d.ts +42 -0
  95. package/package-dist/scripts/lib/foundry-migration-authority.js +280 -0
  96. package/package-dist/scripts/lib/foundry-migration-inventory.d.ts +31 -0
  97. package/package-dist/scripts/lib/foundry-migration-inventory.js +148 -0
  98. package/package-dist/scripts/lib/foundry-migration-plan.d.ts +48 -0
  99. package/package-dist/scripts/lib/foundry-migration-plan.js +234 -0
  100. package/package-dist/scripts/lib/foundry-migration-replay.d.ts +3 -0
  101. package/package-dist/scripts/lib/foundry-migration-replay.js +134 -0
  102. package/package-dist/scripts/lib/foundry-migration-stage.d.ts +15 -0
  103. package/package-dist/scripts/lib/foundry-migration-stage.js +152 -0
  104. package/package-dist/scripts/lib/foundry-migration-transfer-io.d.ts +13 -0
  105. package/package-dist/scripts/lib/foundry-migration-transfer-io.js +226 -0
  106. package/package-dist/scripts/lib/foundry-migration-transfer.d.ts +36 -0
  107. package/package-dist/scripts/lib/foundry-migration-transfer.js +350 -0
  108. package/package-dist/scripts/lib/foundry-operation-result.d.ts +71 -0
  109. package/package-dist/scripts/lib/foundry-operation-result.js +264 -0
  110. package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +319 -0
  111. package/package-dist/scripts/lib/foundry-owner-execution-store.js +293 -0
  112. package/package-dist/scripts/lib/foundry-owner-readback.d.ts +22 -0
  113. package/package-dist/scripts/lib/foundry-owner-readback.js +189 -0
  114. package/package-dist/scripts/lib/foundry-owner-trace-acceptance.d.ts +15 -0
  115. package/package-dist/scripts/lib/foundry-owner-trace-acceptance.js +68 -0
  116. package/package-dist/scripts/lib/foundry-package-contract.d.ts +56 -0
  117. package/package-dist/scripts/lib/foundry-package-contract.js +392 -0
  118. package/package-dist/scripts/lib/foundry-private-path.d.ts +2 -0
  119. package/package-dist/scripts/lib/foundry-private-path.js +20 -0
  120. package/package-dist/scripts/lib/foundry-runtime-cache.d.ts +3 -0
  121. package/package-dist/scripts/lib/foundry-runtime-cache.js +25 -0
  122. package/package-dist/scripts/lib/foundry-runtime-command-policy.d.ts +20 -0
  123. package/package-dist/scripts/lib/foundry-runtime-command-policy.js +173 -0
  124. package/package-dist/scripts/lib/foundry-runtime-context-types.d.ts +59 -0
  125. package/package-dist/scripts/lib/foundry-runtime-context-types.js +1 -0
  126. package/package-dist/scripts/lib/foundry-runtime-context.d.ts +27 -0
  127. package/package-dist/scripts/lib/foundry-runtime-context.js +668 -0
  128. package/package-dist/scripts/lib/foundry-runtime-environment.d.ts +9 -0
  129. package/package-dist/scripts/lib/foundry-runtime-environment.js +90 -0
  130. package/package-dist/scripts/lib/foundry-runtime-error.d.ts +4 -0
  131. package/package-dist/scripts/lib/foundry-runtime-error.js +8 -0
  132. package/package-dist/scripts/lib/foundry-runtime-identity.d.ts +18 -0
  133. package/package-dist/scripts/lib/foundry-runtime-identity.js +127 -0
  134. package/package-dist/scripts/lib/foundry-runtime-paths.d.ts +16 -0
  135. package/package-dist/scripts/lib/foundry-runtime-paths.js +159 -0
  136. package/package-dist/scripts/lib/foundry-runtime-qualification.d.ts +66 -0
  137. package/package-dist/scripts/lib/foundry-runtime-qualification.js +223 -0
  138. package/package-dist/scripts/lib/foundry-runtime-selection-record.d.ts +16 -0
  139. package/package-dist/scripts/lib/foundry-runtime-selection-record.js +32 -0
  140. package/package-dist/scripts/lib/foundry-runtime-selection.d.ts +14 -0
  141. package/package-dist/scripts/lib/foundry-runtime-selection.js +123 -0
  142. package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +178 -0
  143. package/package-dist/scripts/lib/foundry-runtime-utils.js +603 -0
  144. package/package-dist/scripts/lib/foundry-semantic-input.d.ts +30 -0
  145. package/package-dist/scripts/lib/foundry-semantic-input.js +132 -0
  146. package/package-dist/scripts/lib/foundry-task-authorization.d.ts +68 -0
  147. package/package-dist/scripts/lib/foundry-task-authorization.js +350 -0
  148. package/package-dist/scripts/lib/foundry-task-io.d.ts +18 -0
  149. package/package-dist/scripts/lib/foundry-task-io.js +92 -0
  150. package/package-dist/scripts/lib/foundry-task-registration.d.ts +6 -0
  151. package/package-dist/scripts/lib/foundry-task-registration.js +384 -0
  152. package/package-dist/scripts/lib/foundry-task-start-spec.d.ts +34 -0
  153. package/package-dist/scripts/lib/foundry-task-start-spec.js +161 -0
  154. package/package-dist/scripts/lib/foundry-task-store.d.ts +18 -0
  155. package/package-dist/scripts/lib/foundry-task-store.js +466 -0
  156. package/package-dist/scripts/lib/foundry-task-types.d.ts +99 -0
  157. package/package-dist/scripts/lib/foundry-task-types.js +1 -0
  158. package/package-dist/scripts/lib/foundry-workflow-approval-continuation.d.ts +6 -0
  159. package/package-dist/scripts/lib/foundry-workflow-approval-continuation.js +136 -0
  160. package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +3 -0
  161. package/package-dist/scripts/lib/foundry-workflow-assessment.js +231 -0
  162. package/package-dist/scripts/lib/foundry-workflow-authorization.d.ts +22 -0
  163. package/package-dist/scripts/lib/foundry-workflow-authorization.js +174 -0
  164. package/package-dist/scripts/lib/foundry-workflow-context.d.ts +3 -0
  165. package/package-dist/scripts/lib/foundry-workflow-context.js +99 -0
  166. package/package-dist/scripts/lib/foundry-workflow-decisions.d.ts +18 -0
  167. package/package-dist/scripts/lib/foundry-workflow-decisions.js +123 -0
  168. package/package-dist/scripts/lib/foundry-workflow-execution.d.ts +8 -0
  169. package/package-dist/scripts/lib/foundry-workflow-execution.js +248 -0
  170. package/package-dist/scripts/lib/foundry-workflow-finalize.d.ts +13 -0
  171. package/package-dist/scripts/lib/foundry-workflow-finalize.js +264 -0
  172. package/package-dist/scripts/lib/foundry-workflow-identity-apply.d.ts +14 -0
  173. package/package-dist/scripts/lib/foundry-workflow-identity-apply.js +159 -0
  174. package/package-dist/scripts/lib/foundry-workflow-identity.d.ts +6 -0
  175. package/package-dist/scripts/lib/foundry-workflow-identity.js +153 -0
  176. package/package-dist/scripts/lib/foundry-workflow-import.d.ts +4 -0
  177. package/package-dist/scripts/lib/foundry-workflow-import.js +70 -0
  178. package/package-dist/scripts/lib/foundry-workflow-io.d.ts +11 -0
  179. package/package-dist/scripts/lib/foundry-workflow-io.js +77 -0
  180. package/package-dist/scripts/lib/foundry-workflow-reference-verify.d.ts +41 -0
  181. package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +266 -0
  182. package/package-dist/scripts/lib/foundry-workflow-rows.d.ts +2 -0
  183. package/package-dist/scripts/lib/foundry-workflow-rows.js +47 -0
  184. package/package-dist/scripts/lib/foundry-workflow-semantic.d.ts +5 -0
  185. package/package-dist/scripts/lib/foundry-workflow-semantic.js +367 -0
  186. package/package-dist/scripts/lib/foundry-workflow-state.d.ts +37 -0
  187. package/package-dist/scripts/lib/foundry-workflow-state.js +158 -0
  188. package/package-dist/scripts/lib/full-context-proof.d.ts +51 -0
  189. package/package-dist/scripts/lib/full-context-proof.js +932 -0
  190. package/package-dist/scripts/lib/identity-preflight-artifacts.d.ts +184 -0
  191. package/package-dist/scripts/lib/identity-preflight-artifacts.js +573 -0
  192. package/package-dist/scripts/lib/identity-preflight-proof.d.ts +117 -0
  193. package/package-dist/scripts/lib/identity-preflight-proof.js +341 -0
  194. package/package-dist/scripts/lib/identity-reference-rewrite-utils.d.ts +147 -0
  195. package/package-dist/scripts/lib/identity-reference-rewrite-utils.js +817 -0
  196. package/package-dist/scripts/lib/import-curation/authoring-packages.d.ts +28 -0
  197. package/package-dist/scripts/lib/import-curation/authoring-packages.js +92 -0
  198. package/package-dist/scripts/lib/import-curation/curation-cleanup.d.ts +32 -0
  199. package/package-dist/scripts/lib/import-curation/curation-cleanup.js +203 -0
  200. package/package-dist/scripts/lib/import-curation/curation-gate.d.ts +47 -0
  201. package/package-dist/scripts/lib/import-curation/curation-gate.js +528 -0
  202. package/package-dist/scripts/lib/import-curation/internal/artifact-inputs.d.ts +24 -0
  203. package/package-dist/scripts/lib/import-curation/internal/artifact-inputs.js +152 -0
  204. package/package-dist/scripts/lib/import-curation/internal/authoring-patch-workflow.d.ts +3 -0
  205. package/package-dist/scripts/lib/import-curation/internal/authoring-patch-workflow.js +3 -0
  206. package/package-dist/scripts/lib/import-curation/internal/authoring-task-workflow.d.ts +1 -0
  207. package/package-dist/scripts/lib/import-curation/internal/authoring-task-workflow.js +1 -0
  208. package/package-dist/scripts/lib/import-curation/internal/context-inputs.d.ts +56 -0
  209. package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +206 -0
  210. package/package-dist/scripts/lib/import-curation/internal/curation-gate-workflow.d.ts +14 -0
  211. package/package-dist/scripts/lib/import-curation/internal/curation-gate-workflow.js +14 -0
  212. package/package-dist/scripts/lib/import-curation/internal/dataset-payload.d.ts +70 -0
  213. package/package-dist/scripts/lib/import-curation/internal/dataset-payload.js +141 -0
  214. package/package-dist/scripts/lib/import-curation/internal/dataset-types.d.ts +25 -0
  215. package/package-dist/scripts/lib/import-curation/internal/dataset-types.js +45 -0
  216. package/package-dist/scripts/lib/import-curation/internal/full-context-proof.d.ts +129 -0
  217. package/package-dist/scripts/lib/import-curation/internal/full-context-proof.js +552 -0
  218. package/package-dist/scripts/lib/import-curation/internal/hash-utils.d.ts +2 -0
  219. package/package-dist/scripts/lib/import-curation/internal/hash-utils.js +10 -0
  220. package/package-dist/scripts/lib/import-curation/internal/mutation-manifest-workflow.d.ts +15 -0
  221. package/package-dist/scripts/lib/import-curation/internal/mutation-manifest-workflow.js +15 -0
  222. package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.d.ts +31 -0
  223. package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.js +467 -0
  224. package/package-dist/scripts/lib/import-curation/internal/profiles-config.d.ts +47 -0
  225. package/package-dist/scripts/lib/import-curation/internal/profiles-config.js +88 -0
  226. package/package-dist/scripts/lib/import-curation/internal/runtime-io.d.ts +23 -0
  227. package/package-dist/scripts/lib/import-curation/internal/runtime-io.js +132 -0
  228. package/package-dist/scripts/lib/import-curation/internal/trace-summary.d.ts +53 -0
  229. package/package-dist/scripts/lib/import-curation/internal/trace-summary.js +114 -0
  230. package/package-dist/scripts/lib/import-curation/internal/workflow-authoring-tasks.d.ts +141 -0
  231. package/package-dist/scripts/lib/import-curation/internal/workflow-authoring-tasks.js +854 -0
  232. package/package-dist/scripts/lib/import-curation/internal/workflow-decision-apply-context.d.ts +20 -0
  233. package/package-dist/scripts/lib/import-curation/internal/workflow-decision-apply-context.js +46 -0
  234. package/package-dist/scripts/lib/import-curation/internal/workflow-decision-full-context.d.ts +110 -0
  235. package/package-dist/scripts/lib/import-curation/internal/workflow-decision-full-context.js +782 -0
  236. package/package-dist/scripts/lib/import-curation/internal/workflow-dry-run-context.d.ts +24 -0
  237. package/package-dist/scripts/lib/import-curation/internal/workflow-dry-run-context.js +191 -0
  238. package/package-dist/scripts/lib/import-curation/internal/workflow-evidence-scope.d.ts +80 -0
  239. package/package-dist/scripts/lib/import-curation/internal/workflow-evidence-scope.js +359 -0
  240. package/package-dist/scripts/lib/import-curation/internal/workflow-identity-decision-context.d.ts +146 -0
  241. package/package-dist/scripts/lib/import-curation/internal/workflow-identity-decision-context.js +381 -0
  242. package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.d.ts +223 -0
  243. package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.js +1079 -0
  244. package/package-dist/scripts/lib/import-curation/internal/workflow-patch-collect.d.ts +41 -0
  245. package/package-dist/scripts/lib/import-curation/internal/workflow-patch-collect.js +412 -0
  246. package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence-context.d.ts +117 -0
  247. package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence-context.js +278 -0
  248. package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence.d.ts +59 -0
  249. package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence.js +593 -0
  250. package/package-dist/scripts/lib/import-curation/internal/workflow-queue-context.d.ts +58 -0
  251. package/package-dist/scripts/lib/import-curation/internal/workflow-queue-context.js +263 -0
  252. package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.d.ts +177 -0
  253. package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.js +812 -0
  254. package/package-dist/scripts/lib/import-curation/internal/workflow-row-transform-context.d.ts +159 -0
  255. package/package-dist/scripts/lib/import-curation/internal/workflow-row-transform-context.js +466 -0
  256. package/package-dist/scripts/lib/import-curation/internal/workflow-semantic-actions.d.ts +152 -0
  257. package/package-dist/scripts/lib/import-curation/internal/workflow-semantic-actions.js +1377 -0
  258. package/package-dist/scripts/lib/import-curation/internal/workflow-source-reference-context.d.ts +38 -0
  259. package/package-dist/scripts/lib/import-curation/internal/workflow-source-reference-context.js +116 -0
  260. package/package-dist/scripts/lib/import-curation/mutation-manifest.d.ts +51 -0
  261. package/package-dist/scripts/lib/import-curation/mutation-manifest.js +542 -0
  262. package/package-dist/scripts/lib/import-curation/patch-collect.d.ts +18 -0
  263. package/package-dist/scripts/lib/import-curation/patch-collect.js +172 -0
  264. package/package-dist/scripts/lib/import-curation/profiles.d.ts +1 -0
  265. package/package-dist/scripts/lib/import-curation/profiles.js +1 -0
  266. package/package-dist/scripts/lib/import-curation/trace-summary.d.ts +1 -0
  267. package/package-dist/scripts/lib/import-curation/trace-summary.js +1 -0
  268. package/package-dist/scripts/lib/oauth-session-reference.d.ts +1 -0
  269. package/package-dist/scripts/lib/oauth-session-reference.js +20 -0
  270. package/package-dist/scripts/lib/post-authoring-finalize-utils.d.ts +95 -0
  271. package/package-dist/scripts/lib/post-authoring-finalize-utils.js +548 -0
  272. package/package-dist/scripts/lib/post-write-root-proof.d.ts +44 -0
  273. package/package-dist/scripts/lib/post-write-root-proof.js +169 -0
  274. package/package-dist/scripts/lib/reference-description-text.d.ts +2 -0
  275. package/package-dist/scripts/lib/reference-description-text.js +12 -0
  276. package/package-dist/scripts/lib/remote-verification-accepted-diff.d.ts +42 -0
  277. package/package-dist/scripts/lib/remote-verification-accepted-diff.js +424 -0
  278. package/package-dist/scripts/lib/same-identity-commit-recovery.d.ts +8 -0
  279. package/package-dist/scripts/lib/same-identity-commit-recovery.js +52 -0
  280. package/package-dist/scripts/lib/source-semantics.d.ts +255 -0
  281. package/package-dist/scripts/lib/source-semantics.js +888 -0
  282. package/package-dist/scripts/lib/stage-contract.d.ts +36 -0
  283. package/package-dist/scripts/lib/stage-contract.js +25 -0
  284. package/package-dist/scripts/lib/task-authorization.d.ts +84 -0
  285. package/package-dist/scripts/lib/task-authorization.js +210 -0
  286. package/package-dist/scripts/lib/tidas-adapter.d.ts +113 -0
  287. package/package-dist/scripts/lib/tidas-adapter.js +525 -0
  288. package/package-dist/scripts/lib/tidas-language-utils.d.ts +8 -0
  289. package/package-dist/scripts/lib/tidas-language-utils.js +206 -0
  290. package/package-dist/scripts/lib/tidas-row-utils.d.ts +70 -0
  291. package/package-dist/scripts/lib/tidas-row-utils.js +225 -0
  292. package/package-dist/scripts/lib/trace-coverage.d.ts +53 -0
  293. package/package-dist/scripts/lib/trace-coverage.js +178 -0
  294. package/package-dist/scripts/package-entry.d.ts +2 -0
  295. package/package-dist/scripts/package-entry.js +4 -0
  296. package/package-dist/scripts/public-api.d.ts +80 -0
  297. package/package-dist/scripts/public-api.js +28 -0
  298. package/package-dist/scripts/runtime-entry.d.ts +23 -0
  299. package/package-dist/scripts/runtime-entry.js +424 -0
  300. package/package.json +93 -0
  301. package/specs/canonical-support/flow-properties-unit-groups.json +2692 -0
  302. package/specs/import-profiles.json +118 -0
  303. package/specs/prewrite-content-policy.json +105 -0
  304. package/specs/schemas/authorization-derivation.schema.json +34 -0
  305. package/specs/schemas/execution-context.schema.json +68 -0
  306. package/specs/schemas/foundry-authorization-input.schema.json +120 -0
  307. package/specs/schemas/foundry-facade-request-index.schema.json +78 -0
  308. package/specs/schemas/foundry-managed-runtime.schema.json +122 -0
  309. package/specs/schemas/foundry-migration-activation.schema.json +213 -0
  310. package/specs/schemas/foundry-migration-adoption-plan.schema.json +548 -0
  311. package/specs/schemas/foundry-migration-transfer-receipt.schema.json +93 -0
  312. package/specs/schemas/foundry-operation-result.schema.json +147 -0
  313. package/specs/schemas/foundry-package-descriptor.schema.json +134 -0
  314. package/specs/schemas/foundry-runtime-selection.schema.json +59 -0
  315. package/specs/schemas/foundry-semantic-input.schema.json +36 -0
  316. package/specs/schemas/foundry-task-start.schema.json +123 -0
  317. package/specs/schemas/foundry-workspace-migration-pending.schema.json +17 -0
  318. package/specs/schemas/foundry-workspace-migration-plan.schema.json +59 -0
  319. package/specs/schemas/foundry-workspace-migration-transfer-plan.schema.json +357 -0
  320. package/specs/schemas/foundry-workspace-v2.schema.json +70 -0
  321. package/specs/schemas/runtime-qualification.schema.json +63 -0
  322. package/specs/schemas/task-authorization.schema.json +154 -0
  323. package/specs/schemas/tidas-runtime-expectation.schema.json +54 -0
@@ -0,0 +1,888 @@
1
+ export function createSourceSemanticUtils({ asText, bundleClassificationPath, cloneJson, datasetIdentity, deterministicUuid, languageForText, multiLang, pathExpression, repoRelativeMaybe, textValue, }) {
2
+ function sourceDataSetInformation(payload) {
3
+ const payloadRecord = payload;
4
+ const sourceDataSet = payloadRecord?.sourceDataSet;
5
+ const sourceInformation = sourceDataSet?.sourceInformation;
6
+ const dataSetInformation = sourceInformation?.dataSetInformation;
7
+ return dataSetInformation && typeof dataSetInformation === "object"
8
+ ? dataSetInformation
9
+ : {};
10
+ }
11
+ function sourceShortName(payload) {
12
+ const dataSetInformation = sourceDataSetInformation(payload);
13
+ return (textValue(dataSetInformation["common:shortName"]) ||
14
+ textValue(dataSetInformation.shortName) ||
15
+ textValue(dataSetInformation.name));
16
+ }
17
+ function sourceCitationText(payload) {
18
+ const dataSetInformation = sourceDataSetInformation(payload);
19
+ return textValue(dataSetInformation.sourceCitation);
20
+ }
21
+ function sourceDescriptionText(payload) {
22
+ const dataSetInformation = sourceDataSetInformation(payload);
23
+ return textValue(dataSetInformation.sourceDescriptionOrComment);
24
+ }
25
+ function isBareSourceDescriptionText(value) {
26
+ const text = asText(value).trim();
27
+ return text === "" || /^(Report|Publication|Source)$/iu.test(text);
28
+ }
29
+ function isGenericEcoSpoldCompatibilitySourceText(value) {
30
+ return /^Created for EcoSpold 1 compatibility$/iu.test(asText(value));
31
+ }
32
+ function isPlaceholderSourceIdentityText(value) {
33
+ return /^(Not specified|Not declared|Unspecified)$/iu.test(asText(value));
34
+ }
35
+ function sourceMetadataFromDescription(description) {
36
+ const text = asText(description).replace(/\\n/gu, "\n");
37
+ if (!text)
38
+ return null;
39
+ const originalTitle = text.match(/^Original title:\s*(.+)$/imu)?.[1]?.trim();
40
+ const year = text.match(/^Year:\s*(\d{4})$/imu)?.[1] ?? text.match(/\((\d{4})\)/u)?.[1] ?? null;
41
+ const firstAuthor = text.match(/^First author:\s*(.+)$/imu)?.[1]?.trim() ??
42
+ text.match(/^([^(\n]+?)\s*\(\d{4}\)/u)?.[1]?.trim() ??
43
+ null;
44
+ const title = originalTitle ?? text.match(/\(\d{4}\)\s*([^.\n]+(?:\.[^.\n]+)*)/u)?.[1]?.trim() ?? null;
45
+ if (!title || !year)
46
+ return null;
47
+ const firstAuthorLastName = firstAuthor?.split(",")[0]?.trim() || firstAuthor?.split(/\s+/u)[0] || null;
48
+ const shortName = [year, title, firstAuthorLastName].filter(Boolean).join(" - ");
49
+ const firstLine = text.split(/\r?\n/u)[0]?.trim();
50
+ return {
51
+ shortName,
52
+ citation: firstLine && !isGenericEcoSpoldCompatibilitySourceText(firstLine) ? firstLine : shortName,
53
+ };
54
+ }
55
+ function normalizeDoi(value) {
56
+ const text = asText(value);
57
+ const doi = text.match(/\b10\.\d{4,9}\/[-._;()/:A-Z0-9]+/iu)?.[0];
58
+ return doi ? doi.replace(/[),.;\s]+$/u, "") : "";
59
+ }
60
+ function cleanOriginalSourceText(value) {
61
+ return asText(value)
62
+ .replace(/\s+/gu, " ")
63
+ .replace(/\s*UUID:\s*[0-9a-f-]{36}\b.*$/iu, "")
64
+ .replace(/\s*$/u, "")
65
+ .trim();
66
+ }
67
+ function processSourceContextTexts(payload) {
68
+ const payloadRecord = payload;
69
+ const process = (payloadRecord?.processDataSet ?? payload);
70
+ const processInformation = process?.processInformation;
71
+ const dataSetInformation = (processInformation?.dataSetInformation ?? {});
72
+ const modellingAndValidation = process?.modellingAndValidation;
73
+ const treatment = (modellingAndValidation?.dataSourcesTreatmentAndRepresentativeness ??
74
+ {});
75
+ const technology = processInformation?.technology;
76
+ return [
77
+ textValue(dataSetInformation["common:generalComment"]),
78
+ textValue(technology?.technologyDescriptionAndIncludedProcesses),
79
+ textValue(treatment.dataCutOffAndCompletenessPrinciples),
80
+ textValue(treatment.useAdviceForDataSet),
81
+ ]
82
+ .map(cleanOriginalSourceText)
83
+ .filter((text) => text && !/^(Unspecified|Not specified|Not declared)$/iu.test(text));
84
+ }
85
+ function authorLastName(value) {
86
+ const firstAuthor = asText(value)
87
+ .split(/\s*(?:,| and )\s*/u)
88
+ .find(Boolean);
89
+ if (!firstAuthor)
90
+ return "";
91
+ const particles = new Set(["de", "del", "der", "di", "dos", "du", "la", "le", "van", "von"]);
92
+ const tokens = firstAuthor
93
+ .replace(/\b[A-Z]\./gu, "")
94
+ .trim()
95
+ .split(/\s+/u)
96
+ .filter(Boolean);
97
+ if (tokens.length === 0)
98
+ return "";
99
+ const last = tokens[tokens.length - 1];
100
+ if (particles.has(last.toLowerCase()) && tokens.length > 1)
101
+ return tokens[tokens.length - 2];
102
+ return last;
103
+ }
104
+ function originalSourceMetadataFromText(value) {
105
+ const text = cleanOriginalSourceText(value);
106
+ if (!text)
107
+ return null;
108
+ const markerMatch = text.match(/Original source:\s*(.+)$/isu);
109
+ const sourceText = cleanOriginalSourceText(markerMatch?.[1] ?? text);
110
+ if (!markerMatch && !/\bdoi\s*:/iu.test(sourceText))
111
+ return null;
112
+ const doi = normalizeDoi(sourceText);
113
+ const withoutDoi = cleanOriginalSourceText(sourceText.replace(/\s*,?\s*doi\s*:\s*10\.\d{4,9}\/[-._;()/:A-Z0-9]+/iu, ""));
114
+ const sourcePattern = /^(?<authors>.+),\s*(?<title>[^,]+),\s*(?<container>.+?)\s+(?<year>(?:19|20)\d{2})\s*(?<details>.*)$/u;
115
+ const match = withoutDoi.match(sourcePattern);
116
+ const year = match?.groups?.year ?? withoutDoi.match(/\b((?:19|20)\d{2})\b/u)?.[1] ?? "";
117
+ const title = cleanOriginalSourceText(match?.groups?.title ?? "");
118
+ const authors = cleanOriginalSourceText(match?.groups?.authors ?? "");
119
+ const container = cleanOriginalSourceText(match?.groups?.container ?? "");
120
+ const details = cleanOriginalSourceText(match?.groups?.details ?? "");
121
+ if (!doi || !year || !title || !authors)
122
+ return null;
123
+ const firstAuthorLastName = authorLastName(authors);
124
+ return {
125
+ shortName: [year, title, firstAuthorLastName].filter(Boolean).join(" - "),
126
+ citation: sourceText,
127
+ description: [container || null, year || null, details || null, doi ? `DOI: ${doi}` : null]
128
+ .filter(Boolean)
129
+ .join("; "),
130
+ doi,
131
+ title,
132
+ year,
133
+ authors,
134
+ container: container || null,
135
+ details: details || null,
136
+ };
137
+ }
138
+ function processOriginalSourceMetadata(payload) {
139
+ for (const text of processSourceContextTexts(payload)) {
140
+ const metadata = originalSourceMetadataFromText(text);
141
+ if (metadata)
142
+ return metadata;
143
+ }
144
+ return null;
145
+ }
146
+ function sourceSummaryMatchesOriginalMetadata(source, metadata) {
147
+ if (!source?.dataset_id || !metadata)
148
+ return false;
149
+ const haystack = [
150
+ source.short_name,
151
+ source.source_citation,
152
+ source.source_description,
153
+ source.classification_path,
154
+ ]
155
+ .map(asText)
156
+ .join(" ")
157
+ .toLowerCase();
158
+ const doi = normalizeDoi(metadata.doi).toLowerCase();
159
+ if (doi && haystack.includes(doi))
160
+ return true;
161
+ const title = asText(metadata.title).toLowerCase();
162
+ return Boolean(title && haystack.includes(title));
163
+ }
164
+ function repairTrueSourceIdentity(payload, { sourceFile, stats, repairRows, }) {
165
+ if (sourceSemanticKind(payload) !== "true_source")
166
+ return;
167
+ const dataSetInformation = sourceDataSetInformation(payload);
168
+ if (!dataSetInformation || typeof dataSetInformation !== "object")
169
+ return;
170
+ const originalShortName = sourceShortName(payload);
171
+ const originalCitation = sourceCitationText(payload);
172
+ if (!isGenericEcoSpoldCompatibilitySourceText(originalShortName) &&
173
+ !isGenericEcoSpoldCompatibilitySourceText(originalCitation)) {
174
+ return;
175
+ }
176
+ const repaired = sourceMetadataFromDescription(sourceDescriptionText(payload));
177
+ if (!repaired?.shortName)
178
+ return;
179
+ dataSetInformation["common:shortName"] = multiLang(repaired.shortName, "en");
180
+ dataSetInformation.sourceCitation = repaired.citation;
181
+ const identity = datasetIdentity(payload, "source");
182
+ stats.true_source_identity_repairs += 1;
183
+ repairRows.push({
184
+ dataset_id: identity.id,
185
+ dataset_version: identity.version,
186
+ source_file: repoRelativeMaybe(sourceFile),
187
+ relation: "true_source_identity_from_description",
188
+ original_short_name: originalShortName || null,
189
+ original_source_citation: originalCitation || null,
190
+ repaired_short_name: repaired.shortName,
191
+ repaired_source_citation: repaired.citation,
192
+ basis: "Converted EcoSpold compatibility source name was generic; sourceDescriptionOrComment contains report metadata with title, year, and author.",
193
+ });
194
+ }
195
+ function repairTrueSourceDescription(payload, { sourceFile, stats, repairRows, }) {
196
+ if (sourceSemanticKind(payload) !== "true_source")
197
+ return;
198
+ const dataSetInformation = sourceDataSetInformation(payload);
199
+ if (!dataSetInformation || typeof dataSetInformation !== "object")
200
+ return;
201
+ const originalDescription = sourceDescriptionText(payload);
202
+ if (!isBareSourceDescriptionText(originalDescription))
203
+ return;
204
+ const citation = sourceCitationText(payload);
205
+ const shortName = sourceShortName(payload);
206
+ const evidence = citation || shortName;
207
+ if (!evidence)
208
+ return;
209
+ const repairedDescription = `Report/publication: ${evidence}.`;
210
+ dataSetInformation.sourceDescriptionOrComment = multiLang(repairedDescription, "en");
211
+ const identity = datasetIdentity(payload, "source");
212
+ stats.true_source_description_repairs += 1;
213
+ repairRows.push({
214
+ dataset_id: identity.id,
215
+ dataset_version: identity.version,
216
+ source_file: repoRelativeMaybe(sourceFile),
217
+ relation: "true_source_description_from_citation",
218
+ original_description: originalDescription || null,
219
+ repaired_description: repairedDescription,
220
+ basis: "Converted sourceDescriptionOrComment was empty or only a generic type word; citation/shortName identifies the report or publication source.",
221
+ });
222
+ }
223
+ function sourceSemanticKind(payload) {
224
+ // A reference to a known public canonical support source — the ILCD format spec
225
+ // (a97a0155) or the ILCD Data Network compliance system (d92a1a12) — IS that canonical
226
+ // dataset by identity, regardless of how a converted package classifies or names it.
227
+ // Some packages (e.g. USLCI) ship "ILCD format" classified as "Publications and
228
+ // communications" or list it under referenceToDataSource; without this it reads as a
229
+ // placeholder/true_source and is minted at the package version instead of reused, which
230
+ // trips the source-identity prewrite gate and would version_outdated against the
231
+ // published canonical. Recognize it by UUID so the canonical reference rewrite and the
232
+ // reference-only write exclusion both fire (matching its classified-as-format peers).
233
+ const canonicalSupportKind = canonicalSupportSourceKindForId(datasetIdentity(payload, "source")?.id);
234
+ if (canonicalSupportKind)
235
+ return canonicalSupportKind;
236
+ const classificationPath = bundleClassificationPath(payload, "source");
237
+ const classification = classificationPath.toLowerCase();
238
+ const citation = sourceCitationText(payload);
239
+ const shortNameText = sourceShortName(payload);
240
+ const shortName = shortNameText.toLowerCase();
241
+ if (classification.includes("data set formats"))
242
+ return "format_support_source";
243
+ if (classification.includes("compliance systems"))
244
+ return "compliance_support_source";
245
+ if (isPlaceholderSourceIdentityText(shortNameText) ||
246
+ isPlaceholderSourceIdentityText(citation)) {
247
+ return "placeholder_or_unspecified_source";
248
+ }
249
+ if (isGenericEcoSpoldCompatibilitySourceText(shortNameText) ||
250
+ isGenericEcoSpoldCompatibilitySourceText(citation)) {
251
+ const repaired = sourceMetadataFromDescription(sourceDescriptionText(payload));
252
+ return repaired?.shortName ? "true_source" : "unresolved_source_semantics";
253
+ }
254
+ if (citation)
255
+ return "true_source";
256
+ if (shortName.includes("not specified") ||
257
+ shortName.includes("not declared") ||
258
+ shortName === "unspecified") {
259
+ return "placeholder_or_unspecified_source";
260
+ }
261
+ return "unresolved_source_semantics";
262
+ }
263
+ function repairTrueSourceClassification(payload, { sourceFile, stats, repairRows, }) {
264
+ if (sourceSemanticKind(payload) !== "true_source")
265
+ return;
266
+ const currentClassification = bundleClassificationPath(payload, "source");
267
+ if (currentClassification && !/^Other source types$/iu.test(currentClassification)) {
268
+ return;
269
+ }
270
+ const dataSetInformation = sourceDataSetInformation(payload);
271
+ if (!dataSetInformation || typeof dataSetInformation !== "object")
272
+ return;
273
+ const classificationInformation = (dataSetInformation.classificationInformation ??=
274
+ {});
275
+ const classification = (classificationInformation["common:classification"] ??=
276
+ {});
277
+ classification["common:class"] = {
278
+ "@level": "0",
279
+ "@classId": "5",
280
+ "#text": "Publications and communications",
281
+ };
282
+ const identity = datasetIdentity(payload, "source");
283
+ const alreadyReported = repairRows.some((row) => row.dataset_id === identity.id &&
284
+ row.dataset_version === identity.version &&
285
+ row.relation === "true_source_publication_classification");
286
+ if (alreadyReported)
287
+ return;
288
+ stats.true_source_classification_repairs += 1;
289
+ repairRows.push({
290
+ dataset_id: identity.id,
291
+ dataset_version: identity.version,
292
+ source_file: repoRelativeMaybe(sourceFile),
293
+ relation: "true_source_publication_classification",
294
+ original_classification: currentClassification || null,
295
+ repaired_classification: "Publications and communications",
296
+ basis: "sourceCitation is present and the converted source category was generic Other source types.",
297
+ });
298
+ }
299
+ function sourceSemanticSummary(payload, sourceFile) {
300
+ const identity = datasetIdentity(payload, "source");
301
+ const kind = sourceSemanticKind(payload);
302
+ return {
303
+ dataset_id: identity.id,
304
+ dataset_version: identity.version,
305
+ source_file: repoRelativeMaybe(sourceFile),
306
+ kind,
307
+ materialized_as_source_row: kind === "true_source",
308
+ short_name: sourceShortName(payload),
309
+ source_citation: sourceCitationText(payload) || null,
310
+ source_description: sourceDescriptionText(payload) || null,
311
+ classification_path: bundleClassificationPath(payload, "source") || null,
312
+ };
313
+ }
314
+ function bafuFallbackSourceId() {
315
+ if (typeof deterministicUuid === "function") {
316
+ return deterministicUuid("tiangong-lca-foundry:bafu:database-source:BAFU 2025 Version 2");
317
+ }
318
+ return "7d6cb661-93f8-5c42-b23f-c3b73f8a6f97";
319
+ }
320
+ function processContextSourceId(metadata) {
321
+ const identityText = normalizeDoi(metadata?.doi) || asText(metadata?.citation) || asText(metadata?.shortName);
322
+ if (typeof deterministicUuid === "function") {
323
+ return deterministicUuid(`tiangong-lca-foundry:bafu:process-context-source:${identityText}`);
324
+ }
325
+ return identityText;
326
+ }
327
+ function buildBafuProcessContextSourcePayload({ metadata, contactReference, id = null, version = "00.00.001", language = "en", timestamp = null, } = {}) {
328
+ if (!metadata?.shortName || !metadata?.citation)
329
+ return null;
330
+ const sourceId = asText(id) || processContextSourceId(metadata);
331
+ const dataEntryBy = {
332
+ "common:referenceToDataSetFormat": canonicalSourceReferenceForRelation("dataset_format_source"),
333
+ };
334
+ if (timestamp) {
335
+ dataEntryBy["common:timeStamp"] = timestamp;
336
+ }
337
+ const publicationAndOwnership = {
338
+ "common:dataSetVersion": version,
339
+ "common:permanentDataSetURI": `https://www.bafu.admin.ch/bafu-2025-v2/sources/${sourceId}`,
340
+ };
341
+ if (contactReference) {
342
+ publicationAndOwnership["common:referenceToOwnershipOfDataSet"] = cloneJson(contactReference);
343
+ }
344
+ return {
345
+ sourceDataSet: {
346
+ "@xmlns": "http://lca.jrc.it/ILCD/Source",
347
+ "@xmlns:common": "http://lca.jrc.it/ILCD/Common",
348
+ "@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
349
+ "@version": "1.1",
350
+ "@xsi:schemaLocation": "http://lca.jrc.it/ILCD/Source ../../schemas/ILCD_SourceDataSet.xsd",
351
+ sourceInformation: {
352
+ dataSetInformation: {
353
+ "common:UUID": sourceId,
354
+ "common:shortName": multiLang(metadata.shortName, language),
355
+ classificationInformation: {
356
+ "common:classification": {
357
+ "common:class": {
358
+ "@level": "0",
359
+ "@classId": "5",
360
+ "#text": "Publications and communications",
361
+ },
362
+ },
363
+ },
364
+ sourceCitation: metadata.citation,
365
+ sourceDescriptionOrComment: multiLang(metadata.description || `Report/publication: ${metadata.citation}.`, language),
366
+ },
367
+ },
368
+ administrativeInformation: {
369
+ dataEntryBy,
370
+ publicationAndOwnership,
371
+ },
372
+ },
373
+ };
374
+ }
375
+ // Database-level fallback source identity is profile-specific. A converted
376
+ // package whose process data source points at a non-source placeholder (and
377
+ // that has no unambiguous process-specific report/publication source) is
378
+ // rewritten to cite the package's own database-level source. That source must
379
+ // belong to the package being imported — a USLCI process must cite the USLCI
380
+ // database, never BAFU's. The BAFU branch is kept byte-identical to the
381
+ // original so already-imported BAFU rows are unaffected.
382
+ function databaseFallbackSourceConfig(profile) {
383
+ const key = asText(profile).toLowerCase();
384
+ if (key === "uslci") {
385
+ return {
386
+ id: deterministicUuid("tiangong-lca-foundry:uslci:database-source:U.S. Life Cycle Inventory Database (USLCI)"),
387
+ shortName: "U.S. Life Cycle Inventory Database (USLCI)",
388
+ citation: "U.S. Life Cycle Inventory Database (USLCI), National Renewable Energy Laboratory (NREL), U.S. Federal LCA Commons, 2025.",
389
+ description: "Database-level fallback source used when the converted USLCI package has no more specific report, publication, or data-source evidence for the process scope.",
390
+ permanentDataSetUri: (sourceId) => `https://www.lcacommons.gov/uslci/${sourceId}`,
391
+ };
392
+ }
393
+ if (key === "worldsteel") {
394
+ // worldsteel ships no database-level source dataset of its own, so the
395
+ // converted steel processes whose data source resolves to a placeholder
396
+ // are cited to this synthesized worldsteel database source rather than
397
+ // silently inheriting the BAFU default. A worldsteel process must never
398
+ // cite the BAFU 2025 database.
399
+ return {
400
+ id: deterministicUuid("tiangong-lca-foundry:worldsteel:database-source:worldsteel LCI database"),
401
+ shortName: "worldsteel LCI database",
402
+ citation: "worldsteel Life Cycle Inventory (LCI) database, World Steel Association (worldsteel), 2022.",
403
+ description: "Database-level fallback source used when the converted worldsteel package has no more specific report, publication, or data-source evidence for the process scope.",
404
+ permanentDataSetUri: (sourceId) => `https://worldsteel.org/lci/${sourceId}`,
405
+ };
406
+ }
407
+ // Default (BAFU and any unspecified profile): preserve the original behavior.
408
+ return {
409
+ id: bafuFallbackSourceId(),
410
+ shortName: "BAFU 2025 Version 2 LCA database",
411
+ citation: "BAFU 2025 Version 2 LCA database, Federal Office for the Environment (FOEN), 2025.",
412
+ description: "Database-level fallback source used when the converted BAFU package has no more specific report, publication, or data-source evidence for the process scope.",
413
+ permanentDataSetUri: (sourceId) => `https://www.bafu.admin.ch/bafu-2025-v2/${sourceId}`,
414
+ };
415
+ }
416
+ function buildDatabaseFallbackSourcePayload({ profile = "bafu", contactReference, id = null, version = "00.00.001", language = "en", timestamp = null, } = {}) {
417
+ const config = databaseFallbackSourceConfig(profile);
418
+ const sourceId = asText(id) || config.id;
419
+ const shortName = config.shortName;
420
+ const citation = config.citation;
421
+ const description = config.description;
422
+ const dataFormatReference = canonicalSourceReferenceForRelation("dataset_format_source");
423
+ // ILCD expects the format reference inside dataEntryBy (see
424
+ // buildBafuProcessContextSourcePayload); at the administrativeInformation
425
+ // root it fails schema validation as an unknown member.
426
+ const dataEntryBy = {
427
+ "common:referenceToDataSetFormat": dataFormatReference,
428
+ };
429
+ if (timestamp) {
430
+ dataEntryBy["common:timeStamp"] = timestamp;
431
+ }
432
+ const publicationAndOwnership = {
433
+ "common:dataSetVersion": version,
434
+ "common:permanentDataSetURI": config.permanentDataSetUri(sourceId),
435
+ };
436
+ const admin = {
437
+ dataEntryBy,
438
+ publicationAndOwnership,
439
+ };
440
+ if (contactReference) {
441
+ publicationAndOwnership["common:referenceToOwnershipOfDataSet"] = cloneJson(contactReference);
442
+ }
443
+ return {
444
+ sourceDataSet: {
445
+ "@xmlns": "http://lca.jrc.it/ILCD/Source",
446
+ "@xmlns:common": "http://lca.jrc.it/ILCD/Common",
447
+ "@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
448
+ "@version": "1.1",
449
+ "@xsi:schemaLocation": "http://lca.jrc.it/ILCD/Source ../../schemas/ILCD_SourceDataSet.xsd",
450
+ sourceInformation: {
451
+ dataSetInformation: {
452
+ "common:UUID": sourceId,
453
+ "common:shortName": multiLang(shortName, language),
454
+ classificationInformation: {
455
+ "common:classification": {
456
+ "common:class": {
457
+ "@level": "0",
458
+ "@classId": "2",
459
+ "#text": "Databases",
460
+ },
461
+ },
462
+ },
463
+ sourceCitation: citation,
464
+ sourceDescriptionOrComment: multiLang(description, language),
465
+ },
466
+ },
467
+ administrativeInformation: admin,
468
+ },
469
+ };
470
+ }
471
+ // Backward-compatible alias: existing callers that explicitly want the BAFU
472
+ // database-level fallback source. New callers should use
473
+ // buildDatabaseFallbackSourcePayload({ profile }).
474
+ function buildBafuFallbackSourcePayload(options = {}) {
475
+ return buildDatabaseFallbackSourcePayload({ ...options, profile: "bafu" });
476
+ }
477
+ function sourceReferenceFromSummary(source, language = "en") {
478
+ const id = asText(source?.dataset_id);
479
+ if (!id)
480
+ return null;
481
+ const version = asText(source?.dataset_version) || "00.00.001";
482
+ const shortName = asText(source?.short_name) || "BAFU 2025 Version 2 LCA database";
483
+ return {
484
+ "@type": "source data set",
485
+ "@refObjectId": id,
486
+ "@version": version,
487
+ "@uri": `../sources/${id}_${version}.xml`,
488
+ "common:shortDescription": multiLang(shortName, language),
489
+ };
490
+ }
491
+ function sourceReferenceKind(pathSegments) {
492
+ const pathText = pathSegments.join(".");
493
+ if (pathText.includes("referenceToDataSource"))
494
+ return "process_data_source";
495
+ if (pathText.includes("referenceToDataSetFormat"))
496
+ return "dataset_format_source";
497
+ if (pathText.includes("referenceToComplianceSystem"))
498
+ return "compliance_system_source";
499
+ return "other_source_reference";
500
+ }
501
+ const canonicalSourceReferences = {
502
+ dataset_format_source: {
503
+ "@type": "source data set",
504
+ "@refObjectId": "a97a0155-0234-4b87-b4ce-a45da52f2a40",
505
+ "@version": "03.00.003",
506
+ "@uri": "../sources/a97a0155-0234-4b87-b4ce-a45da52f2a40_03.00.003.xml",
507
+ "common:shortDescription": multiLang("ILCD format", "en"),
508
+ },
509
+ compliance_system_source: {
510
+ "@type": "source data set",
511
+ "@refObjectId": "d92a1a12-2545-49e2-a585-55c259997756",
512
+ "@version": "20.20.002",
513
+ "@uri": "../sources/d92a1a12-2545-49e2-a585-55c259997756_20.20.002.xml",
514
+ "common:shortDescription": multiLang("ILCD Data Network - Entry-level", "en"),
515
+ },
516
+ };
517
+ function canonicalSourceReferenceForRelation(relation) {
518
+ const reference = canonicalSourceReferences[relation];
519
+ return reference ? cloneJson(reference) : null;
520
+ }
521
+ // A format/compliance support source is the same public canonical dataset no matter
522
+ // which slot references it. The path-relation maps a format/compliance slot to its
523
+ // canonical; this maps the source's own semantic KIND to the same canonical, so a
524
+ // format/compliance source landing in a non-format/compliance slot (e.g.
525
+ // modellingAndValidation/validation/review/common:referenceToCompleteReviewReport)
526
+ // is rewritten to the same public canonical source it would get on its format slot.
527
+ const canonicalSourceReferenceByKind = {
528
+ format_support_source: "dataset_format_source",
529
+ compliance_support_source: "compliance_system_source",
530
+ };
531
+ function canonicalSourceReferenceForSourceKind(kind) {
532
+ const relation = canonicalSourceReferenceByKind[asText(kind)];
533
+ return relation ? canonicalSourceReferenceForRelation(relation) : null;
534
+ }
535
+ // Inverse of canonicalSourceReferenceByKind + canonicalSourceReferences: map a source's
536
+ // own UUID to its canonical support KIND, so a public canonical support source is
537
+ // recognized by identity even when its converted classification/shortName would not
538
+ // otherwise resolve to format_support_source / compliance_support_source.
539
+ function canonicalSupportSourceKindForId(refObjectId) {
540
+ const id = asText(refObjectId);
541
+ if (!id)
542
+ return null;
543
+ for (const [kind, relation] of Object.entries(canonicalSourceReferenceByKind)) {
544
+ if (asText(canonicalSourceReferences[relation]?.["@refObjectId"]) === id) {
545
+ return kind;
546
+ }
547
+ }
548
+ return null;
549
+ }
550
+ function sourceReferenceSnapshot(reference) {
551
+ const referenceRecord = reference;
552
+ return {
553
+ ref_object_id: asText(referenceRecord?.["@refObjectId"]) || null,
554
+ version: asText(referenceRecord?.["@version"]) || null,
555
+ uri: asText(referenceRecord?.["@uri"]) || null,
556
+ short_description: textValue(referenceRecord?.["common:shortDescription"]) || null,
557
+ };
558
+ }
559
+ function rewriteCanonicalSourceReferences(value, { datasetType, sourceFile, stats, rewriteRows, pathSegments = [], datasetIdentityCache = null, sourceLookup = null, }) {
560
+ if (!value || typeof value !== "object")
561
+ return;
562
+ if (Array.isArray(value)) {
563
+ value.forEach((item, index) => rewriteCanonicalSourceReferences(item, {
564
+ datasetType,
565
+ sourceFile,
566
+ stats,
567
+ rewriteRows,
568
+ pathSegments: [...pathSegments, index],
569
+ datasetIdentityCache,
570
+ sourceLookup,
571
+ }));
572
+ return;
573
+ }
574
+ const valueRecord = value;
575
+ const relation = sourceReferenceKind(pathSegments);
576
+ const refType = asText(valueRecord["@type"]).toLowerCase();
577
+ const refObjectId = asText(valueRecord["@refObjectId"]);
578
+ // The canonical target is fixed first by the reference path-relation (format /
579
+ // compliance slots), then — for any other slot, e.g. referenceToCompleteReviewReport
580
+ // — by the referenced source's own semantic KIND when a sourceLookup is supplied. A
581
+ // format/compliance support source ("ILCD format"/"Data set formats",
582
+ // "...compliance systems") is the same public canonical dataset wherever it is
583
+ // referenced, so it must be rewritten on every path; a true source has no kind-based
584
+ // canonical and is never touched here.
585
+ let canonical = canonicalSourceReferenceForRelation(relation);
586
+ // effectiveRelation records WHY the rewrite happened: a path-relation rewrite keeps
587
+ // its slot relation; a kind-based rewrite on an otherwise-unmapped slot records the
588
+ // referenced source's support kind so the rewrite row is traceable.
589
+ let effectiveRelation = relation;
590
+ let kindBasedRewrite = false;
591
+ if (!canonical && sourceLookup && refObjectId && refType.includes("source")) {
592
+ const referencedKind = sourceLookup.get(refObjectId)?.kind;
593
+ canonical = canonicalSourceReferenceForSourceKind(referencedKind);
594
+ if (canonical) {
595
+ effectiveRelation = asText(referencedKind) || relation;
596
+ kindBasedRewrite = true;
597
+ }
598
+ }
599
+ if (canonical && refObjectId && refType.includes("source")) {
600
+ const before = sourceReferenceSnapshot(valueRecord);
601
+ const after = sourceReferenceSnapshot(canonical);
602
+ if (before.ref_object_id !== after.ref_object_id ||
603
+ before.version !== after.version ||
604
+ before.short_description !== after.short_description) {
605
+ const identity = datasetIdentityCache && datasetIdentityCache.id
606
+ ? datasetIdentityCache
607
+ : datasetIdentity(valueRecord, datasetType);
608
+ stats.source_reference_rewrites += 1;
609
+ rewriteRows.push({
610
+ dataset_type: datasetType,
611
+ dataset_id: identity.id,
612
+ dataset_version: identity.version,
613
+ source_file: repoRelativeMaybe(sourceFile),
614
+ path: pathExpression(pathSegments),
615
+ relation: effectiveRelation,
616
+ original: before,
617
+ canonical: after,
618
+ reason: kindBasedRewrite
619
+ ? "A format/compliance support source referenced outside its format/compliance slot (e.g. a review report reference) is rewritten to the same public canonical source it uses on its format/compliance slot, so reference closure proves it as a reusable public dataset."
620
+ : relation === "dataset_format_source"
621
+ ? "Data set format uses the public canonical ILCD format source instead of a converted package-local support source."
622
+ : "Compliance declaration uses the public canonical ILCD Data Network Entry-level source instead of a converted placeholder support source.",
623
+ });
624
+ }
625
+ Object.keys(valueRecord).forEach((key) => {
626
+ delete valueRecord[key];
627
+ });
628
+ Object.assign(valueRecord, cloneJson(canonical));
629
+ }
630
+ for (const [key, child] of Object.entries(valueRecord)) {
631
+ rewriteCanonicalSourceReferences(child, {
632
+ datasetType,
633
+ sourceFile,
634
+ stats,
635
+ rewriteRows,
636
+ pathSegments: [...pathSegments, key],
637
+ datasetIdentityCache,
638
+ sourceLookup,
639
+ });
640
+ }
641
+ }
642
+ function rewriteTrueSourceReferenceDescriptions(value, { sourceLookup, sourceFile, stats, rewriteRows, pathSegments = [], datasetIdentityCache = null, }) {
643
+ if (!value || typeof value !== "object")
644
+ return;
645
+ if (Array.isArray(value)) {
646
+ value.forEach((item, index) => rewriteTrueSourceReferenceDescriptions(item, {
647
+ sourceLookup,
648
+ sourceFile,
649
+ stats,
650
+ rewriteRows,
651
+ pathSegments: [...pathSegments, index],
652
+ datasetIdentityCache,
653
+ }));
654
+ return;
655
+ }
656
+ const valueRecord = value;
657
+ const relation = sourceReferenceKind(pathSegments);
658
+ const refType = asText(valueRecord["@type"]).toLowerCase();
659
+ const refObjectId = asText(valueRecord["@refObjectId"]);
660
+ if (relation === "process_data_source" && refObjectId && refType.includes("source")) {
661
+ const source = sourceLookup.get(refObjectId);
662
+ const canonicalShortName = asText(source?.short_name);
663
+ const currentShortName = textValue(valueRecord["common:shortDescription"]);
664
+ if (source?.kind === "true_source" &&
665
+ canonicalShortName &&
666
+ currentShortName !== canonicalShortName) {
667
+ const before = sourceReferenceSnapshot(valueRecord);
668
+ valueRecord["common:shortDescription"] = multiLang(canonicalShortName, languageForText(canonicalShortName));
669
+ const after = sourceReferenceSnapshot(valueRecord);
670
+ stats.true_source_reference_description_repairs += 1;
671
+ const identity = datasetIdentityCache && datasetIdentityCache.id
672
+ ? datasetIdentityCache
673
+ : { id: null, version: null };
674
+ rewriteRows.push({
675
+ dataset_type: "process",
676
+ dataset_id: identity.id,
677
+ dataset_version: identity.version,
678
+ source_file: repoRelativeMaybe(sourceFile),
679
+ path: pathExpression(pathSegments),
680
+ relation: "process_data_source_short_description",
681
+ original: before,
682
+ canonical: after,
683
+ reason: "Process data source reference shortDescription is synchronized to the curated true source row name.",
684
+ });
685
+ }
686
+ }
687
+ for (const [key, child] of Object.entries(valueRecord)) {
688
+ rewriteTrueSourceReferenceDescriptions(child, {
689
+ sourceLookup,
690
+ sourceFile,
691
+ stats,
692
+ rewriteRows,
693
+ pathSegments: [...pathSegments, key],
694
+ datasetIdentityCache,
695
+ });
696
+ }
697
+ }
698
+ function rewriteProcessDataSourceReferences(value, { sourceLookup, replacementSource = null, forceReplacementSource = false, replacementRelation = null, replacementReason = null, sourceFile, stats, rewriteRows, pathSegments = [], datasetIdentityCache = null, language = "en", }) {
699
+ if (!value || typeof value !== "object")
700
+ return;
701
+ if (Array.isArray(value)) {
702
+ value.forEach((item, index) => rewriteProcessDataSourceReferences(item, {
703
+ sourceLookup,
704
+ replacementSource,
705
+ forceReplacementSource,
706
+ replacementRelation,
707
+ replacementReason,
708
+ sourceFile,
709
+ stats,
710
+ rewriteRows,
711
+ pathSegments: [...pathSegments, index],
712
+ datasetIdentityCache,
713
+ language,
714
+ }));
715
+ return;
716
+ }
717
+ const valueRecord = value;
718
+ const relation = sourceReferenceKind(pathSegments);
719
+ const refType = asText(valueRecord["@type"]).toLowerCase();
720
+ const refObjectId = asText(valueRecord["@refObjectId"]);
721
+ if (relation === "process_data_source" && refObjectId && refType.includes("source")) {
722
+ const referencedSource = sourceLookup.get(refObjectId);
723
+ const currentShortName = textValue(valueRecord["common:shortDescription"]);
724
+ let targetSource = null;
725
+ let rewriteRelation = null;
726
+ let reason = null;
727
+ if (forceReplacementSource && replacementSource?.dataset_id) {
728
+ targetSource = replacementSource;
729
+ rewriteRelation = replacementRelation || "process_data_source_context_source";
730
+ reason =
731
+ replacementReason ||
732
+ "Process context identifies a more specific original report/publication source than the converted process data source reference.";
733
+ }
734
+ else if (referencedSource?.kind === "true_source") {
735
+ const canonicalShortName = asText(referencedSource.short_name);
736
+ if (canonicalShortName && currentShortName !== canonicalShortName) {
737
+ targetSource = referencedSource;
738
+ rewriteRelation = "process_data_source_short_description";
739
+ reason =
740
+ "Process data source reference shortDescription is synchronized to the curated true source row name.";
741
+ }
742
+ }
743
+ else if (replacementSource?.dataset_id) {
744
+ targetSource = replacementSource;
745
+ rewriteRelation = replacementSource.fallback_database_source
746
+ ? "process_data_source_fallback_database"
747
+ : "process_data_source_true_source";
748
+ reason = replacementSource.fallback_database_source
749
+ ? "Converted process data source pointed to a non-source support placeholder and no unambiguous process-specific report/publication source was available; the reference is rewritten to the imported package's database-level fallback source."
750
+ : "Converted process data source pointed to a non-source support placeholder; the bundle contains one unambiguous true source, so the reference is rewritten to that curated source row.";
751
+ }
752
+ const canonical = sourceReferenceFromSummary(targetSource, language);
753
+ if (canonical && targetSource) {
754
+ const before = sourceReferenceSnapshot(valueRecord);
755
+ const after = sourceReferenceSnapshot(canonical);
756
+ if (before.ref_object_id !== after.ref_object_id ||
757
+ before.version !== after.version ||
758
+ before.short_description !== after.short_description) {
759
+ Object.keys(valueRecord).forEach((key) => {
760
+ delete valueRecord[key];
761
+ });
762
+ Object.assign(valueRecord, cloneJson(canonical));
763
+ const identity = datasetIdentityCache && datasetIdentityCache.id
764
+ ? datasetIdentityCache
765
+ : { id: null, version: null };
766
+ if (rewriteRelation === "process_data_source_short_description") {
767
+ stats.true_source_reference_description_repairs += 1;
768
+ }
769
+ else {
770
+ stats.process_source_reference_rewrites =
771
+ Number(stats.process_source_reference_rewrites ?? 0) + 1;
772
+ if (rewriteRelation === "process_data_source_context_source") {
773
+ stats.process_source_context_rewrites =
774
+ Number(stats.process_source_context_rewrites ?? 0) + 1;
775
+ }
776
+ if (targetSource.fallback_database_source) {
777
+ stats.process_source_reference_fallback_rewrites =
778
+ Number(stats.process_source_reference_fallback_rewrites ?? 0) + 1;
779
+ }
780
+ }
781
+ rewriteRows.push({
782
+ dataset_type: "process",
783
+ dataset_id: identity.id,
784
+ dataset_version: identity.version,
785
+ source_file: repoRelativeMaybe(sourceFile),
786
+ path: pathExpression(pathSegments),
787
+ relation: rewriteRelation,
788
+ original: before,
789
+ canonical: after,
790
+ referenced_source_kind: referencedSource?.kind ?? null,
791
+ replacement_source_kind: targetSource.kind ?? null,
792
+ reason,
793
+ });
794
+ }
795
+ }
796
+ }
797
+ for (const [key, child] of Object.entries(valueRecord)) {
798
+ rewriteProcessDataSourceReferences(child, {
799
+ sourceLookup,
800
+ replacementSource,
801
+ forceReplacementSource,
802
+ replacementRelation,
803
+ replacementReason,
804
+ sourceFile,
805
+ stats,
806
+ rewriteRows,
807
+ pathSegments: [...pathSegments, key],
808
+ datasetIdentityCache,
809
+ language,
810
+ });
811
+ }
812
+ }
813
+ function collectSourceReferences(value, pathSegments = [], refs = []) {
814
+ if (!value || typeof value !== "object")
815
+ return refs;
816
+ if (Array.isArray(value)) {
817
+ value.forEach((item, index) => collectSourceReferences(item, [...pathSegments, index], refs));
818
+ return refs;
819
+ }
820
+ const valueRecord = value;
821
+ const refType = asText(valueRecord["@type"]).toLowerCase();
822
+ const refObjectId = asText(valueRecord["@refObjectId"]);
823
+ if (refObjectId && refType.includes("source")) {
824
+ refs.push({
825
+ path: pathExpression(pathSegments),
826
+ relation: sourceReferenceKind(pathSegments),
827
+ ref_object_id: refObjectId,
828
+ version: asText(valueRecord["@version"]) || null,
829
+ short_description: textValue(valueRecord["common:shortDescription"]) || null,
830
+ });
831
+ }
832
+ for (const [key, child] of Object.entries(valueRecord)) {
833
+ collectSourceReferences(child, [...pathSegments, key], refs);
834
+ }
835
+ return refs;
836
+ }
837
+ function processSourceReferenceRows(payload, sourceLookup, sourceFile) {
838
+ const payloadRecord = payload;
839
+ if (!payloadRecord?.processDataSet)
840
+ return [];
841
+ const identity = datasetIdentity(payload, "process");
842
+ return collectSourceReferences(payloadRecord.processDataSet).map((ref) => ({
843
+ dataset_type: "process",
844
+ dataset_id: identity.id,
845
+ dataset_version: identity.version,
846
+ source_file: repoRelativeMaybe(sourceFile),
847
+ ...ref,
848
+ referenced_source_kind: sourceLookup.get(ref.ref_object_id)?.kind ?? null,
849
+ referenced_source_classification: sourceLookup.get(ref.ref_object_id)?.classification_path ?? null,
850
+ referenced_source_citation: sourceLookup.get(ref.ref_object_id)?.source_citation ?? null,
851
+ }));
852
+ }
853
+ function sourceReferenceSemanticBlockers(processSourceReferenceRows) {
854
+ return processSourceReferenceRows
855
+ .filter((row) => row.relation === "process_data_source" &&
856
+ row.referenced_source_kind &&
857
+ row.referenced_source_kind !== "true_source")
858
+ .map((row) => ({
859
+ code: "process_data_source_not_true_source",
860
+ message: "Process referenceToDataSource must point to a true report/publication/source row, not a format or compliance support source.",
861
+ dataset_id: row.dataset_id,
862
+ dataset_version: row.dataset_version,
863
+ ref_object_id: row.ref_object_id,
864
+ referenced_source_kind: row.referenced_source_kind,
865
+ referenced_source_classification: row.referenced_source_classification,
866
+ source_file: row.source_file,
867
+ path: row.path,
868
+ }));
869
+ }
870
+ return {
871
+ buildBafuFallbackSourcePayload,
872
+ buildDatabaseFallbackSourcePayload,
873
+ buildBafuProcessContextSourcePayload,
874
+ canonicalSourceReferenceForRelation,
875
+ processSourceReferenceRows,
876
+ processOriginalSourceMetadata,
877
+ repairTrueSourceClassification,
878
+ repairTrueSourceDescription,
879
+ repairTrueSourceIdentity,
880
+ rewriteCanonicalSourceReferences,
881
+ rewriteProcessDataSourceReferences,
882
+ rewriteTrueSourceReferenceDescriptions,
883
+ sourceReferenceSemanticBlockers,
884
+ sourceReferenceSnapshot,
885
+ sourceSummaryMatchesOriginalMetadata,
886
+ sourceSemanticSummary,
887
+ };
888
+ }