Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(skillturbo): 对齐 pptx-craft custom 内容页填槽模板单一优化

xukangc7099acbeeaf
diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py
index 89f31cba56..f1f2463eaa 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py
@@ -247,11 +247,16 @@ def _extract_designer_section(
新 skill:主文件含「写前版面意图」;弹性布局/HTML/页面布局/视觉在 appendix.md;
图表/图片在 charts.md / images.md,按页类型按需注入。
- for_content_template_fill=True(content-template 填槽):不注入长附录,
- 改用密度短清单;图表候选页仅附图表切片。
+ for_content_template_fill=True(content-template 填槽):不注入长附录;
+ 注入密度短清单 + designer §3.1 C/D/D-2 + 页型最低信息结构表原文;
+ 图表候选页另附图表切片。
"""
if for_content_template_fill:
parts = [_CONTENT_FILL_DENSITY_CHECKLIST]
+ parts.extend(_extract_content_fill_designer_31_slices(text))
+ density_floor = _extract_content_fill_density_floor_slice(text)
+ if density_floor:
+ parts.append(density_floor)
if include_charts:
chart_src = charts_text or text
chart_section = ""
@@ -393,6 +398,48 @@ _CONTENT_FILL_DENSITY_CHECKLIST = """### PAGE_CONTENT 密度硬约束(精简
- 禁止重写 YAML 预算、开 subagent、整页重写骨架。"""
+def _extract_content_fill_designer_31_slices(text: str) -> list[str]:
+ """从 designer 主文件抽取 §3.1 C/D/D-2(止于 3.2),供 content-template 填槽注入。"""
+ if not (text or "").strip():
+ return []
+ # 优先整段 C→D-2(含分块要点 + form 表 + 骨架表);止于 3.2 / 阶段 4。
+ chunk = _extract_bounded_section(
+ text,
+ "**C. 内容分块",
+ ("\n#### 3.2", "\n### 阶段 4", "\n## "),
+ )
+ if chunk:
+ return [chunk]
+ # 无 C 锚点时分别抽 D / D-2(兼容残缺 fixture)。
+ parts: list[str] = []
+ d_form = _extract_bounded_section(
+ text,
+ "**D. 表达形式选择",
+ ("\n**D-2.", "\n**E. 写前版面意图", "\n#### 3.2", "\n## "),
+ )
+ if d_form:
+ parts.append(d_form)
+ d2 = _extract_bounded_section(
+ text,
+ "**D-2. 承载骨架配方",
+ ("\n**E. 写前版面意图", "\n#### 3.2", "\n## "),
+ )
+ if d2:
+ parts.append(d2)
+ return parts
+
+
+def _extract_content_fill_density_floor_slice(text: str) -> str:
+ """从 designer 主文件抽取「按页面类型的最低信息结构」表原文。"""
+ if not (text or "").strip():
+ return ""
+ return _extract_bounded_section(
+ text,
+ "##### 按页面类型的最低信息结构",
+ ("\n##### ", "\n#### ", "\n### ", "\n## "),
+ )
+
+
_PRESET_STYLE_IDS = {"business-classic", "tech-minimal", "elegant-narrative", "industrial-tech"}
# Phase 4:预设四风格 + custom 走官方模板预铺填槽(结构页 + 内容页)。
_AGENDA_TEMPLATE_FILL_STYLE_IDS = _PRESET_STYLE_IDS | {"custom"}
@@ -1408,6 +1455,7 @@ def _validate_custom_content_template_fill_output(
def _build_content_layout_template(page_type: str) -> str:
+ """自由生成路径仍可用页型参考布局;content-template 填槽勿调用本函数。"""
layout = _PAGE_LAYOUT_TEMPLATES.get(page_type, "")
if not layout:
return ""
@@ -1494,7 +1542,8 @@ def _build_content_template_fill_prompt(
f"{task_text.strip()}\n"
)
constraints_block = _style_constraints_block(style_constraints)
- layout_template = _build_content_layout_template(page_type)
+ # 填槽路径不用 Turbo 自创同质 _PAGE_LAYOUT_TEMPLATES;定型权威=已注入的 designer 原文切片。
+ layout_template = ""
rewrite_section = ""
if rewrite_hint:
original_section = ""
@@ -1698,7 +1747,9 @@ def _build_content_template_fill_system_prompt(
)
if style_id == "custom":
prompt = (
- "你是 PPT 内容页模板填充师,不是设计师。"
+ "你是 PPT 内容页模板填充师。"
+ "框架(chrome)只填槽、不得改写;"
+ "{{PAGE_CONTENT}} 须遵守已注入的 designer §3.1 与页型最低信息结构原文。"
"替换预铺 HTML 中实际出现的占位符(含 {{THEME_CSS_VARIABLES}}、"
"{{THEME_CSS_RULES}}、{{PAGE_TITLE}}、{{PAGE_CONTENT}}、{{PAGE_FOOTER}},"
"未提供的主题槽填空)。保留框架 class/@layer/theme-contract 插槽结构;"
@@ -1712,7 +1763,9 @@ def _build_content_template_fill_system_prompt(
prompt += "只输出完整 HTML 原文,不要解释、不要 Markdown 代码块。"
return prompt
prompt = (
- "你是 PPT 内容页模板填充师,不是设计师。"
+ "你是 PPT 内容页模板填充师。"
+ "框架(chrome)只填槽、不得改写;"
+ "{{PAGE_CONTENT}} 须遵守已注入的 designer §3.1 与页型最低信息结构原文。"
"唯一任务:在预铺 HTML 上替换 {{PAGE_TITLE}}、{{PAGE_CONTENT}}、{{PAGE_FOOTER}} 三处占位符。"
)
if is_chart:
diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/slide_designer_worker.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/slide_designer_worker.py
index 27970b7a40..0d6ae3a1b1 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/slide_designer_worker.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/slide_designer_worker.py
@@ -151,7 +151,7 @@ class SlideDesignerWorker:
last_raw = ""
last_reason = ""
html = ""
- chart_activation_warning = False
+ soft_deliver_warning = False
for attempt in range(max(self._policy.max_fill_attempts, 1)):
rewrite_hint = ""
if attempt > 0 and (last_raw or last_reason):
@@ -168,6 +168,9 @@ class SlideDesignerWorker:
if not html:
# 填槽耗尽:custom 先走既有 free_gen;图表未激活最终仍 soft 交付(不进 missing)
+ soft_deliver_reasons = {
+ "chart_scaffold_not_activated",
+ }
if self._policy.allow_free_gen_fallback:
logger.warning(
"[SlideDesignerWorker] 填槽失败,降级 free_generate page=%d reason=%s",
@@ -186,14 +189,14 @@ class SlideDesignerWorker:
fail_reason="" if ok else "write_failed",
path=path,
)
- if last_reason == "chart_scaffold_not_activated" and last_raw.strip():
+ if last_reason in soft_deliver_reasons and last_raw.strip():
logger.warning(
- "[SlideDesignerWorker] 图表 scaffold 未激活,"
- "free_gen 失败仍交付 page=%d",
+ "[SlideDesignerWorker] %s,free_gen 失败仍交付 page=%d",
+ last_reason,
ctx.page_num,
)
html = last_raw
- chart_activation_warning = True
+ soft_deliver_warning = True
else:
last_reason = fb_reason or last_reason
return SlideDesignerResult(
@@ -203,13 +206,14 @@ class SlideDesignerWorker:
fail_reason=last_reason or "fill_failed",
path=path,
)
- elif last_reason == "chart_scaffold_not_activated" and last_raw.strip():
+ elif last_reason in soft_deliver_reasons and last_raw.strip():
logger.warning(
- "[SlideDesignerWorker] 图表 scaffold 未激活,重试耗尽仍交付 page=%d",
+ "[SlideDesignerWorker] %s,重试耗尽仍交付 page=%d",
+ last_reason,
ctx.page_num,
)
html = last_raw
- chart_activation_warning = True
+ soft_deliver_warning = True
else:
return SlideDesignerResult(
page_num=ctx.page_num,
@@ -241,7 +245,7 @@ class SlideDesignerWorker:
path=path,
)
- if layout_warning or chart_activation_warning:
+ if layout_warning or soft_deliver_warning:
warn_reason = layout_reason or last_reason or "chart_scaffold_not_activated"
logger.warning(
"[SlideDesignerWorker] 页面 %d 已标记警告并继续交付: %s",
diff --git a/tests/unit_tests/server/runtime/skill_turbo/test_ppt_content_fill_e.py b/tests/unit_tests/server/runtime/skill_turbo/test_ppt_content_fill_e.py
index c32846d23f..2c4adf606d 100644
--- a/tests/unit_tests/server/runtime/skill_turbo/test_ppt_content_fill_e.py
+++ b/tests/unit_tests/server/runtime/skill_turbo/test_ppt_content_fill_e.py
@@ -49,19 +49,75 @@ _OUTLINE_CONTENT = """### P3: 市场趋势
"""
-def test_extract_designer_for_fill_uses_density_checklist_only():
+_DESIGNER_31_SLICE = """
+#### 3.1 选材与定型(选内容 + 定表达形式)
+
+**C. 内容分块(强制)**
+
+把素材切成 3–6 个内容块。MARKER_C_BLOCKS
+
+**D. 表达形式选择(强制)**
+
+| 素材特征 | 首选形式 | 可选 | 不得使用 |
+| --- | --- | --- | --- |
+| 时间序列、趋势、同比环比 | 折线图 / 柱状图(ECharts) | 带升降标记的指标卡 | 纯文字罗列数值 |
+| 多对象 × 多维度对比 | 表格 / 对比矩阵 | 分组柱状图 | 并列大段文字 |
+
+MARKER_D_FORM_TABLE
+
+**D-2. 承载骨架配方(强制,选完形式紧接着定)**
+
+| 形式 | 稳定骨架 |
+| --- | --- |
+| 表格 / 对比矩阵 | 默认 `<table class="w-full">` 自然行高 |
+| 统计图表 | 见 charts.md 固定配方 |
+
+选定即冻结:承载骨架属于本步的决定。MARKER_D2_SKELETON
+
+**E. 写前版面意图(生成 HTML 前必须完成)**
+
+写前确认 role/form。MARKER_E_INTENT
+
+#### 3.2 版面落地(简化规则)
+
+3.2 不应进入 content-fill 切片 MARKER_32_LEAK
+
+##### 按页面类型的最低信息结构(下限)
+
+| 页面类型 | 最低语义结构 | 证据要求 |
+| --- | --- | --- |
+| `technology` 架构页 | ≥3 个层级或模块 + 职责 + 关系 | 含总结或关键设计原则 |
+| `case` 案例页 | 背景、问题、方案、结果四段 | 结果含至少 1 项可验证指标 |
+
+MARKER_DENSITY_FLOOR
+
+##### 信息表达转换规则
+
+转换规则不应进入下限切片 MARKER_CONVERT_LEAK
+""".strip()
+
+
+def test_extract_designer_for_fill_includes_31_form_not_appendix():
long_designer = (
"## 用户显式要求优先\n必须遵守用户色板\n\n"
- "**E. 写前版面意图**\n长文版面意图若干行\n\n"
+ f"{_DESIGNER_31_SLICE}\n\n"
"## 关键原则\n禁止空卡片\n"
)
out = _extract_designer_section(
long_designer,
for_content_template_fill=True,
- appendix_text="## 弹性布局模式\n很多附录文字\n",
+ appendix_text="## 弹性布局模式\n很多附录文字 MARKER_FLEX_LEAK\n",
)
assert _CONTENT_FILL_DENSITY_CHECKLIST in out
- assert "写前版面意图" not in out
+ assert "MARKER_D_FORM_TABLE" in out
+ assert "MARKER_D2_SKELETON" in out
+ assert "MARKER_C_BLOCKS" in out
+ assert "选定即冻结" in out
+ assert "MARKER_DENSITY_FLOOR" in out
+ assert "按页面类型的最低信息结构" in out
+ assert "MARKER_32_LEAK" not in out
+ assert "MARKER_CONVERT_LEAK" not in out
+ assert "MARKER_FLEX_LEAK" not in out
assert "弹性布局模式" not in out
@@ -77,6 +133,66 @@ def test_extract_designer_for_fill_appends_charts_when_requested():
assert "CHART_SCAFFOLD" in out
+def test_content_fill_prompt_omits_homogeneous_layout_shell_and_uses_31():
+ prompt = _build_content_template_fill_prompt(
+ page_number=3,
+ style_id="custom",
+ style_text="style body",
+ outline_page=_OUTLINE_CONTENT,
+ research_page="趋势数据与对比矩阵",
+ outline_full="full outline unused",
+ seed_html=_MINIMAL_SEED_HTML,
+ designer_md_text=_DESIGNER_31_SLICE,
+ )
+ assert "MARKER_D_FORM_TABLE" in prompt
+ assert "MARKER_D2_SKELETON" in prompt
+ assert "选定即冻结" in prompt
+ assert "MARKER_DENSITY_FLOOR" in prompt
+ assert "本页定型已冻结" not in prompt
+ assert "primary_form" not in prompt
+ assert "禁止跨页复用同一套" not in prompt
+ assert "4-6 个关键数字卡片" not in prompt
+ assert "6 个核心论点卡片" not in prompt
+ assert "参考布局(data 类型" not in prompt
+ assert "参考布局(trend 类型" not in prompt
+
+
+def test_custom_content_fill_system_prompt_requires_31_form_not_anti_designer():
+ text = _build_content_template_fill_system_prompt(
+ style_id="custom",
+ page_type="content",
+ outline_page=_OUTLINE_CONTENT,
+ research_page="research",
+ )
+ assert "不是设计师" not in text
+ assert "§3.1" in text or "designer §3.1" in text
+ assert "页型最低信息结构" in text
+ assert "PAGE_CONTENT" in text
+ assert "chrome" in text.lower() or "框架" in text
+ assert "primary_form" not in text
+
+
+def test_content_fill_prompt_has_no_turbo_form_freeze():
+ outline = """### P5: 模型
+- **类型**: technology
+- **标题**: 分工模型
+"""
+ for style_id in ("custom", "business-classic"):
+ prompt = _build_content_template_fill_prompt(
+ page_number=5,
+ style_id=style_id,
+ style_text="style",
+ outline_page=outline,
+ research_page="research",
+ outline_full="",
+ seed_html=_MINIMAL_SEED_HTML,
+ designer_md_text=_DESIGNER_31_SLICE,
+ )
+ assert "本页定型已冻结" not in prompt
+ assert "layout_recipe_not_realized" not in prompt
+ assert "MARKER_DENSITY_FLOOR" in prompt
+
+
def test_fix_chart_scaffold_activation_strips_html_comment_markers():
html = (
'<div id="chart-1"></div>\n'