OR Key
drop another .md file to compare - side-by-side diff against document-summarize

document-summarize

Reads a PDF or spreadsheet you upload and answers questions about it.
personal 2 files

What it does for you

Reads a PDF or spreadsheet you upload and answers questions about it.

What it produces

A recent result, so you can see the kind of work it returns.

loading…

How to get it

These run inside the Snappy workspace. Want this working in your business? I set skills like this up with you, in one focused week.

Work with me
For developers how this skill is built, graded, and how it runs

at a glance- the short version

eval modeauto-shape
stages2

what's inside - the parts that make up a skill 2/4 present

A skill is just a few plain-text files. Only the main one is required. The rest are optional, added as the work needs them. This is what the skill is made of; how it runs is just below.

The skill
state/skills/document-summarize/SKILL.md present
the skill itself, in plain text
The main file. It says what the skill is and lays out the steps in plain English.
Code
state/lib/document-summarize.ts not present
code the skill can run
Optional. Many skills are just words and need no code at all.
Scripts
state/bin/document-summarize/ not present
helper scripts
Optional. Added when a skill has a few commands to run.
Loader
state/skills/document-summarize/AGENTS.md present
what the AI loads on the fly
Loaded automatically the moment this skill is needed. Kept short on purpose.

how it's graded - what counts as a good run 4 criteria · 3 deterministic · 1 judge

Each row is one thing a good run has to get right. deterministic means a quick check decides, pass or fail. judge means the AI reads the result and rates it. Grading each piece on its own (instead of one overall score) shows exactly where a run fell short, so the fix is obvious.

name
kind
check
text_extraction_complete
deterministic
parseDocumentFromBase64(name, mimeType, base64) completes and returns {success: true, text, pages?, rows?, error: null} with text.length > 0 (non-empty extracted content).
text_not_truncated_alone
deterministic
When text exceeds 12000 chars, truncation includes a note: '... [truncated at 12000 chars]'. Not truncated ≠ passing - must have actual extracted content.
context_injected
deterministic
<document name=\"...\" [N page(s)]>extracted text</document> block is prepended to promptForLLM before LLM dispatch.
followup_context_preserved
judge
Follow-up questions include the prior assistant summary in prior_conversation block so the LLM can reference it.

how it runs - the shared frame every skill uses 2/5 present

Every skill runs the same way. One part does the work, a separate part checks it, and a short loader hands the AI exactly what it needs for the job. Anything this skill doesn't use shows a one-line note saying why, on purpose, not by accident.

makes the work The worker
inferred
cd ~/projects/snappy-os from a command
No worker named, so the first command in the skill is treated as the worker.
checks the work The reviewer
inferred
shape gate an automatic check
The check is an automatic pass or fail on the shape of the result, run separately from the work itself.
frame
learns Self-correction
not present

This skill doesn't fix its own gaps yet.

tidies up Background fixes
present
queued for rewrite runs in the background
Bigger fixes that can't be made on the spot get queued and rewritten in the background later.
remembers Run history
present
state/log/evals.ndjson auto-shape runs
Every run is written down here, so the next time this skill is used it already knows how the last runs went.
Critical rules the things this skill must not get wrong
No must-not-break rules called out for this skill. Anything important lives in the writeup below.

what it has learned - fixes written back in over time sample

When a run hits something this skill didn't handle, the fix gets written back into the skill so it doesn't happen again. FIXED means it was corrected on the spot. LOGGED means it's queued for a bigger rewrite. Either way, the skill gets a little better and never makes the same mistake twice.

  1. Loading feedback rows…

how the work flows- step by step

1 stage
cd
cd ~/projects/snappy-os
2 auditor
#
# Verify PDF parsing works:

SKILL.md- the skill, written out in plain English

document-summarize

Handles uploaded document attachments in snappy-os. Extracts text server-side and lets the LLM summarize, analyze key points, answer questions, render tables, and compare documents.

