billion-context-dsh 0.2.24 → 0.2.26

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.
@@ -12,6 +12,16 @@
12
12
  */
13
13
  import type { CoreMessage } from 'acp-kernel';
14
14
  import type { Session, SessionEvent } from '@deepseek-ai/dsh-session';
15
+ declare module '@deepseek-ai/dsh-llm/message' {
16
+ interface MessageSourceMap {
17
+ acpNudge: {
18
+ kind: 'plugin:acp-nudge';
19
+ };
20
+ acpPrune: {
21
+ kind: 'plugin:billion-context-dsh';
22
+ };
23
+ }
24
+ }
15
25
  /**
16
26
  * Extract plain text from a DSH content block array or string.
17
27
  *
@@ -89,6 +99,21 @@ export declare function buildToolCallIndex(events: readonly SessionEvent[]): Rea
89
99
  */
90
100
  export declare const SUMMARY_FRAME_PREFIX = "[Model-written summary \u2014 not user words; re-verify any obligations before relying on them]";
91
101
  export declare function withSummaryFramePrefix(text: string): string;
102
+ /**
103
+ * The lead-in of a summary the ENGINE writes itself — today only the
104
+ * context-overflow emergency marker (src/index.ts `compactForOverflow`).
105
+ * Recognition is by content, not by caller: the writer and both framing sites
106
+ * share this ONE literal.
107
+ */
108
+ export declare const ENGINE_SUMMARY_LEAD = "[engine-written summary \u2014 context-overflow emergency compaction";
109
+ export declare function isEngineWrittenSummary(text: string): boolean;
110
+ /**
111
+ * The block summary the automatic overflow recovery writes. It is the engine's
112
+ * own note — not model-written text, not user words — saying which range was
113
+ * hidden to get the request under the window and where the originals still
114
+ * live (the append-only log: search_context/decompress rebuild from it).
115
+ */
116
+ export declare function overflowMarkerSummary(hiddenCount: number): string;
92
117
  export declare function projectEvent(event: SessionEvent, toolNames?: ReadonlyMap<string, string>): CoreMessage[];
93
118
  /** Project a session's message events into CoreMessage[] in log order. */
94
119
  export declare function eventsToCoreMessages(events: readonly SessionEvent[], toolNames?: ReadonlyMap<string, string>): CoreMessage[];
@@ -131,40 +156,85 @@ export declare function mediaBlocksOfEvent(event: SessionEvent): readonly unknow
131
156
  * Whether a surface user message is a compaction checkpoint node (already
132
157
  * compressed). Defined here (not in region.ts) so the classifier below and
133
158
  * region.ts share ONE implementation.
159
+ *
160
+ * Recognizes BOTH host shapes (issue #168): the ≤0.1.6 wrapper
161
+ * `{ kind: 'plugin', plugin: 'compact', compactionId }` and the 0.1.7+
162
+ * producer-owned kind `{ kind: 'compact-checkpoint', compactionId }` written
163
+ * by dsh-compaction's `compactCheckpointSource()` (verified against the
164
+ * published 0.1.7-alpha.1 artifact: the marker object is exactly
165
+ * `{ kind: 'compact-checkpoint' }` plus `compactionId` and an optional
166
+ * `sourceCommandId`). The 0.1.7 V3→V4 migration rewrites pre-0.1.7 sessions
167
+ * to the new shape, so both shapes coexist on one surface and both must be
168
+ * recognized — a row that misses this predicate classifies as `real`, which
169
+ * double-counts its summary text in acp_status, can steal the protected-tail
170
+ * window, and hides it from every distillation entry point below.
134
171
  */
135
172
  export declare function isCheckpointNode(event: SessionEvent): boolean;
