@yefengr/remote-pi 0.7.16 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +44 -95
  2. package/dist/actions/handlers.js +1 -1
  3. package/dist/actions/handlers.js.map +1 -1
  4. package/dist/actions/registry.d.ts +1 -1
  5. package/dist/actions/registry.js +1 -1
  6. package/dist/{daemon/commands.d.ts → commands.d.ts} +3 -4
  7. package/dist/{daemon/commands.js → commands.js} +8 -151
  8. package/dist/commands.js.map +1 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +20 -38
  11. package/dist/index.js.map +1 -1
  12. package/dist/pairing/storage.js +4 -4
  13. package/dist/pairing/storage.js.map +1 -1
  14. package/dist/protocol/v2/schemas.d.ts +64 -7
  15. package/dist/protocol/v2/schemas.js +6 -3
  16. package/dist/protocol/v2/schemas.js.map +1 -1
  17. package/dist/session/local_config.d.ts +0 -5
  18. package/dist/session/local_config.js +6 -29
  19. package/dist/session/local_config.js.map +1 -1
  20. package/dist/timeline/history.d.ts +3 -6
  21. package/dist/timeline/history.js +113 -249
  22. package/dist/timeline/history.js.map +1 -1
  23. package/dist/timeline/runtime.js +29 -37
  24. package/dist/timeline/runtime.js.map +1 -1
  25. package/dist/timeline/sequence.d.ts +7 -0
  26. package/dist/timeline/sequence.js +16 -0
  27. package/dist/timeline/sequence.js.map +1 -0
  28. package/dist/timeline/v2_service.js +3 -1
  29. package/dist/timeline/v2_service.js.map +1 -1
  30. package/dist/transport/relay_client.js.map +1 -1
  31. package/package.json +1 -8
  32. package/dist/bin/supervisord.d.ts +0 -2
  33. package/dist/bin/supervisord.js +0 -78
  34. package/dist/bin/supervisord.js.map +0 -1
  35. package/dist/daemon/cli-links.d.ts +0 -30
  36. package/dist/daemon/cli-links.js +0 -134
  37. package/dist/daemon/cli-links.js.map +0 -1
  38. package/dist/daemon/client.d.ts +0 -20
  39. package/dist/daemon/client.js +0 -131
  40. package/dist/daemon/client.js.map +0 -1
  41. package/dist/daemon/commands.js.map +0 -1
  42. package/dist/daemon/control_protocol.d.ts +0 -198
  43. package/dist/daemon/control_protocol.js +0 -40
  44. package/dist/daemon/control_protocol.js.map +0 -1
  45. package/dist/daemon/cron_log.d.ts +0 -24
  46. package/dist/daemon/cron_log.js +0 -57
  47. package/dist/daemon/cron_log.js.map +0 -1
  48. package/dist/daemon/cron_registry.d.ts +0 -43
  49. package/dist/daemon/cron_registry.js +0 -149
  50. package/dist/daemon/cron_registry.js.map +0 -1
  51. package/dist/daemon/install-runtime.d.ts +0 -10
  52. package/dist/daemon/install-runtime.js +0 -81
  53. package/dist/daemon/install-runtime.js.map +0 -1
  54. package/dist/daemon/install.d.ts +0 -110
  55. package/dist/daemon/install.js +0 -263
  56. package/dist/daemon/install.js.map +0 -1
  57. package/dist/daemon/registry.d.ts +0 -51
  58. package/dist/daemon/registry.js +0 -207
  59. package/dist/daemon/registry.js.map +0 -1
  60. package/dist/daemon/rpc_child.d.ts +0 -135
  61. package/dist/daemon/rpc_child.js +0 -472
  62. package/dist/daemon/rpc_child.js.map +0 -1
  63. package/dist/daemon/status.d.ts +0 -45
  64. package/dist/daemon/status.js +0 -87
  65. package/dist/daemon/status.js.map +0 -1
  66. package/dist/daemon/supervisor-ipc.d.ts +0 -2
  67. package/dist/daemon/supervisor-ipc.js +0 -20
  68. package/dist/daemon/supervisor-ipc.js.map +0 -1
  69. package/dist/daemon/supervisor.d.ts +0 -70
  70. package/dist/daemon/supervisor.js +0 -637
  71. package/dist/daemon/supervisor.js.map +0 -1
  72. package/dist/session/ipc.d.ts +0 -6
  73. package/dist/session/ipc.js +0 -15
  74. package/dist/session/ipc.js.map +0 -1
  75. package/docs/daemon.md +0 -175
  76. package/service-templates/launchd.plist.template +0 -35
  77. package/service-templates/systemd.service.template +0 -19
  78. package/service-templates/task-launcher.vbs.template +0 -10
  79. package/service-templates/task-scheduler.xml.template +0 -38
