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 Probe ¶
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.
type SessionRef ¶
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.