dogfood

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 26 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 dogfood decides which abcd binary a hook runs in a checkout the person has opted in to dogfooding, and builds it (iss-2610070547057816).

In abcd's own source checkout the installed release guards the session, so a hazard rule that landed on the default branch after the last release is not enforced there until the next one ships. The person opts a checkout in by listing it in ~/.abcd.noindex/dogfood-roots, one checkout per line: its absolute path, a tab, the URL of the remote its reviewed branch lives on, and optionally a tab and that branch, main when left out; "#" starts a comment. Inside a listed checkout, and inside every worktree that checkout records as its own, the hooks run a build of that branch's tip as the declared remote reports it, and everywhere else the installed release, unchanged.

Four properties are load-bearing.

The opt-in is the PERSON'S, read from their home and never from a repository. Recognising abcd's source by its module path was rejected: a repository posing as abcd would get its own code run by the hooks. The list is read through fsutil.HomeDeclarationEntry, the fields-bearing form of the one reader behind every "declare this checkout" opt-in (trusted-roots, local-transcript-roots, filter-roots), so it is honoured only as a regular file this account owns that no one else can write, within its size cap, reached through no symlinked folder; a list failing that is IGNORED out loud and the installed release runs everywhere. A line that names a checkout but no remote builds nothing, and says so.

The build's SOURCE is the tip the declared remote reports for the declared branch, and the store's record of that answer is the only thing that chooses a build. The background builder asks the remote (`git ls-remote` under the isolated git environment, outside every repository, never prompting for credentials, bounded in time and in output), records the answer in the store under the build lock, and builds that commit once the checkout holds it. Resolve, the hook's half, never touches the network and names a ready build only for the recorded tip. The checkout's own refs and config choose nothing: refs/remotes/origin/*, origin/HEAD and remote.origin.* are all an agent in the checkout can rewrite with ordinary git commands, so refs/remotes/origin/<branch> serves only to prompt a fresh check when it is not what it was at the last one, as the record's age does once it passes recheckAfter. Moving a local ref therefore costs at most one ls-remote, which returns the reviewed tip, and no agent commit changes the guard that judges the agent's next command.

That holds only for a remote no agent can move, so the declared remote is read over https or ssh alone (remoteRefusal). A filesystem path or a file:// URL names a repository this account can write, which an agent moves to its own commit with one `git fetch` into it, and git:// and http:// let anyone on the network path answer; a line declaring any of them is refused out loud and builds nothing. Which https or ssh remote is declared stays the person's call: it must be one the agent cannot push to, such as a protected branch on a forge.

The build is the reviewed commit or nothing. The checkout's object store, its refs/replace/* and its repository-local attributes are writable by anyone who can commit there, so the commit and every tree under it are read with replacement objects off and re-hashed against their names (verifiedTree), and the export is checked blob by blob against that verified tree (verifyExport) before anything is built.

A failure never weakens the guard below the installed release: no declared remote, a remote that cannot be read, a tip the checkout has not fetched, and a build that is missing, running, failed, or not runnable each leave Resolve naming no binary, the hook runs the installed release, and a note says why on stderr. The PreToolUse shim adds the run-time half: a dogfood guard that answers exit 1, which is a warn or "NOT CHECKED", or that dies, hands the same command to the installed release, whose deny stands.

What this does not defend is the account itself. The declaration and the store are protected by being this uid's alone, so anything running as this account can still edit the declaration or replace a file in the store, and the builder and the hooks inherit the account's whole environment (the go toolchain, its module cache and GOENV, PATH, git's own variables and the certificate and proxy settings it reads, ~/.ssh, among the rest), which stays the account's; what no longer chooses the build is anything in the checkout.

Index

Constants

View Source
const (
	// BinaryName is the build's file name inside its commit directory.
	BinaryName = "abcd"

	// DefaultBranch is the reviewed branch of a line that names none.
	DefaultBranch = "main"

	// TrackingRemote is the remote whose remote-tracking ref for the declared
	// branch prompts a fresh check when it moves. It never names the source.
	TrackingRemote = "origin"
)

Variables

View Source
var (
	// RootsRelPath is the person's opt-in list, relative to their home.
	RootsRelPath = abcdhome.Rel("dogfood-roots")

	// RootsDisplay names the list in tilde form, so a message carries no home
	// path and a line a person pastes into a shell works.
	RootsDisplay = abcdhome.Display("dogfood-roots")

	// StoreDisplay names the build store in tilde form.
	StoreDisplay = abcdhome.Display("dogfood")

	// StoreRelPath is the machine-scoped build store, relative to the home:
	// dogfood/<root-sha>/<commit>/abcd. It is keyed on the repository's root
	// commit, as the worktree and transcript stores are, and on the commit the
	// build was made from, so a build is never shared between repositories and
	// a moved tip is a different directory.
	StoreRelPath = abcdhome.Rel("dogfood")
)
View Source
var ErrBuildRunning = errors.New("another dogfood build is running")

ErrBuildRunning is Build's answer when another build holds the store's lock.

Functions

func Build

func Build(home string, c Checkout) (string, error)

Build checks the declared remote for the reviewed tip, records the answer in the store, and makes the build of that tip unless one is already there, returning its path. It is the only caller of the network. It holds the store's lock for the whole check, export and build, so two hooks firing at once cannot race it: the second gets ErrBuildRunning at once.

c.Commit is ignored: the commit built is the one the remote reports now, never one a caller names. A remote that cannot be read records no tip, and a tip the checkout does not hold yet is recorded with a note to fetch it and is not built; either way Resolve then names no build and says why. The source is a clean export of the tip (`git archive`, checked against the commit's verified tree) into a fresh directory under the store, never the working tree, and the finished binary is moved into place by one rename, so a reader sees no build or a whole one. A failed build leaves a marker beside its log that Resolve reads.

func TipNameForTest

func TipNameForTest(url, branch string) string

TipNameForTest names the verified-tip record of url and branch, for a test outside the package that plants one.

Types

type Checkout

type Checkout struct {
	// Toplevel is the session's working tree.
	Toplevel string
	// Repo is the listed checkout that vouches for Toplevel: Toplevel itself,
	// or the main working tree that records Toplevel as one of its worktrees.
	// Every git read and the export run there.
	Repo    string
	RootSHA string
	// URL and Branch are the reviewed remote and branch the person's line
	// declares for Repo.
	URL, Branch string
	// Tracking is the commit refs/remotes/origin/<Branch> names in Repo, "" when
	// none. It only prompts a check; it is never built.
	Tracking string
	// Commit is the tip the store last verified on URL, "" before a check has
	// succeeded.
	Commit string
}

Checkout is a listed checkout a session runs in, the remote the person declared for it, and the tip the store last verified there.

func (Checkout) LogDisplay

func (c Checkout) LogDisplay() string

LogDisplay is the build log's path in tilde form.

func (Checkout) Short

func (c Checkout) Short() string

Short is the commit's abbreviation as a message shows it.

func (Checkout) Source

func (c Checkout) Source() string

Source names the declared branch and remote as a message shows them, with any credentials in the URL left out.

type Plan

type Plan struct {
	// Binary is the build to run, "" for the installed release.
	Binary string
	// Checkout is set when the session's checkout is listed with a remote.
	Checkout *Checkout
	// StartBuild asks the caller to start a check and build of Checkout in
	// the background; Binary, or the installed release, runs meanwhile.
	StartBuild bool
	// Notes are whole lines for stderr, each starting "abcd dogfood:".
	Notes []string
}

Plan is what a hook runs.

func Resolve

func Resolve(home, cwd string) Plan

Resolve decides what a hook standing in cwd runs. home is the person's home directory. It writes nothing and reads nothing over the network; a check or build it asks for is the caller's to start.

Jump to

Keyboard shortcuts

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