Skip to content

feat(chat): search chats with Ctrl K and list them in All chats (W1-06) - #1838

Merged
gkhngyk merged 28 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-06-search
Oct 30, 2026
Merged

gkhngyk merged 28 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-06-search

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat Wave 1, behind CHAT_AGENTIC. Stacked on #1837 (W1-02). 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-06: search, Ctrl K and All chats.

  • Search API: searches titles and message text (00407's search_tsv), with prefix words, so "citat" finds "citations".
  • Menu: Search chats replaces the day groups while typing. All chats · n › and Archived · n › links sit under the list.
  • Ctrl K / ⌘K opens the search palette, with New chat first. With the menu hidden, the strip has a Search button.
  • All chats (/dashboard/chat/all): Active and Archived tabs, search, the mockup's filters (Running, Needs you, Done, Mine, Team), and bulk archive / unarchive. It also has ← Back to Chat.
  • Archive toast: "Archived · find it in All chats › Archived", as the mockup has it.

No migration, no new dependency.

Related issue

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

Type of change

  • feat — New feature

How to test

Ctrl K, type part of a title: it's found. /dashboard/chat/all: tabs, filters, bulk archive. Tests: search route, palette, All chats.

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 16 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]>
…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]>
@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 7da743d: one fix commit on this branch (1edfade, described below), then a clean merge of the fixed #1837 branch. On the result, tsc is clean and src/lib/chat, src/components/chat and plan-row.test.ts pass (502 tests).

I reviewed only what this PR adds on top of #1837 (680b3caa9..59098e80d): the search API, the Ctrl K palette, Search chats in the menu, All chats and the archive toast.

Fixed: a domain, a number or an email address was never found

searchTermsOf keeps only letters and digits, so nike.com turns into nike:* & com:*. Postgres's parser stores nike.com as one token ('nike.com'), so the com:* term matches nothing and the whole search comes back empty. I checked this with to_tsvector('simple', …) @@ to_tsquery('simple', …):

Typed Sent today Found?
nike.com nike:* & com:* no
4.5 4:* & 5:* no
[email protected] ops:* & nike:* & com:* no
İstanbul (JS lowercases it to i̇stanbul) i:* & stanbul:* no

The commit keeps each space-separated word whole and quotes it as a prefix ('nike.com':*). Postgres then splits the word the same way it split the text, and lowercases it too. A ' is doubled and a \ dropped, so any operators the person types stay inside the quotes and never reach to_tsquery as syntax. I checked every new query shape with to_tsquery (operators, quotes, backslashes, punctuation-only words): no syntax errors, and all of them match. The fake's textSearch now keeps nike.com as one word, as Postgres does, and there are new tests (both fail without the fix).

Suggested commit: fix(chat): find a domain, a number or an email address in Search chats (3 files: lib/chat/conversations.ts, its test, testing/fake-supabase.ts).

Checked and fine

  • Who sees what. Search is read as the person, so the policies decide what comes back. I added 00407 in a rolled-back transaction and tested it. A member sees their own chats and the team's shared ones. They never see a teammate's private chat, a deleted chat (their own or a shared one), or another workspace's chats. Message matches follow the same rule. Anon can read neither table. On top of the policies, the code also checks the owner, and only the person's own chats show under Archived.
  • No text from other chats. The API returns menu rows (title, state, initials) and never a message snippet. The message query reads only conversation_id, then reads those chats again through the policies.
  • Query safety. Zod limits q to 1–200 characters after trimming and limit to 1–50. Search uses at most 8 words. A query with no letters or digits returns [] without a database call. No ilike is added.
  • Flag off. The search route returns 404 (tested), /dashboard/chat/all returns notFound(), and nothing else new runs.
  • Read-only workspace. The new route is a GET. Bulk archive uses the existing PATCH, which is already gated.
  • Embeds. None added.
  • Ctrl K. Nothing else in the app uses it. The demo preview only forwards it into its frame. preventDefault stops the browser's address-bar search. Ctrl J stays free for #1841.
  • Client bundle. The new client components import only types from lib/chat/conversations. plan-row.test.ts passes on the merge.

Follow-ups (not blocking)

  1. The search indexes can't be used for members. @@ (ts_match_vq) isn't leakproof, so under row-level security Postgres can't use it as an index condition. Every search seq-scans all of chat_messages and chat_conversations across every workspace, then applies the policies. In a rolled-back test with 200k messages, each search took about 110 ms on a seq scan, and enable_seqscan = off didn't change the plan. The tables are empty today and the feature is behind the flag, but before Chat is on widely this should become a function in the Chat migration block. That function can scope to the person's visible chats first and then use the GIN index.
  2. Message matches are capped at the newest 200, from every chat the person can read. One busy chat, or active chats under Archived, can push older matches out of the list. The function from (1) would fix this too, for example with distinct on (conversation_id) limited to the view.
  3. All chats loads at most 200 rows per tab with no "more". The tab count can be higher than the rows shown, so older chats can only be reached through search. All chats search also uses the default limit of 20.
  4. All chats selection survives a new search or filter. Archive selected can then act on rows that are no longer visible. Clearing the selection when the query or filter changes would avoid this.
  5. Accessibility nits. Each All chats row is a role="link" that contains a checkbox (one interactive element nested in another). The tabs have no aria-controls and no arrow-key navigation.

Merge status

  • Base: #1837's head (680b3caa9), which includes #1812 and an earlier #1829–#1832. The current #1832 head (7ebe5d35c, with the #1829–#1831 fixes) merges in cleanly, and so does origin/main (a8121a6c8).
  • No migration of its own. (00407–00413 belong to #1812. #1789 also claims 00407.)

Tests (on the fix + #1832 + main)

tsc clean. Vitest for chat lib, components, API, pages, plan-row, subscription-guard-coverage, proxy, dashboard-navigation and demo: 47 files, 577 tests pass. eslint and prettier are clean on the touched paths.


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
…nsvisor#1837 fixes) into take-1843

# Conflicts:
#	web/src/components/chat/chat-shell.tsx
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 30, 2026
…isor#1838 heads and its review fix) into take-1843

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/chat/_chat-page-access.test.ts
#	web/src/app/[locale]/(dashboard)/dashboard/chat/_chat-page-access.ts
#	web/src/components/chat/chat-thread-view.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.

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.

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