Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

feat(cli): let install target chosen clients (#1558)

Martin Vogel0374af1473d4
diff --git a/src/cli/cli.c b/src/cli/cli.c
index 0946a6cc1..0ecde60ef 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -9062,9 +9062,19 @@ static void install_additional_agent_configs(const cbm_detected_agents_t *agents
}
}
+/* #1558: set by `install --clients=...` after validation, consumed at the one
+ * place detection happens. Validation runs in cbm_cmd_install so an unknown
+ * token fails before anything is written, not midway through configuring. */
+static const char *g_client_selection = NULL;
+static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected);
+static void cli_clients_print_list(FILE *out);
+
int cbm_install_agent_configs(const char *home, const char *binary_path, bool force, bool dry_run) {
g_agent_install_errors = 0;
cbm_detected_agents_t agents = cbm_detect_agents(home);
+ if (g_client_selection && !cli_clients_apply_selection(g_client_selection, &agents)) {
+ return CLI_ERR;
+ }
if (!g_install_plan) {
print_detected_agents(&agents, home);
}
@@ -9180,6 +9190,121 @@ int cbm_install_handle_existing_indexes(const char *home, bool reset, bool dry_r
return prepare_result;
}
+/* ── Client selection (#1558) ──────────────────────────────────
+ *
+ * `install` configured EVERY detected client. A user who wanted Claude and
+ * Codex had to revert the OpenCode and Cursor integrations by hand, and the
+ * next install silently recreated them. `--clients=claude,codex` restricts it.
+ *
+ * The table is the flag's vocabulary AND its documentation: 26 clients ship
+ * here, with tokens nobody would guess (factory-droid, mistral-vibe,
+ * copilot-cli), so `--clients=help` prints every token. A selector whose
+ * accepted values can only be learned from the source is not a usable
+ * selector, and an unrecognised token fails loudly with the list rather than
+ * silently configuring nothing. */
+typedef struct {
+ const char *token;
+ size_t offset;
+ const char *display;
+} cli_client_def_t;
+
+#define CLI_CLIENT(field, token, display) \
+ { token, offsetof(cbm_detected_agents_t, field), display }
+
+static const cli_client_def_t CLI_CLIENTS[] = {
+ CLI_CLIENT(claude_code, "claude", "Claude Code"),
+ CLI_CLIENT(codex, "codex", "Codex"),
+ CLI_CLIENT(gemini, "gemini", "Gemini"),
+ CLI_CLIENT(zed, "zed", "Zed"),
+ CLI_CLIENT(opencode, "opencode", "OpenCode"),
+ CLI_CLIENT(antigravity, "antigravity", "Antigravity"),
+ CLI_CLIENT(aider, "aider", "Aider"),
+ CLI_CLIENT(kilocode, "kilocode", "Kilo Code"),
+ CLI_CLIENT(vscode, "vscode", "VS Code"),
+ CLI_CLIENT(cursor, "cursor", "Cursor"),
+ CLI_CLIENT(windsurf, "windsurf", "Windsurf"),
+ CLI_CLIENT(augment, "augment", "Augment"),
+ CLI_CLIENT(openclaw, "openclaw", "OpenClaw"),
+ CLI_CLIENT(kiro, "kiro", "Kiro"),
+ CLI_CLIENT(junie, "junie", "Junie"),
+ CLI_CLIENT(hermes, "hermes", "Hermes"),
+ CLI_CLIENT(openhands, "openhands", "OpenHands"),
+ CLI_CLIENT(cline, "cline", "Cline"),
+ CLI_CLIENT(warp, "warp", "Warp"),
+ CLI_CLIENT(qwen, "qwen", "Qwen"),
+ CLI_CLIENT(copilot_cli, "copilot-cli", "Copilot CLI"),
+ CLI_CLIENT(factory_droid, "factory-droid", "Factory Droid"),
+ CLI_CLIENT(crush, "crush", "Crush"),
+ CLI_CLIENT(goose, "goose", "Goose"),
+ CLI_CLIENT(mistral_vibe, "mistral-vibe", "Mistral Vibe"),
+};
+
+enum { CLI_CLIENT_COUNT = sizeof(CLI_CLIENTS) / sizeof(CLI_CLIENTS[0]) };
+
+static void cli_clients_print_list(FILE *out) {
+ (void)fprintf(out, "Available --clients tokens:\n");
+ for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
+ (void)fprintf(out, " %-16s %s\n", CLI_CLIENTS[i].token, CLI_CLIENTS[i].display);
+ }
+ (void)fprintf(out, "\nExample: --clients=claude,codex\n"
+ "Omit --clients to configure every detected client.\n");
+}
+
+/* Restrict `detected` to the comma-separated token list. Returns false (after
+ * printing the vocabulary) when a token is unknown, so a typo can never be
+ * mistaken for "that client was not installed". */
+static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected) {
+ bool wanted[CLI_CLIENT_COUNT];
+ memset(wanted, 0, sizeof(wanted));
+ char buf[CLI_BUF_1K];
+ snprintf(buf, sizeof(buf), "%s", spec ? spec : "");
+ char *save = NULL;
+ for (char *tok = strtok_r(buf, ",", &save); tok; tok = strtok_r(NULL, ",", &save)) {
+ while (*tok == ' ') {
+ tok++;
+ }
+ size_t len = strlen(tok);
+ while (len > 0 && tok[len - 1] == ' ') {
+ tok[--len] = '\0';
+ }
+ if (!tok[0]) {
+ continue;
+ }
+ bool matched = false;
+ for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
+ if (strcmp(tok, CLI_CLIENTS[i].token) == 0) {
+ wanted[i] = true;
+ matched = true;
+ break;
+ }
+ }
+ if (!matched) {
+ (void)fprintf(stderr, "error: unknown client: %s\n\n", tok);
+ cli_clients_print_list(stderr);
+ return false;
+ }
+ }
+ for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
+ if (!wanted[i]) {
+ *(bool *)((char *)detected + CLI_CLIENTS[i].offset) = false;
+ }
+ }
+ return true;
+}
+
+#ifdef CBM_CLI_ENABLE_TEST_API
+bool cbm_cli_clients_apply_selection_for_testing(const char *spec,
+ cbm_detected_agents_t *detected) {
+ return cli_clients_apply_selection(spec, detected);
+}
+size_t cbm_cli_clients_count_for_testing(void) {
+ return CLI_CLIENT_COUNT;
+}
+const char *cbm_cli_clients_token_for_testing(size_t index) {
+ return index < CLI_CLIENT_COUNT ? CLI_CLIENTS[index].token : NULL;
+}
+#endif
+
/* ── Subcommand: install ──────────────────────────────────────── */
/* The activation flow (self-path detection, simple-copy activate) is the same
@@ -9568,6 +9693,7 @@ int cbm_cmd_install(int argc, char **argv) {
bool skip_config = false;
bool skip_binary = false;
bool force_binary = false;
+ const char *requested_clients = NULL;
const char *requested_bin_dir = NULL;
for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "--dry-run") == 0) {
@@ -9580,6 +9706,18 @@ int cbm_cmd_install(int argc, char **argv) {
reset_indexes = true;
} else if (strcmp(argv[i], "--skip-config") == 0) {
skip_config = true;
+ } else if (strncmp(argv[i], "--clients=", SLEN("--clients=")) == 0) {
+ requested_clients = argv[i] + SLEN("--clients=");
+ if (!requested_clients[0]) {
+ (void)fprintf(stderr, "error: --clients requires a value\n\n");
+ cli_clients_print_list(stderr);
+ return CLI_TRUE;
+ }
+ } else if (strcmp(argv[i], "--clients") == 0) {
+ /* Bare `--clients` (and `--clients=help`/`list`) print the
+ * vocabulary. 26 clients ship with tokens nobody would guess. */
+ cli_clients_print_list(stdout);
+ return 0;
} else if (strcmp(argv[i], "--skip-binary") == 0) {
/* #1566: the mirror of --skip-config. Configure the agents, leave
* the binary and PATH alone. */
@@ -9646,6 +9784,16 @@ int cbm_cmd_install(int argc, char **argv) {
return 0;
}
+ /* #1558: validate the client tokens BEFORE anything is written, so a typo
+ * fails immediately instead of part-way through configuring. */
+ if (requested_clients) {
+ cbm_detected_agents_t probe = cbm_detect_agents(home);
+ if (!cli_clients_apply_selection(requested_clients, &probe)) {
+ return CLI_TRUE;
+ }
+ g_client_selection = requested_clients;
+ }
+
printf("codebase-memory-mcp install %s\n\n", CBM_VERSION);
char self_path[CLI_BUF_1K] = {0};
diff --git a/src/cli/cli.h b/src/cli/cli.h
index 6ddf9e35a..db5e13979 100644
--- a/src/cli/cli.h
+++ b/src/cli/cli.h
@@ -194,6 +194,14 @@ cbm_detected_agents_t cbm_detect_agents(const char *home_dir);
/* Install or refresh every detected agent integration below home. */
int cbm_install_agent_configs(const char *home, const char *binary_path, bool force, bool dry_run);
+#ifdef CBM_CLI_ENABLE_TEST_API
+/* #1558: client-selector vocabulary, exposed so a test can prove every token
+ * resolves and an unknown one is rejected. */
+bool cbm_cli_clients_apply_selection_for_testing(const char *spec, cbm_detected_agents_t *detected);
+size_t cbm_cli_clients_count_for_testing(void);
+const char *cbm_cli_clients_token_for_testing(size_t index);
+#endif
+
#ifdef CBM_CLI_ENABLE_TEST_API
/* #1566: name the package manager that owns a binary path, or NULL when it is
* not recognisably foreign. Detection must be positive evidence — see the
diff --git a/tests/test_cli.c b/tests/test_cli.c
index 6d8690c5f..75b086c7a 100644
--- a/tests/test_cli.c
+++ b/tests/test_cli.c
@@ -12220,6 +12220,50 @@ TEST(cli_external_manager_detection_needs_positive_evidence_issue1566) {
PASS();
}
+/* #1558: `install` configured EVERY detected client, so a user who wanted
+ * Claude and Codex had to revert OpenCode and Cursor by hand — and the next
+ * install silently recreated them. The selector restricts it.
+ *
+ * The vocabulary is the part that makes it usable: 26 clients ship, with tokens
+ * nobody would guess (factory-droid, mistral-vibe, copilot-cli). A selector
+ * whose accepted values can only be learned by reading our source is not a
+ * usable selector, so this pins that every client is listed and that an unknown
+ * token is REJECTED rather than silently matching nothing. */
+TEST(cli_clients_selector_vocabulary_is_complete_and_strict_issue1558) {
+ cbm_detected_agents_t all;
+ memset(&all, 1, sizeof(all)); /* every client "detected" */
+
+ /* A known token keeps its client and drops the rest. */
+ cbm_detected_agents_t sel = all;
+ ASSERT_TRUE(cbm_cli_clients_apply_selection_for_testing("claude,codex", &sel));
+ ASSERT_TRUE(sel.claude_code);
+ ASSERT_TRUE(sel.codex);
+ ASSERT_FALSE(sel.cursor);
+ ASSERT_FALSE(sel.opencode);
+
+ /* Whitespace around tokens is tolerated — people type it. */
+ cbm_detected_agents_t spaced = all;
+ ASSERT_TRUE(cbm_cli_clients_apply_selection_for_testing(" claude , zed ", &spaced));
+ ASSERT_TRUE(spaced.claude_code);
+ ASSERT_TRUE(spaced.zed);
+ ASSERT_FALSE(spaced.codex);
+
+ /* An unknown token must FAIL. Silently treating a typo as "no such client"
+ * would configure nothing and report success. */
+ cbm_detected_agents_t typo = all;
+ ASSERT_FALSE(cbm_cli_clients_apply_selection_for_testing("claude,codx", &typo));
+
+ /* Every token in the table must resolve — a client added to detection but
+ * forgotten here is invisible to the selector. */
+ for (size_t i = 0; i < cbm_cli_clients_count_for_testing(); i++) {
+ const char *token = cbm_cli_clients_token_for_testing(i);
+ ASSERT_NOT_NULL(token);
+ cbm_detected_agents_t one = all;
+ ASSERT_TRUE(cbm_cli_clients_apply_selection_for_testing(token, &one));
+ }
+ PASS();
+}
+
TEST(cli_update_accepts_retired_variant_flags_issue1544) {
char *ui_argv[] = {"--dry-run", "--ui", "--yes"};
char *standard_argv[] = {"--dry-run", "--standard", "--yes"};
@@ -12310,6 +12354,7 @@ SUITE(cli) {
RUN_TEST(cli_update_already_current_does_not_quiesce_sessions);
RUN_TEST(cli_skill_frontmatter_scalars_with_colons_are_quoted_issue1554);
RUN_TEST(cli_external_manager_detection_needs_positive_evidence_issue1566);
+ RUN_TEST(cli_clients_selector_vocabulary_is_complete_and_strict_issue1558);
RUN_TEST(cli_update_accepts_retired_variant_flags_issue1544);
RUN_TEST(cli_update_agent_configs_finish_before_guard_release);
RUN_TEST(cli_uninstall_quiesces_active_cohort_before_removing_binary_and_index);