@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,148 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { captureFoundryInput, FoundryContextError } from "./foundry-runtime-context.js";
4
+ import { sha256Json } from "./identity-preflight-proof.js";
5
+ export const FOUNDRY_WORKSPACE_MIGRATION_PLAN_SCHEMA = "tiangong-foundry.workspace-migration-plan.v1";
6
+ const maxEntries = 10_000;
7
+ const maxDepth = 64;
8
+ const maxHashedFileBytes = 64 * 1024 * 1024;
9
+ const maxHashedTreeBytes = 256 * 1024 * 1024;
10
+ export { migrationCredentialPath } from "./foundry-private-path.js";
11
+ import { migrationCredentialPath } from "./foundry-private-path.js";
12
+ function classify(relative) {
13
+ if (relative === "workspace.json" || relative.startsWith("state/"))
14
+ return "workspace-control";
15
+ if (/(?:^|\/)attempts?(?:\/|$)|UNKNOWN_DO_NOT_REPLAY|dispatch/iu.test(relative))
16
+ return "attempted-or-unknown";
17
+ if (/(?:^|\/)(?:authorization|account-intent)(?:\.|\/|$)/iu.test(relative))
18
+ return "authorization-or-account";
19
+ if (/(?:^|\/)(?:done|closeout|completion|success)(?:\.|\/|$)/iu.test(relative))
20
+ return "terminal-success";
21
+ if (/(?:^|\/)(?:outputs|checkpoints|artifact-index)(?:\.|\/|$)/iu.test(relative))
22
+ return "local-preparation";
23
+ return "unclassified";
24
+ }
25
+ function markerSchema(root) {
26
+ const file = path.join(root, "workspace.json");
27
+ if (!fs.existsSync(file))
28
+ return null;
29
+ const stat = fs.lstatSync(file);
30
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 64 * 1024)
31
+ throw new FoundryContextError("migration_marker_invalid", "Workspace marker must be a bounded regular file.");
32
+ try {
33
+ const value = JSON.parse(fs.readFileSync(file, "utf8"));
34
+ return value &&
35
+ typeof value === "object" &&
36
+ !Array.isArray(value) &&
37
+ typeof value.schema === "string"
38
+ ? value.schema
39
+ : null;
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ }
45
+ export function inventoryFoundryMigrationTree(root, options = {}) {
46
+ const selectedSession = options.sessionReference && fs.existsSync(options.sessionReference)
47
+ ? fs.realpathSync(options.sessionReference)
48
+ : options.sessionReference;
49
+ if (!fs.existsSync(root))
50
+ return Object.freeze({
51
+ exists: false,
52
+ entries: Object.freeze([]),
53
+ tree_sha256: sha256Json([]),
54
+ });
55
+ const stat = fs.lstatSync(root);
56
+ if (!stat.isDirectory() || stat.isSymbolicLink())
57
+ throw new FoundryContextError("migration_root_invalid", "Migration state must be a real directory.");
58
+ const entries = [];
59
+ let hashedBytes = 0;
60
+ const walk = (directory, depth) => {
61
+ if (depth > maxDepth)
62
+ throw new FoundryContextError("migration_depth_limit", "Migration inventory exceeds its directory-depth limit.");
63
+ for (const name of fs.readdirSync(directory).sort()) {
64
+ const file = path.join(directory, name);
65
+ const relative = path.relative(root, file).split(path.sep).join("/");
66
+ const stat = fs.lstatSync(file);
67
+ if (stat.isSymbolicLink())
68
+ throw new FoundryContextError("migration_symlink_unsupported", "Migration inventory refuses symbolic links or junction-like state.");
69
+ if (stat.isDirectory()) {
70
+ entries.push({
71
+ path: relative,
72
+ kind: "directory",
73
+ bytes: null,
74
+ sha256: null,
75
+ state_class: classify(`${relative}/`),
76
+ });
77
+ if (entries.length > maxEntries)
78
+ throw new FoundryContextError("migration_inventory_limit", "Migration inventory exceeds its entry limit.");
79
+ walk(file, depth + 1);
80
+ continue;
81
+ }
82
+ if (!stat.isFile())
83
+ throw new FoundryContextError("migration_entry_unsupported", "Migration inventory supports only regular files and directories.");
84
+ const privateFile = migrationCredentialPath(relative) || file === selectedSession;
85
+ const omitHash = privateFile || stat.size > maxHashedFileBytes;
86
+ if (!omitHash) {
87
+ hashedBytes += stat.size;
88
+ if (hashedBytes > maxHashedTreeBytes)
89
+ throw new FoundryContextError("migration_byte_limit", "Migration inventory exceeds its total hashing byte limit.");
90
+ }
91
+ const fact = omitHash ? null : captureFoundryInput(file);
92
+ entries.push({
93
+ path: relative,
94
+ kind: "file",
95
+ bytes: stat.size,
96
+ sha256: fact?.sha256 ?? null,
97
+ state_class: privateFile ? "authorization-or-account" : classify(relative),
98
+ });
99
+ if (entries.length > maxEntries)
100
+ throw new FoundryContextError("migration_inventory_limit", "Migration inventory exceeds its entry limit.");
101
+ }
102
+ };
103
+ walk(root, 0);
104
+ const immutable = Object.freeze(entries.map((entry) => Object.freeze(entry)));
105
+ return Object.freeze({ exists: true, entries: immutable, tree_sha256: sha256Json(immutable) });
106
+ }
107
+ /** Deterministic read-only inventory. W10 owns any application or rollback. */
108
+ export function inventoryFoundryWorkspace(workspace, options = {}) {
109
+ if (options.sessionReference !== undefined &&
110
+ (typeof options.sessionReference !== "string" || !path.isAbsolute(options.sessionReference)))
111
+ throw new FoundryContextError("migration_session_reference_invalid", "A selected private session reference must be absolute.");
112
+ const selectedSession = options.sessionReference && fs.existsSync(options.sessionReference)
113
+ ? fs.realpathSync(options.sessionReference)
114
+ : options.sessionReference;
115
+ const workspaceRoot = fs.existsSync(workspace)
116
+ ? fs.realpathSync(workspace)
117
+ : path.resolve(workspace);
118
+ if (fs.existsSync(workspaceRoot) && !fs.statSync(workspaceRoot).isDirectory())
119
+ throw new FoundryContextError("migration_workspace_invalid", "Migration workspace must be a directory.");
120
+ const root = path.join(workspaceRoot, ".foundry");
121
+ if (!fs.existsSync(root))
122
+ return Object.freeze({
123
+ schema: FOUNDRY_WORKSPACE_MIGRATION_PLAN_SCHEMA,
124
+ workspace_root: workspaceRoot,
125
+ foundry_root_exists: false,
126
+ marker_schema: null,
127
+ disposition: "no_state",
128
+ write_allowed: false,
129
+ entries: Object.freeze([]),
130
+ tree_sha256: sha256Json([]),
131
+ });
132
+ const rootStat = fs.lstatSync(root);
133
+ if (!rootStat.isDirectory() || rootStat.isSymbolicLink())
134
+ throw new FoundryContextError("migration_root_invalid", "Foundry state root must be a real directory.");
135
+ const tree = inventoryFoundryMigrationTree(root, options);
136
+ const schema = path.join(root, "workspace.json") === selectedSession ? null : markerSchema(root);
137
+ const immutableEntries = tree.entries;
138
+ return Object.freeze({
139
+ schema: FOUNDRY_WORKSPACE_MIGRATION_PLAN_SCHEMA,
140
+ workspace_root: workspaceRoot,
141
+ foundry_root_exists: true,
142
+ marker_schema: schema,
143
+ disposition: schema === "tiangong-foundry.workspace.v1" ? "current_layout" : "explicit_migration_required",
144
+ write_allowed: false,
145
+ entries: immutableEntries,
146
+ tree_sha256: sha256Json(immutableEntries),
147
+ });
148
+ }
@@ -0,0 +1,48 @@
1
+ import { type FoundryRuntimeContext, type FoundryInputFact } from "./foundry-runtime-context.ts";
2
+ import { type FoundryWorkspaceMigrationPlan, type FoundryMigrationTree } from "./foundry-migration-inventory.ts";
3
+ import { type MigrationStageEvidence } from "./foundry-migration-stage.ts";
4
+ export type { MigrationStageEvidence } from "./foundry-migration-stage.ts";
5
+ export declare const FOUNDRY_MIGRATION_TRANSFER_PLAN_SCHEMA: "tiangong-foundry.workspace-migration-transfer-plan.v2";
6
+ export interface FoundryMigrationTransferPlan {
7
+ readonly schema: typeof FOUNDRY_MIGRATION_TRANSFER_PLAN_SCHEMA;
8
+ readonly request_id: string;
9
+ readonly actor_id: string;
10
+ readonly destination_workspace: string;
11
+ readonly account_intent: {
12
+ readonly project_ref: string;
13
+ readonly user_id: string;
14
+ } | null;
15
+ readonly runtime: {
16
+ readonly package_name: string;
17
+ readonly package_version: string;
18
+ readonly manifest_sha256: string;
19
+ readonly entry_sha256: string;
20
+ readonly platform: string;
21
+ readonly scope: "entry-only" | "installed-package";
22
+ readonly payload_sha256: string | null;
23
+ };
24
+ readonly source_inventory: FoundryWorkspaceMigrationPlan;
25
+ readonly source_queue: FoundryMigrationTree;
26
+ readonly external_inputs: readonly FoundryInputFact[];
27
+ readonly stages: readonly MigrationStageEvidence[];
28
+ readonly omitted_private_paths: readonly string[];
29
+ readonly blockers: readonly {
30
+ readonly code: string;
31
+ readonly path: string | null;
32
+ }[];
33
+ readonly source_must_remain_unchanged: true;
34
+ readonly remote_write_allowed: false;
35
+ readonly plan_sha256: string;
36
+ }
37
+ export interface FoundryMigrationPlanningOptions {
38
+ readonly sourceWorkspace: string;
39
+ readonly requestId: string;
40
+ readonly actorId: string;
41
+ readonly stageManifests?: readonly string[];
42
+ readonly externalInputs?: readonly string[];
43
+ }
44
+ /** Read-only planning. Stage labels interpret retained evidence; they grant no execution authority. */
45
+ export declare function planFoundryWorkspaceMigration(context: FoundryRuntimeContext, options: FoundryMigrationPlanningOptions, pendingPlanSha256?: string): FoundryMigrationTransferPlan;
46
+ /** Untrusted serialized plans are accepted only when a fresh independent reconstruction matches every field. */
47
+ export declare function assertFoundryMigrationJson(value: unknown): void;
48
+ export declare function revalidateFoundryMigrationPlan(context: FoundryRuntimeContext, options: FoundryMigrationPlanningOptions, value: unknown, pendingPlanSha256?: string): FoundryMigrationTransferPlan;
@@ -0,0 +1,234 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { assertFoundryRuntimeContext, FoundryContextError, captureFoundryInput, pendingFoundryMigration, } from "./foundry-runtime-context.js";
5
+ import { inventoryFoundryWorkspace, migrationCredentialPath, inventoryFoundryMigrationTree, } from "./foundry-migration-inventory.js";
6
+ import { inspectFoundryMigrationStage, normalizeMigrationStagePath, } from "./foundry-migration-stage.js";
7
+ import { sha256Json } from "./identity-preflight-proof.js";
8
+ import { describeFoundryRuntime } from "./foundry-runtime-paths.js";
9
+ import { assertFoundryPackage } from "./foundry-package-contract.js";
10
+ import { readFoundryMigrationAuthority } from "./foundry-migration-authority.js";
11
+ import { transferRead } from "./foundry-migration-transfer-io.js";
12
+ export const FOUNDRY_MIGRATION_TRANSFER_PLAN_SCHEMA = "tiangong-foundry.workspace-migration-transfer-plan.v2";
13
+ const maxDocumentBytes = 8 * 1024 * 1024;
14
+ function fail(code, message) {
15
+ throw new FoundryContextError(code, message);
16
+ }
17
+ function record(value) {
18
+ if (!value || typeof value !== "object" || Array.isArray(value))
19
+ fail("migration_document_invalid", "Migration evidence must be a JSON object.");
20
+ return value;
21
+ }
22
+ function inside(root, target) {
23
+ const relative = path.relative(root, target);
24
+ return (!relative ||
25
+ (!path.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${path.sep}`)));
26
+ }
27
+ function runtimeFacts(context) {
28
+ try {
29
+ const actual = describeFoundryRuntime(pathToFileURL(context.runtime.entryPath).href);
30
+ if (sha256Json(actual) !== sha256Json(context.runtime))
31
+ fail("migration_runtime_changed", "Runtime identity changed after context construction.");
32
+ const packaged = actual.entryRepoRelativePath.startsWith("package-dist/");
33
+ return Object.freeze({
34
+ package_name: actual.packageName,
35
+ package_version: actual.packageVersion,
36
+ manifest_sha256: actual.packageManifestSha256,
37
+ entry_sha256: actual.entrySha256,
38
+ platform: context.platform,
39
+ scope: packaged ? "installed-package" : "entry-only",
40
+ payload_sha256: packaged ? assertFoundryPackage(actual.runtimeRoot).files_sha256 : null,
41
+ });
42
+ }
43
+ catch {
44
+ return fail("migration_runtime_changed", "The selected runtime no longer matches its captured identity or package closure.");
45
+ }
46
+ }
47
+ /** Read-only planning. Stage labels interpret retained evidence; they grant no execution authority. */
48
+ export function planFoundryWorkspaceMigration(context, options, pendingPlanSha256) {
49
+ assertFoundryRuntimeContext(context);
50
+ const runtime = runtimeFacts(context);
51
+ if (typeof options.actorId !== "string" ||
52
+ typeof options.requestId !== "string" ||
53
+ typeof options.sourceWorkspace !== "string" ||
54
+ !path.isAbsolute(options.sourceWorkspace) ||
55
+ !/^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u.test(options.actorId) ||
56
+ !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/u.test(options.requestId))
57
+ fail("migration_intent_invalid", "Migration planning requires explicit request and actor identifiers.");
58
+ const selection = options.stageManifests ?? [];
59
+ if (!Array.isArray(selection) ||
60
+ selection.some((item) => typeof item !== "string") ||
61
+ selection.length > 128)
62
+ fail("migration_evidence_invalid", "Stage selections must be unique and bounded.");
63
+ const selected = selection.map(normalizeMigrationStagePath);
64
+ if (new Set(selected).size !== selected.length)
65
+ fail("migration_evidence_invalid", "Stage selections contain canonical duplicate paths.");
66
+ const source = fs.realpathSync(options.sourceWorkspace);
67
+ if (inside(source, context.workspaceRoot) || inside(context.workspaceRoot, source))
68
+ fail("migration_roots_overlap", "Migration source and destination must be disjoint.");
69
+ if (fs.existsSync(context.controlRoot) &&
70
+ (!pendingPlanSha256 ||
71
+ (pendingFoundryMigration(context) !== pendingPlanSha256 &&
72
+ context.migration?.plan_sha256 !== pendingPlanSha256)))
73
+ fail("migration_destination_exists", "Choose a destination without existing Foundry state.");
74
+ const privateOptions = { sessionReference: context.accountIntent?.sessionReference };
75
+ const inventory = inventoryFoundryWorkspace(source, privateOptions);
76
+ const queue = inventoryFoundryMigrationTree(path.join(source, "tasks"), privateOptions);
77
+ const inputs = options.externalInputs ?? [];
78
+ if (!Array.isArray(inputs) ||
79
+ inputs.length > 1000 ||
80
+ inputs.some((file) => typeof file !== "string" || !path.isAbsolute(file)))
81
+ fail("migration_inputs_invalid", "External inputs must be explicitly selected absolute files.");
82
+ const externalInputs = inputs
83
+ .map((file) => {
84
+ const canonical = fs.realpathSync(file);
85
+ if (migrationCredentialPath(file) ||
86
+ (privateOptions.sessionReference &&
87
+ fs.existsSync(privateOptions.sessionReference) &&
88
+ canonical === fs.realpathSync(privateOptions.sessionReference)))
89
+ fail("migration_credential_forbidden", "A private file cannot be selected as external migration data.");
90
+ if (inside(context.workspaceRoot, canonical))
91
+ fail("migration_roots_overlap", "External inputs cannot be inside the destination.");
92
+ const stat = fs.lstatSync(file);
93
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 64 * 1024 * 1024)
94
+ fail("migration_inputs_invalid", "External inputs must be bounded regular files.");
95
+ return captureFoundryInput(file);
96
+ })
97
+ .sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
98
+ if (new Set(externalInputs.map((f) => f.path)).size !== externalInputs.length)
99
+ fail("migration_inputs_invalid", "External inputs contain canonical duplicates.");
100
+ const allEntries = [...inventory.entries, ...queue.entries];
101
+ if (allEntries.length + externalInputs.length > 10_000 ||
102
+ allEntries.reduce((n, f) => n + (f.sha256 ? (f.bytes ?? 0) : 0), 0) +
103
+ externalInputs.reduce((n, f) => n + f.bytes, 0) >
104
+ 256 * 1024 * 1024)
105
+ fail("migration_inventory_limit", "Combined migration sources exceed the inventory or byte limit.");
106
+ if (inventory.marker_schema !== null && inventory.marker_schema.length > 256)
107
+ fail("migration_source_schema_unsupported", "Source marker schema exceeds the migration protocol limit.");
108
+ if (!inventory.foundry_root_exists && !queue.exists)
109
+ fail("migration_source_empty", "The selected source has no Foundry state to migrate.");
110
+ const stages = Object.freeze([...selected].sort().map((file) => inspectFoundryMigrationStage(inventory, file)));
111
+ const privateReference = privateOptions.sessionReference && fs.existsSync(privateOptions.sessionReference)
112
+ ? fs.realpathSync(privateOptions.sessionReference)
113
+ : privateOptions.sessionReference;
114
+ const privatePath = (relative) => migrationCredentialPath(relative) ||
115
+ path.join(source, ".foundry", relative) === privateReference;
116
+ const omitted = inventory.entries
117
+ .filter((entry) => privatePath(entry.path))
118
+ .map((entry) => entry.path);
119
+ const queuePrivate = (relative) => migrationCredentialPath(relative) || path.join(source, "tasks", relative) === privateReference;
120
+ omitted.push(...queue.entries
121
+ .filter((entry) => queuePrivate(entry.path))
122
+ .map((entry) => `tasks/${entry.path}`));
123
+ const blockers = inventory.entries
124
+ .filter((entry) => entry.kind === "file" && entry.sha256 === null && !privatePath(entry.path))
125
+ .map((entry) => Object.freeze({ code: "migration_unhashed_file", path: entry.path }));
126
+ blockers.push(...queue.entries
127
+ .filter((entry) => entry.kind === "file" && !entry.sha256 && !queuePrivate(entry.path))
128
+ .map((entry) => Object.freeze({ code: "migration_unhashed_file", path: `tasks/${entry.path}` })));
129
+ if (privatePath("workspace.json"))
130
+ blockers.push(Object.freeze({ code: "migration_private_marker", path: "workspace.json" }));
131
+ if (inventory.marker_schema !== null &&
132
+ !["tiangong-foundry.workspace.v1", "tiangong-foundry.workspace.v2"].includes(inventory.marker_schema))
133
+ blockers.push(Object.freeze({ code: "migration_source_schema_unsupported", path: "workspace.json" }));
134
+ if (inventory.marker_schema === "tiangong-foundry.workspace.v2") {
135
+ try {
136
+ const marker = JSON.parse(transferRead(path.join(source, ".foundry/workspace.json"), 64 * 1024).toString("utf8"));
137
+ const authority = readFoundryMigrationAuthority(path.join(source, ".foundry"), marker.workspace_id, marker.migration, false, privateOptions.sessionReference);
138
+ for (const file of authority.protected_files) {
139
+ const actual = inventory.entries.find((entry) => entry.path === file.path);
140
+ if (!actual || actual.sha256 !== file.sha256 || actual.bytes !== file.bytes)
141
+ fail("migration_source_authority_invalid", "Current migration evidence is missing, private or changed.");
142
+ }
143
+ }
144
+ catch {
145
+ blockers.push(Object.freeze({ code: "migration_source_authority_invalid", path: "workspace.json" }));
146
+ }
147
+ }
148
+ const current = inventoryFoundryWorkspace(source, privateOptions);
149
+ if (sha256Json(current) !== sha256Json(inventory) ||
150
+ sha256Json(inventoryFoundryMigrationTree(path.join(source, "tasks"), privateOptions)) !==
151
+ sha256Json(queue) ||
152
+ externalInputs.some((file) => sha256Json(captureFoundryInput(file.path)) !== sha256Json(file)))
153
+ fail("migration_source_changed", "Source state changed while the migration plan was assembled.");
154
+ if (sha256Json(runtimeFacts(context)) !== sha256Json(runtime))
155
+ fail("migration_runtime_changed", "Runtime bytes changed while migration planning was in progress.");
156
+ const payload = {
157
+ schema: FOUNDRY_MIGRATION_TRANSFER_PLAN_SCHEMA,
158
+ request_id: options.requestId,
159
+ actor_id: options.actorId,
160
+ destination_workspace: context.workspaceRoot,
161
+ account_intent: context.accountIntent
162
+ ? Object.freeze({
163
+ project_ref: context.accountIntent.projectRef,
164
+ user_id: context.accountIntent.userId,
165
+ })
166
+ : null,
167
+ runtime,
168
+ source_inventory: inventory,
169
+ source_queue: queue,
170
+ external_inputs: Object.freeze(externalInputs),
171
+ stages,
172
+ omitted_private_paths: Object.freeze(omitted),
173
+ blockers: Object.freeze(blockers),
174
+ source_must_remain_unchanged: true,
175
+ remote_write_allowed: false,
176
+ };
177
+ const result = Object.freeze({ ...payload, plan_sha256: sha256Json(payload) });
178
+ if (Buffer.byteLength(JSON.stringify(result)) > maxDocumentBytes)
179
+ fail("migration_plan_limit", "The migration plan exceeds its bounded document size.");
180
+ return result;
181
+ }
182
+ /** Untrusted serialized plans are accepted only when a fresh independent reconstruction matches every field. */
183
+ export function assertFoundryMigrationJson(value) {
184
+ let count = 0;
185
+ const json = (item, depth) => {
186
+ if (++count > 200_000 || depth > 64)
187
+ fail("migration_plan_limit", "Migration plan JSON exceeds its structural limits.");
188
+ if (typeof item === "string" && item.length > 8192)
189
+ fail("migration_plan_limit", "Migration plan strings exceed their bound.");
190
+ if (item === null ||
191
+ typeof item === "boolean" ||
192
+ typeof item === "string" ||
193
+ (typeof item === "number" && Number.isFinite(item)))
194
+ return;
195
+ if (!item || typeof item !== "object" || Object.getOwnPropertySymbols(item).length)
196
+ fail("migration_document_invalid", "Migration plan must contain only plain JSON data.");
197
+ if (Array.isArray(item)) {
198
+ if (Object.keys(item).length !== item.length ||
199
+ Object.getOwnPropertyNames(item).length !== item.length + 1)
200
+ fail("migration_document_invalid", "Migration plan arrays cannot contain extra properties.");
201
+ if (item.length > 10_000)
202
+ fail("migration_plan_limit", "Migration plan arrays exceed their bound.");
203
+ for (let index = 0; index < item.length; index += 1) {
204
+ const descriptor = Object.getOwnPropertyDescriptor(item, String(index));
205
+ if (!descriptor || !("value" in descriptor))
206
+ fail("migration_document_invalid", "Migration plan cannot contain sparse arrays or accessors.");
207
+ json(descriptor.value, depth + 1);
208
+ }
209
+ }
210
+ else {
211
+ if (Object.getOwnPropertyNames(item).length !== Object.keys(item).length)
212
+ fail("migration_document_invalid", "Migration plan cannot contain hidden object fields.");
213
+ if (Object.getPrototypeOf(item) !== Object.prototype && Object.getPrototypeOf(item) !== null)
214
+ fail("migration_document_invalid", "Migration plan objects must be plain records.");
215
+ for (const key of Object.keys(item)) {
216
+ const descriptor = Object.getOwnPropertyDescriptor(item, key);
217
+ if (!("value" in descriptor))
218
+ fail("migration_document_invalid", "Migration plan cannot contain accessors.");
219
+ json(descriptor.value, depth + 1);
220
+ }
221
+ }
222
+ };
223
+ json(value, 0);
224
+ if (Buffer.byteLength(JSON.stringify(value)) > maxDocumentBytes)
225
+ fail("migration_plan_limit", "Migration plan exceeds its document byte limit.");
226
+ }
227
+ export function revalidateFoundryMigrationPlan(context, options, value, pendingPlanSha256) {
228
+ assertFoundryMigrationJson(value);
229
+ const supplied = record(value);
230
+ const current = planFoundryWorkspaceMigration(context, options, pendingPlanSha256);
231
+ if (sha256Json(supplied) !== sha256Json(current))
232
+ fail("migration_plan_changed", "The supplied plan differs from current source, destination, intent or runtime facts.");
233
+ return current;
234
+ }
@@ -0,0 +1,3 @@
1
+ import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
2
+ /** Admission guard only. Original CLI dispatch/readback state is never changed or replayed here. */
3
+ export declare function assertFoundryMigrationNoReplay(context: FoundryRuntimeContext, inputFile: string): void;
@@ -0,0 +1,134 @@
1
+ import fs from "node:fs";
2
+ import { parseCapsule } from "./foundry-execution-context-format.js";
3
+ import { sha256Json } from "./identity-preflight-proof.js";
4
+ import path from "node:path";
5
+ import { assertFoundryRuntimeContext, readFoundryInput, } from "./foundry-runtime-context.js";
6
+ import { readFoundryMigrationAuthority, migrationDatasetScope, } from "./foundry-migration-authority.js";
7
+ import { transferFail, transferPath, transferRead, transferHash, } from "./foundry-migration-transfer-io.js";
8
+ function consumed(context, id) {
9
+ const attempts = transferPath(context.controlRoot, `workspaces/${id}/attempts`);
10
+ if (!fs.existsSync(attempts))
11
+ return false;
12
+ const stat = fs.lstatSync(attempts);
13
+ if (!stat.isDirectory() || stat.isSymbolicLink())
14
+ transferFail("migration_attempt_history_invalid", "Current attempt history is not a contained directory.");
15
+ const directory = fs.opendirSync(attempts);
16
+ try {
17
+ return directory.readSync() !== null;
18
+ }
19
+ finally {
20
+ directory.closeSync();
21
+ }
22
+ }
23
+ /** Admission guard only. Original CLI dispatch/readback state is never changed or replayed here. */
24
+ export function assertFoundryMigrationNoReplay(context, inputFile) {
25
+ assertFoundryRuntimeContext(context);
26
+ if (!context.migration)
27
+ return;
28
+ const authority = readFoundryMigrationAuthority(context.controlRoot, context.workspaceId, context.migration);
29
+ const barriers = authority.tasks.filter((task) => task.disposition !== "local-unattempted");
30
+ const workspaceTasks = transferPath(context.controlRoot, "workspaces");
31
+ const registrations = transferPath(context.controlRoot, "state/task-registrations");
32
+ const ids = new Set(fs.existsSync(workspaceTasks) ? fs.readdirSync(workspaceTasks) : []);
33
+ if (fs.existsSync(registrations))
34
+ for (const name of fs.readdirSync(registrations))
35
+ if (name.endsWith(".json"))
36
+ ids.add(name.slice(0, -5));
37
+ if (ids.size > 10_000)
38
+ transferFail("migration_attempt_history_invalid", "Current task history exceeds its audit bound.");
39
+ for (const id of ids) {
40
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/u.test(id))
41
+ transferFail("migration_attempt_history_invalid", "Current task identity is unsupported.");
42
+ const taskRoot = transferPath(context.controlRoot, `workspaces/${id}`);
43
+ if (!fs.existsSync(taskRoot) || !fs.lstatSync(taskRoot).isDirectory())
44
+ transferFail("migration_attempt_history_invalid", "Registered current task history is missing.");
45
+ const registration = JSON.parse(transferRead(transferPath(context.controlRoot, `state/task-registrations/${id}.json`), 24 * 1024 * 1024).toString("utf8"));
46
+ const { registration_sha256: checksum, ...registered } = registration;
47
+ const job = registration.job;
48
+ if (registration.schema !== "tiangong-foundry.task-registration.v1" ||
49
+ checksum !== sha256Json(registered) ||
50
+ !job ||
51
+ typeof job !== "object" ||
52
+ Array.isArray(job) ||
53
+ job.workspace_id !== context.workspaceId ||
54
+ job.task_id !== id ||
55
+ typeof job.actor_id !== "string")
56
+ transferFail("migration_attempt_history_invalid", "Current task registration does not match this workspace.");
57
+ const jobBytes = transferRead(transferPath(context.controlRoot, `workspaces/${id}/foundry-job.json`), 8 * 1024 * 1024);
58
+ const publication = JSON.parse(transferRead(transferPath(context.controlRoot, `state/task-publications/${id}.json`), 64 * 1024).toString("utf8"));
59
+ if (sha256Json(JSON.parse(jobBytes.toString("utf8"))) !== sha256Json(job) ||
60
+ publication.schema !== "tiangong-foundry.task-publication.v1" ||
61
+ publication.workspace_id !== context.workspaceId ||
62
+ publication.task_id !== id ||
63
+ publication.job_sha256 !== transferHash(jobBytes))
64
+ transferFail("migration_attempt_history_invalid", "Current task publication is missing or changed.");
65
+ if (!consumed(context, id))
66
+ continue;
67
+ const task = { task_id: id, actor_id: job.actor_id };
68
+ const keys = new Set();
69
+ let complete = true;
70
+ const executionRoot = transferPath(context.controlRoot, `workspaces/${task.task_id}/evidence/executions`);
71
+ if (!fs.existsSync(executionRoot))
72
+ complete = false;
73
+ else {
74
+ const names = fs.readdirSync(executionRoot);
75
+ if (!names.length || names.length > 1000)
76
+ complete = false;
77
+ for (const name of names.slice(0, 1000)) {
78
+ try {
79
+ if (!/^[0-9a-f]{64}\.json$/u.test(name)) {
80
+ complete = false;
81
+ continue;
82
+ }
83
+ const bytes = transferRead(transferPath(context.controlRoot, `workspaces/${task.task_id}/evidence/executions/${name}`), 1024 * 1024);
84
+ if (transferHash(bytes) !== name.slice(0, -5)) {
85
+ complete = false;
86
+ continue;
87
+ }
88
+ const value = parseCapsule(JSON.parse(bytes.toString("utf8")));
89
+ const fact = value.final_rows;
90
+ if (value.schema !== "tiangong-foundry.execution-context.v1" ||
91
+ value.workspace_id !== context.workspaceId ||
92
+ value.task_id !== task.task_id ||
93
+ value.actor_id !== task.actor_id ||
94
+ !fact ||
95
+ typeof fact.path !== "string" ||
96
+ !fact.path.startsWith(context.controlRoot + path.sep)) {
97
+ complete = false;
98
+ continue;
99
+ }
100
+ const input = transferPath(context.controlRoot, path.relative(context.controlRoot, fact.path).split(path.sep).join("/"));
101
+ const data = transferRead(input, 64 * 1024 * 1024);
102
+ if (data.length !== fact.bytes || transferHash(data) !== fact.sha256) {
103
+ complete = false;
104
+ continue;
105
+ }
106
+ const scope = migrationDatasetScope(input, data);
107
+ complete = complete && scope.complete;
108
+ for (const key of scope.keys)
109
+ keys.add(key);
110
+ }
111
+ catch {
112
+ complete = false;
113
+ }
114
+ }
115
+ }
116
+ barriers.push({
117
+ disposition: "owner-readback-only",
118
+ scope_keys: [...keys].sort(),
119
+ scope_complete: complete && keys.size > 0,
120
+ });
121
+ }
122
+ if (!barriers.length)
123
+ return;
124
+ const current = migrationDatasetScope(inputFile, readFoundryInput(context, inputFile));
125
+ if (!current.complete || barriers.some((task) => !task.scope_complete))
126
+ transferFail("migration_readback_required", "Unresolved migration history has no complete dataset scope; obtain original-owner status/readback before mutation admission.");
127
+ for (const task of barriers) {
128
+ const previous = new Set(task.scope_keys);
129
+ const resources = new Set(task.scope_keys.map((key) => key.split("@")[0]));
130
+ if (current.keys.some((key) => previous.has(key) ||
131
+ (task.disposition !== "terminal-retained" && resources.has(key.split("@")[0]))))
132
+ transferFail("migration_replay_forbidden", "This dataset overlaps retained terminal or unresolved attempt authority; another request, path or runtime cannot authorize replay.");
133
+ }
134
+ }
@@ -0,0 +1,15 @@
1
+ import { type FoundryWorkspaceMigrationPlan } from "./foundry-migration-inventory.ts";
2
+ import { modelExecutionAttemptDisposition } from "./foundry-execution-attempt.ts";
3
+ export interface MigrationStageEvidence {
4
+ readonly path: string;
5
+ readonly sha256: string;
6
+ readonly stage_id: string;
7
+ readonly producer_id: string;
8
+ readonly revision: number;
9
+ readonly scope_binding_sha256: string;
10
+ readonly disposition: ReturnType<typeof modelExecutionAttemptDisposition>["disposition"];
11
+ readonly migration_action: "rebuild-local-preparation" | "retain-terminal" | "owner-readback-only";
12
+ readonly grants_write_authority: false;
13
+ }
14
+ export declare function normalizeMigrationStagePath(value: string): string;
15
+ export declare function inspectFoundryMigrationStage(inventory: FoundryWorkspaceMigrationPlan, selected: string): MigrationStageEvidence;