dsh-context-compression-improved 0.6.1 → 0.6.2

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.
@@ -59,10 +59,7 @@ function tailTrimMessage(stub) {
59
59
  type: "text",
60
60
  text: stub
61
61
  }],
62
- source: {
63
- kind: "plugin",
64
- plugin: "dsh-context-compression-improved-runtime"
65
- }
62
+ source: { kind: "dsh-context-compression" }
66
63
  });
67
64
  }
68
65
  /** Validate the standard prune, adjacent replacement, append roots and stub. */
@@ -71,7 +68,7 @@ function validatePublishedTailTrim(session, manifestSeq) {
71
68
  const manifest = events[manifestSeq];
72
69
  if (manifest?.type !== "compaction/prune" || manifest.data.shadowedSeqs.length < 2 || manifest.data.shadowedSeqs.length > MAX_ROOTS || manifest.data.shadowedSeqs[0] !== Number(manifest.data.shadowedRange.start) || manifest.data.shadowedSeqs.at(-1) !== Number(manifest.data.shadowedRange.end) || new Set(manifest.data.shadowedSeqs).size !== manifest.data.shadowedSeqs.length) return null;
73
70
  const replacement = events[manifestSeq + 1];
74
- if (replacement?.type !== "user/message" || replacement.seq !== manifest.seq + 1 || replacement.data.source.kind !== "plugin" || replacement.data.source.plugin !== "dsh-context-compression-improved-runtime" || replacement.surfaceOp === void 0 || replacement.surfaceOp === "append" || replacement.surfaceOp.startSeq !== manifest.data.shadowedRange.start || replacement.surfaceOp.endSeq !== manifest.data.shadowedRange.end || !sameNumbers(replacement.sourceEventSeqs, [manifest.seq, ...manifest.data.shadowedSeqs]) || replacement.data.content.length !== 1 || replacement.data.content[0]?.type !== "text") return null;
71
+ if (replacement?.type !== "user/message" || replacement.seq !== manifest.seq + 1 || replacement.data.source.kind !== "dsh-context-compression" || replacement.surfaceOp === void 0 || replacement.surfaceOp === "append" || replacement.surfaceOp.startSeq !== manifest.data.shadowedRange.start || replacement.surfaceOp.endSeq !== manifest.data.shadowedRange.end || !sameNumbers(replacement.sourceEventSeqs, [manifest.seq, ...manifest.data.shadowedSeqs]) || replacement.data.content.length !== 1 || replacement.data.content[0]?.type !== "text") return null;
75
72
  const tracedRoots = manifest.data.shadowedSeqs.map((seq) => uniqueAppendRoot(session, seq, manifestSeq));
76
73
  if (tracedRoots.some((root) => root === null)) return null;
77
74
  const sourceEventSeqs = tracedRoots;
@@ -134,7 +131,7 @@ function validRootGroup(roots, manifestSeq) {
134
131
  if (new Set(callIds).size !== callIds.length || roots.length !== callIds.length + 1) return false;
135
132
  for (const [index, root] of roots.slice(1).entries()) {
136
133
  if (root.type !== "tool/result" || root.seq >= manifestSeq || root.surfaceOp !== "append") return false;
137
- if (root.data.message.content[0].isError === true || root.data.error !== void 0 || root.data.turn !== assistant.data.turn || root.data.step !== assistant.data.step || String(root.data.message.source.callId) !== String(callIds[index])) return false;
134
+ if (root.data.message.isError === true || root.data.error !== void 0 || root.data.turn !== assistant.data.turn || root.data.step !== assistant.data.step || String(root.data.message.toolCallId) !== String(callIds[index])) return false;
138
135
  }
139
136
  return true;
140
137
  }
@@ -1,114 +1,114 @@
1
- {
2
- "name": "dsh-context-compression-improved",
3
- "version": "0.2.0",
4
- "description": "One-install context-compression selector bundle for DeepSeek Harness",
5
- "type": "module",
6
- "main": "lib/index.js",
7
- "types": "lib/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./lib/index.d.ts",
11
- "default": "./lib/index.js"
12
- },
13
- "./invariant": {
14
- "types": "./lib/invariant.d.ts",
15
- "default": "./lib/invariant.js"
16
- },
17
- "./pruner": {
18
- "types": "./lib/pruner.d.ts",
19
- "default": "./lib/pruner.js"
20
- },
21
- "./client": {
22
- "types": "./lib/client.d.ts",
23
- "default": "./lib/client.js"
24
- },
25
- "./package.json": "./package.json"
26
- },
27
- "files": [
28
- "lib/**/*.js",
29
- "lib/**/*.d.ts",
30
- "cordis.patch.yml",
31
- "dsh.plugin.json",
32
- "screenshots.json",
33
- "assets",
34
- "README.md",
35
- "README.zh.md",
36
- "LICENSE",
37
- "THIRD_PARTY_NOTICES.md"
38
- ],
39
- "dsh": {
40
- "client": {
41
- "inject": [
42
- "@deepseek-ai/dsh-client-locale",
43
- "@deepseek-ai/dsh-client-ui-slots",
44
- "@deepseek-ai/dsh-client-ui-settings"
45
- ],
46
- "platform": "web"
47
- },
48
- "bundle": {
49
- "patch": "./cordis.patch.yml"
50
- }
51
- },
52
- "scripts": {
53
- "bundle": "tsdown --config tsdown.config.ts && tsdown --config tsdown.client.config.ts",
54
- "typecheck": "tsc --noEmit -p tsconfig.json",
55
- "test": "vitest run --root ../.. --config vitest.config.ts --project runtime --project selector-host --project selector-client",
56
- "pack:dry-run": "npm pack --dry-run"
57
- },
58
- "repository": {
59
- "type": "git",
60
- "url": "git+https://github.com/drscrewdriver/dsh-context-compression-improved.git",
61
- "directory": "packages/selector"
62
- },
63
- "homepage": "https://github.com/drscrewdriver/dsh-context-compression-improved#readme",
64
- "bugs": {
65
- "url": "https://github.com/drscrewdriver/dsh-context-compression-improved/issues"
66
- },
67
- "author": "WilliamShi666",
68
- "engines": {
69
- "node": "^22.19.0 || >=24.0.0",
70
- "dsh": ">=0.1.5-rc.1 <0.2.0-0"
71
- },
72
- "keywords": [
73
- "deepseek",
74
- "harness",
75
- "context",
76
- "compression",
77
- "plugin"
78
- ],
79
- "license": "MIT",
80
- "publishConfig": {
81
- "access": "public",
82
- "tag": "latest"
83
- },
84
- "dependencies": {
85
- "@deepseek-ai/schemastery": "3.18.4",
86
- "@huggingface/tokenizers": "0.1.3",
87
- "js-yaml": "^4.3.2"
88
- },
89
- "peerDependencies": {
90
- "@deepseek-ai/cordis": ">=4.0.1 <5",
91
- "@deepseek-ai/cordis-plugin-include": ">=1.0.6 <2",
92
- "@deepseek-ai/cordis-plugin-loader": ">=1.0.2 <2",
93
- "@deepseek-ai/dsh-agent": ">=0.1.7-rc.1 <0.2.0-0",
94
- "@deepseek-ai/dsh-agent-presets": ">=0.1.7-rc.1 <0.2.0-0",
95
- "@deepseek-ai/dsh-client-locale": ">=0.1.7-rc.1 <0.2.0-0",
96
- "@deepseek-ai/dsh-client-store": ">=0.1.7-rc.1 <0.2.0-0",
97
- "@deepseek-ai/dsh-client-ui-primitives": ">=0.1.7-rc.1 <0.2.0-0",
98
- "@deepseek-ai/dsh-client-ui-session": ">=0.1.7-rc.1 <0.2.0-0",
99
- "@deepseek-ai/dsh-client-ui-settings": ">=0.1.7-rc.1 <0.2.0-0",
100
- "@deepseek-ai/dsh-client-ui-slots": ">=0.1.7-rc.1 <0.2.0-0",
101
- "@deepseek-ai/dsh-client-ui-workspace": ">=0.1.7-rc.1 <0.2.0-0",
102
- "@deepseek-ai/dsh-command-compact": ">=0.1.7-rc.1 <0.2.0-0",
103
- "@deepseek-ai/dsh-compaction": ">=0.1.7-rc.1 <0.2.0-0",
104
- "@deepseek-ai/dsh-compaction-basic": ">=0.1.7-rc.1 <0.2.0-0",
105
- "@deepseek-ai/dsh-invariants": ">=0.1.7-rc.1 <0.2.0-0",
106
- "@deepseek-ai/dsh-llm": ">=0.1.7-rc.1 <0.2.0-0",
107
- "@deepseek-ai/dsh-session": ">=0.1.7-rc.1 <0.2.0-0",
108
- "@deepseek-ai/dsh-settings": ">=0.1.7-rc.1 <0.2.0-0",
109
- "@deepseek-ai/dsh-system-prompt": ">=0.1.7-rc.1 <0.2.0-0",
110
- "@deepseek-ai/dsh-token-meter": ">=0.1.7-rc.1 <0.2.0-0",
111
- "@deepseek-ai/dsh-tools": ">=0.1.7-rc.1 <0.2.0-0",
112
- "react": ">=18 <19"
113
- }
114
- }
1
+ {
2
+ "name": "dsh-context-compression-improved",
3
+ "version": "0.2.0",
4
+ "description": "One-install context-compression selector bundle for DeepSeek Harness",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/index.d.ts",
11
+ "default": "./lib/index.js"
12
+ },
13
+ "./invariant": {
14
+ "types": "./lib/invariant.d.ts",
15
+ "default": "./lib/invariant.js"
16
+ },
17
+ "./pruner": {
18
+ "types": "./lib/pruner.d.ts",
19
+ "default": "./lib/pruner.js"
20
+ },
21
+ "./client": {
22
+ "types": "./lib/client.d.ts",
23
+ "default": "./lib/client.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "lib/**/*.js",
29
+ "lib/**/*.d.ts",
30
+ "cordis.patch.yml",
31
+ "dsh.plugin.json",
32
+ "screenshots.json",
33
+ "assets",
34
+ "README.md",
35
+ "README.zh.md",
36
+ "LICENSE",
37
+ "THIRD_PARTY_NOTICES.md"
38
+ ],
39
+ "dsh": {
40
+ "client": {
41
+ "inject": [
42
+ "@deepseek-ai/dsh-client-locale",
43
+ "@deepseek-ai/dsh-client-ui-slots",
44
+ "@deepseek-ai/dsh-client-ui-settings"
45
+ ],
46
+ "platform": "web"
47
+ },
48
+ "bundle": {
49
+ "patch": "./cordis.patch.yml"
50
+ }
51
+ },
52
+ "scripts": {
53
+ "bundle": "tsdown --config tsdown.config.ts && tsdown --config tsdown.client.config.ts",
54
+ "typecheck": "tsc --noEmit -p tsconfig.json",
55
+ "test": "vitest run --root ../.. --config vitest.config.ts --project runtime --project selector-host --project selector-client",
56
+ "pack:dry-run": "npm pack --dry-run"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/drscrewdriver/dsh-context-compression-improved.git",
61
+ "directory": "packages/selector"
62
+ },
63
+ "homepage": "https://github.com/drscrewdriver/dsh-context-compression-improved#readme",
64
+ "bugs": {
65
+ "url": "https://github.com/drscrewdriver/dsh-context-compression-improved/issues"
66
+ },
67
+ "author": "WilliamShi666",
68
+ "engines": {
69
+ "node": "^22.19.0 || >=24.0.0",
70
+ "dsh": ">=0.1.7-rc.1 <0.1.8-0"
71
+ },
72
+ "keywords": [
73
+ "deepseek",
74
+ "harness",
75
+ "context",
76
+ "compression",
77
+ "plugin"
78
+ ],
79
+ "license": "MIT",
80
+ "publishConfig": {
81
+ "access": "public",
82
+ "tag": "latest"
83
+ },
84
+ "dependencies": {
85
+ "@deepseek-ai/schemastery": "3.18.4",
86
+ "@huggingface/tokenizers": "0.1.3",
87
+ "js-yaml": "^4.3.2"
88
+ },
89
+ "peerDependencies": {
90
+ "@deepseek-ai/cordis": ">=4.0.1 <5",
91
+ "@deepseek-ai/cordis-plugin-include": ">=1.0.6 <2",
92
+ "@deepseek-ai/cordis-plugin-loader": ">=1.0.2 <2",
93
+ "@deepseek-ai/dsh-agent": ">=0.1.7-rc.1 <0.2.0-0",
94
+ "@deepseek-ai/dsh-agent-presets": ">=0.1.7-rc.1 <0.2.0-0",
95
+ "@deepseek-ai/dsh-client-locale": ">=0.1.7-rc.1 <0.2.0-0",
96
+ "@deepseek-ai/dsh-client-store": ">=0.1.7-rc.1 <0.2.0-0",
97
+ "@deepseek-ai/dsh-client-ui-primitives": ">=0.1.7-rc.1 <0.2.0-0",
98
+ "@deepseek-ai/dsh-client-ui-session": ">=0.1.7-rc.1 <0.2.0-0",
99
+ "@deepseek-ai/dsh-client-ui-settings": ">=0.1.7-rc.1 <0.2.0-0",
100
+ "@deepseek-ai/dsh-client-ui-slots": ">=0.1.7-rc.1 <0.2.0-0",
101
+ "@deepseek-ai/dsh-client-ui-workspace": ">=0.1.7-rc.1 <0.2.0-0",
102
+ "@deepseek-ai/dsh-command-compact": ">=0.1.7-rc.1 <0.2.0-0",
103
+ "@deepseek-ai/dsh-compaction": ">=0.1.7-rc.1 <0.2.0-0",
104
+ "@deepseek-ai/dsh-compaction-basic": ">=0.1.7-rc.1 <0.2.0-0",
105
+ "@deepseek-ai/dsh-invariants": ">=0.1.7-rc.1 <0.2.0-0",
106
+ "@deepseek-ai/dsh-llm": ">=0.1.7-rc.1 <0.2.0-0",
107
+ "@deepseek-ai/dsh-session": ">=0.1.7-rc.1 <0.2.0-0",
108
+ "@deepseek-ai/dsh-settings": ">=0.1.7-rc.1 <0.2.0-0",
109
+ "@deepseek-ai/dsh-system-prompt": ">=0.1.7-rc.1 <0.2.0-0",
110
+ "@deepseek-ai/dsh-token-meter": ">=0.1.7-rc.1 <0.2.0-0",
111
+ "@deepseek-ai/dsh-tools": ">=0.1.7-rc.1 <0.2.0-0",
112
+ "react": ">=18 <19"
113
+ }
114
+ }
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  import { useEffect, useId, useState } from 'react'
11
- import { IconChevronDownOutline14, Menu } from '@deepseek-ai/dsh-client-ui-primitives'
11
+ import { IconChevronDownOutlineMedium, Menu } from '@deepseek-ai/dsh-client-ui-primitives'
12
12
  import type { ContextCompressionLocaleKey } from './locales.ts'
