6
6
from pathlib import Path
7
7
from typing import Annotated , Any , Dict , List , Optional
8
8
9
- import requests
10
9
from graph_sitter import Codebase
11
- from graph_sitter .cli .api .client import RestAPI
12
- from graph_sitter .cli .api .endpoints import CODEGEN_SYSTEM_PROMPT_URL
13
- from graph_sitter .cli .auth .token_manager import get_current_token
14
- from graph_sitter .cli .codemod .convert import convert_to_cli
15
10
from graph_sitter .cli .utils .default_code import DEFAULT_CODEMOD
16
11
from graph_sitter .extensions .tools .reveal_symbol import reveal_symbol
17
12
from mcp .server .fastmcp import FastMCP
@@ -99,7 +94,7 @@ async def wrapper(*args, **kwargs):
99
94
# return {"message": f"Codebase is parsed. Found {len(state.parsed_codebase.files)} files.", "status": "parsed"}
100
95
101
96
102
- async def create_codemod_task (name : str , description : str , language : str = "python" ) -> Dict [str , Any ]:
97
+ async def create_codemod_task (name : str , language : str = "python" ) -> Dict [str , Any ]:
103
98
"""Background task to create a codemod using the API."""
104
99
try :
105
100
# Convert name to snake case for filename
@@ -116,37 +111,12 @@ async def create_codemod_task(name: str, description: str, language: str = "pyth
116
111
function_dir .mkdir (parents = True , exist_ok = True )
117
112
logger .info (f"Created directories for codemod { name } in { function_dir } " )
118
113
119
- # Use API to generate implementation if description is provided
120
- if description :
121
- try :
122
- api = RestAPI (get_current_token ())
123
- response = api .create (name = name , query = description )
124
- code = convert_to_cli (response .code , language , name )
125
- context = response .context
126
-
127
- # Save the prompt/context
128
- if context :
129
- prompt_path .write_text (context )
130
- except Exception as e :
131
- # Fall back to default implementation on API error
132
- code = DEFAULT_CODEMOD .format (name = name )
133
- return {"status" : "error" , "message" : f"Error generating codemod via API, using default template: { str (e )} " , "path" : str (codemod_path ), "code" : code }
134
- else :
135
- # Use default implementation
136
- code = DEFAULT_CODEMOD .format (name = name )
114
+ # Use default implementation
115
+ code = DEFAULT_CODEMOD .format (name = name )
137
116
138
117
# Write the codemod file
139
118
codemod_path .write_text (code )
140
119
141
- # Download and save system prompt if not already done
142
- if not prompt_path .exists ():
143
- try :
144
- response = requests .get (CODEGEN_SYSTEM_PROMPT_URL )
145
- response .raise_for_status ()
146
- prompt_path .write_text (response .text )
147
- except Exception :
148
- pass # Ignore system prompt download failures
149
-
150
120
return {"status" : "completed" , "message" : f"Created codemod '{ name } '" , "path" : str (codemod_path ), "docs_path" : str (prompt_path ), "code" : code }
151
121
except Exception as e :
152
122
return {"status" : "error" , "message" : f"Error creating codemod: { str (e )} " }
@@ -268,7 +238,6 @@ def get_config() -> str:
268
238
@mcp .tool (name = "create_codemod" , description = "Initiate creation of a new codemod in the `.codegen/codemods/{name}` directory" )
269
239
async def create_codemod (
270
240
name : Annotated [str , "Name of the codemod to create" ],
271
- description : Annotated [str , "Description of what the codemod does. Be specific, as this is passed to an expert LLM to generate the first draft" ] = None ,
272
241
language : Annotated [str , "Programming language for the codemod (default Python)" ] = "python" ,
273
242
) -> Dict [str , Any ]:
274
243
# Check if a task with this name already exists
@@ -291,13 +260,13 @@ def sync_wrapper():
291
260
new_loop = asyncio .new_event_loop ()
292
261
asyncio .set_event_loop (new_loop )
293
262
# Run our async function to completion in this thread
294
- return new_loop .run_until_complete (create_codemod_task (name , description , language ))
263
+ return new_loop .run_until_complete (create_codemod_task (name , language ))
295
264
296
265
# Run the wrapper in a thread pool
297
266
task = loop .run_in_executor (None , sync_wrapper )
298
267
299
268
# Store task info
300
- state .codemod_tasks [name ] = {"task" : task , "name" : name , "description" : description , " language" : language , "started_at" : loop .time ()}
269
+ state .codemod_tasks [name ] = {"task" : task , "name" : name , "language" : language , "started_at" : loop .time ()}
301
270
302
271
# Return immediately
303
272
return {
0 commit comments