diff --git a/docs/configuration.ja.md b/docs/configuration.ja.md index 5506ba15db..6a8cb64b59 100644 --- a/docs/configuration.ja.md +++ b/docs/configuration.ja.md @@ -319,6 +319,7 @@ | `compress.absorb` | object | opt-in (disabled) | — | ツール結果を短い要約に即時蒸留するオプトイン機能;元データはコンテンツストアに保存される。デフォルトでは画像を含む結果のみが対象となる。 | | `compress.degenerateRetry` | object | 1 attempt (built-in nudge) | — | クライアントに見える出力がゼロで終わるターンのリトライ予算と nudge 文の設定。継続 nudge はリトライ本文にのみ付加され、永続化も次のリクエストでの再生もされない。 | | `compress.blockOps` | object | off | — | 圧縮ブロック管理用のブロックライフサイクルツール(acp_retire / acp_restore / acp_rewrite)のオプトイン;デフォルト無効により、#5765 以前のワイヤーとバイト単位で同一を維持する。 | +| `compress.anchorSidecar` | object | off | — | オプトインの決定論的アンカーサイドカー:折りたたみ要約にファイルパス・エラー署名・永続 ID の有界な字面インデックスを機械的に付加し、T2/T3 蒸留でも引き継ぐ。 | | `compress.ccr` | object | enabled in proxy mode since v2 | — | コンテンツキャッシュと取得:大きな出力はセッションの隣接にロスカレスで保存され、先頭抜粋とポインタに置き換えられ、acp_retrieve 経由で取得される;上限や退避は行われない。 | | `compress.search` | object | off | — | search_context の検索動作設定;現在、planAware リランキングを保持している。 | | `compress.search.planAware` | boolean | false | — | オンにすると、search_context の候補が現在のプラン状態に対してリランキングされる;オフにすると、バイト単位で同一の語彙結果が維持される。 | @@ -337,6 +338,9 @@ | `compress.degenerateRetry.maxAttempts` | integer | 1 | — | 退化ターンのリトライ予算(#7666):クライアントに見える出力が何もないターン終了時に、agent の元のリクエストに末尾ユーザー nudge を追加して再発行する。0 = 無効(そのターンは素通し)、1 = 1 回(#7666 以前の動作)、最大 5;i 回目の試行で nudges[i] を送信(リストが短ければ循環)。ゼロバイト切断の再発行(#2171)とは予算が独立——1 ターンでそれぞれ 1 回まで。 | | `compress.degenerateRetry.nudges` | string[] | 3 built-in | — | 退化ターンリトライ用のカスタム nudge 文(#7666);i 回目のリトライで i 番目の文を送信(短ければ循環)。未設定 = 組み込みローテーション(先頭はデフォルトの継続 nudge)。 | | `compress.blockOps.enabled` | boolean | false | — | 3 つのブロックライフサイクルツール(インジェクション + プロンプト + マニフェスト)を有効にする。Off = ツールなし、プロンプトセクションなし、リクエストごとのコストゼロ。 | +| `compress.anchorSidecar.enabled` | boolean | false | — | 折りたたみブロックへの決定論的アンカーサイドカー抽出を有効にする。Off = バイト単位で同一の要約。 | +| `compress.anchorSidecar.maxAnchors` | number | 16 | — | 1 ブロックあたり出力する決定論的アンカーの最大数(1 以上の整数)。 | +| `compress.anchorSidecar.maxSectionChars` | number | 1200 | — | 1 ブロックあたり付加する ANCHORS セクションの最大文字数(120 以上の整数)。 | | `compress.ccr.enabled` | boolean | true (proxy mode) | — | コンテンツキャッシュおよび取得ブロックを有効にする。 | | `compress.ccr.minToolTokens` | number | ≈4000 | — | CCR ストレージの対象となるツール結果の最小推定トークンサイズ。 | | `compress.ccr.excludeTools` | string[] | [] | — | CCR ストレージから除外されるツール名。 | diff --git a/docs/configuration.md b/docs/configuration.md index 354f18f2b1..5f4f11512b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -322,6 +322,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed | `compress.absorb` | object | opt-in (disabled) | — | Opt-in instant distillation of tool results into short abstracts; originals go to the content store. By default only image-bearing results qualify. | | `compress.degenerateRetry` | object | 1 attempt (built-in nudge) | — | Retry budget and nudge sentences for turns that end with zero client-visible output (degenerate terminal turns). The continuation nudge rides the retry body only — it is never persisted into session state and never replayed on the client's next request. | | `compress.blockOps` | object | off | — | Opt-in block-lifecycle tools (acp_retire / acp_restore / acp_rewrite) for compressed-block management; default-off keeps the wire byte-identical to pre-#5765. | +| `compress.anchorSidecar` | object | off | — | Opt-in deterministic anchor sidecar: mechanically appends a bounded verbatim index of file paths, error signatures, and durable IDs to folded summaries and carries them forward across T2/T3 distillation. | | `compress.ccr` | object | enabled in proxy mode since v2 | — | Content cache & retrieve: large outputs stored losslessly beside the session, replaced by head excerpt + pointer fetched back via acp_retrieve; no cap or eviction. | | `compress.search` | object | off | — | Search-behavior settings for search_context; currently holds planAware re-ranking. | | `compress.search.planAware` | boolean | false | — | When on, search_context candidates are re-ranked against current plan state; off keeps byte-identical lexical results. | @@ -340,6 +341,9 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed | `compress.degenerateRetry.maxAttempts` | integer | 1 | — | Degenerate-terminal retry budget (#7666): when a turn ends with nothing client-visible, the agent's own request is re-issued with a trailing user nudge. 0 = off (the turn passes through bare), 1 = once (pre-#7666 behavior), max 5; attempt i sends nudges[i] (cycling). Independent of the zero-byte-cut re-issue (#2171) — a turn may spend one of each. | | `compress.degenerateRetry.nudges` | string[] | 3 built-in | — | Custom nudge sentences for degenerate-terminal retries (#7666); retry i sends sentence i (cycling when shorter). Unset = the built-in rotation, whose first entry is the default continuation nudge. | | `compress.blockOps.enabled` | boolean | false | — | Enable the three block-lifecycle tools (injection + prompt + manifest). Off = no tools, no prompt section, zero per-request cost. | +| `compress.anchorSidecar.enabled` | boolean | false | — | Enable deterministic anchor sidecar extraction on folded blocks. Off = byte-identical summaries. | +| `compress.anchorSidecar.maxAnchors` | number | 16 | — | Maximum number of deterministic anchors emitted per folded block (integer >= 1). | +| `compress.anchorSidecar.maxSectionChars` | number | 1200 | — | Hard character cap for the appended ANCHORS section per folded block (integer >= 120). | | `compress.ccr.enabled` | boolean | true (proxy mode) | — | Enable the content-cache-and-retrieve block. | | `compress.ccr.minToolTokens` | number | ≈4000 | — | Minimum estimated token size of a tool result eligible for CCR storage. | | `compress.ccr.excludeTools` | string[] | [] | — | Tool names excluded from CCR storage. | diff --git a/docs/configuration.zh-CN.md b/docs/configuration.zh-CN.md index 1d1659c1e2..8374d813f2 100644 --- a/docs/configuration.zh-CN.md +++ b/docs/configuration.zh-CN.md @@ -322,6 +322,7 @@ | `compress.absorb` | object | opt-in (disabled) | — | 可选即时蒸馏:把工具结果蒸馏成短摘要,原文进内容库。默认仅图片类结果参与。 | | `compress.degenerateRetry` | object | 1 attempt (built-in nudge) | — | 零可见输出回合(退化终端回合)的重试预算与 nudge 句配置。续接 nudge 只附在重试请求体上——不写入会话状态,客户端下一轮不重放。 | | `compress.blockOps` | object | off | — | 可选的压缩块生命周期工具(acp_retire / acp_restore / acp_rewrite);默认关闭,关闭时线上字节与 #5765 之前完全一致。 | +| `compress.anchorSidecar` | object | off | — | 可选的确定性锚点 Sidecar:折叠时机械提取并附带受控字面索引(文件路径、错误签名、持久 ID),并在 T2/T3 蒸馏与重折时自动沿袭。 | | `compress.ccr` | object | enabled in proxy mode since v2 | — | 内容缓存与回取:大输出无损存到会话旁、替换为首段摘录+指针,模型用 acp_retrieve 取回原文;无上限、永不清除。 | | `compress.search` | object | off | — | search_context 的检索行为设置;当前含 planAware 重排。 | | `compress.search.planAware` | boolean | false | — | 开启后 search_context 候选按当前计划状态重排;关闭时结果逐字节不变。 | @@ -340,6 +341,9 @@ | `compress.degenerateRetry.maxAttempts` | integer | 1 | — | 空回合重试预算(#7666):回合以客户端零可见输出收尾时,把 agent 自己的原请求追加一条尾部 user nudge 后重发。0=关(空回合直接放行),1=一次(#7666 前的默认行为),上限 5;第 i 次发 nudges[i](短了循环)。与断流重发(#2171)预算独立——同一回合各可花一次。 | | `compress.degenerateRetry.nudges` | string[] | 3 built-in | — | 自定义空回合重试 nudge 句(#7666);第 i 次重试发第 i 句(短了循环)。不填 = 内置轮换,首句即默认续接 nudge。 | | `compress.blockOps.enabled` | boolean | false | — | 启用三个压缩块生命周期工具(注入 + prompt + manifest)。关闭 = 无工具、无 prompt 段、零每请求开销。 | +| `compress.anchorSidecar.enabled` | boolean | false | — | 开启折叠块的确定性锚点 Sidecar 提取。关闭 = 摘要逐字节不变。 | +| `compress.anchorSidecar.maxAnchors` | number | 16 | — | 单个折叠块最多附带的确定性锚点数(>= 1 的整数)。 | +| `compress.anchorSidecar.maxSectionChars` | number | 1200 | — | 单个折叠块附带 ANCHORS 段的字符硬上限(>= 120 的整数)。 | | `compress.ccr.enabled` | boolean | true (proxy mode) | — | 启用内容缓存与回取块。 | | `compress.ccr.minToolTokens` | number | ≈4000 | — | 可进入 CCR 存储的工具结果的最小估算 token 大小。 | | `compress.ccr.excludeTools` | string[] | [] | — | 排除出 CCR 存储的工具名。 | diff --git a/kernel/package-lock.json b/kernel/package-lock.json index eba76b5541..9e0bc6da4b 100644 --- a/kernel/package-lock.json +++ b/kernel/package-lock.json @@ -1,12 +1,12 @@ { "name": "acp-kernel", - "version": "0.0.223", + "version": "0.0.224", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "acp-kernel", - "version": "0.0.223", + "version": "0.0.224", "license": "MIT", "devDependencies": { "@types/node": "^22.0.0", diff --git a/kernel/package.json b/kernel/package.json index 184cc19213..ef712ac2b9 100644 --- a/kernel/package.json +++ b/kernel/package.json @@ -1,6 +1,6 @@ { "name": "acp-kernel", - "version": "0.0.223", + "version": "0.0.224", "description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.", "license": "MIT", "author": "ranxianglei", diff --git a/kernel/src/anchor-sidecar.ts b/kernel/src/anchor-sidecar.ts new file mode 100644 index 0000000000..492a4a4c9d --- /dev/null +++ b/kernel/src/anchor-sidecar.ts @@ -0,0 +1,309 @@ +/** + * Deterministic Anchor Sidecar — pure lower-triangular kernel module. + * + * Complements model-authored prose summaries with a compact, bounded, + * mechanically-extracted ANCHORS section recording exact file paths (with line + * numbers), failure/error signatures, and durable identifiers (PR/issue refs, + * commit SHAs, semver tags) from folded messages — and carries them forward + * across T2/T3 distillation and refolds without relying on model obedience. + * + * Design invariants: + * - Zero LLM calls, pure O(N) single-pass extraction, strictly bounded by + * maxAnchors (default 16) and maxSectionChars (default 1200). + * - Opt-in (`config.anchorSidecar?.enabled === true`): off = byte-identical + * block summaries for all existing callers and golden tests. + * - Orthogonal to `#5620` MEDIA REFS: distinct marker + blank-line boundary so + * both parsers/appenders compose commutatively without bleeding or duplication. + * - Fail-closed secret hygiene: never emits tokens, auth headers, private keys, + * pre-signed URLs, or high-entropy base64 blobs. + */ +import type { + AnchorSidecarConfig, + CompressionBlock, + CoreMessage, +} from "./types.js"; + +export type AnchorKind = "path" | "error" | "id"; + +export interface DeterministicAnchor { + readonly kind: AnchorKind; + readonly value: string; +} + +export const DEFAULT_ANCHOR_SIDECAR_MAX_ANCHORS = 16; +export const DEFAULT_ANCHOR_SIDECAR_MAX_CHARS = 1200; + +/** Deterministic header of the mechanically-appended anchor section. Exact + * line match is the parse boundary — idempotent across append/strip/parse. */ +export const ANCHOR_SIDECAR_MARKER = + "ANCHORS (deterministic verbatim index — preserve when distilling):"; + +const SECRET_RE = + /(?:sk-[A-Za-z0-9_-]{12,}|gh[pou]_[A-Za-z0-9]{16,}|github_pat_[A-Za-z0-9_]{16,}|xox[baprs]-[A-Za-z0-9-]{12,}|AKIA[0-9A-Z]{16}|Bearer\s+[A-Za-z0-9._~+/=-]{12,}|-----BEGIN\s+[A-Z ]*PRIVATE KEY|(?:password|passwd|secret|api[_-]?key|access[_-]?token|auth[_-]?token)\s*[:=]\s*\S+)/i; + +const HIGH_ENTROPY_B64_RE = /[A-Za-z0-9+/=_-]{48,}/; + +const SKIP_PATH_RE = + /^(?:https?:|data:|file:|mailto:|node_modules\/|\/tmp\/|\/proc\/|\/dev\/|\/sys\/)/i; + +const FILE_PATH_RE = + /(?= 0xd800 && code <= 0xdbff) { + const next = i + 1 < raw.length ? raw.charCodeAt(i + 1) : 0; + if (next >= 0xdc00 && next <= 0xdfff) { + clean += raw[i]! + raw[i + 1]!; + i++; + } + continue; + } + if (code >= 0xdc00 && code <= 0xdfff) continue; + if (code < 0x20 && code !== 0x09) { + clean += " "; + continue; + } + clean += raw[i]!; + } + clean = clean.replace(/\s+/g, " ").trim(); + if (clean.length > maxLen) clean = clean.slice(0, maxLen - 1).trimEnd() + "…"; + return clean; +} + +function isUnsafeAnchor(s: string): boolean { + if (!s) return true; + if (SECRET_RE.test(s)) return true; + if (HIGH_ENTROPY_B64_RE.test(s)) return true; + if (/https?:\/\/\S+\?\S*(?:sig|token|auth|expires|x-amz|x-goog)/i.test(s)) { + return true; + } + return false; +} + +function looksLikePath(raw: string): boolean { + if (!raw || raw.length < 3 || raw.length > 220) return false; + if (SKIP_PATH_RE.test(raw)) return false; + if (raw.includes("..")) return false; + if (/^\d+\.\d+\.\d+/.test(raw)) return false; // IP/version + if (!raw.includes("/")) return false; + return true; +} + +/** Extract deterministic anchors from a single CoreMessage. + * Pure, O(|text|), bounded scan cap (first 32KB per message) so giant logs + * cannot stall applyCompression. */ +export function extractMessageAnchors( + message: CoreMessage, +): DeterministicAnchor[] { + const raw = typeof message.text === "string" ? message.text : ""; + if (raw.length === 0) return []; + // Skip synthetic summary blocks — their anchors come via parseAnchorSidecarSection. + if (raw.startsWith("[Compressed conversation section]")) return []; + const text = raw.length > 32_768 ? raw.slice(0, 32_768) : raw; + + const out: DeterministicAnchor[] = []; + const seen = new Set(); + const push = (kind: AnchorKind, value: string, maxLen = 140): void => { + const clean = sanitizeValue(value, maxLen); + if (!clean || isUnsafeAnchor(clean)) return; + const key = `${kind}:${clean}`; + if (seen.has(key)) return; + seen.add(key); + out.push({ kind, value: clean }); + }; + + // 1. High-signal paths from structured tool inputs (Read/Edit/Write/etc.) + if (message.contentType === "tool-call") { + for (const m of text.matchAll(TOOL_PATH_FIELD_RE)) { + const p = m[1]!; + if (looksLikePath(p)) push("path", p, 160); + } + } + + // 2. Explicit repo/filesystem paths with extension (and optional :line[-line]) + for (const m of text.matchAll(FILE_PATH_RE)) { + const p = m[1]!; + if (looksLikePath(p)) push("path", p, 160); + } + + // 3. Failure / error lines (bounded to first 4 distinct lines per message) + let errCount = 0; + for (const line of text.split("\n")) { + if (errCount >= 4) break; + const trimmed = line.trim(); + if (trimmed.length < 8) continue; + if (BENIGN_SUMMARY_LINE_RE.test(trimmed)) continue; + const match = ERROR_LINE_RE.exec(trimmed); + if (match) { + const candidate = trimmed.length <= 400 ? trimmed : match[0].trim(); + push("error", candidate, 120); + errCount++; + } + } + + // 4. Exact identifiers: PR/issue numbers, explicit git commit SHAs, semver + for (const m of text.matchAll(PR_ISSUE_RE)) { + push("id", `#${m[1]!}`, 24); + } + for (const m of text.matchAll(COMMIT_SHA_RE)) { + push("id", m[1]!.toLowerCase(), 24); + } + for (const m of text.matchAll(SEMVER_RE)) { + push("id", `v${m[1]!}`, 40); + } + + return out; +} + +function normalizeAnchorCap(cfg?: AnchorSidecarConfig): { + maxAnchors: number; + maxSectionChars: number; +} { + const maxAnchors = + typeof cfg?.maxAnchors === "number" && + Number.isInteger(cfg.maxAnchors) && + cfg.maxAnchors >= 1 + ? cfg.maxAnchors + : DEFAULT_ANCHOR_SIDECAR_MAX_ANCHORS; + const maxSectionChars = + typeof cfg?.maxSectionChars === "number" && + Number.isInteger(cfg.maxSectionChars) && + cfg.maxSectionChars >= 120 + ? cfg.maxSectionChars + : DEFAULT_ANCHOR_SIDECAR_MAX_CHARS; + return { maxAnchors, maxSectionChars }; +} + +function stripAnchorSidecarSection(summary: string): string { + const lines = summary.split("\n"); + const idx = lines.findIndex((l) => l.trim() === ANCHOR_SIDECAR_MARKER); + if (idx === -1) return summary; + let end = idx + 1; + while (end < lines.length && lines[end]!.startsWith("- ")) end++; + lines.splice(idx, end - idx); + return lines.join("\n").replace(/\n{3,}/g, "\n\n"); +} + +/** Parse a mechanically-appended ANCHORS section back into typed anchors. + * Returns empty array when absent. */ +export function parseAnchorSidecarSection( + summary: string, +): DeterministicAnchor[] { + const lines = summary.split("\n"); + const idx = lines.findIndex((l) => l.trim() === ANCHOR_SIDECAR_MARKER); + if (idx === -1) return []; + const out: DeterministicAnchor[] = []; + const seen = new Set(); + for (let i = idx + 1; i < lines.length && lines[i]!.startsWith("- "); i++) { + const body = lines[i]!.slice(2).trim(); + const match = /^(path|error|id):\s*(.+)$/.exec(body); + if (!match) continue; + const kind = match[1] as AnchorKind; + const value = sanitizeValue(match[2]!, kind === "path" ? 160 : 120); + if (!value || isUnsafeAnchor(value)) continue; + const key = `${kind}:${value}`; + if (seen.has(key)) continue; + seen.add(key); + out.push({ kind, value }); + } + return out; +} + +/** Collect deterministic anchors for a fold: extracted from newly-folded + * direct messages + carried forward from consumed blocks (so T2/T3 + * distillation never drops anchors). Deterministic priority order: + * errors → paths → ids, bounded by maxAnchors. */ +export function collectFoldAnchors( + directMessages: readonly (CoreMessage | undefined)[], + consumedBlocks: readonly (CompressionBlock | undefined)[], + cfg?: AnchorSidecarConfig, +): DeterministicAnchor[] { + const { maxAnchors } = normalizeAnchorCap(cfg); + const buckets: Record = { + error: [], + path: [], + id: [], + }; + const seen = new Set(); + const add = (a: DeterministicAnchor): void => { + const key = `${a.kind}:${a.value}`; + if (seen.has(key)) return; + seen.add(key); + buckets[a.kind].push(a.value); + }; + + for (const m of directMessages) { + if (m) for (const a of extractMessageAnchors(m)) add(a); + } + for (const b of consumedBlocks) { + if (b) for (const a of parseAnchorSidecarSection(b.summary)) add(a); + } + + // Balanced priority allocation: reserve room for errors & paths first so a + // flood of #issue ids never crowds out file paths or failure signatures. + const maxErrors = Math.max(2, Math.floor(maxAnchors * 0.35)); + const maxPaths = Math.max(4, Math.floor(maxAnchors * 0.45)); + const selected: DeterministicAnchor[] = []; + for (const v of buckets.error.slice(0, maxErrors)) { + selected.push({ kind: "error", value: v }); + } + for (const v of buckets.path.slice(0, maxPaths)) { + selected.push({ kind: "path", value: v }); + } + const remaining = Math.max(0, maxAnchors - selected.length); + for (const v of buckets.id.slice(0, remaining)) { + selected.push({ kind: "id", value: v }); + } + // If id bucket was smaller than remaining, top up with extra paths then errors. + for (const v of buckets.path.slice(maxPaths)) { + if (selected.length >= maxAnchors) break; + selected.push({ kind: "path", value: v }); + } + for (const v of buckets.error.slice(maxErrors)) { + if (selected.length >= maxAnchors) break; + selected.push({ kind: "error", value: v }); + } + return selected.slice(0, maxAnchors); +} + +/** Append the canonical ANCHORS section idempotently (replacing any prior + * ANCHORS section so repeated calls never duplicate). Bounded by + * maxSectionChars. Returns input unchanged when anchors is empty. */ +export function appendAnchorSidecarSection( + summary: string, + anchors: readonly DeterministicAnchor[], + cfg?: AnchorSidecarConfig, +): string { + if (anchors.length === 0) return summary; + const { maxAnchors, maxSectionChars } = normalizeAnchorCap(cfg); + const lines: string[] = [ANCHOR_SIDECAR_MARKER]; + let usedChars = ANCHOR_SIDECAR_MARKER.length; + for (const a of anchors.slice(0, maxAnchors)) { + const line = `- ${a.kind}: ${a.value}`; + if (usedChars + 1 + line.length > maxSectionChars) break; + lines.push(line); + usedChars += 1 + line.length; + } + if (lines.length === 1) return summary; + const base = stripAnchorSidecarSection(summary).replace(/\n+$/, ""); + const section = lines.join("\n"); + return base ? `${base}\n\n${section}` : section; +} diff --git a/kernel/src/compress.ts b/kernel/src/compress.ts index f18bcf5195..2ea07138c4 100644 --- a/kernel/src/compress.ts +++ b/kernel/src/compress.ts @@ -42,6 +42,11 @@ import { collectFoldMediaRefs, parseMediaRefsSection, } from "./media-refs.js"; +import { + appendAnchorSidecarSection, + collectFoldAnchors, + parseAnchorSidecarSection, +} from "./anchor-sidecar.js"; import { evaluateRefold, type RefoldDecision } from "./refold.js"; import { computeProtectedRefs, @@ -346,9 +351,17 @@ function applyRefolds(input: { const carriedRefs = parseMediaRefsSection(block.summary).map( scrubLoneSurrogates, ); + const withMedia = appendMediaRefsSection(input.spec.summary, carriedRefs); + const summary = input.config.anchorSidecar?.enabled + ? appendAnchorSidecarSection( + withMedia, + parseAnchorSidecarSection(block.summary), + input.config.anchorSidecar, + ) + : withMedia; return { ...block, - summary: appendMediaRefsSection(input.spec.summary, carriedRefs), + summary, topic: input.spec.topic ?? block.topic, runId: input.runId, restoredInline: false, @@ -2005,9 +2018,15 @@ function applySingleRange(input: SingleRangeInput): SingleRangeOutcome { // the stored summary — appended mechanically (never model discretion; on // the wire a URL part is often invisible to the summarizer), and carried // forward from consumed blocks so merges/distillations drop none. + const directMessagesForFold = filteredIds.map((id) => + input.messages.find((entry) => entry.id === id), + ); + const consumedBlocksForFold = consumedBlockIds.map((id) => + blockById(input.state, id), + ); const foldMediaRefs = collectFoldMediaRefs( - filteredIds.map((id) => input.messages.find((entry) => entry.id === id)), - consumedBlockIds.map((id) => blockById(input.state, id)), + directMessagesForFold, + consumedBlocksForFold, ).map(scrubLoneSurrogates); const blockId = allocateBlockId(input.state); @@ -2015,9 +2034,24 @@ function applySingleRange(input: SingleRangeInput): SingleRangeOutcome { // block. The claim is recorded only when it is EXACT — see // resolveCoverageInterval. const interval = resolveCoverageInterval( - filteredIds.map((id) => input.messages.find((entry) => entry.id === id)), - consumedBlockIds.map((id) => blockById(input.state, id)), + directMessagesForFold, + consumedBlocksForFold, ); + const summaryWithMedia = appendMediaRefsSection( + input.spec.summary, + foldMediaRefs, + ); + const summary = input.config.anchorSidecar?.enabled + ? appendAnchorSidecarSection( + summaryWithMedia, + collectFoldAnchors( + directMessagesForFold, + consumedBlocksForFold, + input.config.anchorSidecar, + ), + input.config.anchorSidecar, + ) + : summaryWithMedia; // #8015: an auto-split stripped the kept higher-tier block's ids from the // coverage but the requested refs still span them — persisting them would // claim ownership the block does not have (two active blocks with overlapping @@ -2041,7 +2075,7 @@ function applySingleRange(input: SingleRangeInput): SingleRangeOutcome { runId: input.runId, tier: outputTier, topic: input.spec.topic, - summary: appendMediaRefsSection(input.spec.summary, foldMediaRefs), + summary, directMessageIds: filteredIds, effectiveMessageIds: [...effectiveMessageIds], directBlockIds: [...consumedBlockIds], diff --git a/kernel/src/index.ts b/kernel/src/index.ts index 068c7cf440..dadb60dac7 100644 --- a/kernel/src/index.ts +++ b/kernel/src/index.ts @@ -336,6 +336,16 @@ export { export * from "./filter/index.js"; export { VIABLE_RANGE_MIN_TOKENS, viableRanges } from "./viable.js"; +export { + ANCHOR_SIDECAR_MARKER, + DEFAULT_ANCHOR_SIDECAR_MAX_ANCHORS, + DEFAULT_ANCHOR_SIDECAR_MAX_CHARS, + extractMessageAnchors, + collectFoldAnchors, + parseAnchorSidecarSection, + appendAnchorSidecarSection, +} from "./anchor-sidecar.js"; +export type { AnchorKind, DeterministicAnchor } from "./anchor-sidecar.js"; export { classifyTurn, verbosityDirective, diff --git a/kernel/src/types.ts b/kernel/src/types.ts index 05cf39a52d..cf74b7fa2c 100644 --- a/kernel/src/types.ts +++ b/kernel/src/types.ts @@ -638,9 +638,22 @@ export interface Config { rules?: RulesConfig; /** Lossless content-cached retrieval for oversized tool results (see ccr.ts). Absent/disabled = feature off. */ ccr?: CcrConfig; + /** Deterministic Anchor Sidecar (see anchor-sidecar.ts): mechanically + * appends a compact verbatim index of file paths, error signatures, and + * durable identifiers to folded summaries and carries them across T2/T3 + * distillation. Absent/disabled = feature off (byte-identical summaries). */ + anchorSidecar?: AnchorSidecarConfig; messageFilters?: import("./filter/types.js").MessageFiltersConfig; } +export interface AnchorSidecarConfig { + enabled: boolean; + /** Maximum anchors emitted per block (default 16). */ + maxAnchors?: number; + /** Maximum characters for the appended ANCHORS section (default 1200). */ + maxSectionChars?: number; +} + export type CompressMode = "range" | "message"; export interface CompressRangeSpec { diff --git a/kernel/tests/anchor-sidecar.test.ts b/kernel/tests/anchor-sidecar.test.ts new file mode 100644 index 0000000000..31e7fc0969 --- /dev/null +++ b/kernel/tests/anchor-sidecar.test.ts @@ -0,0 +1,265 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { + ANCHOR_SIDECAR_MARKER, + appendAnchorSidecarSection, + collectFoldAnchors, + createCore, + createInitialState, + defaultConfig, + extractMessageAnchors, + parseAnchorSidecarSection, + type CoreMessage, +} from "../src/index.js"; + +function msg( + id: string, + role: CoreMessage["role"], + text: string, + extra: Partial = {}, +): CoreMessage { + return { id, role, contentType: "text", text, ...extra }; +} + +test("extractMessageAnchors extracts tool paths, inline paths, errors, and durable IDs while rejecting secrets", () => { + const m1 = msg( + "m1", + "assistant", + JSON.stringify({ file_path: "/repo/src/image-rescale.ts", limit: 50 }), + { contentType: "tool-call", toolName: "Read", toolCallId: "tc1" }, + ); + const m2 = msg( + "m2", + "user", + [ + "Investigated src/server/prepare-anthropic.ts:142-168 for #7626 at commit 0a133d91 (v0.1.216).", + "TypeError: Cannot read properties of undefined (reading 'media_type')", + "ℹ fail 0", + "Authorization: Bearer sk-live-secret-token-1234567890abcdef", + "password=super-secret-value-99", + "signed https://bucket.example.com/a.png?X-Amz-Signature=deadbeef", + ].join("\n"), + ); + + const anchors = [ + ...extractMessageAnchors(m1), + ...extractMessageAnchors(m2), + ]; + const values = anchors.map((a) => `${a.kind}:${a.value}`); + + assert.ok(values.includes("path:/repo/src/image-rescale.ts")); + assert.ok(values.includes("path:src/server/prepare-anthropic.ts:142-168")); + assert.ok( + values.some( + (v) => + v.startsWith("error:") && + v.includes("TypeError: Cannot read properties of undefined"), + ), + ); + assert.ok(values.includes("id:#7626")); + assert.ok(values.includes("id:0a133d91")); + assert.ok(values.includes("id:v0.1.216")); + // Benign test count line must not pollute error anchors + assert.ok(!values.some((v) => v.includes("fail 0"))); + // Secret hygiene: none of the secret/token/signed-URL strings may ever leak + for (const v of values) { + assert.ok(!v.includes("sk-live-secret"), `secret leaked: ${v}`); + assert.ok(!v.includes("super-secret"), `password leaked: ${v}`); + assert.ok(!v.includes("X-Amz-Signature"), `signed URL leaked: ${v}`); + } +}); + +test("appendAnchorSidecarSection + parseAnchorSidecarSection are idempotent and bounded by maxSectionChars", () => { + const anchors = Array.from({ length: 30 }, (_, i) => ({ + kind: "path" as const, + value: `src/module-${i}/handler-${i}.ts:${i + 10}`, + })); + const once = appendAnchorSidecarSection("Summary prose.", anchors, { + enabled: true, + maxAnchors: 16, + maxSectionChars: 360, + }); + const section = once.slice(once.indexOf(ANCHOR_SIDECAR_MARKER)); + assert.ok( + section.length <= 360, + `section exceeded cap: ${section.length} > 360`, + ); + const parsed = parseAnchorSidecarSection(once); + assert.ok(parsed.length > 0 && parsed.length < 16); + // Idempotence: re-appending produces the exact same string + const twice = appendAnchorSidecarSection(once, parsed, { + enabled: true, + maxAnchors: 16, + maxSectionChars: 360, + }); + assert.equal(twice, once); +}); + +test("createCore applyCompression: default-off stays byte-identical; enabled appends deterministic anchors & carries them across T2 distillation and MEDIA REFS", () => { + const core = createCore(); + const makeHistory = (): CoreMessage[] => [ + msg( + "u1", + "user", + "Fix TypeError in src/image-rescale.ts:173 for #7626 on v0.1.216 with commit 0a133d91. ".repeat( + 10, + ), + ), + { + ...msg( + "a1", + "assistant", + "Read src/image-rescale.ts:173 and reproduced ERR_IMAGE_INFLATE across 16 samples. ".repeat( + 10, + ), + ), + rawAnthropicBlock: { + type: "image", + source: { type: "url", url: "https://cdn.example.com/static/diagram.png" }, + }, + } as CoreMessage, + msg( + "u2", + "user", + "Now check kernel/src/compress.ts:2038 and fix AssertionError in tests/anchor.test.ts. ".repeat( + 10, + ), + ), + msg( + "a2", + "assistant", + "Verified kernel/src/compress.ts:2038 after #7804. ".repeat(10), + ), + msg("u3", "user", "Recent message kept outside protected zone check."), + msg("a3", "assistant", "Recent assistant reply."), + msg("u4", "user", "Current user prompt."), + ]; + + // 1. Default OFF: summary is byte-identical (no ANCHORS section) + const offCfg = defaultConfig(200_000); + offCfg.preserveRecentMessages = 2; + offCfg.preserveRecentTokens = 0; + offCfg.compress.minCompressRange = 50; + const offHistory = makeHistory(); + const offTurn = core.processTurn({ + messages: offHistory, + state: createInitialState(), + config: offCfg, + }); + const offRes = core.applyCompression({ + messages: offHistory, + state: offTurn.state, + config: offCfg, + ranges: [ + { + startRef: "m00001", + endRef: "m00002", + summary: + "Prose summary without exact paths or error strings, long enough to satisfy the default minSummaryLength gate.", + }, + ], + }); + assert.equal(offRes.result.blocksCreated, 1); + assert.ok(!offRes.state.blocks[0]!.summary.includes(ANCHOR_SIDECAR_MARKER)); + + // 2. Enabled ON: T1 fold appends ANCHORS alongside MEDIA REFS without bleeding + const onCfg = defaultConfig(200_000); + onCfg.preserveRecentMessages = 2; + onCfg.preserveRecentTokens = 0; + onCfg.compress.minCompressRange = 50; + onCfg.anchorSidecar = { enabled: true, maxAnchors: 16, maxSectionChars: 1200 }; + const onHistory = makeHistory(); + const onTurn = core.processTurn({ + messages: onHistory, + state: createInitialState(), + config: onCfg, + }); + const t1 = core.applyCompression({ + messages: onHistory, + state: onTurn.state, + config: onCfg, + ranges: [ + { + startRef: "m00001", + endRef: "m00002", + summary: "Short prose for first span that omitted paths and error names.", + }, + { + startRef: "m00003", + endRef: "m00004", + summary: "Short prose for second span that omitted paths and error names.", + }, + ], + }); + assert.equal(t1.state.blocks.length, 2); + const b1Summary = t1.state.blocks[0]!.summary; + assert.ok(b1Summary.includes("MEDIA REFS")); + assert.ok(b1Summary.includes("https://cdn.example.com/static/diagram.png")); + assert.ok(b1Summary.includes(ANCHOR_SIDECAR_MARKER)); + assert.ok(b1Summary.includes("- path: src/image-rescale.ts:173")); + assert.ok(b1Summary.includes("ERR_IMAGE_INFLATE")); + assert.ok(b1Summary.includes("- id: #7626")); + + // 3. T2 distillation across b1..b2 carries forward BOTH MEDIA REFS and ANCHORS + const turn2 = core.processTurn({ + messages: onHistory, + state: t1.state, + config: onCfg, + }); + const t2 = core.applyCompression({ + messages: onHistory, + state: turn2.state, + config: onCfg, + ranges: [ + { + startRef: "b1", + endRef: "b2", + summary: + "High-level T2 summary where the model dropped every path, error, and issue id.", + }, + ], + }); + const b3 = t2.state.blocks.find((b) => b.blockId === "b3")!; + assert.equal(b3.tier, 2); + assert.ok(b3.summary.includes("https://cdn.example.com/static/diagram.png")); + assert.ok(b3.summary.includes(ANCHOR_SIDECAR_MARKER)); + assert.ok(b3.summary.includes("- path: src/image-rescale.ts:173")); + assert.ok(b3.summary.includes("- path: kernel/src/compress.ts:2038")); + assert.ok(b3.summary.includes("- id: #7626")); + assert.ok(b3.summary.includes("- id: #7804")); + + // 4. Refold (in-place summary rewrite of a restored T1 block) preserves ANCHORS & MEDIA REFS + const restoredState = { + ...t1.state, + blocks: t1.state.blocks.map((b) => + b.blockId === "b1" ? { ...b, restoredInline: true } : b, + ), + }; + const turn3 = core.processTurn({ + messages: onHistory, + state: restoredState, + config: onCfg, + }); + const refold = core.applyCompression({ + messages: onHistory, + state: turn3.state, + config: onCfg, + ranges: [ + { + startRef: "m00001", + endRef: "m00002", + summary: + "Refolded prose summary replacing the earlier text while omitting every explicit anchor path and issue number.", + }, + ], + }); + const b1After = refold.state.blocks.find((b) => b.blockId === "b1")!; + assert.equal(b1After.restoredInline, false); + assert.ok(b1After.summary.includes("https://cdn.example.com/static/diagram.png")); + assert.ok(b1After.summary.includes(ANCHOR_SIDECAR_MARKER)); + assert.ok(b1After.summary.includes("- path: src/image-rescale.ts:173")); + assert.ok(b1After.summary.includes("- id: #7626")); + + // Verify balanced collector never throws on empty inputs + assert.deepEqual(collectFoldAnchors([], []), []); +}); diff --git a/package-lock.json b/package-lock.json index 571edc9e35..0845ecfc83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,7 +51,7 @@ }, "kernel": { "name": "acp-kernel", - "version": "0.0.223", + "version": "0.0.224", "dev": true, "license": "MIT", "devDependencies": { diff --git a/src/compress-settings.ts b/src/compress-settings.ts index ec262dc18f..356eba97ce 100644 --- a/src/compress-settings.ts +++ b/src/compress-settings.ts @@ -58,6 +58,7 @@ export function mergeCompress( // provider-level excludeTools. const absorbLevels = [global?.absorb, provider?.absorb, model?.absorb].filter(Boolean) as NonNullable[]; const blockOpsLevels = [global?.blockOps, provider?.blockOps, model?.blockOps].filter(Boolean) as NonNullable[]; + const anchorSidecarLevels = [global?.anchorSidecar, provider?.anchorSidecar, model?.anchorSidecar].filter(Boolean) as NonNullable[]; const ccrLevels = [global?.ccr, provider?.ccr, model?.ccr].filter(Boolean) as NonNullable[]; const searchLevels = [global?.search, provider?.search, model?.search].filter(Boolean) as NonNullable[]; const reasoningLevels = [global?.reasoning, provider?.reasoning, model?.reasoning].filter(Boolean) as NonNullable[]; @@ -100,6 +101,7 @@ export function mergeCompress( acknowledgePromptsRisk: pick("acknowledgePromptsRisk"), absorb: absorbLevels.length > 0 ? Object.assign({}, ...absorbLevels) : undefined, blockOps: blockOpsLevels.length > 0 ? Object.assign({}, ...blockOpsLevels) : undefined, + anchorSidecar: anchorSidecarLevels.length > 0 ? Object.assign({}, ...anchorSidecarLevels) : undefined, ccr: ccrLevels.length > 0 ? Object.assign({}, ...ccrLevels) : undefined, search: searchLevels.length > 0 ? Object.assign({}, ...searchLevels) : undefined, rules: pick("rules"), @@ -450,6 +452,15 @@ export function applyCompressSettings(base: Config, limit: number, s: CompressSe // #5765: one-switch opt-in — absent `s.blockOps` leaves base untouched // (off); a present block normalizes enabled (absent/false = off). ...(s.blockOps !== undefined ? { blockOps: { enabled: s.blockOps.enabled === true } } : {}), + ...(s.anchorSidecar !== undefined + ? { + anchorSidecar: { + enabled: s.anchorSidecar.enabled === true, + ...(s.anchorSidecar.maxAnchors !== undefined ? { maxAnchors: s.anchorSidecar.maxAnchors } : {}), + ...(s.anchorSidecar.maxSectionChars !== undefined ? { maxSectionChars: s.anchorSidecar.maxSectionChars } : {}), + }, + } + : {}), ...(ccr !== undefined ? { ccr } : {}), ...(s.rules !== undefined ? { rules: { enabled: s.rules === true } } : {}), }; diff --git a/src/config.ts b/src/config.ts index b6c2823964..29a2fe4e54 100644 --- a/src/config.ts +++ b/src/config.ts @@ -618,6 +618,20 @@ export type CompressSettings = { /** Enable the block-lifecycle tools for this scope. Absent/false = off. */ enabled?: boolean; }; + /** Deterministic Anchor Sidecar (kernel `Config.anchorSidecar`, acp-kernel + * >= 0.0.212): mechanically appends a bounded verbatim index of file + * paths, failure signatures, and durable IDs to folded summaries and + * carries them forward across T2/T3 distillation and refolds. Default off + * (byte-identical summaries). Merged sub-field-wise across global → + * provider → model. */ + anchorSidecar?: { + /** Enable deterministic anchor sidecar extraction. Absent/false = off. */ + enabled?: boolean; + /** Maximum anchors emitted per block (integer >= 1; kernel default 16). */ + maxAnchors?: number; + /** Maximum characters for the appended ANCHORS section (integer >= 120; kernel default 1200). */ + maxSectionChars?: number; + }; /** [#1097] Kernel CCR content store (kernel `Config.ccr`, acp-kernel * 0.0.84). When `enabled`, oversized tool results (>= minToolTokens) are * ID-referenced at arrival by the kernel's ccr-store node (prune → @@ -2701,7 +2715,7 @@ const COMPRESS_SETTING_FIELDS = new Set([ "outputHeadroomMaxPct", "tiers", "protectedLatestTools", "protectedTools", "neverPreserveRecentTools", "preserveRecentTools", "visibilityMarkers", "messageTimestamps", "rules", "injectTool", "injectNudge", - "acknowledgePromptsRisk", "absorb", "blockOps", "ccr", "search", + "acknowledgePromptsRisk", "absorb", "blockOps", "anchorSidecar", "ccr", "search", "prompts", "promptPack", "reasoningGuard", "outputSteering", "priceProfile", "reconcile", "streamSummary", "externalSummary", // #3635: summary-length caps — previously accepted nowhere, silently dropped. @@ -3695,6 +3709,30 @@ export function parseCompressSettings(v: unknown): (CompressSettings & { injectT if (ok) out.blockOps = cleaned; } } + if ("anchorSidecar" in obj && obj.anchorSidecar !== undefined) { + const a = obj.anchorSidecar; + if (!a || typeof a !== "object" || Array.isArray(a)) { + ok = false; + } else { + const ao = a as Record; + const cleaned: NonNullable = {}; + for (const key of ["enabled", "maxAnchors", "maxSectionChars"] as const) { + if (!(key in ao)) continue; + const v = ao[key]; + if (key === "enabled") { + if (typeof v !== "boolean") { ok = false; continue; } + cleaned.enabled = v; + } else if (key === "maxAnchors") { + if (typeof v !== "number" || !Number.isInteger(v) || v < 1) { ok = false; continue; } + cleaned.maxAnchors = v; + } else { + if (typeof v !== "number" || !Number.isInteger(v) || v < 120) { ok = false; continue; } + cleaned.maxSectionChars = v; + } + } + if (ok) out.anchorSidecar = cleaned; + } + } if ("ccr" in obj && obj.ccr !== undefined) { const c = obj.ccr; if (!c || typeof c !== "object" || Array.isArray(c)) { diff --git a/tests/compress-settings.test.ts b/tests/compress-settings.test.ts index 4940464dc0..c20a635edb 100644 --- a/tests/compress-settings.test.ts +++ b/tests/compress-settings.test.ts @@ -394,3 +394,23 @@ test("applyCompressSettings: maps tierNudgeTokens onto kernel nudge.tierGrowthTo assert.equal(absent.nudge.tierGrowthTokens, undefined); assert.equal(base.nudge.tierGrowthTokens, undefined, "base config not mutated"); }); + +test("mergeCompress / parseCompressSettings / applyCompressSettings: anchorSidecar", () => { + const merged = mergeCompress( + { anchorSidecar: { enabled: true, maxAnchors: 12 } }, + { anchorSidecar: { maxSectionChars: 900 } }, + undefined, + ); + assert.deepEqual(merged.anchorSidecar, { enabled: true, maxAnchors: 12, maxSectionChars: 900 }); + assert.deepEqual( + parseCompressSettings({ anchorSidecar: { enabled: true, maxAnchors: 20, maxSectionChars: 1500 } })?.anchorSidecar, + { enabled: true, maxAnchors: 20, maxSectionChars: 1500 }, + ); + assert.equal(parseCompressSettings({ anchorSidecar: true }), undefined); + assert.equal(parseCompressSettings({ anchorSidecar: { maxAnchors: 0 } }), undefined); + assert.equal(parseCompressSettings({ anchorSidecar: { maxSectionChars: 50 } }), undefined); + const base = defaultConfig(200000); + const out = applyCompressSettings(base, 200000, { anchorSidecar: { enabled: true, maxAnchors: 12, maxSectionChars: 800 } }); + assert.deepEqual(out.anchorSidecar, { enabled: true, maxAnchors: 12, maxSectionChars: 800 }); + assert.equal(applyCompressSettings(base, 200000, {}).anchorSidecar, undefined); +}); diff --git a/website/config-reference/compress.yaml b/website/config-reference/compress.yaml index eb4b59705d..067814f44f 100644 --- a/website/config-reference/compress.yaml +++ b/website/config-reference/compress.yaml @@ -415,6 +415,17 @@ entries: desc_ja: "圧縮ブロック管理用のブロックライフサイクルツール(acp_retire / acp_restore / acp_rewrite)のオプトイン;デフォルト無効により、#5765 以前のワイヤーとバイト単位で同一を維持する。" site_en: "blockOps — opt-in compressed-block lifecycle tools (acp_retire / acp_restore / acp_rewrite); off by default so the wire surface stays byte-identical to pre-#5765 (enabled)." site_zh: "blockOps —— 可选的压缩块生命周期工具(acp_retire / acp_restore / acp_rewrite);默认关闭,线上表面与 #5765 之前逐字节一致(enabled)。" + - key: compress.anchorSidecar + type: object + default: "off" + group: compress + id: co.anchorSidecar + render: obj-item + desc_en: "Opt-in deterministic anchor sidecar: mechanically appends a bounded verbatim index of file paths, error signatures, and durable IDs to folded summaries and carries them forward across T2/T3 distillation." + desc_zh: "可选的确定性锚点 Sidecar:折叠时机械提取并附带受控字面索引(文件路径、错误签名、持久 ID),并在 T2/T3 蒸馏与重折时自动沿袭。" + desc_ja: "オプトインの決定論的アンカーサイドカー:折りたたみ要約にファイルパス・エラー署名・永続 ID の有界な字面インデックスを機械的に付加し、T2/T3 蒸留でも引き継ぐ。" + site_en: "anchorSidecar — opt-in deterministic anchor sidecar: mechanically appends bounded file paths, error signatures, and durable IDs to folded summaries and preserves them across T2/T3 distillation (enabled, maxAnchors (16), maxSectionChars (1200))." + site_zh: "anchorSidecar —— 可选的确定性锚点 Sidecar:机械附带受控的文件路径、错误签名与持久 ID 索引,并在 T2/T3 蒸馏时沿袭(enabled, maxAnchors(16), maxSectionChars(1200))。" - key: compress.ccr type: object default: "enabled in proxy mode since v2" @@ -577,6 +588,27 @@ entries: desc_en: "Enable the three block-lifecycle tools (injection + prompt + manifest). Off = no tools, no prompt section, zero per-request cost." desc_zh: "启用三个压缩块生命周期工具(注入 + prompt + manifest)。关闭 = 无工具、无 prompt 段、零每请求开销。" desc_ja: "3 つのブロックライフサイクルツール(インジェクション + プロンプト + マニフェスト)を有効にする。Off = ツールなし、プロンプトセクションなし、リクエストごとのコストゼロ。" + - key: compress.anchorSidecar.enabled + type: boolean + default: "false" + group: compress + desc_en: "Enable deterministic anchor sidecar extraction on folded blocks. Off = byte-identical summaries." + desc_zh: "开启折叠块的确定性锚点 Sidecar 提取。关闭 = 摘要逐字节不变。" + desc_ja: "折りたたみブロックへの決定論的アンカーサイドカー抽出を有効にする。Off = バイト単位で同一の要約。" + - key: compress.anchorSidecar.maxAnchors + type: number + default: "16" + group: compress + desc_en: "Maximum number of deterministic anchors emitted per folded block (integer >= 1)." + desc_zh: "单个折叠块最多附带的确定性锚点数(>= 1 的整数)。" + desc_ja: "1 ブロックあたり出力する決定論的アンカーの最大数(1 以上の整数)。" + - key: compress.anchorSidecar.maxSectionChars + type: number + default: "1200" + group: compress + desc_en: "Hard character cap for the appended ANCHORS section per folded block (integer >= 120)." + desc_zh: "单个折叠块附带 ANCHORS 段的字符硬上限(>= 120 的整数)。" + desc_ja: "1 ブロックあたり付加する ANCHORS セクションの最大文字数(120 以上の整数)。" - key: compress.ccr.enabled type: boolean default: "true (proxy mode)" diff --git a/website/docs/index.html b/website/docs/index.html index 2cfef5a933..54529ea913 100644 --- a/website/docs/index.html +++ b/website/docs/index.html @@ -226,6 +226,7 @@

compress — every knob

  • absorb — opt-in instant distillation of tool results into short abstracts; originals go to the content store; by default only image-bearing results qualify (enabled, minToolTokens (default 1000), contextThresholdPct, excludeTools, mediaOnly (default true), toolName "absorb").
  • degenerateRetry — retry budget for zero-visible-output turns; the continuation nudge rides the retry body only, never persisted (maxAttempts (default 1, 0 = off, max 5), nudges (1–8 custom sentences)).
  • blockOps — opt-in compressed-block lifecycle tools (acp_retire / acp_restore / acp_rewrite); off by default so the wire surface stays byte-identical to pre-#5765 (enabled).
  • +
  • anchorSidecar — opt-in deterministic anchor sidecar: mechanically appends bounded file paths, error signatures, and durable IDs to folded summaries and preserves them across T2/T3 distillation (enabled, maxAnchors (16), maxSectionChars (1200)).
  • ccr — content cache & retrieve: large outputs are stored losslessly beside the session and replaced by a head excerpt plus pointer; the model fetches originals back via acp_retrieve. No cap or eviction; on by default in proxy mode since v2 (enabled, minToolTokens (~4000), excludeTools, toolName "acp_retrieve", maxHeadChars).
  • search — search-behavior settings for search_context; currently holds planAware.
  • search.planAware — off by default: when on, search_context candidates are re-ranked against current plan state (latest-wins todos + last user turn); off keeps byte-identical lexical results.
  • diff --git a/website/main.js b/website/main.js index 588a110950..5af959d259 100644 --- a/website/main.js +++ b/website/main.js @@ -101,6 +101,7 @@ "co.absorb": "absorb — opt-in instant distillation of tool results into short abstracts; originals go to the content store; by default only image-bearing results qualify (enabled, minToolTokens (default 1000), contextThresholdPct, excludeTools, mediaOnly (default true), toolName \"absorb\").", "co.degenerateRetry": "degenerateRetry — retry budget for zero-visible-output turns; the continuation nudge rides the retry body only, never persisted (maxAttempts (default 1, 0 = off, max 5), nudges (1–8 custom sentences)).", "co.blockops": "blockOps — opt-in compressed-block lifecycle tools (acp_retire / acp_restore / acp_rewrite); off by default so the wire surface stays byte-identical to pre-#5765 (enabled).", + "co.anchorSidecar": "anchorSidecar — opt-in deterministic anchor sidecar: mechanically appends bounded file paths, error signatures, and durable IDs to folded summaries and preserves them across T2/T3 distillation (enabled, maxAnchors (16), maxSectionChars (1200)).", "co.ccr": "ccr — content cache & retrieve: large outputs are stored losslessly beside the session and replaced by a head excerpt plus pointer; the model fetches originals back via acp_retrieve. No cap or eviction; on by default in proxy mode since v2 (enabled, minToolTokens (~4000), excludeTools, toolName \"acp_retrieve\", maxHeadChars).", "co.searchRoot": "search — search-behavior settings for search_context; currently holds planAware.", "co.search": "search.planAware — off by default: when on, search_context candidates are re-ranked against current plan state (latest-wins todos + last user turn); off keeps byte-identical lexical results.", @@ -364,6 +365,7 @@ "co.absorb": "absorb —— 可选即时蒸馏:把工具结果蒸馏成短摘要,原文进内容库;默认仅图片类结果参与(enabled, minToolTokens(默认 1000), contextThresholdPct, excludeTools, mediaOnly(默认 true), toolName \"absorb\")。", "co.degenerateRetry": "degenerateRetry —— 零可见输出回合的重试预算;续接 nudge 只附在重试请求体上、不持久化(maxAttempts(默认 1,0=关,上限 5)、nudges(1–8 句自定义))。", "co.blockops": "blockOps —— 可选的压缩块生命周期工具(acp_retire / acp_restore / acp_rewrite);默认关闭,线上表面与 #5765 之前逐字节一致(enabled)。", + "co.anchorSidecar": "anchorSidecar —— 可选的确定性锚点 Sidecar:机械附带受控的文件路径、错误签名与持久 ID 索引,并在 T2/T3 蒸馏时沿袭(enabled, maxAnchors(16), maxSectionChars(1200))。", "co.ccr": "ccr —— 内容缓存与回取:大输出无损存到会话旁、替换为首段摘录+指针,模型用 acp_retrieve 取回原文;无上限、永不清除;自 v2 起代理模式默认开(enabled, minToolTokens(~4000), excludeTools, toolName \"acp_retrieve\", maxHeadChars)。", "co.searchRoot": "search —— search_context 的检索行为设置;当前含 planAware。", "co.search": "search.planAware —— 默认关:开启后 search_context 候选按当前计划状态重排(todo 最新优先 + 上一轮用户消息);关闭时结果逐字节不变。",