@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,70 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { captureFoundryInput, FoundryContextError, readFoundryInput, } from "./foundry-runtime-context.js";
|
|
5
|
+
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
6
|
+
import { copyFoundryIsolatedExecutable, createFoundryIsolatedChildEnvironment, } from "./foundry-runtime-environment.js";
|
|
7
|
+
import { runFoundryTaskOperation } from "./foundry-task-store.js";
|
|
8
|
+
import { runTidasImport } from "./tidas-adapter.js";
|
|
9
|
+
/** Native conversion is local preparation; its outputs enter the existing task index. */
|
|
10
|
+
export async function importFoundryWorkflowPackage(context, qualified, input) {
|
|
11
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
12
|
+
readFoundryInput(context, input);
|
|
13
|
+
return runFoundryTaskOperation(context, { command: "dataset-tidas-import", options: { input, from_format: "auto", target: "tidas" } }, (operation) => {
|
|
14
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
15
|
+
readFoundryInput(context, input);
|
|
16
|
+
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "foundry-workflow-import-"));
|
|
17
|
+
try {
|
|
18
|
+
const executable = path.join(temporary, path.basename(qualified.tidas.executable_path));
|
|
19
|
+
copyFoundryIsolatedExecutable(qualified.tidas.executable_path, executable);
|
|
20
|
+
const copied = captureFoundryInput(executable);
|
|
21
|
+
const expected = qualified.tidas.expectation.executable;
|
|
22
|
+
if (copied.bytes !== expected.bytes || copied.sha256 !== expected.sha256)
|
|
23
|
+
throw new FoundryContextError("runtime_tidas_unqualified", "Selected native bytes changed.");
|
|
24
|
+
const output = path.join(temporary, "converted");
|
|
25
|
+
const result = runTidasImport({
|
|
26
|
+
repoRoot: context.workspaceRoot,
|
|
27
|
+
options: { tidasBin: executable, input, output, target: "tidas" },
|
|
28
|
+
environment: createFoundryIsolatedChildEnvironment({ tempRoot: temporary }),
|
|
29
|
+
});
|
|
30
|
+
readFoundryInput(context, input);
|
|
31
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
32
|
+
const prefix = `outputs/import/${operation.operationId}`;
|
|
33
|
+
const files = [];
|
|
34
|
+
const collect = (directory) => {
|
|
35
|
+
for (const name of fs.readdirSync(directory).sort()) {
|
|
36
|
+
const file = path.join(directory, name);
|
|
37
|
+
const stat = fs.lstatSync(file);
|
|
38
|
+
if (stat.isSymbolicLink() || (!stat.isFile() && !stat.isDirectory()))
|
|
39
|
+
throw new FoundryContextError("workflow_output_invalid", "Native outputs must be regular files.");
|
|
40
|
+
if (stat.isDirectory())
|
|
41
|
+
collect(file);
|
|
42
|
+
else {
|
|
43
|
+
if (files.length >= 9_998)
|
|
44
|
+
throw new FoundryContextError("workflow_output_limit", "Native output exceeds the task artifact limit.");
|
|
45
|
+
const relative = path.relative(output, file).split(path.sep).join("/");
|
|
46
|
+
const destination = `${prefix}/${relative}`;
|
|
47
|
+
const fact = captureFoundryInput(file);
|
|
48
|
+
operation.writeText(destination, fs.readFileSync(file));
|
|
49
|
+
files.push({ path: destination, bytes: fact.bytes, sha256: fact.sha256 });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
if (fs.existsSync(output))
|
|
54
|
+
collect(output);
|
|
55
|
+
const report = {
|
|
56
|
+
schema: "tiangong-foundry.native-import-stage.v1",
|
|
57
|
+
status: result.exit_code === 0 ? "completed" : "blocked",
|
|
58
|
+
input: context.inputs.find((fact) => fact.path === input),
|
|
59
|
+
native_exit: result.exit_code,
|
|
60
|
+
native_report: result.report,
|
|
61
|
+
files,
|
|
62
|
+
};
|
|
63
|
+
operation.writeJson(`${prefix}/foundry-native-import.json`, report);
|
|
64
|
+
return report;
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
fs.rmSync(temporary, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import type { FoundryTaskOperation } from "./foundry-task-types.ts";
|
|
4
|
+
export declare function createWorkflowDirectory(context: FoundryRuntimeContext, prefix: string): string;
|
|
5
|
+
export declare function createWorkflowStageDirectory(context: FoundryRuntimeContext, operation: FoundryTaskOperation, stage: string): string;
|
|
6
|
+
export declare function registerWorkflowStageFiles(context: FoundryRuntimeContext, operation: FoundryTaskOperation, directory: string): string[];
|
|
7
|
+
export declare function runWorkflowLocalCli(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, temporary: string, argv: readonly string[]): Record<string, unknown>;
|
|
8
|
+
export declare function runWorkflowLocalCliResult(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, temporary: string, argv: readonly string[]): {
|
|
9
|
+
exit: number;
|
|
10
|
+
report: Record<string, unknown>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { FoundryContextError, assertFoundryWorkspaceWrite, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
6
|
+
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
7
|
+
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
8
|
+
import { createFoundryIsolatedChildEnvironment } from "./foundry-runtime-environment.js";
|
|
9
|
+
export function createWorkflowDirectory(context, prefix) {
|
|
10
|
+
assertFoundryWorkspaceWrite(context);
|
|
11
|
+
const directory = resolveFoundryOutput(context, `${prefix}${randomUUID()}`);
|
|
12
|
+
fs.mkdirSync(path.dirname(directory), { recursive: true, mode: 0o700 });
|
|
13
|
+
resolveFoundryOutput(context, directory);
|
|
14
|
+
// mkdir is exclusive and supports long Windows paths where mkdtemp fails.
|
|
15
|
+
fs.mkdirSync(directory, { mode: 0o700 });
|
|
16
|
+
return resolveFoundryOutput(context, directory);
|
|
17
|
+
}
|
|
18
|
+
export function createWorkflowStageDirectory(context, operation, stage) {
|
|
19
|
+
return createWorkflowDirectory(context, `outputs/${stage}/${operation.operationId}/run-`);
|
|
20
|
+
}
|
|
21
|
+
export function registerWorkflowStageFiles(context, operation, directory) {
|
|
22
|
+
const files = [];
|
|
23
|
+
const visit = (current) => {
|
|
24
|
+
resolveFoundryOutput(context, current);
|
|
25
|
+
for (const name of fs.readdirSync(current).sort()) {
|
|
26
|
+
const file = path.join(current, name), stat = fs.lstatSync(file);
|
|
27
|
+
if (stat.isSymbolicLink() || (!stat.isDirectory() && !stat.isFile()))
|
|
28
|
+
throw new FoundryContextError("workflow_output_invalid", "Stage outputs must be regular files.");
|
|
29
|
+
if (stat.isDirectory())
|
|
30
|
+
visit(file);
|
|
31
|
+
else {
|
|
32
|
+
if (files.length >= 9_998)
|
|
33
|
+
throw new FoundryContextError("workflow_output_limit", "Stage exceeds the task artifact limit.");
|
|
34
|
+
operation.writeText(file, fs.readFileSync(file));
|
|
35
|
+
files.push(file);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
visit(directory);
|
|
40
|
+
return files;
|
|
41
|
+
}
|
|
42
|
+
export function runWorkflowLocalCli(context, qualified, temporary, argv) {
|
|
43
|
+
const result = runWorkflowLocalCliResult(context, qualified, temporary, argv);
|
|
44
|
+
if (![0, 2].includes(result.exit) || "error" in result.report)
|
|
45
|
+
throw new FoundryContextError("workflow_cli_failed", "Local CLI returned an invalid stage report.");
|
|
46
|
+
return result.report;
|
|
47
|
+
}
|
|
48
|
+
export function runWorkflowLocalCliResult(context, qualified, temporary, argv) {
|
|
49
|
+
const local = (argv[0] === "qa" && ["flow", "process", "lifecyclemodel"].includes(argv[1])) ||
|
|
50
|
+
(argv[0] === "dataset" && argv[1] === "curation-queue" && argv[2] === "build") ||
|
|
51
|
+
(argv[0] === "dataset" &&
|
|
52
|
+
argv[1] === "classification" &&
|
|
53
|
+
["apply", "audit"].includes(argv[2])) ||
|
|
54
|
+
(argv[0] === "dataset" && argv[1] === "patch" && argv[2] === "apply");
|
|
55
|
+
if (!local)
|
|
56
|
+
throw new FoundryContextError("workflow_command_invalid", "This stage admits local QA, queue preparation and patch application only.");
|
|
57
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
58
|
+
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
59
|
+
const child = spawnSync(process.execPath, [cli.binPath, ...argv], {
|
|
60
|
+
cwd: context.workspaceRoot,
|
|
61
|
+
env: createFoundryIsolatedChildEnvironment({ tempRoot: temporary }),
|
|
62
|
+
encoding: "utf8",
|
|
63
|
+
shell: false,
|
|
64
|
+
timeout: 120_000,
|
|
65
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
66
|
+
});
|
|
67
|
+
if (child.error ||
|
|
68
|
+
child.signal ||
|
|
69
|
+
![0, 1, 2].includes(child.status ?? -1) ||
|
|
70
|
+
!child.stdout.trim())
|
|
71
|
+
throw new FoundryContextError("workflow_cli_failed", `Local CLI ${argv.slice(0, 2).join(" ")} did not return a stage report.`);
|
|
72
|
+
const report = JSON.parse(child.stdout);
|
|
73
|
+
if (!report || typeof report !== "object" || Array.isArray(report))
|
|
74
|
+
throw new FoundryContextError("workflow_cli_failed", "Local CLI returned an invalid stage report.");
|
|
75
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
76
|
+
return { exit: child.status, report: report };
|
|
77
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
export declare function foundryReferenceScope(context: FoundryRuntimeContext, entries: readonly ArtifactEntry[]): {
|
|
6
|
+
rows: string;
|
|
7
|
+
sources: import("./foundry-runtime-context-types.ts").FoundryInputFact[];
|
|
8
|
+
targets: {
|
|
9
|
+
table: string;
|
|
10
|
+
id: string;
|
|
11
|
+
version: string;
|
|
12
|
+
}[];
|
|
13
|
+
account: {
|
|
14
|
+
project_ref: string;
|
|
15
|
+
user_id: string;
|
|
16
|
+
} | null;
|
|
17
|
+
sha256: string;
|
|
18
|
+
} | null;
|
|
19
|
+
export declare function inspectFoundryReferences(context: FoundryRuntimeContext, entries: readonly ArtifactEntry[]): {
|
|
20
|
+
scope: null;
|
|
21
|
+
verified: boolean;
|
|
22
|
+
result: null;
|
|
23
|
+
} | {
|
|
24
|
+
scope: {
|
|
25
|
+
rows: string;
|
|
26
|
+
sources: import("./foundry-runtime-context-types.ts").FoundryInputFact[];
|
|
27
|
+
targets: {
|
|
28
|
+
table: string;
|
|
29
|
+
id: string;
|
|
30
|
+
version: string;
|
|
31
|
+
}[];
|
|
32
|
+
account: {
|
|
33
|
+
project_ref: string;
|
|
34
|
+
user_id: string;
|
|
35
|
+
} | null;
|
|
36
|
+
sha256: string;
|
|
37
|
+
};
|
|
38
|
+
verified: boolean;
|
|
39
|
+
result: import("./foundry-workflow-state.ts").WorkflowArtifact<Record<string, unknown>> | null;
|
|
40
|
+
};
|
|
41
|
+
export declare function verifyFoundryReferences(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, entries: readonly ArtifactEntry[], authentication?: FoundryAuthentication): Promise<import("./foundry-task-types.ts").JsonRecord>;
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { captureFoundryInput, FoundryContextError, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
6
|
+
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
7
|
+
import { verifyFoundryRuntimeIdentity, } from "./foundry-runtime-identity.js";
|
|
8
|
+
import { createFoundryAuthenticationEnvironment } from "./foundry-authentication-environment.js";
|
|
9
|
+
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
10
|
+
import { createFoundryCommandSpec } from "./foundry-command-spec.js";
|
|
11
|
+
import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./foundry-workflow-state.js";
|
|
12
|
+
import { runFoundryTaskOperation } from "./foundry-task-store.js";
|
|
13
|
+
import { registerWorkflowStageFiles } from "./foundry-workflow-io.js";
|
|
14
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
15
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
16
|
+
import { datasetIdentity, unwrapDatasetPayload, } from "./import-curation/internal/dataset-payload.js";
|
|
17
|
+
import { bundleRowTypes } from "./bundle-row-types.js";
|
|
18
|
+
function invalid(message) {
|
|
19
|
+
throw new FoundryContextError("reference_evidence_invalid", message);
|
|
20
|
+
}
|
|
21
|
+
function indexedFile(context, entries, file) {
|
|
22
|
+
const resolved = resolveFoundryOutput(context, file);
|
|
23
|
+
const entry = entries.find((item) => path.resolve(context.taskRoot, item.path) === resolved);
|
|
24
|
+
if (!entry)
|
|
25
|
+
return invalid("Reference scope requires registered owner evidence.");
|
|
26
|
+
const fact = captureFoundryInput(resolved);
|
|
27
|
+
if (fact.sha256 !== entry.sha256 || fact.bytes !== entry.bytes)
|
|
28
|
+
return invalid("Reference owner evidence changed.");
|
|
29
|
+
return { entry, fact };
|
|
30
|
+
}
|
|
31
|
+
export function foundryReferenceScope(context, entries) {
|
|
32
|
+
const state = currentWorkflowState(context, entries);
|
|
33
|
+
if (!state.rows)
|
|
34
|
+
return null;
|
|
35
|
+
const sources = [];
|
|
36
|
+
const targets = new Map();
|
|
37
|
+
for (const file of state.rows.value.identity_reports) {
|
|
38
|
+
const source = indexedFile(context, entries, file);
|
|
39
|
+
const report = readWorkflowArtifact(context, source.entry).value;
|
|
40
|
+
const counts = workflowObject(report.counts), count = Number(counts.reference_rows ?? 0);
|
|
41
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
42
|
+
invalid("Reference partition count is invalid.");
|
|
43
|
+
if (!count)
|
|
44
|
+
continue;
|
|
45
|
+
if (report.status !== "completed" || !Array.isArray(report.blockers) || report.blockers.length)
|
|
46
|
+
invalid("Reference partition has no successful identity decision.");
|
|
47
|
+
const files = workflowObject(report.files), type = String(report.dataset_type);
|
|
48
|
+
if (!Object.hasOwn(bundleRowTypes, type))
|
|
49
|
+
invalid("Reference partition has an unsupported dataset type.");
|
|
50
|
+
const references = indexedFile(context, entries, path.resolve(context.assetRoot, String(files.reference_rows)));
|
|
51
|
+
const rewrites = indexedFile(context, entries, path.resolve(context.assetRoot, String(files.identity_reference_rewrites)));
|
|
52
|
+
const rows = readRows(references.fact.path), decisions = readRows(rewrites.fact.path).map(workflowObject);
|
|
53
|
+
if (rows.length !== count || decisions.length !== count)
|
|
54
|
+
invalid("Every reference row needs exactly one canonical decision.");
|
|
55
|
+
const original = rows
|
|
56
|
+
.map((row, index) => {
|
|
57
|
+
const id = datasetIdentity(unwrapDatasetPayload(row, type), index, type);
|
|
58
|
+
return `${id.id}@${id.version}`;
|
|
59
|
+
})
|
|
60
|
+
.sort();
|
|
61
|
+
const selected = [];
|
|
62
|
+
for (const decision of decisions) {
|
|
63
|
+
const canonical = workflowObject(decision.canonical), previous = workflowObject(decision.original);
|
|
64
|
+
if (decision.action !== "reuse_ai_selected_existing_reference" ||
|
|
65
|
+
decision.dataset_type !== type ||
|
|
66
|
+
canonical.table !== bundleRowTypes[type].plural ||
|
|
67
|
+
previous.table !== canonical.table ||
|
|
68
|
+
typeof canonical.ref_object_id !== "string" ||
|
|
69
|
+
!canonical.ref_object_id ||
|
|
70
|
+
typeof canonical.version !== "string" ||
|
|
71
|
+
!canonical.version)
|
|
72
|
+
invalid("Canonical reference decision does not match its owning partition.");
|
|
73
|
+
selected.push(`${String(previous.ref_object_id)}@${String(previous.version)}`);
|
|
74
|
+
const target = {
|
|
75
|
+
table: canonical.table,
|
|
76
|
+
id: canonical.ref_object_id,
|
|
77
|
+
version: canonical.version,
|
|
78
|
+
};
|
|
79
|
+
targets.set(sha256Json(target), target);
|
|
80
|
+
}
|
|
81
|
+
if (sha256Json(original) !== sha256Json(selected.sort()))
|
|
82
|
+
invalid("Canonical decisions do not cover the original reference rows.");
|
|
83
|
+
sources.push(source.fact, references.fact, rewrites.fact);
|
|
84
|
+
}
|
|
85
|
+
if (!targets.size)
|
|
86
|
+
return null;
|
|
87
|
+
const intended = [...targets.entries()]
|
|
88
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
89
|
+
.map(([, target]) => target);
|
|
90
|
+
const binding = {
|
|
91
|
+
rows: state.rows.entry.sha256,
|
|
92
|
+
sources,
|
|
93
|
+
targets: intended,
|
|
94
|
+
account: context.accountIntent
|
|
95
|
+
? { project_ref: context.accountIntent.projectRef, user_id: context.accountIntent.userId }
|
|
96
|
+
: null,
|
|
97
|
+
};
|
|
98
|
+
return { sha256: sha256Json(binding), ...binding };
|
|
99
|
+
}
|
|
100
|
+
export function inspectFoundryReferences(context, entries) {
|
|
101
|
+
const scope = foundryReferenceScope(context, entries);
|
|
102
|
+
if (!scope)
|
|
103
|
+
return { scope, verified: false, result: null };
|
|
104
|
+
const result = entries
|
|
105
|
+
.filter((entry) => entry.command === "dataset-workflow-reference-verify" &&
|
|
106
|
+
path.basename(entry.path) === "foundry-reference-verification.json")
|
|
107
|
+
.map((entry) => readWorkflowArtifact(context, entry))
|
|
108
|
+
.findLast((item) => item.value.scope_sha256 === scope.sha256) ?? null;
|
|
109
|
+
if (result && result.value.schema !== "tiangong-foundry.reference-verification.v1")
|
|
110
|
+
invalid("Unknown reference verification result.");
|
|
111
|
+
const verified = result?.value.status === "verified";
|
|
112
|
+
if (verified) {
|
|
113
|
+
if (!Array.isArray(result.value.blockers) ||
|
|
114
|
+
result.value.blockers.length ||
|
|
115
|
+
sha256Json(result.value.targets) !== sha256Json(scope.targets))
|
|
116
|
+
invalid("Reference verification does not cover the current scope.");
|
|
117
|
+
for (const raw of [result.value.input, result.value.report, result.value.checks]) {
|
|
118
|
+
const fact = workflowObject(raw);
|
|
119
|
+
if (typeof fact.path !== "string")
|
|
120
|
+
invalid("Reference verification artifact is missing.");
|
|
121
|
+
const current = indexedFile(context, entries, fact.path).fact;
|
|
122
|
+
if (current.sha256 !== fact.sha256 || current.bytes !== fact.bytes)
|
|
123
|
+
invalid("Reference verification artifact changed.");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return { scope, verified, result };
|
|
127
|
+
}
|
|
128
|
+
export async function verifyFoundryReferences(context, qualified, entries, authentication = { mode: "oauth" }) {
|
|
129
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
130
|
+
const current = inspectFoundryReferences(context, entries);
|
|
131
|
+
if (current.verified)
|
|
132
|
+
return current.result.value;
|
|
133
|
+
const scope = current.scope;
|
|
134
|
+
if (!scope)
|
|
135
|
+
invalid("No current canonical reference partition exists.");
|
|
136
|
+
verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
137
|
+
for (const fact of scope.sources)
|
|
138
|
+
readFoundryInput(context, fact.path);
|
|
139
|
+
const output = resolveFoundryOutput(context, `outputs/reference-verification/${randomUUID()}`);
|
|
140
|
+
fs.mkdirSync(output, { recursive: true, mode: 0o700 });
|
|
141
|
+
const input = path.join(output, "canonical-references.jsonl");
|
|
142
|
+
fs.writeFileSync(input, scope.targets
|
|
143
|
+
.map((item) => JSON.stringify({ "@type": item.table, "@refObjectId": item.id, "@version": item.version }))
|
|
144
|
+
.join("\n") + "\n", { mode: 0o600 });
|
|
145
|
+
const inputFact = captureFoundryInput(input), cli = resolveInstalledTiangongLcaCliPackage();
|
|
146
|
+
const command = createFoundryCommandSpec({
|
|
147
|
+
executable: process.execPath,
|
|
148
|
+
argv: [
|
|
149
|
+
cli.binPath,
|
|
150
|
+
"dataset",
|
|
151
|
+
"verify-remote",
|
|
152
|
+
"--input",
|
|
153
|
+
input,
|
|
154
|
+
"--root-policy",
|
|
155
|
+
"existing",
|
|
156
|
+
"--out-dir",
|
|
157
|
+
path.join(output, "verify"),
|
|
158
|
+
"--json",
|
|
159
|
+
],
|
|
160
|
+
binding: { artifacts: [{ ...inputFact, role: "canonical_references" }] },
|
|
161
|
+
});
|
|
162
|
+
const environment = createFoundryAuthenticationEnvironment(authentication, context.accountIntent?.sessionReference, process.env);
|
|
163
|
+
try {
|
|
164
|
+
const run = spawnSync(command.executable, [...command.argv], {
|
|
165
|
+
cwd: output,
|
|
166
|
+
env: environment,
|
|
167
|
+
shell: false,
|
|
168
|
+
windowsHide: true,
|
|
169
|
+
encoding: "utf8",
|
|
170
|
+
timeout: 120_000,
|
|
171
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
172
|
+
});
|
|
173
|
+
fs.writeFileSync(path.join(output, "stdout.json"), run.stdout ?? "");
|
|
174
|
+
fs.writeFileSync(path.join(output, "stderr.log"), run.stderr ?? "");
|
|
175
|
+
const blockers = [];
|
|
176
|
+
let reportFact = null, checksFact = null;
|
|
177
|
+
try {
|
|
178
|
+
const report = workflowObject(JSON.parse(run.stdout)), files = workflowObject(report.files);
|
|
179
|
+
for (const key of ["report", "checks"]) {
|
|
180
|
+
if (typeof files[key] !== "string")
|
|
181
|
+
invalid("Reference verification output is missing.");
|
|
182
|
+
const file = resolveFoundryOutput(context, files[key]);
|
|
183
|
+
if (path.relative(path.join(output, "verify"), file).startsWith(".."))
|
|
184
|
+
invalid("Reference verification output is outside its fresh directory.");
|
|
185
|
+
const fact = captureFoundryInput(file);
|
|
186
|
+
if (key === "report")
|
|
187
|
+
reportFact = fact;
|
|
188
|
+
else
|
|
189
|
+
checksFact = fact;
|
|
190
|
+
}
|
|
191
|
+
if (sha256Json(JSON.parse(fs.readFileSync(reportFact.path, "utf8"))) !== sha256Json(report))
|
|
192
|
+
invalid("Reference verification stdout and report differ.");
|
|
193
|
+
const checks = readRows(checksFact.path).map(workflowObject), counts = workflowObject(report.counts);
|
|
194
|
+
const byRow = new Map();
|
|
195
|
+
for (const check of checks) {
|
|
196
|
+
const row = byRow.get(check.row_index) ?? [];
|
|
197
|
+
row.push(check);
|
|
198
|
+
byRow.set(check.row_index, row);
|
|
199
|
+
}
|
|
200
|
+
if (report.status !== "passed_remote_verification" ||
|
|
201
|
+
report.root_policy !== "existing" ||
|
|
202
|
+
report.input_path !== input ||
|
|
203
|
+
!Array.isArray(report.blockers) ||
|
|
204
|
+
report.blockers.length ||
|
|
205
|
+
counts.blockers !== 0 ||
|
|
206
|
+
counts.checked !== scope.targets.length ||
|
|
207
|
+
counts.references !== scope.targets.length ||
|
|
208
|
+
counts.rows !== scope.targets.length ||
|
|
209
|
+
checks.length !== scope.targets.length)
|
|
210
|
+
blockers.push({
|
|
211
|
+
code: "reference_verification_incomplete",
|
|
212
|
+
report_blockers: report.blockers ?? null,
|
|
213
|
+
});
|
|
214
|
+
for (const [index, target] of scope.targets.entries()) {
|
|
215
|
+
const matched = (byRow.get(index) ?? []).filter((item) => item.role === "reference" &&
|
|
216
|
+
item.row_index === index &&
|
|
217
|
+
item.path === "" &&
|
|
218
|
+
item.table === target.table &&
|
|
219
|
+
item.id === target.id &&
|
|
220
|
+
item.version === target.version);
|
|
221
|
+
if (matched.length !== 1 ||
|
|
222
|
+
matched[0].status !== "ok" ||
|
|
223
|
+
matched[0].exact_version !== target.version ||
|
|
224
|
+
matched[0].latest_version !== target.version)
|
|
225
|
+
blockers.push({ code: "canonical_reference_not_verified", target, checks: matched });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
blockers.push({
|
|
230
|
+
code: error instanceof FoundryContextError ? error.code : "reference_report_invalid",
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
if (run.error || run.signal || run.status !== 0)
|
|
234
|
+
blockers.push({ code: "reference_cli_failed", exit_code: run.status });
|
|
235
|
+
if (captureFoundryInput(input).sha256 !== inputFact.sha256)
|
|
236
|
+
invalid("Reference query changed during verification.");
|
|
237
|
+
for (const fact of scope.sources)
|
|
238
|
+
readFoundryInput(context, fact.path);
|
|
239
|
+
return runFoundryTaskOperation(context, {
|
|
240
|
+
command: "dataset-workflow-reference-verify",
|
|
241
|
+
options: { scope: scope.sha256, nonce: path.basename(output) },
|
|
242
|
+
validateCurrent(index) {
|
|
243
|
+
if (foundryReferenceScope(context, index)?.sha256 !== scope.sha256)
|
|
244
|
+
invalid("Reference scope changed during verification.");
|
|
245
|
+
},
|
|
246
|
+
}, (operation) => {
|
|
247
|
+
registerWorkflowStageFiles(context, operation, output);
|
|
248
|
+
const result = {
|
|
249
|
+
schema: "tiangong-foundry.reference-verification.v1",
|
|
250
|
+
status: blockers.length ? "unresolved" : "verified",
|
|
251
|
+
scope_sha256: scope.sha256,
|
|
252
|
+
targets: scope.targets,
|
|
253
|
+
input: inputFact,
|
|
254
|
+
report: reportFact,
|
|
255
|
+
checks: checksFact,
|
|
256
|
+
command,
|
|
257
|
+
blockers,
|
|
258
|
+
};
|
|
259
|
+
operation.writeJson(path.join(output, "foundry-reference-verification.json"), result);
|
|
260
|
+
return result;
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
delete environment.TIANGONG_LCA_ACCESS_TOKEN;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FoundryContextError, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
2
|
+
import { runFoundryTaskOperation } from "./foundry-task-store.js";
|
|
3
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
4
|
+
import { detectDatasetType, unwrapDatasetPayload, } from "./import-curation/internal/dataset-payload.js";
|
|
5
|
+
import { supportedDatasetTypes } from "./import-curation/internal/dataset-types.js";
|
|
6
|
+
export function materializeFoundryWorkflowRows(context, sources) {
|
|
7
|
+
if (!sources.length)
|
|
8
|
+
throw new FoundryContextError("workflow_rows_missing", "No selected or converted dataset rows are available.");
|
|
9
|
+
return runFoundryTaskOperation(context, { command: "dataset-workflow-rows", options: { sources } }, (operation) => {
|
|
10
|
+
const grouped = new Map();
|
|
11
|
+
for (const source of sources) {
|
|
12
|
+
const rows = readRows(source, (file) => readFoundryInput(context, file).toString("utf8"));
|
|
13
|
+
for (const row of rows) {
|
|
14
|
+
const type = detectDatasetType(row) ??
|
|
15
|
+
[...supportedDatasetTypes]
|
|
16
|
+
.map((candidate) => detectDatasetType(unwrapDatasetPayload(row, candidate)))
|
|
17
|
+
.find((candidate) => candidate !== null);
|
|
18
|
+
if (!type)
|
|
19
|
+
throw new FoundryContextError("workflow_row_type_unknown", "A selected row has no recognized TIDAS dataset type.");
|
|
20
|
+
const values = grouped.get(type) ?? [];
|
|
21
|
+
const payload = unwrapDatasetPayload(row, type);
|
|
22
|
+
if (payload !== row && row && typeof row === "object" && !Array.isArray(row)) {
|
|
23
|
+
const normalized = { ...row };
|
|
24
|
+
for (const key of [type, "json_ordered", "jsonOrdered", "json", "payload"])
|
|
25
|
+
delete normalized[key];
|
|
26
|
+
normalized.json = payload;
|
|
27
|
+
values.push(normalized);
|
|
28
|
+
}
|
|
29
|
+
else
|
|
30
|
+
values.push(row);
|
|
31
|
+
grouped.set(type, values);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (!grouped.size)
|
|
35
|
+
throw new FoundryContextError("workflow_rows_missing", "The selected input contains no dataset rows.");
|
|
36
|
+
const sets = [...grouped.entries()]
|
|
37
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
38
|
+
.map(([type, rows]) => {
|
|
39
|
+
const file = resolveFoundryOutput(context, `outputs/rows/${operation.operationId}/${type}.rows.json`);
|
|
40
|
+
operation.writeJson(file, rows);
|
|
41
|
+
return { type, file, count: rows.length };
|
|
42
|
+
});
|
|
43
|
+
const report = { schema: "tiangong-foundry.rows-stage.v1", status: "completed", sets };
|
|
44
|
+
operation.writeJson(`outputs/rows/${operation.operationId}/foundry-rows.json`, report);
|
|
45
|
+
return report;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import { type SelectedSemanticInput } from "./foundry-semantic-input.ts";
|
|
4
|
+
import type { ArtifactEntry } from "./foundry-task-types.ts";
|
|
5
|
+
export declare function applyFoundrySemanticInput(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, entries: readonly ArtifactEntry[], submission: SelectedSemanticInput): Promise<import("./foundry-task-types.ts").JsonRecord>;
|