Repository navigation
feat(cli): squirrel entities command with filters, export formats and --diff (#2092) - #336
Merged
Merged
Conversation
Contributor
Author
|
Follow-up filed as squirrelscan/repo#2105: three fields a map reassembled from the project store cannot recover exactly (a page's declaration count and references, an edge's pages), plus the fact that the store does not record whether an audit wrote a map at all. None is load-bearing here, and this PR documents each as an approximation rather than emitting a plausible number. Fixing them needs an additive migration to tables #2091 had only just shipped, which seemed worth separating from this change. |
… --diff (#2092) Queries the entity map every audit already builds (#2091), shaped like `squirrel report`: a summary with no arguments, `--list` over stored audits, and a lookup by `@id`, key or name. `--type`, `--page` and `--problem` produce a filtered MAP rather than a filtered view, so `-f graphml --type Organization` hands a graph tool the filtered graph and the summary counts describe what survived. Adds csv, dot, graphml and mermaid renderers beside the existing json, jsonld, html and markdown. Each escapes for its own parser: RFC 4180 quoting plus a formula-injection guard for csv, XML character-range filtering for graphml, and label sanitisation with quoted edge labels for mermaid, which is capped at 150 nodes with a comment saying so. `--diff` compares two audits via a new `diffEntityMaps` in the engine. The property it exists to protect is that a smaller crawl never reads as a site that deleted its structured data: an entity is only `removed` when every page that declared it was crawled again, proven from the uncapped per-page index rather than the node's capped sample, and anything unproven is reported as not crawled. Conflicts and dangling references are only called resolved on the same terms. Identity matching across an `@id` change is one-to-one and refuses to pair an ambiguous group. Exits 0 on every path that produced an answer, including a site that declares no JSON-LD. That is a finding, not a failure. Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP Signed-off-by: Nik Cubrilovic <[email protected]>
…to read (#2092) Two defects from a second review pass. `--page` chose between the per-page index and the node's own list. Each is incomplete in a different way — the index is absent from a clipped export, the node's list is truncated past 50 pages — so picking one drops entities that are genuinely on the page. Take the union; neither source can lose anything the other has. `loadEntityMap` reported an unreadable project store only when NO project produced a map. Returning project A's map while project B was unreadable is an answer drawn from part of the data, so carry the failures back and say so. Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP Signed-off-by: Nik Cubrilovic <[email protected]>
A store that could not be READ exited 0 and printed its error to stdout, the same way "no audit stored yet" does. Those call for opposite next steps, so a script could take a broken database for an empty one. Only the not-found case is an answer now; a read failure exits 1 on stderr. A skipped empty crawl was remembered per project, but auto-selection picks the newest map across every project, so the audit it passed over routinely belongs to another site and the note never appeared. Pool the skips and report the newest one that is actually newer than what is being shown. `--diff` looked for the same-site predecessor inside the 50 most recent audits. That window is global and ordered by time, so 50 audits of a busy site bury a quiet site's previous audit past the end and the command claims it has only one. `listEntityMaps` now takes a `baseUrl` that narrows BEFORE the limit. `-o` wrote whatever `fmt` produced, and `fmt` decides on colour from whether stdout is a TTY. Right question for stdout, wrong one for a file: run from a terminal, the entity and list views wrote escape bytes into it. Strip them in `emit`, which is the one place that knows the destination is a file. Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP Signed-off-by: Nik Cubrilovic <[email protected]>
A listing reads the entity rows of every crawl in every project. With two crawl ids given, nothing in it was used. Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP Signed-off-by: Nik Cubrilovic <[email protected]>
…own count (#2092) The index is authoritative for coverage only when it accounts for every page the node claims, `morePages` included. The two disagree only in a document someone assembled by hand, and there the conservative answer is the right one. Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP Signed-off-by: Nik Cubrilovic <[email protected]>
…n empty audit (#2092) `toLocaleString()` runs to 21 characters on a 12-hour clock, so the 22-wide Date column ran straight into Pages. An audit with no entities is skipped as the older side of a default diff on purpose: the store cannot tell "this site declared nothing" from "this audit predates the entity map", and reading the second as the first turns every entity the site has today into a fresh addition. The message now names the escape hatch for when the user knows which it was. Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP Signed-off-by: Nik Cubrilovic <[email protected]>
…rm (#2092) `BASH_BLOCK_END` names the case arm that ends each command's bash completion block, because those blocks contain nested `;;` of their own. Inserting `entities)` between `audit)` and `crawl)` made the audit block over-read into it, and the test failed on `--list`, a flag audit never offered. Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
feat/2092-entities-command
branch
from
September 13, 2026 03:28
5d9383a to
04494d8
Compare
This was referenced Sep 13, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
squirrel entities(squirrelscan/repo#2092, epic #2061 sections 5 and 9) on top of the entity map that #333 made every audit build.The command
Shaped like
squirrel report: same flag names, same project-scoped store access, same--inputescape hatch.squirrel entitiessquirrel entities <@id|key|name>squirrel entities --list@idsharesquirrel entities --diff--type,--pageand--problemproduce a filtered map, not a filtered view, so-f graphml --type Organizationhands a graph tool the filtered graph and the summary counts describe what survived rather than the whole site.--problemacceptsno-id,conflict,dangling,single-pageandsplit-identity.Exit code is 0 on every path that produced an answer, including a site that declares no JSON-LD at all. That is a finding, not a failure. Only a usage mistake or an unreadable store exits 1.
Export formats
csv,dot,graphmlandmermaidjoin the existingjson,jsonld,htmlandmarkdown, all inpackages/reportbeside the renderers they sit with.Every string in a map comes from an audited page, so each renderer escapes for its own parser rather than sharing one escape: RFC 4180 quoting plus a leading-quote guard against spreadsheet formula injection for csv, backslash escaping for dot, XML 1.0 character-range filtering (control bytes, U+FFFE/U+FFFF and unpaired surrogates are dropped, not escaped, because
is itself invalid) for graphml, and label sanitisation with quoted edge labels for mermaid. Mermaid stops rendering usefully past a few hundred nodes, so it draws the 150 most-declared and says so in a comment.--diffNew
diffEntityMapsin the engine, exported from the@squirrelscan/audit-engine/entity-mapsubpath.The property it exists to protect: two audits of a site rarely cover the same pages, and a naive set difference reports every entity on a page that simply was not visited as removed, which reads as "the site deleted its structured data". So an entity is only removed when every page that declared it was crawled again, and everything else lands in not crawled again.
Proving that is the subtle part. A node's
pagesis capped at 50 in the document withmorePagescounting the rest, so deciding on the sample calls a 101-page entity removed the moment the first 50 are recrawled. Coverage is therefore taken from the uncapped per-pagedeclaresindex, and only when that index is itself complete (a publish projection clips it, which the crawl's own page count detects). Where coverage cannot be proven, the answer is not-crawled: conservative, says less, never the reverse.The same rule governs fixes. A conflict or dangling reference counts as resolved only when the entity survived and all of its declaring pages were visited again, because a conflict needs two declarations to exist and seeing one of them tells you nothing.
Identity matching across an
@idchange pairs one-to-one: a group of same-named candidates is only matched when exactly one unmatched candidate exists on each side, so an ambiguous group falls through to added/removed rather than inventing a rename and a deletion at once. Signatures areJSON.stringify([sortedTypes, name]), never a delimiter join, since@typeis site-controlled.Review
Two
codex execpasses over the non-test diff. The first found 16 correctness issues, the second confirmed 12 of those fixes and found the remaining 4 gaps plus one new defect. All are now fixed, with tests for the ones that were behavioural.The load-bearing ones:
getCrawlPageUrlsused request URLs and every status where the collector uses final URLs and 2xx only, so a redirect became a page no entity row could name.backfillDerivedFieldsrepaired present-but-invalid values into a document that then validated. Absent means an older build did not write the field; present-and-invalid means the file is broken.--difflooked for the same-site predecessor inside the 50 most recent audits, but that window is global and ordered by time, so a busy site buried a quiet site's previous audit.-owrote whateverfmtproduced, andfmtdecides colour from whether stdout is a TTY. Run from a terminal, the entity and list views wrote escape bytes into the file.Verification
tsgo --noEmitclean in core-contracts, report, crawler, audit-engine and clioxfmtandoxlintclean onapps/climake validateclean indocs/(394 pages, no broken links)--listcolumn overflow and the empty-older-side case surfaced.Docs
New
/cli/entitiesreference page, added to the CLI nav and the command table.Closes squirrelscan/repo#2092
https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP