codex

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package codex 将 Codex CLI 适配到 Leros 外部 CLI 引擎接口。 使用 codex app-server --listen stdio:// 模式进行通信。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter 通过 Codex CLI app-server 模式执行提示。

func NewAdapter

func NewAdapter(binary string, extraEnv map[string]string) *Adapter

NewAdapter 创建 Codex CLI 引擎适配器(app-server 模式)。

func (*Adapter) GetSkillDir

func (a *Adapter) GetSkillDir() string

GetSkillDir returns the skill directory path for Codex CLI.

func (*Adapter) Prepare

Prepare 执行 Codex 工作区设置(当前为空实现)。

func (*Adapter) Run

Run 启动 Codex CLI 并返回进程句柄。

type AppServer

type AppServer struct {
	// contains filtered or unexported fields
}

AppServer 管理一个 codex app-server 进程。

func (*AppServer) Close

func (s *AppServer) Close() error

func (*AppServer) PID

func (s *AppServer) PID() int

func (*AppServer) PendingApproval

func (s *AppServer) PendingApproval() *ServerRequest

func (*AppServer) RespondApproval

func (s *AppServer) RespondApproval(ctx context.Context, reqID sonic.NoCopyRawMessage, decision string) error

func (*AppServer) ResumeThread

func (s *AppServer) ResumeThread(ctx context.Context, threadID string, modelCfg engines.ModelConfig, systemPrompt string) error

func (*AppServer) SetEventChannel

func (s *AppServer) SetEventChannel(ch chan<- events.Event)

func (*AppServer) SetPendingApproval

func (s *AppServer) SetPendingApproval(req *ServerRequest)

func (*AppServer) SetThreadID

func (s *AppServer) SetThreadID(threadID string)

SetThreadID 设置当前 thread ID(供 invoker 使用)。

func (*AppServer) SetTurnID

func (s *AppServer) SetTurnID(id string)

SetTurnID 设置当前 turn ID(供 invoker 使用)。

func (*AppServer) StartThread

func (s *AppServer) StartThread(ctx context.Context, modelCfg engines.ModelConfig, systemPrompt string) (string, error)

func (*AppServer) StartTurn

func (s *AppServer) StartTurn(ctx context.Context, threadID string, prompt string) (string, error)

func (*AppServer) Stop

func (s *AppServer) Stop() error

func (*AppServer) ThreadID

func (s *AppServer) ThreadID() string

func (*AppServer) TurnID

func (s *AppServer) TurnID() string

type AppServerInvoker

type AppServerInvoker struct {
	// contains filtered or unexported fields
}

func NewAppServerInvoker

func NewAppServerInvoker(binary string, extraEnv map[string]string) *AppServerInvoker

func (*AppServerInvoker) Run

type Client

type Client struct {

	// 回调:由上层设置
	OnNotification  func(method string, params sonic.NoCopyRawMessage)
	OnServerRequest func(req ServerRequest)
	// contains filtered or unexported fields
}

Client 是 JSON-RPC 2.0 客户端,基于独立的 reader/writer 进行行分隔的 JSON 通信。

func NewClient

func NewClient(reader io.Reader, writer io.Writer) *Client

NewClient 创建 JSON-RPC 客户端。 reader 对应 stdout(接收响应/通知),writer 对应 stdin(发送请求)。

func NewClientWithScanner

func NewClientWithScanner(scanner *bufio.Scanner, writer io.Writer) *Client

NewClientWithScanner 使用已有的 scanner 创建客户端。 用于 initialize 阶段已通过独立 scanner 读取首行响应后, 继续复用同一个 scanner(避免 bufio 内部缓冲区数据丢失)。

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params any, result any) error

Call 发送 JSON-RPC 请求并阻塞等待响应。

func (*Client) Close

func (c *Client) Close()

Close 关闭客户端,取消所有 pending 请求。

func (*Client) Notify

func (c *Client) Notify(method string, params any) error

Notify 发送 JSON-RPC 通知(无需等待响应)。

func (*Client) ReadLoop

func (c *Client) ReadLoop(ctx context.Context) error

ReadLoop 持续从 stdout 读取 JSON-RPC 消息并路由。 在独立的 goroutine 中调用。读到 EOF 或错误时返回。

func (*Client) Respond

func (c *Client) Respond(id sonic.NoCopyRawMessage, result any) error

Respond 响应来自 app-server 的请求(如审批决策)。

func (*Client) RespondError

func (c *Client) RespondError(id sonic.NoCopyRawMessage, code int, message string) error

RespondError 响应给 app-server 返回错误。

type ServerRequest

type ServerRequest struct {
	ID     sonic.NoCopyRawMessage
	Method string
	Params sonic.NoCopyRawMessage
}

ServerRequest 表示来自 Codex app-server 的请求(需要客户端响应)。

Jump to

Keyboard shortcuts

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