Documentation
¶
Index ¶
- Constants
- Variables
- func DirtyWorktreeScopePaths(err error) []string
- func FailureCategory(err error) string
- func FailureCategoryWithDetail(err error) string
- func IsVerifierEvidenceRef(ref string) bool
- func VerificationFailureEvidenceRefs(err error) []string
- func WhitespaceWarningEvidenceRefs(err error) []string
- type Command
- type CommandResult
- type CommandRunner
- type Conventions
- type DirtyWorktreeScopeError
- type GeneratedArtifactVerifier
- type Options
- type PostPRChecks
- type PostTaskInput
- type PostTaskResult
- type RenderedOutput
- type Service
- func (svc *Service) Options() Options
- func (svc *Service) PostTask(ctx context.Context, input PostTaskInput) (PostTaskResult, error)
- func (svc *Service) PreTask(ctx context.Context, workDir string) error
- func (svc *Service) PreTaskWithinScope(ctx context.Context, workDir string, allowedPathspecs []string) error
- func (svc *Service) ReconcileLeftoverChanges(ctx context.Context, input PostTaskInput) (string, error)
- type VerificationFailureError
- type VerificationProfile
Constants ¶
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 ¶
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. 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 FailureCategory ¶ added in v0.2.4
func FailureCategoryWithDetail ¶ added in v0.2.4
func IsVerifierEvidenceRef ¶ added in v0.3.0
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 WhitespaceWarningEvidenceRefs ¶ added in v0.3.0
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 CommandResult ¶
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 Options ¶
type Options struct {
Enabled bool
CommitAfterTask bool
PushAfterTask bool
DraftPRAfterPush bool
// MarkPRAfterFinalize, when true (the default), flips the draft PR to "ready
// for review" (gh pr ready <number>) right after ensureDraftPR creates it.
// This surfaces the PR for reviewers/CI immediately instead of leaving it in
// draft. Only fires when DraftPRAfterPush is also true (nothing to mark
// otherwise). Failure to mark ready is a SOFT warning (the PR is already
// created successfully) — it never terminalizes the run. Idempotent: gh pr
// ready on an already-ready PR is a no-op.
MarkPRAfterFinalize 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 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 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 NewWithRunner ¶
func NewWithRunner(options Options, runner CommandRunner) *Service
func (*Service) Options ¶ added in v0.3.0
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) PreTaskWithinScope ¶ added in v0.2.4
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
// command was not on PATH (Phase "tool-unavailable"). It still blocks PR
// creation (it is a verification failure), but FailureCategory routes it to
// the environment/tooling lane via ErrVerifierToolUnavailable so the chain
// recovery treats it as a tooling gap rather than a code defect the repair
// agent cannot fix (FM-5).
IsToolUnavailable bool
// Output captures the verifier command's combined stdout+stderr (truncated
// to verifierOutputCap). Without this, the repair agent is told "fix the
// typecheck" but never sees the actual compiler errors (file paths, line
// numbers, error codes) — so it reproduces the same broken code and loops
// (the MASS-3839 att=7 typecheck loop). The output flows through evidence
// refs → resume instructions → the repair prompt so the agent can fix the
// real errors, not guess at them.
Output 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