billion-context-dsh 0.2.0 → 0.2.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/dist/nudge.d.ts CHANGED
@@ -51,8 +51,16 @@ export declare function rangeTable(session: import('@deepseek-ai/dsh-session').S
51
51
  */
52
52
  export declare function buildNudge(agent: Agent, env: NudgeEnvironment, lastNudgeTurn: Map<string, number>): NudgeOutcome | null;
53
53
  /**
54
- * A short ADVISORY nudge ACP is model-driven, the model decides whether and
55
- * when to compress. Full guidance (tools, philosophy, summary rules) lives in
56
- * the system prompt once, not in every nudge.
54
+ * Render the nudge message text. DEFAULT (no `config.prompts.nudge` override)
55
+ * calls the kernel's own `renderNudgeText` EFFICIENCY_NOTE/EMERGENCY_HEADER,
56
+ * context breakdown, HOW_TO_COMPRESS_RULES, tier rules, and the batch tip all
57
+ * come from acp-kernel verbatim (the kernel-alignment principle). Only the
58
+ * ref-ID-oriented segments are replaced with our seq-based equivalents,
59
+ * because DSH has no `<acp>` ref tags — see docs/dsh-porting-verification.md:
60
+ * - `rangesStr` (mNNNNN refs) → the surface-seq range table;
61
+ * - the emergency JSON example (startId/endId) → a seq example;
62
+ * - the tier trigger block (block ids bN) → our tier line with surface seqs.
63
+ * When a host overrides any `prompts.nudge` slot, the template path is used so
64
+ * `config.prompts` keeps full control (custom copy wins over kernel defaults).
57
65
  */
58
66
  export declare function buildNudgeText(nudge: NudgeDecision, emergency: boolean, session: import('@deepseek-ai/dsh-session').Session, prompts?: ResolvedPrompts): string;
package/dist/prompts.d.ts CHANGED
@@ -22,14 +22,20 @@ export type PromptOverride<T> = {
22
22
  [K in keyof T]?: PromptInput;
23
23
  };
24
24
  export interface NudgePrompts {
25
- /** 普通档首句。占位符:{pct} */
25
+ /** 普通档首句。占位符:{pct} {philosophy} */
26
26
  normal: string;
27
- /** 紧急档首句。占位符:{pct} */
27
+ /** 紧急档首句。占位符:{pct} {philosophy} */
28
28
  emergency: string;
29
- /** 指导行。无占位符 */
29
+ /** 指导行(HOW_TO_COMPRESS_RULES)。无占位符 */
30
30
  guidance: string;
31
31
  /** tier 蒸馏行。占位符:{tier} {count} {prevTier} {tokens} {seqs} */
32
32
  tier: string;
33
+ /** 上下文分解。占位符:{system} {tool} {summaries} {code} {text} */
34
+ breakdown: string;
35
+ /** 增长行。占位符:{growth} */
36
+ growth: string;
37
+ /** 溢出提示。无占位符 */
38
+ tip: string;
33
39
  }
34
40
  export interface RangeTablePrompts {
35
41
  /** 表头。占位符:{surface} */
@@ -74,7 +80,7 @@ export declare function renderTemplate(template: string, vars: Record<string, st
74
80
  * 未传入时返回 DEFAULT_RESOLVED,零校验重跑。
75
81
  */
76
82
  export declare function resolvePrompts(input?: AcpPrompts): ResolvedPrompts;
77
- /** 渲染 system prompt 模板(注入 kernel 压缩哲学)。 */
83
+ /** 渲染 system prompt 模板(注入 kernel 压缩哲学、压缩规则、蒸馏规则)。 */
78
84
  export declare function renderSystemPrompt(prompts: ResolvedPrompts): string;
79
85
  /**
80
86
  * 默认模板 —— 与 v4 之前的硬编码文案逐字节一致
package/dist/region.d.ts CHANGED
@@ -143,6 +143,50 @@ export interface SeqCompressibleRange {
143
143
  readonly count: number;
144
144
  readonly tokens: number;
145
145
  }
146
+ /**
147
+ * Hide one successful `compress` tool's call/result pair after its tool/result
148
+ * has been logged. The durable compaction summary is inserted BEFORE the
149
+ * current tool result (the compress tool runs mid-turn), so leaving the pair on
150
+ * the surface would produce `assistant(tool_calls) → user(summary) →
151
+ * tool(result)` — rejected by strict providers. Replacing both nodes with a
152
+ * plain user message (the result text) removes the pair from the derived
153
+ * surface without touching the compaction block.
154
+ */
155
+ export declare function hideCompressToolPair(session: Session, callId: string, resultSeq?: number): boolean;
156
+ /**
157
+ * Surface-level orphan cleanup: hide tool/result nodes with no matching call,
158
+ * assistant tool-call nodes whose calls all lack results, and "broken pairs"
159
+ * whose result is NOT adjacent to the call node on the surface (a
160
+ * non-tool/result node — typically the compaction summary a buggy older
161
+ * version inserted between a compress call and its result — sits between
162
+ * them). A single orphan result corrupts the whole tool-pairing balance cache
163
+ * (every range resolve throws), orphan calls fragment large ranges into tiny
164
+ * uncompressed fragments, and a broken pair cannot serialize for strict
165
+ * providers — the mechanisms behind issue #18's "only ~28 tokens visible".
166
+ * Uses the same durable prune protocol as `hideSurfaceSeqs`, so the removed
167
+ * nodes stay recoverable from the append-only log.
168
+ */
169
+ export declare function stripOrphanedSurfaceToolMessages(session: Session, inFlightCallIds?: ReadonlySet<string>): number;
170
+ /**
171
+ * All tool-call ids currently visible on the surface with no matching
172
+ * tool/result yet — the in-flight calls of the current step. Sibling tools
173
+ * called in the same assistant message as `compress` are in-flight too, so
174
+ * `handleCompress` must protect the whole set (not just its own call id) or
175
+ * the sibling call would be pruned as an orphan and its result would land
176
+ * orphaned (HTTP 400 until the next cleanup).
177
+ */
178
+ export declare function openToolCallIds(session: Session): Set<string>;
179
+ /**
180
+ * Schedule `hideCompressToolPair` on the microtask queue. `session.append`
181
+ * is NOT reentrant: running it synchronously inside a `session/event`
182
+ * listener (while the outer append is still publishing) throws "session
183
+ * append cannot reenter while another append is being published" on live,
184
+ * store-attached sessions, and the dispatcher silently swallows the error —
185
+ * so a synchronous hide is a silent no-op in production. A microtask drains
186
+ * after the current append fully publishes and before the agent loop resumes,
187
+ * so the pair is hidden before the next request is built.
188
+ */
189
+ export declare function deferCompressPairHide(session: Session, callId: string, resultSeq: number, onError?: (error: unknown) => void): void;
146
190
  /**
147
191
  * Compute compressible spans directly from the surface — independent of the
148
192
  * kernel's ref map, which can drift after surface replacements in long
@@ -3,11 +3,11 @@
3
3
  * ACP_SYSTEM_PROMPT): the load-bearing compression guidance lives here, ONCE,
4
4
  * instead of being re-sent with every nudge. The nudge itself stays a short,
5
5
  * advisory notice — ACP is model-driven, the model decides whether and when
6
- * to compress (never "compress now").
6
+ * to compress.
7
7
  *
8
8
  * The text is DEFAULT_PROMPTS.systemPromptTemplate rendered with the kernel's
9
- * COMPRESS_PHILOSOPHY; hosts can override the whole section via
10
- * `config.prompts.systemPrompt` (see docs/configurable-prompts-design.md).
9
+ * COMPRESS_PHILOSOPHY and HOW_TO_COMPRESS_RULES; hosts can override the whole
10
+ * section via `config.prompts.systemPrompt` (see docs/configurable-prompts-design.md).
11
11
  * @module billion-context-dsh/system-prompt
12
12
  */
13
13
  export declare const ACP_SYSTEM_PROMPT: string;
package/dist/tools.d.ts CHANGED
@@ -23,6 +23,13 @@ export interface ToolEnvironment extends KernelConfigInput {
23
23
  readonly windowFor?: (agent: Agent) => Promise<AcpWindow>;
24
24
  /** Resolved prompt templates (optional: falls back to DEFAULT_RESOLVED). */
25
25
  readonly prompts?: ResolvedPrompts;
26
+ /**
27
+ * Call ids of compress invocations that created a durable block. The engine
28
+ * listens for the matching `tool/result` and hides the call/result pair from
29
+ * the surface, preventing the compaction summary from sitting between them
30
+ * (strict providers reject that sequence with HTTP 400).
31
+ */
32
+ readonly compressCallIdsToHide?: Set<string>;
26
33
  }
27
34
  /** Build the four ACP model tools bound to one engine. */
28
35
  export declare function makeTools(env: ToolEnvironment): ToolDefinition[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "billion-context-dsh",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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",