feat(viewer): add template cluster analysis view#233
Merged
Conversation
Adds listPageTemplateClusters and its supporting helpers to compute a human-readable summary (page count, common directory, common stylesheet set/filenames) for each page_templates.template_key cluster, since the raw key is an opaque @d-zero/page-cluster blocking key with no human-readable meaning on its own. Also extracts the shared SQLITE_IN_CHUNK constant used by three query functions into one module instead of three independent copies within the same package.
Adds a /template-clusters screen listing every page_templates.template_key cluster as a collapsible section, showing page count, common directory, and common stylesheet filenames computed server-side. Each section links to the Pages view pre-filtered by that cluster's templateKey. Falls back to a guidance message (with the `analyze --templates` command) when the archive has no classification yet, rather than showing an indistinguishable empty list. Backend caches the per-archive result in memory (bypassed in stub mode) since page_templates has no viewer read-model fast path of its own. Adds a dedicated Playwright fixture/config/suite (test:e2e:template-clusters) for the "classification present" cases, kept separate from the shared e2e fixture so its extra stylesheet resource doesn't perturb the shared Resources/Unused Resources view assertions. The "never classified" fallback is covered against the shared fixture instead.
Updates the template-classification Reading path to reflect the new query aggregation and viewer analysis screen, replacing the now-outdated note that said this surface was intentionally unimplemented.
computeCommonDirectory computed one deepest-common-prefix directory per cluster origin, which collapses to the site root for any cluster whose member pages span more than one top-level section — real archive data showed clusters of 200+ pages reporting nothing but the origin, hiding which sections they actually belong to. Replaces it with computeDirectoryDistribution: groups by first path segment and returns the top-N (default 5) directories ranked by page count, so a caller can see the sectional spread instead of losing it. Updates the viewer's template-clusters screen to show each directory with its page count and a "N other pages" note for anything outside the top N.
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.
Summary
/template-clustersviewer screen that lists every DOM-structuretemplate cluster (
page_templates.template_key) found by--templates,since the raw key is an opaque blocking key with no human-readable meaning
on its own (
css:<hash>cannot be reversed to a filename,path:<segment>reflects only the shallow blocking depth).
page count (a frequency distribution over the first path segment, not a
single deepest-common-prefix — a cluster spanning multiple sections would
otherwise collapse to the site root and hide which sections it actually
covers), and the common stylesheet set/filenames.
templateKey.analyze --templatescommand)when the archive has no classification yet, rather than showing an
indistinguishable empty list.
Test plan
yarn test— 501 files / 3522 tests passingyarn lint— no errorsyarn buildtest:e2e:template-clusters) for the"classification present" cases, including a 7-directory cluster to
exercise the top-5 truncation + "N other pages" remainder
stylesheet filenames / top directories with page counts, and the
"view pages" link correctly filters the Pages view
🤖 Generated with Claude Code