yzsp-studio/mediakit-shared-suite / artifact-preview
artifact-preview
VerifiedRender workspace artifacts (pdf/pptx/docx/xlsx/html/png/jpg/txt/zip) into text + page screenshots + thumbnail + multi-page collages, saved under ./.preview/{hash}/. Use Read on the resulting jpg/png files to visually inspect your own deliverables before delivering them; it catches what a structural checker cannot — text truncation, colour clashes, clipped chart titles, layout drift, blank slides, CJK rendered as boxes. Triggered by: "看看产物长什么样", "视觉自检", "preview pptx", "render artifact", "screenshot pdf", "渲染产物", "我的报告画出来好看吗", "图表是否完整".
| File | Kind | Size |
|---|---|---|
| README.md | markdown | 7.6 KB |
| SKILL.md | skill md | 10.1 KB |
| bin/preview | other | 2.0 KB |
| bin/preview.cmd | script | 482 B |
| lib/__init__.py | script | 1.7 KB |
| lib/_common.py | script | 13.1 KB |
| lib/_types.py | script | 3.5 KB |
| lib/cache.py | script | 3.3 KB |
| lib/cli.py | script | 10.2 KB |
| lib/collage.py | script | 4.6 KB |
| lib/dispatch.py | script | 8.3 KB |
| lib/docx.py | script | 1.1 KB |
| lib/html.py | script | 2.1 KB |
| lib/image.py | script | 1.4 KB |
| lib/manifest.py | script | 2.7 KB |
| lib/pdf.py | script | 2.2 KB |
| lib/pptx.py | script | 2.5 KB |
| lib/render/__init__.py | script | 2.4 KB |
| lib/render/collage.py | script | 10.9 KB |
| lib/render/constants.py | script | 1.4 KB |
| lib/render/docx.py | script | 2.2 KB |
| lib/render/html.py | script | 12.4 KB |
| lib/render/pdf.py | script | 3.4 KB |
| lib/render/pptx.py | script | 5.6 KB |
| lib/render/types.py | script | 1.3 KB |
| lib/render/xlsx.py | script | 2.9 KB |
| lib/text.py | script | 1.4 KB |
| lib/xlsx.py | script | 1.1 KB |
| lib/zip_.py | script | 1.4 KB |
| requirements.txt | manifest | 4.2 KB |
README.md
View on GitHub# artifact-preview hub
Render workspace deliverables (pdf / pptx / docx / xlsx / html / images / zip)
into text dumps + page screenshots + collages so a multimodal LLM can
visually inspect its own output via `Read`.
Packaged as a **superskill** hub: the model discovers it via the
standard catalog and invokes it through `Bash` + `Read`. See
`SKILL.md` for the model-facing usage doc.
## Hub layout (verifier-hub-style)
```
artifact-preview/
├── SKILL.md model-facing skill description (frontmatter + body)
├── README.md human-facing notes (you are here)
├── requirements.txt third-party deps (informational; VM image owns install)
├── bin/preview python3 entrypoint (sets sys.path → lib/, dispatches CLI)
├── lib/
│ ├── _common.py ok/err/emit/lazy_import, logical paths, file:// URIs,
│ │ cross-platform binary lookup, install hints
│ ├── _types.py dataclasses + kind constants
│ ├── cache.py content-hash output dir resolution
│ ├── manifest.py manifest.json read/write
│ ├── dispatch.py kind detection + render() entry
│ ├── cli.py argparse subcommand layer
│ ├── pdf.py IO wrapper → render.pdf
│ ├── pptx.py IO wrapper → render.pptx
│ ├── docx.py IO wrapper → render.docx
│ ├── xlsx.py IO wrapper → render.xlsx
│ ├── html.py IO wrapper → render.html
│ ├── image.py plain image passthrough + thumbnail
│ ├── text.py plain text copy
│ ├── zip_.py entry list dump
│ ├── collage.py IO wrapper → render.collage + thumbnail
│ └── render/ ▼ shared rendering primitives ▼
│ ├── __init__.py exports + lazy-import contract
│ ├── constants.py DPI / page caps / collage tile params
│ ├── types.py PageImage / CollageResult dataclasses
│ ├── pdf.py PyMuPDF text + per-page PNG
│ ├── pptx.py python-pptx text + LibreOffice→PDF screenshots
│ ├── docx.py python-docx paragraphs + tables
│ ├── xlsx.py openpyxl full-workbook dump
│ ├── html.py Playwright full-page + segmented screenshots
│ └── collage.py multi-page tiling
└── tests/ pytest fixtures (synthetic, no binary blobs)
```
## Why two layers?
* **`lib/render/`** — pure primitives (bytes in, bytes/PIL out).
Single source of truth shared with the host-side
`swalm.core.utils.artifact_render` module (which re-exports from
here so `trace_llm_judge.py` keeps working without a code copy).
* **`lib/<kind>.py`** — IO wrappers: read source bytes from disk,
call the matching `render.<kind>` primitive, write artifacts
(PNG/JPG/text.md) into the deterministic `.preview/<hash>/` cache,
populate the JSON manifest.
This is the same layering verifier-hub uses (`bin/verifier` →
`lib/_common.py` → `lib/<family>.py`).
## Local development
Run the CLI directly without installation:
```bash
./bin/preview render path/to/file.pptx --max-pages 5
```
Run the test suite:
```bash
pytest tests/ -v
```
The test suite generates fixture files programmatically (PIL.Image,
openpyxl.Workbook, python-pptx.Presentation, etc.) so the repo carries
no binary blobs.
## Dependencies
`requirements.txt` lists the optional Python deps. The `superskill`
delivery model assumes the VM image already has them installed (same
contract as verifier-hub); if any are missing the skill degrades
gracefully:
* PyMuPDF (`fitz`) → PDF text + screenshots disabled
* python-pptx → PPTX text disabled
* python-docx → DOCX text disabled
* openpyxl → XLSX text disabled
* Pillow → collage + thumbnail disabled
* (no playwright dependency — HTML rendering uses the system
`chromium-browser` CLI directly; see `System-level deps` below.)
In every case, missing deps surface as a JSON `warnings` entry rather
than an exception, so callers (NotifyHuman flows, judges) don't fail
on capability gaps.
System-level deps:
* LibreOffice — required for PPTX → PDF → PNG conversion.
* A Chromium-family browser — required for HTML page screenshots.
On the rollout VM image the system `chromium-browser` package provides
this, so no Playwright install step is needed.
Both are looked up on `$PATH` and, because the macOS and Windows installers
do not add themselves to `PATH`, at the standard install locations for the
platform. `--soffice` / `--chromium` and the `ARTIFACT_PREVIEW_SOFFICE` /
`ARTIFACT_PREVIEW_CHROMIUM` environment variables override both.
## Programmatic API
```python
import sys
sys.path.insert(0, "/path/to/skills/artifact-preview")
from lib import dispatch_render as render, RenderOptions
m = render("./report.pptx", options=RenderOptions(max_pages=5, collage=True))
print(m.thumbnail_relpath, m.collages, m.text_relpath)
```
## Relationship to host-side `swalm.core.utils.artifact_render`
The host-side module at
`packages/swalm-core/src/swalm/core/utils/artifact_render/` is a
**thin re-export** from this hub:
```python
# swalm.core.utils.artifact_render/__init__.py
from superskill.hub_skills.artifact_preview.lib.render import * # noqa
```
This keeps the canonical implementation here in the hub (single
source of truth) while letting `trace_llm_judge.py` and other
host-side judge code keep their existing `from
swalm.core.utils.artifact_render import extract_pdf` imports.
## Invariants worth keeping
* **One JSON object on stdout per invocation**, including argument errors
(`BAD_ARGS`). Only `--help` prints prose. Errors never go to stderr and never
leak a traceback.
* **`ok` means the tool ran**; a missing optional dependency is `ok: true` plus
a `warnings` entry, not an error.
* **Collages cover every rendered page.** `render/collage.py` balances pages
across tiles rather than filling greedily, because a greedy split can leave a
one-page remainder that used to be dropped silently. `lib/collage.py` also
emits a warning if any page still ends up uncovered.
* **`--text-only` never deletes images** an earlier full render produced; it
carries them forward and says so in `warnings`.
* **`file://` URLs are built with `Path.as_uri()`**, never by string
concatenation. Concatenation breaks on Windows (the drive letter is parsed as
the URL host) and leaves spaces and non-ASCII characters unescaped everywhere.
* **A screenshot existing is not proof the right page was captured.** The HTML
renderer stages the document with a sentinel and confirms it via `--dump-dom`,
because a browser that fails to load a file still writes a perfectly valid
screenshot of its own start page.
* **Reported paths keep the caller's prefix.** `_common.logical_abspath` avoids
`resolve()` so the workspace symlink and the sandbox bind mount are not
collapsed into a path the agent never typed.
## Platform support
Linux and macOS. Windows is not supported: `bin/preview` is an extension-less
shebang script, so `cmd.exe` and PowerShell cannot execute it directly. The
Python code itself is portable, so `python bin/preview ...` does work.
## Packaging
The zip published to TOS contains `bin/`, `lib/`, `SKILL.md`,
`requirements.txt` and `README.md` at the top level — no wrapper directory,
because the installer creates the per-skill directory from the zip name.
`__pycache__` and the test suite are excluded: the VM runs Python 3.10 and
would ignore bytecode compiled elsewhere anyway.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pptxanthropics/skillsUse this skill any time a .pptx or .potx 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 or .potx 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 (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |