feat: flatten node CLI commands
This commit is contained in:
@@ -47,10 +47,7 @@ type NodeDaemonStatusOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function renderNodeServiceStartHints(): string[] {
|
function renderNodeServiceStartHints(): string[] {
|
||||||
const base = [
|
const base = [formatCliCommand("clawdbot node install"), formatCliCommand("clawdbot node start")];
|
||||||
formatCliCommand("clawdbot node service install"),
|
|
||||||
formatCliCommand("clawdbot node start"),
|
|
||||||
];
|
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case "darwin":
|
case "darwin":
|
||||||
return [
|
return [
|
||||||
@@ -172,9 +169,7 @@ export async function runNodeDaemonInstall(opts: NodeDaemonInstallOptions) {
|
|||||||
});
|
});
|
||||||
if (!json) {
|
if (!json) {
|
||||||
defaultRuntime.log(`Node service already ${service.loadedText}.`);
|
defaultRuntime.log(`Node service already ${service.loadedText}.`);
|
||||||
defaultRuntime.log(
|
defaultRuntime.log(`Reinstall with: ${formatCliCommand("clawdbot node install --force")}`);
|
||||||
`Reinstall with: ${formatCliCommand("clawdbot node service install --force")}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ export function registerNodeCli(program: Command) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
node
|
node
|
||||||
.command("start")
|
.command("run")
|
||||||
.description("Start the headless node host (foreground)")
|
.description("Run the headless node host (foreground)")
|
||||||
.option("--host <host>", "Gateway host")
|
.option("--host <host>", "Gateway host")
|
||||||
.option("--port <port>", "Gateway port")
|
.option("--port <port>", "Gateway port")
|
||||||
.option("--tls", "Use TLS for the gateway connection", false)
|
.option("--tls", "Use TLS for the gateway connection", false)
|
||||||
.option("--tls-fingerprint <sha256>", "Expected TLS certificate fingerprint (sha256)")
|
.option("--tls-fingerprint <sha256>", "Expected TLS certificate fingerprint (sha256)")
|
||||||
.option("--node-id <id>", "Override node id")
|
.option("--node-id <id>", "Override node id (clears pairing token)")
|
||||||
.option("--display-name <name>", "Override node display name")
|
.option("--display-name <name>", "Override node display name")
|
||||||
.action(async (opts) => {
|
.action(async (opts) => {
|
||||||
const existing = await loadNodeHostConfig();
|
const existing = await loadNodeHostConfig();
|
||||||
@@ -51,71 +51,51 @@ export function registerNodeCli(program: Command) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const registerNodeServiceCommands = (cmd: Command) => {
|
node
|
||||||
cmd
|
.command("status")
|
||||||
.command("status")
|
.description("Show node host status")
|
||||||
.description("Show node service status")
|
.option("--json", "Output JSON", false)
|
||||||
.option("--json", "Output JSON", false)
|
.action(async (opts) => {
|
||||||
.action(async (opts) => {
|
await runNodeDaemonStatus(opts);
|
||||||
await runNodeDaemonStatus(opts);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
cmd
|
node
|
||||||
.command("install")
|
.command("install")
|
||||||
.description("Install the node service (launchd/systemd/schtasks)")
|
.description("Install the node host service (launchd/systemd/schtasks)")
|
||||||
.option("--host <host>", "Gateway host")
|
.option("--host <host>", "Gateway host")
|
||||||
.option("--port <port>", "Gateway port")
|
.option("--port <port>", "Gateway port")
|
||||||
.option("--tls", "Use TLS for the gateway connection", false)
|
.option("--tls", "Use TLS for the gateway connection", false)
|
||||||
.option("--tls-fingerprint <sha256>", "Expected TLS certificate fingerprint (sha256)")
|
.option("--tls-fingerprint <sha256>", "Expected TLS certificate fingerprint (sha256)")
|
||||||
.option("--node-id <id>", "Override node id")
|
.option("--node-id <id>", "Override node id (clears pairing token)")
|
||||||
.option("--display-name <name>", "Override node display name")
|
.option("--display-name <name>", "Override node display name")
|
||||||
.option("--runtime <runtime>", "Service runtime (node|bun). Default: node")
|
.option("--runtime <runtime>", "Service runtime (node|bun). Default: node")
|
||||||
.option("--force", "Reinstall/overwrite if already installed", false)
|
.option("--force", "Reinstall/overwrite if already installed", false)
|
||||||
.option("--json", "Output JSON", false)
|
.option("--json", "Output JSON", false)
|
||||||
.action(async (opts) => {
|
.action(async (opts) => {
|
||||||
await runNodeDaemonInstall(opts);
|
await runNodeDaemonInstall(opts);
|
||||||
});
|
});
|
||||||
|
|
||||||
cmd
|
node
|
||||||
.command("uninstall")
|
.command("uninstall")
|
||||||
.description("Uninstall the node service (launchd/systemd/schtasks)")
|
.description("Uninstall the node host service (launchd/systemd/schtasks)")
|
||||||
.option("--json", "Output JSON", false)
|
.option("--json", "Output JSON", false)
|
||||||
.action(async (opts) => {
|
.action(async (opts) => {
|
||||||
await runNodeDaemonUninstall(opts);
|
await runNodeDaemonUninstall(opts);
|
||||||
});
|
});
|
||||||
|
|
||||||
cmd
|
node
|
||||||
.command("start")
|
.command("stop")
|
||||||
.description("Start the node service (launchd/systemd/schtasks)")
|
.description("Stop the node host service (launchd/systemd/schtasks)")
|
||||||
.option("--json", "Output JSON", false)
|
.option("--json", "Output JSON", false)
|
||||||
.action(async (opts) => {
|
.action(async (opts) => {
|
||||||
await runNodeDaemonStart(opts);
|
await runNodeDaemonStop(opts);
|
||||||
});
|
});
|
||||||
|
|
||||||
cmd
|
node
|
||||||
.command("stop")
|
.command("restart")
|
||||||
.description("Stop the node service (launchd/systemd/schtasks)")
|
.description("Restart the node host service (launchd/systemd/schtasks)")
|
||||||
.option("--json", "Output JSON", false)
|
.option("--json", "Output JSON", false)
|
||||||
.action(async (opts) => {
|
.action(async (opts) => {
|
||||||
await runNodeDaemonStop(opts);
|
await runNodeDaemonRestart(opts);
|
||||||
});
|
});
|
||||||
|
|
||||||
cmd
|
|
||||||
.command("restart")
|
|
||||||
.description("Restart the node service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runNodeDaemonRestart(opts);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const service = node
|
|
||||||
.command("service")
|
|
||||||
.description("Manage the headless node service (launchd/systemd/schtasks)");
|
|
||||||
registerNodeServiceCommands(service);
|
|
||||||
|
|
||||||
const daemon = node
|
|
||||||
.command("daemon", { hidden: true })
|
|
||||||
.description("Legacy alias for node service commands");
|
|
||||||
registerNodeServiceCommands(daemon);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,14 +52,6 @@ const entries: SubCliEntry[] = [
|
|||||||
mod.registerGatewayCli(program);
|
mod.registerGatewayCli(program);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "service",
|
|
||||||
description: "Service helpers",
|
|
||||||
register: async (program) => {
|
|
||||||
const mod = await import("../service-cli.js");
|
|
||||||
mod.registerServiceCli(program);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "logs",
|
name: "logs",
|
||||||
description: "Gateway logs",
|
description: "Gateway logs",
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
import { Command } from "commander";
|
|
||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
|
|
||||||
const runDaemonStatus = vi.fn(async () => {});
|
|
||||||
const runNodeDaemonStatus = vi.fn(async () => {});
|
|
||||||
|
|
||||||
vi.mock("./daemon-cli/runners.js", () => ({
|
|
||||||
runDaemonInstall: vi.fn(async () => {}),
|
|
||||||
runDaemonRestart: vi.fn(async () => {}),
|
|
||||||
runDaemonStart: vi.fn(async () => {}),
|
|
||||||
runDaemonStatus: (opts: unknown) => runDaemonStatus(opts),
|
|
||||||
runDaemonStop: vi.fn(async () => {}),
|
|
||||||
runDaemonUninstall: vi.fn(async () => {}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("./node-cli/daemon.js", () => ({
|
|
||||||
runNodeDaemonInstall: vi.fn(async () => {}),
|
|
||||||
runNodeDaemonRestart: vi.fn(async () => {}),
|
|
||||||
runNodeDaemonStart: vi.fn(async () => {}),
|
|
||||||
runNodeDaemonStatus: (opts: unknown) => runNodeDaemonStatus(opts),
|
|
||||||
runNodeDaemonStop: vi.fn(async () => {}),
|
|
||||||
runNodeDaemonUninstall: vi.fn(async () => {}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("./deps.js", () => ({
|
|
||||||
createDefaultDeps: vi.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("service CLI coverage", () => {
|
|
||||||
it("routes service gateway status to daemon status", async () => {
|
|
||||||
runDaemonStatus.mockClear();
|
|
||||||
runNodeDaemonStatus.mockClear();
|
|
||||||
|
|
||||||
const { registerServiceCli } = await import("./service-cli.js");
|
|
||||||
const program = new Command();
|
|
||||||
program.exitOverride();
|
|
||||||
registerServiceCli(program);
|
|
||||||
|
|
||||||
await program.parseAsync(["service", "gateway", "status"], { from: "user" });
|
|
||||||
|
|
||||||
expect(runDaemonStatus).toHaveBeenCalledTimes(1);
|
|
||||||
expect(runNodeDaemonStatus).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("routes service node status to node daemon status", async () => {
|
|
||||||
runDaemonStatus.mockClear();
|
|
||||||
runNodeDaemonStatus.mockClear();
|
|
||||||
|
|
||||||
const { registerServiceCli } = await import("./service-cli.js");
|
|
||||||
const program = new Command();
|
|
||||||
program.exitOverride();
|
|
||||||
registerServiceCli(program);
|
|
||||||
|
|
||||||
await program.parseAsync(["service", "node", "status"], { from: "user" });
|
|
||||||
|
|
||||||
expect(runNodeDaemonStatus).toHaveBeenCalledTimes(1);
|
|
||||||
expect(runDaemonStatus).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,181 +0,0 @@
|
|||||||
import type { Command } from "commander";
|
|
||||||
import { formatDocsLink } from "../terminal/links.js";
|
|
||||||
import { theme } from "../terminal/theme.js";
|
|
||||||
import { formatHelpExampleGroup } from "./help-format.js";
|
|
||||||
import { createDefaultDeps } from "./deps.js";
|
|
||||||
import {
|
|
||||||
runDaemonInstall,
|
|
||||||
runDaemonRestart,
|
|
||||||
runDaemonStart,
|
|
||||||
runDaemonStatus,
|
|
||||||
runDaemonStop,
|
|
||||||
runDaemonUninstall,
|
|
||||||
} from "./daemon-cli/runners.js";
|
|
||||||
import {
|
|
||||||
runNodeDaemonInstall,
|
|
||||||
runNodeDaemonRestart,
|
|
||||||
runNodeDaemonStart,
|
|
||||||
runNodeDaemonStatus,
|
|
||||||
runNodeDaemonStop,
|
|
||||||
runNodeDaemonUninstall,
|
|
||||||
} from "./node-cli/daemon.js";
|
|
||||||
|
|
||||||
export function registerServiceCli(program: Command) {
|
|
||||||
const gatewayExamples: Array<[string, string]> = [
|
|
||||||
["clawdbot service gateway status", "Show gateway service status + probe."],
|
|
||||||
[
|
|
||||||
"clawdbot service gateway install --port 18789 --token <token>",
|
|
||||||
"Install the Gateway service on port 18789.",
|
|
||||||
],
|
|
||||||
["clawdbot service gateway restart", "Restart the Gateway service."],
|
|
||||||
];
|
|
||||||
|
|
||||||
const nodeExamples: Array<[string, string]> = [
|
|
||||||
["clawdbot service node status", "Show node host service status."],
|
|
||||||
[
|
|
||||||
"clawdbot service node install --host gateway.local --port 18789 --tls",
|
|
||||||
"Install the node host service with TLS.",
|
|
||||||
],
|
|
||||||
["clawdbot service node restart", "Restart the node host service."],
|
|
||||||
];
|
|
||||||
|
|
||||||
const service = program
|
|
||||||
.command("service")
|
|
||||||
.description("Manage Gateway and node host services (launchd/systemd/schtasks)")
|
|
||||||
.addHelpText(
|
|
||||||
"after",
|
|
||||||
() =>
|
|
||||||
`\n${theme.heading("Examples:")}\n${formatHelpExampleGroup(
|
|
||||||
"Gateway:",
|
|
||||||
gatewayExamples,
|
|
||||||
)}\n\n${formatHelpExampleGroup("Node:", nodeExamples)}\n\n${theme.muted(
|
|
||||||
"Docs:",
|
|
||||||
)} ${formatDocsLink("/cli/service", "docs.clawd.bot/cli/service")}\n`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const gateway = service.command("gateway").description("Manage the Gateway service");
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("status")
|
|
||||||
.description("Show gateway service status + probe the Gateway")
|
|
||||||
.option("--url <url>", "Gateway WebSocket URL (defaults to config/remote/local)")
|
|
||||||
.option("--token <token>", "Gateway token (if required)")
|
|
||||||
.option("--password <password>", "Gateway password (password auth)")
|
|
||||||
.option("--timeout <ms>", "Timeout in ms", "10000")
|
|
||||||
.option("--no-probe", "Skip RPC probe")
|
|
||||||
.option("--deep", "Scan system-level services", false)
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonStatus({
|
|
||||||
rpc: opts,
|
|
||||||
probe: Boolean(opts.probe),
|
|
||||||
deep: Boolean(opts.deep),
|
|
||||||
json: Boolean(opts.json),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("install")
|
|
||||||
.description("Install the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--port <port>", "Gateway port")
|
|
||||||
.option("--runtime <runtime>", "Service runtime (node|bun). Default: node")
|
|
||||||
.option("--token <token>", "Gateway token (token auth)")
|
|
||||||
.option("--force", "Reinstall/overwrite if already installed", false)
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonInstall(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("uninstall")
|
|
||||||
.description("Uninstall the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonUninstall(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("start")
|
|
||||||
.description("Start the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonStart(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("stop")
|
|
||||||
.description("Stop the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonStop(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("restart")
|
|
||||||
.description("Restart the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonRestart(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
const node = service.command("node").description("Manage the node host service");
|
|
||||||
|
|
||||||
node
|
|
||||||
.command("status")
|
|
||||||
.description("Show node host service status")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runNodeDaemonStatus(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
node
|
|
||||||
.command("install")
|
|
||||||
.description("Install the node host service (launchd/systemd/schtasks)")
|
|
||||||
.option("--host <host>", "Gateway host")
|
|
||||||
.option("--port <port>", "Gateway port")
|
|
||||||
.option("--tls", "Use TLS for the Gateway connection", false)
|
|
||||||
.option("--tls-fingerprint <sha256>", "Expected TLS certificate fingerprint (sha256)")
|
|
||||||
.option("--node-id <id>", "Override node id (clears pairing token)")
|
|
||||||
.option("--display-name <name>", "Override node display name")
|
|
||||||
.option("--runtime <runtime>", "Service runtime (node|bun). Default: node")
|
|
||||||
.option("--force", "Reinstall/overwrite if already installed", false)
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runNodeDaemonInstall(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
node
|
|
||||||
.command("uninstall")
|
|
||||||
.description("Uninstall the node host service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runNodeDaemonUninstall(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
node
|
|
||||||
.command("start")
|
|
||||||
.description("Start the node host service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runNodeDaemonStart(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
node
|
|
||||||
.command("stop")
|
|
||||||
.description("Stop the node host service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runNodeDaemonStop(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
node
|
|
||||||
.command("restart")
|
|
||||||
.description("Restart the node host service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runNodeDaemonRestart(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Build default deps (parity with daemon CLI).
|
|
||||||
void createDefaultDeps();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user