Skip to content

feat(extract): cover settings, custom elements, CSS classes and metafields in Shopify themes - #5557

Closed
dalexhd wants to merge 32 commits into
Graphify-Labs:v8from
dalexhd:feat/theme-graph-coverage
Closed

dalexhd wants to merge 32 commits into
Graphify-Labs:v8from
dalexhd:feat/theme-graph-coverage

Conversation

@dalexhd

@dalexhd dalexhd commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Stacked on #5555 (which builds on #5554 and #5553). Refs #5552.

Problem

After the Liquid and theme JSON extractors, a theme graph still misses several constructs that a "what breaks if I change X" question depends on: settings.x reads, custom elements defined in JS and used in Liquid, CSS classes used in markup, shop.metafields reads, and .js.liquid/.css.liquid assets. explain and affected also showed only the first line of an edge that is repeated many times in one file.

Implementation

  • explain and affected print every line of an edge (file:L58,L73), merging source_location with the same-file also_seen entries.
  • .js.liquid assets: Liquid is stripped keeping line numbers ({{ }} becomes 0 so the JS stays parseable) and the result goes through the existing JS extractor in memory. The AST cache schema is bumped.
  • .css.liquid and {% stylesheet %} bodies: a pure selector scanner (classes, ids, custom elements, no pseudo-classes). A minimal .css extractor is registered but yields nothing outside a theme root (ancestor with layout/theme.liquid).
  • Settings: settings.x links to config/settings_schema.json; section and block settings resolve against the file's own {% schema %}. An undeclared setting becomes an unresolved node, not a silent miss.
  • Custom elements: an HTML segmenter over the Liquid scan finds <x-y> and is="x-y"; the element node hangs from the JS file that calls customElements.define, so affected on that JS reaches the templates that use the element. The defines index is read once per file.
  • CSS classes: INFERRED (0.55) edges from each class token in Liquid to every selector of that name in theme CSS. affected of a Liquid file does not grow.
  • Metafields: usage nodes linked to the definition in .shopify/metafields.json; a missing definition is an unresolved node (a warning in the gate), not an error.
  • scripts/theme_gate.py: standalone grep-versus-graph.json harness measuring render/include/section, CSS/JS symbols, custom elements, settings, classes and metafields.

Verification

uv run pytest tests -q
uv run python scripts/theme_gate.py <theme root> [...]
  • Synthetic fixtures for every capability, plus gate tests.
  • Real data: three production themes built on Impact, Horizon and Motion (private, not included), cold build, grep-versus-graph. Before this change the new categories were at 0 % (settings 0/2832, 0/928, 0/1311; CSS classes 0/2656, 0/966, 0/2326; custom elements 0/252, 0/104, 0/16; metafields 0/107, 0/6, 0/26). After: 100 % in every category with cases, on all three.
  • Cold build 7 to 9 s per theme (at most 2.25x the previous build); graph.json grows 1.9x to 3.6x.
  • affected "snippets/accordion.liquid" --depth 5 returns the same set of dependents as before.
  • Full suite: all green except tests/test_liquid_extractor.py::test_two_megabyte_file_is_fast, a 2 s wall-clock limit that already sits at 1.3 to 1.8 s on the base and fails only under machine load; it passes when run alone.

Limitations

  • Settings and metafield reads whose name is built at runtime are not resolved.
  • Custom elements defined outside the theme's own JS (third-party bundles) become unresolved nodes.
  • CSS class edges are INFERRED: a class can be styled by a selector that is not a plain class.

AI disclosure

Written with Claude Code. I reviewed the code and ran the commands above myself.

dalexhd and others added 29 commits November 27, 2026 15:00
Extract .liquid files of a Shopify theme (gated on a layout/theme.liquid ancestor). render/include/section/sections/content_for and schema blocks become 'imports' edges to the file they name, so 'graphify affected' on a snippet lists the sections rendering it. asset_url and the t filter become 'references' edges (asset file, or key of the single default locale). Relation 'includes' is avoided because affected does not follow it. Dynamic names, comment/doc/raw regions and path-traversal names emit nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A statically named render/include/section/sections/content_for target, asset or translation key that does not exist becomes an AMBIGUOUS edge (score 0.2) to a node flagged unresolved with id ref_liquid_<kind>_<name>, instead of being dropped. Documents how to list them from graph.json and adds Liquid to the built-in parsers list. The incremental cache keeps the stale edge of an unchanged citing file after the target appears; pinned by a strict xfail, a full rebuild clears it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A literal such as 'font.eot?#iefix' piped into asset_url named a file that cannot exist. Resolve the part before ? or # instead of reporting a broken reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… to JS siblings

Shopify default locales start with a // header, so json.loads failed and every | t edge was lost; strip // and /* */ outside strings. A .liquid -> .js reference was dropped by the cross-language guard in build, and the references target was not salted with the colliding id when x.css and x.js share a stem.

