Agent-driven creation of editable, tastefully crafted visual artifacts.
Python
feat: make html-to-pptx self-initializing
Junyanyea8132a7ead8c
diff --git a/.gitignore b/.gitignoreindex 962bccb..165a1d1 100644--- a/.gitignore+++ b/.gitignore@@ -7,3 +7,4 @@ out/.trace/*.tar.gz*.zip+.venv/diff --git a/README.md b/README.mdindex 626947a..3e5867a 100644--- a/README.md+++ b/README.md@@ -104,14 +104,22 @@ npm ci --prefix ~/.codex/skills/editable-design/scripts### Optional: Editable PowerPoint export-Install the companion `html-to-pptx` Skill only when editable PowerPoint export is needed:+For a one-step Codex installation, ask:++```text+Install the html-to-pptx Codex Skill from:+https://github.com/yejy53/Editable-Design/tree/main/skills/html-to-pptx++Use it to convert my compatible HTML into an editable PowerPoint file.+```++Codex installs the Skill from that subdirectory. Its first conversion automatically prepares an isolated Python environment and Playwright Chromium; the user does not need to run dependency commands.++For a manual source install:```bashgit sparse-checkout add skills/html-to-pptxcp -R skills/html-to-pptx ~/.codex/skills/-python3 -m pip install -r ~/.codex/skills/html-to-pptx/requirements.txt-python3 -m playwright install chromium-~/.codex/skills/html-to-pptx/scripts/doctor.sh```See [`editable-design`](./skills/editable-design/README.md) and [`html-to-pptx`](./skills/html-to-pptx/README.md) for detailed requirements and commands. To build a clean source archive containing both Skills, run `./pack.sh`.diff --git a/TOOLKIT.md b/TOOLKIT.mdindex 782c9cf..ef23609 100644--- a/TOOLKIT.md+++ b/TOOLKIT.md@@ -40,14 +40,11 @@ npm ci --prefix ~/.codex/skills/editable-design/scriptsThe font kit is self-hosted and versioned. Each generated project copies onlythe WOFF2 files it selects, rather than carrying the full library.-For optional PowerPoint export, install its Python dependencies and Playwright browser:+For optional PowerPoint export, copy the sibling Skill. Its first conversion prepares and reuses an isolated runtime automatically:```bashgit sparse-checkout add skills/html-to-pptxcp -R skills/html-to-pptx ~/.codex/skills/-python3 -m pip install -r ~/.codex/skills/html-to-pptx/requirements.txt-python3 -m playwright install chromium-~/.codex/skills/html-to-pptx/scripts/doctor.sh```Detailed requirements and direct CLI usage are documented in each skill's README:diff --git a/pack.sh b/pack.shindex dd70113..c61a3a1 100755--- a/pack.sh+++ b/pack.sh@@ -17,7 +17,7 @@ cp -R "$toolkit_dir/skills/html-to-pptx" "$stage/$name/skills/"find "$stage/$name" -name '.DS_Store' -deletefind "$stage/$name" -name '._*' -delete-find "$stage/$name" -type d \( -name node_modules -o -name __pycache__ \) -prune -exec rm -rf {} ++find "$stage/$name" -type d \( -name node_modules -o -name __pycache__ -o -name .venv \) -prune -exec rm -rf {} +find "$stage/$name" -type f \( -name '*.tar.gz' -o -name '*.zip' \) -deletetar -czf "$out" -C "$stage" "$name"diff --git a/skills/html-to-pptx/README.md b/skills/html-to-pptx/README.mdindex 7d81618..5bcdb84 100644--- a/skills/html-to-pptx/README.md+++ b/skills/html-to-pptx/README.md@@ -2,33 +2,31 @@`html-to-pptx` is an independent Codex skill that deterministically converts compatible slide, poster, and fixed-canvas HTML into an editable PowerPoint file. One entry point automatically handles clean design HTML, Editable Design's `editor.html`, and `layers.html` exploded-layer boards.-## Requirements+## Zero-configuration setup-- Python 3.10 or newer-- Playwright Chromium-- `python-pptx`, Pillow, and NumPy+Use the wrapper below. On first use it finds a compatible Python runtime, creates an isolated `.venv` inside the Skill, installs the Python packages and Playwright Chromium, and then continues the requested conversion. Later runs reuse the environment.```bash-python3 -m pip install -r requirements.txt-python3 -m playwright install chromium-scripts/doctor.sh+bash scripts/run.sh /path/to/index.html -o /path/to/design.pptx```+Users do not need to run `pip`, install Playwright, or repair executable permissions. If automatic setup needs diagnosis, run `bash scripts/setup.sh`. Set `HTML_TO_PPTX_PYTHON` only when a specific Python 3.10+ executable must be used.+Chromium sandboxing stays enabled by default. Set `HTML_TO_PPTX_NO_SANDBOX=1` only when the host cannot launch Chromium with its sandbox.Optional visual comparison additionally requires LibreOffice and PyMuPDF:```bash-python3 -m pip install -r requirements-check.txt+.venv/bin/python -m pip install -r requirements-check.txt```## Usage```bash-python3 scripts/to_pptx.py /path/to/index.html -o /path/to/design.pptx-python3 scripts/to_pptx.py /path/to/editor.html-python3 scripts/to_pptx.py /path/to/layers.html --keep-overview-python3 scripts/render_check.py /path/to/index.html /path/to/design.pptx+bash scripts/run.sh /path/to/index.html -o /path/to/design.pptx+bash scripts/run.sh /path/to/editor.html+bash scripts/run.sh /path/to/layers.html --keep-overview+.venv/bin/python scripts/render_check.py /path/to/index.html /path/to/design.pptx```The default `--mode auto` recognizes `plain`, `editor`, and `exploded` pages. For `editor.html`, it calls the editor's own `fullHTML()` export to remove the toolbar, panels, and scaled stage before conversion. For `layers.html`, it waits for the animation to settle and removes the overview by default. Use `--mode` only when automatic detection needs to be overridden.diff --git a/skills/html-to-pptx/SKILL.md b/skills/html-to-pptx/SKILL.mdindex 00f9e27..54efdd5 100644--- a/skills/html-to-pptx/SKILL.md+++ b/skills/html-to-pptx/SKILL.md@@ -9,20 +9,25 @@ description: 把 slide/poster 的 HTML 确定性地转成可编辑 PPTX——目标不是「截个图塞进 ppt」,而是让 PowerPoint 里每个元素都能单独选中、拖动、改字、改色。-## 前置依赖+## 零配置入口++始终通过 `scripts/run.sh` 转换。首次调用时,它会自动找到 Codex 或系统提供的 Python+3.10+,在 Skill 内创建隔离的 `.venv`,安装 Python 依赖和 Playwright Chromium,然后继续+当前转换;以后直接复用,不让用户手动配置环境:```bash-python3 -m pip install -r requirements.txt-python3 -m playwright install chromium-./scripts/doctor.sh+bash scripts/run.sh <任意 HTML> -o deck.pptx```+不要要求用户先运行 `pip`、安装 Playwright 或处理脚本权限。若自动初始化失败,再运行+`bash scripts/setup.sh` 查看明确诊断;`HTML_TO_PPTX_PYTHON` 可用于指定兼容的 Python。+确定性转换核心已经随 Skill 固定在 `scripts/_html_to_pptx.py`,不依赖其他私有仓库。浏览器默认保留 Chromium 沙箱;只有运行环境明确不支持沙箱时,才设置`HTML_TO_PPTX_NO_SANDBOX=1`。`render_check.py` 额外需要 LibreOffice(渲染 pptx)和 PyMuPDF:-`brew install --cask libreoffice && python3 -m pip install -r requirements-check.txt`。+`brew install --cask libreoffice && .venv/bin/python -m pip install -r requirements-check.txt`。这两项只用于视觉比对,不影响核心转换。## 转换@@ -30,10 +35,10 @@ python3 -m playwright install chromium一个入口支持三类页面并自动识别:```bash-python3 scripts/to_pptx.py <任意 HTML> # → 同目录同名 .pptx-python3 scripts/to_pptx.py <HTML> -o deck.pptx-python3 scripts/to_pptx.py <HTML> --selector '#hero' # 画布识别失败时手动指定-python3 scripts/to_pptx.py <HTML> --mode exploded # 自动识别出错时手动指定+bash scripts/run.sh <任意 HTML> # → 同目录同名 .pptx+bash scripts/run.sh <HTML> -o deck.pptx+bash scripts/run.sh <HTML> --selector '#hero' # 画布识别失败时手动指定+bash scripts/run.sh <HTML> --mode exploded # 自动识别出错时手动指定```| 输入页面 | 自动模式 | 转换前处理 |@@ -65,10 +70,8 @@ python3 scripts/to_pptx.py <HTML> --mode exploded # 自动识别出PPTX,默认丢掉 overview 那一项:```bash-python3 scripts/to_pptx.py <case>/layers.html # → 同目录 layers.pptx-python3 scripts/to_pptx.py <case>/layers.html --keep-overview-python3 scripts/exploded_to_pptx.py <case>/layers.html # 等价的专用入口-python3 scripts/exploded_to_pptx.py <case>/layers.html --keep-overview+bash scripts/run.sh <case>/layers.html # → 同目录 layers.pptx+bash scripts/run.sh <case>/layers.html --keep-overview``````@@ -227,7 +230,8 @@ z-index:1` 的卡片会排到自己子元素后面,用底色盖住自己的图`pack.sh` 会把完整 Skill(含固定的 `scripts/_html_to_pptx.py`、依赖清单、许可和诊断脚本)一起打包,解压后不依赖本仓库其他文件。-对方:`tar -xzf html-to-pptx-skill.tar.gz -C ~/.codex/skills/`,装好 Python 依赖即可用。+对方:`tar -xzf html-to-pptx-skill.tar.gz -C ~/.codex/skills/`。首次转换会自动准备隔离运行时,+无需另外安装 Python 包或 Playwright。包里带着 `pack.sh` 自己,可继续二次分发。## 与 Editable Design 的关系diff --git a/skills/html-to-pptx/pack.sh b/skills/html-to-pptx/pack.shindex b0d79d8..740a287 100755--- a/skills/html-to-pptx/pack.sh+++ b/skills/html-to-pptx/pack.sh@@ -20,7 +20,7 @@ ficp -R "$HERE" "$STAGE/$NAME"find "$STAGE/$NAME" -name '.DS_Store' -deletefind "$STAGE/$NAME" -name '._*' -delete-find "$STAGE/$NAME" -type d -name '__pycache__' -prune -exec rm -rf {} ++find "$STAGE/$NAME" -type d \( -name '__pycache__' -o -name '.venv' \) -prune -exec rm -rf {} +mkdir -p "$(dirname "$OUT")"rm -f "$OUT"@@ -41,7 +41,8 @@ echo " 体积 $(du -h "$OUT" | cut -f1) 文件 $COUNT 个"echo ""echo "对方使用方式:"echo " $UNPACK"-echo " cd ~/.codex/skills/$NAME && python3 -m pip install -r requirements.txt"-echo " python3 -m playwright install chromium && ./scripts/doctor.sh"+echo " 首次转换直接运行:bash ~/.codex/skills/$NAME/scripts/run.sh <input.html>"+echo " Skill 会自动创建隔离环境并安装所需依赖。"echo ""-echo "前置要求:Python 3.10+。跑 render_check.py 还需 LibreOffice 与 PyMuPDF。"+echo "系统需要可用的 Python 3.10+;Codex Desktop 自带的兼容运行时会被自动发现。"+echo "跑 render_check.py 还需 LibreOffice 与 PyMuPDF。"diff --git a/skills/html-to-pptx/scripts/doctor.sh b/skills/html-to-pptx/scripts/doctor.shindex e1c8228..3aff339 100755--- a/skills/html-to-pptx/scripts/doctor.sh+++ b/skills/html-to-pptx/scripts/doctor.sh@@ -2,6 +2,17 @@set -ufailures=0+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+SKILL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"+VENV_PYTHON="$SKILL_DIR/.venv/bin/python"++if [[ -n "${HTML_TO_PPTX_PYTHON:-}" ]]; then+ PYTHON_BIN="$HTML_TO_PPTX_PYTHON"+elif [[ -x "$VENV_PYTHON" ]]; then+ PYTHON_BIN="$VENV_PYTHON"+else+ PYTHON_BIN="$(command -v python3 2>/dev/null || true)"+fiok() { printf '%-22s %s\n' "$1" "OK $2"; }warn() { printf '%-22s %s\n' "$1" "OPTIONAL $2"; }@@ -9,8 +20,8 @@ bad() { printf '%-22s %s\n' "$1" "MISSING $2"; failures=$((failures + 1)); }printf '%s\n\n' "HTML to PPTX doctor"-if command -v python3 >/dev/null 2>&1; then- version="$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:3])))')"+if [[ -n "$PYTHON_BIN" && -x "$PYTHON_BIN" ]]; then+ version="$("$PYTHON_BIN" -c 'import sys; print(".".join(map(str, sys.version_info[:3])))')"major="${version%%.*}"minor="$(printf '%s' "$version" | cut -d. -f2)"if [[ "$major" -gt 3 || ( "$major" -eq 3 && "$minor" -ge 10 ) ]]; then ok "Python" "$version"; else bad "Python" "$version; requires >=3.10"; fi@@ -19,10 +30,22 @@ elsefifor module in playwright pptx PIL numpy; do- if python3 -c "import $module" >/dev/null 2>&1; then ok "$module" "installed"; else bad "$module" "install requirements.txt"; fi+ if [[ -n "$PYTHON_BIN" ]] && "$PYTHON_BIN" -c "import $module" >/dev/null 2>&1; then ok "$module" "installed"; else bad "$module" "run: bash scripts/setup.sh"; fidone-if python3 -c 'import fitz' >/dev/null 2>&1; then warn "PyMuPDF" "installed for comparison"; else warn "PyMuPDF" "install requirements-check.txt for comparison"; fi+if [[ -n "$PYTHON_BIN" ]] && "$PYTHON_BIN" -c 'import fitz' >/dev/null 2>&1; then warn "PyMuPDF" "installed for comparison"; else warn "PyMuPDF" "install requirements-check.txt for comparison"; fi++if [[ -n "$PYTHON_BIN" ]] && "$PYTHON_BIN" - <<'PY' >/dev/null 2>&1+from pathlib import Path+from playwright.sync_api import sync_playwright+with sync_playwright() as playwright:+ raise SystemExit(0 if Path(playwright.chromium.executable_path).is_file() else 1)+PY+then+ ok "Chromium" "installed"+else+ bad "Chromium" "run: bash scripts/setup.sh"+fisoffice="${SOFFICE_PATH:-}"if [[ -n "$soffice" && -x "$soffice" ]]; thendiff --git a/skills/html-to-pptx/scripts/run.sh b/skills/html-to-pptx/scripts/run.shnew file mode 100755index 0000000..177eb3d--- /dev/null+++ b/skills/html-to-pptx/scripts/run.sh@@ -0,0 +1,30 @@+#!/usr/bin/env bash+set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+SKILL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"+VENV_DIR="${HTML_TO_PPTX_VENV:-$SKILL_DIR/.venv}"+VENV_PYTHON="$VENV_DIR/bin/python"++runtime_is_ready() {+ [[ -f "$VENV_DIR/.setup-complete" ]] || return 1+ [[ -x "$VENV_PYTHON" ]] || return 1+ "$VENV_PYTHON" - <<'PY' >/dev/null 2>&1+from pathlib import Path+from playwright.sync_api import sync_playwright+import numpy # noqa: F401+import PIL # noqa: F401+import pptx # noqa: F401++with sync_playwright() as playwright:+ if not Path(playwright.chromium.executable_path).is_file():+ raise SystemExit(1)+PY+}++if ! runtime_is_ready; then+ printf '%s\n' 'Preparing html-to-pptx for first use…'+ bash "$SCRIPT_DIR/setup.sh"+fi++exec "$VENV_PYTHON" "$SCRIPT_DIR/to_pptx.py" "$@"diff --git a/skills/html-to-pptx/scripts/setup.sh b/skills/html-to-pptx/scripts/setup.shnew file mode 100755index 0000000..d1d7430--- /dev/null+++ b/skills/html-to-pptx/scripts/setup.sh@@ -0,0 +1,69 @@+#!/usr/bin/env bash+set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+SKILL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"+VENV_DIR="${HTML_TO_PPTX_VENV:-$SKILL_DIR/.venv}"++python_is_supported() {+ "$1" -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 10) else 1)' \+ >/dev/null 2>&1+}++find_python() {+ local candidate command_name++ if [[ -n "${HTML_TO_PPTX_PYTHON:-}" ]]; then+ if [[ -x "$HTML_TO_PPTX_PYTHON" ]] && python_is_supported "$HTML_TO_PPTX_PYTHON"; then+ printf '%s\n' "$HTML_TO_PPTX_PYTHON"+ return 0+ fi+ printf 'HTML_TO_PPTX_PYTHON is not an executable Python 3.10+: %s\n' \+ "$HTML_TO_PPTX_PYTHON" >&2+ return 1+ fi++ for command_name in python3.13 python3.12 python3.11 python3.10 python3 python; do+ candidate="$(command -v "$command_name" 2>/dev/null || true)"+ if [[ -n "$candidate" ]] && python_is_supported "$candidate"; then+ printf '%s\n' "$candidate"+ return 0+ fi+ done++ # Codex Desktop ships a private Python runtime that is not always on PATH.+ # Discover it dynamically instead of baking in a user-specific absolute path.+ shopt -s nullglob+ for candidate in "$HOME"/.cache/codex-runtimes/*/dependencies/python/bin/python3; do+ if [[ -x "$candidate" ]] && python_is_supported "$candidate"; then+ printf '%s\n' "$candidate"+ return 0+ fi+ done++ return 1+}++PYTHON_BIN="$(find_python || true)"+if [[ -z "$PYTHON_BIN" ]]; then+ printf '%s\n' \+ 'html-to-pptx needs Python 3.10 or newer. Codex could not find a compatible runtime.' \+ 'Set HTML_TO_PPTX_PYTHON to a compatible Python executable and retry.' >&2+ exit 1+fi++printf 'Setting up html-to-pptx with %s (%s)\n' \+ "$PYTHON_BIN" "$($PYTHON_BIN -c 'import sys; print(sys.version.split()[0])')"++"$PYTHON_BIN" -m venv --clear "$VENV_DIR"+VENV_PYTHON="$VENV_DIR/bin/python"++"$VENV_PYTHON" -m pip install --disable-pip-version-check --upgrade pip+"$VENV_PYTHON" -m pip install --disable-pip-version-check -r "$SKILL_DIR/requirements.txt"+"$VENV_PYTHON" -m playwright install chromium++HTML_TO_PPTX_PYTHON="$VENV_PYTHON" bash "$SCRIPT_DIR/doctor.sh"+printf '%s\n' "$($VENV_PYTHON -c 'import sys; print(sys.version.split()[0])')" \+ > "$VENV_DIR/.setup-complete"++printf '\nhtml-to-pptx is ready. Future conversions will reuse %s\n' "$VENV_DIR"