Skip to content

Add standalone subtree classifier module (Refs #497)#254

Merged
chubes4 merged 1 commit into
trunkfrom
feat/subtree-classifier-497
Jun 28, 2026
Merged

Add standalone subtree classifier module (Refs #497)#254
chubes4 merged 1 commit into
trunkfrom
feat/subtree-classifier-497

Conversation

@chubes4

@chubes4 chubes4 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Refs #497

Summary

Standalone classifier v1 for the subtree classification taxonomy (#497). It is a pure, tested unit that decides the coarse bucket a source subtree fundamentally represents — the layer above the recognizers. Wiring it into the conversion flow is a deliberate follow-up after the HtmlTransformer decomposition (#242), which is actively in flight; this PR adds the module + tests only.

New namespace: Automattic\BlocksEngine\PhpTransformer\HtmlToBlocks\Classification

  • SubtreeClassifierclassify(DOMElement, ClassificationContext): ClassificationResult
  • ClassificationContext — declared CSS + associated JS + optional ancestry
  • ClassificationResultbucket, confidence (0..1), signals (diagnostics)

Buckets & generic signals (per #497)

  • theme_presentation — CSS keyframes/transition/animation/transform/sticky, or JS that only toggles classes/styles for visual effect (scroll-reveal, parallax); no input/data/state.
  • custom_block — cohesive, repeatable content unit a user edits (card grid, gallery, tabs/accordion via interactive role); component-local interactivity only.
  • custom_application — stateful/data-driven: form controls + JS that reads input, fetches data, mutates state; Interactivity API (data-wp-*); canvas. Input drives logic.
  • custom_plugin — site-wide functional JS not tied to one component (global-scope handlers + network/storage), no editable content unit, not decorative, not input-driven.
  • unknown — weak or conflicting evidence; conservative fallback so the caller can route to core/html + a diagnostic.

Only generic structural signals are used (DOM shape, declared CSS text, associated JS text) — no fixture/site-specific strings. Conservative + confidence-scored: a minimum winning score and a minimum margin over the runner-up are required, otherwise unknown.

Tests

Plain-PHP unit suite tests/unit/subtree-classifier.php (style of tests/contract/run.php), wired into composer test:canonical via a new test:unit script. 23 assertions across 10 cases: one confident case per bucket, ambiguous/weak → unknown, and negatives (decorative animation is not a block; static content is not an application; input-driven app is not a plugin; component-local tabs are not a plugin; single non-repeated unit → unknown).

Gates

  • composer test:canonical — green (includes the new unit suite)
  • composer parity — green, 128 fixtures unaffected
  • php -l clean on all new files

Scope guarantee

HtmlTransformer.php and all existing converters/recognizers are untouched — additive only (3 source files + 1 test + composer.json script wiring).

DO NOT MERGE — standalone classifier v1; wiring into the conversion flow is a follow-up post-#242 decomposition.

Introduce a pure, self-contained classifier that decides the coarse
"bucket" a source subtree represents — the layer above the recognizers
described in issue #497:

  - theme_presentation  (CSS animation / JS that only toggles classes)
  - custom_block        (cohesive, repeatable, user-editable content unit)
  - custom_application  (stateful / data-driven; input drives logic)
  - custom_plugin       (site-wide functional JS, not component-bound)
  - unknown             (weak/conflicting -> conservative fallback)

GENERIC structural signals only (DOM shape, declared CSS, associated JS);
no fixture/site-specific strings. Conservative + confidence-scored: ties
and weak evidence return unknown so the caller can fall back to core/html.

Standalone module only — NOT wired into the conversion flow. Wiring is a
deliberate follow-up after the HtmlTransformer decomposition (#242).
HtmlTransformer and existing recognizers are untouched. Adds a plain-PHP
unit suite (tests/unit) wired into composer test:canonical; existing
canonical + 128 parity fixtures stay green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chubes4 chubes4 merged commit 1c9fc8d into trunk Jun 28, 2026
1 check passed
@chubes4 chubes4 deleted the feat/subtree-classifier-497 branch June 28, 2026 00:26
chubes4 added a commit that referenced this pull request Jun 28, 2026
…258)

Run the standalone SubtreeClassifier (#254) on subtrees that fall back to
raw core/html and attach its verdict (bucket + confidence + top signals)
to the existing fallback diagnostic. This surfaces, across the corpus,
which core/html dumps the classifier believes should have been native
blocks — the data the pattern-recognition swarm optimizes against.

Measurement only: routing and block output are unchanged. The classifier
runs solely on the core/html fallback emission path (script, canvas,
template, inline SVG, form, iframe, unsupported-element), never per
converted element, and only adds a `classification` key to the diagnostic.

Parity 128 -> 128 with byte-identical block output; full composer test
green. Adds a contract assertion that the canvas core/html fallback now
carries a classifier verdict.

Refs #497

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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