Skip to content

Commit 5e6fa65

Browse files
authored
Merge pull request DeusData#2517 from DeusData/fix/uninstall-keeps-indexes-v2
fix(cli): keep project indexes by default during uninstall
2 parents 20fd3aa + 4793550 commit 5e6fa65

5 files changed

Lines changed: 405 additions & 37 deletions

File tree

‎README.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,14 @@ Installed through **npm or pip**? Update with your package manager on every plat
185185
codebase-memory-mcp uninstall
186186
```
187187

188-
Removes owned agent config entries, skills, hooks, instructions, and the installed binary. Existing graph indexes are listed and deleted only after confirmation.
188+
Removes owned agent config entries, skills, hooks, instructions, and the installed binary. Existing graph indexes are listed and **kept by default**. `-y`/`--yes`, `-n`/`--no`, and noninteractive input keep them unless `--delete-indexes` is explicitly given. An interactive terminal without that flag is asked separately; the default answer is to keep them.
189+
190+
```bash
191+
codebase-memory-mcp uninstall -y --delete-indexes # also delete every project index
192+
codebase-memory-mcp uninstall --dry-run --delete-indexes # preview; change nothing
193+
```
194+
195+
`--delete-indexes` is explicit consent and takes precedence over `--no`; `--dry-run` always preserves the files. When indexes are kept, uninstall prints their cache directory (`${CBM_CACHE_DIR:-~/.cache/codebase-memory-mcp}`) and how to remove them.
189196

190197
The install script placed beside the binary is **reported, not deleted** — uninstall prints its path and the `rm` command for it. It is left alone on purpose: it may be your own copy, a symlink into a checkout, or managed by a package manager, and an uninstaller should not delete a file it cannot prove it owns.
191198

‎pkg/npm/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ codebase-memory-mcp install # configure all detected coding agents
5555
codebase-memory-mcp --version
5656
codebase-memory-mcp --help
5757
codebase-memory-mcp update # update to latest release
58-
codebase-memory-mcp uninstall # remove agent configs
58+
codebase-memory-mcp uninstall # remove agent configs; keep indexes by default
5959
```
6060

61+
Uninstall keeps project indexes with `--yes`, `--no`, or noninteractive input unless you explicitly add `--delete-indexes`. An interactive terminal without the flag asks separately and defaults to keeping them. `--delete-indexes` overrides `--no`; add `--dry-run` to preview without changing files. Kept indexes remain in the cache directory printed by uninstall.
62+
6163
### CLI Mode
6264

6365
Every MCP tool is also available directly from the command line:

‎src/cli/cli.c‎

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12943,6 +12943,41 @@ static int cli_uninstall_activate(void *opaque) {
1294312943
return CLI_OK;
1294412944
}
1294512945

