Skip to content

feat: feed prompt suggestions with real Search Console demand - #650

Merged
gkhngyk merged 4 commits into
mainfrom
feature/gsc-suggestions
Aug 7, 2026
Merged

gkhngyk merged 4 commits into
mainfrom
feature/gsc-suggestions

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

GSC integration phase 3a: the prompt-suggestion generator now feeds on the brand's real Search Console demand. Every step up to the LLM handoff is deterministic:

  • Mining — gsc_candidate_queries() SQL function aggregates the last 28 days per query in the DB (≥30 impressions, top 200) instead of shipping tens of thousands of daily rows to the app.
  • Coverage filter — normalized token-overlap (≥0.6) against tracked prompts drops queries the brand already covers; unicode-aware (non-English queries), unit-tested.
  • Composition — up to 20 candidates: 10 head-demand + 10 long-tail (4+ words) quick wins. Click-based rationale badges: ≥10 clicks → Protect traffic; ≥100 impressions with CTR <1% → Capture demand.
  • Competition enrichment (cost-capped) — one batched DataForSEO call for ≤20 keywords, 30-day cache table (dataforseo_competition_cache), GSC_SUGGESTION_ENRICHMENT=off kill-switch; competition_index ≤33 → Low competition badge. Enrichment failure degrades to unbadged candidates, never breaks generation.
  • LLM handoff — candidates enter the existing generator's prompt as a "real demand" block; the model converts raw queries into natural prompt phrasings and tags them via a new optional sourceQuery schema field. Only a verbatim match against a provided candidate becomes source: 'gsc' + source_data — a hallucinated sourceQuery degrades to a plain llm row.
  • UI — suggestion card shows a "Search Console · N impr/mo" badge (original query on hover) plus the rationale badge. Accept/dismiss unchanged.
  • Retention — the daily sync now prunes gsc_query_stats rows older than 90 days.

Brands without GSC (no connection, no mapping, or no Composio env) are untouched: the candidate list is empty and both system and user prompts are byte-identical to the pre-GSC build — no new API calls, no behavior change.

Migration 00048: prompt_suggestions.source_data jsonb, the widened source check (adds 'gsc'), the aggregation function, and the competition cache table. Applied to hosted; types/supabase.ts synced.

Related issue

Closes #648

Type of change

  • feat — New feature

How to test

  1. On a brand with a connected + mapped GSC property and synced stats: refresh Prompt Suggestions — part of the batch carries the blue "Search Console" badge with monthly impressions and a rationale badge; hovering shows the original Google query.
  2. Refresh again — enrichment hits the 30-day cache (no new DataForSEO call).
  3. On a brand without GSC: refresh behaves exactly as before.

Manually tested end-to-end against live GSC data (3.2k queries): mining, badges, provenance, and the no-GSC path verified.

Checklist

  • Branch follows the naming convention (feature/)
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

@gkhngyk

gkhngyk commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Pushed three hardening improvements on top: dismissed GSC suggestions can no longer resurrect on refresh (their queries are excluded from mining for 30 days), sourceQuery provenance matching is now case/whitespace-normalized so a cosmetic LLM rewrite can't drop real provenance, and GSC-sourced cards hide the modeled estVolume badge — measured impressions and a modeled estimate side by side read as a contradiction.

@gkhngyk
gkhngyk merged commit d789562 into main Aug 7, 2026
4 checks passed
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.

GSC integration phase 3a: feed prompt suggestions with real Search Console demand

1 participant