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.
Files changed (70) hide show
  1. package/.github/workflows/ci.yml +39 -39
  2. package/CHANGELOG.ja.md +217 -211
  3. package/CHANGELOG.ko.md +211 -205
  4. package/CHANGELOG.md +392 -350
  5. package/CHANGELOG.zh.md +196 -190
  6. package/README.md +97 -96
  7. package/README.zh.md +86 -85
  8. package/eslint.config.js +76 -30
  9. package/package.json +3 -1
  10. package/packages/selector/dsh.plugin.json +1 -1
  11. package/packages/selector/lib/client.js +747 -3
  12. package/packages/selector/lib/index.js +92 -1
  13. package/packages/selector/lib/{advisor-state.js → intent-gate.js} +91 -3
  14. package/packages/selector/lib/profiles.d.ts +9 -0
  15. package/packages/selector/lib/pruner.d.ts +59 -0
  16. package/packages/selector/lib/pruner.js +410 -8
  17. package/packages/selector/src/client/decode.ts +53 -49
  18. package/packages/selector/src/client/index.ts +30 -0
  19. package/packages/selector/src/client/locales/de.ts +98 -0
  20. package/packages/selector/src/client/locales/es.ts +98 -0
  21. package/packages/selector/src/client/locales/fr.ts +98 -0
  22. package/packages/selector/src/client/locales/it.ts +98 -0
  23. package/packages/selector/src/client/locales/ja.ts +98 -0
  24. package/packages/selector/src/client/locales/ko.ts +98 -0
  25. package/packages/selector/src/client/locales/ru.ts +98 -0
  26. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
  27. package/packages/selector/src/index.ts +418 -411
  28. package/packages/selector/src/preset-overlay.ts +629 -626
  29. package/packages/selector/src/profiles.ts +414 -394
  30. package/packages/selector/src/pruner/content.ts +198 -198
  31. package/packages/selector/src/pruner/state.ts +57 -50
  32. package/packages/selector/src/pruner.ts +2665 -2421
  33. package/packages/selector/src/runtime/audit.ts +303 -286
  34. package/packages/selector/src/runtime/config.ts +731 -706
  35. package/packages/selector/src/runtime/reducers.ts +1674 -1674
  36. package/packages/selector/src/runtime/summary-command.ts +133 -0
  37. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -188
  38. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -149
  39. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
  40. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
  41. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
  42. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
  43. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
  44. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +306 -303
  45. package/packages/selector/src/runtime/types.ts +358 -346
  46. package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
  47. package/packages/selector/tests/built/client-artifact.spec.ts +61 -59
  48. package/packages/selector/tests/code-skeleton.client.spec.ts +94 -93
  49. package/packages/selector/tests/custom-contract.client.spec.ts +223 -222
  50. package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
  51. package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
  52. package/packages/selector/tests/profiles.client.spec.tsx +436 -434
  53. package/packages/selector/tests/runtime/audit.spec.ts +275 -274
  54. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
  55. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
  56. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
  57. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
  58. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +5 -0
  59. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
  60. package/packages/selector/tests/standing-generation.host.spec.ts +15 -35
  61. package/scripts/packed-components-smoke.mjs +734 -732
  62. package/scripts/packed-install-e2e.mjs +1275 -1273
  63. package/scripts/verify-release.mjs +318 -317
  64. package/tests/TEST_INVENTORY.md +41 -41
  65. package/tsconfig.tests.json +17 -15
  66. package/vitest.config.ts +57 -43
  67. package/.agents-stash-064.patch +0 -39
  68. package/_dsh_devdeps.json +0 -50
  69. package/_verify064/package/package.json +0 -162
  70. 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
+ }