@wirecat/zoom-cli 0.56.0 → 0.58.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 (147) hide show
  1. package/README.md +1 -1
  2. package/dist/bin/zm.js +35 -5
  3. package/dist/bundle/all-profiles-RS5IWIGR.js +25 -0
  4. package/dist/bundle/answer-policy-R7VZMCGE.js +96 -0
  5. package/dist/bundle/anthropic-5QHQR4WF.js +70 -0
  6. package/dist/bundle/app-server-7LANSZGE.js +232 -0
  7. package/dist/bundle/bun-O6RL6LRQ.js +169 -0
  8. package/dist/bundle/bun-sqlite-PEJM6CS4.js +69 -0
  9. package/dist/bundle/chunk-24DLFGES.js +97 -0
  10. package/dist/bundle/chunk-27P22POE.js +1109 -0
  11. package/dist/bundle/chunk-3SCTDFNO.js +3398 -0
  12. package/dist/bundle/chunk-3SERIWJD.js +36139 -0
  13. package/dist/bundle/chunk-4AURKUDZ.js +60 -0
  14. package/dist/bundle/chunk-4NGLRHWO.js +24 -0
  15. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  16. package/dist/bundle/chunk-5DVW77VC.js +789 -0
  17. package/dist/bundle/chunk-6CYLVFXM.js +9 -0
  18. package/dist/bundle/chunk-6FL25KC5.js +264 -0
  19. package/dist/bundle/chunk-7D2CD3E3.js +193 -0
  20. package/dist/bundle/chunk-7GVNQOV6.js +17 -0
  21. package/dist/bundle/chunk-7H3ZRDLW.js +630 -0
  22. package/dist/bundle/chunk-7Z4ANTAK.js +1095 -0
  23. package/dist/bundle/chunk-A6323R5P.js +22 -0
  24. package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
  25. package/dist/bundle/chunk-AIXLOMH4.js +63 -0
  26. package/dist/bundle/chunk-AQDWGJZT.js +188 -0
  27. package/dist/bundle/chunk-B32SF7J3.js +18 -0
  28. package/dist/bundle/chunk-BAQLQIMI.js +1938 -0
  29. package/dist/bundle/chunk-BGILD4CI.js +1109 -0
  30. package/dist/bundle/chunk-BXZ6WSVF.js +100 -0
  31. package/dist/bundle/chunk-CTGI4ES2.js +138 -0
  32. package/dist/bundle/chunk-CVIKKIGE.js +76 -0
  33. package/dist/bundle/chunk-DDYR6DYL.js +78 -0
  34. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  35. package/dist/bundle/chunk-DP5DX45H.js +151 -0
  36. package/dist/bundle/chunk-DXKVEOSS.js +53 -0
  37. package/dist/bundle/chunk-DXZTLB24.js +120 -0
  38. package/dist/bundle/chunk-G27MRA24.js +82 -0
  39. package/dist/bundle/chunk-HTQTIKWP.js +928 -0
  40. package/dist/bundle/chunk-IYAGQXED.js +433 -0
  41. package/dist/bundle/chunk-K76WFW4I.js +124 -0
  42. package/dist/bundle/chunk-KVHRHBLY.js +884 -0
  43. package/dist/bundle/chunk-L2UIJDWB.js +31 -0
  44. package/dist/bundle/chunk-L3VS3H34.js +482 -0
  45. package/dist/bundle/chunk-MBT7GP7K.js +1970 -0
  46. package/dist/bundle/chunk-MFS52LTZ.js +570 -0
  47. package/dist/bundle/chunk-MMT46EN4.js +29 -0
  48. package/dist/bundle/chunk-MNUTWGSA.js +6094 -0
  49. package/dist/bundle/chunk-N7GAQ27N.js +82 -0
  50. package/dist/bundle/chunk-NDXAZB5Z.js +409 -0
  51. package/dist/bundle/chunk-NOKFJJPA.js +1028 -0
  52. package/dist/bundle/chunk-NW7IMGRR.js +6848 -0
  53. package/dist/bundle/chunk-O5EHUB2V.js +2 -0
  54. package/dist/bundle/chunk-OBZWUNO4.js +160 -0
  55. package/dist/bundle/chunk-PACC5N6T.js +240 -0
  56. package/dist/bundle/chunk-PF25S7L4.js +422 -0
  57. package/dist/bundle/chunk-PKTFZAXG.js +48 -0
  58. package/dist/bundle/chunk-PNBEREOU.js +35626 -0
  59. package/dist/bundle/chunk-POOGFSRA.js +385 -0
  60. package/dist/bundle/chunk-PP3JGQQE.js +3517 -0
  61. package/dist/bundle/chunk-Q2Z3VCM4.js +2 -0
  62. package/dist/bundle/chunk-QCFHL4ES.js +45 -0
  63. package/dist/bundle/chunk-QFGBMS67.js +492 -0
  64. package/dist/bundle/chunk-RUP467ZX.js +948 -0
  65. package/dist/bundle/chunk-RXDIG23Z.js +166 -0
  66. package/dist/bundle/chunk-SIA7HJE2.js +8192 -0
  67. package/dist/bundle/chunk-SL3SXQZ5.js +100 -0
  68. package/dist/bundle/chunk-SV5L36WK.js +19 -0
  69. package/dist/bundle/chunk-T6AAM7UT.js +846 -0
  70. package/dist/bundle/chunk-U6QW67SU.js +18673 -0
  71. package/dist/bundle/chunk-UKR7KH3H.js +288 -0
  72. package/dist/bundle/chunk-UOFOMU3T.js +836 -0
  73. package/dist/bundle/chunk-URO44C5T.js +3570 -0
  74. package/dist/bundle/chunk-UXM7I35J.js +281 -0
  75. package/dist/bundle/chunk-UYJUTZTT.js +73 -0
  76. package/dist/bundle/chunk-VOAVOK4I.js +1146 -0
  77. package/dist/bundle/chunk-VSUY7PDW.js +192 -0
  78. package/dist/bundle/chunk-VYUSEJE4.js +98 -0
  79. package/dist/bundle/chunk-XFCSPOLZ.js +25 -0
  80. package/dist/bundle/chunk-XT7XVPEM.js +538 -0
  81. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  82. package/dist/bundle/chunk-YIFIY7ZE.js +58 -0
  83. package/dist/bundle/chunk-YIMI6O7R.js +5292 -0
  84. package/dist/bundle/chunk-YJRMMZI5.js +275 -0
  85. package/dist/bundle/chunk-YSHSCBPM.js +2315 -0
  86. package/dist/bundle/chunk-ZC5UXEIH.js +215 -0
  87. package/dist/bundle/chunk-ZHXIXDH5.js +161 -0
  88. package/dist/bundle/chunk-ZTOAAYFV.js +122 -0
  89. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  90. package/dist/bundle/cli-IQTASP44.js +831 -0
  91. package/dist/bundle/command-contract-WHZPF7NA.js +38 -0
  92. package/dist/bundle/config-IP5SGHKN.js +79 -0
  93. package/dist/bundle/dist-WT73DF46.js +136 -0
  94. package/dist/bundle/dist-XUFQCJXW.js +7577 -0
  95. package/dist/bundle/echarts-LD3AI55P.js +42501 -0
  96. package/dist/bundle/embed-XEMH4LNX.js +35 -0
  97. package/dist/bundle/embedder-ZCYKSKAE.js +108 -0
  98. package/dist/bundle/first-run-LGYDLIUM.js +23 -0
  99. package/dist/bundle/first-screen-LYQKPNF4.js +36 -0
  100. package/dist/bundle/folders-5ZBUQHAM.js +13 -0
  101. package/dist/bundle/instructions-RZMSW3OC.js +11 -0
  102. package/dist/bundle/main-NKY3JGXY.js +130 -0
  103. package/dist/bundle/mcp-7OXUHLTO.js +189 -0
  104. package/dist/bundle/mcp-OQBZXELQ.js +165 -0
  105. package/dist/bundle/mcp-VISEXTVC.js +92 -0
  106. package/dist/bundle/meetings-XPBHVZAU.js +215 -0
  107. package/dist/bundle/node-P4E63KXA.js +2340 -0
  108. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  109. package/dist/bundle/node-ZRLYQL7J.js +176 -0
  110. package/dist/bundle/node-sqlite-BBEDYBWO.js +45 -0
  111. package/dist/bundle/oauth-UHVRGKZU.js +17 -0
  112. package/dist/bundle/open-J4FCAUAJ.js +19 -0
  113. package/dist/bundle/output-file-SXV2ANW7.js +63 -0
  114. package/dist/bundle/process-LL77573L.js +91 -0
  115. package/dist/bundle/program-EPMIJCGA.js +5845 -0
  116. package/dist/bundle/prompt-LUUMQTMY.js +12 -0
  117. package/dist/bundle/recognize-EMHQX4XF.js +190 -0
  118. package/dist/bundle/remote-ZXS6D7VB.js +26 -0
  119. package/dist/bundle/rerank-WP7RKZNB.js +49 -0
  120. package/dist/bundle/run-log-GS2L66G6.js +111 -0
  121. package/dist/bundle/serve-L6KLLXK2.js +19 -0
  122. package/dist/bundle/server-NOFYENP5.js +53 -0
  123. package/dist/bundle/server-P5TXAPBY.js +66 -0
  124. package/dist/bundle/services-SPOEWVK3.js +330 -0
  125. package/dist/bundle/speech-6OBAKMND.js +44 -0
  126. package/dist/bundle/state-HN5EJKXQ.js +33 -0
  127. package/dist/bundle/store-LEU3M6IN.js +124 -0
  128. package/dist/bundle/store-ZP2URKET.js +141 -0
  129. package/dist/bundle/store-connection-I53XZ2TS.js +76 -0
  130. package/dist/bundle/store-maintenance-command-PSCHEHHY.js +54 -0
  131. package/dist/bundle/streaming-AK6Q2ZGQ.js +15 -0
  132. package/dist/bundle/tokens-CCM3D4ZT.js +17 -0
  133. package/dist/bundle/zm.js +8 -0
  134. package/dist/contract-overrides.d.ts.map +1 -1
  135. package/dist/contract-overrides.js +29 -17
  136. package/dist/contract-overrides.js.map +1 -1
  137. package/dist/mcp-command.d.ts +3 -2
  138. package/dist/mcp-command.d.ts.map +1 -1
  139. package/dist/mcp-command.js +62 -10
  140. package/dist/mcp-command.js.map +1 -1
  141. package/dist/program-bindings.d.ts.map +1 -1
  142. package/dist/program-bindings.js +1 -0
  143. package/dist/program-bindings.js.map +1 -1
  144. package/dist/version.d.ts +1 -1
  145. package/dist/version.js +1 -1
  146. package/package.json +7 -5
  147. package/skills/zoom-cli/SKILL.md +2 -0
