Skip to content

feat(rules): acp_rule tool gains delete/clear; document /acp-rule command - #557

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-26_acp-rule-crud
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-09-26_acp-rule-crud

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #555

What changed

Model tool — full rule rights (src/rule-tool.ts)

  • acp_rule now accepts delete: "ruleN" (remove one) and clear: true (remove all), alongside existing rule (record) and no-arg list.
  • Interface aligns verbatim with billion-context's executeRule (src/rules-feature.ts): one operation per call — mixed operations are rejected with Use one operation per call: record (rule), remove one (delete), remove all (clear: true), or list (no arguments). without mutating anything; kernel validation errors are returned verbatim (no throw, no FAILED marker), same as record today.
  • Tool + parameter descriptions are byte-identical to the acp_rule served by the billion-context proxy (its src/compress-tool.ts RULE_TOOL/RULE_PARAM_SCHEMA), per the cross-host hard requirement — a model trained under one host sees the same parameter shape under the other, no relearning.
  • Description teaches when to delete: stale/mistakenly recorded rules get deleted directly rather than hedged with a counter-rule (wording reused from billion-context CONFIGURATION.md).
  • Kernel side needed nothing: pinned acp-kernel already exports removeRule/clearRules.

Docs (诉求 2, en+zh synced)

  • README.md / README.zh-CN.md: new /acp-rule command section (list / <text> / remove <id> / clear, one-op-per-call, sidecar persistence, dual-registration caveat) + tool-table row updated.
  • CONFIGURATION.md / CONFIGURATION.zh-CN.md: rules table row + ### rules description rewritten for full CRUD incl. delete/clear echo texts, mutual exclusivity, unknown-id verbatim error, byte-identical-shape note, dual-registration blockquote.

