dsh-context-compression-improved 0.6.5 → 0.7.0-beta.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/CHANGELOG.ja.md +9 -0
- package/CHANGELOG.ko.md +9 -0
- package/CHANGELOG.md +26 -0
- package/CHANGELOG.zh.md +9 -0
- package/README.md +1 -0
- package/README.zh.md +1 -0
- package/eslint.config.js +76 -30
- package/package.json +18 -17
- package/packages/selector/dsh.plugin.json +1 -1
- package/packages/selector/lib/client.js +14 -3
- package/packages/selector/lib/index.js +92 -1
- package/packages/selector/lib/{advisor-state.js → intent-gate.js} +91 -3
- package/packages/selector/lib/profiles.d.ts +9 -0
- package/packages/selector/lib/pruner.d.ts +59 -0
- package/packages/selector/lib/pruner.js +410 -8
- package/packages/selector/lib/style.css +46 -46
- package/packages/selector/src/client/decode.ts +6 -2
- package/packages/selector/src/deepseek-v4-tokenizer.ts +1 -1
- package/packages/selector/src/index.ts +418 -411
- package/packages/selector/src/preset-overlay.ts +3 -0
- package/packages/selector/src/profiles.ts +30 -10
- package/packages/selector/src/pruner/content.ts +1 -1
- package/packages/selector/src/pruner/state.ts +7 -0
- package/packages/selector/src/pruner.ts +253 -9
- package/packages/selector/src/runtime/audit.ts +17 -0
- package/packages/selector/src/runtime/config.ts +36 -11
- package/packages/selector/src/runtime/reducers.ts +1 -1
- package/packages/selector/src/runtime/summary-command.ts +133 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +46 -1
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +55 -0
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
- package/packages/selector/src/runtime/tokenpilot/locator.ts +2 -2
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +4 -1
- package/packages/selector/src/runtime/types.ts +12 -0
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
- package/packages/selector/tests/built/client-artifact.spec.ts +2 -0
- package/packages/selector/tests/code-skeleton.client.spec.ts +94 -93
- package/packages/selector/tests/custom-contract.client.spec.ts +223 -222
- package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
- package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +203 -203
- package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/runtime/audit.spec.ts +275 -274
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +3 -3
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +4 -4
- package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +5 -0
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +15 -35
- package/scripts/packed-components-smoke.mjs +2 -0
- package/scripts/packed-install-e2e.mjs +1275 -1273
- package/scripts/verify-release.mjs +318 -317
- package/tsconfig.tests.json +3 -1
- package/vitest.config.ts +14 -0
- package/.agents-stash-064.patch +0 -39
- package/_dsh_devdeps.json +0 -50
- package/_verify064/package/package.json +0 -162
- package/_verify064/package/packages/selector/src/client/index.ts +0 -232
|
@@ -1,274 +1,275 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
COMPRESSION_AUDIT_PREFIX,
|
|
4
|
-
emitCompressionAudit,
|
|
5
|
-
formatCompressionAudit,
|
|
6
|
-
} from '../../src/runtime/audit.ts'
|
|
7
|
-
import type { CompressionAuditRecord, CompressionRewriteAuditRecord } from '../../src/runtime/audit.ts'
|
|
8
|
-
|
|
9
|
-
const custom = {
|
|
10
|
-
version: 3 as const,
|
|
11
|
-
unit: 'tokens' as const,
|
|
12
|
-
fresh: { enabled: true, trigger: 8_192, target: 3_072 },
|
|
13
|
-
aggregate: { enabled: true, trigger: 32_768, target: 12_288 },
|
|
14
|
-
history: {
|
|
15
|
-
enabled: true,
|
|
16
|
-
trigger: 500_000,
|
|
17
|
-
keepRecentToolCalls: 10,
|
|
18
|
-
keepRecentTokens: 64_000,
|
|
19
|
-
minReclaim: 96_000,
|
|
20
|
-
},
|
|
21
|
-
prefixPolicy: 'pressure-break' as const,
|
|
22
|
-
tailTrim: { enabled: true, trigger: 700_000 },
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe('context-compression audit records', () => {
|
|
26
|
-
it('formats one complete frozen-policy record without model-visible content', () => {
|
|
27
|
-
const record: CompressionAuditRecord = {
|
|
28
|
-
schemaVersion: 1,
|
|
29
|
-
kind: 'policy-frozen',
|
|
30
|
-
sessionId: 'audit-session',
|
|
31
|
-
settingsSource: 'host-settings',
|
|
32
|
-
settings: {
|
|
33
|
-
profile: 'custom',
|
|
34
|
-
custom,
|
|
35
|
-
autoCompact: { thresholdPercent: 80 },
|
|
36
|
-
codeSkeleton: { enabled: false },
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
expect(
|
|
49
|
-
expect(line).
|
|
50
|
-
expect(line).not.toContain('
|
|
51
|
-
expect(line).not.toContain('
|
|
52
|
-
expect(line).not.toContain('
|
|
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
|
-
expect(parsed.
|
|
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
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
expect(info).
|
|
147
|
-
expect(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
expect(line).not.toContain('
|
|
198
|
-
expect(line).not.toContain('"
|
|
199
|
-
expect(line).not.toContain('
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
//
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
expect(line).not.toContain('
|
|
251
|
-
expect(line).not.toContain('"
|
|
252
|
-
expect(line).not.toContain('
|
|
253
|
-
expect(line).not.toContain('
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
})
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
COMPRESSION_AUDIT_PREFIX,
|
|
4
|
+
emitCompressionAudit,
|
|
5
|
+
formatCompressionAudit,
|
|
6
|
+
} from '../../src/runtime/audit.ts'
|
|
7
|
+
import type { CompressionAuditRecord, CompressionRewriteAuditRecord } from '../../src/runtime/audit.ts'
|
|
8
|
+
|
|
9
|
+
const custom = {
|
|
10
|
+
version: 3 as const,
|
|
11
|
+
unit: 'tokens' as const,
|
|
12
|
+
fresh: { enabled: true, trigger: 8_192, target: 3_072 },
|
|
13
|
+
aggregate: { enabled: true, trigger: 32_768, target: 12_288 },
|
|
14
|
+
history: {
|
|
15
|
+
enabled: true,
|
|
16
|
+
trigger: 500_000,
|
|
17
|
+
keepRecentToolCalls: 10,
|
|
18
|
+
keepRecentTokens: 64_000,
|
|
19
|
+
minReclaim: 96_000,
|
|
20
|
+
},
|
|
21
|
+
prefixPolicy: 'pressure-break' as const,
|
|
22
|
+
tailTrim: { enabled: true, trigger: 700_000 },
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('context-compression audit records', () => {
|
|
26
|
+
it('formats one complete frozen-policy record without model-visible content', () => {
|
|
27
|
+
const record: CompressionAuditRecord = {
|
|
28
|
+
schemaVersion: 1,
|
|
29
|
+
kind: 'policy-frozen',
|
|
30
|
+
sessionId: 'audit-session',
|
|
31
|
+
settingsSource: 'host-settings',
|
|
32
|
+
settings: {
|
|
33
|
+
profile: 'custom',
|
|
34
|
+
custom,
|
|
35
|
+
autoCompact: { thresholdPercent: 80 },
|
|
36
|
+
codeSkeleton: { enabled: false },
|
|
37
|
+
intentSummary: { enabled: false },
|
|
38
|
+
},
|
|
39
|
+
deploymentConfig: {
|
|
40
|
+
profile: 'balanced',
|
|
41
|
+
headChars: 4_096,
|
|
42
|
+
tailChars: 1_024,
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const line = formatCompressionAudit(record)
|
|
47
|
+
|
|
48
|
+
expect(line).toBe(`${COMPRESSION_AUDIT_PREFIX}${JSON.stringify(record)}`)
|
|
49
|
+
expect(JSON.parse(line.slice(COMPRESSION_AUDIT_PREFIX.length))).toEqual(record)
|
|
50
|
+
expect(line).not.toContain('prompt')
|
|
51
|
+
expect(line).not.toContain('toolArguments')
|
|
52
|
+
expect(line).not.toContain('toolResult')
|
|
53
|
+
expect(line).not.toContain('apiKey')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('keeps component provenance and exact token arithmetic on rewrite records', () => {
|
|
57
|
+
const record: CompressionAuditRecord = {
|
|
58
|
+
schemaVersion: 1,
|
|
59
|
+
kind: 'rewrite',
|
|
60
|
+
sessionId: 'history-session',
|
|
61
|
+
profile: 'cache-strict',
|
|
62
|
+
component: 'history',
|
|
63
|
+
stage: 'pressure',
|
|
64
|
+
reducer: 'historical-tool-result-aging',
|
|
65
|
+
historyMode: 'capacity-pressure',
|
|
66
|
+
manifestEventType: 'compaction/prune',
|
|
67
|
+
manifestSeq: 41,
|
|
68
|
+
replacementSeq: 42,
|
|
69
|
+
sourceSeqs: [12],
|
|
70
|
+
tokensBefore: 600_100,
|
|
71
|
+
tokensAfter: 100,
|
|
72
|
+
tokensRemoved: 600_000,
|
|
73
|
+
tokenizerId: 'mock-tokenizer',
|
|
74
|
+
tokenizerRevision: 'r1',
|
|
75
|
+
measurementBasis: 'exact-tokenizer',
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const parsed = JSON.parse(
|
|
79
|
+
formatCompressionAudit(record).slice(COMPRESSION_AUDIT_PREFIX.length),
|
|
80
|
+
) as CompressionAuditRecord
|
|
81
|
+
|
|
82
|
+
expect(parsed).toEqual(record)
|
|
83
|
+
expect(parsed.kind === 'rewrite' && parsed.tokensRemoved)
|
|
84
|
+
.toBe(record.tokensBefore - record.tokensAfter)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
// task_4c/G7: the elided-line count rides the rewrite audit record (optional,
|
|
88
|
+
// JSON round-trip) so the compress→retrieve M/N ratio is computable from
|
|
89
|
+
// session logs alone; records without reducer telemetry omit the field.
|
|
90
|
+
it('round-trips elidedLines on rewrite records and omits it when absent', () => {
|
|
91
|
+
const withTelemetry: CompressionAuditRecord = {
|
|
92
|
+
schemaVersion: 1,
|
|
93
|
+
kind: 'rewrite',
|
|
94
|
+
sessionId: 'telemetry-session',
|
|
95
|
+
profile: 'balanced',
|
|
96
|
+
component: 'fresh',
|
|
97
|
+
stage: 'fresh',
|
|
98
|
+
reducer: 'hypa-code-skeleton',
|
|
99
|
+
manifestEventType: 'compaction/prune',
|
|
100
|
+
manifestSeq: 7,
|
|
101
|
+
replacementSeq: 8,
|
|
102
|
+
sourceSeqs: [6],
|
|
103
|
+
tokensBefore: 20_000,
|
|
104
|
+
tokensAfter: 3_000,
|
|
105
|
+
tokensRemoved: 17_000,
|
|
106
|
+
tokenizerId: 'mock-tokenizer',
|
|
107
|
+
tokenizerRevision: 'r1',
|
|
108
|
+
measurementBasis: 'exact-tokenizer',
|
|
109
|
+
elidedLines: 412,
|
|
110
|
+
}
|
|
111
|
+
const parsed = JSON.parse(
|
|
112
|
+
formatCompressionAudit(withTelemetry).slice(COMPRESSION_AUDIT_PREFIX.length),
|
|
113
|
+
) as CompressionRewriteAuditRecord
|
|
114
|
+
expect(parsed.elidedLines).toBe(412)
|
|
115
|
+
|
|
116
|
+
const { elidedLines: _omitted, ...placeholderRecord } = withTelemetry
|
|
117
|
+
void _omitted
|
|
118
|
+
const withoutTelemetry: CompressionAuditRecord = {
|
|
119
|
+
...placeholderRecord,
|
|
120
|
+
reducer: 'error-evidence-placeholder',
|
|
121
|
+
}
|
|
122
|
+
expect('elidedLines' in withoutTelemetry).toBe(false)
|
|
123
|
+
const parsedWithout = JSON.parse(
|
|
124
|
+
formatCompressionAudit(withoutTelemetry).slice(COMPRESSION_AUDIT_PREFIX.length),
|
|
125
|
+
) as CompressionRewriteAuditRecord
|
|
126
|
+
expect(parsedWithout.elidedLines).toBeUndefined()
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('publishes exactly one single-line info message', () => {
|
|
130
|
+
const info = vi.fn()
|
|
131
|
+
const record: CompressionAuditRecord = {
|
|
132
|
+
schemaVersion: 1,
|
|
133
|
+
kind: 'native-auto-compact',
|
|
134
|
+
sessionId: 'native-session',
|
|
135
|
+
manifestEventType: 'compaction/summary',
|
|
136
|
+
manifestSeq: 9,
|
|
137
|
+
reducer: 'llm-summary',
|
|
138
|
+
provider: 'mock',
|
|
139
|
+
model: 'mock',
|
|
140
|
+
tokensBefore: 1_024,
|
|
141
|
+
tokensAfter: null,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
emitCompressionAudit({ info }, record)
|
|
145
|
+
|
|
146
|
+
expect(info).toHaveBeenCalledOnce()
|
|
147
|
+
expect(info).toHaveBeenCalledWith(formatCompressionAudit(record))
|
|
148
|
+
expect(String(info.mock.calls[0]?.[0])).not.toContain('\n')
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('does not let logger failure roll back an already committed rewrite', () => {
|
|
152
|
+
const record: CompressionAuditRecord = {
|
|
153
|
+
schemaVersion: 1,
|
|
154
|
+
kind: 'native-auto-compact',
|
|
155
|
+
sessionId: 'native-session',
|
|
156
|
+
manifestEventType: 'compaction/summary',
|
|
157
|
+
manifestSeq: 9,
|
|
158
|
+
reducer: 'llm-summary',
|
|
159
|
+
provider: 'mock',
|
|
160
|
+
model: 'mock',
|
|
161
|
+
tokensBefore: 1_024,
|
|
162
|
+
tokensAfter: null,
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
expect(() => {
|
|
166
|
+
emitCompressionAudit({
|
|
167
|
+
info: () => {
|
|
168
|
+
throw new Error('logger unavailable')
|
|
169
|
+
},
|
|
170
|
+
}, record)
|
|
171
|
+
}).not.toThrow()
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('keeps reduction-advice records free of content, digests, and keys', () => {
|
|
175
|
+
const record: CompressionAuditRecord = {
|
|
176
|
+
schemaVersion: 1,
|
|
177
|
+
kind: 'reduction-advice',
|
|
178
|
+
sessionId: 'advice-session',
|
|
179
|
+
profile: 'tokenpilot-inspired',
|
|
180
|
+
band: 'high-impact',
|
|
181
|
+
stage: 'fresh',
|
|
182
|
+
itemSeqs: [7, 9],
|
|
183
|
+
pricedCandidates: 2,
|
|
184
|
+
maxTokensBefore: 9_200,
|
|
185
|
+
tokensBefore: 12_400,
|
|
186
|
+
tokensAfter: 3_100,
|
|
187
|
+
recoveredTokens: 9_300,
|
|
188
|
+
penaltyTokens: 0,
|
|
189
|
+
paybackTurns: 0,
|
|
190
|
+
turnIndex: 12,
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const line = formatCompressionAudit(record)
|
|
194
|
+
const parsed = JSON.parse(line.slice(COMPRESSION_AUDIT_PREFIX.length)) as CompressionAuditRecord
|
|
195
|
+
expect(parsed).toEqual(record)
|
|
196
|
+
// Only ids, enums, and numbers: no digests, no content fields.
|
|
197
|
+
expect(line).not.toContain('digest')
|
|
198
|
+
expect(line).not.toContain('"content"')
|
|
199
|
+
expect(line).not.toContain('"text"')
|
|
200
|
+
expect(line).not.toContain('apiKey')
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it('describes an advised batch without any gate vocabulary', () => {
|
|
204
|
+
// The band can be the model's worst opinion — `not-worth-it` — and the
|
|
205
|
+
// record still only DESCRIBES a batch that landed: the retired review
|
|
206
|
+
// gate's decision vocabulary cannot be expressed any more.
|
|
207
|
+
const record: CompressionAuditRecord = {
|
|
208
|
+
schemaVersion: 1,
|
|
209
|
+
kind: 'reduction-advice',
|
|
210
|
+
sessionId: 'advice-session',
|
|
211
|
+
profile: 'tokenpilot-inspired',
|
|
212
|
+
band: 'not-worth-it',
|
|
213
|
+
stage: 'history',
|
|
214
|
+
itemSeqs: [3],
|
|
215
|
+
pricedCandidates: 1,
|
|
216
|
+
maxTokensBefore: 5_000,
|
|
217
|
+
tokensBefore: 5_000,
|
|
218
|
+
tokensAfter: 4_000,
|
|
219
|
+
recoveredTokens: 1_000,
|
|
220
|
+
penaltyTokens: 3_600,
|
|
221
|
+
paybackTurns: 36,
|
|
222
|
+
expectedSaving: 0,
|
|
223
|
+
}
|
|
224
|
+
const line = formatCompressionAudit(record)
|
|
225
|
+
const parsed = JSON.parse(line.slice(COMPRESSION_AUDIT_PREFIX.length)) as CompressionAuditRecord
|
|
226
|
+
expect(parsed).toEqual(record)
|
|
227
|
+
for (const gone of ['proposalId', 'proposalKind', 'decision', 'receipt', '"event"', 'reasonCode']) {
|
|
228
|
+
expect(line).not.toContain(gone)
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
it('keeps advisor-outcome records free of prompts, keys, and content', () => {
|
|
233
|
+
const record: CompressionAuditRecord = {
|
|
234
|
+
schemaVersion: 1,
|
|
235
|
+
kind: 'advisor-outcome',
|
|
236
|
+
sessionId: 'advisor-session',
|
|
237
|
+
phase: 'decay',
|
|
238
|
+
ok: true,
|
|
239
|
+
sampledCount: 16,
|
|
240
|
+
decay: 0.42,
|
|
241
|
+
weightedChars: 57_688,
|
|
242
|
+
turnIndex: 12,
|
|
243
|
+
latencyMs: 0,
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const line = formatCompressionAudit(record)
|
|
247
|
+
const parsed = JSON.parse(line.slice(COMPRESSION_AUDIT_PREFIX.length)) as CompressionAuditRecord
|
|
248
|
+
expect(parsed).toEqual(record)
|
|
249
|
+
// Only enums and numbers: never the todo snapshot, assistant text, prompts, or keys.
|
|
250
|
+
expect(line).not.toContain('prompt')
|
|
251
|
+
expect(line).not.toContain('"content"')
|
|
252
|
+
expect(line).not.toContain('"text"')
|
|
253
|
+
expect(line).not.toContain('apiKey')
|
|
254
|
+
expect(line).not.toContain('todo')
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('carries failure reason codes and the LLM channel on advisor-outcome records', () => {
|
|
258
|
+
const record: CompressionAuditRecord = {
|
|
259
|
+
schemaVersion: 1,
|
|
260
|
+
kind: 'advisor-outcome',
|
|
261
|
+
sessionId: 'advisor-session',
|
|
262
|
+
phase: 'scoring',
|
|
263
|
+
channel: 'direct',
|
|
264
|
+
ok: false,
|
|
265
|
+
sampledCount: 0,
|
|
266
|
+
turnIndex: 3,
|
|
267
|
+
reason: 'no-direct-endpoint',
|
|
268
|
+
latencyMs: 4,
|
|
269
|
+
}
|
|
270
|
+
const parsed = JSON.parse(
|
|
271
|
+
formatCompressionAudit(record).slice(COMPRESSION_AUDIT_PREFIX.length),
|
|
272
|
+
) as CompressionAuditRecord
|
|
273
|
+
expect(parsed).toEqual(record)
|
|
274
|
+
})
|
|
275
|
+
})
|
|
@@ -33,7 +33,7 @@ describe('autoCompact settings validation', () => {
|
|
|
33
33
|
const settings = parseContextCompressionSettings({
|
|
34
34
|
...structuredClone(BASE_SETTINGS),
|
|
35
35
|
autoCompact: { thresholdPercent },
|
|
36
|
-
}
|
|
36
|
+
})
|
|
37
37
|
expect(settings.autoCompact.thresholdPercent).toBe(thresholdPercent)
|
|
38
38
|
}
|
|
39
39
|
})
|
|
@@ -65,7 +65,7 @@ describe('autoCompact settings validation', () => {
|
|
|
65
65
|
...structuredClone(BASE_SETTINGS),
|
|
66
66
|
autoCompact: { thresholdPercent: 80 },
|
|
67
67
|
unrelated: true,
|
|
68
|
-
}
|
|
68
|
+
})).toThrow(/unknown key/u)
|
|
69
69
|
})
|
|
70
70
|
|
|
71
71
|
it('publishes one shared validation contract for UI, persistence, and runtime', () => {
|
|
@@ -488,7 +488,7 @@ describe('codeSkeleton settings validation', () => {
|
|
|
488
488
|
const settings = parseContextCompressionSettings({
|
|
489
489
|
...structuredClone(BASE_SETTINGS),
|
|
490
490
|
codeSkeleton: { enabled },
|
|
491
|
-
}
|
|
491
|
+
})
|
|
492
492
|
expect(settings.codeSkeleton).toEqual({ enabled })
|
|
493
493
|
}
|
|
494
494
|
})
|
|
@@ -84,13 +84,13 @@ describe('bundled DeepSeek tokenizer artifact registry', () => {
|
|
|
84
84
|
const { mkdtemp, writeFile } = await import('node:fs/promises')
|
|
85
85
|
const { tmpdir } = await import('node:os')
|
|
86
86
|
const { createHash } = await import('node:crypto')
|
|
87
|
-
const
|
|
88
|
-
const root = await mkdtemp(join(tmpdir(), 'dsh-tokenizer-json-corrupt-'))
|
|
87
|
+
const path = await import('node:path')
|
|
88
|
+
const root = await mkdtemp(path.join(tmpdir(), 'dsh-tokenizer-json-corrupt-'))
|
|
89
89
|
try {
|
|
90
90
|
const payload = 'this is definitely not json'
|
|
91
91
|
const bytes = Buffer.from(payload, 'utf8')
|
|
92
|
-
await writeFile(join(root, 'tokenizer.json'), bytes)
|
|
93
|
-
await writeFile(join(root, 'tokenizer_config.json'), bytes)
|
|
92
|
+
await writeFile(path.join(root, 'tokenizer.json'), bytes)
|
|
93
|
+
await writeFile(path.join(root, 'tokenizer_config.json'), bytes)
|
|
94
94
|
const sha256 = createHash('sha256').update(bytes).digest('hex')
|
|
95
95
|
const integrity = {
|
|
96
96
|
tokenizer: { bytes: bytes.byteLength, sha256 },
|