projectgitops

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const WhitespaceWarningEvidenceRef = "git-diff-check-warning"

WhitespaceWarningEvidenceRef is the stable evidence ref attached when a `git diff --cached --check` failure is converted to a soft warning.

Variables

View Source
var (
	ErrInvalidInput       = errors.New("invalid git operations input")
	ErrBranchPolicy       = errors.New("git operations branch policy failed")
	ErrCommandFailed      = errors.New("git operations command failed")
	ErrDirtyWorktree      = errors.New("git operations dirty worktree")
	ErrDirtyWorktreeScope = errors.New("git operations dirty worktree outside task scope")
	ErrRuntimeFailure     = errors.New("git operations runtime setup failed")
	ErrVerificationFailed = errors.New("git operations verification failed")
	// ErrVerifierToolUnavailable is the distinct category for a verifier command
	// whose leading binary is not on PATH (e.g. nx/pnpm not installed in the
	// runner). Surfacing this distinctly (FM-5) lets the chain GitOps recovery
	// treat it as an environment/tooling gap rather than a code defect the
	// repair agent must fix, avoiding 5 wasted reset cycles.
	ErrVerifierToolUnavailable = errors.New("git operations verifier tool unavailable")
	ErrDownstreamChecks        = errors.New("git operations downstream checks failed")
	// ErrWhitespaceDrift is the soft category for whitespace/EOF/newline drift
	// surfaced by `git diff --cached --check`. Per the automation pipeline policy
	// (.ai/rules/40-automation-pipeline-policy.md) whitespace/newline drift is a
	// forbidden soft blocker that must become warning evidence, not a terminal
	// block. It is only used when WhitespaceWarningOnDiffCheck is enabled.
	ErrWhitespaceDrift = errors.New("git operations whitespace drift warning")
	// ErrRebaseConflict is returned when git rebase onto the current remote
	// default branch produces conflicts. The caller should NOT auto-force-push
	// in this case — surfacing it as a distinct failure category lets the chain
	// recovery agent decide whether to abort+reset or request manual resolution.
	ErrRebaseConflict = errors.New("git operations rebase conflict")
)

Functions

func DirtyWorktreeScopePaths added in v0.2.4

func DirtyWorktreeScopePaths(err error) []string

func FailureCategory added in v0.2.4

func FailureCategory(err error) string

func FailureCategoryWithDetail added in v0.2.4

func FailureCategoryWithDetail(err error) string

func IsVerifierEvidenceRef added in v0.3.0

func IsVerifierEvidenceRef(ref string) bool

IsVerifierEvidenceRef reports whether an evidence/claim ref token indicates the task attempted GitOps verification (success or failure). Single source of truth for the verifier-evidence vocabulary so every guard recognizes the same token set. Covers success (verify-* / project-verification-passed), failure (gitops-verifier-*), and closeout (verifier-result-ref:* / verifier.automation.*). Historical bug: guards checked only verifier-/gitops-verifier- and missed the verify-* success tokens, so completed-and-verified tasks blocked on "no changes" instead of soft-closing out.

func VerificationFailureEvidenceRefs added in v0.3.0

func VerificationFailureEvidenceRefs(err error) []string

func WhitespaceWarningEvidenceRefs added in v0.3.0

func WhitespaceWarningEvidenceRefs(err error) []string

WhitespaceWarningEvidenceRefs returns the warning evidence refs attached to a soft whitespace-drift error (whitespaceDriftError). Callers thread these into the PostTask/Reconcile result evidence so the drift is recorded as a warning, never hidden, but never terminal either.

Types

type Command

type Command struct {
	Path string
	Args []string
	Dir  string
	Env  []string
}

type CommandResult

type CommandResult struct {
	Stdout string
	Stderr string
}

type CommandRunner

type CommandRunner interface {
	Run(context.Context, Command) (CommandResult, error)
}

type Conventions added in v0.2.4

