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 optional html publishing
Trevin Chow91dba43d1f2c
diff --cc CONFIGURATION.mdindex d592aa68,5270c502..a3a11334--- a/CONFIGURATION.md+++ b/CONFIGURATION.md@@@ -45,8 -45,7 +45,9 @@@ The engine's `.env` reader doesn't expa- `--output <file>` - write the rendered output to an exact file path, using the format selected by `--emit`.- `--save-suffix <name>` - distinguish runs of the same topic (e.g. per client: `--save-suffix=acme`).- `--no-browser-cookies` - hard-disable browser-cookie extraction for this run, even when `FROM_BROWSER` is configured. MCP and folder-mode hosts use this for safe defaults.+- `--publish-html` - with `--emit=html`, publish the rendered HTML to `ht-ml.app` after local output/save-dir writes. This is explicit opt-in only; pages are public by default.+- `--publish-password <password>` - optional shared password for `--publish-html`. Prefer `LAST30DAYS_PUBLISH_PASSWORD=<password>` instead so the password is not visible in the process list or shell history. Use a unique non-personal password; never reuse the user's own password. The provider's update key is treated as secret and is not written to stdout, HTML, raw output, or `.publish.json` metadata.+ - `--preflight` - print a human-readable permission preflight. It reports config source, project config trust/ignore state, browser-cookie plan, planned writes, optional commands, source availability, and endpoint overrides without reading browser cookies, writing setup/config/report files, or running research. Add `--emit=json` for machine-readable preflight JSON; use `--diagnose` when you need the full source diagnostic JSON.The footer line `π Raw results saved to ${LAST30DAYS_MEMORY_DIR:-$HOME/Documents/Last30Days}/<slug>-raw.md` is the canonical pointer; if it shows backslashes on Windows update past v3.1.1.diff --cc skills/last30days/SKILL.mdindex 33eb227f,5e29a77d..cc986106--- a/skills/last30days/SKILL.md+++ b/skills/last30days/SKILL.md@@@ -1853,8 -1865,7 +1865,8 @@@ Close with `I have all the links to th- Read `references/save-html-brief.md` BEFORE proceeding to WAIT FOR USER'S RESPONSE- Follow that file's instructions exactly - it is the canonical source for the save flow- - Append the confirmation line (`π Shareable brief saved to <path>`) to your already-emitted chat response+ - End with the artifact handoff defined there: saved HTML path, open the local file when the host can do so, and a concise confirmation for requests where HTML is the requested deliverable+- If the user explicitly asks for a hosted/shareable web link, follow the opt-in publishing instructions in the reference file. Never publish by default.**You MUST NOT:**diff --cc skills/last30days/references/save-html-brief.mdindex 5ea2093e,a030e340..22a0a67e--- a/skills/last30days/references/save-html-brief.md+++ b/skills/last30days/references/save-html-brief.md@@@ -66,44 -76,41 +76,73 @@@ f# For a scoped --hiring-signals brief, --hiring-signals MUST be here too so# the footer reflects the jobs-scoped board, not a generic crawl.- # 3. Append ONE line to your already-emitted chat response, after the- # invitation block. Use a paperclip emoji as a visible signal that an- # artifact was produced:- echo "π Shareable brief saved to $HTML_PATH"+ # 3. Finish with the artifact handoff described below. Do not print the saved+ # path from the shell block; the chat handoff is the single user-visible+ # completion message.```+## Optional hosted publishing++Only publish when the user explicitly asks for a hosted/shareable web link or confirms they want one after you offer it. Local HTML save remains the default.++Respect any existing user, project, or host preference for HTML publishing first. If the user already has a preferred publisher or internal sharing workflow, use that. Offer `ht-ml.app` only as the fallback hosted option when no preference is already established.++Before publishing, tell the user:++- `ht-ml.app` publishes a public URL by default, and public pages may be crawled or indexed.+- A shared password can be set with `--publish-password`; use a unique non-personal password, not the user's real password.+- The local HTML file is still saved first. If upload fails, the local file remains usable.++Then ask whether they want password protection before uploading. Accept either branch:++- **Public link** - proceed with `--publish-html` only.+- **Password-protected link** - ask them to provide the shared password, then pass it through `LAST30DAYS_PUBLISH_PASSWORD`. Do not put passwords in command-line arguments unless the user explicitly accepts that exposure risk.++When the user opts in and answers the password-protection prompt, add `--publish-html` to the same `--emit=html` command. Use `--output "$HTML_PATH"` rather than shell redirection so the engine can write the `.publish.json` companion metadata next to the local HTML file. On the password-protected branch, set `LAST30DAYS_PUBLISH_PASSWORD` in the subprocess environment instead of passing `--publish-password` in the shell command.++```bash+LAST30DAYS_PUBLISH_PASSWORD="${PUBLISH_PASSWORD:-}" \+"${LAST30DAYS_PYTHON}" "${SKILL_ROOT}/scripts/last30days.py" "${TOPIC}" \+ --emit=html \+ --synthesis-file "$SYNTHESIS_FILE" \+ --output "$HTML_PATH" \+ --publish-html \+ "${SCOPE_FLAGS[@]}" \+ >/dev/null+```++The hosted URL appears on stderr as `[last30days] Published HTML to https://...`. Append a second concise line to the chat response: `π Hosted brief: <url>`. The engine writes URL metadata to `<HTML_PATH>.publish.json`. The provider may return an `update_key`; treat it as secret. The engine deliberately does not write the update key to stdout, the HTML artifact, or `.publish.json` companion metadata.++ ## Chat handoff after saving++ Use the mode that matches the request.++ ### HTML as the requested deliverable++ When HTML is the requested deliverable - whether by `--emit=html`, `--emit:html`, `--html`, or natural-language phrasing - do **not** paste the full Markdown report back into chat after saving the artifact. The user asked for an HTML deliverable; repeating the Markdown makes the run feel like a normal report with an attachment bolted on.++ Respond with a concise handoff:++ ```text+ π last30days v{VERSION} Β· synced {YYYY-MM-DD}++ π Shareable brief saved to <absolute HTML path>++ I saved the full HTML brief locally. It is not uploaded or published anywhere.+ ```++ If the host can safely open local files for the user and doing so matches the user's request, open the HTML file after it is written, leave the saved-path line in chat, and add `Opened locally.` Let the host choose the correct OS-specific mechanism; do not print a menu of shell commands. If opening fails or the host is headless, do not treat that as a failed report; show the path and say the file is ready to open in a browser.++ ### Normal report plus HTML copy++ When the user asked for a normal `/last30days` report and also asked for an HTML copy, keep the full chat synthesis and append this artifact block after the invitation:++ ```text+ π Shareable brief saved to <absolute HTML path>+ ```++ If the host can safely open local files, open it for the user when that matches the request; otherwise the saved-path line is enough. Do not offer public publishing or upload in this flow. Hosted sharing is a separate opt-in capability and must not happen automatically.+## What ends up in the HTML fileThe engine's `--emit=html` renderer combines:@@@ -130,11 -141,9 +173,11 @@@ The engine will try to reuse `~/.config- Do NOT save HTML if the user didn't ask. The sparse mode (no synthesis) produces a thin file; not useful as a shareable.- Do NOT add content to the temp file beyond your synthesis prose. The badge / footer / colophon come from the engine.- Do NOT change the file path convention. `${LAST30DAYS_MEMORY_DIR}/${SLUG}-brief.html` is the canonical location.- - Do NOT silently overwrite an existing file. The `--emit=html` output is written via a shell redirect (`>| "$HTML_PATH"`), which OVERWRITES the collision-guarded path β use `>|` not `>` because `set -o noclobber` refuses plain `>` when the file already exists. The collision guard in step 2 handles same-topic re-runs: if `{slug}-brief.html` already exists it date-suffixes to `{slug}-brief-YYYY-MM-DD.html`. Always print whichever path the redirect actually used.-+ - Do NOT silently overwrite an existing file. The `--emit=html` output is written via a shell redirect (`>| "$HTML_PATH"`), which OVERWRITES the collision-guarded path β use `>|` not `>` because `set -o noclobber` refuses plain `>` when the file already exists. The collision guard in step 2 handles same-topic re-runs: if `{slug}-brief.html` already exists it date-suffixes to `{slug}-brief-YYYY-MM-DD.html`. Always report whichever path the redirect actually used in the chat handoff.- Do NOT include the data quality warning text in the temp file or in your final chat line. Warnings are an engine-stderr concern, not an artifact concern.-- Do NOT publish, upload, or send the HTML to a third-party service. This reference only saves and opens local files.++- Do NOT publish, upload, or send the HTML to a third-party service as part of the local save flow.+- Do NOT publish to `ht-ml.app` merely because HTML was requested. Hosted publishing is a separate opt-in step.+- Do NOT paste or store the `update_key` in chat, Markdown, HTML, raw output, or companion metadata.## Edge casesdiff --cc skills/last30days/scripts/last30days.pyindex 8d2fd112,fd11eb73..0e57f0fb--- a/skills/last30days/scripts/last30days.py+++ b/skills/last30days/scripts/last30days.py@@@ -663,6 -680,118 +723,142 @@@ 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,+ )++ publish_companion_paths: list[Path] = []+ if args.output:+ output_path = save_rendered_output(rendered, args.output)++ if args.emit == "html":++ publish_companion_paths.append(output_path)+ 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,+ )++ if args.emit == "html":++ publish_companion_paths.append(save_path)+ 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()++ if args.publish_html:++ try:++ publish_result = publish_rendered_html(++ rendered,++ password=_publish_password_for_args(args),++ companion_paths=publish_companion_paths,++ )++ sys.stderr.write(f"[last30days] Published HTML to {publish_result['url']}\n")++ for warning in publish_result.get("_metadata_errors") or []:++ sys.stderr.write(f"[last30days] Publish metadata warning: {warning}\n")++ if publish_result.get("update_key"):++ sys.stderr.write(++ "[last30days] ht-ml.app returned an update key; not writing it "++ "to stdout, HTML, or publish metadata.\n"++ )++ sys.stderr.flush()++ except Exception as exc:++ sys.stderr.write(f"[last30days] HTML publish failed: {exc}\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 07292a59,d546ebdd..91f50330--- a/tests/test_doc_flag_contract.py+++ b/tests/test_doc_flag_contract.py@@@ -25,28 -25,20 +25,38 @@@ def test_configuration_documents_new_saflags = _parser_flags()assert "--no-browser-cookies" in flagsassert "--no-browser-cookies" in text+ assert "--preflight" in flags+ assert "--preflight" in textassert "--save-dir" in textassert "--output" in text+ assert "--publish-html" in flags+ assert "--publish-html" in text+ assert "--publish-password" in flags+ assert "--publish-password" in text+ assert "LAST30DAYS_PUBLISH_PASSWORD" in text+++def test_html_publish_reference_prompts_for_password_choice():+ text = HTML_REFERENCE.read_text(encoding="utf-8")+ publish_section = text[text.index("## Optional hosted publishing"):text.index("## What ends up in the HTML file")]+ assert "Respect any existing user, project, or host preference for HTML publishing first" in publish_section+ assert "Offer `ht-ml.app` only as the fallback hosted option" in publish_section+ assert "ask whether they want password protection before uploading" in publish_section+ assert "**Public link** - proceed with `--publish-html` only" in publish_section+ assert "**Password-protected link** - ask them to provide the shared password" in publish_section+ assert "LAST30DAYS_PUBLISH_PASSWORD" in publish_section+ assert '--output "$HTML_PATH"' in publish_section+ assert "<HTML_PATH>.publish.json" in publish_section+ def test_reddit_backend_env_var_is_documented_for_users_and_runtime_skill():+ config_text = CONFIGURATION.read_text(encoding="utf-8")+ skill_text = SKILL_MD.read_text(encoding="utf-8")++ assert "LAST30DAYS_REDDIT_BACKEND=scrapecreators" in config_text+ assert "LAST30DAYS_REDDIT_BACKEND=scrapecreators" in skill_text++def test_save_is_not_documented_as_python_cli_flag():text = CONFIGURATION.read_text(encoding="utf-8")assert "--save-dir <path>" in text