13
13
  import css from './CompressionProfileSelector.module.css'
14
14
  import {
@@ -90,7 +90,7 @@ export function CompressionProfileControls({
90
90
  <span className={css.label}>{t('label')}</span>
91
91
  <span className={css.value}>{label}</span>
92
92
  </span>
93
- <IconChevronDownOutline14 className={css.chevron} />
93
+ <IconChevronDownOutlineMedium className={css.chevron} />
94
94
  </button>
95
95
  )}
96
96
  />
@@ -8,7 +8,7 @@
8
8
  * @module dsh-context-compression-improved/client/CompressionProfileSelector
9
9
  */
10
10
 
11
- import type { SettingsScope } from '@deepseek-ai/dsh-client-ui-settings/client'
11
+ import type { SettingsScope } from './scope-face.ts'
12
12
  import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
13
13
  import {
14
14
  COMPRESSION_PROFILES,
@@ -11,8 +11,8 @@ import {
11
11
  import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../profiles.ts'
12
12
  import { decodeSettings } from './decode.ts'
13
13
  import { en, zh } from './locales.ts'
14
- import type { SettingsScope } from '@deepseek-ai/dsh-client-ui-settings/client'
15
14
  import { planPresetOptionsOps, presetOptionsOpsAccepted } from './preset-options.ts'
15
+ import type { SettingsScope } from './scope-face.ts'
16
16
 
17
17
  /**
18
18
  * Harness 0.1.5 mounts the web core's `slots` service on the client context
@@ -29,7 +29,6 @@ interface SlotsService {
29
29
  declare module '@deepseek-ai/cordis' {
30
30
  interface Context {
31
31
  slots: SlotsService
32
- configForms: ConfigFormsFace
33
32
  }
34
33
  }
35
34
 
@@ -115,28 +114,28 @@ export function apply(ctx: ClientContext): void {
115
114
  set: async (field, value) => {
116
115
  const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
117
116
  next[field] = value
118
- await form.set('settings', next)
117
+ return form.set('settings', next)
119
118
  },
120
119
  unset: async (field) => {
121
120
  const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
122
121
  delete next[field]
123
- await form.set('settings', next)
122
+ return form.set('settings', next)
124
123
  },
125
124
  mutate: async (ops) => {
126
125
  const doc = { ...(readDoc() ?? {}) } as Record<string, unknown>
127
126
  for (const op of ops) {
128
127
  const [head, key] = op.path as [string, string]
129
- if (head !== 'presetOptions') return
128
+ if (head !== 'presetOptions') return false
130
129
  const section = { ...((doc.presetOptions ?? {}) as Record<string, unknown>) }
131
130
  if (op.op === 'unset') delete section[key]
132
131
  else section[key] = (op as { value?: unknown }).value
133
132
  doc.presetOptions = section
134
133
  }
135
- await form.set('settings', doc)
134
+ return form.set('settings', doc)
136
135
  },
137
136
  }
138
137
  const writeAndConfirm = async (
139
- write: () => Promise<void>,
138
+ write: () => Promise<unknown>,
140
139
  accepts: (settings: ContextCompressionSettings) => boolean,
141
140
  ): Promise<void> => {
142
141
  const beforeRevision = scope.getSnapshot().revision
@@ -182,7 +181,7 @@ export function apply(ctx: ClientContext): void {
182
181
  const ops = planPresetOptionsOps(scope.getSnapshot().value?.presetOptions, options)
183
182
  if (ops.length === 0) return Promise.resolve()
184
183
  return writeAndConfirm(
185
- () => scope.mutate(ops),
184
+ () => scope.mutate?.(ops) ?? Promise.resolve(false),
186
185
  settings => presetOptionsOpsAccepted(settings.presetOptions, ops),
187
186
  )
188
187
  },
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 0.1.7-rc.2 stopped exporting `SettingsScope` from
3
+ * `@deepseek-ai/dsh-client-ui-settings/client`; the structural face the
4
+ * selector consumes lives here instead (getSnapshot shape mirrors the 0.1.7
5
+ * `ConfigFormSnapshot` minus the parts the components never read).
6
+ */
7
+ export interface SettingsScope<T> {
8
+ getSnapshot(): {
9
+ status: 'loading' | 'ready' | 'unavailable'
10
+ value: T | undefined
11
+ revision: number | undefined
12
+ writable: boolean
13
+ base: unknown
14
+ user: unknown
15
+ mode: 'host' | 'memory'
16
+ }
17
+ subscribe(listener: () => void): () => void
18
+ set(field: string, value: unknown): Promise<boolean>
19
+ unset(field: string): Promise<boolean>
20
+ mutate?(ops: readonly { path: readonly string[]; op: string; value?: unknown }[]): Promise<boolean>
21
+ }
@@ -105,9 +105,6 @@ function pressureCost(blocks: readonly ContentBlock[]): number {
105
105
  + codePointLength(block.name)
106
106
  + codePointLength(block.arguments)
107
107
  break
108
- case 'tool-result':
109
- cost += RICH_BLOCK_PRESSURE_COST + pressureCost(block.content)
110
- break
111
108
  default: {
112
109
  // ContentBlockMap is merge-extensible. Unknown model-visible blocks
113
110
  // scale with their durable JSON payload instead of receiving a fixed
@@ -73,8 +73,10 @@ function tokenizerAuditFact(route: { provider: string, model: string }): { token
73
73
 
74
74
  /** Check whether a snapshot candidate represents an error result. */
75
75
  function isError(candidate: SnapshotCandidate): boolean {
76
- const result = candidate.event.data.message.content[0]
77
- return result.isError === true || candidate.event.data.error !== undefined
76
+ // 0.1.7-rc.2: tool results are first-class `tool`-role messages — `isError`
77
+ // moved from the result block onto the message itself.
78
+ const message = candidate.event.data.message as { isError?: boolean }
79
+ return message.isError === true || candidate.event.data.error !== undefined
78
80
  }
79
81
 
80
82
  /** Wrap a plan list into a HistoryPlanOutcome. */
@@ -14,6 +14,15 @@ import z from '@deepseek-ai/schemastery'
14
14
  import { createUserMessage, freezeMessage } from '@deepseek-ai/dsh-llm'
15
15
  import type { ContentBlock, UserMessage } from '@deepseek-ai/dsh-llm'
16
16
  import { SessionSeq } from '@deepseek-ai/dsh-session'
17
+
18
+ // 0.1.7-rc.2 removed the shared 'plugin' source kind — each producer declares
19
+ // its own kind in its own module (official pattern: compaction's
20
+ // 'compact-checkpoint' in compaction/src/index.ts).
21
+ declare module '@deepseek-ai/dsh-llm' {
22
+ interface MessageSourceMap {
23
+ 'dsh-context-compression': { readonly kind: 'dsh-context-compression' }
24
+ }
25
+ }
17
26
  import type { Session, SessionEvent, ToolResultMessage } from '@deepseek-ai/dsh-session'
18
27
  import type {} from '@deepseek-ai/dsh-agent'
19
28
  import type {} from '@deepseek-ai/dsh-compaction'
@@ -535,7 +544,7 @@ export class ToolResultPruner extends Service {
535
544
  // carrying the marker would fail the host's closed-transaction validation.
536
545
  const replacement = createUserMessage({
537
546
  content,
538
- source: { kind: 'plugin', plugin: 'dsh-context-compression-improved-runtime' },
547
+ source: { kind: 'dsh-context-compression' },
539
548
  })
540
549
  session.append('user/message', replacement, {
541
550
  surfaceOp: { op: 'replace', startSeq: SessionSeq(checkpointSeq), endSeq: SessionSeq(checkpointSeq) },
@@ -1325,11 +1334,11 @@ export class ToolResultPruner extends Service {
1325
1334
  if (shadowedHeuristicTokenCount === undefined) {
1326
1335
  throw new Error(`surface node ${String(seq)} is absent from the atomic legacy projection`)
1327
1336
  }
1328
- const content = event.data.message.content[0].content
1337
+ const content = event.data.message.content
1329
1338
  candidates.push({
1330
1339
  seq,
1331
1340
  event,
1332
- call: calls.get(event.data.message.source.callId) ?? { name: 'unknown', arguments: '{}' },
1341
+ call: calls.get(event.data.message.toolCallId) ?? { name: 'unknown', arguments: '{}' },
1333
1342
  count: onlyTextBlocks(content) === null
1334
1343
  ? unavailableCount(`surface node ${String(seq)} contains unsupported rich tool-result content`)
1335
1344
  : measured.get(seq) ?? unavailableCount(`surface node ${String(seq)} is absent from the atomic token view`),
@@ -1349,7 +1358,7 @@ export class ToolResultPruner extends Service {
1349
1358
  ): PlannedReplacement | null {
1350
1359
  if (this.isRecoveryExempt(session, candidate)) return null
1351
1360
  if (candidate.characterPressure <= charsForTokens(policy.nativeTriggerTokens)) return null
1352
- const result = candidate.event.data.message.content[0]
1361
+ const result = candidate.event.data.message as ToolResultMessage
1353
1362
  if (onlyTextBlocks(result.content) === null) return null
1354
1363
  const sourceSeq = rootToolResultSeq(session, candidate.seq)
1355
1364
  // R9b site: the marker's retrieve hint starts at the event line right
@@ -1401,7 +1410,7 @@ export class ToolResultPruner extends Service {
1401
1410
  view: CompactionTokenView,
1402
1411
  ): PlannedReplacement | null {
1403
1412
  if (typeof candidate.event.surfaceOp === 'object') return null
1404
- const result = candidate.event.data.message.content[0]
1413
+ const result = candidate.event.data.message as ToolResultMessage
1405
1414
  const text = flattenPlainText(result.content)
1406
1415
  if (text === undefined) return null
1407
1416
  if (candidate.characterPressure <= charsForTokens(policy.freshTriggerTokens)) return null
@@ -1449,7 +1458,7 @@ export class ToolResultPruner extends Service {
1449
1458
  // pre-step coordinate filter prevents previously-kept originals from ever
1450
1459
  // being reconsidered after their first request.
1451
1460
  if (typeof candidate.event.surfaceOp === 'object') return null
1452
- const result = candidate.event.data.message.content[0]
1461
+ const result = candidate.event.data.message as ToolResultMessage
1453
1462
  if (candidate.characterPressure <= charsForTokens(policy.freshTriggerTokens)) return null
1454
1463
  const sourceSeq = candidate.seq
1455
1464
  const sourceRef = sourceRefFn(session, sourceSeq)
@@ -1527,7 +1536,7 @@ export class ToolResultPruner extends Service {
1527
1536
  // example one carrying an image) must never reach it. The character basis
1528
1537
  // no longer inherits the exact-tokenizer precondition that used to reject
1529
1538
  // this path implicitly, so the guard has to be explicit.
1530
- const redacted = candidate.event.data.message.content[0]
1539
+ const redacted = candidate.event.data.message as ToolResultMessage
1531
1540
  if (onlyTextBlocks(redacted.content) === null) return null
1532
1541
  const text = [
1533
1542
  '[Tool result reduced to satisfy the completed-step aggregate budget]',
@@ -1561,7 +1570,7 @@ export class ToolResultPruner extends Service {
1561
1570
  historyMode?: HistoryMode,
1562
1571
  ): PlannedReplacement | null {
1563
1572
  if (!isError(candidate)) return null
1564
- const result = candidate.event.data.message.content[0]
1573
+ const result = candidate.event.data.message as ToolResultMessage
1565
1574
  const blocks = onlyTextBlocks(result.content)
1566
1575
  if (blocks === null) return null
1567
1576
  const text = blocks.map(block => block.text).join('\n')
@@ -1619,7 +1628,7 @@ export class ToolResultPruner extends Service {
1619
1628
  const protectedSeqs = this.protectedHistoryCandidateSeqs(candidates, policy)
1620
1629
  const isUnsafe = (candidate: SnapshotCandidate): boolean => {
1621
1630
  if (this.isRecoveryExempt(session, candidate)) return true
1622
- const result = candidate.event.data.message.content[0]
1631
+ const result = candidate.event.data.message as ToolResultMessage
1623
1632
  const block = onlyTextBlock(result.content)
1624
1633
  return block?.text.includes('[Old tool result content cleared from active context]') === true
1625
1634
  }
@@ -1649,7 +1658,7 @@ export class ToolResultPruner extends Service {
1649
1658
  ? minReclaimChars
1650
1659
  : required
1651
1660
  for (const candidate of eligible) {
1652
- const result = candidate.event.data.message.content[0]
1661
+ const result = candidate.event.data.message as ToolResultMessage
1653
1662
  const block = onlyTextBlock(result.content)
1654
1663
  // TokenPilot-inspired R2: a read output whose file was later mutated is
1655
1664
  // superseded — its text can no longer match the file — so it takes the
@@ -1858,11 +1867,11 @@ export class ToolResultPruner extends Service {
1858
1867
  if (event?.type !== 'tool/result'
1859
1868
  || event.data.turn !== assistant.data.turn || event.data.step !== assistant.data.step
1860
1869
  || event.data.error !== undefined) return true
1861
- const block = event.data.message.content[0]
1870
+ const block = event.data.message as ToolResultMessage
1862
1871
  if (block.isError === true) return true
1863
1872
  // Images and other rich inner blocks stay fail-open: a TailTrim stub
1864
1873
  // would silently delete them from the active context.
1865
- return block.content.some(contentBlock => contentBlock.type !== 'text')
1874
+ return block.content.some((contentBlock: ContentBlock) => contentBlock.type !== 'text')
1866
1875
  })) continue
1867
1876
  const next = events[nodes[index + 1 + calls.length] ?? -1]
1868
1877
  if (next?.type === 'tool/result'
@@ -2049,7 +2058,7 @@ export class ToolResultPruner extends Service {
2049
2058
  // noise without reclaiming context. Text-level because the placeholder
2050
2059
  // guidance lines (source refs, retrieval hints) must pay for themselves.
2051
2060
  if (options.noNetSavingsGuard === true) {
2052
- const originalBlocks = onlyTextBlocks(candidate.event.data.message.content[0].content)
2061
+ const originalBlocks = onlyTextBlocks(candidate.event.data.message.content)
2053
2062
  const replacementBlocks = onlyTextBlocks(content)
2054
2063
  if (originalBlocks !== null && replacementBlocks !== null) {
2055
2064
  const originalChars = originalBlocks.reduce((sum, block) => sum + codePointLength(block.text), 0)
@@ -2078,10 +2087,12 @@ export class ToolResultPruner extends Service {
2078
2087
 
2079
2088
  private land(session: Session, plan: PlannedReplacement): PrunedEntry | null {
2080
2089
  const { candidate } = plan
2081
- const result = candidate.event.data.message.content[0]
2090
+ const result = candidate.event.data.message as ToolResultMessage
2091
+ // 0.1.7-rc.2: the tool message's own `content` is the result block set —
2092
+ // no wrapping result block anymore.
2082
2093
  const message = freezeMessage<ToolResultMessage>({
2083
2094
  ...candidate.event.data.message,
2084
- content: [{ ...result, content: plan.content }] as [typeof result],
2095
+ content: plan.content,
2085
2096
  })
2086
2097
  const manifest = session.append('compaction/prune', {
2087
2098
  shadowedRange: { start: SessionSeq(candidate.seq), end: SessionSeq(candidate.seq) },
@@ -35,8 +35,9 @@ export type { TokenCount } from './token-count.ts'
35
35
  * @returns character pressure in Unicode code points, plus rich-block costs.
36
36
  */
37
37
  function nodeCharacterPressure(content: readonly ContentBlock[]): number {
38
- const only = content.length === 1 ? content[0] : undefined
39
- return pressureCost(only?.type === 'tool-result' ? only.content : content)
38
+ // 0.1.7-rc.2: tool results are tool-role messages, so a node's content
39
+ // array can no longer wrap them — the blocks are measured as-is.
40
+ return pressureCost(content)
40
41
  }
41
42
 
42
43
  /** Request identity retained only when every dimension is publicly known. */
@@ -252,10 +253,6 @@ function countCanonicalContent(
252
253
  if (!absorb(counter.countText(block.arguments))) return false
253
254
  break
254
255
  }
255
- case 'tool-result': {
256
- if (!walk(block.content)) return false
257
- break
258
- }
259
256
  case 'image': {
260
257
  if (!absorb(counter.countImage(block.attachment))) return false
261
258
  break
@@ -377,8 +374,6 @@ function intrinsicImageDiagnostic(
377
374
  paddingMinimumTokens += estimate.paddingMinimumTokens
378
375
  paddingMaximumTokens += estimate.paddingMaximumTokens
379
376
  seen = true
380
- } else if (block.type === 'tool-result') {
381
- walk(block.content)
382
377
  }
383
378
  }
384
379
  }
@@ -110,7 +110,7 @@ export function installContextCompressionRetrieve(ctx: Context, config: Config =
110
110
  throw new Error(`context_compression_retrieve: event ${String(seq)} is not a tool/result in the current session`)
111
111
  }
112
112
  const maxLines = resolveMaxLines(args.max_lines)
113
- const scan = scanBlocks(event.data.message.content[0].content, maxScanChars)
113
+ const scan = scanBlocks(event.data.message.content, maxScanChars)
114
114
  const scannedLines = splitScannedLines(scan)
115
115
  const lines = scannedLines.lines
116
116
  const query = args.query
@@ -125,8 +125,8 @@ export function installContextCompressionRetrieve(ctx: Context, config: Config =
125
125
  const total = scan.complete ? String(lines.length) : `at least ${String(lines.length)}`
126
126
  const header = [
127
127
  `source: ${args.ref}`,
128
- `tool_call_id: ${event.data.message.source.callId}`,
129
- `status: ${event.data.message.content[0].isError === true ? 'error' : 'completed'}`,
128
+ `tool_call_id: ${event.data.message.toolCallId}`,
129
+ `status: ${(event.data.message as { isError?: boolean }).isError === true ? 'error' : 'completed'}`,
130
130
  `lines: ${String(selected.start)}-${String(selected.end)} of ${total}`,
131
131
  scan.complete ? '' : 'note: source scan limit reached; later lines were not inspected',
132
132
  selected.partialLine === undefined
@@ -55,7 +55,7 @@ export function tailTrimStub(
55
55
  export function tailTrimMessage(stub: string): UserMessage {
56
56
  return createUserMessage({
57
57
  content: [{ type: 'text', text: stub }],
58
- source: { kind: 'plugin', plugin: 'dsh-context-compression-improved-runtime' },
58
+ source: { kind: 'dsh-context-compression' },
59
59
  })
60
60
  }
61
61
 
@@ -75,8 +75,7 @@ export function validatePublishedTailTrim(
75
75
  const replacement = events[manifestSeq + 1]
76
76
  if (replacement?.type !== 'user/message'
77
77
  || replacement.seq !== manifest.seq + 1
78
- || replacement.data.source.kind !== 'plugin'
79
- || replacement.data.source.plugin !== 'dsh-context-compression-improved-runtime'
78
+ || replacement.data.source.kind !== 'dsh-context-compression'
80
79
  || replacement.surfaceOp === undefined
81
80
  || replacement.surfaceOp === 'append'
82
81
  || replacement.surfaceOp.startSeq !== manifest.data.shadowedRange.start
@@ -150,12 +149,12 @@ function validRootGroup(roots: readonly SessionEvent[], manifestSeq: number): bo
150
149
  if (new Set(callIds).size !== callIds.length || roots.length !== callIds.length + 1) return false
151
150
  for (const [index, root] of roots.slice(1).entries()) {
152
151
  if (root.type !== 'tool/result' || root.seq >= manifestSeq || root.surfaceOp !== 'append') return false
153
- const result = root.data.message.content[0]
152
+ const result = root.data.message as { isError?: boolean }
154
153
  if (result.isError === true
155
154
  || root.data.error !== undefined
156
155
  || root.data.turn !== assistant.data.turn
157
156
  || root.data.step !== assistant.data.step
158
- || String(root.data.message.source.callId) !== String(callIds[index])) return false
157
+ || String((root.data.message as { toolCallId?: unknown }).toolCallId) !== String(callIds[index])) return false
159
158
  }
160
159
  return true
161
160
  }