Skip to content

feat(signals): show where a competitor beats you, prompt by prompt - #1063

Merged
gkhngyk merged 43 commits into
ansvisor:mainfrom
cihan-gyk:feature/competitor-signal-evidence
Oct 17, 2026
Merged

gkhngyk merged 43 commits into
ansvisor:mainfrom
cihan-gyk:feature/competitor-signal-evidence

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Part two of AC-001, for competitor signals. Stacked on #1061, which sits on #1060, #1059 and #1058. Please review the fifth commit, feat(signals): show where a competitor beats you, prompt by prompt, or merge those first.

The spec asks a competitor signal for "per prompt and platform: competitor position vs our position, with the change (e.g. 'Profound #1 ↑2 · You #3 ↓1 on ChatGPT'), the source domains that drive their wins". Until now these signals were recorded with the competitor's name and one number, so the drawer from #1060 said "Not available" for both.

Migration 00142_competitor_signal_positions.sql

ae_competitor_positions(brand, competitor_ids, cur/prev windows, limit):

  • Source: reads the daily rollups insights_competitor_prompt_daily and insights_prompt_daily, not the answers, like the other ae_* detector reads.
  • Positions: a harmonic mean from the same columns on both sides (position_count / sum_inv_position), so the competitor's and the brand's positions compare like with like.
  • Rows kept: only where the competitor is level with or ahead of the brand, or the brand isn't named. A row where the brand leads is not evidence for a competitor signal.
  • Order: biggest lead first, at most 5 per competitor, each with this week's and last week's position for both sides.
  • Access: service role only.

schema.sql is regenerated. I checked it in a rolled-back transaction on the dev database with temporary rollup rows:

Case Result
Competitor 1st this week (3rd before), brand 3rd (2nd before) Returned with those positions
Brand absent this week Ranked first
Brand ahead Left out

Then I applied it there.

Server

signals/competitor-evidence.js runs for competitor_leads, competitor_momentum, competitor_surge, competitor_crossed, competitor_overtaken and competitor_citation_gap. The competitor id comes from the payload (library kinds) or the dedup key (pulse kinds).

  • positions: the rows above, with the prompt's text.
  • winningSources: the domains most cited in the latest answers the competitor wins (it is named, the brand is not), from at most 60 such answers, shopping excluded. The brand's own domains never count; the competitor's do.
  • Best effort: a failure keeps an earlier night's evidence (keepRecordedEvidence now covers these kinds), and overflow signals past their kind's cap get it too.

Web

  • Positions by prompt: one line per prompt and platform, e.g. "ChatGPT · Profound fix(tracking): keep job active until webhook results drain #1 ↑2 · You chore(seo): block search indexing on the app subdomain #3 ↓1", or "You — lost". The prompt links to its page.
  • Colours: news for the brand, as in What changed. The competitor's climb and your fall are red; your climb and their fall are green.
  • Platforms: the platforms it leads on.
  • Sources behind their wins: e.g. "coffeereview.com · cited in 5 of the 8 latest answers they win".
  • MCP: list_signals returns where.competitor_positions (with platform names) and where.winning_sources.

Review

I ran a code review before opening this. Fixed:

  • competitor climbs coloured green;
  • the sources count not saying it is a sample;
  • rows where the brand leads filling the list;
  • shopping answers counted;
  • per-competitor reads run in series;
  • reading answers that name the brand, now filtered in the query.

Left as is: nothing in CI runs the SQL. It was checked by the dry run above.

Related issue

None. Product spec AC-001 (Action Center), part 2 for competitor signals. Topic-level competitor findings (competitor_topic_lead, competitor_uncovered_topic) don't name a competitor yet and are not covered here.

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

  1. Apply 00142_competitor_signal_positions.sql.
  2. Run a signal pass for a brand with competitor signals, or wait for the nightly one.
  3. Open a competitor signal ("… is gaining fast", "… is mentioned far more than you"):
    • Positions by prompt with both positions and their moves;
    • the platforms it leads on;
    • Sources behind their wins.
  4. Call MCP list_signals: where.competitor_positions and where.winning_sources.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors; the 7 warnings are in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • server: npm run format, npm run lint (clean), and npm test 1191/1191. New tests:
    • competitor-evidence.test.js: winning sources, the positions read and its windows.
    • record-evidence.test.js: competitor id from payload or key, a failed read, kept evidence.
  • web: yarn test 604/604 (detail and drawer blocks, including the colours) and yarn build.
  • bash supabase/build-schema.sh: schema.sql is up to date.
  • In the browser: the drawer of a competitor signal with evidence, in light and dark mode, at 1440px and 1024px.

🤖 Generated with Claude Code

cihan-gyk and others added 5 commits October 15, 2026 14:20
…ls by platform

