Coding 工具 · 02

Codex CLI

使用 Codex CLI 顶层 notify 配置接收 agent-turn-complete JSON。示例只使用线程、轮次与工作目录,不上传 prompt 或 assistant 正文。

当前官方配置

notify 接收单个 JSON 参数

Codex CLI 在 agent-turn-complete 时执行 notify 数组指定的程序,并把一段 JSON 作为单个命令行参数传入。当前 payload 提供 thread-id、turn-id、cwd 等字段。

步骤 1

创建 notify 适配脚本

codex-bluebell.py
#!/usr/bin/env python3
import json, os, subprocess, sys

CLI = "/Applications/bluebellMac.app/Contents/Helpers/bluebellctl"

try:
    payload = json.loads(sys.argv[1])
except Exception:
    sys.exit(0)

if payload.get("type") != "agent-turn-complete":
    sys.exit(0)

thread_id = str(payload.get("thread-id") or "")
turn_id = str(payload.get("turn-id") or "")
cwd = str(payload.get("cwd") or "")
if not thread_id or not turn_id:
    sys.exit(0)

subprocess.run([
    CLI, "emit",
    "--source", "Codex CLI",
    "--workspace-name", os.path.basename(cwd) or "Codex CLI",
    "--session-id", thread_id,
    "--turn-id", turn_id,
    "--dedupe-key", f"codex-cli:{thread_id}:{turn_id}",
    "--local",
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=3, check=False)

thread-id + turn-id 组成稳定去重身份。示例不使用 last-assistant-message,避免把回复正文意外加入通知元数据。

步骤 2

加入用户级 config.toml

在 ~/.codex/config.toml 顶层加入一行,并替换脚本的真实绝对路径:

config.toml
notify = ["python3", "/absolute/path/codex-bluebell.py"]

这不是某个项目段落下的配置。保留文件中其他设置,不要添加第二个互相覆盖的 notify。

步骤 3

先验证 CLI 轮次

  1. 保持 bluebell Mac 运行,用 Codex CLI 完成一轮短任务。
  2. 检查最近提醒只出现一条来源为 Codex CLI 的本机事件。
  3. 在同一线程完成第二轮,确认生成不同 turn-id。
  4. 验证后从适配脚本删除 --local,再检查 Mac 总推送、iCloud 队列和真实 Watch。

来源

OpenAI 官方资料