judge

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 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 IsUnavailable added in v0.8.0

func IsUnavailable(localJudge Judge) bool

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 DownloadProgress added in v0.8.0

type DownloadProgress struct {
	Event        DownloadProgressEvent
	CurrentBytes int64
	TotalBytes   int64
	Err          error
}

type DownloadProgressEvent added in v0.8.0

type DownloadProgressEvent string
const (
	DownloadProgressCacheCheck DownloadProgressEvent = "cache_check"
	DownloadProgressCacheHit   DownloadProgressEvent = "cache_hit"
	DownloadProgressStart      DownloadProgressEvent = "download_start"
	DownloadProgressUpdate     DownloadProgressEvent = "download_update"
	DownloadProgressDone       DownloadProgressEvent = "download_done"
	DownloadProgressError      DownloadProgressEvent = "download_error"
)

type DownloadProgressHandler added in v0.8.0

type DownloadProgressHandler func(DownloadProgress)

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     FixtureNormalizedEvent   `json:"normalized_event"`
	DeterministicPolicy FixtureDeterministicRule `json:"deterministic_policy"`
	JudgeExpected       FixtureExpected          `json:"judge_expected"`
	Notes               string                   `json:"notes"`
}

func ReadFixtures

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

type FixtureDeterministicRule added in v0.8.0

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

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 FixtureNormalizedEvent added in v0.8.0

type FixtureNormalizedEvent struct {
	Type               string   `json:"type"`
	ProviderCategory   string   `json:"provider_category,omitempty"`
	OperationClass     string   `json:"operation_class,omitempty"`
	ResourceClass      string   `json:"resource_class,omitempty"`
	Environment        string   `json:"environment,omitempty"`
	PathClass          string   `json:"path_class,omitempty"`
	CommandSummary     string   `json:"command_summary,omitempty"`
	RequestSummary     string   `json:"request_summary,omitempty"`
	ExplicitUserIntent bool     `json:"explicit_user_intent"`
	Signals            []string `json:"signals,omitempty"`
}

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 {
	ToolName           string    `json:"tool_name,omitempty"`
	ExplicitUserIntent bool      `json:"explicit_user_intent,omitempty"`
	ToolInput          ToolInput `json:"tool_input"`
}

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
	DownloadProgress DownloadProgressHandler
}

type Metadata

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

type MetadataProvider

type MetadataProvider interface {
	Metadata() Metadata
}

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 {
	Command string `json:"command,omitempty"`
	Path    string `json:"path,omitempty"`
	Request string `json:"request,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