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
- func Fixture(fsys fs.FS) func(name string) (fs.FS, error)
- func FixtureForge(fsys fs.FS) func(name string) (forge.Forge, forge.Repo, error)
- func Layered(own, base fs.FS) (fs.FS, error)
- func Similarity(got, want string) float64
- func Skills(fsys fs.FS) []string
- type Age
- type Case
- type Factory
- type ForgeSeed
- type IssueRef
- type Runner
- func (r *Runner) ConfirmHistory(ctx context.Context, id string, maxCostUSD float64, author string) (*store.EvalRun, error)
- func (r *Runner) HasFixtures(skill string) bool
- func (r *Runner) Run(ctx context.Context, skill, draftID, author string) (*store.EvalRun, error)
- func (r *Runner) Start(ctx context.Context, skill, draftID, author string) (string, error)
- func (r *Runner) StartHistory(ctx context.Context, skill string, spec store.HistoryRun, author string) (string, error)
- type SeedComment
- type SeedIssue
- type SeedPR
Constants ¶
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 ¶
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 ¶
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 Layered ¶ added in v0.3.0
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 ¶
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.
Types ¶
type Age ¶
Age is how long before the forge was built something happened: a Go duration (90m, 36h) or a whole number of days (14d).
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.
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
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) Dropped ¶ added in v0.3.0
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
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 ¶
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 ¶
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 ¶
HasFixtures reports whether a skill has eval fixtures.
func (*Runner) Run ¶
Run evaluates a skill and waits for the result. The engine's workers must be running.
func (*Runner) Start ¶
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.