The Signals list never said which AI platform or location a signal was
about, and named platforms by their raw ids ("Visibility dropped on
gemini-web", "Weak in JP"). Part one of AC-002:

- Each row's Affected cell gets a line with the engines and locations the
  signal is about: from the payload for platform and country signals, and
  from the prompts' tracked platforms and locations for prompt and topic
  signals. A line rather than a column keeps the table within the page
  beside a pinned sidebar.
- Platforms and locations read as people know them ("Gemini", "Japan").
- Descriptions carry the measured fact instead of a generic sentence, e.g.
  "Your mention rate fell from 34% to 18% against the week before."
- A Platform filter, search over platform and location names, and
  platforms and locations columns in the CSV export.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A brand can track the same prompt text as several prompts, and the
detectors write one signal per prompt: on production one pass wrote ten
identical "Citations lost for '…'" rows, which read as duplicates and
inflated every count. Part two of AC-002:

- Signals of one kind, about one prompt text (case, spacing and the
  closing "?" ignored), found in one pass are one row with a "×N grouped"
  toggle. Opened, it lists each copy with its topic, place and status; each
  copy keeps its own drawer and menu, and the group's menu acts on the
  copies it applies to.
- The category tabs, the tab badge and the summary cards count groups.
  Migration 00141 adds signal_group_key (the same rule as
  lib/signals/group.ts), counts signals_summary over groups, where a group
  is resolved only once every copy is, and adds signals_new_count for the
  badge.
- A drawer opened from a link to a copy opens its group.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hat it rests on

The signal drawer showed bare numbers ("0 → 251 +167") and no platform,
location, page or action. Part one of AC-001: the drawer has three blocks.

- Where: the fields the spec asks per category (prompt, topic, platforms,
  locations, domain, competitor, pages, queries, and for a lost citation
  the page cited before and who is cited now). A field no detector records
  yet says "Not available"; platforms read from a signal's prompts say
  "Tracked on".
- What changed: every figure with its metric, whose or which window, and
  unit, over its period: "Mention rate · previous 7 days 34% → last 7 days
  18%, −16 pts". A source domain's three counts are named instead of read
  as a before and after. A fall in the brand's own numbers is red, a
  competitor's rise too (the old colouring showed drops as good news).
- Evidence and links: the page behind the signal (the prompt's answers, the
  topic, Citations…), first and last detection, and the actions using it.

MCP list_signals returns the same detail per signal (where, change,
evidence, used_by_actions) beside the raw row, from lib/signals/detail.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A lost citation was recorded with its prompt only, so the drawer could not
say which page lost its citation, where, or who replaced it. Part two of
AC-001, for lost citations:

- The recorder reads the lost prompts' answers back (server
  signals/lost-citation-evidence.js) and writes, with the signal: the
  platforms and locations it was lost on, the brand's page cited before
  with its position and last cited date, the pages cited in the quiet
  answers with their position and how many of the answers read cite them,
  and its cited days before and since. Best effort, and a night whose read
  fails keeps the evidence an earlier night recorded.
- The drawer shows them: Platforms and Locations (where it was lost),
  "Your page cited before", "Cited now", and "Cited days · earlier 9 / 11
  → latest 0 / 3". A loss on one platform names it in the title ("Citations
  lost on ChatGPT for …"), and the row says which page is no longer cited.
- MCP list_signals returns the same evidence.
- ownDomainMatcher is the own-domain rule countOwnDomainCitations already
  used, now shared.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A competitor signal named the competitor and one number, so the drawer had
"Not available" for positions by prompt and the sources behind its wins.
Part two of AC-001, for competitor signals (leads, gaining, surge,
crossed, overtaken, citation gap):

- Migration 00142 adds ae_competitor_positions: per competitor, the prompts
  and platforms where it is level with or ahead of the brand, with both
  positions this week and last, from the daily rollups (harmonic mean of
  mention positions). Service role only, like the other detector reads.
- The recorder writes, with each competitor signal, those positions and the
  domains most cited in the latest answers the competitor wins (named, the
  brand not). Best effort, and an earlier night's evidence is kept when a
  read fails.
- The drawer shows "Positions by prompt" ("ChatGPT · Profound #1 ↑2 · You
  #3 ↓1", "You — lost"), coloured as news for the brand, the platforms it
  leads on, and "Sources behind their wins". MCP list_signals returns them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 15, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Part 2 of AC-001 for competitor signals, stacked on #1061 → #1060 → #1059 → #1058 (please review the fifth commit or merge those first). Migration 00142 adds ae_competitor_positions (service role only, reads the daily rollups); competitor signals now carry per-prompt positions against yours and the sources behind their wins, shown in the drawer and MCP list_signals. Applied on my dev database.

…-signal-evidence

# Conflicts:
#	supabase/schema.sql
…-signal-evidence

# Conflicts:
#	supabase/schema.sql
cihan-gyk and others added 20 commits October 16, 2026 11:36
…ure/signals-grouping

# Conflicts:
#	supabase/schema.sql
…ure/signals-grouping

# Conflicts:
#	supabase/schema.sql
…ure/signals-grouping

# Conflicts:
#	supabase/schema.sql
…signal-evidence

# Conflicts:
#	supabase/schema.sql
…signal-evidence

# Conflicts:
#	supabase/schema.sql
…gnal-evidence

main carries ansvisor#1058 through ansvisor#1061 as squashes; this branch keeps only its own commit on top, with schema.sql regenerated.
A SQL-language function is planned without its argument values, so the
day range was a guess: on the largest brand, with its 19 competitors over
two weeks, the read took 28.6 s. As 00147, 00148 and 00152 do, the
function becomes plpgsql with force_custom_plan and work_mem, and takes
0.16 s with the same 80 rows. The body is unchanged.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A

@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.

Thanks, approving. I merged main into the branch, so it keeps only its own commit on top of #1061, and added one commit, perf(signals): plan ae_competitor_positions with its arguments.

ae_competitor_positions was a SQL-language function, planned without its argument values. On production, for the largest brand with its 19 competitors over two weeks, the read took 28.6 s. As plpgsql with force_custom_plan and work_mem, as 00147, 00148 and 00152 do, it takes 0.16 s as the service role and returns the same 80 rows. The body is unchanged. 00142 is applied on production in that form, execute only for the service role. CI is green.

@gkhngyk
gkhngyk merged commit cb68865 into ansvisor:main Oct 17, 2026
5 checks passed
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 17, 2026
…l-evidence

main now carries ansvisor#1063 as a squash; the tree is the one CI 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