Documentation
¶
Overview ¶
ABOUTME: Daemon process orchestrating fsnotify watcher, periodic reconciler, and single-writer sync loop. ABOUTME: Watches agentsview SQLite for changes and triggers sync engine with debounce and status reporting.
ABOUTME: Core sync orchestration: read-mask-write pipeline with incremental message append. ABOUTME: Composes reader, secrets, and store into an idempotent sync engine with watermark tracking.
ABOUTME: Watermark state persistence for idempotent sync. ABOUTME: Tracks which sessions have been synced via per-session hash and last ordinal.
Index ¶
- Constants
- type Daemon
- type DaemonStatus
- type Engine
- type SessionWatermark
- type SyncResult
- type SyncState
- func (s *SyncState) GetLastOrdinal(sessionID string) int
- func (s *SyncState) IsSessionChanged(sessionID, fileHash string) bool
- func (s *SyncState) MarkSynced(sessionID, fileHash string, lastOrdinal int, createdAt string)
- func (s *SyncState) NeedsFullResync(currentVersion int) bool
- func (s *SyncState) ResetForResync(newVersion int)
- func (s *SyncState) Save(path string) error
Constants ¶
const SyncVersion = 3
SyncVersion is incremented when the sync logic changes in a way that requires a full re-sync of all sessions.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon watches for agentsview SQLite changes and triggers sync.
func NewDaemon ¶
NewDaemon creates a daemon from config, initializing reader, store, and sync engine.
func NewDaemonWithDeps ¶
NewDaemonWithDeps creates a daemon using a pre-built store and reader. The caller is responsible for closing the store and reader if this returns an error.
func (*Daemon) Run ¶
Run starts the watcher, reconciler, and writer goroutines and blocks until the context is cancelled. On cancellation, the writer loop finishes its current sync cycle before returning.
func (*Daemon) Status ¶
func (d *Daemon) Status() DaemonStatus
Status returns a snapshot of the current daemon status.
type DaemonStatus ¶
type DaemonStatus struct {
LastSyncAt time.Time
TotalSessionsSynced int64
TotalSecretsDetected int64
LastError string
Running bool
}
DaemonStatus reports the current state of the daemon.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates the read-mask-write sync pipeline.
func NewEngine ¶
NewEngine creates a sync engine. It loads the watermark state from the config DataDir, or initializes empty state if no file exists.
func (*Engine) ForceResync ¶
func (e *Engine) ForceResync()
ForceResync resets the watermark state so the next RunOnce will re-sync all sessions.
type SessionWatermark ¶
type SessionWatermark struct {
FileHash string `json:"file_hash"`
LastOrdinal int `json:"last_ordinal"`
}
SessionWatermark holds the sync position for a single session.
type SyncResult ¶
type SyncResult struct {
SessionsSynced int
SessionsSkipped int
SecretsDetected int
Errors map[string]error
}
SyncResult reports what happened during a single RunOnce invocation.
type SyncState ¶
type SyncState struct {
Version int `json:"version"`
LastSessionCreatedAt string `json:"last_session_created_at"`
Sessions map[string]SessionWatermark `json:"sessions"`
LastSyncedAt time.Time `json:"last_synced_at"`
TotalSynced int64 `json:"total_synced"`
TotalMasked int64 `json:"total_masked"`
}
SyncState tracks the sync position and per-session watermarks for idempotency.
func LoadSyncState ¶
LoadSyncState reads sync state from a JSON file. Returns an empty state if the file does not exist.
func (*SyncState) GetLastOrdinal ¶
GetLastOrdinal returns the last synced ordinal for a session, or -1 if not tracked.
func (*SyncState) IsSessionChanged ¶
IsSessionChanged returns true if the session's file hash differs from the stored hash, or if the session has not been tracked. Used to detect sessions that need re-syncing.
func (*SyncState) MarkSynced ¶
MarkSynced records a session as synced with its file hash and last ordinal, and advances the watermark if createdAt is later than the current position.
func (*SyncState) NeedsFullResync ¶
NeedsFullResync returns true if the stored version is older than currentVersion, indicating all sessions must be re-synced from scratch.
func (*SyncState) ResetForResync ¶
ResetForResync clears all session watermarks and sets the new version, forcing a full re-sync on the next sync run.