3.1 KiB
Phase 5 — Emit /schedule create command
Render the ready-to-paste nightly trigger and ask whether to run it now, copy and do later, or skip to local-only mode.
5a — Load template
Read _primitives/templates/sleep-trigger-prompt.md from the kit install
path:
~/.claude/agents/_primitives/templates/sleep-trigger-prompt.md
If the file is missing (older kit version), fall back to the inline template in this phase file (see 5e).
5b — Compute UTC cron
Local target: 03:00 user-local time, every day.
# macOS / GNU date — detect local TZ offset in minutes
offset_min=$(date +%z | awk '{ s=substr($0,1,1); h=substr($0,2,2); m=substr($0,4,2); print (s=="-" ? 1 : -1) * (h*60+m) }')
# local 03:00 = 180 minutes past midnight local
local_minutes=180
utc_minutes=$(( (local_minutes + offset_min + 1440) % 1440 ))
utc_hour=$(( utc_minutes / 60 ))
utc_min=$(( utc_minutes % 60 ))
utc_cron=$(printf '%d %d * * *' "$utc_min" "$utc_hour")
Keep arithmetic in the skill prompt if Claude Code executes shell; otherwise have Claude compute the offset directly.
5c — Render placeholders
Replace {REPO_URL} with REPO_URL and {UTC_CRON} with utc_cron in
the template. Print the rendered prompt to chat inside a fenced code
block so the user can one-click-copy.
5d — Click
Emit ONE AskUserQuestion:
{
"questions": [
{
"question": "How should we register the nightly REM trigger?",
"header": "Schedule",
"multiSelect": false,
"options": [
{"label": "Run /schedule now", "description": "Invoke /schedule create with the rendered prompt"},
{"label": "Copy, run later", "description": "Leave it to me — I'll paste into /schedule create myself"},
{"label": "Skip (local-only)", "description": "Just push traces; no nightly consolidation"}
]
}
]
}
Handle:
Run now→ setSCHEDULE_ACTION = run-now; invoke/schedule createwith the rendered body.Copy later→ setSCHEDULE_ACTION = copy-later; print the body again and a one-line reminder.Skip→ setSCHEDULE_ACTION = skip; print the local-only footer from SKILL.md's "Final report".
5e — Fallback inline template (if kit missing the file)
If ~/.claude/agents/_primitives/templates/sleep-trigger-prompt.md is
absent, use this minimal inline prompt:
Clone: <REPO_URL>
At UTC <utc_cron>:
1. Clone shallow, read traces/ since reports/last-run.txt
2. Write reports/sleep-<date>.md with session + tool + error summary
3. If >=3 cross-session patterns, prepend to backlog.md
4. Commit + push to main
Invariants: append-only traces; no fabricated findings; never
paraphrase patent-sensitive content into report bodies.
Note the fallback is strictly less capable — loudly log "template file missing from kit install; using fallback" so the user can re-install.
Verify-criterion
- Exactly ONE
AskUserQuestion. - Rendered prompt contains no placeholder (
{REPO_URL}/{UTC_CRON}). SCHEDULE_ACTIONis one ofrun-now/copy-later/skip.- The final report block from SKILL.md is emitted with real values.