Skip to content

feat(rules): thirteen schema/entity-* rules over the entity map with rule docs (#2093) - #338

Merged
nc9 merged 5 commits into
mainfrom
feat/2093-entity-rules
Sep 13, 2026
Merged

nc9 merged 5 commits into
mainfrom
feat/2093-entity-rules

Conversation

@nc9

@nc9 nc9 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Thirteen site-level rules that read the entity map (squirrelscan/repo#2093, epic #2061 section 6), plus the @graph flattening fix they depend on.

Closes #317

Why these are site-level

A structured-data validator checks one page. That is the wrong unit for the expensive failures.

Sixty pages can each carry a perfectly valid Organization block, and if none of them says they are the same organization then a search engine has sixty companies and no reason to connect them. Nothing accumulates: not the reviews, not the profile links, not the authority of the articles. Every per-page check passes.

These thirteen read the whole graph instead.

Rule Severity Fires when
entity-identity error An Organization, LocalBusiness, Person or WebSite is on many pages with no @id
entity-split-identity error One entity under two or more @ids, typically two plugins
entity-dangling error A reference resolves to nothing declared on any crawled page
entity-conflicts warning One entity's name, logo, url, sameAs, phone, address or email differs between pages
entity-id-format warning An @id that is not an absolute URL
entity-type-drift warning One @id declared with different @type sets
entity-authors warning Bylines with no Person, or a Person with no url and no sameAs
entity-publisher-mismatch warning Pages that name different publishers
entity-local-business-per-page warning A LocalBusiness redeclared on nearly every page
entity-website-missing info No WebSite node, or page entities with no isPartOf
entity-organization-missing info A site that presents as a business with no organization entity
entity-sameas-missing info A primary organization with no sameAs
entity-orphan info An @id nothing references, on one page

Two conventions all thirteen share

One capped check each, never a finding per entity. A site that redeclares its organization on 500 pages has one problem, not 500, and the schema category score must not be dominated by whichever rule matched the most nodes. The canonical golden moved by exactly +13 findings, which is the proof.

A missing map is a skip, never a pass. ctx.entityMap is undefined both for a run that built no map and for a site with no structured data. Passing would assert the rule had checked something it never looked at, so it skips with entity-map-unavailable and the empty-map case is reported separately at info.

The builder had to remember one more thing

entity-type-drift asks whether an @id is declared with different @type sets on different pages. The builder unions types across occurrences, which is correct for every consumer and erases exactly that: the merged node simply has both types.

Each occurrence's own sorted type set is now recorded and surfaced as a @type conflict. A conflict's property is already a free string, so this is additive to a v1 document rather than a shape change, and entity-conflicts excludes @type so one defect is never billed to two rules.

Issue #317, as the first commit

Yoast, Rank Math and Slim SEO emit one script containing {"@context":…,"@graph":[…]}, which is most of the WordPress web. Seven rules parsed each script and then did Array.isArray(data) ? data : [data], so the wrapper was the only node they saw and they reported correct markup as missing.

The fix was smaller than the issue implies: flattenJsonLdNodes already exists in the utils package and schema/local-business already uses it. The seven now go through it, flattened per script rather than over the joined schema.raw, because that join can mis-split a pretty-printed block. The test asserts each rule produces the same verdict from @graph markup as from equivalent flat markup, and it is verified falsifiable by reverting one rule.

Verified against three real crawls

Committed as fixtures, and the acceptance criteria are pinned as tests:

  • entity-identity fires on squirrelscan.com, where our own Organization is declared on all 60 crawled pages with no @id.
  • entity-split-identity fires on kinsta.com, where WordLift's data.wordlift.io identifier and Yoast's #organization each declare "Kinsta", on 36 and 39 pages.

One acceptance criterion is wrong and the test records the correction. It names entity-identity for wollongongservicecompany.com.au, with the parenthetical "Organization / LocalBusiness redeclared on every page with no @id". That site's LocalBusiness carries an absolute @id on all 60 pages, so nothing there can match. The defect is real and entity-local-business-per-page is the rule for it. The test asserts both: that entity-identity is silent, and that the other fires at 100% of crawled pages.

Tuning came from the same data rather than from taste. entity-orphan reported 79 entities on the 40-page kinsta crawl before articles and breadcrumbs were excluded, 73 of which were the site's own pages. That is a page count, not a finding.

Docs

Thirteen rule pages on the search-first template, each quoting the message templates with their placeholders rather than a filled example. Plus /entity-map and /entity-map/fixing, because every rule's fix text links to the second and shipping thirteen rules that point at a 404 is not shipping them. The remaining four entity-map/* pages the epic plans stay for the docs issue.

A script checks each page's rule id, severity, weight, scope and both toml blocks against the rule's own metadata, and every message literal in the rule source against the page text. All thirteen agree.

What the review pass changed

A full adversarial codex exec pass over the rules and the doc pages, asked specifically to name a realistic site whose markup is correct and on which each rule would nonetheless fire. That question found six false positives that reading the code did not, and one crash.

The crash came from #317. flattenJsonLdNodes follows @graph with no depth bound, so '{"@graph":'.repeat(40000) parses fine and then overflows the stack. Routing seven more rules through it widened the blast radius from one caller to eight. Bounded at 64 levels.

The false positives, each a different shape of wrong:

  • A same name is not a same thing. entity-split-identity matched on type set and name, which reports two different authors called John Smith as one entity. It now requires them to be declared on a common page, which two plugins describing one organization always are and two different people never are.
  • An even split is a design, not drift. entity-publisher-mismatch warned on any disagreement, which warns a syndicating news site about its architecture. Below 80% dominance it drops to info.
  • A pointer meant to leave the site. A sameAs naming Wikidata was reported as a broken reference. That is the entire purpose of sameAs.
  • Absolute is not the same as stable. urn:isbn: warned. It is unique, stable and identical on every page, which is exactly what the rule wants.
  • An Organization can be the author. Google's Article guidance says so. The rule also judged every Person on the site, including biography subjects, who make no claim to expertise on the site's behalf.
  • Suffix matching for a type hierarchy is wrong in both directions. It missed BankOrCreditUnion and Dentist and accepted OnlineStore, which has no premises.

Plus two unbounded strings. The ten-item cap does not bound value, so a map with 2,000 same-named entities produced a 412,000-character summary line. Now clipped at 300, with a test asserting it for all thirteen.

35 doc corrections. The load-bearing ones: every page told the reader to run squirrel entities --problem with no argument, which is a usage error; Google retired the sitelinks search box in November 2024; Rank Math's Local SEO is under Titles and Meta; and adding a sameAs does not resolve a split identity, because both organizations are still declared. Several claims I could not support are gone, including "the single most common reason" and a requirement that sameAs name only profiles you control, which is the opposite of what it is for.

One disagreement I did not act on. The review argued entity-local-business-per-page should not warn on consistent markup. The epic asks for it and the rationale holds, that repetition is what causes the drift entity-conflicts reports, so it stays at warning with a message that says what the site does rather than claiming the markup is invalid.

Verification

  • tsgo --noEmit clean in core-contracts, rules, report, crawler, audit-engine and cli
  • 2402 rules tests pass, and the audit-engine suite
  • oxfmt and oxlint clean on apps/cli
  • make validate clean in docs/, 409 pages
  • 181 internal doc links checked against the filesystem, 0 dead. tangly check --strict does not catch a dead /rules/ link, so this is checked separately
  • A script checks each doc page's rule id, severity, weight, scope and both toml blocks against the rule's own metadata, and every message literal in the rule source against the page text. It caught a message I had added and not documented, in a file I had just read
  • Rule tally 282 to 295, findings 99721 to 99734 in the canonical golden

https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP

nc9 added 5 commits September 13, 2026 14:44
Yoast, Rank Math and Slim SEO emit one script containing
`{"@context":…,"@graph":[…]}`, which is most of the WordPress web. Seven rules
parsed each script and then did `Array.isArray(data) ? data : [data]`, so the
wrapper was the only node they ever saw and they reported correct markup as
missing: `No Organization schema found` on a page that declares one.

They now go through `flattenJsonLdNodes`, the shared helper in the utils
package that `schema/local-business` and the entity-map builder already use.
Flattened per SCRIPT rather than over the joined `schema.raw`, because that
join can mis-split a pretty-printed block (#1099). The helper returns an empty
list for unparseable input, so the try/catch it replaced is gone.

The test is one fixture read by all seven rather than seven fixtures, because
the defect was a copied idiom and the value is proving none of them still
carries it. It asserts the stronger property too: each rule produces the SAME
verdict from `@graph` markup as from the equivalent flat markup, so a rule that
found the node and then read it differently would not pass. Verified
falsifiable by reverting one rule, which fails it.

Both engine goldens are unchanged: the synthetic corpus carries no `@graph`
markup, so nothing in them moves.

The doc pages described the defect as a known false positive and told readers
to check their markup before adding a second block. That advice is now wrong,
so it is replaced rather than deleted.

Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP
Signed-off-by: Nik Cubrilovic <[email protected]>
Adds `entityMap` to `RuleContext` and `RunnerScope`, following `intel` exactly:
resolved by the engine before rules run so the rules stay synchronous and pure,
and held as per-run immutable state on the runner so concurrent audits in one
isolate cannot share it.

It cannot come from `ctx.siteQuery`. That streams typed columns off
`page_features` and never exposes raw JSON-LD, so the questions the entity rules
ask, is this the same Organization and does this `@id` resolve, are not
answerable from it.

Threaded into the SITE context only, deliberately. Every entity rule is
site-scope, and the per-page rule cache keys a page rule's inputs without
knowing about the entity map, so a page rule that read it would be replayed from
a cache entry that never accounted for it. Withholding it makes that a type
error rather than a silent stale result.

Both engine adapter sites already spread `scope`, so nothing there changes.

`squirrel audit` and `squirrel analyze` now build the map BEFORE the rules phase
rather than after the report. For audit this is a move, not extra work: the
collector finished absorbing during the pre-rules walk, so it sees the same
pages either way. For analyze the site context is already resident. Both degrade
to undefined on a build failure rather than losing a finished audit, and
undefined means "no map was built", which the rules must not confuse with "this
site declares nothing".

Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP
Signed-off-by: Nik Cubrilovic <[email protected]>
Thirteen site-level rules that read the entity map rather than the pages,
because the failures they describe are not visible one page at a time. Sixty
valid Organization blocks with nothing to say they are one organization pass
every per-page check and still leave a search engine with sixty companies.

Two conventions all thirteen share. ONE capped check each, not a finding per
entity: a site that redeclares its organization on 500 pages has one problem,
and the schema category score must not be dominated by whichever rule matched
the most nodes. And a missing map is a SKIP, never a pass: `ctx.entityMap` is
undefined both for a run that built no map and for a site with no structured
data, and asserting the site is clean would claim a check that never happened.

One rule needed the map to remember more than it did. `schema/entity-type-drift`
asks whether an `@id` is declared with different `@type` sets on different
pages, and the builder unions types across occurrences, which is right for every
consumer and erases exactly that. Each occurrence's own sorted type set is now
recorded and surfaced as a `@type` conflict. A conflict's `property` is already
a free string, so this is additive to a v1 document rather than a shape change,
and `schema/entity-conflicts` excludes `@type` so one defect is never billed to
two rules.

Verified against three real crawls, committed as fixtures. `entity-identity`
fires on squirrelscan.com, where our own Organization is on all 60 pages with no
`@id`. `entity-split-identity` fires on kinsta.com, where WordLift and Yoast
each declare "Kinsta" under their own id, on 36 and 39 pages.

The issue's acceptance criteria also name `entity-identity` for
wollongongservicecompany.com.au. It does not fire there and cannot: that site's
LocalBusiness carries an absolute `@id` on all 60 pages. The defect is real and
`entity-local-business-per-page` is the rule for it, so that is what the test
asserts. Both verdicts are pinned, including the silence.

Tuning came from the same data rather than from taste. `entity-orphan` reported
79 entities on a 40-page kinsta crawl before articles and breadcrumbs were
excluded, 73 of which were the site's own pages: that is a page count, not a
finding.

Rule tally 282 to 295 and findings 99721 to 99734 in the canonical golden, which
is exactly +13 — proof that every rule emits a single capped check.

Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP
Signed-off-by: Nik Cubrilovic <[email protected]>
…lisher disagreement (#2093)

Two false positives a review pass surfaced, both on rules that speak about the
whole site and so cost the most when wrong.

`entity-split-identity` matched on a shared type set and a shared name alone.
A large publisher can have two different authors called John Smith, each
correctly given an `@id`, and calling that an error would be worse than saying
nothing. It now additionally requires the two to be declared TOGETHER on a page.
That is what separates them: two plugins describing one organization always emit
on the same pages, and on the committed kinsta.com crawl the WordLift and Yoast
declarations share all 36 pages either appears on. Two different people written
about in different places never do.

`entity-publisher-mismatch` warned on any disagreement. A syndicating news site
or a multi-brand publisher legitimately names several publishers, and warning
about that is warning about someone's architecture. Drift has a shape: a clear
majority and a few strays. Below 80% dominance the finding drops to info and
describes the distribution instead of asserting a defect.

Also fixes a regex CodeQL was right about in the #317 test: in `^A|B` the
anchor binds only the first branch, so `not found` matched anywhere in a
message rather than as an absence claim. Split into two explicit tests, and
re-verified falsifiable by reverting one rule.

Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP
Signed-off-by: Nik Cubrilovic <[email protected]>
…review pass (#2093)

A full adversarial review of the thirteen rules and their doc pages. The
findings were good and most of them were right.

The serious one is a crash I introduced with #317. `flattenJsonLdNodes` follows
`@graph` recursively with no depth bound, and the seven rules now routed through
it inherit that. `'{"@graph":'.repeat(40000)` parses fine and then blows the
stack, taking the rule down with it. Nesting is chosen by the audited page, so
it needs a bound: 64, far past anything a generator emits and far short of the
stack.

FALSE POSITIVES, all on rules that speak about the whole site.

- `entity-dangling` reported a `sameAs` pointing at Wikidata as a broken
  reference. Naming an external authority is the entire purpose of `sameAs` and
  the target will never be declared locally, so reporting it was advice to
  remove the most useful line in an organization block.
- `entity-id-format` warned on `urn:isbn:9780140328721`. A URN is unique, stable
  and the same on every page, which is exactly what the rule wants. It now
  accepts the global identifier schemes and still rejects `mailto:`, which is a
  way to contact a thing rather than a name for it.
- `entity-authors` demanded a `Person` when an `Organization` was the author.
  Google's Article guidance supports organizational authors explicitly. It also
  judged every `Person` on the site, including biography subjects, who make no
  claim to expertise on the site's behalf.
- `entity-organization-missing` told a personal site to declare a company,
  because a personal site has an about page too. A named `Person` and no
  commerce is now left alone.
- `entity-orphan` reported product, event and recipe nodes. A product detail
  page IS the product; expecting another node to reference it is backwards.
- `isLocalBusinessType` matched on suffixes, which is wrong in both directions:
  it missed `BankOrCreditUnion` and `Dentist`, and accepted `OnlineStore`, which
  has no premises. Replaced with the schema.org subtype list.

Two unbounded strings. Every rule's `value` is built from site-controlled text
and was not covered by the ten-item cap, so a map with 2,000 same-named entities
produced a 412,000-character summary line beside a ten-item list. Now clipped at
300, with a test that asserts it for all thirteen.

And the type-set key was joined with ", ", so a site could declare `["A, B"]`
and `["A","B"]` and have a real disagreement go unrecorded. `JSON.stringify` of
the sorted set, for the same reason every other composite key in this feature
uses it.

35 doc corrections. The load-bearing ones: every page told the reader to run
`squirrel entities --problem` with no argument, which is a usage error, and only
five of the thirteen have a matching filter. The sitelinks search box was
retired by Google in November 2024. Rank Math's Local SEO lives under Titles and
Meta. Adding a `sameAs` does NOT resolve a split identity, because both
organizations are still declared. Plus several claims I could not support and
should not have made, including "the single most common reason" and a
requirement that `sameAs` name only profiles you control, which is the opposite
of what it is for.

`entity-local-business-per-page` stays at warning. The review argued consistent
markup should not be warned on; the epic asks for it and the rationale holds,
that repetition is what causes the drift `entity-conflicts` reports. The message
says what the site does rather than claiming the markup is invalid.

Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP
Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the feat/2093-entity-rules branch from c3950a1 to 8647493 Compare September 13, 2026 04:44
@nc9
nc9 merged commit 070598c into main Sep 13, 2026
14 checks passed
@nc9
nc9 deleted the feat/2093-entity-rules branch September 13, 2026 04:52
nc9 added a commit that referenced this pull request Sep 13, 2026
Completes the Entity map group: index and fixing from #338, mcp from #342, and
now the three that were missing.

**cli.mdx** — where the map appears in each of the six report formats and what
each one actually carries, `squirrel entities` with every flag and format, the
diff, and the three store tables with the queries worth knowing. The one worth
calling out is `entity_occurrences`: a node's `pages` array is capped at 50, so
"every page that declares this Organization" is answerable from that table or
from the document's own uncapped page index, and never from the node.

**format.mdx** — the version 1 document, the JSON-LD export and the change set,
with a real sample of each from an audit of docs.squirrelscan.com. Covers the
four key shapes, what can and cannot dangle, and why `coverage` on a gainedId
row needs both of its halves.

**cloud.mdx** — the dashboard Entities page, its filters and exports, and the
two API endpoints. Two differences from the local behaviour are documented
rather than left to be discovered: the API's `page` filter is a prefix match
where the CLI's is a substring match, and a filtered API response keeps a
whole-site `summary` with the filtered totals in `meta.counts`, which is the
opposite of what `squirrel entities` returns.

Also corrects `--page`'s own help text, which claimed a prefix match. It has
always been a substring match.

Every page cross-links the others. `make validate` passes, and a filesystem
link check over all 2,785 internal links finds none dead in this group.

Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP
Signed-off-by: Nik Cubrilovic <[email protected]>
nc9 added a commit that referenced this pull request Sep 13, 2026
* docs(entity-map): cli, format and cloud pages (#2098)

Completes the Entity map group: index and fixing from #338, mcp from #342, and
now the three that were missing.

**cli.mdx** — where the map appears in each of the six report formats and what
each one actually carries, `squirrel entities` with every flag and format, the
diff, and the three store tables with the queries worth knowing. The one worth
calling out is `entity_occurrences`: a node's `pages` array is capped at 50, so
"every page that declares this Organization" is answerable from that table or
from the document's own uncapped page index, and never from the node.

**format.mdx** — the version 1 document, the JSON-LD export and the change set,
with a real sample of each from an audit of docs.squirrelscan.com. Covers the
four key shapes, what can and cannot dangle, and why `coverage` on a gainedId
row needs both of its halves.

**cloud.mdx** — the dashboard Entities page, its filters and exports, and the
two API endpoints. Two differences from the local behaviour are documented
rather than left to be discovered: the API's `page` filter is a prefix match
where the CLI's is a substring match, and a filtered API response keeps a
whole-site `summary` with the filtered totals in `meta.counts`, which is the
opposite of what `squirrel entities` returns.

Also corrects `--page`'s own help text, which claimed a prefix match. It has
always been a substring match.

Every page cross-links the others. `make validate` passes, and a filesystem
link check over all 2,785 internal links finds none dead in this group.

Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP
Signed-off-by: Nik Cubrilovic <[email protected]>

* fix(cli): --page matches a substring, not a prefix

The flag's help text has always said "matching this URL or prefix". The
implementation calls `String.includes`, so `--page /blog` matches
`/tag/blog` too. Say what it does.

Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP
Signed-off-by: Nik Cubrilovic <[email protected]>

---------

Signed-off-by: Nik Cubrilovic <[email protected]>
nc9 added a commit that referenced this pull request Sep 13, 2026
The thirteen schema/entity-* rules in #338 moved the totals. `docs/index.mdx`
was updated with them; two other hard-coded counts were not, and disagree with
the rule registry:

- rules/seo/index.mdx: the Structured Data card said 12 rules, live is 25
- agent-setup/index.mdx: the agent fact said 282 rules, live is 295

Both are asserted against `loadAllRules()` by a test in the private monorepo, so
they block a gitlink bump rather than failing anything here.

`make validate` passes.

Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9 nc9 mentioned this pull request Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rules(schema): seven schema rules do not read JSON-LD nested in @graph, so Yoast-style markup reports as missing

2 participants