package main
import (
"context"
"flag"
"fmt"
"os"
"assistant/agent"
"assistant/automation"
"assistant/config"
"assistant/llm"
"assistant/memory"
"assistant/server"
"assistant/tools"
"assistant/util"
)
func main() {
cfgPath := flag.String("config", "config/config.yaml", "path to config YAML")
flag.Parse()
cfg, err := config.Load(*cfgPath)
if err != nil {
fmt.Fprintf(os.Stderr, "config: %v\n", err)
os.Exit(1)
}
var store *memory.Store
if cfg.Tools.Tasks.Enabled || cfg.Tools.Memory.Enabled {
db, err := memory.Open(cfg.Memory.DBPath)
if err != nil {
fmt.Fprintf(os.Stderr, "memory: %v\n", err)
os.Exit(1)
}
defer db.Close()
store = memory.NewStore(db)
}
reg, err := tools.BuildRegistry(cfg, store)
if err != nil {
fmt.Fprintf(os.Stderr, "tools: %v\n", err)
os.Exit(1)
}
tel := agent.NewTelemetry(300)
util.SetLogHook(tel.AddLogLine)
llmClient := llm.NewClient(cfg.LLM)
ag := agent.New(llmClient, reg, cfg, tel, store)
api := &server.API{
Agent: ag,
Telemetry: tel,
Store: store,
Model: cfg.LLM.Model,
ContextWindowChars: cfg.Agent.ContextWindowChars,
}
ctx := context.Background()
automation.Start(ctx, cfg, ag, tel)
util.Logf("listening on %s:%d", cfg.Server.Host, cfg.Server.Port)
if err := server.Run(&cfg.Server, api); err != nil {
fmt.Fprintf(os.Stderr, "server: %v\n", err)
os.Exit(1)
}
}