| 124 | * detectCodeIndexingFromCommand('ls -la') // returns undefined |
| 125 | */ |
| 126 | export function detectCodeIndexingFromCommand( |
| 127 | command: string, |
| 128 | ): CodeIndexingTool | undefined { |
| 129 | // Extract the first word (command name) |
| 130 | const trimmed = command.trim() |
| 131 | const firstWord = trimmed.split(/\s+/)[0]?.toLowerCase() |
| 132 | |
| 133 | if (!firstWord) { |
| 134 | return undefined |
| 135 | } |
| 136 | |
| 137 | // Check for npx/bunx prefixed commands |
| 138 | if (firstWord === 'npx' || firstWord === 'bunx') { |
| 139 | const secondWord = trimmed.split(/\s+/)[1]?.toLowerCase() |
| 140 | if (secondWord && secondWord in CLI_COMMAND_MAPPING) { |
| 141 | return CLI_COMMAND_MAPPING[secondWord] |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | return CLI_COMMAND_MAPPING[firstWord] |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Detects if an MCP tool is from a code indexing server. |