mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 18:59:29 +08:00
fix(office): 修复独立技能的 Python 依赖入口 (#229)
为 pptx 与 xlsx 提供标准库启动器,使用已准备的受管 XML 依赖,保留目标退出码并避免失败后重放编辑。 同步双语说明、目录版本和固定启动器合同测试。 Refs desirecore/desirecore#5335
This commit is contained in:
12 files changed
+462
-38
No files matched your search
+18
-12
@@ -13,7 +13,7 @@ description: >-
|
||||
content afterward. If a .pptx file needs to be opened, created, or touched,
|
||||
use this skill. Use when 用户提到 PPT、演示文稿、幻灯片、演讲稿、汇报材料、
|
||||
pptx、创建演示、编辑幻灯片。
|
||||
version: 1.0.5
|
||||
version: 1.0.6
|
||||
type: procedural
|
||||
risk_level: low
|
||||
status: enabled
|
||||
@@ -26,7 +26,7 @@ tags:
|
||||
- office
|
||||
metadata:
|
||||
author: anthropic
|
||||
updated_at: '2026-10-14'
|
||||
updated_at: '2026-10-28'
|
||||
i18n:
|
||||
default_locale: en-US
|
||||
source_locale: zh-CN
|
||||
@@ -39,7 +39,7 @@ metadata:
|
||||
description: >-
|
||||
Use this skill any time a .pptx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates, layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx filename, regardless of what they plan to do with the content afterward. If a .pptx file needs to be opened, created, or touched, use this skill. Use when 用户提到 PPT、演示文稿、幻灯片、演讲稿、汇报材料、 pptx、创建演示、编辑幻灯片。
|
||||
body: ./SKILL.zh-CN.md
|
||||
source_hash: sha256:a952bf5622ede8e0
|
||||
source_hash: sha256:c8569b584e23df32
|
||||
translated_by: human
|
||||
en-US:
|
||||
name: Presentation Processing
|
||||
@@ -47,7 +47,7 @@ metadata:
|
||||
description: >-
|
||||
Use this skill any time a .pptx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates, layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx filename, regardless of what they plan to do with the content afterward. If a .pptx file needs to be opened, created, or touched, use this skill. Use when the user mentions PPT, presentation, slides, speaker notes, briefing materials, pptx, creating presentations, or editing slides.
|
||||
body: ./SKILL.md
|
||||
source_hash: sha256:9d8c46a62ef8bfb8
|
||||
source_hash: sha256:c8569b584e23df32
|
||||
translated_by: human
|
||||
market:
|
||||
icon: >-
|
||||
@@ -95,16 +95,19 @@ pptx is a **Procedural Skill** providing full PowerPoint presentation processing
|
||||
|
||||
The Python scripts bundled with this skill live inside the skill installation directory. You **MUST use full paths** when invoking them — never use bare relative paths.
|
||||
|
||||
The skill directory is provided by the `<skill-dir>` tag in the context. Prefix all `scripts/` commands accordingly:
|
||||
The skill directory is provided by the `<skill-dir>` tag in the context. Run Office XML scripts through the cross-platform `with-deps.py` launcher. It adds the client's prepared `runtime-deps/python-libs` and prefers the prepared `runtime-deps/python-runtime` interpreter, so XML editing needs no online package installation:
|
||||
|
||||
```bash
|
||||
python "<skill-dir>/scripts/office/unpack.py" presentation.pptx unpacked/
|
||||
python "<skill-dir>/scripts/office/pack.py" unpacked/ output.pptx
|
||||
python "<skill-dir>/scripts/with-deps.py" office/unpack.py presentation.pptx unpacked/
|
||||
python "<skill-dir>/scripts/with-deps.py" office/pack.py unpacked/ output.pptx
|
||||
python "<skill-dir>/scripts/with-deps.py" office/validate.py output.pptx
|
||||
python "<skill-dir>/scripts/office/soffice.py" --headless --convert-to pdf output.pptx
|
||||
python "<skill-dir>/scripts/thumbnail.py" presentation.pptx
|
||||
python "<skill-dir>/scripts/with-deps.py" --current-python thumbnail.py presentation.pptx
|
||||
```
|
||||
|
||||
**NEVER** run `python scripts/office/unpack.py` directly — that relative path does not exist in the user's working directory.
|
||||
Targets are relative to `scripts/` (absolute paths are also accepted), and arguments/workdir/exit codes are preserved. `--current-python` keeps the interpreter where Pillow is installed for thumbnails while adding the shared pure-Python XML dependency. The launcher does not install Pillow, markitdown, LibreOffice, or any package.
|
||||
|
||||
**NEVER** invoke Office XML scripts directly: a bare `scripts/` path is not relative to the user's workdir, and direct invocation bypasses the prepared dependencies. If no prepared interpreter can start, the current Python must be 3.10+; missing libraries or failed validation remain nonzero failures. Restore the client's prepared runtime rather than treating skipped validation as success. Child scripts do not write bytecode into the installed skill.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
@@ -130,6 +133,8 @@ load the `nodejs-runtime` skill for Node.js (pptxgenjs) issues; load the `dev-en
|
||||
|
||||
### Python Package Dependencies
|
||||
|
||||
Office XML scripts use `defusedxml` and `lxml` from the client's prepared runtime through `with-deps.py`; do not run `pip install` for these dependencies. Full PPTX validation requires the lxml profile. If it is unavailable, report the failure; do not claim complete validation or silently skip it.
|
||||
|
||||
This skill's Python operations depend on the following packages (checked on demand):
|
||||
|
||||
- `markitdown[pptx]` — PPTX content reading
|
||||
@@ -163,10 +168,10 @@ When you create or modify a .pptx file, you **MUST** tell the user the absolute
|
||||
python -m markitdown presentation.pptx
|
||||
|
||||
# Visual overview
|
||||
python scripts/thumbnail.py presentation.pptx
|
||||
python "<skill-dir>/scripts/with-deps.py" --current-python thumbnail.py presentation.pptx
|
||||
|
||||
# Raw XML
|
||||
python scripts/office/unpack.py presentation.pptx unpacked/
|
||||
python "<skill-dir>/scripts/with-deps.py" office/unpack.py presentation.pptx unpacked/
|
||||
```
|
||||
|
||||
---
|
||||
@@ -349,7 +354,7 @@ Report ALL issues found, including minor ones.
|
||||
Convert presentations to individual slide images for visual inspection:
|
||||
|
||||
```bash
|
||||
python scripts/office/soffice.py --headless --convert-to pdf output.pptx
|
||||
python "<skill-dir>/scripts/office/soffice.py" --headless --convert-to pdf output.pptx
|
||||
pdftoppm -jpeg -r 150 output.pdf slide
|
||||
```
|
||||
|
||||
@@ -365,6 +370,7 @@ pdftoppm -jpeg -r 150 -f N -l N output.pdf slide-fixed
|
||||
|
||||
## Dependencies
|
||||
|
||||
- `defusedxml` + `lxml` — Office XML editing and full PPTX validation; supplied by the client's prepared runtime and consumed through `scripts/with-deps.py`, independently of the docx skill.
|
||||
- `pip install "markitdown[pptx]"` - text extraction
|
||||
- `pip install Pillow` - thumbnail grids
|
||||
- `npm install -g pptxgenjs` - creating from scratch
|
||||
|
||||
@@ -46,6 +46,8 @@ Node.js(pptxgenjs)相关问题加载 `nodejs-runtime` 技能;其他(系
|
||||
|
||||
### Python 包依赖
|
||||
|
||||
Office XML 脚本通过 `with-deps.py` 读取客户端运行时预装的 `defusedxml` 与 `lxml`,不要为这两项执行 `pip install`。PPTX 完整校验需要 lxml profile;不可用时如实报告失败,不得跳过后宣称完整校验通过。
|
||||
|
||||
本技能的 Python 操作依赖以下包(按需检测):
|
||||
|
||||
- `markitdown[pptx]` — PPTX 内容读取
|
||||
@@ -62,16 +64,19 @@ python3 -c "import markitdown; import PIL" 2>/dev/null || echo "MISSING"
|
||||
|
||||
本技能自带的 Python 脚本位于技能安装目录内。执行时**必须使用完整路径**,不能使用相对路径。
|
||||
|
||||
技能目录由上下文中的 `<skill-dir>` 标签提供。所有 `scripts/` 开头的命令都应拼接为:
|
||||
技能目录由上下文中的 `<skill-dir>` 标签提供。Office XML 脚本统一经过跨平台 `with-deps.py` 启动器:它注入客户端已准备的 `runtime-deps/python-libs`,优先选择 `runtime-deps/python-runtime` 解释器,不需要在线安装 XML 依赖:
|
||||
|
||||
```bash
|
||||
python "<skill-dir>/scripts/office/unpack.py" presentation.pptx unpacked/
|
||||
python "<skill-dir>/scripts/office/pack.py" unpacked/ output.pptx
|
||||
python "<skill-dir>/scripts/with-deps.py" office/unpack.py presentation.pptx unpacked/
|
||||
python "<skill-dir>/scripts/with-deps.py" office/pack.py unpacked/ output.pptx
|
||||
python "<skill-dir>/scripts/with-deps.py" office/validate.py output.pptx
|
||||
python "<skill-dir>/scripts/office/soffice.py" --headless --convert-to pdf output.pptx
|
||||
python "<skill-dir>/scripts/thumbnail.py" presentation.pptx
|
||||
python "<skill-dir>/scripts/with-deps.py" --current-python thumbnail.py presentation.pptx
|
||||
```
|
||||
|
||||
**禁止**直接执行 `python scripts/office/unpack.py`——该相对路径在用户工作目录下不存在。
|
||||
目标路径相对 `scripts/` 解析,也接受绝对路径;参数、工作目录与退出码保持不变。缩略图使用 `--current-python`,保留已安装 Pillow 的解释器,同时注入共享的纯 Python XML 依赖。启动器不会安装 Pillow、markitdown、LibreOffice 或任何包。
|
||||
|
||||
**禁止**直接执行 Office XML 脚本:裸 `scripts/` 路径不相对用户工作目录,直接调用还会绕过预装依赖。受控解释器无法启动时,当前 Python 必须为 3.10+;缺库或校验失败仍返回非零。应修复客户端运行时,不能把跳过校验当成功。子脚本不在已安装技能中生成字节码缓存。
|
||||
|
||||
## Output Rule
|
||||
|
||||
@@ -94,10 +99,10 @@ When you create or modify a .pptx file, you **MUST** tell the user the absolute
|
||||
python -m markitdown presentation.pptx
|
||||
|
||||
# Visual overview
|
||||
python scripts/thumbnail.py presentation.pptx
|
||||
python "<skill-dir>/scripts/with-deps.py" --current-python thumbnail.py presentation.pptx
|
||||
|
||||
# Raw XML
|
||||
python scripts/office/unpack.py presentation.pptx unpacked/
|
||||
python "<skill-dir>/scripts/with-deps.py" office/unpack.py presentation.pptx unpacked/
|
||||
```
|
||||
|
||||
---
|
||||
@@ -280,7 +285,7 @@ Report ALL issues found, including minor ones.
|
||||
Convert presentations to individual slide images for visual inspection:
|
||||
|
||||
```bash
|
||||
python scripts/office/soffice.py --headless --convert-to pdf output.pptx
|
||||
python "<skill-dir>/scripts/office/soffice.py" --headless --convert-to pdf output.pptx
|
||||
pdftoppm -jpeg -r 150 output.pdf slide
|
||||
```
|
||||
|
||||
@@ -296,6 +301,7 @@ pdftoppm -jpeg -r 150 -f N -l N output.pdf slide-fixed
|
||||
|
||||
## Dependencies
|
||||
|
||||
- `defusedxml` + `lxml` — Office XML 编辑与 PPTX 完整校验;由客户端运行时预装,通过 `scripts/with-deps.py` 使用,不依赖 docx 技能目录。
|
||||
- `pip install "markitdown[pptx]"` - text extraction
|
||||
- `pip install Pillow` - thumbnail grids
|
||||
- `npm install -g pptxgenjs` - creating from scratch
|
||||
|
||||
@@ -30,13 +30,13 @@
|
||||
},
|
||||
"release": {
|
||||
"state": "known",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"versionScheme": "semver"
|
||||
},
|
||||
"timestamps": {
|
||||
"catalogUpdatedAt": {
|
||||
"state": "known",
|
||||
"value": "2026-10-14",
|
||||
"value": "2026-10-28",
|
||||
"precision": "day"
|
||||
},
|
||||
"releasePublishedAt": {
|
||||
|
||||
@@ -6,7 +6,7 @@ When using an existing presentation as a template:
|
||||
|
||||
1. **Analyze existing slides**:
|
||||
```bash
|
||||
python scripts/thumbnail.py template.pptx
|
||||
python "<skill-dir>/scripts/with-deps.py" --current-python thumbnail.py template.pptx
|
||||
python -m markitdown template.pptx
|
||||
```
|
||||
Review `thumbnails.jpg` to see layouts, and markitdown output to see placeholder text.
|
||||
@@ -26,7 +26,7 @@ When using an existing presentation as a template:
|
||||
|
||||
Match content type to layout style (e.g., key points → bullet slide, team info → multi-column, testimonials → quote slide).
|
||||
|
||||
3. **Unpack**: `python scripts/office/unpack.py template.pptx unpacked/`
|
||||
3. **Unpack**: `python "<skill-dir>/scripts/with-deps.py" office/unpack.py template.pptx unpacked/`
|
||||
|
||||
4. **Build presentation** (do this yourself, not via delegation):
|
||||
- Delete unwanted slides (remove from `<p:sldIdLst>`)
|
||||
@@ -39,7 +39,7 @@ When using an existing presentation as a template:
|
||||
|
||||
6. **Clean**: `python scripts/clean.py unpacked/`
|
||||
|
||||
7. **Pack**: `python scripts/office/pack.py unpacked/ output.pptx --original template.pptx`
|
||||
7. **Pack**: `python "<skill-dir>/scripts/with-deps.py" office/pack.py unpacked/ output.pptx --original template.pptx`
|
||||
|
||||
---
|
||||
|
||||
@@ -56,7 +56,7 @@ When using an existing presentation as a template:
|
||||
### unpack.py
|
||||
|
||||
```bash
|
||||
python scripts/office/unpack.py input.pptx unpacked/
|
||||
python "<skill-dir>/scripts/with-deps.py" office/unpack.py input.pptx unpacked/
|
||||
```
|
||||
|
||||
Extracts PPTX, pretty-prints XML, escapes smart quotes.
|
||||
@@ -81,7 +81,7 @@ Removes slides not in `<p:sldIdLst>`, unreferenced media, orphaned rels.
|
||||
### pack.py
|
||||
|
||||
```bash
|
||||
python scripts/office/pack.py unpacked/ output.pptx --original input.pptx
|
||||
python "<skill-dir>/scripts/with-deps.py" office/pack.py unpacked/ output.pptx --original input.pptx
|
||||
```
|
||||
|
||||
Validates, repairs, condenses XML, re-encodes smart quotes.
|
||||
@@ -89,7 +89,7 @@ Validates, repairs, condenses XML, re-encodes smart quotes.
|
||||
### thumbnail.py
|
||||
|
||||
```bash
|
||||
python scripts/thumbnail.py input.pptx [output_prefix] [--cols N]
|
||||
python "<skill-dir>/scripts/with-deps.py" --current-python thumbnail.py input.pptx [output_prefix] [--cols N]
|
||||
```
|
||||
|
||||
Creates `thumbnails.jpg` with slide filenames as labels. Default 3 columns, max 12 per grid.
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run Office XML scripts with the client's prepared Python dependencies.
|
||||
|
||||
Each installed skill carries this launcher so it works without another Office
|
||||
skill. The bootstrap uses only the standard library, including on Python 3.9;
|
||||
the target requires Python 3.10+ and prefers the runtime's prepared interpreter.
|
||||
No packages are installed and target failures are never reported as success.
|
||||
|
||||
python "<skill-dir>/scripts/with-deps.py" office/unpack.py input.pptx unpacked/
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
_HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
# scripts -> skill -> skills -> the effective DesireCore data root
|
||||
_ROOT = os.path.abspath(os.path.join(_HERE, "..", "..", ".."))
|
||||
_PYLIBS = os.path.join(_ROOT, "runtime-deps", "python-libs")
|
||||
_BUNDLED = os.path.join(
|
||||
_ROOT,
|
||||
"runtime-deps",
|
||||
"python-runtime",
|
||||
"python.exe" if os.name == "nt" else os.path.join("bin", "python3"),
|
||||
)
|
||||
|
||||
|
||||
def _current_python_supported():
|
||||
if sys.version_info[:2] >= (3, 10):
|
||||
return True
|
||||
sys.stderr.write(
|
||||
"with-deps.py: Office XML scripts require Python 3.10+. "
|
||||
"Prepare the managed Python runtime in DesireCore and retry.\n"
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
arguments = list(sys.argv[1:])
|
||||
current_python = bool(arguments and arguments[0] == "--current-python")
|
||||
if current_python:
|
||||
arguments.pop(0)
|
||||
if not arguments:
|
||||
sys.stderr.write("usage: with-deps.py [--current-python] <script.py> [args...]\n")
|
||||
return 2
|
||||
|
||||
argument = arguments[0]
|
||||
target = argument if os.path.isabs(argument) else os.path.join(_HERE, argument)
|
||||
if not os.path.isfile(target):
|
||||
sys.stderr.write("with-deps.py: target not found: " + target + "\n")
|
||||
return 2
|
||||
|
||||
interpreter = sys.executable
|
||||
if not current_python and os.path.isfile(_BUNDLED):
|
||||
if os.path.realpath(_BUNDLED) != os.path.realpath(sys.executable):
|
||||
interpreter = _BUNDLED
|
||||
if interpreter == sys.executable and not _current_python_supported():
|
||||
return 1
|
||||
|
||||
environment = dict(os.environ)
|
||||
if os.path.isdir(_PYLIBS):
|
||||
existing = environment.get("PYTHONPATH")
|
||||
environment["PYTHONPATH"] = _PYLIBS + (os.pathsep + existing if existing else "")
|
||||
# Running a skill must not change its installed content digest through .pyc.
|
||||
environment["PYTHONDONTWRITEBYTECODE"] = "1"
|
||||
arguments = ["-B", target, *arguments[1:]]
|
||||
try:
|
||||
return subprocess.run([interpreter, *arguments], env=environment).returncode
|
||||
except OSError as error:
|
||||
if interpreter == sys.executable:
|
||||
sys.stderr.write("with-deps.py: could not start Python: " + str(error) + "\n")
|
||||
return 126
|
||||
# Fall back only when the process could not start. A target's nonzero
|
||||
# exit or signal must never replay an edit that may have already run.
|
||||
sys.stderr.write("with-deps.py: managed Python could not start; trying current Python.\n")
|
||||
if not _current_python_supported():
|
||||
return 1
|
||||
try:
|
||||
return subprocess.run([sys.executable, *arguments], env=environment).returncode
|
||||
except OSError as fallback_error:
|
||||
sys.stderr.write("with-deps.py: could not start Python: " + str(fallback_error) + "\n")
|
||||
return 126
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user