clireview

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: GPL-3.0 Imports: 14 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 clireview is the shared implementation of CLI-tool-backed review providers. The concrete providers (claude-cli, gemini-cli, codex-cli) live in their own packages under internal/provider/ — they only declare a Spec and call clireview.New to get a working Backend that implements provider.Provider plus the provider.PlainTextEmitter marker.

Why a shared package: the three CLIs differ only in their binary name and how they accept a one-shot prompt on the command line. Everything else — registering with the provider registry, running the subprocess, surfacing PATH-not-found and exit-non-zero as translatable errors, returning a provider.Response with the raw CLI output as Content — is identical.

CLI providers deliberately have NO API key, NO model selection (the host CLI manages that), and NO per-call cost estimate (the host CLI bills against the user's existing subscription). The review pipeline branches on provider.PlainTextEmitter to skip the JSON contract path, retry-once, and the cards/markdown renderer.

Index

Constants

This section is empty.

Variables

View Source
var ErrArgTooLong = errors.New("clireview: command line exceeds the platform argument limit")

ErrArgTooLong is matched (errors.Is) by every ArgTooLongError.

Functions

This section is empty.

Types

type ArgKind added in v1.21.1

type ArgKind int

ArgKind says which command-line budget a prompt broke.

const (
	// ArgFits: within every budget.
	ArgFits ArgKind = iota
	// ArgSingleTooLong: one argument (the prompt) is over the per-argument
	// cap, or on Windows the whole command line is over its cap.
	ArgSingleTooLong
	// ArgTotalTooLong: no single argument is over the cap but argv plus the
	// environment together are over the POSIX total budget — the environment
	// is part of the problem, so narrowing the diff may not be enough.
	ArgTotalTooLong
	// ArgRejectedByOS: exec failed with E2BIG although the estimate said the
	// command line fits (unusual stack rlimit, large environment). No limit is
	// known, so none is quoted.
	ArgRejectedByOS
)

func ArgLimit added in v1.21.1

func ArgLimit(goos string, args, env []string) (size, limit int, kind ArgKind)

ArgLimit estimates the OS command-line footprint of args (argv including argv[0]) plus env and reports which conservative platform budget, if any, it breaks. goos is a parameter (callers pass runtime.GOOS) so every platform's arithmetic is unit-testable on any host. size and limit are in bytes (characters on Windows). For ArgSingleTooLong on POSIX, size is the largest argument against the per-argument cap; for ArgTotalTooLong it is the whole argv + environment footprint against the total budget; for ArgFits they are the total footprint and total budget.

type ArgTooLongError added in v1.21.1

type ArgTooLongError struct {
	Provider string
	Kind     ArgKind
	Size     int // bytes (characters on Windows) measured
	Limit    int // the budget that was exceeded; 0 when the OS rejected it unpredicted
	// contains filtered or unexported fields
}

ArgTooLongError reports a prompt that cannot be passed on the command line, either caught by the preflight or reported by the OS as E2BIG. Error() already carries the localized, user-facing text.

func (*ArgTooLongError) Error added in v1.21.1

func (e *ArgTooLongError) Error() string

func (*ArgTooLongError) Unwrap added in v1.21.1

func (e *ArgTooLongError) Unwrap() error

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend is a provider.Provider + provider.PlainTextEmitter built around a single Spec. Construct via New; callers don't need to touch the struct directly.

versionOnce + versionMemo cache the result of the host CLI's version query for the lifetime of the process. DefaultModel is on every cache-key computation, so paying the subprocess cost more than once per process startup would be wasteful — and the version can't change underneath us mid-run anyway.

func New

func New(spec Spec) *Backend

New returns a Backend ready to register with the provider registry. Validation of the Spec is deferred to actual use (Review, TestConnection) so a missing binary doesn't crash init().

func (*Backend) ContextWindow

func (b *Backend) ContextWindow(string) int

ContextWindow is informational for CLI providers — we don't gate the request on it because the host CLI handles its own context management. We return a generous default so the dry-run footer doesn't read "0".

func (*Backend) DefaultModel

func (b *Backend) DefaultModel() string

DefaultModel returns a stable identifier for the cache key. CLI tools don't expose model selection to us, so we tag entries with the binary name + detected version. Across CLI upgrades the version changes and cached entries cleanly invalidate.

func (*Backend) EmitsPlainText

func (b *Backend) EmitsPlainText()

EmitsPlainText implements provider.PlainTextEmitter — the marker interface review.go uses to branch into the CLI-output path.

func (*Backend) EstimateTokens

func (b *Backend) EstimateTokens(s string) int

EstimateTokens uses the shared chars/4 heuristic. CLI tools usually don't expose tokenizers we can call from outside their process, so the approximation has to do for the cost preflight and context-window gate.

func (*Backend) Name

func (b *Backend) Name() string

func (*Backend) Pricing

func (b *Backend) Pricing(string) provider.Pricing

Pricing is zero for CLI providers — the user pays through their host-CLI subscription (Claude Pro, Gemini Advanced, ChatGPT Plus, …), not per-token to us. The cost preflight short-circuits on zero pricing, and the verbose footer shows "—" instead of a token count.

func (*Backend) Review

func (b *Backend) Review(ctx context.Context, req provider.Request) (provider.Response, error)

Review invokes the host CLI with the combined system + user prompt, captures stdout, and returns it verbatim as the Response Content. Token usage is zeroed (the CLI doesn't expose it) and Model is set to the resolved DefaultModel so the cache key invalidates on CLI upgrades.

The review pipeline checks provider.PlainTextEmitter before calling, so this is only invoked when the caller is committed to the CLI path — no JSON parsing follows.

func (*Backend) SetTimeout added in v1.16.0

func (b *Backend) SetTimeout(d time.Duration)

SetTimeout implements provider.TimeoutSetter, replacing the Spec's per-invocation cap with the user's --timeout / review.timeout value. Without it a host CLI chewing through a large diff would still be killed at the Spec default no matter how much time the user allowed, because a context deadline can only shorten the window. A non-positive d is ignored so callers can pass "unset" unconditionally.

func (*Backend) TestConnection

func (b *Backend) TestConnection(ctx context.Context) error

TestConnection verifies the binary is on PATH and runs its version command (when defined). A failed lookup or non-zero exit from the version command surface as the catalog-translatable errors at the CLI layer.

type Spec

type Spec struct {
	// Name is the provider name as it appears in the registry,
	// `commitbrief providers list`, and the `--provider` flag —
	// e.g. "claude-cli", "gemini-cli". The user-facing `--cli`
	// shorthand maps "claude" → "claude-cli" by appending "-cli".
	Name string

	// Binary is the executable name expected on PATH, e.g. "claude",
	// "gemini", "codex". `exec.LookPath` resolves it.
	Binary string

	// PromptArgs returns the argv slice (excluding the binary itself)
	// for a one-shot, non-interactive invocation that prints the
	// model's response to stdout and exits. Implementations should
	// disable colors and tool use where possible so the output stays
	// machine-friendly.
	//
	// When [UseStdin] is true the prompt argument is the empty string
	// and PromptArgs returns *only* the flag/positional combo that
	// makes the host CLI read its prompt from stdin (e.g. claude's
	// `-p -`). The Backend then pipes the combined prompt into the
	// subprocess's stdin instead of embedding it in argv.
	//
	// withContext is the --with-context signal (ADR-0017). When true the
	// adapter appends the minimal read-only capability flags its host CLI
	// needs to read project files beyond the diff (e.g. claude's
	// `--allowedTools Read,Grep,Glob`, gemini's `--approval-mode plan
	// --skip-trust`); codex already permits reads under its read-only
	// sandbox and adds nothing. When false the adapter returns exactly the
	// diff-only argv it always has, so existing behavior is unchanged.
	// Write/network-mutation capability is never granted either way.
	PromptArgs func(prompt string, withContext bool) []string

	// UseStdin selects the stdin transport for the prompt. UC-24 in
	// PATCH_ROADMAP: large prompts (mid-size diffs + rules) exceed the
	// platform ARG_MAX limit when embedded in argv, surfacing as
	// `argument list too long` on Linux/macOS at ~128KB. Piping the
	// prompt via stdin sidesteps the limit entirely.
	//
	// Adapter authors: only set this true when you've confirmed the
	// host CLI reliably reads from stdin in one-shot mode.
	UseStdin bool

	// CheckArgSize opts the provider into the pre-exec command-line size
	// preflight (see [ArgLimit]). Set it for adapters that embed the whole
	// prompt in argv and have no stdin transport (gemini-cli): an oversized
	// prompt is then rejected before the subprocess is started, with an
	// actionable, localized [ArgTooLongError] instead of the OS's opaque
	// `argument list too long`. It is ignored when UseStdin is true, since
	// the prompt is not on the command line then.
	CheckArgSize bool

	// VersionArgs prints the CLI version and exits. Used by
	// TestConnection to confirm the binary works and by the cache
	// key to invalidate cached entries across CLI upgrades. Optional;
	// if nil, version is "" and cache keys can't differentiate
	// across upgrades.
	VersionArgs []string

	// Timeout caps a single CLI invocation. CLIs sometimes hang on
	// rate limits or network issues; we'd rather surface a clear
	// error than block the user indefinitely. Zero means no timeout.
	Timeout time.Duration
}

Spec describes one CLI backend. Each concrete provider package fills this in once and passes it to New.

Jump to

Keyboard shortcuts

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