Skip to content

feat(content): decide create, optimize or expand from the site's pages - #939

Merged
gkhngyk merged 1 commit into
mainfrom
feature/opportunity-page-decision
Oct 5, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/opportunity-page-decision

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Second PR of Phase 2 in #857. Opportunities suggested writing new content even when the site already had a page for the need. Generation now reads the site page inventory (#936) and decides what to do with which page.

Finding candidate pages (lib/page-matching.js)

  • For each cluster, a brand's pages are narrowed to the 8 most likely to cover the need. A page scores the rarer words it shares with the cluster's label, need, prompts and fan-out queries. Words in the title, first heading or URL count twice.
  • At least two shared words are required, so one common word cannot pull a page in.
  • No model call is made.
  • Only pages that answered with a 200 when last read are candidates.

The decision

  • The generation call already writes the opportunities. It now also sees each cluster's candidate pages, with their AI citations, GA sessions and last-modified date.
  • It returns one decision per cluster, with the pages that decision is about:
Decision Meaning
create No page covers the need
optimize A page targets the need; make it the answer AI picks
expand A page covers part of the need
refresh A page covers the need but is out of date
consolidate Near-duplicate pages split the need's signals
defend The brand is already visible
  • resolveDecision holds the decision to what it can stand on. Every decision other than create needs a page, and consolidate needs two; a decision without them falls back.
  • The title says what to do with which page, for example "Expand the Semrush comparison into a list of AI-native SEO and visibility alternatives".

Tightened after real runs

  • Consolidate. It first proposed merging a head-to-head comparison with a general tool list. Consolidate is now only for near-duplicate pages about the same need; pages of different kinds are expanded or optimized instead.
  • Merging. One opportunity absorbed clusters from four other topics, one of them only loosely related. Merging now needs the existing content to answer the cluster's prompts without becoming a different page. An opportunity also stops being offered as a merge target once it holds 3 clusters from other topics (MAX_MERGED_CLUSTERS).

Storage, brief and UI

  • Migration 00105 adds content_opportunities.decision. It is already applied to the hosted database.
  • The pages are kept in source_data.targetPages and survive later merges.
  • When the decision is not create, the brief is told to work on the named page or pages instead of drafting a new one.
  • The list shows the decision under the type badge.
  • The detail page has a Your Site card with the decision, a one-line hint and links to the pages, including their AI citations and sessions.
  • Opportunities from before this change have no decision and look as they did.

Results on the main test brand

Opportunity Decision Pages
Optimize the leading LLM rank tracker pages with updated 2026 feature comparisons optimize the AI rank tracker list (323 AI citations) and a related page
Expand the Semrush comparison into a list of AI-native SEO and visibility alternatives expand the Semrush comparison page
Consolidate conversational SOV and citation tracking guides into a definitive comparison of monitoring platforms consolidate four near-identical "best AI visibility / monitoring tools" lists

Related issue

Part of #857 (Phase 2)

Type of change

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

How to test

  1. On a brand with a site page inventory, run Generate.
  2. New opportunities show a decision badge under the type in the list.
  3. Open one. The Your Site card shows the decision, a hint and links to the pages.
  4. Generate a brief for an optimize or expand opportunity. It works on the named page instead of drafting a new one.

page-matching.test.js covers tokenizing, candidate ranking and the two-word minimum, and the decision fallbacks.

Checklist

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

🤖 Generated with Claude Code

Opportunities suggested new content even when the site already had a page
for the need (#857, Phase 2). Generation now reads the site page inventory
(#936) and says what to do with which page.

- lib/page-matching.js narrows a brand's pages to the 8 most likely to
  cover a cluster's need, by the rarer words they share. No model call.
- The generation call sees those pages, with their AI citations, sessions
  and last-modified date, and returns a decision per cluster: create,
  optimize, expand, refresh, consolidate or defend, with the pages it is
  about. Every decision but create needs a page and consolidate needs two;
  one that lacks them falls back.
- Consolidate is only for near-duplicate pages about the same need, and an
  opportunity takes at most 3 clusters from other topics before it stops
  being offered as a merge target. Both came from bad results on real data.
- Migration 00105 adds content_opportunities.decision. The pages are kept
  in source_data.targetPages and survive merges.
- The brief works on the named page instead of drafting a new one.
- The list shows the decision under the type, and the detail page has a
  "Your Site" card with the decision and links to the pages.
@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 824712d into main Oct 5, 2026
6 checks passed
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