Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(content): generate three opportunities per run instead of five to fifteen (#735)

Gökhan Geyik00597f9f0752
diff --git a/server/src/lib/opportunity-generator.js b/server/src/lib/opportunity-generator.js
index 1f5d8da25..58899d4ac 100644
--- a/server/src/lib/opportunity-generator.js
+++ b/server/src/lib/opportunity-generator.js
@@ -9,6 +9,7 @@ import { resolveModel } from './ai-provider.js';
import { getLanguageName } from './languages.js';
import supabaseAdmin from '../config/supabase.js';
import { logger } from './logger.js';
+import { OPPORTUNITIES_PER_RUN, OPPORTUNITY_COUNT_RULE } from './opportunity-limits.js';
const opportunitySchema = z.object({
opportunities: z
@@ -30,7 +31,7 @@ const opportunitySchema = z.object({
}),
)
.min(1)
- .max(20),
+ .max(OPPORTUNITIES_PER_RUN),
});
const SYSTEM_PROMPT = `You are an AEO content strategist. Given a brand's AI visibility data, generate specific, actionable content recommendations.
@@ -39,7 +40,7 @@ Rules:
- Reference specific data points: volumes, visibility scores, competitor gaps.
- Focus on content that will improve the brand's visibility in AI-generated answers.
- Categorize as "owned" or "earned".
-- Generate between 5 and 15 opportunities.
+${OPPORTUNITY_COUNT_RULE}
- The bracketed [N] indexes in the prompt data exist ONLY for the relatedPromptIndex field. NEVER mention an index like "[0]" or "Prompt 3" in titles or descriptions — refer to the prompt by quoting or paraphrasing its actual text/topic instead.`;
function computeScore(volume, visibility, competitorGap, intent) {
diff --git a/server/src/lib/opportunity-limits.js b/server/src/lib/opportunity-limits.js
new file mode 100644
index 000000000..e9bbb9a0c
--- /dev/null
+++ b/server/src/lib/opportunity-limits.js
@@ -0,0 +1,26 @@
+/**
+ * How many content opportunities one generation run may produce.
+ *
+ * The two generators — the automatic one fired after each tracking cycle and
+ * the queued one behind the Generate button — used to carry this rule as a
+ * hand-written sentence and a schema ceiling apiece, and had already drifted
+ * apart in wording. They share it from here so the button and the nightly run
+ * cannot disagree about how many a brand gets.
+ *
+ * Three, not the five-to-fifteen it was: the model reliably landed near ten,
+ * which is more than anyone works through in a day. Generation appends
+ * nightly, so anything the reader does not act on accumulates — a short list
+ * that gets read beats a long one that gets scrolled past.
+ */
+export const OPPORTUNITIES_PER_RUN = 3;
+
+/**
+ * The count instruction, worded for a model that must now choose.
+ *
+ * At ten the ranking barely mattered; the good ones arrived alongside the
+ * filler. At three there is no room for filler, so the instruction has to say
+ * that the slots go to the highest-impact opportunities in the data rather
+ * than to whichever the model composes first. The prompt data is already
+ * ordered by score, which is what "provided" refers to.
+ */
+export const OPPORTUNITY_COUNT_RULE = `- Generate exactly ${OPPORTUNITIES_PER_RUN} opportunities: the ${OPPORTUNITIES_PER_RUN} highest-impact ones supported by the data provided, not the first ${OPPORTUNITIES_PER_RUN} that come to mind. Weigh volume, the visibility gap and the competitor gap together when choosing which ${OPPORTUNITIES_PER_RUN} to keep, and drop anything you would have ranked below them.`;
diff --git a/server/src/lib/opportunity-limits.test.js b/server/src/lib/opportunity-limits.test.js
new file mode 100644
index 000000000..65c03c73b
--- /dev/null
+++ b/server/src/lib/opportunity-limits.test.js
@@ -0,0 +1,49 @@
+import { describe, expect, it } from 'vitest';
+import { readFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { OPPORTUNITIES_PER_RUN, OPPORTUNITY_COUNT_RULE } from './opportunity-limits.js';
+
+/**
+ * The count rule is shared because it was duplicated (#730).
+ *
+ * Two generators produce opportunities — the automatic one after each tracking
+ * cycle and the queued one behind the Generate button — and each used to carry
+ * its own copy of the sentence and its own schema ceiling. They had already
+ * drifted in wording. These tests fail if a number is hand-written back into
+ * either file, which is the only way they can disagree again.
+ */
+
+const source = (relative) =>
+ readFileSync(fileURLToPath(new URL(relative, import.meta.url)), 'utf8');
+
+const GENERATORS = [
+ ['automatic (tracking cycle)', './opportunity-generator.js'],
+ ['queued (Generate button)', '../workers/content-worker.js'],
+];
+
+describe('opportunity count', () => {
+ it('asks for three', () => {
+ expect(OPPORTUNITIES_PER_RUN).toBe(3);
+ });
+
+ it('states the count and that the slots go to the highest-impact findings', () => {
+ expect(OPPORTUNITY_COUNT_RULE).toContain(String(OPPORTUNITIES_PER_RUN));
+ expect(OPPORTUNITY_COUNT_RULE).toMatch(/highest-impact/i);
+ });
+
+ for (const [label, path] of GENERATORS) {
+ it(`the ${label} generator takes its ceiling from the shared constant`, () => {
+ const code = source(path);
+ expect(code).toContain('OPPORTUNITIES_PER_RUN');
+ expect(code).toContain('.max(OPPORTUNITIES_PER_RUN)');
+ // A literal ceiling here is how the two drifted apart before.
+ expect(code).not.toMatch(/\.max\(\d+\)/);
+ });
+
+ it(`the ${label} generator takes its count instruction from the shared rule`, () => {
+ const code = source(path);
+ expect(code).toContain('${OPPORTUNITY_COUNT_RULE}');
+ expect(code).not.toMatch(/Generate (between )?\d+/);
+ });
+ }
+});
diff --git a/server/src/workers/content-worker.js b/server/src/workers/content-worker.js
index 6a9187e1e..fa4b28537 100644
--- a/server/src/workers/content-worker.js
+++ b/server/src/workers/content-worker.js
@@ -9,6 +9,7 @@ import { resolveModel } from '../lib/ai-provider.js';
import { getLanguageName } from '../lib/languages.js';
import supabaseAdmin from '../config/supabase.js';
import logger from '../lib/logger.js';
+import { OPPORTUNITIES_PER_RUN, OPPORTUNITY_COUNT_RULE } from '../lib/opportunity-limits.js';
const opportunitySchema = z.object({
opportunities: z
@@ -38,7 +39,7 @@ const opportunitySchema = z.object({
}),
)
.min(1)
- .max(20),
+ .max(OPPORTUNITIES_PER_RUN),
});
const OPPORTUNITY_SYSTEM_PROMPT = `You are an AEO (Answer Engine Optimization) content strategist. Given a brand's AI visibility data — including prompt tracking results, search volumes, and competitor mentions — generate specific, actionable content recommendations.
@@ -49,7 +50,7 @@ Rules:
- Focus on content that will improve the brand's visibility in AI-generated answers.
- Categorize as "owned" (blog posts, landing pages, FAQ pages the brand controls) or "earned" (guest posts, PR, review sites).
- Set impact based on: volume × (100 - current visibility) × competitor gap.
-- Generate between 5 and 15 opportunities depending on data richness.
+${OPPORTUNITY_COUNT_RULE}
- Do NOT repeat the same recommendation in different wording.
- The bracketed [N] indexes in the prompt data exist ONLY for the relatedPromptIndex field. NEVER mention an index like "[0]" or "Prompt 3" in titles or descriptions — refer to the prompt by quoting or paraphrasing its actual text/topic instead.`;