11// Reconnecting pattern matching for improved NLP accuracy
2- import { matchRequest , extractParameters } from "../matching-service/index.js" ;
2+ import { matchRequest } from "../matching-service/index.js" ;
33import { MatchResult } from "../../types/tools.js" ;
44import { processWithSequentialThinking } from "../../tools/sequential-thinking.js" ;
55import { OpenRouterConfig } from "../../types/workflow.js" ;
@@ -14,7 +14,7 @@ const __filename = fileURLToPath(import.meta.url);
1414const __dirname = path . dirname ( __filename ) ;
1515
1616// Confidence thresholds
17- const HIGH_CONFIDENCE = 0.8 ;
17+ // const HIGH_CONFIDENCE = 0.8; // Currently unused but may be needed for future confidence checks
1818// const MEDIUM_CONFIDENCE = 0.6; // Removed unused variable
1919// const LOW_CONFIDENCE = 0.4; // Removed unused variable
2020
@@ -25,7 +25,7 @@ let toolDescriptionsCache: Record<string, string> | null = null;
2525 * Hybrid matching result with additional metadata
2626 */
2727export interface EnhancedMatchResult extends MatchResult {
28- parameters : Record < string , string > ;
28+ parameters : Record < string , unknown > ;
2929 matchMethod : "rule" | "intent" | "semantic" | "sequential" ; // Added "semantic"
3030 requiresConfirmation : boolean ;
3131}
@@ -44,9 +44,14 @@ function loadToolDescriptions(): Record<string, string> {
4444 const configContent = readFileSync ( configPath , 'utf-8' ) ;
4545 const config = JSON . parse ( configContent ) ;
4646
47+ interface ToolConfig {
48+ description ?: string ;
49+ [ key : string ] : unknown ;
50+ }
51+
4752 const descriptions : Record < string , string > = { } ;
4853 for ( const [ name , tool ] of Object . entries ( config . tools ) ) {
49- const toolData = tool as any ;
54+ const toolData = tool as ToolConfig ;
5055 descriptions [ name ] = toolData . description || '' ;
5156 }
5257
@@ -267,7 +272,8 @@ function combineResults(
267272 }
268273
269274 // Extract parameters based on the tool
270- let parameters : Record < string , any > = { } ;
275+ // Using 'unknown' for parameters as they vary by tool and will be validated by each tool's schema
276+ let parameters : Record < string , unknown > = { } ;
271277
272278 // For research-manager: requires 'query'
273279 if ( bestTool === 'research-manager' ) {
@@ -343,7 +349,7 @@ function combineResults(
343349 parameters = {
344350 productDescription,
345351 userStories : '' , // Optional
346- ruleCategories : [ ] // Optional array
352+ ruleCategories : [ ] as string [ ] // Optional array
347353 } ;
348354 }
349355 // For context curator: requires 'prompt' or 'task_type'
@@ -357,9 +363,21 @@ function combineResults(
357363 prompt = request ;
358364 }
359365
366+ // Detect task type based on keywords in the request
367+ let task_type : string = 'auto_detect' ; // Default to auto_detect
368+ if ( request . match ( / \b ( b u g | f i x | e r r o r | i s s u e | p r o b l e m ) \b / i) ) {
369+ task_type = 'bug_fix' ;
370+ } else if ( request . match ( / \b ( r e f a c t o r | c l e a n | i m p r o v e | r e s t r u c t u r e ) \b / i) ) {
371+ task_type = 'refactoring' ;
372+ } else if ( request . match ( / \b ( p e r f o r m a n c e | o p t i m i z e | s p e e d | f a s t e r ) \b / i) ) {
373+ task_type = 'performance_optimization' ;
374+ } else if ( request . match ( / \b ( f e a t u r e | a d d | i m p l e m e n t | c r e a t e | n e w ) \b / i) ) {
375+ task_type = 'feature_addition' ;
376+ }
377+
360378 parameters = {
361379 prompt,
362- task_type : 'general' // Default task type
380+ task_type
363381 } ;
364382 }
365383 // For fullstack starter kit generator: requires 'use_case'
@@ -378,7 +396,7 @@ function combineResults(
378396 // For map-codebase: optional 'directory' parameter
379397 else if ( bestTool === 'map-codebase' ) {
380398 // Check if a specific directory is mentioned
381- const dirMatch = request . match ( / (?: f o r | i n | o f | a t ) \s + ( [ \/ \ w\- \. ] + ) / i) ;
399+ const dirMatch = request . match ( / (?: f o r | i n | o f | a t ) \s + ( [ \w \- . / ] + ) / i) ;
382400 if ( dirMatch ) {
383401 parameters = { directory : dirMatch [ 1 ] } ;
384402 } else {
@@ -405,7 +423,7 @@ function combineResults(
405423 if ( workflowMatch ) {
406424 parameters = {
407425 workflowName : workflowMatch [ 1 ] ,
408- workflowInput : { } // Empty object as default
426+ workflowInput : { } as Record < string , unknown > // Empty object as default
409427 } ;
410428 } else {
411429 // If no specific workflow mentioned, look for "run workflow" pattern
@@ -415,13 +433,13 @@ function combineResults(
415433 const nameMatch = request . match ( / \b ( [ a - z A - Z 0 - 9 - _ ] + ) \b / ) ;
416434 parameters = {
417435 workflowName : nameMatch ? nameMatch [ 1 ] : 'default' ,
418- workflowInput : { }
436+ workflowInput : { } as Record < string , unknown >
419437 } ;
420438 } else {
421439 // Fallback - use the full request
422440 parameters = {
423441 workflowName : 'default' ,
424- workflowInput : { request }
442+ workflowInput : { request } as Record < string , unknown >
425443 } ;
426444 }
427445 }
0 commit comments