From 248adfaafd27ce6ca75d5b38285c1b1ac6a60850 Mon Sep 17 00:00:00 2001 From: operator Date: Thu, 16 Apr 2026 15:53:20 +0000 Subject: [PATCH] fix: use runtime API for version and agent list instead of subprocess Use api.runtime.version for openclaw version and api.runtime.config.loadConfig() for agent list. Eliminates the periodic openclaw agents list subprocess that caused high CPU usage. --- plugin/index.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/plugin/index.ts b/plugin/index.ts index 93b5f7b..ecc0287 100644 --- a/plugin/index.ts +++ b/plugin/index.ts @@ -14,7 +14,7 @@ import { hostname, freemem, totalmem, uptime, loadavg, platform } from 'os'; import { getPluginConfig } from './core/config'; import { MonitorBridgeClient, type OpenClawMeta } from './core/monitor-bridge'; -import { listOpenClawAgents } from './core/openclaw-agents'; +import type { OpenClawAgentInfo } from './core/openclaw-agents'; import { registerGatewayStartHook } from './hooks/gateway-start'; import { registerGatewayStopHook } from './hooks/gateway-stop'; import { @@ -32,6 +32,12 @@ interface PluginAPI { warn: (...args: any[]) => void; }; version?: string; + runtime?: { + version?: string; + config?: { + loadConfig?: () => any; + }; + }; config?: Record; pluginConfig?: Record; on: (event: string, handler: () => void) => void; @@ -96,7 +102,7 @@ export default { avg15: load[2], }, openclaw: { - version: process.env.OPENCLAW_SERVICE_VERSION || api.version || 'unknown', + version: api.runtime?.version || api.version || 'unknown', pluginVersion: '0.3.1', // Bumped for PLG-CAL-004 }, timestamp: new Date().toISOString(), @@ -118,10 +124,21 @@ export default { const bridgeClient = getBridgeClient(); if (!bridgeClient) return; + let agentNames: string[] = []; + try { + const cfg = api.runtime?.config?.loadConfig?.(); + const agentsList = cfg?.agents?.list; + if (Array.isArray(agentsList)) { + agentNames = agentsList + .map((a: any) => typeof a === 'string' ? a : a?.name) + .filter(Boolean); + } + } catch { /* non-fatal */ } + const meta: OpenClawMeta = { - version: process.env.OPENCLAW_SERVICE_VERSION || api.version || 'unknown', + version: api.runtime?.version || api.version || 'unknown', plugin_version: '0.3.1', - agents: await listOpenClawAgents(logger), + agents: agentNames.map(name => ({ name })), }; const ok = await bridgeClient.pushOpenClawMeta(meta);