Documentation
¶
Overview ¶
Package audit defines a best-effort, non-blocking audit sink. An Auditor records every tool call (who/when/what/result) for compliance. The async implementation drops events under backpressure and counts them rather than ever blocking or failing the main business flow (invariant I12).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrSinkClosed = errors.New("audit: sink closed")
ErrSinkClosed is returned by Record on a closed AsyncAuditor.
Functions ¶
func RedactInput ¶
func RedactInput(input json.RawMessage, sensitive map[string]bool) json.RawMessage
RedactInput removes values for configured sensitive fields and hashes transaction handles before tool input is queued for persistence.
Types ¶
type AsyncAuditor ¶
type AsyncAuditor struct {
// contains filtered or unexported fields
}
AsyncAuditor pushes events to a bounded queue drained by a background flusher. On overflow it drops and counts (atomic) instead of blocking.
func NewAsyncAuditor ¶
func NewAsyncAuditor(sink Sink, queueSize int) *AsyncAuditor
NewAsyncAuditor starts a flusher goroutine. Call Close to drain and stop.
func NewAsyncAuditorWithClose ¶
func NewAsyncAuditorWithClose(sink Sink, closeSink func() error, queueSize int) *AsyncAuditor
NewAsyncAuditorWithClose starts an auditor and closes the sink after draining.
func (*AsyncAuditor) Close ¶
func (a *AsyncAuditor) Close()
Close stops accepting events and waits for the flusher to drain the queue.
func (*AsyncAuditor) Dropped ¶
func (a *AsyncAuditor) Dropped() int64
Dropped returns the count of events dropped due to a full queue.
type Event ¶
type Event struct {
Time time.Time
DecisionID string
Role string
Entity string
Action string
Tool string
Input json.RawMessage
ResultSummary string
Cost *cost.Plan
Allowed bool
Error string
Duration time.Duration
ReturnedRows int64
}
Event records one tool invocation for compliance. DecisionID correlates the event with the MCP response and trace span of the same call.
type FileSink ¶
type FileSink struct {
// contains filtered or unexported fields
}
FileSink is a long-lived JSON-lines audit sink.
func OpenFileSink ¶
OpenFileSink opens path with owner-only permissions.