diff --git a/.claude/skills/tetrak-articles/SKILL.md b/.claude/skills/tetrak-articles/SKILL.md index 2a09ea9..290e32b 100644 --- a/.claude/skills/tetrak-articles/SKILL.md +++ b/.claude/skills/tetrak-articles/SKILL.md @@ -11,6 +11,10 @@ EasyOCR model. Reference material belongs under `site/content/reference/` and research under `site/content/research/` — an article argues, it does not document. +Drafts and proposals live in the private `tetrak-product` repository +(`product/articles/`); publishing one is a copy into `site/content/articles/` +here. Never link a published article back to a draft. + ## Creating one ```bash @@ -70,12 +74,17 @@ unreadable; an absolute one breaks the day the site is served from a subdirectory; and relref resolves through the page, so a moved target **fails the build** instead of publishing a 404. -## Numbers stay in the research pages - -The research pages read their figures from `evaluation/ocr/benchmark.csv` at -build time and so cannot disagree with the harness. An article may point at a -figure and argue about what it means; it must **not** carry a transcribed copy -of one. +## Numbers stay in the data + +Figures come from the harness's own output, read at build time: +`evaluation/ocr/benchmark.csv` for the corpus (`{{< benchmark >}}`) and +`evaluation/ocr/registers.csv` for the Armenian registers +(`{{< registers >}}`, `{{< registers metric="chr" >}}`). An article may embed +those tables, point at a figure and argue about what it means; it must **not** +carry a transcribed copy of one. That includes counts derived from the tables +("leads on five of eight registers") and figures from a research note ("fixed +465 words"): say "most registers" or "many times more than it broke", and let +the table carry the number. This is not a style preference. The slide deck carried transcribed numbers and disagreed with the harness within a fortnight — nothing failed, and nobody diff --git a/.claude/skills/tetrak-corpus/SKILL.md b/.claude/skills/tetrak-corpus/SKILL.md index b8fa9c6..528f72a 100644 --- a/.claude/skills/tetrak-corpus/SKILL.md +++ b/.claude/skills/tetrak-corpus/SKILL.md @@ -25,27 +25,54 @@ $EDITOR evaluation/ocr/corpus/SOURCES.md # 3. ground truth python tools/generate_expected.py --fixture evaluation/ocr/corpus/images/. -# 4. site renditions (committed, not built — see below) +# 4. classify it: which band fit may learn from it, and whether the site shows it +$EDITOR evaluation/ocr/corpus/splits.toml # [excluded] until a split is designed + +# 5. the Tesseract gate: does CI hold it to the thresholds? +$EDITOR tests/ocr/test_thresholds.py # KNOWN_TESSERACT_LIMITATIONS unless it clears both + +# 6. site renditions (committed, not built — see below) python tools/generate_corpus_thumbnails.py -# 5. a card on the corpus page +# 7. a card on the corpus page, if it is in [published] $EDITOR site/content/reference/corpus.md # add a {{< lightbox >}} entry -# 6. re-measure +# 8. re-measure tetrak-ocr evaluate --all --save ``` Commit the image, its `expected/` transcript, the SOURCES.md entry, the -renditions, the corpus page card, and the regenerated benchmark together. - -## The two steps that fail silently - -**Thumbnails (4) and the corpus card (5).** The renditions are committed +`splits.toml` and threshold-test entries, the renditions, the corpus page card, +and the regenerated benchmark together. + +## The steps that fail silently, and the ones that fail loudly + +**`splits.toml` (4) fails loudly**, on purpose: `tests/ocr/test_calibration.py` +asserts that every split accounts for every fixture, so an unclassified scan +fails CI. Put a new one in `[excluded]`; folding it into a split's fit or +held-out set is a decision about the band fit, not housekeeping. + +`[published]` in the same file records which scans the site is *meant* to +show, but nothing reads it except a check that its names exist: the harness +scores every fixture with ground truth, and the benchmark table renders every +row, so a new scan appears in the results as soon as step 8 runs. What you do +control is the corpus page card (7). + +**The threshold test (5) fails loudly too.** A fixture *absent* from +`KNOWN_TESSERACT_LIMITATIONS` is one CI holds to both thresholds, and the band +fitter treats that as a hard constraint. List it on arrival, as the file's own +comment explains, and take it off once the measurement says it clears both. +The fitter keeps its own copy of the gated set, `CI_GATED` in +`evaluation/ocr/calibration/fit.py`, and `test_calibration` fails until the two +agree, so change both together. Changing which fixtures are gated changes the +fit's constraints: re-fit afterwards (below). + +**Thumbnails (6) and the corpus card (7).** The renditions are committed rather than built, so a new item is simply *missing* from the corpus page until both are done. Nothing errors; the grid is one entry short and looks entirely normal. -**SOURCES.md (2).** Nothing enforces it, and an image whose rights are not +**SOURCES.md (2) fails silently.** Nothing enforces it, and an image whose rights are not recorded cannot be published — which is discovered much later, by someone who has to work out where it came from. @@ -53,17 +80,28 @@ has to work out where it came from. `analyse_image()` picks contrast and PSM from pixel statistics, and its thresholds in `src/tetrak_ocr/backends/tuning.py` were **fitted to part of -this corpus** — `FIT_PROVENANCE` in that module records exactly which images, -and which were not. +this corpus**: the split named in `FIT_PROVENANCE` in that module, defined in +`splits.toml`. If the corpus changes materially, re-fit them with the calibration toolkit -under `evaluation/ocr/calibration/` rather than editing the numbers by hand. +rather than editing the numbers by hand. All three steps write committed +files, and each needs its flag or it only prints: + +```bash +python -m evaluation.ocr.calibration.features --write # pixel statistics; a new raster needs this first +python -m evaluation.ocr.calibration.sweep --save # re-measure every configuration +python -m evaluation.ocr.calibration.fit --write # regenerate the bands in tuning.py +``` + +Skip `--save` and `fit --write` re-fits the old measurements, and CI's +`fit --check` still passes. A corrected transcript invalidates only that +fixture's sweep rows: `sweep --fixture --save`, then `fit --write`. Left un-refitted, `tesseract-auto` quietly becomes miscalibrated: it keeps working, and merely gets worse. -**Do not fold held-out fixtures into a re-fit without saying so.** The images -added after the original fit are held-out data for `tesseract-auto` and -nothing special for any other backend. A band set scored only on the images it +**Do not fold held-out fixtures into a re-fit without saying so.** A split's +held-out fixtures are held-out data for `tesseract-auto` and nothing special +for any other backend. A band set scored only on the images it was fitted to tells you nothing about whether it generalises — that property is worth more than the accuracy it costs. diff --git a/.claude/skills/tetrak-ocr-design/SKILL.md b/.claude/skills/tetrak-ocr-design/SKILL.md index 2a2fe9f..e59fa66 100644 --- a/.claude/skills/tetrak-ocr-design/SKILL.md +++ b/.claude/skills/tetrak-ocr-design/SKILL.md @@ -14,11 +14,13 @@ layouts in `site/layouts/`, styles in `site/assets/scss/`, pages in `site/content/`. There is no `themes/` directory and no external theme. Every npm command below is run from `site/`. -The Python package it documents sits at the repository root. The two files the -site reads from there — `evaluation/ocr/benchmark.csv` and `LICENSING.md` — are -mounted into Hugo's assets by `[module.mounts]` in -`site/config/_default/hugo.toml`, because `os.ReadFile` cannot see above the -project root. Anything else the site needs from the repository needs a mount +The Python package it documents sits at the repository root. The files the +site reads from there — `evaluation/ocr/benchmark.csv`, +`evaluation/ocr/registers.csv` and `LICENSING.md` — are mounted into Hugo's +assets by `[module.mounts]` in `site/config/_default/hugo.toml`, because +`os.ReadFile` cannot see above the project root. (The band table's data is +different: `tools/generate_tuning_data.py` writes `site/data/tuning.toml` +during `prebuild`.) Anything else the site needs from the repository needs a mount too; that is deliberate, since it keeps the reach declared in one place. ## Provenance, and one thing not to undo @@ -214,18 +216,9 @@ is the one part of the site that is dated and signed, but it is not a second design: it opens with the same kicker, `h1` and standfirst as every other page, and everything it adds is apparatus rather than decoration. -Files live at `site/content/articles///-.md` and -publish flat at `/articles////`. **The date directories are -not sections** — they hold no `_index.md`, so nothing renders at -`/articles/2026/`, and giving one an `_index.md` would publish a second, -unstyled index of the same articles. - -The URL is built from front matter, not from the path. **Year and month come -from `date`**, so a file misfiled by a month still publishes correctly. **The -last segment comes from `slug`, which falls through to the title when empty** — -not to the filename, which is what it looks like it does when the file is named -after its title. A sentence-length title becomes a sentence-length URL unless -`slug` is set; the archetype carries an empty `slug` as the reminder. +Where files go, how the URL is assembled, front matter, relref linking and the +rule against transcribed numbers are content rules: load the `tetrak-articles` +skill for those. What follows is the design side. Layouts are `layouts/articles/list.html` and `layouts/articles/single.html`; both listings — the index and the tag pages — render @@ -269,25 +262,16 @@ instead — an empty tag index in place of the article list, with a green build. `_default/list.html` and `_default/single.html` still work where they are, which is what makes this easy to get wrong. -### Linking from an article - -Use `{{< relref "/path" >}}`, not a relative or absolute path. An article sits -four directories deep, so a relative link is unreadable, and an absolute one -reopens [the baseURL trap](#linking-and-the-baseurl-trap) below. relref resolves -through the page, so a moved target fails the build. - -Numbers stay in the research pages, which read them from -`evaluation/ocr/benchmark.csv`. An article may point at a figure and argue about -what it means; it must not carry a transcribed copy of one. - ## Shortcodes | Shortcode | Usage | |---|---| -| `{{< figure src="design/x.png" alt="…" caption="…" class="…" >}}` | Image through the asset pipeline. `src` is relative to `site/assets/images/` | +| `{{< figure src="design/x.webp" alt="…" caption="…" class="…" >}}` | Image through the asset pipeline. `src` is relative to `site/assets/images/` | | `{{< figure-themed src="evaluation/benchmark-comparison" alt="…" >}}` | Light/dark pair, so a chart drawn on white does not glare on a dark page. `src` is the **base name**; it resolves `-light.png` and `-dark.png` | | `{{< lightbox src="corpus/name" alt="…" title="…" width="170" >}}` | Corpus thumbnail linking to its large rendition. Resolves `.webp` and `-large.webp` | -| `{{< benchmark >}}` / `{{< benchmark metric="sec" >}}` | The results table, read from `evaluation/ocr/benchmark.csv` at build time | +| `{{< benchmark >}}` / `{{< benchmark metric="sec" >}}` | The corpus results table, read from `evaluation/ocr/benchmark.csv` at build time | +| `{{< registers >}}` / `{{< registers metric="chr" >}}` / `{{< registers view="summary" >}}` | The Armenian per-register table, read from `evaluation/ocr/registers.csv`. `bold-best="false"` drops the best-in-column marking | +| `{{< bands >}}` / `{{< bands setting="psm" >}}` / `{{< bands provenance="true" >}}` | The Tesseract auto-configuration bands, read from `site/data/tuning.toml` | | `{{< note kind="warning" title="…" >}}…{{< /note >}}` | An admonition. `kind` is `note`, `warning` or `caution`; `title` optional | | `{{< tabs >}}{{< tab "macOS" >}}…{{< /tab >}}{{< /tabs >}}` | Tabbed content. The tab label is a **positional** argument | | `{{< include "LICENSING.md" >}}` | Inlines a file from the repo — positional, repo-root relative | @@ -302,10 +286,10 @@ full URL passed as `linkedin` — the host is built in the template, because a URL in a shortcode attribute trips markdownlint's MD034 and switching that rule off would stop it catching bare URLs in the prose it is actually for. -**Three of these are partials with a shortcode wrapper**, because a layout +**Several of these are partials with a shortcode wrapper**, because a layout cannot call a shortcode and the walkthrough needs the same markup: -`partials/benchmark.html`, `partials/lightbox.html` and -`partials/figure-themed.html`. They take a dict rather than shortcode +`partials/benchmark.html`, `partials/registers.html`, `partials/bands.html`, +`partials/lightbox.html` and `partials/figure-themed.html`. They take a dict rather than shortcode arguments; the shortcode is a two-line wrapper that builds it. Change the partial, not the wrapper. `partials/walkthrough-scores.html` is the one that has no shortcode — it only ever had one caller. @@ -379,9 +363,9 @@ defect is reintroduced. - Sentence case headings. - Write for a competent developer who has already hit the problem. Depth beats brevity; there are no word limits. -- Claim nothing the benchmark does not show. Where a number is published, it is - derived from `evaluation/ocr/benchmark.csv`, not transcribed — the table shortcode - reads the CSV so the page cannot disagree with the data. +- Claim nothing the data does not show. Where a number is published, it is + read from `benchmark.csv`, `registers.csv` or `tuning.toml` by a shortcode, + never transcribed, so the page cannot disagree with the data. - `claude` is a **ceiling reference**, not a competitor: it generated the ground truth everything else is scored against. Mark it as such and exclude it from "best local". diff --git a/CLAUDE.md b/CLAUDE.md index 9bd58dd..34fd719 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -12,10 +12,13 @@ places will drift. ## What this repository is -Separable things that share a repo, deliberately. One repository keeps the -coordination cost down for a two-person project, and the coupling is real: -the site reads `evaluation/ocr/benchmark.csv` at build time through a module -mount, and a publisher serves both pipelines rather than either. +The public half of the project: the pipelines, what measures them, and the +site that publishes the results. Separable things that share a repo +deliberately, because the coupling is real: the site reads +`evaluation/ocr/benchmark.csv` and `registers.csv` at build time through module +mounts, and a publisher serves both pipelines rather than either. Product +management (briefs, decisions, research) lives in the private +`tetrak-product` repository; see "Briefs, decisions and research" below. | Part | Path | What it is | |---|---|---| @@ -52,7 +55,7 @@ never type a number into either renderer. ```bash brew install tesseract poppler # macOS system dependencies python3 -m venv .venv && source .venv/bin/activate -pip install -e '.[dev]' # add ,claude / ,easyocr / ,paddle / ,marker as needed +pip install -e '.[dev]' # add extras as needed: [dev,all,armenian] is everything ``` The Claude backend needs `ANTHROPIC_API_KEY` in `.env` at the repo root. @@ -94,13 +97,11 @@ framework via `ocrmac`, declared with a `sys_platform` marker so `[all]` still installs on Linux. `registry.py` is the single source of truth for that list — add a backend there and the CLI, the harness and the docs all pick it up. -`auto-local-fast` was removed after `evaluate --all` measured it: in every -installed configuration it was at best equal to naming a cheap backend -directly. The one capability it uniquely had — a single engine plus the -triage quality gate — is now `batch --quality-gate`, which applies the -threshold to whichever backend you name. The gate judges a transcript, not an -engine. It is opt-in because it changes which files reach `workspace/processed/`, and -needs the `qa` extra (checked up front, not on the first file). +`batch --quality-gate` sends a poor transcript from any backend to +`workspace/triage/`. It judges a transcript, not an engine, so it is a flag +rather than a backend (an `auto-local-fast` backend was tried and withdrawn). +It is opt-in because it changes which files reach `workspace/processed/`, and +needs the `qa` extra, checked up front rather than on the first file. ## Conventions that matter @@ -301,21 +302,24 @@ actually assembled (neither segment comes from where you would think), the `authors.toml` key, the standfirst's three jobs, relref linking, and the rule that benchmark numbers are cited and never transcribed. - ## Briefs, decisions and research -Product management (briefs, architecture decisions, design research, user -research, the roadmap) is not part of the public project. It is moving to a -private repository, `tetrak-product`; until that split lands it sits in -`product/`, with its own `product/CLAUDE.md`. +Product management (briefs, architecture decisions, design and user research, +the roadmap, article drafts) lives in the private `tetrak-product` repository, +not here. This repository's history starts at the split on 3 October 2026; +`tetrak-product`'s history holds everything before it, including the record of +this code. From the code and the site, **cite it by number, never by path or link**: -"brief 008 (searchable PDF)", "ADR 001". A path couples public code to a -private layout and breaks when a file moves. `site/tests/site.spec.ts` fails -the build if site content links into `product/`. When the reasoning behind a +"brief 008 (searchable PDF)", "ADR 001". A reader of the public repository +cannot follow a link into the private one. `site/tests/site.spec.ts` fails the +build if site content links into `product/`. When the reasoning behind a decision matters to users, put a paragraph of it on the site's research pages instead. +A feature that came from a brief usually lands as two pull requests: the code +here, and the brief's status in `tetrak-product`. + ## CI - `ci.yml` — ruff plus `pytest -m "not slow"` on every push and PR, installing @@ -329,6 +333,8 @@ instead. deploys. - `sphinx-docs.yml` — builds the `docs/` Sphinx site on every push and PR as a check; deploys to GitHub Pages only on push to `main`. See Deployment below. +- `pr-title.yml` — the pull request title must be a Conventional Commit, since + squash-merging makes it the commit on `main` that the release reads. - `release.yml` — see below. The site and Sphinx checks skip paths they cannot be affected by (`docs/**` @@ -340,16 +346,15 @@ superseded in-flight runs. The documentation site is deployed to **Cloudflare Pages** at [tetrak.dev](https://tetrak.dev/), which builds and deploys automatically on -every push to `main`. No manual step is required. The old -`scattercode.github.io/ocr-pipeline/` GitHub Pages site, from the pre-Hugo -mkdocs era, is gone. +every push to `main`. No manual step is required. + +The Sphinx CLI/API reference in `docs/` publishes separately, to GitHub Pages +at `https://scattercode.github.io/tetrak/`, via +`.github/workflows/sphinx-docs.yml` on every push to `main`. It is scoped +strictly to the CLI and Python API reference; narrative content stays on the +Hugo site. -GitHub Pages itself is back in use, though, for a narrower purpose: the -Sphinx CLI/API reference in `docs/` (see below) is unrelated to that old -site and publishes to `https://scattercode.github.io/tetrak/` via -`.github/workflows/sphinx-docs.yml`, deployed on every push to `main`. It is -scoped strictly to CLI + Python API reference — narrative content stays on -the Hugo site. +The Cloudflare Pages project: | Setting | Value | |---|---| @@ -405,10 +410,11 @@ their own lint script: ESLint will not read files above its config, so ## Git hooks -Managed by [Lefthook](https://lefthook.dev) (`lefthook.yml`); install once with -`lefthook install`. +Managed by [Lefthook](https://lefthook.dev) (`lefthook.yml`), installed by +`npm ci` in `site/` or by `lefthook install`. -- **pre-commit** — `ruff check` and `ruff format --check` on staged Python. +- **pre-commit** — `ruff check` and `ruff format --check` on staged Python, and + the site's linters when site files are staged. - **commit-msg** — [Conventional Commits](https://www.conventionalcommits.org/) via the shared `.githooks/commit-msg`. @@ -437,24 +443,18 @@ Releases are automated — do not perform them by hand. commit and tag. Its credentials are the org secrets `RELEASE_CLIENT_ID` and `RELEASE_APP_PRIVATE_KEY`. - This replaced a changelog pull request with auto-merge, which could never - land: a pull request opened with `GITHUB_TOKEN` does not trigger workflows, - so the required checks never started. GitHub Actions itself cannot be given - the bypass -- it is not an installable app, so a ruleset has no identity to - name -- which is why this needs an App at all. A ruleset - requires a pull request, and there is no way to exempt the bot: a bypass must - name an actor, and GitHub Actions is not an installable app, so only - repository admins, organisation admins and deploy keys can be named. Issuing - CI an admin token was the alternative and was declined. Tags are unaffected — - a tag is not a branch, so protection does not apply to it. + Why an App: a ruleset bypass must name an actor, and GitHub Actions is not + an installable app, so it cannot be named; a changelog pull request opened + with `GITHUB_TOKEN` never triggers the required checks, so it could never + merge either. Issuing CI an admin token was the alternative and was + declined. Tags are unaffected: a tag is not a branch. - Never edit `CHANGELOG.md` by hand — change the commit messages or the `commit_parsers` in `cliff.toml` instead. - Never create tags or Releases manually. - **The package version comes from the git tag**, via `hatch-vcs`. Do not add a `version = "..."` literal back to `pyproject.toml`: nothing updates it, so it - silently goes stale. It previously read 0.2.2 across the 1.0.0–1.0.3 - releases. `src/tetrak_ocr/_version.py` is generated at build time and - gitignored. + silently goes stale. `src/tetrak_ocr/_version.py` is generated at build time + and gitignored. - `fix` → patch, `feat` → minor, `!` → major. Choose types accordingly. - Tooling commits use `chore(release):` or `chore(changelog):` so the parser skips them.