Skip to content

Commit bb2b990

Browse files
authored
Merge pull request DeusData#1586 from DeusData/feat/install-clients-selector
feat(cli): let install target chosen clients (DeusData#1558)
2 parents 6b2650c + 0374af1 commit bb2b990

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
@@ -9033,9 +9033,19 @@ static void install_additional_agent_configs(const cbm_detected_agents_t *agents
90339033
}
90349034
}
90359035

9036+
/* #1558: set by `install --clients=...` after validation, consumed at the one
9037+
* place detection happens. Validation runs in cbm_cmd_install so an unknown
9038+
* token fails before anything is written, not midway through configuring. */
9039+
static const char *g_client_selection = NULL;
9040+
static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected);
9041+
static void cli_clients_print_list(FILE *out);
9042+
90369043
int cbm_install_agent_configs(const char *home, const char *binary_path, bool force, bool dry_run) {
90379044
g_agent_install_errors = 0;
90389045
cbm_detected_agents_t agents = cbm_detect_agents(home);
9046+
if (g_client_selection && !cli_clients_apply_selection(g_client_selection, &agents)) {
9047+
return CLI_ERR;
9048+
}
90399049
if (!g_install_plan) {
90409050
print_detected_agents(&agents, home);
90419051
}
@@ -9151,6 +9161,121 @@ int cbm_install_handle_existing_indexes(const char *home, bool reset, bool dry_r
91519161
return prepare_result;
91529162
}
91539163

9164+
/* ── Client selection (#1558) ──────────────────────────────────
9165+
*
9166+
* `install` configured EVERY detected client. A user who wanted Claude and
9167+
* Codex had to revert the OpenCode and Cursor integrations by hand, and the
9168+
* next install silently recreated them. `--clients=claude,codex` restricts it.
9169+
*
9170+
* The table is the flag's vocabulary AND its documentation: 26 clients ship
9171+
* here, with tokens nobody would guess (factory-droid, mistral-vibe,
9172+
* copilot-cli), so `--clients=help` prints every token. A selector whose
9173+
* accepted values can only be learned from the source is not a usable
9174+
* selector, and an unrecognised token fails loudly with the list rather than
9175+
* silently configuring nothing. */
9176+
typedef struct {
9177+
const char *token;
9178+
size_t offset;
9179+
const char *display;
9180+
} cli_client_def_t;
9181+
9182+
#define CLI_CLIENT(field, token, display) \
9183+
{ token, offsetof(cbm_detected_agents_t, field), display }
9184+
9185+
static const cli_client_def_t CLI_CLIENTS[] = {
9186+
CLI_CLIENT(claude_code, "claude", "Claude Code"),
9187+
CLI_CLIENT(codex, "codex", "Codex"),
9188+
CLI_CLIENT(gemini, "gemini", "Gemini"),
9189+
CLI_CLIENT(zed, "zed", "Zed"),
9190+
CLI_CLIENT(opencode, "opencode", "OpenCode"),
9191+
CLI_CLIENT(antigravity, "antigravity", "Antigravity"),
9192+
CLI_CLIENT(aider, "aider", "Aider"),
9193+
CLI_CLIENT(kilocode, "kilocode", "Kilo Code"),
9194+
CLI_CLIENT(vscode, "vscode", "VS Code"),
9195+
CLI_CLIENT(cursor, "cursor", "Cursor"),
9196+
CLI_CLIENT(windsurf, "windsurf", "Windsurf"),
9197+
CLI_CLIENT(augment, "augment", "Augment"),
9198+
CLI_CLIENT(openclaw, "openclaw", "OpenClaw"),
9199+
CLI_CLIENT(kiro, "kiro", "Kiro"),
9200+
CLI_CLIENT(junie, "junie", "Junie"),
9201+
CLI_CLIENT(hermes, "hermes", "Hermes"),
9202+
CLI_CLIENT(openhands, "openhands", "OpenHands"),
9203+
CLI_CLIENT(cline, "cline", "Cline"),
9204+
CLI_CLIENT(warp, "warp", "Warp"),
9205+
CLI_CLIENT(qwen, "qwen", "Qwen"),
9206+
CLI_CLIENT(copilot_cli, "copilot-cli", "Copilot CLI"),
9207+
CLI_CLIENT(factory_droid, "factory-droid", "Factory Droid"),
9208+
CLI_CLIENT(crush, "crush", "Crush"),
9209+
CLI_CLIENT(goose, "goose", "Goose"),
9210+
CLI_CLIENT(mistral_vibe, "mistral-vibe", "Mistral Vibe"),
9211+
};
9212+
9213+
enum { CLI_CLIENT_COUNT = sizeof(CLI_CLIENTS) / sizeof(CLI_CLIENTS[0]) };
9214+
9215+
static void cli_clients_print_list(FILE *out) {
9216+
(void)fprintf(out, "Available --clients tokens:\n");
9217+
for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
9218+
(void)fprintf(out, " %-16s %s\n", CLI_CLIENTS[i].token, CLI_CLIENTS[i].display);
9219+
}
9220+
(void)fprintf(out, "\nExample: --clients=claude,codex\n"
9221+
"Omit --clients to configure every detected client.\n");
9222+
}
9223+
9224+
/* Restrict `detected` to the comma-separated token list. Returns false (after
9225+
* printing the vocabulary) when a token is unknown, so a typo can never be
9226+
* mistaken for "that client was not installed". */
9227+
static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected) {
9228+
bool wanted[CLI_CLIENT_COUNT];
9229+
memset(wanted, 0, sizeof(wanted));
9230+
char buf[CLI_BUF_1K];
9231+
snprintf(buf, sizeof(buf), "%s", spec ? spec : "");
9232+
char *save = NULL;
9233+
for (char *tok = strtok_r(buf, ",", &save); tok; tok = strtok_r(NULL, ",", &save)) {
9234+
while (*tok == ' ') {
9235+
tok++;
9236+
}
9237+
size_t len = strlen(tok);
9238+
while (len > 0 && tok[len - 1] == ' ') {
9239+
tok[--len] = '\0';
9240+
}
9241+
if (!tok[0]) {
9242+
continue;
9243+
}
9244+
bool matched = false;
9245+
for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
9246+
if (strcmp(tok, CLI_CLIENTS[i].token) == 0) {
9247+
wanted[i] = true;
9248+
matched = true;
9249+
break;
9250+
}
9251+
}
9252+
if (!matched) {
9253+
(void)fprintf(stderr, "error: unknown client: %s\n\n", tok);
9254+
cli_clients_print_list(stderr);
9255+
return false;
9256+
}
9257+
}
9258+
for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
9259+
if (!wanted[i]) {
9260+
*(bool *)((char *)detected + CLI_CLIENTS[i].offset) = false;
9261+
}
9262+
}
9263+
return true;
9264+
}
9265+
9266+
#ifdef CBM_CLI_ENABLE_TEST_API
9267+
bool cbm_cli_clients_apply_selection_for_testing(const char *spec,
9268+
cbm_detected_agents_t *detected) {
9269+
return cli_clients_apply_selection(spec, detected);
9270+
}
9271+
size_t cbm_cli_clients_count_for_testing(void) {
9272+
return CLI_CLIENT_COUNT;
9273+
}
9274+
const char *cbm_cli_clients_token_for_testing(size_t index) {
9275+
return index < CLI_CLIENT_COUNT ? CLI_CLIENTS[index].token : NULL;
9276+
}
9277+
#endif
9278+
91549279
/* ── Subcommand: install ──────────────────────────────────────── */
91559280

