fix: gate runtime startup behind gateway_start; migrate to current plugin SDK

Lifecycle:
- Move runtime.start() and shutdown handlers out of register() into
  api.on("gateway_start", ...) and api.on("gateway_stop", ...). register()
  runs in every CLI subprocess that loads plugins (e.g. `openclaw completion`,
  `openclaw doctor`); without this gate the runtime would open a network
  connection / bind a listener every time those one-shot commands ran.
- Drop process.once("SIGTERM"/"SIGINT") in favour of the gateway_stop hook,
  which is the documented way for plugins to react to shutdown.
- Stop relying on the non-standard `api.rootDir` field (not present on the
  current OpenClawPluginApi); compute the per-plugin data directory as
  ~/.openclaw/yonexus-server and ensure it exists before use.

Plugin SDK convention update:
- Wrap default export with definePluginEntry({ id, name, description, register })
  per the current openclaw plugin authoring contract.
- Re-type the register function to accept OpenClawPluginApi instead of the
  hand-crafted { rootDir, pluginConfig, ... } shape.
- Use focused subpath imports openclaw/plugin-sdk/plugin-entry and
  openclaw/plugin-sdk/core.
- Add openclaw as a devDependency (file:/usr/lib/node_modules/openclaw) so
  tsc resolves the SDK type subpaths at build time.
- Modernize openclaw.plugin.json: drop version/entry/permissions, add
  activation.onStartup so gateway_start fires for this plugin at boot.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-05-08 08:08:52 +00:00
parent 0fb9be9dee
commit 9f36312910
3 changed files with 71 additions and 56 deletions

View File

@@ -1,10 +1,13 @@
{
"id": "yonexus-server",
"name": "Yonexus.Server",
"version": "0.1.0",
"description": "Yonexus central hub plugin for cross-instance OpenClaw communication",
"entry": "./dist/Yonexus.Server/plugin/index.js",
"permissions": [],
"activation": {
"onStartup": true
},
"commandAliases": [
{ "name": "yonexus-server" }
],
"configSchema": {
"type": "object",
"additionalProperties": false,