feat(persona): add proactive check-in loop with EST quiet-hours and Prime personality

This commit is contained in:
Prime Backup Bot
2026-03-11 21:46:24 +00:00
parent c44cfd4f3d
commit 85c6f72e80
4 changed files with 100 additions and 0 deletions
+9
View File
@@ -89,3 +89,12 @@ Owner (configured `TELEGRAM_CHAT_ID`) can manage list:
- `allowlist remove <telegram_user_id>`
Owner cannot be removed from allowlist.
## 12) Prime proactive check-in loop
Service: `prime-checkin-loop.service`
Behavior:
- Sends proactive check-ins every ~3 hours
- Asks for goal/task direction when queue is clear
- Quiet hours enforced: 11:00 PM–6:00 AM America/New_York
- Personality: calm, strategic, concise (`prime_core/personality.py`)
+77
View File
@@ -0,0 +1,77 @@
from __future__ import annotations
import json
import time
from pathlib import Path
from datetime import datetime
from zoneinfo import ZoneInfo
from .notify import send_telegram
from .queue import list_items
from .personality import format_checkin
STATE = Path('/srv/prime-core/state/checkin-state.json')
GOALS = Path('/srv/prime-core/state/goals.json')
TZ = ZoneInfo('America/New_York')
QUIET_START = 23
QUIET_END = 6
def quiet_hours_now() -> bool:
hr = datetime.now(TZ).hour
return hr >= QUIET_START or hr < QUIET_END
def load_json(path: Path, default):
if not path.exists():
return default
try:
return json.loads(path.read_text())
except Exception:
return default
def save_state(s: dict):
STATE.parent.mkdir(parents=True, exist_ok=True)
STATE.write_text(json.dumps(s, indent=2))
def summarize() -> str:
items = list_items()
goals = load_json(GOALS, [])
queued = sum(1 for i in items if i.get('status') == 'queued')
blocked = sum(1 for i in items if i.get('status') == 'blocked_approval')
done = sum(1 for i in items if i.get('status') == 'done')
if not goals:
return "I don’t have active goals yet. Want to set one? (`goals add <text>`)")
if queued == 0 and blocked == 0:
return f"Current goals: {len(goals)}. Queue is clear. Want me to advance a specific goal next?"
return f"Goals: {len(goals)} | queued: {queued} | blocked: {blocked} | done: {done}."
def maybe_checkin():
if quiet_hours_now():
return
st = load_json(STATE, {'last_checkin_ts': 0})
now = int(time.time())
# periodic check-in every 3 hours outside quiet window
if now - int(st.get('last_checkin_ts', 0)) < 10800:
return
msg = format_checkin(summarize())
if send_telegram(msg):
st['last_checkin_ts'] = now
save_state(st)
def loop():
while True:
maybe_checkin()
time.sleep(300)
if __name__ == '__main__':
loop()
+10
View File
@@ -0,0 +1,10 @@
PERSONA = {
'name': 'Prime',
'voice': 'calm, strategic, concise, slightly witty',
'style': 'action-first, clear status, no fluff',
'emoji': '🧠'
}
def format_checkin(body: str) -> str:
return f"🧠 Prime check-in\n{body}"
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
cd /srv/prime-core
exec python3 -m prime_core.checkin_loop