# a2z — CHCE Browser Front End — Agent Build Instructions

You are building **a2z**, the reader of the CHCE family. a2z is **not** a compressor
engine and not a second implementation of the format. It parses a `.dr` file, verifies
it, and compresses ordinary files with the platform's own codecs.

If you feel the urge to port rANS, a BWT sort, PPMd or the context mixer into
JavaScript, stop. That belongs in `ziptastic`, and a browser is the wrong place for it.

---

## 1. Mission

Build a static page that:

1. Reads a `CHCE` v8 stream — header, flags, Layer 0 bytes, block headers, trailer,
   offset table — and reports what it found.
2. Recomputes the manifest digest with WebCrypto and compares it with the trailer, so a
   dropped, duplicated, reordered or edited block is caught without a decoder.
3. States, where it reports, exactly which claims it verified and which need
   `ziptastic d`.
4. Compresses ordinary files in the browser: gzip, deflate, ZIP with per-entry levels,
   store for what is already compressed, and the ratio it actually got.
5. Makes **no network request at runtime**. Every library is vendored.

---

## 2. Hard Constraints

- **No CDN, ever.** Tailwind is built to `styles/app.css` and committed. fflate,
  pdf-lib and export-kit live in `vendor/`. Fonts are two `woff2` files in
  `assets/fonts/`. `browser-check.js` fails the build if a request leaves the origin.
- **No CHCE backend.** No entropy coder, no BWT, no PPMd, no LZMA2, no context mixing.
- **No `.dr` writing.** The encoder is `ziptastic`. a2z reads.
- **No decoding a payload and calling it verification.** If a check needs a decoder, say
  the check was not made.
- **Offline at runtime.** The page must work from a USB stick with no network.
- **JavaScript, no build step to run.** `index.html` plus its files is the app. The only
  build is the stylesheet, and its output is committed.
- **Licence:** PolyForm Noncommercial 1.0.0 — the family's one deliberate exception,
  recorded in `PROJECT_OVERVIEW.md` §6. Vendored libraries keep their MIT/OFL terms; see
  `NOTICE.md`.

---

## 3. Directory Layout You Must Produce

```
index.html            the page
worker.js             compression.js in a worker
engine.js             the main-thread client for it
theme.css             design tokens, the two @font-face rules
styles/app.css        Tailwind, built by scripts/build-styles.sh, committed
app.js                the UI
compression.js        gzip, deflate, ZIP, unzip, repack
dr-inspect.js         the CHCE v8 reader
vendor/               export-kit, fflate, pdf-lib — read-only
assets/fonts/         dm-sans-var.woff2, manrope-var.woff2
assets/icon.svg       the mark
docs/ZIPTASTIC.md     the format as this reader implements it
docs/COMPRESSION.md   the engine, and the store rule
docs/assets/          badges, screenshot
scripts/build-styles.sh
test-node.js          the node suite
browser-check.js      the headless-browser suite
```

---

## 4. Phases

Each phase has an exit test. Do not start the next phase until it passes. Update the
phase table in `README.md` after every phase, and commit as
`phase-<N>: <description>`.

| Phase | What | Exit test | State |
|---|---|---|---|
| 0 | The app as received: three static files, CDN-loaded Tailwind, JSZip, pdf-lib | page renders, image conversion works | ✅ done (1.0.0) |
| 1 | Vendor everything; delete every CDN reference | `browser-check.js`: *nothing loads from a CDN* and *every request was served locally* | ✅ done (2.0.0) |
| 2 | The compression engine: gzip, deflate, ZIP with levels, store rule, extraction | `test-node.js`: round-trips byte for byte; a `.jpg` lands in `storedNames` | ✅ done (2.0.0) |
| 3 | The CHCE reader: header, blocks, trailer, offset table, manifest digest | `test-node.js`: a stream written to `block_writer.cpp` parses; an edited digest fails; a v7 stream is refused; a stub changes nothing | ✅ done (2.0.0) |
| 4 | The report UI: header grid, block table, fourteen checks, copy/save | `browser-check.js`: *the manifest digest is verified in the browser*, *every integrity check passes* | ✅ done (2.0.0) |
| 5 | Family adoption: `PROJECT_OVERVIEW.md`, this file, local badges, phase table, `docs/shot.png`, the fleet nav | `browser-check.js` and `test-node.js` both green; badges regenerated from the counts they claim; the nav names all eight members | ✅ done (2.1.1) |
| 5.3 | Report depth (histogram, sort, compare, manifest export), fuzzing, audio bitrate, mobile table | 3,000 mutations without a throw; the comparison finds a shared block by digest | ✅ done (2.5.0) |
| 5.2 | Off the main thread: `worker.js` + `engine.js`, progress per entry, cancel; cross-check against `ziptastic info` in CI; gzip name/mtime; Markdown report | worker output byte-identical to the main thread; 60 fields agree with the engine | ✅ done (2.4.0) |
| 5.1 | Hardening: input ceilings, reproducible archives, containment, and **fixtures written by the real engine** | all four engine fixtures parse and verify; a `--parallel` stream is not failed; a shrinking Layer 0 is a fact; the manifest is checked even when another check fails | ✅ done (2.3.0) |

### Phases not started

- ~~**6 — i18n.**~~ **Done in 2.7.0 for the workspace, finished in 2.18.0**: one string table
  (`i18n.js`, 146 keys), `data-i18n` markup, a switcher, `?lang=`, an assertion that
  `RANS_CTX`, `ZTIX` and `crc32` survive a language switch, and a coverage assertion over
  every visible text node with an explicit allowlist for proper nouns and format lists.
- ~~**7 — a service worker.**~~ **Done in 2.9.0**: `sw.js` precaches the app, serves
  cache-first with a background refresh, and caches nothing of the user's. The exit test is
  an assertion: the browser suite registers the worker, goes offline, reloads, and checks
  the page came back.
- **8 — payload verification**, *only if* a WebAssembly build of `ziptastic` ever ships.
  Then, and only then, a `.dr` payload can be decoded and its per-block SHA-256 checked.
  Until a build exists, this phase must not be attempted in JavaScript.

---

## 5. What You Must Never Do Here

- ❌ Write a `.dr` file, or imply one came out of a browser.
- ❌ Port a CHCE backend to JavaScript.
- ❌ Present a structural check as a decode check.
- ❌ Add a dependency that is fetched at runtime.
- ❌ Grow a second job. This repo reads CHCE streams and compresses ordinary files; a
  feature that belongs to `ziptastic`, `heavenzip` or `compfactory` belongs there.

---

## 6. Verification

```bash
node test-node.js        # 214 assertions — the reader, the engine, byte arithmetic
node browser-check.js    # 140 assertions — the page, driven in headless Chromium
```

Both must pass before a commit is called done. The numbers above are the counts the
suites print; if they change, update `README.md`, `CHANGELOG.md` and the badges in the
same commit.
