AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
Respect Keychain config in setup checks
Jeffrey Sperling96ab2e276be7
diff --git a/hooks/scripts/check-config.sh b/hooks/scripts/check-config.shindex 8a07d7a8..2d523fb3 100755--- a/hooks/scripts/check-config.sh+++ b/hooks/scripts/check-config.sh@@ -2,7 +2,8 @@set -euo pipefail# Check last30days configuration status and show appropriate welcome message.-# Priority: .claude/last30days.env > ~/.config/last30days/.env > env vars+# Priority for this status hook:+# .claude/last30days.env > ~/.config/last30days/.env > env vars > Keychain presencePROJECT_ENV=".claude/last30days.env"GLOBAL_ENV="$HOME/.config/last30days/.env"@@ -70,7 +71,36 @@ if [[ -n "$CONFIG_FILE" ]]; thenload_env_vars "$CONFIG_FILE"fi-# Check SETUP_COMPLETE (from file or env)+# Load Keychain item presence for status checks without reading secret values.+# Runtime credential resolution still happens in lib/env.py; this hook only+# needs to avoid stale first-run/source-count messages.+load_keychain_presence() {+ case "$(uname -s 2>/dev/null)" in+ Darwin*) ;;+ *) return 0 ;;+ esac+ command -v security >/dev/null 2>&1 || return 0++ local user key current+ user="${USER:-}"+ if [[ -z "$user" ]]; then+ user="$(id -un 2>/dev/null || true)"+ fi+ [[ -n "$user" ]] || return 0++ for key in SETUP_COMPLETE OPENAI_API_KEY SCRAPECREATORS_API_KEY AUTH_TOKEN CT0 XAI_API_KEY BSKY_HANDLE EXA_API_KEY; do+ eval "current=\"\${ENV_${key}:-\${${key}:-}}\""+ [[ -n "$current" ]] && continue+ if security find-generic-password -a "$user" -s "last30days-${key}" >/dev/null 2>&1; then+ printf -v "ENV_${key}" '%s' "keychain"+ fi+ done+ return 0+}++load_keychain_presence++# Check SETUP_COMPLETE (from file, env, or Keychain presence)SETUP_COMPLETE="${ENV_SETUP_COMPLETE:-${SETUP_COMPLETE:-}}"# Compute last-run summary line (if last-run.json exists)@@ -119,7 +149,7 @@ if command -v yt-dlp &>/dev/null; thenfi# If setup has never been run, show welcome message for new users-if [[ -z "$SETUP_COMPLETE" && -z "$CONFIG_FILE" && -z "${OPENAI_API_KEY:-}" && -z "${SCRAPECREATORS_API_KEY:-}" && -z "${AUTH_TOKEN:-}" && -z "${XAI_API_KEY:-}" ]]; then+if [[ -z "$SETUP_COMPLETE" && -z "$CONFIG_FILE" && -z "${ENV_OPENAI_API_KEY:-${OPENAI_API_KEY:-}}" && -z "${ENV_SCRAPECREATORS_API_KEY:-${SCRAPECREATORS_API_KEY:-}}" && -z "${ENV_AUTH_TOKEN:-${AUTH_TOKEN:-}}" && -z "${ENV_XAI_API_KEY:-${XAI_API_KEY:-}}" ]]; thenif [[ -n "$HAS_YTDLP" ]]; then# YouTube is already working via the on-system yt-dlp binary — don't list# it as something the wizard needs to unlock. See #394.diff --git a/skills/last30days/SKILL.md b/skills/last30days/SKILL.mdindex 96eefc64..03e39473 100644--- a/skills/last30days/SKILL.md+++ b/skills/last30days/SKILL.md@@ -340,8 +340,9 @@ The engine reads `LAST30DAYS_MEMORY_DIR` from either the process env or `~/.confBefore proceeding to Step 1, handle first-run setup.**First-run detection (silent, no commands, no output to user):**-- If `~/.config/last30days/.env` does NOT exist, this is a first run.-- If the file exists and contains `SETUP_COMPLETE=true`, skip Step 0 entirely and go to Step 1 (CRITICAL: Parse User Intent below). Do NOT announce that setup is complete. The user does not need a status message on every run.+- If `SETUP_COMPLETE=true` is available from process env, project config (`.claude/last30days.env`), global config (`~/.config/last30days/.env`), or the setup check reports configured credentials, skip Step 0 entirely and go to Step 1 (CRITICAL: Parse User Intent below). Do NOT announce that setup is complete. The user does not need a status message on every run.+- Do NOT treat the absence of `~/.config/last30days/.env` alone as a first run. Credentials may live in process env, project config, macOS Keychain (`last30days-<KEY>`), pass(1), or host-provided auth.+- If no setup marker or credential source is present, this is a first run.**If this IS a first run:**- Run `python3 skills/last30days/scripts/last30days.py setup` (relative to the skill root) to launch the setup wizard.diff --git a/skills/last30days/scripts/compare.sh b/skills/last30days/scripts/compare.shindex 880b5097..93aba198 100755--- a/skills/last30days/scripts/compare.sh+++ b/skills/last30days/scripts/compare.sh@@ -28,7 +28,7 @@ echo ""# Run 1: public releaseecho "[1/2] Running /last30days (public release)..."echo " This takes 2-4 minutes..."-claude -p --dangerously-skip-permissions "/last30days $TOPIC" > /dev/null 2>&1 || true+claude -p "/last30days $TOPIC" > /dev/null 2>&1 || trueRELEASE_FILE="$DIR/${SLUG}-raw.md"[ -f "$RELEASE_FILE" ] && echo " Done: $RELEASE_FILE" || echo " FAILED: no output file"echo ""@@ -39,7 +39,7 @@ sleep 30# Run 2: private betaecho "[2/2] Running /last30days-beta (private beta)..."echo " This takes 2-4 minutes..."-claude -p --dangerously-skip-permissions "/last30days-beta $TOPIC" > /dev/null 2>&1 || true+claude -p "/last30days-beta $TOPIC" > /dev/null 2>&1 || trueBETA_FILE="$DIR/${SLUG}-raw-beta.md"[ -f "$BETA_FILE" ] && echo " Done: $BETA_FILE" || echo " FAILED: no output file"echo ""diff --git a/tests/test_check_config_ytdlp_detection.py b/tests/test_check_config_ytdlp_detection.pyindex 7539b745..b07c548f 100644--- a/tests/test_check_config_ytdlp_detection.py+++ b/tests/test_check_config_ytdlp_detection.py@@ -44,8 +44,11 @@ def _run_hook(env_overrides: dict[str, str], path_override: str | None = None) -env.update(env_overrides)if path_override is not None:env["PATH"] = path_override+ bash_path = shutil.which("bash")+ if bash_path is None:+ pytest.skip("bash not on PATH")return subprocess.run(- ["bash", str(HOOK)],+ [bash_path, str(HOOK)],capture_output=True,text=True,env=env,@@ -53,12 +56,21 @@ def _run_hook(env_overrides: dict[str, str], path_override: str | None = None) -)-def _bash_dir() -> str:- """Directory containing the bash binary, so PATH overrides still let us run bash."""- bash_path = shutil.which("bash")- if bash_path is None:- pytest.skip("bash not on PATH")- return str(Path(bash_path).parent)+def _tool_path_without_ytdlp(tmp_path: Path) -> str:+ """Build a tiny PATH with hook dependencies but no yt-dlp."""+ tool_bin = tmp_path / "tool_bin"+ tool_bin.mkdir(exist_ok=True)+ for name in ("cat", "id", "mkdir", "python3", "sed", "stat", "tr", "uname"):+ target = shutil.which(name)+ if target is None:+ if name == "python3":+ continue+ pytest.skip(f"{name} not on PATH")+ link = tool_bin / name+ if not link.exists():+ link.symlink_to(target)+ assert shutil.which("yt-dlp", path=str(tool_bin)) is None+ return str(tool_bin)def _write_fake_last_run(tmp_path: Path) -> str:@@ -106,7 +118,7 @@ def test_new_user_with_ytdlp_says_youtube_works(tmp_path: Path):# PATH must contain bash (so the hook can run) AND the fake yt-dlp dir.# Putting fake_bin FIRST means any real yt-dlp elsewhere is shadowed.- path = f"{fake_bin}:{_bash_dir()}"+ path = f"{fake_bin}:{_tool_path_without_ytdlp(tmp_path)}"assert shutil.which("yt-dlp", path=path) is not None, ("test pre-condition: fake yt-dlp should resolve on the override PATH")@@ -134,7 +146,7 @@ def test_new_user_with_ytdlp_says_youtube_works(tmp_path: Path):@pytest.mark.skipif(shutil.which("bash") is None, reason="bash not on PATH")def test_new_user_without_ytdlp_unchanged_welcome(tmp_path: Path):"""A new user without yt-dlp should see the original wizard-unlock copy."""- path = _bash_dir()+ path = _tool_path_without_ytdlp(tmp_path)assert shutil.which("yt-dlp", path=path) is None, ("test pre-condition: yt-dlp should not resolve on the minimal PATH")@@ -171,7 +183,7 @@ def test_setup_done_user_source_count_includes_ytdlp(tmp_path: Path):fake_bin.mkdir()(fake_bin / "yt-dlp").touch()(fake_bin / "yt-dlp").chmod(0o755)- path_with = f"{fake_bin}:{_bash_dir()}"+ path_with = f"{fake_bin}:{_tool_path_without_ytdlp(tmp_path)}"assert shutil.which("yt-dlp", path=path_with) is not Nonewith_yt = _run_hook(base_env, path_override=path_with)@@ -179,7 +191,7 @@ def test_setup_done_user_source_count_includes_ytdlp(tmp_path: Path):count_with = _parse_source_count(with_yt.stdout)# 2) Run WITHOUT yt-dlp (minimal PATH)- path_without = _bash_dir()+ path_without = _tool_path_without_ytdlp(tmp_path)assert shutil.which("yt-dlp", path=path_without) is Nonewithout_yt = _run_hook(base_env, path_override=path_without)@@ -193,3 +205,51 @@ def test_setup_done_user_source_count_includes_ytdlp(tmp_path: Path):f"Stdout with: {with_yt.stdout!r}\n"f"Stdout without: {without_yt.stdout!r}")++[email protected](shutil.which("bash") is None, reason="bash not on PATH")+def test_keychain_credentials_avoid_new_user_welcome(tmp_path: Path):+ """macOS Keychain credentials should count as configured for the status hook."""+ fake_bin = tmp_path / "fake_bin_keychain"+ fake_bin.mkdir()++ uname = fake_bin / "uname"+ uname.write_text("#!/bin/sh\necho Darwin\n", encoding="utf-8")+ uname.chmod(0o755)++ security = fake_bin / "security"+ security.write_text(+ """#!/bin/sh+service=""+while [ "$#" -gt 0 ]; do+ if [ "$1" = "-s" ]; then+ service="$2"+ shift 2+ else+ shift+ fi+done+case "$service" in+ last30days-XAI_API_KEY|last30days-SCRAPECREATORS_API_KEY) exit 0 ;;+ *) exit 44 ;;+esac+""",+ encoding="utf-8",+ )+ security.chmod(0o755)++ cfg_dir = _write_fake_last_run(tmp_path)+ path = f"{fake_bin}:{_tool_path_without_ytdlp(tmp_path)}"+ result = _run_hook(+ {+ "HOME": str(tmp_path),+ "LAST30DAYS_CONFIG_DIR": cfg_dir,+ },+ path_override=path,+ )++ assert result.returncode == 0, f"hook failed: stderr={result.stderr!r}"+ assert "Ready to use. Run /last30days" not in result.stdout+ assert "Ready" in result.stdout+ assert "sources active" in result.stdout+ assert "Tip: Add ScrapeCreators" not in result.stdoutdiff --git a/tests/test_version_consistency.py b/tests/test_version_consistency.pyindex e8c6472a..19a5110b 100644--- a/tests/test_version_consistency.py+++ b/tests/test_version_consistency.py@@ -44,6 +44,11 @@ class TestVersionConsistency(unittest.TestCase):self.assertNotIn("--save-dir=~/Documents/Last30Days", skill_text)self.assertIn('--save-dir="${LAST30DAYS_MEMORY_DIR}"', skill_text)+ def test_compare_script_does_not_skip_permissions(self) -> None:+ compare_text = (SKILL_ROOT / "scripts" / "compare.sh").read_text(encoding="utf-8")++ self.assertNotIn("--dangerously-skip-permissions", compare_text)+def test_no_stray_hardcoded_memory_dir_paths(self) -> None:allowed_suffixes = {".md", ".py", ".sh", ".txt", ".yml", ".yaml", ".json"}skip_dirs = {".git", "assets", "fixtures", "docs"}