watchd

package
v0.7.164 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package watchd implements the chunk watch background daemon and its client.

Index

Constants

View Source
const (
	// PollInterval is how often the daemon refreshes project state from disk.
	PollInterval = 5 * time.Second
	// RecentEvents is the maximum number of events kept per project.
	RecentEvents = 300
	// RunningTimeout is how long after the last non-terminal event a sidecar is
	// considered to still be running.
	RunningTimeout = 5 * time.Minute
)

Variables

This section is empty.

Functions

func BuildID added in v0.7.164

func BuildID() string

BuildID identifies the binary a process was started from.

The daemon serves snapshots shaped by the code it was started from: a field added to SidecarState since then is absent rather than wrong, so a newer client renders a well-formed view of stale data with nothing to say why. A sidecar owned by a session, for instance, arrives from a pre-session daemon looking like a sidecar nobody owns. Comparing this on every ping is what makes that visible instead of silent.

The version alone will not do: every local build reports the same development version, so the executable's path, size and modification time come along to tell two of them apart. Path is included so a dev build and an installed one are never mistaken for each other.

func EnsureDir

func EnsureDir() (string, error)

EnsureDir creates ~/.chunk/watchd/ if it doesn't exist and returns the path.

func EnsureLaunched added in v0.7.164

func EnsureLaunched(subArgs []string) error

EnsureLaunched starts the daemon when nothing is answering and otherwise leaves whatever is there alone.

Unlike EnsureRunning it never replaces a daemon from another build. It is called when a poll fails mid-session, and a dashboard that has been open for a while has no business restarting a daemon another one is using: the build check is a startup decision, made once, where the cost of being wrong is one restart rather than a restart per poll for as long as two dashboards are open.

func EnsureRunning

func EnsureRunning(subArgs []string) error

EnsureRunning checks whether the watch daemon is running and serving, and launches it if not. subArgs are the CLI arguments used to invoke the daemon (e.g. ["watch", "_daemon"]).

func IsRunning

func IsRunning(path string) (bool, int, error)

IsRunning reports whether the process whose PID is stored in path is alive. Returns (false, 0, nil) when the file doesn't exist.

func LogPath

func LogPath() (string, error)

LogPath returns the path to the daemon log file.

func PIDPath

func PIDPath() (string, error)

PIDPath returns the path to the daemon PID file.

func RunDaemon

func RunDaemon(ctx context.Context) error

RunDaemon is the watch daemon entry point, called by the hidden _daemon subcommand.

func SocketPath

func SocketPath() (string, error)

SocketPath returns the path to the daemon Unix socket.

Types

type ProjectSnapshot

type ProjectSnapshot struct {
	Root     string           `json:"root"`
	Branch   string           `json:"branch"`
	HeadRef  string           `json:"head_ref"`
	RepoName string           `json:"repo_name"`
	Sidecars []SidecarState   `json:"sidecars"`
	Events   []eventlog.Event `json:"events"`
}

ProjectSnapshot is the daemon's view of one project at a point in time.

type SidecarState

type SidecarState struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	// SessionID is the agent session that owns this sidecar, empty for state
	// written outside a session or before sessions existed. Sidecars are
	// isolated per session, so two entries for one project and branch are two
	// sessions working in the same tree — this is what tells them apart.
	SessionID     string      `json:"session_id,omitempty"`
	ProjectName   string      `json:"project_name"`
	RepoName      string      `json:"repo_name"`
	SnapshotName  string      `json:"snapshot_name"`
	FileMtime     time.Time   `json:"file_mtime"`
	LastSyncedRef string      `json:"last_synced_ref"`
	InSync        bool        `json:"in_sync"`
	LastActivity  time.Time   `json:"last_activity"`
	LastOp        eventlog.Op `json:"last_op"`
	LastLevel     string      `json:"last_level"`
	Running       bool        `json:"running"`
}

SidecarState describes one active sidecar as maintained by the daemon.

type Snapshot

type Snapshot struct {
	Projects []ProjectSnapshot `json:"projects"`
}

Snapshot is a point-in-time view of all watched projects.

func FetchSnapshot

func FetchSnapshot(roots []string) (Snapshot, error)

FetchSnapshot connects to the running watch daemon and returns the current snapshot for the given project roots. If roots is empty all known projects are returned.

Jump to

Keyboard shortcuts

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