Skip to main content
Glama

headcleaner

フォルダーをスキャンし、すべてのドキュメントを Markdown(フロントマター付き)、OKF v0.2(フロントマター付き)、またはその両方に変換します — omp スタイルのアニメーション TUI 付き。

headcleaner convert ~/Documents/inbox --format both --output ~/Documents/inbox.clean

headcleaner は、指定したディレクトリをスキャンし、各ドキュメントを拡張子で識別し、適切な抽出エンジン(Office 形式には OfficeCLI、PDF には pdfplumber、HTML には BeautifulSoup など)を実行して、クリーンで正規化された出力 — Markdown と OKF の並列、またはどちらか一方 — を生成する Python CLI です。

  • 出力形式: --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 に着想を得たアニメーションターミナル(ボックス描画パネル、ネオンパレット、パワーラインセパレータ)

  • リンター: headcleaner lint は変換された Markdown / OKF をフォーマットの問題についてレビューします

  • メッセージ単位の PST: メールごとに 1 つの OKF コンセプトを生成(readpst 経由)し、レビュー/承認をファイル単位で行えます

  • office_oxide バックエンド: Office 形式向けの Pure-Rust の Python バインディング(OfficeCLI より約 100 倍高速)

  • ヒューリスティッククリーナップ: headcleaner convert --clean は any2md に着想を得た 12 段階のクリーンアップパイプラインを実行します

  • all2md フォールバック: all2md がインストールされている場合、追加の 38 形式(Jupyter、LaTeX、reST、sourcecode など)を自動処理します

  • headcleaner mcp: headcleaner を MCP サーバーとして実行し、14 個の okf_* ツールをあらゆる MCP エージェントホスト(Claude Code、Cursor など)に公開します — インストール: 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 を参照してください。

Related MCP server: okf-tools

クイックスタート

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 バンドルに対するアテステーションを検証します

## 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 配下でファイルが変更されると、変換を自動的に再実行します。 再実行のたびにマニフェストを Webhook URL に POST します(オプション)。 停止するには Ctrl+C を押します。

Obsidian ボールト同期

headcleaner convert ~/inbox --format okf \
    --output ~/Documents/MyVault/Concepts \
    --obsidian-compat

OKF フロントマターに、Obsidian のプロパティパネルでコンセプトが正しく表示されるように、Obsidian 対応のフラットフィールド(source、sha256、generated_by、verified_by、stale_on)を追加します。元の OKF フィールドはラウンドトリップのためにそのまま保持されます。

レビュー(人間による承認)

自動変換では verified: human:pending が設定されます。headcleaner review TUI はバンドル内のすべての保留中コンセプトを順に表示し、人間がそれぞれを次のいずれかに切り替えられます:

  • approved → verified: human:reviewed、status: verified、 reviewed_at、reviewed_by、reviewed_via

  • rejected → verified: human:rejected、status: rejected、 任意の rejection_reasons[]

  • skipped → コンセプトを 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 バンドルを単一の自己完結型 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

ドキュメント

ドキュメント

目的

README.md

このファイル — インストール、クイックスタート、CLI リファレンス

docs/INSTALL.md

すべてのインストール方法(curl、pip、brew、PowerShell、uv、Docker)

docs/USAGE.md

実際の例を用いた詳細な使用ガイド

docs/ARCHITECTURE.md

パイプラインの全体像と拡張ポイント

docs/FORMAT_MATRIX.md

サポートされるすべての形式 × エンジン × ライブラリ

docs/OKF_NOTES.md

この CLI が出力する OKF v0.2 契約 + 信頼ポリシー

docs/SCHEMA.md

OKF フロントマターの JSON Schema とエディタ/CI 統合

docs/PLUGINS.md

サードパーティアダプターのエントリーポイントプロトコル

docs/TROUBLESHOOTING.md

一般的なエラーとその修正

docs/FAQ.md

よくある質問

docs/CONTRIBUTING.md

新しい形式 / エンジン / エミッターを追加する方法

docs/CHANGELOG.md

リリース履歴

docs/ENHANCEMENTS.md

44 以上の実装済み拡張 + 将来のアイデア

vscode-extension/README.md

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 がない場合 — バンドルに 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

Available Tools

19 tools
get_chunkC

Return one cited chunk after root, policy, and index validation.

Inputs: chunk_id (required), bundle. Returns: object

get_diagnosticsB

Return a stable, content-free diagnostics envelope for a local bundle.

Inputs: bundle. Returns: object

get_readinessC

Return a stable, content-free readiness envelope for a local bundle.

Inputs: bundle. Returns: object

list_review_queueC

Return a stable, content-free review-queue envelope for a local bundle.

Inputs: limit, bundle. Returns: object

okf_context_toolC

Assemble legacy graph context and an additive indexed package when available.

Inputs: depth, start, bundle, max_tokens.

okf_diff_toolC

What changed on disk since the bundle was loaded.

Inputs: bundle.

okf_doctor_toolB

Health report for a bundle (score, errors, warnings, per-rule findings).

Inputs: bundle, stale_days.

okf_get_concept_toolA

Read one concept (frontmatter + body). Accepts id, title, or filename stem.

Inputs: target (required), bundle.

okf_impact_toolB

Report outbound / inbound / transitive links for a concept.

Inputs: concept (required), bundle.

okf_list_bundles_toolA

List the OKF bundles this server has loaded.

Inputs: no named parameters. Returns: result

okf_refresh_toolC

Re-ingest a bundle so the in-memory catalog reflects current files.

Inputs: bundle.

okf_registry_addB

Add a bundle under a slug alias. Then reference it as @/... .

Example:
    okf_registry_add(slug="docs", bundle_path="C:/Users/me/Documents/okf")
    okf_get_concept("@docs/readme")

Inputs: slug (required), bundle_path (required).

okf_registry_listA

List all bundles registered under @slug aliases.

Inputs: no named parameters. Returns: result

okf_registry_removeB

Remove a slug from the registry.

Inputs: slug (required).

okf_registry_resolveA

Resolve @slug/concept to the bundle path + concept id.

Inputs: target (required).

okf_search_toolB

Search one or all loaded bundles.

Set all_bundles=True to search across every bundle currently registered
with the server. Hits from other bundles include a `bundle` field.

Inputs: term (required), limit, bundle, all_bundles. Returns: result

okf_sql_toolA

Read-only SELECT over the in-memory catalog (concepts, links).

Inputs: query (required), bundle. Returns: result

search_chunksC

Return cited, policy-gated chunks from an existing local bundle index.

Inputs: query (required), limit, bundle. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.7/5.0

    Scored across 19 tools

    Disambiguation2/5

    Several tool groups are hard to distinguish: okf_related_tool vs okf_impact_tool both analyze links, search_chunks vs okf_search_tool both search, and okf_doctor_tool/get_diagnostics/get_readiness/list_review_queue all sound like status/health endpoints. The descriptions help only after close reading, but an agent could easily pick the wrong tool.

    Naming Consistency2/5

    Naming conventions are mixed: some tools use okf_*_tool, some use bare get_*/list_* verbs, and registry tools use okf_registry_*. There is no consistent verb_noun or prefix/suffix rule across the set.

    Tool Count3/5

    19 tools is on the heavy side; many are justified by the range of bundle, registry, search, SQL, and graph-analysis capabilities, but the status-envelope and search/link-analysis overlaps add bulk. It is not egregiously overpopulated, but it exceeds the comfortable 3-15 range.

    Completeness4/5

    The server covers the main read-side lifecycle: list/load bundles, search/read concepts and chunks, inspect health/diff, manage registry aliases, and run SQL. Missing mutation tools for bundle content and review actions are likely out of scope, forming only minor gaps agents can work around.

    Maintenance

    ActivityStale
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      D
      quality
      D
      maintenance
      Enables reading, writing, editing, and converting Office documents (ODT, DOCX, ODS, XLSX, PDF, etc.) using MCP tools, with no external dependencies.
      11
      21 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables document conversion and processing through MCP, including Office/PDF/Markdown conversions, OCR, and PDF operations like split, rotate, encrypt, and extract.
      MIT