Skip to content

feat(action-center): score every action's priority on the server - #1071

Merged
gkhngyk merged 27 commits into
ansvisor:mainfrom
cihan-gyk:feature/action-priority-score
Oct 17, 2026
Merged

gkhngyk merged 27 commits into
ansvisor:mainfrom
cihan-gyk:feature/action-priority-score

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

AC-006, part 1 of 2 (server). Every action gets a priority score from 0 to 100, a level and the facts behind it. The web part (the list column and default sort, Top Actions limited to 5, the drawer header, "Why this priority?", the CSV, Copy Data and MCP) follows in a second PR.

Stacked on #1070, which sits on #1058; please review the third commit, feat(action-center): score every action's priority on the server, or merge those first. Nothing in this PR depends on their code; the second PR does.

Spec: AC-006-priority-score.md and AC-spec-priority-score-signal-intelligence.md §2–7.

Why

Impact (high / medium / low) was the only thing actions were ordered by, so a brand with eleven high-impact actions had eleven "top" ones and no order among them. Priority answers the other question the spec asks: what to do first.

The score (lib/action-center/priority.js, pure)

Seven factors, each read as 0–1 and weighted to 100. The weights live in config/action-engine.js → priority.

Factor Weight Read from
Impact 20 The action's impact.
Demand 20 The most searched 5 prompts' monthly AI volume (prompt_volumes), search impressions, or AI-traffic sessions, on a log scale.
Severity 20 The worst finding's change: lost › dropped › slipping › gap/issue › opportunity › gain.
Business value 15 Prompt intent (the existing intent weights, by volume), or what a page is worth (revenue › transactions › key events).
Confidence 10 Distinct kinds and sources of evidence, never repeats of one signal.
Recoverability 10 Ground held before and lost › a site fix › ground never held.
Recency 5 The newest evidence, halving every 10 days.
  • Levels: critical 90+, high 75–89, medium 50–74, low below 50.
  • Quantity ≠ priority holds in two places: demand counts the top 5 targets, and confidence counts independent kinds and sources. The spec's own fixture is a test: 47 low-demand findings against 1 high-demand commercial loss, and the loss scores higher.
  • Impact is one factor of seven, so a medium-impact loss on high demand can come before a high-impact gap nobody searches.
  • Unmeasured demand counts as neutral (0.4), not low: technical and source findings have no demand to measure.
  • Actions sent by a person have no signals. Improve actions are scored from their platform states, content opportunities from their prompts.

"Why this priority?" as facts

priority_reason stores the facts, not a sentence, so the app can write the sentence in the reader's language:

  • The change: change, the subject (entity, count), and days since the evidence.
  • Demand: high / medium / low, or null when unmeasured, with the searches behind it.
  • Business: commercial, and heldBefore (ground the brand held and lost).
  • Evidence: kinds and sources.
  • The factors themselves.

When it is worked out

When What
Every night (generate.js) Every active action is scored again from its open signals, including signals linked that night, and their prompts' demand. Best effort: a score that cannot be saved is logged, never a failed pass.
When an action opens It is written with its score.
When a person sends from Content or the Improve tab It is scored as it is created.

Prompt demand is read once per brand per night (priority-data.js, chunked and paged). If that read fails, actions are still scored, with demand unknown.

The queue uses the same number (your decision)

The queue of waiting findings, and so which actions open each day, used to be ordered by impact plus how many targets an action covered (the opposite of quantity ≠ priority). It is now ordered by the priority score, plus 1 point per day waited up to 14. Nothing starves: two weeks of patience is worth about one level.

Database: migration 00144_action_priority_score.sql

  • Columns: actions.priority_score (smallint, 0–100), priority_level, priority_reason (jsonb), priority_updated_at.
  • Index: a partial index for a brand's open actions by score.
  • Before the first scoring: the columns are null and the app falls back to ordering by impact.
  • Also updated: schema.sql and web/src/types/supabase.ts.

Review

I ran a code review before opening this. Six of eight findings are fixed:

  • gap kinds were scored and labelled as drops;
  • owned-page citation counts were read as page sessions;
  • the demand read could hit the 1,000-row cap;
  • a failed priority write aborted the nightly pass;
  • an action with nothing open still claimed a change;
  • tests were missing for these.

Two are left as is, by design:

  • unmeasured demand counts as neutral;
  • one update per active action per night is cheap.

Related issue

