config

package
v2.0.83 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config reads a fleet's configuration from the PostgreSQL store nova-config keeps: its machines, the friends that work on it, the services it runs, and the model providers and models it can call, the rows of the schema config (nova-config schema). It reads them through the same query nova-config's list verbs run, so a program that imports it sees exactly what nova-config prints; writes go through nova-config, which records each one in the history.

Index

Examples

Constants

View Source
const SchemaMissing = `store has no current schema; run: nova-config schema | PGPASSWORD="$NOVA_PG_PASSWORD" psql "$NOVA_PG_DSN"`

SchemaMissing is the error of a store the current schema was never applied to.

Variables

This section is empty.

Functions

func Columns

func Columns[T any]() []string

Columns are a row type's columns, the name and the stamps aside, in order.

func DSNProblem

func DSNProblem(dsn string) string

DSNProblem says which part of a postgres:// URL is wrong, "" for none; it never quotes the URL, which may hold a password.

Types

type Friend

type Friend struct {
	Name     string `json:"name"`
	Harness  string `json:"harness"` // claude, codex, antigravity, grok, muse, ...
	Model    string `json:"model"`
	Pronouns string `json:"pronouns"` // "" when unstated
	Note     string `json:"note"`
	Enabled  bool   `json:"enabled"`
	Created  string `json:"created"`
	Updated  string `json:"updated"`
}

Friend is an AI that works on the fleet, named by its bus name.

type Machine

type Machine struct {
	Name    string `json:"name"`
	Address string `json:"address"` // the tailnet address Ansible and the fleet use
	Public  string `json:"public"`  // the address the internet reaches it at; "" when unset
	User    string `json:"user"`
	OS      string `json:"os"`
	Arch    string `json:"arch"`
	Cores   *int   `json:"cores"` // nil when unknown
	Roles   string `json:"roles"` // of bench, runner, services
	// Routes names the devices or tools the machine has that a piece of work may need: a comma list of
	// names (lower-case letters, digits and dashes); "" for none
	Routes  string `json:"routes"`
	Runners int    `json:"runners"`
	// RunnerScopes is its Linux and macOS GitHub Actions runners: <url>=<count>[:<label>+<label>], comma-separated
	RunnerScopes string `json:"runner_scopes"`
	// WindowsRunners is a WSL machine's Windows-side runners: <url>=<count>[:<label>+<label>], comma-separated
	WindowsRunners string `json:"windows_runners"`
	// WindowsAdminRunners is a WSL machine's Windows-side runners run as a local administrator account, one per entry:
	// <url>=<account>:<label>[+<label>], comma-separated
	WindowsAdminRunners string `json:"windows_admin_runners"`
	// RunnerEnv is the environment its GitHub Actions runners' services start with (the github-runners play)
	RunnerEnv map[string]string `json:"runner_env"`
	Note      string            `json:"note"`
	Created   string            `json:"created"`
	Updated   string            `json:"updated"`
}

Machine is a machine of the fleet, named by its tailnet host.

type Model added in v2.0.76

type Model struct {
	Name           string `json:"name"`
	Harness        string `json:"harness"`          // the harness it runs in: opencode, claude or codex
	PriceIn        *int   `json:"price_in"`         // micro-dollars per million input tokens; nil is unpriced, never free
	PriceOut       *int   `json:"price_out"`        // micro-dollars per million output tokens; nil is unpriced, never free
	PriceCacheRead *int   `json:"price_cache_read"` // micro-dollars per million cached input tokens; nil bills them at PriceIn
	Machine        string `json:"machine"`          // the one machine that serves it (a local model); "" for any
	Note           string `json:"note"`
	Enabled        bool   `json:"enabled"`
	Created        string `json:"created"`
	Updated        string `json:"updated"`
}

Model is a model the fleet can run, named <provider>/<model id> as a harness names it: the part before the first "/" is a Provider's name, and the model id may itself hold "/".

type Provider added in v2.0.76

