@@ -12,6 +12,7 @@ import { nativeShellDisabledMessage } from "../../../src/adapters/cursor/native-
1212import { encodeCursorRunRequest } from "../../../src/adapters/cursor/protobuf-request" ;
1313import { createCursorRequest } from "../../../src/adapters/cursor/request-builder" ;
1414import { buildCursorToolGuidanceSystemNote } from "../../../src/adapters/cursor/tool-guidance" ;
15+ import { buildCursorToolDefinitions } from "../../../src/adapters/cursor/tool-definitions" ;
1516import { CURSOR_TOOL_CALL_CONTINUATION , cursorUsesPlainToolWording } from "../../../src/adapters/cursor/tool-wording" ;
1617import { parseRequest } from "../../../src/responses/parser" ;
1718import type { CursorRunRequest , CursorServerMessage } from "../../../src/adapters/cursor/types" ;
@@ -22,6 +23,11 @@ import { createTestTranslatorBudget } from "../../helpers/translator-budget";
2223const CONCEALMENT = / d o n o t ( n a r r a t e | c o m m e n t | m e n t i o n | r e - a n n o u n c e ) | c o m m e n t a r y i s f o r b i d d e n | m u s t n o t a p p e a r i n y o u r o u t p u t / i;
2324const CLAUDE_MODELS = [ "claude-sonnet-5-5" , "cursor/claude-4.6-opus-high" , "claude-opus-5-thinking-high-fast" , "claude-4.5-haiku" , "claude-fable-5" , "claude-4-sonnet-1m" ] ;
2425const OTHER_MODELS = [ undefined , "cursor-grok-4.6-high" , "cursor/gpt-5" , "gemini-3-pro" , "composer-2.5" , "cursor/auto" , "default" , "not-claude-sonnet" ] ;
26+ const CLAUDE_CLIENT_CATALOGS = [
27+ { names : [ "Bash" , "Read" ] , wireNames : [ "Bash" , "Read" ] } ,
28+ { names : [ "Read" , "exec_command" ] , wireNames : [ "ocx_client_Read" , "exec_command" ] } ,
29+ { names : [ "exec_command" , "Read" ] , wireNames : [ "exec_command" , "ocx_client_Read" ] } ,
30+ ] ;
2531
2632function execMessage ( message : Parameters < typeof create < typeof ExecServerMessageSchema > > [ 1 ] [ "message" ] ) {
2733 return create ( ExecServerMessageSchema , { id : 1 , execId : "wording-test" , message } ) ;
@@ -55,6 +61,37 @@ const frames = {
5561afterEach ( ( ) => resetCursorBlobStateForTests ( ) ) ;
5662
5763describe ( "Cursor target-specific tool wording" , ( ) => {
64+ test . each ( CLAUDE_CLIENT_CATALOGS ) ( "Claude redirect matches the request catalog: %j" , ( { names, wireNames } ) => {
65+ const tools = names . map ( name => ( { name, description : "Fixture tool" , parameters : { } } ) ) ;
66+ const definitions = buildCursorToolDefinitions ( tools ) ;
67+ expect ( definitions . map ( tool => tool . name ) ) . toEqual ( wireNames ) ;
68+ const hint = cursorNativeExecRedirectHint ( tools , [ ] , "claude-sonnet-5-5" ) ! ;
69+ expect ( hint . match ( / A v a i l a b l e t o o l s i n t h i s r e q u e s t ' s c a t a l o g : ( .* ?) \. / ) ?. [ 1 ] )
70+ . toBe ( wireNames . map ( name => `\`${ name } \`` ) . join ( ", " ) ) ;
71+ const guidance = buildCursorToolGuidanceSystemNote ( tools , undefined , "claude-sonnet-5-5" ) ! ;
72+ for ( const name of wireNames ) expect ( guidance ) . toContain ( `\`${ name } \`` ) ;
73+ } ) ;
74+ test . each ( CLAUDE_CLIENT_CATALOGS ) ( "Claude live transport prepares the request catalog: %j" , async ( { names, wireNames } ) => {
75+ const transport = createLiveCursorTransport ( { provider : { adapter : "cursor" , baseUrl : "https://api2.cursor.sh" , apiKey : "fixture-token" } ,
76+ translatorBudget : createTestTranslatorBudget ( ) , headers : new Headers ( ) } ) ;
77+ const internal = transport as unknown as { open ( bytes : Uint8Array ) : void ; execContext : CursorNativeExecContext } ;
78+ let preparedBytes : Uint8Array | undefined ;
79+ internal . open = bytes => { preparedBytes = bytes ; throw new Error ( "catalog fixture stops before network" ) ; } ;
80+ try {
81+ const request : CursorRunRequest = { modelId : "claude-sonnet-5-5" , conversationId : "catalog-fixture" , system : [ ] ,
82+ messages : [ { role : "user" , content : "Inspect the project." } ] ,
83+ tools : names . map ( name => ( { name, description : "Fixture tool" , parameters : { } } ) ) } ;
84+ await expect ( transport . run ( request ) [ Symbol . asyncIterator ] ( ) . next ( ) ) . rejects . toThrow ( "catalog fixture stops before network" ) ;
85+ expect ( preparedBytes ) . toBeDefined ( ) ;
86+ const decoded = fromBinary ( AgentClientMessageSchema , preparedBytes ! ) ;
87+ if ( decoded . message . case !== "runRequest" ) throw new Error ( "Expected runRequest" ) ;
88+ expect ( decoded . message . value . mcpTools ?. mcpTools . map ( tool => tool . name ) ) . toEqual ( wireNames ) ;
89+ expect ( internal . execContext . clientToolDefs ?. map ( tool => tool . name ) ) . toEqual ( wireNames ) ;
90+ expect ( internal . execContext . nativeExecRedirectHint ?. match ( / A v a i l a b l e t o o l s i n t h i s r e q u e s t ' s c a t a l o g : ( .* ?) \. / ) ?. [ 1 ] )
91+ . toBe ( wireNames . map ( name => `\`${ name } \`` ) . join ( ", " ) ) ;
92+ expect ( internal . execContext . plainToolWording ) . toBe ( true ) ;
93+ } finally { await transport . close ?.( ) ; }
94+ } ) ;
5895 test . each ( CLAUDE_MODELS ) ( "recognizes Claude target %s" , modelId => {
5996 expect ( cursorUsesPlainToolWording ( modelId ) ) . toBe ( true ) ;
6097 } ) ;
0 commit comments