judge

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 2 * time.Second
	DefaultRuntime = "openai-compatible"
)
View Source
const (
	DefaultLlamaServerRuntime         = "llama-server"
	DefaultLlamaServerBinary          = "llama-server"
	DefaultLlamaServerHost            = "127.0.0.1"
	DefaultLlamaServerPort            = 18080
	DefaultLlamaServerStartupTimeout  = 30 * time.Second
	DefaultLlamaServerHFRepo          = "Qwen/Qwen3-0.6B-GGUF"
	DefaultLlamaServerHFFile          = "Qwen3-0.6B-Q8_0.gguf"
	DefaultLlamaServerHFRevision      = "main"
	DefaultLlamaServerDownloadTimeout = 10 * time.Minute
)
View Source
const (
	FailureUnavailable   = "unavailable"
	FailureTimeout       = "timeout"
	FailureInvalidOutput = "invalid_output"
)

Variables

This section is empty.

Functions

func BuildLlamaServerArgs

func BuildLlamaServerArgs(opts LlamaServerOptions) []string

func CachedHFModelPath

func CachedHFModelPath(cacheDir, repo, revision, file string) (string, error)

func CompareFixtureOutput

func CompareFixtureOutput(output Output, expected FixtureExpected) []string

func FailureKind

func FailureKind(err error) string

func ResolveLlamaServerModel

func ResolveLlamaServerModel(ctx context.Context, opts LlamaServerOptions) (string, error)

func ValidateOutput

func ValidateOutput(output Output) error

Types

type Decision

type Decision string
const (
	DecisionAllow Decision = "allow"
	DecisionDeny  Decision = "deny"
)

type DeterministicContext

type DeterministicContext struct {
	Decision      string   `json:"decision"`
	MatchedRules  []string `json:"matched_rules,omitempty"`
	PolicyVersion string   `json:"policy_version"`
}

type Error

type Error struct {
	Kind string
	Err  error
}

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type Fixture

type Fixture struct {
	ID                  string               `json:"id"`
	Description         string               `json:"description"`
	HookEvent           FixtureHookEvent     `json:"hook_event"`
	NormalizedEvent     NormalizedEvent      `json:"normalized_event"`
	DeterministicPolicy DeterministicContext `json:"deterministic_policy"`
	JudgeExpected       FixtureExpected      `json:"judge_expected"`
	Notes               string               `json:"notes"`
}

func ReadFixtures

func ReadFixtures(r io.Reader) ([]Fixture, error)

type FixtureExpected

type FixtureExpected struct {
	ShouldCallJudge bool      `json:"should_call_judge"`
	Decision        Decision  `json:"decision"`
	RiskLevel       RiskLevel `json:"risk_level"`
	Categories      []string  `json:"categories"`
	ReasonContains  []string  `json:"reason_contains"`
}

type FixtureHookEvent

type FixtureHookEvent struct {
	Agent         string         `json:"agent"`
	HookEventName string         `json:"hook_event_name"`
	ToolName      string         `json:"tool_name"`
	ToolInput     map[string]any `json:"tool_input"`
}

type HTTPOptions

type HTTPOptions struct {
	BaseURL         string
	Model           string
	Runtime         string
	Timeout         time.Duration
	HTTPClient      *http.Client
	Prompt          string
	DisableThinking bool
}

type Input

type Input struct {
	Agent               string               `json:"agent,omitempty"`
	HookEvent           string               `json:"hook_event"`
	ToolName            string               `json:"tool_name,omitempty"`
	CWDClass            string               `json:"cwd_class,omitempty"`
	ToolInput           ToolInput            `json:"tool_input"`
	NormalizedEvent     NormalizedEvent      `json:"normalized_event"`
	DeterministicPolicy DeterministicContext `json:"deterministic_policy"`
}

func InputFromFixture

func InputFromFixture(fixture Fixture) Input

type Judge

type Judge interface {
	Decide(context.Context, Input) (Result, error)
}

type LlamaServer

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

func StartLlamaServer

func StartLlamaServer(ctx context.Context, opts LlamaServerOptions) (*LlamaServer, error)

func (*LlamaServer) BaseURL

func (s *LlamaServer) BaseURL() string

func (*LlamaServer) Stop

func (s *LlamaServer) Stop() error

type LlamaServerOptions

type LlamaServerOptions struct {
	BinaryPath     string
	ModelPath      string
	HFRepo         string
	HFFile         string
	HFRevision     string
	CacheDir       string
	Host           string
	Port           int
	StartupTimeout time.Duration
	HTTPClient     *http.Client
	Stdout         io.Writer
	Stderr         io.Writer
}

type Metadata

type Metadata struct {
	Runtime     string
	Model       string
	DurationMs  int64
	FailureKind string
}

type MetadataProvider

type MetadataProvider interface {
	Metadata() Metadata
}

type NormalizedEvent

type NormalizedEvent struct {
	Type               string   `json:"type"`
	Provider           string   `json:"provider,omitempty"`
	ProviderCategory   string   `json:"provider_category,omitempty"`
	Operation          string   `json:"operation,omitempty"`
	OperationClass     string   `json:"operation_class,omitempty"`
	ResourceClass      string   `json:"resource_class,omitempty"`
	Environment        string   `json:"environment,omitempty"`
	CredentialObserved bool     `json:"credential_observed"`
	DirectAPICall      bool     `json:"direct_api_call"`
	ExplicitUserIntent bool     `json:"explicit_user_intent"`
	PathClass          string   `json:"path_class,omitempty"`
	CommandSummary     string   `json:"command_summary,omitempty"`
	RequestSummary     string   `json:"request_summary,omitempty"`
	Signals            []string `json:"signals,omitempty"`
}

type OpenAICompatibleJudge

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

func NewOpenAICompatibleJudge

func NewOpenAICompatibleJudge(opts HTTPOptions) (*OpenAICompatibleJudge, error)

func (*OpenAICompatibleJudge) Decide

func (j *OpenAICompatibleJudge) Decide(ctx context.Context, input Input) (Result, error)

func (*OpenAICompatibleJudge) Metadata

func (j *OpenAICompatibleJudge) Metadata() Metadata

type Output

type Output struct {
	Decision   Decision  `json:"decision"`
	RiskLevel  RiskLevel `json:"risk_level"`
	Categories []string  `json:"categories"`
	Reason     string    `json:"reason"`
}

func ParseOutput

func ParseOutput(content string) (Output, error)

type Result

type Result struct {
	Output   Output
	Metadata Metadata
}

type RiskLevel

type RiskLevel string
const (
	RiskLevelLow    RiskLevel = "low"
	RiskLevelMedium RiskLevel = "medium"
	RiskLevelHigh   RiskLevel = "high"
)

type ToolInput

type ToolInput struct {
	CommandRedacted string `json:"command_redacted,omitempty"`
	PathRedacted    string `json:"path_redacted,omitempty"`
	RequestSummary  string `json:"request_summary,omitempty"`
}

type UnavailableJudge

type UnavailableJudge struct {
	Runtime string
	Model   string
	Kind    string
	Err     error
}

func (UnavailableJudge) Decide

func (UnavailableJudge) Metadata

func (j UnavailableJudge) Metadata() Metadata

Jump to

Keyboard shortcuts

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