syncconfig

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 9 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearAuth

func ClearAuth() error

ClearAuth removes the auth.json file.

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns ~/.config/td, creating it if necessary.

func GenerateDeviceID

func GenerateDeviceID() (string, error)

GenerateDeviceID creates a new random device ID (16 bytes hex).

func GetAPIKey

func GetAPIKey() string

GetAPIKey returns the API key. Priority: TD_AUTH_KEY env > auth.json.

func GetAutoSyncDebounce

func GetAutoSyncDebounce() time.Duration

GetAutoSyncDebounce returns the debounce duration for post-mutation sync. Priority: TD_SYNC_AUTO_DEBOUNCE env > config.json sync.auto.debounce > 3s

func GetAutoSyncEnabled

func GetAutoSyncEnabled() bool

GetAutoSyncEnabled returns whether auto-sync is enabled. Priority: TD_SYNC_AUTO env > config.json sync.auto.enabled > true

func GetAutoSyncInterval

func GetAutoSyncInterval() time.Duration

GetAutoSyncInterval returns the periodic sync interval. Priority: TD_SYNC_AUTO_INTERVAL env > config.json sync.auto.interval > 5m

func GetAutoSyncOnStart

func GetAutoSyncOnStart() bool

GetAutoSyncOnStart returns whether to sync on startup. Priority: TD_SYNC_AUTO_START env > config.json sync.auto.on_start > true

func GetAutoSyncPull

func GetAutoSyncPull() bool

GetAutoSyncPull returns whether auto-sync should include pull. Priority: TD_SYNC_AUTO_PULL env > config.json sync.auto.pull > true

func GetDeviceID

func GetDeviceID() (string, error)

GetDeviceID returns the device ID from auth.json, generating one if needed.

func GetGlobalAutosyncOverride added in v0.52.0

func GetGlobalAutosyncOverride() *bool

GetGlobalAutosyncOverride returns the tri-state global autosync master switch (td-735875).

nil   = no global override set (per-project / feature config decides)
false = global kill-switch engaged (autosync suppressed everywhere)
true  = global kill cleared (per-project still decides)

Precedence: env (TD_FEATURE_SYNC_AUTOSYNC, then TD_SYNC_AUTO) > config.json sync.autosync > nil. The legacy sync.enabled field is intentionally NOT consulted here so a stale "enabled": false never silently kills sync.

func GetServerURL

func GetServerURL() string

GetServerURL returns the sync server URL. Priority: TD_SYNC_URL env > config.json > default.

func GetSnapshotThreshold

func GetSnapshotThreshold() int

GetSnapshotThreshold returns the snapshot bootstrap threshold (min server events). Priority: TD_SYNC_SNAPSHOT_THRESHOLD env > config.json > default (100).

func IsAuthenticated

func IsAuthenticated() bool

IsAuthenticated returns true if an API key is available.

func SaveAuth

func SaveAuth(creds *AuthCredentials) error

SaveAuth writes auth credentials to ~/.config/td/auth.json (0600 perms).

func SaveConfig

func SaveConfig(cfg *Config) error

SaveConfig writes the global config to ~/.config/td/config.json.

func SetGlobalAutosyncOverride added in v0.52.0

func SetGlobalAutosyncOverride(v bool) error

SetGlobalAutosyncOverride persists the global autosync master switch into ~/.config/td/config.json (sync.autosync). Passing a non-nil bool sets the explicit allow/kill value; the legacy sync.enabled field is left untouched.

Types

type AuthCredentials

type AuthCredentials struct {
	APIKey    string `json:"api_key"`
	UserID    string `json:"user_id"`
	Email     string `json:"email"`
	ServerURL string `json:"server_url"`
	DeviceID  string `json:"device_id"`
	ExpiresAt string `json:"expires_at"`
}

AuthCredentials stores authentication state at ~/.config/td/auth.json.

func LoadAuth

func LoadAuth() (*AuthCredentials, error)

LoadAuth reads auth credentials from ~/.config/td/auth.json.

type AutoSyncConfig

type AutoSyncConfig struct {
	Enabled  *bool  `json:"enabled,omitempty"`  // nil = default true
	OnStart  *bool  `json:"on_start,omitempty"` // nil = default true
	Debounce string `json:"debounce,omitempty"` // duration string, default "3s"
	Interval string `json:"interval,omitempty"` // duration string, default "5m"
	Pull     *bool  `json:"pull,omitempty"`     // nil = default true
}

AutoSyncConfig holds auto-sync settings.

type Config

type Config struct {
	Sync SyncConfig `json:"sync"`
}

Config is the global td config stored at ~/.config/td/config.json.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig reads the global config from ~/.config/td/config.json.

type SyncConfig

type SyncConfig struct {
	URL string `json:"url"`
	// Enabled is a LEGACY field. It is intentionally left untouched by the
	// global kill-switch logic: the live production config historically carries
	// "enabled": false while the user actually wants sync on, so a bare legacy
	// false must NOT silently kill sync everywhere. Use Autosync for the global
	// master switch instead (td-735875).
	Enabled bool `json:"enabled"`
	// Autosync is the tri-state GLOBAL autosync master switch (td-735875).
	//   nil   = absent  -> per-project / feature config decides (no global override)
	//   false = kill-all -> global kill-switch engaged, autosync suppressed everywhere
	//   true  = allow    -> removes the global kill (per-project still decides)
	// It is read by every td process via GetGlobalAutosyncOverride, so it works
	// regardless of shell-init semantics (unlike TD_* env vars).
	Autosync          *bool          `json:"autosync,omitempty"`
	SnapshotThreshold *int           `json:"snapshot_threshold,omitempty"`
	Auto              AutoSyncConfig `json:"auto"`
}

SyncConfig holds sync-related settings.

Jump to

Keyboard shortcuts

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