@pushary/agent-hooks 1.9.158 → 1.9.162

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 (146) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +1 -0
  3. package/dist/{api-MRFKFDVV.js → api-7NPCSUGY.js} +17 -13
  4. package/dist/bin/pushary-audit.js +7 -7
  5. package/dist/bin/pushary-bell-hook.js +31 -31
  6. package/dist/bin/pushary-bell.js +16 -16
  7. package/dist/bin/pushary-calls.d.ts +1 -0
  8. package/dist/bin/pushary-calls.js +287 -0
  9. package/dist/bin/pushary-claude.js +37 -37
  10. package/dist/bin/pushary-clean.js +47 -45
  11. package/dist/bin/pushary-codex-bridge.js +27 -27
  12. package/dist/bin/pushary-codex-hook.js +197 -60
  13. package/dist/bin/pushary-codex-session.js +8 -8
  14. package/dist/bin/pushary-codex.js +19 -19
  15. package/dist/bin/pushary-connect.js +41 -40
  16. package/dist/bin/pushary-cowork.js +6 -6
  17. package/dist/bin/pushary-daemon.js +52 -51
  18. package/dist/bin/pushary-disconnect.js +39 -37
  19. package/dist/bin/pushary-display-hook.js +20 -1
  20. package/dist/bin/pushary-doctor.js +61 -59
  21. package/dist/bin/pushary-elicitation-hook.js +32 -32
  22. package/dist/bin/pushary-gemini-bridge.js +19 -19
  23. package/dist/bin/pushary-gemini-hook.js +36 -36
  24. package/dist/bin/pushary-hook.js +39 -38
  25. package/dist/bin/pushary-login.js +28 -28
  26. package/dist/bin/pushary-logout.js +34 -33
  27. package/dist/bin/pushary-mcp.js +15 -15
  28. package/dist/bin/pushary-mode.js +21 -21
  29. package/dist/bin/pushary-notification-hook.js +30 -30
  30. package/dist/bin/pushary-opencode-hook.js +399 -45
  31. package/dist/bin/pushary-permission-denied-hook.js +39 -38
  32. package/dist/bin/pushary-permission-hook.js +39 -38
  33. package/dist/bin/pushary-post-hook.js +31 -31
  34. package/dist/bin/pushary-prompt-hook.js +30 -30
  35. package/dist/bin/pushary-session-end-hook.js +30 -30
  36. package/dist/bin/pushary-session-start-hook.js +41 -40
  37. package/dist/bin/pushary-setup.js +73 -72
  38. package/dist/bin/pushary-stats.js +6 -6
  39. package/dist/bin/pushary-status.js +40 -39
  40. package/dist/bin/pushary-stop-hook.js +30 -30
  41. package/dist/bin/pushary-stopfailure-hook.js +30 -30
  42. package/dist/bin/pushary-suggestions.js +21 -21
  43. package/dist/bin/pushary-transcript-register.js +21 -21
  44. package/dist/bin/pushary-transcripts.js +32 -32
  45. package/dist/bin/pushary-upgrade.js +50 -49
  46. package/dist/bin/pushary-wait.js +23 -23
  47. package/dist/bin/pushary.js +10 -9
  48. package/dist/{chunk-RRVFN432.js → chunk-2H7SDIM7.js} +1 -1
  49. package/dist/{chunk-DHI3X5WK.js → chunk-44DRCGP2.js} +2 -2
  50. package/dist/chunk-4IBUBMMP.js +885 -0
  51. package/dist/{chunk-RL5JLDRE.js → chunk-4U3GYVIW.js} +2 -2
  52. package/dist/{chunk-NW63PGKF.js → chunk-53IBMDX2.js} +12 -7
  53. package/dist/{chunk-XNJ2HOEL.js → chunk-5TU26542.js} +3 -3
  54. package/dist/{chunk-UVWKMFLQ.js → chunk-5ZS73ZLX.js} +2 -2
  55. package/dist/{chunk-4SN4FHFZ.js → chunk-644AKJMN.js} +2 -2
  56. package/dist/{chunk-TZJR5ESF.js → chunk-6QQUGYH6.js} +7 -7
  57. package/dist/{chunk-4B5K6YIP.js → chunk-72SYV43F.js} +1 -1
  58. package/dist/{chunk-JKRQL2BL.js → chunk-A5DXHJVS.js} +5 -5
  59. package/dist/{chunk-K3OCYJPK.js → chunk-AP26EU5H.js} +3 -3
  60. package/dist/{chunk-MLPPQ556.js → chunk-AQKMKVAD.js} +13 -13
  61. package/dist/{chunk-N5SSADNW.js → chunk-BHT76IIB.js} +4 -4
  62. package/dist/{chunk-TMWXWBFP.js → chunk-BMOGTNLK.js} +6 -6
  63. package/dist/{chunk-SNQOEDZ2.js → chunk-CSDB5VTI.js} +1 -1
  64. package/dist/{chunk-YPFOTFEG.js → chunk-CWH4LBUW.js} +1 -1
  65. package/dist/{chunk-FTTSQAF4.js → chunk-DAMTDSAE.js} +1 -1
  66. package/dist/{chunk-MHYX5Q3F.js → chunk-DSWUG4NV.js} +1 -1
  67. package/dist/{chunk-K3I2NMEF.js → chunk-EFKJCBWA.js} +8 -8
  68. package/dist/{chunk-CIAJ55EQ.js → chunk-EKELMI3A.js} +42 -34
  69. package/dist/{chunk-EGBI4GRS.js → chunk-EPQTCF6A.js} +2 -2
  70. package/dist/{chunk-4WL2MINE.js → chunk-FIR2MGSB.js} +1 -1
  71. package/dist/{chunk-N2LWKWNY.js → chunk-G5IL6C6S.js} +3 -3
  72. package/dist/{chunk-IKC33YKC.js → chunk-G6M6YJK4.js} +5 -2
  73. package/dist/{chunk-SZMDRBNK.js → chunk-GJOHGES6.js} +2 -2
  74. package/dist/{chunk-TPLTB256.js → chunk-H7OY4AAT.js} +4 -4
  75. package/dist/{chunk-IVOELLUK.js → chunk-HAOYL5JP.js} +39 -8
  76. package/dist/{chunk-Q7WCDUFV.js → chunk-I35XT5YY.js} +6 -6
  77. package/dist/{chunk-AOP55JR2.js → chunk-I5ANEYUK.js} +14 -3
  78. package/dist/{chunk-TKBCLK4B.js → chunk-I5HCOOAA.js} +5 -5
  79. package/dist/{chunk-IIK3CZXJ.js → chunk-IUXXEM4Q.js} +8 -7
  80. package/dist/{chunk-FGVBFDNV.js → chunk-J6KDUXJF.js} +1 -1
  81. package/dist/{chunk-XHCX6DOY.js → chunk-JCTS7COD.js} +5 -5
  82. package/dist/{chunk-AGYD6XNI.js → chunk-L3LFCZ5D.js} +3 -3
  83. package/dist/{chunk-3QU4WXAH.js → chunk-L44II2WD.js} +5 -5
  84. package/dist/{chunk-PBPQRJ2T.js → chunk-L6BMVCQQ.js} +5 -5
  85. package/dist/{chunk-LVZBLKAU.js → chunk-L6NG6EZS.js} +1 -1
  86. package/dist/{chunk-EHRWEXRN.js → chunk-LGR7WXI5.js} +2 -2
  87. package/dist/{chunk-2MPT7YQK.js → chunk-LQDIOUVU.js} +5 -3
  88. package/dist/{chunk-XSIZKQ2C.js → chunk-LVRFOGQY.js} +11 -11
  89. package/dist/{chunk-HA2SRYYP.js → chunk-M2ZGNZRS.js} +94 -0
  90. package/dist/{chunk-ZYDE6QRW.js → chunk-M74WT5NA.js} +3 -3
  91. package/dist/chunk-NX3Y36VY.js +242 -0
  92. package/dist/{chunk-ANQBLZAE.js → chunk-OH2WAG47.js} +1 -1
  93. package/dist/{chunk-GTYVNVBZ.js → chunk-P4KAYIMX.js} +4 -4
  94. package/dist/{chunk-4I2SHNEU.js → chunk-PIIKLAFY.js} +3 -3
  95. package/dist/{chunk-J7HSUQK2.js → chunk-QKNHNDOY.js} +3 -3
  96. package/dist/{chunk-ALQWZCUT.js → chunk-RKURAOFK.js} +4 -4
  97. package/dist/{chunk-TYBVQ33X.js → chunk-RUAGEPUJ.js} +6 -6
  98. package/dist/{chunk-IOKJJ2SY.js → chunk-SFYX32FX.js} +4 -4
  99. package/dist/{chunk-OCWXE4PR.js → chunk-SKA3U7QI.js} +11 -9
  100. package/dist/{chunk-X254TRBU.js → chunk-SQ4RPZ6O.js} +4 -4
  101. package/dist/chunk-SRSXZINE.js +18 -0
  102. package/dist/{chunk-CAMFNSJS.js → chunk-SVVZFXDX.js} +6 -6
  103. package/dist/{chunk-QVVBU2JU.js → chunk-SVWCMYR7.js} +24 -9
  104. package/dist/{chunk-MTITL2IG.js → chunk-TMDCIVZ2.js} +5 -5
  105. package/dist/{chunk-B3BOAYRO.js → chunk-TUXX7TKR.js} +3 -3
  106. package/dist/{chunk-CSZWWPNS.js → chunk-U4LHE5DH.js} +1 -1
  107. package/dist/{chunk-3UNZ7HRN.js → chunk-UBY7NJCU.js} +20 -18
  108. package/dist/{chunk-ORQ7THNZ.js → chunk-UPCIKGWA.js} +1 -1
  109. package/dist/{chunk-WIIMW5YO.js → chunk-UQTQ6HPO.js} +2 -0
  110. package/dist/{chunk-V36P4KS4.js → chunk-V3TWYF32.js} +1 -1
  111. package/dist/{chunk-N3CFEMLS.js → chunk-VGLIGBAJ.js} +6 -6
  112. package/dist/{chunk-PND5IGC7.js → chunk-VUGF2OC7.js} +6 -6
  113. package/dist/{chunk-APCJZFTJ.js → chunk-W3FE7GTH.js} +1 -1
  114. package/dist/{chunk-GHHVXARK.js → chunk-WCWWO5QL.js} +1 -1
  115. package/dist/{chunk-TSR3FPGL.js → chunk-WIFMTEQI.js} +1 -1
  116. package/dist/{chunk-AMIUB22C.js → chunk-WWSR5LMP.js} +1 -1
  117. package/dist/{chunk-CCKY3JDB.js → chunk-X5QSIMXA.js} +4 -4
  118. package/dist/{chunk-T3PZQNIK.js → chunk-XIICM4TX.js} +2 -2
  119. package/dist/{chunk-C6PAIHLP.js → chunk-XOSSXRIR.js} +10 -10
  120. package/dist/{chunk-QP3TCKRZ.js → chunk-Y3ELKLNH.js} +18 -16
  121. package/dist/{chunk-H6CL3T2S.js → chunk-Y6ILCLKE.js} +1 -1
  122. package/dist/{chunk-UDLWNOXX.js → chunk-YEVRMDG7.js} +2 -2
  123. package/dist/{chunk-CS4Z44F5.js → chunk-YH6EHCKQ.js} +87 -8
  124. package/dist/{chunk-2L52USKM.js → chunk-YPG3RXWO.js} +3 -3
  125. package/dist/{chunk-AZZNHW3R.js → chunk-YUF3AYAP.js} +9 -6
  126. package/dist/{chunk-4NHQAMSK.js → chunk-Z23SHFIC.js} +4 -4
  127. package/dist/{chunk-6GGK3T24.js → chunk-ZC42UG7B.js} +5 -5
  128. package/dist/{chunk-UPI3JDHZ.js → chunk-ZT55PJSW.js} +3 -3
  129. package/dist/{chunk-PI3BOI3A.js → chunk-ZWNFP4HZ.js} +1 -1
  130. package/dist/{codex-app-cards-switch-CXXDGH7R.js → codex-app-cards-switch-PJEY3EU5.js} +14 -14
  131. package/dist/{codex-card-routing-WP4IHJFN.js → codex-card-routing-MNAMCRPO.js} +2 -2
  132. package/dist/{codex-desktop-launch-EN7ACHC6.js → codex-desktop-launch-AUNDRYOL.js} +1 -1
  133. package/dist/{codex-session-launch-7BV4VTJW.js → codex-session-launch-IZNSTT7N.js} +23 -23
  134. package/dist/{config-SZMMBOJV.js → config-LG2RJO37.js} +4 -4
  135. package/dist/{global-upgrade-I5J6BDHA.js → global-upgrade-QE5Q3BYW.js} +11 -11
  136. package/dist/{identity-GLJNTNHW.js → identity-3BT6LWOP.js} +5 -5
  137. package/dist/{live-capabilities-AYO7FOHS.js → live-capabilities-IKTQBLVH.js} +5 -5
  138. package/dist/{paths-NRBEF3T2.js → paths-VEUTZJOY.js} +4 -4
  139. package/dist/reapply-BC2AF55M.js +69 -0
  140. package/dist/src/index.js +39 -38
  141. package/dist/{upgrade-lock-H6SU7MJR.js → upgrade-lock-NUGEPR75.js} +5 -5
  142. package/dist/usage-TEB5CX2Y.js +11 -0
  143. package/package.json +2 -1
  144. package/dist/chunk-GLDSXDRV.js +0 -593
  145. package/dist/reapply-J2QUV7J2.js +0 -68
  146. package/dist/usage-MY3DIFBG.js +0 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.9.162
