Documentation
¶
Index ¶
- Constants
- Variables
- func EventCatalog() []string
- func RuntimeSupported(event string) bool
- type ActionResult
- type Condition
- type Config
- type Defaults
- type Hook
- type HookAction
- type OutputWarning
- type Request
- type Result
- type Service
- func (s *Service) Load(ctx context.Context, botID string) (Config, bool, error)
- func (s *Service) LoadEffective(ctx context.Context, botID string) (Config, bool, error)
- func (s *Service) Run(ctx context.Context, req Request, runner ToolRunner) (Result, error)
- func (s *Service) RunConfig(ctx context.Context, cfg Config, req Request, runner ToolRunner) (Result, error)
- type SystemSectionCache
- type SystemSectionOutput
- type SystemSectionRetention
- type ToolPayload
- type ToolRunner
- type WorkspaceInfo
Constants ¶
View Source
const ( DefaultConfigPath = "/data/.memoh/hooks.json" DefaultWorkDir = "/data" EventPreToolUse = "PreToolUse" EventPostToolUse = "PostToolUse" EventToolError = "ToolError" EventSessionStart = "SessionStart" EventUserMessageReceived = "UserMessageReceived" EventBeforePromptBuild = "BeforePromptBuild" EventAfterPromptBuild = "AfterPromptBuild" EventBeforeModelCall = "BeforeModelCall" EventAfterModelCall = "AfterModelCall" EventTurnEnd = "TurnEnd" EventTurnError = "TurnError" EventBeforeMemorySearch = "BeforeMemorySearch" EventAfterMemorySearch = "AfterMemorySearch" EventBeforeMemoryWrite = "BeforeMemoryWrite" EventAfterMemoryWrite = "AfterMemoryWrite" EventMemoryExtracted = "MemoryExtracted" EventWorkspaceStart = "WorkspaceStart" EventWorkspaceStop = "WorkspaceStop" EventBeforeWorkspaceCommand = "BeforeWorkspaceCommand" EventAfterWorkspaceCommand = "AfterWorkspaceCommand" EventBeforeFileWrite = "BeforeFileWrite" EventAfterFileWrite = "AfterFileWrite" EventBeforeApprovalCreate = "BeforeApprovalCreate" EventApprovalRequested = "ApprovalRequested" EventApprovalResolved = "ApprovalResolved" EventApprovalTimeout = "ApprovalTimeout" EventInboundMessageNormalized = "InboundMessageNormalized" EventBeforeOutboundMessage = "BeforeOutboundMessage" EventAfterOutboundMessage = "AfterOutboundMessage" EventChannelDeliveryFailed = "ChannelDeliveryFailed" EventPreCompact = "PreCompact" EventPostCompact = "PostCompact" EventSubagentStart = "SubagentStart" EventSubagentStop = "SubagentStop" )
View Source
const ( ActionCommand = "command" ActionTool = "tool" ActionMCPTool = "mcp_tool" )
View Source
const ( DecisionAllow = "allow" DecisionDeny = "deny" DecisionAskApproval = "ask_approval" DecisionAppendContext = "append_context" )
View Source
const ( WarningInvalidAppendSystemSection = "invalid_append_system_section" WarningAppendSystemSectionOutputLimited = "hook_system_section_output_limited" WarningSystemSectionRequiredClamped = "hook_system_section_required_clamped" )
View Source
const ( OnErrorIgnore = "ignore" OnErrorFail = "fail" OnErrorBlock = "block" )
Variables ¶
View Source
var ( ErrDenied = errors.New("hook denied action") ErrUnsupported = errors.New("unsupported hook action") )
Functions ¶
func EventCatalog ¶
func EventCatalog() []string
func RuntimeSupported ¶
Types ¶
type ActionResult ¶
type ActionResult struct {
ActionType string `json:"action_type,omitempty"`
Name string `json:"name,omitempty"`
Decision string `json:"decision,omitempty"`
Reason string `json:"reason,omitempty"`
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
ExitCode int32 `json:"exit_code,omitempty"`
Result any `json:"result,omitempty"`
AppendSystemSections []SystemSectionOutput `json:"append_system_sections,omitempty"`
Warnings []OutputWarning `json:"warnings,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Error string `json:"error,omitempty"`
// contains filtered or unexported fields
}
type Config ¶
type Config struct {
Version int `json:"version"`
Enabled *bool `json:"enabled,omitempty"`
Defaults Defaults `json:"defaults,omitempty"`
Env map[string]string `json:"env,omitempty"`
Hooks []Hook `json:"hooks,omitempty"`
}
func ParseConfig ¶
type Hook ¶
type Hook struct {
Name string `json:"name,omitempty"`
Event string `json:"event"`
Matcher string `json:"matcher,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Priority int `json:"priority,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
Actions []HookAction `json:"actions,omitempty"`
// contains filtered or unexported fields
}
type HookAction ¶
type HookAction struct {
Type string `json:"type"`
Command string `json:"command,omitempty"`
Tool string `json:"tool,omitempty"`
Server string `json:"server,omitempty"`
Input map[string]any `json:"input,omitempty"`
Timeout string `json:"timeout,omitempty"`
OnError string `json:"on_error,omitempty"`
WorkDir string `json:"work_dir,omitempty"`
TriggerNestedHooks *bool `json:"trigger_nested_hooks,omitempty"`
}
type OutputWarning ¶
type Request ¶
type Request struct {
Version int `json:"version"`
Event string `json:"event"`
HookName string `json:"hook_name,omitempty"`
BotID string `json:"bot_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
ChatID string `json:"chat_id,omitempty"`
Workspace WorkspaceInfo `json:"workspace,omitempty"`
Tool *ToolPayload `json:"tool,omitempty"`
Approval map[string]any `json:"approval,omitempty"`
Turn map[string]any `json:"turn,omitempty"`
Memory map[string]any `json:"memory,omitempty"`
Channel map[string]any `json:"channel,omitempty"`
Extra map[string]any `json:"extra,omitempty"`
Error string `json:"error,omitempty"`
}
type Result ¶
type Result struct {
Decision string `json:"decision,omitempty"`
Reason string `json:"reason,omitempty"`
AppendContext string `json:"append_context,omitempty"`
AppendSystemSections []SystemSectionOutput `json:"append_system_sections,omitempty"`
Warnings []OutputWarning `json:"warnings,omitempty"`
HooksMatched int `json:"hooks_matched"`
ActionsRun int `json:"actions_run"`
RuntimeSupported bool `json:"runtime_supported"`
ActionResults []ActionResult `json:"action_results,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
// contains filtered or unexported fields
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) LoadEffective ¶
type SystemSectionCache ¶
type SystemSectionCache string
const ( SystemSectionCacheDynamic SystemSectionCache = "dynamic" SystemSectionCacheStable SystemSectionCache = "stable" )
type SystemSectionOutput ¶
type SystemSectionOutput struct {
HookName string `json:"hook_name,omitempty"`
ID string `json:"id,omitempty"`
Text string `json:"text"`
Retention SystemSectionRetention `json:"retention"`
Cache SystemSectionCache `json:"cache"`
WarningCodes []string `json:"-"`
// contains filtered or unexported fields
}
type SystemSectionRetention ¶
type SystemSectionRetention string
const ( SystemSectionRetentionOptional SystemSectionRetention = "optional" SystemSectionRetentionPreferred SystemSectionRetention = "preferred" )
type ToolPayload ¶
type ToolRunner ¶
type WorkspaceInfo ¶
Click to show internal directories.
Click to hide internal directories.