magector 2.6.3 → 2.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/mcp-server.js +17 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magector",
3
- "version": "2.6.3",
3
+ "version": "2.6.4",
4
4
  "description": "Semantic code search for Magento 2 — index, search, MCP server",
5
5
  "type": "module",
6
6
  "main": "src/mcp-server.js",
@@ -33,10 +33,10 @@
33
33
  "ruvector": "^0.1.96"
34
34
  },
35
35
  "optionalDependencies": {
36
- "@magector/cli-darwin-arm64": "2.6.3",
37
- "@magector/cli-linux-x64": "2.6.3",
38
- "@magector/cli-linux-arm64": "2.6.3",
39
- "@magector/cli-win32-x64": "2.6.3"
36
+ "@magector/cli-darwin-arm64": "2.6.4",
37
+ "@magector/cli-linux-x64": "2.6.4",
38
+ "@magector/cli-linux-arm64": "2.6.4",
39
+ "@magector/cli-win32-x64": "2.6.4"
40
40
  },
41
41
  "keywords": [
42
42
  "magento",
package/src/mcp-server.js CHANGED
@@ -4156,16 +4156,27 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
4156
4156
  );
4157
4157
  results = results.concat(pathFallback);
4158
4158
  }
4159
- // Filesystem fallback: grep for the method definition in PHP files
4159
+ // Filesystem fallback: use grep to find method definition across all PHP files
4160
4160
  if (results.length === 0 && config.magentoRoot) {
4161
4161
  try {
4162
4162
  const methodSig = `function ${args.methodName}(`;
4163
- // Use className to narrow the glob if provided
4163
+ // Use className to narrow search if provided, otherwise grep all PHP
4164
4164
  const classShort = args.className ? args.className.split('\\').pop() : null;
4165
- const globPattern = classShort ? `**/${classShort}.php` : '**/*.php';
4166
- const files = await glob(globPattern, { cwd: config.magentoRoot, absolute: false, nodir: true, ignore: ['**/test/**', '**/tests/**', '**/Test/**'] });
4167
- for (const f of files.slice(0, classShort ? 50 : 500)) {
4168
- const absPath = path.join(config.magentoRoot, f);
4165
+ let files = [];
4166
+ if (classShort) {
4167
+ files = await glob(`**/${classShort}.php`, { cwd: config.magentoRoot, absolute: false, nodir: true });
4168
+ } else {
4169
+ // Use grep -rl for fast search across all PHP files (much faster than reading each file)
4170
+ try {
4171
+ const grepResult = execFileSync('grep', ['-rl', '--include=*.php', methodSig, '.'],
4172
+ { cwd: config.magentoRoot, encoding: 'utf-8', timeout: 15000, stdio: ['pipe', 'pipe', 'pipe'] });
4173
+ files = grepResult.trim().split('\n').filter(Boolean).map(f => f.replace(/^\.\//, ''));
4174
+ } catch {
4175
+ // grep returns exit code 1 when no matches — fall through with empty files
4176
+ }
4177
+ }
4178
+ for (const f of files.slice(0, 20)) {
4179
+ const absPath = f.startsWith('/') ? f : path.join(config.magentoRoot, f);
4169
4180
  let content;
4170
4181
  try { content = readFileSync(absPath, 'utf-8'); } catch { continue; }
4171
4182
  if (!content.includes(methodSig)) continue;