From 27a94d1da713684c1e9763e68c03f67b48ba26a2 Mon Sep 17 00:00:00 2001 From: zhi Date: Thu, 5 Mar 2026 18:57:58 +0000 Subject: [PATCH] fix: use OpenClaw plugin SDK format with api.registerTool() - Change index.js to export init() function that receives api - Use api.registerTool() to dynamically register tools - Remove tools array from manifest (not needed for dynamic registration) - Add passMgrPath to configSchema --- index.js | 77 ++++++++++++++++++++++++++++++++++++++------ openclaw.plugin.json | 17 ++-------- 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index e5d4e86..f264981 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,7 @@ -const { pcexec } = require('./pcexec/dist/index.js'); +// PaddedCell Plugin for OpenClaw +// Registers pcexec and safe_restart tools + +const { pcexec, pcexecSync } = require('./pcexec/dist/index.js'); const { safeRestart, createSafeRestartTool, @@ -8,12 +11,66 @@ const { SlashCommandHandler } = require('./safe-restart/dist/index.js'); -module.exports = { - pcexec, - safeRestart, - createSafeRestartTool, - StatusManager, - createApiServer, - startApiServer, - SlashCommandHandler, -}; +// Plugin initialization function +function init(api, config) { + const logger = api.logger || { info: console.log, error: console.error }; + + logger.info('PaddedCell plugin initializing...'); + + // Register pcexec tool + api.registerTool({ + name: 'pcexec', + description: 'Safe exec with password sanitization', + parameters: { + type: 'object', + properties: { + command: { type: 'string', description: 'Command to execute' }, + cwd: { type: 'string', description: 'Working directory' }, + timeout: { type: 'number', description: 'Timeout in milliseconds' }, + }, + required: ['command'], + }, + async handler(params) { + return await pcexec(params.command, { + cwd: params.cwd, + timeout: params.timeout, + }); + }, + }); + + // Register safe_restart tool + api.registerTool({ + name: 'safe_restart', + description: 'Safe coordinated restart of OpenClaw gateway', + parameters: { + type: 'object', + properties: { + rollback: { type: 'string', description: 'Rollback script path' }, + log: { type: 'string', description: 'Log file path' }, + }, + }, + async handler(params, context) { + return await safeRestart({ + agentId: context.agentId, + sessionKey: context.sessionKey, + rollback: params.rollback, + log: params.log, + }); + }, + }); + + logger.info('PaddedCell plugin initialized'); +} + +// Export for OpenClaw +module.exports = { init }; + +// Also export individual modules for direct use +module.exports.pcexec = pcexec; +module.exports.pcexecSync = pcexecSync; +module.exports.safeRestart = safeRestart; +module.exports.createSafeRestartTool = createSafeRestartTool; +module.exports.StatusManager = StatusManager; +module.exports.createApiServer = createApiServer; +module.exports.startApiServer = startApiServer; +module.exports.SlashCommandHandler = SlashCommandHandler; diff --git a/openclaw.plugin.json b/openclaw.plugin.json index 908bc6f..55875e6 100644 --- a/openclaw.plugin.json +++ b/openclaw.plugin.json @@ -7,19 +7,8 @@ "configSchema": { "type": "object", "properties": { - "enabled": { "type": "boolean", "default": true } + "enabled": { "type": "boolean", "default": true }, + "passMgrPath": { "type": "string", "default": "/root/.openclaw/bin/pass_mgr" } } - }, - "tools": [ - { - "name": "pcexec", - "entry": "./pcexec/dist/index.js", - "description": "Safe exec with password sanitization" - }, - { - "name": "safe_restart", - "entry": "./safe-restart/dist/index.js", - "description": "Safe coordinated restart" - } - ] + } }