Skip to content

feat(chat): add Chat Settings › General, Back to Chat and the slim rail (W1-09) - #1839

Merged
gkhngyk merged 33 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-09-settings
Oct 30, 2026
Merged

gkhngyk merged 33 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-09-settings

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat Wave 1, behind CHAT_AGENTIC. Stacked on #1838 (W1-06). The diff against main includes the PRs below it until they merge. The product owner saw this in a local preview and approved it.

W1-09: Chat Settings › General, Back to Chat, Esc and the rail.

  • Settings › General (/dashboard/chat/settings):
    • Fields: default mode, answer language, notifications, "Thought for N s", and Ask Chat on every page.
    • Each change saves at once; a refused save goes back with a toast.
    • The server refuses what the person can't pick: modes for Analyst / agency partner, a locked Full auto, and Slack when it isn't connected.
  • Settings in the menu, with the month's AI use, also in Ctrl K and the chat header's ⋯.
  • ← Back to Chat and a "Chat › page" trail on Inbox, All chats, Activity and What Chat can do. It goes back to the last chat opened in the tab, else Home.
  • Esc closes only the top layer and never leaves the page.
  • The app sidebar on Chat pages is a slim rail. The logo toggles it, and the choice is saved per person (rail_open).
  • Read-only coverage: saveChatRailOpen and saveChatGeneralSettings are listed as the person's own settings.

No migration, no new dependency.

Related issue

Part of Chat (Wave 1, CHAT-01 / CHAT-23).

Type of change

  • feat — New feature

How to test

