$curl -o .claude/agents/doc-processor.md https://raw.githubusercontent.com/Rune-kit/rune/HEAD/agents/doc-processor.mdGenerate and parse office documents — PDF, DOCX, XLSX, PPTX, CSV. Pure format utility for creating reports, exporting data, processing uploaded documents.
| 1 | # doc-processor |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | Document format utility. Generates and parses office documents (PDF, DOCX, XLSX, PPTX, CSV). Pure utility — no business logic, just format handling. Other skills call doc-processor when they need to produce or consume structured documents. |
| 6 | |
| 7 | ## Triggers |
| 8 | |
| 9 | - Called by `docs` when export to PDF/DOCX is requested |
| 10 | - Called by `marketing` for generating PDF reports, PPTX presentations |
| 11 | - Called by Rune Pro packs for business document generation |
| 12 | - `/rune doc-processor generate <format> <source>` — manual document generation |
| 13 | - `/rune doc-processor parse <file>` — manual document parsing |
| 14 | |
| 15 | ## Calls (outbound) |
| 16 | |
| 17 | None — pure L3 utility. Receives content, produces formatted output. |
| 18 | |
| 19 | ## Called By (inbound) |
| 20 | |
| 21 | - `docs` (L2): export documentation to PDF/DOCX |
| 22 | - `marketing` (L2): generate PDF reports, PPTX pitch decks |
| 23 | - Rune Pro packs: business document generation (invoices, proposals, reports) |
| 24 | - User: `/rune doc-processor` direct invocation |
| 25 | |
| 26 | ## Format Reference |
| 27 | |
| 28 | ### Supported Formats |
| 29 | |
| 30 | | Format | Generate | Parse | Node.js Library | Python Library | |
| 31 | |--------|----------|-------|-----------------|----------------| |
| 32 | | PDF | Yes | Yes (via Read tool) | jsPDF, Puppeteer (HTML→PDF) | reportlab, weasyprint | |
| 33 | | DOCX | Yes | Yes | docx (officegen) | python-docx | |
| 34 | | XLSX | Yes | Yes | ExcelJS | openpyxl | |
| 35 | | PPTX | Yes | Yes | pptxgenjs | python-pptx | |
| 36 | | CSV | Yes | Yes | Built-in (fs + string ops) | Built-in (csv module) | |
| 37 | | HTML | Yes | Yes | Built-in | Built-in | |
| 38 | |
| 39 | ### Library Selection |
| 40 | |
| 41 | Detect project language from context: |
| 42 | - If Node.js project → use Node.js libraries |
| 43 | - If Python project → use Python libraries |
| 44 | - If unclear → default to Node.js (wider ecosystem) |
| 45 | - For HTML→PDF → prefer Puppeteer (best fidelity) or weasyprint (Python) |
| 46 | |
| 47 | ## Executable Steps |
| 48 | |
| 49 | ### Generate Mode |
| 50 | |
| 51 | #### Step 1 — Determine Format and Template |
| 52 | |
| 53 | Identify: |
| 54 | - Target format (PDF, DOCX, XLSX, PPTX, CSV) |
| 55 | - Content source (markdown, data object, template + data) |
| 56 | - Styling requirements (brand colors, fonts, layout) |
| 57 | - Output path |
| 58 | |
| 59 | #### Step 2 — Select Generation Strategy |
| 60 | |
| 61 | | Source | Target | Strategy | |
| 62 | |--------|--------|----------| |
| 63 | | Markdown → PDF | HTML intermediate | Render MD → HTML → Puppeteer → PDF | |
| 64 | | Markdown → DOCX | Direct conversion | Parse MD → docx library → DOCX | |
| 65 | | Data → XLSX | Direct write | Map data to sheets/cells → ExcelJS | |
| 66 | | Slides → PPTX | Template + data | Build slides from content → pptxgenjs | |
| 67 | | Data → CSV | Direct write | Serialize rows → CSV string → file | |
| 68 | | Any → HTML | Direct render | Template engine → HTML file | |
| 69 | |
| 70 | #### Step 3 — Generate Code |
| 71 | |
| 72 | Produce the generation script: |
| 73 | |
| 74 | **PDF from Markdown:** |
| 75 | ```javascript |
| 76 | // Strategy: Markdown → HTML → Puppeteer → PDF |
| 77 | const puppeteer = require('puppeteer'); |
| 78 | const { marked } = require('marked'); |
| 79 | |
| 80 | async function generatePDF(markdownContent, outputPath, options = {}) { |
| 81 | const html = ` |
| 82 | <!DOCTYPE html> |
| 83 | <html> |
| 84 | <head><style>${options.css || defaultCSS}</style></head> |
| 85 | <body>${marked(markdownContent)}</body> |
| 86 | </html> |
| 87 | `; |
| 88 | const browser = await puppeteer.launch(); |
| 89 | const page = await browser.newPage(); |
| 90 | await page.setContent(html, { waitUntil: 'networkidle0' }); |
| 91 | await page.pdf({ path: outputPath, format: 'A4', margin: { top: '1in', bottom: '1in', left: '1in', right: '1in' } }); |
| 92 | await browser.close(); |
| 93 | } |
| 94 | ``` |
| 95 | |
| 96 | **XLSX from Data:** |
| 97 | ```javascript |
| 98 | const ExcelJS = require('exceljs'); |
| 99 | |
| 100 | async function generateXLSX(data, outputPath, options = {}) { |
| 101 | const workbook = new ExcelJS.Workbook(); |
| 102 | const sheet = workbook.addWorksheet(options.sheetName || 'Sheet1'); |
| 103 | if (data.length > 0) { |
| 104 | sheet.columns = Object.keys(data[0]).map(key => ({ header: key, key, width: 20 })); |
| 105 | data.forEach(row => sheet.addRow(row)); |
| 106 | // Style header row |
| 107 | sheet.getRow(1).font = { bold: true }; |
| 108 | sheet.getRow(1).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE0E0E0' } }; |
| 109 | } |
| 110 | await workbook.xlsx.writeFile(outputPath); |
| 111 | } |
| 112 | ``` |
| 113 | |
| 114 | **PPTX from Slides:** |
| 115 | ```javascript |
| 116 | const PptxGenJS = require('pptxgenjs'); |
| 117 | |
| 118 | function generatePPTX(slides, outputPath, options = {}) { |
| 119 | const pptx = new PptxGenJS(); |
| 120 | pptx.author = options.author || 'Generated by Rune'; |
| 121 | slides.forEach(slide => { |
| 122 | const s = pptx.addSlide(); |
| 123 | if (slide.title) s.addText(slide.title, { x: 0.5, y: 0.5, fontSize: 28, bold: true }); |
| 124 | if (slide.body) s.addText(slide.body, { x: 0.5, y: 1.5, fontSize: 16 }); |
| 125 | if (slide.bullets) s.addText(slide.bullets.map(b => ({ text: b, options: { bullet: true } })), { x: 0.5, y: 1.5, fontSize: 16 }); |
| 126 | }); |
| 127 | return pptx.writeFile({ fileName: outputPath }); |
| 128 | } |
| 129 | ``` |
| 130 | |
| 131 | #### Step 4 — Execute and Verify |