Skip to content

定时自动化任务 ​

DevAgent 自动化会从 CLI 按计划运行一个提示,这样周期性的分类、审查和维护任务无需你手动打开 worktree 就能启动。读完本页后,你将创建一个被禁用的自动化、检视它,并在准备就绪时运行它。

创建一个安全的首个自动化 ​

在调整提示和目标期间,先用 --disabled 起步:

devcore automations create \
  --name "Weekday triage" \
  --trigger weekdays \
  --time 09:00 \
  --prompt "Triage new issues and summarize blockers" \
  --provider codex \
  --repo my-repo \
  --disabled \
  --json

--trigger 接受 hourly、daily、weekdays 和 weekly 等预设,以及 cron 表达式或 RRULE 字符串。当计划应遵循特定的 IANA 时区而非运行时默认时区时,使用 --timezone <tz>。

选择运行发生的位置 ​

当每次运行都应在某个仓库中创建或选择工作时,使用 --repo <selector>。当自动化应改为在一个已有的 DevAgent worktree 内运行时,使用 --workspace <selector>:

devcore automations create \
  --name "Nightly status" \
  --trigger "0 18 * * 1-5" \
  --prompt "Summarize today's changes" \
  --provider claude \
  --workspace active \
  --disabled

当你两个目标标志都省略时,DevAgent 会在可能的情况下从当前 shell 目录解析出所在的 worktree。

运行前预检 ​

当一个廉价的 shell 探测失败时跳过计划中的工作(非零退出会记录为一次跳过的运行):

devcore automations create \
  --name "PR review" \
  --trigger hourly \
  --precheck "gh pr list --json number -q .[0].number" \
  --prompt "Review requested PRs" \
  --provider codex \
  --repo my-repo \
  --disabled \
  --json

项目 host / 设置目标 ​

当自动化应在特定的项目 host 设置上运行,而不仅仅是 --repo / --workspace 时:

devcore automations create \
  --name "Remote triage" \
  --trigger daily \
  --time 09:00 \
  --prompt "Triage open issues" \
  --provider claude \
  --project <projectId> \
  --host <hostId> \
  --disabled \
  --json

当你已经有一个 setup id 时,使用 --project-host-setup <id>。可选的 --source-context '<json>' 会将任务/提供方数据绑定到某个 host/账号(编辑时传 null 可清除)。

错过运行的宽限期 ​

devcore automations edit <automationId> --missed-run-grace-minutes 30 --json

复用已有的自动化会话 ​

对于目标为已有 worktree 的自动化,当后续运行应在上一个活动的自动化终端中继续、而非每次都从空白终端开始时,添加 --reuse-session:

devcore automations create \
  --name "Inbox digest" \
  --trigger hourly \
  --prompt "Summarize unread mail" \
  --provider codex \
  --workspace active \
  --reuse-session \
  --disabled

使用 devcore automations edit <automationId> --fresh-session --json 可将自动化切回每次运行都使用全新终端。

审查并启用 ​

在启用之前先列出并检视自动化:

devcore automations list --json
devcore automations show <automationId> --json
devcore automations edit <automationId> --enabled --json

在桌面端的自动化列表中,当你有很多计划时,可使用搜索框按 name、project 或 prompt 文本进行过滤。位于 SSH host 上的外部自动化,即使该 host 已断开连接,仍会作为可管理(包括删除)的作业显示——你无需仅仅为了移除一个计划就保持活动的 SSH 会话。

使用 edit 可更改名称、提示、提供方、目标、计划或启用状态。remove 会删除一个自动化及其运行历史。

按需运行 ​

创建自动化后,先手动触发它以检查提示和目标,而不必等到下一个计划时间:

devcore automations run <automationId> --json
devcore automations runs --id <automationId> --json

如果某次运行在打开 workspace 或重连到其目标之前就失败了,可在 DevAgent 中打开该次运行并点击 Rerun,为同一个自动化排队一次全新的手动运行。

后续步骤 ​

DevAgent 桌面客户端文档