Skip to content

Comments

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

Merged
pszymkowiak merged 1 commit intortk-ai:masterfrom
heAdz0r:refactor/upsert-rtk-block
Feb 15, 2026
Merged

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

Conversation

@heAdz0r
Copy link
Contributor

@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.
Copy link
Collaborator

@pszymkowiak pszymkowiak left a comment

Choose a reason for hiding this comment

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

Clean refactor. Pure function with 4 well-tested cases, defensive malformed handling. LGTM.

@pszymkowiak pszymkowiak merged commit 356c0d6 into rtk-ai:master Feb 15, 2026
2 checks passed
ahundt added a commit to ahundt/rtk that referenced this pull request Feb 16, 2026
Merged from upstream/master:
- feat(gain): colored dashboard with efficiency meter and impact bars (rtk-ai#129)
- refactor(init): add upsert_rtk_block for idempotent CLAUDE.md management (rtk-ai#123)
- feat(cargo): add cargo nextest support with failures-only output (rtk-ai#107)
- docs: version references to 0.16.0/0.18.0 in README, ARCHITECTURE, CHANGELOG
- ci: add validate-docs workflow

Conflict resolution in src/init.rs:
- Kept RtkBlockUpsert enum and upsert_rtk_block() from upstream
- Kept patch_instruction_file() from current branch (for @RTK.md references)
- Both features coexist: upsert_rtk_block for legacy --claude-md mode,
  patch_instruction_file for default @RTK.md reference mode

All 688 tests pass.
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.

2 participants