@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,293 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { randomUUID } from "node:crypto";
4
+ import { createBatchContract, createBatchItemContract, parseBatchItemContract, } from "@tiangong-lca/cli/batch";
5
+ import { parseFoundryCommandSpec } from "@tiangong-lca/cli/command-spec";
6
+ import { createScopeAttemptLedgerService } from "./batch-orchestration/scope-attempt-ledger.js";
7
+ import { captureFoundryInput, FoundryContextError, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
8
+ import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./foundry-workflow-state.js";
9
+ import { runFoundryTaskOperation } from "./foundry-task-store.js";
10
+ import { sha256Json } from "./identity-preflight-proof.js";
11
+ function buildRequest(context, authorization) {
12
+ const value = authorization.value, input = workflowObject(value.input), capsule = workflowObject(value.capsule), handoff = workflowObject(value.handoff);
13
+ if (value.status !== "sealed" ||
14
+ typeof value.dataset_type !== "string" ||
15
+ typeof input.path !== "string" ||
16
+ !context.accountIntent)
17
+ throw new FoundryContextError("execution_request_invalid", "Select a sealed current owner scope.");
18
+ readFoundryInput(context, input.path);
19
+ const commands = workflowObject(handoff.commands), commit = parseFoundryCommandSpec(commands.commit), verify = parseFoundryCommandSpec(commands.post_write_verify);
20
+ const capsuleFile = resolveFoundryOutput(context, String(capsule.capsule_file));
21
+ const capsuleFact = captureFoundryInput(capsuleFile);
22
+ if (capsuleFact.sha256 !== capsule.capsule_sha256)
23
+ throw new FoundryContextError("execution_capsule_changed", "The sealed capsule changed before request preparation.");
24
+ const scopeId = sha256Json({ task: context.taskId, type: value.dataset_type });
25
+ if ((handoff.account_mode ?? "ordinary") !== (context.accountIntent.accountMode ?? "ordinary"))
26
+ throw new FoundryContextError("execution_account_mode_mismatch", "Sealed handoff must preserve the registered account verification mode.");
27
+ const content = {
28
+ authorization: authorization.entry.sha256,
29
+ input: captureFoundryInput(input.path),
30
+ capsule: capsuleFact,
31
+ commit,
32
+ verify,
33
+ };
34
+ const policy = {
35
+ task_id: context.taskId,
36
+ actor_id: context.actorId,
37
+ project_ref: context.accountIntent.projectRef,
38
+ user_id: context.accountIntent.userId,
39
+ state_code: 0,
40
+ dataset_type: value.dataset_type,
41
+ account_mode: String(handoff.account_mode ?? "ordinary"),
42
+ };
43
+ const projection = JSON.parse(JSON.stringify(content));
44
+ const contract = createBatchContract({
45
+ identity: { task: context.taskId, scope: scopeId },
46
+ content: projection,
47
+ policy,
48
+ });
49
+ const itemContract = createBatchItemContract({ item_id: scopeId, content: projection, policy });
50
+ return {
51
+ schema: "tiangong-foundry.owner-execution-request.v1",
52
+ scope_id: scopeId,
53
+ content,
54
+ policy,
55
+ contract,
56
+ item_contract: itemContract,
57
+ handoff_file: path.resolve(context.assetRoot, String(workflowObject(handoff.files).report)),
58
+ finalize_file: path.resolve(context.assetRoot, String(handoff.finalize_report)),
59
+ mutation_file: path.resolve(context.assetRoot, String(handoff.mutation_manifest)),
60
+ };
61
+ }
62
+ export async function prepareFoundryOwnerExecution(context, entries) {
63
+ const state = currentWorkflowState(context, entries), approval = state.authorization;
64
+ if (!approval || approval.value.status !== "sealed")
65
+ throw new FoundryContextError("execution_approval_required", "A current sealed approval is required.");
66
+ const request = buildRequest(context, approval);
67
+ return runFoundryTaskOperation(context, {
68
+ command: "dataset-workflow-execution-prepare",
69
+ options: { authorization: approval.entry.sha256 },
70
+ validateCurrent(index) {
71
+ if (currentWorkflowState(context, index).authorization?.entry.sha256 !== approval.entry.sha256)
72
+ throw new FoundryContextError("execution_approval_changed", "Approval changed before execution preparation.");
73
+ },
74
+ }, (operation) => {
75
+ operation.writeJson(`outputs/execution-requests/${request.scope_id}/${approval.entry.sha256}/owner-execution-request.json`, request);
76
+ return request;
77
+ });
78
+ }
79
+ export function readOwnerExecutionRequests(context, entries) {
80
+ return entries
81
+ .filter((entry) => entry.command === "dataset-workflow-execution-prepare" &&
82
+ path.basename(entry.path) === "owner-execution-request.json")
83
+ .map((entry) => {
84
+ const artifact = readWorkflowArtifact(context, entry);
85
+ const request = artifact.value;
86
+ if (request.schema !== "tiangong-foundry.owner-execution-request.v1" ||
87
+ request.policy.task_id !== context.taskId ||
88
+ request.policy.actor_id !== context.actorId)
89
+ throw new FoundryContextError("execution_request_invalid", "Execution request does not belong to this task.");
90
+ parseBatchItemContract(request.item_contract);
91
+ parseFoundryCommandSpec(request.content.commit);
92
+ parseFoundryCommandSpec(request.content.verify);
93
+ const content = JSON.parse(JSON.stringify(request.content));
94
+ if (request.scope_id !==
95
+ sha256Json({ task: context.taskId, type: request.policy.dataset_type }) ||
96
+ request.policy.project_ref !== context.accountIntent?.projectRef ||
97
+ request.policy.user_id !== context.accountIntent?.userId ||
98
+ request.policy.account_mode !== (context.accountIntent?.accountMode ?? "ordinary") ||
99
+ request.policy.state_code !== 0 ||
100
+ sha256Json(request.contract) !==
101
+ sha256Json(createBatchContract({
102
+ identity: { task: context.taskId, scope: request.scope_id },
103
+ content,
104
+ policy: request.policy,
105
+ })) ||
106
+ sha256Json(request.item_contract) !==
107
+ sha256Json(createBatchItemContract({ item_id: request.scope_id, content, policy: request.policy })))
108
+ throw new FoundryContextError("execution_request_invalid", "Owner request scope, account or batch projection changed.");
109
+ return { ...artifact, request };
110
+ });
111
+ }
112
+ export function ownerAttemptStore(context, scopeId, request) {
113
+ if (!/^[0-9a-f]{64}$/u.test(scopeId))
114
+ throw new FoundryContextError("execution_scope_invalid", "Execution scope id is invalid.");
115
+ const root = resolveFoundryOutput(context, `attempts/owner-v1/${scopeId}`);
116
+ const events = path.join(root, `events-${randomUUID()}.jsonl`), state = path.join(root, "state.jsonl");
117
+ const read = (file) => {
118
+ resolveFoundryOutput(context, file);
119
+ if (!fs.existsSync(file))
120
+ return [];
121
+ const stat = fs.lstatSync(file);
122
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 64 * 1024 * 1024)
123
+ throw new FoundryContextError("execution_attempt_invalid", "Attempt events are not a bounded regular file.");
124
+ const text = fs.readFileSync(file, "utf8");
125
+ if (text && !text.endsWith("\n"))
126
+ throw new FoundryContextError("execution_attempt_invalid", "Attempt events are incomplete; mutation replay is forbidden.");
127
+ return text
128
+ .split("\n")
129
+ .filter(Boolean)
130
+ .map((line) => {
131
+ const item = workflowObject(JSON.parse(line));
132
+ if (item.schema_version !== 1 || !item.request)
133
+ throw new FoundryContextError("execution_attempt_invalid", "Unknown attempt evidence cannot permit a mutation.");
134
+ if (item.item_contract)
135
+ parseBatchItemContract(item.item_contract);
136
+ return item;
137
+ });
138
+ };
139
+ const ledger = createScopeAttemptLedgerService({
140
+ paths: { state, events },
141
+ adapter: {
142
+ nowIso: () => new Date().toISOString(),
143
+ readJsonLines: read,
144
+ appendJsonLine(file, value) {
145
+ resolveFoundryOutput(context, file);
146
+ fs.mkdirSync(root, { recursive: true, mode: 0o700 });
147
+ const fd = fs.openSync(file, fs.constants.O_WRONLY |
148
+ fs.constants.O_APPEND |
149
+ fs.constants.O_CREAT |
150
+ fs.constants.O_NOFOLLOW, 0o600);
151
+ try {
152
+ fs.writeFileSync(fd, JSON.stringify({ ...value, request }) + "\n");
153
+ fs.fsyncSync(fd);
154
+ }
155
+ finally {
156
+ fs.closeSync(fd);
157
+ }
158
+ },
159
+ writeJsonLines() {
160
+ throw new FoundryContextError("execution_compaction_forbidden", "Attempt history remains append-only.");
161
+ },
162
+ },
163
+ });
164
+ return {
165
+ ledger,
166
+ readEvents: () => read(events),
167
+ record: (event, itemContract) => ledger.record({ event, itemContract }),
168
+ };
169
+ }
170
+ export async function markOwnerAttemptConsumed(context, artifact) {
171
+ const value = {
172
+ schema: "tiangong-foundry.owner-attempt-consumed.v1",
173
+ scope_id: artifact.request.scope_id,
174
+ request: { path: artifact.file, sha256: artifact.entry.sha256 },
175
+ item_contract: artifact.request.item_contract,
176
+ attempts: 1,
177
+ };
178
+ return runFoundryTaskOperation(context, { command: "dataset-workflow-execution-consume", options: { request: artifact.entry.sha256 } }, (operation) => {
179
+ operation.writeJson(`attempts/owner-v1/${artifact.request.scope_id}/consumed.json`, value);
180
+ return value;
181
+ });
182
+ }
183
+ export function inspectOwnerExecutions(context, entries) {
184
+ const requests = readOwnerExecutionRequests(context, entries), bySha = new Map(requests.map((item) => [item.entry.sha256, item]));
185
+ const consumed = new Map();
186
+ const consume = (value) => {
187
+ const ref = workflowObject(value.request), item = typeof ref.sha256 === "string" ? bySha.get(ref.sha256) : undefined;
188
+ if (!item ||
189
+ ref.path !== item.file ||
190
+ (value.scope_id !== undefined && value.scope_id !== item.request.scope_id))
191
+ throw new FoundryContextError("execution_attempt_invalid", "Consumed attempt does not bind a registered owner request.");
192
+ const contract = parseBatchItemContract(value.item_contract);
193
+ if (sha256Json(contract) !== sha256Json(item.request.item_contract))
194
+ throw new FoundryContextError("execution_attempt_invalid", "Consumed item contract changed.");
195
+ const prior = consumed.get(item.request.scope_id);
196
+ if (prior && prior.entry.sha256 !== item.entry.sha256)
197
+ throw new FoundryContextError("execution_attempt_invalid", "One scope has conflicting consumed requests.");
198
+ consumed.set(item.request.scope_id, item);
199
+ };
200
+ for (const entry of entries.filter((entry) => entry.command === "dataset-workflow-execution-consume" &&
201
+ path.basename(entry.path) === "consumed.json"))
202
+ consume(readWorkflowArtifact(context, entry).value);
203
+ const root = resolveFoundryOutput(context, "attempts");
204
+ if (fs.existsSync(root)) {
205
+ for (const name of fs.readdirSync(root))
206
+ if (name !== "owner-v1")
207
+ throw new FoundryContextError("execution_legacy_attempts", "Existing unknown attempts require their original readback recovery.");
208
+ const ownerRoot = resolveFoundryOutput(context, path.join(root, "owner-v1"));
209
+ if (fs.existsSync(ownerRoot))
210
+ for (const scope of fs.readdirSync(ownerRoot)) {
211
+ if (!/^[0-9a-f]{64}$/u.test(scope))
212
+ throw new FoundryContextError("execution_attempt_invalid", "Unknown execution scope directory.");
213
+ const directory = resolveFoundryOutput(context, path.join(ownerRoot, scope));
214
+ for (const name of fs.readdirSync(directory)) {
215
+ const file = resolveFoundryOutput(context, path.join(directory, name)), stat = fs.lstatSync(file);
216
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 64 * 1024 * 1024)
217
+ throw new FoundryContextError("execution_attempt_invalid", "Attempt state is not a bounded regular file.");
218
+ const bytes = fs.readFileSync(file, "utf8");
219
+ if (name === "consumed.json") {
220
+ const value = workflowObject(JSON.parse(bytes));
221
+ if (value.schema !== "tiangong-foundry.owner-attempt-consumed.v1")
222
+ throw new FoundryContextError("execution_attempt_invalid", "Unknown consumed marker.");
223
+ consume(value);
224
+ }
225
+ else if (/^events-[0-9a-f-]+\.jsonl$/u.test(name)) {
226
+ if (bytes && !bytes.endsWith("\n"))
227
+ throw new FoundryContextError("execution_attempt_invalid", "Incomplete attempt history cannot allow replay.");
228
+ for (const line of bytes.split("\n").filter(Boolean)) {
229
+ const event = workflowObject(JSON.parse(line));
230
+ if (event.schema_version !== 1 || !event.request)
231
+ throw new FoundryContextError("execution_attempt_invalid", "Unknown attempt event.");
232
+ if (["attempt_started", "attempt_failed", "attempt_succeeded"].includes(String(event.type)))
233
+ consume(event);
234
+ }
235
+ }
236
+ else
237
+ throw new FoundryContextError("execution_attempt_invalid", "Unknown attempt file.");
238
+ }
239
+ }
240
+ }
241
+ const results = entries
242
+ .filter((entry) => entry.command === "dataset-workflow-execution-result" &&
243
+ path.basename(entry.path) === "owner-execution-result.json")
244
+ .map((entry) => readWorkflowArtifact(context, entry));
245
+ const verified = new Map();
246
+ for (const result of results)
247
+ if (result.value.status === "verified" || result.value.status === "recovered") {
248
+ const item = bySha.get(String(result.value.request_sha256));
249
+ if (!item || consumed.get(item.request.scope_id)?.entry.sha256 !== item.entry.sha256)
250
+ throw new FoundryContextError("execution_result_invalid", "Execution result has no matching consumed request.");
251
+ const proof = workflowObject(result.value.readback);
252
+ if (proof.status !== "verified" ||
253
+ proof.request_scope !== item.request.scope_id ||
254
+ !Array.isArray(proof.blockers) ||
255
+ proof.blockers.length)
256
+ throw new FoundryContextError("execution_result_invalid", "Execution result has no verified readback.");
257
+ for (const raw of [proof.input, proof.report, proof.checks]) {
258
+ const fact = workflowObject(raw);
259
+ if (typeof fact.path !== "string")
260
+ throw new FoundryContextError("execution_result_invalid", "Readback content fact is missing.");
261
+ resolveFoundryOutput(context, fact.path);
262
+ const current = captureFoundryInput(fact.path);
263
+ if (current.sha256 !== fact.sha256 || current.bytes !== fact.bytes)
264
+ throw new FoundryContextError("execution_result_changed", "Recorded execution readback evidence changed.");
265
+ }
266
+ verified.set(item.request.scope_id, result);
267
+ }
268
+ return {
269
+ requests,
270
+ consumed,
271
+ verified,
272
+ pending: [...consumed.values()].filter((item) => !verified.has(item.request.scope_id)),
273
+ };
274
+ }
275
+ export function completedOwnerScopes(context, entries) {
276
+ const execution = inspectOwnerExecutions(context, entries), state = currentWorkflowState(context, entries);
277
+ const completed = new Map();
278
+ for (const raw of Array.isArray(state.finalization?.value.sets)
279
+ ? state.finalization.value.sets
280
+ : []) {
281
+ const scope = workflowObject(raw), type = String(scope.type), id = sha256Json({ task: context.taskId, type });
282
+ const done = execution.verified.get(id), requested = execution.consumed.get(id);
283
+ if (!done || !requested || typeof scope.final_rows !== "string")
284
+ continue;
285
+ const input = captureFoundryInput(scope.final_rows);
286
+ if (input.sha256 !== requested.request.content.input.sha256 ||
287
+ input.bytes !== requested.request.content.input.bytes)
288
+ throw new FoundryContextError("execution_completed_scope_changed", "A completed scope cannot acquire different rows through a new finalization.");
289
+ completed.set(type, scope);
290
+ }
291
+ const progressSha256 = sha256Json([...execution.verified.entries()].map(([id, value]) => [id, value.entry.sha256]).sort());
292
+ return { ...execution, completed, progressSha256 };
293
+ }
@@ -0,0 +1,22 @@
1
+ import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
2
+ import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
3
+ import { type FoundryAuthentication } from "./foundry-runtime-identity.ts";
4
+ import type { OwnerExecutionRequest } from "./foundry-owner-execution-store.ts";
5
+ export declare function readbackFoundryOwner(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, request: OwnerExecutionRequest, authentication?: FoundryAuthentication, commitReport?: string): Promise<{
6
+ output: string;
7
+ proof: {
8
+ schema: string;
9
+ status: string;
10
+ request_scope: string;
11
+ input: import("./foundry-runtime-context-types.ts").FoundryInputFact;
12
+ command: import("@tiangong-lca/cli/command-spec").FoundryCommandSpec;
13
+ report: import("./foundry-runtime-context-types.ts").FoundryInputFact | null;
14
+ checks: import("./foundry-runtime-context-types.ts").FoundryInputFact | null;
15
+ original_verification: {
16
+ report: import("./foundry-runtime-context-types.ts").FoundryInputFact | null;
17
+ checks: import("./foundry-runtime-context-types.ts").FoundryInputFact | null;
18
+ };
19
+ acceptance: import("./foundry-runtime-context-types.ts").FoundryInputFact | null;
20
+ blockers: Record<string, unknown>[];
21
+ };
22
+ }>;
@@ -0,0 +1,189 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { spawnSync } from "node:child_process";
4
+ import { randomUUID } from "node:crypto";
5
+ import { parseFoundryCommandSpec, commandSpecOptionValue } from "@tiangong-lca/cli/command-spec";
6
+ import { createFoundryCommandSpec } from "./foundry-command-spec.js";
7
+ import { FoundryContextError, resolveFoundryOutput, readFoundryInput, captureFoundryInput, } from "./foundry-runtime-context.js";
8
+ import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
9
+ import { verifyFoundryRuntimeIdentity, } from "./foundry-runtime-identity.js";
10
+ import { createFoundryAuthenticationEnvironment } from "./foundry-authentication-environment.js";
11
+ import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
12
+ import { createFoundryFinalizeOwners } from "./foundry-finalize-owners.js";
13
+ import { canonicalPayloadSha256 } from "./post-write-root-proof.js";
14
+ import { normalizeAllowedTraceHashDifference } from "./remote-verification-accepted-diff.js";
15
+ import { datasetIdentity, unwrapDatasetPayload, } from "./import-curation/internal/dataset-payload.js";
16
+ import { buildReferenceClosureBlockers } from "./import-curation/internal/workflow-reference-closure.js";
17
+ import { readRows } from "./import-curation/internal/runtime-io.js";
18
+ import { bundleRowTypes } from "./bundle-row-types.js";
19
+ import { workflowObject } from "./foundry-workflow-state.js";
20
+ import { acceptFoundryOwnerTraceDifference } from "./foundry-owner-trace-acceptance.js";
21
+ export async function readbackFoundryOwner(context, qualified, request, authentication = { mode: "oauth" }, commitReport) {
22
+ assertQualifiedFoundryRuntime(context, qualified);
23
+ const identity = verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
24
+ if (identity.receipt.project.project_ref !== request.policy.project_ref ||
25
+ identity.receipt.identity.user_id !== request.policy.user_id)
26
+ throw new FoundryContextError("execution_account_mismatch", "Readback account differs from the recorded owner intent.");
27
+ const source = parseFoundryCommandSpec(request.content.verify), cli = resolveInstalledTiangongLcaCliPackage();
28
+ if (source.executable !== process.execPath ||
29
+ source.argv[0] !== cli.binPath ||
30
+ source.argv[1] !== "dataset" ||
31
+ source.argv[2] !== "verify-remote" ||
32
+ !source.argv.includes("--compare-root-payload") ||
33
+ source.argv.includes("--commit") ||
34
+ commandSpecOptionValue(source, "--input") !== request.content.input.path ||
35
+ commandSpecOptionValue(source, "--target-user-id") !== request.policy.user_id ||
36
+ commandSpecOptionValue(source, "--state-code") !== "0")
37
+ throw new FoundryContextError("execution_readback_invalid", "Readback must use the recorded exact owner rows, account and state.");
38
+ readFoundryInput(context, request.content.input.path);
39
+ const output = resolveFoundryOutput(context, `outputs/owner-readback/${randomUUID()}`);
40
+ fs.mkdirSync(output, { recursive: true, mode: 0o700 });
41
+ const argv = [...source.argv], outIndex = argv.indexOf("--out-dir");
42
+ if (outIndex < 0 || argv.lastIndexOf("--out-dir") !== outIndex)
43
+ throw new FoundryContextError("execution_readback_invalid", "Readback output must be explicit.");
44
+ argv[outIndex + 1] = output;
45
+ const spec = createFoundryCommandSpec({
46
+ executable: source.executable,
47
+ argv,
48
+ binding: { artifacts: [...source.binding.artifacts] },
49
+ });
50
+ const environment = createFoundryAuthenticationEnvironment(authentication, context.accountIntent?.sessionReference, process.env);
51
+ environment.FOUNDRY_ACCOUNT_MODE = request.policy.account_mode;
52
+ try {
53
+ const result = spawnSync(spec.executable, [...spec.argv], {
54
+ cwd: output,
55
+ env: environment,
56
+ shell: false,
57
+ windowsHide: true,
58
+ encoding: "utf8",
59
+ timeout: 120_000,
60
+ maxBuffer: 16 * 1024 * 1024,
61
+ });
62
+ fs.writeFileSync(path.join(output, "stdout.json"), result.stdout ?? "");
63
+ fs.writeFileSync(path.join(output, "stderr.log"), result.stderr ?? "");
64
+ const blockers = [];
65
+ let report = {}, reportFile = null, checksFile = null;
66
+ try {
67
+ report = workflowObject(JSON.parse(result.stdout));
68
+ const files = workflowObject(report.files);
69
+ for (const name of ["report", "checks"]) {
70
+ const file = typeof files[name] === "string" ? resolveFoundryOutput(context, files[name]) : null;
71
+ if (!file ||
72
+ path.relative(output, file).startsWith("..") ||
73
+ !fs.lstatSync(file).isFile() ||
74
+ fs.lstatSync(file).isSymbolicLink())
75
+ throw new Error("Readback files must be fresh and contained.");
76
+ if (name === "report")
77
+ reportFile = file;
78
+ else
79
+ checksFile = file;
80
+ }
81
+ if (canonicalPayloadSha256(JSON.parse(fs.readFileSync(reportFile, "utf8"))) !==
82
+ canonicalPayloadSha256(report))
83
+ throw new Error("Readback stdout and report differ.");
84
+ }
85
+ catch {
86
+ blockers.push({
87
+ code: "readback_report_invalid",
88
+ message: "Readback needs matching fresh stdout, report and check artifacts.",
89
+ });
90
+ }
91
+ const original = {
92
+ report: reportFile ? captureFoundryInput(reportFile) : null,
93
+ checks: checksFile ? captureFoundryInput(checksFile) : null,
94
+ };
95
+ let acceptance = null;
96
+ if (!blockers.length &&
97
+ reportFile &&
98
+ !result.error &&
99
+ !result.signal &&
100
+ // The published CLI uses exit 1 for a completed, blocked remote report.
101
+ result.status === 1 &&
102
+ request.policy.account_mode === "ordinary") {
103
+ const accepted = acceptFoundryOwnerTraceDifference(context, qualified, request, reportFile, output, environment);
104
+ if (accepted.accepted) {
105
+ reportFile = resolveFoundryOutput(context, accepted.verifyReportPath);
106
+ report = workflowObject(JSON.parse(fs.readFileSync(reportFile, "utf8")));
107
+ checksFile = resolveFoundryOutput(context, String(workflowObject(report.files).checks));
108
+ acceptance = captureFoundryInput(resolveFoundryOutput(context, accepted.acceptanceReportPath));
109
+ }
110
+ }
111
+ if (result.error || result.signal || (result.status !== 0 && !acceptance))
112
+ blockers.push({ code: "readback_cli_failed", exit_code: result.status });
113
+ if (!blockers.length && reportFile) {
114
+ const rows = readRows(request.content.input.path).map((row) => unwrapDatasetPayload(row, request.policy.dataset_type));
115
+ const type = request.policy.dataset_type;
116
+ if (!Object.hasOwn(bundleRowTypes, type))
117
+ throw new FoundryContextError("execution_readback_invalid", "Unsupported recorded dataset type.");
118
+ const intended = rows.map((row, rowIndex) => {
119
+ const id = datasetIdentity(row, rowIndex, type), normalized = normalizeAllowedTraceHashDifference(row);
120
+ return {
121
+ rowIndex,
122
+ table: bundleRowTypes[type].plural,
123
+ id: id.id,
124
+ version: id.version,
125
+ payloadSha256: canonicalPayloadSha256(row),
126
+ acceptedNormalizedPayloadSha256: normalized.removed_paths.length
127
+ ? normalized.normalized_sha256
128
+ : null,
129
+ acceptedNormalizedRemovedPaths: normalized.removed_paths,
130
+ };
131
+ });
132
+ const owners = createFoundryFinalizeOwners(context, qualified, output, {
133
+ environment,
134
+ tidasExecutable: qualified.tidas.executable_path,
135
+ });
136
+ owners.closeout.validatePostWriteVerifyForCloseout({
137
+ verifyReport: report,
138
+ verifyReportPath: reportFile,
139
+ finalRowsFile: request.content.input.path,
140
+ expectedRows: rows.length,
141
+ targetUserId: request.policy.user_id,
142
+ expectedStateCode: 0,
143
+ intendedRoots: intended,
144
+ allowTraceHashOnlyNormalization: request.policy.account_mode !== "production-test",
145
+ blockers,
146
+ });
147
+ blockers.push(...buildReferenceClosureBlockers({
148
+ repoRoot: context.assetRoot,
149
+ rows,
150
+ datasetType: type,
151
+ remoteVerifyArtifact: { value: report },
152
+ allowAccountLocalSupportAndElementary: false,
153
+ }));
154
+ if (commitReport) {
155
+ const closed = workflowObject(owners.closeout.runDatasetPostWriteCloseout({
156
+ handoffPlan: request.handoff_file,
157
+ commitReport,
158
+ postWriteVerifyReport: reportFile,
159
+ rowsFile: request.content.input.path,
160
+ finalizeReport: request.finalize_file,
161
+ mutationManifest: request.mutation_file,
162
+ outDir: path.join(output, "closeout"),
163
+ targetUserId: request.policy.user_id,
164
+ stateCode: "0",
165
+ }));
166
+ if (closed.status !== "completed")
167
+ blockers.push({ code: "owner_closeout_blocked", report: closed });
168
+ }
169
+ }
170
+ readFoundryInput(context, request.content.input.path);
171
+ const proof = {
172
+ schema: "tiangong-foundry.owner-readback.v1",
173
+ status: blockers.length ? "unresolved" : "verified",
174
+ request_scope: request.scope_id,
175
+ input: request.content.input,
176
+ command: spec,
177
+ report: reportFile ? captureFoundryInput(reportFile) : null,
178
+ checks: checksFile ? captureFoundryInput(checksFile) : null,
179
+ original_verification: original,
180
+ acceptance,
181
+ blockers,
182
+ };
183
+ fs.writeFileSync(path.join(output, "owner-readback.json"), JSON.stringify(proof, null, 2) + "\n");
184
+ return { output, proof };
185
+ }
186
+ finally {
187
+ delete environment.TIANGONG_LCA_ACCESS_TOKEN;
188
+ }
189
+ }
@@ -0,0 +1,15 @@
1
+ import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
2
+ import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
3
+ import type { OwnerExecutionRequest } from "./foundry-owner-execution-store.ts";
4
+ export declare function acceptFoundryOwnerTraceDifference(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, request: OwnerExecutionRequest, verifyReportPath: string, output: string, environment: NodeJS.ProcessEnv): {
5
+ [key: string]: unknown;
6
+ accepted: false;
7
+ reason: string;
8
+ } | {
9
+ accepted: true;
10
+ verifyReportPath: string;
11
+ acceptanceReportPath: string;
12
+ evidence: {
13
+ [x: string]: unknown;
14
+ }[];
15
+ };
@@ -0,0 +1,68 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { randomUUID } from "node:crypto";
4
+ import { spawnSync } from "node:child_process";
5
+ import { acceptTraceHashOnlyRemoteVerificationMismatch } from "./remote-verification-accepted-diff.js";
6
+ import { readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
7
+ import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
8
+ import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
9
+ import { createFoundryCommandSpec } from "./foundry-command-spec.js";
10
+ import { workflowObject } from "./foundry-workflow-state.js";
11
+ import { unwrapDatasetPayload } from "./import-curation/internal/dataset-payload.js";
12
+ export function acceptFoundryOwnerTraceDifference(context, qualified, request, verifyReportPath, output, environment) {
13
+ if (request.policy.account_mode !== "ordinary" ||
14
+ (context.accountIntent?.accountMode ?? "ordinary") !== "ordinary")
15
+ return { accepted: false, reason: "production_test_requires_exact_payload" };
16
+ return acceptTraceHashOnlyRemoteVerificationMismatch({
17
+ verifyReportPath,
18
+ outDir: output,
19
+ repoRoot: context.assetRoot,
20
+ runCliGet({ table, id, version, outDir }) {
21
+ assertQualifiedFoundryRuntime(context, qualified);
22
+ readFoundryInput(context, request.content.input.path);
23
+ const type = table === "flows" ? "flow" : table === "processes" ? "process" : null;
24
+ if (!type)
25
+ return { ok: false, error: "Unsupported root table." };
26
+ const directory = resolveFoundryOutput(context, outDir);
27
+ fs.mkdirSync(directory, { recursive: true, mode: 0o700 });
28
+ const stem = path.join(directory, randomUUID()), cli = resolveInstalledTiangongLcaCliPackage();
29
+ const command = createFoundryCommandSpec({
30
+ executable: process.execPath,
31
+ argv: [cli.binPath, type, "get", "--id", id, "--version", version, "--json"],
32
+ binding: { artifacts: [{ ...request.content.input, role: "final_rows" }] },
33
+ });
34
+ fs.writeFileSync(`${stem}.command.json`, JSON.stringify(command, null, 2) + "\n");
35
+ const result = spawnSync(command.executable, [...command.argv], {
36
+ cwd: directory,
37
+ env: environment,
38
+ shell: false,
39
+ windowsHide: true,
40
+ encoding: "utf8",
41
+ timeout: 120_000,
42
+ maxBuffer: 16 * 1024 * 1024,
43
+ });
44
+ fs.writeFileSync(`${stem}.stdout.json`, result.stdout ?? "");
45
+ fs.writeFileSync(`${stem}.stderr.log`, result.stderr ?? "");
46
+ readFoundryInput(context, request.content.input.path);
47
+ let payload = null;
48
+ try {
49
+ const parsed = workflowObject(JSON.parse(result.stdout));
50
+ const candidate = workflowObject(unwrapDatasetPayload(parsed[type] ?? parsed.payload ?? parsed, type));
51
+ if (Object.hasOwn(candidate, `${type}DataSet`))
52
+ payload = candidate;
53
+ }
54
+ catch {
55
+ /* Retain the unsuccessful fresh get as diagnostic evidence. */
56
+ }
57
+ return {
58
+ ok: !result.error && !result.signal && result.status === 0 && Boolean(payload),
59
+ payload,
60
+ command: command.display,
61
+ executable: command.executable,
62
+ exit_code: result.status ?? 1,
63
+ stdout_log: `${stem}.stdout.json`,
64
+ stderr_log: `${stem}.stderr.log`,
65
+ };
66
+ },
67
+ });
68
+ }
@@ -0,0 +1,56 @@
1
+ export declare const FOUNDRY_PACKAGE_DESCRIPTOR_SCHEMA: "tiangong-foundry.package-descriptor.v1";
2
+ export declare const foundryPackageDescriptorPath: "package-dist/assets/foundry-package-descriptor.json";
3
+ export declare const foundryPackageStaticFiles: readonly ["package-dist/", "specs/import-profiles.json", "specs/prewrite-content-policy.json", "specs/canonical-support/flow-properties-unit-groups.json", "specs/schemas/authorization-derivation.schema.json", "specs/schemas/execution-context.schema.json", "specs/schemas/foundry-facade-request-index.schema.json", "specs/schemas/foundry-operation-result.schema.json", "specs/schemas/foundry-package-descriptor.schema.json", "specs/schemas/foundry-task-start.schema.json", "specs/schemas/foundry-semantic-input.schema.json", "specs/schemas/foundry-authorization-input.schema.json", "specs/schemas/foundry-workspace-migration-plan.schema.json", "specs/schemas/foundry-workspace-migration-transfer-plan.schema.json", "specs/schemas/foundry-migration-transfer-receipt.schema.json", "specs/schemas/foundry-workspace-migration-pending.schema.json", "specs/schemas/foundry-migration-adoption-plan.schema.json", "specs/schemas/foundry-migration-activation.schema.json", "specs/schemas/foundry-workspace-v2.schema.json", "specs/schemas/foundry-runtime-selection.schema.json", "specs/schemas/foundry-managed-runtime.schema.json", "specs/schemas/runtime-qualification.schema.json", "specs/schemas/task-authorization.schema.json", "specs/schemas/tidas-runtime-expectation.schema.json", "docs/architecture.md", "docs/package-distribution-contract.md", "docs/foundry-task-contracts.md", "docs/public-runtime-contract.md", "docs/runtime-context-contract.md", "docs/workspace-migration-contract.md", "docs/safety-policy.md", "docs/task-authorization-contract.md", "docs/import-profiles/bafu/constraints.md", "docs/import-profiles/bafu/leaf-process-classification-authoring.md", "docs/import-profiles/bafu/profile.md", "docs/import-profiles/uslci/constraints.md", "docs/import-profiles/uslci/profile.md", "docs/uslci-import-runbook.md", "docs/import-profiles/worldsteel/constraints.md", "docs/import-profiles/worldsteel/import-coverage.md", "docs/import-profiles/worldsteel/import-plan.md", "docs/import-profiles/worldsteel/profile.md", "README.md", "LICENSE"];
4
+ declare const packageName = "@tiangong-lca/foundry";
5
+ declare const packageVersion = "0.1.2";
6
+ declare const cliPackageName = "@tiangong-lca/cli";
7
+ declare const cliPackageVersion = "0.1.12";
8
+ declare const packageBin = "package-dist/scripts/package-entry.js";
9
+ declare const packageApi = "package-dist/scripts/public-api.js";
10
+ declare const packageTypes = "package-dist/scripts/public-api.d.ts";
11
+ declare const supportedPlatforms: readonly ["linux-x64", "linux-arm64", "darwin-arm64", "win32-x64"];
12
+ declare const protocolSchemas: readonly ["tiangong-foundry.operation-result.v1", "tiangong-foundry.task-start.v1", "tiangong-foundry.semantic-input.v1", "tiangong-foundry.authorization-input.v1", "tiangong-foundry.facade-request-index.v1", "tiangong-foundry.workspace-migration-plan.v1", "tiangong-foundry.workspace-migration-transfer-plan.v2", "tiangong-foundry.migration-transfer-receipt.v1", "tiangong-foundry.workspace-migration-pending.v1", "tiangong-foundry.migration-adoption-plan.v1", "tiangong-foundry.migration-activation.v1", "tiangong-foundry.workspace.v2", "tiangong-foundry.workspace-runtime-selection.v1", "tiangong-foundry.managed-runtime.v1", "tiangong-foundry.runtime-qualification.v1", "tiangong-foundry.tidas-runtime-expectation.v1", "tiangong-foundry.execution-context.v1", "tiangong-foundry.authorization-derivation.v1", "tiangong-foundry.task-authorization.v1"];
13
+ export interface FoundryPackageFileFact {
14
+ readonly path: string;
15
+ readonly bytes: number;
16
+ readonly sha256: string;
17
+ }
18
+ export interface FoundryPackageDescriptor {
19
+ readonly schema: typeof FOUNDRY_PACKAGE_DESCRIPTOR_SCHEMA;
20
+ readonly package: Readonly<{
21
+ name: typeof packageName;
22
+ version: typeof packageVersion;
23
+ cli_dependency: Readonly<{
24
+ name: typeof cliPackageName;
25
+ version: typeof cliPackageVersion;
26
+ }>;
27
+ bin: typeof packageBin;
28
+ public_api: typeof packageApi;
29
+ types: typeof packageTypes;
30
+ }>;
31
+ readonly runtime: Readonly<{
32
+ layout_schema: "tiangong-foundry.runtime-layout.v2";
33
+ supported_platforms: readonly (typeof supportedPlatforms)[number][];
34
+ workspace_read_schemas: readonly [
35
+ "tiangong-foundry.workspace.v1",
36
+ "tiangong-foundry.workspace.v2"
37
+ ];
38
+ workspace_write_schemas: readonly [
39
+ "tiangong-foundry.workspace.v1",
40
+ "tiangong-foundry.workspace.v2"
41
+ ];
42
+ workspace_write_schema: "tiangong-foundry.workspace.v1";
43
+ protocol_schemas: readonly (typeof protocolSchemas)[number][];
44
+ }>;
45
+ readonly files: readonly Readonly<FoundryPackageFileFact>[];
46
+ readonly files_sha256: string;
47
+ }
48
+ export declare class FoundryPackageError extends Error {
49
+ readonly code: string;
50
+ constructor(code: string, message: string);
51
+ }
52
+ export declare function assertFoundryPackageDescriptor(value: unknown): FoundryPackageDescriptor;
53
+ export declare function assertFoundryPackage(packageRoot: string): FoundryPackageDescriptor;
54
+ export declare function createFoundryPackageDescriptor(files: readonly FoundryPackageFileFact[]): FoundryPackageDescriptor;
55
+ export declare function captureFoundryPackageFile(packageRoot: string, relative: string): Readonly<FoundryPackageFileFact>;
56
+ export {};