Compare commits

..

1 Commits

Author SHA1 Message Date
h z
b270649f21 Merge pull request 'dev/2026-04-08' (#1) from dev/2026-04-08 into main
Reviewed-on: #1
2026-04-13 09:34:01 +00:00
5 changed files with 54 additions and 80 deletions

8
package-lock.json generated
View File

@@ -12,14 +12,10 @@
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^25.5.2", "@types/node": "^25.5.2",
"openclaw": "file:/usr/lib/node_modules/openclaw",
"typescript": "^5.6.3", "typescript": "^5.6.3",
"vitest": "^4.1.3" "vitest": "^4.1.3"
} }
}, },
"../../../../../usr/lib/node_modules/openclaw": {
"dev": true
},
"node_modules/@emnapi/core": { "node_modules/@emnapi/core": {
"version": "1.9.1", "version": "1.9.1",
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.9.1.tgz", "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.9.1.tgz",
@@ -918,10 +914,6 @@
], ],
"license": "MIT" "license": "MIT"
}, },
"node_modules/openclaw": {
"resolved": "../../../../../usr/lib/node_modules/openclaw",
"link": true
},
"node_modules/pathe": { "node_modules/pathe": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",

View File

@@ -32,7 +32,6 @@
"devDependencies": { "devDependencies": {
"@types/node": "^25.5.2", "@types/node": "^25.5.2",
"typescript": "^5.6.3", "typescript": "^5.6.3",
"vitest": "^4.1.3", "vitest": "^4.1.3"
"openclaw": "file:/usr/lib/node_modules/openclaw"
} }
} }

View File

@@ -1,12 +1,8 @@
export interface YonexusClientConfig { export interface YonexusClientConfig {
mainHost: string; mainHost: string;
identifier: string; identifier: string;
/** notifyBotToken: string;
* Optional. The client never sends pairing notifications (the server adminUserId: string;
* does); accepted for back-compat but no longer required.
*/
notifyBotToken?: string;
adminUserId?: string;
} }
export class YonexusClientConfigError extends Error { export class YonexusClientConfigError extends Error {
@@ -48,9 +44,15 @@ export function validateYonexusClientConfig(raw: unknown): YonexusClientConfig {
issues.push("identifier is required"); issues.push("identifier is required");
} }
// Optional (back-compat): the client does not send notifications.
const rawNotifyBotToken = source.notifyBotToken; const rawNotifyBotToken = source.notifyBotToken;
if (!isNonEmptyString(rawNotifyBotToken)) {
issues.push("notifyBotToken is required");
}
const rawAdminUserId = source.adminUserId; const rawAdminUserId = source.adminUserId;
if (!isNonEmptyString(rawAdminUserId)) {
issues.push("adminUserId is required");
}
if (issues.length > 0) { if (issues.length > 0) {
throw new YonexusClientConfigError(issues); throw new YonexusClientConfigError(issues);
@@ -58,15 +60,13 @@ export function validateYonexusClientConfig(raw: unknown): YonexusClientConfig {
const mainHost = (rawMainHost as string).trim(); const mainHost = (rawMainHost as string).trim();
const identifier = (rawIdentifier as string).trim(); const identifier = (rawIdentifier as string).trim();
const notifyBotToken = (rawNotifyBotToken as string).trim();
const adminUserId = (rawAdminUserId as string).trim();
return { return {
mainHost, mainHost,
identifier, identifier,
notifyBotToken: isNonEmptyString(rawNotifyBotToken) notifyBotToken,
? rawNotifyBotToken.trim() adminUserId
: undefined,
adminUserId: isNonEmptyString(rawAdminUserId)
? rawAdminUserId.trim()
: undefined
}; };
} }

View File

@@ -39,11 +39,7 @@ export {
type ClientRuleProcessor type ClientRuleProcessor
} from "./core/rules.js"; } from "./core/rules.js";
import os from "node:os";
import path from "node:path"; import path from "node:path";
import fs from "node:fs";
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
import { validateYonexusClientConfig } from "./core/config.js"; import { validateYonexusClientConfig } from "./core/config.js";
import { createYonexusClientStateStore } from "./core/state.js"; import { createYonexusClientStateStore } from "./core/state.js";
import { createClientTransport } from "./core/transport.js"; import { createClientTransport } from "./core/transport.js";
@@ -56,8 +52,6 @@ const _RUNTIME_KEY = "_yonexusClientRuntime";
const _REGISTRY_KEY = "_yonexusClientRegistry"; const _REGISTRY_KEY = "_yonexusClientRegistry";
const _CALLBACKS_KEY = "_yonexusClientOnAuthCallbacks"; const _CALLBACKS_KEY = "_yonexusClientOnAuthCallbacks";
const PLUGIN_DATA_DIR = path.join(os.homedir(), ".openclaw", "yonexus-client");
export interface YonexusClientPluginManifest { export interface YonexusClientPluginManifest {
readonly name: "Yonexus.Client"; readonly name: "Yonexus.Client";
readonly version: string; readonly version: string;
@@ -70,7 +64,7 @@ const manifest: YonexusClientPluginManifest = {
description: "Yonexus client plugin for cross-instance OpenClaw communication" description: "Yonexus client plugin for cross-instance OpenClaw communication"
}; };
export function createYonexusClientPlugin(api: OpenClawPluginApi): void { export function createYonexusClientPlugin(api: { rootDir: string; pluginConfig: unknown }): void {
// 1. Ensure shared state survives hot-reload — only initialise when absent // 1. Ensure shared state survives hot-reload — only initialise when absent
if (!(_G[_REGISTRY_KEY] instanceof YonexusClientRuleRegistry)) { if (!(_G[_REGISTRY_KEY] instanceof YonexusClientRuleRegistry)) {
_G[_REGISTRY_KEY] = createClientRuleRegistry(); _G[_REGISTRY_KEY] = createClientRuleRegistry();
@@ -93,18 +87,12 @@ export function createYonexusClientPlugin(api: OpenClawPluginApi): void {
onAuthenticated: onAuthenticatedCallbacks onAuthenticated: onAuthenticatedCallbacks
}; };
// 3. Runtime startup — only fire when the gateway boots, not eagerly during // 3. Start the runtime only once — the globalThis flag survives hot-reload
// register() inside one-shot CLI subprocesses (e.g. `openclaw completion`).
// Without this gate, every CLI invocation that loads plugins would open
// a WebSocket to the Yonexus server.
api.on("gateway_start", () => {
if (_G[_STARTED_KEY]) return; if (_G[_STARTED_KEY]) return;
_G[_STARTED_KEY] = true; _G[_STARTED_KEY] = true;
fs.mkdirSync(PLUGIN_DATA_DIR, { recursive: true });
const config = validateYonexusClientConfig(api.pluginConfig); const config = validateYonexusClientConfig(api.pluginConfig);
const stateStore = createYonexusClientStateStore(path.join(PLUGIN_DATA_DIR, "state.json")); const stateStore = createYonexusClientStateStore(path.join(api.rootDir, "state.json"));
const transport = createClientTransport({ const transport = createClientTransport({
config, config,
@@ -129,23 +117,18 @@ export function createYonexusClientPlugin(api: OpenClawPluginApi): void {
}); });
_G[_RUNTIME_KEY] = runtime; _G[_RUNTIME_KEY] = runtime;
const shutdown = (): void => {
runtime.stop().catch((err: unknown) => {
console.error("[yonexus-client] shutdown error:", err);
});
};
process.once("SIGTERM", shutdown);
process.once("SIGINT", shutdown);
runtime.start().catch((err: unknown) => { runtime.start().catch((err: unknown) => {
console.error("[yonexus-client] failed to start:", err); console.error("[yonexus-client] failed to start:", err);
}); });
});
api.on("gateway_stop", () => {
const runtime = _G[_RUNTIME_KEY] as YonexusClientRuntime | undefined;
runtime?.stop().catch((err: unknown) => {
console.error("[yonexus-client] shutdown error:", err);
});
});
} }
export default definePluginEntry({ export default createYonexusClientPlugin;
id: "yonexus-client",
name: "Yonexus.Client",
description: "Yonexus client plugin for cross-instance OpenClaw communication",
register: createYonexusClientPlugin,
});
export { manifest }; export { manifest };

View File

@@ -1,10 +1,10 @@
{ {
"id": "yonexus-client", "id": "yonexus-client",
"name": "Yonexus.Client", "name": "Yonexus.Client",
"version": "0.1.0",
"description": "Yonexus client plugin for cross-instance OpenClaw communication", "description": "Yonexus client plugin for cross-instance OpenClaw communication",
"activation": { "entry": "./dist/Yonexus.Client/plugin/index.js",
"onStartup": true "permissions": [],
},
"configSchema": { "configSchema": {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
@@ -14,6 +14,6 @@
"notifyBotToken": { "type": "string" }, "notifyBotToken": { "type": "string" },
"adminUserId": { "type": "string" } "adminUserId": { "type": "string" }
}, },
"required": ["mainHost", "identifier"] "required": ["mainHost", "identifier", "notifyBotToken", "adminUserId"]
} }
} }