dsh-context-compression-improved 0.6.5 → 0.7.0-beta.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.
- package/.github/workflows/ci.yml +39 -39
- package/CHANGELOG.ja.md +217 -211
- package/CHANGELOG.ko.md +211 -205
- package/CHANGELOG.md +392 -350
- package/CHANGELOG.zh.md +196 -190
- package/README.md +97 -96
- package/README.zh.md +86 -85
- package/eslint.config.js +76 -30
- package/package.json +3 -1
- package/packages/selector/dsh.plugin.json +1 -1
- package/packages/selector/lib/client.js +747 -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/src/client/decode.ts +53 -49
- package/packages/selector/src/client/index.ts +30 -0
- package/packages/selector/src/client/locales/de.ts +98 -0
- package/packages/selector/src/client/locales/es.ts +98 -0
- package/packages/selector/src/client/locales/fr.ts +98 -0
- package/packages/selector/src/client/locales/it.ts +98 -0
- package/packages/selector/src/client/locales/ja.ts +98 -0
- package/packages/selector/src/client/locales/ko.ts +98 -0
- package/packages/selector/src/client/locales/ru.ts +98 -0
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
- package/packages/selector/src/index.ts +418 -411
- package/packages/selector/src/preset-overlay.ts +629 -626
- package/packages/selector/src/profiles.ts +414 -394
- package/packages/selector/src/pruner/content.ts +198 -198
- package/packages/selector/src/pruner/state.ts +57 -50
- package/packages/selector/src/pruner.ts +2665 -2421
- package/packages/selector/src/runtime/audit.ts +303 -286
- package/packages/selector/src/runtime/config.ts +731 -706
- package/packages/selector/src/runtime/reducers.ts +1674 -1674
- package/packages/selector/src/runtime/summary-command.ts +133 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -188
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -149
- 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 +128 -128
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +306 -303
- package/packages/selector/src/runtime/types.ts +358 -346
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
- package/packages/selector/tests/built/client-artifact.spec.ts +61 -59
- 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/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 +523 -523
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
- 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 +734 -732
- package/scripts/packed-install-e2e.mjs +1275 -1273
- package/scripts/verify-release.mjs +318 -317
- package/tests/TEST_INVENTORY.md +41 -41
- package/tsconfig.tests.json +17 -15
- package/vitest.config.ts +57 -43
- 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,128 +1,128 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TokenPilot-inspired A2: Exact Sources locator block appended to the Auto
|
|
3
|
-
* Compact summary checkpoint AFTER compaction/end.
|
|
4
|
-
*
|
|
5
|
-
* The block carries three kinds of locators over the shadowed range — the seq
|
|
6
|
-
* range itself, spill files named by the Harness spill notices, and files
|
|
7
|
-
* touched by read/grep-style tool calls — so details removed by the LLM
|
|
8
|
-
* summary remain recoverable through ordinary file reads, the recovery tool,
|
|
9
|
-
* or session event references. The block is only a few hundred bytes and is
|
|
10
|
-
* skipped entirely when it would locate nothing concrete.
|
|
11
|
-
*/
|
|
12
|
-
import type { SessionEvent } from '@deepseek-ai/dsh-session'
|
|
13
|
-
|
|
14
|
-
/** One resolved compaction transaction to annotate. */
|
|
15
|
-
export interface CompactionTrace {
|
|
16
|
-
readonly compactionId: string
|
|
17
|
-
readonly summarySeq: number
|
|
18
|
-
readonly summaryShadowedRange: { readonly start: number, readonly end: number }
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Files touched by read/grep-style tool calls inside the range. */
|
|
22
|
-
const TOUCHED_FILE_TOOL = /(?:^|[-_])?(?:read|write|edit|glob|grep|view|str_replace_editor)(?:$|[-_])/i
|
|
23
|
-
/** Spill notice paths emitted by the Harness output-retention policy. */
|
|
24
|
-
const SPILL_PATH = /stored at:\s*([^\s)\]]+)/g
|
|
25
|
-
/** Tool call arguments keys that commonly carry a file path. */
|
|
26
|
-
const PATH_KEYS = ['path', 'file_path'] as const
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Find the latest compaction/summary event matching the compaction id of a
|
|
30
|
-
* compaction/end event. Returns undefined when the transaction cannot be
|
|
31
|
-
* identified — the caller must skip rather than guess.
|
|
32
|
-
*/
|
|
33
|
-
export function findCompactionTrace(
|
|
34
|
-
events: readonly SessionEvent[],
|
|
35
|
-
compactionId: string,
|
|
36
|
-
): CompactionTrace | undefined {
|
|
37
|
-
let trace: CompactionTrace | undefined
|
|
38
|
-
for (const event of events) {
|
|
39
|
-
if (event.type === 'compaction/summary' && event.data.compactionId === compactionId) {
|
|
40
|
-
trace = {
|
|
41
|
-
compactionId,
|
|
42
|
-
summarySeq: event.seq,
|
|
43
|
-
summaryShadowedRange: event.data.shadowedRange,
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return trace
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Extract spill file paths from one text chunk. */
|
|
51
|
-
export function extractSpillPaths(text: string): string[] {
|
|
52
|
-
const paths: string[] = []
|
|
53
|
-
for (const match of text.matchAll(SPILL_PATH)) {
|
|
54
|
-
const path = match[1]?.replace(/[.,;]+$/, '')
|
|
55
|
-
if (path !== undefined && path.length > 0) paths.push(path)
|
|
56
|
-
}
|
|
57
|
-
return paths
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Extract touched file paths from one tool/call event's arguments. */
|
|
61
|
-
export function extractTouchedPath(name: string, argumentsText: string): string | undefined {
|
|
62
|
-
if (!TOUCHED_FILE_TOOL.test(name)) return undefined
|
|
63
|
-
let parsed: unknown
|
|
64
|
-
try {
|
|
65
|
-
parsed = JSON.parse(argumentsText)
|
|
66
|
-
} catch {
|
|
67
|
-
return undefined
|
|
68
|
-
}
|
|
69
|
-
if (typeof parsed !== 'object' || parsed === null) return undefined
|
|
70
|
-
const record = parsed as Record<string, unknown>
|
|
71
|
-
for (const key of PATH_KEYS) {
|
|
72
|
-
const value = record[key]
|
|
73
|
-
if (typeof value === 'string' && value.length > 0) return value
|
|
74
|
-
}
|
|
75
|
-
return undefined
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Result of one locator block build: text plus locator census for auditing. */
|
|
79
|
-
export interface LocatorBlock {
|
|
80
|
-
readonly text: string
|
|
81
|
-
readonly spillFiles: number
|
|
82
|
-
readonly touchedFiles: number
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Build the Exact Sources block for one shadowed range, or null when the
|
|
87
|
-
* range locates nothing concrete (no spill files and no touched files).
|
|
88
|
-
*/
|
|
89
|
-
export function buildLocatorBlock(
|
|
90
|
-
events: readonly SessionEvent[],
|
|
91
|
-
shadowedRange: { readonly start: number, readonly end: number },
|
|
92
|
-
): LocatorBlock | null {
|
|
93
|
-
const spillFiles = new Set<string>()
|
|
94
|
-
const touchedFiles = new Set<string>()
|
|
95
|
-
for (let seq = shadowedRange.start; seq <= shadowedRange.end && seq < events.length; seq += 1) {
|
|
96
|
-
const event = events[seq]
|
|
97
|
-
if (event === undefined) continue
|
|
98
|
-
if (event.type === 'tool/call') {
|
|
99
|
-
const path = extractTouchedPath(event.data.name, event.data.arguments)
|
|
100
|
-
if (path !== undefined) touchedFiles.add(path)
|
|
101
|
-
continue
|
|
102
|
-
}
|
|
103
|
-
if (event.type === 'tool/result' || event.type === 'user/message') {
|
|
104
|
-
// tool/result nests content under data.message; user/message carries it directly.
|
|
105
|
-
const data = event.data as { content?: unknown, message?: { content?: unknown } }
|
|
106
|
-
const content = Array.isArray(data.content) ? data.content : data.message?.content
|
|
107
|
-
if (!Array.isArray(content)) continue
|
|
108
|
-
for (const block of content) {
|
|
109
|
-
if (block.type === 'text') {
|
|
110
|
-
for (const path of extractSpillPaths(block.text)) spillFiles.add(path)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (spillFiles.size === 0 && touchedFiles.size === 0) return null
|
|
116
|
-
const lines = [
|
|
117
|
-
'## Exact Sources (locators)',
|
|
118
|
-
`- seq range: ${String(shadowedRange.start)}-${String(shadowedRange.end)}`,
|
|
119
|
-
...[...spillFiles].map(path => `- spill file: ${path}`),
|
|
120
|
-
...[...touchedFiles].map(path => `- file touched: ${path}`),
|
|
121
|
-
'(Use `read <spill file>` or `context_compression_retrieve` with a `session://` source — pass start_line/max_lines to window the text — to restore exact text.)',
|
|
122
|
-
]
|
|
123
|
-
return {
|
|
124
|
-
text: lines.join('\n'),
|
|
125
|
-
spillFiles: spillFiles.size,
|
|
126
|
-
touchedFiles: touchedFiles.size,
|
|
127
|
-
}
|
|
128
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* TokenPilot-inspired A2: Exact Sources locator block appended to the Auto
|
|
3
|
+
* Compact summary checkpoint AFTER compaction/end.
|
|
4
|
+
*
|
|
5
|
+
* The block carries three kinds of locators over the shadowed range — the seq
|
|
6
|
+
* range itself, spill files named by the Harness spill notices, and files
|
|
7
|
+
* touched by read/grep-style tool calls — so details removed by the LLM
|
|
8
|
+
* summary remain recoverable through ordinary file reads, the recovery tool,
|
|
9
|
+
* or session event references. The block is only a few hundred bytes and is
|
|
10
|
+
* skipped entirely when it would locate nothing concrete.
|
|
11
|
+
*/
|
|
12
|
+
import type { SessionEvent } from '@deepseek-ai/dsh-session'
|
|
13
|
+
|
|
14
|
+
/** One resolved compaction transaction to annotate. */
|
|
15
|
+
export interface CompactionTrace {
|
|
16
|
+
readonly compactionId: string
|
|
17
|
+
readonly summarySeq: number
|
|
18
|
+
readonly summaryShadowedRange: { readonly start: number, readonly end: number }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Files touched by read/grep-style tool calls inside the range. */
|
|
22
|
+
const TOUCHED_FILE_TOOL = /(?:^|[-_])?(?:read|write|edit|glob|grep|view|str_replace_editor)(?:$|[-_])/i
|
|
23
|
+
/** Spill notice paths emitted by the Harness output-retention policy. */
|
|
24
|
+
const SPILL_PATH = /stored at:\s*([^\s)\]]+)/g
|
|
25
|
+
/** Tool call arguments keys that commonly carry a file path. */
|
|
26
|
+
const PATH_KEYS = ['path', 'file_path'] as const
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Find the latest compaction/summary event matching the compaction id of a
|
|
30
|
+
* compaction/end event. Returns undefined when the transaction cannot be
|
|
31
|
+
* identified — the caller must skip rather than guess.
|
|
32
|
+
*/
|
|
33
|
+
export function findCompactionTrace(
|
|
34
|
+
events: readonly SessionEvent[],
|
|
35
|
+
compactionId: string,
|
|
36
|
+
): CompactionTrace | undefined {
|
|
37
|
+
let trace: CompactionTrace | undefined
|
|
38
|
+
for (const event of events) {
|
|
39
|
+
if (event.type === 'compaction/summary' && event.data.compactionId === compactionId) {
|
|
40
|
+
trace = {
|
|
41
|
+
compactionId,
|
|
42
|
+
summarySeq: event.seq,
|
|
43
|
+
summaryShadowedRange: event.data.shadowedRange,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return trace
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Extract spill file paths from one text chunk. */
|
|
51
|
+
export function extractSpillPaths(text: string): string[] {
|
|
52
|
+
const paths: string[] = []
|
|
53
|
+
for (const match of text.matchAll(SPILL_PATH)) {
|
|
54
|
+
const path = match[1]?.replace(/[.,;]+$/, '')
|
|
55
|
+
if (path !== undefined && path.length > 0) paths.push(path)
|
|
56
|
+
}
|
|
57
|
+
return paths
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Extract touched file paths from one tool/call event's arguments. */
|
|
61
|
+
export function extractTouchedPath(name: string, argumentsText: string): string | undefined {
|
|
62
|
+
if (!TOUCHED_FILE_TOOL.test(name)) return undefined
|
|
63
|
+
let parsed: unknown
|
|
64
|
+
try {
|
|
65
|
+
parsed = JSON.parse(argumentsText)
|
|
66
|
+
} catch {
|
|
67
|
+
return undefined
|
|
68
|
+
}
|
|
69
|
+
if (typeof parsed !== 'object' || parsed === null) return undefined
|
|
70
|
+
const record = parsed as Record<string, unknown>
|
|
71
|
+
for (const key of PATH_KEYS) {
|
|
72
|
+
const value = record[key]
|
|
73
|
+
if (typeof value === 'string' && value.length > 0) return value
|
|
74
|
+
}
|
|
75
|
+
return undefined
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Result of one locator block build: text plus locator census for auditing. */
|
|
79
|
+
export interface LocatorBlock {
|
|
80
|
+
readonly text: string
|
|
81
|
+
readonly spillFiles: number
|
|
82
|
+
readonly touchedFiles: number
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Build the Exact Sources block for one shadowed range, or null when the
|
|
87
|
+
* range locates nothing concrete (no spill files and no touched files).
|
|
88
|
+
*/
|
|
89
|
+
export function buildLocatorBlock(
|
|
90
|
+
events: readonly SessionEvent[],
|
|
91
|
+
shadowedRange: { readonly start: number, readonly end: number },
|
|
92
|
+
): LocatorBlock | null {
|
|
93
|
+
const spillFiles = new Set<string>()
|
|
94
|
+
const touchedFiles = new Set<string>()
|
|
95
|
+
for (let seq = shadowedRange.start; seq <= shadowedRange.end && seq < events.length; seq += 1) {
|
|
96
|
+
const event = events[seq]
|
|
97
|
+
if (event === undefined) continue
|
|
98
|
+
if (event.type === 'tool/call') {
|
|
99
|
+
const path = extractTouchedPath(event.data.name, event.data.arguments)
|
|
100
|
+
if (path !== undefined) touchedFiles.add(path)
|
|
101
|
+
continue
|
|
102
|
+
}
|
|
103
|
+
if (event.type === 'tool/result' || event.type === 'user/message') {
|
|
104
|
+
// tool/result nests content under data.message; user/message carries it directly.
|
|
105
|
+
const data = event.data as { content?: unknown, message?: { content?: unknown } }
|
|
106
|
+
const content = Array.isArray(data.content) ? data.content : data.message?.content
|
|
107
|
+
if (!Array.isArray(content)) continue
|
|
108
|
+
for (const block of content as Array<{ type?: unknown, text?: unknown }>) {
|
|
109
|
+
if (block.type === 'text' && typeof block.text === 'string') {
|
|
110
|
+
for (const path of extractSpillPaths(block.text)) spillFiles.add(path)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (spillFiles.size === 0 && touchedFiles.size === 0) return null
|
|
116
|
+
const lines = [
|
|
117
|
+
'## Exact Sources (locators)',
|
|
118
|
+
`- seq range: ${String(shadowedRange.start)}-${String(shadowedRange.end)}`,
|
|
119
|
+
...[...spillFiles].map(path => `- spill file: ${path}`),
|
|
120
|
+
...[...touchedFiles].map(path => `- file touched: ${path}`),
|
|
121
|
+
'(Use `read <spill file>` or `context_compression_retrieve` with a `session://` source — pass start_line/max_lines to window the text — to restore exact text.)',
|
|
122
|
+
]
|
|
123
|
+
return {
|
|
124
|
+
text: lines.join('\n'),
|
|
125
|
+
spillFiles: spillFiles.size,
|
|
126
|
+
touchedFiles: touchedFiles.size,
|
|
127
|
+
}
|
|
128
|
+
}
|