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(env): strip trailing inline comments from unquoted .env values (#1121)
Ilia Alshanetsky175bc785f9fc
diff --git a/CONFIGURATION.md b/CONFIGURATION.mdindex ba3d27d0..ead33491 100644--- a/CONFIGURATION.md+++ b/CONFIGURATION.md@@ -104,6 +104,8 @@ The skill reads keys from a `.env` file. Two locations are supported: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.+**File syntax.** One `KEY=value` per line; whitespace around the key and value is trimmed. A line starting with `#` is a comment, and a `#` preceded by whitespace after an unquoted value starts a trailing comment (`RATE=1 # req/sec` stores `1`). A `#` glued to the value is literal (`TOKEN=abc#123` stores `abc#123`). Wrap a value in matching `"` or `'` to keep spaces or a `#` verbatim (`NAME="Jane # Doe"` stores `Jane # Doe`); no backslash escapes or `$VAR` expansion are processed. An empty value is ignored (the one exception is `LAST30DAYS_YT_PLAYER_CLIENT=`, where empty is a deliberate disable), so a secret can never be set to `""`.+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. The SessionStart status hook (`hooks/scripts/check-config.sh`) uses the same trust gate — an untrusted repo's `.claude/last30days.env` is not read at session start.**`LAST30DAYS_API_KEY`** + **`LAST30DAYS_API_BASE`** - optional remote-API backend. Set BOTH to route research through a remote API endpoint instead of running the local sources: `LAST30DAYS_API_BASE` is the endpoint (there is no built-in default), and `LAST30DAYS_API_KEY` is the bearer key for it. When both are set (and `--mock` is not passed), the engine submits the topic to that endpoint, polls with progress on stderr, and prints the server's report; none of the per-source keys below are used for that run. A configured local corpus is the privacy exception: the engine bypasses the hosted backend and runs locally rather than forwarding file-derived input. Non-default `--register` selections are forwarded with the request so server-side synthesis uses the same audience preset. Leave either unset to run local sources exactly as normal. Unlike the other keys here, these two are read only from the **process environment** (export them in your shell or host config) - they are deliberately not loaded from the `.env` files above, so a project-scoped `.env` can never silently redirect research to a remote endpoint. The remote endpoint does not return the local `Report` needed for the versioned agent JSON profile; use `--emit=json --json-profile=raw` for its existing server-response JSON contract.diff --git a/changelog.d/+env-inline-comment-parsing.fixed.md b/changelog.d/+env-inline-comment-parsing.fixed.mdnew file mode 100644index 00000000..923b5a69--- /dev/null+++ b/changelog.d/+env-inline-comment-parsing.fixed.md@@ -0,0 +1 @@+Trailing `# comment` annotations on unquoted `.env` values (the shape shown in `CONFIGURATION.md`) are now stripped instead of being stored as part of the value; `#` inside quotes or glued to the value stays literal.diff --git a/skills/last30days/scripts/lib/env.py b/skills/last30days/scripts/lib/env.pyindex f34000d0..ce574131 100644--- a/skills/last30days/scripts/lib/env.py+++ b/skills/last30days/scripts/lib/env.py@@ -235,6 +235,31 @@ def _check_file_permissions(path: Path) -> None:sys.stderr.flush()+def _strip_inline_comment(value: str) -> str:+ """Drop a trailing ``# comment`` from the right-hand side of a KEY=value line.++ Unquoted: ``#`` opens a comment only as the first non-blank character or+ when preceded by whitespace, so ``value#nothash`` stays intact. Quoted:+ everything up to the matching close quote is kept verbatim; only a+ whitespace-separated ``#`` after the close quote is dropped. Anything that+ does not match those shapes is returned unchanged for the existing quote+ handling to deal with.+ """+ stripped = value.lstrip()+ if stripped[:1] in ('"', "'"):+ end = stripped.find(stripped[0], 1)+ if end == -1:+ return value+ rest = stripped[end + 1:]+ if rest[:1].isspace() and rest.lstrip().startswith('#'):+ return stripped[:end + 1]+ return value+ match = re.search(r'(?:^|\s)#', stripped)+ if match:+ return stripped[:match.start()]+ return value++def load_env_file(path: Path) -> dict[str, str]:"""Load environment variables from a file."""env = {}@@ -259,7 +284,7 @@ def load_env_file(path: Path) -> dict[str, str]:if '=' in line:key, _, value = line.partition('=')key = key.strip()- value = value.strip()+ value = _strip_inline_comment(value).strip()# Remove quotes if presentif value and value[0] in ('"', "'") and value[-1] == value[0]:value = value[1:-1]diff --git a/tests/test_env_inline_comments.py b/tests/test_env_inline_comments.pynew file mode 100644index 00000000..335cfc2b--- /dev/null+++ b/tests/test_env_inline_comments.py@@ -0,0 +1,65 @@+import pytest++from lib import env+++def _load(tmp_path, text):+ env_path = tmp_path / ".env"+ env_path.write_text(text, encoding="utf-8")+ env_path.chmod(0o600)+ return env.load_env_file(env_path)+++def test_trailing_inline_comment_is_stripped(tmp_path):+ loaded = _load(tmp_path, "FOO=bar # trailing comment\n")+ assert loaded["FOO"] == "bar"+++def test_tab_before_hash_also_opens_comment(tmp_path):+ loaded = _load(tmp_path, "FOO=bar\t# trailing comment\n")+ assert loaded["FOO"] == "bar"+++def test_hash_without_preceding_whitespace_is_literal(tmp_path):+ loaded = _load(tmp_path, "BAZ=value#nothash\n")+ assert loaded["BAZ"] == "value#nothash"++[email protected]("quote", ['"', "'"])+def test_hash_inside_quotes_is_kept(tmp_path, quote):+ loaded = _load(tmp_path, f"QUX={quote}value # not a comment{quote}\n")+ assert loaded["QUX"] == "value # not a comment"+++def test_comment_after_closing_quote_is_stripped(tmp_path):+ loaded = _load(tmp_path, 'QUX="value # kept" # dropped\n')+ assert loaded["QUX"] == "value # kept"+++def test_leading_whitespace_before_value_is_trimmed(tmp_path):+ loaded = _load(tmp_path, "KEY= spaced\n")+ assert loaded["KEY"] == "spaced"+++def test_whole_line_comment_and_empty_value_are_skipped(tmp_path):+ loaded = _load(tmp_path, "# whole line comment\nEMPTY=\nEMPTY2= # only a comment\n")+ assert loaded == {}+++def test_documented_configuration_example_round_trips(tmp_path):+ # CONFIGURATION.md shows this shape (a path, run-in whitespace, then an+ # annotation); uncommenting it must not leak the annotation into the value.+ # The path is a stand-in: test_version_consistency forbids repeating the+ # real default outside the lines that document it.+ loaded = _load(+ tmp_path,+ "LAST30DAYS_MEMORY_DIR=~/Archive/Briefings # POSIX\n"+ "LAST30DAYS_REDDIT_KEYLESS_RATE=1 # keyless reddit.com req/sec\n",+ )+ assert loaded["LAST30DAYS_MEMORY_DIR"] == "~/Archive/Briefings"+ assert loaded["LAST30DAYS_REDDIT_KEYLESS_RATE"] == "1"+++def test_unterminated_quote_is_left_verbatim(tmp_path):+ loaded = _load(tmp_path, 'RAW="abc # def\n')+ assert loaded["RAW"] == '"abc # def'