tmux + launchd 多项目 Codex CLI 自动化系统。使用 Watchdog 驱动的循环监控 tmux 中的多个 Codex 会话,自动唤醒空闲会话,处理...
Automated multi-project Codex CLI orchestration via tmux + launchd on macOS.
Codex Autopilot runs a watchdog loop that monitors multiple Codex CLI sessions in tmux windows. It detects idle sessions, auto-nudges them to continue, handles permission prompts, rotates logs, dispatches tasks from a queue, and sends notifications via Discord/Telegram.
bash
git clone https://github.com/imwyvern/AIWorkFlowSkill.git ~/.autopilot
cd ~/.autopilot
cp config.yaml.example config.yaml
# Edit config.yaml with your project paths, Telegram bot token, and Discord channels
codex) — OpenAI's coding agentInstall dependencies via Homebrew:
bash
brew install tmux yq jq
Use install.sh to register the launchd plist:
bash
./install.sh
This creates a LaunchAgent that runs the watchdog on a configurable interval.
Main loop engine. On each tick:
codex-status.shCaptures and analyzes tmux pane content. Detects:
Sends keystrokes or text to a specific tmux window. Handles:
Shared function library used by all scripts:
Defines status constants used across scripts (e.g., STATUS_ACTIVE, STATUS_IDLE, STATUS_PERMISSION).
Task queue manager. Supports:
Sends formatted notifications to Discord channels via webhook. Supports project-channel routing defined in config.yaml.
ScriptPurposeauto-nudge.shNudge logic for idle Codex sessionsauto-check.shPeriodic health check across all projectspermission-guard.shAuto-approve or flag permission promptsincremental-review.shRun code review on recent changesmonitor-all.shDashboard: show status of all monitored projectsstatus-sync.shSync state to status.json for external consumptionrotate-logs.shLog rotation and cleanupcleanup-state.pyRemove stale entries from state.jsonclaude-fallback.shFallback handler when Codex is unavailableprd-audit.shAudit PRD completion statusprd-verify.sh / prd_verify_engine.pyVerify PRD items against codebasecodex-token-daily.pyTrack daily token usage
Edit config.yaml (copy from config.yaml.example). Key sections:
yaml
active_threshold: 120 # seconds — Codex considered "working"
idle_threshold: 360 # seconds — Codex considered "idle", triggers nudge
cooldown: 120 # minimum seconds between sends to same project
yaml
max_daily_sends_total: 200 # global daily send cap
max_daily_sends: 50 # per-project daily cap
max_consecutive_failures: 5 # pause project after N failures
loop_detection_threshold: 3 # detect repeated output loops
yaml
scheduler:
strategy: "round-robin" # or "priority"
max_sends_per_tick: 1
inter_project_delay: 5 # seconds between project sends
yaml
project_dirs:
- "~/project-alpha"
- "~/project-beta"
yaml
discord_channels:
my-project:
channel_id: "123456789"
tmux_window: "my-project"
project_dir: "/path/to/project"
yaml
telegram:
bot_token: "YOUR_BOT_TOKEN"
chat_id: "YOUR_CHAT_ID"
status_interval: 1800
Start a Codex CLI session in a named tmux window: bash
tmux new-window -t autopilot -n my-project
# In the new window, cd to project and run codex
Add the project path to config.yaml under project_dirs
Optionally create projects/my-project/tasks.yaml for task queue:
yaml
project:
name: "My Project"
dir: "~/my-project"
enabled: true
priority: 1
tasks:
### Manual Operations
bash
```bash
# Check status of all projects
./scripts/monitor-all.sh
# Manually nudge a specific project
./scripts/auto-nudge.sh my-project
# Send a command to a tmux window
./scripts/tmux-send.sh my-project "codex exec 'fix the tests'"
# Enqueue a task
./scripts/task-queue.sh enqueue my-project "Refactor auth module"
# Run the watchdog once (for testing)
./scripts/watchdog.sh
autopilot.py provides a Python-based alternative with richer state management:
bash
python3 autopilot.py --once # single pass
python3 autopilot.py --daemon # continuous loop
text
~/.autopilot/
├── SKILL.md # This file
├── config.yaml # Local config (not in git)
├── config.yaml.example # Config template
├── scripts/ # All automation scripts
├── projects/ # Per-project task definitions
├── docs/ # Additional documentation
├── code-review/ # Code review templates
├── development/ # Development workflow templates
├── doc-review/ # Doc review templates
├── doc-writing/ # Doc writing templates
├── requirement-discovery/ # Requirement discovery templates
├── testing/ # Testing templates
├── tests/ # Test suite
├── state/ # Runtime state (gitignored)
├── logs/ # Runtime logs (gitignored)
├── task-queue/ # Task queue data (gitignored)
└── archive/ # Deprecated files