| 3745 | } |
| 3746 | |
| 3747 | int cbm_cmd_install(int argc, char **argv) { |
| 3748 | parse_auto_answer(argc, argv); |
| 3749 | bool dry_run = false; |
| 3750 | bool force = false; |
| 3751 | bool plan = false; |
| 3752 | bool reset_indexes = false; |
| 3753 | for (int i = 0; i < argc; i++) { |
| 3754 | if (strcmp(argv[i], "--dry-run") == 0) { |
| 3755 | dry_run = true; |
| 3756 | } |
| 3757 | if (strcmp(argv[i], "--force") == 0) { |
| 3758 | force = true; |
| 3759 | } |
| 3760 | if (strcmp(argv[i], "--plan") == 0) { |
| 3761 | plan = true; |
| 3762 | } |
| 3763 | /* Opt-in: delete existing indexes during install. Default preserves |
| 3764 | * the indexed graph (#607). Only this flag triggers deletion. */ |
| 3765 | if (strcmp(argv[i], "--reset-indexes") == 0) { |
| 3766 | reset_indexes = true; |
| 3767 | } |
| 3768 | } |
| 3769 | |
| 3770 | const char *home = cbm_get_home_dir(); |
| 3771 | if (!home) { |
| 3772 | (void)fprintf(stderr, "error: HOME not set (use USERPROFILE on Windows)\n"); |
| 3773 | return CLI_TRUE; |
| 3774 | } |
| 3775 | |
| 3776 | /* --plan: emit the machine-readable install receipt and exit WITHOUT |
| 3777 | * mutating anything (no config writes, no index deletion, no network) so |
| 3778 | * an agent can inspect exactly what install would touch first (#388). */ |
| 3779 | if (plan) { |
| 3780 | char self_path[CLI_BUF_1K] = {0}; |
| 3781 | cbm_detect_self_path(self_path, sizeof(self_path), home); |
| 3782 | char *json = cbm_build_install_plan_json(home, self_path); |
| 3783 | if (!json) { |
| 3784 | (void)fprintf(stderr, "error: failed to build install plan\n"); |
| 3785 | return CLI_TRUE; |
| 3786 | } |
| 3787 | printf("%s\n", json); |
| 3788 | free(json); |
| 3789 | return 0; |
| 3790 | } |
| 3791 | |
| 3792 | printf("codebase-memory-mcp install %s\n\n", CBM_VERSION); |
| 3793 | |
| 3794 | /* (#607) Default: preserve existing indexes. `--reset-indexes` opts into |
| 3795 | * the old prompt-and-delete behaviour. The helper returns 0 only when the |
| 3796 | * user declines the reset prompt, in which case we abort the install. */ |
| 3797 | if (cbm_install_handle_existing_indexes(home, reset_indexes, dry_run) == 0) { |
| 3798 | return CLI_TRUE; |
| 3799 | } |
| 3800 | |
| 3801 | /* Step 1b: Kill running MCP server instances so agents pick up new config */ |
| 3802 | if (!dry_run) { |
| 3803 | int killed = cbm_kill_other_instances(); |
| 3804 | if (killed > 0) { |
no test coverage detected