Skip to content

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

feat: support historical lookback with --as-of date

suriel123509fd3a55396
diff --git a/skills/last30days/scripts/last30days.py b/skills/last30days/scripts/last30days.py
index 26996529..cc4caad5 100644
--- a/skills/last30days/scripts/last30days.py
+++ b/skills/last30days/scripts/last30days.py
@@ -42,7 +42,7 @@ if os.name == "nt":
SCRIPT_DIR = Path(__file__).parent.resolve()
sys.path.insert(0, str(SCRIPT_DIR))
-from lib import env, html_render, pipeline, render, schema, ui
+from lib import dates, env, html_render, pipeline, render, schema, ui
_child_pids: set[int] = set()
_child_pids_lock = threading.Lock()
@@ -89,6 +89,14 @@ def parse_search_flag(raw: str) -> list[str]:
raise SystemExit("--search requires at least one source.")
return sources
+def parse_as_of_date_arg(value: str) -> str:
+ try:
+ parsed = dates.parse_as_of_date(value)
+ except ValueError as exc:
+ raise argparse.ArgumentTypeError(str(exc)) from exc
+ if parsed is None:
+ raise argparse.ArgumentTypeError("--as-of must be in YYYY-MM-DD format.")
+ return parsed
def slugify(value: str) -> str:
slug = re.sub(r"[^a-z0-9]+", "-", value.lower()).strip("-")
@@ -269,6 +277,15 @@ def build_parser() -> argparse.ArgumentParser:
default=30,
help="Number of days to look back for research (default: 30, watchlist uses 90)",
)
+ parser.add_argument(
+ "--as-of",
+ dest="as_of_date",
+ type=parse_as_of_date_arg,
+ help=(
+ "End date for the lookback window in YYYY-MM-DD format. "
+ "When set, --days looks back from this date instead of today."
+ ),
+)
parser.add_argument("--auto-resolve", action="store_true",
help="Use web search to discover subreddits/handles before planning (for platforms without WebSearch)")
parser.add_argument("--github-user", help="GitHub username for person-mode search (e.g., steipete)")
@@ -750,6 +767,7 @@ def main() -> int:
tiktok_creators=tiktok_creators,
ig_creators=ig_creators,
lookback_days=args.lookback_days,
+ as_of_date=args.as_of_date,
github_user=github_user,
github_repos=github_repos,
)
@@ -879,6 +897,7 @@ def main() -> int:
github_repos=kwargs["github_repos"],
web_backend=args.web_backend,
lookback_days=args.lookback_days,
+ as_of_date=args.as_of_date,
internal_subrun=True,
)
report.artifacts["resolved"] = resolved_effective
diff --git a/skills/last30days/scripts/lib/dates.py b/skills/last30days/scripts/lib/dates.py
index 164f395c..03be045c 100644
--- a/skills/last30days/scripts/lib/dates.py
+++ b/skills/last30days/scripts/lib/dates.py
@@ -4,15 +4,55 @@ from datetime import datetime, timedelta, timezone
from typing import Optional, Tuple
-def get_date_range(days: int = 30) -> Tuple[str, str]:
+def parse_as_of_date(as_of_date: Optional[str]) -> Optional[str]:
+ """Validate and normalize an --as-of date.
+
+ Args:
+ as_of_date: Date string in YYYY-MM-DD format.
+
+ Returns:
+ Normalized YYYY-MM-DD string, or None when no date was provided.
+
+ Raises:
+ ValueError: If the date is not in YYYY-MM-DD format.
+ """
+ if as_of_date is None:
+ return None
+
+ if not as_of_date.strip():
+ raise ValueError("--as-of must be in YYYY-MM-DD format.")
+
+ try:
+ parsed = datetime.strptime(as_of_date, "%Y-%m-%d").date()
+ except ValueError as exc:
+ raise ValueError(
+ f"Invalid --as-of date: {as_of_date}. Expected YYYY-MM-DD."
+ ) from exc
+
+ return parsed.isoformat()
+
+
+def get_date_range(days: int = 30, as_of_date: Optional[str] = None) -> Tuple[str, str]:
"""Get the date range for the last N days.
+ When as_of_date is provided, the range ends at that date instead of today.
+
+ Args:
+ days: Number of days to look back.
+ as_of_date: Optional end date in YYYY-MM-DD format.
+
Returns:
- Tuple of (from_date, to_date) as YYYY-MM-DD strings
+ Tuple of (from_date, to_date) as YYYY-MM-DD strings.
"""
- today = datetime.now(timezone.utc).date()
- from_date = today - timedelta(days=days)
- return from_date.isoformat(), today.isoformat()
+ normalized_as_of = parse_as_of_date(as_of_date)
+
+ if normalized_as_of:
+ to_date = datetime.strptime(normalized_as_of, "%Y-%m-%d").date()
+ else:
+ to_date = datetime.now(timezone.utc).date()
+
+ from_date = to_date - timedelta(days=days)
+ return from_date.isoformat(), to_date.isoformat()
def parse_date(date_str: Optional[str]) -> Optional[datetime]:
diff --git a/skills/last30days/scripts/lib/pipeline.py b/skills/last30days/scripts/lib/pipeline.py
index 4d64edba..aca26613 100644
--- a/skills/last30days/scripts/lib/pipeline.py
+++ b/skills/last30days/scripts/lib/pipeline.py
@@ -188,13 +188,14 @@ def run(
tiktok_creators: list[str] | None = None,
ig_creators: list[str] | None = None,
lookback_days: int = 30,
+ as_of_date: str | None = None,
github_user: str | None = None,
github_repos: list[str] | None = None,
internal_subrun: bool = False,
) -> schema.Report:
settings = DEPTH_SETTINGS[depth]
requested_sources = normalize_requested_sources(requested_sources)
- from_date, to_date = dates.get_date_range(lookback_days)
+ from_date, to_date = dates.get_date_range(lookback_days, as_of_date=as_of_date)
if mock:
runtime = providers.mock_runtime(config, depth)
diff --git a/tests/test_as_of_date.py b/tests/test_as_of_date.py
new file mode 100644
index 00000000..11ac4d6e
--- /dev/null
+++ b/tests/test_as_of_date.py
@@ -0,0 +1,97 @@
+# ruff: noqa: E402
+"""Tests for --as-of date support."""
+
+import json
+import subprocess
+import sys
+import unittest
+from pathlib import Path
+
+
+REPO_ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(REPO_ROOT / "skills" / "last30days" / "scripts"))
+
+import last30days as cli
+from lib import dates
+
+
+class AsOfDateTests(unittest.TestCase):
+ def test_get_date_range_with_as_of_date_and_7_days(self):
+ from_date, to_date = dates.get_date_range(7, "2020-05-25")
+
+ self.assertEqual("2020-05-18", from_date)
+ self.assertEqual("2020-05-25", to_date)
+
+ def test_get_date_range_with_as_of_date_and_30_days(self):
+ from_date, to_date = dates.get_date_range(30, "2020-05-25")
+
+ self.assertEqual("2020-04-25", from_date)
+ self.assertEqual("2020-05-25", to_date)
+
+ def test_get_date_range_rejects_invalid_as_of_date(self):
+ with self.assertRaisesRegex(ValueError, "YYYY-MM-DD"):
+ dates.get_date_range(7, "2020/05/25")
+
+ def test_build_parser_accepts_as_of_date(self):
+ parser = cli.build_parser()
+ args, extra = parser.parse_known_args(
+ ["--as-of", "2020-05-25", "--days", "7", "OpenAI"]
+ )
+
+ self.assertEqual("2020-05-25", args.as_of_date)
+ self.assertEqual(7, args.lookback_days)
+ self.assertEqual(["OpenAI"], args.topic)
+ self.assertEqual([], extra)
+
+ def test_mock_json_cli_uses_as_of_date_range(self):
+ result = subprocess.run(
+ [
+ sys.executable,
+ "skills/last30days/scripts/last30days.py",
+ "OpenAI",
+ "--mock",
+ "--emit=json",
+ "--as-of",
+ "2020-05-25",
+ "--days",
+ "7",
+ ],
+ cwd=REPO_ROOT,
+ capture_output=True,
+ text=True,
+ encoding="utf-8",
+ errors="replace",
+ check=False,
+)
+
+ self.assertEqual(0, result.returncode, result.stderr)
+ payload = json.loads(result.stdout)
+
+ self.assertEqual("2020-05-18", payload["range_from"])
+ self.assertEqual("2020-05-25", payload["range_to"])
+
+ def test_cli_rejects_invalid_as_of_date(self):
+ result = subprocess.run(
+ [
+ sys.executable,
+ "skills/last30days/scripts/last30days.py",
+ "OpenAI",
+ "--mock",
+ "--emit=json",
+ "--as-of",
+ "2020/05/25",
+ ],
+ cwd=REPO_ROOT,
+ capture_output=True,
+ text=True,
+ encoding="utf-8",
+ errors="replace",
+ check=False,
+ )
+
+ self.assertNotEqual(0, result.returncode)
+ self.assertIn("YYYY-MM-DD", result.stderr)
+
+
+if __name__ == "__main__":
+ unittest.main()