@venturewild/workspace 0.1.1 → 0.1.3

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.
@@ -0,0 +1,97 @@
1
+ // logpaths — one registry for the machine-global logs so `doctor`, `logs`, and
2
+ // the operator channel all read the same set, and a tiny append/rotate/tail
3
+ // helper for the new logs we write ourselves (cli, operator).
4
+ //
5
+ // WHY a registry and not just scattered paths: a brand-new user's install is the
6
+ // riskiest moment (no Claude yet, wrong Node, port busy, daemon won't resolve),
7
+ // and "I can't see what happened on their machine" is the #1 un-debuggable
8
+ // failure. Centralising the log locations is what lets `wild-workspace doctor`
9
+ // gather them and the operator channel tail them by name — never by arbitrary
10
+ // path (the tail allowlist is TAILABLE below).
11
+ //
12
+ // NOTE: the supervisor + daemon-supervisor keep writing their logs at the
13
+ // global-dir root (supervisor.log / server.out.log / daemon.log) — those paths
14
+ // are reboot-proven and pinned by tests via an injected globalDir, so we mirror
15
+ // them here for READING rather than moving them. Everything lives under
16
+ // ~/.wild-workspace (NEVER the synced workspace — CLAUDE.md principle #1).
17
+
18
+ import os from 'node:os';
19
+ import path from 'node:path';
20
+ import fs from 'node:fs';
21
+
22
+ // THE machine-global dir. Mirrors service.mjs globalDir() + the supervisor
23
+ // defaults. Overridable via env for tests / unusual homes.
24
+ export function globalDir(env = process.env) {
25
+ return env.WILD_WORKSPACE_GLOBAL_DIR || path.join(os.homedir(), '.wild-workspace');
26
+ }
27
+
28
+ // Logical name → filename. The first three are written by existing components;
29
+ // cli + operator are new. Doctor bundles go under diagnosticsDir() (below).
30
+ export const LOG_FILES = Object.freeze({
31
+ supervisor: 'supervisor.log', // WorkspaceSupervisor watchdog
32
+ server: 'server.out.log', // the :5173 server's stdout/stderr (launcher-redirected)
33
+ daemon: 'daemon.log', // the bmo-sync daemon
34
+ cli: 'cli.log', // every `wild-workspace …` invocation (first-run capture)
35
+ operator: 'operator.log', // the consented operator channel's audit trail
36
+ });
37
+
38
+ // Logs the operator channel may tail BY NAME — never an arbitrary path.
39
+ export const TAILABLE = Object.freeze(Object.keys(LOG_FILES));
40
+
41
+ export function logFile(name, env = process.env) {
42
+ return path.join(globalDir(env), LOG_FILES[name] || `${name}.log`);
43
+ }
44
+
45
+ export function diagnosticsDir(env = process.env) {
46
+ return path.join(globalDir(env), 'diagnostics');
47
+ }
48
+
49
+ const MAX_LOG_BYTES = 2 * 1024 * 1024; // 2 MB → rotate to .1 (keep one prior gen)
50
+
51
+ // Rotate `file` to `file.1` once it grows past maxBytes. Best-effort, no throw.
52
+ export function rotateIfBig(file, maxBytes = MAX_LOG_BYTES) {
53
+ try {
54
+ if (fs.statSync(file).size > maxBytes) fs.renameSync(file, `${file}.1`);
55
+ } catch {
56
+ /* missing / racing rename — nothing to rotate */
57
+ }
58
+ }
59
+
60
+ // Append a timestamped line to a named log; ensures the dir + rotates. Returns
61
+ // the file path. Never throws — logging must not break the caller's path.
62
+ export function appendLine(name, line, env = process.env) {
63
+ const file = logFile(name, env);
64
+ try {
65
+ fs.mkdirSync(path.dirname(file), { recursive: true });
66
+ rotateIfBig(file);
67
+ fs.appendFileSync(file, `[${new Date().toISOString()}] ${line}\n`);
68
+ } catch {
69
+ /* read-only fs etc. — degrade silently */
70
+ }
71
+ return file;
72
+ }
73
+
74
+ // Last `n` lines of a file (logs are size-capped, so reading whole is cheap).
75
+ // Returns '' when the file is missing/unreadable.
76
+ export function tailFile(file, n = 200) {
77
+ try {
78
+ // Drop the trailing newline so the last line isn't an empty entry.
79
+ const lines = fs.readFileSync(file, 'utf8').replace(/\r?\n$/, '').split(/\r?\n/);
80
+ return lines.slice(Math.max(0, lines.length - n)).join('\n');
81
+ } catch {
82
+ return '';
83
+ }
84
+ }
85
+
86
+ // All known logs with on-disk size + mtime (null when absent) — for doctor/logs.
87
+ export function listLogs(env = process.env) {
88
+ return TAILABLE.map((name) => {
89
+ const file = logFile(name, env);
90
+ try {
91
+ const st = fs.statSync(file);
92
+ return { name, file, exists: true, size: st.size, mtime: st.mtimeMs };
93
+ } catch {
94
+ return { name, file, exists: false, size: null, mtime: null };
95
+ }
96
+ });
97
+ }
@@ -0,0 +1,45 @@
1
+ // Consent for the proactive session + install observability feed (session-reporter.mjs
2
+ // + transcript.mjs).
3
+ //
4
+ // DEFAULT-ON: an absent file means consented — because the disclosure is shown at
5
+ // onboarding, and this is the model the apps users already trust use (they retain
6
+ // sessions by default with an easy off). An explicit opt-out persists here. Kept
7
+ // in its own file (not agent-identity.json) so it's readable at first load —
8
+ // before the agent is even named — and trivial to flip. Mirrors operator.mjs.
9
+ //
10
+ // What "on" actually streams: WHAT happened + install health, never the words
11
+ // (redaction lives in session-reporter.mjs). Off also hard-stops the kill switch
12
+ // path WILD_WORKSPACE_NO_TELEMETRY=1, which disables ALL telemetry regardless.
13
+
14
+ import fs from 'node:fs';
15
+ import path from 'node:path';
16
+
17
+ export const OBSERVABILITY_VERSION = 1;
18
+
19
+ function consentFile(dataDir) {
20
+ return path.join(dataDir, 'observability.json');
21
+ }
22
+
23
+ export function loadObservabilityConsent(dataDir) {
24
+ try {
25
+ const p = JSON.parse(fs.readFileSync(consentFile(dataDir), 'utf8'));
26
+ return {
27
+ enabled: p.enabled !== false,
28
+ decidedAt: p.decidedAt ? Number(p.decidedAt) : null,
29
+ version: Number(p.version) || OBSERVABILITY_VERSION,
30
+ };
31
+ } catch {
32
+ return { enabled: true, decidedAt: null, version: OBSERVABILITY_VERSION }; // default-on
33
+ }
34
+ }
35
+
36
+ export function setObservabilityConsent(dataDir, enabled) {
37
+ const rec = { enabled: Boolean(enabled), decidedAt: Date.now(), version: OBSERVABILITY_VERSION };
38
+ try {
39
+ fs.mkdirSync(dataDir, { recursive: true });
40
+ fs.writeFileSync(consentFile(dataDir), JSON.stringify(rec, null, 2), { mode: 0o600 });
41
+ } catch {
42
+ /* read-only fs — fall back to in-memory for this run */
43
+ }
44
+ return rec;
45
+ }
@@ -0,0 +1,65 @@
1
+ // Operator channel token — the consented "let the wild-workspace team help with
2
+ // my install" capability (docs/SECURITY.md, docs/user-experience.md §5).
3
+ //
4
+ // SECURITY POSTURE: this channel is OFF by default. It only exists once a token
5
+ // is minted (`wild-workspace operator enable`, an explicit user opt-in). With no
6
+ // token, the operator role is unreachable and every /api/operator/* route 404s.
7
+ // The token is a separate secret from the partner token (so it can be handed to
8
+ // support + revoked independently), persisted 0600, and accepted ONLY in an
9
+ // Authorization header — never a `?t=` query (it must not leak via logs /
10
+ // history / referrer; SECURITY.md S1). Disabling deletes the token.
11
+
12
+ import fs from 'node:fs';
13
+ import path from 'node:path';
14
+ import crypto from 'node:crypto';
15
+
16
+ export function operatorFile(dataDir) {
17
+ return path.join(dataDir, 'operator.json');
18
+ }
19
+
20
+ // The token, or null when the channel is disabled (the common case).
21
+ export function loadOperatorToken(dataDir) {
22
+ try {
23
+ const parsed = JSON.parse(fs.readFileSync(operatorFile(dataDir), 'utf8'));
24
+ return typeof parsed.operatorToken === 'string' && parsed.operatorToken
25
+ ? parsed.operatorToken
26
+ : null;
27
+ } catch {
28
+ return null;
29
+ }
30
+ }
31
+
32
+ // Turn the channel on. Idempotent by default — returns the existing token if one
33
+ // is already set (so a re-run doesn't invalidate the code the user already
34
+ // shared). Pass { rotate:true } to force a fresh token. Returns the token, or
35
+ // null if it couldn't be persisted.
36
+ export function enableOperator(dataDir, { rotate = false } = {}) {
37
+ const existing = loadOperatorToken(dataDir);
38
+ if (existing && !rotate) return existing;
39
+ const token = crypto.randomBytes(24).toString('base64url');
40
+ try {
41
+ fs.mkdirSync(dataDir, { recursive: true });
42
+ fs.writeFileSync(
43
+ operatorFile(dataDir),
44
+ JSON.stringify({ operatorToken: token, enabledAt: Date.now() }, null, 2),
45
+ { mode: 0o600 },
46
+ );
47
+ } catch {
48
+ return null;
49
+ }
50
+ return token;
51
+ }
52
+
53
+ // Turn the channel off (revoke). Returns true if a token file was removed.
54
+ export function disableOperator(dataDir) {
55
+ try {
56
+ fs.rmSync(operatorFile(dataDir));
57
+ return true;
58
+ } catch {
59
+ return false;
60
+ }
61
+ }
62
+
63
+ export function operatorStatus(dataDir) {
64
+ return { enabled: Boolean(loadOperatorToken(dataDir)), file: operatorFile(dataDir) };
65
+ }
@@ -0,0 +1,297 @@
1
+ // service.mjs — installs / removes the per-OS, NO-ADMIN autostart entry that
2
+ // launches the WorkspaceSupervisor at login. See docs/always-on-design.md.
3
+ //
4
+ // Windows (proven end-to-end incl. a real reboot, 2026-05-30): writes a tiny VBS
5
+ // that runs `node <cli> service run` with no window, and registers it under
6
+ // HKCU\...\Run (per-user, NO admin / UAC).
7
+ //
8
+ // macOS (code-complete + unit-tested 2026-06-01; real-Mac reboot proof pending):
9
+ // writes a `~/Library/LaunchAgents/<label>.plist` (RunAtLoad + KeepAlive +
10
+ // ThrottleInterval) and registers it in the user's GUI domain via
11
+ // `launchctl bootstrap gui/<uid>` (legacy `launchctl load -w` fallback). Runs as
12
+ // the user, NO admin — macOS 13+ shows a one-time "Background item added" toast +
13
+ // a Login Items toggle (consent, not admin). launchd provides crash-restart for
14
+ // free; the supervisor still owns the singleton lock + child watchdog.
15
+ //
16
+ // Linux (systemd --user) is designed but not yet implemented — it returns a clear
17
+ // "not yet" result so callers degrade gracefully (the user runs `wild-workspace`).
18
+ //
19
+ // All state (the VBS / plist, service.json, the supervisor's lock/logs) lives in
20
+ // the machine-global dir (~/.wild-workspace) or ~/Library/LaunchAgents, NEVER the
21
+ // synced workspace (locked principle #1). Every external touch-point (reg.exe,
22
+ // launchctl, kill) is an injected seam for testability.
23
+
24
+ import { execFile } from 'node:child_process';
25
+ import { promisify } from 'node:util';
26
+ import fs from 'node:fs';
27
+ import os from 'node:os';
28
+ import path from 'node:path';
29
+
30
+ const execFileP = promisify(execFile);
31
+
32
+ export const RUN_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';
33
+ export const RUN_VALUE_NAME = 'WildWorkspace';
34
+ export const LAUNCHD_LABEL = 'llc.venturewild.workspace';
35
+
36
+ export function globalDir() { return path.join(os.homedir(), '.wild-workspace'); }
37
+ function defaultLaunchAgentsDir() { return path.join(os.homedir(), 'Library', 'LaunchAgents'); }
38
+ function currentUid() { return typeof process.getuid === 'function' ? process.getuid() : 0; }
39
+
40
+ /** Is per-user autostart implemented for this platform yet? */
41
+ export function isSupported(platform = process.platform) {
42
+ return platform === 'win32' || platform === 'darwin';
43
+ }
44
+
45
+ /** Shared: read the supervisor's pidfile and report whether that pid is alive. */
46
+ function supervisorLiveness(dir) {
47
+ let supervisorPid = null, supervisorAlive = false;
48
+ try { supervisorPid = Number(fs.readFileSync(path.join(dir, 'supervisor.lock'), 'utf8').trim()) || null; } catch { /* none */ }
49
+ if (supervisorPid) {
50
+ try { process.kill(supervisorPid, 0); supervisorAlive = true; } catch (e) { supervisorAlive = !!(e && e.code === 'EPERM'); }
51
+ }
52
+ return { supervisorPid, supervisorAlive };
53
+ }
54
+
55
+ // --- Windows implementation -------------------------------------------------
56
+
57
+ // A VBS that runs `node <cli> service run` with NO window (0 = SW_HIDE,
58
+ // False = don't wait). VBS string literals escape a `"` as `""`.
59
+ export function buildVbs(node, cli) {
60
+ const cmd = `"${node}" "${cli}" service run`;
61
+ const vbsArg = '"' + cmd.replace(/"/g, '""') + '"';
62
+ return [
63
+ "' wild-workspace always-on launcher (generated by `wild-workspace service install`).",
64
+ "' Starts the workspace supervisor hidden at login. Disable via",
65
+ "' `wild-workspace service uninstall` (removes the HKCU\\...\\Run value).",
66
+ `CreateObject("WScript.Shell").Run ${vbsArg}, 0, False`,
67
+ '',
68
+ ].join('\r\n');
69
+ }
70
+
71
+ /** The HKCU\Run value: launch the VBS via the windowless wscript host. */
72
+ export function buildRunValue(vbs) { return `wscript.exe "${vbs}"`; }
73
+
74
+ async function winInstall({ node, cli, workspaceDir, port, version }, { dir, execFileImpl }) {
75
+ fs.mkdirSync(dir, { recursive: true });
76
+ const vbs = path.join(dir, 'launch-hidden.vbs');
77
+ const serviceJson = path.join(dir, 'service.json');
78
+ fs.writeFileSync(vbs, buildVbs(node, cli), 'utf8');
79
+ fs.writeFileSync(
80
+ serviceJson,
81
+ JSON.stringify({ node, cli, workspaceDir, port, version, installedAt: new Date().toISOString() }, null, 2),
82
+ 'utf8',
83
+ );
84
+ const runValue = buildRunValue(vbs);
85
+ await execFileImpl('reg', ['add', RUN_KEY, '/v', RUN_VALUE_NAME, '/t', 'REG_SZ', '/d', runValue, '/f']);
86
+ return { installed: true, mechanism: 'HKCU\\Run', launcher: vbs, vbs, runValue, serviceJson };
87
+ }
88
+
89
+ async function winUninstall({ dir, execFileImpl, killImpl }) {
90
+ let removedKey = false;
91
+ try { await execFileImpl('reg', ['delete', RUN_KEY, '/v', RUN_VALUE_NAME, '/f']); removedKey = true; } catch { /* not present */ }
92
+ let stoppedPid = null;
93
+ try {
94
+ const pid = Number(fs.readFileSync(path.join(dir, 'supervisor.lock'), 'utf8').trim());
95
+ if (pid) { killImpl(pid); stoppedPid = pid; }
96
+ } catch { /* none running */ }
97
+ for (const f of ['launch-hidden.vbs', 'service.json']) { try { fs.unlinkSync(path.join(dir, f)); } catch { /* gone */ } }
98
+ return { uninstalled: true, removedKey, stoppedPid };
99
+ }
100
+
101
+ async function winStatus({ dir, execFileImpl, probeImpl, port }) {
102
+ let installed = false, runValue = null;
103
+ try {
104
+ const { stdout } = await execFileImpl('reg', ['query', RUN_KEY, '/v', RUN_VALUE_NAME]);
105
+ installed = new RegExp(RUN_VALUE_NAME, 'i').test(stdout);
106
+ runValue = (stdout.match(/REG_SZ\s+(.*?)\s*$/m) || [])[1] || null;
107
+ } catch { /* value absent → not installed */ }
108
+ const { supervisorPid, supervisorAlive } = supervisorLiveness(dir);
109
+ const serverUp = await probeImpl(port);
110
+ return { installed, runValue, supervisorPid, supervisorAlive, serverUp };
111
+ }
112
+
113
+ // --- macOS implementation ---------------------------------------------------
114
+
115
+ export function plistPath(launchAgentsDir) {
116
+ return path.join(launchAgentsDir, `${LAUNCHD_LABEL}.plist`);
117
+ }
118
+
119
+ function xmlEscape(s) {
120
+ return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
121
+ }
122
+
123
+ // A LaunchAgent that runs `node <cli> service run` at login + relaunches it if it
124
+ // dies (KeepAlive). ThrottleInterval bounds the restart rate. Output is logged to
125
+ // ~/.wild-workspace so a silent death is debuggable (footgun checklist §8).
126
+ export function buildPlist({ node, cli, workspaceDir, outLog, errLog, label = LAUNCHD_LABEL }) {
127
+ const args = [node, cli, 'service', 'run'].map((a) => ` <string>${xmlEscape(a)}</string>`);
128
+ const env = workspaceDir ? [
129
+ ' <key>EnvironmentVariables</key>',
130
+ ' <dict>',
131
+ ' <key>WILD_WORKSPACE_DIR</key>',
132
+ ` <string>${xmlEscape(workspaceDir)}</string>`,
133
+ ' </dict>',
134
+ ] : [];
135
+ return [
136
+ '<?xml version="1.0" encoding="UTF-8"?>',
137
+ '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
138
+ '<plist version="1.0">',
139
+ '<dict>',
140
+ ' <key>Label</key>',
141
+ ` <string>${xmlEscape(label)}</string>`,
142
+ ' <key>ProgramArguments</key>',
143
+ ' <array>',
144
+ ...args,
145
+ ' </array>',
146
+ ' <key>RunAtLoad</key>',
147
+ ' <true/>',
148
+ ' <key>KeepAlive</key>',
149
+ ' <true/>',
150
+ ' <key>ThrottleInterval</key>',
151
+ ' <integer>10</integer>',
152
+ ...env,
153
+ ' <key>StandardOutPath</key>',
154
+ ` <string>${xmlEscape(outLog)}</string>`,
155
+ ' <key>StandardErrorPath</key>',
156
+ ` <string>${xmlEscape(errLog)}</string>`,
157
+ '</dict>',
158
+ '</plist>',
159
+ '',
160
+ ].join('\n');
161
+ }
162
+
163
+ async function macInstall({ node, cli, workspaceDir, port, version }, { dir, launchAgentsDir, execFileImpl, uid }) {
164
+ fs.mkdirSync(dir, { recursive: true });
165
+ fs.mkdirSync(launchAgentsDir, { recursive: true });
166
+ const plist = plistPath(launchAgentsDir);
167
+ const serviceJson = path.join(dir, 'service.json');
168
+ const outLog = path.join(dir, 'launchagent.out.log');
169
+ const errLog = path.join(dir, 'launchagent.err.log');
170
+ fs.writeFileSync(plist, buildPlist({ node, cli, workspaceDir, outLog, errLog }), 'utf8');
171
+ fs.writeFileSync(
172
+ serviceJson,
173
+ JSON.stringify({ node, cli, workspaceDir, port, version, installedAt: new Date().toISOString() }, null, 2),
174
+ 'utf8',
175
+ );
176
+ const domain = `gui/${uid}`;
177
+ const target = `${domain}/${LAUNCHD_LABEL}`;
178
+ // Clear any prior registration so a changed plist is picked up (launchd caches
179
+ // the loaded plist; bootout→bootstrap makes re-install idempotent).
180
+ try { await execFileImpl('launchctl', ['bootout', target]); } catch { /* not loaded */ }
181
+ let loadVerb = 'bootstrap';
182
+ try {
183
+ await execFileImpl('launchctl', ['bootstrap', domain, plist]);
184
+ } catch {
185
+ // Pre-Yosemite-style macOS without `bootstrap` — fall back to the legacy verb.
186
+ await execFileImpl('launchctl', ['load', '-w', plist]);
187
+ loadVerb = 'load';
188
+ }
189
+ return { installed: true, mechanism: 'LaunchAgent', launcher: plist, plist, label: LAUNCHD_LABEL, runValue: target, serviceJson, loadVerb };
190
+ }
191
+
192
+ async function macUninstall({ dir, launchAgentsDir, execFileImpl, killImpl, uid }) {
193
+ const plist = plistPath(launchAgentsDir);
194
+ const target = `gui/${uid}/${LAUNCHD_LABEL}`;
195
+ try {
196
+ await execFileImpl('launchctl', ['bootout', target]);
197
+ } catch {
198
+ try { await execFileImpl('launchctl', ['unload', '-w', plist]); } catch { /* not loaded */ }
199
+ }
200
+ // launchd's bootout SIGTERMs the launchd-managed supervisor; a manually-started
201
+ // one still holds the lock, so stop it too (mirrors the Windows path).
202
+ let stoppedPid = null;
203
+ try {
204
+ const pid = Number(fs.readFileSync(path.join(dir, 'supervisor.lock'), 'utf8').trim());
205
+ if (pid) { killImpl(pid); stoppedPid = pid; }
206
+ } catch { /* none running */ }
207
+ let removedKey = false;
208
+ try { if (fs.existsSync(plist)) { fs.unlinkSync(plist); removedKey = true; } } catch { /* gone */ }
209
+ try { fs.unlinkSync(path.join(dir, 'service.json')); } catch { /* gone */ }
210
+ return { uninstalled: true, removedKey, stoppedPid };
211
+ }
212
+
213
+ async function macStatus({ dir, launchAgentsDir, execFileImpl, probeImpl, uid, port }) {
214
+ const plist = plistPath(launchAgentsDir);
215
+ const installed = fs.existsSync(plist); // the plist IS the persistent registration
216
+ const target = `gui/${uid}/${LAUNCHD_LABEL}`;
217
+ let loaded = false, launchdPid = null;
218
+ try {
219
+ const { stdout } = await execFileImpl('launchctl', ['print', target]);
220
+ launchdPid = Number((stdout.match(/\bpid\s*=\s*(\d+)/i) || [])[1]) || null;
221
+ loaded = launchdPid !== null || /state\s*=\s*running/i.test(stdout);
222
+ } catch { /* not loaded into launchd */ }
223
+ let { supervisorPid, supervisorAlive } = supervisorLiveness(dir);
224
+ if (launchdPid) { supervisorPid = launchdPid; supervisorAlive = true; }
225
+ else if (loaded) { supervisorAlive = true; }
226
+ const serverUp = await probeImpl(port);
227
+ return { installed, runValue: installed ? plist : null, supervisorPid, supervisorAlive, serverUp, loaded };
228
+ }
229
+
230
+ // --- public API (platform dispatch) ----------------------------------------
231
+
232
+ const unsupported = (platform, key) => ({
233
+ [key]: false,
234
+ supported: false,
235
+ platform,
236
+ message: `always-on autostart for ${platform} is not implemented yet — run \`wild-workspace\` to start manually (see docs/always-on-design.md)`,
237
+ });
238
+
239
+ export async function installService(opts = {}, deps = {}) {
240
+ const platform = deps.platform || process.platform;
241
+ if (platform === 'win32') {
242
+ return winInstall(opts, { dir: deps.dir || globalDir(), execFileImpl: deps.execFileImpl || execFileP });
243
+ }
244
+ if (platform === 'darwin') {
245
+ return macInstall(opts, {
246
+ dir: deps.dir || globalDir(),
247
+ launchAgentsDir: deps.launchAgentsDir || defaultLaunchAgentsDir(),
248
+ execFileImpl: deps.execFileImpl || execFileP,
249
+ uid: deps.uid ?? currentUid(),
250
+ });
251
+ }
252
+ return unsupported(platform, 'installed');
253
+ }
254
+
255
+ export async function uninstallService(deps = {}) {
256
+ const platform = deps.platform || process.platform;
257
+ if (platform === 'win32') {
258
+ return winUninstall({
259
+ dir: deps.dir || globalDir(),
260
+ execFileImpl: deps.execFileImpl || execFileP,
261
+ killImpl: deps.killImpl || ((pid) => process.kill(pid)),
262
+ });
263
+ }
264
+ if (platform === 'darwin') {
265
+ return macUninstall({
266
+ dir: deps.dir || globalDir(),
267
+ launchAgentsDir: deps.launchAgentsDir || defaultLaunchAgentsDir(),
268
+ execFileImpl: deps.execFileImpl || execFileP,
269
+ killImpl: deps.killImpl || ((pid) => process.kill(pid)),
270
+ uid: deps.uid ?? currentUid(),
271
+ });
272
+ }
273
+ return unsupported(platform, 'uninstalled');
274
+ }
275
+
276
+ export async function serviceStatus(opts = {}, deps = {}) {
277
+ const platform = deps.platform || process.platform;
278
+ if (platform === 'win32') {
279
+ return winStatus({
280
+ dir: deps.dir || globalDir(),
281
+ execFileImpl: deps.execFileImpl || execFileP,
282
+ probeImpl: deps.probeImpl || (async () => false),
283
+ port: opts.port || 5173,
284
+ });
285
+ }
286
+ if (platform === 'darwin') {
287
+ return macStatus({
288
+ dir: deps.dir || globalDir(),
289
+ launchAgentsDir: deps.launchAgentsDir || defaultLaunchAgentsDir(),
290
+ execFileImpl: deps.execFileImpl || execFileP,
291
+ probeImpl: deps.probeImpl || (async () => false),
292
+ uid: deps.uid ?? currentUid(),
293
+ port: opts.port || 5173,
294
+ });
295
+ }
296
+ return { supported: false, platform };
297
+ }