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
- Variables
- func DefaultBase(getenv func(string) string, goos string, home func() (string, error)) (string, error)
- func NewID() string
- func ProjectDir(base, runefile string) string
- func ProjectID(runefile string) string
- func Read(dir string, from, to time.Time) ([]Action, []Damage, error)
- type Action
- type Approval
- type Arguments
- type Client
- type Damage
- type Error
- type Filter
- type Git
- type LocationError
- type Log
- type Options
- type Plan
- type Project
- type Record
- type Sandbox
- type UnusableError
Constants ¶
const ( TypeCall = "call" TypeAgentRun = "agent-run" TypeRequest = "request" TypeAuthFailure = "auth-failure" )
The types of a record.
const ( PhaseStart = "start" PhaseEnd = "end" )
The phases of a record that has two: a call and an agent run.
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.
const ( // DefaultRetentionDays is how long a day file is kept when the operator // names no period. DefaultRetentionDays = 90 )
const MaxRecordBytes = 64 << 10
MaxRecordBytes is the most one stored line holds.
const Version = 1
Version is the version of the record format.
Variables ¶
var Outcomes = []string{ OutcomeCompleted, OutcomeFailed, OutcomeRefused, OutcomeInvalidArguments, OutcomeUnknownTool, OutcomeCancelled, OutcomeTimedOut, OutcomeError, OutcomeIncomplete, OutcomeOK, }
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 ProjectDir ¶
ProjectDir is the directory that holds the log of one Runefile.
func ProjectID ¶
ProjectID names a project's directory: the first 16 hex digits of the SHA-256 of its Runefile's resolved path.
func Read ¶
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 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.
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 ¶
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 ¶
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 ¶
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.
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.
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 ¶
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