hooks

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package hooks executes user-defined shell commands before and after tasks and plans. Commands run via "sh -c" with task context passed as environment variables. Hook values prefixed with "plugin:<name>" invoke a discovered plugin instead of a raw shell command.

Index

Constants

View Source
const DefaultTimeout = 10 * time.Minute

DefaultTimeout is the maximum wall-clock duration any hook (or plugin invoked from a hook) may run before it is killed. A misbehaving hook (e.g. one that blocks on stdin or loops forever) would otherwise stall plan execution indefinitely. Callers may override per-config via Config.Timeout. Setting Config.Timeout to a negative duration disables the timeout entirely.

Variables

This section is empty.

Functions

func ParseTimeout

func ParseTimeout(s string) (time.Duration, error)

ParseTimeout converts a config-string timeout (e.g. "30s", "5m") into a time.Duration suitable for Config.Timeout. Empty input maps to 0, which the runner interprets as DefaultTimeout. A parse error is returned to the caller so misconfigured YAML is surfaced rather than silently swallowed.

func RunPostPlan

func RunPostPlan(cfg Config, plan PlanContext, extraEnv ...string) error

RunPostPlan executes cfg.PostPlan. Errors are returned but do not abort anything. Returns nil immediately if cfg.PostPlan is empty. extraEnv is an optional list of KEY=value strings injected into the subprocess env.

func RunPostTask

func RunPostTask(cfg Config, task TaskContext, extraEnv ...string) error

RunPostTask executes cfg.PostTask. Errors are returned but callers typically only log them — post-task failures do not affect task status. Returns nil immediately if cfg.PostTask is empty. extraEnv is an optional list of KEY=value strings injected into the subprocess env.

func RunPrePlan

func RunPrePlan(cfg Config, plan PlanContext, extraEnv ...string) error

RunPrePlan executes cfg.PrePlan. Returns a non-nil error if the command exits non-zero; callers should abort plan execution in that case. Returns nil immediately if cfg.PrePlan is empty. extraEnv is an optional list of KEY=value strings injected into the subprocess env.

func RunPreTask

func RunPreTask(cfg Config, task TaskContext, extraEnv ...string) error

RunPreTask executes cfg.PreTask with the task's env vars set. Returns a non-nil error (with message) if the command exits non-zero; callers should skip the task when this happens. Returns nil immediately if cfg.PreTask is empty. extraEnv is an optional list of KEY=value strings (e.g. from cloop env vars) that are added to the subprocess environment alongside task context vars.

Types

type Config

type Config struct {
	// PreTask runs before each task starts. Exit non-zero skips the task.
	PreTask string `yaml:"pre_task,omitempty"`
	// PostTask runs after each task completes (regardless of outcome).
	PostTask string `yaml:"post_task,omitempty"`
	// PrePlan runs once before plan execution begins.
	PrePlan string `yaml:"pre_plan,omitempty"`
	// PostPlan runs once after the plan finishes (all tasks done/failed/skipped).
	PostPlan string `yaml:"post_plan,omitempty"`
	// PostTaskReview enables AI code review annotations after each successful task.
	// When true, the orchestrator runs git diff HEAD~1 after TASK_DONE and calls
	// the provider for a correctness/security/style review stored as a task annotation.
	PostTaskReview bool `yaml:"post_task_review,omitempty"`
	// Timeout caps the wall-clock duration of each hook invocation. Zero falls
	// back to DefaultTimeout. A negative value disables the timeout (use only
	// for hooks that legitimately run longer than 10 minutes).
	Timeout time.Duration `yaml:"-"`
}

Config holds the shell commands to run at lifecycle events. All fields are optional; an empty string disables the hook.

type PlanContext

type PlanContext struct {
	Goal    string
	Total   int
	Done    int
	Failed  int
	Skipped int
}

PlanContext carries plan metadata exposed to plan hook commands as env vars.

type TaskContext

type TaskContext struct {
	ID     int
	Title  string
	Status string
	Role   string
}

TaskContext carries task metadata exposed to hook commands as env vars.

Jump to

Keyboard shortcuts

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