From 85c6f72e809ff0652047b4420b3305ce6ba80c6f Mon Sep 17 00:00:00 2001 From: Prime Backup Bot Date: Wed, 11 Mar 2026 21:46:24 +0000 Subject: [PATCH] feat(persona): add proactive check-in loop with EST quiet-hours and Prime personality --- docs/PRIME_BOOTSTRAP.md | 9 ++++ prime_core/checkin_loop.py | 77 +++++++++++++++++++++++++++++++++++ prime_core/personality.py | 10 +++++ scripts/start-checkin-loop.sh | 4 ++ 4 files changed, 100 insertions(+) create mode 100644 prime_core/checkin_loop.py create mode 100644 prime_core/personality.py create mode 100755 scripts/start-checkin-loop.sh diff --git a/docs/PRIME_BOOTSTRAP.md b/docs/PRIME_BOOTSTRAP.md index 1d36721..9c9423c 100644 --- a/docs/PRIME_BOOTSTRAP.md +++ b/docs/PRIME_BOOTSTRAP.md @@ -89,3 +89,12 @@ Owner (configured `TELEGRAM_CHAT_ID`) can manage list: - `allowlist remove ` 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`) diff --git a/prime_core/checkin_loop.py b/prime_core/checkin_loop.py new file mode 100644 index 0000000..67c32a8 --- /dev/null +++ b/prime_core/checkin_loop.py @@ -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 `)") + 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() diff --git a/prime_core/personality.py b/prime_core/personality.py new file mode 100644 index 0000000..cfd6ae7 --- /dev/null +++ b/prime_core/personality.py @@ -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}" diff --git a/scripts/start-checkin-loop.sh b/scripts/start-checkin-loop.sh new file mode 100755 index 0000000..f004217 --- /dev/null +++ b/scripts/start-checkin-loop.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -euo pipefail +cd /srv/prime-core +exec python3 -m prime_core.checkin_loop