daemon

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 49 Imported by: 0

Documentation

Overview

Package daemon holds vev's server-side session multiplexer use case.

Lock ordering: never acquire sendMu or session/daemon locks while holding a pane lock. Coordinator callbacks and timer methods run without coordinator.mu; see the lock-specific comments on attachedClient and renderCoordinator.

Package daemon holds vev's server-side session multiplexer use case: the accept loop, the ephemeral/named session registry, the per-tab PTY reader and VT screen, and the per-client debounced render coordinator.

Package daemon holds vev's server-side session multiplexer use case.

Package daemon holds vev's server-side session multiplexer use case.

Package daemon holds vev's server-side session multiplexer use case.

Package daemon holds vev's server-side session multiplexer use case.

Package daemon holds vev's server-side session multiplexer use case.

Package daemon holds vev's server-side session multiplexer use case.

Package daemon holds vev's server-side session multiplexer use case.

Package daemon holds vev's server-side session multiplexer use case.

Package daemon holds vev's server-side session multiplexer use case.

Package daemon holds vev's server-side session multiplexer use case.

Index

Constants

View Source
const CommandRequestTimeout = 10 * time.Second

Variables

View Source
var (
	ErrCommandRequestTimeout     = errors.New("command request timed out")
	ErrCommandRequestUnavailable = errors.New("command request connection is unavailable")
)

Functions

func SnapshotShutdownTimeout

func SnapshotShutdownTimeout() time.Duration

SnapshotShutdownTimeout reports the shared final-checkpoint shutdown budget.

Types

type CommandRequestOutcome added in v0.2.0

type CommandRequestOutcome struct {
	Result ports.CommandResult
	Err    error
}

CommandRequestOutcome is the result delivered for one tracked request.

type CommandRequestTracker added in v0.2.0

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

CommandRequestTracker correlates request results for one connection. The generation is part of every pending entry so a reused request ID from an older connection cannot complete a newer request.

func NewCommandRequestTracker added in v0.2.0

func NewCommandRequestTracker() *CommandRequestTracker

NewCommandRequestTracker constructs an empty per-connection tracker.

func (*CommandRequestTracker) Complete added in v0.2.0

func (t *CommandRequestTracker) Complete(generation uint64, result ports.CommandResult)

Complete accepts only the exact request generation. Unknown, late, and old generation results are safe no-ops.

func (*CommandRequestTracker) Fail added in v0.2.0

func (t *CommandRequestTracker) Fail(requestID, generation uint64, err error)

Fail completes the exact request with a transport or decode failure.

func (*CommandRequestTracker) PendingCount added in v0.2.0

func (t *CommandRequestTracker) PendingCount() int

PendingCount is intended for deterministic lifecycle tests.

func (*CommandRequestTracker) Publish added in v0.2.0

func (t *CommandRequestTracker) Publish(generation uint64) (uint64, <-chan CommandRequestOutcome)

Publish allocates and records a request before its bytes are sent.

func (*CommandRequestTracker) Remove added in v0.2.0

func (t *CommandRequestTracker) Remove(requestID, generation uint64)

Remove abandons only the exact request generation.

func (*CommandRequestTracker) Track added in v0.2.0

func (t *CommandRequestTracker) Track(requestID, generation uint64) (<-chan CommandRequestOutcome, bool)

Track records an existing wire request ID, as used by an inbound one-shot command connection. It rejects duplicate IDs on that connection.

func (*CommandRequestTracker) Wait added in v0.2.0

func (t *CommandRequestTracker) Wait(ctx context.Context, clock ports.Clock, requestID, generation uint64, outcome <-chan CommandRequestOutcome) (ports.CommandResult, error)

Wait waits without holding the tracker or connection sender lock. Timeout and cancellation remove only the matching request.

type Daemon

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

func New

func New(ptys ports.PTYFactory, clock ports.Clock, log *slog.Logger, opts ...Option) *Daemon

New constructs a Daemon. ptys spawns PTY-backed children, clock drives the render debounce, and log receives diagnostics (defaults to slog.Default).

func (*Daemon) ApplyConfig

func (d *Daemon) ApplyConfig(cfg domain.Config)

ApplyConfig validates and atomically swaps daemon runtime configuration.

func (*Daemon) CollectStartupGarbage

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

CollectStartupGarbage runs the one coordinator-owned GC pass before the daemon socket is published.

func (*Daemon) NotifyGlobal

func (d *Daemon) NotifyGlobal(sev domain.NoticeSeverity, code domain.NoticeCode, msg string, cause error)

NotifyGlobal raises a daemon-wide notice from outside the daemon package.

