From 889238b2345f88e60ce15b25b426072ff1b62b5e Mon Sep 17 00:00:00 2001 From: carpedkm Date: Sat, 20 Jun 2026 14:07:50 +0000 Subject: [PATCH] fix: add SKILLOPT_SLEEP_PYTHON override + lookback_hours first-run fallback Two fixes from issue #57 feedback: 1. run-sleep.sh: support SKILLOPT_SLEEP_PYTHON env var to explicitly set the Python interpreter. Useful on macOS where system Python is 3.9 but a newer Python is available elsewhere (e.g. Codex Desktop's bundled Python 3.12). Applied to both the shared runner and the bundled Claude Code plugin copy. 2. cycle.py: on first run (no prior harvest recorded), apply the lookback_hours config (default 72h) as a time cutoff. Previously, first run scanned the entire transcript history, which could trigger massive LLM mining on users with months of session data. Co-Authored-By: Claude Fable 5 --- plugins/claude-code/scripts/run-sleep.sh | 17 +++++++++++------ plugins/run-sleep.sh | 17 +++++++++++------ skillopt_sleep/cycle.py | 8 ++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/plugins/claude-code/scripts/run-sleep.sh b/plugins/claude-code/scripts/run-sleep.sh index e46e212..310d8de 100755 --- a/plugins/claude-code/scripts/run-sleep.sh +++ b/plugins/claude-code/scripts/run-sleep.sh @@ -30,12 +30,17 @@ if [ -z "${REPO_ROOT:-}" ]; then fi PY="" -for cand in python3.12 python3.11 python3.10 python3; do - if command -v "$cand" >/dev/null 2>&1; then - ver="$("$cand" -c 'import sys; print("%d%d" % sys.version_info[:2])' 2>/dev/null || echo 0)" - if [ "${ver:-0}" -ge 310 ]; then PY="$cand"; break; fi - fi -done +# Allow explicit Python override (useful on macOS with old system Python). +if [ -n "${SKILLOPT_SLEEP_PYTHON:-}" ]; then + PY="$SKILLOPT_SLEEP_PYTHON" +else + for cand in python3.12 python3.11 python3.10 python3; do + if command -v "$cand" >/dev/null 2>&1; then + ver="$("$cand" -c 'import sys; print("%d%d" % sys.version_info[:2])' 2>/dev/null || echo 0)" + if [ "${ver:-0}" -ge 310 ]; then PY="$cand"; break; fi + fi + done +fi if [ -z "$PY" ]; then echo "[sleep] ERROR: need Python >= 3.10 (found none)." >&2 exit 1 diff --git a/plugins/run-sleep.sh b/plugins/run-sleep.sh index e46e212..310d8de 100755 --- a/plugins/run-sleep.sh +++ b/plugins/run-sleep.sh @@ -30,12 +30,17 @@ if [ -z "${REPO_ROOT:-}" ]; then fi PY="" -for cand in python3.12 python3.11 python3.10 python3; do - if command -v "$cand" >/dev/null 2>&1; then - ver="$("$cand" -c 'import sys; print("%d%d" % sys.version_info[:2])' 2>/dev/null || echo 0)" - if [ "${ver:-0}" -ge 310 ]; then PY="$cand"; break; fi - fi -done +# Allow explicit Python override (useful on macOS with old system Python). +if [ -n "${SKILLOPT_SLEEP_PYTHON:-}" ]; then + PY="$SKILLOPT_SLEEP_PYTHON" +else + for cand in python3.12 python3.11 python3.10 python3; do + if command -v "$cand" >/dev/null 2>&1; then + ver="$("$cand" -c 'import sys; print("%d%d" % sys.version_info[:2])' 2>/dev/null || echo 0)" + if [ "${ver:-0}" -ge 310 ]; then PY="$cand"; break; fi + fi + done +fi if [ -z "$PY" ]; then echo "[sleep] ERROR: need Python >= 3.10 (found none)." >&2 exit 1 diff --git a/skillopt_sleep/cycle.py b/skillopt_sleep/cycle.py index 4678cff..e66f436 100644 --- a/skillopt_sleep/cycle.py +++ b/skillopt_sleep/cycle.py @@ -144,6 +144,14 @@ def run_sleep_cycle( _progress(cfg, f"using {len(tasks)} seeded tasks") else: since = state.last_harvest_for(project) + # On first run (no prior harvest), apply lookback_hours so we don't + # scan the entire transcript history and trigger massive LLM mining. + if since is None: + lookback_hours = cfg.get("lookback_hours", 72) + if lookback_hours and lookback_hours > 0: + import time + cutoff = time.time() - lookback_hours * 3600 + since = _now_iso(cutoff) max_tasks = cfg.get("max_tasks_per_night", 40) max_sessions = cfg.get("max_sessions_per_night", 0) or max_tasks * 3 candidate_limit = max_tasks