Skip to content

feat(prompts): add an Improve tab with platform-specific position suggestions - #1011

Merged
gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-improve-tab
Oct 13, 2026
Merged

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-improve-tab

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1010. This branch includes #1010's commit (the panel's own date range), which the Improve tab builds on. Please review and merge #1010 first; the new work is the last commit, b597b18.

Not yet tested against a real model. No AI provider key was available locally. Generation, sanitizing and the budget are covered by unit tests, and the UI was exercised end to end with a hand-written suggestion set in the cache table. The first real runs are worth a look for suggestion quality and actual token cost.

Summary

PROMPT-003. The Positions panel gets an Improve tab, next to Platform results and Daily history. For one prompt over the panel's range, it tells the user what to do on each AI platform where the brand is missing or ranked late.

States, per platform over the window:

State When Kind of suggestion
Not mentioned tracked, brand never appears coverage gaps, pages to create, third-party sites to get listed on
Mentioned · Late average mention position below #1, or no stored position positioning, attributes, on-page structure
Mentioned early · not cited #1, but not cited, or cited past the first third citation-focused
Doing well #1 and cited early none
No runs in this period nothing tracked none

Grounded suggestions. For each actionable platform, the server aggregates that platform's own evidence:

  • fan-out sub-queries (search_queries)
  • cited domains
  • competitor URLs and the competitors named (competitor_mentions)
  • the brand's cited pages
  • an excerpt of the newest answer

The aggregation is capped, so the input stays ~6–8k tokens however much data a prompt has. One generateObject call returns {platform, title, body, sources:[{type, ref}], confidence} items. sanitizeSuggestions then:

  • keeps a source only when its ref is found in that platform's evidence; invented sub-queries, URLs and quotes are dropped
  • drops a suggestion left with no real source
  • drops placeholder text such as prompt [0]
  • caps each platform at 3 suggestions

Panel UX.

  • Suggestions are grouped by platform. Each group header says why the platform is listed (e.g. "avg chore(seo): block search indexing on the app subdomain #3.4 of 6 · 8 of 8 runs") and which inputs were used ("No fan-outs recorded. Based on 4 cited domains · AI answer").
  • Each card has a checkbox, title, body and source chips. Cards can be edited inline or removed (with Undo), and "Add your own suggestion" is available per platform.
  • The footer shows "x of y selected · n platforms" and Regenerate.
  • The tab badge shows the count.
  • Changing the panel range or regenerating with unsent edits asks first.
  • Drafts live in the panel until sent. Sending to Action Center is PROMPT-004, a follow-up.

Cost control (product decisions)

Generation is metered, so these are deliberate:

  • Never automatic. The first set is built by Generate suggestions, and a rebuild by Regenerate. When newer runs exist, the tab shows "New runs have arrived since these suggestions were generated" instead of rebuilding on open.
  • Cached per (prompt, range, location) in prompt_improve_suggestions. Reading a cached set is free.
  • Monthly budget = 1% of the plan price, charged at each call's real token cost, so the share holds whichever model IMPROVE_SUGGESTION_MODEL points at.
Plan improveMonthlyBudgetUsd ≈ generations on Gemini 3 Flash
Starter 0 (feature is Growth+) —
Growth 2.49 ~260
Enterprise 4.99 default, or 1% of plan_overrides.contractMonthlyUsd (never below the default); an explicit plan_overrides.improveMonthlyBudgetUsd wins ~525 at the default
Self-hosted unlimited —
  • server/src/lib/improve-cost.js holds the per-model price table. A model missing from it is charged at a deliberately expensive fallback, so it can only use the budget up faster, never overspend. Keep this table in sync with provider prices.
  • Users never see dollars. The panel shows "About N generations left this month", estimated from the org's median recent cost so one outlier doesn't swing it. Hovering shows the % of budget left.
  • The budget is enforced on the server (429 quota_exceeded), and the panel keeps the current set when it's hit.

Setting a custom contract's budget (Enterprise orgs only):

update organizations
set plan_overrides = coalesce(plan_overrides, '{}'::jsonb) || '{"contractMonthlyUsd": 1000}'::jsonb
where id = '<org id>';

Database

supabase/migrations/00120_prompt_improve_suggestions.sql adds two tables. Both have RLS on and no policies (service role only, like action_candidates / brief_usage):

  • prompt_improve_suggestions: cached sets, unique on (prompt_id, range_key, region)
  • prompt_improve_usage: one row per model call with model, tokens and cost_usd

schema.sql is regenerated. This migration needs applying to the hosted database.

API

Both routes sit under requireFeature('prompt_improve'), a new feature flag on Growth, Enterprise and self-hosted:

  • GET /api/prompts/:promptId/improve?preset&from&to&customFrom&customTo&region returns the cached set, stale, and the quota estimate. It never generates.
  • POST /api/prompts/:promptId/improve (same fields in the body) enforces the budget, generates, records the cost, upserts the cache, and returns the set.

Related issue

None. Product task PROMPT-003 ("Improve tab: platform-specific position suggestions").

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 the migration and set an AI key (e.g. GOOGLE_GENERATIVE_AI_API_KEY) in server/.env.
  2. On a Growth or self-hosted org, open Prompts → See on a prompt with runs, then the Improve tab, then Generate suggestions.
  3. Check that each card's chips point at real sub-queries, URLs or answer text for that platform.
  4. Edit, uncheck, remove with Undo, and add your own; the footer and badge follow. Change the range: you're asked first.
  5. Run a new tracking run, reopen the tab, and the "New runs" notice appears.
  6. With IS_CLOUD=true and a Growth org, prompt_improve_usage gets a row with tokens and cost_usd, and the counter goes down. Set the org to Starter and the tab shows "Improve is available on Growth".

What I checked locally (cloud and self-hosted, light and dark, 1024px):

  • the UI with a cached set
  • the missing-key error
  • the Starter lock
  • "About 262 / 162 / 784 generations left" for Growth fresh, after 100 calls, and a $1,000 contract
  • budget exhaustion: buttons disabled, and the server rejects even when the UI is bypassed

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 (476) and yarn build (CI placeholder env) pass in web/. npm run lint, npm run format:check and npm test (1063, including 32 new in prompt-improve.test.js, improve-cost.test.js and plan-guard.test.js) pass in server/. bash supabase/build-schema.sh leaves schema.sql unchanged.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 13, 2026 13:39
The Positions panel was fixed to the table's range, so checking a prompt
over another period meant changing the whole table. The panel now has its
own 24h / 7d / 30d / 90d / Custom control. It opens on the table's range,
and changing it reloads only the panel. The open prompt and the panel's
range are mirrored to the URL (?positions=<id>&positionsRange=7d) so the
view can be shared. A custom range no longer spells its dates twice in
the header.

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

For one prompt and the panel's range, the Positions panel gets an Improve
tab: per AI platform where the brand is not mentioned, mentioned late, or
mentioned early but not cited, AI-generated suggestions grounded in that
platform's own evidence (fan-out sub-queries, cited domains, competitor
URLs, the answer text). The server checks every source against that
evidence and drops invented ones, so each card names something real.
Suggestions are editable drafts: check, edit, remove (undoable) or add
your own.

Generation is always the user's click and is metered: each call's real
token cost is charged against a monthly budget of 1% of the plan price
(Growth $2.49, Enterprise $4.99 or 1% of plan_overrides.contractMonthlyUsd),
so the share holds whichever model IMPROVE_SUGGESTION_MODEL points at.
Sets are cached per prompt, range and location; newer runs show a
"Regenerate" notice instead of rebuilding automatically. Growth+ only.

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 13, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk this one (PROMPT-003, Improve tab) is ready for review too. It's stacked on #1010, so please merge that first. It also adds a migration, and per the description it hasn't been run against a real model yet.

@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, this is a solid feature. I ran the generation against the real model, read-only: 4 prompts on our own test brand, 30-day window, google/gemini-3-flash-preview, 2 generations each.

