omp packages

@maheidem/pi-loop0.8.0

Pi extension: /loop — a generic recurring-prompt loop (Claude Code /loop style) delivered as in-session steer custom messages. Skills (e.g. shepherd) are consumers of /loop, not part of it.

marcos-heidemann Published 7 days ago MIT ~106 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

loop — /loop for pi

Run any prompt on a schedule inside the current session. Modeled on Claude Code's /loop (CronCreate): the interval and the prompt are yours; the loop just keeps injecting the prompt into this conversation every X.

The loop knows nothing about what the prompt says. It is a generic mechanism. Specializations — like the bundled shepherd skill (skills/shepherd/) — are consumers of /loop, not part of it.

Install

The package is on npm as @maheidem/pi-loop. Install an exact version:

pi install npm:@maheidem/pi-loop@<x.y.z>

You can also install from a local path, or add the path to packages in ~/.pi/agent/settings.json. Then run /reload.

Usage

/loop                                               # interactive dashboard
/loop 5m check the deploy and tell me what happened
/loop 30s run the test suite and fix failures       # fast loop (min 15s)
/loop 2h <prompt>                                    # slow loop
/loop status                                         # show active loop
/loop stop                                           # cancel

The bare command opens a responsive dashboard in TUI mode. It shows the current schedule, live countdown, delivery mode, prompt preview, and safe start/edit/stop actions. In print/RPC/JSON modes, the bare command reports status instead. The nested forms remain the stable scripting interface and are taught by argument autocomplete.

Interval formats: 30s, 5m, 2h, 1d (minimum 15s). Omit the interval for the default 10m. A trailing every 5m clause also works: /loop check CI every 5m.

Each tick arrives as a loop-tick custom message — the prompt verbatim, with a one-line provenance header so the model knows it is a scheduled message, not a fresh user request — rendered in the TUI as a collapsible card (↻ loop tick #7 · check the deploy…):

[loop tick #7 · scheduled by /loop, not typed by the user]
check the deploy and tell me what happened

Configuration

The extension has no config file. The loop state is a loop custom entry in the session (see "State & resume" below). /loop status shows the active schedule and the loaded version.

How it works

One mechanism: an in-session timer (extensions/index.ts). Each tick is a single pi.sendMessage({ customType: "loop-tick", content, display: true, details }, { deliverAs: "steer", triggerTurn: true }) call — steer injects into a busy agent and wakes an idle one in the same call, so there is no idle check to race. Catch-up: on agent_settled, if a tick's fire time passed while the agent was busy, it fires immediately (at most one catch-up tick, no backlog). The timer dies with the pi process, the same lifetime a Claude Code in-session cron has. (An earlier version also spawned an external RPC runner; it was removed — old state entries carrying a runnerPid are still read, the field is ignored.)

State & resume

Loop state persists as a loop custom entry in the session JSONL (pi.appendEntry). On /resume, session_start re-arms the timer — CC's "restored on --resume" semantics. /loop stop appends a stopped: true entry. (Entries written by earlier versions under the old entry type, or carrying a legacy runnerPid, are still read.)

Safety & limits

  • One active loop per session (/loop while armed → stop first).
  • Session-scoped by lifetime (delivery is a single in-process call — no child processes, nothing to orphan). No wall-clock expiry.

The shepherd skill (a consumer of /loop)

The bundled skills/shepherd/ skill (installed at ~/.pi/agent/skills/shepherd) is the pi port of the Claude Code shepherd plugin: it pins /loop to a fixed 10-minute cadence with the shepherd-role prompt (watch, act, unblock, understand problems). It's a separate thing from the loop — the loop is generic; the skill just builds a specific prompt and hands it to /loop.

/skill:shepherd <goal to shepherd>

Differences vs Claude Code /loop

Claude Code pi /loop
Scheduler built-in CronCreate (in-process, session-scoped) in-session timer, single steer delivery
Survives model stall yes (cron fires between turns) yes (steer injects into a busy turn)
Survives restart no (restored on --resume) no (re-armed on /resume via session entry)
Interval cron granularity, 1m–7d any ≥15s, no expiry
Dynamic interval yes (model picks delay) no — fixed interval only
Jitter yes (deterministic offset) no

Development

npm install
npm run typecheck
npm test            # offline tests, one file at a time, each with an isolated HOME
npm run test:e2e    # real pi session and a model (~60s)
npm pack --dry-run

npm test runs tests/run.mjs, the shared runner of @maheidem/pi-panel-kit/testing. It needs Node 22.18 or newer. It does not start a live pi.

npm run test:e2e runs tests/e2e.mjs. It needs a working default model. It uses PI_BIN, else ~/.local/bin/pi, else pi from PATH. Each pi call has a time limit. It leaves a session file in /tmp/loop-e2e/.

The shepherd skill source is skills/shepherd/SKILL.md. The pi manifest lists only the extension. With a plain package entry in packages, pi does not load the skill from the package. Copy the file to ~/.pi/agent/skills/shepherd/ after an edit.

Files:

  • extensions/index.ts — the extension: /loop command, loop tool, timer, steer delivery, catch-up, tick renderer
  • extensions/metadata.ts — COMMAND_NAME
  • extensions/state.ts — pure helpers: interval parsing, tick provenance line, state
  • extensions/ui/loop-panel.ts — Pi-free dashboard view model
  • extensions/version.ts — thin wrapper of extensionVersion
  • skills/shepherd/SKILL.md — the shepherd skill (a consumer of /loop)

The panel and the version helper come from @maheidem/pi-panel-kit.

License

MIT. See LICENSE.