Documentation
¶
Overview ¶
Package warden implements the code review agent that reviews Smith's changes.
The Warden spawns a separate Claude session with a review-focused prompt, providing the git diff of changes made by the Smith. It returns a structured verdict: approve, reject, or request-changes with feedback.
Index ¶
- Constants
- func FetchRecentPRNumbers(ctx context.Context, repoDir string, limit int) ([]int, error)
- func GroupComments(comments []PRComment) [][]PRComment
- func RulesPath(anvilPath string) string
- func SaveRules(anvilPath string, rf *RulesFile) error
- type PRComment
- type ReviewIssue
- type ReviewResult
- type Rule
- type RulesFile
- type Verdict
Constants ¶
const RulesFileName = ".forge/warden-rules.yaml"
RulesFileName is the per-anvil file storing learned review rules.
Variables ¶
This section is empty.
Functions ¶
func FetchRecentPRNumbers ¶
FetchRecentPRNumbers returns the most recent merged PR numbers for a repo.
func GroupComments ¶
GroupComments groups semantically similar comments using keyword overlap. First, comments with identical normalized text are merged. Then, groups whose keyword sets exceed a Jaccard similarity threshold are merged together so that comments about the same pattern (e.g. "missing error check on Open()" vs "error from ReadFile not handled") land in one group.
Types ¶
type PRComment ¶
type PRComment struct {
Body string `json:"body"`
User string `json:"user"`
Path string `json:"path"`
PRNumber int `json:"pr_number"`
}
PRComment represents a review comment fetched from GitHub.
type ReviewIssue ¶
type ReviewIssue struct {
// File is the affected file path.
File string `json:"file"`
// Line is the approximate line number (0 if unknown).
Line int `json:"line"`
// Severity is "error", "warning", or "suggestion".
Severity string `json:"severity"`
// Message describes the issue.
Message string `json:"message"`
}
ReviewIssue represents a specific issue found during review.
type ReviewResult ¶
type ReviewResult struct {
// Verdict is the review decision.
Verdict Verdict
// UsedProvider records which provider actually completed the review.
UsedProvider *provider.Provider
// Summary is a brief summary of the review.
Summary string
// Issues is a list of specific issues found.
Issues []ReviewIssue
// RawOutput is the full Claude output.
RawOutput string
// Duration is how long the review took.
Duration time.Duration
// CostUSD is the cost of the review session.
CostUSD float64
// NoDiff is true when the rejection was because Smith produced no diff.
NoDiff bool
}
ReviewResult captures the Warden's review outcome.
func Review ¶
func Review(ctx context.Context, worktreePath, beadID, anvilPath string, db *state.DB, anvilName string, providers ...provider.Provider) (*ReviewResult, error)
Review runs a Warden review of the changes in the given worktree. It gets the git diff, spawns a Claude review session, and parses the verdict.
db and anvilName are used to log lifecycle events; db may be nil to skip logging. providers is the ordered list of AI providers to try. When empty, provider.Defaults() is used. Provider fallback applies on rate limit.
type Rule ¶
type Rule struct {
ID string `yaml:"id" json:"id"`
Category string `yaml:"category" json:"category"`
Pattern string `yaml:"pattern" json:"pattern"`
Check string `yaml:"check" json:"check"`
Source string `yaml:"source" json:"source"`
Added string `yaml:"added" json:"added"`
}
Rule represents a single learned review pattern.
type RulesFile ¶
type RulesFile struct {
Rules []Rule `yaml:"rules"`
}
RulesFile is the top-level structure of warden-rules.yaml.
func LoadRules ¶
LoadRules reads the warden rules file from the anvil path. Returns an empty RulesFile (not an error) if the file does not exist.
func (*RulesFile) AddRule ¶
AddRule appends a rule to the file, skipping duplicates by ID. Returns true if the rule was added (not a duplicate).
func (*RulesFile) FormatChecklist ¶
FormatChecklist returns the rules formatted as a numbered checklist suitable for inclusion in a review prompt.
func (*RulesFile) RemoveRule ¶
RemoveRule removes a rule by ID. Returns true if a rule was removed.