@iowarp/clio-coder 0.3.8 → 0.3.9
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 +49 -0
- package/README.md +7 -3
- package/dist/{acp-U67UHUK2.js → acp-7LOELQFP.js} +6 -6
- package/dist/{agents-YU6SGALZ.js → agents-FIBG2SHA.js} +27 -25
- package/dist/assets/codewiki.json +1 -1
- package/dist/{auth-5ZPJOIVG.js → auth-OI4LIH2I.js} +11 -12
- package/dist/{builtins-C6JMZVV6.js → builtins-AD25UL3C.js} +5 -5
- package/dist/{chunk-5FR74PWO.js → chunk-2JDWVJND.js} +2 -2
- package/dist/chunk-3DPEIQKN.js +113 -0
- package/dist/{chunk-4SPRNWDE.js → chunk-3DUR4WUA.js} +15 -15
- package/dist/{chunk-VHN4MY6O.js → chunk-3MRC2YSQ.js} +2 -2
- package/dist/{chunk-5DHKRSMQ.js → chunk-3UUY7R3Z.js} +11 -7
- package/dist/{chunk-IGWKHNIQ.js → chunk-3V5AYSEQ.js} +8 -8
- package/dist/{chunk-FHJEP5SW.js → chunk-465CC7FK.js} +8 -5
- package/dist/{chunk-5WIGXA4T.js → chunk-47CMYGET.js} +111 -4
- package/dist/{chunk-A3WNZD3P.js → chunk-4H6ULJ3H.js} +67 -21
- package/dist/{chunk-TB5666IT.js → chunk-4LJX2PUC.js} +3 -3
- package/dist/{chunk-XWSF374K.js → chunk-56KB5IJP.js} +2 -2
- package/dist/{chunk-SPULKLCF.js → chunk-5DQRIYDZ.js} +2 -2
- package/dist/{chunk-2HEJ2F35.js → chunk-5HFBWUMU.js} +20 -8
- package/dist/{chunk-WNIJTQQK.js → chunk-5PVQ4SRS.js} +78 -6
- package/dist/{chunk-DYIM5TJT.js → chunk-5QKCQQ3E.js} +262 -6
- package/dist/{chunk-TYPGUK6W.js → chunk-5T7RBWN2.js} +111 -5
- package/dist/{chunk-IIZWH4XA.js → chunk-774ILSRL.js} +2 -2
- package/dist/chunk-7C6RYZGQ.js +391 -0
- package/dist/{chunk-TANS5ZJS.js → chunk-AD7Y7STJ.js} +3 -3
- package/dist/{chunk-RWSI4YD7.js → chunk-AEYBF3TB.js} +33 -12
- package/dist/{chunk-DGSYXYMX.js → chunk-AMKHQW3C.js} +2 -2
- package/dist/{chunk-VWZOAB7K.js → chunk-B5XRQOLB.js} +7 -7
- package/dist/{chunk-WXY7KU3G.js → chunk-BVDVID7E.js} +2 -2
- package/dist/{chunk-PMDBGQSJ.js → chunk-CA42X6KT.js} +2 -2
- package/dist/{chunk-HLE42MG7.js → chunk-D73KXYPF.js} +3 -3
- package/dist/{chunk-5Q2VVUKB.js → chunk-DG4M6ZUE.js} +3 -3
- package/dist/{chunk-ME6CCNFO.js → chunk-EBOC7MT3.js} +6 -6
- package/dist/{chunk-MXKJU4JB.js → chunk-ECUO3KDP.js} +48 -7
- package/dist/{chunk-26LEYJZH.js → chunk-FALJGAWU.js} +2 -2
- package/dist/{chunk-GWS3VEIW.js → chunk-FWDFM5ZU.js} +24 -3
- package/dist/{chunk-7RGZWPB6.js → chunk-GAYUJ7LE.js} +67 -13
- package/dist/{chunk-VCBR6CU7.js → chunk-HAY4ZE2P.js} +2 -2
- package/dist/{chunk-FBVTI2TJ.js → chunk-HCBCAYZU.js} +11 -130
- package/dist/{chunk-WSB3FPX7.js → chunk-HJB5IUKP.js} +32 -136
- package/dist/{chunk-J3YUBZWY.js → chunk-HKO36JWF.js} +33 -5
- package/dist/{chunk-E77JEWSD.js → chunk-HPCTNZM2.js} +6 -36
- package/dist/{chunk-FJ3H4MN5.js → chunk-IHKBWSXF.js} +2 -2
- package/dist/{chunk-NMPKI6XL.js → chunk-JEQQR47K.js} +37 -18
- package/dist/{chunk-3BINW3FP.js → chunk-KV2AOLDF.js} +24 -4
- package/dist/{chunk-YS5VLNH5.js → chunk-LXPJXFM5.js} +7 -7
- package/dist/{chunk-7RFXX52T.js → chunk-MIX5N5AC.js} +271 -41
- package/dist/{chunk-K4XHGFR5.js → chunk-MLOK6ZOS.js} +1297 -218
- package/dist/{chunk-ZNLWCMVZ.js → chunk-MV2VUEJC.js} +2 -2
- package/dist/{chunk-MVVUPGPW.js → chunk-MXHC5QYU.js} +6 -6
- package/dist/{chunk-5H3GB5BO.js → chunk-N3PBVRTZ.js} +4 -382
- package/dist/{chunk-2HFZQUHL.js → chunk-N5XKWMDW.js} +17 -7
- package/dist/{chunk-5C3AQNDW.js → chunk-NNNWO6F2.js} +124 -36
- package/dist/{chunk-GU2UIAFZ.js → chunk-NQ6UCCOD.js} +3 -3
- package/dist/{chunk-N22QMJKY.js → chunk-NZU6YDNV.js} +4 -4
- package/dist/{chunk-ZVJ5BLO2.js → chunk-O6I4CIEU.js} +151 -13
- package/dist/{chunk-XN3L4EYL.js → chunk-OEDBCISO.js} +2 -2
- package/dist/{chunk-VAWNZU7Z.js → chunk-P3JGPQFL.js} +2 -2
- package/dist/{chunk-IJ7RPIYJ.js → chunk-PNY46YEY.js} +20 -3
- package/dist/{chunk-U6MBIEMB.js → chunk-PZ4I4JE2.js} +56 -35
- package/dist/{chunk-GPIEI3LY.js → chunk-QQ7EKM72.js} +2 -2
- package/dist/{chunk-WLFILSD5.js → chunk-R7LNVMCS.js} +66 -28
- package/dist/{chunk-GOXNB3AO.js → chunk-RAPCMZL4.js} +75 -4
- package/dist/chunk-RKKLTLYB.js +45 -0
- package/dist/{chunk-TT36MB5S.js → chunk-RKRLDWD3.js} +3 -1
- package/dist/{chunk-TTHACPOM.js → chunk-S4COXYBG.js} +456 -18
- package/dist/{chunk-WWCZ5F23.js → chunk-T3Z6VAAF.js} +69 -10
- package/dist/{chunk-GN57SG4G.js → chunk-TD7UE2L5.js} +9 -7
- package/dist/{chunk-TLQJPP24.js → chunk-TEO2TLVN.js} +523 -322
- package/dist/{chunk-FCSXB6T2.js → chunk-UOSL25KY.js} +14 -2
- package/dist/{chunk-KTYTFRMB.js → chunk-VKBMFOYV.js} +17 -15
- package/dist/{chunk-PT7HYKEM.js → chunk-VO2LKSTM.js} +2 -2
- package/dist/{chunk-P43ETTHK.js → chunk-VPTUJU4P.js} +2 -2
- package/dist/{chunk-WEH5XRJQ.js → chunk-WIE7ZOSW.js} +2 -2
- package/dist/{chunk-EMYUUSFG.js → chunk-WXCJ7VME.js} +5 -5
- package/dist/{chunk-4DGYLA73.js → chunk-XDOQXGFO.js} +22 -7
- package/dist/{chunk-JOZYP4GM.js → chunk-YKOFT37S.js} +5 -5
- package/dist/chunk-YSEHGPCT.js +127 -0
- package/dist/{chunk-HFSBBKSQ.js → chunk-YW7UVM5V.js} +138 -3
- package/dist/cli/index.js +27 -27
- package/dist/{clio-QVTYJ57A.js → clio-LT5V7SSZ.js} +6 -6
- package/dist/{code-nav-FGGFIE7L.js → code-nav-LMW275PA.js} +4 -4
- package/dist/{config-LW5IJFQN.js → config-RXS5T3JT.js} +71 -43
- package/dist/{configure-7XIZCOU4.js → configure-2WYWSCSD.js} +14 -15
- package/dist/{context-Y6Y7QPR6.js → context-I3BTOTCS.js} +12 -12
- package/dist/{context-L3WL3X7K.js → context-MVOORGMF.js} +34 -33
- package/dist/{context-N52ZA626.js → context-PALKKQYL.js} +20 -20
- package/dist/{context-clear-MBQRLSDQ.js → context-clear-N2WOYZ2K.js} +34 -33
- package/dist/{context-index-HVMFQHK3.js → context-index-HNG3MOME.js} +2 -2
- package/dist/{context-working-set-GS6DSO7F.js → context-working-set-MIEVECVZ.js} +10 -11
- package/dist/{dispatch-runner-22ZCNOM3.js → dispatch-runner-VVA4SRRH.js} +34 -33
- package/dist/doctor-TWBWFK5V.js +165 -0
- package/dist/{eval-BEC2WHDA.js → eval-IJ5VEZDJ.js} +2016 -142
- package/dist/{evidence-REJUMSKM.js → evidence-L5APPXNV.js} +29 -28
- package/dist/{evolve-PY5ZBA5K.js → evolve-RGNKFJ52.js} +29 -28
- package/dist/{extensions-HVKU65YU.js → extensions-7WYWUX5A.js} +9 -3
- package/dist/{fleet-7WZEWRFA.js → fleet-6CNVBZZP.js} +87 -55
- package/dist/{fleet-commands-UVHWM76J.js → fleet-commands-L2SXSYEI.js} +6 -6
- package/dist/{fleet-graph-6ULH7PES.js → fleet-graph-2J3OOIPO.js} +14 -12
- package/dist/{fleet-preflight-J53T6CCE.js → fleet-preflight-CZRJ4JP5.js} +3 -4
- package/dist/{fleet-validate-72PC4SLA.js → fleet-validate-C5RI6DP7.js} +16 -15
- package/dist/{init-OG3TPGQG.js → init-VBN2ACVA.js} +50 -48
- package/dist/{library-CNTMPLRF.js → library-JHGUMLY2.js} +13 -11
- package/dist/{memory-6IS7F275.js → memory-K4OQIYWG.js} +31 -30
- package/dist/{models-ENRJDA5W.js → models-2NCZUWDD.js} +23 -22
- package/dist/{monitor-XLDVO7TN.js → monitor-MMVTJABD.js} +35 -34
- package/dist/{orchestrator-6KSPYRHA.js → orchestrator-ZKBPCHW6.js} +1627 -294
- package/dist/{reset-RZ4ER727.js → reset-DD5JGOY3.js} +3 -3
- package/dist/{run-Y2CNK5RU.js → run-QEGNX7FL.js} +56 -55
- package/dist/{share-A55GYP6Z.js → share-JKD3BQMW.js} +13 -11
- package/dist/{skills-ALC5J6AT.js → skills-LMQIKDOZ.js} +14 -12
- package/dist/{skills-eval-JPBEBYQU.js → skills-eval-I7X2774U.js} +34 -32
- package/dist/{steer-GGWFUJUD.js → steer-CF5TDANS.js} +3 -3
- package/dist/{support-MIETYA5E.js → support-I7LOJLIF.js} +4 -4
- package/dist/{targets-VGNXIR3S.js → targets-RUSR6B5Z.js} +58 -32
- package/dist/{terminal-lease-WOBR64YA.js → terminal-lease-QYVORFR4.js} +6 -4
- package/dist/{trace-PNCASAXC.js → trace-ODOQIVIW.js} +61 -6
- package/dist/{upgrade-FUSUAGHR.js → upgrade-XANW3FXB.js} +17 -16
- package/dist/{usage-N4MKVHKD.js → usage-4H7ZRXQT.js} +88 -44
- package/dist/{verifiers-YAWOJ3H2.js → verifiers-UZXNBZEB.js} +6 -6
- package/dist/{verify-LTDHYBGY.js → verify-BVKWTNDL.js} +5 -5
- package/dist/{wiki-generate-6M7GHTBJ.js → wiki-generate-MY7WV2QI.js} +49 -47
- package/dist/worker/entry.js +29 -33
- package/docs/alcf-provider.md +1 -1
- package/docs/architecture.md +1 -1
- package/docs/artifact-versions.md +6 -1
- package/docs/built-in-agents.md +1 -1
- package/docs/capacity-and-scheduling.md +23 -2
- package/docs/commands-and-modes.md +1 -1
- package/docs/configuration-and-targets.md +30 -3
- package/docs/context-engine.md +63 -4
- package/docs/documentation-coverage.md +3 -3
- package/docs/documentation-guide.md +1 -1
- package/docs/environment-variables.md +2 -0
- package/docs/eval-runner.md +262 -11
- package/docs/evals-internal.md +72 -2
- package/docs/evidence-and-memory.md +11 -10
- package/docs/evolution.md +1 -1
- package/docs/extensions-and-sharing.md +3 -1
- package/docs/fleet-dispatch.md +4 -4
- package/docs/installation-and-lifecycle.md +1 -1
- package/docs/middleware-and-components.md +1 -1
- package/docs/model-catalog.md +1 -1
- package/docs/observability.md +53 -2
- package/docs/proactive-memory.md +127 -14
- package/docs/prompt-envelope-and-tools.md +19 -1
- package/docs/provider-adapter-cookbook.md +1 -1
- package/docs/release-cut-checklist.md +19 -3
- package/docs/safety-model.md +1 -1
- package/docs/scientific-validation.md +1 -1
- package/docs/skills-marketplace.md +1 -1
- package/docs/tool-usage.md +1 -1
- package/docs/trace-store.md +1 -1
- package/docs/troubleshooting.md +87 -0
- package/docs/tui-design.md +1 -1
- package/docs/worker-dispatch-mechanics.md +1 -1
- package/package.json +2 -1
- package/src/cli/agents.ts +1 -1
- package/src/cli/config-inspect.ts +33 -6
- package/src/cli/config.ts +1 -1
- package/src/cli/doctor-state-size.ts +82 -0
- package/src/cli/doctor.ts +3 -1
- package/src/cli/eval.ts +80 -16
- package/src/cli/extensions.ts +5 -1
- package/src/cli/fleet.ts +32 -3
- package/src/cli/targets.ts +44 -13
- package/src/cli/trace.ts +63 -4
- package/src/cli/usage.ts +63 -14
- package/src/core/bus-events.ts +29 -1
- package/src/core/cache-telemetry.ts +42 -0
- package/src/core/config.ts +18 -0
- package/src/core/defaults.ts +36 -6
- package/src/core/endpoint-key.ts +27 -0
- package/src/core/residency-target-key.ts +25 -0
- package/src/core/response-schema.ts +36 -2
- package/src/domains/config/classify.ts +3 -0
- package/src/domains/context/codewiki/coordinator.ts +12 -4
- package/src/domains/dispatch/admission.ts +40 -3
- package/src/domains/dispatch/capacity-lease.ts +98 -9
- package/src/domains/dispatch/contract.ts +11 -0
- package/src/domains/dispatch/execution-plan.ts +44 -4
- package/src/domains/dispatch/extension.ts +166 -42
- package/src/domains/dispatch/fleet-run.ts +23 -3
- package/src/domains/dispatch/heartbeat.ts +32 -8
- package/src/domains/dispatch/index.ts +3 -0
- package/src/domains/dispatch/orphan-recovery.ts +5 -0
- package/src/domains/dispatch/reservation-store.ts +116 -8
- package/src/domains/dispatch/state.ts +4 -0
- package/src/domains/dispatch/worker-spawn.ts +25 -11
- package/src/domains/dispatch/write-boundary-enforcer.ts +20 -3
- package/src/domains/dispatch/write-boundary.ts +62 -1
- package/src/domains/eval/artifacts/store.ts +62 -0
- package/src/domains/eval/compare/behavioral.ts +224 -0
- package/src/domains/eval/compare/compare.ts +355 -2
- package/src/domains/eval/compare/envelope.ts +128 -0
- package/src/domains/eval/compare/gates.ts +24 -6
- package/src/domains/eval/compare/thresholds.ts +30 -3
- package/src/domains/eval/execution-provenance.ts +240 -0
- package/src/domains/eval/metrics/aggregate.ts +136 -0
- package/src/domains/eval/metrics/call-ledger-stream.ts +112 -0
- package/src/domains/eval/metrics/tracked.ts +413 -0
- package/src/domains/eval/provenance.ts +117 -0
- package/src/domains/eval/reports/comparison.ts +128 -0
- package/src/domains/eval/reports/junit.ts +17 -3
- package/src/domains/eval/reports/markdown.ts +3 -3
- package/src/domains/eval/reports/text.ts +14 -0
- package/src/domains/eval/run-compare.ts +20 -0
- package/src/domains/eval/runners/clio-run.ts +127 -0
- package/src/domains/eval/runners/external-command.ts +28 -3
- package/src/domains/eval/schema/adapter.ts +111 -0
- package/src/domains/eval/schema/artifact.ts +20 -0
- package/src/domains/eval/schema/behavioral-metrics.ts +204 -0
- package/src/domains/eval/schema/behavioral.ts +520 -0
- package/src/domains/eval/schema/execution-envelope.ts +194 -0
- package/src/domains/eval/schema/serving.ts +74 -0
- package/src/domains/eval/schema/suite.ts +38 -8
- package/src/domains/eval/schema/validate.ts +58 -3
- package/src/domains/eval/schema/verdict.ts +237 -0
- package/src/domains/eval/suites/resolve.ts +2 -0
- package/src/domains/eval/suites/run.ts +264 -33
- package/src/domains/eval/verifiers/command.ts +2 -1
- package/src/domains/eval/workspaces/temp-copy.ts +145 -13
- package/src/domains/evidence/build.ts +2 -13
- package/src/domains/evidence/eval.ts +2 -12
- package/src/domains/evidence/findings-markdown.ts +33 -0
- package/src/domains/evidence/run-trust.ts +7 -113
- package/src/domains/evidence/trust-projection.ts +2 -2
- package/src/domains/extensions/compatibility.ts +285 -0
- package/src/domains/extensions/discovery.ts +38 -3
- package/src/domains/extensions/resources.ts +1 -1
- package/src/domains/extensions/state.ts +12 -3
- package/src/domains/extensions/types.ts +2 -0
- package/src/domains/lifecycle/doctor.ts +69 -1
- package/src/domains/memory/index.ts +14 -0
- package/src/domains/memory/task-bank-promotion.ts +64 -0
- package/src/domains/memory/task-memory-policy.ts +77 -8
- package/src/domains/memory/task-memory-spend.ts +131 -0
- package/src/domains/memory/task-memory-status.ts +7 -0
- package/src/domains/memory/task-memory-telemetry.ts +2 -0
- package/src/domains/middleware/index.ts +1 -0
- package/src/domains/middleware/memory-intervention.ts +69 -5
- package/src/domains/middleware/memory-step-endpoint.ts +71 -0
- package/src/domains/observability/background-memory-usage.ts +140 -0
- package/src/domains/observability/cost.ts +1 -1
- package/src/domains/observability/index.ts +7 -0
- package/src/domains/observability/out-of-turn-usage.ts +51 -2
- package/src/domains/observability/trace-store.ts +192 -2
- package/src/domains/prompts/compiler.ts +100 -13
- package/src/domains/providers/endpoint-capacity.ts +96 -0
- package/src/domains/providers/index.ts +10 -0
- package/src/domains/providers/models/local-models/clio-local-coding-targets.yaml +243 -1
- package/src/domains/providers/runtime-resolution.ts +8 -1
- package/src/domains/providers/runtimes/common/probe-helpers.ts +31 -9
- package/src/domains/providers/runtimes/local-native/llamacpp-anthropic.ts +1 -1
- package/src/domains/providers/runtimes/local-native/llamacpp-completion.ts +1 -1
- package/src/domains/providers/runtimes/local-native/llamacpp-embed.ts +1 -1
- package/src/domains/providers/runtimes/local-native/llamacpp-rerank.ts +1 -1
- package/src/domains/providers/runtimes/local-native/llamacpp.ts +4 -1
- package/src/domains/providers/runtimes/local-native/lmstudio.ts +4 -1
- package/src/domains/providers/runtimes/local-native/ollama-native.ts +6 -1
- package/src/domains/providers/types/capability-flags.ts +2 -0
- package/src/domains/providers/types/target-descriptor.ts +2 -0
- package/src/domains/resources/prompts/loader.ts +95 -33
- package/src/domains/safety/call-target.ts +52 -0
- package/src/domains/safety/run-effects.ts +35 -4
- package/src/domains/session/context-accounting.ts +52 -1
- package/src/domains/session/context-ledger.ts +37 -13
- package/src/domains/session/index.ts +6 -0
- package/src/domains/session/prompt-cache.ts +140 -0
- package/src/domains/session/prompt-manifest.ts +42 -0
- package/src/engine/acp/adapter.ts +18 -3
- package/src/engine/ai.ts +35 -0
- package/src/engine/apis/llamacpp-residency.ts +55 -3
- package/src/engine/apis/lmstudio.ts +25 -5
- package/src/engine/apis/ollama-native.ts +2 -1
- package/src/engine/apis/openai-completions.ts +80 -17
- package/src/engine/apis/residency-lock.ts +3 -1
- package/src/engine/apis/residency.ts +34 -1
- package/src/engine/provider-payload.ts +29 -1
- package/src/entry/orchestrator.ts +176 -30
- package/src/interactive/chat-loop-messages.ts +26 -7
- package/src/interactive/chat-loop.ts +318 -41
- package/src/interactive/chat-panel.ts +62 -8
- package/src/interactive/clio-editor.ts +45 -8
- package/src/interactive/context-activity.ts +5 -1
- package/src/interactive/context-meter.ts +1 -1
- package/src/interactive/context-overlay.ts +40 -10
- package/src/interactive/cost-overlay.ts +64 -6
- package/src/interactive/dispatch-board.ts +84 -12
- package/src/interactive/fleet-run-preview.ts +41 -15
- package/src/interactive/handoff-round.ts +41 -2
- package/src/interactive/interactive-application.ts +24 -1
- package/src/interactive/interactive-input-runtime.ts +8 -0
- package/src/interactive/interactive-presentation.ts +4 -0
- package/src/interactive/interactive-shell.ts +20 -17
- package/src/interactive/interactive-slash-runtime.ts +27 -4
- package/src/interactive/memory-overlay.ts +8 -0
- package/src/interactive/mutation-preview.ts +295 -0
- package/src/interactive/overlay-general-openers.ts +16 -0
- package/src/interactive/overlay-key-routing.ts +38 -0
- package/src/interactive/overlay-lifecycle.ts +38 -5
- package/src/interactive/overlay-permission-lifecycle.ts +22 -2
- package/src/interactive/overlay-session-lifecycle.ts +73 -9
- package/src/interactive/overlays/ask-user.ts +91 -19
- package/src/interactive/overlays/help-reference.ts +4 -0
- package/src/interactive/overlays/prompts.ts +11 -1
- package/src/interactive/overlays/settings.ts +35 -1
- package/src/interactive/permission-hint.ts +34 -2
- package/src/interactive/permission-overlay.ts +159 -9
- package/src/interactive/prewarm.ts +197 -0
- package/src/interactive/render-trace.ts +162 -15
- package/src/interactive/renderers/tool-execution.ts +4 -0
- package/src/interactive/side-question.ts +58 -1
- package/src/interactive/status/controller.ts +11 -0
- package/src/interactive/status/state-machine.ts +54 -2
- package/src/interactive/status/types.ts +7 -0
- package/src/interactive/terminal-lease.ts +2 -0
- package/src/interactive/turn-context.ts +299 -31
- package/src/interactive/turn-persistence.ts +14 -4
- package/src/interactive/turn-prewarm.ts +364 -0
- package/src/interactive/turn-queues.ts +7 -4
- package/src/interactive/turn-runtime.ts +8 -1
- package/src/interactive/turn-state.ts +23 -0
- package/src/interactive/view/view-overlay.ts +28 -3
- package/src/tools/ask-user.ts +43 -2
- package/src/tools/dispatch-plan.ts +17 -9
- package/src/tools/dispatch-scout.ts +1 -1
- package/src/tools/registry.ts +16 -0
- package/dist/chunk-AOCYTWAV.js +0 -449
- package/dist/chunk-HWUFFB6L.js +0 -83
- package/dist/chunk-R346GLFC.js +0 -31
- package/dist/doctor-M7YEDGAE.js +0 -91
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RESPONSE_SCHEMA_RUNTIME_ID } from "../core/response-schema.js";
|
|
1
|
+
import { RESPONSE_SCHEMA_RUNTIME_ID, type ResponseSchemaDialect } from "../core/response-schema.js";
|
|
2
2
|
import type { ThinkingLevel } from "../domains/providers/index.js";
|
|
3
3
|
import type { EngineModel } from "./types.js";
|
|
4
4
|
|
|
@@ -217,6 +217,34 @@ function patchLlamaCppResponseSchemaPayload(
|
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Apply a JSON-schema response constraint in the dialect the runtime takes.
|
|
222
|
+
*
|
|
223
|
+
* Unlike the worker patcher above, this one is for a seam that treats native
|
|
224
|
+
* enforcement as an optimization: the caller looks the dialect up first and
|
|
225
|
+
* simply does not call this when there is none, so an unconstrained request
|
|
226
|
+
* still goes out and the prompt-level instruction carries it (issue #223).
|
|
227
|
+
* Returns undefined when the payload is not an object, which leaves it alone.
|
|
228
|
+
*/
|
|
229
|
+
export function patchResponseSchemaPayloadForDialect(
|
|
230
|
+
payload: unknown,
|
|
231
|
+
dialect: ResponseSchemaDialect,
|
|
232
|
+
responseSchema: Record<string, unknown>,
|
|
233
|
+
schemaName: string,
|
|
234
|
+
): unknown | undefined {
|
|
235
|
+
if (!isRecord(payload)) return undefined;
|
|
236
|
+
if (dialect === "llamacpp-json-object") {
|
|
237
|
+
return { ...payload, response_format: { type: "json_object", schema: responseSchema } };
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
...payload,
|
|
241
|
+
response_format: {
|
|
242
|
+
type: "json_schema",
|
|
243
|
+
json_schema: { name: schemaName, strict: true, schema: responseSchema },
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
220
248
|
export interface WorkerPayloadPatchOptions {
|
|
221
249
|
runtimeId: string;
|
|
222
250
|
thinkingLevel?: ThinkingLevel;
|
|
@@ -8,6 +8,7 @@ import { installBusTracer } from "../core/bus-trace.js";
|
|
|
8
8
|
import { type ClioSettings, readSettings, type SettingsMutator, updateSettings } from "../core/config.js";
|
|
9
9
|
import { DEFAULT_DELEGATION_PERMISSION_TIMEOUT_MS } from "../core/defaults.js";
|
|
10
10
|
import { loadDomains } from "../core/domain-loader.js";
|
|
11
|
+
import type { SafeEventBus } from "../core/event-bus.js";
|
|
11
12
|
import { expandInlineFileReferencesAsync } from "../core/file-references.js";
|
|
12
13
|
import { setGitCommitAttributionEnabled } from "../core/git-commit-attribution.js";
|
|
13
14
|
import { configureGuardrails } from "../core/guardrails.js";
|
|
@@ -63,9 +64,13 @@ import {
|
|
|
63
64
|
createTaskMemoryTelemetrySink,
|
|
64
65
|
createTaskMemoryTrace,
|
|
65
66
|
loadMemoryRecordsSync,
|
|
67
|
+
proposeInjectedTaskMemory,
|
|
68
|
+
readTaskMemorySpendSummary,
|
|
66
69
|
renderTaskMemoryHandoffSource,
|
|
67
70
|
seedTaskMemoryFromNewestHandoff,
|
|
71
|
+
type TaskMemoryEntry,
|
|
68
72
|
type TaskMemoryModelClient,
|
|
73
|
+
type TaskMemoryStepUsage,
|
|
69
74
|
taskMemoryBankSize,
|
|
70
75
|
taskMemoryHandoffSeedOffer,
|
|
71
76
|
taskMemoryTracePath,
|
|
@@ -88,21 +93,26 @@ import {
|
|
|
88
93
|
writeMiddlewareDiagnosticToStderr,
|
|
89
94
|
} from "../domains/middleware/index.js";
|
|
90
95
|
import { createMemoryInterventionRegistration } from "../domains/middleware/memory-intervention.js";
|
|
96
|
+
import { announceMemoryStepEndpoint } from "../domains/middleware/memory-step-endpoint.js";
|
|
91
97
|
import { createTaskBoardReminderRegistration } from "../domains/middleware/task-board-reminder.js";
|
|
92
98
|
import { createTaskNudgeRegistration } from "../domains/middleware/task-nudge.js";
|
|
93
99
|
import { createWatchdogRegistration } from "../domains/middleware/watchdog.js";
|
|
94
100
|
import type { ObservabilityContract } from "../domains/observability/index.js";
|
|
95
|
-
import { ObservabilityDomainModule } from "../domains/observability/index.js";
|
|
101
|
+
import { ObservabilityDomainModule, recordBackgroundMemoryStep } from "../domains/observability/index.js";
|
|
96
102
|
import type { PromptsContract } from "../domains/prompts/contract.js";
|
|
97
103
|
import { createPromptsDomainModule } from "../domains/prompts/index.js";
|
|
98
104
|
import type { ProvidersContract, TargetDescriptor, ThinkingLevel } from "../domains/providers/index.js";
|
|
99
105
|
import {
|
|
100
106
|
AGENT_ROLE_TOOLS_REQUIRED_REASON,
|
|
101
107
|
applyModelCapabilityPatch,
|
|
108
|
+
canonicalEndpointKey,
|
|
102
109
|
firstRuntimeResolutionError,
|
|
110
|
+
foregroundStreamUsage,
|
|
103
111
|
isOrchestratorEligibleRuntime,
|
|
112
|
+
normalizeCostProvenance,
|
|
104
113
|
ProvidersDomainModule,
|
|
105
114
|
refineRuntimeTargetWithModelHints,
|
|
115
|
+
registerForegroundStream,
|
|
106
116
|
resolveModelCapabilities,
|
|
107
117
|
resolveModelRuntimeCapabilitiesForProviders,
|
|
108
118
|
resolveRuntimeTarget,
|
|
@@ -159,7 +169,7 @@ import {
|
|
|
159
169
|
INTERACTIVE_LOOP_BLOCK_BUDGET,
|
|
160
170
|
readOrchTurnToolCallBudget,
|
|
161
171
|
} from "../engine/loop-guard.js";
|
|
162
|
-
import { openSession, readSessionTailTurns, sessionCurrentPath, sessionPaths } from "../engine/session.js";
|
|
172
|
+
import { cwdHash, openSession, readSessionTailTurns, sessionCurrentPath, sessionPaths } from "../engine/session.js";
|
|
163
173
|
import type { EngineModel } from "../engine/types.js";
|
|
164
174
|
import { createChatLoop } from "../interactive/chat-loop.js";
|
|
165
175
|
import { type RunIo, startInteractive } from "../interactive/index.js";
|
|
@@ -268,6 +278,7 @@ function applyHeadlessSettingsOverlay(
|
|
|
268
278
|
interface CompactionResolution {
|
|
269
279
|
model: EngineModel;
|
|
270
280
|
targetId: string;
|
|
281
|
+
endpointKey: string | null;
|
|
271
282
|
apiKey?: string;
|
|
272
283
|
}
|
|
273
284
|
|
|
@@ -310,11 +321,26 @@ export async function resolveApiKeyForTarget(
|
|
|
310
321
|
return resolved.apiKey;
|
|
311
322
|
}
|
|
312
323
|
|
|
324
|
+
/**
|
|
325
|
+
* The background memory role, resolved to the endpoint it would call.
|
|
326
|
+
*
|
|
327
|
+
* The endpoint key is what lets the middleware decline a step that would land
|
|
328
|
+
* on the same inference scheduler the chat target is streaming against (#229,
|
|
329
|
+
* #250), and it is the same key dispatch admission counts slots on.
|
|
330
|
+
*/
|
|
331
|
+
interface BackgroundMemoryRoute {
|
|
332
|
+
client: TaskMemoryModelClient;
|
|
333
|
+
targetId: string;
|
|
334
|
+
wireModelId: string;
|
|
335
|
+
endpointKey: string | null;
|
|
336
|
+
}
|
|
337
|
+
|
|
313
338
|
function createBackgroundMemoryModelClient(
|
|
314
339
|
providers: ProvidersContract,
|
|
315
340
|
settings: Readonly<ClioSettings>,
|
|
316
341
|
timeoutMs: number,
|
|
317
|
-
|
|
342
|
+
bus: Pick<SafeEventBus, "emit"> | null,
|
|
343
|
+
): BackgroundMemoryRoute | null {
|
|
318
344
|
const targetId = settings.background.target?.trim();
|
|
319
345
|
const wireModelId = settings.background.model?.trim();
|
|
320
346
|
if (!targetId || !wireModelId) return null;
|
|
@@ -343,24 +369,57 @@ function createBackgroundMemoryModelClient(
|
|
|
343
369
|
const model = resolved.target.runtime.synthesizeModel(resolved.target.target, resolved.target.wireModelId, kbHit);
|
|
344
370
|
const refined = refineRuntimeTargetWithModelHints(resolved.target, model, providers.knowledgeBase);
|
|
345
371
|
applyModelCapabilityPatch(model, refined.capabilities);
|
|
372
|
+
const costProvenance = normalizeCostProvenance(refined.costProvenance);
|
|
373
|
+
const endpointKey = canonicalEndpointKey(refined.target);
|
|
346
374
|
return {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
375
|
+
targetId,
|
|
376
|
+
wireModelId: refined.wireModelId,
|
|
377
|
+
endpointKey,
|
|
378
|
+
client: {
|
|
379
|
+
// Wrapped at the layer that knows a request left the process: the step
|
|
380
|
+
// holds endpoint capacity while it is out and publishes the cache
|
|
381
|
+
// disturbance even when a timeout means the usage sink never sees it.
|
|
382
|
+
complete: announceMemoryStepEndpoint({ bus, endpointKey, targetId }, async (request) => {
|
|
383
|
+
const apiKey = targetRequiresAuth(refined.target, refined.runtime)
|
|
384
|
+
? (await providers.auth.resolveForTarget(refined.target, refined.runtime, { signal: request.signal })).apiKey
|
|
385
|
+
: LOCAL_API_KEY_FALLBACK;
|
|
386
|
+
const startedAt = Date.now();
|
|
387
|
+
const completion = await completeEngineText({
|
|
388
|
+
model,
|
|
389
|
+
systemPrompt: request.systemPrompt,
|
|
390
|
+
userPrompt: request.userPrompt,
|
|
391
|
+
maxTokens: request.maxTokens,
|
|
392
|
+
// Always off, never the operator's chat thinking level. A model that
|
|
393
|
+
// reasons anyway still works: `completeEngineText` keeps only text
|
|
394
|
+
// blocks, and the memory output budget leaves room for the preamble.
|
|
395
|
+
thinkingLevel: "off",
|
|
396
|
+
signal: request.signal,
|
|
397
|
+
timeoutMs,
|
|
398
|
+
...(apiKey === undefined ? {} : { apiKey }),
|
|
399
|
+
});
|
|
400
|
+
// The step is billed here whatever the policy later decides about the
|
|
401
|
+
// answer. A model that read a trajectory and chose silence spent the
|
|
402
|
+
// same prefill as one that produced a reminder.
|
|
403
|
+
return {
|
|
404
|
+
text: completion.text,
|
|
405
|
+
inputTokens: completion.inputTokens,
|
|
406
|
+
outputTokens: completion.outputTokens,
|
|
407
|
+
usage: {
|
|
408
|
+
targetId,
|
|
409
|
+
attributedModelId: refined.wireModelId,
|
|
410
|
+
input: completion.usage.input,
|
|
411
|
+
output: completion.usage.output,
|
|
412
|
+
cacheRead: completion.usage.cacheRead,
|
|
413
|
+
cacheWrite: completion.usage.cacheWrite,
|
|
414
|
+
reasoning: completion.usage.reasoning,
|
|
415
|
+
totalTokens: completion.usage.totalTokens,
|
|
416
|
+
costUsd: completion.usage.costUsd,
|
|
417
|
+
costProvenance,
|
|
418
|
+
durationMs: Date.now() - startedAt,
|
|
419
|
+
backend: completion.backend,
|
|
420
|
+
},
|
|
421
|
+
};
|
|
422
|
+
}),
|
|
364
423
|
},
|
|
365
424
|
};
|
|
366
425
|
}
|
|
@@ -463,7 +522,7 @@ async function resolveCompactionModel(
|
|
|
463
522
|
const model = synthesizeOrchestratorModel(providers, target, wireModelId);
|
|
464
523
|
if (!model) return null;
|
|
465
524
|
const apiKey = await resolveApiKeyForTarget(target, providers);
|
|
466
|
-
const resolution: CompactionResolution = { model, targetId };
|
|
525
|
+
const resolution: CompactionResolution = { model, targetId, endpointKey: canonicalEndpointKey(target) };
|
|
467
526
|
if (apiKey !== undefined) resolution.apiKey = apiKey;
|
|
468
527
|
return resolution;
|
|
469
528
|
}
|
|
@@ -591,12 +650,21 @@ async function runCompactionFlow(
|
|
|
591
650
|
const entries = filterEntriesToActivePath(readSessionEntriesForCompact(meta.id), activeLeafTurnId);
|
|
592
651
|
if (entries.length === 0) return null;
|
|
593
652
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
653
|
+
// A compaction summary is a full streamed request against the chat target.
|
|
654
|
+
// Hold the same canonical endpoint slot as an ordinary turn, /btw round, or
|
|
655
|
+
// pre-warm so dispatch admission and background memory see its real usage.
|
|
656
|
+
const releaseEndpointSlot = resolved.endpointKey === null ? () => {} : registerForegroundStream(resolved.endpointKey);
|
|
657
|
+
let result: CompactResult;
|
|
658
|
+
try {
|
|
659
|
+
result = await compact({
|
|
660
|
+
entries,
|
|
661
|
+
model: resolved.model,
|
|
662
|
+
...(resolved.apiKey !== undefined ? { apiKey: resolved.apiKey } : {}),
|
|
663
|
+
...(instructions !== undefined ? { instructions } : {}),
|
|
664
|
+
});
|
|
665
|
+
} finally {
|
|
666
|
+
releaseEndpointSlot();
|
|
667
|
+
}
|
|
600
668
|
if (result.messagesSummarized === 0 || result.summary.length === 0) return null;
|
|
601
669
|
|
|
602
670
|
const entry: Omit<CompactionSummaryEntry, "turnId" | "timestamp"> = {
|
|
@@ -1079,6 +1147,53 @@ export async function bootOrchestrator(options: BootOptions = {}): Promise<BootR
|
|
|
1079
1147
|
// telemetry row says which silence happened; this says what the model wrote.
|
|
1080
1148
|
const memoryTracePath = taskMemoryTracePath();
|
|
1081
1149
|
const memoryTrace = memoryTracePath === null ? null : createTaskMemoryTrace(memoryTracePath);
|
|
1150
|
+
// The route the last resolved memory client would call, kept so the endpoint
|
|
1151
|
+
// check and the cost row read the same resolution the step itself used.
|
|
1152
|
+
let backgroundMemoryRoute: BackgroundMemoryRoute | null = null;
|
|
1153
|
+
/**
|
|
1154
|
+
* Account for one background memory step exactly as a `/btw` side question is
|
|
1155
|
+
* accounted for: the in-process cost tracker under its own label so `/cost`
|
|
1156
|
+
* shows it while the session lives, and one durable out-of-turn row so
|
|
1157
|
+
* `clio-coder usage report` can still see it afterwards.
|
|
1158
|
+
*
|
|
1159
|
+
* Accounting only. The client wrapper (`announceMemoryStepEndpoint`) holds the
|
|
1160
|
+
* endpoint slot and publishes the disturbance; it sees the timed-out and
|
|
1161
|
+
* thrown steps this sink never hears about because their usage stays null.
|
|
1162
|
+
*/
|
|
1163
|
+
const recordBackgroundMemoryUsage = (usage: TaskMemoryStepUsage): void => {
|
|
1164
|
+
const meta = session?.current() ?? null;
|
|
1165
|
+
try {
|
|
1166
|
+
recordBackgroundMemoryStep({
|
|
1167
|
+
usage,
|
|
1168
|
+
stateDir: clioStateDir(),
|
|
1169
|
+
sessionId: meta?.id ?? null,
|
|
1170
|
+
// The identity the session ledger is filed under, so `usage report
|
|
1171
|
+
// --repo` selects these rows with the same hash it selects ledgers with.
|
|
1172
|
+
repoIdentity: meta ? meta.cwdHash || cwdHash(meta.cwd || process.cwd()) : null,
|
|
1173
|
+
...(observability === undefined ? {} : { observability }),
|
|
1174
|
+
});
|
|
1175
|
+
} catch {
|
|
1176
|
+
// Accounting is bookkeeping. Its failure never reaches the memory step.
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
const proposeInjectedMemoryEntries = (entries: ReadonlyArray<TaskMemoryEntry>): void => {
|
|
1180
|
+
const meta = session?.current() ?? null;
|
|
1181
|
+
void proposeInjectedTaskMemory(clioDataDir(), {
|
|
1182
|
+
sessionId: meta?.id ?? null,
|
|
1183
|
+
cwd: meta?.cwd || process.cwd(),
|
|
1184
|
+
entries,
|
|
1185
|
+
})
|
|
1186
|
+
.then((result) => {
|
|
1187
|
+
for (const error of result.errors) {
|
|
1188
|
+
process.stderr.write(`[clio:memory] proposed record not written for ${error}\n`);
|
|
1189
|
+
}
|
|
1190
|
+
})
|
|
1191
|
+
.catch((error: unknown) => {
|
|
1192
|
+
process.stderr.write(
|
|
1193
|
+
`[clio:memory] proposed records not written: ${error instanceof Error ? error.message : String(error)}\n`,
|
|
1194
|
+
);
|
|
1195
|
+
});
|
|
1196
|
+
};
|
|
1082
1197
|
const memoryIntervention = createMemoryInterventionRegistration({
|
|
1083
1198
|
bank: taskMemoryBank,
|
|
1084
1199
|
telemetry: createTaskMemoryTelemetrySink(),
|
|
@@ -1093,10 +1208,26 @@ export async function bootOrchestrator(options: BootOptions = {}): Promise<BootR
|
|
|
1093
1208
|
},
|
|
1094
1209
|
getModelClient: () => {
|
|
1095
1210
|
const settings = effectiveSettingsForDispatch?.();
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1211
|
+
backgroundMemoryRoute =
|
|
1212
|
+
settings === undefined
|
|
1213
|
+
? null
|
|
1214
|
+
: createBackgroundMemoryModelClient(providers, settings, settings.memory.intervention.timeoutMs, bus);
|
|
1215
|
+
return backgroundMemoryRoute?.client ?? null;
|
|
1216
|
+
},
|
|
1217
|
+
// A single-slot local server serves one request at a time, so a memory step
|
|
1218
|
+
// started while the operator's turn is streaming either waits behind it or
|
|
1219
|
+
// makes the server swap the resident model out to answer. The chat loop
|
|
1220
|
+
// registers its stream on the endpoint it streams against, so the two are
|
|
1221
|
+
// compared by the same canonical key dispatch admission counts slots on.
|
|
1222
|
+
backgroundEndpointBusy: () => {
|
|
1223
|
+
const endpointKey = backgroundMemoryRoute?.endpointKey ?? null;
|
|
1224
|
+
if (endpointKey === null) return false;
|
|
1225
|
+
// This runs before the client wrapper registers the admitted step, so the
|
|
1226
|
+
// count contains other requests only and the step cannot refuse itself.
|
|
1227
|
+
return (foregroundStreamUsage()[endpointKey] ?? 0) > 0;
|
|
1099
1228
|
},
|
|
1229
|
+
onStepUsage: (usage) => recordBackgroundMemoryUsage(usage),
|
|
1230
|
+
onInjectedEntries: (entries) => proposeInjectedMemoryEntries(entries),
|
|
1100
1231
|
});
|
|
1101
1232
|
middleware.registerHook(memoryIntervention);
|
|
1102
1233
|
const unsubscribeMemoryLoop = bus.on(BusChannels.LoopBlocked, () => memoryIntervention.signalLoop());
|
|
@@ -1569,6 +1700,12 @@ export async function bootOrchestrator(options: BootOptions = {}): Promise<BootR
|
|
|
1569
1700
|
}
|
|
1570
1701
|
|
|
1571
1702
|
const chat = createChatLoop({
|
|
1703
|
+
// The pre-warm holds one slot on its endpoint while it runs, so dispatch
|
|
1704
|
+
// admission (#250) sees it exactly as it sees the orchestrator's own turn.
|
|
1705
|
+
registerPrewarmEndpointSlot: (runtime) => {
|
|
1706
|
+
const key = canonicalEndpointKey(runtime.runtimeResolution.target);
|
|
1707
|
+
return key === null ? null : registerForegroundStream(key);
|
|
1708
|
+
},
|
|
1572
1709
|
getSettings: getCurrentSettings,
|
|
1573
1710
|
providers,
|
|
1574
1711
|
middleware,
|
|
@@ -1628,6 +1765,11 @@ export async function bootOrchestrator(options: BootOptions = {}): Promise<BootR
|
|
|
1628
1765
|
: {}),
|
|
1629
1766
|
toolRegistry,
|
|
1630
1767
|
hasAttachedDispatch: () => dispatchBackground.size() > 0,
|
|
1768
|
+
// The pre-warm buys latency for a person about to type the next turn. A
|
|
1769
|
+
// headless `run` submits its one prompt immediately and an unattended boot
|
|
1770
|
+
// never submits at all, so neither has latency to buy; the ACP surface has
|
|
1771
|
+
// an operator on the other end of the client and keeps it.
|
|
1772
|
+
isLatencySurface: () => interactive || acpMode,
|
|
1631
1773
|
});
|
|
1632
1774
|
|
|
1633
1775
|
// Coordinated shutdown (SIGINT/SIGTERM, TUI quit) must abort any in-flight
|
|
@@ -1891,6 +2033,10 @@ export async function bootOrchestrator(options: BootOptions = {}): Promise<BootR
|
|
|
1891
2033
|
bank,
|
|
1892
2034
|
activity: memoryIntervention.recentActivity(),
|
|
1893
2035
|
stepInFlight: memoryIntervention.stepInFlight(),
|
|
2036
|
+
// Folded from the telemetry ledger, which is durable across sessions,
|
|
2037
|
+
// so `/memory` answers what the tier has cost since it was turned on
|
|
2038
|
+
// rather than what it cost since this process started.
|
|
2039
|
+
spend: readTaskMemorySpendSummary(clioStateDir()),
|
|
1894
2040
|
};
|
|
1895
2041
|
},
|
|
1896
2042
|
getTaskMemorySeedOffer,
|
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
9
|
+
import {
|
|
10
|
+
type BackendCacheVerdict,
|
|
11
|
+
type BackendCompletionTimings,
|
|
12
|
+
uncachedPrefillTokens,
|
|
13
|
+
} from "../core/cache-telemetry.js";
|
|
9
14
|
import { settingsPath } from "../core/config.js";
|
|
10
15
|
import {
|
|
11
16
|
addResponseModelIdObservationCount,
|
|
@@ -446,20 +451,34 @@ export function sumRunUsage(messages: ReadonlyArray<AgentMessage>): RunUsageSumm
|
|
|
446
451
|
return summary;
|
|
447
452
|
}
|
|
448
453
|
|
|
449
|
-
export type BackendCacheVerdict
|
|
454
|
+
export type { BackendCacheVerdict } from "../core/cache-telemetry.js";
|
|
455
|
+
|
|
456
|
+
function classifyCacheUsage(input: number, cacheRead: number): BackendCacheVerdict {
|
|
457
|
+
if (cacheRead > 0) return input >= 2000 ? "partial" : "hot";
|
|
458
|
+
return input >= 2000 ? "cold" : "small";
|
|
459
|
+
}
|
|
450
460
|
|
|
451
461
|
/**
|
|
452
|
-
* Classify one API call's provider-reported usage.
|
|
453
|
-
*
|
|
454
|
-
*
|
|
462
|
+
* Classify one API call's provider-reported usage. When normalized provider
|
|
463
|
+
* usage reports no cache read but the serving backend supplies cache_n, use
|
|
464
|
+
* that direct observation instead. This is the single definition of a cache
|
|
465
|
+
* verdict; the ledger, the overlay, and any forensics reader all consume the
|
|
466
|
+
* persisted value rather than reclassifying:
|
|
455
467
|
* hot cacheRead > 0 and input < 2000 (prefix reused, prefill ≈ user text)
|
|
456
468
|
* partial cacheRead > 0 and input >= 2000 (prefix reused up to a divergence point)
|
|
457
469
|
* cold cacheRead == 0 and input >= 2000 (full re-prefill)
|
|
458
470
|
* small cacheRead == 0 and input < 2000 (too small to judge)
|
|
459
471
|
*/
|
|
460
|
-
export function backendCacheVerdict(
|
|
461
|
-
|
|
462
|
-
|
|
472
|
+
export function backendCacheVerdict(
|
|
473
|
+
input: number,
|
|
474
|
+
cacheRead: number,
|
|
475
|
+
backend?: BackendCompletionTimings | null,
|
|
476
|
+
): BackendCacheVerdict {
|
|
477
|
+
if (cacheRead === 0 && backend?.cachedTokens !== null && backend?.cachedTokens !== undefined) {
|
|
478
|
+
const backendInput = uncachedPrefillTokens(backend);
|
|
479
|
+
if (backendInput !== null) return classifyCacheUsage(backendInput, backend.cachedTokens);
|
|
480
|
+
}
|
|
481
|
+
return classifyCacheUsage(input, cacheRead);
|
|
463
482
|
}
|
|
464
483
|
|
|
465
484
|
/** Per-API-call latency captured from the agent event stream (T3.2). */
|