4
+
5
+ - Codex: a batch of parallel calls no longer gets calls turned away unasked. Codex can send many calls at once, and Pushary allows eight open questions per session. Before, every call past the eighth was refused at once, and Codex was told nobody was asked and the call did not run. Now such a call waits for a free place: 5 seconds after each refusal it checks your rules and asks again, for at most 30 seconds and at most one phone window, and only while a whole phone window still fits in the time Codex gives the hook. A place frees as soon as someone answers one of the open questions, or when one of them runs out of time. Once the call is asked, it follows your rule like any other question, including a rule that approves when nobody answers. If no place frees in time, the call is refused as before, and never approved.
6
+ - Codex: one tap can clear the rest of a burst. While a Codex call waits for your phone, Pushary checks your rules again, first after 4 seconds and then less often. If a rule now covers the call, for example after you tap "Allow Bash for this session" on another card from the same batch, the call runs and its question is withdrawn from your phone. An answer or a stop that arrives at the same moment wins, and a question that cannot be withdrawn refuses the call. If a deny rule or a Stop now applies, the call is refused and its question withdrawn. Risky commands, calls outside an agreed scope and calls no rule covers keep waiting as before. Only Codex `PreToolUse` changes; other agents and Codex's own confirmation are unchanged.
7
+
8
+ ## 1.9.161
9
+
10
+ - `pushary calls`: set up phone calls from the terminal. `pushary calls on` asks for your mobile number and first name, places the test call, waits for you to confirm the number on it, asks you to agree to the calls, and turns them on. `pushary calls off` turns them off, and `pushary calls` shows whether they are on, the number they ring and the minutes left. `--number`, `--name` and `--yes` answer the questions for a terminal nobody is watching; without `--yes` there, nothing is changed. It uses the key setup saved, and whenever a key sets a new number your phone and email get a note saying which number calls now ring. Setup's list of useful commands now names it.
11
+
12
+ ## 1.9.160
13
+
14
+ - OpenCode: questions ask in OpenCode's own prompt again, and the same question also reaches your phone and the Mac notch. 1.9.156 sent every question through `ask_user`, which took away OpenCode's prompt, could not be interrupted from OpenCode while it waited, and gave the phone only the offered options. Now the plugin watches the form OpenCode's `question` tool raises, and only that form, and asks your phone without holding the prompt. Answer in either place and the first answer wins. The phone question stays open for as long as OpenCode's prompt does, so you can answer after an hour away; after the first ten minutes Pushary checks for your answer every thirty seconds. On the phone a choice shows each option's description and an Other box for a reply of your own when OpenCode takes a typed answer; a multi-select, a free answer and a yes/no work too. A phone answer replies to OpenCode's prompt through OpenCode's own reply route, so the model gets it exactly as if you had answered in the terminal. Pushary asks your phone only when it has checked that route first: on an OpenCode 2 server it cannot reply to, such as a standalone `opencode serve`, the question stays in OpenCode only. If OpenCode refuses the answer anyway, your phone is told to answer it in OpenCode; an answer that lost the race to one given in OpenCode sends nothing. When Pushary cannot confirm that route, it sends one notification, `OpenCode is asking: <question> Answer it in OpenCode.`, so you know to come back, and it follows the kill switch and Terminal mode as a question would. A Pushary outage or a question cancelled on the Pushary side leaves OpenCode's prompt open; only the kill switch or your own stop dismisses it. Answering, dismissing or interrupting in OpenCode, the turn ending or failing, OpenCode unloading the plugin and OpenCode exiting each withdraw the phone question. The kill switch dismisses the question and ends the step; Terminal mode leaves it in OpenCode; Notify-only sends a notification and leaves it in OpenCode; without a key nothing changes. A question call with several questions, a number field and an MCP server's question stay in OpenCode only, so the instructions now ask the model to put one question in each call. The `AGENTS.md` block tells OpenCode to ask with its own `question` tool and to use `ask_user` only when it has no question tool, naming `tools.pushary.ask_user(...)` inside `execute` for OpenCode 2 and `pushary_ask_user` for OpenCode 1. OpenCode 1 questions are answered on its `/question` route. A Mac app connection is unchanged: the Mac app's spec keeps the block that sends every question through `ask_user`, and its plugin leaves OpenCode's form alone, until the Mac app forwards the form.
15
+ - OpenCode 2: a deny from your phone or your Pushary rules now reaches the agent with its reason. Before, the plugin rejected the permission with no message, which OpenCode treats as a stop: it ended the step and rejected every other pending permission in the session. Now OpenCode hands the reason to the model as feedback and the model carries on with it, as Claude Code does after a deny. A kill from Pushary and an approval that was cancelled or became unavailable still reject with no message, so the step still ends, as Claude Code's turn does. An allow is still one approval. OpenCode 1 replies on its session route, which takes no message, so a deny there is unchanged.
16
+ - OpenCode 2: a turn that ends on an error is recorded in Activity as a failed turn and sends the same "OpenCode stopped on an error" push Claude Code's `StopFailure` sends, with OpenCode's own error message. The kill switch and Terminal mode keep it off your phone, and it is still recorded. An interrupted turn still sends nothing.
17
+ - OpenCode 2: a subagent's prompt, turn end and failure are no longer reported as yours. OpenCode runs each subagent in a child session, and Pushary recorded its prompt as a new prompt from you and its end as a finished turn. The plugin learns a session's parent from `session.created`, or asks OpenCode once per session and treats a lookup that takes over 2 seconds as no parent, and skips the prompt. A subagent's turn end or failure is recorded as a subagent stop on its own session under its parent, as Claude Code's `SubagentStop` is, so the subagent no longer looks busy for two minutes, and it sends no push. A subagent's tool calls are still recorded and its permission asks are still gated. When OpenCode cannot say whether a session has a parent, the report is sent as before.
18
+ - OpenCode: a shell command run in the project or in a folder inside it, whether OpenCode writes the working directory relative or absolute, now reaches your phone, judged in that folder: the phone shows it and a repository rule applies for the folder the command runs in, so a rule for a nested clone or submodule is not skipped. Before, any `workdir` not spelled exactly as the project path stayed in OpenCode's prompt. A working directory outside the project, or one starting with `~`, still stays there.
19
+ - OpenCode 2: when the event stream drops, the plugin subscribes again after 1, 2 and 5 seconds and then every 10 seconds until OpenCode unloads it. Before, one dropped stream stopped every approval until OpenCode restarted. A drop keeps what the plugin knows about running tool calls and pending asks, so a shell command outside the project still stays in OpenCode's prompt after the stream comes back, and an ask OpenCode repeats is answered once. It still prints one line, the first time. An approval asked while the stream is down stays in OpenCode's prompt.
20
+ - OpenCode 2: web searches, skills and subagents OpenCode asks about now reach your phone, as `WebSearch` with the query, `Skill` with the skill's name and `Task` with the subagent and its description, so rules for those tools apply, and a standing deny written for `Agent` refuses a subagent too. OpenCode asks about them only when your configuration says to. Questions, todos, `glob` and `grep` stay in OpenCode's prompt, so a broad ask rule does not push every search, and so do MCP tools: OpenCode names them `<server>_<tool>`, which nothing tells apart from a plugin's own tools or from Pushary's own `pushary_ask_user`.
21
+ - Setup and `pushary doctor` read OpenCode 2's `permissions` list after `tools` and `permission`, in the order OpenCode applies them, when they say which of `bash`, `edit` and `webfetch` OpenCode would run without asking. What setup writes is unchanged.
22
+ - Setup and `pushary upgrade` write the new plugin. An existing CLI connection gets it on the next upgrade, and a Mac app connection after the Mac app update and a reconnect.
23
+
24
+ ## 1.9.159
25
+
26
+ - Setup, `pushary upgrade` and automatic updates no longer leave the install lock stuck when npm holds back new releases (`min-release-age` or `before` in your npm config). Before installing, Pushary asks npm which release it would pick with `npm pack --global --dry-run`, which reads the same npm settings as a global install, runs no scripts and writes nothing. A release npm refuses is reported before the lock is marked, so the next run goes ahead with no file to delete. 1.9.154 had brought the stuck lock back: it kept the lock after any failed install, including a release-age refusal, so the next setup failed with "An earlier installation did not finish safely". A failed install that npm did start still keeps the lock, as in 1.9.154.
27
+ - Automatic updates install the newest release your npm allows instead of failing every day while the newest release is younger than your `min-release-age`. They never install an older release than the one you have. When nothing newer is allowed yet, the update is recorded as up to date with a note saying which release is waiting.
28
+ - When setup itself is too new for your npm, it tells you to run the newest release your npm allows, `npm exec --yes --package=pushary@latest -c "pushary setup --agents ..."`, instead of waiting until this exact release is old enough. Setups from 1.9.154 on refuse to replace a newer installed CLI; an older one that npm picks under a long `min-release-age` can still replace it.
29
+
3
30
  ## 1.9.158
