headcleaner
headcleaner
遍历文件夹,将每个文档转换为 Markdown(带 frontmatter)、OKF v0.2(带 frontmatter)或两者兼有——并带有 omp 风格的动画 TUI。
headcleaner convert ~/Documents/inbox --format both --output ~/Documents/inbox.cleanheadcleaner 是一个 Python CLI 工具,它会扫描你提供的目录,根据扩展名识别每个文档,运行相应的提取引擎(Office 格式使用 OfficeCLI,PDF 使用 pdfplumber,HTML 使用 BeautifulSoup 等),并输出干净且规范化的结果——可以是 Markdown 和 OKF 并排输出,也可以只输出其中之一。
输出格式:
--format md(Markdown)、--format okf(OKF v0.2 包)、--format both(默认)引擎覆盖: 开箱即支持 7 种格式(XLSX、DOCX、PPTX、PDF、HTML、HTM、TXT)——16 种格式的 v1.0 路线图见 docs/FORMAT_MATRIX.md
TUI: 受 omp 启发的动画终端(方框绘制面板、霓虹配色、powerline 分隔符)
Linter:
headcleaner lint检查转换后的 Markdown / OKF 是否存在格式问题逐消息 PST: 每封电子邮件对应一个 OKF 概念(通过 readpst),从而实现逐个文件的审查/签核
office_oxide 后端: 面向 Office 格式的纯 Rust Python 绑定(比 OfficeCLI 快约 100 倍)
启发式清理:
headcleaner convert --clean会运行一个 12 阶段、灵感来自 any2md 的清理管道all2md 回退: 当安装 all2md 时,自动处理另外 38 种格式(Jupyter、LaTeX、reST、源代码等)
headcleaner mcp: 将 headcleaner 作为 MCP 服务器运行,向任何 MCP 代理主机(Claude Code、Cursor 等)暴露 14 个okf_*工具——使用uv pip install "headcleaner[mcp]"安装诊断:
headcleaner doctor检查 Python、PATH、OfficeCLI、输出权限和@slug注册表,然后打印 GO/NO-GO 判定适配器插件: 第三方包通过
headcleaner_plugin入口点组注册格式zsv CSV: 当
zsv在 PATH 中时,使用全球最快的 SIMD CSV 解析器(比标准库快约 10-100 倍)信任证明:
headcleaner attest生成 Merkle 根 + ed25519 签名;verify用于校验本地浏览:
headcleaner serve <bundle>提供用于浏览和搜索的 FastAPI UI诚实的默认值: OKF 信任字段以
unverified/human:pending填充,绝不虚构
安装
# 1. The Office engine — single binary, no Office install needed
npm install -g @officecli/officecli
# 2. The CLI itself (Python ≥3.12, uv-managed)
uv tool install headcleaner
# Or for development:
git clone <this repo>
cd headcleaner-cli
uv sync
uv run headcleaner --help其他安装方式(curl | bash、pip、brew、Windows PowerShell)请参阅 docs/INSTALL.md。
快速开始
headcleaner ~/Documents/inbox --format both --output ./clean这将生成:
clean/
├── manifest.json # run summary: per-file status, engine, sha256
├── REPORT.md # count, average time, and error rate by engine
├── _md/ # plain Markdown (one file per source)
│ ├── notes.docx.md
│ ├── q3.pdf.md
│ └── ...
└── okf/ # OKF v0.2 bundle (one concept per source)
├── index.md # auto-generated directory index
├── notes.md # OKF concept: type=Document
├── q3.pdf.md
└── ...CLI 参考
headcleaner convert <INPUT_DIR> [OPTIONS]
Options:
-f, --format {md,okf,both} Output format(s) [default: both]
-o, --output DIR Output directory [default: ./out]
--ocr Enable Tesseract OCR for scanned PDFs
--officecli-timeout <secs> Timeout per OfficeCLI subprocess call (default: 60)
--include, -i GLOB Include glob (may be repeated)
--exclude, -e GLOB Exclude glob (may be repeated)
--jobs, -j N Parallel worker processes (default: 1 = sequential)
--no-cache Re-convert every file (skip the SHA-256 cache)
--no-continue-on-error Stop on the first failure
--obsidian-compat Add Obsidian-friendly flat fields to OKF frontmatter
--clean Run the 12-stage heuristic cleanup pipeline (any2md-inspired) on each body
--tui / --no-tui Force / disable the animated TUI (default: auto-detect TTY)
--no-okf-index Skip OKF directory index.md generation其他命令: headcleaner doctor [--output-dir DIR] 运行安装与权限诊断 headcleaner templates 列出支持的格式 headcleaner agents 显示引擎安装状态 headcleaner watch IN [--webhook-url URL] 文件变化时重新转换(按 Ctrl+C 停止) headcleaner lint 检查转换后的 Markdown / OKF 的格式问题 headcleaner lint --fix 将安全的问题自动修复到 .fixed/ headcleaner serve OKF 包的本地 HTTP 浏览器 headcleaner notion-import <EXPORT.zip> 反向转换 Notion 工作区导出 headcleaner attest 计算 Merkle 根 + 可选的 ed25519 签名 headcleaner verify 校验 bundle 的证明
## Why OKF?
OKF (Open Knowledge Format, v0.2) is just **markdown + YAML frontmatter in a directory hierarchy**. That means:
- Every concept is a single `.md` file you can `cat`, `grep`, edit in any text editor
- Bundles live in git — pull requests, diffs, blame all work
- Obsidian, Notion, MkDocs, Hugo, Jekyll all consume OKF natively
- Required frontmatter key is just `type` — anything beyond that is producer freedom
See [docs/OKF_NOTES.md](docs/OKF_NOTES.md) for the OKF v0.2 specifics this CLI emits.
## Trust stance (honest defaults)
We never auto-claim review. Every emitted OKF concept gets:
- `status: unverified`
- `verified: human:pending`
- `generated: human:<user>@<host>` (OKF §7 actor convention)
- `stale_after: <today + 180d>`
- `sources: [{uri: file://..., sha256: ...}]`
A human can grep `human:pending` later to find concepts needing review. See [docs/OKF_NOTES.md](docs/OKF_NOTES.md) for the full contract.
## Supported formats
See [docs/FORMAT_MATRIX.md](docs/FORMAT_MATRIX.md) for the full engine × library table. At a glance:
| Format | Engine | Library |
|---|---|---|
| `.docx`, `.xlsx`, `.pptx` | OfficeCLI binary | (native DOM) |
| `.pdf` | pdfplumber (text-layer), pytesseract if `--ocr` | pdfplumber / pytesseract |
| `.html`, `.htm` | BeautifulSoup | beautifulsoup4 |
| `.txt` | chardet + read | chardet |
| `.md`, `.markdown` | pass-through + frontmatter inject | stdlib |
| `.csv`, `.tsv` | Sniffer dialect + GFM table (zsv SIMD when installed) | stdlib `csv` (or `zsv` binary) |
| `.json` | pretty-print + fenced block | stdlib `json` |
| `.eml` | headers + text/html body + attachments | stdlib `email` |
| `.epub` | per-chapter HTML → MD | ebooklib (+ bs4 fallback) |
| `.rtf` | control-word stripping | striprtf (+ regex fallback) |
| `.odt`, `.ods`, `.odp` | paragraph/row extraction + GFM tables | odfpy (+ raw-XML fallback) |
| `.msg` | Outlook headers + body + attachments | extract-msg |
| `.pst` | **per-message** (one OKF concept per email) | readpst (libpst) + libpff-python fallback |
| `.docx`, `.xlsx`, `.pptx` | **office_oxide** (primary, ~100x faster), OfficeCLI binary (fallback) | office_oxide 0.1.8 (PyO3) |
| `.ipynb`, `.latex`, `.rst`, sourcecode, `.enex`, `.chm`, etc. (38 formats) | all2md (when installed) | all2md 1.12 |
| `.doc`, `.xls`, `.ppt` | clear error path | needs `libreoffice --convert-to` first |
## Live mode
```bash
headcleaner watch ~/inbox --output ~/out --webhook-url https://hooks.slack.com/...当 ~/inbox 下的文件发生变化时,会自动重新运行转换。每次重新运行都会将 manifest POST 到 webhook URL(可选)。按 Ctrl+C 停止。
Obsidian 库同步
headcleaner convert ~/inbox --format okf \
--output ~/Documents/MyVault/Concepts \
--obsidian-compat将 Obsidian 友好的扁平字段(source、sha256、generated_by、verified_by、stale_on)添加到 OKF frontmatter 中,使概念能正确显示在 Obsidian 的属性面板中。原始 OKF 字段保持不变,以支持往返转换。
审查(人工签核)
自动转换会将 verified 设置为 human:pending。headcleaner review TUI 会遍历 bundle 中每个待处理概念,并让人将每个概念切换为以下状态:
已批准 →
verified: human:reviewed,status: verified,reviewed_at,reviewed_by,reviewed_via已拒绝 →
verified: human:rejected,status: rejected, 可选的rejection_reasons[]已跳过 → 保持概念为
pending
headcleaner review ./out/okf
# Textual TUI: a=approve, r=reject, s=skip, n=next, p=prev, q=quit如果 Textual 不可用(例如无头 CI),会自动回退到普通模式 REPL。
分发
PyPI:
pip install headcleaner(通过 uv 构建,在推送标签时通过 OIDC 可信发布发布)Homebrew:
brew install headcleaner(formula 位于packaging/homebrew/)Docker:
docker pull ghcr.io/local/headcleaner(多阶段镜像,含 tesseract)Windows:
winget install headcleaner、scoop install headcleaner、choco install headcleaner静态二进制:
pip install pyinstaller && pyinstaller packaging/pyinstaller/headcleaner.spec
完整的发布检查清单见 RELEASE.md。
CLI 界面
headcleaner view <bundle>(添加 --tui 可在终端中浏览)会将 OKF bundle 渲染为单个自包含的 HTML 图形(无需后端,可在任何浏览器中打开)。完整选项请参阅 docs/VIEWER.md。
headcleaner convert IN_DIR [flags] # walk + convert
headcleaner watch IN_DIR [flags] # live mode + webhooks
headcleaner review BUNDLE # human sign-off TUI/REPL
headcleaner attest BUNDLE [--private-key PEM] # Merkle root + optional ed25519 sig
headcleaner verify BUNDLE [--public-key PEM] # verify an attestation
headcleaner serve BUNDLE [--host] [--port] # local HTTP browser for the bundle
headcleaner glob DIR # interactive include REPL (Textual)
headcleaner notion-import EXPORT.zip OUT # reverse a Notion workspace export
headcleaner lint DIR [--fix] # OKF + MD rule checks
headcleaner doctor [--output-dir] # dependency and permission preflight
headcleaner agents [stdout] # emit AGENTS.md
headcleaner templates # list supported formats文档
文档 | 用途 |
本文件——安装、快速开始、CLI 参考 | |
所有安装方式(curl、pip、brew、PowerShell、uv、Docker) | |
详细使用指南,包含实际示例 | |
管道如何组合,以及可在何处扩展 | |
每个支持的格式 × 引擎 × 库 | |
此 CLI 生成的 OKF v0.2 约定 + 信任策略 | |
OKF frontmatter JSON Schema 与编辑器/CI 集成 | |
第三方适配器入口点协议 | |
常见错误与修复 | |
常见问题 | |
如何添加新格式 / 引擎 / 输出器 | |
发布历史 | |
44+ 项已发布改进 + 未来构想 | |
HeadCleaner VS Code 扩展(Concept Explorer + Trust Inspector) |
故障排除
officecli not found — 使用 npm install -g @officecli/officecli 安装。运行 headcleaner agents 进行验证。
PDF 无法提取文本 — 你的 PDF 是纯图像。使用 --ocr 重新运行(需要 pytesseract 和 PATH 中的 Tesseract 二进制文件)。
跳过隐藏文件 — 这是有意为之。以 . 开头的文件会被遍历器丢弃。
根目录缺少 OKF index.md — 当 bundle 中至少有 1 个概念时会自动生成。使用 --no-okf-index 选择退出。
更多 — 参见 docs/TROUBLESHOOTING.md。
开发
git clone <this repo>
cd headcleaner-cli
uv sync
uv run pytest # 314 tests, ~14s
uv run headcleaner convert ./tests/fixtures --format both --output ./out架构
src/headcleaner/
├── walk.py # recursive folder walker
├── router.py # extension → engine dispatch
├── normalize.py # CanonicalDoc + OKF/MD frontmatter builders
├── lint.py # post-conversion linter (OKF + Markdown)
├── run.py # pipeline orchestrator
├── cli.py # Click CLI (headcleaner command)
├── tui.py # Textual TUI (omp-style)
├── engines/
│ ├── base.py # Adapter ABC
│ ├── officecli.py
│ ├── pdf.py
│ ├── html.py
│ └── txt.py
└── emit/
├── markdown.py
├── okf.py
├── okf_index.py
└── manifest.py添加新格式:在 engines/ 中放入一个模块,在 router.py 中注册适配器,并在 docs/FORMAT_MATRIX.md 中增加一行。完整扩展指南请参阅 docs/CONTRIBUTING.md。
许可证
Apache-2.0
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Markdown in, any format out. PDFs merged, split, watermarked. Runs on our own doc engines.
Markdown utilities MCP.
MCP server for AgentDocs (agentdocs.eu): read, search, write, comment on & share Markdown docs.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/jamesdsizemore/headcleaner-cli'
If you have feedback or need assistance with the MCP directory API, please join our Discord server