codex worker 把 OpenAI Codex API 暴露为 iii 函数。一次 codex::run 调用执行一轮无头 Codex——与用户在终端使用的同一 agent,同一登录、文件系统与沙箱——在指定工作目录中运行,返回最终结果和 token 用量。该 worker 是纯透传:具名 payload 字段覆盖常见路径,options 字段原样转发任意 Codex SDK ThreadOption,每个线程事件未经改动镜像到 codex::events 流;翻译后的 AgentEvent 视图落到 agent::events,由 iii 控制台渲染。
用途与场景:可一次调用委派整个编码任务(如“加一个端点并跑测试”),用 prompt 和 cwd 调 codex::run;重复传同一 session_id 可跨调用延续对话,保留完整上下文;用 codex::start 立即返回 {session_id, started} 跑长任务,通过 codex::events(group_id = session_id)看原始进度或 agent::events 看渲染视图,用 codex::stop 中断。轮次默认携带 iii 运行时上下文(作为 Codex developer_instructions 下发),agent 可通过 iii CLI 发现并调用已注册函数(engine::functions::list、iii trigger <fn> --help),可用 iii_context: false 按轮禁用。可先用 sandbox_mode: read-only 跑规划提示(写入会失败)读计划,再用同一 session_id 以 workspace-write 发送“implement the plan”。传 output_schema(JSON schema)可得结构化 JSON 最终消息;images: ["/path/a.png"] 可附本地截图;codex_config 可转发 config.toml 覆盖,如 {"codex_config": {"mcp_servers": {"github": {"command": "gh-mcp"}}}};options 可传 SDK ThreadOptions 的任意项,如 {"options": {"networkAccessEnabled": true, "webSearchMode": "live"}}。
函数:codex::run 运行一轮并等待,接受 prompt(或 messages 数组,最后一条 user 作为 prompt),以及 model、cwd、sandbox_mode、approval_policy、reasoning_effort、skip_git_repo_check、output_schema 和原始 options,返回 {session_id, codex_thread_id, result, stop_reason, usage};codex::start 同 payload,立即返回 {session_id, started},进度走流;codex::stop 中断会话的实时运行;codex::status 返回时点视图(live、status、turns、usage);codex::sessions::list 列出该 worker 跑过的所有会话。
限制:需主机安装 codex CLI 并已登录或 worker 环境有 OPENAI_API_KEY,裸容器无此不可用;执行安全由 Codex 自身沙箱(sandbox_mode)决定,非引擎决定,read-only 阻止写入,workspace-write 允许改 cwd,danger-full-access 关闭沙箱,无头轮次 approval_policy: never,被阻命令会失败而非询问;同一会话同一时间只允许一轮,再次 codex::run 前先查 codex::status(live: true),对同一会话并行运行会在底层线程恢复上竞争;agent::events 只带整消息帧,逐项进度细节(命令输出累积、todo 列表)只在 codex::events。需超出 Codex 的能力时,应向总线添加其他 iii worker,而非改造本 worker。