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 ¶
- Variables
- func AllExtraPaths() []string
- func AppendExtraPaths(env []string) []string
- func CompareVersions(v1, v2 string) bool
- func ExtractMajorVersion(version string) int
- func FormatNewest(name string, tool NewestTool) string
- func GetFullSearchPATH() string
- func IsAvailable(name string) bool
- func LookPath(name string) (string, error)
- func SetUserExtraPaths(paths []string)
- type NewestCall
- type NewestTool
Constants ¶
This section is empty.
Variables ¶
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 CompareVersions ¶
func ExtractMajorVersion ¶
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 SetUserExtraPaths ¶
func SetUserExtraPaths(paths []string)
Types ¶
type NewestCall ¶ added in v0.0.269
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.