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-client 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 b270649f21
commit e57fed2e50
3 changed files with 58 additions and 40 deletions

View File

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