runlog

package
v0.182.6 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package runlog records privacy-safe telemetry for commands launched through `wb run --`. The log lives inside a managed worktree so an agent can write it without access to the user's home directory and so lifecycle tooling can later publish or aggregate it with the worktree's other local evidence.

Index

Constants

View Source
const (
	EventSchemaVersion = 1
	OperationIDEnv     = "WB_OPERATION_ID"
)

Variables

This section is empty.

Functions

func Append

func Append(path string, event Event) error

Append writes one event under an exclusive file lock so concurrent commands in the same worktree cannot interleave JSON bytes.

Types

type Event

type Event struct {
	SchemaVersion int       `json:"schema_version"`
	Timestamp     time.Time `json:"timestamp"`
	OperationID   string    `json:"operation_id"`
	State         string    `json:"state"`
	Kind          string    `json:"kind"`
	ArgsSHA256    string    `json:"args_sha256"`
	ArgumentCount int       `json:"argument_count"`
	Repository    string    `json:"repository,omitempty"`
	EffortID      string    `json:"effort_id,omitempty"`
	RunID         string    `json:"run_id,omitempty"`
	DurationMS    int64     `json:"duration_ms,omitempty"`
	UserCPUMS     int64     `json:"user_cpu_ms,omitempty"`
	SystemCPUMS   int64     `json:"system_cpu_ms,omitempty"`
	QueueWaitMS   int64     `json:"queue_wait_ms,omitempty"`
	CPUUnits      int       `json:"cpu_units,omitempty"`
	LoadOverride  bool      `json:"load_override,omitempty"`
	// LoadFloorSkipped names why host-load admission was disabled for this
	// command, when it was: "env" (WB_ADMISSION_LOAD_FLOOR<=0), "ci"
	// (CI/GITHUB_ACTIONS declared), or "config" (wb.yaml
	// admission.load_floor: 0). Empty means the check was active. See
	// internal/hostload.Resolve.
	LoadFloorSkipped string `json:"load_floor_skipped,omitempty"`
	// AdmittedAt is the wall-clock moment this operation's CPU lease was
	// granted (immediately for units <= 0, after QueueWaitMS otherwise). A
	// pointer distinguishes "never admitted" (a command refused before
	// admission) from the zero time. See cmd/wb run.go's queue-visibility
	// receipts, which surface this alongside QueueWaitMS on stderr.
	AdmittedAt *time.Time `json:"admitted_at,omitempty"`
	ExitCode   *int       `json:"exit_code,omitempty"`

	// Provenance fields (wb#631, SDLC logging-gap analysis 2026-09-18): IDs
	// only, stamped by Begin from the environment at zero cost, never a
	// prompt or response body. Additive and omitempty: EventSchemaVersion did
	// not need to move for a purely additive field.
	HarnessSessionID string `json:"harness_session_id,omitempty"`
	Harness          string `json:"harness,omitempty"`
	EffortLevel      string `json:"effort_level,omitempty"`
	AgentID          string `json:"agent_id,omitempty"`
	ToolUseID        string `json:"tool_use_id,omitempty"`
	WBVersion        string `json:"wb_version,omitempty"`
}

Event is one immutable command lifecycle observation. It deliberately omits raw arguments and output; ArgsSHA256 supports correlation without copying prompts, commit messages, paths, tokens, or source into the log.

func Read

func Read(path string) ([]Event, error)

Read parses a run event log. Unknown newer schemas are rejected.

func ReadCurrent

func ReadCurrent(cwd string) ([]Event, string, error)

ReadCurrent returns telemetry for the managed worktree containing cwd.

type KindSummary

type KindSummary struct {
	Kind       string `json:"kind"`
	Operations int    `json:"operations"`
	Failed     int    `json:"failed"`
	WallMS     int64  `json:"wall_ms"`
	P50MS      int64  `json:"p50_ms"`
	P95MS      int64  `json:"p95_ms"`
}

type Recorder

type Recorder struct {
	OperationID string
	Path        string
	StartedAt   time.Time
	// contains filtered or unexported fields
}

Recorder owns one operation ID and its optional managed-worktree log.

func Begin

func Begin(cwd string, argv []string, now time.Time) (Recorder, error)

Begin records a requested operation when cwd belongs to a managed worktree. Unmanaged directories still get an operation ID but no filesystem side effect; WB can therefore wrap diagnostics outside a worktree safely.

func (Recorder) Finish

func (recorder Recorder) Finish(exitCode int, userCPU, systemCPU time.Duration, now time.Time) error

Finish records the terminal result. CPU durations come from the child process state and exclude WB orchestration overhead.

func (*Recorder) RecordAdmission

func (recorder *Recorder) RecordAdmission(units int, wait time.Duration)

RecordAdmission adds scheduler evidence to the terminal event without exposing command arguments or output.

func (*Recorder) RecordLoadFloorSkipped added in v0.118.0

func (recorder *Recorder) RecordLoadFloorSkipped(reason string)

RecordLoadFloorSkipped records why host-load admission was disabled for this command (see internal/hostload.Resolve for the reason values), so a CI or WB_ADMISSION_LOAD_FLOOR-driven skip is provable from the runlog rather than only from the caller's own log.

func (*Recorder) RecordLoadOverride added in v0.118.0

func (recorder *Recorder) RecordLoadOverride(overridden bool)

RecordLoadOverride records whether --allow-saturated-host admitted this command despite the host's load average exceeding the admission floor.

func (*Recorder) RecordQueueAdmittedAt added in v0.120.0

func (recorder *Recorder) RecordQueueAdmittedAt(admittedAt time.Time)

RecordQueueAdmittedAt records the wall-clock moment this operation's CPU lease was granted, alongside RecordAdmission's queue-wait duration. Call it once, right after the lease is acquired (or immediately, for a units <= 0 command that never queues).

type Summary

type Summary struct {
	Since       time.Time     `json:"since"`
	Operations  int           `json:"operations"`
	Running     int           `json:"running"`
	Failed      int           `json:"failed"`
	WallMS      int64         `json:"wall_ms"`
	UserCPUMS   int64         `json:"user_cpu_ms"`
	SystemCPUMS int64         `json:"system_cpu_ms"`
	Kinds       []KindSummary `json:"kinds"`
}

func Summarize

func Summarize(events []Event, since time.Time) Summary

Summarize computes completed-operation cost and currently unmatched starts.

Jump to

Keyboard shortcuts

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