# pi-parse-china-standard

Pi extension that downloads an official Chinese national-standard PDF from the SAMR open-standard site, parses it with MinerU, and returns the generated Markdown path to the agent.

## Install

```powershell
pi install npm:pi-parse-china-standard@0.1.0
```

The package includes `@playwright/cli`. Python 3 must be available as `python` on Windows or `python3` on other platforms.

## Configure MinerU

Copy `config/mineru.example.json` to either:

- `<workspace>/.pi/china-standard/mineru.json`
- another path selected by `MINERU_CONFIG`

Keep credentials in an environment variable:

```json
{
  "mode": "cloud",
  "submit_endpoint": "https://mineru.net/api/v4/file-urls/batch",
  "result_endpoint_template": "https://mineru.net/api/v4/extract-results/batch/{batch_id}",
  "token": "env:MINERU_TOKEN",
  "request_timeout_seconds": 60,
  "parse_timeout_seconds": 1800,
  "poll_interval_seconds": 5
}
```

## Tool

The package registers `china_standard_parse` with one argument:

```json
{
  "standard_number": "GB/T 35697-2026"
}
```

The agent receives only the absolute path to `full.md`. The original PDF, Markdown, JSON, DOCX, HTML, LaTeX, images, MinerU ZIP, and cache manifest remain together under:

```text
<workspace>/china-standard-output/<normalized-standard-number>/
```

## Local cache

The workflow is lazy and local-only:

1. Reuse `source.pdf` only when its PDF signature, standard number, and SHA-256 match `cache-manifest.json`.
2. Reuse parsed files only when the source SHA-256, parsing-profile SHA-256, and every recorded output file match the manifest.
3. If only parsing is stale or incomplete, reuse `source.pdf` and call MinerU again.
4. If the PDF cache is invalid, download a verified replacement before changing the cached source.

Database-backed caching is intentionally deferred to [docs/future-plan.md](docs/future-plan.md).
