Merge pull request #74 from Yif-Yang/fix/python-path-and-lookback
fix: SKILLOPT_SLEEP_PYTHON override + lookback_hours first-run fallback
This commit is contained in:
@@ -30,12 +30,17 @@ if [ -z "${REPO_ROOT:-}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
PY=""
|
PY=""
|
||||||
|
# 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
|
for cand in python3.12 python3.11 python3.10 python3; do
|
||||||
if command -v "$cand" >/dev/null 2>&1; then
|
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)"
|
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
|
if [ "${ver:-0}" -ge 310 ]; then PY="$cand"; break; fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
if [ -z "$PY" ]; then
|
if [ -z "$PY" ]; then
|
||||||
echo "[sleep] ERROR: need Python >= 3.10 (found none)." >&2
|
echo "[sleep] ERROR: need Python >= 3.10 (found none)." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -30,12 +30,17 @@ if [ -z "${REPO_ROOT:-}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
PY=""
|
PY=""
|
||||||
|
# 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
|
for cand in python3.12 python3.11 python3.10 python3; do
|
||||||
if command -v "$cand" >/dev/null 2>&1; then
|
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)"
|
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
|
if [ "${ver:-0}" -ge 310 ]; then PY="$cand"; break; fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
if [ -z "$PY" ]; then
|
if [ -z "$PY" ]; then
|
||||||
echo "[sleep] ERROR: need Python >= 3.10 (found none)." >&2
|
echo "[sleep] ERROR: need Python >= 3.10 (found none)." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -76,7 +76,8 @@ def _add_common(p: argparse.ArgumentParser) -> None:
|
|||||||
p.add_argument("--codex-home", default="", help="override ~/.codex for archived session harvest")
|
p.add_argument("--codex-home", default="", help="override ~/.codex for archived session harvest")
|
||||||
p.add_argument("--source", default="", choices=["", "claude", "codex", "auto"],
|
p.add_argument("--source", default="", choices=["", "claude", "codex", "auto"],
|
||||||
help="session transcript source")
|
help="session transcript source")
|
||||||
p.add_argument("--lookback-hours", type=int, default=0)
|
p.add_argument("--lookback-hours", type=int, default=None,
|
||||||
|
help="harvest window in hours; 0 = scan full history")
|
||||||
p.add_argument("--edit-budget", type=int, default=0)
|
p.add_argument("--edit-budget", type=int, default=0)
|
||||||
p.add_argument("--max-sessions", type=int, default=0,
|
p.add_argument("--max-sessions", type=int, default=0,
|
||||||
help="cap harvested sessions before mining; default derives from max tasks")
|
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:
|
|||||||
overrides["codex_home"] = os.path.abspath(args.codex_home)
|
overrides["codex_home"] = os.path.abspath(args.codex_home)
|
||||||
if getattr(args, "source", ""):
|
if getattr(args, "source", ""):
|
||||||
overrides["transcript_source"] = args.source
|
overrides["transcript_source"] = args.source
|
||||||
if getattr(args, "lookback_hours", 0):
|
lh = getattr(args, "lookback_hours", None)
|
||||||
overrides["lookback_hours"] = args.lookback_hours
|
if lh is not None: # --lookback-hours was explicitly passed (0 = full history)
|
||||||
|
overrides["lookback_hours"] = lh
|
||||||
if getattr(args, "edit_budget", 0):
|
if getattr(args, "edit_budget", 0):
|
||||||
overrides["edit_budget"] = args.edit_budget
|
overrides["edit_budget"] = args.edit_budget
|
||||||
if getattr(args, "max_sessions", 0):
|
if getattr(args, "max_sessions", 0):
|
||||||
|
|||||||
@@ -144,6 +144,15 @@ def run_sleep_cycle(
|
|||||||
_progress(cfg, f"using {len(tasks)} seeded tasks")
|
_progress(cfg, f"using {len(tasks)} seeded tasks")
|
||||||
else:
|
else:
|
||||||
since = state.last_harvest_for(project)
|
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 is not None and lookback_hours > 0:
|
||||||
|
import time
|
||||||
|
ref_time = clock if clock is not None else time.time()
|
||||||
|
cutoff = ref_time - lookback_hours * 3600
|
||||||
|
since = _now_iso(cutoff)
|
||||||
max_tasks = cfg.get("max_tasks_per_night", 40)
|
max_tasks = cfg.get("max_tasks_per_night", 40)
|
||||||
max_sessions = cfg.get("max_sessions_per_night", 0) or max_tasks * 3
|
max_sessions = cfg.get("max_sessions_per_night", 0) or max_tasks * 3
|
||||||
candidate_limit = max_tasks
|
candidate_limit = max_tasks
|
||||||
|
|||||||
@@ -294,6 +294,9 @@ def harvest(
|
|||||||
if not _project_matches(d.project or "", scope, invoked_project):
|
if not _project_matches(d.project or "", scope, invoked_project):
|
||||||
continue
|
continue
|
||||||
if since_iso and d.ended_at and d.ended_at < since_iso:
|
if since_iso and d.ended_at and d.ended_at < since_iso:
|
||||||
|
# Note: files are sorted by mtime but we compare the embedded
|
||||||
|
# ended_at timestamp — mtime can diverge (copy/touch), so we
|
||||||
|
# cannot break here; we must continue to check all files.
|
||||||
continue
|
continue
|
||||||
digests.append(d)
|
digests.append(d)
|
||||||
if limit and len(digests) >= limit:
|
if limit and len(digests) >= limit:
|
||||||
|
|||||||
Reference in New Issue
Block a user