hook

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedEvent = errors.New("unsupported hook event")

ErrUnsupportedEvent is returned when a hook asset's canonical event is not supported by the target client. Callers (typically a client's InstallAssets implementation) use errors.Is to distinguish this from real install failures and surface the result as StatusSkipped rather than StatusFailed.

This is not a user error: the asset is well-formed and the user's configuration is correct; the target client simply has no lifecycle event to fire it from. For example, Gemini Code Assist does not implement `pre-compact` or `subagent-start`, so log hooks for those events are soft-skipped on Gemini and installed as usual on Claude Code.

Functions

func CacheZipFiles

func CacheZipFiles(zipData []byte) []string

CacheZipFiles returns the list of file paths in the zip for later path resolution. Returns nil on error.

func ContainsFile

func ContainsFile(files []string, name string) bool

ContainsFile checks if a filename exists in the file list. It checks both exact match and filepath.Base fallback.

func HasExtractableFiles

func HasExtractableFiles(zipData []byte) bool

HasExtractableFiles returns true if the zip contains files beyond metadata.toml.

func IsZipFile

func IsZipFile(zipFiles []string, arg string) bool

IsZipFile returns true if the given arg matches a file path in the cached zip file list.

func MapEvent

func MapEvent(event string, eventMap map[string]string, clientOverrides map[string]any) (string, bool)

MapEvent maps a canonical hook event name to a client-native event name. It first checks the client-specific override map, then falls back to the standard eventMap. Returns the native event name and whether the event is supported.

func UnsupportedEventError added in v0.16.2

func UnsupportedEventError(clientName, event string) error

UnsupportedEventError builds an error that wraps ErrUnsupportedEvent with the client and event captured as structured fields. Callers detect it via errors.Is(err, ErrUnsupportedEvent), and extract the fields via:

var ue *UnsupportedEventDetails
if errors.As(err, &ue) { ... ue.Client, ue.Event ... }

func ValidateZipForHook

func ValidateZipForHook(zipData []byte) error

ValidateZipForHook performs full validation of a zip archive for a hook asset. It checks that metadata.toml exists, parses it, validates the asset type, verifies the hook section, and checks that any referenced script file exists.

Types

type ResolvedCommand

type ResolvedCommand struct {
	Command string
}

ResolvedCommand holds the result of resolving a hook's command configuration to an absolute command string ready for installation.

func ResolveCommand

func ResolveCommand(hookCfg *metadata.HookConfig, installDir string, zipFiles []string) ResolvedCommand

ResolveCommand resolves a hook's script-file or command+args configuration into an absolute command string. For script-file mode, it returns the absolute path to the script. For command mode, it joins the command with args, resolving any args that match zip files to absolute paths.

type UnsupportedEventDetails added in v0.16.2

type UnsupportedEventDetails = unsupportedEventErr

UnsupportedEventDetails is the public alias for the concrete type used with errors.As to recover the (Client, Event) pair from an UnsupportedEventError.

Jump to

Keyboard shortcuts

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