@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.
- package/LICENSE +21 -0
- package/README.md +532 -0
- package/docs/architecture.md +450 -0
- package/docs/foundry-task-contracts.md +147 -0
- package/docs/import-profiles/bafu/constraints.md +343 -0
- package/docs/import-profiles/bafu/leaf-process-classification-authoring.md +153 -0
- package/docs/import-profiles/bafu/profile.md +183 -0
- package/docs/import-profiles/uslci/constraints.md +29 -0
- package/docs/import-profiles/uslci/profile.md +43 -0
- package/docs/import-profiles/worldsteel/constraints.md +77 -0
- package/docs/import-profiles/worldsteel/import-coverage.md +93 -0
- package/docs/import-profiles/worldsteel/import-plan.md +375 -0
- package/docs/import-profiles/worldsteel/profile.md +78 -0
- package/docs/package-distribution-contract.md +287 -0
- package/docs/public-runtime-contract.md +218 -0
- package/docs/runtime-context-contract.md +138 -0
- package/docs/safety-policy.md +164 -0
- package/docs/task-authorization-contract.md +131 -0
- package/docs/uslci-import-runbook.md +336 -0
- package/docs/workspace-migration-contract.md +127 -0
- package/package-dist/assets/foundry-package-descriptor.json +1661 -0
- package/package-dist/scripts/foundry-facade.d.ts +78 -0
- package/package-dist/scripts/foundry-facade.js +1317 -0
- package/package-dist/scripts/foundry-runtime.d.ts +180 -0
- package/package-dist/scripts/foundry-runtime.js +190 -0
- package/package-dist/scripts/lib/batch-orchestration/scope-attempt-ledger.d.ts +27 -0
- package/package-dist/scripts/lib/batch-orchestration/scope-attempt-ledger.js +85 -0
- package/package-dist/scripts/lib/batch-orchestration/scope-resume-contract.d.ts +38 -0
- package/package-dist/scripts/lib/batch-orchestration/scope-resume-contract.js +90 -0
- package/package-dist/scripts/lib/bundle-row-types.d.ts +44 -0
- package/package-dist/scripts/lib/bundle-row-types.js +46 -0
- package/package-dist/scripts/lib/bundle-sample-utils.d.ts +183 -0
- package/package-dist/scripts/lib/bundle-sample-utils.js +526 -0
- package/package-dist/scripts/lib/bundle-source-context.d.ts +31 -0
- package/package-dist/scripts/lib/bundle-source-context.js +142 -0
- package/package-dist/scripts/lib/canonical-description.d.ts +12 -0
- package/package-dist/scripts/lib/canonical-description.js +72 -0
- package/package-dist/scripts/lib/canonical-support-rewrites.d.ts +127 -0
- package/package-dist/scripts/lib/canonical-support-rewrites.js +527 -0
- package/package-dist/scripts/lib/decision-owners/classification.d.ts +245 -0
- package/package-dist/scripts/lib/decision-owners/classification.js +754 -0
- package/package-dist/scripts/lib/decision-owners/identity-preflight.d.ts +333 -0
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +1353 -0
- package/package-dist/scripts/lib/decision-owners/identity-task.d.ts +130 -0
- package/package-dist/scripts/lib/decision-owners/identity-task.js +494 -0
- package/package-dist/scripts/lib/decision-owners/identity.d.ts +74 -0
- package/package-dist/scripts/lib/decision-owners/identity.js +443 -0
- package/package-dist/scripts/lib/decision-owners/location.d.ts +239 -0
- package/package-dist/scripts/lib/decision-owners/location.js +704 -0
- package/package-dist/scripts/lib/decision-task-utils.d.ts +484 -0
- package/package-dist/scripts/lib/decision-task-utils.js +735 -0
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.d.ts +52 -0
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.js +146 -0
- package/package-dist/scripts/lib/finalize-owners/commit-handoff.d.ts +79 -0
- package/package-dist/scripts/lib/finalize-owners/commit-handoff.js +515 -0
- package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +234 -0
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +1720 -0
- package/package-dist/scripts/lib/finalize-owners/post-write-closeout.d.ts +140 -0
- package/package-dist/scripts/lib/finalize-owners/post-write-closeout.js +656 -0
- package/package-dist/scripts/lib/foundry-args.d.ts +7 -0
- package/package-dist/scripts/lib/foundry-args.js +38 -0
- package/package-dist/scripts/lib/foundry-authentication-environment.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-authentication-environment.js +55 -0
- package/package-dist/scripts/lib/foundry-authorization-input.d.ts +31 -0
- package/package-dist/scripts/lib/foundry-authorization-input.js +151 -0
- package/package-dist/scripts/lib/foundry-command-metadata.d.ts +32 -0
- package/package-dist/scripts/lib/foundry-command-metadata.js +1012 -0
- package/package-dist/scripts/lib/foundry-command-registry.d.ts +34 -0
- package/package-dist/scripts/lib/foundry-command-registry.js +241 -0
- package/package-dist/scripts/lib/foundry-command-spec.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-command-spec.js +1 -0
- package/package-dist/scripts/lib/foundry-decision-owners.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-decision-owners.js +68 -0
- package/package-dist/scripts/lib/foundry-decision-routing.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-decision-routing.js +38 -0
- package/package-dist/scripts/lib/foundry-execution-admission.d.ts +33 -0
- package/package-dist/scripts/lib/foundry-execution-admission.js +225 -0
- package/package-dist/scripts/lib/foundry-execution-attempt.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-execution-attempt.js +33 -0
- package/package-dist/scripts/lib/foundry-execution-context-format.d.ts +18 -0
- package/package-dist/scripts/lib/foundry-execution-context-format.js +83 -0
- package/package-dist/scripts/lib/foundry-facade-store.d.ts +25 -0
- package/package-dist/scripts/lib/foundry-facade-store.js +449 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.d.ts +21 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.js +203 -0
- package/package-dist/scripts/lib/foundry-identity-owners.d.ts +13 -0
- package/package-dist/scripts/lib/foundry-identity-owners.js +58 -0
- package/package-dist/scripts/lib/foundry-managed-host.d.ts +7 -0
- package/package-dist/scripts/lib/foundry-managed-host.js +173 -0
- package/package-dist/scripts/lib/foundry-migration-adoption-plan.d.ts +39 -0
- package/package-dist/scripts/lib/foundry-migration-adoption-plan.js +467 -0
- package/package-dist/scripts/lib/foundry-migration-adoption.d.ts +31 -0
- package/package-dist/scripts/lib/foundry-migration-adoption.js +187 -0
- package/package-dist/scripts/lib/foundry-migration-authority.d.ts +42 -0
- package/package-dist/scripts/lib/foundry-migration-authority.js +280 -0
- package/package-dist/scripts/lib/foundry-migration-inventory.d.ts +31 -0
- package/package-dist/scripts/lib/foundry-migration-inventory.js +148 -0
- package/package-dist/scripts/lib/foundry-migration-plan.d.ts +48 -0
- package/package-dist/scripts/lib/foundry-migration-plan.js +234 -0
- package/package-dist/scripts/lib/foundry-migration-replay.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-migration-replay.js +134 -0
- package/package-dist/scripts/lib/foundry-migration-stage.d.ts +15 -0
- package/package-dist/scripts/lib/foundry-migration-stage.js +152 -0
- package/package-dist/scripts/lib/foundry-migration-transfer-io.d.ts +13 -0
- package/package-dist/scripts/lib/foundry-migration-transfer-io.js +226 -0
- package/package-dist/scripts/lib/foundry-migration-transfer.d.ts +36 -0
- package/package-dist/scripts/lib/foundry-migration-transfer.js +350 -0
- package/package-dist/scripts/lib/foundry-operation-result.d.ts +71 -0
- package/package-dist/scripts/lib/foundry-operation-result.js +264 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +319 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +293 -0
- package/package-dist/scripts/lib/foundry-owner-readback.d.ts +22 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +189 -0
- package/package-dist/scripts/lib/foundry-owner-trace-acceptance.d.ts +15 -0
- package/package-dist/scripts/lib/foundry-owner-trace-acceptance.js +68 -0
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +56 -0
- package/package-dist/scripts/lib/foundry-package-contract.js +392 -0
- package/package-dist/scripts/lib/foundry-private-path.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-private-path.js +20 -0
- package/package-dist/scripts/lib/foundry-runtime-cache.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-runtime-cache.js +25 -0
- package/package-dist/scripts/lib/foundry-runtime-command-policy.d.ts +20 -0
- package/package-dist/scripts/lib/foundry-runtime-command-policy.js +173 -0
- package/package-dist/scripts/lib/foundry-runtime-context-types.d.ts +59 -0
- package/package-dist/scripts/lib/foundry-runtime-context-types.js +1 -0
- package/package-dist/scripts/lib/foundry-runtime-context.d.ts +27 -0
- package/package-dist/scripts/lib/foundry-runtime-context.js +668 -0
- package/package-dist/scripts/lib/foundry-runtime-environment.d.ts +9 -0
- package/package-dist/scripts/lib/foundry-runtime-environment.js +90 -0
- package/package-dist/scripts/lib/foundry-runtime-error.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-runtime-error.js +8 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.d.ts +18 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.js +127 -0
- package/package-dist/scripts/lib/foundry-runtime-paths.d.ts +16 -0
- package/package-dist/scripts/lib/foundry-runtime-paths.js +159 -0
- package/package-dist/scripts/lib/foundry-runtime-qualification.d.ts +66 -0
- package/package-dist/scripts/lib/foundry-runtime-qualification.js +223 -0
- package/package-dist/scripts/lib/foundry-runtime-selection-record.d.ts +16 -0
- package/package-dist/scripts/lib/foundry-runtime-selection-record.js +32 -0
- package/package-dist/scripts/lib/foundry-runtime-selection.d.ts +14 -0
- package/package-dist/scripts/lib/foundry-runtime-selection.js +123 -0
- package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +178 -0
- package/package-dist/scripts/lib/foundry-runtime-utils.js +603 -0
- package/package-dist/scripts/lib/foundry-semantic-input.d.ts +30 -0
- package/package-dist/scripts/lib/foundry-semantic-input.js +132 -0
- package/package-dist/scripts/lib/foundry-task-authorization.d.ts +68 -0
- package/package-dist/scripts/lib/foundry-task-authorization.js +350 -0
- package/package-dist/scripts/lib/foundry-task-io.d.ts +18 -0
- package/package-dist/scripts/lib/foundry-task-io.js +92 -0
- package/package-dist/scripts/lib/foundry-task-registration.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-task-registration.js +384 -0
- package/package-dist/scripts/lib/foundry-task-start-spec.d.ts +34 -0
- package/package-dist/scripts/lib/foundry-task-start-spec.js +161 -0
- package/package-dist/scripts/lib/foundry-task-store.d.ts +18 -0
- package/package-dist/scripts/lib/foundry-task-store.js +466 -0
- package/package-dist/scripts/lib/foundry-task-types.d.ts +99 -0
- package/package-dist/scripts/lib/foundry-task-types.js +1 -0
- package/package-dist/scripts/lib/foundry-workflow-approval-continuation.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-workflow-approval-continuation.js +136 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +231 -0
- package/package-dist/scripts/lib/foundry-workflow-authorization.d.ts +22 -0
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +174 -0
- package/package-dist/scripts/lib/foundry-workflow-context.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-workflow-context.js +99 -0
- package/package-dist/scripts/lib/foundry-workflow-decisions.d.ts +18 -0
- package/package-dist/scripts/lib/foundry-workflow-decisions.js +123 -0
- package/package-dist/scripts/lib/foundry-workflow-execution.d.ts +8 -0
- package/package-dist/scripts/lib/foundry-workflow-execution.js +248 -0
- package/package-dist/scripts/lib/foundry-workflow-finalize.d.ts +13 -0
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +264 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-apply.d.ts +14 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-apply.js +159 -0
- package/package-dist/scripts/lib/foundry-workflow-identity.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-workflow-identity.js +153 -0
- package/package-dist/scripts/lib/foundry-workflow-import.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-workflow-import.js +70 -0
- package/package-dist/scripts/lib/foundry-workflow-io.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-workflow-io.js +77 -0
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.d.ts +41 -0
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +266 -0
- package/package-dist/scripts/lib/foundry-workflow-rows.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-workflow-rows.js +47 -0
- package/package-dist/scripts/lib/foundry-workflow-semantic.d.ts +5 -0
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +367 -0
- package/package-dist/scripts/lib/foundry-workflow-state.d.ts +37 -0
- package/package-dist/scripts/lib/foundry-workflow-state.js +158 -0
- package/package-dist/scripts/lib/full-context-proof.d.ts +51 -0
- package/package-dist/scripts/lib/full-context-proof.js +932 -0
- package/package-dist/scripts/lib/identity-preflight-artifacts.d.ts +184 -0
- package/package-dist/scripts/lib/identity-preflight-artifacts.js +573 -0
- package/package-dist/scripts/lib/identity-preflight-proof.d.ts +117 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +341 -0
- package/package-dist/scripts/lib/identity-reference-rewrite-utils.d.ts +147 -0
- package/package-dist/scripts/lib/identity-reference-rewrite-utils.js +817 -0
- package/package-dist/scripts/lib/import-curation/authoring-packages.d.ts +28 -0
- package/package-dist/scripts/lib/import-curation/authoring-packages.js +92 -0
- package/package-dist/scripts/lib/import-curation/curation-cleanup.d.ts +32 -0
- package/package-dist/scripts/lib/import-curation/curation-cleanup.js +203 -0
- package/package-dist/scripts/lib/import-curation/curation-gate.d.ts +47 -0
- package/package-dist/scripts/lib/import-curation/curation-gate.js +528 -0
- package/package-dist/scripts/lib/import-curation/internal/artifact-inputs.d.ts +24 -0
- package/package-dist/scripts/lib/import-curation/internal/artifact-inputs.js +152 -0
- package/package-dist/scripts/lib/import-curation/internal/authoring-patch-workflow.d.ts +3 -0
- package/package-dist/scripts/lib/import-curation/internal/authoring-patch-workflow.js +3 -0
- package/package-dist/scripts/lib/import-curation/internal/authoring-task-workflow.d.ts +1 -0
- package/package-dist/scripts/lib/import-curation/internal/authoring-task-workflow.js +1 -0
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.d.ts +56 -0
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +206 -0
- package/package-dist/scripts/lib/import-curation/internal/curation-gate-workflow.d.ts +14 -0
- package/package-dist/scripts/lib/import-curation/internal/curation-gate-workflow.js +14 -0
- package/package-dist/scripts/lib/import-curation/internal/dataset-payload.d.ts +70 -0
- package/package-dist/scripts/lib/import-curation/internal/dataset-payload.js +141 -0
- package/package-dist/scripts/lib/import-curation/internal/dataset-types.d.ts +25 -0
- package/package-dist/scripts/lib/import-curation/internal/dataset-types.js +45 -0
- package/package-dist/scripts/lib/import-curation/internal/full-context-proof.d.ts +129 -0
- package/package-dist/scripts/lib/import-curation/internal/full-context-proof.js +552 -0
- package/package-dist/scripts/lib/import-curation/internal/hash-utils.d.ts +2 -0
- package/package-dist/scripts/lib/import-curation/internal/hash-utils.js +10 -0
- package/package-dist/scripts/lib/import-curation/internal/mutation-manifest-workflow.d.ts +15 -0
- package/package-dist/scripts/lib/import-curation/internal/mutation-manifest-workflow.js +15 -0
- package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.d.ts +31 -0
- package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.js +467 -0
- package/package-dist/scripts/lib/import-curation/internal/profiles-config.d.ts +47 -0
- package/package-dist/scripts/lib/import-curation/internal/profiles-config.js +88 -0
- package/package-dist/scripts/lib/import-curation/internal/runtime-io.d.ts +23 -0
- package/package-dist/scripts/lib/import-curation/internal/runtime-io.js +132 -0
- package/package-dist/scripts/lib/import-curation/internal/trace-summary.d.ts +53 -0
- package/package-dist/scripts/lib/import-curation/internal/trace-summary.js +114 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-authoring-tasks.d.ts +141 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-authoring-tasks.js +854 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-decision-apply-context.d.ts +20 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-decision-apply-context.js +46 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-decision-full-context.d.ts +110 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-decision-full-context.js +782 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-dry-run-context.d.ts +24 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-dry-run-context.js +191 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-evidence-scope.d.ts +80 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-evidence-scope.js +359 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-decision-context.d.ts +146 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-decision-context.js +381 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.d.ts +223 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.js +1079 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-collect.d.ts +41 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-collect.js +412 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence-context.d.ts +117 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence-context.js +278 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence.d.ts +59 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence.js +593 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-queue-context.d.ts +58 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-queue-context.js +263 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.d.ts +177 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.js +812 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-row-transform-context.d.ts +159 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-row-transform-context.js +466 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-semantic-actions.d.ts +152 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-semantic-actions.js +1377 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-source-reference-context.d.ts +38 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-source-reference-context.js +116 -0
- package/package-dist/scripts/lib/import-curation/mutation-manifest.d.ts +51 -0
- package/package-dist/scripts/lib/import-curation/mutation-manifest.js +542 -0
- package/package-dist/scripts/lib/import-curation/patch-collect.d.ts +18 -0
- package/package-dist/scripts/lib/import-curation/patch-collect.js +172 -0
- package/package-dist/scripts/lib/import-curation/profiles.d.ts +1 -0
- package/package-dist/scripts/lib/import-curation/profiles.js +1 -0
- package/package-dist/scripts/lib/import-curation/trace-summary.d.ts +1 -0
- package/package-dist/scripts/lib/import-curation/trace-summary.js +1 -0
- package/package-dist/scripts/lib/oauth-session-reference.d.ts +1 -0
- package/package-dist/scripts/lib/oauth-session-reference.js +20 -0
- package/package-dist/scripts/lib/post-authoring-finalize-utils.d.ts +95 -0
- package/package-dist/scripts/lib/post-authoring-finalize-utils.js +548 -0
- package/package-dist/scripts/lib/post-write-root-proof.d.ts +44 -0
- package/package-dist/scripts/lib/post-write-root-proof.js +169 -0
- package/package-dist/scripts/lib/reference-description-text.d.ts +2 -0
- package/package-dist/scripts/lib/reference-description-text.js +12 -0
- package/package-dist/scripts/lib/remote-verification-accepted-diff.d.ts +42 -0
- package/package-dist/scripts/lib/remote-verification-accepted-diff.js +424 -0
- package/package-dist/scripts/lib/same-identity-commit-recovery.d.ts +8 -0
- package/package-dist/scripts/lib/same-identity-commit-recovery.js +52 -0
- package/package-dist/scripts/lib/source-semantics.d.ts +255 -0
- package/package-dist/scripts/lib/source-semantics.js +888 -0
- package/package-dist/scripts/lib/stage-contract.d.ts +36 -0
- package/package-dist/scripts/lib/stage-contract.js +25 -0
- package/package-dist/scripts/lib/task-authorization.d.ts +84 -0
- package/package-dist/scripts/lib/task-authorization.js +210 -0
- package/package-dist/scripts/lib/tidas-adapter.d.ts +113 -0
- package/package-dist/scripts/lib/tidas-adapter.js +525 -0
- package/package-dist/scripts/lib/tidas-language-utils.d.ts +8 -0
- package/package-dist/scripts/lib/tidas-language-utils.js +206 -0
- package/package-dist/scripts/lib/tidas-row-utils.d.ts +70 -0
- package/package-dist/scripts/lib/tidas-row-utils.js +225 -0
- package/package-dist/scripts/lib/trace-coverage.d.ts +53 -0
- package/package-dist/scripts/lib/trace-coverage.js +178 -0
- package/package-dist/scripts/package-entry.d.ts +2 -0
- package/package-dist/scripts/package-entry.js +4 -0
- package/package-dist/scripts/public-api.d.ts +80 -0
- package/package-dist/scripts/public-api.js +28 -0
- package/package-dist/scripts/runtime-entry.d.ts +23 -0
- package/package-dist/scripts/runtime-entry.js +424 -0
- package/package.json +93 -0
- package/specs/canonical-support/flow-properties-unit-groups.json +2692 -0
- package/specs/import-profiles.json +118 -0
- package/specs/prewrite-content-policy.json +105 -0
- package/specs/schemas/authorization-derivation.schema.json +34 -0
- package/specs/schemas/execution-context.schema.json +68 -0
- package/specs/schemas/foundry-authorization-input.schema.json +120 -0
- package/specs/schemas/foundry-facade-request-index.schema.json +78 -0
- package/specs/schemas/foundry-managed-runtime.schema.json +122 -0
- package/specs/schemas/foundry-migration-activation.schema.json +213 -0
- package/specs/schemas/foundry-migration-adoption-plan.schema.json +548 -0
- package/specs/schemas/foundry-migration-transfer-receipt.schema.json +93 -0
- package/specs/schemas/foundry-operation-result.schema.json +147 -0
- package/specs/schemas/foundry-package-descriptor.schema.json +134 -0
- package/specs/schemas/foundry-runtime-selection.schema.json +59 -0
- package/specs/schemas/foundry-semantic-input.schema.json +36 -0
- package/specs/schemas/foundry-task-start.schema.json +123 -0
- package/specs/schemas/foundry-workspace-migration-pending.schema.json +17 -0
- package/specs/schemas/foundry-workspace-migration-plan.schema.json +59 -0
- package/specs/schemas/foundry-workspace-migration-transfer-plan.schema.json +357 -0
- package/specs/schemas/foundry-workspace-v2.schema.json +70 -0
- package/specs/schemas/runtime-qualification.schema.json +63 -0
- package/specs/schemas/task-authorization.schema.json +154 -0
- package/specs/schemas/tidas-runtime-expectation.schema.json +54 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { CLI_RUNTIME_EXPECTATION_SCHEMA, assertCliRuntimeMatches, } from "@tiangong-lca/cli/runtime";
|
|
5
|
+
import { assertFoundryRuntimeContext, captureFoundryInput, FoundryContextError, } from "./foundry-runtime-context.js";
|
|
6
|
+
import { createFoundryIsolatedChildEnvironment } from "./foundry-runtime-environment.js";
|
|
7
|
+
import { copyFoundryIsolatedExecutable } from "./foundry-runtime-environment.js";
|
|
8
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
9
|
+
import { runTidasHandshake, TIDAS_OPERATION_REPORT_SCHEMA, TIDAS_SUPPORTED_VERSION_LINES, TIDAS_VALIDATION_BATCH_FINAL_SCHEMA, TIDAS_VALIDATION_DESCRIBE_SCHEMA, } from "./tidas-adapter.js";
|
|
10
|
+
export const FOUNDRY_RUNTIME_QUALIFICATION_SCHEMA = "tiangong-foundry.runtime-qualification.v1";
|
|
11
|
+
export const FOUNDRY_TIDAS_EXPECTATION_SCHEMA = "tiangong-foundry.tidas-runtime-expectation.v1";
|
|
12
|
+
const qualifications = new WeakSet();
|
|
13
|
+
const shaPattern = /^[0-9a-f]{64}$/u;
|
|
14
|
+
const versionPattern = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/u;
|
|
15
|
+
function fail(code, message) {
|
|
16
|
+
throw new FoundryContextError(code, message);
|
|
17
|
+
}
|
|
18
|
+
function record(value, label) {
|
|
19
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
20
|
+
fail("runtime_qualification_invalid", `${label} must be an object.`);
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function exact(value, keys, label) {
|
|
24
|
+
if (Object.keys(value).length !== keys.length || keys.some((key) => !Object.hasOwn(value, key)))
|
|
25
|
+
fail("runtime_qualification_invalid", `${label} has unsupported or missing fields.`);
|
|
26
|
+
}
|
|
27
|
+
function strings(value, label) {
|
|
28
|
+
if (!Array.isArray(value) ||
|
|
29
|
+
value.length === 0 ||
|
|
30
|
+
value.length > 32 ||
|
|
31
|
+
value.some((item) => typeof item !== "string" || !item || item.length > 128) ||
|
|
32
|
+
new Set(value).size !== value.length ||
|
|
33
|
+
[...value].sort().some((item, index) => item !== value[index]))
|
|
34
|
+
fail("runtime_qualification_invalid", `${label} must be a unique, sorted, bounded string array.`);
|
|
35
|
+
return Object.freeze([...value]);
|
|
36
|
+
}
|
|
37
|
+
function parseTidasExpectation(value, platform) {
|
|
38
|
+
const item = record(value, "TIDAS runtime expectation");
|
|
39
|
+
exact(item, ["schema", "platform", "binary_version", "executable", "validation"], "TIDAS runtime expectation");
|
|
40
|
+
const executable = record(item.executable, "TIDAS executable expectation");
|
|
41
|
+
exact(executable, ["bytes", "sha256"], "TIDAS executable expectation");
|
|
42
|
+
const validation = record(item.validation, "TIDAS validation expectation");
|
|
43
|
+
exact(validation, ["schema_version", "asset_fingerprint", "protocols", "event_schema_versions"], "TIDAS validation expectation");
|
|
44
|
+
if (item.schema !== FOUNDRY_TIDAS_EXPECTATION_SCHEMA ||
|
|
45
|
+
item.platform !== platform ||
|
|
46
|
+
typeof item.binary_version !== "string" ||
|
|
47
|
+
!versionPattern.test(item.binary_version) ||
|
|
48
|
+
!TIDAS_SUPPORTED_VERSION_LINES.includes(item.binary_version.split(".").slice(0, 2).join(".")) ||
|
|
49
|
+
!Number.isSafeInteger(executable.bytes) ||
|
|
50
|
+
Number(executable.bytes) < 1 ||
|
|
51
|
+
Number(executable.bytes) > 512 * 1024 * 1024 ||
|
|
52
|
+
typeof executable.sha256 !== "string" ||
|
|
53
|
+
!shaPattern.test(executable.sha256) ||
|
|
54
|
+
validation.schema_version !== TIDAS_VALIDATION_DESCRIBE_SCHEMA ||
|
|
55
|
+
typeof validation.asset_fingerprint !== "string" ||
|
|
56
|
+
!shaPattern.test(validation.asset_fingerprint))
|
|
57
|
+
fail("runtime_qualification_invalid", "TIDAS expectation does not match the selected platform and reviewed v0.2/v0.3 contract.");
|
|
58
|
+
const protocols = strings(validation.protocols, "TIDAS protocols");
|
|
59
|
+
const eventSchemaVersions = strings(validation.event_schema_versions, "TIDAS event schemas");
|
|
60
|
+
if (!protocols.includes("document-validation-batch.v1") ||
|
|
61
|
+
!eventSchemaVersions.includes(TIDAS_VALIDATION_BATCH_FINAL_SCHEMA))
|
|
62
|
+
fail("runtime_qualification_invalid", "TIDAS expectation omits the required document-validation protocol.");
|
|
63
|
+
return Object.freeze({
|
|
64
|
+
schema: FOUNDRY_TIDAS_EXPECTATION_SCHEMA,
|
|
65
|
+
platform,
|
|
66
|
+
binary_version: item.binary_version,
|
|
67
|
+
executable: Object.freeze({
|
|
68
|
+
bytes: Number(executable.bytes),
|
|
69
|
+
sha256: executable.sha256,
|
|
70
|
+
}),
|
|
71
|
+
validation: Object.freeze({
|
|
72
|
+
schema_version: TIDAS_VALIDATION_DESCRIBE_SCHEMA,
|
|
73
|
+
asset_fingerprint: validation.asset_fingerprint,
|
|
74
|
+
protocols,
|
|
75
|
+
event_schema_versions: eventSchemaVersions,
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
export { parseTidasExpectation as parseFoundryTidasRuntimeExpectation };
|
|
80
|
+
function hash(value) {
|
|
81
|
+
return sha256Json(value);
|
|
82
|
+
}
|
|
83
|
+
function captureExpectedTidas(expectation, executablePath) {
|
|
84
|
+
if (!path.isAbsolute(executablePath))
|
|
85
|
+
fail("runtime_tidas_unqualified", "TIDAS executable selection must be absolute.");
|
|
86
|
+
const executable = captureFoundryInput(executablePath);
|
|
87
|
+
if (executable.bytes !== expectation.executable.bytes ||
|
|
88
|
+
executable.sha256 !== expectation.executable.sha256)
|
|
89
|
+
fail("runtime_tidas_unqualified", "TIDAS executable bytes do not match the independent expectation.");
|
|
90
|
+
return executable;
|
|
91
|
+
}
|
|
92
|
+
function observeTidas(context, expectation, executablePath) {
|
|
93
|
+
const executable = captureExpectedTidas(expectation, executablePath);
|
|
94
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), "foundry-runtime-qualification-"));
|
|
95
|
+
fs.chmodSync(temp, 0o700);
|
|
96
|
+
try {
|
|
97
|
+
const isolatedExecutable = path.join(temp, `tidas-runtime${path.extname(executable.path)}`);
|
|
98
|
+
copyFoundryIsolatedExecutable(executable.path, isolatedExecutable);
|
|
99
|
+
const isolated = captureFoundryInput(isolatedExecutable);
|
|
100
|
+
if (isolated.bytes !== expectation.executable.bytes ||
|
|
101
|
+
isolated.sha256 !== expectation.executable.sha256)
|
|
102
|
+
fail("runtime_tidas_unqualified", "TIDAS executable changed before it could enter the isolated qualification boundary.");
|
|
103
|
+
const environment = createFoundryIsolatedChildEnvironment({
|
|
104
|
+
tempRoot: temp,
|
|
105
|
+
sourceEnv: process.env,
|
|
106
|
+
overrides: { TIDAS_BIN: isolated.path },
|
|
107
|
+
});
|
|
108
|
+
const handshake = runTidasHandshake({
|
|
109
|
+
repoRoot: context.runtimeRoot,
|
|
110
|
+
options: { tidasBin: isolated.path },
|
|
111
|
+
environment,
|
|
112
|
+
});
|
|
113
|
+
if (handshake.stderr || handshake.validation_describe_stderr)
|
|
114
|
+
fail("runtime_tidas_unqualified", "TIDAS qualification produced diagnostics.");
|
|
115
|
+
const validation = handshake.validation_describe;
|
|
116
|
+
const protocols = [...(validation.protocols ?? [])].sort();
|
|
117
|
+
const eventSchemaVersions = [...(validation.event_schema_versions ?? [])].sort();
|
|
118
|
+
if (handshake.report.schema_version !== TIDAS_OPERATION_REPORT_SCHEMA ||
|
|
119
|
+
handshake.binary_version !== expectation.binary_version ||
|
|
120
|
+
validation.schema_version !== expectation.validation.schema_version ||
|
|
121
|
+
validation.asset_fingerprint !== expectation.validation.asset_fingerprint ||
|
|
122
|
+
JSON.stringify(protocols) !== JSON.stringify(expectation.validation.protocols) ||
|
|
123
|
+
JSON.stringify(eventSchemaVersions) !==
|
|
124
|
+
JSON.stringify(expectation.validation.event_schema_versions))
|
|
125
|
+
fail("runtime_tidas_unqualified", "TIDAS version, protocols or assets do not match the independent expectation.");
|
|
126
|
+
return executable;
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error instanceof FoundryContextError)
|
|
130
|
+
throw error;
|
|
131
|
+
return fail("runtime_tidas_unqualified", "TIDAS runtime qualification failed closed.");
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
fs.rmSync(temp, { recursive: true, force: true });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function portableIdentity(context, cli, cliExpectation, tidasExpectation) {
|
|
138
|
+
return {
|
|
139
|
+
schema: FOUNDRY_RUNTIME_QUALIFICATION_SCHEMA,
|
|
140
|
+
foundry: {
|
|
141
|
+
package_name: context.runtime.packageName,
|
|
142
|
+
package_version: context.runtime.packageVersion,
|
|
143
|
+
package_manifest_sha256: context.runtime.packageManifestSha256,
|
|
144
|
+
entry_sha256: context.runtime.entrySha256,
|
|
145
|
+
platform: context.platform,
|
|
146
|
+
},
|
|
147
|
+
cli: { expectation: cliExpectation, content_sha256: cli.content_sha256 },
|
|
148
|
+
tidas: { expectation: tidasExpectation },
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
export function qualifyFoundryRuntime(context, options) {
|
|
152
|
+
assertFoundryRuntimeContext(context);
|
|
153
|
+
let cli;
|
|
154
|
+
try {
|
|
155
|
+
cli = assertCliRuntimeMatches(options.cliExpectation);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return fail("runtime_cli_unqualified", "CLI runtime bytes do not match the independently selected C1 expectation.");
|
|
159
|
+
}
|
|
160
|
+
if (cli.package.version !== "0.1.12" || cli.platform !== context.platform)
|
|
161
|
+
fail("runtime_cli_unqualified", "Foundry requires the exact CLI 0.1.12 C1 runtime on the selected platform.");
|
|
162
|
+
const cliExpectation = Object.freeze({ ...options.cliExpectation });
|
|
163
|
+
if (cliExpectation.schema !== CLI_RUNTIME_EXPECTATION_SCHEMA)
|
|
164
|
+
fail("runtime_cli_unqualified", "CLI runtime expectation is not the supported schema.");
|
|
165
|
+
const tidasExpectation = parseTidasExpectation(options.tidasExpectation, context.platform);
|
|
166
|
+
const executable = observeTidas(context, tidasExpectation, options.tidasExecutable);
|
|
167
|
+
const portable = portableIdentity(context, cli, cliExpectation, tidasExpectation);
|
|
168
|
+
const qualification = Object.freeze({
|
|
169
|
+
...portable,
|
|
170
|
+
foundry: Object.freeze(portable.foundry),
|
|
171
|
+
cli: Object.freeze({
|
|
172
|
+
expectation: cliExpectation,
|
|
173
|
+
content_sha256: cli.content_sha256,
|
|
174
|
+
}),
|
|
175
|
+
tidas: Object.freeze({
|
|
176
|
+
expectation: tidasExpectation,
|
|
177
|
+
executable_path: executable.path,
|
|
178
|
+
}),
|
|
179
|
+
qualification_sha256: hash(portable),
|
|
180
|
+
});
|
|
181
|
+
qualifications.add(qualification);
|
|
182
|
+
return qualification;
|
|
183
|
+
}
|
|
184
|
+
export function assertQualifiedFoundryRuntime(context, qualification) {
|
|
185
|
+
assertFoundryRuntimeContext(context);
|
|
186
|
+
if (!qualification || !qualifications.has(qualification))
|
|
187
|
+
fail("runtime_qualification_unverified", "Serialized or copied runtime qualification is not execution authority.");
|
|
188
|
+
let cli;
|
|
189
|
+
try {
|
|
190
|
+
cli = assertCliRuntimeMatches(qualification.cli.expectation);
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return fail("runtime_cli_unqualified", "CLI runtime changed after its qualification was established.");
|
|
194
|
+
}
|
|
195
|
+
const expected = parseTidasExpectation(qualification.tidas.expectation, context.platform);
|
|
196
|
+
captureExpectedTidas(expected, qualification.tidas.executable_path);
|
|
197
|
+
const portable = portableIdentity(context, cli, qualification.cli.expectation, expected);
|
|
198
|
+
if (hash(portable) !== qualification.qualification_sha256 ||
|
|
199
|
+
qualification.foundry.package_manifest_sha256 !== context.runtime.packageManifestSha256 ||
|
|
200
|
+
qualification.foundry.entry_sha256 !== context.runtime.entrySha256)
|
|
201
|
+
fail("runtime_qualification_changed", "Runtime qualification no longer matches the current Foundry package.");
|
|
202
|
+
}
|
|
203
|
+
export function foundryRuntimeQualificationIdentity(context, qualification) {
|
|
204
|
+
assertQualifiedFoundryRuntime(context, qualification);
|
|
205
|
+
return Object.freeze({
|
|
206
|
+
schema: qualification.schema,
|
|
207
|
+
qualification_sha256: qualification.qualification_sha256,
|
|
208
|
+
cli: Object.freeze({
|
|
209
|
+
package_version: qualification.cli.expectation.package_version,
|
|
210
|
+
platform: qualification.cli.expectation.platform,
|
|
211
|
+
content_sha256: qualification.cli.expectation.content_sha256,
|
|
212
|
+
node_version: qualification.cli.expectation.node_version,
|
|
213
|
+
node_sha256: qualification.cli.expectation.node_sha256,
|
|
214
|
+
}),
|
|
215
|
+
tidas: Object.freeze({
|
|
216
|
+
binary_version: qualification.tidas.expectation.binary_version,
|
|
217
|
+
executable: qualification.tidas.expectation.executable,
|
|
218
|
+
asset_fingerprint: qualification.tidas.expectation.validation.asset_fingerprint,
|
|
219
|
+
protocols: qualification.tidas.expectation.validation.protocols,
|
|
220
|
+
event_schema_versions: qualification.tidas.expectation.validation.event_schema_versions,
|
|
221
|
+
}),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const FOUNDRY_RUNTIME_SELECTION_SCHEMA: "tiangong-foundry.workspace-runtime-selection.v1";
|
|
2
|
+
export interface FoundryRuntimeSelectionRecord {
|
|
3
|
+
readonly schema: typeof FOUNDRY_RUNTIME_SELECTION_SCHEMA;
|
|
4
|
+
readonly workspace_id: string;
|
|
5
|
+
readonly request_id: string;
|
|
6
|
+
readonly actor_id: string;
|
|
7
|
+
readonly previous_manifest_sha256: string;
|
|
8
|
+
readonly selected_manifest_sha256: string;
|
|
9
|
+
readonly access: "read" | "write";
|
|
10
|
+
readonly lease_ids: readonly string[];
|
|
11
|
+
readonly record_sha256: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function readFoundryRuntimeSelection(controlRoot: string, workspaceId: string, sessionReference?: string): {
|
|
14
|
+
value: FoundryRuntimeSelectionRecord;
|
|
15
|
+
bytes: Buffer;
|
|
16
|
+
} | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
3
|
+
import { transferFail, transferPath, transferRead } from "./foundry-migration-transfer-io.js";
|
|
4
|
+
import { assertNotFoundrySessionFile } from "./foundry-private-path.js";
|
|
5
|
+
export const FOUNDRY_RUNTIME_SELECTION_SCHEMA = "tiangong-foundry.workspace-runtime-selection.v1";
|
|
6
|
+
export function readFoundryRuntimeSelection(controlRoot, workspaceId, sessionReference) {
|
|
7
|
+
const file = transferPath(controlRoot, "state/runtime-selection.json");
|
|
8
|
+
if (!fs.existsSync(file))
|
|
9
|
+
return null;
|
|
10
|
+
assertNotFoundrySessionFile(file, sessionReference);
|
|
11
|
+
const bytes = transferRead(file, 64 * 1024);
|
|
12
|
+
const value = JSON.parse(bytes.toString("utf8"));
|
|
13
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
14
|
+
transferFail("runtime_selection_invalid", "Runtime selection must remain a complete record.");
|
|
15
|
+
const item = value;
|
|
16
|
+
const { record_sha256: digest, ...body } = item;
|
|
17
|
+
if (Object.keys(item).length !== 9 ||
|
|
18
|
+
item.schema !== FOUNDRY_RUNTIME_SELECTION_SCHEMA ||
|
|
19
|
+
item.workspace_id !== workspaceId ||
|
|
20
|
+
typeof item.request_id !== "string" ||
|
|
21
|
+
!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/u.test(item.request_id) ||
|
|
22
|
+
typeof item.actor_id !== "string" ||
|
|
23
|
+
!/^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u.test(item.actor_id) ||
|
|
24
|
+
![item.previous_manifest_sha256, item.selected_manifest_sha256, digest].every((value) => typeof value === "string" && /^[0-9a-f]{64}$/u.test(value)) ||
|
|
25
|
+
!["read", "write"].includes(String(item.access)) ||
|
|
26
|
+
!Array.isArray(item.lease_ids) ||
|
|
27
|
+
item.lease_ids.length !== 2 ||
|
|
28
|
+
item.lease_ids.some((id) => typeof id !== "string" || id.length > 256) ||
|
|
29
|
+
digest !== sha256Json(body))
|
|
30
|
+
transferFail("runtime_selection_invalid", "Runtime selection identity or digest changed.");
|
|
31
|
+
return { value: item, bytes };
|
|
32
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type TrustedRuntimeManifest, type RuntimeManagerOptions } from "@tiangong-lca/cli/runtime";
|
|
2
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
3
|
+
import { type FoundryRuntimeSelectionRecord } from "./foundry-runtime-selection-record.ts";
|
|
4
|
+
export type FoundryRuntimeManagerOptions = Omit<RuntimeManagerOptions, "lease">;
|
|
5
|
+
export declare function leaseFoundryRuntime(context: FoundryRuntimeContext, manifest: TrustedRuntimeManifest, workspaceId: string, manager: FoundryRuntimeManagerOptions, excludedRoots?: readonly string[]): Promise<string>;
|
|
6
|
+
export declare function selectFoundryWorkspaceRuntime(context: FoundryRuntimeContext, current: TrustedRuntimeManifest, target: TrustedRuntimeManifest, input: {
|
|
7
|
+
requestId: string;
|
|
8
|
+
actorId: string;
|
|
9
|
+
access: "read" | "write";
|
|
10
|
+
manager: FoundryRuntimeManagerOptions;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
record: FoundryRuntimeSelectionRecord;
|
|
13
|
+
path: string;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { withBatchRunLock } from "@tiangong-lca/cli/batch";
|
|
4
|
+
import { assertWorkspaceCompatibility, ensureRuntimeComponents, inspectRuntimeComponents, } from "@tiangong-lca/cli/runtime";
|
|
5
|
+
import { assertFoundryRuntimeSelector, currentFoundryRuntimeManifest, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
6
|
+
import { FOUNDRY_RUNTIME_SELECTION_SCHEMA, readFoundryRuntimeSelection, } from "./foundry-runtime-selection-record.js";
|
|
7
|
+
import { transferBytes, transferFail, transferPath, transferRead, transferWriteOnce, } from "./foundry-migration-transfer-io.js";
|
|
8
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
9
|
+
import { assertFoundryPackage } from "./foundry-package-contract.js";
|
|
10
|
+
import { canonicalFoundryCachePath as canonicalPath, foundryPathContains as within, assertFoundryCacheRootSeparated, } from "./foundry-runtime-cache.js";
|
|
11
|
+
function cacheOwnsRuntime(context, cache, manager) {
|
|
12
|
+
try {
|
|
13
|
+
const current = currentFoundryRuntimeManifest(context);
|
|
14
|
+
if (!current || current.manifest.product.version !== context.runtime.packageVersion)
|
|
15
|
+
return false;
|
|
16
|
+
const descriptor = assertFoundryPackage(context.runtimeRoot);
|
|
17
|
+
if (descriptor.package.version !== context.runtime.packageVersion)
|
|
18
|
+
return false;
|
|
19
|
+
const report = inspectRuntimeComponents(current, { cacheDir: cache, host: manager.host });
|
|
20
|
+
return (report.status === "ready" &&
|
|
21
|
+
report.components.some((component) => component.status === "ready" &&
|
|
22
|
+
within(fs.realpathSync(component.root), context.runtimeRoot)));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function componentCache(context, manager, excludedRoots = []) {
|
|
29
|
+
const cache = canonicalPath(manager.cacheDir ?? path.join(context.cacheBase, "tiangong-lca/managed-runtimes"));
|
|
30
|
+
for (const selectedRoot of [context.workspaceRoot, ...excludedRoots])
|
|
31
|
+
assertFoundryCacheRootSeparated(cache, selectedRoot);
|
|
32
|
+
const runtime = canonicalPath(context.runtimeRoot);
|
|
33
|
+
if (within(runtime, cache) ||
|
|
34
|
+
(within(cache, runtime) && !cacheOwnsRuntime(context, cache, manager)))
|
|
35
|
+
transferFail("runtime_cache_boundary", "Managed components require a separate cache or the independently verified cache owning this installed package.");
|
|
36
|
+
return cache;
|
|
37
|
+
}
|
|
38
|
+
export async function leaseFoundryRuntime(context, manifest, workspaceId, manager, excludedRoots = []) {
|
|
39
|
+
if (manager.host && manager.host.platform !== context.platform)
|
|
40
|
+
transferFail("runtime_host_mismatch", "Managed components must match the executing platform.");
|
|
41
|
+
const lease = `foundry:${workspaceId}:${manifest.sha256}`;
|
|
42
|
+
const report = await ensureRuntimeComponents(manifest, {
|
|
43
|
+
...manager,
|
|
44
|
+
cacheDir: componentCache(context, manager, excludedRoots),
|
|
45
|
+
lease: { id: lease, owner: `foundry-workspace:${context.workspaceRoot}` },
|
|
46
|
+
});
|
|
47
|
+
if (report.status !== "ready")
|
|
48
|
+
transferFail("runtime_components_required", "Every selected component must be verified before runtime selection.");
|
|
49
|
+
return lease;
|
|
50
|
+
}
|
|
51
|
+
export async function selectFoundryWorkspaceRuntime(context, current, target, input) {
|
|
52
|
+
assertFoundryRuntimeSelector(context);
|
|
53
|
+
if (current.sha256 !== context.workspaceManifestSha256 ||
|
|
54
|
+
!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/u.test(input.requestId) ||
|
|
55
|
+
!/^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u.test(input.actorId))
|
|
56
|
+
transferFail("runtime_selection_invalid", "Runtime selection requires explicit current-runtime and actor/request intent.");
|
|
57
|
+
try {
|
|
58
|
+
assertWorkspaceCompatibility(target, { schema: context.workspaceSchema, features: context.workspaceFeatures }, input.access);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
transferFail("workspace_runtime_incompatible", "The target manifest does not qualify the requested workspace access.");
|
|
62
|
+
}
|
|
63
|
+
if (target.manifest.product.id !== "tiangong-foundry")
|
|
64
|
+
transferFail("runtime_selection_invalid", "Select a Foundry product manifest.");
|
|
65
|
+
const runPath = resolveFoundryOutput(context, "runtime-selection-lock", "state");
|
|
66
|
+
return withBatchRunLock({
|
|
67
|
+
runPath,
|
|
68
|
+
identity: {
|
|
69
|
+
schema: "tiangong-foundry.runtime-selection-lock.v1",
|
|
70
|
+
workspace_id: context.workspaceId,
|
|
71
|
+
},
|
|
72
|
+
reason: "Explicit runtime selection without schema downgrade",
|
|
73
|
+
}, async () => {
|
|
74
|
+
assertFoundryRuntimeSelector(context);
|
|
75
|
+
const previous = readFoundryRuntimeSelection(context.controlRoot, context.workspaceId, context.accountIntent?.sessionReference);
|
|
76
|
+
const history = `state/runtime-selections/${sha256Json(input.requestId)}.json`;
|
|
77
|
+
const historyPath = transferPath(context.controlRoot, history);
|
|
78
|
+
if (fs.existsSync(historyPath)) {
|
|
79
|
+
const existing = JSON.parse(transferRead(historyPath).toString("utf8"));
|
|
80
|
+
const { record_sha256: digest, ...body } = existing;
|
|
81
|
+
if (existing.schema !== FOUNDRY_RUNTIME_SELECTION_SCHEMA ||
|
|
82
|
+
existing.workspace_id !== context.workspaceId ||
|
|
83
|
+
digest !== sha256Json(body) ||
|
|
84
|
+
existing.request_id !== input.requestId ||
|
|
85
|
+
existing.actor_id !== input.actorId ||
|
|
86
|
+
existing.selected_manifest_sha256 !== target.sha256 ||
|
|
87
|
+
existing.access !== input.access ||
|
|
88
|
+
existing.lease_ids[0] !== `foundry:${context.workspaceId}:${current.sha256}`)
|
|
89
|
+
transferFail("runtime_selection_conflict", "This selection request already names different intent.");
|
|
90
|
+
if (previous && previous.value.record_sha256 === existing.record_sha256) {
|
|
91
|
+
await leaseFoundryRuntime(context, current, context.workspaceId, input.manager);
|
|
92
|
+
await leaseFoundryRuntime(context, target, context.workspaceId, input.manager);
|
|
93
|
+
return { record: previous.value, path: historyPath };
|
|
94
|
+
}
|
|
95
|
+
if ((previous?.value.selected_manifest_sha256 ?? current.sha256) !==
|
|
96
|
+
existing.previous_manifest_sha256)
|
|
97
|
+
transferFail("runtime_selection_conflict", "A different selection won; the earlier request was preserved.");
|
|
98
|
+
}
|
|
99
|
+
const leases = [
|
|
100
|
+
await leaseFoundryRuntime(context, current, context.workspaceId, input.manager),
|
|
101
|
+
await leaseFoundryRuntime(context, target, context.workspaceId, input.manager),
|
|
102
|
+
];
|
|
103
|
+
const body = {
|
|
104
|
+
schema: FOUNDRY_RUNTIME_SELECTION_SCHEMA,
|
|
105
|
+
workspace_id: context.workspaceId,
|
|
106
|
+
request_id: input.requestId,
|
|
107
|
+
actor_id: input.actorId,
|
|
108
|
+
previous_manifest_sha256: previous?.value.selected_manifest_sha256 ?? current.sha256,
|
|
109
|
+
selected_manifest_sha256: target.sha256,
|
|
110
|
+
access: input.access,
|
|
111
|
+
lease_ids: leases,
|
|
112
|
+
};
|
|
113
|
+
const record = { ...body, record_sha256: sha256Json(body) };
|
|
114
|
+
transferWriteOnce(context.controlRoot, history, transferBytes(record));
|
|
115
|
+
const actual = readFoundryRuntimeSelection(context.controlRoot, context.workspaceId, context.accountIntent?.sessionReference);
|
|
116
|
+
if ((actual?.bytes.toString("base64") ?? null) !== (previous?.bytes.toString("base64") ?? null))
|
|
117
|
+
transferFail("runtime_selection_conflict", "Runtime selection changed while components were verified.");
|
|
118
|
+
const next = `state/runtime-selections/${record.record_sha256}.next.json`;
|
|
119
|
+
transferWriteOnce(context.controlRoot, next, transferBytes(record));
|
|
120
|
+
fs.renameSync(transferPath(context.controlRoot, next), transferPath(context.controlRoot, "state/runtime-selection.json"));
|
|
121
|
+
return { record, path: historyPath };
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
export interface InstalledTiangongLcaCliPackage {
|
|
2
|
+
packageName: string;
|
|
3
|
+
packageVersion: string;
|
|
4
|
+
packageSpec: string;
|
|
5
|
+
packageJsonPath: string;
|
|
6
|
+
packageRoot: string;
|
|
7
|
+
binName: string;
|
|
8
|
+
binPath: string;
|
|
9
|
+
schemaDir: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TiangongLcaCliRuntimeCommand {
|
|
12
|
+
command: string;
|
|
13
|
+
args: string[];
|
|
14
|
+
display: string;
|
|
15
|
+
source: "TIANGONG_LCA_CLI_BIN" | "installed_package";
|
|
16
|
+
package: string | null;
|
|
17
|
+
package_version: string | null;
|
|
18
|
+
package_root?: string;
|
|
19
|
+
bin_path: string;
|
|
20
|
+
}
|
|
21
|
+
export interface FoundryRuntimeDependencies {
|
|
22
|
+
parseScalar: (value: unknown) => unknown;
|
|
23
|
+
repoRoot: string;
|
|
24
|
+
}
|
|
25
|
+
interface JsonRecord {
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface RuntimeStage extends JsonRecord {
|
|
29
|
+
stage?: string;
|
|
30
|
+
status?: string;
|
|
31
|
+
exit_code?: number;
|
|
32
|
+
command?: string;
|
|
33
|
+
args?: string[];
|
|
34
|
+
stderr?: string;
|
|
35
|
+
report?: JsonRecord | null;
|
|
36
|
+
report_file?: string | null;
|
|
37
|
+
}
|
|
38
|
+
interface LoadEnvOptions {
|
|
39
|
+
override?: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface LoadRuntimeEnvOptions {
|
|
42
|
+
allowFilesystemEnv?: boolean;
|
|
43
|
+
}
|
|
44
|
+
interface GateBlockerOptions {
|
|
45
|
+
code: string;
|
|
46
|
+
message: string;
|
|
47
|
+
}
|
|
48
|
+
interface PostAuthoringGateOptions {
|
|
49
|
+
schemaStage: RuntimeStage;
|
|
50
|
+
qaStage: RuntimeStage;
|
|
51
|
+
locationAuditBlockers: JsonRecord[];
|
|
52
|
+
curationGate: JsonRecord | null;
|
|
53
|
+
curationGateReportFile: string | null;
|
|
54
|
+
requireDeterministicQa?: boolean;
|
|
55
|
+
requireCurationGate?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export declare function resolveInstalledTiangongLcaCliPackage(): InstalledTiangongLcaCliPackage;
|
|
58
|
+
export declare function resolveTiangongLcaCliRuntimeCommand(env?: NodeJS.ProcessEnv): TiangongLcaCliRuntimeCommand;
|
|
59
|
+
export declare function createFoundryRuntimeUtils({ parseScalar, repoRoot }: FoundryRuntimeDependencies): {
|
|
60
|
+
appendOption: (args: string[], flag: string, value: unknown) => void;
|
|
61
|
+
appendRepeatedOptions: (args: string[], flag: string, values: unknown) => void;
|
|
62
|
+
asText: (value: unknown) => string;
|
|
63
|
+
blockersFromLocationAuditStage: (stage: RuntimeStage | null | undefined) => JsonRecord[];
|
|
64
|
+
booleanOption: (value: unknown) => boolean;
|
|
65
|
+
cloneJson: <T>(value: T) => T;
|
|
66
|
+
compactStageReport: (stage: RuntimeStage) => {
|
|
67
|
+
stage: string | undefined;
|
|
68
|
+
status: {} | null;
|
|
69
|
+
exit_code: number | undefined;
|
|
70
|
+
command: string | undefined;
|
|
71
|
+
args: string[] | undefined;
|
|
72
|
+
stderr: string | undefined;
|
|
73
|
+
report_file: string | null;
|
|
74
|
+
};
|
|
75
|
+
countJsonLinesFile: (filePath: string | null | undefined) => number;
|
|
76
|
+
countRowsFile: (filePath: string | null | undefined) => number;
|
|
77
|
+
deterministicUuid: (input: unknown) => string;
|
|
78
|
+
directoryExists: (filePath: string | null | undefined) => boolean;
|
|
79
|
+
ensureArray: (value: unknown) => unknown[];
|
|
80
|
+
fileExists: (filePath: string | null | undefined) => boolean;
|
|
81
|
+
findFilesByName: (startDir: unknown, fileName: string, maxDepth?: number) => string[];
|
|
82
|
+
hasUnresolvedAiPlaceholder: (value: unknown) => boolean;
|
|
83
|
+
hasUsableEnvValue: (key: string) => boolean;
|
|
84
|
+
integerOption: (value: unknown, fallback?: number | null) => number | null;
|
|
85
|
+
isPlaceholderEnvValue: (value: unknown) => boolean;
|
|
86
|
+
jsonSha256: (value: unknown) => string;
|
|
87
|
+
loadEnvFile: (filePath: string | null, { override }?: LoadEnvOptions) => {
|
|
88
|
+
file: string | null;
|
|
89
|
+
loaded: boolean;
|
|
90
|
+
keys: never[];
|
|
91
|
+
} | {
|
|
92
|
+
file: string;
|
|
93
|
+
loaded: boolean;
|
|
94
|
+
keys: string[];
|
|
95
|
+
};
|
|
96
|
+
loadRuntimeEnv: (options?: LoadRuntimeEnvOptions) => {
|
|
97
|
+
repoEnv: {
|
|
98
|
+
file: string | null;
|
|
99
|
+
loaded: boolean;
|
|
100
|
+
keys: never[];
|
|
101
|
+
} | {
|
|
102
|
+
file: string;
|
|
103
|
+
loaded: boolean;
|
|
104
|
+
keys: string[];
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
normalizedList: (value: unknown) => string[];
|
|
108
|
+
nowIso: () => string;
|
|
109
|
+
positiveIntegerOption: (value: unknown, fallback?: number | null) => number | null;
|
|
110
|
+
postAuthoringPrewriteGateBlockers: ({ schemaStage, qaStage, locationAuditBlockers, curationGate, curationGateReportFile, requireDeterministicQa, requireCurationGate, }: PostAuthoringGateOptions) => JsonRecord[];
|
|
111
|
+
readJson: (filePath: string) => unknown;
|
|
112
|
+
readJsonArtifactOption: (value: unknown) => {
|
|
113
|
+
path: string;
|
|
114
|
+
value: unknown;
|
|
115
|
+
} | null;
|
|
116
|
+
readJsonLines: (filePath: string) => unknown[];
|
|
117
|
+
readJsonOrJsonLines: (filePath: unknown) => unknown[];
|
|
118
|
+
readRowsFile: (filePath: string | null | undefined) => unknown[];
|
|
119
|
+
readText: (filePath: string) => string;
|
|
120
|
+
replaceFrontmatterField: (frontmatter: string, key: string, value: unknown) => string;
|
|
121
|
+
reportFileFromCliStage: (stage: RuntimeStage, selectors: string[], fallbackPath: unknown) => string | null;
|
|
122
|
+
reportInputPath: (report: unknown) => string;
|
|
123
|
+
repoRelativeMaybe: (filePath: string | null | undefined) => string | null;
|
|
124
|
+
repoRelativePath: (filePath: string) => string;
|
|
125
|
+
resolveRepoPath: (filePath: unknown) => string | null;
|
|
126
|
+
resolveTiangongLcaCliCommand: () => TiangongLcaCliRuntimeCommand;
|
|
127
|
+
resolveTiangongLcaCliCommandPrefix: () => string[];
|
|
128
|
+
resolveTiangongLcaCliBin: () => string;
|
|
129
|
+
runTiangongJsonStage: (stage: string, args: string[]) => {
|
|
130
|
+
stage: string;
|
|
131
|
+
command: string;
|
|
132
|
+
executable: string;
|
|
133
|
+
args: string[];
|
|
134
|
+
cli_args: string[];
|
|
135
|
+
cli_package: string | null;
|
|
136
|
+
exit_code: number;
|
|
137
|
+
stderr: string;
|
|
138
|
+
report: unknown;
|
|
139
|
+
report_file: null;
|
|
140
|
+
};
|
|
141
|
+
sameResolvedPath: (left: string | null | undefined, right: string | null | undefined) => boolean;
|
|
142
|
+
sha256Text: (value: unknown) => string;
|
|
143
|
+
shellQuote: (value: unknown) => string;
|
|
144
|
+
skippedPrewriteStage: (stage: string, reason: string) => {
|
|
145
|
+
stage: string;
|
|
146
|
+
status: string;
|
|
147
|
+
exit_code: number;
|
|
148
|
+
command: string;
|
|
149
|
+
args: never[];
|
|
150
|
+
stderr: string;
|
|
151
|
+
report: {
|
|
152
|
+
status: string;
|
|
153
|
+
reason: string;
|
|
154
|
+
};
|
|
155
|
+
report_file: null;
|
|
156
|
+
};
|
|
157
|
+
splitFrontmatter: (text: string) => {
|
|
158
|
+
frontmatter: string;
|
|
159
|
+
body: string;
|
|
160
|
+
};
|
|
161
|
+
stageExitBlocker: (stage: RuntimeStage | null | undefined, { code, message }: GateBlockerOptions) => {
|
|
162
|
+
code: string;
|
|
163
|
+
stage: string | null;
|
|
164
|
+
message: string;
|
|
165
|
+
exit_code: number | null;
|
|
166
|
+
report_file: string | null;
|
|
167
|
+
} | null;
|
|
168
|
+
taskMetaFromFile: (filePath: string) => {
|
|
169
|
+
text: string;
|
|
170
|
+
frontmatter: string;
|
|
171
|
+
body: string;
|
|
172
|
+
meta: Record<string, unknown>;
|
|
173
|
+
};
|
|
174
|
+
unique: <T>(values: T[]) => T[];
|
|
175
|
+
writeJson: (filePath: string, value: unknown) => void;
|
|
176
|
+
writeText: (filePath: string, text: string) => void;
|
|
177
|
+
};
|
|
178
|
+
export {};
|