Documentation
¶
Index ¶
- Constants
- Variables
- func ActivateScope(projectDir string, stdin io.Reader) error
- func BuildSettingsJSON(projectName string, commands []config.Command) string
- func DeactivateScope(projectDir string, stdin io.Reader) error
- func IsEnabled(name string) bool
- func ReadStdinJSON(r io.Reader) (map[string]interface{}, error)
- func ResolveProject(flagValue string) string
- func RunEnvUpdate(opts EnvUpdateOptions, streams iostream.Streams) error
- func RunExecCheck(cfg *ResolvedConfig, flags ExecCheckFlags, event map[string]interface{}) error
- func RunExecRun(cfg *ResolvedConfig, flags ExecRunFlags) error
- func RunRepoInit(targetDir, projectName string, commands []config.Command, force bool, ...) error
- func RunSetup(targetDir, projectName, profile string, force, skipEnv bool, envFile string, ...) error
- func RunSyncCheck(cfg *ResolvedConfig, flags SyncCheckFlags, event map[string]interface{}) error
- func RunTaskCheck(cfg *ResolvedConfig, flags TaskCheckFlags, event map[string]interface{}) error
- func SentinelPath(sentinelDir, projectDir, name string) string
- func SentinelsDir() string
- func StateAppend(sentinelDir, projectDir string, stdin io.Reader) error
- func StateClear(sentinelDir, projectDir string, stdin io.Reader) error
- func StateLoad(sentinelDir, projectDir, field string, streams iostream.Streams) error
- func StateSave(sentinelDir, projectDir string, stdin io.Reader) error
- func ValidateProfile(profile string) error
- type BlockError
- type CheckResult
- type CommandSpec
- type EnvUpdateOptions
- type ExecCheckFlags
- type ExecCheckVerdict
- type ExecConfig
- type ExecRunFlags
- type MarkerContent
- type ResolvedConfig
- type Response
- type SentinelData
- type SyncCheckFlags
- type TaskCheckFlags
- type TaskConfig
Constants ¶
const MarkerRel = ".chunk/hook/.chunk-hook-active"
MarkerRel is the scope marker file path relative to project root.
const ProfileEnable = "enable"
ProfileEnable is the default hook profile.
Variables ¶
var ValidProfiles = []string{"disable", ProfileEnable, "tests-lint"}
ValidProfiles lists the allowed profile names.
Functions ¶
func ActivateScope ¶
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
BuildSettingsJSON generates the .claude/settings.json content from detected commands.
func DeactivateScope ¶
DeactivateScope removes the scope marker. Session-aware: only removes if same session.
func IsEnabled ¶
IsEnabled checks whether a specific command is enabled. Resolution: CHUNK_HOOK_ENABLE_{NAME} > CHUNK_HOOK_ENABLE > false.
func ReadStdinJSON ¶
ReadStdinJSON reads and parses a JSON object from r.
func ResolveProject ¶
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, 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, profile 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 ¶
SentinelPath returns the full path to a sentinel file.
func SentinelsDir ¶
func SentinelsDir() string
SentinelsDir returns the sentinel directory from the environment.
func StateAppend ¶
StateAppend reads event JSON from stdin and appends it to existing state.
func StateClear ¶
StateClear clears state for the project.
func StateLoad ¶
StateLoad outputs stored state as JSON. If field is set, resolves a dot-separated path (e.g. "UserPromptSubmit.prompt") into the state tree.
func ValidateProfile ¶
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 ¶
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 {
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
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 ¶
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.