eval

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package eval runs skills against fixture repositories (design §10). A case is a small repository plus a task, and for a skill that reads the forge, the issues and pull requests it reads (forge.go); the skill runs on it as a dry run in a throwaway sandbox, and the case passes when the goal critic accepts the result. A skill must reach the configured pass rate before a draft of it can be activated.

Index

Constants

View Source
const (
	// MaxHistoryCases is the most cases one history eval takes: each runs
	// live models.
	MaxHistoryCases = 50

	// DefaultHistoryDays is how far back mining looks when no date is given.
	DefaultHistoryDays = 90
)

Variables

This section is empty.

Functions

func Fixture

func Fixture(fsys fs.FS) func(name string) (fs.FS, error)

Fixture returns the function the engine opens a fixture with. The name "<skill>/<case>" opens the case's repository, and "<skill>/<case>/references" the directory of its reference repositories.

func FixtureForge

func FixtureForge(fsys fs.FS) func(name string) (forge.Forge, forge.Repo, error)

FixtureForge returns the function the engine opens a fixture's forge with. The name "<skill>/<case>" builds a new in-memory forge holding what the case's forge section seeds, its times counted back from now. A case without a forge section is forge.ErrNotFound.

func IsTestPath

func IsTestPath(p string) bool

IsTestPath reports whether a repository path is a test file: under a test directory (test/, tests/, __tests__/, spec/, testdata/, ...), or named as the common languages name their tests (*_test.go, test_*.py, *.test.ts, *.spec.js, *_spec.rb, *Test.java, ...), or a test helper such as conftest.py. Tests that live inside a source file (Rust's #[cfg(test)] modules, Python doctests) cannot be told apart: such a file is code.

func Layered added in v0.3.0

func Layered(own, base fs.FS) (fs.FS, error)

Layered returns the fixtures of base (fixtures/<skill>/<case>/, as in evals.FS) with those of own laid over them. own holds <skill>/<case>/: a skill with a directory there takes its cases from it alone, and every other skill keeps those of base. With own nil it returns base.

func Similarity

func Similarity(got, want string) float64

Similarity compares two unified diffs by the lines they add and remove: the share of changed lines the two have in common (Jaccard), 0 to 1.

func Skills

func Skills(fsys fs.FS) []string

Skills lists the skills that have fixtures.

Types

type Age

type Age time.Duration

Age is how long before the forge was built something happened: a Go duration (90m, 36h) or a whole number of days (14d).

func (*Age) UnmarshalYAML

func (a *Age) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML reads an Age from a scalar.

type Case

type Case struct {
	Skill string `yaml:"-"`
	Name  string `yaml:"-"`
	// Task is what the skill is asked to do. A case with a Number may leave
	// it out: the task is then the title and body of that issue or pull
	// request, as a forge event would bring them.
	Task string `yaml:"task"`
	// Inputs are values handed to the skill, as an earlier skill would
	// have recorded them (REPRO_CMD for fix-bug).
	Inputs map[string]string `yaml:"inputs,omitempty"`
	// Reference is the human fix as a unified diff, when the fixture has
	// one (reference.patch). The run's diff is compared with it.
	Reference string `yaml:"-"`
	// References is set when the fixture brings reference repositories: a
	// references/ directory with one directory per repository and,
	// optionally, <name>.diff and <name>.md next to it. The engine places
	// them where it would clone a real one (.kojo/refs/<name>).
	References bool `yaml:"-"`
	// Number is the issue or pull request the request is about, as a forge
	// event names it. Forge must seed it; the request is about a pull
	// request when it is seeded as one.
	Number int `yaml:"number,omitempty"`
	// Forge is what the case puts on the forge its session reads: issues,
	// pull requests and comments (forge.go). Without it the forge tools
	// fail, as in any session without a repository.
	Forge *ForgeSeed `yaml:"forge,omitempty"`
}

Case is one eval fixture.

func Cases

func Cases(fsys fs.FS, skill string) ([]Case, error)

Cases lists the fixtures of a skill in fsys (fixtures/<skill>/<case>).

func (Case) IsPR

func (c Case) IsPR() bool

IsPR reports whether the case's request is about a pull request.

type Factory added in v0.3.0

type Factory struct {
	// Skills are the skills of skills/ that parse, by name.
	Skills map[string]*skills.Skill
	// Problems are the skills of skills/ that do not, by name.
	Problems map[string]string
	// Fixtures holds fixtures/<skill>/<case>/ like evals.FS: the cases of
	// evals/<skill>/ for each skill that has that directory, the built-in
	// cases for every other skill.
	Fixtures fs.FS
	// Evaluated are the skills evals/ has a directory for, sorted.
	Evaluated []string
	// contains filtered or unexported fields
}

Factory is a repository's own skills and their eval fixtures, read from its .factory directory on disk: what `kojo eval --local --factory` runs. skills/<name>/ are the skills, in the layout the server reads them in; evals/<skill>/<case>/ are their cases, in the layout of evals/fixtures.

func LoadFactory added in v0.3.0

func LoadFactory(dir string, builtin fs.FS) (*Factory, error)

LoadFactory reads dir, a repository's .factory directory, over the built-in fixtures. Nothing is read through a symbolic link that leads out of dir. Close releases the directory.

func (*Factory) Close added in v0.3.0

func (f *Factory) Close() error

Close releases the directory LoadFactory opened.

func (*Factory) Dropped added in v0.3.0

func (f *Factory) Dropped(set *skills.Set, name string) string

Dropped says why a skill of the factory is not what an eval session runs under its name: the problem set, resolved after Install, records for it, such as a kit that asks for more egress than the scope allows. Empty when it runs, or when the factory has no skill of that name.

func (*Factory) Install added in v0.3.0

func (f *Factory) Install(ctx context.Context, cfg *config.Manager, author string) error

Install makes the factory's skills skills of the org scope of cfg. An eval session has no repository, so it resolves org and built-in skills only: installed there, a repository's skill comes before the built-in skill of the same name, as it does in that repository's sessions, and is held to the same egress limits.

type ForgeSeed

type ForgeSeed struct {
	Issues       []SeedIssue `yaml:"issues,omitempty"`
	PullRequests []SeedPR    `yaml:"pull_requests,omitempty"`
}

ForgeSeed is what a case puts on the forge its session reads: issues and pull requests, with their comments. The session gets an in-memory forge (forgetest) holding them, so get_issue, list_issues, list_pull_requests, get_pr, get_pr_diff and comment behave as on a repository. Times are ages counted back from the moment the forge is built, which is when the session first uses it.

type IssueRef

type IssueRef struct {
	Repo   string
	Number int
}

IssueRef is an issue a pull request's description closes. Repo is the repository path the reference names (owner/name, a GitLab group path), or empty for the pull request's own repository.

func ClosingIssues

func ClosingIssues(forgeName, repo, body string) []IssueRef

ClosingIssues returns the distinct issues a pull request's description closes by the forge's closing keywords, in the order they appear. A reference to repo (owner/name), the pull request's own repository, has an empty Repo however it was written.

type Runner

type Runner struct {
	Engine *core.Engine
	Store  store.Store
	// FS holds the fixtures.
	FS  fs.FS
	Log *slog.Logger
	// CaseTimeout bounds one case. Default 30 minutes.
	CaseTimeout time.Duration
	// Models describes the models in use, recorded with the run.
	Models string

	// HistoryCaseTimeout bounds the skill's session of one case of an eval
	// from a repository's history (history.go), and CheckTimeout one check
	// of it. Defaults: 2 hours and 90 minutes. Poll is how often a waiting
	// eval looks at its sessions; default 500ms.
	HistoryCaseTimeout time.Duration
	CheckTimeout       time.Duration
	Poll               time.Duration
	// contains filtered or unexported fields
}

Runner runs evals through the engine, as ordinary dry-run sessions.

func (*Runner) ConfirmHistory

func (r *Runner) ConfirmHistory(ctx context.Context, id string, maxCostUSD float64, author string) (*store.EvalRun, error)

ConfirmHistory starts the model runs of a validated history eval. maxCostUSD is the bound the person confirming saw: when the bound is now higher (the budget or the cases changed), nothing starts. It implements dashboard.HistoryEvaluator.

func (*Runner) HasFixtures

func (r *Runner) HasFixtures(skill string) bool

HasFixtures reports whether a skill has eval fixtures.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, skill, draftID, author string) (*store.EvalRun, error)

