Skip to content

feat: integrate page-cluster's onClusterReason into template clusters - #242

Merged
YusukeHirao merged 5 commits into
devfrom
worktree-gleaming-crunching-orbit
Jul 29, 2026
Merged

feat: integrate page-cluster's onClusterReason into template clusters#242
YusukeHirao merged 5 commits into
devfrom
worktree-gleaming-crunching-orbit

Conversation

@YusukeHirao

Copy link
Copy Markdown
Member

Summary

Closes #234.

  • Bump @d-zero/page-cluster to 0.5.1 and wire its onClusterReason callback through
    classifyPageTemplates, persisting the reported ClusterReason per cluster in a new
    page_template_cluster_reasons table (atomic with page_templates on every --templates run).
  • Replace the old raw-intersection CSS approximation (compute-css-intersection.ts) with the
    exact distinctiveStylesheetHrefs page-cluster already computed, now surfaced through
    listPageTemplateClusters and the Template Clusters viewer page (blocking evidence, DOM
    structural core tokens, per-landmark chrome commonality, sibling clusters).
  • Clusters classified before this data existed (page-cluster@0.3.1 era) show a
    re-run---templates hint in the new section only — page count and common directories are
    unaffected.

Test plan

  • yarn build
  • yarn lint:eslint:check (0 errors)
  • yarn test (full workspace, 553 files / 3921 tests)
  • yarn workspace @nitpicker/viewer playwright test --config playwright.template-clusters.config.ts
  • Rebased onto origin/dev (console-logs feature, PR feat: capture and persist console log entries (issue #228) #241) with conflicts resolved

🤖 Generated with Claude Code

Add page_template_cluster_reasons (template_key PK, no FK, WITHOUT ROWID)
alongside page_templates, and thread a ClusterReasonData map through
replacePageTemplates so both tables replace atomically in one transaction.

New table is provisioned via createAdjunctTables's existing hasTable guard,
so existing archives pick it up on next open with no explicit migration.
…luster

Bump @d-zero/page-cluster to 0.5.1 (first published version with
onClusterReason). classifyPageTemplates now wires onClusterReason,
returning { templateKeysByUrl, clusterReasons } instead of a bare Map so
nitpicker.ts can pass both to Archive.replacePageTemplates.

ClusterReason is derived structurally from onClusterReason's own callback
signature rather than imported from page-cluster's non-exported
build-cluster-reason subpath, mirroring the existing stance toward that
library's other non-public internals. The classification cache now stores
both maps together so a crash-recovery cache hit restores clusterReasons
too, not just templateKeysByUrl.
listPageTemplateClusters now attaches the ClusterReason (blocking,
structuralCoreTokens, landmarks, siblingClusterKeys) reported for each
cluster, read back via the new readClusterReasonsByTemplateKey. `reason` is
null for clusters classified before this data existed (page-cluster@0.3.1
era) — distinct from hasClassification: false, which means --templates
never ran at all.

Remove compute-css-intersection.ts and collect-page-stylesheet-urls-by-page-id.ts:
ClusterReason.blocking's css-kind distinctiveStylesheetHrefs is the exact set
page-cluster's own first-party/document-frequency filtering already produced,
making the prior raw-intersection approximation unnecessary.
…view

Add a per-cluster section for blocking evidence (css/path/orphanMerge),
DOM-structural core tokens, per-landmark-type chrome commonality, and
sibling cluster keys (linked as in-page anchors) — sourced from
TemplateClusterSummary.reason. Clusters with reason: null (classified
before this data existed) show a re-run-analyze hint in that section only;
page count and common directories keep displaying as before.

clusterHeading()'s common-stylesheet-filenames priority now reads from the
exact blocking evidence instead of the removed raw-intersection
approximation, so the former "this list can include site-wide CSS" caveat
no longer applies.
Update the template-classification reading path to cover the new table,
the ClusterReason collection/persistence flow across core/crawler/query,
and the reason-aware viewer display. Also fix a stale filename reference
(compute-common-directory.ts -> compute-directory-distribution.ts).
@YusukeHirao
YusukeHirao merged commit 78c18bf into dev Jul 29, 2026
10 checks passed
@YusukeHirao
YusukeHirao deleted the worktree-gleaming-crunching-orbit branch July 29, 2026 02:36
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.

クラスタ選定理由(onClusterReason)をtemplateKeyに統合する(page-cluster追加への申し送り)

1 participant