daemon

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package daemon owns CodeGrapher's single-user background freshness process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(parent context.Context, projectPath, stateDir, nonce, token, browserToken string) error

Run owns the lifetime lock, control endpoint, and shared freshness owner.

func RunFromEnvironment

func RunFromEnvironment(ctx context.Context, projectPath string) error

RunFromEnvironment runs the internal daemon child. It is intentionally environment-authenticated and should only be called by the hidden CLI verb.

Types

type Health

type Health struct {
	Live                  bool      `json:"live"`
	WatchReady            bool      `json:"watchReady"`
	IndexCurrent          bool      `json:"indexCurrent"`
	PendingDirtyPaths     int       `json:"pendingDirtyPaths"`
	WholeTreeDirty        bool      `json:"wholeTreeDirty"`
	AcceptedGeneration    uint64    `json:"acceptedGeneration"`
	CompletedGeneration   uint64    `json:"completedGeneration"`
	LastSuccessfulUpdate  time.Time `json:"lastSuccessfulUpdate,omitempty"`
	LastReconciliation    time.Time `json:"lastReconciliation,omitempty"`
	LastOperationDuration string    `json:"lastOperationDuration,omitempty"`
	LastError             string    `json:"lastError,omitempty"`
}

Health separates process liveness, native watch coverage, and graph currency.

type Lifecycle

type Lifecycle string

Lifecycle is the durable daemon state machine.

const (
	LifecycleStarting Lifecycle = "starting"
	LifecycleReady    Lifecycle = "ready"
	LifecycleDegraded Lifecycle = "degraded"
	LifecycleStopping Lifecycle = "stopping"
	LifecycleStopped  Lifecycle = "stopped"
	LifecycleFailed   Lifecycle = "failed"
)

type Manager

type Manager struct {
	StateDir     string
	Executable   string
	HTTPClient   *http.Client
	StartTimeout time.Duration
}

Manager coordinates the one daemon owned by the current user.

func NewManager

func NewManager() (*Manager, error)

NewManager resolves default process and state locations.

func (m *Manager) BrowserLink(ctx context.Context) (string, error)

BrowserLink returns the fragment-secret URL intended for the local user. Neither control status nor the public API contains this secret.

func (*Manager) Restart

func (m *Manager) Restart(ctx context.Context, projectPath string) (Status, error)

Restart stops the current owner and starts projectPath. An empty path reuses the current daemon's project.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, projectPath string) (Status, error)

Start launches the daemon and waits for watch coverage, startup sync, and the startup generation barrier. A live daemon for the same path is idempotent.

func (*Manager) Status

func (m *Manager) Status(ctx context.Context) (Status, error)

Status authenticates the persisted endpoint before reporting a live owner.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) (Status, error)

Stop requests authenticated graceful shutdown. It never signals a PID.

type Status

type Status struct {
	SchemaVersion     int       `json:"schemaVersion"`
	ControlAPIVersion int       `json:"controlApiVersion"`
	Lifecycle         Lifecycle `json:"lifecycle"`
	PID               int       `json:"pid,omitempty"`
	ProjectPath       string    `json:"projectPath,omitempty"`
	Endpoint          string    `json:"endpoint,omitempty"`
	BrowserEndpoint   string    `json:"browserEndpoint,omitempty"`
	StartedAt         time.Time `json:"startedAt,omitempty"`
	ReadyAt           time.Time `json:"readyAt,omitempty"`
	StoppedAt         time.Time `json:"stoppedAt,omitempty"`
	LogPath           string    `json:"logPath,omitempty"`
	Health            Health    `json:"health"`
}

Status is safe to print or encode: lifecycle credentials are never exposed.

Jump to

Keyboard shortcuts

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