Make setup-reaper safe & transactional: backup, --dry-run, staging, --uninstall (closes #6)#36
Merged
Merged
Conversation
A remote-mismatch on the existing install dir called shutil.rmtree, destroying the user's prior install with no recovery path. Replace both call sites with _backup_dir, which moves it to <install>.bak.<timestamp> and reports the path. Never destroy without a way back.
--dry-run prints exactly what a real run would do — clone target+tag, uv sync command, Lua source->dest, bridge data dir, __startup.lua action, and a unified diff of the proposed .mcp.json change — without touching the filesystem or network. On real runs, the .mcp.json diff is now shown before writing. Refactored the config merge into _compute_mcp_merge / _render_mcp_diff / _merge_mcp_config so preview and write share one code path.
A fresh install now clones and runs uv sync inside ~/.phantom/.staging/<tmp> and only moves the tree into place after every step succeeds. If the clone or uv sync fails, the staging dir is removed and the live filesystem is unchanged — no more half-installed bridge from a mid-install failure. Updates to an existing verified install still happen in place. The bridge launches via uv run --directory, which revalidates the moved environment. Tests cover both the sync-failure-leaves-fs-unchanged and success-moves-into- place paths.
Reverses an install: backs up the bridge dir (never destroys), removes the copied Lua + mcp_bridge_data, strips the phantom block from __startup.lua (preserving unrelated content), and removes the reaper entry from .mcp.json (leaving other servers intact). Honors --dry-run (preview) and --yes; needs neither git/uv nor a detected Reaper. Closes #6.
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
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.
Closes #6. Makes
phantom setup-reaper— the most invasive thing the tool does — safe, previewable, and reversible.Changes (4 atomic commits)
shutil.rmtree, deleting a prior install with no recovery. Now moves it to<install>.bak.<timestamp>.--dry-run— prints the exact plan (clone target+tag,uv synccmd, Lua src→dest, bridge dir,__startup.luaaction, and a unified diff of the.mcp.jsonchange) andmutates nothing. The
.mcp.jsondiff is also shown on real runs before writing.uv syncinside~/.phantom/.staging/<tmp>and only moves into place after every step succeeds. A clone/sync failureleaves the live filesystem unchanged (no half-install). Launch via
uv run --directoryrevalidates the moved env.--uninstall— backs up the bridge, removes copied Lua +mcp_bridge_data, strips only the phantom block from__startup.lua, and removes just thereaperentry from.mcp.json. Honors--dry-runand--yes.Note: the issue's "silent
.mcp.jsonoverwrite" was already fixed (the--yes/confirm guard); this adds the diff preview on top.Verification
37 setup-reaper tests pass; lint clean. Exercised live: backup round-trip,
--dry-run(zero mutations), and the full--uninstallreversal (unrelated__startup.luacontentand other
.mcp.jsonservers preserved). Staging's fail-safe is covered by tests (sync-failure → fs unchanged).