eval

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FormatJSON emits full JSON artifact + path message.
	FormatJSON = "json"
	// FormatTable emits a per-task terminal table.
	FormatTable = "table"
	// FormatSummary emits one line per suite with final pass/fail.
	FormatSummary = "summary"
)

Variables

View Source
var ErrPollTimeout = errors.New("eval run polling timed out after 10 minutes")

ErrPollTimeout is returned when a run does not complete within pollTimeout.

View Source
var ErrPreconditionNotMet = errors.New("eval precondition not met (BGE-M3 or AI gateway unavailable)")

ErrPreconditionNotMet is returned when BGE-M3 or AI gateway is unavailable. CLI exits with code 3 on this error.

View Source
var ErrSchemaVersion = errors.New("eval schema version mismatch — plugin may need upgrade")

ErrSchemaVersion is returned when the plugin response uses an unknown schema_ver.

Functions

func WriteGateStatus

func WriteGateStatus(w io.Writer, gs GateStatus, verbose bool)

WriteGateStatus writes the gate check result to w. Purpose: Format the autonomy tier gate check for CLI output. Inputs: w — writer; gs — gate status; verbose — print blocking suites. Outputs: formatted text to w.

func WriteResult

func WriteResult(w io.Writer, result EvalRunResult, format, repoRoot string) error

WriteResult writes the eval run result in the requested format. Purpose: Dispatch to the correct formatter and write artifact file. Inputs: w — output writer; result — run result; format — one of json/table/summary;

repoRoot — path where {repoRoot}/.nself-ci/artifacts/ is written.

Outputs: formatted text to w; eval-results.json on disk. Constraints: Always writes JSON artifact regardless of format flag.

func WriteValidationErrors

func WriteValidationErrors(w io.Writer, errs []ValidationError)

WriteValidationErrors prints validation errors to w.

Types

type Client

type Client struct {
	// BaseURL is the plugin base URL, e.g. "http://localhost:3770".
	BaseURL string
	// HTTP is the underlying client; set to &http.Client{} if nil.
	HTTP *http.Client
	// SourceAccountID is forwarded as X-Nself-Source-Account-Id header.
	SourceAccountID string
}

Client is the typed HTTP client for nself-eval-gate.

func (*Client) GetGateStatus

func (c *Client) GetGateStatus(ctx context.Context, tier string) (GateStatus, error)

GetGateStatus fetches the gate check result for a given autonomy tier. Purpose: Determine whether a tier is cleared for AI autonomy progression. Inputs: ctx, tier — one of: supervised, semi-auto, full-auto. Outputs: GateStatus{Tier, Cleared, BlockingSuites, Enforced}. Constraints: supervised tier always returns Cleared=true (enforced=false by design).

func (*Client) GetRun

func (c *Client) GetRun(ctx context.Context, runID string) (EvalRunResult, error)

GetRun fetches a single run by ID via GET /eval/runs/{id}. Purpose: Single-fetch (no polling) — use for inspection; poll via WaitForRun. Inputs: ctx, runID. Outputs: EvalRunResult; ErrSchemaVersion if schema_ver doesn't match. Constraints: Returns nil error + zero-value if run not found (404).

func (*Client) RunSuite

func (c *Client) RunSuite(ctx context.Context, suiteSlug string) (RunQueued, error)

RunSuite triggers a suite evaluation via POST /eval/run. Purpose: Queue a new eval run for the specified suite slug. Inputs: ctx, suiteSlug — the slug registered in np_eval_suites. Outputs: RunQueued{RunID, Status:"queued"} or error. Constraints: Does not wait for completion — call GetRun to poll.

func (*Client) ValidateYAML

func (c *Client) ValidateYAML(ctx context.Context, yamlContent []byte) (ValidationResult, error)

ValidateYAML validates eval-set YAML via POST /eval/validate. Purpose: Dry-run schema validation without executing a run. Inputs: ctx, yamlContent — raw bytes of the eval-set YAML file. Outputs: ValidationResult{Valid, Errors}; non-nil error on HTTP/network failure only. Constraints: Validation errors are in ValidationResult.Errors, not as Go errors.

