Adds a top-level `fabro uninstall` command that reverses `fabro install` and `install.sh`. Defaults to dry-run (preview) mode, requiring `--yes` to execute. Features: - Inventory and dry-run preview with sizes and `--json` support - Server shutdown (guarded — only when server is running) - Safety guardrails (refuses to delete /, $HOME, or dirs without markers) - Shell config cleanup (exact `# fabro` sentinel match, PATH validation, atomic write via temp+rename) - Binary status reporting with tailored brew/cargo/manual hints - Exit code: 0 on success, 1 on critical failure Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
23 KiB
| title | type | status | date | origin | deepened |
|---|---|---|---|---|---|
| feat: Add `fabro uninstall` command | feat | completed | 2026-04-08 | docs/ideation/2026-04-08-fabro-uninstall-ideation.md | 2026-04-08 |
feat: Add fabro uninstall command
Overview
Add a fabro uninstall top-level CLI command that reverses the effects of fabro install and install.sh. The command stops a running server, removes the ~/.fabro/ directory tree, cleans shell config PATH entries, and handles binary self-removal. Defaults to dry-run (preview) mode, requiring --yes to execute.
Problem Frame
There is no supported way to uninstall Fabro. Users must manually rm -rf ~/.fabro, hunt for stale PATH entries in their shell configs, and figure out how to stop the server. This creates friction, erodes trust, and leaves detritus after uninstall.
Requirements Trace
- R1. Remove the
~/.fabro/directory and all contents - R2. Stop a running server before removing files
- R3. Remove
# fabroPATH lines from shell configs (.zshrc, .bashrc, .bash_profile, .config/fish/config.fish) - R4. Default to dry-run with size reporting; require
--yesto execute - R5. Delete the binary when installed via
install.shto~/.fabro/bin/; print a hint otherwise - R6. Support
--jsonoutput for scriptability
Scope Boundaries
- No selective/component uninstall (users can back up manually)
- No GitHub App deregistration via API
- No export/backup archive feature
- No telemetry farewell event
- No per-repo cascade cleanup (repos can be cleaned individually via
fabro repo deinit)
Context & Research
Relevant Code and Patterns
lib/crates/fabro-cli/src/commands/install.rs— whatfabro installcreates (settings.toml, certs/, secrets.json)apps/marketing/public/install.sh— what the shell installer creates (binary at~/.fabro/bin/fabro, PATH lines with# fabrosentinel)lib/crates/fabro-cli/src/commands/server/stop.rs—execute(storage_dir, timeout): SIGTERM, poll, SIGKILL, record+socket cleanuplib/crates/fabro-cli/src/commands/server/record.rs—active_server_record_details()for detecting running serverlib/crates/fabro-cli/src/commands/system/prune.rs— dry-run-by-default pattern with--yes, size reporting viaformat_size()lib/crates/fabro-cli/src/commands/repo/deinit.rs— cleanup command pattern: green checkmarks, NotFound tolerance,Vec<String>return,--jsonsupportlib/crates/fabro-util/src/home.rs—Homestruct with all path accessors (root(),certs_dir(),storage_dir(), etc.)lib/crates/fabro-config/src/storage.rs—Storagestruct with storage path accessorslib/crates/fabro-cli/src/args.rs—Commandsenum for command registration,Commands::name()for telemetrylib/crates/fabro-cli/src/commands/upgrade.rs—std::env::current_exe()?.canonicalize()?for binary path detectionlib/crates/fabro-config/src/user_config.rs—load_settings()for resolving effective configuration including non-defaultstorage_dir
Institutional Learnings
No docs/solutions/ directory exists. No prior learnings on install/uninstall patterns.
Key Technical Decisions
- Top-level command, not subcommand of
system: Matchesinstall/upgradeplacement. Users will search forfabro uninstall— discoverability matters. (see origin: docs/ideation/2026-04-08-fabro-uninstall-ideation.md) --yesconfirmation model (not--dry-run): Matchessystem prunepattern — destructive operations default to preview. The flag name--yesis already established in the codebase.- Use
Home::from_env()as the canonical root: Respects$FABRO_HOMEfor non-default installations. Never hardcode~/.fabro/. - Shell config cleanup uses exact
# fabrosentinel match: Theinstall.shscript writes# fabroas a marker comment before the PATH export. Match withline.trim() == "# fabro"(exact match, not substring) to avoid deleting unrelated lines like# fabro workflow helper. After matching the sentinel, validate that the following line matches an expected PATH pattern (export PATH=orfish_add_path) before removing it — this prevents accidentally deleting an innocent line if the file was manually edited. - Binary path resolved during inventory, not after deletion:
std::env::current_exe()?.canonicalize()?must be called during the inventory phase (Unit 2) and stored. On macOS,canonicalize()fails withNotFoundafter the file is deleted byremove_dir_all. The stored path is used later by Unit 5. - Binary self-deletion is the final step: On Unix, unlinking a running binary works (the inode stays alive until the process exits). Must be absolutely last since nothing can run after the binary is gone.
- Do not call
stop::execute()without a guard:server::stop::execute()callsstd::process::exit(1)when no server is running. The uninstall command must checkrecord::active_server_record_details()first and only callstop::execute()when a server is confirmed running. - Resolve
storage_dirthrough settings, not justHome: Ifsettings.tomlconfigures a non-defaultstorage_dir, the server record lives at that custom path. Load effective settings viauser_config::load_settings()during inventory to resolve the actualstorage_dir. - Compute-once inventory: The inventory is built once (Unit 2) and consumed by all subsequent units. No step should re-detect artifacts during execution — the directory may already be partially deleted.
- Exit code policy: Exit 0 only if all critical steps (server stop, directory removal) succeeded. Exit 1 if any critical step failed. Shell config cleanup and binary handling failures warn but do not affect the exit code.
- Synchronous implementation: Server stop logic (
stop::execute) is synchronous. The uninstall function itself should be async (matching the dispatch pattern in main.rs) but can call sync helpers.
Open Questions
Resolved During Planning
-
Should uninstall clean up shell configs that
fabro install(Rust) didn't create? Yes —install.shcreates them, and the user experience of "uninstall" should reverse the full installation, not just the Rust command's portion. -
What if the server won't stop? Follow the existing SIGTERM→SIGKILL pattern from
server/stop.rs. If SIGKILL fails (shouldn't happen on Unix), warn and continue with removal. -
Should the dry-run preview show active workflow run count? Yes — if the server is running with in-flight workflows, stopping it will terminate them. The preview should report the count so users can make an informed decision. The run count can be obtained from the server API if available, or noted as "server running (active runs unknown)" if the API is unreachable.
-
What about
$ZDOTDIRmismatch between install and uninstall time? If the user's$ZDOTDIRwas set differently at install time versus uninstall time, the uninstall will look in the wrong file. This is an inherent limitation — document it but do not try to solve it.
Deferred to Implementation
- Fish shell syntax differences:
fish_add_pathvsexport PATH=— the removal logic needs shell-specific handling. Determine exact patterns during implementation.
Implementation Units
- Unit 1: Command registration and skeleton
Goal: Register fabro uninstall as a top-level CLI command with args parsing.
Requirements: R4, R6
Dependencies: None
Files:
- Modify:
lib/crates/fabro-cli/src/args.rs - Modify:
lib/crates/fabro-cli/src/commands/mod.rs - Modify:
lib/crates/fabro-cli/src/main.rs - Create:
lib/crates/fabro-cli/src/commands/uninstall.rs
Approach:
- Add
UninstallArgsstruct with--yesbool field (clap attribute:#[arg(long)]) - Add
Uninstall(UninstallArgs)variant toCommandsenum with doc comment/// Uninstall Fabro from this machine - Add
Self::Uninstall(_) => "uninstall"toCommands::name() - Add
pub(crate) mod uninstall;tocommands/mod.rs - Add dispatch arm in main.rs calling
commands::uninstall::run_uninstall(&args, &globals).await? - Skeleton
run_uninstallthat prints "not yet implemented" and returns Ok
Patterns to follow:
InstallArgsstruct andCommands::Installvariant inargs.rs- Dispatch pattern in
main.rs(line ~176) - Module declaration pattern in
commands/mod.rs
Test scenarios:
- Happy path:
fabro uninstall --helpoutputs usage text including--yesflag description - Happy path:
fabro uninstall(no args) parses successfully and runs the skeleton
Verification:
cargo build -p fabro-clisucceedsfabro uninstall --helpshows the expected usage
- Unit 2: Inventory and dry-run preview
Goal: Discover all Fabro artifacts on the system, compute sizes, and display a preview manifest. When --yes is not passed, this is the complete behavior.
Requirements: R1, R2, R3, R4, R5, R6
Dependencies: Unit 1
Files:
- Modify:
lib/crates/fabro-cli/src/commands/uninstall.rs
Approach:
- Use
Home::from_env()to resolve the root directory - Check if
Home::root()exists; if not, print "Fabro is not installed" and exit 0 (skip settings loading entirely) - If home exists, attempt to load effective settings via
user_config::load_settings()to resolve actualstorage_dir. If settings loading fails (e.g., settings.toml missing or corrupt), fall back toHome::from_env().storage_dir()— this handles partial installs and repeated uninstall attempts - Build an inventory struct containing all information needed by subsequent units:
home_root: resolved Home root pathstorage_dir: resolved storage directory pathhome_exists: whether the home directory existshome_size: total size of home directory (recursive walk)server_running: whether a server is detected viarecord::active_server_record_details(&storage_dir)shell_configs: list of shell config file paths that contain the# fabrosentinel (exact match:line.trim() == "# fabro")binary_path: resolved path fromstd::env::current_exe()?.canonicalize()?(must be resolved NOW, before any deletion)binary_is_managed: whetherbinary_pathstarts withhome_root
- Shell config files to scan:
$ZDOTDIR/.zshrcor~/.zshrc,~/.bashrc,~/.bash_profile,~/.config/fish/config.fish - In dry-run mode (no
--yes): print each item that would be removed with its size, including active run warning if server is running, then print"Pass --yes to confirm."summary - Support
--jsonoutput: serialize inventory as JSON to stdout - Follow the
system pruneoutput style for human-readable format
Patterns to follow:
system prunedry-run output format ("would delete: ...", "N item(s) would be deleted (X freed)")format_size()for human-readable byte formattingconsole::Style/Styles::detect_stderr()for colored outputGlobalArgs.jsoncheck for JSON vs human output
Test scenarios:
- Happy path: preview with populated
~/.fabro/lists all directories and files with sizes - Happy path: preview with
--jsonoutputs structured JSON to stdout - Edge case:
~/.fabro/does not exist — prints "Fabro is not installed" and exits cleanly - Edge case: shell config files exist but contain no fabro lines — omitted from preview
- Edge case: binary is not in
~/.fabro/bin/— preview notes it must be removed manually - Happy path: running server detected — preview notes it will be stopped and warns about active runs
- Edge case:
current_exe()orcanonicalize()fails — inventory storesNonefor binary path, warns in preview
Verification:
fabro uninstall(no--yes) prints a complete manifest and does NOT delete anythingfabro uninstall --jsonoutputs valid JSON with inventory details- Preview accurately reflects what exists on disk
- Unit 3: Server shutdown and directory removal
Goal: When --yes is passed, stop a running server and remove ~/.fabro/ and all contents.
Requirements: R1, R2
Dependencies: Unit 2
Files:
- Modify:
lib/crates/fabro-cli/src/commands/uninstall.rs - Test:
lib/crates/fabro-cli/tests/it/cmd/uninstall.rs
Approach:
- Use the inventory's
server_runningandstorage_dirfields (computed in Unit 2) - Critical: Only call
server::stop::execute()wheninventory.server_runningis true.stop::execute()callsstd::process::exit(1)when no server is found — calling it unconditionally would terminate the process before any cleanup happens. - If running, call
server::stop::execute(&inventory.storage_dir, Duration::from_secs(5)) - If not running, skip with no error
- Safety guardrail before deletion: Validate
inventory.home_rootis reasonable before callingremove_dir_all. Refuse to proceed if the resolved path is a filesystem root (/), the user's home directory ($HOME), or does not contain an expected marker file (e.g.,settings.tomlorcerts/). This prevents catastrophic data loss from a misconfigured$FABRO_HOME. - After validation, remove
inventory.home_rootwithstd::fs::remove_dir_all - If
storage_dirdiffers from the default and is outsidehome_root, validate it contains Fabro artifacts (e.g.,secrets.jsonorstore/) before removing - Handle
ErrorKind::NotFoundgracefully (already uninstalled) - Report each step with green checkmark output following
deinit.rspattern - The
fabro.socksocket file is inside~/.fabro/so it's removed as part of the directory deletion
Patterns to follow:
server::stop::execute()for server shutdown (call ONLY when server is confirmed running)record::active_server_record_details()for server detection (already done in inventory)deinit.rscheckmark output patternRunScratch::remove()for NotFound tolerance
Test scenarios:
- Happy path: with
--yesand no running server,~/.fabro/is removed successfully - Happy path: with
--yesand running server, server is stopped before removal - Edge case:
~/.fabro/does not exist — reports "nothing to remove" without error - Error path: server stop fails (SIGKILL also fails) — warns and continues with removal
- Error path:
$FABRO_HOMEset to/— refuses to delete, prints error - Error path:
$FABRO_HOMEset to$HOME— refuses to delete, prints error - Error path:
$FABRO_HOMEpoints to a directory without Fabro marker files — refuses to delete - Integration: after removal,
~/.fabro/directory does not exist on disk
Verification:
fabro uninstall --yesremoves~/.fabro/completely- A running server is stopped before file removal
- No orphaned processes remain after uninstall
- Unit 4: Shell config cleanup
Goal: Remove PATH lines that install.sh added to shell configuration files, using the # fabro sentinel comment.
Requirements: R3
Dependencies: Unit 2 (uses shell config detection from inventory)
Files:
- Modify:
lib/crates/fabro-cli/src/commands/uninstall.rs - Test:
lib/crates/fabro-cli/tests/it/cmd/uninstall.rs
Approach:
- Use the inventory's
shell_configslist (detected in Unit 2) - For each shell config file in the list:
- Read the file contents
- Find lines where
line.trim() == "# fabro"(exact match, not substring — avoids matching# fabro workflow helper) - Validate that the following line matches an expected PATH pattern before removing it:
- zsh/bash: following line starts with
export PATH= - fish: following line starts with
fish_add_path
- zsh/bash: following line starts with
- If the following line does NOT match, remove only the sentinel line (defensive — the file was manually edited)
- Remove the sentinel line AND the validated following line
- Write the modified contents back
- Handle edge cases: sentinel at end of file, multiple sentinels, sentinel with no following line
- Report each modified file with the deinit checkmark pattern
- If a shell config file is not found or has no fabro lines, skip silently
Patterns to follow:
deinit.rsreporting pattern (green checkmarks per item)- Atomic write pattern: Write modified content to a temporary file in the same directory, then
std::fs::rename()over the original (atomic on POSIX). This prevents a truncated/corrupt dotfile if the process crashes mid-write. Checkstd::fs::symlink_metadata()before modifying — if the file is a symlink, follow it (matchingstd::fs::read_to_stringbehavior) but note this in output so users with dotfile managers are aware.
Test scenarios:
- Happy path:
.zshrcwith# fabro+ PATH line — both lines removed, rest of file intact - Happy path:
.bashrcwith# fabro+ PATH line — both lines removed - Happy path:
.bash_profilewith# fabro+ PATH line — both lines removed - Happy path:
config.fishwith# fabro+fish_add_path— both lines removed - Edge case: shell config exists but has no
# fabroline — file is not modified - Edge case: shell config file does not exist — no error
- Edge case:
# fabrois the last line in the file (no following PATH line) — only sentinel line removed - Edge case: multiple
# fabroblocks in the same file — all are removed - Edge case:
# fabrofollowed by an unrelated line (not PATH export) — only sentinel removed, following line preserved - Edge case: line contains
# fabroas substring (# fabro-related) — not matched, file unchanged - Integration: after cleanup, opening a new shell does not add fabro to PATH
Verification:
- Shell config files have fabro lines removed without corrupting other content
- Files without fabro lines are not modified (mtime unchanged)
- Unit 5: Binary status reporting and final output
Goal: Report whether the binary was already removed (managed install) or print a removal hint (external install). Print final summary.
Requirements: R5
Dependencies: Unit 3 (must run after directory removal)
Files:
- Modify:
lib/crates/fabro-cli/src/commands/uninstall.rs - Test:
lib/crates/fabro-cli/tests/it/cmd/uninstall.rs
Approach:
- Use the inventory's pre-resolved
binary_pathandbinary_is_managedfields (resolved in Unit 2 before any deletion —canonicalize()fails on macOS after the file is deleted) - If
binary_is_managedis true: the binary was inside~/.fabro/bin/and was already removed by Unit 3'sremove_dir_all— report as removed - If
binary_is_managedis false: print a tailored hint- Check if path contains
/Cellar/(Homebrew): "runbrew uninstall fabro" - Check if path contains
.cargo/bin/(cargo): "runcargo uninstall fabro" - Otherwise: "The fabro binary at {path} must be removed manually."
- Check if path contains
- If
binary_pathisNone(resolution failed in Unit 2): warn and skip - Print final summary: "Fabro has been uninstalled." (bold, to stderr)
- For
--jsonoutput: includebinary_removedandbinary_hintfields
Patterns to follow:
deinit.rsfinal summary line pattern (bold text)- Package manager path detection is heuristic — keep it simple
Test scenarios:
- Happy path: binary was in
~/.fabro/bin/and was already removed by directory deletion — reports binary removed - Happy path: binary is in
/opt/homebrew/Cellar/— prints "runbrew uninstall fabro" hint - Happy path: binary is in
~/.cargo/bin/— prints "runcargo uninstall fabro" hint - Edge case: binary path detection fails (
current_exe()error) — warns but does not fail the overall uninstall - Happy path: final summary message is printed after all steps complete
Verification:
- When binary was installed via
install.sh, it is deleted or confirmed deleted - When binary was installed via other means, a clear removal instruction is printed
fabro uninstall --yes --jsonoutputs valid JSON including inventory, execution results, and binary status- The command exits successfully after all steps
System-Wide Impact
- Interaction graph: The uninstall command interacts with:
server::stop(server lifecycle),Home/Storage(path resolution), shell config files (external to fabro), and the running binary itself. No callbacks, middleware, or observers are affected. - Error propagation: Each step warns on failure but continues. Critical steps (server stop, directory removal) affect the exit code (exit 1 on failure). Non-critical steps (shell config, binary) warn only. A partial uninstall is better than aborting on the first error.
- State lifecycle risks: Stopping the server terminates in-flight workflow runs — the dry-run preview warns about this. Mitigated by mandatory server stop as the first step (prevents filesystem corruption) and by defaulting to dry-run (gives user a chance to see the warning before committing).
- API surface parity: No API endpoint equivalent needed — uninstall is a local-only operation.
- Unchanged invariants:
fabro install,fabro server,fabro repo deinit, andsystem pruneare not modified by this plan. The uninstall command reuses their code but does not change their behavior.
Risks & Dependencies
| Risk | Mitigation |
|---|---|
| Shell config surgery corrupts user's dotfiles | Use sentinel-based detection (not regex on PATH content). Only remove exact # fabro + next line. Write tests with realistic file content. |
| Binary self-deletion race condition | Delete binary as the absolute last step. On Unix, unlink of a running binary is safe (inode persists until process exits). |
$FABRO_HOME set to dangerous path (/, $HOME) |
Safety guardrail: validate resolved path is not a root or home dir, and contains expected marker files, before remove_dir_all. |
| Server stop timeout blocks uninstall | Use a short timeout (5s). SIGKILL as fallback. Continue with removal even if stop fails. |
stop::execute() exits process when no server found |
Guard with active_server_record_details() check; never call stop::execute() unconditionally. |
canonicalize() fails after file deletion on macOS |
Resolve binary path during inventory phase (Unit 2), before any deletion occurs. |
Non-default storage_dir in settings.toml |
Load settings during inventory to resolve actual storage_dir; don't assume it's inside ~/.fabro/. |
$ZDOTDIR differs between install and uninstall time |
Known limitation — document it. Uninstall uses current $ZDOTDIR. |
Partial remove_dir_all failure (locked files on macOS) |
Warn and report which files remain. Exit 1. User can retry or manually remove. |
Sources & References
- Origin document: docs/ideation/2026-04-08-fabro-uninstall-ideation.md
- Related code:
lib/crates/fabro-cli/src/commands/install.rs,lib/crates/fabro-cli/src/commands/server/stop.rs,lib/crates/fabro-cli/src/commands/system/prune.rs,lib/crates/fabro-cli/src/commands/repo/deinit.rs - Related code:
lib/crates/fabro-util/src/home.rs,lib/crates/fabro-config/src/storage.rs - Related code:
apps/marketing/public/install.sh