tool_resolve

package
v0.0.269 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 12 Imported by: 1 module, 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 toolresolve provides centralized binary resolution that respects both the system PATH, the well-known extra install paths (e.g. ~/.local/bin, ~/.opencode/bin), and user-configured extra paths from the terminal config.

This package never modifies the process's PATH environment variable. Instead, LookPath dynamically searches the system PATH plus all extra paths. Callers spawning subprocesses should use AppendExtraPaths to build the env for the child process.

Index

Constants

This section is empty.

Variables

View Source
var ExtraPaths = []string{
	"/usr/local/bin",
	"/usr/local/go/bin",
}

ExtraPaths are common install directories that may not be in the server process's PATH but where tools are commonly installed.

Functions

func AllExtraPaths

func AllExtraPaths() []string

func AppendExtraPaths

func AppendExtraPaths(env []string) []string

func CompareVersions

func CompareVersions(v1, v2 string) bool

func ExtractMajorVersion

func ExtractMajorVersion(version string) int

func FormatNewest added in v0.0.269

func FormatNewest(name string, tool NewestTool) string

FormatNewest renders one resolution for a log line. It is the sentence the Code tab shows, so it names the winner with its version and the paths that lost.

func GetFullSearchPATH

func GetFullSearchPATH() string

func IsAvailable

func IsAvailable(name string) bool

func LookPath

func LookPath(name string) (string, error)

func SetUserExtraPaths

func SetUserExtraPaths(paths []string)

Types

type NewestCall added in v0.0.269

type NewestCall struct {
	Path    string
	Version string
	Skipped bool
}

NewestCall is one candidate a resolution considered. It exists so a caller can say which install lost and why, instead of naming only the winner.

func Describe added in v0.0.269

func Describe(name string) []NewestCall

Describe lists every executable the search path offers for name, in search order, with the version each reports. LookPathNewest's winner is the first entry whose Version is the newest; callers log this once per operation so a later "it broke" report can name the binary that ran.

type NewestTool added in v0.0.269

type NewestTool struct {
	// Path is the executable that won. It is absolute when it came from a
	// search directory.
	Path string
	// Version is the version the executable reported. Empty when no candidate
	// answered: the winner is then the first executable, exactly LookPath.
	Version string
}

NewestTool is the highest version of a tool found on the search path.

func LookPathNewest added in v0.0.269

func LookPathNewest(name string) (NewestTool, error)

LookPathNewest resolves a tool the way LookPath does, then keeps the newest installed version instead of the first one on PATH.

Two OpenCode versions coexist on a machine: the npm one earlier on PATH and a newer one in ~/.opencode/bin. They share a data directory but not a session schema, so "the first opencode" is how a working install silently became a broken one. Callers that only need *a* binary keep LookPath; callers that must pick one consistently use this and pass the result to every command of the same operation.

Versions are compared numerically (1.9.0 < 1.18.18), a release sorts above its own prerelease, and a candidate that prints nothing parsable is skipped. When no candidate reports a version the first executable wins and Version is empty: the fallback is LookPath, never "no tool".

Successful resolutions are cached per process: PATH and installed versions do not change under a running server, and a commit-message generation probes the same tool more than once.

Jump to

Keyboard shortcuts

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