@wirecat/mail-cli 0.0.0-stage → 0.1.1

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 (198) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +204 -0
  3. package/README.md +166 -2
  4. package/dist/bin/mail.d.ts +3 -0
  5. package/dist/bin/mail.d.ts.map +1 -0
  6. package/dist/bin/mail.js +36 -0
  7. package/dist/bin/mail.js.map +1 -0
  8. package/dist/bundle/all-profiles-TKMBELRZ.js +286 -0
  9. package/dist/bundle/anthropic-7LMUAEIZ.js +72 -0
  10. package/dist/bundle/app-server-JGMIJDD4.js +229 -0
  11. package/dist/bundle/bun-XRO6XJHQ.js +169 -0
  12. package/dist/bundle/bun-sqlite-Z54LEHVM.js +71 -0
  13. package/dist/bundle/chunk-2LLNPNMB.js +24 -0
  14. package/dist/bundle/chunk-3E3WA2L6.js +1932 -0
  15. package/dist/bundle/chunk-3KEVLSNN.js +138 -0
  16. package/dist/bundle/chunk-3KOA73LS.js +3416 -0
  17. package/dist/bundle/chunk-4E7BN3TC.js +122 -0
  18. package/dist/bundle/chunk-4FEMINO2.js +409 -0
  19. package/dist/bundle/chunk-52F5DWS5.js +27 -0
  20. package/dist/bundle/chunk-5BVIWP3S.js +71 -0
  21. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  22. package/dist/bundle/chunk-5NYMNSSO.js +264 -0
  23. package/dist/bundle/chunk-6MAZWSC3.js +132 -0
  24. package/dist/bundle/chunk-75CWWETH.js +379 -0
  25. package/dist/bundle/chunk-7SXGLT6T.js +444 -0
  26. package/dist/bundle/chunk-BTQX2ZSZ.js +288 -0
  27. package/dist/bundle/chunk-CEW6KIFA.js +1193 -0
  28. package/dist/bundle/chunk-CH6RXYAX.js +82 -0
  29. package/dist/bundle/chunk-D72URWJE.js +532 -0
  30. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  31. package/dist/bundle/chunk-EOEDICIE.js +6848 -0
  32. package/dist/bundle/chunk-F6D6PJ34.js +100 -0
  33. package/dist/bundle/chunk-FDCGTODC.js +78 -0
  34. package/dist/bundle/chunk-FZ5FXIG6.js +18 -0
  35. package/dist/bundle/chunk-GAH7N7HO.js +8181 -0
  36. package/dist/bundle/chunk-GK4M2SUP.js +195 -0
  37. package/dist/bundle/chunk-GN62YOT5.js +161 -0
  38. package/dist/bundle/chunk-GQQJOH7A.js +7050 -0
  39. package/dist/bundle/chunk-GWDCKUBI.js +781 -0
  40. package/dist/bundle/chunk-HTQTIKWP.js +928 -0
  41. package/dist/bundle/chunk-IK5TH3O7.js +217 -0
  42. package/dist/bundle/chunk-J3QXTBD2.js +2742 -0
  43. package/dist/bundle/chunk-J6MSJLIW.js +45 -0
  44. package/dist/bundle/chunk-JBBZCTTF.js +76 -0
  45. package/dist/bundle/chunk-JVMVLITS.js +260 -0
  46. package/dist/bundle/chunk-K4FVKPDQ.js +525 -0
  47. package/dist/bundle/chunk-KHTO2Q6E.js +886 -0
  48. package/dist/bundle/chunk-KM7Q67Z3.js +63 -0
  49. package/dist/bundle/chunk-LQ37ALDJ.js +2416 -0
  50. package/dist/bundle/chunk-MNOIRJEO.js +2315 -0
  51. package/dist/bundle/chunk-MS53RALV.js +168 -0
  52. package/dist/bundle/chunk-NK7EB63L.js +36225 -0
  53. package/dist/bundle/chunk-NPGVOZVK.js +2 -0
  54. package/dist/bundle/chunk-OTUOZ33L.js +82 -0
  55. package/dist/bundle/chunk-P7P5MNAU.js +46 -0
  56. package/dist/bundle/chunk-QLEUNU6G.js +537 -0
  57. package/dist/bundle/chunk-QQB7WT7R.js +216 -0
  58. package/dist/bundle/chunk-QX7RCLRS.js +23 -0
  59. package/dist/bundle/chunk-T6464KYA.js +35130 -0
  60. package/dist/bundle/chunk-TE5U5OAM.js +73 -0
  61. package/dist/bundle/chunk-TI6VBZKJ.js +166 -0
  62. package/dist/bundle/chunk-TQFCPUIM.js +53 -0
  63. package/dist/bundle/chunk-TVREDYX4.js +3574 -0
  64. package/dist/bundle/chunk-TWPDVUBR.js +106 -0
  65. package/dist/bundle/chunk-TWTATDM7.js +461 -0
  66. package/dist/bundle/chunk-UH4DDRHA.js +2989 -0
  67. package/dist/bundle/chunk-VEIZZRQ5.js +630 -0
  68. package/dist/bundle/chunk-WLFLBWNH.js +54 -0
  69. package/dist/bundle/chunk-WXAXYJJ7.js +486 -0
  70. package/dist/bundle/chunk-XQUUANA2.js +24600 -0
  71. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  72. package/dist/bundle/chunk-YO4CUH5E.js +33 -0
  73. package/dist/bundle/chunk-YPQQ5J4X.js +849 -0
  74. package/dist/bundle/chunk-Z34ICZA3.js +1028 -0
  75. package/dist/bundle/chunk-ZANYM66S.js +58 -0
  76. package/dist/bundle/chunk-ZD3WUGR2.js +142 -0
  77. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  78. package/dist/bundle/command-contract-WU434ZUL.js +34 -0
  79. package/dist/bundle/decode-YB3ZDTES.js +162 -0
  80. package/dist/bundle/dispatch-EUKKT3PD.js +411 -0
  81. package/dist/bundle/dist-A6GKSKFC.js +2072 -0
  82. package/dist/bundle/dist-HFUVURJG.js +7577 -0
  83. package/dist/bundle/echarts-YNGCOYHW.js +42501 -0
  84. package/dist/bundle/embed-LWNHIRBQ.js +37 -0
  85. package/dist/bundle/embedder-2LYD3U37.js +110 -0
  86. package/dist/bundle/failure-OAIC5VAP.js +24 -0
  87. package/dist/bundle/first-run-N3HJKGU7.js +27 -0
  88. package/dist/bundle/first-screen-4U2DMV3G.js +32 -0
  89. package/dist/bundle/instructions-GJHHFV64.js +11 -0
  90. package/dist/bundle/mail.js +166 -0
  91. package/dist/bundle/mcp-L7SRVDRN.js +167 -0
  92. package/dist/bundle/node-GFOH6FKP.js +176 -0
  93. package/dist/bundle/node-KM3CUABH.js +2340 -0
  94. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  95. package/dist/bundle/node-sqlite-NBXQXBIU.js +63 -0
  96. package/dist/bundle/oauth-56EFO5AQ.js +19 -0
  97. package/dist/bundle/open-2V7QZQJP.js +21 -0
  98. package/dist/bundle/openai-V3SVACVL.js +251 -0
  99. package/dist/bundle/process-XVDX4SPD.js +91 -0
  100. package/dist/bundle/program-JTJB26P3.js +35542 -0
  101. package/dist/bundle/prompt-YKWAI222.js +14 -0
  102. package/dist/bundle/recognize-PAR66KVM.js +25 -0
  103. package/dist/bundle/remote-CE43TKXC.js +28 -0
  104. package/dist/bundle/rerank-M7S7P2TW.js +51 -0
  105. package/dist/bundle/serve-ENPMIV6J.js +197 -0
  106. package/dist/bundle/server-JRTHUCVY.js +63 -0
  107. package/dist/bundle/server-MBEZLVKZ.js +189 -0
  108. package/dist/bundle/sqlite-runtime-HVGDHBJJ.js +18 -0
  109. package/dist/bundle/state-QZSOSKBD.js +35 -0
  110. package/dist/bundle/store-2BUX6LVX.js +124 -0
  111. package/dist/bundle/store-UJ7SNKXI.js +141 -0
  112. package/dist/bundle/store-maintenance-command-I7V5C44K.js +52 -0
  113. package/dist/commands/account.d.ts +3 -0
  114. package/dist/commands/account.d.ts.map +1 -0
  115. package/dist/commands/account.js +47 -0
  116. package/dist/commands/account.js.map +1 -0
  117. package/dist/commands/context.d.ts +41 -0
  118. package/dist/commands/context.d.ts.map +1 -0
  119. package/dist/commands/context.js +52 -0
  120. package/dist/commands/context.js.map +1 -0
  121. package/dist/commands/folders.d.ts +3 -0
  122. package/dist/commands/folders.d.ts.map +1 -0
  123. package/dist/commands/folders.js +36 -0
  124. package/dist/commands/folders.js.map +1 -0
  125. package/dist/commands/login.d.ts +5 -0
  126. package/dist/commands/login.d.ts.map +1 -0
  127. package/dist/commands/login.js +21 -0
  128. package/dist/commands/login.js.map +1 -0
  129. package/dist/commands/mailbox.d.ts +16 -0
  130. package/dist/commands/mailbox.d.ts.map +1 -0
  131. package/dist/commands/mailbox.js +54 -0
  132. package/dist/commands/mailbox.js.map +1 -0
  133. package/dist/commands/session.d.ts +3 -0
  134. package/dist/commands/session.d.ts.map +1 -0
  135. package/dist/commands/session.js +211 -0
  136. package/dist/commands/session.js.map +1 -0
  137. package/dist/commands/status.d.ts +3 -0
  138. package/dist/commands/status.d.ts.map +1 -0
  139. package/dist/commands/status.js +89 -0
  140. package/dist/commands/status.js.map +1 -0
  141. package/dist/commands/sync.d.ts +3 -0
  142. package/dist/commands/sync.d.ts.map +1 -0
  143. package/dist/commands/sync.js +190 -0
  144. package/dist/commands/sync.js.map +1 -0
  145. package/dist/config.d.ts +190 -0
  146. package/dist/config.d.ts.map +1 -0
  147. package/dist/config.js +46 -0
  148. package/dist/config.js.map +1 -0
  149. package/dist/discovery.d.ts +42 -0
  150. package/dist/discovery.d.ts.map +1 -0
  151. package/dist/discovery.js +179 -0
  152. package/dist/discovery.js.map +1 -0
  153. package/dist/identity.d.ts +5 -0
  154. package/dist/identity.d.ts.map +1 -0
  155. package/dist/identity.js +16 -0
  156. package/dist/identity.js.map +1 -0
  157. package/dist/index.d.ts +3 -0
  158. package/dist/index.d.ts.map +1 -0
  159. package/dist/index.js +3 -0
  160. package/dist/index.js.map +1 -0
  161. package/dist/mail/imap-errors.d.ts +4 -0
  162. package/dist/mail/imap-errors.d.ts.map +1 -0
  163. package/dist/mail/imap-errors.js +41 -0
  164. package/dist/mail/imap-errors.js.map +1 -0
  165. package/dist/mail/imap-messages.d.ts +18 -0
  166. package/dist/mail/imap-messages.d.ts.map +1 -0
  167. package/dist/mail/imap-messages.js +66 -0
  168. package/dist/mail/imap-messages.js.map +1 -0
  169. package/dist/mail/imap.d.ts +67 -0
  170. package/dist/mail/imap.d.ts.map +1 -0
  171. package/dist/mail/imap.js +348 -0
  172. package/dist/mail/imap.js.map +1 -0
  173. package/dist/profile.d.ts +16 -0
  174. package/dist/profile.d.ts.map +1 -0
  175. package/dist/profile.js +31 -0
  176. package/dist/profile.js.map +1 -0
  177. package/dist/program.d.ts +6 -0
  178. package/dist/program.d.ts.map +1 -0
  179. package/dist/program.js +52 -0
  180. package/dist/program.js.map +1 -0
  181. package/dist/providers.d.ts +53 -0
  182. package/dist/providers.d.ts.map +1 -0
  183. package/dist/providers.js +106 -0
  184. package/dist/providers.js.map +1 -0
  185. package/dist/secret.d.ts +30 -0
  186. package/dist/secret.d.ts.map +1 -0
  187. package/dist/secret.js +68 -0
  188. package/dist/secret.js.map +1 -0
  189. package/dist/store.d.ts +12 -0
  190. package/dist/store.d.ts.map +1 -0
  191. package/dist/store.js +25 -0
  192. package/dist/store.js.map +1 -0
  193. package/dist/version.d.ts +2 -0
  194. package/dist/version.d.ts.map +1 -0
  195. package/dist/version.js +2 -0
  196. package/dist/version.js.map +1 -0
  197. package/package.json +83 -4
  198. package/skills/mail-cli/SKILL.md +27 -0
@@ -0,0 +1,379 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ CliError
5
+ } from "./chunk-5BVIWP3S.js";
6
+ import {
7
+ __name
8
+ } from "./chunk-ZVVMGPBJ.js";
9
+
10
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/ordinary-file.js
11
+ import { constants } from "node:fs";
12
+ import { lstat, open } from "node:fs/promises";
13
+ var deviceOf = /* @__PURE__ */ __name((dev) => process.platform === "win32" ? BigInt.asUintN(32, dev) : dev, "deviceOf");
14
+ var sameIdentity = /* @__PURE__ */ __name((left, right) => left.ino === right.ino && deviceOf(left.dev) === deviceOf(right.dev), "sameIdentity");
15
+ var openOrdinaryFile = /* @__PURE__ */ __name(async (path, options = {}) => {
16
+ const before = await lstat(path, { bigint: true });
17
+ if (before.isSymbolicLink())
18
+ throw new CliError("validation_error", "archive path must be an ordinary file without a symlink");
19
+ if (!before.isFile())
20
+ throw new CliError("validation_error", "archive path must be an ordinary file");
21
+ const access = options.writable ? constants.O_RDWR : constants.O_RDONLY;
22
+ const flags = process.platform === "win32" ? access : access | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
23
+ const file = await open(path, flags);
24
+ try {
25
+ const opened = await file.stat({ bigint: true });
26
+ const after = await lstat(path, { bigint: true });
27
+ if (!opened.isFile() || !after.isFile() || before.ino !== opened.ino || before.ino !== after.ino)
28
+ throw new CliError("validation_error", "archive file changed while opening");
29
+ if (process.platform === "win32" && before.dev === 0n && after.dev === 0n) {
30
+ const witness = await open(path, flags);
31
+ try {
32
+ const identified = await witness.stat({ bigint: true });
33
+ const final = await lstat(path, { bigint: true });
34
+ if (opened.dev === 0n || !identified.isFile() || !final.isFile() || !sameIdentity(identified, opened) || final.ino !== before.ino || final.dev !== 0n && deviceOf(final.dev) !== deviceOf(opened.dev))
35
+ throw new CliError("validation_error", "archive file changed while opening");
36
+ } finally {
37
+ await witness.close();
38
+ }
39
+ } else if (deviceOf(before.dev) !== deviceOf(opened.dev) || deviceOf(before.dev) !== deviceOf(after.dev)) {
40
+ throw new CliError("validation_error", "archive file changed while opening");
41
+ }
42
+ return file;
43
+ } catch (error) {
44
+ await file.close();
45
+ throw error;
46
+ }
47
+ }, "openOrdinaryFile");
48
+ var sameOrdinaryFile = /* @__PURE__ */ __name(async (path, created) => {
49
+ let file;
50
+ try {
51
+ file = await openOrdinaryFile(path);
52
+ } catch (error) {
53
+ if (error instanceof CliError || typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")
54
+ return false;
55
+ throw error;
56
+ }
57
+ try {
58
+ return sameIdentity(created, await file.stat({ bigint: true }));
59
+ } finally {
60
+ await file.close();
61
+ }
62
+ }, "sameOrdinaryFile");
63
+ var syncDirectory = /* @__PURE__ */ __name(async (path) => {
64
+ if (process.platform === "win32")
65
+ return;
66
+ const directory = await open(path, constants.O_RDONLY | (constants.O_DIRECTORY ?? 0) | (constants.O_NOFOLLOW ?? 0));
67
+ try {
68
+ if (!(await directory.stat()).isDirectory())
69
+ throw new CliError("validation_error", "archive publication directory must be ordinary");
70
+ await directory.sync();
71
+ } finally {
72
+ await directory.close();
73
+ }
74
+ }, "syncDirectory");
75
+
76
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/atomic-write.js
77
+ import { randomUUID } from "node:crypto";
78
+ import { constants as constants2 } from "node:fs";
79
+ import { link, open as open2, realpath, rename, unlink } from "node:fs/promises";
80
+ import { basename, dirname, join } from "node:path";
81
+ var openFolder = /* @__PURE__ */ __name((folder) => process.platform === "win32" ? Promise.resolve(void 0) : open2(folder, constants2.O_RDONLY | (constants2.O_DIRECTORY ?? 0) | (constants2.O_NOFOLLOW ?? 0)), "openFolder");
82
+ var writeFileAtomic = /* @__PURE__ */ __name(async (path, content, { mode = 384, overwrite = true, signal, beforePublish } = {}) => {
83
+ signal?.throwIfAborted();
84
+ const folder = await realpath(dirname(path));
85
+ const target = join(folder, basename(path));
86
+ const directory = await openFolder(folder);
87
+ try {
88
+ const temporary = join(folder, `.${basename(path)}.${randomUUID()}.tmp`);
89
+ let handle = await open2(temporary, "wx", mode);
90
+ let published = false;
91
+ try {
92
+ await handle.writeFile(content);
93
+ await handle.sync();
94
+ await handle.close();
95
+ handle = void 0;
96
+ signal?.throwIfAborted();
97
+ await beforePublish?.();
98
+ if (overwrite)
99
+ await rename(temporary, target);
100
+ else
101
+ await link(temporary, target);
102
+ published = overwrite;
103
+ await directory?.sync();
104
+ } finally {
105
+ await handle?.close().catch(() => void 0);
106
+ if (!published)
107
+ await unlink(temporary).catch(() => void 0);
108
+ }
109
+ } finally {
110
+ await directory?.close().catch(() => void 0);
111
+ }
112
+ }, "writeFileAtomic");
113
+
114
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/bounded-utf8.js
115
+ var readBoundedUtf8File = /* @__PURE__ */ __name(async (path, { maxBytes }) => {
116
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > 16 * 1024 * 1024)
117
+ throw new CliError("validation_error", "file maxBytes takes 1\u201316777216 bytes");
118
+ const file = await openOrdinaryFile(path);
119
+ try {
120
+ if ((await file.stat()).size > maxBytes)
121
+ throw new CliError("validation_error", "input file exceeds its byte budget");
122
+ const chunks = [], buffer = Buffer.alloc(Math.min(65536, maxBytes + 1));
123
+ let bytes = 0;
124
+ for (; ; ) {
125
+ const { bytesRead } = await file.read(buffer, 0, Math.min(buffer.length, maxBytes - bytes + 1), null);
126
+ if (bytesRead === 0)
127
+ break;
128
+ bytes += bytesRead;
129
+ if (bytes > maxBytes)
130
+ throw new CliError("validation_error", "input file exceeds its byte budget");
131
+ chunks.push(Buffer.from(buffer.subarray(0, bytesRead)));
132
+ }
133
+ try {
134
+ return new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks, bytes));
135
+ } catch {
136
+ throw new CliError("validation_error", "input file must contain valid UTF-8");
137
+ }
138
+ } finally {
139
+ await file.close();
140
+ }
141
+ }, "readBoundedUtf8File");
142
+
143
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/lock.js
144
+ import { mkdir as mkdir2 } from "node:fs/promises";
145
+ import { basename as basename2, dirname as dirname2 } from "node:path";
146
+
147
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/native-writer-lease.js
148
+ import { randomUUID as randomUUID2 } from "node:crypto";
149
+ import { lstat as lstat3, mkdir, open as open3, realpath as realpath3, rmdir as rmdir2, unlink as unlink4 } from "node:fs/promises";
150
+ import { hostname as hostname2 } from "node:os";
151
+ import { join as join3 } from "node:path";
152
+
153
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/native-lease-inspection.js
154
+ import { lstat as lstat2, readdir, realpath as realpath2, unlink as unlink2 } from "node:fs/promises";
155
+ import { join as join2 } from "node:path";
156
+
157
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/native-lease-owner.js
158
+ import { hostname } from "node:os";
159
+ var missingLeaseFile = /* @__PURE__ */ __name((error) => typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT", "missingLeaseFile");
160
+ var readLeaseOwner = /* @__PURE__ */ __name(async (path, name, signal) => {
161
+ signal?.throwIfAborted();
162
+ try {
163
+ const file = await openOrdinaryFile(path);
164
+ try {
165
+ if ((await file.stat()).size > 4096)
166
+ return null;
167
+ const buffer = Buffer.alloc(4097);
168
+ let size = 0;
169
+ while (size < buffer.length) {
170
+ signal?.throwIfAborted();
171
+ const { bytesRead } = await file.read(buffer, size, buffer.length - size, size);
172
+ if (bytesRead === 0)
173
+ break;
174
+ size += bytesRead;
175
+ }
176
+ signal?.throwIfAborted();
177
+ if (size > 4096)
178
+ return null;
179
+ const owner = JSON.parse(buffer.subarray(0, size).toString("utf8"));
180
+ if (owner?.version !== 1 || !Number.isSafeInteger(owner.pid) || owner.pid <= 0 || typeof owner.host !== "string" || !owner.host.trim() || !/^[a-f0-9-]{36}$/.test(owner.nonce) || name !== `${owner.pid}-${owner.nonce}.json`)
181
+ return null;
182
+ return owner;
183
+ } finally {
184
+ await file.close();
185
+ }
186
+ } catch {
187
+ signal?.throwIfAborted();
188
+ return null;
189
+ }
190
+ }, "readLeaseOwner");
191
+ var leaseOwnerStatus = /* @__PURE__ */ __name((owner) => {
192
+ if (owner.host !== hostname())
193
+ return "foreign";
194
+ try {
195
+ process.kill(owner.pid, 0);
196
+ return "active";
197
+ } catch (error) {
198
+ return typeof error === "object" && error !== null && "code" in error && error.code === "ESRCH" ? "stale" : "active";
199
+ }
200
+ }, "leaseOwnerStatus");
201
+
202
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/native-lease-inspection.js
203
+ var leaseInspection = /* @__PURE__ */ __name((markerDirectory) => {
204
+ const inspect = /* @__PURE__ */ __name(async (destination, options = {}) => {
205
+ options.signal?.throwIfAborted();
206
+ const root = await realpath2(destination);
207
+ options.signal?.throwIfAborted();
208
+ const folder = join2(root, markerDirectory);
209
+ let names;
210
+ try {
211
+ if ((await lstat2(folder)).isSymbolicLink())
212
+ throw new Error("symlink");
213
+ names = await readdir(folder);
214
+ } catch (error) {
215
+ options.signal?.throwIfAborted();
216
+ if (missingLeaseFile(error))
217
+ return [];
218
+ throw new CliError("configuration_error", "archive lock directory could not be read");
219
+ }
220
+ options.signal?.throwIfAborted();
221
+ const result = [];
222
+ for (const name of names.sort()) {
223
+ options.signal?.throwIfAborted();
224
+ const owner = await readLeaseOwner(join2(folder, name), name, options.signal);
225
+ result.push({
226
+ name,
227
+ status: owner ? leaseOwnerStatus(owner) : "unrecognized",
228
+ pid: owner?.pid ?? null,
229
+ host: owner?.host ?? null
230
+ });
231
+ }
232
+ return result;
233
+ }, "inspect");
234
+ const recover = /* @__PURE__ */ __name(async (destination, options = {}) => {
235
+ options.signal?.throwIfAborted();
236
+ const root = await realpath2(destination);
237
+ const locks = await inspect(root, options);
238
+ const removed = [];
239
+ if (options.apply)
240
+ for (const lock of locks) {
241
+ options.signal?.throwIfAborted();
242
+ if (lock.status !== "stale")
243
+ continue;
244
+ const path = join2(root, markerDirectory, lock.name);
245
+ const owner = await readLeaseOwner(path, lock.name, options.signal);
246
+ if (!owner || leaseOwnerStatus(owner) !== "stale")
247
+ continue;
248
+ try {
249
+ await unlink2(path);
250
+ removed.push(lock.name);
251
+ } catch (error) {
252
+ if (!missingLeaseFile(error))
253
+ throw new CliError("configuration_error", "stale archive lock could not be removed");
254
+ }
255
+ }
256
+ return { locks, removed };
257
+ }, "recover");
258
+ return { inspect, recover };
259
+ }, "leaseInspection");
260
+
261
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/native-lease-release.js
262
+ import { rmdir, unlink as unlink3 } from "node:fs/promises";
263
+ var ownedNativeLease = /* @__PURE__ */ __name((path, name, owner, folder, identity) => {
264
+ let releasing;
265
+ const held = /* @__PURE__ */ __name(async () => {
266
+ if (!await sameOrdinaryFile(path, identity))
267
+ return false;
268
+ const current = await readLeaseOwner(path, name);
269
+ return current?.host === owner.host && current.pid === owner.pid && current.nonce === owner.nonce;
270
+ }, "held");
271
+ const release = /* @__PURE__ */ __name(async () => {
272
+ if (!await held())
273
+ throw new CliError("configuration_error", "owned archive lock changed before release");
274
+ await unlink3(path);
275
+ await rmdir(folder).catch(() => void 0);
276
+ }, "release");
277
+ return {
278
+ held,
279
+ release: /* @__PURE__ */ __name(() => releasing ??= release().catch((error) => {
280
+ releasing = void 0;
281
+ throw error;
282
+ }), "release")
283
+ };
284
+ }, "ownedNativeLease");
285
+
286
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/native-writer-lease.js
287
+ var validName = /* @__PURE__ */ __name((value) => typeof value === "string" && value.length > 0 && value !== "." && value !== ".." && !/[\\/\0:]/.test(value), "validName");
288
+ var nativeWriterLeaseStore = /* @__PURE__ */ __name((layout) => {
289
+ const { markerDirectory, legacyMarker } = layout;
290
+ if (!validName(markerDirectory) || legacyMarker !== void 0 && (!validName(legacyMarker) || legacyMarker === markerDirectory))
291
+ throw new CliError("validation_error", "archive lock layout requires distinct ordinary entry names");
292
+ const inspection = leaseInspection(markerDirectory);
293
+ return {
294
+ ...inspection,
295
+ acquire: /* @__PURE__ */ __name(async (destination, { signal } = {}) => {
296
+ signal?.throwIfAborted();
297
+ const root = await realpath3(destination);
298
+ signal?.throwIfAborted();
299
+ const folder = join3(root, markerDirectory);
300
+ const owner = { version: 1, pid: process.pid, host: hostname2(), nonce: randomUUID2() };
301
+ const name = `${owner.pid}-${owner.nonce}.json`;
302
+ const path = join3(folder, name);
303
+ const marker = /* @__PURE__ */ __name(async (attempt = 1) => {
304
+ await mkdir(folder, { recursive: true });
305
+ try {
306
+ if ((await lstat3(folder)).isSymbolicLink())
307
+ throw new CliError("validation_error", "archive lock directory must not be a symlink");
308
+ await inspection.recover(root, { apply: true, signal });
309
+ signal?.throwIfAborted();
310
+ return await open3(path, "wx", 384);
311
+ } catch (error) {
312
+ if (attempt < 5 && missingLeaseFile(error))
313
+ return marker(attempt + 1);
314
+ throw error;
315
+ }
316
+ }, "marker");
317
+ const file = await marker();
318
+ let retained = false;
319
+ let identity;
320
+ try {
321
+ identity = await file.stat({ bigint: true });
322
+ await file.writeFile(JSON.stringify(owner));
323
+ await file.sync();
324
+ await file.close();
325
+ signal?.throwIfAborted();
326
+ const inspected = await inspection.inspect(root, { signal });
327
+ const own = inspected.find((lock) => lock.name === name);
328
+ if (own?.status !== "active" || own.pid !== owner.pid || own.host !== owner.host)
329
+ throw new CliError("configuration_error", "archive writer lost its lock before acquisition");
330
+ const locks = inspected.filter((lock) => lock.name !== name);
331
+ if (locks.length)
332
+ return { status: "busy", locks };
333
+ if (legacyMarker) {
334
+ try {
335
+ await lstat3(join3(root, legacyMarker));
336
+ return { status: "legacy" };
337
+ } catch (error) {
338
+ if (!missingLeaseFile(error))
339
+ throw error;
340
+ }
341
+ }
342
+ signal?.throwIfAborted();
343
+ retained = true;
344
+ return { status: "acquired", lease: ownedNativeLease(path, name, owner, folder, identity) };
345
+ } finally {
346
+ await file.close().catch(() => void 0);
347
+ if (!retained) {
348
+ if (identity && await sameOrdinaryFile(path, identity))
349
+ await unlink4(path).catch(() => void 0);
350
+ await rmdir2(folder).catch(() => void 0);
351
+ }
352
+ }
353
+ }, "acquire")
354
+ };
355
+ }, "nativeWriterLeaseStore");
356
+
357
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/files/lock.js
358
+ var acquireLock = /* @__PURE__ */ __name(async (path, { signal } = {}) => {
359
+ const folder = dirname2(path);
360
+ await mkdir2(folder, { recursive: true, mode: 448 });
361
+ const acquired = await nativeWriterLeaseStore({ markerDirectory: basename2(path) }).acquire(folder, {
362
+ ...signal ? { signal } : {}
363
+ });
364
+ if (acquired.status === "acquired")
365
+ return acquired.lease;
366
+ throw new CliError("validation_error", `${basename2(path)} is locked by another process`, {
367
+ reason: "file.locked",
368
+ ...acquired.status === "busy" ? { holders: acquired.locks } : {}
369
+ });
370
+ }, "acquireLock");
371
+
372
+ export {
373
+ writeFileAtomic,
374
+ openOrdinaryFile,
375
+ sameOrdinaryFile,
376
+ syncDirectory,
377
+ readBoundedUtf8File,
378
+ acquireLock
379
+ };