mcpField
E
examples-auto-run

examples-auto-run

github.com/openai测试与质量4.0k106 次安装1 天前更新
代码仓库

关于 examples-auto-run

通过脚本以自动输入模式构建并运行项目示例,支持并行启动、分别记录日志,以及启动、停止、查看和重跑辅助操作。

主要功能

  1. 01运行前构建并检查软件包
  2. 02以自动输入模式启动示例
  3. 03并行运行符合条件的任务
  4. 04为每次启动写入独立日志
  5. 05提供启动、停止、状态和日志操作
  6. 06按顺序重跑记录的失败项

适用场景

  1. 01批量运行示例启动脚本
  2. 02查看各次示例运行日志
  3. 03重试先前运行失败的示例

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/openai/openai-agents-js --skill examples-auto-run

安装后在 Claude Code 中输入/examples-auto-run确认已加载。

附带文件agents/openai.yamlscripts/run.sh

详细介绍

examples-auto-run

功能说明

  • 首先运行 pnpm build && pnpm -r build-check
  • 以自动输入模式运行 pnpm examples:start-all(自动回答交互式提示,并自动批准 HITL/MCP/apply-patch)。
  • 并行执行各项启动任务(默认并发数为 4),并将每项启动任务的 stdout/stderr 输出到 .tmp/examples-start-logs/ 下各自的日志文件中。
  • 通过 run.sh 提供 start/stop/status/logs/tail 辅助命令。
  • 如果 Codex 会话结束(未使用 disown/nohup),子进程会收到 SIGHUP 并退出;也可以使用 stop 手动清理。

用法

# Start (auto mode, concurrency=4 by default)
.agents/skills/examples-auto-run/scripts/run.sh start [extra args to examples:start-all]
# If you invoke the skill name alone ($examples-auto-run):
#   - when `.tmp/examples-rerun.txt` exists and is non-empty, it will run `rerun` automatically
#   - otherwise it runs the default `start` command.

# Examples:
.agents/skills/examples-auto-run/scripts/run.sh start --filter basic
.agents/skills/examples-auto-run/scripts/run.sh start --include-server --include-audio

# Check status
.agents/skills/examples-auto-run/scripts/run.sh status

# Stop running job (kills pid from .tmp/examples-auto-run.pid)
.agents/skills/examples-auto-run/scripts/run.sh stop

# List logs (per start script)
.agents/skills/examples-auto-run/scripts/run.sh logs

# Tail latest log
.agents/skills/examples-auto-run/scripts/run.sh tail
.agents/skills/examples-auto-run/scripts/run.sh tail basic__start_hello-world.log

# After a run, build a rerun list from the latest main log (auto-skip list is imported from `scripts/run-example-starts.mjs` and server/audio/external skips are honored)
.agents/skills/examples-auto-run/scripts/run.sh collect
# Rerun only the entries in .tmp/examples-rerun.txt
.agents/skills/examples-auto-run/scripts/run.sh rerun
# Show the current auto-skip list (env or defaults)
.agents/skills/examples-auto-run/scripts/run.sh start --print-auto-skip --dry-run

默认值(可通过环境变量覆盖)

  • EXAMPLES_INTERACTIVE_MODE=auto
  • AUTO_APPROVE_MCP=1、APPLY_PATCH_AUTO_APPROVE=1、AUTO_APPROVE_HITL=1(在运行器中设置)
  • EXAMPLES_CONCURRENCY=4
    • 运行器仍会串行执行 sandbox:start:memory-generation,因为其预先停止的内存生成任务可能会与共享本地资源产生争用。其他托管、Unix 本地和 Docker 沙盒示例仍会并行执行。
  • EXAMPLES_EXECA_TIMEOUT_MS=300000(5 分钟)
    financial-research-agent 和 computer-use 在脚本中使用 10 分钟超时。
  • 默认包含交互式示例;排除服务端/音频/外部示例:
    • EXAMPLES_INCLUDE_INTERACTIVE=1
    • EXAMPLES_INCLUDE_SERVER=0
    • EXAMPLES_INCLUDE_AUDIO=0
  • EXAMPLES_INCLUDE_EXTERNAL=0
    • 这意味着 realtime-* / nextjs(标记为 server/audio)会被跳过,除非通过 --include-server / --include-audio 或相应的环境变量标志选择包含。
  • 自动跳过列表:EXAMPLES_AUTO_SKIP(以逗号/空格分隔)会覆盖 run.sh 和 run-example-starts.mjs 使用的内置默认值。默认值包括 agent-patterns:start:llm-as-a-judge、connectors:start、mcp:start:hosted-mcp-on-approval、mcp:start:hosted-mcp-human-in-the-loop、sandbox:start:vercel、tools:start:codex、tools:start:codex-same-thread。

Codex 执行环境

  • 当 Codex 调用 start 或 rerun 时,默认在 Codex 沙盒外运行命令(sandbox_permissions=require_escalated)。多个示例会启动嵌套沙盒、浏览器、npm 辅助工具或本地服务进程;在 Codex 沙盒内运行可能导致仅由环境引起的故障,例如 Playwright 浏览器启动权限错误、npm 缓存权限错误或嵌套沙盒设置错误。
  • 仅当用户明确要求,或运行不会执行示例的有限范围试运行/日志检查命令时,才使用沙盒执行。

取消 / 清理

  • 作业会在后台运行,但不会解除关联;如果 Codex 挂起/结束 shell,进程组会收到 SIGHUP 并停止。
  • 手动清理:run.sh stop(如果进程已退出,则会移除过期的 pid)。

日志位置

  • .tmp/examples-start-logs/<package>__<script>.log(每项启动任务一个日志文件)
  • 调用 start 时会打印主运行器的日志路径。
  • 重跑列表(由 collect 生成):.tmp/examples-rerun.txt(每行一个 package:script)。

备注

  • 自动跳过功能采用集中配置(默认值与上文相同),并可通过 EXAMPLES_AUTO_SKIP 覆盖。自动跳过的条目不会纳入重新运行收集,并会自动从重新运行的执行中移除。
  • 自动输入映射涵盖常见的交互式提示;运行器会通过环境变量启用 HITL/MCP/应用补丁的自动批准。
  • 自动模式下,Shell 工具的审批会自动通过(SHELL_AUTO_APPROVE=1)。
  • rerun 会按顺序运行条目,在失败后继续执行,并将 .tmp/examples-rerun.txt 重写为仅包含剩余失败项。自动跳过的条目不会重新添加。
  • 运行器不会进行行为验证,因此 Codex 必须在每次调用 start 或 rerun 后立即执行验证,不得等待用户提出要求。 必须执行以下步骤:
    1. 阅读示例源代码,根据代码和注释推断预期流程(调用的工具、预期输出、保护条件、审批)。
    2. 阅读 .tmp/examples-start-logs/ 下对应的日志。
    3. 对比预期行为与日志:确认关键操作和结果已发生;标记遗漏或偏差。
    4. 对所有退出码为 0 的条目执行此操作,而不仅是抽查样例。
    5. 在运行完成后立即汇总结果;如果结果为“OK”,注明检查了哪些内容(例如“已调用工具 + 已输出最终消息”)。
    6. 汇报时,不得省略或缩写用于证明验证结果的输出;请包含完整的相关行(保持简洁,但不得截断)。
  • 运行器会在摘要后打印完整表格:每个 start 脚本占一行,包含 status、package:script、info(原因/退出状态/是否跳过)和日志路径。如果运行在表格出现前停止,请让分析器查看最新的 main_*.log,以重建表格并完成验证。

评论

支持 Markdown