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
fix: trust project config explicitly
Trevin Chow25cfced30596
diff --git a/CONFIGURATION.md b/CONFIGURATION.mdindex b6ec8a41..5f32b7f5 100644--- a/CONFIGURATION.md+++ b/CONFIGURATION.md@@ -69,14 +69,14 @@ Re-run onboarding by deleting `~/.config/last30days/.env`. The mechanical work l## API keys (`.env`)-The skill reads keys from a `.env` file. Two locations are supported, in priority order:+The skill reads keys from a `.env` file. Two locations are supported:-1. **`.claude/last30days.env`** in the current project directory (project-scoped) - takes precedence when present.-2. **`~/.config/last30days/.env`** at the user level (global default) - the fallback.+1. **`~/.config/last30days/.env`** at the user level (global default) - loaded by default.+2. **`.claude/last30days.env`** in the current project directory (project-scoped) - loaded only when trusted by setting `LAST30DAYS_TRUST_PROJECT_CONFIG=1` in the process environment or global config.Override the global location with `LAST30DAYS_CONFIG_DIR=/path` (or `LAST30DAYS_CONFIG_DIR=""` for no-config mode). File permissions should be `600` on POSIX hosts - the engine warns on every run if they aren't.-The project-scoped file is the cleanest pattern for **per-client setups**: drop a `.claude/last30days.env` into each client folder (`SCRAPECREATORS_API_KEY`, `INCLUDE_SOURCES`, `LAST30DAYS_MEMORY_DIR`, `BSKY_HANDLE`, etc), `cd` into that folder, and the skill picks up that client's configuration automatically. No wrapper scripts needed for the common case.+The project-scoped file is useful for **intentional per-client setups**: drop a `.claude/last30days.env` into each client folder (`SCRAPECREATORS_API_KEY`, `INCLUDE_SOURCES`, `LAST30DAYS_MEMORY_DIR`, `BSKY_HANDLE`, etc), then opt in with `LAST30DAYS_TRUST_PROJECT_CONFIG=1` from your shell or `~/.config/last30days/.env`. Folder-mode hosts such as Codex desktop do not trust hidden project config by default, and discovery stops at the git root so unrelated parent folders cannot silently influence runs.**Source-by-source** - what each key unlocks:@@ -144,7 +144,7 @@ BSKY_APP_PASSWORD=<your-app-password>After editing: `chmod 600 ~/.config/last30days/.env` (or `chmod 600 .claude/last30days.env` if using the project-scoped variant).-**Troubleshooting:** if a source you expected to see isn't appearing in results, run `python3 scripts/last30days.py --diagnose`. It prints a safe preflight report for source availability, config source, browser-cookie plan, external command availability, and write destinations without reading browser cookies or running live provider probes.+**Troubleshooting:** if a source you expected to see isn't appearing in results, run `python3 scripts/last30days.py --diagnose`. It prints a safe preflight report for source availability, config source, browser-cookie plan, external command availability, write destinations, and ignored untrusted project config without reading browser cookies or running live provider probes.### Perplexity source modes@@ -334,9 +334,9 @@ The schedule field stored on each topic is metadata - the actual cron / Task SchThe skill is built to flex around different client environments. Four patterns that compose well:-### 1. Per-client `.claude/last30days.env` (preferred when you cd into client folders)+### 1. Trusted per-client `.claude/last30days.env`-The simplest pattern when each client has its own working directory: drop a `.claude/last30days.env` into the client folder. The skill picks it up automatically (see [API keys](#api-keys-env) for the lookup priority). Typical contents:+When each client has its own working directory, drop a `.claude/last30days.env` into the client folder and opt in with `LAST30DAYS_TRUST_PROJECT_CONFIG=1` from your shell or global `~/.config/last30days/.env`. The skill loads the project file only after that trust signal. Typical contents:```bashLAST30DAYS_MEMORY_DIR=C:\Users\<you>\Clients\acme\Research\Last30Days@@ -345,7 +345,7 @@ INCLUDE_SOURCES=tiktok,instagramBSKY_HANDLE=<acme-bluesky-handle>.bsky.social```-`cd` into the client folder, run `/last30days <topic>` as normal, no flags or wrappers. Combine with `--save-suffix=<client-slug>` per run if you also need to differentiate filenames within that folder.+`cd` into the client folder, run `/last30days <topic>` as normal, no wrappers. Combine with `--save-suffix=<client-slug>` per run if you also need to differentiate filenames within that folder.### 2. Per-client save dir + suffix wrapperdiff --git a/skills/last30days/scripts/last30days.py b/skills/last30days/scripts/last30days.pyindex bc14ce4b..e45e0368 100644--- a/skills/last30days/scripts/last30days.py+++ b/skills/last30days/scripts/last30days.py@@ -651,7 +651,10 @@ def _config_policy_for_args(args: argparse.Namespace, topic: str, extra_argv: librowser_mode = "read" if _setup_allows_browser_cookies(args, extra_argv) else "off"else:browser_mode = "read"- return env.ConfigLoadPolicy(browser_cookies=browser_mode)+ return env.ConfigLoadPolicy(+ browser_cookies=browser_mode,+ inspect_ignored_project_config=args.diagnose,+ )def main() -> int:diff --git a/skills/last30days/scripts/lib/env.py b/skills/last30days/scripts/lib/env.pyindex 29d49499..7da9f971 100644--- a/skills/last30days/scripts/lib/env.py+++ b/skills/last30days/scripts/lib/env.py@@ -84,11 +84,29 @@ BrowserCookieMode = Literal["off", "read", "plan_only"]class ConfigLoadPolicy:"""Local-read gates for configuration loading.- Bare library calls use the safe default: no browser-cookie extraction. CLI- entry points can opt into narrower behavior after parsing command intent.+ Bare library calls use the safe default: no browser-cookie extraction and no+ project-scoped config. CLI entry points can opt into narrower behavior after+ parsing command intent."""browser_cookies: BrowserCookieMode = "off"+ allow_project_config: bool = False+ inspect_ignored_project_config: bool = False+++def _truthy(value: Any) -> bool:+ if value is None:+ return False+ return str(value).strip().lower() in {"1", "true", "yes", "on"}+++def _project_config_trusted(policy: ConfigLoadPolicy, file_env: dict[str, Any]) -> bool:+ if policy.allow_project_config:+ return True+ return _truthy(+ os.environ.get("LAST30DAYS_TRUST_PROJECT_CONFIG")+ or file_env.get("LAST30DAYS_TRUST_PROJECT_CONFIG")+ )def _check_file_permissions(path: Path) -> None:@@ -329,13 +347,15 @@ def _find_project_env() -> Path | None:"""Find per-project .env by walking up from cwd.Searches for .claude/last30days.env in each parent directory,- stopping at the user's home directory or filesystem root.+ stopping at the git root, user's home directory, or filesystem root."""cwd = Path.cwd()for parent in [cwd, *cwd.parents]:candidate = parent / '.claude' / 'last30days.env'if candidate.exists():return candidate+ if (parent / ".git").exists():+ break# Stop at filesystem root or homeif parent == Path.home() or parent == parent.parent:break@@ -347,7 +367,7 @@ def get_config(policy: ConfigLoadPolicy | None = None) -> dict[str, Any]:Priority (highest wins):1. Environment variables (os.environ)- 2. .claude/last30days.env (per-project config)+ 2. Trusted .claude/last30days.env (per-project config)3. ~/.config/last30days/.env (global config)4. macOS Keychain items prefixed ``last30days-`` (Darwin only)"""@@ -355,9 +375,18 @@ def get_config(policy: ConfigLoadPolicy | None = None) -> dict[str, Any]:# Load from global config filefile_env = load_env_file(CONFIG_FILE) if CONFIG_FILE else {}- # Load from per-project config (overrides global)- project_env_path = _find_project_env()+ # Load per-project config only when trust comes from process env, global+ # user config, or an explicit policy. A project file cannot grant trust to+ # itself because it is not parsed until after this decision.+ project_config_trusted = _project_config_trusted(policy, file_env)+ project_env_path = _find_project_env() if project_config_trusted else Noneproject_env = load_env_file(project_env_path) if project_env_path else {}+ ignored_project_env_path = None+ ignored_project_keys: list[str] = []+ if not project_config_trusted and policy.inspect_ignored_project_config:+ ignored_project_env_path = _find_project_env()+ if ignored_project_env_path:+ ignored_project_keys = sorted(load_env_file(ignored_project_env_path).keys())# Merge file sources: project > globalmerged_env = {**file_env, **project_env}@@ -444,6 +473,7 @@ def get_config(policy: ConfigLoadPolicy | None = None) -> dict[str, Any]:# Optional SearXNG instance for the keyless-search fallback rung.('LAST30DAYS_SEARXNG_URL', None),('FROM_BROWSER', None),+ ('LAST30DAYS_TRUST_PROJECT_CONFIG', None),('SETUP_COMPLETE', None),('INCLUDE_SOURCES', ''),('EXCLUDE_SOURCES', ''),@@ -491,7 +521,9 @@ def get_config(policy: ConfigLoadPolicy | None = None) -> dict[str, Any]:config['_CONFIG_SOURCE'] = 'pass'else:config['_CONFIG_SOURCE'] = 'env_only'-+ if ignored_project_env_path:+ config['_IGNORED_PROJECT_CONFIG'] = str(ignored_project_env_path)+ config['_IGNORED_PROJECT_CONFIG_KEYS'] = ignored_project_keysconfig['_BROWSER_COOKIE_MODE'] = policy.browser_cookiesconfig['_BROWSER_COOKIE_BROWSERS'] = cookie_extraction_browsers(config)diff --git a/skills/last30days/scripts/lib/pipeline.py b/skills/last30days/scripts/lib/pipeline.pyindex 7a9c8105..504eb04e 100644--- a/skills/last30days/scripts/lib/pipeline.py+++ b/skills/last30days/scripts/lib/pipeline.py@@ -203,6 +203,10 @@ def diagnose("browsers": list(config.get("_BROWSER_COOKIE_BROWSERS") or []),"reads_values": False if safe else config.get("_BROWSER_COOKIE_MODE") == "read",}+ ignored_project_keys = list(config.get("_IGNORED_PROJECT_CONFIG_KEYS") or [])+ ignored_endpoint_overrides = [+ key for key in ignored_project_keys if key in {"OPENAI_BASE_URL", "XAI_BASE_URL"}+ ]local_writes: list[dict[str, str]] = []if config.get("LAST30DAYS_MEMORY_DIR"):local_writes.append({"kind": "report", "path": str(config.get("LAST30DAYS_MEMORY_DIR"))})@@ -224,6 +228,9 @@ def diagnose("available_sources": available_sources(config, requested_sources),"safe": safe,"config_source": config.get("_CONFIG_SOURCE"),+ "ignored_project_config": config.get("_IGNORED_PROJECT_CONFIG"),+ "ignored_project_config_keys": ignored_project_keys,+ "ignored_endpoint_overrides": ignored_endpoint_overrides,"browser_cookies": browser_cookies,"external_commands": external_commands,"credential_destinations": credential_destinations,diff --git a/tests/test_project_config_trust.py b/tests/test_project_config_trust.pynew file mode 100644index 00000000..3e6157a5--- /dev/null+++ b/tests/test_project_config_trust.py@@ -0,0 +1,114 @@+"""Tests for trusted project-scoped configuration."""++from __future__ import annotations++from unittest import mock++from lib import env, pipeline+++def _neutral_secret_sources():+ return (+ mock.patch.object(env, "_load_keychain", return_value={}),+ mock.patch.object(env, "_load_pass", return_value={}),+ )+++def test_untrusted_project_config_is_ignored_by_default(tmp_path, monkeypatch):+ project_env = tmp_path / ".claude" / "last30days.env"+ project_env.parent.mkdir()+ project_env.write_text("XAI_API_KEY=xai-project\n", encoding="utf-8")+ monkeypatch.chdir(tmp_path)+ monkeypatch.setattr(env, "CONFIG_FILE", None)+ monkeypatch.delenv("LAST30DAYS_TRUST_PROJECT_CONFIG", raising=False)++ keychain, pass_store = _neutral_secret_sources()+ with keychain, pass_store:+ cfg = env.get_config()++ assert cfg["XAI_API_KEY"] is None+ assert cfg["_CONFIG_SOURCE"] == "env_only"+++def test_project_config_loads_with_global_trust_signal(tmp_path, monkeypatch):+ global_env = tmp_path / "global.env"+ global_env.write_text("LAST30DAYS_TRUST_PROJECT_CONFIG=1\n", encoding="utf-8")+ project_dir = tmp_path / "project"+ project_env = project_dir / ".claude" / "last30days.env"+ project_env.parent.mkdir(parents=True)+ project_env.write_text("XAI_API_KEY=xai-project\n", encoding="utf-8")+ monkeypatch.chdir(project_dir)+ monkeypatch.setattr(env, "CONFIG_FILE", global_env)+ monkeypatch.delenv("LAST30DAYS_TRUST_PROJECT_CONFIG", raising=False)++ keychain, pass_store = _neutral_secret_sources()+ with keychain, pass_store:+ cfg = env.get_config()++ assert cfg["XAI_API_KEY"] == "xai-project"+ assert cfg["_CONFIG_SOURCE"].startswith(f"project:{project_env}")+++def test_project_config_discovery_stops_at_git_root(tmp_path, monkeypatch):+ outside_env = tmp_path / ".claude" / "last30days.env"+ outside_env.parent.mkdir()+ outside_env.write_text("XAI_API_KEY=outside\n", encoding="utf-8")+ repo = tmp_path / "repo"+ workdir = repo / "nested"+ workdir.mkdir(parents=True)+ (repo / ".git").mkdir()+ monkeypatch.chdir(workdir)+ monkeypatch.setenv("LAST30DAYS_TRUST_PROJECT_CONFIG", "1")+ monkeypatch.setattr(env, "CONFIG_FILE", None)++ keychain, pass_store = _neutral_secret_sources()+ with keychain, pass_store:+ cfg = env.get_config()++ assert cfg["XAI_API_KEY"] is None+ assert cfg["_CONFIG_SOURCE"] == "env_only"+++def test_global_config_loads_when_project_config_is_untrusted(tmp_path, monkeypatch):+ global_env = tmp_path / "global.env"+ global_env.write_text("XAI_API_KEY=global\n", encoding="utf-8")+ project_dir = tmp_path / "project"+ project_env = project_dir / ".claude" / "last30days.env"+ project_env.parent.mkdir(parents=True)+ project_env.write_text("XAI_API_KEY=project\n", encoding="utf-8")+ monkeypatch.chdir(project_dir)+ monkeypatch.setattr(env, "CONFIG_FILE", global_env)+ monkeypatch.delenv("LAST30DAYS_TRUST_PROJECT_CONFIG", raising=False)++ keychain, pass_store = _neutral_secret_sources()+ with keychain, pass_store:+ cfg = env.get_config()++ assert cfg["XAI_API_KEY"] == "global"+ assert cfg["_CONFIG_SOURCE"].startswith(f"global:{global_env}")+++def test_diagnose_reports_ignored_untrusted_endpoint_override(tmp_path, monkeypatch):+ project_env = tmp_path / ".claude" / "last30days.env"+ project_env.parent.mkdir()+ project_env.write_text(+ "OPENAI_BASE_URL=https://attacker.example\nOPENAI_API_KEY=sk-not-reported\n",+ encoding="utf-8",+ )+ monkeypatch.chdir(tmp_path)+ monkeypatch.setattr(env, "CONFIG_FILE", None)+ monkeypatch.setenv("OPENAI_API_KEY", "sk-global")+ monkeypatch.delenv("LAST30DAYS_TRUST_PROJECT_CONFIG", raising=False)++ keychain, pass_store = _neutral_secret_sources()+ with keychain, pass_store:+ cfg = env.get_config(+ policy=env.ConfigLoadPolicy(inspect_ignored_project_config=True)+ )+ diag = pipeline.diagnose(cfg, safe=True)++ assert cfg["OPENAI_API_KEY"] == "sk-global"+ assert cfg["OPENAI_BASE_URL"] is None+ assert diag["ignored_project_config"] == str(project_env)+ assert diag["ignored_endpoint_overrides"] == ["OPENAI_BASE_URL"]+ assert "sk-not-reported" not in str(diag)diff --git a/tests/test_security_boundaries.py b/tests/test_security_boundaries.pyindex d9e056ad..05325ea0 100644--- a/tests/test_security_boundaries.py+++ b/tests/test_security_boundaries.py@@ -11,6 +11,7 @@ from contextlib import redirect_stderr, redirect_stdoutfrom unittest import mockimport last30days as cli+from lib import envdef test_importing_cli_does_not_load_config_or_propagate_endpoints(monkeypatch):@@ -152,3 +153,40 @@ def test_watchlist_subprocess_disables_browser_cookies():argv = run.call_args.args[0]assert "--no-browser-cookies" in argv+++def test_project_config_ignored_by_default_and_cannot_self_trust(tmp_path, monkeypatch):+ project_env = tmp_path / ".claude" / "last30days.env"+ project_env.parent.mkdir()+ project_env.write_text(+ "LAST30DAYS_TRUST_PROJECT_CONFIG=1\nOPENAI_BASE_URL=https://example.invalid\n",+ encoding="utf-8",+ )+ monkeypatch.chdir(tmp_path)+ monkeypatch.setattr(env, "CONFIG_FILE", None)+ monkeypatch.delenv("LAST30DAYS_TRUST_PROJECT_CONFIG", raising=False)+ monkeypatch.delenv("OPENAI_BASE_URL", raising=False)++ with mock.patch.object(env, "_load_keychain", return_value={}), \+ mock.patch.object(env, "_load_pass", return_value={}):+ cfg = env.get_config()++ assert cfg["OPENAI_BASE_URL"] is None+ assert cfg["_CONFIG_SOURCE"] == "env_only"+++def test_project_config_loads_with_process_trust_signal(tmp_path, monkeypatch):+ project_env = tmp_path / ".claude" / "last30days.env"+ project_env.parent.mkdir()+ project_env.write_text("OPENAI_BASE_URL=https://trusted.example\n", encoding="utf-8")+ monkeypatch.chdir(tmp_path)+ monkeypatch.setattr(env, "CONFIG_FILE", None)+ monkeypatch.setenv("LAST30DAYS_TRUST_PROJECT_CONFIG", "1")+ monkeypatch.delenv("OPENAI_BASE_URL", raising=False)++ with mock.patch.object(env, "_load_keychain", return_value={}), \+ mock.patch.object(env, "_load_pass", return_value={}):+ cfg = env.get_config()++ assert cfg["OPENAI_BASE_URL"] == "https://trusted.example"+ assert cfg["_CONFIG_SOURCE"].startswith(f"project:{project_env}")