From 1930bd29bd517ee584da1b379317fd2a1b61ec1e Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Thu, 2 Apr 2026 12:20:19 -0700 Subject: [PATCH] fix: rotate challenge each session Stop hook clears active.challenge after reporting it. Start hook assigns a random challenge from the buddy's pool if none is set. Result: fresh challenge every session, no stale repeat. --- hooks-handlers/session-start.sh | 14 ++++++++++++++ hooks-handlers/session-stop.sh | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hooks-handlers/session-start.sh b/hooks-handlers/session-start.sh index 1d1937f..5ecf3fc 100755 --- a/hooks-handlers/session-start.sh +++ b/hooks-handlers/session-start.sh @@ -101,6 +101,20 @@ if ch: echo "${ctx}" } +# Assign a fresh challenge if none is set +python3 << PYEOF +import json, random +catalog = json.load(open('${CATALOG}')) +active_file = '${ACTIVE_FILE}' +active = json.load(open(active_file)) +buddy_id = active.get('buddymon_id') +if buddy_id and not active.get('challenge'): + pool = catalog.get('buddymon', {}).get(buddy_id, {}).get('challenges', []) + if pool: + active['challenge'] = random.choice(pool) + json.dump(active, open(active_file, 'w'), indent=2) +PYEOF + CONTEXT=$(build_context) # Escape for JSON diff --git a/hooks-handlers/session-stop.sh b/hooks-handlers/session-stop.sh index 9ad1ab4..07f5429 100755 --- a/hooks-handlers/session-stop.sh +++ b/hooks-handlers/session-stop.sh @@ -87,12 +87,13 @@ print('\n'.join(lines)) PYEOF ) -# Reset session XP counter for next session (keep total in roster) +# Reset session XP + clear challenge so next session assigns a fresh one python3 << PYEOF import json active_file = '${BUDDYMON_DIR}/active.json' active = json.load(open(active_file)) active['session_xp'] = 0 +active['challenge'] = None json.dump(active, open(active_file, 'w'), indent=2) PYEOF