Skip to content

feat(content): read the opportunity list through prompt clusters - #932

Merged
gkhngyk merged 1 commit into
mainfrom
feature/cluster-opportunity-list
Oct 5, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/cluster-opportunity-list

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Third of three PRs for #857 (after #925 and #930). The Content page now reads opportunities through prompt clusters, and the old per-prompt backlog is archived.

Archiving the per-prompt backlog

  • Before feat(content): generate one opportunity per prompt cluster #930, opportunities were generated per prompt and piled up: over 9,300 untouched ones across brands, and up to about 760 on one brand. New cluster opportunities were lost among them.
  • Migration 00103 moves a row to a new archived status when it is still new, has no cluster and has no brief. On the hosted database this archived 9,286 rows.
  • Nothing is deleted. Rows with a brief, and rows that moved past new, are left alone.
  • The list, its summary cards and the MCP list_content_opportunities tool hide archived rows unless archived is the status asked for.
  • The Status filter has an Archived option. An archived opportunity's detail page has a Restore button that sets it back to new.

Filters

  • Prompt filter (feat(content): filter opportunities by prompt #836). Selecting a prompt matches the opportunities of its cluster, own or merged, not only the ones whose prompt_id it is. Older per-prompt rows still match by prompt_id. The option counts in /brand/:id/prompts are computed the same way, which also gives feat(prompts): show a prompt's content opportunities on its detail page #838 the right numbers.
  • Topic filter (new). It matches opportunities whose own or merged clusters are in the topic. Options come from GET /brand/:id/topics, and the filter shows when there are two or more topics.
  • content_opportunity_aggregates takes the topic filter and matches prompts through clusters, so the summary cards follow the list.

Signals analyzed

  • The aggregate also returns the brand's signal count: the prompts and fan-out queries its clusters were built from.
  • The first KPI card shows it under the total as "from N signals analyzed". On the main test brand that is 5,082.

One cluster per topic per run

  • On the main test brand, the 3 highest-scoring clusters of a run all came from one topic. A run now picks at most one cluster per topic, so its few suggestions spread across the brand's topics. The no-topic scope counts as one topic.

Tried on production data

  • Migration applied; 9,286 rows archived.
  • The aggregate was checked with no filter, a non-representative member prompt, the opportunity's topic, a topic with no opportunities, and an archived status. It returns the expected rows for each.
  • The main test brand was clustered: 709 prompts into 183 clusters, with 4,373 queries judged. The first run took about 21 minutes; later runs only process changes.
  • Generation was then run with the per-topic rule. It spread opportunities across topics and merged three clusters into existing opportunities: two "tool list" needs from other topics and one GEO cluster.
  • The nightly run on production had already generated and merged on that brand, so feat(content): generate one opportunity per prompt cluster #930 is live.

Related issue

Part of #857. This completes Phase 1 of the plan; Phases 2–4 stay open there.

Type of change

  • feat — New feature
  • test — Adding or updating tests

How to test

  1. Content Optimization on a brand with cluster opportunities. The first card reads "from N signals analyzed".
  2. Status → Archived lists the archived backlog. Open one, press Restore, and it returns to the default list.
  3. Topic → pick a topic. Opportunities whose own or merged clusters are in it remain.
  4. Prompt → pick any prompt of a cluster. The cluster's opportunity is listed, even when that prompt is not its "related prompt".

opportunity-limits.test.js adds the one-cluster-per-topic case.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint, yarn typecheck, yarn format:check, yarn test (404) and yarn build pass (run from web/)
  • yarn lint, yarn format:check and yarn test (945) pass (run from server/)
  • supabase/schema.sql rebuilt with build-schema.sh

🤖 Generated with Claude Code

Cluster opportunities (#930) were listed among thousands of untouched
per-prompt ones, and the prompt filter only matched an opportunity's own
prompt_id (#857).

- Migration 00103 archives the per-prompt backlog: status 'new', no
  cluster, no brief. Nothing is deleted; Restore on the detail page sets one
  back to 'new'. The list, its summary and the MCP list hide archived rows
  unless the Archived status is chosen.
- The prompt filter matches the opportunities of the prompt's cluster, own
  or merged, and still matches older ones by prompt_id. Its option counts
  are computed the same way.
- A topic filter matches opportunities whose own or merged clusters are in
  the topic, with options from GET /brand/:id/topics.
- content_opportunity_aggregates takes the topic filter, matches prompts
  through clusters and returns the brand's signal count: the prompts and
  fan-out queries its clusters were built from. The first KPI card shows it
  as "from N signals analyzed".
- A run picks at most one cluster per topic, so its few suggestions spread
  across the brand's topics.
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 5, 2026
@gkhngyk
gkhngyk merged commit 50d8717 into main Oct 5, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the feature/cluster-opportunity-list branch October 5, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant