From 255ed66f0dd62884d100267edf68f9fa6f1798e0 Mon Sep 17 00:00:00 2001 From: mrbeandev Date: Mon, 16 Feb 2026 12:13:19 +0530 Subject: [PATCH] feat: persist slash command model/provider changes to config file --- cmd/picoclaw/main.go | 4 ++-- pkg/agent/loop.go | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/picoclaw/main.go b/cmd/picoclaw/main.go index fd7ec484a..03c136189 100644 --- a/cmd/picoclaw/main.go +++ b/cmd/picoclaw/main.go @@ -406,7 +406,7 @@ func agentCmd() { } msgBus := bus.NewMessageBus() - agentLoop := agent.NewAgentLoop(cfg, msgBus, provider) + agentLoop := agent.NewAgentLoop(cfg, msgBus, provider, getConfigPath()) // Print agent startup info (only for interactive mode) startupInfo := agentLoop.GetStartupInfo() @@ -541,7 +541,7 @@ func gatewayCmd() { } msgBus := bus.NewMessageBus() - agentLoop := agent.NewAgentLoop(cfg, msgBus, provider) + agentLoop := agent.NewAgentLoop(cfg, msgBus, provider, getConfigPath()) // Print agent startup info fmt.Println("\n📦 Agent Status:") diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 5821b803a..d30d206c3 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -46,6 +46,7 @@ type AgentLoop struct { running atomic.Bool summarizing sync.Map // Tracks which sessions are currently being summarized channelManager *channels.Manager + configPath string // Path to config.json for persistence } // processOptions configures how a message is processed @@ -109,7 +110,7 @@ func createToolRegistry(workspace string, restrict bool, cfg *config.Config, msg return registry } -func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers.LLMProvider) *AgentLoop { +func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers.LLMProvider, configPath string) *AgentLoop { workspace := cfg.WorkspacePath() os.MkdirAll(workspace, 0755) @@ -154,6 +155,7 @@ func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers contextBuilder: contextBuilder, tools: toolsRegistry, summarizing: sync.Map{}, + configPath: configPath, } } @@ -209,6 +211,16 @@ func (al *AgentLoop) GetModel() string { func (al *AgentLoop) SetModel(model string) { al.model = model + al.cfg.Agents.Defaults.Model = model + al.saveConfig() +} + +func (al *AgentLoop) saveConfig() { + if al.configPath != "" { + if err := config.SaveConfig(al.configPath, al.cfg); err != nil { + logger.ErrorCF("agent", "Failed to save config", map[string]interface{}{"error": err.Error(), "path": al.configPath}) + } + } } // listModelsResponse builds a dynamic /models response from the current config.