dsh-context-compression-improved 0.11.1 → 0.11.2
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/README.md +15 -110
- package/README.zh.md +14 -104
- package/THIRD_PARTY_NOTICES.md +25 -7
- package/{packages/selector/dsh.plugin.json → dsh.plugin.json} +1 -1
- package/{packages/selector/lib → lib}/index.js +101 -0
- package/package.json +125 -112
- package/screenshots.json +3 -6
- package/.agents/plans/improve/checklist.md +0 -32
- package/.agents/plans/improve/findings.md +0 -102
- package/.agents/plans/improve/spec.md +0 -53
- package/.agents/plans/improve/tasks.md +0 -70
- package/.gitattributes +0 -2
- package/.githooks/pre-push +0 -37
- package/.github/workflows/ci.yml +0 -47
- package/CHANGELOG.de.md +0 -580
- package/CHANGELOG.es.md +0 -588
- package/CHANGELOG.fr.md +0 -576
- package/CHANGELOG.it.md +0 -577
- package/CHANGELOG.ja.md +0 -261
- package/CHANGELOG.ko.md +0 -254
- package/CHANGELOG.md +0 -557
- package/CHANGELOG.ru.md +0 -554
- package/CHANGELOG.zh.md +0 -247
- package/CONTRIBUTING.md +0 -22
- package/README.de.md +0 -96
- package/README.es.md +0 -96
- package/README.fr.md +0 -96
- package/README.it.md +0 -96
- package/README.ja.md +0 -102
- package/README.ko.md +0 -102
- package/README.ru.md +0 -96
- package/SECURITY.md +0 -18
- package/assets/board.png +0 -0
- package/assets/context.png +0 -0
- package/assets/dshfind-card.svg +0 -33
- 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 +0 -77
- package/docs/installation.de.md +0 -104
- package/docs/installation.es.md +0 -104
- package/docs/installation.fr.md +0 -104
- package/docs/installation.it.md +0 -104
- package/docs/installation.ja.md +0 -78
- package/docs/installation.ko.md +0 -78
- package/docs/installation.md +0 -103
- package/docs/installation.ru.md +0 -104
- package/docs/installation.zh.md +0 -100
- package/docs/repair-log.md +0 -657
- package/docs/shallow-teaching-preset-template.md +0 -46
- package/eslint.config.js +0 -30
- package/packages/selector/LICENSE +0 -21
- package/packages/selector/README.md +0 -26
- package/packages/selector/README.zh.md +0 -24
- package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
- package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
- package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
- package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
- package/packages/selector/lib/style.css +0 -350
- package/packages/selector/package.json +0 -178
- package/packages/selector/screenshots.json +0 -3
- package/packages/selector/src/client/CompressionProfileControls.tsx +0 -352
- package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
- package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -89
- package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
- package/packages/selector/src/client/EstimatorControls.tsx +0 -277
- package/packages/selector/src/client/bridge-scope.ts +0 -125
- package/packages/selector/src/client/decode.ts +0 -68
- package/packages/selector/src/client/fab-pos.ts +0 -71
- package/packages/selector/src/client/index.ts +0 -438
- package/packages/selector/src/client/locales/de.ts +0 -167
- package/packages/selector/src/client/locales/es.ts +0 -167
- package/packages/selector/src/client/locales/fr.ts +0 -167
- package/packages/selector/src/client/locales/it.ts +0 -167
- package/packages/selector/src/client/locales/ja.ts +0 -167
- package/packages/selector/src/client/locales/ko.ts +0 -167
- package/packages/selector/src/client/locales/ru.ts +0 -167
- package/packages/selector/src/client/locales.ts +0 -334
- package/packages/selector/src/client/monitor-fab.ts +0 -445
- package/packages/selector/src/client/preset-options.ts +0 -88
- package/packages/selector/src/client/savings-card.tsx +0 -269
- package/packages/selector/src/client/scope-face.ts +0 -24
- package/packages/selector/src/client/settings-section.tsx +0 -156
- package/packages/selector/src/compat/host-generation.ts +0 -96
- package/packages/selector/src/compat/llm-messages.ts +0 -50
- package/packages/selector/src/compat/settings-lease.ts +0 -108
- package/packages/selector/src/compat/tool-result.ts +0 -91
- package/packages/selector/src/css-modules.d.ts +0 -6
- package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
- package/packages/selector/src/estimator-catalog.ts +0 -104
- package/packages/selector/src/index.ts +0 -890
- package/packages/selector/src/invariant.ts +0 -113
- package/packages/selector/src/preset-overlay.ts +0 -749
- package/packages/selector/src/profiles.ts +0 -554
- package/packages/selector/src/pruner/content.ts +0 -199
- package/packages/selector/src/pruner/session.ts +0 -97
- package/packages/selector/src/pruner/state.ts +0 -61
- package/packages/selector/src/pruner/tuning.ts +0 -23
- package/packages/selector/src/pruner/types.ts +0 -78
- package/packages/selector/src/pruner.ts +0 -3222
- package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
- package/packages/selector/src/runtime/audit.ts +0 -321
- package/packages/selector/src/runtime/config.ts +0 -887
- package/packages/selector/src/runtime/custom-policy.ts +0 -300
- package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
- package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
- package/packages/selector/src/runtime/display-prefs.ts +0 -98
- package/packages/selector/src/runtime/fold-router.ts +0 -143
- package/packages/selector/src/runtime/measurement.ts +0 -444
- package/packages/selector/src/runtime/monitor.ts +0 -341
- package/packages/selector/src/runtime/panel-command.ts +0 -213
- package/packages/selector/src/runtime/reducers.ts +0 -1755
- package/packages/selector/src/runtime/retrieve.ts +0 -505
- package/packages/selector/src/runtime/savings-integral.ts +0 -117
- package/packages/selector/src/runtime/savings-projection.ts +0 -229
- package/packages/selector/src/runtime/savings-verify.ts +0 -446
- package/packages/selector/src/runtime/savings.ts +0 -526
- package/packages/selector/src/runtime/sediment-card.ts +0 -126
- package/packages/selector/src/runtime/sediment-clock.ts +0 -87
- package/packages/selector/src/runtime/sediment-guard.ts +0 -136
- package/packages/selector/src/runtime/sediment-publish.ts +0 -144
- package/packages/selector/src/runtime/sediment-span.ts +0 -170
- package/packages/selector/src/runtime/sediment.ts +0 -209
- package/packages/selector/src/runtime/session-events.ts +0 -30
- package/packages/selector/src/runtime/session-file-decode.ts +0 -523
- package/packages/selector/src/runtime/shallow-tools.ts +0 -342
- package/packages/selector/src/runtime/stats-backfill.ts +0 -541
- package/packages/selector/src/runtime/stats-db.ts +0 -492
- package/packages/selector/src/runtime/stats-schema.ts +0 -123
- package/packages/selector/src/runtime/stats-sync.ts +0 -307
- package/packages/selector/src/runtime/summary-command.ts +0 -127
- package/packages/selector/src/runtime/tail-trim.ts +0 -177
- package/packages/selector/src/runtime/token-count.ts +0 -72
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -82
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
- package/packages/selector/src/runtime/tokenpilot/locator.ts +0 -129
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
- package/packages/selector/src/runtime/tool-names.ts +0 -42
- package/packages/selector/src/runtime/toolclass.ts +0 -103
- package/packages/selector/src/runtime/triage/masks.ts +0 -128
- package/packages/selector/src/runtime/triage/shallow.ts +0 -132
- package/packages/selector/src/runtime/triage/signals.ts +0 -167
- package/packages/selector/src/runtime/triage/types.ts +0 -125
- package/packages/selector/src/runtime/types.ts +0 -396
- package/packages/selector/src/runtime/value.ts +0 -48
- package/packages/selector/src/settings-bridge.ts +0 -175
- package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
- package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
- package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
- package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
- package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
- package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
- package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
- package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
- package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -202
- package/packages/selector/tests/fab-pos.client.spec.ts +0 -47
- package/packages/selector/tests/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +0 -231
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +0 -236
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +0 -220
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +0 -140
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +0 -117
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +0 -67
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +0 -119
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +0 -119
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +0 -131
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +0 -196
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +0 -71
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +0 -126
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +0 -86
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +0 -50
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +0 -102
- package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
- package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
- package/packages/selector/tests/monitor-fab.client.spec.ts +0 -240
- package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
- package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
- package/packages/selector/tests/profiles.client.spec.tsx +0 -436
- package/packages/selector/tests/ptc-custom-write.client.spec.ts +0 -86
- package/packages/selector/tests/public/package-contract.client.spec.ts +0 -89
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
- package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
- package/packages/selector/tests/runtime/audit.spec.ts +0 -275
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
- package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
- package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
- package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
- package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
- package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +0 -46
- package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
- package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
- package/packages/selector/tests/runtime/fold-router.spec.ts +0 -140
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
- package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
- package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
- package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
- package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
- package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +0 -79
- package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
- package/packages/selector/tests/runtime/monitor.spec.ts +0 -354
- package/packages/selector/tests/runtime/panel-command.spec.ts +0 -101
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
- package/packages/selector/tests/runtime/ptc-profile.spec.ts +0 -133
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2795
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
- package/packages/selector/tests/runtime/savings-accounting.spec.ts +0 -291
- package/packages/selector/tests/runtime/savings-integral.spec.ts +0 -169
- package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
- package/packages/selector/tests/runtime/savings-verify.spec.ts +0 -226
- package/packages/selector/tests/runtime/savings.spec.ts +0 -139
- package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
- package/packages/selector/tests/runtime/sediment-card.spec.ts +0 -111
- package/packages/selector/tests/runtime/sediment-config.spec.ts +0 -56
- package/packages/selector/tests/runtime/sediment-guard.spec.ts +0 -71
- package/packages/selector/tests/runtime/sediment-masks.spec.ts +0 -95
- package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +0 -166
- package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +0 -65
- package/packages/selector/tests/runtime/sediment-publish.spec.ts +0 -142
- package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +0 -158
- package/packages/selector/tests/runtime/sediment-settings.spec.ts +0 -73
- package/packages/selector/tests/runtime/sediment-signals.spec.ts +0 -124
- package/packages/selector/tests/runtime/sediment-span.spec.ts +0 -92
- package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
- package/packages/selector/tests/runtime/session-file-decode.spec.ts +0 -281
- package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
- package/packages/selector/tests/runtime/shallow-primitives.spec.ts +0 -135
- package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
- package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +0 -167
- package/packages/selector/tests/runtime/stats-backfill.spec.ts +0 -350
- package/packages/selector/tests/runtime/stats-db.spec.ts +0 -361
- package/packages/selector/tests/runtime/stats-privacy.spec.ts +0 -55
- package/packages/selector/tests/runtime/stats-sync.spec.ts +0 -278
- package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
- package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
- package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
- package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -121
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
- package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
- package/packages/selector/tests/runtime/value.spec.ts +0 -23
- package/packages/selector/tests/savings-sessions.client.spec.tsx +0 -140
- package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
- package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
- package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
- package/packages/selector/tests/support/mock-adapter.ts +0 -37
- package/packages/selector/tests/support/ui-primitives.tsx +0 -34
- package/packages/selector/tsconfig.json +0 -11
- package/packages/selector/tsdown.client.config.ts +0 -102
- package/packages/selector/tsdown.config.ts +0 -20
- package/pnpm-workspace.yaml +0 -76
- package/scripts/capture-profile-baseline.mjs +0 -42
- package/scripts/cell-browser-e2e.mjs +0 -354
- package/scripts/generate-tokenizer-fixtures.py +0 -81
- package/scripts/generate-vision-fixtures.py +0 -208
- package/scripts/hosts.d.mts +0 -3
- package/scripts/hosts.mjs +0 -81
- package/scripts/packed-components-smoke.mjs +0 -763
- package/scripts/packed-install-e2e.mjs +0 -1346
- package/scripts/sediment-latency-report.mjs +0 -63
- package/scripts/sync-hosts.mjs +0 -174
- package/scripts/toolclass-corpus-replay.mjs +0 -281
- package/scripts/verify-release.mjs +0 -343
- package/tests/TEST_INVENTORY.md +0 -41
- package/tsconfig.base.json +0 -18
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -15
- package/vitest.built.config.ts +0 -9
- package/vitest.config.ts +0 -54
- /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
- /package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +0 -0
- /package/{packages/selector/lib → lib}/client.d.ts +0 -0
- /package/{packages/selector/lib → lib}/client.js +0 -0
- /package/{packages/selector/lib → lib}/index.d.ts +0 -0
- /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
- /package/{packages/selector/lib → lib}/invariant.js +0 -0
- /package/{packages/selector/lib → lib}/profiles.d.ts +0 -0
- /package/{packages/selector/lib → lib}/pruner.d.ts +0 -0
- /package/{packages/selector/lib → lib}/pruner.js +0 -0
- /package/{packages/selector/lib → lib}/savings-integral.js +0 -0
- /package/{packages/selector/lib → lib}/tail-trim.js +0 -0
- /package/{packages/selector/lib → lib}/tool-result.js +0 -0
|
@@ -1,554 +0,0 @@
|
|
|
1
|
-
/** Public context-compression choices shared by the Host schema and browser selector. */
|
|
2
|
-
export const COMPRESSION_PROFILES = [
|
|
3
|
-
'off',
|
|
4
|
-
'native',
|
|
5
|
-
'balanced',
|
|
6
|
-
'cache-strict',
|
|
7
|
-
'savings',
|
|
8
|
-
'adaptive',
|
|
9
|
-
'tokenpilot-inspired',
|
|
10
|
-
'ptc',
|
|
11
|
-
'custom',
|
|
12
|
-
] as const
|
|
13
|
-
|
|
14
|
-
/** One supported context-compression profile. */
|
|
15
|
-
export type CompressionProfile = typeof COMPRESSION_PROFILES[number]
|
|
16
|
-
|
|
17
|
-
/** Single canonical unit stored by a version-1 browser Custom document. */
|
|
18
|
-
export type CustomCompressionUnit = 'tokens' | 'context-percent'
|
|
19
|
-
|
|
20
|
-
/** Whether Custom History may routinely rewrite an already-sent prefix. */
|
|
21
|
-
export type CustomPrefixPolicy = 'preserve' | 'pressure-break'
|
|
22
|
-
|
|
23
|
-
/** Browser representation of one independently enabled Fresh or Aggregate budget. */
|
|
24
|
-
export interface CustomCompressionBudget {
|
|
25
|
-
enabled: boolean
|
|
26
|
-
trigger: number
|
|
27
|
-
target: number
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Legacy browser representation of the Custom History working set. */
|
|
31
|
-
export interface LegacyCustomHistoryPolicy {
|
|
32
|
-
enabled: boolean
|
|
33
|
-
trigger: number
|
|
34
|
-
keepRecentTurns: number
|
|
35
|
-
keepRecent: number
|
|
36
|
-
minReclaim: number
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Browser representation of Custom History tool-call and token-tail protection. */
|
|
40
|
-
export interface CustomHistoryPolicy {
|
|
41
|
-
enabled: boolean
|
|
42
|
-
trigger: number
|
|
43
|
-
keepRecentToolCalls: number
|
|
44
|
-
keepRecentTokens: number
|
|
45
|
-
minReclaim: number
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Browser representation of the Custom-only Experimental TailTrim gate. */
|
|
49
|
-
export interface CustomTailTrimPolicy {
|
|
50
|
-
enabled: boolean
|
|
51
|
-
trigger: number
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
interface CustomCompressionPolicyCommon<HistoryPolicy> {
|
|
55
|
-
unit: CustomCompressionUnit
|
|
56
|
-
fresh: CustomCompressionBudget
|
|
57
|
-
aggregate: CustomCompressionBudget
|
|
58
|
-
history: HistoryPolicy
|
|
59
|
-
prefixPolicy: CustomPrefixPolicy
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Legacy public Custom document; accepted and normalized before editing. */
|
|
63
|
-
export interface CustomCompressionPolicyV1 extends CustomCompressionPolicyCommon<LegacyCustomHistoryPolicy> {
|
|
64
|
-
version: 1
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Legacy Custom document with a default-disabled TailTrim stage. */
|
|
68
|
-
export interface CustomCompressionPolicyV2 extends CustomCompressionPolicyCommon<LegacyCustomHistoryPolicy> {
|
|
69
|
-
version: 2
|
|
70
|
-
tailTrim: CustomTailTrimPolicy
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Public Custom document with tool-call working-set protection. */
|
|
74
|
-
export interface CustomCompressionPolicyV3 extends CustomCompressionPolicyCommon<CustomHistoryPolicy> {
|
|
75
|
-
version: 3
|
|
76
|
-
tailTrim: CustomTailTrimPolicy
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Exact public Custom document accepted by the Host and browser boundary. */
|
|
80
|
-
export type CustomCompressionPolicy = CustomCompressionPolicyV1 | CustomCompressionPolicyV2 | CustomCompressionPolicyV3
|
|
81
|
-
|
|
82
|
-
/** Browser-safe mirror of the Host's Balanced-equivalent Custom default. */
|
|
83
|
-
export const DEFAULT_CUSTOM_COMPRESSION_POLICY: CustomCompressionPolicyV3 = {
|
|
84
|
-
version: 3,
|
|
85
|
-
unit: 'tokens',
|
|
86
|
-
fresh: { enabled: true, trigger: 8_192, target: 3_072 },
|
|
87
|
-
aggregate: { enabled: true, trigger: 32_768, target: 12_288 },
|
|
88
|
-
history: {
|
|
89
|
-
enabled: true,
|
|
90
|
-
trigger: 500_000,
|
|
91
|
-
keepRecentToolCalls: 10,
|
|
92
|
-
keepRecentTokens: 64_000,
|
|
93
|
-
minReclaim: 96_000,
|
|
94
|
-
},
|
|
95
|
-
prefixPolicy: 'pressure-break',
|
|
96
|
-
tailTrim: { enabled: false, trigger: 700_000 },
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Browser-safe mirror of the runtime PTC default policy (absolute, window-independent). */
|
|
100
|
-
export const DEFAULT_PTC_COMPRESSION_POLICY: CustomCompressionPolicyV3 = {
|
|
101
|
-
version: 3,
|
|
102
|
-
unit: 'tokens',
|
|
103
|
-
fresh: { enabled: true, trigger: 4_096, target: 1_536 },
|
|
104
|
-
aggregate: { enabled: true, trigger: 16_384, target: 4_096 },
|
|
105
|
-
history: {
|
|
106
|
-
enabled: true,
|
|
107
|
-
trigger: 20_000,
|
|
108
|
-
keepRecentToolCalls: 8,
|
|
109
|
-
keepRecentTokens: 8_000,
|
|
110
|
-
minReclaim: 6_000,
|
|
111
|
-
},
|
|
112
|
-
prefixPolicy: 'pressure-break',
|
|
113
|
-
tailTrim: { enabled: false, trigger: 700_000 },
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** User-tunable Auto Compact coordination preferences. */
|
|
117
|
-
export interface AutoCompactSettings {
|
|
118
|
-
thresholdPercent: number
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Orthogonal code-skeleton reducer gate, mirrored browser-safe from the
|
|
123
|
-
* runtime: independent of every profile, default off.
|
|
124
|
-
*/
|
|
125
|
-
export interface CodeSkeletonSettings {
|
|
126
|
-
enabled: boolean
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Orthogonal turn-tail intent-summary gate, mirrored browser-safe from the
|
|
131
|
-
* runtime: independent of every profile, default off.
|
|
132
|
-
*/
|
|
133
|
-
export interface IntentSummarySettings {
|
|
134
|
-
enabled: boolean
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** Floating compression-monitor panel (FAB); visibility switch. */
|
|
138
|
-
export interface MonitorPanelSettings {
|
|
139
|
-
enabled: boolean
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Orthogonal turn-tail sedimentation gate (plan cci-sedimentation-triage,
|
|
144
|
-
* R1/R13): whole-turn atomic replacement primary, span as the oversized-turn
|
|
145
|
-
* split and cache-strict fallback granularity. Default OFF; absent inherits
|
|
146
|
-
* the off defaults exactly like `monitorPanel`. Session-frozen like every
|
|
147
|
-
* selector setting: edits affect newly observed sessions only.
|
|
148
|
-
*/
|
|
149
|
-
export interface SedimentSettings {
|
|
150
|
-
enabled: boolean
|
|
151
|
-
/** Replacement granularity; `span` also serves as the cache-strict fallback. */
|
|
152
|
-
granularity: 'turn' | 'span'
|
|
153
|
-
/** Closing-summary qualification floor (tokens); below it the three-tier narrative fallback engages (R13). */
|
|
154
|
-
minClosingTokens: number
|
|
155
|
-
/** Rewrite guard: a cut must save at least tail-rewrite × ratio (community 1:15 evidence, findings F2). */
|
|
156
|
-
rewriteGuardRatio: number
|
|
157
|
-
/** Upper bound for one whole-turn replacement span before it splits (oversized turns). */
|
|
158
|
-
maxTurnSpanTokens: number
|
|
159
|
-
/**
|
|
160
|
-
* Append-only extra failure-signal patterns (R2 extension slot). Merging
|
|
161
|
-
* NEVER replaces the built-in base set; invalid regex entries reject the
|
|
162
|
-
* whole section (never silently dropped).
|
|
163
|
-
*/
|
|
164
|
-
extraSignalPatterns?: string[]
|
|
165
|
-
/** Fold narrative channel (Phase 4); '' keeps narrative tier 2 inert. */
|
|
166
|
-
foldMode?: '' | 'host' | 'direct'
|
|
167
|
-
foldBaseUrl?: string
|
|
168
|
-
foldBaseUrlKey?: string
|
|
169
|
-
foldStrataProvider?: string
|
|
170
|
-
foldStrataModel?: string
|
|
171
|
-
foldLocal35Provider?: string
|
|
172
|
-
foldLocal35Model?: string
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** Off-defaults mirrored browser-safe from the runtime sediment section. */
|
|
176
|
-
export const DEFAULT_SEDIMENT_SETTINGS: SedimentSettings = {
|
|
177
|
-
enabled: false,
|
|
178
|
-
granularity: 'turn',
|
|
179
|
-
minClosingTokens: 120,
|
|
180
|
-
rewriteGuardRatio: 3,
|
|
181
|
-
maxTurnSpanTokens: 32_000,
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Browser-safe mirror of the runtime sediment section (absent inherits the off
|
|
186
|
-
* defaults). Strict like the other gates: unknown keys, wrong types, or an
|
|
187
|
-
* unparseable extra pattern invalidate the whole section — never coerced.
|
|
188
|
-
*/
|
|
189
|
-
export function decodeSedimentSettings(value: unknown): SedimentSettings | undefined {
|
|
190
|
-
if (value === undefined) return { ...DEFAULT_SEDIMENT_SETTINGS }
|
|
191
|
-
if (!isPlainRecord(value)) return undefined
|
|
192
|
-
const allowed = new Set(['enabled', 'granularity', 'minClosingTokens', 'rewriteGuardRatio', 'maxTurnSpanTokens', 'extraSignalPatterns', 'foldMode', 'foldBaseUrl', 'foldBaseUrlKey', 'foldStrataProvider', 'foldStrataModel', 'foldLocal35Provider', 'foldLocal35Model'])
|
|
193
|
-
if (Object.keys(value).some(key => !allowed.has(key))) return undefined
|
|
194
|
-
if (value.enabled !== undefined && typeof value.enabled !== 'boolean') return undefined
|
|
195
|
-
if (value.granularity !== undefined && value.granularity !== 'turn' && value.granularity !== 'span') return undefined
|
|
196
|
-
if (value.foldMode !== undefined && value.foldMode !== '' && value.foldMode !== 'host' && value.foldMode !== 'direct') return undefined
|
|
197
|
-
for (const key of ['foldBaseUrl', 'foldBaseUrlKey', 'foldStrataProvider', 'foldStrataModel', 'foldLocal35Provider', 'foldLocal35Model'] as const) {
|
|
198
|
-
if (value[key] !== undefined && typeof value[key] !== 'string') return undefined
|
|
199
|
-
}
|
|
200
|
-
const bounded: Array<[unknown, number, number]> = [
|
|
201
|
-
[value.minClosingTokens, 40, 2_000],
|
|
202
|
-
[value.rewriteGuardRatio, 1, 10],
|
|
203
|
-
[value.maxTurnSpanTokens, 4_000, 64_000],
|
|
204
|
-
]
|
|
205
|
-
for (const [entry, min, max] of bounded) {
|
|
206
|
-
if (entry !== undefined
|
|
207
|
-
&& (typeof entry !== 'number' || !Number.isSafeInteger(entry) || entry < min || entry > max)) return undefined
|
|
208
|
-
}
|
|
209
|
-
if (value.extraSignalPatterns !== undefined) {
|
|
210
|
-
if (!Array.isArray(value.extraSignalPatterns)
|
|
211
|
-
|| value.extraSignalPatterns.some(entry => typeof entry !== 'string' || !isSafeSignalPattern(entry))) return undefined
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
enabled: (value.enabled as boolean | undefined) ?? DEFAULT_SEDIMENT_SETTINGS.enabled,
|
|
215
|
-
granularity: (value.granularity as 'turn' | 'span' | undefined) ?? DEFAULT_SEDIMENT_SETTINGS.granularity,
|
|
216
|
-
minClosingTokens: (value.minClosingTokens as number | undefined) ?? DEFAULT_SEDIMENT_SETTINGS.minClosingTokens,
|
|
217
|
-
rewriteGuardRatio: (value.rewriteGuardRatio as number | undefined) ?? DEFAULT_SEDIMENT_SETTINGS.rewriteGuardRatio,
|
|
218
|
-
maxTurnSpanTokens: (value.maxTurnSpanTokens as number | undefined) ?? DEFAULT_SEDIMENT_SETTINGS.maxTurnSpanTokens,
|
|
219
|
-
...value.extraSignalPatterns === undefined
|
|
220
|
-
? {}
|
|
221
|
-
: { extraSignalPatterns: [...value.extraSignalPatterns as string[]] },
|
|
222
|
-
...(value.foldMode === undefined ? {} : { foldMode: value.foldMode as '' | 'host' | 'direct' }),
|
|
223
|
-
...(value.foldBaseUrl === undefined ? {} : { foldBaseUrl: value.foldBaseUrl as string }),
|
|
224
|
-
...(value.foldBaseUrlKey === undefined ? {} : { foldBaseUrlKey: value.foldBaseUrlKey as string }),
|
|
225
|
-
...(value.foldStrataProvider === undefined ? {} : { foldStrataProvider: value.foldStrataProvider as string }),
|
|
226
|
-
...(value.foldStrataModel === undefined ? {} : { foldStrataModel: value.foldStrataModel as string }),
|
|
227
|
-
...(value.foldLocal35Provider === undefined ? {} : { foldLocal35Provider: value.foldLocal35Provider as string }),
|
|
228
|
-
...(value.foldLocal35Model === undefined ? {} : { foldLocal35Model: value.foldLocal35Model as string }),
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/** Accept only parseable, length-bounded patterns; caps keep one scan linear. */
|
|
233
|
-
function isSafeSignalPattern(entry: string): boolean {
|
|
234
|
-
if (entry.length === 0 || entry.length > 200) return false
|
|
235
|
-
try {
|
|
236
|
-
new RegExp(entry)
|
|
237
|
-
return true
|
|
238
|
-
} catch {
|
|
239
|
-
return false
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Decode the persisted codeSkeleton section with exactly the runtime schema's
|
|
245
|
-
* strictness: absent means the lossless off default; present values must be a
|
|
246
|
-
* plain object carrying only a boolean `enabled`. Anything else is invalid,
|
|
247
|
-
* never silently coerced.
|
|
248
|
-
*/
|
|
249
|
-
export function decodeCodeSkeletonSettings(value: unknown): CodeSkeletonSettings | undefined {
|
|
250
|
-
if (value === undefined) return { enabled: false }
|
|
251
|
-
if (!isPlainRecord(value)) return undefined
|
|
252
|
-
const keys = Object.keys(value)
|
|
253
|
-
if (keys.length !== 1 || keys[0] !== 'enabled') return undefined
|
|
254
|
-
const enabled = (value as Record<string, unknown>).enabled
|
|
255
|
-
return typeof enabled === 'boolean' ? { enabled } : undefined
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** Browser-safe mirror of the runtime intentSummary section (absent inherits off). */
|
|
259
|
-
export function decodeIntentSummarySettings(value: unknown): IntentSummarySettings | undefined {
|
|
260
|
-
if (value === undefined) return { enabled: false }
|
|
261
|
-
if (!isPlainRecord(value)) return undefined
|
|
262
|
-
const keys = Object.keys(value)
|
|
263
|
-
if (keys.length !== 1 || keys[0] !== 'enabled') return undefined
|
|
264
|
-
const enabled = (value as Record<string, unknown>).enabled
|
|
265
|
-
return typeof enabled === 'boolean' ? { enabled } : undefined
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/** Browser-safe mirror of the runtime monitorPanel section (absent inherits hidden). */
|
|
269
|
-
export function decodeMonitorPanelSettings(value: unknown): MonitorPanelSettings | undefined {
|
|
270
|
-
if (value === undefined) return { enabled: false }
|
|
271
|
-
if (!isPlainRecord(value)) return undefined
|
|
272
|
-
const keys = Object.keys(value)
|
|
273
|
-
if (keys.length !== 1 || keys[0] !== 'enabled') return undefined
|
|
274
|
-
const enabled = (value as Record<string, unknown>).enabled
|
|
275
|
-
return typeof enabled === 'boolean' ? { enabled } : undefined
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/** Browser-safe mirror of the runtime presetOptions section. */
|
|
279
|
-
export interface PresetOptionsSettings {
|
|
280
|
-
readonly dedupeToolResults?: boolean
|
|
281
|
-
readonly summaryLocator?: boolean
|
|
282
|
-
readonly prefixStabilizer?: boolean
|
|
283
|
-
readonly readState?: boolean
|
|
284
|
-
readonly estimatorMode?: '' | 'host' | 'direct'
|
|
285
|
-
readonly estimatorProvider?: string
|
|
286
|
-
readonly estimatorModel?: string
|
|
287
|
-
readonly estimatorBaseUrl?: string
|
|
288
|
-
readonly estimatorApiKey?: string
|
|
289
|
-
readonly estimatorTimeoutMs?: number
|
|
290
|
-
/** Advisory advisor channel; `''` (the default) keeps the advisor off. */
|
|
291
|
-
readonly advisorMode?: '' | 'host' | 'direct'
|
|
292
|
-
readonly advisorTimeoutMs?: number
|
|
293
|
-
readonly advisorRefreshTurns?: number
|
|
294
|
-
readonly advisorScoreThreshold?: number
|
|
295
|
-
readonly advisorSampleLimit?: number
|
|
296
|
-
readonly advisorMinTokens?: number
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Browser mirror of the runtime presetOptions section: absent inherits the
|
|
301
|
-
* preset defaults (decodes to `undefined`); present values must be a plain
|
|
302
|
-
* object carrying only the known keys with valid types.
|
|
303
|
-
*/
|
|
304
|
-
export function decodePresetOptionsSettings(value: unknown): PresetOptionsSettings | undefined {
|
|
305
|
-
if (value === undefined) return undefined
|
|
306
|
-
if (!isPlainRecord(value)) return undefined
|
|
307
|
-
const allowed = new Set([
|
|
308
|
-
'dedupeToolResults', 'summaryLocator', 'prefixStabilizer', 'readState', 'estimatorMode',
|
|
309
|
-
'estimatorProvider', 'estimatorModel', 'estimatorBaseUrl', 'estimatorApiKey', 'estimatorTimeoutMs',
|
|
310
|
-
// Legacy keys of the retired review gate: still ACCEPTED so an existing
|
|
311
|
-
// settings document keeps decoding (rejecting them would report the whole
|
|
312
|
-
// card unreadable), and ignored — nothing reads them any more.
|
|
313
|
-
'reviewMode', 'reviewTimeoutTurns', 'cacheHitDiscountAlpha', 'reviewHighImpactTokens',
|
|
314
|
-
'advisorMode', 'advisorTimeoutMs', 'advisorRefreshTurns', 'advisorScoreThreshold', 'advisorSampleLimit',
|
|
315
|
-
'advisorMinTokens',
|
|
316
|
-
])
|
|
317
|
-
if (Object.keys(value).some(key => !allowed.has(key))) return undefined
|
|
318
|
-
for (const key of ['dedupeToolResults', 'summaryLocator', 'prefixStabilizer', 'readState'] as const) {
|
|
319
|
-
const entry = value[key]
|
|
320
|
-
if (entry !== undefined && typeof entry !== 'boolean') return undefined
|
|
321
|
-
}
|
|
322
|
-
const estimatorMode = value.estimatorMode
|
|
323
|
-
if (estimatorMode !== undefined && estimatorMode !== '' && estimatorMode !== 'host' && estimatorMode !== 'direct') {
|
|
324
|
-
return undefined
|
|
325
|
-
}
|
|
326
|
-
const advisorMode = value.advisorMode
|
|
327
|
-
if (advisorMode !== undefined && advisorMode !== '' && advisorMode !== 'host' && advisorMode !== 'direct') {
|
|
328
|
-
return undefined
|
|
329
|
-
}
|
|
330
|
-
for (const key of ['estimatorProvider', 'estimatorModel', 'estimatorBaseUrl', 'estimatorApiKey'] as const) {
|
|
331
|
-
const entry = value[key]
|
|
332
|
-
if (entry !== undefined && typeof entry !== 'string') return undefined
|
|
333
|
-
}
|
|
334
|
-
const estimatorTimeoutMs = value.estimatorTimeoutMs
|
|
335
|
-
if (estimatorTimeoutMs !== undefined
|
|
336
|
-
&& (typeof estimatorTimeoutMs !== 'number' || !Number.isSafeInteger(estimatorTimeoutMs)
|
|
337
|
-
|| estimatorTimeoutMs < 100 || estimatorTimeoutMs > 60_000)) {
|
|
338
|
-
return undefined
|
|
339
|
-
}
|
|
340
|
-
const advisorTimeoutMs = value.advisorTimeoutMs
|
|
341
|
-
if (advisorTimeoutMs !== undefined
|
|
342
|
-
&& (typeof advisorTimeoutMs !== 'number' || !Number.isSafeInteger(advisorTimeoutMs)
|
|
343
|
-
|| advisorTimeoutMs < 100 || advisorTimeoutMs > 60_000)) {
|
|
344
|
-
return undefined
|
|
345
|
-
}
|
|
346
|
-
const advisorRefreshTurns = value.advisorRefreshTurns
|
|
347
|
-
if (advisorRefreshTurns !== undefined
|
|
348
|
-
&& (typeof advisorRefreshTurns !== 'number' || !Number.isSafeInteger(advisorRefreshTurns)
|
|
349
|
-
|| advisorRefreshTurns < 1)) {
|
|
350
|
-
return undefined
|
|
351
|
-
}
|
|
352
|
-
const advisorScoreThreshold = value.advisorScoreThreshold
|
|
353
|
-
if (advisorScoreThreshold !== undefined
|
|
354
|
-
&& (typeof advisorScoreThreshold !== 'number' || !Number.isFinite(advisorScoreThreshold)
|
|
355
|
-
|| advisorScoreThreshold <= 0 || advisorScoreThreshold >= 1)) {
|
|
356
|
-
return undefined
|
|
357
|
-
}
|
|
358
|
-
const advisorSampleLimit = value.advisorSampleLimit
|
|
359
|
-
if (advisorSampleLimit !== undefined
|
|
360
|
-
&& (typeof advisorSampleLimit !== 'number' || !Number.isSafeInteger(advisorSampleLimit)
|
|
361
|
-
|| advisorSampleLimit < 1 || advisorSampleLimit > 64)) {
|
|
362
|
-
return undefined
|
|
363
|
-
}
|
|
364
|
-
const advisorMinTokens = value.advisorMinTokens
|
|
365
|
-
if (advisorMinTokens !== undefined
|
|
366
|
-
&& (typeof advisorMinTokens !== 'number' || !Number.isSafeInteger(advisorMinTokens) || advisorMinTokens < 1)) {
|
|
367
|
-
return undefined
|
|
368
|
-
}
|
|
369
|
-
const decoded: {
|
|
370
|
-
-readonly [K in keyof PresetOptionsSettings]: PresetOptionsSettings[K]
|
|
371
|
-
} = {}
|
|
372
|
-
if (value.dedupeToolResults !== undefined) decoded.dedupeToolResults = value.dedupeToolResults as boolean
|
|
373
|
-
if (value.summaryLocator !== undefined) decoded.summaryLocator = value.summaryLocator as boolean
|
|
374
|
-
if (value.prefixStabilizer !== undefined) decoded.prefixStabilizer = value.prefixStabilizer as boolean
|
|
375
|
-
if (value.readState !== undefined) decoded.readState = value.readState as boolean
|
|
376
|
-
if (estimatorMode !== undefined) decoded.estimatorMode = estimatorMode as '' | 'host' | 'direct'
|
|
377
|
-
if (value.estimatorProvider !== undefined) decoded.estimatorProvider = value.estimatorProvider as string
|
|
378
|
-
if (value.estimatorModel !== undefined) decoded.estimatorModel = value.estimatorModel as string
|
|
379
|
-
if (value.estimatorBaseUrl !== undefined) decoded.estimatorBaseUrl = value.estimatorBaseUrl as string
|
|
380
|
-
if (value.estimatorApiKey !== undefined) decoded.estimatorApiKey = value.estimatorApiKey as string
|
|
381
|
-
if (estimatorTimeoutMs !== undefined) decoded.estimatorTimeoutMs = estimatorTimeoutMs as number
|
|
382
|
-
if (advisorMode !== undefined) decoded.advisorMode = advisorMode as '' | 'host' | 'direct'
|
|
383
|
-
if (advisorTimeoutMs !== undefined) decoded.advisorTimeoutMs = advisorTimeoutMs as number
|
|
384
|
-
if (advisorRefreshTurns !== undefined) decoded.advisorRefreshTurns = advisorRefreshTurns as number
|
|
385
|
-
if (advisorScoreThreshold !== undefined) decoded.advisorScoreThreshold = advisorScoreThreshold as number
|
|
386
|
-
if (advisorSampleLimit !== undefined) decoded.advisorSampleLimit = advisorSampleLimit as number
|
|
387
|
-
if (advisorMinTokens !== undefined) decoded.advisorMinTokens = advisorMinTokens as number
|
|
388
|
-
return decoded
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* The one threshold contract shared by the UI, the persisted settings, and the
|
|
393
|
-
* runtime resolver; mirrored browser-safe from the runtime package.
|
|
394
|
-
*/
|
|
395
|
-
export const AUTO_COMPACT_THRESHOLD_LIMITS = Object.freeze({
|
|
396
|
-
min: 50,
|
|
397
|
-
max: 90,
|
|
398
|
-
step: 1,
|
|
399
|
-
default: 80,
|
|
400
|
-
} as const)
|
|
401
|
-
|
|
402
|
-
/** Narrow one unknown value to a valid Auto Compact threshold percent. */
|
|
403
|
-
export function isValidAutoCompactThresholdPercent(value: unknown): value is number {
|
|
404
|
-
return typeof value === 'number'
|
|
405
|
-
&& Number.isSafeInteger(value)
|
|
406
|
-
&& value >= AUTO_COMPACT_THRESHOLD_LIMITS.min
|
|
407
|
-
&& value <= AUTO_COMPACT_THRESHOLD_LIMITS.max
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/** Accept JSON-object records while rejecting class instances and exotic prototypes. */
|
|
411
|
-
export function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
412
|
-
if (value === null || typeof value !== 'object' || Array.isArray(value)) return false
|
|
413
|
-
const prototype = Object.getPrototypeOf(value) as object | null
|
|
414
|
-
return prototype === Object.prototype || prototype === null
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Decode the persisted autoCompact section with exactly the runtime schema's
|
|
419
|
-
* strictness: absent means the 80% default; present values must be a plain
|
|
420
|
-
* object carrying only a valid `thresholdPercent`. Anything else is invalid,
|
|
421
|
-
* never silently coerced.
|
|
422
|
-
*/
|
|
423
|
-
export function decodeAutoCompactSettings(value: unknown): AutoCompactSettings | undefined {
|
|
424
|
-
if (value === undefined) return { thresholdPercent: AUTO_COMPACT_THRESHOLD_LIMITS.default }
|
|
425
|
-
if (!isPlainRecord(value)) return undefined
|
|
426
|
-
const keys = Object.keys(value)
|
|
427
|
-
if (keys.length !== 1 || keys[0] !== 'thresholdPercent') return undefined
|
|
428
|
-
const thresholdPercent = (value as Record<string, unknown>).thresholdPercent
|
|
429
|
-
return isValidAutoCompactThresholdPercent(thresholdPercent)
|
|
430
|
-
? { thresholdPercent }
|
|
431
|
-
: undefined
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/** Durable settings section owned by this package. */
|
|
435
|
-
export interface ContextCompressionSettings {
|
|
436
|
-
/** Default profile captured when each Session first reaches the pruner. */
|
|
437
|
-
profile: CompressionProfile
|
|
438
|
-
/** Complete canonical policy captured with `profile` when the runtime first observes a Session. */
|
|
439
|
-
custom: CustomCompressionPolicy
|
|
440
|
-
/** PTC profile's own editable policy, seeded from the ptc defaults; independent of `custom`. Optional like `monitorPanel`/`presetOptions`: schema-defaulted, always present after parse. */
|
|
441
|
-
ptcCustom?: CustomCompressionPolicy
|
|
442
|
-
/** Auto Compact trigger captured with `profile` when the runtime first observes a Session. */
|
|
443
|
-
autoCompact: AutoCompactSettings
|
|
444
|
-
/** Code-skeleton reducer gate captured independently of `profile`. */
|
|
445
|
-
codeSkeleton: CodeSkeletonSettings
|
|
446
|
-
/** Turn-tail intent-summary gate captured independently of `profile`. */
|
|
447
|
-
intentSummary: IntentSummarySettings
|
|
448
|
-
/** Floating compression-monitor panel (FAB); absent inherits hidden. */
|
|
449
|
-
monitorPanel?: MonitorPanelSettings
|
|
450
|
-
/** Turn-tail sedimentation gate (plan cci-sedimentation-triage); absent inherits the off defaults. */
|
|
451
|
-
sediment?: SedimentSettings
|
|
452
|
-
/** Optional tokenpilot-inspired sub-capability overrides (presence-validated only). */
|
|
453
|
-
presetOptions?: PresetOptionsSettings
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Narrow an unknown settings value to a complete supported Custom policy.
|
|
458
|
-
* @param value - Candidate settings value received from the Host or edited locally.
|
|
459
|
-
* @returns Whether the value is a relation-valid Custom policy.
|
|
460
|
-
*/
|
|
461
|
-
export function isCustomCompressionPolicy(value: unknown): value is CustomCompressionPolicy {
|
|
462
|
-
if (!hasExactKeys(
|
|
463
|
-
value,
|
|
464
|
-
value !== null && typeof value === 'object' && 'version' in value && value.version === 1
|
|
465
|
-
? ['version', 'unit', 'fresh', 'aggregate', 'history', 'prefixPolicy']
|
|
466
|
-
: ['version', 'unit', 'fresh', 'aggregate', 'history', 'prefixPolicy', 'tailTrim'],
|
|
467
|
-
)) return false
|
|
468
|
-
if ((value.version !== 1 && value.version !== 2 && value.version !== 3)
|
|
469
|
-
|| (value.unit !== 'tokens' && value.unit !== 'context-percent')) return false
|
|
470
|
-
if (value.prefixPolicy !== 'preserve' && value.prefixPolicy !== 'pressure-break') return false
|
|
471
|
-
if (!isBudget(value.fresh) || !isBudget(value.aggregate)) return false
|
|
472
|
-
const modernHistory = value.version === 3
|
|
473
|
-
if (!hasExactKeys(
|
|
474
|
-
value.history,
|
|
475
|
-
modernHistory
|
|
476
|
-
? ['enabled', 'trigger', 'keepRecentToolCalls', 'keepRecentTokens', 'minReclaim']
|
|
477
|
-
: ['enabled', 'trigger', 'keepRecentTurns', 'keepRecent', 'minReclaim'],
|
|
478
|
-
)) return false
|
|
479
|
-
if (typeof value.history.enabled !== 'boolean'
|
|
480
|
-
|| typeof value.history.trigger !== 'number'
|
|
481
|
-
|| typeof value.history.minReclaim !== 'number') return false
|
|
482
|
-
const recent = modernHistory
|
|
483
|
-
? value.history.keepRecentTokens
|
|
484
|
-
: value.history.keepRecent
|
|
485
|
-
const calls = modernHistory ? value.history.keepRecentToolCalls : value.history.keepRecentTurns
|
|
486
|
-
if (typeof recent !== 'number'
|
|
487
|
-
|| typeof calls !== 'number'
|
|
488
|
-
|| !Number.isSafeInteger(calls)
|
|
489
|
-
|| calls < 0) return false
|
|
490
|
-
let tailTrimTrigger: number | undefined
|
|
491
|
-
if (value.version !== 1) {
|
|
492
|
-
const tailTrim = value.tailTrim
|
|
493
|
-
if (!hasExactKeys(tailTrim, ['enabled', 'trigger'])
|
|
494
|
-
|| typeof tailTrim.enabled !== 'boolean'
|
|
495
|
-
|| typeof tailTrim.trigger !== 'number') return false
|
|
496
|
-
tailTrimTrigger = tailTrim.trigger
|
|
497
|
-
}
|
|
498
|
-
const measured = [
|
|
499
|
-
value.fresh.trigger, value.fresh.target,
|
|
500
|
-
value.aggregate.trigger, value.aggregate.target,
|
|
501
|
-
value.history.trigger, recent, value.history.minReclaim,
|
|
502
|
-
...tailTrimTrigger === undefined ? [] : [tailTrimTrigger],
|
|
503
|
-
]
|
|
504
|
-
if (!measured.every(entry => typeof entry === 'number' && Number.isFinite(entry))) return false
|
|
505
|
-
if (value.fresh.trigger <= 0 || value.fresh.target <= 0
|
|
506
|
-
|| value.aggregate.trigger <= 0 || value.aggregate.target <= 0
|
|
507
|
-
|| value.history.trigger <= 0 || recent < 0
|
|
508
|
-
|| value.history.minReclaim <= 0
|
|
509
|
-
|| (tailTrimTrigger !== undefined && tailTrimTrigger <= 0)) return false
|
|
510
|
-
if (value.unit === 'tokens' && !measured.every(Number.isSafeInteger)) return false
|
|
511
|
-
if (value.unit === 'context-percent' && !measured.every(entry => entry <= 100)) return false
|
|
512
|
-
return value.fresh.target < value.fresh.trigger
|
|
513
|
-
&& value.aggregate.target < value.aggregate.trigger
|
|
514
|
-
&& value.history.minReclaim <= value.history.trigger
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
function isBudget(value: unknown): value is CustomCompressionBudget {
|
|
518
|
-
return hasExactKeys(value, ['enabled', 'trigger', 'target'])
|
|
519
|
-
&& typeof value.enabled === 'boolean'
|
|
520
|
-
&& typeof value.trigger === 'number'
|
|
521
|
-
&& typeof value.target === 'number'
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* Canonicalize one validated Custom document to version 3, mirroring the
|
|
526
|
-
* runtime's `canonicalizeCustomPolicy` exactly so the browser and runtime
|
|
527
|
-
* boundaries hand the SAME complete document to the UI and the policy
|
|
528
|
-
* resolver: legacy v1/v2 History working sets upgrade to the 10-call default,
|
|
529
|
-
* and a v1 document gains the default-disabled TailTrim stage.
|
|
530
|
-
*/
|
|
531
|
-
export function canonicalizeCustomPolicy(policy: CustomCompressionPolicy): CustomCompressionPolicyV3 {
|
|
532
|
-
if (policy.version === 3) return structuredClone(policy)
|
|
533
|
-
return {
|
|
534
|
-
version: 3,
|
|
535
|
-
unit: policy.unit,
|
|
536
|
-
fresh: structuredClone(policy.fresh),
|
|
537
|
-
aggregate: structuredClone(policy.aggregate),
|
|
538
|
-
history: {
|
|
539
|
-
enabled: policy.history.enabled,
|
|
540
|
-
trigger: policy.history.trigger,
|
|
541
|
-
keepRecentToolCalls: 10,
|
|
542
|
-
keepRecentTokens: policy.history.keepRecent,
|
|
543
|
-
minReclaim: policy.history.minReclaim,
|
|
544
|
-
},
|
|
545
|
-
prefixPolicy: policy.prefixPolicy,
|
|
546
|
-
tailTrim: policy.version === 1 ? { enabled: false, trigger: 700_000 } : structuredClone(policy.tailTrim),
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
function hasExactKeys(value: unknown, expected: readonly string[]): value is Record<string, unknown> {
|
|
551
|
-
if (!isPlainRecord(value)) return false
|
|
552
|
-
const keys = Object.keys(value)
|
|
553
|
-
return keys.length === expected.length && keys.every(key => expected.includes(key))
|
|
554
|
-
}
|