@webdevtoday/grok-cli
Version:
A sophisticated CLI tool for interacting with xAI Grok 4, featuring conversation history, file reference, custom commands, memory system, and genetic development workflows
202 lines • 7.64 kB
JavaScript
;
/**
* Tmux session management tool for multi-agent genetic development
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TmuxTool = void 0;
const base_1 = require("./base");
const execa_1 = require("execa");
/**
* Tool for managing tmux sessions for multi-agent development
*/
class TmuxTool extends base_1.BaseTool {
constructor() {
super('Tmux', 'Manage tmux sessions for multi-agent genetic development environments');
}
validateParams(params) {
const { action, sessionName } = params;
if (!action || typeof action !== 'string') {
return false;
}
const validActions = ['new', 'list', 'send', 'kill', 'attach', 'detach', 'status'];
if (!validActions.includes(action)) {
return false;
}
// Session name required for most actions except list and status
if (['new', 'send', 'kill', 'attach', 'detach'].includes(action)) {
if (!sessionName || typeof sessionName !== 'string') {
return false;
}
}
return true;
}
async execute(params) {
const { action, sessionName, command, window, pane } = params;
try {
let tmuxCommand = [];
switch (action) {
case 'new':
// Create new tmux session
tmuxCommand = ['new-session', '-d', '-s', sessionName];
if (command) {
tmuxCommand.push(command);
}
break;
case 'list':
// List all tmux sessions
tmuxCommand = ['list-sessions'];
break;
case 'send':
// Send command to specific session/window/pane
if (!command) {
return {
success: false,
output: '',
error: 'Command is required for send action',
};
}
tmuxCommand = ['send-keys'];
if (window) {
tmuxCommand.push('-t', `${sessionName}:${window}`);
}
else if (pane) {
tmuxCommand.push('-t', `${sessionName}.${pane}`);
}
else {
tmuxCommand.push('-t', sessionName);
}
tmuxCommand.push(command, 'Enter');
break;
case 'kill':
// Kill tmux session
tmuxCommand = ['kill-session', '-t', sessionName];
break;
case 'attach':
// Attach to tmux session (note: this will be limited in headless mode)
tmuxCommand = ['attach-session', '-t', sessionName];
break;
case 'detach':
// Detach from tmux session
tmuxCommand = ['detach-client', '-s', sessionName];
break;
case 'status':
// Show tmux server status
tmuxCommand = ['list-sessions', '-F', '#{session_name}: #{session_windows} windows (created #{session_created_string})'];
break;
default:
return {
success: false,
output: '',
error: `Unknown action: ${action}`,
};
}
const result = await (0, execa_1.execa)('tmux', tmuxCommand, {
reject: false,
timeout: 10000, // 10 second timeout for tmux operations
});
const success = result.exitCode === 0;
return {
success,
output: result.stdout || '',
error: result.stderr || (success ? undefined : `tmux command failed with exit code ${result.exitCode}`),
metadata: {
action,
sessionName,
command: tmuxCommand.join(' '),
exitCode: result.exitCode,
},
};
}
catch (error) {
return {
success: false,
output: '',
error: error instanceof Error ? error.message : String(error),
metadata: {
action,
sessionName,
},
};
}
}
getParameterSchema() {
return {
type: 'object',
properties: {
action: {
type: 'string',
enum: ['new', 'list', 'send', 'kill', 'attach', 'detach', 'status'],
description: 'The tmux action to perform',
},
sessionName: {
type: 'string',
description: 'Name of the tmux session (required for most actions)',
},
command: {
type: 'string',
description: 'Command to send to the session (for send action) or run in new session',
},
window: {
type: 'string',
description: 'Specific window to target (for send action)',
},
pane: {
type: 'string',
description: 'Specific pane to target (for send action)',
},
},
required: ['action'],
};
}
getUsageExamples() {
return [
// Basic session management
'action: "list"',
'action: "new", sessionName: "agent1"',
'action: "new", sessionName: "genetic-dev", command: "cd /workspace && python main.py"',
// Multi-agent coordination
'action: "send", sessionName: "agent1", command: "echo Starting agent1 tasks"',
'action: "send", sessionName: "agent2", command: "git pull origin main"',
'action: "send", sessionName: "coordinator", command: "python coordinate_agents.py"',
// Development workflows
'action: "send", sessionName: "dev-env", command: "npm run dev"',
'action: "send", sessionName: "testing", command: "pytest tests/"',
'action: "send", sessionName: "build", command: "make build"',
// Session cleanup
'action: "kill", sessionName: "old-session"',
'action: "status"',
];
}
/**
* Create a coordinated multi-agent setup
*/
async createMultiAgentEnvironment(agents) {
const results = [];
for (const agent of agents) {
const result = await this.execute({
action: 'new',
sessionName: agent,
command: `echo "Agent ${agent} initialized"`,
});
results.push(result);
}
return results;
}
/**
* Send command to all agents
*/
async broadcastToAgents(agents, command) {
const results = [];
for (const agent of agents) {
const result = await this.execute({
action: 'send',
sessionName: agent,
command,
});
results.push(result);
}
return results;
}
}
exports.TmuxTool = TmuxTool;
//# sourceMappingURL=tmux.js.map