dsh-context-compression-improved 0.6.4 → 0.6.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.
Files changed (40) hide show
  1. package/.agents-stash-064.patch +39 -0
  2. package/CHANGELOG.ja.md +42 -0
  3. package/CHANGELOG.ko.md +38 -0
  4. package/CHANGELOG.md +46 -0
  5. package/CHANGELOG.zh.md +38 -0
  6. package/README.ja.md +2 -2
  7. package/README.ko.md +2 -2
  8. package/README.md +5 -3
  9. package/README.zh.md +2 -2
  10. package/_dsh_devdeps.json +50 -0
  11. package/_verify064/package/package.json +162 -0
  12. package/_verify064/package/packages/selector/src/client/index.ts +232 -0
  13. package/package.json +163 -162
  14. package/packages/selector/dsh.plugin.json +16 -16
  15. package/packages/selector/lib/client.js +2 -1
  16. package/packages/selector/lib/style.css +46 -46
  17. package/packages/selector/package.json +114 -114
  18. package/packages/selector/src/client/index.ts +213 -232
  19. package/packages/selector/src/client/scope-face.ts +24 -24
  20. package/packages/selector/src/index.ts +0 -1
  21. package/packages/selector/src/pruner.ts +0 -1
  22. package/packages/selector/tests/custom-contract.client.spec.ts +222 -222
  23. package/packages/selector/tests/helpers/legacy-namespace.ts +8 -4
  24. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -0
  25. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -0
  26. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -0
  27. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -0
  28. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -0
  29. package/packages/selector/tests/host-preset-overlay.host.spec.ts +3 -5
  30. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -206
  31. package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
  32. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -233
  33. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2731 -2727
  34. package/packages/selector/tests/settings-seat.client.spec.ts +165 -165
  35. package/packages/selector/tests/standing-generation.host.spec.ts +724 -704
  36. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +18 -2
  37. package/packages/selector/tests/support/ui-primitives.tsx +34 -34
  38. package/pnpm-workspace.yaml +1 -1
  39. package/scripts/packed-install-e2e.mjs +6 -6
  40. package/scripts/verify-release.mjs +1 -1
