app

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 60 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 app wires the backend and registered parsers.

Index

Constants

View Source
const (
	// EnabledKey is the settings key that toggles one harness. A missing row
	// means enabled; the literal value "false" disables it.
	EnabledKey = "harness.%s.enabled"
	// RootKey is the settings key that overrides one harness's scan roots.
	RootKey = "harness.%s.root"
)
View Source
const StatsTimezoneKey = "stats_timezone"

StatsTimezoneKey is the settings key holding the reporting timezone every calendar period (budget periods, day buckets, session dates) is resolved in. It is a fixed persisted setting: the app writes it once, on first use, and a snapshot worker reads the same key without ever writing it.

The value is either an IANA zone name (the fixed calendar) or absent. The legacy value "Local" is never written by this build and is not a fixed calendar: it is treated as unresolved (see EnsureStatsTimezone), because a stored "Local" would silently follow the operating system's zone on every later launch, which contradicts a persisted fixed reporting timezone.

Variables

View Source
var (
	// ErrClosed reports a scan operation on a closed app.
	ErrClosed = errors.New("app: closed")
	// ErrNoScanner reports an app with no live scanner.
	ErrNoScanner = errors.New("app: no scanner is available")
)
View Source
var ErrNoIANAZone = errors.New("mytoken: no stable IANA timezone could be identified for this machine")

ErrNoIANAZone reports that no stable IANA name could be discovered for the machine's zone. There is no silent fallback in that case: the calendar stays unconfigured until the user chooses a zone.

Functions

func DefaultStatsTimezone

func DefaultStatsTimezone() string

DefaultStatsTimezone is the most stable IANA name for the machine's current zone: an explicit TZ, else the /etc/localtime target, else /etc/timezone, else the Windows TZ key, else the name Go reports. It returns "" when none of those yields a loadable IANA name, and never invents "Local" or an offset: an offset would silently drop daylight saving, and "Local" would silently follow the OS on a later launch.

func IANAZoneName

func IANAZoneName(name string) (string, bool)

IANAZoneName reports whether name resolves to a zone with a stable name, and returns that canonical name. A bare offset ("" on some hosts, "+08:00") loses daylight saving, so it is refused, as is the legacy "Local".

func ParseStatsTimezone

func ParseStatsTimezone(name string) (*time.Location, error)

ParseStatsTimezone resolves a persisted or typed fixed zone name. Anything other than a loadable IANA name is refused: "Local" is refused on purpose, because persisting it would let the calendar silently follow the operating system. A one-invocation CLI override that wants the system zone uses ParseTimezoneOverride instead.

func ParseTimezoneOverride

func ParseTimezoneOverride(name string) (*time.Location, error)

ParseTimezoneOverride resolves an explicit one-invocation override. It is the only path that accepts the literal "Local", which means the operating system's zone for this invocation only; it is never persisted.

func SourceKey

func SourceKey(h model.Harness) string

SourceKey returns the stored key for h, or "" when none is stored. It exists for the command line, which can reveal what it stored.

func SourceKeyStatus

func SourceKeyStatus(h model.Harness) (takesKey, stored bool)

SourceKeyStatus reports whether a harness takes a database key at all and whether one is stored. It touches no index, so a read-only caller can print the answer.

Types

type App

type App struct {
	Path     string
	Store    *store.Store
	Scanner  *scan.Scanner
	Settings query.Settings
	Query    query.Service
	Resolver *attrib.Resolver
	Pricing  *pricing.Pricer
	Quota    *plan.Service
	// contains filtered or unexported fields
}

App owns the index, the scan lifecycle and the plan-quota service.

func Open

func Open() (*App, error)

Open opens the writable app and refreshes prices in the background.

func OpenLocal

func OpenLocal() (*App, error)

OpenLocal behaves like Open but never uses the network.

func (*App) CaptureSourceKey

func (a *App) CaptureSourceKey(ctx context.Context, h model.Harness, progress func(string)) error

