Skip to content

feat(#537): /acp-rule remove <id> and clear operations - #538

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-25_acp-rule-remove-clear
Sep 25, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-25_acp-rule-remove-clear

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

Ports the rule delete/clear wiring from bili ranxianglei/billion-context#1178 (issue #1177) onto this repo's human surface: the /acp-rule command. The model-side acp_rule tool (#490) stays out of scope per the issue.

Kernel removeRule/clearRules have been exported since acp-kernel 0.0.84; this repo pins 0.0.86 — no pin bump.

Behavior

New argument parsing in src/commands.ts (parseRuleCommand):

Invocation Action
/acp-rule list (unchanged)
/acp-rule <text> record (unchanged)
/acp-rule remove <id> removeRule(state, id) → save → echo Removed ruleN: <text>
/acp-rule clear clearRules(state) → save → echo Cleared N rule(s). / No rules to clear. when empty

Discrimination (per issue constraint — plain text that merely starts with these words must stay recordable):

  • clear only fires on the exact single-token arg clear
  • remove only fires on exactly two tokens where the second matches ^rule\d+$
  • everything else records verbatim — removing old logs nightly, record a rule about removing things, etc. all still record
  • one operation per invocation: mixed ops (remove rule1 clear), repeated clears, or repeated removes are rejected with an explicit error before any mutation, no state touched

Unchanged by design:

  • the runtime.adapter.rules !== true gate fires first, as before
  • success/error echoes go through the same ACP_RULE_CUSTOM_TYPE path (src/messages.ts:40 excludes it from context) — TUI-only, zero wire bytes change
  • kernel validation errors (e.g. unknown id: no rule with id "rule99" — list current rules first…) surface verbatim, same as the record path

Command description string updated to cover all four ops.

Tests

5 new tests in tests/rule-command.test.ts covering every acceptance item:

  1. record→remove-by-id: ok path, sidecar emptied, subsequent list shows none
  2. remove with unknown id: kernel error surfaced verbatim, state unmutated
  3. record×2→clear: count reported; second clear honestly reports No rules to clear.
  4. mixed/repeated ops rejected without executing or recording
  5. plain text starting with remove/clear-like words still records (4 variants)

Plus extended the existing off-gate test: remove/clear now also hit the enablement warning.

Verification

  • npm run typecheck ✅
  • full suite vs pristine-master baseline: identical results except the 5 new tests (see env note below)
  • with writable temp dir: tests/rule-command.test.ts 11/11 pass
  • npm run build ✅; new strings verified present in dist/index.js

Env note (sandbox artifact, not a code issue)

This agent sandbox mounts /tmp read-only, so the committed test files' hardcoded /tmp/pai-acp-rule-* sidecar paths raise EACCES here. Baseline run of pristine master in the same environment fails 94/935 tests for exactly this reason; my branch fails those same 94 plus the 5 new ones — zero new regressions. With the sidecar paths pointed at a writable dir, all 11 rule-command tests pass. CI (writable /tmp) will run them normally.

Behavior change disclosure

/acp-rule gains two new invocation syntaxes (remove <id>, clear). Existing list (no args) and record (text) behavior is byte-identical — the discriminator only intercepts the exact token patterns above. No config, persistence-format, or wire changes.

Closes #537

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Extension Artifact

Branch: 2026-09-25_acp-rule-remove-clear (5c76571)

Option A — Install from npm PR tag (recommended)

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

Each push to this PR publishes a new version under the pr-538 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-pr538.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] 🏷 Reviewing PR #538 (/acp-rule remove <id> / clear) now — pulling branch 2026-09-25_acp-rule-remove-clear, checking original issue #537, diff, tests and CI. Will report conclusions shortly.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review of PR #538 — verdict: mergeable ✅

Reviewed branch 2026-09-25_acp-rule-remove-clear (5c76571, single commit, +161/−8 across 3 files) against current master fd8095e.

① Original issue (#537) — direction check

#537 is a well-scoped port request with explicit acceptance criteria and red lines (no wire bytes change, no pin bump, gate unchanged, TUI-only echo, description update). The PR implements exactly that scope: model-side acp_rule tool correctly left out (#490), kernel pin stays at 0.0.86 (verified in package.json). Direction is right; this is a wiring task done on the right surface.

② Regression review — existing behaviors audited on /acp-rule (src/commands.ts)

Read the pre-change handler and traced each path through the diff:

  1. No-arg list — identical code path (listRules/formatRulesList, same strings). Preserved ✅
  2. Text record — same trim → addRule(state, text, resolveRuleLimits(...)) → same echo. Only intercepted when the arg is exactly the single token clear, or exactly two tokens matching remove ruleN (^rule\d+$). Every other input records byte-identically. Preserved except the two intentionally-disclosed new syntaxes ✅
  3. Rules enablement gate — still fires first, before parsing; message unchanged. The extended off-gate test proves remove/clear also hit it ✅
  4. Echo/wire path — all four success branches converge on the same tail (pi.sendMessage({customType: ACP_RULE_CUSTOM_TYPE,...}) / notify fallback); src/messages.ts untouched by this diff, so the CONTEXT_EXCLUDED_CUSTOM_TYPES exclusion stands — zero wire bytes change holds ✅
  5. Error handling — failed remove surfaces the kernel error verbatim via notify(error, "error") with no save (state unmutated, test asserts sidecar intact) — consistent with the existing record-path convention ✅
  6. Sidecar format / persistence — untouched; mutations go through kernel removeRule/clearRules + existing runtime.save ✅

Intentional behavior change (confirmed disclosed): bare /acp-rule clear and exact /acp-rule remove ruleN are now intercepted instead of recorded as rule text. This is precisely the discriminator #537 requested ("a leading literal remove / bare clear token is the discriminator"), and it's stated in the PR's Behavior change disclosure. OK.

Edge cases checked in code: conflict condition precedence is correct ((clear>0 && remove>0) || clear>1 || remove>1); mixed/repeated ops are rejected before stateFor — i.e. before any state load, stronger than "before mutation"; clear x, Remove rule1 (case-sensitive), x remove rule1 y all fall through to verbatim recording (safe, no mutation); double-space remove rule1 normalizes to the two-token form (reasonable). One non-blocking nit: an empty clear still calls runtime.save on unmutated state — harmless idempotent atomic rewrite, not worth fixing or filing.

③ Code review

Clean. No as any/@ts-ignore; tokens[1]! is guarded by the length check. Kernel API usage matches acp-kernel 0.0.86 exports (verified removeRule/clearRules in the installed node_modules/acp-kernel/dist types). The doc comment on parseRuleCommand justifies itself given the discriminator subtlety.

④ Test validity

The 5 new tests have teeth: exact echo strings, sidecar file read back from disk and asserted deepEqual [], state-unmutated assertions after failed/rejected ops, verbatim kernel error string, 4 plain-text variants starting with remove/clear-like words. Not tautologies — each would fire if the corresponding behavior regressed. Hardcoded /tmp/pai-acp-rule-* follows the file's existing convention; CI has a writable /tmp.

⑤ Diff cleanliness

3 files, every line relevant to the feature; src/config.ts is a doc-comment-only update. No lockfile churn, no version bump, no unrelated files. Clean.

My independent verification (re-ran, didn't take claims on faith)

  • npm run typecheck ✅ · npm run build ✅ (all 3 new echo strings present in dist/index.js)
  • tests/rule-command.test.ts: 11/11 pass locally (sidecar paths pointed at a writable dir, per the env note)
  • Base = current master fd8095e; CI on the branch: all runs green; PR mergeable (no conflicts), blocked only by normal merge gating

中文摘要:审查了 PR #538(/acp-rule 增加 remove / clear 操作)——方向与 issue #537 完全一致,既有行为(list/record/门控/TUI-only 回显/sidecar)逐项核对均无回归,两处新语法拦截属已披露的有意变更且正是 issue 要求的判别方式;本地独立复跑 typecheck/build 绿、rule-command 测试 11/11 通过、CI 全绿、基线为当前 master,可以合并。

@ranxianglei ranxianglei mentioned this pull request Sep 25, 2026
@ranxianglei
ranxianglei merged commit 4817090 into master Sep 25, 2026
9 checks passed
ranxianglei added a commit that referenced this pull request Sep 25, 2026
#545)

rule-command.test.ts (#538 extension) and fork-host-stopgap.test.ts
(#533) landed after the last sweep: 5+2 real write paths back on
hardcoded /tmp. Same conversion as the rest of the suite.
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.

[Enhancement] /acp-rule: add remove/clear operations (port billion-context #1178 delete/clear wiring)

1 participant