/dashboard/chat/settings: change each field; switch Ask Chat off and the header button and Ctrl J go. Tests: general settings (refusals), back link, rail.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: lint, typecheck and the related tests pass (run one at a time on an 8 GB machine; build left to CI)
  • Tests added
  • Help article updated (help/chat/*, approved: false)

🤖 Generated with Claude Code

cihan-gyk and others added 19 commits October 30, 2026 01:12
…iles, Help and add-on packs

Chat's Wave 1 tables in one PR (one DB PR per wave), behind CHAT_AGENTIC:
nothing reads or writes them while the flag is off. Tables, types and the
demo's coverage only; the code that uses them comes in the Wave 1 PRs.

- 00407: chat_conversations gets shared_at (Share with team: every member
  of the workspace reads it), last_read_at (unread results), deleted_at
  (Delete with Undo; deleted chats are hidden from every member) and a
  title search column; chat_messages gets context_json (what a person's
  message was scoped to) and a text search column. 'simple' text search,
  so a chat in any language is found. The author policy now leaves deleted
  chats out, and a shared policy reads shared ones.
- 00408: chat_user_prefs gets the rest of Settings › General and the
  one-time notices: rail_open, panel_size, default_mode, answer_language,
  notify_via, show_thought, panel_on_pages, focus_prompted_at,
  usage_notice_period, legacy_imported_at.
- 00409: chat_uploads and the private bucket chat-uploads: 10 MB a file,
  the composer's 11 types, 5 a message (a trigger backs the server's
  check), kept 90 days.
- 00410: chat_tool_cache (a chat's read results by tool and scope, server
  only) and each step's and model call's measure: latency, cache hit,
  truncation, result tokens on chat_run_steps (never granted to members),
  prompt cache read/write tokens and latency on the ledger.
- 00411: chat_files (filed deliverables and saved answers, the
  workspace's, kept a year, searchable by title, summary and tags),
  chat_file_task_links, chat_storage_usage kept by a trigger, and the
  private bucket chat-files.
- 00412: help_answer_cache and help_gaps (server only, no workspace or
  person ids).
- 00413: add_on_products seeded with the owner's packs (AI credits $10,
  $50, $250, $1,000 at half their price in budget, 12 months; storage
  +25/+100/+250 GB at $5/$15/$29 a month; $50 and +25 GB Most picked),
  add_on_purchases (Admins read), ai_credit_grants and storage_grants
  (server only), and prompt_improve_usage.grant_id.

Members only ever read; every write is the server's. Tool names, tool
results and dollars stay server only. web/src/types/supabase.ts carries
the new tables and columns; schema.test.ts checks the policies, the
server-only tables, the limits and the seeded packs from the SQL;
steps.test.ts keeps the step measure out of the member columns. The demo
coverage skips chat_files and chat_tool_cache (a person's own Chat work).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Behind CHAT_AGENTIC; with it off, the Agent page and its menu link stay as
they are today.

- /dashboard/agent and every path under it answer a 301 to the matching
  /dashboard/chat path, query kept, where the new Chat is on for the
  person's workspace (CHAT-01 item 2). Sent with no-store, so turning the
  flag off again takes effect at once. The sidebar and mobile menu link
  Chat straight to /dashboard/chat.
- The chats API (CHAT-01 §1-3, 7-8, 26): GET /api/chat/conversations lists
  the person's chats and the team's shared ones (or their archived ones),
  newest first, with each row's brand name, dot and live step in words, and
  the Chats / Archived counts; POST starts an empty chat; GET .../{id} opens
  one with its messages and steps; DELETE stops a running agent, then hides
  the chat for everyone; .../restore is the Undo (one minute); .../read
  marks its result read for the author. Refusals come back as values
  (ansvisor#1777), never thrown.
- A chat that isn't there, was deleted or isn't shared says "This chat isn't
  available." with New chat (item 26); opening one marks it read.
- The engine and access requests read chats with the service role, so they
  now leave deleted chats out too (ansvisor#1812 note).
- Help: a "chat" area and its first article (approved: false).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Behind CHAT_AGENTIC; with it off the Chat pages have no frame, as today.

- Every Chat route now sits in a shell (CHAT-01 items 5, 9a-9f; CHAT-23
  G1): the 256px chat menu beside the page and a 52px header with the
  open chat's title and status pill, and the runs tray.
- The menu, top to bottom: the toggle and New chat (Ctrl+Shift+O / ⌘⇧O);
  Menu with Home and the count of what needs the person; Governance with
  Activity, What Chat can do and Tool policy (the governance mockup's
  menu); Agents at work (needs you, running, unread results: three rows,
  See all / Show less, the dots' legend); Chats with its count, Pinned,
  Today, Yesterday, Previous 7 days, Previous 30 days, then by month, in
  the person's own time zone. Rows show the dot, the title (bold while a
  result is unread), the live step or the result's time, or the brand, and
  a teammate's initials on a shared chat. Items whose pages aren't built
  yet stay out (Inbox, Settings, Skills, Integrations, Scheduled, Files,
  Search, All chats, Archived).
- The toggle and Ctrl+\ (⌘\) hide or show the menu and keep the choice on
  the person for every device (chat_user_prefs.menu_open, a server action
  that answers as a value, ansvisor#1777). Hidden, the header starts with a strip:
  toggle, New chat, runs pill. Below 1100px the menu is a drawer that
  leaves the saved choice alone. Ctrl+B stays Bold.
- The list is read from the chats API, again on each page change, every
  5 s while a chat works or waits and every 30 s otherwise.
- Thin, quiet scrollbars for Chat's lists (chat-scroll).
- Help: the chat menu and how to hide it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ete with Undo

Behind CHAT_AGENTIC, like the rest of the Chat shell.

- PATCH /api/chat/conversations/{id} `{ pinned?, title?, shared?,
  archived? }`: the author's own chat only (else 404), a trimmed title of
  1 to 200 characters, answered as a value (ansvisor#1777).
- Each chat row's ⋯ (CHAT-23 chatMenu.rowMore, G9), on hover and focus:
  Open, Open in new window, then for the author Pin / Unpin, Rename,
  Share with team / Stop sharing, Archive, and Delete for the author or an
  Admin on a shared chat. A teammate's shared chat only opens.
- The open chat's ⋯ in the header (G10): Chat settings, Open in new
  window, Pin, Rename (in the title), Share with team, Export chat, Activity
  log, Archive, Delete. Export chat is shown disabled ("Coming soon"):
  wiring it to the answer exports is left to W1-25.
- Rename edits the name in place, in the row or the header: Enter or
  clicking away saves, Esc cancels; double-clicking a row's title starts it.
- Every change shows at once and is then sent; a refused one is put back
  with "Couldn't save that". Archive's toast and Delete's (10 s) carry
  Undo; Delete asks first ("Delete this chat?", focus on Cancel, a red
  Delete), stops a running agent, and leaves the open chat for Chat Home.
- A pinned chat shows the pin where its dot is.
- Help: managing and sharing a chat.

Split view, Pause / Stop run, Schedule this and Save as agent come with
their pages (Wave 2 and 4).

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

Other members' profiles are hidden from the person by their policy, so a
teammate's shared chat showed no initials. Read with the service role,
kept to the person's workspace, for the name only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Behind CHAT_AGENTIC, like the rest of the Chat shell.

- Chat Home (CHAT-01 items 10-12, mockup #s-home): "Good morning /
  afternoon / evening, {first name}" by the person's own clock (switching
  at 12:00 and 18:00; no name, no comma), then one line: "Your agents
  worked while you were away. N things need you." linking to the Inbox, or
  "All caught up.". The composer stays below it.
- The Action Center line (item 12, CHAT-09 item 3): "N Action Center tasks
  are due this week" (singular at 1, hidden at 0): the active brand's open
  actions due by Sunday, overdue ones included, read as the person by a
  server action that answers as a value (ansvisor#1777). Complete with Chat asks
  Chat to complete this week's tasks in a new chat and opens it while the
  run goes on.
- The Inbox at /dashboard/chat/inbox (mockup #s-inbox): what needs the
  person (Review), what runs (its progress, Watch) and unread results
  (Open), with "1 needs you · 1 running · 1 done today"; a row opens its
  chat; one line when empty.
- The chat menu gets Inbox, with its count and an amber dot while
  something needs the person (also beside Menu when folded), and the
  collapsed strip gets an Inbox button, as in the mockup.
- Help: Chat Home and the Inbox.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On a person's first visit to Chat (CHAT_AGENTIC on), their Agent Chat
conversations in their workspace are copied into chat_conversations and
chat_messages with the same ids, so old chats sit in Recents by their
last message and open at /dashboard/chat/{id}. Questions and answers in
words are kept; tool rows, tool-only answers and empty conversations are
not. The default title "New conversation" becomes "New chat".

Once per person: chat_user_prefs.legacy_imported_at (00408) is set only
after a complete copy, so a copy that failed is tried again next visit.
Already-copied ids are left alone (upsert ignoring duplicates), so two
visits at once or a second run change nothing. It never throws and never
keeps Chat from opening; the old tables are only read.

The test fake learns upsert, range and ordering by several columns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Search chats (CHAT-01 item 6; CHAT-23 G2): GET
/api/chat/conversations/search finds the person's chats and the team's
shared ones whose title or messages hold every word typed (00407's
search_tsv, 'simple' configuration, words as prefixes), newest first;
`view=archived` searches their own archived chats. Input is cut to
letters and digits, so no operator reaches Postgres.

- The chat menu gets the Search chats field under Chats: typing lists the
  matches in place of the days, with "No chats match." and Clear filters.
  All chats · {n} › and Archived · {n} › close the list.
- Ctrl K (⌘K) opens the palette (mockup #msearch) under Search chats, or
  under the strip's new Search button while the menu is hidden; again
  closes it. New chat, the latest or matching chats and the Chat pages
  by name; arrows and Enter, Enter opens the first match or a new chat.
- All chats (/dashboard/chat/all, mockup #s-allchats): Active and Archived
  tabs with counts, search over names and messages, filters All, Running,
  Needs you, Done, Mine and Team, and Archive selected / Unarchive
  selected for the person's own chats, with one toast.
- Archive's toast now says "Archived · find it in All chats › Archived";
  it is brought back from All chats › Archived (CHAT-23 chat.archive).

Help: new help/chat/all-chats.md, chat.md updated. Popover passes an
anchor through; the test fake learns textSearch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l beside Chat

Chat Settings › General (/dashboard/chat/settings, mockup #s-settings;
CHAT-23 chatSettings.*): default mode, answer language, notifications,
"Thought for N s" and Ask Chat on every page, kept on chat_user_prefs
(00408) at once and put back when refused. A new server action,
saveChatGeneralSettings, checks each change against the person: no mode
for Analysts and Agency partners, Full auto only on a paid Growth plan
and where the Admin leaves it on for members (it says why when locked),
Inbox + Slack only once Slack connects (not yet). It never throws (ansvisor#1777).
Settings sits in the chat menu under Inbox with the month's AI usage in
percent, in the Ctrl K palette, and in the header ⋯ (Chat settings).

Navigation (CHAT-01 4b, 4e, 4f; CHAT-23 nav.*, rail.toggle):
- Inbox, All chats, Activity and What Chat can do show ← Back to Chat
  and the "Chat › {page}" breadcrumb; Back to Chat returns to the last
  conversation open in this tab, or Chat Home. Settings shows its name.
- Esc closes only the topmost layer and never navigates (covered by tests).
- On Chat's screens the app sidebar is the rail; the logo expands and
  collapses it, kept on the person (chat_user_prefs.rail_open) through a
  new saveChatRailOpen action. Elsewhere, and with the flag off, the
  sidebar keeps its own pinned state and the logo still goes home.

Help: new help/chat/chat-settings.md; chat.md gets "Move around Chat".

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

Creating an empty chat, deleting, restoring and marking your own chat read
start no cost; a chat's first message is a run, which the engine refuses
with 402. The read-only coverage test lists them with that reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n on a read-only workspace

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 30, 2026
…e clock with each list read

A teammate's shared chat that waits on its author's OK no longer shows under
Agents at work or in Home's count. A chat that waits on an OK or is paused no
longer keeps the list on the 5 s pace. A menu left open past midnight now
moves Today's chats to Yesterday on the next list read.
A person reads only their own profile, so the author's name came back
empty on every teammate's shared chat. Read it on the server, within the
workspace; only the initials leave.
…count

A shared chat that waits for approval waits on its author, who alone can
answer it. The Inbox, its counts in the menu and the strip, and Home's
"things need you" now count the person's own chats only.
Agent Chat wrote a conversation's whole thread again on every turn in one
insert, so its messages share one created_at and their ids don't follow
the order. The copy read them by created_at then id, which shuffled them,
and Chat reads a chat by created_at alone. Read each conversation the way
Agent Chat's own page did (by created_at, no tiebreak) and give the copies
a strictly rising created_at, a millisecond apart where they tied.

Also cut a long title or message without splitting an emoji in half.
Each word goes to Postgres quoted, so it splits it the way it split the
text: "nike.com", "4.5" or an address is one token there and is now
found whole, and Postgres lowercases it itself.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk
gkhngyk previously approved these changes Oct 30, 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 with 297aea5: a merge of #1838's new head (with the #1829–#1832 and #1837 fixes), then one formatting commit, described below.

I reviewed only what this PR adds on top of #1838 (59098e80d..cefb44f2e): Settings › General, the Settings item with the usage meter, ← Back to Chat and the breadcrumb, Esc, and the rail.

Fixed: the web format check failed

yarn format:check fails on subscription-guard-coverage.test.ts. The new saveChatGeneralSettings entry is longer than Prettier's line width. This is what fails the "web — format, lint & typecheck" job on this PR. take-1839 wraps it, and format:check then passes.

The branch also merges the current #1838 head (7da743de1, with the #1829–#1832 and #1837 fixes). There was one conflict, in chat-shell.tsx: this PR's status from useChatList() sits next to #1837's inboxItems(chats) Inbox count. I kept both.

Suggested commits: the merge, then style(chat): format the read-only open actions list so the web format check passes.

Checked and fine

  • Who may change what. Everything on this page is the person's own row in chat_user_prefs. The page reads Full auto for members but never writes it. That stays in Settings › Chat, which only Admins change.
  • Server-side checks. saveChatGeneralSettings validates with a strict zod object (unknown keys, bad values and an empty patch are refused). It then reads the live role, plan and workspace switch again with readChatGeneral before it writes. An Analyst or Agency partner can't set a mode, Full auto is refused below Growth (paid) or when the Admin turned it off for members, and Slack is refused until it's connected. The person must still be in the same workspace. The tests cover each refusal.
  • Full auto shown as it runs. A saved Full auto that is locked now shows as Auto, ask before changes. A missing chat_settings row reads as "open to members", the same default the engine uses.
  • Read-only workspace. saveChatRailOpen and saveChatGeneralSettings are listed as open, with reasons. Both write only the person's own preferences, and a run they start is still checked by the engine.
  • Flag off. Both actions return { ok: false } (tested). /dashboard/chat/settings returns notFound(). The sidebar keeps its pinned state and the logo stays a link to the dashboard. The rail, Settings item and Back to Chat only render inside the Chat shell.
  • Back to Chat. Only a real chat id (the UUID pattern) is remembered, per tab, in sessionStorage with a try/catch. A chat that is no longer in the list sends you to Chat Home.
  • Keyboard. The rail's logo is a button with aria-expanded and a label that says what it does, plus a focus ring. The breadcrumb is a nav with aria-current="page". Switches use role="switch". Esc closes only the palette (tested).
  • Client bundle. The sidebar now imports saveChatRailOpen from chat-prefs.ts, a 'use server' file that pulls in the service-role client through general-settings.ts. Client code gets only the action reference. plan-row.test.ts passes, and so does next build (see Tests).
  • Embeds and migrations. No embeds. No migration of its own (00407–00413 are #1812's).

Follow-ups (not blocking)

  1. Three settings are saved but nothing uses them yet. Default mode and Ask Chat on every page are read in #1841 and later. Answer language, Notify me and Show "Thought for N s" aren't read in any open PR, but the Help article says they already work. Either mark them as coming soon or keep the article's wording until they're wired up.
  2. Back to Chat can skip a chat you just had open. It only goes back to chats in the menu's list (the newest 100). If you opened an archived or older chat from All chats or search, it goes to Chat Home instead.
  3. Default mode accessibility. Each radio is its own tab stop and there is no arrow-key navigation. The lock reason for Full auto is only in title, which keyboard and screen-reader users don't get. Adding aria-describedby or visually hidden text would fix that.
  4. Two h1s on Settings. The shell header has one ("Settings") and the page has its own title.
  5. A failed rail save isn't reported. The rail stays as clicked and goes back on the next load. The menu toggle behaves the same way, so this is consistent.

Merge status

  • Base: #1838 at 59098e80d. The current #1838 head (7da743de1) merges in with the one chat-shell.tsx conflict above. It already contains origin/main (a8121a6c8), so take-1839 is up to date with main.

Tests (on take-1839)

tsc clean. Vitest for chat lib, components and API, Chat pages, layout, chat-prefs, chat-home, guards (plan-row), subscription-guard-coverage, proxy and dashboard-navigation: 56 files, 633 tests pass. eslint is clean and yarn format:check passes (it failed before the fix). next build --webpack passes with dummy env (compile and all 75 pages).

gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 30, 2026
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 30, 2026
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 30, 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.

Merging in order with the other approved Chat PRs. This head merges current main; where they overlapped, both sides are kept. Its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build. Chat stays behind CHAT_AGENTIC.

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 30, 2026
@gkhngyk
gkhngyk merged commit 9dfc39a into ansvisor:main Oct 30, 2026
7 of 9 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