Rubric

criteria:
  - name: text_extraction_complete
    kind: deterministic
    check: "parseDocumentFromBase64(name, mimeType, base64) completes and returns {success: true, text, pages?, rows?, error: null} with text.length > 0 (non-empty extracted content)."
  - name: text_not_truncated_alone
    kind: deterministic
    check: "When text exceeds 12000 chars, truncation includes a note: '... [truncated at 12000 chars]'. Not truncated ≠ passing  -  must have actual extracted content."
  - name: context_injected
    kind: deterministic
    check: "<document name=\"...\" [N page(s)]>extracted text</document> block is prepended to promptForLLM before LLM dispatch."
  - name: followup_context_preserved
    kind: judge
    check: "Follow-up questions include the prior assistant summary in prior_conversation block so the LLM can reference it."

Supported formats

FormatExtensionParser
PDF.pdfpdf-parse (PDFParse class, pdfjs-dist)
Word document.docxmammoth (extractRawText)
CSV spreadsheet.csvcsv-parse/sync (renders as markdown table)
Excel spreadsheet.xlsxxlsx package (optional; fallback error message)

Install requirements

All parsers are installed in ~/projects/snappy-os:

cd ~/projects/snappy-os
npm install pdf-parse mammoth csv-parse
# optional:
npm install xlsx

Architecture

  1. file-attach-button.tsx - user drops/selects PDF/DOCX/XLSX/CSV:
  • Binary files read as ArrayBufferbtoa() → base64 string
  • Encoded as [Document: name.pdf]\ndata:application/pdf;base64,<data>\n\n
  • Added to pendingAttachment.content (same as text/image path)
  1. server.ts (POST /dispatch/chat):
  • Extracts [Document: ...] blocks via regex (parallel to image extraction)
  • Calls state/lib/document-parse.tsparseDocumentFromBase64()
  • Builds <document name="..." [N page(s)]>extracted text</document> blocks
  • Injects into promptForLLM as: "The user has attached the following document(s)...\n\n<document>...\n\nUser request: <intent>"
  1. state/lib/document-parse.ts - document parsing library:
  • parseDocumentFromBase64(name, mimeType, base64)DocumentParseResult
  • Truncates to 12000 chars to stay within LLM context budget
  • CLI self-test: npx tsx state/lib/document-parse.ts <path-to-file>

Steps

  1. User attaches a document via the paperclip button or drag-drop in snappy-os.
  2. file-attach-button.tsx detects binary doc (isBinaryDoc()) → reads as ArrayBuffer → encodes as [Document: ...] marker.
  3. User types intent ("summarize this", "what are the key points", etc.) and sends.
  4. App.tsx prepends pendingAttachment.content to the intent string before dispatch.
  5. server.ts extracts the [Document: ...] block, calls parseDocumentFromBase64().
  6. Extracted text is wrapped in <document> tags and prepended to promptForLLM.
  7. LLM receives clean prompt with document context; responds with summary/analysis.
  8. For follow-up questions (step 5-7 in the flow), prior conversation history includes the assistant's previous summary so the LLM can reference it.

Key points / limitations

  • PDF text extraction requires selectable text (scanned/image PDFs will yield empty or garbled text).
  • Max 12000 chars extracted per document; large documents are truncated with a note.
  • XLSX requires npm install xlsx separately (not installed by default).
  • For .docx files, only raw text is extracted (no table structure, no images).
  • CSV files render as a markdown table (max 200 rows; excess noted).
  • "Compare this PDF to the previous one" works via conversation history - the previous summary is in the prior_conversation block.
  • "Extract the table on page 3 as a Lang Table" works for PDFs with selectable table text; the LLM will structure it using OpenUI Table primitive.

Testing

# Verify PDF parsing works:
npx tsx state/lib/document-parse.ts /path/to/test.pdf

# Verify CSV:
npx tsx state/lib/document-parse.ts /path/to/test.csv

