@bacnh85/pi-cron

中文文档
0.4.0发布于 2026/10/11MIT近 30 天下载 3417

Scheduled jobs for Pi — cron-style jobs that fire a prompt into the live session while pi is running, with past-due catch-up and crontab export for 24/7 needs.

原始使用文档
文档目录4 节
  1. Install
  2. Usage
  3. Configuration
  4. Notes

@bacnh85/pi-cron

Scheduled jobs for Pi — cron-style jobs that fire a prompt into the live session while pi is running, with past-due catch-up and crontab export for 24/7 coverage.

Install

pi install @bacnh85/pi-cron

Usage

The cron tool (and /cron command) manages jobs stored in <agentDir>/cron/jobs.json:

ActionWhat it does
addCreate a job: name, schedule (5-field cron), prompt (fired as a standalone turn), optional cwd, optional model / thinking pins.
removeDelete a job by name.
listShow name, schedule, next/last fire, enabled, last run status ([ok] / [FAIL: reason]), model pin.
runFire a job manually right now (also the retry for a failed job).
enable / disableToggle a job. disable pauses (schedule kept; skipped by ticks and export); enable recomputes the next fire from now — no surprise catch-up fire. add also accepts enabled:false to create a disabled job.
testPreview the next 5 fire times of a schedule.
logsTail the newest run log of a job — see what a failed run printed.
exportPrint crontab lines so jobs also run while pi is closed (headless pi -p --no-session, logs under <agentDir>/cron/logs/).

Example: "every weekday at 9, check CI status and summarize failures" → the agent converts that to cron add schedule:"0 9 * * 1-5" prompt:"...", verifies with test, and adds it.

Execution model: a 30s in-process timer fires due jobs as follow-up turns in the open session; past-due jobs catch up once on the next tick (if pi was closed at the scheduled time). Jobs only run while a pi process is open — use export + system crontab for unattended schedules.

Model & thinking pins (Hermes-style): set model:"provider/id" and/or thinking:"high" on a job and it runs headless in its own pi process (pi -p --no-session --model … --thinking …) instead of the live session — useful for cheap/fast models or isolated runs. Output is logged under <agentDir>/cron/logs/ (default 10 min, configurable via cron.timeoutMs) and the result is delivered back into the session as a follow-up. export includes the pins in crontab lines. Headless children run with PI_CRON_DISABLED=1: the cron scheduler is off inside them (no parent/child races on jobs.json) and job mutations (add/remove/run/enable/disable) are refused — a fired run can never schedule more jobs.

Loop guard: for 30s after a fire is armed, add/remove/run/enable/disable are refused. This is a time window, not in-flight immunity — a fired turn running longer than 30s can still mutate. Treat fired prompts as trusted inputs, same as any tool call the session makes.

Working directory: unpinned jobs only deliver into a session whose cwd matches the job's recorded cwd. A session opened elsewhere skips the fire and marks it [FAIL: cwd mismatch …] (visible in cron list / logs) instead of running the prompt against the wrong project. For cross-cwd reliability, pin model/thinking — pinned jobs run headless in job.cwd no matter which session ticks first.

Single session per agent dir: the jobs store has no cross-process lock. Running multiple pi sessions that share an agent dir can double-fire jobs or lose concurrent edits — use one cron-active session per agent dir, or give each session its own PI_CODING_AGENT_DIR.

Configuration

settings.json:

{ "cron": { "enabled": true, "tickMs": 30000, "timeoutMs": 10800000 } }
  • enabled — global kill switch for the scheduler.
  • tickMs — tick interval (clamped 5s–10min).
  • timeoutMs — hard cap for headless (pinned) child runs — SIGTERM at the cap, SIGKILL after a 5s grace (clamped 1min–24h, default 10min). Raise it for long pinned jobs.

Notes

  • Every fired job spends model tokens on a real turn — keep prompts short.
  • Schedule validation and fire-time math use cron-parser.
  • Headless cron children run with HERDR_ENV stripped (and PI_CRON_DISABLED=1), so they never auto-delegate to herdr panes — subagents in cron jobs always run in-process.

版本与发布记录

@bacnh85/pi-cron 共发布 13 个版本,首次发布于 2026/09/10;过去 12 个月发布了 13 个版本。

版本发布日期距今
0.4.0latest2026/10/1127 天前
0.3.102026/09/301 个月前
0.3.92026/09/281 个月前
0.3.82026/09/271 个月前
0.3.72026/09/261 个月前
0.3.62026/09/241 个月前

关于 @bacnh85/pi-cron 的常见问题

@bacnh85/pi-cron 是什么?

Scheduled jobs for Pi — cron-style jobs that fire a prompt into the live session while pi is running, with past-due catch-up and crontab export for 24/7 needs.

如何安装 @bacnh85/pi-cron?

在项目目录运行 npm install @bacnh85/pi-cron,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:typebox(*)、@earendil-works/pi-coding-agent(>=0.84.3 <1.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bacnh85/pi-cron 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bacnh85__pi-cron 是否存在。

@bacnh85/pi-cron 可以商用吗?

@bacnh85/pi-cron 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bacnh85/pi-cron 的下载量有多少?

根据 npm 官方下载统计,@bacnh85/pi-cron 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,417 次,日均约 114 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bacnh85/pi-cron 还在维护吗?

最新版本 0.4.0 发布于 2026/10/11(27 天前);至今共发布 13 个版本,其中过去 12 个月发布了 13 个;首次发布于 2026/09/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。