magector 2.6.3 → 2.6.5

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 +26 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magector",
3
- "version": "2.6.3",
3
+ "version": "2.6.5",
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.5",
37
+ "@magector/cli-linux-x64": "2.6.5",
38
+ "@magector/cli-linux-arm64": "2.6.5",
39
+ "@magector/cli-win32-x64": "2.6.5"
40
40
  },
41
41
  "keywords": [
42
42
  "magento",
package/src/mcp-server.js CHANGED
@@ -2283,6 +2283,7 @@ async function analyzeImpact(className) {
2283
2283
 
2284
2284
  // Filesystem fallback: if vector search found too few files, find the class file via glob
2285
2285
  if (relatedPaths.length < 5 && root) {
2286
+ logToFile('INFO', `impact_analysis: vector search returned ${relatedPaths.length} files for "${className}" — using filesystem fallback`);
2286
2287
  try {
2287
2288
  const classFiles = await glob(`**/${shortName}.php`, { cwd: root, absolute: false, nodir: true });
2288
2289
  const existingPaths = new Set(relatedPaths.map(r => r.path));
@@ -4097,6 +4098,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
4097
4098
  if (results.length === 0 && config.magentoRoot) {
4098
4099
  const shortName = args.className.split('\\').pop();
4099
4100
  const globPattern = `**/${shortName}.php`;
4101
+ logToFile('INFO', `find_class: vector search returned 0 results for "${args.className}" — using filesystem fallback (glob ${globPattern})`);
4100
4102
  try {
4101
4103
  const files = await glob(globPattern, { cwd: config.magentoRoot, absolute: false, nodir: true, ignore: ['**/test/**', '**/tests/**', '**/Test/**'] });
4102
4104
  // Filter by namespace if provided
@@ -4128,6 +4130,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
4128
4130
  results.push({ path: filePath, className, score: 0.5 });
4129
4131
  }
4130
4132
  }
4133
+ if (results.length > 0) logToFile('INFO', `find_class: filesystem fallback found ${results.length} files for "${args.className}"`);
4131
4134
  } catch {}
4132
4135
  }
4133
4136
 
@@ -4156,16 +4159,28 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
4156
4159
  );
4157
4160
  results = results.concat(pathFallback);
4158
4161
  }
4159
- // Filesystem fallback: grep for the method definition in PHP files
4162
+ // Filesystem fallback: use grep to find method definition across all PHP files
4160
4163
  if (results.length === 0 && config.magentoRoot) {
4164
+ logToFile('INFO', `find_method: vector search returned 0 results for "${args.methodName}" — using filesystem fallback (grep -rl)`);
4161
4165
  try {
4162
4166
  const methodSig = `function ${args.methodName}(`;
4163
- // Use className to narrow the glob if provided
4167
+ // Use className to narrow search if provided, otherwise grep all PHP
4164
4168
  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);
4169
+ let files = [];
4170
+ if (classShort) {
4171
+ files = await glob(`**/${classShort}.php`, { cwd: config.magentoRoot, absolute: false, nodir: true });
4172
+ } else {
4173
+ // Use grep -rl for fast search across all PHP files (much faster than reading each file)
4174
+ try {
4175
+ const grepResult = execFileSync('grep', ['-rl', '--include=*.php', methodSig, '.'],
4176
+ { cwd: config.magentoRoot, encoding: 'utf-8', timeout: 15000, stdio: ['pipe', 'pipe', 'pipe'] });
4177
+ files = grepResult.trim().split('\n').filter(Boolean).map(f => f.replace(/^\.\//, ''));
4178
+ } catch {
4179
+ // grep returns exit code 1 when no matches — fall through with empty files
4180
+ }
4181
+ }
4182
+ for (const f of files.slice(0, 20)) {
4183
+ const absPath = f.startsWith('/') ? f : path.join(config.magentoRoot, f);
4169
4184
  let content;
4170
4185
  try { content = readFileSync(absPath, 'utf-8'); } catch { continue; }
4171
4186
  if (!content.includes(methodSig)) continue;
@@ -4189,7 +4204,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
4189
4204
  });
4190
4205
  if (results.length >= 5) break;
4191
4206
  }
4192
- } catch {}
4207
+ if (results.length > 0) logToFile('INFO', `find_method: filesystem fallback found ${results.length} files containing "${args.methodName}"`);
4208
+ } catch (err) {
4209
+ logToFile('WARN', `find_method: filesystem fallback error: ${err.message}`);
4210
+ }
4193
4211
  }
4194
4212
  // Boost exact method matches to top
4195
4213
  results = results.map(r => {
@@ -4734,6 +4752,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
4734
4752
 
4735
4753
  // Filesystem fallback: if vector search found nothing, glob the module directory
4736
4754
  if (results.length === 0 && config.magentoRoot && vendorPath) {
4755
+ logToFile('INFO', `module_structure: vector search returned 0 results for "${args.moduleName}" — using filesystem fallback (glob ${vendorPath})`);
4737
4756
  try {
4738
4757
  const vendorGlob = `**/${vendorPath}**/*.{php,xml,phtml}`;
4739
4758
  const files = await glob(vendorGlob, { cwd: config.magentoRoot, absolute: false, nodir: true });