hook

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const MarkerRel = ".chunk/hook/.chunk-hook-active"

MarkerRel is the scope marker file path relative to project root.

View Source
const ProfileEnable = "enable"

ProfileEnable is the default hook profile.

Variables

View Source
var ValidProfiles = []string{"disable", ProfileEnable, "tests-lint"}

ValidProfiles lists the allowed profile names.

Functions

func ActivateScope

func ActivateScope(projectDir string, stdin io.Reader) error

ActivateScope reads stdin JSON and activates scope if file paths reference the project. Returns nil on success (always exits 0 for the hook).

func DeactivateScope

func DeactivateScope(projectDir string, stdin io.Reader) error

DeactivateScope removes the scope marker. Session-aware: only removes if same session.

func IsEnabled

func IsEnabled(name string) bool

IsEnabled checks whether a specific command is enabled. Resolution: CHUNK_HOOK_ENABLE_{NAME} > CHUNK_HOOK_ENABLE > false.

func ReadStdinJSON

func ReadStdinJSON(r io.Reader) (map[string]interface{}, error)

ReadStdinJSON reads and parses a JSON object from r.

func ResolveProject

func ResolveProject(flagValue string) string

ResolveProject resolves the --project flag to an absolute path.

func RunEnvUpdate

func RunEnvUpdate(opts EnvUpdateOptions, streams iostream.Streams) error

RunEnvUpdate writes the env file with profile-based configuration, ensures shell startup files source it, and migrates legacy paths.

func RunExecCheck

func RunExecCheck(cfg *ResolvedConfig, flags ExecCheckFlags, event map[string]interface{}) error

RunExecCheck reads a saved sentinel and enforces the result.

func RunExecRun

func RunExecRun(cfg *ResolvedConfig, flags ExecRunFlags) error

RunExecRun executes a configured command, saves result as sentinel.

func RunRepoInit

func RunRepoInit(targetDir string, force bool, streams iostream.Streams) error

RunRepoInit initializes a repository with hook configuration files.

func RunSetup

func RunSetup(targetDir, profile string, force, skipEnv bool, envFile string, streams iostream.Streams) error

RunSetup combines env update + repo init.

func RunSyncCheck

func RunSyncCheck(cfg *ResolvedConfig, flags SyncCheckFlags, event map[string]interface{}) error

RunSyncCheck performs a grouped sequential check.

func RunTaskCheck

func RunTaskCheck(cfg *ResolvedConfig, flags TaskCheckFlags, event map[string]interface{}) error

RunTaskCheck checks a task result. When not enabled, exits 0.

func SentinelPath

func SentinelPath(sentinelDir, projectDir, name string) string

SentinelPath returns the full path to a sentinel file.

func SentinelsDir

func SentinelsDir() string

SentinelsDir returns the sentinel directory from the environment.

func StateAppend

func StateAppend(sentinelDir, projectDir string, stdin io.Reader) error

StateAppend reads event JSON from stdin and appends it to existing state.

func StateClear

func StateClear(sentinelDir, projectDir string, stdin io.Reader) error

StateClear clears state for the project.

func StateLoad

func StateLoad(sentinelDir, projectDir, field string, streams iostream.Streams) error

StateLoad outputs stored state as JSON. If field is set, resolves a dot-separated path (e.g. "UserPromptSubmit.prompt") into the state tree.

func StateSave

func StateSave(sentinelDir, projectDir string, stdin io.Reader) error

StateSave reads event JSON from stdin and stores it keyed by event name.

func ValidateProfile

func ValidateProfile(profile string) error

ValidateProfile returns an error if the profile name is not valid.

Types

type BlockError

type BlockError struct {
	Message string
}

BlockError signals that the hook should exit with code 2.

func (*BlockError) Error

func (e *BlockError) Error() string

type CheckResult

type CheckResult struct {
	Kind     string // "missing", "pending", "pass", "fail"
	Sentinel *SentinelData
}

CheckResult is the outcome of evaluating a sentinel.

type CommandSpec

type CommandSpec struct {
	Type string // specTypeExec or specTypeTask
	Name string
}

CommandSpec is a parsed spec like "exec:tests" or "task:review".

func ParseSpecs

func ParseSpecs(args []string) ([]CommandSpec, error)

ParseSpecs parses command specifiers from positional arguments.

type Config

type Config struct {
	Triggers  map[string]TriggerConfig `yaml:"triggers"`
	Execs     map[string]ExecConfig    `yaml:"execs"`
	Tasks     map[string]TaskConfig    `yaml:"tasks"`
	Sentinels *SentinelsConfig         `yaml:"sentinels"`
}

