Skip to content

Commit 0374af1

Browse files
committed
feat(cli): let install target chosen clients (DeusData#1558)
`install` configured EVERY detected client. Someone who wanted Claude and Codex had to revert the OpenCode and Cursor integrations by hand — and the next `install`/`update` silently recreated them, so the choice could not be made to stick. Reported by @PsyTech-Rob. `--clients=claude,codex` restricts it. Omitting the flag keeps today's behaviour, so nothing changes for anyone not asking for this. The vocabulary is what makes the flag usable rather than decorative. 26 clients ship here, several with tokens nobody would guess — factory-droid, mistral-vibe, copilot-cli, kilocode. So: - `install --clients` prints every token with its display name and an example; - an unknown token FAILS and prints that same list. Silently treating a typo as "that client was not detected" would configure nothing and report success, which is the failure mode this project keeps having to fix; - validation runs before anything is written, so a typo cannot strand a half-configured install. The test pins the whole table rather than a sample: every token must resolve, so a client added to detection but forgotten in the selector's list is caught here instead of by a user who cannot select it. Per the maintainer's decision `install` keeps its name — splitting it into a separate `setup` command (DeusData#1566) stays a deliberate future decision rather than something folded into a fix batch. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent bd11088 commit 0374af1

3 files changed

Lines changed: 201 additions & 0 deletions

File tree

‎src/cli/cli.c‎

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
90659072
int 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};

‎src/cli/cli.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ cbm_detected_agents_t cbm_detect_agents(const char *home_dir);
194194
/* Install or refresh every detected agent integration below home. */
195195
int cbm_install_agent_configs(const char *home, const char *binary_path, bool force, bool dry_run);
196196

197+
#ifdef CBM_CLI_ENABLE_TEST_API
198+
/* #1558: client-selector vocabulary, exposed so a test can prove every token
199+
* resolves and an unknown one is rejected. */
200+
bool cbm_cli_clients_apply_selection_for_testing(const char *spec, cbm_detected_agents_t *detected);
201+
size_t cbm_cli_clients_count_for_testing(void);
202+
const char *cbm_cli_clients_token_for_testing(size_t index);
203+
#endif
204+
197205
#ifdef CBM_CLI_ENABLE_TEST_API
198206
/* #1566: name the package manager that owns a binary path, or NULL when it is
199207
* not recognisably foreign. Detection must be positive evidence — see the

‎tests/test_cli.c‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12220,6 +12220,50 @@ TEST(cli_external_manager_detection_needs_positive_evidence_issue1566) {
1222012220
PASS();
1222112221
}
1222212222

12223+
/* #1558: `install` configured EVERY detected client, so a user who wanted
12224+
* Claude and Codex had to revert OpenCode and Cursor by hand — and the next
12225+
* install silently recreated them. The selector restricts it.
12226+
*
12227+
* The vocabulary is the part that makes it usable: 26 clients ship, with tokens
12228+
* nobody would guess (factory-droid, mistral-vibe, copilot-cli). A selector
12229+
* whose accepted values can only be learned by reading our source is not a
12230+
* usable selector, so this pins that every client is listed and that an unknown
12231+
* token is REJECTED rather than silently matching nothing. */
12232+
TEST(cli_clients_selector_vocabulary_is_complete_and_strict_issue1558) {
12233+
cbm_detected_agents_t all;
12234+
memset(&all, 1, sizeof(all)); /* every client "detected" */
12235+
12236+
/* A known token keeps its client and drops the rest. */
12237+
cbm_detected_agents_t sel = all;
12238+
ASSERT_TRUE(cbm_cli_clients_apply_selection_for_testing("claude,codex", &sel));
12239+
ASSERT_TRUE(sel.claude_code);
12240+
ASSERT_TRUE(sel.codex);
12241+
ASSERT_FALSE(sel.cursor);
12242+
ASSERT_FALSE(sel.opencode);
12243+
12244+
/* Whitespace around tokens is tolerated — people type it. */
12245+
cbm_detected_agents_t spaced = all;
12246+
ASSERT_TRUE(cbm_cli_clients_apply_selection_for_testing(" claude , zed ", &spaced));
12247+
ASSERT_TRUE(spaced.claude_code);
12248+
ASSERT_TRUE(spaced.zed);
12249+
ASSERT_FALSE(spaced.codex);
12250+
12251+
/* An unknown token must FAIL. Silently treating a typo as "no such client"
12252+
* would configure nothing and report success. */
12253+
cbm_detected_agents_t typo = all;
12254+
ASSERT_FALSE(cbm_cli_clients_apply_selection_for_testing("claude,codx", &typo));
12255+
12256+
/* Every token in the table must resolve — a client added to detection but
12257+
* forgotten here is invisible to the selector. */
12258+
for (size_t i = 0; i < cbm_cli_clients_count_for_testing(); i++) {
12259+
const char *token = cbm_cli_clients_token_for_testing(i);
12260+
ASSERT_NOT_NULL(token);
12261+
cbm_detected_agents_t one = all;
12262+
ASSERT_TRUE(cbm_cli_clients_apply_selection_for_testing(token, &one));
12263+
}
12264+
PASS();
12265+
}
12266+
1222312267
TEST(cli_update_accepts_retired_variant_flags_issue1544) {
1222412268
char *ui_argv[] = {"--dry-run", "--ui", "--yes"};
1222512269
char *standard_argv[] = {"--dry-run", "--standard", "--yes"};
@@ -12310,6 +12354,7 @@ SUITE(cli) {
1231012354
RUN_TEST(cli_update_already_current_does_not_quiesce_sessions);
1231112355
RUN_TEST(cli_skill_frontmatter_scalars_with_colons_are_quoted_issue1554);
1231212356
RUN_TEST(cli_external_manager_detection_needs_positive_evidence_issue1566);
12357+
RUN_TEST(cli_clients_selector_vocabulary_is_complete_and_strict_issue1558);
1231312358
RUN_TEST(cli_update_accepts_retired_variant_flags_issue1544);
1231412359
RUN_TEST(cli_update_agent_configs_finish_before_guard_release);
1231512360
RUN_TEST(cli_uninstall_quiesces_active_cohort_before_removing_binary_and_index);

0 commit comments

Comments
 (0)