Skip to content

Commit 87b7121

Browse files
authored
refactor(plugins): isolate tool metadata from runtime loading (#132932)
Move tool metadata into one dependency-light owner so catalog and MCP materialization no longer import the plugin tool-construction runtime. Keep the single metadata store, shipped SDK exports, record identity, and tool semantics unchanged; migrate internal readers and producers. Cover the boundary with original-source import-denial reproduction and native loader/SDK metadata singleton proof on the exact candidate tree. Follow up on the startup preparation cleanup in #131503.
1 parent 348ad76 commit 87b7121

73 files changed

Lines changed: 432 additions & 271 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎scripts/test-built-plugin-singleton.mts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,51 @@ assert.equal(match.args, "now");
212212
const result = await match.command.handler({ args: match.args });
213213
assert.deepEqual(result, { text: "paired:now" });
214214

215+
// Keep these imports after the cold native checks so they cannot prewarm the loader.
216+
const { buildBundleMcpToolsFromCatalog } = await import(
217+
pathToFileURL(path.join(repoRoot, "dist", "agents", "agent-bundle-mcp-materialize.js")).href
218+
);
219+
const { getPluginToolMeta } = await import(
220+
pathToFileURL(path.join(repoRoot, "dist", "plugins", "tool-metadata.js")).href
221+
);
222+
const { getPluginToolMeta: getSdkPluginToolMeta } = await import(
223+
pathToFileURL(path.join(repoRoot, "dist", "plugin-sdk", "agent-harness-runtime.js")).href
224+
);
225+
const [mcpTool] = buildBundleMcpToolsFromCatalog({
226+
catalog: {
227+
version: 1,
228+
generatedAt: 0,
229+
servers: {
230+
"build-smoke-mcp": {
231+
serverName: "build-smoke-mcp",
232+
safeServerName: "build-smoke-mcp",
233+
launchSummary: "build smoke inventory fixture",
234+
toolCount: 1,
235+
},
236+
},
237+
tools: [
238+
{
239+
serverName: "build-smoke-mcp",
240+
safeServerName: "build-smoke-mcp",
241+
toolName: "lookup",
242+
inputSchema: { type: "object", properties: {} },
243+
fallbackDescription: "Look up a build smoke inventory item",
244+
},
245+
],
246+
},
247+
});
248+
assert.ok(mcpTool, "compiled MCP materializer did not produce a tool");
249+
const mcpMetadata = getPluginToolMeta(mcpTool);
250+
assert.ok(mcpMetadata, "canonical built metadata owner did not receive MCP tool metadata");
251+
assert.equal(mcpMetadata.pluginId, "bundle-mcp");
252+
assert.equal(mcpMetadata.mcp?.serverName, "build-smoke-mcp");
253+
assert.equal(mcpMetadata.mcp?.safeServerName, "build-smoke-mcp");
254+
assert.equal(mcpMetadata.mcp?.toolName, "lookup");
255+
assert.equal(mcpMetadata.mcp?.operation, "tool");
256+
assert.strictEqual(
257+
getSdkPluginToolMeta(mcpTool),
258+
mcpMetadata,
259+
"public agent-harness-runtime SDK did not read the canonical MCP metadata record",
260+
);
261+
215262
process.stdout.write("[build-smoke] built plugin singleton smoke passed\n");

‎src/agents/agent-bundle-lsp-runtime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
55
import { createAbortError } from "../infra/abort-signal.js";
66
import { logDebug, logWarn } from "../logger.js";
77
import type { PluginManifestRegistry } from "../plugins/manifest-registry.js";
8-
import { setPluginToolMeta } from "../plugins/tools.js";
8+
import { setPluginToolMeta } from "../plugins/tool-metadata.js";
99
import { createPendingRequestRegistry } from "../shared/pending-request-registry.js";
1010
import {
1111
defaultBundleLspRuntimeDependencies,

‎src/agents/agent-bundle-mcp-harness.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { SessionToolOverrides } from "../config/sessions/types.js";
33
import type { OpenClawConfig } from "../config/types.openclaw.js";
44
import type { PluginManifestRegistry } from "../plugins/manifest-registry.js";
5-
import { getPluginToolMeta } from "../plugins/tools.js";
5+
import { getPluginToolMeta } from "../plugins/tool-metadata.js";
66
import {
77
buildBundleMcpToolsFromCatalog,
88
materializeBundleMcpToolsForRun,

‎src/agents/agent-bundle-mcp-materialize.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { isRecord } from "@openclaw/normalization-core/record-coerce";
66
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
77
import type { OpenClawConfig } from "../config/types.openclaw.js";
88
import { logWarn } from "../logger.js";
9-
import { getPluginToolMeta, setPluginToolMeta, type PluginToolMcpMeta } from "../plugins/tools.js";
9+
import {
10+
getPluginToolMeta,
11+
setPluginToolMeta,
12+
type PluginToolMcpMeta,
13+
} from "../plugins/tool-metadata.js";
1014
import {
1115
buildSafeToolName,
1216
normalizeReservedToolNames,

‎src/agents/agent-bundle-mcp-runtime.agent-bundle.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { afterEach, expect, it } from "vitest";
88
import type { OpenClawConfig } from "../config/types.openclaw.js";
99
import { loadEnabledBundleMcpConfig } from "../plugins/bundle-mcp.js";
1010
import { clearPluginMetadataLifecycleCaches } from "../plugins/plugin-metadata-lifecycle.js";
11-
import { getPluginToolMeta } from "../plugins/tools.js";
11+
import { getPluginToolMeta } from "../plugins/tool-metadata.js";
1212
import { withEnvAsync } from "../test-utils/env.js";
1313
import {
1414
disposeAllSessionMcpRuntimes,

‎src/agents/agent-bundle-mcp-runtime.test.ts‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ import type { SessionMcpRuntime } from "./agent-bundle-mcp-types.js";
3333
import { writeExecutable } from "./bundle-mcp-shared.test-harness.js";
3434
import { updateMcpAppModelContext } from "./mcp-app-model-context.js";
3535

36-
const pluginToolMetadata = vi.hoisted(() => new WeakMap<object, unknown>());
37-
38-
vi.mock("../plugins/tools.js", () => ({
39-
getPluginToolMeta: (tool: object) => pluginToolMetadata.get(tool),
40-
setPluginToolMeta: (tool: object, metadata: unknown) => {
41-
pluginToolMetadata.set(tool, metadata);
42-
},
43-
}));
44-
4536
vi.mock("./embedded-agent-mcp.js", async (importOriginal) => {
4637
const actual = await importOriginal<typeof import("./embedded-agent-mcp.js")>();
4738
return {

‎src/agents/agent-bundle-mcp-tools.materialize.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
44
import { expectDefined } from "@openclaw/normalization-core";
55
import { validateToolArguments } from "openclaw/plugin-sdk/llm";
66
import { afterEach, describe, expect, it } from "vitest";
7-
import { getPluginToolMeta } from "../plugins/tools.js";
7+
import { getPluginToolMeta } from "../plugins/tool-metadata.js";
88
import {
99
buildBundleMcpToolsFromCatalog,
1010
createBundleMcpToolRuntime,

‎src/agents/agent-tool-metadata.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { copyPluginToolMeta, getPluginToolMeta } from "../plugins/tools.js";
1+
import { copyPluginToolMeta, getPluginToolMeta } from "../plugins/tool-metadata.js";
22
import type { AnyAgentTool } from "./agent-tools.types.js";
33
import { copyBeforeToolCallHookMarker } from "./before-tool-call-metadata.js";
44
import { copyChannelAgentToolMeta } from "./channel-tool-metadata.js";

‎src/agents/agent-tools.before-tool-call.decision.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { addTestHook } from "../plugins/hooks.test-fixtures.js";
1212
import { createEmptyPluginRegistry } from "../plugins/registry.js";
1313
import { setActivePluginRegistry } from "../plugins/runtime.js";
14-
import { setPluginToolMeta } from "../plugins/tools.js";
14+
import { setPluginToolMeta } from "../plugins/tool-metadata.js";
1515
import type { PluginHookRegistration } from "../plugins/types.js";
1616
import { toToolDefinitions } from "./agent-tool-definition-adapter.js";
1717
import {

‎src/agents/agent-tools.before-tool-call.diagnostics.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { pruneMapToMaxSize } from "../infra/map-size.js";
2929
import type { SessionState } from "../logging/diagnostic-session-state.js";
3030
import { redactToolDetail } from "../logging/redact.js";
3131
import { createSubsystemLogger } from "../logging/subsystem.js";
32-
import { getPluginToolMeta } from "../plugins/tools.js";
32+
import { getPluginToolMeta } from "../plugins/tool-metadata.js";
3333
import { createLazyRuntimeSurface } from "../shared/lazy-runtime.js";
3434
import {
3535
resolveSkillTelemetrySource,

0 commit comments

Comments
 (0)