dsh-context-compression-improved 0.7.0-beta.1 → 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 -220
- package/CHANGELOG.ko.md +211 -214
- package/CHANGELOG.md +392 -376
- package/CHANGELOG.zh.md +196 -199
- package/README.md +97 -97
- package/README.zh.md +86 -86
- package/package.json +18 -17
- package/packages/selector/dsh.plugin.json +1 -1
- package/packages/selector/lib/client.js +733 -0
- package/packages/selector/lib/style.css +46 -46
- package/packages/selector/src/client/decode.ts +53 -53
- 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/preset-overlay.ts +629 -629
- package/packages/selector/src/profiles.ts +414 -414
- package/packages/selector/src/pruner/content.ts +198 -198
- package/packages/selector/src/pruner/state.ts +57 -57
- package/packages/selector/src/pruner.ts +2665 -2665
- package/packages/selector/src/runtime/audit.ts +303 -303
- package/packages/selector/src/runtime/config.ts +731 -731
- package/packages/selector/src/runtime/reducers.ts +1674 -1674
- package/packages/selector/src/runtime/summary-command.ts +133 -133
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -233
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -204
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -53
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -65
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -125
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -37
- package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +306 -306
- package/packages/selector/src/runtime/types.ts +358 -358
- package/packages/selector/tests/built/client-artifact.spec.ts +61 -61
- package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +203 -203
- 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 -62
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -156
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -154
- package/scripts/packed-components-smoke.mjs +734 -734
- package/tests/TEST_INVENTORY.md +41 -41
- package/tsconfig.tests.json +17 -17
- package/vitest.config.ts +57 -57
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `/ctx-summary off|on|status` — in-session temporary override for the
|
|
3
|
-
* turn-tail intent-summary gate.
|
|
4
|
-
*
|
|
5
|
-
* The override is session-scoped by design: settings are session-frozen
|
|
6
|
-
* (changes only affect newly observed sessions), so "temporarily disable and
|
|
7
|
-
* resume" can only be expressed as runtime state. Overrides die with the
|
|
8
|
-
* process and never leak across sessions. `off` wins over the settings gate;
|
|
9
|
-
* `on` never bypasses the numeric growth gates — it only lifts the
|
|
10
|
-
* settings/override veto.
|
|
11
|
-
*
|
|
12
|
-
* Registration mirrors the host's own `/compact` command: optional
|
|
13
|
-
* `commands`-service injection (a host without the registry simply never
|
|
14
|
-
* mounts the command), dynamic `CommandDefinitionId` brand import with a
|
|
15
|
-
* plain fallback so a stripped host cannot break plugin load.
|
|
16
|
-
*/
|
|
17
|
-
import type { Context } from '@deepseek-ai/cordis'
|
|
18
|
-
import {
|
|
19
|
-
getLastIntentFold,
|
|
20
|
-
getObservedIntentEnabled,
|
|
21
|
-
getSummaryOverride,
|
|
22
|
-
setSummaryOverride,
|
|
23
|
-
} from './tokenpilot/advisor-state.ts'
|
|
24
|
-
import { INTENT_GATE_FLOOR_FRACTION, INTENT_GATE_GROWTH_TOKENS } from './tokenpilot/intent-gate.ts'
|
|
25
|
-
|
|
26
|
-
export const SUMMARY_COMMAND_NAME = 'ctx-summary'
|
|
27
|
-
|
|
28
|
-
const USAGE = 'Usage: /ctx-summary off|on|status'
|
|
29
|
-
|
|
30
|
-
export type SummaryCommandArgs = 'off' | 'on' | 'status'
|
|
31
|
-
|
|
32
|
-
/** Parse the raw argument string; `undefined` = unrecognized (usage error). */
|
|
33
|
-
export function parseSummaryCommandArgs(rawInput: string): SummaryCommandArgs | undefined {
|
|
34
|
-
const token = rawInput.trim().toLowerCase()
|
|
35
|
-
if (token === 'off' || token === 'on' || token === 'status') return token
|
|
36
|
-
return undefined
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function describeFold(sessionId: string): string {
|
|
40
|
-
const fold = getLastIntentFold(sessionId)
|
|
41
|
-
if (fold === undefined) return 'none'
|
|
42
|
-
return `turn ${fold.turn}, seq ${fold.startSeq}..${fold.endSeq}`
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Human-facing status line; observability only, never a decision input. */
|
|
46
|
-
export function formatSummaryStatus(sessionId: string): string {
|
|
47
|
-
const override = getSummaryOverride(sessionId)
|
|
48
|
-
const enabled = getObservedIntentEnabled(sessionId)
|
|
49
|
-
const enabledText = enabled === undefined ? 'unknown (gate not evaluated yet)' : enabled ? 'yes' : 'no'
|
|
50
|
-
return [
|
|
51
|
-
`ctx-summary status:`,
|
|
52
|
-
` override: ${override ?? 'default (settings-driven)'}`,
|
|
53
|
-
` intentSummary enabled (settings): ${enabledText}`,
|
|
54
|
-
` gate: floor >${Math.round(INTENT_GATE_FLOOR_FRACTION * 100)}% of window AND growth >${INTENT_GATE_GROWTH_TOKENS} tokens since last fold`,
|
|
55
|
-
` last fold: ${describeFold(sessionId)}`,
|
|
56
|
-
].join('\n')
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Resolve the invoking agent's session id (`''` when the host exposes none). */
|
|
60
|
-
function sessionIdOf(agent: unknown): string {
|
|
61
|
-
const session = (agent as { session?: { id?: unknown } } | undefined)?.session
|
|
62
|
-
if (session === undefined || session.id === undefined || session.id === null) return ''
|
|
63
|
-
// Host session ids are strings in practice; String() keeps the legacy
|
|
64
|
-
// best-effort coercion for exotic host shapes.
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
66
|
-
return String(session.id)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
type CommandsServiceLike = {
|
|
70
|
-
register: (definition: {
|
|
71
|
-
definitionId?: unknown
|
|
72
|
-
name: string
|
|
73
|
-
description: string
|
|
74
|
-
handler: (invocation: { agent?: unknown, rawInput?: unknown }) => Promise<{ kind: 'success' | 'error', text: string }>
|
|
75
|
-
}) => unknown
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Best-effort `CommandDefinitionId` brand; `undefined` on stripped hosts (registered without it). */
|
|
79
|
-
async function loadCommandDefinitionId(): Promise<((id: string) => unknown) | undefined> {
|
|
80
|
-
try {
|
|
81
|
-
const mod = (await import('@deepseek-ai/dsh-commands')) as { CommandDefinitionId?: (id: string) => unknown }
|
|
82
|
-
return mod.CommandDefinitionId
|
|
83
|
-
} catch {
|
|
84
|
-
return undefined
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Mount `/ctx-summary` for every composed human-command adapter. Never
|
|
90
|
-
* throws: the command is a convenience surface, and a host without the
|
|
91
|
-
* commands service (or with an incompatible registry shape) simply runs
|
|
92
|
-
* without it.
|
|
93
|
-
*/
|
|
94
|
-
export function registerSummaryCommand(ctx: Context): void {
|
|
95
|
-
ctx.inject(['commands'], (injected) => {
|
|
96
|
-
const commands = (injected as { commands?: unknown }).commands as CommandsServiceLike | undefined
|
|
97
|
-
if (commands === undefined || typeof commands.register !== 'function') return
|
|
98
|
-
void (async () => {
|
|
99
|
-
try {
|
|
100
|
-
const definitionId = await loadCommandDefinitionId()
|
|
101
|
-
await commands.register({
|
|
102
|
-
name: SUMMARY_COMMAND_NAME,
|
|
103
|
-
description: 'Turn-tail intent summary: temporarily disable/resume or inspect status',
|
|
104
|
-
...(definitionId === undefined ? {} : { definitionId: definitionId('dsh-context-compression-improved/ctx-summary') }),
|
|
105
|
-
// The commands contract expects a promise-returning handler; the
|
|
106
|
-
// body is fully synchronous by design (all host reads are sync).
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
108
|
-
handler: async (invocation) => {
|
|
109
|
-
const rawInput = typeof invocation.rawInput === 'string' ? invocation.rawInput : ''
|
|
110
|
-
const args = parseSummaryCommandArgs(rawInput)
|
|
111
|
-
if (args === undefined) return { kind: 'error' as const, text: USAGE }
|
|
112
|
-
const sessionId = sessionIdOf(invocation.agent)
|
|
113
|
-
if (args === 'status') {
|
|
114
|
-
if (sessionId === '') return { kind: 'error' as const, text: 'ctx-summary: no session is attached to this invocation' }
|
|
115
|
-
return { kind: 'success' as const, text: formatSummaryStatus(sessionId) }
|
|
116
|
-
}
|
|
117
|
-
if (sessionId === '') return { kind: 'error' as const, text: 'ctx-summary: no session is attached to this invocation' }
|
|
118
|
-
setSummaryOverride(sessionId, args)
|
|
119
|
-
return {
|
|
120
|
-
kind: 'success' as const,
|
|
121
|
-
text: args === 'off'
|
|
122
|
-
? 'ctx-summary: turn-tail intent summary paused for this session (until process restart or `/ctx-summary on`)'
|
|
123
|
-
: 'ctx-summary: turn-tail intent summary resumed for this session (numeric gates still apply)',
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
})
|
|
127
|
-
} catch {
|
|
128
|
-
// Registry rejected the definition (shape drift, closed union): the
|
|
129
|
-
// plugin keeps working, only the convenience command is absent.
|
|
130
|
-
}
|
|
131
|
-
})()
|
|
132
|
-
})
|
|
133
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* `/ctx-summary off|on|status` — in-session temporary override for the
|
|
3
|
+
* turn-tail intent-summary gate.
|
|
4
|
+
*
|
|
5
|
+
* The override is session-scoped by design: settings are session-frozen
|
|
6
|
+
* (changes only affect newly observed sessions), so "temporarily disable and
|
|
7
|
+
* resume" can only be expressed as runtime state. Overrides die with the
|
|
8
|
+
* process and never leak across sessions. `off` wins over the settings gate;
|
|
9
|
+
* `on` never bypasses the numeric growth gates — it only lifts the
|
|
10
|
+
* settings/override veto.
|
|
11
|
+
*
|
|
12
|
+
* Registration mirrors the host's own `/compact` command: optional
|
|
13
|
+
* `commands`-service injection (a host without the registry simply never
|
|
14
|
+
* mounts the command), dynamic `CommandDefinitionId` brand import with a
|
|
15
|
+
* plain fallback so a stripped host cannot break plugin load.
|
|
16
|
+
*/
|
|
17
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
18
|
+
import {
|
|
19
|
+
getLastIntentFold,
|
|
20
|
+
getObservedIntentEnabled,
|
|
21
|
+
getSummaryOverride,
|
|
22
|
+
setSummaryOverride,
|
|
23
|
+
} from './tokenpilot/advisor-state.ts'
|
|
24
|
+
import { INTENT_GATE_FLOOR_FRACTION, INTENT_GATE_GROWTH_TOKENS } from './tokenpilot/intent-gate.ts'
|
|
25
|
+
|
|
26
|
+
export const SUMMARY_COMMAND_NAME = 'ctx-summary'
|
|
27
|
+
|
|
28
|
+
const USAGE = 'Usage: /ctx-summary off|on|status'
|
|
29
|
+
|
|
30
|
+
export type SummaryCommandArgs = 'off' | 'on' | 'status'
|
|
31
|
+
|
|
32
|
+
/** Parse the raw argument string; `undefined` = unrecognized (usage error). */
|
|
33
|
+
export function parseSummaryCommandArgs(rawInput: string): SummaryCommandArgs | undefined {
|
|
34
|
+
const token = rawInput.trim().toLowerCase()
|
|
35
|
+
if (token === 'off' || token === 'on' || token === 'status') return token
|
|
36
|
+
return undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function describeFold(sessionId: string): string {
|
|
40
|
+
const fold = getLastIntentFold(sessionId)
|
|
41
|
+
if (fold === undefined) return 'none'
|
|
42
|
+
return `turn ${fold.turn}, seq ${fold.startSeq}..${fold.endSeq}`
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Human-facing status line; observability only, never a decision input. */
|
|
46
|
+
export function formatSummaryStatus(sessionId: string): string {
|
|
47
|
+
const override = getSummaryOverride(sessionId)
|
|
48
|
+
const enabled = getObservedIntentEnabled(sessionId)
|
|
49
|
+
const enabledText = enabled === undefined ? 'unknown (gate not evaluated yet)' : enabled ? 'yes' : 'no'
|
|
50
|
+
return [
|
|
51
|
+
`ctx-summary status:`,
|
|
52
|
+
` override: ${override ?? 'default (settings-driven)'}`,
|
|
53
|
+
` intentSummary enabled (settings): ${enabledText}`,
|
|
54
|
+
` gate: floor >${Math.round(INTENT_GATE_FLOOR_FRACTION * 100)}% of window AND growth >${INTENT_GATE_GROWTH_TOKENS} tokens since last fold`,
|
|
55
|
+
` last fold: ${describeFold(sessionId)}`,
|
|
56
|
+
].join('\n')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Resolve the invoking agent's session id (`''` when the host exposes none). */
|
|
60
|
+
function sessionIdOf(agent: unknown): string {
|
|
61
|
+
const session = (agent as { session?: { id?: unknown } } | undefined)?.session
|
|
62
|
+
if (session === undefined || session.id === undefined || session.id === null) return ''
|
|
63
|
+
// Host session ids are strings in practice; String() keeps the legacy
|
|
64
|
+
// best-effort coercion for exotic host shapes.
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
66
|
+
return String(session.id)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type CommandsServiceLike = {
|
|
70
|
+
register: (definition: {
|
|
71
|
+
definitionId?: unknown
|
|
72
|
+
name: string
|
|
73
|
+
description: string
|
|
74
|
+
handler: (invocation: { agent?: unknown, rawInput?: unknown }) => Promise<{ kind: 'success' | 'error', text: string }>
|
|
75
|
+
}) => unknown
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Best-effort `CommandDefinitionId` brand; `undefined` on stripped hosts (registered without it). */
|
|
79
|
+
async function loadCommandDefinitionId(): Promise<((id: string) => unknown) | undefined> {
|
|
80
|
+
try {
|
|
81
|
+
const mod = (await import('@deepseek-ai/dsh-commands')) as { CommandDefinitionId?: (id: string) => unknown }
|
|
82
|
+
return mod.CommandDefinitionId
|
|
83
|
+
} catch {
|
|
84
|
+
return undefined
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Mount `/ctx-summary` for every composed human-command adapter. Never
|
|
90
|
+
* throws: the command is a convenience surface, and a host without the
|
|
91
|
+
* commands service (or with an incompatible registry shape) simply runs
|
|
92
|
+
* without it.
|
|
93
|
+
*/
|
|
94
|
+
export function registerSummaryCommand(ctx: Context): void {
|
|
95
|
+
ctx.inject(['commands'], (injected) => {
|
|
96
|
+
const commands = (injected as { commands?: unknown }).commands as CommandsServiceLike | undefined
|
|
97
|
+
if (commands === undefined || typeof commands.register !== 'function') return
|
|
98
|
+
void (async () => {
|
|
99
|
+
try {
|
|
100
|
+
const definitionId = await loadCommandDefinitionId()
|
|
101
|
+
await commands.register({
|
|
102
|
+
name: SUMMARY_COMMAND_NAME,
|
|
103
|
+
description: 'Turn-tail intent summary: temporarily disable/resume or inspect status',
|
|
104
|
+
...(definitionId === undefined ? {} : { definitionId: definitionId('dsh-context-compression-improved/ctx-summary') }),
|
|
105
|
+
// The commands contract expects a promise-returning handler; the
|
|
106
|
+
// body is fully synchronous by design (all host reads are sync).
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
108
|
+
handler: async (invocation) => {
|
|
109
|
+
const rawInput = typeof invocation.rawInput === 'string' ? invocation.rawInput : ''
|
|
110
|
+
const args = parseSummaryCommandArgs(rawInput)
|
|
111
|
+
if (args === undefined) return { kind: 'error' as const, text: USAGE }
|
|
112
|
+
const sessionId = sessionIdOf(invocation.agent)
|
|
113
|
+
if (args === 'status') {
|
|
114
|
+
if (sessionId === '') return { kind: 'error' as const, text: 'ctx-summary: no session is attached to this invocation' }
|
|
115
|
+
return { kind: 'success' as const, text: formatSummaryStatus(sessionId) }
|
|
116
|
+
}
|
|
117
|
+
if (sessionId === '') return { kind: 'error' as const, text: 'ctx-summary: no session is attached to this invocation' }
|
|
118
|
+
setSummaryOverride(sessionId, args)
|
|
119
|
+
return {
|
|
120
|
+
kind: 'success' as const,
|
|
121
|
+
text: args === 'off'
|
|
122
|
+
? 'ctx-summary: turn-tail intent summary paused for this session (until process restart or `/ctx-summary on`)'
|
|
123
|
+
: 'ctx-summary: turn-tail intent summary resumed for this session (numeric gates still apply)',
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
})
|
|
127
|
+
} catch {
|
|
128
|
+
// Registry rejected the definition (shape drift, closed union): the
|
|
129
|
+
// plugin keeps working, only the convenience command is absent.
|
|
130
|
+
}
|
|
131
|
+
})()
|
|
132
|
+
})
|
|
133
|
+
}
|