@microwiseai/claude-web-server
Version:
Local server for Web Claude Code - Unofficial web interface for Claude Code
204 lines (203 loc) • 7.96 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const auto_launch_1 = __importDefault(require("auto-launch"));
const inquirer_1 = __importDefault(require("inquirer"));
const chalk_1 = __importDefault(require("chalk"));
const child_process_1 = require("child_process");
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
const program = new commander_1.Command();
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
// Auto-launcher instance
const autoLauncher = new auto_launch_1.default({
name: 'Claude Web Server',
path: process.execPath,
arguments: [path.join(__dirname, 'index.js'), '--daemon']
});
program
.name('claude-web-server')
.description('Local server for unofficial Claude Code web interface')
.version(packageJson.version);
// Default command - start server
program
.command('start', { isDefault: true })
.description('Start the Web Claude Code server')
.option('-d, --daemon', 'Run in background (daemon mode)')
.option('-p, --port <port>', 'Port to run server on', '3001')
.action(async (options) => {
if (options.daemon) {
console.log(chalk_1.default.blue('Starting Web Claude Code in daemon mode...'));
// Fork the server process
const serverProcess = (0, child_process_1.spawn)(process.execPath, [
path.join(__dirname, 'index.js'),
'--port', options.port
], {
detached: true,
stdio: 'ignore'
});
serverProcess.unref();
console.log(chalk_1.default.green('✓ Server started in background on port ' + options.port));
console.log(chalk_1.default.gray('Visit https://claude.microwiseai.com to use Claude Web Interface'));
process.exit(0);
}
else {
console.log(chalk_1.default.blue('Starting Web Claude Code...'));
console.log(chalk_1.default.gray('Press Ctrl+C to stop'));
// Run server in foreground
require('./index');
}
});
// Stop command
program
.command('stop')
.description('Stop the Web Claude Code daemon')
.action(async () => {
// Find and kill the daemon process
// This is a simplified version - in production, you'd want to use a PID file
console.log(chalk_1.default.yellow('Stopping Web Claude Code daemon...'));
try {
if (process.platform === 'win32') {
(0, child_process_1.spawn)('taskkill', ['/F', '/IM', 'node.exe', '/FI', 'WINDOWTITLE eq Web Claude Code']);
}
else {
(0, child_process_1.spawn)('pkill', ['-f', 'web-claude-code.*--daemon']);
}
console.log(chalk_1.default.green('✓ Daemon stopped'));
}
catch (error) {
console.log(chalk_1.default.red('Failed to stop daemon:', error));
}
});
// Auto-start management
program
.command('autostart')
.description('Manage auto-start settings')
.option('--enable', 'Enable auto-start on system boot')
.option('--disable', 'Disable auto-start')
.option('--status', 'Check auto-start status')
.action(async (options) => {
if (options.enable) {
try {
await autoLauncher.enable();
console.log(chalk_1.default.green('✓ Auto-start enabled'));
console.log(chalk_1.default.gray('Web Claude Code will start automatically on system boot'));
}
catch (error) {
console.log(chalk_1.default.red('Failed to enable auto-start:', error));
}
}
else if (options.disable) {
try {
await autoLauncher.disable();
console.log(chalk_1.default.green('✓ Auto-start disabled'));
}
catch (error) {
console.log(chalk_1.default.red('Failed to disable auto-start:', error));
}
}
else if (options.status) {
try {
const isEnabled = await autoLauncher.isEnabled();
if (isEnabled) {
console.log(chalk_1.default.green('Auto-start is enabled'));
}
else {
console.log(chalk_1.default.yellow('Auto-start is disabled'));
}
}
catch (error) {
console.log(chalk_1.default.red('Failed to check auto-start status:', error));
}
}
else {
// Interactive mode
const isEnabled = await autoLauncher.isEnabled();
const { action } = await inquirer_1.default.prompt([
{
type: 'list',
name: 'action',
message: `Auto-start is currently ${isEnabled ? 'enabled' : 'disabled'}. What would you like to do?`,
choices: [
{ name: isEnabled ? 'Disable auto-start' : 'Enable auto-start', value: isEnabled ? 'disable' : 'enable' },
{ name: 'Cancel', value: 'cancel' }
]
}
]);
if (action === 'enable') {
await autoLauncher.enable();
console.log(chalk_1.default.green('✓ Auto-start enabled'));
}
else if (action === 'disable') {
await autoLauncher.disable();
console.log(chalk_1.default.green('✓ Auto-start disabled'));
}
}
});
// Status command
program
.command('status')
.description('Check server status')
.action(async () => {
try {
const response = await fetch('http://localhost:3001/health');
if (response.ok) {
const data = await response.json();
console.log(chalk_1.default.green('✓ Server is running'));
console.log(chalk_1.default.gray('Started at:', new Date(data.timestamp).toLocaleString()));
}
}
catch (error) {
console.log(chalk_1.default.yellow('Server is not running'));
console.log(chalk_1.default.gray('Run "web-claude-code start" to start the server'));
}
});
// Open command
program
.command('open')
.description('Open Web Claude Code in browser')
.action(async () => {
const url = 'http://localhost:3001';
const start = process.platform === 'darwin' ? 'open' :
process.platform === 'win32' ? 'start' : 'xdg-open';
(0, child_process_1.spawn)(start, [url], { detached: true, stdio: 'ignore' });
console.log(chalk_1.default.blue('Opening Web Claude Code in browser...'));
});
program.parse();