Run evaluates a skill and waits for the result. The engine's workers must be running.

func (*Runner) Start

func (r *Runner) Start(ctx context.Context, skill, draftID, author string) (string, error)

Start begins an eval in the background and returns its run ID. It implements dashboard.Evaluator.

func (*Runner) StartHistory

func (r *Runner) StartHistory(ctx context.Context, skill string, spec store.HistoryRun, author string) (string, error)

StartHistory begins an eval of a skill from a repository's history and returns the run's ID. Mining and validation continue in the background; the run then waits, validated, for ConfirmHistory. It implements dashboard.HistoryEvaluator.

type SeedComment

type SeedComment struct {
	// Author defaults to alice.
	Author string `yaml:"author,omitempty"`
	Body   string `yaml:"body"`
	// Age is how long ago it was posted: no earlier than the issue was
	// opened, and no earlier than the comment before it.
	Age Age `yaml:"age,omitempty"`
}

SeedComment is a comment on a seeded issue or pull request.

type SeedIssue

type SeedIssue struct {
	Number int    `yaml:"number"`
	Title  string `yaml:"title"`
	Body   string `yaml:"body,omitempty"`
	// Author defaults to alice.
	Author string   `yaml:"author,omitempty"`
	Labels []string `yaml:"labels,omitempty"`
	// State is open (the default) or closed.
	State string `yaml:"state,omitempty"`
	// Opened is how long ago the issue was opened. Default: just now.
	Opened Age `yaml:"opened,omitempty"`
	// Comments are oldest first.
	Comments []SeedComment `yaml:"comments,omitempty"`
}

SeedIssue is one issue of a ForgeSeed. It was last updated by its last comment, or when it was opened if it has none.

type SeedPR

type SeedPR struct {
	Number int    `yaml:"number"`
	Title  string `yaml:"title"`
	Body   string `yaml:"body,omitempty"`
	// Author defaults to alice.
	Author string `yaml:"author,omitempty"`
	// Head is the pull request's branch, patch-<number> by default; Base
	// is the branch it targets, main by default.
	Head string `yaml:"head,omitempty"`
	Base string `yaml:"base,omitempty"`
	// State is open (the default), closed or merged.
	State string `yaml:"state,omitempty"`
	Draft bool   `yaml:"draft,omitempty"`
	// Opened is how long ago the pull request was opened. Default: just
	// now.
	Opened Age `yaml:"opened,omitempty"`
	// Closed is how long ago a closed or merged pull request was closed or
	// merged: no earlier than it was opened. Default: just now.
	Closed Age `yaml:"closed,omitempty"`
	// Diff names a file of the case directory with the pull request's
	// unified diff, which get_pr_diff returns.
	Diff string `yaml:"diff,omitempty"`
	// Comments are oldest first.
	Comments []SeedComment `yaml:"comments,omitempty"`
}

SeedPR is one pull request of a ForgeSeed. It was last updated by its last comment, or when it was closed or merged, or opened, whichever is latest.

Jump to

Keyboard shortcuts

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