NemoClaw/uninstall.sh
Tinson Lai 2efe25b52d
fix(uninstall): add --destroy-user-data flag to purge preserved data (#5784)
<!-- markdownlint-disable MD041 -->
## Summary

`nemoclaw uninstall --yes` is non-destructive by design — it preserves
`~/.nemoclaw/rebuild-backups/`, `~/.nemoclaw/backups/`, and
`~/.nemoclaw/sandboxes.json`, leaving the state directory non-empty. The
only escape hatch today is the `NEMOCLAW_UNINSTALL_DESTROY_USER_DATA=1`
env var, which is not discoverable from `--help` or the usage banner.
Add a first-class `--destroy-user-data` CLI flag that mirrors the
env-var semantics so users who want a clean uninstall have a visible
flag to reach for, without changing the safe `--yes` default.

## Related Issue

Fixes #5780

## Changes

- `src/commands/internal/uninstall/run-plan.ts`: declare a
`destroy-user-data` boolean flag and forward it into
`UninstallRunOptions.destroyUserData`.
- `src/lib/actions/uninstall/run-plan.ts`: extend `UninstallRunOptions`
with `destroyUserData?: boolean`; `resolvePreserveSet` now checks the
flag before the env var and logs `--destroy-user-data set; purging user
data under ~/.nemoclaw/.` when it triggers; the non-interactive preserve
notice now mentions both the flag and the env var. **Note: the flag is
opt-in precisely to avoid changing the existing safe `--yes` default —
but the flag itself is destructive, so a user (or script) invoking it
without intent will lose the preserved user data.**
- `uninstall.sh`: extend the usage banner with the new flag.
- `src/lib/actions/uninstall/run-plan.test.ts`: four new tests — non-TTY
plus `--yes` plus `--destroy-user-data` purges, TTY plus flag purges
without prompting, flag takes precedence over
`NEMOCLAW_UNINSTALL_DESTROY_USER_DATA=1`, and the preserve hint mentions
both the flag and the env var.
- `docs/manage-sandboxes/lifecycle.mdx`, `docs/reference/commands.mdx`,
`docs/reference/commands-nemohermes.mdx`: add the new flag to the
uninstall flags table, the usage line, and the user-data decision
matrix.

## Type of Change

- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Verification

- [x] PR description includes the DCO sign-off declaration and every
commit appears as `Verified` in GitHub
- [x] Git hooks passed during commit and push, or `npx prek run
--from-ref main --to-ref HEAD` passes
- [x] Targeted tests pass for changed behavior
- [ ] Full `npm test` passes (broad runtime changes only)
- [x] Tests added or updated for new or changed behavior
- [x] No secrets, API keys, or credentials committed
- [x] Docs updated for user-facing behavior changes
- [ ] `npm run docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

---
Signed-off-by: Tinson Lai <tinsonl@nvidia.com>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a `--destroy-user-data` option to uninstall flows, including the
CLI help and reference usage.
* Updated uninstall decision behavior to support full removal of
preserved `~/.nemoclaw/` user data.

* **Bug Fixes**
* Clarified that `--yes` only confirms; preserved `~/.nemoclaw/` data
remains unless `--destroy-user-data` (or the documented env override) is
provided.
* Improved prompts and messaging for interactive vs non-interactive
runs, including secondary confirmation behavior.

* **Documentation**
* Expanded uninstall lifecycle and command reference docs with the new
flag and decision matrix.

* **Tests**
  * Added/updated coverage for preservation vs full purge scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
2026-06-30 14:15:59 -04:00

26 lines
817 B
Bash
Executable file

#!/usr/bin/env bash
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Compatibility wrapper for the TypeScript NemoClaw uninstaller.
#
# Usage: ./uninstall.sh [--yes] [--keep-openshell] [--delete-models] [--destroy-user-data]
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CLI_JS="${NEMOCLAW_CLI_JS:-$SCRIPT_DIR/dist/nemoclaw.js}"
if [ -f "$CLI_JS" ]; then
NODE_BIN="${NEMOCLAW_NODE:-${NODE:-}}"
if [ -z "$NODE_BIN" ]; then
NODE_BIN="$(command -v node || true)"
fi
if [ -z "$NODE_BIN" ]; then
echo "ERROR: node is required to run the NemoClaw uninstaller." >&2
exit 127
fi
exec "$NODE_BIN" "$CLI_JS" internal uninstall run-plan "$@"
fi
exec nemoclaw internal uninstall run-plan "$@"