[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KHYM6YTGZF9YVCZ2F3QT6C":3,"skill-same:01M6KHYM6YTGZF9YVCZ2F3QT6C":69},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":25,"publishedAt":37,"linkOnly":38,"markdownContent":39,"markdownBody":40,"frontMatter":41,"refName":42,"commitSha":43,"skillDirectory":44,"forksCount":13,"repositoryHtmlUrl":45,"repositoryHomepageUrl":6,"ownerHtmlUrl":46,"ownerBlogUrl":6,"ownerDescription":47,"updatedAt":48,"install":49,"resources":62},"01M6KHYM6YTGZF9YVCZ2F3QT6C","document-gen-resilient-workflow",null,"Multi-engine document generation with cascading PDF fallbacks and robust Unicode handling","AG064\u002FOpenSpace","AG064","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184930299?v=4","01M6KHVFG7TB73NHX3RDYSTMH2","01M6KHVFMM7XA2PZA9Z83PHS3V",0,"MIT","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-2794b4\u002FSKILL.md",[17,22],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000002","文档处理","SCENARIO","使用场景",{"categoryNo":23,"categoryName":24,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000023","Skill与智能体开发",[26,27,28,29,30,31,32,33,34,35,36],"workflow","document","document gen resilient workflow","document gen resilient","PDF","engine","generation","multi","Unicode","document generation","with","2026-11-10 10:12:30",false,"---\nname: document-gen-resilient-workflow\ndescription: Multi-engine document generation with cascading PDF fallbacks and robust Unicode handling\n---\n\n# Resilient Document Generation Workflow (Multi-Engine Fallback)\n\n## When to Use\n\nUse this skill when document generation tasks fail or when `shell_agent` returns unknown errors, especially for:\n- Generating documents in multiple formats (`.docx`, `.pdf`, `.html`)\n- **PDF generation fails due to missing LaTeX, encoding issues, or tool errors**\n- Documents contain special characters, symbols, or non-ASCII text\n- You need maximum reliability with automatic fallback options\n\n## Core Technique\n\nSplit document generation into discrete, observable steps with **cascading fallbacks** for PDF generation:\n1. **Content creation** → Use `write_file` to create source Markdown\n2. **Unicode sanitization** → Use Python script for reliable character replacement\n3. **Format conversion** → Try multiple PDF engines in sequence until one succeeds\n4. **Verification** → Check file exists, has non-zero size, and is valid\n\n## ⚠️ Unicode & PDF Engine Guide\n\nDifferent PDF engines have different Unicode support:\n\n| Engine | Unicode Support | Best For | Fallback Position |\n|--------|----------------|----------|-------------------|\n| `pdflatex` | Limited (ASCII-focused) | Simple documents | 1st (fastest) |\n| `xelatex` | Full Unicode | Documents with non-ASCII | 2nd |\n| `wkhtmltopdf` | Good Unicode | Web-style documents | 3rd |\n| `reportlab` (Python) | Full control | Programmatic PDFs | 4th |\n| `fpdf2` (Python) | Full control | Simple text PDFs | 5th (last resort) |\n\n### Character Replacement Table\n\n| Character | Issue | Safe Replacement |\n|-----------|-------|------------------|\n| `—` (em dash) | LaTeX incompatibility | `--` |\n| `–` (en dash) | LaTeX incompatibility | `-` |\n| `\" \"` (curly quotes) | Encoding errors | `\" \"` (straight) |\n| `' '` (curly apostrophe) | Encoding errors | `'` (straight) |\n| `…` (ellipsis) | May not render | `...` |\n| `→` `←` `↑` `↓` | LaTeX incompatibility | `->` `\u003C-` `^` `v` |\n| `✓` `✗` | May not render | `[x]` `[ ]` |\n| `★` `●` | May not render | `*` `-` |\n| `©` `®` `™` | May require packages | `(c)` `(r)` `(tm)` |\n| `é` `ñ` `ü` | Font-dependent | Keep for xelatex, replace for pdflatex |\n\n## Step-by-Step Workflow\n\n### Step 1: Create Source Content with write_file\n\nWrite your document content as Markdown to a source file:\n\n```\nwrite_file\npath: \u002Ftmp\u002Fdocument_source.md\ncontent: |\n  # Document Title\n  \n  ## Section 1\n  Content here...\n  \n  ## Section 2\n  More content...\n```\n\n### Step 2: Sanitize Unicode with Python Script\n\n**Create a reusable Python sanitizer** for reliable character replacement:\n\n```\nwrite_file\npath: \u002Ftmp\u002Fsanitize_unicode.py\ncontent: |\n  #!\u002Fusr\u002Fbin\u002Fenv python3\n  import sys\n  import re\n  \n  if len(sys.argv) \u003C 2:\n      print(\"Usage: sanitize_unicode.py \u003Cinput.md> [output.md]\")\n      sys.exit(1)\n  \n  input_file = sys.argv[1]\n  output_file = sys.argv[2] if len(sys.argv) > 2 else input_file.replace('.md', '_sanitized.md')\n  \n  replacements = {\n      '—': '--',    # em dash\n      '–': '-',     # en dash\n      '\"': '\"',     # left curly quote\n      '\"': '\"',     # right curly quote\n      \"'\": \"'\",     # left curly apostrophe\n      \"'\": \"'\",     # right curly apostrophe\n      '…': '...',   # ellipsis\n      '→': '->',    # right arrow\n      '←': '\u003C-',    # left arrow\n      '↑': '^',     # up arrow\n      '↓': 'v',     # down arrow\n      '✓': '[x]',   # checkmark\n      '✗': '[ ]',   # cross\n      '★': '*',     # star\n      '●': '-',     # bullet\n      '©': '(c)',   # copyright\n      '®': '(r)',   # registered\n      '™': '(tm)',  # trademark\n  }\n  \n  with open(input_file, 'r', encoding='utf-8') as f:\n      content = f.read()\n  \n  for old, new in replacements.items():\n      content = content.replace(old, new)\n  \n  with open(output_file, 'w', encoding='utf-8') as f:\n      f.write(content)\n  \n  print(f\"Sanitized: {input_file} -> {output_file}\")\n```\n\n**Apply sanitization for PDF:**\n\n```\nrun_shell\ncommand: python3 \u002Ftmp\u002Fsanitize_unicode.py \u002Ftmp\u002Fdocument_source.md \u002Ftmp\u002Fdocument_source_sanitized.md\n```\n\n**Note**: Keep original for DOCX\u002FHTML (these formats handle Unicode well).\n\n### Step 3: Convert to Target Formats with Cascading Fallbacks\n\n#### For DOCX (from original, no sanitization needed):\n\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.docx\n```\n\n#### For PDF (try multiple engines in sequence):\n\n**Attempt 1: pdflatex (fastest, limited Unicode)**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source_sanitized.md -o output.pdf --pdf-engine=pdflatex\n```\n\n**If pdflatex fails, Attempt 2: xelatex (full Unicode)**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.pdf --pdf-engine=xelatex\n```\n\n**If xelatex fails, Attempt 3: wkhtmltopdf (web-based)**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.pdf --pdf-engine=wkhtmltopdf\n```\n\n**If all pandoc engines fail, Attempt 4: Python reportlab**\n```\nwrite_file\npath: \u002Ftmp\u002Fgenerate_pdf_reportlab.py\ncontent: |\n  #!\u002Fusr\u002Fbin\u002Fenv python3\n  from reportlab.lib.pagesizes import letter\n  from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer\n  from reportlab.lib.styles import getSampleStyleSheet\n  import markdown\n  \n  input_md = '\u002Ftmp\u002Fdocument_source.md'\n  output_pdf = 'output.pdf'\n  \n  with open(input_md, 'r', encoding='utf-8') as f:\n      md_content = f.read()\n  \n  html_content = markdown.markdown(md_content)\n  \n  doc = SimpleDocTemplate(output_pdf, pagesize=letter)\n  styles = getSampleStyleSheet()\n  story = []\n  \n  # Simple HTML to flowables (basic implementation)\n  for line in html_content.split('\\n'):\n      if line.strip():\n          story.append(Paragraph(line, styles['Normal']))\n          story.append(Spacer(1, 6))\n  \n  doc.build(story)\n  print(f\"PDF created: {output_pdf}\")\n```\n\n```\nrun_shell\ncommand: python3 \u002Ftmp\u002Fgenerate_pdf_reportlab.py\n```\n\n**If reportlab fails, Attempt 5: Python fpdf2 (simpler)**\n```\nwrite_file\npath: \u002Ftmp\u002Fgenerate_pdf_fpdf.py\ncontent: |\n  #!\u002Fusr\u002Fbin\u002Fenv python3\n  from fpdf import FPDF\n  \n  input_md = '\u002Ftmp\u002Fdocument_source.md'\n  output_pdf = 'output.pdf'\n  \n  pdf = FPDF()\n  pdf.add_page()\n  pdf.set_font('Helvetica', '', 12)\n  \n  with open(input_md, 'r', encoding='utf-8') as f:\n      for line in f:\n          # Simple line-by-line, escape special chars\n          safe_line = line.encode('latin-1', 'replace').decode('latin-1')\n          pdf.cell(0, 10, safe_line[:180], ln=True)\n  \n  pdf.output(output_pdf)\n  print(f\"PDF created: {output_pdf}\")\n```\n\n```\nrun_shell\ncommand: python3 \u002Ftmp\u002Fgenerate_pdf_fpdf.py\n```\n\n#### For HTML (from original):\n\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.html\n```\n\n### Step 4: Verify Outputs with Multiple Checks\n\n**Check 1: Files exist and have size**\n```\nrun_shell\ncommand: ls -lh output.docx output.pdf output.html 2>\u002Fdev\u002Fnull && echo \"FILES_OK\" || echo \"FILES_MISSING\"\n```\n\n**Check 2: Validate PDF is not corrupted**\n```\nrun_shell\ncommand: python3 -c \"import fitz; doc=fitz.open('output.pdf'); print(f'PDF_VALID: {doc.page_count} pages')\" 2>\u002Fdev\u002Fnull || echo \"PDF_CHECK_SKIPPED\"\n```\n\n**Check 3: Validate DOCX**\n```\nrun_shell\ncommand: python3 -c \"from docx import Document; d=Document('output.docx'); print(f'DOCX_VALID: {len(d.paragraphs)} paragraphs')\" 2>\u002Fdev\u002Fnull || echo \"DOCX_CHECK_SKIPPED\"\n```\n\n**Check 4: Read back content for manual verification**\n```\nread_file\nfiletype: md\nfile_path: output.html\n```\n\n## Complete Example\n\n```markdown\n# Generate Negotiation Strategy Document (Resilient Workflow)\n\n## Step 1: Write Markdown source\nwrite_file\npath: \u002Ftmp\u002Fnegotiation_strategy.md\ncontent: |\n  # Negotiation Strategy\n  \n  ## Executive Summary\n  Content with original unicode characters...\n  \n  ## Resolution Path\n  More content...\n\n## Step 2: Sanitize for PDF\nwrite_file\npath: \u002Ftmp\u002Fsanitize_unicode.py\ncontent: |\n  [Python sanitizer script from Step 2 above]\n\nrun_shell\ncommand: python3 \u002Ftmp\u002Fsanitize_unicode.py \u002Ftmp\u002Fnegotiation_strategy.md \u002Ftmp\u002Fnegotiation_strategy_sanitized.md\n\n## Step 3: Convert to DOCX (original, Unicode-safe format)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.docx\n\n## Step 4: Convert to PDF (try pdflatex first)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy_sanitized.md -o negotiation_strategy.pdf --pdf-engine=pdflatex\n\n## Step 4b: If pdflatex failed, try xelatex\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.pdf --pdf-engine=xelatex\n\n## Step 4c: If xelatex failed, try wkhtmltopdf\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.pdf --pdf-engine=wkhtmltopdf\n\n## Step 5: Convert to HTML (original)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.html\n\n## Step 6: Verify all outputs\nrun_shell\ncommand: ls -lh negotiation_strategy.* && echo \"ALL_FILES_CREATED\"\n\nrun_shell\ncommand: python3 -c \"import fitz; d=fitz.open('negotiation_strategy.pdf'); print(f'PDF: {d.page_count} pages')\"\n```\n\n## Advantages Over shell_agent\n\n| Aspect | shell_agent | Resilient Manual Workflow |\n|--------|-------------|---------------------------|\n| Error visibility | Opaque, may retry silently | Each step shows explicit output |\n| PDF fallback | May give up after first failure | Cascading engine attempts |\n| Debugging | Hard to isolate | Clear which engine\u002Fstep failed |\n| Unicode control | Agent-dependent | You control sanitization |\n| Recovery | Automatic but may loop | Manual intervention at known points |\n| Tool requirements | Assumes pandoc works | Multiple engine options |\n\n## Troubleshooting by Error Type\n\n### \"LaTeX not found\" or \"pdflatex: command not found\"\n- **Solution**: Try `--pdf-engine=xelatex` or `--pdf-engine=wkhtmltopdf`\n- **Install LaTeX**: `apt-get install texlive-latex-recommended texlive-fonts-recommended`\n- **Or fallback to Python**: Use reportlab\u002Ffpdf2 approach\n\n### \"Encoding error\" or \"UnicodeDecodeError\"\n- **Solution**: Use sanitized markdown file (Step 2)\n- **Or**: Add `-f markdown+utf8` to pandoc command\n- **Or**: Try xelatex engine (better Unicode support)\n\n### \"wkhtmltopdf not found\"\n- **Solution**: Install via `apt-get install wkhtmltopdf` or fallback to Python\n\n### \"ModuleNotFoundError: No module named 'reportlab'\"\n- **Solution**: `pip install reportlab` or fallback to fpdf2\n\n### \"Invalid PDF\" or corrupted output\n- **Diagnosis**: Run `pdftotext output.pdf -` to check if text extracts\n- **Solution**: Try different PDF engine from fallback chain\n\n### DOCX formatting issues\n- **Solution**: Add `--reference-doc=template.docx` for custom styles\n- **Or**: Fix markdown structure in source file\n\n### All pandoc commands fail\n- **Check**: `pandoc --version` to verify installation\n- **Fallback**: Use Python-based PDF generation (reportlab\u002Ffpdf2)\n- **For DOCX**: Try `python-docx` library directly\n\n## Pre-Flight Checks (Optional but Recommended)\n\nBefore starting, verify required tools are available:\n\n```\nrun_shell\ncommand: pandoc --version && echo \"PANDOC_OK\" || echo \"PANDOC_MISSING\"\nrun_shell\ncommand: pdflatex --version && echo \"PDFLATEX_OK\" || echo \"PDFLATEX_MISSING\"\nrun_shell\ncommand: python3 -c \"import reportlab\" && echo \"REPORTLAB_OK\" || echo \"REPORTLAB_MISSING\"\n```\n\nThis helps you know which fallback path will be needed.\n\n## Related Skills\n\n- `document-gen-unicode-safe`: Parent skill with basic Unicode guidance\n- `document-gen-fallback`: Original fallback without Unicode or multi-engine support\n- Use this skill when you need maximum reliability with automatic fallbacks\n\n## When to Return to shell_agent\n\nAfter manually completing this workflow successfully once for a document type, you can attempt `shell_agent` for similar tasks with reduced risk (you now know the fallback path). However, for critical documents or those with heavy Unicode content, consider always using this resilient manual workflow.\n","# Resilient Document Generation Workflow (Multi-Engine Fallback)\n\n## When to Use\n\nUse this skill when document generation tasks fail or when `shell_agent` returns unknown errors, especially for:\n- Generating documents in multiple formats (`.docx`, `.pdf`, `.html`)\n- **PDF generation fails due to missing LaTeX, encoding issues, or tool errors**\n- Documents contain special characters, symbols, or non-ASCII text\n- You need maximum reliability with automatic fallback options\n\n## Core Technique\n\nSplit document generation into discrete, observable steps with **cascading fallbacks** for PDF generation:\n1. **Content creation** → Use `write_file` to create source Markdown\n2. **Unicode sanitization** → Use Python script for reliable character replacement\n3. **Format conversion** → Try multiple PDF engines in sequence until one succeeds\n4. **Verification** → Check file exists, has non-zero size, and is valid\n\n## ⚠️ Unicode & PDF Engine Guide\n\nDifferent PDF engines have different Unicode support:\n\n| Engine | Unicode Support | Best For | Fallback Position |\n|--------|----------------|----------|-------------------|\n| `pdflatex` | Limited (ASCII-focused) | Simple documents | 1st (fastest) |\n| `xelatex` | Full Unicode | Documents with non-ASCII | 2nd |\n| `wkhtmltopdf` | Good Unicode | Web-style documents | 3rd |\n| `reportlab` (Python) | Full control | Programmatic PDFs | 4th |\n| `fpdf2` (Python) | Full control | Simple text PDFs | 5th (last resort) |\n\n### Character Replacement Table\n\n| Character | Issue | Safe Replacement |\n|-----------|-------|------------------|\n| `—` (em dash) | LaTeX incompatibility | `--` |\n| `–` (en dash) | LaTeX incompatibility | `-` |\n| `\" \"` (curly quotes) | Encoding errors | `\" \"` (straight) |\n| `' '` (curly apostrophe) | Encoding errors | `'` (straight) |\n| `…` (ellipsis) | May not render | `...` |\n| `→` `←` `↑` `↓` | LaTeX incompatibility | `->` `\u003C-` `^` `v` |\n| `✓` `✗` | May not render | `[x]` `[ ]` |\n| `★` `●` | May not render | `*` `-` |\n| `©` `®` `™` | May require packages | `(c)` `(r)` `(tm)` |\n| `é` `ñ` `ü` | Font-dependent | Keep for xelatex, replace for pdflatex |\n\n## Step-by-Step Workflow\n\n### Step 1: Create Source Content with write_file\n\nWrite your document content as Markdown to a source file:\n\n```\nwrite_file\npath: \u002Ftmp\u002Fdocument_source.md\ncontent: |\n  # Document Title\n  \n  ## Section 1\n  Content here...\n  \n  ## Section 2\n  More content...\n```\n\n### Step 2: Sanitize Unicode with Python Script\n\n**Create a reusable Python sanitizer** for reliable character replacement:\n\n```\nwrite_file\npath: \u002Ftmp\u002Fsanitize_unicode.py\ncontent: |\n  #!\u002Fusr\u002Fbin\u002Fenv python3\n  import sys\n  import re\n  \n  if len(sys.argv) \u003C 2:\n      print(\"Usage: sanitize_unicode.py \u003Cinput.md> [output.md]\")\n      sys.exit(1)\n  \n  input_file = sys.argv[1]\n  output_file = sys.argv[2] if len(sys.argv) > 2 else input_file.replace('.md', '_sanitized.md')\n  \n  replacements = {\n      '—': '--',    # em dash\n      '–': '-',     # en dash\n      '\"': '\"',     # left curly quote\n      '\"': '\"',     # right curly quote\n      \"'\": \"'\",     # left curly apostrophe\n      \"'\": \"'\",     # right curly apostrophe\n      '…': '...',   # ellipsis\n      '→': '->',    # right arrow\n      '←': '\u003C-',    # left arrow\n      '↑': '^',     # up arrow\n      '↓': 'v',     # down arrow\n      '✓': '[x]',   # checkmark\n      '✗': '[ ]',   # cross\n      '★': '*',     # star\n      '●': '-',     # bullet\n      '©': '(c)',   # copyright\n      '®': '(r)',   # registered\n      '™': '(tm)',  # trademark\n  }\n  \n  with open(input_file, 'r', encoding='utf-8') as f:\n      content = f.read()\n  \n  for old, new in replacements.items():\n      content = content.replace(old, new)\n  \n  with open(output_file, 'w', encoding='utf-8') as f:\n      f.write(content)\n  \n  print(f\"Sanitized: {input_file} -> {output_file}\")\n```\n\n**Apply sanitization for PDF:**\n\n```\nrun_shell\ncommand: python3 \u002Ftmp\u002Fsanitize_unicode.py \u002Ftmp\u002Fdocument_source.md \u002Ftmp\u002Fdocument_source_sanitized.md\n```\n\n**Note**: Keep original for DOCX\u002FHTML (these formats handle Unicode well).\n\n### Step 3: Convert to Target Formats with Cascading Fallbacks\n\n#### For DOCX (from original, no sanitization needed):\n\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.docx\n```\n\n#### For PDF (try multiple engines in sequence):\n\n**Attempt 1: pdflatex (fastest, limited Unicode)**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source_sanitized.md -o output.pdf --pdf-engine=pdflatex\n```\n\n**If pdflatex fails, Attempt 2: xelatex (full Unicode)**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.pdf --pdf-engine=xelatex\n```\n\n**If xelatex fails, Attempt 3: wkhtmltopdf (web-based)**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.pdf --pdf-engine=wkhtmltopdf\n```\n\n**If all pandoc engines fail, Attempt 4: Python reportlab**\n```\nwrite_file\npath: \u002Ftmp\u002Fgenerate_pdf_reportlab.py\ncontent: |\n  #!\u002Fusr\u002Fbin\u002Fenv python3\n  from reportlab.lib.pagesizes import letter\n  from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer\n  from reportlab.lib.styles import getSampleStyleSheet\n  import markdown\n  \n  input_md = '\u002Ftmp\u002Fdocument_source.md'\n  output_pdf = 'output.pdf'\n  \n  with open(input_md, 'r', encoding='utf-8') as f:\n      md_content = f.read()\n  \n  html_content = markdown.markdown(md_content)\n  \n  doc = SimpleDocTemplate(output_pdf, pagesize=letter)\n  styles = getSampleStyleSheet()\n  story = []\n  \n  # Simple HTML to flowables (basic implementation)\n  for line in html_content.split('\\n'):\n      if line.strip():\n          story.append(Paragraph(line, styles['Normal']))\n          story.append(Spacer(1, 6))\n  \n  doc.build(story)\n  print(f\"PDF created: {output_pdf}\")\n```\n\n```\nrun_shell\ncommand: python3 \u002Ftmp\u002Fgenerate_pdf_reportlab.py\n```\n\n**If reportlab fails, Attempt 5: Python fpdf2 (simpler)**\n```\nwrite_file\npath: \u002Ftmp\u002Fgenerate_pdf_fpdf.py\ncontent: |\n  #!\u002Fusr\u002Fbin\u002Fenv python3\n  from fpdf import FPDF\n  \n  input_md = '\u002Ftmp\u002Fdocument_source.md'\n  output_pdf = 'output.pdf'\n  \n  pdf = FPDF()\n  pdf.add_page()\n  pdf.set_font('Helvetica', '', 12)\n  \n  with open(input_md, 'r', encoding='utf-8') as f:\n      for line in f:\n          # Simple line-by-line, escape special chars\n          safe_line = line.encode('latin-1', 'replace').decode('latin-1')\n          pdf.cell(0, 10, safe_line[:180], ln=True)\n  \n  pdf.output(output_pdf)\n  print(f\"PDF created: {output_pdf}\")\n```\n\n```\nrun_shell\ncommand: python3 \u002Ftmp\u002Fgenerate_pdf_fpdf.py\n```\n\n#### For HTML (from original):\n\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.html\n```\n\n### Step 4: Verify Outputs with Multiple Checks\n\n**Check 1: Files exist and have size**\n```\nrun_shell\ncommand: ls -lh output.docx output.pdf output.html 2>\u002Fdev\u002Fnull && echo \"FILES_OK\" || echo \"FILES_MISSING\"\n```\n\n**Check 2: Validate PDF is not corrupted**\n```\nrun_shell\ncommand: python3 -c \"import fitz; doc=fitz.open('output.pdf'); print(f'PDF_VALID: {doc.page_count} pages')\" 2>\u002Fdev\u002Fnull || echo \"PDF_CHECK_SKIPPED\"\n```\n\n**Check 3: Validate DOCX**\n```\nrun_shell\ncommand: python3 -c \"from docx import Document; d=Document('output.docx'); print(f'DOCX_VALID: {len(d.paragraphs)} paragraphs')\" 2>\u002Fdev\u002Fnull || echo \"DOCX_CHECK_SKIPPED\"\n```\n\n**Check 4: Read back content for manual verification**\n```\nread_file\nfiletype: md\nfile_path: output.html\n```\n\n## Complete Example\n\n```markdown\n# Generate Negotiation Strategy Document (Resilient Workflow)\n\n## Step 1: Write Markdown source\nwrite_file\npath: \u002Ftmp\u002Fnegotiation_strategy.md\ncontent: |\n  # Negotiation Strategy\n  \n  ## Executive Summary\n  Content with original unicode characters...\n  \n  ## Resolution Path\n  More content...\n\n## Step 2: Sanitize for PDF\nwrite_file\npath: \u002Ftmp\u002Fsanitize_unicode.py\ncontent: |\n  [Python sanitizer script from Step 2 above]\n\nrun_shell\ncommand: python3 \u002Ftmp\u002Fsanitize_unicode.py \u002Ftmp\u002Fnegotiation_strategy.md \u002Ftmp\u002Fnegotiation_strategy_sanitized.md\n\n## Step 3: Convert to DOCX (original, Unicode-safe format)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.docx\n\n## Step 4: Convert to PDF (try pdflatex first)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy_sanitized.md -o negotiation_strategy.pdf --pdf-engine=pdflatex\n\n## Step 4b: If pdflatex failed, try xelatex\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.pdf --pdf-engine=xelatex\n\n## Step 4c: If xelatex failed, try wkhtmltopdf\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.pdf --pdf-engine=wkhtmltopdf\n\n## Step 5: Convert to HTML (original)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.html\n\n## Step 6: Verify all outputs\nrun_shell\ncommand: ls -lh negotiation_strategy.* && echo \"ALL_FILES_CREATED\"\n\nrun_shell\ncommand: python3 -c \"import fitz; d=fitz.open('negotiation_strategy.pdf'); print(f'PDF: {d.page_count} pages')\"\n```\n\n## Advantages Over shell_agent\n\n| Aspect | shell_agent | Resilient Manual Workflow |\n|--------|-------------|---------------------------|\n| Error visibility | Opaque, may retry silently | Each step shows explicit output |\n| PDF fallback | May give up after first failure | Cascading engine attempts |\n| Debugging | Hard to isolate | Clear which engine\u002Fstep failed |\n| Unicode control | Agent-dependent | You control sanitization |\n| Recovery | Automatic but may loop | Manual intervention at known points |\n| Tool requirements | Assumes pandoc works | Multiple engine options |\n\n## Troubleshooting by Error Type\n\n### \"LaTeX not found\" or \"pdflatex: command not found\"\n- **Solution**: Try `--pdf-engine=xelatex` or `--pdf-engine=wkhtmltopdf`\n- **Install LaTeX**: `apt-get install texlive-latex-recommended texlive-fonts-recommended`\n- **Or fallback to Python**: Use reportlab\u002Ffpdf2 approach\n\n### \"Encoding error\" or \"UnicodeDecodeError\"\n- **Solution**: Use sanitized markdown file (Step 2)\n- **Or**: Add `-f markdown+utf8` to pandoc command\n- **Or**: Try xelatex engine (better Unicode support)\n\n### \"wkhtmltopdf not found\"\n- **Solution**: Install via `apt-get install wkhtmltopdf` or fallback to Python\n\n### \"ModuleNotFoundError: No module named 'reportlab'\"\n- **Solution**: `pip install reportlab` or fallback to fpdf2\n\n### \"Invalid PDF\" or corrupted output\n- **Diagnosis**: Run `pdftotext output.pdf -` to check if text extracts\n- **Solution**: Try different PDF engine from fallback chain\n\n### DOCX formatting issues\n- **Solution**: Add `--reference-doc=template.docx` for custom styles\n- **Or**: Fix markdown structure in source file\n\n### All pandoc commands fail\n- **Check**: `pandoc --version` to verify installation\n- **Fallback**: Use Python-based PDF generation (reportlab\u002Ffpdf2)\n- **For DOCX**: Try `python-docx` library directly\n\n## Pre-Flight Checks (Optional but Recommended)\n\nBefore starting, verify required tools are available:\n\n```\nrun_shell\ncommand: pandoc --version && echo \"PANDOC_OK\" || echo \"PANDOC_MISSING\"\nrun_shell\ncommand: pdflatex --version && echo \"PDFLATEX_OK\" || echo \"PDFLATEX_MISSING\"\nrun_shell\ncommand: python3 -c \"import reportlab\" && echo \"REPORTLAB_OK\" || echo \"REPORTLAB_MISSING\"\n```\n\nThis helps you know which fallback path will be needed.\n\n## Related Skills\n\n- `document-gen-unicode-safe`: Parent skill with basic Unicode guidance\n- `document-gen-fallback`: Original fallback without Unicode or multi-engine support\n- Use this skill when you need maximum reliability with automatic fallbacks\n\n## When to Return to shell_agent\n\nAfter manually completing this workflow successfully once for a document type, you can attempt `shell_agent` for similar tasks with reduced risk (you now know the fallback path). However, for critical documents or those with heavy Unicode content, consider always using this resilient manual workflow.\n",{"name":5,"description":7},"main","ff671ef61ed6587c49bd54c81cdc751c0b99e363","gdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-2794b4","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace","https:\u002F\u002Fgithub.com\u002FAG064","AG064, E.Mi.\r\n\r\nA person who thinks all the time, yet all they have to think about is nothing. I want to improve the world and work on open source projects","2026-10-08 06:53:48",{"source":8,"skillName":5,"commands":50,"prompt":60,"zipAvailable":61},[51,54,57],{"tool":52,"command":53},"npx","npx skills add AG064\u002FOpenSpace --skill document-gen-resilient-workflow",{"tool":55,"command":56},"bunx","bunx skills add AG064\u002FOpenSpace --skill document-gen-resilient-workflow",{"tool":58,"command":59},"pnpm","pnpm dlx skills add AG064\u002FOpenSpace --skill document-gen-resilient-workflow","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-2794b4\u002FSKILL.md",true,[63],{"path":64,"resourceType":65,"resourceTypeDesc":66,"sizeBytes":67,"sourceHtmlUrl":68},".skill_id","OTHER","其他",60,"https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-2794b4\u002F.skill_id",[70,94,110,119,149,165],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":37},"01M6KKMPWA0B5SCCH766F8M5EA","write-special-chars-ts-check","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, plus a reliable TypeScript type-checking step that filters output to only the newly-written files to avoid being misled by pre-existing errors.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-ts-check\u002FSKILL.md",[],[77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93],"write special chars ts check","check","write","filters","Existing","type-checking","for","errors","script","output","type","files","only","template","file","python","typescript",{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":37},"01M6KKMJXVBNVEY3TRK055F4A7","write-special-chars-readback","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, with mandatory post-write verification via read_file and cleanup of \u002Ftmp helper scripts.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-readback\u002FSKILL.md",[],[101,102,79,90,103,104,91,92,105,106,107,108,109,83,85,36],"readback","write special chars readback","cleanup","read","scripts","verification","via","post","helper",{"skillNo":111,"name":112,"nameZh":6,"description":113,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":37},"01M6KKMEGX9M9NC105J0W3Q5B9","write-special-chars-heredoc","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) by using a Python heredoc script executed via shell.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-heredoc\u002FSKILL.md",[],[79,117,92,83,107,90,118,91,85],"write special chars heredoc","shell",{"skillNo":120,"name":121,"nameZh":6,"description":122,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":123,"categories":124,"keywords":130,"publishedAt":37},"01M6KKM8EJ2AATVHZBNB916WT0","worldmonitor-reference","Curated architecture index of the WorldMonitor open-source dashboard. Reference for extracting patterns — vanilla TypeScript, Panel class hierarchy, service layer, CSS grid, API edge functions, refresh scheduler, and 60+ data source integrations.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fworldmonitor-reference\u002FSKILL.md",[125],{"categoryNo":126,"categoryName":127,"taxonomyType":128,"taxonomyTypeDesc":129},"01JBSEEDCAT000000000000033","数据分析师","PROFESSION","适用职业",[131,132,133,134,93,135,136,137,138,139,83,140,141,142,143,144,145,146,147,148],"reference","worldmonitor","worldmonitor reference","dashboard","css","architecture","extracting","hierarchy","source","layer","panel","patterns","edge functions","integrations","open","api","data","scheduler",{"skillNo":150,"name":151,"nameZh":6,"description":152,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":153,"categories":154,"keywords":155,"publishedAt":37},"01M6KKM39PHYK627F19GE2B9XN","virtual-list","Implement efficient virtual scrolling for rendering large lists with DOM recycling, chunk-based rendering, and performance optimizations","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fvirtual-list\u002FSKILL.md",[],[156,157,158,159,83,160,36,161,162,163,164],"virtual list","list","virtual","chunk","dom","rendering","recycling","implement","performance",{"skillNo":166,"name":167,"nameZh":6,"description":168,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":169,"categories":170,"keywords":171,"publishedAt":37},"01M6KKKY7T2P61Y0JH54CDEJKQ","verify-directory-structure","Diagnose and resolve file access issues by first verifying the directory structure.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fverify-directory-structure\u002FSKILL.md",[],[172,173,174,175,176,177,91,178,179,180],"directory","verify","structure","verify directory structure","access","first","issues","diagnose","file access"]