style: apply biome formatting
This commit is contained in:
@@ -25,7 +25,9 @@ export function resolveLaunchAgentPlistPath(
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveGatewayLogPaths(env: Record<string, string | undefined>): {
|
||||
export function resolveGatewayLogPaths(
|
||||
env: Record<string, string | undefined>,
|
||||
): {
|
||||
logDir: string;
|
||||
stdoutPath: string;
|
||||
stderrPath: string;
|
||||
@@ -160,7 +162,11 @@ async function execLaunchctl(
|
||||
const { stdout, stderr } = await execFileAsync("launchctl", args, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
return { stdout: String(stdout ?? ""), stderr: String(stderr ?? ""), code: 0 };
|
||||
return {
|
||||
stdout: String(stdout ?? ""),
|
||||
stderr: String(stderr ?? ""),
|
||||
code: 0,
|
||||
};
|
||||
} catch (error) {
|
||||
const e = error as {
|
||||
stdout?: unknown;
|
||||
@@ -257,10 +263,16 @@ export async function installLaunchAgent({
|
||||
await execLaunchctl(["unload", plistPath]);
|
||||
const boot = await execLaunchctl(["bootstrap", domain, plistPath]);
|
||||
if (boot.code !== 0) {
|
||||
throw new Error(`launchctl bootstrap failed: ${boot.stderr || boot.stdout}`.trim());
|
||||
throw new Error(
|
||||
`launchctl bootstrap failed: ${boot.stderr || boot.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
await execLaunchctl(["enable", `${domain}/${GATEWAY_LAUNCH_AGENT_LABEL}`]);
|
||||
await execLaunchctl(["kickstart", "-k", `${domain}/${GATEWAY_LAUNCH_AGENT_LABEL}`]);
|
||||
await execLaunchctl([
|
||||
"kickstart",
|
||||
"-k",
|
||||
`${domain}/${GATEWAY_LAUNCH_AGENT_LABEL}`,
|
||||
]);
|
||||
|
||||
stdout.write(`Installed LaunchAgent: ${plistPath}\n`);
|
||||
stdout.write(`Logs: ${stdoutPath}\n`);
|
||||
@@ -276,7 +288,9 @@ export async function restartLaunchAgent({
|
||||
const label = GATEWAY_LAUNCH_AGENT_LABEL;
|
||||
const res = await execLaunchctl(["kickstart", "-k", `${domain}/${label}`]);
|
||||
if (res.code !== 0) {
|
||||
throw new Error(`launchctl kickstart failed: ${res.stderr || res.stdout}`.trim());
|
||||
throw new Error(
|
||||
`launchctl kickstart failed: ${res.stderr || res.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
stdout.write(`Restarted LaunchAgent: ${domain}/${label}\n`);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,13 @@ function resolveRepoRootForDev(): string {
|
||||
}
|
||||
|
||||
async function resolveTsxCliPath(repoRoot: string): Promise<string> {
|
||||
const candidate = path.join(repoRoot, "node_modules", "tsx", "dist", "cli.mjs");
|
||||
const candidate = path.join(
|
||||
repoRoot,
|
||||
"node_modules",
|
||||
"tsx",
|
||||
"dist",
|
||||
"cli.mjs",
|
||||
);
|
||||
await fs.access(candidate);
|
||||
return candidate;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ function resolveHomeDir(env: Record<string, string | undefined>): string {
|
||||
return home;
|
||||
}
|
||||
|
||||
function resolveTaskScriptPath(env: Record<string, string | undefined>): string {
|
||||
function resolveTaskScriptPath(
|
||||
env: Record<string, string | undefined>,
|
||||
): string {
|
||||
const home = resolveHomeDir(env);
|
||||
return path.join(home, ".clawdis", "gateway.cmd");
|
||||
}
|
||||
@@ -71,7 +73,10 @@ export async function readScheduledTaskCommand(
|
||||
if (line.toLowerCase().startsWith("rem ")) continue;
|
||||
if (line.toLowerCase().startsWith("set ")) continue;
|
||||
if (line.toLowerCase().startsWith("cd /d ")) {
|
||||
workingDirectory = line.slice("cd /d ".length).trim().replace(/^"|"$/g, "");
|
||||
workingDirectory = line
|
||||
.slice("cd /d ".length)
|
||||
.trim()
|
||||
.replace(/^"|"$/g, "");
|
||||
continue;
|
||||
}
|
||||
commandLine = line;
|
||||
@@ -119,7 +124,11 @@ async function execSchtasks(
|
||||
encoding: "utf8",
|
||||
windowsHide: true,
|
||||
});
|
||||
return { stdout: String(stdout ?? ""), stderr: String(stderr ?? ""), code: 0 };
|
||||
return {
|
||||
stdout: String(stdout ?? ""),
|
||||
stderr: String(stderr ?? ""),
|
||||
code: 0,
|
||||
};
|
||||
} catch (error) {
|
||||
const e = error as {
|
||||
stdout?: unknown;
|
||||
@@ -184,7 +193,9 @@ export async function installScheduledTask({
|
||||
quotedScript,
|
||||
]);
|
||||
if (create.code !== 0) {
|
||||
throw new Error(`schtasks create failed: ${create.stderr || create.stdout}`.trim());
|
||||
throw new Error(
|
||||
`schtasks create failed: ${create.stderr || create.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
await execSchtasks(["/Run", "/TN", GATEWAY_WINDOWS_TASK_NAME]);
|
||||
|
||||
@@ -38,10 +38,13 @@ export type GatewayService = {
|
||||
stdout: NodeJS.WritableStream;
|
||||
}) => Promise<void>;
|
||||
restart: (args: { stdout: NodeJS.WritableStream }) => Promise<void>;
|
||||
isLoaded: (args: { env: Record<string, string | undefined> }) => Promise<boolean>;
|
||||
readCommand: (
|
||||
env: Record<string, string | undefined>,
|
||||
) => Promise<{ programArguments: string[]; workingDirectory?: string } | null>;
|
||||
isLoaded: (args: {
|
||||
env: Record<string, string | undefined>;
|
||||
}) => Promise<boolean>;
|
||||
readCommand: (env: Record<string, string | undefined>) => Promise<{
|
||||
programArguments: string[];
|
||||
workingDirectory?: string;
|
||||
} | null>;
|
||||
};
|
||||
|
||||
export function resolveGatewayService(): GatewayService {
|
||||
@@ -102,5 +105,7 @@ export function resolveGatewayService(): GatewayService {
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error(`Gateway service install not supported on ${process.platform}`);
|
||||
throw new Error(
|
||||
`Gateway service install not supported on ${process.platform}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ function resolveHomeDir(env: Record<string, string | undefined>): string {
|
||||
return home;
|
||||
}
|
||||
|
||||
function resolveSystemdUnitPath(env: Record<string, string | undefined>): string {
|
||||
function resolveSystemdUnitPath(
|
||||
env: Record<string, string | undefined>,
|
||||
): string {
|
||||
const home = resolveHomeDir(env);
|
||||
return path.join(
|
||||
home,
|
||||
@@ -143,7 +145,11 @@ async function execSystemctl(
|
||||
const { stdout, stderr } = await execFileAsync("systemctl", args, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
return { stdout: String(stdout ?? ""), stderr: String(stderr ?? ""), code: 0 };
|
||||
return {
|
||||
stdout: String(stdout ?? ""),
|
||||
stderr: String(stderr ?? ""),
|
||||
code: 0,
|
||||
};
|
||||
} catch (error) {
|
||||
const e = error as {
|
||||
stdout?: unknown;
|
||||
@@ -169,9 +175,13 @@ async function assertSystemdAvailable() {
|
||||
if (res.code === 0) return;
|
||||
const detail = res.stderr || res.stdout;
|
||||
if (detail.toLowerCase().includes("not found")) {
|
||||
throw new Error("systemctl not available; systemd user services are required on Linux.");
|
||||
throw new Error(
|
||||
"systemctl not available; systemd user services are required on Linux.",
|
||||
);
|
||||
}
|
||||
throw new Error(`systemctl --user unavailable: ${detail || "unknown error"}`.trim());
|
||||
throw new Error(
|
||||
`systemctl --user unavailable: ${detail || "unknown error"}`.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
export async function installSystemdService({
|
||||
@@ -191,23 +201,33 @@ export async function installSystemdService({
|
||||
|
||||
const unitPath = resolveSystemdUnitPath(env);
|
||||
await fs.mkdir(path.dirname(unitPath), { recursive: true });
|
||||
const unit = buildSystemdUnit({ programArguments, workingDirectory, environment });
|
||||
const unit = buildSystemdUnit({
|
||||
programArguments,
|
||||
workingDirectory,
|
||||
environment,
|
||||
});
|
||||
await fs.writeFile(unitPath, unit, "utf8");
|
||||
|
||||
const unitName = `${GATEWAY_SYSTEMD_SERVICE_NAME}.service`;
|
||||
const reload = await execSystemctl(["--user", "daemon-reload"]);
|
||||
if (reload.code !== 0) {
|
||||
throw new Error(`systemctl daemon-reload failed: ${reload.stderr || reload.stdout}`.trim());
|
||||
throw new Error(
|
||||
`systemctl daemon-reload failed: ${reload.stderr || reload.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
const enable = await execSystemctl(["--user", "enable", unitName]);
|
||||
if (enable.code !== 0) {
|
||||
throw new Error(`systemctl enable failed: ${enable.stderr || enable.stdout}`.trim());
|
||||
throw new Error(
|
||||
`systemctl enable failed: ${enable.stderr || enable.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
const restart = await execSystemctl(["--user", "restart", unitName]);
|
||||
if (restart.code !== 0) {
|
||||
throw new Error(`systemctl restart failed: ${restart.stderr || restart.stdout}`.trim());
|
||||
throw new Error(
|
||||
`systemctl restart failed: ${restart.stderr || restart.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
stdout.write(`Installed systemd service: ${unitPath}\n`);
|
||||
@@ -243,7 +263,9 @@ export async function restartSystemdService({
|
||||
const unitName = `${GATEWAY_SYSTEMD_SERVICE_NAME}.service`;
|
||||
const res = await execSystemctl(["--user", "restart", unitName]);
|
||||
if (res.code !== 0) {
|
||||
throw new Error(`systemctl restart failed: ${res.stderr || res.stdout}`.trim());
|
||||
throw new Error(
|
||||
`systemctl restart failed: ${res.stderr || res.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
stdout.write(`Restarted systemd service: ${unitName}\n`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user