audit

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 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 writes an append-only JSONL record of what tools did and what the user approved or denied. Secrets are masked before writing.

Index

Constants

View Source
const (
	KindSession    = "session_start"
	KindPrompt     = "prompt"
	KindToolCall   = "tool_call"
	KindToolResult = "tool_result"
	KindApproval   = "approval"
	KindDenial     = "denial"
	KindHook       = "hook"
	KindRule       = "rule"      // a rule's verdict on a prompt or an answer (spec_041_gates)
	KindGuardrail  = "guardrail" // a guardrail's decision on a prompt, a tool call, a result or an answer
	KindUndo       = "undo"
	KindAttachment = "attachment"  // an image sent to the model: path and hash only
	KindUserShell  = "user_shell"  // a command the user ran with "!" (not an agent action)
	KindUserSearch = "user_search" // a web search the user ran with /search web
	KindTurnEnd    = "turn_end"    // a turn that didn't finish: stopped, or at a limit (Decision)
)

Kinds of audit entries.

View Source
const (
	DecisionSteer   = "steer"   // a prompt sent while a turn ran (Workspace.Steer)
	DecisionStopped = "stopped" // the user stopped the turn
	DecisionLimit   = "limit"   // the turn reached a limit; Detail: steps, cost or time
)

Decisions on a KindPrompt and a KindTurnEnd entry.

Variables

This section is empty.

Functions

func Arg added in v0.9.1

func Arg(args map[string]any, keys ...string) string

Arg is the first of keys that args holds as a string that isn't empty ("" when none does): a tool call's argument, by its names.

func SessionFrom added in v0.8.3

func SessionFrom(ctx context.Context) string

SessionFrom is the session WithSession put in ctx ("" none).

func Stamp added in v0.8.3

func Stamp(dir string, since time.Time) string

Stamp identifies the log Read would read from dir since then, as its files are: an entry written since changes it. It reads no entries.

func WithSession added in v0.8.3

func WithSession(ctx context.Context, session string) context.Context

WithSession is ctx for a turn of session: what LogContext audits in it records that session.

Types

type Entry

type Entry struct {
	Time      time.Time      `json:"time"`
	Session   string         `json:"session,omitempty"`
	Kind      string         `json:"kind"`
	Tool      string         `json:"tool,omitempty"`
	Args      map[string]any `json:"args,omitempty"`
	Detail    string         `json:"detail,omitempty"`
	Decision  string         `json:"decision,omitempty"`
	Error     string         `json:"error,omitempty"`
	Workspace string         `json:"workspace,omitempty"`
	// Agent is the agent whose action it was: on denials and failed tool
	// results only, which the harness's evidence blames agents with.
	Agent string `json:"agent,omitempty"`
}

Entry is one audit record.

func Read added in v0.8.3

func Read(dir, workspace string, since time.Time) []Entry

Read returns the entries in dir's daily files (audit-YYYY-MM-DD.jsonl) written since then, about workspace or no workspace in particular, in the order they were written. A missing dir or day is no entries.

type Logger

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

Logger appends entries to <dir>/audit-YYYY-MM-DD.jsonl, each on a line of its own after a torn one (jsonl.Append). A nil *Logger is a valid no-op, so callers never need to check whether auditing is enabled.

func Open

func Open(dir string, r *redact.Redactor) (*Logger, error)

Open creates the audit directory (owner-only) and returns a logger.

func (*Logger) Log

func (l *Logger) Log(e Entry)

Log appends an entry. Its first failure (an entry that can't be written as JSON, a file that can't be opened or written) is reported to stderr, and later ones aren't: auditing must never break the session.

func (*Logger) LogContext added in v0.8.3

func (l *Logger) LogContext(ctx context.Context, e Entry)

LogContext is Log, with the session of ctx's turn when e names none, and the agent of ctx on a denial or a failed result.

func (*Logger) SetWorkspace added in v0.8.3

func (l *Logger) SetWorkspace(workspace string)

SetWorkspace sets the workspace later entries record when they name none. The session is each entry's own (LogContext): a workspace runs turns of several sessions at once, so the logger has none.

Jump to

Keyboard shortcuts

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