Check items from the issue

  • Dual registration (bili plugin + this adapter both enabling rules): verified against pi source (@earendil-works/pi-coding-agent dist/core/extensions/loader.js + runner.js getAllRegisteredTools) — pi dedupes tools by name across extensions; first registration per name wins, later registrations silently ignored, no warning. Since the two implementations back different stores (this adapter: pi session sidecar; proxy: its own session state), which one answers depends on load order. Documented in both READMEs' new section + both CONFIGURATION files: enable rules on only one side. Note the collision can only arise from an undetectable transparent-proxy setup — when the proxy is detectable (BILLION_CONTEXT_PROXY exported or /bili/ baseURL) this adapter stands down entirely, so the two plugins never co-register there.
  • Tests (aligned with feat(#537): /acp-rule remove <id> and clear operations #538 command-side tests): one-op-per-call exclusivity (rule+delete, rule+clear, delete+clear all rejected, state intact); delete of unknown id returns kernel error verbatim (no rule with id "rule99" — list current rules first…); clear empty store → No rules to clear.; plus delete-removes-one with sidecar assertion, clear-count, and a schema-shape test pinning the cross-host parameter contract (keys [clear, delete, rule], types, description invariants).

⚠ Behavior changes (old → new)

  1. {rule: ""} / whitespace-only input: previously returned the validation error rule text is empty — provide the reminder to record.; now falls through to list (matches executeRule semantics: empty-after-trim = list request). WHY: cross-host consistency — the bili proxy has always behaved this way, and the issue requires identical behavior under both hosts.
  2. Tool description text: replaced with the shared cross-host wording (the old pi-specific description is gone). WHY: hard requirement that the model see one identical tool under both hosts; the new wording also carries the delete guidance.
  3. Record input is pre-trimmed in the adapter before addRule. The kernel already trimmed stored text internally, so persisted data is unchanged — only the length-check/duplicate-comparison input is normalized explicitly.

Verification

  • npm run typecheck clean
  • npm test: 998 tests, 992 pass, 0 fail, 6 skipped (full suite, not just rule tests)
  • npm run build success (dist self-contained, acp-kernel still bundled inline)

No version bump (release-branch territory). No changes to load-bearing surfaces: ref-tag rendering, token calibration, host detection/stand-down, .acp.json sidecar format, update.ts, kernel pin.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Extension Artifact

Branch: 2026-09-26_acp-rule-crud (dd55307)

Option A — Install from npm PR tag (recommended)

pi install npm:billion-context-pi@pr-557

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pi-pr557.tgz
pi install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,开始按 PR Review 规范审查本 PR(分支 2026-09-26_acp-rule-crud,基于 master 198149c)。流程:拉取分支核对代码 → 对照原 issue #555 的方向与检查项 → 回归清点 → 本地最小验证(typecheck/test/build)→ 交叉比对 billion-context 的 executeRule/RULE_TOOL_SCHEMA 逐字节一致声明 → CI 状态。结论稍后回帖。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — all checks pass, ready for human merge. (Note: this PR is my own earlier work per #555 floor 4; reviewed it with fresh eyes as an external reviewer would.)

① Issue direction (#555) — correct. The issue was a human decision to give models full CRUD over acp_rule and document /acp-rule; this PR implements exactly that scope (delete/clear ops + docs), completing the deliberately minimal record/list scope from #433. Not a surface fix. Both check items are done: interface alignment with bili and kernel availability.

② Regression review — existing behaviors touched by the diff, each audited:

Existing behavior Verdict
No-arg list (No rules recorded. / formatted list) Unchanged; tests preserved
Record path (Recorded ruleN: … echo) Unchanged; input now pre-trimmed — kernel already trimmed stored text, so persisted data is byte-identical
{rule:""} / whitespace-only Changed: validation error → falls through to list (disclosed change #1; bili parity)
Tool description text Replaced with cross-host wording (disclosed change #2)
Sidecar format (rules[] shape) Unchanged; new tests deepEqual-assert sidecar after delete/clear
/acp-rule command side Untouched by diff; separately verified its echoes match the tool verbatim (src/commands.ts:145-165) — README's "same echo" claim holds
Load-bearing surfaces (ref-tag rendering, token calibration, host detection/stand-down, update.ts, kernel pin) Untouched — diff limited to 6 files: src/rule-tool.ts, tests/rule-tool.test.ts, README en/zh, CONFIGURATION en/zh. No package.json/lockfile churn

No high-risk patterns found: error handling stays verbatim-return (no fail-fast→swallow drift); no default/threshold/timing drift beyond the three disclosed changes.

③ Code review — handleRule mirrors bili's executeRule line-for-line (verified against billion-context master src/rules-feature.ts:49-86): same trim order, same ops-count array order [delId>0, wantsClear, rule>0], same ONE_OP message, same branch order clear→delete→list→record, same echo strings. Exclusivity check runs before any mutation (state provably unmutated on rejection). Edge parity confirmed: {delete:""}/whitespace and {clear:false} fall through to list in both hosts. Kernel errors returned verbatim, never thrown.

Byte-identical claim — independently verified: cloned billion-context master and compared programmatically. Tool description: identical, 614/614 chars. All three parameter descriptions: byte-identical (pi uses single-quotes for the delete param due to embedded quotes; values identical).

Pi dedupe claim — verified against installed pi 0.83.0 (the pinned devDependency): dist/core/extensions/runner.js:281 getAllRegisteredTools() builds a Map keyed by name, first registration wins, later ones silently ignored — matches the documented caveat exactly.

④ Test validity — real tests with teeth: exact string assertions on every echo and kernel error, sidecar persistence via deepEqual, state-intact assertions after exclusivity rejection, schema-shape test pinning key set [clear, delete, rule], types, and description invariants. Deterministic (temp dir + HOME swap). The updated empty-rule assertion carries a comment citing #555. Minor non-blocking gaps: no test for {delete:""} whitespace edge or {clear:false}; schema test checks descriptions by regex rather than byte-exact (byte-exactness is a cross-repo property, covered by my external comparison above).

⑤ Diff cleanliness — clean. Every one of the 6 files serves the PR purpose; no unrelated files, no mass reformatting, no lockfile churn.

Behavior changes (re-flagged per policy):

  1. {rule:""}/whitespace-only: rule text is empty validation error → no-arg list. WHY: cross-host parity — bili treats empty rule as list (The acp_rule tool should support remove/clear (full model authority) + /acp-rule command with zero documentation. | acp_rule 工具应支持 remove/clear(模型全权)+ /acp-rule 命令零文档 #555).
  2. Tool description replaced with cross-host wording; pi-specific phrasing removed. One-time prefix-cache invalidation for opted-in users only (rules:true is default off). WHY: The acp_rule tool should support remove/clear (full model authority) + /acp-rule command with zero documentation. | acp_rule 工具应支持 remove/clear(模型全权)+ /acp-rule 命令零文档 #555 required byte-identical shape across hosts.
  3. Record input pre-trimmed before length/dup check. No persisted-data change (kernel already trimmed). WHY: consistent with delete/clear path and bili.

CI: all green on head dd55307 — e2e (ubuntu+windows), docker, build-artifact, test matrix (ubuntu22/windows24/ubuntu24/windows22), pr-validation. Local reproduction: typecheck clean, 998 tests / 992 pass / 0 fail / 6 skipped (exactly the claimed numbers), build success (dist 955.98 KB, acp-kernel inlined). Typecheck passing also proves pinned acp-kernel 0.0.94 exports removeRule/clearRules.

Auto-merge gate (§7.4): does NOT auto-merge — this is feat: (new capability surface), which must stay human regardless of green status.

Conclusion: mergeable.

中文摘要:审查了 acp_rule 增删改查补全 PR——逐项核对了既有行为(列表/记录/侧边文件/命令侧均无回归,三处行为变更均已披露旧值→新值+原因)、字节级接口对齐和 pi 同名去重说法均实测为真、测试有牙且本地复现与 PR 声称数字一致、CI 全绿;因属新功能按规范留给人工合并。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant