Skip to content

feat: /acp-rule command — human entry point for recorded acp_rule rules (#1251) - #1259

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-24_acp-rule-command
Sep 24, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-24_acp-rule-command

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #1251

What

acp_rule (persistent principle-level reminders) was only reachable by the model. Humans had no way to see what instructions the model had actually recorded ("现在看不到模型到底记录了啥指令"). This adds /acp-rule — the human entry point — mirroring the established /acp-cache seam (#1146):

  • pi/omp (shared factory src/agent/pi.ts, so both launcher and native lanes are covered by one registration): bare /acp-rule lists every recorded rule verbatim (identical output to the acp_rule tool's list); /acp-rule <text> records one directly, as if the model had called it.
  • Output is persisted to the transcript via sendMessage (customType: "bili-acp-rule") with a notify fallback for hosts without it — and the proxy strips the wrapped message from model context by content signature (src/acp-panel.ts: new [acp-rule]/[/acp-rule] markers added to isAcpPanelText, whole-message anchored like the cache report). The recorded rules themselves already reach the model every turn via formatRulesForPrompt system-prompt injection, so the human-facing echo never duplicates into context.
  • When the feature is off in the session's effective config, the proxy's dsh acp rule报错 #1192 note channel (disabledOptionalToolNote) is converted into a friendly enablement hint (compress.rules.enabled: true) instead of echoing the model-facing note.

Deliberately not in this PR

Behavior-change disclosure

Pure additive: one new slash command on pi/omp + two new strip markers. No past behavior changes — isAcpPanelText gains recognition of a brand-new marker pair that no existing content can contain; all pre-existing strip/wire/config behavior is untouched.

Pre-flight (rebased head)

  • npm run typecheck — clean
  • npm test — 2456 pass / 3 fail; the 3 failures are in tests/claude-native.test.ts (spawned-fake-claude e2e/watchdog tests) and were verified to fail identically on clean master in this sandbox (environment-dependent, unrelated to this change)
  • npm run build — success

Tests added: 4 command-behavior tests in tests/plugin-agent.test.ts (list forwarding, record forwarding with trimmed args, notify fallback, disabled-feature hint) + 7 wrapper/strip tests in tests/acp-panel.test.ts (detection, suffix/follow-up rejection, whitespace tolerance, marker-quoting rejection, message + Responses-input stripping).

Docs: README en/zh (status section) + CONFIGURATION en/zh (pi/omp launcher bullets, plugin-install summary, compress.rules section).

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-24_acp-rule-command (730b1fc)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1259

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1259.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] 🏷 收到,这是我在 #1251 里实现的 PR,现在按 PR Review 规范做一轮完整审查(方向 / 回归 / 代码 / 测试有效性 / diff 整洁度),并核对 CI 状态。结论稍后贴在本线程。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Full review complete (per PR规范, reviewed on the rebased head 730b1fc3). Verdict: ready to merge — CI is fully green and local pre-flight reproduces green. Details below.

① Issue direction (#1251)

The issue asks for the missing human entry point to the persistent-rules feature ("现在看不到模型到底记录了啥指令"). This PR addresses the root gap — the feature was only reachable by the model — by reusing the established /acp-cache seam rather than inventing a new surface. Direction is correct; the scoping decisions (delete/clear deferred to #1178 because master's executeRule ignores unknown params and would silently degrade to a list; other lanes deferred to follow-up) are right, and I verified the degradation claim directly in src/rules-feature.ts:45-61.

② Regression audit (existing behaviors on the touched paths)

  • isAcpPanelText (src/acp-panel.ts) — gains recognition of a brand-new, whole-message-anchored marker pair [acp-rule]/[/acp-rule] (same scheme as isCacheReport). No existing content can contain this pair (no prior producer), so pre-existing strip behavior is byte-for-byte unchanged. All call sites untouched: server.ts:2464/:2648 (stripAcpPanelMessages), server.ts:3088 (stripAcpPanelResponsesInput), fork-adoption.ts:80.
  • src/agent/pi.ts — purely additive registration inside the existing registerCommand guard block alongside /acp (:388) and /acp-cache (:451); neither handler nor any tool registration modified.
  • Rules engine, config schema, persistence format, wire shapes: untouched. The customType: "bili-acp-rule" transcript message is host-side only.
  • Both compression modes (§6): the command exists only on pi/omp (plugin-mode hosts); the strip is per-request and mode-agnostic; acp_summary/tool-call carriers unaffected. Recorded rules still reach the model via formatRulesForPrompt system-prompt injection — the human echo never duplicates into context.
  • No regressions found. The "purely additive" disclosure holds.

③ Code review — key contracts verified

  • Disabled-feature hint: plugin checks text.startsWith("acp_rule is not enabled"); the proxy's disabledOptionalToolNote (src/plugin.ts:608) returns exactly that prefix for RULE_TOOL_NAME, and the isProxyToolFor gate answers the note before executeRule can run. I closed the last false-positive edge: when the feature is ON, no executeRule output can carry that prefix — add results start with Recorded …, and the kernel's formatRulesList (acp-kernel dist/index.js:6559) renders lines as N. [<id>] <text>, i.e. always starts with a digit. Safe.
  • Lane-sharing claim confirmed: createBiliPlugin is the single factory behind pi.ts:656, pi-native.ts:135, omp.ts:3, omp-native.ts:72 — one registration covers all four pi/omp lanes.
  • Error/fallback paths: fetch failure → error notify; sendMessage unavailable or throwing → falls back to plain notify (no silent loss). The one console.error in the fallback is in an agent-side file (runs in the host process, exempt from the server-module rule; consistent with the file's existing 15).

④ Test validity

The 11 new tests have teeth: they drive the real command handler against a real HTTP fake proxy and assert the exact forwarded {tool, args} (including the trim behavior), the exact fallback notify text, the disabled-hint warning count and zero sendMessage calls (pins the note-text contract end-to-end), plus strip-boundary cases (suffix/follow-up rejection, whitespace tolerance, marker-quoting rejection, both wire shapes). A regression in forwarding, trimming, anchoring, or the note wording would be caught.

⑤ Diff cleanliness

8 files, +260/−12, single linear commit on the current master tip (a1b4b471, 0 behind). Every line serves the feature: command + strip markers + tests + en/zh-synced docs (CONFIGURATION + README, verified in sync). No lock-file churn, no version bump, no whitespace noise.

Evidence

  • Local (rebased head): typecheck clean · build success · npm test 2456 pass / 3 fail / 2 skipped. The 3 fails are the spawned-fake-claude e2e/watchdog tests in tests/claude-native.test.ts — I reproduced them identically on clean master in this sandbox (same 3 names), confirming the PR's environment-dependent claim. All 11 new tests pass locally.
  • CI (730b1fc3): all 9 check runs success — test matrix ubuntu-latest 22/24 + windows-latest 22/24, build-artifact, version-guard, and both zero-token e2e lanes.

One-line summary: 本 PR 为持久指令功能补齐了人侧入口(pi/omp 的 /acp-rule),方向正确、纯增量无回归,本地与 CI 全绿(3 个失败为本沙箱预存的环境问题,与改动无关),可以合并。

(Merge stays yours — I don't merge PRs.)

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 命令人可以直接调用

1 participant