Documentation
¶
Index ¶
- Constants
- Variables
- func BuildBaseEnv(extraEnv map[string]string) []string
- func BuildRunEnv(baseEnv []string, extraEnv []string, modelEnv map[string]string) []string
- func LerosMCPTokenEnvVar() string
- func PreferredCLIName(available []CLIToolStatus) string
- func ResolveRunWorkDir(workDir string) (string, error)
- func RunCLICommand(ctx context.Context, cliPath string, args []string, extraEnv []string) error
- func ScanJSONLines(r io.Reader, visit func(line string) bool)
- func SkillDirForCLI(name string) string
- type ApprovalHandler
- type ApprovalResponder
- type CLIToolSpec
- type CLIToolStatus
- type CmdProcess
- type InteractionRouter
- func (r *InteractionRouter) GetApprovalResponder(requestID string) ApprovalResponder
- func (r *InteractionRouter) GetQuestionResponder(requestID string) QuestionResponder
- func (r *InteractionRouter) RequestAnswer(ctx context.Context, req *agent.QuestionRequest) (*agent.QuestionAnswer, error)
- func (r *InteractionRouter) RequestApproval(ctx context.Context, req *agent.ApprovalRequest) (*agent.ApprovalDecision, error)
- func (r *InteractionRouter) ResolveApproval(requestID, action, reason string) error
- func (r *InteractionRouter) ResolveQuestion(requestID string, answers [][]string) error
- func (r *InteractionRouter) SetApprovalResponder(requestID string, responder ApprovalResponder)
- func (r *InteractionRouter) SetQuestionResponder(requestID string, responder QuestionResponder)
- type MCPServerConfig
- type PendingApproval
- type PendingQuestion
- type PermissionMode
- type Process
- type QuestionHandler
- type QuestionResponder
Constants ¶
const ( ApprovalActionApprove = "approve" ApprovalActionDeny = "deny" ApprovalActionAlways = "always" )
Variables ¶
var BuiltinCLITools = []CLIToolSpec{ { Name: "claude", DisplayName: "Claude Code", Binary: "claude", InstallCmd: "npm install -g @anthropic-ai/claude-code", DetectCmd: "claude --version", VersionRegex: `Claude CLI[,:]? v?(\d+\.\d+\.\d+)`, Default: true, }, { Name: "codex", DisplayName: "Codex CLI", Binary: "codex", InstallCmd: "npm install -g @openai/codex", DetectCmd: "codex --version", VersionRegex: `(\d+\.\d+\.\d+)`, Default: false, }, { Name: "opencode", DisplayName: "OpenCode", Binary: "opencode", InstallCmd: "npm install -g opencode-ai", DetectCmd: "opencode --version", VersionRegex: `(\d+\.\d+\.\d+)`, Default: false, }, }
BuiltinCLITools lists the external AI coding CLIs Leros can detect.
Functions ¶
func BuildBaseEnv ¶
BuildBaseEnv 返回当前环境并附加额外的环境变量。
func BuildRunEnv ¶
BuildRunEnv 为 CLI 进程组装环境变量条目。
func LerosMCPTokenEnvVar ¶
func LerosMCPTokenEnvVar() string
LerosMCPTokenEnvVar returns the env var name used for CLI MCP bearer token registration.
func PreferredCLIName ¶
func PreferredCLIName(available []CLIToolStatus) string
PreferredCLIName chooses the preferred installed runtime from detected CLI status.
func ResolveRunWorkDir ¶
ResolveRunWorkDir returns the configured run workdir or the workspace temp fallback.
func RunCLICommand ¶
RunCLICommand runs a CLI command with a bounded timeout.
func ScanJSONLines ¶
ScanJSONLines 扫描换行符分隔的 JSON 日志,支持更大的 token 缓冲区。
func SkillDirForCLI ¶
SkillDirForCLI returns the conventional skill directory for a supported CLI.
Types ¶
type ApprovalHandler ¶
type ApprovalHandler interface {
RequestApproval(ctx context.Context, req *agent.ApprovalRequest) (*agent.ApprovalDecision, error)
}
ApprovalHandler handles an approval request raised by a provider.
type ApprovalResponder ¶
ApprovalResponder writes an approval decision back to a provider process.
type CLIToolSpec ¶
type CLIToolSpec struct {
Name string
DisplayName string
Binary string
InstallCmd string
DetectCmd string
VersionRegex string
Default bool
}
CLIToolSpec describes a built-in external AI coding CLI.
func GetCLIToolSpec ¶
func GetCLIToolSpec(name string) *CLIToolSpec
GetCLIToolSpec returns the built-in CLI spec with the given runtime name.
type CLIToolStatus ¶
type CLIToolStatus struct {
Name string `json:"name"`
DisplayName string `json:"display_name"`
Binary string `json:"binary"`
Installed bool `json:"installed"`
Version string `json:"version,omitempty"`
Path string `json:"path,omitempty"`
InstallCmd string `json:"install_cmd"`
Default bool `json:"is_default"`
}
CLIToolStatus reports whether a built-in CLI is available in the current environment.
func DiscoverAvailableCLI ¶
func DiscoverAvailableCLI() []CLIToolStatus
DiscoverAvailableCLI detects all built-in CLI tools from the current PATH.
func GetCLIStatusSummary ¶
func GetCLIStatusSummary() []CLIToolStatus
GetCLIStatusSummary returns the current detection status for all built-in CLI runtimes.
type CmdProcess ¶
type CmdProcess struct {
// contains filtered or unexported fields
}
CmdProcess 实现 os/exec.Cmd 的 Process 接口。
func NewCmdProcess ¶
func NewCmdProcess(cmd *exec.Cmd, done <-chan struct{}) *CmdProcess
NewCmdProcess 将 cmd 和调用方拥有的 Wait 完成信号包装为 Process。 调用方必须保持 cmd.Wait() 的唯一所有权,并在 Wait 返回后关闭 done。
func (*CmdProcess) Stop ¶
func (p *CmdProcess) Stop() error
Stop 优雅地终止子进程,不调用 cmd.Wait 或 cmd.Process.Wait。
关闭流程:
- 发送 SIGTERM 请求子进程自行清理
- 等待 gracefulShutdownTimeout
- 超时则强制 SIGKILL
Stop 是幂等的,多次调用安全。
type InteractionRouter ¶
type InteractionRouter struct {
// contains filtered or unexported fields
}
InteractionRouter 统一管理审批(approval)和问题(question)类型的待处理交互请求。 通过 channel 桥接前端的 HTTP 回传和引擎的阻塞 goroutine。
func NewInteractionRouter ¶
func NewInteractionRouter() *InteractionRouter
NewInteractionRouter 创建交互路由器。
func (*InteractionRouter) GetApprovalResponder ¶
func (r *InteractionRouter) GetApprovalResponder(requestID string) ApprovalResponder
GetApprovalResponder 获取审批请求对应的 Responder。
func (*InteractionRouter) GetQuestionResponder ¶
func (r *InteractionRouter) GetQuestionResponder(requestID string) QuestionResponder
GetQuestionResponder 获取问题请求对应的 Responder。
func (*InteractionRouter) RequestAnswer ¶
func (r *InteractionRouter) RequestAnswer(ctx context.Context, req *agent.QuestionRequest) (*agent.QuestionAnswer, error)
RequestAnswer 注册 pending question 并阻塞等待前端 HTTP 回传答案。 实现 QuestionHandler 接口。
func (*InteractionRouter) RequestApproval ¶
func (r *InteractionRouter) RequestApproval(ctx context.Context, req *agent.ApprovalRequest) (*agent.ApprovalDecision, error)
RequestApproval 注册 pending approval 并阻塞等待前端 HTTP 回传决策。 实现 ApprovalHandler 接口。
func (*InteractionRouter) ResolveApproval ¶
func (r *InteractionRouter) ResolveApproval(requestID, action, reason string) error
ResolveApproval 由 HTTP handler / worker subscriber 调用,填入前端决策并唤醒阻塞的 goroutine。
func (*InteractionRouter) ResolveQuestion ¶
func (r *InteractionRouter) ResolveQuestion(requestID string, answers [][]string) error
ResolveQuestion 由 HTTP handler / worker subscriber 调用,填入用户答案并唤醒阻塞的 goroutine。
func (*InteractionRouter) SetApprovalResponder ¶
func (r *InteractionRouter) SetApprovalResponder(requestID string, responder ApprovalResponder)
SetApprovalResponder 设置审批请求对应的 Responder。
func (*InteractionRouter) SetQuestionResponder ¶
func (r *InteractionRouter) SetQuestionResponder(requestID string, responder QuestionResponder)
SetQuestionResponder 设置问题请求对应的 Responder。
type MCPServerConfig ¶
type MCPServerConfig struct {
Name string
URL string // HTTP 传输
BearerToken string // HTTP 传输:bearer token
Command string // Stdio 传输:可执行文件路径
Args []string // Stdio 传输:命令参数
Env map[string]string // Stdio 传输:进程额外环境变量
}
MCPServerConfig describes the Leros MCP endpoint registered with an external CLI client.
func NormalizeMCPServerConfig ¶
func NormalizeMCPServerConfig(cfg MCPServerConfig) MCPServerConfig
NormalizeMCPServerConfig fills defaults for an MCP server registration.
type PendingApproval ¶
type PendingApproval struct {
Request *agent.ApprovalRequest
Responder ApprovalResponder
ResultCh chan *agent.ApprovalDecision
CreatedAt time.Time
}
PendingApproval represents an approval request waiting for a user decision.
type PendingQuestion ¶
type PendingQuestion struct {
Request *agent.QuestionRequest
Responder QuestionResponder
ResultCh chan *agent.QuestionAnswer
CreatedAt time.Time
}
PendingQuestion 表示一个等待前端回答的问题请求。
type PermissionMode ¶
type PermissionMode string
PermissionMode controls whether a provider requests approval for tool calls.
const ( // PermissionModeBypass skips provider approval requests. PermissionModeBypass PermissionMode = "bypass" // PermissionModeOnRequest forwards provider approval requests to the user. PermissionModeOnRequest PermissionMode = "on-request" // PermissionModeAuto automatically approves safe operations. PermissionModeAuto PermissionMode = "auto" )
type QuestionHandler ¶
type QuestionHandler interface {
RequestAnswer(ctx context.Context, req *agent.QuestionRequest) (*agent.QuestionAnswer, error)
}
QuestionHandler handles a question raised by a provider.
type QuestionResponder ¶
QuestionResponder writes answers back to a provider process.