@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,264 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { captureFoundryInput, FoundryContextError, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
5
|
+
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
6
|
+
import { verifyFoundryRuntimeIdentity, } from "./foundry-runtime-identity.js";
|
|
7
|
+
import { createFoundryAuthenticationEnvironment } from "./foundry-authentication-environment.js";
|
|
8
|
+
import { createFoundryIsolatedChildEnvironment, copyFoundryIsolatedExecutable, } from "./foundry-runtime-environment.js";
|
|
9
|
+
import { createFoundryFinalizeOwners } from "./foundry-finalize-owners.js";
|
|
10
|
+
import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./foundry-workflow-state.js";
|
|
11
|
+
import { runFoundryTaskOperation, withFoundryTaskMetadata } from "./foundry-task-store.js";
|
|
12
|
+
import { registerWorkflowStageFiles } from "./foundry-workflow-io.js";
|
|
13
|
+
import { readTaskBytes } from "./foundry-task-io.js";
|
|
14
|
+
import { loadFoundryTaskAuthorization } from "./foundry-task-authorization.js";
|
|
15
|
+
import { taskAuthorizationMatches } from "./task-authorization.js";
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
export async function finalizeFoundryWorkflow(context, qualified, entries, authentication = { mode: "oauth" }, approval, executionProgress) {
|
|
18
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
19
|
+
const state = currentWorkflowState(context, entries), rows = state.rows;
|
|
20
|
+
if (!rows || !state.assessment)
|
|
21
|
+
throw new FoundryContextError("workflow_assessment_required", "Assess the current rows before finalization.");
|
|
22
|
+
const profile = await withFoundryTaskMetadata(context, (task, index) => {
|
|
23
|
+
if (currentWorkflowState(context, index).rows?.entry.sha256 !== rows.entry.sha256)
|
|
24
|
+
throw new FoundryContextError("workflow_rows_changed", "Current rows changed before finalization.");
|
|
25
|
+
return task.job.target_profile;
|
|
26
|
+
});
|
|
27
|
+
const profileLock = workflowObject(JSON.parse(readTaskBytes(context, "profile-lock.json").toString("utf8")));
|
|
28
|
+
const nonce = randomUUID(), output = resolveFoundryOutput(context, `outputs/finalize/${nonce}`);
|
|
29
|
+
const temporary = resolveFoundryOutput(context, `tmp/finalize-${nonce}`);
|
|
30
|
+
fs.mkdirSync(output, { recursive: true, mode: 0o700 });
|
|
31
|
+
fs.mkdirSync(temporary, { recursive: true, mode: 0o700 });
|
|
32
|
+
const environment = createFoundryIsolatedChildEnvironment({ tempRoot: temporary });
|
|
33
|
+
environment.FOUNDRY_ACCOUNT_MODE = context.accountIntent?.accountMode ?? "ordinary";
|
|
34
|
+
const sets = [], blockers = [];
|
|
35
|
+
let receiptFile;
|
|
36
|
+
let authorization;
|
|
37
|
+
let approvalPointer;
|
|
38
|
+
try {
|
|
39
|
+
if (context.accountIntent && rows.value.sets.length) {
|
|
40
|
+
const identity = verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
41
|
+
if (approval) {
|
|
42
|
+
authorization = await loadFoundryTaskAuthorization(context, identity, approval.inputFile, qualified);
|
|
43
|
+
if (authorization.authorization_sha256 !== approval.authorizationSha256)
|
|
44
|
+
throw new FoundryContextError("authorization_update_conflict", "Preparation approval changed before re-finalization.");
|
|
45
|
+
approvalPointer = createHash("sha256")
|
|
46
|
+
.update(readTaskBytes(context, "authorization.json"))
|
|
47
|
+
.digest("hex");
|
|
48
|
+
}
|
|
49
|
+
Object.assign(environment, createFoundryAuthenticationEnvironment(authentication, context.accountIntent.sessionReference, process.env));
|
|
50
|
+
environment.FOUNDRY_VERIFIED_PROJECT_REF = context.accountIntent.projectRef;
|
|
51
|
+
environment.FOUNDRY_VERIFIED_USER_ID = context.accountIntent.userId;
|
|
52
|
+
receiptFile = path.join(temporary, "identity-receipt.json");
|
|
53
|
+
fs.writeFileSync(receiptFile, JSON.stringify(identity.receipt), { mode: 0o600 });
|
|
54
|
+
}
|
|
55
|
+
const tidasExecutable = path.join(temporary, path.basename(qualified.tidas.executable_path));
|
|
56
|
+
copyFoundryIsolatedExecutable(qualified.tidas.executable_path, tidasExecutable);
|
|
57
|
+
const actual = captureFoundryInput(tidasExecutable), expected = qualified.tidas.expectation.executable;
|
|
58
|
+
if (actual.bytes !== expected.bytes || actual.sha256 !== expected.sha256)
|
|
59
|
+
throw new FoundryContextError("runtime_tidas_unqualified", "The selected native executable changed.");
|
|
60
|
+
const byPath = new Map(entries.map((entry) => [path.resolve(context.taskRoot, entry.path), entry]));
|
|
61
|
+
const operations = new Set(), seen = new Set();
|
|
62
|
+
let ancestor = rows.file;
|
|
63
|
+
while (ancestor) {
|
|
64
|
+
if (seen.has(ancestor))
|
|
65
|
+
throw new FoundryContextError("workflow_lineage_invalid", "Row manifest lineage contains a cycle.");
|
|
66
|
+
seen.add(ancestor);
|
|
67
|
+
const entry = byPath.get(ancestor);
|
|
68
|
+
if (!entry)
|
|
69
|
+
throw new FoundryContextError("workflow_lineage_invalid", "Row predecessor is not registered.");
|
|
70
|
+
operations.add(entry.operation_id);
|
|
71
|
+
const value = readWorkflowArtifact(context, entry).value;
|
|
72
|
+
ancestor = typeof value.predecessor === "string" ? value.predecessor : null;
|
|
73
|
+
}
|
|
74
|
+
const reportFor = (name, type) => {
|
|
75
|
+
const entry = entries.findLast((entry) => operations.has(entry.operation_id) &&
|
|
76
|
+
path.basename(entry.path) === name &&
|
|
77
|
+
entry.path.split("/").includes(type));
|
|
78
|
+
return entry ? path.resolve(context.taskRoot, entry.path) : undefined;
|
|
79
|
+
};
|
|
80
|
+
const contracts = new Map();
|
|
81
|
+
for (const entry of entries.filter((entry) => entry.command === "dataset-context-pack" &&
|
|
82
|
+
path.basename(entry.path) === "contract-report.json")) {
|
|
83
|
+
const report = readWorkflowArtifact(context, entry).value;
|
|
84
|
+
contracts.set(String(report.type), workflowObject(report.files));
|
|
85
|
+
}
|
|
86
|
+
const order = [
|
|
87
|
+
"contact",
|
|
88
|
+
"source",
|
|
89
|
+
"unitgroup",
|
|
90
|
+
"flowproperty",
|
|
91
|
+
"flow",
|
|
92
|
+
"process",
|
|
93
|
+
"lifecyclemodel",
|
|
94
|
+
];
|
|
95
|
+
const scope = [...rows.value.sets].sort((a, b) => order.indexOf(a.type) - order.indexOf(b.type));
|
|
96
|
+
for (const originalSet of scope) {
|
|
97
|
+
const set = approval?.datasetType === originalSet.type
|
|
98
|
+
? { ...originalSet, file: approval.inputFile }
|
|
99
|
+
: originalSet;
|
|
100
|
+
const completed = executionProgress?.scopes.get(set.type);
|
|
101
|
+
if (completed) {
|
|
102
|
+
sets.push(completed);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const owners = createFoundryFinalizeOwners(context, qualified, temporary, {
|
|
106
|
+
environment,
|
|
107
|
+
tidasExecutable,
|
|
108
|
+
receiptFile,
|
|
109
|
+
datasetType: set.type,
|
|
110
|
+
});
|
|
111
|
+
const contract = contracts.get(set.type);
|
|
112
|
+
if (!contract)
|
|
113
|
+
throw new FoundryContextError("workflow_context_required", "Finalization requires the current owner contract pack.");
|
|
114
|
+
const needsIdentity = ["flow", "process"].includes(set.type);
|
|
115
|
+
let identityIndex = state.identity?.value.index;
|
|
116
|
+
if (needsIdentity && typeof identityIndex === "string") {
|
|
117
|
+
const prepared = workflowObject(owners.preflight.runDatasetIdentityPreflightRequestsBuild({
|
|
118
|
+
type: set.type,
|
|
119
|
+
rowsFile: set.file,
|
|
120
|
+
sourceIndex: identityIndex,
|
|
121
|
+
outDir: path.join(output, set.type, "preflight-inputs"),
|
|
122
|
+
}));
|
|
123
|
+
const file = workflowObject(prepared.files).identity_preflight_requests;
|
|
124
|
+
if (prepared.status !== "ready" || typeof file !== "string")
|
|
125
|
+
throw new FoundryContextError("finalize_identity_inputs_invalid", "Finalization needs fresh current-scope identity requests.");
|
|
126
|
+
const merged = workflowObject(owners.preflight.runDatasetIdentityPreflightIndexMerge({
|
|
127
|
+
baseIndex: identityIndex,
|
|
128
|
+
updateIndex: path.resolve(context.assetRoot, file),
|
|
129
|
+
outDir: path.join(output, set.type, "preflight-inputs", "merged"),
|
|
130
|
+
}));
|
|
131
|
+
const mergedFile = workflowObject(merged.files).merged_index;
|
|
132
|
+
if (merged.status !== "ready" || typeof mergedFile !== "string")
|
|
133
|
+
throw new FoundryContextError("finalize_identity_inputs_invalid", "Finalization identity index could not preserve dependency evidence.");
|
|
134
|
+
identityIndex = path.resolve(context.assetRoot, mergedFile);
|
|
135
|
+
}
|
|
136
|
+
const result = workflowObject(owners.invoke(() => owners.finalize.runDatasetPostAuthoringFinalize({
|
|
137
|
+
type: ["unitgroup", "flowproperty"].includes(set.type) ? "support" : set.type,
|
|
138
|
+
rowsFile: set.file,
|
|
139
|
+
outDir: path.join(output, set.type),
|
|
140
|
+
profile,
|
|
141
|
+
...(approval?.datasetType === set.type && authorization
|
|
142
|
+
? {
|
|
143
|
+
taskAuthorization: authorization,
|
|
144
|
+
taskAuthorizationBinding: authorization.binding,
|
|
145
|
+
mintUnmatchedFpUgSupport: ["unitgroup", "flowproperty"].includes(set.type) &&
|
|
146
|
+
authorization.allowed_actions.includes("canonical_support_local_mint"),
|
|
147
|
+
}
|
|
148
|
+
: {}),
|
|
149
|
+
schemaFile: contract.schema,
|
|
150
|
+
yamlFile: contract.methodology,
|
|
151
|
+
rulesetFile: contract.ruleset,
|
|
152
|
+
targetUserId: context.accountIntent?.userId,
|
|
153
|
+
expectedProjectRef: context.accountIntent?.projectRef,
|
|
154
|
+
expectedUserId: context.accountIntent?.userId,
|
|
155
|
+
requireIdentityPreflight: needsIdentity,
|
|
156
|
+
runIdentityPreflight: needsIdentity && Boolean(state.identity) && Boolean(receiptFile),
|
|
157
|
+
identityPreflightIndex: identityIndex,
|
|
158
|
+
identityPreflightAuthReceipt: receiptFile,
|
|
159
|
+
identityPreflightConcurrency: 1,
|
|
160
|
+
identityPreflightMaxAttempts: 1,
|
|
161
|
+
identityDecisionApplyReport: rows.value.identity_reports,
|
|
162
|
+
classificationDecisionApplyReport: reportFor("classification-decisions-apply-report.json", set.type),
|
|
163
|
+
locationDecisionApplyReport: reportFor("location-decisions-apply-report.json", set.type),
|
|
164
|
+
patchCollectReport: reportFor("authoring-patch-collect-report.json", set.type),
|
|
165
|
+
patchApplyReport: reportFor("dataset-patch-apply-report.json", set.type),
|
|
166
|
+
processes: rows.value.sets.find((item) => item.type === "process")?.file,
|
|
167
|
+
flows: executionProgress?.scopes.get("flow")?.final_rows ??
|
|
168
|
+
rows.value.sets.find((item) => item.type === "flow")?.file,
|
|
169
|
+
verifyRemote: Boolean(context.accountIntent),
|
|
170
|
+
remoteStateCode: "0",
|
|
171
|
+
remoteRootPolicy: "candidate",
|
|
172
|
+
})));
|
|
173
|
+
const files = workflowObject(result.files);
|
|
174
|
+
sets.push({
|
|
175
|
+
type: set.type,
|
|
176
|
+
input_rows: set.file,
|
|
177
|
+
status: result.status,
|
|
178
|
+
report: path.resolve(context.assetRoot, String(files.report)),
|
|
179
|
+
final_rows: typeof files.final_rows === "string"
|
|
180
|
+
? path.resolve(context.assetRoot, files.final_rows)
|
|
181
|
+
: null,
|
|
182
|
+
mutation_manifest: files.mutation_manifest,
|
|
183
|
+
handoff: files.commit_handoff_plan,
|
|
184
|
+
authorization_inputs: context.accountIntent
|
|
185
|
+
? [
|
|
186
|
+
{ input_kind: "current_rows", file: set.file },
|
|
187
|
+
...(typeof files.final_rows === "string"
|
|
188
|
+
? [
|
|
189
|
+
{
|
|
190
|
+
input_kind: "final_rows",
|
|
191
|
+
file: path.resolve(context.assetRoot, files.final_rows),
|
|
192
|
+
},
|
|
193
|
+
]
|
|
194
|
+
: []),
|
|
195
|
+
].map((input) => {
|
|
196
|
+
const fact = captureFoundryInput(input.file);
|
|
197
|
+
return {
|
|
198
|
+
...input,
|
|
199
|
+
sha256: fact.sha256,
|
|
200
|
+
binding: {
|
|
201
|
+
workspace_id: context.workspaceId,
|
|
202
|
+
task_id: context.taskId,
|
|
203
|
+
actor_id: context.actorId,
|
|
204
|
+
project_ref: context.accountIntent.projectRef,
|
|
205
|
+
user_id: context.accountIntent.userId,
|
|
206
|
+
profile_id: profile,
|
|
207
|
+
profile_sha256: profileLock.profile_sha256,
|
|
208
|
+
input_scope_sha256: fact.sha256,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
})
|
|
212
|
+
: [],
|
|
213
|
+
});
|
|
214
|
+
const before = blockers.length;
|
|
215
|
+
if (Array.isArray(result.blockers))
|
|
216
|
+
blockers.push(...result.blockers.map(workflowObject));
|
|
217
|
+
if (!["ready_for_remote_write", "ready_reference_only"].includes(String(result.status)) &&
|
|
218
|
+
blockers.length === before)
|
|
219
|
+
blockers.push({ code: "finalize_owner_not_ready", type: set.type, status: result.status });
|
|
220
|
+
}
|
|
221
|
+
if (!scope.length)
|
|
222
|
+
blockers.push({
|
|
223
|
+
code: "reference_only_verification_required",
|
|
224
|
+
message: "Reference-only scopes still require independent canonical reference verification before completion.",
|
|
225
|
+
});
|
|
226
|
+
for (const input of context.inputs)
|
|
227
|
+
readFoundryInput(context, input.path);
|
|
228
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
229
|
+
return await runFoundryTaskOperation(context, {
|
|
230
|
+
command: "dataset-workflow-finalize",
|
|
231
|
+
options: { nonce, rows_report: rows.file },
|
|
232
|
+
validateCurrent(index) {
|
|
233
|
+
if (currentWorkflowState(context, index).rows?.entry.sha256 !== rows.entry.sha256)
|
|
234
|
+
throw new FoundryContextError("workflow_rows_changed", "Rows changed during finalization.");
|
|
235
|
+
if (authorization &&
|
|
236
|
+
(createHash("sha256")
|
|
237
|
+
.update(readTaskBytes(context, "authorization.json"))
|
|
238
|
+
.digest("hex") !== approvalPointer ||
|
|
239
|
+
!taskAuthorizationMatches(authorization, authorization.binding)))
|
|
240
|
+
throw new FoundryContextError("authorization_update_conflict", "Preparation approval expired or changed during finalization.");
|
|
241
|
+
},
|
|
242
|
+
}, (operation) => {
|
|
243
|
+
registerWorkflowStageFiles(context, operation, output);
|
|
244
|
+
const result = {
|
|
245
|
+
schema: "tiangong-foundry.finalize-stage.v1",
|
|
246
|
+
status: blockers.length ? "blocked" : "ready_for_authorization",
|
|
247
|
+
rows_report: rows.file,
|
|
248
|
+
assessment_report: state.assessment.file,
|
|
249
|
+
owner_base: context.assetRoot,
|
|
250
|
+
approval_source_sha256: approval?.sourceSha256 ?? null,
|
|
251
|
+
approval_authorization_sha256: approval?.authorizationSha256 ?? null,
|
|
252
|
+
execution_progress_sha256: executionProgress?.sha256 ?? null,
|
|
253
|
+
sets,
|
|
254
|
+
blockers,
|
|
255
|
+
};
|
|
256
|
+
operation.writeJson(path.join(output, "foundry-finalize.json"), result);
|
|
257
|
+
return result;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
finally {
|
|
261
|
+
delete environment.TIANGONG_LCA_ACCESS_TOKEN;
|
|
262
|
+
fs.rmSync(temporary, { recursive: true, force: true });
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import { type WorkflowRowSet } from "./foundry-workflow-state.ts";
|
|
4
|
+
export declare function applyFoundryIdentityDecisions(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, temporary: string, request: {
|
|
5
|
+
task: Record<string, unknown>;
|
|
6
|
+
decisions: unknown[];
|
|
7
|
+
sets: readonly WorkflowRowSet[];
|
|
8
|
+
output: string;
|
|
9
|
+
}): {
|
|
10
|
+
sets: WorkflowRowSet[];
|
|
11
|
+
reports: string[];
|
|
12
|
+
rewriteReports: string[];
|
|
13
|
+
blockers: Record<string, unknown>[];
|
|
14
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { FoundryContextError, readFoundryInput, } from "./foundry-runtime-context.js";
|
|
5
|
+
import { createFoundryDecisionOwners } from "./foundry-decision-owners.js";
|
|
6
|
+
import { createFoundryIdentityOwners } from "./foundry-identity-owners.js";
|
|
7
|
+
import { createFoundryRuntimeUtils } from "./foundry-runtime-utils.js";
|
|
8
|
+
import { parseScalar } from "./foundry-args.js";
|
|
9
|
+
import { createTidasRowUtils } from "./tidas-row-utils.js";
|
|
10
|
+
import { bundleRowTypes } from "./bundle-row-types.js";
|
|
11
|
+
import { createCanonicalSupportRewriteUtils } from "./canonical-support-rewrites.js";
|
|
12
|
+
import { createIdentityReferenceRewriteUtils } from "./identity-reference-rewrite-utils.js";
|
|
13
|
+
import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
|
|
14
|
+
import { readRows, ensureArray } from "./import-curation/internal/runtime-io.js";
|
|
15
|
+
import { workflowObject } from "./foundry-workflow-state.js";
|
|
16
|
+
const sha = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
17
|
+
function invalid(message) {
|
|
18
|
+
throw new FoundryContextError("task_semantic_identity_invalid", message);
|
|
19
|
+
}
|
|
20
|
+
function key(item) {
|
|
21
|
+
return `${String(item.dataset_type)}:${String(item.dataset_id)}:${String(item.dataset_version)}`;
|
|
22
|
+
}
|
|
23
|
+
export function applyFoundryIdentityDecisions(context, qualified, temporary, request) {
|
|
24
|
+
const task = request.task;
|
|
25
|
+
const roster = new Map(ensureArray(task.identity_action_items).map((item) => {
|
|
26
|
+
const value = workflowObject(item);
|
|
27
|
+
return [key(value), value];
|
|
28
|
+
}));
|
|
29
|
+
const expectedContext = workflowObject(task.context_bundle).sha256;
|
|
30
|
+
if (!roster.size ||
|
|
31
|
+
typeof expectedContext !== "string" ||
|
|
32
|
+
request.decisions.length !== roster.size)
|
|
33
|
+
invalid("Submit every identity in the selected task with its current context bundle.");
|
|
34
|
+
const seen = new Set();
|
|
35
|
+
const decisions = request.decisions.map((raw) => {
|
|
36
|
+
const decision = workflowObject(raw), selected = roster.get(key(decision));
|
|
37
|
+
if (!selected || seen.has(key(decision)))
|
|
38
|
+
invalid("Identity submission scope differs from its task.");
|
|
39
|
+
seen.add(key(decision));
|
|
40
|
+
if (!["flow", "process"].includes(String(decision.dataset_type)) ||
|
|
41
|
+
!["reuse_existing_reference", "create_new", "block_unresolved"].includes(String(decision.identity_decision)))
|
|
42
|
+
invalid("Use the identity task's explicit dataset type and decision values.");
|
|
43
|
+
if (decision.identity_decision === "reuse_existing_reference") {
|
|
44
|
+
const canonical = workflowObject(decision.canonical);
|
|
45
|
+
if (canonical.table !== (decision.dataset_type === "flow" ? "flows" : "processes") ||
|
|
46
|
+
typeof canonical.ref_object_id !== "string" ||
|
|
47
|
+
!canonical.ref_object_id.trim() ||
|
|
48
|
+
typeof canonical.version !== "string" ||
|
|
49
|
+
!canonical.version.trim())
|
|
50
|
+
invalid("Canonical identity must name the matching dataset table, id and version.");
|
|
51
|
+
}
|
|
52
|
+
const authoring = workflowObject(decision.authoring_context);
|
|
53
|
+
if (authoring.context_bundle_sha256 !== expectedContext)
|
|
54
|
+
invalid("Identity decision context bundle differs from the current task.");
|
|
55
|
+
const expectedPackage = path.resolve(context.assetRoot, String(selected.authoring_package));
|
|
56
|
+
if (typeof decision.authoring_package !== "string" ||
|
|
57
|
+
path.resolve(context.assetRoot, decision.authoring_package) !== expectedPackage ||
|
|
58
|
+
decision.authoring_package_sha256 !== selected.authoring_package_sha256)
|
|
59
|
+
invalid("Identity decisions must use their registered task snapshot and digest.");
|
|
60
|
+
if (sha(readFoundryInput(context, expectedPackage)) !== selected.authoring_package_sha256)
|
|
61
|
+
invalid("Identity authoring snapshot changed.");
|
|
62
|
+
if (!request.sets.some((set) => set.type === decision.dataset_type))
|
|
63
|
+
invalid("Identity decision has no current local row scope.");
|
|
64
|
+
return { ...decision, authoring_package: expectedPackage };
|
|
65
|
+
});
|
|
66
|
+
const owners = createFoundryDecisionOwners(context, qualified, temporary);
|
|
67
|
+
const next = new Map(request.sets.map((set) => [set.type, set]));
|
|
68
|
+
const reports = [], rewriteReports = [], blockers = [];
|
|
69
|
+
const decisionFile = path.join(request.output, "identity-decisions.jsonl");
|
|
70
|
+
fs.mkdirSync(request.output, { recursive: true });
|
|
71
|
+
fs.writeFileSync(decisionFile, decisions.map((item) => JSON.stringify(item)).join("\n") + "\n");
|
|
72
|
+
for (const type of new Set(decisions.map((item) => String(item.dataset_type)))) {
|
|
73
|
+
const set = next.get(type);
|
|
74
|
+
readFoundryInput(context, set.file);
|
|
75
|
+
const original = readRows(set.file);
|
|
76
|
+
const rowKeys = new Set(original.map((row) => {
|
|
77
|
+
const id = datasetIdentity(row, 0, type);
|
|
78
|
+
return `${type}:${id.id}:${id.version}`;
|
|
79
|
+
}));
|
|
80
|
+
if (decisions.some((item) => item.dataset_type === type && !rowKeys.has(key(item))))
|
|
81
|
+
invalid("An identity decision does not identify a current row.");
|
|
82
|
+
const result = workflowObject(owners.invoke(() => owners.identity.runDatasetIdentityDecisionsApply({
|
|
83
|
+
type,
|
|
84
|
+
rowsFile: set.file,
|
|
85
|
+
decisions: decisionFile,
|
|
86
|
+
outDir: path.join(request.output, type),
|
|
87
|
+
authoringPackageDir: path.resolve(context.assetRoot, String(workflowObject(task.files).authoring_package_snapshots_dir)),
|
|
88
|
+
})));
|
|
89
|
+
const files = workflowObject(result.files);
|
|
90
|
+
const report = path.resolve(context.assetRoot, String(files.report));
|
|
91
|
+
reports.push(report);
|
|
92
|
+
const output = path.resolve(context.assetRoot, String(files.output_rows));
|
|
93
|
+
const references = path.resolve(context.assetRoot, String(files.reference_rows));
|
|
94
|
+
const unresolved = path.resolve(context.assetRoot, String(files.unresolved_reference_rows));
|
|
95
|
+
const outputRows = readRows(output), referenceRows = readRows(references), unresolvedRows = readRows(unresolved);
|
|
96
|
+
const inventory = (rows) => rows.map((row) => sha(JSON.stringify(row))).sort();
|
|
97
|
+
if (JSON.stringify(inventory(original)) !==
|
|
98
|
+
JSON.stringify(inventory([...outputRows, ...referenceRows, ...unresolvedRows])))
|
|
99
|
+
invalid("Identity output/reference/unresolved partitions do not preserve the input rows.");
|
|
100
|
+
if (result.status !== "completed" || !Array.isArray(result.blockers) || result.blockers.length)
|
|
101
|
+
blockers.push({ code: "semantic_identity_apply_blocked", type, report: result });
|
|
102
|
+
if (unresolvedRows.length)
|
|
103
|
+
blockers.push({
|
|
104
|
+
code: "semantic_identity_unresolved",
|
|
105
|
+
type,
|
|
106
|
+
rows: unresolvedRows.length,
|
|
107
|
+
report,
|
|
108
|
+
});
|
|
109
|
+
next.set(type, { ...set, file: output, count: outputRows.length });
|
|
110
|
+
}
|
|
111
|
+
if (blockers.length)
|
|
112
|
+
return { sets: [...next.values()], reports, rewriteReports, blockers };
|
|
113
|
+
const flowReport = reports.find((file) => workflowObject(JSON.parse(fs.readFileSync(file, "utf8"))).dataset_type === "flow");
|
|
114
|
+
if (flowReport && next.has("process")) {
|
|
115
|
+
const flow = workflowObject(JSON.parse(fs.readFileSync(flowReport, "utf8")));
|
|
116
|
+
if (Number(workflowObject(flow.counts).identity_reference_rewrites) > 0) {
|
|
117
|
+
const runtime = createFoundryRuntimeUtils({ parseScalar, repoRoot: context.assetRoot });
|
|
118
|
+
const rows = createTidasRowUtils({ ...runtime, bundleRowTypes });
|
|
119
|
+
const support = createCanonicalSupportRewriteUtils({
|
|
120
|
+
...runtime,
|
|
121
|
+
...rows,
|
|
122
|
+
});
|
|
123
|
+
const preflight = createFoundryIdentityOwners(context, qualified, "flow", {
|
|
124
|
+
environment: {},
|
|
125
|
+
cwd: temporary,
|
|
126
|
+
}).preflight;
|
|
127
|
+
const dependencies = {
|
|
128
|
+
...runtime,
|
|
129
|
+
...rows,
|
|
130
|
+
ensureArray,
|
|
131
|
+
supportText: support.supportText,
|
|
132
|
+
foundryTraceNamespace: "https://tiangong-lca.dev/foundry/import-curation/1",
|
|
133
|
+
identityPreflightCommands: preflight,
|
|
134
|
+
datasetIdentity: (row, type) => datasetIdentity(row, 0, type),
|
|
135
|
+
};
|
|
136
|
+
const rewrites = createIdentityReferenceRewriteUtils(dependencies);
|
|
137
|
+
const set = next.get("process"), outDir = path.join(request.output, "process-references");
|
|
138
|
+
const result = workflowObject(rewrites.applyIdentityReferenceRewrites({
|
|
139
|
+
datasetType: "process",
|
|
140
|
+
rowsFile: set.file,
|
|
141
|
+
outFile: path.join(outDir, "process.rows.jsonl"),
|
|
142
|
+
outDir,
|
|
143
|
+
options: { identityDecisionApplyReport: flowReport },
|
|
144
|
+
}));
|
|
145
|
+
const report = path.join(outDir, "identity-reference-rewrites-report.json");
|
|
146
|
+
fs.writeFileSync(report, JSON.stringify({ ...result, dataset_type: "process" }, null, 2) + "\n");
|
|
147
|
+
rewriteReports.push(report);
|
|
148
|
+
const file = path.resolve(context.assetRoot, String(result.output_rows_file));
|
|
149
|
+
if (!String(result.status).startsWith("completed") ||
|
|
150
|
+
!Array.isArray(result.blockers) ||
|
|
151
|
+
result.blockers.length ||
|
|
152
|
+
readRows(file).length !== set.count)
|
|
153
|
+
blockers.push({ code: "semantic_identity_rewrite_blocked", report: result });
|
|
154
|
+
else
|
|
155
|
+
next.set("process", { ...set, file });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { sets: [...next.values()], reports, rewriteReports, blockers };
|
|
159
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import { type FoundryAuthentication } from "./foundry-runtime-identity.ts";
|
|
4
|
+
import type { ArtifactEntry } from "./foundry-task-types.ts";
|
|
5
|
+
/** Run the existing read-only owner first; the local transaction only records its captured evidence. */
|
|
6
|
+
export declare function runFoundryWorkflowIdentity(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, entries: readonly ArtifactEntry[], authentication?: FoundryAuthentication): Promise<import("./foundry-task-types.ts").JsonRecord>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { FoundryContextError, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
5
|
+
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
6
|
+
import { verifyFoundryRuntimeIdentity, } from "./foundry-runtime-identity.js";
|
|
7
|
+
import { createFoundryAuthenticationEnvironment } from "./foundry-authentication-environment.js";
|
|
8
|
+
import { createFoundryIdentityOwners } from "./foundry-identity-owners.js";
|
|
9
|
+
import { currentWorkflowState, workflowObject } from "./foundry-workflow-state.js";
|
|
10
|
+
import { runFoundryTaskOperation, withFoundryTaskMetadata } from "./foundry-task-store.js";
|
|
11
|
+
import { registerWorkflowStageFiles } from "./foundry-workflow-io.js";
|
|
12
|
+
import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
|
|
13
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
14
|
+
/** Run the existing read-only owner first; the local transaction only records its captured evidence. */
|
|
15
|
+
export async function runFoundryWorkflowIdentity(context, qualified, entries, authentication = { mode: "oauth" }) {
|
|
16
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
17
|
+
const state = currentWorkflowState(context, entries), rows = state.rows;
|
|
18
|
+
if (!rows || !state.assessment)
|
|
19
|
+
throw new FoundryContextError("workflow_rows_required", "Assess the current rows before identity preflight.");
|
|
20
|
+
if (!context.accountIntent)
|
|
21
|
+
throw new FoundryContextError("needs_auth", "Identity preflight requires a task spec with the intended project and user account.");
|
|
22
|
+
await withFoundryTaskMetadata(context, (_, index) => {
|
|
23
|
+
if (currentWorkflowState(context, index).rows?.entry.sha256 !== rows.entry.sha256)
|
|
24
|
+
throw new FoundryContextError("workflow_identity_rows_changed", "Current rows changed before identity preflight.");
|
|
25
|
+
});
|
|
26
|
+
const identity = verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
27
|
+
const nonce = randomUUID();
|
|
28
|
+
const output = resolveFoundryOutput(context, `outputs/identity/${nonce}`);
|
|
29
|
+
const temporary = resolveFoundryOutput(context, `tmp/identity-${nonce}`);
|
|
30
|
+
fs.mkdirSync(output, { recursive: true, mode: 0o700 });
|
|
31
|
+
fs.mkdirSync(temporary, { recursive: true, mode: 0o700 });
|
|
32
|
+
const environment = createFoundryAuthenticationEnvironment(authentication, context.accountIntent.sessionReference, process.env);
|
|
33
|
+
environment.FOUNDRY_VERIFIED_PROJECT_REF = context.accountIntent.projectRef;
|
|
34
|
+
environment.FOUNDRY_VERIFIED_USER_ID = context.accountIntent.userId;
|
|
35
|
+
const receipt = path.join(temporary, "identity-receipt.json");
|
|
36
|
+
fs.writeFileSync(receipt, JSON.stringify(identity.receipt), { mode: 0o600 });
|
|
37
|
+
const sets = [], blockers = [];
|
|
38
|
+
try {
|
|
39
|
+
for (const input of context.inputs)
|
|
40
|
+
readFoundryInput(context, input.path);
|
|
41
|
+
for (const set of rows.value.sets) {
|
|
42
|
+
if (set.type !== "flow" && set.type !== "process")
|
|
43
|
+
continue;
|
|
44
|
+
readFoundryInput(context, set.file);
|
|
45
|
+
const owner = createFoundryIdentityOwners(context, qualified, set.type, {
|
|
46
|
+
environment,
|
|
47
|
+
cwd: temporary,
|
|
48
|
+
});
|
|
49
|
+
const outDir = path.join(output, set.type);
|
|
50
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
51
|
+
const sourceIndex = path.join(outDir, "source-context.jsonl");
|
|
52
|
+
fs.writeFileSync(sourceIndex, readRows(set.file)
|
|
53
|
+
.map((row) => {
|
|
54
|
+
const selected = datasetIdentity(row, 0, set.type);
|
|
55
|
+
return JSON.stringify({
|
|
56
|
+
dataset_type: set.type,
|
|
57
|
+
dataset_id: selected.id,
|
|
58
|
+
dataset_version: selected.version,
|
|
59
|
+
source_file: set.file,
|
|
60
|
+
});
|
|
61
|
+
})
|
|
62
|
+
.join("\n") + "\n");
|
|
63
|
+
const prepared = workflowObject(owner.invoke(() => owner.preflight.runDatasetIdentityPreflightRequestsBuild({
|
|
64
|
+
type: set.type,
|
|
65
|
+
rowsFile: set.file,
|
|
66
|
+
sourceIndex,
|
|
67
|
+
outDir,
|
|
68
|
+
})));
|
|
69
|
+
const files = workflowObject(prepared.files);
|
|
70
|
+
const index = path.resolve(context.assetRoot, String(files.identity_preflight_requests));
|
|
71
|
+
const audited = workflowObject(owner.invoke(() => owner.preflight.runDatasetIdentityPreflightQueryAudit({
|
|
72
|
+
index,
|
|
73
|
+
outDir: path.join(outDir, "query-audit"),
|
|
74
|
+
})));
|
|
75
|
+
if (prepared.status !== "ready" || audited.status !== "passed") {
|
|
76
|
+
blockers.push({
|
|
77
|
+
code: "identity_query_requires_input",
|
|
78
|
+
type: set.type,
|
|
79
|
+
prepare: prepared.blockers,
|
|
80
|
+
audit: audited.blockers,
|
|
81
|
+
});
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const result = workflowObject(owner.invoke(() => owner.preflight.runDatasetIdentityPreflightRun({
|
|
85
|
+
index,
|
|
86
|
+
outDir: path.join(outDir, "run"),
|
|
87
|
+
authReceipt: receipt,
|
|
88
|
+
expectedProjectRef: context.accountIntent.projectRef,
|
|
89
|
+
expectedUserId: context.accountIntent.userId,
|
|
90
|
+
maxAttempts: 1,
|
|
91
|
+
timeoutMs: 60_000,
|
|
92
|
+
})));
|
|
93
|
+
if (!["completed", "completed_with_identity_findings"].includes(String(result.status)))
|
|
94
|
+
blockers.push({ code: "identity_preflight_failed", type: set.type, report: result });
|
|
95
|
+
sets.push({
|
|
96
|
+
type: set.type,
|
|
97
|
+
rows: set.file,
|
|
98
|
+
index,
|
|
99
|
+
status: result.status,
|
|
100
|
+
report: workflowObject(result.files).report,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
for (const input of context.inputs)
|
|
104
|
+
readFoundryInput(context, input.path);
|
|
105
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
106
|
+
let combinedIndex = sets.length ? String(sets[0].index) : null;
|
|
107
|
+
if (!blockers.length && sets.length > 1) {
|
|
108
|
+
const owner = createFoundryIdentityOwners(context, qualified, "flow", {
|
|
109
|
+
environment,
|
|
110
|
+
cwd: temporary,
|
|
111
|
+
});
|
|
112
|
+
const merged = workflowObject(owner.invoke(() => owner.preflight.runDatasetIdentityPreflightIndexMerge({
|
|
113
|
+
baseIndex: combinedIndex,
|
|
114
|
+
updateIndex: sets.slice(1).map((set) => set.index),
|
|
115
|
+
outDir: path.join(output, "combined"),
|
|
116
|
+
})));
|
|
117
|
+
const file = workflowObject(merged.files).merged_index;
|
|
118
|
+
if (typeof file !== "string")
|
|
119
|
+
blockers.push({ code: "identity_index_merge_failed", report: merged });
|
|
120
|
+
else
|
|
121
|
+
combinedIndex = path.resolve(context.assetRoot, file);
|
|
122
|
+
}
|
|
123
|
+
return await runFoundryTaskOperation(context, {
|
|
124
|
+
command: "dataset-workflow-identity",
|
|
125
|
+
options: { nonce, rows_report: rows.file },
|
|
126
|
+
validateCurrent(index) {
|
|
127
|
+
if (currentWorkflowState(context, index).rows?.entry.sha256 !== rows.entry.sha256)
|
|
128
|
+
throw new FoundryContextError("workflow_identity_rows_changed", "Rows changed during identity preflight; assess and query their current version.");
|
|
129
|
+
},
|
|
130
|
+
}, (operation) => {
|
|
131
|
+
registerWorkflowStageFiles(context, operation, output);
|
|
132
|
+
const report = {
|
|
133
|
+
schema: "tiangong-foundry.identity-stage.v1",
|
|
134
|
+
status: blockers.length ? "blocked" : "completed",
|
|
135
|
+
rows_report: rows.file,
|
|
136
|
+
account: {
|
|
137
|
+
project_ref: context.accountIntent.projectRef,
|
|
138
|
+
user_id: context.accountIntent.userId,
|
|
139
|
+
},
|
|
140
|
+
checked_at_utc: new Date().toISOString(),
|
|
141
|
+
index: combinedIndex,
|
|
142
|
+
sets,
|
|
143
|
+
blockers,
|
|
144
|
+
};
|
|
145
|
+
operation.writeJson(path.join(output, "foundry-identity.json"), report);
|
|
146
|
+
return report;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
delete environment.TIANGONG_LCA_ACCESS_TOKEN;
|
|
151
|
+
fs.rmSync(temporary, { recursive: true, force: true });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
/** Native conversion is local preparation; its outputs enter the existing task index. */
|
|
4
|
+
export declare function importFoundryWorkflowPackage(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, input: string): Promise<import("./foundry-task-types.ts").JsonRecord>;
|