very-happy-cli 0.2.159 → 0.2.161

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 (259) hide show
  1. package/dist/{AcpBackend-VsfkZiVF.mjs → AcpBackend-6U6pQgx1.mjs} +4 -2
  2. package/dist/{AcpBackend-DUYFlyfN.cjs → AcpBackend-Ba98QDif.cjs} +78 -76
  3. package/dist/{AcpSessionManager-Bdv8LWXh.cjs → AcpSessionManager-BAY1Pggx.cjs} +9 -9
  4. package/dist/{AcpSessionManager-rYtVb0kN.mjs → AcpSessionManager-CoMWFVw3.mjs} +1 -1
  5. package/dist/BasePermissionHandler-2R0uH2CI.cjs +157 -0
  6. package/dist/BasePermissionHandler-BvvhBTja.mjs +155 -0
  7. package/dist/BaseReasoningProcessor-DyhO1uoU.mjs +198 -0
  8. package/dist/BaseReasoningProcessor-fsVNmCEF.cjs +200 -0
  9. package/dist/RemoteModeDisplay-D-HewyXg.mjs +150 -0
  10. package/dist/RemoteModeDisplay-NC1gPHtj.cjs +153 -0
  11. package/dist/agentAttachments-Dbw8iMCZ.cjs +20 -0
  12. package/dist/agentAttachments-M_B5qEF2.mjs +18 -0
  13. package/dist/agentGuidance-B5NATuFa.cjs +28 -0
  14. package/dist/agentGuidance-CQuNlNx8.mjs +20 -0
  15. package/dist/{agentHome-CvsJyeQB.mjs → agentHome-Ck1i1TQB.mjs} +8 -22
  16. package/dist/{agentHome-CHh4lmjM.cjs → agentHome-DvNnGphb.cjs} +14 -28
  17. package/dist/api-B2vLMS-z.cjs +3346 -0
  18. package/dist/api-SffjRQ1b.mjs +3339 -0
  19. package/dist/{types-Dh-s4Lqs.mjs → apiMachine-BpW9t8MO.mjs} +9116 -16205
  20. package/dist/{types-BbvK1Tr_.cjs → apiMachine-gFA54X7y.cjs} +9104 -16247
  21. package/dist/assistantTools-BfA0R3_m.cjs +380 -0
  22. package/dist/assistantTools-CgiTbnWb.mjs +376 -0
  23. package/dist/attachmentContent-CSGxr71v.mjs +82 -0
  24. package/dist/attachmentContent-DMMZzevR.cjs +88 -0
  25. package/dist/attachmentLimits-CzVrqgLR.cjs +354 -0
  26. package/dist/attachmentLimits-yba1uHFO.mjs +348 -0
  27. package/dist/auth-Bt4ceBBy.cjs +227 -0
  28. package/dist/auth-CYHjQ8oQ.mjs +225 -0
  29. package/dist/auth-DdyVZSo6.mjs +218 -0
  30. package/dist/auth-x4CEoysH.cjs +220 -0
  31. package/dist/authRelay-BdYkC1Po.cjs +156 -0
  32. package/dist/authRelay-DSAvg1uv.mjs +143 -0
  33. package/dist/{auto-DKmEls8Z.cjs → auto-BDXDUnjB.cjs} +70 -79
  34. package/dist/{auto-nb8GhRRy.mjs → auto-CXLlRi3a.mjs} +27 -36
  35. package/dist/backgroundTaskActivity-8PdPxrvy.mjs +149 -0
  36. package/dist/backgroundTaskActivity-CBvUdj39.cjs +157 -0
  37. package/dist/bootstrap-BNQq05jR.mjs +112 -0
  38. package/dist/bootstrap-CkgIq8N3.cjs +116 -0
  39. package/dist/browser-9pyhQr1R.mjs +20 -0
  40. package/dist/browser-BDOlKWYe.cjs +22 -0
  41. package/dist/claudeCliPath-BqkaH2oR.mjs +8 -0
  42. package/dist/claudeCliPath-U4HHmV4r.cjs +10 -0
  43. package/dist/claudeLocal-BDuGFnjJ.cjs +343 -0
  44. package/dist/claudeLocal-CQa8qnwq.mjs +339 -0
  45. package/dist/claudeLocalLauncher-Bd5I2-j6.cjs +154 -0
  46. package/dist/claudeLocalLauncher-CDqQI9ak.mjs +152 -0
  47. package/dist/cliUpdate-DsKXPFYp.cjs +120 -0
  48. package/dist/cliUpdate-Y34VGe9Y.mjs +112 -0
  49. package/dist/client-Brn-UwVk.mjs +100 -0
  50. package/dist/client-CXb1VJui.mjs +112 -0
  51. package/dist/client-C_axwRry.cjs +104 -0
  52. package/dist/client-DOBWJL3u.cjs +119 -0
  53. package/dist/codex/happyMcpStdioBridge.cjs +33 -14
  54. package/dist/codex/happyMcpStdioBridge.mjs +26 -7
  55. package/dist/codexAppServerClient-ZzhUTWPo.cjs +1090 -0
  56. package/dist/codexAppServerClient-oeQKD6Qf.mjs +1088 -0
  57. package/dist/codexCommand-C7H0NpBe.cjs +2088 -0
  58. package/dist/codexCommand-CJ82bl3l.mjs +2086 -0
  59. package/dist/codexThreadFork-BCaEMBiM.mjs +338 -0
  60. package/dist/codexThreadFork-BZqF-9bX.cjs +350 -0
  61. package/dist/{config-ClLtM6F3.mjs → config-BglnktIo.mjs} +7 -40
  62. package/dist/{config-DLx-vW3I.cjs → config-CYpL1Ahd.cjs} +26 -59
  63. package/dist/configuration-DoWFJUPm.mjs +170 -0
  64. package/dist/configuration-v9f8LM9T.cjs +181 -0
  65. package/dist/connect-hgcNjyAB.mjs +682 -0
  66. package/dist/connect-yEvjdRvx.cjs +684 -0
  67. package/dist/constants-BC4St0xd.mjs +11 -0
  68. package/dist/constants-VJ0N6WuG.cjs +17 -0
  69. package/dist/contentLogMetadata-BlWI0egu.mjs +51 -0
  70. package/dist/contentLogMetadata-ZSFk_NjQ.cjs +54 -0
  71. package/dist/context-B45vMtSZ.cjs +69 -0
  72. package/dist/context-C9GHPLEm.mjs +65 -0
  73. package/dist/controlClient-DjoKTtgK.mjs +260 -0
  74. package/dist/controlClient-fEHE85bH.cjs +279 -0
  75. package/dist/createSessionMetadata-BRLB9CNO.cjs +58 -0
  76. package/dist/createSessionMetadata-mIeehclp.mjs +54 -0
  77. package/dist/defaultPermissionMode-BnxJPVHT.mjs +4 -0
  78. package/dist/defaultPermissionMode-CxmTXUQR.cjs +7 -0
  79. package/dist/detectCLI-CSGMlV51.mjs +58 -0
  80. package/dist/detectCLI-DR9ZaN6B.cjs +61 -0
  81. package/dist/deterministicJson-DKDP_mM-.cjs +507 -0
  82. package/dist/deterministicJson-p835AdAU.mjs +502 -0
  83. package/dist/doctor-BPkYWSuq.mjs +75 -0
  84. package/dist/doctor-BeUuQXFs.mjs +391 -0
  85. package/dist/doctor-hVNnSZJn.cjs +395 -0
  86. package/dist/doctor-u46qYYKX.cjs +79 -0
  87. package/dist/doctorReadiness-BCZGcN0a.cjs +151 -0
  88. package/dist/doctorReadiness-C208SMN9.mjs +142 -0
  89. package/dist/editPaths-BVfS_FFL.mjs +68 -0
  90. package/dist/editPaths-Bqp4OFPw.cjs +73 -0
  91. package/dist/ensureDaemonRunning-CO7d1gOC.mjs +61 -0
  92. package/dist/ensureDaemonRunning-Dg9aZfjs.cjs +64 -0
  93. package/dist/handleResumeCommand-BiTPK0qd.mjs +240 -0
  94. package/dist/handleResumeCommand-DnVmy7a3.cjs +245 -0
  95. package/dist/ids-B6ZC0HGt.cjs +13 -0
  96. package/dist/ids-DU6sLx4C.mjs +10 -0
  97. package/dist/index-B6UGRQ7h.mjs +102 -0
  98. package/dist/{index-2mCaeKyf.mjs → index-CAFwetLk.mjs} +68 -38
  99. package/dist/index-Cqx-Raq6.mjs +68 -0
  100. package/dist/index-D3kI0hDR.cjs +107 -0
  101. package/dist/index-DA7yINuk.cjs +994 -0
  102. package/dist/{index-BEOMECtE.cjs → index-LIn6nCcq.cjs} +121 -91
  103. package/dist/index-Pf2cV9cn.cjs +182 -0
  104. package/dist/index-SPGPenK5.mjs +158 -0
  105. package/dist/index-gNTWtSKN.cjs +71 -0
  106. package/dist/index-qdS1friN.mjs +949 -0
  107. package/dist/index.cjs +5 -46
  108. package/dist/index.mjs +5 -46
  109. package/dist/{install-BPhJppvd.mjs → install-BO_W7VhL.mjs} +37 -37
  110. package/dist/install-Bu85vlHD.cjs +88 -0
  111. package/dist/install-ClUUl3yp.mjs +86 -0
  112. package/dist/{install-BOHrUaFM.cjs → install-Cs5qAPrB.cjs} +38 -38
  113. package/dist/{installPiTools-DuZ6jZvX.cjs → installPiTools-BKnXjrVu.cjs} +2 -3
  114. package/dist/{installPiTools-Cj7yU9Fc.mjs → installPiTools-B_CdM5_2.mjs} +1 -2
  115. package/dist/{installTerminalHooks-Cou3WUf3.cjs → installTerminalHooks-BQZbvxsZ.cjs} +5 -40
  116. package/dist/{installTerminalHooks-WeznjkuC.mjs → installTerminalHooks-By7gBMEF.mjs} +3 -38
  117. package/dist/lib.cjs +28 -19
  118. package/dist/lib.d.cts +12 -2
  119. package/dist/lib.d.mts +12 -2
  120. package/dist/lib.mjs +23 -14
  121. package/dist/lidState-C2dI0FAN.mjs +297 -0
  122. package/dist/lidState-KHHu1015.cjs +305 -0
  123. package/dist/limits-C-a7gr04.cjs +43 -0
  124. package/dist/limits-DIo7rEBR.mjs +36 -0
  125. package/dist/localHappyAgentAuth-BXiHPXdC.cjs +86 -0
  126. package/dist/localHappyAgentAuth-DCsetiyG.mjs +82 -0
  127. package/dist/logger-Bc8-u1w0.cjs +275 -0
  128. package/dist/logger-fXoNzNuB.mjs +271 -0
  129. package/dist/loginShellEnv-BkuYtExZ.cjs +182 -0
  130. package/dist/loginShellEnv-Dw8M7tkI.mjs +167 -0
  131. package/dist/machineMetadata-BHjehxJY.mjs +38 -0
  132. package/dist/machineMetadata-BibDMFVx.cjs +41 -0
  133. package/dist/main-BktM4A1K.mjs +939 -0
  134. package/dist/main-CLaX-t-b.cjs +941 -0
  135. package/dist/manager-BQ4flvQZ.mjs +101 -0
  136. package/dist/manager-Cly8xVIR.cjs +105 -0
  137. package/dist/{mcp-Dy3f_K0h.mjs → mcp-CeUd9KDr.mjs} +27 -33
  138. package/dist/{mcp-CPYbtsYG.cjs → mcp-GBfE70nk.cjs} +42 -48
  139. package/dist/messageBuffer-BWlGgR3A.mjs +71 -0
  140. package/dist/messageBuffer-fJMH6uY8.cjs +73 -0
  141. package/dist/mirrorProtocol-BNLtoWjO.mjs +170 -0
  142. package/dist/mirrorProtocol-BUtmg1ws.cjs +186 -0
  143. package/dist/oneShotPrompts-CL0dip9C.cjs +16 -0
  144. package/dist/oneShotPrompts-DT4p6RNd.mjs +12 -0
  145. package/dist/package-Cl5BEP5x.cjs +173 -0
  146. package/dist/package-uOg9SCKi.mjs +171 -0
  147. package/dist/path-B7zW-WwE.cjs +18 -0
  148. package/dist/path-D2wdaNSk.mjs +15 -0
  149. package/dist/peerTools-CIeiy9wn.cjs +283 -0
  150. package/dist/peerTools-Dz3_7Bkk.mjs +272 -0
  151. package/dist/permissionMode-CH4FoZfU.mjs +80 -0
  152. package/dist/permissionMode-CrV-XuMs.cjs +87 -0
  153. package/dist/persistence-CBNMzSa8.cjs +414 -0
  154. package/dist/persistence-oET5n61f.mjs +372 -0
  155. package/dist/piExtension.mjs +2 -1
  156. package/dist/piRunnerArgs-Bf7RUF__.cjs +66 -0
  157. package/dist/piRunnerArgs-Dk1ncwHF.mjs +59 -0
  158. package/dist/{piRuntime-NtF0YqjH.cjs → piRuntime-B_6TE9Eb.cjs} +4 -4
  159. package/dist/{piRuntime-kLZNpAAl.mjs → piRuntime-BwRdhK_N.mjs} +2 -2
  160. package/dist/{piTerminal-B0fEOV_2.mjs → piTerminal-Bap3R8Re.mjs} +32 -35
  161. package/dist/{piTerminal-9J0GAKzb.cjs → piTerminal-CagmEoez.cjs} +32 -35
  162. package/dist/previewPath-B0rBdhy1.cjs +83 -0
  163. package/dist/previewPath-CXN4Vag0.mjs +81 -0
  164. package/dist/projectPath-BTBIMB57.mjs +10 -0
  165. package/dist/projectPath-ChLhdOyt.cjs +13 -0
  166. package/dist/registerCommonHandlers-BjSV2Skz.cjs +538 -0
  167. package/dist/registerCommonHandlers-CrgvJsOy.mjs +536 -0
  168. package/dist/registerKillSessionHandler-6TC2S3lf.cjs +366 -0
  169. package/dist/registerKillSessionHandler-Cbc8Rgtd.mjs +363 -0
  170. package/dist/remoteSessionClient-BNx78NLb.cjs +634 -0
  171. package/dist/remoteSessionClient-CO7qOjR0.mjs +612 -0
  172. package/dist/resources-BdFBQi8r.mjs +117 -0
  173. package/dist/resources-JDPugcDq.cjs +120 -0
  174. package/dist/run-2l5vSt2h.mjs +5743 -0
  175. package/dist/run-D5xAEWSB.cjs +5766 -0
  176. package/dist/runClaude-BX6ixjtW.cjs +894 -0
  177. package/dist/runClaude-BgN6xo05.mjs +892 -0
  178. package/dist/runClaudeDeps-Bp20MScE.cjs +4168 -0
  179. package/dist/runClaudeDeps-COBBhD9o.mjs +4129 -0
  180. package/dist/{runGemini-F-mqx3_K.cjs → runGemini-CSMPkt0p.cjs} +202 -175
  181. package/dist/{runGemini-DV6Ouadt.mjs → runGemini-Cc2jq-uh.mjs} +58 -31
  182. package/dist/{runOpenClaw-D7MlPS5n.mjs → runOpenClaw-CIlCwdW2.mjs} +31 -32
  183. package/dist/{runOpenClaw-Qqo9j63M.cjs → runOpenClaw-YBwua4Rf.cjs} +64 -65
  184. package/dist/sandbox-C4gXLP1p.cjs +187 -0
  185. package/dist/sandbox-CNkwOtHI.mjs +180 -0
  186. package/dist/selfCheck-CU8xSDsl.cjs +87 -0
  187. package/dist/selfCheck-hJ6PCh7v.mjs +84 -0
  188. package/dist/{send-CLhYXNgy.mjs → send-CGHcKZ-w.mjs} +12 -5
  189. package/dist/{send-4qJTCAYW.cjs → send-DY9Nr-x4.cjs} +16 -9
  190. package/dist/server-II51Mimf.cjs +407 -0
  191. package/dist/server-m2b5pamZ.mjs +404 -0
  192. package/dist/sessionLock-7ePAYDOg.cjs +205 -0
  193. package/dist/sessionLock-Cw6FmbMv.mjs +197 -0
  194. package/dist/sessionModeFile-BVCV5f7E.cjs +36 -0
  195. package/dist/sessionModeFile-CDmDyRkD.mjs +32 -0
  196. package/dist/sessionOps-C_f1wKOr.mjs +760 -0
  197. package/dist/sessionOps-DJdExmBy.cjs +783 -0
  198. package/dist/sessionScanner-CaAHLyNV.mjs +206 -0
  199. package/dist/sessionScanner-D1goKdd3.cjs +209 -0
  200. package/dist/{sessions-Bh1pyddi.cjs → sessions-DGs6ALNo.cjs} +37 -28
  201. package/dist/{sessions-CzIH2rGp.mjs → sessions-DnvmWUel.mjs} +17 -8
  202. package/dist/setupOfflineReconnection-CVViqZft.mjs +72 -0
  203. package/dist/setupOfflineReconnection-R7XuR_sj.cjs +74 -0
  204. package/dist/smallFastModel-BLNgMrwR.mjs +18 -0
  205. package/dist/smallFastModel-D_uxGMo3.cjs +21 -0
  206. package/dist/{spawn-CmFOSVdW.cjs → spawn-CXTH7qg1.cjs} +61 -65
  207. package/dist/{spawn-CPIWlPOM.mjs → spawn-DNYSvFtC.mjs} +35 -40
  208. package/dist/spawnAgents-BGQiEF-w.cjs +52 -0
  209. package/dist/spawnAgents-DZzZ9jMI.mjs +45 -0
  210. package/dist/spawnHappyCLI-BhYj84rv.cjs +66 -0
  211. package/dist/spawnHappyCLI-cqWQbwsb.mjs +64 -0
  212. package/dist/specialCommands-BSqhYg5X.mjs +52 -0
  213. package/dist/specialCommands-DSsTeRej.cjs +54 -0
  214. package/dist/startFileWatcher-CKKx-8ZO.cjs +71 -0
  215. package/dist/startFileWatcher-CdegMbJj.mjs +69 -0
  216. package/dist/startupPlan-BLMbfQIH.cjs +12 -0
  217. package/dist/startupPlan-DFMyNgAs.mjs +10 -0
  218. package/dist/streamRelay-BiKw59Cc.cjs +233 -0
  219. package/dist/streamRelay-FPVbHpbM.mjs +231 -0
  220. package/dist/sync-CVk4QERO.cjs +71 -0
  221. package/dist/sync-CxD-w_40.mjs +69 -0
  222. package/dist/systemPrompt-BygJcmbi.cjs +97 -0
  223. package/dist/systemPrompt-DmtypUc7.mjs +94 -0
  224. package/dist/{teams-CEahj4cm.mjs → teams-BOC6nIPL.mjs} +9 -40
  225. package/dist/{teams-CB1R9-Z9.cjs → teams-BsvpOBfn.cjs} +14 -45
  226. package/dist/template-BaHAmH2K.cjs +129 -0
  227. package/dist/template-CiOPa2rd.mjs +121 -0
  228. package/dist/{terminalTitleSuggest-DKgX3osW.mjs → terminalTitleSuggest-CeKsX_V6.mjs} +1 -9
  229. package/dist/{terminalTitleSuggest-Dji8I0Jy.cjs → terminalTitleSuggest-DhvRFX3H.cjs} +0 -10
  230. package/dist/terminals-B_bfC9c2.cjs +250 -0
  231. package/dist/terminals-Dlg0x3nY.mjs +235 -0
  232. package/dist/time-BZNdNiIV.mjs +38 -0
  233. package/dist/time-CNRE4ChD.cjs +42 -0
  234. package/dist/titleGenerator-CFRhU-xq.cjs +172 -0
  235. package/dist/titleGenerator-ox6ptCsp.mjs +166 -0
  236. package/dist/tmuxSocket-B8Yx20sT.mjs +19 -0
  237. package/dist/tmuxSocket-D-Xt6Vn-.cjs +24 -0
  238. package/dist/{todo-DqyRI4wP.cjs → todo-B-KB7oAB.cjs} +15 -12
  239. package/dist/{todo-Cknp5D4U.mjs → todo-C5KBVbUw.mjs} +11 -8
  240. package/dist/tools-BZabNIid.mjs +177 -0
  241. package/dist/tools-BmQQUATY.mjs +60 -0
  242. package/dist/tools-CsSovyNp.cjs +180 -0
  243. package/dist/tools-lMDra4Pv.cjs +63 -0
  244. package/dist/trimIdent-4gvk9Wk6.cjs +22 -0
  245. package/dist/trimIdent-BAjmv_TG.mjs +20 -0
  246. package/dist/types-CRS-srZK.cjs +66 -0
  247. package/dist/types-CkqAACXx.mjs +64 -0
  248. package/dist/uninstall-B1WLtC1d.mjs +47 -0
  249. package/dist/uninstall-fvA5aWpU.cjs +49 -0
  250. package/package.json +7 -7
  251. package/scripts/session_hook_forwarder.cjs +9 -2
  252. package/dist/agentGuidance-BRDN1NoZ.cjs +0 -2217
  253. package/dist/agentGuidance-KgvYuF3R.mjs +0 -2145
  254. package/dist/index-BF6WfgV5.mjs +0 -19624
  255. package/dist/index-C-JazrMB.mjs +0 -52
  256. package/dist/index-blDSadUR.cjs +0 -58
  257. package/dist/index-rH3DrQ5B.cjs +0 -19688
  258. package/dist/limits-BH5CV5vR.cjs +0 -2683
  259. package/dist/limits-CjRj8IX5.mjs +0 -2558
