@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,548 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { resolveFoundryRuntimePaths } from "./foundry-runtime-paths.js";
5
+ import { sha256Json } from "./import-curation/internal/hash-utils.js";
6
+ const { entryPath: foundryEntryPath, repoRoot } = resolveFoundryRuntimePaths(import.meta.url);
7
+ function record(value) {
8
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
9
+ }
10
+ export function createPostAuthoringFinalizeUtils({ executionEnvironment = process.env, asText, booleanOption, cliWrapperCommands, countRowsFile, datasetIdentity, ensureArray, fileExists, identityPreflightCommands, identityReferenceRewriteIndexPath, normalizedList, readRowsFile, referenceShortDescription, repoRelativeMaybe, resolveRepoPath, unique, writeJsonLines, }) {
11
+ function sourceReferenceRewritesFileForRowsFile(rowsFile, options = {}) {
12
+ const configured = resolveRepoPath(options.sourceReferenceRewrites ||
13
+ options.sourceReferenceRewritesFile ||
14
+ options.sourceReferenceRewriteFile ||
15
+ options.referenceRewrites ||
16
+ options.referenceRewritesFile);
17
+ if (configured && fileExists(configured))
18
+ return configured;
19
+ if (!rowsFile)
20
+ return null;
21
+ const rowsDir = path.dirname(rowsFile);
22
+ const candidates = [
23
+ path.join(rowsDir, "source-reference-rewrites.jsonl"),
24
+ path.join(path.dirname(rowsDir), "source-reference-rewrites.jsonl"),
25
+ ];
26
+ return candidates.find((candidate) => fileExists(candidate)) ?? null;
27
+ }
28
+ function identityReferenceRewritesFileForRowsFile(rowsFile, options = {}) {
29
+ const configured = resolveRepoPath(options.identityReferenceRewrites ||
30
+ options.identityReferenceRewritesFile ||
31
+ options.identityFlowReferenceRewrites ||
32
+ options.identityFlowReferenceRewritesFile);
33
+ if (configured && fileExists(configured))
34
+ return configured;
35
+ if (!rowsFile)
36
+ return null;
37
+ const rowsDir = path.dirname(rowsFile);
38
+ const candidates = [
39
+ path.join(rowsDir, "identity-reference-rewrites.jsonl"),
40
+ path.join(rowsDir, "identity-flow-reference-rewrites.jsonl"),
41
+ path.join(path.dirname(rowsDir), "identity-reference-rewrites.jsonl"),
42
+ path.join(path.dirname(rowsDir), "identity-flow-reference-rewrites.jsonl"),
43
+ ];
44
+ return candidates.find((candidate) => fileExists(candidate)) ?? null;
45
+ }
46
+ function existingSiblingRowsFile(rowsFile, fileName) {
47
+ if (!rowsFile)
48
+ return null;
49
+ const candidate = path.join(path.dirname(rowsFile), fileName);
50
+ return fileExists(candidate) && countRowsFile(candidate) > 0 ? candidate : null;
51
+ }
52
+ function defaultFinalizeSupportRowsFiles(rowsFile) {
53
+ const support = existingSiblingRowsFile(rowsFile, "support.jsonl");
54
+ if (support)
55
+ return [support];
56
+ return [
57
+ existingSiblingRowsFile(rowsFile, "contacts.jsonl"),
58
+ existingSiblingRowsFile(rowsFile, "sources.jsonl"),
59
+ ].filter((filePath) => Boolean(filePath));
60
+ }
61
+ function identityRewriteExternalFlowRefRows(identityReferenceRewriteStage) {
62
+ const seen = new Set();
63
+ const rows = [];
64
+ for (const rewrite of ensureArray(identityReferenceRewriteStage?.rewrite_rows)) {
65
+ const canonical = record(rewrite.canonical) ?? {};
66
+ const id = asText(canonical.ref_object_id ?? canonical.refObjectId ?? canonical.id);
67
+ if (!id)
68
+ continue;
69
+ const version = asText(canonical.version) || "00.00.001";
70
+ const key = `${id}@@${version}`;
71
+ if (seen.has(key))
72
+ continue;
73
+ seen.add(key);
74
+ rows.push({
75
+ id,
76
+ dataset_id: id,
77
+ version,
78
+ dataset_version: version,
79
+ source: "identity_reference_rewrite",
80
+ reason: "Existing database flow selected by CLI identity-preflight and used as an external flow reference for curation queue dependency closure.",
81
+ });
82
+ }
83
+ return rows;
84
+ }
85
+ function writeIdentityRewriteExternalFlowRefs({ outDir, identityReferenceRewriteStage, }) {
86
+ const rows = identityRewriteExternalFlowRefRows(identityReferenceRewriteStage);
87
+ if (rows.length === 0)
88
+ return null;
89
+ const filePath = path.join(outDir, "identity-reference-rewrite-external-flow-refs.jsonl");
90
+ writeJsonLines(filePath, rows);
91
+ return filePath;
92
+ }
93
+ function existingOptionFile(value, label) {
94
+ const files = existingOptionFiles(value, label);
95
+ if (files.length > 1) {
96
+ throw new Error(`${label} accepts one file, received ${files.length}.`);
97
+ }
98
+ return files[0] ?? null;
99
+ }
100
+ function existingOptionFiles(value, label) {
101
+ return normalizedList(value).map((input) => {
102
+ const resolved = resolveRepoPath(input);
103
+ if (!fileExists(resolved)) {
104
+ throw new Error(`${label} must point to an existing file: ${input}`);
105
+ }
106
+ return resolved;
107
+ });
108
+ }
109
+ function curationQueueManifestFile(queueDir) {
110
+ if (!queueDir)
111
+ return null;
112
+ const manifest = path.join(queueDir, "outputs", "curation-queue-manifest.json");
113
+ return fileExists(manifest) ? manifest : null;
114
+ }
115
+ function writeProcessReferenceExternalFlowRefs({ outDir, processRowsFile, flowRowsFile, }) {
116
+ if (!processRowsFile || !fileExists(processRowsFile))
117
+ return null;
118
+ const localFlowKeys = new Set();
119
+ for (const row of readRowsFile(flowRowsFile)) {
120
+ const identity = datasetIdentity(row, "flow");
121
+ if (!identity.id)
122
+ continue;
123
+ localFlowKeys.add(identity.id);
124
+ localFlowKeys.add(`${identity.id}@@${identity.version || "00.00.001"}`);
125
+ }
126
+ const refs = new Map();
127
+ for (const [rowIndex, row] of readRowsFile(processRowsFile).entries()) {
128
+ const processIdentity = datasetIdentity(row, "process");
129
+ const processDataSet = record(row.processDataSet);
130
+ const exchanges = ensureArray(record(processDataSet?.exchanges)?.exchange);
131
+ for (const [exchangeIndex, exchange] of exchanges.entries()) {
132
+ const reference = record(exchange.referenceToFlowDataSet);
133
+ if (!reference)
134
+ continue;
135
+ const id = asText(reference["@refObjectId"]);
136
+ if (!id)
137
+ continue;
138
+ const version = asText(reference["@version"]) || "00.00.001";
139
+ if (localFlowKeys.has(id) || localFlowKeys.has(`${id}@@${version}`)) {
140
+ continue;
141
+ }
142
+ const key = `${id}@@${version}`;
143
+ const existing = refs.get(key) ?? {
144
+ id,
145
+ dataset_id: id,
146
+ version,
147
+ dataset_version: version,
148
+ table: "flows",
149
+ source: "process_reference_remote_verify_required",
150
+ short_description: referenceShortDescription(reference) || id,
151
+ reason: "Process references this flow outside the current local flow write scope. Foundry declares it as an external flow reference for curation queue closure; mutation manifest and remote verification must prove it exists before commit.",
152
+ references: [],
153
+ };
154
+ existing.references.push({
155
+ process_id: processIdentity.id,
156
+ process_version: processIdentity.version || "00.00.001",
157
+ row_index: rowIndex,
158
+ path: `processDataSet.exchanges.exchange.${exchangeIndex}.referenceToFlowDataSet`,
159
+ });
160
+ refs.set(key, existing);
161
+ }
162
+ }
163
+ const rows = [...refs.values()];
164
+ const outFile = path.join(outDir, "process-reference-external-flow-refs.jsonl");
165
+ writeJsonLines(outFile, rows);
166
+ return rows.length > 0 ? outFile : null;
167
+ }
168
+ function readJsonIfExists(filePath) {
169
+ if (!filePath || !fileExists(filePath))
170
+ return null;
171
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
172
+ }
173
+ function resolveIndexArtifact(indexPath, artifactPath) {
174
+ const text = asText(artifactPath);
175
+ if (!text)
176
+ return null;
177
+ if (path.isAbsolute(text))
178
+ return text;
179
+ const repoPath = resolveRepoPath(text);
180
+ if (fileExists(repoPath))
181
+ return repoPath;
182
+ return path.resolve(path.dirname(indexPath), text);
183
+ }
184
+ function identityPreflightIndexTargetSha(indexPath, row) {
185
+ const direct = asText(row?.target_sha256 ?? row?.targetSha256);
186
+ if (direct)
187
+ return direct;
188
+ const requestPath = resolveIndexArtifact(indexPath, row?.request_file ?? row?.requestFile);
189
+ const request = readJsonIfExists(requestPath);
190
+ return request?.target ? sha256Json(request.target) : null;
191
+ }
192
+ function currentScopeIdentityPreflightRefreshPlan({ datasetType, rowsFile, indexPath, }) {
193
+ const normalizedType = String(datasetType || "").toLowerCase();
194
+ if (!["flow", "process"].includes(normalizedType)) {
195
+ return {
196
+ required: false,
197
+ reason: "dataset_type_not_identity_preflight_refreshable",
198
+ current_rows: 0,
199
+ index_rows: 0,
200
+ stale_rows: 0,
201
+ missing_rows: 0,
202
+ missing_target_hash_rows: 0,
203
+ };
204
+ }
205
+ const currentRows = readRowsFile(rowsFile);
206
+ const indexRows = readRowsFile(indexPath);
207
+ const indexByKey = new Map();
208
+ for (const row of indexRows) {
209
+ const type = String(row?.dataset_type ?? row?.type ?? "").toLowerCase();
210
+ const id = asText(row?.dataset_id ?? row?.entity_id ?? row?.id);
211
+ const version = asText(row?.dataset_version ?? row?.version) || "00.00.001";
212
+ if (!type || !id)
213
+ continue;
214
+ indexByKey.set(`${type}:${id}@@${version}`, row);
215
+ if (!indexByKey.has(`${type}:${id}`)) {
216
+ indexByKey.set(`${type}:${id}`, row);
217
+ }
218
+ }
219
+ const staleRows = [];
220
+ const missingRows = [];
221
+ const missingTargetHashRows = [];
222
+ for (const payload of currentRows) {
223
+ const identity = datasetIdentity(payload, normalizedType);
224
+ if (!identity.id)
225
+ continue;
226
+ const version = identity.version || "00.00.001";
227
+ const row = indexByKey.get(`${normalizedType}:${identity.id}@@${version}`) ??
228
+ indexByKey.get(`${normalizedType}:${identity.id}`);
229
+ if (!row) {
230
+ missingRows.push({ id: identity.id, version });
231
+ continue;
232
+ }
233
+ const targetSha = identityPreflightIndexTargetSha(indexPath, row);
234
+ if (!targetSha) {
235
+ missingTargetHashRows.push({ id: identity.id, version });
236
+ continue;
237
+ }
238
+ const currentSha = sha256Json(payload);
239
+ if (targetSha !== currentSha) {
240
+ staleRows.push({
241
+ id: identity.id,
242
+ version,
243
+ request_target_sha256: targetSha,
244
+ current_payload_sha256: currentSha,
245
+ });
246
+ }
247
+ }
248
+ const required = missingRows.length > 0 || missingTargetHashRows.length > 0 || staleRows.length > 0;
249
+ return {
250
+ required,
251
+ reason: required ? "current_scope_index_not_exact" : "current_scope_index_exact",
252
+ current_rows: currentRows.length,
253
+ index_rows: indexRows.length,
254
+ stale_rows: staleRows.length,
255
+ missing_rows: missingRows.length,
256
+ missing_target_hash_rows: missingTargetHashRows.length,
257
+ examples: [...missingRows, ...missingTargetHashRows, ...staleRows].slice(0, 5),
258
+ };
259
+ }
260
+ function runFinalizeAutoCurationQueue({ datasetType, rowsFile, cleanedRowsFile, outDir, options, fullContextRequirement, identityReferenceRewriteStage, }) {
261
+ const providedQueueDir = resolveRepoPath(options.queueDir || options.curationQueueDir);
262
+ if (providedQueueDir) {
263
+ return {
264
+ stage: "curation_queue",
265
+ status: "provided",
266
+ queue_dir: providedQueueDir,
267
+ report_file: curationQueueManifestFile(providedQueueDir),
268
+ report: null,
269
+ files: {},
270
+ };
271
+ }
272
+ if (!(Boolean(fullContextRequirement) && datasetType === "process")) {
273
+ return {
274
+ stage: "curation_queue",
275
+ status: "not_required",
276
+ queue_dir: null,
277
+ report_file: null,
278
+ report: null,
279
+ files: {},
280
+ };
281
+ }
282
+ const queueDir = path.join(outDir, "curation-queue");
283
+ const queueInputsDir = path.join(outDir, "curation-queue-inputs");
284
+ const flowsFile = existingOptionFile(options.flows || options.flowsFile || options.flowRows, "--flows") ??
285
+ existingSiblingRowsFile(rowsFile, "flows.jsonl");
286
+ const explicitSupportFiles = existingOptionFiles(options.support || options.supportFile || options.supportRows, "--support");
287
+ const supportFiles = explicitSupportFiles.length > 0
288
+ ? explicitSupportFiles
289
+ : defaultFinalizeSupportRowsFiles(rowsFile);
290
+ const explicitExternalFlowRefs = existingOptionFiles(options.externalFlowRef ||
291
+ options.externalFlowRefs ||
292
+ options.externalFlowRefFile ||
293
+ options.externalFlowRefRows, "--external-flow-ref");
294
+ const identityExternalRefs = writeIdentityRewriteExternalFlowRefs({
295
+ outDir: queueInputsDir,
296
+ identityReferenceRewriteStage,
297
+ });
298
+ const processReferenceExternalRefs = writeProcessReferenceExternalFlowRefs({
299
+ outDir: queueInputsDir,
300
+ processRowsFile: cleanedRowsFile,
301
+ flowRowsFile: flowsFile,
302
+ });
303
+ const externalFlowRefFiles = unique([
304
+ ...explicitExternalFlowRefs,
305
+ identityExternalRefs,
306
+ processReferenceExternalRefs,
307
+ ]).filter((filePath) => Boolean(filePath));
308
+ const report = cliWrapperCommands.runDatasetCurationQueueBuild({
309
+ processes: cleanedRowsFile,
310
+ flows: flowsFile,
311
+ support: supportFiles,
312
+ externalFlowRef: externalFlowRefFiles,
313
+ outDir: queueDir,
314
+ });
315
+ return {
316
+ stage: "curation_queue",
317
+ status: report.status,
318
+ queue_dir: queueDir,
319
+ report_file: resolveRepoPath(record(report.files)?.manifest),
320
+ report,
321
+ files: {
322
+ manifest: record(report.files)?.manifest ?? null,
323
+ identity_external_flow_refs: repoRelativeMaybe(identityExternalRefs),
324
+ process_reference_external_flow_refs: repoRelativeMaybe(processReferenceExternalRefs),
325
+ },
326
+ };
327
+ }
328
+ // Mega-scope speedup (opt-in via IDENTITY_PREFLIGHT_CONCURRENCY): the per-flow identity
329
+ // preflight remote search is independent per flow and the remote scales with concurrency,
330
+ // but the in-process run loop is serial — the dominant cost on ~2000-flow mega-scopes. When
331
+ // enabled, pre-populate the per-flow identity-decision.json artifacts by running N shard
332
+ // processes of the SAME index over disjoint --offset/--limit slices in parallel; the
333
+ // subsequent in-process run (onlyPending) then sees those flows as completed and skips their
334
+ // remote search. Any shard that fails simply leaves its flows pending, so the in-process run
335
+ // completes them serially — this is a best-effort accelerator that NEVER changes the result.
336
+ // Default 1 → no sharding → the existing serial path runs unchanged (BAFU byte-identical).
337
+ // Applies to every profile (BAFU/USLCI/future) whenever the env var is set.
338
+ function runIdentityPreflightShardsInParallel({ index, outDir, options, }) {
339
+ const concurrency = Math.max(1, Number.parseInt(executionEnvironment.IDENTITY_PREFLIGHT_CONCURRENCY ??
340
+ String(options.identityPreflightConcurrency ?? "1"), 10) || 1);
341
+ if (concurrency <= 1 || !index || !fileExists(index)) {
342
+ return { sharded: false, concurrency: 1 };
343
+ }
344
+ const total = countRowsFile(index);
345
+ if (!total || total <= concurrency) {
346
+ return { sharded: false, concurrency, total: total ?? 0 };
347
+ }
348
+ const chunk = Math.ceil(total / concurrency);
349
+ const timeoutMs = options.identityPreflightTimeoutMs ||
350
+ options.identityPreflightTimeout ||
351
+ options.timeoutMs ||
352
+ options.timeout;
353
+ const maxAttempts = options.identityPreflightMaxAttempts || options.identityPreflightRetryAttempts || 3;
354
+ const commands = [];
355
+ for (let i = 0; i < concurrency; i += 1) {
356
+ const offset = i * chunk;
357
+ if (offset >= total)
358
+ break;
359
+ const args = [
360
+ foundryEntryPath,
361
+ "dataset-identity-preflight-run",
362
+ "--index",
363
+ index,
364
+ "--out-dir",
365
+ path.join(outDir, "identity-preflight-run-parallel", `shard-${i}`),
366
+ "--offset",
367
+ String(offset),
368
+ "--limit",
369
+ String(chunk),
370
+ "--only-pending",
371
+ ];
372
+ if (timeoutMs)
373
+ args.push("--timeout-ms", String(timeoutMs));
374
+ if (maxAttempts)
375
+ args.push("--max-attempts", String(maxAttempts));
376
+ commands.push([process.execPath, ...args]);
377
+ }
378
+ const listFile = path.join(outDir, "identity-preflight-run-parallel", "shard-commands.json");
379
+ fs.mkdirSync(path.dirname(listFile), { recursive: true });
380
+ fs.writeFileSync(listFile, JSON.stringify(commands));
381
+ // Spawn all shards concurrently from a one-shot node worker (args passed as arrays, no
382
+ // shell quoting), wait for every shard, and surface a non-zero exit if any shard failed.
383
+ const worker = "const fs=require('fs'),cp=require('child_process');" +
384
+ "const cmds=JSON.parse(fs.readFileSync(process.argv[1],'utf8'));let fail=0;" +
385
+ "Promise.all(cmds.map(c=>new Promise(r=>{" +
386
+ `const p=cp.spawn(c[0],c.slice(1),{cwd:${JSON.stringify(repoRoot)},env:process.env,stdio:"ignore"});` +
387
+ "p.on('close',code=>{if(code!==0)fail=1;r();});p.on('error',()=>{fail=1;r();});" +
388
+ "}))).then(()=>process.exit(fail));";
389
+ const result = spawnSync(process.execPath, ["-e", worker, listFile], {
390
+ cwd: repoRoot,
391
+ env: executionEnvironment,
392
+ encoding: "utf8",
393
+ });
394
+ return {
395
+ sharded: true,
396
+ concurrency,
397
+ shards: commands.length,
398
+ total,
399
+ chunk,
400
+ exit_code: typeof result.status === "number" ? result.status : null,
401
+ };
402
+ }
403
+ function preseedResolutionReuseDecisions({ index }) {
404
+ const mapFile = resolveRepoPath(executionEnvironment.IDENTITY_PREFLIGHT_REUSE_MAP);
405
+ if (!mapFile || !fileExists(mapFile) || !index || !fileExists(index)) {
406
+ return { enabled: false, seeded: 0 };
407
+ }
408
+ return {
409
+ enabled: false,
410
+ seeded: 0,
411
+ reason: "bound_library_resolution_seed_manifest_required",
412
+ };
413
+ }
414
+ function runFinalizeIdentityPreflightStage({ rowsFile, outDir, options, }) {
415
+ if (!booleanOption(options.runIdentityPreflight)) {
416
+ return {
417
+ stage: "identity_preflight_run",
418
+ status: "not_requested",
419
+ report: null,
420
+ report_file: null,
421
+ };
422
+ }
423
+ const baseIndexPath = identityPreflightCommands.identityPreflightRunIndexPath(options) ||
424
+ identityReferenceRewriteIndexPath(options, rowsFile);
425
+ if (!baseIndexPath || !fileExists(baseIndexPath)) {
426
+ throw new Error("--run-identity-preflight requires --identity-preflight-index, --index, or a sibling identity-preflight-requests/identity-preflight-requests.jsonl.");
427
+ }
428
+ const refreshRequested = options.refreshIdentityPreflight === undefined
429
+ ? false
430
+ : booleanOption(options.refreshIdentityPreflight);
431
+ const allowStaleIdentityPreflight = booleanOption(options.allowStaleIdentityPreflight || options.allowStaleIdentityPreflightIndex);
432
+ const refreshPlan = currentScopeIdentityPreflightRefreshPlan({
433
+ datasetType: options.type,
434
+ rowsFile,
435
+ indexPath: baseIndexPath,
436
+ });
437
+ let indexPath = baseIndexPath;
438
+ let refreshReport = null;
439
+ let mergeReport = null;
440
+ const refreshForcedButExact = Boolean(!allowStaleIdentityPreflight && refreshRequested && !refreshPlan.required);
441
+ if (!allowStaleIdentityPreflight &&
442
+ refreshPlan.required &&
443
+ ["flow", "process"].includes(String(options.type || "").toLowerCase())) {
444
+ const baseIndexHasSourceContext = readRowsFile(baseIndexPath).some((row) => asText(row?.source_file ?? row?.sourceFile));
445
+ refreshReport = identityPreflightCommands.runDatasetIdentityPreflightRequestsBuild({
446
+ type: options.type,
447
+ rowsFile,
448
+ ...(baseIndexHasSourceContext ? { sourceIndex: baseIndexPath } : {}),
449
+ outDir: path.join(outDir, "identity-preflight-current-scope", "requests"),
450
+ });
451
+ const refreshIndex = resolveRepoPath(record(refreshReport.files)?.identity_preflight_requests);
452
+ if (refreshReport.status === "ready" && refreshIndex && fileExists(refreshIndex)) {
453
+ mergeReport = identityPreflightCommands.runDatasetIdentityPreflightIndexMerge({
454
+ baseIndex: baseIndexPath,
455
+ updateIndex: refreshIndex,
456
+ outDir: path.join(outDir, "identity-preflight-current-scope", "merge"),
457
+ });
458
+ const mergedIndex = resolveRepoPath(record(mergeReport.files)?.merged_index);
459
+ if (mergeReport.status === "ready" && mergedIndex && fileExists(mergedIndex)) {
460
+ indexPath = mergedIndex;
461
+ }
462
+ }
463
+ }
464
+ if (refreshReport && refreshReport.status !== "ready") {
465
+ return {
466
+ stage: "identity_preflight_run",
467
+ status: "blocked_current_scope_refresh",
468
+ report: refreshReport,
469
+ report_file: resolveRepoPath(record(refreshReport.files)?.report),
470
+ index_file: repoRelativeMaybe(indexPath),
471
+ refresh_report_file: repoRelativeMaybe(resolveRepoPath(record(refreshReport.files)?.report)),
472
+ merge_report_file: null,
473
+ };
474
+ }
475
+ if (mergeReport && mergeReport.status !== "ready") {
476
+ return {
477
+ stage: "identity_preflight_run",
478
+ status: "blocked_current_scope_merge",
479
+ report: mergeReport,
480
+ report_file: resolveRepoPath(record(mergeReport.files)?.report),
481
+ index_file: repoRelativeMaybe(indexPath),
482
+ refresh_report_file: repoRelativeMaybe(resolveRepoPath(record(refreshReport?.files)?.report)),
483
+ merge_report_file: repoRelativeMaybe(resolveRepoPath(record(mergeReport.files)?.report)),
484
+ };
485
+ }
486
+ // Unbound synthetic reports are intentionally disabled. A future optimization must bind the
487
+ // request, library-resolution bytes, canonical target, and producer provenance in a dedicated
488
+ // seed manifest before onlyPending may skip the live identity search.
489
+ const reuseSeed = preseedResolutionReuseDecisions({ index: indexPath });
490
+ // Best-effort parallel pre-pass (opt-in): populate the REMAINING per-flow decisions concurrently
491
+ // so the in-process run below skips them via onlyPending. No-op when IDENTITY_PREFLIGHT_CONCURRENCY
492
+ // is unset/1, so BAFU and any non-opted run are byte-identical to before.
493
+ const parallelShards = runIdentityPreflightShardsInParallel({
494
+ index: indexPath,
495
+ outDir,
496
+ options,
497
+ });
498
+ const report = identityPreflightCommands.runDatasetIdentityPreflightRun({
499
+ index: indexPath,
500
+ outDir: path.join(outDir, "identity-preflight-run"),
501
+ onlyPending: options.onlyPending === undefined ? true : booleanOption(options.onlyPending),
502
+ timeoutMs: options.identityPreflightTimeoutMs ||
503
+ options.identityPreflightTimeout ||
504
+ options.timeoutMs ||
505
+ options.timeout,
506
+ // Transient CLI/remote failures (timeout, missing JSON report) are retriable per
507
+ // identity-preflight-run; without this a single remote blip blocks the curation gate.
508
+ maxAttempts: options.identityPreflightMaxAttempts || options.identityPreflightRetryAttempts || 3,
509
+ dryRun: options.identityPreflightDryRun || options.dryRunIdentityPreflight,
510
+ authReceipt: options.identityPreflightAuthReceipt ||
511
+ options.authReceipt ||
512
+ options.authIdentityReceipt ||
513
+ options.accountReceipt,
514
+ expectedProjectRef: options.identityPreflightExpectedProjectRef ||
515
+ options.expectedProjectRef ||
516
+ options.expectedProject ||
517
+ options.projectRef,
518
+ expectedUserId: options.identityPreflightExpectedUserId || options.expectedUserId || options.targetUserId,
519
+ authReceiptMaxAgeMs: options.identityPreflightAuthReceiptMaxAgeMs || options.authReceiptMaxAgeMs,
520
+ });
521
+ return {
522
+ stage: "identity_preflight_run",
523
+ status: report.status,
524
+ report,
525
+ report_file: resolveRepoPath(record(report.files)?.report),
526
+ index_file: repoRelativeMaybe(indexPath),
527
+ base_index_file: repoRelativeMaybe(baseIndexPath),
528
+ refresh_required: Boolean(!allowStaleIdentityPreflight && refreshPlan.required),
529
+ refresh_forced: Boolean(!allowStaleIdentityPreflight && refreshRequested && refreshPlan.required),
530
+ refresh_force_skipped_exact: refreshForcedButExact,
531
+ refresh_plan: refreshPlan,
532
+ refresh_report_file: repoRelativeMaybe(resolveRepoPath(record(refreshReport?.files)?.report)),
533
+ merge_report_file: repoRelativeMaybe(resolveRepoPath(record(mergeReport?.files)?.report)),
534
+ refresh_report: refreshReport,
535
+ merge_report: mergeReport,
536
+ parallel_shards: parallelShards,
537
+ reuse_seed: reuseSeed,
538
+ };
539
+ }
540
+ return {
541
+ identityReferenceRewritesFileForRowsFile,
542
+ preseedResolutionReuseDecisions,
543
+ runFinalizeAutoCurationQueue,
544
+ runFinalizeIdentityPreflightStage,
545
+ sourceReferenceRewritesFileForRowsFile,
546
+ };
547
+ }
548
+ export const postAuthoringFinalizeUtilsTestHooks = { foundryEntryPath };
@@ -0,0 +1,44 @@
1
+ export type IntendedRoot = {
2
+ rowIndex: number;
3
+ table: string;
4
+ id: string;
5
+ version: string;
6
+ payloadSha256: string;
7
+ acceptedNormalizedPayloadSha256?: string | null;
8
+ acceptedNormalizedRemovedPaths?: string[];
9
+ };
10
+ export type RootReadbackCheck = {
11
+ role?: unknown;
12
+ row_index?: unknown;
13
+ table?: unknown;
14
+ id?: unknown;
15
+ version?: unknown;
16
+ path?: unknown;
17
+ status?: unknown;
18
+ local_payload_sha256?: unknown;
19
+ remote_payload_sha256?: unknown;
20
+ remote_user_id?: unknown;
21
+ remote_state_code?: unknown;
22
+ foundry_verification_mode?: unknown;
23
+ foundry_original_status?: unknown;
24
+ foundry_original_local_payload_sha256?: unknown;
25
+ foundry_original_remote_payload_sha256?: unknown;
26
+ foundry_accepted_differences?: unknown;
27
+ };
28
+ export type RootProofBlocker = {
29
+ code: string;
30
+ message: string;
31
+ key?: string;
32
+ row_index?: number | null;
33
+ };
34
+ export declare function canonicalPayloadSha256(value: unknown): string;
35
+ export declare function validateUniqueRootReadbacks(input: {
36
+ intended: IntendedRoot[];
37
+ checks: RootReadbackCheck[];
38
+ targetUserId: string;
39
+ expectedStateCode: number;
40
+ allowTraceHashOnlyNormalization?: boolean;
41
+ }): {
42
+ blockers: RootProofBlocker[];
43
+ uniqueReadbackCount: number;
44
+ };