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
- Variables
- func Ask(ctx context.Context, run contract.Runner, backend model.Backend, ...) (answer string, err error)
- func AskOnce(ctx context.Context, once contract.Runner, taskID string, ...) (answer string, err error)
- func BuildPrompt(checklist, diff string, cut []string) string
- func BuildPromptFor(task, checklist, diff string, cut []string) string
- func CommentBody(markdown string) string
- func Diff(ctx context.Context, dir, base string) (string, error)
- func ExitCode(v Verdict, reviewErr error, blocking bool) int
- func GateOf(label string) string
- func Gates(workflows []Workflow) []string
- func PRFromEvent(path string) (int, error)
- func PlaceholderOutgrown(root string) bool
- func ReadOnlyArgv(p providers.Provider, req providers.Request) ([]string, error)
- func Render(jobs []Job, opts Options) ([]byte, error)
- func ReviewChecklist(st Stack) string
- func ReviewProviderNames() []string
- func TruncateDiff(diff string, limit int) (string, []string)
- type Checks
- type Finding
- type Job
- type Language
- type Options
- type Package
- type Review
- type ReviewProvider
- type Stack
- type Step
- type Verdict
- type Workflow
- type WorkflowJob
Constants ¶
const ( VerdictApprove = "approve" VerdictComment = "comment" VerdictRequestChanges = "request_changes" SeverityBlocking = "blocking" SeverityMinor = "minor" )
The verdicts and severities a reviewer may answer with.
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.
const BuiltinChecklist = `` /* 420-byte string literal not displayed */
BuiltinChecklist is what the review applies when the repository has no checklist of its own.
const ChecklistPath = ".github/orch-review.md"
ChecklistPath is the review checklist `orch ci setup` writes and `orch ci review` reads by default.
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.
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.
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).
const Repo = "Guria-Studio/orch"
Repo is where orch is released, for the review job's install step.
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.
const WorkflowPath = ".github/workflows/orch-ci.yml"
WorkflowPath is the workflow orch writes and reads.
Variables ¶
AllChecks runs every check the repo has.
var ReviewBackends = []model.Backend{ model.BackendClaude, model.BackendGemini, model.BackendCodex, model.BackendOpencode, }
ReviewBackends are the providers `orch ci review` runs.
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 ¶
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
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 ¶
CommentBody is the pull request comment for a rendered review: the marker first, and the text cut to fit GitHub's limit.
func Diff ¶
Diff is `git diff --merge-base <base>` in dir: what the pull request changes, against the point it branched from.
func ExitCode ¶
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
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 ¶
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 ¶
PRFromEvent reads the pull request number from a GitHub Actions event payload, the file GITHUB_EVENT_PATH names.
func PlaceholderOutgrown ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 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.
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.
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 ¶
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.
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 ¶
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.