Repository navigation
feat(chat): list every tool Chat may use in one registry - #1759
Merged
Merged
Conversation
…eams The first part of the new Chat (Drive Chat specs, P0 part A1). Nothing uses it yet, and with the flag off nothing changes: today's /dashboard/agent keeps its own tables and code. - CHAT_AGENTIC turns the new Chat on, read on the server at request time (web lib/chat/flag.ts, server lib/chat-flag.js), so the same build runs with it on or off. CHAT_AGENTIC_ORGS narrows it to listed workspaces. Off unless "true", so a self-hosted install sees nothing new. - 00400 adds chat_conversations, chat_messages, chat_runs, chat_run_steps and chat_user_prefs. A chat is private to its author (CHAT-20 §16c): only they read it, admins included, and messages, runs and steps follow their chat's policies, so sharing with the team can be one more policy later. The server writes them; a person writes only their own Chat settings (menu, where pages open, focus areas, model, effort), kept on the server so they follow them across devices (DECISIONS N3). - A step's tool and debug record stay with the server: members are granted every other column. Step kinds live in chat_step_kinds, so a new kind is an inserted row, not a rewritten check. - web lib/chat/events.ts types every event a run streams (CHAT-00, with room for CHAT-25's), names steps by their place in the run, and chatEvent() refuses a tool's name, a debug record, an id or a dollar amount before an event reaches the browser. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A deleted brand now leaves its chats with their author, as about the workspace, the way agent_conversations does (00009), rather than deleting a person's private history with it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd add app links and the step converter A uuid in an event's text (a page path, a link the person pasted) no longer stops the run: chatEvent() shows it as "…". The answer's own text is still sent as it is, and forbidden keys still throw. - Forbidden keys are patterns now, in the type (ChatForbiddenKey) and at run time alike: any tool key (toolInput, toolResult…) and params; debug, tokens and latency; money (usd, price, amount, spend, cost, cents). A cost multiplier, a percent and a tooltip still pass. - Deliverable cards and page.opened get an optional href for their Open (CHAT-06, CHAT-25): a path under /dashboard/ only, with no host, query, fragment, "//" or ".." part, kept whole by the masking. - steps.ts holds chat_run_steps' member columns (every one but tool and debug_json, checked against the migration's grant) and toClientStep(), the one way a stored step reaches the browser: built field by field, so a row read with the service role gives up its tool and debug record too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ch new message - chat_user_prefs.focus holds at most the 8 areas, each once (chat_text_array_distinct: a check can't hold a subquery); the model column says the server checks it against the catalog before a run. - A trigger on chat_messages sets its chat's last_message_at (security definer, so it reaches the chat whoever writes the message; it never moves back). - The step kinds comment no longer says a kind can be removed: steps keep theirs, and there is no index on kind to find out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y be read A change applies when the app starts again: a restart when self-hosted, a new deployment on Vercel. The web flag is for dynamic server code only; a page rendered at build time would keep the build's value. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Chat P0, A2 (CHAT-20 §9): one place that says, for each tool Chat may
call, what it does, who may call it, on which plan and how a call is
approved. The approval flow (A3), the model's tool list (C3), Settings
› Chat and Roles & access (B1, B3) read these rows instead of keeping
their own lists. Nothing calls the registry yet; it sits behind no flag
because it changes nothing on its own.
- lib/chat/registry/define-tool.ts: defineTool and the row fields:
internal name, class (read / write / execute), min role (TeamRole),
plan gate (PlanId, plan Feature, or the plan's platforms), default
and maximum policy, flags (always_card, cost_card, admin may turn a
read off), cost class, label key, app route, the MCP tool doing the
same work, its CHAT-20 row and a fixture. defineTool keeps the hard
rules as rows are defined: a read runs, an execute is always a click,
and an always_card write never goes past Ask.
- read-tools.ts: 27 READ rows, each calling the MCP data function the
MCP tool of the same work calls (imported, not changed), so Chat, the
MCP Server and today's agent read the same numbers.
- write-tools.ts: create_draft, update_opportunity and
dismiss_prompt_suggestion, calling the server actions the app's own
buttons call (createContentDraft, updateOpportunityStatus,
dismissSuggestion), as the signed-in member.
- tools.ts: CHAT_TOOLS, chatTool(name) and registryCatalog(), the rows
as plain JSON-safe data for the Settings pages. No generated file:
every reader is in web/ and can call it.
- messages/en.json: chatTools.{key}.name (Settings) and .step (CHAT-03
step title) per row. The keys don't spell the tool names, since every
page gets all of en.json and a tool name never reaches a customer.
Tests: every row has its two labels and a fixture its schema takes;
names and labels are unique; routes are pages of the app; each row runs
its own function with the fixture (reads with the member's context,
writes through the app's actions, with the same arguments the pages
pass); an execute is always a click; the catalog is plain data. Against
the MCP Server: every named MCP tool is registered, reads map to reads
and writes to writes, and readOnlyHint agrees wherever a tool states it
(3 tools on main; all once ansvisor#1732 merges).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… mentions reads - registryCatalog() is now what a browser may get: each row goes by its label key (`key`), without its internal name, its MCP tool name or its spec row. A tool's name never reaches a customer (CHAT-03 item 22). The names stay on the server in CHAT_TOOLS, where the approval checks, the run steps' `tool` column and the MCP parity read them, so no second, server-side catalog is needed. chatToolByKey() leads a key a page sends back (a policy change, say) to its row. - get_mention, get_mention_competitors and get_mentions_perception: READ rows for the Mentions area's reads today's agent (/dashboard/agent) has, so Chat answers what it does. Not in CHAT-20 §9 yet; mapped to the MCP tools of the same names, with their en.json labels. Tests: the catalog has no tool name in any value and passes the event rule chatEvent() applies (clientEventProblems); every key leads back to its row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 29, 2026
Merged
The MCP context has a role since ansvisor#1762; the registry's tests build one without it, which fails the web typecheck once merged with main.
gkhngyk
approved these changes
Oct 29, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good with 0b9ae51: I made one change on top.
What I changed
- Typecheck on current main. Since #1762,
McpAuthContexthas arole. The two registry tests build the context without one, sotscfails once this is merged with main (tools.test.ts173/190,mcp-parity.test.ts26).- Both tests now pass
role: 'admin'. Inmcp-parity, the context is aconst, so it compiles on this branch's base too. - No runtime code changed. The runner that builds
ChatToolContextwill need to fillrolethe same wayresolveAgentAuth/mcp-authdo.
- Both tests now pass
What I checked
- Nothing calls the registry yet.
- No route, action or page imports
CHAT_TOOLSorregistryCatalog, so withCHAT_AGENTICoff (or on) nothing changes at runtime. - The
chatToolsstrings inen.jsonare only labels.
- No route, action or page imports
- Read rows.
- Every
readrow calls the MCP data function its MCP tool calls (lib/mcp/data,account,content,mentions). - Each one scopes by
auth.organizationId: it checks the brand, audit, action or draft against the organization before reading. - None of them writes. I read each function the rows point at, and the test checks that each read row calls an
mcp/function with the context unchanged. - Row caps match the MCP tools (
rowCap, page size 100 for mentions). get_usagereturns percentages, not dollars.
- Every
- Write rows. There are three, and each calls the server action the app's own button uses, through the member's session:
create_draft→createContentDraft:assertWritable(), the user from the session, and RLS oncontent_drafts.update_opportunity→PATCH /api/content/:id/status: the API's 402 middleware,assertOpportunityAccess, and a role check on dismiss.dismiss_prompt_suggestion→POST /api/prompts/suggestions/:id/dismiss: the 402 middleware,assertBrandAccessandassertRole.- So the read-only gate and organization scoping hold whoever calls them.
- The registry's
minRole: 'manager'is stricter than the API's dismiss roles (admin/manager/analyst). That's fine, but it only holds once the runner checksminRole(follow-up 1).
defineTool's invariants.- A read is
on. - An execute is always
click. - A write's default never passes its maximum.
alwaysCardcaps a write at Ask.- The tests cover each one.
- A read is
- The browser catalog.
registryCatalog()sends the label key, not the internal or MCP tool name. That keeps CHAT-03's "no tool names in the browser". - Classification. Each row's class matches what its function does. The rows with
mcpToolset match the MCP tools' read/write annotations (mcp-parity.test.ts). - No PostgREST embeds. No migration.
- Tests:
lib/chat/registrypasses (82 with the rest oflib/chat).tscpasses on the branch and on main merged in.
Follow-ups
- The runner (A3) must enforce each row's
minRole,planGateand policy beforerun(). The actions it calls only enforce their own roles:createContentDraftlets any member insert a draft through RLS, while the row says manager. - The write rows need a request with a session (as the file says). A scheduled run will need another path, with the same read-only and role checks.
get_shopping_visibility'sproduct_titlehas no.max(). The MCP tool has the same, so this is just for parity.
This was referenced Oct 29, 2026
gkhngyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Oct 29, 2026
Keeps main's merged copies of ansvisor#1758, ansvisor#1759, ansvisor#1776, ansvisor#1780 and ansvisor#1781.
gkhngyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Oct 29, 2026
Keeps main's merged copies of ansvisor#1758, ansvisor#1759, ansvisor#1776, ansvisor#1780, ansvisor#1781 and ansvisor#1786 (request_access's Undo is main's).
5 of 7 tasks
gkhngyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Oct 29, 2026
Keeps main's merged copies of ansvisor#1758, ansvisor#1759, ansvisor#1776, ansvisor#1780, ansvisor#1781 and ansvisor#1786 (request_access's Undo is main's, so 4c7b8cb adds nothing).
5 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Chat P0, part A2: every tool Chat may use, listed once in a registry (CHAT-20 §9 and §20). Nothing is visible. Nothing runs a tool yet; that's the engine, C3. The decision of whether a person may run a tool is A3.
web/src/lib/chat/registry/defineTooldefines each row:read,writeorexecute;prompt_volumes,shopping_analytics);chatTools.<key>.namefor settings,.stepfor a step's title, CHAT-03);30 reads wrap the MCP data functions as they are (
web/src/lib/mcp/), including the three Mentions tools today's/dashboard/agentuses (get_mention,get_mention_competitors,get_mentions_perception).3 writes let the approval flow be built and tried. Each calls the function the app's own buttons use:
create_draft→createContentDraft;update_opportunity→updateOpportunityStatus, reviewed or dismissed only, with the reason;dismiss_prompt_suggestion→dismissSuggestion.All three are
manager, policy "Ask, auto in Full auto".registryCatalog()is what settings pages (B1/B3) read. It's serialisable and carries no tool name: each row is keyed by its label key (CHAT-03 fix(ui): link MIT license text in footer to LICENSE file #22). The internal names stay on the server inCHAT_TOOLS;chatToolByKey()maps a key back.Tests (
tools.test.ts,mcp-parity.test.ts)en.jsonlabels and a fixture, and names are unique.web/src/lib/mcp/server.ts, with the same read/write split as MCP'sisReadTool. Where an MCP tool hasreadOnlyHint(all of them once feat(mcp): give every tool a title and annotations, and tell clients tool results are data #1732 merges), it matches the row's class.clientEventProblems), and none of its values is an internal or MCP tool name.Notes for later parts
Some spec rows have no data function yet (navigation, help, settings facts, GSC/GA summaries, files). They come with the context engine (CHAT-04, wave 1).
MCP tools missing from §9 (beyond the three Mentions ones) should be added to the spec.
The two draft paths differ:
create_content_draftwrites as the agent,in review;CHAT-25's
originandconversation_idcome later.Server-side role checks on writes are being added in their own PRs. Until then Chat's own gate (A3) is the role check for Chat.
Related issue
None (Chat P0, Drive › Chat).
Stacked on #1758 (Chat A1). The diff against it holds only this change.
Type of change
feat— New feature (behindCHAT_AGENTIC, nothing visible)How to test
cd web && yarn vitest run src/lib/chat/: 5 files, 82 tests (with A1's).Checklist
🤖 Generated with Claude Code