Open-source SEO, GEO, and marketing skills for AI agents.
fix: harden live snapshots and business context ranking
Tong1f7d93e61c08
diff --git a/google-ads/copy/evals/evals.json b/google-ads/copy/evals/evals.jsonindex 8bbc40ff..a62c4f80 100644--- a/google-ads/copy/evals/evals.json+++ b/google-ads/copy/evals/evals.json@@ -12,7 +12,7 @@"All headlines are <= 30 characters","Every description shows a character count","All descriptions are <= 90 characters",- "At least one headline includes Example City (location specificity)",+ "At least one headline includes Portland (location specificity)","At least one headline references the 4.8 star rating or 200+ reviews (social proof)","At least one headline references 12 years in business (trust signal)","Pin positions are indicated (at least H1 pinned to position 1)"diff --git a/google-ads/shared/industry-templates.json b/google-ads/shared/industry-templates.jsonindex e55c8c3a..2f2a2a72 100644--- a/google-ads/shared/industry-templates.json+++ b/google-ads/shared/industry-templates.json@@ -39,7 +39,7 @@},"healthcare": {- "aliases": ["dental", "dentist", "dermatology", "medical", "clinic", "urgent care", "physical therapy", "chiropractor", "veterinary"],+ "aliases": ["dental", "dentist", "dermatology", "medical", "clinic", "urgent care", "physical therapy", "chiropractor"],"typical_margin": 0.35,"margin_range": [0.25, 0.5],"aov_range_usd": [150, 2000],diff --git a/openclaw/bin/weekly_review.py b/openclaw/bin/weekly_review.pyindex baf42335..d1054a70 100755--- a/openclaw/bin/weekly_review.py+++ b/openclaw/bin/weekly_review.py@@ -8,6 +8,7 @@ import htmlfrom html.parser import HTMLParserimport jsonimport math+import osimport reimport subprocessimport sys@@ -607,14 +608,35 @@ class PageSnapshotParser(HTMLParser):self.cta_texts.append(text)-def fetch_url_text(url: str, timeout: int = 12) -> tuple[str | None, dict[str, Any]]:- request = Request(- url,- headers={- "User-Agent": "Mozilla/5.0 (compatible; ToprankOpenClawSEOOperator/1.0; +https://openclaw.ai)",- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",- },- )+def live_fetch_headers(site_profile: dict[str, Any] | None = None) -> dict[str, str]:+ headers = {+ "User-Agent": "Mozilla/5.0 (compatible; ToprankOpenClawSEOOperator/1.0; +https://openclaw.ai)",+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",+ }+ profile = site_profile or {}+ for name, value in (profile.get("live_fetch_headers") or {}).items():+ if value:+ headers[str(name)] = str(value)+ for name, env_name in (profile.get("live_fetch_header_env") or {}).items():+ value = os.environ.get(str(env_name))+ if value:+ headers[str(name)] = value++ bypass_env_names = [+ profile.get("vercel_protection_bypass_env"),+ "TOPRANK_VERCEL_PROTECTION_BYPASS",+ "VERCEL_PROTECTION_BYPASS",+ "VERCEL_AUTOMATION_BYPASS_SECRET",+ ]+ for env_name in bypass_env_names:+ if env_name and os.environ.get(str(env_name)):+ headers["x-vercel-protection-bypass"] = os.environ[str(env_name)]+ break+ return headers+++def fetch_url_text(url: str, timeout: int = 12, site_profile: dict[str, Any] | None = None) -> tuple[str | None, dict[str, Any]]:+ request = Request(url, headers=live_fetch_headers(site_profile))try:with urlopen(request, timeout=timeout) as response:content_type = response.headers.get("content-type", "")@@ -721,7 +743,7 @@ def page_snapshot_for_url(url: str | None, site_profile: dict[str, Any] | None =if source_path:return parse_frontmatter_snapshot(source_path.read_text(errors="ignore"), source_path)if live and url:- raw_html, meta = fetch_url_text(url)+ raw_html, meta = fetch_url_text(url, site_profile=site_profile)if raw_html:return parse_html_snapshot(raw_html, "live_fetch")return {"source": "live_fetch", **meta}@@ -1018,44 +1040,52 @@ def apply_business_context_to_issue(issue: dict[str, Any], business_context: dicis_high_priority_query = query_matches_any(query, high_priority_terms)is_support_page = "support" in role_text or "informational" in role_textnational_deprioritized = business_context_says_national_deprioritized(business_context)+ candidates = context_page_candidates(business_context, reference_url)+ context_support_page = candidates.get("support")- if issue.get("recommended_action_type") in {"snippet_content_packaging", "meta_tags", "query_intent_mapping"} and is_support_query and not is_high_priority_query and (is_support_page or national_deprioritized):- candidates = context_page_candidates(business_context, reference_url)- preferred_owner = candidates.get("local_research") or candidates.get("transactional") or target+ if issue.get("recommended_action_type") in {"snippet_content_packaging", "meta_tags", "query_intent_mapping"} and is_support_query and not is_high_priority_query and (is_support_page or context_support_page or national_deprioritized):+ source_support_page = target or context_support_page or reference_url+ preferred_owner = candidates.get("local_research") or candidates.get("transactional") or source_support_pageupdated = dict(issue)updated["recommended_action_type"] = "local_intent_ownership"locality = business_context_local_label(business_context)updated["title"] = f"Resolve {locality} intent ownership for '{query}'"updated["target"] = preferred_ownerupdated["canonical_target"] = preferred_owner- updated["source_target"] = target or reference_url+ updated["source_target"] = source_support_pageupdated["consolidation_targets"] = {- "source_support_page": target or reference_url,+ "source_support_page": source_support_page,"preferred_local_owner": preferred_owner,"conversion_target": candidates.get("transactional"),}updated["expected_click_delta"] = None- updated["expected_impact"] = f"Clarify which {locality} page should own this intent; optimize for qualified local outcomes, not national informational CTR."+ updated["expected_impact"] = f"Clarify which {locality} page should own this intent; optimize for qualified local outcomes, not raw support-page CTR."updated.setdefault("operator_judgment_notes", [])- updated["operator_judgment_notes"] = [- *updated["operator_judgment_notes"],- "business context deprioritizes national informational clicks",- "do not optimize the support page for broad national CTR unless it routes qualified local intent",+ ownership_notes = [+ "supporting intent should route qualified demand to the best local owner","decide whether to consolidate, canonicalize, redirect, or internally link from the support page to the local owner",]+ if national_deprioritized:+ ownership_notes = [+ "business context deprioritizes national informational clicks",+ "do not optimize the support page for broad national CTR unless it routes qualified local intent",+ *ownership_notes,+ ]+ updated["operator_judgment_notes"] = [*updated["operator_judgment_notes"], *ownership_notes]score_components = dict(updated.get("score_components", {}))score_components["business_context_goal_score"] = 1.0- score_components["national_click_discount"] = 0.25+ if national_deprioritized:+ score_components["national_click_discount"] = 0.25updated["score_components"] = score_componentsupdated["business_context_adjustment"] = {"from_action_type": issue.get("recommended_action_type"),- "reason": f"supporting/national query is not the business goal; prioritize {locality} ownership",+ "reason": f"supporting query is not the direct business goal; prioritize {locality} ownership","preferred_local_owner": preferred_owner,- "source_support_page": target or reference_url,+ "source_support_page": source_support_page,}- national_discount = score_components["national_click_discount"]raw_priority = float(issue.get("priority_score", 0))- updated["priority_score"] = round(raw_priority * national_discount, 3)+ if national_deprioritized:+ updated["priority_score"] = round(raw_priority * score_components["national_click_discount"], 3)return updatedreturn issuediff --git a/openclaw/tests/test_weekly_review_scoring.py b/openclaw/tests/test_weekly_review_scoring.pyindex 347d49d2..d3913a4e 100644--- a/openclaw/tests/test_weekly_review_scoring.py+++ b/openclaw/tests/test_weekly_review_scoring.py@@ -1,3 +1,4 @@+import osimport sysimport tempfileimport unittest@@ -215,6 +216,82 @@ class WeeklyReviewScoringTest(unittest.TestCase):self.assertEqual(updated["recommended_action_type"], "snippet_content_packaging")self.assertNotIn("national_click_discount", updated.get("score_components", {}))+ def test_support_page_retargeting_without_national_deprioritization_keeps_score(self) -> None:+ issue = {+ "recommended_action_type": "snippet_content_packaging",+ "primary_query": "how much does roof repair cost",+ "target": "https://www.example.com/blog/roof-repair-cost",+ "canonical_target": "https://www.example.com/blog/roof-repair-cost",+ "priority_score": 0.6,+ "score_components": {},+ "operator_judgment_notes": [],+ }+ business_context = {+ "target_customer_priority": ["local homeowners", "researchers"],+ "booking_intent_hierarchy": {"supporting_only": ["how much does roof repair cost"]},+ "page_role_map": {+ "/blog/roof-repair-cost": "supporting informational page",+ "/roof-repair-prices": "local commercial-research page",+ },+ }++ updated = weekly_review.apply_business_context_to_issue(issue, business_context, site_id="example.com")++ self.assertEqual(updated["recommended_action_type"], "local_intent_ownership")+ self.assertEqual(updated["priority_score"], 0.6)+ self.assertNotIn("national_click_discount", updated.get("score_components", {}))+ self.assertFalse(any("national informational" in note for note in updated["operator_judgment_notes"]))++ def test_query_only_retargeting_uses_context_support_page_as_source(self) -> None:+ issue = {+ "recommended_action_type": "query_intent_mapping",+ "primary_query": "how much does roof repair cost",+ "priority_score": 0.6,+ "score_components": {},+ "operator_judgment_notes": [],+ }+ business_context = {+ "target_customer_priority": {"deprioritized": ["national informational readers outside service area"]},+ "booking_intent_hierarchy": {"supporting_only": ["how much does roof repair cost"]},+ "page_role_map": [+ {"path": "/blog/roof-repair-cost", "role": "supporting informational page"},+ {"path": "/roof-repair-prices", "role": "local commercial-research page"},+ ],+ }++ updated = weekly_review.apply_business_context_to_issue(issue, business_context, site_id="example.com")++ self.assertEqual(updated["recommended_action_type"], "local_intent_ownership")+ self.assertEqual(updated["source_target"], "https://www.example.com/blog/roof-repair-cost")+ self.assertEqual(updated["consolidation_targets"]["source_support_page"], "https://www.example.com/blog/roof-repair-cost")+ self.assertEqual(updated["target"], "https://www.example.com/roof-repair-prices")++ def test_live_fetch_headers_include_vercel_bypass_from_env(self) -> None:+ previous = os.environ.get("TOPRANK_VERCEL_PROTECTION_BYPASS")+ os.environ["TOPRANK_VERCEL_PROTECTION_BYPASS"] = "test-bypass-secret"+ try:+ headers = weekly_review.live_fetch_headers()+ finally:+ if previous is None:+ os.environ.pop("TOPRANK_VERCEL_PROTECTION_BYPASS", None)+ else:+ os.environ["TOPRANK_VERCEL_PROTECTION_BYPASS"] = previous++ self.assertEqual(headers["x-vercel-protection-bypass"], "test-bypass-secret")++ def test_live_fetch_headers_support_site_profile_header_env(self) -> None:+ previous = os.environ.get("CUSTOM_FETCH_TOKEN")+ os.environ["CUSTOM_FETCH_TOKEN"] = "custom-token"+ try:+ headers = weekly_review.live_fetch_headers({"live_fetch_header_env": {"x-custom-token": "CUSTOM_FETCH_TOKEN"}})+ finally:+ if previous is None:+ os.environ.pop("CUSTOM_FETCH_TOKEN", None)+ else:+ os.environ["CUSTOM_FETCH_TOKEN"] = previous++ self.assertEqual(headers["x-custom-token"], "custom-token")+def test_national_click_discount_demotes_ranking_score_without_floor_boost(self) -> None:issue = {"recommended_action_type": "snippet_content_packaging",diff --git a/seo/shared/business-context.md b/seo/shared/business-context.mdindex 93a252d2..cf0b7265 100644--- a/seo/shared/business-context.md+++ b/seo/shared/business-context.md@@ -116,10 +116,16 @@ brand_terms = ["<name variations from user answer 1 + GSC brand signal quercompetitors = ["<from user answer 3, or []>"]key_topics = ["<top 5-8 query clusters from GSC>"]service_value_weights = {"<service>": "<relative value/margin/priority>"}-target_customer_priority = ["<highest-value customer segments>"]+target_customer_priority = {+ "primary": ["<highest-value customer segments>"],+ "deprioritized": ["<segments that should not drive SEO prioritization>"],+}location_priorities = {"<location>": {"priority": "high|medium|low", "notes": "<capacity/margin/strategic context>"}}conversion_events = ["<events that indicate organic business value>"]-booking_intent_hierarchy = ["<highest-intent query patterns first>"]+booking_intent_hierarchy = {+ "highest_priority": ["<highest-intent query patterns>"],+ "supporting_only": ["<research/support queries that need routing, not direct CTR optimization>"],+}local_proof_points = ["<differentiators to use in snippets/content>"]serp_competitor_positioning = {"<priority query>": ["<competitors or SERP features to beat>"]}page_role_map = {"<url or path>": "transactional|informational|supporting|unknown"}@@ -161,6 +167,40 @@ Output `CACHE_STATUS=fresh_loaded` after saving so downstream phases know contexConfirm to the user: "Business profile saved for **$DOMAIN** — I'll use this automatically in all future SEO audits."+### Compatibility examples++Preferred schema with explicit prioritization:++```json+{+ "target_customer_priority": {+ "primary": ["local buyers", "urgent-need customers"],+ "deprioritized": ["national informational readers outside service area"]+ },+ "booking_intent_hierarchy": {+ "highest_priority": ["emergency roof repair near me", "roof repair company"],+ "supporting_only": ["how much does roof repair cost", "roof repair price guide"]+ },+ "page_role_map": {+ "/roof-repair": "transactional local landing page",+ "/blog/roof-repair-cost": "supporting informational page"+ }+}+```++Legacy list schema remains accepted, but list values are treated as positive/ordered priorities only:++```json+{+ "target_customer_priority": ["local buyers", "recurring customers"],+ "booking_intent_hierarchy": ["roof repair near me", "roof repair cost"],+ "page_role_map": [+ {"path": "/roof-repair", "role": "transactional local landing page"},+ {"path": "/blog/roof-repair-cost", "role": "supporting informational page"}+ ]+}+```+---## Using business context in analysis@@ -176,10 +216,10 @@ Once loaded or generated, these values inform every phase that follows:| `key_topics` | Anchor content gap recommendations to confirmed topics, not speculative ones || `business_summary` | Open Phase 6 report with a one-liner so all recommendations read as contextual, not generic || `service_value_weights` | Convert SEO opportunity into business-impact priority instead of click priority |-| `target_customer_priority` | Penalize low-value segments and promote strategic customer journeys |+| `target_customer_priority` | Penalize low-value segments and promote strategic customer journeys. Preferred shape: `{primary: [...], deprioritized: [...]}`; legacy list shape is treated as priority-only, never as deprioritized. || `location_priorities` | Avoid pushing demand to locations that are capacity-constrained or lower priority || `conversion_events` | Define what success means after a proposed SEO action is approved |-| `booking_intent_hierarchy` | Score query opportunities by booking likelihood, not just impression volume |+| `booking_intent_hierarchy` | Score query opportunities by booking likelihood, not just impression volume. Preferred shape: `{highest_priority: [...], supporting_only: [...]}`; legacy list shape is interpreted in order with likely research terms treated as supporting. || `local_proof_points` | Ground titles/snippets/content packaging in real differentiators || `serp_competitor_positioning` | Decide whether CTR gaps are metadata, SERP feature, competitor, or zero-click problems || `page_role_map` | Avoid treating informational blog pages like transactional landing pages |