ci

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ci reads a repository to find what it is built from, and proposes the GitHub Actions pipeline that checks it: install, lint, typecheck, test and build, each only where the repo actually has one. `orch ci setup` and `orch init` write what it proposes.

Detection reads files and never runs anything: a lockfile says which package manager, a script or a tool's config section says which check exists. A check that is not there is left out rather than guessed, because a generated step that fails on day one teaches people to ignore CI.

Package ci is what orch does inside a project's own CI. `orch ci review` lives here: an AI review of a pull request's diff, run on the Actions runner by one of the coding-agent CLIs orch already drives.

Index

Constants

View Source
const (
	VerdictApprove        = "approve"
	VerdictComment        = "comment"
	VerdictRequestChanges = "request_changes"

	SeverityBlocking = "blocking"
	SeverityMinor    = "minor"
)

The verdicts and severities a reviewer may answer with.

View Source
const (
	GateTests     = "tests"
	GateTypecheck = "typecheck"
	GateLint      = "lint"
	GateBuild     = "build"
	GateReview    = "review"
)

The kinds of check a pull request can go through, in the order a client reads them.

View Source
const BuiltinChecklist = `` /* 420-byte string literal not displayed */

BuiltinChecklist is what the review applies when the repository has no checklist of its own.

View Source
const ChecklistPath = ".github/orch-review.md"

ChecklistPath is the review checklist `orch ci setup` writes and `orch ci review` reads by default.

View Source
const CommentMarker = "<!-- orch:ci-review -->"

CommentMarker identifies the one pull request comment `orch ci review --post` owns, so a re-run edits it instead of stacking a new one.

View Source
const Concurrency = `` /* 280-byte string literal not displayed */

Concurrency cancels a pull request's run when a newer push replaces it: orch force-pushes a task's retries, and the superseded run would otherwise go on to the end and bill for it. Pushes to the base branch are never cancelled. Every workflow orch writes carries it.

View Source
const PlaceholderStep = "Placeholder - no stack detected"

PlaceholderStep names the one step of the workflow `orch init` writes for a repository whose stack it cannot tell yet (#348).

View Source
const Repo = "Guria-Studio/orch"

Repo is where orch is released, for the review job's install step.

View Source
const ReviewTaskID = "ci-review"

ReviewTaskID names the review's dispatch. Under ORCH_FAKE_PROVIDER it is the canned response's file name: <dir>/<backend>/ci-review.out.

View Source
const WorkflowPath = ".github/workflows/orch-ci.yml"

WorkflowPath is the workflow orch writes and reads.

Variables

View Source
var AllChecks = Checks{Lint: true, Typecheck: true, Test: true, Build: true}

AllChecks runs every check the repo has.

ReviewBackends are the providers `orch ci review` runs.

View Source
var ReviewProviders = map[string]ReviewProvider{
	"claude": {Backend: "claude", Package: "@anthropic-ai/claude-code",
		Secrets: []string{"ANTHROPIC_API_KEY", "CLAUDE_CODE_OAUTH_TOKEN"}, DefaultModel: "sonnet"},
	"gemini": {Backend: "gemini", Package: "@google/gemini-cli",
		Secrets: []string{"GEMINI_API_KEY"}, DefaultModel: "gemini-2.5-flash"},
	"openai": {Backend: "codex", Package: "@openai/codex",
		Secrets: []string{"OPENAI_API_KEY"}, DefaultModel: "gpt-5.5"},
	"openrouter": {Backend: "opencode", Package: "opencode-ai",
		Secrets: []string{"OPENROUTER_API_KEY"}, ModelPrefix: "openrouter/"},
}

ReviewProviders are the providers the wizard offers, by the name a person types.

Functions

func Ask

func Ask(ctx context.Context, run contract.Runner, backend model.Backend, cliModel, prompt string, timeout time.Duration) (answer string, err error)

Ask runs one provider on prompt, read-only, through run, and returns its final answer. With engine.OneShot as run it gets the engine's own spawn and supervision (a process group, the timeout's SIGTERM then SIGKILL), and so honours ORCH_FAKE_PROVIDER.

func AskOnce

func AskOnce(ctx context.Context, once contract.Runner, taskID string, route model.RouteEntry, prompt string, timeout time.Duration) (answer string, err error)

