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
merge main into cached html rendering
Trevin Chowc966c93653b6
diff --cc skills/last30days/references/save-html-brief.mdindex 96916ad2,1253f201..a030e340--- a/skills/last30days/references/save-html-brief.md+++ b/skills/last30days/references/save-html-brief.md@@@ -94,10 -127,10 +130,12 @@@ Same flow when the topic is `X vs Y` (o## Follow-up turn- If the user runs `/last30days OpenClaw` normally, sees the synthesis in chat, and THEN says "save that as HTML" or "give me a shareable version" in a follow-up turn, do the same save flow on the synthesis you wrote in the previous turn. Do not re-research; the synthesis is already in the conversation history. Just write it to the temp file and call the engine with `--emit=html --synthesis-file`.+ If the user runs `/last30days OpenClaw` normally, sees the synthesis in chat, and THEN explicitly refers back to that visible synthesis ("save that as HTML", "make this shareable", "turn the above into HTML"), do the same save flow on the synthesis you wrote in the previous turn. Do not re-research; the synthesis is already in the conversation history. Just write it to the temp file and call the engine with `--emit=html --synthesis-file`, then use the normal-report-plus-HTML artifact block.++ If the follow-up instead asks for a new HTML deliverable ("give it to me in HTML", `--emit=html`, `--html`) rather than referring back to an already-visible report, treat it as HTML-as-deliverable mode.+The engine will try to reuse `~/.config/last30days/last-report.json` for that second invocation when it is still within `LAST30DAYS_REPORT_CACHE_TTL_SECONDS` (default: one hour). If stderr says it is reusing cached report data, continue normally. If stderr says no matching cache exists, the cache may be stale; let the command finish only if you supplied the same scope flags as the original run. Otherwise stop and re-run with the original flags so the HTML footer does not describe a different dataset.+## What NOT to do- Do NOT save HTML if the user didn't ask. The sparse mode (no synthesis) produces a thin file; not useful as a shareable.diff --cc skills/last30days/scripts/last30days.pyindex 0485d292,dd084a1b..94860906--- a/skills/last30days/scripts/last30days.py+++ b/skills/last30days/scripts/last30days.py@@@ -677,111 -620,6 +677,118 @@@ def _write_last_runpass+def _load_last_report_cache(+ topic: str,+ ttl_seconds: int = DEFAULT_REPORT_CACHE_TTL_SECONDS,+) -> tuple[schema.Report, list[tuple[str, schema.Report]] | None, Path] | None:+ cache_path = _last_report_cache_path()+ if cache_path is None or not cache_path.exists():+ return None+ try:+ payload = json.loads(cache_path.read_text(encoding="utf-8"))+ if payload.get("schema") != REPORT_CACHE_VERSION:+ return None+ if not _is_report_cache_fresh(payload.get("timestamp"), ttl_seconds):+ return None+ cached_topic = str(payload.get("topic") or "").strip().lower()+ if cached_topic != topic.strip().lower():+ return None+ reports_payload = payload.get("reports") or []+ if not reports_payload:+ return None+ entity_reports = [+ (str(item.get("entity") or ""), schema.report_from_dict(item["report"]))+ for item in reports_payload+ if isinstance(item, dict) and isinstance(item.get("report"), dict)+ ]+ if not entity_reports:+ return None+ if payload.get("comparison"):+ if len(entity_reports) < 2:+ return None+ if len(entity_reports) != len(reports_payload):+ return None+ return entity_reports[0][1], entity_reports, cache_path+ return entity_reports[0][1], None, cache_path+ except Exception:+ return None+++def _render_save_and_print(+ args: argparse.Namespace,+ report: schema.Report,+ entity_reports: list[tuple[str, schema.Report]] | None,+ synthesis_md: str | None,+ config: dict[str, object],+) -> int:+ fun_level = str(config.get("FUN_LEVEL", "medium")).lower()+ # Comparison HTML is the one case where the saved file's title and content+ # have to be overridden away from the leading entity's report. Compute the+ # gate once so the footer-display and save-output paths can't disagree.+ is_comparison_html = bool(entity_reports) and args.emit == "html"+ footer_save_path = None+ if args.output:+ footer_save_path = compute_output_path_display(args.output)+ elif args.save_dir:+ save_topic_for_display = comparison_topic(entity_reports) if is_comparison_html else report.topic+ footer_save_path = compute_save_path_display(+ args.save_dir, save_topic_for_display, args.save_suffix or "", args.emit+ )++ if entity_reports:+ rendered = emit_comparison_output(+ entity_reports,+ args.emit,+ fun_level=fun_level,+ save_path=footer_save_path,+ synthesis_md=synthesis_md,+ )+ else:+ rendered = emit_output(+ report,+ args.emit,+ fun_level=fun_level,+ save_path=footer_save_path,+ synthesis_md=synthesis_md,+ )+ if args.output:+ output_path = save_rendered_output(rendered, args.output)+ sys.stderr.write(f"[last30days] Saved output to {output_path}\n")+ sys.stderr.flush()+ if args.save_dir:+ # Save the main topic's raw file (single-entity or comparison main).+ save_path = save_output(+ report,+ args.emit,+ args.save_dir,+ suffix=args.save_suffix or "",+ synthesis_md=synthesis_md,+ topic_override=comparison_topic(entity_reports) if is_comparison_html else None,+ rendered_content=rendered if is_comparison_html else None,+ )+ sys.stderr.write(f"[last30days] Saved output to {save_path}\n")++ comparison_peer_paths: list[Path] = []+ # Competitor / vs-mode: also save a per-entity raw file for each peer.+ # Matches historical vs-mode behavior (N passes -> N save files).+ if entity_reports and len(entity_reports) > 1:+ for label, entity_report in entity_reports[1:]:+ peer_path = save_output(+ entity_report, args.emit, args.save_dir,+ suffix=args.save_suffix or "",+ synthesis_md=synthesis_md,+ )++ comparison_peer_paths.append(peer_path)+ sys.stderr.write(f"[last30days] Saved output to {peer_path}\n")++ peers_display = ", ".join(str(path) for path in comparison_peer_paths)++ sys.stderr.write(++ f"[last30days] Comparison artifact set: main={save_path}; "++ f"peers={peers_display}\n"++ )+ sys.stderr.flush()+ print(rendered)+ return 0++def _propagate_config_to_environ(config: dict[str, object]) -> None:"""Push relevant env keys to os.environ so provider modules can read them.diff --cc tests/test_doc_flag_contract.pyindex c9815e23,804dea7c..4a518a80--- a/tests/test_doc_flag_contract.py+++ b/tests/test_doc_flag_contract.py@@@ -44,17 -51,15 +52,31 @@@ def test_agent_is_documented_as_skill_aassert "Skill tool" in text+def test_html_reference_documents_structured_cache_reuse():+ text = HTML_REFERENCE.read_text(encoding="utf-8")+ assert "~/.config/last30days/last-report.json" in text+ assert "without re-running source fetchers" in text+ assert "No matching cached report data" in text+ assert "LAST30DAYS_REPORT_CACHE_TTL_SECONDS" in text+ assert "default: one hour" in text+++def test_configuration_documents_report_cache_ttl():+ text = CONFIGURATION.read_text(encoding="utf-8")+ assert "LAST30DAYS_REPORT_CACHE_TTL_SECONDS" in text+ assert "defaults to `3600`" in text+ assert "`0` to disable report-cache reuse" in text+++++ def test_comparison_artifact_contract_documents_actual_paths():+ text = SKILL_MD.read_text(encoding="utf-8")+ comparison_start = text.index("\n## If QUERY_TYPE = COMPARISON\n")+ comparison_section = text[comparison_start:comparison_start + 5000]+ assert "there is no separate merged Markdown raw file" in comparison_section+ assert "[last30days] Comparison artifact set: main={path}; peers={path, ...}" in comparison_section+ assert "Treat that log line as authoritative" in comparison_section++ step_start = text.index("## Step 2.5: Append WebSearch Results to Saved Raw File")+ step_section = text[step_start:step_start + 3500]+ assert "append the same `## WebSearch Supplemental Results` section to every listed per-entity Markdown raw file" in step_section+ assert "do not append Markdown text to `.html` or `.json`" in step_sectiondiff --cc tests/test_last_run_state.pyindex af68c862,c44fdf94..3efb47be--- a/tests/test_last_run_state.py+++ b/tests/test_last_run_state.py@@@ -2,12 -2,13 +2,13 @@@ import iimport jsonimport osimport re+ import shutil+ import statimport subprocessimport sys- import shutilimport tempfileimport unittest-from contextlib import redirect_stderr+from contextlib import redirect_stderr, redirect_stdoutfrom pathlib import Pathfrom unittest import mock