@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,384 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { assertFoundryRuntimeContext, assertFoundryWorkspaceWrite, assertPendingFoundryTaskIntent, captureFoundryInput, resolveFoundryAsset, resolveFoundryOutput, writeFoundryArtifact, } from "./foundry-runtime-context.js";
|
|
5
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
6
|
+
import { fail, object, exact, timestamp, bytes, digest, taskPath, readTaskBytes, readTaskJson, reference, facts, sameFact, maxDocumentBytes, } from "./foundry-task-io.js";
|
|
7
|
+
const entityTypes = new Set([
|
|
8
|
+
"contact",
|
|
9
|
+
"source",
|
|
10
|
+
"support",
|
|
11
|
+
"flow",
|
|
12
|
+
"flowproperty",
|
|
13
|
+
"unitgroup",
|
|
14
|
+
"process",
|
|
15
|
+
"lifecyclemodel",
|
|
16
|
+
]);
|
|
17
|
+
function runtimeIdentity(context) {
|
|
18
|
+
return {
|
|
19
|
+
package_name: context.runtime.packageName,
|
|
20
|
+
package_version: context.runtime.packageVersion,
|
|
21
|
+
manifest_sha256: context.runtime.packageManifestSha256,
|
|
22
|
+
entry_sha256: context.runtime.entrySha256,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function profileLock(context, id) {
|
|
26
|
+
const file = resolveFoundryAsset(context, "specs/import-profiles.json");
|
|
27
|
+
const config = object(JSON.parse(fs.readFileSync(file, "utf8")));
|
|
28
|
+
const profiles = object(config.profiles);
|
|
29
|
+
if (!Object.hasOwn(profiles, id))
|
|
30
|
+
fail("task_profile_unknown", "Task profile is not present in the executing runtime.");
|
|
31
|
+
const profile = object(profiles[id]);
|
|
32
|
+
return {
|
|
33
|
+
schema: "tiangong-foundry.profile-lock.v2",
|
|
34
|
+
profile_id: id,
|
|
35
|
+
profile_sha256: sha256Json(profile),
|
|
36
|
+
profile,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function requiredTask(context) {
|
|
40
|
+
assertFoundryRuntimeContext(context);
|
|
41
|
+
if (!context.workspaceId || !context.taskId || !context.taskRoot || !context.actorId)
|
|
42
|
+
fail("task_context_required", "Task storage requires initialized workspace, task and actor intent.");
|
|
43
|
+
}
|
|
44
|
+
function registrationPath(context) {
|
|
45
|
+
return resolveFoundryOutput(context, `task-registrations/${context.taskId}.json`, "state");
|
|
46
|
+
}
|
|
47
|
+
function readRegistration(context) {
|
|
48
|
+
const file = registrationPath(context);
|
|
49
|
+
if (!fs.existsSync(file))
|
|
50
|
+
return null;
|
|
51
|
+
const stat = fs.lstatSync(file);
|
|
52
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 3 * maxDocumentBytes)
|
|
53
|
+
fail("task_registration_invalid", "Task registration must be a bounded regular record.");
|
|
54
|
+
let value;
|
|
55
|
+
try {
|
|
56
|
+
value = object(JSON.parse(fs.readFileSync(file, "utf8")));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
fail("task_registration_invalid", "Task registration is malformed.");
|
|
60
|
+
}
|
|
61
|
+
exact(value, [
|
|
62
|
+
"schema",
|
|
63
|
+
"job",
|
|
64
|
+
"source_manifest",
|
|
65
|
+
"profile_lock",
|
|
66
|
+
"seed_manifest",
|
|
67
|
+
"registration_sha256",
|
|
68
|
+
]);
|
|
69
|
+
const { registration_sha256: checksum, ...payload } = value;
|
|
70
|
+
if (value.schema !== "tiangong-foundry.task-registration.v1" || checksum !== sha256Json(payload))
|
|
71
|
+
fail("task_registration_invalid", "Task registration content changed.");
|
|
72
|
+
const job = object(value.job);
|
|
73
|
+
if (job.workspace_id !== context.workspaceId || job.task_id !== context.taskId)
|
|
74
|
+
fail("task_binding_mismatch", "Registered task belongs to another workspace or task.");
|
|
75
|
+
if (job.actor_id !== context.actorId)
|
|
76
|
+
fail("task_actor_mismatch", "Task actor does not match the registered task intent.");
|
|
77
|
+
if (context.workspaceAccess === "write" &&
|
|
78
|
+
sha256Json(job.runtime_identity) !== sha256Json(runtimeIdentity(context)))
|
|
79
|
+
fail("task_runtime_changed", "Task runtime differs from its registration.");
|
|
80
|
+
if (typeof job.target_profile !== "string" ||
|
|
81
|
+
(context.workspaceAccess === "write" &&
|
|
82
|
+
!bytes(value.profile_lock).equals(bytes(profileLock(context, job.target_profile)))))
|
|
83
|
+
fail("task_profile_changed", "Registered profile does not match current package rules.");
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
function writeStateOnce(context, relativePath, content) {
|
|
87
|
+
assertFoundryWorkspaceWrite(context);
|
|
88
|
+
const target = resolveFoundryOutput(context, relativePath, "state");
|
|
89
|
+
fs.mkdirSync(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
90
|
+
resolveFoundryOutput(context, target, "state");
|
|
91
|
+
if (fs.existsSync(target)) {
|
|
92
|
+
if (!fs.lstatSync(target).isFile() || !fs.readFileSync(target).equals(content))
|
|
93
|
+
fail("task_registration_conflict", "Existing task registration cannot be changed.");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const temp = `${target}.${randomUUID()}.tmp`;
|
|
97
|
+
const fd = fs.openSync(temp, "wx", 0o600);
|
|
98
|
+
try {
|
|
99
|
+
fs.writeFileSync(fd, content);
|
|
100
|
+
fs.fsyncSync(fd);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
fs.closeSync(fd);
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
fs.linkSync(temp, target);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
if (fs.existsSync(temp))
|
|
110
|
+
fs.unlinkSync(temp);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export function loadTask(context, options) {
|
|
114
|
+
const registration = readRegistration(context);
|
|
115
|
+
if (!registration)
|
|
116
|
+
fail("legacy_task_requires_migration", "An unregistered task cannot be adopted as current execution state.");
|
|
117
|
+
const raw = readTaskJson(context, "foundry-job.json");
|
|
118
|
+
exact(raw, [
|
|
119
|
+
"schema",
|
|
120
|
+
"workspace_id",
|
|
121
|
+
"task_id",
|
|
122
|
+
"actor_id",
|
|
123
|
+
"request_id",
|
|
124
|
+
"lane",
|
|
125
|
+
"target_profile",
|
|
126
|
+
"target_entities",
|
|
127
|
+
"source_manifest",
|
|
128
|
+
"profile_lock",
|
|
129
|
+
"seed_manifest",
|
|
130
|
+
"runtime_identity",
|
|
131
|
+
"write_policy",
|
|
132
|
+
"created_at_utc",
|
|
133
|
+
]);
|
|
134
|
+
if (raw.schema !== "tiangong-foundry.job.v2")
|
|
135
|
+
fail("legacy_task_requires_migration", "Existing task schema must be migrated explicitly.");
|
|
136
|
+
if (raw.workspace_id !== context.workspaceId || raw.task_id !== context.taskId)
|
|
137
|
+
fail("task_binding_mismatch", "Task storage belongs to another workspace or task.");
|
|
138
|
+
if (raw.actor_id !== context.actorId)
|
|
139
|
+
fail("task_actor_mismatch", "Task actor does not match the stored task intent.");
|
|
140
|
+
if (!bytes(raw).equals(bytes(registration.job)))
|
|
141
|
+
fail("task_snapshot_changed", "Task job differs from its immutable workspace registration.");
|
|
142
|
+
if (typeof raw.request_id !== "string" ||
|
|
143
|
+
!raw.request_id ||
|
|
144
|
+
!timestamp(raw.created_at_utc) ||
|
|
145
|
+
!["external-dataset-curated-import", "source-evidence-dataset-development"].includes(String(raw.lane)) ||
|
|
146
|
+
typeof raw.target_profile !== "string" ||
|
|
147
|
+
!Array.isArray(raw.target_entities) ||
|
|
148
|
+
!raw.target_entities.length ||
|
|
149
|
+
raw.target_entities.some((kind) => typeof kind !== "string" || !entityTypes.has(kind)))
|
|
150
|
+
fail("task_document_invalid", "Task job metadata is malformed.");
|
|
151
|
+
if ((options.requestId && options.requestId !== raw.request_id) ||
|
|
152
|
+
(options.lane && options.lane !== raw.lane) ||
|
|
153
|
+
(options.profileId && options.profileId !== raw.target_profile) ||
|
|
154
|
+
options.targetEntities?.some((kind) => !raw.target_entities.includes(kind)))
|
|
155
|
+
fail("task_request_mismatch", "Task request, lane, profile or entity scope changed.");
|
|
156
|
+
if (sha256Json(raw.runtime_identity) !== sha256Json(runtimeIdentity(context)))
|
|
157
|
+
fail("task_runtime_changed", "Task runtime identity changed; use the pinned runtime or an explicit migration.");
|
|
158
|
+
if (sha256Json(raw.write_policy) !== sha256Json({ mode: "dry-run", remote_state_code: 0 }))
|
|
159
|
+
fail("task_write_policy_invalid", "Task metadata cannot grant remote write authority.");
|
|
160
|
+
const sourceRef = reference(raw.source_manifest, "source-manifest.json");
|
|
161
|
+
const profileRef = reference(raw.profile_lock, "profile-lock.json");
|
|
162
|
+
const sourceBytes = readTaskBytes(context, sourceRef.path);
|
|
163
|
+
const lockedBytes = readTaskBytes(context, profileRef.path);
|
|
164
|
+
if (digest(sourceBytes) !== sourceRef.sha256 || digest(lockedBytes) !== profileRef.sha256)
|
|
165
|
+
fail("task_snapshot_changed", "Task source or profile snapshot bytes changed.");
|
|
166
|
+
const source = object(JSON.parse(sourceBytes.toString("utf8")));
|
|
167
|
+
exact(source, ["schema", "workspace_id", "task_id", "source_kind", "source_paths"]);
|
|
168
|
+
if (source.schema !== "tiangong-foundry.source-manifest.v2" ||
|
|
169
|
+
source.workspace_id !== context.workspaceId ||
|
|
170
|
+
source.task_id !== context.taskId ||
|
|
171
|
+
source.source_kind !== "selected-local-files")
|
|
172
|
+
fail("task_source_invalid", "Source manifest does not match this task.");
|
|
173
|
+
const sourceFacts = facts(source.source_paths);
|
|
174
|
+
if (sourceFacts.some((fact) => !path.isAbsolute(fact.path)))
|
|
175
|
+
fail("task_source_invalid", "Original source paths must be canonical absolute selections.");
|
|
176
|
+
if (!lockedBytes.equals(bytes(profileLock(context, raw.target_profile))))
|
|
177
|
+
fail("task_profile_changed", "Current profile rules differ from the immutable task lock.");
|
|
178
|
+
if (raw.seed_manifest !== null) {
|
|
179
|
+
const seedRef = reference(raw.seed_manifest, "seed-manifest.json");
|
|
180
|
+
if (digest(readTaskBytes(context, seedRef.path)) !== seedRef.sha256)
|
|
181
|
+
fail("task_snapshot_changed", "Seed manifest bytes changed.");
|
|
182
|
+
}
|
|
183
|
+
else if (raw.lane === "source-evidence-dataset-development")
|
|
184
|
+
fail("task_seed_required", "Source-evidence authoring requires its frozen seed manifest.");
|
|
185
|
+
const publicationPath = resolveFoundryOutput(context, `task-publications/${context.taskId}.json`, "state");
|
|
186
|
+
const publication = bytes({
|
|
187
|
+
schema: "tiangong-foundry.task-publication.v1",
|
|
188
|
+
workspace_id: context.workspaceId,
|
|
189
|
+
task_id: context.taskId,
|
|
190
|
+
job_sha256: digest(bytes(registration.job)),
|
|
191
|
+
});
|
|
192
|
+
if (fs.existsSync(publicationPath)) {
|
|
193
|
+
if (!fs.lstatSync(publicationPath).isFile() ||
|
|
194
|
+
!fs.readFileSync(publicationPath).equals(publication))
|
|
195
|
+
fail("task_publication_changed", "Task publication evidence changed.");
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const allowed = new Set([
|
|
199
|
+
"foundry-job.json",
|
|
200
|
+
"source-manifest.json",
|
|
201
|
+
"profile-lock.json",
|
|
202
|
+
"artifact-index.jsonl",
|
|
203
|
+
...(raw.seed_manifest ? ["seed-manifest.json"] : []),
|
|
204
|
+
]);
|
|
205
|
+
if (fs.readdirSync(context.taskRoot).some((name) => !allowed.has(name)) ||
|
|
206
|
+
readTaskBytes(context, "artifact-index.jsonl").length > 0)
|
|
207
|
+
fail("task_initialization_ambiguous", "Missing task publication evidence cannot be repaired over existing operation or attempt state.");
|
|
208
|
+
writeStateOnce(context, `task-publications/${context.taskId}.json`, publication);
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
job: raw,
|
|
212
|
+
jobSha256: digest(readTaskBytes(context, "foundry-job.json")),
|
|
213
|
+
sources: sourceFacts,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
export function createTask(context, options) {
|
|
217
|
+
assertFoundryWorkspaceWrite(context);
|
|
218
|
+
assertPendingFoundryTaskIntent(context, context.taskId, options.requestId ?? context.taskId, context.actorId);
|
|
219
|
+
const target = context.taskRoot;
|
|
220
|
+
if (fs.existsSync(resolveFoundryOutput(context, `task-publications/${context.taskId}.json`, "state")))
|
|
221
|
+
fail("task_state_missing", "Published task state is missing; restore or audit it rather than resetting its ledger.");
|
|
222
|
+
if (fs.existsSync(target))
|
|
223
|
+
fail("legacy_task_requires_migration", "An existing unversioned task directory cannot be adopted or overwritten.");
|
|
224
|
+
for (const fact of context.inputs)
|
|
225
|
+
if (!sameFact(captureFoundryInput(fact.path), fact))
|
|
226
|
+
fail("input_changed", "Selected source changed before task creation.");
|
|
227
|
+
const lane = options.lane ?? "external-dataset-curated-import";
|
|
228
|
+
const profileId = options.profileId ?? "generic";
|
|
229
|
+
if (!["external-dataset-curated-import", "source-evidence-dataset-development"].includes(lane) ||
|
|
230
|
+
(options.requestId !== undefined &&
|
|
231
|
+
(typeof options.requestId !== "string" ||
|
|
232
|
+
!options.requestId ||
|
|
233
|
+
options.requestId.length > 256)))
|
|
234
|
+
fail("task_request_invalid", "Task lane and request identity are invalid.");
|
|
235
|
+
const targets = [...new Set(options.targetEntities ?? ["flow", "process", "support"])];
|
|
236
|
+
if (!targets.length || targets.some((kind) => !entityTypes.has(kind)))
|
|
237
|
+
fail("task_entities_invalid", "Task target entity types are invalid.");
|
|
238
|
+
if (lane === "source-evidence-dataset-development" && !options.seed)
|
|
239
|
+
fail("task_seed_required", "Source-evidence authoring requires a seed manifest.");
|
|
240
|
+
let source = {
|
|
241
|
+
schema: "tiangong-foundry.source-manifest.v2",
|
|
242
|
+
workspace_id: context.workspaceId,
|
|
243
|
+
task_id: context.taskId,
|
|
244
|
+
source_kind: "selected-local-files",
|
|
245
|
+
source_paths: context.inputs.map((fact) => ({ ...fact })),
|
|
246
|
+
};
|
|
247
|
+
let locked = profileLock(context, profileId);
|
|
248
|
+
let seed = options.seed ?? null;
|
|
249
|
+
let sourceBytes = bytes(source);
|
|
250
|
+
let profileBytes = bytes(locked);
|
|
251
|
+
let seedBytes = seed ? bytes(seed) : null;
|
|
252
|
+
let job = {
|
|
253
|
+
schema: "tiangong-foundry.job.v2",
|
|
254
|
+
workspace_id: context.workspaceId,
|
|
255
|
+
task_id: context.taskId,
|
|
256
|
+
actor_id: context.actorId,
|
|
257
|
+
request_id: options.requestId ?? context.taskId,
|
|
258
|
+
lane,
|
|
259
|
+
target_profile: profileId,
|
|
260
|
+
target_entities: targets,
|
|
261
|
+
source_manifest: { path: "source-manifest.json", sha256: digest(sourceBytes) },
|
|
262
|
+
profile_lock: { path: "profile-lock.json", sha256: digest(profileBytes) },
|
|
263
|
+
seed_manifest: seedBytes ? { path: "seed-manifest.json", sha256: digest(seedBytes) } : null,
|
|
264
|
+
runtime_identity: runtimeIdentity(context),
|
|
265
|
+
write_policy: { mode: "dry-run", remote_state_code: 0 },
|
|
266
|
+
created_at_utc: new Date().toISOString(),
|
|
267
|
+
};
|
|
268
|
+
const registered = readRegistration(context);
|
|
269
|
+
if (registered) {
|
|
270
|
+
if (sha256Json(registered.source_manifest) !== sha256Json(source) ||
|
|
271
|
+
registered.job.target_profile !== profileId ||
|
|
272
|
+
registered.job.lane !== lane ||
|
|
273
|
+
sha256Json(registered.job.target_entities) !== sha256Json(targets) ||
|
|
274
|
+
registered.job.request_id !== job.request_id ||
|
|
275
|
+
sha256Json(registered.seed_manifest) !== sha256Json(seed))
|
|
276
|
+
fail("task_initialization_mismatch", "Interrupted task initialization requires the same original intent and input scope.");
|
|
277
|
+
job = registered.job;
|
|
278
|
+
source = registered.source_manifest;
|
|
279
|
+
locked = registered.profile_lock;
|
|
280
|
+
seed = registered.seed_manifest;
|
|
281
|
+
sourceBytes = bytes(source);
|
|
282
|
+
profileBytes = bytes(locked);
|
|
283
|
+
seedBytes = seed ? bytes(seed) : null;
|
|
284
|
+
}
|
|
285
|
+
if ([sourceBytes, profileBytes, bytes(job), ...(seedBytes ? [seedBytes] : [])].some((content) => content.length > maxDocumentBytes))
|
|
286
|
+
fail("task_document_limit", "Task metadata exceeds its bounded document limit.");
|
|
287
|
+
const staging = resolveFoundryOutput(context, `task-initialization/${context.taskId}-${randomUUID()}`, "state");
|
|
288
|
+
fs.mkdirSync(staging, { recursive: true, mode: 0o700 });
|
|
289
|
+
const documents = [
|
|
290
|
+
["source-manifest.json", sourceBytes],
|
|
291
|
+
["profile-lock.json", profileBytes],
|
|
292
|
+
["foundry-job.json", bytes(job)],
|
|
293
|
+
["artifact-index.jsonl", Buffer.alloc(0)],
|
|
294
|
+
];
|
|
295
|
+
if (seedBytes)
|
|
296
|
+
documents.push(["seed-manifest.json", seedBytes]);
|
|
297
|
+
for (const [name, content] of documents) {
|
|
298
|
+
const fd = fs.openSync(path.join(staging, name), "wx", 0o600);
|
|
299
|
+
try {
|
|
300
|
+
fs.writeFileSync(fd, content);
|
|
301
|
+
fs.fsyncSync(fd);
|
|
302
|
+
}
|
|
303
|
+
finally {
|
|
304
|
+
fs.closeSync(fd);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const registration = {
|
|
308
|
+
schema: "tiangong-foundry.task-registration.v1",
|
|
309
|
+
job,
|
|
310
|
+
source_manifest: source,
|
|
311
|
+
profile_lock: locked,
|
|
312
|
+
seed_manifest: seed,
|
|
313
|
+
};
|
|
314
|
+
writeStateOnce(context, `task-registrations/${context.taskId}.json`, bytes({ ...registration, registration_sha256: sha256Json(registration) }));
|
|
315
|
+
taskPath(context, target);
|
|
316
|
+
if (fs.existsSync(target))
|
|
317
|
+
fail("task_creation_conflict", "A task appeared during initialization; preserve both records and revalidate.");
|
|
318
|
+
fs.mkdirSync(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
319
|
+
taskPath(context, target);
|
|
320
|
+
fs.renameSync(staging, target);
|
|
321
|
+
return loadTask(context, options);
|
|
322
|
+
}
|
|
323
|
+
export function bindAccountIntent(context) {
|
|
324
|
+
const taskFile = taskPath(context, "account-intent.json");
|
|
325
|
+
const statePath = resolveFoundryOutput(context, `task-accounts/${context.taskId}.json`, "state");
|
|
326
|
+
const intent = context.accountIntent;
|
|
327
|
+
let registered = null;
|
|
328
|
+
if (fs.existsSync(statePath)) {
|
|
329
|
+
const stat = fs.lstatSync(statePath);
|
|
330
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 64 * 1024)
|
|
331
|
+
fail("task_account_invalid", "Task account registration is not a bounded regular file.");
|
|
332
|
+
registered = fs.readFileSync(statePath);
|
|
333
|
+
let stored;
|
|
334
|
+
try {
|
|
335
|
+
stored = object(JSON.parse(registered.toString("utf8")));
|
|
336
|
+
}
|
|
337
|
+
catch {
|
|
338
|
+
fail("task_account_invalid", "Task account registration is malformed.");
|
|
339
|
+
}
|
|
340
|
+
exact(stored, [
|
|
341
|
+
"schema",
|
|
342
|
+
"workspace_id",
|
|
343
|
+
"task_id",
|
|
344
|
+
"project_ref",
|
|
345
|
+
"user_id",
|
|
346
|
+
...(Object.hasOwn(stored, "account_mode") ? ["account_mode"] : []),
|
|
347
|
+
]);
|
|
348
|
+
if (stored.schema !== "tiangong-foundry.account-intent.v1" ||
|
|
349
|
+
stored.workspace_id !== context.workspaceId ||
|
|
350
|
+
stored.task_id !== context.taskId ||
|
|
351
|
+
typeof stored.project_ref !== "string" ||
|
|
352
|
+
!/^[a-z0-9]{20}$/u.test(stored.project_ref) ||
|
|
353
|
+
typeof stored.user_id !== "string" ||
|
|
354
|
+
(Object.hasOwn(stored, "account_mode") &&
|
|
355
|
+
stored.account_mode !== "ordinary" &&
|
|
356
|
+
stored.account_mode !== "production-test") ||
|
|
357
|
+
!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u.test(stored.user_id))
|
|
358
|
+
fail("task_account_invalid", "Task account registration does not match this task.");
|
|
359
|
+
if (intent &&
|
|
360
|
+
(stored.project_ref !== intent.projectRef ||
|
|
361
|
+
stored.user_id !== intent.userId ||
|
|
362
|
+
(stored.account_mode ?? "ordinary") !== (intent.accountMode ?? "ordinary")))
|
|
363
|
+
fail("task_account_mismatch", "Task account intent cannot change implicitly.");
|
|
364
|
+
}
|
|
365
|
+
else if (intent) {
|
|
366
|
+
registered = bytes({
|
|
367
|
+
schema: "tiangong-foundry.account-intent.v1",
|
|
368
|
+
workspace_id: context.workspaceId,
|
|
369
|
+
task_id: context.taskId,
|
|
370
|
+
project_ref: intent.projectRef,
|
|
371
|
+
user_id: intent.userId,
|
|
372
|
+
...(intent.accountMode ? { account_mode: intent.accountMode } : {}),
|
|
373
|
+
});
|
|
374
|
+
writeStateOnce(context, `task-accounts/${context.taskId}.json`, registered);
|
|
375
|
+
}
|
|
376
|
+
if (fs.existsSync(taskFile)) {
|
|
377
|
+
if (!registered || !registered.equals(readTaskBytes(context, taskFile)))
|
|
378
|
+
fail("task_account_changed", "Task account intent differs from its workspace registration.");
|
|
379
|
+
}
|
|
380
|
+
else if (registered) {
|
|
381
|
+
// Complete only this already registered account binding after an interrupted local write.
|
|
382
|
+
writeFoundryArtifact(context, taskFile, registered);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FoundryInputFact } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { Lane } from "./foundry-task-types.ts";
|
|
3
|
+
export declare const FOUNDRY_TASK_START_SPEC_SCHEMA: "tiangong-foundry.task-start.v1";
|
|
4
|
+
interface SourceSelection {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
}
|
|
7
|
+
interface AccountIntentSelection {
|
|
8
|
+
readonly project_ref: string;
|
|
9
|
+
readonly user_id: string;
|
|
10
|
+
readonly session_reference: string | null;
|
|
11
|
+
readonly account_mode?: "ordinary" | "production-test";
|
|
12
|
+
}
|
|
13
|
+
interface CleanupPreparation {
|
|
14
|
+
readonly operation: "dataset-curation-cleanup";
|
|
15
|
+
readonly type: string;
|
|
16
|
+
readonly input: string;
|
|
17
|
+
readonly source_input: string | null;
|
|
18
|
+
readonly output_directory: string;
|
|
19
|
+
}
|
|
20
|
+
export interface FoundryTaskStartSpec {
|
|
21
|
+
readonly schema: typeof FOUNDRY_TASK_START_SPEC_SCHEMA;
|
|
22
|
+
readonly request_id: string;
|
|
23
|
+
readonly actor_id: string;
|
|
24
|
+
readonly lane: Lane;
|
|
25
|
+
readonly profile_id: string;
|
|
26
|
+
readonly target_entities: readonly string[];
|
|
27
|
+
readonly sources: readonly Readonly<SourceSelection>[];
|
|
28
|
+
readonly seed: Readonly<SourceSelection> | null;
|
|
29
|
+
readonly account_intent: Readonly<AccountIntentSelection> | null;
|
|
30
|
+
readonly preparation: Readonly<CleanupPreparation> | null;
|
|
31
|
+
}
|
|
32
|
+
export declare function parseFoundryTaskStartSpec(value: unknown): FoundryTaskStartSpec;
|
|
33
|
+
export declare function taskStartSpecFingerprint(spec: FoundryTaskStartSpec, inputs: readonly FoundryInputFact[]): string;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { FoundryContextError } from "./foundry-runtime-context.js";
|
|
3
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
4
|
+
export const FOUNDRY_TASK_START_SPEC_SCHEMA = "tiangong-foundry.task-start.v1";
|
|
5
|
+
const idPattern = /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u;
|
|
6
|
+
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
|
|
7
|
+
const entityTypes = new Set([
|
|
8
|
+
"contact",
|
|
9
|
+
"source",
|
|
10
|
+
"support",
|
|
11
|
+
"flow",
|
|
12
|
+
"flowproperty",
|
|
13
|
+
"unitgroup",
|
|
14
|
+
"process",
|
|
15
|
+
"lifecyclemodel",
|
|
16
|
+
]);
|
|
17
|
+
function fail(code, message) {
|
|
18
|
+
throw new FoundryContextError(code, message);
|
|
19
|
+
}
|
|
20
|
+
function record(value, label) {
|
|
21
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
22
|
+
fail("task_spec_invalid", `${label} must be an object.`);
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function exact(value, keys, label) {
|
|
26
|
+
if (Object.keys(value).length !== keys.length || keys.some((key) => !Object.hasOwn(value, key)))
|
|
27
|
+
fail("task_spec_invalid", `${label} has missing or unsupported fields.`);
|
|
28
|
+
}
|
|
29
|
+
function selectedPath(value, label) {
|
|
30
|
+
if (typeof value !== "string" ||
|
|
31
|
+
!value ||
|
|
32
|
+
value.length > 4_096 ||
|
|
33
|
+
/[\0\r\n]/u.test(value) ||
|
|
34
|
+
/^\.env(?:\.|$)/iu.test(path.basename(value)))
|
|
35
|
+
fail("task_spec_path_invalid", `${label} must be a bounded non-credential file path.`);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function selection(value, label) {
|
|
39
|
+
const item = record(value, label);
|
|
40
|
+
exact(item, ["path"], label);
|
|
41
|
+
return Object.freeze({ path: selectedPath(item.path, `${label} path`) });
|
|
42
|
+
}
|
|
43
|
+
function account(value) {
|
|
44
|
+
if (value === null)
|
|
45
|
+
return null;
|
|
46
|
+
const item = record(value, "Account intent");
|
|
47
|
+
exact(item, [
|
|
48
|
+
"project_ref",
|
|
49
|
+
"user_id",
|
|
50
|
+
"session_reference",
|
|
51
|
+
...(Object.hasOwn(item, "account_mode") ? ["account_mode"] : []),
|
|
52
|
+
], "Account intent");
|
|
53
|
+
if (Object.hasOwn(item, "account_mode") &&
|
|
54
|
+
item.account_mode !== "ordinary" &&
|
|
55
|
+
item.account_mode !== "production-test")
|
|
56
|
+
fail("task_spec_account_invalid", "Account verification mode must be ordinary or production-test.");
|
|
57
|
+
if (typeof item.project_ref !== "string" ||
|
|
58
|
+
!/^[a-z0-9]{20}$/u.test(item.project_ref) ||
|
|
59
|
+
typeof item.user_id !== "string" ||
|
|
60
|
+
!uuidPattern.test(item.user_id) ||
|
|
61
|
+
(item.session_reference !== null &&
|
|
62
|
+
(typeof item.session_reference !== "string" || !path.isAbsolute(item.session_reference))))
|
|
63
|
+
fail("task_spec_account_invalid", "Account intent requires exact project/user identifiers.");
|
|
64
|
+
return Object.freeze({
|
|
65
|
+
project_ref: item.project_ref,
|
|
66
|
+
user_id: item.user_id,
|
|
67
|
+
session_reference: item.session_reference,
|
|
68
|
+
...(item.account_mode
|
|
69
|
+
? { account_mode: item.account_mode }
|
|
70
|
+
: {}),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function preparation(value, sources) {
|
|
74
|
+
if (value === null)
|
|
75
|
+
return null;
|
|
76
|
+
const item = record(value, "Preparation");
|
|
77
|
+
exact(item, ["operation", "type", "input", "source_input", "output_directory"], "Preparation");
|
|
78
|
+
const input = selectedPath(item.input, "Preparation input");
|
|
79
|
+
const sourceInput = item.source_input === null ? null : selectedPath(item.source_input, "Preparation source input");
|
|
80
|
+
if (item.operation !== "dataset-curation-cleanup" ||
|
|
81
|
+
typeof item.type !== "string" ||
|
|
82
|
+
!entityTypes.has(item.type) ||
|
|
83
|
+
!sources.some((source) => source.path === input) ||
|
|
84
|
+
(sourceInput !== null && !sources.some((source) => source.path === sourceInput)) ||
|
|
85
|
+
typeof item.output_directory !== "string" ||
|
|
86
|
+
!item.output_directory ||
|
|
87
|
+
path.isAbsolute(item.output_directory) ||
|
|
88
|
+
item.output_directory.split(/[\\/]/u).some((part) => !part || part === "." || part === ".."))
|
|
89
|
+
fail("task_spec_preparation_invalid", "Preparation must select declared inputs and one contained cleanup output.");
|
|
90
|
+
return Object.freeze({
|
|
91
|
+
operation: "dataset-curation-cleanup",
|
|
92
|
+
type: item.type,
|
|
93
|
+
input,
|
|
94
|
+
source_input: sourceInput,
|
|
95
|
+
output_directory: item.output_directory,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
export function parseFoundryTaskStartSpec(value) {
|
|
99
|
+
const item = record(value, "Task-start spec");
|
|
100
|
+
exact(item, [
|
|
101
|
+
"schema",
|
|
102
|
+
"request_id",
|
|
103
|
+
"actor_id",
|
|
104
|
+
"lane",
|
|
105
|
+
"profile_id",
|
|
106
|
+
"target_entities",
|
|
107
|
+
"sources",
|
|
108
|
+
"seed",
|
|
109
|
+
"account_intent",
|
|
110
|
+
"preparation",
|
|
111
|
+
], "Task-start spec");
|
|
112
|
+
if (item.schema !== FOUNDRY_TASK_START_SPEC_SCHEMA ||
|
|
113
|
+
typeof item.request_id !== "string" ||
|
|
114
|
+
!idPattern.test(item.request_id) ||
|
|
115
|
+
typeof item.actor_id !== "string" ||
|
|
116
|
+
!idPattern.test(item.actor_id) ||
|
|
117
|
+
!["external-dataset-curated-import", "source-evidence-dataset-development"].includes(String(item.lane)) ||
|
|
118
|
+
typeof item.profile_id !== "string" ||
|
|
119
|
+
!idPattern.test(item.profile_id) ||
|
|
120
|
+
!Array.isArray(item.target_entities) ||
|
|
121
|
+
!item.target_entities.length ||
|
|
122
|
+
item.target_entities.length > entityTypes.size ||
|
|
123
|
+
new Set(item.target_entities).size !== item.target_entities.length ||
|
|
124
|
+
item.target_entities.some((type) => typeof type !== "string" || !entityTypes.has(type)) ||
|
|
125
|
+
!Array.isArray(item.sources) ||
|
|
126
|
+
!item.sources.length ||
|
|
127
|
+
item.sources.length > 1_000)
|
|
128
|
+
fail("task_spec_invalid", "Task-start identity, lane, profile or entity scope is invalid.");
|
|
129
|
+
const sources = item.sources.map((source, index) => selection(source, `Source ${index + 1}`));
|
|
130
|
+
if (new Set(sources.map((source) => source.path)).size !== sources.length)
|
|
131
|
+
fail("task_spec_source_duplicate", "Task source selections must be unique.");
|
|
132
|
+
const seed = item.seed === null ? null : selection(item.seed, "Seed");
|
|
133
|
+
if (seed && !sources.some((source) => source.path === seed.path))
|
|
134
|
+
fail("task_seed_invalid", "Task seed must be one of the independently selected sources.");
|
|
135
|
+
if (item.lane === "source-evidence-dataset-development" && !seed)
|
|
136
|
+
fail("task_seed_required", "Source-evidence authoring requires one selected JSON seed file.");
|
|
137
|
+
const spec = {
|
|
138
|
+
schema: FOUNDRY_TASK_START_SPEC_SCHEMA,
|
|
139
|
+
request_id: item.request_id,
|
|
140
|
+
actor_id: item.actor_id,
|
|
141
|
+
lane: item.lane,
|
|
142
|
+
profile_id: item.profile_id,
|
|
143
|
+
target_entities: Object.freeze([...item.target_entities]),
|
|
144
|
+
sources: Object.freeze(sources),
|
|
145
|
+
seed,
|
|
146
|
+
account_intent: account(item.account_intent),
|
|
147
|
+
preparation: preparation(item.preparation, sources),
|
|
148
|
+
};
|
|
149
|
+
return Object.freeze(spec);
|
|
150
|
+
}
|
|
151
|
+
export function taskStartSpecFingerprint(spec, inputs) {
|
|
152
|
+
const parsed = parseFoundryTaskStartSpec(spec);
|
|
153
|
+
if (inputs.length !== parsed.sources.length ||
|
|
154
|
+
inputs.some((fact) => !path.isAbsolute(fact.path) ||
|
|
155
|
+
!Number.isSafeInteger(fact.bytes) ||
|
|
156
|
+
fact.bytes < 0 ||
|
|
157
|
+
!/^[0-9a-f]{64}$/u.test(fact.sha256)) ||
|
|
158
|
+
new Set(inputs.map((fact) => fact.path)).size !== inputs.length)
|
|
159
|
+
fail("task_spec_input_facts_invalid", "Task fingerprint requires exact selected input facts.");
|
|
160
|
+
return sha256Json({ spec: parsed, inputs: inputs.map((fact) => ({ ...fact })) });
|
|
161
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext, type FoundryInputFact } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { JsonRecord, ArtifactEntry, LoadedTask, FoundryTaskOptions, FoundryTaskOperation } from "./foundry-task-types.ts";
|
|
3
|
+
export type { FoundryTaskOptions, FoundryTaskOperation, FoundryTaskJob, } from "./foundry-task-types.ts";
|
|
4
|
+
export declare function withFoundryTaskMetadata<T>(context: FoundryRuntimeContext, inspect: (task: LoadedTask, index: readonly ArtifactEntry[]) => T, options?: {
|
|
5
|
+
verifyCommands?: readonly string[];
|
|
6
|
+
}): Promise<T>;
|
|
7
|
+
/** Prove a selected derived input descends from a selected approved input in the same verified index. */
|
|
8
|
+
export declare function assertFoundryTaskInputLineage(context: FoundryRuntimeContext, ancestorFile: string, derivedFile: string): Promise<Readonly<{
|
|
9
|
+
ancestor: FoundryInputFact;
|
|
10
|
+
derived: FoundryInputFact;
|
|
11
|
+
}>>;
|
|
12
|
+
/** Short local preparation transaction. Remote mutation/batch execution must not use this replay path. */
|
|
13
|
+
export declare function runFoundryTaskOperation(context: FoundryRuntimeContext, input: {
|
|
14
|
+
command: "dataset-curation-cleanup" | "dataset-tidas-import" | "dataset-context-pack" | "dataset-workflow-rows" | "dataset-workflow-assessment" | "dataset-workflow-identity" | "dataset-workflow-finalize" | "dataset-workflow-authorization" | "dataset-workflow-execution-prepare" | "dataset-workflow-execution-result" | "dataset-workflow-execution-consume" | "dataset-workflow-execution-observation" | "dataset-workflow-reference-verify" | "dataset-semantic-apply";
|
|
15
|
+
options: JsonRecord;
|
|
16
|
+
task?: FoundryTaskOptions;
|
|
17
|
+
validateCurrent?: (index: readonly ArtifactEntry[]) => void;
|
|
18
|
+
}, operation: (transaction: FoundryTaskOperation) => JsonRecord): Promise<JsonRecord>;
|