daemon

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBufferSize = 10000

DefaultBufferSize is the default capacity for event buffers.

Variables

This section is empty.

Functions

func IsStdinTTY

func IsStdinTTY() bool

IsStdinTTY returns true if stdin is a terminal.

Types

type Config

type Config struct {
	Headless   bool
	Port       int
	SocketPath string
	PIDPath    string
	BufferSize int
	Debug      bool
	// CommandExecutor is called by REPL for CLI command execution with flags.
	// If nil, REPL falls back to basic IPC-only execution.
	CommandExecutor ipc.CommandExecutor
}

Config holds daemon configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default daemon configuration.

type Daemon

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

Daemon is the persistent webctl daemon process.

func New

func New(cfg Config) *Daemon

New creates a new daemon with the given configuration.

func (*Daemon) Handler

func (d *Daemon) Handler() ipc.Handler

Handler returns the IPC request handler function. Used by the CLI to create a direct executor for REPL command execution.

func (*Daemon) Run

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

Run starts the daemon and blocks until shutdown.

type REPL

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

REPL provides an interactive command interface for the daemon.

func NewREPL

func NewREPL(handler ipc.Handler, cmdExec ipc.CommandExecutor, shutdown func()) *REPL

NewREPL creates a new REPL with the given handler, command executor, and shutdown callback. The cmdExec function executes CLI commands with full flag support. If cmdExec is nil, REPL falls back to basic IPC-only command execution.

func (*REPL) Close

func (r *REPL) Close() error

Close closes the readline instance if it exists. Safe to call multiple times (idempotent). Returns the error from the first close attempt on all subsequent calls.

func (*REPL) Run

func (r *REPL) Run() error

Run starts the REPL loop. Blocks until exit command or EOF.

func (*REPL) SetSessionProvider

func (r *REPL) SetSessionProvider(sp SessionProvider)

SetSessionProvider sets the session provider for dynamic prompt generation.

type RingBuffer

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

RingBuffer is a thread-safe circular buffer with fixed capacity. When the buffer is full, new items overwrite the oldest items.

func NewRingBuffer

func NewRingBuffer[T any](capacity int) *RingBuffer[T]

NewRingBuffer creates a new ring buffer with the specified capacity.

func (*RingBuffer[T]) All

func (b *RingBuffer[T]) All() []T

All returns all items in the buffer, oldest first. Allocates a new slice on each call. This is acceptable for the current request-response IPC pattern where each query is a discrete operation.

func (*RingBuffer[T]) Cap

func (b *RingBuffer[T]) Cap() int

Cap returns the buffer capacity.

func (*RingBuffer[T]) Clear

func (b *RingBuffer[T]) Clear()

Clear removes all items from the buffer.

func (*RingBuffer[T]) Len

func (b *RingBuffer[T]) Len() int

Len returns the current number of items in the buffer.

func (*RingBuffer[T]) Push

func (b *RingBuffer[T]) Push(item T)

Push adds an item to the buffer. If the buffer is full, the oldest item is overwritten.

func (*RingBuffer[T]) RemoveIf

func (b *RingBuffer[T]) RemoveIf(fn func(*T) bool)

RemoveIf removes all items for which fn returns true. Items are compacted in-place, maintaining order.

func (*RingBuffer[T]) Update

func (b *RingBuffer[T]) Update(fn func(*T) bool)

Update iterates through buffer items from newest to oldest, calling fn with a pointer to each item. Iteration stops when fn returns true. This allows in-place modification of buffer entries.

type SessionManager

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

SessionManager tracks CDP page sessions.

func NewSessionManager

func NewSessionManager() *SessionManager

NewSessionManager creates a new session manager.

func (*SessionManager) Active

func (m *SessionManager) Active() *ipc.PageSession

Active returns the active session info, or nil if none.

func (*SessionManager) ActiveID

func (m *SessionManager) ActiveID() string

ActiveID returns the current active session ID (empty if none).

func (*SessionManager) Add

func (m *SessionManager) Add(sessionID, targetID, url, title string)

Add adds a new session. If it's the first session, it becomes active.

func (*SessionManager) All

func (m *SessionManager) All() []ipc.PageSession

All returns all sessions as IPC PageSession list.

func (*SessionManager) Clear

func (m *SessionManager) Clear()

Clear removes all sessions and resets the manager state. Used when browser connection is lost.

func (*SessionManager) Count

func (m *SessionManager) Count() int

Count returns the number of sessions.

func (*SessionManager) FindByQuery

func (m *SessionManager) FindByQuery(query string) []ipc.PageSession

FindByQuery searches for sessions matching the query. Query is matched against session ID prefix (case-sensitive) or title substring (case-insensitive). Returns matching sessions.

func (*SessionManager) Get

func (m *SessionManager) Get(sessionID string) *ipc.PageSession

Get returns a session by ID, or nil if not found.

func (*SessionManager) Remove

func (m *SessionManager) Remove(sessionID string) (newActiveID string, activeChanged bool)

Remove removes a session. If it was active, switches to most recent remaining. Returns the new active session ID (empty if none remain) and true if active changed.

func (*SessionManager) SetActive

func (m *SessionManager) SetActive(sessionID string) bool

SetActive sets the active session by ID. Returns false if the session doesn't exist.

func (*SessionManager) Update

func (m *SessionManager) Update(sessionID, url, title string)

Update updates a session's URL and title by session ID.

func (*SessionManager) UpdateByTargetID

func (m *SessionManager) UpdateByTargetID(targetID, url, title string)

UpdateByTargetID updates a session's URL and title by target ID.

type SessionProvider

type SessionProvider func() (active *ipc.PageSession, count int)

SessionProvider returns the active session info and total count.

Jump to

Keyboard shortcuts

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