ocr-skill
Local image and PDF to Markdown for AI agents. Stdio CLI plus a portable SKILL.md. Primary engine: DeepSeek-OCR-2. No MCP.

What it is
When a user hands an agent a scan, screenshot, or PDF and needs exact wording, the agent shells out to ocr and reads Markdown back. Output is fenced as untrusted document data and paginated when long, so large PDFs do not blow the tool-result budget.
Skill packs ship a bundled CLI at dist/ocr (~27 MiB musl onefile, same idea as blockchain-skill's dist/agent-wallet.mjs). Agents run .noob/skills/ocr/ocr extract ... only. The launcher never calls pip or uv (no package sprawl). Rebuild: ./scripts/build-bundle.sh.
Commands:
| Command | Role |
|---|
init | Backend/model readiness for this session |
doctor | Per-check self-test of deps and engines |
extract | Image(s)/PDF → Markdown (--mode markdown|free|figure|ocr) |
open | Next token-budget page of a prior extract |
Supported inputs
| Kind | Formats |
|---|
| Images | PNG, JPEG, WebP, GIF, BMP, TIFF (.png .jpg .jpeg .webp .gif .bmp .tif .tiff) |
| PDF | .pdf (each page rasterized via pypdfium2; no poppler) |
Not in scope: .docx/Office without rasterizing first, remote URLs (download locally first), plain text files (read them directly).
Install
Four routes. Same skill body everywhere; harnesses only differ in where files land.
1. npx skills add (cross-tool)
npx skills add hec-ovi/ocr-skill
2. noob / Grok-style /skills add
/skills add hec-ovi/ocr-skill
Requires a root SKILL.md (this repo has one). Installs under .noob/skills/ocr.
3. Claude Code plugin marketplace
/plugin marketplace add hec-ovi/ocr-skill
/plugin install ocr@ocr-skill
/reload-plugins
4. Codex marketplace
codex plugin marketplace add hec-ovi/ocr-skill
Uses .agents/plugins/marketplace.json and plugins/ocr-codex/.
CLI on PATH
uv tool install git+https://github.com/hec-ovi/ocr-skill
ocr doctor --quick
One-shot without a permanent install:
uvx --from git+https://github.com/hec-ovi/ocr-skill ocr doctor --quick
Full harness notes: docs/INSTALL.md.
Real OCR backends
Recommended (Vulkan + llama.cpp Docker):
cp docker/.env.example docker/.env
# download GGUF into MODELS_DIR (see docker/README.md)
docker compose -f docker/docker-compose.yml --env-file docker/.env up -d
export OCR_BACKEND=llamacpp
export OCR_LLAMA_URL=http://127.0.0.1:8090
ocr doctor
ocr extract ./scan.png --json
Optional torch path: uv tool install 'git+https://github.com/hec-ovi/ocr-skill[deepseek]' and OCR_BACKEND=deepseek.
OCR_BACKEND=mock is for tests only. Never use it for a real user document.
Usage
ocr extract ./scan.png
ocr extract ./report.pdf --mode markdown --json
ocr open report~a1b2c3d4e5f6 --page 2
ocr extract ./shot.jpg --quiet
Agent flow: run ocr extract <path> --json, answer from fenced content, call ocr open when has_more is true.
Architecture
Contract-isolated layers. Outsiders read contracts only; each layer owns its schema and tests.
| Layer | Role |
|---|
| 1 Ingest | Image/PDF path → ordered page PNGs + checksums |
| 2 OCR | Engine port: llamacpp (Vulkan GGUF), deepseek (torch), mock |
| 3 Format | Join pages, fence as untrusted, paginate, SQLite store |
| 4 Agent I/O | extract / open / init / doctor Envelopes for the CLI |
Resolver: docs/INDEX.md. Full design: docs/ARCHITECTURE.md.
Every --json response:
{ "contract_version": "1.0.0", "ok": true, "data": {}, "error": null, "meta": {} }
Skill packaging
| Path | Consumer |
|---|
dist/ocr | Bundled binary (musl; agent runtime) |
ocr, ocr-skill, bin/ocr | Launcher (prefers dist/ocr) |
SKILL.md + references/ | noob /skills add, direct clone |
skills/ocr/ | npx skills add container layout |
plugins/ocr/ | Claude Code plugin |
plugins/ocr-codex/ | Codex plugin |
Canonical skill body is skills/ocr/. After edits run python3 scripts/sync-skill-copies.py.
Agent resolve order (first hit wins):
test -x .noob/skills/ocr/ocr && echo .noob/skills/ocr/ocr
command -v ocr-skill
command -v ocr # only if `ocr --version` says ocr-skill
Environment