Documentation
¶
Overview ¶
Package hooks orchestrates hook discovery, approval, and execution at the actions layer. The pure executor lives in internal/hooks; this package adds the interactive approval gate and the runner facade.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveApproved ¶
func ResolveApproved(req ResolveRequest) ([]string, error)
ResolveApproved filters Commands down to the list the user has approved for Phase, prompting for any unapproved entries. Empty input is handled cheaply: no config writes or prompts happen when commands is empty.
Must run from the main goroutine — it may prompt interactively.
func Run ¶
func Run(ctx context.Context, hookCmds []string, opts RunOptions) error
Run executes a pre-resolved list of hook commands with the shared executor. On Blocking=true the first failure returns immediately; on Blocking=false failures are logged to opts.Output and the remaining hooks still run.
Types ¶
type ResolveRequest ¶
type ResolveRequest struct {
// Phase is the lifecycle phase the hooks belong to (e.g. "pre-modify").
Phase string
// Commands is the configured hook command list for the phase. Empty
// strings are ignored.
Commands []string
// Config provides the approval read/write store. The same Configurer
// already loaded by app bootstrap is expected here — no extra disk read.
Config config.Configurer
// Prompter is used to ask the user about previously-unseen commands.
// Implementations decide whether the prompt defaults to yes or no.
Prompter handler.PromptHandler
// Output sinks user-facing skip/warn messages. nil is permitted.
Output output.Output
// Required makes unapproved hooks fail closed. Use this for blocking
// pre-command hooks: if the approval prompt fails or the user declines,
// the caller should abort rather than silently skipping the hook.
Required bool
}
ResolveRequest carries the explicit dependencies needed to gate a list of hook commands behind per-user approval. All fields are required except Output, which may be nil to silence informational messages.
type RunOptions ¶
type RunOptions struct {
// Dir is the working directory for each hook process. Defaults to the
// caller's cwd if empty.
Dir string
// Env is a list of NAME=value strings appended to os.Environ() for each
// hook invocation. nil is allowed.
Env []string
// Blocking, when true, causes the first non-zero exit to abort the rest
// and return the error to the caller. When false, errors are surfaced as
// warnings on Output and execution continues.
Blocking bool
// Output sinks per-hook progress and warning messages. nil is permitted
// but discouraged — failures become silent on the non-blocking path.
Output output.Output
}
RunOptions controls how a list of resolved hooks is executed.