export type Platform = 'linux' | 'darwin' | 'win32' | 'freebsd' | 'other';
export interface ServiceInstallOpts {
/** Directory where the binary lives (e.g. `$HOME/.local/bin`). */
installDir: string;
/** Directory where the config + secrets live. */
configDir: string;
/** Absolute path to the binary / shim to exec. */
binaryPath: string;
/** Optional env vars passed to the service (RELAY_URL, AGENT_ID, etc.). */
userEnv?: Record;
/** Service name (default `edge-client-ts`). */
serviceName?: string;
}
export interface ServiceStatus {
installed: boolean;
running: boolean;
platform: Platform;
detail: string;
}
export declare class ServiceManager {
static detectPlatform(): Platform;
/** Default service name. */
static defaultServiceName(): string;
/** Default install dir per platform (user-scoped, no root). */
static defaultInstallDir(platform?: Platform): string;
/** Resolve the service-unit file path for the current platform. */
getServiceFilePath(platform: Platform, serviceName: string): string;
/** Linux systemd --user unit file contents. */
generateSystemdUnit(opts: ServiceInstallOpts, serviceName: string): string;
/** macOS LaunchAgent plist contents. */
generateLaunchdPlist(opts: ServiceInstallOpts, serviceName: string): string;
/** Windows Task Scheduler XML (no admin needed when created per-user). */
generateSchtasksXml(opts: ServiceInstallOpts, serviceName: string): string;
install(opts: ServiceInstallOpts): Promise;
uninstall(opts: ServiceInstallOpts): Promise;
start(serviceName?: string): Promise;
stop(serviceName?: string): Promise;
status(serviceName?: string): Promise;
isInstalled(serviceName?: string): Promise;
}
/** Expand `~` / `$HOME` / `%USERPROFILE%` placeholders. */
export declare function expandUser(p: string): string;
/**
* Validate a string is safe to interpolate into a systemd unit file.
* systemd's INI-like parser treats `[section]` at the start of a line
* as a section boundary and `Key=` as a directive. A newline in any
* interpolated value therefore lets an attacker close the current
* directive, start a new `[Service]` section, and inject `ExecStart=`,
* `Environment=`, etc. We reject anything containing ASCII control
* characters; legitimate values never need them.
*/
export declare function escapeSystemdValue(value: string, fieldName: string): string;
/**
* XML-escape a string for use inside an attribute value or element
* text in plist/schtasks XML. The chars `<`, `>`, `&`, `"`, `'`
* MUST be escaped or an attacker can break out of the surrounding
* construct (`ProgramArguments...`) and inject
* arbitrary plist/schtasks directives. See C1 in security-review
* 2026-07-11.
*/
export declare function escapeXmlAttr(value: string): string;
/**
* Validate that a service name is a valid systemd unit / plist label /
* schtasks task name. The charset is intentionally narrow:
* - alphanumerics, dash, underscore, dot
* - no path separators, no newlines, no leading dot
* Mirrors the constraints checked by `systemd-escape`, launchd
* `Label=`, and `schtasks` at registration time — failing here gives a
* clear "invalid serviceName" error instead of a confusing OS-level
* "unit name not valid" rejection at install.
*/
export declare function validateServiceName(name: string): void;
/**
* Validate that an env var name is a portable POSIX identifier. systemd,
* launchd, and schtasks all follow the same rules:
* - [A-Za-z_][A-Za-z0-9_]*
* - no leading digit
* - empty refused
* A name like `RELAY;ExecStart=/bin/sh` would otherwise inject
* additional directives.
*/
export declare function validateEnvName(name: string): void;