Co-Authored-By: Claude <[email protected]>
Templates and section groups of a Shopify theme place sections and blocks in JSON, which were skipped as data JSON. Route them by path (gated on a theme root) before the generic .json dispatch, link each placed section and existing theme block, and link t: schema keys to the default schema locale.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Templates place top-level blocks with section type _blocks, which Shopify provides; it never has a sections/ file, so it must not be reported as a broken reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
edge_lines() merges source_location with the same-file also_seen entries;
explain and affected print them ascending (file:L58,L73).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XEpopcRhPeknSH9XUaK2bN
Standalone grep-vs-graph.json harness with its own nested-comment masking;
measures render/include/section, css/js symbols, custom elements, settings,
classes and metafields.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XEpopcRhPeknSH9XUaK2bN
- add a pure css_selectors scanner (classes, ids, custom elements; no pseudo-classes)
- strip Liquid keeping line numbers, with nested comment and raw handling
- emit selector nodes for {% stylesheet %} bodies with absolute lines

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XEpopcRhPeknSH9XUaK2bN
- register .css in CODE_EXTENSIONS and the extractor dispatch
- extract_css yields no nodes (and is cached as skipped) outside a Shopify theme

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XEpopcRhPeknSH9XUaK2bN
- strip Liquid keeping lines ({{ }} becomes 0 so JS stays parseable) and call _extract_generic in memory
- bump the AST cache schema to 59

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XEpopcRhPeknSH9XUaK2bN
Adds an HTML segmenter to the Liquid scan and a per-root index of defines; the element node hangs from the defining JS so affected reaches the templates that use it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01XEpopcRhPeknSH9XUaK2bN
Markup echoed from tags and outputs counts too. The defines index is read once per file, not once per match (a 30k-tag file took 13 s).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01XEpopcRhPeknSH9XUaK2bN
…lectors

INFERRED 0.55 edges from each class token to every selector of that name in theme CSS, css.liquid and stylesheet blocks; affected of a Liquid file does not grow.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01XEpopcRhPeknSH9XUaK2bN
@dalexhd
dalexhd requested a review from safishamsi as a code owner November 27, 2026 19:03
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @dalexhd. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Nothing blocking · 20 possible issues to check · Merge confidence 5/5

20 possible issues to check · High impact

20 possible issues we couldn't confirm

They don't change the score.

What this review covered
  • This review stopped before it finished; findings are from the part that ran.
  • The AI model asked for code in a way the review could not use.
  • We didn't review 9 files that aren't source code, such as docs, config, images, or generated or third-party code.
  • A changed file's diff was too long to show in full, so the review may not have seen every changed line in it.
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
  • +1 more notes in Graphify.
  • 18 of 18 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 8291 functions depend on this change
  • 18 functions became more coupled. Largest: extract() (1408 callers), build_from_json() (352 callers), main() (132 callers).
  • 646 of 646 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Review stopped early on 6d50546 · 20 earlier findings not re-checked

return lines


def _custom_element_defines(root: Path) -> dict[str, tuple[Path, int]]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug  Commented-out custom-element definitions are treated as real

A custom element mentioned only in a JavaScript comment can appear to be defined, so Liquid references point to a definition that never runs.

Filter JavaScript comments before applying _CE_DEFINE in _custom_element_defines.

Evidence · checked against the code
  • Independent source review: Checked the Liquid use path and tests covering actual definitions, unresolved uses, and JavaScript blocks. Those tests do not filter comments or prevent the raw scan from matching one; no mitigating guard on this route was found.
  • A changed file's diff was too long to show in full.
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
Prompt to fix with AI
In graphify/extractors/liquid.py, _custom_element_defines (line 1032):
Problem: Commented-out custom-element definitions are treated as real
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

Comment thread graphify/extractors/liquid.py Outdated
return [f for f in files if f.is_file()]


def _signature(files: list[Path]) -> tuple[int, int]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug  Theme indexes can stay stale after editing an older file

After a CSS or JavaScript theme file changes, Liquid extraction can keep using the previous selector or custom-element index, so references may point to outdated results or appear unresolved.

Make _signature detect changes to every scanned file.

Evidence · checked against the code
  • Independent source review: Inspected the Liquid extraction path and existing tests for CSS-class and custom-element linking. They exercise normal index construction, but do not cover editing an indexed file between extractions; no invalidation guard on these paths was found.
  • A changed file's diff was too long to show in full.
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
Prompt to fix with AI
In graphify/extractors/liquid.py, _signature (line 1010):
Problem: Theme indexes can stay stale after editing an older file
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

dalexhd and others added 3 commits November 27, 2026 20:10
Blank // and /* */ comments (strings and template literals untouched) in
assets JS and {% javascript %} bodies before scanning for defines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
.md\:flex and .w-1\/2 were cut at the escape; the selector now stores
md:flex / w-1/2 so it matches class="md:flex" in Liquid.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y file

The (count, newest mtime) signature missed a delete-plus-add and files
restored with an old mtime (cp -p, rsync -t).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
safishamsi pushed a commit that referenced this pull request Nov 28, 2026
…5557)

Squashed landing of @dalexhd's four-PR Liquid/Shopify-theme extractor stack:
a Liquid extractor (.liquid), theme-JSON template→section/block linking, CSS
classes, settings, custom elements and metafields. Pure-stdlib scanners, no
new dependencies; all new extraction is gated to a theme root (layout/
theme.liquid) so non-theme .css/.json files are unaffected. Verified by
adversarial review: zero node/edge diff on Python and a 20-language corpus
(no existing-language regression), new extraction works, broken themes
degrade gracefully.

Schema bump is consolidated with the rest of this release's extraction-output
changes in a following commit.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
safishamsi added a commit that referenced this pull request Nov 28, 2026
…ema 58

Collapse the Shopify stack's internal 58/59/60 bumps and the TS/C++/Markdown
bumps into a single 57->58 bump with one combined entry (TS #5525/#5529,
C++ #5550/#5551, Markdown #5480, Shopify #5553/#5554/#5555/#5557), chaining to
the shipped-57 (0.9.121) entry. Fixes the stack's schema-history mislabel that
had carried the shipped-57 Rust text as 58.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.122 as the Shopify/Liquid theme extractor. The four-PR stack landed as a single squashed commit authored to you (@dalexhd) so it keeps your authorship. Adversarial review confirmed zero regression to existing-language extraction (zero node/edge diff on Python + a 20-language corpus), no new dependencies, and graceful handling of broken themes. Thanks for a substantial feature!

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.

2 participants