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
This commit is contained in:
zhi
2026-03-05 18:57:58 +00:00
parent 858538aaad
commit 27a94d1da7
2 changed files with 70 additions and 24 deletions

View File

@@ -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 { const {
safeRestart, safeRestart,
createSafeRestartTool, createSafeRestartTool,
@@ -8,12 +11,66 @@ const {
SlashCommandHandler SlashCommandHandler
} = require('./safe-restart/dist/index.js'); } = require('./safe-restart/dist/index.js');
module.exports = { // Plugin initialization function
pcexec, function init(api, config) {
safeRestart, const logger = api.logger || { info: console.log, error: console.error };
createSafeRestartTool,
StatusManager, logger.info('PaddedCell plugin initializing...');
createApiServer,
startApiServer, // Register pcexec tool
SlashCommandHandler, 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;

View File

@@ -7,19 +7,8 @@
"configSchema": { "configSchema": {
"type": "object", "type": "object",
"properties": { "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"
}
]
} }