@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,603 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import fs from "node:fs";
4
+ import { createRequire } from "node:module";
5
+ import path from "node:path";
6
+ import process from "node:process";
7
+ import { runtimeEnvFilePolicyDisabled, runtimeEnvFilePolicyKey, } from "./foundry-runtime-environment.js";
8
+ import { resolveFoundryRuntimePaths } from "./foundry-runtime-paths.js";
9
+ const require = createRequire(import.meta.url);
10
+ const tiangongLcaCliPackageName = "@tiangong-lca/cli";
11
+ const tiangongLcaCliPackageVersion = "0.1.12";
12
+ const tiangongLcaCliBinName = "tiangong-lca";
13
+ const { repoRoot: foundryRepoRoot } = resolveFoundryRuntimePaths(import.meta.url);
14
+ function isRecord(value) {
15
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
16
+ }
17
+ export function resolveInstalledTiangongLcaCliPackage() {
18
+ const logicalPackageJsonPath = path.join(foundryRepoRoot, "node_modules", "@tiangong-lca", "cli", "package.json");
19
+ let packageJsonPath = logicalPackageJsonPath;
20
+ if (!fs.existsSync(packageJsonPath)) {
21
+ try {
22
+ const publicBin = require.resolve(`${tiangongLcaCliPackageName}/bin/tiangong-lca.js`);
23
+ packageJsonPath = path.resolve(path.dirname(publicBin), "../package.json");
24
+ }
25
+ catch (error) {
26
+ throw new Error(`Unable to resolve installed ${tiangongLcaCliPackageName}@${tiangongLcaCliPackageVersion}; run pnpm install --frozen-lockfile.`, { cause: error });
27
+ }
28
+ }
29
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
30
+ if (packageJson.name !== tiangongLcaCliPackageName ||
31
+ packageJson.version !== tiangongLcaCliPackageVersion) {
32
+ throw new Error(`Expected installed ${tiangongLcaCliPackageName}@${tiangongLcaCliPackageVersion}, received ${packageJson.name ?? "unknown"}@${packageJson.version ?? "unknown"}.`);
33
+ }
34
+ const binEntry = typeof packageJson.bin === "string"
35
+ ? packageJson.bin
36
+ : isRecord(packageJson.bin)
37
+ ? packageJson.bin[tiangongLcaCliBinName]
38
+ : undefined;
39
+ if (typeof binEntry !== "string" || binEntry.trim() === "") {
40
+ throw new Error(`Installed ${tiangongLcaCliPackageName}@${tiangongLcaCliPackageVersion} does not expose the '${tiangongLcaCliBinName}' package bin.`);
41
+ }
42
+ const packageRoot = path.dirname(packageJsonPath);
43
+ const binPath = path.resolve(packageRoot, binEntry);
44
+ const schemaDir = path.join(packageRoot, "assets", "tidas-schemas");
45
+ if (!fs.existsSync(binPath) || !fs.statSync(binPath).isFile()) {
46
+ throw new Error(`Installed ${tiangongLcaCliPackageName} bin is missing at ${binPath}.`);
47
+ }
48
+ if (!fs.existsSync(schemaDir) || !fs.statSync(schemaDir).isDirectory()) {
49
+ throw new Error(`Installed ${tiangongLcaCliPackageName} schema assets are missing at ${schemaDir}.`);
50
+ }
51
+ return {
52
+ packageName: packageJson.name,
53
+ packageVersion: packageJson.version,
54
+ packageSpec: `${packageJson.name}@${packageJson.version}`,
55
+ packageJsonPath,
56
+ packageRoot,
57
+ binName: tiangongLcaCliBinName,
58
+ binPath,
59
+ schemaDir,
60
+ };
61
+ }
62
+ function shellQuoteCommandToken(value) {
63
+ const text = String(value ?? "");
64
+ if (/^[A-Za-z0-9_./:@%+=,-]+$/u.test(text))
65
+ return text;
66
+ return `'${text.replace(/'/gu, `'\\''`)}'`;
67
+ }
68
+ export function resolveTiangongLcaCliRuntimeCommand(env = process.env) {
69
+ if (env.TIANGONG_LCA_CLI_BIN) {
70
+ const binPath = env.TIANGONG_LCA_CLI_BIN;
71
+ const isNodeScript = process.platform === "win32" && /\.(?:cjs|mjs|js)$/iu.test(binPath);
72
+ const command = isNodeScript ? process.execPath : binPath;
73
+ const args = isNodeScript ? [binPath] : [];
74
+ return {
75
+ command,
76
+ args,
77
+ display: [command, ...args].map(shellQuoteCommandToken).join(" "),
78
+ source: "TIANGONG_LCA_CLI_BIN",
79
+ package: null,
80
+ package_version: null,
81
+ bin_path: binPath,
82
+ };
83
+ }
84
+ const installed = resolveInstalledTiangongLcaCliPackage();
85
+ return {
86
+ command: process.execPath,
87
+ args: [installed.binPath],
88
+ display: [process.execPath, installed.binPath].map(shellQuoteCommandToken).join(" "),
89
+ source: "installed_package",
90
+ package: installed.packageSpec,
91
+ package_version: installed.packageVersion,
92
+ package_root: installed.packageRoot,
93
+ bin_path: installed.binPath,
94
+ };
95
+ }
96
+ export function createFoundryRuntimeUtils({ parseScalar, repoRoot }) {
97
+ function nowIso() {
98
+ return new Date().toISOString();
99
+ }
100
+ function readText(filePath) {
101
+ return fs.readFileSync(filePath, "utf8");
102
+ }
103
+ function writeText(filePath, text) {
104
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
105
+ fs.writeFileSync(filePath, text);
106
+ }
107
+ function resolveTiangongLcaCliCommand() {
108
+ return resolveTiangongLcaCliRuntimeCommand(process.env);
109
+ }
110
+ function resolveTiangongLcaCliBin() {
111
+ return resolveTiangongLcaCliCommand().display;
112
+ }
113
+ function resolveTiangongLcaCliCommandPrefix() {
114
+ const cli = resolveTiangongLcaCliCommand();
115
+ return [cli.command, ...cli.args];
116
+ }
117
+ function tiangongLcaCliInvocation(args = []) {
118
+ const cli = resolveTiangongLcaCliCommand();
119
+ const spawnArgs = [...cli.args, ...args];
120
+ return {
121
+ ...cli,
122
+ spawn_args: spawnArgs,
123
+ command_line: [cli.command, ...spawnArgs].map(shellQuote).join(" "),
124
+ };
125
+ }
126
+ function readJson(filePath) {
127
+ return JSON.parse(readText(filePath));
128
+ }
129
+ function readJsonLines(filePath) {
130
+ return readText(filePath)
131
+ .split(/\r?\n/u)
132
+ .map((line) => line.trim())
133
+ .filter(Boolean)
134
+ .map((line, index) => {
135
+ try {
136
+ return JSON.parse(line);
137
+ }
138
+ catch (error) {
139
+ throw new Error(`Invalid JSONL at ${repoRelativePath(filePath)}:${index + 1}: ${error}`);
140
+ }
141
+ });
142
+ }
143
+ function writeJson(filePath, value) {
144
+ writeText(filePath, `${JSON.stringify(value, null, 2)}\n`);
145
+ }
146
+ function fileExists(filePath) {
147
+ return Boolean(filePath && fs.existsSync(filePath) && fs.statSync(filePath).isFile());
148
+ }
149
+ function directoryExists(filePath) {
150
+ return Boolean(filePath && fs.existsSync(filePath) && fs.statSync(filePath).isDirectory());
151
+ }
152
+ function resolveRepoPath(filePath) {
153
+ if (!filePath)
154
+ return null;
155
+ const value = filePath;
156
+ return path.isAbsolute(value) ? value : path.join(repoRoot, value);
157
+ }
158
+ function repoRelativePath(filePath) {
159
+ return path.relative(repoRoot, filePath).split(path.sep).join(path.posix.sep);
160
+ }
161
+ function repoRelativeMaybe(filePath) {
162
+ return filePath ? repoRelativePath(filePath) : null;
163
+ }
164
+ function sha256Text(value) {
165
+ return createHash("sha256")
166
+ .update(String(value ?? ""))
167
+ .digest("hex");
168
+ }
169
+ function sameResolvedPath(left, right) {
170
+ if (!left || !right)
171
+ return false;
172
+ return path.resolve(left) === path.resolve(right);
173
+ }
174
+ function reportInputPath(report) {
175
+ const record = isRecord(report) ? report : {};
176
+ return asText(record.input_path || record.input_file || record.inputPath || record.inputFile);
177
+ }
178
+ function countRowsFile(filePath) {
179
+ if (!filePath || !fileExists(filePath))
180
+ return 0;
181
+ const text = readText(filePath);
182
+ if (!text.trim())
183
+ return 0;
184
+ if (filePath.toLowerCase().endsWith(".jsonl")) {
185
+ return text.split(/\r?\n/u).filter((line) => line.trim()).length;
186
+ }
187
+ const value = JSON.parse(text);
188
+ if (Array.isArray(value))
189
+ return value.length;
190
+ if (isRecord(value) && Array.isArray(value.rows))
191
+ return value.rows.length;
192
+ if (isRecord(value) && Array.isArray(value.items))
193
+ return value.items.length;
194
+ return 1;
195
+ }
196
+ function countJsonLinesFile(filePath) {
197
+ if (!filePath || !fileExists(filePath))
198
+ return 0;
199
+ return readText(filePath)
200
+ .split(/\r?\n/u)
201
+ .filter((line) => line.trim()).length;
202
+ }
203
+ function readRowsFile(filePath) {
204
+ if (!filePath || !fileExists(filePath))
205
+ return [];
206
+ if (filePath.toLowerCase().endsWith(".jsonl")) {
207
+ return readJsonLines(filePath);
208
+ }
209
+ const value = readJson(filePath);
210
+ if (Array.isArray(value))
211
+ return value;
212
+ if (isRecord(value) && Array.isArray(value.rows))
213
+ return value.rows;
214
+ if (isRecord(value) && Array.isArray(value.items))
215
+ return value.items;
216
+ return [value];
217
+ }
218
+ function findFilesByName(startDir, fileName, maxDepth = 8) {
219
+ const root = resolveRepoPath(startDir);
220
+ if (!root || !directoryExists(root))
221
+ return [];
222
+ const found = [];
223
+ const ignoredDirs = new Set([".git", "node_modules"]);
224
+ function walk(dir, depth) {
225
+ if (depth > maxDepth)
226
+ return;
227
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
228
+ const entryPath = path.join(dir, entry.name);
229
+ if (entry.isDirectory()) {
230
+ if (!ignoredDirs.has(entry.name))
231
+ walk(entryPath, depth + 1);
232
+ }
233
+ else if (entry.isFile() && entry.name === fileName) {
234
+ found.push(entryPath);
235
+ }
236
+ }
237
+ }
238
+ walk(root, 0);
239
+ return found.sort();
240
+ }
241
+ function asText(value) {
242
+ if (value === undefined || value === null)
243
+ return "";
244
+ if (typeof value === "string")
245
+ return value.trim();
246
+ if (typeof value === "number" || typeof value === "boolean")
247
+ return String(value);
248
+ return "";
249
+ }
250
+ function splitFrontmatter(text) {
251
+ if (!text.startsWith("---\n"))
252
+ return { frontmatter: "", body: text };
253
+ const end = text.indexOf("\n---\n", 4);
254
+ if (end === -1)
255
+ throw new Error("Missing closing frontmatter marker.");
256
+ return {
257
+ frontmatter: text.slice(4, end),
258
+ body: text.slice(end + 5),
259
+ };
260
+ }
261
+ function replaceFrontmatterField(frontmatter, key, value) {
262
+ const lines = frontmatter.split(/\r?\n/u);
263
+ let replaced = false;
264
+ const nextLines = lines.map((line) => {
265
+ if (line.match(new RegExp(`^${key}:\\s*`, "u"))) {
266
+ replaced = true;
267
+ return `${key}: ${value}`;
268
+ }
269
+ return line;
270
+ });
271
+ if (!replaced) {
272
+ nextLines.push(`${key}: ${value}`);
273
+ }
274
+ return nextLines.join("\n").replace(/\n+$/u, "");
275
+ }
276
+ function taskMetaFromFile(filePath) {
277
+ const text = readText(filePath);
278
+ const { frontmatter, body } = splitFrontmatter(text);
279
+ const meta = {};
280
+ for (const line of frontmatter.split(/\r?\n/u)) {
281
+ const match = line.match(/^([A-Za-z0-9_.-]+):\s*(.*)$/u);
282
+ if (match)
283
+ meta[match[1]] = parseScalar(match[2]);
284
+ }
285
+ return { text, frontmatter, body, meta };
286
+ }
287
+ function isPlaceholderEnvValue(value) {
288
+ const normalized = String(value ?? "").trim();
289
+ return normalized === "" || normalized === "REPLACE_ME";
290
+ }
291
+ function loadEnvFile(filePath, { override = false } = {}) {
292
+ if (!filePath || !fs.existsSync(filePath))
293
+ return { file: filePath, loaded: false, keys: [] };
294
+ const keys = [];
295
+ for (const rawLine of readText(filePath).split(/\r?\n/u)) {
296
+ const line = rawLine.trim();
297
+ if (!line || line.startsWith("#"))
298
+ continue;
299
+ const match = line.replace(/^export\s+/u, "").match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/u);
300
+ if (!match)
301
+ continue;
302
+ const key = match[1];
303
+ const value = String(match[2] ?? "")
304
+ .trim()
305
+ .replace(/^["']|["']$/gu, "");
306
+ if (override || process.env[key] === undefined || isPlaceholderEnvValue(process.env[key])) {
307
+ process.env[key] = value;
308
+ }
309
+ keys.push(key);
310
+ }
311
+ return { file: filePath, loaded: true, keys };
312
+ }
313
+ function loadRuntimeEnv(options = {}) {
314
+ const envFile = path.join(repoRoot, ".env");
315
+ const allowFilesystemEnv = options.allowFilesystemEnv ??
316
+ process.env[runtimeEnvFilePolicyKey] !== runtimeEnvFilePolicyDisabled;
317
+ const repoEnv = allowFilesystemEnv
318
+ ? loadEnvFile(envFile)
319
+ : { file: envFile, loaded: false, keys: [] };
320
+ return { repoEnv };
321
+ }
322
+ function hasUsableEnvValue(key) {
323
+ return process.env[key] !== undefined && !isPlaceholderEnvValue(process.env[key]);
324
+ }
325
+ function ensureArray(value) {
326
+ if (Array.isArray(value))
327
+ return value;
328
+ if (value === undefined || value === null || value === "")
329
+ return [];
330
+ return [value];
331
+ }
332
+ function normalizedList(value) {
333
+ return ensureArray(value)
334
+ .flatMap((item) => String(item).split(","))
335
+ .map((item) => item.trim())
336
+ .filter(Boolean);
337
+ }
338
+ function unique(values) {
339
+ return [...new Set(values.filter(Boolean))];
340
+ }
341
+ function appendOption(args, flag, value) {
342
+ if (value === undefined || value === null || value === false || value === "")
343
+ return;
344
+ args.push(flag, String(value));
345
+ }
346
+ function appendRepeatedOptions(args, flag, values) {
347
+ for (const value of normalizedList(values)) {
348
+ appendOption(args, flag, value);
349
+ }
350
+ }
351
+ function booleanOption(value) {
352
+ return value === true || value === "true" || value === "1" || value === "yes";
353
+ }
354
+ function integerOption(value, fallback = null) {
355
+ if (value === undefined || value === null || value === "")
356
+ return fallback;
357
+ const number = Number(value);
358
+ return Number.isInteger(number) ? number : fallback;
359
+ }
360
+ function positiveIntegerOption(value, fallback = null) {
361
+ const number = integerOption(value, fallback);
362
+ return number !== null && Number.isInteger(number) && number > 0 ? number : fallback;
363
+ }
364
+ function shellQuote(value) {
365
+ const text = String(value ?? "");
366
+ if (/^[A-Za-z0-9_./:@%+=,-]+$/u.test(text))
367
+ return text;
368
+ return `'${text.replace(/'/gu, `'\\''`)}'`;
369
+ }
370
+ function compactStageReport(stage) {
371
+ return {
372
+ stage: stage.stage,
373
+ status: stage.report?.status ?? stage.status ?? null,
374
+ exit_code: stage.exit_code,
375
+ command: stage.command,
376
+ args: stage.args,
377
+ stderr: stage.stderr,
378
+ report_file: stage.report_file ? repoRelativePath(stage.report_file) : null,
379
+ };
380
+ }
381
+ function reportFileFromCliStage(stage, selectors, fallbackPath) {
382
+ for (const selector of selectors) {
383
+ const parts = selector.split(".");
384
+ let value = stage.report;
385
+ for (const part of parts) {
386
+ value = isRecord(value) ? value[part] : undefined;
387
+ }
388
+ const resolved = resolveRepoPath(value);
389
+ if (fileExists(resolved)) {
390
+ return resolved;
391
+ }
392
+ }
393
+ const fallback = resolveRepoPath(fallbackPath);
394
+ return fileExists(fallback) ? fallback : null;
395
+ }
396
+ function blockersFromLocationAuditStage(stage) {
397
+ const reportBlockers = ensureArray(stage?.report?.blockers);
398
+ const blockers = reportBlockers.map((value) => {
399
+ const blocker = value;
400
+ return {
401
+ ...blocker,
402
+ code: blocker.code || "location_audit_blocker",
403
+ stage: "location_audit",
404
+ message: blocker.message || "Location audit reported a blocker before remote write.",
405
+ };
406
+ });
407
+ if (stage?.exit_code !== 0 && blockers.length === 0) {
408
+ blockers.push({
409
+ code: "location_audit_failed",
410
+ stage: "location_audit",
411
+ message: "Location audit stage failed before remote write; inspect the stage stderr/report.",
412
+ stderr: stage?.stderr || "",
413
+ });
414
+ }
415
+ return blockers;
416
+ }
417
+ function stageExitBlocker(stage, { code, message }) {
418
+ return stage?.exit_code === 0
419
+ ? null
420
+ : {
421
+ code,
422
+ stage: stage?.stage ?? null,
423
+ message,
424
+ exit_code: stage?.exit_code ?? null,
425
+ report_file: repoRelativeMaybe(stage?.report_file),
426
+ };
427
+ }
428
+ function postAuthoringPrewriteGateBlockers({ schemaStage, qaStage, locationAuditBlockers, curationGate, curationGateReportFile, requireDeterministicQa = true, requireCurationGate = true, }) {
429
+ const blockers = [
430
+ stageExitBlocker(schemaStage, {
431
+ code: "schema_validate_not_ready",
432
+ message: "Schema validation must complete before post-authoring dry-run or remote write planning.",
433
+ }),
434
+ requireDeterministicQa
435
+ ? stageExitBlocker(qaStage, {
436
+ code: "deterministic_qa_not_ready",
437
+ message: "Deterministic QA must complete before post-authoring dry-run or remote write planning.",
438
+ })
439
+ : null,
440
+ ...locationAuditBlockers,
441
+ !requireCurationGate ||
442
+ ["ready", "ready_with_profile_waivers"].includes(curationGate?.status)
443
+ ? null
444
+ : {
445
+ code: "post_authoring_curation_gate_not_ready",
446
+ stage: "post_authoring_curation_gate",
447
+ message: "Post-authoring curation gate must be ready before dry-run or remote write planning.",
448
+ status: curationGate?.status ?? null,
449
+ report_file: repoRelativeMaybe(curationGateReportFile),
450
+ },
451
+ ];
452
+ return blockers.filter((blocker) => Boolean(blocker));
453
+ }
454
+ function skippedPrewriteStage(stage, reason) {
455
+ return {
456
+ stage,
457
+ status: "skipped",
458
+ exit_code: 1,
459
+ command: "skipped",
460
+ args: [],
461
+ stderr: reason,
462
+ report: {
463
+ status: "skipped",
464
+ reason,
465
+ },
466
+ report_file: null,
467
+ };
468
+ }
469
+ function readJsonArtifactOption(value) {
470
+ const resolved = resolveRepoPath(value);
471
+ return resolved && fileExists(resolved) ? { path: resolved, value: readJson(resolved) } : null;
472
+ }
473
+ function runTiangongJsonStage(stage, args) {
474
+ const cli = tiangongLcaCliInvocation(args);
475
+ const result = spawnSync(cli.command, cli.spawn_args, {
476
+ cwd: repoRoot,
477
+ env: process.env,
478
+ encoding: "utf8",
479
+ // Mega-scope stages emit large JSON payloads on stdout; the 1MB spawnSync
480
+ // default overflows with ENOBUFS. Cap below V8's max string length.
481
+ maxBuffer: 512 * 1024 * 1024,
482
+ });
483
+ const exitCode = typeof result.status === "number" ? result.status : 1;
484
+ if (result.error) {
485
+ throw result.error;
486
+ }
487
+ let report = null;
488
+ try {
489
+ report = JSON.parse(result.stdout || "{}");
490
+ }
491
+ catch {
492
+ throw new Error([
493
+ `tiangong-lca stage ${stage} did not emit JSON.`,
494
+ result.stdout ? `stdout:\n${result.stdout}` : "",
495
+ result.stderr ? `stderr:\n${result.stderr}` : "",
496
+ ]
497
+ .filter(Boolean)
498
+ .join("\n"));
499
+ }
500
+ return {
501
+ stage,
502
+ command: cli.display,
503
+ executable: cli.command,
504
+ args: cli.spawn_args,
505
+ cli_args: args,
506
+ cli_package: cli.package,
507
+ exit_code: exitCode,
508
+ stderr: result.stderr || "",
509
+ report,
510
+ report_file: null,
511
+ };
512
+ }
513
+ function readJsonOrJsonLines(filePath) {
514
+ const resolved = resolveRepoPath(filePath);
515
+ if (!resolved || !fileExists(resolved))
516
+ return [];
517
+ if (resolved.toLowerCase().endsWith(".jsonl"))
518
+ return readJsonLines(resolved);
519
+ const value = readJson(resolved);
520
+ if (Array.isArray(value))
521
+ return value;
522
+ if (isRecord(value) && Array.isArray(value.decisions))
523
+ return value.decisions;
524
+ if (isRecord(value) && Array.isArray(value.rows))
525
+ return value.rows;
526
+ return value && typeof value === "object" ? [value] : [];
527
+ }
528
+ function hasUnresolvedAiPlaceholder(value) {
529
+ return /__AI_(?:FILL|SELECT)[A-Z0-9_]*__|requires_ai_completion/iu.test(JSON.stringify(value));
530
+ }
531
+ function cloneJson(value) {
532
+ return JSON.parse(JSON.stringify(value));
533
+ }
534
+ function jsonSha256(value) {
535
+ return createHash("sha256").update(JSON.stringify(value)).digest("hex");
536
+ }
537
+ function deterministicUuid(input) {
538
+ const bytes = Buffer.from(createHash("sha1").update(String(input)).digest("hex").slice(0, 32), "hex");
539
+ bytes[6] = (bytes[6] & 0x0f) | 0x50;
540
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
541
+ const hex = bytes.toString("hex");
542
+ return [
543
+ hex.slice(0, 8),
544
+ hex.slice(8, 12),
545
+ hex.slice(12, 16),
546
+ hex.slice(16, 20),
547
+ hex.slice(20),
548
+ ].join("-");
549
+ }
550
+ return {
551
+ appendOption,
552
+ appendRepeatedOptions,
553
+ asText,
554
+ blockersFromLocationAuditStage,
555
+ booleanOption,
556
+ cloneJson,
557
+ compactStageReport,
558
+ countJsonLinesFile,
559
+ countRowsFile,
560
+ deterministicUuid,
561
+ directoryExists,
562
+ ensureArray,
563
+ fileExists,
564
+ findFilesByName,
565
+ hasUnresolvedAiPlaceholder,
566
+ hasUsableEnvValue,
567
+ integerOption,
568
+ isPlaceholderEnvValue,
569
+ jsonSha256,
570
+ loadEnvFile,
571
+ loadRuntimeEnv,
572
+ normalizedList,
573
+ nowIso,
574
+ positiveIntegerOption,
575
+ postAuthoringPrewriteGateBlockers,
576
+ readJson,
577
+ readJsonArtifactOption,
578
+ readJsonLines,
579
+ readJsonOrJsonLines,
580
+ readRowsFile,
581
+ readText,
582
+ replaceFrontmatterField,
583
+ reportFileFromCliStage,
584
+ reportInputPath,
585
+ repoRelativeMaybe,
586
+ repoRelativePath,
587
+ resolveRepoPath,
588
+ resolveTiangongLcaCliCommand,
589
+ resolveTiangongLcaCliCommandPrefix,
590
+ resolveTiangongLcaCliBin,
591
+ runTiangongJsonStage,
592
+ sameResolvedPath,
593
+ sha256Text,
594
+ shellQuote,
595
+ skippedPrewriteStage,
596
+ splitFrontmatter,
597
+ stageExitBlocker,
598
+ taskMetaFromFile,
599
+ unique,
600
+ writeJson,
601
+ writeText,
602
+ };
603
+ }
@@ -0,0 +1,30 @@
1
+ import { type FoundryInputFact, type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
2
+ export declare const FOUNDRY_SEMANTIC_INPUT_SCHEMA: "tiangong-foundry.semantic-input.v1";
3
+ export interface SemanticSubmission {
4
+ readonly kind: "patch" | "classification" | "location" | "identity";
5
+ readonly authoring_task_sha256: string;
6
+ readonly file: string;
7
+ readonly sha256: string;
8
+ }
9
+ export type SemanticPatchInput = SemanticSubmission & {
10
+ readonly kind: "patch";
11
+ };
12
+ export type SemanticDecisionInput = SemanticSubmission & {
13
+ readonly kind: "classification" | "location" | "identity";
14
+ };
15
+ export interface FoundrySemanticInput {
16
+ schema: typeof FOUNDRY_SEMANTIC_INPUT_SCHEMA;
17
+ task_id: string;
18
+ actor_id: string;
19
+ assessment_sha256: string;
20
+ submissions: readonly SemanticSubmission[];
21
+ }
22
+ export interface SelectedSemanticInput {
23
+ readonly spec: FoundrySemanticInput;
24
+ readonly descriptor: FoundryInputFact;
25
+ readonly files: readonly FoundryInputFact[];
26
+ }
27
+ export declare function parseFoundrySemanticInput(value: unknown): FoundrySemanticInput;
28
+ export declare function readSelectedSemanticBytes(fact: FoundryInputFact): Buffer;
29
+ export declare function selectFoundrySemanticInput(context: FoundryRuntimeContext, file: string): SelectedSemanticInput;
30
+ export declare function assertSelectedSemanticInput(value: SelectedSemanticInput): void;