12946+
/* A generic auto-answer is not consent to erase project indexes. An explicit
12947+
* --delete-indexes takes precedence even over --no; otherwise only a separate
12948+
* interactive answer can select deletion. This helper decides and reports,
12949+
* but all deletion remains in the final guarded uninstall activation. */
12950+
static bool uninstall_decide_index_deletion(const char *home, bool requested, bool dry_run) {
12951+
int index_count = count_db_indexes(home);
12952+
if (index_count <= 0) {
12953+
return false;
12954+
}
12955+
printf("\nFound %d index(es):\n", index_count);
12956+
cbm_list_indexes(home);
12957+
bool delete_indexes = requested;
12958+
if (!requested) {
12959+
bool can_ask = g_auto_answer == 0;
12960+
#ifdef _WIN32
12961+
can_ask = can_ask && _isatty(_fileno(stdin));
12962+
#else
12963+
can_ask = can_ask && isatty(fileno(stdin));
12964+
#endif
12965+
delete_indexes = can_ask && prompt_yn("Delete these indexes? (default: no)");
12966+
}
12967+
if (!delete_indexes) {
12968+
const char *cache_dir = get_cache_dir(home);
12969+
printf("Indexes kept in %s. To remove them, uninstall with --delete-indexes "
12970+
"or delete the project .db files there.\n",
12971+
cache_dir ? cache_dir : "the cache directory");
12972+
return false;
12973+
}
12974+
if (dry_run) {
12975+
printf("(dry-run — indexes would be deleted)\n");
12976+
return false;
12977+
}
12978+
return true;
12979+
}
12980+
1294612981
int cbm_cmd_uninstall(int argc, char **argv) {
1294712982
/* `uninstall --help` used to UNINSTALL.
1294812983
*
@@ -12956,20 +12991,25 @@ int cbm_cmd_uninstall(int argc, char **argv) {
1295612991
* cannot auto-confirm the destruction we are trying to prevent. */
1295712992
for (int i = 0; i < argc; i++) {
1295812993
if (argv && argv[i] && (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)) {
12959-
printf("Usage: codebase-memory-mcp uninstall [options]\n\n"
12960-
"Removes the codebase-memory-mcp binary, its agent configurations and,\n"
12961-
"with confirmation, its indexes. THIS IS DESTRUCTIVE.\n\n"
12962-
"Options:\n"
12963-
" --dry-run Show what would be removed, change nothing\n"
12964-
" --dir=PATH Uninstall from a custom install directory\n"
12965-
" -y, --yes Do not prompt for confirmation\n"
12966-
" -h, --help Show this help and exit\n\n"
12967-
"Run with --dry-run first if you are unsure.\n");
12994+
printf(
12995+
"Usage: codebase-memory-mcp uninstall [options]\n\n"
12996+
"Removes the codebase-memory-mcp binary and its agent configurations.\n"
12997+
"THIS IS DESTRUCTIVE. Project indexes are kept by default. An interactive\n"
12998+
"terminal is asked separately; the default answer is to keep them.\n\n"
12999+
"Options:\n"
13000+
" --dry-run Show what would be removed, change nothing\n"
13001+
" --dir=PATH Uninstall from a custom install directory\n"
13002+
" --delete-indexes Also delete every project index (overrides --no)\n"
13003+
" -y, --yes Do not prompt; indexes are kept unless explicitly deleted\n"
13004+
" -n, --no Decline prompts; --delete-indexes still takes precedence\n"
13005+
" -h, --help Show this help and exit\n\n"
13006+
"Run with --dry-run first if you are unsure.\n");
1296813007
return CLI_OK;
1296913008
}
1297013009
}
1297113010
parse_auto_answer(argc, argv);
1297213011
bool dry_run = false;
13012+
bool delete_indexes_requested = false;
1297313013
/* An install into a custom --dir must be removable from that same dir:
1297413014
* without this, anyone who installed outside ~/.local/bin has no supported
1297513015
* uninstall path at all. Mirrors cbm_cmd_install's parsing. */
@@ -12982,6 +13022,8 @@ int cbm_cmd_uninstall(int argc, char **argv) {
1298213022
}
1298313023
if (strcmp(argv[i], "--dry-run") == 0) {
1298413024
dry_run = true;
13025+
} else if (strcmp(argv[i], "--delete-indexes") == 0) {
13026+
delete_indexes_requested = true;
1298513027
} else if (strncmp(argv[i], "--dir=", SLEN("--dir=")) == 0) {
1298613028
requested_bin_dir = argv[i] + SLEN("--dir=");
1298713029
if (!requested_bin_dir[0]) {
@@ -13013,23 +13055,9 @@ int cbm_cmd_uninstall(int argc, char **argv) {
1301313055
agent_uninstall_failures_reset();
1301413056
cbm_detected_agents_t agents = cbm_detect_agents(home);
1301513057

13016-
/* Confirm index removal outside the startup lock, but defer the mutation
13017-
* until the final guarded activation. Dry-run never removes indexes. */
13018-
bool delete_indexes = false;
13019-
int index_count = count_db_indexes(home);
13020-
if (index_count > 0) {
13021-
printf("\nFound %d index(es):\n", index_count);
13022-
cbm_list_indexes(home);
13023-
if (prompt_yn("Delete these indexes?")) {
13024-
if (dry_run) {
13025-
printf("(dry-run — indexes would be deleted)\n");
13026-
} else {
13027-
delete_indexes = true;
13028-
}
13029-
} else {
13030-
printf("Indexes kept.\n");
13031-
}
13032-
}
13058+
/* Decide outside the startup lock; mutate only in the final guarded
13059+
* activation. Dry-run never authorizes actual index removal. */
13060+
bool delete_indexes = uninstall_decide_index_deletion(home, delete_indexes_requested, dry_run);
1303313061

1303413062
char bin_path_storage[CLI_BUF_1K];
1303513063
const char *bin_path = bin_path_storage;

‎src/main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ static void print_help(void) {
11071107
"[--dir=<path>] [--skip-config]\n");
11081108
printf(" [--clients=<tokens>] Run "
11091109
"'install --clients' to list tokens\n");
1110-
printf(" codebase-memory-mcp uninstall [-y|-n] [--dry-run]\n");
1110+
printf(" codebase-memory-mcp uninstall [-y|-n] [--dry-run] [--delete-indexes]\n");
11111111
printf(" codebase-memory-mcp update [-y|-n]\n");
11121112
printf(" codebase-memory-mcp config <list|get|set|reset>\n");
11131113
printf(" codebase-memory-mcp --version Print version\n");

0 commit comments

Comments
 (0)