Metadata-Version: 2.5
Name: zeropx-corpus-scan
Version: 0.4.0
Summary: Byte-honest inventory of a document corpus: SHA-256, UTF-8 validity, heading tree, dedup, PDF page-range partition. Read-only, zero dependencies.
Project-URL: Homepage, https://github.com/NixEngine/zeropx-corpus-scan
Project-URL: Repository, https://github.com/NixEngine/zeropx-corpus-scan
Project-URL: Issues, https://github.com/NixEngine/zeropx-corpus-scan/issues
Author-email: "Dr. Vander Geraldo Rodrigues da Cunha Júnior" <vgrcjr@gmail.com>
License: MIT
License-File: LICENSE
Keywords: audit,compliance,corpus,e-discovery,provenance,sha256,static-analysis
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Legal Industry
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Office/Business
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == 'dev'
Provides-Extra: ledger
Requires-Dist: zeropx-receipt-chain>=0.2; extra == 'ledger'
Description-Content-Type: text/markdown

# zeropx-corpus-scan

Byte-honest inventory of a document corpus.

**Zero dependencies.** Python 3.10+, standard library only. Read-only.
Nothing is imported, executed, decoded past what the format demands, or
sent anywhere.

## Why

You've been handed a directory of documents — an M&A data room, a
research participant's file dump, a legal discovery batch, a client's
compliance archive — and before anyone opens anything you need a
defensible inventory: *what's in there, what's the same, what's
malformed, what's the byte-level footprint of each file*.

`corpus-scan` walks the directory, hashes every file, structurally
parses the text formats (Markdown / JSON / JSONL / CSV), detects exact
duplicates and multi-format representation groups (`report.md`,
`report.jsonl`, `report.json` → one family), and writes a single JSON
inventory suitable for downstream review or audit-trail storage.

## Install

```bash
pip install zeropx-corpus-scan
```
*(Python import module: `corpus_scan` | CLI command: `corpus-scan`)*

## Use

```bash
corpus-scan --root /path/to/corpus --out ./reports
```

By default only these extensions are scanned: `.md .json .jsonl .csv .txt`.
Override with `--extensions .md,.pdf,.docx` — files with other extensions
are counted in the directory but only get a byte-scan, no structural
parse.

To descend into subdirectories, add `--recursive` (or `-r`):

```bash
corpus-scan --root /path/to/corpus --out ./reports --recursive
```

File symlinks whose resolved target lands outside `--root` are silently
skipped — a symlink pointing to `~/`, `/`, or a sibling mount is never
followed into the inventory, so accidental corpus escape can't happen.

### Detect format from magic bytes (v0.3+)

Add `--detect-format` to read each file's first bytes and record its
actual format alongside the extension. Files whose extension implies
one format but whose header shows a different one are flagged:

```bash
corpus-scan --root /path/to/corpus --out ./reports --recursive --detect-format
```

Each `files[]` entry gains a `format_detected` tag (`"pdf"`, `"png"`,
`"zip"`, `"sqlite3"`, `"elf"`, ...) and — if the extension disagrees —
a `format_disagreement` note. The summary gets a
`format_disagreement_count`. Useful for catching renamed executables,
mislabelled attachments, and content-type spoofing without shelling
out to `libmagic`.

With `--detect-format` on, the default extension list is automatically
widened to include common binary formats (PDF, ZIP-family, images,
archives, executables). Pass `--extensions` explicitly to override
that widening.

Writes `./reports/INVENTORY.json` — a single JSON document containing:

- `schema` — versioned schema identifier
- `summary` — file_count, total_bytes, strict_utf8_files, exact_duplicate_groups, representation_group_count
- `files[]` — one record per file: index, name, stem, extension, relative_path, bytes, sha256, line_count_binary_lf, lf_count, max_line_bytes, nul_bytes, high_bytes, utf8_strict_valid, utf8_error, plus a format-specific structural block for text files
- `representation_groups[]` — same-stem families with a chosen semantic representative
- `exact_duplicates[]` — SHA-256-identical file groups

## Use as a library

```python
from pathlib import Path
from corpus_scan import scan_bytes, scan_markdown, audit_corpus, partition_pdf_pages

# Byte-level scan of one file
info = scan_bytes(Path("document.md"))
print(info["sha256"], info["utf8_strict_valid"])

# Full inventory of a tree
payload = audit_corpus(root=Path("/corpus"), out=Path("./reports"))
print(payload["summary"])

# Partition a 850-page PDF into 100-page jobs
jobs = partition_pdf_pages(850, chunk_size=100)  # -> [(1,100,100), (101,200,100), ..., (801,850,50)]
```

## What it does not do

- Recurse into subdirectories by default. (Recursion is opt-in via
  `--recursive` from v0.2 onward. Single-directory remains the default
  because it makes intent explicit; the toolkit is aimed at reviewers
  who pick a "level" of their corpus deliberately.)
- Load PDFs, DOCXs, or any format needing a third-party parser. Those
  files get a byte-scan only. Extending to Poppler / python-docx is on
  the roadmap as an optional extra.
- Decrypt, transcode, or normalize anything. What's on disk goes in the
  inventory as-is.
- Send anything anywhere.

## Tamper-evident inventory log (v0.4+, optional)

Install the sibling `zeropx-receipt-chain` package to unlock a cross-package
feature: every inventory gets appended to an append-only hash-chained
ledger, so you can prove months later exactly which corpus
inventories were taken, when, at which root, and what SHA-256 the
inventory file had.

```bash
pip install "zeropx-corpus-scan[ledger]"
```

CLI:

```bash
corpus-scan --root ./corpus --out ./reports --recursive --detect-format \
            --ledger ./inventories.jsonl --ledger-tag matter-2026-001
```

Library:

```python
from pathlib import Path
from corpus_scan import audit_corpus
from corpus_scan.ledger_integration import append_inventory_to_ledger

audit_corpus(root=Path("./corpus"), out=Path("./reports"), recursive=True)
entry = append_inventory_to_ledger(
    Path("./reports"), Path("./inventories.jsonl"),
    tag="matter-2026-001",
    extras={"matter_id": "M-2026-001", "reviewer": "you"},
)
```

Re-running the same scan appends idempotently — no duplicate entries.

## Suggested workflow: audit / e-discovery

1. `corpus-scan --root /discovery/batch1 --out ./ledger`
2. Store `INVENTORY.json` alongside the batch as tamper-evident manifest.
3. Cite specific file SHA-256s in your review notes.
4. Re-run at any time; diff two `INVENTORY.json` to detect what changed.

## Standalone Windows binary

A precompiled Windows binary is built by:

```powershell
py -3.14 -m pip install pyinstaller
py -3.14 -m PyInstaller --onefile --name corpus-scan --paths src packaging_entry.py
```

Result: single-file `dist/corpus-scan.exe` (~9 MB) that runs on any
Windows machine without Python installed.

## Author & Provenance

**Sole Author:** Dr. Vander Geraldo Rodrigues da Cunha Júnior (`vgrcjr@gmail.com`).

*Technical & AI-Assisted Provenance Disclosure:* Auxiliary computational/LLM tooling was used strictly for boilerplate and test-harness scaffolding under 1:1 human architectural design, code review, deterministic test verification, and sole human authorship. Zero runtime third-party or AI dependencies.

## License

MIT.
