Help us shape the future of Go! Take the 2026 Go Developer Survey

eventlog

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package eventlog fans run events out to sinks: the --json JSONL stream and the opt-in SQLite event log. Every sink receives the same event types and payloads, so they cannot drift apart.

Index

Constants

View Source
const (
	// LevelMetadata stores no prompt, assistant, tool-argument, tool-output
	// or submission bodies: each is replaced by its length.
	LevelMetadata = "metadata"
	// LevelFull stores bodies, redacted and size-capped.
	LevelFull = "full"
)

Levels control how much of each event is stored.

View Source
const DefaultMaxPayloadBytes = 64 << 10

DefaultMaxPayloadBytes caps one stored event payload.

View Source
const MinSecretLen = 6

MinSecretLen keeps short values (e.g. "1" or "true") from being treated as secrets and redacting unrelated text.

View Source
const Redacted = "[REDACTED]"

Redacted replaces every secret the Redactor finds.

Variables

View Source
var BodyKeys = []string{"text", "arguments", "output", "submission", "task", "content", "prompt", "question"}

BodyKeys are the payload fields that carry bodies; at LevelMetadata they are replaced by <key>_len.

View Source
var SchemaVersion = func() int { m := embeddedMigrations(); return m[len(m)-1].version }()

SchemaVersion is the newest schema this binary writes.

Functions

func DSN

func DSN(path string) string

DSN returns the driver connection string for path: WAL journaling, a busy timeout so concurrent runs wait instead of failing, and immediate write transactions so they take the write lock up front.

func FinishAttemptGroup added in v0.9.0

func FinishAttemptGroup(path, id string, r AttemptGroupResult) error

FinishAttemptGroup records how group id ended.

func SecretEnvName

func SecretEnvName(name string) bool

SecretEnvName reports whether an environment variable's value is treated as a secret: names ending in _KEY, _TOKEN, _SECRET or _PASSWORD.

func StartAttemptGroup added in v0.9.0

func StartAttemptGroup(path string, g AttemptGroup) error

StartAttemptGroup records g in the log DB at path, creating or migrating the database like Open. It does not add a runs row: each attempt's child run adds its own.

Types

type AttemptGroup added in v0.9.0

type AttemptGroup struct {
	ID        string
	Cwd       string
	Requested int
	TraceID   string
	Version   string
	Started   time.Time
}

AttemptGroup is one --attempts invocation in the log DB. Its attempts are the runs rows whose attempts_id is ID.

type AttemptGroupResult added in v0.9.0

type AttemptGroupResult struct {
	Run          int
	Winner       *int
	WinnerBranch string
	StopReason   string
	CostUSD      float64
	WallMS       int64
	Ended        time.Time
}

AttemptGroupResult is how a group ended.

type Fanout

type Fanout []Sink

Fanout sends each event to every sink in order.

func (Fanout) Emit

func (f Fanout) Emit(kind string, fields map[string]any)

type JSONL

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

JSONL writes each event as one JSON object and newline, with its kind under "type". After the first failed write it stops and Err reports the error.

func NewJSONL

func NewJSONL(out io.Writer) *JSONL

func (*JSONL) Emit

func (e *JSONL) Emit(kind string, fields map[string]any)

func (*JSONL) Err

func (e *JSONL) Err() error

type Options

type Options struct {
	Path            string
	Level           string // LevelMetadata (default) or LevelFull
	MaxDays         int    // prune runs older than this at open; 0 keeps all
	MaxRuns         int    // keep at most this many runs, including the new one; 0 keeps all
	MaxPayloadBytes int    // 0 means DefaultMaxPayloadBytes
	Redactor        *Redactor
	Run             RunInfo
	// Step returns the current step for each event; nil records 0.
	Step func() int
	// Warn is called at most once, on the caller's goroutine, after the
	// first failed write. Later writes are dropped.
	Warn func(msg string)
	// Now overrides the clock in tests.
	Now func() time.Time
}

Options configures an SQLite sink.

type Redactor

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

Redactor masks secret values and, optionally, token-shaped strings. It is safe for concurrent use.

func EnvRedactor

func EnvRedactor(extra ...string) *Redactor

EnvRedactor is NewRedactor(os.Environ(), extra...).

func NewRedactor

func NewRedactor(env []string, extra ...string) *Redactor

NewRedactor masks the values of secret-named variables in env (KEY=VALUE entries, typically os.Environ()) and the given extra values, such as env values set in the config, plus token-shaped strings.

func NewValueRedactor

func NewValueRedactor(vals []string, patterns bool) *Redactor

NewValueRedactor masks exactly vals (values shorter than MinSecretLen are skipped), each also in its JSON-escaped form, and with patterns also token-shaped strings.

func (*Redactor) Add

func (r *Redactor) Add(vals ...string)

Add registers more secret values, such as credentials refreshed during the run.

func (*Redactor) Len

func (r *Redactor) Len() int

Len is the number of distinct secret values r masks.

func (*Redactor) PartialSuffix

func (r *Redactor) PartialSuffix(s string) int

PartialSuffix returns the length of the longest suffix of s that is the start, but not the whole, of a secret value: output a reader should hold back until more arrives, so a secret split across reads is still masked.

func (*Redactor) Redact

func (r *Redactor) Redact(s string) string

Redact returns s with secrets masked. A nil Redactor still masks token-shaped strings.

func (*Redactor) RedactCount

func (r *Redactor) RedactCount(s string) (string, int)

RedactCount is Redact plus how many secrets it masked.

type RunInfo

type RunInfo struct {
	Cwd, Model, Provider, Task, Version string
	Resumed                             bool
}

RunInfo describes the run being logged.

type SQLite

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

SQLite is a Sink that writes events to an SQLite database from a background goroutine, batching inserts in transactions. Write failures never surface as errors: Warn is called once and later events are dropped.

func Open

func Open(opts Options) (*SQLite, error)

Open creates or migrates the database at opts.Path, prunes old runs, and records a new run. The caller decides what an error means; tinyagent warns and runs without the log.

func (*SQLite) Close

func (s *SQLite) Close()

Close flushes buffered events, marks the run ended if no result was recorded, and closes the database. A write failure is reported through Warn (once), never returned.

func (*SQLite) Emit

func (s *SQLite) Emit(kind string, fields map[string]any)

Emit records one event. It never blocks on a failed database.

func (*SQLite) RunID

func (s *SQLite) RunID() string

RunID identifies this run's row in runs.

type Sink

type Sink interface {
	Emit(kind string, fields map[string]any)
}

Sink receives run events. Emit is called from a single goroutine (the agent's), in event order.

Jump to

Keyboard shortcuts

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