Skip to content

About

earshot - offline, browser-free renderer and severity-graded differ for a web page's non-visual projection: the screen-reader announcement transcript, keyboard focus order, and the role+name surface AI browser agents target. Pure stdlib Python, 39 graded rules, CI exit-code gate, 310 tests.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Development Experiment 050 — earshot

What a page says out loud, printed as a file — and graded when it changes.

earshot reads static HTML with no browser and no JavaScript, computes the accessibility tree (W3C accname 1.2 + HTML-AAM role mapping), and prints the page's non-visual projection: the announcement transcript a screen reader speaks, the numbered keyboard focus order, and the list of controls a browser-driving AI agent can actually target. Then it diffs two versions and grades every change — so a CI gate can fail on "the Save button lost its name" without failing on "the marketing headline changed".

Pure Python 3.11+ standard library. Zero dependencies. One file in, one reviewable artefact out.

$ python main.py diff examples/checkout_before.html examples/checkout_after.html

[CRITICAL] NAM01  Interactive control lost its accessible name
            where: button (unnamed) <button> (line 76)
            The button previously announced as "Apply promo code" now has no
            accessible name at all. It is unusable by name and untargetable by
            an agent selector.

score 0/100  grade F   critical=2  major=9  minor=2  info=2
$ echo $?
1

Thesis

A web page has two machine-readable consumers now, and they read the same thing. Screen-reader users navigate by role and accessible name; so do browser-driving AI agents — Playwright's accessibility snapshot, and every agent built on it, selects with role=button[name="Save"], and September 2026 was the month that went mainstream (Apple let coding agents drive Safari; Playwright MCP hands agents the accessibility tree as YAML). Meanwhile the automated-accessibility literature is unanimous that scanners have hit their ceiling at roughly a third of WCAG — and equally unanimous that regression prevention is where automation still earns its keep. And since June 2026 the European Accessibility Act is actually enforced, so somebody has to be able to show that the last release did not make things worse. Nothing in that shape exists: the two closest tools (Playwright aria-snapshot, guidepup/virtual-screen-reader) both need a live DOM and both do pass/fail snapshot equality, which trains teams to regenerate the baseline without reading it. earshot is the smallest thing that proves the missing idea: compute the non-visual projection offline from the markup, render it as a file a human can read in a pull request, and diff it with graded severities so the gate is set where it will be respected. Lane: web/devtools + accessibility — the ledger's first entry in either, and a deliberate break from the agent-protocol-auditing run of experiments 001–044.

Install and run

No dependencies, no virtualenv strictly needed. Python 3.11 or newer.

git clone https://github.com/freyesperales/dev-experiment-050
cd dev-experiment-050

python main.py                 # guided demo over the bundled example pages
make test                      # 310 tests, stdlib unittest

If you prefer an isolated environment (nothing will be installed into it — earshot has no dependencies):

python -m venv .venv && . .venv/bin/activate    # Windows: .venv\Scripts\activate
python -m unittest discover -s tests -t tests

Commands

python main.py render <page.html>              # the announcement transcript
python main.py render <page.html> --out page.earshot   # commit it as a baseline
python main.py render <page.html> --json       # machine-readable

python main.py audit  <page.html>              # decidable defects in one page
python main.py diff   <before.html> <after.html>       # graded regression report
python main.py rules                           # the 39-rule catalogue

# also: python -m earshot <command>

--fail-on {critical,major,minor,info,never} sets the gate (default critical). Exit codes: 0 clean, 1 gate tripped, 2 usage or I/O error.

Sample run

1. What the baseline page sounds like

$ python main.py render examples/checkout_before.html
# earshot transcript v1
# source: examples/checkout_before.html
# title: Checkout — Acme Supply
# lang: en

