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(scripts): init resolves the projects root from the skill, page count must match the roster, slice diagnostics tell drift from overflow
hugohe37e3eb8de83b3
diff --git a/skills/ppt-master/scripts/project_management/cli.py b/skills/ppt-master/scripts/project_management/cli.pyindex 17e8d7b4..d0089141 100644--- a/skills/ppt-master/scripts/project_management/cli.py+++ b/skills/ppt-master/scripts/project_management/cli.py@@ -230,7 +230,7 @@ class ProjectManager:CANVAS_FORMATS = CANVAS_FORMATSdef __init__(self, base_dir: str | Path | None = None) -> None:- self.base_dir = Path(base_dir) if base_dir is not None else Path.cwd() / "projects"+ self.base_dir = Path(base_dir) if base_dir is not None else PROJECTS_ROOTdef scaffold_artifact(self, project_path: str, artifact: str) -> str:"""Delegate deterministic Markdown scaffold rendering."""diff --git a/skills/ppt-master/scripts/project_management/project_specs.py b/skills/ppt-master/scripts/project_management/project_specs.pyindex ad7db2ba..6abd2086 100644--- a/skills/ppt-master/scripts/project_management/project_specs.py+++ b/skills/ppt-master/scripts/project_management/project_specs.py@@ -840,6 +840,20 @@ def _validate_condition(return errors+_PAGE_COUNT_ROW_RE = re.compile(+ r"^\|[ \t]*Page Count[ \t]*\|[ \t]*([0-9]+)[ \t]*\|",+ flags=re.IGNORECASE | re.MULTILINE,+)+++def _declared_page_count(section: Mapping[str, object] | None) -> int | None:+ """Return the exact integer §I Page Count, or None when absent or not exact."""+ if section is None:+ return None+ match = _PAGE_COUNT_ROW_RE.search(str(section.get("body", "")))+ return int(match.group(1)) if match else None++def _validate_slides(*,markdown_name: str,@@ -862,6 +876,13 @@ def _validate_slides(return [f"{markdown_name} schema: content outline has no Slide blocks"]errors: list[str] = []+ declared = _declared_page_count(matched.get("project_information"))+ if declared is not None and declared != len(heading_matches):+ errors.append(+ f"{markdown_name} schema: §I Page Count is {declared} but the "+ f"content outline has {len(heading_matches)} Slide block(s); "+ "the two must match"+ )required_fields = slide_contract.get("required_fields", [])if not isinstance(required_fields, list):return errorsdiff --git a/skills/ppt-master/scripts/slice_images.py b/skills/ppt-master/scripts/slice_images.pyindex 28efdd2c..5ddc77a8 100644--- a/skills/ppt-master/scripts/slice_images.py+++ b/skills/ppt-master/scripts/slice_images.py@@ -63,6 +63,12 @@ _DEFAULT_FEATHER = 4_BOUNDARY_OPAQUE_ALPHA = 32_SHEET_DIAGNOSTIC_BORDER_RATIO = 0.01_SHEET_DIAGNOSTIC_BUCKET_SIZE = 4+# Isolated pixels this close to the key are compression or ringing artifacts a+# larger tolerance absorbs; farther pixels are content crossing the gutter.+_KEY_DRIFT_MAX_TOLERANCE = 48+_KEY_DRIFT_MARGIN = 4+# At most this many trim pixels on a touched edge count as isolated drift.+_EDGE_DRIFT_MAX_PIXELS = 8def _log(msg: str) -> None:@@ -181,7 +187,12 @@ def _sample_bg(cell: Image.Image, tolerance: int) -> tuple[int, int, int]:def _sample_sheet_border(sheet: Image.Image,) -> tuple[tuple[int, int, int], int]:- """Return the dominant RGB cluster and its spread in the outer 1% ring."""+ """Return the dominant RGB cluster, its spread, and the ring's farthest pixel.++ The spread describes the key field itself; the outlier distance is what a+ ``--tolerance`` must reach so that isolated ringing or compression pixels+ in the gutter still key out.+ """rgb = sheet.convert("RGB")width, height = rgb.sizeborder_x = max(1, round(width * _SHEET_DIAGNOSTIC_BORDER_RATIO))@@ -222,7 +233,11 @@ def _sample_sheet_border(- min(pixel[index] for pixel in dominant_pixels)for index in range(3)]- return dominant, max(channel_spreads) # type: ignore[return-value]+ outlier = max(+ max(abs(pixel[index] - dominant[index]) for index in range(3))+ for pixel in pixels+ )+ return dominant, max(channel_spreads), outlier # type: ignore[return-value]def _max_channel_difference(cell: Image.Image, bg: tuple[int, int, int]) -> Image.Image:@@ -355,8 +370,8 @@ def _content_masks(cell: Image.Image,bg: tuple[int, int, int],tolerance: int,-) -> tuple[Image.Image, Image.Image, Optional[Image.Image]]:- """Build trim/alpha masks and optional chroma-decontaminated RGB."""+) -> tuple[Image.Image, Image.Image, Optional[Image.Image], Image.Image]:+ """Build trim/alpha masks, optional chroma-decontaminated RGB, and the key diff."""rgb = cell.convert("RGB")diff = _max_channel_difference(rgb, bg)trim_mask = diff.point(lambda p: 255 if p > tolerance else 0)@@ -365,10 +380,10 @@ def _content_masks(chroma_alpha = _chroma_alpha(rgb, bg)alpha_mask = ImageChops.multiply(chroma_alpha, tolerance_gate)keyed_rgb = _decontaminate_rgb(rgb, chroma_alpha, bg)- return trim_mask, alpha_mask, keyed_rgb+ return trim_mask, alpha_mask, keyed_rgb, diffalpha_mask = tolerance_gate.filter(ImageFilter.MinFilter(3))- return trim_mask, alpha_mask, None+ return trim_mask, alpha_mask, None, diffdef _keying_findings(@@ -380,6 +395,8 @@ def _keying_findings(*,trim: bool,alpha: bool,+ trim_mask: Optional[Image.Image] = None,+ diff: Optional[Image.Image] = None,) -> list[str]:"""Report objective signs that the flat-background key did not take.@@ -427,18 +444,59 @@ def _keying_findings(if bbox[3] >= cell_height:touched_edges.append("bottom")if touched_edges:- findings.append(- f"{label}: content reaches the {'/'.join(touched_edges)} cell edge(s) "- f"(key background {hex_bg})"- )+ drift = _edge_drift(trim_mask, diff, touched_edges)+ if drift is not None:+ count, distance = drift+ findings.append(+ f"{label}: {count} isolated pixel(s) on the "+ f"{'/'.join(touched_edges)} cell edge(s) exceed the key "+ f"tolerance (farthest {distance} from key {hex_bg}); this is "+ f"key drift, not content — rerun with --tolerance "+ f"{distance + _KEY_DRIFT_MARGIN} or higher"+ )+ else:+ findings.append(+ f"{label}: content reaches the {'/'.join(touched_edges)} "+ f"cell edge(s) (key background {hex_bg})"+ )return findings+def _edge_drift(+ trim_mask: Optional[Image.Image],+ diff: Optional[Image.Image],+ touched_edges: list[str],+) -> Optional[tuple[int, int]]:+ """Return (pixel count, max key distance) when the touched edges hold only+ a few near-key pixels, or None when real content reaches an edge."""+ if trim_mask is None or diff is None:+ return None+ width, height = trim_mask.size+ mask_px = trim_mask.load()+ diff_px = diff.load()+ coords = set()+ if "left" in touched_edges:+ coords.update((0, y) for y in range(height))+ if "right" in touched_edges:+ coords.update((width - 1, y) for y in range(height))+ if "top" in touched_edges:+ coords.update((x, 0) for x in range(width))+ if "bottom" in touched_edges:+ coords.update((x, height - 1) for x in range(width))+ hits = [diff_px[x, y] for x, y in coords if mask_px[x, y]]+ if not hits or len(hits) > _EDGE_DRIFT_MAX_PIXELS:+ return None+ distance = max(hits)+ if distance > _KEY_DRIFT_MAX_TOLERANCE:+ return None+ return len(hits), distance++def _log_keying_findings(findings: list[str],*,- sheet_border: tuple[tuple[int, int, int], int] | None = None,+ sheet_border: tuple[tuple[int, int, int], int, int] | None = None,tolerance: int,) -> None:"""Report incomplete flat-background keying."""@@ -453,17 +511,27 @@ def _log_keying_findings(_log(" --bg <hex> and a larger --tolerance; use --inset when a drawn ""outer gutter is isolated from every element.")if sheet_border is not None:- dominant, drift = sheet_border+ dominant, drift, outlier = sheet_borderhex_bg = "#{:02X}{:02X}{:02X}".format(*dominant)- suggested_tolerance = max(tolerance, drift)_log(" Measured outer 1% border/gutter: "- f"dominant {hex_bg}; max channel spread {drift}."- )- _log(- " Suggested rerun: "- f"--bg {hex_bg} --tolerance {suggested_tolerance}"+ f"dominant {hex_bg}; key spread {drift}; farthest pixel {outlier} "+ "from the key.")+ if outlier > _KEY_DRIFT_MAX_TOLERANCE:+ _log(+ " The gutter holds pixels far from the key: content or an "+ "effect crosses it. Regenerate with a clear key-only gutter; a "+ "larger --tolerance would eat into the elements."+ )+ else:+ suggested_tolerance = max(+ tolerance, drift, outlier + _KEY_DRIFT_MARGIN+ )+ _log(+ " Suggested rerun: "+ f"--bg {hex_bg} --tolerance {suggested_tolerance}"+ )def slice_sheet(@@ -541,7 +609,7 @@ def slice_sheet(bbox = Noneif trim or alpha:cell_bg = bg if bg is not None else _sample_bg(cell, tolerance)- trim_mask, alpha_mask, keyed_rgb = _content_masks(+ trim_mask, alpha_mask, keyed_rgb, diff = _content_masks(cell, cell_bg, tolerance)bbox = trim_mask.getbbox()@@ -549,7 +617,7 @@ def slice_sheet(raise ValueError(f"cell ({r},{c}) is all background; no element was sliced")findings.extend(_keying_findings(f"cell ({r},{c})", cell.size, bbox, alpha_mask, cell_bg,- trim=trim, alpha=alpha,+ trim=trim, alpha=alpha, trim_mask=trim_mask, diff=diff,))if trim and trim_mask is not None and alpha_mask is not None and bbox is not None:diff --git a/skills/ppt-master/scripts/text_measure.py b/skills/ppt-master/scripts/text_measure.pyindex a62f2872..85b29177 100644--- a/skills/ppt-master/scripts/text_measure.py+++ b/skills/ppt-master/scripts/text_measure.py@@ -286,7 +286,10 @@ def _ordered_roles(roles: dict[str, tuple[str, float]]) -> list[tuple[str, str,return [(name, *roles[name]) for name in names]-def _roles_from_spec_lock(lock_path: Path) -> dict[str, tuple[str, float]]:+def _roles_from_spec_lock(+ lock_path: Path,+ fallbacks: dict[str, str] | None = None,+) -> dict[str, tuple[str, float]]:lock = parse_spec_lock(lock_path, report_duplicate_fields=True)typography = next((@@ -315,6 +318,8 @@ def _roles_from_spec_lock(lock_path: Path) -> dict[str, tuple[str, float]]:display_role = 'title' in role or 'numeral' in rolefallback = 'title_family' if display_role else 'body_family'family = rows.get(fallback, '') or rows.get('font_family', '')+ if fallbacks is not None:+ fallbacks[role] = fallbackif not family:raise ValueError(f'spec_lock.md typography role {role!r} has no resolvable font family'@@ -488,6 +493,26 @@ def _calibration_payload(}+def _fallback_notes(+ roles: dict[str, tuple[str, float]],+ fallbacks: dict[str, str],+) -> list[str]:+ """Flag display-sized roles that inherited body_family by default."""+ body = roles.get('body')+ if body is None:+ return []+ notes = []+ for role, fallback in sorted(fallbacks.items()):+ size = roles[role][1]+ if fallback == 'body_family' and size >= 2 * body[1]:+ notes.append(+ f'role {role} ({_format_number(size)}px, at least twice body) has '+ f'no {role}_family and uses body_family; declare {role}_family '+ 'if it is display type'+ )+ return notes++def _render_calibration_table(payload: dict[str, object], *, include_outline: bool) -> str:role_rows = payload['roles']assert isinstance(role_rows, dict)@@ -516,6 +541,8 @@ def _render_calibration_table(payload: dict[str, object], *, include_outline: boelse f'{planned["px"]:.1f}px, {planned["slide"]}, {planned["text"]}')lines.append(' | '.join(row))+ for note in payload.get('notes') or []:+ lines.append(f'[NOTE] {note}')lines.append('[NOTE] mixed line width ≈ (CJK chars ÷ CJK rate + other chars ÷ Latin ''rate) × 100; spaces, digits, and punctuation count as Latin.'@@ -539,9 +566,15 @@ def _run_calibrate(args: argparse.Namespace) -> int:)return 2try:- roles = _roles_from_spec_lock(lock_path) if lock_path.is_file() else {}+ fallbacks: dict[str, str] = {}+ roles = (+ _roles_from_spec_lock(lock_path, fallbacks)+ if lock_path.is_file()+ else {}+ )for name, family, size in args.role:roles[name] = (family, size)+ fallbacks.pop(name, None)ordered_roles = _ordered_roles(roles)if not ordered_roles:raise ValueError('no typography size roles were found')@@ -552,6 +585,7 @@ def _run_calibrate(args: argparse.Namespace) -> int:source=source,include_outline=args.outline,)+ payload['notes'] = _fallback_notes(roles, fallbacks)output_path = project_path / 'validation' / 'text_calibration.json'output_path.parent.mkdir(parents=True, exist_ok=True)rendered_json = json.dumps(payload, ensure_ascii=False, indent=2)