Documentation
¶
Overview ¶
Package hotswap provides workspace change detection and live reload hooks.
It wires file/polling watchers with adaptors that refresh runtime finders and registries when workspace resources change.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adaptor ¶
type Adaptor[T any] struct { // contains filtered or unexported fields }
Adaptor bridges a workspace loader and a finder using the Reloadable interface.
func NewAdaptor ¶
func NewAdaptor[T any](load LoaderFunc[T], set SetFunc[T], remove RemoveFunc) *Adaptor[T]
NewAdaptor creates a generic adaptor.
type Change ¶
type Change struct {
Kind string // workspace kind (e.g. "agents", "models", "embedders")
Name string // bare resource name without extension
Action Action
}
Change represents a single workspace resource mutation.
type FSWatcher ¶
type FSWatcher struct {
// contains filtered or unexported fields
}
FSWatcher implements Watcher using fsnotify for filesystem-based workspaces.
func NewFSWatcher ¶
func NewFSWatcher(root string, opts ...WatcherOption) *FSWatcher
NewFSWatcher creates an FS-based watcher rooted at the given workspace directory.
type LoaderFunc ¶
LoaderFunc loads a resource by name.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates watchers and dispatches changes to registered Reloadables.
func (*Manager) Register ¶
func (m *Manager) Register(kind string, r Reloadable)
Register adds a Reloadable handler for the specified workspace kind.
type PollingOption ¶
type PollingOption func(*PollingWatcher)
PollingOption configures a PollingWatcher.
func WithPollInterval ¶
func WithPollInterval(d time.Duration) PollingOption
WithPollInterval sets the polling interval.
type PollingWatcher ¶
type PollingWatcher struct {
// contains filtered or unexported fields
}
PollingWatcher implements Watcher for non-FS stores by periodically polling Store.Entries and comparing snapshots to detect changes.
func NewPollingWatcher ¶
func NewPollingWatcher(store workspace.Store, opts ...PollingOption) *PollingWatcher
NewPollingWatcher creates a watcher that polls the given store.
func (*PollingWatcher) Close ¶
func (w *PollingWatcher) Close() error
Close is a no-op for the polling watcher.
type Reloadable ¶
Reloadable handles workspace resource changes for a specific kind.
func NewAgentAdaptor ¶
func NewAgentAdaptor(loader agent.Loader, finder *agentfinder.Finder) Reloadable
NewAgentAdaptor creates a Reloadable that reloads agents on workspace changes.
func NewEmbedderAdaptor ¶
func NewEmbedderAdaptor(loader *embedderloader.Service, finder *embedderfinder.Finder) Reloadable
NewEmbedderAdaptor creates a Reloadable that reloads embedder configs on workspace changes.
func NewModelAdaptor ¶
func NewModelAdaptor(loader *modelloader.Service, finder *modelfinder.Finder) Reloadable
NewModelAdaptor creates a Reloadable that reloads model configs on workspace changes.
type Watcher ¶
type Watcher interface {
// Watch begins observing the given workspace kinds and delivers changes to
// the provided callback. It blocks until ctx is cancelled or an
// unrecoverable error occurs.
Watch(ctx context.Context, kinds []string, onChange func(Change)) error
// Close releases watcher resources.
Close() error
}
Watcher is an abstraction over the mechanism that detects workspace changes. An FS implementation uses fsnotify; a DB implementation might poll or use change streams.
type WatcherOption ¶
type WatcherOption func(*FSWatcher)
WatcherOption configures FSWatcher.
func WithDebounce ¶
func WithDebounce(d time.Duration) WatcherOption
WithDebounce sets the debounce duration for the FS watcher.