From Prompt to Production: Engineering Hard‑Core AI Skills with wechat‑publisher
The article defines AI Skill “hard‑core” capabilities versus soft prompt‑based logic, outlines a three‑layer architecture (scripts, metadata, security), and walks through concrete wechat‑publisher implementations—including inline style injection, multi‑template rendering, exit‑code handling, and a step‑by‑step development checklist—to show how to turn AI from a mere text generator into an autonomous executor.
Hard‑core AI Skill Overview
Hard‑core skills extend AI beyond pure‑text reasoning by providing executable code, API integration, and engineering constructs that let the model act on real‑world resources such as sending emails, storing data, or publishing to a WeChat public account.
Three‑Layer Architecture
Business Execution Layer (Scripts) – The script scripts/publish.py performs Markdown conversion, calls the WeChat API, and uploads media. It handles network requests, timeout retries, and binary file uploads that cannot be expressed in text alone.
Core class structure
class WeChatPublisher:
def __init__(self, app_id: str, app_secret: str):
self.access_token = self._get_access_token()
def _get_access_token(self) -> str:
"""获取微信 API 访问令牌"""
def upload_image(self, image_path: str) -> str:
"""上传素材获取 media_id"""
def md_to_wechat_html(self, content: str, template: str = "minimal") -> str:
"""Markdown 转微信兼容 HTML"""
def create_draft(self, title: str, content: str, ...) -> dict:
"""创建草稿并返回结果"""Skill Description Layer (Metadata) – The SKILL.md file tells the AI when and how to invoke the script.
---
name: wechat-publisher
description: 将 Markdown 内容一键推送到微信公众号草稿箱。用户提到"发布到公众号"、"存为草稿"、"同步到微信"时激活此技能。
---Environment Isolation Layer (Security & Config)
Credentials APP_ID and APP_SECRET are stored in a .env file, not hard‑coded.
Dependencies such as requests and markdown are declared explicitly.
wechat-publisher/
├── SKILL.md # Skill description (read by AI)
├── .env # Credential config (not versioned)
├── default_cover.png # Default cover image
└── scripts/
└── publish.py # Core execution scriptKey Implementations in wechat-publisher
Inline Style Injection
Challenge : WeChat strips external CSS and <style> tags, requiring rich formatting via inline styles without breaking existing HTML attributes.
Solution : Define a style‑mapping table per template and apply a regex that preserves any existing attribute suffix.
def md_to_wechat_html(self, content: str, template: str = "minimal") -> str:
html = markdown.markdown(content, extensions=['extra', 'toc', 'tables'])
styles = self._get_styles(template)
for tag, style in styles.items():
pattern = rf'<{tag}(?P<suffix>\s|>)'
def inject_style(match):
suffix = match.group('suffix')
return f'<{tag} style="{style}"{suffix}'
html = re.sub(pattern, inject_style, html)
return htmlMulti‑Template Layout System
minimal– 简约蓝,通用文章、技术博客 tech – 科技蓝,渐变标题,适用于技术教程、AI 相关 elegant – 典雅黑,深度长文、商业分析 fresh – 清新绿,生活类、健康类 minimal-bw – 极简黑白,学术风格 warm-orange – 暖橙色,情感类、故事类 dark – 暗色系,设计类、夜间阅读 business – 商务蓝,企业公告、行业报告
Usage examples:
# Default minimal style
python3 scripts/publish.py --file article.md --title "文章标题"
# Tech style
python3 scripts/publish.py --file article.md --title "文章标题" --template tech
# Elegant style
python3 scripts/publish.py --file article.md --title "文章标题" --template elegantTemplate style definition (excerpt for tech):
"tech": {
"h1": "font-size: 24px; background: linear-gradient(90deg, #0066cc, #00aaff); color: white; padding: 12px 18px; border-radius: 6px;",
"h2": "font-size: 20px; border-bottom: 2px solid #0066cc; padding-bottom: 6px; color: #0066cc;",
"pre": "background: #1e1e1e; color: #d4d4d4; padding: 15px; border-radius: 6px; border-left: 4px solid #0066cc;",
"blockquote": "border-left: 4px solid #0066cc; background: #f0f8ff; padding: 12px 15px; border-radius: 4px;",
# ... more tag styles
}Exit‑Code Management
AI assistants rely on the program’s exit status to decide whether a task succeeded.
Designated codes: 0 – Success (stop AI retry) 1 – Business‑logic failure (AI may retry after fixing parameters) 2 – Configuration or network error (prompt user to check config) 124/137 – Timeout or killed (indicates network issue)
if "media_id" in result:
print("✅ 成功推送到草稿箱!")
sys.exit(0)
else:
print(f"❌ 推送失败: {result}")
sys.exit(1)Reverse‑Engineered CLI Mapping
# UI element → CLI argument
User selects template → --template
Live preview style → style‑mapping dict
Copy HTML button → md_to_wechat_html()
Manual paste publish → API direct pushRobust Exception Handling
def _get_access_token(self) -> str:
print(f"正在获取 Access Token (AppID: {self.app_id[:4]}***)...")
url = f"https://api.weixin.qq.com/cgi-bin/token?..."
try:
response = requests.get(url, timeout=10)
data = response.json()
if "access_token" in data:
print("Access Token 获取成功。")
return data["access_token"]
else:
raise Exception(f"获取失败: {data}")
except requests.exceptions.Timeout:
print("❌ 请求超时,请检查网络连接")
sys.exit(2)
except requests.exceptions.ConnectionError:
print("❌ 网络连接失败,请检查 IP 白名单")
sys.exit(2)
except Exception as e:
print(f"❌ 未知错误: {e}")
sys.exit(1)Skill Development Workflow
Creating a New Skill
# Step 1: Create directory structure
mkdir -p .claude/skills/my-skill/scripts
# Step 2: Write SKILL.md
cat > .claude/skills/my-skill/SKILL.md << 'EOF'
---
name: my-skill
description: 描述这个技能做什么,何时触发。
---
# My Skill
## 操作指令
```
python3 scripts/main.py --param value
```
EOF
# Step 3: Write core script
cat > .claude/skills/my-skill/scripts/main.py << 'EOF'
import sys, argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--param', required=True)
args = parser.parse_args()
print(f"处理参数: {args.param}")
print("✅ 任务完成")
sys.exit(0)
if __name__ == "__main__":
main()
EOF
# Step 4: Test
python3 .claude/skills/my-skill/scripts/main.py --param testQuick‑Start Commands for wechat-publisher
# Install dependencies
pip install requests markdown
# Configure credentials (.env)
cat > .claude/skills/wechat-publisher/.env << 'EOF'
WECHAT_APP_ID=你的AppID
WECHAT_APP_SECRET=你的AppSecret
EOF
# Publish with default style
python3 .claude/skills/wechat-publisher/scripts/publish.py \
--file article.md \
--title "文章标题"
# Publish with a specific template
python3 .claude/skills/wechat-publisher/scripts/publish.py \
--file article.md \
--title "文章标题" \
--template techSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Frontend AI Walk
Looking for a one‑stop platform that deeply merges frontend development with AI? This community focuses on intelligent frontend tech, offering cutting‑edge insights, practical implementation experience, toolchain innovations, and rich content to help developers quickly break through in the AI‑driven frontend era.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
