toolchain

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package toolchain 探测本机装了哪些 executor、各自处于什么状态。

职责:

  • 对 opencode / claude / grok / codex 四家,各查「可执行文件在不在 PATH」 与「凭证文件在不在」,归一成一个三态(claude 两态)

边界:

  • **只探测,不决策**:不排序偏好、不写配置、不阻止任何选择。那是 cmd/init.go 的事
  • **绝不发起真实模型调用**。README 里「claude -p "hi" 能出结果即视为就绪」是给人 看的验证方法,不是这里能用的判据——那是一次真实付费调用,几秒到几十秒且要联网
  • 不打日志:本包是一组纯取值函数,无 I/O 副作用(只读文件是否存在), 在这里打日志只会给 init 的输出制造噪音;探测结果由调用方成表打印

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstReady

func FirstReady(rs []Result) string

FirstReady 返回第一个就绪的 executor 名;一个都没有时返回空串。

供 init 挑 executor.default 的默认值用。**不把 StateAuthUnknown 算进来**, 理由同 Result.Ready。

Types

type Result

type Result struct {
	// Name 是 executor 名,与 dispatch --executor 用的名字一致。
	Name string
	// Path 是可执行文件路径;StateMissing 时为空。
	Path string
	// State 是探测出的状态。
	State State
}

Result 是一家 executor 的探测结果。

func Detect

func Detect() []Result

Detect 探测四家 executor 的状态。

返回:

  • 固定四项,顺序恒为 opencode / claude / grok / codex

注意:

  • 取不到 HOME 时,装了的执行者一律报 StateAuthUnknown。它既不是 StateMissing (「凭证查不到」和「没装」是两件事,混为一谈会让用户去重装一个已经装好的 东西),也不是 StateNoCreds(那是一个「没登录」的断言,而此时凭证文件 根本没查过,下这个断言是在猜)

func (Result) Ready

func (r Result) Ready() bool

Ready 表示「可以放心把它设成缺省执行者」。

注意:StateAuthUnknown 返回 **false**。它的语义是「不知道」, 把不知道当成就绪,就是替用户做了一个没有依据的判断。

type State

type State int

State 是一家 executor 的可用状态。

const (
	// StateMissing:可执行文件不在 PATH 里。
	StateMissing State = iota
	// StateNoCreds:装了,但找不到凭证文件。
	StateNoCreds
	// StateReady:装了且凭证文件在。
	StateReady
	// StateAuthUnknown:装了,但本机没有可靠的轻量凭证判据——只有 claude 会是这个状态。
	//
	// 为什么单独一态而不是并进 StateNoCreds:两者要让用户做的事完全相反。
	// NoCreds 是「去登录」,AuthUnknown 是「大概率能用,自己心里有数」。
	// 合并等于把「不知道」说成「没登录」,那是编造。
	StateAuthUnknown
)

func (State) String

func (s State) String() string

String 返回给人看的中文短语(init 的表格直接打印它)。

Jump to

Keyboard shortcuts

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