@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,467 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { assertWorkspaceCompatibility } from "@tiangong-lca/cli/runtime";
|
|
5
|
+
import { createFoundryRuntime } from "../foundry-runtime.js";
|
|
6
|
+
import { createFoundryRuntimeContext, captureFoundryInput, } from "./foundry-runtime-context.js";
|
|
7
|
+
import { parseFoundryTaskStartSpec, taskStartSpecFingerprint, } from "./foundry-task-start-spec.js";
|
|
8
|
+
import { loadFoundryFacadeTaskRecord } from "./foundry-facade-store.js";
|
|
9
|
+
import { auditFoundryMigration, } from "./foundry-migration-transfer.js";
|
|
10
|
+
import { revalidateFoundryMigrationPlan, } from "./foundry-migration-plan.js";
|
|
11
|
+
import { migrationCredentialPath } from "./foundry-migration-inventory.js";
|
|
12
|
+
import { FOUNDRY_MIGRATED_WORKSPACE_SCHEMA, FOUNDRY_MIGRATED_WORKSPACE_FEATURES, migrationDatasetScope, readFoundryMigrationAuthority, } from "./foundry-migration-authority.js";
|
|
13
|
+
import { transferRead, transferHash, transferPath, transferFail, } from "./foundry-migration-transfer-io.js";
|
|
14
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
15
|
+
export const FOUNDRY_MIGRATION_ADOPTION_PLAN_SCHEMA = "tiangong-foundry.migration-adoption-plan.v1";
|
|
16
|
+
export function materializeMigrationTaskSpec(template) {
|
|
17
|
+
return parseFoundryTaskStartSpec({
|
|
18
|
+
...template,
|
|
19
|
+
schema: "tiangong-foundry.task-start.v1",
|
|
20
|
+
account_intent: template.account_intent
|
|
21
|
+
? { ...template.account_intent, session_reference: null }
|
|
22
|
+
: null,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function migrationTaskTemplate(spec) {
|
|
26
|
+
const { schema: _schema, account_intent: account, ...fields } = spec;
|
|
27
|
+
return {
|
|
28
|
+
...fields,
|
|
29
|
+
account_intent: account
|
|
30
|
+
? {
|
|
31
|
+
project_ref: account.project_ref,
|
|
32
|
+
user_id: account.user_id,
|
|
33
|
+
...(account.account_mode ? { account_mode: account.account_mode } : {}),
|
|
34
|
+
}
|
|
35
|
+
: null,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function object(value) {
|
|
39
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
40
|
+
transferFail("migration_adoption_invalid", "Legacy task evidence must be a JSON object.");
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function archiveJson(context, file) {
|
|
44
|
+
if (!file || file.bytes > 8 * 1024 * 1024)
|
|
45
|
+
transferFail("migration_adoption_invalid", "Task evidence is missing or exceeds its limit.");
|
|
46
|
+
const data = transferRead(transferPath(context.controlRoot, file.destination), 8 * 1024 * 1024);
|
|
47
|
+
if (transferHash(data) !== file.sha256)
|
|
48
|
+
transferFail("migration_authority_changed", "Archived task evidence changed.");
|
|
49
|
+
return object(JSON.parse(data.toString("utf8")));
|
|
50
|
+
}
|
|
51
|
+
function selectedSource(sourceWorkspace, requested, copied) {
|
|
52
|
+
const candidate = path.resolve(sourceWorkspace, requested);
|
|
53
|
+
if (migrationCredentialPath(candidate))
|
|
54
|
+
transferFail("migration_credential_forbidden", "Private storage cannot be adopted as a source.");
|
|
55
|
+
const selected = copied.find((file) => file.source === candidate || file.source === fs.realpathSync(candidate));
|
|
56
|
+
if (!selected)
|
|
57
|
+
transferFail("migration_source_unaccounted", "Every legacy source must be independently included in the transfer.");
|
|
58
|
+
return selected;
|
|
59
|
+
}
|
|
60
|
+
function archivedScope(context, plan, root, copied) {
|
|
61
|
+
try {
|
|
62
|
+
const prefix = path.join(plan.source_inventory.workspace_root, ".foundry", root);
|
|
63
|
+
const manifest = archiveJson(context, copied.find((file) => file.source === path.join(prefix, "source-manifest.json")));
|
|
64
|
+
const job = archiveJson(context, copied.find((file) => file.source === path.join(prefix, "foundry-job.json")));
|
|
65
|
+
if (!Array.isArray(manifest.source_paths) ||
|
|
66
|
+
!manifest.source_paths.length ||
|
|
67
|
+
!Array.isArray(job.target_entities))
|
|
68
|
+
return { keys: [], complete: false, inputs: [] };
|
|
69
|
+
const keys = new Set(), inputs = [];
|
|
70
|
+
let complete = true;
|
|
71
|
+
for (const item of manifest.source_paths) {
|
|
72
|
+
const source = object(item);
|
|
73
|
+
if (typeof source.path !== "string" || typeof source.sha256 !== "string")
|
|
74
|
+
return { keys: [], complete: false, inputs: [] };
|
|
75
|
+
const file = selectedSource(plan.source_inventory.workspace_root, source.path, copied);
|
|
76
|
+
if (file.sha256 !== source.sha256)
|
|
77
|
+
return { keys: [], complete: false, inputs: [] };
|
|
78
|
+
const bytes = transferRead(transferPath(context.controlRoot, file.destination), 64 * 1024 * 1024);
|
|
79
|
+
if (transferHash(bytes) !== file.sha256)
|
|
80
|
+
transferFail("migration_authority_changed", "Archived scope input changed.");
|
|
81
|
+
const scope = migrationDatasetScope(file.source, bytes);
|
|
82
|
+
complete = complete && scope.complete;
|
|
83
|
+
inputs.push(file.destination);
|
|
84
|
+
for (const key of scope.keys)
|
|
85
|
+
keys.add(key);
|
|
86
|
+
}
|
|
87
|
+
for (const file of copied) {
|
|
88
|
+
if (!file.source.startsWith(prefix + path.sep) ||
|
|
89
|
+
inputs.includes(file.destination) ||
|
|
90
|
+
!/\.jsonl?$/iu.test(file.source))
|
|
91
|
+
continue;
|
|
92
|
+
const data = transferRead(transferPath(context.controlRoot, file.destination), 64 * 1024 * 1024);
|
|
93
|
+
const scope = migrationDatasetScope(file.source, data);
|
|
94
|
+
if (!scope.keys.length)
|
|
95
|
+
continue;
|
|
96
|
+
complete = complete && scope.complete;
|
|
97
|
+
inputs.push(file.destination);
|
|
98
|
+
for (const key of scope.keys)
|
|
99
|
+
keys.add(key);
|
|
100
|
+
}
|
|
101
|
+
const types = new Set([...keys].map((key) => key.split(":")[0]));
|
|
102
|
+
if (job.target_entities.some((type) => typeof type !== "string" || !types.has(type)))
|
|
103
|
+
complete = false;
|
|
104
|
+
return { keys: [...keys].sort(), complete, inputs: [...new Set(inputs)].sort() };
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return { keys: [], complete: false, inputs: [] };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function inspectLocalHistory(context, plan, root, files, allFiles, manifest) {
|
|
111
|
+
const originalRoot = path.join(plan.source_inventory.workspace_root, ".foundry", root);
|
|
112
|
+
const byName = new Map(files.map((file) => [path.relative(originalRoot, file.source).split(path.sep).join("/"), file]));
|
|
113
|
+
const job = archiveJson(context, byName.get("foundry-job.json")), source = archiveJson(context, byName.get("source-manifest.json"));
|
|
114
|
+
const profile = archiveJson(context, byName.get("profile-lock.json"));
|
|
115
|
+
if (!["external-dataset-curated-import", "source-evidence-dataset-development"].includes(String(job.lane)) ||
|
|
116
|
+
typeof job.target_profile !== "string" ||
|
|
117
|
+
!Array.isArray(job.target_entities) ||
|
|
118
|
+
!job.target_entities.length ||
|
|
119
|
+
(profile.profile_id !== undefined && profile.profile_id !== job.target_profile) ||
|
|
120
|
+
!Array.isArray(source.source_paths) ||
|
|
121
|
+
!source.source_paths.length)
|
|
122
|
+
transferFail("migration_adoption_invalid", "Legacy source/profile/task intent is incomplete.");
|
|
123
|
+
const sources = source.source_paths.map((value) => {
|
|
124
|
+
const ref = object(value);
|
|
125
|
+
if (typeof ref.path !== "string" || typeof ref.sha256 !== "string")
|
|
126
|
+
transferFail("migration_source_unaccounted", "Legacy source facts are incomplete.");
|
|
127
|
+
const file = selectedSource(plan.source_inventory.workspace_root, ref.path, allFiles);
|
|
128
|
+
if (ref.sha256 !== file.sha256 || (ref.bytes !== undefined && ref.bytes !== file.bytes))
|
|
129
|
+
transferFail("migration_source_changed", "Legacy source hashes do not match the transferred bytes.");
|
|
130
|
+
return file;
|
|
131
|
+
});
|
|
132
|
+
const allowed = new Set([
|
|
133
|
+
"foundry-job.json",
|
|
134
|
+
"source-manifest.json",
|
|
135
|
+
"profile-lock.json",
|
|
136
|
+
"seed-manifest.json",
|
|
137
|
+
]);
|
|
138
|
+
for (const stage of plan.stages.filter((item) => item.path.startsWith(root + "/") && item.migration_action === "rebuild-local-preparation"))
|
|
139
|
+
allowed.add(stage.path.slice(root.length + 1));
|
|
140
|
+
if (job.schema === "tiangong-foundry.job.v2") {
|
|
141
|
+
if (typeof job.task_id !== "string" || typeof job.actor_id !== "string")
|
|
142
|
+
transferFail("migration_adoption_invalid", "Registered legacy task identity is incomplete.");
|
|
143
|
+
const options = {
|
|
144
|
+
moduleUrl: pathToFileURL(context.runtime.entryPath).href,
|
|
145
|
+
workspace: plan.source_inventory.workspace_root,
|
|
146
|
+
cacheBase: context.cacheBase,
|
|
147
|
+
workspaceAccess: { manifest, access: "read" },
|
|
148
|
+
};
|
|
149
|
+
const base = createFoundryRuntimeContext(options);
|
|
150
|
+
const taskContext = createFoundryRuntimeContext({
|
|
151
|
+
...options,
|
|
152
|
+
taskId: job.task_id,
|
|
153
|
+
actorId: job.actor_id,
|
|
154
|
+
inputs: sources.map((file) => ({
|
|
155
|
+
path: file.source,
|
|
156
|
+
bytes: file.bytes,
|
|
157
|
+
sha256: file.sha256,
|
|
158
|
+
})),
|
|
159
|
+
});
|
|
160
|
+
if (fs.existsSync(path.join(base.stateRoot, "facade-tasks", `${job.task_id}.json`)))
|
|
161
|
+
loadFoundryFacadeTaskRecord(base, job.task_id, job.actor_id);
|
|
162
|
+
const inspected = await createFoundryRuntime(taskContext).inspectTask();
|
|
163
|
+
if (inspected.attempts_present)
|
|
164
|
+
transferFail("migration_attempt_history", "Retained task attempts require original-owner readback.");
|
|
165
|
+
allowed.add("artifact-index.jsonl");
|
|
166
|
+
allowed.add("account-intent.json");
|
|
167
|
+
allowed.add("authorization.json");
|
|
168
|
+
for (const entry of inspected.artifacts) {
|
|
169
|
+
allowed.add(entry.path);
|
|
170
|
+
allowed.add(entry.receipt.path);
|
|
171
|
+
const receipt = archiveJson(context, byName.get(entry.receipt.path));
|
|
172
|
+
for (const ref of [receipt.plan, receipt.result]) {
|
|
173
|
+
const item = object(ref);
|
|
174
|
+
if (typeof item.path !== "string")
|
|
175
|
+
transferFail("migration_adoption_invalid", "Local operation evidence is incomplete.");
|
|
176
|
+
allowed.add(item.path);
|
|
177
|
+
}
|
|
178
|
+
if (entry.path.endsWith("dataset-import-completion-report.json")) {
|
|
179
|
+
const completion = archiveJson(context, byName.get(entry.path));
|
|
180
|
+
if (completion.status === "completed" &&
|
|
181
|
+
completion.task_id === job.task_id &&
|
|
182
|
+
Array.isArray(completion.blockers) &&
|
|
183
|
+
completion.blockers.length === 0)
|
|
184
|
+
transferFail("migration_terminal_retained", "The registered terminal report remains historical completion evidence.");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
if (job.schema_version !== 1 ||
|
|
190
|
+
source.schema_version !== 1 ||
|
|
191
|
+
job.task_id !== path.posix.basename(root))
|
|
192
|
+
transferFail("migration_adoption_invalid", "Legacy task schema or directory identity is unsupported.");
|
|
193
|
+
if (typeof job.workspace_dir !== "string" ||
|
|
194
|
+
fs.realpathSync(path.resolve(plan.source_inventory.workspace_root, job.workspace_dir)) !==
|
|
195
|
+
fs.realpathSync(originalRoot))
|
|
196
|
+
transferFail("migration_task_binding_mismatch", "Legacy job layout differs from its selected task directory.");
|
|
197
|
+
if (byName.has("artifact-index.jsonl")) {
|
|
198
|
+
const index = byName.get("artifact-index.jsonl");
|
|
199
|
+
if (index.bytes !== 0)
|
|
200
|
+
transferFail("migration_history_unclassified", "Legacy artifact lineage requires owner verification.");
|
|
201
|
+
allowed.add("artifact-index.jsonl");
|
|
202
|
+
}
|
|
203
|
+
for (const [name, file] of byName) {
|
|
204
|
+
if (!/^checkpoints\/[^/]+\.json$/u.test(name))
|
|
205
|
+
continue;
|
|
206
|
+
const checkpoint = archiveJson(context, file);
|
|
207
|
+
if (checkpoint.schema_version !== 1 ||
|
|
208
|
+
checkpoint.stage_id !== "dataset-curation-cleanup" ||
|
|
209
|
+
!["passed", "blocked"].includes(String(checkpoint.status)))
|
|
210
|
+
transferFail("migration_history_unclassified", "A legacy checkpoint is outside deterministic local preparation.");
|
|
211
|
+
for (const [relative, digest] of Object.entries(object(checkpoint.output_hashes))) {
|
|
212
|
+
const output = byName.get(relative);
|
|
213
|
+
if (!output || output.sha256 !== digest)
|
|
214
|
+
transferFail("migration_authority_changed", "Legacy local output does not match its checkpoint.");
|
|
215
|
+
allowed.add(relative);
|
|
216
|
+
}
|
|
217
|
+
allowed.add(name);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
for (const name of byName.keys())
|
|
221
|
+
if (!allowed.has(name) && !name.startsWith("evidence/authorizations/"))
|
|
222
|
+
transferFail("migration_history_unclassified", "Unclassified task evidence remains with the original owner.");
|
|
223
|
+
return { job, sources, allowed };
|
|
224
|
+
}
|
|
225
|
+
export async function planFoundryMigrationAdoption(context, planning, transfer, selections, manifest) {
|
|
226
|
+
assertWorkspaceCompatibility(manifest, { schema: FOUNDRY_MIGRATED_WORKSPACE_SCHEMA, features: FOUNDRY_MIGRATED_WORKSPACE_FEATURES }, "write");
|
|
227
|
+
if (manifest.manifest.product.id !== "tiangong-foundry" ||
|
|
228
|
+
manifest.manifest.product.version !== context.runtime.packageVersion)
|
|
229
|
+
transferFail("workspace_runtime_incompatible", "Adoption requires the intended current Foundry writer.");
|
|
230
|
+
const audited = auditFoundryMigration(context, planning, transfer);
|
|
231
|
+
const plan = revalidateFoundryMigrationPlan(context, planning, transfer, audited.receipt.plan_sha256);
|
|
232
|
+
if (selections.length > 1000 ||
|
|
233
|
+
new Set(selections.map((item) => item.sourceTask)).size !== selections.length)
|
|
234
|
+
transferFail("migration_adoption_invalid", "Adoption selections must be unique and bounded.");
|
|
235
|
+
const sourceControl = path.join(plan.source_inventory.workspace_root, ".foundry");
|
|
236
|
+
let inheritedRows = [];
|
|
237
|
+
const inheritedFiles = new Set();
|
|
238
|
+
if (plan.source_inventory.marker_schema === FOUNDRY_MIGRATED_WORKSPACE_SCHEMA) {
|
|
239
|
+
const markerFile = audited.receipt.files.find((file) => file.source === path.join(sourceControl, "workspace.json"));
|
|
240
|
+
const marker = archiveJson(context, markerFile);
|
|
241
|
+
const binding = marker.migration;
|
|
242
|
+
const authority = readFoundryMigrationAuthority(sourceControl, String(marker.workspace_id), binding, true, context.accountIntent?.sessionReference);
|
|
243
|
+
const oldAdoption = archiveJson(context, audited.receipt.files.find((file) => file.source ===
|
|
244
|
+
path.join(sourceControl, "migrations", binding.plan_sha256, "adoption.json")));
|
|
245
|
+
inheritedRows = oldAdoption.tasks;
|
|
246
|
+
for (const file of authority.protected_files)
|
|
247
|
+
inheritedFiles.add(file.path);
|
|
248
|
+
inheritedFiles.add(`migrations/${binding.plan_sha256}/activation.json`);
|
|
249
|
+
inheritedFiles.add("migration-claim.json");
|
|
250
|
+
}
|
|
251
|
+
const unaccountedGlobal = audited.receipt.files.some((file) => {
|
|
252
|
+
if (!file.source.startsWith(sourceControl + path.sep))
|
|
253
|
+
return false;
|
|
254
|
+
const name = path.relative(sourceControl, file.source).split(path.sep).join("/");
|
|
255
|
+
return (!name.startsWith("workspaces/") &&
|
|
256
|
+
name !== "workspace.json" &&
|
|
257
|
+
!inheritedFiles.has(name) &&
|
|
258
|
+
!/^state\/(?:task-registrations|task-publications|task-accounts|facade-requests|facade-tasks)\/[^/]+\.json$/u.test(name));
|
|
259
|
+
});
|
|
260
|
+
const roots = new Set(plan.source_inventory.entries
|
|
261
|
+
.map((entry) => /^workspaces\/[^/]+/u.exec(entry.path)?.[0])
|
|
262
|
+
.filter((entry) => Boolean(entry)));
|
|
263
|
+
for (const selection of selections) {
|
|
264
|
+
if (!roots.has(selection.sourceTask) ||
|
|
265
|
+
!path.isAbsolute(selection.specFile) ||
|
|
266
|
+
migrationCredentialPath(selection.specFile))
|
|
267
|
+
transferFail("migration_adoption_invalid", "Select an inventoried task and an explicit non-private task specification.");
|
|
268
|
+
if (context.accountIntent?.sessionReference &&
|
|
269
|
+
fs.existsSync(context.accountIntent.sessionReference) &&
|
|
270
|
+
fs.realpathSync(selection.specFile) ===
|
|
271
|
+
fs.realpathSync(context.accountIntent.sessionReference))
|
|
272
|
+
transferFail("migration_credential_forbidden", "An OAuth session reference cannot be an adoption specification.");
|
|
273
|
+
}
|
|
274
|
+
const rows = [];
|
|
275
|
+
const requestIds = new Set();
|
|
276
|
+
for (const root of [...roots].sort()) {
|
|
277
|
+
const sourceRoot = path.join(sourceControl, root);
|
|
278
|
+
const files = audited.receipt.files.filter((file) => file.source.startsWith(sourceRoot + path.sep));
|
|
279
|
+
const stages = plan.stages.filter((stage) => stage.path.startsWith(root + "/"));
|
|
280
|
+
const selection = selections.find((item) => item.sourceTask === root);
|
|
281
|
+
const inherited = inheritedRows.find((row) => row.authority.task_id === path.posix.basename(root));
|
|
282
|
+
const origin = inherited?.authority.origin_sha256 ??
|
|
283
|
+
sha256Json({
|
|
284
|
+
source: plan.source_inventory.workspace_root,
|
|
285
|
+
task: root,
|
|
286
|
+
files: files.map((file) => ({
|
|
287
|
+
source: file.source,
|
|
288
|
+
bytes: file.bytes,
|
|
289
|
+
sha256: file.sha256,
|
|
290
|
+
})),
|
|
291
|
+
});
|
|
292
|
+
const scope = archivedScope(context, plan, root, audited.receipt.files);
|
|
293
|
+
let disposition = "owner-readback-only";
|
|
294
|
+
let sourceSpec = null, target = null, inputs = [], reason = selection ? "history_unverified" : "not_selected_for_local_adoption";
|
|
295
|
+
if (stages.some((stage) => stage.migration_action === "owner-readback-only"))
|
|
296
|
+
disposition = "owner-readback-only";
|
|
297
|
+
const laterHistory = files.some((file) => /(?:^|\/)(?:attempts?|events?|.*ledger.*|.*readback.*|.*mutation.*)(?:\/|\.|$)/iu.test(path.relative(sourceRoot, file.source).split(path.sep).join("/")) && !stages.some((stage) => file.source === path.join(sourceControl, stage.path)));
|
|
298
|
+
if (unaccountedGlobal || laterHistory) {
|
|
299
|
+
disposition = "owner-readback-only";
|
|
300
|
+
reason = "later_or_unclassified_owner_history";
|
|
301
|
+
}
|
|
302
|
+
if (selection &&
|
|
303
|
+
!unaccountedGlobal &&
|
|
304
|
+
!laterHistory &&
|
|
305
|
+
!stages.some((stage) => stage.migration_action !== "rebuild-local-preparation")) {
|
|
306
|
+
try {
|
|
307
|
+
const inspected = await inspectLocalHistory(context, plan, root, files, audited.receipt.files, manifest);
|
|
308
|
+
const selectedFact = captureFoundryInput(selection.specFile);
|
|
309
|
+
if (selectedFact.bytes > 1024 * 1024)
|
|
310
|
+
transferFail("migration_adoption_invalid", "Task specification exceeds its limit.");
|
|
311
|
+
const specBytes = transferRead(selectedFact.path, 1024 * 1024);
|
|
312
|
+
if (transferHash(specBytes) !== selectedFact.sha256)
|
|
313
|
+
transferFail("migration_source_changed", "Selected task specification changed.");
|
|
314
|
+
const spec = parseFoundryTaskStartSpec(JSON.parse(specBytes.toString("utf8")));
|
|
315
|
+
if (plan.account_intent &&
|
|
316
|
+
(!spec.account_intent ||
|
|
317
|
+
spec.account_intent.project_ref !== plan.account_intent.project_ref ||
|
|
318
|
+
spec.account_intent.user_id !== plan.account_intent.user_id))
|
|
319
|
+
transferFail("migration_account_mismatch", "Adoption account intent differs from the independently selected transfer account.");
|
|
320
|
+
if (files.some((file) => path.relative(sourceRoot, file.source).split(path.sep).join("/").startsWith("outputs/")) &&
|
|
321
|
+
!spec.preparation)
|
|
322
|
+
transferFail("migration_preparation_required", "Retained derived outputs require an explicit current-owner preparation step.");
|
|
323
|
+
if (spec.actor_id !== plan.actor_id ||
|
|
324
|
+
spec.lane !== inspected.job.lane ||
|
|
325
|
+
spec.profile_id !== inspected.job.target_profile ||
|
|
326
|
+
sha256Json([...spec.target_entities].sort()) !==
|
|
327
|
+
sha256Json([...inspected.job.target_entities].sort()) ||
|
|
328
|
+
requestIds.has(spec.request_id))
|
|
329
|
+
transferFail("migration_task_binding_mismatch", "Current task intent differs from the selected legacy scope or actor.");
|
|
330
|
+
const selected = spec.sources.map((item) => selectedSource(plan.source_inventory.workspace_root, item.path, audited.receipt.files));
|
|
331
|
+
if (sha256Json(selected.map((item) => item.source).sort()) !==
|
|
332
|
+
sha256Json(inspected.sources.map((item) => item.source).sort()))
|
|
333
|
+
transferFail("migration_source_unaccounted", "Current task sources do not cover the retained source manifest exactly.");
|
|
334
|
+
const remap = (value) => {
|
|
335
|
+
const file = selectedSource(plan.source_inventory.workspace_root, value, selected);
|
|
336
|
+
return transferPath(context.controlRoot, file.destination);
|
|
337
|
+
};
|
|
338
|
+
target = parseFoundryTaskStartSpec({
|
|
339
|
+
...spec,
|
|
340
|
+
account_intent: spec.account_intent
|
|
341
|
+
? {
|
|
342
|
+
project_ref: spec.account_intent.project_ref,
|
|
343
|
+
user_id: spec.account_intent.user_id,
|
|
344
|
+
...(spec.account_intent.account_mode
|
|
345
|
+
? { account_mode: spec.account_intent.account_mode }
|
|
346
|
+
: {}),
|
|
347
|
+
session_reference: null,
|
|
348
|
+
}
|
|
349
|
+
: null,
|
|
350
|
+
sources: spec.sources.map((item) => ({ ...item, path: remap(item.path) })),
|
|
351
|
+
seed: spec.seed ? { ...spec.seed, path: remap(spec.seed.path) } : null,
|
|
352
|
+
preparation: spec.preparation
|
|
353
|
+
? {
|
|
354
|
+
...spec.preparation,
|
|
355
|
+
input: remap(spec.preparation.input),
|
|
356
|
+
source_input: spec.preparation.source_input
|
|
357
|
+
? remap(spec.preparation.source_input)
|
|
358
|
+
: null,
|
|
359
|
+
}
|
|
360
|
+
: null,
|
|
361
|
+
});
|
|
362
|
+
inputs = selected.map((file) => ({
|
|
363
|
+
path: transferPath(context.controlRoot, file.destination),
|
|
364
|
+
bytes: file.bytes,
|
|
365
|
+
sha256: file.sha256,
|
|
366
|
+
}));
|
|
367
|
+
sourceSpec = selectedFact;
|
|
368
|
+
disposition = "local-unattempted";
|
|
369
|
+
reason = "current_owner_rebuild_required";
|
|
370
|
+
requestIds.add(spec.request_id);
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
reason =
|
|
374
|
+
error instanceof Error && "code" in error
|
|
375
|
+
? String(error.code)
|
|
376
|
+
: "legacy_history_unverified";
|
|
377
|
+
if (reason === "migration_terminal_retained")
|
|
378
|
+
disposition = "terminal-retained";
|
|
379
|
+
else if (!/attempt|history|predecessor/u.test(reason))
|
|
380
|
+
disposition = "blocked-evidence";
|
|
381
|
+
target = null;
|
|
382
|
+
inputs = [];
|
|
383
|
+
sourceSpec = null;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const request = target?.request_id ?? null;
|
|
387
|
+
rows.push({
|
|
388
|
+
authority: {
|
|
389
|
+
source_task: root,
|
|
390
|
+
origin_sha256: origin,
|
|
391
|
+
disposition,
|
|
392
|
+
task_id: request
|
|
393
|
+
? `task-${sha256Json({ workspace_id: audited.receipt.workspace_id, request_id: request })}-r0001`
|
|
394
|
+
: null,
|
|
395
|
+
request_id: request,
|
|
396
|
+
actor_id: plan.actor_id,
|
|
397
|
+
spec_fingerprint_sha256: target ? taskStartSpecFingerprint(target, inputs) : null,
|
|
398
|
+
scope_keys: scope.keys,
|
|
399
|
+
scope_complete: scope.complete && !unaccountedGlobal,
|
|
400
|
+
},
|
|
401
|
+
source_spec: sourceSpec,
|
|
402
|
+
target_spec: target ? migrationTaskTemplate(target) : null,
|
|
403
|
+
inputs,
|
|
404
|
+
evidence_paths: files.map((file) => file.destination).sort(),
|
|
405
|
+
scope_inputs: scope.inputs,
|
|
406
|
+
reasons: [reason],
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
for (const old of inheritedRows) {
|
|
410
|
+
if (old.authority.task_id && roots.has(`workspaces/${old.authority.task_id}`))
|
|
411
|
+
continue;
|
|
412
|
+
if (old.authority.task_id)
|
|
413
|
+
transferFail("migration_source_authority_invalid", "A previously adopted task is missing; it cannot be reconstructed as empty history.");
|
|
414
|
+
const remap = (relative) => {
|
|
415
|
+
const copied = audited.receipt.files.find((file) => file.source === path.join(sourceControl, relative));
|
|
416
|
+
if (!copied)
|
|
417
|
+
transferFail("migration_source_authority_invalid", "Inherited migration evidence was omitted from the new archive.");
|
|
418
|
+
return copied.destination;
|
|
419
|
+
};
|
|
420
|
+
rows.push({
|
|
421
|
+
...old,
|
|
422
|
+
source_spec: null,
|
|
423
|
+
target_spec: null,
|
|
424
|
+
inputs: [],
|
|
425
|
+
evidence_paths: old.evidence_paths.map(remap),
|
|
426
|
+
scope_inputs: old.scope_inputs.map(remap),
|
|
427
|
+
reasons: [...old.reasons, "immutable_prior_migration_authority_retained"],
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
for (const file of audited.receipt.files.filter((file) => file.destination.startsWith(`migrations/${plan.plan_sha256}/original/tasks/`)))
|
|
431
|
+
rows.push({
|
|
432
|
+
authority: {
|
|
433
|
+
source_task: `queue:${path.relative(plan.source_inventory.workspace_root, file.source).split(path.sep).join("/")}`,
|
|
434
|
+
origin_sha256: sha256Json(file),
|
|
435
|
+
disposition: "owner-readback-only",
|
|
436
|
+
task_id: null,
|
|
437
|
+
request_id: null,
|
|
438
|
+
actor_id: plan.actor_id,
|
|
439
|
+
spec_fingerprint_sha256: null,
|
|
440
|
+
scope_keys: [],
|
|
441
|
+
scope_complete: false,
|
|
442
|
+
},
|
|
443
|
+
source_spec: null,
|
|
444
|
+
target_spec: null,
|
|
445
|
+
inputs: [],
|
|
446
|
+
evidence_paths: [file.destination],
|
|
447
|
+
scope_inputs: [],
|
|
448
|
+
reasons: ["retained_queue_is_not_current_task_authority"],
|
|
449
|
+
});
|
|
450
|
+
const payload = {
|
|
451
|
+
schema: FOUNDRY_MIGRATION_ADOPTION_PLAN_SCHEMA,
|
|
452
|
+
workspace_id: audited.receipt.workspace_id,
|
|
453
|
+
plan_sha256: plan.plan_sha256,
|
|
454
|
+
actor_id: plan.actor_id,
|
|
455
|
+
runtime_manifest_sha256: manifest.sha256,
|
|
456
|
+
selections: selections
|
|
457
|
+
.map((item) => ({ source_task: item.sourceTask, spec_file: path.resolve(item.specFile) }))
|
|
458
|
+
.sort((a, b) => a.source_task.localeCompare(b.source_task)),
|
|
459
|
+
tasks: rows,
|
|
460
|
+
remote_write_allowed: false,
|
|
461
|
+
};
|
|
462
|
+
const result = { ...payload, adoption_sha256: sha256Json(payload) };
|
|
463
|
+
if (Buffer.byteLength(JSON.stringify(result)) > 8 * 1024 * 1024)
|
|
464
|
+
transferFail("migration_adoption_invalid", "Adoption plan exceeds its bound.");
|
|
465
|
+
revalidateFoundryMigrationPlan(context, planning, transfer, audited.receipt.plan_sha256);
|
|
466
|
+
return result;
|
|
467
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { TrustedRuntimeManifest } from "@tiangong-lca/cli/runtime";
|
|
2
|
+
import type { FoundryOperationResult } from "./foundry-operation-result.ts";
|
|
3
|
+
import type { FoundryRuntimeManagerOptions } from "./foundry-runtime-selection.ts";
|
|
4
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
5
|
+
import { type FoundryMigrationPlanningOptions } from "./foundry-migration-plan.ts";
|
|
6
|
+
import { type MigrationAdoptionSelection } from "./foundry-migration-adoption-plan.ts";
|
|
7
|
+
import { type FoundryMigrationActivation } from "./foundry-migration-authority.ts";
|
|
8
|
+
export interface MigrationAdoptionExecutionOptions {
|
|
9
|
+
readonly signal?: AbortSignal;
|
|
10
|
+
readonly checkpoint?: (phase: "mapped" | "prepared" | "audited" | "activated", index: number) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface MigrationAdoptionHost {
|
|
13
|
+
readonly runtimeManager?: FoundryRuntimeManagerOptions;
|
|
14
|
+
createTaskFacade(): {
|
|
15
|
+
start(input: {
|
|
16
|
+
specFile: string;
|
|
17
|
+
}): Promise<FoundryOperationResult>;
|
|
18
|
+
resume(input: {
|
|
19
|
+
taskId: string;
|
|
20
|
+
actorId: string;
|
|
21
|
+
}): Promise<FoundryOperationResult>;
|
|
22
|
+
status(input: {
|
|
23
|
+
taskId: string;
|
|
24
|
+
actorId: string;
|
|
25
|
+
}): Promise<FoundryOperationResult>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export declare function applyFoundryMigrationAdoption(context: FoundryRuntimeContext, planning: FoundryMigrationPlanningOptions, transfer: unknown, selections: readonly MigrationAdoptionSelection[], provided: unknown, manifest: TrustedRuntimeManifest, host: MigrationAdoptionHost, options?: MigrationAdoptionExecutionOptions): Promise<{
|
|
29
|
+
activation: FoundryMigrationActivation;
|
|
30
|
+
path: string;
|
|
31
|
+
}>;
|