func (*Daemon) Serve

func (d *Daemon) Serve(ctx context.Context, l ports.Listener) error

Serve runs the accept loop over l, owning it for the loop's lifetime. It returns when the last session is removed or ctx is cancelled; on the latter path attached clients are detached with ReasonServerShutdown.

func (*Daemon) StopDurableWriters

func (d *Daemon) StopDurableWriters(ctx context.Context) []string

StopDurableWriters stops maintenance scheduling, cancels cooperative maintenance calls, stops snapshot admission, and requests the snapshot worker's final drain. The context bounds checkpoint success only: cancellation never detaches a writer from its owner.

func (*Daemon) WaitDurableWriters

func (d *Daemon) WaitDurableWriters()

WaitDurableWriters is the unconditional ownership barrier. It has no timeout or status branch: every writer goroutine must exit before Serve may return. Restoration is joined with the others because it mutates durable state too; it observes serveCtx cancellation, so waiting for it cannot outlive an uncooperative repository call any longer than the snapshot worker does.

type Guarded

type Guarded[T any] struct {
	// contains filtered or unexported fields
}

Guarded protects one value behind a mutex.

func (*Guarded[T]) Get

func (g *Guarded[T]) Get() T

func (*Guarded[T]) Set

func (g *Guarded[T]) Set(v T)

func (*Guarded[T]) With

func (g *Guarded[T]) With(fn func(*T))

type Option

type Option func(*Daemon)

func WithBarScriptCommandRunner

func WithBarScriptCommandRunner(runner ports.ShellCommandRunner) Option

WithBarScriptCommandRunner installs the shell command runner used by bar scripts.

func WithCatalogue

func WithCatalogue(catalogue ports.Catalogue, records []domain.CatalogueRecord) Option

WithCatalogue installs the singular catalogue and the strictly opened records that define the daemon's expected-session registry at startup.

func WithConfig

func WithConfig(cfg domain.Config) Option

WithConfig applies the initial user configuration.

func WithCwdReader

func WithCwdReader(fn func(int) (string, error)) Option

WithCwdReader overrides the process cwd reader used for persistence tests.

func WithDirOrHome

func WithDirOrHome(fn func(string) string) Option

WithDirOrHome installs path fallback behavior from the application layer.

func WithDurableMaintenance

func WithDurableMaintenance(catalogue ports.Catalogue, repository ports.SnapshotRepository) Option

WithDurableMaintenance retains the application wiring for the one pre-publication GC pass. Standalone users without an explicitly supplied coordinator receive the same canonical coordinator path.

func WithNoticeStore

func WithNoticeStore(store ports.NoticeStore) Option

WithNoticeStore enables persisting undeliverable notices across daemon restarts. A nil store keeps the daemon in no-op notice-persistence mode.

func WithProcessInspector

func WithProcessInspector(ins ports.ProcessInspector) Option

WithProcessInspector installs the platform process-inspection implementation.

func WithRecoveryCoordinator

func WithRecoveryCoordinator(coordinator *recoveryusecase.Coordinator) Option

WithRecoveryCoordinator installs the durable recovery coordinator.

func WithRemoteDiscovery added in v0.2.0

WithRemoteDiscovery installs the remote discovery ports used by the daemon. The composition root validates mode before constructing the daemon.

func WithRemotePreview added in v0.2.0

func WithRemotePreview(client ports.RemotePreviewClient) Option

WithRemotePreview installs the optional non-attaching remote viewport client.

func WithResumeParkGrace

func WithResumeParkGrace(grace time.Duration) Option

WithResumeParkGrace overrides how long detached resume-capable clients stay parked for reconnection. Non-positive durations keep the default.

func WithRuntimeObserver

func WithRuntimeObserver(observer ports.SerializedRuntimeObserver) Option

WithRuntimeObserver accepts only a composition-root serialized observer. The application owns its lifecycle; the daemon never creates or closes a second reporting worker around it.

func WithShell

func WithShell(cmd string, args []string) Option

WithShell overrides the command (and its args) each session spawns. The default is $SHELL (or /bin/sh) with no arguments; tests use this to run a deterministic program.

func WithSnapshotRepository

func WithSnapshotRepository(repository ports.SnapshotRepository) Option

WithSnapshotRepository enables content-addressed incremental snapshots.

func WithTempDir

func WithTempDir(dir string) Option

WithTempDir overrides the directory clipboard-image-transfer writes temp files into (production default: os.TempDir()); tests use this with t.TempDir() so writes are isolated and auto-cleaned.

Source Files

Jump to

Keyboard shortcuts

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