audit

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 20 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 audit keeps the audit log of one project: what agents asked Rune's MCP servers to do. The log is a directory of JSON-lines files, one per UTC day, outside the project. A record is appended and never changed, so a call that was started and never finished stays visible as a start without an end. Writers in separate processes take a lock file in turn.

Index

Constants

View Source
const (
	TypeCall        = "call"
	TypeAgentRun    = "agent-run"
	TypeRequest     = "request"
	TypeAuthFailure = "auth-failure"
)

The types of a record.

View Source
const (
	PhaseStart = "start"
	PhaseEnd   = "end"
)

The phases of a record that has two: a call and an agent run.

View Source
const (
	OutcomeCompleted        = "completed"
	OutcomeFailed           = "failed"
	OutcomeRefused          = "refused"
	OutcomeInvalidArguments = "invalid-arguments"
	OutcomeUnknownTool      = "unknown-tool"
	OutcomeCancelled        = "cancelled"
	OutcomeTimedOut         = "timed-out"
	OutcomeError            = "error"
	OutcomeOK               = "ok"
	OutcomeIncomplete       = "incomplete"
)

The outcomes of an action. OutcomeIncomplete is never stored: a reader gives it to a start that has no end.

View Source
const (
	// DefaultRetentionDays is how long a day file is kept when the operator
	// names no period.
	DefaultRetentionDays = 90
)
View Source
const MaxRecordBytes = 64 << 10

MaxRecordBytes is the most one stored line holds.

View Source
const Version = 1

Version is the version of the record format.

Variables

Outcomes lists every outcome a reader can report, in the order the documentation gives them.

Functions

func DefaultBase

func DefaultBase(getenv func(string) string, goos string, home func() (string, error)) (string, error)

DefaultBase is the directory the logs of every project live under when the operator names none: the user's state directory. A relative XDG_STATE_HOME is ignored, as the XDG specification says: a server and `rune log` each have a working directory of their own, and it would name a different directory in each.

func NewID

func NewID() string

NewID returns a new id for an action: 16 hex digits.

func ProjectDir

func ProjectDir(base, runefile string) string

ProjectDir is the directory that holds the log of one Runefile.

func ProjectID

func ProjectID(runefile string) string

ProjectID names a project's directory: the first 16 hex digits of the SHA-256 of its Runefile's resolved path.

func Read

func Read(dir string, from, to time.Time) ([]Action, []Damage, error)

Read returns the actions in the day files of dir whose UTC day lies between the days of from and to, oldest first, and the records it had to skip. A zero from starts at the oldest file and a zero to ends at the newest. A directory that does not exist holds no action.

An action is in the file of the day it started on, so the days of a range of start times are exactly the files to read.

Types

type Action

type Action struct {
	SchemaVersion int        `json:"schemaVersion"`
	Type          string     `json:"type"`
	ID            string     `json:"id"`
	Start         time.Time  `json:"start"`
	End           *time.Time `json:"end,omitempty"`
	DurationMs    *int64     `json:"durationMs,omitempty"`
	Outcome       string     `json:"outcome,omitempty"`
	ExitCode      *int       `json:"exitCode,omitempty"`

	Session   string     `json:"session,omitempty"`
	Parent    string     `json:"parent,omitempty"`
	Transport string     `json:"transport,omitempty"`
	Auth      string     `json:"auth,omitempty"`
	Client    *Client    `json:"client,omitempty"`
	Method    string     `json:"method,omitempty"`
	Tool      string     `json:"tool,omitempty"`
	Task      string     `json:"task,omitempty"`
	Arguments *Arguments `json:"arguments,omitempty"`
	Error     *Error     `json:"error,omitempty"`
	Approval  *Approval  `json:"approval,omitempty"`
	Grants    []string   `json:"grants,omitempty"`
	Plan      *Plan      `json:"plan,omitempty"`
	Sandbox   *Sandbox   `json:"sandbox,omitempty"`
	Project   *Project   `json:"project,omitempty"`

	Remote     string `json:"remote,omitempty"`
	Suppressed int    `json:"suppressed,omitempty"`
}

Action is what a reader builds from the records of one id: the start and, when there is one, the end. It is the object `rune log --json` prints.

type Approval

type Approval struct {
	Asked    bool     `json:"asked"`
	Decision string   `json:"decision"`
	Tasks    []string `json:"tasks,omitempty"`
}

Approval is the decision about a call that needed one.

type Arguments

type Arguments struct {
	Supplied  json.RawMessage `json:"supplied,omitempty"`
	Effective json.RawMessage `json:"effective,omitempty"`
}

Arguments are a call's arguments: as received, and as the task was bound. Both are JSON kept as written, so numbers and the order of names survive.

type Client

type Client struct {
	Name     string `json:"name,omitempty"`
	Version  string `json:"version,omitempty"`
	Reported bool   `json:"reported,omitempty"`
}

Client is what a client reported about itself in the handshake. Reported is set only on an Action, to mark the name as the client's own claim.

type Damage

type Damage struct {
	File  string
	Count int
}

Damage counts the records of one file that could not be read.

type Error

type Error struct {
	Kind    string `json:"kind,omitempty"`
	Message string `json:"message,omitempty"`
}

Error says why an action ran no task.

type Filter

