staletools

command module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause 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.

README

staletools

Which installed Go tools were built with an older toolchain — and, of those, which actually parse Go source, because only for those is staleness a wrong answer rather than an old binary.

$ staletools
READ GO SOURCE and are behind go1.27.1 — these do not fail, they MISREPORT:
  gopls                  go1.26.4     ~/go/bin
                         go install golang.org/x/tools/gopls@latest
  nonnil                 go1.26.4     ~/go/bin
                         go install github.com/go-vet-analyzers/nonnil/cmd/nonnil@latest
  …

INSTALLED TWICE with different toolchains — PATH order decides which runs:
  agentsync
      go1.27.1     ~/.local/bin
      go1.26.4     ~/go/bin
  …

81 Go tool(s), 29 behind go1.27.1, 8 of those read Go source
exit
0 no source-reading tool is behind, and nothing is shadowed
1 something is behind or shadowed — the message says which
2 refused: a directory that cannot be read

Why the distinction is the whole tool

A CLI built with go1.26 runs perfectly well under a go1.27 toolchain. It is old, not broken, and telling somebody to rebuild it is noise.

A tool that analyses Go source embeds go/types, go/parser and friends from its build toolchain. Built with go1.26 it cannot read go1.27 — and it does not fail cleanly. It emits a page of type errors about the standard library and then reports on whatever it managed to load:

rand.go:213:17: method must have no type parameters
-: This application uses version go1.26 of the source-processing packages
   but runs version go1.27 of 'go list'.

Measured 2026-10-08: deadcode did exactly that across a five-module project, and the output reads like findings. After a rebuild it reported 0 — a figure that means something only because a deliberately unreachable function was added first, to prove the tool could still see one.

It does not guess which tools those are

go version -m already prints the toolchain and the module graph; what it does not do is say which entries matter.

This reads the same build info and looks for the source-processing modules in the dependency list. go/types is in the standard library and leaves no trace, so the signal is golang.org/x/tools, honnef.co/go/tools and the like — evidence out of the binary, not a list of names somebody has to maintain.

The prefix match keeps the slash: golang.org/x/tools matches golang.org/x/tools/gopls and not golang.org/x/toolsomething.

And it finds the duplicate, which is the quiet one

A tool installed in two directories — ~/go/bin because go install puts it there, ~/.local/bin because somebody put it there deliberately — runs whichever PATH reaches first.

Observed on the machine this was written for: six tools present twice, the ~/.local/bin copies current and the ~/go/bin copies four months behind. Nothing was wrong until a shell added ~/go/bin, and then the answer would change without the command changing.

Two copies of the same build are not reported: that is housekeeping, and flagging it would train people to skip the section.

Install

go install github.com/go-fleettools/staletools@latest

Dependencies: golang.org/x/sys, and golang.org/x/mod for -sumdb (the tlog-verifying checksum-database client). debug/buildinfo is the standard library.

Usage

staletools [-all] [-want go1.27.1] [-releases] [dir...]
staletools -sumdb [dir...]
staletools -sumdb-hook            # Claude Code PreToolUse hook, JSON on stdin

With no directory it looks at $GOBIN (or $GOPATH/bin, or ~/go/bin) and ~/.local/bin. A directory that does not exist is skipped — not every machine has both.

-want compares against something other than the running toolchain, for asking "what would be stale if we moved to this?" before moving.

The totals are always printed, including the zeros

A command that says nothing when all is well cannot be told apart from one that failed to look — and this one walks directories that may not exist. If it finds no Go binaries at all it says so and asks whether that was the right directory.

-releases — the other way a tool is not what you think

staletools -releases

The default axis asks what a tool was built with. This one asks what it is:

an OLDER RELEASE of themselves — what runs is not what the repository says.
→ marks the 2 SOMETHING RUNS — the shell's PATH, or git's hooks path; the other 19 are where nothing reaches them:
→ pkgx            v0.16.1  → v0.17.1   2 release(s) back   ~/.local/bin
                  go install github.com/go-pkgx/pkgx@v0.17.1
→ bk              v0.27.0  → v0.28.0   1 release(s) back   ~/.local/bin
  tui-explorer    v0.4.1   → v0.62.0  65 release(s) back   ~/go/bin

The founding case: on 2026-10-11 the gitpush on PATH was v0.5.0 while its repository was at v0.6.3, and the global pre-push hook was built from v0.3.2. Nothing looked wrong — "the hook is the floor underneath" reads as a statement about the current code, and it was a week behind. go version -m on each binary would have said so, and nobody runs that on sixty binaries by hand.

→ is the whole point

The first version of this sorted by distance alone. Measured on the machine it was written for: of 30 lines, 24 named binaries in ~/go/bin, which is not on that PATH — tui-explorer, 65 releases behind in a directory nothing reads, printed above pkgx, 2 behind in the directory that runs. Eighty per cent of the report was noise and it was at the top. One release behind in a directory that runs beats sixty-five behind in one nothing reads.

⛔ And PATH is not the only thing that runs a file

The founding case above is a git hook, and for a year the → ranking put git hooks in the group it headed "a directory nothing reads". Measured on 2026-11-22, pointed at the hooks directory of the machine this was written for:

→ marks the 0 in a directory the shell SEARCHES; the other 9 are in one nothing reads:

Nine lines, no arrow — and two of the nine were pre-push and post-checkout, the binaries git executes on every push and every checkout, ranked among seven backup copies. The heading was not merely unhelpful, it was false: git reads that directory. The tool written because of a stale git hook demoted the stale git hook.

So liveness has two sources, read differently. The shell runs a file because its directory is on PATH, whatever the file is called. git runs a file because its name is a hook name and its directory is core.hooksPath (or a repository's own .git/hooks). Same directory, same command, now:

→ marks the 2 SOMETHING RUNS — the shell's PATH, or git's hooks path; the other 0 are where nothing reaches them:
→ post-checkout          v0.59.0  → v0.60.0   1 release(s) back   ~/.config/git/hooks
→ pre-push               v0.59.0  → v0.60.0   1 release(s) back   ~/.config/git/hooks

in git's hooks path under a name git NEVER RUNS — copies and witnesses, not an exposure:
  git-pre-push-guard     v0.40.0  → v0.60.0  32 release(s) back   ~/.config/git/hooks
  pre-push.bak-20261108-114950 …

That second group is the other half. A file sitting where git looks under a name git does not know — an older homonym of the tool rather than of the hook, a .bak-<stamp> witness that a recopy happened — is one git cannot run. That is provably inert, which is a stronger statement than "looks like a backup", and it is why the hook names are read out of githooks(5) rather than guessed: a name that is absent demotes a live hook, and a name that is invented puts an arrow on something nothing runs. The list is re-read from the installed git by a test, after a first draft written from memory carried proc-receive-pre-remote — a hook git has never had.

Those inert copies are reported and counted, but they do not set the exit status: they were seven of nine lines here, every one true and none of them anything to do, and a gate that is permanently red for a reason nobody can act on stops being read.

⚠ If git cannot be asked where it looks, the report says so beside the lines the answer would have ranked. An unreadable answer is not a verdict that nothing runs them.

The oracle is the Go module proxy, not a tag listing

It answers the question actually being asked — what @latest would install — through the GOPROXY protocol (@v/list, @latest; $GOPROXY, default proxy.golang.org), and it costs no GitHub API budget, which on this machine is shared with Renovate and is exhaustible. Answers are cached on disk for six hours (one request per module per 6 h), at most four run at once, and GOPROXY=direct or off means not measured, never a fall-back to a VCS host.

-sumdb — was the binary on PATH verified by sum.golang.org?

staletools -sumdb            # default ~/.local/bin

On 2026-11-29 sum.golang.org answered 404 for a fresh tag and an install was made with GONOSUMDB set: an unverified binary on PATH that every session runs. A deny rule on the spelling of that variable is bypassable (an export in a script, a program's exec environment, go env -w, string concatenation). This checks the result: a Go binary records the h1: zip hash of its main module and every dependency (debug/buildinfo); each is looked up in the checksum database through golang.org/x/mod/sumdb's Client, which verifies the signed tree head with the built-in sum.golang.org key and the record's inclusion in the Merkle tree (design) — a plain GET of the record would only believe the transport. No environment variable, flag or GOPROXY can change the database or the key.

verdict meaning
VERIFIED every module's h1: is confirmed by the database
MISMATCH the database holds a different hash for a module version: built from other bytes than the published ones
UNVERIFIED not confirmed: 404/410 (not yet published), unreachable, misbehaving, or a dependency with no recorded hash. An unreadable answer is never VERIFIED
NOSUM built from a working tree (main module (devel), or a VCS pseudo-version with no recorded sum): nothing published to compare
NOTGO not a Go binary (counted, not listed)
exit
0 every Go binary VERIFIED
1 a MISMATCH, UNVERIFIED or unreadable one (named, with the remedy GOBIN=<dir> go install <path>@<version> once the database answers — never GONOSUMDB), or no Go binary found
3 nothing worse than NOSUM
2 refused: a directory that cannot be read

Only VERIFIED is cached, under os.UserCacheDir()/staletools/sumdb, keyed by the SHA-256 of the file content — an unverified binary is asked again every time, and a changed byte never inherits a verdict. The client's own tile and tree-head cache lives beside it. Responses are bounded (1 MiB), file names cannot leave the cache, files over 512 MiB are not hashed.

-sumdb-hook

A PreToolUse hook for Bash. It reads the command (no shell is run), finds the programs it runs from ~/.local/bin — first word of each simple command, through env/sudo/ bash -c/pipes/$( ) — and answers: MISMATCH → deny; UNVERIFIED → deny (installed before sum.golang.org could verify it; reinstall the verified version); NOSUM → allow, reported on stderr. If the hook cannot read (bad input, unreadable file, database unreachable) it allows and says so on stderr: a refusal must be a verdict. A cache hit costs one read and one SHA-256 of the file (about 12 ms measured).

As a library: sumverify

v := &sumverify.Verifier{Source: sumverify.NewDBSource(sumverify.NewOps(dir)), CacheDir: dir}
r, err := v.Verify("/path/to/binary")   // r.Verdict, r.Bad, r.Detail
d := v.Decide(command, binDir, home)    // the hook's policy: d.Deny, d.Reason

As a library: staleness

import "github.com/go-fleettools/staletools/staleness"

bins, _ := staleness.Scan(dirs)                       // debug/buildinfo of each executable
rel := staleness.Latest(ctx, modules, staleness.ProxyFromEnv())
v := staleness.Judge(bins[0], rel[bins[0].Module])    // v.State

Five distinct states, none folded into "current": current, behind (with the number of releases back), unreleased (a pseudo-version), built locally (no module sum, or (devel): the version string is shown and cannot be compared) and not measured (proxy unreachable, module unknown). staleness.CheckSelf compares the running program with the file now on disk and with the latest release.

staleness/proc lists processes whose executable lies under given directories and which started before that file was last modified, so they still run the previous build. On darwin it uses sysctl (kern.proc.all, kern.procargs2), without cgo; other platforms return proc.ErrNotMeasured. Processes it cannot read are counted (Listing.Unreadable), not dropped. Nothing is signalled or restarted.

Bounds: only the given directories; regular files only; files over 256 MiB skipped; a symlink is followed only if its target stays under the user's home.

⛔ And it is not a comparison against the newest string. A tool built from an unreleased commit carries a pseudo-version that appears nowhere in the list, so it is reported under its own heading — "built from a commit that is NOT a release" — rather than mislabelled as behind. A module the proxy could not answer about is reported separately again: not a verdict of up to date.

Documentation

Overview

staletools reports which installed Go tools were built with an older toolchain — and, of those, which actually PARSE GO SOURCE, because only for those is staleness a wrong answer rather than an old binary.

THE DISTINCTION, WHICH IS THE WHOLE TOOL

A CLI built with go1.26 runs perfectly well under a go1.27 toolchain. It is old, not broken, and telling somebody to rebuild it is noise.

A tool that analyses Go source embeds go/types, go/parser and friends FROM ITS BUILD TOOLCHAIN. Built with go1.26 it cannot read go1.27, and it does not fail cleanly — it emits a page of type errors about the standard library and then reports on whatever it managed to load:

rand.go:213:17: method must have no type parameters
-: This application uses version go1.26 of the source-processing
   packages but runs version go1.27 of 'go list'.

Measured 2026-10-08: `deadcode` did exactly that across go-pkgx, and the output reads like findings. After a rebuild it reported 0 — a figure that means something only because a deliberately unreachable function was added first to prove the tool could still see one.

IT DOES NOT GUESS WHICH TOOLS THOSE ARE

`go version -m` already prints the toolchain and the module graph. What it does not do is say which entries matter. This reads the same build info and looks for the source-processing packages in the DEPENDENCY LIST — go/types is in the standard library, so the signal is the x/tools and analysis modules a source reader must import. That is evidence out of the binary, not a list of names somebody maintained.

AND IT FINDS THE DUPLICATE, WHICH IS THE QUIET ONE

A tool installed in two directories — ~/go/bin because `go install` puts it there, ~/.local/bin because somebody put it there deliberately — runs whichever PATH reaches first. Observed on this machine: every fleet scanner present twice, the ~/.local/bin copies current and the ~/go/bin copies four months behind. Nothing was wrong until a shell added ~/go/bin.

Directories

Path Synopsis
Package staleness answers, read-only, two questions about the Go tools installed on a machine: is this binary an older release of itself, and is anything still running a file that has since been replaced.
Package staleness answers, read-only, two questions about the Go tools installed on a machine: is this binary an older release of itself, and is anything still running a file that has since been replaced.
proc
Package proc finds processes that still run a binary which has since been replaced on disk.
Package proc finds processes that still run a binary which has since been replaced on disk.
Package sumverify answers one question about an installed Go binary: was every module compiled into it checked against sum.golang.org?
Package sumverify answers one question about an installed Go binary: was every module compiled into it checked against sum.golang.org?

Jump to

Keyboard shortcuts

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