Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229import { input, select } from '@inquirer/prompts';import { loadConfig } from '../config.js';import { getCloudflareSummary, getTailscaleSummary, importCloudflareConfig, runCloudflareTunnel, setupCloudflareTunnel, setupTailscaleTunnel } from '../remote.js';import { statusCommand } from './status.js';import { doctorCommand } from './doctor.js';import { setupCommand } from './setup.js';import { upCommand } from './up.js';import { downCommand } from './down.js';import { logsCommand } from './logs.js';import { shellCommand } from './shell.js';import { containersCommand } from './containers.js';import { securityCommand } from './security.js';import { configCommand } from './config-cmd.js';import { rotateKeyCommand } from './rotate-key.js';import * as d from '../utils/display.js';
export async function menuCommand(): Promise<void> { let exit = false;
while (!exit) { renderMenuHome();
const action = await select({ message: 'Choose an area', pageSize: 12, choices: [ { name: 'Overview', value: 'overview', description: 'Detailed runtime and remote-access status' }, { name: 'Init / Setup', value: 'init', description: 'Bootstrap env, start the stack, and configure tunnels' }, { name: 'Doctor', value: 'doctor', description: 'Run readiness checks' }, { name: 'Stack', value: 'stack', description: 'Start, stop, inspect logs, and shell into substrate' }, { name: 'Remote Access', value: 'remote', description: 'Cloudflare and Tailscale workflows' }, { name: 'Containers', value: 'containers', description: 'Inspect substrate-managed containers' }, { name: 'Security', value: 'security', description: 'Run the security audit' }, { name: 'Rotate API Key', value: 'rotate-key', description: 'Generate a new substrate shared secret' }, { name: 'Config', value: 'config', description: 'Toggle features and edit settings' }, { name: 'Exit', value: 'exit', description: 'Leave the interactive CLI' }, ], });
console.clear();
switch (action) { case 'overview': await statusCommand({ banner: true }); await pause(); break; case 'init': await setupCommand({}); await pause(); break; case 'doctor': await doctorCommand({}); await pause(); break; case 'stack': await stackMenu(); break; case 'remote': await remoteMenu(); break; case 'containers': await containersCommand({}); await pause(); break; case 'security': await securityCommand({}); await pause(); break; case 'rotate-key': await rotateKeyCommand({}); await pause(); break; case 'config': await configCommand({}); await pause(); break; case 'exit': exit = true; break; } }}
async function stackMenu(): Promise<void> { let back = false;
while (!back) { console.clear(); d.banner(); d.line(); d.header('Stack');
const action = await select({ message: 'Stack controls', pageSize: 10, choices: [ { name: 'Status', value: 'status' }, { name: 'Start stack', value: 'up' }, { name: 'Start stack + Cloudflare overlay', value: 'up-cloudflare' }, { name: 'Stop stack', value: 'down' }, { name: 'Show recent logs', value: 'logs' }, { name: 'Show Cloudflare logs', value: 'logs-cloudflare' }, { name: 'Shell into substrate', value: 'shell' }, { name: 'Back', value: 'back' }, ], });
console.clear();
switch (action) { case 'status': await statusCommand({ banner: true }); await pause(); break; case 'up': await upCommand({}); await pause(); break; case 'up-cloudflare': await upCommand({ cloudflare: true }); await pause(); break; case 'down': await downCommand({}); await pause(); break; case 'logs': await logsCommand({ follow: false, tail: '150' }); await pause(); break; case 'logs-cloudflare': await logsCommand({ cloudflare: true, follow: false, service: 'cloudflared', tail: '150' }); await pause(); break; case 'shell': await shellCommand(); break; case 'back': back = true; break; } }}
async function remoteMenu(): Promise<void> { let back = false;
while (!back) { console.clear(); d.banner(); d.line(); d.header('Remote Access');
const cloudflare = getCloudflareSummary(loadConfig()); const tailscale = getTailscaleSummary();
d.label('Cloudflare', cloudflare.configExists ? `${cloudflare.hostname || 'configured'}${cloudflare.running ? ' (running)' : ''}` : 'not configured'); if (cloudflare.configPath) d.label('CF Config', cloudflare.configPath); d.label('Tailscale', tailscale.connected ? (tailscale.serveHttpsUrl || tailscale.ip) : 'not connected'); d.line();
const action = await select({ message: 'Remote-access actions', pageSize: 12, choices: [ { name: 'Cloudflare: configure or attach', value: 'cf-setup' }, { name: 'Cloudflare: run existing config', value: 'cf-run' }, { name: 'Cloudflare: import home config into repo', value: 'cf-import' }, { name: 'Tailscale: configure host mode', value: 'ts-setup' }, { name: 'Back', value: 'back' }, ], });
console.clear();
switch (action) { case 'cf-setup': await setupCloudflareTunnel(loadConfig(), {}); await pause(); break; case 'cf-run': try { runCloudflareTunnel(loadConfig()); } catch (error: any) { d.error(error.message); await pause(); } break; case 'cf-import': try { importCloudflareConfig(loadConfig(), { force: true }); } catch (error: any) { d.error(error.message); } await pause(); break; case 'ts-setup': await setupTailscaleTunnel({}); await pause(); break; case 'back': back = true; break; } }}
function renderMenuHome(): void { console.clear(); d.banner(); d.line(); d.header('Navigator');
const config = loadConfig(); const cloudflare = getCloudflareSummary(config); const tailscale = getTailscaleSummary();
d.label('Substrate', config.apiUrl); d.label('Cloudflare', cloudflare.configExists ? (cloudflare.hostname || 'configured') : 'not configured'); d.label('Tailscale', tailscale.connected ? (tailscale.serveHttpsUrl || tailscale.ip) : 'not connected'); d.line(); d.info('Use arrow keys to move, enter to open, and stay in the CLI until you choose Exit.'); d.line();}
async function pause(): Promise<void> { await input({ message: 'Press enter to continue' });}