dsh-context-compression-improved 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.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/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 +554 -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/measurement.ts +444 -0
- package/packages/selector/src/runtime/monitor.ts +341 -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/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/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}/profiles.d.ts +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,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tui-command.ts — `/compress`:上下文压缩策略的 dsh-tui 终端面。
|
|
3
|
+
*
|
|
4
|
+
* 背景:TUI 不加载设置卡/投影卡片,压缩策略(门限、保留轮数、开关)在终端里
|
|
5
|
+
* 既看不到也调不了,而它直接决定长会话会不会崩。命令只读回显设置节。
|
|
6
|
+
*
|
|
7
|
+
* 契约:单行 <=100、总行 <=40、无 ANSI、--json 单行。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
11
|
+
|
|
12
|
+
export type CommandKind = 'success' | 'error'
|
|
13
|
+
export interface CommandResult { kind: CommandKind; text: string }
|
|
14
|
+
|
|
15
|
+
export interface CompressDeps {
|
|
16
|
+
ns: string
|
|
17
|
+
section(): Record<string, unknown> | undefined
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const MAX_LINES = 40
|
|
21
|
+
const MAX_WIDTH = 100
|
|
22
|
+
|
|
23
|
+
export function clip(text: string, width = MAX_WIDTH): string {
|
|
24
|
+
const value = String(text ?? '').replace(/[\r\n]+/g, ' ').replace(/\s+$/, '')
|
|
25
|
+
return value.length <= width ? value : `${value.slice(0, width - 1)}…`
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function renderLines(lines: string[], limit = MAX_LINES): string {
|
|
29
|
+
const clipped = lines.map((line) => clip(line))
|
|
30
|
+
if (clipped.length <= limit) return clipped.join('\n')
|
|
31
|
+
const kept = clipped.slice(0, limit - 1)
|
|
32
|
+
return [...kept, `… 还有 ${clipped.length - kept.length} 行,加 --all 查看`].join('\n')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function sectionOf(ctx: Context, ns: string): Record<string, unknown> | undefined {
|
|
36
|
+
const settings = (ctx as unknown as { get?: (name: string) => unknown }).get?.('settings') as
|
|
37
|
+
| { describe?: () => unknown }
|
|
38
|
+
| undefined
|
|
39
|
+
const raw = settings?.describe?.()
|
|
40
|
+
const list = Array.isArray(raw) ? raw : (raw as { namespaces?: unknown[] } | undefined)?.namespaces
|
|
41
|
+
if (!Array.isArray(list)) return undefined
|
|
42
|
+
for (const entry of list) {
|
|
43
|
+
const row = entry as { ns?: unknown; value?: unknown } | null
|
|
44
|
+
if (row?.ns === ns && row.value !== null && typeof row.value === 'object') return row.value as Record<string, unknown>
|
|
45
|
+
}
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function runCompressCommand(rawInput: string, deps: CompressDeps): CommandResult {
|
|
50
|
+
const argv = String(rawInput ?? '').trim().split(/\s+/).filter(Boolean)
|
|
51
|
+
const json = argv.includes('--json')
|
|
52
|
+
const sub = (argv.find((token) => !token.startsWith('--')) ?? 'status').toLowerCase()
|
|
53
|
+
const wrap = (result: CommandResult, data: unknown): CommandResult => {
|
|
54
|
+
if (!json) return result
|
|
55
|
+
const body = result.kind === 'error'
|
|
56
|
+
? { ok: false, cmd: 'compress', error: { message: result.text.split('\n')[0] ?? result.text } }
|
|
57
|
+
: { ok: true, cmd: 'compress', data }
|
|
58
|
+
return { kind: result.kind, text: JSON.stringify(body) }
|
|
59
|
+
}
|
|
60
|
+
if (sub === 'help' || sub === '?') {
|
|
61
|
+
return wrap({ kind: 'success', text: renderLines([
|
|
62
|
+
'compress — 上下文压缩策略(只读回显)',
|
|
63
|
+
' /compress status 设置节内容(门限/保留轮数/开关)',
|
|
64
|
+
' /compress policy 同 status(别名)',
|
|
65
|
+
' flags --json 单行 JSON',
|
|
66
|
+
' note 改策略走 Desktop 设置页;命令层只读',
|
|
67
|
+
]) }, { help: true })
|
|
68
|
+
}
|
|
69
|
+
if (sub !== 'status' && sub !== 'policy') {
|
|
70
|
+
return wrap({ kind: 'error', text: renderLines([`compress: 未知子命令 "${sub}"`, ' next: /compress help']) }, {})
|
|
71
|
+
}
|
|
72
|
+
const section = deps.section()
|
|
73
|
+
if (section === undefined) {
|
|
74
|
+
return wrap({ kind: 'error', text: renderLines([
|
|
75
|
+
`compress: 设置节 ${deps.ns} 不在 profile 文档里`,
|
|
76
|
+
' next 检查插件是否已进入 profile;或看 cordis.patch.yml',
|
|
77
|
+
]) }, {})
|
|
78
|
+
}
|
|
79
|
+
const keys = Object.keys(section)
|
|
80
|
+
const lines = ['compress — 设置节(只读)']
|
|
81
|
+
for (const key of keys.slice(0, 14)) {
|
|
82
|
+
const value = section[key]
|
|
83
|
+
lines.push(` ${key.padEnd(20)} ${clip(typeof value === 'object' && value !== null ? JSON.stringify(value) : String(value), 60)}`)
|
|
84
|
+
}
|
|
85
|
+
if (keys.length > 14) lines.push(` … 还有 ${keys.length - 14} 个字段`)
|
|
86
|
+
return wrap({ kind: 'success', text: renderLines(lines) }, section)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function registerCompressCommand(ctx: Context, deps: CompressDeps): void {
|
|
90
|
+
const registry = (ctx as unknown as { commands?: { register(definition: unknown): unknown } }).commands
|
|
91
|
+
if (!registry || typeof registry.register !== 'function') return
|
|
92
|
+
registry.register({
|
|
93
|
+
definitionId: 'dsh-context-compression-improved',
|
|
94
|
+
name: 'compress',
|
|
95
|
+
description: 'Context compression console: read-only echo of the strategy section',
|
|
96
|
+
input: { hint: '[status|policy] [--json]' },
|
|
97
|
+
handler: (invocation: { rawInput?: string }) => runCompressCommand(invocation?.rawInput ?? '', deps),
|
|
98
|
+
})
|
|
99
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-side guard for the advisory advisor's HTTP report route.
|
|
3
|
+
*
|
|
4
|
+
* Pins the read-only contract: the route registers under both prefixes only
|
|
5
|
+
* when the row opts in, a session whose advisor never ran reports nulls and
|
|
6
|
+
* empty arrays (not an error), a populated session reports its decay figure
|
|
7
|
+
* and score distribution content-free, and every error path answers a
|
|
8
|
+
* precise status — 400 for a missing sessionId, 404 for an unknown session,
|
|
9
|
+
* 503 when no agents service can resolve sessions at all.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
13
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
14
|
+
import { apply } from '../src/index.ts'
|
|
15
|
+
import { getAdvisorState, recordScore, recordRecertified } from '../src/runtime/tokenpilot/advisor-state.ts'
|
|
16
|
+
|
|
17
|
+
const REPORT_ROUTE = '/api/dsh-context-compression-improved/advisor-report'
|
|
18
|
+
const LEGACY_REPORT_ROUTE = '/endpoint/dsh-context-compression-improved/advisor-report'
|
|
19
|
+
|
|
20
|
+
interface RegisteredRoute {
|
|
21
|
+
kind: string
|
|
22
|
+
path: string
|
|
23
|
+
handler: (req: unknown, res: unknown) => unknown
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface FakeResponse {
|
|
27
|
+
status?: number
|
|
28
|
+
body?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let ctx: Context | undefined
|
|
32
|
+
|
|
33
|
+
afterEach(async () => {
|
|
34
|
+
await ctx?.fiber.dispose()
|
|
35
|
+
ctx = undefined
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const settle = (): Promise<void> => new Promise(resolve => setTimeout(resolve, 20))
|
|
39
|
+
|
|
40
|
+
async function mountWebServer(runtime: Context, routes: RegisteredRoute[]): Promise<void> {
|
|
41
|
+
await runtime.plugin({
|
|
42
|
+
name: 'fake-webserver',
|
|
43
|
+
apply(webCtx) {
|
|
44
|
+
webCtx.provide('webServer', {
|
|
45
|
+
tables: { exact: new Map<string, RegisteredRoute>() },
|
|
46
|
+
register(this: { tables: { exact: Map<string, RegisteredRoute> } }, route: RegisteredRoute) {
|
|
47
|
+
const table = this.tables.exact
|
|
48
|
+
if (table.has(route.path)) {
|
|
49
|
+
throw new Error(`webserver: duplicate ${route.kind} route "${route.path}"`)
|
|
50
|
+
}
|
|
51
|
+
table.set(route.path, route)
|
|
52
|
+
routes.push(route)
|
|
53
|
+
return () => {}
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Mount an agents service that knows session 's1' (and nothing else). */
|
|
61
|
+
function mountAgents(runtime: Context): void {
|
|
62
|
+
void runtime.plugin({
|
|
63
|
+
name: 'fake-agents',
|
|
64
|
+
apply(serviceCtx) {
|
|
65
|
+
serviceCtx.provide('agents', {
|
|
66
|
+
get: (id: unknown) => {
|
|
67
|
+
if (id !== 's1') return undefined
|
|
68
|
+
const session = { id: 's1' }
|
|
69
|
+
const state = getAdvisorState(session as never)
|
|
70
|
+
state.summary = {
|
|
71
|
+
overallTask: 'migrate the auth module',
|
|
72
|
+
activeSubtasks: ['port login flow'],
|
|
73
|
+
keywords: ['auth'],
|
|
74
|
+
todoVersion: 'aaaa1111',
|
|
75
|
+
turn: 4,
|
|
76
|
+
}
|
|
77
|
+
state.lastDecay = { decay: 0.42, weightedChars: 10_000, turn: 4 }
|
|
78
|
+
recordScore(state, 3, { score: 0.95, turn: 4 })
|
|
79
|
+
recordScore(state, 5, { score: 0.10, turn: 4 })
|
|
80
|
+
recordRecertified(state, 5, 4)
|
|
81
|
+
return { session }
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function invoke(route: RegisteredRoute, req?: unknown): Promise<FakeResponse> {
|
|
89
|
+
const captured: FakeResponse = {}
|
|
90
|
+
const res = {
|
|
91
|
+
writeHead(code: number) { captured.status = code },
|
|
92
|
+
end(body?: string) { if (body !== undefined) captured.body = body },
|
|
93
|
+
}
|
|
94
|
+
await route.handler(req ?? { method: 'GET' }, res)
|
|
95
|
+
await settle()
|
|
96
|
+
return captured
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
describe('advisor report route registration', () => {
|
|
100
|
+
it('registers both prefixes only when the row opts in', async () => {
|
|
101
|
+
const routes: RegisteredRoute[] = []
|
|
102
|
+
const runtime = new Context()
|
|
103
|
+
ctx = runtime
|
|
104
|
+
await mountWebServer(runtime, routes)
|
|
105
|
+
apply(runtime, { advisorReportRoute: true })
|
|
106
|
+
await settle()
|
|
107
|
+
const paths = routes.map(route => route.path)
|
|
108
|
+
expect(paths).toContain(REPORT_ROUTE)
|
|
109
|
+
expect(paths).toContain(LEGACY_REPORT_ROUTE)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('registers nothing by default (advisor off adds zero behavior)', async () => {
|
|
113
|
+
const routes: RegisteredRoute[] = []
|
|
114
|
+
const runtime = new Context()
|
|
115
|
+
ctx = runtime
|
|
116
|
+
await mountWebServer(runtime, routes)
|
|
117
|
+
apply(runtime, {})
|
|
118
|
+
await settle()
|
|
119
|
+
expect(routes.map(route => route.path)).not.toContain(REPORT_ROUTE)
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
describe('advisor report route responses', () => {
|
|
124
|
+
async function mountedRoute(): Promise<RegisteredRoute> {
|
|
125
|
+
const routes: RegisteredRoute[] = []
|
|
126
|
+
const runtime = new Context()
|
|
127
|
+
ctx = runtime
|
|
128
|
+
await mountWebServer(runtime, routes)
|
|
129
|
+
apply(runtime, { advisorReportRoute: true })
|
|
130
|
+
await settle()
|
|
131
|
+
const route = routes.find(entry => entry.path === REPORT_ROUTE)
|
|
132
|
+
expect(route).toBeDefined()
|
|
133
|
+
return route as RegisteredRoute
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
it('answers 503 without an agents service', async () => {
|
|
137
|
+
const route = await mountedRoute()
|
|
138
|
+
const response = await invoke(route, { url: `${REPORT_ROUTE}?sessionId=s1` })
|
|
139
|
+
expect(response.status).toBe(503)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('answers 404 for an unknown session and 400 for a missing sessionId', async () => {
|
|
143
|
+
const routes: RegisteredRoute[] = []
|
|
144
|
+
const runtime = new Context()
|
|
145
|
+
ctx = runtime
|
|
146
|
+
await mountWebServer(runtime, routes)
|
|
147
|
+
mountAgents(runtime)
|
|
148
|
+
apply(runtime, { advisorReportRoute: true })
|
|
149
|
+
await settle()
|
|
150
|
+
const route = routes.find(entry => entry.path === REPORT_ROUTE) as RegisteredRoute
|
|
151
|
+
|
|
152
|
+
const unknown = await invoke(route, { url: `${REPORT_ROUTE}?sessionId=other` })
|
|
153
|
+
expect(unknown.status).toBe(404)
|
|
154
|
+
|
|
155
|
+
const missing = await invoke(route, { url: REPORT_ROUTE })
|
|
156
|
+
expect(missing.status).toBe(400)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it('serves the decay figure, summary, and scores content-free', async () => {
|
|
160
|
+
const routes: RegisteredRoute[] = []
|
|
161
|
+
const runtime = new Context()
|
|
162
|
+
ctx = runtime
|
|
163
|
+
await mountWebServer(runtime, routes)
|
|
164
|
+
mountAgents(runtime)
|
|
165
|
+
apply(runtime, { advisorReportRoute: true })
|
|
166
|
+
await settle()
|
|
167
|
+
const route = routes.find(entry => entry.path === REPORT_ROUTE) as RegisteredRoute
|
|
168
|
+
|
|
169
|
+
const response = await invoke(route, { url: `${REPORT_ROUTE}?sessionId=s1` })
|
|
170
|
+
expect(response.status).toBe(200)
|
|
171
|
+
const body = JSON.parse(response.body ?? '{}') as {
|
|
172
|
+
ok: boolean
|
|
173
|
+
sessionId: string
|
|
174
|
+
advisor: {
|
|
175
|
+
summary: { overallTask: string } | null
|
|
176
|
+
decay: number | null
|
|
177
|
+
weightedChars: number | null
|
|
178
|
+
scores: { seq: number, score: number }[]
|
|
179
|
+
lowRelevanceSeqs: number[]
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
expect(body.ok).toBe(true)
|
|
183
|
+
expect(body.sessionId).toBe('s1')
|
|
184
|
+
expect(body.advisor.decay).toBeCloseTo(0.42, 12)
|
|
185
|
+
expect(body.advisor.summary?.overallTask).toBe('migrate the auth module')
|
|
186
|
+
expect(body.advisor.scores).toHaveLength(2)
|
|
187
|
+
expect(body.advisor.lowRelevanceSeqs).toEqual([5])
|
|
188
|
+
// Content-free: no message text ever rides along.
|
|
189
|
+
expect(response.body).not.toContain('"text"')
|
|
190
|
+
expect(response.body).not.toContain('"content"')
|
|
191
|
+
expect(response.body).not.toContain('apiKey')
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
it('answers an empty report (nulls, not an error) for a session whose advisor never ran', async () => {
|
|
195
|
+
const routes: RegisteredRoute[] = []
|
|
196
|
+
const runtime = new Context()
|
|
197
|
+
ctx = runtime
|
|
198
|
+
await mountWebServer(runtime, routes)
|
|
199
|
+
void runtime.plugin({
|
|
200
|
+
name: 'fake-agents-empty',
|
|
201
|
+
apply(serviceCtx) {
|
|
202
|
+
serviceCtx.provide('agents', {
|
|
203
|
+
get: (id: unknown) => (id === 's1' ? { session: { id: 's1' } } : undefined),
|
|
204
|
+
})
|
|
205
|
+
},
|
|
206
|
+
})
|
|
207
|
+
apply(runtime, { advisorReportRoute: true })
|
|
208
|
+
await settle()
|
|
209
|
+
const route = routes.find(entry => entry.path === REPORT_ROUTE) as RegisteredRoute
|
|
210
|
+
|
|
211
|
+
const response = await invoke(route, { url: `${REPORT_ROUTE}?sessionId=s1` })
|
|
212
|
+
expect(response.status).toBe(200)
|
|
213
|
+
const body = JSON.parse(response.body ?? '{}') as {
|
|
214
|
+
ok: boolean
|
|
215
|
+
advisor: { summary: unknown, decay: unknown, scores: unknown[], lowRelevanceSeqs: unknown[] }
|
|
216
|
+
}
|
|
217
|
+
expect(body.ok).toBe(true)
|
|
218
|
+
expect(body.advisor.summary).toBeNull()
|
|
219
|
+
expect(body.advisor.decay).toBeNull()
|
|
220
|
+
expect(body.advisor.scores).toEqual([])
|
|
221
|
+
expect(body.advisor.lowRelevanceSeqs).toEqual([])
|
|
222
|
+
})
|
|
223
|
+
})
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
4
|
+
import { useSyncExternalStore } from 'react'
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import {
|
|
7
|
+
CompressionProfileSelector,
|
|
8
|
+
ContextCompressionSettingsSection,
|
|
9
|
+
type CompressionProfileSelectorProps,
|
|
10
|
+
type ContextCompressionSettings,
|
|
11
|
+
} from '../src/client/CompressionProfileSelector.tsx'
|
|
12
|
+
import { en } from '../src/client/locales.ts'
|
|
13
|
+
|
|
14
|
+
afterEach(cleanup)
|
|
15
|
+
|
|
16
|
+
interface SettingsScopeSnapshot<T> {
|
|
17
|
+
status: 'loading' | 'ready' | 'unavailable'
|
|
18
|
+
value: T | undefined
|
|
19
|
+
base: T | undefined
|
|
20
|
+
user: T | undefined
|
|
21
|
+
revision: number | undefined
|
|
22
|
+
writable: boolean
|
|
23
|
+
mode: 'host' | 'memory'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface SnapshotStore<T> {
|
|
27
|
+
readonly getSnapshot: () => T
|
|
28
|
+
readonly subscribe: (listener: () => void) => () => void
|
|
29
|
+
readonly update: (recipe: (draft: T) => void) => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function createSnapshotStore<T>(initial: T): SnapshotStore<T> {
|
|
33
|
+
let snapshot = structuredClone(initial)
|
|
34
|
+
const listeners = new Set<() => void>()
|
|
35
|
+
return {
|
|
36
|
+
getSnapshot: () => snapshot,
|
|
37
|
+
subscribe(listener) {
|
|
38
|
+
listeners.add(listener)
|
|
39
|
+
return () => { listeners.delete(listener) }
|
|
40
|
+
},
|
|
41
|
+
update(recipe) {
|
|
42
|
+
const draft = structuredClone(snapshot)
|
|
43
|
+
recipe(draft)
|
|
44
|
+
snapshot = draft
|
|
45
|
+
for (const listener of listeners) listener()
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function bindSnapshotSelector<T>(store: SnapshotStore<T>) {
|
|
51
|
+
return function useSnapshotSelector<U>(selector: (snapshot: T) => U): U {
|
|
52
|
+
return useSyncExternalStore(
|
|
53
|
+
store.subscribe,
|
|
54
|
+
() => selector(store.getSnapshot()),
|
|
55
|
+
() => selector(store.getSnapshot()),
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const DEFAULT_CUSTOM = {
|
|
61
|
+
version: 1,
|
|
62
|
+
unit: 'tokens',
|
|
63
|
+
fresh: { enabled: true, trigger: 4_096, target: 2_048 },
|
|
64
|
+
aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
|
|
65
|
+
history: {
|
|
66
|
+
enabled: true,
|
|
67
|
+
trigger: 32_768,
|
|
68
|
+
keepRecentTurns: 2,
|
|
69
|
+
keepRecent: 16_384,
|
|
70
|
+
minReclaim: 8_192,
|
|
71
|
+
},
|
|
72
|
+
prefixPolicy: 'pressure-break',
|
|
73
|
+
} as const satisfies ContextCompressionSettings['custom']
|
|
74
|
+
|
|
75
|
+
const t = (key: string) => en[key as keyof typeof en] ?? key
|
|
76
|
+
|
|
77
|
+
interface MountOptions {
|
|
78
|
+
readonly value?: ContextCompressionSettings
|
|
79
|
+
readonly saveAutoCompact?: (thresholdPercent: number) => Promise<void>
|
|
80
|
+
readonly settingsSection?: boolean
|
|
81
|
+
readonly writable?: boolean
|
|
82
|
+
readonly status?: 'loading' | 'ready'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function mountAutoCompact(options: MountOptions = {}) {
|
|
86
|
+
const state = createSnapshotStore<SettingsScopeSnapshot<ContextCompressionSettings>>({
|
|
87
|
+
status: options.status ?? 'ready',
|
|
88
|
+
value: options.value ?? {
|
|
89
|
+
profile: 'balanced',
|
|
90
|
+
custom: structuredClone(DEFAULT_CUSTOM),
|
|
91
|
+
autoCompact: { thresholdPercent: 80 },
|
|
92
|
+
codeSkeleton: { enabled: false },
|
|
93
|
+
intentSummary: { enabled: false },
|
|
94
|
+
},
|
|
95
|
+
base: undefined,
|
|
96
|
+
user: undefined,
|
|
97
|
+
revision: 0,
|
|
98
|
+
writable: options.writable ?? true,
|
|
99
|
+
mode: 'host',
|
|
100
|
+
})
|
|
101
|
+
const sessions = createSnapshotStore({
|
|
102
|
+
ids: ['s1'],
|
|
103
|
+
byId: { s1: { id: 's1', displayTitle: 's1', running: false, blank: true, updatedAt: 0, agentPreset: 'standard' } },
|
|
104
|
+
current: 's1',
|
|
105
|
+
phase: 'ready',
|
|
106
|
+
subagentsByParent: {},
|
|
107
|
+
jobsBySession: {},
|
|
108
|
+
currentAddress: undefined,
|
|
109
|
+
})
|
|
110
|
+
const saveAutoCompact = options.saveAutoCompact ?? vi.fn(() => Promise.resolve())
|
|
111
|
+
const Component = options.settingsSection === false ? CompressionProfileSelector : ContextCompressionSettingsSection
|
|
112
|
+
render(<Component {...({
|
|
113
|
+
useCompression: bindSnapshotSelector(state),
|
|
114
|
+
useSessions: bindSnapshotSelector(sessions),
|
|
115
|
+
select: vi.fn(() => Promise.resolve()),
|
|
116
|
+
saveCustom: vi.fn(() => Promise.resolve()),
|
|
117
|
+
resetCustom: vi.fn(() => Promise.resolve()),
|
|
118
|
+
saveAutoCompact,
|
|
119
|
+
t,
|
|
120
|
+
} as unknown as CompressionProfileSelectorProps)} />)
|
|
121
|
+
return { state, saveAutoCompact }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const INPUT_LABEL = 'Auto Compact threshold (%)'
|
|
125
|
+
|
|
126
|
+
describe('Auto Compact threshold controls', () => {
|
|
127
|
+
it('renders the editor only inside the context-compression settings section', () => {
|
|
128
|
+
mountAutoCompact({ settingsSection: true })
|
|
129
|
+
expect(screen.getByLabelText(INPUT_LABEL)).not.toBeNull()
|
|
130
|
+
expect(screen.queryByRole('slider')).toBeNull()
|
|
131
|
+
for (const quick of ['70%', '80%', '85%']) expect(screen.queryByRole('button', { name: quick })).toBeNull()
|
|
132
|
+
|
|
133
|
+
// The compact workspace selector shows a summary, never a second editor.
|
|
134
|
+
cleanup()
|
|
135
|
+
mountAutoCompact({ settingsSection: false })
|
|
136
|
+
expect(screen.queryByLabelText(INPUT_LABEL)).toBeNull()
|
|
137
|
+
expect(screen.queryByRole('slider')).toBeNull()
|
|
138
|
+
expect(screen.getByText(/Auto Compact threshold: 80%/)).not.toBeNull()
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
it('saves a non-quick value like 73 and reads the same value back after remount', async () => {
|
|
142
|
+
const saving = vi.fn((thresholdPercent: number): Promise<void> => {
|
|
143
|
+
mounted.state.update(draft => {
|
|
144
|
+
if (draft.value !== undefined) draft.value.autoCompact = { thresholdPercent }
|
|
145
|
+
})
|
|
146
|
+
return Promise.resolve()
|
|
147
|
+
})
|
|
148
|
+
const mounted = mountAutoCompact({ settingsSection: true, saveAutoCompact: saving })
|
|
149
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '73' } })
|
|
150
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Auto Compact threshold' }))
|
|
151
|
+
await waitFor(() => { expect(mounted.state.getSnapshot().value?.autoCompact).toEqual({ thresholdPercent: 73 }) })
|
|
152
|
+
|
|
153
|
+
// A fresh mount reads the same persisted settings.
|
|
154
|
+
cleanup()
|
|
155
|
+
mountAutoCompact({
|
|
156
|
+
settingsSection: true,
|
|
157
|
+
value: { profile: 'balanced', custom: structuredClone(DEFAULT_CUSTOM), autoCompact: { thresholdPercent: 73 }, codeSkeleton: { enabled: false }, intentSummary: { enabled: false } },
|
|
158
|
+
})
|
|
159
|
+
expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).value).toBe('73')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it.each(['49', '91', '72.5', 'abc', ''])('blocks saving the invalid draft %s', (draft) => {
|
|
163
|
+
const { saveAutoCompact } = mountAutoCompact({ settingsSection: true })
|
|
164
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: draft } })
|
|
165
|
+
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
|
|
166
|
+
expect(screen.getByText(/must be an integer between 50 and 90/)).not.toBeNull()
|
|
167
|
+
expect(saveAutoCompact).not.toHaveBeenCalled()
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('uses the typed number input as the only threshold editor', () => {
|
|
171
|
+
mountAutoCompact({ settingsSection: true })
|
|
172
|
+
const input = screen.getByLabelText<HTMLInputElement>(INPUT_LABEL)
|
|
173
|
+
fireEvent.change(input, { target: { value: '73' } })
|
|
174
|
+
expect(input.value).toBe('73')
|
|
175
|
+
expect(screen.queryByRole('slider')).toBeNull()
|
|
176
|
+
for (const quick of ['70%', '80%', '85%']) expect(screen.queryByRole('button', { name: quick })).toBeNull()
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('explains the risk outside the recommended 70–85 band but keeps saving available', () => {
|
|
180
|
+
mountAutoCompact({ settingsSection: true })
|
|
181
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '65' } })
|
|
182
|
+
expect(screen.getByText(/summarization calls and prefix rebuilds/)).not.toBeNull()
|
|
183
|
+
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(false)
|
|
184
|
+
|
|
185
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '90' } })
|
|
186
|
+
expect(screen.getByText(/shared by requests and output/)).not.toBeNull()
|
|
187
|
+
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(false)
|
|
188
|
+
|
|
189
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '80' } })
|
|
190
|
+
expect(screen.queryByText(/summarization calls and prefix rebuilds/)).toBeNull()
|
|
191
|
+
expect(screen.queryByText(/shared by requests and output/)).toBeNull()
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
it('disables every control while saving or when the scope is not writable', () => {
|
|
195
|
+
const { saveAutoCompact } = mountAutoCompact({ settingsSection: true, status: 'loading' })
|
|
196
|
+
expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).disabled).toBe(true)
|
|
197
|
+
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
|
|
198
|
+
expect(saveAutoCompact).not.toHaveBeenCalled()
|
|
199
|
+
|
|
200
|
+
cleanup()
|
|
201
|
+
mountAutoCompact({ settingsSection: true, writable: false })
|
|
202
|
+
expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).disabled).toBe(true)
|
|
203
|
+
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('shows a failed threshold save inline', async () => {
|
|
207
|
+
const rejected = Promise.reject(new Error('threshold write failed'))
|
|
208
|
+
void rejected.catch(() => {})
|
|
209
|
+
mountAutoCompact({ settingsSection: true, saveAutoCompact: () => rejected })
|
|
210
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '73' } })
|
|
211
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Auto Compact threshold' }))
|
|
212
|
+
await waitFor(() => { expect(screen.getByRole('alert').textContent).toContain('threshold write failed') })
|
|
213
|
+
})
|
|
214
|
+
})
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import * as jsxRuntime from 'react/jsx-runtime'
|
|
5
|
+
import { describe, expect, it } from 'vitest'
|
|
6
|
+
|
|
7
|
+
const artifact = resolve(import.meta.dirname, '../../lib/client.js')
|
|
8
|
+
|
|
9
|
+
describe('built Harness client artifact', () => {
|
|
10
|
+
it('registers a self-contained lazy-CJS factory and injects its CSS', () => {
|
|
11
|
+
const code = readFileSync(artifact, 'utf8')
|
|
12
|
+
let registration: { id: string, factory: (require: (id: string) => unknown) => unknown } | undefined
|
|
13
|
+
const moduleLoader = {
|
|
14
|
+
load(value: typeof registration) {
|
|
15
|
+
registration = value
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(window, '__ModuleLoader__', { configurable: true, value: moduleLoader })
|
|
19
|
+
|
|
20
|
+
expect(() => Function(code)()).not.toThrow()
|
|
21
|
+
expect(registration?.id).toBe('dsh-context-compression-improved')
|
|
22
|
+
|
|
23
|
+
const modules = new Map<string, unknown>([
|
|
24
|
+
['react', React],
|
|
25
|
+
['react/jsx-runtime', jsxRuntime],
|
|
26
|
+
// The current selector only keeps this official package as a side-effect
|
|
27
|
+
// external. A minimal public-module stub proves the artifact asks the
|
|
28
|
+
// Harness loader for it without importing the package's raw CSS in Node.
|
|
29
|
+
['@deepseek-ai/dsh-client-ui-primitives', {}],
|
|
30
|
+
])
|
|
31
|
+
const exported = registration?.factory((id) => {
|
|
32
|
+
if (!modules.has(id)) throw new Error(`unexpected client dependency: ${id}`)
|
|
33
|
+
return modules.get(id)
|
|
34
|
+
}) as { apply?: unknown, inject?: unknown }
|
|
35
|
+
|
|
36
|
+
expect(exported.apply).toBeTypeOf('function')
|
|
37
|
+
// compat-legacy 单版本(audit B8,实跑实证):顶层 inject 只声明六线通用服务;
|
|
38
|
+
// configForms(0.1.7+ 才存在)由 apply 内的 scoped 子注入消费。早期把 configForms
|
|
39
|
+
// 放进顶层 inject 会令 0.1.0-0.1.5 宿主的 cordis 永久 hold 整个 client 模块。
|
|
40
|
+
// 另见 src/client/index.ts 顶注:lazy 化曾与 settings client 激活竞速导致全部
|
|
41
|
+
// 设置入口静默消失,故 slots/locale 仍保持官方声明式 inject。
|
|
42
|
+
expect(exported.inject).toEqual(['slots', 'locale'])
|
|
43
|
+
const style = document.querySelector<HTMLStyleElement>(
|
|
44
|
+
'style[data-plugin-css="dsh-context-compression-improved/CompressionProfileSelector.module.css"]',
|
|
45
|
+
)
|
|
46
|
+
expect(style?.dataset.plugin).toBe('dsh-context-compression-improved')
|
|
47
|
+
expect(style?.textContent).toContain('profileGrid')
|
|
48
|
+
expect(document.querySelectorAll('style[data-plugin-css]').length).toBe(1)
|
|
49
|
+
|
|
50
|
+
registration?.factory((id) => modules.get(id))
|
|
51
|
+
expect(document.querySelectorAll('style[data-plugin-css]').length).toBe(1)
|
|
52
|
+
expect(code).not.toMatch(/^\s*(?:import|export)\s/mu)
|
|
53
|
+
expect(code).not.toMatch(/(?:\/home\/|[A-Za-z]:\\Users\\)/u)
|
|
54
|
+
expect(code).not.toContain('sourceMappingURL')
|
|
55
|
+
})
|
|
56
|
+
})
|