@dev-anywhere/proxy 0.9.0 → 0.9.2

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 (73) hide show
  1. package/README.md +25 -3
  2. package/dist/autostart-C3RNQ65S.js +292 -0
  3. package/dist/autostart-C3RNQ65S.js.map +1 -0
  4. package/dist/chunk-2YUDGRJ6.js +379 -0
  5. package/dist/chunk-2YUDGRJ6.js.map +1 -0
  6. package/dist/chunk-74HWO753.js +285 -0
  7. package/dist/chunk-74HWO753.js.map +1 -0
  8. package/dist/chunk-77QVUYU7.js +42 -0
  9. package/dist/chunk-77QVUYU7.js.map +1 -0
  10. package/dist/{chunk-HWPURRXB.js → chunk-7LUBU2WA.js} +10 -2
  11. package/dist/{chunk-HWPURRXB.js.map → chunk-7LUBU2WA.js.map} +1 -1
  12. package/dist/chunk-DAFUSBKJ.js +299 -0
  13. package/dist/chunk-DAFUSBKJ.js.map +1 -0
  14. package/dist/{chunk-HLN3NOD2.js → chunk-GFDOVLGL.js} +70 -1
  15. package/dist/chunk-GFDOVLGL.js.map +1 -0
  16. package/dist/{chunk-SEMZ7GW7.js → chunk-GYL5JKWQ.js} +3 -3
  17. package/dist/{chunk-57LA2LWY.js → chunk-HYDXGNKA.js} +2 -2
  18. package/dist/chunk-ICSO3ZIS.js +658 -0
  19. package/dist/chunk-ICSO3ZIS.js.map +1 -0
  20. package/dist/chunk-JZ7MWN24.js +22 -0
  21. package/dist/chunk-JZ7MWN24.js.map +1 -0
  22. package/dist/chunk-KINQESTO.js +145 -0
  23. package/dist/chunk-KINQESTO.js.map +1 -0
  24. package/dist/{chunk-ZNMJH7BK.js → chunk-KWODOJBK.js} +3 -3
  25. package/dist/chunk-MLE2OKCM.js +116 -0
  26. package/dist/chunk-MLE2OKCM.js.map +1 -0
  27. package/dist/{chunk-UJEZAG57.js → chunk-PCF2R2TG.js} +3 -1
  28. package/dist/{chunk-UJEZAG57.js.map → chunk-PCF2R2TG.js.map} +1 -1
  29. package/dist/{chunk-RN3KQK6E.js → chunk-V4HDLUAQ.js} +770 -774
  30. package/dist/chunk-V4HDLUAQ.js.map +1 -0
  31. package/dist/{chunk-DZ4GXMP5.js → chunk-VHMAUU72.js} +56 -68
  32. package/dist/chunk-VHMAUU72.js.map +1 -0
  33. package/dist/{chunk-K72MFCMC.js → chunk-XADKKDUV.js} +29 -153
  34. package/dist/chunk-XADKKDUV.js.map +1 -0
  35. package/dist/{chunk-WRU3BXW6.js → chunk-YK2XKOP4.js} +26 -10
  36. package/dist/chunk-YK2XKOP4.js.map +1 -0
  37. package/dist/index.js +130 -343
  38. package/dist/index.js.map +1 -1
  39. package/dist/logger-24TGGN76.js +10 -0
  40. package/dist/logger-24TGGN76.js.map +1 -0
  41. package/dist/logger-B7B64O4P.js +14 -0
  42. package/dist/logger-B7B64O4P.js.map +1 -0
  43. package/dist/{quick-tunnel-RI62V2RH.js → quick-tunnel-ZIFTYUUD.js} +3 -3
  44. package/dist/{relay-token-ZP3PAZD2.js → relay-token-N3BSBURG.js} +5 -5
  45. package/dist/serve.js +1290 -371
  46. package/dist/serve.js.map +1 -1
  47. package/dist/session-worker.js +91 -76
  48. package/dist/session-worker.js.map +1 -1
  49. package/dist/{terminal-AHMO45YN.js → terminal-7JY6J3XN.js} +88 -36
  50. package/dist/terminal-7JY6J3XN.js.map +1 -0
  51. package/dist/terminal-worker.js +93 -44
  52. package/dist/terminal-worker.js.map +1 -1
  53. package/dist/update-runner.js +87 -62
  54. package/dist/update-runner.js.map +1 -1
  55. package/package.json +9 -6
  56. package/scripts/postinstall.cjs +22 -0
  57. package/dist/chunk-DZ4GXMP5.js.map +0 -1
  58. package/dist/chunk-HLN3NOD2.js.map +0 -1
  59. package/dist/chunk-K72MFCMC.js.map +0 -1
  60. package/dist/chunk-KGTYU4WO.js +0 -36
  61. package/dist/chunk-KGTYU4WO.js.map +0 -1
  62. package/dist/chunk-RN3KQK6E.js.map +0 -1
  63. package/dist/chunk-WC3KEY7N.js +0 -158
  64. package/dist/chunk-WC3KEY7N.js.map +0 -1
  65. package/dist/chunk-WRU3BXW6.js.map +0 -1
  66. package/dist/chunk-YM74AWYC.js +0 -155
  67. package/dist/chunk-YM74AWYC.js.map +0 -1
  68. package/dist/terminal-AHMO45YN.js.map +0 -1
  69. /package/dist/{chunk-SEMZ7GW7.js.map → chunk-GYL5JKWQ.js.map} +0 -0
  70. /package/dist/{chunk-57LA2LWY.js.map → chunk-HYDXGNKA.js.map} +0 -0
  71. /package/dist/{chunk-ZNMJH7BK.js.map → chunk-KWODOJBK.js.map} +0 -0
  72. /package/dist/{quick-tunnel-RI62V2RH.js.map → quick-tunnel-ZIFTYUUD.js.map} +0 -0
  73. /package/dist/{relay-token-ZP3PAZD2.js.map → relay-token-N3BSBURG.js.map} +0 -0