func (*Client) WaitForRun

func (c *Client) WaitForRun(ctx context.Context, runID string) (EvalRunResult, error)

WaitForRun polls GET /eval/runs/{id} every 2s until the run reaches a terminal state. Purpose: Block CLI until eval run completes; enforce 10min hard ceiling. Inputs: ctx, runID. Outputs: Final EvalRunResult; ErrPollTimeout after 10min; ErrPreconditionNotMet

if the run signals precondition_failed=true.

Constraints: Terminal states: "passed", "failed". "queued"/"running" → keep polling.

type EvalRunResult

type EvalRunResult struct {
	// SchemaVer is the schema version of this response; checked against expectedSchemaVer.
	SchemaVer int `json:"schema_ver"`
	// ID is the unique run identifier.
	ID string `json:"id"`
	// SuiteSlug is the evaluated suite's slug.
	SuiteSlug string `json:"suite_slug"`
	// Status is one of: queued, running, passed, failed.
	Status string `json:"status"`
	// PassRate is the fraction of tasks that passed (0.0–1.0).
	PassRate float64 `json:"pass_rate"`
	// SuiteScore is the weighted mean score across all tasks (0.0–1.0).
	SuiteScore float64 `json:"suite_score"`
	// Passed indicates whether the run met the configured threshold.
	Passed bool `json:"passed"`
	// Tasks holds per-task result details.
	Tasks []EvalTaskResult `json:"tasks"`
	// PreconditionFailed is true when a dependency (BGE-M3, gateway) was unavailable.
	PreconditionFailed bool `json:"precondition_failed"`
	// ErrorMessage is populated when Status is "failed" with a human-readable cause.
	ErrorMessage string `json:"error_message,omitempty"`
}

EvalRunResult is the response from GET /eval/runs/{id} after completion.

type EvalTaskResult

type EvalTaskResult struct {
	// TaskID is the unique task identifier.
	TaskID string `json:"task_id"`
	// Input is the query string used for this task.
	Input string `json:"input"`
	// Output is the system output evaluated.
	Output string `json:"output"`
	// Score is the numeric score (0.0–1.0).
	Score float64 `json:"score"`
	// Passed indicates whether this individual task passed.
	Passed bool `json:"passed"`
	// ScoringMode is one of: exact, semantic, rubric.
	ScoringMode string `json:"scoring_mode"`
	// Rationale is provided for rubric-scored tasks.
	Rationale string `json:"rationale,omitempty"`
}

EvalTaskResult is the per-task breakdown within an EvalRunResult.

type GateStatus

type GateStatus struct {
	// Tier is the autonomy tier checked: supervised, semi-auto, full-auto.
	Tier string `json:"tier"`
	// Cleared is true when all required suites pass their thresholds.
	Cleared bool `json:"cleared"`
	// BlockingSuites lists suite slugs that are failing or have no runs.
	BlockingSuites []string `json:"blocking_suites"`
	// Enforced mirrors the threshold's enforced flag.
	Enforced bool `json:"enforced"`
}

GateStatus is the response from GET /eval/gate/{tier}.

type RunQueued

type RunQueued struct {
	// RunID is the identifier to poll at GET /eval/runs/{id}.
	RunID string `json:"run_id"`
	// Status is always "queued" on the initial response.
	Status string `json:"status"`
}

RunQueued is the 202 response from POST /eval/run.

type RunRequest

type RunRequest struct {
	// SuiteSlug is the slug of the suite to run.
	SuiteSlug string `json:"suite_slug"`
}

RunRequest is sent to POST /eval/run.

type ValidationError

type ValidationError struct {
	// Field is the JSON-path to the failing field.
	Field string `json:"field"`
	// Message is a human-readable description of the failure.
	Message string `json:"message"`
}

ValidationError is a single schema validation failure.

type ValidationResult

type ValidationResult struct {
	// Valid is true when the submitted YAML passes schema validation.
	Valid bool `json:"valid"`
	// Errors lists field-level validation errors.
	Errors []ValidationError `json:"errors,omitempty"`
}

ValidationResult is the response from POST /eval/validate.

Jump to

Keyboard shortcuts

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