Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.
fix(schema): read a @graph document the way the post-edit hook does
lab 120703dc46b86a50
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ca9aacd..5e105c3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Fixed++- `skills/seo-schema/SKILL.md`, `agents/seo-schema.md` and+ `scripts/parse_html.py`: a valid JSON-LD `@graph` document was reported as+ broken markup. A `@graph` container is not an entity, so it needs no+ `@type`, and the `@context` it declares is inherited by the entries it+ holds. `parse_html.py` now keeps that `@context` on the flattened entries,+ and the skill and the agent check `@context` once per document and `@type`+ on entity nodes, the way `hooks/validate-schema.py` already did.+## [2.4.2] - 2026-10-04seo-cockpit, Google sign-in through your own account, and a schema-hook fix.diff --git a/agents/seo-schema.md b/agents/seo-schema.mdindex 905cb0a..9254b69 100644--- a/agents/seo-schema.md+++ b/agents/seo-schema.md@@ -38,8 +38,8 @@ When analyzing pages:## Validation ChecklistFor any schema block, verify:-1. ✅ @context is "https://schema.org"-2. ✅ @type is valid and not deprecated+1. ✅ @context is "https://schema.org" (checked once, on the document; `@graph` entries inherit it)+2. ✅ @type is valid and not deprecated (checked on entity nodes; a `@graph` container needs none)3. ✅ All required properties present4. ✅ Property values match expected types5. ✅ No placeholder text (e.g., "[Business Name]")diff --git a/scripts/parse_html.py b/scripts/parse_html.pyindex 8c411c5..262ae0b 100755--- a/scripts/parse_html.py+++ b/scripts/parse_html.py@@ -12,7 +12,7 @@ import jsonimport osimport reimport sys-from typing import Optional+from typing import Any, Optionalfrom urllib.parse import urljoin, urlparsetry:@@ -88,6 +88,21 @@ def _detect_lazy_method(img) -> str:return "none"+def _inherit_context(node: dict[str, Any], context: Any) -> dict[str, Any]:+ """Return a JSON-LD node that carries the document's ``@context``.++ A ``@graph`` container is not an entity: it declares the document's+ ``@context`` and its entries inherit it. Flattening the container used to+ drop that ``@context``, so every entry came out looking like a block with+ an ``@type`` but no ``@context``, which the seo-schema instructions read as+ broken markup. An entry that declares its own ``@context`` keeps it. The+ input node is never mutated, so the parsed document stays intact.+ """+ if context is None or "@context" in node:+ return node+ return {"@context": context, **node}++def parse_html(html: str, base_url: Optional[str] = None) -> dict:"""Parse HTML and extract SEO-relevant elements.@@ -223,11 +238,14 @@ def parse_html(html: str, base_url: Optional[str] = None) -> dict:for script in soup.find_all("script", type="application/ld+json"):try:schema_data = json.loads(script.string)- # Flatten @graph containers so each @type is a separate entry+ # Flatten @graph containers so each @type is a separate entry.+ # The container is not an entity, so it carries no @type of its+ # own, but its @context is inherited by the entries it holds.if isinstance(schema_data, dict) and "@graph" in schema_data:+ inherited_context = schema_data.get("@context")for item in schema_data["@graph"]:if isinstance(item, dict):- result["schema"].append(item)+ result["schema"].append(_inherit_context(item, inherited_context))elif isinstance(schema_data, list):for item in schema_data:if isinstance(item, dict):diff --git a/skills/seo-schema/SKILL.md b/skills/seo-schema/SKILL.mdindex 18fe062..353a060 100644--- a/skills/seo-schema/SKILL.md+++ b/skills/seo-schema/SKILL.md@@ -19,7 +19,11 @@ metadata:1. Extract JSON-LD with `"${CLAUDE_PLUGIN_ROOT}/scripts/claude-seo" run parse_html.py --url <url> --json`(or scan `<script type="application/ld+json">` in the page source). Flag anyblock without `@context` or `@type`: Google cannot attach it to an entity (a- rating in such a block does not reach the Product).+ rating in such a block does not reach the Product). A `@graph` container is+ not an entity: it needs no `@type`, and the `@context` it declares is+ inherited by the entries it holds. Never flag the container for a missing+ `@type`, and never flag an entry for a missing `@context` that the document+ already provides.2. Check for Microdata (`itemscope`, `itemprop`)3. Check for RDFa (`typeof`, `property`)4. Always recommend JSON-LD as primary format (Google's stated preference)@@ -29,8 +33,8 @@ metadata:- Check required properties per schema type- Validate against Google's supported rich result types- Test for common errors:- - Missing @context- - Invalid @type+ - Missing @context (checked once, on the document; `@graph` entries inherit it)+ - Invalid @type (checked on entity nodes; a `@graph` container needs none)- Wrong data types- Placeholder text- Relative URLs (should be absolute)diff --git a/tests/test_schema_graph_semantics.py b/tests/test_schema_graph_semantics.pynew file mode 100644index 0000000..a2bd30a--- /dev/null+++ b/tests/test_schema_graph_semantics.py@@ -0,0 +1,137 @@+"""A `@graph` document must be read the same way by the seo-schema path and by+the post-edit hook.++`hooks/validate-schema.py` already treats a top-level `@graph` container as a+container rather than an entity: the container needs no `@type`, and its+entries inherit the `@context` the document declares (see+`test_valid_top_level_graph_does_not_require_container_type` in+`tests/test_schema_hook_policy.py`).++The seo-schema path did not agree. `scripts/parse_html.py` flattened the+graph and dropped the document's `@context`, so every entry came out as a+block with an `@type` but no `@context`, and the skill and the agent told+Claude to flag exactly that as broken markup. A valid graph document was+reported as broken on every one of its entries.+"""++from __future__ import annotations++import importlib.util+import json+import re+import sys+from pathlib import Path++REPO_ROOT = Path(__file__).resolve().parent.parent+sys.path.insert(0, str(REPO_ROOT / "scripts"))++from parse_html import parse_html # noqa: E402++SKILL = REPO_ROOT / "skills" / "seo-schema" / "SKILL.md"+AGENT = REPO_ROOT / "agents" / "seo-schema.md"+HOOK = REPO_ROOT / "hooks" / "validate-schema.py"++GRAPH_HTML = (+ "<html><head><title>t</title>"+ '<script type="application/ld+json">'+ '{"@context":"https://schema.org","@graph":['+ '{"@type":"Organization","@id":"#org","name":"Acme"},'+ '{"@type":"WebSite","name":"Acme","publisher":{"@id":"#org"}}'+ "]}</script></head><body><h1>x</h1></body></html>"+)+++def _load_hook():+ """Import the hook module, whose filename cannot be used as an import name."""+ spec = importlib.util.spec_from_file_location("validate_schema", HOOK)+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++def _norm(text: str) -> str:+ """Collapse whitespace runs, so a rewrap of the prose does not break a match.++ Doc prose gets rewrapped whenever a nearby line is edited; asserting+ against the literal wrapped string breaks on every unrelated reflow.+ Matching at sentence level, over normalised whitespace, survives that+ churn while still failing if the actual claim goes missing.+ """+ return re.sub(r"\s+", " ", text).lower()+++def _schema_blocks(entries: list) -> str:+ """Rebuild the HTML of the entries parse_html reported, one block each."""+ return (+ "<html><head>"+ + "".join(+ '<script type="application/ld+json">'+ + json.dumps(entry, ensure_ascii=False)+ + "</script>"+ for entry in entries+ )+ + "</head></html>"+ )+++def test_graph_entries_inherit_the_document_context() -> None:+ """The flattened entries keep the @context the @graph document declared."""+ result = parse_html(GRAPH_HTML)+ assert [entry["@type"] for entry in result["schema"]] == ["Organization", "WebSite"]+ assert all(entry["@context"] == "https://schema.org" for entry in result["schema"])+++def test_graph_entry_keeps_its_own_context() -> None:+ html = (+ '<script type="application/ld+json">'+ '{"@context":"https://schema.org","@graph":['+ '{"@type":"Organization","@context":"https://example.org/ctx"}]}'+ "</script>"+ )+ result = parse_html(html)+ assert result["schema"] == [+ {"@type": "Organization", "@context": "https://example.org/ctx"}+ ]+++def test_graph_document_without_context_is_not_given_one() -> None:+ """A document that declares no @context still has to be reportable."""+ html = (+ '<script type="application/ld+json">'+ '{"@graph":[{"@type":"Organization","name":"Acme"}]}'+ "</script>"+ )+ result = parse_html(html)+ assert result["schema"] == [{"@type": "Organization", "name": "Acme"}]+++def test_non_graph_schema_blocks_are_untouched() -> None:+ html = (+ '<script type="application/ld+json">'+ '{"@context":"https://schema.org","@type":"Article","headline":"h"}'+ "</script>"+ )+ result = parse_html(html)+ assert result["schema"] == [+ {"@context": "https://schema.org", "@type": "Article", "headline": "h"}+ ]+++def test_reported_graph_entries_pass_the_post_edit_hook() -> None:+ """What the seo-schema path reports has to satisfy the hook that accepts graphs."""+ hook = _load_hook()+ result = parse_html(GRAPH_HTML)+ assert hook.validate_jsonld(_schema_blocks(result["schema"])) == []+++def test_seo_schema_skill_states_the_graph_rule() -> None:+ text = _norm(SKILL.read_text(encoding="utf-8"))+ assert "@graph" in text+ assert "not an entity" in text+ assert "inherit" in text+++def test_seo_schema_agent_states_the_graph_rule() -> None:+ text = _norm(AGENT.read_text(encoding="utf-8"))+ assert "@graph" in text+ assert "inherit" in text