mime-detection-routing

Detects MIME types and routes files to extractors via the FORMATS registry in core/mime.rs.

9.2k|581|Updated Jan 31, 2025
One-click install
npx skills add https://github.com/kreuzberg-dev/kreuzberg --skill mime-detection-routing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mime-detection-routing
Source: https://github.com/kreuzberg-dev/kreuzberg/tree/main/.ai-rulez/skills/mime-detection-routing
Command: npx skills add https://github.com/kreuzberg-dev/kreuzberg --skill mime-detection-routing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When adding a new file format or debugging why a file routes to the wrong extractor, developers need to understand how MIME detection, validation, and extractor selection actually work in the codebase instead of guessing which map or function to edit.

Core Features & Use Cases

  • Detection Flow Reference: Documents the path-based detection (detect_mime_type), bytes-based magic-number detection (detect_mime_type_from_bytes via the infer crate), and validate_mime_type behavior.
  • FORMATS Registry Guidance: Explains that EXT_TO_MIME and SUPPORTED_MIME_TYPES are derived from the single FORMATS registry and must never be hand-edited.
  • Extractor Routing Rules: Covers priority-based registry selection, wildcard MIME families like image/*, and the Err-on-no-match behavior of DocumentExtractorRegistry::get.
  • Use Case: When adding support for a new document format, follow the documented four-step procedure: add a FormatEntry, sync published counts, implement InternalDocumentExtractor, and register it in register_default_extractors().

Quick Start

Load this skill and ask how to add a new file format or why a specific file is being routed to the wrong extractor.

Frequently Asked Questions about mime-detection-routing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new file format to the MIME registry?

Add one FormatEntry to the FORMATS array in core/mime.rs, then run the sync script to update published counts. Implement InternalDocumentExtractor with the new MIME type and register it in register_default_extractors().

How does MIME type detection work for files?

detect_mime_type uses only the lowercased file extension mapped through EXT_TO_MIME, with tree-sitter and mime_guess fallbacks. detect_mime_type_from_bytes performs magic-number content sniffing via the infer crate.

Why does a file route to the wrong extractor?

Routing depends on the validated MIME type matched against the extractor registry, which returns the highest-priority extractor. Check whether the extension maps correctly in FORMATS and whether a wildcard family like image/* is shadowing a specific type.

Does validate_mime_type guarantee an extractor exists?

No, validate_mime_type only checks the media type against SUPPORTED_MIME_TYPES and returns the registered spelling. It does not consult the extractor registry, so a valid MIME type may still have no registered extractor.

Can I edit EXT_TO_MIME or SUPPORTED_MIME_TYPES directly?

No, both are LazyLock values derived automatically by iterating the FORMATS registry. There is no insert call site, so all changes must be made by adding or modifying FormatEntry items in FORMATS.