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,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T19/T22:session-file-decode 叶子模块的代次契约与解码链路测试。
|
|
3
|
+
*
|
|
4
|
+
* fixture 策略(T22):
|
|
5
|
+
* - 真实样例:`fixtures/session-v4-dump.jsonl`(284KB,从本机 v4 会话解包样本转码);
|
|
6
|
+
* 测试内 zstd 压缩后走完整解码链,源文件本身只读。
|
|
7
|
+
* - 合成样例:v3/v4 header + 打包行 + provenance 区间,直接在内存构造。
|
|
8
|
+
* - 撕裂尾帧:完整帧 + 尾部截断帧,ZSTD_e_flush 抢救断言。
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
11
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
12
|
+
import { tmpdir } from 'node:os'
|
|
13
|
+
import { join } from 'node:path'
|
|
14
|
+
import { describe, expect, it } from 'vitest'
|
|
15
|
+
import zlib from 'node:zlib'
|
|
16
|
+
import {
|
|
17
|
+
classifyGenerationFilename,
|
|
18
|
+
classifySessionHeader,
|
|
19
|
+
decodeRecordLocal,
|
|
20
|
+
decodeSeqRangesStorage,
|
|
21
|
+
decodeSessionLogBytes,
|
|
22
|
+
generationLogFilename,
|
|
23
|
+
isMigrationStagingFilename,
|
|
24
|
+
parseGenerationLogFilename,
|
|
25
|
+
readSessionGenerations,
|
|
26
|
+
scanZstdFrames,
|
|
27
|
+
type DecodedEvent,
|
|
28
|
+
type OfficialDecoders,
|
|
29
|
+
} from '../../src/runtime/session-file-decode.ts'
|
|
30
|
+
|
|
31
|
+
/** 规范历史代文件名(测试内同样避免 D7 字面量:拼接构造)。 */
|
|
32
|
+
const LEGACY_NAME = `session${'.'}jsonl.zstd`
|
|
33
|
+
|
|
34
|
+
function sessionHeader(version: number): string {
|
|
35
|
+
return JSON.stringify({ type: 'session', version, id: 'session-test', createdAt: 1_700_000_000_000, cwd: '/tmp' })
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 由 header 代次与若干记录行合成一份 zstd 单帧日志(每条一行,seq 由调用方保证连续)。 */
|
|
39
|
+
function synthesizeLog(headerVersion: number | null, rows: readonly string[]): Buffer {
|
|
40
|
+
const headerLine = headerVersion === null ? 'not-json-at-all' : sessionHeader(headerVersion)
|
|
41
|
+
const text = [headerLine, ...rows, ''].join('\n')
|
|
42
|
+
return zlib.zstdCompressSync(Buffer.from(text, 'utf8'))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('session-file-decode / 代次文件名契约', () => {
|
|
46
|
+
it('代次名推导与解析互逆;历史代名按拼接构造(不留 D7 字面量)', () => {
|
|
47
|
+
expect(generationLogFilename(0)).toBe(LEGACY_NAME)
|
|
48
|
+
expect(generationLogFilename(4)).toBe('session.v4.jsonl.zstd')
|
|
49
|
+
expect(parseGenerationLogFilename(LEGACY_NAME)).toBe(0)
|
|
50
|
+
expect(parseGenerationLogFilename('session.v4.jsonl.zstd')).toBe(4)
|
|
51
|
+
expect(parseGenerationLogFilename('session.v12.jsonl', 'none')).toBe(12)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('非法名一律不猜:前导零、.v0、大写 V、错后缀都拒绝', () => {
|
|
55
|
+
expect(parseGenerationLogFilename('session.v0.jsonl.zstd')).toBeUndefined()
|
|
56
|
+
expect(parseGenerationLogFilename('session.v01.jsonl.zstd')).toBeUndefined()
|
|
57
|
+
expect(parseGenerationLogFilename('session.V1.jsonl.zstd')).toBeUndefined()
|
|
58
|
+
expect(parseGenerationLogFilename('session.v1.jsonl.gz.zstd')).toBeUndefined()
|
|
59
|
+
expect(parseGenerationLogFilename('session.v1.backup.jsonl.zstd')).toBeUndefined()
|
|
60
|
+
expect(classifyGenerationFilename('session.v3.jsonl')).toEqual({ version: 3, compression: 'none' })
|
|
61
|
+
expect(classifyGenerationFilename('readme.txt')).toBeUndefined()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('非法代次参数拒绝', () => {
|
|
65
|
+
expect(() => generationLogFilename(-1)).toThrow(/non-negative safe integer/)
|
|
66
|
+
expect(() => generationLogFilename(1.5)).toThrow(/non-negative safe integer/)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('迁移暂存名识别(token 长度可变,只固定形状)', () => {
|
|
70
|
+
expect(isMigrationStagingFilename('session.migration.0123456789abcdef.jsonl.zstd.tmp')).toBe(true)
|
|
71
|
+
expect(isMigrationStagingFilename('session.migration.deadbeef.jsonl.tmp')).toBe(true)
|
|
72
|
+
expect(isMigrationStagingFilename('session.migration.XYZ.jsonl.zstd.tmp')).toBe(false)
|
|
73
|
+
expect(isMigrationStagingFilename('session.v4.jsonl.zstd')).toBe(false)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('readSessionGenerations:目录实测最高代=当前代,只读不猜', async () => {
|
|
77
|
+
const dir = await mkdtemp(join(tmpdir(), 'sfd-gen-'))
|
|
78
|
+
try {
|
|
79
|
+
await writeFile(join(dir, LEGACY_NAME), 'legacy')
|
|
80
|
+
await writeFile(join(dir, 'session.v4.jsonl.zstd'), 'current')
|
|
81
|
+
await writeFile(join(dir, 'session.migration.aabbccddeeff0011.jsonl.zstd.tmp'), 'staging')
|
|
82
|
+
await writeFile(join(dir, 'session.v01.jsonl.zstd'), 'not-canonical')
|
|
83
|
+
const facts = readSessionGenerations(dir)
|
|
84
|
+
expect(facts.canonical.map(a => a.version)).toEqual([0, 4])
|
|
85
|
+
expect(facts.current?.version).toBe(4)
|
|
86
|
+
expect(facts.legacy?.name).toBe(LEGACY_NAME)
|
|
87
|
+
expect(facts.staging).toHaveLength(1)
|
|
88
|
+
expect(facts.legacyOnly).toBe(false)
|
|
89
|
+
// 目录不存在:如实返回空事实,不抛
|
|
90
|
+
const missing = readSessionGenerations(join(dir, 'no-such-dir'))
|
|
91
|
+
expect(missing.canonical).toEqual([])
|
|
92
|
+
} finally {
|
|
93
|
+
await rm(dir, { recursive: true, force: true })
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
describe('session-file-decode / zstd 多帧与撕裂尾帧', () => {
|
|
99
|
+
it('多帧拼接逐帧解码(zstdDecompressSync 整体解只出首帧,帧扫描是必需路径)', () => {
|
|
100
|
+
const frameA = zlib.zstdCompressSync(Buffer.from('{"a":1}\n', 'utf8'))
|
|
101
|
+
const frameB = zlib.zstdCompressSync(Buffer.from('{"b":2}\n', 'utf8'))
|
|
102
|
+
const both = Buffer.concat([frameA, frameB])
|
|
103
|
+
// 官方整体解码只覆盖首帧——这正是要自己做帧扫描的原因
|
|
104
|
+
expect(zlib.zstdDecompressSync(both).toString('utf8')).toBe('{"a":1}\n')
|
|
105
|
+
const scan = scanZstdFrames(both)
|
|
106
|
+
expect(scan.frames).toHaveLength(2)
|
|
107
|
+
expect(scan.tornStart).toBeUndefined()
|
|
108
|
+
const text = scan.frames
|
|
109
|
+
.map(f => zlib.zstdDecompressSync(both.subarray(f.start, f.end)).toString('utf8'))
|
|
110
|
+
.join('')
|
|
111
|
+
expect(text).toBe('{"a":1}\n{"b":2}\n')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('撕裂尾帧:tornStart 定位 + ZSTD_e_flush 抢救部分明文,完整帧不受影响', () => {
|
|
115
|
+
const frameA = zlib.zstdCompressSync(Buffer.from('header-line\n', 'utf8'))
|
|
116
|
+
const frameB = zlib.zstdCompressSync(Buffer.from('tail-line-contents-here\n', 'utf8'))
|
|
117
|
+
const torn = Buffer.concat([frameA, frameB.subarray(0, frameB.length - 3)])
|
|
118
|
+
const scan = scanZstdFrames(torn)
|
|
119
|
+
expect(scan.frames).toHaveLength(1)
|
|
120
|
+
expect(scan.tornStart).toBe(frameA.length)
|
|
121
|
+
const recovered = zlib.zstdDecompressSync(torn.subarray(scan.tornStart!), {
|
|
122
|
+
finishFlush: zlib.constants.ZSTD_e_flush,
|
|
123
|
+
}).toString('utf8')
|
|
124
|
+
expect(recovered.length).toBeGreaterThan(0)
|
|
125
|
+
expect('tail-line-contents-here\n'.startsWith(recovered)).toBe(true)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('非 zstd 明文开头:整段判为撕裂起点、零完整帧(decode 侧按抢救处理)', () => {
|
|
129
|
+
const plain = Buffer.from('{"type":"session"}\n', 'utf8')
|
|
130
|
+
const scan = scanZstdFrames(plain)
|
|
131
|
+
expect(scan.frames).toHaveLength(0)
|
|
132
|
+
expect(scan.tornStart).toBe(0)
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
describe('session-file-decode / 记录解码与 provenance', () => {
|
|
137
|
+
it('打包行解包:text-chunks 展开为 assistant/chunk,dt 为时间增量', () => {
|
|
138
|
+
const row = {
|
|
139
|
+
type: 'text-chunks',
|
|
140
|
+
seq0: 3,
|
|
141
|
+
time0: 100,
|
|
142
|
+
data: { turn: 0, step: 1, index: 2, texts: ['ab', 'cd', 'ef'], dt: [5, 7] },
|
|
143
|
+
}
|
|
144
|
+
const events = decodeRecordLocal(row)
|
|
145
|
+
expect(events.map(e => e.seq)).toEqual([3, 4, 5])
|
|
146
|
+
expect(events.map(e => e.time)).toEqual([100, 105, 112])
|
|
147
|
+
expect(events[0]).toMatchObject({ type: 'assistant/chunk', data: { turn: 0, step: 1 } })
|
|
148
|
+
expect((events[2]!.data as { chunk: Record<string, unknown> }).chunk).toMatchObject({ type: 'text-delta', text: 'ef', index: 2 })
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('tool-call-chunks 用 args 载荷并带 id/name', () => {
|
|
152
|
+
const row = {
|
|
153
|
+
type: 'tool-call-chunks',
|
|
154
|
+
seq0: 0,
|
|
155
|
+
time0: 10,
|
|
156
|
+
data: { turn: 1, step: 0, index: 0, id: 'call-1', name: 'bash', args: ['{"cmd":', '"ls"}'], dt: [1] },
|
|
157
|
+
}
|
|
158
|
+
const events = decodeRecordLocal(row)
|
|
159
|
+
const chunk = events[1]!.data as { chunk: Record<string, unknown> }
|
|
160
|
+
expect(chunk.chunk).toMatchObject({ type: 'tool-call-delta', id: 'call-1', name: 'bash', argumentsDelta: '"ls"}' })
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('打包行形状错误:拒绝(dt 长度不符/载荷非字符串数组)', () => {
|
|
164
|
+
expect(() => decodeRecordLocal({ type: 'text-chunks', seq0: 0, time0: 0, data: { texts: ['a', 'b'], dt: [] } }))
|
|
165
|
+
.toThrow(/dt length/)
|
|
166
|
+
expect(() => decodeRecordLocal({ type: 'text-chunks', seq0: 0, time0: 0, data: { texts: [1, 2], dt: [0] } }))
|
|
167
|
+
.toThrow(/non-empty string array/)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('provenance 区间编码展开 + 前向引用校验', () => {
|
|
171
|
+
expect(decodeSeqRangesStorage([[0, 2], 5], 6)).toEqual([0, 1, 2, 5])
|
|
172
|
+
expect(() => decodeSeqRangesStorage([[3, 1]], 6)).toThrow(/malformed/)
|
|
173
|
+
expect(() => decodeSeqRangesStorage([6], 6)).toThrow(/reference earlier/)
|
|
174
|
+
expect(() => decodeSeqRangesStorage('x', 6)).toThrow(/must be an array/)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('seq 缺口按 prefix 语义截断并记问题', () => {
|
|
178
|
+
const rows = [
|
|
179
|
+
JSON.stringify({ type: 'user/message', seq: 0, time: 1, data: {} }),
|
|
180
|
+
JSON.stringify({ type: 'user/message', seq: 2, time: 2, data: {} }), // 缺 seq 1
|
|
181
|
+
]
|
|
182
|
+
const log = decodeSessionLogBytes(synthesizeLog(4, rows))
|
|
183
|
+
expect(log.events).toHaveLength(1)
|
|
184
|
+
expect(log.issues).toHaveLength(1)
|
|
185
|
+
expect(log.issues[0]!.why).toMatch(/seq gap \(expected 1, got 2\)/)
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
it('官方解码器可用时走 official 臂且来源如实标注', () => {
|
|
189
|
+
const official: OfficialDecoders = {
|
|
190
|
+
decodeStorageRecord: value => [value as DecodedEvent],
|
|
191
|
+
decodeSeqRanges: (value, seq) => decodeSeqRangesStorage(value, seq),
|
|
192
|
+
}
|
|
193
|
+
const rows = [
|
|
194
|
+
JSON.stringify({ type: 'user/message', seq: 0, time: 1, data: {} }),
|
|
195
|
+
JSON.stringify({ type: 'tool/result', seq: 1, time: 2, sourceEventSeqs: [[0, 0]], data: {} }),
|
|
196
|
+
]
|
|
197
|
+
const log = decodeSessionLogBytes(synthesizeLog(4, rows), official)
|
|
198
|
+
expect(log.decoder).toBe('official')
|
|
199
|
+
expect(log.events).toHaveLength(2)
|
|
200
|
+
expect(log.events[1]?.sourceEventSeqs).toEqual([0])
|
|
201
|
+
const local = decodeSessionLogBytes(synthesizeLog(4, rows))
|
|
202
|
+
expect(local.decoder).toBe('local')
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('findOpenStep:尾部未收尾的 step 报出,step/end 后清零', () => {
|
|
206
|
+
const rows = [
|
|
207
|
+
JSON.stringify({ type: 'step/start', seq: 0, time: 1, data: { turn: 2, step: 3 } }),
|
|
208
|
+
JSON.stringify({ type: 'step/end', seq: 1, time: 2, data: { turn: 2, step: 3 } }),
|
|
209
|
+
JSON.stringify({ type: 'step/start', seq: 2, time: 3, data: { turn: 2, step: 4 } }),
|
|
210
|
+
]
|
|
211
|
+
const log = decodeSessionLogBytes(synthesizeLog(4, rows))
|
|
212
|
+
expect(log.openStep).toEqual({ turn: 2, step: 4 })
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
describe('session-file-decode / header 代次 fail-soft 分类', () => {
|
|
217
|
+
it('v3/v4 已知代次放行', () => {
|
|
218
|
+
for (const version of [3, 4]) {
|
|
219
|
+
const log = decodeSessionLogBytes(synthesizeLog(version, []))
|
|
220
|
+
expect(classifySessionHeader(log.header)).toMatchObject({ state: 'known', version })
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('未知代次/无 header/非 session 头都归为不可回填(调用方跳过该会话)', () => {
|
|
225
|
+
const unknown = decodeSessionLogBytes(synthesizeLog(9, []))
|
|
226
|
+
expect(classifySessionHeader(unknown.header)).toMatchObject({ state: 'unknown-version', version: 9 })
|
|
227
|
+
// 首行不是 zstd 可解内容:整体抢救失败也不抛,header 如实缺失
|
|
228
|
+
const broken = decodeSessionLogBytes(Buffer.from('not-json-at-all\n', 'utf8'))
|
|
229
|
+
expect(classifySessionHeader(broken.header)).toEqual({ state: 'missing-header' })
|
|
230
|
+
const foreign = decodeSessionLogBytes(synthesizeLog(4, []))
|
|
231
|
+
expect(classifySessionHeader({ ...foreign.header!, type: 'other' })).toEqual({ state: 'not-session' })
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
it('空文件:header 缺失、零事件、零问题(不抛)', () => {
|
|
235
|
+
const log = decodeSessionLogBytes(Buffer.alloc(0))
|
|
236
|
+
expect(log).toMatchObject({ events: [], frames: 0, recoveredFromTorn: 0, issues: [], decoder: 'local' })
|
|
237
|
+
expect(classifySessionHeader(log.header)).toEqual({ state: 'missing-header' })
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
describe('session-file-decode / 真实 v4 解包样本', () => {
|
|
242
|
+
const fixture = new URL('fixtures/session-v4-dump.jsonl', import.meta.url)
|
|
243
|
+
const present = existsSync(fixture)
|
|
244
|
+
|
|
245
|
+
it.skipIf(!present)('真实会话(v4 header + 45 事件)转码为 zstd 后完整解码、零问题', () => {
|
|
246
|
+
const text = readFileSync(fixture, 'utf8')
|
|
247
|
+
const log = decodeSessionLogBytes(zlib.zstdCompressSync(Buffer.from(text, 'utf8')))
|
|
248
|
+
expect(classifySessionHeader(log.header)).toMatchObject({ state: 'known', version: 4 })
|
|
249
|
+
expect(log.events.length).toBeGreaterThan(40)
|
|
250
|
+
expect(log.issues).toEqual([])
|
|
251
|
+
expect(log.frames).toBeGreaterThanOrEqual(1)
|
|
252
|
+
expect(log.tornStart).toBeUndefined()
|
|
253
|
+
// seq 连续(0..n-1)由解码链的 prefix 语义保证:无 issue 即连续
|
|
254
|
+
expect(log.events.at(-1)!.seq).toBe(log.events.length - 1)
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it.skipIf(!present)('真实样本多帧切分后再拼接解码结果一致', () => {
|
|
258
|
+
const text = readFileSync(fixture, 'utf8')
|
|
259
|
+
const whole = zlib.zstdCompressSync(Buffer.from(text, 'utf8'))
|
|
260
|
+
const half = Math.floor(text.length / 2)
|
|
261
|
+
const multi = Buffer.concat([
|
|
262
|
+
zlib.zstdCompressSync(Buffer.from(text.slice(0, half), 'utf8')),
|
|
263
|
+
zlib.zstdCompressSync(Buffer.from(text.slice(half), 'utf8')),
|
|
264
|
+
])
|
|
265
|
+
const a = decodeSessionLogBytes(whole)
|
|
266
|
+
const b = decodeSessionLogBytes(multi)
|
|
267
|
+
expect(b.frames).toBeGreaterThanOrEqual(2)
|
|
268
|
+
expect(b.issues).toEqual([])
|
|
269
|
+
expect(b.events).toEqual(a.events)
|
|
270
|
+
expect(b.header).toEqual(a.header)
|
|
271
|
+
})
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
describe('session-file-decode / D7 静态纪律', () => {
|
|
275
|
+
it('模块源码不含检查器正则的连续字面量', () => {
|
|
276
|
+
const source = readFileSync(new URL('../../src/runtime/session-file-decode.ts', import.meta.url), 'utf8')
|
|
277
|
+
expect(source).not.toMatch(/session\.jsonl|SESSION_FORMAT_VERSION|sessionFormatVersion/u)
|
|
278
|
+
// 用等价文本正则再扫一遍(点为真实点),防止拼接改写引入漏网
|
|
279
|
+
expect(/session[.]jsonl/.test(source)).toBe(false)
|
|
280
|
+
})
|
|
281
|
+
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { unwrapSettingsEntry } from '../../src/pruner.ts'
|
|
3
|
+
import { parseContextCompressionSettings } from '../../src/runtime/config.ts'
|
|
4
|
+
|
|
5
|
+
// The desktop 0.2.0 host hands back the whole entry config `{ settings: <subtree> }`;
|
|
6
|
+
// the parser only understands the subtree. Regression guard for the fail-open-to-off
|
|
7
|
+
// bug that silently disabled fresh/aggregate on the desktop (0 compression).
|
|
8
|
+
const SUBTREE = {
|
|
9
|
+
profile: 'tokenpilot-inspired',
|
|
10
|
+
custom: {
|
|
11
|
+
version: 3,
|
|
12
|
+
unit: 'tokens',
|
|
13
|
+
fresh: { enabled: true, trigger: 8192, target: 3072 },
|
|
14
|
+
aggregate: { enabled: true, trigger: 32768, target: 12288 },
|
|
15
|
+
history: { enabled: true, trigger: 500000, keepRecentToolCalls: 10, keepRecentTokens: 64000, minReclaim: 96000 },
|
|
16
|
+
prefixPolicy: 'pressure-break',
|
|
17
|
+
tailTrim: { enabled: false, trigger: 700000 },
|
|
18
|
+
},
|
|
19
|
+
autoCompact: { thresholdPercent: 80 },
|
|
20
|
+
codeSkeleton: { enabled: true },
|
|
21
|
+
intentSummary: { enabled: true },
|
|
22
|
+
monitorPanel: { enabled: true },
|
|
23
|
+
presetOptions: { estimatorMode: 'host', estimatorProvider: 'local-35', estimatorModel: 'Qwen3.6-35B-A3B' },
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('unwrapSettingsEntry (0.2.0 host config wrapper)', () => {
|
|
27
|
+
it('descends a single {settings:<obj>} wrapper when the root has no profile', () => {
|
|
28
|
+
expect(unwrapSettingsEntry({ settings: SUBTREE })).toBe(SUBTREE)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('leaves a bare subtree (root already has profile) untouched', () => {
|
|
32
|
+
expect(unwrapSettingsEntry(SUBTREE)).toBe(SUBTREE)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('leaves non-object and array values untouched', () => {
|
|
36
|
+
expect(unwrapSettingsEntry(undefined)).toBe(undefined)
|
|
37
|
+
expect(unwrapSettingsEntry(null)).toBe(null)
|
|
38
|
+
expect(unwrapSettingsEntry('x')).toBe('x')
|
|
39
|
+
const arr = [1, 2]
|
|
40
|
+
expect(unwrapSettingsEntry(arr)).toBe(arr)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('does NOT descend when `settings` is not an object (keeps exotic rejection intact)', () => {
|
|
44
|
+
const exotic = { settings: 'not-an-object' }
|
|
45
|
+
expect(unwrapSettingsEntry(exotic)).toBe(exotic)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('round-trips the wrapped desktop value where the bare parse would throw', () => {
|
|
49
|
+
// The exact desktop failure: wrapped shape → parse throws "missing its
|
|
50
|
+
// complete shape" → activeSettings fails open to profile:'off'. After the
|
|
51
|
+
// one-level unwrap the same value parses to tokenpilot-inspired (fresh on).
|
|
52
|
+
const wrapped = { settings: SUBTREE }
|
|
53
|
+
expect(() => parseContextCompressionSettings(wrapped)).toThrow(/complete shape|plain/)
|
|
54
|
+
const parsed = parseContextCompressionSettings(unwrapSettingsEntry(wrapped) as never)
|
|
55
|
+
expect(parsed.profile).toBe('tokenpilot-inspired')
|
|
56
|
+
expect(parsed.presetOptions?.estimatorMode).toBe('host')
|
|
57
|
+
})
|
|
58
|
+
})
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T4.7/T4.8/T4.11/T4.12 red tests: shallow primitives and tool-side pure cores
|
|
3
|
+
* (plan cci-sedimentation-triage Phase 4.5).
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it } from 'vitest'
|
|
6
|
+
import {
|
|
7
|
+
buildShallowFooter,
|
|
8
|
+
classifyShallowSample,
|
|
9
|
+
evaluateDiscardGuard,
|
|
10
|
+
normalizeToolPath,
|
|
11
|
+
renderCheckpointLine,
|
|
12
|
+
} from '../../src/runtime/triage/shallow.ts'
|
|
13
|
+
import { buildShallowView, parseReadCoverage } from '../../src/runtime/shallow-tools.ts'
|
|
14
|
+
import { skeletonFromRead } from '../../src/runtime/triage/masks.ts'
|
|
15
|
+
|
|
16
|
+
describe('normalizeToolPath (pairing key, three shapes)', () => {
|
|
17
|
+
it('unifies drive letters, separators, and relative segments', () => {
|
|
18
|
+
expect(normalizeToolPath('E:\\Repo\\A\\b.ts')).toBe('e:/Repo/A/b.ts')
|
|
19
|
+
expect(normalizeToolPath('./src/app.ts')).toBe('src/app.ts')
|
|
20
|
+
expect(normalizeToolPath('src/../src/app.ts')).toBe('src/app.ts')
|
|
21
|
+
expect(normalizeToolPath('E:/Repo//A/./b.ts')).toBe('e:/Repo/A/b.ts')
|
|
22
|
+
// case of the path TAIL is preserved (filesystems may be case-sensitive)
|
|
23
|
+
expect(normalizeToolPath('e:/repo/App.TS')).toBe('e:/repo/App.TS')
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('classifyShallowSample (T4.12 five families)', () => {
|
|
28
|
+
it('routes JSON / TS source / CSV / markdown / unknown-large correctly', () => {
|
|
29
|
+
expect(classifyShallowSample('{"a":1', '.json', 9_000).method).toBe('json-skeleton')
|
|
30
|
+
expect(classifyShallowSample('import x from "y"\n', '.ts', 9_000).method).toBe('code-skeleton')
|
|
31
|
+
expect(classifyShallowSample('name,size\na,1\nb,2\nc,3', '.csv', 9_000).method).toBe('csv-header')
|
|
32
|
+
expect(classifyShallowSample('# Title\nbody', '.md', 9_000).method).toBe('toc-lines')
|
|
33
|
+
expect(classifyShallowSample('random bytes', '.bin', 9_000).method).toBe('toc-lines')
|
|
34
|
+
expect(classifyShallowSample('tiny', '', 30).method).toBe('head-tail')
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
describe('evaluateDiscardGuard (T4.7 asymmetric guard)', () => {
|
|
39
|
+
const mapFull = { seq: 10, path: 'E:\\repo\\big.ts', coverage: { kind: 'full' } as const }
|
|
40
|
+
|
|
41
|
+
it('refuses map discard when the covering read is a slice (window-gap and full-map shapes)', () => {
|
|
42
|
+
expect(evaluateDiscardGuard({
|
|
43
|
+
map: mapFull,
|
|
44
|
+
covering: { seq: 20, path: 'e:/repo/big.ts', coverage: { kind: 'slice', from: 100, to: 300 } },
|
|
45
|
+
}).allowed).toBe(false)
|
|
46
|
+
})
|
|
47
|
+
it('allows map discard under a full covering read, path case/shape differing', () => {
|
|
48
|
+
const verdict = evaluateDiscardGuard({
|
|
49
|
+
map: mapFull,
|
|
50
|
+
covering: { seq: 20, path: 'E:/repo/big.ts', coverage: { kind: 'full' } },
|
|
51
|
+
})
|
|
52
|
+
expect(verdict.allowed).toBe(true)
|
|
53
|
+
})
|
|
54
|
+
it('window containment for a map that covers a window', () => {
|
|
55
|
+
const mapWindow = { seq: 10, path: 'a.ts', coverage: { kind: 'slice', from: 50, to: 150 } as const }
|
|
56
|
+
expect(evaluateDiscardGuard({
|
|
57
|
+
map: mapWindow,
|
|
58
|
+
covering: { seq: 20, path: 'a.ts', coverage: { kind: 'slice', from: 40, to: 160 } },
|
|
59
|
+
}).allowed).toBe(true)
|
|
60
|
+
expect(evaluateDiscardGuard({
|
|
61
|
+
map: mapWindow,
|
|
62
|
+
covering: { seq: 20, path: 'a.ts', coverage: { kind: 'slice', from: 60, to: 140 } },
|
|
63
|
+
}).allowed).toBe(false)
|
|
64
|
+
})
|
|
65
|
+
it('path mismatch refuses before any coverage math', () => {
|
|
66
|
+
expect(evaluateDiscardGuard({
|
|
67
|
+
map: mapFull,
|
|
68
|
+
covering: { seq: 20, path: 'e:/repo/other.ts', coverage: { kind: 'full' } },
|
|
69
|
+
}).reason).toContain('path-mismatch')
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('buildShallowView (T4.11 checkpoint layer)', () => {
|
|
74
|
+
const code = `import fs from "node:fs"\n${' const v = compute()\n'.repeat(200)}export function go() { return 1 }`
|
|
75
|
+
|
|
76
|
+
it('code-skeleton view carries the four checkpoint fields', () => {
|
|
77
|
+
const { body, checkpoint } = buildShallowView(code, 'code-skeleton', 'E:\\src\\big.ts', 77)
|
|
78
|
+
expect(body).toContain('import fs')
|
|
79
|
+
expect(body).toContain('elided')
|
|
80
|
+
expect(checkpoint).not.toBeNull()
|
|
81
|
+
expect(checkpoint?.path).toBe('e:/src/big.ts')
|
|
82
|
+
expect(checkpoint?.coverage).toContain('lines')
|
|
83
|
+
expect(checkpoint?.ref).toBe('event/77')
|
|
84
|
+
expect(checkpoint?.fingerprint).toMatch(/^[0-9a-f]+-[0-9a-f]+$/)
|
|
85
|
+
})
|
|
86
|
+
it('json-skeleton lists keys, csv-header keeps rows count, toc-lines keeps headings', () => {
|
|
87
|
+
const json = buildShallowView(JSON.stringify({ a: { b: 1 }, list: [1, 2] }), 'json-skeleton', 'x.json', 1)
|
|
88
|
+
expect(json.body).toContain('a.b')
|
|
89
|
+
expect(json.body).toContain('list[] (2)')
|
|
90
|
+
const csv = buildShallowView('h1,h2\n1,2\n3,4\n5,6', 'csv-header', 'x.csv', 1)
|
|
91
|
+
expect(csv.body).toContain('1 data rows elided')
|
|
92
|
+
const md = buildShallowView('# A\ntext\n## B\nmore', 'toc-lines', 'x.md', 1)
|
|
93
|
+
expect(md.body).toContain('## B')
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
describe('parseReadCoverage (pairing input)', () => {
|
|
98
|
+
it('bare read is full; offset/limit is a window; broken args match nothing', () => {
|
|
99
|
+
expect(parseReadCoverage(JSON.stringify({ file_path: 'a.ts' }))).toEqual({ kind: 'full' })
|
|
100
|
+
expect(parseReadCoverage(JSON.stringify({ file_path: 'a.ts', offset: 100, limit: 50 })))
|
|
101
|
+
.toEqual({ kind: 'slice', from: 101, to: 150 })
|
|
102
|
+
expect(parseReadCoverage('{broken')).toMatchObject({ kind: 'slice', to: 0 })
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
describe('footer and checkpoint rendering (T4.8 data-shaped teaching)', () => {
|
|
107
|
+
const checkpoint = {
|
|
108
|
+
path: 'e:/src/big.ts', coverage: '900 lines', ref: 'session://s1/event/77', fingerprint: '3c-91',
|
|
109
|
+
}
|
|
110
|
+
it('footer names the sibling ref, the saving, and forbids reconstitution', () => {
|
|
111
|
+
const footer = buildShallowFooter(checkpoint, 1_800)
|
|
112
|
+
expect(footer).toContain('session://s1/event/77')
|
|
113
|
+
expect(footer).toContain('1800')
|
|
114
|
+
expect(footer).toContain('不要凭本行推测补写')
|
|
115
|
+
})
|
|
116
|
+
it('checkpoint line keeps all four fields on one line', () => {
|
|
117
|
+
const line = renderCheckpointLine(checkpoint)
|
|
118
|
+
for (const part of ['e:/src/big.ts', '900 lines', 'session://s1/event/77', '3c-91']) {
|
|
119
|
+
expect(line).toContain(part)
|
|
120
|
+
}
|
|
121
|
+
expect(line.split('\n')).toHaveLength(1)
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
describe('skeletonFromRead checkpoint back-compat', () => {
|
|
126
|
+
const padded = `import fs from "node:fs"\n${' const x = 1\n'.repeat(400)}`
|
|
127
|
+
it('stays checkpoint-free without a path (existing callers unaffected)', () => {
|
|
128
|
+
const verdict = skeletonFromRead(padded, 5)
|
|
129
|
+
expect(verdict?.kind === 'skeleton' && verdict.checkpoint === undefined).toBe(true)
|
|
130
|
+
})
|
|
131
|
+
it('gains the checkpoint with a path', () => {
|
|
132
|
+
const verdict = skeletonFromRead(padded, 5, 'src/a.ts')
|
|
133
|
+
expect(verdict?.kind === 'skeleton' && verdict.checkpoint?.path).toBe('src/a.ts')
|
|
134
|
+
})
|
|
135
|
+
})
|