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:
@@ -41,6 +41,11 @@ type AgentPresetInfo struct {
|
||||
// Args are the default command-line arguments for autonomous mode.
|
||||
Args []string `json:"args"`
|
||||
|
||||
// Env are environment variables to set when starting the agent.
|
||||
// These are merged with the standard GT_* variables.
|
||||
// Used for agent-specific configuration like OPENCODE_PERMISSION.
|
||||
Env map[string]string `json:"env,omitempty"`
|
||||
|
||||
// ProcessNames are the process names to look for when detecting if the agent is running.
|
||||
// Used by tmux.IsAgentRunning to check pane_current_command.
|
||||
// E.g., ["node"] for Claude, ["cursor-agent"] for Cursor.
|
||||
@@ -318,7 +323,7 @@ func DefaultAgentPreset() AgentPreset {
|
||||
}
|
||||
|
||||
// RuntimeConfigFromPreset creates a RuntimeConfig from an agent preset.
|
||||
// This provides the basic Command/Args; additional fields from AgentPresetInfo
|
||||
// This provides the basic Command/Args/Env; additional fields from AgentPresetInfo
|
||||
// can be accessed separately for extended functionality.
|
||||
func RuntimeConfigFromPreset(preset AgentPreset) *RuntimeConfig {
|
||||
info := GetAgentPreset(preset)
|
||||
@@ -327,9 +332,19 @@ func RuntimeConfigFromPreset(preset AgentPreset) *RuntimeConfig {
|
||||
return DefaultRuntimeConfig()
|
||||
}
|
||||
|
||||
// Copy Env map to avoid mutation
|
||||
var envCopy map[string]string
|
||||
if len(info.Env) > 0 {
|
||||
envCopy = make(map[string]string, len(info.Env))
|
||||
for k, v := range info.Env {
|
||||
envCopy[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
rc := &RuntimeConfig{
|
||||
Command: info.Command,
|
||||
Args: append([]string(nil), info.Args...), // Copy to avoid mutation
|
||||
Env: envCopy,
|
||||
}
|
||||
|
||||
// Resolve command path for claude preset (handles alias installations)
|
||||
|
||||
Reference in New Issue
Block a user