hook

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 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.

Variables

This section is empty.

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 BuildSettingsJSON added in v0.7.2

func BuildSettingsJSON(projectName string, commands []config.Command) (string, error)

BuildSettingsJSON generates the .claude/settings.json content from detected commands.

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() bool

IsEnabled reports whether hooks are globally enabled via CHUNK_HOOK_ENABLE.

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 logging and project root 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, projectName string, commands []config.Command, force bool, streams iostream.Streams) error

RunRepoInit initializes a repository with hook configuration files. If projectName is empty, it falls back to the directory basename.

func RunSetup

func RunSetup(targetDir, projectName string, force, skipEnv bool, envFile string, commands []config.Command, 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.

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 EnvUpdateOptions

type EnvUpdateOptions struct {
	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
	AllowMissing bool
}

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
	FileExt string
	Always  bool
	Timeout int
	Limit   int
}

ExecConfig holds per-exec configuration.

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 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
	Schema       string
	Limit        int
	Always       bool
	Timeout      int
}

TaskConfig holds task command configuration.

Jump to

Keyboard shortcuts

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