plan

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 15 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, and every configuration key it writes as a configuration file sets one.

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, and configuration keys it writes as a file sets
	// them. 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"`
	// NotFoundCodes are the exit codes the documents say mean a lookup found
	// nothing, such as witr's "2 not found". A documented binary exiting with
	// one of them reports an empty result rather than a broken command.
	NotFoundCodes []int `json:"notFoundCodes,omitempty"`
	// Unrun are the commands of code blocks the plan leaves out, of two words
	// or more. A failure that tells the reader to run one of them first, as
	// headscale's Makefile says to run `nix develop`, failed for want of a
	// step the documents give and the session could not take.
	Unrun []string `json:"unrun,omitempty"`
	// RootGoFiles are the Go files at the top of the checkout before the
	// session starts. A Go build that finds a document's file beside one of
	// them met the repository's own package, which the document never wrote.
	RootGoFiles []string `json:"rootGoFiles,omitempty"`
	// Roots are the names at the top of the checkout, .git aside. A path a
	// line names that starts with one of them points into the repository, so
	// its absence is the document's gap. A path that starts nowhere in the
	// checkout is the reader's own input, such as the chart or the parameters
	// file a flag example scans.
	Roots []string `json:"roots,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
	// FromCheckout marks an install kibble made up because no documented one
	// gave the session a binary: the tool built from the checkout. Examples
	// run against it say so, and the documented install stays untested.
	FromCheckout bool `json:"fromCheckout,omitempty"`
	// Release is the release asset URL a documented download fetched, set when
	// that download is the session's install because no other documented
	// install puts the tool on PATH. Examples run against it say so.
	Release string `json:"release,omitempty"`
}

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"`
	// Need is a file the line reads that the planner saw no earlier line
	// create. The session reports whether it exists just before the line
	// runs, so a missing file is judged at run time rather than guessed.
	Need string `json:"need,omitempty"`
	// Unplanned is the location of a code block earlier in the document that
	// the plan leaves out, set only alongside Need. That block never runs,
	// so it may be what creates the needed file, and a missing file after it
	// is not proof of the document's gap.
	Unplanned string `json:"unplanned,omitempty"`
	// NonzeroOK accepts a nonzero exit as documented behavior.
	NonzeroOK bool `json:"nonzeroOk,omitempty"`
	// Shown is the output the document shows for this line, as the comment
	// lines directly under it in its block, without the leading #. The verdict
	// accepts a nonzero exit only when the tool printed one of them.
	Shown []string `json:"shown,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"`
	// File is the path a titled code block names when this line writes the
	// block's content to it. Documentation sites show a file the reader is to
	// create as a block titled with its name, and a later line that reads it
	// was never missing it.
	File string `json:"file,omitempty"`
	// Creates names the paths this line writes, as the planner reads them. A
	// later line that finds one missing after this line failed may be missing
	// it for that reason alone, which is not the document's gap.
	Creates []string `json:"creates,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"`
	// Details numbers the outermost HTML details element the block sits in,
	// 0 outside one. Collapsed details under one heading are separate
	// sections, often alternative setups.
	Details int `json:"details,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
	// Provides returns the binary a line installs when that binary is some
	// other tool an example uses, such as ruff after `uv tool install ruff`
	// in uv's README. Later lines calling it are examples, not unknown
	// commands. It returns empty for every other line.
	Provides func(flat string) string
}

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