Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,14 @@ For each request, the proxy resolves the settings by longest-URL-prefix match (t

- **Type:** `object` (`{ enabled?, minToolTokens?, excludeTools?, toolName?, maxHeadChars? }`)
- **Default:** *(disabled — the feature is off unless you set `enabled: true`)*
- **Status:** ACTIVE (v1 — proxy mode, native-tools wires only)
- **Status:** ACTIVE (v1 — proxy mode; plugin lanes on the anthropic + openai wires, #1271)
- **Description:** Opt-in **content-addressed message store** / built-in CCR (issue #1097, via the `acp-kernel` CCR API, acp-kernel >= 0.0.84). Instead of force-distilling oversized tool results (like `absorb`) or carrying them on the wire forever, the kernel ID-references them at arrival (the ccr-store node runs between prune and absorb within `processTurn` — ID-referencing wins over distillation): the wire keeps a deterministic, byte-stable placeholder (`📦 [acp-stored #m00423 · shell output · 4,213 tok] \`npm run build\`\n → acp_retrieve("m00423") returns the full text`) and the original goes into the session's content store. The model retrieves the full original on demand via the injected `acp_retrieve` tool; a retrieve is ephemeral (it rides the intra-request tool-result channel, never enters fold space, consumes no message ref). Lossless by default: a retrieve not made costs one cheap tool call; a detail distilled away by absorb is gone for good. Sub-fields (merged deepest-wins like every other CompressSettings field):
- `enabled: boolean` — master switch; anything other than `true` keeps the feature fully off (no placeholders, no tool).
- `minToolTokens: number` — only tool results at or above this many tokens are ID-referenced (kernel default `4000`); smaller results stay verbatim.
- `excludeTools: string[]` — tool-name patterns never stored (glob suffixes allowed; kernel default: none).
- `toolName: string` — rename the retrieval tool (default `"acp_retrieve"`); declaration, dispatch and the placeholder hint all follow the name. Must stay unique against the client's own tool names.
- `maxHeadChars: number` — head/command preview length inside the placeholder (kernel default `96`).
The store persists as a single envelope file (`.content-store.json`) next to the session JSON, using the same at-rest codec as the session file when `BILI_ENCRYPTION_KEY` is set; entries are deduped by content hash and lazily loaded per session. Only the *content* inside a `tool` result shrinks — pairing with the assistant `tool_calls` is untouched. v1 scope gates: **proxy mode only** (plugin agents would need `acp_retrieve` advertised in their plugin manifest before a placeholder could be emitted — otherwise silent loss), and **native-tools wires only**: responses marker/text-protocol routes and `ACP_NO_INJECT_TOOL` have no channel to execute the retrieve, so the store disarms itself there instead of losing content. Known limitation: no eviction policy yet — the envelope grows with the unique originals held (tracked as a follow-up). Per-session stats (stored bytes, current wire bytes saved, retrieve rate) surface in `acp_status`; each retrieve logs a `[ccr] retrieve …` line.
The store persists as a single envelope file (`.content-store.json`) next to the session JSON, using the same at-rest codec as the session file when `BILI_ENCRYPTION_KEY` is set; entries are deduped by content hash and lazily loaded per session. Only the *content* inside a `tool` result shrinks — pairing with the assistant `tool_calls` is untouched. v1 scope gates: **proxy mode**, plus **plugin mode on the anthropic + openai wires** where the plugin manifest advertises `acp_retrieve` while CCR is enabled (#1271); responses marker/text-protocol routes, `ACP_NO_INJECT_TOOL`, and the responses/google wires in plugin mode have no proven request-only round-trip channel to execute the retrieve, so the store disarms itself there instead of losing content. Known limitation: no eviction policy yet — the envelope grows with the unique originals held (tracked as a follow-up). Per-session stats (stored bytes, current wire bytes saved, retrieve rate) surface in `acp_status`; each retrieve logs a `[ccr] retrieve …` line.

#### `imageCompression`

Expand Down
4 changes: 2 additions & 2 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,14 @@

- **类型:** `object`(`{ enabled?, minToolTokens?, excludeTools?, toolName?, maxHeadChars? }`)
- **默认值:** *(禁用 — 除非显式设置 `enabled: true`,该特性完全关闭)*
- **状态:** ACTIVE(v1 — 仅代理模式、仅原生工具线)
- **状态:** ACTIVE(v1 — 代理模式;插件通道限 anthropic + openai wire,#1271)
- **说明:** 可选开启的**内容寻址消息存储**/内置 CCR(issue #1097,经 `acp-kernel` CCR API,需 acp-kernel >= 0.0.84)。超大工具结果不再被强制蒸馏(如 `absorb`)或永远挂在线上:kernel 在到达时将其 ID 引用(ccr-store 节点位于 `processTurn` 内 prune 与 absorb 之间 —— ID 引用优先于蒸馏),线上保留一个确定性、字节稳定的占位符(`📦 [acp-stored #m00423 · shell output · 4,213 tok] \`npm run build\`\n → acp_retrieve("m00423") returns the full text`),原文进入该会话的内容存储。模型通过注入的 `acp_retrieve` 工具按需取回完整原文;retrieve 是临时的(走请求内工具结果通道,不进入折叠空间,不占用消息 ref)。默认无损:未执行的 retrieve 只花一次廉价工具调用;而被 absorb 蒸馏掉的细节则永久丢失。子字段(按字段最深层级胜出,与其他 CompressSettings 字段一致):
- `enabled: boolean` — 主开关;任何值不为 `true` 时特性完全关闭(无占位符、无工具)。
- `minToolTokens: number` — 仅达到此 token 数的工具结果被 ID 引用(kernel 默认 `4000`);更小的结果保持原样。
- `excludeTools: string[]` — 从不存储的工具名模式(允许 glob 后缀;kernel 默认为空)。
- `toolName: string` — 重命名检索工具(默认 `"acp_retrieve"`);声明、分发与占位符提示都跟随名称。必须与客户端自身工具名保持唯一。
- `maxHeadChars: number` — 占位符中头部/命令预览的长度(kernel 默认 `96`)。
存储以单个信封文件(`.content-store.json`)持久化在会话 JSON 旁边,设置 `BILI_ENCRYPTION_KEY` 时使用与会话文件相同的静态加密编解码器;条目按内容哈希去重,按会话懒加载。只有 `tool` 结果*内部的内容*缩小——与 assistant `tool_calls` 的配对不受影响。v1 范围门控:**仅代理模式**(插件 agent 需要在其插件清单中声明 `acp_retrieve`,否则占位符会造成静默丢失);且**仅限原生工具线**:responses marker/文本协议路由与 `ACP_NO_INJECT_TOOL` 没有执行 retrieve 的通道,因此存储在这些场景下自动解除武装,而不是丢失内容。已知限制:尚无驱逐策略——信封随持有的唯一原文数量增长(已记录为后续项)。按会话统计(已存字节、当前线上节省字节、retrieve 率)在 `acp_status` 中展示;每次 retrieve 记录一条 `[ccr] retrieve …` 日志。
存储以单个信封文件(`.content-store.json`)持久化在会话 JSON 旁边,设置 `BILI_ENCRYPTION_KEY` 时使用与会话文件相同的静态加密编解码器;条目按内容哈希去重,按会话懒加载。只有 `tool` 结果*内部的内容*缩小——与 assistant `tool_calls` 的配对不受影响。v1 范围门控:**代理模式**,外加 **anthropic + openai wire 上的插件模式**(CCR 启用时插件清单会声明 `acp_retrieve`,#1271);responses marker/文本协议路由、`ACP_NO_INJECT_TOOL`、以及插件模式下的 responses/google wire 没有经过验证的请求内往返通道来执行 retrieve,因此存储在这些场景下自动解除武装,而不是丢失内容。已知限制:尚无驱逐策略——信封随持有的唯一原文数量增长(已记录为后续项)。按会话统计(已存字节、当前线上节省字节、retrieve 率)在 `acp_status` 中展示;每次 retrieve 记录一条 `[ccr] retrieve …` 日志。

#### `imageCompression`

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ An opt-in fifth tool, `absorb` (`compress.absorb.enabled: true` — see [CONFIGU

An opt-in sixth tool, `acp_rule` (`compress.rules: true` — see [CONFIGURATION.md](CONFIGURATION.md)), records **persistent principle-level reminders**: a short rule recorded by the model (user-emphasized lessons, behaviors to remember, major pitfalls hit) is hard-protected from compression — the call and its result stay in context across every fold — and omitting the argument lists the recorded rules ([ranxianglei/billion-context-pi#433](https://github.com/ranxianglei/billion-context-pi/issues/433)).

An opt-in seventh tool, `acp_retrieve` (`compress.ccr.enabled: true` — see [CONFIGURATION.md](CONFIGURATION.md)), backs the **content-addressed message store** (built-in CCR, #1097): oversized tool results are **ID-referenced at arrival instead of force-distilled** — the wire keeps a byte-stable placeholder and the original goes into a per-session content-store envelope (hash-deduped), retrievable on demand via one cheap tool call. Lossless by default: a retrieve not made costs nothing but the call; a detail distilled away by absorb is gone for good. Proxy mode and native-tools wires only in v1 (the marker/text protocol has no channel to execute the retrieve, so the store disarms itself there rather than silently losing content).
An opt-in seventh tool, `acp_retrieve` (`compress.ccr.enabled: true` — see [CONFIGURATION.md](CONFIGURATION.md)), backs the **content-addressed message store** (built-in CCR, #1097): oversized tool results are **ID-referenced at arrival instead of force-distilled** — the wire keeps a byte-stable placeholder and the original goes into a per-session content-store envelope (hash-deduped), retrievable on demand via one cheap tool call. Lossless by default: a retrieve not made costs nothing but the call; a detail distilled away by absorb is gone for good. Proxy mode plus plugin lanes on the anthropic + openai wires in v1 (`acp_retrieve` is advertised in the plugin manifest while CCR is enabled, #1271); responses marker/text routes and google stay disarmed because no request-only round-trip channel exists there (silent loss, #1097).

An opt-in tool, `image_full` (`compress.imageCompression.enabled: true` — see [CONFIGURATION.md](CONFIGURATION.md)), backs **image pre-compression** (#1095): screenshot-like images in tool results are downscaled once at arrival — the kernel decides routing and recipe, the host encodes via optional `sharp` — cutting billed pixels before they enter the wire (providers bill by pixel area; halving dimensions cuts billed tokens ~4×). Non-screenshot images pass through byte-identical. Lossy by nature: when the model can't read details it calls `image_full` with the message's ref to restore the original resolution for the rest of the session — no proxy-side storage needed, since the client's own history still carries the original bytes (it never saw the shrunk form). Default off.

Expand Down
15 changes: 11 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ServerResponse } from "node:http";
import fs from "node:fs";
import path from "node:path";
import { acquireInFlight, effectiveConfig, findSessionByCanonicalId, listSessions, markCompactionBoundary, markDirty, peekSession, releaseInFlight, withSessionLock, type Session } from "./session.js";
import { ABSORB_TOOL, ABSORB_TOOL_NAME, ABSORB_TOOL_OPENAI, ABSORB_TOOL_RESPONSES, BILI_ACP_TOOLS_ANTHROPIC, BILI_ACP_TOOLS_OPENAI, BILI_ACP_TOOLS_RESPONSES, PROXY_TOOL_NAMES, RULE_TOOL, RULE_TOOL_NAME, RULE_TOOL_OPENAI, RULE_TOOL_RESPONSES, SEARCH_CONTEXT_CONVERSATION_ID_PARAM, SEARCH_CONTEXT_TOOL_NAME } from "./compress-tool.js";
import { ABSORB_TOOL, ABSORB_TOOL_NAME, ABSORB_TOOL_OPENAI, ABSORB_TOOL_RESPONSES, BILI_ACP_TOOLS_ANTHROPIC, BILI_ACP_TOOLS_OPENAI, BILI_ACP_TOOLS_RESPONSES, PROXY_TOOL_NAMES, RETRIEVE_TOOL_NAME, RULE_TOOL, RULE_TOOL_NAME, RULE_TOOL_OPENAI, RULE_TOOL_RESPONSES, SEARCH_CONTEXT_CONVERSATION_ID_PARAM, SEARCH_CONTEXT_TOOL_NAME, retrieveToolsFor } from "./compress-tool.js";
import { absorbEnabled, effectiveAbsorbConfig, isProxyToolFor } from "./absorb.js";
import { effectiveRulesConfig, rulesEnabled } from "./rules-feature.js";
import { executeProxyTool } from "./loop/core.js";
Expand Down Expand Up @@ -540,16 +540,23 @@ export function handlePluginManifest(res: import("node:http").ServerResponse, co
// enablement stays enforced at execution (isProxyToolFor / executeProxyTool).
const absorbOn = absorbEnabled(config);
const rulesOn = rulesEnabled(config);
// [#1271] acp_retrieve is advertised only while the base config enables CCR (same
// #1192 conservative rule as absorb/acp_rule). The proxy wires it on the anthropic/
// openai lanes in plugin mode; the responses wire is deliberately NOT advertised —
// that proxy disarms CCR there, so advertising would break #1192.
const ccrOn = config.ccr?.enabled === true;
const ccrName = config.ccr?.toolName ?? RETRIEVE_TOOL_NAME;
const ccrTools = ccrOn ? retrieveToolsFor(ccrName) : undefined;
res.writeHead(200, { "content-type": "application/json" });
res.end(JSON.stringify({
ok: true,
protocolVersion: PLUGIN_PROTOCOL_VERSION,
proxy: "billion-context",
version: VERSION,
toolNames: [...PROXY_TOOL_NAMES, ...(absorbOn ? [ABSORB_TOOL_NAME] : []), ...(rulesOn ? [RULE_TOOL_NAME] : [])],
toolNames: [...PROXY_TOOL_NAMES, ...(absorbOn ? [ABSORB_TOOL_NAME] : []), ...(rulesOn ? [RULE_TOOL_NAME] : []), ...(ccrOn ? [ccrName] : [])],
tools: {
anthropic: withSearchContextConversationDescription([...BILI_ACP_TOOLS_ANTHROPIC, ...(absorbOn ? [ABSORB_TOOL] : []), ...(rulesOn ? [RULE_TOOL] : [])].map(withConversationIdParam)),
openai: withSearchContextConversationDescription([...BILI_ACP_TOOLS_OPENAI, ...(absorbOn ? [ABSORB_TOOL_OPENAI] : []), ...(rulesOn ? [RULE_TOOL_OPENAI] : [])].map(withConversationIdParam)),
anthropic: withSearchContextConversationDescription([...BILI_ACP_TOOLS_ANTHROPIC, ...(absorbOn ? [ABSORB_TOOL] : []), ...(rulesOn ? [RULE_TOOL] : []), ...(ccrTools ? [ccrTools.anthropic] : [])].map(withConversationIdParam)),
openai: withSearchContextConversationDescription([...BILI_ACP_TOOLS_OPENAI, ...(absorbOn ? [ABSORB_TOOL_OPENAI] : []), ...(rulesOn ? [RULE_TOOL_OPENAI] : []), ...(ccrTools ? [ccrTools.openai] : [])].map(withConversationIdParam)),
responses: withSearchContextConversationDescription([...BILI_ACP_TOOLS_RESPONSES, ...(absorbOn ? [ABSORB_TOOL_RESPONSES] : []), ...(rulesOn ? [RULE_TOOL_RESPONSES] : [])].map(withConversationIdParam)),
},
headers: { agent: PLUGIN_AGENT_HEADER, conversation: PLUGIN_CONVERSATION_HEADER, contextWindow: PLUGIN_CONTEXT_WINDOW_HEADER, maxOutput: PLUGIN_MAX_OUTPUT_HEADER, model: PLUGIN_MODEL_HEADER, instructionsMutable: PLUGIN_INSTRUCTIONS_MUTABLE_HEADER },
Expand Down
Loading
Loading