refactor: consolidate agent env vars into config.AgentEnv

Create centralized AgentEnv function as single source of truth for all
agent environment variables. All agents now consistently receive:
- GT_ROLE, BD_ACTOR, GIT_AUTHOR_NAME (role identity)
- GT_ROOT, BEADS_DIR (workspace paths)
- GT_RIG, GT_POLECAT/GT_CREW (rig-specific identity)
- BEADS_AGENT_NAME, BEADS_NO_DAEMON (beads config)
- CLAUDE_CONFIG_DIR (optional account selection)

Remove RoleEnvVars in favor of AgentEnvSimple wrapper.
Remove IncludeBeadsEnv flag - beads env vars always included.
Update all manager and cmd call sites to use AgentEnv.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
julianknutsen
2026-01-09 09:20:33 -08:00
committed by Steve Yegge
parent 52b9a95f98
commit e999ceb1c1
16 changed files with 336 additions and 114 deletions

View File

@@ -186,21 +186,21 @@ func (m *SessionManager) Start(polecat string, opts SessionStartOptions) error {
}
// Set environment (non-fatal: session works without these)
debugSession("SetEnvironment GT_RIG", m.tmux.SetEnvironment(sessionID, "GT_RIG", m.rig.Name))
debugSession("SetEnvironment GT_POLECAT", m.tmux.SetEnvironment(sessionID, "GT_POLECAT", polecat))
// Set runtime config dir for account selection (non-fatal)
if runtimeConfig.Session != nil && runtimeConfig.Session.ConfigDirEnv != "" && opts.RuntimeConfigDir != "" {
debugSession("SetEnvironment "+runtimeConfig.Session.ConfigDirEnv, m.tmux.SetEnvironment(sessionID, runtimeConfig.Session.ConfigDirEnv, opts.RuntimeConfigDir))
// Use centralized AgentEnv for consistency across all role startup paths
townRoot := filepath.Dir(m.rig.Path)
envVars := config.AgentEnv(config.AgentEnvConfig{
Role: "polecat",
Rig: m.rig.Name,
AgentName: polecat,
TownRoot: townRoot,
BeadsDir: beads.ResolveBeadsDir(m.rig.Path),
RuntimeConfigDir: opts.RuntimeConfigDir,
BeadsNoDaemon: true,
})
for k, v := range envVars {
debugSession("SetEnvironment "+k, m.tmux.SetEnvironment(sessionID, k, v))
}
// Set beads environment for worktree polecats (non-fatal)
// Use ResolveBeadsDir to follow redirects for repos with tracked beads
beadsDir := beads.ResolveBeadsDir(m.rig.Path)
debugSession("SetEnvironment BEADS_DIR", m.tmux.SetEnvironment(sessionID, "BEADS_DIR", beadsDir))
debugSession("SetEnvironment BEADS_NO_DAEMON", m.tmux.SetEnvironment(sessionID, "BEADS_NO_DAEMON", "1"))
debugSession("SetEnvironment BEADS_AGENT_NAME", m.tmux.SetEnvironment(sessionID, "BEADS_AGENT_NAME", fmt.Sprintf("%s/%s", m.rig.Name, polecat)))
// Hook the issue to the polecat if provided via --issue flag
if opts.Issue != "" {
agentID := fmt.Sprintf("%s/polecats/%s", m.rig.Name, polecat)