Result
Schema failures 0 of 8
Tokens per generation ~4.3k input, ~2.1k output
Cost per generation ~$0.0086, so about 290 on the Growth budget
Latency 9–16 s (one run over the 15 s the panel mentions)
Suggestions 41 returned, 41 kept
Sources 92 of 103 matched the evidence; the rest were dropped as intended

The suggestions were specific and grounded in the answers. Three things to fix before merge, plus a rebase.

Required

  1. The state ignores how often the brand is mentioned. classifyPlatform calls a platform not_mentioned only when no run in the window mentions the brand. Otherwise it judges position alone. In the pilot:

    • a platform where the brand appeared in 8 of 120 answers, at #1, came out doing_well, with no suggestions;
    • platforms with 1 of 71 and 1 of 65 came out mentioned_late.

    These are mostly-missing platforms, and they get the positioning advice instead of the coverage advice. The impact score in #1012 inherits the same state. Please factor in the mention rate, e.g. treat a platform mentioned in fewer than half of its runs as not mentioned. Show "mentioned in 8 of 120 runs" in the header, so the reason stays visible.

  2. Retry can spend budget on a read. When the GET fails, the error state's Retry calls generate, a paid call. A failed Regenerate also clears the set already on screen. Retry the read when the read failed, and keep the current set when a generate fails, as on quota_exceeded.

  3. Rebase on main. #1010 was squash-merged, so the stacked commit now conflicts in prompt-positions-sheet.tsx.

Should fix

  • Failed calls aren't charged.
    • The usage row is written only after a successful call, so attempts that withRetry repeats never reach prompt_improve_usage. They were rare in the pilot, but they are still spend.
    • NoObjectGeneratedError carries usage, so failed attempts can be recorded too.
    • The insert's error isn't checked.
  • The price table misses OpenRouter ids. An openrouter/google/... model id isn't in MODEL_PRICES and falls back to $5 / $25. That would use the budget up about 8 times faster. Strip the openrouter/ prefix in priceFor.
  • States use only the newest 600 rows. Platform results reads the whole window. One pilot prompt had 615 results in 30 days, so the two tabs can disagree. Classifying from the light columns over all rows, and using the 600 for evidence only, would keep them in line.
  • server/.env.example has a stale name. It refers to maxImproveGenerations; the limit is improveMonthlyBudgetUsd.
  • Any member can spend the budget. Any member can generate and spend the organization's budget. Fine if intended.

cihan-gyk and others added 2 commits October 13, 2026 20:53
# Conflicts:
#	web/src/components/prompts/prompt-positions-sheet.tsx
- Treat a platform mentioned in fewer than half its runs as not mentioned,
  and show "mentioned in X of Y runs" in each platform header.
- Retry on a failed read re-reads the cache instead of generating; a failed
  generate keeps the set already on screen.
- Charge every model attempt, including schema misses withRetry repeats,
  and log a failed usage insert.
- Price openrouter/ model ids as the model they route to.
- Classify platforms from every answer in the window, like the Positions
  tab; keep the newest 600 for evidence only.
- Fix the stale budget name in server/.env.example.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk thanks for the pilot run and the detailed review. All addressed in a9d2cc4.

Required

  1. Mention rate. A platform where the brand appears in fewer than half its runs is now not_mentioned (MIN_MENTION_RATE = 0.5), so it gets coverage advice. Each platform header shows "mentioned in X of Y runs", and the model prompt says "mentioned in only X of Y runs" for these platforms. feat(prompts): send selected Improve suggestions to Action Center #1012's impact score picks up the new states automatically.
  2. Retry. A failed read lands on the error state, and its Retry now re-reads the cache (reload). It never generates. A failed generate keeps the set and edits already on screen and shows the error inline, as quota_exceeded does.
  3. Main. Merged main into the branch instead of rebasing, which avoids a force push; the result squashes the same way. The prompt-positions-sheet.tsx conflict is resolved, and the PR is mergeable again.

