跳到正文
Skillpedia
PDF、Word 与幻灯片7.8k · #12862

document-gen-resilient-workflow

它能做什么

这项技能是一套分步方法,用于制作 Word、PDF 或 HTML 文档,并提供备用方案和错误详情。它适合文档任务因未知错误而不断失败的人。

适用场景

  • ✓当 shell 命令返回未知错误,且没有任何有用细节的时候。
  • ✓当 PDF 因缺少 LaTeX 引擎或编码问题而失败的时候。
  • ✓当类似的文档工作多次失败的时候。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/document-gen-fallback-enhanced-enhanced/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/document-gen-fallback-enhanced-enhanced/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的 PDF 一直因未知错误而失败。请检查工具,换一个引擎试试,并告诉我哪里出了问题。”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会检查工作文件夹和工具,撰写内容,捕获错误输出,按顺序尝试 PDF 引擎直到成功,并确认输出文件可以读取。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Resilient Document Generation Workflow

When to Use

Use this skill when document generation tasks encounter tool errors or failures, especially:

  • run_shell commands return 'unknown error' without diagnostic details
  • PDF generation fails with LaTeX encoding or missing engine errors
  • You need fallback options when primary conversion methods fail
  • Workspace or path issues cause file access problems
  • Unicode/special characters cause rendering issues in PDF output
  • shell_agent has failed multiple times on similar tasks

Core Technique

Split document generation into observable, verifiable steps with explicit error capture and progressive fallback:

  1. Validate workspace → Confirm current directory and write permissions
  2. Pre-flight checks → Verify required tools (pandoc, LaTeX engines) are available
  3. Content creation → Use write_file for source Markdown with full visibility
  4. Unicode sanitization → Preprocess for PDF conversion when needed
  5. Progressive conversion → Try multiple engines/methods until one succeeds
  6. Explicit error capture → Redirect stderr to diagnose failures
  7. Verification → Confirm output files exist and are readable

⚠️ Critical: Tool Error Patterns

'unknown error' from run_shell: This typically indicates:

  • Sandbox execution context issues (not the command itself)
  • Missing stderr capture preventing diagnosis
  • Transient file access problems

Solution: Use explicit error capture with 2>&1 and verify tool availability first:

run_shell
command: pandoc --version 2>&1 || echo "PANDOC NOT AVAILABLE"

Pre-Flight Checklist

Before starting conversion, verify your environment:

## Pre-Flight Checks

### Check 1: Verify working directory
run_shell
command: pwd && ls -la

### Check 2: Verify pandoc availability
run_shell
command: pandoc --version 2>&1 | head -3 || echo "PANDOC MISSING"

### Check 3: Check LaTeX engines
run_shell
command: which pdflatex xelatex wkhtmltopdf 2>&1 || echo "Some engines missing"

### Check 4: Check Python libraries (fallback option)
run_shell
command: python3 -c "import fpdf; print('fpdf OK')" 2>&1 || echo "fpdf missing"
run_shell
command: python3 -c "import docx; print('python-docx OK')" 2>&1 || echo "python-docx missing"

Complete Step-by-Step Workflow

Step 1: Validate Workspace

Confirm you're in the correct directory and can write files:

run_shell
command: pwd && echo "Test write" > /tmp/workspace_test_$$.txt && ls -la /tmp/workspace_test_$$.txt && rm /tmp/workspace_test_$$.txt

If this fails, you may have directory permission issues. Use absolute paths for all files.

Step 2: Create Source Content with write_file

Write document content as Markdown to a source file:

write_file
path: /tmp/document_source.md
content: |
  # Document Title
  
  ## Section 1
  Content here...

Step 3: Unicode Sanitization (PDF Only)

Only needed for PDF conversion via LaTeX engines. DOCX and HTML handle Unicode natively.

Create a sanitized version replacing LaTeX-problematic characters:

write_file
path: /tmp/document_source_sanitized.md
content: |
  # Document Title
  
  [Same content with: em-dash → --, curly quotes → straight, → arrows → text, etc.]

Common replacements (see full table below):

Original Replace With
— (em dash) --
" " (curly quotes) " " (straight)
… (ellipsis) ...
→ ← (arrows) -> <-
✓ ✗ [x] [ ]
© ® ™ (c) (r) (tm)

Alternative: Use sanitization script (see Scripts section below).

Step 4: Progressive Format Conversion

Try multiple methods in order of preference. Capture stderr explicitly for diagnosis.

Method A: DOCX Conversion (Most Reliable)

run_shell
command: pandoc /tmp/document_source.md -o output.docx 2>&1 && echo "SUCCESS" || echo "FAILED: $?"

If this fails, try with explicit UTF-8 flag:

run_shell
command: pandoc /tmp/document_source.md -f markdown+utf8 -o output.docx 2>&1

Method B: PDF Conversion (Progressive Fallback)

Try engines in this order until one succeeds:

run_shell
command: pandoc /tmp/document_source_sanitized.md -o output.pdf 2>&1 | tee /tmp/pdf_error.log && echo "PDF SUCCESS"

If Method B fails, check error log and try next engine:

run_shell
command: pandoc /tmp/document_source_sanitized.md --pdf-engine=xelatex -o output.pdf 2>&1 | tee 
常见问题

它首先检查哪些工具?

在转换之前,它会检查 pandoc 和 LaTeX 引擎是否存在。

为什么要捕获错误输出?

错误细节能显示真正的原因,因此 AI 不必猜测。

如果是文件夹出了问题呢?

指南要求在转换前检查当前文件夹和写入权限。

详情

作者的原始描述

Robust document generation with engine fallback chain, error diagnostics, and Python alternatives

repo: HKUDS/AgentPilot

热度

GitHub 星标
7.8k
排名
#12862
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能