@@ -1,469 +0,0 @@
1-# Per-Mysis Configuration Implementation Plan
2-
3-**Date:** 2026-02-04
4-**Status:** Ready for implementation
5-
6-## Goal
7-
8-Enable per-mysis provider/model/temperature configuration and document OpenCode Zen free models.
9-
10-## Architecture
11-
12-The current singleton provider pattern will be replaced with a factory pattern. Each mysis will own a dedicated provider instance configured with its stored model and temperature. Config defines defaults; database stores per-mysis overrides.
13-
14-## Tech Stack
15-
16-Go 1.22+, SQLite (modernc.org/sqlite), go-openai, BurntSushi/toml
17-
18----
19-
20-## Phase 1: Documentation
21-
22-**Files:**
23-- Create: `documentation/OPENCODE_ZEN_MODELS.md`
24-
25-**Content:**
26-Document models and configuration details in `documentation/OPENCODE_ZEN_MODELS.md`.
27-
28----
29-
30-## Phase 2: Config Changes
31-
32-**Files:**
33-- Modify: `internal/config/config.go`
34-- Modify: `config.toml`
35-
36-**Changes to `config.go`:**
37-
38-```go
39-// ProviderConfig holds LLM provider settings.
40-type ProviderConfig struct {
41- Endpoint string `toml:"endpoint"`
42- Model string `toml:"model"`
43- Temperature float64 `toml:"temperature"`
44-}
45-
46-// In DefaultConfig():
47-Providers: map[string]ProviderConfig{
48- "ollama": {
49- Endpoint: "http://localhost:11434",
50- Model: "llama3",
51- Temperature: 0.7,
52- },
53-},
54-
55-// In applyEnvOverrides():
56-if v := os.Getenv("ZOEA_OLLAMA_TEMPERATURE"); v != "" {
57- if f, err := strconv.ParseFloat(v, 64); err == nil {
58- if p, ok := cfg.Providers["ollama"]; ok {
59- p.Temperature = f
60- cfg.Providers["ollama"] = p
61- }
62- }
63-}
64-
65-if v := os.Getenv("ZOEA_OPENCODE_TEMPERATURE"); v != "" {
66- if f, err := strconv.ParseFloat(v, 64); err == nil {
67- if p, ok := cfg.Providers["opencode_zen"]; ok {
68- p.Temperature = f
69- cfg.Providers["opencode_zen"] = p
70- }
71- }
72-}
73-```
74-
75-**Changes to `config.toml`:**
76-
77-```toml
78-[providers.ollama]
79-endpoint = "http://localhost:11434"
80-model = "qwen3:4b"
81-temperature = 0.7
82-
83-[providers.opencode_zen]
84-endpoint = "https://api.opencode.ai/v1"
85-model = "glm-4.7-free"
86-temperature = 0.7
87-```
88-
89----
90-
91-## Phase 3: Store Changes
92-
93-**Files:**
94-- Modify: `internal/store/schema.sql`
95-- Modify: `internal/store/myses.go`
96-
97-**Changes to `schema.sql`:**
98-
99-```sql
100-INSERT OR REPLACE INTO schema_version (version) VALUES (4);
101-
102-CREATE TABLE IF NOT EXISTS myses (
103- id TEXT PRIMARY KEY,
104- name TEXT NOT NULL,
105- provider TEXT NOT NULL,
106- model TEXT NOT NULL,
107- temperature REAL NOT NULL DEFAULT 0.7,
108- state TEXT NOT NULL DEFAULT 'idle',
109- created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
110- updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
111-);
112-```
113-
114-**Changes to `myses.go`:**
115-
116-```go
117-// Mysis struct
118-type Mysis struct {
119- ID string
120- Name string
121- Provider string
122- Model string
123- Temperature float64
124- State MysisState
125- CreatedAt time.Time
126- UpdatedAt time.Time
127-}
128-
129-// CreateMysis signature
130-func (s *Store) CreateMysis(name, provider, model string, temperature float64) (*Mysis, error)
131-
132-// UpdateMysisConfig signature
133-func (s *Store) UpdateMysisConfig(id, provider, model string, temperature float64) error
134-
135-// Scan functions updated to include temperature
136-```
137-
138----
139-
140-## Phase 4: Provider Changes
141-
142-**Files:**
143-- Modify: `internal/provider/ollama.go`
144-- Modify: `internal/provider/opencode.go`
145-- Modify: `internal/provider/provider.go`
146-- Create: `internal/provider/factory.go`
147-- Modify: `internal/provider/mock.go`
148-
149-**Changes to `provider.go`:**
150-
151-```go
152-// ProviderFactory creates provider instances with specific configurations.
153-type ProviderFactory interface {
154- Name() string
155- Create(model string, temperature float64) Provider
156-}
157-
158-// Registry holds provider factories.
159-type Registry struct {
160- factories map[string]ProviderFactory
161-}
162-
163-func (r *Registry) RegisterFactory(f ProviderFactory) {
164- r.factories[f.Name()] = f
165-}
166-
167-func (r *Registry) Create(name, model string, temperature float64) (Provider, error) {
168- f, ok := r.factories[name]
169- if !ok {
170- return nil, ErrProviderNotFound
171- }
172- return f.Create(model, temperature), nil
173-}
174-```
175-
176-**New `factory.go`:**
177-
178-```go
179-package provider
180-
181-// OllamaFactory creates Ollama providers.
182-type OllamaFactory struct {
183- endpoint string
184-}
185-
186-func NewOllamaFactory(endpoint string) *OllamaFactory {
187- return &OllamaFactory{endpoint: endpoint}
188-}
189-
190-func (f *OllamaFactory) Name() string { return "ollama" }
191-
192-func (f *OllamaFactory) Create(model string, temperature float64) Provider {
193- return NewOllamaWithTemp(f.endpoint, model, temperature)
194-}
195-
196-// OpenCodeFactory creates OpenCode Zen providers.
197-type OpenCodeFactory struct {
198- endpoint string
199- apiKey string
200-}
201-
202-func NewOpenCodeFactory(endpoint, apiKey string) *OpenCodeFactory {
203- return &OpenCodeFactory{endpoint: endpoint, apiKey: apiKey}
204-}
205-
206-func (f *OpenCodeFactory) Name() string { return "opencode_zen" }
207-
208-func (f *OpenCodeFactory) Create(model string, temperature float64) Provider {
209- return NewOpenCodeWithTemp(f.endpoint, model, f.apiKey, temperature)
210-}
211-```
212-
213-**Changes to `ollama.go`:**
214-
215-```go
216-type OllamaProvider struct {
217- client *openai.Client
218- model string
219- temperature float64
220-}
221-
222-func NewOllamaWithTemp(endpoint, model string, temperature float64) *OllamaProvider {
223- config := openai.DefaultConfig("")
224- config.BaseURL = endpoint + "/v1"
225- return &OllamaProvider{
226- client: openai.NewClientWithConfig(config),
227- model: model,
228- temperature: temperature,
229- }
230-}
231-
232-// In Chat/ChatWithTools, add Temperature to request:
233-resp, err := p.client.CreateChatCompletion(ctx, openai.ChatCompletionRequest{
234- Model: p.model,
235- Messages: toOpenAIMessages(messages),
236- Temperature: float32(p.temperature),
237-})
238-```
239-
240-**Changes to `opencode.go`:**
241-
242-Similar temperature field and usage as ollama.go.
243-
244----
245-
246-## Phase 5: Commander Changes
247-
248-**Files:**
249-- Modify: `internal/core/commander.go`
250-
251-**Key changes:**
252-
253-```go
254-// Commander now uses factory pattern
255-type Commander struct {
256- // ... existing fields
257- registry *provider.Registry // Now holds factories
258-}
259-
260-// CreateMysis creates provider using factory
261-func (c *Commander) CreateMysis(name, providerName string) (*Mysis, error) {
262- provCfg := c.config.Providers[providerName]
263-
264- // Create provider instance for this mysis
265- p, err := c.registry.Create(providerName, provCfg.Model, provCfg.Temperature)
266- if err != nil {
267- return nil, err
268- }
269-
270- // Store with model and temperature
271- stored, err := c.store.CreateMysis(name, providerName, provCfg.Model, provCfg.Temperature)
272- // ...
273-}
274-
275-// ConfigureMysis now accepts model parameter
276-func (c *Commander) ConfigureMysis(id, providerName, model string) error {
277- provCfg := c.config.Providers[providerName]
278- temperature := provCfg.Temperature
279-
280- // Create new provider with specified model
281- p, err := c.registry.Create(providerName, model, temperature)
282- // ...
283-
284- c.store.UpdateMysisConfig(id, providerName, model, temperature)
285- mysis.SetProvider(p)
286-}
287-
288-// LoadMyses creates providers from stored config
289-func (c *Commander) LoadMyses() error {
290- for _, sm := range stored {
291- p, err := c.registry.Create(sm.Provider, sm.Model, sm.Temperature)
292- // ...
293- }
294-}
295-```
296-
297----
298-
299-## Phase 6: TUI Changes
300-
301-**Files:**
302-- Modify: `internal/tui/input.go`
303-- Modify: `internal/tui/app.go`
304-
305-**Changes to `input.go`:**
306-
307-```go
308-const (
309- InputModeNone InputMode = iota
310- InputModeBroadcast
311- InputModeMessage
312- InputModeNewMysis
313- InputModeConfigProvider
314- InputModeConfigModel // NEW
315-)
316-
317-// In SetMode():
318-case InputModeConfigModel:
319- m.textInput.Placeholder = "Enter model name..."
320- m.textInput.Prompt = inputPromptStyle.Render("🔧 ") + " "
321-```
322-
323-**Changes to `app.go`:**
324-
325-```go
326-// Add field to track pending provider during config flow
327-type Model struct {
328- // ... existing fields
329- pendingProvider string // Temporary storage during config flow
330-}
331-
332-// In handleInputKey, case InputModeConfigProvider:
333-case InputModeConfigProvider:
334- // Validate provider exists
335- if value != "ollama" && value != "opencode_zen" {
336- m.err = fmt.Errorf("unknown provider: %s", value)
337- m.input.Reset()
338- return m, nil
339- }
340- // Store provider and prompt for model
341- m.pendingProvider = value
342- m.input.SetMode(InputModeConfigModel, m.input.TargetID())
343- return m, m.input.Focus()
344-
345-case InputModeConfigModel:
346- m.err = m.commander.ConfigureMysis(m.input.TargetID(), m.pendingProvider, value)
347- m.pendingProvider = ""
348-```
349-
350----
351-
352-## Phase 7: Main.go Changes
353-
354-**Files:**
355-- Modify: `cmd/zoea/main.go`
356-
357-**Changes:**
358-
359-```go
360-func initProviders(cfg *config.Config, creds *config.Credentials) *provider.Registry {
361- registry := provider.NewRegistry()
362-
363- // Register Ollama factory
364- if ollCfg, ok := cfg.Providers["ollama"]; ok {
365- factory := provider.NewOllamaFactory(ollCfg.Endpoint)
366- registry.RegisterFactory(factory)
367- }
368-
369- // Register OpenCode Zen factory
370- if zenCfg, ok := cfg.Providers["opencode_zen"]; ok {
371- apiKey := creds.GetAPIKey("opencode_zen")
372- if apiKey != "" {
373- factory := provider.NewOpenCodeFactory(zenCfg.Endpoint, apiKey)
374- registry.RegisterFactory(factory)
375- }
376- }
377-
378- return registry
379-}
380-```
381-
382----
383-
384-## Phase 8: Tests
385-
386-**Files:**
387-- Modify: `internal/config/config_test.go`
388-- Modify: `internal/store/store_test.go`
389-- Modify: `internal/core/commander_test.go`
390-
391-**Test additions:**
392-
393-```go
394-// config_test.go
395-func TestLoadWithTemperature(t *testing.T) {
396- content := `
397-[providers.ollama]
398-endpoint = "http://localhost:11434"
399-model = "qwen3:4b"
400-temperature = 0.5
401-`
402- // ... verify temperature is parsed
403-}
404-
405-// store_test.go
406-func TestMysisCRUDWithTemperature(t *testing.T) {
407- mysis, err := s.CreateMysis("test", "ollama", "llama3", 0.5)
408- // ... verify temperature is stored and retrieved
409-}
410-
411-// commander_test.go
412-func TestCommanderConfigureMysisWithModel(t *testing.T) {
413- // ... verify model can be changed per-mysis
414-}
415-```
416-
417----
418-
419-## Phase 9: Verification
420-
421-1. Run `make test` - all tests must pass
422-2. Run `make build` - compilation must succeed
423-3. Manual test: create mysis, configure with different model, verify provider uses correct model
424-4. Update `KNOWN_ISSUES.md` to mark first item complete
425-
426----
427-
428-## Summary of Files Changed
429-
430-| File | Action |
431-|------|--------|
432-| `documentation/OPENCODE_ZEN_MODELS.md` | Create |
433-| `internal/config/config.go` | Modify |
434-| `internal/config/config_test.go` | Modify |
435-| `config.toml` | Modify |
436-| `internal/store/schema.sql` | Modify |
437-| `internal/store/myses.go` | Modify |
438-| `internal/store/store_test.go` | Modify |
439-| `internal/provider/provider.go` | Modify |
440-| `internal/provider/factory.go` | Create |
441-| `internal/provider/ollama.go` | Modify |
442-| `internal/provider/opencode.go` | Modify |
443-| `internal/provider/mock.go` | Modify |
444-| `internal/core/commander.go` | Modify |
445-| `internal/core/commander_test.go` | Modify |
446-| `internal/tui/input.go` | Modify |
447-| `internal/tui/app.go` | Modify |
448-| `cmd/zoea/main.go` | Modify |
449-| `documentation/KNOWN_ISSUES.md` | Modify |
450-
451----
452-
453-## Database Migration Note
454-
455-This change requires schema v4 with a new `temperature` column. Per AGENTS.md, no data migrations are supported. See `AGENTS.md` for the reset command and backup details.
456-
457----
458-
459-## Implementation Order
460-
461-1. Documentation (OpenCode Zen models)
462-2. Config layer (add temperature field)
463-3. Store layer (schema + CRUD)
464-4. Provider layer (factory pattern)
465-5. Commander layer (use factories)
466-6. TUI layer (model selection)
467-7. Main.go (register factories)
468-8. Tests (verify all layers)
469-9. Verification (build + manual test)