Documents

From ahang1598/doubao-workbuddy-qwenwork-skills · View interactive version

Documents is an AI agent skill from the GitHub repository ahang1598/doubao-workbuddy-qwenwork-skills. Create, edit, redline, and comment on `.docx`, Word, and Google Docs-targeted document artifacts inside the container, with a strict render-and-verify workflow. Use `render_docx.py` to generate page PNGs (and optional PDF) for visual QA, then iterate until layout is flawless before delivering the fi

How to use this skill

Skill file

DOCX Skill (Read • Create • Edit • Redline • Comment)

Titles + Intro to doc

Title clarity is an absolute requirement. State the specific subject and purpose so the reader understands what the document is for before reading the body. Use plain descriptive language with no slogans and no punctuation. Apply this to document titles, subtitles, and section titles, using only words, numbers, and spaces. Use Word’s Title paragraph style for document titles. Keep it black with no underlining, paragraph borders, or decorative lines beneath it. Remove any direct formatting or separately added lines that conflict.

The opening content is essential to the reader's understanding of the whole document. Establish what the document covers, why it matters to this reader, and the main conclusion, decision, or task. Give enough context and scope to make the sections that follow easy to understand and show what the reader should learn or do.

Writing quality

Before formatting, read the title and section headings as an outline. Write connected paragraphs that explain relationships, and replace compressed labels or unnecessary compounds with natural wording. Preserve the source's meaning, including uncertainty, conditions, time periods, and comparisons. Use punctuation and passive voice in body text when they improve precision.

For the review steps, examples, and more context, read writing_quality.md.

Use this skill when you need to create or modify .docx, Word, or Google Docs-targeted document artifacts in this container environment and verify them visually.

Tools + Contract Requirements

Immediately before the first create/edit authoring command, run mark_artifact_operation_started.mjs successfully exactly once using the command below. Do not run it for read-only work. For edits, replace create with edit; adjust the expected count and output format to match the requested outputs.

node container_tools/mark_artifact_operation_started.mjs --operation-kind create --expected-output-count 1 --output-format docx

Artifact Template Selection

When creating new documents without a template, reference, or visual direction, or when the user asks to browse or upload templates, read template selection before choosing a design or starting creation.

Google Docs-targeted output

For a net-new Google Docs request, create and visually verify a local .docx with this skill first. The native Google Docs deliverable must then be produced by the Google Drive plugin's document import action, mcp__codex_apps__google_drive_import_document, with upload_mode: "native_google_docs".

Before rendering or importing any Google Docs-targeted DOCX, run the deterministic title sanitizer:

python scripts/google_docs_title_sanitize.py input.docx --out sanitized.docx
python scripts/google_docs_title_sanitize.py sanitized.docx --check

Use the sanitized DOCX for render QA and native Google Docs import. This is not a style preference or prose reminder: the sanitizer removes Word Title paragraph-style border residue, direct title-paragraph borders, and leading title-block paragraph borders from the OOXML so Word's built-in blue title rule cannot survive into the imported Google Doc.

Do not use Computer Use, Browser Use, blank-Google-Doc creation plus Google Docs write APIs, or another direct-to-Docs construction path for net-new Google Docs unless the user explicitly asks for that alternate workflow. If they do, mention first that output quality is expected to be best when a local .docx is imported through the Google Drive plugin.

If the Google Drive plugin is unavailable, use the plugin-install/user-elicitation flow to ask the user to install google-drive@openai-curated. If the plugin is available but _import_document is missing, ask the user to reinstall or refresh the Google Drive plugin before continuing with the native Google Docs deliverable.

Template Following

When an attached or retained DOCX is meant to control a new document, read

template-distill.md and then template-create.md. Keep the reference file and

the task-local $TMP_DIR/artifact.md together throughout authoring. In this

mode, the retained reference is the design authority: do not apply a generic

design preset, page baseline, or header pattern unless the user explicitly asks

to depart from the template. The render gate and Google Docs import contract

still apply. For a Google Docs-targeted result, record any change made by the

required title sanitizer as an intentional fidelity deviation.

Non-negotiable: render → inspect PNGs → iterate

You do not “know” a DOCX is satisfactory until you’ve rendered it and visually inspected page images.

DOCX text extraction (or reading XML) will miss layout defects: clipping, overlap, missing glyphs, broken tables, spacing drift, and header/footer issues.

Shipping gate: before delivering any DOCX, you must:

If rendering fails, diagnose the packaged renderer using its logs before retrying.

Deliverable discipline: Rendered artifacts (PNGs and optional PDFs) are for internal QA only. Unless the user explicitly asks for intermediates, return only the requested final deliverable (e.g., when the task asks for a DOCX, deliver the DOCX — not page images or PDFs).

Design standards for document generation

For generating new documents or major rewrite/repackages, follow the design standards below unless the user explicitly requests otherwise. The user's instructions always take precedence; otherwise, adhere to these standards.

When creating the document design, do not compromise on the content and make factual/technical errors. Do not produce something that looks polished but not actually what the user requested.

It is very important that the document is professional and aesthetically pleasing. As such, you should follow this general workflow to make your final delivered document:

  1. Before you make the DOCX, please first think about the high-level design of the DOCX:
  1. Once you have a working DOCX, continue iterating until the entire document is polished and correct. After every change or edit, render the DOCX and review it carefully to evaluate the result. The plan from (1) should guide you, but it is only a flexible draft; you should update your decisions as needed throughout the revision process. Important: each time you render and reflect, you should check for both:

1. Design aesthetics: the document should be aesthetically pleasing and easy to skim. Ask yourself: if a human were to look at my document, would they find it aesthetically nice? It should feel natural, smooth, and visually cohesive.

2. Formatting issues that need to be fixed: e.g. text overlap, overflow, cramped spacing between adjacent elements, awkward spacing in tables/charts, awkward page breaks, etc. This is super important. Do not stop revising until all formatting issues are fixed.

While making and revising the DOCX, please adhere to and check against these quality reminders, to ensure the deliverable is visually high quality:

Note on page sizing

When creating a new DOCX, always default to the Letter size 8.5 x 11 inches, in Portrait orientation, unless the user specifies otherwise.

Note on font sizing

Use a readable size appropriate to the text's role and typeface; ~11-12 pt is a good default for sustained prose. Use text 10 pt and below only if ideal for secondary roles or constrained tables/forms, and only when it remains comfortable at normal print or fit-width viewing. Do not shrink type merely to meet a page-count or compactness target. Follow explicit user typography instructions, but never at the expense of practical readability.

Editing tasks (DOCX edits) — apply instead of major rewrite behavior

When the user asks to edit an existing document, preserve the original and make minimal, local changes:

Equations: native Word math vs rendered fallback

When the requested document or source contains mathematical equations, choose the equation

representation deliberately. Never leave raw LaTeX in the document or approximate structured

notation with plain text.

  1. Prefer native Word equations (OMML, such as <m:oMath> or <m:oMathPara>) when the user

asks for native or editable equations, when an existing DOCX already uses native equations, or

when equations need to remain searchable, accessible, copyable, inline with prose, or easy to

revise. Use native equations only through a tested OMML authoring path, and verify that Word and

the final LibreOffice render preserve the notation correctly.

  1. Use the rendered MathJax fallback below when native/editable math is not required and either

no reliable OMML authoring path is available or a complex display equation needs predictable

visual fidelity across renderers. This path produces an image, not a native Word equation. It is

best for stable display equations where portability matters more than editability.

Do not silently rasterize an equation when the user explicitly requires native or editable Word

math. If no tested OMML path is available, explain that limitation rather than mislabeling an image

as native. When editing an existing DOCX, preserve its equation representation unless the request or

render QA gives a clear reason to change it.

Rendered fallback: MathJax to high-resolution PNG

