plan

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 14 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

Index

Constants

This section is empty.

Variables

View Source
var CommandEcosystem = map[string]string{
	"cargo":  "rust",
	"rustc":  "rust",
	"rustup": "rust",
	"npm":    "node",
	"npx":    "node",
	"pnpm":   "node",
	"yarn":   "node",
	"node":   "node",
	"pip":    "python",
	"pip3":   "python",
	"poetry": "python",
	"uv":     "python",
	"python": "python",
	"go":     "go",
	"gofmt":  "go",
}

CommandEcosystem maps a build command to the ecosystem that provides it. Commands present in every image, such as make and cc, are deliberately absent: they say nothing about which toolchain a recipe needs. CommandEcosystem maps a command to the ecosystem that provides it. Both the planner and the toolchain chooser need this answer, so it has one home.

Functions

func CreatesToken

func CreatesToken(flat string) [][]string

CreatesToken reports whether a line produces the named path: a redirect target, an -o argument, or an argument to mkdir, touch, cp or mv. The session writer asks this to know which files a step will bring into being.

func DocumentedSettingNames

func DocumentedSettingNames(markdown string) []string

DocumentedSettingNames collects every environment setting the document mentions, in any context.

func InvokedBinary

func InvokedBinary(flat string, binaries map[string]bool) (string, string)

InvokedBinary returns the documented binary a line invokes and its first subcommand, or empty strings when the line invokes none. Leading VAR=value prefixes are stepped over, so `KEY=x tool sub` still names the tool, and so are wrappers such as env and xargs, so `env KEY=x tool sub` does too.

func IsSimpleWord

func IsSimpleWord(s string) bool

IsSimpleWord reports whether a token is a bare command word.

Types

type Plan

type Plan struct {
	// Repo is the repository directory name.
	Repo string `json:"repo"`
	// Installs are the documented installs run to put the binaries on PATH.
	Installs []PlanInstall `json:"installs,omitempty"`
	// Binaries are the documented binaries the session installs.
	Binaries []string `json:"binaries,omitempty"`
	// Packages are Debian packages installed before any step runs.
	Packages []string `json:"packages,omitempty"`
	// Env is extra environment exported for the whole session.
	Env map[string]string `json:"env,omitempty"`
	// Fixtures are files written into the workdir before any step runs.
	Fixtures []config.Fixture `json:"fixtures,omitempty"`
	// Steps are the example blocks in documented order.
	Steps []PlanStep `json:"steps,omitempty"`
	// Settings are environment names the document mentions anywhere, prose
	// and tables included. A tool that fails asking for one of these is
	// asking the reader for something the document already told them about.
	Settings []string `json:"settings,omitempty"`
	// Excluded counts code blocks that are not shell recipes.
	Excluded int `json:"excluded,omitempty"`
}

Plan describes how kibble replays one repo's documented examples: which code blocks run, the lines inside them, and the fixtures, packages, and environment the session needs. Every judgment call lives in the plan, so the executor stays deterministic and the plan can be inspected with -plan.

func BuildPlan

func BuildPlan(repo, dir, markdown string, binaries []string, installs []PlanInstall, cfg *config.ExamplesConfig, rec *Recognizer) *Plan

func (*Plan) Merge

func (p *Plan) Merge(doc string, other *Plan)

Merge folds another document's plan into this one, so a repository's whole documentation tree is replayed in a single session.

Installing the documented tool once per document is what made a large tree unverifiable: the install dominates a session, and multiplying it by the number of pages meant mise could not finish three of its 421. Everything a session needs that is the same for every page, the installs, the binaries, the packages and the environment, is therefore kept once, and only the steps accumulate. Step identifiers are renumbered as they arrive, since each document numbered its own blocks from one and merging them would otherwise produce several b1s in the same session.

type PlanInstall

type PlanInstall struct {
	// Cmd is the shell command that performs the install.
	Cmd string `json:"cmd"`
	// Ecosystem is the toolchain the command needs, empty when it is Go and
	// the configured default image already provides it.
	Ecosystem string `json:"ecosystem,omitempty"`
	// Dir is the directory the install runs from, empty for the session's
	// copy of the repository.
	Dir string `json:"dir,omitempty"`
	// binary is the tool this install is expected to provide. It exists to
	// drop alternative installs of the same tool and is not part of output.
	Binary string
	// Bootstrap installs the package manager itself when the image lacks it.
	Bootstrap string
}

PlanInstall is one documented install the session runs before replaying examples, so the binary the examples call is on PATH.

type PlanLine

type PlanLine struct {
	// Cmd is the command exactly as the session will run it.
	Cmd string `json:"cmd"`
	// Skip is why the line does not run; empty means it runs.
	Skip string `json:"skip,omitempty"`
	// SkipReason is the machine-readable code for Skip, so a consumer can
	// filter and audit skip reasons without parsing the human-facing string.
	SkipReason verdict.Reason `json:"skipReason,omitempty"`
	// Gap marks a Skip whose cause is the document rather than the
	// container: the line names something no documented step creates.
	Gap bool `json:"gap,omitempty"`
	// NonzeroOK accepts a nonzero exit as documented behavior.
	NonzeroOK bool `json:"nonzeroOk,omitempty"`
	// Synthetic names the files kibble fabricated so this line had something
	// to read. The document referenced them and never created them, so a pass
	// here proves the command accepts kibble's invented input, which is a
	// weaker claim than the documented example working.
	Synthetic []string `json:"synthetic,omitempty"`
	// Line is the 1-based README line the command sits on, 0 when unknown.
	Line int `json:"line,omitempty"`
}

PlanLine is one logical command from a block: a single documented line, or several physical lines joined by a continuation or a heredoc.

type PlanStep

type PlanStep struct {
	// ID names the step by its order in the plan, such as b3.
	ID string `json:"id"`
	// Doc is the document the block came from, relative to the repository
	// root. One session now replays every document a repository has, because
	// installing the tool once per document made a documentation tree of any
	// size unverifiable: mise carries 421 of them and three could not finish.
	// The step has to carry its own provenance, since the session no longer
	// belongs to a single page.
	Doc string `json:"doc,omitempty"`
	// Heading is the section heading the block appears under.
	Heading string `json:"heading,omitempty"`
	// Lines are the logical shell lines of the block.
	Lines []PlanLine `json:"lines"`
	// Background runs the step behind the session and kills it at the end.
	Background bool `json:"background,omitempty"`
	// ReadyLog is output that marks a background step ready.
	ReadyLog string `json:"readyLog,omitempty"`
}

PlanStep is one documented code block prepared for execution.

func (PlanStep) Runnable

func (s PlanStep) Runnable() bool

Runnable reports whether any line of the step actually runs.

type Recognizer

type Recognizer struct {
	// Clones reports whether a line clones a repository. A block containing
	// one is a build recipe, not an example, so the whole block is dropped.
	Clones func(flat string) bool
	// Installs reports whether a line installs the documented tool. Such a
	// line is skipped on its own; the rest of the block may still be examples.
	Installs func(flat string) bool
}

BuildPlan turns a README's code blocks into an execution plan for one repo. binaries and modules come from the repo's go-install steps, dir is the local checkout used to resolve file references, and cfg carries the repo's .kibble.yml overrides, if any. Recognizer answers what a documented line is, so the planner can leave install recipes to whatever installs them instead of replaying them as examples. The planner used to hold the patterns itself, which meant the layer deciding what to run also had to know what every ecosystem's install looks like. Asking instead of knowing keeps that knowledge in one place.

Jump to

Keyboard shortcuts

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