dsh-context-compression-improved 0.12.0 → 0.13.1
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/.agents/plans/improve/checklist.md +32 -0
- package/.agents/plans/improve/findings.md +102 -0
- package/.agents/plans/improve/spec.md +53 -0
- package/.agents/plans/improve/tasks.md +70 -0
- package/.gitattributes +2 -0
- package/.githooks/pre-push +37 -0
- package/.github/workflows/ci.yml +47 -0
- package/CHANGELOG.de.md +580 -0
- package/CHANGELOG.es.md +588 -0
- package/CHANGELOG.fr.md +576 -0
- package/CHANGELOG.it.md +577 -0
- package/CHANGELOG.ja.md +261 -0
- package/CHANGELOG.ko.md +254 -0
- package/CHANGELOG.md +582 -0
- package/CHANGELOG.pt.md +167 -0
- package/CHANGELOG.ru.md +554 -0
- package/CHANGELOG.zh.md +247 -0
- package/CONTRIBUTING.md +22 -0
- package/README.de.md +96 -0
- package/README.es.md +96 -0
- package/README.fr.md +96 -0
- package/README.it.md +96 -0
- package/README.ja.md +102 -0
- package/README.ko.md +102 -0
- package/README.md +128 -22
- package/README.pt.md +96 -0
- package/README.ru.md +96 -0
- package/README.zh.md +114 -24
- package/SECURITY.md +18 -0
- package/THIRD_PARTY_NOTICES.md +7 -25
- package/assets/board.png +0 -0
- package/assets/context.png +0 -0
- package/assets/dshfind-card.svg +33 -0
- package/docs/assets/context-compression-selector-profiles.jpg +0 -0
- package/docs/assets/context-compression-selector-settings.png +0 -0
- package/docs/compat-0.1.5-report.md +77 -0
- package/docs/installation.de.md +104 -0
- package/docs/installation.es.md +104 -0
- package/docs/installation.fr.md +104 -0
- package/docs/installation.it.md +104 -0
- package/docs/installation.ja.md +78 -0
- package/docs/installation.ko.md +78 -0
- package/docs/installation.md +103 -0
- package/docs/installation.ru.md +104 -0
- package/docs/installation.zh.md +100 -0
- package/docs/repair-log.md +657 -0
- package/docs/shallow-teaching-preset-template.md +46 -0
- package/eslint.config.js +30 -0
- package/package.json +112 -127
- package/packages/selector/LICENSE +21 -0
- package/packages/selector/README.md +26 -0
- package/packages/selector/README.zh.md +24 -0
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -0
- package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -0
- package/packages/selector/docs/native-tool-result-selector-spec.md +34 -0
- package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -0
- package/{dsh.plugin.json → packages/selector/dsh.plugin.json} +1 -1
- package/{lib → packages/selector/lib}/client.js +18 -10
- package/{lib → packages/selector/lib}/profiles.d.ts +6 -0
- package/packages/selector/lib/style.css +350 -0
- package/packages/selector/package.json +180 -0
- package/packages/selector/screenshots.json +3 -0
- package/packages/selector/src/client/CompressionProfileControls.tsx +352 -0
- package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -0
- package/packages/selector/src/client/CompressionProfileSelector.tsx +89 -0
- package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -0
- package/packages/selector/src/client/EstimatorControls.tsx +277 -0
- package/packages/selector/src/client/bridge-scope.ts +125 -0
- package/packages/selector/src/client/decode.ts +68 -0
- package/packages/selector/src/client/fab-pos.ts +71 -0
- package/packages/selector/src/client/guide-steps.ts +50 -0
- package/packages/selector/src/client/guide.tsx +368 -0
- package/packages/selector/src/client/index.ts +456 -0
- package/packages/selector/src/client/locales/de.ts +167 -0
- package/packages/selector/src/client/locales/es.ts +167 -0
- package/packages/selector/src/client/locales/fr.ts +167 -0
- package/packages/selector/src/client/locales/it.ts +167 -0
- package/packages/selector/src/client/locales/ja.ts +167 -0
- package/packages/selector/src/client/locales/ko.ts +167 -0
- package/packages/selector/src/client/locales/pt.ts +167 -0
- package/packages/selector/src/client/locales/ru.ts +167 -0
- package/packages/selector/src/client/locales.ts +334 -0
- package/packages/selector/src/client/monitor-fab.ts +445 -0
- package/packages/selector/src/client/preset-options.ts +88 -0
- package/packages/selector/src/client/savings-card.tsx +269 -0
- package/packages/selector/src/client/scope-face.ts +24 -0
- package/packages/selector/src/client/settings-section.tsx +171 -0
- package/packages/selector/src/compat/host-generation.ts +96 -0
- package/packages/selector/src/compat/llm-messages.ts +50 -0
- package/packages/selector/src/compat/settings-lease.ts +108 -0
- package/packages/selector/src/compat/tool-result.ts +91 -0
- package/packages/selector/src/css-modules.d.ts +6 -0
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -0
- package/packages/selector/src/estimator-catalog.ts +104 -0
- package/packages/selector/src/index.ts +909 -0
- package/packages/selector/src/invariant.ts +113 -0
- package/packages/selector/src/preset-overlay.ts +749 -0
- package/packages/selector/src/profiles.ts +560 -0
- package/packages/selector/src/pruner/content.ts +199 -0
- package/packages/selector/src/pruner/session.ts +97 -0
- package/packages/selector/src/pruner/state.ts +61 -0
- package/packages/selector/src/pruner/tuning.ts +23 -0
- package/packages/selector/src/pruner/types.ts +78 -0
- package/packages/selector/src/pruner.ts +3222 -0
- package/packages/selector/src/runtime/adaptive-cost.ts +205 -0
- package/packages/selector/src/runtime/audit.ts +321 -0
- package/packages/selector/src/runtime/config.ts +887 -0
- package/packages/selector/src/runtime/custom-policy.ts +300 -0
- package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -0
- package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -0
- package/packages/selector/src/runtime/display-prefs.ts +98 -0
- package/packages/selector/src/runtime/fold-router.ts +143 -0
- package/packages/selector/src/runtime/injected-kinds.ts +62 -0
- package/packages/selector/src/runtime/measurement.ts +444 -0
- package/packages/selector/src/runtime/monitor.ts +341 -0
- package/packages/selector/src/runtime/netgain.ts +48 -0
- package/packages/selector/src/runtime/panel-command.ts +213 -0
- package/packages/selector/src/runtime/reducers.ts +1755 -0
- package/packages/selector/src/runtime/retrieve.ts +505 -0
- package/packages/selector/src/runtime/savings-integral.ts +117 -0
- package/packages/selector/src/runtime/savings-projection.ts +229 -0
- package/packages/selector/src/runtime/savings-verify.ts +446 -0
- package/packages/selector/src/runtime/savings.ts +526 -0
- package/packages/selector/src/runtime/sediment-card.ts +126 -0
- package/packages/selector/src/runtime/sediment-clock.ts +87 -0
- package/packages/selector/src/runtime/sediment-guard.ts +136 -0
- package/packages/selector/src/runtime/sediment-publish.ts +144 -0
- package/packages/selector/src/runtime/sediment-span.ts +170 -0
- package/packages/selector/src/runtime/sediment.ts +209 -0
- package/packages/selector/src/runtime/session-events.ts +30 -0
- package/packages/selector/src/runtime/session-file-decode.ts +523 -0
- package/packages/selector/src/runtime/shallow-tools.ts +342 -0
- package/packages/selector/src/runtime/stats-backfill.ts +541 -0
- package/packages/selector/src/runtime/stats-db.ts +492 -0
- package/packages/selector/src/runtime/stats-schema.ts +123 -0
- package/packages/selector/src/runtime/stats-sync.ts +307 -0
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tail-trim.ts +177 -0
- package/packages/selector/src/runtime/token-count.ts +72 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +82 -0
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -0
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
- package/packages/selector/src/runtime/tokenpilot/locator.ts +129 -0
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -0
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -0
- package/packages/selector/src/runtime/tool-names.ts +42 -0
- package/packages/selector/src/runtime/toolclass.ts +103 -0
- package/packages/selector/src/runtime/triage/masks.ts +128 -0
- package/packages/selector/src/runtime/triage/shallow.ts +132 -0
- package/packages/selector/src/runtime/triage/signals.ts +167 -0
- package/packages/selector/src/runtime/triage/types.ts +125 -0
- package/packages/selector/src/runtime/types.ts +396 -0
- package/packages/selector/src/runtime/value.ts +48 -0
- package/packages/selector/src/settings-bridge.ts +175 -0
- package/packages/selector/src/tui-command.ts +99 -0
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -0
- package/packages/selector/tests/built/client-artifact.spec.ts +56 -0
- package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -0
- package/packages/selector/tests/code-skeleton.client.spec.ts +98 -0
- package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +150 -0
- package/packages/selector/tests/custom-contract.client.spec.ts +226 -0
- package/packages/selector/tests/estimator-catalog.spec.ts +70 -0
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -0
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +202 -0
- package/packages/selector/tests/fab-pos.client.spec.ts +47 -0
- package/packages/selector/tests/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +231 -0
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +236 -0
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +220 -0
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +140 -0
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +117 -0
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +67 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +119 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +119 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +131 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +196 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +71 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +126 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +86 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +50 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +102 -0
- package/packages/selector/tests/helpers/legacy-namespace.ts +35 -0
- package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -0
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -0
- package/packages/selector/tests/monitor-fab.client.spec.ts +240 -0
- package/packages/selector/tests/preset-options-write.client.spec.ts +192 -0
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -0
- package/packages/selector/tests/preset-overlay.host.spec.ts +246 -0
- package/packages/selector/tests/profiles.client.spec.tsx +436 -0
- package/packages/selector/tests/ptc-custom-write.client.spec.ts +86 -0
- package/packages/selector/tests/public/package-contract.client.spec.ts +91 -0
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -0
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -0
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
- package/packages/selector/tests/runtime/audit.spec.ts +275 -0
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -0
- package/packages/selector/tests/runtime/behavior-lock-profiles.spec.ts +128 -0
- package/packages/selector/tests/runtime/char-basis.spec.ts +30 -0
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -0
- package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -0
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -0
- package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -0
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
- package/packages/selector/tests/runtime/fallback-diversity.spec.ts +75 -0
- package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -0
- package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +46 -0
- package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -0
- package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -0
- package/packages/selector/tests/runtime/fold-router.spec.ts +140 -0
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -0
- package/packages/selector/tests/runtime/fresh-gate.spec.ts +43 -0
- package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -0
- package/packages/selector/tests/runtime/injected-kinds.spec.ts +86 -0
- package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
- package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +79 -0
- package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -0
- package/packages/selector/tests/runtime/monitor.spec.ts +354 -0
- package/packages/selector/tests/runtime/netgain.spec.ts +61 -0
- package/packages/selector/tests/runtime/panel-command.spec.ts +101 -0
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -0
- package/packages/selector/tests/runtime/ptc-profile.spec.ts +133 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2795 -0
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -0
- package/packages/selector/tests/runtime/savings-accounting.spec.ts +291 -0
- package/packages/selector/tests/runtime/savings-integral.spec.ts +169 -0
- package/packages/selector/tests/runtime/savings-projection.spec.ts +89 -0
- package/packages/selector/tests/runtime/savings-verify.spec.ts +226 -0
- package/packages/selector/tests/runtime/savings.spec.ts +139 -0
- package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -0
- package/packages/selector/tests/runtime/sediment-card.spec.ts +111 -0
- package/packages/selector/tests/runtime/sediment-config.spec.ts +56 -0
- package/packages/selector/tests/runtime/sediment-guard.spec.ts +71 -0
- package/packages/selector/tests/runtime/sediment-masks.spec.ts +95 -0
- package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +166 -0
- package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +65 -0
- package/packages/selector/tests/runtime/sediment-publish.spec.ts +142 -0
- package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +158 -0
- package/packages/selector/tests/runtime/sediment-settings.spec.ts +73 -0
- package/packages/selector/tests/runtime/sediment-signals.spec.ts +124 -0
- package/packages/selector/tests/runtime/sediment-span.spec.ts +92 -0
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -0
- package/packages/selector/tests/runtime/session-file-decode.spec.ts +281 -0
- package/packages/selector/tests/runtime/settings-unwrap.spec.ts +58 -0
- package/packages/selector/tests/runtime/shallow-primitives.spec.ts +135 -0
- package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -0
- package/packages/selector/tests/runtime/source-kind-audit.spec.ts +79 -0
- package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +167 -0
- package/packages/selector/tests/runtime/stats-backfill.spec.ts +350 -0
- package/packages/selector/tests/runtime/stats-db.spec.ts +361 -0
- package/packages/selector/tests/runtime/stats-privacy.spec.ts +55 -0
- package/packages/selector/tests/runtime/stats-sync.spec.ts +278 -0
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -0
- package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -0
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
- package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -0
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -0
- package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -0
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +121 -0
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -0
- package/packages/selector/tests/runtime/toolclass.spec.ts +156 -0
- package/packages/selector/tests/runtime/value.spec.ts +23 -0
- package/packages/selector/tests/savings-sessions.client.spec.tsx +140 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +215 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +729 -0
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +269 -0
- package/packages/selector/tests/support/cache-prefix-audit.ts +105 -0
- package/packages/selector/tests/support/mock-adapter.ts +37 -0
- package/packages/selector/tests/support/ui-primitives.tsx +34 -0
- package/packages/selector/tsconfig.json +11 -0
- package/packages/selector/tsdown.client.config.ts +102 -0
- package/packages/selector/tsdown.config.ts +20 -0
- package/pnpm-workspace.yaml +76 -0
- package/screenshots.json +6 -3
- package/scripts/capture-profile-baseline.mjs +42 -0
- package/scripts/cell-browser-e2e.mjs +354 -0
- package/scripts/generate-tokenizer-fixtures.py +81 -0
- package/scripts/generate-vision-fixtures.py +208 -0
- package/scripts/hosts.d.mts +3 -0
- package/scripts/hosts.mjs +81 -0
- package/scripts/packed-components-smoke.mjs +763 -0
- package/scripts/packed-install-e2e.mjs +1346 -0
- package/scripts/sediment-latency-report.mjs +63 -0
- package/scripts/sync-hosts.mjs +176 -0
- package/scripts/toolclass-corpus-replay.mjs +281 -0
- package/scripts/verify-release.mjs +342 -0
- package/tests/TEST_INVENTORY.md +41 -0
- package/tsconfig.base.json +18 -0
- package/tsconfig.json +7 -0
- package/tsconfig.tests.json +15 -0
- package/vitest.built.config.ts +9 -0
- package/vitest.config.ts +54 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/manifest.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer_config.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/manifest.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
- /package/{cordis.patch.yml → packages/selector/cordis.patch.yml} +0 -0
- /package/{lib → packages/selector/lib}/client.d.ts +0 -0
- /package/{lib → packages/selector/lib}/index.d.ts +0 -0
- /package/{lib → packages/selector/lib}/index.js +0 -0
- /package/{lib → packages/selector/lib}/invariant.d.ts +0 -0
- /package/{lib → packages/selector/lib}/invariant.js +0 -0
- /package/{lib → packages/selector/lib}/pruner.d.ts +0 -0
- /package/{lib → packages/selector/lib}/pruner.js +0 -0
- /package/{lib → packages/selector/lib}/savings-integral.js +0 -0
- /package/{lib → packages/selector/lib}/tail-trim.js +0 -0
- /package/{lib → packages/selector/lib}/tool-result.js +0 -0
- /package/{locale → packages/selector/locale}/de.json +0 -0
- /package/{locale → packages/selector/locale}/en.json +0 -0
- /package/{locale → packages/selector/locale}/es.json +0 -0
- /package/{locale → packages/selector/locale}/fr.json +0 -0
- /package/{locale → packages/selector/locale}/it.json +0 -0
- /package/{locale → packages/selector/locale}/ja.json +0 -0
- /package/{locale → packages/selector/locale}/ko.json +0 -0
- /package/{locale → packages/selector/locale}/pt.json +0 -0
- /package/{locale → packages/selector/locale}/ru.json +0 -0
- /package/{locale → packages/selector/locale}/zh.json +0 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shallow-read tool surface (plan cci-sedimentation-triage, Phase 4.5).
|
|
3
|
+
*
|
|
4
|
+
* Registers the upgrade-discard primitives next to the existing retrieve tool:
|
|
5
|
+
* - `context_compression_probe` — O(1) header sample → recommended shallow view
|
|
6
|
+
* - `context_compression_shallow` — the map: classified shallow view + checkpoint
|
|
7
|
+
* - `context_compression_discard` — drops one side of a shallow/full pair,
|
|
8
|
+
* guarded so the MAP only dies under full coverage; the checkpoint line
|
|
9
|
+
* always survives (R11).
|
|
10
|
+
*
|
|
11
|
+
* The decision core is exported pure (`buildShallowView`, `parseReadCoverage`,
|
|
12
|
+
* registry helpers) so the guard arithmetic is unit-testable without a host;
|
|
13
|
+
* `installShallowTools` only adapts those to `defineTool`.
|
|
14
|
+
*/
|
|
15
|
+
import fs from 'node:fs/promises'
|
|
16
|
+
import path from 'node:path'
|
|
17
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
18
|
+
import type { SessionSeq as SessionSeqBrand } from '@deepseek-ai/dsh-session'
|
|
19
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
20
|
+
import { PTC_BINDING_NOTE, RUNTIME_TOOL_NAMES } from './tool-names.ts'
|
|
21
|
+
import {
|
|
22
|
+
buildShallowFooter,
|
|
23
|
+
classifyShallowSample,
|
|
24
|
+
evaluateDiscardGuard,
|
|
25
|
+
normalizeToolPath,
|
|
26
|
+
renderCheckpointLine,
|
|
27
|
+
shallowFingerprint,
|
|
28
|
+
type ReadPairSide,
|
|
29
|
+
} from './triage/shallow.ts'
|
|
30
|
+
import { skeletonFromRead } from './triage/masks.ts'
|
|
31
|
+
import { sessionEvents } from './session-events.ts'
|
|
32
|
+
import { getSavingsLedger } from './savings.ts'
|
|
33
|
+
import { tailTrimMessage } from './tail-trim.ts'
|
|
34
|
+
import type { ShallowCheckpoint } from './triage/types.ts'
|
|
35
|
+
|
|
36
|
+
const PROBE_SAMPLE_BYTES = 2_048
|
|
37
|
+
const SHALLOW_MAX_BYTES = 2_000_000
|
|
38
|
+
const REF_PATTERN = /^session:\/\/([^/]+)\/event\/(\d+)$/
|
|
39
|
+
|
|
40
|
+
/** Live shallow maps per session, keyed by normalized path. */
|
|
41
|
+
export interface ShallowEntry {
|
|
42
|
+
readonly seq: number
|
|
43
|
+
readonly checkpoint: ShallowCheckpoint
|
|
44
|
+
readonly bodyTokens: number
|
|
45
|
+
discarded: boolean
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const registry = new WeakMap<object, Map<string, ShallowEntry>>()
|
|
49
|
+
|
|
50
|
+
export function shallowRegistryFor(session: object): Map<string, ShallowEntry> {
|
|
51
|
+
let map = registry.get(session)
|
|
52
|
+
if (map === undefined) {
|
|
53
|
+
map = new Map()
|
|
54
|
+
registry.set(session, map)
|
|
55
|
+
}
|
|
56
|
+
return map
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The live (undiscarded) map for a path, if any — footer pairing source. */
|
|
60
|
+
export function liveShallowFor(session: object, rawPath: string): ShallowEntry | undefined {
|
|
61
|
+
const entry = shallowRegistryFor(session).get(normalizeToolPath(rawPath))
|
|
62
|
+
return entry !== undefined && !entry.discarded ? entry : undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Pure view builder shared by the shallow tool and tests. */
|
|
66
|
+
export function buildShallowView(
|
|
67
|
+
text: string,
|
|
68
|
+
method: ReturnType<typeof classifyShallowSample>['method'],
|
|
69
|
+
rawPath: string,
|
|
70
|
+
seq: number,
|
|
71
|
+
): { readonly body: string; readonly checkpoint: ShallowCheckpoint | null } {
|
|
72
|
+
const lines = text.replace(/\n+$/, '').split('\n')
|
|
73
|
+
const checkpointBase = {
|
|
74
|
+
path: normalizeToolPath(rawPath),
|
|
75
|
+
coverage: `${lines.length} lines`,
|
|
76
|
+
ref: `event/${seq}`,
|
|
77
|
+
fingerprint: shallowFingerprint(text),
|
|
78
|
+
}
|
|
79
|
+
if (method === 'code-skeleton') {
|
|
80
|
+
const verdict = skeletonFromRead(text, seq, rawPath)
|
|
81
|
+
if (verdict !== null && verdict.kind === 'skeleton') {
|
|
82
|
+
const body = `${verdict.lines.join('\n')}\n[… body elided: ${verdict.totalLines - verdict.lines.length} lines / ${verdict.elidedChars} chars]`
|
|
83
|
+
return { body, checkpoint: verdict.checkpoint ?? { ...checkpointBase } }
|
|
84
|
+
}
|
|
85
|
+
// zero-hit code: honest head/tail instead of an empty skeleton
|
|
86
|
+
return headTailView(lines, checkpointBase)
|
|
87
|
+
}
|
|
88
|
+
if (method === 'json-skeleton') {
|
|
89
|
+
try {
|
|
90
|
+
const parsed: unknown = JSON.parse(text)
|
|
91
|
+
const keys: string[] = []
|
|
92
|
+
collectJsonKeys(parsed, '', keys, 40)
|
|
93
|
+
if (keys.length === 0) return headTailView(lines, checkpointBase)
|
|
94
|
+
return { body: `${keys.join('\n')}\n[… ${lines.length} lines of JSON values elided]`, checkpoint: { ...checkpointBase } }
|
|
95
|
+
} catch {
|
|
96
|
+
return headTailView(lines, checkpointBase)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (method === 'csv-header') {
|
|
100
|
+
const header = lines.slice(0, 3).join('\n')
|
|
101
|
+
return { body: `${header}\n[… ${Math.max(0, lines.length - 3)} data rows elided]`, checkpoint: { ...checkpointBase } }
|
|
102
|
+
}
|
|
103
|
+
if (method === 'toc-lines') {
|
|
104
|
+
const headings = lines.filter(line => /^#{1,6} |^\s*\*\*\w/.test(line)).slice(0, 60)
|
|
105
|
+
if (headings.length === 0) return headTailView(lines, checkpointBase)
|
|
106
|
+
return { body: `${headings.join('\n')}\n[… ${lines.length} lines under the outline elided]`, checkpoint: { ...checkpointBase } }
|
|
107
|
+
}
|
|
108
|
+
return headTailView(lines, checkpointBase)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function headTailView(
|
|
112
|
+
lines: string[],
|
|
113
|
+
base: ShallowCheckpoint,
|
|
114
|
+
): { body: string; checkpoint: ShallowCheckpoint } {
|
|
115
|
+
const head = lines.slice(0, 20)
|
|
116
|
+
const tail = lines.slice(-10)
|
|
117
|
+
const middle = Math.max(0, lines.length - head.length - tail.length)
|
|
118
|
+
return {
|
|
119
|
+
body: [...head, ...(middle > 0 ? [`[… ${middle} lines elided]`] : []), ...tail].join('\n'),
|
|
120
|
+
checkpoint: base,
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function collectJsonKeys(node: unknown, prefix: string, out: string[], cap: number): void {
|
|
125
|
+
if (out.length >= cap) return
|
|
126
|
+
if (Array.isArray(node)) {
|
|
127
|
+
out.push(`${prefix}[] (${node.length})`)
|
|
128
|
+
if (node.length > 0) collectJsonKeys(node[0], `${prefix}[]`, out, cap)
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
if (node !== null && typeof node === 'object') {
|
|
132
|
+
for (const [key, value] of Object.entries(node)) {
|
|
133
|
+
if (out.length >= cap) return
|
|
134
|
+
const at = `${prefix}.${key}`.replace(/^\./, '')
|
|
135
|
+
if (value !== null && typeof value === 'object') collectJsonKeys(value, at, out, cap)
|
|
136
|
+
else out.push(at)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Coverage of a host `read` call from its arguments JSON (pairing input). */
|
|
142
|
+
export function parseReadCoverage(argsJson: string): ReadPairSide['coverage'] {
|
|
143
|
+
let args: Record<string, unknown>
|
|
144
|
+
try {
|
|
145
|
+
args = JSON.parse(argsJson) as Record<string, unknown>
|
|
146
|
+
} catch {
|
|
147
|
+
return { kind: 'slice', from: 1, to: 0 } // matches nothing
|
|
148
|
+
}
|
|
149
|
+
const offset = typeof args.offset === 'number' && Number.isSafeInteger(args.offset) ? Math.max(0, args.offset) : 0
|
|
150
|
+
const limit = typeof args.limit === 'number' && Number.isSafeInteger(args.limit) ? args.limit : undefined
|
|
151
|
+
if (limit === undefined && offset === 0) return { kind: 'full' }
|
|
152
|
+
const from = offset + 1
|
|
153
|
+
const to = limit === undefined ? Number.MAX_SAFE_INTEGER : offset + limit
|
|
154
|
+
return { kind: 'slice', from, to }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Register probe/shallow/discard. Reachability and the pairing registry are
|
|
159
|
+
* in-process truth; every tool call stays inside the caller's own session.
|
|
160
|
+
*/
|
|
161
|
+
export function installShallowTools(ctx: Context): void {
|
|
162
|
+
const OUTPUT = {
|
|
163
|
+
schema: { type: 'string' as const },
|
|
164
|
+
render: (_args: unknown, value: string) => [{ type: 'text' as const, text: value }],
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
ctx.systemPrompt.section({
|
|
168
|
+
name: 'tool:context-compression-shallow',
|
|
169
|
+
order: 115,
|
|
170
|
+
text: `Before reading a large unknown file, call ${RUNTIME_TOOL_NAMES.PROBE} with its path to pick the right shallow view, then ${RUNTIME_TOOL_NAMES.SHALLOW} to get the map (declaration/outline/keys + checkpoint line) instead of the full body. `
|
|
171
|
+
+ `After a full read supersedes a live map, or a map's body is no longer needed, ${RUNTIME_TOOL_NAMES.DISCARD} frees it — the checkpoint line always remains and ${RUNTIME_TOOL_NAMES.RETRIEVE} can still recover the body. `
|
|
172
|
+
+ 'Never reconstitute discarded output from memory or guesswork; use the ref. '
|
|
173
|
+
+ PTC_BINDING_NOTE,
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
ctx.tools.register(defineTool({
|
|
177
|
+
name: RUNTIME_TOOL_NAMES.PROBE,
|
|
178
|
+
description: `Read at most the first ${PROBE_SAMPLE_BYTES} bytes of a file and return the recommended shallow view method with reasons. ${PTC_BINDING_NOTE}`,
|
|
179
|
+
parameters: {
|
|
180
|
+
path: { type: 'string', required: true, description: 'File path to probe.' },
|
|
181
|
+
},
|
|
182
|
+
output: OUTPUT,
|
|
183
|
+
isConcurrencySafe: () => true,
|
|
184
|
+
async execute(args) {
|
|
185
|
+
const handle = await fs.open(args.path, 'r')
|
|
186
|
+
try {
|
|
187
|
+
const buffer = Buffer.alloc(PROBE_SAMPLE_BYTES)
|
|
188
|
+
const { bytesRead } = await handle.read(buffer, 0, PROBE_SAMPLE_BYTES, 0)
|
|
189
|
+
const stat = await handle.stat()
|
|
190
|
+
const verdict = classifyShallowSample(
|
|
191
|
+
buffer.subarray(0, bytesRead).toString('utf8'),
|
|
192
|
+
path.extname(args.path),
|
|
193
|
+
stat.size,
|
|
194
|
+
)
|
|
195
|
+
return `${verdict.method} | ${verdict.reason} | size ${stat.size} B`
|
|
196
|
+
} finally {
|
|
197
|
+
await handle.close()
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
}))
|
|
201
|
+
|
|
202
|
+
ctx.tools.register(defineTool({
|
|
203
|
+
name: RUNTIME_TOOL_NAMES.SHALLOW,
|
|
204
|
+
description: 'Return a shallow view (declaration skeleton / JSON keys / outline / csv header + head/tail) of a file plus its permanent checkpoint line. Cheaper than a full read; pairs with discard and retrieve. ' + PTC_BINDING_NOTE,
|
|
205
|
+
parameters: {
|
|
206
|
+
path: { type: 'string', required: true, description: 'File path to view shallowly.' },
|
|
207
|
+
method: { type: 'string', description: `Override the classified view: json-skeleton | code-skeleton | csv-header | toc-lines | head-tail.` },
|
|
208
|
+
},
|
|
209
|
+
output: OUTPUT,
|
|
210
|
+
isConcurrencySafe: () => true,
|
|
211
|
+
async execute(args, exec) {
|
|
212
|
+
if (exec.agent === undefined) throw new Error(`${RUNTIME_TOOL_NAMES.SHALLOW} requires an agent session`)
|
|
213
|
+
const stat = await fs.stat(args.path)
|
|
214
|
+
if (stat.size > SHALLOW_MAX_BYTES) {
|
|
215
|
+
throw new Error(`${RUNTIME_TOOL_NAMES.SHALLOW}: file is ${stat.size} B, above the ${SHALLOW_MAX_BYTES} B shallow cap; read slices instead`)
|
|
216
|
+
}
|
|
217
|
+
const text = await fs.readFile(args.path, 'utf8')
|
|
218
|
+
const method = (args.method ?? classifyShallowSample(
|
|
219
|
+
text.slice(0, PROBE_SAMPLE_BYTES), path.extname(args.path), stat.size,
|
|
220
|
+
).method) as ReturnType<typeof classifyShallowSample>['method']
|
|
221
|
+
const events = sessionEvents(exec.agent.session as never)
|
|
222
|
+
const seq = events.length
|
|
223
|
+
const { body, checkpoint } = buildShallowView(text, method, args.path, seq)
|
|
224
|
+
if (checkpoint !== null) {
|
|
225
|
+
shallowRegistryFor(exec.agent.session).set(checkpoint.path, {
|
|
226
|
+
seq,
|
|
227
|
+
checkpoint,
|
|
228
|
+
bodyTokens: Math.ceil((body.length + checkpoint.path.length) / 4),
|
|
229
|
+
discarded: false,
|
|
230
|
+
})
|
|
231
|
+
return `${body}\n\n${renderCheckpointLine(checkpoint)}`
|
|
232
|
+
}
|
|
233
|
+
return body
|
|
234
|
+
},
|
|
235
|
+
}))
|
|
236
|
+
|
|
237
|
+
ctx.tools.register(defineTool({
|
|
238
|
+
name: RUNTIME_TOOL_NAMES.DISCARD,
|
|
239
|
+
description: 'Free one side of a shallow/full read pair from the context: the live shallow map (only when a covering full read spans it) or a full read whose map suffices. The checkpoint line always remains; retrieve can recover bodies by ref. ' + PTC_BINDING_NOTE,
|
|
240
|
+
parameters: {
|
|
241
|
+
ref: { type: 'string', required: true, description: 'session://<current-session-id>/event/<seq> of the shallow map to discard.' },
|
|
242
|
+
covering_ref: { type: 'string', description: 'event ref of the full read that supersedes the map (required to discard the map).' },
|
|
243
|
+
},
|
|
244
|
+
output: OUTPUT,
|
|
245
|
+
isConcurrencySafe: () => false,
|
|
246
|
+
async execute(args, exec) {
|
|
247
|
+
if (exec.agent === undefined) throw new Error(`${RUNTIME_TOOL_NAMES.DISCARD} requires an agent session`)
|
|
248
|
+
const session = exec.agent.session
|
|
249
|
+
const match = REF_PATTERN.exec(args.ref)
|
|
250
|
+
if (match === null || match[1] !== String(session.id)) {
|
|
251
|
+
throw new Error(`${RUNTIME_TOOL_NAMES.DISCARD}: ref must be session://<current-session-id>/event/<seq>`)
|
|
252
|
+
}
|
|
253
|
+
const targetSeq = Number(match[2])
|
|
254
|
+
const registryMap = shallowRegistryFor(session)
|
|
255
|
+
const entry = [...registryMap.values()].find(candidate => candidate.seq === targetSeq)
|
|
256
|
+
if (entry === undefined) {
|
|
257
|
+
throw new Error(`${RUNTIME_TOOL_NAMES.DISCARD}: ${args.ref} is not a live shallow map of this session (only ${RUNTIME_TOOL_NAMES.SHALLOW} results are discardable here)`)
|
|
258
|
+
}
|
|
259
|
+
if (entry.discarded) return `${renderCheckpointLine(entry.checkpoint)} (already discarded)`
|
|
260
|
+
const coveringRef = args.covering_ref
|
|
261
|
+
if (coveringRef === undefined) {
|
|
262
|
+
throw new Error(`${RUNTIME_TOOL_NAMES.DISCARD}: discarding the map requires covering_ref of the full read that supersedes it`)
|
|
263
|
+
}
|
|
264
|
+
const coveringMatch = REF_PATTERN.exec(coveringRef)
|
|
265
|
+
if (coveringMatch === null || coveringMatch[1] !== String(session.id)) {
|
|
266
|
+
throw new Error(`${RUNTIME_TOOL_NAMES.DISCARD}: covering_ref must be in the current session`)
|
|
267
|
+
}
|
|
268
|
+
const events = sessionEvents(session as never) as unknown as ReadonlyArray<Record<string, unknown>>
|
|
269
|
+
const coveringEvent = events[Number(coveringMatch[2])]
|
|
270
|
+
if (coveringEvent?.type !== 'tool/result') {
|
|
271
|
+
throw new Error(`${RUNTIME_TOOL_NAMES.DISCARD}: covering_ref does not cite a tool/result`)
|
|
272
|
+
}
|
|
273
|
+
const coveringMessage = (coveringEvent.data as Record<string, unknown> | undefined)?.message as Record<string, unknown> | undefined
|
|
274
|
+
const coveringArgs = typeof coveringMessage?.toolCallId === 'string'
|
|
275
|
+
? findCallArgs(events, coveringMessage.toolCallId)
|
|
276
|
+
: undefined
|
|
277
|
+
const covering: ReadPairSide = {
|
|
278
|
+
seq: Number(coveringMatch[2]),
|
|
279
|
+
path: coveringArgs?.path ?? '',
|
|
280
|
+
coverage: coveringArgs === undefined
|
|
281
|
+
? { kind: 'slice', from: 1, to: 0 }
|
|
282
|
+
: parseReadCoverage(coveringArgs.argsJson),
|
|
283
|
+
}
|
|
284
|
+
const mapSide: ReadPairSide = {
|
|
285
|
+
seq: entry.seq,
|
|
286
|
+
path: entry.checkpoint.path,
|
|
287
|
+
coverage: { kind: 'full' }, // a map stands for the whole file outline
|
|
288
|
+
}
|
|
289
|
+
const guard = evaluateDiscardGuard({ map: mapSide, covering })
|
|
290
|
+
if (!guard.allowed) {
|
|
291
|
+
throw new Error(`${RUNTIME_TOOL_NAMES.DISCARD}: refused (${guard.reason}) — the map covers the whole file and the cited read does not supersede it`)
|
|
292
|
+
}
|
|
293
|
+
const message = tailTrimMessage(renderCheckpointLine(entry.checkpoint))
|
|
294
|
+
session.append('user/message', message as never, {
|
|
295
|
+
surfaceOp: { op: 'replace', startSeq: entry.seq as SessionSeqBrand, endSeq: entry.seq as SessionSeqBrand },
|
|
296
|
+
sourceEventSeqs: [entry.seq as SessionSeqBrand],
|
|
297
|
+
})
|
|
298
|
+
entry.discarded = true
|
|
299
|
+
// 记账隔离(T4.9):模型发起的弃对节省单列 component,不与插件发起压缩混算。
|
|
300
|
+
getSavingsLedger().recordSaving({
|
|
301
|
+
sessionId: String(session.id),
|
|
302
|
+
component: 'shallow-discard',
|
|
303
|
+
tokensBefore: entry.bodyTokens,
|
|
304
|
+
tokensAfter: Math.ceil(renderCheckpointLine(entry.checkpoint).length / 4),
|
|
305
|
+
basis: 'characters',
|
|
306
|
+
sourceSeq: entry.seq,
|
|
307
|
+
replacementSeq: entry.seq,
|
|
308
|
+
originalText: `${entry.checkpoint.path} shallow body`,
|
|
309
|
+
})
|
|
310
|
+
return buildShallowFooter(entry.checkpoint, 0) + `\n[discarded] ${renderCheckpointLine(entry.checkpoint)}`
|
|
311
|
+
},
|
|
312
|
+
}))
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Find the arguments JSON + file path of the call owning a tool/result. */
|
|
316
|
+
function findCallArgs(
|
|
317
|
+
events: ReadonlyArray<Record<string, unknown>>,
|
|
318
|
+
callId: string,
|
|
319
|
+
): { path: string; argsJson: string } | undefined {
|
|
320
|
+
for (const event of events) {
|
|
321
|
+
if (event.type !== 'assistant/message') continue
|
|
322
|
+
const message = (event.data as Record<string, unknown> | undefined)?.message as Record<string, unknown> | undefined
|
|
323
|
+
const blocks = Array.isArray(message?.content) ? message.content : []
|
|
324
|
+
for (const raw of blocks) {
|
|
325
|
+
const block = raw as Record<string, unknown> | null
|
|
326
|
+
if (block !== null && block.type === 'tool-call' && block.id === callId) {
|
|
327
|
+
const argsJson = typeof block.arguments === 'string'
|
|
328
|
+
? block.arguments
|
|
329
|
+
: JSON.stringify(block.arguments ?? {})
|
|
330
|
+
let filePath: string
|
|
331
|
+
try {
|
|
332
|
+
const parsed = JSON.parse(argsJson) as Record<string, unknown>
|
|
333
|
+
filePath = typeof parsed.file_path === 'string' ? parsed.file_path : typeof parsed.path === 'string' ? parsed.path : ''
|
|
334
|
+
} catch {
|
|
335
|
+
filePath = ''
|
|
336
|
+
}
|
|
337
|
+
return { path: filePath, argsJson }
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return undefined
|
|
342
|
+
}
|