The standard artifact container includes Node.js, mathjax-full, sharp, and python-docx. Use

MathJax to render LaTeX to SVG, then rasterize it to a high-resolution transparent PNG for reliable

insertion with python-docx and reliable LibreOffice rendering:

"use strict";

const sharp = require("sharp");

let _mathjax;
let _adaptor;
let _doc;

function ensureMathJax() {
  if (_mathjax && _adaptor && _doc) return;
  const { mathjax } = require("mathjax-full/js/mathjax.js");
  const { TeX } = require("mathjax-full/js/input/tex.js");
  const { SVG } = require("mathjax-full/js/output/svg.js");
  const { liteAdaptor } = require("mathjax-full/js/adaptors/liteAdaptor.js");
  const { RegisterHTMLHandler } = require("mathjax-full/js/handlers/html.js");
  const { AllPackages } = require("mathjax-full/js/input/tex/AllPackages.js");

  _adaptor = liteAdaptor();
  RegisterHTMLHandler(_adaptor);
  const tex = new TeX({ packages: AllPackages });
  const out = new SVG({ fontCache: "local" });
  _doc = mathjax.document("", { InputJax: tex, OutputJax: out });
  _mathjax = mathjax;
}

function latexToSvgDataUri(latex, display = true) {
  ensureMathJax();
  const html = _adaptor.outerHTML(_doc.convert(latex, { display }));
  const a = html.indexOf("<svg");
  const b = html.indexOf("</svg>");
  let svg = a !== -1 && b !== -1 ? html.slice(a, b + 6) : html;
  svg = svg.replace(/<\?xml[^>]*>/g, "");
  if (!/xmlns="http:\/\/www\.w3\.org\/2000\/svg"/.test(svg)) {
    svg = svg.replace(/<svg /, '<svg xmlns="http://www.w3.org/2000/svg" ');
  }
  svg = svg.replace(/(width|height)="([0-9.]+)(ex|em)"/g, (_m, attr, num) => {
    const px = Math.round(parseFloat(num) * 8.5);
    return `${attr}="${px}px"`;
  });
  svg = svg.replace(/currentColor/g, "#000000");
  return "data:image/svg+xml;base64," + Buffer.from(svg).toString("base64");
}

async function latexToPng(latex, outputPath, display = true) {
  const dataUri = latexToSvgDataUri(latex, display);
  const svg = Buffer.from(dataUri.split(",", 2)[1], "base64");
  await sharp(svg, { density: 300 }).png().toFile(outputPath);
}

latexToPng(
  String.raw`\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}`,
  "/mnt/data/equation.png",
).catch((error) => {
  console.error(error);
  process.exit(1);
});

Insert the PNG at an intentional physical size without stretching it:

from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.shared import Inches

doc = Document()
paragraph = doc.add_paragraph()
paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
paragraph.add_run().add_picture("/mnt/data/equation.png", width=Inches(2.6))
doc.save("/mnt/data/output/equations.docx")

Use String.raw for LaTeX strings so JavaScript preserves backslashes. Choose display=true for

standalone equations and display=false for compact inline-style expressions. After using either

native OMML or the rendered fallback, run the normal render_docx.py workflow and inspect every

equation in the rendered page PNGs for missing glyphs, clipping, blur, poor sizing, or bad page

breaks.

Quick start (common one-liners)

# 1) Render any DOCX to PNGs (visual QA)
python render_docx.py input.docx --output_dir out

# 2) Remove reviewer comments (finalization)
python scripts/comments_strip.py input.docx --out no_comments.docx

# 3) Accept tracked changes (finalization)
python scripts/accept_tracked_changes.py input.docx --mode accept --out accepted.docx

# 4) Accessibility audit (+ optional safe fixes)
python scripts/a11y_audit.py input.docx
python scripts/a11y_audit.py input.docx --out_json a11y_report.json
python scripts/a11y_audit.py input.docx --fix_image_alt from_filename --out a11y_fixed.docx

