Skip to content

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

fix: harden optional html publishing

Trevin Chowe12330df3fb0
diff --git a/CONFIGURATION.md b/CONFIGURATION.md
index 89294892..d592aa68 100644
--- a/CONFIGURATION.md
+++ b/CONFIGURATION.md
@@ -46,7 +46,7 @@ The engine's `.env` reader doesn't expand `$HOME` — only the tilde, via `Path(
- `--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`. 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.
+- `--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.
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 --git a/skills/last30days/references/save-html-brief.md b/skills/last30days/references/save-html-brief.md
index e76cbc9a..5ea2093e 100644
--- a/skills/last30days/references/save-html-brief.md
+++ b/skills/last30days/references/save-html-brief.md
@@ -76,6 +76,8 @@ echo "📎 Shareable brief saved to $HTML_PATH"
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.
@@ -85,20 +87,22 @@ Before publishing, tell the user:
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 add `--publish-password "$PUBLISH_PASSWORD"`.
+- **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. Add `--publish-password "$PUBLISH_PASSWORD"` only on the password-protected branch.
+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[@]}" \
- >| "$HTML_PATH"
+ >/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 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.
+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.
## What ends up in the HTML file
diff --git a/skills/last30days/scripts/last30days.py b/skills/last30days/scripts/last30days.py
index 68db7f75..8d2fd112 100644
--- a/skills/last30days/scripts/last30days.py
+++ b/skills/last30days/scripts/last30days.py
@@ -181,11 +181,22 @@ def publish_rendered_html(
from lib import html_publish
result = html_publish.publish_html(rendered, password=password)
+ metadata_errors: list[str] = []
for path in companion_paths or []:
- _write_publish_metadata(path, result)
+ try:
+ _write_publish_metadata(path, result)
+ except OSError as exc:
+ metadata_errors.append(f"{path}: {exc}")
+ if metadata_errors:
+ result = dict(result)
+ result["_metadata_errors"] = metadata_errors
return result
+def _publish_password_for_args(args: argparse.Namespace) -> str | None:
+ return (args.publish_password or os.environ.get("LAST30DAYS_PUBLISH_PASSWORD") or None)
+
+
def emit_output(
report: schema.Report,
emit: str,
@@ -329,7 +340,7 @@ def build_parser() -> argparse.ArgumentParser:
parser.add_argument("--publish-html", action="store_true",
help="Publish --emit=html output to ht-ml.app (explicit opt-in; public by default)")
parser.add_argument("--publish-password",
- help="Optional shared password for --publish-html")
+ help="Optional shared password for --publish-html; prefer LAST30DAYS_PUBLISH_PASSWORD to avoid exposing secrets in process lists")
parser.add_argument("--store", action="store_true", help="Persist ranked findings to the SQLite research store")
parser.add_argument("--x-handle", help="X handle for targeted supplemental search")
parser.add_argument("--x-related", help="Comma-separated related X handles (searched with lower weight)")
@@ -1267,10 +1278,12 @@ def main() -> int:
try:
publish_result = publish_rendered_html(
rendered,
- password=args.publish_password,
+ 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 "
diff --git a/tests/test_doc_flag_contract.py b/tests/test_doc_flag_contract.py
index 1757a2e4..07292a59 100644
--- a/tests/test_doc_flag_contract.py
+++ b/tests/test_doc_flag_contract.py
@@ -31,15 +31,20 @@ def test_configuration_documents_new_safety_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 "Add `--publish-password \"$PUBLISH_PASSWORD\"` only on the password-protected branch" 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_save_is_not_documented_as_python_cli_flag():
diff --git a/tests/test_html_publish.py b/tests/test_html_publish.py
index f9af70c6..a26ae8fc 100644
--- a/tests/test_html_publish.py
+++ b/tests/test_html_publish.py
@@ -171,6 +171,66 @@ class HtmlPublishCliTests(unittest.TestCase):
self.assertEqual("https://site.ht-ml.app", metadata["url"])
self.assertNotIn("update_key", metadata)
+ def test_publish_uses_password_from_environment(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ output_path = Path(tmp) / "brief.html"
+ with mock.patch.object(cli.env, "get_config", return_value={}), \
+ mock.patch.object(cli.pipeline, "diagnose", return_value=_diag()), \
+ mock.patch.object(cli.pipeline, "run", return_value=_report()), \
+ mock.patch.object(cli, "emit_output", return_value="<html>brief</html>"), \
+ mock.patch("lib.html_publish.publish_html", return_value={
+ "url": "https://site.ht-ml.app",
+ }) as publish_mock, \
+ mock.patch.object(sys, "argv", [
+ "last30days.py",
+ "OpenClaw",
+ "--emit=html",
+ "--output",
+ str(output_path),
+ "--publish-html",
+ ]), \
+ mock.patch.dict(os.environ, {
+ "LAST30DAYS_SKIP_PREFLIGHT": "1",
+ "LAST30DAYS_PUBLISH_PASSWORD": "share-pass",
+ }, clear=False):
+ stdout = io.StringIO()
+ stderr = io.StringIO()
+ with redirect_stdout(stdout), redirect_stderr(stderr):
+ rc = cli.main()
+
+ self.assertEqual(0, rc)
+ self.assertEqual("share-pass", publish_mock.call_args.kwargs["password"])
+
+ def test_publish_metadata_failure_still_reports_url(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ output_path = Path(tmp) / "brief.html"
+ with mock.patch.object(cli.env, "get_config", return_value={}), \
+ mock.patch.object(cli.pipeline, "diagnose", return_value=_diag()), \
+ mock.patch.object(cli.pipeline, "run", return_value=_report()), \
+ mock.patch.object(cli, "emit_output", return_value="<html>brief</html>"), \
+ mock.patch("lib.html_publish.publish_html", return_value={
+ "url": "https://site.ht-ml.app",
+ "site_id": "site_123",
+ }), \
+ mock.patch.object(cli, "_write_publish_metadata", side_effect=PermissionError("denied")), \
+ mock.patch.object(sys, "argv", [
+ "last30days.py",
+ "OpenClaw",
+ "--emit=html",
+ "--output",
+ str(output_path),
+ "--publish-html",
+ ]), \
+ mock.patch.dict(os.environ, {"LAST30DAYS_SKIP_PREFLIGHT": "1"}, clear=False):
+ stdout = io.StringIO()
+ stderr = io.StringIO()
+ with redirect_stdout(stdout), redirect_stderr(stderr):
+ rc = cli.main()
+
+ self.assertEqual(0, rc)
+ self.assertIn("Published HTML to https://site.ht-ml.app", stderr.getvalue())
+ self.assertIn("Publish metadata warning", stderr.getvalue())
+
def test_publish_failure_preserves_local_output(self):
with tempfile.TemporaryDirectory() as tmp:
output_path = Path(tmp) / "brief.html"