prompt

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DiffFilePathPlaceholder = "/tmp/roborev diff placeholder"

DiffFilePathPlaceholder is a sentinel path embedded in prebuilt prompts for oversized diffs. The worker replaces it with a real diff file path at execution time so the stored prompt remains reusable across retries.

View Source
const InRangeReviewsHeader = `` /* 360-byte string literal not displayed */

InRangeReviewsHeader introduces per-commit reviews within a range review

View Source
const InsightsSystemPrompt = `` /* 1967-byte string literal not displayed */

InsightsSystemPrompt is the instruction for analyzing review patterns

View Source
const MaxPromptSize = 250 * 1024

MaxPromptSize is the legacy maximum size of a prompt in bytes (250KB). New code should use Builder.maxPromptSize() which respects config.

View Source
const PreviousAttemptsForCommitHeader = `` /* 355-byte string literal not displayed */

PreviousAttemptsForCommitHeader introduces previous review attempts for the same commit

View Source
const PreviousAttemptsHeader = `` /* 357-byte string literal not displayed */

PreviousAttemptsHeader introduces previous addressing attempts section

View Source
const PreviousReviewsHeader = `` /* 478-byte string literal not displayed */

PreviousReviewsHeader introduces the previous reviews section

View Source
const ProjectGuidelinesHeader = `` /* 202-byte string literal not displayed */

ProjectGuidelinesHeader introduces the project-specific guidelines section

View Source
const SystemPromptAddress = `` /* 1018-byte string literal not displayed */

SystemPromptAddress is the instruction for addressing review findings

View Source
const SystemPromptDesignReview = `` /* 1270-byte string literal not displayed */

SystemPromptDesignReview is the base instruction for reviewing design documents. The input is a code diff (commit, range, or uncommitted changes) that is expected to contain design artifacts such as PRDs, task lists, or architectural proposals.

View Source
const SystemPromptDirty = `` /* 789-byte string literal not displayed */

SystemPromptDirty is the base instruction for reviewing uncommitted (dirty) changes

View Source
const SystemPromptRange = `` /* 875-byte string literal not displayed */

SystemPromptRange is the base instruction for commit range reviews

View Source
const SystemPromptSecurity = `` /* 1541-byte string literal not displayed */

SystemPromptSecurity is the instruction for security-focused reviews

View Source
const SystemPromptSingle = `` /* 870-byte string literal not displayed */

SystemPromptSingle is the base instruction for single commit reviews

View Source
const UserCommentsHeader = `` /* 223-byte string literal not displayed */

UserCommentsHeader introduces user-authored comments on a review.

Variables

View Source
var ErrDiffTruncatedNoFile = errors.New("diff too large to inline and no snapshot file available")

ErrDiffTruncatedNoFile is returned when the diff is too large to inline and no snapshot file path was provided. Callers should write the diff to a file and retry with BuildWithDiffFile.

Functions

func BuildInsightsPrompt added in v0.49.0

func BuildInsightsPrompt(data InsightsData) string

BuildInsightsPrompt constructs the full prompt for insights analysis. It prioritizes unaddressed (open) findings over addressed (closed) ones when truncating to fit within size limits.

func BuildSimple

func BuildSimple(repoPath, sha, agentName string) (string, error)

BuildSimple constructs a simpler prompt without database context

func FormatToolAttempts added in v0.51.0

func FormatToolAttempts(attempts []storage.Response) string

FormatToolAttempts renders automated tool responses (roborev-fix, roborev-refine) into a prompt section. Returns empty string when empty.

func FormatUserComments added in v0.51.0

func FormatUserComments(comments []storage.Response) string

FormatUserComments renders user-authored comments into a prompt section. Returns empty string when there are no comments.

func GetSystemPrompt added in v0.17.0

func GetSystemPrompt(agentName string, promptType string) string

GetSystemPrompt returns the system prompt for the specified agent and type. If a specific template exists for the agent, it uses that. Otherwise, it falls back to the default constant. Supported prompt types: review, range, dirty, address, design-review, run, security

func IsToolResponse added in v0.51.0

func IsToolResponse(r storage.Response) bool

IsToolResponse returns true when the response was left by an automated tool (roborev-fix, roborev-refine, etc.) rather than a human user.

func LoadGuidelines added in v0.49.0

func LoadGuidelines(repoPath string) string

LoadGuidelines loads review guidelines from the repo's default branch, falling back to filesystem config when the default branch has no .roborev.toml.

func SplitResponses added in v0.51.0

func SplitResponses(responses []storage.Response) (toolAttempts, userComments []storage.Response)

SplitResponses partitions responses into tool-generated attempts and user-authored comments based on the Responder field.

func WriteDiffSnapshot added in v0.51.0

func WriteDiffSnapshot(
	repoPath, gitRef string, excludes []string,
) (string, func(), error)

WriteDiffSnapshot writes the full diff for a git ref to a file in the repo's git dir. Returns the file path and a cleanup function.

Types

type Builder

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

Builder constructs review prompts

func NewBuilder

func NewBuilder(db *storage.DB) *Builder

NewBuilder creates a new prompt builder

func NewBuilderWithConfig added in v0.47.0

