Skip to content

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

Merge origin/main into feat/emit-brief-pipeline-output

Trevin Chow9eff7be21c6f
diff --cc skills/last30days/scripts/last30days.py
index e4580ab6,9b80a159..7bfebefc
--- a/skills/last30days/scripts/last30days.py
+++ b/skills/last30days/scripts/last30days.py
@@@ -238,9 -268,12 +270,12 @@@ def persist_report(report: schema.Repor
def build_parser() -> argparse.ArgumentParser:
- parser = argparse.ArgumentParser(description="Research a topic across live social, market, and grounded web sources.")
+ parser = argparse.ArgumentParser(
+ description="Research a topic across live social, market, and grounded web sources.",
+ allow_abbrev=False,
+ )
parser.add_argument("topic", nargs="*", help="Research topic")
- parser.add_argument("--emit", default="compact", choices=["compact", "json", "context", "md", "html"])
+ parser.add_argument("--emit", default="compact", choices=["compact", "json", "context", "md", "html", "brief"])
parser.add_argument("--search", help="Comma-separated source list")
parser.add_argument("--quick", action="store_true", help="Lower-latency retrieval profile")
parser.add_argument("--deep", action="store_true", help="Higher-recall retrieval profile")
diff --cc skills/last30days/scripts/lib/render.py
index 734f637b,d394ecb4..fda4dab6
--- a/skills/last30days/scripts/lib/render.py
+++ b/skills/last30days/scripts/lib/render.py
@@@ -961,115 -987,71 +987,180 @@@ def render_context(report: schema.Repor
return "\n".join(lines).strip() + "\n"
+def render_brief(report: schema.Report, cluster_limit: int = 8) -> str:
+ """Production brief for downstream pipelines (video, scripting, structured synthesis).
+
+ Reshapes ranked pipeline output into five sections that scripting pipelines
+ can consume directly: Ranked Storylines, Narrative Hooks, Topic Tensions,
+ Audience Questions, and Source Clusters. Sections 2-4 are omitted when there
+ is no matching data; Sections 1 and 5 always appear.
+ """
+ non_empty = [s for s, items in sorted(report.items_by_source.items()) if items]
+ lines = [
+ f"# Production Brief: {report.topic}",
+ "",
+ *_assistant_safety_lines(),
+ f"- Date range: {report.range_from} to {report.range_to}",
+ f"- Sources: {len(non_empty)} active ({', '.join(_source_label(s) for s in non_empty)})" if non_empty else "- Sources: none",
+ "",
+ ]
+
+ lines.append("## Ranked Storylines")
+ lines.append("")
+ candidate_by_id = {c.candidate_id: c for c in report.ranked_candidates}
+ for i, cluster in enumerate(report.clusters[:cluster_limit], start=1):
+ source_tags = ", ".join(_source_label(s) for s in cluster.sources)
+ qualifier = f" [{cluster.uncertainty.replace('-', ' ')}]" if cluster.uncertainty else ""
+ lines.append(f"### {i}. {cluster.title} (score {cluster.score:.0f}, {source_tags}){qualifier}")
+ for cid in cluster.representative_ids[:2]:
+ candidate = candidate_by_id.get(cid)
+ if not candidate:
+ continue
+ if candidate.snippet:
+ lines.append(f"- {_truncate(candidate.snippet, 280)}")
+ explanation = _format_explanation(candidate)
+ if explanation:
+ lines.append(f" _Why: {explanation}_")
+ lines.append("")
+
+ hooks = sorted(
+ (c for c in report.ranked_candidates if c.fun_score is not None and c.fun_score >= 70),
+ key=lambda c: -(c.fun_score or 0),
+ )
+ if hooks:
+ lines.append("## Narrative Hooks")
+ lines.append("")
+ for candidate in hooks[:5]:
+ source_label = _source_label(candidate.source)
+ primary = schema.candidate_primary_item(candidate)
+ author = primary.author if primary else None
+ if author and candidate.source in ("x", "tiktok", "instagram", "threads"):
+ attribution = f"@{author} on {source_label}"
+ elif author and candidate.source == "reddit":
+ container = primary.container if primary else None
+ attribution = f"r/{container}" if container else "Reddit"
+ else:
+ attribution = source_label
+ reason = (
+ f" — {candidate.fun_explanation}"
+ if candidate.fun_explanation and candidate.fun_explanation != "heuristic-fallback"
+ else ""
+ )
+ lines.append(
+ f'- "{_truncate(candidate.title, 200)}"'
+ f" ({attribution}, fun:{candidate.fun_score:.0f}){reason}"
+ )
+ lines.append("")
+
+ tensions = [c for c in report.clusters[:cluster_limit] if c.uncertainty]
+ if tensions:
+ lines.append("## Topic Tensions")
+ lines.append("")
+ for cluster in tensions[:cluster_limit]:
+ label = cluster.uncertainty.replace("-", " ").title() if cluster.uncertainty else ""
+ source_tags = ", ".join(_source_label(s) for s in cluster.sources)
+ lines.append(f"- **{cluster.title}** [{label}]: {source_tags}")
+ lines.append("")
+
+ questions = _extract_audience_questions(report.ranked_candidates)
+ if questions:
+ lines.append("## Audience Questions")
+ lines.append("")
+ for q in questions[:8]:
+ lines.append(f"- {q}")
+ lines.append("")
+
+ lines.append("## Source Clusters")
+ lines.append("")
+ for cluster in report.clusters[:cluster_limit]:
+ source_tags = " + ".join(_source_label(s) for s in cluster.sources)
+ lines.append(f"- **{cluster.title}**: {source_tags}")
+ lines.append("")
+
+ return "\n".join(lines).strip() + "\n"
+
+
+def _extract_audience_questions(candidates: list[schema.Candidate]) -> list[str]:
+ """Return titles that read as audience questions, deduped and in ranked order."""
+ questions: list[str] = []
+ seen: set[str] = set()
+ for candidate in candidates:
+ title = candidate.title.strip()
+ if not title:
+ continue
+ if title.endswith("?"):
+ norm = title.lower()
+ if norm not in seen:
+ seen.add(norm)
+ questions.append(title)
+ return questions
+
+
+ def _render_hiring_signals(report: schema.Report) -> list[str]:
+ summary = report.artifacts.get("hiring_signals")
+ if not isinstance(summary, dict):
+ return []
+ signals = summary.get("signals") or []
+ include = bool(summary.get("include"))
+ mode = summary.get("mode") or "standard"
+ if not include and mode != "explicit":
+ return []
+
+ out = [
+ "## Hiring Signals",
+ "",
+ (
+ f"- Mode: {mode}; company-size tier: "
+ f"{summary.get('company_size_tier') or 'unknown'}"
+ ),
+ ]
+ if not signals:
+ reason = summary.get("omitted_reason") or "no reliable hiring signal found"
+ out.append(f"- No reliable hiring signal found: {reason}.")
+ return out
+
+ out.append(
+ "- Interpret these as focus or priority signals, not exact roadmap predictions."
+ )
+ for signal in signals[:4]:
+ evidence = signal.get("evidence") or []
+ out.append(
+ f"- {signal.get('theme', 'hiring theme')}: "
+ f"{signal.get('interpretation', 'possible hiring focus')} "
+ f"(confidence: {signal.get('confidence', 'low')}; "
+ f"evidence: {signal.get('evidence_count', len(evidence))} roles)"
+ )
+ for item in evidence[:3]:
+ title = item.get("title") or "Job posting"
+ url = item.get("url") or ""
+ dept = item.get("department") or ""
+ date = item.get("published_at") or "date unknown"
+ link = f"[{title}]({url})" if url else title
+ detail = " | ".join(part for part in [dept, date] if part)
+ out.append(f" - {link}" + (f" ({detail})" if detail else ""))
+
+ strategic = summary.get("strategic_candidates") or []
+ if strategic:
+ out.append("")
+ out.append(
+ "- Strategic single-role signals (judge novelty yourself - a founding "
+ "or first-of-function role can outweigh a whole department; in synthesis, "
+ "distinguish \"new bets\" from \"doubling down\"):"
+ )
+ for cand in strategic[:8]:
+ title = cand.get("title") or "Job posting"
+ url = cand.get("url") or ""
+ flags = ", ".join(cand.get("flags") or [])
+ dept = cand.get("department") or ""
+ location = cand.get("location") or ""
+ date = cand.get("published_at") or "date unknown"
+ link = f"[{title}]({url})" if url else title
+ detail = " | ".join(part for part in [dept, location, date] if part)
+ tag = f" [{flags}]" if flags else ""
+ out.append(f" - {link}{tag}" + (f" ({detail})" if detail else ""))
+ return out
+
+
def _render_candidate(candidate: schema.Candidate, prefix: str) -> list[str]:
primary = schema.candidate_primary_item(candidate)
detail_parts = [