Skip to content

Commit bd9f376

Browse files
committed
Fixes duplication issues: Added events based cache invalidation and rm mcp debug comments
1 parent 211c35c commit bd9f376

26 files changed

+365
-167
lines changed

libs/remix-ai-core/src/agents/codeExplainAgent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export class CodeExplainAgent {
2929
return content
3030
} else return prompt
3131
} catch {
32-
console.log('There is No file selected')
3332
return 'There is No file selected'
3433
}
3534
}

libs/remix-ai-core/src/agents/contractAgent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export class ContractAgent {
3636
async writeContracts(payload, userPrompt, statusCallback?: (status: string) => Promise<void>) {
3737
const prev_statusCallback = statusCallback
3838
statusCallback = async (status: string) => {
39-
console.log('Generation status:', status)
4039
if (prev_statusCallback) {
4140
await prev_statusCallback(status)
4241
}

libs/remix-ai-core/src/agents/securityAgent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export class SecurityAgent {
123123

124124
try {
125125
this.processFile(file);
126-
console.log('Checking for vulnerabilities after compilation', this.reports);
127126
} catch (error) {
128127
console.error('Error checking for vulnerabilities after compilation: ', error);
129128
}

libs/remix-ai-core/src/helpers/chatCommandParser.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export class ChatCommandParser {
4747
if (handler) {
4848
return handler(rawArgs, this, statusCallback);
4949
} else {
50-
console.log(`Unknown command: ${commandName}`);
5150
return "";
5251
}
5352
}

libs/remix-ai-core/src/helpers/compile.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ export const compilecontracts = async (contracts, plugin): Promise<CompilationRe
1111
// do not compile tests files
1212
let result
1313
try {
14-
// console.log('Compiling contracts:', contracts)
1514
result = await plugin.call('solidity' as any, 'compileWithParameters', contracts, compilationParams)
1615
const data = result.data
1716
let error = false
1817

1918
if (data.errors) {
20-
// console.log('Compilation errors:', data.errors)
2119
error = data.errors.find((error) => error.type !== 'Warning')
2220
}
2321

libs/remix-ai-core/src/inferencers/mcp/codeExecutor.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ export class CodeExecutor {
5757

5858
// CRITICAL: race condition - Wait for all pending tool calls to complete before returning
5959
if (this.pendingToolCalls.length > 0) {
60-
console.log(`[MCP Code mode] - Waiting for ${this.pendingToolCalls.length} pending tool call(s) to complete...`);
6160
await Promise.allSettled(this.pendingToolCalls);
62-
console.log(`[MCP Code mode] - All tool calls completed`);
6361
}
6462

6563
const executionTime = Date.now() - startTime;

libs/remix-ai-core/src/inferencers/mcp/mcpClient.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ export class MCPClient {
183183
let initialized = false;
184184

185185
this.wsConnection.onopen = () => {
186-
console.log(`[MCP] WebSocket connection opened to ${this.server.name}`);
187186

188187
// Send initialize message
189188
const initMessage = {
@@ -395,7 +394,6 @@ export class MCPClient {
395394
// Check cache for HTTP servers
396395
const now = Date.now();
397396
if (this.resourceListCache && (now - this.resourceListCache.timestamp) < this.CACHE_TTL) {
398-
console.log(`[MCP] Using cached resource list for ${this.server.name}`);
399397
return this.resourceListCache.resources;
400398
}
401399

libs/remix-ai-core/src/inferencers/mcp/mcpInferencer.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ export class MCPInferencer extends RemoteInferencer implements ICompletions, IGe
405405
const mcpToolCall = this.convertLLMToolCallToMCP(llmToolCall);
406406
const result = await this.executeToolForLLM(mcpToolCall, uiCallback);
407407
console.log(`[MCP] Tool ${mcpToolCall.name} executed successfully`);
408-
console.log("[MCP] Tool result", result);
409408

410409
// Extract full text content from MCP result
411410
const extractContent = (mcpResult: any): string => {
@@ -712,8 +711,6 @@ export class MCPInferencer extends RemoteInferencer implements ICompletions, IGe
712711

713712
async getToolsForLLMRequest(provider?: string, prompt?: string): Promise<any[]> {
714713
const mcpTools = await this.getAvailableToolsForLLM();
715-
console.log('[MCPInferencer] Total available tools:', mcpTools.length)
716-
717714
if (mcpTools.length === 0) return [];
718715

719716
// Use keyword-based tool selection if prompt provided and more than 15 tools
@@ -731,7 +728,6 @@ export class MCPInferencer extends RemoteInferencer implements ICompletions, IGe
731728
});
732729

733730
console.log(`[MCPInferencer] Tool selection: ${mcpTools.length}${selectedTools.length} tools (${Math.round((1 - selectedTools.length / mcpTools.length) * 100)}% reduction)`)
734-
console.log('[MCPInferencer] Selected tools:', selectedTools.map(t => t.name).join(', '))
735731
} catch (error) {
736732
console.warn('[MCPInferencer] Tool selection failed, using all tools:', error)
737733
selectedTools = mcpTools
@@ -953,7 +949,6 @@ ${toolsList}`,
953949
if (!targetServer) {
954950
throw new Error(`Tool '${toolCall.name}' not found in any connected MCP server`);
955951
}
956-
console.log(`[MCP Legacy Mode] Executing tool ${toolCall.name} from server ${targetServer}`)
957952
return this.executeTool(targetServer, toolCall);
958953
}
959954

libs/remix-ai-core/src/inferencers/remote/remoteInference.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ export class RemoteInferencer implements ICompletions, IGeneration {
131131
if (done) break;
132132

133133
try {
134-
console.log("value" + decoder.decode(value))
135134
const chunk = parser.safeJsonParse<{ generatedText: string; isGenerating: boolean }>(decoder.decode(value, { stream: true }));
136135
for (const parsedData of chunk) {
137136
if (parsedData.isGenerating) {

libs/remix-ai-core/src/remix-mcp-server/RemixMCPServer.ts

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,6 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
181181

182182
try {
183183
await this._configManager.loadConfig();
184-
const securityConfig = this._configManager.getSecurityConfig();
185-
const validationConfig = this._configManager.getValidationConfig();
186-
console.log('[RemixMCPServer] Middlewares connected:');
187-
console.log(` - SecurityMiddleware: using ${securityConfig.excludeTools?.length || 0} excluded tools`);
188-
console.log(` - ValidationMiddleware: strictMode=${validationConfig.strictMode}, ${Object.keys(validationConfig.toolValidation || {}).length} tool-specific rules`);
189-
190184
} catch (error) {
191185
console.log(`[RemixMCPServer] Failed to load MCP config: ${error.message}, using defaults`);
192186
}
@@ -331,17 +325,21 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
331325

332326
// Get current user (default to 'default' role)
333327
const currentUser = 'default'; // Can be extended to get from plugin context
334-
console.log("checking permissions")
335328
const permissionCheckResult = await this.checkPermissions(call.name, currentUser);
336-
console.log("permissions checked", permissionCheckResult)
329+
330+
const timestamp = Date.now();
331+
const [workspace, currentFile] = await Promise.all([
332+
this.getCurrentWorkspace(),
333+
this.getCurrentFile()
334+
]);
337335

338336
const execution: ToolExecutionStatus = {
339337
id: executionId,
340338
toolName: call.name,
341339
startTime,
342340
status: 'running',
343341
context: {
344-
workspace: await this.getCurrentWorkspace(),
342+
workspace,
345343
user: currentUser,
346344
permissions: permissionCheckResult.userPermissions
347345
}
@@ -352,28 +350,22 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
352350

353351
try {
354352
const context = {
355-
workspace: execution.context.workspace,
356-
currentFile: await this.getCurrentFile(),
353+
workspace,
354+
currentFile,
357355
permissions: permissionCheckResult.userPermissions,
358-
timestamp: Date.now(),
356+
timestamp,
359357
requestId: executionId
360358
};
361359

362-
// STEP 1: Security Validation (uses MCPConfigManager for dynamic config)
363-
console.log(`[RemixMCPServer] Step 1: Security validation for tool '${call.name}' (using MCPConfigManager)`);
364360
const securityResult = await this._securityMiddleware.validateToolCall(call, context, this._plugin);
365361

366362
if (!securityResult.allowed) {
367363
console.log(`[RemixMCPServer] Security validation FAILED for tool '${call.name}': ${securityResult.reason}`);
368364
throw new Error(`Security validation failed: ${securityResult.reason}`);
369365
}
370-
console.log(`[RemixMCPServer] Security validation PASSED for tool '${call.name}'`);
371366

372-
// STEP 2: Input Validation (uses MCPConfigManager for dynamic config)
373-
console.log(`[RemixMCPServer] Step 2: Input validation for tool '${call.name}' (using MCPConfigManager)`);
374367
const toolDefinition = this._tools.get(call.name);
375368
const inputSchema = toolDefinition?.inputSchema;
376-
377369
const validationResult = await this._validationMiddleware.validateToolCall(
378370
call,
379371
inputSchema,
@@ -391,14 +383,12 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
391383
if (validationResult.warnings.length > 0) {
392384
const warnings = validationResult.warnings.map(w => w.message).join(', ');
393385
console.log(`[RemixMCPServer] Input validation warnings for tool '${call.name}': ${warnings}`);
394-
} else {
395-
console.log(`[RemixMCPServer] Input validation PASSED for tool '${call.name}'`);
396386
}
397387

398-
// STEP 3: File Write Permission Check (for file_write and file_create tools)
399-
if (call.name === 'file_write' || call.name === 'file_create') {
400-
console.log(`[RemixMCPServer] Step 3: File write permission check for tool '${call.name}'`);
401-
const filePath = call.arguments?.path || call.arguments?.filePath;
388+
// STEP 3: File Permision Check (for file operations)
389+
const fileOperations = ['file_write', 'file_create', 'file_delete', 'file_move', 'file_copy'];
390+
if (fileOperations.includes(call.name)) {
391+
const filePath = call.arguments?.path || call.arguments?.filePath || call.arguments?.from || call.arguments?.source;
402392

403393
if (filePath) {
404394
const permissionResult = await this._filePermissionMiddleware.checkFileWritePermission(
@@ -407,10 +397,10 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
407397
);
408398

409399
if (!permissionResult.allowed) {
410-
console.log(`[RemixMCPServer] File write permission DENIED for '${filePath}': ${permissionResult.reason}`);
411-
throw new Error(`File write permission denied: ${permissionResult.reason || 'User denied the operation'}`);
400+
console.log(`[RemixMCPServer] File operation permission DENIED for '${filePath}': ${permissionResult.reason}`);
401+
throw new Error(`File operation permission denied: ${permissionResult.reason || 'User denied the operation'}`);
412402
}
413-
console.log(`[RemixMCPServer] File write permission GRANTED for '${filePath}'`);
403+
console.log(`[RemixMCPServer] File operation permission GRANTED for '${filePath}'`);
414404
}
415405
}
416406

@@ -429,7 +419,6 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
429419
this._stats.totalToolCalls++;
430420

431421
trackMatomoEvent('ai', 'remixAI', `mcp_tool_executed_${call.name}`);
432-
console.log(`[RemixMCPServer] Tool '${call.name}' executed successfully`);
433422
this.emit('tool-executed', execution);
434423
return result;
435424

@@ -491,8 +480,6 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
491480
async checkPermissions(operation: string, user: string, resource?: string): Promise<PermissionCheckResult> {
492481
try {
493482
const securityConfig = this._configManager.getSecurityConfig();
494-
console.log("securityConfig", securityConfig)
495-
// If permissions
496483

497484
if (!securityConfig.permissions.requirePermissions) {
498485
return {
@@ -504,9 +491,7 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
504491
}
505492

506493
const userPermissions = this.getUserPermissions(user, securityConfig);
507-
console.log("userPermissions", userPermissions)
508494
const requiredPermissions = this.getOperationPermissions(operation);
509-
console.log("requiredPermissions", requiredPermissions)
510495

511496
if (userPermissions.includes('*')) {
512497
return {
@@ -555,7 +540,6 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
555540
// Additional resource-specific checks
556541
if (resource) {
557542
const resourceCheck = this.checkResourcePermissions(resource, userPermissions, securityConfig);
558-
console.log("Resource check:", resourceCheck)
559543
if (!resourceCheck.allowed) {
560544
// Log denied resource access
561545
this.logAuditEntry({
@@ -647,7 +631,6 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
647631
}
648632

649633
private getUserPermissions(user: string, securityConfig: any): string[] {
650-
console.log('security config', securityConfig)
651634
const permissions: string[] = [];
652635

653636
if (securityConfig.permissions?.defaultPermissions) {
@@ -701,10 +684,14 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
701684
// Analysis
702685
'analyze_code': ['analysis:static'],
703686
'security_scan': ['analysis:security'],
704-
'estimate_gas': ['analysis:gas']
687+
'estimate_gas': ['analysis:gas'],
688+
689+
// Additional tools
690+
'run_script': ['transaction:send'],
691+
'simulate_transaction': ['transaction:simulate']
705692
};
706693

707-
return defaultPermissionMap[operation] || ['*'];
694+
return defaultPermissionMap[operation] || [`tool:${operation}`];
708695
}
709696

710697
private checkResourcePermissions(resource: string, userPermissions: string[], securityConfig: any): { allowed: boolean; reason?: string } {
@@ -779,10 +766,7 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
779766
*/
780767
async reloadConfig(): Promise<void> {
781768
try {
782-
console.log('[RemixMCPServer] Reloading MCP configuration...');
783769
const mcpConfig = await this._configManager.reloadConfig();
784-
console.log('[RemixMCPServer] Configuration reloaded successfully');
785-
console.log('[RemixMCPServer] Configuration summary:', this._configManager.getConfigSummary());
786770
this.emit('config-reloaded', mcpConfig);
787771
} catch (error) {
788772
console.log(`[RemixMCPServer] Failed to reload config: ${error.message}`);
@@ -796,7 +780,6 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
796780

797781
updateMCPConfig(partialConfig: Partial<any>): void {
798782
this._configManager.updateConfig(partialConfig);
799-
console.log('[RemixMCPServer] Configuration updated at runtime');
800783
this.emit('config-updated', this._configManager.getConfig());
801784
}
802785

@@ -894,19 +877,13 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
894877
this._resources.register(compilationProvider);
895878

896879
// Register deployment resource provider
897-
const deploymentProvider = new DeploymentResourceProvider();
880+
const deploymentProvider = new DeploymentResourceProvider(this._plugin);
898881
this._resources.register(deploymentProvider);
899882

900883
// Register tutorial resource provider
901884
const tutorialsProvider = new TutorialsResourceProvider(this._plugin);
902885
this._resources.register(tutorialsProvider);
903886

904-
// Register Amp resource provider
905-
/*
906-
const ampProvider = new AmpResourceProvider(this._plugin);
907-
this._resources.register(ampProvider);
908-
*/
909-
910887
// Register debugging resource provider
911888
const debuggingProvider = new DebuggingResourceProvider(this._plugin);
912889
this._resources.register(debuggingProvider);

0 commit comments

Comments
 (0)