dsh-context-compression-improved 0.7.0-beta.1 → 0.7.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 (83) hide show
  1. package/.github/workflows/ci.yml +39 -39
  2. package/CHANGELOG.ja.md +217 -220
  3. package/CHANGELOG.ko.md +211 -214
  4. package/CHANGELOG.md +401 -376
  5. package/CHANGELOG.zh.md +196 -199
  6. package/README.md +97 -97
  7. package/README.zh.md +86 -86
  8. package/package.json +1 -1
  9. package/packages/selector/dsh.plugin.json +1 -1
  10. package/packages/selector/lib/client.d.ts +44 -0
  11. package/packages/selector/lib/client.js +1733 -6
  12. package/packages/selector/lib/{intent-gate.js → config.js} +799 -136
  13. package/packages/selector/lib/index.d.ts +13 -1
  14. package/packages/selector/lib/index.js +204 -3
  15. package/packages/selector/lib/profiles.d.ts +6 -0
  16. package/packages/selector/lib/pruner.d.ts +6 -0
  17. package/packages/selector/lib/pruner.js +90 -258
  18. package/packages/selector/lib/style.css +88 -46
  19. package/packages/selector/src/client/CompressionProfileControls.tsx +293 -226
  20. package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
  21. package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -83
  22. package/packages/selector/src/client/decode.ts +57 -53
  23. package/packages/selector/src/client/index.ts +307 -213
  24. package/packages/selector/src/client/locales/de.ts +141 -0
  25. package/packages/selector/src/client/locales/es.ts +141 -0
  26. package/packages/selector/src/client/locales/fr.ts +141 -0
  27. package/packages/selector/src/client/locales/it.ts +141 -0
  28. package/packages/selector/src/client/locales/ja.ts +141 -0
  29. package/packages/selector/src/client/locales/ko.ts +141 -0
  30. package/packages/selector/src/client/locales/ru.ts +141 -0
  31. package/packages/selector/src/client/locales.ts +282 -196
  32. package/packages/selector/src/client/monitor-fab.ts +336 -0
  33. package/packages/selector/src/client/savings-card.tsx +150 -0
  34. package/packages/selector/src/client/settings-section.tsx +140 -124
  35. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
  36. package/packages/selector/src/index.ts +207 -5
  37. package/packages/selector/src/preset-overlay.ts +629 -629
  38. package/packages/selector/src/profiles.ts +431 -414
  39. package/packages/selector/src/pruner/content.ts +198 -198
  40. package/packages/selector/src/pruner/state.ts +57 -57
  41. package/packages/selector/src/pruner.ts +2759 -2665
  42. package/packages/selector/src/runtime/audit.ts +303 -303
  43. package/packages/selector/src/runtime/config.ts +756 -731
  44. package/packages/selector/src/runtime/monitor.ts +235 -0
  45. package/packages/selector/src/runtime/reducers.ts +1674 -1674
  46. package/packages/selector/src/runtime/retrieve.ts +479 -457
  47. package/packages/selector/src/runtime/savings.ts +337 -0
  48. package/packages/selector/src/runtime/summary-command.ts +133 -133
  49. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -233
  50. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -204
  51. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -53
  52. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -65
  53. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -125
  54. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -37
  55. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
  56. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +306 -306
  57. package/packages/selector/src/runtime/types.ts +365 -358
  58. package/packages/selector/tests/built/client-artifact.spec.ts +61 -61
  59. package/packages/selector/tests/code-skeleton.client.spec.ts +2 -2
  60. package/packages/selector/tests/custom-contract.client.spec.ts +2 -2
  61. package/packages/selector/tests/estimator-channel.client.spec.tsx +2 -0
  62. package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -188
  63. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
  64. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
  65. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
  66. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
  67. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
  68. package/packages/selector/tests/host-preset-overlay.host.spec.ts +203 -203
  69. package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
  70. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
  71. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
  72. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -62
  73. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -156
  74. package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
  75. package/packages/selector/tests/runtime/savings.spec.ts +120 -0
  76. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -154
  77. package/packages/selector/tests/settings-seat.client.spec.ts +177 -165
  78. package/scripts/packed-components-smoke.mjs +734 -734
  79. package/scripts/packed-install-e2e.mjs +1 -1
  80. package/scripts/verify-release.mjs +1 -1
  81. package/tests/TEST_INVENTORY.md +41 -41
  82. package/tsconfig.tests.json +17 -17
  83. package/vitest.config.ts +57 -57
