场景定位
让 Codex 为一个 Mac 功能添加轻量 unified logging,运行应用、触发路径,并用 Console 或 `log stream` 验证事件顺序,而不是只靠代码审查猜测行为。
- 难度
- 中级
- 时间跨度
- 约 1 小时
适合用于
- 需要追踪窗口打开、侧边栏选择、菜单命令、菜单栏动作、同步里程碑或 fallback path 的 Mac app 功能
- 希望 Codex patch、rerun、inspect logs,再基于证据继续修复的 agentic debugging loop
- 需要保存一段紧凑 app session timeline,供后续 Codex run 对比的本地调试流程
Skills & Plugins
相关工具
Starter Prompt
起步提示词
Use the Build macOS Apps plugin to add lightweight unified logging around [name one Mac feature or action flow], then run the app and verify from logs that those events fire in the expected order.
Constraints:
- Prefer `Logger` from `OSLog`, not `print`, and create a clear subsystem/category pair for this feature so the logs are easy to filter.
- Log one concise line for each important action boundary or state transition: for example window opened, sidebar selection changed, menu command invoked, sync started, sync finished, or fallback path taken.
- Keep permanent `info` logs stable and high signal. Use `debug` only for noisy local details, and remove or demote temporary instrumentation before finishing.
- Do not log secrets, auth tokens, personal data, or raw document contents.
- Build and run the app, exercise the feature path yourself, and verify the events with Console or a focused `log stream` predicate.
Deliver:
- files changed
- logger subsystem/category
- exact build/run/log commands
- one or two representative log lines that prove the flow is instrumented correctly 在 ChatGPT 中尝试 在模糊处添加一个 Logger
这个场景适合 Mac app 中“某件事发生了”但只靠代码审查无法确定的流程。让 Codex 围绕一个行为添加少量高信号 unified logs,运行应用、触发行为,并从 Console 或 `log stream` 验证预期事件是否出现。
Build macOS Apps 插件的 telemetry skill 很轻量:使用 Apple `Logger`,选择明确 subsystem/category,记录 action boundaries 和 state transitions,避免敏感 payload,并在本地 build/run 后验证事件。
为什么遥测适合 agentic engineering
好日志能在每次 patch 后给 Codex 一个可重复反馈循环。它不用让你手工检查每个窗口、菜单动作或同步 transition,而是可以运行应用、操作流程、检查过滤后的日志,再基于证据决定下一次改动。
- Hands-free debug loop:instrument 可疑流程,启动应用,触发 sidebar 或 command,读取日志序列,patch 状态更新路径,再跑同一流程。
- App session collection loop:记录 app launch、window open、sidebar selection、import started/finished/failed 等关键事件,并总结 timeline。
- Regression evidence loop:在修复后保留同一 log predicate 和样例输出,作为后续验证入口。
保持 instrumentation 小而可过滤
让 Codex 为每个 feature area 建一个 logger,而不是为每次 state mutation 永久加日志。`Windowing`、`Commands`、`MenuBar`、`Sidebar`、`Sync`、`Import` 这类 category 更容易在下一轮调试中过滤。
import OSLog
private let logger = Logger(
subsystem: Bundle.main.bundleIdentifier ?? "SampleApp",
category: "Sidebar"
)
@MainActor
func selectItem(_ item: SidebarItem) {
logger.info("Selected sidebar item: \(item.id, privacy: .public)")
selection = item.id
} 要求 Codex 用日志证明事件
价值不只是添加 `Logger` 调用。让 Codex 运行应用、触发被 instrument 的流程,并给出它使用的 Console filter 或 `log stream` predicate,以及一两条代表性日志行。
如果预期事件没有出现,让 Codex 把日志移动到更接近可疑控制路径的位置,重新运行同一流程,并持续迭代到日志能解释发生了什么。
log stream --style compact --predicate 'subsystem == "com.example.app" && category == "Sidebar"' 保存 session trace 供后续使用
对更长或间歇性 bug,让 Codex 把聚焦 log stream 保存到一个小型本地 trace 文件,概括 timeline,并把 artifact 留在 workspace。后续 Codex run 就能复用同一证据,而不必每次重放完整 session。
如果某部分需要人手动操作,也可以让 Codex 启动 logging-friendly debug loop,开始过滤捕获,等你复现完成后读取保存的 trace 文件。
实用提示
- 一次 instrument 一个 feature:sidebar、window、command 或 sync path,保持序列容易检查。
- 把隐私写进 prompt:要求 Codex 解释每个 logged identifier,并避免把 secrets、个人数据或原始内容写入 unified logs。
- 在最终总结里保留 predicate 和样例输出,让下一轮 agent 能复用同一个验证循环。
技术栈
结构化 unified logging 给 Codex 一个窄而可过滤的反馈循环,避免把代码库变成 `print` 墙。
插件的 telemetry 和 build/run skills 设计为一起使用:instrument 一个流程,启动应用,检查日志,再收紧事件集。
具体 log filter 加样例输出可以成为可复用 handoff,也让新增 instrumentation 更容易跨运行验证。