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 |
lib/cache.py
View on GitHub"""Hash-based output dir resolution.
The contract is simple: given an input file, produce a deterministic
output directory so that repeat ``preview render`` calls on an unchanged
file return the same path. The model can rely on the path being stable
across calls.
We hash the *full file content* (not mtime), so any byte change
invalidates the cache. For typical artifact sizes (≤ 50 MB) the SHA-256
cost is dwarfed by the rendering cost itself; using mtime would be
faster but unsafe under git checkouts and tar extraction.
"""
from __future__ import annotations
import hashlib
import os
from pathlib import Path
from . import _common
# Files larger than this are hashed in 64KB-prefix mode + size sentinel,
# trading off determinism for speed. 100 MB is well above the typical
# artifact budget; anything bigger is almost certainly not a deliverable.
_FULL_HASH_MAX_BYTES = 100 * 1024 * 1024
def _hash_file_full(path: Path) -> str:
h = hashlib.sha256()
with open(path, "rb") as fh:
while True:
chunk = fh.read(1 << 20)
if not chunk:
break
h.update(chunk)
return h.hexdigest()
def _hash_file_prefix(path: Path, size: int) -> str:
"""Fallback for huge files: 64KB prefix + 64KB suffix + size."""
h = hashlib.sha256()
with open(path, "rb") as fh:
h.update(fh.read(65536))
if size > 131072:
fh.seek(max(0, size - 65536))
h.update(fh.read(65536))
h.update(str(size).encode())
return h.hexdigest()
def compute_source_hash(path: str | Path) -> str:
"""Return a 12-hex-char content hash for ``path``.
Raises FileNotFoundError if the path does not exist.
"""
p = Path(path)
if not p.is_file():
raise FileNotFoundError(f"not a file: {p}")
size = p.stat().st_size
if size <= _FULL_HASH_MAX_BYTES:
digest = _hash_file_full(p)
else:
digest = _hash_file_prefix(p, size)
return digest[:12]
def default_output_root() -> Path:
"""Resolve the default ``.preview/`` directory.
Lookup order:
1. ``ARTIFACT_PREVIEW_HOME`` environment variable
2. CWD ``./.preview/`` if CWD is writable
3. ``$HOME/.preview/`` as a last resort
"""
env = os.environ.get("ARTIFACT_PREVIEW_HOME")
if env:
return Path(_common.logical_abspath(env))
# logical_cwd(), not Path.cwd(): the latter collapses the workspace symlink
# and the sandbox bind mount, so every path we report back would carry a
# prefix the caller never used.
cwd = Path(_common.logical_cwd())
if os.access(cwd, os.W_OK):
return cwd / ".preview"
return Path(_common.logical_abspath(Path.home() / ".preview"))
def resolve_output_dir(
source_path: str | Path,
output_root: str | Path | None = None,
*,
source_hash: str | None = None,
) -> tuple[Path, str]:
"""Compute (output_dir, source_hash) for a given input file.
``output_root`` defaults to :func:`default_output_root` when None.
The output dir is ``<root>/<hash>/`` and is NOT created here —
:func:`dispatch.render` does that.
"""
src = Path(source_path)
sh = source_hash or compute_source_hash(src)
root = (Path(_common.logical_abspath(output_root)) if output_root
else default_output_root())
out_dir = root / sh
return out_dir, sh
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 |