← back to AbramsEgo

build-queue/done/20-cron-lastnext-run.md

30 lines

# AbramsEgo task 20 — cron cards: last/next run (SPEC panel 4 literal miss)

Read SPEC.md. Panel 4 spec text: "every scheduled job: status, schedule, **last/next run**, model."
The live cron grid (114 jobs) shows status pill + schedule + program + created 🕓 chip, but NO
last-run and NO next-run — the collector never computes them. Job fields today:
`label, loaded, pid, lastExit, state, schedule, program, created, modified` (verified live 2026-07-01).

Surgical, ~12 min, two touch points:

1. `server.js` — `readCronPlistMeta()` (~line 204) already parses `StartInterval` seconds and
   `StartCalendarInterval` Hour/Minute. Extend it:
   - `nextRun`: for `StartInterval s` → can't know phase, so emit `null` and let the UI show the
     interval; for calendar jobs → compute the next occurrence of `HH:MM` from now (today or
     tomorrow) as ISO. One small helper, no deps.
   - `lastRun` (best-effort): parse `StandardOutPath`/`StandardErrorPath` from the plist XML; if
     the file exists, `fs.statSync(...).mtimeMs` → ISO. Missing/no-log → `null`.
   - `model` (best-effort): regex the raw XML ProgramArguments for `--model\s*<\/string>\s*<string>([^<]+)`
     or a `claude-(opus|sonnet|haiku|fable)[\w.-]*` token; else `null`.
   Add `lastRun, nextRun, model` to the job object in `collectCrons()` (~line 252).
2. `public/index.html` — cron card render (~line 526): add one `.subcard-when` line
   `last ${whenChip(j.lastRun)||'—'} · next ${whenChip(j.nextRun)|| esc(j.schedule||'—')}` and, when
   `j.model` present, a small `<span class="pill">` with the model. Keep the existing created 🕓 chip.

Verify: `pm2 restart abramsego && sleep 3 && curl -s -u admin:'DW2024!' http://127.0.0.1:9773/api/data | node -e "const d=JSON.parse(require('fs').readFileSync(0));console.log(d.crons.jobs.filter(j=>j.lastRun||j.nextRun).length,'jobs with last/next run')"`
— expect a clearly nonzero count, and eyeball one calendar job's nextRun is in the future.

Commit: `git add -A && git commit -m "feat: cron cards show last/next run + model (SPEC panel 4)" --author="Steve <steve@designerwallcoverings.com>"`

Do NOT restyle other panels. Local only, no deploy.