audithook

package
v1.10.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package audithook bridges Cortex lifecycle events to an audit trail backend.

Index

Constants

View Source
const (
	SeverityInfo     = "info"
	SeverityWarning  = "warning"
	SeverityCritical = "critical"
)

Severity constants.

View Source
const (
	OutcomeSuccess = "success"
	OutcomeFailure = "failure"
)

Outcome constants.

View Source
const (
	ActionPublicationRejected    = "cortex.publication.rejected"
	ActionRunTerminated          = "cortex.agent.run.terminated"
	ActionRunStarted             = "cortex.agent.run.started"
	ActionRunCompleted           = "cortex.agent.run.completed"
	ActionRunFailed              = "cortex.agent.run.failed"
	ActionStepStarted            = "cortex.step.started"
	ActionStepCompleted          = "cortex.step.completed"
	ActionToolCalled             = "cortex.tool.called"
	ActionToolCompleted          = "cortex.tool.completed"
	ActionToolFailed             = "cortex.tool.failed"
	ActionPersonaResolved        = "cortex.persona.resolved"
	ActionSkillActivated         = "cortex.skill.activated"
	ActionBehaviorTriggered      = "cortex.behavior.triggered"
	ActionCognitivePhaseChanged  = "cortex.cognitive.phase_changed"
	ActionTraitApplied           = "cortex.trait.applied"
	ActionCheckpointCreated      = "cortex.checkpoint.created"
	ActionCheckpointResolved     = "cortex.checkpoint.resolved"
	ActionOrchestrationStarted   = "cortex.orchestration.started"
	ActionOrchestrationCompleted = "cortex.orchestration.completed"
	ActionAgentHandoff           = "cortex.agent.handoff"
)

Action constants.

View Source
const (
	ResourceAgent         = "agent"
	ResourceRun           = "run"
	ResourceTool          = "tool"
	ResourcePersona       = "persona"
	ResourceSkill         = "skill"
	ResourceBehavior      = "behavior"
	ResourceCheckpoint    = "checkpoint"
	ResourceOrchestration = "orchestration"
)

Resource constants.

View Source
const (
	CategoryAgent         = "agent"
	CategoryTool          = "tool"
	CategoryPersona       = "persona"
	CategoryCheckpoint    = "checkpoint"
	CategoryOrchestration = "orchestration"
)

Category constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditEvent

type AuditEvent struct {
	Action     string         `json:"action"`
	Resource   string         `json:"resource"`
	Category   string         `json:"category"`
	ResourceID string         `json:"resource_id,omitempty"`
	Metadata   map[string]any `json:"metadata,omitempty"`
	Outcome    string         `json:"outcome"`
	Severity   string         `json:"severity"`
	Reason     string         `json:"reason,omitempty"`
}

AuditEvent mirrors chronicle/audit.Event without a module dependency.

type Extension

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

Extension bridges Cortex lifecycle events to an audit trail backend.

func New

func New(r Recorder, opts ...Option) *Extension

New creates an Extension that emits audit events through the provided Recorder.

func (*Extension) Name

func (e *Extension) Name() string

Name implements plugin.Extension.

func (*Extension) OnBehaviorTriggered

func (e *Extension) OnBehaviorTriggered(ctx context.Context, runID id.AgentRunID, behaviorName string) error

func (*Extension) OnCheckpointCreated

func (e *Extension) OnCheckpointCreated(ctx context.Context, cpID id.CheckpointID, runID id.AgentRunID, reason string) error

func (*Extension) OnCheckpointResolved

func (e *Extension) OnCheckpointResolved(ctx context.Context, cpID id.CheckpointID, decision string) error

func (*Extension) OnPersonaResolved

func (e *Extension) OnPersonaResolved(ctx context.Context, agentID id.AgentID, personaName string) error

func (*Extension) OnPublicationRejected

func (e *Extension) OnPublicationRejected(ctx context.Context, agentID id.AgentID, runID id.AgentRunID, reason run.StopReason) error

OnPublicationRejected records a bounded rejection reason without raw content.

func (*Extension) OnRunCompleted

func (e *Extension) OnRunCompleted(ctx context.Context, agentID id.AgentID, runID id.AgentRunID, _ string, elapsed time.Duration) error

func (*Extension) OnRunFailed

func (e *Extension) OnRunFailed(ctx context.Context, agentID id.AgentID, runID id.AgentRunID, runErr error) error

func (*Extension) OnRunStarted

func (e *Extension) OnRunStarted(ctx context.Context, agentID id.AgentID, runID id.AgentRunID, input string) error

func (*Extension) OnRunTerminated

func (e *Extension) OnRunTerminated(ctx context.Context, agentID id.AgentID, runID id.AgentRunID, summary run.TerminalSummary) error

OnRunTerminated records execution and verification independently, without raw content.

func (*Extension) OnToolCalled

func (e *Extension) OnToolCalled(ctx context.Context, runID id.AgentRunID, toolName string, _ any) error

func (*Extension) OnToolCompleted

func (e *Extension) OnToolCompleted(ctx context.Context, runID id.AgentRunID, toolName, _ string, elapsed time.Duration) error

func (*Extension) OnToolFailed

func (e *Extension) OnToolFailed(ctx context.Context, runID id.AgentRunID, toolName string, toolErr error) error

type Option

type Option func(*Extension)

Option configures the audit hook Extension.

func WithActions

func WithActions(actions ...string) Option

WithActions limits which actions are recorded.

func WithLogger

func WithLogger(l log.Logger) Option

WithLogger sets a custom logger for the extension.

type Recorder

type Recorder interface {
	Record(ctx context.Context, event *AuditEvent) error
}

Recorder is the interface that audit backends must implement. Matches chronicle.Emitter but defined locally to avoid the import.

type RecorderFunc

type RecorderFunc func(ctx context.Context, event *AuditEvent) error

RecorderFunc is an adapter to use a plain function as a Recorder.

func (RecorderFunc) Record

func (f RecorderFunc) Record(ctx context.Context, event *AuditEvent) error

Jump to

Keyboard shortcuts

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