#!/usr/bin/env node import { Command } from 'commander'; import { statusCommand } from './commands/status.js'; import { doctorCommand } from './commands/doctor.js'; import { menuCommand } from './commands/menu.js'; import { setupCommand } from './commands/setup.js'; import { upCommand } from './commands/up.js'; import { downCommand } from './commands/down.js'; import { logsCommand } from './commands/logs.js'; import { shellCommand } from './commands/shell.js'; import { trustCommand } from './commands/trust.js'; import { containersCommand } from './commands/containers.js'; import { securityCommand } from './commands/security.js'; import { configCommand } from './commands/config-cmd.js'; import { rotateKeyCommand } from './commands/rotate-key.js'; import { loadConfig } from './config.js'; import { setupCloudflareTunnel, setupTailscaleTunnel } from './remote.js'; import * as d from './utils/display.js'; const program = new Command(); program .name('aether-substrate') .description('Bootstrap, run, and expose your Aether Substrate.') .version('1.1.0') .showHelpAfterError() .showSuggestionAfterError(true) .configureHelp({ sortSubcommands: true }); program.addHelpText('after', ` Examples: aether-substrate aether-substrate menu aether-substrate init aether-substrate init --runtime podman aether-substrate doctor aether-substrate rotate-key --restart aether-substrate config --enable embeddings --restart aether-substrate up --cloudflare aether-substrate tunnel cloudflare --hostname substrate.example.com aether-substrate tunnel tailscale Environment: CONTAINER_RUNTIME Override the container CLI (docker, podman, nerdctl). Docker is used by default. SUBSTRATE_API_KEY Shared secret between the frontend and Substrate API. SUBSTRATE_URL Base URL used by status/doctor/containers (default: http://127.0.0.1:3100). `); program .command('menu') .alias('dashboard') .description('Open the persistent interactive navigator') .action(menuCommand); program .command('status') .description('Show service health, local configuration, and remote-access summary') .option('--key ', 'API key') .option('--url ', 'Substrate URL') .action(statusCommand); program .command('doctor') .description('Run readiness checks for the container runtime, env, health, and tunnel tooling') .option('--key ', 'API key') .option('--url ', 'Substrate URL') .option('--runtime ', 'Override the container runtime for this run') .action(doctorCommand); program .command('init') .alias('setup') .description('Interactive bootstrap for env, build, startup, and optional remote access') .option('--env-only', 'Only configure .env') .option('--runtime ', 'Container runtime (docker, podman, nerdctl, or a custom binary)') .option('--tunnel ', 'Set up a tunnel during init (cloudflare, tailscale)') .option('--hostname ', 'Hostname to use for the Cloudflare tunnel') .action(setupCommand); program .command('up') .description('Build and start the Substrate stack') .option('--no-cache', 'Rebuild without cache') .option('--cloudflare', 'Include the Cloudflare compose overlay') .option('--runtime ', 'Override the container runtime for this run') .action(upCommand); program .command('down') .description('Stop the Substrate stack') .option('--cloudflare', 'Include the Cloudflare compose overlay') .action(downCommand); program .command('logs') .description('Stream compose logs') .option('--tail ', 'Number of lines to show', '100') .option('--service ', 'Restrict output to a single compose service') .option('--cloudflare', 'Include the Cloudflare compose overlay') .option('--no-follow', 'Do not follow log output') .action(logsCommand); program .command('shell') .description('Open a shell in the substrate container') .action(shellCommand); program .command('trust') .description('Trust the local Caddy certificate on macOS') .action(trustCommand); program .command('containers') .alias('c') .description('List and manage substrate-managed containers') .option('--key ', 'API key') .option('--url ', 'Substrate URL') .action(containersCommand); program .command('security') .alias('audit') .description('Run security audit checks against a live Substrate') .option('--key ', 'API key') .option('--url ', 'Substrate URL') .action(securityCommand); program .command('rotate-key') .alias('key:rotate') .description('Generate a new SUBSTRATE_API_KEY, update .env, and optionally restart') .option('--bytes ', 'Random byte length before hex encoding (32-128)', '32') .option('--frontend-env ', 'Also update a frontend .env/.env.local file with SUBSTRATE_API_KEY') .option('--restart', 'Restart substrate after writing the new key') .option('--cloudflare', 'Include the Cloudflare compose overlay when restarting') .option('--runtime ', 'Override the container runtime for restart') .option('--show', 'Print the new key once for copying into another secret store') .option('--yes', 'Skip confirmation prompts') .action(rotateKeyCommand); program .command('config') .description('Toggle features and edit substrate settings') .option('--key ', 'API key') .option('--url ', 'Substrate URL') .option('--enable ', 'Enable a feature (containers, workspace, terminal, embeddings)') .option('--disable ', 'Disable a feature') .option('--llm-provider ', 'Set the default LLM provider (ollama, lmstudio, openai-compatible, anthropic, openai, letta)') .option('--llm-model ', 'Set the default model for the selected LLM provider') .option('--llm-base-url ', 'Override the LLM provider base URL') .option('--llm-api-key ', 'Set the LLM API key for hosted providers') .option('--restart', 'Restart substrate to apply changes') .action(configCommand); const tunnel = program .command('tunnel') .description('Set up or inspect remote-access workflows'); tunnel .command('cloudflare') .description('Create or connect a Cloudflare Tunnel and write compose-ready config') .option('--config ', 'Use a specific cloudflared config file') .option('--force', 'Overwrite cloudflared-config.yml if it already exists') .option('--hostname ', 'Hostname to route to the tunnel') .option('--run', 'Run an existing Cloudflare tunnel config in the foreground') .option('--skip-dns', 'Skip `cloudflared tunnel route dns`') .option('--tunnel-name ', 'Cloudflare tunnel name (defaults to a unique name per instance)') .action(async (opts: { config?: string; force?: boolean; hostname?: string; run?: boolean; skipDns?: boolean; tunnelName?: string; }) => { await setupCloudflareTunnel(loadConfig(), opts); }); tunnel .command('tailscale') .description('Use Tailscale host mode and optionally enable `tailscale serve`') .option('--serve', 'Run `tailscale serve https / http://127.0.0.1:3100`') .action(async ( opts: { serve?: boolean }, command: Command, ) => { const specified = command.getOptionValueSource('serve') !== 'default'; await setupTailscaleTunnel(specified ? opts : {}); }); program.action(async () => { if (process.stdout.isTTY) { await menuCommand(); return; } d.banner(); d.line(); await statusCommand({ banner: false }); d.info('Suggested next commands'); d.command('aether-substrate menu'); d.command('aether-substrate init'); d.command('aether-substrate doctor'); d.line(); }); program.parse();