@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,854 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { datasetTypePlural, supportedDatasetTypes } from "./dataset-types.js";
|
|
4
|
+
import { sha256Text } from "./hash-utils.js";
|
|
5
|
+
import { annualSupplyMissingDataSentinelText } from "./prewrite-cleanup.js";
|
|
6
|
+
import { asText, ensureArray, fileExists, jsonLines, nowIso, readJson, readText, repoRelativePath, resolveRepoPath, sanitizeFileName, unique, writeJson, writeText, } from "./runtime-io.js";
|
|
7
|
+
import { buildPatchTemplate, contextSummaryHasKind, contextSummaryHasNonEmptyPayload, contextSummaryHasPattern, decisionOnlyActionItems, fullContextAiConfigRequiresAuthoring, markdownList, packageContextFileSummary, patchAuthoringActionItems, relOrNull, requiredFullContextFilePatterns, requiredFullContextKinds, sharedContextBundleReadinessBlockers, } from "./workflow-semantic-actions.js";
|
|
8
|
+
function isRecord(value) {
|
|
9
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
function asRecord(value) {
|
|
12
|
+
return isRecord(value) ? value : {};
|
|
13
|
+
}
|
|
14
|
+
// part-03.mjs
|
|
15
|
+
export function authoringPackageFullContextReadinessBlockers({ repoRoot, packagePayload, actionItems, packagePath = null, }) {
|
|
16
|
+
const typedPackage = asRecord(packagePayload);
|
|
17
|
+
if (ensureArray(actionItems).length === 0)
|
|
18
|
+
return [];
|
|
19
|
+
const requirement = typedPackage.full_context_ai_completion;
|
|
20
|
+
if (!fullContextAiConfigRequiresAuthoring(requirement))
|
|
21
|
+
return [];
|
|
22
|
+
const blockers = [];
|
|
23
|
+
const authoringPackage = packagePath ? repoRelativePath(repoRoot, packagePath) : null;
|
|
24
|
+
const contractFiles = ensureArray(typedPackage.contract_context_files);
|
|
25
|
+
for (const missingContext of ensureArray(typedPackage.missing_context_files)) {
|
|
26
|
+
const typedContext = asRecord(missingContext);
|
|
27
|
+
blockers.push({
|
|
28
|
+
code: "authoring_task_context_file_missing",
|
|
29
|
+
message: "AI authoring task cannot start while its authoring package records missing context files.",
|
|
30
|
+
authoring_package: authoringPackage,
|
|
31
|
+
kind: asText(typedContext.kind) || null,
|
|
32
|
+
path: asText(typedContext.path) || null,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
for (const file of contractFiles) {
|
|
36
|
+
const typedFile = asRecord(file);
|
|
37
|
+
if (!contextSummaryHasNonEmptyPayload(file)) {
|
|
38
|
+
blockers.push({
|
|
39
|
+
code: "authoring_task_context_file_empty",
|
|
40
|
+
message: "AI authoring task cannot start with an empty contract context file.",
|
|
41
|
+
authoring_package: authoringPackage,
|
|
42
|
+
kind: asText(typedFile.kind) || null,
|
|
43
|
+
path: asText(typedFile.path) || null,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const kind of requiredFullContextKinds(requirement)) {
|
|
48
|
+
if (!contextSummaryHasKind(contractFiles, kind)) {
|
|
49
|
+
blockers.push({
|
|
50
|
+
code: "authoring_task_required_context_missing",
|
|
51
|
+
message: "AI authoring task must include full schema/YAML/ruleset/category/location context before patch authoring.",
|
|
52
|
+
authoring_package: authoringPackage,
|
|
53
|
+
required_kind: kind,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const pattern of requiredFullContextFilePatterns(requirement)) {
|
|
58
|
+
if (!contextSummaryHasPattern(contractFiles, pattern)) {
|
|
59
|
+
blockers.push({
|
|
60
|
+
code: "authoring_task_required_context_file_missing",
|
|
61
|
+
message: "AI authoring task must include the required full-context file before patch authoring.",
|
|
62
|
+
authoring_package: authoringPackage,
|
|
63
|
+
required_file_pattern: pattern,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (!typedPackage.source_row ||
|
|
68
|
+
typeof typedPackage.source_row !== "object" ||
|
|
69
|
+
Array.isArray(typedPackage.source_row)) {
|
|
70
|
+
blockers.push({
|
|
71
|
+
code: "authoring_task_source_row_payload_missing",
|
|
72
|
+
message: "AI authoring task must include the source row payload used as evidence.",
|
|
73
|
+
authoring_package: authoringPackage,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (!typedPackage.entity_payload ||
|
|
77
|
+
typeof typedPackage.entity_payload !== "object" ||
|
|
78
|
+
Array.isArray(typedPackage.entity_payload)) {
|
|
79
|
+
blockers.push({
|
|
80
|
+
code: "authoring_task_entity_payload_missing",
|
|
81
|
+
message: "AI authoring task must include the converted TIDAS entity payload to patch.",
|
|
82
|
+
authoring_package: authoringPackage,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return blockers;
|
|
86
|
+
}
|
|
87
|
+
export function authoringTaskFullContextReadinessBlockers({ repoRoot, task, }) {
|
|
88
|
+
const typedTask = asRecord(task);
|
|
89
|
+
const context = asRecord(typedTask.context);
|
|
90
|
+
const files = asRecord(typedTask.files);
|
|
91
|
+
if (ensureArray(typedTask.action_items).length === 0)
|
|
92
|
+
return [];
|
|
93
|
+
const requirement = context.full_context_ai_completion;
|
|
94
|
+
if (!fullContextAiConfigRequiresAuthoring(requirement))
|
|
95
|
+
return [];
|
|
96
|
+
const blockers = [];
|
|
97
|
+
const contractFiles = ensureArray(context.contract_context_files);
|
|
98
|
+
blockers.push(...sharedContextBundleReadinessBlockers({
|
|
99
|
+
repoRoot,
|
|
100
|
+
sharedContextBundle: context.shared_context_bundle,
|
|
101
|
+
sourceKind: "task",
|
|
102
|
+
sourcePath: asText(files.task_json) || null,
|
|
103
|
+
}));
|
|
104
|
+
for (const missingContext of ensureArray(context.missing_context_files)) {
|
|
105
|
+
const typedContext = asRecord(missingContext);
|
|
106
|
+
blockers.push({
|
|
107
|
+
code: "authoring_task_context_file_missing",
|
|
108
|
+
message: "AI patch collect cannot accept a task whose context files were missing at authoring time.",
|
|
109
|
+
kind: asText(typedContext.kind) || null,
|
|
110
|
+
path: asText(typedContext.path) || null,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
for (const kind of requiredFullContextKinds(requirement)) {
|
|
114
|
+
if (!contextSummaryHasKind(contractFiles, kind)) {
|
|
115
|
+
blockers.push({
|
|
116
|
+
code: "authoring_task_required_context_missing",
|
|
117
|
+
message: "AI patch collect requires the authoring task to carry full schema/YAML/ruleset/category/location context.",
|
|
118
|
+
required_kind: kind,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const pattern of requiredFullContextFilePatterns(requirement)) {
|
|
123
|
+
if (!contextSummaryHasPattern(contractFiles, pattern)) {
|
|
124
|
+
blockers.push({
|
|
125
|
+
code: "authoring_task_required_context_file_missing",
|
|
126
|
+
message: "AI patch collect requires the authoring task to carry every required full-context file.",
|
|
127
|
+
required_file_pattern: pattern,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const packagePath = resolveRepoPath(repoRoot, asText(files.authoring_package));
|
|
132
|
+
if (!packagePath || !fileExists(packagePath)) {
|
|
133
|
+
blockers.push({
|
|
134
|
+
code: "authoring_task_authoring_package_missing",
|
|
135
|
+
message: "AI patch collect cannot verify full-context readiness without the authoring package.",
|
|
136
|
+
authoring_package: files.authoring_package ?? null,
|
|
137
|
+
});
|
|
138
|
+
return blockers;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const packagePayload = readJson(packagePath);
|
|
142
|
+
blockers.push(...authoringPackageFullContextReadinessBlockers({
|
|
143
|
+
repoRoot,
|
|
144
|
+
packagePayload,
|
|
145
|
+
actionItems: typedTask.action_items,
|
|
146
|
+
packagePath,
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
blockers.push({
|
|
151
|
+
code: "authoring_task_authoring_package_invalid",
|
|
152
|
+
message: error instanceof Error ? error.message : String(error),
|
|
153
|
+
authoring_package: files.authoring_package ?? null,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return blockers;
|
|
157
|
+
}
|
|
158
|
+
export function shellQuote(value) {
|
|
159
|
+
const text = String(value ?? "");
|
|
160
|
+
if (/^[A-Za-z0-9_./:@%+=,-]+$/u.test(text))
|
|
161
|
+
return text;
|
|
162
|
+
return `'${text.replace(/'/gu, `'\\''`)}'`;
|
|
163
|
+
}
|
|
164
|
+
export function renderAuthoringTaskMarkdown(task) {
|
|
165
|
+
const actionItems = task.action_items.map((item) => {
|
|
166
|
+
const lines = [
|
|
167
|
+
`- [${item.index}] ${item.code}`,
|
|
168
|
+
` - path: ${item.path ?? "(AI must choose path)"}`,
|
|
169
|
+
` - json_pointer: ${item.json_pointer}`,
|
|
170
|
+
` - message: ${item.message ?? "(none)"}`,
|
|
171
|
+
];
|
|
172
|
+
if (item.instruction)
|
|
173
|
+
lines.push(` - instruction: ${item.instruction}`);
|
|
174
|
+
if (ensureArray(item.allowed_resolution_modes).length > 0) {
|
|
175
|
+
lines.push(` - allowed_resolution_modes: ${item.allowed_resolution_modes.join(", ")}`);
|
|
176
|
+
}
|
|
177
|
+
if (item.evidence !== null && item.evidence !== undefined) {
|
|
178
|
+
lines.push(` - evidence: ${JSON.stringify(item.evidence)}`);
|
|
179
|
+
}
|
|
180
|
+
return lines.join("\n");
|
|
181
|
+
});
|
|
182
|
+
const contextFiles = [
|
|
183
|
+
...task.context.profile_context_files,
|
|
184
|
+
...task.context.contract_context_files,
|
|
185
|
+
].map((file) => `${file.kind}: ${file.path} (${file.bytes} bytes, sha256=${file.sha256})`);
|
|
186
|
+
const sharedContextBundle = task.context?.shared_context_bundle;
|
|
187
|
+
const sharedContextLines = sharedContextBundle
|
|
188
|
+
? [
|
|
189
|
+
`- shared context bundle: ${sharedContextBundle.path} (sha256=${sharedContextBundle.sha256})`,
|
|
190
|
+
`- shared context files: ${sharedContextBundle.counts?.files ?? "(unknown)"}`,
|
|
191
|
+
`- duplicate context bytes avoided: ${sharedContextBundle.counts?.duplicate_context_bytes_avoided ?? 0}`,
|
|
192
|
+
]
|
|
193
|
+
: [];
|
|
194
|
+
const sharedContextInstruction = sharedContextBundle
|
|
195
|
+
? "\nIf a shared context bundle is listed above, read it once for the batch-level full schema/YAML/ruleset/category/location text. Still read the entity authoring package for source row, entity payload, action items, support rows, queue/dependency closure, and hash-bound proof. Do not treat the shared bundle as a replacement for package lineage or action-item evidence.\n"
|
|
196
|
+
: "";
|
|
197
|
+
return `# Foundry AI Authoring Task
|
|
198
|
+
|
|
199
|
+
Status: ${task.status}
|
|
200
|
+
|
|
201
|
+
## Entity
|
|
202
|
+
|
|
203
|
+
- type: ${task.entity.dataset_type}
|
|
204
|
+
- id: ${task.entity.entity_id}
|
|
205
|
+
- version: ${task.entity.version}
|
|
206
|
+
- profile: ${task.entity.profile}
|
|
207
|
+
|
|
208
|
+
## Required Inputs
|
|
209
|
+
|
|
210
|
+
- authoring package: ${task.files.authoring_package}
|
|
211
|
+
- source rows file: ${task.context.source_rows_file ?? "(not recorded)"}
|
|
212
|
+
- patch template: ${task.files.patch_template}
|
|
213
|
+
- output patch file: ${task.files.output_patch_file}
|
|
214
|
+
${sharedContextLines.length > 0 ? sharedContextLines.join("\n") : ""}
|
|
215
|
+
|
|
216
|
+
Read the full authoring package before writing the patch. It contains the converted row, source row, schema issues, QA findings, profile constraints, queue/dependency closure, support rows, bundled TIDAS taxonomy/location schemas, and full contract context text when supplied by the SDK/CLI.
|
|
217
|
+
${sharedContextInstruction}
|
|
218
|
+
|
|
219
|
+
## Context Files
|
|
220
|
+
|
|
221
|
+
${markdownList(contextFiles)}
|
|
222
|
+
|
|
223
|
+
## Action Items
|
|
224
|
+
|
|
225
|
+
${actionItems.length > 0 ? actionItems.join("\n") : "- none"}
|
|
226
|
+
|
|
227
|
+
## Output Contract
|
|
228
|
+
|
|
229
|
+
Write a structured patch JSON to:
|
|
230
|
+
|
|
231
|
+
\`${task.files.output_patch_file}\`
|
|
232
|
+
|
|
233
|
+
The patch must:
|
|
234
|
+
|
|
235
|
+
- target this dataset id/version or row_index
|
|
236
|
+
- keep \`authoring_package\` set to the package filename
|
|
237
|
+
- treat template paths as suggestions and fix JSON Pointers against the actual authoring package row
|
|
238
|
+
- provide \`basis\` or \`evidence\` for every non-test operation
|
|
239
|
+
- for full-context tasks, provide both \`basis\` and structured \`evidence\` with a source/context identifier plus \`quote_or_trace\`, source path, field path, citation, or equivalent pointer
|
|
240
|
+
- provide \`resolution.mode\` for every non-test operation; use one of the action item's allowed modes
|
|
241
|
+
- include \`resolution.used_context_kinds\` with every full-context kind required by the task, normally \`schema\`, \`methodology_yaml\`, \`ruleset\`, \`classification_schema\`, and \`location_schema\`
|
|
242
|
+
- close every AI-required action item with \`closes_action_items\`
|
|
243
|
+
- for full-context import profiles, every non-test operation must include \`closes_action_items\`; supporting cleanup operations should close the same action item they are needed to resolve
|
|
244
|
+
- avoid database writes, direct Supabase calls, or hand-edited row files
|
|
245
|
+
- preserve source-language content and provide evidence-backed English for fields required by the current TIDAS/profile contract; keep the same factual meaning
|
|
246
|
+
- do not use \`common:other\` as a substitute for mandatory schema fields; schema-required values need evidence-backed values or must remain blocked
|
|
247
|
+
- if a value cannot be inferred safely and the action item's allowed modes include \`deferred_to_common_other\`, add \`common:other.tiangongfoundry:unresolvedTrace\` with \`status\`, \`action_item_code\`, \`blocked_path\`, \`reason\`, structured \`evidence\`, and \`next_action\`; evidence must include source plus quote/trace/path/citation pointer
|
|
248
|
+
- do not defer \`annualSupplyOrProductionVolume\` to \`common:other\`; if source annual volume evidence is missing, Foundry deterministic cleanup writes \`${annualSupplyMissingDataSentinelText}\` into the required field for later database-side curation
|
|
249
|
+
- if source exchange completeness is being accepted as source-faithful, use \`resolution.mode=source_trace_verified\` and add \`common:other.tiangongfoundry:sourceExchangeCompleteness\` with accepted \`status\` and structured source trace evidence; evidence must include source plus quote/trace/path/citation pointer
|
|
250
|
+
|
|
251
|
+
## Deterministic Apply
|
|
252
|
+
|
|
253
|
+
${task.commands.apply_patch ? `\`\`\`bash\n${task.commands.apply_patch}\n\`\`\`` : "Prepare the completed patch file for review. Apply it only through a structured next action from the public task; do not invoke a developer source runner."}
|
|
254
|
+
|
|
255
|
+
After apply, rerun Rust tidas validation, deterministic CLI QA where relevant, Foundry cleanup, dry-run publish/save, mutation manifest, explicit commit, and post-commit \`dataset verify-remote --compare-root-payload\`.
|
|
256
|
+
`;
|
|
257
|
+
}
|
|
258
|
+
export function buildDatasetAuthoringTaskFromPackage({ repoRoot, packagePath, outDir, options = {}, }) {
|
|
259
|
+
if (!packagePath || !fileExists(packagePath)) {
|
|
260
|
+
throw new Error("--authoring-package is required and must point to a Foundry AI authoring package JSON file.");
|
|
261
|
+
}
|
|
262
|
+
const packagePayload = readJson(packagePath);
|
|
263
|
+
const datasetTypeText = asText(packagePayload.dataset_type);
|
|
264
|
+
if (!supportedDatasetTypes.has(datasetTypeText)) {
|
|
265
|
+
throw new Error(`Authoring package dataset_type must be one of ${[...supportedDatasetTypes].join(", ")}.`);
|
|
266
|
+
}
|
|
267
|
+
const datasetType = datasetTypeText;
|
|
268
|
+
const entityId = asText(packagePayload.entity_id ?? packagePayload.process_id);
|
|
269
|
+
if (!entityId) {
|
|
270
|
+
throw new Error("Authoring package is missing entity_id.");
|
|
271
|
+
}
|
|
272
|
+
const patchFile = resolveRepoPath(repoRoot, options.patchFile || options.patch || path.join(outDir, "ai-patches.json"));
|
|
273
|
+
const patchTemplateFile = path.join(outDir, "patch-template.json");
|
|
274
|
+
const taskFile = path.join(outDir, "ai-authoring-task.json");
|
|
275
|
+
const markdownFile = path.join(outDir, "ai-authoring-task.md");
|
|
276
|
+
const patchedRowsFile = resolveRepoPath(repoRoot, options.patchedRows ||
|
|
277
|
+
options.out ||
|
|
278
|
+
path.join(outDir, `${datasetTypePlural[datasetType]}.patched.jsonl`));
|
|
279
|
+
const applyDir = resolveRepoPath(repoRoot, options.applyDir || path.join(outDir, "patch-apply"));
|
|
280
|
+
const packageDir = path.dirname(packagePath);
|
|
281
|
+
const actionItems = patchAuthoringActionItems(packagePayload);
|
|
282
|
+
const decisionOnlyItems = decisionOnlyActionItems(packagePayload);
|
|
283
|
+
const contextBlockers = authoringPackageFullContextReadinessBlockers({
|
|
284
|
+
repoRoot,
|
|
285
|
+
packagePayload,
|
|
286
|
+
actionItems,
|
|
287
|
+
packagePath,
|
|
288
|
+
});
|
|
289
|
+
const patchTemplate = buildPatchTemplate(packagePayload, packagePath);
|
|
290
|
+
const sourceRowsFile = packagePayload.source_rows_file
|
|
291
|
+
? repoRelativePath(repoRoot, resolveRepoPath(repoRoot, asText(packagePayload.source_rows_file)))
|
|
292
|
+
: null;
|
|
293
|
+
const applyArgs = [
|
|
294
|
+
"node",
|
|
295
|
+
"scripts/foundry.ts",
|
|
296
|
+
"dataset-patch-apply",
|
|
297
|
+
"--input",
|
|
298
|
+
sourceRowsFile ?? "<source-rows.jsonl>",
|
|
299
|
+
"--patch",
|
|
300
|
+
relOrNull(repoRoot, patchFile),
|
|
301
|
+
"--out",
|
|
302
|
+
relOrNull(repoRoot, patchedRowsFile),
|
|
303
|
+
"--out-dir",
|
|
304
|
+
relOrNull(repoRoot, applyDir),
|
|
305
|
+
"--authoring-package-dir",
|
|
306
|
+
relOrNull(repoRoot, packageDir),
|
|
307
|
+
"--require-authoring-package",
|
|
308
|
+
"--require-action-item-closure",
|
|
309
|
+
];
|
|
310
|
+
const task = {
|
|
311
|
+
schema_version: 1,
|
|
312
|
+
generated_at_utc: nowIso(),
|
|
313
|
+
status: actionItems.length > 0 && contextBlockers.length > 0
|
|
314
|
+
? "blocked_missing_full_context"
|
|
315
|
+
: actionItems.length > 0
|
|
316
|
+
? "ready_for_ai_authoring"
|
|
317
|
+
: "ready_no_action_items",
|
|
318
|
+
purpose: "Use Codex/skill semantic judgment to turn one Foundry AI authoring package into a strict structured patch. Deterministic CLI apply and validation remain separate gates.",
|
|
319
|
+
entity: {
|
|
320
|
+
dataset_type: datasetType,
|
|
321
|
+
entity_id: entityId,
|
|
322
|
+
version: asText(packagePayload.version) || "00.00.001",
|
|
323
|
+
profile: asText(packagePayload.profile) || null,
|
|
324
|
+
},
|
|
325
|
+
context: {
|
|
326
|
+
source_rows_file: sourceRowsFile,
|
|
327
|
+
authoring_package_sha256: sha256Text(readText(packagePath)),
|
|
328
|
+
profile_context_files: packageContextFileSummary(packagePayload.profile_context_files),
|
|
329
|
+
contract_context_files: packageContextFileSummary(packagePayload.contract_context_files),
|
|
330
|
+
full_context_ai_completion: packagePayload.full_context_ai_completion ?? {
|
|
331
|
+
required: false,
|
|
332
|
+
},
|
|
333
|
+
missing_context_files: ensureArray(packagePayload.missing_context_files),
|
|
334
|
+
curation_queue_status: asRecord(packagePayload.curation_queue_context).status ?? null,
|
|
335
|
+
},
|
|
336
|
+
action_items: actionItems,
|
|
337
|
+
decision_only_action_items: decisionOnlyItems,
|
|
338
|
+
blockers: contextBlockers,
|
|
339
|
+
counts: {
|
|
340
|
+
action_items: actionItems.length,
|
|
341
|
+
decision_only_action_items: decisionOnlyItems.length,
|
|
342
|
+
blockers: contextBlockers.length,
|
|
343
|
+
},
|
|
344
|
+
policy: {
|
|
345
|
+
database_write: "forbidden_in_ai_authoring_task",
|
|
346
|
+
ai_output: "structured_patch_json_only",
|
|
347
|
+
decision_only_action_items: "Identity, classification, and location action items are not patchable here; resolve them with the dedicated deterministic decision apply commands.",
|
|
348
|
+
unresolved_trace: "If a value cannot be inferred safely and the action item allows deferral, record structured tiangongfoundry:unresolvedTrace under common:other. Mandatory schema fields need evidence-backed values or remain blocked.",
|
|
349
|
+
source_language: "Preserve source-language content. For TIDAS-required multilingual fields, add an evidence-backed English variant from full task context before write planning.",
|
|
350
|
+
},
|
|
351
|
+
files: {
|
|
352
|
+
authoring_package: repoRelativePath(repoRoot, packagePath),
|
|
353
|
+
task_json: repoRelativePath(repoRoot, taskFile),
|
|
354
|
+
task_markdown: repoRelativePath(repoRoot, markdownFile),
|
|
355
|
+
patch_template: repoRelativePath(repoRoot, patchTemplateFile),
|
|
356
|
+
output_patch_file: repoRelativePath(repoRoot, patchFile),
|
|
357
|
+
patched_rows: repoRelativePath(repoRoot, patchedRowsFile),
|
|
358
|
+
apply_dir: repoRelativePath(repoRoot, applyDir),
|
|
359
|
+
},
|
|
360
|
+
commands: {
|
|
361
|
+
apply_patch: options.includeExecutionCommands === false ? null : applyArgs.map(shellQuote).join(" "),
|
|
362
|
+
validate_after_apply: options.includeExecutionCommands === false
|
|
363
|
+
? null
|
|
364
|
+
: `node scripts/foundry.ts dataset-tidas-validate --type ${datasetType} --rows-file ${shellQuote(repoRelativePath(repoRoot, patchedRowsFile))} --out-dir ${shellQuote(path.join(repoRelativePath(repoRoot, outDir), "dataset-validate"))}`,
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
368
|
+
writeJson(patchTemplateFile, patchTemplate);
|
|
369
|
+
writeJson(taskFile, task);
|
|
370
|
+
writeText(markdownFile, renderAuthoringTaskMarkdown(task));
|
|
371
|
+
return {
|
|
372
|
+
...task,
|
|
373
|
+
files: task.files,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
export function shouldBuildAuthoringTaskFromEntity(entity, includeReady) {
|
|
377
|
+
const typedEntity = asRecord(entity);
|
|
378
|
+
if (includeReady)
|
|
379
|
+
return true;
|
|
380
|
+
const actionItemCount = Number(typedEntity.action_item_count ?? typedEntity.actionItemCount ?? 0);
|
|
381
|
+
if (actionItemCount > 0)
|
|
382
|
+
return true;
|
|
383
|
+
return String(typedEntity.status ?? "").includes("needs_foundry_ai_authoring");
|
|
384
|
+
}
|
|
385
|
+
export function authoringPackageEntriesFromGate(repoRoot, reportPath, includeReady) {
|
|
386
|
+
const report = readJson(reportPath);
|
|
387
|
+
const entities = ensureArray(report.entities ?? report.processes ?? report.flows ?? report.items);
|
|
388
|
+
return entities
|
|
389
|
+
.filter((entity) => shouldBuildAuthoringTaskFromEntity(entity, includeReady))
|
|
390
|
+
.map((entity, index) => {
|
|
391
|
+
const typedEntity = asRecord(entity);
|
|
392
|
+
const packageRef = asText(typedEntity.authoring_package ?? typedEntity.authoringPackage);
|
|
393
|
+
const packagePath = resolveRepoPath(repoRoot, packageRef);
|
|
394
|
+
const datasetType = asText(typedEntity.dataset_type ?? typedEntity.type) || "dataset";
|
|
395
|
+
const entityId = asText(typedEntity.entity_id ?? typedEntity.process_id ?? typedEntity.id) ||
|
|
396
|
+
`entity-${index + 1}`;
|
|
397
|
+
return {
|
|
398
|
+
index,
|
|
399
|
+
entity,
|
|
400
|
+
package_ref: packageRef || null,
|
|
401
|
+
package_path: packagePath,
|
|
402
|
+
task_dir_name: `${sanitizeFileName(datasetType)}-${sanitizeFileName(entityId)}`,
|
|
403
|
+
};
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
export function buildSharedAuthoringContextBundle(repoRoot, outDir, tasks, source, options = {}) {
|
|
407
|
+
const fileMap = new Map();
|
|
408
|
+
const references = [];
|
|
409
|
+
for (const task of tasks) {
|
|
410
|
+
const packageRef = task.files?.authoring_package;
|
|
411
|
+
const packagePath = resolveRepoPath(repoRoot, packageRef);
|
|
412
|
+
if (!packagePath || !fileExists(packagePath))
|
|
413
|
+
continue;
|
|
414
|
+
const stablePackageRef = packageRef ? path.basename(packageRef) : null;
|
|
415
|
+
let packagePayload = null;
|
|
416
|
+
try {
|
|
417
|
+
packagePayload = readJson(packagePath);
|
|
418
|
+
}
|
|
419
|
+
catch {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
for (const [scope, contextFiles] of [
|
|
423
|
+
["profile_context_files", packagePayload.profile_context_files],
|
|
424
|
+
["contract_context_files", packagePayload.contract_context_files],
|
|
425
|
+
]) {
|
|
426
|
+
for (const contextFile of ensureArray(contextFiles)) {
|
|
427
|
+
const typedFile = asRecord(contextFile);
|
|
428
|
+
const text = String(typedFile.text ?? "");
|
|
429
|
+
const sha256 = asText(typedFile.sha256) || sha256Text(text);
|
|
430
|
+
const bytes = Number(typedFile.bytes) || Buffer.byteLength(text, "utf8");
|
|
431
|
+
const kind = asText(typedFile.kind) || "context";
|
|
432
|
+
const contextPath = asText(typedFile.path) || null;
|
|
433
|
+
const key = JSON.stringify([scope, kind, contextPath, sha256]);
|
|
434
|
+
if (!fileMap.has(key)) {
|
|
435
|
+
fileMap.set(key, {
|
|
436
|
+
scope,
|
|
437
|
+
kind,
|
|
438
|
+
path: contextPath,
|
|
439
|
+
sha256,
|
|
440
|
+
bytes,
|
|
441
|
+
text,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
references.push({
|
|
445
|
+
authoring_package: stablePackageRef,
|
|
446
|
+
authoring_package_sha256: task.context?.authoring_package_sha256 ?? null,
|
|
447
|
+
dataset_type: task.entity?.dataset_type ?? null,
|
|
448
|
+
entity_id: task.entity?.entity_id ?? null,
|
|
449
|
+
dataset_version: task.entity?.version ?? null,
|
|
450
|
+
scope,
|
|
451
|
+
kind,
|
|
452
|
+
path: contextPath,
|
|
453
|
+
sha256,
|
|
454
|
+
bytes,
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
const files = [...fileMap.values()];
|
|
460
|
+
const uniqueBytes = files.reduce((total, file) => total + (Number(file.bytes) || 0), 0);
|
|
461
|
+
const referenceBytes = references.reduce((total, ref) => total + (Number(ref.bytes) || 0), 0);
|
|
462
|
+
const counts = {
|
|
463
|
+
tasks: tasks.length,
|
|
464
|
+
authoring_packages: unique(tasks.map((task) => path.basename(task.files.authoring_package ?? "")).filter(Boolean)).length,
|
|
465
|
+
files: files.length,
|
|
466
|
+
references: references.length,
|
|
467
|
+
duplicate_references: Math.max(0, references.length - files.length),
|
|
468
|
+
unique_context_bytes: uniqueBytes,
|
|
469
|
+
referenced_context_bytes: referenceBytes,
|
|
470
|
+
duplicate_context_bytes_avoided: Math.max(0, referenceBytes - uniqueBytes),
|
|
471
|
+
};
|
|
472
|
+
const stablePayload = {
|
|
473
|
+
schema_version: 1,
|
|
474
|
+
kind: "tiangong_foundry_shared_authoring_context_bundle",
|
|
475
|
+
source,
|
|
476
|
+
counts,
|
|
477
|
+
files,
|
|
478
|
+
references,
|
|
479
|
+
};
|
|
480
|
+
const bundle = {
|
|
481
|
+
...stablePayload,
|
|
482
|
+
generated_at_utc: nowIso(),
|
|
483
|
+
hash_scope: "schema_version, kind, source, counts, files, and references; generated_at_utc is excluded so identical batch context keeps a stable hash.",
|
|
484
|
+
sha256: sha256Text(JSON.stringify(stablePayload)),
|
|
485
|
+
};
|
|
486
|
+
const cacheDir = options.sharedContextCacheDir
|
|
487
|
+
? resolveRepoPath(repoRoot, options.sharedContextCacheDir)
|
|
488
|
+
: null;
|
|
489
|
+
const bundlePath = cacheDir
|
|
490
|
+
? path.join(cacheDir, `authoring.${bundle.sha256}.json`)
|
|
491
|
+
: path.join(outDir, "shared-context-bundle.json");
|
|
492
|
+
let cacheReused = false;
|
|
493
|
+
if (cacheDir && fileExists(bundlePath)) {
|
|
494
|
+
try {
|
|
495
|
+
cacheReused = readJson(bundlePath).sha256 === bundle.sha256;
|
|
496
|
+
}
|
|
497
|
+
catch {
|
|
498
|
+
cacheReused = false;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (!cacheReused)
|
|
502
|
+
writeJson(bundlePath, bundle);
|
|
503
|
+
return {
|
|
504
|
+
path: bundlePath,
|
|
505
|
+
bundle,
|
|
506
|
+
cache: cacheDir
|
|
507
|
+
? {
|
|
508
|
+
enabled: true,
|
|
509
|
+
dir: repoRelativePath(repoRoot, cacheDir),
|
|
510
|
+
reused: cacheReused,
|
|
511
|
+
}
|
|
512
|
+
: {
|
|
513
|
+
enabled: false,
|
|
514
|
+
reused: false,
|
|
515
|
+
},
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
export function attachSharedContextBundleToTask(task, sharedContextBundle) {
|
|
519
|
+
return {
|
|
520
|
+
...task,
|
|
521
|
+
context: {
|
|
522
|
+
...task.context,
|
|
523
|
+
shared_context_bundle: sharedContextBundle,
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
export function rewriteAuthoringTaskFile(repoRoot, task) {
|
|
528
|
+
const taskFile = resolveRepoPath(repoRoot, task?.files?.task_json);
|
|
529
|
+
const markdownFile = resolveRepoPath(repoRoot, task?.files?.task_markdown);
|
|
530
|
+
if (taskFile)
|
|
531
|
+
writeJson(taskFile, task);
|
|
532
|
+
if (markdownFile)
|
|
533
|
+
writeText(markdownFile, renderAuthoringTaskMarkdown(task));
|
|
534
|
+
}
|
|
535
|
+
export function writeAuthoringTaskBatchManifest(repoRoot, outDir, tasks, source, options = {}) {
|
|
536
|
+
const manifestPath = path.join(outDir, "authoring-task-manifest.json");
|
|
537
|
+
const tasksPath = path.join(outDir, "authoring-tasks.jsonl");
|
|
538
|
+
const batchPatchFile = path.join(outDir, "ai-patches.batch.json");
|
|
539
|
+
const datasetTypes = [...new Set(tasks.map((task) => task.entity.dataset_type).filter(Boolean))];
|
|
540
|
+
const sourceRowsFiles = [
|
|
541
|
+
...new Set(tasks
|
|
542
|
+
.map((task) => task.context.source_rows_file)
|
|
543
|
+
.filter((filePath) => Boolean(filePath))),
|
|
544
|
+
];
|
|
545
|
+
const packageDirs = [
|
|
546
|
+
...new Set(tasks
|
|
547
|
+
.map((task) => resolveRepoPath(repoRoot, task.files.authoring_package))
|
|
548
|
+
.filter((filePath) => Boolean(filePath))
|
|
549
|
+
.map((filePath) => repoRelativePath(repoRoot, path.dirname(filePath)))),
|
|
550
|
+
];
|
|
551
|
+
const totalActionItems = tasks.reduce((total, task) => total + ensureArray(task.action_items).length, 0);
|
|
552
|
+
const totalDecisionOnlyActionItems = tasks.reduce((total, task) => total + ensureArray(task.decision_only_action_items).length, 0);
|
|
553
|
+
const canApplyBatch = totalActionItems > 0 &&
|
|
554
|
+
datasetTypes.length === 1 &&
|
|
555
|
+
sourceRowsFiles.length === 1 &&
|
|
556
|
+
packageDirs.length === 1;
|
|
557
|
+
const batchPatchedRows = path.join(outDir, `${datasetTypePlural[datasetTypes[0]] ?? "datasets"}.patched.jsonl`);
|
|
558
|
+
const batchApplyDir = path.join(outDir, "patch-apply");
|
|
559
|
+
const applyBatchArgs = canApplyBatch
|
|
560
|
+
? [
|
|
561
|
+
"node",
|
|
562
|
+
"scripts/foundry.ts",
|
|
563
|
+
"dataset-patch-apply",
|
|
564
|
+
"--input",
|
|
565
|
+
sourceRowsFiles[0],
|
|
566
|
+
"--patch",
|
|
567
|
+
repoRelativePath(repoRoot, batchPatchFile),
|
|
568
|
+
"--out",
|
|
569
|
+
repoRelativePath(repoRoot, batchPatchedRows),
|
|
570
|
+
"--out-dir",
|
|
571
|
+
repoRelativePath(repoRoot, batchApplyDir),
|
|
572
|
+
"--authoring-package-dir",
|
|
573
|
+
packageDirs[0],
|
|
574
|
+
"--require-authoring-package",
|
|
575
|
+
"--require-action-item-closure",
|
|
576
|
+
]
|
|
577
|
+
: [];
|
|
578
|
+
const blockedTasks = tasks.filter((task) => task.status === "blocked_missing_full_context");
|
|
579
|
+
const taskBlockers = tasks.flatMap((task, taskIndex) => task.status === "blocked_missing_full_context"
|
|
580
|
+
? ensureArray(task.blockers).map((blocker) => ({
|
|
581
|
+
...blocker,
|
|
582
|
+
task_index: taskIndex,
|
|
583
|
+
entity: task.entity,
|
|
584
|
+
}))
|
|
585
|
+
: []);
|
|
586
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
587
|
+
const sharedContext = buildSharedAuthoringContextBundle(repoRoot, outDir, tasks, source, options);
|
|
588
|
+
const sharedContextBundleRef = {
|
|
589
|
+
path: repoRelativePath(repoRoot, sharedContext.path),
|
|
590
|
+
sha256: sharedContext.bundle.sha256,
|
|
591
|
+
counts: sharedContext.bundle.counts,
|
|
592
|
+
cache: sharedContext.cache,
|
|
593
|
+
instruction: "Read this shared bundle once per batch for full schema/YAML/ruleset/category/location context; per-entity authoring packages still carry source/entity/action evidence and remain the hash-bound proof records.",
|
|
594
|
+
};
|
|
595
|
+
const tasksWithSharedContext = tasks.map((task) => attachSharedContextBundleToTask(task, sharedContextBundleRef));
|
|
596
|
+
for (const task of tasksWithSharedContext) {
|
|
597
|
+
rewriteAuthoringTaskFile(repoRoot, task);
|
|
598
|
+
}
|
|
599
|
+
const manifest = {
|
|
600
|
+
schema_version: 1,
|
|
601
|
+
generated_at_utc: nowIso(),
|
|
602
|
+
status: blockedTasks.length > 0
|
|
603
|
+
? "blocked_missing_full_context"
|
|
604
|
+
: tasks.some((task) => task.status === "ready_for_ai_authoring")
|
|
605
|
+
? "ready_for_ai_authoring_batch"
|
|
606
|
+
: "ready_no_action_items",
|
|
607
|
+
source,
|
|
608
|
+
counts: {
|
|
609
|
+
tasks: tasks.length,
|
|
610
|
+
ready_for_ai_authoring: tasks.filter((task) => task.status === "ready_for_ai_authoring")
|
|
611
|
+
.length,
|
|
612
|
+
ready_no_action_items: tasks.filter((task) => task.status === "ready_no_action_items").length,
|
|
613
|
+
blocked_missing_full_context: blockedTasks.length,
|
|
614
|
+
action_items: totalActionItems,
|
|
615
|
+
decision_only_action_items: totalDecisionOnlyActionItems,
|
|
616
|
+
blockers: taskBlockers.length,
|
|
617
|
+
shared_context_files: sharedContext.bundle.counts.files,
|
|
618
|
+
shared_context_references: sharedContext.bundle.counts.references,
|
|
619
|
+
duplicate_context_references: sharedContext.bundle.counts.duplicate_references,
|
|
620
|
+
duplicate_context_bytes_avoided: sharedContext.bundle.counts.duplicate_context_bytes_avoided,
|
|
621
|
+
},
|
|
622
|
+
blockers: taskBlockers,
|
|
623
|
+
batch_patch_contract: {
|
|
624
|
+
status: totalActionItems === 0
|
|
625
|
+
? "not_required_no_patch_action_items"
|
|
626
|
+
: canApplyBatch
|
|
627
|
+
? "available"
|
|
628
|
+
: "not_available_mixed_inputs",
|
|
629
|
+
output_patch_file: canApplyBatch ? repoRelativePath(repoRoot, batchPatchFile) : null,
|
|
630
|
+
patched_rows: canApplyBatch ? repoRelativePath(repoRoot, batchPatchedRows) : null,
|
|
631
|
+
apply_dir: canApplyBatch ? repoRelativePath(repoRoot, batchApplyDir) : null,
|
|
632
|
+
instruction: options.includeExecutionCommands === false
|
|
633
|
+
? "Prepare the completed per-task patch sets in this batch file for review. Apply only through a structured action from the public task."
|
|
634
|
+
: totalActionItems === 0
|
|
635
|
+
? "No patch batch is required; resolve decision_only_action_items with the dedicated deterministic decision apply commands."
|
|
636
|
+
: "AI/Codex may combine all per-task patch sets into this batch file, then run apply_all_patches once to produce one patched rows file.",
|
|
637
|
+
},
|
|
638
|
+
commands: {
|
|
639
|
+
apply_all_patches: options.includeExecutionCommands !== false && canApplyBatch
|
|
640
|
+
? applyBatchArgs.map(shellQuote).join(" ")
|
|
641
|
+
: null,
|
|
642
|
+
},
|
|
643
|
+
shared_context_bundle: sharedContextBundleRef,
|
|
644
|
+
tasks: tasksWithSharedContext.map((task) => ({
|
|
645
|
+
status: task.status,
|
|
646
|
+
entity: task.entity,
|
|
647
|
+
context: task.context,
|
|
648
|
+
action_item_count: ensureArray(task.action_items).length,
|
|
649
|
+
action_items: task.action_items,
|
|
650
|
+
decision_only_action_item_count: ensureArray(task.decision_only_action_items).length,
|
|
651
|
+
decision_only_action_items: task.decision_only_action_items,
|
|
652
|
+
blockers: ensureArray(task.blockers),
|
|
653
|
+
files: task.files,
|
|
654
|
+
commands: task.commands,
|
|
655
|
+
})),
|
|
656
|
+
};
|
|
657
|
+
writeJson(manifestPath, manifest);
|
|
658
|
+
writeText(tasksPath, jsonLines(manifest.tasks));
|
|
659
|
+
return {
|
|
660
|
+
...manifest,
|
|
661
|
+
files: {
|
|
662
|
+
manifest: repoRelativePath(repoRoot, manifestPath),
|
|
663
|
+
tasks: repoRelativePath(repoRoot, tasksPath),
|
|
664
|
+
shared_context_bundle: repoRelativePath(repoRoot, sharedContext.path),
|
|
665
|
+
},
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
export function patchSetOperations(value) {
|
|
669
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
670
|
+
return null;
|
|
671
|
+
const record = value;
|
|
672
|
+
const operations = Array.isArray(record.operations)
|
|
673
|
+
? record.operations
|
|
674
|
+
: Array.isArray(record.patches)
|
|
675
|
+
? record.patches
|
|
676
|
+
: null;
|
|
677
|
+
if (!operations || !operations.every((operation) => operation && typeof operation === "object")) {
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
return operations;
|
|
681
|
+
}
|
|
682
|
+
export function patchPayloadPatchSets(rawPatch) {
|
|
683
|
+
if (Array.isArray(rawPatch))
|
|
684
|
+
return rawPatch;
|
|
685
|
+
if (!rawPatch || typeof rawPatch !== "object")
|
|
686
|
+
return [];
|
|
687
|
+
if (patchSetOperations(rawPatch))
|
|
688
|
+
return [rawPatch];
|
|
689
|
+
const record = rawPatch;
|
|
690
|
+
for (const key of ["patch_sets", "patchSets", "patches", "suggestions", "items"]) {
|
|
691
|
+
if (Array.isArray(record[key]))
|
|
692
|
+
return record[key];
|
|
693
|
+
}
|
|
694
|
+
return [];
|
|
695
|
+
}
|
|
696
|
+
export function patchSetDatasetId(patchSet) {
|
|
697
|
+
const record = asRecord(patchSet);
|
|
698
|
+
return asText(record.dataset_id ?? record.id ?? record.uuid ?? record.entity_id);
|
|
699
|
+
}
|
|
700
|
+
export function patchSetDatasetVersion(patchSet) {
|
|
701
|
+
const record = asRecord(patchSet);
|
|
702
|
+
return asText(record.dataset_version ?? record.version) || "00.00.001";
|
|
703
|
+
}
|
|
704
|
+
export function patchSetAuthoringPackage(patchSet) {
|
|
705
|
+
const record = asRecord(patchSet);
|
|
706
|
+
return asText(record.authoring_package ?? record.authoringPackage);
|
|
707
|
+
}
|
|
708
|
+
export function operationHasEvidence(operation) {
|
|
709
|
+
const record = asRecord(operation);
|
|
710
|
+
const basis = asText(record.basis);
|
|
711
|
+
const evidence = record.evidence;
|
|
712
|
+
if (basis)
|
|
713
|
+
return true;
|
|
714
|
+
if (typeof evidence === "string")
|
|
715
|
+
return evidence.trim().length > 0;
|
|
716
|
+
if (Array.isArray(evidence))
|
|
717
|
+
return evidence.length > 0;
|
|
718
|
+
if (evidence && typeof evidence === "object")
|
|
719
|
+
return Object.keys(evidence).length > 0;
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
export function taskRequiresFullContextEvidence(task) {
|
|
723
|
+
const context = asRecord(asRecord(task).context);
|
|
724
|
+
return (asRecord(context.full_context_ai_completion).required === true ||
|
|
725
|
+
asRecord(context.fullContextAiCompletion).required === true);
|
|
726
|
+
}
|
|
727
|
+
export function evidenceEntries(value) {
|
|
728
|
+
if (Array.isArray(value))
|
|
729
|
+
return value;
|
|
730
|
+
if (value === undefined || value === null)
|
|
731
|
+
return [];
|
|
732
|
+
return [value];
|
|
733
|
+
}
|
|
734
|
+
export function firstNonEmptyEvidenceValue(entry, keys) {
|
|
735
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
736
|
+
return "";
|
|
737
|
+
const record = entry;
|
|
738
|
+
for (const key of keys) {
|
|
739
|
+
const value = asText(record[key]);
|
|
740
|
+
if (value)
|
|
741
|
+
return value;
|
|
742
|
+
}
|
|
743
|
+
return "";
|
|
744
|
+
}
|
|
745
|
+
export const evidenceSourceKeys = [
|
|
746
|
+
"source",
|
|
747
|
+
"source_id",
|
|
748
|
+
"sourceId",
|
|
749
|
+
"source_file",
|
|
750
|
+
"sourceFile",
|
|
751
|
+
"context_kind",
|
|
752
|
+
"contextKind",
|
|
753
|
+
"citation",
|
|
754
|
+
"cited_source",
|
|
755
|
+
"citedSource",
|
|
756
|
+
"provenance",
|
|
757
|
+
];
|
|
758
|
+
export const evidenceTraceKeys = [
|
|
759
|
+
"quote_or_trace",
|
|
760
|
+
"quoteOrTrace",
|
|
761
|
+
"quote",
|
|
762
|
+
"trace",
|
|
763
|
+
"source_trace",
|
|
764
|
+
"sourceTrace",
|
|
765
|
+
"source_path",
|
|
766
|
+
"sourcePath",
|
|
767
|
+
"source_field",
|
|
768
|
+
"sourceField",
|
|
769
|
+
"field_path",
|
|
770
|
+
"fieldPath",
|
|
771
|
+
"json_pointer",
|
|
772
|
+
"jsonPointer",
|
|
773
|
+
"path",
|
|
774
|
+
"evidence_path",
|
|
775
|
+
"evidencePath",
|
|
776
|
+
"pointer",
|
|
777
|
+
"note",
|
|
778
|
+
"excerpt",
|
|
779
|
+
];
|
|
780
|
+
export function operationFullContextEvidenceBlockers({ operation, task, }) {
|
|
781
|
+
if (!taskRequiresFullContextEvidence(task))
|
|
782
|
+
return [];
|
|
783
|
+
const blockers = [];
|
|
784
|
+
const typedOperation = asRecord(operation);
|
|
785
|
+
if (!asText(typedOperation.basis)) {
|
|
786
|
+
blockers.push({
|
|
787
|
+
code: "patch_basis_required_full_context",
|
|
788
|
+
message: "Full-context AI patch operations must include basis explaining why the value follows from the package/context.",
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
const structuredEntries = evidenceEntries(typedOperation.evidence).filter((entry) => entry && typeof entry === "object" && !Array.isArray(entry));
|
|
792
|
+
if (structuredEntries.length === 0) {
|
|
793
|
+
blockers.push({
|
|
794
|
+
code: "patch_structured_evidence_required_full_context",
|
|
795
|
+
message: "Full-context AI patch operations require structured evidence; a free-text basis alone is invalid.",
|
|
796
|
+
});
|
|
797
|
+
return blockers;
|
|
798
|
+
}
|
|
799
|
+
const hasEvidencePointer = structuredEntries.some((entry) => firstNonEmptyEvidenceValue(entry, evidenceSourceKeys) &&
|
|
800
|
+
firstNonEmptyEvidenceValue(entry, evidenceTraceKeys));
|
|
801
|
+
if (!hasEvidencePointer) {
|
|
802
|
+
blockers.push({
|
|
803
|
+
code: "patch_structured_evidence_incomplete_full_context",
|
|
804
|
+
message: "Full-context AI patch evidence must include both a source/context identifier and a quote, trace, field path, citation, or equivalent pointer.",
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
return blockers;
|
|
808
|
+
}
|
|
809
|
+
export function operationResolution(operation) {
|
|
810
|
+
const resolution = asRecord(operation).resolution;
|
|
811
|
+
return resolution && typeof resolution === "object" && !Array.isArray(resolution)
|
|
812
|
+
? resolution
|
|
813
|
+
: null;
|
|
814
|
+
}
|
|
815
|
+
export function operationResolutionMode(operation) {
|
|
816
|
+
return asText(operationResolution(operation)?.mode);
|
|
817
|
+
}
|
|
818
|
+
export function operationUsedContextKinds(operation) {
|
|
819
|
+
return ensureArray(operationResolution(operation)?.used_context_kinds ??
|
|
820
|
+
operationResolution(operation)?.usedContextKinds)
|
|
821
|
+
.map((kind) => asText(kind))
|
|
822
|
+
.filter(Boolean);
|
|
823
|
+
}
|
|
824
|
+
export function taskRequiredContextKinds(task) {
|
|
825
|
+
const context = asRecord(asRecord(task).context);
|
|
826
|
+
const kinds = new Set(ensureArray(context.contract_context_files)
|
|
827
|
+
.map((file) => asText(asRecord(file).kind))
|
|
828
|
+
.filter(Boolean));
|
|
829
|
+
const requiredKinds = ensureArray(asRecord(context.full_context_ai_completion).required_context_kinds ??
|
|
830
|
+
asRecord(context.fullContextAiCompletion).requiredContextKinds)
|
|
831
|
+
.map((kind) => asText(kind))
|
|
832
|
+
.filter(Boolean);
|
|
833
|
+
const candidates = requiredKinds.length > 0
|
|
834
|
+
? requiredKinds
|
|
835
|
+
: ["schema", "methodology_yaml", "ruleset", "classification_schema", "location_schema"];
|
|
836
|
+
return candidates.filter((kind) => kinds.has(kind) || requiredKinds.includes(kind));
|
|
837
|
+
}
|
|
838
|
+
export function operationTouchesCommonOther(operation) {
|
|
839
|
+
const record = asRecord(operation);
|
|
840
|
+
const pointer = asText(record.path);
|
|
841
|
+
if (pointer.includes("/common:other") || pointer.includes("/tiangongfoundry:"))
|
|
842
|
+
return true;
|
|
843
|
+
return (JSON.stringify(record.value ?? "").includes("common:other") ||
|
|
844
|
+
JSON.stringify(record.value ?? "").includes("tiangongfoundry:"));
|
|
845
|
+
}
|
|
846
|
+
export function hasNonEmptyTraceEvidence(value) {
|
|
847
|
+
if (typeof value === "string")
|
|
848
|
+
return value.trim().length > 0;
|
|
849
|
+
if (Array.isArray(value))
|
|
850
|
+
return value.some((item) => hasNonEmptyTraceEvidence(item));
|
|
851
|
+
if (value && typeof value === "object")
|
|
852
|
+
return Object.keys(value).length > 0;
|
|
853
|
+
return false;
|
|
854
|
+
}
|