@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,466 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { withBatchRunLock } from "@tiangong-lca/cli/batch";
|
|
5
|
+
import { captureFoundryInput, resolveFoundryInputPath, resolveFoundryOutput, writeFoundryArtifact, assertFoundryWorkspaceWrite, } from "./foundry-runtime-context.js";
|
|
6
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
7
|
+
import { fail, object, exact, timestamp, bytes, digest, taskPath, relative, readTaskBytes, readTaskJson, reference, facts, sameFact, shaPattern, maxIndexBytes, } from "./foundry-task-io.js";
|
|
8
|
+
import { requiredTask, createTask, loadTask, bindAccountIntent, } from "./foundry-task-registration.js";
|
|
9
|
+
export async function withFoundryTaskMetadata(context, inspect, options = {}) {
|
|
10
|
+
requiredTask(context);
|
|
11
|
+
const inspectCurrent = () => {
|
|
12
|
+
const task = loadTask(context, {});
|
|
13
|
+
bindAccountIntent(context);
|
|
14
|
+
const index = readIndex(context);
|
|
15
|
+
const extra = index
|
|
16
|
+
.filter((entry) => options.verifyCommands?.includes(entry.command))
|
|
17
|
+
.map((entry) => ({
|
|
18
|
+
path: taskPath(context, entry.path),
|
|
19
|
+
bytes: entry.bytes,
|
|
20
|
+
sha256: entry.sha256,
|
|
21
|
+
}));
|
|
22
|
+
verifyInputs(context, task, index, [...context.inputs, ...extra]);
|
|
23
|
+
return inspect(task, index);
|
|
24
|
+
};
|
|
25
|
+
if (context.workspaceAccess === "read")
|
|
26
|
+
return inspectCurrent();
|
|
27
|
+
const runPath = resolveFoundryOutput(context, `task-locks/${context.taskId}.json`, "state");
|
|
28
|
+
return withBatchRunLock({
|
|
29
|
+
runPath,
|
|
30
|
+
identity: {
|
|
31
|
+
schema: "foundry-task-store-lock.v1",
|
|
32
|
+
workspace_id: context.workspaceId,
|
|
33
|
+
task_id: context.taskId,
|
|
34
|
+
},
|
|
35
|
+
reason: "Foundry task metadata verification",
|
|
36
|
+
}, inspectCurrent);
|
|
37
|
+
}
|
|
38
|
+
function selectedInput(context, file) {
|
|
39
|
+
const resolved = resolveFoundryInputPath(context, file);
|
|
40
|
+
return context.inputs.find((fact) => fact.path === resolved);
|
|
41
|
+
}
|
|
42
|
+
function producerLookup(context, index) {
|
|
43
|
+
const key = (fact) => JSON.stringify([fact.path, fact.sha256, fact.bytes]);
|
|
44
|
+
const byFact = new Map();
|
|
45
|
+
for (const entry of index) {
|
|
46
|
+
const id = key({
|
|
47
|
+
path: taskPath(context, entry.path),
|
|
48
|
+
sha256: entry.sha256,
|
|
49
|
+
bytes: entry.bytes,
|
|
50
|
+
});
|
|
51
|
+
const candidates = byFact.get(id) ?? [];
|
|
52
|
+
candidates.push(entry);
|
|
53
|
+
byFact.set(id, candidates);
|
|
54
|
+
}
|
|
55
|
+
return (fact, before = Number.POSITIVE_INFINITY) => (byFact.get(key(fact)) ?? []).filter((entry) => entry.sequence < before);
|
|
56
|
+
}
|
|
57
|
+
/** Prove a selected derived input descends from a selected approved input in the same verified index. */
|
|
58
|
+
export async function assertFoundryTaskInputLineage(context, ancestorFile, derivedFile) {
|
|
59
|
+
const ancestor = selectedInput(context, ancestorFile);
|
|
60
|
+
const derived = selectedInput(context, derivedFile);
|
|
61
|
+
if (sameFact(ancestor, derived))
|
|
62
|
+
fail("task_lineage_not_derived", "A derived authorization requires a distinct indexed output.");
|
|
63
|
+
return withFoundryTaskMetadata(context, (task, index) => {
|
|
64
|
+
const findProducers = producerLookup(context, index);
|
|
65
|
+
const first = findProducers(derived);
|
|
66
|
+
if (!first.length)
|
|
67
|
+
fail("task_lineage_invalid", "Derived input has no indexed producer.");
|
|
68
|
+
const pending = [...first];
|
|
69
|
+
const visited = new Set();
|
|
70
|
+
while (pending.length) {
|
|
71
|
+
const entry = pending.pop();
|
|
72
|
+
if (visited.has(entry.record_sha256))
|
|
73
|
+
continue;
|
|
74
|
+
visited.add(entry.record_sha256);
|
|
75
|
+
const receiptBytes = readTaskBytes(context, entry.receipt.path);
|
|
76
|
+
if (digest(receiptBytes) !== entry.receipt.sha256)
|
|
77
|
+
fail("task_lineage_invalid", "Derived input producer receipt changed.");
|
|
78
|
+
const receipt = object(JSON.parse(receiptBytes.toString("utf8")));
|
|
79
|
+
exact(receipt, ["schema", "mode", "status", "plan", "job_sha256", "outputs", "result"]);
|
|
80
|
+
const outputs = facts(receipt.outputs);
|
|
81
|
+
if (receipt.schema !== "tiangong-foundry.operation-receipt.v1" ||
|
|
82
|
+
receipt.mode !== "deterministic-local" ||
|
|
83
|
+
receipt.status !== "completed" ||
|
|
84
|
+
receipt.job_sha256 !== task.jobSha256 ||
|
|
85
|
+
!outputs.some((output) => output.path === entry.path &&
|
|
86
|
+
output.bytes === entry.bytes &&
|
|
87
|
+
output.sha256 === entry.sha256))
|
|
88
|
+
fail("task_lineage_invalid", "Derived input has no valid same-task producer receipt.");
|
|
89
|
+
const planRef = reference(receipt.plan);
|
|
90
|
+
const planBytes = readTaskBytes(context, planRef.path);
|
|
91
|
+
if (digest(planBytes) !== planRef.sha256)
|
|
92
|
+
fail("task_lineage_invalid", "Derived input producer plan changed.");
|
|
93
|
+
const plan = object(JSON.parse(planBytes.toString("utf8")));
|
|
94
|
+
exact(plan, [
|
|
95
|
+
"schema",
|
|
96
|
+
"operation_id",
|
|
97
|
+
"job_sha256",
|
|
98
|
+
"command",
|
|
99
|
+
"options_sha256",
|
|
100
|
+
"input_scope_sha256",
|
|
101
|
+
"inputs",
|
|
102
|
+
"created_at_utc",
|
|
103
|
+
]);
|
|
104
|
+
const parents = facts(plan.inputs);
|
|
105
|
+
const computedOperation = sha256Json({
|
|
106
|
+
job: task.jobSha256,
|
|
107
|
+
command: plan.command,
|
|
108
|
+
input_scope: sha256Json(parents),
|
|
109
|
+
options: plan.options_sha256,
|
|
110
|
+
});
|
|
111
|
+
if (plan.schema !== "tiangong-foundry.operation-plan.v1" ||
|
|
112
|
+
plan.operation_id !== entry.operation_id ||
|
|
113
|
+
computedOperation !== entry.operation_id ||
|
|
114
|
+
plan.job_sha256 !== task.jobSha256 ||
|
|
115
|
+
plan.command !== entry.command ||
|
|
116
|
+
plan.input_scope_sha256 !== entry.input_scope_sha256 ||
|
|
117
|
+
sha256Json(parents) !== entry.input_scope_sha256 ||
|
|
118
|
+
!timestamp(plan.created_at_utc))
|
|
119
|
+
fail("task_lineage_invalid", "Derived input producer binding changed.");
|
|
120
|
+
for (const parent of parents) {
|
|
121
|
+
if (sameFact(parent, ancestor))
|
|
122
|
+
return Object.freeze({ ancestor, derived });
|
|
123
|
+
pending.push(...findProducers(parent, entry.sequence));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return fail("task_lineage_scope_mismatch", "Derived input is valid task output but does not descend from the approved input scope.");
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function readIndex(context) {
|
|
130
|
+
const content = readTaskBytes(context, "artifact-index.jsonl", maxIndexBytes).toString("utf8");
|
|
131
|
+
if (content && !content.endsWith("\n"))
|
|
132
|
+
fail("task_index_incomplete", "Artifact index is truncated; do not infer missing entries as permission.");
|
|
133
|
+
let previous = null;
|
|
134
|
+
return content
|
|
135
|
+
.split("\n")
|
|
136
|
+
.filter(Boolean)
|
|
137
|
+
.map((line, index) => {
|
|
138
|
+
let entry;
|
|
139
|
+
try {
|
|
140
|
+
entry = object(JSON.parse(line));
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
fail("task_index_invalid", "Artifact index contains incomplete JSON.");
|
|
144
|
+
}
|
|
145
|
+
exact(entry, [
|
|
146
|
+
"schema",
|
|
147
|
+
"sequence",
|
|
148
|
+
"previous_sha256",
|
|
149
|
+
"operation_id",
|
|
150
|
+
"command",
|
|
151
|
+
"input_scope_sha256",
|
|
152
|
+
"receipt",
|
|
153
|
+
"path",
|
|
154
|
+
"bytes",
|
|
155
|
+
"sha256",
|
|
156
|
+
"record_sha256",
|
|
157
|
+
]);
|
|
158
|
+
const { record_sha256: recorded, ...unsigned } = entry;
|
|
159
|
+
if (entry.schema !== "tiangong-foundry.artifact-index.v2" ||
|
|
160
|
+
entry.sequence !== index + 1 ||
|
|
161
|
+
entry.previous_sha256 !== previous ||
|
|
162
|
+
recorded !== sha256Json(unsigned) ||
|
|
163
|
+
typeof entry.operation_id !== "string" ||
|
|
164
|
+
!shaPattern.test(entry.operation_id) ||
|
|
165
|
+
typeof entry.command !== "string" ||
|
|
166
|
+
typeof entry.input_scope_sha256 !== "string" ||
|
|
167
|
+
!shaPattern.test(entry.input_scope_sha256))
|
|
168
|
+
fail("task_index_invalid", "Artifact index sequence or content binding changed.");
|
|
169
|
+
const fact = facts([{ path: entry.path, bytes: entry.bytes, sha256: entry.sha256 }])[0];
|
|
170
|
+
if (path.isAbsolute(fact.path) ||
|
|
171
|
+
fact.path.includes("\\") ||
|
|
172
|
+
fact.path.split("/").some((part) => part === ".." || part === "." || !part))
|
|
173
|
+
fail("task_index_invalid", "Artifact index paths must be task-relative.");
|
|
174
|
+
taskPath(context, fact.path);
|
|
175
|
+
reference(entry.receipt);
|
|
176
|
+
previous = recorded;
|
|
177
|
+
return entry;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function verifyRecordedArtifact(context, fact) {
|
|
181
|
+
const actual = captureFoundryInput(taskPath(context, fact.path));
|
|
182
|
+
if (actual.bytes !== fact.bytes || actual.sha256 !== fact.sha256)
|
|
183
|
+
fail("task_artifact_changed", "Recorded artifact bytes no longer match their producer evidence.");
|
|
184
|
+
}
|
|
185
|
+
function verifyInputs(context, task, index, inputs = context.inputs) {
|
|
186
|
+
for (const source of task.sources) {
|
|
187
|
+
try {
|
|
188
|
+
if (sameFact(captureFoundryInput(source.path), source))
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
/* No unavailable source becomes fresh scope. */
|
|
193
|
+
}
|
|
194
|
+
fail("task_source_changed", "Original source is missing or changed; restore its frozen snapshot or create an explicit revision.");
|
|
195
|
+
}
|
|
196
|
+
const verified = new Set();
|
|
197
|
+
const producers = producerLookup(context, index);
|
|
198
|
+
const findProducer = (fact, before = Number.POSITIVE_INFINITY) => producers(fact, before)[0];
|
|
199
|
+
for (const fact of inputs) {
|
|
200
|
+
if (!task.sources.some((source) => sameFact(source, fact))) {
|
|
201
|
+
const first = findProducer(fact);
|
|
202
|
+
if (!first)
|
|
203
|
+
fail("task_input_unrecognized", "Input is neither frozen source nor an indexed derived artifact; a new scope requires explicit revision.");
|
|
204
|
+
const pending = [first];
|
|
205
|
+
while (pending.length) {
|
|
206
|
+
const entry = pending.pop();
|
|
207
|
+
if (verified.has(entry.record_sha256))
|
|
208
|
+
continue;
|
|
209
|
+
const receiptBytes = readTaskBytes(context, entry.receipt.path);
|
|
210
|
+
if (digest(receiptBytes) !== entry.receipt.sha256)
|
|
211
|
+
fail("task_lineage_invalid", "Derived input producer receipt changed.");
|
|
212
|
+
const receipt = object(JSON.parse(receiptBytes.toString("utf8")));
|
|
213
|
+
exact(receipt, ["schema", "mode", "status", "plan", "job_sha256", "outputs", "result"]);
|
|
214
|
+
if (receipt.schema !== "tiangong-foundry.operation-receipt.v1" ||
|
|
215
|
+
receipt.mode !== "deterministic-local" ||
|
|
216
|
+
receipt.status !== "completed" ||
|
|
217
|
+
receipt.job_sha256 !== task.jobSha256)
|
|
218
|
+
fail("task_lineage_invalid", "Derived input has no completed producer in the same task.");
|
|
219
|
+
const outputs = facts(receipt.outputs);
|
|
220
|
+
if (!outputs.some((output) => output.path === entry.path &&
|
|
221
|
+
output.bytes === entry.bytes &&
|
|
222
|
+
output.sha256 === entry.sha256))
|
|
223
|
+
fail("task_lineage_invalid", "Derived input is outside its producer output scope.");
|
|
224
|
+
const planRef = reference(receipt.plan);
|
|
225
|
+
const planBytes = readTaskBytes(context, planRef.path);
|
|
226
|
+
if (digest(planBytes) !== planRef.sha256)
|
|
227
|
+
fail("task_lineage_invalid", "Producer input plan changed.");
|
|
228
|
+
const plan = object(JSON.parse(planBytes.toString("utf8")));
|
|
229
|
+
exact(plan, [
|
|
230
|
+
"schema",
|
|
231
|
+
"operation_id",
|
|
232
|
+
"job_sha256",
|
|
233
|
+
"command",
|
|
234
|
+
"options_sha256",
|
|
235
|
+
"input_scope_sha256",
|
|
236
|
+
"inputs",
|
|
237
|
+
"created_at_utc",
|
|
238
|
+
]);
|
|
239
|
+
const parents = facts(plan.inputs);
|
|
240
|
+
const computedOperation = sha256Json({
|
|
241
|
+
job: task.jobSha256,
|
|
242
|
+
command: plan.command,
|
|
243
|
+
input_scope: sha256Json(parents),
|
|
244
|
+
options: plan.options_sha256,
|
|
245
|
+
});
|
|
246
|
+
if (plan.schema !== "tiangong-foundry.operation-plan.v1" ||
|
|
247
|
+
plan.operation_id !== entry.operation_id ||
|
|
248
|
+
computedOperation !== entry.operation_id ||
|
|
249
|
+
plan.job_sha256 !== task.jobSha256 ||
|
|
250
|
+
plan.command !== entry.command ||
|
|
251
|
+
plan.input_scope_sha256 !== entry.input_scope_sha256 ||
|
|
252
|
+
sha256Json(parents) !== entry.input_scope_sha256 ||
|
|
253
|
+
!timestamp(plan.created_at_utc))
|
|
254
|
+
fail("task_lineage_invalid", "Producer binding does not match the artifact index.");
|
|
255
|
+
for (const parent of parents) {
|
|
256
|
+
if (task.sources.some((source) => sameFact(source, parent)))
|
|
257
|
+
continue;
|
|
258
|
+
const earlier = findProducer(parent, entry.sequence);
|
|
259
|
+
if (!earlier)
|
|
260
|
+
fail("task_lineage_invalid", "Producer input has no earlier source-bound artifact.");
|
|
261
|
+
pending.push(earlier);
|
|
262
|
+
}
|
|
263
|
+
verified.add(entry.record_sha256);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (!sameFact(captureFoundryInput(fact.path), fact))
|
|
267
|
+
fail("input_changed", "Current operation input changed after selection.");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function replaceIndex(context, entries, before) {
|
|
271
|
+
const target = taskPath(context, "artifact-index.jsonl");
|
|
272
|
+
const content = Buffer.from(entries.map((entry) => JSON.stringify(entry)).join("\n") + (entries.length ? "\n" : ""));
|
|
273
|
+
if (content.length > maxIndexBytes)
|
|
274
|
+
fail("task_index_limit", "Artifact index exceeds the bounded metadata store.");
|
|
275
|
+
const temp = taskPath(context, `.artifact-index-${randomUUID()}.tmp`);
|
|
276
|
+
const fd = fs.openSync(temp, "wx", 0o600);
|
|
277
|
+
try {
|
|
278
|
+
fs.writeFileSync(fd, content);
|
|
279
|
+
fs.fsyncSync(fd);
|
|
280
|
+
}
|
|
281
|
+
finally {
|
|
282
|
+
fs.closeSync(fd);
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
if (!readTaskBytes(context, target, maxIndexBytes).equals(before))
|
|
286
|
+
fail("task_index_conflict", "Artifact index changed outside the task lock.");
|
|
287
|
+
fs.renameSync(temp, target);
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
if (fs.existsSync(temp))
|
|
291
|
+
fs.unlinkSync(temp);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/** Short local preparation transaction. Remote mutation/batch execution must not use this replay path. */
|
|
295
|
+
export async function runFoundryTaskOperation(context, input, operation) {
|
|
296
|
+
assertFoundryWorkspaceWrite(context);
|
|
297
|
+
requiredTask(context);
|
|
298
|
+
const lockPath = resolveFoundryOutput(context, `task-locks/${context.taskId}.json`, "state");
|
|
299
|
+
return withBatchRunLock({
|
|
300
|
+
runPath: lockPath,
|
|
301
|
+
identity: {
|
|
302
|
+
schema: "foundry-task-store-lock.v1",
|
|
303
|
+
workspace_id: context.workspaceId,
|
|
304
|
+
task_id: context.taskId,
|
|
305
|
+
},
|
|
306
|
+
reason: "Foundry local task preparation",
|
|
307
|
+
}, () => {
|
|
308
|
+
requiredTask(context);
|
|
309
|
+
const task = fs.existsSync(taskPath(context, "foundry-job.json"))
|
|
310
|
+
? loadTask(context, input.task ?? {})
|
|
311
|
+
: createTask(context, input.task ?? {});
|
|
312
|
+
bindAccountIntent(context);
|
|
313
|
+
const indexBefore = readTaskBytes(context, "artifact-index.jsonl", maxIndexBytes);
|
|
314
|
+
const index = readIndex(context);
|
|
315
|
+
verifyInputs(context, task, index);
|
|
316
|
+
input.validateCurrent?.(Object.freeze(index.map((entry) => Object.freeze({ ...entry, receipt: Object.freeze({ ...entry.receipt }) }))));
|
|
317
|
+
const inputScopeSha256 = sha256Json(context.inputs);
|
|
318
|
+
const optionsSha256 = sha256Json(input.options);
|
|
319
|
+
const operationId = sha256Json({
|
|
320
|
+
job: task.jobSha256,
|
|
321
|
+
command: input.command,
|
|
322
|
+
input_scope: inputScopeSha256,
|
|
323
|
+
options: optionsSha256,
|
|
324
|
+
});
|
|
325
|
+
const planPath = `checkpoints/${operationId}.plan.json`;
|
|
326
|
+
const receiptPath = `checkpoints/${operationId}.json`;
|
|
327
|
+
let plan;
|
|
328
|
+
if (fs.existsSync(taskPath(context, planPath))) {
|
|
329
|
+
const old = readTaskJson(context, planPath);
|
|
330
|
+
exact(old, [
|
|
331
|
+
"schema",
|
|
332
|
+
"operation_id",
|
|
333
|
+
"job_sha256",
|
|
334
|
+
"command",
|
|
335
|
+
"options_sha256",
|
|
336
|
+
"input_scope_sha256",
|
|
337
|
+
"inputs",
|
|
338
|
+
"created_at_utc",
|
|
339
|
+
]);
|
|
340
|
+
if (old.schema !== "tiangong-foundry.operation-plan.v1" ||
|
|
341
|
+
old.operation_id !== operationId ||
|
|
342
|
+
old.job_sha256 !== task.jobSha256 ||
|
|
343
|
+
old.command !== input.command ||
|
|
344
|
+
old.options_sha256 !== optionsSha256 ||
|
|
345
|
+
old.input_scope_sha256 !== inputScopeSha256 ||
|
|
346
|
+
sha256Json(old.inputs) !== inputScopeSha256 ||
|
|
347
|
+
!timestamp(old.created_at_utc))
|
|
348
|
+
fail("task_operation_changed", "Existing operation plan does not match current inputs.");
|
|
349
|
+
plan = old;
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
plan = {
|
|
353
|
+
schema: "tiangong-foundry.operation-plan.v1",
|
|
354
|
+
operation_id: operationId,
|
|
355
|
+
job_sha256: task.jobSha256,
|
|
356
|
+
command: input.command,
|
|
357
|
+
options_sha256: optionsSha256,
|
|
358
|
+
input_scope_sha256: inputScopeSha256,
|
|
359
|
+
inputs: context.inputs.map((fact) => ({ ...fact })),
|
|
360
|
+
created_at_utc: new Date().toISOString(),
|
|
361
|
+
};
|
|
362
|
+
writeFoundryArtifact(context, planPath, bytes(plan));
|
|
363
|
+
}
|
|
364
|
+
const planRef = { path: planPath, sha256: digest(readTaskBytes(context, planPath)) };
|
|
365
|
+
let receipt;
|
|
366
|
+
let result;
|
|
367
|
+
if (fs.existsSync(taskPath(context, receiptPath))) {
|
|
368
|
+
const old = readTaskJson(context, receiptPath);
|
|
369
|
+
exact(old, ["schema", "mode", "status", "plan", "job_sha256", "outputs", "result"]);
|
|
370
|
+
if (old.schema !== "tiangong-foundry.operation-receipt.v1" ||
|
|
371
|
+
old.mode !== "deterministic-local" ||
|
|
372
|
+
old.status !== "completed" ||
|
|
373
|
+
old.job_sha256 !== task.jobSha256 ||
|
|
374
|
+
sha256Json(old.plan) !== sha256Json(planRef))
|
|
375
|
+
fail("task_receipt_invalid", "Operation receipt does not match this local preparation.");
|
|
376
|
+
const outputs = facts(old.outputs);
|
|
377
|
+
for (const fact of outputs)
|
|
378
|
+
verifyRecordedArtifact(context, fact);
|
|
379
|
+
const resultRef = reference(old.result);
|
|
380
|
+
const data = readTaskBytes(context, resultRef.path);
|
|
381
|
+
if (digest(data) !== resultRef.sha256 ||
|
|
382
|
+
!outputs.some((fact) => fact.path === resultRef.path && fact.sha256 === resultRef.sha256))
|
|
383
|
+
fail("task_receipt_invalid", "Cached result is not a current operation artifact.");
|
|
384
|
+
result = object(JSON.parse(data.toString("utf8")));
|
|
385
|
+
receipt = old;
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
const outputs = new Map();
|
|
389
|
+
const jsonObjects = new Map();
|
|
390
|
+
let active = true;
|
|
391
|
+
const write = (file, content) => {
|
|
392
|
+
if (!active)
|
|
393
|
+
fail("task_operation_closed", "Operation writers cannot escape the task transaction.");
|
|
394
|
+
loadTask(context, input.task ?? {});
|
|
395
|
+
const relativePath = relative(context, file);
|
|
396
|
+
const consumedMarker = input.command === "dataset-workflow-execution-consume" &&
|
|
397
|
+
/^attempts\/owner-v1\/[0-9a-f]{64}\/consumed\.json$/u.test(relativePath);
|
|
398
|
+
if (!/^(?:outputs|evidence)\//u.test(relativePath) && !consumedMarker)
|
|
399
|
+
fail("task_output_role_invalid", "Command output cannot overwrite task control records.");
|
|
400
|
+
writeFoundryArtifact(context, file, content);
|
|
401
|
+
const fact = captureFoundryInput(taskPath(context, file));
|
|
402
|
+
outputs.set(relativePath, { path: relativePath, bytes: fact.bytes, sha256: fact.sha256 });
|
|
403
|
+
};
|
|
404
|
+
try {
|
|
405
|
+
result = operation({
|
|
406
|
+
job: task.job,
|
|
407
|
+
operationId,
|
|
408
|
+
inputScopeSha256,
|
|
409
|
+
nowIso: () => plan.created_at_utc,
|
|
410
|
+
writeText(file, content) {
|
|
411
|
+
write(file, typeof content === "string"
|
|
412
|
+
? content
|
|
413
|
+
: Buffer.from(content.buffer, content.byteOffset, content.byteLength));
|
|
414
|
+
},
|
|
415
|
+
writeJson(file, value) {
|
|
416
|
+
const data = bytes(value);
|
|
417
|
+
write(file, data);
|
|
418
|
+
jsonObjects.set(digest(data), {
|
|
419
|
+
path: relative(context, file),
|
|
420
|
+
sha256: digest(data),
|
|
421
|
+
});
|
|
422
|
+
},
|
|
423
|
+
});
|
|
424
|
+
const resultRef = jsonObjects.get(digest(bytes(result)));
|
|
425
|
+
if (!resultRef)
|
|
426
|
+
fail("task_result_not_recorded", "Local operation must write its exact returned report as an artifact.");
|
|
427
|
+
verifyInputs(context, task, index);
|
|
428
|
+
receipt = {
|
|
429
|
+
schema: "tiangong-foundry.operation-receipt.v1",
|
|
430
|
+
mode: "deterministic-local",
|
|
431
|
+
status: "completed",
|
|
432
|
+
plan: planRef,
|
|
433
|
+
job_sha256: task.jobSha256,
|
|
434
|
+
outputs: [...outputs.values()],
|
|
435
|
+
result: resultRef,
|
|
436
|
+
};
|
|
437
|
+
writeFoundryArtifact(context, receiptPath, bytes(receipt));
|
|
438
|
+
}
|
|
439
|
+
finally {
|
|
440
|
+
active = false;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const receiptRef = { path: receiptPath, sha256: digest(readTaskBytes(context, receiptPath)) };
|
|
444
|
+
const next = [...index];
|
|
445
|
+
for (const fact of receipt.outputs) {
|
|
446
|
+
if (next.some((entry) => entry.operation_id === operationId &&
|
|
447
|
+
entry.path === fact.path &&
|
|
448
|
+
entry.sha256 === fact.sha256))
|
|
449
|
+
continue;
|
|
450
|
+
const entry = {
|
|
451
|
+
schema: "tiangong-foundry.artifact-index.v2",
|
|
452
|
+
sequence: next.length + 1,
|
|
453
|
+
previous_sha256: next.at(-1)?.record_sha256 ?? null,
|
|
454
|
+
operation_id: operationId,
|
|
455
|
+
command: input.command,
|
|
456
|
+
input_scope_sha256: inputScopeSha256,
|
|
457
|
+
receipt: receiptRef,
|
|
458
|
+
...fact,
|
|
459
|
+
};
|
|
460
|
+
next.push({ ...entry, record_sha256: sha256Json(entry) });
|
|
461
|
+
}
|
|
462
|
+
if (next.length !== index.length)
|
|
463
|
+
replaceIndex(context, next, indexBefore);
|
|
464
|
+
return result;
|
|
465
|
+
});
|
|
466
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { FoundryInputFact } from "./foundry-runtime-context.ts";
|
|
2
|
+
export type JsonRecord = Record<string, unknown>;
|
|
3
|
+
export type Lane = "external-dataset-curated-import" | "source-evidence-dataset-development";
|
|
4
|
+
export interface FileReference {
|
|
5
|
+
path: string;
|
|
6
|
+
sha256: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TaskRuntimeIdentity {
|
|
9
|
+
package_name: string;
|
|
10
|
+
package_version: string;
|
|
11
|
+
manifest_sha256: string;
|
|
12
|
+
entry_sha256: string;
|
|
13
|
+
}
|
|
14
|
+
export interface FoundryTaskJob {
|
|
15
|
+
schema: "tiangong-foundry.job.v2";
|
|
16
|
+
workspace_id: string;
|
|
17
|
+
task_id: string;
|
|
18
|
+
actor_id: string;
|
|
19
|
+
request_id: string;
|
|
20
|
+
lane: Lane;
|
|
21
|
+
target_profile: string;
|
|
22
|
+
target_entities: string[];
|
|
23
|
+
source_manifest: FileReference;
|
|
24
|
+
profile_lock: FileReference;
|
|
25
|
+
seed_manifest: FileReference | null;
|
|
26
|
+
runtime_identity: TaskRuntimeIdentity;
|
|
27
|
+
write_policy: {
|
|
28
|
+
mode: "dry-run";
|
|
29
|
+
remote_state_code: 0;
|
|
30
|
+
};
|
|
31
|
+
created_at_utc: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SourceManifest {
|
|
34
|
+
schema: "tiangong-foundry.source-manifest.v2";
|
|
35
|
+
workspace_id: string;
|
|
36
|
+
task_id: string;
|
|
37
|
+
source_kind: "selected-local-files";
|
|
38
|
+
source_paths: FoundryInputFact[];
|
|
39
|
+
}
|
|
40
|
+
export interface FoundryTaskOptions {
|
|
41
|
+
profileId?: string;
|
|
42
|
+
lane?: Lane;
|
|
43
|
+
requestId?: string;
|
|
44
|
+
targetEntities?: string[];
|
|
45
|
+
seed?: JsonRecord;
|
|
46
|
+
}
|
|
47
|
+
export interface ArtifactFact extends FoundryInputFact {
|
|
48
|
+
path: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ArtifactEntry extends ArtifactFact {
|
|
51
|
+
schema: "tiangong-foundry.artifact-index.v2";
|
|
52
|
+
sequence: number;
|
|
53
|
+
previous_sha256: string | null;
|
|
54
|
+
operation_id: string;
|
|
55
|
+
command: string;
|
|
56
|
+
input_scope_sha256: string;
|
|
57
|
+
receipt: FileReference;
|
|
58
|
+
record_sha256: string;
|
|
59
|
+
}
|
|
60
|
+
export interface OperationPlan {
|
|
61
|
+
schema: "tiangong-foundry.operation-plan.v1";
|
|
62
|
+
operation_id: string;
|
|
63
|
+
job_sha256: string;
|
|
64
|
+
command: string;
|
|
65
|
+
options_sha256: string;
|
|
66
|
+
input_scope_sha256: string;
|
|
67
|
+
inputs: FoundryInputFact[];
|
|
68
|
+
created_at_utc: string;
|
|
69
|
+
}
|
|
70
|
+
export interface OperationReceipt {
|
|
71
|
+
schema: "tiangong-foundry.operation-receipt.v1";
|
|
72
|
+
mode: "deterministic-local";
|
|
73
|
+
status: "completed";
|
|
74
|
+
plan: FileReference;
|
|
75
|
+
job_sha256: string;
|
|
76
|
+
outputs: ArtifactFact[];
|
|
77
|
+
result: FileReference;
|
|
78
|
+
}
|
|
79
|
+
export interface LoadedTask {
|
|
80
|
+
job: FoundryTaskJob;
|
|
81
|
+
jobSha256: string;
|
|
82
|
+
sources: FoundryInputFact[];
|
|
83
|
+
}
|
|
84
|
+
export interface TaskRegistration {
|
|
85
|
+
schema: "tiangong-foundry.task-registration.v1";
|
|
86
|
+
job: FoundryTaskJob;
|
|
87
|
+
source_manifest: SourceManifest;
|
|
88
|
+
profile_lock: JsonRecord;
|
|
89
|
+
seed_manifest: JsonRecord | null;
|
|
90
|
+
registration_sha256: string;
|
|
91
|
+
}
|
|
92
|
+
export interface FoundryTaskOperation {
|
|
93
|
+
readonly job: FoundryTaskJob;
|
|
94
|
+
readonly operationId: string;
|
|
95
|
+
readonly inputScopeSha256: string;
|
|
96
|
+
readonly nowIso: () => string;
|
|
97
|
+
writeText(filePath: string, bytes: string | NodeJS.ArrayBufferView): void;
|
|
98
|
+
writeJson(filePath: string, value: unknown): void;
|
|
99
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import { type FoundryAuthentication } from "./foundry-runtime-identity.ts";
|
|
4
|
+
import { type WorkflowArtifact } from "./foundry-workflow-state.ts";
|
|
5
|
+
import type { ArtifactEntry } from "./foundry-task-types.ts";
|
|
6
|
+
export declare function continueFoundryPreparedApproval(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, entries: readonly ArtifactEntry[], approval: WorkflowArtifact<Record<string, unknown>>, authentication?: FoundryAuthentication): Promise<import("./foundry-task-types.ts").JsonRecord>;
|