SuperAPI AI 工具集

examples-auto-run

编程与开发

查看项目

更新于 10-16 15:08

技能介绍

用途

examples-auto-run 用于自动、批量地运行 openai-agents-js 仓库中的示例脚本(examples:start-all),并配套启动、停止、日志查看与失败重跑等辅助能力,适合在开发或验证示例时减少人工干预。

主要能力

  • 运行前先执行 pnpm build && pnpm -r build-check。
  • 以自动输入模式运行 pnpm examples:start-all,交互提示自动应答,HITL/MCP/apply-patch 自动批准。
  • 并行执行启动(默认并发 4),每个 start 的 stdout/stderr 分别写入 .tmp/examples-start-logs/ 下的独立日志文件。
  • 通过 run.sh 提供 start/stop/status/logs/tail 辅助命令。
  • 支持 collect 从最新主日志生成重跑列表,rerun 只重跑 .tmp/examples-rerun.txt 中的条目。
  • 支持自动跳过列表(EXAMPLES_AUTO_SKIP,逗号或空格分隔),可覆盖内置默认值,自动跳过项不会进入重跑收集,也会从重跑执行中移除。

使用方式

启动(自动模式,默认并发 4):

.agents/skills/examples-auto-run/scripts/run.sh start [extra args to examples:start-all]

仅调用技能名($examples-auto-run)时:若 .tmp/examples-rerun.txt 存在且非空,自动执行 rerun;否则执行默认的 start。

示例:

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

查看状态:

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

停止任务(终止 .tmp/examples-auto-run.pid 中的 pid):

.agents/skills/examples-auto-run/scripts/run.sh stop

列出日志(按启动脚本):

.agents/skills/examples-auto-run/scripts/run.sh logs

跟踪最新日志:

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

运行后从最新主日志构建重跑列表(自动跳过列表从 scripts/run-example-starts.mjs 导入,server/audio/external 跳过会被遵循):

.agents/skills/examples-auto-run/scripts/run.sh collect

仅重跑 .tmp/examples-rerun.txt 中的条目:

.agents/skills/examples-auto-run/scripts/run.sh rerun

查看当前自动跳过列表(env 或默认值):

.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(在 runner 中设置)
  • EXAMPLES_CONCURRENCY=4;其中 sandbox:start:memory-generation 仍由 runner 串行执行,因为其 pre-stop memory generation 可能与共享本地资源争用,其他 hosted、Unix-local、Docker sandbox 示例仍并行。
  • EXAMPLES_EXECA_TIMEOUT_MS=300000(5 分钟);financial-research-agent 与 computer-use 在脚本内使用 10 分钟。
  • 默认包含 interactive,排除 server/audio/external:EXAMPLES_INCLUDE_INTERACTIVE=1、EXAMPLES_INCLUDE_SERVER=0、EXAMPLES_INCLUDE_AUDIO=0、EXAMPLES_INCLUDE_EXTERNAL=0。这意味着 realtime-* / nextjs(标记为 server/audio)会被跳过,除非用 --include-server / --include-audio 或对应 env 标志显式启用。
  • 自动跳过默认值包括: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 调用 start 或 rerun 时,默认在 Codex 沙箱之外运行(sandbox_permissions=require_escalated)。多个示例会启动嵌套沙箱、浏览器、npm 辅助程序或本地服务进程,在 Codex 沙箱内运行可能产生仅由环境导致的失败,例如 Playwright 浏览器启动权限错误、npm 缓存权限错误或嵌套沙箱设置错误。仅当用户明确要求,或运行不执行示例的窄范围 dry-run / 日志检查命令时,才使用沙箱执行。
  • 任务在后台运行但不 disown;若 Codex 挂起或结束 shell,进程组收到 SIGHUP 并停止。手动清理:run.sh stop(若已退出会移除陈旧 pid)。

日志位置

  • .tmp/examples-start-logs/<package>__<script>.log(每个 start)
  • 主 runner 日志路径在调用 start 时打印。
  • 重跑列表(由 collect 生成):.tmp/examples-rerun.txt(每行一个 package:script)。

注意事项

  • 自动跳过集中管理(默认值同上),可通过 EXAMPLES_AUTO_SKIP 覆盖。
  • 自动输入映射覆盖常见交互提示;HITL/MCP/apply-patch 通过 env 在 runner 中自动批准。shell 工具批准在自动模式下自动批准(SHELL_AUTO_APPROVE=1)。
  • rerun 顺序执行条目,失败后继续,并仅用剩余失败项重写 .tmp/examples-rerun.txt,自动跳过项不会被重新加入。
  • runner 不进行行为校验,因此每次 start 或 rerun 后必须立即执行校验,无需等待用户要求:
    1. 阅读示例源码,从代码/注释推断预期流程(调用的工具、预期输出、守卫、批准)。
    2. 阅读 .tmp/examples-start-logs/ 下对应日志。
    3. 对比意图与日志:确认关键动作/结果发生,标记遗漏或偏差。
    4. 对所有 exit-0 条目执行此操作,而不仅是样本。
    5. 运行完成后立即总结发现;当为 “OK” 时,说明检查了什么(例如 “tools called + final message emitted”)。
    6. 报告时不要省略或截断用于支撑校验的输出;包含完整相关行(保持简洁但不截断)。
  • runner 在总结后打印完整表格:每个启动脚本一行,包含 status、package:script、info(原因/退出/跳过)和日志路径。若运行在表格出现前停止,将分析器指向最新 main_*.log 以重建表格与校验。

限制

  • 行为校验不在 runner 中完成,需人工/Codex 后续执行。
  • 任务未 disown,shell 结束会导致子进程收到 SIGHUP 退出。
  • 默认排除 server/audio/external 相关示例,需显式启用。
  • 部分示例(如 sandbox:start:memory-generation)被串行化处理。
  • 其他平台支持、收费、价格信息暂未提供。