Repository navigation
feat: tool-result valuator + deterministic crush plugin interface (two-tier absorb gate) - #359
Conversation
…o-tier absorb gate)
1d92a7f to
b8c17c2
Compare
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)In your adapter project: npm install acp-kernel@pr-359Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf acp-kernel-pr359.tgz
npm install ./packageThis comment is automatically updated on each push. |
…nt misparse, plugin fail-open hardening
[bot] 🏷 Review complete — PR #359 (tool-result valuator + deterministic crush plugin interface) TL;DR: Rebased onto current master (v0.0.82), fixed two blocking correctness bugs found in review plus hardcoded plugin fail-open paths, everything green. Mergeable from my side — merge is yours to do. What I did
Bugs found & fixed in review (commit
|
| Touched path | Existing behavior | Verdict |
|---|---|---|
Pipeline shape (src/compress.ts) |
canonical node sequence | Intentional change (disclosed): new crush node between absorb-hide and absorb-prompt; canonical list updated in tests/pipeline.test.ts (11→12). Gated off by default. This is §7.3 contract #8 territory → human-gated merge regardless. |
Default run (crush.enabled: false) |
byte-identical output | Preserved — PR's own off-by-default test + full suite green. |
src/config.ts validation |
rules validation (from master) | Preserved verbatim; crush validation purely additive. |
src/index.ts exports |
rules exports (from master) | Preserved; crush exports additive. |
src/types.ts |
TerminalEscapeSignal / RuleRecord / RulesConfig | Preserved; Config gains optional crush? (back-compat). |
| Absorb gates | minToolTokens / contextThresholdPct semantics |
Untouched — crush re-evaluates in-view only, no persisted-state mutation (NodeEffects only). |
| Wire format / nudge invariants / protected-tool filtering | — | No diff in those paths. |
| Docs | AGENTS.md module map, README pipeline section | Accurate after the B5 fix. Nit: AGENTS.md §7.3(8) still says "the canonical 9-node sequence" — already stale pre-PR (actual count was 11), now 12. |
| Formatting | format:check |
Pre-existing repo-wide failure (AGENTS.md/README.md fail on plain master too); PR-touched source files pass locally. |
Diff cleanliness: every hunk maps to the stated scope (valuator, plugin interface, 3 built-in strategies, node wiring, config, exports, docs, tests). No generated-file churn, no mass whitespace/reformatting.
Unfixed nits (follow-up candidates, none blocking)
- Unreachable
triple-midbranch infindCommentOrTriple(the quote toggle consumes the first quote first). normalizeForDedupe: the\d+→N pass runs before0x…→ADDR, making the latter mostly dead.evaluateToolResultignorescrush.enabled(direct-API footgun; doc line candidate).- Missing edge tests: exact minReduction boundary, unicode / empty-array round-trips, >2M cap bail-out, template-literal bail-out.
- Duplicate-id plugin registration silently shadows built-ins — consider rejecting or warning.
- Module-global registry is shared across cores in one process.
- Lossy strategies normalize CRLF→LF (acceptable for log/code trimming, worth a doc note).
- Scalar JSON / bash scripts fall into the
logstrategy by kind fallback.
Verdict
Two blocking correctness bugs found and fixed on the branch, base brought current, CI green on c6dd2bf. This is a feat that adds a pipeline node (§7.3 #8), so it stays human-gated either way — but from my side it is mergeable. Per repo rules I can't merge PRs; please merge yourself: #359
中文摘要: 审查了 PR #359(crush 估值器 + 插件接口):发现并直接修复了两个阻塞级正确性 bug(json-fold 常量提升会静默丢失「首行缺失但其余行为 null」的字段、code-trim 把含 /* 的 JS 正则字面量误判为注释开头导致真实代码行被裁掉),外加插件契约违规的 fail-open 加固和 README 措辞修正,并把分支 rebase 到最新 master(v0.0.82,冲突均为纯增量、按并集解决);本地 915/915 测试通过、新 head CI 全绿,功能默认关闭且关闭时输出与改动前逐字节一致——可以合并。
Closes #354
Implements the kernel side of the two-tier absorb gate per the ruling on billion-context#1094: valuation in the kernel, compression as an open plugin interface with kernel defaults, kernel first. Phases 1+2 of the issue; phase 3 (retrieve-time application) waits on billion-context#1097's store and reuses the same registry as a second call site.
What lands
Valuator (
evaluateToolResult, pure + deterministic): for each absorb-candidate tool result under context pressure, decidesskip(belowabsorb.minToolTokensor underabsorb.contextThresholdPct) /crushed(deterministic compression brought it under threshold — no model round-trip) /distill(still over, or uncrushable — forwarded to the[ACP absorb]prompt path, carrying the crushed payload when crushing succeeded). ReusesdefaultCountTokens+ the absorb gates; adds aminReductionfloor (default 0.1). Same payload + config ⇒ same bytes (prefix-cache friendly).Plugin interface: narrow sync contract
(text, meta) => { text, lossy, stats? } | null; null = pass-through. Ordered registry (registerCrushPlugin/unregisterCrushPlugin/listCrushPlugins/resetCrushPlugins), hosts can add/replace/disable; per-strategy toggles +excludeToolsvia config. Kernel-enforced guarantees: dispatch guards keep json/code/log payloads on their own strategies; any throw, sub-minReductionresult, or invariant violation fails open to the next candidate or pass-through.Built-in strategies:
json-fold(lossless): constant-field hoisting + identical row/run collapse into annotated envelopes, decodable byte-for-byte.code-trim(lossy): comment/docstring elision behind a string-literal-aware scanner; template literals and assigned triple-quoted strings survive verbatim; unterminated constructs fail open.log-select(lossy): level-classified line selection; warnings deduped; runtime stack frames collapsed; honest[N lines omitted]footer instead of opaque retrieval hashes.Pipeline: new
crushnode betweenabsorb-hideandabsorb-prompt, so the absorb-prompt decision runs on post-crush sizes atomically in the same turn (a stale[ACP absorb]marker is stripped and re-decided). View-only per-turn recomputation — no persisted-state mutation; effects reported via NodeEffects only.Config: new top-level
config.crushblock{ enabled, minReduction, strategies? }resolved + validated through the existing path (defaultConfig,validateConfig). No wire-shape change beyond tool-result text itself; zero new runtime dependencies.Behavior changes (old → new)
crush.enabled: false, and requiresabsorb.enabled: true). With it off, pipeline output is byte-identical to before — verified by test. No host behavior changes until explicitly opted in.crushbetweenabsorb-hideandabsorb-prompt(inert unless both switches are on); canonical node list grows from 11 to 12 (pipeline order test updated accordingly).LOG_MAX_ERRORS: 10 → 20, plus a strict invariant: every distinct ERROR/FAIL line must survive verbatim in lossy log output or the result is rejected (fail-open to pass-through). The prototype could silently drop middle errors beyond its budget of 10; the kernel never will. Logs with >20 distinct errors fail open rather than drop any.__pre_crush/[pre-crush: …]→__acp_crush/[acp-crush: …](kernel-owned naming).config.crush(block-shaped likeabsorb), not nested underabsorb.preCrushas in the host-side prototype.Verification
npm run typecheckclean;npm test807/807 (was 766; +41 new tests intests/crush.test.tscovering lossless round-trips, determinism, dispatch guards, fail-open paths, the error-line invariant, registry semantics, all three valuator decisions, per-strategy disable/excludeTools, stale-marker stripping, and processTurn integration incl. byte-identical-when-off);npm run buildclean.format:checkrepo-wide failure is pre-existing on master (untouched files included) and not gated by CI here.