👁️ 123
👍 53
📅 2026-06-13 收录
🔄 2026-06-15 更新

正文内容

维护路径: 所有 Codex profile 操作请统一使用 codex-profiler

独立的 codex-usagecodex-auth 技能已弃用。

本技能整合了以下两个脚本:

  • scripts/codex_usage.py(用量/配额检查)
  • scripts/codex_auth.py(用于启动/状态查询的 OAuth 辅助工具)

对于认证(auth)或 profile 的变更操作,本技能现已统一采用网关原生命令:openclaw models auth ...


安全默认行为

  • 用量检查默认为只读操作。
  • 认证状态由运行时动态管理;一次性直接编辑文件不可靠,可能被内存中状态或冷却期(cooldown)覆盖。
  • 请将 auth-profiles.json 视为网关托管的状态文件,在常规操作中禁止直接修改
  • 优先使用网关原生命令进行认证变更(如 openclaw models auth ...openclaw models auth order ...),而非脚本级的文件写入。
  • 建议采用“预检(dry-run / read-only)→ 应用 → 验证”的三步流程(详见下方严格防漂移流程)。
  • 具体允许/禁止的操作边界,请参阅 RISK.md

命令列表

用量查询(Usage)

  • /codex_usage → 启动 profile 选择器(默认 / 全部 / 已发现的 profiles)
  • /codex_usage → 查询指定 profile 的用量信息

认证操作(Auth)

  • /codex_auth → 启动 profile 选择器
  • /codex_auth → 查询指定 profile 的认证状态
  • /codex_auth finish → 仅限回调解析辅助;profile 或 order 的变更必须通过网关原生命令执行

用户体验要求(跨渠道通用)

对于 /codex_usage,需首先单独发送一条即时进度消息

  • “正在运行 Codex 用量检查……”

交付规则:

  • 若进度消息通过 channel message 工具路径发送,则最终结果也必须通过同一路径(相同目标/会话) 发送,并返回 NO_REPLY
  • 禁止混合交付方式(例如:工具路径发进度 + 普通文本回复发结果)。

对于 auth/profile/order 变更操作,须明确提示用户:

  • “我将通过 openclaw models auth ... 执行变更,并随后使用 models statusauth order get 进行验证。”
  • “我不会直接手动编辑认证文件,因为运行时状态可能漂移或覆盖一次性编辑。”

交互适配器(Interaction adapter)

  • 若支持内联按钮(inline buttons):使用 selector 按钮。
  • 若不支持内联按钮:使用纯文本 fallback 提示。
  • 对同一用户的重复请求实施约 20 秒的去重抑制(duplicate-request suppression)。
  • 响应中严禁回显完整 callback URL。

Profile 删除策略(强制执行)

  1. 推荐方式(默认):操作性停用(operational retire),非硬删除(hard delete)

    • 将目标 profile 从活跃 provider 排序中移除(openclaw models auth order set ...),确保其永不被选中。
    • 除非用户明确要求永久删除,否则应保留 profile 数据完整。
  2. 仅在用户明确指令下执行硬删除

    • 仅当用户清晰表达“永久删除”或“彻底移除”意图时,才执行永久 profile 删除。
    • 若当前安装的 OpenClaw 版本不支持网关原生删除命令,不得自行构造高风险的实时文件编辑;应转入受控的维护窗口流程处理。

严格防漂移认证变更流程(强制执行)

所有 auth/profile/order 变更均须严格遵循以下三步流程:

1) 预检(Preflight,只读)

openclaw models status --json
openclaw models auth order get --provider openai-codex --agent 

2) 应用(Apply,网关原生命令)

openclaw models auth order set --provider openai-codex --agent 
# 或
openclaw models auth order clear --provider openai-codex --agent 
# 或触发 provider 登录流程
openclaw models auth login --provider openai-codex

3) 验证(Verify,应用后校验,不作任何假设)

openclaw models status --json
openclaw models auth order get --provider openai-codex --agent 

绝不跳过验证步骤。 若验证结果与预期不符,禁止手动编辑文件;应诊断问题并重新通过网关原生命令执行变更。


如何运行

# 用量检查(只读)
python3 skills/codex-profiler/scripts/codex_usage.py --profile all --timeout-sec 25 --retries 1 --debug
python3 skills/codex-profiler/scripts/codex_usage.py --profile all --format text

# OAuth 辅助(仅解析 callback / 查询状态)
python3 skills/codex-profiler/scripts/codex_auth.py start --profile default
python3 skills/codex-profiler/scripts/codex_auth.py status

安全立场(Safety posture)

  • 本技能禁止执行任何远程 shell 命令(如 curl|bashwget|sh)。
  • 不包含任何 sudo / SSH / 系统级主机变更命令
  • 用量检查仅限于可信 HTTPS 端点白名单域名(chatgpt.com)。
  • Callback URL 与 token 类敏感材料须严格保密,禁止在响应中完整回显

多账号轮换指南(Multi-account rotation guidance)

当被问及多 Codex 账号/profile 运行、轮换策略或降级方案时,请查阅:

  • references/multi-account-rotation.md
  • 快速聊天回复请使用简版模板(short template);
  • 配置/排障类请求请使用深度模板(deep-dive template)。

补充说明(Notes)

  • 默认使用认证 profile 文件路径:~/.openclaw/agents/main/agent/auth-profiles.json
  • 当前唯一可信数据源为 auth-profiles.jsonauth.json 仅为向后兼容遗留文件,不应作为主状态源使用
  • 若 profile 路由行为异常,请先排查混合状态问题:是否存在缺失/过期的 auth-profiles.json、残留的 legacy 文件、或运行时冷却态(stale runtime cooldown),再判断是否为模型 fallback 缺陷。
  • 同一 accountId 出现在两个 profile 标签中不自动视为缺陷。在此环境中,多个标签可映射至同一 workspace/account 身份,且仍可正常工作;只要两个 profile 在 /codex_usage 中均认证有效且可用,即属健康状态;仅当出现认证失败或路由失败时才需深入排查。
  • Codex 用量端点地址:https://chatgpt.com/backend-api/wham/usage
  • 用量脚本现将 401 错误归类为 auth_not_accepted_by_usage_endpoint,并附带清晰提示,同时仍返回本地 profile 健康状态。
  • 用量输出新增顶层字段:summaryformatted_profilessuggested_user_message,以提升 slash-command 格式整洁度。
  • /codex_usage 推荐严格单行输出格式(每 profile 一行):