Skip to content

feat: protectedLatestTools — protect only the latest instance of a tool - #223

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-09_protected-latest-tools
Open

feat: protectedLatestTools — protect only the latest instance of a tool#223
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-09_protected-latest-tools

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem

Cumulative-snapshot tools (e.g. todo_list) keep their full state in the newest result — every older result is strictly redundant. The existing mechanisms can't express "protect only the latest instance":

  • protectedTools over-protects: all instances are BLOCKED forever, so stale snapshots accumulate and are never compressed.
  • preserveRecentMessages under-protects: N must be large enough to always span back to the newest instance.

Requested by ranxianglei/billion-context#637 (todo continuity: protect, don't recall-after-compression; only the latest todo message needs protection).

Change

New Config.protectedLatestTools (optional, string[], glob patterns via the existing matchToolPattern): for each pattern, only the LAST matching tool-call (message order) and its paired tool-result are protected from compression; older instances remain compressible.

  • Superseded pairs keep their BLOCKED ref (refs are never re-issued) but become foldable at apply time, because apply-time protection is re-checked against the current config. Verified by test.
  • Wired into every protection site so recommend/apply/absorb agree:
    • assignRefsNode — latest pair gets BLOCKED ref (never citable as a boundary)
    • filterProtectedToolMessages — latest pair excluded from a block's directMessageIds and effectiveMessageIds (Bug 39 semantics: protected msgs must not be hidden by block coverage)
    • buildCompressibleRanges — latest pair shows up in the protected ranges (nudge display)
    • isAbsorbCandidate / appendAbsorbPrompts / applyAbsorb — latest-protected results are not absorbable
  • isAbsorbCandidate gains an optional third param (latest?: LatestProtected) — existing 2-arg call sites are unaffected.
  • Field is optional on Config (default [] in defaultConfig) so hosts building Config literals don't break.

New exports: collectLatestProtected, isMessageLatestProtected, type LatestProtected (from protected.js + index).

Pre-flight

  • npm run typecheck: PASS
  • npm test: 637/637 (624 existing + 13 new in tests/protected-latest.test.ts: latest-pair selection incl. glob + no-toolCallId, BLOCKED-ref assignment, range-apply exclusion vs older-pair folding, superseded-pair folding, hard-vs-soft contrast, recommendation split, absorb reject/accept)
  • npm run build: PASS

Refs ranxianglei/billion-context#637

Cumulative-snapshot tools (e.g. todo_list) keep their full state in the newest result, so every older result is strictly redundant. protectedTools over-protects them (all instances BLOCKED forever); preserveRecentMessages under-protects (N must span far enough back).

New Config.protectedLatestTools (optional, glob patterns): for each pattern, only the LAST matching tool-call and its paired tool-result are protected from compression; older instances stay compressible. Superseded pairs keep their BLOCKED ref (never re-issued) but become foldable at apply time, since apply-time protection is re-checked against the current config.

Wired into all protection sites: assignRefsNode (BLOCKED ref), filterProtectedToolMessages (range-apply exclusion), buildCompressibleRanges (recommendation), isAbsorbCandidate/appendAbsorbPrompts/applyAbsorb (absorb).

Pre-flight: typecheck PASS; 637/637 tests (624 existing + 13 new in tests/protected-latest.test.ts); build PASS.
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

📦 Built Package Artifact

Branch: 2026-09-09_protected-latest-tools (4abf11a)

Option A — Install from npm PR tag (recommended)

In your adapter project:

npm install acp-kernel@pr-223

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

Option B — Download artifact

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

This comment is automatically updated on each push.

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