doctor

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 5 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 doctor 实现 kite doctor 命令:逐项环境自检。

检查项:版本(build info)/会话与网络(一次轻量 rpc)/补全安装指引。 渲染层输出(✓/✗/! 清单 + 每项修复指引),任一 fail → exit 1;warn 不影响。 --json 白拿,bug report 可粘贴(PRD-0014 #J)。

设计:doctor 是协调器,检查逻辑由可注入的 Checker 列表提供(表驱动), 生产装配真实检查器(注入 endpoint/cookie),测试用 fake。这让 doctor 易测且与具体 endpoint 解耦。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasFail

func HasFail(results []Result) bool

HasFail 判断结果列表是否有 fail 项(决定退出码)。

func RenderHuman

func RenderHuman(w io.Writer, results []Result)

RenderHuman 渲染人类可读的逐项清单(✓/✗/! + 详情 + 修复指引)。 用于 TTY 默认输出。

func ShellName

func ShellName(shellPath string) string

ShellName 从 $SHELL 路径提取 shell 名(zsh/bash/fish/powershell),未知返回空。

跨平台处理路径分隔符:Unix 用 /、Windows 用 \。$SHELL 在 Windows 上可能是 反斜杠路径(如 C:\...\pwsh.exe)。filepath.Base 是平台相关的(Unix build 不认 \), 故用 strings.LastIndexAny 同时认 / 和 \,取末段,修复评审指出的 Windows 问题。 Windows 可执行文件常带 .exe 后缀,去除后再匹配。

导出供 cli 包(install-completion)复用,避免重复实现(评审指出的代码臭味)。

Types

type Checker

type Checker interface {
	Check() Result
}

Checker 是一个检查项的接口。Check 执行检查返回 Result。 生产实现注入具体依赖(endpoint/cookie);测试用 fake。

func CompletionChecker

func CompletionChecker(shell string, installedProbe func(shell string) (path string, ok bool)) Checker

CompletionChecker 检查当前 shell 的补全脚本是否已安装。

检测常见安装位置是否存在补全脚本(zsh: ~/.zsh/completions/_kite; bash: ~/.local/share/bash-completion/completions/kite;fish: ~/.config/fish/...)。 这覆盖大多数安装方式;fpath 是否真 source 无法跨进程可靠检测,故文件存在视为已装。

已装 → pass(显示路径);未装 → warn(给一键安装命令,引导用户装上)。 warn 非 fail:没装补全 kite 仍可用,只是 Tab 不列命令。

shell 从 $SHELL 推断;installedProbe 注入使测试用 fake(不碰真实文件系统)。

func ConfigChecker added in v0.2.0

func ConfigChecker(probe func() (path string, exists bool, loadErr error)) Checker

ConfigChecker 检查 config.toml 状态(PRD-0017)。

probe 返回(路径, 是否存在, 加载错误)。加载错误 = 文件存在但解析失败/key 越界 (LoadConfig 的硬错误语义)。三种态:

  • 加载错误 → fail(与命令侧硬错误一致:静默回退会掩盖用户设置)
  • 不存在 → pass(全新用户正常态,全部内置默认)
  • 存在且可解析 → pass(显示路径)

probe 注入使测试用 fake(不碰真实配置目录)。

func ProxyChecker added in v0.2.0

func ProxyChecker(probe func() (flagVal, cfgVal, envVal string)) Checker

ProxyChecker 显示代理解析链(PRD-0018)。恒 pass 信息行——不做连通性探活: 「会话」检查已实际走一遍完整链路,独立探活受境内外网络差异影响易误报。

probe 返回(flag 值, config 值, 环境变量值),空串 = 该层未设置。 展示优先级与生效优先级一致:--proxy > config > 环境变量 > 直连。

func SessionChecker

func SessionChecker(cookieProbe func() string, netProbe func(ctx context.Context, cookie string) error) Checker

SessionChecker 检查会话与网络(一次轻量 rpc 合一)。

cookieProbe 返回当前 cookie(空=未登录);netProbe 用该 cookie 发一次最轻量 rpc (生产:login-status endpoint)验证 cookie 仍有效。两者合并避免重复请求:

  • 无 cookie → fail「未登录」
  • 有 cookie 但 netProbe 失败 → fail「cookie 失效或网络问题」
  • 成功 → pass

注入两个 probe 使测试用 fake(不碰真实网络/cookie)。

func VersionChecker

func VersionChecker() Checker

VersionChecker 检查版本(build info)。直接调 version.LoadVersion,无依赖。

type CheckerFunc

type CheckerFunc func() Result

CheckerFunc 让普通函数实现 Checker。

func (CheckerFunc) Check

func (f CheckerFunc) Check() Result

type JSONReport added in v0.4.0

type JSONReport struct {
	Results []Result `json:"results"`
	OK      bool     `json:"ok"` // 无 fail 为 true
}

JSONReport 是 doctor 的结构化 JSON 报告(供 --json / bug report 粘贴)。

func ReportJSON

func ReportJSON(results []Result) JSONReport

ReportJSON 构造 JSON 报告(含 results + ok 汇总)。

type Result

type Result struct {
	Name    string `json:"name"`               // 检查项名(如「版本」「会话」)
	Status  Status `json:"status"`             // pass/fail/warn
	Detail  string `json:"detail"`             // 状态详情(如版本号、「未登录」)
	FixHint string `json:"fix_hint,omitempty"` // 非 pass 时的修复指引
}

Result 是单个检查项的结果。

func Run

func Run(checkers []Checker) []Result

Run 执行所有检查项,返回结果列表与是否有 fail。 顺序:按 checkers 传入顺序(渲染时保持)。

type Status

type Status string

Status 是检查项的结果状态。

const (
	StatusPass Status = "pass" // ✓ 通过
	StatusFail Status = "fail" // ✗ 失败(影响退出码 → exit 1)
	StatusWarn Status = "warn" // ! 警告(不影响退出码,合法场景如补全未装)
)

Jump to

Keyboard shortcuts

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