watch

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureWatcherService

func EnsureWatcherService(homeDir, binPath string) error

EnsureWatcherService checks if the watcher service should be installed or removed based on whether any project has precise mode enabled. binPath is the path to the hourgit binary.

func IsDaemonRunning

func IsDaemonRunning(homeDir string) (bool, int, error)

IsDaemonRunning checks if the daemon is running by reading the PID file and verifying the process is alive.

func IsProcessAlive

func IsProcessAlive(pid int) bool

IsProcessAlive checks if a process with the given PID is running.

func LoadGitignorePatterns

func LoadGitignorePatterns(repoDir string) []string

LoadGitignorePatterns reads .gitignore from the repo root and returns patterns.

func PIDPath

func PIDPath(homeDir string) string

PIDPath returns the path to the PID file.

func ReadPID

func ReadPID(homeDir string) (int, error)

ReadPID reads the PID from the PID file. Returns 0 if the file doesn't exist.

func RemovePID

func RemovePID(homeDir string) error

RemovePID removes the PID file.

func RemoveState

func RemoveState(homeDir string) error

RemoveState removes the state file.

func ServiceFileContent

func ServiceFileContent(binPath string) string

ServiceFileContent generates the systemd service unit content.

func ShouldIgnore

func ShouldIgnore(repoDir, filePath string) bool

ShouldIgnore checks if a file path should be ignored based on the repo's .gitignore patterns and built-in exclusions. Reads .gitignore from disk on each call — use ShouldIgnoreWithPatterns for the hot path.

func ShouldIgnoreWithPatterns

func ShouldIgnoreWithPatterns(repoDir, filePath string, patterns []string) bool

ShouldIgnoreWithPatterns checks if a file path should be ignored using pre-loaded gitignore patterns. Use this on the hot path to avoid re-reading .gitignore from disk on every event.

func StatePath

func StatePath(homeDir string) string

StatePath returns the path to the state file.

func WritePID

func WritePID(homeDir string) error

WritePID writes the current process PID to the PID file.

Types

type Daemon

type Daemon struct {
	// contains filtered or unexported fields
}

Daemon is the central background watcher that monitors repos with precise mode.

func NewDaemon

func NewDaemon(homeDir string, writer EntryWriter) *Daemon

NewDaemon creates a new daemon instance.

func (*Daemon) Run

func (d *Daemon) Run() error

Run starts the daemon, loads config, sets up watchers, and blocks until stopped.

func (*Daemon) Stop

func (d *Daemon) Stop()

Stop signals the daemon to stop.

type DaemonConfig

type DaemonConfig struct {
	Repo      string
	Slug      string
	Threshold time.Duration
}

DaemonConfig holds the daemon's runtime configuration for a single repo.

type EntryWriter

type EntryWriter interface {
	WriteActivityStop(homeDir, slug string, e entry.ActivityStopEntry) error
	WriteActivityStart(homeDir, slug string, e entry.ActivityStartEntry) error
}

EntryWriter abstracts entry writing for testability.

func DefaultEntryWriter

func DefaultEntryWriter() EntryWriter

DefaultEntryWriter returns the real entry writer.

type RepoDebouncer

type RepoDebouncer struct {
	// contains filtered or unexported fields
}

RepoDebouncer manages the debounce state machine for a single repo.

func NewRepoDebouncer

func NewRepoDebouncer(repo, slug, homeDir string, threshold time.Duration, writer EntryWriter, state *WatchState) *RepoDebouncer

NewRepoDebouncer creates a debouncer for a single repo.

func (*RepoDebouncer) IsIdle

func (d *RepoDebouncer) IsIdle() bool

IsIdle returns whether the debouncer is in idle state.

func (*RepoDebouncer) LastActivity

func (d *RepoDebouncer) LastActivity() time.Time

LastActivity returns the last observed file change time.

func (*RepoDebouncer) OnFileEvent

func (d *RepoDebouncer) OnFileEvent(now time.Time)

OnFileEvent is called when a file change is detected in the repo.

func (*RepoDebouncer) Shutdown

func (d *RepoDebouncer) Shutdown()

Shutdown writes activity_stop if currently active and stops the timer.

type RepoState

type RepoState struct {
	LastActivity time.Time `json:"last_activity"`
}

RepoState holds the last activity time for a single repo.

type ServiceManager

type ServiceManager interface {
	Install(binPath string) error
	Remove() error
	Start() error
	Stop() error
	IsInstalled() bool
	IsRunning() bool
}

ServiceManager manages the daemon as an OS service.

func NewServiceManager

func NewServiceManager(homeDir string) (ServiceManager, error)

NewServiceManager returns the Linux (systemd) service manager.

type WatchState

type WatchState struct {
	Repos map[string]RepoState `json:"repos"`
	// contains filtered or unexported fields
}

WatchState holds the daemon's state, flushed periodically to disk.

func LoadWatchState

func LoadWatchState(homeDir string) (*WatchState, error)

LoadWatchState reads the state from disk. Returns a new empty state if the file doesn't exist.

func NewWatchState

func NewWatchState() *WatchState

NewWatchState creates a new empty WatchState.

func (*WatchState) Flush

func (s *WatchState) Flush(homeDir string) error

Flush writes the state to disk.

func (*WatchState) GetLastActivity

func (s *WatchState) GetLastActivity(repo string) (time.Time, bool)

GetLastActivity returns the last activity time for a repo.

func (*WatchState) RemoveRepo

func (s *WatchState) RemoveRepo(repo string)

RemoveRepo removes a repo from the state.

func (*WatchState) SetLastActivity

func (s *WatchState) SetLastActivity(repo string, t time.Time)

SetLastActivity updates the last activity time for a repo.

Jump to

Keyboard shortcuts

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