rotation

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rotation watches claude's session directory for /clear-style UUID rotations and notifies its host (internal/sessions) so the registry can follow claude to the new <uuid>.jsonl in real time.

The package has no dependency on internal/sessions; the contract is expressed via a Config struct of closures over primitive types so the import direction stays one-way (sessions -> rotation).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Dir is the claude sessions dir to watch (cfg.ClaudeSessionsDir).
	Dir string

	// Probe is the platform-specific FD probe. Required.
	Probe Probe

	// Snapshot returns the (id, pid) pairs to consider on each CREATE event.
	// The watcher snapshots once per event; ordering is not significant.
	Snapshot func() []SessionRef

	// IsAllocated reports whether id is in the freshly-allocated set, and
	// consumes the entry on a true return. Watcher calls this before
	// considering a CREATE for rotation.
	IsAllocated func(id string) bool

	// OnRotate is invoked when a CREATE for newID matches a session whose
	// probe reports it has newID's JSONL open. The watcher logs and continues
	// on error — rotation detection failures are not fatal.
	OnRotate func(oldID, newID string) error

	// Logger is required.
	Logger *slog.Logger
}

Config is the watcher's contract with its host. All callbacks are invoked from the watcher's single event-loop goroutine, but MUST be safe to call from a goroutine other than the one that constructed them.

type OpenFile

type OpenFile struct {
	FD   string // e.g. "12u" — see `lsof -F` docs
	Name string // path
}

OpenFile is one row of lsof's machine-readable output (Darwin).

type Probe

type Probe interface {
	OpenJSONL(pid int) (string, error)
}

Probe answers "what JSONL does PID currently have open?".

Returns absolute path on success, "" if PID has no JSONL fd open. Returns error only for unrecoverable probe failures; transient conditions like "process exited" or "permission denied on one fd" are squashed to ("", nil) so the watcher skips and retries on the next event.

func DefaultProbe

func DefaultProbe(_ *slog.Logger) Probe

DefaultProbe returns the Linux probe.

type SessionRef

type SessionRef struct {
	ID  string
	PID int
}

SessionRef is one (id, pid) pair the watcher should consider when matching a CREATE event. PID == 0 means no live child — skip and let the next event retry.

type Watcher

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

Watcher detects /clear-style UUID rotations by combining fsnotify CREATE events on the claude session dir with a per-PID probe of each tracked process's currently-open JSONL.

func New

func New(cfg Config) (*Watcher, error)

New constructs a Watcher. Returns an error only if fsnotify itself fails to initialize or the dir cannot be created and added. A missing Dir is created (MkdirAll, 0700) before the watch is added.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) error

Run blocks until ctx is cancelled or the underlying fsnotify watcher's channels are closed. Returns ctx.Err() on clean shutdown.

Jump to

Keyboard shortcuts

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