Skip to content

feat(content): start from the prompts AI doesn't name or cite the brand for yet - #1323

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/start-unseen-prompts
Oct 22, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/start-unseen-prompts

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

From the user's review of New content: Start from Prompt should only suggest prompts where AI neither names nor cites the brand. If the brand is already cited or mentioned for a prompt, it needs no new page.

Migration 00230_content_start_prompts.sql

New function content_start_prompts(brand, days = 30, limit = 500). It returns:

  • the brand's active prompts, each marked seen when an answer in the last 30 UTC days (today included) named the brand or cited its pages;
  • the count of seen prompts, including any past the limit.

How it reads and orders:

  • Reads the prompt-grain Insights rollup (insights_prompt_daily, by its (brand_id, day) index), not the answers.
  • Unseen prompts come first, each group ordered by text, up to the limit, so a large brand's unseen prompts aren't cut by its seen ones.

It is built like the content reads in 00226: plpgsql, force_custom_plan, security definer with the organization check made explicit, and null for a caller outside the organization. It's applied on the dev DB and checked as a member (8 prompts → 3 unseen, 5 seen; the limit holds) and as an outsider (null). schema.sql is rebuilt.

Web

  • getContentStartOptions reads the prompts through it.
    • DraftStartOptions.prompts gains seen, plus a new promptsSeen count.
    • Until the migration is applied (PGRST202), it falls back to the old prompts query with nothing seen.
  • New content → Start from → Prompt lists only unseen prompts. A note under the picker says "N prompts where AI already names or cites you in the last 30 days aren't listed: they need no new page". When every prompt is seen, the empty list says so.
  • Editor → Sources → Add source still offers every prompt, sorted by text as before. Adding a cited prompt as a source is still useful.

Opportunities and Topics are unchanged.

Related issue

None. Product feedback from the user.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

Apply 00230 first.

  1. Library → New content → Create from scratch → Prompt. The picker lists only prompts with no mention or citation in the last 30 days. The note under it gives how many are left out.
    • Compare with Prompts → Tracked Prompts: a prompt showing mentions or citations there isn't offered.
  2. For a brand that shows for every prompt, the picker's empty state reads "AI already names or cites you for every tracked prompt in the last 30 days."
  3. Editor → Sources → Add source: every prompt is still listed, by text.

Checked in light and dark, at 1024 px and wider.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • 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

yarn test passes: 281 files, 2,486 tests. yarn build passes with CI's placeholders. bash supabase/build-schema.sh was run.

🤖 Generated with Claude Code

…nd for yet

New content › Prompt lists only the tracked prompts where no answer of
the last 30 days named the brand or cited its pages: a prompt it already
shows for needs no new page. A note says how many are left out, and the
empty list says when the brand shows for every prompt. Add source in the
editor still offers every prompt.

Migration 00230 adds content_start_prompts (insights_prompt_daily; not
seen first, with the seen count; security definer, members only). Before
it is applied, every prompt is listed as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk This is item E of the Plan feedback. New content → Prompt now lists only the prompts where AI hasn't named or cited the brand in the last 30 days.

  • Migration 00230_content_start_prompts.sql: one function over insights_prompt_daily (has_mention or has_citation, (brand_id, day) index). It's built like 00226: plpgsql, force_custom_plan, security definer with the org check, and null for outsiders. Please apply it before the web deploy, although the web falls back to the old prompts query on PGRST202.
  • Migration numbers: 00229 is feat(content): assign, mark as a priority or hide a Content plan row #1321's and 00230 is this one.
  • Add source: the editor still offers every prompt, sorted by text as before.
  • Your call: the 30-day window matches the app's default period. If you'd rather use the latest run per platform, it's a one-line change.

Checks: web 281 files / 2,486 tests, lint, typecheck and build. Checked on the dev DB as a member (8 → 3 unseen) and as an outsider (null).

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 21, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of small fixes before merge:

  1. Wrong empty-state message on a search miss. ComboboxEmpty also renders when the search box filters the list down to nothing. With promptsSeen > 0, typing a query that matches no unseen prompt shows "AI already names or cites you for every tracked prompt in the last 30 days", even when unseen prompts exist (web/src/components/content/new-content-dialog.tsx:763-767).
    Fix: show allSeen only when the unfiltered list is empty, e.g. kind === 'prompt' && items.length === 0 && options?.promptsSeen ? allSeen : empty. Add a test that types a non-matching query and expects the generic empty text.

  2. A malformed RPC payload reads as "no prompts". readStartPrompts maps every safeParse failure to { prompts: [], seen: 0 } (web/src/lib/actions/content-drafts.ts:268-272). Only null means "not the member's brand". Any shape drift between the function and the schema would silently empty the picker.
    Fix: if (read.data === null) return { prompts: [], seen: 0 }; return startPromptsSchema.parse(read.data); so drift throws, and New content then shows its load error.

Migration 00230 looks right. It's security definer with search_path set and the membership check (null for an outsider). Execute is revoked from public/anon and granted to authenticated/service_role, and create or replace keeps it idempotent. I timed a copy as an authenticated member on the largest brand (about 78k rollup rows in 30 days, 226 active prompts): about 110 ms cold, 23 ms warm. A member of another org gets null as expected. No brand has more than 500 active prompts today, so the cap doesn't change what Add source lists. This merges cleanly with #1333.

cihan-gyk and others added 2 commits October 22, 2026 13:04
…n-prompts

# Conflicts:
#	supabase/schema.sql
…own start-prompts payload

- New content's prompt picker says every prompt is seen only when nothing
  is left to list; a search that matches nothing reads the generic empty
  text.
- readStartPrompts treats only null as "not the member's brand"; any other
  payload goes through the schema's parse, so drift throws and New content
  shows its load error instead of an empty picker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Thanks, both are in 5c5861a4, on top of a merge of main (87a8bd89; only schema.sql conflicted, rebuilt): (1) allSeen shows only when the unfiltered list is empty (items.length === 0), with a test that types a non-matching query and expects "No tracked prompts." (it fails without the fix); (2) readStartPrompts returns { prompts: [], seen: 0 } only for null and otherwise startPromptsSchema.parses, with a test for a drifted payload. Web: 2,502 tests and the build pass; tried in the browser.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both items are fixed:

  • A search miss now shows the generic empty text.
  • Only null reads as "not the member's brand"; any other payload is parsed, and drift throws.

00230 on production. For the largest brand, a member gets 226 prompts (208 seen) in 0.16 s, and an outsider gets null.

Tests. Run on top of main together with #1345: web and server tests, tsc, lint and Prettier pass, and schema.sql matches a rebuild.

@gkhngyk
gkhngyk merged commit 3a4fcde into ansvisor:main Oct 22, 2026
5 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.

2 participants