Skip to content

refactor(init): idempotent upsert_rtk_block for CLAUDE.md management#123

Open
heAdz0r wants to merge 1 commit intortk-ai:masterfrom
heAdz0r:refactor/upsert-rtk-block
Open

refactor(init): idempotent upsert_rtk_block for CLAUDE.md management#123
heAdz0r wants to merge 1 commit intortk-ai:masterfrom
heAdz0r:refactor/upsert-rtk-block

Conversation

@heAdz0r
Copy link

@heAdz0r heAdz0r commented Feb 14, 2026

Summary

Extracted from #118 per reviewer feedback (split into focused PRs).

Replaces the naive append-or-skip logic in run_claude_md_mode() with upsert_rtk_block() — a pure function that handles all 4 CLAUDE.md states:

State Behavior
No existing block Append new block
Stale block (different content) Replace in-place, preserve surrounding content
Current block (identical) No-op
Malformed (open marker, no close) Warn safely, do not rewrite

Changes

  • src/init.rs: RtkBlockUpsert enum, upsert_rtk_block() function, refactored run_claude_md_mode()
  • 4 unit tests covering each upsert case

Why this is safe

  • Pure function: takes &str content + desired block, returns (String, Action) — caller decides whether to write
  • Malformed case explicitly refuses to rewrite, prints location and manual fix instructions
  • All existing init tests continue to pass (26 total)

Test plan

  • cargo test init:: — 26 tests pass
  • cargo fmt --all --check — clean
  • cargo clippy --all-targets — no new warnings

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.
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.

1 participant