very-happy-cli 0.2.165 → 0.2.167
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.
- package/README.md +1 -1
- package/dist/{AcpBackend-DCfNt9bD.cjs → AcpBackend-D1IKJGz_.cjs} +3 -3
- package/dist/{AcpBackend-C11FnVw5.mjs → AcpBackend-kFZlee5E.mjs} +3 -3
- package/dist/{AcpSessionManager-BQnDJvct.mjs → AcpSessionManager-B7FIrsys.mjs} +1 -1
- package/dist/{AcpSessionManager-9yN2iH4b.cjs → AcpSessionManager-Zf00QnlL.cjs} +1 -1
- package/dist/{BasePermissionHandler-BwQHxl6M.cjs → BasePermissionHandler-DHxYAK5L.cjs} +1 -1
- package/dist/{BasePermissionHandler-CwJ48yiB.mjs → BasePermissionHandler-DS0kRTNI.mjs} +1 -1
- package/dist/{BaseReasoningProcessor-ClF2g1qz.mjs → BaseReasoningProcessor-BRtCCt7q.mjs} +1 -1
- package/dist/{BaseReasoningProcessor-81lf_M8G.cjs → BaseReasoningProcessor-CsjVdt_H.cjs} +1 -1
- package/dist/{agentGuidance-CQuNlNx8.mjs → agentGuidance-BDYt2Qy2.mjs} +4 -2
- package/dist/{agentGuidance-B5NATuFa.cjs → agentGuidance-BtBx2xxE.cjs} +4 -1
- package/dist/{agentHome-DvR176E5.mjs → agentHome-Ct-VXFeG.mjs} +4 -4
- package/dist/{agentHome-D3Nn82kI.cjs → agentHome-DeAWzhSe.cjs} +4 -4
- package/dist/{api-AzdzTKFs.cjs → api-BZYLRDM9.cjs} +93 -13
- package/dist/{api-DTVPUE7g.mjs → api-CReZazeT.mjs} +93 -13
- package/dist/{apiMachine-B_cJldfa.cjs → apiMachine-BgMxGPsR.cjs} +2173 -66
- package/dist/{apiMachine-BQ-b4Lu3.mjs → apiMachine-CWndf1Vn.mjs} +2176 -69
- package/dist/{attachmentContent-muDCe4Gy.cjs → attachmentContent-HcJqFQW8.cjs} +2 -2
- package/dist/{attachmentContent-dzIs-wis.mjs → attachmentContent-j875mwU7.mjs} +2 -2
- package/dist/{attachmentLimits-eJZ4ZBjF.cjs → attachmentLimits-BEYEEBm8.cjs} +40 -2
- package/dist/{attachmentLimits-B8nzhw-i.mjs → attachmentLimits-CxG3T18E.mjs} +40 -2
- package/dist/{auth-Jtmvh1w4.mjs → auth-BIHuc7vY.mjs} +10 -10
- package/dist/{auth-BY5ujhGn.mjs → auth-CFS9Lfgv.mjs} +5 -5
- package/dist/{auth-DtP-B4gf.cjs → auth-Myr2Q42x.cjs} +10 -10
- package/dist/{auth-CfLd3phE.cjs → auth-VzWpbo5P.cjs} +5 -5
- package/dist/{auto-ClNnbSoF.cjs → auto-Bf6Dr7_o.cjs} +85 -21
- package/dist/{auto-DjWfR1UB.mjs → auto-Df9-zmuN.mjs} +84 -22
- package/dist/{bootstrap-D_ExGrY2.mjs → bootstrap-BSOxYpaP.mjs} +2 -2
- package/dist/{bootstrap-B1dMZA-u.cjs → bootstrap-Dj8WBiR2.cjs} +2 -2
- package/dist/{browser-mwzpOmcw.mjs → browser-BCFIHOvo.mjs} +1 -1
- package/dist/{browser-_gV7tcPs.cjs → browser-BoCV40yC.cjs} +1 -1
- package/dist/{claudeLocal-G5UmJ81F.cjs → claudeLocal-CGsq7Kul.cjs} +7 -7
- package/dist/{claudeLocal-BeHToEK5.mjs → claudeLocal-D5-eA9SC.mjs} +7 -7
- package/dist/{claudeLocalLauncher-Cq6bqAT4.mjs → claudeLocalLauncher-C9Cc438l.mjs} +15 -12
- package/dist/{claudeLocalLauncher-B4y2BsmO.cjs → claudeLocalLauncher-Cf9QeYDT.cjs} +15 -12
- package/dist/{claudeSessionFork-CDJq_b9r.cjs → claudeSessionFork-Byd8zD1U.cjs} +1 -1
- package/dist/{claudeSessionFork-CokUhS4r.mjs → claudeSessionFork-CMzAva8G.mjs} +1 -1
- package/dist/{client-Do7cGPEq.cjs → client-BKnKRLSt.cjs} +3 -3
- package/dist/{client-CJZKBZCE.mjs → client-C7FYMer0.mjs} +2 -2
- package/dist/{client-uN9d6Git.cjs → client-D0T5-6Ds.cjs} +2 -2
- package/dist/{client-BwaWdlCm.mjs → client-Dsfy_SAb.mjs} +3 -3
- package/dist/codex/happyMcpStdioBridge.cjs +23 -18
- package/dist/codex/happyMcpStdioBridge.mjs +22 -17
- package/dist/{codexAppServerClient-B0QaMQsC.mjs → codexAppServerClient-Dd_4TxHv.mjs} +48 -4
- package/dist/{codexAppServerClient-BuSdeUxT.cjs → codexAppServerClient-TiW9OBk4.cjs} +47 -3
- package/dist/{codexCommand-C3gdjMAw.mjs → codexCommand-BZSr4MKI.mjs} +170 -69
- package/dist/{codexCommand-YdYmykAR.cjs → codexCommand-Bxryqh90.cjs} +170 -69
- package/dist/{config-CGCIFRCN.mjs → config-C_Pj7yxV.mjs} +3 -3
- package/dist/{config-ChoHFnfO.cjs → config-DXPash-r.cjs} +3 -3
- package/dist/{configuration-BE61XNsg.cjs → configuration-C3piBtxY.cjs} +1 -1
- package/dist/{configuration-L1qcGTFM.mjs → configuration-WspKd2C2.mjs} +2 -2
- package/dist/{connect-D5IKfcfd.cjs → connect-BN-IBElA.cjs} +14 -14
- package/dist/{connect-CFD0Em6a.mjs → connect-DGPZs5px.mjs} +14 -14
- package/dist/{context-DaCCB4cm.mjs → context-Cr6a3NTg.mjs} +1 -1
- package/dist/{context-3WVw8qPz.cjs → context-Jrq4-eCZ.cjs} +1 -1
- package/dist/{controlClient-RWTlQA4_.cjs → controlClient-BI6Fw3fQ.cjs} +28 -5
- package/dist/{controlClient-Ci7HTMII.mjs → controlClient-DTheOlvC.mjs} +27 -6
- package/dist/{createSessionMetadata-CWR-AB2A.mjs → createSessionMetadata-BEZ4DIDA.mjs} +57 -5
- package/dist/{createSessionMetadata-CPGTztXP.cjs → createSessionMetadata-zQSz3hgk.cjs} +56 -3
- package/dist/defaultPermissionMode-Cif_RHGb.mjs +191 -0
- package/dist/defaultPermissionMode-DNKNzk7l.cjs +197 -0
- package/dist/{deterministicJson-BBwG-Ase.mjs → deterministicJson-BMMifViN.mjs} +36 -52
- package/dist/{deterministicJson-C4Jo2RWy.cjs → deterministicJson-C7O2ulKY.cjs} +41 -59
- package/dist/{doctor-ZOQLE5AH.cjs → doctor-BykBaMTr.cjs} +6 -6
- package/dist/{doctor-CAC6qY9Z.mjs → doctor-D1KKyPzB.mjs} +6 -6
- package/dist/{assistantTools-BsrG3PD-.cjs → downloadTarget-CWTb2-EM.cjs} +44 -6
- package/dist/{assistantTools-DPGga5lM.mjs → downloadTarget-Cp48jrIP.mjs} +45 -8
- package/dist/{ensureDaemonRunning-b1pvEFcS.mjs → ensureDaemonRunning-Ba5fYoxb.mjs} +5 -5
- package/dist/{ensureDaemonRunning-mIgX2vnc.cjs → ensureDaemonRunning-CCxX7MoP.cjs} +5 -5
- package/dist/{handleResumeCommand-CTGbZkCL.mjs → handleResumeCommand-BTUGlNjB.mjs} +5 -5
- package/dist/{handleResumeCommand-DGNhbv-3.cjs → handleResumeCommand-yPdDQHqz.cjs} +5 -5
- package/dist/{index-vVWpCoTr.mjs → index-B0HEEYGh.mjs} +22 -5
- package/dist/{index-BzIxE0Eu.cjs → index-BjhKqDa0.cjs} +3 -3
- package/dist/{index-BgzjPv07.mjs → index-C3_83bqS.mjs} +3 -3
- package/dist/{index-DqlyNgt4.cjs → index-C9hI8a10.cjs} +26 -4
- package/dist/{index-DjtBengz.mjs → index-CE2GgPbr.mjs} +40 -39
- package/dist/{index-Diu6HdWH.mjs → index-D8m8Ripb.mjs} +4 -4
- package/dist/{index-DrSPR59N.cjs → index-DifM62wX.cjs} +39 -38
- package/dist/{index-DIodyAqF.cjs → index-PNMQPKhz.cjs} +4 -4
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{install-BO_W7VhL.mjs → install-BdvKiOQw.mjs} +2 -0
- package/dist/{install-Cp_aB-NQ.mjs → install-C0-QFn9s.mjs} +3 -3
- package/dist/{install-Cs5qAPrB.cjs → install-Cf6AFSWC.cjs} +2 -0
- package/dist/{install-DrUQk2DJ.cjs → install-CqZVeze8.cjs} +3 -3
- package/dist/lib.cjs +12 -12
- package/dist/lib.d.cts +116 -2
- package/dist/lib.d.mts +116 -2
- package/dist/lib.mjs +12 -12
- package/dist/{lidState-BLHLmhwd.mjs → lidState-B2ZxdREe.mjs} +1 -1
- package/dist/{lidState-z9ekRpZu.cjs → lidState-Bc2K9H9l.cjs} +1 -1
- package/dist/{localHappyAgentAuth-BWvmc_Hg.mjs → localHappyAgentAuth-B5XPEMwk.mjs} +1 -1
- package/dist/{localHappyAgentAuth-BCx0y1qW.cjs → localHappyAgentAuth-T5GOvRha.cjs} +1 -1
- package/dist/{logger-D0hkk7Vo.cjs → logger-B_MWPbZz.cjs} +2 -2
- package/dist/{logger-CknSVkIe.mjs → logger-CbBv3q_b.mjs} +2 -2
- package/dist/{machineMetadata-BDCYOXQg.cjs → machineMetadata-BafS4JY8.cjs} +4 -3
- package/dist/{machineMetadata-Cj1DoFot.mjs → machineMetadata-DHg238U4.mjs} +4 -3
- package/dist/{main-COAPGIso.cjs → main-DNrA0qBy.cjs} +45 -45
- package/dist/{main-CKUfkVG_.mjs → main-DXAK0n7x.mjs} +45 -45
- package/dist/{manager-BQ4flvQZ.mjs → manager-BEsI4qt3.mjs} +9 -3
- package/dist/{manager-Cly8xVIR.cjs → manager-HrEj442o.cjs} +8 -2
- package/dist/{mcp-BILnw4si.cjs → mcp-AvPOhDXy.cjs} +24 -19
- package/dist/{mcp-DeYUfpo8.mjs → mcp-BotAjCdD.mjs} +23 -18
- package/dist/mirrorProtocol-BdcN6QlN.cjs +1270 -0
- package/dist/mirrorProtocol-BwHm8odn.mjs +1247 -0
- package/dist/{package-UkmvSFsg.cjs → package-C9ZP9bpX.cjs} +7 -7
- package/dist/{package-VIUXrYZ1.mjs → package-DU1DxhH9.mjs} +7 -7
- package/dist/{peerTools-CttfOxti.cjs → peerTools-Dkbu7gag.cjs} +4 -4
- package/dist/{peerTools-SWITnkqz.mjs → peerTools-os2DVjA0.mjs} +4 -4
- package/dist/{persistence-C6ztVW1W.cjs → persistence-BYGl0QYw.cjs} +147 -25
- package/dist/{persistence-DujtUH94.mjs → persistence-ON0zpHfb.mjs} +123 -12
- package/dist/{piRunnerArgs-BVJHIjlk.mjs → piRunnerArgs-CYsnT9sV.mjs} +1 -1
- package/dist/{piRunnerArgs-tBQg6xDw.cjs → piRunnerArgs-DpbvstUX.cjs} +1 -1
- package/dist/{piRuntime-DZzjF9It.cjs → piRuntime-CDnILlCd.cjs} +1 -1
- package/dist/{piRuntime-DKFA8u8t.mjs → piRuntime-CmEid-wu.mjs} +1 -1
- package/dist/{piTerminal-BTSaFlpV.mjs → piTerminal-0eNlXSlL.mjs} +17 -17
- package/dist/{piTerminal-t5pQHCPT.cjs → piTerminal-B57TgMON.cjs} +17 -17
- package/dist/precheckCompat-CWOi5c9L.cjs +29 -0
- package/dist/precheckCompat-DeEbilbr.mjs +26 -0
- package/dist/rateLimitWindows-CusGIqlq.cjs +258 -0
- package/dist/rateLimitWindows-vZ9Bo7aT.mjs +248 -0
- package/dist/{registerCommonHandlers-BR0J4g64.mjs → registerCommonHandlers-B0PVff2U.mjs} +2 -2
- package/dist/{registerCommonHandlers--8ds2auE.cjs → registerCommonHandlers-DVYB3iVn.cjs} +2 -2
- package/dist/{registerKillSessionHandler-Czz0tdki.mjs → registerKillSessionHandler-BJMHJHXe.mjs} +15 -10
- package/dist/{registerKillSessionHandler-CI23l8aJ.cjs → registerKillSessionHandler-BwXGKtg_.cjs} +15 -10
- package/dist/{remoteSessionClient-DCAUHgPz.mjs → remoteSessionClient-BzPXSC21.mjs} +5 -5
- package/dist/{remoteSessionClient-BAkIwM2S.cjs → remoteSessionClient-PyUAIhwK.cjs} +5 -5
- package/dist/{tools-BVRoGcQH.mjs → reportProgressTool-BvB13EwC.mjs} +67 -10
- package/dist/{tools-mWqsE6ji.cjs → reportProgressTool-D4KB_4cP.cjs} +73 -9
- package/dist/{run-CkKujjn8.cjs → run-BC8jzq_h.cjs} +558 -122
- package/dist/{run-B75qm2I6.mjs → run-O2M8LsWf.mjs} +556 -120
- package/dist/{runClaude-B1T9DLLi.cjs → runClaude-C7jPa8VP.cjs} +93 -26
- package/dist/{runClaude-aBfBweec.mjs → runClaude-DGkr5E7s.mjs} +93 -26
- package/dist/{runClaudeDeps-BGjNGfuZ.cjs → runClaudeDeps-5kzncqME.cjs} +113 -35
- package/dist/{runClaudeDeps-BOrPP4J1.mjs → runClaudeDeps-CX_TxS78.mjs} +116 -37
- package/dist/{runGemini-BuAA_OQb.cjs → runGemini-BfYA4Uqc.cjs} +43 -36
- package/dist/{runGemini-a-V7JE-J.mjs → runGemini-CwmGBH3L.mjs} +43 -36
- package/dist/{runOpenClaw-DUSwXg1A.mjs → runOpenClaw-BYAPYFyL.mjs} +18 -18
- package/dist/{runOpenClaw-BBVffIh9.cjs → runOpenClaw-C72jut7v.cjs} +18 -18
- package/dist/{sandbox-Fd2G5yaq.cjs → sandbox-Bqkp8IT7.cjs} +4 -4
- package/dist/{sandbox-Brb_5wzc.mjs → sandbox-DlVnK1Vi.mjs} +4 -4
- package/dist/{selfCheck-NuJKMInJ.cjs → selfCheck-B4lLZplk.cjs} +34 -34
- package/dist/selfCheck-DYTGBdIO.mjs +84 -0
- package/dist/{send-DEQJiq_x.mjs → send-B5bWW9Tl.mjs} +8 -8
- package/dist/{send-4dgHKC3u.cjs → send-BCwS6n_s.cjs} +8 -8
- package/dist/{server-C6AlUFkw.mjs → server-CEJfRQfj.mjs} +4 -4
- package/dist/{server-DWGcDmHG.cjs → server-CFWZehnC.cjs} +6 -6
- package/dist/{sessionLock-Dm8QyGo4.mjs → sessionLock-AwOYsKT7.mjs} +12 -4
- package/dist/{sessionLock-B1GgaO1q.cjs → sessionLock-LBWNjpHf.cjs} +12 -3
- package/dist/{sessionModeFile-BvOEJ4Fl.cjs → sessionModeFile-CyPuZRIU.cjs} +1 -1
- package/dist/{sessionModeFile-CuNAWCKL.mjs → sessionModeFile-fvFn1JVG.mjs} +1 -1
- package/dist/{sessionOps-DG5MMEp_.mjs → sessionOps-DZRH4-hV.mjs} +4 -4
- package/dist/{sessionOps-JP64uJmc.cjs → sessionOps-DzbZI3Eq.cjs} +4 -4
- package/dist/{sessionScanner-DqSk5Ol_.mjs → sessionScanner-Q_Ei2flB.mjs} +75 -19
- package/dist/{sessionScanner-BBPEgJ5S.cjs → sessionScanner-i-cgwFVw.cjs} +75 -19
- package/dist/{sessions-4isbBAWi.mjs → sessions-DAmjMAZN.mjs} +9 -9
- package/dist/{sessions-DgJuw_i0.cjs → sessions-DYK5hD4T.cjs} +9 -9
- package/dist/{setupOfflineReconnection-_MoZtsro.mjs → setupOfflineReconnection-BfDBxNdo.mjs} +2 -2
- package/dist/{setupOfflineReconnection-CKJKVIUS.cjs → setupOfflineReconnection-C2LO3hSP.cjs} +2 -2
- package/dist/{spawn-BTOG4tTm.mjs → spawn-BmjG5j5Y.mjs} +15 -14
- package/dist/{spawn-CshERWbY.cjs → spawn-GK_sXE8h.cjs} +15 -14
- package/dist/{spawnAgents-Czi2VDzj.mjs → spawnAgents-HDaE3C0-.mjs} +1 -1
- package/dist/{spawnAgents-McixdtV1.cjs → spawnAgents-vglexX9N.cjs} +1 -1
- package/dist/{spawnHappyCLI-Dc4xYm8P.mjs → spawnHappyCLI-B2h0P4b5.mjs} +1 -1
- package/dist/{spawnHappyCLI-Dd5_8Vex.cjs → spawnHappyCLI-J4iEhfyZ.cjs} +1 -1
- package/dist/specialCommands-DisVxagO.mjs +93 -0
- package/dist/specialCommands-DmJMKspE.cjs +96 -0
- package/dist/{startFileWatcher-B0VlG-Fn.mjs → startFileWatcher-CeK1k5gt.mjs} +1 -1
- package/dist/{startFileWatcher-1LedLBY-.cjs → startFileWatcher-xKo8AoYl.cjs} +1 -1
- package/dist/{streamRelay-C0AffuX6.cjs → streamRelay-Ce9sgcOV.cjs} +1 -1
- package/dist/{streamRelay-BzMEEvJU.mjs → streamRelay-Iogsh51a.mjs} +1 -1
- package/dist/{sync-DwUUGGFz.cjs → sync-Bvc-vh6C.cjs} +1 -1
- package/dist/{sync-Dfm6K2te.mjs → sync-CCwYpJMS.mjs} +1 -1
- package/dist/{systemPrompt-D41Zw1a3.mjs → systemPrompt-BNIkP3tR.mjs} +3 -3
- package/dist/{systemPrompt-CB1Ls0AE.cjs → systemPrompt-DwOddbuG.cjs} +3 -3
- package/dist/{teams-D8Ly3i6u.mjs → teams-DRrLBcys.mjs} +7 -7
- package/dist/{teams-NWv2ji16.cjs → teams-GHMCRZOw.cjs} +7 -7
- package/dist/{time-BbzJ7PJQ.cjs → time-BXvtjhe9.cjs} +1 -1
- package/dist/{time-v1Y_qEJp.mjs → time-PG5Dfwdv.mjs} +1 -1
- package/dist/{titleGenerator-cH6IkPRi.cjs → titleGenerator-B07bZA0V.cjs} +2 -2
- package/dist/{titleGenerator-BhoblAQY.mjs → titleGenerator-CIzfpfZW.mjs} +1 -1
- package/dist/{todo-D1hgWV6d.cjs → todo-B0aeoNu3.cjs} +6 -6
- package/dist/{todo-CuNct-fw.mjs → todo-CfL7SBFc.mjs} +6 -6
- package/dist/{tools-jof0Bu54.mjs → tools-D91mq5Ib.mjs} +1 -1
- package/dist/{tools-c2fb0CF5.cjs → tools-DJIANHSh.cjs} +1 -1
- package/dist/transcriptCursor-B7T_gkQ0.mjs +102 -0
- package/dist/transcriptCursor-DcXGLeSc.cjs +106 -0
- package/dist/{uninstall-BB7WYYAk.mjs → uninstall-5xz3Xvhf.mjs} +3 -3
- package/dist/{uninstall-VPH5GfrA.cjs → uninstall-AtzOfdrj.cjs} +3 -3
- package/package.json +7 -7
- package/scripts/terminal_status_forwarder.cjs +89 -0
- package/dist/defaultPermissionMode-BnxJPVHT.mjs +0 -4
- package/dist/defaultPermissionMode-CxmTXUQR.cjs +0 -7
- package/dist/mirrorProtocol-BNLtoWjO.mjs +0 -170
- package/dist/mirrorProtocol-BUtmg1ws.cjs +0 -186
- package/dist/selfCheck-BgwJ3NGS.mjs +0 -84
- package/dist/specialCommands-BSqhYg5X.mjs +0 -52
- package/dist/specialCommands-DSsTeRej.cjs +0 -54
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const PRECHECK_UNSUPPORTED_SERVER_MESSAGE = "This server does not support automation prechecks: it would drop the precheck and run the action every time. Upgrade the server, or create the automation without a precheck.";
|
|
4
|
+
function serverStoresPrecheck(automation) {
|
|
5
|
+
return Object.prototype.hasOwnProperty.call(automation, "precheck");
|
|
6
|
+
}
|
|
7
|
+
async function createAutomationChecked(client, input) {
|
|
8
|
+
if (!input.precheck) return client.create(input);
|
|
9
|
+
const created = await client.create({ ...input, status: "paused" });
|
|
10
|
+
if (!serverStoresPrecheck(created)) {
|
|
11
|
+
const removed = await client.remove(created.id).then(() => true, () => false);
|
|
12
|
+
throw new Error(removed ? PRECHECK_UNSUPPORTED_SERVER_MESSAGE : `${PRECHECK_UNSUPPORTED_SERVER_MESSAGE} The automation "${created.name}" was left paused; delete it.`);
|
|
13
|
+
}
|
|
14
|
+
if (input.status === "paused") return created;
|
|
15
|
+
try {
|
|
16
|
+
return await client.resume(created.id);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
19
|
+
throw new Error(`Automation "${created.name}" (id ${created.id}) was created paused, with its precheck, but could not be resumed: ${reason} Resume it (very-happy auto resume ${created.name}) or delete it.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function updateAutomationChecked(client, id, input) {
|
|
23
|
+
const updated = await client.update(id, input);
|
|
24
|
+
if (input.precheck && !serverStoresPrecheck(updated)) throw new Error(`${PRECHECK_UNSUPPORTED_SERVER_MESSAGE} (Other changes were saved.)`);
|
|
25
|
+
return updated;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.createAutomationChecked = createAutomationChecked;
|
|
29
|
+
exports.updateAutomationChecked = updateAutomationChecked;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const PRECHECK_UNSUPPORTED_SERVER_MESSAGE = "This server does not support automation prechecks: it would drop the precheck and run the action every time. Upgrade the server, or create the automation without a precheck.";
|
|
2
|
+
function serverStoresPrecheck(automation) {
|
|
3
|
+
return Object.prototype.hasOwnProperty.call(automation, "precheck");
|
|
4
|
+
}
|
|
5
|
+
async function createAutomationChecked(client, input) {
|
|
6
|
+
if (!input.precheck) return client.create(input);
|
|
7
|
+
const created = await client.create({ ...input, status: "paused" });
|
|
8
|
+
if (!serverStoresPrecheck(created)) {
|
|
9
|
+
const removed = await client.remove(created.id).then(() => true, () => false);
|
|
10
|
+
throw new Error(removed ? PRECHECK_UNSUPPORTED_SERVER_MESSAGE : `${PRECHECK_UNSUPPORTED_SERVER_MESSAGE} The automation "${created.name}" was left paused; delete it.`);
|
|
11
|
+
}
|
|
12
|
+
if (input.status === "paused") return created;
|
|
13
|
+
try {
|
|
14
|
+
return await client.resume(created.id);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
17
|
+
throw new Error(`Automation "${created.name}" (id ${created.id}) was created paused, with its precheck, but could not be resumed: ${reason} Resume it (very-happy auto resume ${created.name}) or delete it.`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function updateAutomationChecked(client, id, input) {
|
|
21
|
+
const updated = await client.update(id, input);
|
|
22
|
+
if (input.precheck && !serverStoresPrecheck(updated)) throw new Error(`${PRECHECK_UNSUPPORTED_SERVER_MESSAGE} (Other changes were saved.)`);
|
|
23
|
+
return updated;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { createAutomationChecked as c, updateAutomationChecked as u };
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var logger = require('./logger-B_MWPbZz.cjs');
|
|
4
|
+
|
|
5
|
+
const MAX_WINDOWS_PER_PROVIDER = 8;
|
|
6
|
+
function finite(value) {
|
|
7
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
8
|
+
}
|
|
9
|
+
function round2(value) {
|
|
10
|
+
return Math.round(value * 100) / 100;
|
|
11
|
+
}
|
|
12
|
+
const RATE_LIMIT_MAX_RESET_AHEAD_MS = 30 * 24 * 60 * 6e4;
|
|
13
|
+
const RATE_LIMIT_NULL_RESET_MAX_AGE_MS = 7 * 24 * 60 * 6e4;
|
|
14
|
+
const RATE_LIMIT_MAX_USED_PERCENT = 1e3;
|
|
15
|
+
function plausibleReset(resetsAt, now) {
|
|
16
|
+
if (resetsAt === null) return null;
|
|
17
|
+
return resetsAt - now > RATE_LIMIT_MAX_RESET_AHEAD_MS ? null : resetsAt;
|
|
18
|
+
}
|
|
19
|
+
function epochToMs(value, now) {
|
|
20
|
+
const n = finite(value);
|
|
21
|
+
if (n === void 0 || n <= 0) return null;
|
|
22
|
+
return plausibleReset(n > 1e12 ? Math.round(n) : Math.round(n * 1e3), now);
|
|
23
|
+
}
|
|
24
|
+
function plausiblePercent(percent, source) {
|
|
25
|
+
if (percent === void 0 || percent < 0) return void 0;
|
|
26
|
+
if (percent > RATE_LIMIT_MAX_USED_PERCENT) {
|
|
27
|
+
logger.logger.debug(`[rate-limits] dropped ${source}: ${percent}% is outside the plausible range`);
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
return round2(percent);
|
|
31
|
+
}
|
|
32
|
+
function finiteOrLog(value, source) {
|
|
33
|
+
const n = finite(value);
|
|
34
|
+
if (n === void 0 && value !== void 0 && value !== null) {
|
|
35
|
+
logger.logger.debug(`[rate-limits] dropped ${source}: non-finite value`);
|
|
36
|
+
}
|
|
37
|
+
return n;
|
|
38
|
+
}
|
|
39
|
+
const CLAUDE_UNIFIED_KINDS = ["five_hour", "seven_day", "seven_day_overage_included"];
|
|
40
|
+
const CLAUDE_WINDOW_MINUTES = {
|
|
41
|
+
five_hour: 300,
|
|
42
|
+
seven_day: 10080,
|
|
43
|
+
seven_day_opus: 10080,
|
|
44
|
+
seven_day_sonnet: 10080,
|
|
45
|
+
seven_day_overage_included: 10080
|
|
46
|
+
};
|
|
47
|
+
function fromClaudeRateLimitInfo(info, now) {
|
|
48
|
+
if (!info || typeof info !== "object") return null;
|
|
49
|
+
const raw = info;
|
|
50
|
+
const windows = /* @__PURE__ */ new Map();
|
|
51
|
+
const unified = raw.unifiedWindows;
|
|
52
|
+
if (unified && typeof unified === "object") {
|
|
53
|
+
for (const kind of CLAUDE_UNIFIED_KINDS) {
|
|
54
|
+
const w = unified[kind];
|
|
55
|
+
if (!w || typeof w !== "object") continue;
|
|
56
|
+
const utilization = finiteOrLog(w.utilization, `claude ${kind}`);
|
|
57
|
+
const usedPercent = plausiblePercent(utilization === void 0 ? void 0 : utilization * 100, `claude ${kind}`);
|
|
58
|
+
if (usedPercent === void 0) continue;
|
|
59
|
+
windows.set(kind, {
|
|
60
|
+
kind,
|
|
61
|
+
usedPercent,
|
|
62
|
+
resetsAt: epochToMs(w.resetsAt, now),
|
|
63
|
+
windowMinutes: CLAUDE_WINDOW_MINUTES[kind],
|
|
64
|
+
observedAt: now
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const status = typeof raw.status === "string" ? raw.status : void 0;
|
|
69
|
+
const topKind = typeof raw.rateLimitType === "string" ? raw.rateLimitType : void 0;
|
|
70
|
+
if (topKind && topKind !== "overage") {
|
|
71
|
+
const utilization = finiteOrLog(raw.utilization, `claude ${topKind}`);
|
|
72
|
+
const usedPercent = utilization !== void 0 ? plausiblePercent(utilization * 100, `claude ${topKind}`) : status === "rejected" ? 100 : void 0;
|
|
73
|
+
if (usedPercent !== void 0) {
|
|
74
|
+
const prior = windows.get(topKind);
|
|
75
|
+
windows.set(topKind, {
|
|
76
|
+
kind: topKind,
|
|
77
|
+
// The limiting window's own number wins only if it is higher —
|
|
78
|
+
// both describe the same window, the larger is the safer read.
|
|
79
|
+
usedPercent: prior ? Math.max(prior.usedPercent, usedPercent) : usedPercent,
|
|
80
|
+
resetsAt: epochToMs(raw.resetsAt, now) ?? prior?.resetsAt ?? null,
|
|
81
|
+
windowMinutes: CLAUDE_WINDOW_MINUTES[topKind],
|
|
82
|
+
observedAt: now
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (windows.size === 0) return null;
|
|
87
|
+
return {
|
|
88
|
+
provider: "claude",
|
|
89
|
+
observedAt: now,
|
|
90
|
+
...status ? { status } : {},
|
|
91
|
+
windows: [...windows.values()]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function codexKind(windowMinutes, fallback) {
|
|
95
|
+
if (windowMinutes === 300) return "five_hour";
|
|
96
|
+
if (windowMinutes === 10080) return "seven_day";
|
|
97
|
+
if (windowMinutes !== void 0) return `window_${windowMinutes}m`;
|
|
98
|
+
return fallback;
|
|
99
|
+
}
|
|
100
|
+
function fromCodexRateLimits(snapshot, now) {
|
|
101
|
+
if (!snapshot || typeof snapshot !== "object") return null;
|
|
102
|
+
const raw = snapshot;
|
|
103
|
+
const limitId = raw.limitId;
|
|
104
|
+
if (limitId !== void 0 && limitId !== null && limitId !== "codex") return null;
|
|
105
|
+
const windows = [];
|
|
106
|
+
for (const slot of ["primary", "secondary"]) {
|
|
107
|
+
const w = raw[slot];
|
|
108
|
+
if (!w || typeof w !== "object") continue;
|
|
109
|
+
const usedPercent = plausiblePercent(finiteOrLog(w.usedPercent, `codex ${slot}`), `codex ${slot}`);
|
|
110
|
+
if (usedPercent === void 0) continue;
|
|
111
|
+
const windowMinutes = finite(w.windowDurationMins);
|
|
112
|
+
windows.push({
|
|
113
|
+
kind: codexKind(windowMinutes, slot),
|
|
114
|
+
usedPercent,
|
|
115
|
+
resetsAt: epochToMs(w.resetsAt, now),
|
|
116
|
+
...windowMinutes !== void 0 ? { windowMinutes } : {},
|
|
117
|
+
observedAt: now
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (windows.length === 0) return null;
|
|
121
|
+
return { provider: "codex", observedAt: now, windows };
|
|
122
|
+
}
|
|
123
|
+
function sanitizeWindow(value) {
|
|
124
|
+
if (!value || typeof value !== "object") return null;
|
|
125
|
+
const w = value;
|
|
126
|
+
const kind = typeof w.kind === "string" && w.kind.length > 0 && w.kind.length <= 64 ? w.kind : null;
|
|
127
|
+
const usedPercent = finite(w.usedPercent);
|
|
128
|
+
const observedAt = finite(w.observedAt);
|
|
129
|
+
if (!kind || usedPercent === void 0 || usedPercent < 0 || observedAt === void 0) return null;
|
|
130
|
+
const resetsAt = w.resetsAt === null ? null : finite(w.resetsAt) ?? null;
|
|
131
|
+
const windowMinutes = finite(w.windowMinutes);
|
|
132
|
+
return {
|
|
133
|
+
kind,
|
|
134
|
+
usedPercent,
|
|
135
|
+
resetsAt,
|
|
136
|
+
...windowMinutes !== void 0 ? { windowMinutes } : {},
|
|
137
|
+
observedAt
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function sanitizeRateLimitReport(value) {
|
|
141
|
+
if (!value || typeof value !== "object") return null;
|
|
142
|
+
const r = value;
|
|
143
|
+
if (r.provider !== "claude" && r.provider !== "codex") return null;
|
|
144
|
+
const observedAt = finite(r.observedAt);
|
|
145
|
+
if (observedAt === void 0 || !Array.isArray(r.windows)) return null;
|
|
146
|
+
const windows = r.windows.map(sanitizeWindow).filter((w) => w !== null).slice(0, MAX_WINDOWS_PER_PROVIDER);
|
|
147
|
+
if (windows.length === 0) return null;
|
|
148
|
+
return {
|
|
149
|
+
provider: r.provider,
|
|
150
|
+
observedAt,
|
|
151
|
+
...typeof r.status === "string" && r.status.length <= 32 ? { status: r.status } : {},
|
|
152
|
+
windows
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function isExpired(window, now) {
|
|
156
|
+
if (window.resetsAt === null) return now - window.observedAt > RATE_LIMIT_NULL_RESET_MAX_AGE_MS;
|
|
157
|
+
return window.resetsAt <= now;
|
|
158
|
+
}
|
|
159
|
+
function withPlausibleReset(window, now) {
|
|
160
|
+
const resetsAt = plausibleReset(window.resetsAt, now);
|
|
161
|
+
return resetsAt === window.resetsAt ? window : { ...window, resetsAt };
|
|
162
|
+
}
|
|
163
|
+
function keepWindow(window, now) {
|
|
164
|
+
if (window.usedPercent > RATE_LIMIT_MAX_USED_PERCENT) return null;
|
|
165
|
+
const normalized = withPlausibleReset(window, now);
|
|
166
|
+
return isExpired(normalized, now) ? null : normalized;
|
|
167
|
+
}
|
|
168
|
+
function keepWindows(windows, now) {
|
|
169
|
+
return windows.map((w) => keepWindow(w, now)).filter((w) => w !== null);
|
|
170
|
+
}
|
|
171
|
+
function readRateLimitsState(value) {
|
|
172
|
+
if (!value || typeof value !== "object") return null;
|
|
173
|
+
const raw = value;
|
|
174
|
+
if (!raw.providers || typeof raw.providers !== "object") return null;
|
|
175
|
+
const providers = {};
|
|
176
|
+
for (const [name, p] of Object.entries(raw.providers)) {
|
|
177
|
+
if (!p || typeof p !== "object") continue;
|
|
178
|
+
const observedAt = finite(p.observedAt);
|
|
179
|
+
const windowsRaw = p.windows;
|
|
180
|
+
if (observedAt === void 0 || !Array.isArray(windowsRaw)) continue;
|
|
181
|
+
const windows = windowsRaw.map(sanitizeWindow).filter((w) => w !== null);
|
|
182
|
+
const status = p.status;
|
|
183
|
+
providers[name] = { observedAt, ...typeof status === "string" ? { status } : {}, windows };
|
|
184
|
+
}
|
|
185
|
+
return { v: 1, updatedAt: finite(raw.updatedAt) ?? 0, providers };
|
|
186
|
+
}
|
|
187
|
+
function mergeRateLimits(current, report, now) {
|
|
188
|
+
const base = readRateLimitsState(current) ?? { providers: {} };
|
|
189
|
+
const prior = base.providers[report.provider];
|
|
190
|
+
const byKind = /* @__PURE__ */ new Map();
|
|
191
|
+
for (const w of prior?.windows ?? []) byKind.set(w.kind, w);
|
|
192
|
+
for (const w of report.windows) {
|
|
193
|
+
const existing = byKind.get(w.kind);
|
|
194
|
+
if (!existing || w.observedAt >= existing.observedAt) byKind.set(w.kind, w);
|
|
195
|
+
}
|
|
196
|
+
const windows = keepWindows([...byKind.values()], now).slice(0, MAX_WINDOWS_PER_PROVIDER);
|
|
197
|
+
const providers = {};
|
|
198
|
+
for (const [name, p] of Object.entries(base.providers)) {
|
|
199
|
+
if (name === report.provider) continue;
|
|
200
|
+
providers[name] = { ...p, windows: keepWindows(p.windows, now) };
|
|
201
|
+
}
|
|
202
|
+
const newer = !prior || report.observedAt >= prior.observedAt;
|
|
203
|
+
providers[report.provider] = {
|
|
204
|
+
observedAt: newer ? report.observedAt : prior.observedAt,
|
|
205
|
+
...(newer ? report.status : prior?.status) ? { status: newer ? report.status : prior?.status } : {},
|
|
206
|
+
windows
|
|
207
|
+
};
|
|
208
|
+
return { v: 1, updatedAt: now, providers };
|
|
209
|
+
}
|
|
210
|
+
function rateLimitSignature(state) {
|
|
211
|
+
if (!state) return "";
|
|
212
|
+
return Object.keys(state.providers).sort().map((name) => {
|
|
213
|
+
const p = state.providers[name];
|
|
214
|
+
const windows = [...p.windows].sort((a, b) => a.kind.localeCompare(b.kind)).map((w) => `${w.kind}:${Math.round(w.usedPercent)}:${w.resetsAt === null ? "-" : Math.round(w.resetsAt / 6e4)}`).join(",");
|
|
215
|
+
return `${name}[${p.status ?? ""}]{${windows}}`;
|
|
216
|
+
}).join(";");
|
|
217
|
+
}
|
|
218
|
+
function rateLimitReportSignature(report) {
|
|
219
|
+
return rateLimitSignature({ providers: { [report.provider]: report } });
|
|
220
|
+
}
|
|
221
|
+
const CODEX_RATE_LIMIT_READ_MIN_INTERVAL_MS = 10 * 6e4;
|
|
222
|
+
function shouldReadCodexRateLimits(state) {
|
|
223
|
+
if (state.unsupported || state.inFlight) return false;
|
|
224
|
+
return state.lastReadAt === 0 || state.now - state.lastReadAt >= CODEX_RATE_LIMIT_READ_MIN_INTERVAL_MS;
|
|
225
|
+
}
|
|
226
|
+
function isUnsupportedCodexMethodError(error) {
|
|
227
|
+
const message = error instanceof Error ? error.message : typeof error === "string" ? error : "";
|
|
228
|
+
return /\(code=-3260[01]\)/.test(message) || /unknown variant/i.test(message);
|
|
229
|
+
}
|
|
230
|
+
const RATE_LIMIT_OBSERVED_REFRESH_MS = 30 * 6e4;
|
|
231
|
+
function mergeRateLimitReports(current, reports, now) {
|
|
232
|
+
let merged = readRateLimitsState(current);
|
|
233
|
+
for (const report of reports) merged = mergeRateLimits(merged, report, now);
|
|
234
|
+
return merged;
|
|
235
|
+
}
|
|
236
|
+
function planRateLimitWrite(current, reports, now) {
|
|
237
|
+
if (reports.length === 0) return null;
|
|
238
|
+
const before = readRateLimitsState(current);
|
|
239
|
+
const merged = mergeRateLimitReports(current, reports, now);
|
|
240
|
+
if (!merged) return null;
|
|
241
|
+
if (rateLimitSignature(merged) !== rateLimitSignature(before)) return merged;
|
|
242
|
+
for (const report of reports) {
|
|
243
|
+
const prior = before?.providers[report.provider];
|
|
244
|
+
const next = merged.providers[report.provider];
|
|
245
|
+
if (!prior || next && next.observedAt - prior.observedAt >= RATE_LIMIT_OBSERVED_REFRESH_MS) return merged;
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
exports.RATE_LIMIT_OBSERVED_REFRESH_MS = RATE_LIMIT_OBSERVED_REFRESH_MS;
|
|
251
|
+
exports.fromClaudeRateLimitInfo = fromClaudeRateLimitInfo;
|
|
252
|
+
exports.fromCodexRateLimits = fromCodexRateLimits;
|
|
253
|
+
exports.isUnsupportedCodexMethodError = isUnsupportedCodexMethodError;
|
|
254
|
+
exports.mergeRateLimitReports = mergeRateLimitReports;
|
|
255
|
+
exports.planRateLimitWrite = planRateLimitWrite;
|
|
256
|
+
exports.rateLimitReportSignature = rateLimitReportSignature;
|
|
257
|
+
exports.sanitizeRateLimitReport = sanitizeRateLimitReport;
|
|
258
|
+
exports.shouldReadCodexRateLimits = shouldReadCodexRateLimits;
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { l as logger } from './logger-CbBv3q_b.mjs';
|
|
2
|
+
|
|
3
|
+
const MAX_WINDOWS_PER_PROVIDER = 8;
|
|
4
|
+
function finite(value) {
|
|
5
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
6
|
+
}
|
|
7
|
+
function round2(value) {
|
|
8
|
+
return Math.round(value * 100) / 100;
|
|
9
|
+
}
|
|
10
|
+
const RATE_LIMIT_MAX_RESET_AHEAD_MS = 30 * 24 * 60 * 6e4;
|
|
11
|
+
const RATE_LIMIT_NULL_RESET_MAX_AGE_MS = 7 * 24 * 60 * 6e4;
|
|
12
|
+
const RATE_LIMIT_MAX_USED_PERCENT = 1e3;
|
|
13
|
+
function plausibleReset(resetsAt, now) {
|
|
14
|
+
if (resetsAt === null) return null;
|
|
15
|
+
return resetsAt - now > RATE_LIMIT_MAX_RESET_AHEAD_MS ? null : resetsAt;
|
|
16
|
+
}
|
|
17
|
+
function epochToMs(value, now) {
|
|
18
|
+
const n = finite(value);
|
|
19
|
+
if (n === void 0 || n <= 0) return null;
|
|
20
|
+
return plausibleReset(n > 1e12 ? Math.round(n) : Math.round(n * 1e3), now);
|
|
21
|
+
}
|
|
22
|
+
function plausiblePercent(percent, source) {
|
|
23
|
+
if (percent === void 0 || percent < 0) return void 0;
|
|
24
|
+
if (percent > RATE_LIMIT_MAX_USED_PERCENT) {
|
|
25
|
+
logger.debug(`[rate-limits] dropped ${source}: ${percent}% is outside the plausible range`);
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
return round2(percent);
|
|
29
|
+
}
|
|
30
|
+
function finiteOrLog(value, source) {
|
|
31
|
+
const n = finite(value);
|
|
32
|
+
if (n === void 0 && value !== void 0 && value !== null) {
|
|
33
|
+
logger.debug(`[rate-limits] dropped ${source}: non-finite value`);
|
|
34
|
+
}
|
|
35
|
+
return n;
|
|
36
|
+
}
|
|
37
|
+
const CLAUDE_UNIFIED_KINDS = ["five_hour", "seven_day", "seven_day_overage_included"];
|
|
38
|
+
const CLAUDE_WINDOW_MINUTES = {
|
|
39
|
+
five_hour: 300,
|
|
40
|
+
seven_day: 10080,
|
|
41
|
+
seven_day_opus: 10080,
|
|
42
|
+
seven_day_sonnet: 10080,
|
|
43
|
+
seven_day_overage_included: 10080
|
|
44
|
+
};
|
|
45
|
+
function fromClaudeRateLimitInfo(info, now) {
|
|
46
|
+
if (!info || typeof info !== "object") return null;
|
|
47
|
+
const raw = info;
|
|
48
|
+
const windows = /* @__PURE__ */ new Map();
|
|
49
|
+
const unified = raw.unifiedWindows;
|
|
50
|
+
if (unified && typeof unified === "object") {
|
|
51
|
+
for (const kind of CLAUDE_UNIFIED_KINDS) {
|
|
52
|
+
const w = unified[kind];
|
|
53
|
+
if (!w || typeof w !== "object") continue;
|
|
54
|
+
const utilization = finiteOrLog(w.utilization, `claude ${kind}`);
|
|
55
|
+
const usedPercent = plausiblePercent(utilization === void 0 ? void 0 : utilization * 100, `claude ${kind}`);
|
|
56
|
+
if (usedPercent === void 0) continue;
|
|
57
|
+
windows.set(kind, {
|
|
58
|
+
kind,
|
|
59
|
+
usedPercent,
|
|
60
|
+
resetsAt: epochToMs(w.resetsAt, now),
|
|
61
|
+
windowMinutes: CLAUDE_WINDOW_MINUTES[kind],
|
|
62
|
+
observedAt: now
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const status = typeof raw.status === "string" ? raw.status : void 0;
|
|
67
|
+
const topKind = typeof raw.rateLimitType === "string" ? raw.rateLimitType : void 0;
|
|
68
|
+
if (topKind && topKind !== "overage") {
|
|
69
|
+
const utilization = finiteOrLog(raw.utilization, `claude ${topKind}`);
|
|
70
|
+
const usedPercent = utilization !== void 0 ? plausiblePercent(utilization * 100, `claude ${topKind}`) : status === "rejected" ? 100 : void 0;
|
|
71
|
+
if (usedPercent !== void 0) {
|
|
72
|
+
const prior = windows.get(topKind);
|
|
73
|
+
windows.set(topKind, {
|
|
74
|
+
kind: topKind,
|
|
75
|
+
// The limiting window's own number wins only if it is higher —
|
|
76
|
+
// both describe the same window, the larger is the safer read.
|
|
77
|
+
usedPercent: prior ? Math.max(prior.usedPercent, usedPercent) : usedPercent,
|
|
78
|
+
resetsAt: epochToMs(raw.resetsAt, now) ?? prior?.resetsAt ?? null,
|
|
79
|
+
windowMinutes: CLAUDE_WINDOW_MINUTES[topKind],
|
|
80
|
+
observedAt: now
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (windows.size === 0) return null;
|
|
85
|
+
return {
|
|
86
|
+
provider: "claude",
|
|
87
|
+
observedAt: now,
|
|
88
|
+
...status ? { status } : {},
|
|
89
|
+
windows: [...windows.values()]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function codexKind(windowMinutes, fallback) {
|
|
93
|
+
if (windowMinutes === 300) return "five_hour";
|
|
94
|
+
if (windowMinutes === 10080) return "seven_day";
|
|
95
|
+
if (windowMinutes !== void 0) return `window_${windowMinutes}m`;
|
|
96
|
+
return fallback;
|
|
97
|
+
}
|
|
98
|
+
function fromCodexRateLimits(snapshot, now) {
|
|
99
|
+
if (!snapshot || typeof snapshot !== "object") return null;
|
|
100
|
+
const raw = snapshot;
|
|
101
|
+
const limitId = raw.limitId;
|
|
102
|
+
if (limitId !== void 0 && limitId !== null && limitId !== "codex") return null;
|
|
103
|
+
const windows = [];
|
|
104
|
+
for (const slot of ["primary", "secondary"]) {
|
|
105
|
+
const w = raw[slot];
|
|
106
|
+
if (!w || typeof w !== "object") continue;
|
|
107
|
+
const usedPercent = plausiblePercent(finiteOrLog(w.usedPercent, `codex ${slot}`), `codex ${slot}`);
|
|
108
|
+
if (usedPercent === void 0) continue;
|
|
109
|
+
const windowMinutes = finite(w.windowDurationMins);
|
|
110
|
+
windows.push({
|
|
111
|
+
kind: codexKind(windowMinutes, slot),
|
|
112
|
+
usedPercent,
|
|
113
|
+
resetsAt: epochToMs(w.resetsAt, now),
|
|
114
|
+
...windowMinutes !== void 0 ? { windowMinutes } : {},
|
|
115
|
+
observedAt: now
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (windows.length === 0) return null;
|
|
119
|
+
return { provider: "codex", observedAt: now, windows };
|
|
120
|
+
}
|
|
121
|
+
function sanitizeWindow(value) {
|
|
122
|
+
if (!value || typeof value !== "object") return null;
|
|
123
|
+
const w = value;
|
|
124
|
+
const kind = typeof w.kind === "string" && w.kind.length > 0 && w.kind.length <= 64 ? w.kind : null;
|
|
125
|
+
const usedPercent = finite(w.usedPercent);
|
|
126
|
+
const observedAt = finite(w.observedAt);
|
|
127
|
+
if (!kind || usedPercent === void 0 || usedPercent < 0 || observedAt === void 0) return null;
|
|
128
|
+
const resetsAt = w.resetsAt === null ? null : finite(w.resetsAt) ?? null;
|
|
129
|
+
const windowMinutes = finite(w.windowMinutes);
|
|
130
|
+
return {
|
|
131
|
+
kind,
|
|
132
|
+
usedPercent,
|
|
133
|
+
resetsAt,
|
|
134
|
+
...windowMinutes !== void 0 ? { windowMinutes } : {},
|
|
135
|
+
observedAt
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function sanitizeRateLimitReport(value) {
|
|
139
|
+
if (!value || typeof value !== "object") return null;
|
|
140
|
+
const r = value;
|
|
141
|
+
if (r.provider !== "claude" && r.provider !== "codex") return null;
|
|
142
|
+
const observedAt = finite(r.observedAt);
|
|
143
|
+
if (observedAt === void 0 || !Array.isArray(r.windows)) return null;
|
|
144
|
+
const windows = r.windows.map(sanitizeWindow).filter((w) => w !== null).slice(0, MAX_WINDOWS_PER_PROVIDER);
|
|
145
|
+
if (windows.length === 0) return null;
|
|
146
|
+
return {
|
|
147
|
+
provider: r.provider,
|
|
148
|
+
observedAt,
|
|
149
|
+
...typeof r.status === "string" && r.status.length <= 32 ? { status: r.status } : {},
|
|
150
|
+
windows
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function isExpired(window, now) {
|
|
154
|
+
if (window.resetsAt === null) return now - window.observedAt > RATE_LIMIT_NULL_RESET_MAX_AGE_MS;
|
|
155
|
+
return window.resetsAt <= now;
|
|
156
|
+
}
|
|
157
|
+
function withPlausibleReset(window, now) {
|
|
158
|
+
const resetsAt = plausibleReset(window.resetsAt, now);
|
|
159
|
+
return resetsAt === window.resetsAt ? window : { ...window, resetsAt };
|
|
160
|
+
}
|
|
161
|
+
function keepWindow(window, now) {
|
|
162
|
+
if (window.usedPercent > RATE_LIMIT_MAX_USED_PERCENT) return null;
|
|
163
|
+
const normalized = withPlausibleReset(window, now);
|
|
164
|
+
return isExpired(normalized, now) ? null : normalized;
|
|
165
|
+
}
|
|
166
|
+
function keepWindows(windows, now) {
|
|
167
|
+
return windows.map((w) => keepWindow(w, now)).filter((w) => w !== null);
|
|
168
|
+
}
|
|
169
|
+
function readRateLimitsState(value) {
|
|
170
|
+
if (!value || typeof value !== "object") return null;
|
|
171
|
+
const raw = value;
|
|
172
|
+
if (!raw.providers || typeof raw.providers !== "object") return null;
|
|
173
|
+
const providers = {};
|
|
174
|
+
for (const [name, p] of Object.entries(raw.providers)) {
|
|
175
|
+
if (!p || typeof p !== "object") continue;
|
|
176
|
+
const observedAt = finite(p.observedAt);
|
|
177
|
+
const windowsRaw = p.windows;
|
|
178
|
+
if (observedAt === void 0 || !Array.isArray(windowsRaw)) continue;
|
|
179
|
+
const windows = windowsRaw.map(sanitizeWindow).filter((w) => w !== null);
|
|
180
|
+
const status = p.status;
|
|
181
|
+
providers[name] = { observedAt, ...typeof status === "string" ? { status } : {}, windows };
|
|
182
|
+
}
|
|
183
|
+
return { v: 1, updatedAt: finite(raw.updatedAt) ?? 0, providers };
|
|
184
|
+
}
|
|
185
|
+
function mergeRateLimits(current, report, now) {
|
|
186
|
+
const base = readRateLimitsState(current) ?? { providers: {} };
|
|
187
|
+
const prior = base.providers[report.provider];
|
|
188
|
+
const byKind = /* @__PURE__ */ new Map();
|
|
189
|
+
for (const w of prior?.windows ?? []) byKind.set(w.kind, w);
|
|
190
|
+
for (const w of report.windows) {
|
|
191
|
+
const existing = byKind.get(w.kind);
|
|
192
|
+
if (!existing || w.observedAt >= existing.observedAt) byKind.set(w.kind, w);
|
|
193
|
+
}
|
|
194
|
+
const windows = keepWindows([...byKind.values()], now).slice(0, MAX_WINDOWS_PER_PROVIDER);
|
|
195
|
+
const providers = {};
|
|
196
|
+
for (const [name, p] of Object.entries(base.providers)) {
|
|
197
|
+
if (name === report.provider) continue;
|
|
198
|
+
providers[name] = { ...p, windows: keepWindows(p.windows, now) };
|
|
199
|
+
}
|
|
200
|
+
const newer = !prior || report.observedAt >= prior.observedAt;
|
|
201
|
+
providers[report.provider] = {
|
|
202
|
+
observedAt: newer ? report.observedAt : prior.observedAt,
|
|
203
|
+
...(newer ? report.status : prior?.status) ? { status: newer ? report.status : prior?.status } : {},
|
|
204
|
+
windows
|
|
205
|
+
};
|
|
206
|
+
return { v: 1, updatedAt: now, providers };
|
|
207
|
+
}
|
|
208
|
+
function rateLimitSignature(state) {
|
|
209
|
+
if (!state) return "";
|
|
210
|
+
return Object.keys(state.providers).sort().map((name) => {
|
|
211
|
+
const p = state.providers[name];
|
|
212
|
+
const windows = [...p.windows].sort((a, b) => a.kind.localeCompare(b.kind)).map((w) => `${w.kind}:${Math.round(w.usedPercent)}:${w.resetsAt === null ? "-" : Math.round(w.resetsAt / 6e4)}`).join(",");
|
|
213
|
+
return `${name}[${p.status ?? ""}]{${windows}}`;
|
|
214
|
+
}).join(";");
|
|
215
|
+
}
|
|
216
|
+
function rateLimitReportSignature(report) {
|
|
217
|
+
return rateLimitSignature({ providers: { [report.provider]: report } });
|
|
218
|
+
}
|
|
219
|
+
const CODEX_RATE_LIMIT_READ_MIN_INTERVAL_MS = 10 * 6e4;
|
|
220
|
+
function shouldReadCodexRateLimits(state) {
|
|
221
|
+
if (state.unsupported || state.inFlight) return false;
|
|
222
|
+
return state.lastReadAt === 0 || state.now - state.lastReadAt >= CODEX_RATE_LIMIT_READ_MIN_INTERVAL_MS;
|
|
223
|
+
}
|
|
224
|
+
function isUnsupportedCodexMethodError(error) {
|
|
225
|
+
const message = error instanceof Error ? error.message : typeof error === "string" ? error : "";
|
|
226
|
+
return /\(code=-3260[01]\)/.test(message) || /unknown variant/i.test(message);
|
|
227
|
+
}
|
|
228
|
+
const RATE_LIMIT_OBSERVED_REFRESH_MS = 30 * 6e4;
|
|
229
|
+
function mergeRateLimitReports(current, reports, now) {
|
|
230
|
+
let merged = readRateLimitsState(current);
|
|
231
|
+
for (const report of reports) merged = mergeRateLimits(merged, report, now);
|
|
232
|
+
return merged;
|
|
233
|
+
}
|
|
234
|
+
function planRateLimitWrite(current, reports, now) {
|
|
235
|
+
if (reports.length === 0) return null;
|
|
236
|
+
const before = readRateLimitsState(current);
|
|
237
|
+
const merged = mergeRateLimitReports(current, reports, now);
|
|
238
|
+
if (!merged) return null;
|
|
239
|
+
if (rateLimitSignature(merged) !== rateLimitSignature(before)) return merged;
|
|
240
|
+
for (const report of reports) {
|
|
241
|
+
const prior = before?.providers[report.provider];
|
|
242
|
+
const next = merged.providers[report.provider];
|
|
243
|
+
if (!prior || next && next.observedAt - prior.observedAt >= RATE_LIMIT_OBSERVED_REFRESH_MS) return merged;
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export { RATE_LIMIT_OBSERVED_REFRESH_MS as R, fromClaudeRateLimitInfo as a, sanitizeRateLimitReport as b, fromCodexRateLimits as f, isUnsupportedCodexMethodError as i, mergeRateLimitReports as m, planRateLimitWrite as p, rateLimitReportSignature as r, shouldReadCodexRateLimits as s };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as logger } from './logger-
|
|
1
|
+
import { l as logger } from './logger-CbBv3q_b.mjs';
|
|
2
2
|
import { spawn as spawn$1, exec } from 'child_process';
|
|
3
3
|
import { promisify } from 'util';
|
|
4
4
|
import { mkdir, writeFile, appendFile, stat, rename, unlink, readdir, readFile } from 'fs/promises';
|
|
@@ -7,7 +7,7 @@ import { resolve, join, sep } from 'path';
|
|
|
7
7
|
import { spawn } from 'cross-spawn';
|
|
8
8
|
import { p as projectPath } from './projectPath-BTBIMB57.mjs';
|
|
9
9
|
import { platform } from 'os';
|
|
10
|
-
import { c as configuration } from './configuration-
|
|
10
|
+
import { c as configuration } from './configuration-WspKd2C2.mjs';
|
|
11
11
|
|
|
12
12
|
function run$1(args, options) {
|
|
13
13
|
const RUNNER_PATH = resolve(join(projectPath(), "scripts", "ripgrep_launcher.cjs"));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var logger = require('./logger-
|
|
3
|
+
var logger = require('./logger-B_MWPbZz.cjs');
|
|
4
4
|
var child_process = require('child_process');
|
|
5
5
|
var util = require('util');
|
|
6
6
|
var fs = require('fs/promises');
|
|
@@ -9,7 +9,7 @@ var path = require('path');
|
|
|
9
9
|
var spawn = require('cross-spawn');
|
|
10
10
|
var projectPath = require('./projectPath-ChLhdOyt.cjs');
|
|
11
11
|
var os = require('os');
|
|
12
|
-
var configuration = require('./configuration-
|
|
12
|
+
var configuration = require('./configuration-C3piBtxY.cjs');
|
|
13
13
|
|
|
14
14
|
function run$1(args, options) {
|
|
15
15
|
const RUNNER_PATH = path.resolve(path.join(projectPath.projectPath(), "scripts", "ripgrep_launcher.cjs"));
|
package/dist/{registerKillSessionHandler-Czz0tdki.mjs → registerKillSessionHandler-BJMHJHXe.mjs}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { l as logger } from './logger-
|
|
1
|
+
import { l as logger } from './logger-CbBv3q_b.mjs';
|
|
2
2
|
import 'axios';
|
|
3
3
|
import 'node:events';
|
|
4
4
|
import 'socket.io-client';
|
|
5
|
-
import './attachmentLimits-
|
|
5
|
+
import './attachmentLimits-CxG3T18E.mjs';
|
|
6
6
|
import 'node:crypto';
|
|
7
7
|
import 'tweetnacl';
|
|
8
|
-
import './configuration-
|
|
9
|
-
import './index-
|
|
10
|
-
import './registerCommonHandlers-
|
|
8
|
+
import './configuration-WspKd2C2.mjs';
|
|
9
|
+
import './index-B0HEEYGh.mjs';
|
|
10
|
+
import './registerCommonHandlers-B0PVff2U.mjs';
|
|
11
11
|
import 'os';
|
|
12
12
|
import 'child_process';
|
|
13
13
|
import '@paralleldrive/cuid2';
|
|
14
|
-
import './persistence-
|
|
14
|
+
import './persistence-ON0zpHfb.mjs';
|
|
15
15
|
import 'chalk';
|
|
16
16
|
import './types-CkqAACXx.mjs';
|
|
17
17
|
|
|
@@ -342,10 +342,15 @@ function registerKillSessionHandler(rpcHandlerManager, killThisHappy, archiveEve
|
|
|
342
342
|
terminationStarted = true;
|
|
343
343
|
void killThisHappy();
|
|
344
344
|
};
|
|
345
|
+
const signalOnce = () => {
|
|
346
|
+
if (terminationStarted) return;
|
|
347
|
+
terminationStarted = true;
|
|
348
|
+
void (options?.onSignal ?? killThisHappy)();
|
|
349
|
+
};
|
|
345
350
|
archiveEvents.on("archived", terminateOnce);
|
|
346
351
|
if (options?.processSignals) {
|
|
347
|
-
process.on("SIGTERM",
|
|
348
|
-
process.on("SIGINT",
|
|
352
|
+
process.on("SIGTERM", signalOnce);
|
|
353
|
+
process.on("SIGINT", signalOnce);
|
|
349
354
|
}
|
|
350
355
|
rpcHandlerManager.registerHandler("killSession", async () => {
|
|
351
356
|
logger.debug("Kill session request received");
|
|
@@ -358,8 +363,8 @@ function registerKillSessionHandler(rpcHandlerManager, killThisHappy, archiveEve
|
|
|
358
363
|
return () => {
|
|
359
364
|
archiveEvents.off?.("archived", terminateOnce);
|
|
360
365
|
if (options?.processSignals) {
|
|
361
|
-
process.off("SIGTERM",
|
|
362
|
-
process.off("SIGINT",
|
|
366
|
+
process.off("SIGTERM", signalOnce);
|
|
367
|
+
process.off("SIGINT", signalOnce);
|
|
363
368
|
}
|
|
364
369
|
};
|
|
365
370
|
}
|