4
31
 
5
32
  - The CLI now tells Pushary why each tool call ran without a question, so a quiet session can be told apart from a broken one. This covers Claude Code and every agent that runs the same `pushary-hook` and `pushary-post-hook`: Qwen Code, CodeBuddy, Qoder, Droid, Devin, Antigravity CLI and Grok Build. `PreToolUse` leaves a small record for the call, keyed by its tool use id, saying how it ended: the agent's permission mode owned it, Claude Code's own allowlist owned it, a standing rule allowed it, Pushary asked, Pushary tried to ask and could not (for example because the workspace has no active subscription), the call went to the agent's prompt, Pushary could not decide, or it was refused or stopped. The `PostToolUse` report for the same call reads the record back and sends it as `gateOutcome`. Only calls whose `PostToolUse` Pushary reports leave a record: the gated tools, `Task` and `WebFetch`. `Agent`, `ExitPlanMode`, `AskUserQuestion` and MCP calls leave none, and a machine with no key leaves none. The record lives in your temporary folder for at most an hour, at most 512 at a time, in a folder only you can open. Expired records are cleared at most every 10 minutes, and a record that cannot be written is skipped without a message. What `PreToolUse` decides is unchanged.
package/README.md CHANGED
@@ -219,6 +219,7 @@ disconnect Turn off one agent (claude|codex|gemini|cursor|opencode|qwen|codebu
219
219
  clean Remove Pushary from this machine (--everything: the Mac app's setup too, --dry-run: preview)
220
220
  mode Choose where approval requests appear
221
221
  wait Show or set the "wait for your phone" ladder (pushary wait 45)
222
+ calls Get a phone call when an approval waits: add your number, confirm it, turn calls on or off
222
223
  stats Show the approval moments your agents hit while not connected
223
224
  audit Check a verifiable audit export: every hash, every signature, and the checkpoints you verified before
224
225
  suggestions List rules mined from your own approvals
@@ -13,31 +13,33 @@ import {
13
13
  pollForAnswer,
14
14
  requestGate,
15
15
  sendNotification,
16
+ sleepUnlessAborted,
16
17
  unavailableQuestionUnlessRefused,
17
18
  waitForAnswer,
19
+ waitForOpenQuestion,
18
20
  waitForQuestion,
19
21
  waitRetryPauseMs,
20
22
  waitsForThePhone,
21
23
  withdrawQuestion
22
- } from "./chunk-CS4Z44F5.js";
24
+ } from "./chunk-YH6EHCKQ.js";
23
25
  import "./chunk-POFBE6ZY.js";
24
- import "./chunk-TZJR5ESF.js";
25
- import "./chunk-PBPQRJ2T.js";
26
- import "./chunk-PND5IGC7.js";
27
- import "./chunk-TSR3FPGL.js";
28
- import "./chunk-MHYX5Q3F.js";
26
+ import "./chunk-6QQUGYH6.js";
27
+ import "./chunk-WIFMTEQI.js";
28
+ import "./chunk-L6BMVCQQ.js";
29
+ import "./chunk-VUGF2OC7.js";
30
+ import "./chunk-DSWUG4NV.js";
31
+ import "./chunk-TUXX7TKR.js";
32
+ import "./chunk-HAOYL5JP.js";
33
+ import "./chunk-DAMTDSAE.js";
29
34
  import "./chunk-YU2EUD7O.js";
30
- import "./chunk-B3BOAYRO.js";
31
- import "./chunk-IVOELLUK.js";
32
- import "./chunk-FTTSQAF4.js";
33
- import "./chunk-BG4HHB7E.js";
34
35
  import "./chunk-TODDEIYG.js";
35
- import "./chunk-AOP55JR2.js";
36
- import "./chunk-WIIMW5YO.js";
36
+ import "./chunk-BG4HHB7E.js";
37
+ import "./chunk-I5ANEYUK.js";
38
+ import "./chunk-UQTQ6HPO.js";
37
39
  import {
38
40
  DECISION_STOP_REASON,
39
41
  UNVERIFIABLE_APPROVAL_REASON
40
- } from "./chunk-HA2SRYYP.js";
42
+ } from "./chunk-M2ZGNZRS.js";
41
43
  import "./chunk-MLKGABMK.js";
42
44
  export {
43
45
  ABANDONED_WAIT,
@@ -56,8 +58,10 @@ export {
56
58
  pollForAnswer,
57
59
  requestGate,
58
60
  sendNotification,
61
+ sleepUnlessAborted,
59
62
  unavailableQuestionUnlessRefused,
60
63
  waitForAnswer,
64
+ waitForOpenQuestion,
61
65
  waitForQuestion,
62
66
  waitRetryPauseMs,
63
67
  waitsForThePhone,
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  exitOnHelpFlag
4
- } from "../chunk-T3PZQNIK.js";
5
- import {
6
- EXIT
7
- } from "../chunk-BG4HHB7E.js";
4
+ } from "../chunk-XIICM4TX.js";
8
5
  import {
9
6
  readJsonSafe,
10
7
  writeJsonAtomic
11
8
  } from "../chunk-TODDEIYG.js";
12
- import "../chunk-AOP55JR2.js";
13
- import "../chunk-WIIMW5YO.js";
9
+ import {
10
+ EXIT
11
+ } from "../chunk-BG4HHB7E.js";
12
+ import "../chunk-I5ANEYUK.js";
13
+ import "../chunk-UQTQ6HPO.js";
14
14
  import {
15
15
  AUDIT_CHAIN_FINDING_SEVERITY,
16
16
  AUDIT_CHECKPOINT_MAX_AGE_MS,
@@ -22,7 +22,7 @@ import {
22
22
  parseAuditChainExport,
23
23
  parseAuditKnownHead,
24
24
  verifyAuditChainSite
25
- } from "../chunk-HA2SRYYP.js";
25
+ } from "../chunk-M2ZGNZRS.js";
26
26
  import "../chunk-MLKGABMK.js";
27
27
 
28
28
  // src/audit-verify.ts
@@ -1,45 +1,45 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handleBell
4
- } from "../chunk-ORQ7THNZ.js";
4
+ } from "../chunk-UPCIKGWA.js";
5
5
  import {
6
6
  readHookInput
7
- } from "../chunk-3QU4WXAH.js";
8
- import "../chunk-GTYVNVBZ.js";
9
- import "../chunk-C6PAIHLP.js";
7
+ } from "../chunk-L44II2WD.js";
8
+ import "../chunk-P4KAYIMX.js";
9
+ import "../chunk-XOSSXRIR.js";
10
10
  import "../chunk-WHB622LP.js";
11
- import "../chunk-MTITL2IG.js";
12
- import "../chunk-K3I2NMEF.js";
13
- import "../chunk-TPLTB256.js";
14
- import "../chunk-QP3TCKRZ.js";
15
- import "../chunk-IKC33YKC.js";
16
- import "../chunk-FGVBFDNV.js";
17
- import "../chunk-V36P4KS4.js";
11
+ import "../chunk-TMDCIVZ2.js";
12
+ import "../chunk-EFKJCBWA.js";
13
+ import "../chunk-H7OY4AAT.js";
14
+ import "../chunk-Y3ELKLNH.js";
15
+ import "../chunk-G6M6YJK4.js";
16
+ import "../chunk-J6KDUXJF.js";
17
+ import "../chunk-V3TWYF32.js";
18
18
  import "../chunk-YPY4YCIZ.js";
19
- import "../chunk-4I2SHNEU.js";
19
+ import "../chunk-PIIKLAFY.js";
20
20
  import "../chunk-352FIVVH.js";
21
- import "../chunk-APCJZFTJ.js";
22
- import "../chunk-4WL2MINE.js";
23
- import "../chunk-CS4Z44F5.js";
21
+ import "../chunk-W3FE7GTH.js";
22
+ import "../chunk-Y6ILCLKE.js";
23
+ import "../chunk-FIR2MGSB.js";
24
+ import "../chunk-YH6EHCKQ.js";
25
+ import "../chunk-OH2WAG47.js";
24
26
  import "../chunk-POFBE6ZY.js";
25
- import "../chunk-TZJR5ESF.js";
26
- import "../chunk-PBPQRJ2T.js";
27
- import "../chunk-PND5IGC7.js";
28
- import "../chunk-H6CL3T2S.js";
29
- import "../chunk-ANQBLZAE.js";
30
- import "../chunk-TSR3FPGL.js";
31
- import "../chunk-MHYX5Q3F.js";
27
+ import "../chunk-6QQUGYH6.js";
28
+ import "../chunk-WIFMTEQI.js";
29
+ import "../chunk-L6BMVCQQ.js";
30
+ import "../chunk-VUGF2OC7.js";
31
+ import "../chunk-DSWUG4NV.js";
32
+ import "../chunk-M74WT5NA.js";
33
+ import "../chunk-YEVRMDG7.js";
34
+ import "../chunk-TUXX7TKR.js";
35
+ import "../chunk-HAOYL5JP.js";
36
+ import "../chunk-DAMTDSAE.js";
32
37
  import "../chunk-YU2EUD7O.js";
33
- import "../chunk-ZYDE6QRW.js";
34
- import "../chunk-UDLWNOXX.js";
35
- import "../chunk-B3BOAYRO.js";
36
- import "../chunk-IVOELLUK.js";
37
- import "../chunk-FTTSQAF4.js";
38
- import "../chunk-BG4HHB7E.js";
39
38
  import "../chunk-TODDEIYG.js";
40
- import "../chunk-AOP55JR2.js";
41
- import "../chunk-WIIMW5YO.js";
42
- import "../chunk-HA2SRYYP.js";
39
+ import "../chunk-BG4HHB7E.js";
40
+ import "../chunk-I5ANEYUK.js";
41
+ import "../chunk-UQTQ6HPO.js";
42
+ import "../chunk-M2ZGNZRS.js";
43
43
  import "../chunk-MLKGABMK.js";
44
44
 
45
45
  // bin/pushary-bell-hook.ts
@@ -5,41 +5,41 @@ import {
5
5
  liveAgentCount,
6
6
  ring,
7
7
  upgradeThreshold
8
- } from "../chunk-ORQ7THNZ.js";
8
+ } from "../chunk-UPCIKGWA.js";
9
9
  import {
10
10
  createIo
11
- } from "../chunk-GHHVXARK.js";
11
+ } from "../chunk-WCWWO5QL.js";
12
12
  import {
13
13
  exitOnHelpFlag
14
- } from "../chunk-T3PZQNIK.js";
14
+ } from "../chunk-XIICM4TX.js";
15
15
  import {
16
16
  addBellHooks,
17
17
  bellInstalled,
18
18
  removeBellHooks
19
- } from "../chunk-V36P4KS4.js";
19
+ } from "../chunk-V3TWYF32.js";
20
20
  import {
21
21
  parseFlags
22
22
  } from "../chunk-YPY4YCIZ.js";
23
- import "../chunk-YU2EUD7O.js";
24
- import "../chunk-ZYDE6QRW.js";
25
- import "../chunk-UDLWNOXX.js";
23
+ import "../chunk-M74WT5NA.js";
24
+ import "../chunk-YEVRMDG7.js";
26
25
  import {
27
26
  claudeSettings
28
- } from "../chunk-B3BOAYRO.js";
29
- import "../chunk-IVOELLUK.js";
30
- import "../chunk-FTTSQAF4.js";
31
- import {
32
- EXIT
33
- } from "../chunk-BG4HHB7E.js";
27
+ } from "../chunk-TUXX7TKR.js";
28
+ import "../chunk-HAOYL5JP.js";
29
+ import "../chunk-DAMTDSAE.js";
30
+ import "../chunk-YU2EUD7O.js";
34
31
  import {
35
32
  readJsonSafe,
36
33
  writeJsonAtomic
37
34
  } from "../chunk-TODDEIYG.js";
38
- import "../chunk-AOP55JR2.js";
39
- import "../chunk-WIIMW5YO.js";
35
+ import {
36
+ EXIT
37
+ } from "../chunk-BG4HHB7E.js";
38
+ import "../chunk-I5ANEYUK.js";
39
+ import "../chunk-UQTQ6HPO.js";
40
40
  import {
41
41
  isRecord
42
- } from "../chunk-HA2SRYYP.js";
42
+ } from "../chunk-M2ZGNZRS.js";
43
43
  import "../chunk-MLKGABMK.js";
44
44
 
45
45
  // bin/pushary-bell.ts
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,287 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ exitOnFailedResponse
4
+ } from "../chunk-IUXXEM4Q.js";
5
+ import "../chunk-44DRCGP2.js";
6
+ import "../chunk-GJOHGES6.js";
7
+ import {
8
+ createIo
9
+ } from "../chunk-WCWWO5QL.js";
10
+ import {
11
+ exitOnHelpFlag
12
+ } from "../chunk-XIICM4TX.js";
13
+ import {
14
+ parseFlags
15
+ } from "../chunk-YPY4YCIZ.js";
16
+ import "../chunk-L6BMVCQQ.js";
17
+ import {
18
+ pusharyFetch
19
+ } from "../chunk-VUGF2OC7.js";
20
+ import "../chunk-DSWUG4NV.js";
21
+ import "../chunk-M74WT5NA.js";
22
+ import "../chunk-YEVRMDG7.js";
23
+ import "../chunk-TUXX7TKR.js";
24
+ import "../chunk-HAOYL5JP.js";
25
+ import {
26
+ getApiKey,
27
+ getBaseUrl
28
+ } from "../chunk-DAMTDSAE.js";
29
+ import {
30
+ UsageError,
31
+ exitCodeFor
32
+ } from "../chunk-YU2EUD7O.js";
33
+ import "../chunk-TODDEIYG.js";
34
+ import {
35
+ EXIT
36
+ } from "../chunk-BG4HHB7E.js";
37
+ import {
38
+ isInvocationOf
39
+ } from "../chunk-I5ANEYUK.js";
40
+ import "../chunk-UQTQ6HPO.js";
41
+ import {
42
+ PHONE_CALL_SETUP_PATH,
43
+ PHONE_CALL_SETUP_TEST_CALL_PARAM,
44
+ parsePhoneCallSetupReply,
45
+ parseTestCallReply
46
+ } from "../chunk-M2ZGNZRS.js";
47
+ import "../chunk-MLKGABMK.js";
48
+
49
+ // bin/pushary-calls.ts
50
+ import { confirm, input } from "@inquirer/prompts";
51
+
52
+ // src/cli/phone-calls-copy.ts
53
+ var PHONE_CALL_SETTINGS_PAGE = "/dashboard/agent/settings?tab=phone-calls";
54
+ var TEST_CALL_POLL_INTERVAL_MS = 3e3;
55
+ var TEST_CALL_WAIT_LIMIT_MS = 15e4;
56
+ var CALL_CONSENT_LINE = "Pushary may call this number with an AI voice that explains what my agent wants to do. The call is transcribed and kept for 30 days.";
57
+ var COUNTRY_NAMES = {
58
+ US: "the US",
59
+ CA: "Canada",
60
+ GB: "the UK",
61
+ DE: "Germany",
62
+ AT: "Austria",
63
+ CH: "Switzerland",
64
+ NL: "the Netherlands"
65
+ };
66
+ var listOf = (items) => items.length <= 1 ? items[0] ?? "" : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
67
+ var callableCountriesLine = (liveCountries) => `Calls go to ${listOf(liveCountries.map((code) => COUNTRY_NAMES[code] ?? code))}.`;
68
+ var NUMBER_PROMPT_HINT = "Include the country code, like +1 415 555 0134.";
69
+ var SETUP_ERROR_LINES = {
70
+ unauthorized: "Pushary did not accept this key. Run npx pushary@latest setup to sign in again.",
71
+ no_site: "This key has no Pushary workspace. Run npx pushary@latest setup.",
72
+ not_available: "Phone calls are not available right now. Try again later.",
73
+ invalid_input: "Pushary could not read that request. Update the CLI with npx pushary@latest upgrade and try again.",
74
+ phone_rejected: "That number cannot be called.",
75
+ phone_required: "Add your number first: pushary calls on",
76
+ consent_required: "Calls stay off until you agree to be called.",
77
+ invalid_rules: "Those call rules are not valid.",
78
+ invalid_time_zone: "Your computer reports a time zone Pushary does not know. Set your time zone and try again.",
79
+ invalid_name: "Enter a first name of up to 40 characters.",
80
+ country_not_available: "Calls to that country are not available right now.",
81
+ daily_test_limit: "You used today's test calls. Try again tomorrow.",
82
+ number_test_limit: "This number had too many test calls. Try again tomorrow.",
83
+ no_minutes: "You have no call minutes left this month.",
84
+ not_entitled: "Your plan has no phone calls. Agent and Agent Pro include call minutes.",
85
+ daily_limit: "You reached today's call limit.",
86
+ busy: "A call to you is already running. Try again in a minute.",
87
+ provider_failed: "The call could not be placed. Try again in a minute.",
88
+ unknown_call: "Pushary has no record of that test call."
89
+ };
90
+ var PHONE_REJECTION_LINES = {
91
+ not_a_number: "That is not a phone number.",
92
+ not_a_supported_country: "Pushary cannot call that country.",
93
+ crown_dependency_number: "Pushary cannot call Jersey, Guernsey or the Isle of Man.",
94
+ service_number: "That is a service number. Use your own mobile number.",
95
+ not_a_mobile_number: "Use a mobile number for this country.",
96
+ wrong_length: "That number has too few or too many digits.",
97
+ country_not_available: "Calls to that country are not available right now."
98
+ };
99
+ var TEST_CALL_RESULT_LINES = {
100
+ confirmed: "Number confirmed.",
101
+ not_confirmed: "The number was not confirmed on the call. Run pushary calls on to try again.",
102
+ not_answered: "The call was not answered. Run pushary calls on to try again.",
103
+ failed: "The call could not be completed. Try again in a minute."
104
+ };
105
+ var NOT_FOUND = 404;
106
+ var TOO_MANY_REQUESTS = 429;
107
+ var FIRST_SERVER_ERROR = 500;
108
+ var unreadableReplyLineOf = (status) => {
109
+ if (status === NOT_FOUND) return "This Pushary server cannot set up calls yet. Set them up in the dashboard for now.";
110
+ if (status === TOO_MANY_REQUESTS) return "Too many requests. Try again in a minute.";
111
+ if (status >= FIRST_SERVER_ERROR) return `Pushary had a problem (HTTP ${status}). Try again in a minute.`;
112
+ return `Pushary answered with something this CLI cannot read (HTTP ${status}). Update it with npx pushary@latest upgrade.`;
113
+ };
114
+ var NUMBER_FLAG_NEEDED = "Add your mobile number with --number, since nobody is at this terminal to type it.";
115
+ var TEST_CALL_TIMED_OUT_LINE = "No result yet. Run pushary calls in a minute to see if the number is confirmed.";
116
+ var settingsPageOf = (baseUrl) => `${baseUrl}${PHONE_CALL_SETTINGS_PAGE}`;
117
+ var errorLineOf = (error, phoneRejection) => error === "phone_rejected" && phoneRejection !== void 0 ? PHONE_REJECTION_LINES[phoneRejection] : SETUP_ERROR_LINES[error];
118
+ var hourOf = (hour) => `${String(hour).padStart(2, "0")}:00`;
119
+ var minutesOf = (seconds) => {
120
+ const minutes = Math.round(seconds / 60);
121
+ return minutes === 1 ? "1 min" : `${minutes} min`;
122
+ };
123
+ var callTimesLine = (status) => `Rings after ${minutesOf(status.callAfterSeconds)}, ${hourOf(status.startHour)} to ${hourOf(status.endHour)}${status.weekdaysOnly ? " on weekdays" : ""} (${status.timeZone}).`;
124
+ var callsOnLine = (status) => `Calls are on. Pushary calls ${status.number ?? "you"} when an approval waits. ${callTimesLine(status)}`;
125
+ var callsStateOf = (status) => {
126
+ if (status.ready) return "on";
127
+ if (status.number === null) return "needs_number";
128
+ return status.confirmed ? "off" : "needs_test_call";
129
+ };
130
+ var STATE_LINES = {
131
+ on: "on",
132
+ off: "off",
133
+ needs_number: "off, no number yet",
134
+ needs_test_call: "off, number not confirmed yet"
135
+ };
136
+ var statusLines = (status) => [
137
+ `Phone calls ${STATE_LINES[callsStateOf(status)]}`,
138
+ ...status.number === null ? [] : [`Number ${status.number}${status.confirmed ? "" : " (not confirmed)"}`],
139
+ ...callsStateOf(status) === "on" ? [`When ${callTimesLine(status)}`] : [],
140
+ `Minutes ${status.entitled ? `${minutesOf(status.secondsLeft)} left` : "not in your plan"}`
141
+ ];
142
+ var testCallWaitExpired = (elapsedMs) => elapsedMs >= TEST_CALL_WAIT_LIMIT_MS;
143
+
144
+ // src/phone-call-setup-api.ts
145
+ var KEY_REFUSED_STATUSES = /* @__PURE__ */ new Set([401, 403]);
146
+ var headersFor = (client) => ({
147
+ Authorization: `Bearer ${client.apiKey}`,
148
+ "Content-Type": "application/json"
149
+ });
150
+ var answerOf = async (response, parse) => {
151
+ if (KEY_REFUSED_STATUSES.has(response.status)) return { kind: "key_refused", response };
152
+ const reply = parse(await response.json().catch(() => null));
153
+ return reply === null ? { kind: "unreadable", status: response.status } : { kind: "reply", reply };
154
+ };
155
+ var setupUrlOf = (client) => `${client.baseUrl}${PHONE_CALL_SETUP_PATH}`;
156
+ var readPhoneCallSetup = async (client) => answerOf(await pusharyFetch(setupUrlOf(client), { headers: headersFor(client) }), parsePhoneCallSetupReply);
157
+ var changePhoneCallSetup = async (client, request) => answerOf(await pusharyFetch(setupUrlOf(client), { method: "POST", headers: headersFor(client), body: JSON.stringify(request) }), parsePhoneCallSetupReply);
158
+ var readTestCall = async (client, testCallId) => {
159
+ const url = new URL(setupUrlOf(client));
160
+ url.searchParams.set(PHONE_CALL_SETUP_TEST_CALL_PARAM, testCallId);
161
+ return answerOf(await pusharyFetch(url.toString(), { headers: headersFor(client) }), parseTestCallReply);
162
+ };
163
+
164
+ // bin/pushary-calls.ts
165
+ exitOnHelpFlag("calls");
166
+ var io = createIo();
167
+ var CallsRefused = class extends Error {
168
+ };
169
+ var CONSENT_FLAG_NEEDED = "Add --yes to agree to the calls, since nobody is at this terminal to agree.";
170
+ var answeredReply = async (client, answer) => {
171
+ if (answer.kind === "key_refused") return exitOnFailedResponse(answer.response, client.baseUrl);
172
+ if (answer.kind === "unreadable") throw new CallsRefused(unreadableReplyLineOf(answer.status));
173
+ return answer.reply;
174
+ };
175
+ var acceptedStatus = (reply) => {
176
+ if (!reply.ok) throw new CallsRefused(errorLineOf(reply.error, reply.phoneRejection));
177
+ return reply;
178
+ };
179
+ var currentStatus = async (client) => acceptedStatus(await answeredReply(client, await readPhoneCallSetup(client))).status;
180
+ var change = async (client, request) => answeredReply(client, await changePhoneCallSetup(client, request));
181
+ var printStatus = (status, baseUrl) => {
182
+ io.line();
183
+ for (const line of statusLines(status)) io.line(` ${line}`);
184
+ io.line();
185
+ io.line(` ${io.dim(callsStateOf(status) === "on" ? `Change the rules: ${settingsPageOf(baseUrl)}` : "Turn them on: pushary calls on")}`);
186
+ io.line();
187
+ };
188
+ var askNumber = async () => (await input({ message: "Your mobile number", validate: (value) => value.trim().length > 0 || NUMBER_PROMPT_HINT })).trim();
189
+ var askName = async (status) => (await input({ message: "Your first name, for the call", default: status.firstName ?? void 0, validate: (value) => value.trim().length > 0 || "Enter a first name." })).trim();
190
+ var timeZoneFor = (status) => status.number === null ? Intl.DateTimeFormat().resolvedOptions().timeZone : status.timeZone;
191
+ var saveNumber = async (client, status, options) => {
192
+ if (options.interactive && options.number === void 0) {
193
+ io.line(` ${io.dim(`${callableCountriesLine(status.liveCountries)} ${NUMBER_PROMPT_HINT}`)}`);
194
+ }
195
+ for (; ; ) {
196
+ const phone = options.number ?? await askNumber();
197
+ const firstName = options.name ?? status.firstName ?? (options.interactive ? await askName(status) : void 0);
198
+ if (firstName === void 0) throw new UsageError("Add your first name with --name, so the call can greet you.");
199
+ const reply = await change(client, { action: "number", phone, country: status.suggestedCountry, firstName, timeZone: timeZoneFor(status) });
200
+ if (reply.ok) {
201
+ io.line(` ${io.check()} Saved ${reply.status.number ?? phone}`);
202
+ return reply.status;
203
+ }
204
+ if (!options.interactive || options.number !== void 0 || reply.error !== "phone_rejected") throw new CallsRefused(errorLineOf(reply.error, reply.phoneRejection));
205
+ io.warn(errorLineOf(reply.error, reply.phoneRejection));
206
+ }
207
+ };
208
+ var pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
209
+ var waitForTestCall = async (client, testCallId) => {
210
+ const startedAt = Date.now();
211
+ for (; ; ) {
212
+ const reply = await answeredReply(client, await readTestCall(client, testCallId));
213
+ if (!reply.ok) throw new CallsRefused(errorLineOf(reply.error));
214
+ const progress = reply.progress;
215
+ if (progress !== "calling") return progress;
216
+ if (testCallWaitExpired(Date.now() - startedAt)) return "timed_out";
217
+ await pause(TEST_CALL_POLL_INTERVAL_MS);
218
+ }
219
+ };
220
+ var confirmNumberByTestCall = async (client, status) => {
221
+ io.line(` Calling ${status.number ?? "you"} now for a test. Answer it and say yes when it asks if this is your number.`);
222
+ const started = acceptedStatus(await change(client, { action: "test_call" }));
223
+ if (started.testCallId === void 0) throw new CallsRefused(unreadableReplyLineOf(200));
224
+ const result = await waitForTestCall(client, started.testCallId);
225
+ if (result === "timed_out") throw new CallsRefused(TEST_CALL_TIMED_OUT_LINE);
226
+ if (result !== "confirmed") throw new CallsRefused(TEST_CALL_RESULT_LINES[result]);
227
+ io.line(` ${io.check()} ${TEST_CALL_RESULT_LINES.confirmed}`);
228
+ };
229
+ var agreeToCalls = async (options) => {
230
+ io.line(` ${io.dim(CALL_CONSENT_LINE)}`);
231
+ if (options.agreed) return true;
232
+ if (!options.interactive) throw new UsageError(CONSENT_FLAG_NEEDED);
233
+ return confirm({ message: "Turn on calls?", default: true });
234
+ };
235
+ var turnCallsOn = async (client, options) => {
236
+ if (!options.interactive && !options.agreed) throw new UsageError(CONSENT_FLAG_NEEDED);
237
+ let status = await currentStatus(client);
238
+ if (!status.entitled) throw new CallsRefused(errorLineOf("not_entitled"));
239
+ if (!options.interactive && options.number === void 0 && status.number === null) throw new UsageError(NUMBER_FLAG_NEEDED);
240
+ if (status.ready && options.number === void 0) {
241
+ io.line(` ${io.check()} ${callsOnLine(status)}`);
242
+ return;
243
+ }
244
+ io.line();
245
+ io.line(` ${io.bold("Phone calls")} Pushary calls you when an approval waits too long.`);
246
+ io.line();
247
+ if (status.number === null || options.number !== void 0) status = await saveNumber(client, status, options);
248
+ if (!status.confirmed) await confirmNumberByTestCall(client, status);
249
+ if (!await agreeToCalls(options)) {
250
+ io.line(" Calls stay off.");
251
+ return;
252
+ }
253
+ const on = acceptedStatus(await change(client, { action: "enabled", enabled: true, consented: true })).status;
254
+ io.line(` ${io.check()} ${callsOnLine(on)}`);
255
+ io.line(` ${io.dim(`Turn them off: pushary calls off. Change the rules: ${settingsPageOf(client.baseUrl)}`)}`);
256
+ io.line();
257
+ };
258
+ var turnCallsOff = async (client) => {
259
+ acceptedStatus(await change(client, { action: "enabled", enabled: false, consented: false }));
260
+ io.line(` ${io.check()} Calls are off. Turn them back on: pushary calls on`);
261
+ };
262
+ var main = async () => {
263
+ const raw = process.argv.slice(2);
264
+ const flags = parseFlags(raw[0] !== void 0 && isInvocationOf(raw[0], "calls") ? raw.slice(1) : raw, { bools: ["yes"], values: ["number", "name"] });
265
+ if (flags.rest.length > 0) throw new UsageError("calls takes one subcommand: on, off or status");
266
+ const client = { apiKey: getApiKey(), baseUrl: getBaseUrl() };
267
+ const options = {
268
+ number: flags.values.get("number"),
269
+ name: flags.values.get("name"),
270
+ agreed: flags.bools.has("yes"),
271
+ interactive: process.stdin.isTTY === true && process.stdout.isTTY === true
272
+ };
273
+ if (flags.command === "on") return turnCallsOn(client, options);
274
+ if (flags.command === "off") return turnCallsOff(client);
275
+ if (flags.command === void 0 || flags.command === "status") return printStatus(await currentStatus(client), client.baseUrl);
276
+ throw new UsageError(`Unknown: ${flags.command}. Try \`pushary calls on\`, \`off\` or \`status\`.`);
277
+ };
278
+ try {
279
+ await main();
280
+ } catch (error) {
281
+ if (error instanceof CallsRefused) {
282
+ io.warn(error.message);
283
+ process.exit(EXIT.FAILED);
284
+ }
285
+ console.error(error instanceof Error ? error.message : String(error));
286
+ process.exit(exitCodeFor(error));
287
+ }