Documentation
¶
Index ¶
Constants ¶
const ( SessionStart = "SessionStart" UserPromptSubmit = "UserPromptSubmit" PreToolUse = "PreToolUse" PostToolUse = "PostToolUse" PostToolUseFailure = "PostToolUseFailure" PreCompact = "PreCompact" PostCompact = "PostCompact" Stop = "Stop" SessionEnd = "SessionEnd" )
Event names. config.HookEvents lists the same set for validation.
const MaxAdditionalContext = 10 << 10
MaxAdditionalContext bounds the additionalContext text one event delivers to the model, summed over its hooks.
const MaxEnvPayload = 64 << 10
MaxEnvPayload bounds the event JSON copied into K_BRAIN_HOOK_EVENT. Systems cap a single environment string (Linux at 128 KiB), and an oversized one makes the hook fail to start; stdin always carries the full event.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DeniedError ¶ added in v0.107.13
type DeniedError struct {
Reason string
}
DeniedError is a PreToolUse hook's structured refusal: it exited 0 and printed {"decision":"deny","reason":"..."} as its output or as the last output line.
func (*DeniedError) Error ¶ added in v0.107.13
func (e *DeniedError) Error() string
type Event ¶
type Event struct {
Name string `json:"event"`
SessionID string `json:"sessionId,omitempty"`
CWD string `json:"cwd,omitempty"`
Prompt string `json:"prompt,omitempty"`
ToolID string `json:"toolId,omitempty"`
ToolName string `json:"toolName,omitempty"`
ToolArgs string `json:"toolArgs,omitempty"`
ToolResult string `json:"toolResult,omitempty"`
// Trigger is "auto" or "manual" for PreCompact and PostCompact.
Trigger string `json:"trigger,omitempty"`
// MessagesBefore and TokensBefore describe the context PreCompact and
// PostCompact compact; MessagesAfter and TokensAfter the result (PostCompact).
// Tokens are the agent's estimate.
MessagesBefore int `json:"messagesBefore,omitempty"`
TokensBefore int `json:"tokensBefore,omitempty"`
MessagesAfter int `json:"messagesAfter,omitempty"`
TokensAfter int `json:"tokensAfter,omitempty"`
// Summary is the new compaction summary (PostCompact).
Summary string `json:"summary,omitempty"`
// Reason says why a session ended (SessionEnd): "exit", "close" or "switch".
Reason string `json:"reason,omitempty"`
// StopHookActive is set on a Stop event when an earlier Stop hook of the
// same turn blocked the stop and the agent is continuing because of it.
StopHookActive bool `json:"stopHookActive,omitempty"`
}
type Outcome ¶ added in v0.107.40
type Outcome struct {
// Block is set when a Stop hook replied {"decision":"block"}; Reason is its
// reason. Hooks after the blocking one do not run.
Block bool
Reason string
// AdditionalContext joins the additionalContext replies of UserPromptSubmit,
// PostToolUse and PostToolUseFailure hooks, in order, capped at
// MaxAdditionalContext bytes.
AdditionalContext string
}
Outcome is what the hooks of one event asked for beyond success or failure.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
func (*Runner) RunOutcome ¶ added in v0.107.40
RunOutcome runs the hooks configured for event in order, stopping at the first failure, PreToolUse denial or Stop block. The outcome collected up to that point is returned with the error.