Skip to content

fix(init): preserve user prose during uninstall - #4405

Merged
KuSh merged 9 commits into
rtk-ai:developfrom
yeahjack:fix/init-preserve-user-prose-3403
Oct 18, 2026
Merged

KuSh merged 9 commits into
rtk-ai:developfrom
yeahjack:fix/init-preserve-user-prose-3403

Conversation

@yeahjack

@yeahjack yeahjack commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Search for an RTK closing marker only after its opening marker, so an earlier stray closing marker cannot duplicate user content or leave the real block installed.
  • Remove only exact, trimmed @RTK.md reference lines during Claude uninstall. Preserve user prose, similarly named files, and files with no actual RTK reference.
  • Add regression coverage for malformed markers, repeated cleanup, whitespace-padded references, real uninstall behavior, and dry-run preservation.

Related to #3403. This is a partial fix for the marker-pairing and prefix-match defects. Line-ending and blank-line normalization when removing an actual artifact remain unchanged, so this PR does not resolve the whole issue.

Test plan

  • Confirmed four regression tests fail before the production changes (309 init tests passed, 4 failed).
  • cargo test --locked hooks::init:: (313 passed).
  • cargo fmt --all --check.
  • cargo clippy --locked --all-targets.
  • cargo test --locked --all (4,095 passed, 0 failed, 8 ignored).
  • git diff --check.

Validated on Linux with Rust 1.91.0. Uninstall tests use isolated temporary agent/home directories.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working hooks init testing labels Oct 2, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes two bugs in RTK init/uninstall logic: the RTK block end-marker search is now anchored to search only after the start marker (preventing a stray earlier closing marker from corrupting content), and @RTK.md reference removal now requires an exact trimmed line match instead of a prefix match (preventing deletion of user prose lines that merely start with @RTK.md). Adds regression tests covering malformed markers, repeated cleanup, whitespace-padded references, real uninstall behavior, and dr…

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

@yeahjack
yeahjack marked this pull request as ready for review October 2, 2026 21:23

@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: remove_rtk_block pairs the opening marker with a closing marker found after it, and Claude uninstall removes only lines whose trimmed text is exactly @RTK.md.
Scope: accept. #4425 changes the same lines of remove_rtk_block; this PR came first and is narrower, so it lands first and #4425's anchoring hunk becomes a no-op on rebase.
Ran: rtk init -g with --uninstall, --uninstall --dry-run, --auto-patch (install migration), --copilot --uninstall and --codex --uninstall, over 13 instruction files (prose starting with @RTK.md, a whitespace-padded reference, CRLF prose with no reference, a closing marker quoted before the block, after the block, and before both the block and a reference, an opening marker quoted before the block, install followed by uninstall, and two uninstalls in a row), on develop e542dca and on ff4ec6e, in an isolated HOME. Invariants: non-default targets (Copilot, Codex, install migration); under the hook (rtk rewrite leaves these commands unchanged); every decision. Savings: n/a (not a filter).
Pins: 4 decisions, 7 mutations, 1 survived the suite: pairing with the last closing marker instead of the first, on the line this PR rewrites. Develop already picks the first, so this is not new behaviour; the fixup below pins it.
Matrix: executed this round; pin check: executed this round.
CI @ff4ec6e1f: all green; @b15136a13 (fixup): all green.

Blocks merge (0, frozen at round 1)

Filed as follow-ups

  • #4650: install and init --show still treat any mention of @RTK.md as the reference line. Claude install adds nothing yet reports "reference added", Codex install rewrites the user's prose to an absolute path, and a BOM-prefixed reference line survives uninstall. All of this is outside this PR's hunks and behaves the same on develop; filed.
  • #3403: an opening marker quoted above the block still makes remove_rtk_block delete the user's text from the quote to the end of the block, with the same output on develop; comment added with the repro. #3403's line-ending item is also still open, as the PR says.

Checked and correct — no need to re-verify

  • Closing marker quoted before the block: develop duplicated the span and left the block installed, and a second uninstall duplicated it again; here the block is removed and a second run is a no-op. The same holds on install migration and in the Copilot and Codex uninstall paths, which all go through remove_rtk_block.
  • A closing marker with no opening marker after it leaves the file unchanged and returns false.
  • Prose lines that start with or contain @RTK.md are kept, and both the bare and the whitespace-padded reference lines are removed.
  • A CRLF file with prose but no reference line is left byte-identical. Develop rewrote it to LF and deleted a line.
  • --dry-run leaves the file untouched.
  • The new uninstall tests go through the real uninstall() with an isolated Claude dir. Each mutation of the uninstall gate and filter (contains, starts_with, no trim, trim_end, always true) turns one of them red.
  • The src/llm_proxy.rs hunk removes a duplicated, identical #[cfg(feature = "engine")] attribute; no effect.

Your questions

None asked.

Next

Fixup b15136a pushed, code-reviewed: it adds test_remove_rtk_block_stops_at_first_end_marker, which fails when the closing marker is searched with rfind (a closing marker quoted after the block would otherwise swallow the prose before it). Approving.
Rounds: 1. Threads: 0 open, 0 resolved this round.

@KuSh
KuSh merged commit ecff3e0 into rtk-ai:develop Oct 18, 2026
15 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hooks init testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants