dsh-context-compression-improved 0.13.4 → 0.14.1
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/package.json +1 -1
- package/packages/selector/dsh.plugin.json +1 -1
- package/packages/selector/lib/profiles.d.ts +9 -0
- package/packages/selector/lib/pruner.d.ts +8 -0
- package/packages/selector/lib/pruner.js +23 -8
- package/packages/selector/package.json +1 -1
- package/packages/selector/src/profiles.ts +9 -0
- package/packages/selector/src/pruner/state.ts +2 -0
- package/packages/selector/src/pruner.ts +18 -4
- package/packages/selector/src/runtime/fold-router.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-external/dsh-context-compression-improved",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"description": "Token-saving, auditable tool-result context-compression selector with code-skeleton gate for DeepSeek Harness — fewer tokens on every turn",
|
|
6
6
|
"engines": {
|
|
@@ -157,6 +157,15 @@ interface ContextCompressionSettings {
|
|
|
157
157
|
* 0 disables the check. Default 1000.
|
|
158
158
|
*/
|
|
159
159
|
minNetGain?: number;
|
|
160
|
+
/**
|
|
161
|
+
* F8 (v0.14.5): Zero-copy mode — when true, no fallback copies are written;
|
|
162
|
+
* retrieve reads only from the session log. Default false (v0.14), true (v0.15+).
|
|
163
|
+
*/
|
|
164
|
+
zeroCopy?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* F19 (v0.14.6): Enable self-update pre-download checking.
|
|
167
|
+
*/
|
|
168
|
+
updateCheck?: boolean;
|
|
160
169
|
}
|
|
161
170
|
//#endregion
|
|
162
171
|
export { PresetOptionsSettings as i, ContextCompressionSettings as n, CustomCompressionPolicy as r, CompressionProfile as t };
|
|
@@ -512,6 +512,14 @@ interface PrunerState {
|
|
|
512
512
|
readonly intentFoldedSeqs: WeakMap<Session, Set<number>>;
|
|
513
513
|
/** Live-surface tokens when the last intent fold landed (growth-gate baseline). */
|
|
514
514
|
readonly intentBaselines: WeakMap<Session, number>;
|
|
515
|
+
/** F14 (v0.14.1): Incremental calls cache — rebuilt only when event count changes. */
|
|
516
|
+
readonly callsCache: WeakMap<Session, {
|
|
517
|
+
map: Map<string, {
|
|
518
|
+
name: string;
|
|
519
|
+
arguments: string;
|
|
520
|
+
}>;
|
|
521
|
+
eventCount: number;
|
|
522
|
+
}>;
|
|
515
523
|
}
|
|
516
524
|
//#endregion
|
|
517
525
|
//#region src/runtime/token-count.d.ts
|
|
@@ -3160,9 +3160,9 @@ function foldTier(inputTokens) {
|
|
|
3160
3160
|
return inputTokens <= FOLD_TIER_LIMITS.strataMax ? "strata" : "local35";
|
|
3161
3161
|
}
|
|
3162
3162
|
const FOLD_SYSTEM = "You are writing a short connective narrative for a durable context card. Summarize ONLY the material given below: what was attempted and what was concluded, in 2-6 bullets. The card already contains verbatim error lines, file manifests, and code skeletons that were DELIBERATELY withheld from you. Never restate, guess, or reconstitute withheld output; never add facts not present in the material. Output only the bullets.";
|
|
3163
|
-
/** Rough meter aligned with the replay corpus estimator (CJK-aware). */
|
|
3163
|
+
/** Rough meter aligned with the replay corpus estimator (CJK-aware, F9 fix: all CJK ranges). */
|
|
3164
3164
|
function foldTokens(text) {
|
|
3165
|
-
const cjk = (text.match(/[\u4e00-\u9fff]/g) ?? []).length;
|
|
3165
|
+
const cjk = (text.match(/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uac00-\ud7af]/g) ?? []).length;
|
|
3166
3166
|
return Math.ceil(cjk / 1.5 + (text.length - cjk) / 4);
|
|
3167
3167
|
}
|
|
3168
3168
|
/**
|
|
@@ -4759,7 +4759,8 @@ var ToolResultPruner = class extends Service {
|
|
|
4759
4759
|
projectedSavings: /* @__PURE__ */ new WeakSet(),
|
|
4760
4760
|
pendingIntentFolds: /* @__PURE__ */ new WeakMap(),
|
|
4761
4761
|
intentFoldedSeqs: /* @__PURE__ */ new WeakMap(),
|
|
4762
|
-
intentBaselines: /* @__PURE__ */ new WeakMap()
|
|
4762
|
+
intentBaselines: /* @__PURE__ */ new WeakMap(),
|
|
4763
|
+
callsCache: /* @__PURE__ */ new WeakMap()
|
|
4763
4764
|
};
|
|
4764
4765
|
try {
|
|
4765
4766
|
ctx.on("session/disposed", (session) => {
|
|
@@ -6016,11 +6017,25 @@ var ToolResultPruner = class extends Service {
|
|
|
6016
6017
|
}
|
|
6017
6018
|
snapshot(session, view) {
|
|
6018
6019
|
const events = sessionEvents(session);
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6020
|
+
let cached = this.state.callsCache.get(session);
|
|
6021
|
+
if (cached === void 0 || cached.eventCount !== events.length) {
|
|
6022
|
+
const calls = /* @__PURE__ */ new Map();
|
|
6023
|
+
const startIndex = cached?.eventCount ?? 0;
|
|
6024
|
+
if (cached !== void 0 && cached.eventCount < events.length) for (const [key, value] of cached.map) calls.set(key, value);
|
|
6025
|
+
for (let i = cached !== void 0 ? startIndex : 0; i < events.length; i++) {
|
|
6026
|
+
const event = events[i];
|
|
6027
|
+
if (event.type === "tool/call") calls.set(event.data.callId, {
|
|
6028
|
+
name: event.data.name,
|
|
6029
|
+
arguments: event.data.arguments
|
|
6030
|
+
});
|
|
6031
|
+
}
|
|
6032
|
+
cached = {
|
|
6033
|
+
map: calls,
|
|
6034
|
+
eventCount: events.length
|
|
6035
|
+
};
|
|
6036
|
+
this.state.callsCache.set(session, cached);
|
|
6037
|
+
}
|
|
6038
|
+
const calls = cached.map;
|
|
6024
6039
|
const candidates = [];
|
|
6025
6040
|
const measured = new Map(view.measuredNodes.map((node) => [node.seq, node.count]));
|
|
6026
6041
|
const projectionPrices = new Map(view.nodes.map((node) => [node.seq, node.tokens]));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-context-compression-improved",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Token-saving context-compression selector bundle for DeepSeek Harness — fewer tool-result tokens on every turn, fully auditable",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -457,6 +457,15 @@ export interface ContextCompressionSettings {
|
|
|
457
457
|
* 0 disables the check. Default 1000.
|
|
458
458
|
*/
|
|
459
459
|
minNetGain?: number
|
|
460
|
+
/**
|
|
461
|
+
* F8 (v0.14.5): Zero-copy mode — when true, no fallback copies are written;
|
|
462
|
+
* retrieve reads only from the session log. Default false (v0.14), true (v0.15+).
|
|
463
|
+
*/
|
|
464
|
+
zeroCopy?: boolean
|
|
465
|
+
/**
|
|
466
|
+
* F19 (v0.14.6): Enable self-update pre-download checking.
|
|
467
|
+
*/
|
|
468
|
+
updateCheck?: boolean
|
|
460
469
|
}
|
|
461
470
|
|
|
462
471
|
/**
|
|
@@ -58,4 +58,6 @@ export interface PrunerState {
|
|
|
58
58
|
readonly intentFoldedSeqs: WeakMap<Session, Set<number>>
|
|
59
59
|
/** Live-surface tokens when the last intent fold landed (growth-gate baseline). */
|
|
60
60
|
readonly intentBaselines: WeakMap<Session, number>
|
|
61
|
+
/** F14 (v0.14.1): Incremental calls cache — rebuilt only when event count changes. */
|
|
62
|
+
readonly callsCache: WeakMap<Session, { map: Map<string, { name: string; arguments: string }>; eventCount: number }>
|
|
61
63
|
}
|
|
@@ -363,6 +363,7 @@ export class ToolResultPruner extends Service {
|
|
|
363
363
|
pendingIntentFolds: new WeakMap(),
|
|
364
364
|
intentFoldedSeqs: new WeakMap(),
|
|
365
365
|
intentBaselines: new WeakMap(),
|
|
366
|
+
callsCache: new WeakMap(),
|
|
366
367
|
}
|
|
367
368
|
|
|
368
369
|
// 会话结束汇总(dsh-token-optimizer monitor 模式的同款体验):输出该会话的
|
|
@@ -2021,12 +2022,25 @@ export class ToolResultPruner extends Service {
|
|
|
2021
2022
|
|
|
2022
2023
|
private snapshot(session: Session, view: CompactionTokenView): SnapshotCandidate[] {
|
|
2023
2024
|
const events = sessionEvents(session)
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2025
|
+
// F14 incremental cache: rebuild calls map only when event count changes
|
|
2026
|
+
let cached = this.state.callsCache.get(session)
|
|
2027
|
+
if (cached === undefined || cached.eventCount !== events.length) {
|
|
2028
|
+
const calls = new Map<string, ToolCallInfo>()
|
|
2029
|
+
const startIndex = cached?.eventCount ?? 0
|
|
2030
|
+
// Start from existing map if available, only process new events
|
|
2031
|
+
if (cached !== undefined && cached.eventCount < events.length) {
|
|
2032
|
+
for (const [key, value] of cached.map) calls.set(key, value)
|
|
2033
|
+
}
|
|
2034
|
+
for (let i = cached !== undefined ? startIndex : 0; i < events.length; i++) {
|
|
2035
|
+
const event = events[i]!
|
|
2036
|
+
if (event.type === 'tool/call') {
|
|
2037
|
+
calls.set(event.data.callId, { name: event.data.name, arguments: event.data.arguments })
|
|
2038
|
+
}
|
|
2028
2039
|
}
|
|
2040
|
+
cached = { map: calls, eventCount: events.length }
|
|
2041
|
+
this.state.callsCache.set(session, cached)
|
|
2029
2042
|
}
|
|
2043
|
+
const calls = cached.map
|
|
2030
2044
|
const candidates: SnapshotCandidate[] = []
|
|
2031
2045
|
const measured = new Map(view.measuredNodes.map(node => [node.seq, node.count]))
|
|
2032
2046
|
const projectionPrices = new Map(view.nodes.map(node => [node.seq, node.tokens]))
|
|
@@ -52,9 +52,10 @@ export interface FoldPrompt {
|
|
|
52
52
|
readonly inputTokens: number
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/** Rough meter aligned with the replay corpus estimator (CJK-aware). */
|
|
55
|
+
/** Rough meter aligned with the replay corpus estimator (CJK-aware, F9 fix: all CJK ranges). */
|
|
56
56
|
function foldTokens(text: string): number {
|
|
57
|
-
|
|
57
|
+
// F9 (v0.14.5): cover CJK Unified + Extension A + Kana + Hangul
|
|
58
|
+
const cjk = (text.match(/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uac00-\ud7af]/g) ?? []).length
|
|
58
59
|
return Math.ceil(cjk / 1.5 + (text.length - cjk) / 4)
|
|
59
60
|
}
|
|
60
61
|
|