@wirecat/wordpress-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 (256) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +204 -0
  3. package/README.md +248 -2
  4. package/contracts/wirecat.json +2535 -0
  5. package/dist/bin/wordpress.d.ts +3 -0
  6. package/dist/bin/wordpress.d.ts.map +1 -0
  7. package/dist/bin/wordpress.js +40 -0
  8. package/dist/bin/wordpress.js.map +1 -0
  9. package/dist/bundle/agent-LKBRYKNB.js +37 -0
  10. package/dist/bundle/all-profiles-OEV7VFQG.js +320 -0
  11. package/dist/bundle/anthropic-JKTZP2DW.js +91 -0
  12. package/dist/bundle/app-server-7LWLDDE2.js +249 -0
  13. package/dist/bundle/bun-2FLR4IV4.js +169 -0
  14. package/dist/bundle/bun-sqlite-GRSRX5P4.js +76 -0
  15. package/dist/bundle/chunk-2BI25SEE.js +259 -0
  16. package/dist/bundle/chunk-2UEGJ5AJ.js +52 -0
  17. package/dist/bundle/chunk-2XUV7HNE.js +58 -0
  18. package/dist/bundle/chunk-2Z7UOXFC.js +16 -0
  19. package/dist/bundle/chunk-3BM6KBWP.js +2788 -0
  20. package/dist/bundle/chunk-3BRAZVHR.js +1010 -0
  21. package/dist/bundle/chunk-3LMW7U7F.js +1233 -0
  22. package/dist/bundle/chunk-3LVTQFGB.js +2000 -0
  23. package/dist/bundle/chunk-3TKFFSFU.js +106 -0
  24. package/dist/bundle/chunk-3UX4VJWD.js +78 -0
  25. package/dist/bundle/chunk-4HEXAGKT.js +334 -0
  26. package/dist/bundle/chunk-4HP6KGBI.js +32 -0
  27. package/dist/bundle/chunk-4ZAQMDLD.js +1308 -0
  28. package/dist/bundle/chunk-4ZTB7LS3.js +87 -0
  29. package/dist/bundle/chunk-5XPHFV7H.js +2333 -0
  30. package/dist/bundle/chunk-5Z3P543G.js +80 -0
  31. package/dist/bundle/chunk-6UYDKCV6.js +794 -0
  32. package/dist/bundle/chunk-7GNB4LBX.js +50 -0
  33. package/dist/bundle/chunk-7HJFBOAT.js +161 -0
  34. package/dist/bundle/chunk-7JVKQ6NM.js +206 -0
  35. package/dist/bundle/chunk-7QH5BZUG.js +142 -0
  36. package/dist/bundle/chunk-A474OVIW.js +1392 -0
  37. package/dist/bundle/chunk-AENEMQL3.js +1068 -0
  38. package/dist/bundle/chunk-AL7I4DT4.js +65718 -0
  39. package/dist/bundle/chunk-ARGRGTPX.js +108 -0
  40. package/dist/bundle/chunk-AV2ZJ4WX.js +7 -0
  41. package/dist/bundle/chunk-BAXNAOOL.js +76 -0
  42. package/dist/bundle/chunk-BH63B66W.js +407 -0
  43. package/dist/bundle/chunk-CCOSG3F2.js +24616 -0
  44. package/dist/bundle/chunk-CFQQTDSA.js +46 -0
  45. package/dist/bundle/chunk-CGCUOT67.js +388 -0
  46. package/dist/bundle/chunk-CHPWBQUK.js +39 -0
  47. package/dist/bundle/chunk-D72URWJE.js +532 -0
  48. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  49. package/dist/bundle/chunk-DQSOYH6N.js +20 -0
  50. package/dist/bundle/chunk-ECYOTDJM.js +14 -0
  51. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  52. package/dist/bundle/chunk-EHW45LLT.js +100 -0
  53. package/dist/bundle/chunk-F3AV5ZSL.js +338 -0
  54. package/dist/bundle/chunk-F4BX7TH2.js +15 -0
  55. package/dist/bundle/chunk-F5ZAN7OC.js +6848 -0
  56. package/dist/bundle/chunk-FMMYBVCH.js +38 -0
  57. package/dist/bundle/chunk-FNB4SWTY.js +66 -0
  58. package/dist/bundle/chunk-FQROWBKV.js +12660 -0
  59. package/dist/bundle/chunk-FV2HJOSC.js +771 -0
  60. package/dist/bundle/chunk-GCAJW4SR.js +53 -0
  61. package/dist/bundle/chunk-GPRJXJC7.js +102 -0
  62. package/dist/bundle/chunk-HCOZUOSN.js +54 -0
  63. package/dist/bundle/chunk-HM6AMYHR.js +72 -0
  64. package/dist/bundle/chunk-HVXOA4FO.js +23 -0
  65. package/dist/bundle/chunk-HWQ7572G.js +95 -0
  66. package/dist/bundle/chunk-IJVTN5L3.js +82 -0
  67. package/dist/bundle/chunk-IZDDBOHU.js +3610 -0
  68. package/dist/bundle/chunk-JAE5B4G7.js +388 -0
  69. package/dist/bundle/chunk-K2Y5K37O.js +218 -0
  70. package/dist/bundle/chunk-KCH224US.js +9581 -0
  71. package/dist/bundle/chunk-KZJQPJK5.js +230 -0
  72. package/dist/bundle/chunk-L7P3LUDQ.js +286 -0
  73. package/dist/bundle/chunk-LECMHK2F.js +18 -0
  74. package/dist/bundle/chunk-LWEMZJLG.js +1332 -0
  75. package/dist/bundle/chunk-LWTETL2O.js +185 -0
  76. package/dist/bundle/chunk-MEYYH47C.js +25 -0
  77. package/dist/bundle/chunk-MJ6LTG4L.js +170 -0
  78. package/dist/bundle/chunk-NMQRSEZM.js +37 -0
  79. package/dist/bundle/chunk-ODVGFCBE.js +557 -0
  80. package/dist/bundle/chunk-OEQNP56V.js +633 -0
  81. package/dist/bundle/chunk-OV6WQY3L.js +39 -0
  82. package/dist/bundle/chunk-PL5P7UKW.js +25216 -0
  83. package/dist/bundle/chunk-PPNTY7LD.js +733 -0
  84. package/dist/bundle/chunk-PRZYRA66.js +358 -0
  85. package/dist/bundle/chunk-PV5UYGRJ.js +41594 -0
  86. package/dist/bundle/chunk-QYTOLPNI.js +52 -0
  87. package/dist/bundle/chunk-R7Y3XU66.js +362 -0
  88. package/dist/bundle/chunk-S4UUN6LD.js +1410 -0
  89. package/dist/bundle/chunk-SD5CXGIG.js +188 -0
  90. package/dist/bundle/chunk-SXY5G62I.js +288 -0
  91. package/dist/bundle/chunk-T37TAXVL.js +29 -0
  92. package/dist/bundle/chunk-T5SOY3AE.js +1197 -0
  93. package/dist/bundle/chunk-TJ7OORSO.js +1876 -0
  94. package/dist/bundle/chunk-TRYYWV7J.js +291 -0
  95. package/dist/bundle/chunk-U6VLNYCO.js +73 -0
  96. package/dist/bundle/chunk-UC7JLE6J.js +58 -0
  97. package/dist/bundle/chunk-UUIOAZPH.js +156 -0
  98. package/dist/bundle/chunk-UXQ24OY6.js +4072 -0
  99. package/dist/bundle/chunk-VBRRMGON.js +1007 -0
  100. package/dist/bundle/chunk-VRIBES2C.js +319 -0
  101. package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
  102. package/dist/bundle/chunk-XT5XYQEZ.js +3414 -0
  103. package/dist/bundle/chunk-XTAS5Z3G.js +2231 -0
  104. package/dist/bundle/chunk-XYQVVW4R.js +24 -0
  105. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  106. package/dist/bundle/chunk-YHWFF6DN.js +39 -0
  107. package/dist/bundle/chunk-YUDVRFXN.js +63 -0
  108. package/dist/bundle/chunk-Z3I2MCUT.js +131 -0
  109. package/dist/bundle/chunk-ZDI3WC7V.js +353 -0
  110. package/dist/bundle/chunk-ZVQ7KFMT.js +274 -0
  111. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  112. package/dist/bundle/command-contract-P7YE4EKS.js +37 -0
  113. package/dist/bundle/command-server-entry-XIMCBWMV.js +166 -0
  114. package/dist/bundle/decode-6XK55WYV.js +297 -0
  115. package/dist/bundle/definitions-GIQCGYPR.js +7986 -0
  116. package/dist/bundle/dispatch-JQBAZWCL.js +411 -0
  117. package/dist/bundle/dist-2TV3NVE5.js +7577 -0
  118. package/dist/bundle/dist-PAKDDIBT.js +191 -0
  119. package/dist/bundle/echarts-YRRVLEX3.js +42501 -0
  120. package/dist/bundle/embed-L3EEQSGX.js +38 -0
  121. package/dist/bundle/embedder-BIKLBV3J.js +111 -0
  122. package/dist/bundle/failure-I6AAF5R5.js +25 -0
  123. package/dist/bundle/first-run-W6G6TYZ2.js +29 -0
  124. package/dist/bundle/first-screen-ITIAJIBU.js +37 -0
  125. package/dist/bundle/hast-util-from-html-ZHU6HGIE.js +10531 -0
  126. package/dist/bundle/hast-util-to-html-IIFHILP5.js +998 -0
  127. package/dist/bundle/hast-util-to-mdast-D62XX3NR.js +2272 -0
  128. package/dist/bundle/instructions-AG7SRWTR.js +11 -0
  129. package/dist/bundle/mcp-YGOAUNC3.js +167 -0
  130. package/dist/bundle/mdast-util-from-markdown-WVUJDSUO.js +1900 -0
  131. package/dist/bundle/mdast-util-gfm-KN2D32QS.js +1040 -0
  132. package/dist/bundle/mdast-util-to-hast-AYJV7KAE.js +879 -0
  133. package/dist/bundle/mdast-util-to-markdown-UCAJNHJO.js +18 -0
  134. package/dist/bundle/meeting-combined-CQJ3JHHU.js +24 -0
  135. package/dist/bundle/meeting-model-MZ7VVBNK.js +25 -0
  136. package/dist/bundle/meeting-semantic-DADWRRHP.js +22 -0
  137. package/dist/bundle/micromark-extension-gfm-EEJRRJ36.js +1771 -0
  138. package/dist/bundle/node-GJQYN4FT.js +176 -0
  139. package/dist/bundle/node-JJ3WDCNJ.js +2340 -0
  140. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  141. package/dist/bundle/node-sqlite-TPR62DT2.js +74 -0
  142. package/dist/bundle/oauth-WGY7JQVW.js +20 -0
  143. package/dist/bundle/open-DE7QZNAN.js +23 -0
  144. package/dist/bundle/openai-NHEFT3HS.js +238 -0
  145. package/dist/bundle/process-MEKCZMX3.js +91 -0
  146. package/dist/bundle/program-EP2S5BTM.js +38857 -0
  147. package/dist/bundle/prompt-PWY53BYH.js +17 -0
  148. package/dist/bundle/recognize-74TXHKMQ.js +26 -0
  149. package/dist/bundle/remote-F5TJZ5ER.js +31 -0
  150. package/dist/bundle/rerank-HWUO52UF.js +52 -0
  151. package/dist/bundle/schemas-4K6WWS5N.js +2157 -0
  152. package/dist/bundle/serve-I2USUY4X.js +199 -0
  153. package/dist/bundle/server-GDYDNO6K.js +79 -0
  154. package/dist/bundle/server-KYUW2AHB.js +212 -0
  155. package/dist/bundle/sqlite-runtime-N6VFGBJK.js +20 -0
  156. package/dist/bundle/state-L6JSCN77.js +36 -0
  157. package/dist/bundle/store-EPG2YPN3.js +291 -0
  158. package/dist/bundle/store-SQWQJE32.js +181 -0
  159. package/dist/bundle/store-maintenance-command-FTGSICVA.js +66 -0
  160. package/dist/bundle/surface-SNMHY6GP.js +65 -0
  161. package/dist/bundle/wordpress.js +183 -0
  162. package/dist/commands/api.d.ts +22 -0
  163. package/dist/commands/api.d.ts.map +1 -0
  164. package/dist/commands/api.js +37 -0
  165. package/dist/commands/api.js.map +1 -0
  166. package/dist/commands/content.d.ts +4 -0
  167. package/dist/commands/content.d.ts.map +1 -0
  168. package/dist/commands/content.js +94 -0
  169. package/dist/commands/content.js.map +1 -0
  170. package/dist/commands/session.d.ts +8 -0
  171. package/dist/commands/session.d.ts.map +1 -0
  172. package/dist/commands/session.js +28 -0
  173. package/dist/commands/session.js.map +1 -0
  174. package/dist/config.d.ts +13 -0
  175. package/dist/config.d.ts.map +1 -0
  176. package/dist/config.js +69 -0
  177. package/dist/config.js.map +1 -0
  178. package/dist/context.d.ts +37 -0
  179. package/dist/context.d.ts.map +1 -0
  180. package/dist/context.js +31 -0
  181. package/dist/context.js.map +1 -0
  182. package/dist/generated/definitions.d.ts +3 -0
  183. package/dist/generated/definitions.d.ts.map +1 -0
  184. package/dist/generated/definitions.js +7982 -0
  185. package/dist/generated/definitions.js.map +1 -0
  186. package/dist/generated/manifest.d.ts +6 -0
  187. package/dist/generated/manifest.d.ts.map +1 -0
  188. package/dist/generated/manifest.js +8830 -0
  189. package/dist/generated/manifest.js.map +1 -0
  190. package/dist/generated/schemas.d.ts +229 -0
  191. package/dist/generated/schemas.d.ts.map +1 -0
  192. package/dist/generated/schemas.js +2019 -0
  193. package/dist/generated/schemas.js.map +1 -0
  194. package/dist/generated/types.d.ts +3365 -0
  195. package/dist/generated/types.d.ts.map +1 -0
  196. package/dist/generated/types.js +5 -0
  197. package/dist/generated/types.js.map +1 -0
  198. package/dist/generated/wirecat-config.d.ts +11 -0
  199. package/dist/generated/wirecat-config.d.ts.map +1 -0
  200. package/dist/generated/wirecat-config.js +337 -0
  201. package/dist/generated/wirecat-config.js.map +1 -0
  202. package/dist/identity.d.ts +28 -0
  203. package/dist/identity.d.ts.map +1 -0
  204. package/dist/identity.js +29 -0
  205. package/dist/identity.js.map +1 -0
  206. package/dist/index.d.ts +3 -0
  207. package/dist/index.d.ts.map +1 -0
  208. package/dist/index.js +3 -0
  209. package/dist/index.js.map +1 -0
  210. package/dist/program.d.ts +6 -0
  211. package/dist/program.d.ts.map +1 -0
  212. package/dist/program.js +53 -0
  213. package/dist/program.js.map +1 -0
  214. package/dist/version.d.ts +2 -0
  215. package/dist/version.d.ts.map +1 -0
  216. package/dist/version.js +2 -0
  217. package/dist/version.js.map +1 -0
  218. package/dist/wcat.d.ts +3 -0
  219. package/dist/wcat.d.ts.map +1 -0
  220. package/dist/wcat.js +4 -0
  221. package/dist/wcat.js.map +1 -0
  222. package/package.json +87 -4
  223. package/skills/wordpress-cli/SKILL.md +88 -0
  224. package/skills/wordpress-cli/references/api/api-block-directory.md +17 -0
  225. package/skills/wordpress-cli/references/api/api-block-patterns.md +13 -0
  226. package/skills/wordpress-cli/references/api/api-block-types.md +34 -0
  227. package/skills/wordpress-cli/references/api/api-blocks.md +159 -0
  228. package/skills/wordpress-cli/references/api/api-categories.md +69 -0
  229. package/skills/wordpress-cli/references/api/api-comments.md +79 -0
  230. package/skills/wordpress-cli/references/api/api-font-collections.md +16 -0
  231. package/skills/wordpress-cli/references/api/api-font-families.md +122 -0
  232. package/skills/wordpress-cli/references/api/api-global-styles.md +29 -0
  233. package/skills/wordpress-cli/references/api/api-media.md +106 -0
  234. package/skills/wordpress-cli/references/api/api-menu-items.md +115 -0
  235. package/skills/wordpress-cli/references/api/api-menu-locations.md +22 -0
  236. package/skills/wordpress-cli/references/api/api-menus.md +69 -0
  237. package/skills/wordpress-cli/references/api/api-navigation.md +155 -0
  238. package/skills/wordpress-cli/references/api/api-pages.md +161 -0
  239. package/skills/wordpress-cli/references/api/api-pattern-directory.md +23 -0
  240. package/skills/wordpress-cli/references/api/api-plugins.md +25 -0
  241. package/skills/wordpress-cli/references/api/api-posts.md +166 -0
  242. package/skills/wordpress-cli/references/api/api-search.md +21 -0
  243. package/skills/wordpress-cli/references/api/api-settings.md +19 -0
  244. package/skills/wordpress-cli/references/api/api-sidebars.md +34 -0
  245. package/skills/wordpress-cli/references/api/api-statuses.md +22 -0
  246. package/skills/wordpress-cli/references/api/api-tags.md +69 -0
  247. package/skills/wordpress-cli/references/api/api-taxonomies.md +23 -0
  248. package/skills/wordpress-cli/references/api/api-template-parts.md +38 -0
  249. package/skills/wordpress-cli/references/api/api-templates.md +38 -0
  250. package/skills/wordpress-cli/references/api/api-themes.md +12 -0
  251. package/skills/wordpress-cli/references/api/api-types.md +22 -0
  252. package/skills/wordpress-cli/references/api/api-users.md +149 -0
  253. package/skills/wordpress-cli/references/api/api-widget-types.md +46 -0
  254. package/skills/wordpress-cli/references/api/api-widgets.md +57 -0
  255. package/skills/wordpress-cli/references/api/api-wp-pattern-category.md +69 -0
  256. package/skills/wordpress-cli/references/api.md +44 -0
@@ -0,0 +1,100 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ MAX_SECRET_INPUT,
5
+ bufferedInput,
6
+ inputPolicy
7
+ } from "./chunk-IJVTN5L3.js";
8
+ import {
9
+ CliError
10
+ } from "./chunk-HM6AMYHR.js";
11
+ import {
12
+ __name
13
+ } from "./chunk-ZVVMGPBJ.js";
14
+
15
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/terminal/prompt.js
16
+ import { createInterface } from "node:readline";
17
+ import { Writable } from "node:stream";
18
+ var EMPTY_TRIES = 3;
19
+ var pasteHint = /* @__PURE__ */ __name((platform = process.platform) => `Nothing arrived. To paste in a terminal, use ${platform === "darwin" ? "Cmd+V" : "Ctrl+Shift+V (or right-click \u2192 Paste)"}.`, "pasteHint");
20
+ var readSecret = /* @__PURE__ */ __name(async (prompt, { input = process.stdin, output = process.stderr, echo = false, signal: givenSignal } = {}) => {
21
+ const policy = inputPolicy(input);
22
+ const signals = [givenSignal, policy.signal].filter((one) => one !== void 0);
23
+ const signal = signals.length ? AbortSignal.any(signals) : void 0;
24
+ const cancelled = /* @__PURE__ */ __name(() => new CliError("cancelled", "cancelled \u2014 nothing was stored"), "cancelled");
25
+ if (signal?.aborted)
26
+ throw cancelled();
27
+ if (input.isTTY && policy.noInput)
28
+ throw new CliError("validation_error", "interactive input is disabled \u2014 provide the input through a pipe", {
29
+ reason: "input.required"
30
+ });
31
+ if (!input.isTTY) {
32
+ return (await bufferedInput(input, {
33
+ maxBytes: Math.min(policy.maxBytes ?? MAX_SECRET_INPUT, MAX_SECRET_INPUT),
34
+ ...signal ? { signal } : {}
35
+ })).toString("utf8").trim();
36
+ }
37
+ let muted = false;
38
+ const shim = new Writable({
39
+ write(chunk, _encoding, done) {
40
+ if (!muted)
41
+ output.write(chunk);
42
+ done();
43
+ }
44
+ });
45
+ const reader = createInterface({ input, output: shim, terminal: true });
46
+ const abort = /* @__PURE__ */ __name(() => reader.close(), "abort");
47
+ let bytes = 0;
48
+ let inputFailure;
49
+ const data = /* @__PURE__ */ __name((chunk) => {
50
+ bytes += Buffer.byteLength(chunk);
51
+ if (bytes > Math.min(policy.maxBytes ?? MAX_SECRET_INPUT, MAX_SECRET_INPUT)) {
52
+ inputFailure = new CliError("validation_error", "secret input exceeds its byte limit", {
53
+ reason: "input.too-large",
54
+ retryable: false
55
+ });
56
+ reader.close();
57
+ }
58
+ }, "data");
59
+ const inputError = /* @__PURE__ */ __name((error) => {
60
+ inputFailure = error;
61
+ reader.close();
62
+ }, "inputError");
63
+ input.on("data", data).on("error", inputError);
64
+ try {
65
+ const answer = await new Promise((resolve, reject) => {
66
+ const cancel = /* @__PURE__ */ __name(() => reject(inputFailure ?? cancelled()), "cancel");
67
+ reader.once("SIGINT", cancel);
68
+ reader.once("close", cancel);
69
+ signal?.addEventListener("abort", abort, { once: true });
70
+ const ask = /* @__PURE__ */ __name((tries) => {
71
+ muted = false;
72
+ reader.question(prompt, (line) => {
73
+ if (echo || line.trim() || tries >= EMPTY_TRIES)
74
+ return resolve(line);
75
+ output.write(`
76
+ ${pasteHint()}
77
+ `);
78
+ ask(tries + 1);
79
+ });
80
+ muted = !echo;
81
+ }, "ask");
82
+ ask(1);
83
+ });
84
+ if (!echo && !answer.trim())
85
+ throw new CliError("validation_error", `nothing arrived after ${EMPTY_TRIES} tries. ${pasteHint()}`, {
86
+ reason: "input.empty"
87
+ });
88
+ return answer.trim();
89
+ } finally {
90
+ input.off("data", data).off("error", inputError);
91
+ signal?.removeEventListener("abort", abort);
92
+ reader.close();
93
+ output.write("\n");
94
+ }
95
+ }, "readSecret");
96
+
97
+ export {
98
+ pasteHint,
99
+ readSecret
100
+ };
@@ -0,0 +1,338 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ throughWrapper
5
+ } from "./chunk-PPNTY7LD.js";
6
+ import {
7
+ environmentOf,
8
+ readOnlyLockOf
9
+ } from "./chunk-FQROWBKV.js";
10
+ import {
11
+ array,
12
+ boolean,
13
+ check,
14
+ pipe,
15
+ record,
16
+ safeParse,
17
+ strictObject,
18
+ string
19
+ } from "./chunk-S4UUN6LD.js";
20
+ import {
21
+ CliError
22
+ } from "./chunk-HM6AMYHR.js";
23
+ import {
24
+ __name
25
+ } from "./chunk-ZVVMGPBJ.js";
26
+
27
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/background/relay.js
28
+ import { createHash } from "node:crypto";
29
+ import { chmodSync, lstatSync, mkdirSync, rmSync } from "node:fs";
30
+ import { createConnection, createServer } from "node:net";
31
+ import { tmpdir } from "node:os";
32
+ import { dirname, isAbsolute, join } from "node:path";
33
+ import { PassThrough, Writable } from "node:stream";
34
+ var RELAY_PROTOCOL = 1;
35
+ var requestSchema = strictObject({
36
+ argv: array(string()),
37
+ env: record(string(), string()),
38
+ cwd: pipe(string(), check((path) => isAbsolute(path))),
39
+ tty: boolean(),
40
+ stdinTty: boolean()
41
+ });
42
+ var MAX_CLIENT_LINE = 1024 * 1024;
43
+ var MAX_SERVE_LINE = 64 * 1024 * 1024;
44
+ var MAX_SOCKET_PATH = 100;
45
+ var relayPath = /* @__PURE__ */ __name((lockPath) => {
46
+ const beside = lockPath.replace(/\.lock$/, ".sock");
47
+ if (beside.length <= MAX_SOCKET_PATH)
48
+ return beside;
49
+ const hash = createHash("sha256").update(beside).digest("hex").slice(0, 16);
50
+ const name = join(`wirecat-relay-${process.getuid?.() ?? "user"}`, `${hash}.sock`);
51
+ const temporary = join(tmpdir(), name);
52
+ if (temporary.length <= MAX_SOCKET_PATH || process.platform === "win32")
53
+ return temporary;
54
+ return join("/tmp", name);
55
+ }, "relayPath");
56
+ var privateDirectory = /* @__PURE__ */ __name((dir) => {
57
+ mkdirSync(dir, { recursive: true, mode: 448 });
58
+ const stat = lstatSync(dir);
59
+ const mine = process.getuid === void 0 || stat.uid === process.getuid();
60
+ if (!stat.isDirectory() || !mine || (stat.mode & 63) !== 0) {
61
+ throw new CliError("permission_error", `${dir} is not a private directory, so serve does not listen there`);
62
+ }
63
+ }, "privateDirectory");
64
+ var lines = /* @__PURE__ */ __name((socket, max, onLine, onTooLong) => {
65
+ let buffered = "";
66
+ socket.setEncoding("utf8");
67
+ socket.on("data", (chunk) => {
68
+ buffered += chunk;
69
+ for (let end = buffered.indexOf("\n"); end >= 0; end = buffered.indexOf("\n")) {
70
+ const line = buffered.slice(0, end);
71
+ buffered = buffered.slice(end + 1);
72
+ if (line)
73
+ onLine(line);
74
+ }
75
+ if (buffered.length > max)
76
+ onTooLong();
77
+ });
78
+ }, "lines");
79
+ var frame = /* @__PURE__ */ __name((socket, value) => {
80
+ if (!socket.destroyed)
81
+ socket.write(`${JSON.stringify(value)}
82
+ `);
83
+ }, "frame");
84
+ var listenRelay = /* @__PURE__ */ __name(async (path, run) => {
85
+ privateDirectory(dirname(path));
86
+ rmSync(path, { force: true });
87
+ const open = /* @__PURE__ */ new Set();
88
+ const running = /* @__PURE__ */ new Set();
89
+ const server = createServer((socket) => {
90
+ open.add(socket);
91
+ const stop = new AbortController();
92
+ const stdin = new PassThrough();
93
+ let started = false;
94
+ socket.on("error", () => {
95
+ });
96
+ socket.on("close", () => {
97
+ open.delete(socket);
98
+ stop.abort(new CliError("cancelled", "the client went away", { retryable: false }));
99
+ if (!stdin.writableEnded)
100
+ stdin.end();
101
+ });
102
+ lines(socket, MAX_CLIENT_LINE, (line) => {
103
+ let message;
104
+ try {
105
+ message = JSON.parse(line);
106
+ } catch {
107
+ socket.destroy();
108
+ return;
109
+ }
110
+ if (!started) {
111
+ started = true;
112
+ if (message.v !== RELAY_PROTOCOL) {
113
+ frame(socket, { diagnostic: `serve speaks relay protocol ${RELAY_PROTOCOL}; restart it`, exit: 1 });
114
+ socket.end();
115
+ return;
116
+ }
117
+ const parsed = safeParse(requestSchema, message.run);
118
+ if (!parsed.success) {
119
+ socket.destroy();
120
+ return;
121
+ }
122
+ stdin.isTTY = parsed.output.stdinTty;
123
+ if (parsed.output.stdinTty)
124
+ stdin.end();
125
+ const job = serve(socket, parsed.output, stdin, stop.signal, run);
126
+ running.add(job);
127
+ void job.then(() => running.delete(job), () => running.delete(job));
128
+ return;
129
+ }
130
+ if (typeof message.stdin === "string" && !stdin.writableEnded)
131
+ stdin.write(Buffer.from(message.stdin, "base64"));
132
+ if (message.stdinEnd === true && !stdin.writableEnded)
133
+ stdin.end();
134
+ }, () => socket.destroy());
135
+ });
136
+ await new Promise((resolve, reject) => {
137
+ server.once("error", reject);
138
+ server.listen(path, () => {
139
+ server.off("error", reject);
140
+ resolve();
141
+ });
142
+ });
143
+ chmodSync(path, 384);
144
+ return {
145
+ close: /* @__PURE__ */ __name(async () => {
146
+ for (const socket of open)
147
+ socket.destroy();
148
+ await new Promise((resolve) => server.close(() => resolve()));
149
+ await Promise.allSettled(running);
150
+ rmSync(path, { force: true });
151
+ }, "close")
152
+ };
153
+ }, "listenRelay");
154
+ var serve = /* @__PURE__ */ __name(async (socket, request, stdin, signal, run) => {
155
+ const streams = {
156
+ data: /* @__PURE__ */ __name((text) => frame(socket, { data: text }), "data"),
157
+ diagnostic: /* @__PURE__ */ __name((text) => frame(socket, { diagnostic: text }), "diagnostic"),
158
+ progress: /* @__PURE__ */ __name((text) => frame(socket, { progress: text }), "progress")
159
+ };
160
+ const stdout = new Writable({
161
+ write: /* @__PURE__ */ __name((chunk, _encoding, done) => {
162
+ frame(socket, { raw: Buffer.from(chunk).toString("base64") });
163
+ done();
164
+ }, "write")
165
+ });
166
+ let code = 1;
167
+ try {
168
+ code = await run(request, { streams, stdin, stdout, signal });
169
+ } finally {
170
+ frame(socket, { exit: code });
171
+ socket.end();
172
+ }
173
+ }, "serve");
174
+ var relayCommand = /* @__PURE__ */ __name((path, request, options) => new Promise((resolve, reject) => {
175
+ const { streams, stdin, stdout, signal, deadlineMs, writes, holder, listens = false } = options;
176
+ const socket = createConnection(path);
177
+ let connected = false;
178
+ let settled = false;
179
+ let timer;
180
+ const forward = /* @__PURE__ */ __name((chunk) => frame(socket, { stdin: Buffer.from(chunk).toString("base64") }), "forward");
181
+ const ended = /* @__PURE__ */ __name(() => frame(socket, { stdinEnd: true }), "ended");
182
+ const brokenPipe = /* @__PURE__ */ __name((error) => {
183
+ if (error.code === "EPIPE")
184
+ finish({ code: 0 });
185
+ }, "brokenPipe");
186
+ const finish = /* @__PURE__ */ __name((outcome) => {
187
+ if (settled)
188
+ return;
189
+ settled = true;
190
+ if (timer)
191
+ clearTimeout(timer);
192
+ stdout.off("error", brokenPipe);
193
+ signal.removeEventListener("abort", aborted);
194
+ stdin.off("data", forward).off("end", ended);
195
+ stdin.pause();
196
+ socket.destroy();
197
+ if ("code" in outcome)
198
+ resolve(outcome.code);
199
+ else
200
+ reject(outcome.error);
201
+ }, "finish");
202
+ const stopped = /* @__PURE__ */ __name(() => writes ? new CliError("outcome_unknown", `${holder} stopped before the command finished; it may have run \u2014 check before repeating it`, { retryable: false }) : new CliError("provider_unavailable", `${holder} stopped before the command finished`, { retryable: true }), "stopped");
203
+ const aborted = /* @__PURE__ */ __name(() => finish(listens ? { code: 0 } : { error: signal.reason }), "aborted");
204
+ if (signal.aborted)
205
+ return aborted();
206
+ signal.addEventListener("abort", aborted, { once: true });
207
+ stdout.on("error", brokenPipe);
208
+ if (deadlineMs !== void 0)
209
+ timer = setTimeout(() => finish({ error: stopped() }), deadlineMs);
210
+ socket.on("connect", () => {
211
+ connected = true;
212
+ frame(socket, { v: RELAY_PROTOCOL, run: request });
213
+ if (request.stdinTty)
214
+ ended();
215
+ else {
216
+ stdin.on("data", forward).once("end", ended);
217
+ stdin.resume();
218
+ }
219
+ });
220
+ socket.on("error", (error) => {
221
+ if (connected)
222
+ return finish({ error: stopped() });
223
+ finish({
224
+ error: new CliError("provider_unavailable", `${holder} holds the connection but does not answer its relay (${error.code ?? error.message}) \u2014 restart it`, { retryable: false, sent: false })
225
+ });
226
+ });
227
+ socket.on("close", () => finish({ error: stopped() }));
228
+ lines(socket, MAX_SERVE_LINE, (line) => {
229
+ let message;
230
+ try {
231
+ message = JSON.parse(line);
232
+ } catch {
233
+ return finish({ error: stopped() });
234
+ }
235
+ if (typeof message.data === "string")
236
+ streams.data(message.data);
237
+ if (typeof message.diagnostic === "string")
238
+ streams.diagnostic(message.diagnostic);
239
+ if (typeof message.progress === "string")
240
+ streams.progress?.(message.progress);
241
+ if (typeof message.raw === "string")
242
+ stdout.write(Buffer.from(message.raw, "base64"));
243
+ if (typeof message.exit === "number")
244
+ finish({ code: message.exit });
245
+ }, () => finish({ error: stopped() }));
246
+ }), "relayCommand");
247
+
248
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-relay.js
249
+ var lentConnection = /* @__PURE__ */ __name((connection, watchers) => throughWrapper(connection, {
250
+ close: /* @__PURE__ */ __name(async () => {
251
+ }, "close"),
252
+ feed: void 0,
253
+ storedChats: void 0,
254
+ listen: void 0,
255
+ listenHistory: void 0,
256
+ ...connection.watch && watchers ? {
257
+ // A watcher that throws (its output limit, a closed reader) ends its own watch, never serve's.
258
+ watch: /* @__PURE__ */ __name(async (onEvent, signal, onReady) => {
259
+ let watcher;
260
+ try {
261
+ await new Promise((resolve, reject) => {
262
+ watcher = /* @__PURE__ */ __name((event) => {
263
+ try {
264
+ onEvent(event);
265
+ } catch (error) {
266
+ reject(error);
267
+ }
268
+ }, "watcher");
269
+ watchers.add(watcher);
270
+ signal.addEventListener("abort", () => resolve(), { once: true });
271
+ onReady?.();
272
+ if (signal.aborted)
273
+ resolve();
274
+ });
275
+ } finally {
276
+ if (watcher)
277
+ watchers.delete(watcher);
278
+ }
279
+ }, "watch")
280
+ } : { watch: void 0 }
281
+ }), "lentConnection");
282
+ var serveRelay = /* @__PURE__ */ __name((command, messenger) => {
283
+ let held;
284
+ let relay;
285
+ const watchers = /* @__PURE__ */ new Set();
286
+ const borrowed = /* @__PURE__ */ __name(() => {
287
+ const connection = held;
288
+ if (!connection)
289
+ throw new CliError("provider_unavailable", "serve is not connected yet", { retryable: true });
290
+ return lentConnection(connection, watchers);
291
+ }, "borrowed");
292
+ return {
293
+ messenger: {
294
+ ...messenger,
295
+ connect: /* @__PURE__ */ __name(async (...args) => {
296
+ held = await messenger.connect(...args);
297
+ return held;
298
+ }, "connect")
299
+ },
300
+ arrived: /* @__PURE__ */ __name((event) => {
301
+ for (const watcher of watchers)
302
+ watcher(event);
303
+ }, "arrived"),
304
+ /** Listens beside the lock; the address goes into it, which is how a client finds it. */
305
+ open: /* @__PURE__ */ __name(async (lockPath, profile) => {
306
+ const environment = environmentOf(command);
307
+ const runCommand = environment.runCommand;
308
+ if (!runCommand)
309
+ return void 0;
310
+ const readOnly = readOnlyLockOf(messenger.app, environment.env ?? process.env);
311
+ const path = relayPath(lockPath);
312
+ relay = await listenRelay(path, (request, io) => runCommand(request.argv, {
313
+ env: {
314
+ ...request.env,
315
+ ...readOnly ? { [`${messenger.app.envPrefix}_READ_ONLY`]: "1" } : {}
316
+ },
317
+ streams: io.streams,
318
+ stdin: io.stdin,
319
+ stdout: io.stdout,
320
+ tty: request.tty,
321
+ signal: io.signal,
322
+ answer: /* @__PURE__ */ __name(() => null, "answer"),
323
+ relayed: { profile, cwd: request.cwd, connection: borrowed }
324
+ }));
325
+ return { path, protocol: RELAY_PROTOCOL };
326
+ }, "open"),
327
+ close: /* @__PURE__ */ __name(async () => {
328
+ await relay?.close();
329
+ }, "close")
330
+ };
331
+ }, "serveRelay");
332
+
333
+ export {
334
+ RELAY_PROTOCOL,
335
+ relayCommand,
336
+ lentConnection,
337
+ serveRelay
338
+ };
@@ -0,0 +1,15 @@
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/micromark-util-normalize-identifier@2.0.1/node_modules/micromark-util-normalize-identifier/index.js
8
+ function normalizeIdentifier(value) {
9
+ return value.replace(/[\t\n\r ]+/g, " ").replace(/^ | $/g, "").toLowerCase().toUpperCase();
10
+ }
11
+ __name(normalizeIdentifier, "normalizeIdentifier");
12
+
13
+ export {
14
+ normalizeIdentifier
15
+ };