Metadata-Version: 2.5
Name: zeropx-gguf-inspect
Version: 0.3.0
Summary: Zero-dependency static inspection of GGUF model files. Extracts chat_template, tokenizer metadata, tensor info; flags prompt-injection surface. Does not load the model.
Project-URL: Homepage, https://github.com/NixEngine/zeropx-gguf-inspect
Project-URL: Repository, https://github.com/NixEngine/zeropx-gguf-inspect
Project-URL: Issues, https://github.com/NixEngine/zeropx-gguf-inspect/issues
Author-email: "Dr. Vander Geraldo Rodrigues da Cunha Júnior" <vgrcjr@gmail.com>
License: MIT
License-File: LICENSE
Keywords: gguf,llama.cpp,lm-studio,ollama,prompt-injection,security,static-analysis
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
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 :: Security
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Systems Administration
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-gguf-inspect

Zero-dependency static inspection of GGUF model files.

**Read-only.** No model loading. No `chat_template` rendering. No Jinja
evaluation. No network. No external dependencies (Python 3.10+, standard
library only).

## Why

You've downloaded a GGUF from HuggingFace / civitai / a Discord dump / a
customer / a research collaborator, and before you drop it into llama.cpp,
Ollama, or LM Studio, you want to know:

- What's in the `tokenizer.chat_template`? (arbitrary Jinja is dangerous.)
- What does the model call itself in `general.name` / `general.description`?
- What's the architecture, quant, expert count, context length?
- Are there prompt-injection markers in the metadata strings?
- Does the manifest match what was advertised?
- Two files claim to be the same model — are they byte-identical?

`gguf-inspect` answers those without ever asking the runtime to interpret
the file. It walks a directory, parses the GGUF binary layout, and writes
a set of report files you can open in Excel, `jq`, or your text editor.

## Install

```bash
pip install zeropx-gguf-inspect
```
*(Python import module: `gguf_inspect` | CLI command: `gguf-inspect`)*

Or from source:

```bash
git clone https://github.com/NixEngine/zeropx-gguf-inspect
cd zeropx-gguf-inspect
pip install -e .
```

## Use

```bash
gguf-inspect --root /path/to/models --out ./reports
```

With per-file string scanning (slower — reads first 64 MB of every file):

```bash
gguf-inspect --root /path/to/models --out ./reports --scan-strings
```

For a self-contained HTML report on top of the CSV/JSON artifacts:

```bash
gguf-inspect --root /path/to/models --out ./reports --html-report
```

Writes `./reports/report.html` — one page, adaptive light/dark, no
external assets. Open in a browser, screenshot it, print it to PDF,
or ship it as the reviewable deliverable next to the raw CSVs.

The `--root` directory is walked recursively. Every file is inventoried
(SHA-256, size, mtime). Every `*.gguf` file is parsed for header, metadata
KV table, and tensor info.

### Outputs in `--out`

| file                          | contents                                                                 |
|-------------------------------|--------------------------------------------------------------------------|
| `manifest_files.csv`          | Every file: path, size, mtime, SHA-256                                   |
| `manifest_files.jsonl`        | Same, JSON-lines                                                         |
| `gguf_metadata_summary.csv`   | One row per GGUF: version, tensor_count, metadata_kv_count, all keys     |
| `gguf_tensor_summary.csv`     | One row per tensor: name, dims, type, offset                             |
| `gguf_metadata_full.json`     | Complete metadata dump for every GGUF                                    |
| `interesting_metadata.csv`    | KV rows matching key patterns (chat_template, arch, rope, expert, ...)   |
| `interesting_strings.csv`     | (with `--scan-strings`) Printable strings matching injection patterns    |
| `folder_comparison.csv`       | Per top-level folder: file_count, total_size, gguf_count, all SHA-256s   |
| `run_summary.json`            | Root, timing, counts, safety notes                                       |

## As a library

```python
from pathlib import Path
from gguf_inspect import parse_gguf, audit_root

# One file
info = parse_gguf(Path("model.gguf"))
print(info["header"])
print(info["metadata"].get("tokenizer.chat_template", "(none)"))

# Whole tree
summary = audit_root(root=Path("/models"), out=Path("./reports"))
```

## What it will NOT do

- Load the model.
- Render `tokenizer.chat_template` (Jinja or otherwise).
- Call any external service.
- Modify the input files.

Template strings are surfaced verbatim to the report so you can read them
yourself.

## Safety note

If you got a GGUF from an untrusted source, **do not** load it into a
runtime just to inspect it. Templates and metadata are the delivery
surface for prompt-injection payloads targeting the runtime that renders
them. This tool exists so you can read that surface first.

## License

MIT.

## Tamper-evident scan log (v0.3+, optional)

Install the sibling `zeropx-receipt-chain` package to unlock a cross-package
feature: every scan gets appended to an append-only hash-chained
ledger, so you can prove months later exactly which scans were run,
when, and what SHA-256 the artefacts had at the moment they were
written.

```bash
pip install "zeropx-gguf-inspect[ledger]"
```

CLI:

```bash
gguf-inspect --root ./models --out ./reports --html-report \
             --ledger ./scans.jsonl --ledger-tag production
```

The scan's `run_summary.json`, `gguf_metadata_full.json`,
`manifest_files.csv`, and (if generated) `report.html` all get their
SHA-256 recorded in one ledger event, chained to whatever entries
came before it. Re-running the same scan appends idempotently — no
duplicate entries.

Library:

```python
from pathlib import Path
from gguf_inspect import audit_root
from gguf_inspect.ledger_integration import append_scan_to_ledger

audit_root(root=Path("./models"), out=Path("./reports"))
entry = append_scan_to_ledger(
    Path("./reports"), Path("./scans.jsonl"),
    tag="production",
    extras={"reviewer": "you", "ticket_id": "SEC-2026-08-17-001"},
)
print(entry["entry_sha256"])
```

Verify the chain later with:

```bash
pip install zeropx-receipt-chain
receipt-chain verify --path ./scans.jsonl --tag production
```

## 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 gguf-inspect --paths src build_pyi/entry.py
```

Result: single-file `dist/gguf-inspect.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, binary-parser review, deterministic test verification, and sole human authorship. Zero runtime third-party or AI dependencies.

