feat(tool-search): expand dynamic group activation

This commit is contained in:
云服务部-叶林立
2026-08-28 12:05:11 +08:00
parent bf874455db
commit 2dcec0207c
15 changed files with 897 additions and 119 deletions
+25
View File
@@ -11,7 +11,9 @@ import {
parseGeneratedCatalog,
rankGroups,
readCachedCatalog,
selectConfidentGroup,
writeCachedCatalog,
type ToolCatalog,
} from "../extensions/catalog.ts";
function tool(name: string, description: string): ToolInfo {
@@ -62,6 +64,29 @@ test("validates exact generated assignments and ranks generated metadata", () =>
);
});
test("prefers exact tool names and refuses weak or ambiguous query activation", () => {
const catalog: ToolCatalog = {
version: 1,
manifestHash: "test",
generatedAt: new Date(0).toISOString(),
groups: [
{ id: "remote-files", title: "Remote files", summary: "Read remote files", useWhen: [], avoidWhen: [], tools: ["ssh_read"] },
{ id: "web-reader", title: "Web reader", summary: "Read web pages", useWhen: [], avoidWhen: [], tools: ["web_read"] },
],
tools: [
{ name: "ssh_read", summary: "Read a remote file", useWhen: [], avoidWhen: [], keywords: ["SSH"], primaryGroup: "remote-files" },
{ name: "web_read", summary: "Read a web page", useWhen: [], avoidWhen: [], keywords: ["web"], primaryGroup: "web-reader" },
],
};
assert.equal(selectConfidentGroup(rankGroups(catalog, "ssh_read"), "ssh_read")?.id, "remote-files");
assert.equal(selectConfidentGroup(rankGroups(catalog, "read"), "read"), undefined);
assert.equal(
selectConfidentGroup(rankGroups(catalog, "completely unrelated capability"), "completely unrelated capability"),
undefined,
);
});
test("writes a private cache and rejects a stale manifest hash", async () => {
const directory = await mkdtemp(join(tmpdir(), "tool-search-catalog-"));
try {