Skip to content

fix(init): prevent clobbering instruction files (GEMINI.md, RTK.md)#835

Open
bnaylor wants to merge 1 commit intortk-ai:developfrom
bnaylor:fix/gemini-md-clobbering
Open

fix(init): prevent clobbering instruction files (GEMINI.md, RTK.md)#835
bnaylor wants to merge 1 commit intortk-ai:developfrom
bnaylor:fix/gemini-md-clobbering

Conversation

@bnaylor
Copy link
Copy Markdown

@bnaylor bnaylor commented Mar 25, 2026

Problem

The current implementation of rtk init and rtk uninstall performs full file overwrites/deletions of instruction files like GEMINI.md and RTK.md. This leads to data loss if users have custom notes or configuration in those files.

Solution

  • Introduced upsert_write_rtk_block to manage RTK's instruction block using <!-- rtk-instructions v2 --> markers.
  • Introduced remove_rtk_block_from_file to only remove RTK's block during uninstalls, preserving other content.
  • Updated run_gemini, run_default_mode, and run_codex_mode to use these safer functions.
  • Ensured all file updates are atomic to prevent corruption.
  • Added comprehensive unit and end-to-end tests for file-level block management.

Verification

  • Added test_upsert_write_rtk_block and test_remove_rtk_block_from_file tests pass.
  • Manually verified with rtk cargo test that existing tests are not regressed.

Fixes #834 (Referenced but not closed, as per user instructions).
Credit for the fix: Gemini CLI (with assistance from bnaylor).

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 25, 2026

CLA assistant check
All committers have signed the CLA.

@pszymkowiak
Copy link
Copy Markdown
Collaborator

Hi! Two things needed before we can review:

  1. Retarget to develop — this PR targets master, but all PRs should target develop. You can change the base branch in the PR settings (right sidebar).
  2. Sign the CLA — if not already done, please sign at https://cla-assistant.io/rtk-ai/rtk

Thanks!

@bnaylor bnaylor changed the base branch from master to develop March 26, 2026 15:24
@bnaylor
Copy link
Copy Markdown
Author

bnaylor commented Mar 26, 2026

Thanks! Switched branches. CLA should be good.

@aeppling
Copy link
Copy Markdown
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git detects renames automatically. If you get import conflicts, update the paths:

use crate::git;        // now: use crate::cmds::git::git;
use crate::tracking;   // now: use crate::core::tracking;
use crate::config;     // now: use crate::core::config;
use crate::init;       // now: use crate::hooks::init;
use crate::gain;       // now: use crate::analytics::gain;

Need help rebasing? Tag @aeppling

- Implement  to preserve user content
- Implement  for safer uninstalls
- Add end-to-end tests for file-level block management
- Use atomic writes for all instruction file updates

Fixes issue where
Gemini CLI hook installed (global).

  Hook: /Users/bnaylor/.gemini/hooks/rtk-hook-gemini.sh
  GEMINI.md: /Users/bnaylor/.gemini/GEMINI.md
  Restart Gemini CLI. Test with: git status would overwrite existing ~/.gemini/GEMINI.md
@bnaylor bnaylor force-pushed the fix/gemini-md-clobbering branch from 0c1c3b5 to 9446258 Compare March 28, 2026 19:04
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.

[BUG] rtk init -g --gemini clobbers ~/.gemini/GEMINI.md instead of appending

5 participants