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,157 @@
1
+ 'use strict';
2
+
3
+ var logger = require('./logger-Bc8-u1w0.cjs');
4
+
5
+ class BasePermissionHandler {
6
+ pendingRequests = /* @__PURE__ */ new Map();
7
+ session;
8
+ isResetting = false;
9
+ constructor(session) {
10
+ this.session = session;
11
+ this.setupRpcHandler();
12
+ }
13
+ /**
14
+ * Update the session reference (used after offline reconnection swaps sessions).
15
+ * This is critical for avoiding stale session references after onSessionSwap.
16
+ */
17
+ updateSession(newSession) {
18
+ logger.logger.debug(`${this.getLogPrefix()} Session reference updated`);
19
+ this.session = newSession;
20
+ this.setupRpcHandler();
21
+ }
22
+ /**
23
+ * Setup RPC handler for permission responses.
24
+ */
25
+ setupRpcHandler() {
26
+ this.session.rpcHandlerManager.registerHandler(
27
+ "permission",
28
+ async (response) => {
29
+ const pending = this.pendingRequests.get(response.id);
30
+ if (!pending) {
31
+ logger.logger.debug(`${this.getLogPrefix()} Permission request not found or already resolved`);
32
+ return;
33
+ }
34
+ this.pendingRequests.delete(response.id);
35
+ const result = response.approved ? { decision: response.decision === "approved_for_session" ? "approved_for_session" : "approved" } : { decision: response.decision === "denied" ? "denied" : "abort" };
36
+ pending.resolve(result);
37
+ this.session.updateAgentState((currentState) => {
38
+ const request = currentState.requests?.[response.id];
39
+ if (!request) return currentState;
40
+ const { [response.id]: _, ...remainingRequests } = currentState.requests || {};
41
+ let res = {
42
+ ...currentState,
43
+ requests: remainingRequests,
44
+ completedRequests: {
45
+ ...currentState.completedRequests,
46
+ [response.id]: {
47
+ ...request,
48
+ completedAt: Date.now(),
49
+ status: response.approved ? "approved" : "denied",
50
+ decision: result.decision
51
+ }
52
+ }
53
+ };
54
+ return res;
55
+ });
56
+ logger.logger.debug(`${this.getLogPrefix()} Permission ${response.approved ? "approved" : "denied"} for ${pending.toolName}`);
57
+ }
58
+ );
59
+ }
60
+ /**
61
+ * Add a pending request to the agent state.
62
+ */
63
+ addPendingRequestToState(toolCallId, toolName, input) {
64
+ this.session.updateAgentState((currentState) => ({
65
+ ...currentState,
66
+ requests: {
67
+ ...currentState.requests,
68
+ [toolCallId]: {
69
+ tool: toolName,
70
+ arguments: input,
71
+ createdAt: Date.now()
72
+ }
73
+ }
74
+ }));
75
+ }
76
+ /**
77
+ * Abort all pending permission requests.
78
+ * Unlike reset(), this resolves (not rejects) pending promises with { decision: 'abort' },
79
+ * causing the approval response to send 'cancel' to the provider. This is used when the
80
+ * user presses the abort/stop button — it unblocks any pending tool approval so the provider
81
+ * can process the turn cancellation.
82
+ */
83
+ abortAll() {
84
+ const pendingSnapshot = Array.from(this.pendingRequests.entries());
85
+ if (pendingSnapshot.length === 0) return;
86
+ this.pendingRequests.clear();
87
+ for (const [id, pending] of pendingSnapshot) {
88
+ try {
89
+ pending.resolve({ decision: "abort" });
90
+ } catch (err) {
91
+ logger.logger.debug(`${this.getLogPrefix()} Error resolving aborted request ${id}:`, err);
92
+ }
93
+ }
94
+ this.session.updateAgentState((currentState) => {
95
+ const pendingRequests = currentState.requests || {};
96
+ const completedRequests = { ...currentState.completedRequests };
97
+ for (const [id, request] of Object.entries(pendingRequests)) {
98
+ completedRequests[id] = {
99
+ ...request,
100
+ completedAt: Date.now(),
101
+ status: "canceled",
102
+ reason: "Aborted by user"
103
+ };
104
+ }
105
+ return {
106
+ ...currentState,
107
+ requests: {},
108
+ completedRequests
109
+ };
110
+ });
111
+ logger.logger.debug(`${this.getLogPrefix()} Aborted ${pendingSnapshot.length} pending permission(s)`);
112
+ }
113
+ /**
114
+ * Reset state for new sessions.
115
+ * This method is idempotent - safe to call multiple times.
116
+ */
117
+ reset(reason = "Session reset") {
118
+ if (this.isResetting) {
119
+ logger.logger.debug(`${this.getLogPrefix()} Reset already in progress, skipping`);
120
+ return;
121
+ }
122
+ this.isResetting = true;
123
+ try {
124
+ const pendingSnapshot = Array.from(this.pendingRequests.entries());
125
+ this.pendingRequests.clear();
126
+ for (const [id, pending] of pendingSnapshot) {
127
+ try {
128
+ pending.reject(new Error("Session reset"));
129
+ } catch (err) {
130
+ logger.logger.debug(`${this.getLogPrefix()} Error rejecting pending request ${id}:`, err);
131
+ }
132
+ }
133
+ this.session.updateAgentState((currentState) => {
134
+ const pendingRequests = currentState.requests || {};
135
+ const completedRequests = { ...currentState.completedRequests };
136
+ for (const [id, request] of Object.entries(pendingRequests)) {
137
+ completedRequests[id] = {
138
+ ...request,
139
+ completedAt: Date.now(),
140
+ status: "canceled",
141
+ reason
142
+ };
143
+ }
144
+ return {
145
+ ...currentState,
146
+ requests: {},
147
+ completedRequests
148
+ };
149
+ });
150
+ logger.logger.debug(`${this.getLogPrefix()} Permission handler reset`);
151
+ } finally {
152
+ this.isResetting = false;
153
+ }
154
+ }
155
+ }
156
+
157
+ exports.BasePermissionHandler = BasePermissionHandler;
@@ -0,0 +1,155 @@
1
+ import { l as logger } from './logger-fXoNzNuB.mjs';
2
+
3
+ class BasePermissionHandler {
4
+ pendingRequests = /* @__PURE__ */ new Map();
5
+ session;
6
+ isResetting = false;
7
+ constructor(session) {
8
+ this.session = session;
9
+ this.setupRpcHandler();
10
+ }
11
+ /**
12
+ * Update the session reference (used after offline reconnection swaps sessions).
13
+ * This is critical for avoiding stale session references after onSessionSwap.
14
+ */
15
+ updateSession(newSession) {
16
+ logger.debug(`${this.getLogPrefix()} Session reference updated`);
17
+ this.session = newSession;
18
+ this.setupRpcHandler();
19
+ }
20
+ /**
21
+ * Setup RPC handler for permission responses.
22
+ */
23
+ setupRpcHandler() {
24
+ this.session.rpcHandlerManager.registerHandler(
25
+ "permission",
26
+ async (response) => {
27
+ const pending = this.pendingRequests.get(response.id);
28
+ if (!pending) {
29
+ logger.debug(`${this.getLogPrefix()} Permission request not found or already resolved`);
30
+ return;
31
+ }
32
+ this.pendingRequests.delete(response.id);
33
+ const result = response.approved ? { decision: response.decision === "approved_for_session" ? "approved_for_session" : "approved" } : { decision: response.decision === "denied" ? "denied" : "abort" };
34
+ pending.resolve(result);
35
+ this.session.updateAgentState((currentState) => {
36
+ const request = currentState.requests?.[response.id];
37
+ if (!request) return currentState;
38
+ const { [response.id]: _, ...remainingRequests } = currentState.requests || {};
39
+ let res = {
40
+ ...currentState,
41
+ requests: remainingRequests,
42
+ completedRequests: {
43
+ ...currentState.completedRequests,
44
+ [response.id]: {
45
+ ...request,
46
+ completedAt: Date.now(),
47
+ status: response.approved ? "approved" : "denied",
48
+ decision: result.decision
49
+ }
50
+ }
51
+ };
52
+ return res;
53
+ });
54
+ logger.debug(`${this.getLogPrefix()} Permission ${response.approved ? "approved" : "denied"} for ${pending.toolName}`);
55
+ }
56
+ );
57
+ }
58
+ /**
59
+ * Add a pending request to the agent state.
60
+ */
61
+ addPendingRequestToState(toolCallId, toolName, input) {
62
+ this.session.updateAgentState((currentState) => ({
63
+ ...currentState,
64
+ requests: {
65
+ ...currentState.requests,
66
+ [toolCallId]: {
67
+ tool: toolName,
68
+ arguments: input,
69
+ createdAt: Date.now()
70
+ }
71
+ }
72
+ }));
73
+ }
74
+ /**
75
+ * Abort all pending permission requests.
76
+ * Unlike reset(), this resolves (not rejects) pending promises with { decision: 'abort' },
77
+ * causing the approval response to send 'cancel' to the provider. This is used when the
78
+ * user presses the abort/stop button — it unblocks any pending tool approval so the provider
79
+ * can process the turn cancellation.
80
+ */
81
+ abortAll() {
82
+ const pendingSnapshot = Array.from(this.pendingRequests.entries());
83
+ if (pendingSnapshot.length === 0) return;
84
+ this.pendingRequests.clear();
85
+ for (const [id, pending] of pendingSnapshot) {
86
+ try {
87
+ pending.resolve({ decision: "abort" });
88
+ } catch (err) {
89
+ logger.debug(`${this.getLogPrefix()} Error resolving aborted request ${id}:`, err);
90
+ }
91
+ }
92
+ this.session.updateAgentState((currentState) => {
93
+ const pendingRequests = currentState.requests || {};
94
+ const completedRequests = { ...currentState.completedRequests };
95
+ for (const [id, request] of Object.entries(pendingRequests)) {
96
+ completedRequests[id] = {
97
+ ...request,
98
+ completedAt: Date.now(),
99
+ status: "canceled",
100
+ reason: "Aborted by user"
101
+ };
102
+ }
103
+ return {
104
+ ...currentState,
105
+ requests: {},
106
+ completedRequests
107
+ };
108
+ });
109
+ logger.debug(`${this.getLogPrefix()} Aborted ${pendingSnapshot.length} pending permission(s)`);
110
+ }
111
+ /**
112
+ * Reset state for new sessions.
113
+ * This method is idempotent - safe to call multiple times.
114
+ */
115
+ reset(reason = "Session reset") {
116
+ if (this.isResetting) {
117
+ logger.debug(`${this.getLogPrefix()} Reset already in progress, skipping`);
118
+ return;
119
+ }
120
+ this.isResetting = true;
121
+ try {
122
+ const pendingSnapshot = Array.from(this.pendingRequests.entries());
123
+ this.pendingRequests.clear();
124
+ for (const [id, pending] of pendingSnapshot) {
125
+ try {
126
+ pending.reject(new Error("Session reset"));
127
+ } catch (err) {
128
+ logger.debug(`${this.getLogPrefix()} Error rejecting pending request ${id}:`, err);
129
+ }
130
+ }
131
+ this.session.updateAgentState((currentState) => {
132
+ const pendingRequests = currentState.requests || {};
133
+ const completedRequests = { ...currentState.completedRequests };
134
+ for (const [id, request] of Object.entries(pendingRequests)) {
135
+ completedRequests[id] = {
136
+ ...request,
137
+ completedAt: Date.now(),
138
+ status: "canceled",
139
+ reason
140
+ };
141
+ }
142
+ return {
143
+ ...currentState,
144
+ requests: {},
145
+ completedRequests
146
+ };
147
+ });
148
+ logger.debug(`${this.getLogPrefix()} Permission handler reset`);
149
+ } finally {
150
+ this.isResetting = false;
151
+ }
152
+ }
153
+ }
154
+
155
+ export { BasePermissionHandler as B };
@@ -0,0 +1,198 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { l as logger } from './logger-fXoNzNuB.mjs';
3
+
4
+ class BaseReasoningProcessor {
5
+ accumulator = "";
6
+ inTitleCapture = false;
7
+ titleBuffer = "";
8
+ contentBuffer = "";
9
+ hasTitle = false;
10
+ currentCallId = null;
11
+ toolCallStarted = false;
12
+ currentTitle = null;
13
+ onMessage = null;
14
+ constructor(onMessage) {
15
+ this.onMessage = onMessage || null;
16
+ this.reset();
17
+ }
18
+ /**
19
+ * Set the message callback for sending messages directly.
20
+ */
21
+ setMessageCallback(callback) {
22
+ this.onMessage = callback;
23
+ }
24
+ /**
25
+ * Process a reasoning section break - indicates a new reasoning section is starting.
26
+ */
27
+ handleSectionBreak() {
28
+ this.finishCurrentToolCall("canceled");
29
+ this.resetState();
30
+ logger.debug(`${this.getLogPrefix()} Section break - reset state`);
31
+ }
32
+ /**
33
+ * Process a reasoning delta/chunk and accumulate content.
34
+ */
35
+ processInput(input) {
36
+ this.accumulator += input;
37
+ if (!this.inTitleCapture && !this.hasTitle && !this.contentBuffer) {
38
+ if (this.accumulator.startsWith("**")) {
39
+ this.inTitleCapture = true;
40
+ this.titleBuffer = this.accumulator.substring(2);
41
+ logger.debug(`${this.getLogPrefix()} Started title capture`);
42
+ } else if (this.accumulator.length > 0) {
43
+ this.contentBuffer = this.accumulator;
44
+ }
45
+ } else if (this.inTitleCapture) {
46
+ this.titleBuffer = this.accumulator.substring(2);
47
+ const titleEndIndex = this.titleBuffer.indexOf("**");
48
+ if (titleEndIndex !== -1) {
49
+ const title = this.titleBuffer.substring(0, titleEndIndex);
50
+ const afterTitle = this.titleBuffer.substring(titleEndIndex + 2);
51
+ this.hasTitle = true;
52
+ this.inTitleCapture = false;
53
+ this.currentTitle = title;
54
+ this.contentBuffer = afterTitle;
55
+ this.currentCallId = randomUUID();
56
+ logger.debug(`${this.getLogPrefix()} Title captured: "${title}"`);
57
+ this.sendToolCallStart(title);
58
+ }
59
+ } else if (this.hasTitle) {
60
+ const titleStartIndex = this.accumulator.indexOf("**");
61
+ if (titleStartIndex !== -1) {
62
+ this.contentBuffer = this.accumulator.substring(
63
+ titleStartIndex + 2 + this.currentTitle.length + 2
64
+ );
65
+ }
66
+ } else {
67
+ this.contentBuffer = this.accumulator;
68
+ }
69
+ }
70
+ /**
71
+ * Send the tool call start message.
72
+ */
73
+ sendToolCallStart(title) {
74
+ if (!this.currentCallId || this.toolCallStarted) {
75
+ return;
76
+ }
77
+ const toolCall = {
78
+ type: "tool-call",
79
+ name: this.getToolName(),
80
+ callId: this.currentCallId,
81
+ input: {
82
+ title
83
+ },
84
+ id: randomUUID()
85
+ };
86
+ logger.debug(`${this.getLogPrefix()} Sending tool call start for: "${title}"`);
87
+ this.onMessage?.(toolCall);
88
+ this.toolCallStarted = true;
89
+ }
90
+ /**
91
+ * Complete the reasoning section.
92
+ * Returns true if reasoning was completed, false if there was nothing to complete.
93
+ */
94
+ completeReasoning(fullText) {
95
+ const text = fullText ?? this.accumulator;
96
+ if (!text.trim() && !this.toolCallStarted) {
97
+ logger.debug(`${this.getLogPrefix()} Complete called but no content accumulated, skipping`);
98
+ return false;
99
+ }
100
+ let title;
101
+ let content = text;
102
+ if (text.startsWith("**")) {
103
+ const titleEndIndex = text.indexOf("**", 2);
104
+ if (titleEndIndex !== -1) {
105
+ title = text.substring(2, titleEndIndex);
106
+ content = text.substring(titleEndIndex + 2).trim();
107
+ }
108
+ }
109
+ logger.debug(`${this.getLogPrefix()} Complete reasoning - Title: "${title}", Has content: ${content.length > 0}`);
110
+ if (title && !this.toolCallStarted) {
111
+ this.currentCallId = this.currentCallId || randomUUID();
112
+ this.sendToolCallStart(title);
113
+ }
114
+ if (this.toolCallStarted && this.currentCallId) {
115
+ const toolResult = {
116
+ type: "tool-call-result",
117
+ callId: this.currentCallId,
118
+ output: {
119
+ content,
120
+ status: "completed"
121
+ },
122
+ id: randomUUID()
123
+ };
124
+ logger.debug(`${this.getLogPrefix()} Sending tool call result`);
125
+ this.onMessage?.(toolResult);
126
+ } else if (content.trim()) {
127
+ const reasoningMessage = {
128
+ type: "reasoning",
129
+ message: content,
130
+ id: randomUUID()
131
+ };
132
+ logger.debug(`${this.getLogPrefix()} Sending reasoning message`);
133
+ this.onMessage?.(reasoningMessage);
134
+ }
135
+ this.resetState();
136
+ return true;
137
+ }
138
+ /**
139
+ * Abort the current reasoning section.
140
+ */
141
+ abort() {
142
+ logger.debug(`${this.getLogPrefix()} Abort called`);
143
+ this.finishCurrentToolCall("canceled");
144
+ this.resetState();
145
+ }
146
+ /**
147
+ * Reset the processor state.
148
+ */
149
+ reset() {
150
+ this.finishCurrentToolCall("canceled");
151
+ this.resetState();
152
+ }
153
+ /**
154
+ * Finish current tool call if one is in progress.
155
+ */
156
+ finishCurrentToolCall(status) {
157
+ if (this.toolCallStarted && this.currentCallId) {
158
+ const toolResult = {
159
+ type: "tool-call-result",
160
+ callId: this.currentCallId,
161
+ output: {
162
+ content: this.contentBuffer || "",
163
+ status
164
+ },
165
+ id: randomUUID()
166
+ };
167
+ logger.debug(`${this.getLogPrefix()} Sending tool call result with status: ${status}`);
168
+ this.onMessage?.(toolResult);
169
+ }
170
+ }
171
+ /**
172
+ * Reset internal state.
173
+ */
174
+ resetState() {
175
+ this.accumulator = "";
176
+ this.inTitleCapture = false;
177
+ this.titleBuffer = "";
178
+ this.contentBuffer = "";
179
+ this.hasTitle = false;
180
+ this.currentCallId = null;
181
+ this.toolCallStarted = false;
182
+ this.currentTitle = null;
183
+ }
184
+ /**
185
+ * Get the current call ID for tool result matching.
186
+ */
187
+ getCurrentCallId() {
188
+ return this.currentCallId;
189
+ }
190
+ /**
191
+ * Check if a tool call has been started.
192
+ */
193
+ hasStartedToolCall() {
194
+ return this.toolCallStarted;
195
+ }
196
+ }
197
+
198
+ export { BaseReasoningProcessor as B };
@@ -0,0 +1,200 @@
1
+ 'use strict';
2
+
3
+ var node_crypto = require('node:crypto');
4
+ var logger = require('./logger-Bc8-u1w0.cjs');
5
+
6
+ class BaseReasoningProcessor {
7
+ accumulator = "";
8
+ inTitleCapture = false;
9
+ titleBuffer = "";
10
+ contentBuffer = "";
11
+ hasTitle = false;
12
+ currentCallId = null;
13
+ toolCallStarted = false;
14
+ currentTitle = null;
15
+ onMessage = null;
16
+ constructor(onMessage) {
17
+ this.onMessage = onMessage || null;
18
+ this.reset();
19
+ }
20
+ /**
21
+ * Set the message callback for sending messages directly.
22
+ */
23
+ setMessageCallback(callback) {
24
+ this.onMessage = callback;
25
+ }
26
+ /**
27
+ * Process a reasoning section break - indicates a new reasoning section is starting.
28
+ */
29
+ handleSectionBreak() {
30
+ this.finishCurrentToolCall("canceled");
31
+ this.resetState();
32
+ logger.logger.debug(`${this.getLogPrefix()} Section break - reset state`);
33
+ }
34
+ /**
35
+ * Process a reasoning delta/chunk and accumulate content.
36
+ */
37
+ processInput(input) {
38
+ this.accumulator += input;
39
+ if (!this.inTitleCapture && !this.hasTitle && !this.contentBuffer) {
40
+ if (this.accumulator.startsWith("**")) {
41
+ this.inTitleCapture = true;
42
+ this.titleBuffer = this.accumulator.substring(2);
43
+ logger.logger.debug(`${this.getLogPrefix()} Started title capture`);
44
+ } else if (this.accumulator.length > 0) {
45
+ this.contentBuffer = this.accumulator;
46
+ }
47
+ } else if (this.inTitleCapture) {
48
+ this.titleBuffer = this.accumulator.substring(2);
49
+ const titleEndIndex = this.titleBuffer.indexOf("**");
50
+ if (titleEndIndex !== -1) {
51
+ const title = this.titleBuffer.substring(0, titleEndIndex);
52
+ const afterTitle = this.titleBuffer.substring(titleEndIndex + 2);
53
+ this.hasTitle = true;
54
+ this.inTitleCapture = false;
55
+ this.currentTitle = title;
56
+ this.contentBuffer = afterTitle;
57
+ this.currentCallId = node_crypto.randomUUID();
58
+ logger.logger.debug(`${this.getLogPrefix()} Title captured: "${title}"`);
59
+ this.sendToolCallStart(title);
60
+ }
61
+ } else if (this.hasTitle) {
62
+ const titleStartIndex = this.accumulator.indexOf("**");
63
+ if (titleStartIndex !== -1) {
64
+ this.contentBuffer = this.accumulator.substring(
65
+ titleStartIndex + 2 + this.currentTitle.length + 2
66
+ );
67
+ }
68
+ } else {
69
+ this.contentBuffer = this.accumulator;
70
+ }
71
+ }
72
+ /**
73
+ * Send the tool call start message.
74
+ */
75
+ sendToolCallStart(title) {
76
+ if (!this.currentCallId || this.toolCallStarted) {
77
+ return;
78
+ }
79
+ const toolCall = {
80
+ type: "tool-call",
81
+ name: this.getToolName(),
82
+ callId: this.currentCallId,
83
+ input: {
84
+ title
85
+ },
86
+ id: node_crypto.randomUUID()
87
+ };
88
+ logger.logger.debug(`${this.getLogPrefix()} Sending tool call start for: "${title}"`);
89
+ this.onMessage?.(toolCall);
90
+ this.toolCallStarted = true;
91
+ }
92
+ /**
93
+ * Complete the reasoning section.
94
+ * Returns true if reasoning was completed, false if there was nothing to complete.
95
+ */
96
+ completeReasoning(fullText) {
97
+ const text = fullText ?? this.accumulator;
98
+ if (!text.trim() && !this.toolCallStarted) {
99
+ logger.logger.debug(`${this.getLogPrefix()} Complete called but no content accumulated, skipping`);
100
+ return false;
101
+ }
102
+ let title;
103
+ let content = text;
104
+ if (text.startsWith("**")) {
105
+ const titleEndIndex = text.indexOf("**", 2);
106
+ if (titleEndIndex !== -1) {
107
+ title = text.substring(2, titleEndIndex);
108
+ content = text.substring(titleEndIndex + 2).trim();
109
+ }
110
+ }
111
+ logger.logger.debug(`${this.getLogPrefix()} Complete reasoning - Title: "${title}", Has content: ${content.length > 0}`);
112
+ if (title && !this.toolCallStarted) {
113
+ this.currentCallId = this.currentCallId || node_crypto.randomUUID();
114
+ this.sendToolCallStart(title);
115
+ }
116
+ if (this.toolCallStarted && this.currentCallId) {
117
+ const toolResult = {
118
+ type: "tool-call-result",
119
+ callId: this.currentCallId,
120
+ output: {
121
+ content,
122
+ status: "completed"
123
+ },
124
+ id: node_crypto.randomUUID()
125
+ };
126
+ logger.logger.debug(`${this.getLogPrefix()} Sending tool call result`);
127
+ this.onMessage?.(toolResult);
128
+ } else if (content.trim()) {
129
+ const reasoningMessage = {
130
+ type: "reasoning",
131
+ message: content,
132
+ id: node_crypto.randomUUID()
133
+ };
134
+ logger.logger.debug(`${this.getLogPrefix()} Sending reasoning message`);
135
+ this.onMessage?.(reasoningMessage);
136
+ }
137
+ this.resetState();
138
+ return true;
139
+ }
140
+ /**
141
+ * Abort the current reasoning section.
142
+ */
143
+ abort() {
144
+ logger.logger.debug(`${this.getLogPrefix()} Abort called`);
145
+ this.finishCurrentToolCall("canceled");
146
+ this.resetState();
147
+ }
148
+ /**
149
+ * Reset the processor state.
150
+ */
151
+ reset() {
152
+ this.finishCurrentToolCall("canceled");
153
+ this.resetState();
154
+ }
155
+ /**
156
+ * Finish current tool call if one is in progress.
157
+ */
158
+ finishCurrentToolCall(status) {
159
+ if (this.toolCallStarted && this.currentCallId) {
160
+ const toolResult = {
161
+ type: "tool-call-result",
162
+ callId: this.currentCallId,
163
+ output: {
164
+ content: this.contentBuffer || "",
165
+ status
166
+ },
167
+ id: node_crypto.randomUUID()
168
+ };
169
+ logger.logger.debug(`${this.getLogPrefix()} Sending tool call result with status: ${status}`);
170
+ this.onMessage?.(toolResult);
171
+ }
172
+ }
173
+ /**
174
+ * Reset internal state.
175
+ */
176
+ resetState() {
177
+ this.accumulator = "";
178
+ this.inTitleCapture = false;
179
+ this.titleBuffer = "";
180
+ this.contentBuffer = "";
181
+ this.hasTitle = false;
182
+ this.currentCallId = null;
183
+ this.toolCallStarted = false;
184
+ this.currentTitle = null;
185
+ }
186
+ /**
187
+ * Get the current call ID for tool result matching.
188
+ */
189
+ getCurrentCallId() {
190
+ return this.currentCallId;
191
+ }
192
+ /**
193
+ * Check if a tool call has been started.
194
+ */
195
+ hasStartedToolCall() {
196
+ return this.toolCallStarted;
197
+ }
198
+ }
199
+
200
+ exports.BaseReasoningProcessor = BaseReasoningProcessor;