# Building the 227Law Court Bundle Tool

The downloadable source is the preferred form for making changes to the standalone Court Bundle Tool. It contains the BunTool application, 227Law changes, the build configuration and source for the optional account/storage integration. The companion archives supply dependency source and notices. No user documents, live account database, encryption keys, credentials or private logs are distributed.

## Application

This version was built with Node.js 22 and npm 10.9.9. The application archive contains `package.json`, `package-lock.json`, the Astro pages, browser JavaScript, fonts and the vendor-build script.

From the application directory:

```sh
npm ci
npm run build
```

The build first runs `scripts/vendor-227law.mjs` and then Astro. Publish `index.html`, `_astro/`, `js/`, `fonts/`, `vendor/` `law227-tool.css` and `law-ai.css` from `dist` under `/court-bundle-tool/`. Other upstream marketing pages remain as source but are not part of the 227Law installation. The generated browser dependencies must stay on the same site. Preserve the supplied licence files, source link and dependency notices. The download `runtime-dependencies-20261201.tar.gz` contains the exact installed runtime npm packages used for this distribution, with their shipped source and maps where supplied. The application lock file also records build tools and their exact package integrity values. Build tools are installed by `npm ci`.

The source archive's integration directory and installation notes describe the PHP endpoints and their route mapping. Account and storage implementations run on PHP 8.3 with OpenSSL, PDO SQLite and the command-line `pdfinfo` utility. Install those PHP sources outside the web root except for the thin public endpoints. Generate a new private storage key on the destination server using the supplied setup script; never copy another installation's keys or data. Adapt absolute private paths and the allowed origin to your installation. Account integration source is included so the boundary can be changed for another account system. The existing separate Community, News and other 227Law applications are not included in this standalone package.

## MuPDF WebAssembly

The app uses the unmodified `mupdf` npm package **1.27.0**. Its installed WebAssembly SHA-256 is recorded in `MUPDF-SOURCE-PROVENANCE.json`. The package's npm `gitHead` is `7956afdc373785865f651fcb76f3112ab1208ba0`. The official 1.27.0 release tag is `d3b7556577b790e9761868c314ad6fd9b6dd86a9`. Upstream records one intervening change: a patch-version update in `include/mupdf/fitz/version.h`.

Both source states are supplied:

- `mupdf-1.27.0-official-source.tar.gz` is the original upstream release, unchanged.
- `mupdf-1.27.0-npm-corresponding-source.tar.gz` contains that complete release source, including populated third-party source directories, with only the version header replaced by the file at the npm package's exact recorded commit. The header and upstream commit patch are also supplied separately.

The package is named 1.27.0 even though its recorded commit's header identifies 1.27.1. This discrepancy is retained in the provenance record. Neither source archive is presented as a verified, bit-for-bit reproduction of the upstream binary. No MuPDF rebuild was performed for this 227Law distribution; the application uses the npm binary recorded above.

Follow `MUPDF-BUILDING.md`, copied from the release's `platform/wasm/BUILDING.md`. It specifies Linux, Node.js 22 and Emscripten SDK **4.0.8**. The default SDK location in its build script is `/opt/emsdk`.

```sh
cd mupdf-1.27.0-source/platform/wasm
npm install
npm run prepack
```

Use the archive's actual top-level directory if its name differs. `platform/wasm/tools/build.sh` is the controlling build script. Its defaults select `BUILD=small`, the `TOFU`, `TOFU_CJK_EXT` and `FZ_ENABLE_HYPHEN=0` defines, and disable brotli, mujs, extract, xps and svg through its feature arguments. Retain that script and its interfaces when rebuilding. The complete source archives include both C and TypeScript code and 17 populated third-party directories; the npm WebAssembly file alone is not the source offer.

Official references:

- https://github.com/ArtifexSoftware/mupdf-downloads/releases/tag/1.27.0
- https://github.com/ArtifexSoftware/mupdf/commit/7956afdc373785865f651fcb76f3112ab1208ba0
- https://github.com/ArtifexSoftware/mupdf/blob/1.27.0/platform/wasm/BUILDING.md
- https://registry.npmjs.org/mupdf/1.27.0

## Font sources

`fontkit-1.1.1-source.tar.gz` is the original Fontkit source and build scripts at commit `72b8e42bd6a398d496a63a6d483eabeed43861fb`, the latest upstream commit before npm 1.1.1 was published. That package has no recorded `gitHead` or matching Git tag; this source's package version still reads 1.1.0. This source is supplied with that limitation and is not asserted to reproduce the npm binary bit for bit. Its `Makefile.js`, Rollup/Babel configuration and `yarn.lock` describe rebuilding the dependency.

The Liberation Sans family uses the four official 2.1.5 TTF files without modification. `liberation-fonts-2.1.5-source.tar.gz` includes its SFD sources and Makefile. Follow its README to build with FontForge. The TTFs, source and licence provenance are recorded in `LIBERATION-SANS-PROVENANCE.json`. The remaining font licences are listed in `FONT-LICENCES.md` and copied under `font-licences/`.

## Redistribution

Retain `LICENSING.md`, MPL and AGPL texts, third-party notices and fonts' notices. Supply the source corresponding to any changes you distribute, with the scripts needed to build and install them. Keep a prominent source-download link available to users of a modified network version. The current downloads are directly accessible from `/court-bundle-tool/source/` without an account or fee.

## Optional AI review (1 December 2026)

The application includes the review component, browser text-extraction worker and editable suggestions. It reads the first two original pages per selected PDF, within the displayed limits, and has no OCR. Review and explicit consent precede sending filenames and excerpts. Apply is a separate action. Original PDF bytes remain unchanged. The summary consists of source excerpts with original-page references.

Install `integration/ai/ai.php` outside the web root, run its setup script to create private counter state, and place only `ai-api.php` beside the bundle endpoint. Append the supplied per-file Apache limits while retaining the existing rules. Do not publish the upstream `js/README.md` with the runtime.

The PHP service uses the existing shared account adapter and the owning site's settings module. The latter supplies OAC_GATEWAY, OAC_KEY and OAC_MODEL constants. The application enforces its approved private gateway URL and owner-specific key path; adapt these explicit checks and paths together for another installation. The key is read from private trusted storage, never distributed. No direct or fallback OpenAI route is provided. Preserve the provider timeout, response cap, JSON validation, quote validation, request limits, CSRF and consent checks. Existing unrelated services are external dependencies, not part of this standalone source package.
