Skip to content

feat: acp_rule delete/clear — wire kernel removeRule/clearRules (#1177) - #1178

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-23_rule-delete
Sep 25, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-23_rule-delete

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #1177

What changed

Wires acp_rule to acp-kernel 0.0.84's removeRule/clearRules, so recorded rules can be removed instead of staying permanent (or being hedged with counter-rules).

  • src/compress-tool.ts: the acp_rule schema gains two optional params — delete: "ruleN" (remove one by id) and clear: true (remove all) — plus description sentences so the model can discover the capability. All four wire shapes (anthropic/openai/responses/google) share the one definition.
  • src/rules-feature.ts (executeRule, shared by both proxy mode and plugin mode): dispatches to removeRule(state, id) / clearRules(state); unknown ids pass the kernel error through verbatim; mixing operations in one call returns an explicit conflict message without mutating state; non-string delete / non-true clear are ignored (same convention as non-string rule).
  • Tests: 5 new cases in tests/rules.test.ts (delete-by-id + returned text, id trim + unknown-id passthrough, clear count + honest empty clear, pairwise mutual exclusivity + no state mutation on conflict, schema documents rule/delete/clear on all four wire shapes) + the loop-routing test extended to cover delete through executeProxyTool.
  • Docs: README + CONFIGURATION (en/zh) describe the two new operations and the version requirement.

Behavior change (old → new)

  • Old: acp_rule accepted only optional rule; once written, a rule could never be removed.
  • New: two new optional params. Success strings: Removed ruleN: <text> and Cleared N rule(s).; clearing with nothing recorded answers No rules to clear. (honest, no false success). Default behavior is otherwise byte-identical: no args = list, rule = record. The tool description string is extended (visible to models only when compress.rules: true).
  • Dependency note: delete/clear need acp-kernel >= 0.0.84; master already pins exactly 0.0.84 (PR chore: bump acp-kernel 0.0.82 -> 0.0.84 #1175), so this PR bumps no dependency. CONFIGURATION.md now states ">= 0.0.70 (>= 0.0.84 for delete/clear)".

Pre-flight (on this branch head)

  • npm run typecheck ✅
  • npm test ✅ 2321 pass / 0 fail (2 skipped = e2e gated off by default)
  • npm run build ✅ (tsup; new strings verified present in dist/index.js)
  • E2E_CHECK=1 node --import tsx --test tests/e2e/e2e-codex.test.ts ✅ (zero-token preflight). Full 4-phase e2e needs the upstream at 127.0.0.1:8199, which is not reachable from this sandbox — the changed path sits behind the default-off compress.rules gate and is covered by the HTTP-level wire tests on all three native-tool wires. The manual-dispatch CI e2e can run it if desired.

Minor nit (out of scope, belongs to acp-kernel)

The kernel 0.0.84 not-found message reads …list current rules first (omit the text argument). while the param is named rule, not "text". Cosmetic wording only; we pass it through verbatim.

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-23_rule-delete (fd2a2da)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1178

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1178.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Reviewed PR #1178 (head f1c2eb23, base = current master — fresh base, no rebase needed).

Diff cleanliness. Single commit, 7 files, +90/−9, every line serves the PR's purpose (schema + dispatch + tests + en/zh doc parity). No unrelated files, no whitespace churn, no lock-file drift, version untouched. Dependency claim verified: master pins acp-kernel exactly 0.0.84 (package.json + lockfile in sync), so the PR bumps nothing.

Code review.

  • Kernel contract checked against the installed acp-kernel 0.0.84 typings: removeRule(state, id) → {ok:true, rule} | {ok:false, error}, clearRules(state) → {ok:true, count} — usage in src/rules-feature.ts matches both. allocateRuleId is documented monotonic (never re-issued after removal), so there is no id-reuse hazard under the kernel's never-reuse contract.
  • Both modes genuinely share the path: the proxy-mode compress loop (src/loop/core.ts:185-187) and the plugin endpoint (src/plugin.ts:797) both route through executeProxyTool → executeRule; the plugin endpoint passes the JSON-body args object verbatim, so delete/clear behave identically in both modes. Client-side extensions pick up the new schema automatically because all four wire shapes derive from the one definition in src/compress-tool.ts served by the proxy manifest.
  • Edge cases hold: whitespace-only delete is ignored; clear: false is ignored (same convention as non-string rule); a conflicting multi-op call returns before any mutation — the test asserts state is untouched.
  • Persistence: src/persist.ts:158 round-trips state.rules, so removals/clears survive restart as the docs claim. Logging goes through ctx.log/loggerLog, no console.error.

Regression review — existing behaviors on touched paths, each dispositioned:

  1. Default config (compress.rules off): acp_rule is never injected or advertised → byte-identical behavior for default users. Preserved.
  2. Rules on, old call shapes: no-arg → list, {rule} → record, non-string rule → list. Same code paths, pre-existing tests still green. Preserved.
  3. Tool definition on the wire when rules are on: description extended + two new optional params. Intentional feature change, disclosed in the PR body's behavior-change section; visible to models only behind the opt-in gate, stable within a session (no prefix-cache churn beyond the one-time release bump).
  4. Unknown-id delete passes the kernel error through verbatim — consistent with the existing addRule error-passthrough convention. Consistent.
  5. Persistence format: no new fields; the rules array was already serialized. No format/version change.
  6. Nothing touches src/update.ts, session binding, MITM/CA, or wire protocol shape beyond the injected tool definition itself. Untouched.

Verification (re-ran on branch head f1c2eb23):

  • npm run typecheck ✅
  • npm test ✅ 2323 tests / 2321 pass / 0 fail / 2 skipped (e2e gated off by default)
  • npm run build ✅; new strings (No rules to clear., Use one operation per call) confirmed present in dist/index.js
  • GitHub CI on head: all green (test ubuntu/windows × node 22/24, build-artifact, version-guard, e2e zero-token preflight)

Minor nit (acknowledged, left out of scope): the kernel 0.0.84 not-found message says "…(omit the text argument)" while the param is named rule. Cosmetic wording that belongs to acp-kernel; we pass it through verbatim. It's already flagged in the PR body, so I'm leaving it there rather than filing a separate issue for a one-word fix.

Verdict: mergeable.

中文摘要:审查了 acp_rule 新增 delete/clear 功能的 PR——内核 API 契约、双模式执行路径、持久化与既有行为回归面逐项核实无误,本地复跑 typecheck/test/build 全绿、CI 全绿,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Rebase conflict vs master resolved (head fd2a2da) — docs union, no code changes:

  • CONFIGURATION.md / CONFIGURATION.zh-CN.md rules section: kept both sides — this PR's delete/clear sentences + master's /acp-rule human-command sentence (/acp-rule 命令人可以直接调用 #1251), and on the EN side master's dsh acp rule报错 #1192 manifest wording (only while enabled) which postdates the branch base.
  • src/compress-tool.ts, src/rules-feature.ts, tests/rules.test.ts auto-merged cleanly; verified the merged tool description/schema still carries delete/clear and the manifest gating is master's current behavior.
  • Gates on the merged tree: typecheck ✓ / rules 17/17 + absorb 29/29 ✓ / build ✓.

(Wrongly-pushed stray branch 2026-09-22_rule-delete-clear deleted; PR head is 2026-09-23_rule-delete @ fd2a2da, mergeable: True.)

@ranxianglei
ranxianglei merged commit db50552 into master Sep 25, 2026
9 checks passed
antclt pushed a commit to antclt/billion-context that referenced this pull request Sep 27, 2026
…xianglei#1399)

诉求 1 — compress.rules defaults ON (owner decision: the model owns session rules):
- rulesEnabled(): absent block now means enabled; only explicit false disables
- new effectiveRulesEnabled() for the session-level plugin-tool paths
  (loop/core executeProxyTool, absorb isProxyToolFor, plugin tool allowlist)
- kernel needs no change: acp_rule is unconditionally protected there

诉求 2 — human-side parity: pi/omp /acp-rule now forwards the full op set:
- bare = list, text = record (unchanged)
- 'remove <id>' -> { delete: id }; bare 'remove' warns with usage, no forward
- bare 'clear' -> { clear: true }; 'clear <text>' records (typo guard)

Docs en+zh: rules default line + migration note, /acp-rule usage incl.
remove/clear, stale 'ranxianglei#1178' claim removed. Tests: default-on expectations
flipped at every gate site, new forwarding/regression cases, wire-contract
ledger + manifest-default golden regenerated via scripts/update-wire-contract-goldens.ts.
@ranxianglei
ranxianglei deleted the 2026-09-23_rule-delete branch October 15, 2026 05:32
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.

acp_rule 工具请接线 kernel 0.0.84 的 removeRule/clearRules,支持删除规则

1 participant