## announcement order (42 nodes)
   1  document
   2    banner
   3      link, "Acme Supply home"  [name from contents]
   4      navigation, "Checkout steps"  [name from aria-label]
   5        list, 3 items
   6          listitem, 1 of 3
   7            link, "Cart"  [name from contents]
   8          listitem, 2 of 3
   9            link, "Delivery"  [name from contents]
  10          listitem, 3 of 3
  11            generic, "Payment", current=step  [name from contents]
  12    main
  13      heading level 1, "Checkout"  [name from contents]
  14      region, "Order summary"  [name from aria-label]
  15        heading level 2, "Order summary"  [name from contents]
  16        figure, "Brass desk lamp — £89.00"  [name from figcaption]
  17          img, "Brass desk lamp with an articulated arm"  [name from alt]
  ...
  23          textbox, "Email address"  -- "We only use this to send your receipt."  [name from label-element]
  ...
  35          textbox, "Promo code", required  [name from label-element]
  36          button, "Apply promo code"  [name from contents]

## focus order (13 stops)
   1. link "Acme Supply home"  <a line 10>
   2. link "Cart"  <a line 13>
   ...
  12. button "Continue to payment"  <button line 73>
  13. link "Help centre"  <a line 78>

## addressability
   score 100/100  (13 of 13 focus stops uniquely addressable)

2. What the "cleaner checkout" redesign did to it

examples/checkout_after.html is pixel-for-pixel identical: same fields, same order, same copy. A screenshot diff shows nothing. Here is the non-visual diff:

$ python main.py diff examples/checkout_before.html examples/checkout_after.html

[CRITICAL] FOC04  Focusable element stranded inside a hidden subtree
            where: <button> (line 96)
            button "Close" is now inside a hidden subtree yet still focusable:
            keyboard focus disappears into content no one can perceive.

[CRITICAL] NAM01  Interactive control lost its accessible name
            where: button (unnamed) <button> (line 76)
            The button previously announced as "Apply promo code" now has no
            accessible name at all.

[MAJOR   ] AGT01  Duplicate role+name makes a control ambiguous to agents
            where: link "Edit" (line 38)
            2 controls now share the identity link "Edit". A role+name selector —
            the way both screen-reader users and browser agents target controls —
            can no longer pick the right one.

[MAJOR   ] FOC02  Focus order changed
            Tab stop 1 used to be link "Acme Supply home" and is now
            button "Continue to payment".

[MAJOR   ] FOC03  Positive tabindex introduced; focus order now diverges from DOM order
[MAJOR   ] NAM02  Accessible name of an interactive control changed
            Announced as "Edit cart" before, "Edit" now.
[MAJOR   ] NAM03  Accessible name source degraded to a fragile source
            Name now comes from placeholder instead of label-element.
[MAJOR   ] NAM04  Informative image lost its alternative text
[MAJOR   ] STA01  Announced state was dropped
            The 'required' state (True) is no longer announced.
[MAJOR   ] STR03  Heading removed from the accessibility tree
            where: heading "Delivery address" <h2> [baseline] (line 34)
[MAJOR   ] STR04  Landmark removed from the accessibility tree
            where: navigation "Checkout steps" <nav> [baseline] (line 11)
[MINOR   ] AGT03  Addressability dropped from 100/100 to 79/100.
[MINOR   ] NAM05  Accessible description "We only use this to send your receipt." was removed.
[INFO    ] FOC05  A new keyboard stop appeared: link "Edit".
[INFO    ] STR06  A new link is exposed to assistive technology.

score 0/100  grade F   critical=2  major=9  minor=2  info=2

Twelve regressions, every one invisible to a visual review, every one a true positive. Running the diff in reverse (after → before) reports the same changes as improvements — zero criticals, STA03 for required returning, STR06 for the heading and landmark coming back.

3. The addressability view — the agent's half of the story

$ python main.py render examples/checkout_after.html | tail -6
## addressability
   score 79/100  (11 of 14 focus stops uniquely addressable)
   - unaddressable: button <button line 76>
   - ambiguous: 2 x link "Edit" (lines 38, 67)
   - fragile name: textbox "Email address" from placeholder <line 47>

Three controls an agent asked to "apply the promo code" or "edit the delivery address" cannot reliably reach — and three controls a screen-reader user cannot either. Same defect, same fix, one report.

4. As a CI gate

