audit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package audit writes the append-only, hash-chained audit log.

Every action writes an intent line before it runs and a result line after, sharing one id. Lines go to <state>/audit/YYYY-MM.jsonl. Each line carries "prev", the sha256 of the previous line's bytes (across month files), so an edited or deleted line breaks the chain and ReadAll reports where.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mask

func Mask(s string) string

Mask hides tokens, bearer headers, key=value secrets, secret flags and URL credentials.

func MaskArgv

func MaskArgv(argv []string) []string

MaskArgv masks every word of a command, and the word after a secret flag such as --password.

func ReadAll

func ReadAll(dir string) ([]Record, Chain, error)

ReadAll returns every record, oldest first, and the chain check.

Types

type Chain

type Chain struct {
	OK       bool
	Lines    int
	BrokenAt string // "2026-10.jsonl:12" when not OK
}

Chain is the result of checking every line's prev against the line before.

type Entry

type Entry struct {
	TS         string         `json:"ts"`
	ID         string         `json:"id"`
	Phase      string         `json:"phase"` // intent | result | event
	Action     string         `json:"action"`
	Project    string         `json:"project,omitempty"`
	Remote     string         `json:"remote,omitempty"`
	Cwd        string         `json:"cwd,omitempty"`
	Argv       []string       `json:"argv,omitempty"`
	Trigger    string         `json:"trigger,omitempty"`
	Outcome    string         `json:"outcome,omitempty"` // ok | failed | cancelled
	ExitCode   *int           `json:"exit_code,omitempty"`
	DurationMS *int64         `json:"duration_ms,omitempty"`
	Details    map[string]any `json:"details,omitempty"`
	Error      string         `json:"error,omitempty"`
	AppVersion string         `json:"app_version"`
	Prev       string         `json:"prev"`
}

type Logger

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

func New

func New(stateDir, version string) (*Logger, error)

func (*Logger) Begin

func (l *Logger) Begin(e Entry) (*Op, error)

Begin writes the intent line. The returned Op must be ended with End.

func (*Logger) Dir

func (l *Logger) Dir() string

func (*Logger) Event

func (l *Logger) Event(e Entry) error

Event writes a single line for things with no separate result, such as a panel session starting.

type Op

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

Op is one audited action between its intent and result lines.

func (*Op) End

func (op *Op) End(outcome string, exitCode *int, details map[string]any, err error) error

End writes the result line for the op.

type Record

type Record struct {
	Entry
	File string
	Line int
}

Jump to

Keyboard shortcuts

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