type Filter struct {
	// Since and Until bound the start time: at or after Since, before Until.
	Since, Until time.Time
	// Tasks match the task name or the tool name.
	Tasks []string
	// Outcomes match the outcome.
	Outcomes []string
	// Clients match the client name, ignoring case.
	Clients []string
	// Sessions match the session id or a prefix of it.
	Sessions []string
	// All also selects the requests that are not tool calls.
	All bool
}

Filter selects actions. A zero field selects everything. An action that lacks the field a filter names does not match that filter.

func (Filter) Match

func (f Filter) Match(a Action) bool

Match reports whether a passes every part of the filter.

type Git

type Git struct {
	State  string `json:"state"`
	Commit string `json:"commit,omitempty"`
	Dirty  *bool  `json:"dirty,omitempty"`
}

Git is the repository state at a call. Dirty is nil when git did not say.

type LocationError

type LocationError struct {
	Dir     string
	Project string
}

LocationError reports a log directory that lies inside the project, where a task's own files are.

func (*LocationError) Error

func (e *LocationError) Error() string

type Log

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

Log is the audit log of one project. It is safe for concurrent use, and several processes may write to one directory.

func Open

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

Open returns the log of opts.Runefile under opts.Base, creating its directory when it is missing. It refuses a directory inside the project, one that is a symbolic link, and one that belongs to another user. Files past the retention period are removed.

func (*Log) Append

func (l *Log) Append(start time.Time, rec Record, sync bool) error

Append writes rec to the file of the UTC day its action started on. The end of an action is given the start of that action, so both are in one file. With sync the bytes are flushed to the disk before Append returns.

func (*Log) Dir

func (l *Log) Dir() string

Dir is the directory that holds the project's day files.

func (*Log) Prune

func (l *Log) Prune() error

Prune removes the day files older than the retention period. Only files named as a day file are touched.

type Options

type Options struct {
	// Base is the directory the logs of every project live under.
	Base string
	// Runefile is the resolved path of the project's Runefile.
	Runefile string
	// Outside lists the directories the log must not be inside: the places
	// a task of the project normally writes.
	Outside []string
	// RetentionDays is how many days a day file is kept. Zero keeps every
	// file.
	RetentionDays int
	// Now is the clock for retention. Nil means time.Now.
	Now func() time.Time
	// Warn is told about a day file that could not be removed. Nil drops
	// the warning. It is never called for a record that was not written:
	// Append returns that error.
	Warn func(error)
}

Options says where a log lives and how long it keeps its files.

type Plan

type Plan struct {
	Role   string `json:"role"`
	ID     string `json:"id"`
	Digest string `json:"digest,omitempty"`
}

Plan is the stored plan a call made or applied.

type Project

type Project struct {
	Runefile         string `json:"runefile,omitempty"`
	DefinitionDigest string `json:"definitionDigest,omitempty"`
	ConfigDigest     string `json:"configDigest,omitempty"`
	Git              *Git   `json:"git,omitempty"`
}

Project is what a call ran against.

type Record

type Record struct {
	V     int       `json:"v"`
	Type  string    `json:"type"`
	Phase string    `json:"phase,omitempty"`
	ID    string    `json:"id"`
	Time  time.Time `json:"time"`

	DurationMs *int64 `json:"durationMs,omitempty"`
	Outcome    string `json:"outcome,omitempty"`
	ExitCode   *int   `json:"exitCode,omitempty"`

	Session   string     `json:"session,omitempty"`
	Parent    string     `json:"parent,omitempty"`
	Transport string     `json:"transport,omitempty"`
	Auth      string     `json:"auth,omitempty"`
	Client    *Client    `json:"client,omitempty"`
	Method    string     `json:"method,omitempty"`
	Tool      string     `json:"tool,omitempty"`
	Task      string     `json:"task,omitempty"`
	Arguments *Arguments `json:"arguments,omitempty"`
	Error     *Error     `json:"error,omitempty"`
	Approval  *Approval  `json:"approval,omitempty"`
	Grants    []string   `json:"grants,omitempty"`
	Plan      *Plan      `json:"plan,omitempty"`
	Sandbox   *Sandbox   `json:"sandbox,omitempty"`
	Project   *Project   `json:"project,omitempty"`

	Remote     string `json:"remote,omitempty"`
	Suppressed int    `json:"suppressed,omitempty"`
}

Record is one stored line. Which fields are set depends on Type and Phase.

func (Record) Encode

func (r Record) Encode() ([]byte, error)

Encode writes the record as one line that ends with a line break. A record that would pass MaxRecordBytes loses its arguments, which are the only part an agent sizes: they are replaced by a mark with the bytes left out.

type Sandbox

type Sandbox struct {
	Enforced bool   `json:"enforced"`
	Backend  string `json:"backend,omitempty"`
	Mode     string `json:"mode,omitempty"`
}

Sandbox states whether a sandbox was enforced for a call, which backend enforced it, and the operator's mode: "enforce" or "off". A record written before spec 053 has neither a backend nor a mode.

type UnusableError

type UnusableError struct {
	Path   string
	Reason string
}

UnusableError reports a log directory that is a link, is not a directory or belongs to another user.

func (*UnusableError) Error

func (e *UnusableError) Error() string

Jump to

Keyboard shortcuts

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