Documentation
¶
Overview ¶
Package hooks charge, filtre et exécute les hooks utilisateur, au format compatible avec les hooks de Claude Code.
Index ¶
- Constants
- func BuildPrompt(tmpl string, input []byte) string
- func ClaudeName(tenon string) string
- func FromClaude(tenon string, in json.RawMessage) (json.RawMessage, error)
- func Load(o Options) (*Set, []Notice, error)
- func ParseVerdict(text string) (ok bool, reason string, err error)
- func ToClaude(tenon string, args json.RawMessage) json.RawMessage
- type Env
- type Evaluator
- type Event
- type Hook
- type Notice
- type Options
- type Outcome
- type Result
- type Set
- type Source
- type Status
- type Type
Constants ¶
const ( // MaxHooks borne le nombre total de hooks chargés. MaxHooks = 200 // MaxFileBytes borne la taille d'un fichier de hooks (1 MiB). MaxFileBytes = 1 << 20 )
Variables ¶
This section is empty.
Functions ¶
func BuildPrompt ¶
BuildPrompt remplace $ARGUMENTS par input ; absent, input est ajouté après une ligne vide.
func ClaudeName ¶
ClaudeName renvoie le nom Claude Code de l'outil tenon, ou le nom inchangé.
func FromClaude ¶
func FromClaude(tenon string, in json.RawMessage) (json.RawMessage, error)
FromClaude traduit des arguments au format Claude Code (updatedInput d'un hook) vers le format de l'outil tenon. in doit être un objet JSON.
func Load ¶
Load lit les fichiers de hooks utilisateur. Une erreur de fichier utilisateur est fatale (fail closed) ; les fichiers projet ne produisent que des notices.
func ParseVerdict ¶
ParseVerdict lit le verdict {"ok": bool, "reason": string} du premier « { » au dernier « } ».
func ToClaude ¶
func ToClaude(tenon string, args json.RawMessage) json.RawMessage
ToClaude traduit les arguments d'un outil tenon vers le format Claude Code. Des arguments qui ne sont pas un objet JSON sont renvoyés inchangés.
Types ¶
type Env ¶
type Env struct {
SessionID, TranscriptPath, ProjectRoot string
}
Env regroupe le contexte d'exécution commun à tous les hooks.
type Evaluator ¶
type Evaluator interface {
Evaluate(ctx context.Context, h Hook, prompt string) (text string, err error)
}
Evaluator exécute les hooks prompt et agent : il renvoie le texte du modèle.
type Event ¶
type Event string
Event est le nom d'un événement de hook.
const ( PreToolUse Event = "PreToolUse" PostToolUse Event = "PostToolUse" UserPromptSubmit Event = "UserPromptSubmit" Stop Event = "Stop" SubagentStop Event = "SubagentStop" SessionStart Event = "SessionStart" SessionEnd Event = "SessionEnd" PreCompact Event = "PreCompact" Notification Event = "Notification" )
type Hook ¶
type Hook struct {
ID string // <source>:<event>:<i>.<j>
Source Source
Event Event
Matcher string
Type Type
Command string
Prompt string
Model string
Timeout time.Duration
// contains filtered or unexported fields
}
Hook est un hook compilé et validé.
type Outcome ¶
type Outcome struct {
Results []Result
Block bool
Ask bool
Allow bool
Reason string
Context string
StopReason string
// UpdatedInput : valeur unique demandée par les hooks ; nil en cas de conflit.
UpdatedInput json.RawMessage
Conflict bool
Stop bool
}
Outcome est le résultat combiné d'un point de hook. Après combinaison, au plus un de Block, Ask, Allow est vrai.
type Result ¶
type Result struct {
Hook Hook
Status Status
ExitCode int // -1 si ce n'est pas un hook command (ou lancement impossible)
// Decision : "", "allow", "ask", "deny" ou "block".
Decision string
Reason string
Context string
SystemMessage string
StopReason string
Stdout string
Stderr string
Err string
UpdatedInput json.RawMessage // format Claude, non traduit
Stop bool
Duration time.Duration
}
Result est le résultat d'un hook.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set est l'ensemble des hooks chargés, dans l'ordre de configuration.