Config is the top-level shape matching .chunk/hook/config.yml.

type EnvUpdateOptions

type EnvUpdateOptions struct {
	Profile      string
	EnvFile      string
	LogDir       string
	Verbose      bool
	ProjectRoot  string
	StartupFiles []string // override shell startup files (for testing)
}

EnvUpdateOptions holds options for the env update command.

type ExecCheckFlags

type ExecCheckFlags struct {
	Name    string
	Timeout int
	FileExt string
	Staged  bool
	Always  bool
	On      string
	Trigger string
	Limit   int
	Matcher string
	Cmd     string
}

ExecCheckFlags holds parsed flags for exec check.

type ExecCheckVerdict

type ExecCheckVerdict struct {
	Kind     string // "skip-trigger", "skip-no-changes", "missing", "pending", "pass", "fail"
	Sentinel *SentinelData
}

ExecCheckVerdict is the outcome of pre-evaluating an exec spec.

type ExecConfig

type ExecConfig struct {
	Command string `yaml:"command"`
	FileExt string `yaml:"fileExt"`
	Always  bool   `yaml:"always"`
	Timeout int    `yaml:"timeout"`
	Limit   int    `yaml:"limit"`
}

ExecConfig holds per-exec configuration from the YAML execs section.

type ExecRunFlags

type ExecRunFlags struct {
	Name    string
	Cmd     string
	Timeout int
	FileExt string
	Staged  bool
	Always  bool
	NoCheck bool
	On      string
	Trigger string
	Limit   int
	Matcher string
}

ExecRunFlags holds parsed flags for exec run.

type MarkerContent

type MarkerContent struct {
	SessionID string `json:"sessionId"`
	Timestamp int64  `json:"timestamp"`
}

MarkerContent is stored in the scope marker file.

func ReadMarker

func ReadMarker(projectDir string) *MarkerContent

ReadMarker reads the marker file. Returns nil if absent or malformed.

type ResolvedConfig

type ResolvedConfig struct {
	Triggers    map[string][]string
	Execs       map[string]ExecConfig
	Tasks       map[string]TaskConfig
	SentinelDir string
	ProjectDir  string
}

ResolvedConfig is the merged configuration ready for use by commands.

func LoadConfig

func LoadConfig(projectDir string) *ResolvedConfig

LoadConfig reads and resolves config from the project directory.

type Response

type Response struct {
	Action  string // "allow" or "block"
	Message string // block reason (only for "block")
}

Response represents the action to take: allow or block.

type SentinelData

type SentinelData struct {
	Status            string `json:"status"`
	StartedAt         string `json:"startedAt"`
	FinishedAt        string `json:"finishedAt,omitempty"`
	ExitCode          int    `json:"exitCode,omitempty"`
	Command           string `json:"command,omitempty"`
	ConfiguredCommand string `json:"configuredCommand,omitempty"`
	Output            string `json:"output,omitempty"`
	Details           string `json:"details,omitempty"`
	Project           string `json:"project,omitempty"`
	Skipped           bool   `json:"skipped,omitempty"`
	RawResult         string `json:"rawResult,omitempty"`
	SessionID         string `json:"sessionId,omitempty"`
	ContentHash       string `json:"contentHash,omitempty"`
}

SentinelData is the shape of a sentinel JSON file.

type SentinelsConfig

type SentinelsConfig struct {
	Dir string `yaml:"dir"`
}

SentinelsConfig holds sentinel directory configuration.

type SyncCheckFlags

type SyncCheckFlags struct {
	Specs   []CommandSpec
	On      string
	Trigger string
	Matcher string
	Limit   int
	Staged  bool
	Always  bool
	OnFail  string
	Bail    bool
}

SyncCheckFlags holds parsed flags for sync check.

type TaskCheckFlags

type TaskCheckFlags struct {
	Name         string
	Instructions string
	Schema       string
	Always       bool
	Staged       bool
	On           string
	Trigger      string
	Matcher      string
	Limit        int
}

TaskCheckFlags holds parsed flags for task check.

type TaskConfig

type TaskConfig struct {
	Instructions string `yaml:"instructions"`
	Schema       string `yaml:"schema"`
	Limit        int    `yaml:"limit"`
	Always       bool   `yaml:"always"`
	Timeout      int    `yaml:"timeout"`
}

TaskConfig holds task command configuration.

type TriggerConfig

type TriggerConfig struct {
	Patterns []string `yaml:"patterns"`
}

TriggerConfig holds trigger group patterns.

Jump to

Keyboard shortcuts

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