None. Product spec AC-006 (Action Center), part 1.

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 00144_action_priority_score.sql.
  2. Run a signal pass for a brand, or wait for the nightly one. Every open action gets priority_score, priority_level and priority_reason.
  3. Send an action from Content or from a prompt's Improve tab: it is created with a score.
  4. Check the order: an action on high-demand commercial prompts that lost citations ranks above a wide action on low-demand prompts.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): only types/supabase.ts changed on the web side
  • 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 1193/1193. New and changed tests:
    • priority.test.js:
      • levels, and the spec's 47-vs-1 fixture;
      • the top-5 demand cap, and impact not being the whole answer;
      • confidence ignoring repeats, and recency fading;
      • recoverability and gap kinds;
      • owned-page counts, query and page demand;
      • actions sent by hand, and nothing open.
    • priority-data.test.js: largest volume and newest intent, chunking and paging, scoring on create when demand cannot be read.
    • generate.test.js:
      • an opened action carries its score;
      • the 47-vs-1 promotion;
      • nightly rescoring without touching updated_at;
      • a failed score write not stopping the night.
    • candidates.test.js: rewritten for priority plus wait.
  • bash supabase/build-schema.sh: run.
  • Against the dev database:
    • Migration: applied 00144 after a rolled-back trial; the checks reject 101 and an unknown level.
    • Scoring: the demo brand's open actions now score 84 (high).

🤖 Generated with Claude Code

cihan-gyk and others added 3 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]>
Every action's drawer gets Copy Data, Export CSV and Export Excel
(AC-005). Copy Data opens the whole action as Markdown, every tab of the
drawer, to copy a part or all of it with one click; the copy falls back
to the browser's copy command where the clipboard API is blocked. The
CSV (action-AC-52.csv, UTF-8 with a BOM) has a row per task and per
signal marked by a section column; the Excel workbook has a sheet each
for the action, its tasks, its signals and its history. Adds the
write-excel-file package, loaded only when a workbook is asked for.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each action gets a priority score from 0 to 100 with a level (critical,
high, medium, low), and the facts behind it for "Why this priority?"
(AC-006). The score weighs impact, the demand of the most searched
prompts, queries or pages, how severe the change is, commercial intent,
independent kinds and sources of evidence, whether the ground was held
before, and how recent it is, never how many signals repeat. It is
worked out when an action is created and again every night, stored in
new columns (migration 00144), and orders the queue of waiting findings
too, with a little added for each day waited.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk AC-006 part 1 (server) ready for review: a 0–100 priority score with a level and its reasons on every action, worked out nightly and on create, and used to order the queue of waiting findings. Adds migration 00144 with schema.sql regenerated. Stacked on #1070; the web part follows in a second PR.

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

# Conflicts:
#	supabase/schema.sql
cihan-gyk and others added 21 commits October 16, 2026 00:26
# Conflicts:
#	web/src/components/action-center/action-drawer.tsx
# Conflicts:
#	server/src/lib/action-center/from-prompt-improve.js
#	supabase/schema.sql
#	web/src/types/supabase.ts
…ure/action-priority-score

# Conflicts:
#	supabase/schema.sql
…ure/action-priority-score

# Conflicts:
#	supabase/schema.sql
…ure/action-priority-score

# Conflicts:
#	supabase/schema.sql
…rity-score

# Conflicts:
#	supabase/schema.sql
…rity-score

# Conflicts:
#	web/src/lib/action-center/display.test.ts
…rity-score

# Conflicts:
#	supabase/schema.sql

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

Reviewed. Merged main into the branch (conflicts in from-prompt-improve.js and the generated types kept both sides; schema.sql regenerated). Migration 00144 is applied to production. Scoring stays on the server and the app falls back to impact while a row is unscored.

@gkhngyk
gkhngyk merged commit 048b6f1 into ansvisor:main Oct 17, 2026
5 checks passed
gkhngyk pushed a commit that referenced this pull request Oct 18, 2026
…backfill unscored ones (#1145)

Priority scores (#1071, migration 00144) are worked out when an action is
created and again by the nightly generator. Actions opened before then
show "—" in the Priority Score column until the next nightly pass, and
completed or dismissed ones never get a score. The generator also doesn't
run when a brand's signal pass is skipped for no fresh results, so such a
brand's actions stayed unscored, or kept old scores.

- rescoreBrandActions (priority-data.js) scores a brand's actions in one
  go: their open signals and the prompts' demand are read once.
- A skipped signal pass now rescores the brand's active actions, best
  effort; the ledger row records how many.
- scripts/rescore-actions.js scores every action with no score yet, in
  any status, for one brand or --all. Safe to re-run.

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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