Skip to content

yzsp-studio/mediakit-shared-suite / artifact-preview

artifact-preview

Verified

Render 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", "渲染产物", "我的报告画出来好看吗", "图表是否完整".

FileKindSize
README.mdmarkdown7.6 KB
SKILL.mdskill md10.1 KB
bin/previewother2.0 KB
bin/preview.cmdscript482 B
lib/__init__.pyscript1.7 KB
lib/_common.pyscript13.1 KB
lib/_types.pyscript3.5 KB
lib/cache.pyscript3.3 KB
lib/cli.pyscript10.2 KB
lib/collage.pyscript4.6 KB
lib/dispatch.pyscript8.3 KB
lib/docx.pyscript1.1 KB
lib/html.pyscript2.1 KB
lib/image.pyscript1.4 KB
lib/manifest.pyscript2.7 KB
lib/pdf.pyscript2.2 KB
lib/pptx.pyscript2.5 KB
lib/render/__init__.pyscript2.4 KB
lib/render/collage.pyscript10.9 KB
lib/render/constants.pyscript1.4 KB
lib/render/docx.pyscript2.2 KB
lib/render/html.pyscript12.4 KB
lib/render/pdf.pyscript3.4 KB
lib/render/pptx.pyscript5.6 KB
lib/render/types.pyscript1.3 KB
lib/render/xlsx.pyscript2.9 KB
lib/text.pyscript1.4 KB
lib/xlsx.pyscript1.1 KB
lib/zip_.pyscript1.4 KB
requirements.txtmanifest4.2 KB

lib/render/xlsx.py

View on GitHub
"""XLSX full-workbook text dump via openpyxl.

Pipe-delimited rows, all sheets, all cells. The global text budget in
the calling skill remains the only safety net — see
``trace_llm_judge._extract_xlsx_content`` for the original design notes.
"""

from __future__ import annotations

import io
import logging
from typing import Any

logger = logging.getLogger(__name__)

_CELL_MAX_CHARS = 500


def _fmt_cell(value: Any) -> str:
    """Render an openpyxl cell value as compact, single-line text.

    Long cells are clipped to ``_CELL_MAX_CHARS``; embedded newlines and
    pipes are escaped so each row stays on one line in the
    pipe-delimited dump.
    """
    if value is None:
        return ""
    s = str(value)
    if len(s) > _CELL_MAX_CHARS:
        s = s[:_CELL_MAX_CHARS] + "…"
    return s.replace("\n", " ").replace("\r", " ").replace("|", "\\|")


def extract_xlsx_text(xlsx_bytes: bytes) -> tuple[str, list[dict]]:
    """Dump every sheet as ``--- Sheet: <name> --- \\n R<i>: c1 | c2 …``.

    Returns
    -------
    (text, sheets)
        ``sheets`` is a list of ``{"name", "rows", "cols"}`` per sheet.

    Falls back to ``("", [])`` when openpyxl is missing or the workbook
    can't be opened (legacy ``.xls`` binary format, password-protected,
    truncated bytes, etc.).
    """
    try:
        import openpyxl
    except ImportError:
        logger.warning("openpyxl not installed — xlsx extract skipped")
        return "", []

    try:
        wb = openpyxl.load_workbook(
            io.BytesIO(xlsx_bytes),
            read_only=True,
            data_only=True,
        )
    except Exception as exc:
        logger.warning("[xlsx] open failed: %s", exc)
        return "", []

    text_parts: list[str] = []
    sheets: list[dict] = []
    for sheet_name in wb.sheetnames:
        try:
            ws = wb[sheet_name]
        except Exception as exc:
            logger.debug("[xlsx] skip sheet %r: %s", sheet_name, exc)
            continue
        max_row = ws.max_row or 0
        max_col = ws.max_column or 0
        sheets.append({"name": sheet_name, "rows": max_row, "cols": max_col})
        if max_row == 0 or max_col == 0:
            text_parts.append(f"--- Sheet: {sheet_name} (empty) ---")
            continue
        lines: list[str] = []
        for r_idx, row in enumerate(
            ws.iter_rows(
                min_row=1, max_row=max_row, min_col=1, max_col=max_col,
                values_only=True,
            ),
            start=1,
        ):
            cells = [_fmt_cell(v) for v in row]
            while cells and cells[-1] == "":
                cells.pop()
            lines.append(f"R{r_idx}: " + " | ".join(cells))
        header = f"--- Sheet: {sheet_name} (rows={max_row}, cols={max_col}) ---"
        text_parts.append(header + "\n" + "\n".join(lines))

    try:
        wb.close()
    except Exception:
        pass
    return "\n\n".join(text_parts), sheets
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall