hookruntime

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeClaudeResult

func EncodeClaudeResult(hookEventName string, result Result) ([]byte, error)

func MarshalMap

func MarshalMap(value map[string]any) (json.RawMessage, error)

func Run

func Run(stdin io.Reader, stdout, stderr io.Writer, codec Codec, sink Sink) int

Types

type ClaudeHookInput

type ClaudeHookInput struct {
	SessionID        string         `json:"session_id"`
	SessionIDAlt     string         `json:"sessionId"`
	HookEventName    string         `json:"hook_event_name"`
	HookEventNameAlt string         `json:"hookEventName"`
	HookEventLegacy  string         `json:"hook_event"`
	ToolName         string         `json:"tool_name"`
	ToolNameAlt      string         `json:"toolName"`
	ToolInput        map[string]any `json:"tool_input"`
	ToolInputAlt     map[string]any `json:"toolInput"`
	ToolResponse     map[string]any `json:"tool_response"`
	ToolResponseAlt  map[string]any `json:"toolResponse"`
	ToolUseID        string         `json:"tool_use_id"`
	ToolUseIDAlt     string         `json:"toolUseId"`
	ToolUseIDUpper   string         `json:"toolUseID"`
	CWD              string         `json:"cwd"`
	PermissionMode   *string        `json:"permission_mode"`
	DurationMs       *int64         `json:"duration_ms"`
	Error            *string        `json:"error"`
	IsInterrupt      *bool          `json:"is_interrupt"`
}

type Codec

type Codec interface {
	DecodeHookEvent([]byte) (Event, error)
	EncodeHookResult(Event, Result) ([]byte, error)
}

type Decision

type Decision string
const (
	DecisionAllow Decision = "ALLOW"
	DecisionAsk   Decision = "ASK"
	DecisionDeny  Decision = "DENY"
)

type Event

type Event struct {
	SessionID      string
	Agent          string
	HookEventName  string
	ToolName       string
	ToolInput      map[string]any
	ToolResponse   map[string]any
	ToolUseID      string
	CWD            string
	PermissionMode string
	DurationMs     *int64
	Error          string
	IsInterrupt    *bool
}

func DecodeClaudeEvent

func DecodeClaudeEvent(input []byte, agentName string) (Event, error)

func EventFromAgent

func EventFromAgent(agentName string, event *agent.HookEvent) Event

type Result

type Result struct {
	Decision     Decision
	Reason       string
	ReasonCode   string
	RequestID    string
	Mode         string
	Epoch        string
	UpdatedInput map[string]any
}

func ResultFromBool

func ResultFromBool(allowed bool, reason string) Result

func (Result) Allowed

func (r Result) Allowed() bool

func (Result) ClaudeReason

func (r Result) ClaudeReason() string

type Sink

type Sink interface {
	ProcessHookEvent(Event) (Result, error)
}

type SinkFunc

type SinkFunc func(Event) (Result, error)

func (SinkFunc) ProcessHookEvent

func (f SinkFunc) ProcessHookEvent(event Event) (Result, error)

Jump to

Keyboard shortcuts

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