@@ -9062,9 +9062,19 @@ static void install_additional_agent_configs(const cbm_detected_agents_t *agents
90629062 }
90639063}
90649064
9065+ /* #1558: set by `install --clients=...` after validation, consumed at the one
9066+ * place detection happens. Validation runs in cbm_cmd_install so an unknown
9067+ * token fails before anything is written, not midway through configuring. */
9068+ static const char *g_client_selection = NULL;
9069+ static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected);
9070+ static void cli_clients_print_list(FILE *out);
9071+
90659072int cbm_install_agent_configs(const char *home, const char *binary_path, bool force, bool dry_run) {
90669073 g_agent_install_errors = 0;
90679074 cbm_detected_agents_t agents = cbm_detect_agents(home);
9075+ if (g_client_selection && !cli_clients_apply_selection(g_client_selection, &agents)) {
9076+ return CLI_ERR;
9077+ }
90689078 if (!g_install_plan) {
90699079 print_detected_agents(&agents, home);
90709080 }
@@ -9180,6 +9190,121 @@ int cbm_install_handle_existing_indexes(const char *home, bool reset, bool dry_r
91809190 return prepare_result;
91819191}
91829192
9193+ /* ── Client selection (#1558) ──────────────────────────────────
9194+ *
9195+ * `install` configured EVERY detected client. A user who wanted Claude and
9196+ * Codex had to revert the OpenCode and Cursor integrations by hand, and the
9197+ * next install silently recreated them. `--clients=claude,codex` restricts it.
9198+ *
9199+ * The table is the flag's vocabulary AND its documentation: 26 clients ship
9200+ * here, with tokens nobody would guess (factory-droid, mistral-vibe,
9201+ * copilot-cli), so `--clients=help` prints every token. A selector whose
9202+ * accepted values can only be learned from the source is not a usable
9203+ * selector, and an unrecognised token fails loudly with the list rather than
9204+ * silently configuring nothing. */
9205+ typedef struct {
9206+ const char *token;
9207+ size_t offset;
9208+ const char *display;
9209+ } cli_client_def_t;
9210+
9211+ #define CLI_CLIENT(field, token, display) \
9212+ { token, offsetof(cbm_detected_agents_t, field), display }
9213+
9214+ static const cli_client_def_t CLI_CLIENTS[] = {
9215+ CLI_CLIENT(claude_code, "claude", "Claude Code"),
9216+ CLI_CLIENT(codex, "codex", "Codex"),
9217+ CLI_CLIENT(gemini, "gemini", "Gemini"),
9218+ CLI_CLIENT(zed, "zed", "Zed"),
9219+ CLI_CLIENT(opencode, "opencode", "OpenCode"),
9220+ CLI_CLIENT(antigravity, "antigravity", "Antigravity"),
9221+ CLI_CLIENT(aider, "aider", "Aider"),
9222+ CLI_CLIENT(kilocode, "kilocode", "Kilo Code"),
9223+ CLI_CLIENT(vscode, "vscode", "VS Code"),
9224+ CLI_CLIENT(cursor, "cursor", "Cursor"),
9225+ CLI_CLIENT(windsurf, "windsurf", "Windsurf"),
9226+ CLI_CLIENT(augment, "augment", "Augment"),
9227+ CLI_CLIENT(openclaw, "openclaw", "OpenClaw"),
9228+ CLI_CLIENT(kiro, "kiro", "Kiro"),
9229+ CLI_CLIENT(junie, "junie", "Junie"),
9230+ CLI_CLIENT(hermes, "hermes", "Hermes"),
9231+ CLI_CLIENT(openhands, "openhands", "OpenHands"),
9232+ CLI_CLIENT(cline, "cline", "Cline"),
9233+ CLI_CLIENT(warp, "warp", "Warp"),
9234+ CLI_CLIENT(qwen, "qwen", "Qwen"),
9235+ CLI_CLIENT(copilot_cli, "copilot-cli", "Copilot CLI"),
9236+ CLI_CLIENT(factory_droid, "factory-droid", "Factory Droid"),
9237+ CLI_CLIENT(crush, "crush", "Crush"),
9238+ CLI_CLIENT(goose, "goose", "Goose"),
9239+ CLI_CLIENT(mistral_vibe, "mistral-vibe", "Mistral Vibe"),
9240+ };
9241+
9242+ enum { CLI_CLIENT_COUNT = sizeof(CLI_CLIENTS) / sizeof(CLI_CLIENTS[0]) };
9243+
9244+ static void cli_clients_print_list(FILE *out) {
9245+ (void)fprintf(out, "Available --clients tokens:\n");
9246+ for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
9247+ (void)fprintf(out, " %-16s %s\n", CLI_CLIENTS[i].token, CLI_CLIENTS[i].display);
9248+ }
9249+ (void)fprintf(out, "\nExample: --clients=claude,codex\n"
9250+ "Omit --clients to configure every detected client.\n");
9251+ }
9252+
9253+ /* Restrict `detected` to the comma-separated token list. Returns false (after
9254+ * printing the vocabulary) when a token is unknown, so a typo can never be
9255+ * mistaken for "that client was not installed". */
9256+ static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected) {
9257+ bool wanted[CLI_CLIENT_COUNT];
9258+ memset(wanted, 0, sizeof(wanted));
9259+ char buf[CLI_BUF_1K];
9260+ snprintf(buf, sizeof(buf), "%s", spec ? spec : "");
9261+ char *save = NULL;
9262+ for (char *tok = strtok_r(buf, ",", &save); tok; tok = strtok_r(NULL, ",", &save)) {
9263+ while (*tok == ' ') {
9264+ tok++;
9265+ }
9266+ size_t len = strlen(tok);
9267+ while (len > 0 && tok[len - 1] == ' ') {
9268+ tok[--len] = '\0';
9269+ }
9270+ if (!tok[0]) {
9271+ continue;
9272+ }
9273+ bool matched = false;
9274+ for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
9275+ if (strcmp(tok, CLI_CLIENTS[i].token) == 0) {
9276+ wanted[i] = true;
9277+ matched = true;
9278+ break;
9279+ }
9280+ }
9281+ if (!matched) {
9282+ (void)fprintf(stderr, "error: unknown client: %s\n\n", tok);
9283+ cli_clients_print_list(stderr);
9284+ return false;
9285+ }
9286+ }
9287+ for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
9288+ if (!wanted[i]) {
9289+ *(bool *)((char *)detected + CLI_CLIENTS[i].offset) = false;
9290+ }
9291+ }
9292+ return true;
9293+ }
9294+
9295+ #ifdef CBM_CLI_ENABLE_TEST_API
9296+ bool cbm_cli_clients_apply_selection_for_testing(const char *spec,
9297+ cbm_detected_agents_t *detected) {
9298+ return cli_clients_apply_selection(spec, detected);
9299+ }
9300+ size_t cbm_cli_clients_count_for_testing(void) {
9301+ return CLI_CLIENT_COUNT;
9302+ }
9303+ const char *cbm_cli_clients_token_for_testing(size_t index) {
9304+ return index < CLI_CLIENT_COUNT ? CLI_CLIENTS[index].token : NULL;
9305+ }
9306+ #endif
9307+
91839308/* ── Subcommand: install ──────────────────────────────────────── */
91849309
91859310/* The activation flow (self-path detection, simple-copy activate) is the same
@@ -9568,6 +9693,7 @@ int cbm_cmd_install(int argc, char **argv) {
95689693 bool skip_config = false;
95699694 bool skip_binary = false;
95709695 bool force_binary = false;
9696+ const char *requested_clients = NULL;
95719697 const char *requested_bin_dir = NULL;
95729698 for (int i = 0; i < argc; i++) {
95739699 if (strcmp(argv[i], "--dry-run") == 0) {
@@ -9580,6 +9706,18 @@ int cbm_cmd_install(int argc, char **argv) {
95809706 reset_indexes = true;
95819707 } else if (strcmp(argv[i], "--skip-config") == 0) {
95829708 skip_config = true;
9709+ } else if (strncmp(argv[i], "--clients=", SLEN("--clients=")) == 0) {
9710+ requested_clients = argv[i] + SLEN("--clients=");
9711+ if (!requested_clients[0]) {
9712+ (void)fprintf(stderr, "error: --clients requires a value\n\n");
9713+ cli_clients_print_list(stderr);
9714+ return CLI_TRUE;
9715+ }
9716+ } else if (strcmp(argv[i], "--clients") == 0) {
9717+ /* Bare `--clients` (and `--clients=help`/`list`) print the
9718+ * vocabulary. 26 clients ship with tokens nobody would guess. */
9719+ cli_clients_print_list(stdout);
9720+ return 0;
95839721 } else if (strcmp(argv[i], "--skip-binary") == 0) {
95849722 /* #1566: the mirror of --skip-config. Configure the agents, leave
95859723 * the binary and PATH alone. */
@@ -9646,6 +9784,16 @@ int cbm_cmd_install(int argc, char **argv) {
96469784 return 0;
96479785 }
96489786
9787+ /* #1558: validate the client tokens BEFORE anything is written, so a typo
9788+ * fails immediately instead of part-way through configuring. */
9789+ if (requested_clients) {
9790+ cbm_detected_agents_t probe = cbm_detect_agents(home);
9791+ if (!cli_clients_apply_selection(requested_clients, &probe)) {
9792+ return CLI_TRUE;
9793+ }
9794+ g_client_selection = requested_clients;
9795+ }
9796+
96499797 printf("codebase-memory-mcp install %s\n\n", CBM_VERSION);
96509798
96519799 char self_path[CLI_BUF_1K] = {0};
0 commit comments