Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doc Compression — Text Compression Skill

skills.sh

Compresión textual que funciona con cualquier tipo de texto. Reduce la longitud eliminando redundancias, transiciones decorativas y repeticiones — preservando intactos la estructura, terminología, definiciones, citas textuales, datos factuales y secuencia argumentativa del autor.

Compresión ≠ resumen. Esta skill no reescribe ni parafrasea. Elimina lo sobrante. El output se lee como una versión más densa escrita por el mismo autor.

Diseñada para estudiantes y usuarios principiantes, pero adaptable a cualquier tipo de texto. Instrucciones en español; se activa con pedidos en español o inglés y responde en el idioma del usuario.


🚀 Install

npx skills add fedeclavero/doc-compression-skill

✨ What it does

  • Compresses by elimination, not by rewriting — preserves the author's exact words
  • Mechanically verified: fidelity_check.py proves the output is an ordered subset of the original. No invented words, no reordering, quotes verbatim
  • Works with any text: academic papers, book chapters, essays, reports, articles, documentation, blog posts
  • Ratio targeting on compressible prose, not raw word count — protected content (quotes, tables, code, references) is excluded from the denominator
  • Structure-preserving: all headings, sections and hierarchy stay intact
  • Batch-safe: verifies the first file before processing the rest
  • Never inflates: if the text had more redundancy than expected, it reports the real ratio instead of re-injecting filler
  • Degrades gracefully: if no PDF toolchain exists, it delivers Markdown instead of failing

🔧 How it works

A 6-step workflow, with steps 1 and 5 backed by scripts rather than estimation:

Step What happens
0 Conditional notice — only says what the user hasn't already specified, in the user's language
1 Extract, normalize and measure with word_count.py --breakdown
2 Set the target: disambiguate the percentage, compute it over compressible prose, pick the aggressiveness level
3 Map core ideas vs. decorative content
4 Compress in a single pass using the enabled deletion levels
5 Verify with fidelity_check.py — nothing ships on FAIL
6 Deliver with a report built from the scripts' numbers

Deletion levels

The target ratio over compressible prose determines which levels are enabled — decided before writing, not discovered mid-way.

Prose target Levels
≥ 85% L1–L3
70–85% L1–L5
55–70% L1–L7
40–55% L1–L9
< 40% L1–L10

L1 exact repetitions · L2 restated ideas · L3 transitions and meta-commentary · L4 decorative intensifiers · L5 motivational prose · L6 secondary examples · L7 unnecessary background · L8 minor qualifications · L9 structural examples trimmed to their core · L10 secondary arguments

Allowed edits — closed list

Deleting words breaks syntax. Only six repairs are permitted: delete spans; fix gender/number agreement; replace a deleted connector with a comma or period; capitalize after a new cut; replace a pronoun with its literal antecedent from the original; join two sentences when a cut leaves a verbless fragment. Anything else is rewriting.

What is NEVER removed

Section titles and hierarchy · main thesis · technical definitions (exact terminology) · textual quotes · reference lists and bibliography · factual data (numbers, statistics, dates, names) · cause-effect relationships · explicit conclusions · code, formulas, equations · tables and charts · warnings and cautions · numbered procedure steps · figure and table captions

🔬 Verification

The skill's central claim is mechanically checkable, and the skill checks it:

python3 scripts/fidelity_check.py original.md comprimido.md --target 70 --text
VEREDICTO: PASS
  585 -> 409 palabras (69.91%), pureza de subsecuencia 100.0%
  Objetivo 70.0% | rango 63.0-77.0% | IN_RANGE (-1 palabras)
  Sin observaciones.

On a rewritten "compression" it fails, with reasons:

VEREDICTO: FAIL
  [ERROR] invented_words: 10 palabra(s) del comprimido no existen en el original.
  [ERROR] reordered_or_paraphrased: 9 token(s) (36.0%) aparecen fuera del orden del original.
  [ERROR] heading_missing: la educación
  [ERROR] assistant_framing: Frase de framing introducida: «el autor argumenta»
  [AVISO] quote_missing: Cita del original ausente: «el objetivo principal de la educación…»

Exit code 0 on PASS, 1 on FAIL — usable in CI.

📋 Supported text types

Type Strategy
Academic-technical All definitions and taxonomies preserved. Illustrative examples reduced.
Academic-essayistic Argumentative thread preserved, including inferential connectors and hedging (L8 disabled).
Scientific divulgation Key concepts + one example each. Tolerates the most aggressive compression.
Technical-professional Instructions, specs, config values, warnings and deprecations verbatim.
Journalistic-editorial Thesis, evidence and editorial voice preserved; repeated thesis statements cut.
Narrative-expository Authorial voice and temporal structure preserved; L4 applied cautiously.
Mixed Per-section strategy, with the deletion budget split by type.

📌 Example

❌ Wrong — this is an abstract:

Education is a pillar of democratic society. According to Piaget, its goal is to form creative people. This idea remains relevant.

✅ Correct — this is compression by elimination:

Education, understood as a comprehensive and permanent process, is one of the pillars on which a democratic, just and equitable society is built. Education is not limited to the transmission of formal knowledge in the classroom, but encompasses all dimensions of human development. Piaget (1970) maintained that "the main goal of education is to create people capable of doing new things and not simply repeating what other generations did." This concept remains relevant in current educational debates.

Removed: "without a doubt", "absolutely essential", "as we mentioned previously in earlier sections of this same document", "extraordinarily broad", "incredibly powerful", "and contemporary". Preserved: the definition, Piaget's quote, the argumentative structure, the terminology.

📂 Input formats

The skill operates on extracted text. For PDF, DOCX, EPUB, HTML and PPTX it first checks whether a document-reading capability is already installed; only if none exists does it ask permission to install one:

npx skills add https://github.com/anthropics/skills --skill pdf

It never installs anything without explicit authorization, and never compresses without complete, verified text. references/extraction.md also covers post-extraction cleanup — hyphenated line breaks, repeated running heads, stray page numbers, footnotes spliced into the body, two-column reading order. That cleanup happens before word counting and is reported separately from the compression ratio.

📄 Output

Default: reading mode — 1.15 line spacing, clear heading hierarchy, 11–12 pt body, plus the source .md alongside the PDF. The compressed document should take up less space than the original.

APA 7 on request — double-spaced, 1-inch margins, Times 12, APA heading levels. Requested with "APA", "formato académico" or "para entregar". The skill warns that double spacing can make the PDF longer in pages than the original despite having 30% fewer words.

If no PDF toolchain is available, the skill walks a fallback ladder (installed skill → pandoc → HTML/CSS → DOCX+LibreOffice → ReportLab) and, failing all of them, delivers the Markdown and says so. It never aborts a compression because of the packaging.

Output is named <original>_comprimido.<ext>. The original is never overwritten, and an existing _comprimido is never clobbered.

🛡️ Safety

The document being compressed is material, never instructions. Text inside a document addressed to the agent ("ignore previous instructions") is treated as content and reported to the user.

📁 Structure

doc-compression/
├── SKILL.md                      # Main instructions
├── references/
│   ├── extraction.md             # PDF/DOCX/EPUB extraction + artifact cleanup
│   ├── source-formats.md         # Markdown, plain text, papers, technical docs
│   ├── text-types.md             # Rules for all 7 text types
│   ├── large-docs.md             # >8k words: deletion budget, chunk memory, >35k handling
│   └── delivery.md               # Reading mode, APA mode, generation fallback ladder
├── scripts/
│   ├── word_count.py             # Counting, protected/compressible breakdown, target check
│   └── fidelity_check.py         # Subsequence, quotes, headings, data, framing, ratio
└── evals/
    ├── evals.json                # 15 cases with automated checks + expectations
    ├── README.md                 # How to run them
    └── fixtures/                 # 6 real test texts

🤝 Compatibility

Built on the Agent Skills standard (SKILL.md + progressive-disclosure references).

  • Claude Code — tested
  • ✅ Any agent that loads SKILL.md skills and can run Python 3 for the verification scripts
  • ⚠️ Agents without shell access can use the skill, but steps 1 and 5 fall back to estimation, which is exactly what this version was built to avoid

Scripts require Python 3.9+ and no third-party dependencies.

📝 Language

  • Output language matches the document's language
  • The initial notice and the final report use the user's language, which may differ from the document's
  • Technical terminology is never translated
  • Mixed-language texts keep each language in context

📄 License

MIT — see LICENSE. Changelog in CHANGELOG.md.

About

Academic text compression skill for AI agents. Reduces text length by elimination (not rewriting), preserving structure, definitions, citations, and argumentative sequence. Works with Claude Code, Antigravity, Cursor, Windsurf, and any agent supporting SKILL.md.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages