@wirecat/yandex-disk-cli 0.0.0-stage → 0.1.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 (235) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +204 -0
  3. package/README.md +243 -2
  4. package/contracts/wirecat.json +1554 -0
  5. package/dist/bin/ydisk.d.ts +3 -0
  6. package/dist/bin/ydisk.d.ts.map +1 -0
  7. package/dist/bin/ydisk.js +40 -0
  8. package/dist/bin/ydisk.js.map +1 -0
  9. package/dist/bundle/all-profiles-4OLZF3RT.js +279 -0
  10. package/dist/bundle/anthropic-DKB4OJXZ.js +91 -0
  11. package/dist/bundle/app-server-G4545SSV.js +247 -0
  12. package/dist/bundle/bun-RXEQKFED.js +169 -0
  13. package/dist/bundle/bun-sqlite-VHT5LN7U.js +76 -0
  14. package/dist/bundle/chunk-2BITUXGC.js +12289 -0
  15. package/dist/bundle/chunk-2CLWDQKA.js +39330 -0
  16. package/dist/bundle/chunk-2JFDOPKA.js +9575 -0
  17. package/dist/bundle/chunk-3GVI2MAO.js +106 -0
  18. package/dist/bundle/chunk-3SZBWBMI.js +131 -0
  19. package/dist/bundle/chunk-44VSEXW6.js +4054 -0
  20. package/dist/bundle/chunk-4YPRRQBE.js +95 -0
  21. package/dist/bundle/chunk-5COYRL5B.js +379 -0
  22. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  23. package/dist/bundle/chunk-5DM7DIZL.js +1402 -0
  24. package/dist/bundle/chunk-6R2DVTVZ.js +24 -0
  25. package/dist/bundle/chunk-762BS35H.js +2787 -0
  26. package/dist/bundle/chunk-AG64V7AB.js +1233 -0
  27. package/dist/bundle/chunk-BC5HGIXB.js +334 -0
  28. package/dist/bundle/chunk-BH7LFEX7.js +36 -0
  29. package/dist/bundle/chunk-BLNPGY7N.js +53 -0
  30. package/dist/bundle/chunk-CNIA2LJF.js +372 -0
  31. package/dist/bundle/chunk-COSXMDC7.js +230 -0
  32. package/dist/bundle/chunk-D72URWJE.js +532 -0
  33. package/dist/bundle/chunk-D7FO33KU.js +785 -0
  34. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  35. package/dist/bundle/chunk-DJH26PQ3.js +1396 -0
  36. package/dist/bundle/chunk-DJPT7IUC.js +64567 -0
  37. package/dist/bundle/chunk-DTMSCZDW.js +209 -0
  38. package/dist/bundle/chunk-E6LGZ5LX.js +16 -0
  39. package/dist/bundle/chunk-E6YRIHS5.js +92 -0
  40. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  41. package/dist/bundle/chunk-F3DDSZTF.js +78 -0
  42. package/dist/bundle/chunk-F4WWTQNL.js +188 -0
  43. package/dist/bundle/chunk-FDDAUASC.js +1028 -0
  44. package/dist/bundle/chunk-FMNPG6N2.js +170 -0
  45. package/dist/bundle/chunk-FOKJ4POB.js +274 -0
  46. package/dist/bundle/chunk-G22C7JG6.js +731 -0
  47. package/dist/bundle/chunk-GA442SYZ.js +161 -0
  48. package/dist/bundle/chunk-GEBSW7UK.js +6848 -0
  49. package/dist/bundle/chunk-GGRKWAOK.js +594 -0
  50. package/dist/bundle/chunk-HHINRNZA.js +788 -0
  51. package/dist/bundle/chunk-HUZCL33L.js +128 -0
  52. package/dist/bundle/chunk-IALSIQVT.js +142 -0
  53. package/dist/bundle/chunk-IOXR2QBX.js +398 -0
  54. package/dist/bundle/chunk-J5CXR6VX.js +63 -0
  55. package/dist/bundle/chunk-J5PWSTOX.js +82 -0
  56. package/dist/bundle/chunk-J7BVAEHR.js +364 -0
  57. package/dist/bundle/chunk-JH46HMZW.js +1334 -0
  58. package/dist/bundle/chunk-JOBO7F6W.js +52 -0
  59. package/dist/bundle/chunk-JXZ5B3L5.js +2333 -0
  60. package/dist/bundle/chunk-KBIAMDZN.js +66 -0
  61. package/dist/bundle/chunk-KFVDL2QS.js +146 -0
  62. package/dist/bundle/chunk-LNHTLSR5.js +288 -0
  63. package/dist/bundle/chunk-M24RAKMJ.js +58 -0
  64. package/dist/bundle/chunk-MDQ57Q3H.js +1197 -0
  65. package/dist/bundle/chunk-MGUEZYFA.js +5546 -0
  66. package/dist/bundle/chunk-MLXQ4X5L.js +206 -0
  67. package/dist/bundle/chunk-NQAKARHE.js +54 -0
  68. package/dist/bundle/chunk-OF7VVUDQ.js +23 -0
  69. package/dist/bundle/chunk-OQVPE3XK.js +324 -0
  70. package/dist/bundle/chunk-OR3QG7UR.js +259 -0
  71. package/dist/bundle/chunk-OUUYVROP.js +76 -0
  72. package/dist/bundle/chunk-PQBAM64O.js +168 -0
  73. package/dist/bundle/chunk-PYVIA7WF.js +88 -0
  74. package/dist/bundle/chunk-Q6HK3PHE.js +72 -0
  75. package/dist/bundle/chunk-QB3KECV2.js +218 -0
  76. package/dist/bundle/chunk-QGWXSFYN.js +73 -0
  77. package/dist/bundle/chunk-RC5QAAAE.js +29 -0
  78. package/dist/bundle/chunk-RMJ26HLB.js +18 -0
  79. package/dist/bundle/chunk-S4UUN6LD.js +1410 -0
  80. package/dist/bundle/chunk-T7ZUDA4C.js +72 -0
  81. package/dist/bundle/chunk-TRCSMVV5.js +72 -0
  82. package/dist/bundle/chunk-UD2BQEKA.js +46 -0
  83. package/dist/bundle/chunk-V4TL55GS.js +1068 -0
  84. package/dist/bundle/chunk-VJNWN5VU.js +4072 -0
  85. package/dist/bundle/chunk-VRRNBLMA.js +1227 -0
  86. package/dist/bundle/chunk-WUCMMNFJ.js +771 -0
  87. package/dist/bundle/chunk-XDESE3NY.js +44 -0
  88. package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
  89. package/dist/bundle/chunk-XQUUANA2.js +24600 -0
  90. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  91. package/dist/bundle/chunk-Z2QEON7B.js +2275 -0
  92. package/dist/bundle/chunk-ZMJ56GME.js +7 -0
  93. package/dist/bundle/chunk-ZTSB3D7Q.js +100 -0
  94. package/dist/bundle/chunk-ZVJWD3FK.js +38 -0
  95. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  96. package/dist/bundle/command-contract-YIOYGPJA.js +40 -0
  97. package/dist/bundle/command-server-entry-MHBQDXS4.js +169 -0
  98. package/dist/bundle/decode-NUGJIOUW.js +297 -0
  99. package/dist/bundle/definitions-AILHKEQT.js +2005 -0
  100. package/dist/bundle/dispatch-5LC4UEGY.js +411 -0
  101. package/dist/bundle/dist-4I2W6X2I.js +7577 -0
  102. package/dist/bundle/echarts-MHSH6PGC.js +42501 -0
  103. package/dist/bundle/embed-ZDXTHHYS.js +38 -0
  104. package/dist/bundle/embedder-XFEELFUL.js +111 -0
  105. package/dist/bundle/failure-5S7VPBYK.js +25 -0
  106. package/dist/bundle/first-run-JHCHT3RJ.js +29 -0
  107. package/dist/bundle/first-screen-FHGQ6QRV.js +40 -0
  108. package/dist/bundle/instructions-WKSMBUFX.js +11 -0
  109. package/dist/bundle/mcp-HS2ZDUVR.js +167 -0
  110. package/dist/bundle/mdast-util-from-markdown-R66F4HZA.js +1958 -0
  111. package/dist/bundle/mdast-util-gfm-LN2ELINH.js +2699 -0
  112. package/dist/bundle/meeting-combined-K4U4NYRZ.js +25 -0
  113. package/dist/bundle/meeting-model-KCEG6Y5O.js +26 -0
  114. package/dist/bundle/meeting-semantic-VYGSV3H6.js +22 -0
  115. package/dist/bundle/micromark-extension-gfm-5X7YT43T.js +1838 -0
  116. package/dist/bundle/node-CM6NC6UE.js +176 -0
  117. package/dist/bundle/node-KM3CUABH.js +2340 -0
  118. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  119. package/dist/bundle/node-sqlite-5YDQ3LIJ.js +74 -0
  120. package/dist/bundle/notes-search-PGO7KM2U.js +62 -0
  121. package/dist/bundle/oauth-NY4C5UCK.js +20 -0
  122. package/dist/bundle/open-YNUTA6ZE.js +23 -0
  123. package/dist/bundle/openai-4CVT5PHH.js +241 -0
  124. package/dist/bundle/process-2XT3TL27.js +91 -0
  125. package/dist/bundle/program-FMIVF5T6.js +31904 -0
  126. package/dist/bundle/prompt-VNWY3H6S.js +17 -0
  127. package/dist/bundle/recognize-JS4PBPSZ.js +26 -0
  128. package/dist/bundle/remote-RCLFH4V2.js +32 -0
  129. package/dist/bundle/rerank-EG6VKYGO.js +52 -0
  130. package/dist/bundle/schemas-ED2LHKXK.js +645 -0
  131. package/dist/bundle/serve-AHG25QXB.js +199 -0
  132. package/dist/bundle/server-5FTB7WM3.js +78 -0
  133. package/dist/bundle/server-JNZVSAZE.js +209 -0
  134. package/dist/bundle/sqlite-runtime-XSZOAQPF.js +20 -0
  135. package/dist/bundle/state-XGVAJFF7.js +36 -0
  136. package/dist/bundle/store-OHSCWZEV.js +177 -0
  137. package/dist/bundle/store-PKSPKJXL.js +293 -0
  138. package/dist/bundle/store-maintenance-command-KAWGBSWK.js +69 -0
  139. package/dist/bundle/ydisk.js +183 -0
  140. package/dist/commands/api.d.ts +9 -0
  141. package/dist/commands/api.d.ts.map +1 -0
  142. package/dist/commands/api.js +59 -0
  143. package/dist/commands/api.js.map +1 -0
  144. package/dist/commands/comments.d.ts +3 -0
  145. package/dist/commands/comments.d.ts.map +1 -0
  146. package/dist/commands/comments.js +114 -0
  147. package/dist/commands/comments.js.map +1 -0
  148. package/dist/commands/files.d.ts +3 -0
  149. package/dist/commands/files.d.ts.map +1 -0
  150. package/dist/commands/files.js +272 -0
  151. package/dist/commands/files.js.map +1 -0
  152. package/dist/commands/library.d.ts +13 -0
  153. package/dist/commands/library.d.ts.map +1 -0
  154. package/dist/commands/library.js +118 -0
  155. package/dist/commands/library.js.map +1 -0
  156. package/dist/commands/session.d.ts +3 -0
  157. package/dist/commands/session.d.ts.map +1 -0
  158. package/dist/commands/session.js +99 -0
  159. package/dist/commands/session.js.map +1 -0
  160. package/dist/config.d.ts +18 -0
  161. package/dist/config.d.ts.map +1 -0
  162. package/dist/config.js +62 -0
  163. package/dist/config.js.map +1 -0
  164. package/dist/context.d.ts +80 -0
  165. package/dist/context.d.ts.map +1 -0
  166. package/dist/context.js +77 -0
  167. package/dist/context.js.map +1 -0
  168. package/dist/generated/definitions.d.ts +3 -0
  169. package/dist/generated/definitions.d.ts.map +1 -0
  170. package/dist/generated/definitions.js +2001 -0
  171. package/dist/generated/definitions.js.map +1 -0
  172. package/dist/generated/manifest.d.ts +6 -0
  173. package/dist/generated/manifest.d.ts.map +1 -0
  174. package/dist/generated/manifest.js +1473 -0
  175. package/dist/generated/manifest.js.map +1 -0
  176. package/dist/generated/schemas.d.ts +127 -0
  177. package/dist/generated/schemas.d.ts.map +1 -0
  178. package/dist/generated/schemas.js +545 -0
  179. package/dist/generated/schemas.js.map +1 -0
  180. package/dist/generated/types.d.ts +829 -0
  181. package/dist/generated/types.d.ts.map +1 -0
  182. package/dist/generated/types.js +5 -0
  183. package/dist/generated/types.js.map +1 -0
  184. package/dist/identity.d.ts +10 -0
  185. package/dist/identity.d.ts.map +1 -0
  186. package/dist/identity.js +33 -0
  187. package/dist/identity.js.map +1 -0
  188. package/dist/index.d.ts +3 -0
  189. package/dist/index.d.ts.map +1 -0
  190. package/dist/index.js +3 -0
  191. package/dist/index.js.map +1 -0
  192. package/dist/program.d.ts +6 -0
  193. package/dist/program.d.ts.map +1 -0
  194. package/dist/program.js +65 -0
  195. package/dist/program.js.map +1 -0
  196. package/dist/sample/comments.d.ts +61 -0
  197. package/dist/sample/comments.d.ts.map +1 -0
  198. package/dist/sample/comments.js +39 -0
  199. package/dist/sample/comments.js.map +1 -0
  200. package/dist/sample/records.d.ts +16 -0
  201. package/dist/sample/records.d.ts.map +1 -0
  202. package/dist/sample/records.js +22 -0
  203. package/dist/sample/records.js.map +1 -0
  204. package/dist/sample/transport.d.ts +42 -0
  205. package/dist/sample/transport.d.ts.map +1 -0
  206. package/dist/sample/transport.js +153 -0
  207. package/dist/sample/transport.js.map +1 -0
  208. package/dist/version.d.ts +2 -0
  209. package/dist/version.d.ts.map +1 -0
  210. package/dist/version.js +2 -0
  211. package/dist/version.js.map +1 -0
  212. package/dist/wcat.d.ts +3 -0
  213. package/dist/wcat.d.ts.map +1 -0
  214. package/dist/wcat.js +4 -0
  215. package/dist/wcat.js.map +1 -0
  216. package/dist/yandex/source.d.ts +39 -0
  217. package/dist/yandex/source.d.ts.map +1 -0
  218. package/dist/yandex/source.js +189 -0
  219. package/dist/yandex/source.js.map +1 -0
  220. package/dist/yandex/transport.d.ts +41 -0
  221. package/dist/yandex/transport.d.ts.map +1 -0
  222. package/dist/yandex/transport.js +152 -0
  223. package/dist/yandex/transport.js.map +1 -0
  224. package/dist/yandex/writes.d.ts +27 -0
  225. package/dist/yandex/writes.d.ts.map +1 -0
  226. package/dist/yandex/writes.js +61 -0
  227. package/dist/yandex/writes.js.map +1 -0
  228. package/package.json +88 -4
  229. package/skills/yandex-disk-cli/SKILL.md +46 -0
  230. package/skills/yandex-disk-cli/references/api/api-disk-operations-operation-id.md +13 -0
  231. package/skills/yandex-disk-cli/references/api/api-disk-public-resources.md +50 -0
  232. package/skills/yandex-disk-cli/references/api/api-disk-resources.md +171 -0
  233. package/skills/yandex-disk-cli/references/api/api-disk-trash-resources.md +48 -0
  234. package/skills/yandex-disk-cli/references/api/api-disk.md +13 -0
  235. package/skills/yandex-disk-cli/references/api.md +17 -0
