fix: remove shell:true default to fix command output

- Removed shell:true default that caused double shell wrapping
- This was causing echo and other commands to return empty output
- Now matches OpenClaw exec behavior which never uses shell:true
This commit is contained in:
zhi
2026-03-06 09:20:38 +00:00
parent 9c70cc33a5
commit 903e5efddb
2 changed files with 72 additions and 44 deletions

100
index.js
View File

@@ -11,52 +11,78 @@ const {
SlashCommandHandler SlashCommandHandler
} = require('./safe-restart/dist/index.js'); } = require('./safe-restart/dist/index.js');
// Plugin registration function (OpenClaw expects 'register' or 'activate') // Plugin registration function
function register(api, config) { function register(api, config) {
const logger = api.logger || { info: console.log, error: console.error }; const logger = api.logger || { info: console.log, error: console.error };
logger.info('PaddedCell plugin initializing...'); logger.info('PaddedCell plugin initializing...');
// Register pcexec tool // Register pcexec tool - pass a FACTORY function that receives context
api.registerTool({ api.registerTool((ctx) => {
name: 'pcexec', console.log(`[PaddedCell] pcexec factory called with ctx:`, JSON.stringify(ctx, null, 2));
description: 'Safe exec with password sanitization', const agentId = ctx.agentId;
parameters: { const workspaceDir = ctx.workspaceDir;
type: 'object',
properties: { return {
command: { type: 'string', description: 'Command to execute' }, name: 'pcexec',
cwd: { type: 'string', description: 'Working directory' }, description: 'Safe exec with password sanitization',
timeout: { type: 'number', description: 'Timeout in milliseconds' }, 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'],
}, },
required: ['command'], async execute(_id, params) {
}, const command = params.command;
async handler(params) { if (!command) {
return await pcexec(params.command, { throw new Error('Missing required parameter: command');
cwd: params.cwd, }
timeout: params.timeout, console.log(`[PaddedCell] pcexec execute: agentId=${agentId}, workspaceDir=${workspaceDir}`);
}); const result = await pcexec(command, {
}, cwd: params.cwd || workspaceDir,
timeout: params.timeout,
env: {
AGENT_ID: agentId || '',
AGENT_WORKSPACE: workspaceDir || '',
},
});
// Format output for OpenClaw tool response
let output = result.stdout;
if (result.stderr) {
output += result.stderr;
}
return { content: [{ type: 'text', text: output }] };
},
};
}); });
// Register safe_restart tool // Register safe_restart tool - pass a FACTORY function that receives context
api.registerTool({ api.registerTool((ctx) => {
name: 'safe_restart', const agentId = ctx.agentId;
description: 'Safe coordinated restart of OpenClaw gateway', const sessionKey = ctx.sessionKey;
parameters: {
type: 'object', return {
properties: { name: 'safe_restart',
rollback: { type: 'string', description: 'Rollback script path' }, description: 'Safe coordinated restart of OpenClaw gateway',
log: { type: 'string', description: 'Log file path' }, parameters: {
type: 'object',
properties: {
rollback: { type: 'string', description: 'Rollback script path' },
log: { type: 'string', description: 'Log file path' },
},
}, },
}, async execute(_id, params) {
async handler(params, context) { return await safeRestart({
return await safeRestart({ agentId: agentId,
agentId: context.agentId, sessionKey: sessionKey,
sessionKey: context.sessionKey, rollback: params.rollback,
rollback: params.rollback, log: params.log,
log: params.log, });
}); },
}, };
}); });
logger.info('PaddedCell plugin initialized'); logger.info('PaddedCell plugin initialized');

View File

@@ -201,7 +201,8 @@ export async function pcexec(command: string, options: PcExecOptions = {}): Prom
const spawnOptions: SpawnOptions = { const spawnOptions: SpawnOptions = {
cwd: options.cwd, cwd: options.cwd,
env, env,
shell: options.shell ?? true, // Don't use shell by default - we're already using bash -c explicitly
shell: options.shell,
windowsHide: options.windowsHide, windowsHide: options.windowsHide,
uid: options.uid, uid: options.uid,
gid: options.gid, gid: options.gid,
@@ -327,7 +328,8 @@ export function pcexecSync(command: string, options: PcExecOptions = {}): PcExec
const execOptions: any = { const execOptions: any = {
cwd: options.cwd, cwd: options.cwd,
env, env,
shell: options.shell ?? true, // Don't use shell by default
shell: options.shell,
encoding: 'utf8', encoding: 'utf8',
windowsHide: options.windowsHide, windowsHide: options.windowsHide,
uid: options.uid, uid: options.uid,