validate

package
v0.7.67 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxAttempts = 3

DefaultMaxAttempts is the default number of consecutive Stop hook re-signals before chunk gives up and tells the agent to ask the user for help.

View Source
const DefaultTimeout = 300

DefaultTimeout is the per-command execution timeout in seconds.

Variables

View Source
var ErrNotConfigured = errors.New("no validate commands configured")

ErrNotConfigured indicates no validate commands are configured.

View Source
var ErrWorkspaceNotFound = errors.New("workspace directory not found on sidecar")

ErrWorkspaceNotFound is returned when the remote workspace directory does not exist.

Functions

func DetectCommands added in v0.7.2

func DetectCommands(ctx context.Context, claude *anthropic.Client, workDir string) ([]config.Command, error)

DetectCommands returns the full set of validate commands for the repo with metadata. For known toolchains it returns richer commands without calling Claude. Claude is only used as a fallback for unknown toolchains, and only when a client is provided.

func HasGitChanges added in v0.7.31

func HasGitChanges(workDir string) bool

HasGitChanges reports whether the working tree at workDir has any uncommitted modifications (staged or unstaged). Returns true when git is unavailable or the directory is not a repository so that validation still runs in ambiguous cases.

func HooksDisabled added in v0.7.51

func HooksDisabled(workDir string, envDisabled bool) bool

HooksDisabled reports whether chunk validate hooks are currently suppressed. envDisabled should be set by the caller from CHUNK_HOOKS_DISABLED; it returns true when that flag is set or the sentinel file .chunk/hooks-disabled exists under workDir. On any error other than ErrNotExist the function fails open (returns false) so hooks continue to run when the check is uncertain.

func List

func List(cfg *config.ProjectConfig, status iostream.StatusFunc) error

List prints all configured command names and their run strings.

func NewHookExitError added in v0.7.51

func NewHookExitError(code int) error

NewHookExitError returns a HookExitError with the given exit code.

func ResetAttempts added in v0.7.31

func ResetAttempts(sessionID string)

ResetAttempts clears the failure counter for the given session.

func RunAll

func RunAll(ctx context.Context, workDir string, cfg *config.ProjectConfig, status iostream.StatusFunc, streams iostream.Streams) error

RunAll runs all configured commands, stopping at the first failure.

func RunDryRun

func RunDryRun(cfg *config.ProjectConfig, name string, status iostream.StatusFunc) error

RunDryRun prints commands without executing them.

func RunInline

func RunInline(ctx context.Context, workDir, name, command string, status iostream.StatusFunc, streams iostream.Streams) error

RunInline runs an inline command string.

func RunNamed

func RunNamed(ctx context.Context, workDir, name string, cfg *config.ProjectConfig, status iostream.StatusFunc, streams iostream.Streams) error

RunNamed runs a single named command from config.

func RunRemote

func RunRemote(ctx context.Context, execFn func(ctx context.Context, script string) (stdout, stderr string, exitCode int, err error), cfg *config.ProjectConfig, name, dest string, status iostream.StatusFunc, streams iostream.Streams) error

RunRemote runs commands on a remote sidecar via SSH. If name is non-empty, only the named command is run.

func RunRemoteInline added in v0.7.29

func RunRemoteInline(ctx context.Context, execFn func(ctx context.Context, script string) (stdout, stderr string, exitCode int, err error), name, command, dest string, status iostream.StatusFunc, streams iostream.Streams) error

RunRemoteInline runs a single inline command on a remote sidecar via SSH.

func TestSuitesTemplate added in v0.7.52

func TestSuitesTemplate(workDir string) string

TestSuitesTemplate returns the contents of .circleci/test-suites.yml for the detected toolchain in workDir, or "" if no toolchain template applies.

The returned YAML targets CircleCI Smarter Testing: `<< test.atoms >>` is substituted at run time with the subset of test atoms picked by the platform.

func TrackFailedAttempt added in v0.7.31

func TrackFailedAttempt(sessionID string, warn io.Writer) int

TrackFailedAttempt increments the failure counter for the given session and returns the new count. warn is an optional writer for diagnostic messages (pass nil to suppress).

func WorkspaceExists added in v0.7.49

func WorkspaceExists(ctx context.Context, execFn func(context.Context, string) (string, string, int, error), dest string) error

WorkspaceExists checks whether dest exists as a directory on the remote sidecar.

func WrapHookResult added in v0.7.31

func WrapHookResult(sessionID string, execErr error, maxAttempts int, warn io.Writer) error

WrapHookResult applies Stop hook lifecycle to the result of running validate commands. On success it resets the attempt counter. On failure it increments the counter and returns a HookExitError with code 2 to re-signal the agent, or prints a give-up message and returns nil once maxAttempts is reached.

Types

type HookExitError added in v0.7.31

type HookExitError struct {
	// contains filtered or unexported fields
}

HookExitError signals a specific process exit code without printing additional error output. All output must be written before this error is returned.

func (*HookExitError) Error added in v0.7.31

func (e *HookExitError) Error() string

func (*HookExitError) ExitCode added in v0.7.31

func (e *HookExitError) ExitCode() int

type PackageManager added in v0.7.2

type PackageManager struct {
	Name           string
	InstallCommand string
}

PackageManager holds the name and CI-safe install command for a detected package manager.

func DetectPackageManager added in v0.7.2

func DetectPackageManager(workDir string) *PackageManager

DetectPackageManager returns the detected package manager and its CI-safe install command, or nil.

Jump to

Keyboard shortcuts

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