@@ -0,0 +1,78 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ __name
5
+ } from "./chunk-ZVVMGPBJ.js";
6
+
7
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/http/listen.js
8
+ import { createServer } from "node:http";
9
+ import { Readable } from "node:stream";
10
+ var MAX_BODY = 4 * 1024 * 1024;
11
+ var TooLarge = class extends Error {
12
+ static {
13
+ __name(this, "TooLarge");
14
+ }
15
+ };
16
+ var readBody = /* @__PURE__ */ __name((incoming, limit) => new Promise((resolve, reject) => {
17
+ if (Number(incoming.headers["content-length"] ?? 0) > limit)
18
+ return reject(new TooLarge());
19
+ const chunks = [];
20
+ let size = 0;
21
+ incoming.on("data", (chunk) => {
22
+ size += chunk.length;
23
+ if (size > limit) {
24
+ incoming.destroy();
25
+ reject(new TooLarge());
26
+ } else
27
+ chunks.push(chunk);
28
+ });
29
+ incoming.once("end", () => resolve(Buffer.concat(chunks)));
30
+ incoming.once("error", reject);
31
+ }), "readBody");
32
+ var toRequest = /* @__PURE__ */ __name(async (incoming, origin, maxBody) => {
33
+ const headers = new Headers();
34
+ for (const [name, value] of Object.entries(incoming.headers)) {
35
+ if (Array.isArray(value))
36
+ for (const one of value)
37
+ headers.append(name, one);
38
+ else if (value !== void 0)
39
+ headers.set(name, value);
40
+ }
41
+ const method = incoming.method ?? "GET";
42
+ const body = method === "GET" || method === "HEAD" ? void 0 : await readBody(incoming, maxBody);
43
+ if (body)
44
+ headers.set("content-length", String(body.length));
45
+ return new Request(new URL(incoming.url ?? "/", origin), { method, headers, ...body ? { body } : {} });
46
+ }, "toRequest");
47
+ var send = /* @__PURE__ */ __name(async (response, outgoing) => {
48
+ outgoing.writeHead(response.status, Object.fromEntries(response.headers));
49
+ if (!response.body)
50
+ return void outgoing.end();
51
+ const body = Readable.fromWeb(response.body);
52
+ outgoing.once("close", () => body.destroy());
53
+ body.pipe(outgoing);
54
+ }, "send");
55
+ var listen = /* @__PURE__ */ __name((handle, { host, port, maxBody = MAX_BODY }) => new Promise((resolve, reject) => {
56
+ const server = createServer((incoming, outgoing) => {
57
+ toRequest(incoming, `http://${host}`, maxBody).then(handle).then((response) => send(response, outgoing)).catch((error) => {
58
+ if (!outgoing.headersSent)
59
+ outgoing.writeHead(error instanceof TooLarge ? 413 : 500, { connection: "close" });
60
+ outgoing.end();
61
+ });
62
+ });
63
+ server.once("error", reject);
64
+ server.listen(port, host, () => {
65
+ const { port: bound } = server.address();
66
+ resolve({
67
+ url: new URL(`http://${host}:${bound}`),
68
+ close: /* @__PURE__ */ __name(() => new Promise((done) => {
69
+ server.close(() => done());
70
+ server.closeAllConnections();
71
+ }), "close")
72
+ });
73
+ });
74
+ }), "listen");
75
+
76
+ export {
77
+ listen
78
+ };
@@ -0,0 +1,188 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ stdinFieldOf
5
+ } from "./chunk-RMJ26HLB.js";
6
+ import {
7
+ commandPathOf
8
+ } from "./chunk-3SZBWBMI.js";
9
+ import {
10
+ commandServerRequest,
11
+ metaOf
12
+ } from "./chunk-2BITUXGC.js";
13
+ import {
14
+ errorObjectOf,
15
+ renderError
16
+ } from "./chunk-AG64V7AB.js";
17
+ import {
18
+ CliError
19
+ } from "./chunk-T7ZUDA4C.js";
20
+ import {
21
+ __name
22
+ } from "./chunk-ZVVMGPBJ.js";
23
+
24
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/cli/command-server.js
25
+ import { createInterface } from "node:readline";
26
+
27
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/cli/command-server-argv.js
28
+ var COMMAND_SERVER_ARGV = ["commands", "--serve"];
29
+ var isCommandServer = /* @__PURE__ */ __name((args) => args.length === COMMAND_SERVER_ARGV.length && COMMAND_SERVER_ARGV.every((word, at) => args[at] === word), "isCommandServer");
30
+
31
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/cli/command-server.js
32
+ var COMMAND_SERVER_PROTOCOL = 1;
33
+ var COMMAND_SERVER_IDLE_MS = 10 * 6e4;
34
+ var COMMAND_SERVER_CONCURRENT = 8;
35
+ var runsAlone = /* @__PURE__ */ __name((command) => commandPathOf(command)[0] === "store", "runsAlone");
36
+ var enterCommandServer = /* @__PURE__ */ __name(async (command, cli) => {
37
+ const request = commandServerRequest();
38
+ if (!request)
39
+ return;
40
+ refuseInCommandServer(command, cli);
41
+ if (runsAlone(command))
42
+ await request.alone();
43
+ }, "enterCommandServer");
44
+ var refuseInCommandServer = /* @__PURE__ */ __name((command, cli) => {
45
+ if (!commandServerRequest())
46
+ return;
47
+ const typed = [cli, ...commandPathOf(command)].join(" ");
48
+ const { lifetime } = metaOf(command);
49
+ if (lifetime)
50
+ throw new CliError("validation_error", `\`${typed}\` ${lifetime === "persistent" ? "runs until it is stopped" : "waits on a person"}; the command server runs only commands that return \u2014 start it as a process of its own`);
51
+ if (stdinFieldOf(command))
52
+ throw new CliError("validation_error", `\`${typed}\` reads its input on stdin, which the command server does not pass on \u2014 start it as a process of its own`);
53
+ }, "refuseInCommandServer");
54
+ var refusal = /* @__PURE__ */ __name((cli, message) => `${renderError(errorObjectOf(new CliError("validation_error", message)), { cli, interactive: false })}
55
+ `, "refusal");
56
+ var requestOf = /* @__PURE__ */ __name((line, cli) => {
57
+ let parsed;
58
+ try {
59
+ parsed = JSON.parse(line);
60
+ } catch {
61
+ return { id: null, error: "a request is one JSON object per line" };
62
+ }
63
+ const { id, argv } = parsed ?? {};
64
+ const known = typeof id === "number" && Number.isFinite(id) ? id : null;
65
+ if (known === null)
66
+ return { id: null, error: 'a request needs a numeric "id"' };
67
+ if (!Array.isArray(argv) || !argv.every((word) => typeof word === "string"))
68
+ return { id: known, error: '"argv" is a list of strings' };
69
+ if (isCommandServer(argv))
70
+ return { id: known, error: `\`${cli} commands --serve\` cannot run inside itself` };
71
+ return { id: known, argv };
72
+ }, "requestOf");
73
+ var serveCommands = /* @__PURE__ */ __name(async ({ input, write, run, cli, version, idleMs = COMMAND_SERVER_IDLE_MS, concurrent = COMMAND_SERVER_CONCURRENT, signal }) => {
74
+ const send = /* @__PURE__ */ __name((value) => write(`${JSON.stringify(value)}
75
+ `), "send");
76
+ await send({ ready: true, protocol: COMMAND_SERVER_PROTOCOL, version, concurrent });
77
+ const lines = createInterface({ input, crlfDelay: Number.POSITIVE_INFINITY });
78
+ return new Promise((resolve) => {
79
+ const waiting = [];
80
+ let active = 0;
81
+ let running = 0;
82
+ let gated = false;
83
+ let drained;
84
+ let turns = Promise.resolve();
85
+ let timer;
86
+ let ending = false;
87
+ let done = false;
88
+ const finish = /* @__PURE__ */ __name(() => {
89
+ if (done)
90
+ return;
91
+ done = true;
92
+ clearTimeout(timer);
93
+ lines.close();
94
+ resolve(0);
95
+ }, "finish");
96
+ const settle = /* @__PURE__ */ __name(() => {
97
+ if (running === 0 && drained) {
98
+ const go = drained;
99
+ drained = void 0;
100
+ go();
101
+ }
102
+ pump();
103
+ if (active > 0 || waiting.length > 0 || done)
104
+ return;
105
+ if (ending)
106
+ finish();
107
+ else {
108
+ clearTimeout(timer);
109
+ timer = setTimeout(finish, idleMs);
110
+ }
111
+ }, "settle");
112
+ const start = /* @__PURE__ */ __name((line) => {
113
+ active += 1;
114
+ running += 1;
115
+ let holdsPlace = true;
116
+ let ended = false;
117
+ let turn;
118
+ let release;
119
+ const alone = /* @__PURE__ */ __name(() => {
120
+ if (turn)
121
+ return turn;
122
+ holdsPlace = false;
123
+ running -= 1;
124
+ turn = turns.then(() => new Promise((go) => {
125
+ if (ended)
126
+ return go();
127
+ gated = true;
128
+ drained = /* @__PURE__ */ __name(() => {
129
+ if (ended)
130
+ gated = false;
131
+ else {
132
+ holdsPlace = true;
133
+ running += 1;
134
+ }
135
+ go();
136
+ }, "drained");
137
+ settle();
138
+ }));
139
+ turns = turn.then(() => ended && !holdsPlace ? void 0 : new Promise((free) => release = free));
140
+ return turn;
141
+ }, "alone");
142
+ const answer = /* @__PURE__ */ __name(async () => {
143
+ const request = requestOf(line, cli);
144
+ if ("error" in request)
145
+ return send({ id: request.id, code: 2, stdout: "", stderr: refusal(cli, request.error) });
146
+ const answered = await run(request.argv, alone);
147
+ return send({ id: request.id, ...answered });
148
+ }, "answer");
149
+ answer().catch(finish).finally(() => {
150
+ ended = true;
151
+ active -= 1;
152
+ if (holdsPlace)
153
+ running -= 1;
154
+ if (release) {
155
+ gated = false;
156
+ release();
157
+ }
158
+ settle();
159
+ });
160
+ }, "start");
161
+ const pump = /* @__PURE__ */ __name(() => {
162
+ while (!done && !gated && running < concurrent && waiting.length > 0)
163
+ start(waiting.shift());
164
+ }, "pump");
165
+ lines.on("line", (line) => {
166
+ if (done || ending || line.trim() === "")
167
+ return;
168
+ clearTimeout(timer);
169
+ waiting.push(line);
170
+ pump();
171
+ });
172
+ const end = /* @__PURE__ */ __name(() => {
173
+ ending = true;
174
+ settle();
175
+ }, "end");
176
+ lines.on("close", end);
177
+ if (signal?.aborted)
178
+ end();
179
+ signal?.addEventListener("abort", end, { once: true });
180
+ settle();
181
+ });
182
+ }, "serveCommands");
183
+
184
+ export {
185
+ COMMAND_SERVER_CONCURRENT,
186
+ enterCommandServer,
187
+ serveCommands
188
+ };