refactor(init): idempotent upsert_rtk_block for CLAUDE.md management#123
Open
heAdz0r wants to merge 1 commit intortk-ai:masterfrom
Open
refactor(init): idempotent upsert_rtk_block for CLAUDE.md management#123heAdz0r wants to merge 1 commit intortk-ai:masterfrom
heAdz0r wants to merge 1 commit intortk-ai:masterfrom
Conversation
Replace naive append-or-skip logic in run_claude_md_mode with upsert_rtk_block() that handles all 4 cases: - Added: no existing block → append - Updated: stale block → replace in-place - Unchanged: current block → no-op - Malformed: opening marker without closing → warn safely Includes 4 unit tests covering each case.
This was referenced Feb 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracted from #118 per reviewer feedback (split into focused PRs).
Replaces the naive append-or-skip logic in
run_claude_md_mode()withupsert_rtk_block()— a pure function that handles all 4 CLAUDE.md states:Changes
src/init.rs:RtkBlockUpsertenum,upsert_rtk_block()function, refactoredrun_claude_md_mode()Why this is safe
&strcontent + desired block, returns(String, Action)— caller decides whether to writeTest plan
cargo test init::— 26 tests passcargo fmt --all --check— cleancargo clippy --all-targets— no new warnings