semantic

package
v1.0.64 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReviewActionMustFix = "must_fix"
	ReviewActionConfirm = "confirm"
	ReviewActionObserve = "observe"
)

Variables

View Source
var (
	ErrReviewerUnavailable   = errors.New("semantic reviewer is not configured")
	ErrReviewerConfiguration = errors.New("semantic reviewer configuration is invalid")
)
View Source
var ErrReviewerRequestTooLarge = errors.New("semantic review request too large")

Functions

func IsTrustedBaseURL

func IsTrustedBaseURL(raw string, cfg ModelConfig) bool

func Markdown

func Markdown(decision Decision) string

func ParseBlockMode

func ParseBlockMode(value string) bool

func WriteDecision

func WriteDecision(path string, decision Decision) error

func WriteMarkdown

func WriteMarkdown(path string, decision Decision) error

Types

type ChangedSummary

type ChangedSummary struct {
	Commands      int      `json:"commands,omitempty"`
	Skills        int      `json:"skills,omitempty"`
	SkillQuality  int      `json:"skill_quality,omitempty"`
	Errors        int      `json:"errors,omitempty"`
	Outputs       int      `json:"outputs,omitempty"`
	Examples      int      `json:"examples,omitempty"`
	PublicContent int      `json:"public_content,omitempty"`
	Domains       []string `json:"domains,omitempty"`
	Sources       []string `json:"sources,omitempty"`
}

type Client

type Client struct {
	BaseURL         string
	APIKey          string
	Model           string
	Timeout         time.Duration
	MaxTokens       int
	MaxRequestBytes int
	AllowedModels   map[string]bool
	HTTPClient      *http.Client
}

func FromEnvWithConfig

func FromEnvWithConfig(cfg ModelConfig) (Client, bool, error)

func (Client) Review

func (c Client) Review(ctx context.Context, f facts.Facts) (Review, error)

type CommandInput

type CommandInput struct {
	FactRef string `json:"fact_ref"`
	facts.CommandFact
}

type Decision

type Decision struct {
	BlockMode             bool            `json:"block_mode"`
	Skipped               bool            `json:"skipped,omitempty"`
	Degraded              bool            `json:"degraded,omitempty"`
	InfrastructureFailure bool            `json:"infrastructure_failure,omitempty"`
	Blockers              []Finding       `json:"blockers,omitempty"`
	Warnings              []Finding       `json:"warnings,omitempty"`
	SystemWarnings        []SystemWarning `json:"system_warnings,omitempty"`
}

func Decide

func Decide(f facts.Facts, r Review, p Policy) Decision

func DecideWithWaivers

func DecideWithWaivers(f facts.Facts, r Review, p Policy, waivers Waivers) Decision

func DegradedDecision

func DegradedDecision(err error) Decision

func InfrastructureFailureDecision

func InfrastructureFailureDecision(err error) Decision

func SkippedDecision

func SkippedDecision(err error) Decision

type ErrorInput

type ErrorInput struct {
	FactRef string `json:"fact_ref"`
	facts.ErrorFact
}

type ExampleInput

type ExampleInput struct {
	FactRef string `json:"fact_ref"`
	facts.CommandExample
}

type FactScope

type FactScope struct {
	FactKind    string
	Domain      string
	Changed     bool
	Source      string
	SourceFile  string
	Line        int
	CommandPath string
}

type Finding

type Finding struct {
	Category        string   `json:"category"`
	Severity        string   `json:"severity"`
	Evidence        []string `json:"evidence"`
	Message         string   `json:"message"`
	SuggestedAction string   `json:"suggested_action"`
	ReviewAction    string   `json:"review_action,omitempty"`
	Fingerprint     string   `json:"fingerprint,omitempty"`
	RolloutGroups   []string `json:"rollout_groups,omitempty"`
	WaiverID        string   `json:"waiver_id,omitempty"`
	WaiverKeys      []string `json:"waiver_keys,omitempty"`
}

type InputView

type InputView struct {
	SchemaVersion        int                    `json:"schema_version"`
	ChangedSummary       ChangedSummary         `json:"changed_summary"`
	RuleSummary          []RuleSummaryItem      `json:"rule_summary,omitempty"`
	Commands             []CommandInput         `json:"commands,omitempty"`
	Skills               []SkillInput           `json:"skills,omitempty"`
	SkillQuality         []SkillQualityInput    `json:"skill_quality,omitempty"`
	Errors               []ErrorInput           `json:"errors,omitempty"`
	Outputs              []OutputInput          `json:"outputs,omitempty"`
	Examples             []ExampleInput         `json:"examples,omitempty"`
	PublicContentLeakage []PublicContentInput   `json:"public_content_leakage,omitempty"`
	Diagnostics          []facts.DiagnosticFact `json:"diagnostics,omitempty"`
}

