fix: disambiguate shared rules files via footer agent name#617
fix: disambiguate shared rules files via footer agent name#617RyanNg1403 wants to merge 2 commits intomainfrom
Conversation
When Amp / Codex / OpenCode share AGENTS.md (and Claude Code / OpenClaude share CLAUDE.md), the rules connector's status check previously reported installed:true for every agent that maps to the file as soon as the BRV markers were present. The user only installed once, but `brv connectors list` showed up to three rules entries. Read the existing `Generated by ByteRover CLI for X` footer that the template service already writes inside the BRV section, and require the extracted agent name to match the agent being queried. Footer-less files (legacy installs predating the footer) keep today's behavior so existing users are not surprised. The disambiguation lives only in the rules connector. The MCP, hook, and skill connectors do not have a shared-file collision today: the only manual-mode MCP that reads AGENTS.md content is OpenCode, and no other agent overlaps with it on that path. The new helper `extractInstalledAgentFromBrvSection` is generic and can be reused if that situation changes.
|
Claude finished @RyanNg1403's task in 3m 8s —— View job Claude PR ReviewOverall score: 4.5 / 5 — focused, well-tested, low-risk fix that aligns with project conventions. Ship-ready after considering the inline notes (none are blocking). SummaryThis PR fixes a genuine, user-visible bug ( What's good
Issues / suggestions (all non-blocking)
Out-of-scope but worth trackingThe PR description correctly flags that Correctness / security / quality
ConclusionI'd merge this. The four inline notes are polish, not gates. The 0.5 deduction is for: (1) the loose |
… descriptions - Tighten `BRV_RULE_TAG` matching to require the trailing space delimiter so a malformed footer like `Generated by ByteRover CLIforXxx` no longer matches. Add a unit test pinning the new boundary. - Rename five "returns null" test cases to "returns undefined" to match the helper's actual return type and the project's nullish convention.
|
Claude finished @RyanNg1403's task in 1m 38s —— View job Claude PR Review (follow-up: synchronize)Overall score: 4.8 / 5 — both blocking-ish items from the previous review are cleanly resolved. Ship-ready. SummaryThe new commit
What I checked
Items not addressed (both non-blocking from prior review, deliberately deferred)
Out-of-scope tracker (carried forward)
ConclusionThe 0.2-point deduction (down from 0.5) reflects only the two non-blocking nits intentionally deferred. Correctness, security, and code quality remain unchanged from the prior review — both clean.
|
Summary
brv connectors listreported every agent that maps to a shared rules file (e.g. Amp, Codex, OpenCode all map toAGENTS.md; Claude Code and OpenClaude both map toCLAUDE.md) as having a rules connector installed, as soon as the BRV markers were present in the file. A user who installed once for one agent saw "ghost" entries for the others.brv connectors installfor a single agent.status()now reads the existingGenerated by ByteRover CLI for Xfooter that the template service already writes inside the BRV section, and requires the extracted agent name to match the agent being queried. Footer-less files (legacy installs predating the footer) keep today's behavior so existing users are not surprised.extractInstalledAgentFromBrvSectionis exported but only consumed by the rules connector for now.Type of change
Scope (select all touched areas)
Linked issues
Root cause (bug fixes only, otherwise write
N/A)installed = hasMarkers && !hasMcpTools. For agents that share a rule file (Amp / Codex / OpenCode ->AGENTS.md; Claude Code / OpenClaude ->CLAUDE.md), every sharing agent saw the same markers and reportedinstalled: true, even though the install had been performed once for a single agent. The template service has been writing a per-agent footer (Generated by ByteRover CLI for X) inside the BRV section for some time, but no read path consulted it..cursor/rules/agent-context.mdc), where one file maps to one agent. The shared-file collision only surfaces when a project is configured with one of the agents that shareAGENTS.mdorCLAUDE.md.Test plan
test/unit/infra/connectors/shared/constants.test.ts(new) — 8 cases forextractInstalledAgentFromBrvSection(happy path, multi-word agents, missing footer, missing markers, footer outside section, end-before-start, blank footer) plus a regression guard forhasMcpToolsInBrvSectiontest/unit/infra/connectors/rules/rules-connector.test.ts(new) — 5 cases covering the shared-file scenarios: Codex-authoredAGENTS.md, Amp-authoredAGENTS.md, footer-less legacy file (fallback contract),CLAUDE.mdisolation, and the existing MCP-tools-in-section guardAGENTS.md-> Codex rulesinstalled: true; Amp + OpenCodeinstalled: falseAGENTS.md-> Amp rulesinstalled: true; Codex + OpenCodeinstalled: falseAGENTS.md-> all three sharing agentsinstalled: true(legacy fallback preserved)brv connectors install Codex --type rules) writes the footer; subsequentbrv connectors listshows only CodexCLAUDE.mdpopulated for Claude Code -> Claude Code only; Amp / Codex / OpenCodeinstalled: falseUser-visible changes
brv connectors listno longer reports ghost rules entries for agents that share a rule file. After installing a rules connector for one agent (e.g. Codex), the list shows only that agent, not every other agent that happens to use the same file path.For users on a footer-less rule file from an older CLI version, behavior is unchanged until the next
brv connectors installfor that agent rewrites the section with a footer.Evidence
Manual reproduction (interactive
brv connectors list --format json):Test 1 — Codex-authored
AGENTS.md(footer says Codex):{ "connectors": [ { "agent": "Codex", "connectorType": "rules", ... } ] }(before this PR: Amp, Codex, OpenCode all listed as rules)
Test 2 — Amp-authored
AGENTS.md:{ "connectors": [ { "agent": "Amp", "connectorType": "rules", ... } ] }Test 3 — footer-less
AGENTS.md(legacy fallback):{ "connectors": [ { "agent": "Amp", ... }, { "agent": "Codex", ... }, { "agent": "OpenCode", ... } ] }Test 4 — fresh
brv connectors install Codex --type rulesfollowed bybrv connectors list: shows Codex only.Test 5 —
CLAUDE.mdwritten for Claude Code: shows Claude Code only.Unit test run:
15 passingacross the two new test files. Full suite:7377 passing, 16 pending.Checklist
npm test)npm run lint)npm run typecheck)npm run build)mainRisks and mitigations
AGENTS.mdwill continue to see all sharing agents listed until they reinstall.brv connectors install <agent> --type rulesrewrites the section with a footer and the new disambiguation kicks in for that file. Documented in the inline comment atrules-connector.ts:135-137and exercised by a dedicated unit test.AGENTS.md/CLAUDE.mdwould re-introduce a similar shared-file collision on the MCP path, wheremcp-connector.statusManualdoes not yet check the footer.extractInstalledAgentFromBrvSectionis generic; wiring it intostatusManualis a two-line follow-up if/when that situation arises.