@@ -0,0 +1,281 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ answeredWire
5
+ } from "./chunk-CVIKKIGE.js";
6
+ import {
7
+ CALLER_META_KEY,
8
+ PROXY_CLIENT_NAME,
9
+ StdioServerTransport,
10
+ callerOf,
11
+ serveStdio
12
+ } from "./chunk-7H3ZRDLW.js";
13
+ import {
14
+ McpServer
15
+ } from "./chunk-5D4AEUVA.js";
16
+ import {
17
+ __name
18
+ } from "./chunk-ZVVMGPBJ.js";
19
+
20
+ // node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/mcp/all-profiles.js
21
+ import { spawn } from "node:child_process";
22
+ import { randomUUID } from "node:crypto";
23
+ var PROTOCOL = "2025-06-18";
24
+ var START_MS = 3e4;
25
+ var CHILD_IDLE_MS = 10 * 60 * 1e3;
26
+ var startChild = /* @__PURE__ */ __name((spec, note, onExit) => {
27
+ const child = spawn(spec.command, spec.args, { env: spec.env, stdio: "pipe" });
28
+ const pending = /* @__PURE__ */ new Map();
29
+ let next = 1;
30
+ let buffer = "";
31
+ let gone;
32
+ const fail = /* @__PURE__ */ __name((error) => {
33
+ gone ??= error;
34
+ for (const waiter of pending.values())
35
+ waiter.reject(error);
36
+ pending.clear();
37
+ }, "fail");
38
+ child.on("error", () => fail(new Error("the profile's MCP server could not be started")));
39
+ child.on("exit", () => {
40
+ fail(new Error("the profile's MCP server stopped"));
41
+ onExit();
42
+ });
43
+ child.stdin.on("error", () => fail(new Error("the profile's MCP server closed its input")));
44
+ child.stderr.setEncoding("utf8");
45
+ let errors = "";
46
+ child.stderr.on("data", (chunk) => {
47
+ const lines = (errors + chunk).split("\n");
48
+ errors = lines.pop() ?? "";
49
+ for (const line of lines)
50
+ if (line.trim())
51
+ note(line);
52
+ });
53
+ child.stdout.setEncoding("utf8");
54
+ child.stdout.on("data", (chunk) => {
55
+ buffer += chunk;
56
+ for (let at = buffer.indexOf("\n"); at !== -1; at = buffer.indexOf("\n")) {
57
+ const line = buffer.slice(0, at);
58
+ buffer = buffer.slice(at + 1);
59
+ let message;
60
+ try {
61
+ message = JSON.parse(line);
62
+ } catch {
63
+ continue;
64
+ }
65
+ if (message.method !== void 0 && message.id !== void 0) {
66
+ send({ id: message.id, error: { code: -32601, message: "not offered through the all-profiles server" } });
67
+ continue;
68
+ }
69
+ if (typeof message.id !== "number")
70
+ continue;
71
+ const waiter = pending.get(message.id);
72
+ if (!waiter)
73
+ continue;
74
+ pending.delete(message.id);
75
+ if (message.error)
76
+ waiter.reject(new Error(message.error.message ?? "the profile's MCP server refused"));
77
+ else
78
+ waiter.resolve(message.result ?? {});
79
+ }
80
+ });
81
+ const send = /* @__PURE__ */ __name((message) => child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", ...message })}
82
+ `), "send");
83
+ const request = /* @__PURE__ */ __name((method, params) => new Promise((resolve, reject) => {
84
+ if (gone)
85
+ return reject(gone);
86
+ const id = next++;
87
+ pending.set(id, { resolve, reject });
88
+ send({ id, method, params });
89
+ }), "request");
90
+ const close = /* @__PURE__ */ __name(() => new Promise((resolve) => {
91
+ if (child.exitCode !== null || child.signalCode !== null)
92
+ return resolve();
93
+ child.once("exit", () => resolve());
94
+ child.stdin.end();
95
+ }), "close");
96
+ const timer = setTimeout(() => fail(new Error("the profile's MCP server did not answer in time")), START_MS);
97
+ return request("initialize", {
98
+ protocolVersion: PROTOCOL,
99
+ capabilities: {},
100
+ clientInfo: { name: PROXY_CLIENT_NAME, version: "1" }
101
+ }).then(() => {
102
+ send({ method: "notifications/initialized" });
103
+ return { request, close };
104
+ }).catch(async (error) => {
105
+ await close();
106
+ throw error;
107
+ }).finally(() => clearTimeout(timer));
108
+ }, "startChild");
109
+ var pool = /* @__PURE__ */ __name((options) => {
110
+ const idleMs = options.idleMs ?? CHILD_IDLE_MS;
111
+ const note = options.note ?? (() => {
112
+ });
113
+ const running = /* @__PURE__ */ new Map();
114
+ const forget = /* @__PURE__ */ __name((profile, child) => {
115
+ const one = running.get(profile);
116
+ if (one?.child !== child)
117
+ return;
118
+ clearTimeout(one.timer);
119
+ running.delete(profile);
120
+ }, "forget");
121
+ const use = /* @__PURE__ */ __name(async (profile, work) => {
122
+ let one = running.get(profile);
123
+ if (!one) {
124
+ const child = startChild(options.child(profile), (line) => note(`${profile}: ${line}`), () => forget(profile, child));
125
+ child.catch(() => forget(profile, child));
126
+ one = { child };
127
+ running.set(profile, one);
128
+ }
129
+ clearTimeout(one.timer);
130
+ const entry = one;
131
+ try {
132
+ return await work(await entry.child);
133
+ } finally {
134
+ if (running.get(profile) === entry) {
135
+ entry.timer = setTimeout(() => {
136
+ forget(profile, entry.child);
137
+ void entry.child.then((child) => child.close()).catch(() => void 0);
138
+ }, idleMs);
139
+ entry.timer.unref();
140
+ }
141
+ }
142
+ }, "use");
143
+ const close = /* @__PURE__ */ __name(async () => {
144
+ const all = [...running.values()];
145
+ running.clear();
146
+ for (const one of all)
147
+ clearTimeout(one.timer);
148
+ await Promise.all(all.map((one) => one.child.then((child) => child.close()).catch(() => void 0)));
149
+ }, "close");
150
+ return { use, close };
151
+ }, "pool");
152
+ var withProfile = /* @__PURE__ */ __name((tool, profiles, name, signedIn = () => true) => {
153
+ const schema = tool.inputSchema;
154
+ const out = profiles.filter((profile) => !signedIn(profile));
155
+ const states = out.length === 0 ? "" : ` Signed in: ${profiles.filter(signedIn).join(", ") || "none"} \xB7 Not signed in: ${out.join(", ")}.`;
156
+ return {
157
+ ...tool,
158
+ inputSchema: {
159
+ ...tool.inputSchema,
160
+ properties: {
161
+ profile: {
162
+ type: "string",
163
+ enum: [...profiles],
164
+ oneOf: profiles.map((profile) => ({
165
+ const: profile,
166
+ title: signedIn(profile) ? profile : `${profile} \u2014 not signed in`
167
+ })),
168
+ description: `Which ${name} account, by its profile. If the owner did not name one, ask which \u2014 never guess.${states}`
169
+ },
170
+ ...schema.properties
171
+ },
172
+ required: ["profile", ...(schema.required ?? []).filter((field) => field !== "profile")]
173
+ }
174
+ };
175
+ }, "withProfile");
176
+ var refusal = /* @__PURE__ */ __name((text) => ({
177
+ isError: true,
178
+ content: [{ type: "text", text }]
179
+ }), "refusal");
180
+ var allProfilesServer = /* @__PURE__ */ __name((options) => {
181
+ const children = pool(options);
182
+ let listed;
183
+ const tools = /* @__PURE__ */ __name((profiles) => {
184
+ listed ??= children.use(profiles.find(signedIn) ?? profiles[0], (child) => child.request("tools/list", {})).then((answer) => answer.tools ?? []);
185
+ listed.catch(() => {
186
+ listed = void 0;
187
+ });
188
+ return listed;
189
+ }, "tools");
190
+ const signedIn = /* @__PURE__ */ __name((profile) => options.signedIn?.(profile) ?? true, "signedIn");
191
+ const build = /* @__PURE__ */ __name(() => {
192
+ const profiles = [...options.profiles()].sort();
193
+ const server = new McpServer({ name: options.command, version: options.version }, { capabilities: { tools: {} }, instructions: options.instructions });
194
+ server.server.setRequestHandler("tools/list", async () => ({
195
+ tools: profiles.length === 0 ? [] : (await tools(profiles)).map((one) => withProfile(one, profiles, options.name, signedIn))
196
+ }));
197
+ const callers = {
198
+ env: options.env ?? process.env,
199
+ client: /* @__PURE__ */ __name(() => server.server.getClientVersion(), "client"),
200
+ connectionId: randomUUID()
201
+ };
202
+ server.server.setRequestHandler("tools/call", async (request, ctx) => {
203
+ const { name, arguments: given = {}, _meta } = request.params;
204
+ const { profile, ...rest } = given;
205
+ if (typeof profile !== "string" || !profiles.includes(profile))
206
+ return refusal(`${name} needs "profile", one of: ${profiles.join(", ")}. If the owner did not say which account, ask.`);
207
+ if (!signedIn(profile))
208
+ return refusal(options.signIn?.(profile) ?? `profile ${profile} is not signed in.`);
209
+ try {
210
+ return await children.use(profile, (child) => (
211
+ // Children are shared by every session, so each call names its own caller.
212
+ child.request("tools/call", {
213
+ name,
214
+ arguments: rest,
215
+ _meta: { ..._meta, [CALLER_META_KEY]: callerOf(ctx, name, callers) }
216
+ })
217
+ ));
218
+ } catch (error) {
219
+ return refusal(`profile ${profile}: ${error instanceof Error ? error.message : String(error)}`);
220
+ }
221
+ });
222
+ return server;
223
+ }, "build");
224
+ return { build, close: /* @__PURE__ */ __name(() => children.close(), "close") };
225
+ }, "allProfilesServer");
226
+ var serveAllProfilesOverStdio = /* @__PURE__ */ __name(async (options, io = {}) => {
227
+ const { build, close } = allProfilesServer(options);
228
+ const own = io.stdin !== void 0 && io.stdin !== process.stdin;
229
+ const wire = answeredWire(io.stdin ?? process.stdin, io.stdout ?? process.stdout);
230
+ const handle = serveStdio(build, {
231
+ transport: new StdioServerTransport(wire.input, wire.output),
232
+ onerror: /* @__PURE__ */ __name((error) => options.note?.(`mcp: ${error.message}`), "onerror")
233
+ });
234
+ const ended = await new Promise((resolve) => {
235
+ wire.ended.then(() => resolve("input"));
236
+ if (own)
237
+ io.signal?.addEventListener("abort", () => resolve("stopped"), { once: true });
238
+ else {
239
+ process.once("SIGINT", () => resolve("stopped"));
240
+ process.once("SIGTERM", () => resolve("stopped"));
241
+ }
242
+ });
243
+ try {
244
+ if (ended === "input")
245
+ await wire.answered();
246
+ wire.release();
247
+ await handle.close();
248
+ } finally {
249
+ await close();
250
+ }
251
+ }, "serveAllProfilesOverStdio");
252
+ var serveAllProfilesOverHttp = /* @__PURE__ */ __name(async (options, http) => {
253
+ const { build, close } = allProfilesServer(options);
254
+ const { serveOverHttp } = await import("./serve-L6KLLXK2.js");
255
+ const listening = await serveOverHttp(build, {
256
+ ...http,
257
+ appName: options.command,
258
+ onError: /* @__PURE__ */ __name((error) => options.note?.(`mcp: ${error.message}`), "onError")
259
+ }).catch(async (error) => {
260
+ await close();
261
+ throw error;
262
+ });
263
+ return {
264
+ url: listening.url,
265
+ close: /* @__PURE__ */ __name(async () => {
266
+ try {
267
+ await listening.close();
268
+ } finally {
269
+ await close();
270
+ }
271
+ }, "close")
272
+ };
273
+ }, "serveAllProfilesOverHttp");
274
+
275
+ export {
276
+ CHILD_IDLE_MS,
277
+ withProfile,
278
+ allProfilesServer,
279
+ serveAllProfilesOverStdio,
280
+ serveAllProfilesOverHttp
281
+ };
@@ -0,0 +1,73 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ alive
5
+ } from "./chunk-AIXLOMH4.js";
6
+ import {
7
+ resolvePaths,
8
+ writeSecurely
9
+ } from "./chunk-YIMI6O7R.js";
10
+ import {
11
+ __name
12
+ } from "./chunk-ZVVMGPBJ.js";
13
+
14
+ // node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/background/lock.js
15
+ import { existsSync, linkSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
16
+ import { dirname, join } from "node:path";
17
+ var lockPath = /* @__PURE__ */ __name((app, profile, env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "serve", `${profile}.lock`), "lockPath");
18
+ var readLock = /* @__PURE__ */ __name((path) => {
19
+ try {
20
+ const lock = JSON.parse(readFileSync(path, "utf8"));
21
+ return typeof lock.pid === "number" && typeof lock.startedAt === "string" ? lock : void 0;
22
+ } catch {
23
+ return void 0;
24
+ }
25
+ }, "readLock");
26
+ var holdLock = /* @__PURE__ */ __name((path, lock) => writeSecurely(path, `${JSON.stringify(lock)}
27
+ `, 384), "holdLock");
28
+ var takeLock = /* @__PURE__ */ __name((path, lock) => {
29
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
30
+ const draft = `${path}.${lock.pid}.tmp`;
31
+ writeFileSync(draft, `${JSON.stringify(lock)}
32
+ `, { mode: 384 });
33
+ try {
34
+ for (let attempt = 0; attempt < 5; attempt++) {
35
+ try {
36
+ linkSync(draft, path);
37
+ return void 0;
38
+ } catch (error) {
39
+ if (error.code !== "EEXIST")
40
+ throw error;
41
+ }
42
+ const held = readLock(path);
43
+ if (held && held.pid !== lock.pid && alive(held.pid))
44
+ return held;
45
+ rmSync(path, { force: true });
46
+ }
47
+ throw new Error(`could not take the lock ${path}: it keeps changing`);
48
+ } finally {
49
+ rmSync(draft, { force: true });
50
+ }
51
+ }, "takeLock");
52
+ var releaseLock = /* @__PURE__ */ __name((path, pid = process.pid) => {
53
+ if (readLock(path)?.pid === pid)
54
+ rmSync(path, { force: true });
55
+ }, "releaseLock");
56
+ var servingProfiles = /* @__PURE__ */ __name((app, env) => {
57
+ const dir = dirname(lockPath(app, "default", env));
58
+ if (!existsSync(dir))
59
+ return [];
60
+ return readdirSync(dir).filter((name) => name.endsWith(".lock")).map((name) => name.slice(0, -".lock".length)).filter((profile) => {
61
+ const lock = readLock(lockPath(app, profile, env));
62
+ return lock !== void 0 && alive(lock.pid);
63
+ });
64
+ }, "servingProfiles");
65
+
66
+ export {
67
+ lockPath,
68
+ readLock,
69
+ holdLock,
70
+ takeLock,
71
+ releaseLock,
72
+ servingProfiles
73
+ };