@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,99 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { FoundryContextError, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
5
|
+
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
6
|
+
import { createFoundryIsolatedChildEnvironment } from "./foundry-runtime-environment.js";
|
|
7
|
+
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
8
|
+
import { runFoundryTaskOperation } from "./foundry-task-store.js";
|
|
9
|
+
import { supportedDatasetTypes } from "./import-curation/internal/dataset-types.js";
|
|
10
|
+
import { createWorkflowDirectory } from "./foundry-workflow-io.js";
|
|
11
|
+
export async function prepareFoundryWorkflowContext(context, qualified, selectedTypes) {
|
|
12
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
13
|
+
if (!selectedTypes.length || selectedTypes.some((type) => !supportedDatasetTypes.has(type)))
|
|
14
|
+
throw new FoundryContextError("workflow_context_type_invalid", "Select supported task entity types.");
|
|
15
|
+
const types = [
|
|
16
|
+
...new Set(selectedTypes.flatMap((type) => type === "support" ? ["contact", "source", "flowproperty", "unitgroup"] : [type])),
|
|
17
|
+
].sort();
|
|
18
|
+
return runFoundryTaskOperation(context, { command: "dataset-context-pack", options: { types, profile: "ai-import" } }, (operation) => {
|
|
19
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
20
|
+
for (const input of context.inputs)
|
|
21
|
+
readFoundryInput(context, input.path);
|
|
22
|
+
const parent = resolveFoundryOutput(context, `outputs/context/${operation.operationId}`);
|
|
23
|
+
fs.mkdirSync(parent, { recursive: true, mode: 0o700 });
|
|
24
|
+
resolveFoundryOutput(context, parent);
|
|
25
|
+
// The owner writes to a new task-contained generation. Only this invocation's
|
|
26
|
+
// inspected outputs enter the transaction; an interrupted generation is never adopted.
|
|
27
|
+
const output = createWorkflowDirectory(context, path.join(parent, "run-"));
|
|
28
|
+
fs.mkdirSync(resolveFoundryOutput(context, "tmp"), { recursive: true, mode: 0o700 });
|
|
29
|
+
const temporary = createWorkflowDirectory(context, path.join(context.tempRoot, "context-"));
|
|
30
|
+
try {
|
|
31
|
+
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
32
|
+
const environment = createFoundryIsolatedChildEnvironment({ tempRoot: temporary });
|
|
33
|
+
const reports = [];
|
|
34
|
+
for (const type of types) {
|
|
35
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
36
|
+
const destination = path.join(output, type);
|
|
37
|
+
const child = spawnSync(process.execPath, [
|
|
38
|
+
cli.binPath,
|
|
39
|
+
"dataset",
|
|
40
|
+
"context-pack",
|
|
41
|
+
"--type",
|
|
42
|
+
type,
|
|
43
|
+
"--profile",
|
|
44
|
+
"ai-import",
|
|
45
|
+
"--out-dir",
|
|
46
|
+
destination,
|
|
47
|
+
"--json",
|
|
48
|
+
], {
|
|
49
|
+
cwd: context.workspaceRoot,
|
|
50
|
+
env: environment,
|
|
51
|
+
encoding: "utf8",
|
|
52
|
+
shell: false,
|
|
53
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
54
|
+
timeout: 120_000,
|
|
55
|
+
});
|
|
56
|
+
if (child.error || child.signal || child.status !== 0 || child.stderr)
|
|
57
|
+
throw new FoundryContextError("workflow_context_failed", `CLI context preparation failed for ${type}.`);
|
|
58
|
+
const value = JSON.parse(child.stdout);
|
|
59
|
+
if (!value ||
|
|
60
|
+
typeof value !== "object" ||
|
|
61
|
+
!("status" in value) ||
|
|
62
|
+
value.status !== "completed")
|
|
63
|
+
throw new FoundryContextError("workflow_context_invalid", "CLI returned no completed context pack.");
|
|
64
|
+
reports.push({ type, report: path.join(destination, "outputs/contract-report.json") });
|
|
65
|
+
}
|
|
66
|
+
const files = [];
|
|
67
|
+
const register = (directory) => {
|
|
68
|
+
for (const name of fs.readdirSync(directory).sort()) {
|
|
69
|
+
const file = path.join(directory, name), stat = fs.lstatSync(file);
|
|
70
|
+
if (stat.isSymbolicLink() || (!stat.isDirectory() && !stat.isFile()))
|
|
71
|
+
throw new FoundryContextError("workflow_output_invalid", "Context outputs must be regular files.");
|
|
72
|
+
if (stat.isDirectory())
|
|
73
|
+
register(file);
|
|
74
|
+
else {
|
|
75
|
+
if (files.length >= 9_998)
|
|
76
|
+
throw new FoundryContextError("workflow_output_limit", "Context exceeds the task artifact limit.");
|
|
77
|
+
operation.writeText(file, fs.readFileSync(file));
|
|
78
|
+
files.push(file);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
for (const input of context.inputs)
|
|
83
|
+
readFoundryInput(context, input.path);
|
|
84
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
85
|
+
register(output);
|
|
86
|
+
const report = {
|
|
87
|
+
schema: "tiangong-foundry.context-stage.v1",
|
|
88
|
+
status: "completed",
|
|
89
|
+
reports,
|
|
90
|
+
files,
|
|
91
|
+
};
|
|
92
|
+
operation.writeJson(path.join(output, "foundry-context.json"), report);
|
|
93
|
+
return report;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
fs.rmSync(temporary, { recursive: true, force: true });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
export interface FoundryDecisionWork {
|
|
4
|
+
kind: "classification" | "location" | "identity";
|
|
5
|
+
type: string;
|
|
6
|
+
rows: string;
|
|
7
|
+
task: string;
|
|
8
|
+
queue: string | null;
|
|
9
|
+
status: string;
|
|
10
|
+
blockers: unknown[];
|
|
11
|
+
}
|
|
12
|
+
export declare function prepareFoundryDecisionWork(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, temporary: string, request: {
|
|
13
|
+
type: string;
|
|
14
|
+
rows: string;
|
|
15
|
+
gateReport: string;
|
|
16
|
+
contract: Record<string, unknown>;
|
|
17
|
+
outDir: string;
|
|
18
|
+
}): FoundryDecisionWork[];
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createFoundryDecisionOwners } from "./foundry-decision-owners.js";
|
|
4
|
+
import { decisionTargetPath } from "./foundry-decision-routing.js";
|
|
5
|
+
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
6
|
+
import { workflowObject } from "./foundry-workflow-state.js";
|
|
7
|
+
import { unwrapDatasetPayload } from "./import-curation/internal/dataset-payload.js";
|
|
8
|
+
export function prepareFoundryDecisionWork(context, qualified, temporary, request) {
|
|
9
|
+
const owners = createFoundryDecisionOwners(context, qualified, temporary);
|
|
10
|
+
const gate = workflowObject(JSON.parse(fs.readFileSync(request.gateReport, "utf8")));
|
|
11
|
+
const classification = new Map(), locations = new Map();
|
|
12
|
+
let needsIdentity = false;
|
|
13
|
+
for (const value of Array.isArray(gate.entities) ? gate.entities : []) {
|
|
14
|
+
const entity = workflowObject(value);
|
|
15
|
+
if (typeof entity.authoring_package !== "string")
|
|
16
|
+
continue;
|
|
17
|
+
const file = path.resolve(context.assetRoot, entity.authoring_package);
|
|
18
|
+
const pkg = workflowObject(JSON.parse(fs.readFileSync(file, "utf8")));
|
|
19
|
+
const payload = workflowObject(unwrapDatasetPayload(pkg.source_row, request.type));
|
|
20
|
+
for (const actionValue of Array.isArray(pkg.action_items) ? pkg.action_items : []) {
|
|
21
|
+
const action = workflowObject(actionValue), kind = action.action_kind;
|
|
22
|
+
if (kind === "identity_decision_authoring") {
|
|
23
|
+
needsIdentity = true;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const base = {
|
|
27
|
+
dataset_type: request.type,
|
|
28
|
+
dataset_id: entity.entity_id,
|
|
29
|
+
dataset_version: entity.version,
|
|
30
|
+
source_file: request.rows,
|
|
31
|
+
code: action.code,
|
|
32
|
+
evidence: action.evidence ?? null,
|
|
33
|
+
};
|
|
34
|
+
if (kind === "classification_decision_authoring") {
|
|
35
|
+
const schemaType = request.type === "flow" ? owners.flowClassificationSchemaType(payload) : request.type;
|
|
36
|
+
classification.set(`${String(entity.entity_id)}:${String(entity.version)}:${schemaType}`, {
|
|
37
|
+
...base,
|
|
38
|
+
current_classification: action.evidence ?? null,
|
|
39
|
+
classification_workflow: {
|
|
40
|
+
schema_type: schemaType,
|
|
41
|
+
row_type: request.type,
|
|
42
|
+
commands: {
|
|
43
|
+
input_rows: request.rows,
|
|
44
|
+
output_rows: path.join(request.outDir, "classification", "classified.rows.json"),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else if (kind === "location_decision_authoring" && typeof action.path === "string") {
|
|
50
|
+
const target = decisionTargetPath(action.path);
|
|
51
|
+
locations.set(`${String(entity.entity_id)}:${String(entity.version)}:${target}`, {
|
|
52
|
+
...base,
|
|
53
|
+
path: target,
|
|
54
|
+
location_workflow: {
|
|
55
|
+
schema_type: "location",
|
|
56
|
+
commands: {
|
|
57
|
+
input_rows: request.rows,
|
|
58
|
+
output_rows: path.join(request.outDir, "location", "located.rows.json"),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
66
|
+
const schemas = fs
|
|
67
|
+
.readdirSync(cli.schemaDir)
|
|
68
|
+
.filter((name) => /^tidas_.*_category\.json$/u.test(name))
|
|
69
|
+
.map((name) => path.join(cli.schemaDir, name));
|
|
70
|
+
const result = [];
|
|
71
|
+
for (const [kind, rows] of [
|
|
72
|
+
["classification", [...classification.values()]],
|
|
73
|
+
["location", [...locations.values()]],
|
|
74
|
+
]) {
|
|
75
|
+
if (!rows.length)
|
|
76
|
+
continue;
|
|
77
|
+
const outDir = path.join(request.outDir, kind);
|
|
78
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
79
|
+
const queue = path.join(outDir, `${kind}-queue.jsonl`);
|
|
80
|
+
fs.writeFileSync(queue, rows.map((row) => JSON.stringify(row)).join("\n") + "\n");
|
|
81
|
+
const options = {
|
|
82
|
+
[`${kind}Queue`]: queue,
|
|
83
|
+
rowsFile: request.rows,
|
|
84
|
+
outDir,
|
|
85
|
+
schemaFile: request.contract.schema,
|
|
86
|
+
yamlFile: request.contract.methodology,
|
|
87
|
+
rulesetFile: request.contract.ruleset,
|
|
88
|
+
classificationSchema: schemas.filter((file) => !file.endsWith("tidas_locations_category.json")),
|
|
89
|
+
locationSchema: path.join(cli.schemaDir, "tidas_locations_category.json"),
|
|
90
|
+
};
|
|
91
|
+
const built = owners.invoke(() => kind === "classification"
|
|
92
|
+
? owners.classification.runDatasetClassificationDecisionTaskBuild(options)
|
|
93
|
+
: owners.location.runDatasetLocationDecisionTaskBuild(options));
|
|
94
|
+
const task = workflowObject(built), files = workflowObject(task.files);
|
|
95
|
+
result.push({
|
|
96
|
+
kind,
|
|
97
|
+
type: request.type,
|
|
98
|
+
rows: request.rows,
|
|
99
|
+
task: path.resolve(context.assetRoot, String(files.task)),
|
|
100
|
+
queue: path.resolve(context.assetRoot, String(task[`${kind}_queue`])),
|
|
101
|
+
status: String(task.status),
|
|
102
|
+
blockers: Array.isArray(task.blockers) ? task.blockers : [],
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (needsIdentity) {
|
|
106
|
+
const task = workflowObject(owners.invoke(() => owners.identityTask.runDatasetIdentityDecisionTaskBuild({
|
|
107
|
+
curationGateReport: request.gateReport,
|
|
108
|
+
rowsFile: request.rows,
|
|
109
|
+
outDir: path.join(request.outDir, "identity"),
|
|
110
|
+
})));
|
|
111
|
+
const files = workflowObject(task.files);
|
|
112
|
+
result.push({
|
|
113
|
+
kind: "identity",
|
|
114
|
+
type: request.type,
|
|
115
|
+
rows: request.rows,
|
|
116
|
+
task: path.resolve(context.assetRoot, String(files.task)),
|
|
117
|
+
queue: null,
|
|
118
|
+
status: String(task.status),
|
|
119
|
+
blockers: Array.isArray(task.blockers) ? task.blockers : [],
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 readOwnerExecutionRequests } from "./foundry-owner-execution-store.ts";
|
|
5
|
+
import type { ArtifactEntry } from "./foundry-task-types.ts";
|
|
6
|
+
type RequestArtifact = ReturnType<typeof readOwnerExecutionRequests>[number];
|
|
7
|
+
export declare function executeFoundryOwnerScope(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, entries: readonly ArtifactEntry[], requested: RequestArtifact, authentication?: FoundryAuthentication): Promise<import("./foundry-task-types.ts").JsonRecord>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,248 @@
|
|
|
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 { runBoundedBatch, withBatchRunLock } from "@tiangong-lca/cli/batch";
|
|
6
|
+
import { commandSpecOptionValue } from "@tiangong-lca/cli/command-spec";
|
|
7
|
+
import { captureFoundryInput, FoundryContextError, resolveFoundryOutput, writeFoundryArtifact, } from "./foundry-runtime-context.js";
|
|
8
|
+
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
9
|
+
import { verifyFoundryRuntimeIdentity, } from "./foundry-runtime-identity.js";
|
|
10
|
+
import { rehydrateFoundryExecutionAdmission, assertFoundryExecutionAdmission, } from "./foundry-execution-admission.js";
|
|
11
|
+
import { createFoundryAuthenticationEnvironment } from "./foundry-authentication-environment.js";
|
|
12
|
+
import { createFoundryFinalizeOwners } from "./foundry-finalize-owners.js";
|
|
13
|
+
import { inspectOwnerExecutions, ownerAttemptStore, markOwnerAttemptConsumed, } from "./foundry-owner-execution-store.js";
|
|
14
|
+
import { readbackFoundryOwner } from "./foundry-owner-readback.js";
|
|
15
|
+
import { runFoundryTaskOperation, withFoundryTaskMetadata } from "./foundry-task-store.js";
|
|
16
|
+
import { registerWorkflowStageFiles } from "./foundry-workflow-io.js";
|
|
17
|
+
import { workflowObject } from "./foundry-workflow-state.js";
|
|
18
|
+
import { canonicalPayloadSha256 } from "./post-write-root-proof.js";
|
|
19
|
+
import { summarizeSameIdentityCommitFailures } from "./same-identity-commit-recovery.js";
|
|
20
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
21
|
+
export async function executeFoundryOwnerScope(context, qualified, entries, requested, authentication = { mode: "oauth" }) {
|
|
22
|
+
const request = requested.request;
|
|
23
|
+
if (!entries.some((entry) => entry.path === requested.entry.path && entry.sha256 === requested.entry.sha256))
|
|
24
|
+
throw new FoundryContextError("execution_request_unregistered", "Select a registered owner execution request.");
|
|
25
|
+
const lock = resolveFoundryOutput(context, `owner-locks/${context.taskId}-${request.scope_id}.json`, "state");
|
|
26
|
+
return withBatchRunLock({
|
|
27
|
+
runPath: lock,
|
|
28
|
+
identity: { task: context.taskId, scope: request.scope_id },
|
|
29
|
+
reason: "Foundry owner execution and readback",
|
|
30
|
+
}, async () => {
|
|
31
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
32
|
+
const inspected = await withFoundryTaskMetadata(context, (_, index) => inspectOwnerExecutions(context, index));
|
|
33
|
+
const consumed = inspected.consumed.get(request.scope_id);
|
|
34
|
+
if (consumed && consumed.entry.sha256 !== requested.entry.sha256)
|
|
35
|
+
throw new FoundryContextError("execution_request_changed", "A consumed scope must recover its original request.");
|
|
36
|
+
if (inspected.verified.has(request.scope_id))
|
|
37
|
+
return inspected.verified.get(request.scope_id).value;
|
|
38
|
+
const observationDir = resolveFoundryOutput(context, `outputs/owner-dispatch/${requested.entry.sha256}`);
|
|
39
|
+
const observationFile = path.join(observationDir, "dispatch-observation.json");
|
|
40
|
+
let observationRegistered = entries.some((entry) => path.resolve(context.taskRoot, entry.path) === observationFile);
|
|
41
|
+
let observation = fs.existsSync(observationFile)
|
|
42
|
+
? workflowObject(JSON.parse(fs.readFileSync(observationFile, "utf8")))
|
|
43
|
+
: null;
|
|
44
|
+
if (observation && observation.request_sha256 !== requested.entry.sha256)
|
|
45
|
+
throw new FoundryContextError("execution_observation_invalid", "Dispatch observation belongs to another request.");
|
|
46
|
+
let identity = null;
|
|
47
|
+
let admission = null;
|
|
48
|
+
if (!consumed) {
|
|
49
|
+
identity = verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
50
|
+
admission = await rehydrateFoundryExecutionAdmission(context, qualified, identity, {
|
|
51
|
+
capsuleFile: request.content.capsule.path,
|
|
52
|
+
commandSpec: request.content.commit,
|
|
53
|
+
});
|
|
54
|
+
await assertFoundryExecutionAdmission(context, qualified, identity, admission);
|
|
55
|
+
if (observation)
|
|
56
|
+
throw new FoundryContextError("execution_observation_invalid", "Existing dispatch evidence cannot be treated as unattempted.");
|
|
57
|
+
const out = commandSpecOptionValue(request.content.commit, "--out-dir");
|
|
58
|
+
resolveFoundryOutput(context, out);
|
|
59
|
+
if (fs.existsSync(out) && fs.readdirSync(out).length)
|
|
60
|
+
throw new FoundryContextError("execution_output_not_empty", "An unattempted command cannot adopt existing output artifacts.");
|
|
61
|
+
}
|
|
62
|
+
const attemptStore = ownerAttemptStore(context, request.scope_id, {
|
|
63
|
+
path: requested.file,
|
|
64
|
+
sha256: requested.entry.sha256,
|
|
65
|
+
});
|
|
66
|
+
let lastRead = null;
|
|
67
|
+
const readResult = () => lastRead;
|
|
68
|
+
const readback = async () => {
|
|
69
|
+
if (observation?.disposition === "failed")
|
|
70
|
+
return null;
|
|
71
|
+
const commitReport = observation?.disposition === "confirmed" && observation.report
|
|
72
|
+
? String(workflowObject(observation.report).path)
|
|
73
|
+
: undefined;
|
|
74
|
+
lastRead = await readbackFoundryOwner(context, qualified, request, authentication, commitReport);
|
|
75
|
+
return lastRead.proof.status === "verified" ? lastRead : null;
|
|
76
|
+
};
|
|
77
|
+
const batch = await runBoundedBatch({
|
|
78
|
+
contract: request.contract,
|
|
79
|
+
items: [request],
|
|
80
|
+
getItemIdentity: (item) => item.scope_id,
|
|
81
|
+
projectItemContent: (item) => JSON.parse(JSON.stringify(item.content)),
|
|
82
|
+
projectItemPolicy: (item) => item.policy,
|
|
83
|
+
mode: "mutation",
|
|
84
|
+
maxConcurrency: 1,
|
|
85
|
+
...(consumed
|
|
86
|
+
? {
|
|
87
|
+
resume: {
|
|
88
|
+
contract: request.contract,
|
|
89
|
+
items: [{ ...request.item_contract, state: "attempted", attempts: 1 }],
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
: {}),
|
|
93
|
+
eventSink: async (event) => {
|
|
94
|
+
if (event.type === "attempt_started")
|
|
95
|
+
await markOwnerAttemptConsumed(context, requested);
|
|
96
|
+
attemptStore.record(event, request.item_contract);
|
|
97
|
+
},
|
|
98
|
+
execute: async () => {
|
|
99
|
+
if (!identity || !admission)
|
|
100
|
+
throw new FoundryContextError("execution_admission_required", "Mutation requires fresh process-local admission.");
|
|
101
|
+
const command = request.content.commit;
|
|
102
|
+
const environment = createFoundryAuthenticationEnvironment(authentication, context.accountIntent?.sessionReference, process.env);
|
|
103
|
+
environment.FOUNDRY_VERIFIED_PROJECT_REF = request.policy.project_ref;
|
|
104
|
+
environment.FOUNDRY_VERIFIED_USER_ID = request.policy.user_id;
|
|
105
|
+
environment.FOUNDRY_ACCOUNT_MODE = request.policy.account_mode;
|
|
106
|
+
fs.mkdirSync(observationDir, { recursive: true, mode: 0o700 });
|
|
107
|
+
const commitOutput = commandSpecOptionValue(command, "--out-dir");
|
|
108
|
+
resolveFoundryOutput(context, commitOutput);
|
|
109
|
+
let result;
|
|
110
|
+
try {
|
|
111
|
+
result = spawnSync(command.executable, [...command.argv], {
|
|
112
|
+
cwd: observationDir,
|
|
113
|
+
env: environment,
|
|
114
|
+
shell: false,
|
|
115
|
+
windowsHide: true,
|
|
116
|
+
encoding: "utf8",
|
|
117
|
+
timeout: 120_000,
|
|
118
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
delete environment.TIANGONG_LCA_ACCESS_TOKEN;
|
|
123
|
+
}
|
|
124
|
+
writeFoundryArtifact(context, path.join(observationDir, "stdout.json"), result.stdout ?? "");
|
|
125
|
+
writeFoundryArtifact(context, path.join(observationDir, "stderr.log"), result.stderr ?? "");
|
|
126
|
+
let report = null, reportFile = null;
|
|
127
|
+
try {
|
|
128
|
+
report = workflowObject(JSON.parse(result.stdout));
|
|
129
|
+
const files = workflowObject(report.files);
|
|
130
|
+
const candidate = files.report ?? files.summary_json;
|
|
131
|
+
if (typeof candidate === "string") {
|
|
132
|
+
const file = resolveFoundryOutput(context, candidate);
|
|
133
|
+
if (path.relative(commitOutput, file).startsWith(".."))
|
|
134
|
+
throw new Error("Commit report is outside its output root.");
|
|
135
|
+
if (canonicalPayloadSha256(JSON.parse(fs.readFileSync(file, "utf8"))) !==
|
|
136
|
+
canonicalPayloadSha256(report))
|
|
137
|
+
throw new Error("Commit stdout/report mismatch.");
|
|
138
|
+
reportFile = file;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
report = null;
|
|
143
|
+
reportFile = null;
|
|
144
|
+
}
|
|
145
|
+
const commitBlockers = [];
|
|
146
|
+
if (report && reportFile) {
|
|
147
|
+
createFoundryFinalizeOwners(context, qualified, observationDir, {
|
|
148
|
+
environment: {},
|
|
149
|
+
tidasExecutable: qualified.tidas.executable_path,
|
|
150
|
+
}).closeout.validateCommitReportForCloseout({
|
|
151
|
+
commitReport: report,
|
|
152
|
+
commitReportPath: reportFile,
|
|
153
|
+
datasetType: request.policy.dataset_type,
|
|
154
|
+
finalRowsFile: request.content.input.path,
|
|
155
|
+
expectedRows: readRows(request.content.input.path).length,
|
|
156
|
+
blockers: commitBlockers,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const disposition = result.error || result.signal || !report || !reportFile
|
|
160
|
+
? "unknown"
|
|
161
|
+
: result.status === 0 && !commitBlockers.length
|
|
162
|
+
? "confirmed"
|
|
163
|
+
: summarizeSameIdentityCommitFailures([report]).accepted
|
|
164
|
+
? "same_identity_conflict"
|
|
165
|
+
: "failed";
|
|
166
|
+
observation = {
|
|
167
|
+
schema: "tiangong-foundry.dispatch-observation.v1",
|
|
168
|
+
request_sha256: requested.entry.sha256,
|
|
169
|
+
disposition,
|
|
170
|
+
exit_code: result.status,
|
|
171
|
+
signal: result.signal,
|
|
172
|
+
report: reportFile ? captureFoundryInput(reportFile) : null,
|
|
173
|
+
blockers: commitBlockers,
|
|
174
|
+
};
|
|
175
|
+
writeFoundryArtifact(context, observationFile, JSON.stringify(observation, null, 2) + "\n");
|
|
176
|
+
await runFoundryTaskOperation(context, {
|
|
177
|
+
command: "dataset-workflow-execution-observation",
|
|
178
|
+
options: { request: requested.entry.sha256 },
|
|
179
|
+
}, (operation) => {
|
|
180
|
+
registerWorkflowStageFiles(context, operation, observationDir);
|
|
181
|
+
if (fs.existsSync(commitOutput))
|
|
182
|
+
registerWorkflowStageFiles(context, operation, commitOutput);
|
|
183
|
+
operation.writeJson(observationFile, observation);
|
|
184
|
+
return observation;
|
|
185
|
+
});
|
|
186
|
+
observationRegistered = true;
|
|
187
|
+
if (disposition !== "confirmed")
|
|
188
|
+
throw new Error("Owner dispatch requires retained-state recovery.");
|
|
189
|
+
const verified = await readback();
|
|
190
|
+
if (!verified)
|
|
191
|
+
throw new Error("Owner write is not independently verified.");
|
|
192
|
+
return verified.proof;
|
|
193
|
+
},
|
|
194
|
+
recoverMutation: async () => {
|
|
195
|
+
const verified = lastRead
|
|
196
|
+
? lastRead.proof.status === "verified"
|
|
197
|
+
? lastRead
|
|
198
|
+
: null
|
|
199
|
+
: await readback();
|
|
200
|
+
return verified
|
|
201
|
+
? { status: "recovered", value: verified.proof }
|
|
202
|
+
: { status: "unresolved" };
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
const item = batch.results_input_order[0];
|
|
206
|
+
const successful = item?.status === "succeeded" || item?.status === "recovered";
|
|
207
|
+
const read = readResult();
|
|
208
|
+
const output = resolveFoundryOutput(context, `outputs/owner-results/${randomUUID()}`);
|
|
209
|
+
return runFoundryTaskOperation(context, {
|
|
210
|
+
command: "dataset-workflow-execution-result",
|
|
211
|
+
options: { request: requested.entry.sha256, nonce: path.basename(output) },
|
|
212
|
+
}, (operation) => {
|
|
213
|
+
if (!observationRegistered) {
|
|
214
|
+
if (fs.existsSync(observationDir))
|
|
215
|
+
registerWorkflowStageFiles(context, operation, observationDir);
|
|
216
|
+
const commitDir = commandSpecOptionValue(request.content.commit, "--out-dir");
|
|
217
|
+
if (commitDir && fs.existsSync(commitDir))
|
|
218
|
+
registerWorkflowStageFiles(context, operation, commitDir);
|
|
219
|
+
}
|
|
220
|
+
if (read)
|
|
221
|
+
registerWorkflowStageFiles(context, operation, read.output);
|
|
222
|
+
const result = {
|
|
223
|
+
schema: "tiangong-foundry.owner-execution-result.v1",
|
|
224
|
+
status: successful
|
|
225
|
+
? item.status === "recovered"
|
|
226
|
+
? "recovered"
|
|
227
|
+
: "verified"
|
|
228
|
+
: "unresolved",
|
|
229
|
+
request_sha256: requested.entry.sha256,
|
|
230
|
+
scope_id: request.scope_id,
|
|
231
|
+
dataset_type: request.policy.dataset_type,
|
|
232
|
+
input: request.content.input,
|
|
233
|
+
attempt_consumed: item?.attempt_consumed ?? Boolean(consumed),
|
|
234
|
+
observation,
|
|
235
|
+
readback: read?.proof ?? null,
|
|
236
|
+
batch_item_status: item?.status ?? "missing",
|
|
237
|
+
failure_code: item?.status === "failed"
|
|
238
|
+
? item.error instanceof FoundryContextError
|
|
239
|
+
? item.error.code
|
|
240
|
+
: "owner_execution_unresolved"
|
|
241
|
+
: null,
|
|
242
|
+
batch_status: batch.status,
|
|
243
|
+
};
|
|
244
|
+
operation.writeJson(path.join(output, "owner-execution-result.json"), result);
|
|
245
|
+
return result;
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 finalizeFoundryWorkflow(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, entries: readonly ArtifactEntry[], authentication?: FoundryAuthentication, approval?: {
|
|
6
|
+
sourceSha256: string;
|
|
7
|
+
authorizationSha256: string;
|
|
8
|
+
datasetType: string;
|
|
9
|
+
inputFile: string;
|
|
10
|
+
}, executionProgress?: {
|
|
11
|
+
sha256: string;
|
|
12
|
+
scopes: ReadonlyMap<string, Record<string, unknown>>;
|
|
13
|
+
}): Promise<import("./foundry-task-types.ts").JsonRecord>;
|