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/README.en.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [English](./README.en.md) | [中文](./README.md)
4
4
 
5
5
  > **⚠️ Beta notice — not for production use**
6
- > This project (**v0.2.0**) is a work-in-progress beta. The [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) itself is also in **public beta**. **Do not use either in engineering / production environments** — expect breaking changes and rough edges.
6
+ > This project (**v0.2.2**) is a work-in-progress beta. The [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) itself is also in **public beta**. **Do not use either in engineering / production environments** — expect breaking changes and rough edges.
7
7
 
8
8
  <p align="center">
9
9
  <strong>Built with gratitude on top of these projects</strong> — please give them a ⭐:
@@ -88,19 +88,19 @@ That's it. Then add a composition row where a compaction backend is expected —
88
88
  modelContextLimit: 128000 # optional; omit to auto-detect the model's real window (fallback 128000)
89
89
  ```
90
90
 
91
- **(Optional) Custom prompt copy — `config.prompts`.** Every model-visible prompt (normal/emergency nudge opener, tier line, range table, the ACP system-prompt section, the four tool descriptions) ships with built-in copy that you can override per slot through the composition row's `config`. Templates support named placeholders (e.g. `{pct}` for nudges, `{surface}` for the range table) and are **validated at construction**: a misspelled placeholder fails engine startup (fail-fast) instead of leaking a literal `{pct}` into the model context:
91
+ **(Optional) Custom prompt copy — `config.prompts`.** Every model-visible prompt (normal/emergency nudge opener, context breakdown, growth line, batch tip, tier line, range table, the ACP system-prompt section, the four tool descriptions) defaults to **acp-kernel's own `renderNudgeText`** the efficiency note, context breakdown, compression rules, and batch tip all come from the kernel verbatim; only the range table is swapped for the surface-seq version (the kernel uses mNNNNN refs, and DSH has no `<acp>` tags). Overriding any nudge slot switches to template rendering. Templates support named placeholders (e.g. `{pct}` and `{philosophy}` for nudges, `{surface}` for the range table) and are **validated at construction**: a misspelled placeholder fails engine startup (fail-fast) instead of leaking a literal `{pct}` into the model context:
92
92
 
93
93
  ```yaml
94
94
  config:
95
95
  modelContextLimit: 128000
96
96
  prompts:
97
97
  nudge:
98
- normal: 'Context usage is at {pct}%. This is a suggestion, not a requirement — you decide.' # custom nudge opener
98
+ normal: 'This is an efficiency nudge to compress early and keep context lean.' # custom nudge opener
99
99
  tools:
100
100
  acpStatus: 'Report the ACP block ledger: compressed blocks, reclaimed tokens, and current context pressure.' # custom tool description
101
101
  ```
102
102
 
103
- See [docs/configurable-prompts-design.md](docs/configurable-prompts-design.md) for the full slot list, per-slot placeholders, and the empty-string/`null` semantics. Deployments that omit `prompts` behave exactly as before (default copy byte-identical).
103
+ See [docs/configurable-prompts-design.md](docs/configurable-prompts-design.md) for the full slot list, per-slot placeholders, and the empty-string/`null` semantics. Deployments that omit `prompts` use the kernel rendering directly (aligned with kernel/pi; see design doc v6).
104
104
 
105
105
  **Per-mode — an agent preset's `compaction` realm.** First *disable (or delete) the realm's existing `dsh-compaction-basic` row*, then mount this engine — two backends cannot coexist in the same realm:
106
106
 
@@ -126,14 +126,14 @@ DSH derives every model request from its append-only session log (the *surface*)
126
126
  |---|---|
127
127
  | `compress` tool shadows a range | durable `surfaceOp: { op: 'replace' }` — the model-written summary becomes a checkpoint node; the originals stay in the log |
128
128
  | refs (`m00001` tags) | surface seqs, carried by the nudge's compressible-range table |
129
- | nudge ("consider compressing") | injected at `agent/pre-step` by the kernel's pressure decision — a short advisory, never an order |
129
+ | nudge ("efficiency note — compress early and keep context lean") | injected at `agent/pre-step` by the kernel's pressure decision — efficiency note + context breakdown + compression rules, tone aligned with kernel/pi; never an order |
130
130
  | `decompress` | read-only recovery of shadowed originals from the log |
131
131
  | `search_context` | scores block summaries + originals rebuilt from the log |
132
132
  | `acp_status` | block ledger + context pressure |
133
133
  | block state | in-memory kernel state + **log-rebuilt ledger** (no sidecar files) |
134
134
  | tiered distillation (T2/T3) | re-compressing a block's summary node distills that block (tier 2); distilling a tier-2 block yields tier 3. Tier + kernel block ids are persisted to the log, so kernel state rehydrates from the log after a restart and stays distillable |
135
135
 
136
- The load-bearing compression guidance (tools, philosophy, summary rules) is registered as a one-time system-prompt section, so nudges stay short. There is deliberately **no automatic summarization**: automatic policy only nudges the model (`compactIfNeeded` returns null).
136
+ The load-bearing compression guidance (tools, philosophy, summary rules, tier rules) is registered as a one-time system-prompt section; each nudge carries a condensed version (efficiency note + philosophy + context breakdown + HOW_TO_COMPRESS_RULES + range table + batch tip). There is deliberately **no automatic summarization**: automatic policy only nudges the model (`compactIfNeeded` returns null).
137
137
 
138
138
  ## Video
139
139
 
@@ -202,6 +202,7 @@ src/
202
202
  ├── nudge.ts # M4: kernel pressure decision → injected advisory nudge
203
203
  ├── system-prompt.ts# M4: one-time ACP guidance section (keeps nudges short)
204
204
  ├── config.ts # kernel config assembly (thresholds + coreOverrides)
205
+ ├── window.ts # auto context-window detection (LLM runtime probe, fallback 128000)
205
206
  └── commands.ts # M4: /acp slash command
206
207
  ```
207
208
 
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [中文](./README.md) | [English](./README.en.md)
4
4
 
5
5
  > **⚠️ 测试版声明——请勿用于生产环境**
6
- > 本项目(**v0.2.0**)仍处于开发中的测试版。[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 本身也处于**公开测试版**阶段。**请勿将两者用于工程化 / 生产环境**——预期会有破坏性变更与粗糙之处。
6
+ > 本项目(**v0.2.2**)仍处于开发中的测试版。[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 本身也处于**公开测试版**阶段。**请勿将两者用于工程化 / 生产环境**——预期会有破坏性变更与粗糙之处。
7
7
 
8
8
  <p align="center">
9
9
  <strong>衷心感谢以下项目——请给它们一个 ⭐:</strong>
@@ -89,19 +89,19 @@ dsh plugin --profile web add billion-context-dsh
89
89
  modelContextLimit: 128000 # 可选;省略时自动探测模型真实窗口(回退 128000)
90
90
  ```
91
91
 
92
- **(可选)自定义提示词文案 —— `config.prompts`。** 所有模型可见的提示词(普通/紧急 nudge 首句、tier 蒸馏行、范围表、ACP system prompt 段、四个工具描述)默认是内置文案,可通过组合行的 `config` 按槽位覆盖。模板支持命名占位符(如 nudge 的 `{pct}`、范围表的 `{surface}`),**构造期校验**:占位符拼写错误会在引擎启动时抛错(fail-fast),而不是把字面 `{pct}` 漏进模型上下文:
92
+ **(可选)自定义提示词文案 —— `config.prompts`。** 所有模型可见的提示词(普通/紧急 nudge 首句、上下文分解、增长行、批量提示、tier 蒸馏行、范围表、ACP system prompt 段、四个工具描述)默认**直接复用 acp-kernel 的 `renderNudgeText`**——效率提示、上下文分解、压缩规则、批量提示全部来自 kernel 原文,仅范围表换成 surface-seq 版(kernel 用 mNNNNN 引用,我们架构没有 `<acp>` 标签)。覆盖任一 nudge 槽位后自动切换到模板渲染。模板支持命名占位符(如 nudge 的 `{pct}`、`{philosophy}`、范围表的 `{surface}`),**构造期校验**:占位符拼写错误会在引擎启动时抛错(fail-fast),而不是把字面 `{pct}` 漏进模型上下文:
93
93
 
94
94
  ```yaml
95
95
  config:
96
96
  modelContextLimit: 128000
97
97
  prompts:
98
98
  nudge:
99
- normal: '上下文使用率 {pct}%。这是建议而非命令——由你决定是否压缩。' # 中文 nudge 首句
99
+ normal: '上下文使用率 {pct}%。这是效率提示——请尽早压缩保持上下文精简。' # 中文 nudge 首句
100
100
  tools:
101
101
  acpStatus: '报告 ACP 块账本:压缩块数、回收 token、当前上下文压力。' # 自定义工具描述
102
102
  ```
103
103
 
104
- 可配置槽位清单、每槽可用占位符、空串/`null` 语义见 [docs/configurable-prompts-design.md](docs/configurable-prompts-design.md)。未配置 `prompts` 的部署行为与以往完全一致(默认文案逐字节不变)。
104
+ 可配置槽位清单、每槽可用占位符、空串/`null` 语义见 [docs/configurable-prompts-design.md](docs/configurable-prompts-design.md)。未配置 `prompts` 的部署直接使用 kernel 渲染(对齐 kernel/pi,见设计文档 v6)。
105
105
 
106
106
  **单模式生效(agent preset 的 `compaction` realm)**。先在该 realm 内*禁用(或删除)原有的 `dsh-compaction-basic` 行*,再插入本引擎——同一 realm 内两个后端不能并存:
107
107
 
@@ -127,14 +127,14 @@ DSH 的每个模型请求都派生自其 append-only 会话日志(*surface*)
127
127
  |---|---|
128
128
  | `compress` 工具遮蔽一段范围 | 持久化 `surfaceOp: { op: 'replace' }`——模型书写的摘要成为 checkpoint 节点;原文保留在日志中 |
129
129
  | refs(`m00001` 标签) | surface seq,由 nudge 的可压缩范围表携带 |
130
- | nudge("考虑压缩一下") | 由内核的压力决策在 `agent/pre-step` 注入——简短建议,绝非命令 |
130
+ | nudge("效率提示——尽早压缩保持精简") | 由内核的压力决策在 `agent/pre-step` 注入——效率通知 + 上下文分解 + 压缩规则,语气对齐 kernel/pi;绝非命令 |
131
131
  | `decompress` | 从日志只读恢复被遮蔽的原文 |
132
132
  | `search_context` | 对从日志重建的块摘要与原文打分 |
133
133
  | `acp_status` | 块账本与上下文压力 |
134
134
  | 块状态 | 内存内核状态 + **日志重建账本**(无旁车文件) |
135
135
  | 分层蒸馏(T2/T3) | 再次压缩某块的摘要节点 = 蒸馏该块(tier 2),蒸馏 tier-2 块得 tier 3;tier 与内核块 id 持久化进日志,重启后内核状态从日志再水合、可继续蒸馏 |
136
136
 
137
- 承载性的压缩指引(工具、哲学、摘要规则)注册为一次性系统提示段,因此 nudge 保持简短。刻意**不做自动摘要**:自动策略只 nudge 模型(`compactIfNeeded` 返回 null)。
137
+ 承载性的压缩指引(工具、哲学、摘要规则、tier 蒸馏/浓缩规则)注册为一次性系统提示段;每条 nudge 携带精简版(效率提示 + 哲学 + 上下文分解 + 压缩规则 + 范围表 + 批量提示)。刻意**不做自动摘要**:自动策略只 nudge 模型(`compactIfNeeded` 返回 null)。
138
138
 
139
139
  ## 视频讲解
140
140
 
@@ -203,6 +203,7 @@ src/
203
203
  ├── nudge.ts # M4: 内核压力决策 → 注入的建议式 nudge
204
204
  ├── system-prompt.ts# M4: 一次性 ACP 指引段(让 nudge 保持简短)
205
205
  ├── config.ts # 内核配置组装(阈值 + coreOverrides)
206
+ ├── window.ts # 自动上下文窗口探测(LLM 运行时探测,回退 128000)
206
207
  └── commands.ts # M4: /acp 斜杠命令
207
208
  ```
208
209
 
package/dist/index.d.ts CHANGED
@@ -40,7 +40,7 @@ export { makeTools, type ToolEnvironment } from './tools.ts';
40
40
  export { acpCommand } from './commands.ts';
41
41
  export { buildNudge, resolveTokenCount, type NudgeEnvironment, type NudgeOutcome } from './nudge.ts';
42
42
  export { DEFAULT_CONTEXT_WINDOW, detectContextWindow, windowSourceLabel, type AcpWindow, } from './window.ts';
43
- export { AlreadyCompressedRangeError, rebuildBlockLedger, resolveSurfaceRange, runCompactionTransaction, shadowedSeqsOf, findOpenTurn, assertNoActiveCompaction, blockRegistry, blockRefForSummarySeq, compactionIdsOfKernelBlocks, summarySeqOfKernelBlock, expandShadowedSeqs, type AcpBlockLedgerEntry, type CompactionTransactionInput, type ResolvedSurfaceRange, } from './region.ts';
43
+ export { AlreadyCompressedRangeError, rebuildBlockLedger, resolveSurfaceRange, runCompactionTransaction, shadowedSeqsOf, findOpenTurn, assertNoActiveCompaction, blockRegistry, blockRefForSummarySeq, compactionIdsOfKernelBlocks, summarySeqOfKernelBlock, expandShadowedSeqs, hideCompressToolPair, stripOrphanedSurfaceToolMessages, type AcpBlockLedgerEntry, type CompactionTransactionInput, type ResolvedSurfaceRange, } from './region.ts';
44
44
  export { eventsToCoreMessages, projectEvent, surfaceEventsOf, extractEventText } from './messages.ts';
45
45
  export interface AcpConfig {
46
46
  /**
@@ -108,6 +108,8 @@ export declare class AcpCompactionEngine extends CompactionEngine {
108
108
  /** Resolved prompt templates (validated at construction — fail-fast on template typos). */
109
109
  readonly prompts: ResolvedPrompts;
110
110
  private readonly lastNudgeTurn;
111
+ /** Successful compress call ids awaiting their tool/result so the pair can be hidden. */
112
+ private readonly compressCallIdsToHide;
111
113
  /** Per provider/model route the resolved window (probe failures cached too). */
112
114
  private readonly windowCache;
113
115
  constructor(ctx: Context, config?: Partial<AcpConfig>);