@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,187 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { assertFoundryWorkspaceWrite, withFoundryPendingAdoption, } from "./foundry-runtime-context.js";
|
|
4
|
+
import { assertFoundryMigrationJson, revalidateFoundryMigrationPlan, } from "./foundry-migration-plan.js";
|
|
5
|
+
import { auditFoundryMigration, withFoundryMigrationLock } from "./foundry-migration-transfer.js";
|
|
6
|
+
import { planFoundryMigrationAdoption, materializeMigrationTaskSpec, } from "./foundry-migration-adoption-plan.js";
|
|
7
|
+
import { FOUNDRY_MIGRATION_ACTIVATION_SCHEMA, FOUNDRY_MIGRATED_WORKSPACE_SCHEMA, FOUNDRY_MIGRATED_WORKSPACE_FEATURES, readFoundryMigrationAuthority, } from "./foundry-migration-authority.js";
|
|
8
|
+
import { transferBytes, transferFail, transferFileFact, transferHash, transferPath, transferRead, transferWriteOnce, } from "./foundry-migration-transfer-io.js";
|
|
9
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
10
|
+
import { leaseFoundryRuntime } from "./foundry-runtime-selection.js";
|
|
11
|
+
function check(options) {
|
|
12
|
+
if (options.signal?.aborted)
|
|
13
|
+
transferFail("operation_interrupted", "Adoption was interrupted; preserved source and pending state remain available for recovery.");
|
|
14
|
+
}
|
|
15
|
+
function sameAdoption(provided, current) {
|
|
16
|
+
assertFoundryMigrationJson(provided);
|
|
17
|
+
if (sha256Json(provided) !== sha256Json(current))
|
|
18
|
+
transferFail("migration_adoption_changed", "The supplied adoption differs from independent source, task, actor or runtime selections.");
|
|
19
|
+
}
|
|
20
|
+
function protectedFact(context, relative) {
|
|
21
|
+
const fact = transferFileFact(transferPath(context.controlRoot, relative));
|
|
22
|
+
return { path: relative, bytes: fact.bytes, sha256: fact.sha256 };
|
|
23
|
+
}
|
|
24
|
+
export async function applyFoundryMigrationAdoption(context, planning, transfer, selections, provided, manifest, host, options = {}) {
|
|
25
|
+
assertFoundryWorkspaceWrite(context);
|
|
26
|
+
check(options);
|
|
27
|
+
assertFoundryMigrationJson(provided);
|
|
28
|
+
if (context.migration) {
|
|
29
|
+
revalidateFoundryMigrationPlan(context, planning, transfer, context.migration.plan_sha256);
|
|
30
|
+
const base = `migrations/${context.migration.plan_sha256}`;
|
|
31
|
+
const saved = JSON.parse(transferRead(transferPath(context.controlRoot, `${base}/adoption.json`)).toString("utf8"));
|
|
32
|
+
sameAdoption(provided, saved);
|
|
33
|
+
const selected = selections
|
|
34
|
+
.map((item) => ({ source_task: item.sourceTask, spec_file: path.resolve(item.specFile) }))
|
|
35
|
+
.sort((a, b) => (a.source_task < b.source_task ? -1 : a.source_task > b.source_task ? 1 : 0));
|
|
36
|
+
if (saved.runtime_manifest_sha256 !== manifest.sha256 ||
|
|
37
|
+
sha256Json(saved.selections) !== sha256Json(selected))
|
|
38
|
+
transferFail("migration_adoption_changed", "Repeated application requires the same independent task and runtime selections.");
|
|
39
|
+
const activation = readFoundryMigrationAuthority(context.controlRoot, context.workspaceId, context.migration);
|
|
40
|
+
return { activation, path: transferPath(context.controlRoot, `${base}/activation.json`) };
|
|
41
|
+
}
|
|
42
|
+
const planned = await planFoundryMigrationAdoption(context, planning, transfer, selections, manifest);
|
|
43
|
+
sameAdoption(provided, planned);
|
|
44
|
+
return withFoundryMigrationLock(context, planning.sourceWorkspace, async () => {
|
|
45
|
+
check(options);
|
|
46
|
+
const plan = await planFoundryMigrationAdoption(context, planning, transfer, selections, manifest);
|
|
47
|
+
sameAdoption(provided, plan);
|
|
48
|
+
if (host.runtimeManager)
|
|
49
|
+
await leaseFoundryRuntime(context, manifest, plan.workspace_id, host.runtimeManager, [
|
|
50
|
+
planning.sourceWorkspace,
|
|
51
|
+
]);
|
|
52
|
+
const base = `migrations/${plan.plan_sha256}`;
|
|
53
|
+
const scratch = `${base}/scratch`;
|
|
54
|
+
transferWriteOnce(context.controlRoot, `${base}/adoption.json`, transferBytes(plan), scratch);
|
|
55
|
+
for (const row of plan.tasks) {
|
|
56
|
+
if (row.source_spec) {
|
|
57
|
+
const selected = transferRead(row.source_spec.path, 1024 * 1024);
|
|
58
|
+
if (selected.length !== row.source_spec.bytes ||
|
|
59
|
+
transferHash(selected) !== row.source_spec.sha256)
|
|
60
|
+
transferFail("migration_source_changed", "Selected current task specification changed before adoption.");
|
|
61
|
+
transferWriteOnce(context.controlRoot, `${base}/specs/source-${row.source_spec.sha256}.json`, selected, scratch);
|
|
62
|
+
}
|
|
63
|
+
if (row.target_spec)
|
|
64
|
+
transferWriteOnce(context.controlRoot, `${base}/specs/${row.authority.task_id}.json`, transferBytes(materializeMigrationTaskSpec(row.target_spec)), scratch);
|
|
65
|
+
}
|
|
66
|
+
options.checkpoint?.("mapped", 0);
|
|
67
|
+
check(options);
|
|
68
|
+
await withFoundryPendingAdoption(context, async () => {
|
|
69
|
+
const facade = host.createTaskFacade();
|
|
70
|
+
let index = 0;
|
|
71
|
+
for (const row of plan.tasks) {
|
|
72
|
+
if (!row.target_spec || !row.authority.task_id)
|
|
73
|
+
continue;
|
|
74
|
+
check(options);
|
|
75
|
+
const started = await facade.start({
|
|
76
|
+
specFile: transferPath(context.controlRoot, `${base}/specs/${row.authority.task_id}.json`),
|
|
77
|
+
});
|
|
78
|
+
if (started.task_id !== row.authority.task_id ||
|
|
79
|
+
!["ready", "blocked"].includes(started.status))
|
|
80
|
+
transferFail("migration_preparation_failed", `Current task registration did not complete: ${started.blockers[0]?.code ?? started.status}.`);
|
|
81
|
+
if (row.target_spec.preparation) {
|
|
82
|
+
const prepared = await facade.resume({
|
|
83
|
+
taskId: row.authority.task_id,
|
|
84
|
+
actorId: row.authority.actor_id,
|
|
85
|
+
});
|
|
86
|
+
if (!["ready", "blocked"].includes(prepared.status) ||
|
|
87
|
+
prepared.blockers.some((item) => /attempt|readback|predecessor/u.test(item.code)))
|
|
88
|
+
transferFail("migration_preparation_failed", `Current local preparation did not complete: ${prepared.blockers[0]?.code ?? prepared.status}.`);
|
|
89
|
+
}
|
|
90
|
+
const inspected = await facade.status({
|
|
91
|
+
taskId: row.authority.task_id,
|
|
92
|
+
actorId: row.authority.actor_id,
|
|
93
|
+
});
|
|
94
|
+
if (!["ready", "blocked"].includes(inspected.status) ||
|
|
95
|
+
inspected.blockers.some((item) => /attempt|readback|predecessor/u.test(item.code)))
|
|
96
|
+
transferFail("migration_preparation_failed", "Adopted task cannot pass independent current-owner inspection.");
|
|
97
|
+
options.checkpoint?.("prepared", ++index);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
check(options);
|
|
101
|
+
const original = auditFoundryMigration(context, planning, transfer);
|
|
102
|
+
sameAdoption(provided, await planFoundryMigrationAdoption(context, planning, transfer, selections, manifest));
|
|
103
|
+
const pending = transferRead(transferPath(context.controlRoot, "workspace.json"), 64 * 1024);
|
|
104
|
+
transferWriteOnce(context.controlRoot, `${base}/pending-marker.json`, pending, scratch);
|
|
105
|
+
const names = new Set([
|
|
106
|
+
`${base}/plan.json`,
|
|
107
|
+
`${base}/receipt.json`,
|
|
108
|
+
`${base}/adoption.json`,
|
|
109
|
+
`${base}/pending-marker.json`,
|
|
110
|
+
...original.receipt.files.map((file) => file.destination),
|
|
111
|
+
]);
|
|
112
|
+
for (const row of plan.tasks) {
|
|
113
|
+
if (row.source_spec)
|
|
114
|
+
names.add(`${base}/specs/source-${row.source_spec.sha256}.json`);
|
|
115
|
+
const id = row.authority.task_id;
|
|
116
|
+
if (!id)
|
|
117
|
+
continue;
|
|
118
|
+
names.add(`${base}/specs/${id}.json`);
|
|
119
|
+
for (const name of [
|
|
120
|
+
"foundry-job.json",
|
|
121
|
+
"source-manifest.json",
|
|
122
|
+
"profile-lock.json",
|
|
123
|
+
"seed-manifest.json",
|
|
124
|
+
"account-intent.json",
|
|
125
|
+
]) {
|
|
126
|
+
const relative = `workspaces/${id}/${name}`;
|
|
127
|
+
if (fs.existsSync(transferPath(context.controlRoot, relative)))
|
|
128
|
+
names.add(relative);
|
|
129
|
+
}
|
|
130
|
+
for (const area of [
|
|
131
|
+
"task-registrations",
|
|
132
|
+
"task-publications",
|
|
133
|
+
"task-accounts",
|
|
134
|
+
"facade-tasks",
|
|
135
|
+
]) {
|
|
136
|
+
const relative = `state/${area}/${id}.json`;
|
|
137
|
+
if (fs.existsSync(transferPath(context.controlRoot, relative)))
|
|
138
|
+
names.add(relative);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const protectedFiles = [...names].sort().map((name) => protectedFact(context, name));
|
|
142
|
+
const activationPath = transferPath(context.controlRoot, `${base}/activation.json`);
|
|
143
|
+
const previous = fs.existsSync(activationPath)
|
|
144
|
+
? JSON.parse(transferRead(activationPath).toString("utf8"))
|
|
145
|
+
: null;
|
|
146
|
+
const payload = {
|
|
147
|
+
schema: FOUNDRY_MIGRATION_ACTIVATION_SCHEMA,
|
|
148
|
+
workspace_id: plan.workspace_id,
|
|
149
|
+
plan_sha256: plan.plan_sha256,
|
|
150
|
+
adoption_sha256: plan.adoption_sha256,
|
|
151
|
+
created_at_utc: previous?.created_at_utc ?? new Date().toISOString(),
|
|
152
|
+
tasks: plan.tasks.map((row) => row.authority),
|
|
153
|
+
protected_files: protectedFiles,
|
|
154
|
+
remote_write_allowed: false,
|
|
155
|
+
};
|
|
156
|
+
const activation = {
|
|
157
|
+
...payload,
|
|
158
|
+
activation_sha256: sha256Json(payload),
|
|
159
|
+
};
|
|
160
|
+
transferWriteOnce(context.controlRoot, `${base}/activation.json`, transferBytes(activation), scratch);
|
|
161
|
+
const binding = {
|
|
162
|
+
plan_sha256: plan.plan_sha256,
|
|
163
|
+
activation_sha256: transferHash(transferBytes(activation)),
|
|
164
|
+
};
|
|
165
|
+
readFoundryMigrationAuthority(context.controlRoot, plan.workspace_id, binding);
|
|
166
|
+
options.checkpoint?.("audited", plan.tasks.length);
|
|
167
|
+
check(options);
|
|
168
|
+
auditFoundryMigration(context, planning, transfer);
|
|
169
|
+
sameAdoption(provided, await planFoundryMigrationAdoption(context, planning, transfer, selections, manifest));
|
|
170
|
+
readFoundryMigrationAuthority(context.controlRoot, plan.workspace_id, binding);
|
|
171
|
+
const marker = transferBytes({
|
|
172
|
+
schema: FOUNDRY_MIGRATED_WORKSPACE_SCHEMA,
|
|
173
|
+
layout_version: 2,
|
|
174
|
+
workspace_id: plan.workspace_id,
|
|
175
|
+
created_at_utc: activation.created_at_utc,
|
|
176
|
+
required_features: FOUNDRY_MIGRATED_WORKSPACE_FEATURES,
|
|
177
|
+
migration: binding,
|
|
178
|
+
extensions: {},
|
|
179
|
+
});
|
|
180
|
+
transferWriteOnce(context.controlRoot, `${base}/workspace-next.json`, marker, scratch);
|
|
181
|
+
if (!transferRead(transferPath(context.controlRoot, "workspace.json"), 64 * 1024).equals(pending))
|
|
182
|
+
transferFail("migration_destination_conflict", "Workspace marker changed before activation; all state was preserved.");
|
|
183
|
+
fs.renameSync(transferPath(context.controlRoot, `${base}/workspace-next.json`), transferPath(context.controlRoot, "workspace.json"));
|
|
184
|
+
options.checkpoint?.("activated", plan.tasks.length);
|
|
185
|
+
return { activation, path: activationPath };
|
|
186
|
+
});
|
|
187
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FoundryRuntimeContext } from "./foundry-runtime-context-types.ts";
|
|
2
|
+
export declare const FOUNDRY_MIGRATION_ACTIVATION_SCHEMA: "tiangong-foundry.migration-activation.v1";
|
|
3
|
+
export declare const FOUNDRY_MIGRATED_WORKSPACE_SCHEMA: "tiangong-foundry.workspace.v2";
|
|
4
|
+
export declare const FOUNDRY_MIGRATED_WORKSPACE_FEATURES: readonly string[];
|
|
5
|
+
export interface MigrationProtectedFile {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly bytes: number;
|
|
8
|
+
readonly sha256: string;
|
|
9
|
+
}
|
|
10
|
+
export interface MigrationTaskAuthority {
|
|
11
|
+
readonly source_task: string;
|
|
12
|
+
readonly origin_sha256: string;
|
|
13
|
+
readonly disposition: "local-unattempted" | "terminal-retained" | "owner-readback-only" | "blocked-evidence";
|
|
14
|
+
readonly task_id: string | null;
|
|
15
|
+
readonly request_id: string | null;
|
|
16
|
+
readonly actor_id: string;
|
|
17
|
+
readonly spec_fingerprint_sha256: string | null;
|
|
18
|
+
readonly scope_keys: readonly string[];
|
|
19
|
+
readonly scope_complete: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface FoundryMigrationActivation {
|
|
22
|
+
readonly schema: typeof FOUNDRY_MIGRATION_ACTIVATION_SCHEMA;
|
|
23
|
+
readonly workspace_id: string;
|
|
24
|
+
readonly plan_sha256: string;
|
|
25
|
+
readonly adoption_sha256: string;
|
|
26
|
+
readonly created_at_utc: string;
|
|
27
|
+
readonly tasks: readonly MigrationTaskAuthority[];
|
|
28
|
+
readonly protected_files: readonly MigrationProtectedFile[];
|
|
29
|
+
readonly remote_write_allowed: false;
|
|
30
|
+
readonly activation_sha256: string;
|
|
31
|
+
}
|
|
32
|
+
/** Uses the existing dataset owner interpretation; metadata or opaque inputs never prove an empty scope. */
|
|
33
|
+
export declare function migrationDatasetScope(file: string, data: Buffer): {
|
|
34
|
+
keys: string[];
|
|
35
|
+
complete: boolean;
|
|
36
|
+
};
|
|
37
|
+
export declare function readFoundryMigrationAuthority(controlRoot: string, workspaceId: string, migration: {
|
|
38
|
+
readonly plan_sha256: string;
|
|
39
|
+
readonly activation_sha256: string;
|
|
40
|
+
}, verifyProtected?: boolean, sessionReference?: string): Readonly<FoundryMigrationActivation>;
|
|
41
|
+
export declare function assertMigrationTaskIntent(context: FoundryRuntimeContext, requestId: string, actorId: string, id: string, fingerprint?: string): void;
|
|
42
|
+
export declare function migratedTaskRoot(controlRoot: string, planSha256: string): string;
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
3
|
+
import { transferFail, transferRead, transferHash, transferPath, transferFileFact, } from "./foundry-migration-transfer-io.js";
|
|
4
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
5
|
+
import { datasetIdentity, detectDatasetType, unwrapDatasetPayload, } from "./import-curation/internal/dataset-payload.js";
|
|
6
|
+
import { assertNotFoundrySessionFile } from "./foundry-private-path.js";
|
|
7
|
+
export const FOUNDRY_MIGRATION_ACTIVATION_SCHEMA = "tiangong-foundry.migration-activation.v1";
|
|
8
|
+
export const FOUNDRY_MIGRATED_WORKSPACE_SCHEMA = "tiangong-foundry.workspace.v2";
|
|
9
|
+
export const FOUNDRY_MIGRATED_WORKSPACE_FEATURES = Object.freeze([
|
|
10
|
+
"migration-adoption-v1",
|
|
11
|
+
"registered-tasks-v2",
|
|
12
|
+
]);
|
|
13
|
+
const sha = /^[0-9a-f]{64}$/u;
|
|
14
|
+
const taskId = /^task-[0-9a-f]{64}-r\d{4}$/u;
|
|
15
|
+
const scopeKey = /^(?:contact|source|flow|flowproperty|unitgroup|process|lifecyclemodel):[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}@[0-9]{2}\.[0-9]{2}\.[0-9]{3}$/u;
|
|
16
|
+
/** Uses the existing dataset owner interpretation; metadata or opaque inputs never prove an empty scope. */
|
|
17
|
+
export function migrationDatasetScope(file, data) {
|
|
18
|
+
try {
|
|
19
|
+
const rows = readRows(file, () => data.toString("utf8"));
|
|
20
|
+
if (!rows.length || rows.length > 100_000)
|
|
21
|
+
return { keys: [], complete: false };
|
|
22
|
+
const keys = new Set();
|
|
23
|
+
for (const [index, row] of rows.entries()) {
|
|
24
|
+
const type = detectDatasetType(row) ??
|
|
25
|
+
[
|
|
26
|
+
"flow",
|
|
27
|
+
"process",
|
|
28
|
+
"contact",
|
|
29
|
+
"source",
|
|
30
|
+
"unitgroup",
|
|
31
|
+
"flowproperty",
|
|
32
|
+
"lifecyclemodel",
|
|
33
|
+
].find((candidate) => detectDatasetType(unwrapDatasetPayload(row, candidate)) === candidate);
|
|
34
|
+
if (!type)
|
|
35
|
+
return { keys: [...keys].sort(), complete: false };
|
|
36
|
+
const identity = datasetIdentity(row, index, type);
|
|
37
|
+
const key = `${identity.dataset_type}:${identity.id.toLowerCase()}@${identity.version}`;
|
|
38
|
+
if (!scopeKey.test(key))
|
|
39
|
+
return { keys: [...keys].sort(), complete: false };
|
|
40
|
+
keys.add(key);
|
|
41
|
+
}
|
|
42
|
+
return { keys: [...keys].sort(), complete: true };
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return { keys: [], complete: false };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function object(value) {
|
|
49
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
50
|
+
transferFail("migration_authority_invalid", "Migration authority must be a JSON object.");
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function exact(value, fields) {
|
|
54
|
+
if (Object.keys(value).length !== fields.length ||
|
|
55
|
+
fields.some((key) => !Object.hasOwn(value, key)))
|
|
56
|
+
transferFail("migration_authority_invalid", "Migration authority fields differ from the supported contract.");
|
|
57
|
+
}
|
|
58
|
+
export function readFoundryMigrationAuthority(controlRoot, workspaceId, migration, verifyProtected = true, sessionReference) {
|
|
59
|
+
const checkedRead = (relative, limit = 16 * 1024 * 1024) => {
|
|
60
|
+
const file = transferPath(controlRoot, relative);
|
|
61
|
+
assertNotFoundrySessionFile(file, sessionReference);
|
|
62
|
+
return transferRead(file, limit);
|
|
63
|
+
};
|
|
64
|
+
const bytes = checkedRead(`migrations/${migration.plan_sha256}/activation.json`);
|
|
65
|
+
if (transferHash(bytes) !== migration.activation_sha256)
|
|
66
|
+
transferFail("migration_authority_changed", "Migration activation differs from the workspace anchor.");
|
|
67
|
+
const value = object(JSON.parse(bytes.toString("utf8")));
|
|
68
|
+
exact(value, [
|
|
69
|
+
"schema",
|
|
70
|
+
"workspace_id",
|
|
71
|
+
"plan_sha256",
|
|
72
|
+
"adoption_sha256",
|
|
73
|
+
"created_at_utc",
|
|
74
|
+
"tasks",
|
|
75
|
+
"protected_files",
|
|
76
|
+
"remote_write_allowed",
|
|
77
|
+
"activation_sha256",
|
|
78
|
+
]);
|
|
79
|
+
const { activation_sha256: digest, ...unsigned } = value;
|
|
80
|
+
if (value.schema !== FOUNDRY_MIGRATION_ACTIVATION_SCHEMA ||
|
|
81
|
+
value.workspace_id !== workspaceId ||
|
|
82
|
+
value.plan_sha256 !== migration.plan_sha256 ||
|
|
83
|
+
typeof value.adoption_sha256 !== "string" ||
|
|
84
|
+
!sha.test(value.adoption_sha256) ||
|
|
85
|
+
digest !== sha256Json(unsigned) ||
|
|
86
|
+
value.remote_write_allowed !== false ||
|
|
87
|
+
typeof value.created_at_utc !== "string" ||
|
|
88
|
+
!Number.isFinite(Date.parse(value.created_at_utc)) ||
|
|
89
|
+
new Date(value.created_at_utc).toISOString() !== value.created_at_utc ||
|
|
90
|
+
!Array.isArray(value.tasks) ||
|
|
91
|
+
value.tasks.length > 1000 ||
|
|
92
|
+
!Array.isArray(value.protected_files) ||
|
|
93
|
+
value.protected_files.length > 20_000)
|
|
94
|
+
transferFail("migration_authority_invalid", "Migration activation identity or digest is invalid.");
|
|
95
|
+
const ids = new Set(), origins = new Set();
|
|
96
|
+
for (const entry of value.tasks) {
|
|
97
|
+
const item = object(entry);
|
|
98
|
+
exact(item, [
|
|
99
|
+
"source_task",
|
|
100
|
+
"origin_sha256",
|
|
101
|
+
"disposition",
|
|
102
|
+
"task_id",
|
|
103
|
+
"request_id",
|
|
104
|
+
"actor_id",
|
|
105
|
+
"spec_fingerprint_sha256",
|
|
106
|
+
"scope_keys",
|
|
107
|
+
"scope_complete",
|
|
108
|
+
]);
|
|
109
|
+
if (typeof item.source_task !== "string" ||
|
|
110
|
+
!item.source_task ||
|
|
111
|
+
typeof item.origin_sha256 !== "string" ||
|
|
112
|
+
!sha.test(item.origin_sha256) ||
|
|
113
|
+
origins.has(item.origin_sha256) ||
|
|
114
|
+
typeof item.actor_id !== "string" ||
|
|
115
|
+
!/^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u.test(item.actor_id) ||
|
|
116
|
+
![
|
|
117
|
+
"local-unattempted",
|
|
118
|
+
"terminal-retained",
|
|
119
|
+
"owner-readback-only",
|
|
120
|
+
"blocked-evidence",
|
|
121
|
+
].includes(String(item.disposition)))
|
|
122
|
+
transferFail("migration_authority_invalid", "Migration task origin or disposition is invalid.");
|
|
123
|
+
if (!Array.isArray(item.scope_keys) ||
|
|
124
|
+
item.scope_keys.length > 100_000 ||
|
|
125
|
+
item.scope_keys.some((key) => typeof key !== "string" || !scopeKey.test(key)) ||
|
|
126
|
+
new Set(item.scope_keys).size !== item.scope_keys.length ||
|
|
127
|
+
typeof item.scope_complete !== "boolean" ||
|
|
128
|
+
(item.scope_complete && item.scope_keys.length === 0))
|
|
129
|
+
transferFail("migration_authority_invalid", "Migration dataset scope is invalid.");
|
|
130
|
+
origins.add(item.origin_sha256);
|
|
131
|
+
if (item.disposition === "local-unattempted") {
|
|
132
|
+
if (typeof item.task_id !== "string" ||
|
|
133
|
+
!taskId.test(item.task_id) ||
|
|
134
|
+
ids.has(item.task_id) ||
|
|
135
|
+
typeof item.request_id !== "string" ||
|
|
136
|
+
!item.request_id ||
|
|
137
|
+
typeof item.spec_fingerprint_sha256 !== "string" ||
|
|
138
|
+
!sha.test(item.spec_fingerprint_sha256))
|
|
139
|
+
transferFail("migration_authority_invalid", "Adopted preparation identity is invalid.");
|
|
140
|
+
ids.add(item.task_id);
|
|
141
|
+
}
|
|
142
|
+
else if (item.task_id !== null ||
|
|
143
|
+
item.request_id !== null ||
|
|
144
|
+
item.spec_fingerprint_sha256 !== null)
|
|
145
|
+
transferFail("migration_authority_invalid", "Retained attempted work cannot become a new executable task.");
|
|
146
|
+
}
|
|
147
|
+
const names = new Set();
|
|
148
|
+
let total = 0;
|
|
149
|
+
for (const entry of value.protected_files) {
|
|
150
|
+
const file = object(entry);
|
|
151
|
+
exact(file, ["path", "bytes", "sha256"]);
|
|
152
|
+
if (typeof file.path !== "string" ||
|
|
153
|
+
names.has(file.path) ||
|
|
154
|
+
typeof file.bytes !== "number" ||
|
|
155
|
+
!Number.isSafeInteger(file.bytes) ||
|
|
156
|
+
file.bytes < 0 ||
|
|
157
|
+
typeof file.sha256 !== "string" ||
|
|
158
|
+
!sha.test(file.sha256))
|
|
159
|
+
transferFail("migration_authority_invalid", "Protected migration evidence is invalid.");
|
|
160
|
+
names.add(file.path);
|
|
161
|
+
total += file.bytes;
|
|
162
|
+
if (total > 512 * 1024 * 1024)
|
|
163
|
+
transferFail("migration_authority_invalid", "Protected migration evidence exceeds its bound.");
|
|
164
|
+
const selected = transferPath(controlRoot, file.path);
|
|
165
|
+
assertNotFoundrySessionFile(selected, sessionReference);
|
|
166
|
+
if (verifyProtected) {
|
|
167
|
+
const actual = transferFileFact(selected);
|
|
168
|
+
if (actual.bytes !== file.bytes || actual.sha256 !== file.sha256)
|
|
169
|
+
transferFail("migration_authority_changed", "Protected migration evidence changed or is missing.");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const required = [
|
|
173
|
+
`migrations/${migration.plan_sha256}/plan.json`,
|
|
174
|
+
`migrations/${migration.plan_sha256}/receipt.json`,
|
|
175
|
+
`migrations/${migration.plan_sha256}/adoption.json`,
|
|
176
|
+
];
|
|
177
|
+
if (required.some((file) => !names.has(file)))
|
|
178
|
+
transferFail("migration_authority_invalid", "Activation omits required migration evidence.");
|
|
179
|
+
const documents = required.map((file) => object(JSON.parse(checkedRead(file, 8 * 1024 * 1024).toString("utf8"))));
|
|
180
|
+
const [plan, receipt, adoption] = documents;
|
|
181
|
+
const { plan_sha256: planDigest, ...planBody } = plan;
|
|
182
|
+
const { receipt_sha256: receiptDigest, ...receiptBody } = receipt;
|
|
183
|
+
const { adoption_sha256: adoptionDigest, ...adoptionBody } = adoption;
|
|
184
|
+
if (planDigest !== migration.plan_sha256 ||
|
|
185
|
+
planDigest !== sha256Json(planBody) ||
|
|
186
|
+
receipt.schema !== "tiangong-foundry.migration-transfer-receipt.v1" ||
|
|
187
|
+
receiptDigest !== sha256Json(receiptBody) ||
|
|
188
|
+
receipt.plan_sha256 !== planDigest ||
|
|
189
|
+
receipt.workspace_id !== workspaceId ||
|
|
190
|
+
receipt.activated !== false ||
|
|
191
|
+
receipt.remote_write_allowed !== false ||
|
|
192
|
+
adoption.schema !== "tiangong-foundry.migration-adoption-plan.v1" ||
|
|
193
|
+
adoptionDigest !== value.adoption_sha256 ||
|
|
194
|
+
adoptionDigest !== sha256Json(adoptionBody) ||
|
|
195
|
+
adoption.workspace_id !== workspaceId ||
|
|
196
|
+
adoption.plan_sha256 !== planDigest ||
|
|
197
|
+
adoption.actor_id !== plan.actor_id ||
|
|
198
|
+
!Array.isArray(adoption.tasks) ||
|
|
199
|
+
!Array.isArray(receipt.files))
|
|
200
|
+
transferFail("migration_authority_invalid", "Activation, adoption and transfer evidence do not describe the same migration.");
|
|
201
|
+
const protectedByPath = new Map(value.protected_files.map((file) => [file.path, file]));
|
|
202
|
+
for (const file of receipt.files) {
|
|
203
|
+
const protectedFile = protectedByPath.get(String(file.destination));
|
|
204
|
+
if (!protectedFile ||
|
|
205
|
+
protectedFile.sha256 !== file.sha256 ||
|
|
206
|
+
protectedFile.bytes !== file.bytes)
|
|
207
|
+
transferFail("migration_authority_invalid", "Activation does not protect every archived source file.");
|
|
208
|
+
}
|
|
209
|
+
if (sha256Json(adoption.tasks.map((row) => object(row).authority)) !== sha256Json(value.tasks))
|
|
210
|
+
transferFail("migration_authority_invalid", "Activated task dispositions differ from their reviewed adoption.");
|
|
211
|
+
for (const row of adoption.tasks) {
|
|
212
|
+
const task = object(row.authority);
|
|
213
|
+
if (!Array.isArray(row.scope_inputs) ||
|
|
214
|
+
row.scope_inputs.some((file) => typeof file !== "string" || !protectedByPath.has(file)))
|
|
215
|
+
transferFail("migration_authority_invalid", "Adopted dataset scope is not anchored to protected inputs.");
|
|
216
|
+
if (verifyProtected) {
|
|
217
|
+
const keys = new Set();
|
|
218
|
+
let complete = row.scope_inputs.length > 0;
|
|
219
|
+
for (const file of row.scope_inputs) {
|
|
220
|
+
const input = transferPath(controlRoot, file);
|
|
221
|
+
const scope = migrationDatasetScope(input, checkedRead(file, 64 * 1024 * 1024));
|
|
222
|
+
complete = complete && scope.complete;
|
|
223
|
+
for (const key of scope.keys)
|
|
224
|
+
keys.add(key);
|
|
225
|
+
}
|
|
226
|
+
if (sha256Json([...keys].sort()) !== sha256Json(task.scope_keys) ||
|
|
227
|
+
(task.scope_complete === true && !complete))
|
|
228
|
+
transferFail("migration_authority_changed", "Retained dataset scope differs from independently observed archived inputs.");
|
|
229
|
+
}
|
|
230
|
+
if (task.task_id !== null) {
|
|
231
|
+
const id = String(task.task_id);
|
|
232
|
+
const requiredTaskFiles = [
|
|
233
|
+
`workspaces/${id}/foundry-job.json`,
|
|
234
|
+
`workspaces/${id}/source-manifest.json`,
|
|
235
|
+
`workspaces/${id}/profile-lock.json`,
|
|
236
|
+
`state/task-registrations/${id}.json`,
|
|
237
|
+
`state/task-publications/${id}.json`,
|
|
238
|
+
`state/facade-tasks/${id}.json`,
|
|
239
|
+
];
|
|
240
|
+
if (requiredTaskFiles.some((file) => !protectedByPath.has(file)))
|
|
241
|
+
transferFail("migration_authority_invalid", "An adopted task is missing protected registration or predecessor bindings.");
|
|
242
|
+
const pointer = object(JSON.parse(checkedRead(`state/facade-tasks/${id}.json`, 64 * 1024).toString("utf8")));
|
|
243
|
+
const index = object(JSON.parse(checkedRead(`state/facade-requests/${id.slice(5, 69)}.json`, 8 * 1024 * 1024).toString("utf8")));
|
|
244
|
+
const { index_sha256: indexDigest, ...indexBody } = index;
|
|
245
|
+
if (pointer.schema !== "tiangong-foundry.facade-task-pointer.v1" ||
|
|
246
|
+
pointer.workspace_id !== workspaceId ||
|
|
247
|
+
pointer.task_id !== id ||
|
|
248
|
+
index.schema !== "tiangong-foundry.facade-request-index.v1" ||
|
|
249
|
+
index.workspace_id !== workspaceId ||
|
|
250
|
+
index.request_id !== task.request_id ||
|
|
251
|
+
indexDigest !== sha256Json(indexBody) ||
|
|
252
|
+
!Array.isArray(index.revisions) ||
|
|
253
|
+
typeof pointer.revision !== "number")
|
|
254
|
+
transferFail("migration_authority_changed", "The adopted request lineage is missing or changed.");
|
|
255
|
+
const revision = object(index.revisions[pointer.revision - 1]);
|
|
256
|
+
const { record_sha256: revisionDigest, ...revisionBody } = revision;
|
|
257
|
+
if (revision.task_id !== id ||
|
|
258
|
+
revision.fingerprint_sha256 !== task.spec_fingerprint_sha256 ||
|
|
259
|
+
revisionDigest !== pointer.revision_sha256 ||
|
|
260
|
+
revisionDigest !== sha256Json(revisionBody))
|
|
261
|
+
transferFail("migration_authority_changed", "The immutable adopted revision no longer matches its request index.");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return value;
|
|
265
|
+
}
|
|
266
|
+
export function assertMigrationTaskIntent(context, requestId, actorId, id, fingerprint) {
|
|
267
|
+
if (!context.migration)
|
|
268
|
+
return;
|
|
269
|
+
const authority = readFoundryMigrationAuthority(context.controlRoot, context.workspaceId, context.migration);
|
|
270
|
+
const selected = authority.tasks.find((task) => task.task_id === id && task.disposition === "local-unattempted");
|
|
271
|
+
if (!selected)
|
|
272
|
+
return;
|
|
273
|
+
if (selected.actor_id !== actorId ||
|
|
274
|
+
selected.request_id !== requestId ||
|
|
275
|
+
(fingerprint !== undefined && selected.spec_fingerprint_sha256 !== fingerprint))
|
|
276
|
+
transferFail("migration_task_adoption_required", "This request is outside the audited migration task mapping; retain the original owner history and use explicit adoption for a changed task.");
|
|
277
|
+
}
|
|
278
|
+
export function migratedTaskRoot(controlRoot, planSha256) {
|
|
279
|
+
return path.join(controlRoot, "migrations", planSha256);
|
|
280
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const FOUNDRY_WORKSPACE_MIGRATION_PLAN_SCHEMA: "tiangong-foundry.workspace-migration-plan.v1";
|
|
2
|
+
export interface MigrationEntry {
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly kind: "directory" | "file";
|
|
5
|
+
readonly bytes: number | null;
|
|
6
|
+
readonly sha256: string | null;
|
|
7
|
+
readonly state_class: "workspace-control" | "local-preparation" | "terminal-success" | "attempted-or-unknown" | "authorization-or-account" | "unclassified";
|
|
8
|
+
}
|
|
9
|
+
export interface FoundryWorkspaceMigrationPlan {
|
|
10
|
+
readonly schema: typeof FOUNDRY_WORKSPACE_MIGRATION_PLAN_SCHEMA;
|
|
11
|
+
readonly workspace_root: string;
|
|
12
|
+
readonly foundry_root_exists: boolean;
|
|
13
|
+
readonly marker_schema: string | null;
|
|
14
|
+
readonly disposition: "no_state" | "current_layout" | "explicit_migration_required";
|
|
15
|
+
readonly write_allowed: false;
|
|
16
|
+
readonly entries: readonly Readonly<MigrationEntry>[];
|
|
17
|
+
readonly tree_sha256: string;
|
|
18
|
+
}
|
|
19
|
+
export { migrationCredentialPath } from "./foundry-private-path.ts";
|
|
20
|
+
export interface FoundryMigrationTree {
|
|
21
|
+
readonly exists: boolean;
|
|
22
|
+
readonly entries: readonly Readonly<MigrationEntry>[];
|
|
23
|
+
readonly tree_sha256: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function inventoryFoundryMigrationTree(root: string, options?: {
|
|
26
|
+
sessionReference?: string;
|
|
27
|
+
}): FoundryMigrationTree;
|
|
28
|
+
/** Deterministic read-only inventory. W10 owns any application or rollback. */
|
|
29
|
+
export declare function inventoryFoundryWorkspace(workspace: string, options?: {
|
|
30
|
+
sessionReference?: string;
|
|
31
|
+
}): FoundryWorkspaceMigrationPlan;
|