audit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package audit writes a tamper-evident JSONL audit log. Every record embeds the SHA-256 of the previous record, forming a hash chain: editing or deleting any line breaks verification of every line after it.

Index

Constants

View Source
const (
	// PhaseIntent is written before a mutating command runs, so an executed
	// action can never be missing from the log.
	PhaseIntent = "intent"
	// PhaseOutcome carries the result of the command.
	PhaseOutcome = "outcome"
)

Phase distinguishes the two records a state-changing call produces.

Variables

This section is empty.

Functions

func SumOutput

func SumOutput(out []byte) string

SumOutput returns the SHA-256 hex digest of tool output for the log.

func Verify

func Verify(path string) (int, error)

Verify walks a JSONL audit file and checks the hash chain. It returns the number of valid records, or an error naming the first broken line.

Types

type Logger

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

Logger appends records to a JSONL file.

func Open

func Open(path string, redactKeys []string) (*Logger, error)

Open creates (or resumes) the audit log at path.

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Log

func (l *Logger) Log(r Record) error

Log writes one record, filling seq, hashes, and redacting sensitive args.

type Record

type Record struct {
	Seq  int64     `json:"seq"`
	Time time.Time `json:"time"`
	Host string    `json:"host"`
	Tool string    `json:"tool"`
	// Phase is PhaseIntent or PhaseOutcome for mutating calls, empty for
	// read-only calls and refusals, which produce a single record.
	Phase      string         `json:"phase,omitempty"`
	Args       map[string]any `json:"args,omitempty"`
	Decision   string         `json:"decision"`
	Approved   *bool          `json:"approved,omitempty"`
	ExitCode   int            `json:"exit_code"`
	DurationMS int64          `json:"duration_ms"`
	OutputSHA  string         `json:"output_sha256,omitempty"`
	OutputLen  int            `json:"output_len"`
	Err        string         `json:"error,omitempty"`
	PrevHash   string         `json:"prev_hash"`
	Hash       string         `json:"hash"`
}

Record is one audited tool call.

Jump to

Keyboard shortcuts

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