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.
234 lines (192 loc) ⢠7.2 kB
JavaScript
#!/usr/bin/env node
/**
* Post-install script for TLNT package
* Handles setup for both global and local installations with demo prompt
*/
import { execSync } from 'child_process';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { createInterface } from 'readline';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// ANSI color codes
const colors = {
cyan: '\x1b[36m',
green: '\x1b[32m',
yellow: '\x1b[33m',
red: '\x1b[31m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
bold: '\x1b[1m',
reset: '\x1b[0m',
dim: '\x1b[2m'
};
function log(message, color = '') {
console.log(`${color}${message}${colors.reset}`);
}
function isGlobalInstall() {
// Check if we're in a global node_modules
const currentPath = process.cwd();
return currentPath.includes('/lib/node_modules/') ||
currentPath.includes('\\lib\\node_modules\\') ||
process.env.npm_config_global === 'true';
}
function createLocalAlias() {
const packageRoot = join(__dirname, '..');
const binPath = join(packageRoot, 'bin', 'tlnt.js');
if (!existsSync(binPath)) {
log('ā ļø Binary file not found, skipping alias creation', colors.yellow);
return;
}
// Create a wrapper script for local usage
const wrapperScript = `#!/usr/bin/env node
// Auto-generated wrapper for local tlnt installation
const { spawn } = require('child_process');
const path = require('path');
const binPath = path.join(__dirname, '..', 'bin', 'tlnt.js');
const child = spawn('node', [binPath, ...process.argv.slice(2)], {
stdio: 'inherit',
shell: false
});
child.on('exit', (code) => {
process.exit(code);
});
`;
const wrapperPath = join(packageRoot, 'tlnt.js');
writeFileSync(wrapperPath, wrapperScript);
log('ā
Created local tlnt wrapper', colors.green);
return wrapperPath;
}
function showInstallationGuide() {
log('\n' + '='.repeat(60), colors.cyan);
log('š TLNT INSTALLATION COMPLETE!', colors.bold + colors.cyan);
log('='.repeat(60), colors.cyan);
log('\nš Welcome to TLNT - Your Self-Optimizing AI Agent!', colors.bold + colors.magenta);
log('TLNT adapts and learns from every interaction to serve you better.', colors.dim);
if (isGlobalInstall()) {
log('\nā
Global installation detected', colors.green);
log('You can now use tlnt from anywhere:', colors.dim);
log(' tlnt demo', colors.cyan);
log(' tlnt ask "Help me with coding"', colors.cyan);
log(' tlnt system start', colors.cyan);
log(' tlnt --help', colors.cyan);
} else {
log('\nš¦ Local installation detected', colors.yellow);
log('Use one of these methods to run tlnt:\n', colors.dim);
log('š Method 1 - Use npx (recommended):', colors.bold);
log(' npx tlnt demo', colors.cyan);
log(' npx tlnt ask "Help me with accounting"', colors.cyan);
log(' npx tlnt system start', colors.cyan);
log(' npx tlnt --help', colors.cyan);
log('\nā” Method 2 - Use npm/pnpm scripts:', colors.bold);
log(' npm run tlnt demo', colors.cyan);
log(' pnpm tlnt demo', colors.cyan);
log('\nš§ Method 3 - Add to package.json scripts:', colors.bold);
log(' "scripts": { "tlnt": "tlnt" }', colors.dim);
log(' then: npm run tlnt demo', colors.cyan);
log('\nš” Method 4 - Global install for direct access:', colors.bold);
log(' npm install -g tlnt@latest', colors.cyan);
log(' then: tlnt demo', colors.cyan);
}
log('\nš¬ Quick Start:', colors.bold + colors.green);
if (isGlobalInstall()) {
log(' tlnt demo --quick', colors.cyan);
} else {
log(' npx tlnt demo --quick', colors.cyan);
}
log('\nš Documentation: https://docs.hms-dev.com', colors.dim);
log('š Issues: https://github.com/HMS-OPM/tlnt/issues', colors.dim);
log('\n' + '='.repeat(60), colors.cyan);
}
function updatePackageJson() {
try {
const packageJsonPath = join(process.cwd(), 'package.json');
if (existsSync(packageJsonPath)) {
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
// Add tlnt script if it doesn't exist
if (!packageJson.scripts) {
packageJson.scripts = {};
}
if (!packageJson.scripts.tlnt) {
packageJson.scripts.tlnt = 'tlnt';
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
log('ā
Added "tlnt" script to package.json', colors.green);
}
}
} catch (error) {
// Silent fail - not critical
}
}
async function promptForDemo() {
return new Promise((resolve) => {
// Check if we're in a CI environment or non-interactive terminal
if (process.env.CI || process.env.NODE_ENV === 'production' || !process.stdin.isTTY) {
resolve(false);
return;
}
const rl = createInterface({
input: process.stdin,
output: process.stdout
});
log('\nš Would you like to see a quick demo of TLNT\'s capabilities?', colors.bold + colors.blue);
log(' This will show you multi-domain AI collaboration in action!', colors.dim);
rl.question('\nRun demo now? (Y/n): ', (answer) => {
rl.close();
const shouldDemo = !answer || answer.toLowerCase().startsWith('y');
resolve(shouldDemo);
});
});
}
async function runDemo() {
try {
log('\nš¬ Starting TLNT Demo...', colors.cyan);
const packageRoot = join(__dirname, '..');
const command = isGlobalInstall() ? 'tlnt' : 'npx tlnt';
if (isGlobalInstall()) {
execSync('tlnt demo --quick --auto', { stdio: 'inherit' });
} else {
// For local installation, use node directly
const binPath = join(packageRoot, 'bin', 'tlnt.js');
execSync(`node "${binPath}" demo --quick --auto`, { stdio: 'inherit' });
}
} catch (error) {
log('\nā ļø Demo encountered an issue, but TLNT is ready to use!', colors.yellow);
log('Try running the demo manually:', colors.dim);
if (isGlobalInstall()) {
log(' tlnt demo --quick', colors.cyan);
} else {
log(' npx tlnt demo --quick', colors.cyan);
}
}
}
// Main execution
async function main() {
try {
log('\nš§ Setting up TLNT...', colors.cyan);
if (!isGlobalInstall()) {
createLocalAlias();
updatePackageJson();
}
showInstallationGuide();
// Prompt for demo
const shouldRunDemo = await promptForDemo();
if (shouldRunDemo) {
await runDemo();
log('\n⨠Demo complete! TLNT is ready for your projects.', colors.green);
} else {
log('\nš Demo skipped. You can run it anytime with:', colors.blue);
if (isGlobalInstall()) {
log(' tlnt demo', colors.cyan);
} else {
log(' npx tlnt demo', colors.cyan);
}
}
log('\nš Happy coding with TLNT! š\n', colors.bold + colors.magenta);
} catch (error) {
log('\nā Setup encountered an issue:', colors.red);
log(error.message, colors.dim);
log('\nYou can still use tlnt with: npx tlnt', colors.yellow);
}
}
main().catch(console.error);