dsh-context-compression-improved 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +10 -1
  2. package/package.json +162 -140
  3. package/packages/selector/README.md +6 -1
  4. package/packages/selector/README.zh.md +6 -1
  5. package/packages/selector/dsh.plugin.json +1 -1
  6. package/packages/selector/lib/advisor-state.js +1 -1
  7. package/packages/selector/lib/client.d.ts +19 -104
  8. package/packages/selector/lib/client.js +42 -5
  9. package/packages/selector/lib/index.d.ts +9 -0
  10. package/packages/selector/lib/index.js +18 -50
  11. package/packages/selector/lib/profiles.d.ts +105 -0
  12. package/packages/selector/lib/pruner.js +3 -2
  13. package/packages/selector/package.json +114 -114
  14. package/packages/selector/src/client/index.ts +71 -8
  15. package/packages/selector/src/index.ts +35 -86
  16. package/packages/selector/src/pruner.ts +12 -3
  17. package/packages/selector/src/runtime/config.ts +1 -1
  18. package/packages/selector/tests/code-skeleton.client.spec.ts +93 -90
  19. package/packages/selector/tests/custom-contract.client.spec.ts +19 -1
  20. package/packages/selector/tests/helpers/legacy-namespace.ts +31 -0
  21. package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -206
  22. package/packages/selector/tests/preset-options-write.client.spec.ts +63 -82
  23. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +206 -201
  24. package/packages/selector/tests/public/package-contract.client.spec.ts +2 -2
  25. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +3 -2
  26. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +20 -17
  27. package/packages/selector/tests/settings-seat.client.spec.ts +2 -2
  28. package/packages/selector/tests/standing-generation.host.spec.ts +704 -697
@@ -1,6 +1,5 @@
1
- import { o as CONTEXT_COMPRESSION_SETTINGS_NAMESPACE, s as ContextCompressionSettingsSchema, t as getAdvisorState } from "./advisor-state.js";
1
+ import { l as DEFAULT_CONTEXT_COMPRESSION_SETTINGS, t as getAdvisorState } from "./advisor-state.js";
2
2
  import z from "@deepseek-ai/schemastery";
3
- import "@deepseek-ai/dsh-settings";
4
3
  import { AsyncLocalStorage } from "node:async_hooks";
5
4
  import { createHash } from "node:crypto";
6
5
  import { chmod, mkdtemp, readFile, rename, rm, stat, utimes, writeFile } from "node:fs/promises";
@@ -503,7 +502,6 @@ function restoreMethod(presets, snapshot) {
503
502
  }
504
503
  //#endregion
505
504
  //#region src/index.ts
506
- const CONTEXT_COMPRESSION_NAMESPACE = CONTEXT_COMPRESSION_SETTINGS_NAMESPACE;
507
505
  const ESTIMATOR_CATALOG_ROUTES = ["/endpoint/dsh-context-compression-improved/estimator-catalog", "/api/dsh-context-compression-improved/estimator-catalog"];
508
506
  const ADVISOR_REPORT_ROUTES = ["/endpoint/dsh-context-compression-improved/advisor-report", "/api/dsh-context-compression-improved/advisor-report"];
509
507
  function sessionFor(readService, sessionId) {
@@ -720,20 +718,28 @@ function registerEstimatorCatalogRoute(ctx) {
720
718
  });
721
719
  log("warn", "context-compression webServer not active yet — estimator catalog route pending: %s", ESTIMATOR_CATALOG_ROUTES.join(", "));
722
720
  }
723
- /** Symbol properties reach the shared service target through Cordis proxies. */
724
- const SHARED_SETTINGS = Symbol.for("dsh-context-compression-improved/settings-registration");
721
+ /**
722
+ * Resolve one possibly-volatile field: a live ref on 0.1.7+, a plain value
723
+ * otherwise (0.1.7 hands `.volatile()` fields to `apply()` as live refs).
724
+ */
725
+ function readVolatileValue(value) {
726
+ if (value !== null && typeof value === "object" && typeof value.get === "function") return value.get();
727
+ return value;
728
+ }
729
+ /** The compression settings document carried by this row's composition entry. */
730
+ function readCompressionDoc(config) {
731
+ return readVolatileValue(config?.settings);
732
+ }
725
733
  /** Loader validation for the standalone Bundle opt-in. */
