Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

fix(generate): harden planning and export contract checks

hugohe3e78ec39238bc
diff --git a/skills/ppt-master/scripts/page_context.py b/skills/ppt-master/scripts/page_context.py
index 301effc7..ea500d85 100644
--- a/skills/ppt-master/scripts/page_context.py
+++ b/skills/ppt-master/scripts/page_context.py
@@ -26,7 +26,11 @@ from dataclasses import dataclass
from pathlib import Path
from typing import Callable, Iterable
-from project_specs import default_spec_lock_forbidden, parse_markdown_artifact
+from project_specs import (
+ default_spec_lock_forbidden,
+ parse_markdown_artifact,
+ validate_project_artifacts,
+)
from svg_to_pptx.pptx_package.template_structure import (
PptxStructureLock,
TemplateStructureError,
@@ -52,10 +56,10 @@ TEXT_SLOTS_TOKEN_TARGET = 1000
_PAGE_RE = re.compile(r"^(?:P)?([0-9]+)$", re.IGNORECASE)
_SLIDE_HEADING_RE = re.compile(
- r"^####[ \t]+Slide[ \t]+0*([0-9]+)(?:[ \t]*(?:[-:–—]).*)?$",
+ r"^#{3,6}[ \t]+Slide[ \t]+0*([0-9]+)(?:[ \t]*(?:[-:–—]).*)?$",
re.IGNORECASE | re.MULTILINE,
)
-_BLOCK_BOUNDARY_RE = re.compile(r"^#{2,4}[ \t]+", re.MULTILINE)
+_BLOCK_BOUNDARY_RE = re.compile(r"^#{2,6}[ \t]+", re.MULTILINE)
_PART_HEADING_RE = re.compile(r"^###[ \t]+(?!#)(.+?)[ \t]*$", re.MULTILINE)
_PAGE_TOKEN_RE = re.compile(
r"(?<![A-Za-z0-9_])P0*([1-9][0-9]*)(?![A-Za-z0-9_])",
@@ -583,6 +587,21 @@ def build_page_context(project: str | Path, raw_page: str) -> PageContextResult:
for required in (lock_path, design_path):
if not required.is_file():
raise PageContextError(f"required artifact not found: {required.name}")
+ preflight_errors, _preflight_warnings = validate_project_artifacts(
+ project_path,
+ include_design=False,
+ )
+ if preflight_errors:
+ preview = "; ".join(preflight_errors[:8])
+ suffix = (
+ ""
+ if len(preflight_errors) <= 8
+ else f"; +{len(preflight_errors) - 8} more"
+ )
+ raise PageContextError(
+ "spec_lock/template preflight failed before page generation: "
+ f"{preview}{suffix}"
+ )
try:
lock_sections_raw = parse_markdown_artifact(
lock_path,
diff --git a/skills/ppt-master/scripts/project_specs.py b/skills/ppt-master/scripts/project_specs.py
index 99d2c0bc..33fa2a85 100644
--- a/skills/ppt-master/scripts/project_specs.py
+++ b/skills/ppt-master/scripts/project_specs.py
@@ -13,7 +13,7 @@ Examples:
from project_specs import validate_markdown_schema
Dependencies:
- None (only uses the standard library and local project_utils.py)
+ None (only uses the standard library and local project modules)
"""
from __future__ import annotations
@@ -607,8 +607,17 @@ def _validate_references(
)
if isinstance(asset_pattern, str):
+ asset_value = reference_value
+ suffix_match = re.search(r"\{value\}(\.[A-Za-z0-9]+)$", asset_pattern)
+ if (
+ suffix_match is not None
+ and asset_value.casefold().endswith(
+ suffix_match.group(1).casefold()
+ )
+ ):
+ asset_value = asset_value[: -len(suffix_match.group(1))]
try:
- relative_asset = asset_pattern.format(value=reference_value)
+ relative_asset = asset_pattern.format(value=asset_value)
except (KeyError, ValueError) as exc:
errors.append(
f"{markdown_name} schema: reference '{rule_id}' has invalid "
@@ -702,6 +711,8 @@ def _validate_spec_lock_relations(
_, _, source = parts
if source.startswith("template:"):
basename = source.removeprefix("template:").strip()
+ if basename.casefold().endswith(".svg"):
+ basename = basename[:-4]
template_path = markdown_path.parent / "templates" / f"{basename}.svg"
if not template_path.is_file():
errors.append(
@@ -908,14 +919,16 @@ def validate_markdown_schema(markdown_path: Path, schema_path: Path) -> list[str
def validate_project_artifacts(
project_path: Path,
project_info: Mapping[str, object] | None = None,
+ *,
+ include_design: bool = True,
) -> tuple[list[str], list[str]]:
- """Validate versioned artifacts and preserve markerless legacy projects."""
+ """Validate the lock and, when requested, the human-facing design brief."""
info = project_info or get_project_info_common(str(project_path))
errors: list[str] = []
warnings: list[str] = []
artifacts: list[tuple[Path, Path, str]] = []
spec_name = info.get("spec_file")
- if isinstance(spec_name, str):
+ if include_design and isinstance(spec_name, str):
artifacts.append(
(
project_path / spec_name,
@@ -934,6 +947,7 @@ def validate_project_artifacts(
legacy_design = False
legacy_lock = False
+ versioned_lock_valid = False
for artifact_path, schema_path, artifact_kind in artifacts:
try:
text = artifact_path.read_text(encoding="utf-8-sig")
@@ -952,7 +966,23 @@ def validate_project_artifacts(
legacy_design = legacy_design or artifact_kind == "design"
legacy_lock = legacy_lock or artifact_kind == "lock"
continue
- errors.extend(validate_markdown_schema(artifact_path, schema_path))
+ artifact_errors = validate_markdown_schema(artifact_path, schema_path)
+ errors.extend(artifact_errors)
+ if artifact_kind == "lock" and not artifact_errors:
+ versioned_lock_valid = True
+ if versioned_lock_valid:
+ try:
+ from svg_to_pptx.pptx_package.template_structure import (
+ TemplateStructureError,
+ load_pptx_structure_lock,
+ template_prototype_lock_errors,
+ )
+
+ structure_lock = load_pptx_structure_lock(project_path)
+ if structure_lock is not None:
+ errors.extend(template_prototype_lock_errors(structure_lock))
+ except (ImportError, TemplateStructureError) as exc:
+ errors.append(f"spec_lock.md structure preflight failed: {exc}")
if legacy_design or legacy_lock:
errors.extend(
validate_communication_trace(
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_colors.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_colors.py
index 2a5bf880..a296d9d4 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_colors.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_colors.py
@@ -138,7 +138,14 @@ def _color_rows(lock_path: Path) -> dict[str, str]:
match = _LOCK_ROW_RE.fullmatch(line)
if not match:
continue
- color = parse_hex_color(match.group(2))
+ raw_color = match.group(2).strip()
+ if (
+ len(raw_color) >= 2
+ and raw_color[0] == raw_color[-1]
+ and raw_color[0] in {'"', "'"}
+ ):
+ raw_color = raw_color[1:-1].strip()
+ color = parse_hex_color(raw_color)
if color is not None:
rows[match.group(1)] = color
return rows
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
index 71cbb534..7fed90f7 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
@@ -56,6 +56,7 @@ EA_FONTS = {
'Hiragino Kaku Gothic ProN', 'Hiragino Kaku Gothic Pro',
'Hiragino Mincho Pro',
'Noto Sans SC', 'Noto Sans TC', 'Noto Serif SC', 'Noto Serif TC',
+ 'Noto Sans CJK SC',
'Noto Sans JP', 'Noto Serif JP', 'Noto Sans CJK JP',
'Source Han Sans SC', 'Source Han Sans TC',
'Source Han Serif SC', 'Source Han Serif TC',
@@ -98,6 +99,7 @@ FONT_FALLBACK_WIN = {
'Songti SC': 'SimSun',
'Songti TC': 'SimSun',
'Noto Sans SC': 'Microsoft YaHei',
+ 'Noto Sans CJK SC': 'Microsoft YaHei',
'Noto Sans TC': 'Microsoft JhengHei',
'Noto Serif SC': 'SimSun',
'Noto Serif TC': 'SimSun',
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
index 6508c5d7..77d35297 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
@@ -290,6 +290,7 @@ def _quality_report_context(
def _postflight_warning_summaries(
*,
quality_gate: str,
+ introduced_warning_count: int,
unresolved_token_count: int,
external_image_count: int,
generic_font_stack_count: int,
@@ -298,6 +299,8 @@ def _postflight_warning_summaries(
warnings: list[str] = []
if quality_gate != 'passed':
warnings.append(f'quality_gate={quality_gate}')
+ if introduced_warning_count:
+ warnings.append(f'quality_introduced_warnings={introduced_warning_count}')
if unresolved_token_count:
warnings.append(f'unresolved_template_tokens={unresolved_token_count}')
if external_image_count:
@@ -338,10 +341,14 @@ def _write_postflight_report(
quality = _quality_report_context(project_path, source_fingerprint)
quality_categories = quality.get('categories')
blocking_count = None
+ introduced_warning_count = 0
if isinstance(quality_categories, dict):
blocking = quality_categories.get('blocking')
if isinstance(blocking, dict):
blocking_count = blocking.get('count')
+ introduced = quality_categories.get('introduced')
+ if isinstance(introduced, dict) and isinstance(introduced.get('count'), int):
+ introduced_warning_count = int(introduced['count'])
if quality.get('status') != 'loaded':
quality_gate = str(quality.get('status') or 'not-provided')
elif quality.get('stage') != 'final':
@@ -365,6 +372,7 @@ def _write_postflight_report(
not unresolved_tokens
and not external_image_count
and not generic_only_font_stacks
+ and not introduced_warning_count
and quality_gate == 'passed'
):
report_status = 'passed'
@@ -398,6 +406,9 @@ def _write_postflight_report(
'transitions': 'enforced-at-build',
'animations': 'enforced-at-build',
'quality_gate': quality_gate,
+ 'quality_warnings': (
+ 'passed' if not introduced_warning_count else 'warning'
+ ),
'template_tokens': (
'passed' if not unresolved_tokens else 'warning'
),
@@ -424,6 +435,7 @@ def _write_postflight_report(
)
warnings = _postflight_warning_summaries(
quality_gate=quality_gate,
+ introduced_warning_count=introduced_warning_count,
unresolved_token_count=len(unresolved_tokens),
external_image_count=external_image_count,
generic_font_stack_count=len(generic_only_font_stacks),
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/template_structure.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/template_structure.py
index 9e66d044..d2d569c5 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/template_structure.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/template_structure.py
@@ -1985,6 +1985,28 @@ def structured_layout_definition_files(
return definition_files
+def template_prototype_lock_errors(
+ structure_lock: PptxStructureLock,
+) -> list[str]:
+ """Return template-root identity mismatches visible before page generation."""
+ if structure_lock.mode != "structured":
+ return []
+
+ errors: list[str] = []
+ specs: list[TemplateSlideSpec] = []
+ for prototype in structure_lock.prototypes:
+ try:
+ specs.append(
+ parse_template_slide(prototype.svg_path, prototype.slide_num)
+ )
+ except TemplateStructureError as exc:
+ errors.append(str(exc))
+ if errors:
+ return list(dict.fromkeys(errors))
+ errors.extend(template_lock_errors(specs, structure_lock))
+ return list(dict.fromkeys(errors))
+
+
def template_lock_errors(
specs: list[TemplateSlideSpec],
structure_lock: PptxStructureLock,