173
+ /**
174
+ * The durable compaction id stamped on a checkpoint summary node, reading BOTH
175
+ * host shapes (see {@link isCheckpointNode}). Returns null when the event is
176
+ * not a checkpoint node or carries no id — a malformed row still CLASSIFIES
177
+ * as a checkpoint (it must never read as real content) but has no block to
178
+ * link to. Single shared extractor for the ledger index (`summarySeqIndex`),
179
+ * the distill-edge resolver (`blockRefForSummarySeq`) and the decompress
180
+ * recursion (`checkpointBlockIdOf`) — those sites must not re-derive the shape
181
+ * check themselves (issue #168).
182
+ */
183
+ export declare function checkpointCompactionIdOf(event: SessionEvent): string | null;
136
184
  /**
137
185
  * Injection/authoring classification of one surface event — the ONE shared
138
186
  * classifier for range scanning and the protected-tail scan (never ad-hoc
139
187
  * predicates that drift apart).
140
188
  *
141
189
  * - `real` — genuine conversation content (user turns without an injected
142
- * source, assistant prose/tool-calls, tool results, sub-agent relay rows).
143
- * This is the only class that may win "last real user message" protection
144
- * (minus relay rows, see `isRealUserTurn`).
190
+ * source, assistant prose/tool-calls, tool results, sub-agent relay rows,
191
+ * and host content channels in BOTH spellings: legacy plugin names and the
192
+ * DSH >= 0.1.7 direct-kind renames, issue #169). This is the only class
193
+ * that may win "last real user message" protection (minus all non-user
194
+ * rows, see `isRealUserTurn`).
145
195
  * - `metadata` — the engine's own ephemeral rows: nudge echoes and
146
196
  * compress-pair replacement stubs. Their content is derived from
147
197
  * already-visible messages, so folding them into an adjacent real segment
148
198
  * is zero-loss — this preserves main's behavior for engine-authored rows.
149
- * - `checkpoint` — compaction summary nodes (`plugin: 'compact'`).
199
+ * - `checkpoint` — compaction summary nodes (both host shapes, see
200
+ * `isCheckpointNode`: legacy `plugin: 'compact'` and 0.1.7+
201
+ * `kind: 'compact-checkpoint'`, issue #168).
150
202
  * Distillation is an explicit act; never folded into any segment.
151
203
  * - `instruction` — host-authored policy/instructions: AGENTS.md injections
152
- * (both host shapes), skill catalogs, and ANY unknown `kind:'plugin'` row.
153
- * Folding these is unsafe (the model would lose live policy text, and the
154
- * host re-injects the current AGENTS.md copy when it disappears — the
155
- * compress → re-inject loop this PR fixes). Unknown plugin names fall here
156
- * deliberately: a future host injection must never silently become
157
- * compressible content.
204
+ * (both host shapes), skill catalogs, host compaction summary rows
205
+ * (`compact-basic`, issue #169), and ANY unknown `kind:'plugin'` row or
206
+ * unaudited direct kind. Folding these is unsafe (the model would lose
207
+ * live policy text, and the host re-injects the current AGENTS.md copy
208
+ * when it disappears — the compress → re-inject loop this PR fixes).
209
+ * Unknown channel names fall here deliberately in BOTH namespaces: a
210
+ * future host injection must never silently become compressible content.
158
211
  */
159
212
  export type SurfaceEventClass = 'real' | 'metadata' | 'checkpoint' | 'instruction';
160
213
  /** Plugin names the engine itself authors — safe to fold into real segments. */
161
214
  export declare const METADATA_PLUGINS: ReadonlySet<string>;
162
215
  /**
163
- * True for AGENTS.md instruction rows in BOTH host shapes: the hook shape
164
- * (`kind:'agent-instructions'`, form 'instructions') and the baseline shape
165
- * (`kind:'plugin'` + plugin 'agent-instructions'). Shared by the newest-row
166
- * scan and the range scanner so protection and folding always agree on what
167
- * counts as an AGENTS.md row.
216
+ * Resolve the owning plugin name from either durable source shape: the legacy
217
+ * V3 wrapper `{ kind: 'plugin', plugin: '<name>' }` or the V4 producer kind
218
+ * `'plugin:<name>'`. DSH 0.1.7's V3→V4 migration rewrites every unregistered
219
+ * plugin row into the latter on file open, so both shapes coexist on a live
220
+ * surface until a session has been fully rewritten (issue #163). Returns
221
+ * undefined when neither shape is present, or when the name is missing,
222
+ * non-string, or empty — callers then keep their conservative fallback.
223
+ */
224
+ export declare function sourcePluginOf(source: {
225
+ kind?: unknown;
226
+ plugin?: unknown;
227
+ } | undefined): string | undefined;
228
+ /**
229
+ * True for AGENTS.md instruction rows in ALL host shapes: the hook shape
230
+ * (`kind:'agent-instructions'`, form 'instructions'), the legacy V3 wrapper
231
+ * (`kind:'plugin'` + plugin 'agent-instructions'), and the V4 producer kind
232
+ * (`kind:'plugin:agent-instructions'`) that DSH 0.1.7's migration rewrites
233
+ * legacy rows into on file open (issue #163) — a migrated session must keep
234
+ * its newest-row pin, or the current copy becomes foldable and the
235
+ * compress → re-inject loop returns. Shared by the newest-row scan and the
236
+ * range scanner so protection and folding always agree on what counts as an
237
+ * AGENTS.md row.
168
238
  */
169
239
  export declare function isAgentInstructionsRow(event: SessionEvent): boolean;
170
240
  export declare function classifySurfaceEvent(event: SessionEvent): SurfaceEventClass;
