dsh-context-compression-improved 0.2.4 → 0.2.5
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 +2 -1
- package/.githooks/pre-push +37 -0
- package/.github/workflows/ci.yml +8 -8
- package/CHANGELOG.ja.md +169 -39
- package/CHANGELOG.ko.md +167 -39
- package/CHANGELOG.md +212 -16
- package/CHANGELOG.zh.md +152 -39
- package/CONTRIBUTING.md +22 -22
- package/README.ja.md +85 -104
- package/README.ko.md +85 -103
- package/README.md +1 -19
- package/README.zh.md +85 -101
- package/THIRD_PARTY_NOTICES.md +14 -14
- package/docs/compat-0.1.5-report.md +77 -0
- package/docs/installation.ja.md +78 -76
- package/docs/installation.ko.md +78 -76
- package/docs/installation.md +103 -76
- package/docs/installation.zh.md +100 -76
- package/docs/repair-log.md +657 -582
- package/eslint.config.js +30 -30
- package/package.json +75 -54
- package/packages/selector/README.md +7 -12
- package/packages/selector/README.zh.md +6 -13
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -38
- package/packages/selector/cordis.patch.yml +27 -19
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.d.ts +97 -5
- package/packages/selector/lib/client.js +1884 -92
- package/packages/selector/lib/config.js +863 -6
- package/packages/selector/lib/index.d.ts +29 -21
- package/packages/selector/lib/index.js +424 -18
- package/packages/selector/lib/invariant.js +4 -4
- package/packages/selector/lib/pruner.d.ts +179 -4
- package/packages/selector/lib/pruner.js +1406 -371
- package/packages/selector/lib/style.css +42 -0
- package/packages/selector/lib/tail-trim.js +13 -4
- package/packages/selector/package.json +18 -27
- package/packages/selector/screenshots.json +3 -6
- package/packages/selector/src/client/CompressionProfileControls.tsx +293 -229
- package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
- package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -79
- package/packages/selector/src/client/EstimatorControls.tsx +277 -281
- package/packages/selector/src/client/decode.ts +57 -49
- package/packages/selector/src/client/index.ts +200 -62
- package/packages/selector/src/client/locales/de.ts +141 -0
- package/packages/selector/src/client/locales/es.ts +141 -0
- package/packages/selector/src/client/locales/fr.ts +141 -0
- package/packages/selector/src/client/locales/it.ts +141 -0
- package/packages/selector/src/client/locales/ja.ts +141 -0
- package/packages/selector/src/client/locales/ko.ts +141 -0
- package/packages/selector/src/client/locales/ru.ts +141 -0
- package/packages/selector/src/client/locales.ts +282 -198
- package/packages/selector/src/client/monitor-fab.ts +336 -0
- package/packages/selector/src/client/preset-options.ts +88 -70
- package/packages/selector/src/client/savings-card.tsx +150 -0
- package/packages/selector/src/client/settings-section.tsx +140 -126
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -210
- package/packages/selector/src/index.ts +671 -327
- package/packages/selector/src/invariant.ts +113 -113
- package/packages/selector/src/profiles.ts +431 -342
- package/packages/selector/src/pruner/state.ts +57 -43
- package/packages/selector/src/pruner.ts +2736 -2154
- package/packages/selector/src/runtime/audit.ts +303 -231
- package/packages/selector/src/runtime/config.ts +756 -642
- package/packages/selector/src/runtime/measurement.ts +436 -432
- 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/session-events.ts +30 -17
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tail-trim.ts +166 -166
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -183
- 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/sidechannel.ts +303 -275
- package/packages/selector/src/runtime/types.ts +365 -325
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -226
- package/packages/selector/tests/built/client-artifact.spec.ts +59 -51
- package/packages/selector/tests/code-skeleton.client.spec.ts +91 -88
- package/packages/selector/tests/custom-contract.client.spec.ts +205 -202
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -247
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -176
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -204
- package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
- package/packages/selector/tests/preset-options-write.client.spec.ts +207 -181
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +201 -196
- package/packages/selector/tests/preset-overlay.host.spec.ts +8 -18
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -33
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -0
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
- package/packages/selector/tests/runtime/audit.spec.ts +275 -172
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
- 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/monitor.spec.ts +301 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2724 -2702
- package/packages/selector/tests/runtime/savings.spec.ts +120 -0
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -56
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -100
- package/packages/selector/tests/settings-seat.client.spec.ts +130 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +142 -87
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +253 -250
- package/pnpm-workspace.yaml +66 -19
- package/scripts/capture-profile-baseline.mjs +42 -0
- package/scripts/generate-tokenizer-fixtures.py +81 -81
- package/scripts/generate-vision-fixtures.py +208 -208
- package/scripts/{packed-components-smoke.ts → packed-components-smoke.mjs} +732 -713
- package/scripts/{packed-install-e2e.ts → packed-install-e2e.mjs} +1273 -1072
- package/scripts/toolclass-corpus-replay.mjs +281 -273
- package/scripts/{verify-release.ts → verify-release.mjs} +318 -300
- package/tests/TEST_INVENTORY.md +41 -42
- package/scripts/capture-profile-baseline.ts +0 -80
- package/tsconfig.scripts.json +0 -13
- /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-profiles.jpg +0 -0
- /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-settings.png +0 -0
|
@@ -1,231 +1,303 @@
|
|
|
1
|
-
/** Structured, content-free runtime audit records for context compression. */
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
| '
|
|
18
|
-
| '
|
|
19
|
-
| '
|
|
20
|
-
| '
|
|
21
|
-
| '
|
|
22
|
-
| '
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
readonly
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
readonly
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
readonly
|
|
41
|
-
readonly
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
readonly
|
|
48
|
-
readonly
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
readonly
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
readonly
|
|
76
|
-
readonly
|
|
77
|
-
readonly
|
|
78
|
-
readonly
|
|
79
|
-
readonly
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
readonly
|
|
86
|
-
readonly
|
|
87
|
-
readonly
|
|
88
|
-
readonly
|
|
89
|
-
readonly
|
|
90
|
-
readonly
|
|
91
|
-
readonly
|
|
92
|
-
readonly
|
|
93
|
-
readonly
|
|
94
|
-
readonly
|
|
95
|
-
readonly
|
|
96
|
-
readonly
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*
|
|
100
|
-
* tokenizer
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
readonly
|
|
106
|
-
readonly
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
readonly
|
|
121
|
-
readonly
|
|
122
|
-
readonly
|
|
123
|
-
readonly
|
|
124
|
-
readonly
|
|
125
|
-
readonly
|
|
126
|
-
readonly
|
|
127
|
-
readonly
|
|
128
|
-
readonly
|
|
129
|
-
readonly
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
readonly
|
|
140
|
-
readonly
|
|
141
|
-
|
|
142
|
-
| '
|
|
143
|
-
| '
|
|
144
|
-
| '
|
|
145
|
-
| '
|
|
146
|
-
|
|
147
|
-
readonly
|
|
148
|
-
readonly
|
|
149
|
-
readonly
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
readonly
|
|
156
|
-
readonly
|
|
157
|
-
readonly
|
|
158
|
-
readonly
|
|
159
|
-
readonly
|
|
160
|
-
readonly
|
|
161
|
-
readonly
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
readonly
|
|
168
|
-
readonly
|
|
169
|
-
readonly
|
|
170
|
-
readonly
|
|
171
|
-
readonly
|
|
172
|
-
readonly
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
readonly
|
|
179
|
-
readonly
|
|
180
|
-
readonly
|
|
181
|
-
readonly
|
|
182
|
-
readonly
|
|
183
|
-
readonly
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
|
192
|
-
|
|
193
|
-
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
|
|
199
|
-
/**
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
1
|
+
/** Structured, content-free runtime audit records for context compression. */
|
|
2
|
+
|
|
3
|
+
import type { AdviceBand } from './tokenpilot/benefit.ts'
|
|
4
|
+
import type {
|
|
5
|
+
CompressionPolicy,
|
|
6
|
+
CompressionProfile,
|
|
7
|
+
ContextCompressionSettings,
|
|
8
|
+
HistoryMode,
|
|
9
|
+
ResolvedConfig,
|
|
10
|
+
} from './types.ts'
|
|
11
|
+
|
|
12
|
+
/** Stable prefix used to locate one JSON audit record in Harness runtime logs. */
|
|
13
|
+
export const COMPRESSION_AUDIT_PREFIX = 'context-compression audit '
|
|
14
|
+
|
|
15
|
+
/** Compression primitive that committed one model-free surface rewrite. */
|
|
16
|
+
export type CompressionAuditComponent =
|
|
17
|
+
| 'fresh'
|
|
18
|
+
| 'aggregate'
|
|
19
|
+
| 'history'
|
|
20
|
+
| 'tail-trim'
|
|
21
|
+
| 'native-tool-result'
|
|
22
|
+
| 'dedupe'
|
|
23
|
+
| 'summary-locator'
|
|
24
|
+
|
|
25
|
+
/** Non-mutating outcome of evaluating one component at one runtime boundary. */
|
|
26
|
+
export type CompressionAuditEvaluationStatus = 'disabled' | 'skipped'
|
|
27
|
+
|
|
28
|
+
interface CompressionAuditBase {
|
|
29
|
+
readonly schemaVersion: 1
|
|
30
|
+
readonly sessionId: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Complete settings and deployment config frozen on first runtime observation. */
|
|
34
|
+
export interface CompressionPolicyFrozenAuditRecord extends CompressionAuditBase {
|
|
35
|
+
readonly kind: 'policy-frozen'
|
|
36
|
+
readonly settingsSource: 'host-settings' | 'plugin-config-fallback'
|
|
37
|
+
/** Where the frozen Auto Compact threshold came from. */
|
|
38
|
+
readonly autoCompactThresholdSource?: 'generation-config' | 'host-settings' | 'schema-default'
|
|
39
|
+
/** Present when the stored document was invalid and the session froze losslessly. */
|
|
40
|
+
readonly settingsInvalidFallback?: 'lossless-off'
|
|
41
|
+
readonly settings: ContextCompressionSettings
|
|
42
|
+
readonly deploymentConfig: ResolvedConfig
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Routed request facts captured alongside one policy resolution. */
|
|
46
|
+
export interface CompressionRouteAuditFact {
|
|
47
|
+
readonly provider: string
|
|
48
|
+
readonly model: string
|
|
49
|
+
readonly modality?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Bundled tokenizer identity backing exact counts for one route. */
|
|
53
|
+
export interface CompressionTokenizerAuditFact {
|
|
54
|
+
readonly repository: string
|
|
55
|
+
readonly revision: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** How the resolved History watermarks were derived for one Session. */
|
|
59
|
+
export interface CompressionCoordinationAuditFact {
|
|
60
|
+
/** Frozen Auto Compact threshold percent from the settings snapshot. */
|
|
61
|
+
readonly thresholdPercent: number
|
|
62
|
+
/** `A = floor(C × a)`; undefined when linkage did not resolve. */
|
|
63
|
+
readonly autoCompactTokens?: number
|
|
64
|
+
/** `D = floor(A × 0.875)`; undefined when linkage did not resolve. */
|
|
65
|
+
readonly microDeadlineTokens?: number
|
|
66
|
+
/**
|
|
67
|
+
* Whether History follows the Auto Compact watermark, explicit deployment
|
|
68
|
+
* overrides, a mix of both, Custom manual tokens, or the fixed preset.
|
|
69
|
+
*/
|
|
70
|
+
readonly paramSource: 'auto-compact-linked' | 'deployment-override' | 'mixed' | 'custom-manual' | 'fixed-preset'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** One effective policy resolution, including context-percent capacity when used. */
|
|
74
|
+
export interface CompressionPolicyResolvedAuditRecord extends CompressionAuditBase {
|
|
75
|
+
readonly kind: 'policy-resolved'
|
|
76
|
+
readonly policy: CompressionPolicy
|
|
77
|
+
readonly contextWindowTokens?: number
|
|
78
|
+
readonly coordination?: CompressionCoordinationAuditFact
|
|
79
|
+
readonly route?: CompressionRouteAuditFact
|
|
80
|
+
readonly tokenizer?: CompressionTokenizerAuditFact
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** One committed model-free surface rewrite and its accounting. */
|
|
84
|
+
export interface CompressionRewriteAuditRecord extends CompressionAuditBase {
|
|
85
|
+
readonly kind: 'rewrite'
|
|
86
|
+
readonly profile: CompressionProfile
|
|
87
|
+
readonly component: CompressionAuditComponent
|
|
88
|
+
readonly stage: 'fresh' | 'pressure'
|
|
89
|
+
readonly reducer: string
|
|
90
|
+
readonly historyMode?: HistoryMode
|
|
91
|
+
readonly manifestEventType: 'compaction/prune'
|
|
92
|
+
readonly manifestSeq: number
|
|
93
|
+
readonly replacementSeq: number
|
|
94
|
+
readonly sourceSeqs: readonly number[]
|
|
95
|
+
readonly tokensBefore: number
|
|
96
|
+
readonly tokensAfter: number
|
|
97
|
+
readonly tokensRemoved: number
|
|
98
|
+
/**
|
|
99
|
+
* Which measurement backed this record's decision and token figures:
|
|
100
|
+
* 'exact-tokenizer' when both sides of the reduction carry one bundled
|
|
101
|
+
* tokenizer identity, 'characters' when the proof ran on Unicode code
|
|
102
|
+
* points and `tokensBefore/After` were derived at 4.0 chars per token
|
|
103
|
+
* (`tokenizerId: 'characters'`, `tokenizerRevision: 'chars-per-token-4.0'`).
|
|
104
|
+
*/
|
|
105
|
+
readonly measurementBasis: 'exact-tokenizer' | 'characters'
|
|
106
|
+
readonly tokenizerId: string
|
|
107
|
+
readonly tokenizerRevision: string
|
|
108
|
+
/**
|
|
109
|
+
* Original-event lines the reducer elided (task_4c/G7, from
|
|
110
|
+
* `ReducerOutput.elidedLines` via the plan). Present when the landing
|
|
111
|
+
* reducer reports it; absent for placeholder/trim rewrites. Exists so the
|
|
112
|
+
* compress→retrieve M/N ratio is computable from session logs alone —
|
|
113
|
+
* never printed into replacement content.
|
|
114
|
+
*/
|
|
115
|
+
readonly elidedLines?: number
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Why an enabled component did not rewrite, or why it was disabled. */
|
|
119
|
+
export interface CompressionComponentEvaluationAuditRecord extends CompressionAuditBase {
|
|
120
|
+
readonly kind: 'component-evaluation'
|
|
121
|
+
readonly profile: CompressionProfile
|
|
122
|
+
readonly component: CompressionAuditComponent
|
|
123
|
+
readonly stage: 'fresh' | 'pressure'
|
|
124
|
+
readonly status: CompressionAuditEvaluationStatus
|
|
125
|
+
readonly reason: string
|
|
126
|
+
readonly historyMode?: HistoryMode
|
|
127
|
+
readonly measurementKind?: 'exact-tokenizer' | 'tokenizer-estimate' | 'characters' | 'unavailable'
|
|
128
|
+
readonly currentTokens?: number
|
|
129
|
+
readonly triggerTokens?: number
|
|
130
|
+
readonly targetTokens?: number
|
|
131
|
+
/** Reclaim the planned batch reached (insufficient-reclaim family only). */
|
|
132
|
+
readonly reclaimTokens?: number
|
|
133
|
+
/** Reclaim the batch required (insufficient-reclaim family only). */
|
|
134
|
+
readonly requiredTokens?: number
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** One fail-open runtime error, without prompt or tool-result content. */
|
|
138
|
+
export interface CompressionFailureAuditRecord extends CompressionAuditBase {
|
|
139
|
+
readonly kind: 'failure'
|
|
140
|
+
readonly stage: 'fresh' | 'pressure'
|
|
141
|
+
readonly operation:
|
|
142
|
+
| 'request-boundary'
|
|
143
|
+
| 'terminal-pass'
|
|
144
|
+
| 'policy-resolution'
|
|
145
|
+
| 'summary-locator'
|
|
146
|
+
| 'publication'
|
|
147
|
+
readonly component?: CompressionAuditComponent
|
|
148
|
+
readonly manifestSeq?: number
|
|
149
|
+
readonly errorName: string
|
|
150
|
+
readonly errorMessage: string
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** One observed core Native auto-compaction summary event. */
|
|
154
|
+
export interface NativeAutoCompactAuditRecord extends CompressionAuditBase {
|
|
155
|
+
readonly kind: 'native-auto-compact'
|
|
156
|
+
readonly manifestEventType: 'compaction/summary'
|
|
157
|
+
readonly manifestSeq: number
|
|
158
|
+
readonly reducer: 'llm-summary'
|
|
159
|
+
readonly provider: string
|
|
160
|
+
readonly model: string
|
|
161
|
+
readonly tokensBefore: number | null
|
|
162
|
+
readonly tokensAfter: null
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** One Exact Sources locator block appended to a landed Auto Compact summary. */
|
|
166
|
+
export interface SummaryLocatorAuditRecord extends CompressionAuditBase {
|
|
167
|
+
readonly kind: 'summary-locator'
|
|
168
|
+
readonly profile: CompressionProfile
|
|
169
|
+
readonly checkpointSeq: number
|
|
170
|
+
readonly summarySeq: number
|
|
171
|
+
readonly locatorChars: number
|
|
172
|
+
readonly spillFiles: number
|
|
173
|
+
readonly touchedFiles: number
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** One background estimator pass. Only numeric metadata — never prompts or keys. */
|
|
177
|
+
export interface EstimatorOutcomeAuditRecord extends CompressionAuditBase {
|
|
178
|
+
readonly kind: 'estimator-outcome'
|
|
179
|
+
readonly profile: CompressionProfile
|
|
180
|
+
readonly channel: 'host' | 'direct'
|
|
181
|
+
readonly sampled: number
|
|
182
|
+
readonly expired: number
|
|
183
|
+
readonly latencyMs: number
|
|
184
|
+
readonly ok: boolean
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** One background relevance-advisor pass. Only numeric metadata — never prompts, keys, or content. */
|
|
188
|
+
export interface AdvisorOutcomeAuditRecord extends CompressionAuditBase {
|
|
189
|
+
readonly kind: 'advisor-outcome'
|
|
190
|
+
/** Which advisory stage produced this record. */
|
|
191
|
+
readonly phase: 'summary' | 'scoring' | 'decay'
|
|
192
|
+
/** LLM channel; omitted for the locally computed 'decay' phase. */
|
|
193
|
+
readonly channel?: 'host' | 'direct'
|
|
194
|
+
readonly ok: boolean
|
|
195
|
+
/** Whether the pass found candidates to sample (scoring phase). */
|
|
196
|
+
readonly sampledCount?: number
|
|
197
|
+
/** Prefix-decay figure in [0, 1] (decay phase; also emitted by summary/scoring on success). */
|
|
198
|
+
readonly decay?: number
|
|
199
|
+
/** Weighted surface the decay was computed over, in Unicode code points. */
|
|
200
|
+
readonly weightedChars?: number
|
|
201
|
+
/** Turn index the pass ran at. */
|
|
202
|
+
readonly turnIndex?: number
|
|
203
|
+
/** Aligned failure/skip reason code (e.g. 'no-direct-endpoint', 'parse-failed'). */
|
|
204
|
+
readonly reason?: string
|
|
205
|
+
readonly latencyMs: number
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** One turn-tail intent-summary pass: gate decision, ask outcome, or landing. Numeric metadata only. */
|
|
209
|
+
export interface IntentSummaryOutcomeAuditRecord extends CompressionAuditBase {
|
|
210
|
+
readonly kind: 'intent-summary-outcome'
|
|
211
|
+
readonly ok: boolean
|
|
212
|
+
/** Aligned decision/reason code (gate reason, 'parse-failed', 'landed', 'expired'...). */
|
|
213
|
+
readonly reason: string
|
|
214
|
+
readonly turnIndex?: number
|
|
215
|
+
/** Folded candidate count when a range was selected or landed. */
|
|
216
|
+
readonly foldedCount?: number
|
|
217
|
+
/** Aggregate retention ratio of the landed batch (charsAfter / charsBefore). */
|
|
218
|
+
readonly retentionRatio?: number
|
|
219
|
+
/** Characters spent on the summary-writer call itself (credit accounting). */
|
|
220
|
+
readonly summaryCallChars?: number
|
|
221
|
+
readonly latencyMs?: number
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* One advisory benefit-model label for a batch that LANDED. The retired review
|
|
226
|
+
* gate used these bands to withhold a batch; a reduction must never block
|
|
227
|
+
* automatic processing, so the band is published as advice instead. Numeric and
|
|
228
|
+
* enum fields only — never content.
|
|
229
|
+
*/
|
|
230
|
+
export interface ReductionAdviceAuditRecord extends CompressionAuditBase {
|
|
231
|
+
readonly kind: 'reduction-advice'
|
|
232
|
+
/** Profile the advised pass ran under. */
|
|
233
|
+
readonly profile: CompressionProfile
|
|
234
|
+
/** Band the benefit model labelled the landed batch with. */
|
|
235
|
+
readonly band: AdviceBand
|
|
236
|
+
/** Landing stage the batch was priced at. */
|
|
237
|
+
readonly stage: 'fresh' | 'history'
|
|
238
|
+
readonly itemSeqs: readonly number[]
|
|
239
|
+
/** Candidates that carried a positive recovery and were priced. */
|
|
240
|
+
readonly pricedCandidates: number
|
|
241
|
+
/** Largest single-candidate token mass in the batch. */
|
|
242
|
+
readonly maxTokensBefore: number
|
|
243
|
+
readonly tokensBefore: number
|
|
244
|
+
readonly tokensAfter: number
|
|
245
|
+
readonly recoveredTokens: number
|
|
246
|
+
readonly penaltyTokens: number
|
|
247
|
+
/** Turns of discounted recovery needed to recoup the refill penalty. */
|
|
248
|
+
readonly paybackTurns?: number
|
|
249
|
+
/** Discounted net benefit over the remaining session; omitted when Ŝ is unknown. */
|
|
250
|
+
readonly expectedSaving?: number
|
|
251
|
+
/** Turn index the batch landed at. */
|
|
252
|
+
readonly turnIndex?: number
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Closed version-one context-compression audit vocabulary. */
|
|
256
|
+
export type CompressionAuditRecord =
|
|
257
|
+
| CompressionPolicyFrozenAuditRecord
|
|
258
|
+
| CompressionPolicyResolvedAuditRecord
|
|
259
|
+
| CompressionRewriteAuditRecord
|
|
260
|
+
| CompressionComponentEvaluationAuditRecord
|
|
261
|
+
| CompressionFailureAuditRecord
|
|
262
|
+
| NativeAutoCompactAuditRecord
|
|
263
|
+
| SummaryLocatorAuditRecord
|
|
264
|
+
| EstimatorOutcomeAuditRecord
|
|
265
|
+
| AdvisorOutcomeAuditRecord
|
|
266
|
+
| IntentSummaryOutcomeAuditRecord
|
|
267
|
+
| ReductionAdviceAuditRecord
|
|
268
|
+
|
|
269
|
+
/** Minimal logger method consumed by the audit publisher. */
|
|
270
|
+
export interface CompressionAuditLogger {
|
|
271
|
+
/**
|
|
272
|
+
* Publish one informational message.
|
|
273
|
+
* @param message - complete single-line audit message.
|
|
274
|
+
* @returns logger-specific chaining value, if any.
|
|
275
|
+
*/
|
|
276
|
+
info(message: string): unknown
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Encode one stable single-line audit message.
|
|
281
|
+
* @param record - content-free structured audit record.
|
|
282
|
+
* @returns the fixed prefix followed by one JSON object.
|
|
283
|
+
*/
|
|
284
|
+
export function formatCompressionAudit(record: CompressionAuditRecord): string {
|
|
285
|
+
return `${COMPRESSION_AUDIT_PREFIX}${JSON.stringify(record)}`
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Publish one audit message through the Harness logger.
|
|
290
|
+
* @param logger - current plugin logger.
|
|
291
|
+
* @param record - structured record committed by the caller.
|
|
292
|
+
*/
|
|
293
|
+
export function emitCompressionAudit(
|
|
294
|
+
logger: CompressionAuditLogger,
|
|
295
|
+
record: CompressionAuditRecord,
|
|
296
|
+
): void {
|
|
297
|
+
try {
|
|
298
|
+
logger.info(formatCompressionAudit(record))
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
// Swallow logger failures: audit publication must not roll back a committed rewrite.
|
|
302
|
+
}
|
|
303
|
+
}
|