Skip to content

feat(viewer): add template cluster analysis view#233

Merged
YusukeHirao merged 4 commits into
devfrom
feature/template-cluster-view
Jul 24, 2026
Merged

feat(viewer): add template cluster analysis view#233
YusukeHirao merged 4 commits into
devfrom
feature/template-cluster-view

Conversation

@YusukeHirao

Copy link
Copy Markdown
Member

Summary

  • Add a /template-clusters viewer screen that lists every DOM-structure
    template 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).
  • For each cluster, compute server-side: page count, the top directories by
    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.
  • 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.

Test plan

  • yarn test — 501 files / 3522 tests passing
  • yarn lint — no errors
  • yarn build
  • Dedicated Playwright suite (test:e2e:template-clusters) for the
    "classification present" cases, including a 7-directory cluster to
    exercise the top-5 truncation + "N other pages" remainder
  • Shared-fixture e2e suite covers the "never classified" fallback
  • Verified against a real archive: cluster headings show real common
    stylesheet filenames / top directories with page counts, and the
    "view pages" link correctly filters the Pages view

🤖 Generated with Claude Code

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.
@YusukeHirao
YusukeHirao merged commit 7342ad2 into dev Jul 24, 2026
4 checks passed
@YusukeHirao
YusukeHirao deleted the feature/template-cluster-view branch July 24, 2026 15:26
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.

1 participant