Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ export function isHostVersionSupported(hostVersion: string): boolean {
return compareVersions(host, min) >= 0;
}

/** Tracks host versions that have already passed the compatibility check. */
const checkedHostVersions = new Set<string>();

/**
* Fail-fast guard. Call at the very start of `register()` to prevent the
* plugin from loading on an incompatible host.
*
* On the first successful check the result is logged at `info` level.
* Subsequent re-entrant calls for the same version are logged at `debug`
* to avoid log spam when the host invokes `register()` multiple times.
*
* @throws {Error} with a human-readable message when the host is out of range.
*/
export function assertHostCompatibility(hostVersion: string | undefined): void {
Expand All @@ -65,7 +72,12 @@ export function assertHostCompatibility(hostVersion: string | undefined): void {
return;
}
if (isHostVersionSupported(hostVersion)) {
logger.info(`[compat] Host OpenClaw ${hostVersion} >= ${SUPPORTED_HOST_MIN}, OK.`);
if (checkedHostVersions.has(hostVersion)) {
logger.debug(`[compat] Host OpenClaw ${hostVersion} >= ${SUPPORTED_HOST_MIN}, OK (already verified).`);
} else {
checkedHostVersions.add(hostVersion);
logger.info(`[compat] Host OpenClaw ${hostVersion} >= ${SUPPORTED_HOST_MIN}, OK.`);
}
return;
}
throw new Error(
Expand Down
12 changes: 11 additions & 1 deletion src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ import type { PluginRuntime } from "openclaw/plugin-sdk/core";
import { logger } from "./util/logger.js";

let pluginRuntime: PluginRuntime | null = null;
let runtimeInitialized = false;

export type PluginChannelRuntime = PluginRuntime["channel"];

/**
* Sets the global Weixin runtime (called from plugin register).
*
* The first successful call is logged at `info` level. Subsequent
* re-entrant calls (caused by the host re-invoking `register()`) are
* logged at `debug` to keep log output clean.
*/
export function setWeixinRuntime(next: PluginRuntime): void {
pluginRuntime = next;
logger.info(`[runtime] setWeixinRuntime called, runtime set successfully`);
if (runtimeInitialized) {
logger.debug(`[runtime] setWeixinRuntime called (re-entrant), runtime updated`);
} else {
runtimeInitialized = true;
logger.info(`[runtime] setWeixinRuntime called, runtime set successfully`);
}
}

/**
Expand Down