Documentation
¶
Overview ¶
Package prstate fetches a PR's diff at pinned SHAs and builds the state the decision model sees.
Index ¶
Constants ¶
const MaxBatches = 16
MaxBatches caps patch batches per context, bounding cost per PR.
Variables ¶
var DefaultLimits = Limits{Question: jev.MaxQuestionTokens, Request: jev.MaxRequestTokens}
DefaultLimits are the provider's limits.
var DefaultRegistries = []string{
"registry.npmjs.org", "registry.yarnpkg.com", "pypi.org", "files.pythonhosted.org",
"index.crates.io", "static.crates.io", "rubygems.org", "pub.dev", "pub.dartlang.org",
}
DefaultRegistries are the hosts a lockfile may resolve packages from without holding the PR. Config adds to them.
var ErrHeadMoved = errors.New("PR head moved while listing files")
ErrHeadMoved means the PR head changed while files were being listed, so the file list may not match the scored SHA.
var ErrNoFiles = errors.New("no files to score after excludes")
ErrNoFiles means nothing is left to score after excludes.
Functions ¶
func IsLockfile ¶
IsLockfile reports whether p is a lockfile the check reads.
Types ¶
type AutoRun ¶
type AutoRun struct {
Path, What string
}
AutoRun is a file the diff changes that sets commands to run on their own on a developer's machine: editor tasks, dev containers, git hooks, and AI-agent hooks. Attacks use these to run code without anyone starting it (docs/calibration.md#safety). Any change to one holds, because a command edit or a trigger outside the patch's context would slip past a check of the trigger line alone.
type Call ¶
type Call struct {
Context rubric.Context
Questions []rubric.Question
State State
Batch int
Batches int
}
Call is one decision request. Batch and Batches are 1-based; an unbatched call has Batches == 1. Values from batches of one question are min-combined.
type File ¶
type File struct {
Path string `json:"path"`
PreviousPath string `json:"previous_path,omitempty"`
Status string `json:"status"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Patch string `json:"patch,omitempty"`
Changes int `json:"-"` // GitHub's count; above 0 with no patch means GitHub omitted it
}
File is one changed file. Patch is empty for excluded and unseen files.
type LockSource ¶
type LockSource struct {
Path, URL, Host string
}
LockSource is a package source a lockfile change adds that isn't one of the usual registries. Lockfiles are excluded from the model by default, so this check is the only thing that reads them.
type PR ¶
type PR struct {
Owner, Repo string
Number int
BaseSHA string
HeadSHA string
BaseRef string
HeadRef string
Title string
Body string
Labels []string
Author string
Fork bool
ChangedFiles int
}
PR identifies the scored PR. SHAs come from the event payload, never from a fresh read of the PR.
func FromPullRequest ¶
func FromPullRequest(owner, repo string, p *github.PullRequest) PR
FromPullRequest pins a PR from an event payload or API read.
type PRState ¶
type PRState struct {
Title string `json:"title"`
Body string `json:"body"`
Base string `json:"base"`
Head string `json:"head"`
Labels []string `json:"labels,omitempty"`
LinkedIssues []string `json:"linked_issues,omitempty"`
}
PRState is the `pr` field of state.
type Raw ¶
type Raw struct {
PR PR
Files []File
LinkedIssues []string
Partial []string // why GitHub's file list is incomplete
}
Raw is what Fetch reads from GitHub, before exclude globs. Replay stores it so a later run can build the snapshot without GitHub.
type Snapshot ¶
type Snapshot struct {
PR PR
LinkedIssues []string
Files []File // patches the model sees
Excluded []File // matched exclude globs; stats only
Unseen []Unseen
// Partial lists reasons the model's view is incomplete. A partial view
// never approves.
Partial []string
// LockSources are lockfile package sources outside DefaultRegistries,
// read from patches before exclude globs drop them.
LockSources []LockSource
// AutoRuns are commands the diff sets to run on their own on a
// developer's machine.
AutoRuns []AutoRun
}
Snapshot is everything fetched for one scoring run.
type State ¶
type State struct {
PR *PRState `json:"pr,omitempty"`
Files []File `json:"files"`
Excluded []File `json:"excluded"`
Note string `json:"note,omitempty"`
}
State is the JSON object sent as the decision request's state. The diff context has no `pr` field, so author-written prose can't sway it.