Repository navigation
Description
Summary
Add a Query Fan-out tab to the prompts page (/dashboard/prompts), between Prompts and Insights, that surfaces the observed query fan-out — the sub-queries AI answer engines actually ran (from #332) — and lets the user promote any of them into a tracked prompt in one click.
Placement is a tab on the existing prompts page (not a new left-nav item): fan-out is conceptually a lens on prompts.
Depends on
#332 (captures prompt_results.search_queries as [{ query, engine?, source_platform }]). This issue is read-only over that data + a small intent classifier + the existing prompt-add flow. No schema change is needed for the Sourced prompts column below — prompt_results.search_queries already lives on a row that carries prompt_id, so the originating prompt is inherently linked.
Core principle — observed only
The fan-out list is 100% what the engines returned — we never generate/predict sub-queries. The only derived layer is an intent tag (see below), clearly a label on top of observed text.
What the tab shows (v1)
A prompt-filtered, brand-wide table of the observed fan-out for the selected window:
| Sub-query (observed) | Engine / source | Times searched | Sourced prompts | Intent | Action |
|---|---|---|---|---|---|
| "best running shoes 2026" | Copilot | 34 | "running shoes for flat feet" +2 | best-top | + / Tracked ✓ |
- Times searched = across the window and all engines/runs, how many tracked answers issued this sub-query (count distinct answers whose
search_queriescontains it). This is the default sort and our observed "demand" signal — we deliberately do not use Google Ads volume (these are long-tail natural-language queries that return ~0; the engines' own search frequency is the on-topic signal). - Engine / source chip = which engine(s) surfaced it. Copilot is the primary source; Perplexity secondary (web queries); ChatGPT is usually empty — the chip makes this transparent.
- Sourced prompts = the distinct tracked prompts of yours whose answers ran this sub-query. A single fan-out sub-query commonly surfaces across several of your prompts, so this shows its origin — which prompt(s) the engine fanned out from. Users will want to see the prompts a fan-out was shown under. Derived from the same aggregation (
prompt_results.prompt_id→ prompt text); render as the first prompt's text + a+Noverflow, with a popover/expander listing all of them, each linking to its prompt (e.g./dashboard/prompts/[id]or the Insights prompt view). No extra query shape — it falls straight out of the read aggregation. - Intent = the same 7-value taxonomy as the Insights "intent" column (
comparison,how-to,what-is,best-top,vs-review,recommendation,problem-solving), via a new lightweightclassifyPromptIntent(text)— see below. - Action = a
+to track this sub-query as a prompt (the loop: observed fan-out → track → measure its own visibility). If a prompt with that text already exists, show Tracked ✓ linking to it (dedup — mirror the "add as competitor"+pattern on the citations Domains table).
Intent classification
- Add
classifyPromptIntent(text)toserver/src/lib/intent-extraction.js: shares the same intent enum asintentKeywordSchema(one taxonomy, no drift with the Insights column) but does not extract keywords and does no volume work — intent only, a cheaper call. - Applied to distinct sub-query strings, deduped + cached (many answers repeat the same sub-query → classify each unique string once), on-demand (not per tracking ingest) to control LLM cost.
- Nothing here touches volume / DataForSEO.
The "+" (promote to tracked prompt)
- Reuse the existing prompt-add path (
savePromptSet/ the prompt creation used by the Insights Suggestions card +prompt_suggestions). - Enforce the plan's prompt limit (
maxPromptsvia the existingenforceLimitguard) — promoting spends daily Cloro + LLM budget. - After adding, the sub-query is a normal tracked prompt and gets its own visibility/mention/citation over time (cleaner per-query attribution than the answer-level fan-out).
Explicit non-goals (v1)
- No Google Ads volume / competition for the sub-queries (dropped — long-tail, ~0;
Times searchedreplaces it). - No competitor / citation coverage on the fan-out.
- No answer-level "were we cited on this sub-query" co-occurrence badge (the fan-out array carries no per-sub-query citations; the real signal comes only after promoting via
+). - No LLM-generated fan-out — observed only.
Files to touch
server/src/lib/intent-extraction.js— addclassifyPromptIntent(text)(shared enum, intent-only).- A read action (e.g.
web/src/lib/actions/tracking.tsor a newfanout.ts) — aggregateprompt_results.search_queriesinto distinct sub-queries withtimes_searched, engines, per-string intent (cached), and the set of sourced prompts (distinctprompt_id+ prompt text) each sub-query came from; mark which sub-queries already exist as prompts. web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx— new Query Fan-out tab between Prompts and Insights; the table (incl. the Sourced prompts column with links to the origin prompts) ++/Tracked action; reuse the existing prompt-add +maxPromptsguard.
How to test
- Brand with tracked prompts and a few Copilot/Perplexity runs (so
search_queriesis populated) → Prompts → Query Fan-out: a list of observed sub-queries withTimes searched, engine chips, intent, and the Sourced prompts they came from, sorted by most-searched. - A sub-query that surfaced under multiple of your prompts shows all of them in Sourced prompts (first +
+N, expandable), each linking to that prompt. - A sub-query already tracked as a prompt shows Tracked ✓ (not
+); a new one shows+. - Click
+→ the sub-query is added as a tracked prompt (respectsmaxPrompts); the row flips to Tracked ✓. - ChatGPT-only brands show a sparse/empty fan-out (transparent via engine chips) — no crash.
- No Google volume / DataForSEO call fires from this tab.
Notes
- Fan-out is sparse and Copilot-heavy (per feat(tracking): capture & store observed query fan-out (Cloro searchQueries / search_model_queries) #332 findings) — the empty/low state should be a clear notice, not a broken table.
Times searchedandSourced promptsare both read-time aggregations oversearch_queries(jsonb unnest) joined to the owningprompt_id; fine for v1, revisit materialization only if it gets slow at scale.
Activity
fix(fanout): trim sub-queries, guard engine + array on write (Copilot…
feat(tracking): capture & store observed query fan-out (Cloro searchQ…
feat(prompts): Query Fan-out tab — observed sub-queries with times-se…
feat(prompts): Query Fan-out intent column — classifyPromptIntent + o…