Skip to content

feat: preserveRecentTools — positive override for the recent-zone exclusion list - #428

Merged
ranxianglei merged 3 commits into
masterfrom
2026-09-25_preserve-recent-tools
Sep 25, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-09-25_preserve-recent-tools

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Follow-up to #395 (neverPreserveRecentTools).

The trap

neverPreserveRecentTools replaces the built-in list ["decompress","search_context","read","bash"] verbatim. A user who wants to protect ONE tool (e.g. read, the #1198 batch-read fold→re-read remedy) must (a) know the built-in list, (b) restate the other three entries, and (c) silently lose any future built-in additions. Wrong-direction edits accidentally un-exclude search_context/decompress and pin just-restored blocks in the recent zone — a different disease.

Fix: the positive-facing knob

{ "preserveRecentTools": ["read"] }   // protect read in the recent zone — that's it

Effective exclusion = (neverPreserveRecentTools ?? built-in) minus preserveRecentTools

  • Common case is one entry; follows built-in evolution automatically
  • Composable with an explicit neverPreserveRecentTools (subtraction applies to the explicit list too)
  • Glob-suffix patterns subtract matching list entries ("bash*" removes bash)
  • Unset or [] = no-op (NOT protect-everything — that stays neverPreserveRecentTools: [])
  • No syntax inventions (a +/- prefix design was considered and rejected — double negation on top of an exclusion list)

Changes

  • src/types.ts: Config.preserveRecentTools?: string[]
  • src/protected.ts: isNeverPreserveRecent(msg, patterns, preservePatterns) — filter the effective list by the preserve patterns
  • src/recommend.ts: thread config.preserveRecentTools through the single call site
  • src/config.ts: validateConfig shape check (non-string array rejected; [] tolerated as no-op)

Tests (+5 in tests/protect-recent.test.ts, file 19/19)

  • subtraction protects the fresh read without touching bash exclusion
  • combines with explicit list (read protected, bash still excluded)
  • glob subtraction, no-match no-op, [] no-op
  • applyCompression refuses a range over a fresh read under preserveRecentTools:["read"] (/protected/i)
  • validateConfig shape + [] tolerance

Preflight: typecheck clean, full suite 1120/1120.

Refs ranxianglei/billion-context#1277 (adapter wiring follows there).

…lusion list

Effective exclusion = (neverPreserveRecentTools ?? built-in) minus
preserveRecentTools. The common remedy for the batch-read fold->re-read
loop (billion-context #1198/#1277) becomes a one-entry config,
["read"], without restating — or freezing a copy of — the built-in
list. Glob-suffix patterns subtract matching list entries; unset or
empty is a no-op. neverPreserveRecentTools keeps its verbatim-replace
semantics for power users (incl. the [] protect-everything hatch).

Refs ranxianglei/billion-context#1277
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-25_preserve-recent-tools (d54835b)

Option A — Install from npm PR tag (recommended)

In your adapter project:

npm install acp-kernel@pr-428

Each push to this PR publishes a new version under the pr-428 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf acp-kernel-pr428.tgz
npm install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review of #428 — preserveRecentTools, positive-facing override for the recent-zone exclusion list. I did not re-implement anything; this was already done as this PR. I fetched the branch, audited it against current master, verified locally, and fixed one diff-hygiene issue directly on the branch. Details below.

① Direction (original issue)

Follow-up to #395. The trap is real and I confirmed it in code: isNeverPreserveRecent treats an explicit neverPreserveRecentTools as a verbatim replacement of the built-in ["decompress","search_context","read","bash"] (src/protected.ts:31-36), so protecting one tool forces restating the whole list and silently drops future built-in additions. The positive-facing subtraction knob is the right shape: additive, no-op by default, composable with an explicit list, no prefix-syntax invention. Matches upstream billion-context#1198/#1277 intent.

② Regression audit (existing behaviors on touched paths)

  • Default behavior (unset preserveRecentTools): preserved exactly. isNeverPreserveRecent short-circuits to the old list when the new arg is undefined or [] (src/protected.ts:63-66) — byte-identical semantics for every existing config.
  • Explicit neverPreserveRecentTools without preserve: unchanged; subtraction only applies when preserve patterns are present, and applies to the explicit list too (documented + tested).
  • Call-site coverage: single call site computeProtectedRefs (src/recommend.ts:86) threads config.preserveRecentTools; both consumers pass the full config — applyCompression's default protected set (src/compress.ts:356, enforced as hard backstop by applySingleRange) and the recommend node (src/compress.ts:946). Rejection path and recommendation path therefore agree; no stale second path exists (grep-verified: no other isNeverPreserveRecent callers).
  • validateConfig: mirrors the existing neverPreserveRecentTools shape check; non-string array rejected, [] tolerated as no-op — consistent with the documented "NOT protect-everything" semantics.
  • Contracts (§7.3): untouched — no wire-format, state-schema, ref-semantics, pipeline-ordering, or default-value changes. This is a pure opt-in config addition.
  • Documented edge (not a bug): preserve patterns match list entries via matchToolPattern (glob-suffix). Exact "read" removes only the exact entry read; an explicit list containing "read*" would need preserveRecentTools:["read*"]. Consistent with the existing pattern semantics and the PR docs.

③ Code

Clean. Per-message base.filter(...) allocation over a ≤N-entry list is negligible. src/recommend.ts:86 is 106 chars — consistent with the repo's de facto line lengths (repo has no prettier config and CI does not run format:check; my local format:check flags 251 pre-existing files on default settings, unrelated to this PR). No as any / @ts-ignore.

④ Test validity

The 5 new tests have teeth and pin both directions: default keeps fresh read compressible while ["read"] protects it; bash stays excluded (per-tool subtraction); explicit-list combination; glob/no-match/[] are no-ops; e2e applyCompression refusal with /protected/i; validateConfig shape + [] tolerance. Reverting the subtraction or making [] protect-everything would fail them.

⑤ Diff cleanliness — one issue found, fixed on the branch

The feature commit had committed an unrelated 475 KB acp-kernel-0.0.91.tgz (a local npm pack artifact, stale — master is at v0.0.92; CI generates its own tarballs via pr-artifact.yml). Fixed directly on the branch as two labeled commits:

Verification

  • Local: typecheck clean; full suite 1120/1120 pass (matches the stated preflight).
  • CI on new head d54835b: test (22) ✅, test (24) ✅, build-artifact ✅, pr-validation ✅.

Verdict: mergeable once you merge it — per repo rules the merge itself is human-only: #428

中文摘要:审核了 preserveRecentTools 正向覆盖方案——方向正确(#395 的“整表替换”陷阱属实),默认行为完全保持(unset/[] 纯 no-op,唯一调用点及两个消费方均已透传,§7.3 契约未触碰);测试有牙、能兜底;顺手修掉了误提交进分支的 475KB tgz 打包产物并加 *.tgz gitignore(a5ff78e、d54835b);本地 1120/1120 全绿、新 head CI 四项全过,可以合并。

@ranxianglei
ranxianglei merged commit faf1ba1 into master Sep 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant