Skip to content

fix(init): treat @RTK.md reference as a whole line - #5206

Merged
KuSh merged 4 commits into
rtk-ai:developfrom
helmipradita:fix/init-rtk-reference-line-match-4650
Nov 29, 2026
Merged

KuSh merged 4 commits into
rtk-ai:developfrom
helmipradita:fix/init-rtk-reference-line-match-4650

Conversation

@helmipradita

Copy link
Copy Markdown
Contributor

Fixes #4650

claude.rs, agents_md.rs and --show used content.contains("@RTK.md"), so any prose mention counted as an installed reference: init added none and --show reported ok. The Codex migration then used whole-file replace, 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 --check clean; cargo test --lib → 4918 passed, 0 failed. Four new regressions in hooks::init::agents_md::tests cover prose mentions, BOM detection, prose-preserving migration and BOM removal.

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 TechWizard9999 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up. The line-only migration and reusing has_rtk_reference look right. A few gaps against #4650:

  1. agents_md.rs:171: the outer check in patch_agents_md is still content.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 to has_rtk_reference(&content, &[RTK_MD_REF, rtk_md_ref]) should fix it.

  2. mod.rs:1593: the CLAUDE.md uninstall filter still uses line.trim() != RTK_MD_REF. Since has_rtk_reference is now BOM-aware, a CLAUDE.md of \u{feff}@RTK.md\n is detected but not removed: RTK.md gets deleted, the line stays, and uninstall reports "removed @RTK.md reference". Using normalize_reference_line there too would close case 4.

  3. The claude.rs:87 and show_claude_config changes have no test that fails if they're reverted, and test_reference_requires_a_whole_line_not_a_mention already 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>
@helmipradita

Copy link
Copy Markdown
Contributor Author

@/tmp/opencode/pr-audit-1123/reply5206.md

@TechWizard9999

Copy link
Copy Markdown
Contributor

Rechecked bce960fc: the AGENTS.md gate, the BOM uninstall filter, the BOM-before-trim order, the claude.rs check and the clippy warning are all fixed, and reverting each one fails a test.

One spot is still unpinned: show_claude_config (mod.rs:2164). Reverting has_rtk_reference(&content, &[RTK_MD_REF]) to content.contains(RTK_MD_REF) keeps all hooks::init tests green, since no test runs rtk init --show for Claude. A global CLAUDE.md containing only Read @RTK.md for details. would then report [ok] ... @RTK.md reference again. A --show test with a prose-only CLAUDE.md, or dropping that hunk from this PR, would close it.

cc @KuSh

helmipradita and others added 2 commits November 26, 2026 13:36
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 KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --show matches 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 --codex with Read @RTK.md for details.: the sentence is kept and an absolute reference line is added; a second init reports "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.md in place.
  • Codex --show and the local rtk init / --claude-md flows 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.

@KuSh
KuSh merged commit 443ff2a into rtk-ai:develop Nov 29, 2026
16 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Nov 29, 2026
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.

rtk init treats any mention of @RTK.md as the reference line: install adds none, Codex rewrites user prose, --show reports ok

3 participants