Documentation
¶
Overview ¶
Package checks runs a project's check command against a session's worktree when its agent stops, and stores the result for the card to show.
It is the session half of docs/agent-events.md section 4 ("Checks"). Tasks keep their existing one-shot auto-verify (internal/scheduler, unchanged attempts.verify_json shape); this package's Resolve/Execute are what that path now calls too, so "verify_cmd, or auto-detected .verify.yaml" is one rule instead of two. Sessions are different from a task attempt in one important way: they are ongoing, so running the same command again every time an agent goes idle — often with nothing new in the worktree — would be pure waste. RunForSession exists to make that cheap: a fingerprint over the worktree's diff decides whether there is anything worth checking.
Index ¶
- Constants
- func SessionCheckWorkdir(row *store.Session) (string, error)
- func SessionWorkdir(row *store.Session) (string, error)
- func WorktreeFingerprint(ctx context.Context, ex executor.Executor, dir string) (string, error)
- type Runner
- func (r *Runner) CommandIn(ctx context.Context, ex executor.Executor, project *store.Project, dir string) (cmd string, ok bool)
- func (r *Runner) DetectCommand(ctx context.Context, project *store.Project) (cmd, source string)
- func (r *Runner) OnAgentStop(sessionID int64)
- func (r *Runner) RunForSession(ctx context.Context, sessionID int64, reason string)
- func (r *Runner) RunForTask(ctx context.Context, ex executor.Executor, project *store.Project, ...) (map[string]any, bool)
- type StopListener
Constants ¶
const ( StatusRunning = "running" StatusPassed = "passed" StatusFailed = "failed" StatusError = "error" StatusSkipped = "skipped" )
Status values stored in session_checks.status (see store/schema.go).
const ( ReasonStop = "stop" // an agent Stop (or codex AgentTurnComplete) hook ReasonScreen = "screen" // the screen-derived busy->idle fallback ReasonManual = "manual" // a human pressed "Run check" )
Trigger reasons stored in session_checks.reason.
const AutoVerifyCommand = "verify run .verify.yaml"
AutoVerifyCommand is what a project with no verify_cmd but a checked-in .verify.yaml and `verify` on the target's PATH gets for free — see probeAutoCommand and docs/agent-events.md section 4.
const DefaultTimeout = 15 * time.Minute
DefaultTimeout is 15 minutes, matching the literal the task auto-verify path used before this package existed.
Variables ¶
This section is empty.
Functions ¶
func SessionCheckWorkdir ¶ added in v2.10.2
SessionCheckWorkdir mirrors internal/api's sessionRepoDiffs (session_review.go) closely enough to reuse its worktree_json shape, but simplified to the one directory a check runs in: the session's own project's repository when a grouped multi-repo workspace has one, otherwise the first repository with a worktree, otherwise the session's single worktree/workdir. A session with no worktree and no workdir has nothing to check.
func SessionWorkdir ¶ added in v2.10.2
SessionWorkdir is the directory a session's checks run in. The approval witness reads the same directory, so the two always agree on what "the worktree" is.
func WorktreeFingerprint ¶ added in v2.10.2
WorktreeFingerprint hashes HEAD's sha, `git status --porcelain` and a diff against HEAD (which covers both staged and unstaged changes) — enough to tell "the worktree has moved since the last check" from "nothing to see here" without capturing or storing the diff itself.
Types ¶
type Runner ¶
type Runner struct {
DB *store.DB
Reg *executor.Registry
Bus *bus.Bus
Notifier *sinks.Notifier
Log *slog.Logger
// Timeout bounds one check run; DefaultTimeout is used when unset.
Timeout time.Duration
// contains filtered or unexported fields
}
Runner owns check execution for both sessions (this file) and, via RunForTask, the task auto-verify path (internal/scheduler).
func New ¶
func New(db *store.DB, reg *executor.Registry, b *bus.Bus, notifier *sinks.Notifier, timeout time.Duration, log *slog.Logger) *Runner
New builds a Runner.
func (*Runner) CommandIn ¶ added in v2.10.2
func (r *Runner) CommandIn(ctx context.Context, ex executor.Executor, project *store.Project, dir string) (cmd string, ok bool)
CommandIn is resolve for a worktree the caller already has: the same verify_cmd-or-.verify.yaml rule the check runner applies, so a pre-merge validation runs exactly what the project's own checks would run.
func (*Runner) DetectCommand ¶
DetectCommand is resolve for a project with no live worktree yet — the project settings UI's "Check command: auto-detected: ..." preview. It probes the project's own repo checkout on its target, since .verify.yaml is checked into the repo and so is present in any worktree cut from it.
func (*Runner) OnAgentStop ¶
OnAgentStop implements StopListener. The actual run happens on a fresh goroutine with its own background context: the caller (a hook's HTTP handler, or a poll tick) must get its own turn back immediately, and a check that legitimately takes minutes must not be cancelled just because the request that triggered it already answered.
func (*Runner) RunForSession ¶
RunForSession resolves a session's check command and runs it if the worktree has changed since the last check (or reason is ReasonManual, which always runs). Only one check runs at a time per session; a request that arrives while one is already running is coalesced into a single extra run afterward, using whichever reason arrived last.
func (*Runner) RunForTask ¶
func (r *Runner) RunForTask(ctx context.Context, ex executor.Executor, project *store.Project, worktreePath string) (map[string]any, bool)
RunForTask runs a project's check command against a finished task attempt's worktree, in the exact {"cmd","rc","output"} shape scheduler.go has always stored in attempts.verify_json — callers must not change that shape, since the timeline event and the board badge both parse it. Unlike a session, a task attempt is one-shot: there is nothing to fingerprint against and no coalescing concern, so this is just resolve-then-execute.
type StopListener ¶
type StopListener interface {
// OnAgentStop is fire-and-forget: it must not block its caller (a hook
// handler that owes the agent a fast HTTP response, or a poll tick that
// owes the rest of the fleet its turn). The runner performs the actual
// check on its own goroutine, coalescing overlapping requests.
OnAgentStop(sessionID int64)
}
StopListener is how something that observes an agent's lifecycle (a Stop hook, or the screen-derived status fallback) tells the checks runner a session may have new work to check. It is defined here, not imported by its callers as a concrete type, so internal/agentevents and internal/sessions never need to import internal/checks — *Runner satisfies this interface structurally, wired up in internal/app.