Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix(skill): first-run NUX gaps (welcome skipped, install list, device code, already-linked) (#746)

Matt Van Horn47b924c87ff3
diff --git a/skills/last30days/SKILL.md b/skills/last30days/SKILL.md
index 4daeac03..25c60f80 100644
--- a/skills/last30days/SKILL.md
+++ b/skills/last30days/SKILL.md
@@ -417,7 +417,7 @@ The engine reads `LAST30DAYS_MEMORY_DIR` from either the process env or `~/.conf
**Follow these steps IN ORDER. Do NOT skip ahead to research. The sequence is: (1) welcome text → (2) setup modal → (3) run setup if chosen → (4) ScrapeCreators offer modal → (5) source opt-in modal → (6) first-topic picker. Start at step 1.**
-**Step 1 - Welcome.** Display this welcome text ONCE as a normal message (not blockquoted).
+**Step 1 - Welcome (REQUIRED FIRST — do not skip).** You MUST output this welcome text as a normal chat message (not blockquoted) BEFORE calling any AskUserQuestion modal. Skipping the welcome and jumping straight to the setup modal is a bug. Display it ONCE.
Welcome to /last30days!
@@ -437,11 +437,11 @@ Want TikTok and Instagram too? ScrapeCreators adds those (10,000 free calls, scr
Power users can turn on more sources in the Manual Setup guide (LinkedIn, Bluesky, Perplexity, and others) - each needs its own credential, so they are off by default.
-**Step 2 - Setup choice.** Then IMMEDIATELY call AskUserQuestion with ONLY this question and these options (do not repeat the welcome text inside the modal):
+**Step 2 - Setup choice.** After the welcome message from Step 1 has been shown, call AskUserQuestion with ONLY this question and these options (do not repeat the welcome text inside the modal):
Question: "How would you like to set up?"
Options:
-- "Auto setup (~30 seconds) - scans browser cookies for X + installs yt-dlp (YouTube) and the Digg CLI"
+- "Auto setup (~30 seconds) - scans browser cookies for X + installs yt-dlp (YouTube), Digg, arXiv, and Techmeme CLIs"
- "Manual setup - show me what to configure"
- "Skip for now - Reddit (with comments), HN, Polymarket, GitHub (if `gh` installed), Web"
@@ -471,8 +471,17 @@ Before the modal, run `which gh` via Bash silently; store as gh_available.
**Call AskUserQuestion:**
Question: "Want to add TikTok and Instagram? Your key also keeps Reddit and YouTube working when they hit rate limits. (We don't get a cut.)"
Options:
-- "ScrapeCreators via GitHub (recommended - most free calls)" - description: "Opens GitHub, you enter a short code (~20-30s). Grants the full 10,000 free calls - more than the web signup." (Recommend this over the web option because the GitHub path grants more free calls.) After selection, tell the user: "GitHub will ask for a short code - I'll show it to you in a moment." Then **run `setup --github` in the BACKGROUND** (do not block the foreground): `"${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/last30days.py setup --github` with a 5-minute timeout, run in the background. **Poll its stdout every ~2-3 seconds** and, the moment a line of the form `{"event":"device_code_ready","user_code":"XXXX-XXXX","verification_uri":"..."}` appears, immediately show the user their code and the URL: "Enter this code on the GitHub page: **XXXX-XXXX** (also copied to your clipboard)." Do NOT wait for the process to finish before showing the code - that is the bug this fixes. When the process exits, parse the **LAST** JSON line of stdout for the final status (stdout carries the early `device_code_ready` line plus the final status blob). On `status == "success"` the engine persists the key automatically and returns `"persisted": true` with a MASKED `api_key` (the raw key never appears - do not ask for or echo it); confirm "You're in! 10,000 free calls. TikTok, Instagram, and the Reddit/YouTube backups are now active." On `status == "already_registered"`, tell the user "You're already set up - your existing ScrapeCreators key is active." On `status == "success"` but `"persisted": false` (key write failed, e.g. a permissions error), do NOT claim sources are active - tell the user the signup worked but saving the key failed, and have them add `SCRAPECREATORS_API_KEY=<key>` to `~/.config/last30days/.env` manually (the raw key is masked in output, so re-run `setup --github` or retrieve it from scrapecreators.com to get the value). On `status` `timeout`/`denied`/`error`, show "GitHub auth didn't complete - no worries, sign up at scrapecreators.com or try again later," then offer the web option below.
- - **Host without background execution** (can't background a Bash process): run `setup --github` in the foreground, but tell the user first: "A short code will appear - watch for it and enter it on the GitHub page that opens." The engine prints the `device_code_ready` line and the code box to the terminal.
+- "ScrapeCreators via GitHub (recommended - most free calls)" - description: "Opens GitHub, you paste a short code (~20-30s). Grants the full 10,000 free calls - more than the web signup." (Recommend this over the web option because the GitHub path grants more free calls.) Run this device-code flow **IN ORDER — the steps are numbered because step 3 is the one that keeps getting skipped:**
+ 1. **Tell the user upfront** (chat message): "GitHub is opening in your browser. Your one-time code will be on your clipboard - on that page, just paste it (Cmd+V) and click Continue."
+ 2. **Run in the BACKGROUND** (do not block the foreground): `"${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/last30days.py setup --github` with a 5-minute timeout, in the background.
+ 3. **Read the code, then STOP and SHOW IT.** Poll its stdout every ~2-3 seconds until a line of the form `{"event":"device_code_ready","user_code":"XXXX-XXXX","verification_uri":"..."}` appears. The MOMENT it appears, output ONE chat message to the user: "Enter this code on the GitHub page: **XXXX-XXXX** - it's already on your clipboard, so just paste (Cmd+V) and click Continue." This is a **REQUIRED** step: do NOT skip it, and do NOT fold it into the completion-wait loop. Surfacing the code is the entire point of this flow.
+ 4. **Then** wait for the process to exit and parse the **LAST** JSON line of stdout for the final status (stdout carries the early `device_code_ready` line plus the final status blob). Handle it:
+ - `status == "success"`: the engine persisted the key (`"persisted": true`, MASKED `api_key` - never ask for or echo the raw key); confirm "You're in! 10,000 free calls. TikTok, Instagram, and the Reddit/YouTube backups are now active."
+ - `status == "already_registered"`: "You're already set up - your existing ScrapeCreators key is active."
+ - `status == "success"` but `"persisted": false` (key write failed): do NOT claim sources are active - tell the user signup worked but saving the key failed, and have them add `SCRAPECREATORS_API_KEY=<key>` to `~/.config/last30days/.env` manually (the key is masked in output; re-run `setup --github` or get it from scrapecreators.com).
+ - `status == "error"` **with `message == "Authorized but failed to fetch API key"`**: GitHub authorized fine - do NOT say auth failed. This usually means your GitHub is **already linked** to a ScrapeCreators account. Tell the user: "GitHub authorized, but I couldn't auto-grab your ScrapeCreators key - your GitHub is probably already linked to an account. Get your key at scrapecreators.com and paste it here, or Skip." Then accept a pasted key (write `SCRAPECREATORS_API_KEY` to `.env`) or offer the web/skip options.
+ - `status == "timeout"`, or any other `status == "error"` message: show "GitHub auth didn't complete - no worries, sign up at scrapecreators.com or try again later," then offer the web option below.
+ - **Host without background execution** (can't background a Bash process): run `setup --github` in the foreground, but tell the user first: "A short code will appear - your clipboard will have it, so just paste (Cmd+V) on the GitHub page that opens." The engine prints the `device_code_ready` line and the code box to the terminal.
- "Open scrapecreators.com (Google sign-in)" - run `open https://scrapecreators.com` via Bash, then ask them to paste the API key. Write `SCRAPECREATORS_API_KEY={key}` to `~/.config/last30days/.env`.
- "I have a key" - accept the key, write to `.env`.
- "Skip for now" - proceed without ScrapeCreators. No TikTok/Instagram, and no ScrapeCreators backup if Reddit or YouTube get rate-limited (your free sources still work).
@@ -520,9 +529,11 @@ For hosts without interactive modal prompts (OpenClaw, Codex, Cursor, Gemini CLI
**5. ScrapeCreators signup offer (every first run, consent BEFORE launching the browser).** Explain it grants 10,000 free calls that add TikTok and Instagram, plus a backup that keeps Reddit and YouTube working when they hit rate limits (a Reddit backup and a YouTube transcript fallback), that GitHub signup grants the full 10,000 free calls (more than the web form), and that it opens a GitHub authorization page where you enter a short code. Ask, e.g.: `Want to unlock TikTok, Instagram, and more? I can sign you up for ScrapeCreators with GitHub (10,000 free calls, ~20-30s) - it opens a browser and you enter a short code. (yes / no)` **Wait for the answer.**
- On **yes** → run `"${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/last30days.py setup --github`. If your host can background a process, run it in the background and poll its stdout; the moment a `{"event":"device_code_ready","user_code":"XXXX-XXXX",...}` line appears, show the user the code and the GitHub URL immediately (do not wait for the process to finish). If you cannot background, run it in the foreground and tell the user to watch for the short code the engine prints, then enter it on the GitHub page. When the process exits, parse the **LAST** JSON line of stdout for the final status. On success the engine persists the key automatically and returns `"persisted": true` with a MASKED `api_key` (never ask for or echo the raw key). Confirm the paid sources are active.
+ - Also, right after backgrounding, tell the user the code is on their clipboard so they can just paste it (Cmd+V) on the GitHub page - do not make them hunt for it.
- On **`status == "already_registered"`** → tell the user they are already set up; their existing key is active.
- On **success but `"persisted": false`** (auth completed yet the key write failed) → do NOT claim sources are active. Tell the user signup worked but saving failed, and have them add `SCRAPECREATORS_API_KEY=<key>` to `~/.config/last30days/.env` manually (the raw key is masked in output, so re-run `setup --github` or retrieve it from scrapecreators.com to get the value).
- - On **timeout / denied** → tell the user it didn't complete and offer to retry or the web signup at scrapecreators.com.
+ - On **`status == "error"` with `message == "Authorized but failed to fetch API key"`** → GitHub authorized fine, so do NOT say auth failed. This usually means the GitHub account is already linked to a ScrapeCreators account. Tell the user: "GitHub authorized, but I couldn't auto-grab your ScrapeCreators key - your GitHub is probably already linked to an account. Get your key at scrapecreators.com and paste it, or Skip." Accept a pasted key or offer web/skip.
+ - On **timeout, or any other error** → tell the user it didn't complete and offer to retry or the web signup at scrapecreators.com.
- On **no** → note they can run it later by asking to set up ScrapeCreators, then continue.
**5b. Source tier (only if a key was saved).** Your key runs TikTok and Instagram on every search plus the Reddit/YouTube backups. Ask whether they want more, e.g.: `Want just TikTok + Instagram (recommended), or Everything - also Threads, Pinterest, and comment sentiment (more credits per run)? (recommended / everything)` **Wait for the answer.**
diff --git a/skills/last30days/scripts/lib/setup_wizard.py b/skills/last30days/scripts/lib/setup_wizard.py
index c114670d..30f11b46 100644
--- a/skills/last30days/scripts/lib/setup_wizard.py
+++ b/skills/last30days/scripts/lib/setup_wizard.py
@@ -813,7 +813,18 @@ def fetch_api_key(access_token: str) -> Optional[str]:
logger.warning("Failed to fetch API key: %s", exc)
return None
- return data.get("api_key")
+ api_key = data.get("api_key")
+ if not api_key:
+ # The /profile response parsed but carried no api_key — the common case
+ # for a GitHub account already linked to a ScrapeCreators account. Log
+ # the response's FIELD NAMES only (never values — the body may contain a
+ # key under a different field) so the already-registered response shape
+ # can be handled in a follow-up (see plan OQ1).
+ logger.warning(
+ "Device auth /profile returned no api_key (fields: %s)", sorted(data.keys())
+ )
+ return None
+ return api_key
def run_full_device_auth(timeout: int = 300) -> Dict[str, Any]:
diff --git a/tests/test_github_device_auth.py b/tests/test_github_device_auth.py
index c2202223..34343cc6 100644
--- a/tests/test_github_device_auth.py
+++ b/tests/test_github_device_auth.py
@@ -10,7 +10,7 @@ All hermetic — the network, clipboard, and browser are patched.
import io
import json
from contextlib import redirect_stdout
-from unittest.mock import patch
+from unittest.mock import MagicMock, patch
from lib import setup_wizard
@@ -103,3 +103,26 @@ class TestAlreadyRegistered:
masked = setup_wizard.mask_api_key("sc_live_realkey1234567890")
assert "realkey" not in masked
assert masked != "sc_live_realkey1234567890"
+
+
+class TestFetchApiKeyLogging:
+ """U4: the /profile no-key path logs field NAMES only, never values."""
+
+ @patch("lib.setup_wizard.logger")
+ @patch("lib.setup_wizard.urlopen")
+ def test_no_key_logs_field_names_not_values(self, mock_urlopen, mock_logger):
+ # An already-linked account: /profile parses but carries no api_key,
+ # and could carry a secret under another field (here, "token").
+ body = json.dumps({"linked": True, "token": "sc_secret_value_xyz"}).encode()
+ resp = MagicMock()
+ resp.read.return_value = body
+ resp.__enter__.return_value = resp
+ mock_urlopen.return_value = resp
+
+ result = setup_wizard.fetch_api_key("gh_access_token")
+
+ assert result is None
+ # The warning must include the field names but never the secret value.
+ logged = " ".join(str(c) for c in mock_logger.warning.call_args_list)
+ assert "linked" in logged and "token" in logged
+ assert "sc_secret_value_xyz" not in logged
diff --git a/tests/test_onboarding_contract.py b/tests/test_onboarding_contract.py
index 03888520..3442effb 100644
--- a/tests/test_onboarding_contract.py
+++ b/tests/test_onboarding_contract.py
@@ -126,8 +126,8 @@ class TestOnboardingContract(unittest.TestCase):
self.assertIn("Digg", self.modal)
self.assertIn("Digg", self.prose)
self.assertIn("Digg", self.manual)
- # The Auto-setup modal option names both tools together.
- self.assertIn("yt-dlp (YouTube) and the Digg CLI", self.modal)
+ # The Auto-setup modal option names every installed CLI, not just two.
+ self.assertIn("yt-dlp (YouTube), Digg, arXiv, and Techmeme CLIs", self.modal)
# --- Credit count = 10,000, no conflicting numbers in onboarding ---
@@ -199,6 +199,40 @@ class TestOnboardingContract(unittest.TestCase):
self.assertIn("already_registered", self.modal)
self.assertIn("already_registered", self.prose)
+ # --- Welcome must render before the modal (U1) ---
+
+ def test_welcome_is_required_before_modal(self):
+ """Step 1 mandates the welcome message before any modal; the old
+
+ 'IMMEDIATELY call AskUserQuestion' wording (which induced skipping the
+ welcome) is gone.
+ """
+ self.assertIn("REQUIRED FIRST", self.modal)
+ self.assertIn("BEFORE calling any AskUserQuestion", self.modal)
+ self.assertNotIn("Then IMMEDIATELY call AskUserQuestion", self.modal)
+
+ # --- Device code surfaced with a clipboard-paste hint (U3) ---
+
+ def test_device_code_clipboard_paste_instruction(self):
+ """The GitHub flow tells the user the code is on their clipboard to paste,
+
+ and makes surfacing the code a required step (the bug the user hit).
+ """
+ self.assertIn("on your clipboard", self.modal)
+ self.assertIn("paste", self.modal.lower()[self.modal.find("device_code_ready"):])
+ self.assertIn("REQUIRED", self.modal)
+
+ # --- Honest 'authorized but no key' branch, distinct from auth-failed (U4) ---
+
+ def test_authorized_but_no_key_branch_present(self):
+ """A key-fetch failure after successful auth is handled honestly (likely
+
+ an already-linked account), not lumped into 'auth didn't complete'.
+ """
+ for slice_name, slice_text in (("modal", self.modal), ("prose", self.prose)):
+ self.assertIn("Authorized but failed to fetch API key", slice_text, slice_name)
+ self.assertIn("already linked", slice_text, slice_name)
+
# --- Legacy guarantees retained ---
def test_old_silent_wizard_instruction_removed(self):