feat: add native user service installs

This commit is contained in:
Federico Jaramillo Martinez
2026-05-25 16:28:09 +02:00
parent 711c4f3d98
commit 824728174b
10 changed files with 633 additions and 227 deletions
+10 -3
View File
@@ -1,12 +1,14 @@
import { spawn } from "node:child_process";
import { existsSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
const cliPath = join(packageRoot, "dist", "cli.js");
const serviceNames = ["pi-web-sessiond.service", "pi-web.service"];
const serviceNames = ["pi-web-sessiond.service", "pi-web.service", "pi-web-ui-dev.service"];
const macLogPaths = ["sessiond.log", "web.log", "ui-dev.log"].map((name) => join(homedir(), ".pi-web", "logs", name));
const subcommands = [
"install",
@@ -76,7 +78,12 @@ function isSubcommand(value: string): value is Subcommand {
}
async function boundedLogs(): Promise<{ code: number; output: string }> {
return run("journalctl", ["--user", "-u", serviceNames[0] ?? "", "-u", serviceNames[1] ?? "", "-n", "100", "--no-pager"]);
if (process.platform === "darwin") {
const existingLogs = macLogPaths.filter((path) => existsSync(path));
if (existingLogs.length === 0) return { code: 1, output: "No PI WEB log files found in ~/.pi-web/logs." };
return run("tail", ["-n", "100", ...existingLogs]);
}
return run("journalctl", ["--user", ...serviceNames.flatMap((serviceName) => ["-u", serviceName]), "-n", "100", "--no-pager"]);
}
export default function piWebExtension(pi: ExtensionAPI): void {
@@ -95,7 +102,7 @@ export default function piWebExtension(pi: ExtensionAPI): void {
const rest = parsedArgs.slice(1);
if (subcommand === "help") {
ctx.ui.notify(`PI WEB commands:\n\n${subcommands.map((command) => `/pi-web ${command}`).join("\n")}\n\nLogs are bounded to the last 100 journal lines in the Pi command. Use \`pi-web logs\` in a shell to follow logs.`, "info");
ctx.ui.notify(`PI WEB commands:\n\n${subcommands.map((command) => `/pi-web ${command}`).join("\n")}\n\nLogs are bounded to the last 100 service log lines in the Pi command. Use \`pi-web logs\` in a shell to follow logs.`, "info");
return;
}