Documentation
¶
Index ¶
- func FormatList(config Config, diagnostics []Diagnostic) string
- func IsValidEvent(event Event) bool
- func WriteConfig(path string, config Config) error
- type AppendCompletedInput
- type AppendStartedInput
- type AuditCommand
- type AuditEvent
- type AuditResult
- type AuditStatus
- type AuditStore
- type AuditStoreOptions
- type Command
- type Config
- type ConfigSource
- type ConfigStore
- type Definition
- type Diagnostic
- type DiagnosticKind
- type DispatchInput
- type DispatchOutcome
- type Dispatcher
- type DispatcherOptions
- type Event
- type LoadOptions
- type LoadResult
- type Paths
- type ResolvePathOptions
- type SelectInput
- type StoreOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatList ¶
func FormatList(config Config, diagnostics []Diagnostic) string
func IsValidEvent ¶
IsValidEvent reports whether event is one Zero recognizes.
func WriteConfig ¶
Types ¶
type AppendCompletedInput ¶
type AppendCompletedInput struct {
HookID string
Event Event
Matcher string
ToolCallID string
Status AuditStatus
Results []AuditResult
DurationMs int
}
type AppendStartedInput ¶
type AppendStartedInput struct {
HookID string
Event Event
Matcher string
ToolCallID string
Commands []AuditCommand
}
type AuditCommand ¶
type AuditCommand = Command
type AuditEvent ¶
type AuditEvent struct {
Sequence int `json:"sequence"`
CreatedAt string `json:"createdAt"`
Type string `json:"type"`
HookID string `json:"hookId"`
Event Event `json:"event"`
Matcher string `json:"matcher,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
Commands []AuditCommand `json:"commands,omitempty"`
Status AuditStatus `json:"status,omitempty"`
Results []AuditResult `json:"results,omitempty"`
DurationMs int `json:"durationMs,omitempty"`
}
type AuditResult ¶
type AuditStatus ¶
type AuditStatus string
const ( AuditCompleted AuditStatus = "completed" AuditError AuditStatus = "error" AuditBlocked AuditStatus = "blocked" )
type AuditStore ¶
type AuditStore struct {
// contains filtered or unexported fields
}
func NewAuditStore ¶
func NewAuditStore(options AuditStoreOptions) (*AuditStore, error)
func (*AuditStore) AppendCompleted ¶
func (store *AuditStore) AppendCompleted(input AppendCompletedInput) (AuditEvent, error)
func (*AuditStore) AppendStarted ¶
func (store *AuditStore) AppendStarted(input AppendStartedInput) (AuditEvent, error)
func (*AuditStore) ReadEvents ¶
func (store *AuditStore) ReadEvents() ([]AuditEvent, error)
ReadEvents deliberately does not acquire store.mu. append holds store.mu while writing a single O_APPEND JSONL record, and lock-free readers may miss or skip an in-progress append while still avoiding deadlocks with append's read step.
type AuditStoreOptions ¶
type Config ¶
type Config struct {
Enabled bool `json:"enabled"`
Hooks []Definition `json:"hooks"`
}
type ConfigSource ¶
type ConfigSource string
const ( SourceUser ConfigSource = "user" SourceProject ConfigSource = "project" )
type ConfigStore ¶
type ConfigStore struct {
// contains filtered or unexported fields
}
func NewConfigStore ¶
func NewConfigStore(options StoreOptions) (*ConfigStore, error)
func (*ConfigStore) List ¶
func (store *ConfigStore) List() (Config, error)
func (*ConfigStore) SetEnabled ¶
func (store *ConfigStore) SetEnabled(hookID string, enabled bool) (bool, error)
func (*ConfigStore) Upsert ¶
func (store *ConfigStore) Upsert(hook Definition) (Definition, error)
type Definition ¶
type Definition struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Event Event `json:"event"`
Matcher string `json:"matcher,omitempty"`
Command string `json:"command"`
Args []string `json:"args"`
Enabled bool `json:"enabled"`
}
func Select ¶
func Select(config Config, input SelectInput) []Definition
type Diagnostic ¶
type Diagnostic struct {
Kind DiagnosticKind `json:"kind"`
Message string `json:"message"`
Source ConfigSource `json:"source,omitempty"`
Path string `json:"path,omitempty"`
HookID string `json:"hookId,omitempty"`
FieldPath string `json:"fieldPath,omitempty"`
}
type DiagnosticKind ¶
type DiagnosticKind string
const ( DiagnosticIO DiagnosticKind = "io" DiagnosticJSON DiagnosticKind = "json" DiagnosticSchema DiagnosticKind = "schema" DiagnosticDuplicate DiagnosticKind = "duplicate" )
type DispatchInput ¶
type DispatchInput struct {
Event Event
ToolName string // for beforeTool/afterTool matching
ToolCallID string
// Payload is serialized to JSON and written to each hook command's stdin so a
// hook can inspect the tool call, its result, or session context.
Payload any
}
DispatchInput describes one lifecycle point at which hooks may run.
type DispatchOutcome ¶
type DispatchOutcome struct {
Ran int // hooks that executed
Blocked bool // a blocking-event hook exited non-zero, vetoing the action
BlockedBy string // ID of the hook that blocked (empty unless Blocked)
Reason string // the blocking hook's stderr/stdout, for surfacing to the model
// Messages collects the output (stdout, else stderr) of each hook that
// produced any, in run order. afterTool validators use this to feed results
// (e.g. a formatter diff or vet warning) back to the model on the tool result.
Messages []string
}
DispatchOutcome reports what happened for one Dispatch call.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher selects and runs the hooks configured for a lifecycle event, recording each run to the audit store. A beforeTool hook that exits non-zero blocks the tool; hooks for other events are advisory (failures are recorded but do not interrupt the run).
func NewDispatcher ¶
func NewDispatcher(options DispatcherOptions) *Dispatcher
NewDispatcher builds a Dispatcher. A zero/empty config yields a dispatcher that runs nothing, so callers can always construct one unconditionally.
func (*Dispatcher) Dispatch ¶
func (dispatcher *Dispatcher) Dispatch(ctx context.Context, input DispatchInput) DispatchOutcome
Dispatch runs every enabled hook configured for the input event (and matcher, for tool events). It returns once all hooks have run, or early if a blocking hook vetoes the action.
type DispatcherOptions ¶
type DispatcherOptions struct {
Config Config
Audit *AuditStore // optional; when set, every run is recorded
Cwd string // working directory for hook commands
Env []string // extra environment entries appended to the process env
Timeout time.Duration // per-command timeout (defaults to defaultHookTimeout)
// contains filtered or unexported fields
}
DispatcherOptions configures a Dispatcher.
type Event ¶
type Event string
func KnownEvents ¶
func KnownEvents() []Event
KnownEvents returns the hook events Zero recognizes, in dispatch order.
type LoadOptions ¶
type LoadResult ¶
type LoadResult struct {
Config Config `json:"config"`
Diagnostics []Diagnostic `json:"diagnostics"`
Paths Paths `json:"paths"`
}
func LoadConfig ¶
func LoadConfig(options LoadOptions) (LoadResult, error)
type Paths ¶
type Paths struct {
UserConfigPath string `json:"userConfigPath"`
ProjectConfigPath string `json:"projectConfigPath"`
AuditPath string `json:"auditPath"`
}
func ResolvePaths ¶
func ResolvePaths(options ResolvePathOptions) (Paths, error)
type ResolvePathOptions ¶
type SelectInput ¶
type StoreOptions ¶
type StoreOptions struct {
ConfigPath string
}