Should fix

  • Failed calls are charged. Every attempt is recorded, including the ones withRetry repeats: a successful call with its usage, and a NoObjectGeneratedError with err.usage. A failed usage insert is now logged.
  • OpenRouter ids. priceFor strips the openrouter/ prefix, so openrouter/google/gemini-3-flash-preview is priced as Gemini 3 Flash.
  • States over the whole window. States are now classified from the light columns of every answer in the window (paged, up to 5,000, like the Positions tab). Source lists are fetched only for cited answers. The newest 600 are used for evidence only.
  • .env.example. Now refers to improveMonthlyBudgetUsd.
  • Any member can spend the budget. This is intentional. Generating is part of the everyday workflow, and the dollar budget caps the spend.

Checks: server lint/format and tests pass (1096), and web lint, typecheck, tests (490) and build pass.

@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, all addressed. Migration 00120 is applied to production.

@gkhngyk
gkhngyk merged commit f78b4b6 into ansvisor:main Oct 13, 2026
5 checks passed
gkhngyk added a commit that referenced this pull request Oct 14, 2026
…#1019)

* feat(content): show and enforce the monthly content opportunity quota

Plans get a monthly limit on new content opportunities (Starter 10,
Growth 50, Enterprise/self-hosted unlimited), counted separately from the
existing brief quota and renewing with the subscription. Usage is recorded
in opportunity_usage, so dismissed and deleted opportunities still count.

The nightly generation claims slots atomically per organization
(claim_opportunity_usage) before calling the model and hands back the ones
it doesn't use. The Content page leads its stat row with a usage card for
both counters, and GET /api/content/usage exposes the same figures.

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

