Documentation
¶
Overview ¶
Package app wires the backend and registered parsers.
Index ¶
- Constants
- Variables
- func DefaultStatsTimezone() string
- func IANAZoneName(name string) (string, bool)
- func ParseStatsTimezone(name string) (*time.Location, error)
- func ParseTimezoneOverride(name string) (*time.Location, error)
- func SourceKey(h model.Harness) string
- func SourceKeyStatus(h model.Harness) (takesKey, stored bool)
- type App
- func (a *App) CaptureSourceKey(ctx context.Context, h model.Harness, progress func(string)) error
- func (a *App) CatalogInfo() (string, int)
- func (a *App) Close() error
- func (a *App) Compact(ctx context.Context) error
- func (a *App) CurrentScanner() *scan.Scanner
- func (a *App) CustomPrices(ctx context.Context) ([]CustomPrice, error)
- func (a *App) EnsureStatsTimezone(ctx context.Context) error
- func (a *App) Info(ctx context.Context) (DBInfo, error)
- func (a *App) ListSources(ctx context.Context) ([]Source, error)
- func (a *App) Location() *time.Location
- func (a *App) QuotaService() *plan.Service
- func (a *App) Rebuild(ctx context.Context) error
- func (a *App) RefreshQuotas(ctx context.Context)
- func (a *App) Rescan(ctx context.Context) error
- func (a *App) ScanError() error
- func (a *App) ScannerIngestRate(now time.Time) ingestrate.Snapshot
- func (a *App) ScannerProgress() (done, total int)
- func (a *App) SetCustomPrices(ctx context.Context, prices []CustomPrice) error
- func (a *App) SetSourceEnabled(ctx context.Context, h model.Harness, on bool) error
- func (a *App) SetSourceKey(ctx context.Context, h model.Harness, key string) error
- func (a *App) SetSourceRoot(ctx context.Context, h model.Harness, dir string) error
- func (a *App) SetTimezone(ctx context.Context, name string) error
- func (a *App) SourceKeySet(h model.Harness) bool
- func (a *App) StartScanning(ctx context.Context) error
- func (a *App) Timezone(ctx context.Context) (string, error)
- func (a *App) TimezoneState() TimezoneState
- type CustomPrice
- type DBInfo
- type Source
- type StartupFailure
- type TimezoneState
Constants ¶
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" )
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 ¶
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") )
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 (*App) CaptureSourceKey ¶
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 ¶
CatalogInfo reports the loaded price catalog version and model count.
func (*App) CurrentScanner ¶
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 ¶
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) ListSources ¶
ListSources reports every compiled harness with its settings and usage.
func (*App) 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 ¶
QuotaService exposes the plan-quota service (nil-safe for callers).
func (*App) RefreshQuotas ¶
RefreshQuotas fetches every detected plan now.
func (*App) Rescan ¶
Rescan rebuilds the parser set from settings and replaces the live scanner. An already-running watcher is restarted on the new set.
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 ¶
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 ¶
SetSourceEnabled toggles one harness and rebuilds the scanner.
func (*App) SetSourceKey ¶
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 ¶
SetSourceRoot saves a root override ("" = automatic roots) after validating that the directory really holds data for this harness.
func (*App) SetTimezone ¶
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 ¶
SourceKeySet reports whether a harness that needs a key has one stored.
func (*App) StartScanning ¶
StartScanning starts the watcher over the current scanner once.
func (*App) Timezone ¶
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.