# Verify DOCX:
npx tsx state/lib/document-parse.ts /path/to/test.docx

# Verify the server extracts documents (direct API):
curl -X POST 127.0.0.1:3147/dispatch/chat \
  -H "Content-Type: application/json" \
  -d "{\"intent\":\"[Document: test.pdf]\\ndata:application/pdf;base64,$(base64 -i /path/to/test.pdf | tr -d '\\n')\\n\\nSummarize this.\"}" \
  | grep -o '"delta":"[^"]*' | head -5

AGENTS.md- what the AI loads when this skill comes up

document-summarize - loader

Per-turn rules for document attachment + summarization in snappy-chat. Full skill: state/skills/document-summarize/SKILL.md. Integration skill, eval=auto-shape. No executable verbs; parser at state/lib/document-parse.ts.

Critical Rules

  1. Binary docs use ArrayBuffer, not readAsText. readAsText() on PDF/DOCX/XLSX = garbage. Route via isBinaryDoc()readAsArrayBuffer() → base64.
  2. Encoding: [Document: name]\ndata:<mime>;base64,<data>\n\n. Server regex extracts via [Document:([^\]]+)]\ndata:([^;]+);base64,([^\n]+) - exact format or silent fail.
  3. Parser at state/lib/document-parse.ts. Import: await import("../../lib/document-parse.ts"). Test: npx tsx state/lib/document-parse.ts <file>.
  4. PDF: PDFParse class, not default import. Correct: import { PDFParse } from 'pdf-parse'. Wrong: import pdfParse from 'pdf-parse'.
  5. mammoth: extractRawText({ buffer: buf }){ value: string }. Import: import { extractRawText } from 'mammoth'.
  6. csv-parse: sync path, { columns: true, skip_empty_lines: true, relax_column_count: true }. Renders as markdown table.
  7. LLM context: <document name="..." [N page(s)]>...text...</document>. Prepended with "The user has attached the following document(s)...".
  8. Empty intent allowed. Defaults to "Please summarize this document."
  9. 12000 char truncation intentional. Max per-document for LLM context budget. Suffix: [...document truncated...].
  10. Follow-ups via history. No re-attach needed; prior conversation includes prior summary for context.
  11. XLSX requires separate install. npm install xlsx.
  12. Drag-drop same as click. useFileDrop hook routes via readAsArrayBuffer().

Commands

verbinvokeinputoutput
(integration)---

Test commands: npx tsx ~/projects/snappy-os/state/lib/document-parse.ts <file.pdf|csv|docx> | Verify server: curl -s -X POST 127.0.0.1:3147/dispatch/chat -d '{"intent":"[Document: test.pdf]\ndata:application/pdf;base64,...\n\nSummarize."}' | grep delta

Self-Test

  • [ ] Binary docs use readAsArrayBuffer(), not readAsText()
  • [ ] Encoding: [Document: name]\ndata:<mime>;base64,...
  • [ ] Parser at state/lib/document-parse.ts
  • [ ] PDF uses PDFParse class import
  • [ ] mammoth uses extractRawText({ buffer })
  • [ ] csv-parse uses sync path with correct options
  • [ ] 12000 char truncation is context budget (intentional)
  • [ ] Follow-ups work via conversation history (no re-attach)
  • [ ] XLSX needs separate npm install
  • [ ] Drag-drop routes via readAsArrayBuffer

Found a gap? Edit this file. <!-- footer-injection-point -->

api.ts- the code it can call

⚠ no api.ts - this skill has no typed action surface

scripts- helper scripts it can run

prose-only skill - 3 inline code blocks live in SKILL.md above (no state/bin/ sidecar yet).

how we check it- the checks, plus the last 10 runs

rubric auto-shape no rubric declared
recent no runs actor/auditor: unverifiable
deps none declared

no recent runs logged - the eval contract is declared but nothing has been graded yet