tail

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 12 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 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

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

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

func (w *Watcher) Offset() int64

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.

func (*Watcher) Run

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

Run blocks until end-of-turn fires, ctx is cancelled, or an unrecoverable I/O error occurs. Returns nil after OnEndOfTurn has been invoked.

Cleans up the fsnotify watcher (and any file opened by the watcher) via defer; safe to call exactly once per Watcher.

Jump to

Keyboard shortcuts

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