type Conventions struct {
	CommitType               string
	CommitScope              string
	AllowedChangeTypes       []string
	DefaultChangeType        string
	RequireTicket            bool
	BranchNameTemplate       string
	TicketRefPattern         string
	TicketURLTemplate        string
	CommitSummaryTemplate    string
	PullRequestTitleTemplate string
	PullRequestBodyTemplate  string
	WhatChangedTemplate      string
	HowVerifiedTemplate      string
	TestsTemplate            string
}

func DefaultConventions added in v0.2.4

func DefaultConventions() Conventions

type DirtyWorktreeScopeError added in v0.2.4

type DirtyWorktreeScopeError struct {
	Paths []string
}

func (DirtyWorktreeScopeError) Error added in v0.2.4

func (err DirtyWorktreeScopeError) Error() string

func (DirtyWorktreeScopeError) Unwrap added in v0.2.4

func (err DirtyWorktreeScopeError) Unwrap() error

type GeneratedArtifactVerifier added in v0.2.4

type GeneratedArtifactVerifier struct {
	Paths            []string
	Command          string
	RequiredBeforePR bool
}

type Options

type Options struct {
	Enabled                      bool
	CommitAfterTask              bool
	PushAfterTask                bool
	DraftPRAfterPush             bool
	RequireCleanBeforeTask       bool
	CleanupWorktreeAfterPlanDone bool
	RemoteName                   string
	// DefaultBranch is the project's default branch (main, master, develop, ...).
	// Resolution order: per-project override → remote HEAD symbolic-ref → "main".
	// Used as the fetch+rebase base before push and as the squash reset base, so
	// the PR diff is always computed against the real current default branch and
	// never against a stale local remote-tracking ref (MASS-3997 PR #3540).
	DefaultBranch              string
	BranchPrefix               string
	BranchNamePattern          string
	CommitAuthorName           string
	CommitAuthorEmailEnv       string
	CommitAuthorEmailFile      string
	SignCommits                bool
	SSHPrivateKeyPath          string
	SSHPublicKeyPath           string
	SSHKnownHostsPath          string
	GitHubTokenEnv             string
	GitHubTokenFile            string
	GitHubCLIPath              string
	GitHubAuthPreflight        bool
	DirtyScopeSupportPathspecs []string
	Conventions                Conventions
	Verification               VerificationProfile
	PostPRChecks               PostPRChecks
	// WhitespaceWarningOnDiffCheck converts `git diff --cached --check` failures
	// (trailing whitespace, missing/extra final newline, blank lines at EOF) into
	// soft warning evidence instead of a hard terminal block. Per the automation
	// pipeline policy this whitespace/newline drift is a forbidden soft blocker.
	// Defaults to true in NewWithRunner so production behavior is policy-compliant.
	WhitespaceWarningOnDiffCheck bool
	// PushMaxAttempts bounds in-function retries for `git push` on transient
	// network errors (5xx, timeout, rate limit) before surfacing the failure to
	// the chain retry budget. Defaults to 3 in NewWithRunner; set to 1 to disable.
	PushMaxAttempts int
	// PushBackoffBase is the base delay for push retry backoff (exponential).
	// Defaults to 5s in NewWithRunner.
	PushBackoffBase time.Duration
	// PRCreateMaxAttempts bounds in-function retries for `gh pr create` on
	// transient network errors. Defaults to 3 in NewWithRunner; set to 1 to disable.
	PRCreateMaxAttempts int
	// PRCreateBackoffBase is the base delay for pr-create retry backoff (exponential).
	// Defaults to 5s in NewWithRunner.
	PRCreateBackoffBase time.Duration
	// BypassRepoCommitHooks appends --no-verify to every git commit the service
	// issues. Opt-in: repos with a reliable pre-commit hook leave this false (the
	// default) and the hook gates commits as intended. Repos whose hook breaks
	// automation on internals (e.g. mass-monorepo Husky → scripts/dev-precommit.sh
	// --hook with `set -euo pipefail` running lint-staged + typecheck, failing on
	// pnpm warnings/env quirks the automation cannot satisfy) set this true. The
	// pipeline runs its own verifiers via runPostCommitVerification, so the repo
	// hook is redundant double-validation for automation when enabled.
	BypassRepoCommitHooks bool
}