- name: Fail on CRITICAL non-visual regressions
  run: python main.py diff baseline/checkout.html dist/checkout.html --fail-on critical

See .github/workflows/ci.yml.


Architecture

HTML file
   │
   ├─ htmlparse.py   tolerant DOM builder on html.parser
   │                 (void elements, implied end tags, first-attribute-wins,
   │                  line numbers, id index)
   │
   ├─ roles.py       HTML-AAM implicit roles + the ARIA vocabularies
   ├─ visibility.py  static hidden/aria-hidden/display:none rules
   ├─ accname.py     accname 1.2 — and, crucially, the NAME SOURCE
   │
   ├─ tree.py        accessibility tree + announced state + set positions
   │                 + focus order (positive tabindex, stranded focusables)
   │        │
   │        ├─ transcript.py  → the readable .earshot artefact / JSON
   │        ├─ reach.py       → addressability: unnamed & ambiguous controls
   │        ├─ audit.py       → 12 single-document rules
   │        └─ diff.py        → two-pass alignment + 27 graded diff rules
   │
   └─ findings.py    severity model, weights, score, grade
       cli.py        commands and exit codes

Data flow. Parse → role-map → name (with source) → tree + states + focus order → either render a transcript, or run single-document rules, or align against a second tree and run the graded diff rules. Nothing is cached, nothing is stateful, every stage is a pure function of its input.

The two design decisions worth explaining

1. Alignment: positional comparison vs. keyed two-pass alignment.

The hard part of diffing accessibility trees is deciding which node in the new page is which node in the old one. A redesign moves, rewraps and renames things, so a positional walk reports the whole page as removed-and-added.

  • Considered: compare the two flattened transcripts line by line, like a text diff. Trivial to implement, near-zero memory, and useless in practice — wrapping one button in a <div> shifts nothing semantically but resynchronises the whole file.
  • Chosen: a two-pass alignment. Pass one runs an LCS over stable node keys (role|name when the node is named, role|@dom-path otherwise) to establish anchors; named nodes survive markup refactors, so the anchors are robust. Pass two pairs leftovers inside each anchor gap greedily by role. A third pass pairs any remaining removals and additions that share an exact key, recovering moves as reading-order changes rather than as a deletion plus an unrelated insertion. Cost: O(n·m) time and memory for the LCS table. For a 500-node page that is a 250k-cell table — microseconds. Beyond a 4M-cell budget it degrades to a linear first-match-wins pairing, which loses some move detection but never hangs. Payoff: this is what turns "button "Apply promo code" disappeared" plus "button (unnamed) appeared" into the one finding that is actually true: that button lost its accessible name. Without pass two, the single most important defect class in the tool reports as two unrelated INFO-grade events.

2. Grading: snapshot equality vs. a severity-weighted rule catalogue.

  • Considered: golden-file equality, the way Playwright aria-snapshots and @guidepup/jest work. Almost free to maintain — but a page's copy changes every sprint, so the gate fails constantly, and the muscle memory becomes "regenerate the baseline" without reading the diff. The one time it mattered, it is skimmed with everything else.
  • Chosen: 39 rules across six families, each with a fixed severity (CRITICAL 25 / MAJOR 8 / MINOR 2 / INFO 0 penalty points), a --fail-on threshold, and a 0–100 score with a letter grade. Cost: real maintenance — someone has to decide and defend each severity, and the catalogue has to grow deliberately rather than automatically. Payoff: the gate can sit at critical and stay green through normal copy churn, while still stopping the four things that genuinely break the page for a non-visual user: a control losing its name, a control leaving the tab order, focus being stranded in an aria-hidden subtree, and a new unnamed control shipping. A gate that is never spuriously red is a gate people keep.

Rule families

Prefix Family Rules Catches
NAM naming 7 name loss, name change, name-source degradation, alt loss, description loss
STR structure 9 role change, heading level/removal, landmark removal, reading-order moves
FOC keyboard 5 left the tab order, order changed, positive tabindex, stranded focusable
STA state 3 required/invalid/expanded/checked… dropped or changed
AGT addressability 3 duplicate role+name, new unnamed control, score drop
AUD single page 12 the decidable defects in one document, no baseline needed

