clinkx 0.3.0 → 1.0.0
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/CHANGELOG.md +33 -0
- package/LICENSE +10 -0
- package/README.md +82 -26
- package/clinkx-workflows/dist/allowed-roots.d.ts +1 -0
- package/clinkx-workflows/dist/allowed-roots.js +5 -0
- package/clinkx-workflows/dist/allowed-roots.js.map +1 -0
- package/clinkx-workflows/dist/artifacts.d.ts +20 -1
- package/clinkx-workflows/dist/artifacts.js +38 -9
- package/clinkx-workflows/dist/artifacts.js.map +1 -1
- package/clinkx-workflows/dist/backend.d.ts +4 -0
- package/clinkx-workflows/dist/citation-check.d.ts +40 -0
- package/clinkx-workflows/dist/citation-check.js +348 -0
- package/clinkx-workflows/dist/citation-check.js.map +1 -0
- package/clinkx-workflows/dist/clink-client.d.ts +2 -1
- package/clinkx-workflows/dist/clink-client.js +17 -4
- package/clinkx-workflows/dist/clink-client.js.map +1 -1
- package/clinkx-workflows/dist/config.d.ts +145 -16
- package/clinkx-workflows/dist/config.js +384 -26
- package/clinkx-workflows/dist/config.js.map +1 -1
- package/clinkx-workflows/dist/contained-file.d.ts +172 -0
- package/clinkx-workflows/dist/contained-file.js +483 -0
- package/clinkx-workflows/dist/contained-file.js.map +1 -0
- package/clinkx-workflows/dist/context-builder-lifecycle-contract.d.ts +416 -0
- package/clinkx-workflows/dist/context-builder-lifecycle-contract.js +328 -0
- package/clinkx-workflows/dist/context-builder-lifecycle-contract.js.map +1 -0
- package/clinkx-workflows/dist/context-builder-lifecycle-router.d.ts +24 -0
- package/clinkx-workflows/dist/context-builder-lifecycle-router.js +39 -0
- package/clinkx-workflows/dist/context-builder-lifecycle-router.js.map +1 -0
- package/clinkx-workflows/dist/context-cache-key.d.ts +53 -0
- package/clinkx-workflows/dist/context-cache-key.js +91 -0
- package/clinkx-workflows/dist/context-cache-key.js.map +1 -0
- package/clinkx-workflows/dist/context-mode-resolver.d.ts +27 -0
- package/clinkx-workflows/dist/context-mode-resolver.js +126 -0
- package/clinkx-workflows/dist/context-mode-resolver.js.map +1 -0
- package/clinkx-workflows/dist/context-preflight.d.ts +184 -0
- package/clinkx-workflows/dist/context-preflight.js +91 -0
- package/clinkx-workflows/dist/context-preflight.js.map +1 -0
- package/clinkx-workflows/dist/council-expander.d.ts +1 -1
- package/clinkx-workflows/dist/council-expander.js +2 -1
- package/clinkx-workflows/dist/council-expander.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/activity-contract.d.ts +165 -0
- package/clinkx-workflows/dist/dashboard/activity-contract.js +105 -0
- package/clinkx-workflows/dist/dashboard/activity-contract.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/activity-lease.d.ts +25 -0
- package/clinkx-workflows/dist/dashboard/activity-lease.js +34 -0
- package/clinkx-workflows/dist/dashboard/activity-lease.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/activity-reader.d.ts +86 -0
- package/clinkx-workflows/dist/dashboard/activity-reader.js +480 -0
- package/clinkx-workflows/dist/dashboard/activity-reader.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/api-routes.d.ts +36 -0
- package/clinkx-workflows/dist/dashboard/api-routes.js +1047 -0
- package/clinkx-workflows/dist/dashboard/api-routes.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/artifact-index.d.ts +37 -0
- package/clinkx-workflows/dist/dashboard/artifact-index.js +145 -0
- package/clinkx-workflows/dist/dashboard/artifact-index.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.d.ts +31 -0
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.js +65 -0
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/auth/controller.d.ts +26 -0
- package/clinkx-workflows/dist/dashboard/auth/controller.js +596 -0
- package/clinkx-workflows/dist/dashboard/auth/controller.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/auth/credential-store.d.ts +60 -0
- package/clinkx-workflows/dist/dashboard/auth/credential-store.js +776 -0
- package/clinkx-workflows/dist/dashboard/auth/credential-store.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.d.ts +9 -0
- package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.js +44 -0
- package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/auth/session-store.d.ts +17 -0
- package/clinkx-workflows/dist/dashboard/auth/session-store.js +77 -0
- package/clinkx-workflows/dist/dashboard/auth/session-store.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/auth/webauthn-service.d.ts +25 -0
- package/clinkx-workflows/dist/dashboard/auth/webauthn-service.js +71 -0
- package/clinkx-workflows/dist/dashboard/auth/webauthn-service.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/context-run-liveness.d.ts +37 -0
- package/clinkx-workflows/dist/dashboard/context-run-liveness.js +49 -0
- package/clinkx-workflows/dist/dashboard/context-run-liveness.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/context-run-reader.d.ts +222 -0
- package/clinkx-workflows/dist/dashboard/context-run-reader.js +1178 -0
- package/clinkx-workflows/dist/dashboard/context-run-reader.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/contracts.d.ts +8936 -0
- package/clinkx-workflows/dist/dashboard/contracts.js +1157 -0
- package/clinkx-workflows/dist/dashboard/contracts.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/generation.d.ts +14 -0
- package/clinkx-workflows/dist/dashboard/generation.js +41 -0
- package/clinkx-workflows/dist/dashboard/generation.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/index.d.ts +28 -0
- package/clinkx-workflows/dist/dashboard/index.js +16 -0
- package/clinkx-workflows/dist/dashboard/index.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/lazy-content.d.ts +101 -0
- package/clinkx-workflows/dist/dashboard/lazy-content.js +748 -0
- package/clinkx-workflows/dist/dashboard/lazy-content.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +303 -0
- package/clinkx-workflows/dist/dashboard/progress-report-contract.js +221 -0
- package/clinkx-workflows/dist/dashboard/progress-report-contract.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/progress-report-reader.d.ts +50 -0
- package/clinkx-workflows/dist/dashboard/progress-report-reader.js +581 -0
- package/clinkx-workflows/dist/dashboard/progress-report-reader.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.d.ts +89 -0
- package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.js +71 -0
- package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/progress-report-status-store.d.ts +28 -0
- package/clinkx-workflows/dist/dashboard/progress-report-status-store.js +110 -0
- package/clinkx-workflows/dist/dashboard/progress-report-status-store.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/read-model.d.ts +86 -0
- package/clinkx-workflows/dist/dashboard/read-model.js +440 -0
- package/clinkx-workflows/dist/dashboard/read-model.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/request-admission.d.ts +31 -0
- package/clinkx-workflows/dist/dashboard/request-admission.js +126 -0
- package/clinkx-workflows/dist/dashboard/request-admission.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/scanner.d.ts +75 -0
- package/clinkx-workflows/dist/dashboard/scanner.js +1110 -0
- package/clinkx-workflows/dist/dashboard/scanner.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/server-factory.d.ts +50 -0
- package/clinkx-workflows/dist/dashboard/server-factory.js +431 -0
- package/clinkx-workflows/dist/dashboard/server-factory.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +2611 -0
- package/clinkx-workflows/dist/dashboard/session-log-contract.js +480 -0
- package/clinkx-workflows/dist/dashboard/session-log-contract.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/session-log-identity.d.ts +21 -0
- package/clinkx-workflows/dist/dashboard/session-log-identity.js +101 -0
- package/clinkx-workflows/dist/dashboard/session-log-identity.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/session-log-journal.d.ts +43 -0
- package/clinkx-workflows/dist/dashboard/session-log-journal.js +522 -0
- package/clinkx-workflows/dist/dashboard/session-log-journal.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/session-log-reader.d.ts +61 -0
- package/clinkx-workflows/dist/dashboard/session-log-reader.js +378 -0
- package/clinkx-workflows/dist/dashboard/session-log-reader.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/session-log-redaction.d.ts +6 -0
- package/clinkx-workflows/dist/dashboard/session-log-redaction.js +367 -0
- package/clinkx-workflows/dist/dashboard/session-log-redaction.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/session-log-retention.d.ts +23 -0
- package/clinkx-workflows/dist/dashboard/session-log-retention.js +212 -0
- package/clinkx-workflows/dist/dashboard/session-log-retention.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/static-responses.d.ts +10 -0
- package/clinkx-workflows/dist/dashboard/static-responses.js +94 -0
- package/clinkx-workflows/dist/dashboard/static-responses.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/worker-lock-observer.d.ts +28 -0
- package/clinkx-workflows/dist/dashboard/worker-lock-observer.js +241 -0
- package/clinkx-workflows/dist/dashboard/worker-lock-observer.js.map +1 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-500-normal-6ng42L7E.woff2 +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-500-normal-BgVn5rGT.woff +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/index-DOkMXTfB.js +25 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/style-ChJsn0KD.css +1 -0
- package/clinkx-workflows/dist/dashboard-ui/contracts/council-plan-review-input-v1.json +158 -0
- package/clinkx-workflows/dist/dashboard-ui/index.html +15 -0
- package/clinkx-workflows/dist/dashboard-ui/licenses/IBM-Plex-Mono-OFL.txt +93 -0
- package/clinkx-workflows/dist/dashboard-ui/licenses/IBM-Plex-Sans-OFL.txt +93 -0
- package/clinkx-workflows/dist/dashboard-ui/licenses/JetBrains-Mono-OFL.txt +93 -0
- package/clinkx-workflows/dist/dashboard-ui/licenses/NOTICE.md +32 -0
- package/clinkx-workflows/dist/dashboard-ui/theme-init.js +8 -0
- package/clinkx-workflows/dist/definition-normalizer.d.ts +19 -0
- package/clinkx-workflows/dist/definition-normalizer.js.map +1 -1
- package/clinkx-workflows/dist/delegate-validate.d.ts +78 -0
- package/clinkx-workflows/dist/delegate-validate.js +97 -0
- package/clinkx-workflows/dist/delegate-validate.js.map +1 -0
- package/clinkx-workflows/dist/engine.d.ts +141 -0
- package/clinkx-workflows/dist/engine.js +882 -28
- package/clinkx-workflows/dist/engine.js.map +1 -1
- package/clinkx-workflows/dist/errors.d.ts +2 -0
- package/clinkx-workflows/dist/errors.js.map +1 -1
- package/clinkx-workflows/dist/fingerprint.d.ts +1 -1
- package/clinkx-workflows/dist/fingerprint.js +1 -1
- package/clinkx-workflows/dist/index.d.ts +19 -0
- package/clinkx-workflows/dist/index.js +15 -0
- package/clinkx-workflows/dist/index.js.map +1 -1
- package/clinkx-workflows/dist/loader.d.ts +9 -3
- package/clinkx-workflows/dist/loader.js +92 -21
- package/clinkx-workflows/dist/loader.js.map +1 -1
- package/clinkx-workflows/dist/plan-review/admission.d.ts +160 -0
- package/clinkx-workflows/dist/plan-review/admission.js +290 -0
- package/clinkx-workflows/dist/plan-review/admission.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/context-policy.d.ts +55 -0
- package/clinkx-workflows/dist/plan-review/context-policy.js +146 -0
- package/clinkx-workflows/dist/plan-review/context-policy.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/contract.d.ts +763 -0
- package/clinkx-workflows/dist/plan-review/contract.js +289 -0
- package/clinkx-workflows/dist/plan-review/contract.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/digest.d.ts +68 -0
- package/clinkx-workflows/dist/plan-review/digest.js +241 -0
- package/clinkx-workflows/dist/plan-review/digest.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/discovery.d.ts +45 -0
- package/clinkx-workflows/dist/plan-review/discovery.js +36 -0
- package/clinkx-workflows/dist/plan-review/discovery.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/execution-contract.d.ts +298 -0
- package/clinkx-workflows/dist/plan-review/execution-contract.js +194 -0
- package/clinkx-workflows/dist/plan-review/execution-contract.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/expander.d.ts +48 -0
- package/clinkx-workflows/dist/plan-review/expander.js +243 -0
- package/clinkx-workflows/dist/plan-review/expander.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/projector.d.ts +126 -0
- package/clinkx-workflows/dist/plan-review/projector.js +437 -0
- package/clinkx-workflows/dist/plan-review/projector.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/publication.d.ts +95 -0
- package/clinkx-workflows/dist/plan-review/publication.js +182 -0
- package/clinkx-workflows/dist/plan-review/publication.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/ranking-reducer.d.ts +34 -0
- package/clinkx-workflows/dist/plan-review/ranking-reducer.js +139 -0
- package/clinkx-workflows/dist/plan-review/ranking-reducer.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/resume.d.ts +38 -0
- package/clinkx-workflows/dist/plan-review/resume.js +122 -0
- package/clinkx-workflows/dist/plan-review/resume.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/rubric.d.ts +7 -0
- package/clinkx-workflows/dist/plan-review/rubric.js +24 -0
- package/clinkx-workflows/dist/plan-review/rubric.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/run-state.d.ts +398 -0
- package/clinkx-workflows/dist/plan-review/run-state.js +183 -0
- package/clinkx-workflows/dist/plan-review/run-state.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/runtime-policy.d.ts +74 -0
- package/clinkx-workflows/dist/plan-review/runtime-policy.js +186 -0
- package/clinkx-workflows/dist/plan-review/runtime-policy.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/snapshot.d.ts +81 -0
- package/clinkx-workflows/dist/plan-review/snapshot.js +170 -0
- package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/stage-error.d.ts +19 -0
- package/clinkx-workflows/dist/plan-review/stage-error.js +20 -0
- package/clinkx-workflows/dist/plan-review/stage-error.js.map +1 -0
- package/clinkx-workflows/dist/post-processors/index.d.ts +20 -0
- package/clinkx-workflows/dist/post-processors/index.js +21 -0
- package/clinkx-workflows/dist/post-processors/index.js.map +1 -0
- package/clinkx-workflows/dist/prompt-budget.d.ts +7 -0
- package/clinkx-workflows/dist/prompt-budget.js +7 -1
- package/clinkx-workflows/dist/prompt-budget.js.map +1 -1
- package/clinkx-workflows/dist/reducers/index.js +2 -0
- package/clinkx-workflows/dist/reducers/index.js.map +1 -1
- package/clinkx-workflows/dist/run-lock-heartbeat.d.ts +2 -0
- package/clinkx-workflows/dist/run-lock-heartbeat.js +3 -0
- package/clinkx-workflows/dist/run-lock-heartbeat.js.map +1 -0
- package/clinkx-workflows/dist/run-summary/cards/council-plan-review.d.ts +34 -0
- package/clinkx-workflows/dist/run-summary/cards/council-plan-review.js +74 -0
- package/clinkx-workflows/dist/run-summary/cards/council-plan-review.js.map +1 -0
- package/clinkx-workflows/dist/run-summary/cards/index.js +5 -0
- package/clinkx-workflows/dist/run-summary/cards/index.js.map +1 -1
- package/clinkx-workflows/dist/run-summary.d.ts +13 -0
- package/clinkx-workflows/dist/run-summary.js +29 -1
- package/clinkx-workflows/dist/run-summary.js.map +1 -1
- package/clinkx-workflows/dist/schema.d.ts +76 -21
- package/clinkx-workflows/dist/schema.js +10 -1
- package/clinkx-workflows/dist/schema.js.map +1 -1
- package/clinkx-workflows/dist/seed-terms.d.ts +30 -0
- package/clinkx-workflows/dist/seed-terms.js +176 -0
- package/clinkx-workflows/dist/seed-terms.js.map +1 -0
- package/clinkx-workflows/dist/server.d.ts +5 -2
- package/clinkx-workflows/dist/server.js +82 -52
- package/clinkx-workflows/dist/server.js.map +1 -1
- package/clinkx-workflows/dist/shutdown.d.ts +18 -20
- package/clinkx-workflows/dist/shutdown.js +43 -61
- package/clinkx-workflows/dist/shutdown.js.map +1 -1
- package/clinkx-workflows/dist/state-schema.d.ts +38 -0
- package/clinkx-workflows/dist/state.d.ts +170 -3
- package/clinkx-workflows/dist/state.js +1275 -28
- package/clinkx-workflows/dist/state.js.map +1 -1
- package/clinkx-workflows/dist/transport.d.ts +15 -0
- package/clinkx-workflows/dist/transport.js +19 -10
- package/clinkx-workflows/dist/transport.js.map +1 -1
- package/clinkx-workflows/dist/types.d.ts +14 -2
- package/clinkx-workflows/dist/validators/council.d.ts +318 -85
- package/clinkx-workflows/dist/validators/council.js +52 -13
- package/clinkx-workflows/dist/validators/council.js.map +1 -1
- package/clinkx-workflows/dist/validators/index.d.ts +1 -0
- package/clinkx-workflows/dist/validators/index.js +3 -0
- package/clinkx-workflows/dist/validators/index.js.map +1 -1
- package/clinkx-workflows/dist/validators/plan-review.d.ts +398 -0
- package/clinkx-workflows/dist/validators/plan-review.js +316 -0
- package/clinkx-workflows/dist/validators/plan-review.js.map +1 -0
- package/clinkx-workflows/dist/workflow-receipt.js +188 -4
- package/clinkx-workflows/dist/workflow-receipt.js.map +1 -1
- package/clinkx-workflows/dist/workflow-tools.d.ts +48 -3
- package/clinkx-workflows/dist/workflow-tools.js +1402 -59
- package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
- package/clinkx-workflows/dist/workspace-signature.d.ts +16 -0
- package/clinkx-workflows/dist/workspace-signature.js +388 -0
- package/clinkx-workflows/dist/workspace-signature.js.map +1 -0
- package/clinkx-workflows/templates/council/answer-specialist.txt +2 -1
- package/clinkx-workflows/templates/council/code-review-chairman.txt +13 -0
- package/clinkx-workflows/templates/council/code-review-cross-reviewer.txt +4 -1
- package/clinkx-workflows/templates/council/code-review-reviewer.txt +19 -3
- package/clinkx-workflows/templates/council/debug-debugger.txt +2 -1
- package/clinkx-workflows/templates/council/discover-analyst.txt +2 -1
- package/clinkx-workflows/templates/council/member.txt +2 -1
- package/clinkx-workflows/templates/council/plan-review-chairman.txt +68 -0
- package/clinkx-workflows/templates/council/plan-review-cross-reviewer.txt +51 -0
- package/clinkx-workflows/templates/council/plan-review-reviewer.txt +60 -0
- package/clinkx-workflows/templates/plan-review/chairman.txt +48 -0
- package/clinkx-workflows/templates/plan-review/cross-review.txt +52 -0
- package/clinkx-workflows/templates/plan-review/ranking.txt +16 -0
- package/clinkx-workflows/templates/plan-review/reviewer.txt +57 -0
- package/clinkx-workflows/workflows/council-answer.yaml +97 -8
- package/clinkx-workflows/workflows/council-code-review.yaml +103 -8
- package/clinkx-workflows/workflows/council-debug.yaml +97 -8
- package/clinkx-workflows/workflows/council-default.yaml +97 -8
- package/clinkx-workflows/workflows/council-discover.yaml +97 -8
- package/clinkx-workflows/workflows/council-plan-review.yaml +250 -0
- package/clinkx-workflows/workflows/plan-review-receipts.yaml +230 -0
- package/conf/adapters/agy.json +49 -0
- package/conf/adapters/claude.json +5 -0
- package/conf/adapters/codex-app-server.json +44 -0
- package/conf/adapters/codex.json +7 -2
- package/conf/adapters/glm.json +5 -0
- package/conf/adapters/grok.json +60 -0
- package/conf/adapters/hapi/agy.json +52 -0
- package/conf/adapters/hapi/claude.json +5 -0
- package/conf/adapters/hapi/codex.json +7 -2
- package/conf/adapters/hapi/glm.json +5 -0
- package/dist/activity-journal.d.ts +42 -0
- package/dist/activity-journal.js +381 -0
- package/dist/activity-journal.js.map +1 -0
- package/dist/allowed-roots.d.ts +41 -0
- package/dist/allowed-roots.js +125 -3
- package/dist/allowed-roots.js.map +1 -1
- package/dist/codex/activity-session-log.d.ts +14 -0
- package/dist/codex/activity-session-log.js +206 -0
- package/dist/codex/activity-session-log.js.map +1 -0
- package/dist/codex/agent-tools.d.ts +23 -0
- package/dist/codex/agent-tools.js +1270 -0
- package/dist/codex/agent-tools.js.map +1 -0
- package/dist/codex/app-server-client.d.ts +76 -0
- package/dist/codex/app-server-client.js +582 -0
- package/dist/codex/app-server-client.js.map +1 -0
- package/dist/codex/app-server-registry.d.ts +389 -0
- package/dist/codex/app-server-registry.js +1407 -0
- package/dist/codex/app-server-registry.js.map +1 -0
- package/dist/codex/client-types.d.ts +109 -0
- package/dist/codex/client-types.js +2 -0
- package/dist/codex/client-types.js.map +1 -0
- package/dist/codex/protocol.d.ts +5375 -0
- package/dist/codex/protocol.js +614 -0
- package/dist/codex/protocol.js.map +1 -0
- package/dist/codex/session.d.ts +263 -0
- package/dist/codex/session.js +466 -0
- package/dist/codex/session.js.map +1 -0
- package/dist/config.d.ts +185 -19
- package/dist/config.js +82 -16
- package/dist/config.js.map +1 -1
- package/dist/context-builder/anchors.d.ts +1 -0
- package/dist/context-builder/anchors.js +3 -0
- package/dist/context-builder/anchors.js.map +1 -1
- package/dist/context-builder/bundle.d.ts +35 -2
- package/dist/context-builder/bundle.js +342 -2417
- package/dist/context-builder/bundle.js.map +1 -1
- package/dist/context-builder/codemap.d.ts +5 -0
- package/dist/context-builder/codemap.js +387 -13
- package/dist/context-builder/codemap.js.map +1 -1
- package/dist/context-builder/config.d.ts +1 -0
- package/dist/context-builder/config.js +12 -0
- package/dist/context-builder/config.js.map +1 -1
- package/dist/context-builder/context-run-catalog.d.ts +17 -0
- package/dist/context-builder/context-run-catalog.js +99 -0
- package/dist/context-builder/context-run-catalog.js.map +1 -0
- package/dist/context-builder/delegate-packet.d.ts +37 -0
- package/dist/context-builder/delegate-packet.js +359 -67
- package/dist/context-builder/delegate-packet.js.map +1 -1
- package/dist/context-builder/delegate-validation.d.ts +10 -1
- package/dist/context-builder/delegate-validation.js +153 -41
- package/dist/context-builder/delegate-validation.js.map +1 -1
- package/dist/context-builder/delegate.d.ts +2 -0
- package/dist/context-builder/delegate.js +1 -0
- package/dist/context-builder/delegate.js.map +1 -1
- package/dist/context-builder/diagnostics.d.ts +11 -2
- package/dist/context-builder/diagnostics.js +39 -6
- package/dist/context-builder/diagnostics.js.map +1 -1
- package/dist/context-builder/discovery.d.ts +29 -1
- package/dist/context-builder/discovery.js +475 -175
- package/dist/context-builder/discovery.js.map +1 -1
- package/dist/context-builder/globs.js +10 -10
- package/dist/context-builder/globs.js.map +1 -1
- package/dist/context-builder/handler.d.ts +26 -2
- package/dist/context-builder/handler.js +1158 -2416
- package/dist/context-builder/handler.js.map +1 -1
- package/dist/context-builder/lifecycle-contract.d.ts +424 -0
- package/dist/context-builder/lifecycle-contract.js +523 -0
- package/dist/context-builder/lifecycle-contract.js.map +1 -0
- package/dist/context-builder/lifecycle-journal.d.ts +62 -0
- package/dist/context-builder/lifecycle-journal.js +88 -0
- package/dist/context-builder/lifecycle-journal.js.map +1 -0
- package/dist/context-builder/lifecycle-observer.d.ts +102 -0
- package/dist/context-builder/lifecycle-observer.js +258 -0
- package/dist/context-builder/lifecycle-observer.js.map +1 -0
- package/dist/context-builder/lifecycle-reconcile.d.ts +32 -0
- package/dist/context-builder/lifecycle-reconcile.js +191 -0
- package/dist/context-builder/lifecycle-reconcile.js.map +1 -0
- package/dist/context-builder/lifecycle-recovery.d.ts +2 -0
- package/dist/context-builder/lifecycle-recovery.js +14 -0
- package/dist/context-builder/lifecycle-recovery.js.map +1 -0
- package/dist/context-builder/path-signals.js +9 -5
- package/dist/context-builder/path-signals.js.map +1 -1
- package/dist/context-builder/progress.d.ts +3 -1
- package/dist/context-builder/progress.js +23 -0
- package/dist/context-builder/progress.js.map +1 -1
- package/dist/context-builder/receipt.d.ts +6 -4
- package/dist/context-builder/receipt.js +12 -1
- package/dist/context-builder/receipt.js.map +1 -1
- package/dist/context-builder/refine-handler.d.ts +14 -0
- package/dist/context-builder/refine-handler.js +790 -0
- package/dist/context-builder/refine-handler.js.map +1 -0
- package/dist/context-builder/review-coverage.d.ts +84 -0
- package/dist/context-builder/review-coverage.js +437 -0
- package/dist/context-builder/review-coverage.js.map +1 -0
- package/dist/context-builder/schema.d.ts +239 -1
- package/dist/context-builder/schema.js +112 -6
- package/dist/context-builder/schema.js.map +1 -1
- package/dist/context-builder/secrets.d.ts +28 -0
- package/dist/context-builder/secrets.js +1473 -44
- package/dist/context-builder/secrets.js.map +1 -1
- package/dist/context-builder/selection.d.ts +7 -3
- package/dist/context-builder/selection.js +200 -738
- package/dist/context-builder/selection.js.map +1 -1
- package/dist/context-builder/session-log-identity.d.ts +1 -0
- package/dist/context-builder/session-log-identity.js +66 -0
- package/dist/context-builder/session-log-identity.js.map +1 -0
- package/dist/context-builder/slice-range-math.d.ts +16 -0
- package/dist/context-builder/slice-range-math.js +137 -0
- package/dist/context-builder/slice-range-math.js.map +1 -0
- package/dist/context-builder/status.d.ts +22 -1
- package/dist/context-builder/status.js +59 -4
- package/dist/context-builder/status.js.map +1 -1
- package/dist/context-builder/storage.d.ts +35 -2
- package/dist/context-builder/storage.js +271 -14
- package/dist/context-builder/storage.js.map +1 -1
- package/dist/context-builder/token-estimate.d.ts +13 -2
- package/dist/context-builder/token-estimate.js +77 -4
- package/dist/context-builder/token-estimate.js.map +1 -1
- package/dist/context-builder/versions.d.ts +29 -0
- package/dist/context-builder/versions.js +30 -0
- package/dist/context-builder/versions.js.map +1 -0
- package/dist/context-builder/workflow-runner.d.ts +69 -0
- package/dist/context-builder/workflow-runner.js +1051 -0
- package/dist/context-builder/workflow-runner.js.map +1 -0
- package/dist/context-builder/write-watchdog.d.ts +14 -0
- package/dist/context-builder/write-watchdog.js +38 -0
- package/dist/context-builder/write-watchdog.js.map +1 -0
- package/dist/dashboard-adapter-catalog.d.ts +9 -0
- package/dist/dashboard-adapter-catalog.js +46 -0
- package/dist/dashboard-adapter-catalog.js.map +1 -0
- package/dist/dashboard-cli.d.ts +79 -0
- package/dist/dashboard-cli.js +585 -0
- package/dist/dashboard-cli.js.map +1 -0
- package/dist/dashboard-companion/client.d.ts +36 -0
- package/dist/dashboard-companion/client.js +210 -0
- package/dist/dashboard-companion/client.js.map +1 -0
- package/dist/dashboard-companion/config.d.ts +8 -0
- package/dist/dashboard-companion/config.js +52 -0
- package/dist/dashboard-companion/config.js.map +1 -0
- package/dist/dashboard-companion/http-proxy.d.ts +10 -0
- package/dist/dashboard-companion/http-proxy.js +234 -0
- package/dist/dashboard-companion/http-proxy.js.map +1 -0
- package/dist/dashboard-companion/protocol.d.ts +80 -0
- package/dist/dashboard-companion/protocol.js +455 -0
- package/dist/dashboard-companion/protocol.js.map +1 -0
- package/dist/dashboard-companion/standalone-assets.d.ts +12 -0
- package/dist/dashboard-companion/standalone-assets.js +72 -0
- package/dist/dashboard-companion/standalone-assets.js.map +1 -0
- package/dist/dashboard-companion/standalone-entry.d.ts +1 -0
- package/dist/dashboard-companion/standalone-entry.js +17 -0
- package/dist/dashboard-companion/standalone-entry.js.map +1 -0
- package/dist/dashboard-gateway/config.d.ts +9 -0
- package/dist/dashboard-gateway/config.js +44 -0
- package/dist/dashboard-gateway/config.js.map +1 -0
- package/dist/dashboard-gateway/index.d.ts +11 -0
- package/dist/dashboard-gateway/index.js +755 -0
- package/dist/dashboard-gateway/index.js.map +1 -0
- package/dist/dashboard-gateway/main.d.ts +1 -0
- package/dist/dashboard-gateway/main.js +25 -0
- package/dist/dashboard-gateway/main.js.map +1 -0
- package/dist/dashboard-pairing-token.d.ts +1 -0
- package/dist/dashboard-pairing-token.js +5 -0
- package/dist/dashboard-pairing-token.js.map +1 -0
- package/dist/elaris/client.d.ts +73 -0
- package/dist/elaris/client.js +825 -0
- package/dist/elaris/client.js.map +1 -0
- package/dist/elaris/config.d.ts +18 -0
- package/dist/elaris/config.js +75 -0
- package/dist/elaris/config.js.map +1 -0
- package/dist/elaris/errors.d.ts +41 -0
- package/dist/elaris/errors.js +205 -0
- package/dist/elaris/errors.js.map +1 -0
- package/dist/elaris/github-repo.d.ts +18 -0
- package/dist/elaris/github-repo.js +89 -0
- package/dist/elaris/github-repo.js.map +1 -0
- package/dist/elaris/index.d.ts +10 -0
- package/dist/elaris/index.js +11 -0
- package/dist/elaris/index.js.map +1 -0
- package/dist/elaris/redact.d.ts +89 -0
- package/dist/elaris/redact.js +423 -0
- package/dist/elaris/redact.js.map +1 -0
- package/dist/elaris/run-id.d.ts +5 -0
- package/dist/elaris/run-id.js +20 -0
- package/dist/elaris/run-id.js.map +1 -0
- package/dist/elaris/status.d.ts +45 -0
- package/dist/elaris/status.js +122 -0
- package/dist/elaris/status.js.map +1 -0
- package/dist/elaris/tool-schemas.d.ts +314 -0
- package/dist/elaris/tool-schemas.js +208 -0
- package/dist/elaris/tool-schemas.js.map +1 -0
- package/dist/elaris/tools.d.ts +73 -0
- package/dist/elaris/tools.js +1065 -0
- package/dist/elaris/tools.js.map +1 -0
- package/dist/elaris/types.d.ts +1541 -0
- package/dist/elaris/types.js +252 -0
- package/dist/elaris/types.js.map +1 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.js +19 -0
- package/dist/errors.js.map +1 -1
- package/dist/handler.d.ts +4 -0
- package/dist/handler.js +10 -1
- package/dist/handler.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/dist/local-clink-backend.d.ts +3 -0
- package/dist/local-clink-backend.js +4 -0
- package/dist/local-clink-backend.js.map +1 -1
- package/dist/package-info.d.ts +2 -0
- package/dist/package-info.js +18 -0
- package/dist/package-info.js.map +1 -0
- package/dist/parsers/codex-jsonl.js +48 -3
- package/dist/parsers/codex-jsonl.js.map +1 -1
- package/dist/parsers/extract.d.ts +10 -1
- package/dist/parsers/extract.js +11 -3
- package/dist/parsers/extract.js.map +1 -1
- package/dist/pipeline.d.ts +4 -0
- package/dist/pipeline.js +129 -8
- package/dist/pipeline.js.map +1 -1
- package/dist/run-dir.d.ts +24 -0
- package/dist/run-dir.js +201 -2
- package/dist/run-dir.js.map +1 -1
- package/dist/runner.d.ts +13 -0
- package/dist/runner.js +184 -15
- package/dist/runner.js.map +1 -1
- package/dist/safety.d.ts +4 -4
- package/dist/safety.js +4 -4
- package/dist/schema.d.ts +7 -7
- package/dist/server.d.ts +1 -0
- package/dist/server.js +359 -17
- package/dist/server.js.map +1 -1
- package/dist/session-log-stream.d.ts +18 -0
- package/dist/session-log-stream.js +319 -0
- package/dist/session-log-stream.js.map +1 -0
- package/package.json +46 -5
- package/conf/adapters/gemini.json +0 -44
- package/conf/adapters/hapi/gemini.json +0 -47
- package/dist/parsers/gemini-json.d.ts +0 -2
- package/dist/parsers/gemini-json.js +0 -72
- package/dist/parsers/gemini-json.js.map +0 -1
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile as fsReadFile, realpath as fsRealpath, stat as fsStat, } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
5
|
+
import { isSamePathOrDescendant, parseAllowedRootsEnv } from "../allowed-roots.js";
|
|
6
|
+
import { CancellationError, InvalidParamsError } from "../errors.js";
|
|
7
|
+
import { logger } from "../logger.js";
|
|
8
|
+
import { writeContextBuilderFinalArtifacts, } from "./bundle.js";
|
|
9
|
+
import { CONTEXT_BUILDER_INTERNAL_CAP_DEFAULTS, getSharedContextBuilderSemaphore, resolveContextBuilderRunsDir, } from "./config.js";
|
|
10
|
+
import { splitTextLines, } from "./discovery.js";
|
|
11
|
+
import { resolveContextBuilderRoots } from "./paths.js";
|
|
12
|
+
import { createContextBuilderReceiptTextResponse, } from "./receipt.js";
|
|
13
|
+
import { generateContextBuilderRunId } from "./run-id.js";
|
|
14
|
+
import { recordContextRunCatalogMarker } from "./context-run-catalog.js";
|
|
15
|
+
import { appendLifecycleCompletionWarning } from "./lifecycle-recovery.js";
|
|
16
|
+
import { withContextBuilderWriteWatchdog } from "./write-watchdog.js";
|
|
17
|
+
import { normalizeContextBuilderPublicBudget, RefineContextRunInputSchema, } from "./schema.js";
|
|
18
|
+
import { coalesceRanges, } from "./slice-range-math.js";
|
|
19
|
+
import { resolveAllowSecrets, sanitizeHighConfidenceSecretContent, scanSecretPath, } from "./secrets.js";
|
|
20
|
+
import { cleanupContextBuilderIncompleteRun, createContextBuilderRun, resolveContextBuilderRunPaths, } from "./storage.js";
|
|
21
|
+
import { estimateContextBuilderTokensFromUtf8Bytes } from "./token-estimate.js";
|
|
22
|
+
import { ContextBuilderLifecycleController, ContextBuilderLifecycleObserverError, } from "./lifecycle-observer.js";
|
|
23
|
+
import { createContextBuilderLifecycleJournal } from "./lifecycle-journal.js";
|
|
24
|
+
export async function handleRefineContextRun(args, options = {}) {
|
|
25
|
+
const input = parseRefineContextRunInput(args);
|
|
26
|
+
const semaphore = options.semaphore ?? getDefaultRefineSemaphore();
|
|
27
|
+
semaphore.acquire();
|
|
28
|
+
let lifecycle;
|
|
29
|
+
let storage;
|
|
30
|
+
let committed = false;
|
|
31
|
+
try {
|
|
32
|
+
// Resolve the runs dir up front so a broad/forbidden runs_dir is rejected
|
|
33
|
+
// with its canonical error before any lifecycle transition, and so the
|
|
34
|
+
// journal reuses this one already-validated path.
|
|
35
|
+
const runsDir = await resolveContextBuilderRunsDir(options.runsDir);
|
|
36
|
+
// A refine operation that owns its lifecycle (no injected observer) persists
|
|
37
|
+
// authoritatively through the .context-runs journal.
|
|
38
|
+
const journal = options.lifecycle == null
|
|
39
|
+
? createContextBuilderLifecycleJournal({
|
|
40
|
+
runsDir,
|
|
41
|
+
resolveRunsDir: async () => runsDir,
|
|
42
|
+
})
|
|
43
|
+
: undefined;
|
|
44
|
+
lifecycle = new ContextBuilderLifecycleController({
|
|
45
|
+
operationKind: "refine",
|
|
46
|
+
execution: {
|
|
47
|
+
curator: { configured: false, enabled: false },
|
|
48
|
+
finalizer: { configured: false, enabled: false },
|
|
49
|
+
},
|
|
50
|
+
...(options.lifecycle != null
|
|
51
|
+
? {
|
|
52
|
+
observer: options.lifecycle.observer,
|
|
53
|
+
...(options.lifecycle.origin == null
|
|
54
|
+
? {}
|
|
55
|
+
: { origin: options.lifecycle.origin }),
|
|
56
|
+
}
|
|
57
|
+
: journal == null
|
|
58
|
+
? {}
|
|
59
|
+
: { observer: journal.observe }),
|
|
60
|
+
...(options.now == null ? {} : { now: options.now }),
|
|
61
|
+
});
|
|
62
|
+
await lifecycle?.transition("resolving");
|
|
63
|
+
await lifecycle?.transition("validating");
|
|
64
|
+
const allowSecrets = resolveAllowSecrets(input.allow_secrets ?? options.allowSecrets);
|
|
65
|
+
const priorStorage = resolveContextBuilderRunPaths(runsDir, input.prior_run_id);
|
|
66
|
+
const priorManifest = await readPriorManifest(priorStorage.manifestJson);
|
|
67
|
+
const roots = await validatePriorRoots(priorManifest);
|
|
68
|
+
const selection = reconstructSelection(priorManifest);
|
|
69
|
+
applyRefineOps(selection, input.ops, roots);
|
|
70
|
+
await lifecycle?.transition("selecting");
|
|
71
|
+
const createdAt = (options.now?.() ?? new Date()).toISOString();
|
|
72
|
+
const runId = generateContextBuilderRunId();
|
|
73
|
+
const internalCaps = options.internalCaps ?? CONTEXT_BUILDER_INTERNAL_CAP_DEFAULTS;
|
|
74
|
+
const budget = normalizeManifestBudget(priorManifest);
|
|
75
|
+
const priorFingerprints = priorFingerprintMap(priorManifest);
|
|
76
|
+
const warnings = [];
|
|
77
|
+
const omissions = [];
|
|
78
|
+
const materialized = await materializeSelection({
|
|
79
|
+
selection: [...selection.values()],
|
|
80
|
+
roots,
|
|
81
|
+
budget,
|
|
82
|
+
priorFingerprints,
|
|
83
|
+
warnings,
|
|
84
|
+
omissions,
|
|
85
|
+
allowSecrets,
|
|
86
|
+
...(options.signal == null ? {} : { signal: options.signal }),
|
|
87
|
+
});
|
|
88
|
+
const budgeted = applyBudget({
|
|
89
|
+
files: materialized,
|
|
90
|
+
budget,
|
|
91
|
+
omissions,
|
|
92
|
+
});
|
|
93
|
+
const metrics = buildMetrics({
|
|
94
|
+
consideredCount: selection.size,
|
|
95
|
+
rawBytesRead: materialized.reduce((total, file) => total + file.rawByteLength, 0),
|
|
96
|
+
selected: budgeted.selected,
|
|
97
|
+
omittedCount: omissions.length,
|
|
98
|
+
});
|
|
99
|
+
const renderInput = {
|
|
100
|
+
run_id: runId,
|
|
101
|
+
created_at: createdAt,
|
|
102
|
+
task: `Refine context_builder run ${input.prior_run_id}`,
|
|
103
|
+
allowSecrets,
|
|
104
|
+
roots,
|
|
105
|
+
inputs: {
|
|
106
|
+
prior_run_id: input.prior_run_id,
|
|
107
|
+
ops: input.ops,
|
|
108
|
+
resolved_budget: budget,
|
|
109
|
+
},
|
|
110
|
+
budget,
|
|
111
|
+
internal_caps: internalCaps,
|
|
112
|
+
tree: budgeted.tree,
|
|
113
|
+
search: [],
|
|
114
|
+
slices: budgeted.slices,
|
|
115
|
+
selected_context: budgeted.selected,
|
|
116
|
+
omissions,
|
|
117
|
+
warnings,
|
|
118
|
+
metrics,
|
|
119
|
+
open_questions: [],
|
|
120
|
+
observability: {
|
|
121
|
+
curator_ms: null,
|
|
122
|
+
finalizer_ms: null,
|
|
123
|
+
candidate_pool_size: materialized.length,
|
|
124
|
+
// Deprecated alias of delegate_packet_estimated_tokens (see
|
|
125
|
+
// ContextBuilderObservabilityMetrics); refine runs never build a packet.
|
|
126
|
+
delegate_packet_size: 0,
|
|
127
|
+
delegate_packet_estimated_tokens: 0,
|
|
128
|
+
},
|
|
129
|
+
parent_run_id: input.prior_run_id,
|
|
130
|
+
refine_ops: input.ops,
|
|
131
|
+
file_fingerprints: budgeted.fingerprints,
|
|
132
|
+
};
|
|
133
|
+
await lifecycle?.transition("writing", {
|
|
134
|
+
artifactRunId: runId,
|
|
135
|
+
counts: lifecycleCounts(metrics),
|
|
136
|
+
});
|
|
137
|
+
const writingStorage = await createContextBuilderRun({
|
|
138
|
+
runsDir,
|
|
139
|
+
runId,
|
|
140
|
+
createdAt,
|
|
141
|
+
});
|
|
142
|
+
storage = writingStorage;
|
|
143
|
+
const committingLifecycle = lifecycle;
|
|
144
|
+
const receipt = await withContextBuilderWriteWatchdog((signal) => writeContextBuilderFinalArtifacts(writingStorage, {
|
|
145
|
+
...renderInput,
|
|
146
|
+
debug: true,
|
|
147
|
+
debug_diagnostics: {
|
|
148
|
+
counters: {
|
|
149
|
+
parent_run_id_recorded: 1,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
}, {
|
|
153
|
+
signal,
|
|
154
|
+
...(writingStorage.ownerNonce == null ? {} : { ownerNonce: writingStorage.ownerNonce }),
|
|
155
|
+
// Capture into a const so the closure keeps the narrowed non-undefined
|
|
156
|
+
// type (the outer binding is a reassignable let).
|
|
157
|
+
...(committingLifecycle == null
|
|
158
|
+
? {}
|
|
159
|
+
: { beforeManifestCommit: () => committingLifecycle.transition("committing") }),
|
|
160
|
+
}), options.signal == null ? {} : { signal: options.signal });
|
|
161
|
+
committed = true;
|
|
162
|
+
await recordContextRunCatalogMarker({
|
|
163
|
+
runsDir,
|
|
164
|
+
kind: "artifact",
|
|
165
|
+
id: receipt.run_id,
|
|
166
|
+
createdAt,
|
|
167
|
+
}).catch(() => {
|
|
168
|
+
logger.warn({ contextRunId: receipt.run_id }, "context run catalog marker write failed");
|
|
169
|
+
});
|
|
170
|
+
let responseReceipt = receipt;
|
|
171
|
+
try {
|
|
172
|
+
await lifecycle?.complete(receipt.status, {
|
|
173
|
+
artifactRunId: receipt.run_id,
|
|
174
|
+
counts: lifecycleCounts(receipt.metrics),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (!(error instanceof ContextBuilderLifecycleObserverError))
|
|
179
|
+
throw error;
|
|
180
|
+
logger.warn({ contextRunId: lifecycle?.contextRunId }, "context run lifecycle completion unavailable after retry");
|
|
181
|
+
responseReceipt = appendLifecycleCompletionWarning(receipt, internalCaps.max_warnings);
|
|
182
|
+
}
|
|
183
|
+
return createContextBuilderReceiptTextResponse(responseReceipt);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
if (storage != null && !committed && storage.ownerNonce != null) {
|
|
187
|
+
await cleanupContextBuilderIncompleteRun(storage, storage.ownerNonce).catch(() => { });
|
|
188
|
+
}
|
|
189
|
+
if (lifecycle != null && !(error instanceof ContextBuilderLifecycleObserverError)) {
|
|
190
|
+
const cancelled = error instanceof CancellationError || options.signal?.aborted === true;
|
|
191
|
+
await lifecycle.fail(cancelled ? "cancelled" : "failed", {
|
|
192
|
+
reasonCodes: [cancelled ? "operation_cancelled" : "internal_failure"],
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
semaphore.release();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function lifecycleCounts(metrics) {
|
|
202
|
+
return {
|
|
203
|
+
files_seen: metrics.files_seen,
|
|
204
|
+
files_considered: metrics.files_considered,
|
|
205
|
+
files_selected: metrics.files_selected,
|
|
206
|
+
files_omitted: metrics.files_omitted,
|
|
207
|
+
search_results: 0,
|
|
208
|
+
bytes_read: metrics.bytes_read,
|
|
209
|
+
bytes_written: metrics.bytes_written,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
export function refineContextRunJsonSchema() {
|
|
213
|
+
return zodToJsonSchema(RefineContextRunInputSchema, {
|
|
214
|
+
target: "jsonSchema7",
|
|
215
|
+
$refStrategy: "none",
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function parseRefineContextRunInput(input) {
|
|
219
|
+
const result = RefineContextRunInputSchema.safeParse(input);
|
|
220
|
+
if (!result.success) {
|
|
221
|
+
throw new InvalidParamsError(`Invalid refine_context_run input: ${result.error.issues
|
|
222
|
+
.map((issue) => issue.message)
|
|
223
|
+
.join("; ")}`);
|
|
224
|
+
}
|
|
225
|
+
return result.data;
|
|
226
|
+
}
|
|
227
|
+
async function readPriorManifest(manifestPath) {
|
|
228
|
+
try {
|
|
229
|
+
return JSON.parse(await fsReadFile(manifestPath, "utf8"));
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
throw new InvalidParamsError("refine_context_run prior_run_id does not identify a readable context_builder run");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async function validatePriorRoots(manifest) {
|
|
236
|
+
const roots = manifestRoots(manifest);
|
|
237
|
+
const resolution = await resolveContextBuilderRoots(roots.map((root) => root.path), {
|
|
238
|
+
allowedRoots: parseAllowedRootsEnv({ includeArtifactOnly: false }),
|
|
239
|
+
});
|
|
240
|
+
return resolution.roots.map((root) => ({
|
|
241
|
+
root_index: root.root_index,
|
|
242
|
+
input_path: roots[root.root_index]?.input_path ?? root.input_path,
|
|
243
|
+
path: root.path,
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
246
|
+
function manifestRoots(manifest) {
|
|
247
|
+
const raw = manifest["roots"];
|
|
248
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
249
|
+
throw new InvalidParamsError("refine_context_run prior manifest has no recorded roots");
|
|
250
|
+
}
|
|
251
|
+
return raw
|
|
252
|
+
.map((entry) => {
|
|
253
|
+
if (!isRecord(entry) || typeof entry["path"] !== "string") {
|
|
254
|
+
throw new InvalidParamsError("refine_context_run prior manifest root entry is invalid");
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
root_index: typeof entry["root_index"] === "number" ? entry["root_index"] : 0,
|
|
258
|
+
...(typeof entry["input_path"] === "string"
|
|
259
|
+
? { input_path: entry["input_path"] }
|
|
260
|
+
: {}),
|
|
261
|
+
path: entry["path"],
|
|
262
|
+
};
|
|
263
|
+
})
|
|
264
|
+
.sort((left, right) => left.root_index - right.root_index);
|
|
265
|
+
}
|
|
266
|
+
function reconstructSelection(manifest) {
|
|
267
|
+
const raw = manifest["selected_context"];
|
|
268
|
+
if (!Array.isArray(raw)) {
|
|
269
|
+
throw new InvalidParamsError("refine_context_run prior manifest selected_context is invalid");
|
|
270
|
+
}
|
|
271
|
+
const selection = new Map();
|
|
272
|
+
for (const entry of raw) {
|
|
273
|
+
const selected = parseManifestSelectedFile(entry);
|
|
274
|
+
const selectionEntry = {
|
|
275
|
+
root_index: selected.root_index,
|
|
276
|
+
path: selected.path,
|
|
277
|
+
ranges: coalesceRanges(selected.ranges ?? []),
|
|
278
|
+
disposition: selected.disposition ?? "slices",
|
|
279
|
+
};
|
|
280
|
+
selection.set(selectionKey(selectionEntry), selectionEntry);
|
|
281
|
+
}
|
|
282
|
+
return selection;
|
|
283
|
+
}
|
|
284
|
+
function selectionKey(entry) {
|
|
285
|
+
return fingerprintKey(entry);
|
|
286
|
+
}
|
|
287
|
+
function parseManifestSelectedFile(input) {
|
|
288
|
+
if (!isRecord(input) ||
|
|
289
|
+
typeof input["root_index"] !== "number" ||
|
|
290
|
+
typeof input["path"] !== "string") {
|
|
291
|
+
throw new InvalidParamsError("refine_context_run prior manifest selected_context entry is invalid");
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
root_index: input["root_index"],
|
|
295
|
+
path: normalizeRefinePath(input["path"]),
|
|
296
|
+
ranges: Array.isArray(input["ranges"])
|
|
297
|
+
? input["ranges"].map(parseManifestRange)
|
|
298
|
+
: [],
|
|
299
|
+
...(typeof input["bytes"] === "number" ? { bytes: input["bytes"] } : {}),
|
|
300
|
+
...(typeof input["estimated_tokens"] === "number"
|
|
301
|
+
? { estimated_tokens: input["estimated_tokens"] }
|
|
302
|
+
: {}),
|
|
303
|
+
...(input["source"] === "focus" || input["source"] === "search"
|
|
304
|
+
? { source: input["source"] }
|
|
305
|
+
: {}),
|
|
306
|
+
...(isSelectionDisposition(input["disposition"])
|
|
307
|
+
? { disposition: input["disposition"] }
|
|
308
|
+
: {}),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function parseManifestRange(input) {
|
|
312
|
+
if (!isRecord(input) ||
|
|
313
|
+
typeof input["start_line"] !== "number" ||
|
|
314
|
+
typeof input["end_line"] !== "number") {
|
|
315
|
+
throw new InvalidParamsError("refine_context_run prior manifest selected range is invalid");
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
start_line: input["start_line"],
|
|
319
|
+
end_line: input["end_line"],
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function applyRefineOps(selection, ops, roots) {
|
|
323
|
+
for (const op of ops) {
|
|
324
|
+
switch (op.op) {
|
|
325
|
+
case "add":
|
|
326
|
+
if (op.mode === "slices") {
|
|
327
|
+
// `add` materializes a whole-file selection (full or codemap_only);
|
|
328
|
+
// it carries no ranges, so an empty-range "slices" add would be
|
|
329
|
+
// silently dropped. Direct ranged additions to set_slices.
|
|
330
|
+
throw new InvalidParamsError("refine_context_run add does not support mode:\"slices\"; use set_slices to add ranged selections");
|
|
331
|
+
}
|
|
332
|
+
for (const rawPath of op.paths) {
|
|
333
|
+
const selectedPath = normalizeRefinePath(rawPath);
|
|
334
|
+
const existing = resolveOpTarget(selection, roots, selectedPath);
|
|
335
|
+
const entry = {
|
|
336
|
+
root_index: existing?.root_index ?? newEntryRootIndex(roots, selectedPath),
|
|
337
|
+
path: selectedPath,
|
|
338
|
+
ranges: existing?.ranges ?? [],
|
|
339
|
+
disposition: op.mode,
|
|
340
|
+
};
|
|
341
|
+
setSelectionEntry(selection, existing, entry);
|
|
342
|
+
}
|
|
343
|
+
break;
|
|
344
|
+
case "remove":
|
|
345
|
+
for (const rawPath of op.paths) {
|
|
346
|
+
const selectedPath = normalizeRefinePath(rawPath);
|
|
347
|
+
const existing = resolveOpTarget(selection, roots, selectedPath);
|
|
348
|
+
if (existing != null) {
|
|
349
|
+
selection.delete(selectionKey(existing));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
break;
|
|
353
|
+
case "set_slices": {
|
|
354
|
+
const selectedPath = normalizeRefinePath(op.path);
|
|
355
|
+
const existing = resolveOpTarget(selection, roots, selectedPath);
|
|
356
|
+
const entry = {
|
|
357
|
+
root_index: existing?.root_index ?? newEntryRootIndex(roots, selectedPath),
|
|
358
|
+
path: selectedPath,
|
|
359
|
+
ranges: coalesceRanges(op.ranges),
|
|
360
|
+
disposition: "slices",
|
|
361
|
+
};
|
|
362
|
+
setSelectionEntry(selection, existing, entry);
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
case "promote":
|
|
366
|
+
for (const rawPath of op.paths) {
|
|
367
|
+
const selectedPath = normalizeRefinePath(rawPath);
|
|
368
|
+
const existing = resolveOpTarget(selection, roots, selectedPath);
|
|
369
|
+
const entry = {
|
|
370
|
+
root_index: existing?.root_index ?? newEntryRootIndex(roots, selectedPath),
|
|
371
|
+
path: selectedPath,
|
|
372
|
+
ranges: [],
|
|
373
|
+
disposition: "full",
|
|
374
|
+
};
|
|
375
|
+
setSelectionEntry(selection, existing, entry);
|
|
376
|
+
}
|
|
377
|
+
break;
|
|
378
|
+
case "demote":
|
|
379
|
+
for (const rawPath of op.paths) {
|
|
380
|
+
const selectedPath = normalizeRefinePath(rawPath);
|
|
381
|
+
const existing = resolveOpTarget(selection, roots, selectedPath);
|
|
382
|
+
const entry = {
|
|
383
|
+
root_index: existing?.root_index ?? newEntryRootIndex(roots, selectedPath),
|
|
384
|
+
path: selectedPath,
|
|
385
|
+
ranges: [],
|
|
386
|
+
disposition: "codemap_only",
|
|
387
|
+
};
|
|
388
|
+
setSelectionEntry(selection, existing, entry);
|
|
389
|
+
}
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
// Resolve a bare op path to the single existing selection entry it targets.
|
|
395
|
+
// Returns undefined when the path is not selected. Throws if the bare path is
|
|
396
|
+
// ambiguous (selected under 2+ roots) — fail closed rather than guess a root.
|
|
397
|
+
function resolveOpTarget(selection, roots, selectedPath) {
|
|
398
|
+
const matches = [...selection.values()].filter((entry) => entry.path === selectedPath);
|
|
399
|
+
if (matches.length >= 2) {
|
|
400
|
+
throw new InvalidParamsError(`refine_context_run path "${selectedPath}" is ambiguous: selected under ${matches.length} roots. ` +
|
|
401
|
+
"Refine each root's run separately.");
|
|
402
|
+
}
|
|
403
|
+
return matches[0];
|
|
404
|
+
}
|
|
405
|
+
// Root index for a not-yet-selected path. Unambiguous only when the run has a
|
|
406
|
+
// single root; otherwise fail closed (never silently default to root 0).
|
|
407
|
+
function newEntryRootIndex(roots, selectedPath) {
|
|
408
|
+
if (roots.length === 1) {
|
|
409
|
+
const only = roots[0];
|
|
410
|
+
if (only == null) {
|
|
411
|
+
throw new InvalidParamsError("refine_context_run prior manifest has no usable roots");
|
|
412
|
+
}
|
|
413
|
+
return only.root_index;
|
|
414
|
+
}
|
|
415
|
+
throw new InvalidParamsError(`refine_context_run cannot add "${selectedPath}" without a root: ${roots.length} roots are available. ` +
|
|
416
|
+
"Disambiguate by refining a single-root run.");
|
|
417
|
+
}
|
|
418
|
+
function setSelectionEntry(selection, existing, entry) {
|
|
419
|
+
if (existing != null && existing.root_index !== entry.root_index) {
|
|
420
|
+
selection.delete(selectionKey(existing));
|
|
421
|
+
}
|
|
422
|
+
selection.set(selectionKey(entry), entry);
|
|
423
|
+
}
|
|
424
|
+
async function materializeSelection(input) {
|
|
425
|
+
const materialized = [];
|
|
426
|
+
for (const entry of input.selection) {
|
|
427
|
+
throwIfCancelled(input.signal);
|
|
428
|
+
const resolved = await resolveEntryFile(entry, input.roots);
|
|
429
|
+
if (resolved == null) {
|
|
430
|
+
input.omissions.push(omission(entry, "missing_root", "Recorded root is unavailable"));
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
if (resolved.kind === "missing") {
|
|
434
|
+
input.omissions.push(omission(entry, "missing_file", "Refined file no longer exists"));
|
|
435
|
+
input.warnings.push({
|
|
436
|
+
code: "refine_missing_file",
|
|
437
|
+
message: `Refined file no longer exists: ${entry.path}`,
|
|
438
|
+
});
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
const { root, realPath } = resolved;
|
|
442
|
+
if (!isSamePathOrDescendant(realPath, root.path)) {
|
|
443
|
+
input.omissions.push(omission(entry, "path_escape", "Refined file resolved outside its root"));
|
|
444
|
+
input.warnings.push({
|
|
445
|
+
code: "refine_path_escape",
|
|
446
|
+
message: `Refined file resolved outside its recorded root: ${entry.path}`,
|
|
447
|
+
});
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
const pathSecrets = input.allowSecrets ? [] : scanSecretPath(entry.path);
|
|
451
|
+
if (pathSecrets.length > 0) {
|
|
452
|
+
input.omissions.push(omission(entry, "secret_path", "Refined file path matched a secret-path rule"));
|
|
453
|
+
input.warnings.push({
|
|
454
|
+
code: "refine_secret_path",
|
|
455
|
+
message: `Refined file omitted by secret-path filter: ${entry.path}`,
|
|
456
|
+
});
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
// Stat before read: reject an over-cap in-root file without ever reading or
|
|
460
|
+
// hashing the whole body. Slice-level budget checks still run in applyBudget.
|
|
461
|
+
// By design, a file whose RAW size exceeds max_bytes_per_file is omitted
|
|
462
|
+
// WHOLE and cannot be narrowed via a refine set_slices op — it fails safe as
|
|
463
|
+
// a max_bytes_per_file omission (partial run), unlike standalone focus
|
|
464
|
+
// head-slicing.
|
|
465
|
+
const stats = await fsStat(realPath).catch(() => undefined);
|
|
466
|
+
if (stats != null && stats.size > input.budget.max_bytes_per_file) {
|
|
467
|
+
input.omissions.push(omission(entry, "max_bytes_per_file", "Refined file exceeds max_bytes_per_file before read; rejected without loading the full body"));
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const raw = await fsReadFile(realPath).catch(() => undefined);
|
|
471
|
+
if (raw == null) {
|
|
472
|
+
input.omissions.push(omission(entry, "unreadable_file", "Refined file is not readable"));
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
// Post-read recheck closes the stat→read TOCTOU: a file that grew or was
|
|
476
|
+
// swapped between the size guard above and this read must NOT be decoded,
|
|
477
|
+
// hashed, or secret-scanned at over-cap size. Make the cap hard on the
|
|
478
|
+
// actual bytes returned, before any whole-body processing.
|
|
479
|
+
if (raw.byteLength > input.budget.max_bytes_per_file) {
|
|
480
|
+
input.omissions.push(omission(entry, "max_bytes_per_file", "Refined file grew past max_bytes_per_file between stat and read; rejected after read, before decode/hash/scan."));
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
const rawText = raw.toString("utf8");
|
|
484
|
+
const fingerprint = {
|
|
485
|
+
root_index: root.root_index,
|
|
486
|
+
path: entry.path,
|
|
487
|
+
sha256: createHash("sha256").update(raw).digest("hex"),
|
|
488
|
+
byte_length: raw.byteLength,
|
|
489
|
+
};
|
|
490
|
+
warnOnDrift(entry, fingerprint, input.priorFingerprints, input.warnings);
|
|
491
|
+
const sanitized = input.allowSecrets
|
|
492
|
+
? { status: "unchanged", content: rawText, findings: [] }
|
|
493
|
+
: sanitizeHighConfidenceSecretContent(rawText);
|
|
494
|
+
if (sanitized.status === "blocked") {
|
|
495
|
+
input.omissions.push(omission(entry, "content_secret", "Refined file content matched a high-confidence secret rule"));
|
|
496
|
+
input.warnings.push({
|
|
497
|
+
code: "refine_content_secret",
|
|
498
|
+
message: `Refined file omitted by high-confidence secret filter: ${entry.path}`,
|
|
499
|
+
});
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
const content = sanitized.content;
|
|
503
|
+
materialized.push(buildMaterializedFile({
|
|
504
|
+
entry,
|
|
505
|
+
root,
|
|
506
|
+
content,
|
|
507
|
+
rawByteLength: raw.byteLength,
|
|
508
|
+
fingerprint,
|
|
509
|
+
warnings: input.warnings,
|
|
510
|
+
omissions: input.omissions,
|
|
511
|
+
}));
|
|
512
|
+
}
|
|
513
|
+
return materialized;
|
|
514
|
+
}
|
|
515
|
+
async function resolveEntryFile(entry, roots) {
|
|
516
|
+
// Resolve ONLY against the entry's recorded root. Never fall through to a
|
|
517
|
+
// different root that happens to hold the same relative path — that would
|
|
518
|
+
// expose wrong-root content.
|
|
519
|
+
const root = roots.find((candidate) => candidate.root_index === entry.root_index);
|
|
520
|
+
if (root == null) {
|
|
521
|
+
return undefined;
|
|
522
|
+
}
|
|
523
|
+
const absolutePath = path.join(root.path, entry.path);
|
|
524
|
+
const realPath = await fsRealpath(absolutePath).catch(() => undefined);
|
|
525
|
+
if (realPath == null) {
|
|
526
|
+
return { kind: "missing" };
|
|
527
|
+
}
|
|
528
|
+
return { kind: "found", root, realPath };
|
|
529
|
+
}
|
|
530
|
+
function buildMaterializedFile(input) {
|
|
531
|
+
const lines = splitTextLines(input.content);
|
|
532
|
+
const ranges = rangesForDisposition(input.entry, lines.length, input.warnings, input.omissions);
|
|
533
|
+
// Budget contract: `full` and `codemap_only` are BOTH budgeted on full-body
|
|
534
|
+
// bytes, even though `codemap_only` only renders an outline. This is an
|
|
535
|
+
// intentional, conservative over-charge — it can never exceed budget, and it
|
|
536
|
+
// avoids a speculative codemap pre-render sizing path. Only `slices` is
|
|
537
|
+
// budgeted on its narrowed payload.
|
|
538
|
+
const selectedContent = input.entry.disposition === "slices"
|
|
539
|
+
? contentForRanges(lines, ranges)
|
|
540
|
+
: input.content;
|
|
541
|
+
const selectedBytes = Buffer.byteLength(selectedContent, "utf8");
|
|
542
|
+
const slices = input.entry.disposition === "codemap_only"
|
|
543
|
+
? []
|
|
544
|
+
: ranges.map((range) => ({
|
|
545
|
+
root_index: input.root.root_index,
|
|
546
|
+
path: input.entry.path,
|
|
547
|
+
start_line: range.start_line,
|
|
548
|
+
end_line: range.end_line,
|
|
549
|
+
source: "focus",
|
|
550
|
+
content: contentForRanges(lines, [range]),
|
|
551
|
+
}));
|
|
552
|
+
return {
|
|
553
|
+
selected: {
|
|
554
|
+
root_index: input.root.root_index,
|
|
555
|
+
path: input.entry.path,
|
|
556
|
+
ranges,
|
|
557
|
+
content: selectedContent,
|
|
558
|
+
bytes: selectedBytes,
|
|
559
|
+
estimated_tokens: estimateContextBuilderTokensFromUtf8Bytes(selectedBytes),
|
|
560
|
+
source: "focus",
|
|
561
|
+
disposition: input.entry.disposition,
|
|
562
|
+
},
|
|
563
|
+
tree: {
|
|
564
|
+
root_index: input.root.root_index,
|
|
565
|
+
path: input.entry.path,
|
|
566
|
+
size_bytes: input.rawByteLength,
|
|
567
|
+
eligible: true,
|
|
568
|
+
content_eligible: input.entry.disposition !== "codemap_only",
|
|
569
|
+
},
|
|
570
|
+
slices,
|
|
571
|
+
fingerprint: input.fingerprint,
|
|
572
|
+
rawByteLength: input.rawByteLength,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
function rangesForDisposition(entry, lineCount, warnings, omissions) {
|
|
576
|
+
if (entry.disposition === "full" || entry.disposition === "codemap_only") {
|
|
577
|
+
return lineCount === 0 ? [] : [{ start_line: 1, end_line: lineCount }];
|
|
578
|
+
}
|
|
579
|
+
const ranges = clampRanges(entry.ranges, lineCount, entry, warnings);
|
|
580
|
+
if (ranges.length === 0) {
|
|
581
|
+
omissions.push(omission(entry, "stale_slice_range", "All refined slice ranges are outside the current file"));
|
|
582
|
+
}
|
|
583
|
+
return ranges;
|
|
584
|
+
}
|
|
585
|
+
function clampRanges(ranges, lineCount, entry, warnings) {
|
|
586
|
+
const clamped = [];
|
|
587
|
+
for (const range of coalesceRanges(ranges)) {
|
|
588
|
+
if (lineCount === 0 || range.start_line > lineCount) {
|
|
589
|
+
warnings.push({
|
|
590
|
+
code: "refine_slice_range_stale",
|
|
591
|
+
message: `Dropped stale slice range for ${entry.path}: ${range.start_line}-${range.end_line}`,
|
|
592
|
+
});
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
const endLine = Math.min(range.end_line, lineCount);
|
|
596
|
+
if (endLine !== range.end_line) {
|
|
597
|
+
warnings.push({
|
|
598
|
+
code: "refine_slice_range_clamped",
|
|
599
|
+
message: `Clamped stale slice range for ${entry.path}: ${range.start_line}-${range.end_line}`,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
clamped.push({ start_line: range.start_line, end_line: endLine });
|
|
603
|
+
}
|
|
604
|
+
return clamped;
|
|
605
|
+
}
|
|
606
|
+
function applyBudget(input) {
|
|
607
|
+
const selected = [];
|
|
608
|
+
const tree = [];
|
|
609
|
+
const slices = [];
|
|
610
|
+
const fingerprints = [];
|
|
611
|
+
let totalBytes = 0;
|
|
612
|
+
let totalTokens = 0;
|
|
613
|
+
for (const file of input.files) {
|
|
614
|
+
const budgetReason = budgetRejectionReason(file.selected, input.budget, selected.length, totalBytes, totalTokens);
|
|
615
|
+
if (budgetReason != null) {
|
|
616
|
+
input.omissions.push(omission(file.selected, budgetReason, budgetOmissionMessage(budgetReason)));
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
selected.push(file.selected);
|
|
620
|
+
tree.push(file.tree);
|
|
621
|
+
slices.push(...file.slices);
|
|
622
|
+
fingerprints.push(file.fingerprint);
|
|
623
|
+
totalBytes += file.selected.bytes;
|
|
624
|
+
totalTokens += file.selected.estimated_tokens;
|
|
625
|
+
}
|
|
626
|
+
return { selected, tree, slices, fingerprints };
|
|
627
|
+
}
|
|
628
|
+
function budgetRejectionReason(file, budget, selectedCount, totalBytes, totalTokens) {
|
|
629
|
+
if (selectedCount >= budget.max_files) {
|
|
630
|
+
return "max_files";
|
|
631
|
+
}
|
|
632
|
+
if (file.bytes > budget.max_bytes_per_file) {
|
|
633
|
+
return "max_bytes_per_file";
|
|
634
|
+
}
|
|
635
|
+
if (totalBytes + file.bytes > budget.max_total_bytes) {
|
|
636
|
+
return "max_total_bytes";
|
|
637
|
+
}
|
|
638
|
+
if (totalTokens + file.estimated_tokens > budget.target_estimated_tokens) {
|
|
639
|
+
return "target_estimated_tokens";
|
|
640
|
+
}
|
|
641
|
+
return undefined;
|
|
642
|
+
}
|
|
643
|
+
function budgetOmissionMessage(reason) {
|
|
644
|
+
switch (reason) {
|
|
645
|
+
case "max_files":
|
|
646
|
+
return "Refined selection omitted by max_files budget";
|
|
647
|
+
case "max_bytes_per_file":
|
|
648
|
+
return "Refined selection omitted by max_bytes_per_file budget";
|
|
649
|
+
case "max_total_bytes":
|
|
650
|
+
return "Refined selection omitted by max_total_bytes budget";
|
|
651
|
+
case "target_estimated_tokens":
|
|
652
|
+
return "Refined selection omitted by target_estimated_tokens budget";
|
|
653
|
+
default:
|
|
654
|
+
return "Refined selection omitted by budget";
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function buildMetrics(input) {
|
|
658
|
+
return {
|
|
659
|
+
files_seen: input.consideredCount,
|
|
660
|
+
files_considered: input.consideredCount,
|
|
661
|
+
files_selected: input.selected.length,
|
|
662
|
+
files_omitted: input.omittedCount,
|
|
663
|
+
scan_cap_hit: false,
|
|
664
|
+
search_cap_hit: false,
|
|
665
|
+
discovery_byte_cap_hit: false,
|
|
666
|
+
discovery_candidate_cap_hit: false,
|
|
667
|
+
candidate_cap_hit: false,
|
|
668
|
+
bytes_read: input.rawBytesRead,
|
|
669
|
+
bytes_written: 0,
|
|
670
|
+
estimated_tokens: input.selected.reduce((total, file) => total + file.estimated_tokens, 0),
|
|
671
|
+
truncated: input.omittedCount > 0,
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
function normalizeManifestBudget(manifest) {
|
|
675
|
+
const budget = manifest["budget"];
|
|
676
|
+
return normalizeContextBuilderPublicBudget(isRecord(budget) ? budget : undefined);
|
|
677
|
+
}
|
|
678
|
+
function priorFingerprintMap(manifest) {
|
|
679
|
+
const result = new Map();
|
|
680
|
+
const raw = manifest["file_fingerprints"];
|
|
681
|
+
if (Array.isArray(raw)) {
|
|
682
|
+
for (const entry of raw) {
|
|
683
|
+
if (isRecord(entry) &&
|
|
684
|
+
typeof entry["root_index"] === "number" &&
|
|
685
|
+
typeof entry["path"] === "string" &&
|
|
686
|
+
typeof entry["sha256"] === "string" &&
|
|
687
|
+
typeof entry["byte_length"] === "number") {
|
|
688
|
+
const fingerprint = {
|
|
689
|
+
root_index: entry["root_index"],
|
|
690
|
+
path: normalizeRefinePath(entry["path"]),
|
|
691
|
+
sha256: entry["sha256"],
|
|
692
|
+
byte_length: entry["byte_length"],
|
|
693
|
+
};
|
|
694
|
+
result.set(fingerprintKey(fingerprint), fingerprint);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return result;
|
|
698
|
+
}
|
|
699
|
+
// v1 manifests before refine_context_run did not record content hashes.
|
|
700
|
+
// For those parents, drift detection is limited to selected payload bytes,
|
|
701
|
+
// which can miss same-size edits and slice-vs-full differences.
|
|
702
|
+
const selected = manifest["selected_context"];
|
|
703
|
+
if (Array.isArray(selected)) {
|
|
704
|
+
for (const entry of selected) {
|
|
705
|
+
if (isRecord(entry) &&
|
|
706
|
+
typeof entry["root_index"] === "number" &&
|
|
707
|
+
typeof entry["path"] === "string" &&
|
|
708
|
+
typeof entry["bytes"] === "number") {
|
|
709
|
+
const fingerprint = {
|
|
710
|
+
root_index: entry["root_index"],
|
|
711
|
+
path: normalizeRefinePath(entry["path"]),
|
|
712
|
+
sha256: "",
|
|
713
|
+
byte_length: entry["bytes"],
|
|
714
|
+
};
|
|
715
|
+
result.set(fingerprintKey(fingerprint), fingerprint);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return result;
|
|
720
|
+
}
|
|
721
|
+
function warnOnDrift(entry, current, priorFingerprints, warnings) {
|
|
722
|
+
const prior = priorFingerprints.get(fingerprintKey(current));
|
|
723
|
+
if (prior == null) {
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
if (prior.sha256.length > 0) {
|
|
727
|
+
// v2: authoritative raw-content hash + raw byte_length comparison.
|
|
728
|
+
if (prior.sha256 !== current.sha256 ||
|
|
729
|
+
prior.byte_length !== current.byte_length) {
|
|
730
|
+
warnings.push({
|
|
731
|
+
code: "refine_content_drift",
|
|
732
|
+
message: `Refined file changed since prior run: ${entry.path}`,
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
// v1 fallback: the parent recorded only SELECTED payload bytes, which cannot
|
|
738
|
+
// be compared to current RAW bytes without false positives on sliced files
|
|
739
|
+
// (selected bytes < raw bytes even when unchanged). Emit a low-confidence,
|
|
740
|
+
// non-definitive note instead of asserting drift.
|
|
741
|
+
if (prior.byte_length !== current.byte_length) {
|
|
742
|
+
warnings.push({
|
|
743
|
+
code: "refine_drift_unverified",
|
|
744
|
+
message: `Cannot confirm whether ${entry.path} changed since prior run: parent run predates content hashing`,
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
function contentForRanges(lines, ranges) {
|
|
749
|
+
return ranges
|
|
750
|
+
.flatMap((range) => lines.slice(range.start_line - 1, range.end_line))
|
|
751
|
+
.join("\n");
|
|
752
|
+
}
|
|
753
|
+
function normalizeRefinePath(input) {
|
|
754
|
+
const normalized = path.posix
|
|
755
|
+
.normalize(input.replaceAll("\\", "/").replace(/^\.\/+/, ""))
|
|
756
|
+
.replace(/^\.\//, "");
|
|
757
|
+
if (normalized === "." ||
|
|
758
|
+
normalized === ".." ||
|
|
759
|
+
normalized.startsWith("../") ||
|
|
760
|
+
path.posix.isAbsolute(normalized)) {
|
|
761
|
+
throw new InvalidParamsError(`refine_context_run path must be root-relative: ${input}`);
|
|
762
|
+
}
|
|
763
|
+
return normalized;
|
|
764
|
+
}
|
|
765
|
+
function omission(file, reason, message) {
|
|
766
|
+
return {
|
|
767
|
+
root_index: file.root_index,
|
|
768
|
+
reason,
|
|
769
|
+
message,
|
|
770
|
+
paths: [file.path],
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
function fingerprintKey(input) {
|
|
774
|
+
return `${input.root_index}\u0000${input.path}`;
|
|
775
|
+
}
|
|
776
|
+
function isSelectionDisposition(input) {
|
|
777
|
+
return input === "full" || input === "slices" || input === "codemap_only";
|
|
778
|
+
}
|
|
779
|
+
function isRecord(input) {
|
|
780
|
+
return typeof input === "object" && input !== null && !Array.isArray(input);
|
|
781
|
+
}
|
|
782
|
+
function throwIfCancelled(signal) {
|
|
783
|
+
if (signal?.aborted === true) {
|
|
784
|
+
throw new CancellationError();
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
function getDefaultRefineSemaphore() {
|
|
788
|
+
return getSharedContextBuilderSemaphore();
|
|
789
|
+
}
|
|
790
|
+
//# sourceMappingURL=refine-handler.js.map
|