refactor(config): remove BEADS_DIR from agent environment and add doctor check (#455)

* fix(sling_test): update test for cook dir change

The cook command no longer needs database context and runs from cwd,
not the target rig directory. Update test to match this behavior
change from bd2a5ab5.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(tests): skip tests requiring missing binaries, handle --allow-stale

- Add skipIfAgentBinaryMissing helper to skip tests when codex/gemini
  binaries aren't available in the test environment
- Update rig manager test stub to handle --allow-stale flag

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor(config): remove BEADS_DIR from agent environment

Stop exporting BEADS_DIR in AgentEnv - agents should use beads redirect
mechanism instead of relying on environment variable. This prevents
prefix mismatches when agents operate across different beads databases.

Changes:
- Remove BeadsDir field from AgentEnvConfig
- Remove BEADS_DIR from env vars set on agent sessions
- Update doctor env_check to not expect BEADS_DIR
- Update all manager Start() calls to not pass BeadsDir

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(doctor): detect BEADS_DIR in tmux session environment

Add a doctor check that warns when BEADS_DIR is set in any Gas Town
tmux session. BEADS_DIR in the environment overrides prefix-based
routing and breaks multi-rig lookups - agents should use the beads
redirect mechanism instead.

The check:
- Iterates over all Gas Town tmux sessions (gt-* and hq-*)
- Checks if BEADS_DIR is set in the session environment
- Returns a warning with fix hint to restart sessions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: julianknutsen <julianknutsen@users.noreply.github>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Julian Knutsen
2026-01-14 06:13:57 +00:00
committed by GitHub
parent 3cf77b2e8b
commit e7ca4908dc
19 changed files with 252 additions and 126 deletions

View File

@@ -9,14 +9,12 @@ func TestAgentEnv_Mayor(t *testing.T) {
env := AgentEnv(AgentEnvConfig{
Role: "mayor",
TownRoot: "/town",
BeadsDir: "/town/.beads",
})
assertEnv(t, env, "GT_ROLE", "mayor")
assertEnv(t, env, "BD_ACTOR", "mayor")
assertEnv(t, env, "GIT_AUTHOR_NAME", "mayor")
assertEnv(t, env, "GT_ROOT", "/town")
assertEnv(t, env, "BEADS_DIR", "/town/.beads")
assertNotSet(t, env, "GT_RIG")
assertNotSet(t, env, "BEADS_NO_DAEMON")
}
@@ -27,7 +25,6 @@ func TestAgentEnv_Witness(t *testing.T) {
Role: "witness",
Rig: "myrig",
TownRoot: "/town",
BeadsDir: "/town/myrig/.beads",
})
assertEnv(t, env, "GT_ROLE", "witness")
@@ -35,7 +32,6 @@ func TestAgentEnv_Witness(t *testing.T) {
assertEnv(t, env, "BD_ACTOR", "myrig/witness")
assertEnv(t, env, "GIT_AUTHOR_NAME", "myrig/witness")
assertEnv(t, env, "GT_ROOT", "/town")
assertEnv(t, env, "BEADS_DIR", "/town/myrig/.beads")
}
func TestAgentEnv_Polecat(t *testing.T) {
@@ -45,7 +41,6 @@ func TestAgentEnv_Polecat(t *testing.T) {
Rig: "myrig",
AgentName: "Toast",
TownRoot: "/town",
BeadsDir: "/town/myrig/.beads",
BeadsNoDaemon: true,
})
@@ -65,7 +60,6 @@ func TestAgentEnv_Crew(t *testing.T) {
Rig: "myrig",
AgentName: "emma",
TownRoot: "/town",
BeadsDir: "/town/myrig/.beads",
BeadsNoDaemon: true,
})
@@ -84,7 +78,6 @@ func TestAgentEnv_Refinery(t *testing.T) {
Role: "refinery",
Rig: "myrig",
TownRoot: "/town",
BeadsDir: "/town/myrig/.beads",
BeadsNoDaemon: true,
})
@@ -100,14 +93,12 @@ func TestAgentEnv_Deacon(t *testing.T) {
env := AgentEnv(AgentEnvConfig{
Role: "deacon",
TownRoot: "/town",
BeadsDir: "/town/.beads",
})
assertEnv(t, env, "GT_ROLE", "deacon")
assertEnv(t, env, "BD_ACTOR", "deacon")
assertEnv(t, env, "GIT_AUTHOR_NAME", "deacon")
assertEnv(t, env, "GT_ROOT", "/town")
assertEnv(t, env, "BEADS_DIR", "/town/.beads")
assertNotSet(t, env, "GT_RIG")
assertNotSet(t, env, "BEADS_NO_DAEMON")
}
@@ -117,14 +108,12 @@ func TestAgentEnv_Boot(t *testing.T) {
env := AgentEnv(AgentEnvConfig{
Role: "boot",
TownRoot: "/town",
BeadsDir: "/town/.beads",
})
assertEnv(t, env, "GT_ROLE", "boot")
assertEnv(t, env, "BD_ACTOR", "deacon-boot")
assertEnv(t, env, "GIT_AUTHOR_NAME", "boot")
assertEnv(t, env, "GT_ROOT", "/town")
assertEnv(t, env, "BEADS_DIR", "/town/.beads")
assertNotSet(t, env, "GT_RIG")
assertNotSet(t, env, "BEADS_NO_DAEMON")
}
@@ -136,7 +125,6 @@ func TestAgentEnv_WithRuntimeConfigDir(t *testing.T) {
Rig: "myrig",
AgentName: "Toast",
TownRoot: "/town",
BeadsDir: "/town/myrig/.beads",
RuntimeConfigDir: "/home/user/.config/claude",
})
@@ -150,7 +138,6 @@ func TestAgentEnv_WithoutRuntimeConfigDir(t *testing.T) {
Rig: "myrig",
AgentName: "Toast",
TownRoot: "/town",
BeadsDir: "/town/myrig/.beads",
})
assertNotSet(t, env, "CLAUDE_CONFIG_DIR")
@@ -163,28 +150,25 @@ func TestAgentEnvSimple(t *testing.T) {
assertEnv(t, env, "GT_ROLE", "polecat")
assertEnv(t, env, "GT_RIG", "myrig")
assertEnv(t, env, "GT_POLECAT", "Toast")
// Simple doesn't set TownRoot/BeadsDir, so keys should be absent
// (not empty strings which would override tmux session environment)
// Simple doesn't set TownRoot, so key should be absent
// (not empty string which would override tmux session environment)
assertNotSet(t, env, "GT_ROOT")
assertNotSet(t, env, "BEADS_DIR")
}
func TestAgentEnv_EmptyTownRootBeadsDirOmitted(t *testing.T) {
func TestAgentEnv_EmptyTownRootOmitted(t *testing.T) {
t.Parallel()
// Regression test: empty TownRoot/BeadsDir should NOT create keys in the map.
// If they were set to empty strings, ExportPrefix would generate "export GT_ROOT= ..."
// which overrides tmux session environment where these are correctly set.
// Regression test: empty TownRoot should NOT create keys in the map.
// If it was set to empty string, ExportPrefix would generate "export GT_ROOT= ..."
// which overrides tmux session environment where it's correctly set.
env := AgentEnv(AgentEnvConfig{
Role: "polecat",
Rig: "myrig",
AgentName: "Toast",
TownRoot: "", // explicitly empty
BeadsDir: "", // explicitly empty
})
// Keys should be absent, not empty strings
// Key should be absent, not empty string
assertNotSet(t, env, "GT_ROOT")
assertNotSet(t, env, "BEADS_DIR")
// Other keys should still be set
assertEnv(t, env, "GT_ROLE", "polecat")