Help us shape the future of Go! Take the 2026 Go Developer Survey

engine

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package engine runs reviews: it queues PRs from poll results, runs them with a bounded worker pool under the daily budget, and records everything.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderPrompt

func RenderPrompt(cfg *config.Config, agentName string, pr github.PRDetail) (string, error)

RenderPrompt fills the agent's prompt template with pr's details. The caller appends Ghost's fixed sections with agent.BuildPrompt.

Types

type Deps

type Deps struct {
	Store       *store.Store
	GetPR       func(ctx context.Context, repo string, number int) (github.PRDetail, error)
	Checkout    func(ctx context.Context, repo string, number int, baseRef, headSHA string) (workspace.Workspace, func(), error)
	NewReviewer func(name string, a config.Agent) (agent.Reviewer, error)
	PostReview  func(ctx context.Context, repo string, number int, p github.ReviewPost) (github.PostResult, error)
	HasReview   func(ctx context.Context, repo string, number int, marker string) (bool, error)
	Approve     func(ctx context.Context, repo string, number int, commitID, body string) error
	AddLabel    func(ctx context.Context, repo string, number int, label string) error
	Now         func() time.Time
	Log         *slog.Logger // receives every audit event; nil = discard
}

type Engine

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

func New

func New(cfg config.Config, d Deps) *Engine

func (*Engine) Approve

func (e *Engine) Approve(ctx context.Context, repo string, number int) error

Approve approves a PR whose review is pending approval, or retries one whose earlier approval may not have reached GitHub.

func (*Engine) Changes

func (e *Engine) Changes() <-chan struct{}

Changes signals (coalesced) whenever engine state may have changed.

func (*Engine) HandlePoll

func (e *Engine) HandlePoll(r poller.Result)

HandlePoll hands a poll result to the engine without blocking. If the engine is busy the result is dropped; the next poll carries the same PRs.

func (*Engine) PRState

func (e *Engine) PRState(repo string, number int) PRState

PRState returns a PR's recent audit trail and latest review.

func (*Engine) PostPending

func (e *Engine) PostPending(ctx context.Context, repo string, number int) error

PostPending posts a PR's finished review (state ready), or retries one whose earlier post may not have reached GitHub (state post-unknown).

func (*Engine) Rereview

func (e *Engine) Rereview(pr github.PR) error

Rereview queues a fresh review of pr's head, using the PR's last agent (or the default), unless one is already queued or running.

func (*Engine) ReviewNow added in v0.6.0

func (e *Engine) ReviewNow(pr github.PR, agentName string) error

ReviewNow queues a review of pr right away with agentName ("" = the default agent), as `ghost review <pr>` does: it runs even if this commit was reviewed before, because someone asked for it.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context)

Run settles reviews a previous process left in flight, then processes poll results and runs reviews until ctx is cancelled. It returns once its workers have finished.

func (*Engine) SetViews

func (e *Engine) SetViews(views []config.View)

SetViews replaces the views the engine auto-reviews from.

func (*Engine) Snapshot

func (e *Engine) Snapshot() Snapshot

func (*Engine) TogglePause

func (e *Engine) TogglePause() bool

TogglePause stops or resumes starting new reviews and returns the new state.

type PRState

type PRState struct {
	Audit    []store.AuditEvent
	Latest   *store.Review
	Comments []agent.InlineComment // Latest's comments, decoded
	Waiting  string                // why Latest, if queued, hasn't started; "" = it starts as soon as a worker takes it
}

type Snapshot

type Snapshot struct {
	SpendTodayUSD float64
	MaxDailyUSD   float64
	Running       int
	Queued        int
	Paused        bool
	BudgetPaused  bool // reviews are queued but the daily budget is reached
}

Jump to

Keyboard shortcuts

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