* feat(prompts): show tracked prompt usage against the plan limit (#1009)

The Tracked Prompts page showed only "All Prompts (N)", with no sign of the
plan limit or how many slots were left, so users found out at save time.
The header now shows "used / limit prompt locations · <plan> plan" with a
progress bar and the slots left (amber from 80%, red when full or over).
When the limit is reached, Add prompt explains it with Upgrade plan
(Starter) or Contact us (Growth / Enterprise) instead of the form.

The numbers come from getLocationQuota, the same org-wide prompt-location
count the plan-limit guard enforces, so the counter can't promise a slot a
save would reject. getPromptsPageData returns it in the page's single
round trip.

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

* feat(prompts): pick the Positions panel's date range inside the panel (#1010)

The Positions panel was fixed to the table's range, so checking a prompt
over another period meant changing the whole table. The panel now has its
own 24h / 7d / 30d / 90d / Custom control. It opens on the table's range,
and changing it reloads only the panel. The open prompt and the panel's
range are mirrored to the URL (?positions=<id>&positionsRange=7d) so the
view can be shared. A custom range no longer spells its dates twice in
the header.

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

* feat(prompts): add an Improve tab with platform-specific position suggestions (#1011)

* feat(prompts): pick the Positions panel's date range inside the panel

The Positions panel was fixed to the table's range, so checking a prompt
over another period meant changing the whole table. The panel now has its
own 24h / 7d / 30d / 90d / Custom control. It opens on the table's range,
and changing it reloads only the panel. The open prompt and the panel's
range are mirrored to the URL (?positions=<id>&positionsRange=7d) so the
view can be shared. A custom range no longer spells its dates twice in
the header.

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

* feat(prompts): add an Improve tab with platform-specific position suggestions

For one prompt and the panel's range, the Positions panel gets an Improve
tab: per AI platform where the brand is not mentioned, mentioned late, or
mentioned early but not cited, AI-generated suggestions grounded in that
platform's own evidence (fan-out sub-queries, cited domains, competitor
URLs, the answer text). The server checks every source against that
evidence and drops invented ones, so each card names something real.
Suggestions are editable drafts: check, edit, remove (undoable) or add
your own.

Generation is always the user's click and is metered: each call's real
token cost is charged against a monthly budget of 1% of the plan price
(Growth $2.49, Enterprise $4.99 or 1% of plan_overrides.contractMonthlyUsd),
so the share holds whichever model IMPROVE_SUGGESTION_MODEL points at.
Sets are cached per prompt, range and location; newer runs show a
"Regenerate" notice instead of rebuilding automatically. Growth+ only.

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

* fix(prompts): address review on the Improve tab

- Treat a platform mentioned in fewer than half its runs as not mentioned,
  and show "mentioned in X of Y runs" in each platform header.
- Retry on a failed read re-reads the cache instead of generating; a failed
  generate keeps the set already on screen.
- Charge every model attempt, including schema misses withRetry repeats,
  and log a failed usage insert.
- Price openrouter/ model ids as the model they route to.
- Classify platforms from every answer in the window, like the Positions
  tab; keep the newest 600 for evidence only.
- Fix the stale budget name in server/.env.example.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

* feat(prompts): send selected Improve suggestions to Action Center (#1012)

* feat(prompts): pick the Positions panel's date range inside the panel

The Positions panel was fixed to the table's range, so checking a prompt
over another period meant changing the whole table. The panel now has its
own 24h / 7d / 30d / 90d / Custom control. It opens on the table's range,
and changing it reloads only the panel. The open prompt and the panel's
range are mirrored to the URL (?positions=<id>&positionsRange=7d) so the
view can be shared. A custom range no longer spells its dates twice in
the header.

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

* feat(prompts): add an Improve tab with platform-specific position suggestions

For one prompt and the panel's range, the Positions panel gets an Improve
tab: per AI platform where the brand is not mentioned, mentioned late, or
mentioned early but not cited, AI-generated suggestions grounded in that
platform's own evidence (fan-out sub-queries, cited domains, competitor
URLs, the answer text). The server checks every source against that
evidence and drops invented ones, so each card names something real.
Suggestions are editable drafts: check, edit, remove (undoable) or add
your own.

Generation is always the user's click and is metered: each call's real
token cost is charged against a monthly budget of 1% of the plan price
(Growth $2.49, Enterprise $4.99 or 1% of plan_overrides.contractMonthlyUsd),
so the share holds whichever model IMPROVE_SUGGESTION_MODEL points at.
Sets are cached per prompt, range and location; newer runs show a
"Regenerate" notice instead of rebuilding automatically. Growth+ only.

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

* feat(prompts): send selected Improve suggestions to Action Center

The Improve tab's footer gets Send Actions: the checked suggestions, exactly
as edited, become one Action Center action (kind prompt_improve, category
compete). Each suggestion is a task with its body, platform and evidence
in the new action_tasks.details column. The action's why and goal are
written from the platform states at send time, its impact from the
prompt's demand and the size of the gap, and its baseline keeps the
positions per platform for PROMPT-008. Validation measures it on its own
prompt.

After a send the button turns into Open in Actions, the footer shows the
action id, and the sent suggestions are marked. The send is recorded on
the cached set, so this survives a reload, and is dropped once the action
is dismissed. An idempotency key per send makes a double click create one
action.

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

* fix(prompts): address review on the Improve tab

- Treat a platform mentioned in fewer than half its runs as not mentioned,
  and show "mentioned in X of Y runs" in each platform header.
- Retry on a failed read re-reads the cache instead of generating; a failed
  generate keeps the set already on screen.
- Charge every model attempt, including schema misses withRetry repeats,
  and log a failed usage insert.
- Price openrouter/ model ids as the model they route to.
- Classify platforms from every answer in the window, like the Positions
  tab; keep the newest 600 for evidence only.
- Fix the stale budget name in server/.env.example.

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

* fix(prompts): measure Improve action citations on the pages it names

Citations are counted on a basket's pages, and the action's payload had
none, so the metric was always null. Carry the selected suggestions'
brand_page sources as payload.pages, and list citations in kpi_keys only
when there are pages to measure.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>

* feat(mcp): add a create_improve_action tool for sending Improve suggestions to Action Center (#1014)

* feat(prompts): pick the Positions panel's date range inside the panel

The Positions panel was fixed to the table's range, so checking a prompt
over another period meant changing the whole table. The panel now has its
own 24h / 7d / 30d / 90d / Custom control. It opens on the table's range,
and changing it reloads only the panel. The open prompt and the panel's
range are mirrored to the URL (?positions=<id>&positionsRange=7d) so the
view can be shared. A custom range no longer spells its dates twice in
the header.

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

* feat(prompts): add an Improve tab with platform-specific position suggestions

For one prompt and the panel's range, the Positions panel gets an Improve
tab: per AI platform where the brand is not mentioned, mentioned late, or
mentioned early but not cited, AI-generated suggestions grounded in that
platform's own evidence (fan-out sub-queries, cited domains, competitor
URLs, the answer text). The server checks every source against that
evidence and drops invented ones, so each card names something real.
Suggestions are editable drafts: check, edit, remove (undoable) or add
your own.

Generation is always the user's click and is metered: each call's real
token cost is charged against a monthly budget of 1% of the plan price
(Growth $2.49, Enterprise $4.99 or 1% of plan_overrides.contractMonthlyUsd),
so the share holds whichever model IMPROVE_SUGGESTION_MODEL points at.
Sets are cached per prompt, range and location; newer runs show a
"Regenerate" notice instead of rebuilding automatically. Growth+ only.

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

* feat(prompts): send selected Improve suggestions to Action Center

The Improve tab's footer gets Send Actions: the checked suggestions, exactly
as edited, become one Action Center action (kind prompt_improve, category
compete). Each suggestion is a task with its body, platform and evidence
in the new action_tasks.details column. The action's why and goal are
written from the platform states at send time, its impact from the
prompt's demand and the size of the gap, and its baseline keeps the
positions per platform for PROMPT-008. Validation measures it on its own
prompt.

After a send the button turns into Open in Actions, the footer shows the
action id, and the sent suggestions are marked. The send is recorded on
the cached set, so this survives a reload, and is dropped once the action
is dismissed. An idempotency key per send makes a double click create one
action.

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

* feat(mcp): add a create_improve_action tool for sending Improve suggestions to Action Center

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

* fix(prompts): address review on the Improve tab

- Treat a platform mentioned in fewer than half its runs as not mentioned,
  and show "mentioned in X of Y runs" in each platform header.
- Retry on a failed read re-reads the cache instead of generating; a failed
  generate keeps the set already on screen.
- Charge every model attempt, including schema misses withRetry repeats,
  and log a failed usage insert.
- Price openrouter/ model ids as the model they route to.
- Classify platforms from every answer in the window, like the Positions
  tab; keep the newest 600 for evidence only.
- Fix the stale budget name in server/.env.example.

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

* fix(prompts): measure Improve action citations on the pages it names

Citations are counted on a basket's pages, and the action's payload had
none, so the metric was always null. Carry the selected suggestions'
brand_page sources as payload.pages, and list citations in kpi_keys only
when there are pages to measure.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>

* feat(prompts): replace the row's Edit icon with a ⋯ actions menu (#1015)

* feat(prompts): pick the Positions panel's date range inside the panel

The Positions panel was fixed to the table's range, so checking a prompt
over another period meant changing the whole table. The panel now has its
own 24h / 7d / 30d / 90d / Custom control. It opens on the table's range,
and changing it reloads only the panel. The open prompt and the panel's
range are mirrored to the URL (?positions=<id>&positionsRange=7d) so the
view can be shared. A custom range no longer spells its dates twice in
the header.

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

* feat(prompts): add an Improve tab with platform-specific position suggestions

For one prompt and the panel's range, the Positions panel gets an Improve
tab: per AI platform where the brand is not mentioned, mentioned late, or
mentioned early but not cited, AI-generated suggestions grounded in that
platform's own evidence (fan-out sub-queries, cited domains, competitor
URLs, the answer text). The server checks every source against that
evidence and drops invented ones, so each card names something real.
Suggestions are editable drafts: check, edit, remove (undoable) or add
your own.

