config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 10 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 config defines the on-disk JSON configuration for vigil, along with defaults, validation and atomic load/save helpers.

Index

Constants

View Source
const CurrentVersion = 1

CurrentVersion is the config schema version written by this build. It allows future migrations to detect and upgrade older files.

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir(scope Scope) (string, error)

ConfigDir returns the directory that holds config.json for the given scope.

User scope follows the XDG convention on every OS (including macOS, where we deliberately use ~/.config rather than ~/Library/Application Support so the location is predictable and easy to find):

  • $XDG_CONFIG_HOME/vigil if set
  • Windows: %AppData%\vigil
  • otherwise: ~/.config/vigil

func ConfigPath

func ConfigPath(scope Scope) (string, error)

ConfigPath returns the absolute path to config.json for the given scope.

func ParseISODuration

func ParseISODuration(s string) (time.Duration, error)

ParseISODuration parses the subset of ISO-8601 durations used by Microsoft Graph (days, hours, minutes, seconds — e.g. "PT8H", "P1DT2H30M"). Week, month and year designators are rejected because they are ambiguous as fixed durations.

func RuntimeDir

func RuntimeDir(scope Scope) (string, error)

RuntimeDir returns the directory used for mutable runtime artifacts: status.json, override.json, the single-instance lock, logs and the Graph token cache.

For user scope these live under the XDG state dir so an unprivileged CLI can always write the override file that the daemon watches:

  • $XDG_STATE_HOME/vigil if set
  • Windows: %LocalAppData%\vigil
  • otherwise: ~/.local/state/vigil

For system scope they live alongside the system config (writable only by the service account / root) — see docs/configuration.md for the multi-user caveat.

func SettableKeys

func SettableKeys() []string

SettableKeys returns the sorted list of supported dotted keys.

func TokenPath

func TokenPath(scope Scope) (string, error)

TokenPath returns the absolute path to the Graph token cache.

Types

type Clock

type Clock int

Clock is a wall-clock time of day expressed as minutes since midnight, in the range [0,1440).

func ParseClock

func ParseClock(s string) (Clock, error)

ParseClock parses an "HH:MM" 24-hour string into a Clock.

func (Clock) Minutes

func (c Clock) Minutes() int

Minutes returns the clock value as minutes since midnight.

func (Clock) String

func (c Clock) String() string

String renders the clock as "HH:MM".

type Config

type Config struct {
	Version  int            `json:"version"`
	Engine   Engine         `json:"engine"`
	Timezone string         `json:"timezone"`
	Schedule ScheduleConfig `json:"schedule"`
	Input    InputConfig    `json:"input"`
	Graph    GraphConfig    `json:"graph"`
	Control  ControlConfig  `json:"control"`
	Log      LogConfig      `json:"log"`
}

Config is the root configuration object persisted as config.json.

func Default

func Default() Config

Default returns a Config populated with sensible defaults (Mon–Fri 08:00–17:00, synthetic-input engine).

func Load

func Load(path string) (Config, error)

Load reads and validates the config at path. A missing file is reported via os.IsNotExist on the returned error so callers can offer `config init`.

func (Config) GetField

func (c Config) GetField(key string) (string, error)

GetField returns the string value of a dotted key.

func (Config) Location

func (c Config) Location() (*time.Location, error)

Location resolves the configured timezone. "Local" and "" map to time.Local.

func (Config) Save

func (c Config) Save(path string) error

Save atomically writes c to path (temp file + rename), creating parent dirs.

func (*Config) SetField

func (c *Config) SetField(key, value string) error

SetField sets a dotted key from a string and re-validates the whole config. On validation failure the config is left unchanged.

func (Config) UsesGraph

func (c Config) UsesGraph() bool

UsesGraph reports whether the configured engine runs the Graph strategy.

func (Config) UsesInput

func (c Config) UsesInput() bool

UsesInput reports whether the configured engine runs the input strategy.

func (Config) Validate

func (c Config) Validate() error

Validate checks the config for internal consistency and returns the first problem found.

type ControlConfig

type ControlConfig struct {
	Port int `json:"port"`
}

ControlConfig configures the control plane. Port 0 means file-based control.

type Engine

type Engine string

Engine selects which activation strategy (or strategies) the daemon runs.

const (
	// EngineInput keeps the session active with synthetic input (default).
	EngineInput Engine = "input"
	// EngineGraph sets a sticky presence via Microsoft Graph.
	EngineGraph Engine = "graph"
	// EngineBoth runs the input and graph strategies together.
	EngineBoth Engine = "both"
)

type GraphConfig

type GraphConfig struct {
	TenantID       string `json:"tenant_id"`
	ClientID       string `json:"client_id"`
	Availability   string `json:"availability"`
	Activity       string `json:"activity"`
	Expiration     string `json:"expiration"` // ISO-8601 duration, e.g. "PT8H"
	RefreshMinutes int    `json:"refresh_minutes"`
}

GraphConfig holds Microsoft Graph engine settings.

type InputConfig

type InputConfig struct {
	IntervalSeconds int         `json:"interval_seconds"`
	JitterSeconds   int         `json:"jitter_seconds"`
	Method          InputMethod `json:"method"`
	PreventSleep    bool        `json:"prevent_sleep"`
	// MovePixels is the maximum magnitude (px) of the mouse nudge; each tick
	// uses a random 1..MovePixels offset and returns to origin.
	MovePixels int `json:"move_pixels"`
}

InputConfig tunes the synthetic-input engine.

type InputMethod

type InputMethod string

InputMethod selects how synthetic input is generated.

const (
	// MethodMouse performs a small real relative mouse move (default, reliable).
	MethodMouse InputMethod = "mouse"
	// MethodKey presses a benign key (F15) that has no side effects.
	MethodKey InputMethod = "key"
	// MethodZen requests an invisible/zero-delta nudge. May be ignored by apps
	// that implement their own idle detection — opt-in only.
	MethodZen InputMethod = "zen"
)

type LogConfig

type LogConfig struct {
	Level      string `json:"level"`
	MaxSizeMB  int    `json:"max_size_mb"`
	MaxBackups int    `json:"max_backups"`
}

LogConfig configures the rotating log file.

type ScheduleConfig

type ScheduleConfig struct {
	// Enabled turns schedule evaluation on. When false the daemon stays idle
	// unless a manual override forces it active.
	Enabled bool `json:"enabled"`
	// Always keeps the daemon active whenever it runs, ignoring Windows.
	Always bool `json:"always"`
	// Windows are the active periods, evaluated in Config.Timezone.
	Windows []Window `json:"windows"`
}

ScheduleConfig describes when the daemon should keep Teams active.

type Scope

type Scope string

Scope determines whether files are resolved against per-user or system-wide (all users) locations.

const (
	// ScopeUser resolves paths under the current user's config/cache dirs.
	ScopeUser Scope = "user"
	// ScopeSystem resolves paths under OS-wide machine locations.
	ScopeSystem Scope = "system"
)

func (Scope) Valid

func (s Scope) Valid() bool

Valid reports whether s is a recognised scope.

type Window

type Window struct {
	Days  []string `json:"days"`  // e.g. ["Mon","Tue",...]; "Mon".."Sun"
	Start string   `json:"start"` // "HH:MM"
	End   string   `json:"end"`   // "HH:MM"
}

Window is a recurring weekly active period. Start/End are "HH:MM" 24h local times; an End that is not after Start denotes an overnight window.

Jump to

Keyboard shortcuts

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