func BuildInputView

func BuildInputView(f facts.Facts) InputView

func (InputView) HasReviewableFacts added in v1.0.58

func (v InputView) HasReviewableFacts() bool

type Message

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

func BuildPrompt

func BuildPrompt(f facts.Facts) []Message

type ModelConfig

type ModelConfig struct {
	Default         string   `json:"default"`
	Allowed         []string `json:"allowed"`
	AllowedBaseURLs []string `json:"allowed_base_urls"`
}

func LoadModelConfig

func LoadModelConfig(repo string) (ModelConfig, error)

func (ModelConfig) AllowsModel

func (cfg ModelConfig) AllowsModel(model string) bool

type OutputInput

type OutputInput struct {
	FactRef          string `json:"fact_ref"`
	Command          string `json:"command"`
	Domain           string `json:"domain,omitempty"`
	Changed          bool   `json:"changed,omitempty"`
	Source           string `json:"source,omitempty"`
	IsList           bool   `json:"is_list"`
	HasDefaultLimit  bool   `json:"has_default_limit"`
	HasDecisionField bool   `json:"has_decision_field"`
}

type Policy

type Policy struct {
	SchemaVersion      int            `json:"schema_version"`
	DefaultEnforcement string         `json:"default_enforcement"`
	BlockCategories    []string       `json:"block_categories"`
	RolloutGroups      []RolloutGroup `json:"rollout_groups,omitempty"`
}

func DefaultPolicy

func DefaultPolicy() Policy

func LoadPolicy

func LoadPolicy(repo string) (Policy, error)

type PublicContentInput added in v1.0.58

type PublicContentInput struct {
	FactRef string `json:"fact_ref"`
	facts.PublicContentFact
}

type Review

type Review struct {
	Verdict  string    `json:"verdict"`
	Findings []Finding `json:"findings"`
}

func DecodeModelReview

func DecodeModelReview(r io.Reader) (Review, error)

Model responses are normalized through modelReview for compatibility; the local gatekeeper still recomputes blocking evidence from facts.

func DecodeReview

func DecodeReview(r io.Reader) (Review, error)

func LoadOrReviewWithConfig

func LoadOrReviewWithConfig(ctx context.Context, f facts.Facts, reviewPath string, cfg ModelConfig) (Review, error)

type RolloutGroup

type RolloutGroup struct {
	ID          string        `json:"id"`
	Enforcement string        `json:"enforcement"`
	Scope       ScopeSelector `json:"scope,omitempty"`
	Categories  []string      `json:"categories"`
	Owner       string        `json:"owner"`
	Reason      string        `json:"reason"`
}

type RuleSummaryItem

type RuleSummaryItem struct {
	Rule   string        `json:"rule"`
	Action report.Action `json:"action"`
	Count  int           `json:"count"`
}

type ScopeSelector

type ScopeSelector struct {
	ChangedOnly bool     `json:"changed_only,omitempty"`
	Domains     []string `json:"domains,omitempty"`
	FactKinds   []string `json:"fact_kinds,omitempty"`
	Sources     []string `json:"sources,omitempty"`
}

type SkillInput

type SkillInput struct {
	FactRef string `json:"fact_ref"`
	facts.SkillFact
}

type SkillQualityInput

type SkillQualityInput struct {
	FactRef string `json:"fact_ref"`
	facts.SkillQualityFact
}

type SystemWarning

type SystemWarning struct {
	Severity        string `json:"severity"`
	Message         string `json:"message"`
	SuggestedAction string `json:"suggested_action,omitempty"`
}

type Waiver

type Waiver struct {
	ID          string
	Category    string
	FactKind    string
	SourceFile  string
	Line        int
	CommandPath string
	Owner       string
	Reason      string
	AddedAt     time.Time
	ExpiresAt   time.Time
}

type Waivers

type Waivers struct {
	Items []Waiver
}

func LoadWaivers

func LoadWaivers(repo string, now time.Time) (Waivers, []report.Diagnostic, error)

func LoadWaiversFile

func LoadWaiversFile(file string, now time.Time) (Waivers, []report.Diagnostic, error)

func ParseWaivers

func ParseWaivers(r *strings.Reader, now time.Time) (Waivers, []report.Diagnostic, error)

func (Waivers) MatchFinding

func (w Waivers) MatchFinding(category string, scopes []FactScope) (string, []string, bool)

Jump to

Keyboard shortcuts

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