Generation is always the user's click and is metered: each call's real
token cost is charged against a monthly budget of 1% of the plan price
(Growth $2.49, Enterprise $4.99 or 1% of plan_overrides.contractMonthlyUsd),
so the share holds whichever model IMPROVE_SUGGESTION_MODEL points at.
Sets are cached per prompt, range and location; newer runs show a
"Regenerate" notice instead of rebuilding automatically. Growth+ only.

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

* feat(prompts): send selected Improve suggestions to Action Center

The Improve tab's footer gets Send Actions: the checked suggestions, exactly
as edited, become one Action Center action (kind prompt_improve, category
compete). Each suggestion is a task with its body, platform and evidence
in the new action_tasks.details column. The action's why and goal are
written from the platform states at send time, its impact from the
prompt's demand and the size of the gap, and its baseline keeps the
positions per platform for PROMPT-008. Validation measures it on its own
prompt.

After a send the button turns into Open in Actions, the footer shows the
action id, and the sent suggestions are marked. The send is recorded on
the cached set, so this survives a reload, and is dropped once the action
is dismissed. An idempotency key per send makes a double click create one
action.

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

* feat(prompts): replace the row's Edit icon with a ⋯ actions menu

The last column of the Tracked Prompts table was a single pencil. It is
now a ⋯ menu (Base UI, so it opens from mouse and keyboard and closes on
Esc and outside clicks) with:
- Edit: the existing dialog
- Pause tracking / Resume tracking: one click, with a toast
- Improve position…: opens the Positions panel on its Improve tab
- Delete: confirms "Delete prompt and its history?", removes the row and
  its count at once, and offers Undo for 10 s