@@ -0,0 +1,379 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ acquireFileLock,
4
+ requestServiceControl,
5
+ tryAcquireFileLock,
6
+ tryConnectSocket
7
+ } from "./chunk-DAFUSBKJ.js";
8
+ import {
9
+ spawnScript
10
+ } from "./chunk-PCF2R2TG.js";
11
+ import {
12
+ DESIRED_RELAY_PATH,
13
+ PROFILE_NAME,
14
+ SERVICE_CONTROL_PATH,
15
+ SERVICE_OPERATION_LOCK_PATH,
16
+ SERVICE_RUNTIME_LOCK_PATH,
17
+ SOCK_PATH,
18
+ STOPPED_PATH,
19
+ ensureProfileWorkspace
20
+ } from "./chunk-YK2XKOP4.js";
21
+
22
+ // src/common/daemon-env.ts
23
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
24
+ import { dirname } from "path";
25
+ function setDesiredDaemonRelay(relayName) {
26
+ const normalized = relayName?.trim();
27
+ if (normalized) {
28
+ mkdirSync(dirname(DESIRED_RELAY_PATH), { recursive: true });
29
+ writeFileSync(DESIRED_RELAY_PATH, `${normalized}
30
+ `);
31
+ return;
32
+ }
33
+ try {
34
+ unlinkSync(DESIRED_RELAY_PATH);
35
+ } catch {
36
+ }
37
+ }
38
+ function readDesiredDaemonRelay() {
39
+ if (!existsSync(DESIRED_RELAY_PATH)) return void 0;
40
+ const value = readFileSync(DESIRED_RELAY_PATH, "utf-8").trim();
41
+ return value || void 0;
42
+ }
43
+ function daemonRelayArgs(relayName) {
44
+ const selected = relayName?.trim() || readDesiredDaemonRelay();
45
+ return selected ? ["--relay", selected] : [];
46
+ }
47
+
48
+ // src/common/service-lifecycle.ts
49
+ import { randomUUID } from "crypto";
50
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "fs";
51
+ import { dirname as dirname2 } from "path";
52
+ import { setTimeout as sleep } from "timers/promises";
53
+ var ServiceLifecycleError = class extends Error {
54
+ constructor(code, message, options) {
55
+ super(message, options);
56
+ this.code = code;
57
+ this.name = "ServiceLifecycleError";
58
+ }
59
+ code;
60
+ recoveryToken;
61
+ };
62
+ function messageOf(error) {
63
+ return error instanceof Error ? error.message : String(error);
64
+ }
65
+ function runtimeIsFree(path) {
66
+ const lock = tryAcquireFileLock(path);
67
+ if (!lock) return false;
68
+ lock.release();
69
+ return true;
70
+ }
71
+ async function socketIsOccupied(path, timeoutMs) {
72
+ const socket = await tryConnectSocket(path, timeoutMs);
73
+ socket?.destroy();
74
+ return socket !== null;
75
+ }
76
+ function childHasExited(child) {
77
+ return child.exitCode !== null || child.signalCode !== null;
78
+ }
79
+ async function stopOwnChild(child) {
80
+ if (!child.pid || childHasExited(child)) return;
81
+ for (const [signal, timeoutMs] of [
82
+ ["SIGTERM", 2e3],
83
+ ["SIGKILL", 1e3]
84
+ ]) {
85
+ const exited = await new Promise((resolve, reject) => {
86
+ let timer;
87
+ const finish = (value) => {
88
+ if (timer) clearTimeout(timer);
89
+ child.off("exit", onExit);
90
+ resolve(value);
91
+ };
92
+ const onExit = () => finish(true);
93
+ child.once("exit", onExit);
94
+ try {
95
+ child.kill(signal);
96
+ } catch (error) {
97
+ child.off("exit", onExit);
98
+ if (childHasExited(child)) resolve(true);
99
+ else reject(error);
100
+ return;
101
+ }
102
+ if (childHasExited(child)) finish(true);
103
+ else timer = setTimeout(() => finish(false), timeoutMs);
104
+ });
105
+ if (exited) return;
106
+ }
107
+ throw new Error("The service child did not exit after termination");
108
+ }
109
+ function createServiceLifecycle(options) {
110
+ const startupTimeoutMs = options.startupTimeoutMs ?? 3e4;
111
+ const stopTimeoutMs = options.stopTimeoutMs ?? 1e4;
112
+ for (const timeout of [startupTimeoutMs, stopTimeoutMs]) {
113
+ if (!Number.isFinite(timeout) || timeout <= 0) throw new TypeError("Invalid service timeout");
114
+ }
115
+ if (options.runtimeLockPath === options.operationLockPath) {
116
+ throw new TypeError("Service operation and runtime locks must be different");
117
+ }
118
+ const control = async (action, timeoutMs = 5e3) => {
119
+ let status;
120
+ try {
121
+ status = await requestServiceControl(options.controlPath, action, timeoutMs);
122
+ } catch (error) {
123
+ throw new ServiceLifecycleError("STOP_FAILED", "Service control could not be verified", {
124
+ cause: error
125
+ });
126
+ }
127
+ if (status && status.profile !== options.profile) {
128
+ throw new ServiceLifecycleError("STOP_FAILED", "Service control belongs to another profile");
129
+ }
130
+ return status;
131
+ };
132
+ const budget = (deadline) => Math.max(1, Math.min(5e3, deadline - Date.now()));
133
+ const pause = (deadline) => sleep(Math.max(1, Math.min(50, deadline - Date.now())));
134
+ const markStopped = () => {
135
+ mkdirSync2(dirname2(options.stoppedPath), { recursive: true });
136
+ const token = randomUUID();
137
+ writeFileSync2(options.stoppedPath, token, { mode: 384 });
138
+ return token;
139
+ };
140
+ const stoppedToken = () => {
141
+ try {
142
+ return readFileSync2(options.stoppedPath, "utf8");
143
+ } catch (error) {
144
+ if (error.code === "ENOENT") return null;
145
+ throw error;
146
+ }
147
+ };
148
+ const clearStopped = () => {
149
+ try {
150
+ unlinkSync2(options.stoppedPath);
151
+ } catch (error) {
152
+ if (error.code !== "ENOENT") throw error;
153
+ }
154
+ };
155
+ const unsupported = () => new ServiceLifecycleError(
156
+ "UNSUPPORTED_SERVICE",
157
+ "An existing service cannot be managed by this version. Stop it using the CLI that started it before retrying."
158
+ );
159
+ const withOperation = async (run) => {
160
+ let lock;
161
+ try {
162
+ lock = await acquireFileLock(options.operationLockPath, {
163
+ timeoutMs: startupTimeoutMs + stopTimeoutMs
164
+ });
165
+ } catch (error) {
166
+ throw new ServiceLifecycleError("STOP_FAILED", "Another service operation is still active", {
167
+ cause: error
168
+ });
169
+ }
170
+ try {
171
+ return await run();
172
+ } finally {
173
+ lock.release();
174
+ }
175
+ };
176
+ const canStart = async (deadline) => {
177
+ const runtime = tryAcquireFileLock(options.runtimeLockPath);
178
+ if (!runtime) return false;
179
+ try {
180
+ if (await socketIsOccupied(options.socketPath, budget(deadline))) throw unsupported();
181
+ if (await control("status", budget(deadline))) {
182
+ throw new ServiceLifecycleError(
183
+ "STOP_FAILED",
184
+ "Service control is live without runtime ownership"
185
+ );
186
+ }
187
+ return true;
188
+ } finally {
189
+ runtime.release();
190
+ }
191
+ };
192
+ const startInternal = async (intent, expectedStoppedToken, foreground) => {
193
+ if (expectedStoppedToken !== void 0 && stoppedToken() !== expectedStoppedToken) {
194
+ throw new ServiceLifecycleError(
195
+ "STOPPED",
196
+ "The service stop state changed; recovery was cancelled"
197
+ );
198
+ }
199
+ if (intent === "recover" && existsSync2(options.stoppedPath) && expectedStoppedToken === void 0) {
200
+ throw new ServiceLifecycleError("STOPPED", "Service was explicitly stopped");
201
+ }
202
+ if (intent === "explicit" || expectedStoppedToken !== void 0) clearStopped();
203
+ const deadline = Date.now() + startupTimeoutMs;
204
+ let child;
205
+ let childFailure;
206
+ const onChildError = (error) => {
207
+ childFailure = error;
208
+ };
209
+ try {
210
+ while (Date.now() < deadline) {
211
+ const current = await control("status", budget(deadline));
212
+ if (current?.state === "ready") {
213
+ if (runtimeIsFree(options.runtimeLockPath)) {
214
+ throw new ServiceLifecycleError(
215
+ "STOP_FAILED",
216
+ "Service control is live without runtime ownership"
217
+ );
218
+ }
219
+ return { status: "ready", service: current };
220
+ }
221
+ if (childFailure) throw childFailure;
222
+ if (child && childHasExited(child)) {
223
+ throw new Error(
224
+ `Service child exited during startup (code=${child.exitCode}, signal=${child.signalCode})`
225
+ );
226
+ }
227
+ if (!child && !current && await canStart(deadline)) {
228
+ if (foreground) {
229
+ let timer;
230
+ try {
231
+ await Promise.race([
232
+ foreground(),
233
+ new Promise((_, reject) => {
234
+ timer = setTimeout(
235
+ () => reject(new Error("Foreground service startup timed out")),
236
+ Math.max(1, deadline - Date.now())
237
+ );
238
+ })
239
+ ]);
240
+ } finally {
241
+ if (timer) clearTimeout(timer);
242
+ }
243
+ const service = await control("status", budget(deadline));
244
+ if (service?.state !== "ready") throw new Error("Service did not publish readiness");
245
+ if (runtimeIsFree(options.runtimeLockPath)) {
246
+ throw new ServiceLifecycleError(
247
+ "STOP_FAILED",
248
+ "Foreground service did not retain runtime ownership"
249
+ );
250
+ }
251
+ return { status: "ready", service };
252
+ }
253
+ child = options.spawn();
254
+ child.once("error", onChildError);
255
+ }
256
+ await pause(deadline);
257
+ }
258
+ throw new Error(`Service did not become ready within ${startupTimeoutMs}ms`);
259
+ } catch (error) {
260
+ if (child) {
261
+ try {
262
+ await stopOwnChild(child);
263
+ } catch (terminationError) {
264
+ throw new ServiceLifecycleError("STOP_FAILED", "Could not confirm service child exit", {
265
+ cause: terminationError
266
+ });
267
+ }
268
+ }
269
+ if (error instanceof ServiceLifecycleError) throw error;
270
+ try {
271
+ if (!await canStart(Date.now() + 1e3)) {
272
+ throw new ServiceLifecycleError(
273
+ "STOP_FAILED",
274
+ "A service is still running but could not be managed",
275
+ { cause: error }
276
+ );
277
+ }
278
+ } catch (inspectionError) {
279
+ if (inspectionError instanceof ServiceLifecycleError) throw inspectionError;
280
+ throw new ServiceLifecycleError(
281
+ "STOP_FAILED",
282
+ "Could not verify the service state after startup failure",
283
+ { cause: inspectionError }
284
+ );
285
+ }
286
+ throw new ServiceLifecycleError(
287
+ "START_FAILED",
288
+ `Service failed to start: ${messageOf(error)}`,
289
+ { cause: error }
290
+ );
291
+ } finally {
292
+ child?.off("error", onChildError);
293
+ child?.unref();
294
+ }
295
+ };
296
+ const stopInternal = async () => {
297
+ markStopped();
298
+ const deadline = Date.now() + stopTimeoutMs;
299
+ let stopRequested = false;
300
+ try {
301
+ while (Date.now() < deadline) {
302
+ if (!stopRequested) {
303
+ const service = await control("stop", budget(deadline));
304
+ stopRequested = service !== null;
305
+ }
306
+ const runtime = tryAcquireFileLock(options.runtimeLockPath);
307
+ if (runtime) {
308
+ try {
309
+ if (await socketIsOccupied(options.socketPath, budget(deadline))) throw unsupported();
310
+ if (await control("status", budget(deadline))) {
311
+ throw new ServiceLifecycleError(
312
+ "STOP_FAILED",
313
+ "Service control is still live after runtime ownership ended"
314
+ );
315
+ }
316
+ return;
317
+ } finally {
318
+ runtime.release();
319
+ }
320
+ }
321
+ await pause(deadline);
322
+ }
323
+ throw new Error(`Service did not stop within ${stopTimeoutMs}ms`);
324
+ } catch (error) {
325
+ if (error instanceof ServiceLifecycleError) throw error;
326
+ throw new ServiceLifecycleError(
327
+ "STOP_FAILED",
328
+ `Could not confirm service stop: ${messageOf(error)}`,
329
+ { cause: error }
330
+ );
331
+ }
332
+ };
333
+ return {
334
+ status: () => control("status"),
335
+ start: (intent, expectedStoppedToken) => withOperation(() => startInternal(intent, expectedStoppedToken)),
336
+ startForeground: (start) => withOperation(() => startInternal("explicit", void 0, start)),
337
+ stop: () => withOperation(stopInternal),
338
+ restart: (intent = "explicit") => withOperation(async () => {
339
+ if (intent === "recover" && existsSync2(options.stoppedPath)) {
340
+ throw new ServiceLifecycleError("STOPPED", "Service was explicitly stopped");
341
+ }
342
+ await stopInternal();
343
+ try {
344
+ return await startInternal("explicit");
345
+ } catch (error) {
346
+ const token = markStopped();
347
+ if (error instanceof ServiceLifecycleError && error.code === "START_FAILED") {
348
+ error.recoveryToken = token;
349
+ }
350
+ throw error;
351
+ }
352
+ })
353
+ };
354
+ }
355
+
356
+ // src/common/profile-service.ts
357
+ function createProfileServiceLifecycle(options = {}) {
358
+ ensureProfileWorkspace();
359
+ return createServiceLifecycle({
360
+ profile: PROFILE_NAME,
361
+ socketPath: SOCK_PATH,
362
+ controlPath: SERVICE_CONTROL_PATH,
363
+ runtimeLockPath: SERVICE_RUNTIME_LOCK_PATH,
364
+ operationLockPath: SERVICE_OPERATION_LOCK_PATH,
365
+ stoppedPath: STOPPED_PATH,
366
+ spawn: () => spawnScript("serve", ["--profile", PROFILE_NAME, ...daemonRelayArgs(options.relayName)], {
367
+ env: { ...options.env ?? process.env },
368
+ stdio: "ignore",
369
+ unref: false
370
+ })
371
+ });
372
+ }
373
+
374
+ export {
375
+ setDesiredDaemonRelay,
376
+ ServiceLifecycleError,
377
+ createProfileServiceLifecycle
378
+ };
379
+ //# sourceMappingURL=chunk-2YUDGRJ6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common/daemon-env.ts","../src/common/service-lifecycle.ts","../src/common/profile-service.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { DESIRED_RELAY_PATH } from \"./paths.js\";\n\nexport function setDesiredDaemonRelay(relayName: string | undefined): void {\n const normalized = relayName?.trim();\n if (normalized) {\n mkdirSync(dirname(DESIRED_RELAY_PATH), { recursive: true });\n writeFileSync(DESIRED_RELAY_PATH, `${normalized}\\n`);\n return;\n }\n try {\n unlinkSync(DESIRED_RELAY_PATH);\n } catch {\n // Missing desired-relay file means \"use the selected profile's relay\".\n }\n}\n\nfunction readDesiredDaemonRelay(): string | undefined {\n if (!existsSync(DESIRED_RELAY_PATH)) return undefined;\n const value = readFileSync(DESIRED_RELAY_PATH, \"utf-8\").trim();\n return value || undefined;\n}\n\nexport function daemonRelayArgs(relayName?: string): string[] {\n const selected = relayName?.trim() || readDesiredDaemonRelay();\n return selected ? [\"--relay\", selected] : [];\n}\n","import type { ChildProcess } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\nimport { acquireFileLock, tryAcquireFileLock } from \"./file-lock.js\";\nimport { requestServiceControl, type ServiceStatus } from \"./service-control.js\";\nimport { tryConnectSocket } from \"./socket-connect.js\";\n\nexport type ServiceLifecycleErrorCode =\n | \"STOP_FAILED\"\n | \"START_FAILED\"\n | \"STOPPED\"\n | \"UNSUPPORTED_SERVICE\";\n\nexport class ServiceLifecycleError extends Error {\n recoveryToken?: string;\n\n constructor(\n readonly code: ServiceLifecycleErrorCode,\n message: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = \"ServiceLifecycleError\";\n }\n}\n\nexport interface ServiceLifecycleOptions {\n profile: string;\n controlPath: string;\n socketPath: string;\n runtimeLockPath: string;\n operationLockPath: string;\n stoppedPath: string;\n spawn(): ChildProcess;\n startupTimeoutMs?: number;\n stopTimeoutMs?: number;\n}\n\nexport interface ServiceReadyResult {\n status: \"ready\";\n service: ServiceStatus;\n}\n\nexport interface ServiceLifecycle {\n status(): Promise<ServiceStatus | null>;\n start(intent: \"explicit\" | \"recover\", expectedStoppedToken?: string): Promise<ServiceReadyResult>;\n startForeground(start: () => Promise<void>): Promise<ServiceReadyResult>;\n stop(): Promise<void>;\n restart(intent?: \"explicit\" | \"recover\"): Promise<ServiceReadyResult>;\n}\n\nfunction messageOf(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nfunction runtimeIsFree(path: string): boolean {\n const lock = tryAcquireFileLock(path);\n if (!lock) return false;\n lock.release();\n return true;\n}\n\nasync function socketIsOccupied(path: string, timeoutMs: number): Promise<boolean> {\n const socket = await tryConnectSocket(path, timeoutMs);\n socket?.destroy();\n return socket !== null;\n}\n\nfunction childHasExited(child: ChildProcess): boolean {\n return child.exitCode !== null || child.signalCode !== null;\n}\n\nasync function stopOwnChild(child: ChildProcess): Promise<void> {\n if (!child.pid || childHasExited(child)) return;\n for (const [signal, timeoutMs] of [\n [\"SIGTERM\", 2_000],\n [\"SIGKILL\", 1_000],\n ] as const) {\n const exited = await new Promise<boolean>((resolve, reject) => {\n let timer: NodeJS.Timeout | undefined;\n const finish = (value: boolean) => {\n if (timer) clearTimeout(timer);\n child.off(\"exit\", onExit);\n resolve(value);\n };\n const onExit = () => finish(true);\n child.once(\"exit\", onExit);\n try {\n child.kill(signal);\n } catch (error) {\n child.off(\"exit\", onExit);\n if (childHasExited(child)) resolve(true);\n else reject(error);\n return;\n }\n if (childHasExited(child)) finish(true);\n else timer = setTimeout(() => finish(false), timeoutMs);\n });\n if (exited) return;\n }\n throw new Error(\"The service child did not exit after termination\");\n}\n\nexport function createServiceLifecycle(options: ServiceLifecycleOptions): ServiceLifecycle {\n const startupTimeoutMs = options.startupTimeoutMs ?? 30_000;\n const stopTimeoutMs = options.stopTimeoutMs ?? 10_000;\n for (const timeout of [startupTimeoutMs, stopTimeoutMs]) {\n if (!Number.isFinite(timeout) || timeout <= 0) throw new TypeError(\"Invalid service timeout\");\n }\n if (options.runtimeLockPath === options.operationLockPath) {\n throw new TypeError(\"Service operation and runtime locks must be different\");\n }\n\n const control = async (action: \"status\" | \"stop\", timeoutMs = 5_000) => {\n let status;\n try {\n status = await requestServiceControl(options.controlPath, action, timeoutMs);\n } catch (error) {\n throw new ServiceLifecycleError(\"STOP_FAILED\", \"Service control could not be verified\", {\n cause: error,\n });\n }\n if (status && status.profile !== options.profile) {\n throw new ServiceLifecycleError(\"STOP_FAILED\", \"Service control belongs to another profile\");\n }\n return status;\n };\n const budget = (deadline: number) => Math.max(1, Math.min(5_000, deadline - Date.now()));\n const pause = (deadline: number) => sleep(Math.max(1, Math.min(50, deadline - Date.now())));\n const markStopped = () => {\n mkdirSync(dirname(options.stoppedPath), { recursive: true });\n const token = randomUUID();\n writeFileSync(options.stoppedPath, token, { mode: 0o600 });\n return token;\n };\n const stoppedToken = () => {\n try {\n return readFileSync(options.stoppedPath, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw error;\n }\n };\n const clearStopped = () => {\n try {\n unlinkSync(options.stoppedPath);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n };\n const unsupported = () =>\n new ServiceLifecycleError(\n \"UNSUPPORTED_SERVICE\",\n \"An existing service cannot be managed by this version. Stop it using the CLI that started it before retrying.\",\n );\n\n const withOperation = async <T>(run: () => Promise<T>): Promise<T> => {\n let lock;\n try {\n lock = await acquireFileLock(options.operationLockPath, {\n timeoutMs: startupTimeoutMs + stopTimeoutMs,\n });\n } catch (error) {\n throw new ServiceLifecycleError(\"STOP_FAILED\", \"Another service operation is still active\", {\n cause: error,\n });\n }\n try {\n return await run();\n } finally {\n lock.release();\n }\n };\n\n // The runtime lock protects this inspection. It is never transferred to a child: a candidate\n // must acquire its own runtime lock before opening sockets or starting any service work.\n const canStart = async (deadline: number): Promise<boolean> => {\n const runtime = tryAcquireFileLock(options.runtimeLockPath);\n if (!runtime) return false;\n try {\n if (await socketIsOccupied(options.socketPath, budget(deadline))) throw unsupported();\n if (await control(\"status\", budget(deadline))) {\n throw new ServiceLifecycleError(\n \"STOP_FAILED\",\n \"Service control is live without runtime ownership\",\n );\n }\n return true;\n } finally {\n runtime.release();\n }\n };\n\n const startInternal = async (\n intent: \"explicit\" | \"recover\",\n expectedStoppedToken?: string,\n foreground?: () => Promise<void>,\n ): Promise<ServiceReadyResult> => {\n if (expectedStoppedToken !== undefined && stoppedToken() !== expectedStoppedToken) {\n throw new ServiceLifecycleError(\n \"STOPPED\",\n \"The service stop state changed; recovery was cancelled\",\n );\n }\n if (\n intent === \"recover\" &&\n existsSync(options.stoppedPath) &&\n expectedStoppedToken === undefined\n ) {\n throw new ServiceLifecycleError(\"STOPPED\", \"Service was explicitly stopped\");\n }\n if (intent === \"explicit\" || expectedStoppedToken !== undefined) clearStopped();\n\n const deadline = Date.now() + startupTimeoutMs;\n let child: ChildProcess | undefined;\n let childFailure: Error | undefined;\n const onChildError = (error: Error) => {\n childFailure = error;\n };\n try {\n while (Date.now() < deadline) {\n const current = await control(\"status\", budget(deadline));\n if (current?.state === \"ready\") {\n if (runtimeIsFree(options.runtimeLockPath)) {\n throw new ServiceLifecycleError(\n \"STOP_FAILED\",\n \"Service control is live without runtime ownership\",\n );\n }\n return { status: \"ready\", service: current };\n }\n if (childFailure) throw childFailure;\n if (child && childHasExited(child)) {\n throw new Error(\n `Service child exited during startup (code=${child.exitCode}, signal=${child.signalCode})`,\n );\n }\n if (!child && !current && (await canStart(deadline))) {\n if (foreground) {\n let timer: NodeJS.Timeout | undefined;\n try {\n await Promise.race([\n foreground(),\n new Promise<never>((_, reject) => {\n timer = setTimeout(\n () => reject(new Error(\"Foreground service startup timed out\")),\n Math.max(1, deadline - Date.now()),\n );\n }),\n ]);\n } finally {\n if (timer) clearTimeout(timer);\n }\n const service = await control(\"status\", budget(deadline));\n if (service?.state !== \"ready\") throw new Error(\"Service did not publish readiness\");\n if (runtimeIsFree(options.runtimeLockPath)) {\n throw new ServiceLifecycleError(\n \"STOP_FAILED\",\n \"Foreground service did not retain runtime ownership\",\n );\n }\n return { status: \"ready\", service };\n }\n child = options.spawn();\n child.once(\"error\", onChildError);\n }\n await pause(deadline);\n }\n throw new Error(`Service did not become ready within ${startupTimeoutMs}ms`);\n } catch (error) {\n if (child) {\n try {\n await stopOwnChild(child);\n } catch (terminationError) {\n throw new ServiceLifecycleError(\"STOP_FAILED\", \"Could not confirm service child exit\", {\n cause: terminationError,\n });\n }\n }\n if (error instanceof ServiceLifecycleError) throw error;\n try {\n if (!(await canStart(Date.now() + 1_000))) {\n throw new ServiceLifecycleError(\n \"STOP_FAILED\",\n \"A service is still running but could not be managed\",\n { cause: error },\n );\n }\n } catch (inspectionError) {\n if (inspectionError instanceof ServiceLifecycleError) throw inspectionError;\n throw new ServiceLifecycleError(\n \"STOP_FAILED\",\n \"Could not verify the service state after startup failure\",\n { cause: inspectionError },\n );\n }\n throw new ServiceLifecycleError(\n \"START_FAILED\",\n `Service failed to start: ${messageOf(error)}`,\n { cause: error },\n );\n } finally {\n child?.off(\"error\", onChildError);\n child?.unref();\n }\n };\n\n const stopInternal = async (): Promise<void> => {\n markStopped();\n const deadline = Date.now() + stopTimeoutMs;\n let stopRequested = false;\n try {\n while (Date.now() < deadline) {\n if (!stopRequested) {\n const service = await control(\"stop\", budget(deadline));\n stopRequested = service !== null;\n }\n const runtime = tryAcquireFileLock(options.runtimeLockPath);\n if (runtime) {\n try {\n if (await socketIsOccupied(options.socketPath, budget(deadline))) throw unsupported();\n if (await control(\"status\", budget(deadline))) {\n throw new ServiceLifecycleError(\n \"STOP_FAILED\",\n \"Service control is still live after runtime ownership ended\",\n );\n }\n return;\n } finally {\n runtime.release();\n }\n }\n await pause(deadline);\n }\n throw new Error(`Service did not stop within ${stopTimeoutMs}ms`);\n } catch (error) {\n if (error instanceof ServiceLifecycleError) throw error;\n throw new ServiceLifecycleError(\n \"STOP_FAILED\",\n `Could not confirm service stop: ${messageOf(error)}`,\n { cause: error },\n );\n }\n };\n\n return {\n status: () => control(\"status\"),\n start: (intent, expectedStoppedToken) =>\n withOperation(() => startInternal(intent, expectedStoppedToken)),\n startForeground: (start) => withOperation(() => startInternal(\"explicit\", undefined, start)),\n stop: () => withOperation(stopInternal),\n restart: (intent = \"explicit\") =>\n withOperation(async () => {\n if (intent === \"recover\" && existsSync(options.stoppedPath)) {\n throw new ServiceLifecycleError(\"STOPPED\", \"Service was explicitly stopped\");\n }\n await stopInternal();\n try {\n return await startInternal(\"explicit\");\n } catch (error) {\n const token = markStopped();\n if (error instanceof ServiceLifecycleError && error.code === \"START_FAILED\") {\n error.recoveryToken = token;\n }\n throw error;\n }\n }),\n };\n}\n","import {\n PROFILE_NAME,\n SOCK_PATH,\n SERVICE_CONTROL_PATH,\n SERVICE_RUNTIME_LOCK_PATH,\n SERVICE_OPERATION_LOCK_PATH,\n STOPPED_PATH,\n ensureProfileWorkspace,\n} from \"./paths.js\";\nimport { spawnScript } from \"./env.js\";\nimport { daemonRelayArgs } from \"./daemon-env.js\";\nimport { createServiceLifecycle } from \"./service-lifecycle.js\";\n\nexport function createProfileServiceLifecycle(\n options: {\n relayName?: string;\n env?: NodeJS.ProcessEnv;\n } = {},\n) {\n ensureProfileWorkspace();\n return createServiceLifecycle({\n profile: PROFILE_NAME,\n socketPath: SOCK_PATH,\n controlPath: SERVICE_CONTROL_PATH,\n runtimeLockPath: SERVICE_RUNTIME_LOCK_PATH,\n operationLockPath: SERVICE_OPERATION_LOCK_PATH,\n stoppedPath: STOPPED_PATH,\n spawn: () =>\n spawnScript(\"serve\", [\"--profile\", PROFILE_NAME, ...daemonRelayArgs(options.relayName)], {\n env: { ...(options.env ?? process.env) },\n stdio: \"ignore\",\n unref: false,\n }),\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,cAAc,YAAY,qBAAqB;AAC/E,SAAS,eAAe;AAGjB,SAAS,sBAAsB,WAAqC;AACzE,QAAM,aAAa,WAAW,KAAK;AACnC,MAAI,YAAY;AACd,cAAU,QAAQ,kBAAkB,GAAG,EAAE,WAAW,KAAK,CAAC;AAC1D,kBAAc,oBAAoB,GAAG,UAAU;AAAA,CAAI;AACnD;AAAA,EACF;AACA,MAAI;AACF,eAAW,kBAAkB;AAAA,EAC/B,QAAQ;AAAA,EAER;AACF;AAEA,SAAS,yBAA6C;AACpD,MAAI,CAAC,WAAW,kBAAkB,EAAG,QAAO;AAC5C,QAAM,QAAQ,aAAa,oBAAoB,OAAO,EAAE,KAAK;AAC7D,SAAO,SAAS;AAClB;AAEO,SAAS,gBAAgB,WAA8B;AAC5D,QAAM,WAAW,WAAW,KAAK,KAAK,uBAAuB;AAC7D,SAAO,WAAW,CAAC,WAAW,QAAQ,IAAI,CAAC;AAC7C;;;AC1BA,SAAS,kBAAkB;A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gCAAgC;AAAA,MAC7E;AACA,YAAM,aAAa;AACnB,UAAI;AACF,eAAO,MAAM,cAAc,UAAU;AAAA,MACvC,SAAS,OAAO;AACd,cAAM,QAAQ,YAAY;AAC1B,YAAI,iBAAiB,yBAAyB,MAAM,SAAS,gBAAgB;AAC3E,gBAAM,gBAAgB;AAAA,QACxB;AACA,cAAM;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACL;AACF;;;ACrWO,SAAS,8BACd,UAGI,CAAC,GACL;AACA,yBAAuB;AACvB,SAAO,uBAAuB;AAAA,IAC5B,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,aAAa;AAAA,IACb,OAAO,MACL,YAAY,SAAS,CAAC,aAAa,cAAc,GAAG,gBAAgB,QAAQ,SAAS,CAAC,GAAG;AAAA,MACvF,KAAK,EAAE,GAAI,QAAQ,OAAO,QAAQ,IAAK;AAAA,MACvC,OAAO;AAAA,MACP,OAAO;AAAA,IACT,CAAC;AAAA,EACL,CAAC;AACH;","names":["existsSync","mkdirSync","readFileSync","unlinkSync","writeFileSync","dirname","mkdirSync","dirname","writeFileSync","readFileSync","unlinkSync","existsSync"]}