Merge pull request 'fix: remove shell:true default to fix command output' (#2) from fix/shell-option into main
Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
110
index.js
110
index.js
@@ -2,61 +2,87 @@
|
||||
// Registers pcexec and safe_restart tools
|
||||
|
||||
const { pcexec, pcexecSync } = require('./pcexec/dist/index.js');
|
||||
const {
|
||||
safeRestart,
|
||||
createSafeRestartTool,
|
||||
StatusManager,
|
||||
const {
|
||||
safeRestart,
|
||||
createSafeRestartTool,
|
||||
StatusManager,
|
||||
createApiServer,
|
||||
startApiServer,
|
||||
SlashCommandHandler
|
||||
} = require('./safe-restart/dist/index.js');
|
||||
|
||||
// Plugin registration function (OpenClaw expects 'register' or 'activate')
|
||||
// Plugin registration function
|
||||
function register(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' },
|
||||
// Register pcexec tool - pass a FACTORY function that receives context
|
||||
api.registerTool((ctx) => {
|
||||
console.log(`[PaddedCell] pcexec factory called with ctx:`, JSON.stringify(ctx, null, 2));
|
||||
const agentId = ctx.agentId;
|
||||
const workspaceDir = ctx.workspaceDir;
|
||||
|
||||
return {
|
||||
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'],
|
||||
},
|
||||
required: ['command'],
|
||||
},
|
||||
async handler(params) {
|
||||
return await pcexec(params.command, {
|
||||
cwd: params.cwd,
|
||||
timeout: params.timeout,
|
||||
});
|
||||
},
|
||||
async execute(_id, params) {
|
||||
const command = params.command;
|
||||
if (!command) {
|
||||
throw new Error('Missing required parameter: command');
|
||||
}
|
||||
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
|
||||
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' },
|
||||
// Register safe_restart tool - pass a FACTORY function that receives context
|
||||
api.registerTool((ctx) => {
|
||||
const agentId = ctx.agentId;
|
||||
const sessionKey = ctx.sessionKey;
|
||||
|
||||
return {
|
||||
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,
|
||||
});
|
||||
},
|
||||
async execute(_id, params) {
|
||||
return await safeRestart({
|
||||
agentId: agentId,
|
||||
sessionKey: sessionKey,
|
||||
rollback: params.rollback,
|
||||
log: params.log,
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
logger.info('PaddedCell plugin initialized');
|
||||
|
||||
@@ -201,7 +201,8 @@ export async function pcexec(command: string, options: PcExecOptions = {}): Prom
|
||||
const spawnOptions: SpawnOptions = {
|
||||
cwd: options.cwd,
|
||||
env,
|
||||
shell: options.shell ?? true,
|
||||
// Don't use shell by default - we're already using bash -c explicitly
|
||||
shell: options.shell,
|
||||
windowsHide: options.windowsHide,
|
||||
uid: options.uid,
|
||||
gid: options.gid,
|
||||
@@ -327,7 +328,8 @@ export function pcexecSync(command: string, options: PcExecOptions = {}): PcExec
|
||||
const execOptions: any = {
|
||||
cwd: options.cwd,
|
||||
env,
|
||||
shell: options.shell ?? true,
|
||||
// Don't use shell by default
|
||||
shell: options.shell,
|
||||
encoding: 'utf8',
|
||||
windowsHide: options.windowsHide,
|
||||
uid: options.uid,
|
||||
|
||||
Reference in New Issue
Block a user