func NewBuilderWithConfig(
	db *storage.DB, globalCfg *config.Config,
) *Builder

NewBuilderWithConfig creates a prompt builder that also resolves global config settings (e.g., exclude_patterns).

func (*Builder) Build

func (b *Builder) Build(repoPath, gitRef string, repoID int64, contextCount int, agentName, reviewType, minSeverity string) (string, error)

Build constructs a review prompt for a commit or range with context from previous reviews. reviewType selects the system prompt variant (e.g., "security"); any default alias (see config.IsDefaultReviewType) uses the standard prompt.

func (*Builder) BuildAddressPrompt

func (b *Builder) BuildAddressPrompt(repoPath string, review *storage.Review, previousAttempts []storage.Response, minSeverity string) (string, error)

BuildAddressPrompt constructs a prompt for addressing review findings. When minSeverity is non-empty, a severity filtering instruction is injected before the findings section.

func (*Builder) BuildDirty

func (b *Builder) BuildDirty(repoPath, diff string, repoID int64, contextCount int, agentName, reviewType, minSeverity string) (string, error)

BuildDirty constructs a review prompt for uncommitted (dirty) changes. The diff is provided directly since it was captured at enqueue time. reviewType selects the system prompt variant (e.g., "security"); any default alias (see config.IsDefaultReviewType) uses the standard prompt.

func (*Builder) BuildDirtyWithSnapshot added in v0.51.0

func (b *Builder) BuildDirtyWithSnapshot(
	repoPath, diff string, repoID int64,
	contextCount int, agentName, reviewType, minSeverity string,
) (SnapshotResult, error)

BuildDirtyWithSnapshot builds a dirty review prompt, writing the diff to a snapshot file when it's too large to inline. The caller must call Cleanup (if non-nil) after the prompt is no longer needed.

func (*Builder) BuildWithAdditionalContext added in v0.50.0

func (b *Builder) BuildWithAdditionalContext(repoPath, gitRef string, repoID int64, contextCount int, agentName, reviewType, minSeverity, additionalContext string) (string, error)

BuildWithAdditionalContext constructs a review prompt with an optional caller-provided markdown context block inserted ahead of the current diff.

func (*Builder) BuildWithAdditionalContextAndDiffFile added in v0.51.0

func (b *Builder) BuildWithAdditionalContextAndDiffFile(repoPath, gitRef string, repoID int64, contextCount int, agentName, reviewType, minSeverity, additionalContext, diffFilePath string) (string, error)

BuildWithAdditionalContextAndDiffFile constructs a review prompt with caller-provided markdown context and an optional oversized-diff file reference for sandboxed Codex reviews.

func (*Builder) BuildWithDiffFile added in v0.51.0

func (b *Builder) BuildWithDiffFile(repoPath, gitRef string, repoID int64, contextCount int, agentName, reviewType, minSeverity, diffFilePath string) (string, error)

BuildWithDiffFile constructs a review prompt where a pre-written diff file is referenced for large diffs instead of git commands. This is used for Codex agents running in a sandboxed environment that cannot execute git directly.

func (*Builder) BuildWithSnapshot added in v0.51.0

func (b *Builder) BuildWithSnapshot(
	repoPath, gitRef string, repoID int64,
	contextCount int, agentName, reviewType, minSeverity string,
	excludes []string,
) (SnapshotResult, error)

BuildWithSnapshot builds a review prompt, automatically writing a diff snapshot file when the diff is too large to inline. The caller must call Cleanup (if non-nil) after the prompt is no longer needed. excludes are applied to the snapshot diff.

type InsightsData added in v0.49.0

type InsightsData struct {
	Reviews            []InsightsReview
	Guidelines         string
	RepoName           string
	Since              time.Time
	MaxReviews         int // Cap for number of reviews to include
	MaxOutputPerReview int // Cap for individual review output size
	MaxPromptSize      int // Overall prompt size budget (0 = use MaxPromptSize default)
}

InsightsData holds the data needed to build an insights prompt

type InsightsReview added in v0.49.0

type InsightsReview struct {
	JobID      int64
	Agent      string
	GitRef     string
	Branch     string
	FinishedAt *time.Time
	Output     string
	Responses  []storage.Response
	Closed     bool
	Verdict    string // "P" or "F"
}

InsightsReview is a simplified review record for the insights prompt

func InsightsReviewFromJob added in v0.49.0

func InsightsReviewFromJob(
	job storage.ReviewJob, output string, responses []storage.Response, closed bool,
) InsightsReview

InsightsReviewFromJob converts a ReviewJob (with verdict) to an InsightsReview. The review output must be fetched separately.

type ReviewContext

type ReviewContext struct {
	SHA       string
	Review    *storage.Review
	Responses []storage.Response
}

ReviewContext holds a commit SHA and its associated review (if any) plus responses

type SnapshotResult added in v0.51.0

type SnapshotResult struct {
	Prompt  string
	Cleanup func() // nil when no snapshot was written
}

SnapshotResult holds a prompt and an optional cleanup function for a diff snapshot file that was written during prompt construction.

Directories

Path Synopsis
Package analyze provides built-in analysis prompts for file-level reviews.
Package analyze provides built-in analysis prompts for file-level reviews.

Jump to

Keyboard shortcuts

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