config: environment delegates are opt-in
Decision, and the reason: the claude entry built from CLAUDE_CODE_OAUTH_TOKEN
does not work (the child exits 2 although the same 'claude -p' answers fine from
a shell), it duplicates the explicit claudecli delegate, and it appeared the
moment the wrapper started loading ~/.hermes/.env. An entry nobody wrote down,
that does not work, and competes for work is worse than no entry.
So env_delegates defaults to off:
env_delegates = 1 # then CLAUDE_CODE_OAUTH_TOKEN(_N) become delegates
Ollama keys are unaffected - they feed the exit ring, which is what they were for.
Also: the id counts claude delegates instead of the array position ('claude', not
'claude-5'), and its tags are its own (claude,cli,big,review) at prio 5, so it can
never take a planning task by accident.
delegate_list -> kontron, ocgo, ollama, claudecli, occli
env_delegates = 1 -> ... occli, claude
test_config pins both: 3 with the flag off, 4 with it on, and the id is 'claude'.
This commit is contained in:
1 parent
c56ba892b5
commit
4c4975c08a
4 files changed
+43
-8
No files matched your search
+18
-4
@@ -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;
|
||||
}
|
||||
@@ -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 *);
|
||||
|
||||
Binary file not shown.
+18
-4
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user