@iowarp/clio-coder 0.3.3 → 0.3.6
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 +74 -0
- package/CONTRIBUTING.md +7 -7
- package/README.md +3 -3
- package/dist/{acp-P2AQILE2.js → acp-2BEHC4DL.js} +9 -8
- package/dist/{agents-72W3BI7I.js → agents-LNNFTM53.js} +29 -24
- package/dist/assets/codewiki.json +1 -1
- package/dist/{auth-5TWEIYDN.js → auth-KXXFI2VS.js} +14 -10
- package/dist/{chunk-GGXXDWE4.js → chunk-22NAGB7X.js} +2 -2
- package/dist/{chunk-YCWGATWI.js → chunk-24I7BN55.js} +2 -2
- package/dist/{chunk-EKMEHE4H.js → chunk-33YXPOE3.js} +2 -3
- package/dist/chunk-3BPUFZDL.js +37 -0
- package/dist/chunk-43AOLP7E.js +375 -0
- package/dist/{chunk-ZDOOVTXZ.js → chunk-4OC57DA6.js} +27 -4
- package/dist/{chunk-6SGHMWE3.js → chunk-5JGRAMKL.js} +5 -5
- package/dist/{chunk-V6RTAOC2.js → chunk-6US73PDB.js} +572 -51
- package/dist/{chunk-5UFT4SUX.js → chunk-6XXKFVSN.js} +3 -3
- package/dist/{chunk-A3CYT5EX.js → chunk-AD2SYQYC.js} +55 -2
- package/dist/chunk-AOCYTWAV.js +449 -0
- package/dist/chunk-CFGTUFWB.js +67 -0
- package/dist/chunk-CJUB2JJ2.js +1478 -0
- package/dist/{chunk-FNTMWMX5.js → chunk-CKXWIANG.js} +14 -12
- package/dist/{chunk-PIWWS5BL.js → chunk-CYQKWTG3.js} +63 -78
- package/dist/{chunk-LZSJBIVT.js → chunk-DJVECN66.js} +271 -762
- package/dist/{chunk-CBCAPZAA.js → chunk-E25LMLRW.js} +2 -2
- package/dist/{chunk-ZWMF7253.js → chunk-E2ER4LJF.js} +304 -9
- package/dist/{chunk-STBPMHSX.js → chunk-EKY57CSP.js} +51 -84
- package/dist/{chunk-DUYJ5IO6.js → chunk-EYPA3EGJ.js} +12 -4
- package/dist/{chunk-M6SHUN7Q.js → chunk-FO5ZOVUY.js} +2 -2
- package/dist/chunk-FYYLNIL5.js +313 -0
- package/dist/{chunk-OQ33BKR3.js → chunk-G7MUEIGA.js} +3 -60
- package/dist/chunk-GEYXPTRF.js +613 -0
- package/dist/chunk-GOXNB3AO.js +261 -0
- package/dist/{chunk-G4BMMOKF.js → chunk-HVDIIIQW.js} +2 -2
- package/dist/chunk-HWUFFB6L.js +83 -0
- package/dist/{chunk-4XUGQOHA.js → chunk-K7T3E2SR.js} +15 -8
- package/dist/chunk-K7VKOLQQ.js +15 -0
- package/dist/{chunk-UFIIWP2H.js → chunk-KHSFENX2.js} +8 -8
- package/dist/{chunk-BMEMKKIT.js → chunk-KOHPCX4K.js} +2 -2
- package/dist/chunk-LCGCVYZ4.js +57 -0
- package/dist/chunk-LL4KHSZI.js +22 -0
- package/dist/{chunk-PAJK6MAQ.js → chunk-LYF7OHWH.js} +42 -15
- package/dist/{chunk-POHLU5DW.js → chunk-M6L6IDJG.js} +3 -3
- package/dist/{chunk-5UUP6MWO.js → chunk-MV3K5QF2.js} +5 -436
- package/dist/{chunk-X4RCMKVQ.js → chunk-NDINPTJ4.js} +2 -2
- package/dist/{chunk-TZK7PACC.js → chunk-NILBFAPG.js} +14 -8
- package/dist/chunk-ODFEOB4F.js +1082 -0
- package/dist/{chunk-AGYYIBLL.js → chunk-OH3TOQTB.js} +6 -2
- package/dist/chunk-OZNBF4L3.js +23 -0
- package/dist/{chunk-DSELYM6W.js → chunk-PBTHKCPN.js} +30 -10
- package/dist/{verify-375KUB3Y.js → chunk-PCZJO5TI.js} +127 -42
- package/dist/{chunk-ED4KHGC3.js → chunk-PPAMZ32Z.js} +9 -2
- package/dist/{chunk-SRDMMSEP.js → chunk-QM3F2GKX.js} +1063 -1645
- package/dist/{chunk-X6IAEBZR.js → chunk-QNQHSOLF.js} +7 -7
- package/dist/{chunk-OC7FIQPC.js → chunk-R46L2BIR.js} +10 -7
- package/dist/{chunk-2TLUCQVG.js → chunk-RD5U66HV.js} +3 -3
- package/dist/{chunk-6N5PTWMY.js → chunk-RY3LY4J5.js} +50 -13
- package/dist/{chunk-OKGUZO2U.js → chunk-SPULKLCF.js} +4 -3
- package/dist/{chunk-OOJYHWRB.js → chunk-TSHXZTOQ.js} +6 -5
- package/dist/chunk-TZSKNMZG.js +434 -0
- package/dist/{chunk-7MNJORFF.js → chunk-UL3WSD3F.js} +6 -1
- package/dist/{chunk-VJWL6YS5.js → chunk-UUVG37B4.js} +2 -2
- package/dist/{chunk-COU2UHX6.js → chunk-VEZEGCGW.js} +170 -2
- package/dist/chunk-W6GROXXM.js +69 -0
- package/dist/{chunk-OAO4GE4M.js → chunk-WHGPSPT5.js} +2 -2
- package/dist/chunk-WHJYKASB.js +677 -0
- package/dist/{chunk-ORBHGJC5.js → chunk-WR67VIZY.js} +3 -3
- package/dist/{chunk-YHZX5GEU.js → chunk-XAKHZX5N.js} +2 -2
- package/dist/{chunk-TZTZS7QK.js → chunk-XE2VEJHX.js} +5 -3
- package/dist/{chunk-LM5TQCJZ.js → chunk-XF5N4U5A.js} +8 -7
- package/dist/{chunk-LWLEKMDQ.js → chunk-XXQNGV4M.js} +1073 -552
- package/dist/{chunk-KZWTDYJF.js → chunk-XYDYPRZI.js} +7 -7
- package/dist/chunk-ZGVHUX3M.js +66 -0
- package/dist/{chunk-LW6DSM3M.js → chunk-ZRGEBJ4T.js} +1192 -1119
- package/dist/{chunk-2DJ2KNFG.js → chunk-ZXF4XRKW.js} +202 -40
- package/dist/chunk-ZZMN5OM4.js +122 -0
- package/dist/cli/index.js +34 -30
- package/dist/{clio-JOU4FXVA.js → clio-M2KGYUFZ.js} +7 -6
- package/dist/{code-nav-7AX6FYE6.js → code-nav-GQNL7XA6.js} +8 -6
- package/dist/codewiki/build-worker.js +4 -4
- package/dist/{components-KELWS457.js → components-5TTYYX6G.js} +3 -3
- package/dist/{config-XCDVKR23.js → config-XUUYQIWO.js} +47 -35
- package/dist/{configure-4GAP54ZW.js → configure-IHJ7YOMV.js} +18 -15
- package/dist/{context-77FM5DV5.js → context-74JLXAWD.js} +18 -10
- package/dist/{context-4UOGGLQ5.js → context-75MIWW3U.js} +41 -29
- package/dist/{context-5VKGUVJJ.js → context-ZQ7SIFJV.js} +85 -9
- package/dist/{context-clear-XXJRLCJJ.js → context-clear-GYKWNUML.js} +41 -29
- package/dist/{context-index-BZ4UYMTC.js → context-index-SSR5ECNE.js} +3 -3
- package/dist/context-working-set-UX5KEP4J.js +1553 -0
- package/dist/{dispatch-runner-QPRDDBDX.js → dispatch-runner-GIJBHNFL.js} +47 -32
- package/dist/{docs-2C2LTVT2.js → docs-6FZSCG5B.js} +3 -3
- package/dist/{doctor-HR46URBJ.js → doctor-SVJ5BZCW.js} +12 -12
- package/dist/{eval-XSSNATB4.js → eval-CG6LLBLD.js} +54 -238
- package/dist/{evidence-6HG2PY2B.js → evidence-ZYFIEN42.js} +57 -28
- package/dist/{evolve-K7YU3NCY.js → evolve-QGEXEMDW.js} +36 -25
- package/dist/{extensions-QVDOHDGJ.js → extensions-ADGNCJJD.js} +3 -3
- package/dist/{fleet-VY3HHKN6.js → fleet-S5R4ZOQY.js} +73 -44
- package/dist/{fleet-preflight-DDN536IT.js → fleet-preflight-BHSNPBMH.js} +3 -3
- package/dist/{init-JYGXI3FK.js → init-5DRU55YR.js} +49 -37
- package/dist/memory-7YKKR6UC.js +467 -0
- package/dist/{models-I5QWSEOM.js → models-ZPOLRU2C.js} +24 -21
- package/dist/{monitor-GE4ID3IA.js → monitor-US5F5YGZ.js} +73 -46
- package/dist/{orchestrator-EM5MC3HM.js → orchestrator-E2AL4T5N.js} +1624 -1007
- package/dist/{paths-UXLN5YYZ.js → paths-E7KYAQWE.js} +3 -3
- package/dist/{reset-L2FQEE3E.js → reset-KZ652EK6.js} +6 -5
- package/dist/{run-ZU3QMZPZ.js → run-SRNBKDWD.js} +76 -54
- package/dist/{share-S5BZQC5I.js → share-CGZE33UP.js} +7 -6
- package/dist/{skills-X5VXCRNQ.js → skills-S2X4DLY5.js} +4 -4
- package/dist/{skills-eval-WKIHWTHR.js → skills-eval-W2GGIC4R.js} +40 -29
- package/dist/{targets-SNCPI2NR.js → targets-54SWINWB.js} +28 -23
- package/dist/{terminal-lease-BNAHVHBS.js → terminal-lease-SAIF2OGY.js} +6 -4
- package/dist/{uninstall-FZCQCDKC.js → uninstall-BVLWXKBT.js} +3 -3
- package/dist/{upgrade-JQHHPQ4K.js → upgrade-JKAR27XC.js} +20 -19
- package/dist/{usage-OR4O5SMZ.js → usage-MSAWCLX4.js} +79 -36
- package/dist/verifiers-NCBTHHN2.js +1220 -0
- package/dist/verify-X5HDROLA.js +25 -0
- package/dist/{wiki-generate-UEXP2ARI.js → wiki-generate-GUSOQ6ZP.js} +50 -37
- package/dist/worker/entry.js +90 -70
- package/dist/{workspace-G4ZWUIPR.js → workspace-ZJ6BFM3Q.js} +4 -4
- package/docs/README.md +8 -7
- package/docs/acp.md +1 -1
- package/docs/alcf-provider.md +1 -1
- package/docs/architecture.md +2 -2
- package/docs/artifact-placement.md +1 -2
- package/docs/artifact-versions.md +1 -1
- package/docs/built-in-agents.md +1 -1
- package/docs/capacity-and-scheduling.md +1 -1
- package/docs/commands-and-modes.md +60 -26
- package/docs/config-knobs-audit.md +1 -2
- package/docs/configuration-and-targets.md +26 -1
- package/docs/context-engine.md +67 -13
- package/docs/context-working-set.md +194 -0
- package/docs/development-pipeline.md +1 -1
- package/docs/documentation-coverage.md +6 -6
- package/docs/documentation-guide.md +7 -6
- package/docs/environment-variables.md +2 -1
- package/docs/eval-runner.md +1 -1
- package/docs/evals-internal.md +4 -32
- package/docs/evidence-and-memory.md +139 -7
- package/docs/evolution.md +1 -1
- package/docs/exit-codes-and-output.md +1 -1
- package/docs/extensions-and-sharing.md +2 -2
- package/docs/fleet-dispatch.md +49 -8
- package/docs/glossary.md +21 -1
- package/docs/installation-and-lifecycle.md +2 -2
- package/docs/middleware-and-components.md +19 -2
- package/docs/model-catalog.md +7 -9
- package/docs/observability.md +4 -4
- package/docs/proactive-memory.md +26 -16
- package/docs/prompt-envelope-and-tools.md +7 -5
- package/docs/provider-adapter-cookbook.md +1 -1
- package/docs/release-cut-checklist.md +43 -40
- package/docs/safety-model.md +49 -8
- package/docs/scientific-validation.md +21 -3
- package/docs/session-lifecycle.md +3 -3
- package/docs/skills-marketplace.md +1 -1
- package/docs/tool-usage.md +79 -12
- package/docs/trace-store.md +1 -1
- package/docs/troubleshooting.md +1 -1
- package/docs/tui-design.md +38 -4
- package/docs/worker-dispatch-mechanics.md +11 -1
- package/package.json +13 -13
- package/skills/meta/clio-test/SKILL.md +20 -17
- package/skills/meta/clio-test/evals.md +3 -3
- package/skills/meta/clio-test/references/harness.md +35 -6
- package/skills/meta/clio-test/references/test-map.md +20 -10
- package/skills/registry.yaml +2 -2
- package/skills/skill-marketplace.json +1 -1
- package/src/cli/agents.ts +2 -3
- package/src/cli/argv.ts +14 -1
- package/src/cli/context-working-set.ts +513 -0
- package/src/cli/context.ts +8 -0
- package/src/cli/evidence.ts +20 -2
- package/src/cli/fleet.ts +15 -0
- package/src/cli/index.ts +5 -1
- package/src/cli/memory.ts +272 -10
- package/src/cli/modes/json-stream.ts +2 -2
- package/src/cli/modes/print.ts +12 -1
- package/src/cli/run.ts +22 -2
- package/src/cli/targets.ts +12 -3
- package/src/cli/usage.ts +55 -7
- package/src/cli/verifiers.ts +325 -0
- package/src/core/bash-exec.ts +39 -14
- package/src/core/bus-events.ts +22 -4
- package/src/core/config.ts +54 -0
- package/src/core/defaults.ts +50 -3
- package/src/core/response-model-id.ts +134 -0
- package/src/core/toml.ts +62 -0
- package/src/core/verification-scripts.ts +6 -0
- package/src/core/workspace-files.ts +0 -1
- package/src/domains/agents/builtins/architect.md +1 -1
- package/src/domains/agents/builtins/verifier.md +3 -0
- package/src/domains/agents/catalog.ts +5 -4
- package/src/domains/agents/recipe.ts +54 -14
- package/src/domains/agents/result-contract.ts +7 -4
- package/src/domains/config/classify.ts +1 -0
- package/src/domains/context/bootstrap.ts +36 -27
- package/src/domains/context/project-metadata.ts +19 -63
- package/src/domains/context/prompt-context.ts +8 -0
- package/src/domains/context/working-set/contract.ts +161 -0
- package/src/domains/context/working-set/defaults.ts +28 -0
- package/src/domains/context/working-set/engine.ts +203 -0
- package/src/domains/context/working-set/fold.ts +62 -0
- package/src/domains/context/working-set/horizon.ts +38 -0
- package/src/domains/context/working-set/marker.ts +103 -0
- package/src/domains/context/working-set/path-index.ts +436 -0
- package/src/domains/context/working-set/payload.ts +152 -0
- package/src/domains/context/working-set/policies/age-horizon.ts +55 -0
- package/src/domains/context/working-set/policies/index.ts +20 -0
- package/src/domains/context/working-set/policies/structural.ts +160 -0
- package/src/domains/context/working-set/project.ts +132 -0
- package/src/domains/context/working-set/protect.ts +109 -0
- package/src/domains/context/working-set/recall.ts +177 -0
- package/src/domains/context/working-set/replay/controls.ts +112 -0
- package/src/domains/context/working-set/replay/load-clio.ts +199 -0
- package/src/domains/context/working-set/replay/metrics.ts +185 -0
- package/src/domains/context/working-set/replay/reference-graph.ts +79 -0
- package/src/domains/context/working-set/replay/report.ts +139 -0
- package/src/domains/context/working-set/replay/runner.ts +325 -0
- package/src/domains/context/working-set/replay/synthetic.ts +422 -0
- package/src/domains/context/working-set/replay/trace.ts +21 -0
- package/src/domains/context/working-set/visible.ts +54 -0
- package/src/domains/dispatch/budget-envelope.ts +396 -0
- package/src/domains/dispatch/contract.ts +2 -0
- package/src/domains/dispatch/extension.ts +81 -27
- package/src/domains/dispatch/orphan-recovery.ts +1 -0
- package/src/domains/dispatch/receipt-integrity.ts +4 -0
- package/src/domains/dispatch/state.ts +1 -0
- package/src/domains/dispatch/types.ts +10 -3
- package/src/domains/dispatch/validation.ts +14 -0
- package/src/domains/dispatch/worker-spawn.ts +14 -3
- package/src/domains/eval/metrics/evidence.ts +0 -116
- package/src/domains/eval/metrics/invariants.ts +1 -1
- package/src/domains/eval/runners/clio-run.ts +1 -10
- package/src/domains/eval/runners/external-command.ts +2 -29
- package/src/domains/eval/schema/suite.ts +0 -7
- package/src/domains/eval/suites/run.ts +1 -7
- package/src/domains/evidence/build.ts +112 -45
- package/src/domains/evidence/eval.ts +24 -7
- package/src/domains/evidence/index.ts +53 -0
- package/src/domains/evidence/ordering.ts +12 -0
- package/src/domains/evidence/run-trust.ts +221 -0
- package/src/domains/evidence/store.ts +46 -6
- package/src/domains/evidence/trust-status.ts +854 -0
- package/src/domains/evidence/types.ts +26 -0
- package/src/domains/memory/index.ts +22 -0
- package/src/domains/memory/operations.ts +58 -1
- package/src/domains/memory/promotion.ts +281 -0
- package/src/domains/memory/prompt-section.ts +25 -5
- package/src/domains/memory/proposal.ts +51 -7
- package/src/domains/memory/task-bank.ts +3 -2
- package/src/domains/memory/task-memory-handoff.ts +181 -24
- package/src/domains/memory/task-memory-policy.ts +3 -1
- package/src/domains/memory/types.ts +37 -0
- package/src/domains/memory/validate.ts +178 -0
- package/src/domains/middleware/memory-intervention.ts +38 -25
- package/src/domains/middleware/runtime.ts +6 -0
- package/src/domains/middleware/skills-reminder.ts +19 -4
- package/src/domains/middleware/stalled-turn.ts +208 -5
- package/src/domains/middleware/types.ts +10 -0
- package/src/domains/observability/contract.ts +6 -1
- package/src/domains/observability/cost.ts +20 -4
- package/src/domains/observability/extension.ts +2 -2
- package/src/domains/providers/index.ts +3 -0
- package/src/domains/providers/model-discovery.ts +9 -0
- package/src/domains/providers/runtime-resolution.ts +38 -1
- package/src/domains/providers/runtimes/common/probe-helpers.ts +97 -16
- package/src/domains/providers/types/context-window-slots.ts +18 -0
- package/src/domains/providers/types/runtime-descriptor.ts +3 -1
- package/src/domains/safety/autonomy.ts +1 -1
- package/src/domains/safety/call-target.ts +211 -14
- package/src/domains/safety/decision-presentation.ts +268 -0
- package/src/domains/safety/default-path-policy.ts +8 -0
- package/src/domains/safety/finish-contract.ts +4 -3
- package/src/domains/safety/policy-engine.ts +48 -6
- package/src/domains/safety/redaction.ts +73 -0
- package/src/domains/session/compaction/compact.ts +23 -1
- package/src/domains/session/compaction/cut-point.ts +2 -0
- package/src/domains/session/compaction/tokens.ts +16 -1
- package/src/domains/session/context-ledger.ts +12 -1
- package/src/domains/session/decision-board.ts +4 -0
- package/src/domains/session/entries.ts +110 -1
- package/src/domains/session/history.ts +68 -19
- package/src/domains/session/manager.ts +9 -2
- package/src/domains/session/migrations/index.ts +22 -3
- package/src/domains/session/usage.ts +24 -7
- package/src/engine/acp/event-mapper.ts +7 -0
- package/src/engine/acp/server.ts +32 -2
- package/src/engine/agent.ts +18 -1
- package/src/engine/apis/lmstudio.ts +25 -4
- package/src/engine/apis/openai-completions.ts +147 -22
- package/src/engine/claude/sdk-runtime.ts +8 -2
- package/src/engine/claude/tool-safety.ts +13 -0
- package/src/engine/loop-guard.ts +27 -3
- package/src/engine/session.ts +9 -3
- package/src/engine/worker-events.ts +4 -3
- package/src/engine/worker-runtime.ts +59 -54
- package/src/entry/orchestrator.ts +34 -5
- package/src/interactive/chat-loop-messages.ts +40 -6
- package/src/interactive/chat-loop.ts +13 -0
- package/src/interactive/chat-panel.ts +17 -1
- package/src/interactive/chat-renderer.ts +49 -24
- package/src/interactive/clio-editor.ts +44 -7
- package/src/interactive/context-meter.ts +10 -0
- package/src/interactive/context-overlay.ts +120 -7
- package/src/interactive/context-recall-command.ts +110 -0
- package/src/interactive/cost-overlay.ts +39 -8
- package/src/interactive/dispatch-board.ts +212 -35
- package/src/interactive/footer/widgets.ts +13 -0
- package/src/interactive/interactive-application.ts +6 -1
- package/src/interactive/interactive-input-runtime.ts +11 -1
- package/src/interactive/interactive-presentation.ts +11 -1
- package/src/interactive/interactive-slash-runtime.ts +37 -1
- package/src/interactive/memory-overlay.ts +89 -4
- package/src/interactive/model-session-replay.ts +21 -0
- package/src/interactive/overlay-ask-user-lifecycle.ts +1 -1
- package/src/interactive/overlay-frame.ts +5 -2
- package/src/interactive/overlay-general-openers.ts +46 -1
- package/src/interactive/overlay-key-routing.ts +41 -1
- package/src/interactive/overlay-lifecycle.ts +11 -4
- package/src/interactive/overlay-permission-lifecycle.ts +23 -8
- package/src/interactive/overlay-session-lifecycle.ts +8 -4
- package/src/interactive/overlay-transitions.ts +11 -0
- package/src/interactive/overlays/ask-user.ts +74 -30
- package/src/interactive/overlays/decisions.ts +3 -1
- package/src/interactive/permission-hint.ts +35 -0
- package/src/interactive/permission-overlay.ts +95 -45
- package/src/interactive/renderers/tool-execution.ts +37 -51
- package/src/interactive/session-last-turn.ts +8 -1
- package/src/interactive/session-transcript.ts +2 -2
- package/src/interactive/session-usage-reseed.ts +36 -10
- package/src/interactive/slash-commands.ts +31 -4
- package/src/interactive/status/summary.ts +5 -0
- package/src/interactive/status/types.ts +5 -0
- package/src/interactive/terminal-lease.ts +1 -0
- package/src/interactive/turn-context.ts +333 -110
- package/src/interactive/turn-middleware.ts +7 -6
- package/src/interactive/turn-runtime.ts +37 -8
- package/src/interactive/turn-state.ts +3 -0
- package/src/interactive/worker-progress.ts +440 -0
- package/src/interactive/worker-stream.ts +51 -110
- package/src/tools/agent-tools.ts +39 -7
- package/src/tools/ask-user.ts +21 -1
- package/src/tools/bash.ts +144 -82
- package/src/tools/builtin-tool-catalog.ts +11 -5
- package/src/tools/context/index.ts +107 -5
- package/src/tools/context/surface.ts +3 -2
- package/src/tools/core-bootstrap.ts +21 -0
- package/src/tools/dispatch-arguments.ts +8 -0
- package/src/tools/dispatch-event-text.ts +19 -0
- package/src/tools/dispatch-runner.ts +9 -7
- package/src/tools/dispatch.ts +24 -1
- package/src/tools/monitor.ts +43 -20
- package/src/tools/registry.ts +72 -10
- package/src/tools/result-disposition.ts +706 -0
- package/src/tools/result-shaping.ts +321 -20
- package/src/tools/safe-exec.ts +2 -0
- package/src/tools/verify/authoring.ts +1120 -0
- package/src/tools/verify/catalog.ts +346 -0
- package/src/tools/verify/index.ts +13 -3
- package/src/tools/verify/scripts.ts +135 -37
- package/src/tools/verify/surface.ts +9 -5
- package/src/tools/worker-evidence.ts +54 -12
- package/src/worker/spec-contract.ts +43 -3
- package/dist/chunk-J7CWMCQD.js +0 -255
- package/dist/chunk-T6YILFSB.js +0 -80
- package/dist/chunk-VAKQQHWR.js +0 -434
- package/dist/chunk-VPAYEGVX.js +0 -184
- package/dist/chunk-XBXAASKX.js +0 -18
- package/dist/memory-WFZMGYHX.js +0 -236
- package/src/domains/eval/metrics/chaos-stream.ts +0 -93
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
import { createRequire as __clioCreateRequire } from "node:module"; const require = __clioCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
buildPathIndex,
|
|
4
|
+
callPathsByToolCallId,
|
|
5
|
+
covers,
|
|
6
|
+
hasLegacyCompactionMarker,
|
|
7
|
+
hasThinking,
|
|
8
|
+
isRecord,
|
|
9
|
+
offloadPathOf,
|
|
10
|
+
primaryPathOf,
|
|
11
|
+
protectionCutoffIndex,
|
|
12
|
+
refKey,
|
|
13
|
+
toolResultBodyTokens,
|
|
14
|
+
toolResultPayload,
|
|
15
|
+
toolResultText,
|
|
16
|
+
withoutThinkingBlocks
|
|
17
|
+
} from "./chunk-TZSKNMZG.js";
|
|
18
|
+
import {
|
|
19
|
+
filterEntriesToActivePath
|
|
20
|
+
} from "./chunk-W6GROXXM.js";
|
|
21
|
+
import {
|
|
22
|
+
formatSize
|
|
23
|
+
} from "./chunk-OZNBF4L3.js";
|
|
24
|
+
import {
|
|
25
|
+
ceilChars,
|
|
26
|
+
contentChars,
|
|
27
|
+
estimateAgentMessageTokens
|
|
28
|
+
} from "./chunk-GEYXPTRF.js";
|
|
29
|
+
import {
|
|
30
|
+
init_esm_shims
|
|
31
|
+
} from "./chunk-3R73A4XB.js";
|
|
32
|
+
|
|
33
|
+
// src/domains/session/compaction/tokens.ts
|
|
34
|
+
init_esm_shims();
|
|
35
|
+
function estimateMessage(entry) {
|
|
36
|
+
if (entry.role !== "assistant" || !entry.payload || typeof entry.payload !== "object") {
|
|
37
|
+
return estimateAgentMessageTokens(entry);
|
|
38
|
+
}
|
|
39
|
+
const payload = entry.payload;
|
|
40
|
+
if (!("contextUsageInvalidated" in payload)) return estimateAgentMessageTokens(entry);
|
|
41
|
+
const { contextUsageInvalidated: _stamp, ...promptPayload } = payload;
|
|
42
|
+
return estimateAgentMessageTokens({ ...entry, payload: promptPayload });
|
|
43
|
+
}
|
|
44
|
+
function estimateBashExecution(entry) {
|
|
45
|
+
return ceilChars(entry.command.length + entry.output.length);
|
|
46
|
+
}
|
|
47
|
+
function estimateCustom(entry) {
|
|
48
|
+
if (entry.data === void 0) return 0;
|
|
49
|
+
return ceilChars(contentChars(entry.data));
|
|
50
|
+
}
|
|
51
|
+
function estimateSummary(entry) {
|
|
52
|
+
return ceilChars(entry.summary.length);
|
|
53
|
+
}
|
|
54
|
+
function estimateTokens(entry) {
|
|
55
|
+
switch (entry.kind) {
|
|
56
|
+
case "message":
|
|
57
|
+
return estimateMessage(entry);
|
|
58
|
+
case "bashExecution":
|
|
59
|
+
return estimateBashExecution(entry);
|
|
60
|
+
case "custom":
|
|
61
|
+
return estimateCustom(entry);
|
|
62
|
+
case "skillActivation":
|
|
63
|
+
return ceilChars(JSON.stringify(entry.activation).length);
|
|
64
|
+
case "branchSummary":
|
|
65
|
+
case "compactionSummary":
|
|
66
|
+
return estimateSummary(entry);
|
|
67
|
+
case "modelChange":
|
|
68
|
+
case "thinkingLevelChange":
|
|
69
|
+
case "fileEntry":
|
|
70
|
+
case "sessionInfo":
|
|
71
|
+
case "label":
|
|
72
|
+
case "protectedArtifact":
|
|
73
|
+
case "taskLedger":
|
|
74
|
+
case "decisionLedger":
|
|
75
|
+
case "workerRun":
|
|
76
|
+
// Working-set bookkeeping: refs and markers, never bodies. The
|
|
77
|
+
// projection accounts for marker cost on the projected messages.
|
|
78
|
+
case "contextEviction":
|
|
79
|
+
case "contextRecall":
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function usageTotalTokens(usage) {
|
|
84
|
+
return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
85
|
+
}
|
|
86
|
+
function extractUsage(payload) {
|
|
87
|
+
if (!payload || typeof payload !== "object") return void 0;
|
|
88
|
+
const p = payload;
|
|
89
|
+
if (p.contextUsageInvalidated === true) return void 0;
|
|
90
|
+
if (p.stopReason === "aborted" || p.stopReason === "error") return void 0;
|
|
91
|
+
const u = p.usage;
|
|
92
|
+
if (!u || typeof u !== "object") return void 0;
|
|
93
|
+
const usage = u;
|
|
94
|
+
if (typeof usage.input !== "number" || typeof usage.output !== "number") return void 0;
|
|
95
|
+
return usage;
|
|
96
|
+
}
|
|
97
|
+
function getLastAssistantUsage(entries) {
|
|
98
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
99
|
+
const entry = entries[i];
|
|
100
|
+
if (entry?.kind !== "message" || entry?.role !== "assistant") continue;
|
|
101
|
+
const usage = extractUsage(entry.payload);
|
|
102
|
+
if (usage) return usage;
|
|
103
|
+
}
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
function findLastAssistantUsageIndex(entries) {
|
|
107
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
108
|
+
const entry = entries[i];
|
|
109
|
+
if (entry?.kind !== "message" || entry?.role !== "assistant") continue;
|
|
110
|
+
if (extractUsage(entry.payload)) return i;
|
|
111
|
+
}
|
|
112
|
+
return -1;
|
|
113
|
+
}
|
|
114
|
+
function calculateContextTokens(entries, lastUsage) {
|
|
115
|
+
const usage = lastUsage ?? getLastAssistantUsage(entries);
|
|
116
|
+
if (usage) {
|
|
117
|
+
const anchorTokens = usageTotalTokens(usage);
|
|
118
|
+
const anchorIndex = findLastAssistantUsageIndex(entries);
|
|
119
|
+
let trailing = 0;
|
|
120
|
+
for (let i = anchorIndex + 1; i < entries.length; i++) {
|
|
121
|
+
const entry = entries[i];
|
|
122
|
+
if (entry) trailing += estimateTokens(entry);
|
|
123
|
+
}
|
|
124
|
+
return anchorTokens + trailing;
|
|
125
|
+
}
|
|
126
|
+
let total = 0;
|
|
127
|
+
for (const entry of entries) total += estimateTokens(entry);
|
|
128
|
+
return total;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/domains/session/compaction/defaults.ts
|
|
132
|
+
init_esm_shims();
|
|
133
|
+
var DEFAULT_RESERVE_TOKENS = 16384;
|
|
134
|
+
var DEFAULT_KEEP_RECENT_TOKENS = 2e4;
|
|
135
|
+
|
|
136
|
+
// src/domains/context/working-set/policies/index.ts
|
|
137
|
+
init_esm_shims();
|
|
138
|
+
|
|
139
|
+
// src/domains/context/working-set/policies/age-horizon.ts
|
|
140
|
+
init_esm_shims();
|
|
141
|
+
var ageHorizonPolicy = {
|
|
142
|
+
id: "age-horizon",
|
|
143
|
+
select(input) {
|
|
144
|
+
const { entries, view, settings } = input;
|
|
145
|
+
const cutoff = protectionCutoffIndex(entries, settings.protectLastTurns);
|
|
146
|
+
const candidates = [];
|
|
147
|
+
for (let i = cutoff - 1; i >= 0; i -= 1) {
|
|
148
|
+
const entry = entries[i];
|
|
149
|
+
if (entry === void 0 || entry.kind !== "message") continue;
|
|
150
|
+
if (view.evicted.has(entry.turnId)) continue;
|
|
151
|
+
if (entry.role === "tool_result") {
|
|
152
|
+
if (hasLegacyCompactionMarker(entry.payload)) continue;
|
|
153
|
+
if (toolResultBodyTokens(entry.payload) < settings.minEvictableTokens) continue;
|
|
154
|
+
candidates.push({ ref: { entry: entry.turnId }, reason: "age_horizon" });
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (entry.role === "assistant" && hasThinking(entry.payload)) {
|
|
158
|
+
candidates.push({ ref: { entry: entry.turnId }, reason: "thinking_turn_closed" });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return candidates;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// src/domains/context/working-set/policies/structural.ts
|
|
166
|
+
init_esm_shims();
|
|
167
|
+
|
|
168
|
+
// src/domains/context/working-set/engine.ts
|
|
169
|
+
init_esm_shims();
|
|
170
|
+
|
|
171
|
+
// src/domains/context/working-set/marker.ts
|
|
172
|
+
init_esm_shims();
|
|
173
|
+
var PREVIEW_LIMIT = 120;
|
|
174
|
+
function lineCount(text) {
|
|
175
|
+
if (text.length === 0) return 0;
|
|
176
|
+
let count = 1;
|
|
177
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
178
|
+
const code = text.charCodeAt(index);
|
|
179
|
+
if (code === 10 || code === 13 && text.charCodeAt(index + 1) !== 10) count += 1;
|
|
180
|
+
}
|
|
181
|
+
return count;
|
|
182
|
+
}
|
|
183
|
+
function preview(text) {
|
|
184
|
+
let out = "";
|
|
185
|
+
let pendingSpace = false;
|
|
186
|
+
for (const char of text) {
|
|
187
|
+
if (/\s/.test(char)) {
|
|
188
|
+
pendingSpace = out.length > 0;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (pendingSpace) out += " ";
|
|
192
|
+
pendingSpace = false;
|
|
193
|
+
out += char;
|
|
194
|
+
if (out.length >= PREVIEW_LIMIT) break;
|
|
195
|
+
}
|
|
196
|
+
return out.slice(0, PREVIEW_LIMIT).replace(/"/g, '\\"');
|
|
197
|
+
}
|
|
198
|
+
function firstLine(text) {
|
|
199
|
+
const line = /[^\r\n]*\S[^\r\n]*/.exec(text)?.[0] ?? "";
|
|
200
|
+
return line.trim().slice(0, PREVIEW_LIMIT).replace(/"/g, '\\"');
|
|
201
|
+
}
|
|
202
|
+
function renderMarker(input) {
|
|
203
|
+
const ref = input.ref.entry;
|
|
204
|
+
const fields = [`ref=${ref}`, `reason=${input.reason}`];
|
|
205
|
+
if (input.by !== void 0) fields.push(`by=${input.by}`);
|
|
206
|
+
fields.push(`tool=${input.toolName}`);
|
|
207
|
+
if (input.path !== void 0) fields.push(`path=${input.path}`);
|
|
208
|
+
fields.push(`size=${lineCount(input.text)} lines/${formatSize(Buffer.byteLength(input.text, "utf8"))}`);
|
|
209
|
+
if (input.offloadPath !== void 0) fields.push(`offload=${input.offloadPath}`);
|
|
210
|
+
fields.push(`recall=context(scope="recall", ref="${ref}")`);
|
|
211
|
+
if (input.offloadPath === void 0) {
|
|
212
|
+
const failed = input.reason === "failure_resolved";
|
|
213
|
+
const tail = failed ? firstLine(input.text) : preview(input.text);
|
|
214
|
+
if (tail.length > 0) fields.push(`${failed ? "first_line" : "preview"}="${tail}"`);
|
|
215
|
+
}
|
|
216
|
+
return `[evicted ${fields.join(" ")}]`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/domains/context/working-set/project.ts
|
|
220
|
+
init_esm_shims();
|
|
221
|
+
function projectToolResult(entry, state) {
|
|
222
|
+
const next = { ...entry };
|
|
223
|
+
const { obj, result } = toolResultPayload(next.payload);
|
|
224
|
+
const details = isRecord(result) && isRecord(result.details) ? result.details : {};
|
|
225
|
+
next.payload = {
|
|
226
|
+
...obj,
|
|
227
|
+
result: {
|
|
228
|
+
content: [{ type: "text", text: state.marker }],
|
|
229
|
+
details: {
|
|
230
|
+
...details,
|
|
231
|
+
workingSet: { evicted: true, reason: state.reason, ref: entry.turnId }
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
output: void 0,
|
|
235
|
+
out: void 0,
|
|
236
|
+
content: void 0
|
|
237
|
+
};
|
|
238
|
+
return next;
|
|
239
|
+
}
|
|
240
|
+
function projectAssistant(entry) {
|
|
241
|
+
const obj = isRecord(entry.payload) ? entry.payload : null;
|
|
242
|
+
if (obj === null || !hasThinking(obj)) return entry;
|
|
243
|
+
const content = withoutThinkingBlocks(obj.content);
|
|
244
|
+
if (!hasVisibleContent(obj, content)) return entry;
|
|
245
|
+
const next = { ...entry };
|
|
246
|
+
next.payload = {
|
|
247
|
+
...obj,
|
|
248
|
+
...content !== void 0 ? { content } : {},
|
|
249
|
+
thinking: void 0
|
|
250
|
+
};
|
|
251
|
+
return next;
|
|
252
|
+
}
|
|
253
|
+
function hasVisibleContent(obj, content) {
|
|
254
|
+
if (typeof obj.text === "string" && obj.text.length > 0) return true;
|
|
255
|
+
return content !== void 0 && content.length > 0;
|
|
256
|
+
}
|
|
257
|
+
function invalidateUsage(entry) {
|
|
258
|
+
if (entry.kind !== "message" || entry.role !== "assistant") return entry;
|
|
259
|
+
const obj = isRecord(entry.payload) ? entry.payload : null;
|
|
260
|
+
if (obj === null || obj.contextUsageInvalidated === true) return entry;
|
|
261
|
+
const next = { ...entry };
|
|
262
|
+
next.payload = { ...obj, contextUsageInvalidated: true };
|
|
263
|
+
return next;
|
|
264
|
+
}
|
|
265
|
+
function eventIndex(entries, lastEvictionTurnId) {
|
|
266
|
+
if (lastEvictionTurnId === null) return entries.length;
|
|
267
|
+
const index = entries.findIndex((entry) => entry.turnId === lastEvictionTurnId);
|
|
268
|
+
return index < 0 ? entries.length : index;
|
|
269
|
+
}
|
|
270
|
+
function projectWorkingSet(entries, view) {
|
|
271
|
+
if (view.evicted.size === 0 && view.evictionEvents === 0) return [...entries];
|
|
272
|
+
const cutoff = view.evictionEvents > 0 ? eventIndex(entries, view.lastEvictionTurnId) : -1;
|
|
273
|
+
const out = [];
|
|
274
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
275
|
+
const entry = entries[index];
|
|
276
|
+
if (entry === void 0) continue;
|
|
277
|
+
let next = entry;
|
|
278
|
+
if (entry.kind === "message") {
|
|
279
|
+
const state = view.evicted.get(entry.turnId);
|
|
280
|
+
if (state !== void 0) {
|
|
281
|
+
if (entry.role === "tool_result") next = projectToolResult(entry, state);
|
|
282
|
+
else if (entry.role === "assistant") next = projectAssistant(entry);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (index < cutoff) next = invalidateUsage(next);
|
|
286
|
+
out.push(next);
|
|
287
|
+
}
|
|
288
|
+
return out;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// src/domains/context/working-set/engine.ts
|
|
292
|
+
var NO_CALL_PATHS = /* @__PURE__ */ new Map();
|
|
293
|
+
var PENDING_EVENT_TURN_ID = "";
|
|
294
|
+
function markerFor(entry, candidate, callPaths) {
|
|
295
|
+
if (entry.kind !== "message") return null;
|
|
296
|
+
if (entry.role === "assistant") return hasThinking(entry.payload) ? "" : null;
|
|
297
|
+
if (entry.role !== "tool_result") return null;
|
|
298
|
+
const payload = toolResultPayload(entry.payload);
|
|
299
|
+
const toolCallId = typeof payload.obj.toolCallId === "string" ? payload.obj.toolCallId : void 0;
|
|
300
|
+
return renderMarker({
|
|
301
|
+
ref: candidate.ref,
|
|
302
|
+
reason: candidate.reason,
|
|
303
|
+
by: candidate.by,
|
|
304
|
+
toolName: payload.toolName,
|
|
305
|
+
text: toolResultText(payload.result),
|
|
306
|
+
offloadPath: offloadPathOf(payload),
|
|
307
|
+
path: primaryPathOf(payload) ?? (toolCallId === void 0 ? void 0 : callPaths.get(toolCallId))
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
function pendingState(candidate, marker, policyId) {
|
|
311
|
+
return {
|
|
312
|
+
reason: candidate.reason,
|
|
313
|
+
marker,
|
|
314
|
+
...candidate.by === void 0 ? {} : { by: candidate.by },
|
|
315
|
+
tokensFreed: 0,
|
|
316
|
+
evictedAtTurnId: PENDING_EVENT_TURN_ID,
|
|
317
|
+
policyId
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function soloView(key, state) {
|
|
321
|
+
return {
|
|
322
|
+
evicted: /* @__PURE__ */ new Map([[key, state]]),
|
|
323
|
+
// Zero events: pricing one body must not also stamp usage invalidation,
|
|
324
|
+
// which would put the cost of a different mechanism in this item's total.
|
|
325
|
+
evictionEvents: 0,
|
|
326
|
+
itemsEvicted: 1,
|
|
327
|
+
recalls: 0,
|
|
328
|
+
lastPolicyId: null,
|
|
329
|
+
lastEvictionTurnId: null
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function viewWithItems(view, items, policyId) {
|
|
333
|
+
const evicted = new Map(view.evicted);
|
|
334
|
+
for (const item of items) {
|
|
335
|
+
evicted.set(refKey(item.ref), {
|
|
336
|
+
reason: item.reason,
|
|
337
|
+
marker: item.marker,
|
|
338
|
+
...item.by === void 0 ? {} : { by: item.by },
|
|
339
|
+
tokensFreed: item.tokensFreed,
|
|
340
|
+
evictedAtTurnId: PENDING_EVENT_TURN_ID,
|
|
341
|
+
policyId
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return { ...view, evicted, itemsEvicted: view.itemsEvicted + items.length };
|
|
345
|
+
}
|
|
346
|
+
function sumTokens(entries, estimate) {
|
|
347
|
+
let total = 0;
|
|
348
|
+
for (const entry of entries) total += estimate(entry);
|
|
349
|
+
return total;
|
|
350
|
+
}
|
|
351
|
+
function tokensFreedByEviction(estimateTokens2, entry, candidate, callPaths = NO_CALL_PATHS) {
|
|
352
|
+
const marker = markerFor(entry, candidate, callPaths);
|
|
353
|
+
if (marker === null) return 0;
|
|
354
|
+
const key = refKey(candidate.ref);
|
|
355
|
+
const projected = projectWorkingSet([entry], soloView(key, pendingState(candidate, marker, "")))[0] ?? entry;
|
|
356
|
+
return Math.max(0, estimateTokens2(entry) - estimateTokens2(projected));
|
|
357
|
+
}
|
|
358
|
+
function planEviction(policy, input) {
|
|
359
|
+
const candidates = policy.select(input);
|
|
360
|
+
if (candidates.length === 0) return null;
|
|
361
|
+
const byTurnId = /* @__PURE__ */ new Map();
|
|
362
|
+
for (const entry of input.entries) byTurnId.set(entry.turnId, entry);
|
|
363
|
+
const callPaths = callPathsByToolCallId(input.entries);
|
|
364
|
+
const items = [];
|
|
365
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
366
|
+
for (const candidate of candidates) {
|
|
367
|
+
const key = refKey(candidate.ref);
|
|
368
|
+
if (input.view.evicted.has(key) || claimed.has(key)) continue;
|
|
369
|
+
const entry = byTurnId.get(key);
|
|
370
|
+
if (entry === void 0) continue;
|
|
371
|
+
const marker = markerFor(entry, candidate, callPaths);
|
|
372
|
+
if (marker === null) continue;
|
|
373
|
+
const tokensFreed = tokensFreedByEviction(input.estimateTokens, entry, candidate, callPaths);
|
|
374
|
+
if (tokensFreed <= 0) continue;
|
|
375
|
+
claimed.add(key);
|
|
376
|
+
items.push({
|
|
377
|
+
ref: candidate.ref,
|
|
378
|
+
reason: candidate.reason,
|
|
379
|
+
tokensFreed,
|
|
380
|
+
marker,
|
|
381
|
+
...candidate.by === void 0 ? {} : { by: candidate.by }
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
if (items.length === 0) return null;
|
|
385
|
+
return {
|
|
386
|
+
policyId: policy.id,
|
|
387
|
+
items,
|
|
388
|
+
tokensBefore: sumTokens(projectWorkingSet(input.entries, input.view), input.estimateTokens),
|
|
389
|
+
tokensAfter: sumTokens(
|
|
390
|
+
projectWorkingSet(input.entries, viewWithItems(input.view, items, policy.id)),
|
|
391
|
+
input.estimateTokens
|
|
392
|
+
)
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function buildEvictionFields(plan, meta) {
|
|
396
|
+
return {
|
|
397
|
+
kind: "contextEviction",
|
|
398
|
+
policyId: plan.policyId,
|
|
399
|
+
trigger: meta.trigger,
|
|
400
|
+
evicted: plan.items,
|
|
401
|
+
tokensBefore: plan.tokensBefore,
|
|
402
|
+
tokensAfter: plan.tokensAfter,
|
|
403
|
+
pressureBefore: meta.pressureBefore,
|
|
404
|
+
snapshotIdBefore: meta.snapshotIdBefore
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/domains/context/working-set/protect.ts
|
|
409
|
+
init_esm_shims();
|
|
410
|
+
var PATH_IDENTIFIED_OPS = /* @__PURE__ */ new Set(["read", "grep", "find"]);
|
|
411
|
+
function isBlockedResult(payload) {
|
|
412
|
+
if (!isRecord(payload)) return false;
|
|
413
|
+
return payload.outcome === "blocked" || typeof payload.blockReason === "string";
|
|
414
|
+
}
|
|
415
|
+
function isErrorResult(payload) {
|
|
416
|
+
if (!isRecord(payload)) return false;
|
|
417
|
+
return payload.isError === true || payload.error === true;
|
|
418
|
+
}
|
|
419
|
+
function findLaterSuccess(observation, index) {
|
|
420
|
+
for (const candidate of index.observations) {
|
|
421
|
+
if (candidate.entryIndex <= observation.entryIndex || candidate.isError || candidate.isBlocked) continue;
|
|
422
|
+
if (candidate.toolName === observation.toolName && observation.argsKey.length > 0) {
|
|
423
|
+
if (candidate.argsKey === observation.argsKey) return candidate;
|
|
424
|
+
}
|
|
425
|
+
if (PATH_IDENTIFIED_OPS.has(observation.op) && candidate.op === observation.op && observation.path.length > 0 && candidate.path === observation.path) {
|
|
426
|
+
return candidate;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
function isActiveTurnMutation(observation, index) {
|
|
432
|
+
if (observation.op !== "write" && observation.op !== "edit") return false;
|
|
433
|
+
return observation.turnIndex >= index.turnCount;
|
|
434
|
+
}
|
|
435
|
+
function isProtected(entry, ctx) {
|
|
436
|
+
if (entry.kind !== "message") return true;
|
|
437
|
+
if (entry.role !== "tool_result" && entry.role !== "assistant") return true;
|
|
438
|
+
if (ctx.entryIndex >= ctx.cutoffIndex) return true;
|
|
439
|
+
if (entry.role === "assistant") return false;
|
|
440
|
+
if (toolResultBodyTokens(entry.payload) < ctx.input.settings.minEvictableTokens) return true;
|
|
441
|
+
if (hasLegacyCompactionMarker(entry.payload)) return true;
|
|
442
|
+
if (isBlockedResult(entry.payload)) return true;
|
|
443
|
+
const observation = ctx.index.byRef.get(entry.turnId);
|
|
444
|
+
if (observation === void 0) return isErrorResult(entry.payload);
|
|
445
|
+
if (isActiveTurnMutation(observation, ctx.index)) return true;
|
|
446
|
+
if (observation.isError && findLaterSuccess(observation, ctx.index) === null) return true;
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// src/domains/context/working-set/policies/structural.ts
|
|
451
|
+
var READ_CLASS = /* @__PURE__ */ new Set(["read", "grep", "find", "ls", "code_nav"]);
|
|
452
|
+
var MUTATING = /* @__PURE__ */ new Set(["write", "edit"]);
|
|
453
|
+
function firstMutationAfter(observation, index) {
|
|
454
|
+
for (const other of index.byPath.get(observation.path) ?? []) {
|
|
455
|
+
if (other.entryIndex > observation.entryIndex && MUTATING.has(other.op) && !other.isError) return other;
|
|
456
|
+
}
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
function lastCoveringRead(observation, index) {
|
|
460
|
+
let found = null;
|
|
461
|
+
for (const other of index.byPath.get(observation.path) ?? []) {
|
|
462
|
+
if (other.entryIndex <= observation.entryIndex || other.op !== "read" || other.isError) continue;
|
|
463
|
+
if (covers(other.range, observation.range)) found = other;
|
|
464
|
+
}
|
|
465
|
+
return found;
|
|
466
|
+
}
|
|
467
|
+
function isListingConsumed(observation, index) {
|
|
468
|
+
if (observation.surfaced.length === 0) return false;
|
|
469
|
+
for (const path of observation.surfaced) {
|
|
470
|
+
const readLater = (index.byPath.get(path) ?? []).some(
|
|
471
|
+
(other) => other.op === "read" && !other.isError && other.entryIndex > observation.entryIndex
|
|
472
|
+
);
|
|
473
|
+
if (!readLater) return false;
|
|
474
|
+
}
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
var structuralPolicy = {
|
|
478
|
+
id: "structural-v1",
|
|
479
|
+
select(input) {
|
|
480
|
+
const { entries, view, settings, pressure, estimateTokens: estimateTokens2 } = input;
|
|
481
|
+
const index = buildPathIndex(entries, { cwd: input.cwd });
|
|
482
|
+
const callPaths = callPathsByToolCallId(entries);
|
|
483
|
+
const cutoffIndex = protectionCutoffIndex(entries, settings.protectLastTurns);
|
|
484
|
+
const candidates = [];
|
|
485
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
486
|
+
let freed = 0;
|
|
487
|
+
const entryIndexOf = /* @__PURE__ */ new Map();
|
|
488
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
489
|
+
const entry = entries[i];
|
|
490
|
+
if (entry !== void 0) entryIndexOf.set(entry.turnId, i);
|
|
491
|
+
}
|
|
492
|
+
const emit = (turnId, reason, by) => {
|
|
493
|
+
if (claimed.has(turnId) || view.evicted.has(turnId)) return false;
|
|
494
|
+
const entryIndex = entryIndexOf.get(turnId);
|
|
495
|
+
if (entryIndex === void 0) return false;
|
|
496
|
+
const entry = entries[entryIndex];
|
|
497
|
+
if (entry === void 0) return false;
|
|
498
|
+
if (isProtected(entry, { entryIndex, cutoffIndex, input, index })) return false;
|
|
499
|
+
const candidate = { ref: { entry: turnId }, reason, ...by === void 0 ? {} : { by } };
|
|
500
|
+
claimed.add(turnId);
|
|
501
|
+
candidates.push(candidate);
|
|
502
|
+
freed += tokensFreedByEviction(estimateTokens2, entry, candidate, callPaths);
|
|
503
|
+
return true;
|
|
504
|
+
};
|
|
505
|
+
const newestFirst = [...index.observations].reverse();
|
|
506
|
+
for (const observation of newestFirst) {
|
|
507
|
+
if (!READ_CLASS.has(observation.op) || observation.path.length === 0) continue;
|
|
508
|
+
const mutation = firstMutationAfter(observation, index);
|
|
509
|
+
if (mutation !== null) emit(observation.ref.entry, "stale_after_mutation", mutation.ref.entry);
|
|
510
|
+
}
|
|
511
|
+
for (const observation of newestFirst) {
|
|
512
|
+
if (observation.op !== "read" || observation.path.length === 0) continue;
|
|
513
|
+
const superseding = lastCoveringRead(observation, index);
|
|
514
|
+
if (superseding !== null) emit(observation.ref.entry, "superseded_read", superseding.ref.entry);
|
|
515
|
+
}
|
|
516
|
+
for (const observation of newestFirst) {
|
|
517
|
+
if (!observation.isError) continue;
|
|
518
|
+
const success = findLaterSuccess(observation, index);
|
|
519
|
+
if (success !== null) emit(observation.ref.entry, "failure_resolved", success.ref.entry);
|
|
520
|
+
}
|
|
521
|
+
for (const observation of newestFirst) {
|
|
522
|
+
if (isListingConsumed(observation, index)) emit(observation.ref.entry, "listing_consumed");
|
|
523
|
+
}
|
|
524
|
+
for (let i = cutoffIndex - 1; i >= 0; i -= 1) {
|
|
525
|
+
const entry = entries[i];
|
|
526
|
+
if (entry?.kind !== "message" || entry.role !== "assistant") continue;
|
|
527
|
+
if (hasThinking(entry.payload)) emit(entry.turnId, "thinking_turn_closed");
|
|
528
|
+
}
|
|
529
|
+
const window = pressure.contextWindow;
|
|
530
|
+
if (window <= 0) return candidates;
|
|
531
|
+
let projected = pressure.tokens - freed;
|
|
532
|
+
if (projected <= pressure.threshold * window) return candidates;
|
|
533
|
+
const targetTokens = pressure.target * window;
|
|
534
|
+
for (let i = cutoffIndex - 1; i >= 0 && projected > targetTokens; i -= 1) {
|
|
535
|
+
const entry = entries[i];
|
|
536
|
+
if (entry?.kind !== "message" || entry.role !== "tool_result") continue;
|
|
537
|
+
const before = freed;
|
|
538
|
+
if (emit(entry.turnId, "age_horizon")) projected -= freed - before;
|
|
539
|
+
}
|
|
540
|
+
return candidates;
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
// src/domains/context/working-set/policies/index.ts
|
|
545
|
+
function resolveWorkingSetPolicy(id) {
|
|
546
|
+
if (id === "age-horizon") return ageHorizonPolicy;
|
|
547
|
+
return structuralPolicy;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// src/domains/session/compaction/cut-point.ts
|
|
551
|
+
init_esm_shims();
|
|
552
|
+
function findTurnStartIndex(entries, entryIndex, startIndex = 0) {
|
|
553
|
+
for (let i = entryIndex; i >= startIndex; i--) {
|
|
554
|
+
const entry = entries[i];
|
|
555
|
+
if (!entry) continue;
|
|
556
|
+
if (entry.kind === "branchSummary") return i;
|
|
557
|
+
if (entry.kind === "bashExecution") return i;
|
|
558
|
+
if (entry.kind === "message" && entry.role === "user") return i;
|
|
559
|
+
}
|
|
560
|
+
return -1;
|
|
561
|
+
}
|
|
562
|
+
function isValidCutPoint(entry) {
|
|
563
|
+
switch (entry.kind) {
|
|
564
|
+
case "message":
|
|
565
|
+
return entry.role !== "tool_result";
|
|
566
|
+
case "bashExecution":
|
|
567
|
+
case "custom":
|
|
568
|
+
case "skillActivation":
|
|
569
|
+
case "branchSummary":
|
|
570
|
+
case "compactionSummary":
|
|
571
|
+
return true;
|
|
572
|
+
case "modelChange":
|
|
573
|
+
case "thinkingLevelChange":
|
|
574
|
+
case "fileEntry":
|
|
575
|
+
case "sessionInfo":
|
|
576
|
+
case "label":
|
|
577
|
+
case "protectedArtifact":
|
|
578
|
+
case "taskLedger":
|
|
579
|
+
case "decisionLedger":
|
|
580
|
+
case "workerRun":
|
|
581
|
+
case "contextEviction":
|
|
582
|
+
case "contextRecall":
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
function findValidCutPoints(entries, startIndex, endIndex) {
|
|
587
|
+
const cuts = [];
|
|
588
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
589
|
+
const entry = entries[i];
|
|
590
|
+
if (!entry) continue;
|
|
591
|
+
if (isValidCutPoint(entry)) cuts.push(i);
|
|
592
|
+
}
|
|
593
|
+
return cuts;
|
|
594
|
+
}
|
|
595
|
+
function findCutPoint(entries, keepRecentTokens, opts = {}) {
|
|
596
|
+
const startIndex = opts.startIndex ?? 0;
|
|
597
|
+
const endIndex = opts.endIndex ?? entries.length;
|
|
598
|
+
const cutPoints = findValidCutPoints(entries, startIndex, endIndex);
|
|
599
|
+
if (cutPoints.length === 0) {
|
|
600
|
+
return { firstKeptEntryIndex: startIndex, turnStartIndex: -1, isSplitTurn: false };
|
|
601
|
+
}
|
|
602
|
+
let accumulated = 0;
|
|
603
|
+
let cutIndex = -1;
|
|
604
|
+
for (let i = endIndex - 1; i >= startIndex; i--) {
|
|
605
|
+
const entry = entries[i];
|
|
606
|
+
if (!entry) continue;
|
|
607
|
+
accumulated += estimateTokens(entry);
|
|
608
|
+
if (accumulated >= keepRecentTokens) {
|
|
609
|
+
for (const candidate of cutPoints) {
|
|
610
|
+
if (candidate >= i) {
|
|
611
|
+
cutIndex = candidate;
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
break;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (cutIndex === -1) {
|
|
619
|
+
const lastTurnStart = findTurnStartIndex(entries, endIndex - 1, startIndex);
|
|
620
|
+
cutIndex = lastTurnStart !== -1 ? lastTurnStart : cutPoints[0] ?? startIndex;
|
|
621
|
+
}
|
|
622
|
+
while (cutIndex > startIndex) {
|
|
623
|
+
const prev = entries[cutIndex - 1];
|
|
624
|
+
if (!prev) break;
|
|
625
|
+
if (prev.kind === "compactionSummary") break;
|
|
626
|
+
if (prev.kind === "message" || prev.kind === "bashExecution" || prev.kind === "custom" || prev.kind === "skillActivation" || prev.kind === "branchSummary") {
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
cutIndex--;
|
|
630
|
+
}
|
|
631
|
+
const cutEntry = entries[cutIndex];
|
|
632
|
+
const cutIsUserTurn = !!cutEntry && cutEntry.kind === "message" && cutEntry.role === "user";
|
|
633
|
+
const turnStartIndex = cutIsUserTurn ? -1 : findTurnStartIndex(entries, cutIndex, startIndex);
|
|
634
|
+
return {
|
|
635
|
+
firstKeptEntryIndex: cutIndex,
|
|
636
|
+
turnStartIndex,
|
|
637
|
+
isSplitTurn: !cutIsUserTurn && turnStartIndex !== -1
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// src/domains/context/working-set/visible.ts
|
|
642
|
+
init_esm_shims();
|
|
643
|
+
function compactionCut(entries) {
|
|
644
|
+
let compactionIndex = -1;
|
|
645
|
+
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
646
|
+
if (entries[i]?.kind === "compactionSummary") {
|
|
647
|
+
compactionIndex = i;
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
const compaction = entries[compactionIndex];
|
|
652
|
+
if (compaction?.kind !== "compactionSummary") return { compactionIndex: -1, visible: [...entries] };
|
|
653
|
+
const firstKeptIndex = compaction.firstKeptTurnId.length > 0 ? entries.findIndex((entry) => entry.turnId === compaction.firstKeptTurnId) : -1;
|
|
654
|
+
const kept = firstKeptIndex >= 0 && firstKeptIndex < compactionIndex ? entries.slice(firstKeptIndex, compactionIndex) : [];
|
|
655
|
+
return { compactionIndex, visible: [...kept, ...entries.slice(compactionIndex + 1)] };
|
|
656
|
+
}
|
|
657
|
+
function selectVisibleEntries(entries, activeLeafTurnId) {
|
|
658
|
+
return compactionCut(filterEntriesToActivePath(entries, activeLeafTurnId)).visible;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
export {
|
|
662
|
+
estimateTokens,
|
|
663
|
+
getLastAssistantUsage,
|
|
664
|
+
calculateContextTokens,
|
|
665
|
+
findCutPoint,
|
|
666
|
+
DEFAULT_RESERVE_TOKENS,
|
|
667
|
+
DEFAULT_KEEP_RECENT_TOKENS,
|
|
668
|
+
projectWorkingSet,
|
|
669
|
+
tokensFreedByEviction,
|
|
670
|
+
planEviction,
|
|
671
|
+
buildEvictionFields,
|
|
672
|
+
isProtected,
|
|
673
|
+
resolveWorkingSetPolicy,
|
|
674
|
+
compactionCut,
|
|
675
|
+
selectVisibleEntries
|
|
676
|
+
};
|
|
677
|
+
//# sourceMappingURL=chunk-WHJYKASB.js.map
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
readSettings,
|
|
4
4
|
settingsPath,
|
|
5
5
|
updateSettings
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AD2SYQYC.js";
|
|
7
7
|
import {
|
|
8
8
|
DEFAULT_SETTINGS
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-4OC57DA6.js";
|
|
10
10
|
import {
|
|
11
11
|
require_dist
|
|
12
12
|
} from "./chunk-APJ265NV.js";
|
|
@@ -552,4 +552,4 @@ export {
|
|
|
552
552
|
importShareArchive,
|
|
553
553
|
ShareDomainModule
|
|
554
554
|
};
|
|
555
|
-
//# sourceMappingURL=chunk-
|
|
555
|
+
//# sourceMappingURL=chunk-WR67VIZY.js.map
|