Codex Autopilot
Multi-model AI coding orchestration via tmux + launchd on macOS.
Overview
Codex Autopilot runs a watchdog loop that orchestrates multiple AI coding sessions in tmux. It features intelligent task routing — frontend tasks (UI, components, H5) are routed to Gemini CLI (1M context window, superior design aesthetics), while backend tasks (API, database, deployment) go to Codex CLI. The watchdog detects idle sessions, auto-nudges them, handles permission prompts, dispatches tasks from a priority queue, and sends notifications via Discord/Telegram.
Multi-Model Architecture
| Role | Model | Strengths |
|---|
| Backend coding | Codex (GPT-5.4) | API, database, deployment, refactoring |
| Frontend development |
Gemini CLI | UI, components, pages, styles, 1M context |
| Orchestration | Claude / OpenClaw | Task routing, code review, project management |
Tasks are automatically classified by keywords and routed to the appropriate model. Frontend tasks fall back to Codex if Gemini is unavailable.
Installation
CODEBLOCK0
Dependencies
- - macOS with launchd (for scheduled execution)
- tmux — session multiplexer for Codex windows
- Codex CLI (
codex) — OpenAI's coding agent - python3 — for state cleanup and PRD verification scripts
- yq — YAML processor for config parsing
- jq — JSON processor for state management
- bash 4+ — for associative arrays in scripts
Install dependencies via Homebrew:
CODEBLOCK1
launchd Setup
Use install.sh to register the launchd plist:
CODEBLOCK2
This creates a LaunchAgent that runs the watchdog on a configurable interval.
Core Components
watchdog.sh
Main loop engine. On each tick:
- 1. Iterates through configured project tmux windows
- Captures current Codex output via INLINECODE2
- Determines if session is active, idle, or stuck
- Dispatches appropriate action (nudge, permission grant, task from queue)
- Enforces cooldowns, daily send limits, and loop detection
codex-status.sh
Captures and analyzes tmux pane content. Detects:
- - Codex activity state (working / idle / waiting for permission)
- Permission prompts requiring approval
- Context compaction signals
- Error states and crashes
tmux-send.sh
Sends keystrokes or text to a specific tmux window. Handles:
- - Typing text into Codex prompt
- Pressing Enter/keys for permission approval
- Verification polling to confirm send succeeded
autopilot-lib.sh
Shared function library used by all scripts:
- - Telegram notification helpers
- File locking primitives
- Timeout and retry logic
- Logging utilities
- State file read/write
autopilot-constants.sh
Defines status constants used across scripts (e.g.,
STATUS_ACTIVE,
STATUS_IDLE,
STATUS_PERMISSION).
task-queue.sh
Task queue manager. Supports:
- - Enqueuing tasks for specific projects
- Dequeueing next task based on priority
- Task status tracking (pending/running/done/failed)
discord-notify.sh
Sends formatted notifications to Discord channels via webhook. Supports project-channel routing defined in
config.yaml.
test-agent.sh
Built-in CI/CD that runs on every commit. Evaluates test suites, tracks coverage, and
auto-enqueues bugfix tasks when tests fail.
CODEBLOCK3
Triggers:
- -
on_commit_evaluate — every new commit - INLINECODE8 — after code review passes
- INLINECODE9 — scheduled full evaluation (default 02:30)
Coverage ratchet: global coverage must not regress; weekly +1% target, capped at 90%.
Other Scripts
| Script | Purpose |
|---|
| INLINECODE10 | Nudge logic for idle Codex sessions |
| INLINECODE11 |
Periodic health check across all projects |
|
permission-guard.sh | Auto-approve or flag permission prompts |
|
incremental-review.sh | Run code review on recent changes |
|
monitor-all.sh | Dashboard: show status of all monitored projects |
|
status-sync.sh | Sync state to status.json for external consumption |
|
rotate-logs.sh | Log rotation and cleanup |
|
cleanup-state.py | Remove stale entries from state.json |
|
claude-fallback.sh | Fallback handler when Codex is unavailable |
|
prd-audit.sh | Audit PRD completion status |
|
prd-verify.sh /
prd_verify_engine.py | Verify PRD items against codebase |
|
codex-token-daily.py | Track daily token usage |
|
coverage-collect.sh | Collect and merge coverage reports |
Configuration
Edit config.yaml (copy from config.yaml.example). Key sections:
Timing Thresholds
CODEBLOCK4
Safety Limits
CODEBLOCK5
Multi-Project Scheduler
CODEBLOCK6
Project Directories
CODEBLOCK7
Gemini Frontend Routing
CODEBLOCK8
Frontend task detection keywords: 页面, 组件, 样式, UI, 前端, H5, 小程序, 界面, frontend, component, style, page, INLINECODE38
Discord Channel Routing
CODEBLOCK9
Telegram Notifications
CODEBLOCK10
Usage
Adding a Project
- 1. Start a Codex CLI session in a named tmux window:
CODEBLOCK11
- 2. Add the project path to
config.yaml under INLINECODE40
- 3. Optionally create
projects/my-project/tasks.yaml for task queue:
CODEBLOCK12
Manual Operations
CODEBLOCK13
Python Autopilot (Alternative)
INLINECODE42 provides a Python-based alternative with richer state management:
CODEBLOCK14
Directory Structure
CODEBLOCK15
Codex Autopilot
通过 tmux + launchd 在 macOS 上实现多模型 AI 编码编排。
概述
Codex Autopilot 运行一个看门狗循环,在 tmux 中编排多个 AI 编码会话。它具备智能任务路由功能——前端任务(UI、组件、H5)被路由到 Gemini CLI(100万上下文窗口,卓越的设计美学),而后端任务(API、数据库、部署)则交给 Codex CLI。看门狗检测空闲会话,自动提示,处理权限提示,从优先级队列分发任务,并通过 Discord/Telegram 发送通知。
多模型架构
| 角色 | 模型 | 优势 |
|---|
| 后端编码 | Codex (GPT-5.4) | API、数据库、部署、重构 |
| 前端开发 |
Gemini CLI | UI、组件、页面、样式、100万上下文 |
| 编排 | Claude / OpenClaw | 任务路由、代码审查、项目管理 |
任务根据关键词自动分类并路由到相应模型。如果 Gemini 不可用,前端任务将回退到 Codex。
安装
bash
git clone https://github.com/imwyvern/AIWorkFlowSkill.git ~/.autopilot
cd ~/.autopilot
cp config.yaml.example config.yaml
使用你的项目路径、Telegram 机器人令牌和 Discord 频道编辑 config.yaml
依赖项
- - macOS 带 launchd(用于定时执行)
- tmux — Codex 窗口的会话复用器
- Codex CLI (codex) — OpenAI 的编码代理
- python3 — 用于状态清理和 PRD 验证脚本
- yq — 用于配置解析的 YAML 处理器
- jq — 用于状态管理的 JSON 处理器
- bash 4+ — 用于脚本中的关联数组
通过 Homebrew 安装依赖项:
bash
brew install tmux yq jq
launchd 设置
使用 install.sh 注册 launchd plist:
bash
./install.sh
这将创建一个 LaunchAgent,以可配置的间隔运行看门狗。
核心组件
watchdog.sh
主循环引擎。每次执行:
- 1. 遍历配置的项目 tmux 窗口
- 通过 codex-status.sh 捕获当前 Codex 输出
- 判断会话是活跃、空闲还是卡住
- 分发相应操作(提示、权限授予、队列中的任务)
- 执行冷却、每日发送限制和循环检测
codex-status.sh
捕获并分析 tmux 窗格内容。检测:
- - Codex 活动状态(工作中 / 空闲 / 等待权限)
- 需要批准的权限提示
- 上下文压缩信号
- 错误状态和崩溃
tmux-send.sh
向特定 tmux 窗口发送按键或文本。处理:
- - 在 Codex 提示符中输入文本
- 按 Enter/键以批准权限
- 验证轮询以确认发送成功
autopilot-lib.sh
所有脚本使用的共享函数库:
- - Telegram 通知辅助函数
- 文件锁定原语
- 超时和重试逻辑
- 日志工具
- 状态文件读写
autopilot-constants.sh
定义跨脚本使用的状态常量(例如 STATUS
ACTIVE、STATUSIDLE、STATUS_PERMISSION)。
task-queue.sh
任务队列管理器。支持:
- - 为特定项目入队任务
- 基于优先级出队下一个任务
- 任务状态跟踪(待处理/运行中/已完成/失败)
discord-notify.sh
通过 webhook 向 Discord 频道发送格式化通知。支持 config.yaml 中定义的项目-频道路由。
test-agent.sh
内置 CI/CD,每次提交时运行。评估测试套件,跟踪覆盖率,并在测试失败时
自动入队错误修复任务。
提交 → 看门狗检测 → test-agent 评估
├─ 全部通过 → 审查通过 → 为低覆盖率文件入队覆盖率任务
└─ 失败 → 解析日志 → 自动入队 fix(test): ... 错误修复任务
└─ 每个文件 1 小时冷却(防止重试循环)
触发器:
- - oncommitevaluate — 每次新提交
- onreviewclean — 代码审查通过后
- nightly — 定时全面评估(默认 02:30)
覆盖率棘轮: 全局覆盖率不得下降;每周 +1% 目标,上限 90%。
其他脚本
| 脚本 | 用途 |
|---|
| auto-nudge.sh | 空闲 Codex 会话的提示逻辑 |
| auto-check.sh |
所有项目的定期健康检查 |
| permission-guard.sh | 自动批准或标记权限提示 |
| incremental-review.sh | 对最近更改运行代码审查 |
| monitor-all.sh | 仪表盘:显示所有监控项目的状态 |
| status-sync.sh | 将状态同步到 status.json 供外部使用 |
| rotate-logs.sh | 日志轮转和清理 |
| cleanup-state.py | 从 state.json 中移除过期条目 |
| claude-fallback.sh | Codex 不可用时的回退处理程序 |
| prd-audit.sh | 审计 PRD 完成状态 |
| prd-verify.sh / prd
verifyengine.py | 对照代码库验证 PRD 项 |
| codex-token-daily.py | 跟踪每日令牌使用量 |
| coverage-collect.sh | 收集和合并覆盖率报告 |
配置
编辑 config.yaml(从 config.yaml.example 复制)。关键部分:
时间阈值
yaml
active_threshold: 120 # 秒 — Codex 被视为工作中
idle_threshold: 360 # 秒 — Codex 被视为空闲,触发提示
cooldown: 120 # 同一项目发送之间的最小秒数
安全限制
yaml
max
dailysends_total: 200 # 全局每日发送上限
max
dailysends: 50 # 每个项目每日上限
max
consecutivefailures: 5 # N 次失败后暂停项目
loop
detectionthreshold: 3 # 检测重复输出循环
多项目调度器
yaml
scheduler:
strategy: round-robin # 或 priority
max
sendsper_tick: 1
inter
projectdelay: 5 # 项目发送之间的秒数
项目目录
yaml
project_dirs:
- ~/project-alpha
- ~/project-beta
Gemini 前端路由
yaml
gemini:
default_window: gemini-h5 # 前端任务的默认 tmux 窗口
project_windows:
youxin: gemini-youxin # 每个项目的 Gemini 窗口覆盖
前端任务检测关键词:页面、组件、样式、UI、前端、H5、小程序、界面、frontend、component、style、page、layout
Discord 频道路由
yaml
discord_channels:
my-project:
channel_id: 123456789
tmux_window: my-project
project_dir: /path/to/project
Telegram 通知
yaml
telegram:
bot
token: YOURBOT_TOKEN
chat
id: YOURCHAT_ID
status_interval: 1800
使用
添加项目
- 1. 在命名 tmux 窗口中启动 Codex CLI 会话:
bash
tmux new-window -t autopilot -n my-project
# 在新窗口中,cd 到项目并运行 codex
- 2. 将项目路径添加到 config.yaml 的 project_dirs 下
- 3. 可选地创建 projects/my-project/tasks.yaml 用于任务队列:
yaml
project:
name: My Project
dir: ~/my-project
enabled: true
priority: 1
tasks:
- id: feature-x
name: Implement feature X
prompt: |
Implement feature X per the spec in docs/feature-x.md
手动操作
bash
检查所有项目的状态
./scripts/monitor-all.sh
手动提示特定项目
./scripts/auto-nudge.sh my-project
向 tmux 窗口发送命令
./scripts/tmux-send.sh my-project codex exec fix the tests
入队后端任务(