Documentation
¶
Overview ¶
Package environment 在 Waveloom 启动时探测宿主编译/运行时工具链可用性, 将结果注入 System Prompt,让 LLM 在尝试调用工具前就了解系统环境, 避免因命令缺失导致的反复试错探测循环。
Package environment — Waveloom 启动时探测宿主编译/运行时工具链可用性。
本文件实现自更新流程:下载 GitHub Release tar.gz → 解压 → 替换当前二进制。 TUI 通过 Progress 回调获取进度并渲染到 tool 段落。
Package environment — Waveloom 启动时探测宿主编译/运行时工具链可用性。
本文件实现 GitHub Release 版本更新检查: 通过 GitHub API 获取最新 release tag,与当前编译版本比较, 有新版时在 TUI header 中显示更新提示。
Index ¶
- Constants
- func BuildDownloadURL() string
- func CheckForUpdateAsync(currentVersion string) <-chan *UpdateInfo
- func DefaultProbes() []string
- func FormatEnvironmentSection(results []ProbeResult, osName, shellPath string, ...) string
- func LoadToolOverrides(settingsPath string) map[string]string
- func SelfUpdate(ctx context.Context, currentPath, downloadURL string, ...) error
- type ProbeResult
- type SelfUpdatePhase
- type SelfUpdateProgress
- type UpdateCache
- type UpdateInfo
Constants ¶
const ProbeTimeout = 4 * time.Second
ProbeTimeout 是单个探针命令的最大等待时间。 4s 容纳 node 系 LSP server 的启动延迟(pyright-langserver 的 CLI wrapper 启动 ~2s;typescript-language-server 同源)。
Variables ¶
This section is empty.
Functions ¶
func BuildDownloadURL ¶
func BuildDownloadURL() string
BuildDownloadURL 返回当前平台对应的 GitHub Release 下载地址。 Windows 使用 .zip,其他平台使用 .tar.gz。
func CheckForUpdateAsync ¶
func CheckForUpdateAsync(currentVersion string) <-chan *UpdateInfo
CheckForUpdateAsync 在后台 goroutine 执行更新检查,结果通过 channel 返回。 2s 超时保护,失败时静默跳过。
func DefaultProbes ¶
func DefaultProbes() []string
DefaultProbes 返回跨平台的默认探针命令列表。 所有命令均设计为"输出版本号后立即退出",超时短(2s), 确保启动延迟控制在可接受范围内。
func FormatEnvironmentSection ¶
func FormatEnvironmentSection(results []ProbeResult, osName, shellPath string, toolOverrides map[string]string) string
FormatEnvironmentSection 将探测结果格式化为 System Prompt 的 ## Environment 节。
toolOverrides 来自 settings.json 的 environment.tools 配置,key=命令名 value=完整路径。 已配置路径的工具将在 "Configured tools" 下展示,即使探针未在 PATH 中检测到。
func LoadToolOverrides ¶
LoadToolOverrides 从 settings.json 文件加载用户配置的工具路径覆盖。 返回 map[命令名]完整路径。文件不存在或缺少 environment.tools 时返回空 map。
func SelfUpdate ¶
func SelfUpdate(ctx context.Context, currentPath, downloadURL string, progress SelfUpdateProgress) error
SelfUpdate 下载 release tar.gz 到临时目录,解压并替换 currentPath 指向的二进制文件。 成功时新二进制已替换 currentPath;失败时尝试回滚(从 .old 备份恢复)。 progress 可为 nil,此时不报告进度。
Types ¶
type ProbeResult ¶
type ProbeResult struct {
Command string // 原始命令字符串,如 "go version"
Binary string // 命令的第一个词(仅用于展示),如 "go"
Output string // 成功时:stdout 首行(已 trim)
Found bool // 命令是否存在于 PATH 且能在超时内执行成功
Error string // 失败原因(command_not_found / timeout / non-zero exit)
}
ProbeResult 表示单个探针命令的执行结果。
func RunProbes ¶
func RunProbes(ctx context.Context, commands []string) []ProbeResult
RunProbes 并行执行给定的探针命令列表,返回按 binary 名排序的结果切片。 每个命令超时 ProbeTimeout 秒,失败结果也返回(Found=false)。
为避免阻塞主线程过久,所有命令并行执行,最坏情况延迟 = ProbeTimeout。
func RunProbesWithCache ¶
func RunProbesWithCache(ctx context.Context, commands []string) []ProbeResult
RunProbesWithCache 是 RunProbes 的带缓存版本。 首次使用或缓存过期/PATH 变化时执行完整探测并写入缓存; 缓存有效时直接返回,跳过 2 秒的探测延迟。
type SelfUpdatePhase ¶
type SelfUpdatePhase string
SelfUpdatePhase 表示自更新流程的阶段。
const ( PhaseDownload SelfUpdatePhase = "download" PhaseExtract SelfUpdatePhase = "extract" PhaseInstall SelfUpdatePhase = "install" PhaseDone SelfUpdatePhase = "done" )
type SelfUpdateProgress ¶
type SelfUpdateProgress func(phase SelfUpdatePhase, pct int, detail string)
SelfUpdateProgress 是自更新进度回调。 phase 是当前阶段;pct 是 0-100 的百分比(仅 download 阶段有意义);detail 是人类可读的描述。
type UpdateCache ¶
type UpdateCache struct {
// contains filtered or unexported fields
}
UpdateCache 线程安全缓存单次更新检查结果。
type UpdateInfo ¶
type UpdateInfo struct {
CurrentVersion string // 当前编译版本号(如 "v0.1.0-alpha.6")
LatestVersion string // GitHub 最新 release tag(如 "v0.2.0")
UpdateAvailable bool // 是否有新版本可用
URL string // release 页面 URL
}
UpdateInfo 包含版本更新检查的结果。
func CheckForUpdate ¶
func CheckForUpdate(ctx context.Context, currentVersion string) (*UpdateInfo, error)
CheckForUpdate 获取 GitHub 最新 release tag 并与当前版本比较。 通过访问 releases/latest 重定向地址提取 tag,无需 API 认证,不受限流。 返回的 UpdateInfo 线程安全,可跨 goroutine 传递。 网络错误静默忽略,返回 (nil, nil) 表示跳过本次检查。