CaptureSourceKey reads h's key out of its own application and stores it.

A key that only ever exists in memory cannot be read from disk, and asking the user to hunt for it in a debugger is not a workflow. This asks the running application instead: capture opens the application once, takes the key from its memory, proves it against the database and stores it. progress may be nil and receives a line per step for a UI that has somewhere to say it.

func (*App) CatalogInfo

func (a *App) CatalogInfo() (string, int)

CatalogInfo reports the loaded price catalog version and model count.

func (*App) Close

func (a *App) Close() error

Close stops the scanner, quota service and workers, then closes the store.

func (*App) Compact

func (a *App) Compact(ctx context.Context) error

Compact rewrites the database file, reclaiming free pages.

func (*App) CurrentScanner

func (a *App) CurrentScanner() *scan.Scanner

CurrentScanner returns the live scanner.

func (*App) CustomPrices

func (a *App) CustomPrices(ctx context.Context) ([]CustomPrice, error)

CustomPrices lists the stored per-model overrides.

func (*App) EnsureStatsTimezone

func (a *App) EnsureStatsTimezone(ctx context.Context) error

EnsureStatsTimezone loads the persisted stats timezone, discovering and writing a stable IANA name on first use. It runs on normal app startup, before anything reads a calendar period.

It never writes a value that cannot be used as a fixed calendar:

  • no stable IANA name can be discovered: nothing is written, the calendar stays unconfigured, and the GUI must ask for an explicit choice;
  • the stored value is the legacy "Local" or cannot be loaded: it is left exactly as it is (no destructive rewrite, no silent UTC or guessed offset) and reported as needing an explicit choice.

func (*App) Info

func (a *App) Info(ctx context.Context) (DBInfo, error)

Info describes the index file.

func (*App) ListSources

func (a *App) ListSources(ctx context.Context) ([]Source, error)

ListSources reports every compiled harness with its settings and usage.

func (*App) Location

func (a *App) Location() *time.Location

Location is the fixed stats timezone, or nil while the calendar is unconfigured. A caller that needs calendar boundaries must treat nil as "ask the user for a timezone", never as "use the system zone": silently following the OS is exactly the bug this setting exists to prevent.

func (*App) QuotaService

func (a *App) QuotaService() *plan.Service

QuotaService exposes the plan-quota service (nil-safe for callers).

func (*App) Rebuild

func (a *App) Rebuild(ctx context.Context) error

Rebuild empties the index and scans every enabled harness again.

func (*App) RefreshQuotas

func (a *App) RefreshQuotas(ctx context.Context)

RefreshQuotas fetches every detected plan now.

func (*App) Rescan

func (a *App) Rescan(ctx context.Context) error

Rescan rebuilds the parser set from settings and replaces the live scanner. An already-running watcher is restarted on the new set.

func (*App) ScanError

func (a *App) ScanError() error

ScanError reports why the watcher stopped on its own.

func (*App) ScannerIngestRate

func (a *App) ScannerIngestRate(now time.Time) ingestrate.Snapshot

ScannerIngestRate reports the committed output-token rate of the live scan.

func (*App) ScannerProgress

func (a *App) ScannerProgress() (done, total int)

ScannerProgress reports the current scan's completed and total sources.

func (*App) SetCustomPrices

func (a *App) SetCustomPrices(ctx context.Context, prices []CustomPrice) error

SetCustomPrices replaces the per-model overrides and reprices the index.

func (*App) SetSourceEnabled

func (a *App) SetSourceEnabled(ctx context.Context, h model.Harness, on bool) error

SetSourceEnabled toggles one harness and rebuilds the scanner.

func (*App) SetSourceKey

func (a *App) SetSourceKey(ctx context.Context, h model.Harness, key string) error

SetSourceKey stores the key a harness needs to open its sources and rebuilds the scanner. An empty key forgets it. The key is proved against the data on disk before it is stored, so a wrong key is refused here rather than turning into an empty scan later.

