dsh-context-compression-improved 0.9.3 → 0.9.7
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.de.md +3 -3
- package/README.es.md +3 -3
- package/README.fr.md +3 -3
- package/README.it.md +3 -3
- package/README.ja.md +16 -3
- package/README.ko.md +16 -3
- package/README.md +16 -3
- package/README.ru.md +3 -3
- package/README.zh.md +16 -3
- package/assets/board.png +0 -0
- package/assets/context.png +0 -0
- package/docs/installation.de.md +2 -2
- package/docs/installation.es.md +2 -2
- package/docs/installation.fr.md +2 -2
- package/docs/installation.it.md +2 -2
- package/docs/installation.ja.md +2 -2
- package/docs/installation.ko.md +2 -2
- package/docs/installation.md +2 -2
- package/docs/installation.ru.md +2 -2
- package/docs/installation.zh.md +2 -2
- package/package.json +7 -6
- package/packages/selector/dsh.plugin.json +2 -2
- package/packages/selector/lib/client.d.ts +1 -0
- package/packages/selector/lib/client.js +63 -10
- package/packages/selector/lib/config.js +71 -7
- package/packages/selector/lib/index.js +145 -20
- package/packages/selector/lib/pruner.d.ts +158 -107
- package/packages/selector/lib/pruner.js +332 -22
- package/packages/selector/lib/tail-trim.js +25 -2
- package/packages/selector/package.json +22 -21
- package/packages/selector/src/client/index.ts +29 -2
- package/packages/selector/src/client/locales/de.ts +1 -0
- package/packages/selector/src/client/locales/es.ts +1 -0
- package/packages/selector/src/client/locales/fr.ts +1 -0
- package/packages/selector/src/client/locales/it.ts +1 -0
- package/packages/selector/src/client/locales/ja.ts +1 -0
- package/packages/selector/src/client/locales/ko.ts +1 -0
- package/packages/selector/src/client/locales/ru.ts +1 -0
- package/packages/selector/src/client/locales.ts +2 -0
- package/packages/selector/src/client/monitor-fab.ts +19 -4
- package/packages/selector/src/compat/llm-messages.ts +50 -0
- package/packages/selector/src/index.ts +27 -0
- package/packages/selector/src/preset-overlay.ts +145 -22
- package/packages/selector/src/pruner/content.ts +1 -1
- package/packages/selector/src/pruner/state.ts +4 -0
- package/packages/selector/src/pruner.ts +109 -16
- package/packages/selector/src/runtime/config.ts +1 -1
- package/packages/selector/src/runtime/reducers.ts +81 -1
- package/packages/selector/src/runtime/retrieve.ts +4 -3
- package/packages/selector/src/runtime/savings-projection.ts +226 -0
- package/packages/selector/src/runtime/savings.ts +83 -3
- package/packages/selector/src/runtime/tail-trim.ts +2 -1
- package/packages/selector/tests/public/package-contract.client.spec.ts +4 -4
- package/packages/selector/tests/runtime/fresh-gate.spec.ts +43 -0
- package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +79 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +48 -0
- package/packages/selector/tests/runtime/savings-projection.spec.ts +89 -0
- package/packages/selector/tests/runtime/savings.spec.ts +22 -3
- package/packages/selector/tests/runtime/settings-unwrap.spec.ts +58 -0
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +5 -2
- package/pnpm-workspace.yaml +6 -0
- package/screenshots.json +6 -0
- package/scripts/hosts.mjs +5 -2
- package/scripts/packed-install-e2e.mjs +19 -3
- package/scripts/sync-hosts.mjs +2 -2
- package/scripts/verify-release.mjs +6 -6
|
@@ -1608,6 +1608,10 @@ window.__ModuleLoader__.load({
|
|
|
1608
1608
|
x: 0,
|
|
1609
1609
|
y: 0
|
|
1610
1610
|
};
|
|
1611
|
+
let startPos = {
|
|
1612
|
+
x: 0,
|
|
1613
|
+
y: 0
|
|
1614
|
+
};
|
|
1611
1615
|
el.addEventListener("pointerdown", (e) => {
|
|
1612
1616
|
active = true;
|
|
1613
1617
|
moved = false;
|
|
@@ -1615,13 +1619,17 @@ window.__ModuleLoader__.load({
|
|
|
1615
1619
|
x: e.clientX,
|
|
1616
1620
|
y: e.clientY
|
|
1617
1621
|
};
|
|
1622
|
+
startPos = {
|
|
1623
|
+
x: pos.x,
|
|
1624
|
+
y: pos.y
|
|
1625
|
+
};
|
|
1618
1626
|
el.setPointerCapture(e.pointerId);
|
|
1619
1627
|
});
|
|
1620
1628
|
el.addEventListener("pointermove", (e) => {
|
|
1621
1629
|
if (!active) return;
|
|
1622
1630
|
const next = clamp({
|
|
1623
|
-
x:
|
|
1624
|
-
y:
|
|
1631
|
+
x: startPos.x + (e.clientX - origin.x),
|
|
1632
|
+
y: startPos.y + (e.clientY - origin.y)
|
|
1625
1633
|
});
|
|
1626
1634
|
if (Math.abs(next.x - pos.x) > 2 || Math.abs(next.y - pos.y) > 2) moved = true;
|
|
1627
1635
|
pos = key === "fab" ? next : pos;
|
|
@@ -1665,10 +1673,22 @@ window.__ModuleLoader__.load({
|
|
|
1665
1673
|
let stale = false;
|
|
1666
1674
|
let busyAction = false;
|
|
1667
1675
|
const fmtTokens = (n) => num(n).toLocaleString("en-US");
|
|
1676
|
+
const lead = (exact, estimated) => {
|
|
1677
|
+
const ex = num(exact);
|
|
1678
|
+
const es = num(estimated);
|
|
1679
|
+
return ex !== 0 ? {
|
|
1680
|
+
v: ex,
|
|
1681
|
+
est: false
|
|
1682
|
+
} : {
|
|
1683
|
+
v: es,
|
|
1684
|
+
est: es !== 0
|
|
1685
|
+
};
|
|
1686
|
+
};
|
|
1668
1687
|
const render = (snap) => {
|
|
1669
1688
|
const net = num(snap.net?.exact) + num(snap.net?.estimated);
|
|
1670
1689
|
const netEl = panel.querySelector("[data-net]");
|
|
1671
|
-
|
|
1690
|
+
const netLead = lead(snap.net?.exact, snap.net?.estimated);
|
|
1691
|
+
netEl.textContent = netLead.est ? `${fmtTokens(netLead.v)} est` : fmtTokens(netLead.v);
|
|
1672
1692
|
netEl.classList.toggle("neg", net < 0);
|
|
1673
1693
|
const suggest = snap.suggestion?.suggest === true;
|
|
1674
1694
|
fab.classList.toggle("lit", suggest || net < 0);
|
|
@@ -1678,8 +1698,10 @@ window.__ModuleLoader__.load({
|
|
|
1678
1698
|
hint.textContent = t("monitor.panel.suggest").replace("{pct}", String(pct ?? "–"));
|
|
1679
1699
|
hint.classList.add("show");
|
|
1680
1700
|
} else hint.classList.remove("show");
|
|
1681
|
-
|
|
1682
|
-
panel.querySelector("[data-
|
|
1701
|
+
const grossLead = lead(snap.gross?.exact, snap.gross?.estimated);
|
|
1702
|
+
panel.querySelector("[data-gross]").textContent = grossLead.est ? `${fmtTokens(grossLead.v)} est` : fmtTokens(grossLead.v);
|
|
1703
|
+
const offLead = lead(snap.offsets?.exact, snap.offsets?.estimated);
|
|
1704
|
+
panel.querySelector("[data-offsets]").textContent = offLead.est ? `-${fmtTokens(offLead.v)} est` : `-${fmtTokens(offLead.v)}`;
|
|
1683
1705
|
const ctxBar = panel.querySelector("[data-ctxbar]");
|
|
1684
1706
|
const ctxPct = panel.querySelector("[data-ctxpct]");
|
|
1685
1707
|
const ctxPctNum = typeof snap.context?.pct === "number" ? snap.context.pct : null;
|
|
@@ -1840,6 +1862,7 @@ window.__ModuleLoader__.load({
|
|
|
1840
1862
|
"monitor.panel.cost": "成本(实际 / 省估)",
|
|
1841
1863
|
"monitor.panel.intent": "意图摘要",
|
|
1842
1864
|
"monitor.panel.overrideHint": "会话覆盖",
|
|
1865
|
+
"monitor.panel.overridePrefix": "会话覆盖",
|
|
1843
1866
|
"monitor.panel.resume": "恢复",
|
|
1844
1867
|
"monitor.panel.disable": "停用",
|
|
1845
1868
|
"monitor.panel.stateOn": "开",
|
|
@@ -1978,6 +2001,7 @@ window.__ModuleLoader__.load({
|
|
|
1978
2001
|
"monitor.panel.cost": "Cost (actual / saved est.)",
|
|
1979
2002
|
"monitor.panel.intent": "Intent summary",
|
|
1980
2003
|
"monitor.panel.overrideHint": "Session override",
|
|
2004
|
+
"monitor.panel.overridePrefix": "Session override",
|
|
1981
2005
|
"monitor.panel.resume": "Resume",
|
|
1982
2006
|
"monitor.panel.disable": "Disable",
|
|
1983
2007
|
"monitor.panel.stateOn": "on",
|
|
@@ -2118,6 +2142,7 @@ window.__ModuleLoader__.load({
|
|
|
2118
2142
|
"monitor.panel.cost": "Kosten (ist / gespart gesch.)",
|
|
2119
2143
|
"monitor.panel.intent": "Intent-Zusammenfassung",
|
|
2120
2144
|
"monitor.panel.overrideHint": "Sitzungs-Übersteuerung",
|
|
2145
|
+
"monitor.panel.overridePrefix": "Sitzungs-Übersteuerung",
|
|
2121
2146
|
"monitor.panel.resume": "Fortsetzen",
|
|
2122
2147
|
"monitor.panel.disable": "Deaktivieren",
|
|
2123
2148
|
"monitor.panel.stateOn": "ein",
|
|
@@ -2258,6 +2283,7 @@ window.__ModuleLoader__.load({
|
|
|
2258
2283
|
"monitor.panel.cost": "Coste (real / ahorro est.)",
|
|
2259
2284
|
"monitor.panel.intent": "Resumen de intención",
|
|
2260
2285
|
"monitor.panel.overrideHint": "Invalidación de sesión",
|
|
2286
|
+
"monitor.panel.overridePrefix": "Invalidación de sesión",
|
|
2261
2287
|
"monitor.panel.resume": "Reanudar",
|
|
2262
2288
|
"monitor.panel.disable": "Desactivar",
|
|
2263
2289
|
"monitor.panel.stateOn": "sí",
|
|
@@ -2398,6 +2424,7 @@ window.__ModuleLoader__.load({
|
|
|
2398
2424
|
"monitor.panel.cost": "Coût (réel / écon. est.)",
|
|
2399
2425
|
"monitor.panel.intent": "Résumé d'intention",
|
|
2400
2426
|
"monitor.panel.overrideHint": "Priorité de session",
|
|
2427
|
+
"monitor.panel.overridePrefix": "Priorité de session",
|
|
2401
2428
|
"monitor.panel.resume": "Reprendre",
|
|
2402
2429
|
"monitor.panel.disable": "Désactiver",
|
|
2403
2430
|
"monitor.panel.stateOn": "activé",
|
|
@@ -2538,6 +2565,7 @@ window.__ModuleLoader__.load({
|
|
|
2538
2565
|
"monitor.panel.cost": "Costo (effettivo / stimo)",
|
|
2539
2566
|
"monitor.panel.intent": "Riepilogo di intento",
|
|
2540
2567
|
"monitor.panel.overrideHint": "Override di sessione",
|
|
2568
|
+
"monitor.panel.overridePrefix": "Override di sessione",
|
|
2541
2569
|
"monitor.panel.resume": "Riprendi",
|
|
2542
2570
|
"monitor.panel.disable": "Disattiva",
|
|
2543
2571
|
"monitor.panel.stateOn": "on",
|
|
@@ -2678,6 +2706,7 @@ window.__ModuleLoader__.load({
|
|
|
2678
2706
|
"monitor.panel.cost": "コスト(実績 / 節約概算)",
|
|
2679
2707
|
"monitor.panel.intent": "インテント要約",
|
|
2680
2708
|
"monitor.panel.overrideHint": "セッション上書き",
|
|
2709
|
+
"monitor.panel.overridePrefix": "セッション上書き",
|
|
2681
2710
|
"monitor.panel.resume": "再開",
|
|
2682
2711
|
"monitor.panel.disable": "停止",
|
|
2683
2712
|
"monitor.panel.stateOn": "オン",
|
|
@@ -2818,6 +2847,7 @@ window.__ModuleLoader__.load({
|
|
|
2818
2847
|
"monitor.panel.cost": "비용 (실제 / 절감 추정)",
|
|
2819
2848
|
"monitor.panel.intent": "인텐트 요약",
|
|
2820
2849
|
"monitor.panel.overrideHint": "세션 재정의",
|
|
2850
|
+
"monitor.panel.overridePrefix": "세션 재정의",
|
|
2821
2851
|
"monitor.panel.resume": "재개",
|
|
2822
2852
|
"monitor.panel.disable": "중지",
|
|
2823
2853
|
"monitor.panel.stateOn": "켬",
|
|
@@ -2958,6 +2988,7 @@ window.__ModuleLoader__.load({
|
|
|
2958
2988
|
"monitor.panel.cost": "Стоимость (факт / эконом. оценка)",
|
|
2959
2989
|
"monitor.panel.intent": "Итог намерения",
|
|
2960
2990
|
"monitor.panel.overrideHint": "Приоритет сессии",
|
|
2991
|
+
"monitor.panel.overridePrefix": "Приоритет сессии",
|
|
2961
2992
|
"monitor.panel.resume": "Возобновить",
|
|
2962
2993
|
"monitor.panel.disable": "Отключить",
|
|
2963
2994
|
"monitor.panel.stateOn": "вкл",
|
|
@@ -3215,10 +3246,14 @@ window.__ModuleLoader__.load({
|
|
|
3215
3246
|
return left.version === right.version && left.unit === right.unit && left.prefixPolicy === right.prefixPolicy && left.fresh.enabled === right.fresh.enabled && left.fresh.trigger === right.fresh.trigger && left.fresh.target === right.fresh.target && left.aggregate.enabled === right.aggregate.enabled && left.aggregate.trigger === right.aggregate.trigger && left.aggregate.target === right.aggregate.target && left.history.enabled === right.history.enabled && left.history.trigger === right.history.trigger && left.history.keepRecentToolCalls === right.history.keepRecentToolCalls && left.history.keepRecentTokens === right.history.keepRecentTokens && left.history.minReclaim === right.history.minReclaim && left.tailTrim.enabled === right.tailTrim.enabled && left.tailTrim.trigger === right.tailTrim.trigger;
|
|
3216
3247
|
}
|
|
3217
3248
|
function apply(ctx) {
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3249
|
+
try {
|
|
3250
|
+
ctx.locale.register(NS, {
|
|
3251
|
+
zh,
|
|
3252
|
+
en
|
|
3253
|
+
});
|
|
3254
|
+
} catch (error) {
|
|
3255
|
+
console.warn("[dsh-context-compression-improved] locale 默认包(zh/en) 已注册,跳过:", error);
|
|
3256
|
+
}
|
|
3222
3257
|
const languages = [
|
|
3223
3258
|
{
|
|
3224
3259
|
id: "de",
|
|
@@ -3270,6 +3305,8 @@ window.__ModuleLoader__.load({
|
|
|
3270
3305
|
let configFormsHandle;
|
|
3271
3306
|
/** Last monitorPanel.enabled seen through whichever scope is current (FAB 读数缓存). */
|
|
3272
3307
|
let monitorPanelEnabledCache = false;
|
|
3308
|
+
/** configForms 臂是否已经成功读过一次文档(FAB 读数是否可信)。 */
|
|
3309
|
+
let nativeMonitorReady = false;
|
|
3273
3310
|
/** 浮动监控面板(FAB): body 级幂等单例。enabled 读数走双臂 scope 的投影缓存。 */
|
|
3274
3311
|
let readMonitorPanelEnabled = () => monitorPanelEnabledCache;
|
|
3275
3312
|
let latestSessionId;
|
|
@@ -3299,12 +3336,27 @@ window.__ModuleLoader__.load({
|
|
|
3299
3336
|
const bridgeScope = createBridgeScope();
|
|
3300
3337
|
bridgeScope.refresh();
|
|
3301
3338
|
const bridgeReadEnabled = () => decodeSettings(bridgeScope.getSnapshot().value)?.monitorPanel?.enabled ?? false;
|
|
3302
|
-
readMonitorPanelEnabled = () => configFormsHandle
|
|
3339
|
+
readMonitorPanelEnabled = () => configFormsHandle !== void 0 && nativeMonitorReady ? monitorPanelEnabledCache : bridgeReadEnabled();
|
|
3303
3340
|
try {
|
|
3304
3341
|
ctx.inject(["configForms"], (configFormsArg) => {
|
|
3305
3342
|
const svc = configFormsArg?.configForms;
|
|
3306
3343
|
const face = svc !== void 0 && svc !== null ? svc : configFormsArg;
|
|
3307
3344
|
configFormsHandle = typeof face?.get === "function" ? face : void 0;
|
|
3345
|
+
if (configFormsHandle !== void 0) try {
|
|
3346
|
+
const form = configFormsHandle.get(ENTRY_ID);
|
|
3347
|
+
const refresh = () => {
|
|
3348
|
+
monitorPanelEnabledCache = decodeSettings(form.getSnapshot().value?.settings)?.monitorPanel?.enabled ?? false;
|
|
3349
|
+
nativeMonitorReady = true;
|
|
3350
|
+
};
|
|
3351
|
+
refresh();
|
|
3352
|
+
form.subscribe(() => {
|
|
3353
|
+
try {
|
|
3354
|
+
refresh();
|
|
3355
|
+
} catch {}
|
|
3356
|
+
});
|
|
3357
|
+
} catch (error) {
|
|
3358
|
+
console.warn("[dsh-context-compression-improved] FAB 读数预热失败(沿用桥面):", error);
|
|
3359
|
+
}
|
|
3308
3360
|
});
|
|
3309
3361
|
} catch (error) {
|
|
3310
3362
|
console.warn("[dsh-context-compression-improved] configForms 臂挂载失败(桥面继续服务):", error);
|
|
@@ -3339,6 +3391,7 @@ window.__ModuleLoader__.load({
|
|
|
3339
3391
|
};
|
|
3340
3392
|
}
|
|
3341
3393
|
monitorPanelEnabledCache = projected.value?.monitorPanel?.enabled ?? false;
|
|
3394
|
+
nativeMonitorReady = true;
|
|
3342
3395
|
return projected;
|
|
3343
3396
|
},
|
|
3344
3397
|
subscribe: (listener) => form.subscribe(listener),
|
|
@@ -74,7 +74,12 @@ var SavingsLedger = class {
|
|
|
74
74
|
const hit = snap.usage.cacheHitRate;
|
|
75
75
|
return `net=${snap.net.exact}(exact)/${snap.net.estimated}(est) gross=${snap.gross.exact}/${snap.gross.estimated} offsets=${snap.offsets.exact}/${snap.offsets.estimated} requests=${snap.usage.requests} cacheHit=${hit === null ? "–" : `${Math.round(hit * 100)}%`}`;
|
|
76
76
|
}
|
|
77
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* 记录一次已落盘的压缩节省(land 成功后调用;tokensRemoved ≤ 0 忽略)。
|
|
79
|
+
*
|
|
80
|
+
* 仪表口径:该条目在替换事件离开当前 surface 前一直计入"当前生效毛节省"
|
|
81
|
+
* (由 {@link observeActive} 每回合收敛),不再一次性永久累加。
|
|
82
|
+
*/
|
|
78
83
|
recordSaving(input) {
|
|
79
84
|
const removed = input.tokensBefore - input.tokensAfter;
|
|
80
85
|
if (!Number.isFinite(removed) || removed <= 0) return;
|
|
@@ -83,7 +88,8 @@ var SavingsLedger = class {
|
|
|
83
88
|
component: input.component,
|
|
84
89
|
tokens: removed,
|
|
85
90
|
basis: input.basis,
|
|
86
|
-
at: Date.now()
|
|
91
|
+
at: Date.now(),
|
|
92
|
+
...input.replacementSeq === void 0 ? {} : { replacementSeq: input.replacementSeq }
|
|
87
93
|
});
|
|
88
94
|
if (typeof input.originalText === "string" && input.originalText.length > 0) {
|
|
89
95
|
const hash = savingsHash(input.originalText);
|
|
@@ -116,8 +122,7 @@ var SavingsLedger = class {
|
|
|
116
122
|
this.seenFullText.add(seenKey);
|
|
117
123
|
}
|
|
118
124
|
const hit = this.registry.get(savingsHash(input.text));
|
|
119
|
-
if (hit === void 0 || hit.
|
|
120
|
-
hit.consumed = true;
|
|
125
|
+
if (hit === void 0 || hit.sessionId !== input.sessionId) return;
|
|
121
126
|
const { tokens, basis } = input.measure(input.text);
|
|
122
127
|
if (tokens <= 0) return;
|
|
123
128
|
this.push(input.sessionId, {
|
|
@@ -153,6 +158,65 @@ var SavingsLedger = class {
|
|
|
153
158
|
list.push(entry);
|
|
154
159
|
if (list.length > MAX_ENTRIES_PER_SESSION) list.splice(0, list.length - MAX_ENTRIES_PER_SESSION);
|
|
155
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* 仪表口径收敛:一个 'saving' 条目只在其替换事件仍位于当前 surface 时计为
|
|
163
|
+
* "当前生效毛节省"。pruner 每回合传入存活 seq 集合,离开 surface 的替换
|
|
164
|
+
* (被后续压缩/裁剪替换)即从毛节省中扣除,数字随压缩内容进出而涨落。
|
|
165
|
+
* 无 replacementSeq 的条目保持原样(无法追踪者不收敛)。
|
|
166
|
+
*/
|
|
167
|
+
observeActive(sessionId, liveSeqs) {
|
|
168
|
+
const list = this.entries.get(sessionId);
|
|
169
|
+
if (list === void 0) return;
|
|
170
|
+
const kept = list.filter((entry) => entry.kind !== "saving" || entry.replacementSeq === void 0 || liveSeqs.has(entry.replacementSeq));
|
|
171
|
+
if (kept.length !== list.length) this.entries.set(sessionId, kept);
|
|
172
|
+
}
|
|
173
|
+
/** 该会话是否已有账本条目(重进会话时用于避免投影与实时叠加)。 */
|
|
174
|
+
hasSession(sessionId) {
|
|
175
|
+
return this.entries.has(sessionId);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* 用会话日志投影播种一个会话的账本(重进/重启会话时调用一次)。写入
|
|
179
|
+
* savings/offsets 条目及其原文配对 registry,后续实时增量(observeActive /
|
|
180
|
+
* noteFullText)在同一条目集合上继续工作。调用方负责只播种一次。
|
|
181
|
+
*/
|
|
182
|
+
seedProjected(sessionId, projection) {
|
|
183
|
+
for (const entry of projection.savings) {
|
|
184
|
+
if (!Number.isFinite(entry.tokens) || entry.tokens <= 0) continue;
|
|
185
|
+
this.push(sessionId, {
|
|
186
|
+
kind: "saving",
|
|
187
|
+
component: entry.component,
|
|
188
|
+
tokens: entry.tokens,
|
|
189
|
+
basis: entry.basis,
|
|
190
|
+
at: entry.at,
|
|
191
|
+
replacementSeq: entry.replacementSeq
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
for (const entry of projection.offsets) {
|
|
195
|
+
if (!Number.isFinite(entry.tokens) || entry.tokens <= 0) continue;
|
|
196
|
+
this.push(sessionId, {
|
|
197
|
+
kind: "offset",
|
|
198
|
+
component: entry.component,
|
|
199
|
+
tokens: entry.tokens,
|
|
200
|
+
basis: entry.basis,
|
|
201
|
+
at: entry.at,
|
|
202
|
+
...entry.note === void 0 ? {} : { note: entry.note }
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
for (const item of projection.registry) {
|
|
206
|
+
if (this.registry.size >= MAX_REGISTRY && !this.registry.has(item.hash)) {
|
|
207
|
+
const oldest = this.registry.keys().next().value;
|
|
208
|
+
if (oldest !== void 0) this.registry.delete(oldest);
|
|
209
|
+
}
|
|
210
|
+
this.registry.set(item.hash, {
|
|
211
|
+
sessionId,
|
|
212
|
+
component: "projection",
|
|
213
|
+
claimedTokens: item.claimedTokens,
|
|
214
|
+
basis: item.basis,
|
|
215
|
+
sourceSeq: item.sourceSeq,
|
|
216
|
+
consumed: false
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
156
220
|
/** 汇总快照。sessionId 缺省 = 全会话聚合。两个 basis 分列,永不合并。 */
|
|
157
221
|
snapshot(sessionId) {
|
|
158
222
|
const scope = sessionId === void 0 ? [...this.entries.keys()] : [sessionId];
|
|
@@ -1662,8 +1726,8 @@ function resolvePolicy(config, profile, custom = DEFAULT_CUSTOM_COMPRESSION_POLI
|
|
|
1662
1726
|
historyMode: "routine",
|
|
1663
1727
|
nativeTriggerTokens: Number.MAX_SAFE_INTEGER,
|
|
1664
1728
|
nativeTargetTokens: Number.MAX_SAFE_INTEGER,
|
|
1665
|
-
freshTriggerTokens:
|
|
1666
|
-
freshTargetTokens:
|
|
1729
|
+
freshTriggerTokens: 4096,
|
|
1730
|
+
freshTargetTokens: 1536,
|
|
1667
1731
|
aggregateTriggerTokens: 32768,
|
|
1668
1732
|
aggregateTargetTokens: 12288,
|
|
1669
1733
|
historyTriggerTokens: 5e5,
|
|
@@ -1710,4 +1774,4 @@ function assertNonNegativeInteger(name, value) {
|
|
|
1710
1774
|
if (!Number.isSafeInteger(value) || value < 0) throw new Error(`ToolResultPruneConfig: ${name} (${String(value)}) must be a non-negative safe integer`);
|
|
1711
1775
|
}
|
|
1712
1776
|
//#endregion
|
|
1713
|
-
export { getLastIntentFold as A, decimalRateNanoUnits as B, estimateSavingsPricing as C, INTENT_GATE_GROWTH_TOKENS as D, INTENT_GATE_FLOOR_FRACTION as E, recordIntentFold as F, resolveOfficialDeepSeekPrice as H, recordRecertified as I, recordScore as L, getSummaryOverride as M, invalidateOnTaskChange as N, evaluateIntentGate as O, observeIntentEnabled as P, setSummaryOverride as R, buildMonitorSnapshot as S, observeContextUsage as T, getSavingsLedger as U, priceOfficialDeepSeekUsage as V, resolveCustomPolicy as _, DEFAULT_CONTEXT_COMPRESSION_SETTINGS as a, COMPRESSION_PROFILES as b, charsToTokens as c, isValidAutoCompactThresholdPercent as d, parseContextCompressionSettings as f, DEFAULT_CUSTOM_COMPRESSION_POLICY as g, CustomCompressionPolicySchema as h, DEFAULTS as i, getObservedIntentEnabled as j, getAdvisorState as k, codePointLength as l, resolvePolicy as m, CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as n, PRUNE_MARKER as o, resolveConfig as p, ContextCompressionSettingsSchema as r, charsForTokens as s, AUTO_COMPACT_THRESHOLD_LIMITS as t, isCompressionProfile as u, assertNever as v, isSessionOverrideAction as w, applySessionOverride as x, deepFreeze as y, DEEPSEEK_OFFICIAL_PRICE_CATALOG_VERSION as z };
|
|
1777
|
+
export { getLastIntentFold as A, decimalRateNanoUnits as B, estimateSavingsPricing as C, INTENT_GATE_GROWTH_TOKENS as D, INTENT_GATE_FLOOR_FRACTION as E, recordIntentFold as F, resolveOfficialDeepSeekPrice as H, recordRecertified as I, recordScore as L, getSummaryOverride as M, invalidateOnTaskChange as N, evaluateIntentGate as O, observeIntentEnabled as P, setSummaryOverride as R, buildMonitorSnapshot as S, observeContextUsage as T, getSavingsLedger as U, priceOfficialDeepSeekUsage as V, savingsHash as W, resolveCustomPolicy as _, DEFAULT_CONTEXT_COMPRESSION_SETTINGS as a, COMPRESSION_PROFILES as b, charsToTokens as c, isValidAutoCompactThresholdPercent as d, parseContextCompressionSettings as f, DEFAULT_CUSTOM_COMPRESSION_POLICY as g, CustomCompressionPolicySchema as h, DEFAULTS as i, getObservedIntentEnabled as j, getAdvisorState as k, codePointLength as l, resolvePolicy as m, CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as n, PRUNE_MARKER as o, resolveConfig as p, ContextCompressionSettingsSchema as r, charsForTokens as s, AUTO_COMPACT_THRESHOLD_LIMITS as t, isCompressionProfile as u, assertNever as v, isSessionOverrideAction as w, applySessionOverride as x, deepFreeze as y, DEEPSEEK_OFFICIAL_PRICE_CATALOG_VERSION as z };
|
|
@@ -373,6 +373,17 @@ function wireSettingsBridge(ctx) {
|
|
|
373
373
|
//#endregion
|
|
374
374
|
//#region src/preset-overlay.ts
|
|
375
375
|
/** Plugin-owned, reversible compression overlays for native agent presets. */
|
|
376
|
+
/** Cordis 把未被代理的原始 service 暴露在该 symbol 下(见 cordis createTraceable 的 get 陷阱)。 */
|
|
377
|
+
const CORDIS_ORIGINAL = Symbol.for("cordis.original");
|
|
378
|
+
/**
|
|
379
|
+
* 取得 Cordis traceable 代理背后的原始 service。原始对象是宿主内部调用
|
|
380
|
+
* (`this.resolveMountable → this.resolve`) 时的接收者;只有装饰它,压缩栈补丁才能
|
|
381
|
+
* 真正注入(实证:装饰代理/原型代理均失败)。
|
|
382
|
+
*/
|
|
383
|
+
function rawService(presets) {
|
|
384
|
+
const raw = presets[CORDIS_ORIGINAL];
|
|
385
|
+
return raw !== null && typeof raw === "object" ? raw : presets;
|
|
386
|
+
}
|
|
376
387
|
/**
|
|
377
388
|
* Fixed base for deterministic standing mtimes. The stamp is derived from the
|
|
378
389
|
* FULL content identity (source + modules + threshold), not from the write
|
|
@@ -658,6 +669,75 @@ function renderPatchWarning(message, args) {
|
|
|
658
669
|
let index = 0;
|
|
659
670
|
return `context-compression selector: ${message.replace(/%C/g, () => JSON.stringify(args[index++]))}`;
|
|
660
671
|
}
|
|
672
|
+
/** Read a definition's preset id when the shape is a plain object. */
|
|
673
|
+
function readDefinitionId(definition) {
|
|
674
|
+
if (typeof definition !== "object" || definition === null) return void 0;
|
|
675
|
+
const id = definition.id;
|
|
676
|
+
return typeof id === "string" ? id : void 0;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Inject the canonical compression stack into one preset definition's rows.
|
|
680
|
+
*
|
|
681
|
+
* The 0.2.0 `dsh-agent-preset-registry` PRE-BUILDS a generation per definition
|
|
682
|
+
* (`activate` → `mountPreset(ctx, id, definition.plugins)`) and `mount` only
|
|
683
|
+
* `retain`s it; the composition never calls `resolve`. So the stack must land in
|
|
684
|
+
* the definition's own `plugins` before activation, not in a resolved preset
|
|
685
|
+
* file. Best-effort: a failed injection leaves the original rows untouched.
|
|
686
|
+
*/
|
|
687
|
+
function injectCompressionRows(definition, options, excluded) {
|
|
688
|
+
const id = readDefinitionId(definition);
|
|
689
|
+
if (id === void 0 || excluded.has(id)) return;
|
|
690
|
+
const plugins = definition.plugins;
|
|
691
|
+
if (!Array.isArray(plugins)) return;
|
|
692
|
+
try {
|
|
693
|
+
const thresholdPercent = options.autoCompactThresholdPercent?.();
|
|
694
|
+
definition.plugins = applyEntryPatches(stripCompressionRows(plugins), [{ insert: compressionRowsBySpecifier(thresholdPercent) }], (message, ...args) => {
|
|
695
|
+
throw new Error(renderPatchWarning(message, args));
|
|
696
|
+
});
|
|
697
|
+
} catch {}
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* The canonical compression stack addressed by BARE SPECIFIERS. The 0.2.0
|
|
701
|
+
* `dsh-agent-preset-registry` preset files declare this exact group by package
|
|
702
|
+
* name, and its loader resolves bare specifiers (`@deepseek-ai/...`,
|
|
703
|
+
* `dsh-context-compression-improved/pruner`) — absolute filesystem paths from
|
|
704
|
+
* {@link resolveCompressionModulePaths} are NOT accepted there (empirically:
|
|
705
|
+
* every injected row reports "never started").
|
|
706
|
+
*/
|
|
707
|
+
function compressionRowsBySpecifier(thresholdPercent) {
|
|
708
|
+
return [{
|
|
709
|
+
id: "compaction",
|
|
710
|
+
name: "cordis:group",
|
|
711
|
+
group: true,
|
|
712
|
+
isolate: {
|
|
713
|
+
compaction: true,
|
|
714
|
+
toolResultPruner: true
|
|
715
|
+
},
|
|
716
|
+
config: [
|
|
717
|
+
{
|
|
718
|
+
id: "compaction-basic",
|
|
719
|
+
name: "@deepseek-ai/dsh-compaction-basic",
|
|
720
|
+
...thresholdPercent === void 0 ? {} : { config: {
|
|
721
|
+
thresholdRatio: thresholdPercent / 100,
|
|
722
|
+
retainRatio: .16
|
|
723
|
+
} }
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
id: "command-compact",
|
|
727
|
+
name: "@deepseek-ai/dsh-command-compact"
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
id: "tool-result-pruner",
|
|
731
|
+
name: "dsh-context-compression-improved/pruner",
|
|
732
|
+
config: {
|
|
733
|
+
headChars: 4096,
|
|
734
|
+
tailChars: 1024,
|
|
735
|
+
...thresholdPercent === void 0 ? {} : { autoCompactThresholdPercent: thresholdPercent }
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
]
|
|
739
|
+
}];
|
|
740
|
+
}
|
|
661
741
|
/**
|
|
662
742
|
* Cordis can hand two callers different traceable proxies for one service.
|
|
663
743
|
* Symbol properties forward to the shared target, unlike proxy identity.
|
|
@@ -734,47 +814,67 @@ function installAgentPresetsDecoration(presets, options) {
|
|
|
734
814
|
const excluded = new Set(options.excludedPresetIds ?? ["minimal"]);
|
|
735
815
|
const operations = new AsyncLocalStorage();
|
|
736
816
|
const store = new PresetOverlayStore(options);
|
|
817
|
+
const raw = rawService(presets);
|
|
737
818
|
const snapshots = snapshotMethods(presets);
|
|
738
819
|
const resolveSnapshot = snapshotFor(snapshots, "resolve");
|
|
739
820
|
const resolveWrapped = async (id) => {
|
|
740
|
-
const preset = await Reflect.apply(resolveSnapshot.original,
|
|
741
|
-
if (operations.getStore()?.composing
|
|
821
|
+
const preset = await Reflect.apply(resolveSnapshot.original, raw, [id]);
|
|
822
|
+
if (!(operations.getStore()?.composing === true) || excluded.has(preset.id)) return preset;
|
|
742
823
|
return await store.overlay(preset);
|
|
743
824
|
};
|
|
744
|
-
installMethod(
|
|
825
|
+
installMethod(resolveSnapshot, resolveWrapped);
|
|
745
826
|
for (const method of [
|
|
746
827
|
"mount",
|
|
747
828
|
"recompose",
|
|
748
829
|
"standingKeyFor"
|
|
749
830
|
]) {
|
|
750
|
-
const snapshot =
|
|
751
|
-
|
|
752
|
-
|
|
831
|
+
const snapshot = snapshots.find((candidate) => candidate.name === method);
|
|
832
|
+
if (snapshot === void 0) continue;
|
|
833
|
+
const wrapped = (...args) => {
|
|
834
|
+
return operations.run({ composing: true }, () => Reflect.apply(snapshot.original, raw, args));
|
|
835
|
+
};
|
|
836
|
+
installMethod(snapshot, wrapped);
|
|
837
|
+
}
|
|
838
|
+
const registerSnapshot = snapshots.find((candidate) => candidate.name === "register");
|
|
839
|
+
if (registerSnapshot !== void 0) {
|
|
840
|
+
const registerWrapped = async (definition) => {
|
|
841
|
+
injectCompressionRows(definition, options, excluded);
|
|
842
|
+
return await Reflect.apply(registerSnapshot.original, raw, [definition]);
|
|
843
|
+
};
|
|
844
|
+
installMethod(registerSnapshot, registerWrapped);
|
|
753
845
|
}
|
|
754
846
|
let disposed = false;
|
|
755
847
|
return { async dispose() {
|
|
756
848
|
if (disposed) return;
|
|
757
849
|
disposed = true;
|
|
758
|
-
for (const snapshot of [...snapshots].reverse()) restoreMethod(
|
|
850
|
+
for (const snapshot of [...snapshots].reverse()) restoreMethod(snapshot);
|
|
759
851
|
await store.dispose();
|
|
760
852
|
} };
|
|
761
853
|
}
|
|
762
854
|
/** Capture callable methods and whether each was inherited or owned. */
|
|
763
855
|
function snapshotMethods(presets) {
|
|
764
|
-
|
|
856
|
+
const methods = [];
|
|
857
|
+
for (const name of [
|
|
765
858
|
"resolve",
|
|
766
859
|
"mount",
|
|
767
860
|
"recompose",
|
|
768
|
-
"standingKeyFor"
|
|
769
|
-
|
|
861
|
+
"standingKeyFor",
|
|
862
|
+
"register"
|
|
863
|
+
]) {
|
|
770
864
|
const original = presets[name];
|
|
771
|
-
if (typeof original !== "function")
|
|
772
|
-
|
|
865
|
+
if (typeof original !== "function") {
|
|
866
|
+
if (name === "resolve") throw new TypeError(`context-compression selector: AgentPresets.${name} is unavailable`);
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
const home = rawService(presets);
|
|
870
|
+
methods.push({
|
|
773
871
|
name,
|
|
774
|
-
|
|
872
|
+
home,
|
|
873
|
+
own: Object.getOwnPropertyDescriptor(home, name),
|
|
775
874
|
original
|
|
776
|
-
};
|
|
777
|
-
}
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
return methods;
|
|
778
878
|
}
|
|
779
879
|
/** Return the captured method or fail loudly if the snapshot set is corrupt. */
|
|
780
880
|
function snapshotFor(snapshots, name) {
|
|
@@ -783,18 +883,18 @@ function snapshotFor(snapshots, name) {
|
|
|
783
883
|
return snapshot;
|
|
784
884
|
}
|
|
785
885
|
/** Install one own method while retaining its identity for safe disposal. */
|
|
786
|
-
function installMethod(
|
|
886
|
+
function installMethod(snapshot, wrapped) {
|
|
787
887
|
snapshot.wrapped = wrapped;
|
|
788
|
-
Object.defineProperty(
|
|
888
|
+
Object.defineProperty(snapshot.home, snapshot.name, {
|
|
789
889
|
configurable: true,
|
|
790
890
|
writable: true,
|
|
791
891
|
value: wrapped
|
|
792
892
|
});
|
|
793
893
|
}
|
|
794
894
|
/** Restore the captured own/prototype state after the final shared lease. */
|
|
795
|
-
function restoreMethod(
|
|
796
|
-
if (snapshot.own === void 0) Reflect.deleteProperty(
|
|
797
|
-
else Object.defineProperty(
|
|
895
|
+
function restoreMethod(snapshot) {
|
|
896
|
+
if (snapshot.own === void 0) Reflect.deleteProperty(snapshot.home, snapshot.name);
|
|
897
|
+
else Object.defineProperty(snapshot.home, snapshot.name, snapshot.own);
|
|
798
898
|
}
|
|
799
899
|
//#endregion
|
|
800
900
|
//#region src/index.ts
|
|
@@ -930,6 +1030,16 @@ function asWebServer(value) {
|
|
|
930
1030
|
return typeof value.register === "function" ? value : void 0;
|
|
931
1031
|
}
|
|
932
1032
|
/**
|
|
1033
|
+
* `webServer.register` throws `duplicate exact route` when the same lib is
|
|
1034
|
+
* mounted twice by the host (two plugin ids resolving to one module: the
|
|
1035
|
+
* package-root manifest and the nested selector manifest). The other mount
|
|
1036
|
+
* already owns every path in the batch, so the collision is a success from
|
|
1037
|
+
* the plugin's point of view — without this, the losing arm logs a stack-
|
|
1038
|
+
* heavy warn pair on every boot (observed 0.9.5 on 0.2.0-rc.2, savings and
|
|
1039
|
+
* monitor).
|
|
1040
|
+
*/
|
|
1041
|
+
const isDuplicateRouteError = (error) => String(error?.message ?? error).includes("duplicate exact route");
|
|
1042
|
+
/**
|
|
933
1043
|
* Serve `GET /api/dsh-context-compression-improved/estimator-catalog` — the
|
|
934
1044
|
* settings card's host-route dropdowns (live provider/model groups from the DSH
|
|
935
1045
|
* `llm` service plus the effective selection). Best effort: without the
|
|
@@ -999,6 +1109,11 @@ function registerEstimatorCatalogRoute(ctx) {
|
|
|
999
1109
|
}, "contextCompressionSelector.estimator-catalog route");
|
|
1000
1110
|
log("info", "context-compression estimator catalog route registered (%s): %s", channel, ESTIMATOR_CATALOG_ROUTES.join(", "));
|
|
1001
1111
|
} catch (error) {
|
|
1112
|
+
if (isDuplicateRouteError(error)) {
|
|
1113
|
+
registered = true;
|
|
1114
|
+
log("info", "context-compression estimator catalog route already registered by another mount (%s)", channel);
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1002
1117
|
log("warn", "context-compression estimator catalog route registration failed (%s): %o", channel, error);
|
|
1003
1118
|
}
|
|
1004
1119
|
};
|
|
@@ -1070,6 +1185,11 @@ function registerSavingsRoute(ctx) {
|
|
|
1070
1185
|
}, "contextCompressionSelector.savings route");
|
|
1071
1186
|
log("info", "context-compression savings route registered (%s): %s", channel, SAVINGS_ROUTES.join(", "));
|
|
1072
1187
|
} catch (error) {
|
|
1188
|
+
if (isDuplicateRouteError(error)) {
|
|
1189
|
+
registered = true;
|
|
1190
|
+
log("info", "context-compression savings route already registered by another mount (%s)", channel);
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1073
1193
|
log("warn", "context-compression savings route registration failed (%s): %o", channel, error);
|
|
1074
1194
|
}
|
|
1075
1195
|
};
|
|
@@ -1196,6 +1316,11 @@ function registerMonitorRoute(ctx) {
|
|
|
1196
1316
|
}, "contextCompressionSelector.monitor route");
|
|
1197
1317
|
log("info", "context-compression monitor route registered (%s): %s", channel, MONITOR_ROUTES.join(", "));
|
|
1198
1318
|
} catch (error) {
|
|
1319
|
+
if (isDuplicateRouteError(error)) {
|
|
1320
|
+
registered = true;
|
|
1321
|
+
log("info", "context-compression monitor route already registered by another mount (%s)", channel);
|
|
1322
|
+
return;
|
|
1323
|
+
}
|
|
1199
1324
|
log("warn", "context-compression monitor route registration failed (%s): %o", channel, error);
|
|
1200
1325
|
}
|
|
1201
1326
|
};
|