Codex Autopilot: 多项目 AI CLI 自动化 - Openclaw Skills

作者:互联网

2026-04-16

AI教程

什么是 Codex Autopilot?

Codex Autopilot 是专为管理多个并发 AI 辅助编码会话的开发人员设计的复杂自动化层。通过利用 tmux 进行会话复用以及 launchd 进行计划执行,它提供了一个强大的看门狗系统,使 AI 代理在无需人工干预的情况下保持高效。此 Openclaw Skills 条目重点介绍了该系统如何通过自动催促空闲会话和处理权限提示来维持项目动力。

该框架作为基于 CLI 的 AI 代理与开发人员操作需求之间的桥梁,提供了诸如自动代码审查、PRD 验证和状态管理等功能。对于需要在多个项目目录中保持 AI 代理专注的复杂开发环境,它具有极高的价值。

下载入口:https://github.com/openclaw/skills/tree/main/skills/imwyvern/autopilot

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install autopilot

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 autopilot。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Codex Autopilot 应用场景

  • 在不同仓库中管理多个并发的 Codex CLI 编码会话。
  • 自动执行背景开发任务,如代码审查或 PRD 验证。
  • 在无需人工监督的情况下编排并行的 AI 辅助编码工作流。
  • 通过 Discord 或 T@elegrimm 接收长时间运行的 AI 任务的实时状态更新。
Codex Autopilot 工作原理
  1. 看门狗循环通过 launchd 启动,并扫描配置好的项目 tmux 窗口。
  2. 系统分析终端输出,以识别会话是处于活跃、空闲还是等待用户权限的状态。
  3. 根据预定义的安全限制,自动驾驶系统会发送操作,例如自动催促空闲提示或批准文件权限。
  4. 任务从优先级列表中出队,并使用专用注入脚本发送到相应的 tmux 窗格。
  5. 状态信息同步到中央 JSON 状态文件,并将通知推送到外部通信渠道。

Codex Autopilot 配置指南

首先,克隆仓库并初始化配置文件:

git clone https://github.com/imwyvern/AIWorkFlowSkill.git ~/.autopilot
cd ~/.autopilot
cp config.yaml.example config.yaml

通过 Homebrew 安装所需的系统依赖项:

brew install tmux yq jq

注册 launchd 代理以启动后台看门狗:

./install.sh

Codex Autopilot 数据架构与分类体系

该技能利用结构化文件层级来管理状态和项目配置,作为 Openclaw Skills 生态系统的一部分:

组件 格式 描述
config.yaml YAML 关于时间阈值、安全限制和项目目录的全局设置。
projects/ YAML 每个项目的任务定义和优先级。
state/ JSON 活跃会话和循环检测的运行时状态跟踪。
logs/ 文本 用于调试看门狗操作和任务执行的轮转日志。
task-queue/ 文件系统 待处理和已处理任务 ID 的持久化存储。
name: codex-autopilot
description: |
  tmux + launchd multi-project Codex CLI automation system. Watchdog-driven loop that monitors multiple Codex sessions in tmux, auto-nudges idle sessions, handles permissions, manages context compaction, runs incremental code reviews, and dispatches tasks from a queue.
  Use when managing multiple concurrent Codex CLI coding sessions, automating development workflows, or orchestrating parallel AI-assisted coding across projects.
  Triggers: autopilot, watchdog, codex automation, tmux codex, multi-project codex, auto-nudge codex, codex session management.

Codex Autopilot

Automated multi-project Codex CLI orchestration via tmux + launchd on macOS.

Overview

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/T@elegrimm.

Installation

git clone https://github.com/imwyvern/AIWorkFlowSkill.git ~/.autopilot
cd ~/.autopilot
cp config.yaml.example config.yaml
# Edit config.yaml with your project paths, T@elegrimm bot token, and Discord channels

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:

brew install tmux yq jq

launchd Setup

Use install.sh to register the launchd plist:

./install.sh

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
  2. Captures current Codex output via codex-status.sh
  3. Determines if session is active, idle, or stuck
  4. Dispatches appropriate action (nudge, permission grant, task from queue)
  5. 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:

  • T@elegrimm 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.

Other Scripts

Script Purpose
auto-nudge.sh Nudge logic for idle Codex sessions
auto-check.sh 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

Configuration

Edit config.yaml (copy from config.yaml.example). Key sections:

Timing Thresholds

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

Safety Limits

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

Multi-Project Scheduler

scheduler:
  strategy: "round-robin"    # or "priority"
  max_sends_per_tick: 1
  inter_project_delay: 5     # seconds between project sends

Project Directories

project_dirs:
  - "~/project-alpha"
  - "~/project-beta"

Discord Channel Routing

discord_channels:
  my-project:
    channel_id: "123456789"
    tmux_window: "my-project"
    project_dir: "/path/to/project"

T@elegrimm Notifications

telegram:
  bot_token: "YOUR_BOT_TOKEN"
  ch@t_id: "YOUR_CHAT_ID"
  status_interval: 1800

Usage

Adding a Project

  1. Start a Codex CLI session in a named tmux window:

    tmux new-window -t autopilot -n my-project
    # In the new window, cd to project and run codex
    
  2. Add the project path to config.yaml under project_dirs

  3. Optionally create projects/my-project/tasks.yaml for task queue:

    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
    

Manual Operations

# 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

Python Autopilot (Alternative)

autopilot.py provides a Python-based alternative with richer state management:

python3 autopilot.py --once        # single pass
python3 autopilot.py --daemon      # continuous loop

Directory Structure

~/.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

相关推荐