Documentation
¶
Overview ¶
Package review runs a directory of prompts as independent reviews, each on its own sidecar.
Index ¶
- Constants
- Variables
- func ClientExec(ctx context.Context, entry *sidecar.PoolEntry, script string, ...) (int, error)
- func DetachEnv(circleCIToken string, opts Options) map[string]string
- func DetachScript(s DetachSpec) string
- func IsPromptFile(name string) bool
- func PoolSize(parallelism, prompts int) int
- func ReadScript(runDir string) string
- func WaitReady(ctx context.Context, waitSynced func(context.Context) error) error
- type Credential
- type DetachSpec
- type Execer
- type Options
- type ProgressEvent
- type Prompt
- type PromptState
- type Result
- type RunStatus
Constants ¶
const ( ResultFile = "review.json" // the --json report LogFile = "review.err" // progress and errors ExitFile = "exit" // exit code; absent while the run is going PidFile = "pid" // the run's shell; lets a reader tell a dead run from a live one )
Files a detached run leaves in its run directory.
const ( // ExitNoReview means the chunk on the primary runs but has no review command. ExitNoReview = 64 // ExitBadBinary means the chunk on the primary cannot be executed at all, // for example a build for another OS or architecture. ExitBadBinary = 66 )
Exit codes of the detach script.
const ( RunRunning = "running" RunDone = "done" RunMissing = "missing" RunDied = "died" // no exit code, and the run's process is gone )
Run states reported by ReadScript.
const DefaultDir = ".chunk/reviews"
DefaultDir is where prompts are read from, relative to the project root, when no directory is given.
const DefaultTimeout = 15 * time.Minute
DefaultTimeout bounds one review. Claude explores the repo before answering, so this is minutes rather than the seconds a single API call would take.
const InstallRelease = `` /* 203-byte string literal not displayed */
InstallRelease is the shell that installs the latest released chunk into $HOME on a Linux sidecar. Used when no local binary is uploaded.
const PoolName = "review"
PoolName is the sidecar pool name for reviews. It keys the persisted pool state in .chunk/review-pool.json, so a later run — or a later pass in the same run — picks up the same warm sidecars instead of booting new ones.
const PrimaryPoolName = "review-primary"
PrimaryPoolName names the one-sidecar pool that hosts a detached review. It differs from PoolName so the primary's own pool of reviewers, which lives in the primary's checkout, never collides with the laptop's state.
const RunsDir = ".chunk-review"
RunsDir is where detached runs keep their files on the primary, relative to the sidecar user's home.
const UploadInstall = `gunzip > "$HOME/chunk.new" && chmod +x "$HOME/chunk.new" && mv -f "$HOME/chunk.new" "$HOME/chunk"`
UploadInstall is the shell that installs a binary streamed on stdin, gzipped, as $HOME/chunk. It writes a new file and moves it into place, because writing over a chunk that an earlier detached review is still running fails with "text file busy".
Variables ¶
var ErrClaudeMissing = errors.New("claude is not installed on the sidecar")
ErrClaudeMissing is returned when a sidecar has no claude binary.
var ErrCredentialRejected = errors.New("anthropic rejected the credential")
ErrCredentialRejected is returned when Anthropic rejects the credential.
var ErrNoPrompts = errors.New("no prompts found")
ErrNoPrompts is returned when a prompts directory holds nothing to review.
Functions ¶
func ClientExec ¶
func ClientExec(ctx context.Context, entry *sidecar.PoolEntry, script string, env map[string]string, onOutput circleci.OutputFn) (int, error)
ClientExec runs scripts through the pool entry's CircleCI client.
func DetachEnv ¶ added in v0.7.195
DetachEnv is the environment the primary's review runs with: the credentials its own chunk needs to create the reviewer sidecars and to run Claude on them.
func DetachScript ¶ added in v0.7.195
func DetachScript(s DetachSpec) string
DetachScript builds the shell script that starts the review on the primary and returns at once. The review runs under nohup and setsid so it outlives the exec that started it; its report, log and exit code land in the run directory, which is printed as the script's last line.
func IsPromptFile ¶ added in v0.7.195
IsPromptFile reports whether name has an extension that LoadPrompts reads.
func PoolSize ¶
PoolSize picks how many sidecars to boot: one per prompt, capped at the requested parallelism. Booting more sidecars than prompts only bills idle machines, since each review occupies exactly one sidecar.
func ReadScript ¶ added in v0.7.195
ReadScript builds the shell script that reports a detached run: a STATUS line first, then the report once the run has finished or the tail of its log while it is still going.
func WaitReady ¶
WaitReady blocks until the pool's background clone creation and sync have finished, via waitSynced (the pool's WaitSynced), and reports any member that failed.
sidecar.NewPool returns as soon as its members exist, while reused members may still be syncing in the background. Waiting here makes a failed sync surface before any review starts, rather than as one review failing partway through a pass. It holds no members while waiting: the pool reports a failed member through Acquire only once nothing is checked out.
Types ¶
type Credential ¶ added in v0.7.194
Credential is the Claude credential a review authenticates with. EnvVar is the variable claude reads it from, so only one of the two is ever sent and a stale one cannot shadow the other.
type DetachSpec ¶ added in v0.7.195
type DetachSpec struct {
RunID string
RepoPath string // checkout on the primary
OrgID string
PromptsDir string // relative to RepoPath; empty for the default
Parallelism int
Model string
Timeout time.Duration
Image string // snapshot for the primary's reviewer sidecars; empty for its config default
DestroyPool bool // delete the primary's reviewer sidecars when the review ends
// Install is a shell fragment that puts chunk at $HOME/chunk, run before
// the review starts. Empty when the binary is already there.
Install string
}
DetachSpec describes the review the primary sidecar runs.
func (DetachSpec) RunDir ¶ added in v0.7.195
func (s DetachSpec) RunDir() string
RunDir returns the run's directory as a path relative to the sidecar home.
type Execer ¶
type Execer func(ctx context.Context, entry *sidecar.PoolEntry, script string, env map[string]string, onOutput circleci.OutputFn) (exitCode int, err error)
Execer runs a shell script on a sidecar and streams its output.
type Options ¶
type Options struct {
Credential Credential
// BaseURL is forwarded to claude when it is not Anthropic's own, so a
// credential issued by a gateway is sent to that gateway.
BaseURL string
Model string // optional; claude's default when empty
Timeout time.Duration // per review; DefaultTimeout when zero
StatusFn iostream.StatusFunc
ProgressFn func(ProgressEvent) // optional; called on each prompt state change
}
Options configures one review pass.
type ProgressEvent ¶ added in v0.7.194
type ProgressEvent struct {
Prompt string
SidecarID string
State PromptState
Duration time.Duration
Error string
}
ProgressEvent reports a state change for one prompt.
type Prompt ¶
Prompt is one review to run. Name is the file name without its extension and identifies the review in output across passes.
func LoadPrompts ¶
LoadPrompts reads every prompt file directly inside dir, sorted by name so runs are reproducible. Subdirectories are not descended into, and files that are empty after trimming whitespace are skipped rather than run as blank reviews.
type PromptState ¶ added in v0.7.194
type PromptState int
PromptState is the lifecycle state of one review in a pass.
const ( StateQueued PromptState = iota // waiting for a sidecar StateRunning // executing on a sidecar StateDone // completed successfully StateFailed // completed with error )
Prompt lifecycle states.
type Result ¶
type Result struct {
Prompt string
SidecarID string
Output string
Error string
Duration time.Duration
}
Result is the outcome of one prompt in one pass. Output and Error are not exclusive: a review that fails partway keeps what it produced.
func RunPass ¶
func RunPass(ctx context.Context, acquire func(context.Context) (*sidecar.PoolEntry, error), release func(*sidecar.PoolEntry), exec Execer, prompts []Prompt, opts Options) ([]Result, error)
RunPass runs every prompt once, each on a sidecar checked out with acquire and returned with release (the pool's Acquire and Release), and returns results in prompt order for every prompt that started. Per-prompt failures are recorded in Result.Error; the returned error is for failures that stop the pass itself.
A missing claude binary or a rejected credential stops the pass rather than being recorded per prompt: every sidecar in a pool shares one image and one credential, so either would fail every review the same way.
type RunStatus ¶ added in v0.7.195
type RunStatus struct {
State string // RunRunning, RunDone, RunMissing or RunDied
ExitCode int // meaningful when State is RunDone
Body string // the report when done, the log tail when running
Log string // the log tail when done
}
RunStatus is a detached run as ReadScript reported it.