Skip to content

fix(studio): classify destructive tool approvals by name tokens - #2230

Merged
kantord merged 5 commits into
mainfrom
fix/studio-approval-destructive-2224
Oct 14, 2026
Merged

kantord merged 5 commits into
mainfrom
fix/studio-approval-destructive-2224

Conversation

@peppescg

@peppescg peppescg commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Stack: part of gh stack #2227 (… ← #2232 ← this PR ← #2233). It moved into the stack because the chat port (#2207) builds on isDestructiveToolName. The rebase was conflict-free and the gates were rerun on the rebased head: server 195, web 980, browser 60.

Summary

This fixes the tone of the chat approval card (#2224, part of #2210). The card used a word-boundary regex on the tool name to choose between the destructive (red) and warning (amber) treatments. \b doesn't split camelCase or snake_case, so DeleteFile, delete_file, removeBranch, and drop_table got the amber card and badge. The card now matches whole name tokens against the same seven verbs. Every name the old regex classified as destructive still is, and verbs inside longer words (confirm, format, dropdown, deleted_items_report) still read as warnings.

What changed

  • features/chat/destructive-tool.ts (new) holds a pure classifier, isDestructiveToolName, and its tokeniser, toolNameTokens:
    • The name is split into runs of ASCII letters and digits. Every other character separates them: _ (including MCP's server__tool), -, ., /, :, and spaces.
    • Each run is kept whole and is also split at case boundaries: removeBranch, DeleteFile, HTTPDelete, v2Delete.
    • A name is destructive when any token is exactly delete, remove, drop, revoke, destroy, purge, or rm. That's the same verb set as before.
  • approval-panel.tsx calls isDestructiveToolName instead of the regex. Nothing else in the card changes.
  • user-docs/operating/studio.md says when the card is red, and that the color comes from the tool name only.

Structured risk signal

Scope item 2 asked whether the permission ask carries a structured risk signal. It doesn't. PermissionAsk in contracts/proto/mecatl/v1/harness.proto and PermissionAskEventPayload in the published SDK (0.4.0) carry askId, tool, args, reason, callId, and an optional guardrail scope. The guardrail.kind field is action, result_release, or unknown, which describes what an approval releases, not how risky it is. MCP tool annotations such as destructiveHint aren't forwarded in the ask. The tool name is still the only input. If the daemon adds a risk field later, it should take precedence and this classifier becomes the fallback.

Visible change

Approval cards for tools whose name has a destructive verb as a camelCase, PascalCase, snake_case, or MCP-style word now use the destructive treatment: red border and tint, red shield icon, and red badge. Before, they used the warning treatment. Other cards are pixel-identical, including Edit (amber) and rm (red).

Differences from the prototype

  • The prototype (stack-08, apps/web/src/features/chat/approval-panel.tsx) exports the same word-boundary regex as destructiveTool, and approval-detail-panel.tsx reuses it. So the prototype has the same bug, and this PR deliberately classifies differently: delete_file, DeleteFile, and the other names in the tests are red in Studio and amber in the prototype. The treatment itself (classes and tokens) is unchanged. When the prototype's approval panels are ported (Studio alignment: chat UI from the prototype on Studio's chat logic #2207), they should call isDestructiveToolName instead of importing the regex.
  • Classification differs from the prototype only for names the old regex missed. For names it already matched, both agree.

No regression

Pinning tests

approval-panel.test.tsx was committed first, alone (963264cce), against the unchanged panel. It renders ApprovalPanel and reads the tone from the card, the icon, and the badge together, and it fails on a mixed tone. It pins 34 names:

  • 18 destructive, including delete, DELETE, rm, RM, Remove file, git rm, rm -rf, delete-file, fs.delete, mcp/delete, and server:drop
  • 16 warning, including Bash, Edit, Read, Write, PresentPlan, confirm, format, term, dropdown, deleted_items_report, rmdir, undelete, and removal

All 34 pass on the base and on the fix, unchanged.

New tests

  • approval-panel.test.tsx adds 7 bug cases (additions only): DeleteFile, delete_file, RemoveBranch, removeBranch, drop_table, revokeToken, and github__delete_branch render destructive.
  • destructive-tool.test.ts (77 tests):
    • 39 destructive names: 18 the old regex already caught (including the mixed-case ReMove), and 21 it missed, including every name the issue lists
    • 27 non-destructive names, including the issue's Read, Edit, deleted_items_report, and Bash, and the false-positive guards confirm, format, term, terminal, dropdown, farm, purgeable, dropbox_upload, and list_removed_files
    • a superset check that enumerates all 14,424 names of up to three pieces, built from verbs in several casings, ordinary words, separators, digits, and a non-ASCII letter. Every name the old regex classifies as destructive must still be destructive.
    • 10 tokeniser cases

Proof that the tests catch the bug

With isDestructiveToolName temporarily switched back to the old regex, 28 tests fail: the 7 panel bug cases and the 21 classifier names the old regex misses. Every pinning test, false-positive guard, and the superset check still pass. Three more mutations were each caught:

  • a plain substring match: 17 failures
  • dropping the whole-run token: the superset check fails on delete
  • dropping the case-boundary split: 17 failures

Gates

Gate Base e9c216aa1 Head 828e44de4
task studio:check, web 114 files, 724 tests 116 files, 842 tests (+118 new)
task studio:check, server 24 files, 187 tests 24 files, 187 tests
task studio:browser 54 passed 54 passed

Lint, typecheck, and the generated-artifact check pass on both. task docs passes on the head. The browser journeys and the screenshots ran on dc99b41e7, which differs from the head only in where one test row sits in destructive-tool.test.ts.

Modified tests

None. Every test file that existed on main is unchanged. approval-panel.test.tsx is new in the pinning commit, and the fix commit only adds a block to it.

Screenshots

Captured with a throwaway Playwright journey (Chromium, not committed). It uses the offline BFF fixtures from e2e/fixtures.ts, the same session, tool-call, and permission.ask frames as e2e/chat-approval.spec.ts, a fixed clock (2026-09-25 12:30 UTC), Europe/Rome, and en-US. Each card was shot at desktop 1280×800 and mobile 390×844, in light and dark, as the card alone (2× upscale) and as the full page. Before is main (e9c216aa1) and after is this PR's head (828e44de4). Each tree was captured twice, and the two runs matched pixel for pixel. Every pair was pixel-compared, and red boxes mark the regions that differ. Only the delete_file card differs. On each full page, the differing pixels are exactly those of the card. The Edit and rm pairs are pixel-identical. Desktop composites are downscaled to 1600px wide.

delete_file (was amber, now red)

Intended change: the card, shield icon, and tool badge take the destructive treatment. Nothing outside the card changes.

delete_file card, desktop light

Dark, mobile, and full page

Card, desktop, dark:

delete_file card, desktop dark

Card, mobile, light:

delete_file card, mobile light

Card, mobile, dark:

delete_file card, mobile dark

Full page, desktop, light:

delete_file page, desktop light

Full page, desktop, dark:

delete_file page, desktop dark

Full page, mobile, light:

delete_file page, mobile light

Full page, mobile, dark:

delete_file page, mobile dark

Edit (amber, unchanged)

Unchanged: pixel-identical before and after.

Edit card, desktop light

Dark, mobile, and full page

Card, desktop, dark:

Edit card, desktop dark

Card, mobile, light:

Edit card, mobile light

Card, mobile, dark:

Edit card, mobile dark

Full page, desktop, light:

Edit page, desktop light

Full page, desktop, dark:

Edit page, desktop dark

Full page, mobile, light:

Edit page, mobile light

Full page, mobile, dark:

Edit page, mobile dark

rm (red, unchanged)

Unchanged: pixel-identical before and after.

rm card, desktop light

Dark, mobile, and full page

Card, desktop, dark:

rm card, desktop dark

Card, mobile, light:

rm card, mobile light

Card, mobile, dark:

rm card, mobile dark

Full page, desktop, light:

rm page, desktop light

Full page, desktop, dark:

rm page, desktop dark

Full page, mobile, light:

rm page, mobile light

Full page, mobile, dark:

rm page, mobile dark

Review fixes

Fixes from the final regression and security review of the stack (stack #2227). Each one comes with a test that fails without the fix.

  • The superset claim failed for ſ and K (nit). The old regex matched case-insensitively with the u flag, which folds ſ (U+017F) to s and the Kelvin sign K (U+212A) to k. So deſtroy and revoKe were red under the old regex but amber under the ASCII tokenizer. Tool names are now NFKC-normalized before they are split, so those letters, and fullwidth letters, read as their ASCII forms. The exhaustive no-regression check gains both letters, plus the fragments that combine with them into verbs. On the old code, six tests fail, including the exhaustive check, which fails on deſtroy. (1af49eb4d)
  • The MCP server name turned every tool red (minor, cosmetic). An MCP tool is named mcp__<server>__<tool>, so every tool from a server called remove_bg got the red card, for example mcp__remove_bg__preview. The classifier now judges only the tool part when the server segment is a valid server name ([A-Za-z0-9_]+, split at the first __, as the daemon splits it). Any other shape is judged whole.
    • No regression: valid server names consist only of word characters, so the old \b regex could never match inside one. A new exhaustive check over MCP-shaped names proves that no name the old regex flagged loses its red card. It also fails if the server-name guard is removed. (a9e6ecd94)
  • rmdir is now red (minor). rmdir deletes a directory. It was pinned amber only because the old regex couldn't see rm inside the word, so the pin recorded a false negative, not a decision. It is now a destructive verb, and its two amber pins (classifier and card tone) move to the destructive lists. Every other pinned colour is unchanged. (a9e6ecd94)
  • On the previous head, 15 of the new and moved assertions fail; all pass now. The Studio operating page lists rmdir and explains the MCP rule.
Gate Result
task studio:check passed: web 1002 tests (980 before; +22 classifier and card cases), server 195
task studio:browser 60 passed (unchanged)
task docs:check passed, 0 broken links

Screenshots: Before is a9cc2a4c5 (the NFKC change has no visible effect on these names), After is a8bf32036. Each tree was captured twice, and both captures were pixel-identical. Only the rmdir and mcp__remove_bg__preview cards change. delete_file, Edit, and mcp__remove_bg__delete_image are pixel-identical before and after. The prototype still uses the old word-boundary regex, so it shows the same tones as Before for these names. Its column shows its approval card for layout reference only.

rmdir (was amber, now red):

rmdir card, desktop light

mcp__remove_bg__preview (was red because of its server name, now amber):

mcp__remove_bg__preview card, desktop light

Dark, mobile, full page with prototype, and unchanged cards

rmdir card, desktop dark
rmdir card, mobile light
rmdir card, mobile dark
rmdir page with prototype, desktop light
mcp__remove_bg__preview card, desktop dark
mcp__remove_bg__preview card, mobile light
mcp__remove_bg__preview card, mobile dark
mcp__remove_bg__preview page with prototype, desktop light
mcp__remove_bg__delete_image card (red, unchanged)
delete_file card (red, unchanged)
Edit card (amber, unchanged)

Re-verification (2026-10-11)

  • NFKC let compatibility characters hide a verb (nit). Normalizing turned x, fi, ①, ª and ² into ASCII letters and digits, which fused into a neighbouring verb, so xdelete, ①delete and x²rm went from red (old regex) to amber. The classifier now reads the action both as written and normalized. (722398adb) Tests: six new destructive cases, and a fullwidth letter and a circled digit in the exhaustive superset check (7 tests fail without the fix). No visible change for ordinary names.

Gates on the restacked head 722398adb: studio:check passes (web 1,042, server 210 tests). At the stack top (#2256): studio:browser 118 passed, 30 skipped; the mecated --mock integration suite 8 passed. The browser suite takes 5.3 minutes on a CI runner.

Commit hashes cited earlier in this body predate the restacks; the current commits keep the same subjects. Hashes in Review fixes are updated.

Closes #2224

🤖 Generated with Claude Code

@peppescg peppescg self-assigned this Oct 9, 2026
@peppescg
peppescg force-pushed the fix/studio-approval-destructive-2224 branch from 828e44d to 3b2b7b1 Compare October 10, 2026 09:24
@peppescg
peppescg changed the base branch from main to feat/studio-learning-1855 October 10, 2026 09:24
@peppescg
peppescg added this pull request to stack #2227 October 10, 2026 09:24
@peppescg
peppescg force-pushed the fix/studio-approval-destructive-2224 branch from 3b2b7b1 to b9a094f Compare October 11, 2026 14:57
@peppescg
peppescg force-pushed the fix/studio-approval-destructive-2224 branch from b9a094f to 97bf12c Compare October 11, 2026 15:48
@peppescg
peppescg force-pushed the fix/studio-approval-destructive-2224 branch from 97bf12c to c8e609c Compare October 13, 2026 13:29
@peppescg
peppescg force-pushed the fix/studio-approval-destructive-2224 branch from c8e609c to 722398a Compare October 14, 2026 08:44
@kantord
kantord force-pushed the fix/studio-approval-destructive-2224 branch 2 times, most recently from ed35206 to 3aa95f4 Compare October 14, 2026 08:59
Base automatically changed from feat/studio-learning-1855 to main October 14, 2026 09:00
peppescg and others added 5 commits October 14, 2026 12:00
Pin the destructive and warning treatment of the approval card, icon,
and badge for names the word-boundary classifier already gets right,
before the classifier changes.

Refs #2224

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The approval card chose its destructive treatment with a word-boundary
regex, and `\b` does not split camelCase or snake_case, so DeleteFile,
delete_file, removeBranch, and drop_table got the warning card and
badge. Split the tool name into ASCII alphanumeric segments, each kept
whole and also split at case boundaries, and match whole tokens against
the same seven verbs. Verbs inside longer words (confirm, format,
dropdown, deleted_items_report) still read as warnings, and every name
the old regex classified as destructive still is.

The permission ask carries no structured risk signal, so the tool name
remains the only input.

Closes #2224

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The word-boundary regex this classifier replaced matched case-insensitively
with the u flag, which folds ſ (U+017F) to s and the Kelvin sign (U+212A)
to k, so deſtroy and revoKe were destructive under the old regex but not
under the ASCII tokenizer. The superset claim did not hold for them.

Tool names are now NFKC-normalized before they are split, so those
letters, and fullwidth letters, read as their ASCII forms. The exhaustive
no-regression check gains both letters and the fragments that combine
with them into verbs, and the named cases cover them directly.

Refs #2224

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
An MCP tool is named mcp__<server>__<tool>, and the token classifier read
the server segment too, so every tool from a server named, say,
remove_bg (mcp__remove_bg__preview) got the red destructive card. The
server name is configuration, not an action. The classifier now judges
only the tool part when the server segment is a valid server name
([A-Za-z0-9_]+, split at the first __ as the daemon does). Any other
shape is judged whole, so no name the old word-boundary regex flagged
loses its red card; a new exhaustive check over MCP-shaped names proves
it, and fails if the server-name guard is dropped.

rmdir deletes a directory, but it was pinned amber only because the old
regex could not see it inside the word. It is now a destructive verb, and
its two amber pins (classifier and card tone) move to the destructive
lists. Every other pinned colour is unchanged.

The Studio operating page lists rmdir and explains the MCP rule.

Refs #2224

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…verb

NFKC normalization made ſ and the Kelvin sign read as s and k, but it
also turns characters such as fullwidth x, the fi ligature, circled
digits, ª, and superscript digits into ASCII letters and digits. Beside
a verb they then fused into one token, so xdelete, ①delete, and x²rm,
red under the old word-boundary regex, turned amber.

The classifier now reads the action both as written and normalized, and
is destructive if either form has a verb token. The exhaustive superset
check gains a fullwidth letter and a circled digit.

Refs #2224

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@kantord
kantord force-pushed the fix/studio-approval-destructive-2224 branch from 3aa95f4 to b3e484b Compare October 14, 2026 09:00

@kantord kantord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: as per discussion, the logic of matching text to determine the danger level will be removed from the FE code in a follow up. approving this just in the interest of aligning the current implementation with the prototypes, fixing the actual technical issues is anoterh follow-up

@kantord
kantord merged commit 1ade902 into main Oct 14, 2026
31 checks passed
@kantord
kantord deleted the fix/studio-approval-destructive-2224 branch October 14, 2026 09:40
@kantord

kantord commented Oct 14, 2026

Copy link
Copy Markdown
Member

Post-merge review follow-ups for this PR. No blockers or regressions found. The one item worth tracking was filed here:

Other candidate findings (verb-list gaps, homoglyph names, the duplicated mcp__server__tool split) were checked and dropped as not worth tracking.

Fully or partially written by an AI agent.

@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 20, 2026
2 tasks
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.

Studio chat: classify destructive tool approvals by name tokens, not word boundaries

2 participants