91569281
/* The activation flow (self-path detection, simple-copy activate) is the same
@@ -9539,6 +9664,7 @@ int cbm_cmd_install(int argc, char **argv) {
95399664
bool skip_config = false;
95409665
bool skip_binary = false;
95419666
bool force_binary = false;
9667+
const char *requested_clients = NULL;
95429668
const char *requested_bin_dir = NULL;
95439669
for (int i = 0; i < argc; i++) {
95449670
if (strcmp(argv[i], "--dry-run") == 0) {
@@ -9551,6 +9677,18 @@ int cbm_cmd_install(int argc, char **argv) {
95519677
reset_indexes = true;
95529678
} else if (strcmp(argv[i], "--skip-config") == 0) {
95539679
skip_config = true;
9680+
} else if (strncmp(argv[i], "--clients=", SLEN("--clients=")) == 0) {
9681+
requested_clients = argv[i] + SLEN("--clients=");
9682+
if (!requested_clients[0]) {
9683+
(void)fprintf(stderr, "error: --clients requires a value\n\n");
9684+
cli_clients_print_list(stderr);
9685+
return CLI_TRUE;
9686+
}
9687+
} else if (strcmp(argv[i], "--clients") == 0) {
9688+
/* Bare `--clients` (and `--clients=help`/`list`) print the
9689+
* vocabulary. 26 clients ship with tokens nobody would guess. */
9690+
cli_clients_print_list(stdout);
9691+
return 0;
95549692
} else if (strcmp(argv[i], "--skip-binary") == 0) {
95559693
/* #1566: the mirror of --skip-config. Configure the agents, leave
95569694
* the binary and PATH alone. */
@@ -9617,6 +9755,16 @@ int cbm_cmd_install(int argc, char **argv) {
96179755
return 0;
96189756
}
96199757

9758+
/* #1558: validate the client tokens BEFORE anything is written, so a typo
9759+
* fails immediately instead of part-way through configuring. */
9760+
if (requested_clients) {
9761+
cbm_detected_agents_t probe = cbm_detect_agents(home);
9762+
if (!cli_clients_apply_selection(requested_clients, &probe)) {
9763+
return CLI_TRUE;
9764+
}
9765+
g_client_selection = requested_clients;
9766+
}
9767+
96209768
printf("codebase-memory-mcp install %s\n\n", CBM_VERSION);
96219769

96229770
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
@@ -12306,6 +12306,50 @@ TEST(cli_external_manager_detection_needs_positive_evidence_issue1566) {
1230612306
PASS();
1230712307
}
1230812308

12309+
/* #1558: `install` configured EVERY detected client, so a user who wanted
12310+
* Claude and Codex had to revert OpenCode and Cursor by hand — and the next
12311+
* install silently recreated them. The selector restricts it.
12312+
*
12313+
* The vocabulary is the part that makes it usable: 26 clients ship, with tokens
12314+
* nobody would guess (factory-droid, mistral-vibe, copilot-cli). A selector
12315+
* whose accepted values can only be learned by reading our source is not a
12316+
* usable selector, so this pins that every client is listed and that an unknown
12317+
* token is REJECTED rather than silently matching nothing. */
12318+
TEST(cli_clients_selector_vocabulary_is_complete_and_strict_issue1558) {
12319+
cbm_detected_agents_t all;
12320+
memset(&all, 1, sizeof(all)); /* every client "detected" */
12321+
12322+
/* A known token keeps its client and drops the rest. */
12323+
cbm_detected_agents_t sel = all;
12324+
ASSERT_TRUE(cbm_cli_clients_apply_selection_for_testing("claude,codex", &sel));
12325+
ASSERT_TRUE(sel.claude_code);
12326+
ASSERT_TRUE(sel.codex);
12327+
ASSERT_FALSE(sel.cursor);
12328+
ASSERT_FALSE(sel.opencode);
12329+
12330+
/* Whitespace around tokens is tolerated — people type it. */
12331+
cbm_detected_agents_t spaced = all;
12332+
ASSERT_TRUE(cbm_cli_clients_apply_selection_for_testing(" claude , zed ", &spaced));
12333+
ASSERT_TRUE(spaced.claude_code);
12334+
ASSERT_TRUE(spaced.zed);
12335+
ASSERT_FALSE(spaced.codex);
12336+
12337+
/* An unknown token must FAIL. Silently treating a typo as "no such client"
12338+
* would configure nothing and report success. */
12339+
cbm_detected_agents_t typo = all;
12340+
ASSERT_FALSE(cbm_cli_clients_apply_selection_for_testing("claude,codx", &typo));
12341+
12342+
/* Every token in the table must resolve — a client added to detection but
12343+
* forgotten here is invisible to the selector. */
12344+
for (size_t i = 0; i < cbm_cli_clients_count_for_testing(); i++) {
12345+
const char *token = cbm_cli_clients_token_for_testing(i);
12346+
ASSERT_NOT_NULL(token);
12347+
cbm_detected_agents_t one = all;
12348+
ASSERT_TRUE(cbm_cli_clients_apply_selection_for_testing(token, &one));
12349+
}
12350+
PASS();
12351+
}
12352+
1230912353
TEST(cli_update_accepts_retired_variant_flags_issue1544) {
1231012354
char *ui_argv[] = {"--dry-run", "--ui", "--yes"};
1231112355
char *standard_argv[] = {"--dry-run", "--standard", "--yes"};
@@ -12396,6 +12440,7 @@ SUITE(cli) {
1239612440
RUN_TEST(cli_update_already_current_does_not_quiesce_sessions);
1239712441
RUN_TEST(cli_skill_frontmatter_scalars_with_colons_are_quoted_issue1554);
1239812442
RUN_TEST(cli_external_manager_detection_needs_positive_evidence_issue1566);
12443+
RUN_TEST(cli_clients_selector_vocabulary_is_complete_and_strict_issue1558);
1239912444
RUN_TEST(cli_update_accepts_retired_variant_flags_issue1544);
1240012445
RUN_TEST(cli_update_agent_configs_finish_before_guard_release);
1240112446
RUN_TEST(cli_uninstall_quiesces_active_cohort_before_removing_binary_and_index);

0 commit comments

Comments
 (0)