feat(launcher): install the server from a prebuilt archive (P1.3c)
The launcher is now a self-contained installer with install, run, update, doctor and uninstall. Install downloads waggle-server-<version>-<target> .tar.gz, checks its SHA-256, unpacks it into a per-user program directory and writes a waggle-server command that runs the tool on the archive's own Node. Nothing is built on the user's machine and the data directory stays WAGGLE_DATA_DIR or ~/.waggle. scripts/build-server-archive.mjs packs the staged desktop sidecar payload with the built web UI and a manifest. The download location waits for the repository decision; until then install takes --from or WAGGLE_RELEASE_BASE_URL (ADR-0009). Removes install.sh, scripts/waggle-server.sh and their CI job, which the installer replaces, and the bin name clash with @waggle/cli.
This commit is contained in:
@@ -1,117 +1,84 @@
|
||||
/**
|
||||
* Waggle CLI Launcher - `npx waggle`
|
||||
* Waggle server installer and launcher.
|
||||
*
|
||||
* Starts the Waggle server and opens the frontend in the default browser.
|
||||
* npx <package> install download the server for this system and install it
|
||||
* waggle-server start it and open the browser (same as `run`)
|
||||
* waggle-server doctor check the installation
|
||||
* waggle-server update install this tool's version over the installed one
|
||||
* waggle-server uninstall remove the program; the data directory stays
|
||||
*
|
||||
* Usage:
|
||||
* npx waggle # Start on default port 3333
|
||||
* npx waggle --port 4000 # Start on custom port
|
||||
* npx waggle --skip-litellm # Skip LiteLLM proxy
|
||||
* npx waggle --no-open # Do not open browser automatically
|
||||
* The tool is one self-contained script. Install copies it next to the
|
||||
* payload, and the shim runs that copy with the payload's own Node.
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { formatHelp, parseArgs } from './args.js';
|
||||
import { UserError, doctor, install, run, uninstall, type Context } from './commands.js';
|
||||
import { currentHost } from './platform.js';
|
||||
|
||||
import { execFile } from 'node:child_process';
|
||||
import os from 'node:os';
|
||||
import {
|
||||
formatHelp,
|
||||
formatStartupFailure,
|
||||
formatStartupSuccess,
|
||||
parseArgs,
|
||||
} from './cli-core.js';
|
||||
declare const __WAGGLE_SERVER_VERSION__: string | undefined;
|
||||
|
||||
function openBrowser(url: string): void {
|
||||
const platform = os.platform();
|
||||
const onOpenError = (err: Error | null): void => {
|
||||
if (err) console.log(` Open manually: ${url}`);
|
||||
};
|
||||
const VERSION: string = typeof __WAGGLE_SERVER_VERSION__ === 'string'
|
||||
? __WAGGLE_SERVER_VERSION__
|
||||
: (JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')) as { version: string }).version;
|
||||
|
||||
if (platform === 'win32') {
|
||||
execFile('cmd', ['/c', 'start', '', url], onOpenError);
|
||||
} else if (platform === 'darwin') {
|
||||
execFile('open', [url], onOpenError);
|
||||
} else {
|
||||
execFile('xdg-open', [url], onOpenError);
|
||||
}
|
||||
const MIN_NODE_MAJOR = 20;
|
||||
|
||||
/** The bundled script can be copied into an install; a TypeScript source cannot run on its own. */
|
||||
function launcherSource(): string | null {
|
||||
const self = fileURLToPath(import.meta.url);
|
||||
return /\.m?js$/.test(self) ? self : null;
|
||||
}
|
||||
|
||||
function checkNodeVersion(): boolean {
|
||||
const [major] = process.versions.node.split('.').map(Number);
|
||||
if (major < 18) {
|
||||
console.error(`\n Waggle requires Node.js >= 18. You have ${process.versions.node}.`);
|
||||
console.error(' Install a newer version: https://nodejs.org\n');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const { port, skipLiteLLM, noBrowser, help, error } = parseArgs(process.argv);
|
||||
|
||||
if (help) {
|
||||
console.log(formatHelp());
|
||||
process.exit(0);
|
||||
async function main(): Promise<number> {
|
||||
const major = Number(process.versions.node.split('.')[0]);
|
||||
if (major < MIN_NODE_MAJOR) {
|
||||
console.error(`\n Waggle needs Node.js ${MIN_NODE_MAJOR} or newer to install. This is ${process.versions.node}.\n`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const { command, options, error } = parseArgs(process.argv.slice(2));
|
||||
if (error) {
|
||||
console.error();
|
||||
console.error(` ${error}`);
|
||||
console.error(formatHelp());
|
||||
process.exit(1);
|
||||
console.error(`\n ${error}`);
|
||||
console.error(formatHelp(VERSION));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!checkNodeVersion()) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log();
|
||||
console.log(' Waggle - AI Agent Swarm');
|
||||
console.log(' ------------------------');
|
||||
|
||||
const { startService, isFirstRun } = await import('@waggle/server/local/service');
|
||||
const dataDir = process.env.WAGGLE_DATA_DIR || undefined;
|
||||
const displayDataDir = dataDir ?? `${os.homedir()}/.waggle`;
|
||||
const firstRun = isFirstRun(displayDataDir);
|
||||
|
||||
if (firstRun) {
|
||||
console.log(' Welcome! Setting up for the first time...');
|
||||
console.log();
|
||||
}
|
||||
|
||||
try {
|
||||
const { server } = await startService({
|
||||
port,
|
||||
skipLiteLLM,
|
||||
dataDir,
|
||||
onProgress: (event) => {
|
||||
const pct = Math.round(event.progress * 100);
|
||||
process.stdout.write(`\r [${pct.toString().padStart(3)}%] ${event.message}`);
|
||||
if (event.phase === 'ready') {
|
||||
process.stdout.write('\n');
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const addr = server.server.address();
|
||||
const actualPort = typeof addr === 'object' && addr ? addr.port : port;
|
||||
const url = `http://localhost:${actualPort}`;
|
||||
const llm = server.agentState.llmProvider;
|
||||
|
||||
console.log(formatStartupSuccess({
|
||||
url,
|
||||
llmProvider: llm.provider,
|
||||
llmHealth: llm.health,
|
||||
dataDir: displayDataDir,
|
||||
noBrowser,
|
||||
}));
|
||||
|
||||
if (!noBrowser) {
|
||||
openBrowser(url);
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
console.error(formatStartupFailure(message, port));
|
||||
process.exit(1);
|
||||
const ctx: Context = {
|
||||
host: currentHost(),
|
||||
version: VERSION,
|
||||
launcherSource: launcherSource(),
|
||||
out: (line) => console.log(line),
|
||||
};
|
||||
switch (command) {
|
||||
case 'help':
|
||||
console.log(formatHelp(VERSION));
|
||||
return 0;
|
||||
case 'version':
|
||||
console.log(VERSION);
|
||||
return 0;
|
||||
case 'install':
|
||||
await install(ctx, options);
|
||||
return 0;
|
||||
case 'update':
|
||||
await install(ctx, options, 'update');
|
||||
return 0;
|
||||
case 'doctor':
|
||||
return doctor(ctx, options);
|
||||
case 'uninstall':
|
||||
return uninstall(ctx, options);
|
||||
case 'run':
|
||||
return run(ctx, options);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
main().then(
|
||||
(code) => {
|
||||
process.exitCode = code;
|
||||
},
|
||||
(error: unknown) => {
|
||||
console.error(`\n ${error instanceof Error ? error.message : String(error)}\n`);
|
||||
if (!(error instanceof UserError) && error instanceof Error && error.stack) console.error(error.stack);
|
||||
process.exitCode = 1;
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user