package/dist/nudge.d.ts CHANGED
@@ -38,6 +38,14 @@ export interface NudgeOutcome {
38
38
  * minimal hosts that lack the token-meter service.
39
39
  */
40
40
  export declare function resolveTokenCount(agent: Agent, coreMessages: CoreMessage[]): number;
41
+ /**
42
+ * Lazy per-seq media price. The FIRST lookup triggers one meter measurement, so
43
+ * the range walk only asks about seqs that really carry an attachment — a
44
+ * media-free session never pays for the measurement (issue #117, issue #110).
45
+ * Exported for the context-overflow recovery path, which ranks ranges with the
46
+ * same vocabulary as the nudge table.
47
+ */
48
+ export declare function meterMediaPriceResolver(agent: Agent, session: import('@deepseek-ai/dsh-session').Session): MediaPriceOf;
41
49
  /**
42
50
  * Render the compressible-range table as seq refs for the model.
43
51
  *
@@ -70,7 +78,7 @@ export declare function rangeTable(session: import('@deepseek-ai/dsh-session').S
70
78
  * source marker). We instead count active-block summaries directly from kernel
71
79
  * state (same source `buildStatusReport` uses), and the caller must exclude
72
80
  * checkpoint summary nodes from `messages` (they are not in any block's
73
- * `effectiveMessageIds` and would double-count — mirror of `/acp` status's
81
+ * `effectiveMessageIds` and would double-count — mirror of `/acp-prune` status's
74
82
  * `isCheckpointNode` exclusion).
75
83
  */
76
84
  export declare function computeSurfaceBreakdown(state: CompressionState, messages: readonly CoreMessage[], total: number, growth: number): ContextBreakdown;
package/dist/presets.d.ts CHANGED
@@ -18,7 +18,7 @@
18
18
  *
19
19
  * Presets are set at composition time (`config: { preset: 'efficient' }`).
20
20
  * Runtime hot-reload of the underlying keys rides on issue #75 Phase 1
21
- * (`settings.yaml` + `/acp config`); surfacing the `preset` alias through that
21
+ * (`settings.yaml` + `/acp-prune config`); surfacing the `preset` alias through that
22
22
  * same channel is the small follow-up once Phase 1 lands. The two knobs named in
23
23
  * the original request that are NOT first-class engine knobs today — `growthRatio`
24
24
  * (exists in acp-kernel as `nudge.growthRatio`, reachable via `coreOverrides`) and
package/dist/region.d.ts CHANGED
@@ -257,7 +257,7 @@ export declare function newestInstructionSeqsOf(session: Session): Set<number>;
257
257
  * agent-instructions row of every scope, restricted to rows still visible on
258
258
  * the surface (one definition of "current" — `newestInstructionSeqsOf`).
259
259
  * `buildCompressibleSeqRanges` never OFFERS them, and both compress entry
260
- * points (`handleCompress` in src/tools.ts, `/acp compress` in
260
+ * points (`handleCompress` in src/tools.ts, `/acp-prune compress` in
261
261
  * src/commands.ts) probe the RESOLVED span against this set and HARD-REJECT a
262
262
  * covering range before the kernel applies it, so nothing durable lands and no
263
263
  * phantom block can exist. This supersedes the earlier F7 draft (warn only):
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Layering (per key): schemastery schema default → composition-row subset
9
9
  * (the `base` layer, filtered by `filterSettingsEntry`) → user section.
10
- * The `/acp config` slash command reads and writes the same namespace
10
+ * The `/acp-prune config` slash command reads and writes the same namespace
11
11
  * through the `SettingsCommandSurface` built here.
12
12
  *
13
13
  * Deliberately NOT exposed through settings: `coreOverrides`, `countTokens`,
@@ -27,7 +27,7 @@ import type { SettingsDescriptor, SettingsProvider } from '@deepseek-ai/dsh-sett
27
27
  * (`installSection`'s `Namespace & SettingsNamespaceInput<Namespace>`).
28
28
  */
29
29
  export declare const ACP_SETTINGS_NAMESPACE = "compaction-acp";
30
- /** The six knobs exposed to the runtime settings layer. Order defines /acp config listing order. */
30
+ /** The six knobs exposed to the runtime settings layer. Order defines /acp-prune config listing order. */
31
31
  export declare const SETTINGS_KEYS: readonly ['modelContextLimit', 'autoModelContextLimit', 'nudgeMinContextLimitPct', 'nudgeMaxContextLimitPct', 'nudgeEmergencyThresholdPct', 'autoNudge'];
32
32
  export type SettingsKey = (typeof SETTINGS_KEYS)[number];
33
33
  /** Resolved shape of one settings snapshot — what every consumer read returns. */
@@ -116,7 +116,7 @@ export interface SettingsChangeEffect {
116
116
  }
117
117
  /** Pure diff used by the engine's change handler (unit-testable without a context). */
118
118
  export declare function describeSettingsChange(prev: AcpSettings, next: AcpSettings): SettingsChangeEffect;
119
- /** Result of parsing a `/acp config set` value. `null` means "reset this key". */
119
+ /** Result of parsing a `/acp-prune config set` value. `null` means "reset this key". */
120
120
  export type ParsedSettingValue = {
121
121
  ok: true;
122
122
  value: number | boolean | null;
@@ -125,7 +125,7 @@ export type ParsedSettingValue = {
125
125
  reason: string;
126
126
  };
127
127
  /**
128
- * Four-step value parser for `/acp config set` — deliberately NOT bare
128
+ * Four-step value parser for `/acp-prune config set` — deliberately NOT bare
129
129
  * JSON.parse, which rejects the most common human inputs (`.7` throws a
130
130
  * SyntaxError and the raw string would then fail schema validation; `null`
131
131
  * would silently mean "unset" only by convention). Order:
@@ -135,7 +135,7 @@ export type ParsedSettingValue = {
135
135
  * 4. otherwise rejected with guidance.
136
136
  */
137
137
  export declare function parseSettingValue(raw: string): ParsedSettingValue;
138
- /** Everything `/acp config` needs from the engine. Fakes in tests implement this directly. */
138
+ /** Everything `/acp-prune config` needs from the engine. Fakes in tests implement this directly. */
139
139
  export interface SettingsCommandSurface {
140
140
  /** False in processes without a settings provider (plain npm-install compositions): the command degrades to advice instead of failing. */
141
141
  readonly available: boolean;
package/dist/tools.d.ts CHANGED
@@ -22,7 +22,7 @@ import type { PresetName } from './presets.ts';
22
22
  export interface ToolEnvironment extends KernelConfigInput {
23
23
  readonly kernel: CompressionCore;
24
24
  readonly store: AcpStateStore;
25
- /** Display-only: the named preset that produced the nudge thresholds above, if any (`/acp status` names it). Never read by the kernel path. */
25
+ /** Display-only: the named preset that produced the nudge thresholds above, if any (`/acp-prune status` names it). Never read by the kernel path. */
26
26
  readonly preset?: PresetName;
27
27
  /** Resolve the effective context window for an agent (optional: status falls back to modelContextLimit). */
28
28
  readonly windowFor?: (agent: Agent) => Promise<AcpWindow>;
@@ -36,7 +36,7 @@ export interface ToolEnvironment extends KernelConfigInput {
36
36
  */
37
37
  readonly compressCallIdsToHide?: Set<string>;
38
38
  /**
39
- * Read/write access to the runtime settings layer for `/acp config`.
39
+ * Read/write access to the runtime settings layer for `/acp-prune config`.
40
40
  * Absent surfaces (never expected — the engine always builds one) would
41
41
  * degrade the command to advice text.
42
42
  */
@@ -46,7 +46,7 @@ export interface ToolEnvironment extends KernelConfigInput {
46
46
  * Resolve the effective context window for a tool or command run: probe the
47
47
  * agent's real window via `windowFor` when provided, otherwise fall back to
48
48
  * the environment's `modelContextLimit`. Shared by the compress and
49
- * acp_status tool handlers and the `/acp` command so the resolution logic
49
+ * acp_status tool handlers and the `/acp-prune` command so the resolution logic
50
50
  * lives in exactly one place (issue #63 — the tools used the 128K fallback
51
51
  * for pressure decisions even when auto-detection had found a larger window).
52
52
  */
package/dist/window.d.ts CHANGED
@@ -55,7 +55,7 @@ export interface AcpWindow {
55
55
  */
56
56
  readonly outputReserved?: number;
57
57
  }
58
- /** Human label for an AcpWindow's source (used by /acp status). */
58
+ /** Human label for an AcpWindow's source (used by /acp-prune status). */
59
59
  export declare function windowSourceLabel(window: AcpWindow): string;
60
60
  /**
61
61
  * Read the live context window from the host session projection
@@ -87,7 +87,7 @@ export declare function liveRoute(agent: Agent): {
87
87
  * resolved against, in ONE place: the session's live `request/context` route,
88
88
  * falling back to `agent.options` only before the session has recorded any
89
89
  * route. `windowFor` (src/index.ts), the `compress` tool (src/tools.ts) and
90
- * `/acp compress` (src/commands.ts) all need this exact pair; three hand-copied
90
+ * `/acp-prune compress` (src/commands.ts) all need this exact pair; three hand-copied
91
91
  * copies is precisely how a stale-route bug gets fixed in one call site and
92
92
  * left behind in the others.
93
93
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "billion-context-dsh",
3
- "version": "0.2.24",
3
+ "version": "0.2.26",
4
4
  "description": "Active Context Pruning (ACP) for the DeepSeek Harness — model-driven context management as a CompactionEngine backend.",
5
5
  "keywords": [
6
6
  "deepseek",