@@ -1,233 +1,230 @@
1
- /**
2
- * The retired review gate's replacement, pinned at the host integration level.
3
- *
4
- * This spec exists to make the OLD failure impossible to reintroduce: with the
5
- * exact settings that used to divert 100% of a fresh batch into the human-gated
6
- * review queue (`reviewMode: true` + a `reviewHighImpactTokens` threshold far
7
- * below the batch), the batch must LAND, and the benefit model must publish its
8
- * opinion as a `reduction-advice` audit instead of withholding anything.
9
- *
10
- * "缩减不阻断自动处理": advice describes a landing, it never gates one.
11
- */
12
- import { describe, expect, it, vi } from 'vitest'
13
- import { Context } from '@deepseek-ai/cordis'
14
- import {
15
- ToolCallId as CallId,
16
- createMessage,
17
- createUserMessage,
18
- createToolResultMessage,
19
- } from '@deepseek-ai/dsh-llm'
20
- import SessionStore, {
21
- Session,
22
- SessionId,
23
- canonicalHeader,
24
- } from '@deepseek-ai/dsh-session'
25
- import {
26
- SettingsProvider,
27
- type SettingsNamespace,
28
- } from '@deepseek-ai/dsh-settings'
29
- import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
30
- import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
31
- import TokenMeter from '@deepseek-ai/dsh-token-meter'
32
- import ToolRuntime from '@deepseek-ai/dsh-tools'
33
- import * as SelectorHost from '../../src/index.ts'
34
- import { LegacyNamespaceRegistrar } from '../helpers/legacy-namespace.ts'
35
- import ToolResultPruner, {
36
- CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
37
- } from '../../src/pruner.ts'
38
- import { measureForCompaction } from '../../src/runtime/measurement.ts'
39
- import {
40
- COMPRESSION_AUDIT_PREFIX,
41
- type CompressionAuditRecord,
42
- type CompressionRewriteAuditRecord,
43
- type ReductionAdviceAuditRecord,
44
- } from '../../src/runtime/audit.ts'
45
-
46
- const MODEL = 'deepseek-v4-flash'
47
-
48
- class TestSettings extends SettingsProvider {
49
- readonly writable = true
50
- private readonly stored: Record<string, unknown> = {}
51
-
52
- protected override load(): Promise<Record<string, unknown>> {
53
- return Promise.resolve(structuredClone(this.stored))
54
- }
55
-
56
- protected override persist(namespace: SettingsNamespace, section: Record<string, unknown>): Promise<void> {
57
- this.stored[namespace] = structuredClone(section)
58
- return Promise.resolve()
59
- }
60
- }
61
-
62
- async function runtimeContext(): Promise<Context> {
63
- const ctx = new Context()
64
- await ctx.plugin(SessionStore).await()
65
- await ctx.plugin(SystemPrompt).await()
66
- await ctx.plugin(ToolRuntime).await()
67
- await ctx.plugin(SessionProjectionRegistry).await()
68
- await ctx.plugin(TokenMeter).await()
69
- return ctx
70
- }
71
-
72
- function captureAudit(ctx: Context): { records(): CompressionAuditRecord[] } {
73
- const info = vi.spyOn(ctx.logger, 'info').mockImplementation(() => ctx.logger)
74
- return {
75
- records: () => info.mock.calls.flatMap((call) => {
76
- const line = String(call[0])
77
- return line.startsWith(COMPRESSION_AUDIT_PREFIX)
78
- ? [JSON.parse(line.slice(COMPRESSION_AUDIT_PREFIX.length)) as CompressionAuditRecord]
79
- : []
80
- }),
81
- }
82
- }
83
-
84
- function rewrites(records: readonly CompressionAuditRecord[]): CompressionRewriteAuditRecord[] {
85
- return records.filter((record): record is CompressionRewriteAuditRecord => record.kind === 'rewrite')
86
- }
87
-
88
- function adviceOf(records: readonly CompressionAuditRecord[]): ReductionAdviceAuditRecord[] {
89
- return records.filter((record): record is ReductionAdviceAuditRecord => record.kind === 'reduction-advice')
90
- }
91
-
92
- const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
93
-
94
- function appendToolTurn(session: Session, turn: number, text: string): void {
95
- const callId = CallId(`call-${String(turn)}`)
96
- session.append('turn/start', { turn })
97
- if (session.requestHeader() === undefined) {
98
- session.append('request/header', {
99
- reason: 'initial',
100
- header: canonicalHeader({ config: { provider: 'deepseek', model: MODEL } }),
101
- })
102
- }
103
- session.append('user/message', createUserMessage({
104
- content: [{ type: 'text', text: `user turn ${String(turn)}` }],
105
- source: { kind: 'user' },
106
- }), { surfaceOp: 'append' })
107
- session.append('step/start', { turn, step: 1 })
108
- session.append('assistant/message', {
109
- stream: [],
110
- turn,
111
- step: 1,
112
- message: createMessage({
113
- role: 'assistant',
114
- content: [{ type: 'tool-call', id: callId, name: 'bash', arguments: '{}' }],
115
- source: { kind: 'model', provider: 'deepseek', model: MODEL },
116
- }),
117
- }, { surfaceOp: 'append' })
118
- session.append('tool/call', { turn, step: 1, callId, name: 'bash', arguments: '{}' })
119
- session.append('tool/result', {
120
- turn,
121
- step: 1,
122
- message: createToolResultMessage({
123
- callId,
124
- content: [{ type: 'text', text }],
125
- isError: false,
126
- }),
127
- }, { surfaceOp: 'append' })
128
- session.append('step/end', { turn, step: 1 })
129
- }
130
-
131
- /**
132
- * The settings that used to withhold everything: review mode ON with a
133
- * high-impact threshold of 1 token. History pricing is kept production-like
134
- * (64,000 protected tail tokens) so the batch is only landable through the
135
- * fresh stage.
136
- */
137
- async function gatedSettings(ctx: Context): Promise<void> {
138
- await ctx.plugin(TestSettings).await()
139
- await ctx.plugin(LegacyNamespaceRegistrar).await()
140
- await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
141
- profile: 'tokenpilot-inspired',
142
- presetOptions: { reviewMode: true, reviewHighImpactTokens: 1 },
143
- })
144
- await ctx.plugin(ToolResultPruner, {
145
- profile: 'tokenpilot-inspired',
146
- freshTriggerTokens: 200,
147
- freshTargetTokens: 100,
148
- aggregateTriggerTokens: 1_000_000,
149
- aggregateTargetTokens: 900_000,
150
- historyTriggerTokens: 400,
151
- historyKeepRecentToolCalls: 0,
152
- historyKeepRecentTokens: 64_000,
153
- historyMinReclaimTokens: 1,
154
- }).await()
155
- }
156
-
157
- function freshSession(ctx: Context, id: string, text: string): Session {
158
- const session = Session.create(SessionId(id))
159
- appendToolTurn(session, 1, text)
160
- const total = measureForCompaction(ctx, session).totalTokens
161
- session.append('request/context', {
162
- provider: 'deepseek',
163
- model: MODEL,
164
- contextWindow: Math.floor(total / 0.6),
165
- })
166
- // Fresh landing publishes a surface replacement, which requires an open turn.
167
- session.append('turn/start', { turn: 2 })
168
- return session
169
- }
170
-
171
- /** ~36,400 characters. The shipped advice threshold is 4,000 tokens, and this
172
- * fixture is repetitive enough that the exact tokenizer packs it denser than
173
- * the conservative 4-chars-per-token estimate (an 18,200-character variant
174
- * measured under 4,000 tokens), so the volume is doubled to keep the
175
- * `high-impact` label deterministic. */
176
- const HIGH_IMPACT_TEXT = 'fresh reviewable evidence '.repeat(1_400)
177
-
178
- describe('advice never withholds (retired review gate)', () => {
179
- it('lands the fresh batch the gate used to divert, and advises instead', async () => {
180
- const ctx = await runtimeContext()
181
- await gatedSettings(ctx)
182
- const audit = captureAudit(ctx)
183
- const session = freshSession(ctx, 'advice-lands', HIGH_IMPACT_TEXT)
184
-
185
- const result = ctx.toolResultPruner.pruneSession(session, { stage: 'fresh', freshTurn: 1, freshStep: 1 })
186
- const records = audit.records()
187
-
188
- // 1. The reduction LANDED. Under the retired gate this was the assertion
189
- // that failed: the batch was withheld pending human approval.
190
- expect(result.pruned).toHaveLength(1)
191
- expect(rewrites(records).some(entry => entry.component === 'fresh')).toBe(true)
192
-
193
- // 2. The benefit model still speaks — as advice about the landing.
194
- const advice = adviceOf(records)
195
- expect(advice).toHaveLength(1)
196
- expect(advice[0]!.stage).toBe('fresh')
197
- expect(advice[0]!.band).toBe('high-impact')
198
- expect(advice[0]!.maxTokensBefore).toBeGreaterThanOrEqual(4_000)
199
- expect(advice[0]!.recoveredTokens).toBeGreaterThan(0)
200
- // The batch it describes is exactly the batch that landed.
201
- const landedSeqs = rewrites(records).flatMap(entry => [...entry.sourceSeqs])
202
- expect(advice[0]!.itemSeqs.every(seq => landedSeqs.includes(seq))).toBe(true)
203
-
204
- // 3. Every advice record describes a landing, never a pending decision.
205
- expect(advice.length).toBeLessThanOrEqual(rewrites(records).length)
206
- })
207
-
208
- it('keeps the automatic path identical when no legacy gate key is present', async () => {
209
- const ctx = await runtimeContext()
210
- await ctx.plugin(TestSettings).await()
211
- await ctx.plugin(LegacyNamespaceRegistrar).await()
212
- await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
213
- profile: 'tokenpilot-inspired',
214
- })
215
- await ctx.plugin(ToolResultPruner, {
216
- profile: 'tokenpilot-inspired',
217
- freshTriggerTokens: 200,
218
- freshTargetTokens: 100,
219
- aggregateTriggerTokens: 1_000_000,
220
- aggregateTargetTokens: 900_000,
221
- historyTriggerTokens: 400,
222
- historyKeepRecentToolCalls: 0,
223
- historyKeepRecentTokens: 64_000,
224
- historyMinReclaimTokens: 1,
225
- }).await()
226
- const audit = captureAudit(ctx)
227
- const session = freshSession(ctx, 'advice-default', HIGH_IMPACT_TEXT)
228
-
229
- const result = ctx.toolResultPruner.pruneSession(session, { stage: 'fresh', freshTurn: 1, freshStep: 1 })
230
- expect(result.pruned).toHaveLength(1)
231
- expect(adviceOf(audit.records())).toHaveLength(1)
232
- })
233
- })
1
+ /**
2
+ * The retired review gate's replacement, pinned at the host integration level.
3
+ *
4
+ * This spec exists to make the OLD failure impossible to reintroduce: with the
5
+ * exact settings that used to divert 100% of a fresh batch into the human-gated
6
+ * review queue (`reviewMode: true` + a `reviewHighImpactTokens` threshold far
7
+ * below the batch), the batch must LAND, and the benefit model must publish its
8
+ * opinion as a `reduction-advice` audit instead of withholding anything.
9
+ *
10
+ * "缩减不阻断自动处理": advice describes a landing, it never gates one.
11
+ */
12
+ import { describe, expect, it, vi } from 'vitest'
13
+ import { Context } from '@deepseek-ai/cordis'
14
+ import {
15
+ ToolCallId as CallId,
16
+ createMessage,
17
+ createUserMessage,
18
+ createToolResultMessage,
19
+ } from '@deepseek-ai/dsh-llm'
20
+ import SessionStore, {
21
+ Session,
22
+ SessionId,
23
+ canonicalHeader,
24
+ } from '@deepseek-ai/dsh-session'
25
+ import { type SettingsNamespace } from '@deepseek-ai/dsh-settings'
26
+ import { LegacySettingsProvider } from '../helpers/legacy-settings/index.ts'
27
+ import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
28
+ import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
29
+ import TokenMeter from '@deepseek-ai/dsh-token-meter'
30
+ import ToolRuntime from '@deepseek-ai/dsh-tools'
31
+ import { LegacyNamespaceRegistrar } from '../helpers/legacy-namespace.ts'
32
+ import ToolResultPruner, {
33
+ CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
34
+ } from '../../src/pruner.ts'
35
+ import { measureForCompaction } from '../../src/runtime/measurement.ts'
36
+ import {
37
+ COMPRESSION_AUDIT_PREFIX,
38
+ type CompressionAuditRecord,
39
+ type CompressionRewriteAuditRecord,
40
+ type ReductionAdviceAuditRecord,
41
+ } from '../../src/runtime/audit.ts'
42
+
43
+ const MODEL = 'deepseek-v4-flash'
44
+
45
+ class TestSettings extends LegacySettingsProvider {
46
+ readonly writable = true
47
+ private readonly stored: Record<string, unknown> = {}
48
+
49
+ protected override load(): Promise<Record<string, unknown>> {
50
+ return Promise.resolve(structuredClone(this.stored))
51
+ }
52
+
53
+ protected override persist(namespace: SettingsNamespace, section: Record<string, unknown>): Promise<void> {
54
+ this.stored[namespace] = structuredClone(section)
55
+ return Promise.resolve()
56
+ }
57
+ }
58
+
59
+ async function runtimeContext(): Promise<Context> {
60
+ const ctx = new Context()
61
+ await ctx.plugin(SessionStore).await()
62
+ await ctx.plugin(SystemPrompt).await()
63
+ await ctx.plugin(ToolRuntime).await()
64
+ await ctx.plugin(SessionProjectionRegistry).await()
65
+ await ctx.plugin(TokenMeter).await()
66
+ return ctx
67
+ }
68
+
69
+ function captureAudit(ctx: Context): { records(): CompressionAuditRecord[] } {
70
+ const info = vi.spyOn(ctx.logger, 'info').mockImplementation(() => ctx.logger)
71
+ return {
72
+ records: () => info.mock.calls.flatMap((call) => {
73
+ const line = String(call[0])
74
+ return line.startsWith(COMPRESSION_AUDIT_PREFIX)
75
+ ? [JSON.parse(line.slice(COMPRESSION_AUDIT_PREFIX.length)) as CompressionAuditRecord]
76
+ : []
77
+ }),
78
+ }
79
+ }
80
+
81
+ function rewrites(records: readonly CompressionAuditRecord[]): CompressionRewriteAuditRecord[] {
82
+ return records.filter((record): record is CompressionRewriteAuditRecord => record.kind === 'rewrite')
83
+ }
84
+
85
+ function adviceOf(records: readonly CompressionAuditRecord[]): ReductionAdviceAuditRecord[] {
86
+ return records.filter((record): record is ReductionAdviceAuditRecord => record.kind === 'reduction-advice')
87
+ }
88
+
89
+ const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
90
+
91
+ function appendToolTurn(session: Session, turn: number, text: string): void {
92
+ const callId = CallId(`call-${String(turn)}`)
93
+ session.append('turn/start', { turn })
94
+ if (session.requestHeader() === undefined) {
95
+ session.append('request/header', {
96
+ reason: 'initial',
97
+ header: canonicalHeader({ config: { provider: 'deepseek', model: MODEL } }),
98
+ })
99
+ }
100
+ session.append('user/message', createUserMessage({
101
+ content: [{ type: 'text', text: `user turn ${String(turn)}` }],
102
+ source: { kind: 'user' },
103
+ }), { surfaceOp: 'append' })
104
+ session.append('step/start', { turn, step: 1 })
105
+ session.append('assistant/message', {
106
+ stream: [],
107
+ turn,
108
+ step: 1,
109
+ message: createMessage({
110
+ role: 'assistant',
111
+ content: [{ type: 'tool-call', id: callId, name: 'bash', arguments: '{}' }],
112
+ source: { kind: 'model', provider: 'deepseek', model: MODEL },
113
+ }),
114
+ }, { surfaceOp: 'append' })
115
+ session.append('tool/call', { turn, step: 1, callId, name: 'bash', arguments: '{}' })
116
+ session.append('tool/result', {
117
+ turn,
118
+ step: 1,
119
+ message: createToolResultMessage({
120
+ callId,
121
+ content: [{ type: 'text', text }],
122
+ isError: false,
123
+ }),
124
+ }, { surfaceOp: 'append' })
125
+ session.append('step/end', { turn, step: 1 })
126
+ }
127
+
128
+ /**
129
+ * The settings that used to withhold everything: review mode ON with a
130
+ * high-impact threshold of 1 token. History pricing is kept production-like
131
+ * (64,000 protected tail tokens) so the batch is only landable through the
132
+ * fresh stage.
133
+ */
134
+ async function gatedSettings(ctx: Context): Promise<void> {
135
+ await ctx.plugin(TestSettings).await()
136
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
137
+ await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
138
+ profile: 'tokenpilot-inspired',
139
+ presetOptions: { reviewMode: true, reviewHighImpactTokens: 1 },
140
+ })
141
+ await ctx.plugin(ToolResultPruner, {
142
+ profile: 'tokenpilot-inspired',
143
+ freshTriggerTokens: 200,
144
+ freshTargetTokens: 100,
145
+ aggregateTriggerTokens: 1_000_000,
146
+ aggregateTargetTokens: 900_000,
147
+ historyTriggerTokens: 400,
148
+ historyKeepRecentToolCalls: 0,
149
+ historyKeepRecentTokens: 64_000,
150
+ historyMinReclaimTokens: 1,
151
+ }).await()
152
+ }
153
+
154
+ function freshSession(ctx: Context, id: string, text: string): Session {
155
+ const session = Session.create(SessionId(id))
156
+ appendToolTurn(session, 1, text)
157
+ const total = measureForCompaction(ctx, session).totalTokens
158
+ session.append('request/context', {
159
+ provider: 'deepseek',
160
+ model: MODEL,
161
+ contextWindow: Math.floor(total / 0.6),
162
+ })
163
+ // Fresh landing publishes a surface replacement, which requires an open turn.
164
+ session.append('turn/start', { turn: 2 })
165
+ return session
166
+ }
167
+
168
+ /** ~36,400 characters. The shipped advice threshold is 4,000 tokens, and this
169
+ * fixture is repetitive enough that the exact tokenizer packs it denser than
170
+ * the conservative 4-chars-per-token estimate (an 18,200-character variant
171
+ * measured under 4,000 tokens), so the volume is doubled to keep the
172
+ * `high-impact` label deterministic. */
173
+ const HIGH_IMPACT_TEXT = 'fresh reviewable evidence '.repeat(1_400)
174
+
175
+ describe('advice never withholds (retired review gate)', () => {
176
+ it('lands the fresh batch the gate used to divert, and advises instead', async () => {
177
+ const ctx = await runtimeContext()
178
+ await gatedSettings(ctx)
179
+ const audit = captureAudit(ctx)
180
+ const session = freshSession(ctx, 'advice-lands', HIGH_IMPACT_TEXT)
181
+
182
+ const result = ctx.toolResultPruner.pruneSession(session, { stage: 'fresh', freshTurn: 1, freshStep: 1 })
183
+ const records = audit.records()
184
+
185
+ // 1. The reduction LANDED. Under the retired gate this was the assertion
186
+ // that failed: the batch was withheld pending human approval.
187
+ expect(result.pruned).toHaveLength(1)
188
+ expect(rewrites(records).some(entry => entry.component === 'fresh')).toBe(true)
189
+
190
+ // 2. The benefit model still speaks — as advice about the landing.
191
+ const advice = adviceOf(records)
192
+ expect(advice).toHaveLength(1)
193
+ expect(advice[0]!.stage).toBe('fresh')
194
+ expect(advice[0]!.band).toBe('high-impact')
195
+ expect(advice[0]!.maxTokensBefore).toBeGreaterThanOrEqual(4_000)
196
+ expect(advice[0]!.recoveredTokens).toBeGreaterThan(0)
197
+ // The batch it describes is exactly the batch that landed.
198
+ const landedSeqs = rewrites(records).flatMap(entry => [...entry.sourceSeqs])
199
+ expect(advice[0]!.itemSeqs.every(seq => landedSeqs.includes(seq))).toBe(true)
200
+
201
+ // 3. Every advice record describes a landing, never a pending decision.
202
+ expect(advice.length).toBeLessThanOrEqual(rewrites(records).length)
203
+ })
204
+
205
+ it('keeps the automatic path identical when no legacy gate key is present', async () => {
206
+ const ctx = await runtimeContext()
207
+ await ctx.plugin(TestSettings).await()
208
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
209
+ await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
210
+ profile: 'tokenpilot-inspired',
211
+ })
212
+ await ctx.plugin(ToolResultPruner, {
213
+ profile: 'tokenpilot-inspired',
214
+ freshTriggerTokens: 200,
215
+ freshTargetTokens: 100,
216
+ aggregateTriggerTokens: 1_000_000,
217
+ aggregateTargetTokens: 900_000,
218
+ historyTriggerTokens: 400,
219
+ historyKeepRecentToolCalls: 0,
220
+ historyKeepRecentTokens: 64_000,
221
+ historyMinReclaimTokens: 1,
222
+ }).await()
223
+ const audit = captureAudit(ctx)
224
+ const session = freshSession(ctx, 'advice-default', HIGH_IMPACT_TEXT)
225
+
226
+ const result = ctx.toolResultPruner.pruneSession(session, { stage: 'fresh', freshTurn: 1, freshStep: 1 })
227
+ expect(result.pruned).toHaveLength(1)
228
+ expect(adviceOf(audit.records())).toHaveLength(1)
229
+ })
230
+ })