@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,656 @@
1
+ import path from "node:path";
2
+ import { createFileArtifactFact } from "../foundry-command-spec.js";
3
+ import { normalizeAllowedTraceHashDifference } from "../remote-verification-accepted-diff.js";
4
+ import { canonicalPayloadSha256, validateUniqueRootReadbacks } from "../post-write-root-proof.js";
5
+ function isJsonRecord(value) {
6
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7
+ }
8
+ export function createPostWriteCloseoutCommands({ executionEnvironment = process.env, asText, countJsonLinesFile, countRowsFile, datasetIdentity, ensureArray, fileExists, fullContextProofCheck, nowIso, readJsonArtifactOption, readJsonLines, readRowsFile, repoRelativeMaybe, repoRelativePath, reportInputPath, resolveRepoPath, sameResolvedPath, validateTraceQueueCoverageForRows, writeCloseoutImportLedger, writeJson, }) {
9
+ function validateCommitReportForCloseout({ commitReport, commitReportPath, datasetType, finalRowsFile, expectedRows, blockers, }) {
10
+ const inputPath = resolveRepoPath(reportInputPath(commitReport));
11
+ const status = asText(commitReport.status);
12
+ const mode = asText(commitReport.mode);
13
+ const counts = commitReport.counts ?? {};
14
+ const failedCount = Number(counts.failed ?? counts.failure_count ?? 0);
15
+ const executedCount = Number(counts.executed ?? 0);
16
+ const successCount = Number(counts.success_count ?? 0);
17
+ const selectedCount = Number(counts.selected ?? counts.total_rows ?? 0);
18
+ if (!inputPath || !sameResolvedPath(inputPath, finalRowsFile)) {
19
+ blockers.push({
20
+ code: "commit_report_input_mismatch",
21
+ message: "Commit report input must match the handoff final rows file.",
22
+ commit_report: repoRelativePath(commitReportPath),
23
+ expected_input: repoRelativeMaybe(finalRowsFile),
24
+ actual_input: inputPath ? repoRelativeMaybe(inputPath) : null,
25
+ });
26
+ }
27
+ if (mode !== "commit") {
28
+ blockers.push({
29
+ code: "commit_report_not_commit_mode",
30
+ message: `Commit report mode is ${mode || "missing"}; expected commit.`,
31
+ commit_report: repoRelativePath(commitReportPath),
32
+ });
33
+ }
34
+ if (Object.hasOwn(commitReport, "commit") && commitReport.commit !== true) {
35
+ blockers.push({
36
+ code: "commit_report_commit_flag_false",
37
+ message: "Commit report has commit=false; dry-run reports cannot close an import.",
38
+ commit_report: repoRelativePath(commitReportPath),
39
+ });
40
+ }
41
+ if (!status || /with_failures|failure|failed|prepared/u.test(status)) {
42
+ blockers.push({
43
+ code: "commit_report_status_not_completed",
44
+ message: `Commit report status is ${status || "missing"}; expected a completed commit without failures.`,
45
+ commit_report: repoRelativePath(commitReportPath),
46
+ });
47
+ }
48
+ if (!Number.isFinite(failedCount) || failedCount !== 0) {
49
+ blockers.push({
50
+ code: "commit_report_failures_present",
51
+ message: `Commit report contains ${Number.isFinite(failedCount) ? failedCount : "unknown"} failed rows.`,
52
+ commit_report: repoRelativePath(commitReportPath),
53
+ });
54
+ }
55
+ const committedRows = datasetType === "flow" ? successCount : executedCount || successCount;
56
+ if (!Number.isFinite(committedRows) || committedRows < expectedRows || expectedRows <= 0) {
57
+ blockers.push({
58
+ code: "commit_report_row_count_incomplete",
59
+ message: `Commit report proves ${Number.isFinite(committedRows) ? committedRows : "unknown"} committed rows; expected ${expectedRows}.`,
60
+ commit_report: repoRelativePath(commitReportPath),
61
+ });
62
+ }
63
+ if (selectedCount && selectedCount < expectedRows) {
64
+ blockers.push({
65
+ code: "commit_report_selected_count_incomplete",
66
+ message: `Commit report selected ${selectedCount} rows; expected at least ${expectedRows}.`,
67
+ commit_report: repoRelativePath(commitReportPath),
68
+ });
69
+ }
70
+ }
71
+ function validatePostWriteVerifyForCloseout({ verifyReport, verifyReportPath, finalRowsFile, expectedRows, targetUserId, expectedStateCode, intendedRoots, allowTraceHashOnlyNormalization, blockers, }) {
72
+ const inputPath = resolveRepoPath(reportInputPath(verifyReport));
73
+ const counts = verifyReport.counts ?? {};
74
+ const blockerCount = Number(counts.blockers ?? (Array.isArray(verifyReport.blockers) ? verifyReport.blockers.length : 0));
75
+ const rootReadbackCount = Number(counts.root_readback_checks ?? 0);
76
+ const rootPayloadMismatches = Number(counts.root_payload_mismatches ?? -1);
77
+ if (!inputPath || !sameResolvedPath(inputPath, finalRowsFile)) {
78
+ blockers.push({
79
+ code: "post_write_verify_input_mismatch",
80
+ message: "Post-write verification input must match the handoff final rows file.",
81
+ post_write_verify_report: repoRelativePath(verifyReportPath),
82
+ expected_input: repoRelativeMaybe(finalRowsFile),
83
+ actual_input: inputPath ? repoRelativeMaybe(inputPath) : null,
84
+ });
85
+ }
86
+ if (verifyReport.status !== "passed_remote_verification") {
87
+ blockers.push({
88
+ code: "post_write_verify_not_passed",
89
+ message: `Post-write verification status is ${verifyReport.status ?? "missing"}.`,
90
+ post_write_verify_report: repoRelativePath(verifyReportPath),
91
+ });
92
+ }
93
+ if (!Number.isFinite(blockerCount) ||
94
+ blockerCount !== 0 ||
95
+ ensureArray(verifyReport.blockers).length > 0) {
96
+ blockers.push({
97
+ code: "post_write_verify_blockers_present",
98
+ message: `Post-write verification contains ${Number.isFinite(blockerCount) ? blockerCount : "unknown"} blockers.`,
99
+ post_write_verify_report: repoRelativePath(verifyReportPath),
100
+ });
101
+ }
102
+ if (!Number.isFinite(rootReadbackCount) ||
103
+ rootReadbackCount !== expectedRows ||
104
+ expectedRows <= 0) {
105
+ blockers.push({
106
+ code: "post_write_verify_root_readback_incomplete",
107
+ message: `Post-write verification has ${Number.isFinite(rootReadbackCount) ? rootReadbackCount : "unknown"} root readback checks; expected exactly ${expectedRows}.`,
108
+ post_write_verify_report: repoRelativePath(verifyReportPath),
109
+ });
110
+ }
111
+ if (!Number.isFinite(rootPayloadMismatches) || rootPayloadMismatches !== 0) {
112
+ blockers.push({
113
+ code: "post_write_verify_payload_mismatch",
114
+ message: `Post-write verification root payload mismatches: ${Number.isFinite(rootPayloadMismatches) ? rootPayloadMismatches : "missing"}.`,
115
+ post_write_verify_report: repoRelativePath(verifyReportPath),
116
+ });
117
+ }
118
+ const checksFile = resolveRepoPath(verifyReport.files?.checks);
119
+ if (!checksFile || !fileExists(checksFile)) {
120
+ blockers.push({
121
+ code: "post_write_verify_checks_missing",
122
+ message: "Post-write closeout requires the remote-verification.jsonl checks file to prove --compare-root-payload hashes.",
123
+ post_write_verify_report: repoRelativePath(verifyReportPath),
124
+ checks_file: verifyReport.files?.checks ?? null,
125
+ });
126
+ return { checksFile: null, readbackChecks: [], uniqueReadbackCount: 0 };
127
+ }
128
+ const checks = readJsonLines(checksFile);
129
+ const readbackChecks = checks.filter((check) => check?.role === "root" && String(check?.path ?? "").endsWith("#readback"));
130
+ if (readbackChecks.length !== expectedRows) {
131
+ blockers.push({
132
+ code: "post_write_verify_readback_check_rows_missing",
133
+ message: `Post-write check file contains ${readbackChecks.length} root readback checks; expected exactly ${expectedRows}.`,
134
+ checks_file: repoRelativePath(checksFile),
135
+ });
136
+ }
137
+ for (const check of readbackChecks) {
138
+ const localHash = asText(check.local_payload_sha256);
139
+ const remoteHash = asText(check.remote_payload_sha256);
140
+ if (check.status !== "ok") {
141
+ blockers.push({
142
+ code: "post_write_verify_readback_check_not_ok",
143
+ message: `Readback check for ${check.table}:${check.id}@${check.version} is ${check.status ?? "missing"}.`,
144
+ checks_file: repoRelativePath(checksFile),
145
+ row_index: check.row_index ?? null,
146
+ });
147
+ }
148
+ if (!localHash || !remoteHash || localHash !== remoteHash) {
149
+ blockers.push({
150
+ code: "post_write_verify_compare_root_payload_not_proven",
151
+ message: "Readback check is missing equal local/remote payload hashes, so --compare-root-payload was not proven.",
152
+ checks_file: repoRelativePath(checksFile),
153
+ row_index: check.row_index ?? null,
154
+ table: check.table ?? null,
155
+ id: check.id ?? null,
156
+ });
157
+ }
158
+ if (targetUserId && check.remote_user_id !== targetUserId) {
159
+ blockers.push({
160
+ code: "post_write_verify_owner_not_proven",
161
+ message: `Readback owner ${check.remote_user_id ?? "missing"} does not match ${targetUserId}.`,
162
+ checks_file: repoRelativePath(checksFile),
163
+ row_index: check.row_index ?? null,
164
+ });
165
+ }
166
+ if (expectedStateCode !== null && Number(check.remote_state_code) !== expectedStateCode) {
167
+ blockers.push({
168
+ code: "post_write_verify_state_code_not_proven",
169
+ message: `Readback state_code ${check.remote_state_code ?? "missing"} does not match ${expectedStateCode}.`,
170
+ checks_file: repoRelativePath(checksFile),
171
+ row_index: check.row_index ?? null,
172
+ });
173
+ }
174
+ }
175
+ const uniqueProof = validateUniqueRootReadbacks({
176
+ intended: intendedRoots,
177
+ checks: readbackChecks,
178
+ targetUserId,
179
+ expectedStateCode: expectedStateCode,
180
+ allowTraceHashOnlyNormalization,
181
+ });
182
+ blockers.push(...uniqueProof.blockers);
183
+ return {
184
+ checksFile,
185
+ readbackChecks,
186
+ uniqueReadbackCount: uniqueProof.uniqueReadbackCount,
187
+ };
188
+ }
189
+ function validateTraceQueuesForCloseout({ handoffPlan, finalizeReport, mutationManifest, datasetType, finalRowsFile, blockers, }) {
190
+ const counts = {
191
+ unresolved_trace_entries: Number(handoffPlan.counts?.unresolved_trace_entries ??
192
+ mutationManifest?.counts?.unresolved_trace_entries ??
193
+ finalizeReport?.counts?.unresolved_trace_entries ??
194
+ 0) || 0,
195
+ source_exchange_completeness_entries: Number(handoffPlan.counts?.source_exchange_completeness_entries ??
196
+ mutationManifest?.counts?.source_exchange_completeness_entries ??
197
+ finalizeReport?.counts?.source_exchange_completeness_entries ??
198
+ 0) || 0,
199
+ source_reference_rewrites: Number(handoffPlan.counts?.source_reference_rewrites ??
200
+ mutationManifest?.counts?.source_reference_rewrites ??
201
+ finalizeReport?.counts?.source_reference_rewrites ??
202
+ 0) || 0,
203
+ };
204
+ const traceQueues = {
205
+ unresolved_traces: handoffPlan.files?.trace_queues?.unresolved_traces ??
206
+ mutationManifest?.files?.unresolved_traces ??
207
+ finalizeReport?.files?.unresolved_traces ??
208
+ null,
209
+ source_exchange_completeness_traces: handoffPlan.files?.trace_queues?.source_exchange_completeness_traces ??
210
+ mutationManifest?.files?.source_exchange_completeness_traces ??
211
+ finalizeReport?.files?.source_exchange_completeness_traces ??
212
+ null,
213
+ source_reference_rewrites: handoffPlan.files?.trace_queues?.source_reference_rewrites ??
214
+ mutationManifest?.files?.source_reference_rewrites ??
215
+ finalizeReport?.files?.source_reference_rewrites ??
216
+ null,
217
+ };
218
+ for (const [key, queuePath] of Object.entries(traceQueues)) {
219
+ const expectedCount = key === "unresolved_traces"
220
+ ? counts.unresolved_trace_entries
221
+ : key === "source_exchange_completeness_traces"
222
+ ? counts.source_exchange_completeness_entries
223
+ : counts.source_reference_rewrites;
224
+ const resolved = resolveRepoPath(queuePath);
225
+ if (!resolved) {
226
+ if (expectedCount > 0) {
227
+ blockers.push({
228
+ code: "trace_queue_missing",
229
+ message: `${key} has ${expectedCount} entries but no queue file is recorded.`,
230
+ trace_queue: key,
231
+ });
232
+ }
233
+ continue;
234
+ }
235
+ if (!fileExists(resolved)) {
236
+ blockers.push({
237
+ code: "trace_queue_file_missing",
238
+ message: `${key} is recorded but the queue file is not readable.`,
239
+ trace_queue: key,
240
+ file: queuePath,
241
+ });
242
+ continue;
243
+ }
244
+ const actualCount = countJsonLinesFile(resolved);
245
+ if (actualCount < expectedCount) {
246
+ blockers.push({
247
+ code: "trace_queue_count_incomplete",
248
+ message: `${key} has ${actualCount} JSONL rows; expected at least ${expectedCount}.`,
249
+ trace_queue: key,
250
+ file: repoRelativePath(resolved),
251
+ });
252
+ }
253
+ }
254
+ if (finalRowsFile && fileExists(finalRowsFile)) {
255
+ validateTraceQueueCoverageForRows({
256
+ datasetType,
257
+ finalRowsFile,
258
+ traceQueues,
259
+ counts,
260
+ blockers,
261
+ });
262
+ }
263
+ return {
264
+ counts,
265
+ files: {
266
+ unresolved_traces: traceQueues.unresolved_traces,
267
+ source_exchange_completeness_traces: traceQueues.source_exchange_completeness_traces,
268
+ source_reference_rewrites: traceQueues.source_reference_rewrites,
269
+ },
270
+ };
271
+ }
272
+ function rootTypeAndTable(row, fallbackType) {
273
+ if (row?.contactDataSet)
274
+ return { type: "contact", table: "contacts" };
275
+ if (row?.sourceDataSet)
276
+ return { type: "source", table: "sources" };
277
+ if (row?.flowPropertyDataSet)
278
+ return { type: "flowproperty", table: "flowproperties" };
279
+ if (row?.unitGroupDataSet)
280
+ return { type: "unitgroup", table: "unitgroups" };
281
+ if (row?.flowDataSet)
282
+ return { type: "flow", table: "flows" };
283
+ if (row?.processDataSet)
284
+ return { type: "process", table: "processes" };
285
+ if (row?.lifeCycleModelDataSet || row?.lifecycleModelDataSet) {
286
+ return { type: "lifecyclemodel", table: "lifecyclemodels" };
287
+ }
288
+ const table = fallbackType === "process"
289
+ ? "processes"
290
+ : fallbackType === "flow"
291
+ ? "flows"
292
+ : fallbackType === "contact"
293
+ ? "contacts"
294
+ : fallbackType === "source"
295
+ ? "sources"
296
+ : fallbackType === "lifecyclemodel"
297
+ ? "lifecyclemodels"
298
+ : "";
299
+ return { type: fallbackType, table };
300
+ }
301
+ function validateHandoffFinalRowsArtifact({ handoffPlan, finalRowsFile, blockers, }) {
302
+ const artifact = handoffPlan.final_rows_artifact;
303
+ if (!artifact ||
304
+ !isJsonRecord(artifact) ||
305
+ typeof artifact.path !== "string" ||
306
+ !Number.isSafeInteger(artifact.bytes) ||
307
+ Number(artifact.bytes) < 0 ||
308
+ typeof artifact.sha256 !== "string" ||
309
+ !/^[a-f0-9]{64}$/u.test(artifact.sha256)) {
310
+ blockers.push({
311
+ code: "handoff_final_rows_artifact_missing_or_invalid",
312
+ message: "Post-write closeout requires handoff final_rows_artifact path/bytes/SHA-256.",
313
+ });
314
+ return null;
315
+ }
316
+ const artifactPath = resolveRepoPath(artifact.path);
317
+ if (!artifactPath || !sameResolvedPath(artifactPath, finalRowsFile)) {
318
+ blockers.push({
319
+ code: "handoff_final_rows_artifact_path_mismatch",
320
+ message: "Handoff final_rows_artifact path must resolve to the exact final rows file.",
321
+ expected_rows: repoRelativeMaybe(finalRowsFile),
322
+ artifact_path: artifact.path,
323
+ });
324
+ return null;
325
+ }
326
+ const current = createFileArtifactFact({
327
+ role: "final_rows",
328
+ path: artifact.path,
329
+ filePath: finalRowsFile,
330
+ });
331
+ if (current.bytes !== artifact.bytes) {
332
+ blockers.push({
333
+ code: "handoff_final_rows_artifact_bytes_drift",
334
+ message: "Final rows byte length changed after commit handoff.",
335
+ expected_bytes: artifact.bytes,
336
+ actual_bytes: current.bytes,
337
+ });
338
+ }
339
+ if (current.sha256 !== artifact.sha256) {
340
+ blockers.push({
341
+ code: "handoff_final_rows_artifact_sha256_drift",
342
+ message: "Final rows bytes changed after commit handoff.",
343
+ expected_sha256: artifact.sha256,
344
+ actual_sha256: current.sha256,
345
+ });
346
+ }
347
+ return current;
348
+ }
349
+ function runDatasetPostWriteCloseout(options) {
350
+ if (options.help) {
351
+ return {
352
+ schema_version: 1,
353
+ status: "help",
354
+ command: "dataset-post-write-closeout",
355
+ usage: [
356
+ "node scripts/foundry.ts dataset-post-write-closeout --handoff-plan <dataset-commit-handoff-plan.json> --commit-report <summary-or-sync-report.json> --post-write-verify-report <remote-verification-report.json> --out-dir <closeout-dir> --ledger-dir <task-import-ledger-dir>",
357
+ ],
358
+ purpose: "Close an explicit remote write only after Foundry handoff, CLI commit report, and post-write verify-root-payload evidence prove the exact same final rows were written and read back.",
359
+ remote_write_mode: "read-only",
360
+ };
361
+ }
362
+ const handoffArtifact = readJsonArtifactOption(options.handoffPlan || options.plan || options.input);
363
+ const commitArtifact = readJsonArtifactOption(options.commitReport || options.commit || options.writeReport);
364
+ const verifyArtifact = readJsonArtifactOption(options.postWriteVerifyReport || options.verifyReport || options.remoteVerifyReport);
365
+ if (!handoffArtifact) {
366
+ throw new Error("--handoff-plan is required and must point to dataset-commit-handoff-plan.json.");
367
+ }
368
+ if (!commitArtifact) {
369
+ throw new Error("--commit-report is required and must point to the CLI commit report JSON.");
370
+ }
371
+ if (!verifyArtifact) {
372
+ throw new Error("--post-write-verify-report is required and must point to remote-verification-report.json.");
373
+ }
374
+ const handoffPlan = handoffArtifact.value;
375
+ const datasetType = String(options.type || handoffPlan.dataset_type || "")
376
+ .trim()
377
+ .toLowerCase();
378
+ if (!["support", "contact", "source", "process", "flow", "lifecyclemodel"].includes(datasetType)) {
379
+ throw new Error(`Unsupported dataset type for post-write closeout: ${datasetType || "(missing)"}.`);
380
+ }
381
+ const outDir = resolveRepoPath(options.outDir || path.join(path.dirname(handoffArtifact.path), "post-write-closeout"));
382
+ const finalRowsFile = resolveRepoPath(options.rowsFile || handoffPlan.final_rows_file);
383
+ const finalizeArtifact = readJsonArtifactOption(options.finalizeReport || handoffPlan.finalize_report);
384
+ const mutationArtifact = readJsonArtifactOption(options.mutationManifest || handoffPlan.mutation_manifest);
385
+ const finalizeReport = finalizeArtifact?.value ?? null;
386
+ const mutationManifest = mutationArtifact?.value ?? null;
387
+ const targetUserId = asText(options.targetUserId || handoffPlan.target_user_id);
388
+ const expectedStateCodeText = asText(options.stateCode ?? handoffPlan.expected_state_code);
389
+ const expectedStateCode = expectedStateCodeText === "" || Number.isNaN(Number(expectedStateCodeText))
390
+ ? null
391
+ : Number(expectedStateCodeText);
392
+ const blockers = [];
393
+ const handoffAccountMode = asText(handoffPlan.account_mode).toLowerCase() || "ordinary";
394
+ const environmentAccountMode = asText(executionEnvironment.FOUNDRY_ACCOUNT_MODE).toLowerCase();
395
+ if (environmentAccountMode && environmentAccountMode !== handoffAccountMode) {
396
+ blockers.push({
397
+ code: "handoff_account_mode_mismatch",
398
+ message: "Post-write closeout account mode must match the receipt-bound handoff mode.",
399
+ });
400
+ }
401
+ const productionTestAccount = handoffAccountMode === "production-test" ||
402
+ environmentAccountMode === "production-test" ||
403
+ ["1", "true"].includes(String(options.productionCase || ""));
404
+ if (handoffPlan.status !== "ready_for_explicit_commit") {
405
+ blockers.push({
406
+ code: "handoff_plan_not_ready",
407
+ message: `Handoff plan status is ${handoffPlan.status ?? "missing"}.`,
408
+ handoff_plan: repoRelativePath(handoffArtifact.path),
409
+ });
410
+ }
411
+ if (!finalRowsFile || !fileExists(finalRowsFile)) {
412
+ blockers.push({
413
+ code: "final_rows_missing",
414
+ message: "Post-write closeout requires the exact final rows file from handoff.",
415
+ final_rows_file: handoffPlan.final_rows_file ?? null,
416
+ });
417
+ }
418
+ const finalRowsArtifact = finalRowsFile && fileExists(finalRowsFile)
419
+ ? validateHandoffFinalRowsArtifact({ handoffPlan, finalRowsFile, blockers })
420
+ : null;
421
+ if (!targetUserId) {
422
+ blockers.push({
423
+ code: "target_user_id_missing",
424
+ message: "Post-write closeout requires target_user_id from handoff or options.",
425
+ });
426
+ }
427
+ if (expectedStateCodeText === "" || expectedStateCode === null) {
428
+ blockers.push({
429
+ code: "state_code_missing",
430
+ message: "Post-write closeout requires expected_state_code from handoff or options.",
431
+ });
432
+ }
433
+ if (!finalizeArtifact) {
434
+ blockers.push({
435
+ code: "finalize_report_missing",
436
+ message: "Post-write closeout requires the finalize report referenced by the handoff so AI/context prewrite gates remain attached to the committed import.",
437
+ finalize_report: handoffPlan.finalize_report ?? null,
438
+ });
439
+ }
440
+ if (!mutationArtifact) {
441
+ blockers.push({
442
+ code: "mutation_manifest_missing",
443
+ message: "Post-write closeout requires the mutation manifest referenced by the handoff so exact-scope AI/context evidence remains attached to the committed import.",
444
+ mutation_manifest: handoffPlan.mutation_manifest ?? null,
445
+ });
446
+ }
447
+ if (finalizeReport && finalizeReport.status !== "ready_for_remote_write") {
448
+ blockers.push({
449
+ code: "finalize_report_not_ready",
450
+ message: `Finalize report status is ${finalizeReport.status ?? "missing"}.`,
451
+ finalize_report: repoRelativeMaybe(finalizeArtifact?.path),
452
+ });
453
+ }
454
+ if (mutationManifest && mutationManifest.status !== "ready_for_remote_write") {
455
+ blockers.push({
456
+ code: "mutation_manifest_not_ready",
457
+ message: `Mutation manifest status is ${mutationManifest.status ?? "missing"}.`,
458
+ mutation_manifest: repoRelativeMaybe(mutationArtifact?.path),
459
+ });
460
+ }
461
+ if (finalizeReport && finalRowsFile) {
462
+ const finalizeRowsFile = resolveRepoPath(finalizeReport.files?.final_rows ||
463
+ finalizeReport.final_rows_file ||
464
+ finalizeReport.rows_file);
465
+ if (!finalizeRowsFile || !sameResolvedPath(finalizeRowsFile, finalRowsFile)) {
466
+ blockers.push({
467
+ code: "finalize_report_rows_mismatch",
468
+ message: "Finalize report final rows must match the handoff final rows file.",
469
+ finalize_report: repoRelativeMaybe(finalizeArtifact?.path),
470
+ expected_rows: repoRelativeMaybe(finalRowsFile),
471
+ actual_rows: finalizeRowsFile ? repoRelativeMaybe(finalizeRowsFile) : null,
472
+ });
473
+ }
474
+ }
475
+ if (mutationManifest && finalRowsFile) {
476
+ const mutationRowsFile = resolveRepoPath(mutationManifest.rows_file ||
477
+ mutationManifest.files?.final_rows ||
478
+ mutationManifest.files?.rows_file);
479
+ if (!mutationRowsFile || !sameResolvedPath(mutationRowsFile, finalRowsFile)) {
480
+ blockers.push({
481
+ code: "mutation_manifest_rows_mismatch",
482
+ message: "Mutation manifest rows_file must match the handoff final rows file.",
483
+ mutation_manifest: repoRelativeMaybe(mutationArtifact?.path),
484
+ expected_rows: repoRelativeMaybe(finalRowsFile),
485
+ actual_rows: mutationRowsFile ? repoRelativeMaybe(mutationRowsFile) : null,
486
+ });
487
+ }
488
+ }
489
+ const closeoutProfile = asText(handoffPlan.profile ?? finalizeReport?.profile ?? mutationManifest?.profile);
490
+ const postWriteFullContextCheck = fullContextProofCheck({
491
+ profileId: closeoutProfile,
492
+ datasetType,
493
+ mutationArtifact,
494
+ codePrefix: "post_write_closeout",
495
+ });
496
+ blockers.push(...postWriteFullContextCheck.blockers);
497
+ const expectedRows = finalRowsFile && fileExists(finalRowsFile) ? countRowsFile(finalRowsFile) : 0;
498
+ const intendedRoots = [];
499
+ if (finalRowsFile && fileExists(finalRowsFile)) {
500
+ readRowsFile(finalRowsFile).forEach((row, rowIndex) => {
501
+ const rootType = rootTypeAndTable(row, datasetType);
502
+ const identity = datasetIdentity(row, rootType.type);
503
+ if (!rootType.table || !identity.id || !identity.version) {
504
+ blockers.push({
505
+ code: "intended_root_identity_missing",
506
+ message: `Final row ${rowIndex} does not expose one supported root identity.`,
507
+ row_index: rowIndex,
508
+ });
509
+ return;
510
+ }
511
+ const acceptedNormalization = normalizeAllowedTraceHashDifference(row);
512
+ intendedRoots.push({
513
+ rowIndex,
514
+ table: rootType.table,
515
+ id: identity.id,
516
+ version: identity.version,
517
+ payloadSha256: canonicalPayloadSha256(row),
518
+ acceptedNormalizedPayloadSha256: acceptedNormalization.removed_paths.length > 0
519
+ ? acceptedNormalization.normalized_sha256
520
+ : null,
521
+ acceptedNormalizedRemovedPaths: acceptedNormalization.removed_paths,
522
+ });
523
+ });
524
+ }
525
+ if (expectedRows <= 0) {
526
+ blockers.push({
527
+ code: "final_rows_empty",
528
+ message: "Post-write closeout requires at least one final row.",
529
+ final_rows_file: repoRelativeMaybe(finalRowsFile),
530
+ });
531
+ }
532
+ let rootProof = { checksFile: null, readbackChecks: [], uniqueReadbackCount: 0 };
533
+ if (finalRowsFile && fileExists(finalRowsFile)) {
534
+ validateCommitReportForCloseout({
535
+ commitReport: commitArtifact.value,
536
+ commitReportPath: commitArtifact.path,
537
+ datasetType,
538
+ finalRowsFile,
539
+ expectedRows,
540
+ blockers,
541
+ });
542
+ rootProof = validatePostWriteVerifyForCloseout({
543
+ verifyReport: verifyArtifact.value,
544
+ verifyReportPath: verifyArtifact.path,
545
+ finalRowsFile,
546
+ expectedRows,
547
+ targetUserId,
548
+ expectedStateCode,
549
+ intendedRoots,
550
+ allowTraceHashOnlyNormalization: !productionTestAccount,
551
+ blockers,
552
+ });
553
+ }
554
+ const traceQueues = validateTraceQueuesForCloseout({
555
+ handoffPlan,
556
+ finalizeReport,
557
+ mutationManifest,
558
+ datasetType,
559
+ finalRowsFile,
560
+ blockers,
561
+ });
562
+ const reportPath = path.join(outDir, "dataset-post-write-closeout-report.json");
563
+ const report = {
564
+ schema_version: 1,
565
+ generated_at_utc: nowIso(),
566
+ status: blockers.length === 0 ? "completed" : "blocked",
567
+ dataset_type: datasetType,
568
+ profile: handoffPlan.profile ?? finalizeReport?.profile ?? mutationManifest?.profile ?? null,
569
+ remote_write_mode: "read-only",
570
+ handoff_plan: repoRelativePath(handoffArtifact.path),
571
+ finalize_report: finalizeArtifact ? repoRelativePath(finalizeArtifact.path) : null,
572
+ mutation_manifest: mutationArtifact ? repoRelativePath(mutationArtifact.path) : null,
573
+ commit_report: repoRelativePath(commitArtifact.path),
574
+ post_write_verify_report: repoRelativePath(verifyArtifact.path),
575
+ final_rows_file: repoRelativeMaybe(finalRowsFile),
576
+ final_rows_artifact: finalRowsArtifact
577
+ ? {
578
+ path: finalRowsArtifact.path,
579
+ bytes: finalRowsArtifact.bytes,
580
+ sha256: finalRowsArtifact.sha256,
581
+ }
582
+ : null,
583
+ target_user_id: targetUserId || null,
584
+ expected_state_code: expectedStateCode,
585
+ policy: {
586
+ ai_full_context_semantic_completion_required_before_entry: true,
587
+ commit_boundary: "This closeout is read-only. It accepts only an already executed explicit CLI commit plus post-write root payload readback evidence.",
588
+ compare_root_payload_required: true,
589
+ accepted_trace_hash_only_normalization: !productionTestAccount,
590
+ closeout_completion: "completed means Foundry handoff was ready, CLI commit completed without row failures, post-write verify proved owner, state_code, and local/remote payload hash equality for the same final rows, and profile-required full schema/YAML/context AI proof remained attached.",
591
+ },
592
+ counts: {
593
+ blockers: blockers.length,
594
+ final_rows: expectedRows,
595
+ commit_rows: Number(commitArtifact.value.counts?.executed ??
596
+ commitArtifact.value.counts?.success_count ??
597
+ 0) || 0,
598
+ post_write_verify_blockers: Number(verifyArtifact.value.counts?.blockers ??
599
+ (Array.isArray(verifyArtifact.value.blockers)
600
+ ? verifyArtifact.value.blockers.length
601
+ : 0)) || 0,
602
+ root_readback_checks: Number(verifyArtifact.value.counts?.root_readback_checks ?? 0) || 0,
603
+ unique_root_readback_checks: rootProof.uniqueReadbackCount,
604
+ root_payload_mismatches: Number(verifyArtifact.value.counts?.root_payload_mismatches ?? -1),
605
+ unresolved_trace_entries: traceQueues.counts.unresolved_trace_entries,
606
+ source_exchange_completeness_entries: traceQueues.counts.source_exchange_completeness_entries,
607
+ source_reference_rewrites: traceQueues.counts.source_reference_rewrites,
608
+ ai_patch_evidence_entries: Number(mutationManifest?.counts?.ai_patch_evidence_entries ?? 0) || 0,
609
+ ai_classification_decision_entries: Number(mutationManifest?.counts?.ai_classification_decision_entries ?? 0) || 0,
610
+ ai_location_decision_entries: Number(mutationManifest?.counts?.ai_location_decision_entries ?? 0) || 0,
611
+ ai_identity_decision_entries: Number(mutationManifest?.counts?.ai_identity_decision_entries ?? 0) || 0,
612
+ source_contact_rewrite_semantic_evidence_entries: Number(mutationManifest?.counts?.source_contact_rewrite_semantic_evidence_entries ?? 0) ||
613
+ 0,
614
+ ai_semantic_evidence_entries: (Number(mutationManifest?.counts?.ai_patch_evidence_entries ?? 0) || 0) +
615
+ (Number(mutationManifest?.counts?.ai_classification_decision_entries ?? 0) || 0) +
616
+ (Number(mutationManifest?.counts?.ai_location_decision_entries ?? 0) || 0) +
617
+ (Number(mutationManifest?.counts?.ai_identity_decision_entries ?? 0) || 0) +
618
+ (Number(mutationManifest?.counts?.source_contact_rewrite_semantic_evidence_entries ?? 0) || 0),
619
+ full_context_ai_completion_required: postWriteFullContextCheck.required,
620
+ },
621
+ blockers,
622
+ files: {
623
+ report: repoRelativePath(reportPath),
624
+ trace_queues: traceQueues.files,
625
+ remote_verification_checks: verifyArtifact.value.files?.checks
626
+ ? repoRelativeMaybe(resolveRepoPath(verifyArtifact.value.files.checks))
627
+ : null,
628
+ },
629
+ };
630
+ const importLedger = writeCloseoutImportLedger
631
+ ? writeCloseoutImportLedger({
632
+ report,
633
+ reportPath,
634
+ ledgerDir: resolveRepoPath(options.ledgerDir || options.importLedgerDir || path.join(outDir, "import-ledger")),
635
+ })
636
+ : { status: "skipped", files: {}, counts: { entries_written: 0 } };
637
+ const finalReport = {
638
+ ...report,
639
+ counts: {
640
+ ...report.counts,
641
+ import_ledger_entries: importLedger.counts?.entries_written ?? 0,
642
+ },
643
+ files: {
644
+ ...report.files,
645
+ import_ledger: importLedger.files ?? {},
646
+ },
647
+ };
648
+ writeJson(reportPath, finalReport);
649
+ return finalReport;
650
+ }
651
+ return {
652
+ runDatasetPostWriteCloseout,
653
+ validatePostWriteVerifyForCloseout,
654
+ validateCommitReportForCloseout,
655
+ };
656
+ }
@@ -0,0 +1,7 @@
1
+ export type ParsedScalar = boolean | number | string;
2
+ export type ParsedArgs = {
3
+ _: string[];
4
+ [key: string]: ParsedScalar | ParsedScalar[];
5
+ };
6
+ export declare function parseScalar(value: unknown): ParsedScalar;
7
+ export declare function parseArgs(argv: readonly string[]): ParsedArgs;