loop

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0, MIT Imports: 27 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 loop is `go`, the hot-path loop in one command (rust-anything's `go.rs`; a Go package cannot be called `go`): profile the workload, bridge the outermost portable hot function, record it with the calls the workload makes, hand the port to an agent, then build, diff, gate and bench it, and switch it on with `enable` only when every case matches, gate passes and the port is not slower as its callers call it. Run it again after porting by hand: every finished step is kept (the port module, a recording that is not stale, a port with no stubs left).

Index

Constants

View Source
const DefaultMinCases = 20

DefaultMinCases is the bar under which a recording says too little: a port checked against a dozen cases, half of them exceptions, says nothing about the original.

View Source
const DefaultRounds = 3

DefaultRounds is how many agent turns `go --agent` takes by default.

View Source
const TaskFile = "TASK.md"

TaskFile is the task `go` writes into the port module and hands to the agent.

Variables

This section is empty.

Functions

func AgentCommand

func AgentCommand(agent string) (*exec.Cmd, error)

AgentCommand is the agent's command line: `claude` and `codex` run headless with edits allowed in the port module; anything else runs as given, reading the prompt on stdin.

func ModuleName

func ModuleName(function string) string

ModuleName is the port module `go` makes for a function: `fuzzyScore` gets `fuzzy-score-go`.

func SlowerAdvice

func SlowerAdvice(p *Pick, speedup float64) string

SlowerAdvice is what to do when every case matches but the port, called as its callers call it, loses.

func Task

func Task(root, moduleDir string, p *Pick, command []string) string

Task is what the port of the pick asks for: the function, the rules the port follows, the repository's own rules, and the loop that checks it.

Types

type Options

type Options struct {
	Root    string
	Command []string
	Lang    core.Lang
	// Agent is `claude`, `codex`, or a command that reads the prompt on stdin; empty stops at the
	// task.
	Agent string
	// Function is ported instead of the profile's pick.
	Function string
	// Count is the number of generated cases per function.
	Count int
	// Rounds are agent turns: the first port, then one per failed diff or gate; nil is the
	// default, DefaultRounds.
	Rounds *int
	// MinCases is the number of recorded cases that did not throw, at least, before the port goes
	// to an agent or is switched on.
	MinCases int
	// Progress receives each step as `go: <step>` (stderr on the command line); the agent's and
	// the workload's output go there too.
	Progress io.Writer
	// Version is the go-anything version written to the audit log.
	Version string
}

Options are `go`'s flags.

type Outcome

type Outcome struct {
	Stage     Stage           `json:"stage"`
	Pick      Pick            `json:"pick"`
	ModuleDir string          `json:"module_dir"`
	Task      string          `json:"task"`
	Cases     *int            `json:"cases,omitempty"`
	Matched   *int            `json:"matched,omitempty"`
	Recording *RecordingFacts `json:"recording,omitempty"`
	// Speedup is `bench`'s geometric-mean speedup, call included, once every check passed.
	Speedup      *float64 `json:"speedup,omitempty"`
	FailedChecks []string `json:"failed_checks"`
	Steps        []string `json:"steps"`
	Next         string   `json:"next"`
}

Outcome is what a run did and where it stopped.

func Run

func Run(ctx context.Context, opts Options) (*Outcome, error)

Run is `go`.

type Pick

type Pick struct {
	Function string        `json:"function"`
	File     string        `json:"file"`
	Line     int           `json:"line"`
	TotalPct profile.Float `json:"total_pct"`
	// Batch is the `function:param` the profile advises batching; `bridge --batch` is not built
	// in go-anything yet, so the function is bridged alone and the plan says so.
	Batch *string `json:"batch,omitempty"`
	// Caller is the caller that spends the most time in it: its name and `file:line`.
	Caller *[2]string `json:"caller,omitempty"`
	Why    string     `json:"why"`
}

Pick is the function `go` ports, and why.

type RecordingFacts

type RecordingFacts struct {
	Cases int `json:"cases"`
	// Generated cases `record` made; nil for a recording kept from an earlier run.
	Generated *int `json:"generated,omitempty"`
	// Captured calls the workload made, recorded as cases; nil when none were captured (or the
	// recording was kept).
	Captured *int `json:"captured,omitempty"`
	// Threw counts the cases whose original threw.
	Threw int `json:"threw"`
}

RecordingFacts are where the recorded cases came from.

type Stage

type Stage string

Stage is where a run stopped.

const (
	// WaitingForPort: the task is written; port port/port.go and run `go` again.
	WaitingForPort Stage = "waiting_for_port"
	// Mismatch: recorded cases still differ after the agent's turns.
	Mismatch Stage = "mismatch"
	// GateFailed: every case matches but a gate check fails.
	GateFailed Stage = "gate_failed"
	// Thin: too few recorded cases that did not throw to trust a port against.
	Thin Stage = "thin"
	// On: everything passed and the unit is switched on.
	On Stage = "on"
	// Passed: everything passed; the unit is switched with the shadow module instead.
	Passed Stage = "passed"
	// Slower: everything matches, but `bench` times the port slower than the original as its
	// callers call it, so it stays off.
	Slower Stage = "slower"
)

func (Stage) Verdict

func (s Stage) Verdict() bool

Verdict says whether a stage is an answer of "no": the command then exits 1.

Jump to

Keyboard shortcuts

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