@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,132 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { captureFoundryInput, FoundryContextError, } from "./foundry-runtime-context.js";
|
|
5
|
+
import { assertNotFoundrySessionFile, migrationCredentialPath } from "./foundry-private-path.js";
|
|
6
|
+
import { workflowObject } from "./foundry-workflow-state.js";
|
|
7
|
+
export const FOUNDRY_SEMANTIC_INPUT_SCHEMA = "tiangong-foundry.semantic-input.v1";
|
|
8
|
+
const selectedInputs = new WeakSet();
|
|
9
|
+
const sha = /^[0-9a-f]{64}$/u;
|
|
10
|
+
function invalid(message) {
|
|
11
|
+
throw new FoundryContextError("task_semantic_input_invalid", message);
|
|
12
|
+
}
|
|
13
|
+
function exact(value, keys) {
|
|
14
|
+
if (Object.keys(value).length !== keys.length || keys.some((key) => !Object.hasOwn(value, key)))
|
|
15
|
+
invalid("Semantic input has missing or unsupported fields.");
|
|
16
|
+
}
|
|
17
|
+
export function parseFoundrySemanticInput(value) {
|
|
18
|
+
const data = workflowObject(value);
|
|
19
|
+
exact(data, ["schema", "task_id", "actor_id", "assessment_sha256", "submissions"]);
|
|
20
|
+
if (data.schema !== FOUNDRY_SEMANTIC_INPUT_SCHEMA ||
|
|
21
|
+
typeof data.task_id !== "string" ||
|
|
22
|
+
!/^task-[0-9a-f]{64}-r\d{4}$/u.test(data.task_id) ||
|
|
23
|
+
typeof data.actor_id !== "string" ||
|
|
24
|
+
!/^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u.test(data.actor_id) ||
|
|
25
|
+
typeof data.assessment_sha256 !== "string" ||
|
|
26
|
+
!sha.test(data.assessment_sha256) ||
|
|
27
|
+
!Array.isArray(data.submissions) ||
|
|
28
|
+
!data.submissions.length ||
|
|
29
|
+
data.submissions.length > 1000)
|
|
30
|
+
invalid("Semantic input must bind a task, actor, assessment and bounded submission selection.");
|
|
31
|
+
const submissions = data.submissions.map((item) => {
|
|
32
|
+
const part = workflowObject(item);
|
|
33
|
+
exact(part, ["kind", "authoring_task_sha256", "file", "sha256"]);
|
|
34
|
+
if ((part.kind !== "patch" &&
|
|
35
|
+
part.kind !== "classification" &&
|
|
36
|
+
part.kind !== "location" &&
|
|
37
|
+
part.kind !== "identity") ||
|
|
38
|
+
typeof part.authoring_task_sha256 !== "string" ||
|
|
39
|
+
!sha.test(part.authoring_task_sha256) ||
|
|
40
|
+
typeof part.sha256 !== "string" ||
|
|
41
|
+
!sha.test(part.sha256) ||
|
|
42
|
+
typeof part.file !== "string" ||
|
|
43
|
+
!part.file ||
|
|
44
|
+
part.file.length > 4096 ||
|
|
45
|
+
/[\0\r\n]/u.test(part.file))
|
|
46
|
+
invalid("A semantic submission reference is invalid.");
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
kind: part.kind,
|
|
49
|
+
authoring_task_sha256: part.authoring_task_sha256,
|
|
50
|
+
file: part.file,
|
|
51
|
+
sha256: part.sha256,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
if (new Set(submissions.map((part) => part.authoring_task_sha256)).size !== submissions.length)
|
|
55
|
+
invalid("A work item may appear only once in a submission.");
|
|
56
|
+
return Object.freeze({
|
|
57
|
+
schema: FOUNDRY_SEMANTIC_INPUT_SCHEMA,
|
|
58
|
+
task_id: data.task_id,
|
|
59
|
+
actor_id: data.actor_id,
|
|
60
|
+
assessment_sha256: data.assessment_sha256,
|
|
61
|
+
submissions: Object.freeze(submissions),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export function readSelectedSemanticBytes(fact) {
|
|
65
|
+
const fd = fs.openSync(fact.path, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
66
|
+
try {
|
|
67
|
+
const stat = fs.fstatSync(fd);
|
|
68
|
+
if (!stat.isFile() || stat.size !== fact.bytes || stat.size > 8 * 1024 * 1024)
|
|
69
|
+
invalid("Semantic input must be a bounded regular file.");
|
|
70
|
+
const bytes = fs.readFileSync(fd);
|
|
71
|
+
if (bytes.length !== fact.bytes ||
|
|
72
|
+
createHash("sha256").update(bytes).digest("hex") !== fact.sha256)
|
|
73
|
+
throw new FoundryContextError("semantic_input_changed", "Semantic input changed after selection.");
|
|
74
|
+
return bytes;
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
fs.closeSync(fd);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export function selectFoundrySemanticInput(context, file) {
|
|
81
|
+
let selectedBytes = 0;
|
|
82
|
+
const select = (value) => {
|
|
83
|
+
if (!value || value.length > 4096 || /[\0\r\n]/u.test(value))
|
|
84
|
+
invalid("Semantic input path is invalid.");
|
|
85
|
+
const target = path.resolve(context.workspaceRoot, value);
|
|
86
|
+
if (migrationCredentialPath(path.relative(context.workspaceRoot, target)))
|
|
87
|
+
invalid("Credential paths cannot be semantic inputs.");
|
|
88
|
+
assertNotFoundrySessionFile(target, context.accountIntent?.sessionReference);
|
|
89
|
+
const stat = fs.lstatSync(target);
|
|
90
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 8 * 1024 * 1024)
|
|
91
|
+
invalid("Semantic input must be a bounded regular file.");
|
|
92
|
+
selectedBytes += stat.size;
|
|
93
|
+
if (selectedBytes > 64 * 1024 * 1024)
|
|
94
|
+
invalid("Semantic submission exceeds the 64 MiB batch limit.");
|
|
95
|
+
return captureFoundryInput(target);
|
|
96
|
+
};
|
|
97
|
+
const descriptor = select(file);
|
|
98
|
+
let spec;
|
|
99
|
+
try {
|
|
100
|
+
spec = parseFoundrySemanticInput(JSON.parse(readSelectedSemanticBytes(descriptor).toString("utf8")));
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error instanceof FoundryContextError && error.code !== "workflow_report_invalid")
|
|
104
|
+
throw error;
|
|
105
|
+
invalid("Semantic input must be a complete supported JSON descriptor.");
|
|
106
|
+
}
|
|
107
|
+
if (spec.task_id !== context.taskId || spec.actor_id !== context.actorId)
|
|
108
|
+
throw new FoundryContextError("semantic_input_scope_mismatch", "Submission task or actor differs from this invocation.");
|
|
109
|
+
const files = spec.submissions.map((part) => {
|
|
110
|
+
const fact = select(part.file);
|
|
111
|
+
if (fact.sha256 !== part.sha256)
|
|
112
|
+
throw new FoundryContextError("semantic_input_changed", "Patch bytes do not match the submitted digest.");
|
|
113
|
+
readSelectedSemanticBytes(fact);
|
|
114
|
+
return fact;
|
|
115
|
+
});
|
|
116
|
+
if (descriptor.bytes + files.reduce((sum, fact) => sum + fact.bytes, 0) > 64 * 1024 * 1024)
|
|
117
|
+
invalid("Semantic submission exceeds the 64 MiB batch limit.");
|
|
118
|
+
const result = Object.freeze({
|
|
119
|
+
spec,
|
|
120
|
+
descriptor: Object.freeze(descriptor),
|
|
121
|
+
files: Object.freeze(files.map((fact) => Object.freeze(fact))),
|
|
122
|
+
});
|
|
123
|
+
selectedInputs.add(result);
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
export function assertSelectedSemanticInput(value) {
|
|
127
|
+
if (!selectedInputs.has(value))
|
|
128
|
+
throw new FoundryContextError("semantic_input_unverified", "Select semantic input through the current invocation.");
|
|
129
|
+
readSelectedSemanticBytes(value.descriptor);
|
|
130
|
+
for (const file of value.files)
|
|
131
|
+
readSelectedSemanticBytes(file);
|
|
132
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type FoundryInputFact, type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import { type VerifiedFoundryIdentity } from "./foundry-runtime-identity.ts";
|
|
3
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
4
|
+
import { type ValidatedTaskAuthorization } from "./task-authorization.ts";
|
|
5
|
+
import type { LoadedTask, ArtifactEntry } from "./foundry-task-types.ts";
|
|
6
|
+
export interface TaskApprovalEvidence {
|
|
7
|
+
id: string;
|
|
8
|
+
kind: "user-decision" | "source-model";
|
|
9
|
+
file: FoundryInputFact;
|
|
10
|
+
}
|
|
11
|
+
export interface PrepareDerivedFoundryTaskAuthorizationOptions {
|
|
12
|
+
approvedInputFile: string;
|
|
13
|
+
derivedInputFile: string;
|
|
14
|
+
}
|
|
15
|
+
/** Explicit host approval boundary. Evidence selections come from the trusted caller, never from grant text. */
|
|
16
|
+
export declare function registerFoundryTaskAuthorization(context: FoundryRuntimeContext, identity: VerifiedFoundryIdentity, options: {
|
|
17
|
+
inputFile: string;
|
|
18
|
+
grant: unknown;
|
|
19
|
+
evidence: readonly TaskApprovalEvidence[];
|
|
20
|
+
expectedPreviousSha256?: string | null;
|
|
21
|
+
validateCurrent?: (task: LoadedTask, index: readonly ArtifactEntry[]) => void;
|
|
22
|
+
}, qualification?: QualifiedFoundryRuntime): Promise<{
|
|
23
|
+
authorization_sha256: string;
|
|
24
|
+
pointer_sha256: string;
|
|
25
|
+
}>;
|
|
26
|
+
export declare function loadFoundryTaskAuthorization(context: FoundryRuntimeContext, identity: VerifiedFoundryIdentity, inputFile: string, qualification?: QualifiedFoundryRuntime): Promise<ValidatedTaskAuthorization>;
|
|
27
|
+
/** Prepare, but do not activate, an exact successor grant for a verified derived task artifact. */
|
|
28
|
+
export declare function prepareDerivedFoundryTaskAuthorization(context: FoundryRuntimeContext, qualification: QualifiedFoundryRuntime, identity: VerifiedFoundryIdentity, options: PrepareDerivedFoundryTaskAuthorizationOptions): Promise<Readonly<{
|
|
29
|
+
grant: Readonly<{
|
|
30
|
+
schema: "tiangong-foundry.task-authorization.v1";
|
|
31
|
+
binding: Readonly<{
|
|
32
|
+
workspace_id: string;
|
|
33
|
+
task_id: string;
|
|
34
|
+
actor_id: string;
|
|
35
|
+
project_ref: string;
|
|
36
|
+
user_id: string;
|
|
37
|
+
profile_id: string;
|
|
38
|
+
profile_sha256: string;
|
|
39
|
+
input_scope_sha256: string;
|
|
40
|
+
}>;
|
|
41
|
+
issued_at_utc: string;
|
|
42
|
+
expires_at_utc: string;
|
|
43
|
+
remote_state_code: 0;
|
|
44
|
+
allowed_actions: readonly ("canonical_support_local_mint" | "elementary_flow_create_new" | "elementary_flow_write" | "flowproperty_write" | "unitgroup_write")[];
|
|
45
|
+
qa_waivers: readonly Readonly<{
|
|
46
|
+
dataset_type: "process";
|
|
47
|
+
code: "process_material_balance_deviation";
|
|
48
|
+
evidence_ids: readonly string[];
|
|
49
|
+
}>[];
|
|
50
|
+
evidence: readonly Readonly<{
|
|
51
|
+
id: string;
|
|
52
|
+
kind: "user-decision" | "source-model";
|
|
53
|
+
reference: string;
|
|
54
|
+
sha256: string;
|
|
55
|
+
}>[];
|
|
56
|
+
}>;
|
|
57
|
+
evidence: readonly Readonly<{
|
|
58
|
+
id: string;
|
|
59
|
+
kind: "source-model" | "user-decision";
|
|
60
|
+
file: FoundryInputFact;
|
|
61
|
+
}>[];
|
|
62
|
+
expected_previous_sha256: string;
|
|
63
|
+
derivation: Readonly<{
|
|
64
|
+
path: string;
|
|
65
|
+
bytes: number;
|
|
66
|
+
sha256: string;
|
|
67
|
+
}>;
|
|
68
|
+
}>>;
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { captureFoundryInput, resolveFoundryInputPath, resolveFoundryOutput, writeFoundryArtifact, assertFoundryWorkspaceActive, } from "./foundry-runtime-context.js";
|
|
5
|
+
import { assertVerifiedFoundryIdentity, } from "./foundry-runtime-identity.js";
|
|
6
|
+
import { assertFoundryTaskInputLineage, withFoundryTaskMetadata } from "./foundry-task-store.js";
|
|
7
|
+
import { bytes, digest, exact, fail, object, readTaskBytes, reference, shaPattern, taskPath, } from "./foundry-task-io.js";
|
|
8
|
+
import { validateTaskAuthorization, deriveTaskAuthorizationGrant, taskAuthorizationMatches, } from "./task-authorization.js";
|
|
9
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
10
|
+
function inputFact(context, file) {
|
|
11
|
+
const resolved = resolveFoundryInputPath(context, file);
|
|
12
|
+
return context.inputs.find((fact) => fact.path === resolved);
|
|
13
|
+
}
|
|
14
|
+
function binding(context, task, input) {
|
|
15
|
+
if (!context.accountIntent)
|
|
16
|
+
fail("account_intent_required", "Authorization requires an explicit task account intent.");
|
|
17
|
+
const locked = object(JSON.parse(readTaskBytes(context, "profile-lock.json").toString("utf8")));
|
|
18
|
+
if (typeof locked.profile_sha256 !== "string" || !shaPattern.test(locked.profile_sha256))
|
|
19
|
+
fail("task_profile_changed", "Profile lock lacks a current content identity.");
|
|
20
|
+
return {
|
|
21
|
+
workspace_id: context.workspaceId,
|
|
22
|
+
task_id: context.taskId,
|
|
23
|
+
actor_id: context.actorId,
|
|
24
|
+
project_ref: context.accountIntent.projectRef,
|
|
25
|
+
user_id: context.accountIntent.userId,
|
|
26
|
+
profile_id: task.job.target_profile,
|
|
27
|
+
profile_sha256: locked.profile_sha256,
|
|
28
|
+
input_scope_sha256: input.sha256,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function readEvidence(context, fact) {
|
|
32
|
+
const sessionReference = context.accountIntent?.sessionReference;
|
|
33
|
+
const sessionPath = sessionReference && fs.existsSync(sessionReference)
|
|
34
|
+
? fs.realpathSync(sessionReference)
|
|
35
|
+
: sessionReference;
|
|
36
|
+
if (fact.path === sessionPath || fact.bytes > 8 * 1024 * 1024)
|
|
37
|
+
fail("authorization_evidence_invalid", "Approval evidence must be a bounded non-credential file.");
|
|
38
|
+
const current = captureFoundryInput(fact.path);
|
|
39
|
+
if (current.path !== fact.path || current.bytes !== fact.bytes || current.sha256 !== fact.sha256)
|
|
40
|
+
fail("authorization_evidence_changed", "Approval/source evidence differs from the independently selected content fact.");
|
|
41
|
+
const data = fs.readFileSync(fact.path);
|
|
42
|
+
if (data.length !== fact.bytes || digest(data) !== fact.sha256)
|
|
43
|
+
fail("authorization_evidence_changed", "Approval evidence changed while it was read.");
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
function registrationPath(context, authorizationSha256) {
|
|
47
|
+
if (!shaPattern.test(authorizationSha256))
|
|
48
|
+
fail("task_authorization_unregistered", "Authorization identity must be a content digest.");
|
|
49
|
+
return resolveFoundryOutput(context, `task-authorizations/${context.taskId}/${authorizationSha256}.json`, "state");
|
|
50
|
+
}
|
|
51
|
+
function writeRegistration(context, registration) {
|
|
52
|
+
const target = registrationPath(context, registration.authorization_sha256);
|
|
53
|
+
const content = bytes(registration);
|
|
54
|
+
fs.mkdirSync(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
55
|
+
resolveFoundryOutput(context, target, "state");
|
|
56
|
+
if (fs.existsSync(target)) {
|
|
57
|
+
const stat = fs.lstatSync(target);
|
|
58
|
+
if (!stat.isFile() || stat.isSymbolicLink() || !fs.readFileSync(target).equals(content))
|
|
59
|
+
fail("authorization_registration_conflict", "An approved grant identity cannot be replaced with different evidence.");
|
|
60
|
+
return content;
|
|
61
|
+
}
|
|
62
|
+
const temp = `${target}.${randomUUID()}.tmp`;
|
|
63
|
+
const fd = fs.openSync(temp, "wx", 0o600);
|
|
64
|
+
try {
|
|
65
|
+
fs.writeFileSync(fd, content);
|
|
66
|
+
fs.fsyncSync(fd);
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
fs.closeSync(fd);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
fs.linkSync(temp, target);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
if (fs.existsSync(temp))
|
|
76
|
+
fs.unlinkSync(temp);
|
|
77
|
+
}
|
|
78
|
+
return content;
|
|
79
|
+
}
|
|
80
|
+
function setActiveAuthorization(context, content, expectedPreviousSha256) {
|
|
81
|
+
const target = taskPath(context, "authorization.json");
|
|
82
|
+
const existing = fs.existsSync(target) ? readTaskBytes(context, target) : null;
|
|
83
|
+
if (existing?.equals(content))
|
|
84
|
+
return;
|
|
85
|
+
if (existing) {
|
|
86
|
+
const pointer = object(JSON.parse(existing.toString("utf8")));
|
|
87
|
+
if (pointer.schema !== "tiangong-foundry.authorization-pointer.v1")
|
|
88
|
+
fail("legacy_authorization_requires_migration", "Legacy authorization files must be mapped explicitly, not overwritten.");
|
|
89
|
+
}
|
|
90
|
+
if ((existing ? digest(existing) : null) !== expectedPreviousSha256)
|
|
91
|
+
fail("authorization_update_conflict", "Active authorization changed; review the current pointer before replacing it.");
|
|
92
|
+
const temp = taskPath(context, `.authorization-${randomUUID()}.tmp`);
|
|
93
|
+
const fd = fs.openSync(temp, "wx", 0o600);
|
|
94
|
+
try {
|
|
95
|
+
fs.writeFileSync(fd, content);
|
|
96
|
+
fs.fsyncSync(fd);
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
fs.closeSync(fd);
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const current = fs.existsSync(target) ? readTaskBytes(context, target) : null;
|
|
103
|
+
if ((current ? digest(current) : null) !== expectedPreviousSha256)
|
|
104
|
+
fail("authorization_update_conflict", "Authorization pointer changed outside the metadata lock.");
|
|
105
|
+
if (current)
|
|
106
|
+
fs.renameSync(temp, target);
|
|
107
|
+
else
|
|
108
|
+
fs.linkSync(temp, target);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
if (fs.existsSync(temp))
|
|
112
|
+
fs.unlinkSync(temp);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** Explicit host approval boundary. Evidence selections come from the trusted caller, never from grant text. */
|
|
116
|
+
export async function registerFoundryTaskAuthorization(context, identity, options, qualification) {
|
|
117
|
+
assertFoundryWorkspaceActive(context);
|
|
118
|
+
assertVerifiedFoundryIdentity(context, identity, qualification);
|
|
119
|
+
return withFoundryTaskMetadata(context, (task, index) => {
|
|
120
|
+
assertVerifiedFoundryIdentity(context, identity, qualification);
|
|
121
|
+
options.validateCurrent?.(task, index);
|
|
122
|
+
const input = inputFact(context, options.inputFile);
|
|
123
|
+
const result = validateTaskAuthorization(options.grant, binding(context, task, input));
|
|
124
|
+
if (result.status !== "authorized")
|
|
125
|
+
fail(result.blockers[0]?.code ?? "task_authorization_required", result.blockers[0]?.message ?? "Explicit task authorization is required.");
|
|
126
|
+
const authorization = result.authorization;
|
|
127
|
+
if (options.evidence.length !== authorization.evidence.length ||
|
|
128
|
+
new Set(options.evidence.map((entry) => entry.id)).size !== options.evidence.length)
|
|
129
|
+
fail("authorization_evidence_invalid", "Every grant evidence item needs one independent host selection.");
|
|
130
|
+
const selected = authorization.evidence.map((entry) => {
|
|
131
|
+
const expected = options.evidence.find((value) => value.id === entry.id);
|
|
132
|
+
const requested = path.isAbsolute(entry.reference)
|
|
133
|
+
? path.resolve(entry.reference)
|
|
134
|
+
: taskPath(context, entry.reference);
|
|
135
|
+
if (!expected ||
|
|
136
|
+
expected.kind !== entry.kind ||
|
|
137
|
+
expected.file.sha256 !== entry.sha256 ||
|
|
138
|
+
expected.file.path !== requested)
|
|
139
|
+
fail("authorization_evidence_invalid", "Grant evidence does not match the independent host selection.");
|
|
140
|
+
return { entry, expected, data: readEvidence(context, expected.file) };
|
|
141
|
+
});
|
|
142
|
+
const grantPath = `evidence/authorizations/${authorization.authorization_sha256}/grant.json`;
|
|
143
|
+
const grantBytes = bytes(options.grant);
|
|
144
|
+
const registeredEvidence = [];
|
|
145
|
+
for (const { entry, expected, data } of selected) {
|
|
146
|
+
const snapshotPath = `evidence/authorizations/${authorization.authorization_sha256}/sources/${sha256Json(entry.id)}.bin`;
|
|
147
|
+
writeFoundryArtifact(context, snapshotPath, data);
|
|
148
|
+
registeredEvidence.push({
|
|
149
|
+
id: entry.id,
|
|
150
|
+
kind: entry.kind,
|
|
151
|
+
file: { ...expected.file },
|
|
152
|
+
snapshot: { path: snapshotPath, sha256: digest(data) },
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
writeFoundryArtifact(context, grantPath, grantBytes);
|
|
156
|
+
const registration = {
|
|
157
|
+
schema: "tiangong-foundry.authorization-registration.v1",
|
|
158
|
+
job_sha256: task.jobSha256,
|
|
159
|
+
authorization_sha256: authorization.authorization_sha256,
|
|
160
|
+
input: { ...input },
|
|
161
|
+
grant: { path: grantPath, sha256: digest(grantBytes) },
|
|
162
|
+
evidence: registeredEvidence,
|
|
163
|
+
identity: {
|
|
164
|
+
project_ref: identity.receipt.project.project_ref,
|
|
165
|
+
user_id: identity.receipt.identity.user_id,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
assertVerifiedFoundryIdentity(context, identity, qualification);
|
|
169
|
+
if (validateTaskAuthorization(options.grant, binding(context, task, input)).status !==
|
|
170
|
+
"authorized")
|
|
171
|
+
fail("task_authorization_invalid", "Authorization expired or changed before it could be activated.");
|
|
172
|
+
const registrationBytes = writeRegistration(context, registration);
|
|
173
|
+
options.validateCurrent?.(task, index);
|
|
174
|
+
const pointer = bytes({
|
|
175
|
+
schema: "tiangong-foundry.authorization-pointer.v1",
|
|
176
|
+
authorization_sha256: authorization.authorization_sha256,
|
|
177
|
+
registration_sha256: digest(registrationBytes),
|
|
178
|
+
});
|
|
179
|
+
setActiveAuthorization(context, pointer, options.expectedPreviousSha256 ?? null);
|
|
180
|
+
return {
|
|
181
|
+
authorization_sha256: authorization.authorization_sha256,
|
|
182
|
+
pointer_sha256: digest(pointer),
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
export async function loadFoundryTaskAuthorization(context, identity, inputFile, qualification) {
|
|
187
|
+
assertVerifiedFoundryIdentity(context, identity, qualification);
|
|
188
|
+
const loaded = await withFoundryTaskMetadata(context, (task) => {
|
|
189
|
+
assertVerifiedFoundryIdentity(context, identity, qualification);
|
|
190
|
+
const input = inputFact(context, inputFile);
|
|
191
|
+
if (!fs.existsSync(taskPath(context, "authorization.json")))
|
|
192
|
+
fail("task_authorization_required", "This task has no active registered authorization.");
|
|
193
|
+
const pointer = object(JSON.parse(readTaskBytes(context, "authorization.json").toString("utf8")));
|
|
194
|
+
exact(pointer, ["schema", "authorization_sha256", "registration_sha256"]);
|
|
195
|
+
if (pointer.schema !== "tiangong-foundry.authorization-pointer.v1" ||
|
|
196
|
+
typeof pointer.authorization_sha256 !== "string")
|
|
197
|
+
fail("task_authorization_unregistered", "Only explicitly registered task authorization can be loaded.");
|
|
198
|
+
const statePath = registrationPath(context, pointer.authorization_sha256);
|
|
199
|
+
const stat = fs.lstatSync(statePath);
|
|
200
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 8 * 1024 * 1024)
|
|
201
|
+
fail("task_authorization_unregistered", "Authorization registration is not a bounded regular file.");
|
|
202
|
+
const registrationBytes = fs.readFileSync(statePath);
|
|
203
|
+
if (digest(registrationBytes) !== pointer.registration_sha256)
|
|
204
|
+
fail("authorization_registration_changed", "Authorization registration content changed.");
|
|
205
|
+
const registration = object(JSON.parse(registrationBytes.toString("utf8")));
|
|
206
|
+
exact(registration, [
|
|
207
|
+
"schema",
|
|
208
|
+
"job_sha256",
|
|
209
|
+
"authorization_sha256",
|
|
210
|
+
"input",
|
|
211
|
+
"grant",
|
|
212
|
+
"evidence",
|
|
213
|
+
"identity",
|
|
214
|
+
]);
|
|
215
|
+
const registeredInput = object(registration.input);
|
|
216
|
+
exact(registeredInput, ["path", "bytes", "sha256"]);
|
|
217
|
+
if (registration.schema !== "tiangong-foundry.authorization-registration.v1" ||
|
|
218
|
+
registration.job_sha256 !== task.jobSha256 ||
|
|
219
|
+
registration.authorization_sha256 !== pointer.authorization_sha256 ||
|
|
220
|
+
typeof registeredInput.path !== "string" ||
|
|
221
|
+
registeredInput.bytes !== input.bytes ||
|
|
222
|
+
registeredInput.sha256 !== input.sha256 ||
|
|
223
|
+
sha256Json(registration.identity) !==
|
|
224
|
+
sha256Json({
|
|
225
|
+
project_ref: identity.receipt.project.project_ref,
|
|
226
|
+
user_id: identity.receipt.identity.user_id,
|
|
227
|
+
}))
|
|
228
|
+
fail("task_authorization_binding_mismatch", "Registered authorization does not match current task inputs and account.");
|
|
229
|
+
const grantRef = reference(registration.grant);
|
|
230
|
+
const grantBytes = readTaskBytes(context, grantRef.path);
|
|
231
|
+
if (digest(grantBytes) !== grantRef.sha256)
|
|
232
|
+
fail("task_authorization_changed", "Approved grant snapshot changed.");
|
|
233
|
+
const result = validateTaskAuthorization(JSON.parse(grantBytes.toString("utf8")), binding(context, task, input));
|
|
234
|
+
if (result.status !== "authorized" ||
|
|
235
|
+
result.authorization.authorization_sha256 !== pointer.authorization_sha256)
|
|
236
|
+
fail("task_authorization_invalid", "Approved grant is expired, invalid or no longer bound to current intent.");
|
|
237
|
+
if (!Array.isArray(registration.evidence) ||
|
|
238
|
+
registration.evidence.length !== result.authorization.evidence.length ||
|
|
239
|
+
new Set(registration.evidence.map((entry) => object(entry).id)).size !==
|
|
240
|
+
registration.evidence.length)
|
|
241
|
+
fail("authorization_evidence_invalid", "Registered approval evidence is incomplete.");
|
|
242
|
+
for (const raw of registration.evidence) {
|
|
243
|
+
const selected = object(raw);
|
|
244
|
+
exact(selected, ["id", "kind", "file", "snapshot"]);
|
|
245
|
+
const file = object(selected.file);
|
|
246
|
+
exact(file, ["path", "bytes", "sha256"]);
|
|
247
|
+
if (typeof file.path !== "string" ||
|
|
248
|
+
!path.isAbsolute(file.path) ||
|
|
249
|
+
typeof file.bytes !== "number" ||
|
|
250
|
+
!Number.isSafeInteger(file.bytes) ||
|
|
251
|
+
file.bytes < 0 ||
|
|
252
|
+
typeof file.sha256 !== "string" ||
|
|
253
|
+
!shaPattern.test(file.sha256))
|
|
254
|
+
fail("authorization_evidence_invalid", "Registered evidence fact is malformed.");
|
|
255
|
+
const actual = readEvidence(context, {
|
|
256
|
+
path: file.path,
|
|
257
|
+
bytes: file.bytes,
|
|
258
|
+
sha256: file.sha256,
|
|
259
|
+
});
|
|
260
|
+
const snapshot = reference(selected.snapshot);
|
|
261
|
+
const snapshotBytes = readTaskBytes(context, snapshot.path);
|
|
262
|
+
if (!snapshotBytes.equals(actual) || digest(snapshotBytes) !== snapshot.sha256)
|
|
263
|
+
fail("authorization_evidence_changed", "Approved evidence snapshot or original source changed.");
|
|
264
|
+
const proof = result.authorization.evidence.find((entry) => entry.id === selected.id);
|
|
265
|
+
const evidencePath = proof
|
|
266
|
+
? path.isAbsolute(proof.reference)
|
|
267
|
+
? path.resolve(proof.reference)
|
|
268
|
+
: taskPath(context, proof.reference)
|
|
269
|
+
: null;
|
|
270
|
+
if (!proof ||
|
|
271
|
+
proof.kind !== selected.kind ||
|
|
272
|
+
proof.sha256 !== file.sha256 ||
|
|
273
|
+
evidencePath !== file.path)
|
|
274
|
+
fail("authorization_evidence_invalid", "Grant and selected evidence no longer agree.");
|
|
275
|
+
}
|
|
276
|
+
assertVerifiedFoundryIdentity(context, identity, qualification);
|
|
277
|
+
const refreshed = validateTaskAuthorization(JSON.parse(grantBytes.toString("utf8")), binding(context, task, input));
|
|
278
|
+
if (refreshed.status !== "authorized")
|
|
279
|
+
fail("task_authorization_invalid", "Task authorization expired during evidence verification.");
|
|
280
|
+
return {
|
|
281
|
+
authorization: refreshed.authorization,
|
|
282
|
+
registeredInput: registeredInput.path,
|
|
283
|
+
pointerSha256: digest(readTaskBytes(context, "authorization.json")),
|
|
284
|
+
inputPath: input.path,
|
|
285
|
+
};
|
|
286
|
+
});
|
|
287
|
+
if (loaded.registeredInput !== loaded.inputPath) {
|
|
288
|
+
await assertFoundryTaskInputLineage(context, loaded.registeredInput, loaded.inputPath);
|
|
289
|
+
return withFoundryTaskMetadata(context, (task) => {
|
|
290
|
+
assertVerifiedFoundryIdentity(context, identity, qualification);
|
|
291
|
+
if (digest(readTaskBytes(context, "authorization.json")) !== loaded.pointerSha256)
|
|
292
|
+
fail("authorization_update_conflict", "Approval changed during equivalent-content lineage verification.");
|
|
293
|
+
if (!taskAuthorizationMatches(loaded.authorization, binding(context, task, inputFact(context, inputFile))))
|
|
294
|
+
fail("task_authorization_invalid", "Approval expired during equivalent-content lineage verification.");
|
|
295
|
+
return loaded.authorization;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
return loaded.authorization;
|
|
299
|
+
}
|
|
300
|
+
/** Prepare, but do not activate, an exact successor grant for a verified derived task artifact. */
|
|
301
|
+
export async function prepareDerivedFoundryTaskAuthorization(context, qualification, identity, options) {
|
|
302
|
+
assertFoundryWorkspaceActive(context);
|
|
303
|
+
assertVerifiedFoundryIdentity(context, identity, qualification);
|
|
304
|
+
const parent = await loadFoundryTaskAuthorization(context, identity, options.approvedInputFile, qualification);
|
|
305
|
+
const parentPointer = readTaskBytes(context, "authorization.json");
|
|
306
|
+
const pointer = object(JSON.parse(parentPointer.toString("utf8")));
|
|
307
|
+
exact(pointer, ["schema", "authorization_sha256", "registration_sha256"]);
|
|
308
|
+
if (pointer.schema !== "tiangong-foundry.authorization-pointer.v1" ||
|
|
309
|
+
pointer.authorization_sha256 !== parent.authorization_sha256 ||
|
|
310
|
+
typeof pointer.registration_sha256 !== "string" ||
|
|
311
|
+
!shaPattern.test(pointer.registration_sha256))
|
|
312
|
+
fail("authorization_update_conflict", "Active authorization changed before its derived-input successor could be prepared.");
|
|
313
|
+
const lineage = await assertFoundryTaskInputLineage(context, options.approvedInputFile, options.derivedInputFile);
|
|
314
|
+
const grant = deriveTaskAuthorizationGrant(parent, {
|
|
315
|
+
...parent.binding,
|
|
316
|
+
input_scope_sha256: lineage.derived.sha256,
|
|
317
|
+
});
|
|
318
|
+
const evidence = parent.evidence.map((entry) => {
|
|
319
|
+
const filePath = path.isAbsolute(entry.reference)
|
|
320
|
+
? path.resolve(entry.reference)
|
|
321
|
+
: taskPath(context, entry.reference);
|
|
322
|
+
return Object.freeze({
|
|
323
|
+
id: entry.id,
|
|
324
|
+
kind: entry.kind,
|
|
325
|
+
file: captureFoundryInput(filePath),
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
const plan = Object.freeze({
|
|
329
|
+
schema: "tiangong-foundry.authorization-derivation.v1",
|
|
330
|
+
parent_authorization_sha256: parent.authorization_sha256,
|
|
331
|
+
derived_authorization_sha256: sha256Json(grant),
|
|
332
|
+
approved_input: Object.freeze({ ...lineage.ancestor }),
|
|
333
|
+
derived_input: Object.freeze({ ...lineage.derived }),
|
|
334
|
+
});
|
|
335
|
+
const relativePath = `evidence/authorizations/${plan.derived_authorization_sha256}/derivation.json`;
|
|
336
|
+
const planBytes = bytes(plan);
|
|
337
|
+
writeFoundryArtifact(context, relativePath, planBytes);
|
|
338
|
+
if (!readTaskBytes(context, "authorization.json").equals(parentPointer))
|
|
339
|
+
fail("authorization_update_conflict", "Active authorization changed while its derived-input successor was prepared.");
|
|
340
|
+
return Object.freeze({
|
|
341
|
+
grant,
|
|
342
|
+
evidence: Object.freeze(evidence),
|
|
343
|
+
expected_previous_sha256: digest(parentPointer),
|
|
344
|
+
derivation: Object.freeze({
|
|
345
|
+
path: relativePath,
|
|
346
|
+
bytes: planBytes.length,
|
|
347
|
+
sha256: digest(planBytes),
|
|
348
|
+
}),
|
|
349
|
+
});
|
|
350
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext, type FoundryInputFact } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { JsonRecord, FileReference } from "./foundry-task-types.ts";
|
|
3
|
+
export declare const shaPattern: RegExp;
|
|
4
|
+
export declare const maxDocumentBytes: number;
|
|
5
|
+
export declare const maxIndexBytes: number;
|
|
6
|
+
export declare function fail(code: string, message: string): never;
|
|
7
|
+
export declare function object(value: unknown): JsonRecord;
|
|
8
|
+
export declare function exact(value: JsonRecord, keys: string[]): void;
|
|
9
|
+
export declare function timestamp(value: unknown): value is string;
|
|
10
|
+
export declare function bytes(value: unknown): Buffer;
|
|
11
|
+
export declare function digest(value: Buffer | string): string;
|
|
12
|
+
export declare function taskPath(context: FoundryRuntimeContext, relative: string): string;
|
|
13
|
+
export declare function relative(context: FoundryRuntimeContext, file: string): string;
|
|
14
|
+
export declare function readTaskBytes(context: FoundryRuntimeContext, file: string, limit?: number): Buffer;
|
|
15
|
+
export declare function readTaskJson(context: FoundryRuntimeContext, file: string): JsonRecord;
|
|
16
|
+
export declare function reference(value: unknown, expectedPath?: string): FileReference;
|
|
17
|
+
export declare function facts(value: unknown): FoundryInputFact[];
|
|
18
|
+
export declare function sameFact(left: FoundryInputFact, right: FoundryInputFact): boolean;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { FoundryContextError, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
5
|
+
export const shaPattern = /^[0-9a-f]{64}$/u;
|
|
6
|
+
export const maxDocumentBytes = 8 * 1024 * 1024;
|
|
7
|
+
export const maxIndexBytes = 64 * 1024 * 1024;
|
|
8
|
+
export function fail(code, message) {
|
|
9
|
+
throw new FoundryContextError(code, message);
|
|
10
|
+
}
|
|
11
|
+
export function object(value) {
|
|
12
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
13
|
+
fail("task_document_invalid", "Task document must be a JSON object.");
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
export function exact(value, keys) {
|
|
17
|
+
if (Object.keys(value).length !== keys.length || keys.some((key) => !Object.hasOwn(value, key)))
|
|
18
|
+
fail("task_document_invalid", "Task document has missing or unsupported fields.");
|
|
19
|
+
}
|
|
20
|
+
export function timestamp(value) {
|
|
21
|
+
return (typeof value === "string" &&
|
|
22
|
+
Number.isFinite(Date.parse(value)) &&
|
|
23
|
+
new Date(value).toISOString() === value);
|
|
24
|
+
}
|
|
25
|
+
export function bytes(value) {
|
|
26
|
+
return Buffer.from(`${JSON.stringify(value, null, 2)}\n`);
|
|
27
|
+
}
|
|
28
|
+
export function digest(value) {
|
|
29
|
+
return createHash("sha256").update(value).digest("hex");
|
|
30
|
+
}
|
|
31
|
+
export function taskPath(context, relative) {
|
|
32
|
+
return resolveFoundryOutput(context, relative);
|
|
33
|
+
}
|
|
34
|
+
export function relative(context, file) {
|
|
35
|
+
return path.relative(context.taskRoot, taskPath(context, file)).split(path.sep).join("/");
|
|
36
|
+
}
|
|
37
|
+
export function readTaskBytes(context, file, limit = maxDocumentBytes) {
|
|
38
|
+
const target = taskPath(context, file);
|
|
39
|
+
const stat = fs.lstatSync(target);
|
|
40
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > limit)
|
|
41
|
+
fail("task_document_invalid", "Task metadata must be a bounded regular file.");
|
|
42
|
+
const content = fs.readFileSync(target);
|
|
43
|
+
if (content.length > limit)
|
|
44
|
+
fail("task_document_invalid", "Task metadata changed beyond its limit while reading.");
|
|
45
|
+
return content;
|
|
46
|
+
}
|
|
47
|
+
export function readTaskJson(context, file) {
|
|
48
|
+
try {
|
|
49
|
+
return object(JSON.parse(readTaskBytes(context, file).toString("utf8")));
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error instanceof FoundryContextError)
|
|
53
|
+
throw error;
|
|
54
|
+
return fail("task_document_invalid", "Task metadata could not be read as complete JSON.");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function reference(value, expectedPath) {
|
|
58
|
+
const ref = object(value);
|
|
59
|
+
exact(ref, ["path", "sha256"]);
|
|
60
|
+
if (typeof ref.path !== "string" ||
|
|
61
|
+
!ref.path ||
|
|
62
|
+
path.isAbsolute(ref.path) ||
|
|
63
|
+
ref.path.split(/[\\/]/u).includes("..") ||
|
|
64
|
+
typeof ref.sha256 !== "string" ||
|
|
65
|
+
!shaPattern.test(ref.sha256) ||
|
|
66
|
+
(expectedPath && ref.path !== expectedPath))
|
|
67
|
+
fail("task_reference_invalid", "Task metadata references must be exact contained content facts.");
|
|
68
|
+
return { path: ref.path, sha256: ref.sha256 };
|
|
69
|
+
}
|
|
70
|
+
export function facts(value) {
|
|
71
|
+
if (!Array.isArray(value) || value.length > 100_000)
|
|
72
|
+
fail("task_inputs_invalid", "Task input facts must be a bounded array.");
|
|
73
|
+
const result = value.map((item) => {
|
|
74
|
+
const fact = object(item);
|
|
75
|
+
exact(fact, ["path", "bytes", "sha256"]);
|
|
76
|
+
if (typeof fact.path !== "string" ||
|
|
77
|
+
!fact.path ||
|
|
78
|
+
typeof fact.bytes !== "number" ||
|
|
79
|
+
!Number.isSafeInteger(fact.bytes) ||
|
|
80
|
+
fact.bytes < 0 ||
|
|
81
|
+
typeof fact.sha256 !== "string" ||
|
|
82
|
+
!shaPattern.test(fact.sha256))
|
|
83
|
+
fail("task_inputs_invalid", "Task file facts require path, size and SHA-256.");
|
|
84
|
+
return { path: fact.path, bytes: fact.bytes, sha256: fact.sha256 };
|
|
85
|
+
});
|
|
86
|
+
if (new Set(result.map((fact) => fact.path)).size !== result.length)
|
|
87
|
+
fail("task_inputs_invalid", "Task file facts must be unique.");
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
export function sameFact(left, right) {
|
|
91
|
+
return left.path === right.path && left.bytes === right.bytes && left.sha256 === right.sha256;
|
|
92
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { FoundryTaskOptions, LoadedTask } from "./foundry-task-types.ts";
|
|
3
|
+
export declare function requiredTask(context: FoundryRuntimeContext): void;
|
|
4
|
+
export declare function loadTask(context: FoundryRuntimeContext, options: FoundryTaskOptions): LoadedTask;
|
|
5
|
+
export declare function createTask(context: FoundryRuntimeContext, options: FoundryTaskOptions): LoadedTask;
|
|
6
|
+
export declare function bindAccountIntent(context: FoundryRuntimeContext): void;
|