diff --git a/src/config.c b/src/config.c index 357e38e..8b40644 100644 --- a/src/config.c +++ b/src/config.c @@ -354,6 +354,9 @@ load_one(struct sp_config *c, const char *path, struct sp_buf *err) c->steps = (size_t)strtoul(val, NULL, 10); else if (!strcmp(key, "max_bytes")) c->max_bytes = (size_t)strtoul(val, NULL, 10); + else if (!strcmp(key, "env_delegates")) + c->env_delegates = (!strcmp(val, "1") || + !strcmp(val, "true") || !strcmp(val, "yes")) ? 1 : 0; else if (!strcmp(key, "autonomous")) c->autonomous = (!strcmp(val, "1") || !strcmp(val, "true") || !strcmp(val, "yes")) ? 1 : 0; @@ -608,11 +611,21 @@ scan_family(struct sp_config *c, const char *base, int is_ollama, size_t base_id snprintf(d->about, sizeof(d->about), "Claude Code (aus CLAUDE_CODE_OAUTH_TOKEN), " "plant und definiert Arbeit"); + /* + * Its own tags, not the planner's. A delegate that appears + * because an environment variable is set must not silently + * win every planning task; it is chosen when someone asks + * for it by name or tag. + */ snprintf(d->tags, sizeof(d->tags), - "plan,design,review,claude"); + "claude,cli,big,review"); snprintf(d->key, sizeof(d->key), "%.255s", token); - /* the planner is worth more than a worker */ - d->prio = 10; + /* + * Lower than the configured cloud delegates: an automatic + * entry gets no precedence over what was written down on + * purpose. + */ + d->prio = 5; d->max_parallel = 1; added++; } @@ -629,6 +642,7 @@ sp_config_scan_env(struct sp_config *c) if (c == NULL) return 0; n += scan_family(c, "OLLAMA_KEY", 1, 0); - n += scan_family(c, "CLAUDE_CODE_OAUTH_TOKEN", 0, 0); + if (c->env_delegates) + n += scan_family(c, "CLAUDE_CODE_OAUTH_TOKEN", 0, 0); return n; } diff --git a/src/config.h b/src/config.h index befb0c5..e0e49a2 100644 --- a/src/config.h +++ b/src/config.h @@ -82,6 +82,13 @@ struct sp_config { size_t steps; /* 0: not set */ size_t max_bytes; /* 0: not set */ int autonomous; /* -1 not set, 0 off, 1 on */ + /* + * Delegates built from environment tokens (CLAUDE_CODE_OAUTH_TOKEN and the + * numbered variants) are off unless asked for. An entry that appears because + * a variable happens to be exported competes for work nobody assigned it, + * and there is already an explicit cli delegate for the same program. + */ + int env_delegates; }; void sp_config_init(struct sp_config *); diff --git a/tests/test_config b/tests/test_config index 2f13263..91c6e53 100755 Binary files a/tests/test_config and b/tests/test_config differ diff --git a/tests/test_config.c b/tests/test_config.c index 41f2aea..00c83b0 100644 --- a/tests/test_config.c +++ b/tests/test_config.c @@ -135,11 +135,25 @@ main(void) (void)setenv("OLLAMA_KEY_0", "k2", 1); (void)setenv("OLLAMA_KEY_1", "k3", 1); (void)setenv("CLAUDE_CODE_OAUTH_TOKEN", "t1", 1); - CHECK(sp_config_scan_env(&c) == 4); - CHECK(c.ndelegates == 4); + /* + * Environment delegates are opt-in: a token in the environment must not + * add an entry that competes for work nobody assigned it. + */ + CHECK(sp_config_scan_env(&c) == 3); + CHECK(c.ndelegates == 3); CHECK(c.nexits == 3); /* one exit per Ollama key */ - CHECK(strcmp(c.delegate[3].kind, "cli") == 0); - CHECK(c.delegate[3].prio > 0); /* the planner ranks higher */ + c.env_delegates = 1; + { + struct sp_config c2; + + sp_config_init(&c2); + c2.env_delegates = 1; + CHECK(sp_config_scan_env(&c2) == 4); + CHECK(c2.ndelegates == 4); + CHECK(strcmp(c2.delegate[3].kind, "cli") == 0); + CHECK(strcmp(c2.delegate[3].id, "claude") == 0); + CHECK(c2.delegate[3].prio > 0); + } CHECK(strcmp(c.exit[0].endpoint, "https://ollama.com/v1/chat/completions") == 0); (void)unsetenv("OLLAMA_KEY");