NAM03 (name-source degradation) is the family's quiet star and is, as far as this research found, not implemented anywhere else: a control named by a <label> and the same control named by a placeholder produce an identical accessible name, and an identical snapshot — but the placeholder disappears the moment the user types and several assistive-technology configurations ignore it entirely. Snapshot equality cannot see this regression. earshot tracks the provenance of every name and ranks the sources, so it can.

Assumptions & limitations

Stated plainly, because a compliance-adjacent tool that overstates its reach is worse than no tool.

  1. Static markup only. No JavaScript is executed. earshot sees what the server sends. For a client-rendered app, point it at prerendered or server-rendered HTML (or at a saved DOM snapshot) — the analysis is identical, the capture is your build's job.
  2. No CSS. Only inline display:none / visibility:hidden are honoured. Content hidden by an external stylesheet, off-screen clipping (.sr-only), content-visibility, and every CSS-driven order/flex-direction reordering are invisible to earshot. It therefore cannot check colour contrast, visible focus indicators, reflow, or target size.
  3. Roles are a pragmatic HTML-AAM subset, covering the elements that appear in shipped product UI. Unmapped elements become generic (transparent: their children still count). Known deliberate deviations: input[type=password] is mapped to textbox although HTML-AAM assigns it no role; <dl>/<dt>/<dd> are mapped to list/term/definition; <summary> is mapped to button. Each makes the transcript more useful and none changes a diff verdict.
  4. aria-owns and aria-activedescendant are not followed, so the tree reflects DOM containment. Composite widgets that reparent via aria-owns will be described in their DOM position.
  5. Focus order models the tab sequence, not roving tabindex. A composite widget that manages arrow-key focus internally appears as one stop, which is what a Tab press actually does — but earshot says nothing about whether the arrow-key model inside it is correct.
  6. This is not a WCAG conformance checker and does not claim to be one. The AUD family is deliberately small and covers only what is fully decidable from markup. It will never tell you whether alt text is meaningful, whether a heading is accurate, or whether a flow is usable. The European Commission's position — that no automated tool can establish conformance — applies here too. earshot is a regression instrument and a review artefact.
  7. The addressability score is a heuristic, not a guarantee. It measures whether each keyboard stop is uniquely identifiable by role + accessible name, which is how the agent frameworks surveyed actually select elements. An agent may still fail for reasons earshot cannot see.
  8. Severity weights are a judgement call. They are all in one table in findings.py; disagree with them and edit them.
  9. Duplicate ids resolve first-wins, matching getElementById. earshot reports the ones that participate in name resolution (AUD10) rather than guessing which the browser meant.
  10. Encoding. Input is decoded as UTF-8 with replacement; a BOM is stripped. Transcripts are written with \n endings on every platform so baselines are diffable across machines.

Tests

310 tests, standard-library unittest, no dependencies, sub-second.

$ make test
Ran 310 tests in 0.550s
OK

Coverage by area: the DOM builder's recovery rules; the full accname priority chain including aria-labelledby recursion, self-reference and cycles; role mapping including context-sensitive header/footer/section/form and th scope inference; tree pruning, announced state and set positions; focus order including positive/negative tabindex, disabled controls and stranded focusables; every diff rule; every audit rule; the CLI's exit codes and JSON shapes; ground truth over the example pair (tests/test_examples.py maps each planted defect to the rule that must catch it, and asserts that no other rule fires); and a robustness suite that feeds malformed markup, degenerate shapes and seeded random tag soup through every stage — including the invariant that diffing any document against itself must be silent, which is what found and killed a false-positive AGT02 during development.

License

MIT — see LICENSE.


Development Experiment 050 of the dev-experiments-365 series. Built 2026-09-19. Research notes and sources: RESEARCH.md.

About

earshot - offline, browser-free renderer and severity-graded differ for a web page's non-visual projection: the screen-reader announcement transcript, keyboard focus order, and the role+name surface AI browser agents target. Pure stdlib Python, 39 graded rules, CI exit-code gate, 310 tests.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages