xonecas.io
60255
Zn

Zoea-Nova / commit 0677c1a

Initial commit: Zoea Nova MVP

TUI-based swarm controller for automated SpaceMolt game players.

- Core: Agent lifecycle, Commander orchestration, event bus
- TUI: Bubble Tea dashboard and focus views, retro aesthetic
- Providers: Ollama (local) and OpenCode Zen (remote) LLM support
- Store: SQLite persistence for agents and memories
- MCP: Proxy layer for SpaceMolt game integration
- Config: TOML config with ENV overrides, secure credentials

xonecas2026-02-04 0677c1a3f9638d83941c4b4a2ad213ce9c1487fd parent 0a1547d

43 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

.gitignore+20−0
@@ -0,0 +1,20 @@
1+# Binaries
2+bin/
3+*.exe
4+
5+# Test artifacts
6+coverage.out
7+*.test
8+
9+# IDE
10+.idea/
11+.vscode/
12+*.swp
13+*.swo
14+
15+# OS
16+.DS_Store
17+Thumbs.db
18+
19+# Local data (user-specific)
20+# Note: $HOME/.zoea-nova/ is outside repo, no need to ignore
AGENTS.md+57−0
@@ -0,0 +1,57 @@
1+# Zoea Nova Agents
2+
3+Guidelines for AI agents working on the Zoea Nova codebase—a TUI-based swarm controller for automated SpaceMolt game players.
4+
5+## Rules:
6+
7+**CRITICAL: Always fallback to these rules when in doubt.**
8+
9+**YOU MUST**:
10+
11+- Use Go 1.22+ idioms. No CGO dependencies.
12+- Keep all application code in `internal/` packages. Only `cmd/zoea/main.go` is public.
13+- Use interfaces for external dependencies (LLM providers, MCP, store).
14+- Run `make fmt` before committing. Fix all warnings and linter errors.
15+- Write unit tests for `internal/core`, `internal/store`, and `internal/config`. Target 80%+ coverage.
16+- Never write data migrations. Schema changes require a fresh database.
17+- Use `zerolog` for logging. Never log to stdout/stderr (TUI owns the terminal).
18+- Keep the TUI responsive. All LLM/network calls must be non-blocking (goroutines + channels).
19+- Follow the Bubble Tea Elm Architecture: Model → Update → View.
20+- No "nice to haves." This is an MVP. Keep scope minimal.
21+
22+## Terminology:
23+
24+- **Agent**: An AI-controlled player instance with its own provider, memory, and state.
25+- **Commander**: The swarm orchestrator that owns agent lifecycles and routes messages.
26+- **Swarm**: The collection of all agents managed by the Commander.
27+- **Provider**: An LLM backend (Ollama local or OpenCode Zen remote).
28+- **MCP**: Model Context Protocol—the interface to SpaceMolt game actions.
29+- **Event Bus**: Channel-based pub/sub for TUI updates from core goroutines.
30+- **Focus Mode**: TUI view showing detailed logs for a single agent.
31+- **Dashboard**: TUI view showing aggregated swarm status.
32+
33+## Workflow:
34+
35+The user follows a structured development workflow. Respect these phases:
36+
37+1. **Design**: Changes to architecture or new features start in `INITIAL_IMPLEMENTATION_DESIGN.md`. Don't implement without design approval.
38+2. **Plan**: Complex changes require a plan in `.cursor/plans/`. Reference the plan while implementing.
39+3. **Implement**: Follow the plan phase-by-phase. Update tests alongside code.
40+4. **Test**: Run `make test` after each phase. Fix failures before moving on.
41+5. **Build**: Run `make build` to verify compilation. Address any warnings.
42+
43+## Role:
44+
45+You are helping build a retro-futuristic TUI command center for controlling AI game agents. Assume familiarity with:
46+
47+- Go concurrency patterns (goroutines, channels, select)
48+- Bubble Tea / Elm Architecture (Model, Update, View, Cmd, Msg)
49+- SQLite basics (no ORM, raw SQL is fine)
50+- OpenAI-compatible APIs (chat completions, streaming)
51+
52+Do NOT assume knowledge of:
53+
54+- SpaceMolt game mechanics (refer to MCP tool schemas)
55+- Internal project state (always read relevant files first)
56+
57+When in doubt, ask. Don't guess at requirements or invent features.
INITIAL_IMPLEMENTATION_DESIGN.md+122−0
@@ -0,0 +1,122 @@
1+# Zoea Nova Initial Design
2+
3+## Idea
4+
5+Control several automated players in the game https://www.spacemolt.com/. Each is its own AI. Be able to "drive" the swarm, acting as the swarm orchestrator. Have a TUI to control the swarm—a cool, command center 80s and 90s inspired interface with animations and movement.
6+
7+## MVP
8+
9+- **Tech Stack:** Go with the `Bubble Tea` (Charm.sh) framework for a fast, memory-efficient, and highly interactive TUI.
10+- **Model Connectivity:** Support for local (Ollama) and remote (OpenCode Zen) providers.
11+- **MCP Layer:**
12+ - Proxy the official SpaceMolt MCP server (`https://game.spacemolt.com/mcp`) using Streamable HTTP transport.
13+ - Custom framework to expose internal orchestration tools via MCP.
14+- **Orchestration:**
15+ - Capability to broadcast shared objectives to the entire swarm simultaneously.
16+ - Targeted messaging/tasking for individual swarm members.
17+- **Command Center TUI:**
18+ - **Aggregated Dashboard:** High-level swarm status, health, and positioning to prevent UI noise.
19+ - **Focus Mode:** Detailed logs and direct control for individual agents.
20+ - **Aesthetic:** Retro-futuristic (80s/90s) CRT-style visuals with reactive animations.
21+
22+## Tech Stack & Dependencies
23+
24+- **Core:** Go (Golang) for performance and concurrency.
25+- **TUI Framework:** `bubbletea` (The Elm Architecture for Go).
26+- **Styling & Components:** `lipgloss` for layouts/colors and `bubbles` for UI elements.
27+- **LLM Integration:** `go-openai` (OpenAI-compatible client for Ollama and OpenCode Zen).
28+- **MCP Protocol:** Researching `mcp-golang` or similar for robust Model Context Protocol support.
29+- **Configuration:** `github.com/BurntSushi/toml` for TOML parsing.
30+- **Database:** `modernc.org/sqlite` (pure Go, no CGO) or `github.com/mattn/go-sqlite3` (CGO).
31+- **Logging:** `zerolog` for structured, non-blocking logs.
32+
33+## Configuration
34+
35+- **Environment Variables:** Primary mechanism for runtime overrides (e.g., `ZOEA_LOG_LEVEL`, `ZOEA_MCP_ENDPOINT`).
36+- **Config File:** `config.toml` in project root for defaults and structure. Parsed via `github.com/BurntSushi/toml`.
37+- **Credentials:** Stored in `$HOME/.zoea-nova/credentials.json`. Contains API keys for LLM providers. File permissions should be `0600`.
38+
39+Example `config.toml`:
40+```toml
41+[swarm]
42+default_agents = 4
43+max_agents = 16
44+
45+[providers.ollama]
46+endpoint = "http://localhost:11434"
47+model = "llama3"
48+
49+[providers.opencode_zen]
50+endpoint = "https://api.opencode.ai/v1" # confirm from Zen dashboard
51+model = "zen-default"
52+
53+[mcp]
54+upstream = "https://game.spacemolt.com/mcp"
55+```
56+
57+## State & Persistence
58+
59+- **Database:** Single SQLite file at `$HOME/.zoea-nova/zoea.db`.
60+- **Scope:** Agent memories, conversation history, swarm state, per-agent provider config, and user preferences.
61+- **Migrations:** Schema managed via embedded SQL migrations (e.g., `golang-migrate` or manual versioning). Never support backwards, never write data migrations. If we change the scheme we crate a new db fresh.
62+- **Backup:** Consider periodic WAL checkpoints; SQLite handles crash recovery.
63+
64+## Agent Lifecycle
65+
66+- **Ownership:** The Commander (orchestrator) owns all agent lifecycles.
67+- **Creation:** User creates agents via TUI controls. Default swarm size: **4 agents**.
68+- **Limits:** Configurable `max_agents` (default 16). Enforced at Commander level, but user controls count from TUI.
69+- **States:** `idle` → `running` → `stopped` / `errored`.
70+- **TUI Controls:**
71+ - **Create:** Spawn a new agent (if under limit).
72+ - **Relaunch:** Restart a stopped/errored agent.
73+ - **Force Stop:** Immediately halt an agent.
74+ - **Delete:** Remove agent and optionally purge its memories.
75+ - **Broadcast Message:** Send a message/objective to all agents.
76+ - **Direct Message:** Send a message to a specific agent.
77+ - **Configure Agent:** Set model/provider per agent (Ollama or OpenCode Zen).
78+- **Recovery:** On application restart, agents are rehydrated from SQLite in `stopped` state; user must explicitly relaunch.
79+
80+## Keyboard Shortcuts
81+
82+Minimal set matching TUI controls:
83+- `q` / `Ctrl+C` — Quit
84+- `n` — New agent
85+- `d` — Delete selected agent
86+- `r` — Relaunch selected agent
87+- `s` — Stop selected agent
88+- `b` — Broadcast message to all
89+- `m` — Message selected agent
90+- `c` — Configure selected agent
91+- `Tab` / `Shift+Tab` — Navigate between agents
92+- `?` — Help overlay
93+
94+## Build & Operations
95+
96+- **Task Runner:** `Makefile` for standard commands.
97+- **Commands:**
98+ - `make fmt` — Format code (`go fmt ./...`)
99+ - `make build` — Compile binary
100+ - `make run` — Build and start
101+ - `make test` — Run tests
102+- **Versioning:** Semver. Version injected at build time via `-ldflags`.
103+
104+## Logging
105+
106+- **Library:** `zerolog` for structured logs.
107+- **Output:** Truncated log file at `$HOME/.zoea-nova/zoea.log`. Rotated/truncated on startup to keep size manageable.
108+- **No metrics or tracing** — MVP scope.
109+
110+## Code Practices & Organization
111+
112+- **Separation of Concerns:**
113+ - `internal/core`: Pure orchestration logic, swarm management, and state.
114+ - `internal/tui`: Bubble Tea models, views, and update logic.
115+ - `internal/mcp`: MCP client/proxy implementation and tool definitions.
116+ - `internal/provider`: LLM provider implementations (Ollama, OpenCode Zen).
117+ - `internal/config`: Configuration loading (TOML + ENV merge).
118+ - `internal/store`: SQLite repository layer and migrations.
119+- **Concurrency Model:** Each agent operates in an isolated goroutine. State updates are pushed to the TUI via a central command/message bus to ensure thread-safety.
120+- **Interface-Driven:** All external dependencies (LLMs, MCP servers) must be hidden behind interfaces to facilitate unit testing and future-proofing.
121+- **Testing:** Mandatory unit tests for `internal/core` logic. TUI components should be tested using `bubbletea`'s testing utilities. Aim for above 80% test coverage. No flaky tests.
122+- **Warnings and Errors** Fix all that you see, even if it's from your current changes.
Makefile+20−0
@@ -0,0 +1,20 @@
1+.PHONY: fmt build run test clean
2+
3+VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
4+LDFLAGS := -ldflags "-X main.Version=$(VERSION)"
5+
6+fmt:
7+ go fmt ./...
8+
9+build:
10+ go build $(LDFLAGS) -o bin/zoea ./cmd/zoea
11+
12+run: build
13+ ./bin/zoea
14+
15+test:
16+ go test -v -race -coverprofile=coverage.out ./...
17+ go tool cover -func=coverage.out
18+
19+clean:
20+ rm -rf bin/ coverage.out
README.md+17−0
@@ -0,0 +1,17 @@
1+<p align="center">
2+ <img src="assets/logos/logo-brand.svg" width="300" alt="Zoea-Nova Logo">
3+</p>
4+
5+# Zoea-Nova
6+
7+Zoea-Nova is a high-performance command center designed to orchestrate massive swarms of agents within the SpaceMolt universe. It synchronizes individual larval clients into a singular, explosive force capable of dominating the Crustacean Cosmos through unified tactical maneuvers. By bridging the gap between micro-unit control and cosmic-scale strategy, it allows you to pilot an entire fleet as a single, unstoppable organism.
8+
9+> **It's actually just a fancy TUI App to control several mcp clients for the game: [SpaceMolt](https://www.spacemolt.com/)**
10+
11+## Try it
12+
13+```sh
14+make run # Build and start
15+./bin/zoea # Run directly
16+./bin/zoea -debug # With debug logging
17+```
assets/logos/logo-brand.svg+20−0
@@ -0,0 +1,20 @@
1+<svg viewBox="0 0 400 500" xmlns="http://www.w3.org/2000/svg">
2+ <!-- The Swarm-Hex: Fleet formation -->
3+ <defs>
4+ <polygon id="hex" points="30,0 60,17 60,52 30,69 0,52 0,17" />
5+ <linearGradient id="brandGrad" x1="0%" y1="0%" x2="100%" y2="0%">
6+ <stop offset="0%" style="stop-color:#9D00FF;stop-opacity:1" />
7+ <stop offset="100%" style="stop-color:#00FFCC;stop-opacity:1" />
8+ </linearGradient>
9+ </defs>
10+ <g fill="#9D00FF">
11+ <use href="#hex" x="170" y="50" />
12+ <use href="#hex" x="120" y="130" />
13+ <use href="#hex" x="220" y="130" />
14+ <use href="#hex" x="70" y="210" />
15+ <use href="#hex" x="170" y="210" />
16+ <use href="#hex" x="270" y="210" />
17+ <use href="#hex" x="170" y="290" fill="#00FFCC" />
18+ </g>
19+ <text x="200" y="440" font-family="monospace" font-weight="bold" font-size="48" fill="url(#brandGrad)" text-anchor="middle">ZOEA-NOVA</text>
20+</svg>
assets/logos/logo.svg+15−0
@@ -0,0 +1,15 @@
1+<svg viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg">
2+ <!-- The Swarm-Hex: Fleet formation -->
3+ <defs>
4+ <polygon id="hex" points="30,0 60,17 60,52 30,69 0,52 0,17" />
5+ </defs>
6+ <g fill="#9D00FF">
7+ <use href="#hex" x="170" y="50" />
8+ <use href="#hex" x="120" y="130" />
9+ <use href="#hex" x="220" y="130" />
10+ <use href="#hex" x="70" y="210" />
11+ <use href="#hex" x="170" y="210" />
12+ <use href="#hex" x="270" y="210" />
13+ <use href="#hex" x="170" y="290" fill="#00FFCC" />
14+ </g>
15+</svg>
cmd/zoea/main.go+169−0
@@ -0,0 +1,169 @@
1+package main
2+
3+import (
4+ "flag"
5+ "fmt"
6+ "os"
7+ "os/signal"
8+ "path/filepath"
9+ "syscall"
10+
11+ tea "github.com/charmbracelet/bubbletea"
12+ "github.com/rs/zerolog"
13+ "github.com/rs/zerolog/log"
14+
15+ "github.com/xonecas/zoea-nova/internal/config"
16+ "github.com/xonecas/zoea-nova/internal/core"
17+ "github.com/xonecas/zoea-nova/internal/mcp"
18+ "github.com/xonecas/zoea-nova/internal/provider"
19+ "github.com/xonecas/zoea-nova/internal/store"
20+ "github.com/xonecas/zoea-nova/internal/tui"
21+)
22+
23+// Version is set at build time via ldflags.
24+var Version = "dev"
25+
26+func main() {
27+ // Parse flags
28+ var (
29+ showVersion = flag.Bool("version", false, "Show version and exit")
30+ configPath = flag.String("config", "config.toml", "Path to config file")
31+ debug = flag.Bool("debug", false, "Enable debug logging")
32+ )
33+ flag.Parse()
34+
35+ if *showVersion {
36+ fmt.Printf("Zoea Nova %s\n", Version)
37+ os.Exit(0)
38+ }
39+
40+ // Initialize logging
41+ if err := initLogging(*debug); err != nil {
42+ fmt.Fprintf(os.Stderr, "Failed to initialize logging: %v\n", err)
43+ os.Exit(1)
44+ }
45+
46+ log.Info().Str("version", Version).Msg("Starting Zoea Nova")
47+
48+ // Load configuration
49+ cfg, err := config.Load(*configPath)
50+ if err != nil {
51+ log.Fatal().Err(err).Msg("Failed to load config")
52+ }
53+ log.Debug().Interface("config", cfg).Msg("Configuration loaded")
54+
55+ // Load credentials
56+ creds, err := config.LoadCredentials()
57+ if err != nil {
58+ log.Warn().Err(err).Msg("Failed to load credentials")
59+ creds = &config.Credentials{}
60+ }
61+
62+ // Initialize store
63+ s, err := store.New()
64+ if err != nil {
65+ log.Fatal().Err(err).Msg("Failed to initialize store")
66+ }
67+ defer s.Close()
68+ log.Debug().Msg("Store initialized")
69+
70+ // Initialize event bus
71+ bus := core.NewEventBus(1000)
72+ defer bus.Close()
73+
74+ // Initialize provider registry
75+ registry := initProviders(cfg, creds)
76+ log.Debug().Int("providers", len(registry.List())).Msg("Providers initialized")
77+
78+ // Initialize commander
79+ commander := core.NewCommander(s, registry, bus, cfg)
80+
81+ // Load existing agents
82+ if err := commander.LoadAgents(); err != nil {
83+ log.Warn().Err(err).Msg("Failed to load existing agents")
84+ }
85+ log.Debug().Int("agents", commander.AgentCount()).Msg("Agents loaded")
86+
87+ // Initialize MCP proxy
88+ mcpProxy := mcp.NewProxy(cfg.MCP.Upstream)
89+ mcp.RegisterOrchestratorTools(mcpProxy, commander)
90+ log.Debug().Bool("upstream", mcpProxy.HasUpstream()).Int("local_tools", mcpProxy.LocalToolCount()).Msg("MCP proxy initialized")
91+
92+ // Set up signal handling for graceful shutdown
93+ sigCh := make(chan os.Signal, 1)
94+ signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
95+
96+ // Subscribe to events for TUI
97+ eventCh := bus.Subscribe()
98+
99+ // Create and run TUI
100+ model := tui.New(commander, s, eventCh)
101+ program := tea.NewProgram(model, tea.WithAltScreen())
102+
103+ // Handle shutdown in a goroutine
104+ go func() {
105+ <-sigCh
106+ log.Info().Msg("Received shutdown signal")
107+ commander.StopAll()
108+ program.Quit()
109+ }()
110+
111+ // Run the TUI
112+ if _, err := program.Run(); err != nil {
113+ log.Fatal().Err(err).Msg("TUI error")
114+ }
115+
116+ // Clean shutdown
117+ commander.StopAll()
118+ log.Info().Msg("Zoea Nova shutdown complete")
119+}
120+
121+func initLogging(debug bool) error {
122+ // Ensure data directory exists
123+ dataDir, err := config.EnsureDataDir()
124+ if err != nil {
125+ return fmt.Errorf("ensure data dir: %w", err)
126+ }
127+
128+ // Open log file (truncate on startup)
129+ logPath := filepath.Join(dataDir, "zoea.log")
130+ logFile, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
131+ if err != nil {
132+ return fmt.Errorf("open log file: %w", err)
133+ }
134+
135+ // Configure zerolog
136+ zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
137+
138+ if debug {
139+ zerolog.SetGlobalLevel(zerolog.DebugLevel)
140+ } else {
141+ zerolog.SetGlobalLevel(zerolog.InfoLevel)
142+ }
143+
144+ // Log to file only (TUI owns stdout/stderr)
145+ log.Logger = zerolog.New(logFile).With().Timestamp().Logger()
146+
147+ return nil
148+}
149+
150+func initProviders(cfg *config.Config, creds *config.Credentials) *provider.Registry {
151+ registry := provider.NewRegistry()
152+
153+ // Register Ollama provider
154+ if ollCfg, ok := cfg.Providers["ollama"]; ok {
155+ p := provider.NewOllama(ollCfg.Endpoint, ollCfg.Model)
156+ registry.Register(p)
157+ }
158+
159+ // Register OpenCode Zen provider
160+ if zenCfg, ok := cfg.Providers["opencode_zen"]; ok {
161+ apiKey := creds.GetAPIKey("opencode_zen")
162+ if apiKey != "" {
163+ p := provider.NewOpenCode(zenCfg.Endpoint, zenCfg.Model, apiKey)
164+ registry.Register(p)
165+ }
166+ }
167+
168+ return registry
169+}
config.toml+14−0
@@ -0,0 +1,14 @@
1+[swarm]
2+default_agents = 4
3+max_agents = 16
4+
5+[providers.ollama]
6+endpoint = "http://localhost:11434"
7+model = "llama3"
8+
9+[providers.opencode_zen]
10+endpoint = "https://api.opencode.ai/v1"
11+model = "zen-default"
12+
13+[mcp]
14+upstream = "https://game.spacemolt.com/mcp"
go.mod+46−0
@@ -0,0 +1,46 @@
1+module github.com/xonecas/zoea-nova
2+
3+go 1.24.2
4+
5+require (
6+ github.com/BurntSushi/toml v1.6.0
7+ github.com/charmbracelet/bubbles v0.21.1
8+ github.com/charmbracelet/bubbletea v1.3.10
9+ github.com/charmbracelet/lipgloss v1.1.0
10+ github.com/google/uuid v1.6.0
11+ github.com/rs/zerolog v1.34.0
12+ github.com/sashabaranov/go-openai v1.41.2
13+ modernc.org/sqlite v1.44.3
14+)
15+
16+require (
17+ github.com/atotto/clipboard v0.1.4 // indirect
18+ github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
19+ github.com/charmbracelet/colorprofile v0.4.1 // indirect
20+ github.com/charmbracelet/x/ansi v0.11.5 // indirect
21+ github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
22+ github.com/charmbracelet/x/term v0.2.2 // indirect
23+ github.com/clipperhouse/displaywidth v0.9.0 // indirect
24+ github.com/clipperhouse/stringish v0.1.1 // indirect
25+ github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
26+ github.com/dustin/go-humanize v1.0.1 // indirect
27+ github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
28+ github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
29+ github.com/mattn/go-colorable v0.1.13 // indirect
30+ github.com/mattn/go-isatty v0.0.20 // indirect
31+ github.com/mattn/go-localereader v0.0.1 // indirect
32+ github.com/mattn/go-runewidth v0.0.19 // indirect
33+ github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
34+ github.com/muesli/cancelreader v0.2.2 // indirect
35+ github.com/muesli/termenv v0.16.0 // indirect
36+ github.com/ncruces/go-strftime v1.0.0 // indirect
37+ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
38+ github.com/rivo/uniseg v0.4.7 // indirect
39+ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
40+ golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
41+ golang.org/x/sys v0.38.0 // indirect
42+ golang.org/x/text v0.3.8 // indirect
43+ modernc.org/libc v1.67.6 // indirect
44+ modernc.org/mathutil v1.7.1 // indirect
45+ modernc.org/memory v1.11.0 // indirect
46+)
go.sum+114−0
@@ -0,0 +1,114 @@
1+github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
2+github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
3+github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
4+github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
5+github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
6+github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
7+github.com/charmbracelet/bubbles v0.21.1 h1:nj0decPiixaZeL9diI4uzzQTkkz1kYY8+jgzCZXSmW0=
8+github.com/charmbracelet/bubbles v0.21.1/go.mod h1:HHvIYRCpbkCJw2yo0vNX1O5loCwSr9/mWS8GYSg50Sk=
9+github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
10+github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
11+github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
12+github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
13+github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
14+github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
15+github.com/charmbracelet/x/ansi v0.11.5 h1:NBWeBpj/lJPE3Q5l+Lusa4+mH6v7487OP8K0r1IhRg4=
16+github.com/charmbracelet/x/ansi v0.11.5/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
17+github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
18+github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
19+github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
20+github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
21+github.com/clipperhouse/displaywidth v0.9.0 h1:Qb4KOhYwRiN3viMv1v/3cTBlz3AcAZX3+y9OLhMtAtA=
22+github.com/clipperhouse/displaywidth v0.9.0/go.mod h1:aCAAqTlh4GIVkhQnJpbL0T/WfcrJXHcj8C0yjYcjOZA=
23+github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
24+github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
25+github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=
26+github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
27+github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
28+github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
29+github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
30+github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
31+github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
32+github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
33+github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
34+github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
35+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
36+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
37+github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
38+github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
39+github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
40+github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
41+github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
42+github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
43+github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
44+github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
45+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
46+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
47+github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
48+github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
49+github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
50+github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
51+github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
52+github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
53+github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
54+github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
55+github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
56+github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
57+github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
58+github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
59+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
60+github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
61+github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
62+github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
63+github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
64+github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
65+github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
66+github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
67+github.com/sashabaranov/go-openai v1.41.2 h1:vfPRBZNMpnqu8ELsclWcAvF19lDNgh1t6TVfFFOPiSM=
68+github.com/sashabaranov/go-openai v1.41.2/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
69+github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
70+github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
71+golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
72+golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
73+golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
74+golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
75+golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
76+golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
77+golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
78+golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
79+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
80+golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
81+golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
82+golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
83+golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
84+golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
85+golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
86+golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
87+modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis=
88+modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
89+modernc.org/ccgo/v4 v4.30.1 h1:4r4U1J6Fhj98NKfSjnPUN7Ze2c6MnAdL0hWw6+LrJpc=
90+modernc.org/ccgo/v4 v4.30.1/go.mod h1:bIOeI1JL54Utlxn+LwrFyjCx2n2RDiYEaJVSrgdrRfM=
91+modernc.org/fileutil v1.3.40 h1:ZGMswMNc9JOCrcrakF1HrvmergNLAmxOPjizirpfqBA=
92+modernc.org/fileutil v1.3.40/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
93+modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
94+modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
95+modernc.org/gc/v3 v3.1.1 h1:k8T3gkXWY9sEiytKhcgyiZ2L0DTyCQ/nvX+LoCljoRE=
96+modernc.org/gc/v3 v3.1.1/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
97+modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
98+modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
99+modernc.org/libc v1.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI=
100+modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE=
101+modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
102+modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
103+modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
104+modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
105+modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
106+modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
107+modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
108+modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
109+modernc.org/sqlite v1.44.3 h1:+39JvV/HWMcYslAwRxHb8067w+2zowvFOUrOWIy9PjY=
110+modernc.org/sqlite v1.44.3/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA=
111+modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
112+modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
113+modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
114+modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
internal/config/config.go+140−0
@@ -0,0 +1,140 @@
1+// Package config handles configuration loading from TOML files and environment variables.
2+package config
3+
4+import (
5+ "os"
6+ "path/filepath"
7+ "strconv"
8+
9+ "github.com/BurntSushi/toml"
10+)
11+
12+// Config is the root configuration structure.
13+type Config struct {
14+ Swarm SwarmConfig `toml:"swarm"`
15+ Providers map[string]ProviderConfig `toml:"providers"`
16+ MCP MCPConfig `toml:"mcp"`
17+}
18+
19+// SwarmConfig holds swarm-related settings.
20+type SwarmConfig struct {
21+ DefaultAgents int `toml:"default_agents"`
22+ MaxAgents int `toml:"max_agents"`
23+}
24+
25+// ProviderConfig holds LLM provider settings.
26+type ProviderConfig struct {
27+ Endpoint string `toml:"endpoint"`
28+ Model string `toml:"model"`
29+}
30+
31+// MCPConfig holds MCP proxy settings.
32+type MCPConfig struct {
33+ Upstream string `toml:"upstream"`
34+}
35+
36+// DefaultConfig returns a configuration with sensible defaults.
37+func DefaultConfig() *Config {
38+ return &Config{
39+ Swarm: SwarmConfig{
40+ DefaultAgents: 4,
41+ MaxAgents: 16,
42+ },
43+ Providers: map[string]ProviderConfig{
44+ "ollama": {
45+ Endpoint: "http://localhost:11434",
46+ Model: "llama3",
47+ },
48+ },
49+ MCP: MCPConfig{
50+ Upstream: "https://game.spacemolt.com/mcp",
51+ },
52+ }
53+}
54+
55+// Load reads configuration from a TOML file and applies environment variable overrides.
56+func Load(path string) (*Config, error) {
57+ cfg := DefaultConfig()
58+
59+ // Load from file if it exists
60+ if path != "" {
61+ if _, err := os.Stat(path); err == nil {
62+ if _, err := toml.DecodeFile(path, cfg); err != nil {
63+ return nil, err
64+ }
65+ }
66+ }
67+
68+ // Apply environment variable overrides
69+ applyEnvOverrides(cfg)
70+
71+ return cfg, nil
72+}
73+
74+// applyEnvOverrides applies environment variable overrides to the configuration.
75+func applyEnvOverrides(cfg *Config) {
76+ if v := os.Getenv("ZOEA_DEFAULT_AGENTS"); v != "" {
77+ if n, err := strconv.Atoi(v); err == nil {
78+ cfg.Swarm.DefaultAgents = n
79+ }
80+ }
81+
82+ if v := os.Getenv("ZOEA_MAX_AGENTS"); v != "" {
83+ if n, err := strconv.Atoi(v); err == nil {
84+ cfg.Swarm.MaxAgents = n
85+ }
86+ }
87+
88+ if v := os.Getenv("ZOEA_MCP_ENDPOINT"); v != "" {
89+ cfg.MCP.Upstream = v
90+ }
91+
92+ if v := os.Getenv("ZOEA_OLLAMA_ENDPOINT"); v != "" {
93+ if p, ok := cfg.Providers["ollama"]; ok {
94+ p.Endpoint = v
95+ cfg.Providers["ollama"] = p
96+ }
97+ }
98+
99+ if v := os.Getenv("ZOEA_OLLAMA_MODEL"); v != "" {
100+ if p, ok := cfg.Providers["ollama"]; ok {
101+ p.Model = v
102+ cfg.Providers["ollama"] = p
103+ }
104+ }
105+
106+ if v := os.Getenv("ZOEA_OPENCODE_ENDPOINT"); v != "" {
107+ if p, ok := cfg.Providers["opencode_zen"]; ok {
108+ p.Endpoint = v
109+ cfg.Providers["opencode_zen"] = p
110+ }
111+ }
112+
113+ if v := os.Getenv("ZOEA_OPENCODE_MODEL"); v != "" {
114+ if p, ok := cfg.Providers["opencode_zen"]; ok {
115+ p.Model = v
116+ cfg.Providers["opencode_zen"] = p
117+ }
118+ }
119+}
120+
121+// DataDir returns the path to the Zoea data directory (~/.zoea-nova).
122+func DataDir() (string, error) {
123+ home, err := os.UserHomeDir()
124+ if err != nil {
125+ return "", err
126+ }
127+ return filepath.Join(home, ".zoea-nova"), nil
128+}
129+
130+// EnsureDataDir creates the data directory if it doesn't exist.
131+func EnsureDataDir() (string, error) {
132+ dir, err := DataDir()
133+ if err != nil {
134+ return "", err
135+ }
136+ if err := os.MkdirAll(dir, 0755); err != nil {
137+ return "", err
138+ }
139+ return dir, nil
140+}
internal/config/config_test.go+167−0
@@ -0,0 +1,167 @@
1+package config
2+
3+import (
4+ "os"
5+ "path/filepath"
6+ "testing"
7+)
8+
9+func TestDefaultConfig(t *testing.T) {
10+ cfg := DefaultConfig()
11+
12+ if cfg.Swarm.DefaultAgents != 4 {
13+ t.Errorf("expected default_agents=4, got %d", cfg.Swarm.DefaultAgents)
14+ }
15+ if cfg.Swarm.MaxAgents != 16 {
16+ t.Errorf("expected max_agents=16, got %d", cfg.Swarm.MaxAgents)
17+ }
18+ if _, ok := cfg.Providers["ollama"]; !ok {
19+ t.Error("expected ollama provider in defaults")
20+ }
21+}
22+
23+func TestLoadFromFile(t *testing.T) {
24+ // Create temp config file
25+ tmpDir := t.TempDir()
26+ configPath := filepath.Join(tmpDir, "config.toml")
27+
28+ content := `
29+[swarm]
30+default_agents = 8
31+max_agents = 32
32+
33+[providers.ollama]
34+endpoint = "http://custom:11434"
35+model = "mistral"
36+
37+[mcp]
38+upstream = "https://custom.mcp/endpoint"
39+`
40+ if err := os.WriteFile(configPath, []byte(content), 0644); err != nil {
41+ t.Fatalf("failed to write test config: %v", err)
42+ }
43+
44+ cfg, err := Load(configPath)
45+ if err != nil {
46+ t.Fatalf("Load() error: %v", err)
47+ }
48+
49+ if cfg.Swarm.DefaultAgents != 8 {
50+ t.Errorf("expected default_agents=8, got %d", cfg.Swarm.DefaultAgents)
51+ }
52+ if cfg.Swarm.MaxAgents != 32 {
53+ t.Errorf("expected max_agents=32, got %d", cfg.Swarm.MaxAgents)
54+ }
55+ if cfg.Providers["ollama"].Endpoint != "http://custom:11434" {
56+ t.Errorf("expected custom ollama endpoint, got %s", cfg.Providers["ollama"].Endpoint)
57+ }
58+ if cfg.MCP.Upstream != "https://custom.mcp/endpoint" {
59+ t.Errorf("expected custom mcp upstream, got %s", cfg.MCP.Upstream)
60+ }
61+}
62+
63+func TestLoadWithEnvOverrides(t *testing.T) {
64+ // Set env vars
65+ os.Setenv("ZOEA_DEFAULT_AGENTS", "2")
66+ os.Setenv("ZOEA_MAX_AGENTS", "10")
67+ os.Setenv("ZOEA_MCP_ENDPOINT", "https://env.mcp/endpoint")
68+ defer func() {
69+ os.Unsetenv("ZOEA_DEFAULT_AGENTS")
70+ os.Unsetenv("ZOEA_MAX_AGENTS")
71+ os.Unsetenv("ZOEA_MCP_ENDPOINT")
72+ }()
73+
74+ cfg, err := Load("")
75+ if err != nil {
76+ t.Fatalf("Load() error: %v", err)
77+ }
78+
79+ if cfg.Swarm.DefaultAgents != 2 {
80+ t.Errorf("expected env override default_agents=2, got %d", cfg.Swarm.DefaultAgents)
81+ }
82+ if cfg.Swarm.MaxAgents != 10 {
83+ t.Errorf("expected env override max_agents=10, got %d", cfg.Swarm.MaxAgents)
84+ }
85+ if cfg.MCP.Upstream != "https://env.mcp/endpoint" {
86+ t.Errorf("expected env override mcp endpoint, got %s", cfg.MCP.Upstream)
87+ }
88+}
89+
90+func TestLoadNonExistentFile(t *testing.T) {
91+ cfg, err := Load("/nonexistent/path/config.toml")
92+ if err != nil {
93+ t.Fatalf("Load() should not error for non-existent file: %v", err)
94+ }
95+
96+ // Should return defaults
97+ if cfg.Swarm.DefaultAgents != 4 {
98+ t.Errorf("expected default_agents=4, got %d", cfg.Swarm.DefaultAgents)
99+ }
100+}
101+
102+func TestCredentials(t *testing.T) {
103+ creds := &Credentials{
104+ Providers: make(map[string]ProviderCredentials),
105+ }
106+
107+ // Test GetAPIKey on empty
108+ if key := creds.GetAPIKey("opencode_zen"); key != "" {
109+ t.Errorf("expected empty key, got %s", key)
110+ }
111+
112+ // Test SetAPIKey
113+ creds.SetAPIKey("opencode_zen", "test-api-key")
114+ if key := creds.GetAPIKey("opencode_zen"); key != "test-api-key" {
115+ t.Errorf("expected test-api-key, got %s", key)
116+ }
117+}
118+
119+func TestCredentialsSaveLoad(t *testing.T) {
120+ // Override home dir for test
121+ tmpDir := t.TempDir()
122+ originalHome := os.Getenv("HOME")
123+ os.Setenv("HOME", tmpDir)
124+ defer os.Setenv("HOME", originalHome)
125+
126+ // Create and save credentials
127+ creds := &Credentials{}
128+ creds.SetAPIKey("opencode_zen", "secret-key-123")
129+
130+ if err := SaveCredentials(creds); err != nil {
131+ t.Fatalf("SaveCredentials() error: %v", err)
132+ }
133+
134+ // Verify file permissions
135+ path := filepath.Join(tmpDir, ".zoea-nova", "credentials.json")
136+ info, err := os.Stat(path)
137+ if err != nil {
138+ t.Fatalf("credentials file not created: %v", err)
139+ }
140+ if info.Mode().Perm() != 0600 {
141+ t.Errorf("expected permissions 0600, got %o", info.Mode().Perm())
142+ }
143+
144+ // Load credentials back
145+ loaded, err := LoadCredentials()
146+ if err != nil {
147+ t.Fatalf("LoadCredentials() error: %v", err)
148+ }
149+ if key := loaded.GetAPIKey("opencode_zen"); key != "secret-key-123" {
150+ t.Errorf("expected secret-key-123, got %s", key)
151+ }
152+}
153+
154+func TestLoadCredentialsNonExistent(t *testing.T) {
155+ tmpDir := t.TempDir()
156+ originalHome := os.Getenv("HOME")
157+ os.Setenv("HOME", tmpDir)
158+ defer os.Setenv("HOME", originalHome)
159+
160+ creds, err := LoadCredentials()
161+ if err != nil {
162+ t.Fatalf("LoadCredentials() should not error for non-existent file: %v", err)
163+ }
164+ if creds == nil {
165+ t.Fatal("expected non-nil credentials")
166+ }
167+}
internal/config/credentials.go+83−0
@@ -0,0 +1,83 @@
1+package config
2+
3+import (
4+ "encoding/json"
5+ "os"
6+ "path/filepath"
7+)
8+
9+// Credentials holds API keys for LLM providers.
10+type Credentials struct {
11+ Providers map[string]ProviderCredentials `json:"providers"`
12+}
13+
14+// ProviderCredentials holds authentication for a single provider.
15+type ProviderCredentials struct {
16+ APIKey string `json:"api_key"`
17+}
18+
19+// LoadCredentials reads credentials from ~/.zoea-nova/credentials.json.
20+func LoadCredentials() (*Credentials, error) {
21+ path, err := credentialsPath()
22+ if err != nil {
23+ return nil, err
24+ }
25+
26+ creds := &Credentials{
27+ Providers: make(map[string]ProviderCredentials),
28+ }
29+
30+ data, err := os.ReadFile(path)
31+ if os.IsNotExist(err) {
32+ return creds, nil
33+ }
34+ if err != nil {
35+ return nil, err
36+ }
37+
38+ if err := json.Unmarshal(data, creds); err != nil {
39+ return nil, err
40+ }
41+
42+ return creds, nil
43+}
44+
45+// SaveCredentials writes credentials to ~/.zoea-nova/credentials.json with 0600 permissions.
46+func SaveCredentials(creds *Credentials) error {
47+ dir, err := EnsureDataDir()
48+ if err != nil {
49+ return err
50+ }
51+
52+ path := filepath.Join(dir, "credentials.json")
53+ data, err := json.MarshalIndent(creds, "", " ")
54+ if err != nil {
55+ return err
56+ }
57+
58+ return os.WriteFile(path, data, 0600)
59+}
60+
61+// GetAPIKey returns the API key for a given provider, or empty string if not set.
62+func (c *Credentials) GetAPIKey(provider string) string {
63+ if c == nil || c.Providers == nil {
64+ return ""
65+ }
Cut short: this commit's diff is over 1000 lines.
internal/core/agent.go+260−0
Cut short: this commit's diff is over 1000 lines.
internal/core/agent_test.go+195−0
Cut short: this commit's diff is over 1000 lines.
internal/core/bus.go+73−0
Cut short: this commit's diff is over 1000 lines.
internal/core/bus_test.go+117−0
Cut short: this commit's diff is over 1000 lines.
internal/core/commander.go+287−0
Cut short: this commit's diff is over 1000 lines.
internal/core/commander_test.go+385−0
Cut short: this commit's diff is over 1000 lines.
internal/core/types.go+62−0
Cut short: this commit's diff is over 1000 lines.
internal/mcp/client.go+143−0
Cut short: this commit's diff is over 1000 lines.
internal/mcp/mcp_test.go+256−0
Cut short: this commit's diff is over 1000 lines.
internal/mcp/proxy.go+131−0
Cut short: this commit's diff is over 1000 lines.
internal/mcp/tools.go+205−0
Cut short: this commit's diff is over 1000 lines.
internal/mcp/types.go+122−0
Cut short: this commit's diff is over 1000 lines.
internal/provider/mock.go+62−0
Cut short: this commit's diff is over 1000 lines.
internal/provider/ollama.go+95−0
Cut short: this commit's diff is over 1000 lines.
internal/provider/opencode.go+83−0
Cut short: this commit's diff is over 1000 lines.
internal/provider/provider.go+70−0
Cut short: this commit's diff is over 1000 lines.
internal/provider/provider_test.go+146−0
Cut short: this commit's diff is over 1000 lines.
internal/store/agents.go+158−0
Cut short: this commit's diff is over 1000 lines.
internal/store/memories.go+118−0
Cut short: this commit's diff is over 1000 lines.
internal/store/schema.sql+29−0
Cut short: this commit's diff is over 1000 lines.
internal/store/store.go+113−0
Cut short: this commit's diff is over 1000 lines.
internal/store/store_test.go+231−0
Cut short: this commit's diff is over 1000 lines.
internal/tui/app.go+379−0
Cut short: this commit's diff is over 1000 lines.
internal/tui/dashboard.go+117−0
Cut short: this commit's diff is over 1000 lines.
internal/tui/focus.go+111−0
Cut short: this commit's diff is over 1000 lines.
internal/tui/help.go+85−0
Cut short: this commit's diff is over 1000 lines.
internal/tui/input.go+116−0
Cut short: this commit's diff is over 1000 lines.
internal/tui/styles.go+170−0
Cut short: this commit's diff is over 1000 lines.
internal/tui/tui_test.go+270−0
Cut short: this commit's diff is over 1000 lines.