tools

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 39 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 tools is abcd's explain-then-install mode (itd-63): the curated registry of the external tools abcd knows, the plain-language explanation a verb gives when it finds one missing, and the one place a confirmed install step is run.

It is a MODE other verbs call, never a surface of its own (the product thinker's decision 3, 2026-09-21): a verb that finds a tool missing asks Explain for what to say and, where it offers the install, hands Install a Confirm function its front door supplies. The package has no transport knowledge — it never reads a terminal and never writes to stdout — so the CLI asks on the terminal, the plugin page asks through the host's question tool, and this code is the same under both (criterion 5).

The trust boundary is Install. What it fetches is fixed data compiled into the binary (release.go): one release download per platform, named by its full URL with its sha256 pinned beside it, never composed from a flag, a repository file or an environment value, and never discovered (brief invariant 7: no version-discovery request exists anywhere in abcd). It runs only after the caller's Confirm returns yes, never in CI, writes nothing until the download has passed its check, and needs no admin rights. See install.go and adr-2610241057124151.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Known

func Known(name string) bool

Known reports whether the registry holds an entry for name.

func Missing

func Missing(cause error, name string, capability Capability) error

Missing wraps cause with the explanation for name as capability uses it.

func Names

func Names() []string

Names returns the registered tool names, sorted.

func Resolve added in v0.16.0

func Resolve(name string) (string, error)

Resolve is where abcd runs name from: abcd's own recorded copy when there is one, it is intact and its version lies in the range abcd works with, whatever comes first on PATH (the intent's fourth criterion), and otherwise the PATH lookup. Every caller that runs a registered tool resolves it here, never by a bare exec.LookPath.

func SwapNetworkForTest added in v0.16.0

func SwapNetworkForTest(get func(ctx context.Context, url string, limit int64) ([]byte, error), attest Attester) (restore func())

SwapNetworkForTest makes Default download through get and check signed build records through attest, for a test of another package that drives an install to a yes. It returns the restore.

func WithinTree added in v0.12.0

func WithinTree(p, resolved, guard string) bool

WithinTree reports whether the program at p, which resolves to resolved after symlinks, lies inside the tree at guard, judged lexically and after symlink resolution on both sides. It is the one in-checkout judgement for a program: the installer refuses to run what it holds, and ahoy's presence check does not count it as installed. Both p and guard are absolute; the caller has already resolved p.

Types

type Answer

type Answer struct {
	Yes bool
	Why string
}

Answer is a caller's reply to the install question: yes or no, and in words how the reply was reached (typed at a terminal, named with a flag, no terminal to ask at), which the result repeats so a no is never silent.

type Archive added in v0.16.0

type Archive string

Archive is how an asset is packaged.

const (
	// TarGz is a gzip-compressed tar archive.
	TarGz Archive = "tar.gz"
	// Zip is a zip archive.
	Zip Archive = "zip"
)

type Asset added in v0.16.0

type Asset struct {
	// URL is the release asset's full https://github.com/<repo>/releases/download/
	// address: no "latest", no redirect a release page could move.
	URL string
	// SHA256 is the asset's digest, copied from the release's published
	// checksums file and checked against the downloaded bytes when it was
	// pinned. It is the check every download must pass before anything is
	// written.
	SHA256 string
	// Archive is the asset's packaging.
	Archive Archive
	// Member is the program's path inside the archive.
	Member string
}

Asset is one platform's download.

type Attester added in v0.16.0

type Attester func(ctx context.Context, s Signer, digest []byte) (string, error)

Attester checks an asset's build provenance against a Signer, returning the verified signer identity.

type Capability

type Capability string

Capability names what a verb is doing when it finds a tool missing. The same tool is optional for one capability and required for another, so an explanation is always for a (tool, capability) pair.

const (
	// TranscriptScan is the secret scan of captured session transcripts in a
	// repository that has NOT armed gitleaks: the native scanner covers it.
	TranscriptScan Capability = "transcript-scan"
	// TranscriptScanArmed is the same scan in a repository that armed gitleaks
	// in .abcd/config/gitleaks.json: without the binary a release refuses,
	// while the history store still stores the transcript on the native
	// scanner and names the gap in its receipt (the 2026-09-25 ruling on
	// iss-2608291814575788).
	TranscriptScanArmed Capability = "transcript-scan-armed"
	// GitHubSettings is every verb that reads or changes the repository's
	// settings on GitHub (ahoy remote, site setup), which abcd does only
	// through gh.
	GitHubSettings Capability = "github-settings"
)

type Confirm

type Confirm func(Explanation) Answer

Confirm asks the person whether to run the install the explanation shows. The front door supplies it; a nil Confirm is a no.

type Copy added in v0.16.0

type Copy struct {
	// Path is where it is, in the tilde form.
	Path string `json:"path"`
	// Version is the version it reports, or "" when it reported none.
	Version string `json:"version,omitempty"`
	// Compatible reports that Version lies in the range abcd works with.
	Compatible bool `json:"compatible"`
	// Why says why it is not compatible.
	Why string `json:"why,omitempty"`
	// Unjudged reports that its version was not read (Installer.PathOnly).
	Unjudged bool `json:"unjudged,omitempty"`
	// contains filtered or unexported fields
}

Copy is one copy of a tool on the machine.

type Download added in v0.16.0

type Download struct {
	Version string `json:"version"`
	URL     string `json:"url"`
	SHA256  string `json:"sha256"`
	// Member is the program's path inside the archive.
	Member string `json:"member"`
	// Dest is where the program is written, in the tilde form.
	Dest string `json:"dest"`
	// Checks is how far the download is checked.
	Checks string `json:"checks"`
	// ChecksumOnly reports a tool whose makers publish no signed build record.
	ChecksumOnly bool `json:"checksum_only"`
	// contains filtered or unexported fields
}

Download is the checked download an install would make.

type Explanation

type Explanation struct {
	Tool           string      `json:"tool"`
	Known          bool        `json:"known"`
	Capability     Capability  `json:"capability"`
	CapabilityName string      `json:"capability_name,omitempty"`
	Requirement    Requirement `json:"requirement,omitempty"`
	What           string      `json:"what,omitempty"`
	Homepage       string      `json:"homepage,omitempty"`
	Does           string      `json:"does,omitempty"`
	WithoutIt      string      `json:"without_it,omitempty"`
	NativeDefault  string      `json:"native_default,omitempty"`
	OnDecline      string      `json:"on_decline,omitempty"`
	// Download is the checked download Install would make on this platform:
	// the pinned version, its full URL and sha256, where the program goes and
	// how far it is checked. nil when the registry names none (an unknown
	// tool, or a platform abcd's release holds no download for).
	Download *Download `json:"download,omitempty"`
	// Plan is what Install found on this machine before it asked: the copy
	// already installed and whether it is compatible, and which copy will
	// run. Set only on the explanation Install hands its Confirm.
	Plan    *Plan    `json:"plan,omitempty"`
	Effects string   `json:"effects,omitempty"`
	Verify  []string `json:"verify,omitempty"`
	// RegistryGap is set for a tool the registry does not know: the gap is
	// abcd's own, and this names the capture that records it.
	RegistryGap string `json:"registry_gap,omitempty"`
}

Explanation is what a verb says when it finds a tool missing (criterion 1): the tool, whether it is optional or required for this capability, what works without it, what it would do, and the exact install step, all from the registry. It is structured so each front door renders it its own way (the plugin page reads it from a verb's --json); Lines is the plain-text rendering every front door shares.

func Explain

func Explain(name string, capability Capability) Explanation

Explain renders the explanation for name as capability uses it, on the running platform, into the running account's bin folder.

func (Explanation) Lines

func (e Explanation) Lines() []string

Lines is the plain-text explanation, one line per part, the first naming the tool and whether it is optional or required.

func (Explanation) ManualText added in v0.16.0

func (e Explanation) ManualText() string

ManualText is the same install for a person to make by hand: the exact URL, the sha256 to check it against, and where the program goes.

func (Explanation) StepText

func (e Explanation) StepText() string

StepText is the install as a person reads it in the install question, or the reason there is none. It never names a step that needs admin rights.

type Installed added in v0.16.0

type Installed struct {
	// Path is the program's absolute path.
	Path string `json:"path"`
	// SHA256 is the digest of the bytes abcd wrote there.
	SHA256 string `json:"sha256"`
	// Version is the pinned release it came from.
	Version string `json:"version"`
	// AssetSHA256 is the digest of the downloaded archive, which matched the
	// pin.
	AssetSHA256 string `json:"asset_sha256"`
	// Checked is how far the download was checked, as the result said it.
	Checked string `json:"checked"`
}

Installed is one copy abcd installed.

type Installer

type Installer struct {
	// LookPath resolves a bare program name on the operator's PATH.
	LookPath func(string) (string, error)
	// Run executes an argv whose argv[0] is already resolved, without a shell.
	Run func(context.Context, []string) ([]byte, error)
	// Getenv reads the environment (CI detection, PATH, the XDG folders).
	Getenv func(string) string
	// GOOS and GOARCH select the platform's download.
	GOOS, GOARCH string
	// Guard is the directory a program abcd runs, and the bin folder it
	// writes into, must lie outside: the repository the verb was run from.
	Guard string
	// Home is the person's home directory: the record lives below it, and
	// ~/.local/bin is the default bin folder.
	Home string
	// Get downloads one URL whole, bounded to limit bytes.
	Get func(ctx context.Context, url string, limit int64) ([]byte, error)
	// Attest checks a download's signed build record.
	Attest Attester
	// Release is the pinned release for a registered tool; the registry's by
	// default, replaced in tests to point a download at a local server.
	Release func(name string) (Release, bool)
	// PathOnly makes Plan start no program: a copy the PATH finds counts as
	// usable without its version being read. The detection pass the hooks
	// run sets it; an install never does.
	PathOnly bool
}

Installer installs the registry's tools. Every process-, network- and home-touching seam is a field so the whole decision path is exercised in tests with no network and no real home; Default is the production wiring.

func Default

func Default(guard string) *Installer

Default is the production installer for a verb run from guard (its repository root, or its working directory outside one). Inside a test binary its network is the one SwapNetworkForTest installed, and by default none: a test that reaches a yes is refused the download rather than making one, so no test of another package can fetch a real release.

func (*Installer) Install

func (in *Installer) Install(name string, capability Capability, confirm Confirm) Result

Install is the trust boundary. In order, and each refusal writes nothing:

  1. An unknown tool is refused: nothing is composed from a name.
  2. CI never installs, and is not asked.
  3. The plan is made: an intact copy of abcd's own, or a compatible copy installed some other way, is used and nothing is asked or installed; a platform with no download, or a bin folder whose program abcd did not install, is refused.
  4. The caller's Confirm must return yes; nil is a no.
  5. The bin folder must lie outside the guarded tree.
  6. The download is fetched whole, bounded, over https from GitHub alone, and its sha256 must equal the one abcd's release pins.
  7. A tool whose makers sign their builds must carry a signed build record that verifies against the pinned signer.
  8. The program is read out of the archive by its exact name.

Only then is the program written, atomically, at the account's own rights; the verify command must then report the pinned version, and the copy is recorded so abcd runs it by its path. A copy that fails the verify, or cannot be recorded, is removed again.

func (*Installer) Plan added in v0.16.0

func (in *Installer) Plan(name string) Plan

Plan decides what to do about name. It never downloads, never writes, and runs only the verify command of a copy PATH already finds, to read its version, and not even that under PathOnly.

abcd's own recorded copy is used only while its version lies in the range abcd works with and is the one abcd's release pins. A copy of abcd's at another version in the range still runs, and the pin is offered as an upgrade over it; one outside the range is not run, and abcd's pinned copy is offered in its place. Either way the download replaces only a copy that is still the bytes abcd wrote (Install).

type MissingError

type MissingError struct {
	Cause       error
	Explanation Explanation
}

MissingError is a verb's refusal for a missing tool with the registry's explanation appended: the refusal stands exactly as it was (its cause stays reachable through errors.Is), and only its message grows to say what the tool is, whether this capability needs it, and the exact install step.

func (*MissingError) Error

func (m *MissingError) Error() string

func (*MissingError) Unwrap

func (m *MissingError) Unwrap() error

type Plan added in v0.16.0

type Plan struct {
	Tool   string     `json:"tool"`
	Action PlanAction `json:"action"`
	// Pinned is the version abcd's release fixes.
	Pinned string `json:"pinned,omitempty"`
	// Compatible is the range of versions abcd works with, as a person reads
	// it.
	Compatible string `json:"compatible,omitempty"`
	// Download is the checked download, when one is offered.
	Download *Download `json:"download,omitempty"`
	// Existing is the copy PATH finds first, when it is not abcd's own.
	Existing *Copy `json:"existing,omitempty"`
	// Owned is abcd's own recorded copy, when one is in place.
	Owned *Copy `json:"owned,omitempty"`
	// Runs says which copy abcd runs, and which the person's shell runs.
	Runs string `json:"runs,omitempty"`
	// Upgrade reports that the download replaces abcd's own copy, which
	// still works, with the version abcd's release pins.
	Upgrade bool `json:"upgrade,omitempty"`
	// Why says why the tool is unavailable.
	Why string `json:"why,omitempty"`
}

Plan is what setup would do about one tool, decided from the disk, the PATH and the version the copy already installed reports, with no network: the core API a setup flow lays out before it asks anything. It prints nothing.

type PlanAction added in v0.16.0

type PlanAction string

PlanAction is what setup does about one tool.

const (
	// UseOwned: abcd's own recorded copy is in place and intact.
	UseOwned PlanAction = "use-abcd-copy"
	// UseExisting: a copy installed some other way is compatible, so it is
	// used and nothing is installed.
	UseExisting PlanAction = "use-existing"
	// InstallOwn: no compatible copy is in place, so abcd offers its own.
	InstallOwn PlanAction = "install"
	// Unavailable: abcd cannot install the tool here, and says why.
	Unavailable PlanAction = "unavailable"
)

type Record added in v0.16.0

type Record struct {
	SchemaVersion int                  `json:"schema_version"`
	Tools         map[string]Installed `json:"tools"`
}

Record is the installed-tools record.

type Release added in v0.16.0

type Release struct {
	// Repo is the tool's GitHub repository, owner/name.
	Repo string
	// Version is the pinned release, without its leading v.
	Version string
	// Assets is the download for each platform abcd supports, keyed
	// "<GOOS>/<GOARCH>". A platform with no entry has no install.
	Assets map[string]Asset
	// Signer is who must have signed the asset's SLSA build provenance, for a
	// tool whose makers publish one. nil is a tool that publishes no signed
	// build record: its download is checked by checksum only, and every
	// explanation and result says so.
	Signer *Signer
	// Compatible is the range of the tool's versions abcd works with. A copy
	// already installed is used, and nothing installed, only when its version
	// falls inside it (the intent's third criterion). The pinned Version must
	// fall inside it too (TestEveryPinnedReleaseIsCompatible), which is the
	// hook a release-time compatibility check moves (iss-2610240959030370).
	// The version is read from the output of the tool's Verify argv.
	Compatible VersionRange
}

Release is the one build of a tool abcd installs, fixed in abcd's own release (brief invariant 7: "provisioning fetches only a manifest-named, pinned, checksum-verified artifact. No version-discovery request exists anywhere in abcd"). Every field is compiled in: the download URL is spelled out in full, the asset's sha256 is pinned beside it, and nothing about it is read from the network, a flag, a repository file or the environment. A tool therefore updates only when abcd does (dcn-2610240845548776, and the intent's third decision).

func (Release) Checks added in v0.16.0

func (r Release) Checks() string

Checks says how far a download of this release is checked, in the words a person reads: always the sha256 abcd's release fixes, and the signed build record only where the makers publish one.

type Removal added in v0.16.0

type Removal struct {
	Tool    string `json:"tool"`
	Path    string `json:"path"`
	Removed bool   `json:"removed"`
	Note    string `json:"note"`
}

Removal reports what uninstall did with one recorded copy.

func Uninstall added in v0.16.0

func Uninstall(home string) ([]Removal, error)

Uninstall removes the copies the record in home names, and only those, and only while each is still the bytes abcd wrote: a file changed since, or replaced by another, is left where it is and said so. The record goes once nothing it names is still abcd's to remove. Nothing else is touched: a copy installed some other way was never recorded, so it is never reached.

type Requirement

type Requirement string

Requirement is whether a capability needs a tool or merely works better with it (adr-22: most dependencies are optional adapters over a native default).

const (
	// Optional: the capability runs on its native default without the tool.
	Optional Requirement = "optional"
	// Required: the capability cannot run without the tool.
	Required Requirement = "required"
)

type Result

type Result struct {
	Tool string `json:"tool"`
	// Ready reports that a copy abcd can run is in place: one already
	// installed and compatible, abcd's own recorded copy, or the one this
	// install wrote and verified.
	Ready bool `json:"ready"`
	// Ran reports that a download was started.
	Ran bool `json:"ran"`
	// Installed reports that the checked program was written into the bin
	// folder.
	Installed bool `json:"installed"`
	// Verified reports that the verify command ran the written copy and it
	// reported the pinned version.
	Verified bool `json:"verified"`
	// Declined reports that nobody said yes (a no, no confirmation, CI).
	Declined bool `json:"declined"`
	// Path is the copy abcd runs, in the tilde form, when Ready.
	Path string `json:"path,omitempty"`
	// Version is the version of that copy.
	Version string `json:"version,omitempty"`
	// Checked is how far the download was checked, when one was written.
	Checked string `json:"checked,omitempty"`
	// ChecksumOnly reports that the download was checked by its pinned sha256
	// alone, because its makers publish no signed build record.
	ChecksumOnly bool `json:"checksum_only,omitempty"`
	// Runs says which copy abcd runs, and which one the person's shell runs.
	Runs string `json:"runs,omitempty"`
	// Why is the reason nothing was written, or what failed.
	Why string `json:"why,omitempty"`
	// Output is the bounded tail of the verify command's output on a failure,
	// or its first line on success.
	Output string `json:"output,omitempty"`
	// OnDecline is the capability's standing after a no or a failure.
	OnDecline string `json:"on_decline,omitempty"`
	// contains filtered or unexported fields
}

Result reports one Install: whether a compatible copy is ready for abcd to run, what was downloaded and how far it was checked, or why nothing was written and what the capability continues on.

func Install

func Install(name string, capability Capability, confirm Confirm, guard string) Result

Install explains name as capability uses it, asks confirm, and on a yes installs the pinned release. It is the package-level spelling of Default(guard).Install.

func (Result) Summary

func (r Result) Summary() string

Summary is the one line a verb reports for the result. Every path that leaves no copy ready ends with the capability's standing ("continuing on the native secret scanner"), so a no is loud rather than silent.

type Signer added in v0.16.0

type Signer struct {
	Repo     string // owner/name
	Workflow string // path of the signing workflow inside the repository
	Ref      string // the git ref the signing workflow ran from
}

Signer is a build-provenance policy: the certificate identity a Sigstore bundle over the asset must carry. It is pinned exactly (no prefix match): the repository, the workflow file inside it, and the ref that workflow ran from. The digest is pinned in abcd's own source, so the provenance is not bound to a commit: it proves the pinned bytes were built by the makers' workflow, which a release page edit cannot forge (provenance.go's rationale).

func (Signer) SAN added in v0.16.0

func (s Signer) SAN() string

SAN is the certificate's subject alternative name the policy requires.

type Tool

type Tool struct {
	Name     string
	What     string // what the tool is, plainly
	Homepage string // where to read what it is
	Uses     map[Capability]Use
	// Release is the one build of the tool abcd installs: its version, its
	// download per platform with the sha256 pinned here, and how far its
	// makers let a download be checked (release.go).
	Release Release
	// Effects is what the install does on the machine and over the network, and
	// what it does not.
	Effects string
	// Verify is the argv that proves the tool runs once installed; argv[0] is
	// the tool's name, replaced by the absolute path of the copy being judged.
	Verify []string
}

Tool is one registry entry.

type Use

type Use struct {
	// Capability is the capability's human name.
	Capability string
	// Requirement is optional or required, for this capability.
	Requirement Requirement
	// Does is what abcd uses the tool for here.
	Does string
	// WithoutIt is what works without the tool (for an optional use, the
	// native default; for a required one, what fails and the way back).
	WithoutIt string
	// NativeDefault is what the capability continues on after a no; empty when
	// there is none.
	NativeDefault string
	// OnDecline is the loud line's tail after a no or a failed install:
	// "continuing on <native default>" for an optional use, the standing
	// refusal for a required one.
	OnDecline string
}

Use is what one capability does with a tool, in the words a person reads.

type VersionRange added in v0.16.0

type VersionRange struct {
	Min   string
	Below string
}

VersionRange is [Min, Below): Min inclusive, Below exclusive. Below empty means no upper bound.

func (VersionRange) Contains added in v0.16.0

func (r VersionRange) Contains(v string) bool

Contains reports whether v lies in the range. A version that does not parse lies in no range.

func (VersionRange) String added in v0.16.0

func (r VersionRange) String() string

String is the range as a person reads it.

Jump to

Keyboard shortcuts

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