Documentation
¶
Overview ¶
Package ciloop is the CI-aware PR loop (docs/ci-loop.md): once Lectern opens a pull request for a task or session on a project that opted in, it watches the PR's checks through the target's own `gh`, and when they fail it sends the owning agent a short failure report — failing job names and a trimmed, redacted log tail — asking it to fix them. A session's agent pushes its own fix; a task's headless follow-up usually cannot run git, so Lectern commits and pushes what it leaves (commit.go). It stops on pass, merge, close or the attempt cap, and pushes a phone notification when CI goes green after fixes or when it gives up.
There are no webhooks (Lectern is tailnet-only). The loop polls, with backoff, and only while a PR still has pending or failing checks.
Index ¶
Constants ¶
const ( StatePending = "pending" // checks running, or not reported yet StateFailing = "failing" // failed; a fix request was sent, waiting for a push StatePassed = "passed" StateCapped = "capped" // still failing after max_attempts fix requests StateMerged = "merged" StateClosed = "closed" StateNone = "none" // the PR never reported any checks StateError = "error" // gh cannot do the job (not signed in, not installed, …) StateStalled = "stalled" // no progress for StallAfter )
Watch states stored in ci_watches.state. pending and failing are the active ones; everything else is terminal.
const ( DefaultMinInterval = 30 * time.Second DefaultMaxInterval = 10 * time.Minute DefaultStallAfter = 24 * time.Hour DefaultNoChecksAfter = 15 * time.Minute )
Defaults for the poll schedule.
Variables ¶
var ErrNotEnabled = errors.New("the CI loop is not enabled for this project")
ErrNotEnabled is Arm's answer for a project that has not opted in.
Functions ¶
func FindPRURL ¶
FindPRURL pulls a PR URL out of gh output — `gh pr create` prints it on success, and names the existing one when a PR for the branch already exists.
func ValidPRURL ¶
ValidPRURL reports whether s looks like a pull request URL.
Types ¶
type SessionSender ¶
SessionSender delivers a message into a live session's agent. It is agent-agnostic: *sessions.Manager types it into the tmux pane, which is how every CLI Lectern runs receives a message.
type View ¶
type View struct {
ID int64 `json:"id"`
TaskID *int64 `json:"task_id,omitempty"`
SessionID *int64 `json:"session_id,omitempty"`
PRURL string `json:"pr_url"`
State string `json:"state"`
Attempts int `json:"attempts"`
MaxAttempts int `json:"max_attempts"`
Failing []string `json:"failing"`
Detail string `json:"detail,omitempty"`
Label string `json:"label"`
Active bool `json:"active"`
UpdatedAt float64 `json:"updated_at"`
}
View is the compact form a task or session card renders.
type Watcher ¶
type Watcher struct {
DB *store.DB
Reg *executor.Registry
Bus *bus.Bus
Notifier Notifier
Sessions SessionSender
Log *slog.Logger
MinInterval, MaxInterval, StallAfter, NoChecksAfter time.Duration
// Now is the clock, replaceable in tests.
Now func() float64
// Sync polls due watches inline in Tick instead of on goroutines.
Sync bool
// contains filtered or unexported fields
}
Watcher owns every ci_watches row.
func New ¶
func New(db *store.DB, reg *executor.Registry, b *bus.Bus, n Notifier, s SessionSender, log *slog.Logger) *Watcher
New builds a Watcher with the default schedule.
func (*Watcher) Arm ¶
Arm starts watching prURL for owner. Unless force is set (a human asking for it explicitly), the owner's project must have opted in; otherwise it returns ErrNotEnabled and records nothing.
func (*Watcher) AttemptFinished ¶
AttemptFinished is the scheduler telling the loop that a task attempt ended. If it was a CI fix, the watch looks again now rather than after its backoff, so Lectern commits and pushes the fix straight away.
func (*Watcher) Poll ¶
Poll is one observation of one watch: read the PR and its checks, decide, act, and schedule the next look.