Skip to content

feat(prompts): say when a new location's first results come, and when the plan's locations are used up (PROMPT-015, part 6) - #1660

Merged
gkhngyk merged 56 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-location-pending
Oct 28, 2026
Merged

gkhngyk merged 56 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-location-pending

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

PROMPT-015, part 6 of 6: say when a new location's first results come, and when the plan's locations are used up.

Stacked on #1659. This PR's own change is its commits after part 5's.

A location just added to a prompt showed a bare dash until the next daily run. Its cells now say when its answers come, or why they won't:

  • Within 24h: tracked there, and asked by the next daily run.
  • Paused: the prompt is paused.
  • No engine here: none of the prompt's engines answers from that country or city, going by the engines' country lists (part 5).

A custom range that ended before today keeps the plain dash. Once the plan's prompt locations are used up, + Track reads Limit reached and still opens the dialog with the plan's way out. The dialog's toast says the first results come within 24 hours.

Pre-push review fixes:

  • 13f8a37: a custom range is read on the viewer's clock. A range that ended yesterday counts as past, not as "Within 24h".
  • 00c289f, "No engine here":
    • In a US state, the run asks Google's engines country-wide and saves their answers as the country's. A Google-only prompt's state cell now says "No engine here" instead of "Within 24h" forever.
    • An engine whose country list was never read is asked everywhere, so the cell no longer says no engine answers for it.
  • 6363eb2: "Within 24h", "Paused" and "No engine here" are focusable, with their reason in a tooltip on hover and on keyboard focus, and given to screen readers as the description. "Limit reached" announces that the plan's locations are used up.
  • a57d9d8: a test keeps the provider models, and the engines left out of a US state, the same on the web and the API.

Where people see it: Prompts › Tracked Prompts › Locations, in a new location's column.

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. Add a country to a few prompts: their cells say "Within 24h". Tab to one; the tooltip says why.
  2. Pause one: its cell says "Paused". Pick a custom range that ended yesterday: the plain dash.
  3. Add US-CA to a prompt tracked only on Google AI Overviews and AI Mode: "No engine here".
  4. Use up the plan's locations: + Track reads "Limit reached" and opens the dialog.
  5. cd web && npx vitest run src/lib/prompt-location-matrix.test.ts src/lib/tracking-countries.test.ts

Browser check: local, 1024 px, light and dark. The tooltip opens on keyboard focus.

Related issue

PROMPT-015 (location matrix and custom columns), spec and mockup in Drive › Prompt. No GitHub issue.

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

Full checks at the top of the stack (part 6, 29f649d):

  • server format, lint and npm test: 248 files, 3,364 tests passed;
  • web format, lint (0 errors; 7 warnings already on main), typecheck, vitest (453 files, 4,403 tests) and build: all pass;
  • schema.sql matches build-schema.sh.

A pre-push review found 9 issues; all are fixed in this stack (the fix(...) commits). Migrations 00363 and 00364 are applied on the dev database.

Follow-ups, not in this stack:

🤖 Generated with Claude Code

cihan-gyk and others added 30 commits October 28, 2026 03:46
…columns, and share them with the brand (PROMPT-015, part 1)

PROMPT-015a. A Columns panel beside the table's search:
- show or hide every column but Prompt, and reorder them by dragging or with
  the arrows;
- saved per person and brand (00363 prompt_table_views, RLS);
- an admin or manager can share their columns with everyone on the brand,
  who see them until they change their own;
- Reset goes back to the brand's view, or the default.

Nobody who never opens Columns sees a change: the default is today's
columns in today's order. The table builds its header and cells by column
id, unchanged inside.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Locations view (PROMPT-015, part 2)

PROMPT-015b. A Table | Locations switch above Tracked Prompts:
- Locations shows each prompt in each location the brand tracks, side by
  side: Visibility, Position, Mentions or Citations; an average row; a Gap
  column (best minus worst location); and three cards: the weakest and
  strongest location and the prompt that differs most between them.
- Cells use Brand Visibility's Topics vs competitors shades (HEAT_SHADES,
  moved beside heatShade). A cell opens the prompt's Positions panel on that
  location; a location the prompt isn't tracked in offers + Track (its Edit
  dialog for now).
- The Columns panel can add "<metric> · <location>" columns to the table.
- getPromptLocationMatrix reads each location with the table's own reads
  (visibility summaries, position sums), side by side, so a location's
  numbers equal the table filtered to it. No migration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… brand (PROMPT-015, part 1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aving, with more countries (PROMPT-015, part 3)

PROMPT-015c. Track in more locations, from the Locations view's
+ Add location or a cell's + Track:
- pick countries or US states (LocationPicker), and the prompts to ask
  there: the one clicked, the selected, a topic, or all shown;
- Plan usage shows used → after of the plan's prompt locations before
  anything is saved, with the same arithmetic the save enforces
  (planBulkLocationChange, bulkUpdatePromptLocations);
- past the limit the dialog says what the choice needs and what is left,
  with the plan's way out (Starter: upgrade or a custom plan; Growth: a
  custom plan; Enterprise: raise the limit), and Save stays off.

