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): 修复 exclude 后仍被 page_count+2 抬总页,改以 outline/total_pages 为权威
xukang771868e7f9de
diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/content_plan.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/content_plan.pyindex 1fd58956ca..9fa0cbd790 100644--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/content_plan.py+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/content_plan.py@@ -121,11 +121,10 @@ _P43_COMMON_RULES = pipeline_role_boundary("P4.3") + ("4. 内容页数(研究需求:✅):\n"" - 严格模式(用户已指定页数):必须等于 page_count\n"" - 扩展模式(用户给出维度/结构意图且未指定页数):必须 ≥ page_count\n"- " 封面(cover)、结束页(ending)及用户明确要求的结构页(section/agenda/chapter 等)标 ❌,"- "其余页必须标 ✅。\n"- " 中间结构页的添加规则见下方「中间结构页」指令(由系统根据用户需求动态注入)。\n"- " **页面顺序**:cover 必须是 P1(首页),ending 必须是末页(P{总页数})。\n"- " **ending 页约束**:标题优先「感谢聆听」或 ≤16 字简短收束语;全文总结、数据回响、趋势展望必须"+ " 用户明确要求的中间结构页(section/agenda/chapter 等)标 ❌,其余内容页标 ✅。\n"+ " **首尾页与中间结构页规则**见下方动态指令(由系统按 page_structure_mode / "+ "exclude_cover_ending / structural_page_request 注入;禁止与动态指令矛盾)。\n"+ " **ending 页约束**(仅当生成 ending 时):标题优先感谢语/收束语(≤16 字);全文总结、数据回响、趋势展望必须""放在最后一个内容页(✅),不得把长总结句写入 ending 页标题;ending 页内容概要只描述结束页展示""(感谢语、可选一句总结语、汇报人/日期),不得复制正文页大纲。\n"" **agenda 页内容**:内容概要只列内容页(✅)章节标题与导航,不得列入 cover/ending/agenda 等"@@ -872,40 +871,85 @@ def _has_no_image_source(inputs: dict[str, Any]) -> bool:return not need_imagegen+def _build_cover_ending_directive(inputs: dict[str, Any]) -> str:+ """按 page_structure_mode / exclude_cover_ending 注入首尾规则(互斥,对齐 outline-planner)。"""+ mode = str(inputs.get("page_structure_mode") or "default").strip().lower()+ if mode == "explicit_sequence":+ return (+ "- 首尾结构页(page_structure_mode=explicit_sequence):"+ "按 user_structure 逐页清单逐项一页映射,条目数必须等于 total_pages;"+ "只把用户明确标为封面/目录/章节/结束的项设为结构页 ❌,其余为内容页 ✅;"+ "不得自动增加 cover、ending、agenda、section 或 chapter;"+ "首页/末页不强制为 cover/ending。\n"+ )+ exclude = bool(inputs.get("exclude_cover_ending"))+ if exclude:+ return (+ "- 首尾结构页:exclude_cover_ending=true(仅 default 生效)。"+ "禁止生成任何 cover/intro/ending/conclusion/transition 页面;"+ "P1 直接是第一个内容页(研究需求 ✅),末页是最后一个内容页(✅);"+ "总页数 = page_count + 中间结构页数(无封面/结束页的 +2)。\n"+ )+ return (+ "- 首尾结构页:exclude_cover_ending=false(默认)。"+ "必须生成 P1 cover 与末页 ending,二者研究需求 ❌;"+ "总页数 = page_count + 2 + 中间结构页数。"+ "封面含主题标题、副标题、日期信息;结束页含感谢语/联系方式。"+ "conclusion/transition 不再支持;如需总结页,并入最后的 ending 页。\n"+ )++def _build_structural_page_directive(inputs: dict[str, Any]) -> str:"""根据 structural_page_request 构建中间结构页指令,注入 P4.3 prompt。与 pptx-craft outline-planner 的「中间结构页触发与默认数量规则」对齐:+ - explicit_sequence: 不适用默认 mid 规则- none: 禁止自行添加任何中间结构页- agenda/section/chapter: 按指定类型生成,数量由 structural_page_count 或默认规则决定- auto: 用户要求章节页但未指定类型,由 LLM 根据语境选择 section 或 chapter"""+ mode = str(inputs.get("page_structure_mode") or "default").strip().lower()+ if mode == "explicit_sequence":+ return (+ "- 中间结构页:page_structure_mode=explicit_sequence,禁止按 structural_page_request "+ "自动插入 agenda/section/chapter;仅清单明确标注的结构页保留。\n"+ )+spr = str(inputs.get("structural_page_request") or "none").strip().lower()spc = inputs.get("structural_page_count")page_count = inputs.get("page_count")+ cover_ending = 0 if bool(inputs.get("exclude_cover_ending")) else 2+ shell_note = "无封面/结束页" if cover_ending == 0 else "含封面/结束页"if spr == "none":return ("- 中间结构页:用户未要求任何中间结构页(目录页/章节页/分隔页)。""禁止自行添加 section/chapter/transition/agenda/conclusion 等结构页。""即使内容有章节结构,也通过内容页标题、页内分组和视觉层级承接,不单独占用一页过渡。"- "总页数 = page_count + 2。\n"+ f"总页数 = page_count + {cover_ending}({shell_note})。\n")if spr == "agenda":total_structural = PptCommon.resolve_mid_structural_page_count(page_count, spr, spc,)+ order = (+ "第一个内容页 → agenda → 其余内容页(✅)…"+ if cover_ending == 0+ else "cover → agenda → 内容页(✅)… → ending"+ )return ("- 中间结构页:用户要求目录页(agenda),固定生成 1 页 agenda。\n"" 规则:\n"- " 1. 页面顺序:cover → agenda → 内容页(✅)… → ending\n"+ f" 1. 页面顺序:{order}\n"" 2. 禁止生成 section/chapter/transition 等章节分隔页\n"" 3. user_dimensions / user_structure 中的条目(除「封面」「目录」「结束页」外)""一律映射为内容页,不得标为 section\n"- f" 4. 总页数 = page_count + 2 + {total_structural}(内容页 + 封面/结束页 + agenda)\n"+ f" 4. 总页数 = page_count + {cover_ending} + {total_structural}"+ f"(内容页 + 首尾{cover_ending} + agenda)\n"" 5. agenda 页内容概要只列后续内容页(✅)的章节标题与导航\n"- " 6. conclusion/transition 不再支持;如需总结页,并入最后的 ending 页\n"+ " 6. conclusion/transition 不再支持;如需总结页,并入最后的 ending 页"+ "(若 exclude_cover_ending=true 则并入末个内容页概要,不得另起 ending)\n")# section / chapter / auto:章节分隔页规则@@ -928,28 +972,45 @@ def _build_structural_page_directive(inputs: dict[str, Any]) -> str:else:count_str = f"{total_structural} 页(无法确定 page_count,默认)"+ order = (+ "(可选 agenda)-> 结构页 1 -> 内容组 1 -> …"+ if cover_ending == 0+ else "cover ->(可选 agenda)-> 结构页 1 -> 内容组 1 -> 结构页 2 -> 内容组 2 -> ... -> ending"+ )return (f"- 中间结构页:用户已明确要求中间结构页,类型={type_hint},数量={count_str}。\n"f" 规则:\n"f" 1. 中间结构页的「研究需求」标 ❌,不计入 page_count 内容页配额\n"- f" 2. 总页数 = page_count + 2 + {total_structural}(内容页 + 封面/结束页 + 结构页)\n"- f" 3. 结构页放在每个内容组之前:cover ->(可选 agenda)-> 结构页 1 -> 内容组 1 -> 结构页 2 -> 内容组 2 -> ... -> ending\n"+ f" 2. 总页数 = page_count + {cover_ending} + {total_structural}"+ f"(内容页 + 首尾{cover_ending} + 结构页)\n"+ f" 3. 结构页放在每个内容组之前:{order}\n"f" 4. 每组至少含 2 个内容页,最后一组不得仅含 1 页\n"f" 5. 结构页必须有明确的章节编号、章节标题或转场目的;不得为了填页数生成空泛页面\n"- f" 6. conclusion/transition 不再支持;如需总结页,并入最后的 ending 页\n"+ f" 6. conclusion/transition 不再支持;如需总结页,并入最后的 ending 页"+ f"(若 exclude_cover_ending=true 则并入末个内容页)\n")def _build_agenda_mapping_directive(inputs: dict[str, Any]) -> str:"""agenda 模式下注入显式页面映射,避免 user_dimensions 被误标为 section。"""+ if str(inputs.get("page_structure_mode") or "default").strip().lower() == "explicit_sequence":+ return ""spr = str(inputs.get("structural_page_request") or "none").strip().lower()if spr != "agenda":return ""+ exclude = bool(inputs.get("exclude_cover_ending"))+ if exclude:+ shell_line = " - P1: 第一个内容页;末页: 最后一个内容页(禁止 cover/ending)\n"+ agenda_line = " - 紧接首页之后放 1 页 agenda(目录),类型必须为 agenda\n"+ else:+ shell_line = " - P1: cover;末页: ending\n"+ agenda_line = " - 紧接 cover 之后放 1 页 agenda(目录),类型必须为 agenda\n"+parts = ["- 页面映射(agenda 模式,强制):\n",- " - P1: cover;末页: ending\n",- " - 紧接 cover 之后放 1 页 agenda(目录),类型必须为 agenda\n",+ shell_line,+ agenda_line," - 禁止生成 section/chapter/transition 章节分隔页\n",]@@ -994,10 +1055,17 @@ def _build_p43_prompt(expand_mode = PptCommon.is_expand_page_mode(inputs)entity = str(inputs.get("p4_search_entity") or "").strip()+ page_structure_mode = str(inputs.get("page_structure_mode") or "default").strip().lower()+ exclude_cover_ending = bool(inputs.get("exclude_cover_ending"))+ target_total_pages = inputs.get("total_pages")parts = [f"请生成 outline.md 正文,主题:「{topic}」\n",- f"- page_count: {page_count}(内容页数,不含封面/结束页;默认总页数为 page_count + 2)\n",+ f"- page_count: {page_count}(内容页数 ✅,不含中间结构页;首尾是否另计见下方指令)\n",+ f"- page_structure_mode: {page_structure_mode}\n",+ f"- exclude_cover_ending: {exclude_cover_ending}"+ f"(仅 page_structure_mode=default 生效)\n",+ f"- total_pages: {target_total_pages}(P2 已算目标总页;扩展模式允许实际 ≥)\n",f"- audience: {audience}\n",f"- source_type: {source_type}\n",f"- search_mode: {search_mode}\n",@@ -1062,7 +1130,8 @@ def _build_p43_prompt('- no_search 模式:研究查询与数据需求仍需填写(描述"如有搜索会查询什么"),但标注为「仅参考」。\n')- # 中间结构页需求注入+ # 首尾 + 中间结构页:互斥注入(同一轮不得同时出现「必须 cover」与「禁止 cover」)+ parts.append(_build_cover_ending_directive(inputs))parts.append(_build_structural_page_directive(inputs))agenda_mapping = _build_agenda_mapping_directive(inputs)if agenda_mapping:@@ -1108,6 +1177,11 @@ def _strip_markdown_fence(text: str) -> str:return stripped+_COVER_TYPES = frozenset({"cover", "intro"})+_ENDING_TYPES = frozenset({"ending", "conclusion", "transition"})+_SHELL_TYPES = _COVER_TYPES | _ENDING_TYPES++def _validate_outline_markdown_basic(text: str,*,@@ -1116,6 +1190,9 @@ def _validate_outline_markdown_basic(structural_page_request: str = "none",structural_page_count: Any = None,expand_page_mode: bool = False,+ page_structure_mode: str = "default",+ exclude_cover_ending: bool = False,+ total_pages: Any = None,) -> None:stripped = text.strip()if not stripped:@@ -1136,10 +1213,13 @@ def _validate_outline_markdown_basic(if not page_numbers:raise ContentPlanError("P4.3 outline 缺少 `### P{N}:` 页面块")+ mode = str(page_structure_mode or "default").strip().lower()+ exclude = bool(exclude_cover_ending) if mode != "explicit_sequence" else Falseexpected_content_pages = int(page_count) if page_count is not None else None+ _struct_pages = _split_outline_pages(stripped)+if expected_content_pages is not None:- pages = _split_outline_pages(stripped)- content_count = sum(1 for _, blk in pages if _is_research_required_page(blk))+ content_count = sum(1 for _, blk in _struct_pages if _is_research_required_page(blk))if expand_page_mode:if content_count < expected_content_pages:raise ContentPlanError(@@ -1152,51 +1232,71 @@ def _validate_outline_markdown_basic(f"实际 {content_count}")- # 总页数校验:max(page_numbers) 应等于 page_count + 2(封面/结束) + 结构页数- # 防止 intent 阶段 page_count 算错导致总页数与用户要求不一致- if expected_content_pages is not None:+ actual_total = max(page_numbers) if page_numbers else 0+ if mode == "explicit_sequence":+ # 清单权威:总页 == total_pages;不强制首尾;不按 mid 公式加壳+ if isinstance(total_pages, int) and total_pages > 0:+ if expand_page_mode:+ if actual_total < total_pages:+ raise ContentPlanError(+ f"P4.3 outline 扩展模式下总页数应 ≥ {total_pages}"+ f"(explicit_sequence 清单长),实际最大页码为 {actual_total}"+ )+ elif actual_total != total_pages:+ raise ContentPlanError(+ f"P4.3 outline 总页数应为 {total_pages}"+ f"(explicit_sequence 清单长),实际最大页码为 {actual_total}"+ )+ elif expected_content_pages is not None:structural_num = PptCommon.resolve_mid_structural_page_count(expected_content_pages,structural_page_request,structural_page_count,)- expected_total = expected_content_pages + 2 + structural_num- actual_total = max(page_numbers) if page_numbers else 0+ cover_ending = 0 if exclude else 2+ expected_total = expected_content_pages + cover_ending + structural_numif expand_page_mode:if actual_total < expected_total:raise ContentPlanError(f"P4.3 outline 扩展模式下总页数应 ≥ {expected_total}"- f"(内容页{expected_content_pages} + 封面/结束2 + 结构页{structural_num}),"- f"实际最大页码为 {actual_total}"+ f"(内容页{expected_content_pages} + 首尾{cover_ending}"+ f" + 结构页{structural_num}),实际最大页码为 {actual_total}")elif actual_total != expected_total:raise ContentPlanError(f"P4.3 outline 总页数应为 {expected_total}"- f"(内容页{expected_content_pages} + 封面/结束2 + 结构页{structural_num}),"- f"实际最大页码为 {actual_total}"+ f"(内容页{expected_content_pages} + 首尾{cover_ending}"+ f" + 结构页{structural_num}),实际最大页码为 {actual_total}")- # 遵从 pptx-craft outline-planner(Phase 2)产物验证:- # 首页类型为 cover,末页类型为 ending(conclusion/transition 为别名)- _struct_pages = _split_outline_pages(stripped)- if _struct_pages:- _first_type = _extract_outline_field(_struct_pages[0][1], "类型").strip().lower()- if _first_type and _first_type not in ("cover", "intro"):- raise ContentPlanError(- f"P4.3 outline 首页类型应为 cover,实际为 {_first_type}"- )- _last_type = _extract_outline_field(_struct_pages[-1][1], "类型").strip().lower()- if _last_type and _last_type not in ("ending", "conclusion", "transition"):- raise ContentPlanError(- f"P4.3 outline 末页类型应为 ending,实际为 {_last_type}"- )+ if _struct_pages and mode != "explicit_sequence":+ if exclude:+ for page_num, blk in _struct_pages:+ ptype = _extract_outline_field(blk, "类型").strip().lower()+ if ptype in _SHELL_TYPES:+ raise ContentPlanError(+ f"P4.3 outline exclude_cover_ending=true 时禁止出现"+ f" cover/ending,P{page_num} 类型为 {ptype}"+ )+ else:+ _first_type = _extract_outline_field(_struct_pages[0][1], "类型").strip().lower()+ if _first_type and _first_type not in _COVER_TYPES:+ raise ContentPlanError(+ f"P4.3 outline 首页类型应为 cover,实际为 {_first_type}"+ )+ _last_type = _extract_outline_field(_struct_pages[-1][1], "类型").strip().lower()+ if _last_type and _last_type not in _ENDING_TYPES:+ raise ContentPlanError(+ f"P4.3 outline 末页类型应为 ending,实际为 {_last_type}"+ )- # 中间结构页合法性校验- _validate_structural_pages(- _struct_pages,- structural_page_request=structural_page_request,- structural_page_count=structural_page_count,- )+ # explicit:清单权威,跳过 mid 自动插页校验;default:按 structural_page_request+ if mode != "explicit_sequence":+ _validate_structural_pages(+ _struct_pages,+ structural_page_request=structural_page_request,+ structural_page_count=structural_page_count,+ )required_fields = ("**类型**", "**研究需求**", "**标题**", "**内容概要**", "**研究查询**", "**数据需求**")for field in required_fields:@@ -1325,6 +1425,9 @@ def _validate_outline_markdown_full(structural_page_request: str = "none",structural_page_count: Any = None,expand_page_mode: bool = False,+ page_structure_mode: str = "default",+ exclude_cover_ending: bool = False,+ total_pages: Any = None,) -> None:_validate_outline_markdown_basic(text,@@ -1333,6 +1436,9 @@ def _validate_outline_markdown_full(structural_page_request=structural_page_request,structural_page_count=structural_page_count,expand_page_mode=expand_page_mode,+ page_structure_mode=page_structure_mode,+ exclude_cover_ending=exclude_cover_ending,+ total_pages=total_pages,)_validate_notes_leakage(text)@@ -1365,6 +1471,9 @@ def _outline_validate_kwargs(inputs: dict[str, Any]) -> dict[str, Any]:"structural_page_request": str(inputs.get("structural_page_request") or "none"),"structural_page_count": inputs.get("structural_page_count"),"expand_page_mode": PptCommon.is_expand_page_mode(inputs),+ "page_structure_mode": str(inputs.get("page_structure_mode") or "default"),+ "exclude_cover_ending": bool(inputs.get("exclude_cover_ending")),+ "total_pages": inputs.get("total_pages"),}diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/intent_classify.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/intent_classify.pyindex 4930094d9e..c2ec74ffbc 100644--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/intent_classify.py+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/intent_classify.py@@ -75,12 +75,16 @@ _LLM_PATH_AND_SLOTS_SYSTEM_PROMPT = """你是 PPT 任务分析助手。从用户第二步:PPT 需求信息提取(仅当没有找到任何文件路径时执行)- 只提取用户**明确提到**的信息,不要推断或补充- 未提及的字段留空字符串或 null-- page_count 必须是正整数(内容页数,不含封面/结束页,也不含目录页/章节页等中间结构页;总页数 = page_count + 2 + 中间结构页数)。+- page_count 必须是正整数(内容页数,不含封面/结束页,也不含目录页/章节页等中间结构页;默认总页数 = page_count + 2 + 中间结构页数;exclude_cover_ending=true 时总页数 = page_count + 中间结构页数)。判断规则:①用户说"生成N页PPT"/"做N页汇报"/"PPT共N页"/"总页数N页"/"总共N页"/"一共N页"/"N页"/"做N页PPT"/"N页以内"/"不超过N页"/"最多N页"等未特指内容页的表达 → N 表示总页数:- 无中间结构或未指定结构数量 → page_count = max(N - 2, 1);指定结构数量 K → page_count = max(N - 2 - K, 1);+ exclude_cover_ending=false(默认):无中间结构或未指定结构数量 → page_count = max(N - 2, 1);指定结构数量 K → page_count = max(N - 2 - K, 1);+ exclude_cover_ending=true:无中间结构或未指定结构数量 → page_count = N;指定结构数量 K → page_count = max(N - K, 1);未指定结构数量时禁止自行扣减结构页或试算 ceil(下游系统按 outline-planner 反推)。②用户明确说"N个内容页"/"N页正文",或正在回答"需要多少页内容页"时 → page_count = N(中间结构页另行添加,不占此配额)。- 示例:"10页以内"→8, "总页数8页"→6, "8页"→6, "做8页PPT"→6, "共7页"+要求目录页→4, "8页PPT"+3个章节页→3+ 示例:"10页以内"→8, "总页数8页"→6, "8页"→6, "做8页PPT"→6, "共7页"+要求目录页→4, "8页PPT"+3个章节页→3, "做8页PPT不要封面和结束页"→8 + exclude_cover_ending=true+- page_structure_mode: "default"(默认)或 "explicit_sequence"。用户给出有序逐页清单(如"第1页封面、第2页背景、第3页方案、第4页结束")时填 explicit_sequence;否则 default。explicit_sequence 时清单即总页数与顺序权威,不得自动加封面/结束/目录/章节。+- exclude_cover_ending: 是否不生成封面页和结束页。布尔;默认 false。仅 page_structure_mode=default 且用户**明确否定**首尾页(如"不要封面和结束页""不需要首尾页/致谢页")时为 true;沉默不推断。用户单独否定其中一页并明确保留另一页时仍为 false。explicit_sequence 时本字段不适用,填 false。+- total_pages: 仅 page_structure_mode=explicit_sequence 时必填(清单条目数,正整数);default 模式填 null。- style_id 可选值:business-classic / tech-minimal / elegant-narrative / industrial-tech / custom / 其他风格名用户要求“自由发挥”时填写 custom“华为风格/华为/华为红/华为风/华为商务”统一填写 business-classic,不得填 custom@@ -99,6 +103,7 @@ _LLM_PATH_AND_SLOTS_SYSTEM_PROMPT = """你是 PPT 任务分析助手。从用户提取规则:仅当用户明确表达时才提取,例如"加章节页""每章一个章节页""需要目录页""加 PART 页""加章首页"。普通章节结构、素材中的标题层级、模型自己觉得需要分节,都不构成触发条件 -> "none"。用户指定数量时(如"加 2 页章节页"),数量信息保留在 structural_page_count 中。+ page_structure_mode=explicit_sequence 时填 "none"(清单权威,不另抽中间结构需求)。- structural_page_count: 用户指定的中间结构页数量(整数;未指定或"每章一个"等需自动计算时为 null)。重要:如果找到了文件路径,slots 各字段留空,不需要提取需求信息;@@ -107,6 +112,7 @@ _LLM_PATH_AND_SLOTS_SYSTEM_PROMPT = """你是 PPT 任务分析助手。从用户必须只输出 JSON,格式:{"doc_paths": ["路径1"], "slots": {"topic": "", "page_count": null, "audience": "","presentation_purpose": "", "style_id": "", "pack_dir": "",+"page_structure_mode": "default", "exclude_cover_ending": false, "total_pages": null,"structural_page_request": "none", "structural_page_count": null}}(page_count 为正整数或 null,禁止字符串)"""@@ -227,6 +233,10 @@ def _collect_files_paths(inputs: dict[str, Any]) -> list[str]:_SLOT_NAMES = ("topic", "page_count", "audience", "presentation_purpose", "style_id", "pack_dir")+# 与 requirement_collect._VALID_STRUCTURAL_REQUESTS 同值;本地常量避免交叉 import+_VALID_STRUCTURAL_REQUESTS = frozenset(+ {"none", "agenda", "section", "chapter", "auto"}+)def _build_llm_path_prompt(text: str) -> str:@@ -324,6 +334,35 @@ def _parse_slots_from_llm_response(raw: str) -> dict[str, Any]:result[name] = valueelse:result[name] = "" if name != "page_count" else None+ mode = str(slots_raw.get("page_structure_mode") or "default").strip().lower()+ if mode not in ("default", "explicit_sequence"):+ mode = "default"+ result["page_structure_mode"] = mode+ exc = slots_raw.get("exclude_cover_ending")+ if mode == "explicit_sequence":+ result["exclude_cover_ending"] = False+ elif isinstance(exc, bool):+ result["exclude_cover_ending"] = exc+ elif isinstance(exc, str) and exc.strip().lower() in ("true", "1", "yes"):+ result["exclude_cover_ending"] = True+ else:+ result["exclude_cover_ending"] = False+ spr = slots_raw.get("structural_page_request")+ if mode == "explicit_sequence":+ result["structural_page_request"] = "none"+ elif isinstance(spr, str) and spr.strip().lower() in _VALID_STRUCTURAL_REQUESTS:+ result["structural_page_request"] = spr.strip().lower()+ spc = slots_raw.get("structural_page_count")+ if isinstance(spc, int) and spc > 0:+ result["structural_page_count"] = spc+ elif isinstance(spc, float) and spc > 0 and spc == int(spc):+ result["structural_page_count"] = int(spc)+ if mode == "explicit_sequence":+ tp = slots_raw.get("total_pages")+ if isinstance(tp, int) and tp > 0:+ result["total_pages"] = tp+ elif isinstance(tp, float) and tp > 0 and tp == int(tp):+ result["total_pages"] = int(tp)return resultdiff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/outline_review.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/outline_review.pyindex abc4e71f41..6695df14cf 100644--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/outline_review.py+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/outline_review.py@@ -136,6 +136,9 @@ class OutlineReviewNode(PlanNode):structural_page_request=str(inputs.get("structural_page_request") or "none"),structural_page_count=inputs.get("structural_page_count"),expand_page_mode=PptCommon.is_expand_page_mode(inputs),+ page_structure_mode=str(inputs.get("page_structure_mode") or "default"),+ exclude_cover_ending=bool(inputs.get("exclude_cover_ending")),+ total_pages=inputs.get("total_pages"),)_validate_notes_leakage(text)return ""diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_common.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_common.pyindex 91105aa4c8..2614a11b20 100644--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_common.py+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_common.py@@ -196,6 +196,10 @@ _PHASE1_DEFAULTS: dict[str, Any] = {"images_extracted": False,"parse_degraded": False,"page_count_user_specified": False,+ # pptx-craft §1.2:default 用默认首尾;explicit_sequence 以清单为准+ "page_structure_mode": "default",+ # pptx-craft §1.2/1.4:仅明确否定首尾时为 true;沉默不推断+ "exclude_cover_ending": False,"content_branch": "","thinking_strategy": "accelerated", # P6/P8 DisableThinkingMixin 节点强制 thinking=off"presentation_paths": [],@@ -678,9 +682,11 @@ class PptCommon:outline_pages: dict[int, str] | None = None,default_structural_pages: int = 2,) -> int:- """从 outline 页码、上下文 total_pages 与 page_count 兜底推算总页数。+ """推算总页数:大纲最大页码 / 已归一 total_pages 为权威。- 含 agenda 等额外结构页时,``page_count + 2`` 会低估总页数;优先取 outline 最大页码。+ 对齐 pptx-craft:主控与 outline 写准的总页不得再被 ``page_count+2`` 抬高+ (exclude_cover_ending 时 total==page_count,旧 max(+2) 会把 2 页抬成 4)。+ 仅当二者皆缺时,才用 ``page_count + default_structural_pages`` 作缺省壳页兜底。"""candidates: list[int] = []if total_pages is not None:@@ -699,9 +705,11 @@ class PptCommon:]if page_nums:candidates.append(max(page_nums))+ if candidates:+ return max(candidates)if page_count > 0:- candidates.append(page_count + default_structural_pages)- return max(candidates) if candidates else 0+ return page_count + default_structural_pages+ return 0@staticmethoddef default_mid_structural_pages(page_count: int) -> int:diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/requirement_collect.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/requirement_collect.pyindex 076328ee04..3e5b24619f 100644--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/requirement_collect.py+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/requirement_collect.py@@ -101,16 +101,21 @@ _P21_SLOT_SYSTEM_PROMPT = ("""你是 PPT 需求槽位分析助手。从用户消提取字段:- topic: 演示主题(字符串;未知则 "")-- page_count: 内容页数(整数;不含封面/结束页,也不含目录/章节等中间结构页;总页数 = page_count + 2 + 中间结构页数;未知则 null)。+- page_count: 内容页数(整数;不含封面/结束页,也不含目录/章节等中间结构页;默认总页数 = page_count + 2 + 中间结构页数;exclude_cover_ending=true 时总页数 = page_count + 中间结构页数;未知则 null)。判断规则:①用户说"生成N页PPT"/"做N页汇报"/"PPT共N页"/"总页数N页"/"总共N页"/"一共N页"/"N页"/"做N页PPT"/"N页以内"/"不超过N页"/"最多N页"/"不大于N页"等未特指内容页的表达 → N 表示总页数:- page_count_basis 填 "total";- - 无中间结构页要求:page_count = max(N - 2, 1);- - 用户指定了中间结构页数量 K:page_count = max(N - 2 - K, 1);- - 要求中间结构页但未指定数量:page_count = max(N - 2, 1),structural_page_count=null;**禁止**自行猜测结构页扣减或试算 ceil(由系统按 outline-planner 反推)。- ②用户明确说"N个内容页"/"N页正文",或正在回答"需要多少页内容页"时 → page_count = N,page_count_basis 填 "content"(中间结构页另行添加,不占此配额)。- 示例:"10页以内"→8/total;"总页数严格为8页"→6/total;"8页"→6/total;"做8页PPT"→6/total;"共7页"+要求目录页→5/total(只扣封面结束);"8页PPT"+3个章节页→3/total;"8个内容页"+章节页→8/content+ - exclude_cover_ending=false(默认):无中间结构页要求 → page_count = max(N - 2, 1);用户指定中间结构页数量 K → page_count = max(N - 2 - K, 1);要求中间结构页但未指定数量 → page_count = max(N - 2, 1),structural_page_count=null;**禁止**自行猜测结构页扣减或试算 ceil(由系统按 outline-planner 反推)。+ - exclude_cover_ending=true:无中间结构页要求 → page_count = N;用户指定中间结构页数量 K → page_count = max(N - K, 1);要求中间结构页但未指定数量 → page_count = N,structural_page_count=null(系统反推)。+ ②用户明确说"N个内容页"/"N页正文",或正在回答"需要多少页内容页"时 → page_count = N,page_count_basis 填 "content"(中间结构页另行添加,不占此配额;exclude_cover_ending 不影响此口径)。+ 示例:"10页以内"→8/total;"总页数严格为8页"→6/total;"8页"→6/total;"做8页PPT"→6/total;"共7页"+要求目录页→5/total(只扣封面结束);"8页PPT"+3个章节页→3/total;"8个内容页"+章节页→8/content;"做8页PPT,不要封面和结束页"→8/total + exclude_cover_ending=true- page_count_basis: "total"(规则①)/ "content"(规则②)/ ""(未知)- page_count_user_specified: 用户原文是否明确给出页数(含总页数/内容页表达);有则为 true,否则 false+- page_structure_mode: "default"(默认)或 "explicit_sequence"。用户给出有序逐页清单(如"第1页封面、第2页背景…")时填 explicit_sequence;否则 default。explicit_sequence 时清单即总页数与顺序权威,不得自动加封面/结束/目录/章节;此时 exclude_cover_ending 填 false,structural_page_request 填 "none";total_pages 填清单条目数,page_count 填清单中非结构页(非封面/目录/章节/结束)的项数。+- exclude_cover_ending: 是否不生成封面页和结束页。布尔;默认 false。+ 仅 page_structure_mode=default 且用户**明确否定**首尾页(如"不要封面和结束页""不需要首尾页/致谢页")时为 true;沉默不推断。+ 用户单独否定其中一页并明确保留另一页时,尊重表述保留那一页,本字段仍为 false。+ page_structure_mode=explicit_sequence 时本字段不适用,填 false。+- total_pages: 仅 page_structure_mode=explicit_sequence 时必填(清单条目数);default 模式填 null(由系统按 page_count 公式计算)。- audience: 目标受众(字符串;未知则 "")- presentation_purpose: 汇报目的,如「工作汇报」「产品展示」「教学分享」「auto」;未知则 ""- style_id: 用户明确提及风格时填写:business-classic / tech-minimal / elegant-narrative / industrial-tech / custom;“自由发挥”统一填写 custom;未知则 ""@@ -147,14 +152,17 @@ _P21_SLOT_SYSTEM_PROMPT = ("""你是 PPT 需求槽位分析助手。从用户消4. 不要输出 search_mode / source_type。5. topic 缺失时由下游 LLM 生成 4 个主题候选并 ask 用户选择,不要生成询问文案。6. pack_dir 存在时 style_id 填 "custom"(模板包优先于预设风格),need_ask_style 设 false。-7. page_count 为内容页数(不含封面/结束页,也不含目录/章节等中间结构页),总页数 = page_count + 2 + 中间结构页数。- 用户说"生成N页PPT"等未特指内容页的表达 → N 为总页数:page_count_basis="total";无结构页或未指定结构数量时 page_count=max(N-2,1);指定结构数量 K 时 page_count=max(N-2-K,1);未指定结构数量时禁止自行扣减结构页(系统反推)。+7. page_count 为内容页数(不含封面/结束页,也不含目录/章节等中间结构页)。exclude_cover_ending=false 时总页数 = page_count + 2 + 中间结构页数;true 时总页数 = page_count + 中间结构页数。+ 用户说"生成N页PPT"等未特指内容页的表达 → N 为总页数:page_count_basis="total";exclude=false 且无结构页或未指定结构数量时 page_count=max(N-2,1);exclude=true 且无结构页或未指定结构数量时 page_count=N;指定结构数量 K 时按是否 exclude 扣 2 或 0 再扣 K;未指定结构数量时禁止自行扣减结构页(系统反推)。用户明确说"N个内容页"/"N页正文"或正在回答"需要多少页内容页"时,page_count=N,page_count_basis="content"。8. style_constraints / user_dimensions / user_structure 不进 outline.md,只供下游透传。+9. exclude_cover_ending 仅从明确否定首尾的原话提取;不得因“简洁/少页”等理由自行置 true。+10. page_structure_mode=explicit_sequence 时以清单为准:exclude_cover_ending=false,structural_page_request="none"。必须只输出 JSON:"""+ '{"topic":"","page_count":null,"page_count_basis":"",'- + '"page_count_user_specified":false,'+ + '"page_count_user_specified":false,"page_structure_mode":"default",'+ + '"exclude_cover_ending":false,"total_pages":null,'+ '"audience":"","presentation_purpose":"",'+ '"style_id":"","style_description":"","style_constraints":"",'+ '"user_dimensions":[],"user_structure":"","notes_requirements":"",'@@ -456,6 +464,58 @@ def _require_batch_fields_collected(inputs: dict[str, Any]) -> None:raise RequirementCollectError(f"需求收集未完成:缺少 {names}")+def _coerce_bool_flag(value: Any, *, default: bool = False) -> bool:+ """Normalize LLM/JSON bool-ish values for exclude_cover_ending etc."""+ if isinstance(value, bool):+ return value+ if isinstance(value, (int, float)) and value in (0, 1):+ return bool(value)+ if isinstance(value, str):+ lowered = value.strip().lower()+ if lowered in ("true", "1", "yes"):+ return True+ if lowered in ("false", "0", "no", ""):+ return False+ return default+++def _normalize_page_structure_mode(value: Any) -> str:+ mode = str(value or "default").strip().lower()+ if mode not in ("default", "explicit_sequence"):+ return "default"+ return mode+++def _apply_structure_mode_guards(inputs: dict[str, Any]) -> None:+ """explicit_sequence:exclude 不适用;不驱动 mid(对齐 outline-planner)。"""+ if str(inputs.get("page_structure_mode") or "default") != "explicit_sequence":+ return+ inputs["exclude_cover_ending"] = False+ inputs["structural_page_request"] = "none"+ inputs["structural_page_count"] = None+++def _sync_target_total_pages(inputs: dict[str, Any]) -> None:+ """按 pptx-craft 公式写入目标 total_pages(P4 消费,禁止下游猜)。"""+ page_count = inputs.get("page_count")+ if not isinstance(page_count, int) or page_count <= 0:+ return+ mode = str(inputs.get("page_structure_mode") or "default").strip().lower()+ if mode == "explicit_sequence":+ # 清单条目数应由上游槽位给出;已有合法值则保留+ existing = inputs.get("total_pages")+ if isinstance(existing, int) and existing > 0:+ return+ return+ mid = PptCommon.resolve_mid_structural_page_count(+ page_count,+ inputs.get("structural_page_request"),+ inputs.get("structural_page_count"),+ )+ cover_ending = 0 if bool(inputs.get("exclude_cover_ending")) else 2+ inputs["total_pages"] = page_count + cover_ending + mid++def _prune_satisfied_batch_missing_fields(inputs: dict[str, Any]) -> None:_reconcile_missing_fields(inputs)@@ -611,7 +671,32 @@ def _merge_slot_payload(else:inputs.setdefault("structural_page_count", None)+ # pptx-craft §1.2:page_structure_mode / exclude_cover_ending+ if "page_structure_mode" in payload:+ inputs["page_structure_mode"] = _normalize_page_structure_mode(+ payload.get("page_structure_mode")+ )+ else:+ inputs.setdefault("page_structure_mode", "default")++ if "exclude_cover_ending" in payload:+ inputs["exclude_cover_ending"] = _coerce_bool_flag(+ payload.get("exclude_cover_ending"), default=False+ )+ else:+ inputs.setdefault("exclude_cover_ending", False)++ # explicit:total_pages = 清单条目数(由 LLM 填)+ if str(inputs.get("page_structure_mode")) == "explicit_sequence":+ tp = payload.get("total_pages")+ if isinstance(tp, int) and tp > 0:+ inputs["total_pages"] = tp+ elif isinstance(tp, float) and tp > 0 and tp == int(tp):+ inputs["total_pages"] = int(tp)++ _apply_structure_mode_guards(inputs)_normalize_total_derived_page_count(inputs, payload)+ _sync_target_total_pages(inputs)need_ask_style = payload.get("need_ask_style")if isinstance(need_ask_style, bool) and not inputs.get("pack_dir"):@@ -632,7 +717,10 @@ def _normalize_total_derived_page_count("""总页数表达 + 未指定结构数量:由代码按 outline-planner 反推 page_count。LLM 只填 max(N-2,1),禁止在 prompt 里试算 ceil,避免鸡生蛋。+ explicit_sequence 不适用本归一。"""+ if str(inputs.get("page_structure_mode") or "default") == "explicit_sequence":+ returnbasis = str(payload.get("page_count_basis") or "").strip().lower()if basis != "total":return@@ -642,7 +730,7 @@ def _normalize_total_derived_page_count(spr = str(inputs.get("structural_page_request") or "none").strip().lower()spc = inputs.get("structural_page_count")if isinstance(spc, int) and spc > 0:- # 指定 K 时 LLM 已按 max(N-2-K,1) 填好+ # 指定 K 时 LLM 已按 max(N-2-K,1) 或 exclude 口径填好returnif spr in ("", "none"):return@@ -1940,6 +2028,21 @@ class RequirementCollectNode(PlanNode):else:ctx.setdefault("structural_page_count", None)+ mode = _normalize_page_structure_mode(pre_slots.get("page_structure_mode"))+ ctx["page_structure_mode"] = mode+ if "exclude_cover_ending" in pre_slots:+ ctx["exclude_cover_ending"] = _coerce_bool_flag(+ pre_slots.get("exclude_cover_ending"), default=False+ )+ else:+ ctx.setdefault("exclude_cover_ending", False)+ if mode == "explicit_sequence":+ tp = pre_slots.get("total_pages")+ if isinstance(tp, int) and tp > 0:+ ctx["total_pages"] = tp+ _apply_structure_mode_guards(ctx)+ _sync_target_total_pages(ctx)+# 快捷路径仍跑一次轻量 P2.1,补齐 constraints/dims/structureawait self.execute_subplan(self.sub_plans[0], ctx)await self.skip_subplan(self.sub_plans[1], ctx, message="slots pre-filled from query")@@ -1980,6 +2083,23 @@ class RequirementCollectNode(PlanNode):ctx["structural_page_count"] = _spcelse:ctx.setdefault("structural_page_count", None)+ if "page_structure_mode" not in ctx and "page_structure_mode" in pre_slots:+ ctx["page_structure_mode"] = _normalize_page_structure_mode(+ pre_slots.get("page_structure_mode")+ )+ if "exclude_cover_ending" not in ctx and "exclude_cover_ending" in pre_slots:+ ctx["exclude_cover_ending"] = _coerce_bool_flag(+ pre_slots.get("exclude_cover_ending"), default=False+ )+ if (+ str(ctx.get("page_structure_mode") or "") == "explicit_sequence"+ and not (isinstance(ctx.get("total_pages"), int) and ctx["total_pages"] > 0)+ ):+ tp = pre_slots.get("total_pages")+ if isinstance(tp, int) and tp > 0:+ ctx["total_pages"] = tp+ _apply_structure_mode_guards(ctx)+ _sync_target_total_pages(ctx)if _p21_should_skip(ctx):_reconcile_missing_fields(ctx)diff --git a/tests/unit_tests/server/runtime/skill_turbo/test_ppt_outline_contract_c.py b/tests/unit_tests/server/runtime/skill_turbo/test_ppt_outline_contract_c.pyindex 30b0846672..a7d712ae7c 100644--- a/tests/unit_tests/server/runtime/skill_turbo/test_ppt_outline_contract_c.py+++ b/tests/unit_tests/server/runtime/skill_turbo/test_ppt_outline_contract_c.py@@ -72,6 +72,31 @@ def test_intent_and_requirement_prompts_deduct_structural_pages():assert "max(N - 2 - 结构页扣减, 1)" not in rc._P21_SLOT_SYSTEM_PROMPT+def test_intent_prompt_and_parse_close_explicit_total_pages_gap():+ """P1 须声明并解析 total_pages;脏 structural_page_request 不得写入。"""+ prompt = ic._LLM_PATH_AND_SLOTS_SYSTEM_PROMPT+ assert '"total_pages": null' in prompt+ assert "仅 page_structure_mode=explicit_sequence 时必填" in prompt++ parsed = ic._parse_slots_from_llm_response(+ '{"doc_paths":[],"slots":{'+ '"topic":"T","page_count":2,"audience":"","presentation_purpose":"",'+ '"style_id":"","pack_dir":"",'+ '"page_structure_mode":"explicit_sequence","exclude_cover_ending":true,'+ '"total_pages":4,"structural_page_request":"agenda"}}'+ )+ assert parsed["page_structure_mode"] == "explicit_sequence"+ assert parsed["exclude_cover_ending"] is False+ assert parsed["structural_page_request"] == "none"+ assert parsed["total_pages"] == 4++ dirty = ic._parse_slots_from_llm_response(+ '{"doc_paths":[],"slots":{"topic":"T","page_count":3,'+ '"page_structure_mode":"default","structural_page_request":"foobar"}}'+ )+ assert "structural_page_request" not in dirty++def test_resolve_mid_structural_matches_outline_planner_default():from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_common import PptCommon@@ -107,6 +132,204 @@ def test_validate_outline_total_pages_mismatch_raises():)+def _outline_without_cover_ending(*, topic: str = "AI 助手", content_n: int = 4) -> str:+ pages = [+ _page_block(+ i + 1,+ page_type="content",+ research="✅",+ title=f"内容{i+1}",+ )+ for i in range(content_n)+ ]+ body = "\n".join(pages)+ return f"# 大纲:{topic}\n\n## 页面规划\n\n{body}\n"+++def test_validate_outline_exclude_cover_ending_ok():+ text = _outline_without_cover_ending(content_n=4)+ cp._validate_outline_markdown_basic(+ text,+ topic="AI 助手",+ page_count=4,+ structural_page_request="none",+ exclude_cover_ending=True,+ )+++def test_validate_outline_exclude_forbids_shell_types():+ # 页数对齐 exclude 公式,但页类型仍写了 cover/ending → 应拒+ pages = [+ _page_block(1, page_type="cover", research="✅", title="误用封面类型"),+ _page_block(2, page_type="content", research="✅", title="内容2"),+ _page_block(3, page_type="content", research="✅", title="内容3"),+ _page_block(4, page_type="ending", research="✅", title="误用结束类型"),+ ]+ text = "# 大纲:AI 助手\n\n## 页面规划\n\n" + "\n".join(pages) + "\n"+ with pytest.raises(cp.ContentPlanError, match="exclude_cover_ending"):+ cp._validate_outline_markdown_basic(+ text,+ topic="AI 助手",+ page_count=4,+ structural_page_request="none",+ exclude_cover_ending=True,+ )+++def test_validate_outline_explicit_sequence_uses_total_pages():+ # 清单:封面 + 2 内容 + 结束 = 4;page_count=2+ pages = [+ _page_block(1, page_type="cover", research="❌", title="封面", queries="-", needs="-"),+ _page_block(2, page_type="content", research="✅", title="背景"),+ _page_block(3, page_type="content", research="✅", title="方案"),+ _page_block(4, page_type="ending", research="❌", title="结束", queries="-", needs="-"),+ ]+ text = f"# 大纲:清单主题\n\n## 页面规划\n\n" + "\n".join(pages) + "\n"+ cp._validate_outline_markdown_basic(+ text,+ topic="清单主题",+ page_count=2,+ page_structure_mode="explicit_sequence",+ total_pages=4,+ structural_page_request="none",+ )+++def test_validate_outline_explicit_mismatch_total_raises():+ text = _minimal_outline(with_agenda=False) # 6 pages+ with pytest.raises(cp.ContentPlanError, match="清单长"):+ cp._validate_outline_markdown_basic(+ text,+ topic="AI 助手",+ page_count=4,+ page_structure_mode="explicit_sequence",+ total_pages=4,+ )+++def test_cover_ending_directive_mutex():+ default_d = cp._build_cover_ending_directive(+ {"page_structure_mode": "default", "exclude_cover_ending": False}+ )+ exclude_d = cp._build_cover_ending_directive(+ {"page_structure_mode": "default", "exclude_cover_ending": True}+ )+ explicit_d = cp._build_cover_ending_directive(+ {"page_structure_mode": "explicit_sequence"}+ )+ assert "必须生成 P1 cover" in default_d+ assert "禁止生成任何 cover" in exclude_d+ assert "不得自动增加 cover" in explicit_d+ assert "必须生成 P1 cover" not in exclude_d+ assert "必须生成 P1 cover" not in explicit_d++ prompt = cp._build_p43_prompt(+ {+ "topic": "T",+ "page_count": 4,+ "page_structure_mode": "default",+ "exclude_cover_ending": True,+ "total_pages": 4,+ "structural_page_request": "none",+ "source_type": "topic",+ "search_mode": "no_search",+ },+ "",+ "",+ )+ assert "禁止生成任何 cover" in prompt+ assert "必须生成 P1 cover" not in prompt+ assert "page_structure_mode: default" in prompt+ assert "exclude_cover_ending: True" in prompt+++def test_structural_directive_exclude_zero_shell():+ d = cp._build_structural_page_directive(+ {+ "structural_page_request": "none",+ "page_count": 4,+ "exclude_cover_ending": True,+ }+ )+ assert "page_count + 0" in d+ assert "page_count + 2" not in d+++def test_merge_slot_syncs_total_pages_for_exclude():+ inputs: dict = {}+ rc._merge_slot_payload(+ inputs,+ {+ "topic": "主题",+ "page_count": 5,+ "page_count_basis": "content",+ "exclude_cover_ending": True,+ "page_structure_mode": "default",+ "structural_page_request": "none",+ },+ )+ assert inputs["exclude_cover_ending"] is True+ assert inputs["total_pages"] == 5+++def test_merge_slot_explicit_preserves_total_pages():+ inputs: dict = {}+ rc._merge_slot_payload(+ inputs,+ {+ "topic": "主题",+ "page_count": 2,+ "page_count_basis": "content",+ "page_structure_mode": "explicit_sequence",+ "exclude_cover_ending": True, # 应被 guard 打回 false+ "total_pages": 4,+ "structural_page_request": "agenda",+ },+ )+ assert inputs["page_structure_mode"] == "explicit_sequence"+ assert inputs["exclude_cover_ending"] is False+ assert inputs["structural_page_request"] == "none"+ assert inputs["total_pages"] == 4+++def test_content_pages_from_total_respects_exclude():+ from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_common import PptCommon++ assert PptCommon.content_pages_from_total_pages(8, exclude_cover_ending=False) == 6+ assert PptCommon.content_pages_from_total_pages(8, exclude_cover_ending=True) == 8+++def test_resolve_total_pages_does_not_inflate_over_authoritative_total():+ """G9:已写 total_pages / outline 时不得再用 page_count+2 抬页(exclude 场景)。"""+ from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_common import PptCommon++ # exclude:page_count==total_pages==2,旧逻辑 max(2, 2+2)=4+ assert (+ PptCommon.resolve_total_pages(page_count=2, total_pages=2) == 2+ )+ assert (+ PptCommon.resolve_total_pages(+ page_count=2,+ total_pages=2,+ outline_pages={1: "a", 2: "b"},+ )+ == 2+ )+ # 默认有首尾:P2/P4 已写 total=page_count+2+ assert PptCommon.resolve_total_pages(page_count=6, total_pages=8) == 8+ # agenda 等:大纲最大页码权威+ assert (+ PptCommon.resolve_total_pages(+ page_count=4,+ total_pages=7,+ outline_pages={1: "c", 7: "e"},+ )+ == 7+ )+ # 二者皆缺:才用 page_count+2 缺省兜底+ assert PptCommon.resolve_total_pages(page_count=6, total_pages=None) == 8++def test_normalize_outline_contract_fixes_title_and_sources_and_placeholders():raw = ("# 大纲:旧标题\n\n"