Skip to content

feat(chat): fit Chat Home to the person's focus: shortcuts, starter questions and a competitor's rise (W2-23a) - #1915

Merged
gkhngyk merged 9 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w2-23a-home-by-focus
Nov 1, 2026
Merged

gkhngyk merged 9 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w2-23a-home-by-focus

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat W2-23a: Chat Home fits the person's focus (CHAT-24 §4, mockup CHAT-mockup-v2.html#s-dept). Stacked on #1914, the focus picker: review and merge that first; this PR's own change is 789815d (then a merge of #1914's last commit). Web only. No migration. Behind CHAT_AGENTIC.

What changes with a focus

  • For you now takes the picked areas' shortcuts in turn: the first of each, then the second of each…, so every picked area shows.

    • It shows five beside Ask anything, plus More. That's five, not CHAT-24's six: CHAT-08 v2 caps For you now at six chips with Ask anything.
    • The three jobs (Complete tasks, Win back citations, Ready to publish) keep their counts and rules. They show only when there is something to do, and the writing ones aren't shown to reader roles.
    • Fact check shows only when the brand has approved brand facts.
  • Start with a question: four questions from the picked areas, in turn. They are filled with the workspace's own words where it knows them:

    • its most mentioned competitor over 14 days;
    • its topic with the most active prompts;
    • a second market, only when the brand's prompts track two or more countries.

    Otherwise a question keeps its general wording.

  • Greeting line, only with Competitors picked: "{rival}'s mention rate rose {n} points this week." It compares insights_competitor_daily this week against the week before, needs a 3+ point rise, and shows only when nothing needs the person.

  • The / menu lists the focus's skills first.

Without a focus, Home is as on main. The only addition is #1914's "Choose focus" pill.

How it's built

  • lib/chat/focus-home.ts (pure): each area's shortcuts and starters, the turn-by-turn merge, the fill, the greeting line and the skill order.
  • readFocusFill (lib/actions/chat-home.ts) reads as the person, for the active brand, and only for the areas that need it.
    • It never throws: what can't be read is unknown, and the question takes its general wording.
  • for-you-now.tsx takes the focus shortcuts. Shortcuts with an Ansvisor skill (tasks, winback, publish, quality, report, wrongclaim) ask in that skill's words. The rest ask in plain sentences, and Chat picks the skill from its description.
  • en.json chatShell.home.focus.*.

Next: W2-23b adds the seven focus-tagged skills and New for you (stacked on this).

Help: help/chat/focus.md gets "What changes on Chat Home" (approved: false).

Related issue

None. Chat Wave 2 (W2-23a).

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. Set CHAT_AGENTIC=true. Give a person the focus Competitors, Product and Markets, and give the active brand a competitor whose mention rate rose 3+ points this week. A seed is available on request.
  2. Open Chat Home. Check:
    • the line under the greeting names the competitor;
    • the pill reads "Focused on Competitors, Product +1";
    • For you now shows five shortcuts from the three areas, then More;
    • Start with a question shows four questions with the brand's competitor, topic and market.
  3. Type / in the composer: beat, compare and faq come first.
  4. Clear the focus (Settings › Your focus, all unticked). Home is the default again, with Choose focus.
  5. Unit tests: focus-home, chat-home (action and component) and _chat-page-access.

Checked in the browser at 1024px, light and dark, with and without a focus. The user approved the screens. Screenshots are available on request.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (0 errors; 7 old warnings in files this PR doesn't touch)
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

Full checks on 789815d: web 801 of 802 files / 8,370 tests passed, and yarn build passes. Server format:check and lint are clean, and 351 files / 4,987 tests pass (3 skipped). The one failing file was subscription-guard-coverage.test.ts, the same failure as #1914 (the focus actions). It passes after merging #1914's fix (be0174c, 6/6). readFocusFill only reads, so it adds nothing to that list.

🤖 Generated with Claude Code

cihan-gyk and others added 8 commits October 31, 2026 23:20
…son's work areas (W2-22)

CHAT-24 §3: the focus picker opens once on the first Chat Home (marked
shown as it opens) with the areas the person's work areas suggest, Home's
pill reopens it, and Settings › General › Your focus keeps changes at
once. Focus only changes suggestions; no migration (00400 focus, 00408
focus_prompted_at).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main hid Answer language, notifications and "Thought for N s" in Chat
Settings (ansvisor#1903). Keep them hidden and keep the new Your focus row, in
the component, the page comment and the help article.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uestions and a competitor's rise (W2-23a)

CHAT-24 §4: For you now takes the picked areas' shortcuts in turn (five
beside Ask anything, CHAT-08 v2's six chips; the three jobs keep their
counts and rules), Start with a question offers four in the workspace's
own competitor, topic and market or their general wording, the line under
the greeting says a competitor's mention rate rose 3+ points this week
when nothing needs the person, and the / menu lists the focus's skills
first. No migration.

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

saveChatFocus, skipChatFocus and markFocusPrompted write only the person's
own chat_user_prefs row and cost nothing, like saveChatGeneralSettings, so
they join the read-only coverage test's open list with their reasons.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… pill is cancelled

From the pill the picker's way out still saved an empty focus, so changing
your mind wiped the focus you had. Opened from the pill it now reads
Cancel and only closes; Skip for now stays the first opening's answer.
gkhngyk
gkhngyk previously approved these changes Nov 1, 2026

@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, approving. There is nothing to fix here on its own. Merge commit b3d251e brings in #1914's fix (1793813: cancelling the pill's picker no longer wipes the focus) and current main.

Checked:

  • Read-only roles and the focus shortcuts. Tasks and Ready to publish still go through the job rules, so they stay hidden without canChange, and Win back keeps its read wording. The other shortcuts are fine for Analyst and Agency partner roles. Site audit fixes, What to write next, Weekly report, Quality pass and Fact check all answer in the chat: a prioritised list, Before/After passages, a table to paste. The only write any of them reaches is the optional create_draft, which goes through the role check and its card like any other write. The read-only test that keeps auditFixes and report matches that.
  • Brand access. readFocusFill reads as the person. On prod, insights_competitor_daily, competitors, topics, prompts and prompt_sets are all filtered through RLS-filtered brands, so brand scope holds. The brand id and the focus are both validated, and the CHAT_AGENTIC flag is checked.
  • en.json keys resolve. Help sections are under 150 words, and the article is unapproved, so the snapshot doesn't change. focus-home.ts is pure and safe in the client bundle.

Follow-up (not blocking): readRivals pages through raw insights_competitor_daily rows and sums them in JS. On prod, the largest brand has 7,191 rows in the 14-day window: 8 sequential 1000-row pages at about 17 ms of database time each, as the person (EXPLAIN ANALYZE). Wall time is probably 0.4 to 0.7 s once round trips are counted. It runs after Home renders and only for Competitors, SEO or Product, so it isn't blocking. Still, a small RPC that groups by competitor and week would cut it to one call returning about 100 rows. PostgREST aggregates are off, and the existing competitor_aggregates_daily counts total_mentions rather than mention_answers and takes about 174 ms per week, so it isn't a drop-in.

Tests: vitest on src/components/chat, src/lib/chat, the chat pages, src/lib/actions, src/lib/guards (plan-row included), src/lib/help, subscription-guard-coverage and demo-gate(-routes): 229 files and 2595 tests pass. One engine.test.ts case timed out at 5 s under parallel load and passes alone (158/158). tsc --noEmit is clean, and eslint and prettier are clean on the touched files.

# Conflicts:
#	help/chat/focus.md
#	web/src/app/[locale]/(dashboard)/dashboard/chat/_chat-page-access.ts
#	web/src/components/chat/chat-home.test.tsx
#	web/src/components/chat/chat-home.tsx

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

LGTM

@gkhngyk
gkhngyk merged commit 28224e1 into ansvisor:main Nov 1, 2026
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