Skip to content

Commit fc1f827

Browse files
authored
Merge pull request microsoft#74 from Yif-Yang/fix/python-path-and-lookback
fix: SKILLOPT_SLEEP_PYTHON override + lookback_hours first-run fallback
2 parents b5a1c2b + 01b3e01 commit fc1f827

5 files changed

Lines changed: 39 additions & 15 deletions

File tree

plugins/claude-code/scripts/run-sleep.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ if [ -z "${REPO_ROOT:-}" ]; then
3030
fi
3131

3232
PY=""
33-
for cand in python3.12 python3.11 python3.10 python3; do
34-
if command -v "$cand" >/dev/null 2>&1; then
35-
ver="$("$cand" -c 'import sys; print("%d%d" % sys.version_info[:2])' 2>/dev/null || echo 0)"
36-
if [ "${ver:-0}" -ge 310 ]; then PY="$cand"; break; fi
37-
fi
38-
done
33+
# Allow explicit Python override (useful on macOS with old system Python).
34+
if [ -n "${SKILLOPT_SLEEP_PYTHON:-}" ]; then
35+
PY="$SKILLOPT_SLEEP_PYTHON"
36+
else
37+
for cand in python3.12 python3.11 python3.10 python3; do
38+
if command -v "$cand" >/dev/null 2>&1; then
39+
ver="$("$cand" -c 'import sys; print("%d%d" % sys.version_info[:2])' 2>/dev/null || echo 0)"
40+
if [ "${ver:-0}" -ge 310 ]; then PY="$cand"; break; fi
41+
fi
42+
done
43+
fi
3944
if [ -z "$PY" ]; then
4045
echo "[sleep] ERROR: need Python >= 3.10 (found none)." >&2
4146
exit 1

plugins/run-sleep.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ if [ -z "${REPO_ROOT:-}" ]; then
3030
fi
3131

3232
PY=""
33-
for cand in python3.12 python3.11 python3.10 python3; do
34-
if command -v "$cand" >/dev/null 2>&1; then
35-
ver="$("$cand" -c 'import sys; print("%d%d" % sys.version_info[:2])' 2>/dev/null || echo 0)"
36-
if [ "${ver:-0}" -ge 310 ]; then PY="$cand"; break; fi
37-
fi
38-
done
33+
# Allow explicit Python override (useful on macOS with old system Python).
34+
if [ -n "${SKILLOPT_SLEEP_PYTHON:-}" ]; then
35+
PY="$SKILLOPT_SLEEP_PYTHON"
36+
else
37+
for cand in python3.12 python3.11 python3.10 python3; do
38+
if command -v "$cand" >/dev/null 2>&1; then
39+
ver="$("$cand" -c 'import sys; print("%d%d" % sys.version_info[:2])' 2>/dev/null || echo 0)"
40+
if [ "${ver:-0}" -ge 310 ]; then PY="$cand"; break; fi
41+
fi
42+
done
43+
fi
3944
if [ -z "$PY" ]; then
4045
echo "[sleep] ERROR: need Python >= 3.10 (found none)." >&2
4146
exit 1

skillopt_sleep/__main__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def _add_common(p: argparse.ArgumentParser) -> None:
7676
p.add_argument("--codex-home", default="", help="override ~/.codex for archived session harvest")
7777
p.add_argument("--source", default="", choices=["", "claude", "codex", "auto"],
7878
help="session transcript source")
79-
p.add_argument("--lookback-hours", type=int, default=0)
79+
p.add_argument("--lookback-hours", type=int, default=None,
80+
help="harvest window in hours; 0 = scan full history")
8081
p.add_argument("--edit-budget", type=int, default=0)
8182
p.add_argument("--max-sessions", type=int, default=0,
8283
help="cap harvested sessions before mining; default derives from max tasks")
@@ -111,8 +112,9 @@ def _cfg_from_args(args, task_meta: Dict[str, Any] | None = None) -> Any:
111112
overrides["codex_home"] = os.path.abspath(args.codex_home)
112113
if getattr(args, "source", ""):
113114
overrides["transcript_source"] = args.source
114-
if getattr(args, "lookback_hours", 0):
115-
overrides["lookback_hours"] = args.lookback_hours
115+
lh = getattr(args, "lookback_hours", None)
116+
if lh is not None: # --lookback-hours was explicitly passed (0 = full history)
117+
overrides["lookback_hours"] = lh
116118
if getattr(args, "edit_budget", 0):
117119
overrides["edit_budget"] = args.edit_budget
118120
if getattr(args, "max_sessions", 0):

skillopt_sleep/cycle.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ def run_sleep_cycle(
144144
_progress(cfg, f"using {len(tasks)} seeded tasks")
145145
else:
146146
since = state.last_harvest_for(project)
147+
# On first run (no prior harvest), apply lookback_hours so we don't
148+
# scan the entire transcript history and trigger massive LLM mining.
149+
if since is None:
150+
lookback_hours = cfg.get("lookback_hours", 72)
151+
if lookback_hours is not None and lookback_hours > 0:
152+
import time
153+
ref_time = clock if clock is not None else time.time()
154+
cutoff = ref_time - lookback_hours * 3600
155+
since = _now_iso(cutoff)
147156
max_tasks = cfg.get("max_tasks_per_night", 40)
148157
max_sessions = cfg.get("max_sessions_per_night", 0) or max_tasks * 3
149158
candidate_limit = max_tasks

skillopt_sleep/harvest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ def harvest(
294294
if not _project_matches(d.project or "", scope, invoked_project):
295295
continue
296296
if since_iso and d.ended_at and d.ended_at < since_iso:
297+
# Note: files are sorted by mtime but we compare the embedded
298+
# ended_at timestamp — mtime can diverge (copy/touch), so we
299+
# cannot break here; we must continue to check all files.
297300
continue
298301
digests.append(d)
299302
if limit and len(digests) >= limit:

0 commit comments

Comments
 (0)