feat(config): add Env field to RuntimeConfig and AgentPresetInfo (#860)

Add support for agent presets to specify environment variables that
get exported when starting sessions. This enables agents to use
environment-based configuration.

Changes:
- Add Env field to RuntimeConfig struct in types.go
- Add Env field to AgentPresetInfo struct in agents.go
- Update RuntimeConfigFromPreset to copy Env from preset
- Update fillRuntimeDefaults to preserve Env field
- Merge agent Env vars in BuildStartupCommand functions
- Add comprehensive tests for Env preservation and copy semantics

This is a prerequisite for the OpenCode agent preset which uses
OPENCODE_PERMISSION='{"*":"allow"}' for auto-approve mode.

Co-authored-by: Avyukth <subhrajit.makur@hotmail.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2026-01-21 17:20:09 -08:00
committed by GitHub
parent 9f06eb94c4
commit e12aa45dd6
5 changed files with 145 additions and 1 deletions

View File

@@ -1085,6 +1085,13 @@ func fillRuntimeDefaults(rc *RuntimeConfig) *RuntimeConfig {
Args: rc.Args,
InitialPrompt: rc.InitialPrompt,
}
// Copy Env map to avoid mutation and preserve agent-specific env vars
if len(rc.Env) > 0 {
result.Env = make(map[string]string, len(rc.Env))
for k, v := range rc.Env {
result.Env[k] = v
}
}
if result.Command == "" {
result.Command = "claude"
}
@@ -1252,6 +1259,10 @@ func BuildStartupCommand(envVars map[string]string, rigPath, prompt string) stri
if rc.Session != nil && rc.Session.SessionIDEnv != "" {
resolvedEnv["GT_SESSION_ID_ENV"] = rc.Session.SessionIDEnv
}
// Merge agent-specific env vars (e.g., OPENCODE_PERMISSION for yolo mode)
for k, v := range rc.Env {
resolvedEnv[k] = v
}
// Build environment export prefix
var exports []string
@@ -1362,6 +1373,10 @@ func BuildStartupCommandWithAgentOverride(envVars map[string]string, rigPath, pr
if agentOverride != "" {
resolvedEnv["GT_AGENT"] = agentOverride
}
// Merge agent-specific env vars (e.g., OPENCODE_PERMISSION for yolo mode)
for k, v := range rc.Env {
resolvedEnv[k] = v
}
// Build environment export prefix
var exports []string