KeiSeiKit-1.0/_primitives/templates/sleep-trigger-prompt.md

3.1 KiB
Raw Blame History

Nightly REM consolidation (KeiSeiKit v0.11 sleep-sync)

Clone: {REPO_URL} Branch: main Time: 03:00 local (UTC cron: {UTC_CRON})

Task

  1. Clone the memory repo shallow.

  2. Identify NEW traces in traces/ since the last consolidation by comparing filenames against reports/last-run.txt (if the file is missing, treat ALL traces as new on the first run).

  3. For each new trace (JSONL, one event per line), extract:

    • user prompts (role = "user", type = "message")
    • tool calls (type = "tool_use", name + input summary)
    • tool errors (is_error = true)
    • session duration (first vs last timestamp)
  4. Group events into topics via simple keyword matching on user prompts (no ML, no embeddings — keyword co-occurrence ≥ 2 is enough).

  5. Count recurring patterns: any tool-call sequence OR error class that appears in ≥ 2 distinct sessions is a "cross-session pattern".

  6. Write reports/sleep-YYYY-MM-DD.md with this structure:

    # REM report — YYYY-MM-DD
    
    Sessions analyzed: <count>
    Total duration:    <hh:mm>
    
    ## Top tool-call sequences (cross-session)
    1. <seq> ×<count>
    ...
    
    ## Top error classes
    1. <class> ×<count>
    ...
    
    ## Suggested rule/hook candidates (dry-run only)
    - [ ] <name> — why (<E-grade>)
    ...
    
  7. If there are ≥ 3 cross-session patterns, prepend a timestamped block to backlog.md:

    ## YYYY-MM-DD — REM consolidation
    - <pattern 1>
    - <pattern 2>
    - <pattern 3>
    
  8. Write a single line to reports/last-run.txt with this run's ISO-8601 UTC timestamp (overwrite, no append).

  9. Stage, commit, push:

    git add reports/ backlog.md
    git commit -m "REM: consolidation $(date -I)"
    git push
    

Invariants

  • Traces are append-only. Never delete or modify traces/*.jsonl.
  • If nothing recurred this cycle, the report MUST still be written — with body "no patterns this cycle" — so you can tell "ran and found nothing" apart from "did not run".
  • Never fabricate findings. If the analyzer outputs an empty list, emit an empty report.
  • Never paraphrase patent-sensitive content from the traces into the report body. Install a project-local pre-commit gate on the memory-repo if you want hard enforcement of that boundary.
  • Success signal = commit pushed cleanly. Anything else is a failure that surfaces to the user on the next git pull.

Failure handling

  • Clone fails → post an issue to the repo if possible; otherwise exit 1.
  • Commit hook blocks → do NOT force-push. Write the failure reason to reports/sleep-YYYY-MM-DD.md body and attempt a commit excluding the offending file.
  • Push fails → retry once with exponential backoff; on second failure, leave local commit in place and exit 1 (next run will push).