Skip to content

feat(demo): fill the demo brand's Action Center, content, suggestions and reports (demo brand, part 2) - #1735

Merged
gkhngyk merged 30 commits into
ansvisor:mainfrom
cihan-gyk:feature/demo-brand-workflows
Oct 29, 2026
Merged

gkhngyk merged 30 commits into
ansvisor:mainfrom
cihan-gyk:feature/demo-brand-workflows

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Demo brand, part 2 of 7 (server). The demo brand's Action Center, Content, suggestions and reports, as generator modules beside the core. The demo moves to DEMO_VERSION = 2, so every demo brand is rebuilt on its next visit.

  • Action Center (lib/demo/action-center.js): signals, the actions raised from them over the month with their tasks, history and measured outcomes, the KPI framework, a task waiting for review, and Getting started.
    • Each signal's numbers are counted from the demo's own answers (stats.js), in the detectors' shapes. Actions are built the way generate.js builds them (payload, planTasks, scorePriority). Closed ones are measured as validate.js measures them (basketValues, deriveOutcome).
    • signals/library/detect.js exports single and promptTarget for this; nothing else changes there.
  • Content (content.js, content-pages.js): prompt clusters (stored as replace_prompt_clusters stores them, so nothing reads them as stale), content opportunities with the generator's own metrics, score and assets, Content Editor drafts and Plan marks.
  • Suggestions (suggestions.js): prompt, topic and Improve suggestions.
  • Reports (reports.js): a weekly visibility summary and a competitor benchmark, with the web's ReportPayload shape and numbers counted from the demo's answers.
  • Every module is rebuilt in place over its old rows, beside the others, after the core.
  • Coverage: these tables move from PENDING to built. action_candidates, action_task_runs, signal_runs and content_author_defaults are skipped, each with its reason.

Migration / deploy notes: no migration. Demo brands built at version 1 are rebuilt at the next visit.

Related issue

None (demo brand).

Stacked on #1734 (demo brand, part 1: core).

Type of change

  • feat — New feature

How to test

  1. With parts 1–2 on a dev database, open the demo brand (POST /api/demo, or pick Brewline Coffee in the brand menu). Its demo is rebuilt at version 2.
  2. Action Center: Actions (Getting started and the actions), Signals, KPIs, History (outcomes) and Needs review are filled.
  3. Content: Opportunities, Plan, Library and an Editor draft open with sample content.
  4. Prompts › Suggestions and Topics show suggestions; Reports lists two reports that open.

Checklist

🤖 Generated with Claude Code

cihan-gyk and others added 24 commits October 28, 2026 14:29
… counts

Migration 00380 adds brands.is_demo, demo_version, demo_built_at and
demo_hidden_at, one demo brand per organization (partial unique index) and
policies that let members read it but never insert, change or delete one.
The plan's prompt-location quota, the usage cards' account totals and the
web's brand limit leave the demo brand out; the health report's fan-out
share leaves out its answers. The brand delete route refuses it: the demo
brand is hidden, not deleted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The daily tracking list, the job claim and recovery (activeBrandFilter /
isBrandActive), the signal catch-up, the pulse, the task writer, executor
and checks, action validation and Improve outcomes, the Insights sweep,
brand facts, Search Console and Analytics syncs, page opportunities, the
traffic digest, auto-audits, catalog feeds, Webflow status and volume
analysis all leave demo brands out: their data is sample data and nothing
may track, write or spend for it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lib/demo/ builds an organization's demo brand in its own brands: Brewline
Coffee (brewline.example) with fictional `.example` competitors and
publishers, 12 prompts in 3 topics, 6 engines and a run every 3 days over
a month (720 short answers) with citations, product cards, searches and
volumes. Answers are raw engine responses run through tracking's own
parseScraperResponse, parseResponse and the result and shopping card rows
(now pure resultRow and shoppingCardRows in cloro-result-handler.js), and
the rollups are rebuilt by the nightly run's own functions.

ensureDemoBrand creates it, rebuilds it in place (same ids) when
DEMO_VERSION moves on or its data is three days old, and leaves it alone
otherwise; concurrent visits share one build (one-per-org index, a
compare-and-set claim, a lease). Modules are { name, tables, build }, and
a coverage test fails on any brand_id table the demo neither builds nor
lists as skipped or pending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
POST /api/demo creates or rebuilds the organization's demo brand for any
member and returns { brandId, version, rebuilt }; PATCH /api/demo
{ hidden } hides or shows it for admins and managers ({ brandId, hidden },
404 no_demo without one). Both stay open once a plan has ended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s and reports

Four demo modules over core's answers: signals and a month of actions
(tasks, trail, measured outcomes, a task waiting for review, ready-made
KPIs, Getting started with its page steps opened), prompt clusters,
content opportunities, Editor drafts and Plan marks, prompt, topic and
Improve suggestions, and two saved reports. Numbers are counted from the
demo's own answers; shapes come from the engine's own functions. detect.js
exports single and promptTarget so the demo writes signals in their shape.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DEMO_MODULES runs core, suggestions, actionCenter, content and reports;
DEMO_VERSION 2 rebuilds existing demo brands on their next visit. The
coverage lists move the workflow tables to built, skip the engine's
internal queues and logs and the org-level author default, and leave the
draft shopping check to demo-site with the catalog.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The first module lays down what the others point at; the rest write their
own tables together, each after the module it names in `after`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A first build no longer clears 70 empty tables, and the core writes each
step's independent tables side by side through a shared queue of four
statements (write.js: insertChunks, demoWriter). Its rollups move to a
refresh step that runs alongside the other modules, Insights, Citations and
Mentions together, the month's answer terms in one call (refreshMentionsDaily
takes an optional termDays). The core alone went from about 17 s to 7 s on
the dev database.