Prompts can be tracked in about 50 countries (TRACKING_COUNTRIES), not 18;
a brand's own region keeps the shorter list that volumes and audits read.
PromptLimitActions moves to its own file (a page can't export it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n answer from one (PROMPT-015, part 4)

PROMPT-015d. A city is the location code `<country>~<CITY>` (`TR~ISTANBUL`),
51 major cities in both lists (server/src/lib/cities.js,
web/src/config/cities.ts; same ids):
- Google AI Overview and AI Mode ask from the city: the provider gets the
  city's Google canonical name as `location` beside the country.
- The API models (OpenAI, Claude) get `user_location` with the city and its
  region.
- ChatGPT, Perplexity, Copilot, Gemini and Grok can't target a city through
  the provider, so locationsForScraper skips city codes for them: no second
  country-wide run, no double cost. A prompt tracked only in cities runs
  nothing on them.
- A city counts one location on the plan, like a country (decision 6), on
  every plan.

Web: the location picker lists cities ("City · Turkey") with a note on which
engines ask there; the Locations view marks a city column "AI Mode · AIO ·
APIs"; Track in more locations turns a city off, and says why, when none of
the chosen prompts runs one of those engines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ound of reads (PROMPT-015, part 2)

The user's bar: data within 1–2 s of a choice. Measured locally (dev, hosted
dev DB) the matrix read took 1.4–1.8 s.
- getPromptLocationMatrix starts every read at once: the plan's engines no
  longer wait in front of the locations' reads.
- A matrix read stays a minute in the browser (loadLocationMatrix), so going
  Table ↔ Locations, or back to a location column, reads nothing again;
  switching the metric was already in the browser.
- The Locations button reads ahead on hover or focus, so the view opens on
  data already there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d-locations

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
…from, read daily from the provider (PROMPT-015, part 5)

PROMPT-015e. The tracking provider supports a different set of countries
per engine, and asking an engine in a country it doesn't support fails;
its GET /v1/countries?model= is the only source of truth (its docs publish
no list). So:
- The daily run reads every engine's list before tracking
  (refreshCloroCountries) into cloro_countries (00364). A list that can't be
  read keeps the last one; an empty or malformed answer never empties it.
  No provider key (self-hosted, local): nothing read, nothing restricted.
- The tracking run skips an engine in a country it doesn't support
  (supportedLocations), and logs how many pairs it skipped: no failed task,
  no spent credit.
- The location picker offers the countries the engines answer from, named
  by the runtime's own region names, with "not on <engine>" where one
  doesn't; cities only where Google's engines answer. Before the first read
  it keeps its own list. Any country code is now valid on save.

Real lists need the provider key: gkhngyk was asked on ansvisor#1625 to paste them,
to check the first read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the plan's locations are used up (PROMPT-015, part 6)

A location just added to a prompt showed a bare dash until the next daily
run. Its cells now say when its answers come or why they won't:

- "Within 24h": tracked there, asked by the next daily run;
- "Paused": the prompt is paused;
- "No engine here": none of the prompt's engines answers from that
  country (or city), from the engines' country lists (00364).

A custom range that ended before today keeps the plain dash. Once the
plan's prompt locations are used up, + Track reads "Limit reached" and
still opens the dialog with the plan's way out. The dialog's toast says
the first results come within 24 hours.

useTrackingCountries moves into its own module so the matrix can share
it with the location picker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…their own view with the brand (PROMPT-015, part 1)

