dsh-context-compression-improved 0.7.0-beta.2 → 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.
- package/CHANGELOG.md +9 -0
- package/package.json +17 -18
- package/packages/selector/dsh.plugin.json +1 -1
- package/packages/selector/lib/client.d.ts +44 -0
- package/packages/selector/lib/client.js +1007 -13
- package/packages/selector/lib/{intent-gate.js → config.js} +799 -136
- package/packages/selector/lib/index.d.ts +13 -1
- package/packages/selector/lib/index.js +204 -3
- package/packages/selector/lib/profiles.d.ts +6 -0
- package/packages/selector/lib/pruner.d.ts +6 -0
- package/packages/selector/lib/pruner.js +90 -258
- package/packages/selector/lib/style.css +42 -0
- package/packages/selector/src/client/CompressionProfileControls.tsx +293 -226
- package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
- package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -83
- package/packages/selector/src/client/decode.ts +5 -1
- package/packages/selector/src/client/index.ts +307 -243
- package/packages/selector/src/client/locales/de.ts +43 -0
- package/packages/selector/src/client/locales/es.ts +43 -0
- package/packages/selector/src/client/locales/fr.ts +43 -0
- package/packages/selector/src/client/locales/it.ts +43 -0
- package/packages/selector/src/client/locales/ja.ts +43 -0
- package/packages/selector/src/client/locales/ko.ts +43 -0
- package/packages/selector/src/client/locales/ru.ts +43 -0
- package/packages/selector/src/client/locales.ts +282 -196
- package/packages/selector/src/client/monitor-fab.ts +336 -0
- package/packages/selector/src/client/savings-card.tsx +150 -0
- package/packages/selector/src/client/settings-section.tsx +140 -124
- package/packages/selector/src/index.ts +207 -5
- package/packages/selector/src/profiles.ts +17 -0
- package/packages/selector/src/pruner.ts +96 -2
- package/packages/selector/src/runtime/config.ts +26 -1
- package/packages/selector/src/runtime/monitor.ts +235 -0
- package/packages/selector/src/runtime/retrieve.ts +479 -457
- package/packages/selector/src/runtime/savings.ts +337 -0
- package/packages/selector/src/runtime/types.ts +7 -0
- package/packages/selector/tests/code-skeleton.client.spec.ts +2 -2
- package/packages/selector/tests/custom-contract.client.spec.ts +2 -2
- package/packages/selector/tests/estimator-channel.client.spec.tsx +2 -0
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -188
- package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
- package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
- package/packages/selector/tests/runtime/savings.spec.ts +120 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +177 -165
- package/scripts/packed-install-e2e.mjs +1 -1
- package/scripts/verify-release.mjs +1 -1
|
@@ -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 {
|
|
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
|
}
|