# 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. ```bash # 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`: ```json { "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` → set `SCHEDULE_ACTION = run-now`; invoke `/schedule create` with the rendered body. - `Copy later` → set `SCHEDULE_ACTION = copy-later`; print the body again and a one-line reminder. - `Skip` → set `SCHEDULE_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: At UTC : 1. Clone shallow, read traces/ since reports/last-run.txt 2. Write reports/sleep-.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_ACTION` is one of `run-now` / `copy-later` / `skip`. - The final report block from SKILL.md is emitted with real values.