@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,526 @@
1
+ import { createBundleSourceContextUtils } from "./bundle-source-context.js";
2
+ import { createHash } from "node:crypto";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ function isJsonRecord(value) {
6
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
7
+ }
8
+ function asJsonRecord(value) {
9
+ return isJsonRecord(value) ? value : {};
10
+ }
11
+ function nestedValue(value, ...keys) {
12
+ let current = value;
13
+ for (const key of keys) {
14
+ if (!isJsonRecord(current))
15
+ return undefined;
16
+ current = current[key];
17
+ }
18
+ return current;
19
+ }
20
+ export function createBundleSampleUtils({ asText, bundleClassificationPath, canonicalSourceReferenceForRelation, cloneJson, contactGlobalReference, datasetIdentity, deterministicUuid, directoryExists, ensureArray: _ensureArray, fileExists, flowClassificationSchemaType, flowTypeOfDataSet, isConvertedDefaultClassification, isObjectEmpty, jsonSha256, languageForText: _languageForText, multiLang, normalizeUtcDateTimeString, normalizedList, nowIso, pathExpression, readJson, repoRelativeMaybe, repoRelativePath: _repoRelativePath, resolveRepoPath, sanitizePlaceholderText, sourceReferenceSnapshot, textValue: _textValue, }) {
21
+ const { flowNameParts, collectSourceTracePayloads, sourceTraceAttribute, sourceTraceLocationCode, sourceTraceChildText, processSourceClassificationSummary, processAuthoringContextFromTrace, } = createBundleSourceContextUtils({ asText });
22
+ function collectBundleQualityFindings({ payload, type, sourceFile, sourceTraces, blockers, stats, classificationQueueRows, classificationCommandsByType, }) {
23
+ if (type !== "process" && type !== "flow")
24
+ return;
25
+ if (type === "flow" && flowClassificationSchemaType(payload) !== "flow-product")
26
+ return;
27
+ const identity = datasetIdentity(payload, type);
28
+ const currentClassification = bundleClassificationPath(payload, type);
29
+ if (!isConvertedDefaultClassification(currentClassification))
30
+ return;
31
+ if (type === "process") {
32
+ stats.default_process_classification_blockers += 1;
33
+ }
34
+ else {
35
+ stats.default_flow_classification_blockers += 1;
36
+ }
37
+ const schemaType = type === "flow" ? flowClassificationSchemaType(payload) : "process";
38
+ const code = `${type}_classification_requires_authoring`;
39
+ const sourceClassification = processSourceClassificationSummary(sourceTraces);
40
+ const authoringContext = processAuthoringContextFromTrace(sourceTraces);
41
+ const queueRow = {
42
+ dataset_type: type,
43
+ dataset_id: identity.id,
44
+ dataset_version: identity.version,
45
+ source_file: repoRelativeMaybe(sourceFile),
46
+ code,
47
+ current_classification: currentClassification,
48
+ source_classification: sourceClassification,
49
+ authoring_context: authoringContext,
50
+ classification_workflow: {
51
+ schema_type: schemaType,
52
+ row_type: type,
53
+ commands: classificationCommandsByType[schemaType],
54
+ decision_contract: {
55
+ required_selector: "row_index or dataset_id",
56
+ required_classification: "code, leaf_code, class_id, cat_id, or classes[]",
57
+ optional_fields: ["basis", "evidence"],
58
+ },
59
+ },
60
+ required_resolution: "Use the Foundry AI authoring/classification gate with full TIDAS schema/YAML/context to replace the converted default classification before remote write.",
61
+ };
62
+ classificationQueueRows.push(queueRow);
63
+ blockers.push({
64
+ code,
65
+ message: `${type} classification is the converter default path and must be resolved by AI/classification authoring before commit.`,
66
+ dataset_type: type,
67
+ dataset_id: identity.id,
68
+ dataset_version: identity.version,
69
+ source_file: repoRelativeMaybe(sourceFile),
70
+ current_classification: currentClassification,
71
+ source_classification: sourceClassification,
72
+ schema_type: schemaType,
73
+ queue: "classification-authoring-queue.jsonl",
74
+ });
75
+ }
76
+ function collectElementaryFlowReuseFindings({ payload, type, sourceFile, sourceTraces, blockers, stats, elementaryFlowReuseRows, allowAccountLocalSupportAndElementary = false, }) {
77
+ if (type !== "flow")
78
+ return;
79
+ // Override: BAFU profile may mint account-local (My Data, state_code=0) elementary
80
+ // flows; do not require reuse-from-existing or block the bundle.
81
+ if (allowAccountLocalSupportAndElementary)
82
+ return;
83
+ if (flowClassificationSchemaType(payload) !== "flow-elementary")
84
+ return;
85
+ const identity = datasetIdentity(payload, type);
86
+ const sourceClassification = processSourceClassificationSummary(sourceTraces);
87
+ const authoringContext = processAuthoringContextFromTrace(sourceTraces);
88
+ stats.elementary_flow_reuse_blockers += 1;
89
+ elementaryFlowReuseRows.push({
90
+ dataset_type: "flow",
91
+ dataset_id: identity.id,
92
+ dataset_version: identity.version,
93
+ source_file: repoRelativeMaybe(sourceFile),
94
+ code: "elementary_flow_requires_existing_database_match",
95
+ flow_type: flowTypeOfDataSet(payload),
96
+ source_name_fields: flowNameParts(payload),
97
+ source_classification: sourceClassification,
98
+ authoring_context: authoringContext,
99
+ required_resolution: "Search the existing TianGong elementary flow library by UUID/version, CAS/name/category/synonyms, and structured semantic candidates. Rewrite process exchanges to the selected existing flow. If no defensible match exists, keep this as an unresolved mapping blocker; do not write a BAFU-owned elementary flow.",
100
+ });
101
+ blockers.push({
102
+ code: "elementary_flow_requires_existing_database_match",
103
+ message: "Elementary flow must be selected from existing TianGong database flows before commit; Foundry must not publish BAFU-owned elementary flows.",
104
+ dataset_type: type,
105
+ dataset_id: identity.id,
106
+ dataset_version: identity.version,
107
+ source_file: repoRelativeMaybe(sourceFile),
108
+ flow_type: flowTypeOfDataSet(payload),
109
+ source_name_fields: flowNameParts(payload),
110
+ source_classification: sourceClassification,
111
+ queue: "elementary-flow-reuse-queue.jsonl",
112
+ });
113
+ }
114
+ function normalizeTimestampText(text, pathSegments, stats) {
115
+ if (pathSegments.at(-1) !== "common:timeStamp")
116
+ return text;
117
+ const value = String(text ?? "").trim();
118
+ if (!value)
119
+ return text;
120
+ let normalized = value;
121
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?[+-]\d{2}:\d{2}$/u.test(value)) {
122
+ normalized = normalizeUtcDateTimeString(value) ?? value;
123
+ }
124
+ if (normalized !== value) {
125
+ stats.timestamp_normalizations += 1;
126
+ }
127
+ return normalized;
128
+ }
129
+ function textItem(value) {
130
+ if (value && typeof value === "object" && !Array.isArray(value)) {
131
+ const record = value;
132
+ return typeof record["#text"] === "string" ? record : null;
133
+ }
134
+ if (Array.isArray(value)) {
135
+ return (value.find((item) => item && typeof item === "object" && typeof item["#text"] === "string") ?? null);
136
+ }
137
+ return null;
138
+ }
139
+ function productionVolumeToAnnualText(value) {
140
+ const text = asText(value);
141
+ if (!text)
142
+ return null;
143
+ let match = text.match(/^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?)\s+(.+?)\s+per\s+year\b/iu);
144
+ if (!match) {
145
+ match = text.match(/([+-]?(?:\d[\d'.,]*(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?)\s+([^\s,.;()]+)\s*\/\s*(?:year|yr|a)\b/iu);
146
+ }
147
+ if (!match)
148
+ return null;
149
+ const amount = match[1].replace(/[',]/gu, "");
150
+ const unit = match[2].replace(/[.。]\s*$/u, "").trim();
151
+ return `${amount} ${unit}/year`;
152
+ }
153
+ function sourceTraceYear(sourceTraces) {
154
+ for (const candidate of [
155
+ sourceTraceChildText(sourceTraces, "endYear"),
156
+ sourceTraceChildText(sourceTraces, "startYear"),
157
+ sourceTraceAttribute(sourceTraces, "version"),
158
+ sourceTraceAttribute(sourceTraces, "timestamp"),
159
+ ]) {
160
+ const match = asText(candidate).match(/\b(19|20)\d{2}\b/u);
161
+ if (match)
162
+ return Number(match[0]);
163
+ }
164
+ return null;
165
+ }
166
+ function repairProcessFieldsFromSourceTrace(payload, sourceTraces, stats) {
167
+ if (!isJsonRecord(payload))
168
+ return;
169
+ const root = asJsonRecord(payload.processDataSet);
170
+ if (!isJsonRecord(payload.processDataSet))
171
+ return;
172
+ const processInformation = asJsonRecord(root.processInformation);
173
+ const time = isJsonRecord(processInformation.time) ? processInformation.time : null;
174
+ if (time && time["common:referenceYear"] === 9999) {
175
+ const year = sourceTraceYear(sourceTraces);
176
+ if (year !== null && Number.isInteger(year) && year > 0 && year < 9999) {
177
+ time["common:referenceYear"] = year;
178
+ stats.reference_year_repairs += 1;
179
+ }
180
+ }
181
+ const modelling = asJsonRecord(root.modellingAndValidation);
182
+ const dataSources = isJsonRecord(modelling.dataSourcesTreatmentAndRepresentativeness)
183
+ ? modelling.dataSourcesTreatmentAndRepresentativeness
184
+ : null;
185
+ if (!dataSources)
186
+ return;
187
+ const annualText = textItem(dataSources.annualSupplyOrProductionVolume);
188
+ if (!annualText)
189
+ return;
190
+ const current = asText(annualText["#text"]);
191
+ if (!current ||
192
+ current.toLowerCase().includes("not declared in source package") ||
193
+ !/(?:\/\s*(?:year|yr|a)\b|\bper\s+(?:year|annum)\b|\/\s*年|每年|年度|年供应|年产)/iu.test(current)) {
194
+ const repaired = productionVolumeToAnnualText(sourceTraceAttribute(sourceTraces, "productionVolume"));
195
+ if (repaired) {
196
+ annualText["#text"] = repaired;
197
+ stats.annual_supply_repairs += 1;
198
+ }
199
+ }
200
+ }
201
+ function sanitizeImportContent(value, stats, traceRows, context, pathSegments = []) {
202
+ if (!value || typeof value !== "object")
203
+ return false;
204
+ if (Array.isArray(value)) {
205
+ for (let index = value.length - 1; index >= 0; index -= 1) {
206
+ const child = value[index];
207
+ if (typeof child === "string") {
208
+ value[index] = normalizeTimestampText(sanitizePlaceholderText(child, [...pathSegments, index], stats), [...pathSegments, index], stats);
209
+ }
210
+ else if (sanitizeImportContent(child, stats, traceRows, context, [...pathSegments, index])) {
211
+ value.splice(index, 1);
212
+ }
213
+ }
214
+ return false;
215
+ }
216
+ const record = value;
217
+ if (record["tidasimport:sourceTrace"]) {
218
+ traceRows.push({
219
+ dataset_type: context.type,
220
+ dataset_id: context.identity.id,
221
+ dataset_version: context.identity.version,
222
+ source_file: repoRelativeMaybe(context.sourceFile),
223
+ path: pathExpression([...pathSegments, "tidasimport:sourceTrace"]),
224
+ trace: cloneJson(record["tidasimport:sourceTrace"]),
225
+ });
226
+ delete record["tidasimport:sourceTrace"];
227
+ stats.removed_import_traces += 1;
228
+ }
229
+ if (record["@xmlns:tidasimport"]) {
230
+ delete record["@xmlns:tidasimport"];
231
+ stats.removed_import_trace_namespaces += 1;
232
+ }
233
+ for (const [key, child] of Object.entries(record)) {
234
+ const childPath = [...pathSegments, key];
235
+ if (typeof child === "string") {
236
+ record[key] = normalizeTimestampText(sanitizePlaceholderText(child, childPath, stats), childPath, stats);
237
+ continue;
238
+ }
239
+ if (typeof child === "number" && key === "common:referenceYear" && child === 9999) {
240
+ continue;
241
+ }
242
+ if (sanitizeImportContent(child, stats, traceRows, context, childPath)) {
243
+ delete record[key];
244
+ }
245
+ }
246
+ return pathSegments.at(-1) === "common:other" && isObjectEmpty(record);
247
+ }
248
+ function sanitizeBundlePayload(payload, type, sourceFile, stats, traceRows, sourceTraces = null) {
249
+ sourceTraces ??= collectSourceTracePayloads(payload);
250
+ if (type === "process") {
251
+ repairProcessFieldsFromSourceTrace(payload, sourceTraces, stats);
252
+ }
253
+ const identity = datasetIdentity(payload, type);
254
+ sanitizeImportContent(payload, stats, traceRows, {
255
+ type,
256
+ identity,
257
+ sourceFile,
258
+ });
259
+ return payload;
260
+ }
261
+ function findFirstBundleContactTemplate(bundleDirs) {
262
+ for (const bundleDir of bundleDirs) {
263
+ const contactsDir = path.join(bundleDir, "tidas", "contacts");
264
+ if (!directoryExists(contactsDir))
265
+ continue;
266
+ for (const name of fs.readdirSync(contactsDir).sort()) {
267
+ if (name.endsWith(".json")) {
268
+ return readJson(path.join(contactsDir, name));
269
+ }
270
+ }
271
+ }
272
+ return null;
273
+ }
274
+ function buildLibraryContactPayload(options, templateContact = null, rewriteContext = {}) {
275
+ const language = asText(options.language || options.lang || "en") || "en";
276
+ const profile = asText(options.profile || "bafu");
277
+ // The FOEN/BAFU contact strings are fallbacks ONLY for the BAFU profile. Other import
278
+ // profiles (e.g. worldsteel) MUST supply their own organisation's real identity — the
279
+ // caller passes libraryName/shortName/website/email/telephone/contactAddress/... from
280
+ // the package metadata + research, so no BAFU contact detail (email, phone, address,
281
+ // organisation category) can leak into a different organisation's minted contact.
282
+ const bafuDefault = (value) => (profile === "bafu" ? value : "");
283
+ const libraryName = asText(options.libraryName ||
284
+ options.name ||
285
+ bafuDefault("Swiss Federal Administration - Federal Office for the Environment (FOEN)"));
286
+ // `library*`-prefixed alternates let cross-process callers (the finalize CLI
287
+ // subprocess) pass library contact fields via collision-free flags
288
+ // (`--library-short-name`, `--library-website`, …) instead of generic option
289
+ // names. In-process callers (materialize) keep using the plain fields.
290
+ const shortName = asText(options.libraryShortName ||
291
+ options.shortName ||
292
+ bafuDefault("Federal Office for the Environment FOEN (BAFU)"));
293
+ const website = asText(options.libraryWebsite ||
294
+ options.website ||
295
+ options.url ||
296
+ bafuDefault("https://www.bafu.admin.ch/en/contact-en"));
297
+ const email = asText(options.libraryEmail || options.email || bafuDefault("info@bafu.admin.ch"));
298
+ const telephone = asText(options.libraryTelephone ||
299
+ options.telephone ||
300
+ options.phone ||
301
+ bafuDefault("+41 58 462 93 11"));
302
+ const contactAddress = asText(options.libraryContactAddress ||
303
+ options.contactAddress ||
304
+ options.address ||
305
+ bafuDefault("Federal Office for the Environment FOEN, 3003 Bern, Switzerland"));
306
+ const centralContactPoint = asText(options.libraryCentralContactPoint ||
307
+ options.centralContactPoint ||
308
+ bafuDefault("Federal Office for the Environment FOEN, 3003 Bern, Switzerland; info@bafu.admin.ch; +41 58 462 93 11"));
309
+ const description = asText(options.libraryDescription ||
310
+ options.description ||
311
+ bafuDefault("Library-level contact for the BAFU 2025 Version 2 LCA data package."));
312
+ // `library*`-prefixed alternates (libraryContactId/libraryContactVersion) let the
313
+ // cross-process finalize CLI pass an explicit visible contact identity to reuse
314
+ // instead of deriving a deterministic owner-draft contact. Worldsteel omits these
315
+ // alternates because its packaged contact id is foreign/private.
316
+ const version = asText(options.libraryContactVersion || options.contactVersion || options.version || "00.00.001");
317
+ const id = asText(options.libraryContactId || options.contactId || options.id) ||
318
+ (profile === "bafu"
319
+ ? "a6db11f5-1cb4-579a-b503-bd17c361b8c2"
320
+ : deterministicUuid(`tiangong-lca-foundry:library-contact:${profile}:${libraryName}:${website}`));
321
+ const stableTimestamp = asText(options.timestamp || options.timeStamp || options.generatedAt) ||
322
+ (profile === "bafu" ? "2025-01-01T00:00:00.000Z" : nowIso());
323
+ const templateRoot = asJsonRecord(templateContact?.contactDataSet);
324
+ const templateDataEntryBy = asJsonRecord(nestedValue(templateRoot, "administrativeInformation", "dataEntryBy"));
325
+ const originalReferenceToDataSetFormat = asJsonRecord(cloneJson(templateDataEntryBy["common:referenceToDataSetFormat"] ?? {
326
+ "@type": "source data set",
327
+ "@refObjectId": "16938856-0a35-5654-8aff-56c17e61da4d",
328
+ "@version": "00.00.001",
329
+ "@uri": "../sources/16938856-0a35-5654-8aff-56c17e61da4d.json",
330
+ "common:shortDescription": multiLang("ILCD format", language),
331
+ }));
332
+ const referenceToDataSetFormat = canonicalSourceReferenceForRelation("dataset_format_source") ??
333
+ originalReferenceToDataSetFormat;
334
+ const originalFormatSnapshot = sourceReferenceSnapshot(originalReferenceToDataSetFormat);
335
+ const canonicalFormatSnapshot = sourceReferenceSnapshot(referenceToDataSetFormat);
336
+ if (rewriteContext?.rewriteRows &&
337
+ (originalFormatSnapshot.ref_object_id !== canonicalFormatSnapshot.ref_object_id ||
338
+ originalFormatSnapshot.version !== canonicalFormatSnapshot.version ||
339
+ originalFormatSnapshot.short_description !== canonicalFormatSnapshot.short_description)) {
340
+ rewriteContext.rewriteRows.push({
341
+ dataset_type: "contact",
342
+ dataset_id: id,
343
+ dataset_version: version,
344
+ source_file: "foundry:library-contact",
345
+ path: "contactDataSet.administrativeInformation.dataEntryBy.common:referenceToDataSetFormat",
346
+ relation: "dataset_format_source",
347
+ original: originalFormatSnapshot,
348
+ canonical: canonicalFormatSnapshot,
349
+ reason: "Library contact data set format uses the public canonical ILCD format source instead of a converted package-local support source.",
350
+ });
351
+ if (rewriteContext.stats) {
352
+ rewriteContext.stats.source_reference_rewrites =
353
+ Number(rewriteContext.stats.source_reference_rewrites ?? 0) + 1;
354
+ }
355
+ }
356
+ const selfRef = contactGlobalReference({
357
+ id,
358
+ version,
359
+ shortDescription: libraryName,
360
+ language,
361
+ });
362
+ // Organisation category (组织类别) must reflect THIS organisation, not BAFU's. The
363
+ // caller passes options.contactClassification (a [{@level,@classId,#text}, ...] array)
364
+ // derived from the package's own contact metadata / research. Fall back to the FOEN
365
+ // category only for the BAFU profile; for any other profile default to the generic
366
+ // "Organisations > Other organisations" (2 / 2.4) rather than BAFU's "Governmental
367
+ // organisations" (2.2). classIds follow tidas_contacts_category.json.
368
+ const contactClass = Array.isArray(options.contactClassification) && options.contactClassification.length > 0
369
+ ? options.contactClassification
370
+ : profile === "bafu"
371
+ ? [
372
+ { "@level": "0", "@classId": "2", "#text": "Organisations" },
373
+ { "@level": "1", "@classId": "2.2", "#text": "Governmental organisations" },
374
+ ]
375
+ : [
376
+ { "@level": "0", "@classId": "2", "#text": "Organisations" },
377
+ { "@level": "1", "@classId": "2.4", "#text": "Other organisations" },
378
+ ];
379
+ const dataSetInformation = {
380
+ "common:UUID": id,
381
+ "common:shortName": multiLang(shortName, language),
382
+ "common:name": multiLang(libraryName, language),
383
+ classificationInformation: {
384
+ "common:classification": {
385
+ "common:class": contactClass,
386
+ },
387
+ },
388
+ WWWAddress: website,
389
+ email,
390
+ telephone,
391
+ contactAddress: multiLang(contactAddress, language),
392
+ centralContactPoint: multiLang(centralContactPoint, language),
393
+ contactDescriptionOrComment: multiLang(description, language),
394
+ "common:other": {
395
+ "@xmlns:foundry": "https://tiangong.earth/tidas/foundry/1.0",
396
+ "foundry:libraryContactPolicy": {
397
+ "@marker": "FOUNDRY_LIBRARY_CONTACT_POLICY_V1",
398
+ profile,
399
+ libraryName,
400
+ sourceLanguage: language,
401
+ policy: "One shared library contact is used for every dataset row imported from this source library.",
402
+ evidence: {
403
+ source: "Foundry BAFU import profile/library-level source attribution",
404
+ website,
405
+ email,
406
+ telephone,
407
+ contactAddress,
408
+ },
409
+ },
410
+ },
411
+ };
412
+ return {
413
+ contactDataSet: {
414
+ "@version": templateRoot?.["@version"] ?? "1.1",
415
+ "@xmlns": templateRoot?.["@xmlns"] ?? "http://lca.jrc.it/ILCD/Contact",
416
+ "@xmlns:common": templateRoot?.["@xmlns:common"] ?? "http://lca.jrc.it/ILCD/Common",
417
+ "@xmlns:xsi": templateRoot?.["@xmlns:xsi"] ?? "http://www.w3.org/2001/XMLSchema-instance",
418
+ "@xsi:schemaLocation": templateRoot?.["@xsi:schemaLocation"] ??
419
+ "http://lca.jrc.it/ILCD/Contact ../../schemas/ILCD_ContactDataSet.xsd",
420
+ contactInformation: {
421
+ dataSetInformation,
422
+ },
423
+ administrativeInformation: {
424
+ dataEntryBy: {
425
+ "common:timeStamp": stableTimestamp,
426
+ "common:referenceToDataSetFormat": referenceToDataSetFormat,
427
+ },
428
+ publicationAndOwnership: {
429
+ "common:dataSetVersion": version,
430
+ "common:permanentDataSetURI": `https://lcdn.tiangong.earth/datasetdetail/contact.xhtml?uuid=${id}&version=${version}`,
431
+ "common:referenceToOwnershipOfDataSet": selfRef,
432
+ },
433
+ },
434
+ },
435
+ };
436
+ }
437
+ function listProcessBundleDirs(bundlesDir) {
438
+ const root = resolveRepoPath(bundlesDir);
439
+ if (!root || !directoryExists(root)) {
440
+ throw new Error("--bundles-dir is required and must point to a process-bundles directory.");
441
+ }
442
+ return fs
443
+ .readdirSync(root, { withFileTypes: true })
444
+ .filter((entry) => entry.isDirectory())
445
+ .map((entry) => path.join(root, entry.name))
446
+ .filter((dir) => fileExists(path.join(dir, "manifest.json")) && directoryExists(path.join(dir, "tidas")))
447
+ .sort();
448
+ }
449
+ function selectProcessBundleDirs(allBundleDirs, options) {
450
+ const requestedProcessIds = normalizedList(options.processId || options.processIds);
451
+ if (requestedProcessIds.length > 0) {
452
+ const byName = new Map(allBundleDirs.map((dir) => [path.basename(dir), dir]));
453
+ const selected = requestedProcessIds
454
+ .map((id) => byName.get(id))
455
+ .filter((directory) => Boolean(directory));
456
+ return {
457
+ seed: null,
458
+ selected,
459
+ missing_process_ids: requestedProcessIds.filter((id) => !byName.has(id)),
460
+ };
461
+ }
462
+ const seed = asText(options.seed) || `sample-${Date.now()}`;
463
+ const sampleSizeText = asText(options.sampleSize || options.limit || options.count || 3);
464
+ const sampleSize = sampleSizeText.toLowerCase() === "all"
465
+ ? allBundleDirs.length
466
+ : Math.max(1, Number(sampleSizeText));
467
+ if (!Number.isFinite(sampleSize)) {
468
+ throw new Error("--sample-size must be a positive number or all.");
469
+ }
470
+ const selected = [...allBundleDirs]
471
+ .sort((left, right) => createHash("sha256")
472
+ .update(`${seed}:${path.basename(left)}`)
473
+ .digest("hex")
474
+ .localeCompare(createHash("sha256")
475
+ .update(`${seed}:${path.basename(right)}`)
476
+ .digest("hex")))
477
+ .slice(0, Math.min(sampleSize, allBundleDirs.length));
478
+ return { seed, selected, missing_process_ids: [] };
479
+ }
480
+ function addDedupedBundleRow({ rowsByType, sourceByType, blockers, type, payload, sourceFile, }) {
481
+ const identity = datasetIdentity(payload, type);
482
+ const key = `${identity.id || path.basename(sourceFile)}::${identity.version || ""}`;
483
+ if (!identity.id || !identity.version) {
484
+ blockers.push({
485
+ code: "bundle_row_identity_missing",
486
+ message: `${type} row is missing common:UUID or common:dataSetVersion.`,
487
+ source_file: repoRelativeMaybe(sourceFile),
488
+ id: identity.id,
489
+ version: identity.version,
490
+ });
491
+ return false;
492
+ }
493
+ if (!rowsByType[type].has(key)) {
494
+ rowsByType[type].set(key, payload);
495
+ sourceByType[type].set(key, sourceFile);
496
+ return true;
497
+ }
498
+ const existing = rowsByType[type].get(key);
499
+ if (jsonSha256(existing) !== jsonSha256(payload)) {
500
+ blockers.push({
501
+ code: "bundle_row_duplicate_payload_conflict",
502
+ message: `${type} ${identity.id}@${identity.version} appears with different payloads in sampled bundles.`,
503
+ kept_source_file: repoRelativeMaybe(sourceByType[type].get(key) ?? null),
504
+ conflicting_source_file: repoRelativeMaybe(sourceFile),
505
+ });
506
+ }
507
+ return false;
508
+ }
509
+ return {
510
+ addDedupedBundleRow,
511
+ buildLibraryContactPayload,
512
+ collectBundleQualityFindings,
513
+ collectElementaryFlowReuseFindings,
514
+ collectSourceTracePayloads,
515
+ findFirstBundleContactTemplate,
516
+ flowNameParts,
517
+ listProcessBundleDirs,
518
+ processAuthoringContextFromTrace,
519
+ processSourceClassificationSummary,
520
+ sanitizeBundlePayload,
521
+ selectProcessBundleDirs,
522
+ sourceTraceAttribute,
523
+ sourceTraceChildText,
524
+ sourceTraceLocationCode,
525
+ };
526
+ }
@@ -0,0 +1,31 @@
1
+ type JsonRecord = Record<string, unknown>;
2
+ export declare function createBundleSourceContextUtils({ asText }: {
3
+ asText: (value: unknown) => string;
4
+ }): {
5
+ flowNameParts: (payload: JsonRecord | null) => {
6
+ base_name: string;
7
+ treatment_standards_routes: string;
8
+ mix_and_location_types: string;
9
+ functional_unit_flow_properties: string;
10
+ };
11
+ collectSourceTracePayloads: (value: unknown, traces?: JsonRecord[]) => JsonRecord[];
12
+ sourceTraceAttribute: (sourceTraces: JsonRecord[], attributeName: string) => string | null;
13
+ sourceTraceLocationCode: (sourceTraces: JsonRecord[]) => string | null;
14
+ sourceTraceChildText: (sourceTraces: JsonRecord[], childName: string) => string | null;
15
+ processSourceClassificationSummary: (sourceTraces: JsonRecord[]) => {
16
+ category: string | null;
17
+ subCategory: string | null;
18
+ localCategory: string | null;
19
+ localSubCategory: string | null;
20
+ };
21
+ processAuthoringContextFromTrace: (sourceTraces: JsonRecord[]) => {
22
+ source_name: string | null;
23
+ source_local_name: string | null;
24
+ source_location: string | null;
25
+ source_unit: string | null;
26
+ general_comment: string | null;
27
+ included_processes: string | null;
28
+ technology: string | null;
29
+ };
30
+ };
31
+ export {};