@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,812 @@
1
+ import { fullContextAiCompletionRequirement } from "./context-inputs.js";
2
+ import { taskAuthorizationWaivesQa } from "../../task-authorization.js";
3
+ import { datasetIdentity, identityKey } from "./dataset-payload.js";
4
+ import { datasetTypePlural, referenceOnlySupportDatasetTypes, supportDatasetTypes, } from "./dataset-types.js";
5
+ import { authoringPackageProofsFromCurationGate, authoringPackageProofsFromPatchCollect, curationGateContextHasKind, curationGateContextHasPattern, evidenceResolutionContextKinds, evidenceResolutionMode, fullContextPackageProofBlockers, } from "./full-context-proof.js";
6
+ import { externalizeImportTraceMetadata } from "./prewrite-cleanup.js";
7
+ import { asText, ensureArray, fileExists, repoRelativePath, resolveRepoPath, } from "./runtime-io.js";
8
+ import { foundryTraceSummary } from "./trace-summary.js";
9
+ import { buildClassificationDecisionFullContextBlockers, buildIdentityDecisionFullContextBlockers, buildLocationDecisionFullContextBlockers, decisionApplyContextRelevantToRowsFile, } from "./workflow-decision-full-context.js";
10
+ import { normalizeDryRunOperation } from "./workflow-dry-run-context.js";
11
+ import { prewriteIdentityBlockers } from "./workflow-identity-preflight.js";
12
+ import { readJsonLines } from "./workflow-patch-collect.js";
13
+ import { hasImportOnlyTrace, patchEvidenceForRow, tracePatchEvidenceBlockers, } from "./workflow-patch-evidence-context.js";
14
+ import { deterministicRowsFileTransformEntries, rowsFileReachableThroughTransformChain, } from "./workflow-row-transform-context.js";
15
+ import { allowedPatchResolutionModes, jsonPointerToken } from "./workflow-semantic-actions.js";
16
+ function asRecord(value) {
17
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
18
+ }
19
+ // part-11.mjs
20
+ export function sourceContactRewriteSemanticEvidenceCount({ repoRoot, datasetType, rowsFile, sourceContactRewriteContext, canonicalSupportRewriteContext, cleanupContext, }) {
21
+ if (!["support", "source", "contact"].includes(asText(datasetType).toLowerCase()))
22
+ return 0;
23
+ if (sourceContactRewriteContext?.status !== "completed")
24
+ return 0;
25
+ if (!sourceContactRewriteContext?.inputRowsFile || !sourceContactRewriteContext?.outputRowsFile) {
26
+ return 0;
27
+ }
28
+ const reachesFinalRows = rowsFileReachableThroughTransformChain({
29
+ repoRoot,
30
+ startFiles: [sourceContactRewriteContext.outputRowsFile],
31
+ expectedRowsFile: rowsFile,
32
+ transforms: deterministicRowsFileTransformEntries({
33
+ sourceContactRewriteContext,
34
+ canonicalSupportRewriteContext,
35
+ cleanupContext,
36
+ }),
37
+ });
38
+ if (!reachesFinalRows)
39
+ return 0;
40
+ const counts = sourceContactRewriteContext.counts ?? {};
41
+ return Math.max(Number(counts.output_rows ?? 0) || 0, Number(counts.contact_reference_rewrites ?? 0) || 0, Number(counts.source_reference_rewrites ?? 0) || 0, 1);
42
+ }
43
+ export function buildFullContextAiCompletionBlockers({ repoRoot, profile, datasetType, curationGateArtifact, rowsFile, patchApplyArtifact, patchApplyContext, patchCollectArtifact, cleanupArtifact, classificationDecisionApplyArtifact, classificationDecisionApplyContext, locationDecisionApplyArtifact, locationDecisionApplyContext, identityDecisionApplyArtifact, identityDecisionApplyContext, identityReferenceRewriteContext, unresolvedExchangeExternalizationContext, sourceContactRewriteContext, canonicalSupportRewriteContext, cleanupContext, }) {
44
+ const requirement = fullContextAiCompletionRequirement(profile, datasetType, repoRoot);
45
+ if (!requirement)
46
+ return [];
47
+ const blockers = [];
48
+ const curationPackageProofs = curationGateArtifact
49
+ ? authoringPackageProofsFromCurationGate(repoRoot, curationGateArtifact)
50
+ : [];
51
+ const patchTaskPackageProofs = patchCollectArtifact
52
+ ? authoringPackageProofsFromPatchCollect(repoRoot, patchCollectArtifact)
53
+ : [];
54
+ if (!curationGateArtifact) {
55
+ blockers.push({
56
+ code: "full_context_curation_gate_required",
57
+ stage: "full_context_ai_completion",
58
+ message: "This profile requires a post-authoring curation gate built with full schema/YAML/context before remote write planning.",
59
+ });
60
+ }
61
+ else {
62
+ for (const kind of requirement.requiredContextKinds) {
63
+ if (!curationGateContextHasKind(curationGateArtifact, kind)) {
64
+ blockers.push({
65
+ code: "full_context_curation_gate_context_kind_missing",
66
+ stage: "full_context_ai_completion",
67
+ message: `Curation gate report does not prove full-context authoring kind '${kind}'.`,
68
+ required_kind: kind,
69
+ artifact: repoRelativePath(repoRoot, curationGateArtifact.path),
70
+ });
71
+ }
72
+ }
73
+ for (const pattern of requirement.requiredContextFilePatterns) {
74
+ if (!curationGateContextHasPattern(curationGateArtifact, pattern)) {
75
+ blockers.push({
76
+ code: "full_context_curation_gate_context_file_missing",
77
+ stage: "full_context_ai_completion",
78
+ message: `Curation gate report does not reference required context file '${pattern}'.`,
79
+ required_file_pattern: pattern,
80
+ artifact: repoRelativePath(repoRoot, curationGateArtifact.path),
81
+ });
82
+ }
83
+ }
84
+ }
85
+ for (const proof of [...curationPackageProofs, ...patchTaskPackageProofs]) {
86
+ blockers.push(...fullContextPackageProofBlockers({ requirement, proof }));
87
+ }
88
+ const hasClassificationDecisionProof = classificationDecisionApplyArtifact &&
89
+ classificationDecisionApplyContext?.status === "completed" &&
90
+ classificationDecisionApplyContext.decisions.length > 0 &&
91
+ decisionApplyContextRelevantToRowsFile({
92
+ repoRoot,
93
+ rowsFile,
94
+ cleanupArtifact,
95
+ context: classificationDecisionApplyContext,
96
+ });
97
+ const hasLocationDecisionProof = locationDecisionApplyArtifact &&
98
+ locationDecisionApplyContext?.status === "completed" &&
99
+ locationDecisionApplyContext.decisions.length > 0 &&
100
+ decisionApplyContextRelevantToRowsFile({
101
+ repoRoot,
102
+ rowsFile,
103
+ cleanupArtifact,
104
+ context: locationDecisionApplyContext,
105
+ });
106
+ const hasIdentityDecisionProof = identityDecisionApplyArtifact &&
107
+ identityDecisionApplyContext?.status === "completed" &&
108
+ identityDecisionApplyContext.decisions.length > 0 &&
109
+ decisionApplyContextRelevantToRowsFile({
110
+ repoRoot,
111
+ rowsFile,
112
+ cleanupArtifact,
113
+ context: identityDecisionApplyContext,
114
+ });
115
+ const hasDecisionProof = hasClassificationDecisionProof || hasLocationDecisionProof || hasIdentityDecisionProof;
116
+ const hasSourceContactRewriteProof = sourceContactRewriteSemanticEvidenceCount({
117
+ repoRoot,
118
+ datasetType,
119
+ rowsFile,
120
+ sourceContactRewriteContext,
121
+ canonicalSupportRewriteContext,
122
+ cleanupContext,
123
+ }) > 0;
124
+ blockers.push(...buildClassificationDecisionFullContextBlockers({
125
+ repoRoot,
126
+ rowsFile,
127
+ cleanupArtifact,
128
+ requirement,
129
+ classificationDecisionApplyArtifact,
130
+ classificationDecisionApplyContext: classificationDecisionApplyContext,
131
+ locationDecisionApplyContext: locationDecisionApplyContext,
132
+ patchApplyContext,
133
+ identityDecisionApplyContext: identityDecisionApplyContext,
134
+ identityReferenceRewriteContext: identityReferenceRewriteContext,
135
+ unresolvedExchangeExternalizationContext,
136
+ sourceContactRewriteContext,
137
+ canonicalSupportRewriteContext,
138
+ cleanupContext,
139
+ }));
140
+ blockers.push(...buildLocationDecisionFullContextBlockers({
141
+ repoRoot,
142
+ rowsFile,
143
+ cleanupArtifact,
144
+ requirement,
145
+ locationDecisionApplyArtifact,
146
+ locationDecisionApplyContext: locationDecisionApplyContext,
147
+ patchApplyContext,
148
+ identityDecisionApplyContext: identityDecisionApplyContext,
149
+ identityReferenceRewriteContext: identityReferenceRewriteContext,
150
+ unresolvedExchangeExternalizationContext,
151
+ sourceContactRewriteContext,
152
+ canonicalSupportRewriteContext,
153
+ cleanupContext,
154
+ }));
155
+ blockers.push(...buildIdentityDecisionFullContextBlockers({
156
+ repoRoot,
157
+ rowsFile,
158
+ cleanupArtifact,
159
+ requirement,
160
+ identityDecisionApplyArtifact,
161
+ identityDecisionApplyContext: identityDecisionApplyContext,
162
+ classificationDecisionApplyContext: classificationDecisionApplyContext,
163
+ identityReferenceRewriteContext: identityReferenceRewriteContext,
164
+ unresolvedExchangeExternalizationContext,
165
+ sourceContactRewriteContext,
166
+ canonicalSupportRewriteContext,
167
+ cleanupContext,
168
+ }));
169
+ if (!patchCollectArtifact && !hasDecisionProof && !hasSourceContactRewriteProof) {
170
+ blockers.push({
171
+ code: "full_context_ai_completion_output_required",
172
+ stage: "full_context_ai_completion",
173
+ message: "This profile requires AI authoring output evidence from dataset-identity-decisions-apply, dataset-classification-decisions-apply, dataset-location-decisions-apply, or dataset-authoring-patch-collect before remote write planning.",
174
+ proof: requirement.proof,
175
+ });
176
+ }
177
+ else if (patchCollectArtifact &&
178
+ patchCollectArtifact.value?.status !== "ready_for_patch_apply") {
179
+ blockers.push({
180
+ code: "full_context_ai_patch_collect_not_ready",
181
+ stage: "full_context_ai_completion",
182
+ message: `dataset-authoring-patch-collect status is ${patchCollectArtifact.value?.status ?? "missing"}.`,
183
+ artifact: repoRelativePath(repoRoot, patchCollectArtifact.path),
184
+ });
185
+ }
186
+ if (!patchApplyArtifact && !hasDecisionProof && !hasSourceContactRewriteProof) {
187
+ blockers.push({
188
+ code: "full_context_ai_deterministic_apply_required",
189
+ stage: "full_context_ai_completion",
190
+ message: "This profile requires full-context AI semantic outputs to be deterministically applied through identity/classification/location decision apply or patch apply before remote write planning.",
191
+ proof: requirement.proof,
192
+ });
193
+ }
194
+ else if (patchApplyArtifact && patchApplyArtifact.value?.status !== "completed") {
195
+ blockers.push({
196
+ code: "full_context_ai_patch_apply_not_completed",
197
+ stage: "full_context_ai_completion",
198
+ message: `dataset-patch-apply status is ${patchApplyArtifact.value?.status ?? "missing"}.`,
199
+ artifact: repoRelativePath(repoRoot, patchApplyArtifact.path),
200
+ });
201
+ }
202
+ const evidenceRows = ensureArray(patchApplyContext?.evidenceRows);
203
+ if (patchApplyArtifact && evidenceRows.length === 0) {
204
+ blockers.push({
205
+ code: "full_context_ai_patch_evidence_required",
206
+ stage: "full_context_ai_completion",
207
+ message: "AI patch apply completed without patch evidence rows; semantic completion must be traceable to authoring packages.",
208
+ artifact: repoRelativePath(repoRoot, patchApplyArtifact.path),
209
+ });
210
+ }
211
+ const missingPackageHash = evidenceRows.filter((entry) => !asText(entry?.authoring_package_sha256));
212
+ if (missingPackageHash.length > 0) {
213
+ blockers.push({
214
+ code: "full_context_ai_patch_package_hash_missing",
215
+ stage: "full_context_ai_completion",
216
+ message: "Every AI patch evidence row must include authoring_package_sha256 to prove it used the full authoring package context.",
217
+ count: missingPackageHash.length,
218
+ artifact: patchApplyArtifact ? repoRelativePath(repoRoot, patchApplyArtifact.path) : null,
219
+ });
220
+ }
221
+ const knownPackageHashes = new Set([...curationPackageProofs, ...patchTaskPackageProofs]
222
+ .map((proof) => asText(proof?.sha256))
223
+ .filter(Boolean));
224
+ const unknownPackageHash = evidenceRows.filter((entry) => {
225
+ const hash = asText(entry?.authoring_package_sha256);
226
+ return hash && !knownPackageHashes.has(hash);
227
+ });
228
+ if (unknownPackageHash.length > 0) {
229
+ blockers.push({
230
+ code: "full_context_ai_patch_package_hash_unknown",
231
+ stage: "full_context_ai_completion",
232
+ message: "AI patch evidence authoring_package_sha256 must match a readable full-context authoring package from the patch task manifest or curation gate.",
233
+ count: unknownPackageHash.length,
234
+ artifact: patchApplyArtifact ? repoRelativePath(repoRoot, patchApplyArtifact.path) : null,
235
+ });
236
+ }
237
+ const missingClosures = evidenceRows.filter((entry) => ensureArray(entry?.closes_action_items).length === 0);
238
+ if (missingClosures.length > 0) {
239
+ blockers.push({
240
+ code: "full_context_ai_patch_action_closure_missing",
241
+ stage: "full_context_ai_completion",
242
+ message: "Every AI patch evidence row must close at least one authoring action item for this profile.",
243
+ count: missingClosures.length,
244
+ artifact: patchApplyArtifact ? repoRelativePath(repoRoot, patchApplyArtifact.path) : null,
245
+ });
246
+ }
247
+ const missingResolution = evidenceRows.filter((entry) => !evidenceResolutionMode(entry));
248
+ if (missingResolution.length > 0) {
249
+ blockers.push({
250
+ code: "full_context_ai_patch_resolution_missing",
251
+ stage: "full_context_ai_completion",
252
+ message: "Every AI patch evidence row must include resolution.mode to explain how the action item was completed or deferred.",
253
+ count: missingResolution.length,
254
+ artifact: patchApplyArtifact ? repoRelativePath(repoRoot, patchApplyArtifact.path) : null,
255
+ });
256
+ }
257
+ const invalidResolutionMode = evidenceRows.filter((entry) => {
258
+ const mode = evidenceResolutionMode(entry);
259
+ return mode && !allowedPatchResolutionModes.has(mode);
260
+ });
261
+ if (invalidResolutionMode.length > 0) {
262
+ blockers.push({
263
+ code: "full_context_ai_patch_resolution_mode_invalid",
264
+ stage: "full_context_ai_completion",
265
+ message: "AI patch evidence contains unsupported resolution.mode values.",
266
+ count: invalidResolutionMode.length,
267
+ artifact: patchApplyArtifact ? repoRelativePath(repoRoot, patchApplyArtifact.path) : null,
268
+ });
269
+ }
270
+ const missingResolutionContext = [];
271
+ for (const entry of evidenceRows) {
272
+ const usedKinds = new Set(evidenceResolutionContextKinds(entry));
273
+ for (const requiredKind of requirement.requiredContextKinds) {
274
+ if (!usedKinds.has(requiredKind)) {
275
+ missingResolutionContext.push({ entry, requiredKind });
276
+ }
277
+ }
278
+ }
279
+ if (missingResolutionContext.length > 0) {
280
+ blockers.push({
281
+ code: "full_context_ai_patch_resolution_context_missing",
282
+ stage: "full_context_ai_completion",
283
+ message: "AI patch evidence resolution.used_context_kinds must include every required full-context kind for this profile.",
284
+ count: missingResolutionContext.length,
285
+ required_context_kinds: requirement.requiredContextKinds,
286
+ artifact: patchApplyArtifact ? repoRelativePath(repoRoot, patchApplyArtifact.path) : null,
287
+ });
288
+ }
289
+ return blockers;
290
+ }
291
+ export const referenceTableByTypeToken = [
292
+ ["contact", "contacts"],
293
+ ["compliance system", "sources"],
294
+ ["compliancesystem", "sources"],
295
+ ["flow property", "flowproperties"],
296
+ ["flowproperty", "flowproperties"],
297
+ ["flow data", "flows"],
298
+ ["lcia method", "lciamethods"],
299
+ ["lciamethod", "lciamethods"],
300
+ ["life cycle model", "lifecyclemodels"],
301
+ ["lifecycle model", "lifecyclemodels"],
302
+ ["lifecyclemodel", "lifecyclemodels"],
303
+ ["process", "processes"],
304
+ ["source", "sources"],
305
+ ["unit group", "unitgroups"],
306
+ ["unitgroup", "unitgroups"],
307
+ ];
308
+ export const referenceTableByPathToken = [
309
+ ["flowproperties", "flowproperties"],
310
+ ["flowproperty", "flowproperties"],
311
+ ["flowdataset", "flows"],
312
+ ["lciamethod", "lciamethods"],
313
+ ["lifecyclemodel", "lifecyclemodels"],
314
+ ["datasetformat", "sources"],
315
+ ["compliancesystem", "sources"],
316
+ ["datasource", "sources"],
317
+ ["source", "sources"],
318
+ ["processdataset", "processes"],
319
+ ["unitgroup", "unitgroups"],
320
+ ["commissioner", "contacts"],
321
+ ["personorentity", "contacts"],
322
+ ["ownership", "contacts"],
323
+ ["contact", "contacts"],
324
+ ];
325
+ export function referenceTableFromType(value) {
326
+ const text = asText(value).toLowerCase();
327
+ if (!text)
328
+ return null;
329
+ const match = referenceTableByTypeToken.find(([token]) => text.includes(token));
330
+ return match?.[1] ?? null;
331
+ }
332
+ export function referenceTableFromPath(pathSegments) {
333
+ const text = pathSegments.join(".").toLowerCase();
334
+ if (!text)
335
+ return null;
336
+ const compact = text.replace(/[^a-z0-9]/gu, "");
337
+ const match = referenceTableByPathToken.find(([token]) => compact.includes(token));
338
+ return match?.[1] ?? null;
339
+ }
340
+ export function referenceKey({ table, id, version }) {
341
+ return [asText(table), asText(id), asText(version)].join("\u0000");
342
+ }
343
+ export function plannedRootReferenceKeys(rows, datasetType) {
344
+ return new Set(rows.map((row, index) => {
345
+ const identity = datasetIdentity(row, index, datasetType);
346
+ return referenceKey({
347
+ table: datasetTypePlural[identity.dataset_type || datasetType],
348
+ id: identity.id,
349
+ version: identity.version,
350
+ });
351
+ }));
352
+ }
353
+ export function plannedRootReferenceIds(rows, datasetType) {
354
+ return new Set(rows.map((row, index) => datasetIdentity(row, index, datasetType).id).filter(Boolean));
355
+ }
356
+ export function collectDatasetReferences(value, pathSegments = [], refs = []) {
357
+ if (isFoundryTracePathSegments(pathSegments))
358
+ return refs;
359
+ if (Array.isArray(value)) {
360
+ value.forEach((item, index) => collectDatasetReferences(item, [...pathSegments, String(index)], refs));
361
+ return refs;
362
+ }
363
+ if (!value || typeof value !== "object")
364
+ return refs;
365
+ const record = asRecord(value);
366
+ const id = asText(record["@refObjectId"] ?? record.refObjectId ?? record.ref_object_id ?? record.ref_id);
367
+ if (id) {
368
+ const version = asText(record["@version"] ?? record.version ?? record.refVersion ?? record.ref_version);
369
+ const table = referenceTableFromType(record["@type"] ?? record.type) ??
370
+ referenceTableFromPath(pathSegments);
371
+ refs.push({
372
+ table,
373
+ id,
374
+ version,
375
+ path: pathSegments.length > 0 ? `/${pathSegments.map(jsonPointerToken).join("/")}` : "/",
376
+ type: asText(record["@type"] ?? record.type) || null,
377
+ short_description: asText(asRecord(record["common:shortDescription"])["#text"]) ||
378
+ asText(record.shortDescription) ||
379
+ null,
380
+ });
381
+ }
382
+ for (const [key, child] of Object.entries(record)) {
383
+ collectDatasetReferences(child, [...pathSegments, key], refs);
384
+ }
385
+ return refs;
386
+ }
387
+ export function isFoundryTracePathSegments(pathSegments) {
388
+ return (pathSegments.includes("common:other") &&
389
+ pathSegments.some((segment) => segment.startsWith("tiangongfoundry:") && segment.toLowerCase().includes("trace")));
390
+ }
391
+ export function remoteVerifyChecks(repoRoot, remoteVerifyArtifact) {
392
+ const value = remoteVerifyArtifact?.value;
393
+ const checks = ensureArray(value?.checks);
394
+ if (checks.length > 0)
395
+ return checks;
396
+ const checksFile = asRecord(value?.files).checks;
397
+ const checksPath = resolveRepoPath(repoRoot, checksFile);
398
+ return checksPath && fileExists(checksPath) ? readJsonLines(checksPath) : [];
399
+ }
400
+ export function remoteVerifiedReferenceKeys(repoRoot, remoteVerifyArtifact, { acceptExactExistingOutdated = false } = {}) {
401
+ // `version_outdated` is returned by the CLI remote-verify ONLY when the exact
402
+ // referenced version EXISTS remotely but a newer version is also published
403
+ // (otherwise the status would be `missing_version`). For a *reference* row the
404
+ // referenced dataset existing at that exact version is sufficient proof of the
405
+ // write dependency closure — the "use latest" preference is a publish-quality
406
+ // concern, not a reference-integrity one. Under the BAFU My Data override we
407
+ // accept such references (e.g. account-local FP/UG at state_code=0 referenced
408
+ // at their source version while a 01.00.000 row also exists).
409
+ const acceptableStatuses = acceptExactExistingOutdated
410
+ ? new Set(["ok", "version_outdated"])
411
+ : new Set(["ok"]);
412
+ return new Set(remoteVerifyChecks(repoRoot, remoteVerifyArtifact)
413
+ .filter((check) => asText(check?.role) === "reference" &&
414
+ acceptableStatuses.has(asText(check?.status)) &&
415
+ asText(check?.table) &&
416
+ asText(check?.id))
417
+ .map((check) => referenceKey({
418
+ table: check.table,
419
+ id: check.id,
420
+ version: check.version,
421
+ })));
422
+ }
423
+ export function identityReferenceRewriteProofKeys(context) {
424
+ return new Set(ensureArray(context?.scopedRows)
425
+ .map((row) => asRecord(row).canonical)
426
+ .filter(Boolean)
427
+ .map((canonical) => ({
428
+ table: asText(asRecord(canonical).table) || "flows",
429
+ id: asText(asRecord(canonical).ref_object_id ??
430
+ asRecord(canonical).refObjectId ??
431
+ asRecord(canonical).id),
432
+ version: asText(asRecord(canonical).version ??
433
+ asRecord(canonical)["@version"] ??
434
+ asRecord(canonical).ref_version) || "00.00.001",
435
+ }))
436
+ .filter((reference) => reference.id)
437
+ .map(referenceKey));
438
+ }
439
+ export function buildReferenceClosureBlockers({ repoRoot, rows, datasetType, remoteVerifyArtifact, provenReferenceKeys = new Set(), unresolvedReferenceKeys = new Set(), allowAccountLocalSupportAndElementary = false, }) {
440
+ const plannedRootKeys = plannedRootReferenceKeys(rows, datasetType);
441
+ const remoteOkKeys = remoteVerifiedReferenceKeys(repoRoot, remoteVerifyArtifact, {
442
+ acceptExactExistingOutdated: allowAccountLocalSupportAndElementary,
443
+ });
444
+ const blockers = [];
445
+ const seen = new Set();
446
+ rows.forEach((row, rowIndex) => {
447
+ for (const ref of collectDatasetReferences(row)) {
448
+ if (!ref.table) {
449
+ const key = `unsupported\u0000${rowIndex}\u0000${ref.id}\u0000${ref.path}`;
450
+ if (seen.has(key))
451
+ continue;
452
+ seen.add(key);
453
+ blockers.push({
454
+ code: "reference_closure_type_unresolved",
455
+ stage: "reference_closure",
456
+ message: "A TIDAS reference could not be mapped to a dataset table, so Foundry cannot prove the write dependency closure.",
457
+ row_index: rowIndex,
458
+ reference_id: ref.id,
459
+ reference_version: ref.version || null,
460
+ reference_type: ref.type,
461
+ path: ref.path,
462
+ });
463
+ continue;
464
+ }
465
+ const key = referenceKey(ref);
466
+ if (plannedRootKeys.has(key) ||
467
+ remoteOkKeys.has(key) ||
468
+ provenReferenceKeys.has(key) ||
469
+ unresolvedReferenceKeys.has(key)) {
470
+ continue;
471
+ }
472
+ const seenKey = `${rowIndex}\u0000${key}\u0000${ref.path}`;
473
+ if (seen.has(seenKey))
474
+ continue;
475
+ seen.add(seenKey);
476
+ blockers.push({
477
+ code: remoteVerifyArtifact
478
+ ? "reference_closure_unproven"
479
+ : "reference_closure_remote_verify_required",
480
+ stage: "reference_closure",
481
+ message: remoteVerifyArtifact
482
+ ? "Referenced dataset is neither covered by the exact write scope nor proven reusable by the supplied remote verification report."
483
+ : "Referenced dataset is outside the exact write scope; run remote verification after support rows exist, or include the dependency in an earlier write scope before commit handoff.",
484
+ row_index: rowIndex,
485
+ table: ref.table,
486
+ reference_id: ref.id,
487
+ reference_version: ref.version || null,
488
+ path: ref.path,
489
+ });
490
+ }
491
+ });
492
+ return blockers;
493
+ }
494
+ export function failureReasons(row) {
495
+ const record = asRecord(row);
496
+ return ensureArray(record.reason ?? record.reasons ?? asRecord(record.validation).issues ?? record.issues).map((value) => {
497
+ const item = asRecord(value);
498
+ return {
499
+ code: item.code ?? "failure",
500
+ stage: item.stage ?? null,
501
+ path: item.path ?? null,
502
+ message: item.message ?? asRecord(item.error).message ?? null,
503
+ validator: item.validator ?? null,
504
+ };
505
+ });
506
+ }
507
+ export function decisionCounts(items) {
508
+ const counts = {};
509
+ for (const item of items) {
510
+ counts[item.decision] = (counts[item.decision] ?? 0) + 1;
511
+ }
512
+ return counts;
513
+ }
514
+ export function operationCounts(items) {
515
+ const counts = {};
516
+ for (const item of items) {
517
+ if (!item.operation)
518
+ continue;
519
+ counts[item.operation] = (counts[item.operation] ?? 0) + 1;
520
+ }
521
+ return counts;
522
+ }
523
+ export function buildWriteCandidateItem({ repoRoot, datasetType, row, identity, rowIndex, schemaRow, curationEntity, curationWaivedQaCodes = [], curationGateProvided, dryRun, remoteVerifyBlockers, targetUserId, cleanupStatus, patchApplyContext, sourceReferenceRewritesByKey, identityReferenceRewritesByKey, identityDecisionApplyContext, cleanupContext = null, evidenceScopeBlockers = [], allowAccountLocalSupportAndElementary = false, profile = null, }) {
524
+ const key = identityKey(identity);
525
+ const blockers = [];
526
+ blockers.push(...evidenceScopeBlockers);
527
+ const invalidDryRunReport = evidenceScopeBlockers.some((blocker) => blocker?.code === "dry_run_report_is_commit_report");
528
+ const aiPatchEvidence = patchEvidenceForRow(patchApplyContext, identity, rowIndex);
529
+ const sourceReferenceRewrites = sourceReferenceRewritesByKey?.get(key) ?? [];
530
+ const identityReferenceRewrites = identityReferenceRewritesByKey?.get(key) ?? [];
531
+ for (const blocker of patchApplyContext?.globalBlockers ?? []) {
532
+ blockers.push(blocker);
533
+ }
534
+ const schemaStatus = schemaRow?.status ?? "not_found";
535
+ if (schemaStatus !== "valid") {
536
+ blockers.push({
537
+ code: "schema_not_valid",
538
+ stage: "schema",
539
+ message: `Schema status is ${schemaStatus}.`,
540
+ issues: ensureArray(schemaRow?.issues),
541
+ });
542
+ }
543
+ if (referenceOnlySupportDatasetTypes.has(datasetType) && !allowAccountLocalSupportAndElementary) {
544
+ blockers.push({
545
+ code: "reference_only_support_type_write_blocked",
546
+ stage: "support_reference_policy",
547
+ message: "Unit Groups and Flow Properties are reference-only support data for Foundry imports. Select existing database rows and rewrite references instead of writing account-local My Data rows.",
548
+ });
549
+ }
550
+ blockers.push(...prewriteIdentityBlockers(identity.payload, datasetType, repoRoot, {
551
+ allowAccountLocalSupportAndElementary,
552
+ profile: profile,
553
+ }));
554
+ const curationStatus = curationEntity?.status ?? null;
555
+ if ((curationStatus === "ready_with_profile_waivers" ||
556
+ Number(curationEntity?.waived_finding_count ?? 0) > 0) &&
557
+ (curationWaivedQaCodes.length === 0 ||
558
+ !curationWaivedQaCodes.every((code) => taskAuthorizationWaivesQa(asRecord(profile).authorization, datasetType, asText(code))))) {
559
+ blockers.push({
560
+ code: "task_authorization_qa_waiver_required",
561
+ stage: "foundry_curation",
562
+ message: "Retained curation waivers require current task approval for every exact QA code and input scope.",
563
+ });
564
+ }
565
+ if (curationGateProvided && !curationEntity) {
566
+ blockers.push({
567
+ code: "curation_gate_entity_missing",
568
+ stage: "foundry_curation",
569
+ message: "Curation gate report does not contain this write candidate.",
570
+ });
571
+ }
572
+ if (curationEntity &&
573
+ !["ready", "ready_with_profile_waivers"].includes(curationStatus)) {
574
+ blockers.push({
575
+ code: "curation_gate_not_ready",
576
+ stage: "foundry_curation",
577
+ message: `Curation entity status is ${curationStatus}.`,
578
+ authoring_package: curationEntity.authoring_package ?? null,
579
+ });
580
+ }
581
+ if (remoteVerifyBlockers.has(identity.id)) {
582
+ blockers.push({
583
+ code: "remote_reference_closure_blocked",
584
+ stage: "remote_verify",
585
+ message: "Remote verification reported a blocker involving this entity.",
586
+ });
587
+ }
588
+ if (hasImportOnlyTrace(row)) {
589
+ blockers.push({
590
+ code: "import_only_trace_not_cleaned",
591
+ stage: "prewrite_cleanup",
592
+ message: "Payload still contains tidasimport:sourceTrace or @xmlns:tidasimport.",
593
+ });
594
+ }
595
+ if (!targetUserId) {
596
+ blockers.push({
597
+ code: "target_user_id_required",
598
+ stage: "owner_guard",
599
+ message: "Remote write planning requires an explicit target user id.",
600
+ });
601
+ }
602
+ if (cleanupStatus !== "completed") {
603
+ blockers.push({
604
+ code: "curation_cleanup_required",
605
+ stage: "prewrite_cleanup",
606
+ message: "dataset-curation-cleanup must complete for the exact write rows before remote write planning.",
607
+ });
608
+ }
609
+ let dryRunStatus = "missing";
610
+ let operation = null;
611
+ let dryRunEvidence = null;
612
+ if (invalidDryRunReport) {
613
+ dryRunStatus = "invalid_report";
614
+ }
615
+ else if (datasetType === "flow") {
616
+ const success = dryRun.flow?.success.get(key);
617
+ const failure = dryRun.flow?.failures.get(key);
618
+ if (success) {
619
+ dryRunStatus = "success";
620
+ operation = normalizeDryRunOperation(success.operation);
621
+ dryRunEvidence = success;
622
+ }
623
+ else if (failure) {
624
+ dryRunStatus = "failure";
625
+ blockers.push({
626
+ code: "dry_run_failed",
627
+ stage: "dry_run",
628
+ message: "flow publish-version dry-run reported this row as failed.",
629
+ reasons: failureReasons(failure),
630
+ });
631
+ dryRunEvidence = { reasons: failureReasons(failure) };
632
+ }
633
+ }
634
+ else if (datasetType === "process") {
635
+ const prepared = dryRun.process?.prepared.get(key);
636
+ const failure = dryRun.process?.failures.get(key);
637
+ if (prepared) {
638
+ dryRunStatus = "success";
639
+ operation = "save_draft_prepared";
640
+ dryRunEvidence = prepared;
641
+ }
642
+ else if (failure) {
643
+ dryRunStatus = "failure";
644
+ blockers.push({
645
+ code: "dry_run_failed",
646
+ stage: "dry_run",
647
+ message: "process save-draft dry-run reported this row as failed.",
648
+ reasons: failureReasons(failure),
649
+ });
650
+ dryRunEvidence = { reasons: failureReasons(failure) };
651
+ }
652
+ }
653
+ else if (datasetType === "lifecyclemodel") {
654
+ const prepared = dryRun.lifecyclemodel?.prepared.get(key);
655
+ const failure = dryRun.lifecyclemodel?.failures.get(key);
656
+ if (prepared) {
657
+ dryRunStatus = "success";
658
+ operation = "save_draft_prepared";
659
+ dryRunEvidence = prepared;
660
+ }
661
+ else if (failure) {
662
+ dryRunStatus = "failure";
663
+ blockers.push({
664
+ code: "dry_run_failed",
665
+ stage: "dry_run",
666
+ message: "lifecyclemodel save-draft dry-run reported this row as failed.",
667
+ reasons: failureReasons(failure),
668
+ });
669
+ dryRunEvidence = { reasons: failureReasons(failure) };
670
+ }
671
+ }
672
+ else if (supportDatasetTypes.has(datasetType) ||
673
+ referenceOnlySupportDatasetTypes.has(datasetType)) {
674
+ // unitgroup/flowproperty are reference-only by default but, under the
675
+ // account-local override (P1a), they are committed through the same
676
+ // dataset save-draft (--type auto) dry-run as contacts/sources, so their
677
+ // prepared/failure evidence lives in the datasetSaveDraft maps too.
678
+ const prepared = dryRun.datasetSaveDraft?.prepared.get(key);
679
+ const failure = dryRun.datasetSaveDraft?.failures.get(key);
680
+ if (prepared) {
681
+ dryRunStatus = "success";
682
+ operation = normalizeDryRunOperation(prepared.operation);
683
+ dryRunEvidence = prepared;
684
+ }
685
+ else if (failure) {
686
+ dryRunStatus = "failure";
687
+ blockers.push({
688
+ code: "dry_run_failed",
689
+ stage: "dry_run",
690
+ message: "dataset save-draft dry-run reported this support row as failed.",
691
+ reasons: failureReasons(failure),
692
+ });
693
+ dryRunEvidence = { reasons: failureReasons(failure) };
694
+ }
695
+ }
696
+ if (dryRunStatus === "missing") {
697
+ blockers.push({
698
+ code: "dry_run_evidence_missing",
699
+ stage: "dry_run",
700
+ message: "No matching dry-run success or failure artifact was found for this row.",
701
+ });
702
+ }
703
+ const traceSummary = foundryTraceSummary({
704
+ datasetType,
705
+ identity,
706
+ row,
707
+ rowIndex,
708
+ });
709
+ blockers.push(...tracePatchEvidenceBlockers({
710
+ traceSummary,
711
+ aiPatchEvidence: aiPatchEvidence,
712
+ identityDecisionApplyContext,
713
+ cleanupContext,
714
+ identity,
715
+ rowIndex,
716
+ }));
717
+ const decision = blockers.length > 0 ? "blocked" : "write_or_update";
718
+ return {
719
+ dataset_type: datasetType,
720
+ entity_id: identity.id,
721
+ version: identity.version,
722
+ role: "write_candidate",
723
+ decision,
724
+ operation: operation,
725
+ target_user_id: targetUserId,
726
+ schema_status: schemaStatus,
727
+ curation_status: curationStatus,
728
+ ai_patch_apply_status: patchApplyContext?.status ?? "not_provided",
729
+ ai_patch_evidence_count: aiPatchEvidence.length,
730
+ ai_patch_evidence: aiPatchEvidence,
731
+ source_reference_rewrite_count: sourceReferenceRewrites.length,
732
+ source_reference_rewrites: sourceReferenceRewrites,
733
+ identity_reference_rewrite_count: identityReferenceRewrites.length,
734
+ identity_reference_rewrites: identityReferenceRewrites,
735
+ dry_run_status: dryRunStatus,
736
+ trace_summary_count: traceSummary.import_trace_summary_count,
737
+ unresolved_trace_count: traceSummary.unresolved_trace_count,
738
+ unresolved_exchange_trace_count: traceSummary.unresolved_exchange_trace_count,
739
+ source_exchange_completeness_count: traceSummary.source_exchange_completeness_count,
740
+ foundry_traces: {
741
+ unresolved_traces: traceSummary.unresolved_traces,
742
+ unresolved_exchange_traces: traceSummary.unresolved_exchange_traces,
743
+ source_exchange_completeness: traceSummary.source_exchange_completeness,
744
+ },
745
+ blockers,
746
+ dry_run_evidence: dryRunEvidence,
747
+ source_rows_file: repoRelativePath(repoRoot, resolveRepoPath(repoRoot, identity.sourceRowsFile) ?? ""),
748
+ };
749
+ }
750
+ export function buildReferenceReuseItems({ repoRoot: _repoRoot, datasetType, rows, writeCandidateKeys, identityReferenceRewritesByKey, }) {
751
+ return rows.map((row, index) => {
752
+ const identity = datasetIdentity(row, index, datasetType);
753
+ const key = identityKey(identity);
754
+ const identityReferenceRewrites = identityReferenceRewritesByKey?.get(key) ??
755
+ identityReferenceRewritesByKey?.get(identity.id) ??
756
+ [];
757
+ const traceSummary = foundryTraceSummary({
758
+ datasetType,
759
+ identity,
760
+ row,
761
+ rowIndex: index,
762
+ });
763
+ const alreadyWriteCandidate = writeCandidateKeys.has(key);
764
+ // Reference-reuse rows are never written, but the closure proof still
765
+ // requires their payload snapshot to be free of raw import-only trace.
766
+ // Write-candidate rows get this scrubbing via curation cleanup; reference
767
+ // rows skip it, so a benign converter import trace would otherwise block
768
+ // closure on a row we never write. Externalize it here (after the trace
769
+ // summary is captured for reporting) so the raw tidasimport:* trace becomes
770
+ // the sanctioned Foundry summary breadcrumb instead of a blocker. Matches
771
+ // externalizeImportTraceMetadata's use on the write-candidate path.
772
+ if (hasImportOnlyTrace(row)) {
773
+ externalizeImportTraceMetadata(row);
774
+ }
775
+ const blockers = hasImportOnlyTrace(row)
776
+ ? [
777
+ {
778
+ code: "reference_payload_contains_import_only_trace",
779
+ stage: "prewrite_cleanup",
780
+ message: "Reference-only rows are not written, but the payload snapshot still contains import-only trace metadata.",
781
+ },
782
+ ]
783
+ : [];
784
+ return {
785
+ dataset_type: datasetType,
786
+ entity_id: identity.id,
787
+ version: identity.version,
788
+ role: "reference_reuse",
789
+ decision: alreadyWriteCandidate ? "covered_by_write_candidate" : "reuse_existing_reference",
790
+ operation: null,
791
+ target_user_id: null,
792
+ schema_status: "not_required_for_reference_reuse",
793
+ curation_status: "not_required_for_reference_reuse",
794
+ dry_run_status: "not_required_for_reference_reuse",
795
+ identity_reference_rewrite_count: identityReferenceRewrites.length,
796
+ identity_reference_rewrites: identityReferenceRewrites,
797
+ canonical_references: identityReferenceRewrites
798
+ .map((rewrite) => asRecord(rewrite).canonical)
799
+ .filter(Boolean),
800
+ trace_summary_count: traceSummary.import_trace_summary_count,
801
+ unresolved_trace_count: traceSummary.unresolved_trace_count,
802
+ unresolved_exchange_trace_count: traceSummary.unresolved_exchange_trace_count,
803
+ source_exchange_completeness_count: traceSummary.source_exchange_completeness_count,
804
+ foundry_traces: {
805
+ unresolved_traces: traceSummary.unresolved_traces,
806
+ unresolved_exchange_traces: traceSummary.unresolved_exchange_traces,
807
+ source_exchange_completeness: traceSummary.source_exchange_completeness,
808
+ },
809
+ blockers,
810
+ };
811
+ });
812
+ }