feat: add proxy pcexec tool
This commit is contained in:
@@ -26,6 +26,12 @@ function resolveOpenclawPath(config?: { openclawProfilePath?: string }): string
|
||||
return require('path').join(home, '.openclaw');
|
||||
}
|
||||
|
||||
function resolveProxyAllowlist(config?: { proxyAllowlist?: unknown; 'proxy-allowlist'?: unknown }): string[] {
|
||||
const value = config?.proxyAllowlist ?? config?.['proxy-allowlist'];
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value.filter((item): item is string => typeof item === 'string');
|
||||
}
|
||||
|
||||
// Plugin registration function
|
||||
function register(api: any, config?: any) {
|
||||
const logger = api.logger || { info: console.log, error: console.error };
|
||||
@@ -33,6 +39,7 @@ function register(api: any, config?: any) {
|
||||
logger.info('PaddedCell plugin initializing...');
|
||||
|
||||
const openclawPath = resolveOpenclawPath(config);
|
||||
const proxyAllowlist = resolveProxyAllowlist(config);
|
||||
const binDir = require('path').join(openclawPath, 'bin');
|
||||
|
||||
// Register pcexec tool — pass a FACTORY function that receives context
|
||||
@@ -85,6 +92,69 @@ function register(api: any, config?: any) {
|
||||
};
|
||||
});
|
||||
|
||||
api.registerTool((ctx: any) => {
|
||||
const agentId = ctx.agentId;
|
||||
const workspaceDir = ctx.workspaceDir;
|
||||
|
||||
return {
|
||||
name: 'proxy-pcexec',
|
||||
description: 'Safe exec with password sanitization using a proxied AGENT_ID',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
command: { type: 'string', description: 'Command to execute' },
|
||||
cwd: { type: 'string', description: 'Working directory' },
|
||||
timeout: { type: 'number', description: 'Timeout in milliseconds' },
|
||||
'proxy-for': { type: 'string', description: 'AGENT_ID value to inject for the subprocess' },
|
||||
},
|
||||
required: ['command', 'proxy-for'],
|
||||
},
|
||||
async execute(_id: string, params: any) {
|
||||
const command = params.command;
|
||||
const proxyFor = params['proxy-for'];
|
||||
if (!command) {
|
||||
throw new Error('Missing required parameter: command');
|
||||
}
|
||||
if (!proxyFor) {
|
||||
throw new Error('Missing required parameter: proxy-for');
|
||||
}
|
||||
if (!agentId || !proxyAllowlist.includes(agentId)) {
|
||||
throw new Error('Current agent is not allowed to call proxy-pcexec');
|
||||
}
|
||||
|
||||
logger.info('proxy-pcexec invoked', {
|
||||
executor: agentId,
|
||||
proxyFor,
|
||||
command,
|
||||
});
|
||||
|
||||
const currentPath = process.env.PATH || '';
|
||||
const newPath = currentPath.includes(binDir)
|
||||
? currentPath
|
||||
: `${currentPath}:${binDir}`;
|
||||
|
||||
const result = await pcexec(command, {
|
||||
cwd: params.cwd || workspaceDir,
|
||||
timeout: params.timeout,
|
||||
env: {
|
||||
AGENT_ID: String(proxyFor),
|
||||
AGENT_WORKSPACE: workspaceDir || '',
|
||||
AGENT_VERIFY,
|
||||
PROXY_PCEXEC_EXECUTOR: agentId || '',
|
||||
PCEXEC_PROXIED: 'true',
|
||||
PATH: newPath,
|
||||
},
|
||||
});
|
||||
|
||||
let output = result.stdout;
|
||||
if (result.stderr) {
|
||||
output += result.stderr;
|
||||
}
|
||||
return { content: [{ type: 'text', text: output }] };
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
// Register safe_restart tool
|
||||
api.registerTool((ctx: any) => {
|
||||
const agentId = ctx.agentId;
|
||||
|
||||
Reference in New Issue
Block a user