dsh-context-compression-improved 0.5.1 → 0.5.3
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/.gitattributes +1 -0
- package/CHANGELOG.ja.md +144 -83
- package/CHANGELOG.ko.md +143 -82
- package/CHANGELOG.md +278 -212
- package/CHANGELOG.zh.md +131 -77
- package/docs/installation.md +103 -103
- package/docs/installation.zh.md +100 -100
- package/package.json +1 -1
- package/packages/selector/cordis.patch.yml +5 -6
- package/packages/selector/lib/advisor-state.js +4 -231
- package/packages/selector/lib/client.d.ts +0 -24
- package/packages/selector/lib/client.js +6 -501
- package/packages/selector/lib/index.d.ts +4 -10
- package/packages/selector/lib/index.js +16 -234
- package/packages/selector/lib/pruner.d.ts +13 -248
- package/packages/selector/lib/pruner.js +148 -552
- package/packages/selector/src/client/EstimatorControls.tsx +0 -101
- package/packages/selector/src/client/index.ts +0 -17
- package/packages/selector/src/client/locales.ts +0 -38
- package/packages/selector/src/client/preset-options.ts +3 -2
- package/packages/selector/src/client/settings-section.tsx +8 -17
- package/packages/selector/src/index.ts +24 -271
- package/packages/selector/src/profiles.ts +4 -27
- package/packages/selector/src/pruner/state.ts +2 -25
- package/packages/selector/src/pruner.ts +75 -403
- package/packages/selector/src/runtime/audit.ts +27 -21
- package/packages/selector/src/runtime/config.ts +6 -32
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +188 -188
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +149 -133
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -419
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
- package/packages/selector/src/runtime/types.ts +0 -17
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -223
- package/packages/selector/tests/preset-options-write.client.spec.ts +7 -23
- package/packages/selector/tests/public/package-contract.client.spec.ts +20 -0
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -0
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -272
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -226
- package/packages/selector/tests/runtime/audit.spec.ts +35 -21
- package/packages/selector/tests/runtime/char-basis.spec.ts +30 -30
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +4 -5
- package/packages/selector/tests/settings-seat.client.spec.ts +45 -14
- package/scripts/toolclass-corpus-replay.mjs +281 -281
- package/packages/selector/src/client/ReviewOverlay.tsx +0 -320
- package/packages/selector/src/client/review-scope.ts +0 -16
- package/packages/selector/src/runtime/tokenpilot/proposal.ts +0 -267
- package/packages/selector/src/runtime/tokenpilot/review-queue.ts +0 -231
- package/packages/selector/src/runtime/tokenpilot/review-registry.ts +0 -117
- package/packages/selector/src/runtime/tokenpilot/review-storage.ts +0 -122
- package/packages/selector/tests/review-overlay.client.spec.tsx +0 -118
- package/packages/selector/tests/review-routes-registry.host.spec.ts +0 -142
- package/packages/selector/tests/review-routes.host.spec.ts +0 -290
- package/packages/selector/tests/runtime/tokenpilot/proposal.spec.ts +0 -393
- package/packages/selector/tests/runtime/tokenpilot/pruner-review.spec.ts +0 -382
- package/packages/selector/tests/runtime/tokenpilot/review-queue.spec.ts +0 -168
|
@@ -1,133 +1,149 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-session state for the advisory relevance advisor.
|
|
3
|
-
*
|
|
4
|
-
* The advisor is statistics and suggestions only — its outputs (summaries,
|
|
5
|
-
* scores, decay, recertification marks) are observational and must never
|
|
6
|
-
* suppress, delay, or rewrite any reduction that would land. All state lives
|
|
7
|
-
* in WeakMaps keyed by the Session object so it is collected with the session
|
|
8
|
-
* and never leaks across sessions; every collection inside the state is
|
|
9
|
-
* bounded.
|
|
10
|
-
*
|
|
11
|
-
* Module-level `getAdvisorState` mirrors the PrunerState consolidation pattern
|
|
12
|
-
* (GC semantics identical) so `pruner.ts` reaches advisor state through a
|
|
13
|
-
* plain import rather than constructor injection.
|
|
14
|
-
*/
|
|
15
|
-
import type { Session } from '@deepseek-ai/dsh-session'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
readonly
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
readonly
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
*
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
state.
|
|
131
|
-
state.
|
|
132
|
-
|
|
133
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Per-session state for the advisory relevance advisor.
|
|
3
|
+
*
|
|
4
|
+
* The advisor is statistics and suggestions only — its outputs (summaries,
|
|
5
|
+
* scores, decay, recertification marks) are observational and must never
|
|
6
|
+
* suppress, delay, or rewrite any reduction that would land. All state lives
|
|
7
|
+
* in WeakMaps keyed by the Session object so it is collected with the session
|
|
8
|
+
* and never leaks across sessions; every collection inside the state is
|
|
9
|
+
* bounded.
|
|
10
|
+
*
|
|
11
|
+
* Module-level `getAdvisorState` mirrors the PrunerState consolidation pattern
|
|
12
|
+
* (GC semantics identical) so `pruner.ts` reaches advisor state through a
|
|
13
|
+
* plain import rather than constructor injection.
|
|
14
|
+
*/
|
|
15
|
+
import type { Session } from '@deepseek-ai/dsh-session'
|
|
16
|
+
import type { AdviceBand } from './benefit.ts'
|
|
17
|
+
|
|
18
|
+
/** The most recent benefit-model label of a landed batch. Observational only:
|
|
19
|
+
* no decision path reads it — the report route serves it verbatim. */
|
|
20
|
+
export interface AdvisorAdviceSnapshot {
|
|
21
|
+
readonly band: AdviceBand
|
|
22
|
+
/** Turn index the advised batch landed at. */
|
|
23
|
+
readonly turn: number
|
|
24
|
+
readonly itemSeqs: readonly number[]
|
|
25
|
+
readonly recoveredTokens: number
|
|
26
|
+
readonly penaltyTokens: number
|
|
27
|
+
readonly paybackTurns?: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** One relevance score for one surface seq, with the turn it was scored at. */
|
|
31
|
+
export interface AdvisorScoreEntry {
|
|
32
|
+
readonly score: number
|
|
33
|
+
/** Turn index the score was produced at. */
|
|
34
|
+
readonly turn: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** LLM-summarized tail-task semantics bound to the session todolist. */
|
|
38
|
+
export interface AdvisorSummary {
|
|
39
|
+
/** The session's overall task, one sentence. */
|
|
40
|
+
readonly overallTask: string
|
|
41
|
+
/** Subtasks currently being pushed forward. */
|
|
42
|
+
readonly activeSubtasks: readonly string[]
|
|
43
|
+
/** Short task keywords used by the local relevance prescreen. */
|
|
44
|
+
readonly keywords: readonly string[]
|
|
45
|
+
/** Task-semantics version the summary was derived from. */
|
|
46
|
+
readonly todoVersion: string
|
|
47
|
+
/** Turn index the summary was produced at. */
|
|
48
|
+
readonly turn: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Per-session estimator-style failure bookkeeping for exponential backoff. */
|
|
52
|
+
export interface AdvisorFailures {
|
|
53
|
+
failures: number
|
|
54
|
+
cooldownUntil: number
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Bounded per-session advisor state bag. */
|
|
58
|
+
export interface AdvisorState {
|
|
59
|
+
/** Version of the task semantics the cached summary and scores were built against. */
|
|
60
|
+
todoVersion: string | undefined
|
|
61
|
+
summary: AdvisorSummary | undefined
|
|
62
|
+
/** Turn index the last summary pass ran at. */
|
|
63
|
+
lastSummaryTurn: number
|
|
64
|
+
/** Highest candidate seq the scoring pass has examined (incremental watermark). */
|
|
65
|
+
watermarkSeq: number
|
|
66
|
+
/** LRU-bounded seq → score map (most recent touch wins, oldest evicted). */
|
|
67
|
+
readonly scores: Map<number, AdvisorScoreEntry>
|
|
68
|
+
/** Bounded seq → turn marks for old low-relevance segments (suggestions only). */
|
|
69
|
+
readonly recertified: Map<number, number>
|
|
70
|
+
failures: AdvisorFailures | undefined
|
|
71
|
+
/** Re-entry guard: summary + scoring are two LLM calls, so the overlap window is wide. */
|
|
72
|
+
inFlight: boolean
|
|
73
|
+
/** Most recent decay computation, shared verbatim by audits and the report route. */
|
|
74
|
+
lastDecay: { readonly decay: number, readonly weightedChars: number, readonly turn: number } | undefined
|
|
75
|
+
/** Most recent benefit-model advice; replaced by every advised batch. */
|
|
76
|
+
lastAdvice: AdvisorAdviceSnapshot | undefined
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Upper bound of the per-session scores LRU. */
|
|
80
|
+
export const ADVISOR_SCORES_LIMIT = 64
|
|
81
|
+
/** Upper bound of the per-session recertification marks. */
|
|
82
|
+
export const ADVISOR_RECERTIFIED_LIMIT = 64
|
|
83
|
+
|
|
84
|
+
const advisorStates = new WeakMap<Session, AdvisorState>()
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The per-session advisor state, created on first touch.
|
|
88
|
+
* @param session - the session to key the state on (by object identity).
|
|
89
|
+
*/
|
|
90
|
+
export function getAdvisorState(session: Session): AdvisorState {
|
|
91
|
+
let state = advisorStates.get(session)
|
|
92
|
+
if (state === undefined) {
|
|
93
|
+
state = {
|
|
94
|
+
todoVersion: undefined,
|
|
95
|
+
summary: undefined,
|
|
96
|
+
lastSummaryTurn: -1,
|
|
97
|
+
watermarkSeq: 0,
|
|
98
|
+
scores: new Map(),
|
|
99
|
+
recertified: new Map(),
|
|
100
|
+
failures: undefined,
|
|
101
|
+
inFlight: false,
|
|
102
|
+
lastDecay: undefined,
|
|
103
|
+
lastAdvice: undefined,
|
|
104
|
+
}
|
|
105
|
+
advisorStates.set(session, state)
|
|
106
|
+
}
|
|
107
|
+
return state
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Insert or refresh one score with LRU semantics: a re-touched seq moves to
|
|
112
|
+
* the newest position, and the oldest entry is evicted once the map exceeds
|
|
113
|
+
* {@link ADVISOR_SCORES_LIMIT}.
|
|
114
|
+
*/
|
|
115
|
+
export function recordScore(state: AdvisorState, seq: number, entry: AdvisorScoreEntry): void {
|
|
116
|
+
state.scores.delete(seq)
|
|
117
|
+
state.scores.set(seq, entry)
|
|
118
|
+
if (state.scores.size > ADVISOR_SCORES_LIMIT) {
|
|
119
|
+
const oldest = state.scores.keys().next()
|
|
120
|
+
if (oldest.done !== true) state.scores.delete(oldest.value)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Mark one seq as LLM-recertified low relevance (a suggestion for later
|
|
126
|
+
* history-aggressiveness decisions, consumed by nothing in this round).
|
|
127
|
+
* Bounded at {@link ADVISOR_RECERTIFIED_LIMIT} with the same LRU eviction.
|
|
128
|
+
*/
|
|
129
|
+
export function recordRecertified(state: AdvisorState, seq: number, turn: number): void {
|
|
130
|
+
state.recertified.delete(seq)
|
|
131
|
+
state.recertified.set(seq, turn)
|
|
132
|
+
if (state.recertified.size > ADVISOR_RECERTIFIED_LIMIT) {
|
|
133
|
+
const oldest = state.recertified.keys().next()
|
|
134
|
+
if (oldest.done !== true) state.recertified.delete(oldest.value)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Drop every cached artifact that depends on the task semantics: a changed
|
|
140
|
+
* todo version invalidates the summary and makes all eligible candidates
|
|
141
|
+
* rescore-worthy (the watermark alone would otherwise hide them).
|
|
142
|
+
*/
|
|
143
|
+
export function invalidateOnTaskChange(state: AdvisorState, todoVersion: string): boolean {
|
|
144
|
+
if (state.todoVersion === todoVersion) return false
|
|
145
|
+
state.todoVersion = todoVersion
|
|
146
|
+
state.summary = undefined
|
|
147
|
+
state.lastSummaryTurn = -1
|
|
148
|
+
return true
|
|
149
|
+
}
|