state

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Save

func Save(state *State) error

Save writes the given State to disk.

Types

type AIReview

type AIReview struct {
	Summary  string `json:"summary"`            // rendered final review text (legacy: free-form markdown)
	Findings string `json:"findings,omitempty"` // per-batch raw findings (PR-level only)

	// Structured review output — populated by Phase 5+ review flows.
	// When present, the TUI renders this instead of the legacy Summary field.
	Structured *ReviewOutput `json:"structured,omitempty"`

	// DiffSnapshot records the DiffHash of each file at the time the review
	// was generated. Used to detect staleness when diffs change after a review.
	DiffSnapshot map[string]string `json:"diff_snapshot,omitempty"`

	// SecurityDigest is the AOI pre-scan summary injected into review prompts.
	// Persisted so the TUI can display it even after the review is cached.
	SecurityDigest string `json:"security_digest,omitempty"`
}

AIReview stores the result of an AI review for a file or the overall PR.

type FileState

type FileState struct {
	Status          ReviewStatus    `json:"status"`
	DiffHash        string          `json:"diff_hash"`
	Chat            []Message       `json:"chat,omitempty"`
	Purpose         string          `json:"purpose,omitempty"`           // AI-generated description of what the file does
	BatchFindings   string          `json:"batch_findings,omitempty"`    // cached findings from PR-level batch review
	AOIResults      json.RawMessage `json:"aoi_results,omitempty"`       // cached AOI scan result (AOIScanResult JSON)
	AOIContextLines int             `json:"aoi_context_lines,omitempty"` // context lines used when AOI was generated
}

FileState holds the review status and chat history for a specific file

type FindingRevalidation added in v1.3.0

type FindingRevalidation struct {
	Verdict    string `json:"verdict"` // "true-positive", "false-positive", "fixed", "uncertain"
	Reasoning  string `json:"reasoning"`
	Confidence string `json:"confidence"` // "high", "medium", "low"
}

FindingRevalidation holds the result of a security revalidation pass.

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message represents a single chat message in an AI conversation

type ReviewFinding

type ReviewFinding struct {
	Severity   string `json:"severity"` // "critical", "high", "medium", "low", "nit"
	Category   string `json:"category"` // "bug", "security", "performance", "testing", "style", "architecture", "docs"
	File       string `json:"file"`
	Line       int    `json:"line"`
	Title      string `json:"title"`
	Detail     string `json:"detail"`
	Suggestion string `json:"suggestion,omitempty"`
	CWE        string `json:"cwe,omitempty"`      // e.g. "CWE-89" — populated for security findings
	Resolved   bool   `json:"resolved,omitempty"` // user-toggled or auto-resolved by task completion

	// Revalidation — populated by the security revalidation pass (Phase 4).
	Revalidation *FindingRevalidation `json:"revalidation,omitempty"`
}

ReviewFinding is a single finding from the structured review.

func (ReviewFinding) SeverityRank

func (f ReviewFinding) SeverityRank() int

SeverityRank returns a numeric rank for sorting findings by severity (lower = more severe).

type ReviewOutput

type ReviewOutput struct {
	Summary            string          `json:"summary"`
	Verdict            string          `json:"verdict"` // "approve", "request_changes", "comment"
	Findings           []ReviewFinding `json:"findings"`
	MissingTests       []string        `json:"missing_tests"`
	QuestionsForAuthor []string        `json:"questions_for_author"`
}

ReviewOutput is the structured JSON output from a PR review. Both single-pass and multi-pass synthesis produce this format.

type ReviewStatus

type ReviewStatus string

ReviewStatus represents the current review state of a file

const (
	StatusUnreviewed ReviewStatus = "unreviewed"
	StatusReviewed   ReviewStatus = "reviewed"
	StatusModified   ReviewStatus = "modified" // Represents a file that was reviewed but has new changes
)

type State

type State struct {
	PRNumber           string                `json:"pr_number"`
	GlobalChat         []Message             `json:"global_chat,omitempty"`
	Review             *AIReview             `json:"review,omitempty"` // PR-level AI review
	Files              map[string]*FileState `json:"files"`
	ProjectContext     string                `json:"project_context,omitempty"`      // cached project briefing
	ProjectContextHash string                `json:"project_context_hash,omitempty"` // hash of inputs used to generate it
	// contains filtered or unexported fields
}

State represents the persisted review state for a single pull request

func Load

func Load(prNumber string) (*State, error)

Load reads the state for a given PR number from disk. If the file does not exist, it returns a new, empty State.

func NewState

func NewState(prNumber string) *State

NewState initializes a new empty state object for a PR

func (*State) ClearAllCaches added in v1.3.0

func (s *State) ClearAllCaches()

ClearAllCaches clears all per-file cached data (batch findings, AOI results) and the PR-level review. Used by forceReReview.

func (*State) CollectCachedFindings added in v1.3.0

func (s *State) CollectCachedFindings(paths []string) (combined string, fileFindings map[string]string)

CollectCachedFindings reassembles per-file findings from cache.

func (*State) DiffSnapshotFromFiles

func (s *State) DiffSnapshotFromFiles() map[string]string

DiffSnapshotFromFiles returns a snapshot of the current DiffHash for each file in the state. This is meant to be stored on AIReview.DiffSnapshot at the time a review is generated so staleness can be detected later.

func (*State) GetAOIResults added in v1.3.0

func (s *State) GetAOIResults(path string) (json.RawMessage, int)

GetAOIResults returns the cached AOI results for a file, or nil. Also returns the context lines used when the results were generated.

func (*State) GetBatchFindings added in v1.3.0

func (s *State) GetBatchFindings(path string) (purpose, findings string)

GetBatchFindings returns the cached purpose and findings for a file.

func (*State) GetProjectContext added in v1.3.0

func (s *State) GetProjectContext() (summary, inputHash string)

GetProjectContext returns the cached project context and its input hash.

func (*State) HasCachedBatch added in v1.3.0

func (s *State) HasCachedBatch(paths []string) bool

HasCachedBatch reports whether all files in the given paths have cached findings.

func (*State) HasFile added in v1.3.0

func (s *State) HasFile(path string) bool

HasFile reports whether a file exists in the state.

func (*State) IsReviewStale

func (s *State) IsReviewStale() bool

IsReviewStale reports whether the stored review's DiffSnapshot differs from the current file diff hashes. A review is considered stale when any file's hash has changed, files have been added, or files have been removed since the review was generated.

func (*State) SetAOIResults added in v1.3.0

func (s *State) SetAOIResults(path string, data json.RawMessage, contextLines int)

SetAOIResults stores AOI scan results for a file along with the context lines used to generate them. Creates the FileState if it doesn't exist.

func (*State) SetBatchFindings added in v1.3.0

func (s *State) SetBatchFindings(path, purpose, findings string)

SetBatchFindings stores the batch review purpose and findings for a file.

func (*State) SetProjectContext added in v1.3.0

func (s *State) SetProjectContext(summary, inputHash string)

SetProjectContext stores a cached project context and its input hash.

func (*State) SyncWithDiffs

func (s *State) SyncWithDiffs(currentDiffHashes map[string]string, prFiles map[string]bool)

SyncWithDiffs compares current diff hashes against stored hashes and invalidates state where necessary. currentDiffHashes maps file path to SHA-256 hash of its current diff (only files where diff succeeded). prFiles is the complete set of files in the PR (used to detect removed files).

Jump to

Keyboard shortcuts

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