@@ -0,0 +1,536 @@
1
+ import { l as logger } from './logger-fXoNzNuB.mjs';
2
+ import { spawn as spawn$1, exec } from 'child_process';
3
+ import { promisify } from 'util';
4
+ import { mkdir, writeFile, appendFile, stat, rename, unlink, readdir, readFile } from 'fs/promises';
5
+ import { randomUUID, createHash } from 'crypto';
6
+ import { resolve, join, sep } from 'path';
7
+ import { spawn } from 'cross-spawn';
8
+ import { p as projectPath } from './projectPath-BTBIMB57.mjs';
9
+ import { platform } from 'os';
10
+ import { c as configuration } from './configuration-DoWFJUPm.mjs';
11
+
12
+ function run$1(args, options) {
13
+ const RUNNER_PATH = resolve(join(projectPath(), "scripts", "ripgrep_launcher.cjs"));
14
+ return new Promise((resolve2, reject) => {
15
+ const child = spawn("node", [RUNNER_PATH, JSON.stringify(args)], {
16
+ stdio: ["pipe", "pipe", "pipe"],
17
+ cwd: options?.cwd,
18
+ windowsHide: true
19
+ });
20
+ let stdout = "";
21
+ let stderr = "";
22
+ child.stdout.on("data", (data) => {
23
+ stdout += data.toString();
24
+ });
25
+ child.stderr.on("data", (data) => {
26
+ stderr += data.toString();
27
+ });
28
+ child.on("close", (code) => {
29
+ resolve2({
30
+ exitCode: code || 0,
31
+ stdout,
32
+ stderr
33
+ });
34
+ });
35
+ child.on("error", (err) => {
36
+ reject(err);
37
+ });
38
+ });
39
+ }
40
+
41
+ function getBinaryPath() {
42
+ const platformName = platform();
43
+ const binaryName = platformName === "win32" ? "difft.exe" : "difft";
44
+ return resolve(join(projectPath(), "tools", "unpacked", binaryName));
45
+ }
46
+ function run(args, options) {
47
+ const binaryPath = getBinaryPath();
48
+ return new Promise((resolve2, reject) => {
49
+ const child = spawn$1(binaryPath, args, {
50
+ stdio: ["pipe", "pipe", "pipe"],
51
+ cwd: options?.cwd,
52
+ windowsHide: true,
53
+ env: {
54
+ ...process.env,
55
+ // Force color output when needed
56
+ FORCE_COLOR: "1"
57
+ }
58
+ });
59
+ let stdout = "";
60
+ let stderr = "";
61
+ child.stdout.on("data", (data) => {
62
+ stdout += data.toString();
63
+ });
64
+ child.stderr.on("data", (data) => {
65
+ stderr += data.toString();
66
+ });
67
+ child.on("close", (code) => {
68
+ resolve2({
69
+ exitCode: code || 0,
70
+ stdout,
71
+ stderr
72
+ });
73
+ });
74
+ child.on("error", (err) => {
75
+ reject(err);
76
+ });
77
+ });
78
+ }
79
+
80
+ function validatePath(targetPath, workingDirectory) {
81
+ const resolvedTarget = resolve(workingDirectory, targetPath);
82
+ const resolvedWorkingDir = resolve(workingDirectory);
83
+ if (!resolvedTarget.startsWith(resolvedWorkingDir + sep) && resolvedTarget !== resolvedWorkingDir) {
84
+ return {
85
+ valid: false,
86
+ resolvedPath: resolvedTarget,
87
+ error: `Access denied: Path '${targetPath}' is outside the working directory`
88
+ };
89
+ }
90
+ return { valid: true, resolvedPath: resolvedTarget };
91
+ }
92
+
93
+ const MAX_USER_UPLOAD_BYTES = 8 * 1024 * 1024;
94
+ const MAX_USER_UPLOAD_CHUNK_BYTES = 96 * 1024;
95
+ const MAX_ACTIVE_UPLOADS = 8;
96
+ const UPLOAD_TTL_MS = 10 * 60 * 1e3;
97
+ function safeSegment(value, fallback, maxLength) {
98
+ const sanitized = (value || fallback).replace(/[^\w.\-]+/g, "_").slice(0, maxLength) || fallback;
99
+ return sanitized === "." || sanitized === ".." ? fallback : sanitized;
100
+ }
101
+ function safeFileName(value) {
102
+ const basename = (value || "file").split(/[/\\]/).pop() || "file";
103
+ return safeSegment(basename, "file", 200);
104
+ }
105
+ function uniqueFileName(name, token) {
106
+ const dot = name.lastIndexOf(".");
107
+ return dot > 0 ? `${name.slice(0, dot)}-${token}${name.slice(dot)}` : `${name}-${token}`;
108
+ }
109
+ function decodeUploadBase64(content, maxBytes) {
110
+ const maxEncodedLength = Math.ceil(maxBytes / 3) * 4;
111
+ if (content.length > maxEncodedLength || content.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(content)) {
112
+ throw new Error("Invalid upload payload");
113
+ }
114
+ const buffer = Buffer.from(content, "base64");
115
+ if (buffer.length > maxBytes || buffer.toString("base64") !== content) {
116
+ throw new Error("Invalid upload payload");
117
+ }
118
+ return buffer;
119
+ }
120
+ function validateUploadId(value) {
121
+ if (!/^[A-Za-z0-9_-]{8,80}$/.test(value)) {
122
+ throw new Error("Invalid upload id");
123
+ }
124
+ return value;
125
+ }
126
+ function defaultPathQuoteStyle() {
127
+ if (process.platform !== "win32") return "posix";
128
+ const shell = (process.env.COMSPEC || "powershell.exe").toLowerCase();
129
+ return shell.includes("powershell") || shell.includes("pwsh") ? "powershell" : "cmd";
130
+ }
131
+ function createUploadFileHandlers(happyHomeDir, now = Date.now, pathQuoteStyle = defaultPathQuoteStyle()) {
132
+ const active = /* @__PURE__ */ new Map();
133
+ let operationQueue = Promise.resolve();
134
+ const serialize = (handler) => (data) => {
135
+ const result = operationQueue.then(() => handler(data), () => handler(data));
136
+ operationQueue = result.then(() => void 0, () => void 0);
137
+ return result;
138
+ };
139
+ const removeActive = async (uploadId) => {
140
+ const upload = active.get(uploadId);
141
+ active.delete(uploadId);
142
+ if (upload) await unlink(upload.tempPath).catch(() => {
143
+ });
144
+ };
145
+ const sweepExpired = async () => {
146
+ const cutoff = now() - UPLOAD_TTL_MS;
147
+ await Promise.all(
148
+ [...active.entries()].filter(([, upload]) => upload.touchedAt < cutoff).map(([uploadId]) => removeActive(uploadId))
149
+ );
150
+ };
151
+ const sweepExpiredFiles = async (dir) => {
152
+ const cutoff = now() - UPLOAD_TTL_MS;
153
+ const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
154
+ await Promise.all(entries.map(async (entry) => {
155
+ if (!entry.isFile() || !/^\..+\.[A-Za-z0-9_-]{8,80}\.part$/.test(entry.name)) return;
156
+ const path = join(dir, entry.name);
157
+ const fileStat = await stat(path).catch(() => null);
158
+ if (fileStat && fileStat.mtimeMs < cutoff) await unlink(path).catch(() => {
159
+ });
160
+ }));
161
+ };
162
+ const uploadFileUnlocked = async (data) => {
163
+ let tempPath = null;
164
+ try {
165
+ const buffer = decodeUploadBase64(data.content, MAX_USER_UPLOAD_BYTES);
166
+ const dir = join(happyHomeDir, "uploads", safeSegment(data.subdir, "misc", 80));
167
+ await mkdir(dir, { recursive: true });
168
+ const name = safeFileName(data.name);
169
+ const token = randomUUID().replace(/-/g, "").slice(0, 12);
170
+ const target = join(dir, uniqueFileName(name, token));
171
+ tempPath = join(dir, `.${name}.legacy_${randomUUID().replace(/-/g, "")}.part`);
172
+ await writeFile(tempPath, buffer, { flag: "wx" });
173
+ await rename(tempPath, target);
174
+ tempPath = null;
175
+ return { success: true, path: target, pathQuoteStyle, size: buffer.length };
176
+ } catch (error) {
177
+ if (tempPath) await unlink(tempPath).catch(() => {
178
+ });
179
+ return { success: false, error: error instanceof Error ? error.message : "Failed to upload file" };
180
+ }
181
+ };
182
+ const uploadFileChunkUnlocked = async (data) => {
183
+ try {
184
+ await sweepExpired();
185
+ const uploadId = validateUploadId(data.uploadId);
186
+ if (data.action === "start") {
187
+ if (!Number.isSafeInteger(data.totalSize) || data.totalSize < 0 || data.totalSize > MAX_USER_UPLOAD_BYTES) {
188
+ throw new Error(`File exceeds the ${MAX_USER_UPLOAD_BYTES / 1024 / 1024} MB upload limit`);
189
+ }
190
+ if (active.has(uploadId)) throw new Error("Upload id is already active");
191
+ if (active.size >= MAX_ACTIVE_UPLOADS) throw new Error("Too many active uploads");
192
+ const dir = join(happyHomeDir, "uploads", safeSegment(data.subdir, "misc", 80));
193
+ await mkdir(dir, { recursive: true });
194
+ await sweepExpiredFiles(dir);
195
+ const name = safeFileName(data.name);
196
+ const targetPath = join(dir, uniqueFileName(name, randomUUID().replace(/-/g, "").slice(0, 12)));
197
+ const tempPath = join(dir, `.${name}.${uploadId}.part`);
198
+ await writeFile(tempPath, Buffer.alloc(0), { flag: "wx" });
199
+ active.set(uploadId, { tempPath, targetPath, totalSize: data.totalSize, received: 0, touchedAt: now() });
200
+ return { success: true, size: 0 };
201
+ }
202
+ if (data.action === "abort") {
203
+ const upload2 = active.get(uploadId);
204
+ if (!upload2) return { success: true, size: 0 };
205
+ await removeActive(uploadId);
206
+ return { success: true, size: upload2.received };
207
+ }
208
+ const upload = active.get(uploadId);
209
+ if (!upload) throw new Error("Upload is not active or has expired");
210
+ if (data.action === "append") {
211
+ if (!Number.isSafeInteger(data.offset) || data.offset !== upload.received) {
212
+ throw new Error("Upload chunk is out of order");
213
+ }
214
+ const chunk = decodeUploadBase64(data.content, MAX_USER_UPLOAD_CHUNK_BYTES);
215
+ if (upload.received + chunk.length > upload.totalSize) {
216
+ throw new Error("Upload exceeds declared size");
217
+ }
218
+ await appendFile(upload.tempPath, chunk);
219
+ upload.received += chunk.length;
220
+ upload.touchedAt = now();
221
+ return { success: true, size: upload.received };
222
+ }
223
+ if (data.action !== "finish") throw new Error("Invalid upload action");
224
+ if (upload.received !== upload.totalSize) throw new Error("Upload is incomplete");
225
+ const tempStat = await stat(upload.tempPath);
226
+ if (tempStat.size !== upload.totalSize) throw new Error("Upload size verification failed");
227
+ await rename(upload.tempPath, upload.targetPath);
228
+ active.delete(uploadId);
229
+ return { success: true, path: upload.targetPath, pathQuoteStyle, size: upload.totalSize };
230
+ } catch (error) {
231
+ return { success: false, error: error instanceof Error ? error.message : "Failed to upload file" };
232
+ }
233
+ };
234
+ return {
235
+ uploadFile: serialize(uploadFileUnlocked),
236
+ uploadFileChunk: serialize(uploadFileChunkUnlocked)
237
+ };
238
+ }
239
+
240
+ const execAsync = promisify(exec);
241
+ function registerCommonHandlers(rpcHandlerManager, workingDirectory) {
242
+ rpcHandlerManager.registerHandler("bash", async (data) => {
243
+ logger.debug("Shell command request:", data.command);
244
+ if (data.cwd && data.cwd !== "/") {
245
+ const validation = validatePath(data.cwd, workingDirectory);
246
+ if (!validation.valid) {
247
+ return { success: false, error: validation.error };
248
+ }
249
+ data.cwd = validation.resolvedPath;
250
+ }
251
+ try {
252
+ const options = {
253
+ cwd: data.cwd === "/" ? void 0 : data.cwd,
254
+ timeout: data.timeout || 3e4,
255
+ // Default 30 seconds timeout
256
+ windowsHide: true
257
+ // Prevent cmd.exe popup on Windows for every RPC bash call
258
+ };
259
+ logger.debug("Shell command executing...", { cwd: options.cwd, timeout: options.timeout });
260
+ const { stdout, stderr } = await execAsync(data.command, options);
261
+ logger.debug("Shell command executed, processing result...");
262
+ const result = {
263
+ success: true,
264
+ stdout: stdout ? stdout.toString() : "",
265
+ stderr: stderr ? stderr.toString() : "",
266
+ exitCode: 0
267
+ };
268
+ logger.debug("Shell command result:", {
269
+ success: true,
270
+ exitCode: 0,
271
+ stdoutLen: result.stdout.length,
272
+ stderrLen: result.stderr.length
273
+ });
274
+ return result;
275
+ } catch (error) {
276
+ const execError = error;
277
+ if (execError.code === "ETIMEDOUT" || execError.killed) {
278
+ const result2 = {
279
+ success: false,
280
+ stdout: execError.stdout || "",
281
+ stderr: execError.stderr || "",
282
+ exitCode: typeof execError.code === "number" ? execError.code : -1,
283
+ error: "Command timed out"
284
+ };
285
+ logger.debug("Shell command timed out:", {
286
+ success: false,
287
+ exitCode: result2.exitCode,
288
+ error: "Command timed out"
289
+ });
290
+ return result2;
291
+ }
292
+ const result = {
293
+ success: false,
294
+ stdout: execError.stdout ? execError.stdout.toString() : "",
295
+ stderr: execError.stderr ? execError.stderr.toString() : execError.message || "Command failed",
296
+ exitCode: typeof execError.code === "number" ? execError.code : 1,
297
+ error: execError.message || "Command failed"
298
+ };
299
+ logger.debug("Shell command failed:", {
300
+ success: false,
301
+ exitCode: result.exitCode,
302
+ error: result.error,
303
+ stdoutLen: result.stdout.length,
304
+ stderrLen: result.stderr.length
305
+ });
306
+ return result;
307
+ }
308
+ });
309
+ rpcHandlerManager.registerHandler("readFile", async (data) => {
310
+ logger.debug("Read file request:", data.path);
311
+ const validation = validatePath(data.path, workingDirectory);
312
+ if (!validation.valid) {
313
+ return { success: false, error: validation.error };
314
+ }
315
+ try {
316
+ const buffer = await readFile(validation.resolvedPath);
317
+ const content = buffer.toString("base64");
318
+ return { success: true, content };
319
+ } catch (error) {
320
+ logger.debug("Failed to read file:", error);
321
+ return { success: false, error: error instanceof Error ? error.message : "Failed to read file" };
322
+ }
323
+ });
324
+ rpcHandlerManager.registerHandler("writeFile", async (data) => {
325
+ logger.debug("Write file request:", data.path);
326
+ const validation = validatePath(data.path, workingDirectory);
327
+ if (!validation.valid) {
328
+ return { success: false, error: validation.error };
329
+ }
330
+ try {
331
+ if (data.expectedHash !== null && data.expectedHash !== void 0) {
332
+ try {
333
+ const existingBuffer = await readFile(validation.resolvedPath);
334
+ const existingHash = createHash("sha256").update(existingBuffer).digest("hex");
335
+ if (existingHash !== data.expectedHash) {
336
+ return {
337
+ success: false,
338
+ error: `File hash mismatch. Expected: ${data.expectedHash}, Actual: ${existingHash}`
339
+ };
340
+ }
341
+ } catch (error) {
342
+ const nodeError = error;
343
+ if (nodeError.code !== "ENOENT") {
344
+ throw error;
345
+ }
346
+ return {
347
+ success: false,
348
+ error: "File does not exist but hash was provided"
349
+ };
350
+ }
351
+ } else {
352
+ try {
353
+ await stat(validation.resolvedPath);
354
+ return {
355
+ success: false,
356
+ error: "File already exists but was expected to be new"
357
+ };
358
+ } catch (error) {
359
+ const nodeError = error;
360
+ if (nodeError.code !== "ENOENT") {
361
+ throw error;
362
+ }
363
+ }
364
+ }
365
+ const buffer = Buffer.from(data.content, "base64");
366
+ await writeFile(validation.resolvedPath, buffer);
367
+ const hash = createHash("sha256").update(buffer).digest("hex");
368
+ return { success: true, hash };
369
+ } catch (error) {
370
+ logger.debug("Failed to write file:", error);
371
+ return { success: false, error: error instanceof Error ? error.message : "Failed to write file" };
372
+ }
373
+ });
374
+ const uploadHandlers = createUploadFileHandlers(configuration.happyHomeDir);
375
+ rpcHandlerManager.registerHandler("uploadFile", uploadHandlers.uploadFile);
376
+ rpcHandlerManager.registerHandler("uploadFileChunk", uploadHandlers.uploadFileChunk);
377
+ rpcHandlerManager.registerHandler("listDirectory", async (data) => {
378
+ logger.debug("List directory request:", data.path);
379
+ const validation = validatePath(data.path, workingDirectory);
380
+ if (!validation.valid) {
381
+ return { success: false, error: validation.error };
382
+ }
383
+ try {
384
+ const directoryPath = validation.resolvedPath;
385
+ const entries = await readdir(directoryPath, { withFileTypes: true });
386
+ const directoryEntries = await Promise.all(
387
+ entries.map(async (entry) => {
388
+ const fullPath = join(directoryPath, entry.name);
389
+ let type = "other";
390
+ let size;
391
+ let modified;
392
+ if (entry.isDirectory()) {
393
+ type = "directory";
394
+ } else if (entry.isFile()) {
395
+ type = "file";
396
+ }
397
+ try {
398
+ const stats = await stat(fullPath);
399
+ size = stats.size;
400
+ modified = stats.mtime.getTime();
401
+ } catch (error) {
402
+ logger.debug(`Failed to stat ${fullPath}:`, error);
403
+ }
404
+ return {
405
+ name: entry.name,
406
+ type,
407
+ size,
408
+ modified
409
+ };
410
+ })
411
+ );
412
+ directoryEntries.sort((a, b) => {
413
+ if (a.type === "directory" && b.type !== "directory") return -1;
414
+ if (a.type !== "directory" && b.type === "directory") return 1;
415
+ return a.name.localeCompare(b.name);
416
+ });
417
+ return { success: true, entries: directoryEntries };
418
+ } catch (error) {
419
+ logger.debug("Failed to list directory:", error);
420
+ return { success: false, error: error instanceof Error ? error.message : "Failed to list directory" };
421
+ }
422
+ });
423
+ rpcHandlerManager.registerHandler("getDirectoryTree", async (data) => {
424
+ logger.debug("Get directory tree request:", data.path, "maxDepth:", data.maxDepth);
425
+ const validation = validatePath(data.path, workingDirectory);
426
+ if (!validation.valid) {
427
+ return { success: false, error: validation.error };
428
+ }
429
+ async function buildTree(path, name, currentDepth) {
430
+ try {
431
+ const stats = await stat(path);
432
+ const node = {
433
+ name,
434
+ path,
435
+ type: stats.isDirectory() ? "directory" : "file",
436
+ size: stats.size,
437
+ modified: stats.mtime.getTime()
438
+ };
439
+ if (stats.isDirectory() && currentDepth < data.maxDepth) {
440
+ const entries = await readdir(path, { withFileTypes: true });
441
+ const children = [];
442
+ await Promise.all(
443
+ entries.map(async (entry) => {
444
+ if (entry.isSymbolicLink()) {
445
+ logger.debug(`Skipping symlink: ${join(path, entry.name)}`);
446
+ return;
447
+ }
448
+ const childPath = join(path, entry.name);
449
+ const childNode = await buildTree(childPath, entry.name, currentDepth + 1);
450
+ if (childNode) {
451
+ children.push(childNode);
452
+ }
453
+ })
454
+ );
455
+ children.sort((a, b) => {
456
+ if (a.type === "directory" && b.type !== "directory") return -1;
457
+ if (a.type !== "directory" && b.type === "directory") return 1;
458
+ return a.name.localeCompare(b.name);
459
+ });
460
+ node.children = children;
461
+ }
462
+ return node;
463
+ } catch (error) {
464
+ logger.debug(`Failed to process ${path}:`, error instanceof Error ? error.message : String(error));
465
+ return null;
466
+ }
467
+ }
468
+ try {
469
+ if (data.maxDepth < 0) {
470
+ return { success: false, error: "maxDepth must be non-negative" };
471
+ }
472
+ const rootPath = validation.resolvedPath;
473
+ const baseName = rootPath === "/" ? "/" : rootPath.split("/").pop() || rootPath;
474
+ const tree = await buildTree(rootPath, baseName, 0);
475
+ if (!tree) {
476
+ return { success: false, error: "Failed to access the specified path" };
477
+ }
478
+ return { success: true, tree };
479
+ } catch (error) {
480
+ logger.debug("Failed to get directory tree:", error);
481
+ return { success: false, error: error instanceof Error ? error.message : "Failed to get directory tree" };
482
+ }
483
+ });
484
+ rpcHandlerManager.registerHandler("ripgrep", async (data) => {
485
+ logger.debug("Ripgrep request with args:", data.args, "cwd:", data.cwd);
486
+ if (data.cwd) {
487
+ const validation = validatePath(data.cwd, workingDirectory);
488
+ if (!validation.valid) {
489
+ return { success: false, error: validation.error };
490
+ }
491
+ data.cwd = validation.resolvedPath;
492
+ }
493
+ try {
494
+ const result = await run$1(data.args, { cwd: data.cwd });
495
+ return {
496
+ success: true,
497
+ exitCode: result.exitCode,
498
+ stdout: result.stdout.toString(),
499
+ stderr: result.stderr.toString()
500
+ };
501
+ } catch (error) {
502
+ logger.debug("Failed to run ripgrep:", error);
503
+ return {
504
+ success: false,
505
+ error: error instanceof Error ? error.message : "Failed to run ripgrep"
506
+ };
507
+ }
508
+ });
509
+ rpcHandlerManager.registerHandler("difftastic", async (data) => {
510
+ logger.debug("Difftastic request with args:", data.args, "cwd:", data.cwd);
511
+ if (data.cwd) {
512
+ const validation = validatePath(data.cwd, workingDirectory);
513
+ if (!validation.valid) {
514
+ return { success: false, error: validation.error };
515
+ }
516
+ data.cwd = validation.resolvedPath;
517
+ }
518
+ try {
519
+ const result = await run(data.args, { cwd: data.cwd });
520
+ return {
521
+ success: true,
522
+ exitCode: result.exitCode,
523
+ stdout: result.stdout.toString(),
524
+ stderr: result.stderr.toString()
525
+ };
526
+ } catch (error) {
527
+ logger.debug("Failed to run difftastic:", error);
528
+ return {
529
+ success: false,
530
+ error: error instanceof Error ? error.message : "Failed to run difftastic"
531
+ };
532
+ }
533
+ });
534
+ }
535
+
536
+ export { registerCommonHandlers as r };