Skip to content

feat(chat): add the composer's / @ and + menus, with a reference search (W1-12) - #1828

Merged
gkhngyk merged 8 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-12-menus
Oct 30, 2026
Merged

gkhngyk merged 8 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-12-menus

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat Wave 1, behind CHAT_AGENTIC. Stacked on #1827. The diff against main includes the PRs below it until they merge. The product owner saw it in the /dashboard/chat/preview page and approved it.

W1-12: the / @ + menus.

  • "/" opens from the button or a leading "/". It lists /analyze "Analyze", /report "Create a report on" and /create "Create content for". Typing filters by command or name word; without a match it shows "No shortcuts match". The grouped layout (Do · Report · Library · Create a skill) fills in when skills land in Wave 2. Hidden for read-only roles.
  • "@" Reference your data opens from the button or an "@" at a word start. It lists the page's own references (the references prop, for W1-08), then the brand's matches from the new searchChatReferences(brandId, q).
    • The action: behind the flag; it never throws and returns { ok, failure }; at most 8 rows.
    • What it searches: tracked prompts and open Action Center tasks through RLS, and site pages with the service role after an RLS check on the brand.
    • A pick becomes a chip and is sent as { type, id, label, scope }; the id is never shown.
  • "+" holds Attach files (when onAttach is given; W1-13) and Connect a tool. Admins go to Settings › Integrations; others send an access request in one click. Read a page and Create an image are hidden until their waves.
  • Keys: ↑↓, Enter, Esc (keeps the text), and a click outside closes.

The components aren't wired into /dashboard/chat yet; the shell PRs (W1-01…05) wire them in. No migration, no new dependency.

Related issue

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

Type of change

  • feat — New feature

How to test

yarn vitest run src/components/chat src/lib/actions/chat-references.test.ts (39 tests): filtering, keys, ids never shown, the action's RLS path and failures, and read-only rules.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: eslint/prettier, typecheck and the related tests pass (run one at a time on an 8 GB machine; build left to CI)
  • Tests added
  • Help article: written when the composer is wired into the Chat page (the shell PR adds help/chat)

🤖 Generated with Claude Code

cihan-gyk and others added 4 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]>
… and a read-only view

Chat Wave 1, W1-10 (CHAT-02, agentic update). A copy of the mockup's
composer (compHTML), as components to be wired into the Chat pages by the
shell (W1-01).

- ChatComposer: the box, a toolbar with the run mode and Send, and the line
  under it. Variants: home (2 rows), dock and panel (1 row). The box grows
  to 240px, then scrolls.
- Enter sends, Shift+Enter adds a line. Enter during an input method's
  composition or on a touch screen is the box's own (composerKeyAction).
  Send is off for an empty box.
- While a run answers, Send is Stop, and Esc stops too. The box steers:
  "Steer while I work…". Enter stops the run, its done steps kept, and
  sends the text as the next message (onSteer; decided 2026-10-30). The
  line under reads "Enter stops this run and sends your message". A page
  without steering keeps the text until the run ends.
- ModeSwitch: Ask me first · Auto, ask before changes · Full auto, each pick
  with the mockup's toast. Full auto below Growth is locked: "Needs Growth",
  and it can't be picked.
- Analysts and Agency partners read only: no mode switch, a "Read-only ·
  Analyst" link to Your access, and "@ data · read-only" under the box.
- The model button reads "Auto · Haiku reads, Sonnet writes". Slots for
  the + / @ tools (W1-12) and the usage meter (W1-23).
- The Chat pieces preview gets a Composer section: home, a dock with a
  pretend run, and an Analyst's panel.

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

Chat Wave 1, W1-11 (CHAT-02 items 5–10c), on the composer (W1-10).

- Context chips above the text: what Chat looks at, by name ("Ansvisor",
  "Last 30 days"), never an ID. A label over 28 characters is cut, with the
  whole name in its tooltip. × asks the page to drop it for the chat
  (onRemoveChip). A send or a steer carries the chips left
  (onSend(text, { context })).
- One ghost suggestion in the empty box, dim, with a Tab key hint. Tab, or a
  click on it, makes it the text with the cursor after it. Typing replaces
  it, and it comes back when the box is empty again. It never sends by
  itself: while only it shows, Enter does nothing and Send stays off. With
  text, Tab moves on as usual. No ghost while a run answers. The page picks
  the suggestion: the variant's starter, then a clear follow-up, and a READ
  one for Analysts and Agency partners.
- The line under reads "Tab to accept · / skills · @ data" while the ghost
  shows.
- The preview's composers get the mockup's chips and starters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Chat Wave 1, W1-12 (CHAT-02 items 11–17, agentic update; mockup #slash,
#atmenu, #plusmenu), on the composer's chips (W1-11). Menus open above the
box: ↑ ↓ move, Enter picks, Esc closes and keeps the text, and a click
outside closes them.

- /: typed first in an empty box, or from the / button. It lists Wave 1's
  shortcuts, which start a message: /analyze "Analyze", /report "Create a
  report on", /create "Create content for". Typing filters them by command
  or a word of the name. From the button, the box's text stays after the
  starter. Analysts and Agency partners have no / (as the mockup). Skills
  join the menu in Wave 2.
- @: typed at the start of a word, or from the @ button at the cursor. It
  references data: the page's own charts and metrics first (references,
  for W1-08), then the brand's matches (searchReferences), up to eight. A
  pick leaves the "@…" text and shows as a chip by name. × takes it off,
  and the send carries it (references: type, id, label, scope). No ID
  shows.
- searchChatReferences (server action, CHAT_AGENTIC): the brand's tracked
  prompts, its pages and its open Action Center tasks that match, a source
  at a time. Read with the person's session; site_pages isn't in the
  generated types, so it is read with the service role for a brand the
  session can read. Template tasks are named from their keys. A search is
  made safe for PostgREST's filters. It answers { ok, failure } and never
  throws (ansvisor#1777).
- +: Attach files when the page uploads (onAttach, W1-13). Connect a tool:
  Settings › Integrations for an Admin; for others, "Ask your Admin to
  connect" sends one access request (B2). Read a page and Create an image
  stay hidden until their waves.
- The preview's composers reference the mockup's chart, metric, table,
  page and task.

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
The × button unmounts with its chip, so a keyboard user lost their place
(focus fell to the page body). Focus the message box after removing a chip.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
# Conflicts:
#	web/src/components/chat/composer/chat-composer.tsx
PostgREST reads * as % in like and ilike, so "@price*list" matched
anything between the two words. Strip it with the other pattern
characters.

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 602a4e2. It's this PR, a merge of #1827's new head, and one small fix. Nice work: the menus are small, and the @ search is narrow enough to read in one pass.

  • Merging #1827's new head. #1827 now puts the focus back in the box after a chip is removed, on the same line where this PR changed the × to chip.remove. The merge keeps both: chip.remove?.(); box.current?.focus();. #1827's focus test passes.
  • * in the @ search. referenceQuery already turns %, _, \ and ,() into spaces, but PostgREST reads * as % inside like/ilike, so @price*list matched anything between the two words. Only the person's own brand is searched, so this is about correctness. * is now stripped too, and a new test in references.test.ts fails without it.

Checked, fine

  • With CHAT_AGENTIC off the action returns chat_off after the session and profile reads, the same order as the other Chat actions.
  • The brand is checked through the person's session first. Prompts and tasks are read through the session with a brand_id filter. site_pages is read with the service role, but only after the brand check and filtered by brand. It has member RLS, so the session client would do (nit).
  • The query is capped at 100 characters. Each source has a limit (8 prompts, 8 pages, 100 tasks), and the menu shows 8. The action_tasks → actions!inner embed has one FK and already runs in production code.
  • / is hidden for read-only roles. "Connect a tool" goes to Integrations for Admins, and everyone else gets an "ask your Admin" request with its own daily limit. Labels render as text, and arrow keys, Enter and Esc work.

Nits: the connect-request toast shows a generic "failed" for too_many / daily_limit. Enter while @ is still loading sends the raw @text. The textarea has no aria-activedescendant. Each pause in typing costs auth, profile, brand and three reads.

Tests: chat references, composer, preview, plan-row.test.ts, subscription-guard coverage and demo brand pass. tsc, eslint and prettier are clean, and next build passes. No migrations.

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 added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 30, 2026
…svisor#1833 and ansvisor#1834 fixes) 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
#	web/src/components/chat/composer/chat-composer.test.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 0e8c0e6 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