Repository navigation
fix(init): treat @RTK.md reference as a whole line - #5206
Conversation
Addressed rtk-ai#4650. claude.rs, agents_md.rs and --show used substring contains(RTK_MD_REF), so any mention in prose counted as an installed reference (install added none, --show reported ok). The Codex migration also used whole-file replace, rewriting user prose. Switch all three to the existing whole-trimmed-line has_rtk_reference predicate, replace only the matching line, and strip a U+FEFF BOM so editor-prefixed references are detected and removed. Four regressions cover prose mentions, BOM, migration prose preservation and BOM removal. cargo test --lib: 4918 passed, 0 failed; fmt clean. Signed-off-by: Helmi Pradita <helmipraditaa@gmail.com>
TechWizard9999
left a comment
There was a problem hiding this comment.
Thanks for picking this up. The line-only migration and reusing has_rtk_reference look right. A few gaps against #4650:
-
agents_md.rs:171: the outer check inpatch_agents_mdis stillcontent.contains(RTK_MD_REF) || content.contains(rtk_md_ref). With an AGENTS.md of# Agents\n\nRead @RTK.md for details.\n, prose is no longer rewritten, but no reference line is added either, and Codex init reports the reference as already present. Switching that gate tohas_rtk_reference(&content, &[RTK_MD_REF, rtk_md_ref])should fix it. -
mod.rs:1593: the CLAUDE.md uninstall filter still usesline.trim() != RTK_MD_REF. Sincehas_rtk_referenceis now BOM-aware, a CLAUDE.md of\u{feff}@RTK.md\nis detected but not removed: RTK.md gets deleted, the line stays, and uninstall reports "removed @RTK.md reference". Usingnormalize_reference_linethere too would close case 4. -
The
claude.rs:87andshow_claude_configchanges have no test that fails if they're reverted, andtest_reference_requires_a_whole_line_not_a_mentionalready passes on develop. Could you add a CLAUDE.md install test with a prose-only mention (expect the line to be added), plus one for the BOM uninstall above?
Small things: the format!(...) with no arguments at agents_md.rs:508 will trip clippy's useless_format, and stripping the BOM before trimming (line.trim_start_matches('\u{FEFF}').trim()) would also catch a BOM followed by indentation.
cc @KuSh
Signed-off-by: Helmi Pradita <helmipraditaa@gmail.com>
|
@/tmp/opencode/pr-audit-1123/reply5206.md |
|
Rechecked One spot is still unpinned: cc @KuSh |
Claude Code imports an @RTK.md token written inside a sentence or a list item (`Read @RTK.md for details.`, `- @RTK.md`), not only one on its own line. The whole-line check made `rtk init --show` report such a CLAUDE.md as not configured while RTK.md was loaded, so the Claude install check and `--show` go back to the substring match. The whole-line rule stays for AGENTS.md and for removal, where deleting a user's sentence would lose content. The `--show` tests now assert that reading, each in a directory of its own. Also pins the migration's absolute-line condition both ways: an absolute path quoted in prose does not stop the relative reference line from being rewritten, and an existing absolute reference line skips the migration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KuSh
left a comment
There was a problem hiding this comment.
Round 1 — APPROVED, follow-ups filed
Claim: rtk init stops treating a prose mention of @RTK.md as the installed reference: Codex no longer rewrites user prose during the relative-to-absolute migration, install and --show require a whole line, and a BOM-prefixed reference is detected and removed.
Scope: accept if narrowed to "AGENTS.md: whole-line detection and line-only migration; BOM-aware reference matching, including the CLAUDE.md uninstall filter" (round 1, frozen). The Claude install check and the global --show check go back to develop's substring match, by the fixup below: Claude Code imports @RTK.md written inside a sentence, which #4650 got wrong. Maintainer PRs: checked against #4269 (KuSh), both test sets pass on the combination.
Ran: release builds of merge-base ef0b734 and a42c4dd in isolated HOMEs, LC_ALL=C: 13 Claude rows (init -g --auto-patch, init -g, --dry-run, --show, --uninstall, a second init, prose / list / BOM / indented+CRLF / fenced / old-block inputs), 9 Codex rows (init -g --codex, local init --codex, --show, --uninstall, --dry-run, a second init, prose / BOM / CRLF / absolute path quoted in prose), 3 local and --claude-md rows. Claude Code 2.1.332 against a local Messages API stand-in, 15 CLAUDE.md shapes, checking whether RTK.md content reaches the model. Invariants: every decision; foreign content survives byte for byte outside the reference line; idempotence. No savings figure applies (no filter).
Pins: 11 decisions, 12 mutations, 2 survived the suite: the has_rtk_reference(&content, &[RTK_MD_REF]) migration conjunct (equivalent, implied by the outer gate) and the !has_rtk_reference(&content, &[rtk_md_ref]) conjunct (pinned by the fixup). The fixup's own 4 decisions: 4 mutated, 4 killed.
Matrix: executed this round; pin check: executed this round.
CI @a42c4dd4: all green (16/16); @25310713: all green (16/16)
Blocks merge (0)
Follow-ups
- #5344 rtk init: Claude CLAUDE.md status does not follow what Claude Code imports —
Read @RTK.md.,(@RTK.md), inline code and fenced blocks count as installed but are not imported; the summary always says "added"; uninstall leaves- @RTK.md; local--showmatches any "rtk" — pre-existing, outside the narrowed claim; filed. - #4650 — correction comment: its cases 1 and 3 were wrong for Claude.
- #3403 already covers the remover dropping the final newline and rewriting CRLF (the comment in
test_remove_reference_with_bom).
Checked and correct — no need to re-verify
- Codex
init -g --codexwithRead @RTK.md for details.: the sentence is kept and an absolute reference line is added; a secondinitreports "already present" and writes nothing. - The migration rewrites only the reference line, including with CRLF line endings, a BOM-prefixed line and the relative line beside a quoted absolute path.
--uninstall(Claude and Codex) removes a BOM-prefixed reference line and leaves prose mentioning@RTK.mdin place.- Codex
--showand the localrtk init/--claude-mdflows are unchanged. - develop 2ffac49 + this PR with the fixup: fmt, clippy (0 warnings), 5967 tests pass.
Your questions
(none)
Next
Fixup 2531071 pushed, code-reviewed: Claude's install check and global --show go back to content.contains("@RTK.md"), because Claude Code 2.1.332 imports Read @RTK.md for details. and - @RTK.md (a whole-line check reported those as not configured and appended a duplicate line). The --show tests now assert that, each in a directory of its own, and two migration tests pin the absolute-line condition both ways. Approving.
Threads: 0 open, 0 resolved this round.
Fixes #4650
claude.rs,agents_md.rsand--showusedcontent.contains("@RTK.md"), so any prose mention counted as an installed reference:initadded none and--showreported ok. The Codex migration then used whole-filereplace, rewriting unrelated user prose (Read @RTK.md→Read @/home/.../RTK.md). A U+FEFF BOM also hid a real reference from detection/removal.Fix reuses
has_rtk_reference(whole trimmed line) at all three sites, replaces only the matching line during migration, and normalizes a leading BOM in the shared line helper. Zero new deps.cargo fmt --checkclean;cargo test --lib→ 4918 passed, 0 failed. Four new regressions inhooks::init::agents_md::testscover prose mentions, BOM detection, prose-preserving migration and BOM removal.