返回 last30days-skill
save-html-brief.md
根目录 / skills / last30days / references / save-html-brief.md
1 # Save shareable HTML brief
2
3 This reference file is loaded by the main `SKILL.md` when the user asked for an HTML brief (either through an HTML-looking prompt argument like `--emit=html` / `--emit:html` / `--html`, or in natural language - "give me a shareable HTML brief", "give it to me in HTML", "for Slack", "for Notion", "export as HTML", etc.). The detection happens in `SKILL.md` so that the common no-HTML path stays short; the implementation lives here. Those prompt arguments are user intent signals for the skill; they are not the full Python CLI contract.
4
5 The contract has two modes:
6
7 - **HTML as the requested deliverable** (`--emit=html`, `--emit:html`, `--html`, or prose like "give it to me in HTML"): the HTML artifact is the primary output. Write the synthesis to the temp file, render the HTML, then give a concise artifact handoff in chat instead of pasting the full Markdown report again.
8 - **Normal report plus HTML copy** (the user asks for the normal report and also wants an HTML copy): the synthesis still appears in chat as the primary output. The HTML is an additional artifact saved to disk for sharing. Both happen in the same turn.
9
10 ## When to fire this flow
11
12 - For normal-report-plus-HTML mode: after you have already emitted the full chat response: badge, "What I learned:" (or comparison title), bold-lead-in paragraphs with citations, KEY PATTERNS list, engine footer pass-through, invitation block.
13 - For HTML-as-deliverable mode: after you have drafted the synthesis that will go into the HTML, before emitting the final chat response.
14 - BEFORE the closing invitation and wait for the user's response.
15 - ONLY if the user asked. Do NOT save HTML when the user didn't ask for it.
16
17 ## How to fire it
18
19 ```bash
20 SYNTHESIS_FILE=$(mktemp "${TMPDIR:-/tmp}/last30days-synthesis.XXXXXXXX") || exit "$?"
21 KEEP_SYNTHESIS=false
22 trap 'if [ "$KEEP_SYNTHESIS" = false ]; then rm -f -- "$SYNTHESIS_FILE"; fi' EXIT
23
24 # 1. Write your synthesis prose VERBATIM to a temp file. The synthesis is the
25 # "What I learned:" prose label, the bold-lead-in paragraphs with their
26 # inline citations, and the "KEY PATTERNS from the research:" numbered list.
27 # Do NOT include the badge or the engine footer in the temp file - the engine
28 # adds those when it renders the HTML.
29 # - HTML-as-deliverable mode: use the exact synthesis draft you prepared for
30 # the artifact. Do not paste it to chat first.
31 # - Normal-report-plus-HTML mode: use the exact synthesis text you already
32 # wrote in chat.
33 # In both modes, do not paraphrase, summarize, or reorder. The HTML must read
34 # identically to the intended report in voice and citations.
35 cat >| "${SYNTHESIS_FILE}" << 'SYNTHESIS_EOF' || exit "$?"
36 What I learned:
37
38 **{First headline}** - {body with [name](url) inline citations}
39
40 **{Second headline}** - {body}
41
42 **{Third headline}** - {body}
43
44 KEY PATTERNS from the research:
45 1. {pattern} - per [@handle](url)
46 2. {pattern} - per [r/sub](url)
47 3. {pattern} - per [@handle](url)
48 SYNTHESIS_EOF
49
50 # 2. Convert the synthesis to a self-contained HTML file via the engine.
51 # Use --cached-report with the same topic as your original run. The engine
52 # reuses the original scope and per-entity reports in the structured cache at
53 # ~/.config/last30days/last-report.json to build badge metadata and footer
54 # without re-running source fetchers. That cache is intentionally short-lived
55 # (default: one hour; tune with LAST30DAYS_REPORT_CACHE_TTL_SECONDS, or set
56 # it to 0 to disable reuse). Do not replay --plan, --competitors-plan, or
57 # --x-posts: their temporary files can already be removed. If the cache is
58 # stale, missing, or for a different topic, stderr says
59 # "No matching cached report data" and the command exits without research. Recreate the original
60 # research plans, rerun research with the original scope, and update the
61 # synthesis before retrying this export.
62 SLUG=$(printf '%s\n' "${TOPIC}" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-' | sed 's/^-//;s/-$//')
63 # Render beside the destination, then create a new name atomically. The hard
64 # link refuses existing paths even when another exporter wins the same name.
65 HTML_PATH=$(
66 HTML_TMP=$(mktemp "${LAST30DAYS_MEMORY_DIR}/.last30days-html.XXXXXXXX") || exit "$?"
67 trap 'rm -f -- "$HTML_TMP"' EXIT
68 "${LAST30DAYS_PYTHON}" "${SKILL_DIR}/scripts/last30days.py" "${TOPIC}" \
69 --emit=html \
70 --cached-report \
71 --synthesis-file "${SYNTHESIS_FILE}" \
72 >| "${HTML_TMP}" || exit "$?"
73 "${LAST30DAYS_PYTHON}" -I - "${HTML_TMP}" "${LAST30DAYS_MEMORY_DIR}" "${SLUG}" << 'HTML_PATH_PY'
74 from datetime import date
75 import os
76 from pathlib import Path
77 import sys
78
79 temporary, directory, slug = sys.argv[1:]
80 base = Path(directory) / f"{slug}-brief"
81 dated = f"{base}-{date.today().isoformat()}"
82 candidate = Path(f"{base}.html")
83 suffix = 1
84 while True:
85 try:
86 os.link(temporary, candidate)
87 except FileExistsError:
88 candidate = Path(f"{dated}.html" if suffix == 1 else f"{dated}-{suffix}.html")
89 suffix += 1
90 else:
91 print(candidate)
92 break
93 HTML_PATH_PY
94 ) || exit "$?"
95 # The cached report preserves hiring scope and comparison targeting.
96
97 # Retain both assignments for the publishing decision, even across shell calls.
98 printf 'HTML_PATH=%q\nSYNTHESIS_FILE=%q\n' "$HTML_PATH" "$SYNTHESIS_FILE" || exit "$?"
99 KEEP_SYNTHESIS=true
100 ```
101
102 Show only the finished HTML path in the chat handoff. Keep the owner-only draft until the access decision so the publisher can use the exact synthesis. If the user opens the local file, chooses Done, cancels, or uses a publisher that reads the HTML directly, remove the draft with `rm -f -- "$SYNTHESIS_FILE"`. Use the exact path from the save command. The tool output carries the saved paths between shell calls, and the chat handoff is the single user-visible completion message.
103
104 ## Optional hosted publishing
105
106 Only publish after the local HTML file has already been saved and the user chooses a publish option. The local HTML save is always first, and its absolute path is always shown before any publish/upload step.
107
108 Respect any existing user, project, or host preference for HTML publishing first. If the user already has a preferred publisher or internal sharing workflow, include that option. If multiple publishing options are available, show each as its own choice and include `ht-ml.app` as one option; label `ht-ml.app` as supporting optional password protection. If no preference exists, use `ht-ml.app` as the fallback publishing option.
109
110 Use this decision flow:
111
112 - Save the local HTML file.
113 - Show the absolute saved path.
114 - Then proactively present next-step choices:
115 1. Open HTML file
116 2. Publish to `<preferred/configured service>`; if `ht-ml.app` is shown, say password protection is available
117 3. Done for now
118 - Do not upload until the user chooses a publishing option.
119
120 When publishing to `ht-ml.app`, ask a second question:
121
122 - **Public link** - publish without a password.
123 - **Password-protected link** - ask the user to type the shared password in free form, then publish with that password.
124
125 Before the `ht-ml.app` choice, tell the user that public pages may be crawled or indexed, and that password protection is available. If the user chooses password protection, use a unique shared password they provide for this report; do not use their own account password.
126
127 Agents should discover the current publishing mechanics for the selected service when needed, including by visiting the service site, rather than hard-coding detailed service-specific instructions in chat. For the built-in `ht-ml.app` path, the engine supports `--publish-html`; on the password-protected branch, pass the shared password through `LAST30DAYS_PUBLISH_PASSWORD` rather than command-line arguments.
128
129 When the user chooses the built-in `ht-ml.app` path, restore the saved `HTML_PATH` and `SYNTHESIS_FILE` assignments if the shell changed. Pass the saved HTML path as `--output "$HTML_PATH"` so the engine can write the `.publish.json` companion metadata next to it. On the password-protected branch, set `LAST30DAYS_PUBLISH_PASSWORD` to a non-empty shared password in the subprocess environment; on the public branch, leave `LAST30DAYS_PUBLISH_PASSWORD` unset. If the draft is missing, stop before calling the engine and explain that the original synthesis is unavailable.
130
131 ```bash
132 (
133 [ -f "${SYNTHESIS_FILE:-}" ] || { printf '%s\n' 'The original synthesis draft is unavailable.' >&2; exit 1; }
134 trap 'rm -f -- "$SYNTHESIS_FILE"' EXIT
135 LAST30DAYS_PUBLISH_PASSWORD="${LAST30DAYS_PUBLISH_PASSWORD:-${PUBLISH_PASSWORD:-}}" \
136 "${LAST30DAYS_PYTHON}" "${SKILL_DIR}/scripts/last30days.py" "${TOPIC}" \
137 --emit=html \
138 --cached-report \
139 --synthesis-file "$SYNTHESIS_FILE" \
140 --output "$HTML_PATH" \
141 --publish-html \
142 >/dev/null
143 )
144 ```
145
146 The hosted URL appears on stderr as `[last30days] Published HTML to https://...`. Confirm the result with the hosted URL. If the user chose password protection, also repeat the shared password they selected so they can send the URL and password together. 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.
147
148 ## Chat handoff after saving
149
150 Use the mode that matches the request.
151
152 ### HTML as the requested deliverable
153
154 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.
155
156 Respond with a concise handoff that includes the next-step choices:
157
158 ```text
159 {the engine's first line, copied verbatim}
160
161 📎 Shareable brief saved to <absolute HTML path>
162
163 What do you want to do next?
164 1. Open HTML file
165 2. Publish to <available HTML publishing service> (<service-specific note, e.g. ht-ml.app supports optional password protection>)
166 3. Done for now
167 ```
168
169 If the user chooses open, open the HTML file when the host can safely open local files, 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.
170
171 ### Normal report plus HTML copy
172
173 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:
174
175 ```text
176 📎 Shareable brief saved to <absolute HTML path>
177
178 What do you want to do next?
179 1. Open HTML file
180 2. Publish to <available HTML publishing service> (<service-specific note, e.g. ht-ml.app supports optional password protection>)
181 3. Done for now
182 ```
183
184 If the user chooses open, open it when the host can safely open local files; otherwise the saved-path line is enough. Do not upload in this flow unless the user chooses a publishing option.
185
186 ## What ends up in the HTML file
187
188 The engine's `--emit=html` renderer combines:
189
190 - The engine's badge line at the top
191 - A single inline metadata line (`{date range} · {active sources}`) below the badge
192 - Your synthesis verbatim, with prose labels promoted to `<h2>` and bold lead-ins preserved
193 - All `[name](url)` citations rendered as `<a>` tags
194 - The engine footer (`✅ All agents reported back!` tree) preserved verbatim in monospace
195 - A colophon with the topic and a re-run hint
196
197 The renderer strips engine-internal noise that doesn't belong in a shareable artifact: the `# last30days vX.Y.Z: TOPIC` debug file header, the model-facing `> Safety note:` blockquote, and the `I'm now an expert on X` invitation block. Raw engine stderr logs stay out of the share-ready file; any partial-coverage notes already live in the synthesis prose.
198
199 ## Comparison mode
200
201 Same flow when the topic is `X vs Y` (or `X vs Y vs Z`). Use `--cached-report` without the deleted `--competitors-plan` and `--plan` files. The engine routes the stored entity reports through `render_for_html_comparison`. The synthesis temp file should still contain the comparison-shaped synthesis you wrote in chat (`## Quick Verdict`, `## {Entity}` per entity, `## Head-to-Head` table, `## The Bottom Line`, `## The emerging stack` per LAW 4 comparison exception).
202
203 ## Follow-up turn
204
205 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. Write the synthesis to the temp file. Call the engine with `--cached-report --emit=html --synthesis-file`. Use the normal-report-plus-HTML artifact block.
206
207 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.
208
209 The engine reuses `~/.config/last30days/last-report.json` 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 no matching cache exists, the command stops before research. Recreate the original plans, rerun the original research scope, and update the synthesis before exporting again.
210
211 ## What NOT to do
212
213 - Do NOT save HTML if the user didn't ask. The sparse mode (no synthesis) produces a thin file; not useful as a shareable.
214 - Do NOT add content to the temp file beyond your synthesis prose. The badge / footer / colophon come from the engine.
215 - Do NOT change the file path convention. `${LAST30DAYS_MEMORY_DIR}/${SLUG}-brief.html` is the canonical location.
216 - Do NOT overwrite an existing file. Step 2 renders to a private temporary file and links the completed output to a new name. If `{slug}-brief.html` exists, try `{slug}-brief-YYYY-MM-DD.html`, then `{slug}-brief-YYYY-MM-DD-2.html`, incrementing until a name is available. This also handles concurrent exporters without replacing files, directories, or symlinks. The temporary file is removed on success or failure. If rendering or linking fails, report the error instead of a successful save. Always report the path stored in `HTML_PATH` in the chat handoff.
217 - 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.
218 - Do NOT publish, upload, or send the HTML to a third-party service as part of the local save flow.
219 - Do NOT publish to any service merely because HTML was requested. Show the saved path and next-step choices first; publishing requires the user to choose a publish option.
220 - Do NOT block a local HTML export on a hosting decision unless the user explicitly asked for a hosted URL.
221 - Do NOT paste or store the `update_key` in chat, Markdown, HTML, raw output, or companion metadata.
222
223 ## Edge cases
224
225 - **Topic with shell-special characters** (quotes, ampersands): the file name for the finished brief uses a slug, and the engine receives the raw topic. The quoted `SYNTHESIS_EOF` heredoc preserves synthesis text without expanding it. Pick a delimiter that does not occur on a line by itself in the synthesis.
226 - **Very long synthesis**: no upper bound. The engine handles long markdown bodies. Just paste verbatim.
227 - **Synthesis with images or non-ASCII**: emoji and Unicode pass through. Image tags pass through as raw HTML; the renderer doesn't transform them. If you didn't include images in chat, don't add them here.
228 - **No `${LAST30DAYS_MEMORY_DIR}` set**: defaults to `~/Documents/Last30Days/` per the `Configuration` section of `references/runtime.md`.
229
229 lines MARKDOWN