Documentation
¶
Overview ¶
Package tail watches ~/.claude/projects/<encoded-cwd>/<sid>.jsonl for claude's per-session JSONL output, opens the file as it appears, and feeds appended bytes into a jsonl.Reader until the deterministic end-of-turn signal fires or the caller cancels.
MUST NOT log file contents. Like the jsonl package, this watcher logs only paths, offsets, and error messages — never line bytes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Workdir is the directory pyry's agent-run was invoked from. The watcher
// uses agentrun.EncodeProjectDir(Workdir) to compute the claude project
// directory to watch.
Workdir string
// SessionID is the claude session UUID — the stem of the .jsonl file we
// are watching for.
SessionID string
// HomeDir is the home directory under which ~/.claude/projects lives.
// Injectable for tests. If empty, os.UserHomeDir() is consulted at New.
HomeDir string
// StartOffset is a resume hint. When > 0, the watcher Seeks the file to
// StartOffset on open and passes the same value through to jsonl.Config
// so Offset() reports absolute file positions.
StartOffset int64
// OnEvent is invoked once per assistant event surfaced by jsonl.Reader.
// Required. Invoked from the Run goroutine.
OnEvent func(jsonl.Event)
// OnEndOfTurn is invoked at most once, when an Event with EndOfTurn=true
// is surfaced. After it returns, Run returns nil. Required.
OnEndOfTurn func()
// Logger is optional and defaults to slog.Default().
Logger *slog.Logger
}
Config configures a Watcher. OnEvent and OnEndOfTurn are invoked from the Run goroutine; callers that need to hand them to another goroutine should send on a channel from the callback.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher wraps an fsnotify.Watcher with the claude session-JSONL lifecycle: wait for <sid>.jsonl to appear under ~/.claude/projects/<encoded>/, open it, and drive a jsonl.Reader until end-of-turn or cancellation.
func New ¶
New constructs a Watcher. Creates the encoded project directory (mode 0700) if it does not exist — mirrors internal/sessions/rotation's pattern and covers the first-run-in-this-workdir case where claude has not yet created the dir.
Caller MUST call Run; otherwise the underlying fsnotify watcher leaks (closed via defer in Run).
func (*Watcher) Offset ¶
Offset returns the byte position of the next not-yet-consumed line. Equals Config.StartOffset before the file is opened. Call after Run returns; NOT safe to call concurrently with Run.