daemon

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSyncInterval is the base interval for syncing files
	DefaultSyncInterval = 30 * time.Second
)

Variables

This section is empty.

Functions

func GetInboxPath

func GetInboxPath(externalID string) (string, error)

GetInboxPath returns the path to the event inbox file for a given external ID

func GetStatePath

func GetStatePath(externalID string) (string, error)

GetStatePath returns the path to the state file for a given external ID

func GetSyncDir

func GetSyncDir() (string, error)

GetSyncDir returns the path to the sync state directory

func StopDaemon

func StopDaemon(externalID string, hookInput *types.HookInput) error

StopDaemon sends SIGTERM to a running daemon by external ID. If hookInput is provided, it writes a session_end event to the daemon's inbox before signaling, so the daemon can access the full SessionEnd payload.

Types

type Config

type Config struct {
	ExternalID         string
	TranscriptPath     string
	CWD                string
	ParentPID          int // Claude Code process ID to monitor (0 to disable)
	SyncInterval       time.Duration
	SyncIntervalJitter time.Duration // 0 to disable jitter (for testing)
}

Config holds daemon configuration

type Daemon

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

Daemon is the background sync process.

The daemon is resilient to backend unavailability - it will keep running and retry connecting to the backend on each sync interval. Once connected, it will sync any accumulated changes.

If ParentPID is set, the daemon monitors the parent process and shuts down gracefully when it exits. This handles cases where Claude Code crashes or is killed without firing the SessionEnd hook.

func New

func New(cfg Config) *Daemon

New creates a new daemon instance

func (*Daemon) Run

func (d *Daemon) Run(ctx context.Context) error

Run starts the daemon and blocks until stopped

func (*Daemon) Stop

func (d *Daemon) Stop()

Stop signals the daemon to stop. Safe to call multiple times.

type State

type State struct {
	ExternalID      string    `json:"external_id"`
	TranscriptPath  string    `json:"transcript_path"`
	CWD             string    `json:"cwd"`
	PID             int       `json:"pid"`
	ParentPID       int       `json:"parent_pid,omitempty"` // Claude Code process ID
	InboxPath       string    `json:"inbox_path"`           // Path to event inbox (JSONL)
	StartedAt       time.Time `json:"started_at"`
	ConfabSessionID string    `json:"confab_session_id,omitempty"` // Backend session ID (set after Init)
}

State represents the daemon's persistent state

func ListAllStates

func ListAllStates() ([]*State, error)

ListAllStates returns all active sync states

func LoadState

func LoadState(externalID string) (*State, error)

LoadState reads the state from disk for a given external ID Returns nil if the state file doesn't exist

func NewState

func NewState(externalID, transcriptPath, cwd string, parentPID int) *State

NewState creates a new daemon state. parentPID is the Claude Code process ID to monitor (0 to disable monitoring).

func (*State) Delete

func (s *State) Delete() error

Delete removes the state file from disk

func (*State) IsDaemonRunning

func (s *State) IsDaemonRunning() bool

IsDaemonRunning checks if the daemon process is still alive

func (*State) IsParentRunning

func (s *State) IsParentRunning() bool

IsParentRunning checks if the parent Claude Code process is still alive

func (*State) Save

func (s *State) Save() error

Save writes the state to disk

Jump to

Keyboard shortcuts

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