cli

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 81 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 cli 定义 openvaala 命令行:加载配置,运行 TUI、serve、web、acp、app-server、codex、reindex、plugin 和 config 命令。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddURLFlag added in v0.7.0

func AddURLFlag(flags *pflag.FlagSet)

AddURLFlag 注册客户端连接 serve 的 --url 参数。

func BuildCLIHandler

func BuildCLIHandler(handler func(context.Context, *AppArgs) error) func(*cobra.Command, []string) error

BuildCLIHandler 包装 handler 成 RunE:先加载配置、收集命令参数,再调用 handler。

func GetConfigFlags

func GetConfigFlags(flags *pflag.FlagSet) ([]string, error)

GetConfigFlags 收集显式传入的全局配置参数,写成 --name=value。

func GetWebUIURL

func GetWebUIURL(runtimeURL, token string) (string, error)

GetWebUIURL 将服务连接地址转成 WebUI 地址,并把登录令牌放在 fragment 中。

func LoadConfig added in v0.3.0

func LoadConfig(command *cobra.Command) (*config.Config, *config.LoadConfigOpt, error)

LoadConfig 按命令的 --config-file 等参数加载配置,返回配置和加载用的选项。

func NewCLI

func NewCLI(opt *CLIOpt) *cobra.Command

NewCLI 创建命令树,注册参数和子命令。

Types

type AppArgs

type AppArgs struct {
	RuntimeToken   string
	ConversationID defs.ConversationID
	Config         *config.Config
	Stdin          io.Reader
	Stdout         io.Writer
	// RuntimeURL 是 --url 指定的 Runtime Server 地址;为空时 getRuntimeConnection 依次用 client.url、本机 serve(没有就自动拉起)。
	RuntimeURL string
	// Stderr 接收 serve、acp 和 app-server 的文本日志,以及客户端的旧 serve 提示;codex 子进程使用它,正常退出后追加重连提示。TUI 不使用。
	Stderr io.Writer
	// IdleTimeout 是 serve 的隐藏参数 --idle-timeout:大于 0 时没有连接且没有 Turn 在执行这么久后 serve 自己退出;为 0 时常驻。
	IdleTimeout time.Duration
	// ConfigFlags 保存显式传入的配置文件、Agent 目录、模型目录和 Agent 名称,格式为 --name=value;仅配置文件转为绝对路径。自动启动 serve 时原样传入,不含 Codex 的 -c/--config。
	ConfigFlags []string
	// Executable 是当前进程的可执行文件路径,客户端用它自动拉起 serve;取不到时为空,拉起 serve 会失败。
	Executable string
	// ConfigPath 是读取的配置文件的绝对路径(--config-file、OPENVAALA_CONFIG 或默认位置);app-server 把它所在目录交给 Codex 客户端。
	ConfigPath string
	// ConfigOpt 是加载 Config 用的选项;serve 把它交给 config.ConfigFiles,重新加载时用同一个配置路径和 flag。
	ConfigOpt *config.LoadConfigOpt
	// AppServerListen 是 app-server 的 --listen,默认 stdio://。
	AppServerListen string
	// IsAppServerStdio 是否传入了 --stdio?
	IsAppServerStdio bool
	// PrintAppServerStartupConfig 是否只输出 Codex 桌面启动检查需要的 JSON,然后退出?
	PrintAppServerStartupConfig bool
	// UnsupportedWebSocketFlags 是 app-server 收到的 codex WebSocket 认证参数名(--ws-auth 等):OpenVaala 不支持,出现就报错。
	UnsupportedWebSocketFlags []string
	// IgnoredCodexFlags 是用户传入的 codex 参数名(-c/--config、--enable、--disable、--strict-config,
	// 以及 app-server 的分析、code-mode、remote-control 和启动客户端、退出登录参数);普通 app-server 启动时写一条 Debug 日志。
	IgnoredCodexFlags []string
	// CodexRootArguments 是用户传入的 codex 根命令参数,按 codex 的写法排好(-c k=v、--enable x、--disable y、--strict-config);
	// openvaala codex 把它们交给 codex,app-server 等命令收下不用。
	CodexRootArguments []string
	// CodexArguments 是 openvaala codex 之后的参数(codex 自己的参数写在 -- 之后),接在 CodexRootArguments 之后交给 codex;
	// codex app 时是可选的一个工作目录。其他命令不收位置参数,为空。
	CodexArguments []string
}

AppArgs 保存已加载的配置、命令参数、标准流和版本。

type CLIFlags

type CLIFlags struct {
	ConfigFilePath  string
	DataDirectory   string
	AgentsDirectory string
	ModelsDirectory string
	AgentName       string
}

CLIFlags 保存 Cobra 直接解析的参数;是否显式传入由 Cobra 的 Changed 状态判断。

type CLIOpt

type CLIOpt struct {
	Stdout io.Writer
	Stderr io.Writer
}

CLIOpt 是命令树使用的标准输出和标准错误。

type DesktopStartTarget added in v0.7.0

type DesktopStartTarget struct {
	URL   string
	Token string
	// IsOverride 为真表示来自命令行 --url 的一次性覆盖,不写入桌面偏好。
	IsOverride bool
}

DesktopStartTarget 是桌面端启动时解析出的远端目标;URL 为空时按桌面默认逻辑处理。

func ResolveDesktopStartTarget added in v0.7.0

func ResolveDesktopStartTarget(command *cobra.Command) (DesktopStartTarget, *config.Config)

ResolveDesktopStartTarget 按 --url > client.url 的优先级解析桌面端启动目标,不拉起本机 serve。 配置加载失败时记录警告:显式传入 --url 仍按该地址连接,未传 --url 时返回空目标。

type RuntimeServerConnection

type RuntimeServerConnection struct {
	ResetFor string `yaml:"reset_for,omitempty"`
	URL      string `yaml:"url"`
	// Listen 是本机 serve 实际绑定的地址,保留通配监听的 host。
	Listen string `yaml:"listen,omitempty"`
	Token  string `yaml:"token"`
	// Executable 是 serve 的可执行文件路径(软链接已解析),取不到时为空;客户端拿它和自己的可执行文件比较,发现升级或重新编译前的旧 serve。
	Executable string `yaml:"executable"`
	// ExecutableModifiedAt 是 serve 启动时 Executable 的修改时间,取不到时为零值。
	ExecutableModifiedAt time.Time `yaml:"executable_modified_at"`
	// ServerID 标识这台机器上的 serve,重启后沿用;客户端读到的和 initialize 返回的一致时,两边用的是同一个文件系统。
	ServerID string `yaml:"server_id"`
}

RuntimeServerConnection 是 serve 启动后写入 ~/.local/state/openvaala/runtime-server.yaml 的连接信息,本机客户端读它来连接。

func EnsureRuntimeServer

func EnsureRuntimeServer(ctx context.Context, opt *RuntimeServerStartOpt) (connection RuntimeServerConnection, err error)

EnsureRuntimeServer 复用能访问的本机 serve,没有时在后台拉起并等待就绪;空闲时长为 0 时新进程常驻。

type RuntimeServerStartOpt

type RuntimeServerStartOpt struct {
	Config      *config.Config
	Executable  string
	ConfigFlags []string
	IdleTimeout time.Duration
	LogFile     string
}

RuntimeServerStartOpt 保存自动启动本机 serve 使用的程序、参数、空闲时长和日志位置。

Jump to

Keyboard shortcuts

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