Documentation
¶
Overview ¶
Package run owns the on-disk layout of review runs: paths, references, atomic writes and locking.
Index ¶
- Constants
- func CreateRun(dir string, target Target, diff, draftJSON []byte, optional map[string][]byte) (err error)
- func DataRoot(getenv func(string) string) (string, error)
- func DiffSHA256(diff []byte) string
- func EncodeOutline(files []OutlineEntry) ([]byte, error)
- func HasReceipt(dir string) (bool, error)
- func HasReturn(dir string) (bool, error)
- func LoadDiff(dir string, target Target) (*diff.Diff, error)
- func LoadOutline(dir string) (diff.Outline, error)
- func LocalDir(root string, n int) string
- func LocalRoot(root string) string
- func Newest(root, owner, repo string, number int) (int, error)
- func ReadDiff(dir string, target Target) ([]byte, error)
- func ReadJSON(path string, v any, schema int) error
- func RecordRefusal(path string, cause error) error
- func Rounds(root, owner, repo string, number int) ([]int, error)
- func RunDir(root, owner, repo string, number, round int) string
- func RunsDir(root string) string
- func SessionOpen(dir string) (bool, error)
- func ValidateModel(model string) error
- func ValidateSource(source string) error
- func WriteFileAtomic(path string, data []byte) (err error)
- func WriteJSONAtomic(path string, v any) error
- type Entry
- type Held
- type LocalEntry
- type LocalFile
- type LocalSkipped
- type LocalTarget
- type LocalTargetFile
- type Outline
- type OutlineEntry
- type Ref
- func NextLocal(root, cmd string, getenv func(string) string, target Target, ...) (string, Ref, error)
- func OpenSession(root string, ref Ref) (Ref, bool, error)
- func ParseRef(s string) (Ref, error)
- func ResolveBranch(ctx context.Context, root, clone string, gh func() (github.Client, error)) (Ref, error)
- func ResolveRef(root string, ref Ref) (string, Ref, error)
- type Session
- type Target
Constants ¶
const CommentsFile = "comments.json"
CommentsFile holds the feedback capture read from other reviewers. See publish.Comments.
const KindLocal = "local"
const ModelPattern = `^[a-z0-9][a-z0-9._/:-]*$`
ModelPattern admits ids like anthropic/claude-sonnet-5 and, like SourcePattern, keeps > out because loupe-meta carries the value unescaped inside an HTML comment. ValidateModel refuses -- for the same reason.
const OutlineFile = "outline.json"
OutlineFile holds the headings of each Markdown file the diff changes, read at the head, so add resolves a heading anchor from the run alone.
const OutlineSchema = 1
Bump on any field change, so an older loupe refuses the file instead of dropping fields (docs/versioning.md).
const PreviousFile = "previous.json"
PreviousFile holds the round capture read back from GitHub. See publish.Previous.
const SourcePattern = `^[a-z0-9][a-z0-9._-]*(@[0-9][0-9A-Za-z.+-]*)?$`
SourcePattern keeps a source to one token without > because loupe-meta carries it unescaped inside an HTML comment. ValidateSource also refuses --, which RE2 cannot express, for the same reason. LoadTarget applies it to stored runs, so tightening it would refuse runs captured under the looser rule.
const TargetSchema = 3
Bump on any field change, so an older loupe refuses the file instead of dropping fields (docs/versioning.md).
Variables ¶
This section is empty.
Functions ¶
func CreateRun ¶
func CreateRun(dir string, target Target, diff, draftJSON []byte, optional map[string][]byte) (err error)
CreateRun takes the draft and the optional files, such as PreviousFile and CommentsFile, as bytes because run must not import draft or publish. The run appears complete or not at all: files are written to a sibling temp directory that is renamed into place.
func DiffSHA256 ¶
DiffSHA256 is the fingerprint target.json records for pr.diff.
func EncodeOutline ¶
func EncodeOutline(files []OutlineEntry) ([]byte, error)
EncodeOutline returns the file capture stores; run takes bytes in CreateRun.
func HasReceipt ¶
func HasReturn ¶
HasReturn reports whether the run directory contains a return.json, which seals the run.
func LoadOutline ¶
LoadOutline returns nil for a run captured before heading anchors, and refuses a damaged or newer file as ReadJSON does.
func ReadDiff ¶
ReadDiff returns pr.diff only when it still matches the fingerprint capture recorded, so a truncated or edited diff cannot silently change which locations are valid, what the review shows, or what a pipeline hands its reviewer.
func ReadJSON ¶
ReadJSON reads a run file whose schema is from 1 up to schema. It refuses a damaged record rather than repairing it, so the human can inspect what went wrong, and refuses a newer one as a loupe too old to read it. It decodes every accepted schema into the current struct, so the first bump that removes or redefines a field MUST add a migration step here (docs/versioning.md).
func RecordRefusal ¶
RecordRefusal refuses a damaged run file, naming it and a command to inspect it; loupe never repairs one.
func Rounds ¶
Rounds ignores non-numeric entries such as the temp directories CreateRun leaves while it works.
func SessionOpen ¶
SessionOpen reports whether any review of the run is running: an exclusive flock fails only while one holds it.
func ValidateModel ¶
ValidateModel accepts the empty model, which means none.
func ValidateSource ¶
ValidateSource accepts the empty source, which means none.
func WriteFileAtomic ¶
WriteFileAtomic leaves either the old or the new content at path, never a partial file, even across a crash.
func WriteJSONAtomic ¶
Types ¶
type Held ¶
type Held struct {
// contains filtered or unexported fields
}
func Lock ¶
Lock takes the run's exclusive flock. The kernel drops a flock when its holder dies, so a timeout means a live contender or a wedged process, never a leftover from a crash.
func LockNotifying ¶
LockNotifying is Lock that calls busy, when set, each time it finds the lock held, so a test can order a race on the lock instead of sleeping and hoping the other process got there first.
type LocalEntry ¶
LocalEntry is returned by WalkLocal for each numeric local run directory.
func WalkLocal ¶
func WalkLocal(root string) ([]LocalEntry, error)
WalkLocal returns every local run in numeric order, skipping non-numeric and non-directory entries.
type LocalSkipped ¶
type LocalTarget ¶
type LocalTarget struct {
N int `json:"n"`
Prefix string `json:"prefix"`
Repository string `json:"repository,omitempty"`
Capture string `json:"capture"`
Root string `json:"root"`
Branch string `json:"branch,omitempty"`
BaseRef string `json:"baseRef,omitempty"`
MergeBase string `json:"mergeBase,omitempty"`
Files []LocalFile `json:"files"`
Skipped []LocalSkipped `json:"skipped"`
}
type LocalTargetFile ¶
type LocalTargetFile struct {
Schema int `json:"schema"`
Kind string `json:"kind"`
Title string `json:"title,omitempty"`
Applier string `json:"applier,omitempty"`
Source string `json:"source,omitempty"`
Model string `json:"model,omitempty"`
CapturedAt time.Time `json:"capturedAt"`
DiffSHA256 string `json:"diffSha256"`
Local LocalTarget `json:"local"`
}
LocalTargetFile is the on-disk format for local-run target.json. Local targets marshal through this struct so that PR-only fields (owner, repo, round, etc.) are absent from the file.
type Outline ¶
type Outline struct {
Schema int `json:"schema"`
// Files lists every changed Markdown file that is neither deleted nor binary, in diff order, including one with no
// headings, so a missing path is damage rather than a file without headings.
Files []OutlineEntry `json:"files"`
}
Outline is written once by capture and never changed.
type OutlineEntry ¶
type Ref ¶
type Ref struct {
Owner string
Repo string
Number int
Round int
// Local is the local run number (1-based); non-zero for local refs.
Local int
// Prefix is the display-only repository prefix recorded in the target; never checked on input.
Prefix string
}
Ref names a run. Round 0 means the newest round of the pull request. Local > 0 means a local run.
func NextLocal ¶
func NextLocal(root, cmd string, getenv func(string) string, target Target, diff, draftJSON []byte, optional map[string][]byte) (string, Ref, error)
NextLocal allocates the next local run number under a lock, writes n+1 to local/next, and creates the run directory through CreateRun. target.Local must not be nil; NextLocal sets its N field before writing.
func OpenSession ¶
OpenSession reports a review running on any round of ref's pull request: the resolved run first, then the others newest first. A new round is a new run, so a per-run probe would let a second pane open on the same pull request. For local refs, only that run's directory is probed.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a running review's shared flock on the run. The kernel drops it when the process ends by any route, so an open session is always a live one; several reviews of one run can hold it at once.
func HoldSession ¶
type Target ¶
type Target struct {
Schema int `json:"schema"`
Owner string `json:"owner"`
Repo string `json:"repo"`
Number int `json:"number"`
URL string `json:"url"`
Title string `json:"title"`
Author string `json:"author"`
Viewer string `json:"viewer"`
// BaseSHA and HeadSHA come from the API and were verified against the fetched refs.
BaseSHA string `json:"baseSha"`
HeadSHA string `json:"headSha"`
// Round is 1-based, one higher than any existing round for the pull request.
Round int `json:"round"`
// PreviousRound is Round-1 when any earlier round exists, published or not; lineage only.
PreviousRound int `json:"previousRound,omitempty"`
CapturedAt time.Time `json:"capturedAt"`
ClonePath string `json:"clonePath"`
// BaseRef and HeadRef are refs/loupe/<owner>/<repo>/<number>/<round>/{base,head}.
BaseRef string `json:"baseRef"`
HeadRef string `json:"headRef"`
// MergeBaseSHA is the merge base of BaseRef and HeadRef, the commit pr.diff compares the head against.
MergeBaseSHA string `json:"mergeBaseSha"`
DiffSHA256 string `json:"diffSha256"`
// Source names what filed the findings, as name[@version]; empty when capture was given none.
Source string `json:"source,omitempty"`
// Model is the reviewer's model id as the caller names it; empty when capture was given none. Provenance only.
Model string `json:"model,omitempty"`
// PRState is the pull request's state as GitHub reported it at capture, open or closed; empty before schema 2.
PRState string `json:"prState,omitempty"`
// Kind is KindLocal for local runs; empty for PR runs.
Kind string `json:"kind,omitempty"`
// Applier names the agent that will apply changes; local runs only.
Applier string `json:"applier,omitempty"`
// Local holds the local-run-specific fields; nil for PR runs.
Local *LocalTarget `json:"local,omitempty"`
}
Target is written once by capture and never changed.
func LoadTarget ¶
func (Target) MarshalJSON ¶
MarshalJSON writes local targets as LocalTargetFile and PR targets as the standard struct.