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): 修复目录校验过严导致PPT生成失败问题,对齐基于完整html的内容页重试与再填契约

Kinsamd50e40e6bbed
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 0c2963d77e..f4cb1b25b1 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
@@ -610,8 +610,11 @@ def _extract_head_url_fingerprint(html: str) -> frozenset[str]:
return frozenset(urls)
-# agenda 条目编号模式:>01< ~ >09<(模板内编号 span)
-_AGENDA_ITEM_NUM_RE = re.compile(r">0([1-9])<")
+# agenda 模板注释锚点:预设模板默认保留 `<!-- 条目 N -->` / `<!-- 01 -->` / `<!-- Ⅰ -->`
+_AGENDA_ITEM_COMMENT_RE = re.compile(
+ r"<!--\s*(?:条目\s*\d+|0*\d+|[ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ]+)\s*-->",
+ re.IGNORECASE,
+)
# 大纲中研究需求 ✅ 行模式
_OUTLINE_RESEARCH_REQ_RE = re.compile(r"\*\*研究需求\*\*.*?✅")
@@ -639,8 +642,26 @@ def _find_agenda_page_num(outline_text: str) -> int:
def _count_agenda_items(html: str) -> int:
- """从 agenda 页 HTML 中统计条目数(按编号 01-09 去重计数)。"""
- return len(set(_AGENDA_ITEM_NUM_RE.findall(html or "")))
+ """从 agenda 页 HTML 中统计条目数。
+
+ 对齐 pptx-craft:目录条目允许随风格使用 01/罗马数字/P03 等不同展示形式,
+ 因此这里只按条目结构做宽松统计,不把编号字面量当作硬门禁。
+ """
+ if not html:
+ return 0
+
+ comment_hits = _AGENDA_ITEM_COMMENT_RE.findall(html)
+ if comment_hits:
+ return len(set(comment_hits))
+
+ main_match = _MAIN_BLOCK_RE.search(html)
+ scan_html = main_match.group(0) if main_match else html
+ item_count = 0
+ for match in _VISIBLE_TEXT_LEAF_RE.finditer(scan_html):
+ marker = _normalize_page_marker_text(match.group("text"))
+ if _VISIBLE_PAGE_MARKER_RE.fullmatch(marker):
+ item_count += 1
+ return item_count
def _validate_agenda_item_count(
@@ -1121,6 +1142,7 @@ def _build_content_template_fill_prompt(
user_query: str = "",
total_pages: int = 0,
rewrite_hint: str = "",
+ original_html: str = "",
) -> str:
"""内容页 content-template 预铺填槽 prompt(四预设三槽;custom 含 THEME_*)。"""
user_query_section = ""
@@ -1167,6 +1189,13 @@ def _build_content_template_fill_prompt(
f"{rewrite_hint}\n"
"⚠️ 仅修复上述不通过项,不要改动其他正常部分。\n"
)
+ if original_html:
+ rewrite_section += (
+ "⚠️ 本轮必须以“上次产物(原始 HTML)”为编辑基底做定点修复,"
+ "不要回退为从预铺 seed 模板重新整页填充。\n"
+ "⚠️ `seed_html` 仅用于约束骨架/Chrome/占位符边界;"
+ "`original_html` 才是当前页面已形成状态的来源。\n"
+ )
if is_chart_candidate:
if style_id == "custom":
rewrite_section += (
@@ -1329,6 +1358,14 @@ def _build_content_template_fill_prompt(
seed_caption = (
"## 预铺模板 HTML(只填槽,勿重写;Chrome 必须与下方稿逐字节一致,除三处占位符外)\n"
)
+ original_html_section = ""
+ if original_html:
+ original_html_section = (
+ "\n## 上次产物(原始 HTML,作为本轮定点修复基底)\n"
+ "```html\n"
+ f"{original_html}\n"
+ "```\n"
+ )
return (
f"{user_query_section}"
f"{task_line}"
@@ -1347,6 +1384,7 @@ def _build_content_template_fill_prompt(
f"{designer_section}"
f"{layout_template}\n"
f"{rewrite_section}"
+ f"{original_html_section}"
f"{seed_caption}"
f"{seed_html}\n"
)
@@ -5011,14 +5049,11 @@ class PageWorkerNode(DisableThinkingMixin, PlanNode):
sorted(vote_deviant),
)
- # agenda 条目数校验:目录页条目数必须等于大纲内容章节数
+ # agenda 条目数校验:仅记 warning,不把已生成的目录页打成 missing。
agenda_deviant = _validate_agenda_item_count(outline_full, vote_pages)
if agenda_deviant:
- missing_pages.extend(
- p for p in agenda_deviant if p not in missing_pages
- )
logger.warning(
- "[P8.1] agenda 条目数与大纲内容章节数不匹配 pages=%s,转 missing 走补写",
+ "[P8.1] agenda 条目数与大纲内容章节数不匹配 pages=%s(仅警告,不进 missing)",
sorted(agenda_deviant),
)
@@ -5468,7 +5503,7 @@ class PageWorkerNode(DisableThinkingMixin, PlanNode):
)
async def _generate_content_template_fill(
- self, ctx: PageGenContext, *, rewrite_hint: str = ""
+ self, ctx: PageGenContext, *, rewrite_hint: str = "", original_html: str = ""
) -> tuple[str, str, str]:
"""四预设 ∪ custom 内容页:官方 content-template 预铺填槽。
@@ -5508,6 +5543,7 @@ class PageWorkerNode(DisableThinkingMixin, PlanNode):
user_query=ctx.user_query,
total_pages=ctx.total_pages,
rewrite_hint=rewrite_hint,
+ original_html=original_html,
),
system_prompt=_build_content_template_fill_system_prompt(
style_id=ctx.style_id,
@@ -5544,7 +5580,7 @@ class PageWorkerNode(DisableThinkingMixin, PlanNode):
return (filled or "", "", "")
if _uses_content_template_fill(ctx.style_id, page_type, ctx.outline_page):
return await self._generate_content_template_fill(
- ctx, rewrite_hint=rewrite_hint
+ ctx, rewrite_hint=rewrite_hint, original_html=original_html
)
try:
@@ -6431,7 +6467,7 @@ class PPTPageGenNode(PlanNode):
check_ok = False
break
- # agenda 条目数校验:读取生成的 agenda 页 HTML,比对大纲内容章节数
+ # agenda 条目数校验:仅记 warning,不把已生成的目录页打成 missing。
agenda_page_num = _find_agenda_page_num(outline_text)
if agenda_page_num and agenda_page_num not in missing_pages:
agenda_path = f"{pages_dir}/page-{agenda_page_num}.pptx.html"
@@ -6441,10 +6477,9 @@ class PPTPageGenNode(PlanNode):
item_count = _count_agenda_items(agenda_html)
if content_chapters > 0 and item_count != content_chapters:
logger.warning(
- "[P8-TP] agenda 条目数(%d) ≠ 大纲内容章节数(%d) page=%d,转 missing 走补写",
+ "[P8-TP] agenda 条目数(%d) ≠ 大纲内容章节数(%d) page=%d(仅警告,不进 missing)",
item_count, content_chapters, agenda_page_num,
)
- missing_pages.append(agenda_page_num)
ppt_gen_status = "ok"
if missing_pages:
diff --git a/tests/unit_tests/server/runtime/skill_turbo/test_pptx_craft_compat_adapt.py b/tests/unit_tests/server/runtime/skill_turbo/test_pptx_craft_compat_adapt.py
index d2892a4889..aec600daba 100644
--- a/tests/unit_tests/server/runtime/skill_turbo/test_pptx_craft_compat_adapt.py
+++ b/tests/unit_tests/server/runtime/skill_turbo/test_pptx_craft_compat_adapt.py
@@ -9,8 +9,11 @@ import json
import pytest
from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_page_gen import (
+ PageGenContext,
+ PageWorkerNode,
_build_content_template_fill_prompt,
_build_content_template_fill_system_prompt,
+ _count_agenda_items,
_build_page_gen_rewrite_hint,
_extract_chart_scaffold_region,
_extract_designer_section,
@@ -168,6 +171,20 @@ def test_content_fill_prompt_non_chart_page_skips_chart_section():
assert "OUTLINE_FULL_MARKER" not in prompt
+def test_content_fill_prompt_retry_uses_original_html_as_edit_base():
+ prompt = _minimal_fill_prompt(
+ style_id="business-classic",
+ outline_page="**类型**:data\n**标题**:数据页",
+ rewrite_hint="修复 chart 容器高度链",
+ original_html="<html><body><main><section>旧版本</section></main></body></html>",
+ )
+
+ assert "上次产物(原始 HTML,作为本轮定点修复基底)" in prompt
+ assert "<section>旧版本</section>" in prompt
+ assert "本轮必须以“上次产物(原始 HTML)”为编辑基底做定点修复" in prompt
+ assert "`seed_html` 仅用于约束骨架/Chrome/占位符边界;`original_html` 才是当前页面已形成状态的来源。" in prompt
+
+
def test_content_fill_prompt_custom_vs_preset_page_content_rules():
custom_prompt = _minimal_fill_prompt(style_id="custom")
preset_prompt = _minimal_fill_prompt(style_id="business-classic")
@@ -216,6 +233,86 @@ def test_is_chart_candidate_structural_never_elevates():
)
+def test_count_agenda_items_accepts_custom_target_page_markers():
+ html = """
+ <div class="ppt-slide" type="agenda">
+ <main>
+ <section><span>P03</span><p>市场概览</p></section>
+ <section><span>P05</span><p>竞争格局</p></section>
+ <section><span>P07</span><p>落地路径</p></section>
+ </main>
+ </div>
+ """
+
+ assert _count_agenda_items(html) == 3
+
+
+def test_count_agenda_items_accepts_preset_roman_anchor_comments():
+ html = """
+ <div class="ppt-slide agenda-stage" type="agenda">
+ <div class="grid">
+ <!-- Ⅰ -->
+ <div><span>Ⅰ</span><p>背景</p></div>
+ <!-- Ⅱ -->
+ <div><span>Ⅱ</span><p>策略</p></div>
+ <!-- Ⅲ -->
+ <div><span>Ⅲ</span><p>执行</p></div>
+ </div>
+ </div>
+ """
+
+ assert _count_agenda_items(html) == 3
+
+
+def test_count_agenda_items_ignores_visible_page_marker_outside_main():
+ html = """
+ <div class="ppt-slide" type="agenda">
+ <main>
+ <section><span>P03</span><p>市场概览</p></section>
+ <section><span>P05</span><p>竞争格局</p></section>
+ <section><span>P07</span><p>落地路径</p></section>
+ </main>
+ <span data-skill-turbo-page-number="true">第 03 页 / 共 12 页</span>
+ </div>
+ """
+
+ assert _count_agenda_items(html) == 3
+
+
+def test_count_agenda_items_deduplicates_repeated_comment_anchors():
+ html = """
+ <div class="ppt-slide agenda-stage" type="agenda">
+ <div class="grid">
+ <!-- 01 -->
+ <div><span>01</span><p>背景</p></div>
+ <!-- 01 -->
+ <div><span>01</span><p>背景</p></div>
+ <!-- 02 -->
+ <div><span>02</span><p>策略</p></div>
+ </div>
+ </div>
+ """
+
+ assert _count_agenda_items(html) == 2
+
+
+def test_count_agenda_items_accepts_double_digit_comment_anchors():
+ html = """
+ <div class="ppt-slide agenda-stage" type="agenda">
+ <div class="grid">
+ <!-- 09 -->
+ <div><span>09</span><p>阶段一</p></div>
+ <!-- 10 -->
+ <div><span>10</span><p>阶段二</p></div>
+ <!-- 11 -->
+ <div><span>11</span><p>阶段三</p></div>
+ </div>
+ </div>
+ """
+
+ assert _count_agenda_items(html) == 3
+
+
def test_content_fill_prompt_content_type_elevated_by_data_needs():
prompt = _minimal_fill_prompt(
style_id="business-classic",
@@ -495,3 +592,48 @@ async def test_skill_turbo_template_path_bypass_hard_fails():
error = str(result.get("error") or "")
assert "自定义模板" in error or "模板包" in error
assert "skill_tool" in error
+
+
+async def test_generate_one_passes_original_html_to_content_template_fill(monkeypatch):
+ node = object.__new__(PageWorkerNode)
+ captured: dict[str, str] = {}
+
+ async def fake_generate_content_template_fill(self, ctx, *, rewrite_hint="", original_html=""):
+ captured["rewrite_hint"] = rewrite_hint
+ captured["original_html"] = original_html
+ return "<html></html>", "", ""
+
+ monkeypatch.setattr(
+ PageWorkerNode,
+ "_generate_content_template_fill",
+ fake_generate_content_template_fill,
+ )
+
+ ctx = PageGenContext(
+ page_num=3,
+ style_id="business-classic",
+ style_text="style stub",
+ outline_page=_RESEARCH_OUTLINE,
+ research_page="research stub",
+ outline_is_full=False,
+ image_map_page="",
+ designer_md_text="",
+ user_query="",
+ total_pages=8,
+ pptx_root="D:/pptx-craft",
+ outline_full=_RESEARCH_OUTLINE,
+ )
+
+ html, raw_html, reason = await PageWorkerNode._generate_one(
+ node,
+ ctx,
+ rewrite_hint="仅修复 overflow",
+ original_html="<html><body><main>旧页</main></body></html>",
+ )
+
+ assert html == "<html></html>"
+ assert raw_html == ""
+ assert reason == ""
+ assert captured["rewrite_hint"] == "仅修复 overflow"
+ assert captured["original_html"] == "<html><body><main>旧页</main></body></html>"