Adapted from tau's eventbus/metrics designs (per Sam), slimmed for a small daemon: - internal/events: single-type bus with mutex fan-out and bounded per-subscriber buffers that DROP on overflow (counted) — a stalled dashboard can never backpressure the task engine (tau's blocking delivery deliberately not copied) - store: events table + queries powering the dashboards: task timelines, per-workflow outcomes/spend, stage durations and error counts (from stage_finish events), token spend by day - emit points: task_queued, stage_start/finish(duration, error), agent_finish(status, tokens, steps, model), parked, outcome, pr_merged/pr_rejected - internal/webui: read-only dashboard (embedded single page, no build step) — status cards, task board with click-through timelines, live SSE event tail with catch-up via ?since=<event id>, workflow/stage metrics tables. [web] listen config, default 127.0.0.1:8484, no auth by design (bind localhost/tailnet); "off" disables - sink pipeline: bus -> SQLite insert (stamps row id) -> SSE broadcast Verified live: dashboard serves real workflow stats from the existing task history; bus overflow and event-log round-trips unit-tested.
144 lines
3.8 KiB
Go
144 lines
3.8 KiB
Go
// Package config loads archied's TOML configuration. The GitHub token is
|
|
// deliberately not part of the file: it comes from ARCHIE_GITHUB_TOKEN.
|
|
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
// Duration is a time.Duration that unmarshals from TOML strings ("60s").
|
|
type Duration time.Duration
|
|
|
|
func (d *Duration) UnmarshalText(b []byte) error {
|
|
v, err := time.ParseDuration(string(b))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*d = Duration(v)
|
|
return nil
|
|
}
|
|
|
|
func (d Duration) Std() time.Duration { return time.Duration(d) }
|
|
|
|
// Repo is one managed repository.
|
|
type Repo struct {
|
|
Owner string `toml:"owner"`
|
|
Name string `toml:"name"`
|
|
// Base is the branch PRs target. Defaults to "main".
|
|
Base string `toml:"base"`
|
|
// Gate is the quality-gate command list for this repo, e.g.
|
|
// [["go","vet","./..."], ["task","check"]]. Workflow stages may
|
|
// extend or override it (a TDD repro stage inverts the test command).
|
|
Gate [][]string `toml:"gate"`
|
|
}
|
|
|
|
func (r Repo) FullName() string { return r.Owner + "/" + r.Name }
|
|
|
|
func (r Repo) BaseBranch() string {
|
|
if r.Base == "" {
|
|
return "main"
|
|
}
|
|
return r.Base
|
|
}
|
|
|
|
// Budgets bound every agent stage. Zero disables a limit.
|
|
type Budgets struct {
|
|
MaxSteps int `toml:"max_steps"`
|
|
MaxTokens int `toml:"max_tokens"`
|
|
WallClock Duration `toml:"wall_clock"`
|
|
GateMaxFailures int `toml:"gate_max_failures"`
|
|
}
|
|
|
|
// Provider configures one LLM provider for the runtime catalog.
|
|
type Provider struct {
|
|
Class string `toml:"class"`
|
|
APIKeyEnv string `toml:"api_key_env"`
|
|
BaseURL string `toml:"base_url"`
|
|
}
|
|
|
|
// Config is the daemon configuration.
|
|
type Config struct {
|
|
WorkDir string `toml:"work_dir"`
|
|
DBPath string `toml:"db_path"`
|
|
PollInterval Duration `toml:"poll_interval"`
|
|
// Label marks issues archie should pick up.
|
|
Label string `toml:"label"`
|
|
BotUser string `toml:"bot_user"`
|
|
// BotEmail is the git author email; defaults to the GitHub noreply
|
|
// address for BotUser.
|
|
BotEmail string `toml:"bot_email"`
|
|
DiffCapLines int `toml:"diff_cap_lines"`
|
|
|
|
// Models maps a role ("planner", "builder", "triage") to a runtime
|
|
// model ref ("provider/model").
|
|
Models map[string]string `toml:"models"`
|
|
|
|
Providers map[string]Provider `toml:"providers"`
|
|
|
|
Budgets Budgets `toml:"budgets"`
|
|
Web Web `toml:"web"`
|
|
Repos []Repo `toml:"repos"`
|
|
}
|
|
|
|
// Web configures the observability dashboard.
|
|
type Web struct {
|
|
// Listen is the dashboard address; empty disables the web UI.
|
|
// Bind localhost (or a LAN/tailnet address) — there is no auth.
|
|
Listen string `toml:"listen"`
|
|
}
|
|
|
|
// Load reads, parses, and defaults the configuration.
|
|
func Load(path string) (Config, error) {
|
|
var cfg Config
|
|
if _, err := toml.DecodeFile(path, &cfg); err != nil {
|
|
return cfg, fmt.Errorf("config %s: %w", path, err)
|
|
}
|
|
if cfg.WorkDir == "" {
|
|
cfg.WorkDir = filepath.Join(dataHome(), "archie", "work")
|
|
}
|
|
if cfg.DBPath == "" {
|
|
cfg.DBPath = filepath.Join(dataHome(), "archie", "archie.db")
|
|
}
|
|
if cfg.PollInterval == 0 {
|
|
cfg.PollInterval = Duration(60 * time.Second)
|
|
}
|
|
if cfg.Label == "" {
|
|
cfg.Label = "archie"
|
|
}
|
|
if cfg.DiffCapLines == 0 {
|
|
cfg.DiffCapLines = 400
|
|
}
|
|
if cfg.Web.Listen == "" {
|
|
cfg.Web.Listen = "127.0.0.1:8484" // "off" disables
|
|
}
|
|
if cfg.BotUser == "" {
|
|
return cfg, errors.New("config: bot_user is required")
|
|
}
|
|
if cfg.BotEmail == "" {
|
|
cfg.BotEmail = cfg.BotUser + "@users.noreply.github.com"
|
|
}
|
|
if len(cfg.Repos) == 0 {
|
|
return cfg, errors.New("config: at least one [[repos]] entry is required")
|
|
}
|
|
for i, r := range cfg.Repos {
|
|
if r.Owner == "" || r.Name == "" {
|
|
return cfg, fmt.Errorf("config: repos[%d] needs owner and name", i)
|
|
}
|
|
}
|
|
return cfg, nil
|
|
}
|
|
|
|
func dataHome() string {
|
|
if x := os.Getenv("XDG_DATA_HOME"); x != "" {
|
|
return x
|
|
}
|
|
home, _ := os.UserHomeDir()
|
|
return filepath.Join(home, ".local", "share")
|
|
}
|