Science Slides
БесплатноЗапускает вложенные скриптыНе проверенUse after report-writer when a Chinese academic-style proposal (开题报告) slide deck is needed; generates a PPTX with python-pptx.
от yihanghu200466 установок в других каталогахОб этом скилле
Skill 9:science-slides — 开题报告 PPT
触发:需要生成中文学术风格开题报告 PPT,通常在 report-writer 之后使用。
依赖:pip install python-pptx(通过 exec 安装)
Trajectory Memory Protocol
Before executing this skill, follow skills/trajectory-memory/SKILL.md: read
trajectory_context.md and recent trajectory_memory.jsonl as workflow prior.
After meaningful template, outline, render, or export decisions, append a
S9_ScienceSlides trajectory record. Do not treat trajectory memory as evidence.
工作流(四步走)
Step 0 检测用户模板 ← ~/slides/templates/*.pptx 或用户指定路径
↓ 有模板 → 模板模式(克隆背景复用)
↓ 无模板 → 从零绘制(academic-zh.md 默认样式)
Step 1 加载/初始化样式 ← ~/slides/styles/academic-zh.md
Step 2 生成 HTML 预览 → 输出到聊天界面(用户确认配色与布局)
Step 3 生成完整 .pptx → state/projects/<slug>/slides/开题报告.pptx
Step 0:检测用户模板(模板模式 vs 从零绘制)
检测路径(按优先级):
- 用户本次对话中提供的
.pptx路径 slides/templates/目录(workspace 相对路径,即~/.openclaw/workspace-scientist/slides/templates/)下的.pptx文件(取最新修改的)- USER_CONFIG.md 中配置的
template_path字段(绝对路径,如C:\Users\hp\Downloads\模版.pptx) - 无模板 → 进入从零绘制流程
模板检测代码(Step 0 执行时运行):
import os, re, glob
def find_template(slug: str) -> str | None:
"""Return template path by priority, or None if not found."""
workspace = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Priority 1: user-provided in conversation (passed as argument)
# handled by caller
# Priority 2: slides/templates/ in workspace
tmpl_dir = os.path.join(workspace, "slides", "templates")
if os.path.isdir(tmpl_dir):
pptx_files = glob.glob(os.path.join(tmpl_dir, "*.pptx"))
if pptx_files:
return max(pptx_files, key=os.path.getmtime)
# Priority 3: template_path field in USER_CONFIG.md
config_path = os.path.join(workspace, "USER_CONFIG.md")
if os.path.isfile(config_path):
with open(config_path, encoding="utf-8") as f:
for line in f:
m = re.match(r'\s*-\s*\*\*template_path\*\*:\s*(.+)', line)
if m:
tp = m.group(1).strip()
if tp and os.path.isfile(tp):
return tp
return None # → 从零绘制
模板缓存:检测到模板后,立即复制到项目目录:
import shutil, os
CACHE_PATH = f"state/projects/{slug}/slides/template_cache.pptx"
os.makedirs(os.path.dirname(CACHE_PATH), exist_ok=True)
if not os.path.exists(CACHE_PATH):
shutil.copy2(template_path, CACHE_PATH)
print(f"Template cached: {CACHE_PATH}")
else:
print(f"Using cached template: {CACHE_PATH}")
# 后续所有操作均从 CACHE_PATH 读取,不再依赖原始路径
template_path = CACHE_PATH
缓存规则:
- 同一项目首次使用时复制,之后复用缓存(即使原始文件被删除或移动)
- 用户更换模板时需显式说明 → 覆盖缓存后重新生成
- 缓存文件名固定为
template_cache.pptx,不含原始文件名(避免路径中文或空格问题)
模板模式:用 Presentation(template_path) 打开,继承背景图、主题配色、字体方案,用 clone_slide 复用内容页背景:
from lxml import etree
import copy
def clone_slide(prs, source_slide):
"""克隆幻灯片,保留背景图和所有形状,重新映射图片关系。"""
new_slide = prs.slides.add_slide(source_slide.slide_layout)
# 复制所有非 layout 关系,建立 rId 映射
rId_map = {}
for rId, rel in source_slide.part.rels.items():
if 'slideLayout' in rel.reltype:
continue
if not rel.is_external:
new_rId = new_slide.part.relate_to(rel.target_part, rel.reltype)
rId_map[rId] = new_rId
# 深拷贝 spTree,替换 rId 引用
src_xml = etree.tostring(source_slide.shapes._spTree, encoding='unicode')
for old_rId, new_rId in rId_map.items():
src_xml = src_xml.replace(f'"{old_rId}"', f'"{new_rId}"')
new_spTree = etree.fromstring(src_xml)
dst_spTree = new_slide.shapes._spTree
dst_spTree.getparent().replace(dst_spTree, new_spTree)
return new_slide
标准用法:
prs = Presentation(template_path)
COVER_PROTO = prs.slides[0] # 封面原型
CONTENT_PROTO = prs.slides[1] # 内容页原型(含背景图)
N_PROTOS = len(prs.slides) # 最后删除原始 demo 幻灯片
# 按需克隆
cover = clone_slide(prs, COVER_PROTO)
s2 = clone_slide(prs, CONTENT_PROTO)
# ... 其余内容页同理
# 删除原始 demo 幻灯片
for _ in range(N_PROTOS):
rId = prs.slides._sldIdLst[0].rId
prs.part.drop_rel(rId)
del prs.slides._sldIdLst[0]
设置占位符文字(必须清除所有段落,防止模板残留文字):
from pptx.oxml.ns import qn
def set_placeholder(slide, idx, text, size_pt=None, bold=None, color=None):
for ph in slide.placeholders:
if ph.placeholder_format.idx == idx:
tf = ph.text_frame
tf.word_wrap = True
# ⚠️ 必须删除第一段之后的所有段落(模板常有多段残留)
txBody = tf._txBody
for extra_p in txBody.findall(qn('a:p'))[1:]:
txBody.remove(extra_p)
p = tf.paragraphs[0]
p.clear()
run = p.add_run()
run.text = text
if size_pt: run.font.size = Pt(size_pt)
if bold is not None: run.font.bold = bold
if color: run.font.color.rgb = color
return
Step 1:样式加载
读取 ~/slides/styles/academic-zh.md:
- 文件存在 → 加载其中的配色、字体、布局参数,覆盖以下默认值
- *文件不存在
Установить Science Slides в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Science Slides?
Use after report-writer when a Chinese academic-style proposal (开题报告) slide deck is needed; generates a PPTX with python-pptx.
Как установить скилл Science Slides?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Science Slides запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
docx
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
от AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
от Anthropicxlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
от Anthropicpptx
Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…
от Anthropic