@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,367 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { FoundryContextError, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
4
|
+
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
5
|
+
import { assertSelectedSemanticInput, readSelectedSemanticBytes, } from "./foundry-semantic-input.js";
|
|
6
|
+
import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./foundry-workflow-state.js";
|
|
7
|
+
import { runFoundryTaskOperation } from "./foundry-task-store.js";
|
|
8
|
+
import { createWorkflowStageDirectory, createWorkflowDirectory, registerWorkflowStageFiles, runWorkflowLocalCliResult, } from "./foundry-workflow-io.js";
|
|
9
|
+
import { runDatasetAuthoringPatchCollect } from "./import-curation/patch-collect.js";
|
|
10
|
+
import { readJsonOrJsonl, ensureArray, readRows } from "./import-curation/internal/runtime-io.js";
|
|
11
|
+
import { createFoundryDecisionOwners } from "./foundry-decision-owners.js";
|
|
12
|
+
import { applyFoundryIdentityDecisions } from "./foundry-workflow-identity-apply.js";
|
|
13
|
+
import { operationFullContextEvidenceBlockers, operationUsedContextKinds, patchPayloadPatchSets, patchSetOperations, taskRequiredContextKinds, } from "./import-curation/internal/workflow-authoring-tasks.js";
|
|
14
|
+
function fail(code, message) {
|
|
15
|
+
throw new FoundryContextError(code, message);
|
|
16
|
+
}
|
|
17
|
+
function text(value, label) {
|
|
18
|
+
if (typeof value !== "string" || !value)
|
|
19
|
+
fail("semantic_work_invalid", `${label} is missing.`);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
function priorApplication(context, entries, submission) {
|
|
23
|
+
for (const entry of [...entries].reverse()) {
|
|
24
|
+
if (entry.command !== "dataset-semantic-apply" ||
|
|
25
|
+
path.basename(entry.path) !== "semantic-result.json")
|
|
26
|
+
continue;
|
|
27
|
+
const value = readWorkflowArtifact(context, entry).value;
|
|
28
|
+
if (value.status === "completed" && value.submission_sha256 === submission.descriptor.sha256)
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
export async function applyFoundrySemanticInput(context, qualified, entries, submission) {
|
|
34
|
+
assertSelectedSemanticInput(submission);
|
|
35
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
36
|
+
const prior = priorApplication(context, entries, submission);
|
|
37
|
+
if (prior)
|
|
38
|
+
return prior;
|
|
39
|
+
const state = currentWorkflowState(context, entries);
|
|
40
|
+
if (!state.rows ||
|
|
41
|
+
!state.assessment ||
|
|
42
|
+
state.assessment.entry.sha256 !== submission.spec.assessment_sha256)
|
|
43
|
+
fail("semantic_assessment_mismatch", "Submit against the current assessed row version.");
|
|
44
|
+
const rows = state.rows, assessment = state.assessment;
|
|
45
|
+
const selected = new Map(submission.spec.submissions.map((part, index) => [
|
|
46
|
+
part.authoring_task_sha256,
|
|
47
|
+
{ part, fact: submission.files[index] },
|
|
48
|
+
]));
|
|
49
|
+
const used = new Set();
|
|
50
|
+
const decisionWork = [];
|
|
51
|
+
const work = [];
|
|
52
|
+
for (const set of assessment.value.sets) {
|
|
53
|
+
const manifestFile = text(set.authoring_manifest, "Authoring manifest");
|
|
54
|
+
const manifest = workflowObject(JSON.parse(readFoundryInput(context, manifestFile).toString("utf8")));
|
|
55
|
+
if (!Array.isArray(manifest.tasks))
|
|
56
|
+
fail("semantic_work_invalid", "Authoring tasks are missing.");
|
|
57
|
+
const tasks = [];
|
|
58
|
+
for (const raw of manifest.tasks) {
|
|
59
|
+
const task = workflowObject(raw), files = workflowObject(task.files);
|
|
60
|
+
const taskFile = path.resolve(assessment.value.owner_base, text(files.task_json, "Authoring task"));
|
|
61
|
+
const entry = entries.find((candidate) => resolveFoundryOutput(context, candidate.path) === taskFile);
|
|
62
|
+
if (!entry)
|
|
63
|
+
fail("semantic_work_unregistered", "Authoring work is not registered in this task.");
|
|
64
|
+
const chosen = selected.get(entry.sha256);
|
|
65
|
+
if (!chosen || chosen.part.kind !== "patch")
|
|
66
|
+
continue;
|
|
67
|
+
readFoundryInput(context, taskFile);
|
|
68
|
+
if (task.status !== "ready_for_ai_authoring" || Number(task.action_item_count ?? 0) < 1)
|
|
69
|
+
fail("semantic_work_not_patchable", "The selected item requires its dedicated decision owner or more context.");
|
|
70
|
+
if (used.has(entry.sha256))
|
|
71
|
+
fail("semantic_work_ambiguous", "A submitted work item is ambiguous.");
|
|
72
|
+
used.add(entry.sha256);
|
|
73
|
+
tasks.push({ task, sha: entry.sha256, fact: chosen.fact });
|
|
74
|
+
}
|
|
75
|
+
if (tasks.length)
|
|
76
|
+
work.push({ set, manifest, manifestFile, tasks });
|
|
77
|
+
for (const raw of Array.isArray(set.decisions) ? set.decisions : []) {
|
|
78
|
+
const decision = workflowObject(raw);
|
|
79
|
+
if (decision.kind !== "classification" &&
|
|
80
|
+
decision.kind !== "location" &&
|
|
81
|
+
decision.kind !== "identity")
|
|
82
|
+
continue;
|
|
83
|
+
const taskFile = text(decision.task, "Decision task");
|
|
84
|
+
const entry = entries.find((candidate) => resolveFoundryOutput(context, candidate.path) === taskFile);
|
|
85
|
+
if (!entry)
|
|
86
|
+
fail("semantic_work_unregistered", "Decision work is not registered.");
|
|
87
|
+
const chosen = selected.get(entry.sha256);
|
|
88
|
+
if (!chosen)
|
|
89
|
+
continue;
|
|
90
|
+
if (chosen.part.kind !== decision.kind || used.has(entry.sha256))
|
|
91
|
+
fail("semantic_work_mismatch", "Submission kind differs from the current decision owner.");
|
|
92
|
+
if (decision.status !== `ready_for_ai_${decision.kind}_decisions`)
|
|
93
|
+
fail("semantic_work_not_ready", "Decision work requires its missing context before submission.");
|
|
94
|
+
used.add(entry.sha256);
|
|
95
|
+
decisionWork.push({
|
|
96
|
+
kind: decision.kind,
|
|
97
|
+
type: text(set.type, "Dataset type"),
|
|
98
|
+
rows: text(set.rows, "Rows"),
|
|
99
|
+
task: taskFile,
|
|
100
|
+
queue: decision.kind === "identity" ? null : text(decision.queue, "Decision queue"),
|
|
101
|
+
sha: entry.sha256,
|
|
102
|
+
fact: chosen.fact,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (used.size !== selected.size)
|
|
107
|
+
fail("semantic_work_mismatch", "Every submitted digest must identify current registered authoring work.");
|
|
108
|
+
const rowOwners = new Set(work.map((group) => text(group.set.type, "Dataset type")));
|
|
109
|
+
if (decisionWork.some((item) => item.kind === "identity") &&
|
|
110
|
+
(decisionWork.length !== 1 || work.length))
|
|
111
|
+
fail("task_semantic_owner_conflict", "Submit one identity task at a time; reference rewrites may affect multiple row types.");
|
|
112
|
+
for (const item of decisionWork) {
|
|
113
|
+
if (rowOwners.has(item.type))
|
|
114
|
+
fail("task_semantic_owner_conflict", "Submit one decision/patch owner per row set, then reassess before the next owner.");
|
|
115
|
+
rowOwners.add(item.type);
|
|
116
|
+
}
|
|
117
|
+
return runFoundryTaskOperation(context, {
|
|
118
|
+
command: "dataset-semantic-apply",
|
|
119
|
+
options: {
|
|
120
|
+
submission: submission.descriptor,
|
|
121
|
+
files: submission.files,
|
|
122
|
+
assessment: assessment.entry.sha256,
|
|
123
|
+
},
|
|
124
|
+
validateCurrent(index) {
|
|
125
|
+
const current = currentWorkflowState(context, index);
|
|
126
|
+
if (current.assessment?.entry.sha256 !== assessment.entry.sha256 ||
|
|
127
|
+
current.rows?.entry.sha256 !== rows.entry.sha256)
|
|
128
|
+
fail("semantic_assessment_changed", "Assessment advanced before this submission acquired the task lock.");
|
|
129
|
+
},
|
|
130
|
+
}, (operation) => {
|
|
131
|
+
assertSelectedSemanticInput(submission);
|
|
132
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
133
|
+
for (const input of context.inputs)
|
|
134
|
+
readFoundryInput(context, input.path);
|
|
135
|
+
const output = createWorkflowStageDirectory(context, operation, "semantic");
|
|
136
|
+
fs.mkdirSync(resolveFoundryOutput(context, "tmp"), { recursive: true, mode: 0o700 });
|
|
137
|
+
const temporary = createWorkflowDirectory(context, path.join(context.tempRoot, "semantic-"));
|
|
138
|
+
const updated = new Map();
|
|
139
|
+
const identityReports = [...rows.value.identity_reports], rewriteReports = [...rows.value.identity_rewrite_reports];
|
|
140
|
+
const results = [];
|
|
141
|
+
const blockers = [];
|
|
142
|
+
try {
|
|
143
|
+
operation.writeText(path.join(output, "submission.json"), readSelectedSemanticBytes(submission.descriptor));
|
|
144
|
+
for (const group of work) {
|
|
145
|
+
const type = text(group.set.type, "Dataset type");
|
|
146
|
+
const previousBlockers = blockers.length;
|
|
147
|
+
const projected = structuredClone(group.manifest);
|
|
148
|
+
projected.tasks = group.tasks.map(({ task, sha, fact }) => {
|
|
149
|
+
const snapshot = path.join(output, "inputs", `${sha}.json`);
|
|
150
|
+
const bytes = readSelectedSemanticBytes(fact);
|
|
151
|
+
operation.writeText(snapshot, bytes);
|
|
152
|
+
const strictTask = {
|
|
153
|
+
...task,
|
|
154
|
+
context: {
|
|
155
|
+
...workflowObject(task.context),
|
|
156
|
+
full_context_ai_completion: { required: true },
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
const requiredKinds = taskRequiredContextKinds(task);
|
|
160
|
+
let payload;
|
|
161
|
+
try {
|
|
162
|
+
payload = JSON.parse(bytes.toString("utf8"));
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
blockers.push({ code: "semantic_patch_json_invalid", type, work_item: sha });
|
|
166
|
+
}
|
|
167
|
+
for (const patch of patchPayloadPatchSets(payload)) {
|
|
168
|
+
for (const patchOperation of patchSetOperations(patch) ?? []) {
|
|
169
|
+
if (patchOperation.op === "test")
|
|
170
|
+
continue;
|
|
171
|
+
blockers.push(...operationFullContextEvidenceBlockers({
|
|
172
|
+
operation: patchOperation,
|
|
173
|
+
task: strictTask,
|
|
174
|
+
}));
|
|
175
|
+
const usedKinds = operationUsedContextKinds(patchOperation);
|
|
176
|
+
if (requiredKinds.some((kind) => !usedKinds.includes(kind)))
|
|
177
|
+
blockers.push({
|
|
178
|
+
code: "semantic_context_evidence_missing",
|
|
179
|
+
type,
|
|
180
|
+
work_item: sha,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
...structuredClone(task),
|
|
186
|
+
files: { ...workflowObject(task.files), output_patch_file: snapshot },
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
const projectedFile = path.join(output, type, "selected-work.json");
|
|
190
|
+
operation.writeJson(projectedFile, projected);
|
|
191
|
+
if (blockers.length !== previousBlockers)
|
|
192
|
+
continue;
|
|
193
|
+
const collection = runDatasetAuthoringPatchCollect({
|
|
194
|
+
repoRoot: assessment.value.owner_base,
|
|
195
|
+
options: {
|
|
196
|
+
taskManifest: projectedFile,
|
|
197
|
+
outDir: path.join(output, type, "collect"),
|
|
198
|
+
out: path.join(output, type, "collected-patches.json"),
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
if (collection.status !== "ready_for_patch_apply" ||
|
|
202
|
+
!Array.isArray(collection.blockers) ||
|
|
203
|
+
collection.blockers.length) {
|
|
204
|
+
blockers.push({ code: "semantic_patch_invalid", type, collection });
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const originalRows = text(group.set.rows, "Assessed rows");
|
|
208
|
+
const packageDirectories = new Set(group.tasks.map(({ task }) => path.dirname(path.resolve(assessment.value.owner_base, text(workflowObject(task.files).authoring_package, "Authoring package")))));
|
|
209
|
+
if (packageDirectories.size !== 1)
|
|
210
|
+
fail("semantic_work_invalid", "Selected work must share its registered package snapshot directory.");
|
|
211
|
+
const repaired = path.join(output, type, "repaired.rows.jsonl");
|
|
212
|
+
const applied = runWorkflowLocalCliResult(context, qualified, temporary, [
|
|
213
|
+
"dataset",
|
|
214
|
+
"patch",
|
|
215
|
+
"apply",
|
|
216
|
+
"--input",
|
|
217
|
+
originalRows,
|
|
218
|
+
"--patch",
|
|
219
|
+
path.join(output, type, "collected-patches.json"),
|
|
220
|
+
"--out",
|
|
221
|
+
repaired,
|
|
222
|
+
"--out-dir",
|
|
223
|
+
path.join(output, type, "apply"),
|
|
224
|
+
"--authoring-package-dir",
|
|
225
|
+
[...packageDirectories][0],
|
|
226
|
+
"--require-authoring-package",
|
|
227
|
+
"--require-action-item-closure",
|
|
228
|
+
"--json",
|
|
229
|
+
]);
|
|
230
|
+
if (applied.exit !== 0 ||
|
|
231
|
+
applied.report.status !== "completed" ||
|
|
232
|
+
!Array.isArray(applied.report.blockers) ||
|
|
233
|
+
applied.report.blockers.length) {
|
|
234
|
+
blockers.push({ code: "semantic_apply_blocked", type, report: applied.report });
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const original = rows.value.sets.find((set) => set.type === type && set.file === originalRows);
|
|
238
|
+
if (!original || Number(applied.report.row_count) !== original.count)
|
|
239
|
+
fail("semantic_row_scope_changed", "Patch application changed the assessed row scope.");
|
|
240
|
+
updated.set(type, { ...original, file: repaired });
|
|
241
|
+
results.push({
|
|
242
|
+
type,
|
|
243
|
+
original_rows: originalRows,
|
|
244
|
+
repaired_rows: repaired,
|
|
245
|
+
applied_operations: applied.report.applied_operation_count,
|
|
246
|
+
closed_actions: applied.report.closed_action_item_count,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
const decisionOwners = createFoundryDecisionOwners(context, qualified, temporary);
|
|
250
|
+
for (const item of decisionWork) {
|
|
251
|
+
const beforeCount = blockers.length;
|
|
252
|
+
const bytes = readSelectedSemanticBytes(item.fact);
|
|
253
|
+
operation.writeText(path.join(output, "inputs", `${item.sha}.submitted`), bytes);
|
|
254
|
+
const task = workflowObject(JSON.parse(readFoundryInput(context, item.task).toString("utf8")));
|
|
255
|
+
const requiredKinds = taskRequiredContextKinds({
|
|
256
|
+
context: { contract_context_files: task.contract_context_files },
|
|
257
|
+
});
|
|
258
|
+
let decisions = [];
|
|
259
|
+
try {
|
|
260
|
+
decisions = ensureArray(readJsonOrJsonl(item.fact.path, () => bytes.toString("utf8")));
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
blockers.push({ code: "semantic_decisions_invalid_json", type: item.type });
|
|
264
|
+
}
|
|
265
|
+
for (const value of decisions) {
|
|
266
|
+
const decision = workflowObject(value);
|
|
267
|
+
blockers.push(...operationFullContextEvidenceBlockers({
|
|
268
|
+
operation: decision,
|
|
269
|
+
task: { context: { full_context_ai_completion: { required: true } } },
|
|
270
|
+
}));
|
|
271
|
+
const kinds = Array.isArray(decision.used_context_kinds)
|
|
272
|
+
? decision.used_context_kinds
|
|
273
|
+
: [];
|
|
274
|
+
if (requiredKinds.some((kind) => !kinds.includes(kind)))
|
|
275
|
+
blockers.push({ code: "semantic_context_evidence_missing", type: item.type });
|
|
276
|
+
}
|
|
277
|
+
if (blockers.length !== beforeCount)
|
|
278
|
+
continue;
|
|
279
|
+
if (item.kind === "identity") {
|
|
280
|
+
const applied = applyFoundryIdentityDecisions(context, qualified, temporary, {
|
|
281
|
+
task,
|
|
282
|
+
decisions,
|
|
283
|
+
sets: rows.value.sets,
|
|
284
|
+
output: path.join(output, "identity"),
|
|
285
|
+
});
|
|
286
|
+
blockers.push(...applied.blockers);
|
|
287
|
+
identityReports.push(...applied.reports);
|
|
288
|
+
rewriteReports.push(...applied.rewriteReports);
|
|
289
|
+
for (const set of applied.sets)
|
|
290
|
+
updated.set(set.type, set);
|
|
291
|
+
results.push({
|
|
292
|
+
kind: "identity",
|
|
293
|
+
reports: applied.reports,
|
|
294
|
+
rewrite_reports: applied.rewriteReports,
|
|
295
|
+
});
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const decisionFile = path.join(output, item.type, `${item.kind}-decisions.jsonl`);
|
|
299
|
+
operation.writeText(decisionFile, decisions.map((value) => JSON.stringify(value)).join("\n") + "\n");
|
|
300
|
+
const repaired = path.join(output, item.type, "repaired.rows.jsonl");
|
|
301
|
+
const options = {
|
|
302
|
+
[`${item.kind}Queue`]: item.queue,
|
|
303
|
+
decisions: decisionFile,
|
|
304
|
+
decisionTask: item.task,
|
|
305
|
+
rowsFile: item.rows,
|
|
306
|
+
out: repaired,
|
|
307
|
+
outDir: path.join(output, item.type, item.kind),
|
|
308
|
+
};
|
|
309
|
+
const applied = workflowObject(decisionOwners.invoke(() => item.kind === "classification"
|
|
310
|
+
? decisionOwners.classification.runDatasetClassificationDecisionsApply(options)
|
|
311
|
+
: decisionOwners.location.runDatasetLocationDecisionsApply(options)));
|
|
312
|
+
if (applied.status !== "completed" ||
|
|
313
|
+
!Array.isArray(applied.blockers) ||
|
|
314
|
+
applied.blockers.length) {
|
|
315
|
+
blockers.push({
|
|
316
|
+
code: "semantic_decision_apply_blocked",
|
|
317
|
+
type: item.type,
|
|
318
|
+
kind: item.kind,
|
|
319
|
+
report: applied,
|
|
320
|
+
});
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
const original = rows.value.sets.find((set) => set.type === item.type && set.file === item.rows);
|
|
324
|
+
if (!original || !fs.existsSync(repaired) || readRows(repaired).length !== original.count)
|
|
325
|
+
fail("semantic_row_scope_changed", "Decision application changed row scope.");
|
|
326
|
+
updated.set(item.type, { ...original, file: repaired });
|
|
327
|
+
results.push({
|
|
328
|
+
kind: item.kind,
|
|
329
|
+
type: item.type,
|
|
330
|
+
original_rows: item.rows,
|
|
331
|
+
repaired_rows: repaired,
|
|
332
|
+
report: applied,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
assertSelectedSemanticInput(submission);
|
|
336
|
+
for (const input of context.inputs)
|
|
337
|
+
readFoundryInput(context, input.path);
|
|
338
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
339
|
+
registerWorkflowStageFiles(context, operation, output);
|
|
340
|
+
if (!blockers.length)
|
|
341
|
+
operation.writeJson(path.join(output, "foundry-rows.json"), {
|
|
342
|
+
schema: "tiangong-foundry.rows-stage.v1",
|
|
343
|
+
status: "completed",
|
|
344
|
+
predecessor: rows.file,
|
|
345
|
+
sets: rows.value.sets
|
|
346
|
+
.map((set) => updated.get(set.type) ?? set)
|
|
347
|
+
.filter((set) => set.count > 0),
|
|
348
|
+
identity_reports: identityReports,
|
|
349
|
+
identity_rewrite_reports: rewriteReports,
|
|
350
|
+
});
|
|
351
|
+
const report = {
|
|
352
|
+
schema: "tiangong-foundry.semantic-result.v1",
|
|
353
|
+
status: blockers.length ? "blocked" : "completed",
|
|
354
|
+
submission_sha256: submission.descriptor.sha256,
|
|
355
|
+
assessment_sha256: assessment.entry.sha256,
|
|
356
|
+
work_items: [...used],
|
|
357
|
+
results,
|
|
358
|
+
blockers,
|
|
359
|
+
};
|
|
360
|
+
operation.writeJson(path.join(output, "semantic-result.json"), report);
|
|
361
|
+
return report;
|
|
362
|
+
}
|
|
363
|
+
finally {
|
|
364
|
+
fs.rmSync(temporary, { recursive: true, force: true });
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { ArtifactEntry } from "./foundry-task-types.ts";
|
|
3
|
+
export interface WorkflowRowSet {
|
|
4
|
+
type: string;
|
|
5
|
+
file: string;
|
|
6
|
+
count: number;
|
|
7
|
+
}
|
|
8
|
+
export interface WorkflowArtifact<T> {
|
|
9
|
+
entry: ArtifactEntry;
|
|
10
|
+
file: string;
|
|
11
|
+
value: T;
|
|
12
|
+
}
|
|
13
|
+
export interface WorkflowRows {
|
|
14
|
+
schema: "tiangong-foundry.rows-stage.v1";
|
|
15
|
+
status: "completed";
|
|
16
|
+
sets: WorkflowRowSet[];
|
|
17
|
+
identity_reports: string[];
|
|
18
|
+
identity_rewrite_reports: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface WorkflowAssessment {
|
|
21
|
+
schema: "tiangong-foundry.assessment-stage.v1";
|
|
22
|
+
status: string;
|
|
23
|
+
owner_base: string;
|
|
24
|
+
rows_report?: string;
|
|
25
|
+
identity_report?: string | null;
|
|
26
|
+
sets: Array<Record<string, unknown>>;
|
|
27
|
+
}
|
|
28
|
+
export declare function workflowObject(value: unknown): Record<string, unknown>;
|
|
29
|
+
export declare function readWorkflowArtifact(context: FoundryRuntimeContext, entry: ArtifactEntry): WorkflowArtifact<Record<string, unknown>>;
|
|
30
|
+
export declare function currentWorkflowState(context: FoundryRuntimeContext, entries: readonly ArtifactEntry[]): {
|
|
31
|
+
rows: WorkflowArtifact<WorkflowRows> | null;
|
|
32
|
+
assessment: WorkflowArtifact<WorkflowAssessment> | null;
|
|
33
|
+
identity: WorkflowArtifact<Record<string, unknown>> | null;
|
|
34
|
+
finalization: WorkflowArtifact<Record<string, unknown>> | null;
|
|
35
|
+
authorization: WorkflowArtifact<Record<string, unknown>> | null;
|
|
36
|
+
preparedApproval: WorkflowArtifact<Record<string, unknown>> | null;
|
|
37
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
import { readTaskBytes } from "./foundry-task-io.js";
|
|
6
|
+
export function workflowObject(value) {
|
|
7
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
8
|
+
throw new FoundryContextError("workflow_report_invalid", "Workflow metadata must be an object.");
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
export function readWorkflowArtifact(context, entry) {
|
|
12
|
+
const file = resolveFoundryOutput(context, entry.path);
|
|
13
|
+
const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
14
|
+
try {
|
|
15
|
+
const stat = fs.fstatSync(fd);
|
|
16
|
+
if (!stat.isFile() || stat.size > 8 * 1024 * 1024 || stat.size !== entry.bytes)
|
|
17
|
+
throw new FoundryContextError("workflow_artifact_changed", "Workflow artifact size or identity changed.");
|
|
18
|
+
const bytes = fs.readFileSync(fd);
|
|
19
|
+
if (bytes.length !== entry.bytes ||
|
|
20
|
+
createHash("sha256").update(bytes).digest("hex") !== entry.sha256)
|
|
21
|
+
throw new FoundryContextError("workflow_artifact_changed", "Workflow artifact content changed.");
|
|
22
|
+
return { entry, file, value: workflowObject(JSON.parse(bytes.toString("utf8"))) };
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
fs.closeSync(fd);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function currentWorkflowState(context, entries) {
|
|
29
|
+
const rowEntry = entries.findLast((entry) => ["dataset-workflow-rows", "dataset-semantic-apply"].includes(entry.command) &&
|
|
30
|
+
path.basename(entry.path) === "foundry-rows.json");
|
|
31
|
+
let rows = null;
|
|
32
|
+
if (rowEntry) {
|
|
33
|
+
const found = readWorkflowArtifact(context, rowEntry);
|
|
34
|
+
if (found.value.schema !== "tiangong-foundry.rows-stage.v1" ||
|
|
35
|
+
found.value.status !== "completed" ||
|
|
36
|
+
!Array.isArray(found.value.sets))
|
|
37
|
+
throw new FoundryContextError("workflow_rows_invalid", "Registered row metadata is invalid.");
|
|
38
|
+
const sets = found.value.sets.map((value) => {
|
|
39
|
+
const set = workflowObject(value);
|
|
40
|
+
if (typeof set.type !== "string" ||
|
|
41
|
+
typeof set.file !== "string" ||
|
|
42
|
+
!Number.isSafeInteger(set.count) ||
|
|
43
|
+
Number(set.count) < 0)
|
|
44
|
+
throw new FoundryContextError("workflow_rows_invalid", "A registered row set is invalid.");
|
|
45
|
+
return { type: set.type, file: set.file, count: Number(set.count) };
|
|
46
|
+
});
|
|
47
|
+
const retainedReports = (key) => {
|
|
48
|
+
const value = found.value[key] ?? [];
|
|
49
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string"))
|
|
50
|
+
throw new FoundryContextError("workflow_rows_invalid", "Identity report references are invalid.");
|
|
51
|
+
return value;
|
|
52
|
+
};
|
|
53
|
+
rows = {
|
|
54
|
+
...found,
|
|
55
|
+
value: {
|
|
56
|
+
schema: "tiangong-foundry.rows-stage.v1",
|
|
57
|
+
status: "completed",
|
|
58
|
+
sets,
|
|
59
|
+
identity_reports: retainedReports("identity_reports"),
|
|
60
|
+
identity_rewrite_reports: retainedReports("identity_rewrite_reports"),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
let identity = null;
|
|
65
|
+
if (rows) {
|
|
66
|
+
for (const entry of [...entries].reverse()) {
|
|
67
|
+
if (entry.command !== "dataset-workflow-identity" ||
|
|
68
|
+
path.basename(entry.path) !== "foundry-identity.json")
|
|
69
|
+
continue;
|
|
70
|
+
const found = readWorkflowArtifact(context, entry);
|
|
71
|
+
if (found.value.schema !== "tiangong-foundry.identity-stage.v1" ||
|
|
72
|
+
!Array.isArray(found.value.sets))
|
|
73
|
+
throw new FoundryContextError("workflow_identity_invalid", "Registered identity metadata is invalid.");
|
|
74
|
+
if (found.value.rows_report === rows.file) {
|
|
75
|
+
identity = found;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let assessment = null;
|
|
81
|
+
if (rows) {
|
|
82
|
+
for (const entry of [...entries].reverse()) {
|
|
83
|
+
if (entry.command !== "dataset-workflow-assessment" ||
|
|
84
|
+
path.basename(entry.path) !== "foundry-assessment.json")
|
|
85
|
+
continue;
|
|
86
|
+
const found = readWorkflowArtifact(context, entry), value = found.value;
|
|
87
|
+
if (value.schema !== "tiangong-foundry.assessment-stage.v1" ||
|
|
88
|
+
typeof value.owner_base !== "string" ||
|
|
89
|
+
!Array.isArray(value.sets))
|
|
90
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Registered assessment metadata is invalid.");
|
|
91
|
+
const sets = value.sets.map(workflowObject);
|
|
92
|
+
const matchingRows = sets.length === rows.value.sets.length &&
|
|
93
|
+
rows.value.sets.every((row) => sets.some((set) => set.type === row.type && set.rows === row.file));
|
|
94
|
+
if ((value.rows_report === undefined || value.rows_report === rows.file) &&
|
|
95
|
+
matchingRows &&
|
|
96
|
+
(value.identity_report ?? null) ===
|
|
97
|
+
(identity?.value.status === "completed" ? identity.file : null)) {
|
|
98
|
+
assessment = {
|
|
99
|
+
...found,
|
|
100
|
+
value: {
|
|
101
|
+
schema: "tiangong-foundry.assessment-stage.v1",
|
|
102
|
+
status: String(value.status),
|
|
103
|
+
owner_base: value.owner_base,
|
|
104
|
+
rows_report: rows.file,
|
|
105
|
+
identity_report: identity?.value.status === "completed" ? identity.file : null,
|
|
106
|
+
sets,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
let finalization = null;
|
|
114
|
+
if (rows && assessment) {
|
|
115
|
+
for (const entry of [...entries].reverse()) {
|
|
116
|
+
if (entry.command !== "dataset-workflow-finalize" ||
|
|
117
|
+
path.basename(entry.path) !== "foundry-finalize.json")
|
|
118
|
+
continue;
|
|
119
|
+
const found = readWorkflowArtifact(context, entry);
|
|
120
|
+
if (found.value.schema !== "tiangong-foundry.finalize-stage.v1" ||
|
|
121
|
+
!Array.isArray(found.value.sets) ||
|
|
122
|
+
!Array.isArray(found.value.blockers))
|
|
123
|
+
throw new FoundryContextError("workflow_finalize_invalid", "Registered finalization metadata is invalid.");
|
|
124
|
+
if (found.value.rows_report === rows.file &&
|
|
125
|
+
found.value.assessment_report === assessment.file) {
|
|
126
|
+
finalization = found;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
let authorization = null;
|
|
132
|
+
let preparedApproval = null;
|
|
133
|
+
if (finalization && fs.existsSync(path.join(context.taskRoot, "authorization.json"))) {
|
|
134
|
+
const pointer = createHash("sha256")
|
|
135
|
+
.update(readTaskBytes(context, "authorization.json"))
|
|
136
|
+
.digest("hex");
|
|
137
|
+
for (const entry of [...entries].reverse()) {
|
|
138
|
+
if (entry.command !== "dataset-workflow-authorization" ||
|
|
139
|
+
path.basename(entry.path) !== "foundry-authorization.json")
|
|
140
|
+
continue;
|
|
141
|
+
const found = readWorkflowArtifact(context, entry);
|
|
142
|
+
if (found.value.schema !== "tiangong-foundry.authorization-stage.v1")
|
|
143
|
+
throw new FoundryContextError("workflow_authorization_invalid", "Registered approval metadata is invalid.");
|
|
144
|
+
const prepared = finalization.value.approval_source_sha256 === entry.sha256 &&
|
|
145
|
+
found.value.input_kind === "current_rows";
|
|
146
|
+
if (prepared)
|
|
147
|
+
preparedApproval = found;
|
|
148
|
+
if ((found.value.finalization_sha256 === finalization.entry.sha256 || prepared) &&
|
|
149
|
+
found.value.pointer_sha256 === pointer &&
|
|
150
|
+
typeof found.value.expires_at_utc === "string" &&
|
|
151
|
+
Date.parse(found.value.expires_at_utc) > Date.now()) {
|
|
152
|
+
authorization = found;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { rows, assessment, identity, finalization, authorization, preparedApproval };
|
|
158
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
type JsonRecord = Record<string, unknown>;
|
|
2
|
+
interface JsonArtifact {
|
|
3
|
+
path: string;
|
|
4
|
+
value: unknown;
|
|
5
|
+
}
|
|
6
|
+
interface FullContextRequirement extends JsonRecord {
|
|
7
|
+
profile_id: unknown;
|
|
8
|
+
dataset_type: string | null;
|
|
9
|
+
required_context_kinds: string[];
|
|
10
|
+
required_context_file_patterns: string[];
|
|
11
|
+
}
|
|
12
|
+
interface FullContextProofDependencies {
|
|
13
|
+
asText: (value: unknown) => string;
|
|
14
|
+
classificationDecisionUsedContextKinds: (row: unknown) => string[];
|
|
15
|
+
decisionCompletionStatus: (row: unknown) => string;
|
|
16
|
+
decisionContextBundleSha256: (row: unknown) => string;
|
|
17
|
+
ensureArray: (value: unknown) => unknown[];
|
|
18
|
+
fileExists: (filePath: string) => boolean;
|
|
19
|
+
listImportProfiles: (options: {
|
|
20
|
+
repoRoot: string;
|
|
21
|
+
}) => unknown;
|
|
22
|
+
normalizedList: (value: unknown) => string[];
|
|
23
|
+
readJson: (filePath: string) => unknown;
|
|
24
|
+
readJsonArtifactOption: (value: unknown) => JsonArtifact | null;
|
|
25
|
+
readJsonLines: (filePath: string) => unknown[];
|
|
26
|
+
readText: (filePath: string) => string;
|
|
27
|
+
repoRelativePath: (filePath: string) => string;
|
|
28
|
+
resolveRepoPath: (value: unknown) => string | null;
|
|
29
|
+
repoRoot: string;
|
|
30
|
+
sha256Text: (value: unknown) => string;
|
|
31
|
+
unique: <T>(values: T[]) => T[];
|
|
32
|
+
}
|
|
33
|
+
export declare function createFullContextProofUtils({ asText, classificationDecisionUsedContextKinds, decisionCompletionStatus, decisionContextBundleSha256, ensureArray, fileExists, listImportProfiles, normalizedList, readJson, readJsonArtifactOption, readJsonLines, readText, repoRelativePath, resolveRepoPath, repoRoot, sha256Text, unique, }: FullContextProofDependencies): {
|
|
34
|
+
completionFullContextBlockers: ({ task, completionReport, }: {
|
|
35
|
+
task: unknown;
|
|
36
|
+
completionReport: unknown;
|
|
37
|
+
}) => JsonRecord[];
|
|
38
|
+
fullContextProofCheck: ({ prefix, profileId, datasetType, closeoutCounts, mutationArtifact, codePrefix, }: {
|
|
39
|
+
prefix?: JsonRecord;
|
|
40
|
+
profileId?: unknown;
|
|
41
|
+
datasetType?: unknown;
|
|
42
|
+
closeoutCounts?: unknown;
|
|
43
|
+
mutationArtifact?: JsonArtifact | null;
|
|
44
|
+
codePrefix?: string;
|
|
45
|
+
}) => {
|
|
46
|
+
required: boolean;
|
|
47
|
+
blockers: JsonRecord[];
|
|
48
|
+
};
|
|
49
|
+
profileFullContextRequirement: (profileId: unknown, datasetType: unknown) => FullContextRequirement | null;
|
|
50
|
+
};
|
|
51
|
+
export {};
|