@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,411 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ require_cross_spawn
5
+ } from "./chunk-D72URWJE.js";
6
+ import {
7
+ BUILT_IN_COMMANDS,
8
+ DESCRIBE_FLAG,
9
+ FIRST_PARTY_TOOLS,
10
+ PROGRAM_PREFIX,
11
+ TOOL_NAME,
12
+ fileState,
13
+ parseDescribe,
14
+ shimFiles,
15
+ writeShim
16
+ } from "./chunk-TI6VBZKJ.js";
17
+ import "./chunk-Y5E2WNWB.js";
18
+ import {
19
+ CliError
20
+ } from "./chunk-5BVIWP3S.js";
21
+ import {
22
+ __name,
23
+ __toESM
24
+ } from "./chunk-ZVVMGPBJ.js";
25
+
26
+ // node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/wcat/dispatch.js
27
+ var import_cross_spawn2 = __toESM(require_cross_spawn(), 1);
28
+ import { randomUUID } from "node:crypto";
29
+ import { constants } from "node:os";
30
+
31
+ // node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/wcat/path.js
32
+ import { readdirSync, statSync } from "node:fs";
33
+ import { join } from "node:path";
34
+ var variable = /* @__PURE__ */ __name((env, name, platform) => platform === "win32" ? Object.entries(env).find(([key]) => key.toUpperCase() === name)?.[1] : env[name], "variable");
35
+ var pathEntries = /* @__PURE__ */ __name(({ env, platform }) => {
36
+ const raw = variable(env, "PATH", platform) ?? "";
37
+ const entries = raw.split(platform === "win32" ? ";" : ":").map((entry) => entry.replace(/^"(.*)"$/, "$1"));
38
+ const seen = /* @__PURE__ */ new Set();
39
+ return entries.filter((entry) => {
40
+ const key = platform === "win32" ? entry.toLowerCase().replace(/[\\/]+$/, "") : entry.replace(/\/+$/, "");
41
+ if (entry === "" || seen.has(key))
42
+ return false;
43
+ seen.add(key);
44
+ return true;
45
+ });
46
+ }, "pathEntries");
47
+ var programExtensions = /* @__PURE__ */ __name(({ env, platform }) => platform === "win32" ? (variable(env, "PATHEXT", platform) ?? ".COM;.EXE;.BAT;.CMD").split(";").filter((ext) => /^\.[a-z0-9]+$/i.test(ext)).map((ext) => ext.toLowerCase()) : [""], "programExtensions");
48
+ var isProgram = /* @__PURE__ */ __name((path, platform) => {
49
+ try {
50
+ const stat = statSync(path);
51
+ return stat.isFile() && (platform === "win32" || (stat.mode & 73) !== 0);
52
+ } catch {
53
+ return false;
54
+ }
55
+ }, "isProgram");
56
+ var findOnPath = /* @__PURE__ */ __name((command, search) => {
57
+ const extensions = programExtensions(search);
58
+ return pathEntries(search).flatMap((dir) => {
59
+ for (const extension of extensions) {
60
+ const path = join(dir, command + extension);
61
+ if (isProgram(path, search.platform))
62
+ return [path];
63
+ }
64
+ return [];
65
+ });
66
+ }, "findOnPath");
67
+ var findTools = /* @__PURE__ */ __name((search) => {
68
+ const extensions = programExtensions(search);
69
+ const tools = /* @__PURE__ */ new Map();
70
+ for (const dir of pathEntries(search)) {
71
+ let files;
72
+ try {
73
+ files = readdirSync(dir);
74
+ } catch {
75
+ continue;
76
+ }
77
+ const here = /* @__PURE__ */ new Map();
78
+ for (const file of files) {
79
+ if (!(search.platform === "win32" ? file.toLowerCase() : file).startsWith(PROGRAM_PREFIX))
80
+ continue;
81
+ const extension = extensions.find((ext) => ext !== "" && file.toLowerCase().endsWith(ext)) ?? "";
82
+ if (search.platform === "win32" && extension === "")
83
+ continue;
84
+ const base = search.platform === "win32" ? file.toLowerCase() : file;
85
+ const name = base.slice(PROGRAM_PREFIX.length, base.length - extension.length);
86
+ if (!TOOL_NAME.test(name))
87
+ continue;
88
+ const best = here.get(name);
89
+ const rank = /* @__PURE__ */ __name((path2) => extensions.findIndex((ext) => path2.toLowerCase().endsWith(ext)), "rank");
90
+ const path = join(dir, file);
91
+ if (best !== void 0 && rank(best) <= rank(path))
92
+ continue;
93
+ if (isProgram(path, search.platform))
94
+ here.set(name, path);
95
+ }
96
+ for (const [name, path] of here)
97
+ tools.set(name, [...tools.get(name) ?? [], path]);
98
+ }
99
+ return new Map([...tools].sort(([a], [b]) => a < b ? -1 : 1));
100
+ }, "findTools");
101
+ var isBuiltIn = /* @__PURE__ */ __name((name) => name === "wcat" || BUILT_IN_COMMANDS.includes(name), "isBuiltIn");
102
+
103
+ // node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/wcat/probe.js
104
+ var import_cross_spawn = __toESM(require_cross_spawn(), 1);
105
+ import { readFileSync } from "node:fs";
106
+ var MAX_ANSWER_BYTES = 64 * 1024;
107
+ var probeDescribe = /* @__PURE__ */ __name((path, { env, timeoutMs }) => new Promise((resolve) => {
108
+ let child;
109
+ try {
110
+ child = (0, import_cross_spawn.default)(path, [DESCRIBE_FLAG], { stdio: ["ignore", "pipe", "ignore"], env, windowsHide: true });
111
+ } catch {
112
+ resolve(void 0);
113
+ return;
114
+ }
115
+ const chunks = [];
116
+ let size = 0;
117
+ let settled = false;
118
+ const settle = /* @__PURE__ */ __name((answer) => {
119
+ if (settled)
120
+ return;
121
+ settled = true;
122
+ clearTimeout(timer);
123
+ resolve(answer);
124
+ }, "settle");
125
+ const giveUp = /* @__PURE__ */ __name(() => {
126
+ child.kill();
127
+ child.stdout?.destroy();
128
+ child.unref();
129
+ settle(void 0);
130
+ }, "giveUp");
131
+ const timer = setTimeout(giveUp, timeoutMs);
132
+ child.stdout?.on("data", (chunk) => {
133
+ size += chunk.length;
134
+ if (size > MAX_ANSWER_BYTES)
135
+ giveUp();
136
+ else
137
+ chunks.push(chunk);
138
+ });
139
+ child.once("error", () => settle(void 0));
140
+ child.once("close", (code) => settle(code === 0 ? parseDescribe(Buffer.concat(chunks).toString("utf8")) : void 0));
141
+ }), "probeDescribe");
142
+ var baseVersion = /* @__PURE__ */ __name(() => {
143
+ try {
144
+ const raw = readFileSync(new URL("../../package.json", new URL("wcat/probe.js", import.meta.resolve("@wirecat/cli-base")).href), "utf8");
145
+ const { name, version } = JSON.parse(raw);
146
+ return name === "@wirecat/cli-base" && typeof version === "string" ? version : "unknown";
147
+ } catch {
148
+ return "unknown";
149
+ }
150
+ }, "baseVersion");
151
+
152
+ // node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/wcat/shortcuts.js
153
+ import { closeSync, openSync, readSync, realpathSync, rmSync } from "node:fs";
154
+ import { basename, dirname } from "node:path";
155
+ var WIRECAT_PACKAGE = /node_modules[\\/]+@wirecat[\\/]/;
156
+ var isWirecatPackage = /* @__PURE__ */ __name((path) => {
157
+ try {
158
+ if (WIRECAT_PACKAGE.test(realpathSync(path)))
159
+ return true;
160
+ const buffer = Buffer.alloc(16 * 1024);
161
+ const fd = openSync(path, "r");
162
+ try {
163
+ const read = readSync(fd, buffer, 0, buffer.length, 0);
164
+ return WIRECAT_PACKAGE.test(buffer.subarray(0, read).toString("latin1"));
165
+ } finally {
166
+ closeSync(fd);
167
+ }
168
+ } catch {
169
+ return false;
170
+ }
171
+ }, "isWirecatPackage");
172
+ var ourShortcut = /* @__PURE__ */ __name((path) => {
173
+ const state = fileState(path);
174
+ return state.state === "ours" && state.mark.kind === "shortcut";
175
+ }, "ourShortcut");
176
+ var statusOf = /* @__PURE__ */ __name((name, program, search) => {
177
+ const files = shimFiles("shortcut", {
178
+ dir: dirname(program),
179
+ name,
180
+ target: basename(program),
181
+ platform: search.platform
182
+ });
183
+ const named = findOnPath(name, search);
184
+ const made = [...files.map((file) => file.path), ...named].find(ourShortcut);
185
+ if (made)
186
+ return { name, status: "made", path: made, program };
187
+ const first = named[0];
188
+ if (first === void 0)
189
+ return { name, status: "free", program };
190
+ return { name, status: isWirecatPackage(first) ? "package" : "taken", path: first, program };
191
+ }, "statusOf");
192
+ var changeFile = /* @__PURE__ */ __name((path, change) => {
193
+ try {
194
+ change();
195
+ } catch (error) {
196
+ throw new CliError("permission_error", `could not change ${path}: ${error.code ?? error}`, {
197
+ reason: "access.denied"
198
+ });
199
+ }
200
+ }, "changeFile");
201
+ var installedPrograms = /* @__PURE__ */ __name((search) => new Map([...findTools(search)].filter(([name]) => !isBuiltIn(name))), "installedPrograms");
202
+ var chosen = /* @__PURE__ */ __name((names, search) => {
203
+ const installed = installedPrograms(search);
204
+ if (names === void 0 || names.length === 0)
205
+ return [...installed].map(([name, paths]) => [name, paths[0]]);
206
+ const missing = names.filter((name) => !installed.has(name));
207
+ if (missing.length > 0)
208
+ throw new CliError("not_found", `not installed: ${missing.map((name) => `wcat-${name}`).join(", ")}`, {
209
+ reason: "tool.not-installed",
210
+ tool: missing[0],
211
+ installed: [...installed.keys()]
212
+ });
213
+ return [...new Set(names)].map((name) => [name, installed.get(name)[0]]);
214
+ }, "chosen");
215
+ var listShortcuts = /* @__PURE__ */ __name((search, names) => chosen(names, search).map(([name, program]) => statusOf(name, program, search)), "listShortcuts");
216
+ var addShortcuts = /* @__PURE__ */ __name((search, names) => listShortcuts(search, names).map((shortcut) => {
217
+ if (shortcut.status !== "free")
218
+ return { ...shortcut, changed: false };
219
+ const files = shimFiles("shortcut", {
220
+ dir: dirname(shortcut.program),
221
+ name: shortcut.name,
222
+ target: basename(shortcut.program),
223
+ platform: search.platform
224
+ });
225
+ for (const file of files)
226
+ changeFile(file.path, () => writeShim(file));
227
+ return { ...shortcut, status: "made", path: files[0]?.path, changed: true };
228
+ }), "addShortcuts");
229
+ var removeShortcuts = /* @__PURE__ */ __name((search, names) => listShortcuts(search, names).map((shortcut) => {
230
+ if (shortcut.status !== "made")
231
+ return { ...shortcut, changed: false };
232
+ const files = shimFiles("shortcut", {
233
+ dir: dirname(shortcut.path),
234
+ name: shortcut.name,
235
+ target: basename(shortcut.program),
236
+ platform: search.platform
237
+ });
238
+ for (const file of files)
239
+ if (ourShortcut(file.path))
240
+ changeFile(file.path, () => rmSync(file.path, { force: true }));
241
+ return { ...statusOf(shortcut.name, shortcut.program, search), changed: true };
242
+ }), "removeShortcuts");
243
+
244
+ // node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/wcat/dispatch.js
245
+ var DEFAULT_DESCRIBE_TIMEOUT_MS = 2e3;
246
+ var listTools = /* @__PURE__ */ __name(async (context) => {
247
+ const installed = installedPrograms(context);
248
+ const timeoutMs = context.describeTimeoutMs ?? DEFAULT_DESCRIBE_TIMEOUT_MS;
249
+ const found = await Promise.all([...installed].map(async ([name, paths]) => {
250
+ const [path, ...shadowed] = paths;
251
+ const own = context.self?.command === name ? context.self : void 0;
252
+ const described = own ?? await probeDescribe(path, { env: context.env, timeoutMs });
253
+ return {
254
+ name,
255
+ installed: true,
256
+ path,
257
+ ...described?.version ? { version: described.version } : {},
258
+ ...described?.description ? { description: described.description } : {},
259
+ ...described?.docs ? { docs_url: described.docs } : {},
260
+ ...shadowed.length > 0 ? { shadowed } : {}
261
+ };
262
+ }));
263
+ const missing = FIRST_PARTY_TOOLS.filter((tool) => tool.package && !installed.has(tool.name)).map((tool) => ({
264
+ name: tool.name,
265
+ installed: false,
266
+ package: tool.package,
267
+ install: `npm install -g ${tool.package}`
268
+ }));
269
+ return [...found, ...missing];
270
+ }, "listTools");
271
+ var envelope = /* @__PURE__ */ __name((items, started) => ({
272
+ items,
273
+ page: { mode: "page", limit: Math.max(items.length, 1), has_more: false },
274
+ meta: { run_id: randomUUID(), duration_ms: Math.max(0, Math.round(performance.now() - started)), complete: true }
275
+ }), "envelope");
276
+ var column = /* @__PURE__ */ __name((rows) => {
277
+ const widths = rows[0]?.map((_, at) => rows.reduce((wide, row) => Math.max(wide, (row[at] ?? "").length), 0)) ?? [];
278
+ return rows.map((row) => ` ${row.map((cell, at) => cell.padEnd(widths[at] ?? 0)).join(" ")}`.trimEnd());
279
+ }, "column");
280
+ var USAGE = [
281
+ "wcat <tool> [arguments] run a tool: wcat tg --help",
282
+ "wcat shortcuts [add|remove] [tool...] short names, such as tg, for installed tools",
283
+ "wcat --json the list below as JSON"
284
+ ];
285
+ var listText = /* @__PURE__ */ __name((tools) => {
286
+ const installed = tools.filter((tool) => tool.installed);
287
+ const missing = tools.filter((tool) => !tool.installed);
288
+ return [
289
+ "wcat runs WireCat tools, and any other wcat-<name> program on PATH.",
290
+ "",
291
+ ...USAGE,
292
+ "",
293
+ installed.length > 0 ? "Installed:" : "Installed: none",
294
+ ...column(installed.map((tool) => [tool.name, tool.version ?? "", tool.description ?? "(no description)"])),
295
+ ...missing.length > 0 ? ["", "Not installed:", ...column(missing.map((tool) => [tool.name, tool.install ?? ""]))] : [],
296
+ ""
297
+ ].join("\n");
298
+ }, "listText");
299
+ var shadowWarnings = /* @__PURE__ */ __name((tools) => tools.filter((tool) => tool.shadowed).map((tool) => `wcat: ${(tool.shadowed?.length ?? 0) + 1} programs are named ${PROGRAM_PREFIX}${tool.name}; wcat runs the first:
300
+ ${[tool.path, ...tool.shadowed ?? []].map((path) => ` ${path}`).join("\n")}
301
+ `).join(""), "shadowWarnings");
302
+ var shortcutText = /* @__PURE__ */ __name((shortcuts2) => {
303
+ if (shortcuts2.length === 0)
304
+ return "No wcat-<name> programs are installed.\n";
305
+ const said = /* @__PURE__ */ __name((shortcut) => {
306
+ switch (shortcut.status) {
307
+ case "made":
308
+ return `made: ${shortcut.path}`;
309
+ case "free":
310
+ return shortcut.changed ? "removed" : "free: wcat shortcuts add makes it";
311
+ case "package":
312
+ return `installed by the package: ${shortcut.path}`;
313
+ case "taken":
314
+ return `taken by ${shortcut.path}`;
315
+ }
316
+ }, "said");
317
+ return `${column(shortcuts2.map((shortcut) => [shortcut.name, said(shortcut)])).join("\n")}
318
+ `;
319
+ }, "shortcutText");
320
+ var signalNumber = /* @__PURE__ */ __name((signal) => constants.signals[signal] ?? 1, "signalNumber");
321
+ var runTool = /* @__PURE__ */ __name((path, args, context) => new Promise((resolve, reject) => {
322
+ const signals = context.signals ?? process;
323
+ const child = (0, import_cross_spawn2.default)(path, [...args], { stdio: "inherit", env: context.env });
324
+ const pass = /* @__PURE__ */ __name((signal) => () => child.kill(signal), "pass");
325
+ const term = pass("SIGTERM");
326
+ const hup = pass("SIGHUP");
327
+ const ignore = /* @__PURE__ */ __name(() => {
328
+ }, "ignore");
329
+ signals.on("SIGTERM", term).on("SIGHUP", hup).on("SIGINT", ignore);
330
+ const done = /* @__PURE__ */ __name(() => signals.off("SIGTERM", term).off("SIGHUP", hup).off("SIGINT", ignore), "done");
331
+ child.once("error", (error) => {
332
+ done();
333
+ reject(new CliError("configuration_error", `could not start ${path}: ${error.message}`));
334
+ });
335
+ child.once("exit", (code, signal) => {
336
+ done();
337
+ resolve(code ?? (signal ? 128 + signalNumber(signal) : 1));
338
+ });
339
+ }), "runTool");
340
+ var fail = /* @__PURE__ */ __name(async (error, json, context) => {
341
+ const { errorObjectOf, exitCodeOfError, renderError } = await import("./failure-OAIC5VAP.js");
342
+ const object = errorObjectOf(error);
343
+ context.stderr.write(`${renderError(object, { cli: "wcat", interactive: !json })}
344
+ `);
345
+ return exitCodeOfError(object);
346
+ }, "fail");
347
+ var shortcuts = /* @__PURE__ */ __name(async (args, json, context) => {
348
+ const [action, ...names] = args;
349
+ const started = performance.now();
350
+ const result = action === "add" ? addShortcuts(context, names) : action === "remove" ? removeShortcuts(context, names) : action === void 0 || action === "list" ? listShortcuts(context, names) : void 0;
351
+ if (result === void 0)
352
+ throw new CliError("validation_error", `wcat shortcuts takes list, add or remove, not "${action}"`, {
353
+ reason: "input.invalid"
354
+ });
355
+ context.stdout.write(json ? `${JSON.stringify(envelope(result, started))}
356
+ ` : shortcutText(result));
357
+ return 0;
358
+ }, "shortcuts");
359
+ var runWcat = /* @__PURE__ */ __name(async (args, context) => {
360
+ const [first, ...rest] = args;
361
+ const json = args.includes("--json");
362
+ const words = args.filter((word) => word !== "--json");
363
+ const started = performance.now();
364
+ try {
365
+ if (first === "--version" || first === "-V" || first === "version") {
366
+ const tools = await listTools(context);
367
+ const by = context.self ? `, run by ${PROGRAM_PREFIX}${context.self.command} ${context.self.version}` : "";
368
+ context.stdout.write(`wcat ${baseVersion()} (@wirecat/cli-base${by})
369
+
370
+ ${listText(tools)}`);
371
+ return 0;
372
+ }
373
+ if (words.length === 0 || first === "--help" || first === "-h" || first === "help") {
374
+ const tools = await listTools(context);
375
+ if (json)
376
+ context.stdout.write(`${JSON.stringify(envelope(tools, started))}
377
+ `);
378
+ else {
379
+ context.stderr.write(shadowWarnings(tools));
380
+ context.stdout.write(listText(tools));
381
+ }
382
+ return 0;
383
+ }
384
+ if (first === "shortcuts")
385
+ return await shortcuts(words.slice(1), json, context);
386
+ if (BUILT_IN_COMMANDS.includes(first))
387
+ throw new CliError("validation_error", `wcat ${first} is reserved for a later version of wcat`, {
388
+ reason: "input.invalid"
389
+ });
390
+ if (first?.startsWith("-"))
391
+ throw new CliError("validation_error", `wcat does not take ${first} before a tool's name`, {
392
+ reason: "input.invalid"
393
+ });
394
+ const name = first;
395
+ const [path, ...shadowed] = TOOL_NAME.test(name) ? findOnPath(`${PROGRAM_PREFIX}${name}`, context) : [];
396
+ if (path === void 0) {
397
+ const installed = [...installedPrograms(context).keys()];
398
+ throw new CliError("not_found", `no ${PROGRAM_PREFIX}${name} on PATH; installed: ${installed.length > 0 ? installed.join(", ") : "none"}`, { reason: "tool.not-installed", tool: name, installed });
399
+ }
400
+ if (shadowed.length > 0 && context.stderr.isTTY)
401
+ context.stderr.write(shadowWarnings([{ name, installed: true, path, shadowed }]));
402
+ return await runTool(path, rest, context);
403
+ } catch (error) {
404
+ return fail(error, json, context);
405
+ }
406
+ }, "runWcat");
407
+ export {
408
+ listTools,
409
+ runTool,
410
+ runWcat
411
+ };