type Provider struct {
	Name        string `json:"name"`
	URL         string `json:"url"`         // the API base URL requests go to
	API         string `json:"api"`         // the wire protocol it speaks: openai or anthropic
	Key         string `json:"key"`         // the name of the secret holding its API key, never the key; "" for none
	ModelsURL   string `json:"models_url"`  // where its model list is read; "" for none
	BalanceURL  string `json:"balance_url"` // where its balance is read; "" for none
	Concurrency int    `json:"concurrency"` // the most runs it takes at once; 0 is no cap
	Note        string `json:"note"`
	Enabled     bool   `json:"enabled"`
	Created     string `json:"created"`
	Updated     string `json:"updated"`
}

Provider is a model API endpoint the fleet can call.

type Row

type Row struct {
	Name             string
	F                map[string]string
	Created, Updated string
}

Row is one row as text: its name, its fields by column name, and its stamps (RFC 3339, UTC). An unset value is "".

type Service

type Service struct {
	Name      string            `json:"name"`
	Machine   string            `json:"machine"`
	Argv      []string          `json:"argv"`
	Seat      string            `json:"seat"`
	Keys      string            `json:"keys"`
	Every     int               `json:"every"`
	Keepalive bool              `json:"keepalive"`
	Enabled   bool              `json:"enabled"`
	Env       map[string]string `json:"env"`
	Log       string            `json:"log"`
	Created   string            `json:"created"`
	Updated   string            `json:"updated"`
}

Service is a program one machine keeps running, or runs every Every seconds.

type Snapshot

type Snapshot struct {
	Machines  []Machine
	Friends   []Friend
	Services  []Service
	Providers []Provider
	Models    []Model
}

Snapshot is every row of the five kinds, read at one instant.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is one open connection to the store.

func Open

func Open(ctx context.Context, dsn, password string) (*Store, error)

Open connects to the store dsn names (postgres://USER@HOST:PORT/DB, no password in it), with password when it is not empty. Every error is one line that never quotes the dsn.

func (*Store) Close

func (s *Store) Close()

Close closes the connection.

func (*Store) Conn

func (s *Store) Conn() *pgx.Conn

Conn is the connection, for nova-config's own writes.

func (*Store) Err

func (s *Store) Err(err error, op string) error

Err is a failure of op (read, add, set, remove) on the store as one line.

func (*Store) Friends

func (s *Store) Friends(ctx context.Context) ([]Friend, error)

Friends returns config.friends in name order.

Example

Read the friends nova-config keeps, as nova-config friend list does.

package main

import (
	"context"
	"fmt"
	"os"

	config "github.com/mas-bandwidth/nova-tools/v2/modules/config"
)

func main() {
	ctx := context.Background()
	st, err := config.Open(ctx, os.Getenv("NOVA_PG_DSN"), os.Getenv("NOVA_PG_PASSWORD"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}
	defer st.Close()
	friends, err := st.Friends(ctx)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}
	for _, f := range friends {
		fmt.Println(f.Name, f.Harness, f.Model)
	}
}

func (*Store) Machines

func (s *Store) Machines(ctx context.Context) ([]Machine, error)

Machines returns config.machines in name order.

func (*Store) Models added in v2.0.76

func (s *Store) Models(ctx context.Context) ([]Model, error)

Models returns config.models in name order.

func (*Store) Providers added in v2.0.76

func (s *Store) Providers(ctx context.Context) ([]Provider, error)

Providers returns config.providers in name order.

func (*Store) Rows

func (s *Store) Rows(ctx context.Context, table string, columns []string) ([]Row, error)

Rows reads the given columns of every row of config.<table>, in name order: the one query behind nova-config's list verbs and the row readers (Machines, Friends, ...).

func (*Store) Services

func (s *Store) Services(ctx context.Context) ([]Service, error)

Services returns config.services in name order.

func (*Store) Snapshot

func (s *Store) Snapshot(ctx context.Context) (Snapshot, error)

Snapshot reads Machines, Friends, Services, Providers and Models inside one read-only REPEATABLE READ transaction, so all five are from the same instant.

func (*Store) Text

func (s *Store) Text(ctx context.Context, query string, args ...any) ([][]string, error)

Text runs a query whose columns are all text and returns its rows.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL