mirror of
https://github.com/Finesssee/ProxyPilot.git
synced 2026-11-19 02:17:46 +00:00
feat(agents): add shell config interface for CLI setup
Add GetShellConfig() to AgentHandler interface returning ShellConfigInfo with environment variables and shell profile snippets. Implement for all agents: Claude Code, Codex, Gemini CLI, Cursor, OpenCode, Factory Droid, and Amazon Q CLI.
This commit is contained in:
@@ -252,6 +252,24 @@ Note: Amazon Q CLI has separate usage quota from Kiro IDE.
|
||||
`
|
||||
}
|
||||
|
||||
// GetShellConfig returns shell profile configuration for Amazon Q CLI
|
||||
func (h *AmazonQCLIHandler) GetShellConfig(proxyURL string) string {
|
||||
return fmt.Sprintf(`# ProxyPilot - Amazon Q CLI Configuration
|
||||
# Amazon Q CLI uses its own authentication via 'q login'.
|
||||
# ProxyPilot automatically imports the tokens after you authenticate.
|
||||
|
||||
# To authenticate:
|
||||
# q login
|
||||
|
||||
# ProxyPilot will detect and use the tokens automatically.
|
||||
# No additional environment variables needed.
|
||||
|
||||
# Optional: For other OpenAI-compatible tools
|
||||
export OPENAI_BASE_URL="%s/v1"
|
||||
export OPENAI_API_KEY="proxypilot-local"
|
||||
`, proxyURL)
|
||||
}
|
||||
|
||||
// GetWSLInfo returns WSL distro and user information (for external use)
|
||||
func (h *AmazonQCLIHandler) GetWSLInfo() (distro, user string) {
|
||||
return h.wslDistro, h.wslUser
|
||||
|
||||
@@ -204,6 +204,25 @@ func (h *ClaudeCodeHandler) GetInstructions(proxyURL string) string {
|
||||
`, h.configPath, proxyURL)
|
||||
}
|
||||
|
||||
// GetShellConfig returns shell profile configuration for Claude Code
|
||||
func (h *ClaudeCodeHandler) GetShellConfig(proxyURL string) string {
|
||||
return fmt.Sprintf(`# ProxyPilot - Claude Code Configuration
|
||||
# Add these lines to your shell profile (~/.bashrc, ~/.zshrc, or ~/.profile)
|
||||
|
||||
export ANTHROPIC_BASE_URL="%s"
|
||||
export ANTHROPIC_AUTH_TOKEN="proxypilot-local"
|
||||
|
||||
# For Claude Code 2.x, you can also set default models:
|
||||
# export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-1-20250805"
|
||||
# export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-5-20250929"
|
||||
# export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-3-5-haiku-20241022"
|
||||
|
||||
# For Claude Code 1.x:
|
||||
# export ANTHROPIC_MODEL="claude-sonnet-4-5-20250929"
|
||||
# export ANTHROPIC_SMALL_FAST_MODEL="claude-3-5-haiku-20241022"
|
||||
`, proxyURL)
|
||||
}
|
||||
|
||||
// readConfig reads the Claude Code settings file
|
||||
func (h *ClaudeCodeHandler) readConfig() (map[string]any, error) {
|
||||
data, err := os.ReadFile(h.configPath)
|
||||
|
||||
@@ -203,3 +203,17 @@ wire_api = "openai"
|
||||
4. Restart Codex CLI for changes to take effect.
|
||||
`, h.configPath, proxyURL)
|
||||
}
|
||||
|
||||
// GetShellConfig returns shell profile configuration for Codex CLI
|
||||
func (h *CodexHandler) GetShellConfig(proxyURL string) string {
|
||||
return fmt.Sprintf(`# ProxyPilot - Codex CLI Configuration
|
||||
# Add these lines to your shell profile (~/.bashrc, ~/.zshrc, or ~/.profile)
|
||||
|
||||
export PROXYPILOT_API_KEY="proxypilot-local"
|
||||
export OPENAI_BASE_URL="%s/v1"
|
||||
export OPENAI_API_KEY="proxypilot-local"
|
||||
|
||||
# Note: Codex CLI also requires config.toml configuration.
|
||||
# See the setup instructions for full details.
|
||||
`, proxyURL)
|
||||
}
|
||||
|
||||
@@ -193,6 +193,18 @@ Or edit %s directly and add:
|
||||
`, proxyURL, h.configPath, proxyURL)
|
||||
}
|
||||
|
||||
// GetShellConfig returns shell profile configuration for Cursor
|
||||
func (h *CursorHandler) GetShellConfig(proxyURL string) string {
|
||||
return fmt.Sprintf(`# ProxyPilot - Cursor IDE Configuration
|
||||
# Note: Cursor primarily uses settings.json, not environment variables.
|
||||
# Use the UI or edit settings.json directly.
|
||||
|
||||
# Optional: Set OPENAI-compatible environment variables as fallback
|
||||
export OPENAI_BASE_URL="%s/v1"
|
||||
export OPENAI_API_KEY="proxypilot-local"
|
||||
`, proxyURL)
|
||||
}
|
||||
|
||||
// readConfig reads the Cursor settings file
|
||||
func (h *CursorHandler) readConfig() (map[string]any, error) {
|
||||
data, err := os.ReadFile(h.configPath)
|
||||
|
||||
@@ -196,6 +196,18 @@ func (h *FactoryDroidHandler) GetInstructions(proxyURL string) string {
|
||||
`, h.settingsPath, proxyURL)
|
||||
}
|
||||
|
||||
// GetShellConfig returns shell profile configuration for Factory Droid
|
||||
func (h *FactoryDroidHandler) GetShellConfig(proxyURL string) string {
|
||||
return fmt.Sprintf(`# ProxyPilot - Factory Droid Configuration
|
||||
# Factory Droid uses settings.json for configuration, not environment variables.
|
||||
# Use the auto-configure feature or edit %s directly.
|
||||
|
||||
# Optional: For other OpenAI-compatible tools
|
||||
export OPENAI_BASE_URL="%s/v1"
|
||||
export OPENAI_API_KEY="proxypilot-local"
|
||||
`, h.settingsPath, proxyURL)
|
||||
}
|
||||
|
||||
func (h *FactoryDroidHandler) readSettings() (map[string]any, error) {
|
||||
data, err := os.ReadFile(h.settingsPath)
|
||||
if err != nil {
|
||||
@@ -277,7 +289,7 @@ func buildDroidModels(proxyURL string) []map[string]any {
|
||||
displayName := "proxypilot-" + m.displayName
|
||||
// Create ID in Droid's format: custom:<name>-<index>
|
||||
id := fmt.Sprintf("custom:%s-%d", strings.ReplaceAll(displayName, " ", "-"), i)
|
||||
|
||||
|
||||
models = append(models, map[string]any{
|
||||
"model": m.modelID,
|
||||
"id": id,
|
||||
|
||||
@@ -198,3 +198,17 @@ func (h *GeminiCLIHandler) writeConfig(config map[string]any) error {
|
||||
|
||||
return os.WriteFile(h.configPath, data, 0644)
|
||||
}
|
||||
|
||||
// GetShellConfig returns shell profile configuration for Gemini CLI
|
||||
func (h *GeminiCLIHandler) GetShellConfig(proxyURL string) string {
|
||||
return fmt.Sprintf(`# ProxyPilot - Gemini CLI Configuration
|
||||
# Add these lines to your shell profile (~/.bashrc, ~/.zshrc, or ~/.profile)
|
||||
|
||||
# Option 1: OAuth mode (local only)
|
||||
export CODE_ASSIST_ENDPOINT="%s"
|
||||
|
||||
# Option 2: API Key mode (works with any IP/domain)
|
||||
# export GOOGLE_GEMINI_BASE_URL="%s"
|
||||
# export GEMINI_API_KEY="proxypilot-local"
|
||||
`, proxyURL, proxyURL)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ type AgentInfo struct {
|
||||
CanAutoConfigure bool `json:"can_auto_configure"`
|
||||
ConfigPath string `json:"config_path,omitempty"`
|
||||
Instructions string `json:"instructions,omitempty"`
|
||||
ShellConfig string `json:"shell_config,omitempty"`
|
||||
EnvVars map[string]string `json:"env_vars,omitempty"`
|
||||
}
|
||||
|
||||
@@ -56,6 +57,10 @@ type AgentHandler interface {
|
||||
|
||||
// GetInstructions returns manual configuration instructions
|
||||
GetInstructions(proxyURL string) string
|
||||
|
||||
// GetShellConfig returns shell script configuration for this agent.
|
||||
// This is used for agents that need environment variables in shell profiles.
|
||||
GetShellConfig(proxyURL string) string
|
||||
}
|
||||
|
||||
// Manager manages all CLI agent configurations
|
||||
@@ -133,6 +138,7 @@ func (m *Manager) DetectAll() ([]AgentInfo, error) {
|
||||
CanAutoConfigure: handler.CanAutoConfigure(),
|
||||
ConfigPath: handler.GetConfigPath(),
|
||||
Instructions: handler.GetInstructions(m.proxyURL),
|
||||
ShellConfig: handler.GetShellConfig(m.proxyURL),
|
||||
}
|
||||
|
||||
detected, err := handler.Detect()
|
||||
@@ -174,6 +180,7 @@ func (m *Manager) GetAgentInfo(agentID string) (AgentInfo, error) {
|
||||
CanAutoConfigure: handler.CanAutoConfigure(),
|
||||
ConfigPath: handler.GetConfigPath(),
|
||||
Instructions: handler.GetInstructions(m.proxyURL),
|
||||
ShellConfig: handler.GetShellConfig(m.proxyURL),
|
||||
}
|
||||
|
||||
detected, _ := handler.Detect()
|
||||
|
||||
@@ -197,6 +197,20 @@ func (h *OpenCodeHandler) GetInstructions(proxyURL string) string {
|
||||
`, h.configPath, proxyURL)
|
||||
}
|
||||
|
||||
// GetShellConfig returns shell profile configuration for OpenCode
|
||||
func (h *OpenCodeHandler) GetShellConfig(proxyURL string) string {
|
||||
return fmt.Sprintf(`# ProxyPilot - OpenCode Configuration
|
||||
# Add these lines to your shell profile (~/.bashrc, ~/.zshrc, or ~/.profile)
|
||||
|
||||
export OPENAI_BASE_URL="%s/v1"
|
||||
export OPENAI_API_KEY="proxypilot-local"
|
||||
|
||||
# Or use Anthropic-compatible settings:
|
||||
# export ANTHROPIC_BASE_URL="%s"
|
||||
# export ANTHROPIC_AUTH_TOKEN="proxypilot-local"
|
||||
`, proxyURL, proxyURL)
|
||||
}
|
||||
|
||||
// readConfig reads the OpenCode settings file
|
||||
func (h *OpenCodeHandler) readConfig() (map[string]any, error) {
|
||||
data, err := os.ReadFile(h.configPath)
|
||||
|
||||
Reference in New Issue
Block a user