@@ -1,43 +0,0 @@
1
- export declare const MIN_INTERVAL_MS = 60000;
2
- /** A scheduled prompt. Cron never owns a daemon's lifecycle. */
3
- export interface CronJob {
4
- id: string;
5
- daemon_id: string;
6
- schedule: string;
7
- tz?: string;
8
- prompt: string;
9
- enabled: boolean;
10
- skip_if_busy: boolean;
11
- catchup: boolean;
12
- created_at: string;
13
- last_run?: string;
14
- last_status?: string;
15
- }
16
- export interface CronRegistry {
17
- jobs: CronJob[];
18
- }
19
- export declare function cronRegistryPath(): string;
20
- /** Old wake-bearing jobs are intentionally not carried into the new contract. */
21
- export declare function loadCronRegistry(): CronRegistry;
22
- export declare function saveCronRegistry(registry: CronRegistry): void;
23
- export declare function listJobs(): CronJob[];
24
- export declare function getJob(id: string): CronJob | undefined;
25
- export interface NewJobInput {
26
- daemon_id: string;
27
- schedule: string;
28
- prompt: string;
29
- tz?: string;
30
- skip_if_busy?: boolean;
31
- catchup?: boolean;
32
- }
33
- export declare function addJob(input: NewJobInput): CronJob;
34
- export declare function removeJob(id: string): boolean;
35
- export declare function setJobEnabled(id: string, enabled: boolean): boolean;
36
- export declare function recordRun(id: string, at: string, status: string): void;
37
- export interface ScheduleValidation {
38
- ok: boolean;
39
- error?: string;
40
- intervalMs?: number;
41
- }
42
- export declare function validateSchedule(schedule: string, tz?: string): ScheduleValidation;
43
- export declare function nextRunFor(job: CronJob): Date | null;
@@ -1,149 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { homedir } from "node:os";
3
- import { randomBytes } from "node:crypto";
4
- import { dirname, join } from "node:path";
5
- import { Cron } from "croner";
6
- export const MIN_INTERVAL_MS = 60_000;
7
- function cronPath() {
8
- const root = process.env["REMOTE_PI_HOME"] || homedir();
9
- return join(root, ".pi", "remote", "cron.json");
10
- }
11
- export function cronRegistryPath() { return cronPath(); }
12
- /** Old wake-bearing jobs are intentionally not carried into the new contract. */
13
- export function loadCronRegistry() {
14
- if (!existsSync(cronPath()))
15
- return { jobs: [] };
16
- try {
17
- const parsed = JSON.parse(readFileSync(cronPath(), "utf8"));
18
- if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.jobs))
19
- return { jobs: [] };
20
- return { jobs: parsed.jobs.flatMap((item) => {
21
- const job = coerceJob(item);
22
- return job ? [job] : [];
23
- }) };
24
- }
25
- catch {
26
- return { jobs: [] };
27
- }
28
- }
29
- export function saveCronRegistry(registry) {
30
- mkdirSync(dirname(cronPath()), { recursive: true });
31
- writeFileSync(cronPath(), JSON.stringify(registry, null, 2) + "\n");
32
- }
33
- export function listJobs() { return loadCronRegistry().jobs; }
34
- export function getJob(id) { return listJobs().find((job) => job.id === id); }
35
- export function addJob(input) {
36
- const registry = loadCronRegistry();
37
- const job = {
38
- id: freshId(registry.jobs),
39
- daemon_id: input.daemon_id,
40
- schedule: input.schedule,
41
- prompt: input.prompt,
42
- enabled: true,
43
- skip_if_busy: input.skip_if_busy ?? true,
44
- catchup: input.catchup ?? false,
45
- created_at: new Date().toISOString(),
46
- };
47
- if (input.tz)
48
- job.tz = input.tz;
49
- registry.jobs.push(job);
50
- saveCronRegistry(registry);
51
- return job;
52
- }
53
- export function removeJob(id) {
54
- const registry = loadCronRegistry();
55
- const index = registry.jobs.findIndex((job) => job.id === id);
56
- if (index < 0)
57
- return false;
58
- registry.jobs.splice(index, 1);
59
- saveCronRegistry(registry);
60
- return true;
61
- }
62
- export function setJobEnabled(id, enabled) {
63
- const registry = loadCronRegistry();
64
- const job = registry.jobs.find((item) => item.id === id);
65
- if (!job)
66
- return false;
67
- job.enabled = enabled;
68
- saveCronRegistry(registry);
69
- return true;
70
- }
71
- export function recordRun(id, at, status) {
72
- const registry = loadCronRegistry();
73
- const job = registry.jobs.find((item) => item.id === id);
74
- if (!job)
75
- return;
76
- job.last_run = at;
77
- job.last_status = status;
78
- saveCronRegistry(registry);
79
- }
80
- export function validateSchedule(schedule, tz) {
81
- let cron;
82
- try {
83
- cron = new Cron(schedule, tz ? { timezone: tz } : {});
84
- }
85
- catch (error) {
86
- return { ok: false, error: `invalid cron expression: ${error.message}` };
87
- }
88
- try {
89
- const first = cron.nextRun();
90
- const second = first ? cron.nextRun(first) : null;
91
- if (!first || !second)
92
- return { ok: false, error: "schedule has no upcoming runs" };
93
- const intervalMs = second.getTime() - first.getTime();
94
- if (intervalMs < MIN_INTERVAL_MS) {
95
- return { ok: false, intervalMs, error: `schedule too frequent: ~${Math.round(intervalMs / 1000)}s between runs (minimum is 60s)` };
96
- }
97
- return { ok: true, intervalMs };
98
- }
99
- finally {
100
- cron.stop();
101
- }
102
- }
103
- export function nextRunFor(job) {
104
- try {
105
- const cron = new Cron(job.schedule, job.tz ? { timezone: job.tz } : {});
106
- const next = cron.nextRun();
107
- cron.stop();
108
- return next;
109
- }
110
- catch {
111
- return null;
112
- }
113
- }
114
- function freshId(existing) {
115
- for (let attempt = 0; attempt < 1000; attempt += 1) {
116
- const id = `j_${randomBytes(4).toString("hex")}`;
117
- if (!existing.some((job) => job.id === id))
118
- return id;
119
- }
120
- throw new Error("cron id space exhausted");
121
- }
122
- function coerceJob(value) {
123
- if (!value || typeof value !== "object")
124
- return null;
125
- const raw = value;
126
- // No dual-read/migration of wake: old records are deliberately excluded.
127
- if (Object.hasOwn(raw, "wake"))
128
- return null;
129
- if (typeof raw["id"] !== "string" || typeof raw["daemon_id"] !== "string" || typeof raw["schedule"] !== "string" || typeof raw["prompt"] !== "string")
130
- return null;
131
- const job = {
132
- id: raw["id"],
133
- daemon_id: raw["daemon_id"],
134
- schedule: raw["schedule"],
135
- prompt: raw["prompt"],
136
- enabled: raw["enabled"] !== false,
137
- skip_if_busy: raw["skip_if_busy"] !== false,
138
- catchup: raw["catchup"] === true,
139
- created_at: typeof raw["created_at"] === "string" ? raw["created_at"] : new Date(0).toISOString(),
140
- };
141
- if (typeof raw["tz"] === "string")
142
- job.tz = raw["tz"];
143
- if (typeof raw["last_run"] === "string")
144
- job.last_run = raw["last_run"];
145
- if (typeof raw["last_status"] === "string")
146
- job.last_status = raw["last_status"];
147
- return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Cleanup commands may fail when the service is not currently installed. */
3
- export declare function tryExecCommand(cmd: string, args: string[], log: string[]): void;
4
- /** Build the elevated Windows batch script. Kept pure for cross-platform tests. */
5
- export declare function buildElevatedCmd(lines: string[], logFile: string): string;
6
- /** Run a schtasks sequence through one UAC prompt and surface its output. */
7
- export declare function execElevatedWindows(lines: string[], log: string[]): void;
8
- export declare const _exec: typeof execCommand;
9
- export declare const _tryExec: typeof tryExecCommand;
10
- export declare const _execElevatedWindows: typeof execElevatedWindows;
@@ -1,81 +0,0 @@
1
- import { execFileSync } from "node:child_process";
2
- import { readFileSync, unlinkSync, writeFileSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { tmpdir } from "node:os";
5
- export function execCommand(cmd, args, log) {
6
- try {
7
- const out = execFileSync(cmd, args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
8
- if (out.trim())
9
- log.push(`$ ${cmd} ${args.join(" ")}\n${out.trim()}`);
10
- else
11
- log.push(`$ ${cmd} ${args.join(" ")}`);
12
- }
13
- catch (error) {
14
- const err = error;
15
- const stderr = typeof err.stderr === "string" ? err.stderr : err.stderr?.toString() ?? "";
16
- throw new Error(`\`${cmd} ${args.join(" ")}\` exited ${err.status ?? "?"}\n${stderr.trim() || err.message}`);
17
- }
18
- }
19
- /** Cleanup commands may fail when the service is not currently installed. */
20
- export function tryExecCommand(cmd, args, log) {
21
- try {
22
- execCommand(cmd, args, log);
23
- }
24
- catch { /* expected cleanup failure */ }
25
- }
26
- /** Build the elevated Windows batch script. Kept pure for cross-platform tests. */
27
- export function buildElevatedCmd(lines, logFile) {
28
- const redirect = ` >> "${logFile}" 2>&1`;
29
- const body = lines.map((line) => /^\s*(if|exit|rem|@)/i.test(line) ? line : line + redirect);
30
- return ["@echo off", ...body].join("\r\n") + "\r\n";
31
- }
32
- function readIfExists(path) {
33
- try {
34
- return readFileSync(path, "utf8");
35
- }
36
- catch {
37
- return "";
38
- }
39
- }
40
- /** Run a schtasks sequence through one UAC prompt and surface its output. */
41
- export function execElevatedWindows(lines, log) {
42
- const base = join(tmpdir(), `remote-pi-elevate-${process.pid}`);
43
- const cmdPath = `${base}.cmd`;
44
- const logFile = `${base}.log`;
45
- writeFileSync(cmdPath, buildElevatedCmd(lines, logFile));
46
- try {
47
- unlinkSync(logFile);
48
- }
49
- catch { /* none yet */ }
50
- let thrown = null;
51
- try {
52
- execFileSync("powershell", [
53
- "-NoProfile", "-NonInteractive", "-Command",
54
- `$p = Start-Process -FilePath cmd.exe -ArgumentList '/c','"${cmdPath}"' ` +
55
- "-Verb RunAs -Wait -PassThru -WindowStyle Hidden; exit $p.ExitCode",
56
- ], { stdio: ["ignore", "pipe", "pipe"] });
57
- }
58
- catch (error) {
59
- thrown = error;
60
- }
61
- const output = readIfExists(logFile).trim();
62
- if (output)
63
- log.push(output);
64
- try {
65
- unlinkSync(cmdPath);
66
- }
67
- catch { /* best-effort */ }
68
- try {
69
- unlinkSync(logFile);
70
- }
71
- catch { /* best-effort */ }
72
- if (thrown) {
73
- throw new Error("administrator privileges required — the UAC prompt was declined or the " +
74
- "schtasks operation failed. Run the command again and accept the Windows " +
75
- `elevation prompt.${output ? `\n${output}` : ""}`);
76
- }
77
- }
78
- export const _exec = execCommand;
79
- export const _tryExec = tryExecCommand;
80
- export const _execElevatedWindows = execElevatedWindows;
81
- //# sourceMappingURL=install-runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"install-runtime.js","sourceRoot":"","sources":["../../src/daemon/install-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,IAAc,EAAE,GAAa;IACpE,IAAI,CA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,EAAE,CAAC;QACf,MAAM,GAAG,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5C,IAAI,MAAM;QAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7B,IAAI,CAAC;QAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACxD,IAAI,CAAC;QAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;IAExD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,yEAAyE;YACzE,0EAA0E;YAC1E,oBAAoB,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAClD,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC;AACjC,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC;AACvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC"}
@@ -1,110 +0,0 @@
1
- export { buildElevatedCmd } from "./install-runtime.js";
2
- export { buildCmdShim, isOnPath, linkCliBinaries, unlinkCliBinaries, userLocalBinDir, } from "./cli-links.js";
3
- export type { LinkBinariesResult, UnlinkBinariesResult } from "./cli-links.js";
4
- /**
5
- * Generates and activates a system service for `pi-supervisord` so the
6
- * daemon fleet survives reboots (plan/26 W3).
7
- *
8
- * Platform support:
9
- * - **macOS**: writes `~/Library/LaunchAgents/dev.remotepi.supervisord.plist`
10
- * and runs `launchctl bootstrap gui/<uid> <plist>` (modern API) with a
11
- * fallback to `launchctl load` for older macOS.
12
- * - **Linux**: writes `~/.config/systemd/user/remote-pi-supervisord.service`
13
- * and runs `systemctl --user daemon-reload && systemctl --user enable
14
- * --now remote-pi-supervisord.service`.
15
- *
16
- * Uninstall reverses both. Idempotent — re-running install over an existing
17
- * unit refreshes it (paths could have changed if user moved node_modules).
18
- *
19
- * **What does NOT happen here**: the actual `npm install -g @yefengr/remote-pi` step.
20
- * The user has to make the supervisor bin reachable on disk before install
21
- * can wire up the service. The `findSupervisorScript` resolver detects
22
- * common cases (npm global, pnpm global, local dev clone) and yields a
23
- * clear error otherwise.
24
- */
25
- export type SupervisorPlatform = "macos" | "linux" | "windows" | "unsupported";
26
- export declare function detectPlatform(): SupervisorPlatform;
27
- /**
28
- * Absolute path to the supervisor's compiled entry. We resolve from
29
- * `import.meta.url` (this file's location) since wherever the daemon
30
- * module lives, `bin/supervisord.js` is a sibling of `daemon/` under
31
- * `dist/`.
32
- *
33
- * After build: `dist/daemon/install.js` → `dist/bin/supervisord.js`.
34
- * In dev (`tsx`): same path resolution still lands inside `src/`, which
35
- * isn't directly runnable by `node` — dev install isn't expected.
36
- */
37
- export declare function findSupervisorScript(): string;
38
- /**
39
- * Absolute path to the extension's CLI entry (`dist/index.js`). This is
40
- * the file we symlink to `~/.local/bin/remote-pi` so the user can run
41
- * `remote-pi <subcommand>` from any shell after installing the extension
42
- * through Pi (`pi install npm:@yefengr/remote-pi`).
43
- *
44
- * Same resolution strategy as `findSupervisorScript`: from
45
- * `dist/daemon/install.js` → `dist/index.js`.
46
- */
47
- export declare function findRemotePiScript(): string;
48
- export declare function findNodeBinary(): string;
49
- export declare function findTemplate(name: "systemd" | "launchd" | "taskscheduler" | "vbs-launcher"): string;
50
- export declare function systemdUnitPath(): string;
51
- export declare function launchdPlistPath(): string;
52
- export declare const LAUNCHD_LABEL = "dev.remotepi.supervisord";
53
- /** systemd --user unit name (with `.service`) for the supervisor. */
54
- export declare const SYSTEMD_UNIT = "remote-pi-supervisord.service";
55
- /** Windows Task Scheduler task name (plan/40). */
56
- export declare const WINDOWS_TASK_NAME = "RemotePiSupervisor";
57
- /** Path of the rendered Task Scheduler XML (input to `schtasks /Create /XML`). */
58
- export declare function taskXmlPath(): string;
59
- /**
60
- * Path of the rendered VBScript launcher the Task Scheduler action invokes
61
- * via `wscript.exe` (plan/40, Windows). Launching node through this hidden
62
- * wrapper is what keeps the supervisor from flashing a console window.
63
- */
64
- export declare function vbsLauncherPath(): string;
65
- /**
66
- * Combined stdout/stderr log for the Windows supervisor. The Task Scheduler
67
- * launches it hidden via wscript, so without this redirect its output (and the
68
- * forwarded daemon-child stderr) would vanish — mirrors launchd/systemd, which
69
- * already log to `~/.pi/remote/supervisord.log`.
70
- */
71
- export declare function supervisordLogPath(): string;
72
- export interface RenderVars {
73
- node: string;
74
- supervisor: string;
75
- home: string;
76
- user: string;
77
- /** PATH inherited so `pi --mode rpc` resolves the same way it does
78
- * interactively. We snapshot `process.env.PATH` at install time. */
79
- path: string;
80
- /** Windows only: absolute path of the VBScript launcher the Task Scheduler
81
- * action runs via `wscript.exe`. Empty on POSIX (templates ignore `{VBS}`). */
82
- vbs: string;
83
- /** Windows only: combined stdout/stderr log the hidden supervisor appends to.
84
- * Empty on POSIX (templates ignore `{LOG}`). */
85
- logPath: string;
86
- }
87
- export declare function defaultRenderVars(): RenderVars;
88
- /** Replace `{NODE}` / `{SUPERVISOR}` / `{USER}` / `{HOME}` / `{PATH}` / `{VBS}` / `{LOG}`. */
89
- export declare function renderTemplate(template: string, vars: RenderVars): string;
90
- export interface InstallResult {
91
- platform: SupervisorPlatform;
92
- unitPath: string;
93
- /** Lines describing each step taken — surfaced to the user via notify. */
94
- log: string[];
95
- }
96
- /**
97
- * Writes the unit/plist, runs the platform's activation command. Throws
98
- * on unsupported OS or when the supervisor script isn't found.
99
- *
100
- * Idempotent: re-running re-writes the unit (paths could have changed)
101
- * and re-activates via the platform tool's idempotent flag.
102
- */
103
- export declare function installService(vars?: RenderVars): InstallResult;
104
- export interface UninstallResult {
105
- platform: SupervisorPlatform;
106
- unitPath: string;
107
- removed: boolean;
108
- log: string[];
109
- }
110
- export declare function uninstallService(): UninstallResult;