billion-context-dsh 0.1.4 → 0.1.6
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 +10 -8
- package/README.md +10 -8
- package/dist/config.d.ts +6 -2
- package/dist/index.d.ts +37 -6
- package/dist/index.js +379 -70
- package/dist/index.js.map +1 -1
- package/dist/messages.d.ts +8 -0
- package/dist/nudge.d.ts +7 -1
- package/dist/region.d.ts +88 -1
- package/dist/state.d.ts +7 -0
- package/dist/system-prompt.d.ts +1 -1
- package/dist/tools.d.ts +4 -0
- package/dist/window.d.ts +32 -0
- package/package.json +1 -1
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.1.
|
|
6
|
+
> This project (**v0.1.6**) 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 ⭐:
|
|
@@ -73,7 +73,7 @@ That's it. Then add a composition row where a compaction backend is expected —
|
|
|
73
73
|
- id: compaction-acp
|
|
74
74
|
name: 'billion-context-dsh'
|
|
75
75
|
config:
|
|
76
|
-
modelContextLimit: 128000 #
|
|
76
|
+
modelContextLimit: 128000 # optional; omit to auto-detect the model's real window (fallback 128000)
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
**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:
|
|
@@ -87,7 +87,7 @@ That's it. Then add a composition row where a compaction backend is expected —
|
|
|
87
87
|
- id: compaction-acp
|
|
88
88
|
name: 'billion-context-dsh'
|
|
89
89
|
config:
|
|
90
|
-
modelContextLimit: 128000 #
|
|
90
|
+
modelContextLimit: 128000 # optional; omit to auto-detect the model's real window (fallback 128000)
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
> **One context manager per agent.** Two backends providing `ctx.compaction` collide — never run both in the same realm. Full install & verification guide: [docs/INSTALL.md](docs/INSTALL.md).
|
|
@@ -105,6 +105,7 @@ DSH derives every model request from its append-only session log (the *surface*)
|
|
|
105
105
|
| `search_context` | scores block summaries + originals rebuilt from the log |
|
|
106
106
|
| `acp_status` | block ledger + context pressure |
|
|
107
107
|
| block state | in-memory kernel state + **log-rebuilt ledger** (no sidecar files) |
|
|
108
|
+
| 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 |
|
|
108
109
|
|
|
109
110
|
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).
|
|
110
111
|
|
|
@@ -118,7 +119,7 @@ A walkthrough of the ACP philosophy this project inherits — how active context
|
|
|
118
119
|
|
|
119
120
|
| Tool | What it does |
|
|
120
121
|
| --- | --- |
|
|
121
|
-
| `compress` | Replace a seq range with a dense summary you write (edges auto-balanced to tool-pair boundaries) |
|
|
122
|
+
| `compress` | Replace a seq range with a dense summary you write (edges auto-balanced to tool-pair boundaries); re-compressing a block's summary node distills it (tier 2/3) |
|
|
122
123
|
| `decompress` | Restore a previously compressed block's original content (read-only) |
|
|
123
124
|
| `search_context` | Search compressed block summaries and originals by keyword |
|
|
124
125
|
| `acp_status` | Context usage, compressed blocks, compressible ranges |
|
|
@@ -141,10 +142,11 @@ This project reuses `acp-kernel`'s compression core and `billion-context-pi`'s d
|
|
|
141
142
|
|
|
142
143
|
| Key | Default | Meaning |
|
|
143
144
|
|---|---|---|
|
|
144
|
-
| `modelContextLimit` | `128000` | Context window used for the kernel's pressure decisions |
|
|
145
|
-
| `
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
145
|
+
| `modelContextLimit` | auto-detected (fallback `128000`) | Context window used for the kernel's pressure decisions; an explicit value wins and skips the probe |
|
|
146
|
+
| `autoModelContextLimit` | `true` | Probe the model's real window from the model API (`agent.ctx.llm.resolveModelInfo`); fall back to the default on failure, `acp_status` shows the window source |
|
|
147
|
+
| `nudgeMinContextLimitPct` | kernel default `0.45` | Nudge window lower bound (usage fraction) — validation only; the growth-driven trigger has no percentage floor — same default as billion-context-pi |
|
|
148
|
+
| `nudgeMaxContextLimitPct` | engine default `0.70` (kernel/pi default `0.75`) | Over-limit line: above this the nudge fires regardless of growth — deliberately below the host compaction-basic 80% auto-compaction line so the forced nudge fires first; an explicit value wins |
|
|
149
|
+
| `nudgeEmergencyThresholdPct` | engine default `0.85` (kernel/pi default `0.95`) | Emergency nudge (bypasses the per-turn dedup) — lowered from `0.95`: at 95% the model has no room to act and the 80% auto-compaction line shadows it; an explicit value wins |
|
|
148
150
|
| `coreOverrides` | — | Any other acp-kernel `Config` override (billion-context-pi's `coreOverrides` escape hatch) |
|
|
149
151
|
| `autoTools` | `true` | Register the four model tools on `ctx.tools` |
|
|
150
152
|
| `autoCommand` | `true` | Register the `/acp` command on `ctx.commands` |
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[中文](./README.md) | [English](./README.en.md)
|
|
4
4
|
|
|
5
5
|
> **⚠️ 测试版声明——请勿用于生产环境**
|
|
6
|
-
> 本项目(**v0.1.
|
|
6
|
+
> 本项目(**v0.1.6**)仍处于开发中的测试版。[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 本身也处于**公开测试版**阶段。**请勿将两者用于工程化 / 生产环境**——预期会有破坏性变更与粗糙之处。
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
9
9
|
<strong>衷心感谢以下项目——请给它们一个 ⭐:</strong>
|
|
@@ -75,7 +75,7 @@ npm install billion-context-dsh
|
|
|
75
75
|
- id: compaction-acp
|
|
76
76
|
name: 'billion-context-dsh'
|
|
77
77
|
config:
|
|
78
|
-
modelContextLimit: 128000 #
|
|
78
|
+
modelContextLimit: 128000 # 可选;省略时自动探测模型真实窗口(回退 128000)
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
**单模式生效(agent preset 的 `compaction` realm)**。先在该 realm 内*禁用(或删除)原有的 `dsh-compaction-basic` 行*,再插入本引擎——同一 realm 内两个后端不能并存:
|
|
@@ -89,7 +89,7 @@ npm install billion-context-dsh
|
|
|
89
89
|
- id: compaction-acp
|
|
90
90
|
name: 'billion-context-dsh'
|
|
91
91
|
config:
|
|
92
|
-
modelContextLimit: 128000 #
|
|
92
|
+
modelContextLimit: 128000 # 可选;省略时自动探测模型真实窗口(回退 128000)
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
> **每个 agent 只留一个上下文管理器。** 两个后端同时 provide `ctx.compaction` 会冲突——同一 realm 内切勿并存。完整安装与验证指南见 [docs/INSTALL.md](docs/INSTALL.md)。
|
|
@@ -107,6 +107,7 @@ DSH 的每个模型请求都派生自其 append-only 会话日志(*surface*)
|
|
|
107
107
|
| `search_context` | 对从日志重建的块摘要与原文打分 |
|
|
108
108
|
| `acp_status` | 块账本与上下文压力 |
|
|
109
109
|
| 块状态 | 内存内核状态 + **日志重建账本**(无旁车文件) |
|
|
110
|
+
| 分层蒸馏(T2/T3) | 再次压缩某块的摘要节点 = 蒸馏该块(tier 2),蒸馏 tier-2 块得 tier 3;tier 与内核块 id 持久化进日志,重启后内核状态从日志再水合、可继续蒸馏 |
|
|
110
111
|
|
|
111
112
|
承载性的压缩指引(工具、哲学、摘要规则)注册为一次性系统提示段,因此 nudge 保持简短。刻意**不做自动摘要**:自动策略只 nudge 模型(`compactIfNeeded` 返回 null)。
|
|
112
113
|
|
|
@@ -120,7 +121,7 @@ DSH 的每个模型请求都派生自其 append-only 会话日志(*surface*)
|
|
|
120
121
|
|
|
121
122
|
| 工具 | 作用 |
|
|
122
123
|
| --- | --- |
|
|
123
|
-
| `compress` | 用你书写的紧凑摘要替换 seq 范围(边界自动平衡到 tool-call/result
|
|
124
|
+
| `compress` | 用你书写的紧凑摘要替换 seq 范围(边界自动平衡到 tool-call/result 配对点);对某块的摘要节点再次压缩 = 分层蒸馏(tier 2/3) |
|
|
124
125
|
| `decompress` | 恢复已压缩块的原始内容(只读) |
|
|
125
126
|
| `search_context` | 按关键词搜索压缩块摘要与原文 |
|
|
126
127
|
| `acp_status` | 上下文占用、压缩块、可压缩范围 |
|
|
@@ -143,10 +144,11 @@ DSH 的每个模型请求都派生自其 append-only 会话日志(*surface*)
|
|
|
143
144
|
|
|
144
145
|
| 键 | 默认值 | 含义 |
|
|
145
146
|
|---|---|---|
|
|
146
|
-
| `modelContextLimit` | `128000
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
147
|
+
| `modelContextLimit` | 自动探测(回退 `128000`) | 用于内核压力决策的上下文窗口;显式配置时优先且跳过探测 |
|
|
148
|
+
| `autoModelContextLimit` | `true` | 从模型 API 自动探测真实窗口(`agent.ctx.llm.resolveModelInfo`);探测失败回退默认值,`acp_status` 展示窗口来源 |
|
|
149
|
+
| `nudgeMinContextLimitPct` | 内核默认 `0.45` | Nudge 窗口下界(用量占比)——仅作配置校验,增长路径的触发没有百分比下限——与 billion-context-pi 相同的默认值 |
|
|
150
|
+
| `nudgeMaxContextLimitPct` | engine 默认 `0.70`(内核/pi 默认 `0.75`) | 过限线:超过此值则无论增长与否都触发 nudge——刻意低于宿主 compaction-basic 的 80% 自动压缩线,保证强制 nudge 先触发;显式配置优先 |
|
|
151
|
+
| `nudgeEmergencyThresholdPct` | engine 默认 `0.85`(内核/pi 默认 `0.95`) | 紧急 nudge(绕过每轮去重)——从 `0.95` 下调:95% 时模型已无操作空间且会被 80% 自动压缩线遮蔽;显式配置优先 |
|
|
150
152
|
| `coreOverrides` | — | 任何其他 acp-kernel `Config` 覆盖(billion-context-pi 的 `coreOverrides` 逃生口) |
|
|
151
153
|
| `autoTools` | `true` | 在 `ctx.tools` 注册四个模型工具 |
|
|
152
154
|
| `autoCommand` | `true` | 在 `ctx.commands` 注册 `/acp` 命令 |
|
package/dist/config.d.ts
CHANGED
|
@@ -7,15 +7,19 @@
|
|
|
7
7
|
* growth ratio 5%, protected last messages 5). Every knob is optional — an
|
|
8
8
|
* omitted value keeps the kernel default, so the behavior matches the Pi
|
|
9
9
|
* adapter exactly unless a deployment opts out.
|
|
10
|
+
*
|
|
11
|
+
* NOTE: `AcpCompactionEngine` (src/index.ts) ships its own engine-level
|
|
12
|
+
* defaults 0.70/0.85 for the two nudge thresholds on top of this layer, so an
|
|
13
|
+
* engine with no explicit config lands on 0.70/0.85, not 0.75/0.95.
|
|
10
14
|
* @module billion-context-dsh/config
|
|
11
15
|
*/
|
|
12
16
|
import { type Config } from 'acp-kernel';
|
|
13
17
|
/** The kernel-facing knobs shared by the nudge path and the compress tool. */
|
|
14
18
|
export interface KernelConfigInput {
|
|
15
19
|
readonly modelContextLimit: number;
|
|
16
|
-
/** Nudge window lower bound (usage fraction). Kernel default: 0.45. */
|
|
20
|
+
/** Nudge window lower bound (usage fraction; validation only — the growth-driven trigger has no percentage floor). Kernel default: 0.45. */
|
|
17
21
|
readonly nudgeMinContextLimitPct?: number;
|
|
18
|
-
/** Nudge window upper bound — over-limit. Kernel default: 0.75. */
|
|
22
|
+
/** Nudge window upper bound — over-limit guarantee line. Kernel default: 0.75. */
|
|
19
23
|
readonly nudgeMaxContextLimitPct?: number;
|
|
20
24
|
/** Emergency nudge threshold (bypasses per-turn dedup). Kernel default: 0.95. */
|
|
21
25
|
readonly nudgeEmergencyThresholdPct?: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -28,23 +28,44 @@
|
|
|
28
28
|
import type { Context } from '@deepseek-ai/cordis';
|
|
29
29
|
import { CompactionEngine, type CompactionAgentContext, type CompactionResult, type CompactionTrigger, type ManualCompactAgentContext } from '@deepseek-ai/dsh-compaction';
|
|
30
30
|
import { type CompressionCore } from 'acp-kernel';
|
|
31
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
31
32
|
import { AcpStateStore } from './state.ts';
|
|
33
|
+
import { type AcpWindow } from './window.ts';
|
|
32
34
|
export { AcpStateStore } from './state.ts';
|
|
33
35
|
export { kernelConfigFor, type KernelConfigInput } from './config.ts';
|
|
34
36
|
export { ACP_SYSTEM_PROMPT, ACP_SYSTEM_PROMPT_ORDER } from './system-prompt.ts';
|
|
35
37
|
export { makeTools, type ToolEnvironment } from './tools.ts';
|
|
36
38
|
export { acpCommand } from './commands.ts';
|
|
37
39
|
export { buildNudge, type NudgeEnvironment, type NudgeOutcome } from './nudge.ts';
|
|
38
|
-
export {
|
|
40
|
+
export { DEFAULT_CONTEXT_WINDOW, detectContextWindow, windowSourceLabel, type AcpWindow, } from './window.ts';
|
|
41
|
+
export { rebuildBlockLedger, resolveSurfaceRange, runCompactionTransaction, shadowedSeqsOf, findOpenTurn, assertNoActiveCompaction, blockRegistry, blockRefForSummarySeq, compactionIdsOfKernelBlocks, summarySeqOfKernelBlock, expandShadowedSeqs, type AcpBlockLedgerEntry, type CompactionTransactionInput, } from './region.ts';
|
|
39
42
|
export { eventsToCoreMessages, projectEvent, surfaceEventsOf, extractEventText } from './messages.ts';
|
|
40
43
|
export interface AcpConfig {
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
/**
|
|
45
|
+
* The context window used for pressure decisions, in tokens. When omitted,
|
|
46
|
+
* `autoModelContextLimit` (default true) probes the model's real window via
|
|
47
|
+
* `agent.ctx.llm.resolveModelInfo(provider, model)`; an explicit value
|
|
48
|
+
* always wins and disables the probe.
|
|
49
|
+
*/
|
|
50
|
+
readonly modelContextLimit?: number;
|
|
51
|
+
/** Probe the model's real context window from the LLM runtime. Default true. */
|
|
52
|
+
readonly autoModelContextLimit: boolean;
|
|
53
|
+
/** Nudge window lower bound (usage fraction; validation only — the growth-driven trigger has no percentage floor). Kernel default 0.45 — same as billion-context-pi. */
|
|
44
54
|
readonly nudgeMinContextLimitPct?: number;
|
|
45
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Nudge window upper bound — over-limit guarantee line: above this the
|
|
57
|
+
* kernel injects a nudge regardless of growth or cadence. Engine default
|
|
58
|
+
* 0.70 (deliberately BELOW the kernel/billion-context-pi default 0.75 and
|
|
59
|
+
* the host compaction-basic auto-compaction line 0.80, so the forced nudge
|
|
60
|
+
* always fires first); an explicit value wins.
|
|
61
|
+
*/
|
|
46
62
|
readonly nudgeMaxContextLimitPct?: number;
|
|
47
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Emergency nudge threshold (bypasses the per-turn dedup). Engine default
|
|
65
|
+
* 0.85 (down from the kernel/billion-context-pi default 0.95: 95% leaves
|
|
66
|
+
* the model no room to act before the API rejects, and the host's 80%
|
|
67
|
+
* compaction-basic line shadows it in standard/code/cordis modes).
|
|
68
|
+
*/
|
|
48
69
|
readonly nudgeEmergencyThresholdPct?: number;
|
|
49
70
|
/** Any other acp-kernel Config override (billion-context-pi's `coreOverrides` escape hatch). */
|
|
50
71
|
readonly coreOverrides?: Partial<import('acp-kernel').Config>;
|
|
@@ -69,7 +90,17 @@ export declare class AcpCompactionEngine extends CompactionEngine {
|
|
|
69
90
|
/** Resolved engine configuration. */
|
|
70
91
|
readonly config: AcpConfig;
|
|
71
92
|
private readonly lastNudgeTurn;
|
|
93
|
+
/** Per provider/model route the resolved window (probe failures cached too). */
|
|
94
|
+
private readonly windowCache;
|
|
72
95
|
constructor(ctx: Context, config?: Partial<AcpConfig>);
|
|
96
|
+
/**
|
|
97
|
+
* Resolve the effective context window for an agent. An explicitly
|
|
98
|
+
* configured `modelContextLimit` always wins (no probe). Otherwise probe the
|
|
99
|
+
* model's real window via `agent.ctx.llm.resolveModelInfo` (cached per
|
|
100
|
+
* provider/model route, probe failures cached too) and fall back to
|
|
101
|
+
* DEFAULT_CONTEXT_WINDOW when auto-detection is disabled or unavailable.
|
|
102
|
+
*/
|
|
103
|
+
windowFor(agent: Agent): Promise<AcpWindow>;
|
|
73
104
|
/** ACP is model-driven: automatic pressure policy never summarizes by itself. */
|
|
74
105
|
compactIfNeeded(_agent: CompactionAgentContext, _trigger: CompactionTrigger, signal: AbortSignal): Promise<CompactionResult | null>;
|
|
75
106
|
/** Explicit idle-session compaction: ACP leaves the decision to the model. */
|