tlnt
Version:
TLNT - HMS-Powered Multi-Agent Platform with Government Agency Analysis, Deep Research, and Enterprise-Ready Deployment. Self-optimizing multi-domain AI agent with continuous learning and enterprise-grade performance monitoring.
326 lines • 14.1 kB
JavaScript
import { Command } from 'commander';
import chalk from 'chalk';
import { readFileSync } from 'fs';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { SimpleTUI } from '../ui/simpleTui.js';
import { AgentHub } from '../core/agentHub.js';
import { HubAdapter } from '../integrations/agency/hubAdapter.js';
import { PluginLoader } from '../core/pluginLoader.js';
import { blaxApi } from '../services/blaxApiClient.js';
import { blaxConfig } from '../config/blax.js';
import { HMSCommands } from './hmsCommands.js';
import { DemoScript } from '../demo/demoScript.js';
import { loadingScreen, showQuickLoading } from '../ui/loadingScreen.js';
import createTmuxCommand from './tmuxCommand.js';
import createThemeCommand from './themeCommand.js';
import createPanelCommand from './panelCommand.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Read package.json for version
const packageJsonPath = resolve(__dirname, '../../package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
export default async function boot() {
// Set environment variables for color support
process.env.FORCE_COLOR = '1';
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const program = new Command();
program
.name('blax')
.description('Multi-Agent Collaboration Platform with Human-in-the-Loop Supervision')
.version(packageJson.version);
// Initialize HMS Dev commands
const hmsCommands = new HMSCommands();
hmsCommands.registerCommands(program);
// Add tmux-style interface command
program.addCommand(createTmuxCommand());
// Add theme management command
program.addCommand(createThemeCommand());
// Add panel management command
program.addCommand(createPanelCommand());
// Main interactive command (default)
program
.command('interactive', { isDefault: true })
.description('Start interactive full-screen mode')
.option('--debug', 'Enable debug logging')
.option('--offline', 'Run in offline mode without hub connection')
.action(async (options) => {
try {
// Show loading screen with ASCII art
await loadingScreen.show();
// Initialize core components
const agentHub = new AgentHub();
await agentHub.initialize();
const hubAdapter = new HubAdapter();
const pluginLoader = new PluginLoader(agentHub);
// Load plugins
await pluginLoader.loadPlugins();
// Connect to agency hub if not offline
if (!options.offline) {
try {
await hubAdapter.connect();
console.log(chalk.green('✓ Connected to agency hub'));
}
catch (error) {
console.log(chalk.yellow('⚠ Running in offline mode'));
}
}
// Start TUI
const tui = new SimpleTUI(agentHub, hubAdapter);
await tui.start();
}
catch (error) {
console.error(chalk.red('Error starting Blax:'), error);
process.exit(1);
}
});
// One-shot ask command
program
.command('ask <prompt>')
.description('Ask a one-shot question and get markdown response')
.option('--agent <name>', 'Specify agent to use')
.option('--json', 'Output response in JSON format')
.action(async (prompt, options) => {
try {
await showQuickLoading('Processing query...', 500);
const agentHub = new AgentHub();
await agentHub.initialize();
const result = await agentHub.execute('chat', {
sessionId: `ask-${Date.now()}`,
userId: 'cli-user',
workspacePath: process.cwd(),
environment: 'production',
capabilities: ['chat'],
metadata: {}
}, { prompt, agent: options.agent });
if (options.json) {
console.log(JSON.stringify(result, null, 2));
}
else {
console.log(result.data);
}
}
catch (error) {
console.error(chalk.red('Error:'), error);
process.exit(1);
}
});
// Agency ecosystem commands
const agencyCmd = program
.command('agents')
.description('Manage agency ecosystem agents');
agencyCmd
.command('list')
.description('List all registered agents')
.option('--json', 'Output in JSON format')
.option('--offline', 'Show offline mode message')
.action(async (options) => {
try {
const hubAdapter = new HubAdapter();
// Add error handler to prevent unhandled errors
hubAdapter.on('error', () => {
// Silently handle connection errors
});
// Try to connect with a short timeout
const connectPromise = hubAdapter.connect();
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Connection timeout')), 2000));
try {
await Promise.race([connectPromise, timeoutPromise]);
const agents = await hubAdapter.listAgents();
if (options.json) {
console.log(JSON.stringify(agents, null, 2));
}
else {
console.log(chalk.cyan('Registered agents:'));
if (agents.length === 0) {
console.log(chalk.gray(' No agents registered'));
}
else {
agents.forEach(agent => {
const statusColor = agent.status === 'active' ? 'green' :
agent.status === 'error' ? 'red' : 'yellow';
console.log(` ${chalk[statusColor](agent.status)} ${chalk.bold(agent.name)} (${agent.id})`);
});
}
}
}
catch (connectionError) {
// Connection failed - show offline message
if (options.json) {
console.log(JSON.stringify({ error: 'Hub not available', agents: [] }, null, 2));
}
else {
console.log(chalk.yellow('⚠ Agency hub not available'));
console.log(chalk.gray(' Connect to blax.ai hub to see registered agents'));
console.log(chalk.gray(' Default hub URL: wss://api.blax.ai/hub'));
console.log(chalk.gray(' Set BLAX_HUB_URL env var for custom endpoint'));
}
}
}
catch (error) {
console.error(chalk.red('Error:'), error instanceof Error ? error.message : String(error));
process.exit(1);
}
});
// Cloud agents command (blax.ai integration)
const cloudCmd = program
.command('cloud')
.description('Manage blax.ai cloud agents and services');
cloudCmd
.command('status')
.description('Check blax.ai system status')
.option('--json', 'Output in JSON format')
.action(async (options) => {
try {
const response = await blaxApi.getSystemStatus();
if (options.json) {
console.log(JSON.stringify(response, null, 2));
}
else if (response.success) {
const status = response.data;
const statusColor = status.status === 'healthy' ? 'green' :
status.status === 'degraded' ? 'yellow' : 'red';
console.log(chalk.cyan.bold('Blax.ai System Status'));
console.log(`Status: ${chalk[statusColor](status.status)}`);
console.log(`Agents: ${chalk.white(status.agents.active)}/${chalk.gray(status.agents.total)} active`);
console.log(`Deals: ${chalk.white(status.deals.active)}/${chalk.gray(status.deals.total)} active`);
console.log(`Uptime: ${chalk.gray(Math.round(status.uptime / 3600))}h`);
}
else {
console.log(chalk.red('Error:'), response.error);
}
}
catch (error) {
console.error(chalk.red('Error:'), error instanceof Error ? error.message : String(error));
}
});
cloudCmd
.command('agents')
.description('List cloud agents from blax.ai')
.option('--json', 'Output in JSON format')
.option('--domain <domain>', 'Filter by domain (coding, accounting, legal)')
.action(async (options) => {
try {
const response = await blaxApi.getAgents();
if (response.success) {
let agents = response.data;
if (options.domain) {
agents = agents.filter(agent => agent.domains.includes(options.domain.toLowerCase()));
}
if (options.json) {
console.log(JSON.stringify(agents, null, 2));
}
else {
console.log(chalk.cyan.bold('Blax.ai Cloud Agents'));
if (agents.length === 0) {
console.log(chalk.gray(' No agents found'));
}
else {
agents.forEach(agent => {
const statusColor = agent.status === 'active' ? 'green' :
agent.status === 'error' ? 'red' : 'yellow';
console.log(` ${chalk[statusColor]('●')} ${chalk.bold(agent.name)}`);
console.log(` Domains: ${chalk.gray(agent.domains.join(', '))}`);
console.log(` Capabilities: ${chalk.gray(agent.capabilities.join(', '))}`);
if (agent.pricing) {
console.log(` Cost: ${chalk.yellow(`$${agent.pricing.costPerToken}/token`)}`);
}
});
}
}
}
else {
console.log(chalk.red('Error:'), response.error);
}
}
catch (error) {
console.error(chalk.red('Error:'), error instanceof Error ? error.message : String(error));
}
});
cloudCmd
.command('execute <agentId> <skill>')
.description('Execute a skill on a cloud agent')
.option('--args <json>', 'Arguments as JSON string')
.option('--json', 'Output in JSON format')
.action(async (agentId, skill, options) => {
try {
let args = {};
if (options.args) {
try {
args = JSON.parse(options.args);
}
catch {
console.error(chalk.red('Error: Invalid JSON in --args'));
return;
}
}
const response = await blaxApi.executeSkill(agentId, skill, args);
if (options.json) {
console.log(JSON.stringify(response, null, 2));
}
else if (response.success) {
console.log(chalk.green('✓ Skill executed successfully'));
console.log(JSON.stringify(response.data, null, 2));
}
else {
console.log(chalk.red('Error:'), response.error);
}
}
catch (error) {
console.error(chalk.red('Error:'), error instanceof Error ? error.message : String(error));
}
});
program
.command('config')
.description('Show Blax configuration')
.action(() => {
console.log(chalk.cyan.bold('Blax Configuration'));
console.log(`API URL: ${chalk.white(blaxConfig.api.baseUrl)}`);
console.log(`Hub URL: ${chalk.white(blaxConfig.api.hubUrl)}`);
console.log(`Docs: ${chalk.white(blaxConfig.domains.docs)}`);
console.log(`Status: ${chalk.white(blaxConfig.domains.status)}`);
console.log(`Offline Mode: ${blaxConfig.features.offlineMode ? chalk.green('enabled') : chalk.gray('disabled')}`);
console.log(`Telemetry: ${blaxConfig.features.telemetry ? chalk.green('enabled') : chalk.gray('disabled')}`);
});
// Demo command
program
.command('demo')
.description('Run interactive demo showcasing Blax v2.0 features')
.option('--quick', 'Run quick 5-minute demo')
.option('--advanced', 'Run full advanced demo with all features')
.option('--auto', 'Run automatically without user interaction')
.action(async (options) => {
try {
const demoType = options.quick ? 'quick' : options.advanced ? 'advanced' : 'full';
const interactive = !options.auto;
console.log(chalk.cyan('🎬 Starting Blax Demo...'));
const demo = new DemoScript({
interactive,
demoType,
skipIntro: false
});
// Handle cleanup on exit
const cleanup = async () => {
console.log(chalk.yellow('\n\n🧹 Cleaning up demo resources...'));
await demo.cleanup();
process.exit(0);
};
process.on('SIGINT', cleanup);
process.on('SIGTERM', cleanup);
await demo.runDemo();
await demo.cleanup();
}
catch (error) {
console.error(chalk.red('Demo error:'), error instanceof Error ? error.message : String(error));
process.exit(1);
}
});
try {
await program.parseAsync(process.argv);
}
catch (error) {
console.error(chalk.red('Command error:'), error);
process.exit(1);
}
}
//# sourceMappingURL=boot.js.map