iter(g154): MCP 搜索补组件级命中

原 search_components 只搜包级字段,命中后返回包,Agent 还得再猜组件 id。
改为返回 { packages, components } 两级,组件按 id / 标题 / props 名命中并带 package。
This commit is contained in:
HIsheR
2026-10-26 15:54:05 +08:00
parent c423d9cb2d
commit ab758ab9fc
2 changed files with 19 additions and 3 deletions
+8
View File
@@ -1588,6 +1588,14 @@
"acceptance": "ua search a b 取各词命中的最弱档做 AND 过滤仍保持 id>标题>props>步骤 的排序;未命中输出相近建议并 exit 1;无参数打印用法。", "acceptance": "ua search a b 取各词命中的最弱档做 AND 过滤仍保持 id>标题>props>步骤 的排序;未命中输出相近建议并 exit 1;无参数打印用法。",
"notes": "", "notes": "",
"status": "done" "status": "done"
},
{
"id": "g154",
"title": "MCP search_components 补组件级命中",
"motivation": "原实现只在包级字段(name/description/tags/api.exports)里搜,命中后只返回包:Agent 搜「日期」得到 @ui-arch/ui,还得再猜组件 id。",
"acceptance": "返回 { packages, components } 两级结构,components 按 id/标题/props 名命中并带 package 字段;空 query 与无命中都抛明确错误;工具描述同步。",
"notes": "",
"status": "open"
} }
] ]
} }
+11 -3
View File
@@ -566,7 +566,7 @@ function cmdMcp() {
}, },
{ {
name: 'search_components', name: 'search_components',
description: 'Search packages by keyword across name/description/tags/api', description: 'Search by keyword: returns matched packages plus matched components (id/title/props)',
inputSchema: { inputSchema: {
type: 'object', type: 'object',
properties: { query: { type: 'string' } }, properties: { query: { type: 'string' } },
@@ -619,8 +619,9 @@ function cmdMcp() {
return { package: hit.pkg.name, ...hit.comp, recipes: recipesFor(hit.comp.id) }; return { package: hit.pkg.name, ...hit.comp, recipes: recipesFor(hit.comp.id) };
} }
if (name === 'search_components') { if (name === 'search_components') {
const q = String(args.query ?? '').toLowerCase(); const q = String(args.query ?? '').toLowerCase().trim();
return packages if (!q) throw new Error('query 不能为空');
const pkgs = packages
.filter((p) => .filter((p) =>
[p.name, p.description, p.type, ...(p.tags ?? []), ...(p.api?.exports ?? [])] [p.name, p.description, p.type, ...(p.tags ?? []), ...(p.api?.exports ?? [])]
.join(' ') .join(' ')
@@ -628,6 +629,13 @@ function cmdMcp() {
.includes(q), .includes(q),
) )
.map((p) => ({ name: p.name, version: p.version, type: p.type, description: p.description })); .map((p) => ({ name: p.name, version: p.version, type: p.type, description: p.description }));
const comps = collectComponents(packages) // 组件级命中:包级 exports 只给出包名,Agent 还得再查一次
.filter(({ comp }) =>
[comp.id, comp.title, ...(comp.props ?? []).map((p) => p.n)].join(' ').toLowerCase().includes(q),
)
.map(({ pkg, comp }) => ({ package: pkg.name, id: comp.id, title: comp.title }));
if (!pkgs.length && !comps.length) throw new Error(`no match: ${args.query}`);
return { packages: pkgs, components: comps };
} }
if (name === 'get_tokens') { if (name === 'get_tokens') {
const list = loadTokenList(); const list = loadTokenList();