726
734
  const Config = z.object({
727
735
  presetOverlay: z.boolean().default(false),
728
736
  estimatorCatalogRoute: z.boolean().default(false),
729
- advisorReportRoute: z.boolean().default(false)
737
+ advisorReportRoute: z.boolean().default(false),
738
+ settings: z.any().default(DEFAULT_CONTEXT_COMPRESSION_SETTINGS).volatile()
730
739
  });
731
740
  /** Register the persisted default read by the currently mounted root pruner. */
732
741
  function apply(ctx, config = {}) {
733
742
  try {
734
- ctx.inject(["settings"], (settingsCtx) => {
735
- acquireSettingsRegistration(settingsCtx);
736
- });
737
743
  if (config.estimatorCatalogRoute === true) registerEstimatorCatalogRoute(ctx);
738
744
  if (config.advisorReportRoute === true) registerAdvisorReportRoute(ctx);
739
745
  if (config.presetOverlay !== true) return;
@@ -741,7 +747,7 @@ function apply(ctx, config = {}) {
741
747
  const installation = decorateAgentPresets(presetsCtx.agentPresets, {
742
748
  modules: resolveCompressionModulePaths(),
743
749
  excludedPresetIds: ["minimal"],
744
- autoCompactThresholdPercent: () => resolveAutoCompactThresholdPercent(presetsCtx)
750
+ autoCompactThresholdPercent: () => resolveAutoCompactThresholdPercent(config, presetsCtx)
745
751
  });
746
752
  presetsCtx.effect(() => () => installation.dispose(), "contextCompressionSelector.agentPresets()");
747
753
  });
@@ -755,8 +761,8 @@ function apply(ctx, config = {}) {
755
761
  * values are revalidated here, and any unreadable value falls back to the 80%
756
762
  * default rather than blocking preset composition.
757
763
  */
758
- function resolveAutoCompactThresholdPercent(presetsCtx) {
759
- const raw = presetsCtx.get("settings")?.get(CONTEXT_COMPRESSION_NAMESPACE);
764
+ function resolveAutoCompactThresholdPercent(config, presetsCtx) {
765
+ const raw = readCompressionDoc(config) ?? (presetsCtx?.get("settings"))?.get?.("context-compression");
760
766
  try {
761
767
  const threshold = structuredClone(raw)?.autoCompact;
762
768
  const value = typeof threshold?.thresholdPercent === "number" ? threshold.thresholdPercent : 80;
@@ -765,43 +771,5 @@ function resolveAutoCompactThresholdPercent(presetsCtx) {
765
771
  return 80;
766
772
  }
767
773
  }
768
- /**
769
- * Lease one native settings registration across duplicate Host rows.
770
- *
771
- * The lease effect is intentionally registered before settings.register().
772
- * Cordis disposes effects in reverse order, so the native registration first
773
- * releases the namespace; this disposer can then transfer it to another live
774
- * owner without a duplicate-registration window.
775
- */
776
- function acquireSettingsRegistration(ctx) {
777
- const settings = ctx.settings;
778
- const owner = { settings };
779
- let shared = settings[SHARED_SETTINGS];
780
- if (shared === void 0) {
781
- shared = {
782
- owners: /* @__PURE__ */ new Set(),
783
- registrationOwner: owner,
784
- scope: void 0
785
- };
786
- Object.defineProperty(settings, SHARED_SETTINGS, {
787
- configurable: true,
788
- enumerable: false,
789
- writable: false,
790
- value: shared
791
- });
792
- }
793
- shared.owners.add(owner);
794
- const state = shared;
795
- ctx.effect(() => () => {
796
- state.owners.delete(owner);
797
- if (state.registrationOwner === owner && state.owners.size > 0) {
798
- const next = state.owners.values().next().value;
799
- state.registrationOwner = next;
800
- state.scope = next.settings.register(CONTEXT_COMPRESSION_NAMESPACE, ContextCompressionSettingsSchema);
801
- }
802
- if (state.owners.size === 0 && settings[SHARED_SETTINGS] === state) Reflect.deleteProperty(settings, SHARED_SETTINGS);
803
- }, "contextCompressionSelector.settingsLease()");
804
- if (state.owners.size === 1) state.scope = settings.register(CONTEXT_COMPRESSION_NAMESPACE, ContextCompressionSettingsSchema);
805
- }
806
774
  //#endregion
807
775
  export { Config, apply };
@@ -0,0 +1,105 @@
1
+ //#region src/profiles.d.ts
2
+ /** Public context-compression choices shared by the Host schema and browser selector. */
3
+ declare const COMPRESSION_PROFILES: readonly ["off", "native", "balanced", "cache-strict", "savings", "adaptive", "tokenpilot-inspired", "custom"];
4
+ /** One supported context-compression profile. */
5
+ type CompressionProfile = typeof COMPRESSION_PROFILES[number];
6
+ /** Single canonical unit stored by a version-1 browser Custom document. */
7
+ type CustomCompressionUnit = 'tokens' | 'context-percent';
8
+ /** Whether Custom History may routinely rewrite an already-sent prefix. */
9
+ type CustomPrefixPolicy = 'preserve' | 'pressure-break';
10
+ /** Browser representation of one independently enabled Fresh or Aggregate budget. */
11
+ interface CustomCompressionBudget {
12
+ enabled: boolean;
13
+ trigger: number;
14
+ target: number;
15
+ }
16
+ /** Legacy browser representation of the Custom History working set. */
17
+ interface LegacyCustomHistoryPolicy {
18
+ enabled: boolean;
19
+ trigger: number;
20
+ keepRecentTurns: number;
21
+ keepRecent: number;
22
+ minReclaim: number;
23
+ }
24
+ /** Browser representation of Custom History tool-call and token-tail protection. */
25
+ interface CustomHistoryPolicy {
26
+ enabled: boolean;
27
+ trigger: number;
28
+ keepRecentToolCalls: number;
29
+ keepRecentTokens: number;
30
+ minReclaim: number;
31
+ }
32
+ /** Browser representation of the Custom-only Experimental TailTrim gate. */
33
+ interface CustomTailTrimPolicy {
34
+ enabled: boolean;
35
+ trigger: number;
36
+ }
37
+ interface CustomCompressionPolicyCommon<HistoryPolicy> {
38
+ unit: CustomCompressionUnit;
39
+ fresh: CustomCompressionBudget;
40
+ aggregate: CustomCompressionBudget;
41
+ history: HistoryPolicy;
42
+ prefixPolicy: CustomPrefixPolicy;
43
+ }
44
+ /** Legacy public Custom document; accepted and normalized before editing. */
45
+ interface CustomCompressionPolicyV1 extends CustomCompressionPolicyCommon<LegacyCustomHistoryPolicy> {
46
+ version: 1;
47
+ }
48
+ /** Legacy Custom document with a default-disabled TailTrim stage. */
49
+ interface CustomCompressionPolicyV2 extends CustomCompressionPolicyCommon<LegacyCustomHistoryPolicy> {
50
+ version: 2;
51
+ tailTrim: CustomTailTrimPolicy;
52
+ }
53
+ /** Public Custom document with tool-call working-set protection. */
54
+ interface CustomCompressionPolicyV3 extends CustomCompressionPolicyCommon<CustomHistoryPolicy> {
55
+ version: 3;
56
+ tailTrim: CustomTailTrimPolicy;
57
+ }
58
+ /** Exact public Custom document accepted by the Host and browser boundary. */
59
+ type CustomCompressionPolicy = CustomCompressionPolicyV1 | CustomCompressionPolicyV2 | CustomCompressionPolicyV3;
60
+ /** User-tunable Auto Compact coordination preferences. */
61
+ interface AutoCompactSettings {
62
+ thresholdPercent: number;
63
+ }
64
+ /**
65
+ * Orthogonal code-skeleton reducer gate, mirrored browser-safe from the
66
+ * runtime: independent of every profile, default off.
67
+ */
68
+ interface CodeSkeletonSettings {
69
+ enabled: boolean;
70
+ }
71
+ /** Browser-safe mirror of the runtime presetOptions section. */
72
+ interface PresetOptionsSettings {
73
+ readonly dedupeToolResults?: boolean;
74
+ readonly summaryLocator?: boolean;
75
+ readonly prefixStabilizer?: boolean;
76
+ readonly readState?: boolean;
77
+ readonly estimatorMode?: '' | 'host' | 'direct';
78
+ readonly estimatorProvider?: string;
79
+ readonly estimatorModel?: string;
80
+ readonly estimatorBaseUrl?: string;
81
+ readonly estimatorApiKey?: string;
82
+ readonly estimatorTimeoutMs?: number;
83
+ /** Advisory advisor channel; `''` (the default) keeps the advisor off. */
84
+ readonly advisorMode?: '' | 'host' | 'direct';
85
+ readonly advisorTimeoutMs?: number;
86
+ readonly advisorRefreshTurns?: number;
87
+ readonly advisorScoreThreshold?: number;
88
+ readonly advisorSampleLimit?: number;
89
+ readonly advisorMinTokens?: number;
90
+ }
91
+ /** Durable settings section owned by this package. */
92
+ interface ContextCompressionSettings {
93
+ /** Default profile captured when each Session first reaches the pruner. */
94
+ profile: CompressionProfile;
95
+ /** Complete canonical policy captured with `profile` when the runtime first observes a Session. */
96
+ custom: CustomCompressionPolicy;
97
+ /** Auto Compact trigger captured with `profile` when the runtime first observes a Session. */
98
+ autoCompact: AutoCompactSettings;
99
+ /** Code-skeleton reducer gate captured independently of `profile`. */
100
+ codeSkeleton: CodeSkeletonSettings;
101
+ /** Optional tokenpilot-inspired sub-capability overrides (presence-validated only). */
102
+ presetOptions?: PresetOptionsSettings;
103
+ }
104
+ //#endregion
105
+ export { PresetOptionsSettings as i, ContextCompressionSettings as n, CustomCompressionPolicy as r, CompressionProfile as t };
@@ -1,4 +1,4 @@
1
- import { C as COMPRESSION_PROFILES, S as deepFreeze, _ as resolvePolicy, a as AUTO_COMPACT_THRESHOLD_LIMITS, b as resolveCustomPolicy, c as DEFAULTS, d as charsToTokens, f as codePointLength, g as resolveConfig, h as parseContextCompressionSettings, i as recordScore, l as PRUNE_MARKER, m as isValidAutoCompactThresholdPercent, n as invalidateOnTaskChange, o as CONTEXT_COMPRESSION_SETTINGS_NAMESPACE, p as isCompressionProfile, r as recordRecertified, s as ContextCompressionSettingsSchema, t as getAdvisorState, u as charsForTokens, v as CustomCompressionPolicySchema, x as assertNever, y as DEFAULT_CUSTOM_COMPRESSION_POLICY } from "./advisor-state.js";
1
+ import { C as deepFreeze, S as assertNever, _ as resolveConfig, a as AUTO_COMPACT_THRESHOLD_LIMITS, b as DEFAULT_CUSTOM_COMPRESSION_POLICY, c as DEFAULTS, d as charsForTokens, f as charsToTokens, g as parseContextCompressionSettings, h as isValidAutoCompactThresholdPercent, i as recordScore, m as isCompressionProfile, n as invalidateOnTaskChange, o as CONTEXT_COMPRESSION_SETTINGS_NAMESPACE, p as codePointLength, r as recordRecertified, s as ContextCompressionSettingsSchema, t as getAdvisorState, u as PRUNE_MARKER, v as resolvePolicy, w as COMPRESSION_PROFILES, x as resolveCustomPolicy, y as CustomCompressionPolicySchema } from "./advisor-state.js";
2
2
  import { a as validatePublishedTailTrim, i as tailTrimStub, n as tailTrimMessage, o as eventBySeq, r as tailTrimRef, s as sessionEvents, t as parseTailTrimRef } from "./tail-trim.js";
3
3
  import z from "@deepseek-ai/schemastery";
4
4
  import { createHash } from "node:crypto";
@@ -4170,7 +4170,8 @@ var ToolResultPruner = class extends Service {
4170
4170
  activeSettings(session) {
4171
4171
  const frozen = this.state.sessionSettings.get(session);
4172
4172
  if (frozen !== void 0) return frozen;
4173
- const settings = this.ctx.get("settings")?.get(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE);
4173
+ const settingsHost = this.ctx.get("settings");
4174
+ const settings = settingsHost?.describe?.().find((d) => String(d.ns) === "context-compression-improved-bundle")?.value ?? settingsHost?.get?.("context-compression");
4174
4175
  let resolved;
4175
4176
  let settingsSource = settings === void 0 ? "plugin-config-fallback" : "host-settings";
4176
4177
  let autoCompactThresholdSource = settings === void 0 ? "schema-default" : "host-settings";
@@ -1,114 +1,114 @@
1
- {
2
- "name": "dsh-context-compression-improved",
3
- "version": "0.1.0",
4
- "description": "One-install context-compression selector bundle for DeepSeek Harness",
5
- "type": "module",
6
- "main": "lib/index.js",
7
- "types": "lib/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./lib/index.d.ts",
11
- "default": "./lib/index.js"
12
- },
13
- "./invariant": {
14
- "types": "./lib/invariant.d.ts",
15
- "default": "./lib/invariant.js"
16
- },
17
- "./pruner": {
18
- "types": "./lib/pruner.d.ts",
19
- "default": "./lib/pruner.js"
20
- },
21
- "./client": {
22
- "types": "./lib/client.d.ts",
23
- "default": "./lib/client.js"
24
- },
25
- "./package.json": "./package.json"
26
- },
27
- "files": [
28
- "lib/**/*.js",
29
- "lib/**/*.d.ts",
30
- "cordis.patch.yml",
31
- "dsh.plugin.json",
32
- "screenshots.json",
33
- "assets",
34
- "README.md",
35
- "README.zh.md",
36
- "LICENSE",
37
- "THIRD_PARTY_NOTICES.md"
38
- ],
39
- "dsh": {
40
- "client": {
41
- "inject": [
42
- "@deepseek-ai/dsh-client-locale",
43
- "@deepseek-ai/dsh-client-ui-slots",
44
- "@deepseek-ai/dsh-client-ui-settings"
45
- ],
46
- "platform": "web"
47
- },
48
- "bundle": {
49
- "patch": "./cordis.patch.yml"
50
- }
51
- },
52
- "scripts": {
53
- "bundle": "tsdown --config tsdown.config.ts && tsdown --config tsdown.client.config.ts",
54
- "typecheck": "tsc --noEmit -p tsconfig.json",
55
- "test": "vitest run --root ../.. --config vitest.config.ts --project runtime --project selector-host --project selector-client",
56
- "pack:dry-run": "npm pack --dry-run"
57
- },
58
- "repository": {
59
- "type": "git",
60
- "url": "git+https://github.com/drscrewdriver/dsh-context-compression-improved.git",
61
- "directory": "packages/selector"
62
- },
63
- "homepage": "https://github.com/drscrewdriver/dsh-context-compression-improved#readme",
64
- "bugs": {
65
- "url": "https://github.com/drscrewdriver/dsh-context-compression-improved/issues"
66
- },
67
- "author": "WilliamShi666",
68
- "engines": {
69
- "node": "^22.19.0 || >=24.0.0",
70
- "dsh": ">=0.1.5-alpha.1 <0.2.0-0"
71
- },
72
- "keywords": [
73
- "deepseek",
74
- "harness",
75
- "context",
76
- "compression",
77
- "plugin"
78
- ],
79
- "license": "MIT",
80
- "publishConfig": {
81
- "access": "public",
82
- "tag": "latest"
83
- },
84
- "dependencies": {
85
- "@deepseek-ai/schemastery": "3.18.2",
86
- "@huggingface/tokenizers": "0.1.3",
87
- "js-yaml": "^4.3.2"
88
- },
89
- "peerDependencies": {
90
- "@deepseek-ai/cordis": ">=4.0.1 <5",
91
- "@deepseek-ai/cordis-plugin-include": ">=1.0.6 <2",
92
- "@deepseek-ai/cordis-plugin-loader": ">=1.0.2 <2",
93
- "@deepseek-ai/dsh-agent": ">=0.1.5-rc.2 <0.2.0-0",
94
- "@deepseek-ai/dsh-agent-presets": ">=0.1.5-rc.2 <0.2.0-0",
95
- "@deepseek-ai/dsh-command-compact": ">=0.1.5-rc.2 <0.2.0-0",
96
- "@deepseek-ai/dsh-compaction": ">=0.1.5-rc.2 <0.2.0-0",
97
- "@deepseek-ai/dsh-compaction-basic": ">=0.1.5-rc.2 <0.2.0-0",
98
- "@deepseek-ai/dsh-client-locale": ">=0.1.5-rc.2 <0.2.0-0",
99
- "@deepseek-ai/dsh-client-store": ">=0.1.5-rc.2 <0.2.0-0",
100
- "@deepseek-ai/dsh-client-ui-session": ">=0.1.5-rc.2 <0.2.0",
101
- "@deepseek-ai/dsh-client-ui-primitives": ">=0.1.5-rc.2 <0.2.0-0",
102
- "@deepseek-ai/dsh-client-ui-settings": ">=0.1.5-rc.2 <0.2.0-0",
103
- "@deepseek-ai/dsh-client-ui-slots": ">=0.1.5-rc.2 <0.2.0-0",
104
- "@deepseek-ai/dsh-client-ui-workspace": ">=0.1.5-rc.2 <0.2.0-0",
105
- "@deepseek-ai/dsh-invariants": ">=0.1.5-rc.2 <0.2.0-0",
106
- "@deepseek-ai/dsh-llm": ">=0.1.5-rc.2 <0.2.0-0",
107
- "@deepseek-ai/dsh-session": ">=0.1.5-rc.2 <0.2.0-0",
108
- "@deepseek-ai/dsh-settings": ">=0.1.5-rc.2 <0.2.0-0",
109
- "@deepseek-ai/dsh-system-prompt": ">=0.1.5-rc.2 <0.2.0-0",
110
- "@deepseek-ai/dsh-token-meter": ">=0.1.5-rc.2 <0.2.0-0",
111
- "@deepseek-ai/dsh-tools": ">=0.1.5-rc.2 <0.2.0-0",
112
- "react": ">=18 <19"
113
- }
114
- }
1
+ {
2
+ "name": "dsh-context-compression-improved",
3
+ "version": "0.2.0",
4
+ "description": "One-install context-compression selector bundle for DeepSeek Harness",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/index.d.ts",
11
+ "default": "./lib/index.js"
12
+ },
13
+ "./invariant": {
14
+ "types": "./lib/invariant.d.ts",
15
+ "default": "./lib/invariant.js"
16
+ },
17
+ "./pruner": {
18
+ "types": "./lib/pruner.d.ts",
19
+ "default": "./lib/pruner.js"
20
+ },
21
+ "./client": {
22
+ "types": "./lib/client.d.ts",
23
+ "default": "./lib/client.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "lib/**/*.js",
29
+ "lib/**/*.d.ts",
30
+ "cordis.patch.yml",
31
+ "dsh.plugin.json",
32
+ "screenshots.json",
33
+ "assets",
34
+ "README.md",
35
+ "README.zh.md",
36
+ "LICENSE",
37
+ "THIRD_PARTY_NOTICES.md"
38
+ ],
39
+ "dsh": {
40
+ "client": {
41
+ "inject": [
42
+ "@deepseek-ai/dsh-client-locale",
43
+ "@deepseek-ai/dsh-client-ui-slots",
44
+ "@deepseek-ai/dsh-client-ui-settings"
45
+ ],
46
+ "platform": "web"
47
+ },
48
+ "bundle": {
49
+ "patch": "./cordis.patch.yml"
50
+ }
51
+ },
52
+ "scripts": {
53
+ "bundle": "tsdown --config tsdown.config.ts && tsdown --config tsdown.client.config.ts",
54
+ "typecheck": "tsc --noEmit -p tsconfig.json",
55
+ "test": "vitest run --root ../.. --config vitest.config.ts --project runtime --project selector-host --project selector-client",
56
+ "pack:dry-run": "npm pack --dry-run"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/drscrewdriver/dsh-context-compression-improved.git",
61
+ "directory": "packages/selector"
62
+ },
63
+ "homepage": "https://github.com/drscrewdriver/dsh-context-compression-improved#readme",
64
+ "bugs": {
65
+ "url": "https://github.com/drscrewdriver/dsh-context-compression-improved/issues"
66
+ },
67
+ "author": "WilliamShi666",
68
+ "engines": {
69
+ "node": "^22.19.0 || >=24.0.0",
70
+ "dsh": ">=0.1.5-rc.1 <0.2.0-0"
71
+ },
72
+ "keywords": [
73
+ "deepseek",
74
+ "harness",
75
+ "context",
76
+ "compression",
77
+ "plugin"
78
+ ],
79
+ "license": "MIT",
80
+ "publishConfig": {
81
+ "access": "public",
82
+ "tag": "latest"
83
+ },
84
+ "dependencies": {
85
+ "@deepseek-ai/schemastery": "3.18.4",
86
+ "@huggingface/tokenizers": "0.1.3",
87
+ "js-yaml": "^4.3.2"
88
+ },
89
+ "peerDependencies": {
90
+ "@deepseek-ai/cordis": ">=4.0.1 <5",
91
+ "@deepseek-ai/cordis-plugin-include": ">=1.0.6 <2",
92
+ "@deepseek-ai/cordis-plugin-loader": ">=1.0.2 <2",
93
+ "@deepseek-ai/dsh-agent": ">=0.1.7-rc.1 <0.2.0-0",
94
+ "@deepseek-ai/dsh-agent-presets": ">=0.1.7-rc.1 <0.2.0-0",
95
+ "@deepseek-ai/dsh-client-locale": ">=0.1.7-rc.1 <0.2.0-0",
96
+ "@deepseek-ai/dsh-client-store": ">=0.1.7-rc.1 <0.2.0-0",
97
+ "@deepseek-ai/dsh-client-ui-primitives": ">=0.1.7-rc.1 <0.2.0-0",
98
+ "@deepseek-ai/dsh-client-ui-session": ">=0.1.7-rc.1 <0.2.0-0",
99
+ "@deepseek-ai/dsh-client-ui-settings": ">=0.1.7-rc.1 <0.2.0-0",
100
+ "@deepseek-ai/dsh-client-ui-slots": ">=0.1.7-rc.1 <0.2.0-0",
101
+ "@deepseek-ai/dsh-client-ui-workspace": ">=0.1.7-rc.1 <0.2.0-0",
102
+ "@deepseek-ai/dsh-command-compact": ">=0.1.7-rc.1 <0.2.0-0",
103
+ "@deepseek-ai/dsh-compaction": ">=0.1.7-rc.1 <0.2.0-0",
104
+ "@deepseek-ai/dsh-compaction-basic": ">=0.1.7-rc.1 <0.2.0-0",
105
+ "@deepseek-ai/dsh-invariants": ">=0.1.7-rc.1 <0.2.0-0",
106
+ "@deepseek-ai/dsh-llm": ">=0.1.7-rc.1 <0.2.0-0",
107
+ "@deepseek-ai/dsh-session": ">=0.1.7-rc.1 <0.2.0-0",
108
+ "@deepseek-ai/dsh-settings": ">=0.1.7-rc.1 <0.2.0-0",
109
+ "@deepseek-ai/dsh-system-prompt": ">=0.1.7-rc.1 <0.2.0-0",
110
+ "@deepseek-ai/dsh-token-meter": ">=0.1.7-rc.1 <0.2.0-0",
111
+ "@deepseek-ai/dsh-tools": ">=0.1.7-rc.1 <0.2.0-0",
112
+ "react": ">=18 <19"
113
+ }
114
+ }
@@ -11,6 +11,7 @@ import {
11
11
  import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../profiles.ts'
12
12
  import { decodeSettings } from './decode.ts'
13
13
  import { en, zh } from './locales.ts'
14
+ import type { SettingsScope } from '@deepseek-ai/dsh-client-ui-settings/client'
14
15
  import { planPresetOptionsOps, presetOptionsOpsAccepted } from './preset-options.ts'
15
16
 
16
17
  /**
@@ -28,19 +29,40 @@ interface SlotsService {
28
29
  declare module '@deepseek-ai/cordis' {
29
30
  interface Context {
30
31
  slots: SlotsService
32
+ configForms: ConfigFormsFace
31
33
  }
32
34
  }
33
35
 
34
36
  // Declare all consumed services (the official client-plugin pattern, and the
35
37
  // shape dsh-thinking-levels proves on this same 0.1.5 host line): cordis holds
36
- // apply until `locale` / `settingsScope` are provided, so registration can use
38
+ // apply until `locale` / `configForms` are provided, so registration can use
37
39
  // them directly. Resolving them lazily via ctx.get() instead races the settings
38
40
  // client's activation — on a loss the apply early-returned and EVERY settings
39
- // entry (the standalone section, the plugins-tab card, the item card) silently
40
- // vanished.
41
- export const inject = ['slots', 'locale', 'settingsScope']
41
+ // entry silently vanished.
42
+ export const inject = ['slots', 'locale', 'configForms']
42
43
  const NS = 'context-compression'
43
44
 
45
+ /** 0.1.7: the profile entry whose config carries the compression settings doc. */
46
+ const ENTRY_ID = 'context-compression-improved-bundle'
47
+
48
+ /** The configForms face this client consumes (structural; 0.1.7 ui-settings). */
49
+ interface ConfigFormsFace {
50
+ get<T>(entryId: string): {
51
+ getSnapshot(): {
52
+ status: 'loading' | 'ready' | 'unavailable'
53
+ value: T | undefined
54
+ revision: number | undefined
55
+ writable: boolean
56
+ base: unknown
57
+ user: unknown
58
+ mode: 'host' | 'memory'
59
+ }
60
+ subscribe(listener: () => void): () => void
61
+ set(field: string, value: unknown): Promise<boolean>
62
+ unset(field: string): Promise<boolean>
63
+ }
64
+ }
65
+
44
66
 
45
67
  function sameCustomPolicy(
46
68
  left: ContextCompressionSettings['custom'],
@@ -68,10 +90,51 @@ function sameCustomPolicy(
68
90
  export function apply(ctx: ClientContext): void {
69
91
  ctx.locale.register(NS, { zh, en })
70
92
  const injected = (): CompressionSelectorInjected => {
71
- // Bind per factory call on the caller's fiber (0.1.5: activation must
72
- // never block on the settings transport; the scope disposer belongs to
73
- // the calling registration's lifecycle).
74
- const scope = ctx.settingsScope.bind<ContextCompressionSettings>({ namespace: NS, decode: decodeSettings })
93
+ // 0.1.7: the compression document rides the selector row's entry config as
94
+ // the volatile `settings` field. The form handle is fetched per factory
95
+ // call on the caller's fiber (same activation rule as the old bind); the
96
+ // wrapper below decodes the stored doc and converts per-field writes into
97
+ // whole-doc commits (a volatile object replaces as one snapshot).
98
+ const form = ctx.configForms.get<Record<string, unknown>>(ENTRY_ID)
99
+ const readDoc = (): ContextCompressionSettings | undefined =>
100
+ decodeSettings(form.getSnapshot().value?.settings)
101
+ const scope: SettingsScope<ContextCompressionSettings> = {
102
+ getSnapshot() {
103
+ const snap = form.getSnapshot()
104
+ return {
105
+ status: snap.status,
106
+ value: readDoc(),
107
+ revision: snap.revision,
108
+ writable: snap.writable,
109
+ base: snap.base,
110
+ user: snap.user,
111
+ mode: snap.mode,
112
+ }
113
+ },
114
+ subscribe: (listener) => form.subscribe(listener),
115
+ set: async (field, value) => {
116
+ const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
117
+ next[field] = value
118
+ await form.set('settings', next)
119
+ },
120
+ unset: async (field) => {
121
+ const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
122
+ delete next[field]
123
+ await form.set('settings', next)
124
+ },
125
+ mutate: async (ops) => {
126
+ const doc = { ...(readDoc() ?? {}) } as Record<string, unknown>
127
+ for (const op of ops) {
128
+ const [head, key] = op.path as [string, string]
129
+ if (head !== 'presetOptions') return
130
+ const section = { ...((doc.presetOptions ?? {}) as Record<string, unknown>) }
131
+ if (op.op === 'unset') delete section[key]
132
+ else section[key] = (op as { value?: unknown }).value
133
+ doc.presetOptions = section
134
+ }
135
+ await form.set('settings', doc)
136
+ },
137
+ }
75
138
  const writeAndConfirm = async (
76
139
  write: () => Promise<void>,
77
140
  accepts: (settings: ContextCompressionSettings) => boolean,