Someone looking at the brand's shared view without one of their own
changed it with every click: a member got "Only admins and managers can
share" errors, and a manager hiding one column changed it for everyone.
Changes now update the brand's view only after an admin or manager
shared their own, which sharing now also saves as theirs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…able (PROMPT-015, part 1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ations-view

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/_columns-panel.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/_columns-panel.tsx
… and each location once a minute (PROMPT-015, part 2)

Up to twelve locations ran two heavy aggregates each, all at once, on
every open, every read-ahead on hover and every new location column.
The server now runs at most three of them at a time, the page sends one
read at a time, read-ahead included, and each location's figures are
kept for a minute on their own, so a new location column reads only its
location.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed, resumed, deleted or edited (PROMPT-015, part 2)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d-locations

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
…o longer shown, not to every prompt (PROMPT-015, part 3)

Track in more locations opened from a Locations view cell fell back to
every prompt shown when the cell's prompt had left the rows. It now
targets none, says to choose the prompts, and keeps the save button off
until a scope is picked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y-tracking

# Conflicts:
#	web/messages/en.json
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/_add-locations-dialog.tsx
…ntry-wide under its name (PROMPT-015, part 4)

An unknown city code read as its country: Google's engines ran without a
location and the API models without a city, and both answers were saved
with the city's code. The worker now skips such a code for every engine
and logs it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o, and ask Google from its cities as Turkiye (PROMPT-015, part 4)

The location lists, labels and docs say Türkiye. The picker finds it,
and its cities, typed as Turkey or Turkiye. The cities' Google location
names spell the country Turkiye, from one constant, to be confirmed
with a real request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iye name (PROMPT-015, part 4)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e same on the web and the API (PROMPT-015, part 4)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ro-countries

# Conflicts:
#	server/src/workers/tracking-worker.js
#	supabase/schema.sql
#	web/src/components/dashboard/location-picker.tsx
#	web/src/lib/region.test.ts
…try lists (PROMPT-015, part 5)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 9 commits October 28, 2026 05:22
…e viewer's clock, not as within 24 hours (PROMPT-015, part 6)

A range ending yesterday still counted as reaching today, since its last
moment was less than a day ago, so its locations said "Within 24h". A
range now reaches today only when it ends at or after the start of today
in the viewer's time zone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s would ask, and not for an engine with no country list (PROMPT-015, part 6)

The run asks Google AI Overview and AI Mode country-wide in a US state
and records their answers as the country's, so a Google-only prompt's
state cell said "Within 24h" for good. It now says no engine answers
there. An engine no country list was read for is asked everywhere by the
run, so the cell no longer says no engine answers for it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… no answers yet, and name a used-up limit as such (PROMPT-015, part 6)

"Within 24h", "Paused" and "No engine here" kept their reason in a title,
which only a mouse reaches. They now show it in a tooltip on hover and
on keyboard focus, and give it to screen readers as the description.
"Limit reached" was announced as "Track … in …"; its label now says the
plan's locations are used up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…of a US state, the same on the web and the API (PROMPT-015, part 6)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a promise (PROMPT-015, part 2)

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

mintlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 7cc4c4c.

Approve preview

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
cihan-gyk and others added 13 commits October 28, 2026 13:08
…no runs in the range

"Within 24h" showed in every tracked location without answers in the
range, so an older prompt whose runs were missing or failed in it read as
a new one. A location now says it only while its first answers can still
come from the next daily run:

- the prompt was added within the last 48 hours; or
- it has answers in another location in the range, so this one was most
  likely just added.

Otherwise the cell keeps the plain dash ("No answers here in this
period"). "Paused" and "No engine here" are unchanged, whatever the
prompt's age. Applies to the Locations view and the Table view's
location columns; the guide says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…le-columns

# Conflicts:
#	supabase/schema.sql
…ro-countries

# Conflicts:
#	server/src/lib/catalog/__fixtures__/fake-db.js
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward (8356ba3) via #1659; no new conflicts, and it carries the local fix 1a80a87. Typecheck passes.

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

Looks good, with follow-ups

Reviewed this PR's own change (part 5's head be050b1 → 29f649d). No migrations.

What I checked

  • Pending cells. "Within 24h", "Paused" and "No engine here" follow what the run actually asks. answersFrom mirrors the API: a city only on Google's engines, a US state never on them, an engine only in a country its list includes, and an unlisted engine or one with no list asked everywhere. The new tests keep the provider models and the US-state rule the same on the web and the API. A custom range that ended before today, on the viewer's clock, keeps the plain dash.
  • Limit reached. It's read from getLocationQuota, which is the org's usage against the plan computed on the server. The button still opens the dialog, and the dialog and the server action still enforce the cap. This PR doesn't change any write path.
  • Reads. The engine lists are read once per page (a module-level promise shared by every cell), and the quota once per brand or tracked-count change. Neither runs once per cell.
  • Accessibility. The reason sits in a tooltip on hover and on focus, and in an sr-only description. "Limit reached" carries the counts in its label.
  • Copy. It reads well; the guide's new section matches the behaviour.
  • Tests on this tree: web prompt-location-matrix, tracking-countries, region, location-picker, _add-locations-dialog, _location-matrix, _columns-panel (60 passed); web tsc clean; eslint and prettier clean on the touched files; full server suite passes apart from the known timing-sensitive tests under load.
  • Merge on current main: it carries part 5's fake-db.js conflict (see #1659) and the schema.sql one. Its own files merge cleanly.

Follow-ups

  1. "Within 24h" is shown for any tracked location with no answers in the window, not only a new one. A location that has been tracked for weeks without answers (failing tasks, for example) says "Within 24h" every day. When the prompt's created_at and the window's start allow it, that case could keep the dash or say "No answers yet".
  2. answersFrom returns true for an engine with no provider model (Grok) before it checks the city. A Grok-only prompt in a city says "Within 24h", but the run never asks Grok from a city. Check location.city first.
  3. "Limit reached" also shows on a paused prompt's empty cells, where adding a location wouldn't count until the prompt is resumed. This is minor, since the dialog prices it correctly.

@gkhngyk
gkhngyk merged commit cfd8a35 into ansvisor:main Oct 28, 2026
5 of 6 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants