dsh-context-compression-improved 0.14.1 → 0.14.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/package.json +1 -1
- package/packages/selector/dsh.plugin.json +1 -1
- package/packages/selector/lib/client.js +1 -0
- package/packages/selector/lib/profiles.d.ts +1 -1
- package/packages/selector/package.json +1 -1
- package/packages/selector/src/profiles.ts +1 -0
- package/packages/selector/src/runtime/presets.ts +78 -0
- package/packages/selector/src/runtime/update-checker.ts +90 -0
- package/packages/selector/src/runtime/watchlist.ts +82 -0
- package/packages/selector/tests/profiles.client.spec.tsx +5 -5
- package/packages/selector/tests/runtime/behavior-lock-profiles.spec.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-external/dsh-context-compression-improved",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"description": "Token-saving, auditable tool-result context-compression selector with code-skeleton gate for DeepSeek Harness — fewer tokens on every turn",
|
|
6
6
|
"engines": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/profiles.d.ts
|
|
2
2
|
/** Public context-compression choices shared by the Host schema and browser selector. */
|
|
3
|
-
declare const COMPRESSION_PROFILES: readonly ["off", "native", "balanced", "cache-strict", "savings", "adaptive", "tokenpilot-inspired", "ptc", "custom"];
|
|
3
|
+
declare const COMPRESSION_PROFILES: readonly ["off", "native", "balanced", "cache-strict", "savings", "adaptive", "tokenpilot-inspired", "ptc", "flash-tuned", "custom"];
|
|
4
4
|
/** One supported context-compression profile. */
|
|
5
5
|
type CompressionProfile = typeof COMPRESSION_PROFILES[number];
|
|
6
6
|
/** Single canonical unit stored by a version-1 browser Custom document. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-context-compression-improved",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"description": "Token-saving context-compression selector bundle for DeepSeek Harness — fewer tool-result tokens on every turn, fully auditable",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preset tiers (F7) and update-checker (F19) stubs.
|
|
3
|
+
*
|
|
4
|
+
* Plan: cci-longterm-refactor v0.14.4 / v0.14.6
|
|
5
|
+
*
|
|
6
|
+
* @module dsh-context-compression-improved/runtime/presets
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs'
|
|
9
|
+
import { join } from 'node:path'
|
|
10
|
+
|
|
11
|
+
export interface PresetTier {
|
|
12
|
+
readonly name: string
|
|
13
|
+
readonly description: string
|
|
14
|
+
readonly settings: {
|
|
15
|
+
readonly minNetGain?: number
|
|
16
|
+
readonly autoCompact?: { readonly thresholdPercent: number }
|
|
17
|
+
readonly codeSkeleton?: { readonly enabled: boolean }
|
|
18
|
+
readonly cardMerge?: { readonly enabled: boolean }
|
|
19
|
+
readonly zeroCopy?: boolean
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const PRESET_RECOMMENDED: PresetTier = {
|
|
24
|
+
name: 'recommended',
|
|
25
|
+
description: '日常首选:小刀常开、中刀关、骨架开、大刀阈值 70%',
|
|
26
|
+
settings: { minNetGain: 1000, autoCompact: { thresholdPercent: 70 }, codeSkeleton: { enabled: true }, cardMerge: { enabled: false } },
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const PRESET_SMALL_KNIFE: PresetTier = {
|
|
30
|
+
name: 'small-knife-first',
|
|
31
|
+
description: '小刀优先:多切少压、连续 4 刀、中刀冷却 10min',
|
|
32
|
+
settings: { minNetGain: 500, autoCompact: { thresholdPercent: 80 }, codeSkeleton: { enabled: true }, cardMerge: { enabled: false } },
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const PRESET_BIG_KNIFE: PresetTier = {
|
|
36
|
+
name: 'big-knife-first',
|
|
37
|
+
description: '大刀优先:压住成本、少切快摘要、minNetGain=3000',
|
|
38
|
+
settings: { minNetGain: 3000, autoCompact: { thresholdPercent: 50 }, codeSkeleton: { enabled: true }, cardMerge: { enabled: false } },
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const ALL_PRESETS: readonly PresetTier[] = [PRESET_RECOMMENDED, PRESET_SMALL_KNIFE, PRESET_BIG_KNIFE]
|
|
42
|
+
|
|
43
|
+
/** Preset storage file path. */
|
|
44
|
+
function presetsFilePath(): string {
|
|
45
|
+
const dshHome = process.env.DSH_HOME ?? join(process.env.USERPROFILE || process.env.HOME || '', '.dsh')
|
|
46
|
+
return join(dshHome, 'storages', 'dsh-context-compression', 'presets.json')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface PresetDocument {
|
|
50
|
+
'session:<sid>'?: PresetTier['settings']
|
|
51
|
+
'workspace:<dir>'?: PresetTier['settings']
|
|
52
|
+
all?: PresetTier['settings']
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Load the preset document, creating defaults if missing. */
|
|
56
|
+
export function loadPresets(): PresetDocument {
|
|
57
|
+
const path = presetsFilePath()
|
|
58
|
+
if (!existsSync(path)) return {}
|
|
59
|
+
try { return JSON.parse(readFileSync(path, 'utf8')) as PresetDocument } catch { return {} }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Save a preset at the given scope. */
|
|
63
|
+
export function savePreset(scope: string, settings: PresetTier['settings']): void {
|
|
64
|
+
const path = presetsFilePath()
|
|
65
|
+
const dir = path.substring(0, path.lastIndexOf('\\') > -1 ? path.lastIndexOf('\\') : path.lastIndexOf('/'))
|
|
66
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true })
|
|
67
|
+
const doc = loadPresets()
|
|
68
|
+
doc[scope as keyof PresetDocument] = settings
|
|
69
|
+
writeFileSync(path, JSON.stringify(doc, null, 2), 'utf8')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Resolve effective preset: session > workspace > all > undefined. */
|
|
73
|
+
export function resolvePreset(sessionScope?: string, workspaceScope?: string): PresetTier['settings'] | undefined {
|
|
74
|
+
const doc = loadPresets()
|
|
75
|
+
if (sessionScope && doc[`session:${sessionScope}`]) return doc[`session:${sessionScope}`]
|
|
76
|
+
if (workspaceScope && doc[`workspace:${workspaceScope}`]) return doc[`workspace:${workspaceScope}`]
|
|
77
|
+
return doc.all
|
|
78
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-update pre-download checker (F19).
|
|
3
|
+
*
|
|
4
|
+
* Plan: cci-longterm-refactor v0.14.6
|
|
5
|
+
*
|
|
6
|
+
* Checks npm registry metadata for newer versions and pre-downloads tarballs.
|
|
7
|
+
* Does NOT auto-install — generates offline upgrade scripts for user control.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-context-compression-improved/runtime/update-checker
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'node:fs'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
|
|
14
|
+
export interface UpdateCheckResult {
|
|
15
|
+
readonly available: boolean
|
|
16
|
+
readonly currentVersion: string
|
|
17
|
+
readonly latestVersion?: string
|
|
18
|
+
readonly tarballPath?: string
|
|
19
|
+
readonly shasumValid?: boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const STAGING_DIR_NAME = '_staging'
|
|
23
|
+
const DISMISSED_FILE = 'dismissed.json'
|
|
24
|
+
|
|
25
|
+
function getStagingDir(): string {
|
|
26
|
+
const dshHome = process.env.DSH_HOME ?? join(process.env.USERPROFILE || process.env.HOME || '', '.dsh')
|
|
27
|
+
return join(dshHome, STAGING_DIR_NAME)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getDismissedSet(): Set<string> {
|
|
31
|
+
const path = join(getStagingDir(), DISMISSED_FILE)
|
|
32
|
+
if (!existsSync(path)) return new Set()
|
|
33
|
+
try { return new Set(JSON.parse(readFileSync(path, 'utf8')) as string[]) } catch { return new Set() }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check if a newer version is available (metadata-only, no tarball download).
|
|
38
|
+
* Returns null if check failed or no update available.
|
|
39
|
+
*/
|
|
40
|
+
export function compareVersions(current: string, latest: string): boolean {
|
|
41
|
+
const c = current.split('.').map(Number)
|
|
42
|
+
const l = latest.split('.').map(Number)
|
|
43
|
+
for (let i = 0; i < 3; i++) {
|
|
44
|
+
if ((l[i] ?? 0) > (c[i] ?? 0)) return true
|
|
45
|
+
if ((l[i] ?? 0) < (c[i] ?? 0)) return false
|
|
46
|
+
}
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Check if a specific version has been dismissed by the user. */
|
|
51
|
+
export function isDismissed(pkgName: string, version: string): boolean {
|
|
52
|
+
return getDismissedSet().has(`${pkgName}@${version}`)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Dismiss a version (won't prompt again for this version). */
|
|
56
|
+
export function dismissVersion(pkgName: string, version: string): void {
|
|
57
|
+
const dir = getStagingDir()
|
|
58
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true })
|
|
59
|
+
const set = getDismissedSet()
|
|
60
|
+
set.add(`${pkgName}@${version}`)
|
|
61
|
+
writeFileSync(join(dir, DISMISSED_FILE), JSON.stringify([...set]), 'utf8')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Generate an offline upgrade script for a staged tarball.
|
|
66
|
+
* Script is written but NEVER executed automatically.
|
|
67
|
+
*/
|
|
68
|
+
export function generateUpgradeScript(pkgName: string, version: string, profileDir: string): string {
|
|
69
|
+
const script = `#!/usr/bin/env node
|
|
70
|
+
// CCI pre-download upgrade script — generated ${new Date().toISOString()}
|
|
71
|
+
// Usage: Close DSH, then run: node this-script.mjs
|
|
72
|
+
import { execSync } from 'node:child_process'
|
|
73
|
+
import { existsSync } from 'node:fs'
|
|
74
|
+
import { join } from 'node:path'
|
|
75
|
+
|
|
76
|
+
const STAGING = join(process.env.DSH_HOME || join(process.env.USERPROFILE || process.env.HOME, '.dsh'), '${STAGING_DIR_NAME}')
|
|
77
|
+
const TARBALL = join(STAGING, '${pkgName}-${version}.tgz')
|
|
78
|
+
const PROFILE = '${profileDir}'
|
|
79
|
+
|
|
80
|
+
if (!existsSync(TARBALL)) { console.error('TARBALL not found:', TARBALL); process.exit(1) }
|
|
81
|
+
|
|
82
|
+
// Verify DSH is not running (Windows)
|
|
83
|
+
try { execSync('tasklist /FI "IMAGENAME eq DeepSeek Harness.exe"', { stdio: 'pipe' }); console.warn('WARNING: DSH may still be running') } catch {}
|
|
84
|
+
|
|
85
|
+
console.log('Upgrading ${pkgName}@${version}...')
|
|
86
|
+
execSync(\`pnpm add "file:\${TARBALL}" --dir "\${PROFILE}" --registry https://registry.npmjs.org\`, { stdio: 'inherit' })
|
|
87
|
+
console.log('Done. Restart DSH to load the update.')
|
|
88
|
+
`
|
|
89
|
+
return script
|
|
90
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-plugin watchlist (F20).
|
|
3
|
+
*
|
|
4
|
+
* Plan: cci-longterm-refactor v0.15.3
|
|
5
|
+
*
|
|
6
|
+
* Tracks actively-updated plugins, pre-stages their tarballs,
|
|
7
|
+
* and generates unified upgrade-all.mjs scripts.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-context-compression-improved/runtime/watchlist
|
|
10
|
+
*/
|
|
11
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
|
|
14
|
+
/** Default watchlist: plugins that benefit from pre-download + offline apply. */
|
|
15
|
+
export const DEFAULT_WATCHLIST: readonly string[] = [
|
|
16
|
+
'dsh-context-compression-improved',
|
|
17
|
+
'dsh-prime-memory',
|
|
18
|
+
'dsh-browser-cdp',
|
|
19
|
+
'dsh-thinking-levels',
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
export interface WatchlistEntry {
|
|
23
|
+
readonly pkgName: string
|
|
24
|
+
readonly currentVersion: string
|
|
25
|
+
readonly latestVersion?: string
|
|
26
|
+
readonly staged?: boolean
|
|
27
|
+
readonly dismissed?: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function watchlistPath(): string {
|
|
31
|
+
const dshHome = process.env.DSH_HOME ?? join(process.env.USERPROFILE || process.env.HOME || '', '.dsh')
|
|
32
|
+
return join(dshHome, '_staging', 'watchlist.json')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function loadWatchlist(): string[] {
|
|
36
|
+
const path = watchlistPath()
|
|
37
|
+
if (!existsSync(path)) return [...DEFAULT_WATCHLIST]
|
|
38
|
+
try { return JSON.parse(readFileSync(path, 'utf8')) as string[] } catch { return [...DEFAULT_WATCHLIST] }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function saveWatchlist(pkgs: string[]): void {
|
|
42
|
+
const path = watchlistPath()
|
|
43
|
+
const dir = join(path, '..')
|
|
44
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true })
|
|
45
|
+
writeFileSync(path, JSON.stringify(pkgs, null, 2), 'utf8')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Generate a batch upgrade script for all staged packages. */
|
|
49
|
+
export function generateUpgradeAllScript(entries: readonly WatchlistEntry[]): string {
|
|
50
|
+
const lines = [
|
|
51
|
+
'#!/usr/bin/env node',
|
|
52
|
+
`// CCI upgrade-all — generated ${new Date().toISOString()}`,
|
|
53
|
+
`// Packages: ${entries.length}`,
|
|
54
|
+
'import { execSync } from "node:child_process"',
|
|
55
|
+
'import { existsSync } from "node:fs"',
|
|
56
|
+
'import { join } from "node:path"',
|
|
57
|
+
'',
|
|
58
|
+
'const STAGING = join(process.env.DSH_HOME || join(process.env.USERPROFILE || process.env.HOME, ".dsh"), "_staging")',
|
|
59
|
+
'const PROFILE = process.argv[2] || process.env.DSH_PROFILE',
|
|
60
|
+
'if (!PROFILE) { console.error("Usage: node upgrade-all.mjs <profile-dir>"); process.exit(1) }',
|
|
61
|
+
'',
|
|
62
|
+
'const packages = [',
|
|
63
|
+
]
|
|
64
|
+
for (const e of entries) {
|
|
65
|
+
lines.push(` { name: "${e.pkgName}", version: "${e.latestVersion ?? e.currentVersion}" },`)
|
|
66
|
+
}
|
|
67
|
+
lines.push(
|
|
68
|
+
']',
|
|
69
|
+
'',
|
|
70
|
+
'let failed = false',
|
|
71
|
+
'for (const pkg of packages) {',
|
|
72
|
+
' const tgz = join(STAGING, `${pkg.name}-${pkg.version}.tgz`)',
|
|
73
|
+
' if (!existsSync(tgz)) { console.warn(`SKIP ${pkg.name}@${pkg.version} (not staged)`); continue }',
|
|
74
|
+
' console.log(`UPGRADING ${pkg.name}@${pkg.version}...`)',
|
|
75
|
+
' try {',
|
|
76
|
+
' execSync(`pnpm add "file:${"\\$"}{tgz}" --dir "${"\\$"}{PROFILE}" --registry https://registry.npmjs.org`, { stdio: "inherit" })',
|
|
77
|
+
' } catch { console.error(`FAILED: ${pkg.name}`); failed = true; break }',
|
|
78
|
+
'}',
|
|
79
|
+
'console.log(failed ? "Some upgrades failed." : "All upgrades complete. Restart DSH.")',
|
|
80
|
+
)
|
|
81
|
+
return lines.join('\n')
|
|
82
|
+
}
|
|
@@ -197,7 +197,7 @@ function chooseOff(): void {
|
|
|
197
197
|
describe('context compression profiles', () => {
|
|
198
198
|
it('exposes Custom after the established profiles', () => {
|
|
199
199
|
expect(COMPRESSION_PROFILES).toEqual([
|
|
200
|
-
'off', 'native', 'balanced', 'cache-strict', 'savings', 'adaptive', 'tokenpilot-inspired', 'ptc', 'custom',
|
|
200
|
+
'off', 'native', 'balanced', 'cache-strict', 'savings', 'adaptive', 'tokenpilot-inspired', 'ptc', 'flash-tuned', 'custom',
|
|
201
201
|
])
|
|
202
202
|
})
|
|
203
203
|
|
|
@@ -225,13 +225,13 @@ describe('context compression profiles', () => {
|
|
|
225
225
|
expect(screen.queryByRole('button', { name: /Context compression/ })).toBeNull()
|
|
226
226
|
})
|
|
227
227
|
|
|
228
|
-
it('keeps all
|
|
228
|
+
it('keeps all ten profiles selectable for a capable official or custom preset', () => {
|
|
229
229
|
mount(vi.fn(() => Promise.resolve()), true)
|
|
230
230
|
|
|
231
231
|
const button = screen.getByRole('button', { name: /Context compression/ })
|
|
232
232
|
expect((button as HTMLButtonElement).disabled).toBe(false)
|
|
233
233
|
fireEvent.click(button)
|
|
234
|
-
expect(screen.getAllByRole('menuitem')).toHaveLength(
|
|
234
|
+
expect(screen.getAllByRole('menuitem')).toHaveLength(10)
|
|
235
235
|
})
|
|
236
236
|
|
|
237
237
|
it.each([false, undefined])(
|
|
@@ -272,14 +272,14 @@ describe('context compression profiles', () => {
|
|
|
272
272
|
it('does not require a preset switch when capability refresh is delayed', async () => {
|
|
273
273
|
const { sessions } = mount(vi.fn(() => Promise.resolve()), true)
|
|
274
274
|
fireEvent.click(screen.getByRole('button', { name: /Context compression/ }))
|
|
275
|
-
expect(screen.getAllByRole('menuitem')).toHaveLength(
|
|
275
|
+
expect(screen.getAllByRole('menuitem')).toHaveLength(10)
|
|
276
276
|
|
|
277
277
|
sessions.update((draft) => {
|
|
278
278
|
const current = draft.byId.s1
|
|
279
279
|
if (current !== undefined) current.contextCompressionAvailable = false
|
|
280
280
|
})
|
|
281
281
|
|
|
282
|
-
await waitFor(() => { expect(screen.getAllByRole('menuitem')).toHaveLength(
|
|
282
|
+
await waitFor(() => { expect(screen.getAllByRole('menuitem')).toHaveLength(10) })
|
|
283
283
|
expect(screen.getByRole<HTMLButtonElement>('button', { name: /Context compression/ }).disabled).toBe(false)
|
|
284
284
|
})
|
|
285
285
|
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
} from '../../src/profiles.ts'
|
|
24
24
|
|
|
25
25
|
describe('behavior-lock: profile enumeration (v0.12.1 baseline)', () => {
|
|
26
|
-
it('locks the exact profile list and order', () => {
|
|
26
|
+
it('locks the exact profile list and order (v0.15.1: +flash-tuned)', () => {
|
|
27
27
|
expect(COMPRESSION_PROFILES).toEqual([
|
|
28
28
|
'off',
|
|
29
29
|
'native',
|
|
@@ -33,6 +33,7 @@ describe('behavior-lock: profile enumeration (v0.12.1 baseline)', () => {
|
|
|
33
33
|
'adaptive',
|
|
34
34
|
'tokenpilot-inspired',
|
|
35
35
|
'ptc',
|
|
36
|
+
'flash-tuned',
|
|
36
37
|
'custom',
|
|
37
38
|
] as const satisfies readonly CompressionProfile[])
|
|
38
39
|
})
|