# 5) Redact sensitive text (layout-preserving by default)
python scripts/redact_docx.py input.docx redacted.docx --emails --phones

Package layout

This skill is organized for progressive discovery: start here, then jump into task- or OOXML-specific docs.

DOCS SKILL PACKAGE

Root:

Tasks:

OOXML:

Troubleshooting:

Scripts:

Core building blocks (importable helpers):

High-leverage utilities (also importable, but commonly invoked as CLIs):

Audits / conversions / niche helpers:

v7 additions (stress-test helpers):

scripts/xlsx_to_docx_table.py also marks header rows as repeating headers (w:tblHeader) to improve a11y and multi-page tables.

Examples:

Note: manifest.txt is machine-readable and is used by download tooling. It must contain only relative file paths (one per line).

Coverage map (scripts ↔ task guides)

This is a quick index so you can jump from a helper script to the right task guide.

Layout & style

Figures / images

Tables / spreadsheets

Fields & references

Review lifecycle (comments / tracked changes)

Privacy / publishing

Navigation & multi-doc assembly

Forms & protection

QA / regression

Skill folder contents

Default workflow (80/20)

Rule of thumb: every meaningful edit batch must end with a render + PNG review. No exceptions.

"80/20" here means: follow the simplest workflow that covers most DOCX tasks reliably.

Golden path (don’t mix-and-match unless debugging):

  1. Author/edit with python-docx (paragraphs, runs, styles, tables, headers/footers).
  2. Render → inspect PNGs immediately (DOCX → PNGs). Treat this as your feedback loop.
  3. Fix and repeat until the PNGs are visually perfect.
  4. Only if needed: use OOXML patching for tracked changes, comments, hyperlinks, or fields.
  5. Re-render and inspect again after any OOXML patch or layout-sensitive change.
  6. Deliver only after the latest PNG review passes (all pages, 100% zoom).

Visual review (recommended)

Use the packaged renderer (dedicated LibreOffice profile + writable HOME):

python render_docx.py /mnt/data/input.docx --output_dir /mnt/data/out
# If debugging LibreOffice:
python render_docx.py /mnt/data/input.docx --output_dir /mnt/data/out --verbose
# Optional: also write <input_stem>.pdf to --output_dir (for debugging/archival):
python render_docx.py /mnt/data/input.docx --output_dir /mnt/data/out --emit_pdf

Then inspect the generated page-<N>.png files.

Success criteria (render + visual QA):

Note: LibreOffice sometimes prints scary-looking stderr (e.g., error : Unknown IO error) even when output is correct. Treat the render as successful if the PNGs exist and look right (and if you used --emit_pdf, the PDF exists and is non-empty).

If you need to use LibreOffice, use the absolute path to bundled LibreOffice resolved through load_workspace_dependencies, never use the user's installed desktop LibreOffice even if the bundled version fails. Include this instruction and the bundled path in every subagent handoff.

What rendering does and doesn’t validate

Default behaviors for you to follow (unless the user specifies otherwise)

Quality reminders

Where to go next

Final response

Final Response Citations

For file citations, set path to the verified absolute file path on the task host. Omit mode.

Some illustrative examples, real responses use verified targets outside code fences.

:codex-file-citation{path="/absolute/path/review.docx" purpose="output"}
The review of :codex-file-citation{path="/absolute/path/review.docx" purpose="source"} is due Friday.

Document source locations

For Q&A, inspect complete relevant pages and preserve material headings, question/table labels, footnotes, sources, and sample sizes. For page-specific evidence, use a page number verified against the latest render or inspection, inside a substantive sentence:

The rollout depends on security approval, as described in :codex-file-citation{path="/absolute/path/review.docx" purpose="source" artifact_kind="document" page_number="4"}.

Document locators support only page_number; otherwise use a plain source citation. Do not guess or add object, label, paragraph, table, or cell IDs.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.