create-agentwise
Version:
š Interactive installer for Agentwise - AI multi-agent development platform that transforms project creation through intelligent automation
333 lines (319 loc) ⢠12.9 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const prompts_1 = require("@clack/prompts");
const chalk_1 = __importDefault(require("chalk"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const os_1 = __importDefault(require("os"));
const child_process_1 = require("child_process");
const simple_git_1 = __importDefault(require("simple-git"));
class AgentwiseInstaller {
homeDir = os_1.default.homedir();
defaultPath = path_1.default.join(this.homeDir, 'agentwise');
async main() {
console.clear();
(0, prompts_1.intro)(chalk_1.default.bgBlue.white(' Agentwise Installer v2.3.0 '));
(0, prompts_1.note)(`š Welcome to Agentwise - AI Multi-Agent Development Platform
š This installer will:
⢠Check for existing installation
⢠Allow you to choose installation location
⢠Download and setup Agentwise
⢠Configure your development environment
š Security: All actions are transparent and require your confirmation`, 'What this installer does');
try {
const options = await this.gatherOptions();
if (!options)
return;
if (options.action === 'install') {
await this.performInstallation(options);
}
else {
await this.performUpdate(options);
}
(0, prompts_1.outro)(chalk_1.default.green('ā
Agentwise setup completed successfully!'));
this.showNextSteps(options);
}
catch (error) {
(0, prompts_1.cancel)('Installation failed: ' + error.message);
process.exit(1);
}
}
async gatherOptions() {
// Check for existing installation
const existingInstallation = await this.findExistingInstallation();
if (existingInstallation) {
(0, prompts_1.note)(`Found existing Agentwise installation at:
${chalk_1.default.cyan(existingInstallation)}`, 'Existing Installation Detected');
const action = await (0, prompts_1.select)({
message: 'What would you like to do?',
options: [
{ value: 'update', label: 'Update existing installation' },
{ value: 'install', label: 'Install in a different location' },
{ value: 'cancel', label: 'Cancel installation' }
]
});
if ((0, prompts_1.isCancel)(action) || action === 'cancel') {
(0, prompts_1.cancel)('Installation cancelled');
return null;
}
if (action === 'update') {
return {
action: 'update',
installPath: existingInstallation,
existingPath: existingInstallation
};
}
}
// Get installation path
const pathChoice = await (0, prompts_1.select)({
message: 'Where would you like to install Agentwise?',
options: [
{
value: 'default',
label: `Default location (${this.defaultPath})`,
hint: 'Recommended'
},
{
value: 'custom',
label: 'Custom location',
hint: 'You choose the path'
}
]
});
if ((0, prompts_1.isCancel)(pathChoice)) {
(0, prompts_1.cancel)('Installation cancelled');
return null;
}
let installPath = this.defaultPath;
if (pathChoice === 'custom') {
const customPath = await (0, prompts_1.text)({
message: 'Enter the full path where you want to install Agentwise:',
placeholder: '/path/to/agentwise',
validate: (value) => {
if (!value)
return 'Path is required';
if (!path_1.default.isAbsolute(value))
return 'Please provide an absolute path';
return undefined;
}
});
if ((0, prompts_1.isCancel)(customPath)) {
(0, prompts_1.cancel)('Installation cancelled');
return null;
}
installPath = customPath;
}
// Confirm installation
const confirmed = await (0, prompts_1.confirm)({
message: `Install Agentwise to: ${chalk_1.default.cyan(installPath)}?`
});
if ((0, prompts_1.isCancel)(confirmed) || !confirmed) {
(0, prompts_1.cancel)('Installation cancelled');
return null;
}
return {
action: 'install',
installPath
};
}
async findExistingInstallation() {
const commonPaths = [
this.defaultPath,
path_1.default.join(this.homeDir, 'Documents', 'agentwise'),
path_1.default.join(this.homeDir, 'Desktop', 'agentwise'),
path_1.default.join(process.cwd(), 'agentwise')
];
for (const checkPath of commonPaths) {
if (await this.isAgentwiseDirectory(checkPath)) {
return checkPath;
}
}
return null;
}
async isAgentwiseDirectory(dirPath) {
try {
if (!await fs_extra_1.default.pathExists(dirPath))
return false;
const packageJsonPath = path_1.default.join(dirPath, 'package.json');
if (!await fs_extra_1.default.pathExists(packageJsonPath))
return false;
const packageJson = await fs_extra_1.default.readJson(packageJsonPath);
return packageJson.name === 'agentwise';
}
catch {
return false;
}
}
async performInstallation(options) {
const s = (0, prompts_1.spinner)();
try {
// Check Node.js version
s.start('Checking system requirements...');
await this.checkNodeVersion();
s.stop('ā
System requirements met');
// Create directory
s.start(`Creating directory: ${options.installPath}`);
await fs_extra_1.default.ensureDir(options.installPath);
s.stop('ā
Directory created');
// Clone repository
s.start('Downloading Agentwise from GitHub...');
const git = (0, simple_git_1.default)();
await git.clone('https://github.com/VibeCodingWithPhil/agentwise.git', options.installPath, ['--depth', '1']);
s.stop('ā
Repository cloned');
// Install dependencies
s.start('Installing dependencies... (this may take a few minutes)');
process.chdir(options.installPath);
(0, child_process_1.execSync)('npm install --legacy-peer-deps', {
stdio: 'pipe',
cwd: options.installPath
});
s.stop('ā
Dependencies installed');
// Setup environment
s.start('Setting up environment...');
await this.setupEnvironment(options.installPath);
s.stop('ā
Environment configured');
// Create start script
s.start('Creating startup scripts...');
await this.createStartupScripts(options.installPath);
s.stop('ā
Startup scripts created');
}
catch (error) {
s.stop('ā Installation failed');
throw error;
}
}
async performUpdate(options) {
const s = (0, prompts_1.spinner)();
try {
s.start('Backing up workspace...');
await this.backupWorkspace(options.installPath);
s.stop('ā
Workspace backed up');
s.start('Updating from GitHub...');
const git = (0, simple_git_1.default)(options.installPath);
await git.stash();
await git.pull('origin', 'main');
s.stop('ā
Code updated');
s.start('Updating dependencies...');
(0, child_process_1.execSync)('npm install --legacy-peer-deps', {
stdio: 'pipe',
cwd: options.installPath
});
s.stop('ā
Dependencies updated');
}
catch (error) {
s.stop('ā Update failed');
throw error;
}
}
async checkNodeVersion() {
const nodeVersion = process.version;
const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]);
if (majorVersion < 18) {
throw new Error(`Node.js 18+ required. Current: ${nodeVersion}. Please upgrade at https://nodejs.org/`);
}
}
async setupEnvironment(installPath) {
const envPath = path_1.default.join(installPath, '.env');
if (!await fs_extra_1.default.pathExists(envPath)) {
const envContent = `# Agentwise Configuration
NODE_ENV=production
PORT=3001
# Optional: Add your API keys here
# OPENAI_API_KEY=your_key_here
# GITHUB_TOKEN=your_token_here
# ANTHROPIC_API_KEY=your_key_here
`;
await fs_extra_1.default.writeFile(envPath, envContent);
}
// Create necessary directories
const dirs = ['workspace', '.claude/agents', '.claude/commands', 'logs', 'backups'];
for (const dir of dirs) {
await fs_extra_1.default.ensureDir(path_1.default.join(installPath, dir));
}
}
async createStartupScripts(installPath) {
// Cross-platform start script (JavaScript)
const startScript = `#!/usr/bin/env node
const path = require('path')
const { spawn } = require('child_process')
console.log('š Starting Agentwise...')
// Find entry point
const entryPoints = [
path.join(__dirname, 'dist', 'index.js'),
path.join(__dirname, 'src', 'index.js'),
path.join(__dirname, 'index.js')
]
let entryPoint = null
for (const point of entryPoints) {
if (require('fs').existsSync(point)) {
entryPoint = point
break
}
}
if (!entryPoint) {
console.error('ā Could not find entry point. Please check installation.')
process.exit(1)
}
// Start the application
const child = spawn('node', [entryPoint], {
stdio: 'inherit',
cwd: __dirname
})
child.on('close', (code) => {
console.log(\`Agentwise exited with code \${code}\`)
})`;
await fs_extra_1.default.writeFile(path_1.default.join(installPath, 'start.js'), startScript);
// Make executable on Unix systems
if (process.platform !== 'win32') {
await fs_extra_1.default.chmod(path_1.default.join(installPath, 'start.js'), '755');
}
// Create platform-specific shortcuts
if (process.platform === 'win32') {
// Windows batch file
const batScript = `@echo off
cd /d "%~dp0"
node start.js
pause`;
await fs_extra_1.default.writeFile(path_1.default.join(installPath, 'start-agentwise.bat'), batScript);
}
else {
// Unix shell script
const shellScript = `#!/bin/bash
cd "$(dirname "$0")"
node start.js`;
await fs_extra_1.default.writeFile(path_1.default.join(installPath, 'start-agentwise.sh'), shellScript);
await fs_extra_1.default.chmod(path_1.default.join(installPath, 'start-agentwise.sh'), '755');
}
}
async backupWorkspace(installPath) {
const workspacePath = path_1.default.join(installPath, 'workspace');
const backupPath = path_1.default.join(installPath, 'backups', `workspace-backup-${Date.now()}`);
if (await fs_extra_1.default.pathExists(workspacePath)) {
await fs_extra_1.default.copy(workspacePath, backupPath);
}
}
showNextSteps(options) {
const platform = process.platform;
const startCommand = platform === 'win32'
? 'start-agentwise.bat'
: './start-agentwise.sh';
(0, prompts_1.note)(`To start Agentwise:
${chalk_1.default.cyan(`cd ${options.installPath}`)}
${chalk_1.default.cyan(platform === 'win32' ? 'start-agentwise.bat' : 'node start.js')}
Or double-click: ${chalk_1.default.yellow(startCommand)}
For Claude Code integration:
${chalk_1.default.cyan('Open Claude Code and run: /setup-mcps')}
Documentation: ${chalk_1.default.blue('https://agentwise-docs.vercel.app')}
GitHub: ${chalk_1.default.blue('https://github.com/VibeCodingWithPhil/agentwise')}`, 'Next Steps');
}
}
// Run the installer
const installer = new AgentwiseInstaller();
installer.main().catch((error) => {
console.error(chalk_1.default.red('Installation failed:'), error.message);
process.exit(1);
});
;