Prompts have no soft delete (a delete drops their history), so the undo
window is a delayed delete: the row is hidden at once and deleted when the
window ends, or right away if the table unmounts first. Closing the page
inside the window leaves the prompt in place.

Suggest Content and the bulk action bar from the task are follow-ups.

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

* chore(prompts): import the row menu icons apart from the limit counter's

Keeps this branch merging cleanly with the tracked prompt limit counter
(feature/prompts-tracked-limit-counter), which adds an icon to the same list.

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

* chore(prompts): import the dropdown menu apart from the bulk import's

Keeps this branch merging cleanly with bulk import
(feature/prompts-bulk-import), which adds imports at the same spot.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>

* feat(prompts): make Prompts an expandable sidebar menu with a route per view (#1016)

* feat(prompts): make Prompts an expandable sidebar menu with a route per view

The sidebar had a single Prompts link, and the page's views lived behind
?tab= / ?view= query params. Prompts now expands in the sidebar to:
- Tracked Prompts, with the brand's prompt count
- Prompt Suggestions
- Query Fan-outs
- Insights

Each has its own route: /dashboard/prompts/{tracked,suggestions,fan-outs,
insights}. Each route renders the same page, which reads its view from the
path. The page's tabs stay, and switching them rewrites the path in place,
so the sidebar and the tabs always show the same view. Moving between views
from the sidebar keeps the date range and location; location is now in the
URL as well.

/dashboard/prompts and its old ?tab= / ?view= links redirect to the matching
route (next.config redirects). The submenu's open state is remembered in
localStorage and opens on any Prompts route. Arrow keys move through the
sidebar links (right/left open, enter or leave the submenu), the parent
carries aria-expanded, and a collapsed sidebar opens on keyboard focus as it
already does on hover. The mobile nav lists the four views under Prompts.

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

* chore(prompts): define the tracked prompt count apart from bulk import's action

Keeps this branch merging cleanly with bulk import
(feature/prompts-bulk-import), which adds a function at the same spot.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 15, 2026
…rove-outcome

ansvisor#1010, ansvisor#1011 and ansvisor#1012, which this branch was stacked on, are now in main
in their final, reviewed form. The merge keeps main's versions of their
files and this branch's own change (measuring the position outcome of sent
Improve actions) on top: sendImproveToActionCenter keeps main's KPI keys
from the action's pages and adds the 7-day baseline and position_outcome.
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