Documentation
¶
Index ¶
- func ClearAuth() error
- func ConfigDir() (string, error)
- func GenerateDeviceID() (string, error)
- func GetAPIKey() string
- func GetAutoSyncDebounce() time.Duration
- func GetAutoSyncEnabled() bool
- func GetAutoSyncInterval() time.Duration
- func GetAutoSyncOnStart() bool
- func GetAutoSyncPull() bool
- func GetDeviceID() (string, error)
- func GetGlobalAutosyncOverride() *bool
- func GetServerURL() string
- func GetSnapshotThreshold() int
- func IsAuthenticated() bool
- func SaveAuth(creds *AuthCredentials) error
- func SaveConfig(cfg *Config) error
- func SetGlobalAutosyncOverride(v bool) error
- type AuthCredentials
- type AutoSyncConfig
- type Config
- type SyncConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateDeviceID ¶
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 ¶
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 ¶
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 ¶
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 ¶
SaveConfig writes the global config to ~/.config/td/config.json.
func SetGlobalAutosyncOverride ¶ added in v0.52.0
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 ¶
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.