Libra CodeHub

CedarCopilot/cedar-mail

Branch: staging

feat(chat): search past chat threads by title and message content

open#2814CedarCopilot

CedarCopilot wants to merge 1 commit into staging from feat/chat-history-search

Not deployedTimeline and evidence
  1. Opened
    Sep 17, 2026, 3:48 PM
  2. Sep 17, 2026, 4:06 PM
  3. Merged, live on staging, live on prod, observed
    Pending
  4. Not deployed

    Not deployed

    Pending

Libra has no production signal for this change yet because it has not deployed. Libra checks hourly for 3 days after each deploy.

Summary

  • Adds a search bar to the History popover (embedded chat panel tab bar) and the Recent popover (left sidebar Chats section) , the two places past chat threads are listed.
  • Adds a search-chat-history in-app agent tool so the chat agent can search the user's own past threads too.
  • Search hits both chat_threads.name and chat_messages.content , per feedback from Zach in #cedar-concentrate, title-only search "wouldn't work" for a thread whose title never mentions what's actually inside it (his example: a CSV account upload buried in a message). Any result whose match wasn't in the title shows a snippet of the matching message.

Implementation

  • services/chat/search-chat-threads.ts , shared search core, reused by the tRPC route, the agent tool, and (indirectly) both frontend surfaces.
  • trpc/routes/chat.ts , new chat.searchThreads query, same SELF-only assertActor gating as getThreads.
  • mastra/tools/chat/searchChatHistoryTool.ts , new in-app-only tool, registered on both the granular chat agents and the family-surface Master agent (master-surface.ts) so it works regardless of the cedar-master-agent-families flag state.
  • db/migrations/chat_search_trgm.sql , pg_trgm GIN trigram indexes on chat_messages.content and chat_threads.name for ILIKE '%x%' substring search, mirroring the existing crm_email_threads_subject_trgm.sql precedent. Already applied to the dev database.
  • Frontend: EmbeddedCedarChat.tsx (History popover) and LeftSidebarContent.tsx (Recent popover) both get a filter field styled per crystallized.md §3.4 (h-9, no rule underneath, placeholder doubling as the panel title), debounced, falling back to the existing thread list when the query is empty.

Test plan

  • pnpm --filter @zero/server run types , clean
  • pnpm --filter @zero/mail run types , clean
  • search-chat-threads.integration.test.ts (real DB): content match with snippet, title match, cross-user isolation , all passing
  • Migration applied to dev DB (idx_chat_messages_content_trgm 62MB, idx_chat_threads_name_trgm 1.7MB, both valid)
  • Manual: open History/Recent popover, search a thread by content not in its title, confirm the snippet surfaces and clicking switches to it
  • Manual: ask the in-app agent to search a past chat and confirm it uses the new tool

🤖 Generated with Claude Code

RetriggerConfidence Score: 3/5

The PR is not safe to merge until chat-history search works on the Agent SDK harness and stale search results can no longer trigger actions for a previous query; explicit repository-rule violations must also be corrected.

Findings

  1. P1 Harness Omits History Search
  2. P1 Stale Results Remain Actionable
  3. P2 Snippet Query Loads Every Match
  4. <img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="t
Show production surfaces and changed-file mapping

Production surfaces

Libra has not measured any production surfaces for this change yet.

Changed files → surfaces

  • apps/mail/modules/cedar-os/src/cedar-os-components/chatComponents/EmbeddedCedarChat.tsxno production surface mapped
  • apps/mail/modules/conversations/components/LeftSidebarContent.tsxno production surface mapped
  • apps/server/src/db/chat-schema.tsno production surface mapped
  • apps/server/src/db/migrations/chat_search_trgm.sqlno production surface mapped
  • apps/server/src/mastra/agents/chat-agent.tsno production surface mapped
  • apps/server/src/mastra/tools/chat/searchChatHistoryTool.tsno production surface mapped
  • apps/server/src/mastra/tools/master-surface.tsno production surface mapped
  • apps/server/src/services/chat/search-chat-threads.integration.test.tsno production surface mapped
  • apps/server/src/services/chat/search-chat-threads.tsno production surface mapped
  • apps/server/src/trpc/routes/chat.tsno production surface mapped