Skip to content

Make setup-reaper safe & transactional: backup, --dry-run, staging, --uninstall (closes #6)#36

Merged
leesaenz merged 6 commits into
mainfrom
fix/setup-reaper-transactional
Jun 1, 2026
Merged

Make setup-reaper safe & transactional: backup, --dry-run, staging, --uninstall (closes #6)#36
leesaenz merged 6 commits into
mainfrom
fix/setup-reaper-transactional

Conversation

@leesaenz

@leesaenz leesaenz commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #6. Makes phantom setup-reaper — the most invasive thing the tool does — safe, previewable, and reversible.

Changes (4 atomic commits)

  • Backup, not destroy — the remote-mismatch path called 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 sync cmd, Lua src→dest, bridge dir, __startup.lua action, and a unified diff of the .mcp.json change) and
    mutates nothing. The .mcp.json diff is also shown on real runs before writing.
  • Transactional install — a fresh install clones + uv sync inside ~/.phantom/.staging/<tmp> and only moves into place after every step succeeds. A clone/sync failure
    leaves the live filesystem unchanged (no half-install). Launch via uv run --directory revalidates 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 the reaper entry from
    .mcp.json. Honors --dry-run and --yes.

Note: the issue's "silent .mcp.json overwrite" 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 --uninstall reversal (unrelated __startup.lua content
and other .mcp.json servers preserved). Staging's fail-safe is covered by tests (sync-failure → fs unchanged).

leesaenz added 4 commits June 1, 2026 16:13
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.
Comment thread src/phantom/cli/setup_reaper.py Fixed
leesaenz and others added 2 commits June 1, 2026 16:35
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@leesaenz leesaenz merged commit e7e397b into main Jun 1, 2026
10 checks passed
@leesaenz leesaenz deleted the fix/setup-reaper-transactional branch June 1, 2026 21:39
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.

Make setup-reaper transactional with --dry-run and .mcp.json diff preview

1 participant