billion-context-dsh 0.1.0
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/LICENSE +21 -0
- package/README.md +113 -0
- package/README.zh-CN.md +116 -0
- package/dist/commands.d.ts +9 -0
- package/dist/config.d.ts +30 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +724 -0
- package/dist/index.js.map +1 -0
- package/dist/messages.d.ts +38 -0
- package/dist/nudge.d.ts +29 -0
- package/dist/region.d.ts +61 -0
- package/dist/state.d.ts +20 -0
- package/dist/system-prompt.d.ts +11 -0
- package/dist/tools.d.ts +21 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 billion-context-dsh contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# billion-context-dsh
|
|
2
|
+
|
|
3
|
+
**One billion, not one million.** [Active Context Pruning (ACP)](https://github.com/ranxianglei/acp-kernel) for the [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) — model-driven context management as a `CompactionEngine` backend.
|
|
4
|
+
|
|
5
|
+
The model decides *when* and *what* to compress — not a hard limit. Long conversations stay lean while critical details (paths, decisions, errors) survive in high-fidelity summaries you can search and decompress.
|
|
6
|
+
|
|
7
|
+
This is the DSH port of [billion-context-pi](https://github.com/ranxianglei/billion-context-pi) (the Pi coding-agent adapter). The compression kernel (`acp-kernel`) is reused verbatim; the adapter layer was rewritten against DSH's durable-surface model — see [docs/dsh-porting-verification.md](docs/dsh-porting-verification.md) for the verified mapping.
|
|
8
|
+
|
|
9
|
+
## Upstream & credits
|
|
10
|
+
|
|
11
|
+
This project is a **port/derivation** and stands on the shoulders of the following upstream work — all MIT licensed. **Thank you** to [ranxianglei](https://github.com/ranxianglei) and the DeepSeek Harness team for building these projects and making them open source:
|
|
12
|
+
|
|
13
|
+
| Upstream | Author | Role |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| **[billion-context-pi](https://github.com/ranxianglei/billion-context-pi)** | [ranxianglei](https://github.com/ranxianglei) | The Pi coding-agent adapter this project ports to DeepSeek Harness; source of the adapter design, tool semantics, and this project's default configuration |
|
|
16
|
+
| **[acp-kernel](https://github.com/ranxianglei/acp-kernel)** | [ranxianglei](https://github.com/ranxianglei) | Framework-agnostic context-compression engine — reused **verbatim** (refs, blocks, tiers, nudge decisions, search, status) |
|
|
17
|
+
| **[opencode-acp](https://github.com/ranxianglei/opencode-acp)** | [ranxianglei](https://github.com/ranxianglei) | Origin of the ACP ("model decides when and what to compress") design |
|
|
18
|
+
| **[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)** | DeepSeek AI | The host platform this project extends (compaction capability seam, agent presets, durable session log) |
|
|
19
|
+
|
|
20
|
+
This project reuses `acp-kernel`'s compression core and `billion-context-pi`'s default behavior unchanged; the DSH adapter layer (session-event projection, durable surface transaction, model tools, nudge, config) is original work in this repository. Upstream copyright and licenses remain with their respective authors; see [LICENSE](LICENSE) for this project's terms.
|
|
21
|
+
|
|
22
|
+
## How it works
|
|
23
|
+
|
|
24
|
+
DSH derives every model request from its append-only session log (the *surface*). ACP semantics map onto that model directly:
|
|
25
|
+
|
|
26
|
+
| ACP concept | DSH implementation |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `compress` tool shadows a range | durable `surfaceOp: { op: 'replace' }` — the model-written summary becomes a checkpoint node; the originals stay in the log |
|
|
29
|
+
| refs (`m00001` tags) | surface seqs, carried by the nudge's compressible-range table |
|
|
30
|
+
| nudge ("you should compress") | injected at `agent/pre-step` by the kernel's pressure decision |
|
|
31
|
+
| `decompress` | read-only recovery of shadowed originals from the log |
|
|
32
|
+
| `search_context` | scores block summaries + originals rebuilt from the log |
|
|
33
|
+
| `acp_status` | block ledger + context pressure |
|
|
34
|
+
| block state | in-memory kernel state + **log-rebuilt ledger** (no sidecar files) |
|
|
35
|
+
|
|
36
|
+
There is deliberately **no automatic summarization**: automatic policy only nudges the model (`compactIfNeeded` returns null). That is the ACP cost win — the model writes one dense summary instead of paying for a second LLM summarization call.
|
|
37
|
+
|
|
38
|
+
## Install / mount
|
|
39
|
+
|
|
40
|
+
The package is a drop-in compaction backend. Add one row to the host composition (or an agent preset's compaction realm):
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
# host composition (e.g. profile cordis.patch.yml)
|
|
44
|
+
- insert:
|
|
45
|
+
- id: compaction-billion-context
|
|
46
|
+
name: 'billion-context-dsh'
|
|
47
|
+
config:
|
|
48
|
+
modelContextLimit: 128000 # default; the pressure window
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
To replace `dsh-compaction-basic` for one agent, mount it inside the preset's `compaction` isolate realm instead:
|
|
52
|
+
|
|
53
|
+
```yaml
|
|
54
|
+
- id: compaction
|
|
55
|
+
name: cordis:group
|
|
56
|
+
group: true
|
|
57
|
+
isolate:
|
|
58
|
+
compaction: true
|
|
59
|
+
config:
|
|
60
|
+
- id: compaction-acp
|
|
61
|
+
name: 'billion-context-dsh'
|
|
62
|
+
config:
|
|
63
|
+
modelContextLimit: 128000
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
When the hosting context provides `ctx.tools` / `ctx.commands`, the engine also registers:
|
|
67
|
+
|
|
68
|
+
- `compress` — replace ranges with dense summaries you write
|
|
69
|
+
- `decompress` — recover a block's original content (read-only)
|
|
70
|
+
- `search_context` — find information inside compressed blocks
|
|
71
|
+
- `acp_status` — block ledger and pressure
|
|
72
|
+
- `/acp` — status / compress / decompress from the command bar
|
|
73
|
+
|
|
74
|
+
## Configuration
|
|
75
|
+
|
|
76
|
+
| Key | Default | Meaning |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| `modelContextLimit` | `128000` | Context window used for the kernel's pressure decisions |
|
|
79
|
+
| `nudgeMinContextLimitPct` | kernel default `0.45` | Nudge window lower bound (usage fraction) — same default as billion-context-pi |
|
|
80
|
+
| `nudgeMaxContextLimitPct` | kernel default `0.75` | Over-limit line: above this the nudge fires regardless of growth |
|
|
81
|
+
| `nudgeEmergencyThresholdPct` | kernel default `0.95` | Emergency nudge (bypasses the per-turn dedup) |
|
|
82
|
+
| `coreOverrides` | — | Any other acp-kernel `Config` override (billion-context-pi's `coreOverrides` escape hatch) |
|
|
83
|
+
| `autoTools` | `true` | Register the four model tools on `ctx.tools` |
|
|
84
|
+
| `autoCommand` | `true` | Register the `/acp` command on `ctx.commands` |
|
|
85
|
+
| `autoNudge` | `true` | Inject the nudge into `agent/pre-step` |
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npm install
|
|
91
|
+
npm run typecheck # strict TS
|
|
92
|
+
npm test # node --import tsx --test tests/*.test.ts
|
|
93
|
+
npm run build # tsup bundle (inlines acp-kernel) + .d.ts
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`dist/index.js` is self-contained except for the `@deepseek-ai/*` seam packages, which the hosting deployment provides.
|
|
97
|
+
|
|
98
|
+
## Architecture
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
src/
|
|
102
|
+
├── index.ts # AcpCompactionEngine (CompactionEngine backend) + wiring
|
|
103
|
+
├── messages.ts # M1: session events ↔ acp-kernel CoreMessage projection
|
|
104
|
+
├── state.ts # M2: per-session kernel state
|
|
105
|
+
├── region.ts # M5: durable region transaction + log-rebuilt block ledger
|
|
106
|
+
├── tools.ts # M3: compress / decompress / search_context / acp_status
|
|
107
|
+
├── nudge.ts # M4: kernel pressure decision → injected nudge message
|
|
108
|
+
└── commands.ts # M4: /acp slash command
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# billion-context-dsh
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | [中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
**One billion, not one million(十亿,而非百万)。** 面向 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 的 [Active Context Pruning(ACP,主动上下文裁剪)](https://github.com/ranxianglei/acp-kernel)——以 `CompactionEngine` 后端形式提供的模型驱动上下文管理。
|
|
6
|
+
|
|
7
|
+
由**模型自己决定何时压缩、压缩什么**——而不是一个硬性上限。长对话保持精简,关键细节(路径、决策、错误信息)以高保真摘要保留,且可搜索、可解压。
|
|
8
|
+
|
|
9
|
+
这是 [billion-context-pi](https://github.com/ranxianglei/billion-context-pi)(Pi 编码代理适配器)在 DSH 上的移植。压缩内核(`acp-kernel`)原样复用;适配层针对 DSH 的 durable-surface(持久化表面)模型重写——验证过的映射关系见 [docs/dsh-porting-verification.md](docs/dsh-porting-verification.md)。
|
|
10
|
+
|
|
11
|
+
## 上游项目与致谢
|
|
12
|
+
|
|
13
|
+
本项目是一个**移植/派生项目**,站在以下上游工作的肩膀上——全部为 MIT 许可。**衷心感谢** [ranxianglei](https://github.com/ranxianglei) 和 DeepSeek Harness 团队创建并开源这些项目:
|
|
14
|
+
|
|
15
|
+
| 上游项目 | 作者 | 角色 |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| **[billion-context-pi](https://github.com/ranxianglei/billion-context-pi)** | [ranxianglei](https://github.com/ranxianglei) | 本项目移植的 Pi 编码代理适配器;适配器设计、工具语义与本项目默认配置的来源 |
|
|
18
|
+
| **[acp-kernel](https://github.com/ranxianglei/acp-kernel)** | [ranxianglei](https://github.com/ranxianglei) | 框架无关的上下文压缩引擎——**原样复用**(refs、blocks、tiers、nudge 决策、search、status) |
|
|
19
|
+
| **[opencode-acp](https://github.com/ranxianglei/opencode-acp)** | [ranxianglei](https://github.com/ranxianglei) | ACP("模型决定何时压缩、压缩什么")设计的源头 |
|
|
20
|
+
| **[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)** | DeepSeek AI | 本项目所扩展的宿主平台(compaction 能力接缝、agent preset、持久化会话日志) |
|
|
21
|
+
|
|
22
|
+
本项目原样复用 `acp-kernel` 的压缩内核与 `billion-context-pi` 的默认行为;DSH 适配层(会话事件投影、持久化表面事务、模型工具、nudge、配置)为本仓库原创。上游版权与许可归其各自作者所有;本项目的许可条款见 [LICENSE](LICENSE)。
|
|
23
|
+
|
|
24
|
+
## 工作原理
|
|
25
|
+
|
|
26
|
+
DSH 的每个模型请求都派生自其 append-only 会话日志(*surface*)。ACP 语义直接映射到这一模型:
|
|
27
|
+
|
|
28
|
+
| ACP 概念 | DSH 实现 |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `compress` 工具遮蔽一段范围 | 持久化 `surfaceOp: { op: 'replace' }`——模型书写的摘要成为 checkpoint 节点;原文保留在日志中 |
|
|
31
|
+
| refs(`m00001` 标签) | 表面 seq,由 nudge 的可压缩范围表携带 |
|
|
32
|
+
| nudge("你也许该压缩了") | 由内核的压力决策在 `agent/pre-step` 注入 |
|
|
33
|
+
| `decompress` | 从日志只读恢复被遮蔽的原文 |
|
|
34
|
+
| `search_context` | 对从日志重建的块摘要与原文打分 |
|
|
35
|
+
| `acp_status` | 块账本与上下文压力 |
|
|
36
|
+
| 块状态 | 内存内核状态 + **日志重建账本**(无旁车文件) |
|
|
37
|
+
|
|
38
|
+
刻意**不做自动摘要**:自动策略只 nudge 模型(`compactIfNeeded` 返回 null)。这正是 ACP 的成本优势——模型书写一份紧凑摘要,而不是为第二次 LLM 摘要调用付费。
|
|
39
|
+
|
|
40
|
+
## 安装 / 挂载
|
|
41
|
+
|
|
42
|
+
本包是即插即用的压缩后端。在宿主组合(或 agent preset 的 compaction realm)中添加一行:
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
# 宿主组合(例如 profile 的 cordis.patch.yml)
|
|
46
|
+
- insert:
|
|
47
|
+
- id: compaction-billion-context
|
|
48
|
+
name: 'billion-context-dsh'
|
|
49
|
+
config:
|
|
50
|
+
modelContextLimit: 128000 # 默认;压力窗口
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
要为某个 agent 替换 `dsh-compaction-basic`,改为挂载在 preset 的 `compaction` isolate realm 中:
|
|
54
|
+
|
|
55
|
+
```yaml
|
|
56
|
+
- id: compaction
|
|
57
|
+
name: cordis:group
|
|
58
|
+
group: true
|
|
59
|
+
isolate:
|
|
60
|
+
compaction: true
|
|
61
|
+
config:
|
|
62
|
+
- id: compaction-acp
|
|
63
|
+
name: 'billion-context-dsh'
|
|
64
|
+
config:
|
|
65
|
+
modelContextLimit: 128000
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
当宿主上下文提供 `ctx.tools` / `ctx.commands` 时,引擎还会注册:
|
|
69
|
+
|
|
70
|
+
- `compress` — 用你书写的紧凑摘要替换范围
|
|
71
|
+
- `decompress` — 恢复某块的原始内容(只读)
|
|
72
|
+
- `search_context` — 在压缩块内查找信息
|
|
73
|
+
- `acp_status` — 块账本与压力
|
|
74
|
+
- `/acp` — 从命令栏执行 status / compress / decompress
|
|
75
|
+
|
|
76
|
+
## 配置
|
|
77
|
+
|
|
78
|
+
| 键 | 默认值 | 含义 |
|
|
79
|
+
|---|---|---|
|
|
80
|
+
| `modelContextLimit` | `128000` | 用于内核压力决策的上下文窗口 |
|
|
81
|
+
| `nudgeMinContextLimitPct` | 内核默认 `0.45` | Nudge 窗口下界(用量占比)——与 billion-context-pi 相同的默认值 |
|
|
82
|
+
| `nudgeMaxContextLimitPct` | 内核默认 `0.75` | 过限线:超过此值则无论增长与否都触发 nudge |
|
|
83
|
+
| `nudgeEmergencyThresholdPct` | 内核默认 `0.95` | 紧急 nudge(绕过每轮去重) |
|
|
84
|
+
| `coreOverrides` | — | 任何其他 acp-kernel `Config` 覆盖(billion-context-pi 的 `coreOverrides` 逃生口) |
|
|
85
|
+
| `autoTools` | `true` | 在 `ctx.tools` 注册四个模型工具 |
|
|
86
|
+
| `autoCommand` | `true` | 在 `ctx.commands` 注册 `/acp` 命令 |
|
|
87
|
+
| `autoNudge` | `true` | 当内核建议时向 `agent/pre-step` 注入 nudge |
|
|
88
|
+
|
|
89
|
+
## 开发
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm install
|
|
93
|
+
npm run typecheck # 严格 TS
|
|
94
|
+
npm test # node --import tsx --test tests/*.test.ts
|
|
95
|
+
npm run build # tsup 打包(内联 acp-kernel)+ .d.ts
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`dist/index.js` 自包含,仅外链 `@deepseek-ai/*` 接缝包(由宿主部署提供)。
|
|
99
|
+
|
|
100
|
+
## 架构
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
src/
|
|
104
|
+
├── index.ts # AcpCompactionEngine(CompactionEngine 后端)+ 接线
|
|
105
|
+
├── messages.ts # M1: 会话事件 ↔ acp-kernel CoreMessage 投影
|
|
106
|
+
├── state.ts # M2: 每会话内核状态
|
|
107
|
+
├── region.ts # M5: 持久化区域事务 + 日志重建块账本
|
|
108
|
+
├── tools.ts # M3: compress / decompress / search_context / acp_status
|
|
109
|
+
├── nudge.ts # M4: 内核压力决策 → 注入的建议式 nudge 消息
|
|
110
|
+
├── system-prompt.ts # M4: ACP 指引系统提示段(一次性,不进 nudge)
|
|
111
|
+
└── commands.ts # M4: /acp 斜杠命令
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M4 — the `/acp` slash command: a human-friendly window into the same
|
|
3
|
+
* machinery the model tools expose (status, one-shot compress, decompress).
|
|
4
|
+
* @module billion-context-dsh/commands
|
|
5
|
+
*/
|
|
6
|
+
import type { CommandDefinition } from '@deepseek-ai/dsh-commands';
|
|
7
|
+
import type { ToolEnvironment } from './tools.ts';
|
|
8
|
+
/** Register the /acp command (idempotent per engine). */
|
|
9
|
+
export declare function acpCommand(env: ToolEnvironment): CommandDefinition;
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel configuration assembly — the DSH counterpart of billion-context-pi's
|
|
3
|
+
* `resolveConfig`: build acp-kernel's `Config` from adapter-level knobs.
|
|
4
|
+
*
|
|
5
|
+
* Defaults are deliberately the acp-kernel `defaultConfig` values (the same
|
|
6
|
+
* defaults billion-context-pi ships: nudge window 45%–75%, emergency 95%,
|
|
7
|
+
* growth ratio 5%, protected last messages 5). Every knob is optional — an
|
|
8
|
+
* omitted value keeps the kernel default, so the behavior matches the Pi
|
|
9
|
+
* adapter exactly unless a deployment opts out.
|
|
10
|
+
* @module billion-context-dsh/config
|
|
11
|
+
*/
|
|
12
|
+
import { type Config } from 'acp-kernel';
|
|
13
|
+
/** The kernel-facing knobs shared by the nudge path and the compress tool. */
|
|
14
|
+
export interface KernelConfigInput {
|
|
15
|
+
readonly modelContextLimit: number;
|
|
16
|
+
/** Nudge window lower bound (usage fraction). Kernel default: 0.45. */
|
|
17
|
+
readonly nudgeMinContextLimitPct?: number;
|
|
18
|
+
/** Nudge window upper bound — over-limit. Kernel default: 0.75. */
|
|
19
|
+
readonly nudgeMaxContextLimitPct?: number;
|
|
20
|
+
/** Emergency nudge threshold (bypasses per-turn dedup). Kernel default: 0.95. */
|
|
21
|
+
readonly nudgeEmergencyThresholdPct?: number;
|
|
22
|
+
/** Any other acp-kernel Config override (the billion-context-pi escape hatch). */
|
|
23
|
+
readonly coreOverrides?: Partial<Config>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Assemble the kernel config: `defaultConfig(limit)` merged with the optional
|
|
27
|
+
* nudge thresholds (merged into the defaults, never replacing them wholesale)
|
|
28
|
+
* and any additional `coreOverrides`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function kernelConfigFor(input: KernelConfigInput): Config;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* billion-context-dsh — Active Context Pruning (ACP) for the DeepSeek Harness,
|
|
3
|
+
* delivered as a `CompactionEngine` backend.
|
|
4
|
+
*
|
|
5
|
+
* The model decides when and what to compress (pure ACP semantics):
|
|
6
|
+
* - the `compress` tool durably shadows a surface range with the model-written
|
|
7
|
+
* summary (no second LLM summarization call — the ACP cost win);
|
|
8
|
+
* - the original events stay in the append-only session log, so `decompress`,
|
|
9
|
+
* `search_context`, and replay always work;
|
|
10
|
+
* - refs are surface seqs carried by the injected nudge's range table (DSH
|
|
11
|
+
* has no in-memory message rewrite hook — see docs/dsh-porting-verification.md);
|
|
12
|
+
* - automatic policy never summarizes by itself: it nudges the model.
|
|
13
|
+
*
|
|
14
|
+
* Mount it wherever a compaction backend is expected:
|
|
15
|
+
*
|
|
16
|
+
* ```yaml
|
|
17
|
+
* - id: compaction-billion-context
|
|
18
|
+
* name: 'billion-context-dsh'
|
|
19
|
+
* config:
|
|
20
|
+
* modelContextLimit: 128000
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* The package registers `ctx.compaction` plus the four model tools and the
|
|
24
|
+
* `/acp` command when the hosting composition provides `ctx.tools` /
|
|
25
|
+
* `ctx.commands`.
|
|
26
|
+
* @module billion-context-dsh
|
|
27
|
+
*/
|
|
28
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
29
|
+
import { CompactionEngine, type CompactionAgentContext, type CompactionResult, type CompactionTrigger, type ManualCompactAgentContext } from '@deepseek-ai/dsh-compaction';
|
|
30
|
+
import { type CompressionCore } from 'acp-kernel';
|
|
31
|
+
import { AcpStateStore } from './state.ts';
|
|
32
|
+
export { AcpStateStore } from './state.ts';
|
|
33
|
+
export { kernelConfigFor, type KernelConfigInput } from './config.ts';
|
|
34
|
+
export { ACP_SYSTEM_PROMPT, ACP_SYSTEM_PROMPT_ORDER } from './system-prompt.ts';
|
|
35
|
+
export { makeTools, type ToolEnvironment } from './tools.ts';
|
|
36
|
+
export { acpCommand } from './commands.ts';
|
|
37
|
+
export { buildNudge, type NudgeEnvironment, type NudgeOutcome } from './nudge.ts';
|
|
38
|
+
export { rebuildBlockLedger, resolveSurfaceRange, runCompactionTransaction, shadowedSeqsOf, findOpenTurn, assertNoActiveCompaction, type AcpBlockLedgerEntry, type CompactionTransactionInput, } from './region.ts';
|
|
39
|
+
export { eventsToCoreMessages, projectEvent, surfaceEventsOf, extractEventText } from './messages.ts';
|
|
40
|
+
export interface AcpConfig {
|
|
41
|
+
/** The context window used for pressure decisions. Default 128000. */
|
|
42
|
+
readonly modelContextLimit: number;
|
|
43
|
+
/** Nudge window lower bound (usage fraction). Kernel default 0.45 — same as billion-context-pi. */
|
|
44
|
+
readonly nudgeMinContextLimitPct?: number;
|
|
45
|
+
/** Nudge window upper bound (over-limit). Kernel default 0.75 — same as billion-context-pi. */
|
|
46
|
+
readonly nudgeMaxContextLimitPct?: number;
|
|
47
|
+
/** Emergency nudge threshold (bypasses per-turn dedup). Kernel default 0.95 — same as billion-context-pi. */
|
|
48
|
+
readonly nudgeEmergencyThresholdPct?: number;
|
|
49
|
+
/** Any other acp-kernel Config override (billion-context-pi's `coreOverrides` escape hatch). */
|
|
50
|
+
readonly coreOverrides?: Partial<import('acp-kernel').Config>;
|
|
51
|
+
/** Register the four model tools on `ctx.tools`. Default true. */
|
|
52
|
+
readonly autoTools: boolean;
|
|
53
|
+
/** Register the `/acp` command on `ctx.commands`. Default true. */
|
|
54
|
+
readonly autoCommand: boolean;
|
|
55
|
+
/** Inject the nudge into `agent/pre-step` when the kernel recommends it. Default true. */
|
|
56
|
+
readonly autoNudge: boolean;
|
|
57
|
+
}
|
|
58
|
+
export declare function resolveAcpConfig(config?: Partial<AcpConfig>): AcpConfig;
|
|
59
|
+
/**
|
|
60
|
+
* The ACP compaction backend. Subclasses the seam exactly like
|
|
61
|
+
* `dsh-compaction-basic`; swaps summarization-driven compaction for
|
|
62
|
+
* model-driven block compression without touching the agent loop.
|
|
63
|
+
*/
|
|
64
|
+
export declare class AcpCompactionEngine extends CompactionEngine {
|
|
65
|
+
/** The framework-agnostic ACP compression core, reused verbatim. */
|
|
66
|
+
readonly kernel: CompressionCore;
|
|
67
|
+
/** Per-session kernel state. */
|
|
68
|
+
readonly store: AcpStateStore;
|
|
69
|
+
/** Resolved engine configuration. */
|
|
70
|
+
readonly config: AcpConfig;
|
|
71
|
+
private readonly lastNudgeTurn;
|
|
72
|
+
constructor(ctx: Context, config?: Partial<AcpConfig>);
|
|
73
|
+
/** ACP is model-driven: automatic pressure policy never summarizes by itself. */
|
|
74
|
+
compactIfNeeded(_agent: CompactionAgentContext, _trigger: CompactionTrigger, signal: AbortSignal): Promise<CompactionResult | null>;
|
|
75
|
+
/** Explicit idle-session compaction: ACP leaves the decision to the model. */
|
|
76
|
+
compactNow(_agent: ManualCompactAgentContext, signal: AbortSignal): Promise<CompactionResult | null>;
|
|
77
|
+
/**
|
|
78
|
+
* The model-driven path lands through the `compress` tool, which runs the
|
|
79
|
+
* full durable transaction directly. This seam method rejects with guidance:
|
|
80
|
+
* automatic summarization is exactly what ACP replaces.
|
|
81
|
+
*/
|
|
82
|
+
compactRegion(_start: number, _end: number, _agent: CompactionAgentContext, signal?: AbortSignal): Promise<CompactionResult>;
|
|
83
|
+
}
|
|
84
|
+
export default AcpCompactionEngine;
|