A rebuild (new DEMO_VERSION, or data older than three days) no longer
deletes the demo first: an `inPlace` module writes over its rows by key
(ids are deterministic) and deletes only the rows it didn't write again,
then rebuilds the rollups over the old and new days, each refresh call
rewriting its days in one statement. Someone opening the demo meanwhile sees
last week's data, not empty pages. Modules not marked `inPlace` still have
their tables cleared, now just before they are built.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A brand just created isn't empty: its insert trigger starts Getting started,
so skipping every clear on a first build made the Action Center's insert hit
getting_started_pkey. An in-place module now always writes over by key (the
first build only skips reading back and pruning); a module that isn't
rebuilt in place clears its own tables just before it is built, on a first
build too, alongside the other modules rather than all up front.

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

Nobody looks at a demo being built for the first time, so every module not
rebuilt in place starts clearing what the new brand's triggers made at once,
while the core writes, instead of each in turn later, when its deletes queue
behind the rollups. A rebuild still clears each module just before it is
built, so its old rows stay on show as long as they can.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A table with an identity id and no other unique columns (ai_bot_events)
can't be written over by key. write(table, rows, { generated: true })
inserts the new rows and, on a rebuild, deletes the brand's rows that were
there before right after: never empty, both there for a moment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts in place

The four workflow modules write through the build's writer (ctx.write):
each step's independent tables side by side, and on a rebuild over their
old rows by key, deleting only what isn't written again, so their pages
never empty while the demo is rebuilt. Keys where a row has no id:
getting_started (brand_id, also what a new brand's trigger made),
getting_started_steps, action_signals, the cluster members, searches and
scopes, and the plan marks; the action and cluster children are found
through their parent (scopes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
refreshMentionsDaily takes `together`: the rollups (refresh_mentions_daily)
and the answer terms (refresh_mention_terms) take their own locks and write
their own tables, so the demo runs them side by side instead of one after
the other, a second off the longest step of its build. The nightly run
keeps them in turn.

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

# Conflicts:
#	server/src/lib/action-center/task-checks.js
#	server/src/lib/action-center/validate.js
#	server/src/routes/index.js
#	supabase/schema.sql
…ver main's new tables

sweepPromptDemand chose brands by their organization's plan only, so an
active workspace's demo brand would have had its sample prompts read and
DataForSEO's paid tasks set for them. It now leaves demo brands out, as
the other sweeps do. The demo coverage list names the two brand tables
main added: prompt_table_views (skipped: the demo starts on the default
columns) and prompt_demand (pending a demo follow-up).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 3 commits October 29, 2026 18:49
…core

# Conflicts:
#	server/src/lib/action-center/execution/run.js
#	server/src/lib/action-center/execution/run.test.js
#	supabase/schema.sql
…n's new tables

sweepCompetitorTimeline (learning C3, on main) chose brands by their
organization's plan only, so a demo brand's sample answers would have had
their cited pages read every night. It now leaves demo brands out, as the
other sweeps do. The demo coverage list names the brand tables main added:
cited_page_features, competitor_page_events and competitor_timeline_scans
(pending a demo follow-up) and chat_conversations (with Chat).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 2 commits October 29, 2026 18:53
Chat's precedence (ansvisor#1776) left readBrandIsDemo false until the demo chain
added brands.is_demo, with a type check that stops compiling once the
column exists. It now reads the column, as the server's demo guard does,
so a tool that changes or spends on the demo brand is refused with
demo_brand; a brand that isn't found isn't one, and a failed read throws.

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

Copy link
Copy Markdown
Collaborator Author

Merged main forward through #1734's updated branch (no conflicts of its own; it carries #1734's resolution and follow-ups). Typecheck and the demo tests pass; server lint clean.

@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 ebe6378 (part 2), as its own diff on top of #1734's head 85ccbe6. No migration. Outside lib/demo it only exports single and promptTarget from signals/library/detect.js; nothing else there changes.

What I checked

  • It writes only the demo brand's own rows. Action Center, Content, suggestions and reports write through the build's writer:
    • Every id is demoId(brandId, …).
    • The keys that aren't id include brand_id or a parent of the demo (getting_started_steps: brand_id,step, action_signals: action_id,signal_id, prompt_cluster_scopes: brand_id,topic_id, content_plan_marks: brand_id,row_key).
    • The tables without a brand_id (action_tasks, action_events, action_task_reviews, action_signals, prompt_cluster_members/queries) are found and pruned only through the demo's own actions and prompt_clusters ids.
  • Nothing it writes starts work. These rows are written directly, not through the engine, so no webhook, e-mail or model call follows. The nightly passes that would read them leave a demo brand out: the task writer, task checks, execution, validation and Improve outcomes (part 1), and the signal catch-up through activeBrandFilter.
  • No usage table is written. prompt_improve_usage, opportunity_usage, brief_usage and suggestion_relevance_usage stay empty for the demo, so the AI usage meter, the opportunity quota and the brief quota don't move.
  • Coverage: action_candidates, action_task_runs, signal_runs and content_author_defaults are skipped with reasons that hold. Getting started is written over by brand_id, so the row the brand-insert trigger made is reused.
  • Tests: src/lib/demo passes on this head and on the stack merged with main.

Merging main. Same three conflicts as #1734 (execution/run.js, its test, schema.sql). They are resolved on the branch noted on #1736.

Follow-ups

  1. The demo's content drafts and suggestions are ordinary rows. Until part 4's write guard lands, a member can edit them, accept a suggestion or run one, and the server's paths that cost (brief, Improve, refresh) take a demo brand like any other. Please merge parts 1–4 together, not part by part.

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 29, 2026
@gkhngyk
gkhngyk merged commit 58b7426 into ansvisor:main Oct 29, 2026
3 of 5 checks passed
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