cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0 modules, 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 cli holds the daemon's command implementations.

Index

Constants

View Source
const (
	StateOK        = "ok"
	StateBacklog   = "backlog"
	StateBlocked   = "blocked"
	StateOffline   = "offline"
	StateLoggedOut = "logged_out"
)

Sync states of StatsSync.State.

View Source
const StatsTTL = 30 * time.Second

StatsTTL is how long a fetched answer is reused.

View Source
const StatsVersion = 1

StatsVersion is the version of the `braid stats --json` contract (band/stats.schema.json).

Variables

View Source
var ErrLocked = errors.New("another braid process is syncing")

ErrLocked is returned by AcquireLock when another process holds the lock.

Functions

func AcquireLock

func AcquireLock(dataDir string) (release func(), err error)

AcquireLock takes <data>/braid.lock non-blocking; returns ErrLocked if held.

func Run

func Run(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) int

Run dispatches subcommands; returns the process exit code.

func RunWithHooks

func RunWithHooks(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer, h Hooks) int

RunWithHooks is Run with test hooks.

Types

type Hooks

type Hooks struct {
	NoKeychain bool             // keychain Set fails with auth.ErrNoKeychain
	FakeToken  string           // skip the device flow and use this token
	ConfigDir  string           // overrides the config dir
	DataDir    string           // overrides the data dir
	Now        func() time.Time // nil means time.Now
}

Hooks override environment lookups. Only meant for tests; Run uses the zero value.

type Runner

type Runner struct {
	Engine  *syncer.Engine
	Trigger <-chan struct{}
	Backoff client.Backoff
	Log     *slog.Logger
	Sleep   func(ctx context.Context, d time.Duration) error // default: timer with ctx
	// contains filtered or unexported fields
}

Runner drives sync passes from triggers.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run loops: on trigger it runs a pass, retrying retryable errors with backoff. Unauthorized, protocol and permanent errors are logged; the loop keeps waiting for triggers (the spool keeps the data). Returns nil when ctx ends.

type StatsLimit

type StatsLimit struct {
	Type     string `json:"type"`
	ResetsAt string `json:"resets_at"` // RFC 3339 UTC
}

StatsLimit is the active usage limit.

type StatsOut

type StatsOut struct {
	Version int           `json:"version"`
	Sync    StatsSync     `json:"sync"`
	Today   StatsToday    `json:"today"`
	Session *StatsSession `json:"session,omitempty"`
	Limit   *StatsLimit   `json:"limit,omitempty"`
}

StatsOut is the output of `braid stats --json`.

type StatsSession

type StatsSession struct {
	CostUSD  float64 `json:"cost_usd"`
	Tokens   int64   `json:"tokens"`
	Failures int64   `json:"failures"`
}

StatsSession is the figures of the requested session.

type StatsSync

type StatsSync struct {
	State        string `json:"state"`
	BacklogBytes int64  `json:"backlog_bytes"`
	LastAck      string `json:"last_ack,omitempty"` // RFC 3339 UTC, omitted if never
}

StatsSync is the local sync state.

type StatsToday

type StatsToday struct {
	CostUSD    float64 `json:"cost_usd"`
	Tokens     int64   `json:"tokens"`
	Sessions   int64   `json:"sessions"`
	AgentTimeS int64   `json:"agent_time_s"`
	Failures   int64   `json:"failures"`
}

StatsToday is today's figures across devices.

Jump to

Keyboard shortcuts

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