From ca36dd2312fbba985e0515e4e653bce6817a2eb2 Mon Sep 17 00:00:00 2001 From: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com> Date: Tue, 17 Nov 2026 03:44:44 -0800 Subject: [PATCH] fix: stop recommendation engine reading Intent Routing rows as agents parseCatalog accepted any table row with a kebab-case first cell, so the Intent Routing table in CATALOG.md (harden, document, skip-frontend, skip-backend, security-only) was parsed as five extra agents and could be recommended. Only accept rows whose File column is agents/.md. --- scripts/recommendation-engine.js | 2 ++ tests/recommendation-engine.test.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/recommendation-engine.js b/scripts/recommendation-engine.js index c78b8ba..d2d245d 100644 --- a/scripts/recommendation-engine.js +++ b/scripts/recommendation-engine.js @@ -118,6 +118,8 @@ function parseCatalog() { if (cols.length < 4) continue; const id = cols[0]; if (!/^[a-z0-9-]+$/.test(id)) continue; + // Only Agent Catalog rows point at an agent file; skip other tables (e.g. Intent Routing). + if (!/^agents\/[a-z0-9-]+\.md$/.test(cols[1].replace(/`/g, ''))) continue; const specialty = cols[2].toLowerCase(); const taskTypes = cols[3] diff --git a/tests/recommendation-engine.test.js b/tests/recommendation-engine.test.js index c34cb80..15b1c06 100644 --- a/tests/recommendation-engine.test.js +++ b/tests/recommendation-engine.test.js @@ -6,7 +6,7 @@ const fs = require('fs'); const path = require('path'); const ROOT = path.resolve(__dirname, '..'); -const { recommendAgents, parseAgentMetadata, metadataScore, archetypeBoost, detectTaskType, classifyConfidence } = require(path.join(ROOT, 'scripts', 'recommendation-engine.js')); +const { recommendAgents, parseCatalog, parseAgentMetadata, metadataScore, archetypeBoost, detectTaskType, classifyConfidence } = require(path.join(ROOT, 'scripts', 'recommendation-engine.js')); const cases = JSON.parse( fs.readFileSync(path.join(ROOT, 'tests', 'fixtures', 'recommendation', 'cases.json'), 'utf8') @@ -331,3 +331,12 @@ test('recommendAgents handles non-numeric memoryScores gracefully', () => { assert.ok(Number.isFinite(topRec.totalScore), 'totalScore should be finite, not NaN'); assert.equal(topRec.memoryBoost, 0, 'non-numeric memoryScore should be treated as 0'); }); + +test('parseCatalog returns only agents that have an agents/*.md file', () => { + const agentFiles = fs.readdirSync(path.join(ROOT, 'agents')).filter((f) => f.endsWith('.md')); + const ids = parseCatalog().map((a) => a.id); + assert.deepEqual([...ids].sort(), agentFiles.map((f) => f.replace(/\.md$/, '')).sort()); + + const recs = recommendAgents({ prompt: 'harden api security audit', topN: 10 }).recommendations; + assert.ok(!recs.some((r) => r.id === 'harden'), 'intent rows must not be recommended as agents'); +});