Gateway: suppress tools.catalog plugin conflict diagnostics

This commit is contained in:
Tak Hoffman
2026-02-23 00:05:57 -06:00
parent 9e1a13bf4c
commit 35fbf26d24
3 changed files with 40 additions and 14 deletions

View File

@@ -84,6 +84,7 @@ function buildPluginGroups(params: {
},
existingToolNames: params.existingToolNames,
toolAllowlist: ["group:plugins"],
suppressNameConflicts: true,
});
const groups = new Map<string, ToolCatalogGroup>();
for (const tool of pluginTools) {

View File

@@ -154,4 +154,24 @@ describe("resolvePluginTools optional tools", () => {
expect(registry.diagnostics).toHaveLength(1);
expect(registry.diagnostics[0]?.message).toContain("plugin tool name conflict");
});
it("suppresses conflict diagnostics when requested", () => {
const registry = setRegistry([
{
pluginId: "multi",
optional: false,
source: "/tmp/multi.js",
factory: () => [makeTool("message"), makeTool("other_tool")],
},
]);
const tools = resolvePluginTools({
context: createContext() as never,
existingToolNames: new Set(["message"]),
suppressNameConflicts: true,
});
expect(tools.map((tool) => tool.name)).toEqual(["other_tool"]);
expect(registry.diagnostics).toHaveLength(0);
});
});

View File

@@ -46,6 +46,7 @@ export function resolvePluginTools(params: {
context: OpenClawPluginToolContext;
existingToolNames?: Set<string>;
toolAllowlist?: string[];
suppressNameConflicts?: boolean;
}): AnyAgentTool[] {
// Fast path: when plugins are effectively disabled, avoid discovery/jiti entirely.
// This matters a lot for unit tests and for tool construction hot paths.
@@ -74,13 +75,15 @@ export function resolvePluginTools(params: {
const pluginIdKey = normalizeToolName(entry.pluginId);
if (existingNormalized.has(pluginIdKey)) {
const message = `plugin id conflicts with core tool name (${entry.pluginId})`;
log.error(message);
registry.diagnostics.push({
level: "error",
pluginId: entry.pluginId,
source: entry.source,
message,
});
if (!params.suppressNameConflicts) {
log.error(message);
registry.diagnostics.push({
level: "error",
pluginId: entry.pluginId,
source: entry.source,
message,
});
}
blockedPlugins.add(entry.pluginId);
continue;
}
@@ -111,13 +114,15 @@ export function resolvePluginTools(params: {
for (const tool of list) {
if (nameSet.has(tool.name) || existing.has(tool.name)) {
const message = `plugin tool name conflict (${entry.pluginId}): ${tool.name}`;
log.error(message);
registry.diagnostics.push({
level: "error",
pluginId: entry.pluginId,
source: entry.source,
message,
});
if (!params.suppressNameConflicts) {
log.error(message);
registry.diagnostics.push({
level: "error",
pluginId: entry.pluginId,
source: entry.source,
message,
});
}
continue;
}
nameSet.add(tool.name);