type PostPRChecks added in v0.3.0

type PostPRChecks struct {
	Enabled         bool
	RequiredOnly    bool
	Watch           bool
	FailFast        bool
	IntervalSeconds int
}

type PostTaskInput

type PostTaskInput struct {
	WorkDir          string
	ProjectID        string
	PlanID           string
	TaskID           string
	TaskRef          string
	TaskTitle        string
	TicketRef        string
	ChangeType       string
	BranchName       string
	BaseRef          string
	AutomationID     string
	AutomationRunID  string
	OperatorID       string
	CommitBody       string
	AllowedPathspecs []string
	ReviewRefs       []string
	VerifierRefs     []string
	TestResults      []string
}

type PostTaskResult

type PostTaskResult struct {
	Skipped        bool
	NoChanges      bool
	CommitRef      string
	PushRef        string
	PullRequestRef string
	EvidenceRefs   []string
}

type RenderedOutput added in v0.2.4

type RenderedOutput struct {
	CommitSubject    string
	CommitBody       string
	PullRequestTitle string
	PullRequestBody  string
}

func Render added in v0.2.4

func Render(input PostTaskInput, conventions Conventions) (RenderedOutput, error)

type Service

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

func New

func New(options Options) *Service

func NewWithRunner

func NewWithRunner(options Options, runner CommandRunner) *Service

func (*Service) Options added in v0.3.0

func (svc *Service) Options() Options

Options returns the effective (normalized) gitops options the service was constructed with. Callers use it to gate behavior (e.g. the runner checks Enabled/CommitAfterTask before reconciling leftover worktree changes).

func (*Service) PostTask

func (svc *Service) PostTask(ctx context.Context, input PostTaskInput) (PostTaskResult, error)

func (*Service) PreTask

func (svc *Service) PreTask(ctx context.Context, workDir string) error

func (*Service) PreTaskWithinScope added in v0.2.4

func (svc *Service) PreTaskWithinScope(ctx context.Context, workDir string, allowedPathspecs []string) error

func (*Service) ReconcileLeftoverChanges added in v0.3.0

func (svc *Service) ReconcileLeftoverChanges(ctx context.Context, input PostTaskInput) (string, error)

ReconcileLeftoverChanges commits a dedicated worktree's uncommitted agent changes as a continuation commit, WITHOUT pushing or creating a PR. It exists so a follow-up task can start on a clean worktree when a prior agent left changes uncommitted (a structurally common case in agent-owned dedicated worktrees, where leftover changes are the agent's own prior work).

It stages ONLY the task's allowed pathspecs (reusing the same scope enforcement as PostTask) and returns the commit ref. It must only be invoked for dedicated_worktree isolation (the caller gates this), because only there is the worktree provably agent-owned. If the worktree is already clean, it returns "" with a nil error (no-op). On scope violations it returns ErrDirtyWorktreeScope.

type VerificationFailureError added in v0.3.0

type VerificationFailureError struct {
	CommandHash string
	CommandRef  string
	Phase       string
	// Source identifies which verifier loop produced the failure so downstream
	// classifiers can route bootstrap (environment/install) failures to the
	// infrastructure-retry lane instead of the code-repair lane. Values:
	//   "bootstrap" - runPreCommitVerification BootstrapCommands loop
	//   "generated" - runPreCommitVerification GeneratedArtifacts loop
	//   "verify"    - runPostCommitVerification AlwaysBeforePR loop (default)
	// An empty Source is treated as "verify" for backward compatibility.
	Source string
}

func (VerificationFailureError) Error added in v0.3.0

func (err VerificationFailureError) Error() string

func (VerificationFailureError) Unwrap added in v0.3.0

func (err VerificationFailureError) Unwrap() error

type VerificationProfile added in v0.2.4

type VerificationProfile struct {
	BootstrapCommands  []string
	AlwaysBeforePR     []string
	AutofixCommands    []string
	GeneratedArtifacts []GeneratedArtifactVerifier
	Env                map[string]string
}

Jump to

Keyboard shortcuts

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