AskOnce is Ask on a whole route, under taskID, through once: an engine.OneShot with its State set the spend is recorded under taskID, with its Gate the budget is checked first (#461). taskID is also the fake's canned response name.

func BuildPrompt

func BuildPrompt(checklist, diff string, cut []string) string

BuildPrompt assembles the reviewer's prompt: instructions, checklist, diff. cut names the files TruncateDiff shortened, so the reviewer does not report the missing half of one as a bug.

func BuildPromptFor added in v0.31.0

func BuildPromptFor(task, checklist, diff string, cut []string) string

BuildPromptFor is BuildPrompt with what the change is for (#539): task is the task's title, description and spec section, as markdown; "" leaves it out.

func CommentBody

func CommentBody(markdown string) string

CommentBody is the pull request comment for a rendered review: the marker first, and the text cut to fit GitHub's limit.

func Diff

func Diff(ctx context.Context, dir, base string) (string, error)

Diff is `git diff --merge-base <base>` in dir: what the pull request changes, against the point it branched from.

func ExitCode

func ExitCode(v Verdict, reviewErr error, blocking bool) int

ExitCode is the process exit code for a review: 0 unless blocking is set and the review either did not complete (reviewErr) or blocks. Without blocking a failed review is only a warning, so a provider that is down never holds up a merge.

func GateOf added in v0.31.0

func GateOf(label string) string

GateOf is the kind of check a command or step label runs, by the words Gates reads (tests first, then typecheck, lint, build); "" when it says none of them. The evidence bundle labels verify's commands with it (#520).

func Gates

func Gates(workflows []Workflow) []string

Gates names the kinds of check the workflows that run on pull requests amount to, from their jobs' and steps' names. A job whose name or id says review is a review, whatever its steps are called ("Build review input" is not a build). Workflows that do not run on pull requests check nothing a delivery goes through, and are ignored.

ponytail: word matching on labels; a step named oddly is missed rather than misread, and the operator's CI page still shows it by name.

func PRFromEvent

func PRFromEvent(path string) (int, error)

PRFromEvent reads the pull request number from a GitHub Actions event payload, the file GITHUB_EVENT_PATH names.

func PlaceholderOutgrown

func PlaceholderOutgrown(root string) bool

PlaceholderOutgrown reports whether root's workflow is still init's placeholder although the repository now has something to check — the tasks built the code since. `orch ci setup --force` proposes the real one.

func ReadOnlyArgv

func ReadOnlyArgv(p providers.Provider, req providers.Request) ([]string, error)

ReadOnlyArgv is the provider's own argv with its tool grant swapped for the read-only flags in readOnly. An adapter whose argv no longer has the flag being swapped is an error rather than a review that silently keeps it.

func Render

func Render(jobs []Job, opts Options) ([]byte, error)

Render writes the workflow for the jobs, or an error when there is nothing to check: an empty workflow would pass every PR while checking nothing.

func ReviewChecklist

func ReviewChecklist(st Stack) string

ReviewChecklist is the checklist written for a repository: the general rules, then the rules for the languages it has.

func ReviewProviderNames

func ReviewProviderNames() []string

ReviewProviderNames lists the providers, sorted, for prompts and errors.

func TruncateDiff

func TruncateDiff(diff string, limit int) (string, []string)

TruncateDiff cuts a diff larger than limit bytes, file by file. Small files are kept whole and the budget they leave is shared among the large ones, each cut at a line boundary and followed by a line saying so. It returns the diff and the names of the files it cut.

Types

type Checks

type Checks struct {
	Lint, Typecheck, Test, Build bool
}

Checks chooses which kinds of check the pipeline runs. A kind the repo does not have is skipped whatever this says.

type Finding

type Finding struct {
	Severity string `json:"severity"`
	File     string `json:"file,omitempty"`
	Line     int    `json:"line,omitempty"`
	Title    string `json:"title"`
	Detail   string `json:"detail,omitempty"`
}

Finding is one problem the reviewer reports.

type Job

type Job struct {
	ID      string
	Package Package
	Steps   []Step
}

Job is one job of the pipeline, for one package.

func Jobs

func Jobs(st Stack, checks Checks) []Job

Jobs lists the pipeline's jobs: one per package that has at least one chosen check, in the order Detect found them.

type Language

type Language string

Language is a toolchain family a package is built with.

const (
	Go     Language = "go"
	Node   Language = "node"
	Python Language = "python"
	Rust   Language = "rust"
	Make   Language = "make"
)

type Options

type Options struct {
	// BaseBranch is where pushes are also checked; "" means main.
	BaseBranch string
	Checks     Checks
	// Review adds an AI review job after the checks; nil adds none.
	Review *Review
	// Private leaves out the run on pushes to the base branch: GitHub bills a
	// private repository's minutes, and that run re-checks what its pull
	// request already did.
	Private bool
}

Options shape the generated workflow.

type Package

type Package struct {
	// Dir is the package's directory relative to the repo root, "." for the
	// root itself, always with forward slashes.
	Dir      string
	Language Language
	// Manager is how dependencies are installed: go, pnpm, yarn, npm, bun,
	// uv, poetry, pip, cargo, make.
	Manager string
	// Version is the toolchain version the repo pins (.nvmrc,
	// .python-version, ...), "" when it pins none.
	Version string
	// Install installs the dependencies; "" when nothing needs installing.
	Install string
	// The checks the repo has, as the command that runs each; "" when absent.
	Lint, Typecheck, Test, Build string
	// Workspace is true for a node package whose scripts cover its
	// workspace members (pnpm-workspace.yaml or package.json workspaces).
	Workspace bool
	// PnpmVersion is the pnpm major the repo declares in packageManager, ""
	// when it declares none.
	PnpmVersion string
	// Lockfile is the node lockfile's path from the repo root, "" when there
	// is none. setup-node's dependency cache refuses to run without one.
	Lockfile string
}

Package is one buildable unit of the repository.

type Review

type Review struct {
	Provider string // a ReviewProviders key
	Model    string
	// OrchVersion is the orch release the job installs, the one that wrote
	// the workflow; "" installs the latest release (a dev build).
	OrchVersion string
	// Blocking fails the review job, and so the PR's checks, on a blocking
	// finding.
	Blocking bool
}

Review is an AI review added to the pipeline.

func NewReview

func NewReview(provider, model string, blocking bool) (*Review, error)

NewReview validates a provider and model, filling the default model and the model prefix. An empty provider or "none" is no review: nil, nil.

type ReviewProvider

type ReviewProvider struct {
	// Backend is `orch ci review --provider`: the coding-agent CLI.
	Backend string
	// Package installs that CLI with npm on the runner.
	Package string
	// Secrets are the repository secrets the CLI reads; one is enough.
	Secrets []string
	// DefaultModel is suggested when none is given; "" means one is required.
	DefaultModel string
	// ModelPrefix is prepended to a model given without it.
	ModelPrefix string
}

ReviewProvider is one AI review provider as a person names it, and what the generated job needs to run it.

type Stack

type Stack struct {
	Packages []Package
	// Workflows are the files already under .github/workflows, sorted.
	Workflows []string
}

Stack is what Detect found.

func Detect

func Detect(root string) (Stack, error)

Detect reads the repository at root.

func (Stack) HasChecks

func (s Stack) HasChecks() bool

HasChecks reports whether the stack has anything a pipeline could run.

type Step

type Step struct {
	Name string
	Run  string
	// Uses runs an action instead of a command; With is its inputs.
	Uses string
	With map[string]string
}

Step is a named command, or an action when Uses is set.

type Verdict

type Verdict struct {
	Verdict  string    `json:"verdict"`
	Summary  string    `json:"summary"`
	Findings []Finding `json:"findings"`
}

Verdict is the reviewer's validated answer.

func ParseVerdict

func ParseVerdict(answer string) (Verdict, error)

ParseVerdict pulls the reviewer's JSON out of its answer and validates it.

Forgiving about the envelope, strict about the contents, as .github/review/parse-review.py is: a code fence or a sentence around the object is fine, and when the answer holds several objects (the schema echoed back, then the answer) the last one wins. A verdict or severity outside its enum, or a finding without a title, is an error.

func (Verdict) Blocks

func (v Verdict) Blocks() bool

Blocks reports whether the verdict should fail a job run with --blocking.

func (Verdict) Markdown

func (v Verdict) Markdown(by string, notes []string) string

Markdown renders the verdict for stdout and for the comment. by names the provider and model; notes are what the reader should know about how the review ran (no checklist, a diff that was cut).

type Workflow

type Workflow struct {
	File     string        `json:"file"`
	Name     string        `json:"name"`
	Triggers []string      `json:"triggers"`
	Jobs     []WorkflowJob `json:"jobs"`
	OnPRs    bool          `json:"runs_on_pull_requests"`
	// ParseFailed says why the file is not YAML GitHub can read. The file is
	// still listed: a broken workflow is exactly what a reader needs to see.
	ParseFailed string `json:"parse_error,omitempty"`
}

Workflow summarises one GitHub Actions workflow file: what triggers it and what its jobs run, by name. The operator's CI page shows it as is; the client portal reads which checks it amounts to (Gates).

func ReadWorkflows

func ReadWorkflows(dir string) ([]Workflow, error)

ReadWorkflows summarises every *.yml and *.yaml file in dir, sorted by name. A missing directory is no workflows, not an error.

type WorkflowJob

type WorkflowJob struct {
	ID    string   `json:"id"`
	Name  string   `json:"name"`
	Needs []string `json:"needs"`
	Steps []string `json:"steps"`
	// ParseFailed says why a job's body could not be read, e.g. a job that is
	// a string instead of a mapping. The job is still listed by its id.
	ParseFailed string `json:"parse_error,omitempty"`
}

WorkflowJob is one job, with its steps labelled by name, action or the first line of its command.

Jump to

Keyboard shortcuts

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