@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,735 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export function createDecisionTaskUtils({ asText, cloneJson, ensureArray, fileExists, integerOption, normalizedList, nowIso, positiveIntegerOption, readJson, readJsonLines, readText, repoRelativePath, resolveRepoPath, sameResolvedPath, sha256Text, unique, writeJson, }) {
|
|
3
|
+
function classificationQueueSchemaType(row) {
|
|
4
|
+
return asText(row?.classification_workflow?.schema_type ??
|
|
5
|
+
row?.schema_type ??
|
|
6
|
+
row?.category_type ??
|
|
7
|
+
row?.type);
|
|
8
|
+
}
|
|
9
|
+
function classificationQueueRowType(row) {
|
|
10
|
+
return asText(row?.classification_workflow?.row_type ?? row?.dataset_type);
|
|
11
|
+
}
|
|
12
|
+
function classificationQueueInputRows(row) {
|
|
13
|
+
return asText(row?.classification_workflow?.commands?.input_rows);
|
|
14
|
+
}
|
|
15
|
+
function classificationQueueOutputRows(row) {
|
|
16
|
+
return asText(row?.classification_workflow?.commands?.output_rows);
|
|
17
|
+
}
|
|
18
|
+
function queueRowSourceFile(row) {
|
|
19
|
+
return asText(row?.source_file ?? row?.sourceFile);
|
|
20
|
+
}
|
|
21
|
+
function queueRowBundleId(row) {
|
|
22
|
+
const match = queueRowSourceFile(row).match(/(?:^|\/)process-bundles\/([^/]+)\//u);
|
|
23
|
+
return match?.[1] ?? "";
|
|
24
|
+
}
|
|
25
|
+
function hasQueueSelectionOptions(options) {
|
|
26
|
+
return Boolean(normalizedList(options.datasetId || options.datasetIds || options.id).length ||
|
|
27
|
+
normalizedList(options.datasetType || options.datasetTypes).length ||
|
|
28
|
+
normalizedList(options.categoryType || options.categoryTypes || options.schemaType || options.schemaTypes).length ||
|
|
29
|
+
normalizedList(options.bundleId || options.bundleIds || options.processId).length ||
|
|
30
|
+
integerOption(options.offset, null) !== null ||
|
|
31
|
+
positiveIntegerOption(options.limit || options.count, null) !== null);
|
|
32
|
+
}
|
|
33
|
+
function queueSelectionSummary(options) {
|
|
34
|
+
return {
|
|
35
|
+
dataset_ids: normalizedList(options.datasetId || options.datasetIds || options.id),
|
|
36
|
+
dataset_types: normalizedList(options.datasetType || options.datasetTypes),
|
|
37
|
+
category_types: normalizedList(options.categoryType || options.categoryTypes || options.schemaType || options.schemaTypes),
|
|
38
|
+
bundle_ids: normalizedList(options.bundleId || options.bundleIds || options.processId),
|
|
39
|
+
offset: Math.max(0, integerOption(options.offset, 0) ?? 0),
|
|
40
|
+
limit: positiveIntegerOption(options.limit || options.count, null),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function queueRowMatchesSelection(row, selection, schemaTypeForRow) {
|
|
44
|
+
const datasetId = asText(row?.dataset_id);
|
|
45
|
+
const datasetType = asText(row?.dataset_type);
|
|
46
|
+
const categoryType = schemaTypeForRow(row);
|
|
47
|
+
const bundleId = queueRowBundleId(row);
|
|
48
|
+
if (selection.dataset_ids.length > 0 && !selection.dataset_ids.includes(datasetId)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (selection.dataset_types.length > 0 && !selection.dataset_types.includes(datasetType)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (selection.category_types.length > 0 && !selection.category_types.includes(categoryType)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (selection.bundle_ids.length > 0 && !selection.bundle_ids.includes(bundleId)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
function selectDecisionTaskQueueRows(queueRows, options, schemaTypeForRow) {
|
|
63
|
+
const selection = queueSelectionSummary(options);
|
|
64
|
+
const filtered = queueRows
|
|
65
|
+
.map((row, sourceIndex) => ({ row, sourceIndex }))
|
|
66
|
+
.filter(({ row }) => queueRowMatchesSelection(row, selection, schemaTypeForRow));
|
|
67
|
+
const start = selection.offset;
|
|
68
|
+
const end = selection.limit ? start + selection.limit : undefined;
|
|
69
|
+
const selected = filtered.slice(start, end);
|
|
70
|
+
return {
|
|
71
|
+
selection: {
|
|
72
|
+
...selection,
|
|
73
|
+
source_queue_rows: queueRows.length,
|
|
74
|
+
matched_queue_rows: filtered.length,
|
|
75
|
+
selected_queue_rows: selected.length,
|
|
76
|
+
source_queue_row_indices: selected.map((item) => item.sourceIndex),
|
|
77
|
+
},
|
|
78
|
+
selected,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function safeFileToken(value, fallback) {
|
|
82
|
+
const token = asText(value)
|
|
83
|
+
.replace(/[^A-Za-z0-9_.-]+/gu, "-")
|
|
84
|
+
.replace(/^-+|-+$/gu, "");
|
|
85
|
+
return token || fallback;
|
|
86
|
+
}
|
|
87
|
+
function decisionTaskChunkLabel(options, selection, fallback) {
|
|
88
|
+
if (options.chunkLabel || options.chunk || options.label) {
|
|
89
|
+
return safeFileToken(options.chunkLabel || options.chunk || options.label, fallback);
|
|
90
|
+
}
|
|
91
|
+
const bundleIds = ensureArray(selection.bundle_ids);
|
|
92
|
+
const datasetTypes = ensureArray(selection.dataset_types);
|
|
93
|
+
const categoryTypes = ensureArray(selection.category_types);
|
|
94
|
+
if (bundleIds.length === 1) {
|
|
95
|
+
return safeFileToken(`bundle-${bundleIds[0]}`, fallback);
|
|
96
|
+
}
|
|
97
|
+
if (datasetTypes.length === 1 && categoryTypes.length === 1) {
|
|
98
|
+
return safeFileToken(`${datasetTypes[0]}-${categoryTypes[0]}`, fallback);
|
|
99
|
+
}
|
|
100
|
+
if (datasetTypes.length === 1) {
|
|
101
|
+
return safeFileToken(datasetTypes[0], fallback);
|
|
102
|
+
}
|
|
103
|
+
return safeFileToken(`offset-${selection.offset}-limit-${selection.limit ?? "all"}`, fallback);
|
|
104
|
+
}
|
|
105
|
+
function rewriteDecisionTaskQueueRowsForChunk({ selected, sourceQueuePath, outDir, chunkLabel, workflowKey, outputSuffix, inputRowsForRow, inputRowsOverride = null, }) {
|
|
106
|
+
const outputByInput = new Map();
|
|
107
|
+
return selected.map(({ row, sourceIndex }) => {
|
|
108
|
+
const next = cloneJson(row);
|
|
109
|
+
const inputRows = inputRowsOverride || resolveRepoPath(inputRowsForRow(next));
|
|
110
|
+
const inputBase = inputRows
|
|
111
|
+
? path.basename(inputRows).replace(/\.(jsonl|json)$/iu, "")
|
|
112
|
+
: `rows-${sourceIndex}`;
|
|
113
|
+
if (!outputByInput.has(inputBase)) {
|
|
114
|
+
outputByInput.set(inputBase, path.join(outDir, "rows", `${inputBase}.${chunkLabel}.${outputSuffix}.jsonl`));
|
|
115
|
+
}
|
|
116
|
+
next.foundry_selection = {
|
|
117
|
+
source_queue: repoRelativePath(sourceQueuePath),
|
|
118
|
+
source_queue_row_index: sourceIndex,
|
|
119
|
+
bundle_id: queueRowBundleId(row) || null,
|
|
120
|
+
};
|
|
121
|
+
next[workflowKey] ??= {};
|
|
122
|
+
const workflow = next[workflowKey];
|
|
123
|
+
workflow.commands ??= {};
|
|
124
|
+
if (inputRowsOverride) {
|
|
125
|
+
workflow.commands.input_rows = repoRelativePath(inputRowsOverride);
|
|
126
|
+
}
|
|
127
|
+
workflow.commands.output_rows = repoRelativePath(outputByInput.get(inputBase));
|
|
128
|
+
return next;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function decisionTaskInputRowsOverride(options) {
|
|
132
|
+
const optionValue = options.rowsFile ||
|
|
133
|
+
options.inputRows ||
|
|
134
|
+
options.inputRowsFile ||
|
|
135
|
+
options.currentRows ||
|
|
136
|
+
options.currentRowsFile;
|
|
137
|
+
if (!optionValue)
|
|
138
|
+
return null;
|
|
139
|
+
const resolved = resolveRepoPath(optionValue);
|
|
140
|
+
if (!resolved || !fileExists(resolved)) {
|
|
141
|
+
throw new Error("--rows-file/--input-rows must point to a readable current rows JSON/JSONL file.");
|
|
142
|
+
}
|
|
143
|
+
return resolved;
|
|
144
|
+
}
|
|
145
|
+
function classificationDecisionSchemaType(decision) {
|
|
146
|
+
return asText(decision?.category_type ??
|
|
147
|
+
decision?.categoryType ??
|
|
148
|
+
decision?.classification_type ??
|
|
149
|
+
decision?.classificationType ??
|
|
150
|
+
decision?.type);
|
|
151
|
+
}
|
|
152
|
+
function classificationDecisionTargetKey(decision, schemaType = "") {
|
|
153
|
+
const datasetId = asText(decision?.dataset_id ?? decision?.datasetId ?? decision?.id ?? decision?.uuid);
|
|
154
|
+
const version = asText(decision?.dataset_version ?? decision?.datasetVersion ?? decision?.version);
|
|
155
|
+
const type = classificationDecisionSchemaType(decision) || schemaType;
|
|
156
|
+
return `${type}::${datasetId}::${version}`;
|
|
157
|
+
}
|
|
158
|
+
function classificationQueueTargetKey(row) {
|
|
159
|
+
return `${classificationQueueSchemaType(row)}::${asText(row?.dataset_id)}::${asText(row?.dataset_version)}`;
|
|
160
|
+
}
|
|
161
|
+
function classificationDecisionCode(decision) {
|
|
162
|
+
return asText(decision?.code ??
|
|
163
|
+
decision?.class_id ??
|
|
164
|
+
decision?.classId ??
|
|
165
|
+
decision?.cat_id ??
|
|
166
|
+
decision?.catId ??
|
|
167
|
+
decision?.leaf_code ??
|
|
168
|
+
decision?.leafCode);
|
|
169
|
+
}
|
|
170
|
+
function classificationDecisionUsedContextKinds(decision) {
|
|
171
|
+
return unique([
|
|
172
|
+
...normalizedList(decision?.used_context_kinds ?? decision?.usedContextKinds),
|
|
173
|
+
...normalizedList(decision?.evidence?.used_context_kinds ?? decision?.evidence?.usedContextKinds),
|
|
174
|
+
...normalizedList(decision?.resolution?.used_context_kinds ?? decision?.resolution?.usedContextKinds),
|
|
175
|
+
]);
|
|
176
|
+
}
|
|
177
|
+
function readClassificationTaskJsonlContextRows(baseDir, fileName, maxRows = 2000) {
|
|
178
|
+
const filePath = path.join(baseDir, fileName);
|
|
179
|
+
if (!fileExists(filePath))
|
|
180
|
+
return { file: null, rows: [] };
|
|
181
|
+
const rows = readJsonLines(filePath);
|
|
182
|
+
return {
|
|
183
|
+
file: repoRelativePath(filePath),
|
|
184
|
+
rows: rows.slice(0, maxRows),
|
|
185
|
+
truncated: rows.length > maxRows,
|
|
186
|
+
total_rows: rows.length,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function buildClassificationTaskProvenanceContext(queuePath) {
|
|
190
|
+
const baseDir = path.dirname(queuePath);
|
|
191
|
+
const sourceSemantics = readClassificationTaskJsonlContextRows(baseDir, "source-semantics.jsonl");
|
|
192
|
+
const processSourceReferences = readClassificationTaskJsonlContextRows(baseDir, "process-source-references.jsonl");
|
|
193
|
+
const sourceReferenceRewrites = readClassificationTaskJsonlContextRows(baseDir, "source-reference-rewrites.jsonl");
|
|
194
|
+
return {
|
|
195
|
+
source_semantics: sourceSemantics,
|
|
196
|
+
process_source_references: processSourceReferences,
|
|
197
|
+
source_reference_rewrites: sourceReferenceRewrites,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function decisionTaskContextFileDetails(contractContext) {
|
|
201
|
+
return contractContext.files.map((file) => ({
|
|
202
|
+
kind: file.kind,
|
|
203
|
+
path: file.path,
|
|
204
|
+
sha256: file.sha256,
|
|
205
|
+
bytes: file.bytes,
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
function decisionTaskContextFileWithText(file) {
|
|
209
|
+
const text = String(file?.text ?? "");
|
|
210
|
+
return {
|
|
211
|
+
kind: asText(file?.kind) || "context",
|
|
212
|
+
path: asText(file?.path) || null,
|
|
213
|
+
sha256: asText(file?.sha256) || sha256Text(text),
|
|
214
|
+
bytes: Number(file?.bytes) || Buffer.byteLength(text, "utf8"),
|
|
215
|
+
text,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function decisionTaskContextFileSummary(file) {
|
|
219
|
+
const withText = decisionTaskContextFileWithText(file);
|
|
220
|
+
return {
|
|
221
|
+
kind: withText.kind,
|
|
222
|
+
path: withText.path,
|
|
223
|
+
sha256: withText.sha256,
|
|
224
|
+
bytes: withText.bytes,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function dedupeDecisionTaskContextFiles(files) {
|
|
228
|
+
const byKey = new Map();
|
|
229
|
+
for (const file of ensureArray(files).map(decisionTaskContextFileWithText)) {
|
|
230
|
+
const key = JSON.stringify([file.kind, file.path, file.sha256]);
|
|
231
|
+
if (!byKey.has(key))
|
|
232
|
+
byKey.set(key, file);
|
|
233
|
+
}
|
|
234
|
+
return [...byKey.values()];
|
|
235
|
+
}
|
|
236
|
+
function writeDecisionTaskSharedContextBundle({ outDir, taskKind, files, references = [], cacheDir = null, }) {
|
|
237
|
+
const uniqueFiles = dedupeDecisionTaskContextFiles(files);
|
|
238
|
+
const uniqueBytes = uniqueFiles.reduce((total, file) => total + (Number(file.bytes) || 0), 0);
|
|
239
|
+
const referenceRows = ensureArray(references);
|
|
240
|
+
const referencedBytes = referenceRows.length > 0
|
|
241
|
+
? referenceRows.reduce((total, ref) => total + (Number(ref.bytes) || 0), 0)
|
|
242
|
+
: uniqueBytes;
|
|
243
|
+
const stablePayload = {
|
|
244
|
+
schema_version: 1,
|
|
245
|
+
kind: "tiangong_foundry_decision_shared_context_bundle",
|
|
246
|
+
task_kind: taskKind,
|
|
247
|
+
counts: {
|
|
248
|
+
files: uniqueFiles.length,
|
|
249
|
+
references: referenceRows.length,
|
|
250
|
+
duplicate_references: Math.max(0, referenceRows.length - uniqueFiles.length),
|
|
251
|
+
unique_context_bytes: uniqueBytes,
|
|
252
|
+
referenced_context_bytes: referencedBytes,
|
|
253
|
+
duplicate_context_bytes_avoided: Math.max(0, referencedBytes - uniqueBytes),
|
|
254
|
+
},
|
|
255
|
+
files: uniqueFiles,
|
|
256
|
+
references: referenceRows,
|
|
257
|
+
};
|
|
258
|
+
const bundle = {
|
|
259
|
+
...stablePayload,
|
|
260
|
+
generated_at_utc: nowIso(),
|
|
261
|
+
hash_scope: "schema_version, kind, task_kind, counts, files, and references; generated_at_utc and output path are excluded so identical decision context keeps a stable hash.",
|
|
262
|
+
sha256: sha256Text(JSON.stringify(stablePayload)),
|
|
263
|
+
};
|
|
264
|
+
const resolvedCacheDir = cacheDir ? resolveRepoPath(cacheDir) : null;
|
|
265
|
+
const bundlePath = resolvedCacheDir
|
|
266
|
+
? path.join(resolvedCacheDir, `${taskKind}.${bundle.sha256}.json`)
|
|
267
|
+
: path.join(outDir, "shared-context-bundle.json");
|
|
268
|
+
let cacheReused = false;
|
|
269
|
+
if (resolvedCacheDir && fileExists(bundlePath)) {
|
|
270
|
+
try {
|
|
271
|
+
cacheReused = readJson(bundlePath)?.sha256 === bundle.sha256;
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
cacheReused = false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (!cacheReused) {
|
|
278
|
+
writeJson(bundlePath, bundle);
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
path: repoRelativePath(bundlePath),
|
|
282
|
+
sha256: bundle.sha256,
|
|
283
|
+
counts: bundle.counts,
|
|
284
|
+
hash_scope: bundle.hash_scope,
|
|
285
|
+
cache: resolvedCacheDir
|
|
286
|
+
? {
|
|
287
|
+
enabled: true,
|
|
288
|
+
dir: repoRelativePath(resolvedCacheDir),
|
|
289
|
+
reused: cacheReused,
|
|
290
|
+
}
|
|
291
|
+
: {
|
|
292
|
+
enabled: false,
|
|
293
|
+
reused: false,
|
|
294
|
+
},
|
|
295
|
+
instruction: "Read this shared bundle once for full schema/YAML/ruleset/category/location text; the decision task carries queue rows, attached payloads, provenance, and the stable context bundle hash used by deterministic apply.",
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function stableDecisionTaskQueueRows(queueRows) {
|
|
299
|
+
return ensureArray(queueRows).map((row) => {
|
|
300
|
+
const next = cloneJson(row);
|
|
301
|
+
if (next?.classification_workflow?.commands) {
|
|
302
|
+
delete next.classification_workflow.commands.output_rows;
|
|
303
|
+
}
|
|
304
|
+
if (next?.location_workflow?.commands) {
|
|
305
|
+
delete next.location_workflow.commands.output_rows;
|
|
306
|
+
}
|
|
307
|
+
return next;
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
function decisionTaskQueueSha256(queueRows) {
|
|
311
|
+
return sha256Text(JSON.stringify(stableDecisionTaskQueueRows(queueRows)));
|
|
312
|
+
}
|
|
313
|
+
function decisionTaskProvenanceFileDetails(provenanceContext) {
|
|
314
|
+
return Object.fromEntries(Object.entries(provenanceContext).map(([key, value]) => [
|
|
315
|
+
key,
|
|
316
|
+
{
|
|
317
|
+
file: value?.file ?? null,
|
|
318
|
+
total_rows: value?.total_rows ?? 0,
|
|
319
|
+
truncated: Boolean(value?.truncated),
|
|
320
|
+
},
|
|
321
|
+
]));
|
|
322
|
+
}
|
|
323
|
+
function buildDecisionTaskContextBundle({ taskKind, taskPath, outDir, sharedContextCacheDir = null, queuePath, queueRows, contractContext, provenanceContext, attachedInputRows, }) {
|
|
324
|
+
const contextFiles = dedupeDecisionTaskContextFiles(contractContext.files);
|
|
325
|
+
const contractFiles = contextFiles.map(decisionTaskContextFileSummary);
|
|
326
|
+
const sharedContextBundle = writeDecisionTaskSharedContextBundle({
|
|
327
|
+
outDir: outDir ?? path.dirname(taskPath),
|
|
328
|
+
taskKind,
|
|
329
|
+
files: contextFiles,
|
|
330
|
+
references: contextFiles.map((file) => ({
|
|
331
|
+
kind: file.kind,
|
|
332
|
+
path: file.path,
|
|
333
|
+
sha256: file.sha256,
|
|
334
|
+
bytes: file.bytes,
|
|
335
|
+
})),
|
|
336
|
+
cacheDir: sharedContextCacheDir,
|
|
337
|
+
});
|
|
338
|
+
const stablePayload = {
|
|
339
|
+
task_kind: taskKind,
|
|
340
|
+
queue_sha256: decisionTaskQueueSha256(queueRows),
|
|
341
|
+
queue_rows: queueRows.length,
|
|
342
|
+
contract_context_files: contractFiles,
|
|
343
|
+
missing_context_files: contractContext.missing,
|
|
344
|
+
provenance_context: decisionTaskProvenanceFileDetails(provenanceContext),
|
|
345
|
+
attached_input_rows: attachedInputRows.map((row) => ({
|
|
346
|
+
input_rows: row.input_rows,
|
|
347
|
+
input_row_index: row.index,
|
|
348
|
+
row_type: row.row_type,
|
|
349
|
+
dataset_id: row.dataset_id,
|
|
350
|
+
dataset_version: row.dataset_version,
|
|
351
|
+
})),
|
|
352
|
+
shared_context_bundle_sha256: sharedContextBundle.sha256,
|
|
353
|
+
};
|
|
354
|
+
return {
|
|
355
|
+
...stablePayload,
|
|
356
|
+
task: repoRelativePath(taskPath),
|
|
357
|
+
queue: repoRelativePath(queuePath),
|
|
358
|
+
shared_context_bundle: sharedContextBundle,
|
|
359
|
+
hash_scope: "task_kind, normalized queue_sha256, queue_rows, contract_context_files, missing_context_files, provenance_context, attached_input_rows, and shared_context_bundle_sha256; task path, queue path, and generated output_rows paths are excluded.",
|
|
360
|
+
sha256: sha256Text(JSON.stringify(stablePayload)),
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function decisionAuthoringContext(contextBundle) {
|
|
364
|
+
return {
|
|
365
|
+
task: contextBundle.task,
|
|
366
|
+
context_bundle_sha256: contextBundle.sha256,
|
|
367
|
+
required_context_kinds: unique(contextBundle.contract_context_files.map((file) => file.kind)),
|
|
368
|
+
context_files: contextBundle.contract_context_files.map((file) => ({
|
|
369
|
+
kind: file.kind,
|
|
370
|
+
path: file.path,
|
|
371
|
+
sha256: file.sha256,
|
|
372
|
+
})),
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function classificationDecisionTaskContextKind(kind, filePath) {
|
|
376
|
+
const baseName = path.basename(String(filePath || "")).toLowerCase();
|
|
377
|
+
if (baseName === "schema.json")
|
|
378
|
+
return "schema";
|
|
379
|
+
if (baseName === "methodology.yaml" || baseName === "methodology.yml") {
|
|
380
|
+
return "methodology_yaml";
|
|
381
|
+
}
|
|
382
|
+
if (baseName === "runtime-ruleset.json")
|
|
383
|
+
return "ruleset";
|
|
384
|
+
if (baseName === "tidas_locations_category.json")
|
|
385
|
+
return "location_schema";
|
|
386
|
+
if (/^tidas_.*_category\.json$/u.test(baseName)) {
|
|
387
|
+
return "classification_schema";
|
|
388
|
+
}
|
|
389
|
+
return kind;
|
|
390
|
+
}
|
|
391
|
+
function buildClassificationDecisionTaskContextFiles(options) {
|
|
392
|
+
const inputs = [
|
|
393
|
+
["schema", options.schemaFile],
|
|
394
|
+
["methodology_yaml", options.yamlFile],
|
|
395
|
+
["ruleset", options.rulesetFile],
|
|
396
|
+
["context", options.contextFile],
|
|
397
|
+
["classification_schema", options.classificationSchema],
|
|
398
|
+
["location_schema", options.locationSchema],
|
|
399
|
+
];
|
|
400
|
+
const files = [];
|
|
401
|
+
const missing = [];
|
|
402
|
+
for (const [defaultKind, optionValue] of inputs) {
|
|
403
|
+
for (const filePath of normalizedList(optionValue)) {
|
|
404
|
+
const resolved = resolveRepoPath(filePath);
|
|
405
|
+
const kind = classificationDecisionTaskContextKind(defaultKind, filePath);
|
|
406
|
+
if (!resolved || !fileExists(resolved)) {
|
|
407
|
+
missing.push({ kind, path: filePath });
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
const text = readText(resolved);
|
|
411
|
+
files.push({
|
|
412
|
+
kind,
|
|
413
|
+
path: repoRelativePath(resolved),
|
|
414
|
+
sha256: sha256Text(text),
|
|
415
|
+
bytes: Buffer.byteLength(text, "utf8"),
|
|
416
|
+
text,
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return { files, missing };
|
|
421
|
+
}
|
|
422
|
+
function decisionTaskContextBlockers({ kind, queueRows, contractContext, requiredContextKinds, attachedInputRowCount, }) {
|
|
423
|
+
if (queueRows.length === 0)
|
|
424
|
+
return [];
|
|
425
|
+
const blockers = [];
|
|
426
|
+
const availableKinds = new Set(contractContext.files.filter((file) => Number(file.bytes) > 0).map((file) => file.kind));
|
|
427
|
+
for (const missingFile of contractContext.missing) {
|
|
428
|
+
blockers.push({
|
|
429
|
+
code: `${kind}_decision_task_context_file_missing`,
|
|
430
|
+
message: "Decision task cannot be sent to AI while a referenced context file is missing.",
|
|
431
|
+
kind: missingFile.kind,
|
|
432
|
+
path: missingFile.path,
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
for (const file of contractContext.files) {
|
|
436
|
+
if (Number(file.bytes) === 0) {
|
|
437
|
+
blockers.push({
|
|
438
|
+
code: `${kind}_decision_task_context_file_empty`,
|
|
439
|
+
message: "Decision task cannot be sent to AI with an empty context file.",
|
|
440
|
+
kind: file.kind,
|
|
441
|
+
path: file.path,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
for (const requiredKind of requiredContextKinds) {
|
|
446
|
+
if (!availableKinds.has(requiredKind)) {
|
|
447
|
+
blockers.push({
|
|
448
|
+
code: `${kind}_decision_task_required_context_missing`,
|
|
449
|
+
message: "Decision task must include the full schema/YAML/ruleset/category context before AI authoring.",
|
|
450
|
+
kind: requiredKind,
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const missingInputRows = queueRows.length - attachedInputRowCount;
|
|
455
|
+
if (missingInputRows > 0) {
|
|
456
|
+
blockers.push({
|
|
457
|
+
code: `${kind}_decision_task_input_row_payload_missing`,
|
|
458
|
+
message: "Decision task must attach the converted TIDAS row payload for every queued item before AI authoring.",
|
|
459
|
+
missing_input_row_payloads: missingInputRows,
|
|
460
|
+
queue_rows: queueRows.length,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
return blockers;
|
|
464
|
+
}
|
|
465
|
+
function decisionTaskBuildStatus({ queueRows, blockers, readyStatus, emptyStatus, }) {
|
|
466
|
+
if (queueRows.length === 0)
|
|
467
|
+
return emptyStatus;
|
|
468
|
+
if (blockers.length > 0)
|
|
469
|
+
return "blocked_missing_full_context";
|
|
470
|
+
return readyStatus;
|
|
471
|
+
}
|
|
472
|
+
function decisionTaskOptionPath(options, kind) {
|
|
473
|
+
if (kind === "classification") {
|
|
474
|
+
return (options.decisionTask ||
|
|
475
|
+
options.classificationDecisionTask ||
|
|
476
|
+
options.classificationTask ||
|
|
477
|
+
options.taskReport ||
|
|
478
|
+
options.task);
|
|
479
|
+
}
|
|
480
|
+
return (options.decisionTask ||
|
|
481
|
+
options.locationDecisionTask ||
|
|
482
|
+
options.locationTask ||
|
|
483
|
+
options.taskReport ||
|
|
484
|
+
options.task);
|
|
485
|
+
}
|
|
486
|
+
function decisionTaskOptionPaths(options, kind) {
|
|
487
|
+
return normalizedList(decisionTaskOptionPath(options, kind));
|
|
488
|
+
}
|
|
489
|
+
function readDecisionTaskSharedContextBundleProof(task, proofPath) {
|
|
490
|
+
const contextBundle = task?.context_bundle ?? task?.authoring_context ?? {};
|
|
491
|
+
const sharedContext = task?.shared_context_bundle ?? contextBundle?.shared_context_bundle ?? {};
|
|
492
|
+
const sharedPath = asText(sharedContext?.path ?? task?.files?.shared_context_bundle);
|
|
493
|
+
const expectedSha256 = asText(sharedContext?.sha256 ?? contextBundle?.shared_context_bundle_sha256);
|
|
494
|
+
const proof = {
|
|
495
|
+
path: sharedPath || null,
|
|
496
|
+
sha256: null,
|
|
497
|
+
expected_sha256: expectedSha256 || null,
|
|
498
|
+
counts: sharedContext?.counts ?? null,
|
|
499
|
+
files: [],
|
|
500
|
+
blockers: [],
|
|
501
|
+
};
|
|
502
|
+
if (!sharedPath)
|
|
503
|
+
return proof;
|
|
504
|
+
const resolved = resolveRepoPath(sharedPath);
|
|
505
|
+
if (!resolved || !fileExists(resolved)) {
|
|
506
|
+
proof.blockers.push({
|
|
507
|
+
code: "decision_task_shared_context_bundle_missing",
|
|
508
|
+
message: "Decision task references an unreadable shared full-context bundle.",
|
|
509
|
+
decision_task: proofPath,
|
|
510
|
+
shared_context_bundle: sharedPath,
|
|
511
|
+
});
|
|
512
|
+
return proof;
|
|
513
|
+
}
|
|
514
|
+
try {
|
|
515
|
+
const bundle = readJson(resolved);
|
|
516
|
+
proof.sha256 = asText(bundle?.sha256);
|
|
517
|
+
proof.files = ensureArray(bundle?.files);
|
|
518
|
+
proof.counts = bundle?.counts ?? proof.counts;
|
|
519
|
+
if (expectedSha256 && proof.sha256 !== expectedSha256) {
|
|
520
|
+
proof.blockers.push({
|
|
521
|
+
code: "decision_task_shared_context_bundle_hash_mismatch",
|
|
522
|
+
message: "Decision task shared context bundle sha256 no longer matches the task reference.",
|
|
523
|
+
decision_task: proofPath,
|
|
524
|
+
shared_context_bundle: sharedPath,
|
|
525
|
+
expected_sha256: expectedSha256,
|
|
526
|
+
actual_sha256: proof.sha256 || null,
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
catch (error) {
|
|
531
|
+
proof.blockers.push({
|
|
532
|
+
code: "decision_task_shared_context_bundle_invalid",
|
|
533
|
+
message: error instanceof Error ? error.message : String(error),
|
|
534
|
+
decision_task: proofPath,
|
|
535
|
+
shared_context_bundle: sharedPath,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
return proof;
|
|
539
|
+
}
|
|
540
|
+
function readDecisionTaskProofFromPath(taskPathInput, kind, queuePath) {
|
|
541
|
+
const taskPath = resolveRepoPath(taskPathInput);
|
|
542
|
+
if (!taskPath)
|
|
543
|
+
return null;
|
|
544
|
+
const proof = {
|
|
545
|
+
path: repoRelativePath(taskPath),
|
|
546
|
+
sha256: null,
|
|
547
|
+
status: null,
|
|
548
|
+
task_kind: null,
|
|
549
|
+
context_bundle_sha256: null,
|
|
550
|
+
queue: null,
|
|
551
|
+
source_queue: null,
|
|
552
|
+
contract_context_files: [],
|
|
553
|
+
missing_context_files: [],
|
|
554
|
+
shared_context_bundle: null,
|
|
555
|
+
blockers: [],
|
|
556
|
+
};
|
|
557
|
+
if (!fileExists(taskPath)) {
|
|
558
|
+
proof.blockers.push({
|
|
559
|
+
code: `${kind}_decision_task_missing`,
|
|
560
|
+
message: "Decision apply was given an unreadable AI decision task file.",
|
|
561
|
+
decision_task: proof.path,
|
|
562
|
+
});
|
|
563
|
+
return proof;
|
|
564
|
+
}
|
|
565
|
+
try {
|
|
566
|
+
const rawText = readText(taskPath);
|
|
567
|
+
proof.sha256 = sha256Text(rawText);
|
|
568
|
+
const task = JSON.parse(rawText);
|
|
569
|
+
const contextBundle = task.context_bundle ?? task.authoring_context;
|
|
570
|
+
proof.status = asText(task.status);
|
|
571
|
+
proof.task_kind = asText(task.task_kind);
|
|
572
|
+
proof.context_bundle_sha256 = asText(contextBundle?.sha256 ?? contextBundle?.context_bundle_sha256);
|
|
573
|
+
proof.queue = asText(kind === "classification" ? task.classification_queue : task.location_queue);
|
|
574
|
+
proof.source_queue = asText(kind === "classification" ? task.source_classification_queue : task.source_location_queue);
|
|
575
|
+
proof.contract_context_files = ensureArray(task.contract_context_files);
|
|
576
|
+
proof.missing_context_files = ensureArray(task.missing_context_files);
|
|
577
|
+
proof.context_bundle = contextBundle ?? null;
|
|
578
|
+
proof.shared_context_bundle = readDecisionTaskSharedContextBundleProof(task, proof.path);
|
|
579
|
+
proof.blockers.push(...proof.shared_context_bundle.blockers);
|
|
580
|
+
if (kind === "classification" && proof.task_kind !== "classification_decision_authoring") {
|
|
581
|
+
proof.blockers.push({
|
|
582
|
+
code: "classification_decision_task_kind_invalid",
|
|
583
|
+
message: "Classification decisions must be bound to a classification decision task.",
|
|
584
|
+
task_kind: proof.task_kind,
|
|
585
|
+
decision_task: proof.path,
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
if (kind === "location" && proof.task_kind !== "location_decision_authoring") {
|
|
589
|
+
proof.blockers.push({
|
|
590
|
+
code: "location_decision_task_kind_invalid",
|
|
591
|
+
message: "Location decisions must be bound to a location decision task.",
|
|
592
|
+
task_kind: proof.task_kind,
|
|
593
|
+
decision_task: proof.path,
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
const taskQueuePath = resolveRepoPath(proof.queue);
|
|
597
|
+
const sourceQueuePath = resolveRepoPath(proof.source_queue);
|
|
598
|
+
if (!sameResolvedPath(taskQueuePath, queuePath) &&
|
|
599
|
+
!sameResolvedPath(sourceQueuePath, queuePath)) {
|
|
600
|
+
proof.blockers.push({
|
|
601
|
+
code: `${kind}_decision_task_queue_mismatch`,
|
|
602
|
+
message: "Decision task queue does not match the queue being applied.",
|
|
603
|
+
decision_task: proof.path,
|
|
604
|
+
task_queue: proof.queue,
|
|
605
|
+
source_queue: proof.source_queue,
|
|
606
|
+
apply_queue: repoRelativePath(queuePath),
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
if (!proof.context_bundle_sha256) {
|
|
610
|
+
proof.blockers.push({
|
|
611
|
+
code: `${kind}_decision_task_context_bundle_missing`,
|
|
612
|
+
message: "Decision task must include context_bundle.sha256 so AI output can be tied to the exact context bundle.",
|
|
613
|
+
decision_task: proof.path,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
if (proof.missing_context_files.length > 0) {
|
|
617
|
+
proof.blockers.push({
|
|
618
|
+
code: `${kind}_decision_task_context_files_missing`,
|
|
619
|
+
message: "Decision task records missing context files and cannot prove full-context AI completion.",
|
|
620
|
+
decision_task: proof.path,
|
|
621
|
+
missing_context_files: proof.missing_context_files,
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
catch (error) {
|
|
626
|
+
proof.blockers.push({
|
|
627
|
+
code: `${kind}_decision_task_invalid`,
|
|
628
|
+
message: error instanceof Error ? error.message : String(error),
|
|
629
|
+
decision_task: proof.path,
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
return proof;
|
|
633
|
+
}
|
|
634
|
+
function readDecisionTaskProof(options, kind, queuePath) {
|
|
635
|
+
const [taskPath] = decisionTaskOptionPaths(options, kind);
|
|
636
|
+
return taskPath ? readDecisionTaskProofFromPath(taskPath, kind, queuePath) : null;
|
|
637
|
+
}
|
|
638
|
+
function readDecisionTaskProofs(options, kind, queuePath) {
|
|
639
|
+
return decisionTaskOptionPaths(options, kind)
|
|
640
|
+
.map((taskPath) => readDecisionTaskProofFromPath(taskPath, kind, queuePath))
|
|
641
|
+
.filter((proof) => proof !== null);
|
|
642
|
+
}
|
|
643
|
+
function decisionContextBundleSha256(decision) {
|
|
644
|
+
return asText(decision?.authoring_context?.context_bundle_sha256 ??
|
|
645
|
+
decision?.authoringContext?.contextBundleSha256 ??
|
|
646
|
+
decision?.authoring_context_sha256 ??
|
|
647
|
+
decision?.context_bundle_sha256 ??
|
|
648
|
+
decision?.contextBundleSha256);
|
|
649
|
+
}
|
|
650
|
+
function decisionCompletionStatus(decision) {
|
|
651
|
+
return asText(decision?.decision_status ?? decision?.decisionStatus ?? decision?.status);
|
|
652
|
+
}
|
|
653
|
+
function decisionTaskReportPayload(proof) {
|
|
654
|
+
if (!proof)
|
|
655
|
+
return null;
|
|
656
|
+
return {
|
|
657
|
+
path: proof.path,
|
|
658
|
+
sha256: proof.sha256,
|
|
659
|
+
status: proof.status,
|
|
660
|
+
task_kind: proof.task_kind,
|
|
661
|
+
queue: proof.queue,
|
|
662
|
+
source_queue: proof.source_queue,
|
|
663
|
+
context_bundle_sha256: proof.context_bundle_sha256,
|
|
664
|
+
contract_context_files: proof.contract_context_files.map((file) => ({
|
|
665
|
+
kind: file.kind,
|
|
666
|
+
path: file.path,
|
|
667
|
+
sha256: file.sha256,
|
|
668
|
+
bytes: file.bytes,
|
|
669
|
+
})),
|
|
670
|
+
missing_context_files: proof.missing_context_files,
|
|
671
|
+
shared_context_bundle: proof.shared_context_bundle
|
|
672
|
+
? {
|
|
673
|
+
path: proof.shared_context_bundle.path,
|
|
674
|
+
sha256: proof.shared_context_bundle.sha256,
|
|
675
|
+
expected_sha256: proof.shared_context_bundle.expected_sha256,
|
|
676
|
+
counts: proof.shared_context_bundle.counts,
|
|
677
|
+
}
|
|
678
|
+
: null,
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
function decisionTaskProofList(proofOrProofs) {
|
|
682
|
+
return ensureArray(proofOrProofs).filter((proof) => proof !== null && proof !== undefined);
|
|
683
|
+
}
|
|
684
|
+
function decisionTaskContextBundleHashes(proofs) {
|
|
685
|
+
return unique(decisionTaskProofList(proofs).map((proof) => proof.context_bundle_sha256));
|
|
686
|
+
}
|
|
687
|
+
return {
|
|
688
|
+
classificationQueueSchemaType,
|
|
689
|
+
classificationQueueRowType,
|
|
690
|
+
classificationQueueInputRows,
|
|
691
|
+
classificationQueueOutputRows,
|
|
692
|
+
queueRowSourceFile,
|
|
693
|
+
queueRowBundleId,
|
|
694
|
+
hasQueueSelectionOptions,
|
|
695
|
+
queueSelectionSummary,
|
|
696
|
+
queueRowMatchesSelection,
|
|
697
|
+
selectDecisionTaskQueueRows,
|
|
698
|
+
safeFileToken,
|
|
699
|
+
decisionTaskChunkLabel,
|
|
700
|
+
rewriteDecisionTaskQueueRowsForChunk,
|
|
701
|
+
decisionTaskInputRowsOverride,
|
|
702
|
+
classificationDecisionSchemaType,
|
|
703
|
+
classificationDecisionTargetKey,
|
|
704
|
+
classificationQueueTargetKey,
|
|
705
|
+
classificationDecisionCode,
|
|
706
|
+
classificationDecisionUsedContextKinds,
|
|
707
|
+
readClassificationTaskJsonlContextRows,
|
|
708
|
+
buildClassificationTaskProvenanceContext,
|
|
709
|
+
decisionTaskContextFileDetails,
|
|
710
|
+
decisionTaskContextFileWithText,
|
|
711
|
+
decisionTaskContextFileSummary,
|
|
712
|
+
dedupeDecisionTaskContextFiles,
|
|
713
|
+
writeDecisionTaskSharedContextBundle,
|
|
714
|
+
stableDecisionTaskQueueRows,
|
|
715
|
+
decisionTaskQueueSha256,
|
|
716
|
+
decisionTaskProvenanceFileDetails,
|
|
717
|
+
buildDecisionTaskContextBundle,
|
|
718
|
+
decisionAuthoringContext,
|
|
719
|
+
classificationDecisionTaskContextKind,
|
|
720
|
+
buildClassificationDecisionTaskContextFiles,
|
|
721
|
+
decisionTaskContextBlockers,
|
|
722
|
+
decisionTaskBuildStatus,
|
|
723
|
+
decisionTaskOptionPath,
|
|
724
|
+
decisionTaskOptionPaths,
|
|
725
|
+
readDecisionTaskSharedContextBundleProof,
|
|
726
|
+
readDecisionTaskProofFromPath,
|
|
727
|
+
readDecisionTaskProof,
|
|
728
|
+
readDecisionTaskProofs,
|
|
729
|
+
decisionContextBundleSha256,
|
|
730
|
+
decisionCompletionStatus,
|
|
731
|
+
decisionTaskReportPayload,
|
|
732
|
+
decisionTaskProofList,
|
|
733
|
+
decisionTaskContextBundleHashes,
|
|
734
|
+
};
|
|
735
|
+
}
|