Day 17 / 共 20 天 · 第 4 周 · 工程化与收官

codex exec:非交互与 CI

--json / -o / schema、CI 安全默认、review 子命令。

📍 你在整门课的位置 · 第 4 周 · 工程化与收官
D16 会话D17 codex execD18 TypeScript SDK 嵌入D19 app-server 与 IDE/桌面桥D20 收官串讲与学习路线
L01

非交互跑一轮

codex exec "修复失败的单元测试并说明改动"
codex e "summarize this repo in 5 bullets"
codex exec resume --last "继续"

实现:codex-rs/exec/——同样走 in-process app-server,事件经 human 或 JSONL processor 输出。

L02

给机器读的输出

codex exec --json "…"
codex exec -o last.txt "…"
codex exec --output-schema schema.json "生成符合 schema 的结果"
Flag用途
--jsonstdout 打 JSONL 事件
-o最终消息落盘
--ephemeral不持久化会话
--skip-git-repo-check非 git 目录也跑

还有 codex review / codex exec review 做非交互审查。

L03

CI 注意

安全CI 才考虑 bypass;仍要限制可写目录与密钥。默认能严则严。
# 示例:只读分析(按你环境调整)
codex exec -s read-only --json "列出可能的安全问题,不要改文件"
L04

今日小结

✅ 会 exec --json 与 -o;知道和 TUI 共用 core。
← Day 16 Day 18 · TypeScript SDK 嵌入 →