executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
zhili-illustration为「直隶按察使」公众号长文统一配图。读取 HTML → 提取 shot list → mmx image generate 生图 → 上传微信素材 → 注入 HTML。 触发条件:用户说「配图」「生成插图」「zhili-illustration」「给文章配图」。
Independent GitHub snapshot · Automated classification · Original documentation governs
name: zhili-illustration description: > 为「直隶按察使」公众号长文统一配图。读取 HTML → 提取 shot list → mmx image generate 生图 → 上传微信素材 → 注入 HTML。 触发条件:用户说「配图」「生成插图」「zhili-illustration」「给文章配图」。 triggers:
HTML → 提取 shot list → mmx image generate ×N
↓
下载图片
↓
微信素材上传 → mmbiz URL
↓
注入 HTML → HTML-FINAL
从 HTML 读取所有 H2 章节,每个 H2 对应一张配图。
from bs4 import BeautifulSoup
def extract_shots(html_path):
with open(html_path, encoding='utf-8') as f:
html = f.read()
soup = BeautifulSoup(html, 'html.parser')
shots = []
for h2 in soup.find_all('h2'):
title = h2.get_text(strip=True)
if title:
shots.append(title)
return shots
Shot 即章节标题,不需要另外写 prompt。mmx 会根据标题语义生成契合图片。
每张图用 mmx image generate,比例 16:9,输出到统一目录。
# 单张
mmx image generate \
--prompt "Open source autonomous driving dashboard, futuristic HUD, self-driving car interface, dark blue theme" \
--aspect-ratio 16:9 \
--out-dir /tmp/zhili-illustration/ \
--out-prefix "shot-01" \
--quiet
# 并发生图(可用 & / xargs -P)
for i in "${!shots[@]}"; do
n=$((i+1))
mmx image generate \
--prompt "Caption for: ${shots[$i]}" \
--aspect-ratio 16:9 \
--out-dir /tmp/zhili-illustration/ \
--out-prefix "shot-$(printf '%02d' $n)" \
--quiet \
&
done
wait
Prompt 优化策略:
futuristic, dark theme, neon accentsopen source, community, code interfaceclean editorial, portrait styleminimalist product shot, clean background用 publish_zhili.py 内部函数,避免硬编码凭证。
import sys, os
sys.path.insert(0, os.path.expanduser(
"~/.hermes/skills/social-media/.agents/skills/zhili-publish/scripts/"
))
from publish_zhili import load_config, get_access_token, upload_article_image
def upload_to_mmbiz(image_path):
config = load_config()
token = get_access_token(config["APPID"], config["APPSECRET"])
return upload_article_image(token, image_path)
mmbiz_urls = {}
for i, shot in enumerate(shots, 1):
local = f"/tmp/zhili-illustration/shot-{i:02d}.png"
url = upload_to_mmbiz(local)
mmbiz_urls[i] = url
统计 HTML 中「图片」占位符数量,逐一替换为 mmbiz URL。
def inject_mmbiz(html, mmbiz_urls):
for i, url in mmbiz_urls.items():
placeholder = f'<img src="图片{i}">'
replacement = f'<img src="{url}">'
html = html.replace(placeholder, replacement, 1)
return html
with open("article-final.html", "w", encoding="utf-8") as f:
f.write(final_html)
/tmp/zhili-illustration/shot-01.png … shot-NN.png — 配图原图{html_同目录}/xxx-final.html — 已注入 mmbiz URL 的发布用 HTML凭证由 zhili-publish/scripts/publish_zhili.py 的 load_config() 管理,
无需传入 APPID/APPSECRET。技能内部通过 sys.path.insert 复用。
封面图也使用本技能的视觉规范:无文字、问号人 IP、统一画风、按公众号封面比例裁切。
zhiliGitHub / zhiligeoreport 可在各自 push.py 中复用本规范生成 16:9 底图,再裁切为 900×383 并用 material/add_material 上传。
要求:封面生成失败必须中断发布,不允许继续上传不存在或旧封面。
<img src="图片N"> 格式(N 从 1 开始连续)