func (*App) SetSourceRoot

func (a *App) SetSourceRoot(ctx context.Context, h model.Harness, dir string) error

SetSourceRoot saves a root override ("" = automatic roots) after validating that the directory really holds data for this harness.

func (*App) SetTimezone

func (a *App) SetTimezone(ctx context.Context, name string) error

SetTimezone applies an explicit change: the name is validated as a fixed calendar, persisted and adopted, then the budget is asked to re-evaluate because moving the zone can move a period boundary. This is the only path that both persists and enables calendar calculations.

func (*App) SourceKeySet

func (a *App) SourceKeySet(h model.Harness) bool

SourceKeySet reports whether a harness that needs a key has one stored.

func (*App) StartScanning

func (a *App) StartScanning(ctx context.Context) error

StartScanning starts the watcher over the current scanner once.

func (*App) Timezone

func (a *App) Timezone(ctx context.Context) (string, error)

Timezone reports the effective stats timezone and any problem with it. An unconfigured calendar reports an empty name with a non-nil error, so a caller cannot mistake it for a fixed zone.

func (*App) TimezoneState

func (a *App) TimezoneState() TimezoneState

TimezoneState reports the calendar's configuration state for the GUI and the read-only metadata. It is always safe to call and never writes.

type CustomPrice

type CustomPrice struct {
	Model      string  `json:"model"`
	Input      float64 `json:"input"`
	Output     float64 `json:"output"`
	CacheRead  float64 `json:"cacheRead"`
	CacheWrite float64 `json:"cacheWrite"`
}

CustomPrice is a per-model override in USD per 1M tokens.

type DBInfo

type DBInfo struct {
	Path     string    `json:"path"`
	Bytes    int64     `json:"bytes"`
	Events   int64     `json:"events"`
	Sessions int64     `json:"sessions"`
	Oldest   time.Time `json:"oldest"`
	Newest   time.Time `json:"newest"`
}

DBInfo describes the index file and the history it holds.

type Source

type Source struct {
	Harness  model.Harness `json:"harness"`
	Detected bool          `json:"detected"`
	Enabled  bool          `json:"enabled"`
	Roots    []string      `json:"roots"`
	Override string        `json:"override"`
	Problem  string        `json:"problem"`
	// NeedsKey marks a harness whose sources are encrypted with a secret the
	// user supplies once; HasKey says whether that secret is stored already.
	NeedsKey bool      `json:"needsKey"`
	HasKey   bool      `json:"hasKey"`
	Requests int64     `json:"requests"`
	LastSeen time.Time `json:"lastSeen"`
}

Source is one harness row in the settings' data-source panel.

type StartupFailure

type StartupFailure struct {
	Title         string
	Summary       string
	DatabaseLabel string
	Database      string
	ErrorLabel    string
	Error         string
	Guidance      string
	RevealLabel   string
	QuitLabel     string
}

StartupFailure is the user-facing explanation of a fatal startup error: the app could not open its index, or a migration refused to run. The CLI prints the same cause on stderr and exits non-zero; the desktop app shows this text in a window instead of disappearing without a trace.

func DescribeStartupFailure

func DescribeStartupFailure(lang, dbPath string, cause error) StartupFailure

DescribeStartupFailure builds the message shown when the app cannot start. It is pure — language, database path and cause are all inputs — so the wording, the database path and the recovery guidance are unit-testable without a window or a running event loop.

The guidance never tells the user to delete anything: the cause is usually a full disk, a permission problem or a leftover pre-migration backup, and the data next to the database is the only copy of their history.

type TimezoneState

type TimezoneState = reporttime.TimezoneState

TimezoneState is the read side of the persisted reporting timezone. It distinguishes a fixed, user-chosen calendar from an unresolved one, so no caller has to guess whether a zone name is a real setting or the system zone standing in for a missing one. The type lives in reporttime so the GUI, the snapshot metadata and the budget gate describe the state identically.

Jump to

Keyboard shortcuts

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