@@ -2,6 +2,18 @@ import { n as ContextCompressionSettings } from "./profiles.js";
2
2
  import z from "@deepseek-ai/schemastery";
3
3
  import { Context } from "@deepseek-ai/cordis";
4
4
  //#region src/index.d.ts
5
+ /**
6
+ * Floating-panel monitor route (`GET|POST .../monitor?sessionId=…`):
7
+ * - GET → the monitor snapshot (savings aggregate + intent control block +
8
+ * pricing) — the payload shape the panel polls;
9
+ * - POST → session override action (`{"action":"on"|"off"|"clear"}`),
10
+ * driving the exact state machine `/ctx-summary` drives.
11
+ * Registration mirrors the savings route (webServer gate alone, dual channels,
12
+ * single guarded registration); the handler branches on `req.method` because
13
+ * the registration surface is method-agnostic.
14
+ */
15
+ /** Exported for the runtime monitor spec; the entry owns all webServer wiring. */
16
+ declare function registerMonitorRoute(ctx: Context): void;
5
17
  /** Standalone Bundle behavior; the settings/UI owner remains safe when false. */
6
18
  interface Config {
7
19
  /** Add the canonical compression stack to every non-Minimal preset. */
@@ -40,4 +52,4 @@ declare const Config: z<Config>;
40
52
  /** Register the persisted default read by the currently mounted root pruner. */
41
53
  declare function apply(ctx: Context, config?: Config): void;
42
54
  //#endregion
43
- export { Config, apply };
55
+ export { Config, apply, registerMonitorRoute };
@@ -1,7 +1,7 @@
1
- import { a as getLastIntentFold, i as getAdvisorState, n as INTENT_GATE_GROWTH_TOKENS, o as getObservedIntentEnabled, p as setSummaryOverride, s as getSummaryOverride, t as INTENT_GATE_FLOOR_FRACTION, v as DEFAULT_CONTEXT_COMPRESSION_SETTINGS } from "./intent-gate.js";
1
+ import { A as getLastIntentFold, C as estimateSavingsPricing, D as INTENT_GATE_GROWTH_TOKENS, E as INTENT_GATE_FLOOR_FRACTION, M as getSummaryOverride, R as setSummaryOverride, S as buildMonitorSnapshot, U as getSavingsLedger, a as DEFAULT_CONTEXT_COMPRESSION_SETTINGS, j as getObservedIntentEnabled, k as getAdvisorState, w as isSessionOverrideAction, x as applySessionOverride } from "./config.js";
2
2
  import z from "@deepseek-ai/schemastery";
3
- import { AsyncLocalStorage } from "node:async_hooks";
4
3
  import { createHash } from "node:crypto";
4
+ import { AsyncLocalStorage } from "node:async_hooks";
5
5
  import { chmod, mkdtemp, readFile, rename, rm, stat, utimes, writeFile } from "node:fs/promises";
6
6
  import { tmpdir } from "node:os";
7
7
  import { isAbsolute, join } from "node:path";
@@ -594,6 +594,8 @@ function restoreMethod(presets, snapshot) {
594
594
  //#region src/index.ts
595
595
  const ESTIMATOR_CATALOG_ROUTES = ["/endpoint/dsh-context-compression-improved/estimator-catalog", "/api/dsh-context-compression-improved/estimator-catalog"];
596
596
  const ADVISOR_REPORT_ROUTES = ["/endpoint/dsh-context-compression-improved/advisor-report", "/api/dsh-context-compression-improved/advisor-report"];
597
+ const SAVINGS_ROUTES = ["/endpoint/dsh-context-compression-improved/savings", "/api/dsh-context-compression-improved/savings"];
598
+ const MONITOR_ROUTES = ["/endpoint/dsh-context-compression-improved/monitor", "/api/dsh-context-compression-improved/monitor"];
597
599
  function sessionFor(readService, sessionId) {
598
600
  const agents = readService("agents");
599
601
  return typeof agents?.get === "function" ? agents.get(sessionId)?.session : void 0;
@@ -716,6 +718,7 @@ function registerAdvisorReportRoute(ctx) {
716
718
  * never reasons to withhold the route.
717
719
  */
718
720
  const ESTIMATOR_CATALOG_ROUTE_DEPS = ["webServer"];
721
+ /** The estimator-side service the catalog handler enriches its response with. */
719
722
  function asWebServer(value) {
720
723
  if (typeof value !== "object" || value === null) return void 0;
721
724
  return typeof value.register === "function" ? value : void 0;
@@ -809,6 +812,202 @@ function registerEstimatorCatalogRoute(ctx) {
809
812
  log("warn", "context-compression webServer not active yet — estimator catalog route pending: %s", ESTIMATOR_CATALOG_ROUTES.join(", "));
810
813
  }
811
814
  /**
815
+ * Read-only savings snapshot route (`GET .../savings?sessionId=…`): gross saved,
816
+ * offsets (negative savings — compressed content later re-read in full), and net,
817
+ * with exact-tokenizer and chars/4 bases reported separately and never merged.
818
+ * Registration mirrors the estimator-catalog route (webServer gate alone, dual
819
+ * channels for both service arrival orders, single guarded registration).
820
+ */
821
+ function registerSavingsRoute(ctx) {
822
+ const readService = (name) => {
823
+ try {
824
+ return ctx.get(name);
825
+ } catch {
826
+ return;
827
+ }
828
+ };
829
+ const log = (level, message, ...args) => {
830
+ console[level](message, ...args);
831
+ };
832
+ let registered = false;
833
+ const register = (webServer, channel) => {
834
+ if (registered) return;
835
+ const handler = (req, res) => {
836
+ const resTyped = res;
837
+ if (typeof resTyped?.writeHead !== "function" || typeof resTyped?.end !== "function") return;
838
+ let sessionId;
839
+ try {
840
+ const raw = new URL(String(req?.url ?? "/"), "http://localhost").searchParams.get("sessionId");
841
+ if (typeof raw === "string" && raw.length > 0 && raw.length <= 512) sessionId = raw;
842
+ } catch {}
843
+ const snapshot = getSavingsLedger().snapshot(sessionId);
844
+ const pricing = estimateSavingsPricing(readService, snapshot);
845
+ resTyped.writeHead(200, {
846
+ "content-type": "application/json; charset=utf-8",
847
+ "cache-control": "no-cache"
848
+ });
849
+ resTyped.end(JSON.stringify({
850
+ ok: true,
851
+ ...snapshot,
852
+ ...pricing === void 0 ? {} : { pricing }
853
+ }));
854
+ };
855
+ try {
856
+ const disposers = SAVINGS_ROUTES.map((path) => webServer.register({
857
+ kind: "exact",
858
+ path,
859
+ handler
860
+ })).filter((off) => typeof off === "function");
861
+ registered = true;
862
+ ctx.effect(() => () => {
863
+ for (const off of disposers) off();
864
+ }, "contextCompressionSelector.savings route");
865
+ log("info", "context-compression savings route registered (%s): %s", channel, SAVINGS_ROUTES.join(", "));
866
+ } catch (error) {
867
+ log("warn", "context-compression savings route registration failed (%s): %o", channel, error);
868
+ }
869
+ };
870
+ const active = asWebServer(readService("webServer"));
871
+ if (active !== void 0) {
872
+ register(active, "direct");
873
+ if (registered) return;
874
+ }
875
+ ctx.inject(["webServer"], (injected) => {
876
+ const webServer = asWebServer(injected.webServer);
877
+ if (webServer === void 0) {
878
+ log("warn", "context-compression webServer exposes no register() — savings route not registered");
879
+ return;
880
+ }
881
+ register(webServer, "inject");
882
+ });
883
+ }
884
+ /**
885
+ * Floating-panel monitor route (`GET|POST .../monitor?sessionId=…`):
886
+ * - GET → the monitor snapshot (savings aggregate + intent control block +
887
+ * pricing) — the payload shape the panel polls;
888
+ * - POST → session override action (`{"action":"on"|"off"|"clear"}`),
889
+ * driving the exact state machine `/ctx-summary` drives.
890
+ * Registration mirrors the savings route (webServer gate alone, dual channels,
891
+ * single guarded registration); the handler branches on `req.method` because
892
+ * the registration surface is method-agnostic.
893
+ */
894
+ /** Exported for the runtime monitor spec; the entry owns all webServer wiring. */
895
+ function registerMonitorRoute(ctx) {
896
+ const readService = (name) => {
897
+ try {
898
+ return ctx.get(name);
899
+ } catch {
900
+ return;
901
+ }
902
+ };
903
+ const log = (level, message, ...args) => {
904
+ console[level](message, ...args);
905
+ };
906
+ let registered = false;
907
+ const register = (webServer, channel) => {
908
+ if (registered) return;
909
+ const handler = (req, res) => {
910
+ const resTyped = res;
911
+ if (typeof resTyped?.writeHead !== "function" || typeof resTyped?.end !== "function") return;
912
+ let sessionId;
913
+ try {
914
+ const raw = new URL(String(req?.url ?? "/"), "http://localhost").searchParams.get("sessionId");
915
+ if (typeof raw === "string" && raw.length > 0 && raw.length <= 512) sessionId = raw;
916
+ } catch {}
917
+ if (String(req?.method ?? "GET").toUpperCase() === "POST") {
918
+ const chunks = [];
919
+ let size = 0;
920
+ let done = false;
921
+ const respond = (status, body) => {
922
+ if (done) return;
923
+ done = true;
924
+ resTyped.writeHead(status, {
925
+ "content-type": "application/json; charset=utf-8",
926
+ "cache-control": "no-cache"
927
+ });
928
+ resTyped.end(JSON.stringify(body));
929
+ };
930
+ const reqTyped = req;
931
+ if (typeof reqTyped?.on !== "function") {
932
+ respond(400, {
933
+ ok: false,
934
+ error: "unreadable request body"
935
+ });
936
+ return;
937
+ }
938
+ reqTyped.on("data", (chunk) => {
939
+ size += chunk?.length ?? 0;
940
+ if (size <= 4096) chunks.push(Buffer.from(chunk ?? /* @__PURE__ */ new Uint8Array()));
941
+ });
942
+ reqTyped.on("end", () => {
943
+ let action;
944
+ try {
945
+ action = JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}").action;
946
+ } catch {
947
+ respond(400, {
948
+ ok: false,
949
+ error: "monitor override action must be JSON"
950
+ });
951
+ return;
952
+ }
953
+ if (!isSessionOverrideAction(action)) {
954
+ respond(400, {
955
+ ok: false,
956
+ error: "monitor override action must be \"on\" | \"off\" | \"clear\""
957
+ });
958
+ return;
959
+ }
960
+ const { override } = applySessionOverride(sessionId ?? "", action);
961
+ respond(200, {
962
+ ok: true,
963
+ override: override ?? null,
964
+ sessionScope: sessionId ?? null
965
+ });
966
+ });
967
+ return;
968
+ }
969
+ const snapshot = buildMonitorSnapshot(sessionId);
970
+ const pricing = estimateSavingsPricing(readService, snapshot);
971
+ resTyped.writeHead(200, {
972
+ "content-type": "application/json; charset=utf-8",
973
+ "cache-control": "no-cache"
974
+ });
975
+ resTyped.end(JSON.stringify({
976
+ ok: true,
977
+ ...snapshot,
978
+ ...pricing === void 0 ? {} : { pricing }
979
+ }));
980
+ };
981
+ try {
982
+ const disposers = MONITOR_ROUTES.map((path) => webServer.register({
983
+ kind: "exact",
984
+ path,
985
+ handler
986
+ })).filter((off) => typeof off === "function");
987
+ registered = true;
988
+ ctx.effect(() => () => {
989
+ for (const off of disposers) off();
990
+ }, "contextCompressionSelector.monitor route");
991
+ log("info", "context-compression monitor route registered (%s): %s", channel, MONITOR_ROUTES.join(", "));
992
+ } catch (error) {
993
+ log("warn", "context-compression monitor route registration failed (%s): %o", channel, error);
994
+ }
995
+ };
996
+ const active = asWebServer(readService("webServer"));
997
+ if (active !== void 0) {
998
+ register(active, "direct");
999
+ if (registered) return;
1000
+ }
1001
+ ctx.inject(["webServer"], (injected) => {
1002
+ const webServer = asWebServer(injected.webServer);
1003
+ if (webServer === void 0) {
1004
+ log("warn", "context-compression webServer exposes no register() — monitor route not registered");
1005
+ return;
1006
+ }
1007
+ register(webServer, "inject");
1008
+ });
1009
+ }
1010
+ /**
812
1011
  * Resolve one possibly-volatile field: a live ref on 0.1.7+, a plain value
813
1012
  * otherwise (0.1.7 hands `.volatile()` fields to `apply()` as live refs).
814
1013
  */
@@ -831,6 +1030,8 @@ const Config = z.object({
831
1030
  function apply(ctx, config = {}) {
832
1031
  try {
833
1032
  if (config.estimatorCatalogRoute === true) registerEstimatorCatalogRoute(ctx);
1033
+ registerSavingsRoute(ctx);
1034
+ registerMonitorRoute(ctx);
834
1035
  if (config.advisorReportRoute === true) registerAdvisorReportRoute(ctx);
835
1036
  registerSummaryCommand(ctx);
836
1037
  if (config.presetOverlay !== true) return;
@@ -863,4 +1064,4 @@ function resolveAutoCompactThresholdPercent(config, presetsCtx) {
863
1064
  }
864
1065
  }
865
1066
  //#endregion
866
- export { Config, apply };
1067
+ export { Config, apply, registerMonitorRoute };
@@ -75,6 +75,10 @@ interface CodeSkeletonSettings {
75
75
  interface IntentSummarySettings {
76
76
  enabled: boolean;
77
77
  }
78
+ /** Floating compression-monitor panel (FAB); visibility switch. */
79
+ interface MonitorPanelSettings {
80
+ enabled: boolean;
81
+ }
78
82
  /** Browser-safe mirror of the runtime presetOptions section. */
79
83
  interface PresetOptionsSettings {
80
84
  readonly dedupeToolResults?: boolean;
@@ -107,6 +111,8 @@ interface ContextCompressionSettings {
107
111
  codeSkeleton: CodeSkeletonSettings;
108
112
  /** Turn-tail intent-summary gate captured independently of `profile`. */
109
113
  intentSummary: IntentSummarySettings;
114
+ /** Floating compression-monitor panel (FAB); absent inherits hidden. */
115
+ monitorPanel?: MonitorPanelSettings;
110
116
  /** Optional tokenpilot-inspired sub-capability overrides (presence-validated only). */
111
117
  presetOptions?: PresetOptionsSettings;
112
118
  }
@@ -143,6 +143,10 @@ interface CodeSkeletonSettings {
143
143
  interface IntentSummarySettings {
144
144
  enabled: boolean;
145
145
  }
146
+ /** Floating compression-monitor panel (FAB); visibility switch. */
147
+ interface MonitorPanelSettings {
148
+ enabled: boolean;
149
+ }
146
150
  /**
147
151
  * Persisted sub-capability overrides for the `tokenpilot-inspired` preset.
148
152
  * Absent fields inherit the preset defaults; the section is only meaningful
@@ -184,6 +188,8 @@ interface ContextCompressionSettings {
184
188
  codeSkeleton: CodeSkeletonSettings;
185
189
  /** Turn-tail intent-summary gate snapped independently of `profile`. */
186
190
  intentSummary: IntentSummarySettings;
191
+ /** Floating compression-monitor panel (FAB); absent inherits hidden. */
192
+ monitorPanel?: MonitorPanelSettings;
187
193
  /** Optional tokenpilot-inspired sub-capability overrides; absent inherits preset defaults. */
188
194
  presetOptions?: PresetOptionsSettings;
189
195
  }