pushary 1.9.269 → 1.9.271

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 (143) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{api-ILQDGJL4.js → api-QRQC65E7.js} +12 -12
  3. package/dist/bin/pushary-audit.js +3 -3
  4. package/dist/bin/pushary-bell-hook.js +28 -28
  5. package/dist/bin/pushary-bell.js +11 -11
  6. package/dist/bin/pushary-calls.js +14 -14
  7. package/dist/bin/pushary-claude.js +25 -25
  8. package/dist/bin/pushary-clean.js +39 -39
  9. package/dist/bin/pushary-codex-bridge.js +22 -22
  10. package/dist/bin/pushary-codex-hook.js +34 -34
  11. package/dist/bin/pushary-codex-session.js +8 -8
  12. package/dist/bin/pushary-codex.js +16 -16
  13. package/dist/bin/pushary-connect.js +35 -35
  14. package/dist/bin/pushary-cowork.js +5 -5
  15. package/dist/bin/pushary-daemon.js +46 -46
  16. package/dist/bin/pushary-disconnect.js +30 -30
  17. package/dist/bin/pushary-display-hook.js +14 -0
  18. package/dist/bin/pushary-doctor.js +48 -48
  19. package/dist/bin/pushary-elicitation-hook.js +27 -27
  20. package/dist/bin/pushary-gemini-bridge.js +17 -17
  21. package/dist/bin/pushary-gemini-hook.js +31 -31
  22. package/dist/bin/pushary-hook.js +35 -35
  23. package/dist/bin/pushary-login.js +42 -42
  24. package/dist/bin/pushary-logout.js +31 -31
  25. package/dist/bin/pushary-mcp.js +12 -12
  26. package/dist/bin/pushary-mode.js +15 -15
  27. package/dist/bin/pushary-notification-hook.js +27 -27
  28. package/dist/bin/pushary-opencode-bridge.js +21 -21
  29. package/dist/bin/pushary-opencode-hook.js +32 -32
  30. package/dist/bin/pushary-permission-denied-hook.js +34 -34
  31. package/dist/bin/pushary-permission-hook.js +35 -35
  32. package/dist/bin/pushary-post-hook.js +28 -28
  33. package/dist/bin/pushary-prompt-hook.js +27 -27
  34. package/dist/bin/pushary-session-end-hook.js +27 -27
  35. package/dist/bin/pushary-session-start-hook.js +39 -39
  36. package/dist/bin/pushary-sessions.js +12 -12
  37. package/dist/bin/pushary-setup.js +59 -59
  38. package/dist/bin/pushary-stats.js +5 -5
  39. package/dist/bin/pushary-status.js +36 -36
  40. package/dist/bin/pushary-stop-hook.js +27 -27
  41. package/dist/bin/pushary-stopfailure-hook.js +27 -27
  42. package/dist/bin/pushary-suggestions.js +15 -15
  43. package/dist/bin/pushary-transcript-register.js +16 -16
  44. package/dist/bin/pushary-transcripts.js +25 -25
  45. package/dist/bin/pushary-upgrade.js +47 -47
  46. package/dist/bin/pushary-wait.js +16 -16
  47. package/dist/bin/pushary.js +7 -7
  48. package/dist/{chunk-AHYV7ZQE.js → chunk-2ABJ4VCG.js} +1 -1
  49. package/dist/{chunk-ZTQS2ZVJ.js → chunk-2C2XPI5Y.js} +1 -1
  50. package/dist/{chunk-43EYM5PY.js → chunk-3IHL4N2G.js} +6 -6
  51. package/dist/{chunk-3D6EDVCE.js → chunk-3P3GPF6O.js} +11 -11
  52. package/dist/{chunk-HV2DBLA2.js → chunk-3TN6OKJ2.js} +5 -5
  53. package/dist/{chunk-E274RVGY.js → chunk-3ZEKDHAX.js} +4 -4
  54. package/dist/{chunk-KGZSVBUD.js → chunk-4JXYINSC.js} +3 -3
  55. package/dist/{chunk-4R2BZ7ZV.js → chunk-4O2FHBHY.js} +1 -1
  56. package/dist/{chunk-XIWZX5YY.js → chunk-4U7GLWVM.js} +5 -5
  57. package/dist/{chunk-4NBFRTVM.js → chunk-4ZISYOJF.js} +6 -6
  58. package/dist/{chunk-ALWSX6SA.js → chunk-5G6VZEDJ.js} +3 -3
  59. package/dist/{chunk-MPXY3I3M.js → chunk-65AS4TO4.js} +6 -6
  60. package/dist/{chunk-GFX5AAWT.js → chunk-67FOJA34.js} +7 -7
  61. package/dist/{chunk-KYCPYOKD.js → chunk-6Q2D4OON.js} +2 -2
  62. package/dist/{chunk-ZNQ5YZ2L.js → chunk-7JVJ4ZKU.js} +2 -2
  63. package/dist/{chunk-DBYHLVQ2.js → chunk-7TVCL4PI.js} +1 -1
  64. package/dist/{chunk-6LRUCUBE.js → chunk-A2AN2T5O.js} +5 -5
  65. package/dist/{chunk-NCHOWL5Y.js → chunk-AGK5KU7B.js} +2 -2
  66. package/dist/{chunk-TOHXHAFM.js → chunk-ARDNSSLS.js} +8 -8
  67. package/dist/{chunk-VIMAUIPP.js → chunk-B25EAOUY.js} +6 -6
  68. package/dist/{chunk-7CBU5D6G.js → chunk-BIJU6CPZ.js} +1 -1
  69. package/dist/{chunk-4JO5JG2P.js → chunk-BIY5PLF6.js} +5 -5
  70. package/dist/{chunk-EPQDQGVZ.js → chunk-BY4SOA5N.js} +1 -1
  71. package/dist/{chunk-XNYZBQCJ.js → chunk-CDGZIVNU.js} +1 -1
  72. package/dist/{chunk-MFQNYRKP.js → chunk-CGTPKZWB.js} +4 -4
  73. package/dist/{chunk-P2OVSHIW.js → chunk-COHRE67K.js} +3 -3
  74. package/dist/{chunk-U7WPURWA.js → chunk-DEMI4ZEH.js} +2 -2
  75. package/dist/{chunk-Q7VXJ634.js → chunk-DFN4FVB6.js} +4 -4
  76. package/dist/{chunk-TDV2RONN.js → chunk-DQA3PMYT.js} +3 -3
  77. package/dist/{chunk-GCWAQMHF.js → chunk-DTGU4J77.js} +5 -5
  78. package/dist/{chunk-5EQYWIQ2.js → chunk-DXPE4F2K.js} +4 -4
  79. package/dist/{chunk-QFOMZSIU.js → chunk-EZ5HNO4L.js} +1 -1
  80. package/dist/{chunk-LKKOKKUX.js → chunk-FB25FA3O.js} +2 -2
  81. package/dist/{chunk-ZVSSHI6H.js → chunk-GA7L6ZHW.js} +5 -5
  82. package/dist/{chunk-AY37CFHF.js → chunk-GOSMCOHB.js} +6 -0
  83. package/dist/{chunk-RBZCLXTE.js → chunk-HBU5P5EC.js} +1 -1
  84. package/dist/{chunk-P3DV5JOE.js → chunk-HEBBPZDN.js} +7 -7
  85. package/dist/{chunk-FM73BOSO.js → chunk-HHOTW23E.js} +2 -2
  86. package/dist/{chunk-Z4XTXCRP.js → chunk-HLJDCM3Z.js} +1 -1
  87. package/dist/{chunk-PWP6NIWM.js → chunk-IJCWAVT7.js} +2 -2
  88. package/dist/{chunk-JGMEZV2Q.js → chunk-IU4M7QPA.js} +3 -3
  89. package/dist/{chunk-3K2HA65U.js → chunk-J35H5XWH.js} +4 -4
  90. package/dist/{chunk-RQCVHU7Q.js → chunk-JF6IHH5E.js} +1 -1
  91. package/dist/{chunk-Z26E6HSF.js → chunk-JL4REHDW.js} +5 -5
  92. package/dist/{chunk-UT7O4WQ6.js → chunk-JNPZUDLA.js} +4 -4
  93. package/dist/{chunk-WT2RG7RS.js → chunk-JRPOC47L.js} +1 -1
  94. package/dist/{chunk-Z7ZBH7RU.js → chunk-JTLHPORS.js} +10 -10
  95. package/dist/{chunk-ESH2IFRQ.js → chunk-KBT4OBJM.js} +3 -3
  96. package/dist/{chunk-AVST42GD.js → chunk-LATT2QB4.js} +1 -1
  97. package/dist/{chunk-THDJL37Z.js → chunk-MDD4MCQY.js} +1 -1
  98. package/dist/{chunk-7GFQHVKY.js → chunk-NJB2WPGE.js} +16 -16
  99. package/dist/{chunk-WUUVZEKA.js → chunk-O4ZFUVDI.js} +3 -3
  100. package/dist/{chunk-JYUIHUMK.js → chunk-O63L6PLB.js} +1 -1
  101. package/dist/{chunk-ULOJDRKP.js → chunk-O753NJME.js} +1 -1
  102. package/dist/{chunk-WAZZ2JJ3.js → chunk-OHO3OYQJ.js} +12 -12
  103. package/dist/{chunk-ZG6QJH5C.js → chunk-OW4AMHJV.js} +1 -1
  104. package/dist/{chunk-7O2OZQ6L.js → chunk-PFNWKGAN.js} +4 -4
  105. package/dist/{chunk-ESMAFA2J.js → chunk-PGXWER6L.js} +5 -5
  106. package/dist/{chunk-4VUQPSEP.js → chunk-PJDMIJG7.js} +1 -1
  107. package/dist/{chunk-D57LIC6X.js → chunk-PK5JMVGN.js} +1 -1
  108. package/dist/{chunk-J2PCHNZO.js → chunk-PWDSHCY4.js} +5 -5
  109. package/dist/{chunk-UVWYN2UR.js → chunk-QG7UBHU6.js} +144 -19
  110. package/dist/{chunk-UXRP56HU.js → chunk-R6JRCEIX.js} +1 -1
  111. package/dist/{chunk-Y2DBHR2N.js → chunk-RFCTFMJS.js} +1 -1
  112. package/dist/{chunk-M3VS3PEK.js → chunk-RII5XZLB.js} +79 -18
  113. package/dist/{chunk-3YU4M3H6.js → chunk-RUWD6OFZ.js} +10 -10
  114. package/dist/{chunk-3QOTNFNM.js → chunk-TR5A6H2P.js} +3 -3
  115. package/dist/{chunk-DLMR45RP.js → chunk-TTU65I6T.js} +1 -1
  116. package/dist/{chunk-PAKMLOFV.js → chunk-TZYJNKFN.js} +3 -3
  117. package/dist/{chunk-CNNEMTRD.js → chunk-UCK4UKBV.js} +4 -4
  118. package/dist/{chunk-XLJTD3PP.js → chunk-UMZ2VLLR.js} +6 -6
  119. package/dist/{chunk-WQVKU4BI.js → chunk-VMIUZMAD.js} +3 -3
  120. package/dist/{chunk-KARQYZR3.js → chunk-VSKX62AG.js} +1 -1
  121. package/dist/{chunk-D6OF2TD3.js → chunk-VWXR34GR.js} +5 -5
  122. package/dist/{chunk-Z32D32PL.js → chunk-W2SZOATE.js} +4 -4
  123. package/dist/{chunk-ARWKVVKB.js → chunk-WS7Z6IJV.js} +1 -1
  124. package/dist/{chunk-L7GL5TJY.js → chunk-WXQA6JZO.js} +2 -2
  125. package/dist/{chunk-EY4XHT6G.js → chunk-X3DYMWPL.js} +2 -2
  126. package/dist/{chunk-QICIMORB.js → chunk-Y4DC5KRB.js} +2 -2
  127. package/dist/{chunk-O54TEHYJ.js → chunk-ZGVMX36I.js} +2 -2
  128. package/dist/{chunk-66EWTFIK.js → chunk-ZX2HQ25K.js} +1 -1
  129. package/dist/{chunk-TZ32ZFFG.js → chunk-ZXPNAYQC.js} +7 -7
  130. package/dist/{codex-app-cards-switch-ROGUHXKQ.js → codex-app-cards-switch-EULJQSJY.js} +11 -11
  131. package/dist/{codex-card-routing-CQX3C552.js → codex-card-routing-RWF7Q5NP.js} +2 -2
  132. package/dist/{codex-desktop-launch-U6XMY4AD.js → codex-desktop-launch-6FTCM3KC.js} +3 -3
  133. package/dist/{codex-session-launch-FFF7HWWT.js → codex-session-launch-7L5PTJTO.js} +21 -21
  134. package/dist/{config-J6IB5GWC.js → config-RUJK4OSC.js} +3 -3
  135. package/dist/{global-upgrade-W6O44GGK.js → global-upgrade-JASHEAL5.js} +9 -9
  136. package/dist/{identity-6W3NU4R3.js → identity-FKXV4DDS.js} +4 -4
  137. package/dist/{live-capabilities-XGYRPZB3.js → live-capabilities-M5ZFRYQR.js} +4 -4
  138. package/dist/{paths-BK42XGTR.js → paths-OWVAAP4Y.js} +3 -3
  139. package/dist/{reapply-WEEWFQOE.js → reapply-VI2TE6B4.js} +34 -34
  140. package/dist/src/index.js +33 -33
  141. package/dist/{upgrade-lock-AOHJCJIT.js → upgrade-lock-6H24K6S3.js} +10 -6
  142. package/dist/{usage-AG2GXZV6.js → usage-PENWECBI.js} +3 -3
  143. package/package.json +1 -1
@@ -16,7 +16,7 @@ import {
16
16
  uninstallOpenClawPlugin,
17
17
  unsetOpenClawEntry,
18
18
  writeOpenClawEntry
19
- } from "./chunk-JGMEZV2Q.js";
19
+ } from "./chunk-IU4M7QPA.js";
20
20
  import {
21
21
  needsShell
22
22
  } from "./chunk-3PSNUHC5.js";
@@ -28,10 +28,10 @@ import {
28
28
  openClawDirectoriesToLookIn,
29
29
  openClawPluginFolder,
30
30
  openClawSetupReceiptDirectory
31
- } from "./chunk-O54TEHYJ.js";
31
+ } from "./chunk-ZGVMX36I.js";
32
32
  import {
33
33
  resolvePathBinary
34
- } from "./chunk-3K2HA65U.js";
34
+ } from "./chunk-J35H5XWH.js";
35
35
  import {
36
36
  readJsonSafe,
37
37
  writeJsonAtomic
@@ -42,7 +42,7 @@ import {
42
42
  } from "./chunk-CXQWDQCJ.js";
43
43
  import {
44
44
  isRecord
45
- } from "./chunk-AY37CFHF.js";
45
+ } from "./chunk-GOSMCOHB.js";
46
46
 
47
47
  // src/hermes/plugin-payload.ts
48
48
  import { createHash } from "crypto";
@@ -1391,7 +1391,7 @@ def _await_decision(request, created, correlation_id: str, offered, uses_select:
1391
1391
  return _decided(request, correlation_id, "deny", None)
1392
1392
  ` },
1393
1393
  { path: "cancellation.py", contents: 'from __future__ import annotations\n\nfrom typing import Literal, Mapping, Tuple\n\nCancellation = Literal[\n "withdrawn_by_this_call",\n "cancelled_unproven",\n "already_cancelled",\n "not_pending",\n "unreachable",\n]\n\nWITHDRAWN_BY_THIS_CALL: Cancellation = "withdrawn_by_this_call"\nCANCELLED_UNPROVEN: Cancellation = "cancelled_unproven"\nALREADY_CANCELLED: Cancellation = "already_cancelled"\nNOT_PENDING: Cancellation = "not_pending"\nUNREACHABLE: Cancellation = "unreachable"\nCANCELLATIONS: Tuple[Cancellation, ...] = (\n WITHDRAWN_BY_THIS_CALL,\n CANCELLED_UNPROVEN,\n ALREADY_CANCELLED,\n NOT_PENDING,\n UNREACHABLE,\n)\n\nUNAVAILABLE_STATUS = "unavailable"\nSTOP_HANDOFF = "stop"\n\n\ndef classify_cancellation(response: object) -> Cancellation:\n if not isinstance(response, Mapping):\n return UNREACHABLE\n fields: Mapping[object, object] = response\n cancelled = fields.get("cancelled")\n by_this_call = fields.get("cancelledByThisCall")\n if (\n not isinstance(cancelled, bool)\n or fields.get("status") == UNAVAILABLE_STATUS\n or fields.get("handoffAction") == STOP_HANDOFF\n or (by_this_call is not None and not isinstance(by_this_call, bool))\n or (by_this_call is True and not cancelled)\n ):\n return UNREACHABLE\n if not cancelled:\n return NOT_PENDING\n if by_this_call is None:\n return CANCELLED_UNPROVEN\n return WITHDRAWN_BY_THIS_CALL if by_this_call else ALREADY_CANCELLED\n' },
1394
- { path: "dashboard/manifest.json", contents: '{\n "name": "pushary",\n "label": "Pushary",\n "description": "Approvals Pushary is carrying to your phone, answerable from Hermes Desktop",\n "version": "1.0.12",\n "tab": { "hidden": true },\n "entry": "web.js",\n "api": "plugin_api.py"\n}\n' },
1394
+ { path: "dashboard/manifest.json", contents: '{\n "name": "pushary",\n "label": "Pushary",\n "description": "Approvals Pushary is carrying to your phone, answerable from Hermes Desktop",\n "version": "1.0.13",\n "tab": { "hidden": true },\n "entry": "web.js",\n "api": "plugin_api.py"\n}\n' },
1395
1395
  { path: "dashboard/plugin_api.py", contents: `import importlib
1396
1396
  import sys
1397
1397
  import time
@@ -1643,6 +1643,7 @@ def shared_answers() -> DesktopAnswers:
1643
1643
 
1644
1644
  import hashlib
1645
1645
  import contextvars
1646
+ import importlib.util
1646
1647
  import json
1647
1648
  import logging
1648
1649
  import math
@@ -1658,14 +1659,21 @@ import time
1658
1659
  from collections.abc import Sequence
1659
1660
  from datetime import datetime, timezone
1660
1661
  from pathlib import Path, PureWindowsPath
1661
- from typing import NamedTuple
1662
+ from typing import TYPE_CHECKING, NamedTuple
1662
1663
 
1663
1664
  from . import api
1664
1665
 
1666
+ if TYPE_CHECKING:
1667
+ from persistence_assembly import Persistence
1668
+
1665
1669
  logger = logging.getLogger(__name__)
1666
1670
  MAX_DATABASE_ROWS = 25_000
1667
1671
  MAX_DATABASE_BYTES = 64_000_000
1668
1672
  MAX_SOURCE_BYTES = 64_000_000
1673
+ MAX_LINEAGE_SEGMENTS = 100
1674
+ PAGE_ROWS = 1_000
1675
+ READ_DEADLINE_SECONDS = 2
1676
+ MAX_SNAPSHOT_ATTEMPTS = 3
1669
1677
  POLL_SECONDS = 5
1670
1678
  SNAPSHOT_REFRESH_SECONDS = 60
1671
1679
  AUTHORIZATION_LIFETIME_SECONDS = 60
@@ -1692,6 +1700,10 @@ CLI_HELPER_RECORD_MAX_BYTES = 8192
1692
1700
  CLI_HELPER_RECORD_OPEN_FLAGS = os.O_RDONLY | getattr(os, "O_BINARY", 0) | getattr(os, "O_NOFOLLOW", 0) | getattr(os, "O_NONBLOCK", 0)
1693
1701
 
1694
1702
 
1703
+ class HistoryTooLarge(ValueError):
1704
+ pass
1705
+
1706
+
1695
1707
  class _Authorization(NamedTuple):
1696
1708
  inputs: tuple[object, ...]
1697
1709
  expires_at: float
@@ -1768,23 +1780,121 @@ def normalize_messages(rows: Sequence[object]) -> list[dict[str, object]]:
1768
1780
  return messages
1769
1781
 
1770
1782
 
1771
- def read_display_history(database_path: Path, session_id: str) -> list[dict[str, object]]:
1783
+ def _require_primary_lineage(lineage: Sequence[str], root: dict[str, object] | None) -> None:
1784
+ if not lineage or len(lineage) > MAX_LINEAGE_SEGMENTS:
1785
+ raise ValueError("Unsupported Hermes compression lineage")
1786
+ if not root or root.get("parent_session_id") or root.get("source") in ("subagent", "tool"):
1787
+ raise ValueError("Child history is not a primary conversation")
1788
+
1789
+
1790
+ def _row_size(row: dict[str, object]) -> int:
1791
+ return sum(len(str(value).encode("utf-8", "surrogatepass")) for value in row.values() if value is not None)
1792
+
1793
+
1794
+ def _page_rows(store: Persistence, session_id: str, deadline: float) -> list[dict[str, object]]:
1795
+ from persistence.conversation.messages import TranscriptRead, TranscriptView
1796
+
1797
+ rows: list[dict[str, object]] = []
1798
+ size = 0
1799
+ while True:
1800
+ page = store.messages.read_transcript(
1801
+ session_id, TranscriptRead(view=TranscriptView.DISPLAY, limit=PAGE_ROWS, offset=len(rows)))
1802
+ wire_rows = [row.as_wire_row() for row in page]
1803
+ size += sum(map(_row_size, wire_rows))
1804
+ rows.extend(wire_rows)
1805
+ if len(rows) > MAX_DATABASE_ROWS or size > MAX_DATABASE_BYTES:
1806
+ raise HistoryTooLarge("Hermes history exceeds the bounded reader limit")
1807
+ if len(page) < PAGE_ROWS:
1808
+ return rows
1809
+ if time.monotonic() > deadline:
1810
+ raise TimeoutError("Hermes history read passed its deadline")
1811
+
1812
+
1813
+ def _whole_display_rows(store: Persistence, session_id: str) -> list[dict[str, object]]:
1814
+ from persistence.conversation.messages import TranscriptRead, TranscriptView
1815
+
1816
+ page = store.messages.read_transcript(session_id, TranscriptRead(view=TranscriptView.DISPLAY, include_lineage=True))
1817
+ rows = [row.as_wire_row() for row in page]
1818
+ if len(rows) > MAX_DATABASE_ROWS or sum(map(_row_size, rows)) > MAX_DATABASE_BYTES:
1819
+ raise HistoryTooLarge("Hermes history exceeds the bounded reader limit")
1820
+ return rows
1821
+
1822
+
1823
+ def _require_bounded_rows(store: Persistence, session_id: str) -> None:
1824
+ from persistence.conversation.messages import ResumeTooLarge
1825
+
1826
+ try:
1827
+ store.messages.assert_resume_safe(session_id, max_messages=MAX_DATABASE_ROWS)
1828
+ except ResumeTooLarge as refusal:
1829
+ raise HistoryTooLarge("Hermes history exceeds the bounded reader limit") from refusal
1830
+
1831
+
1832
+ class _ConversationState(NamedTuple):
1833
+ revision: object
1834
+ stored_rows: tuple[int, int, int]
1835
+ displayed_messages: tuple[int, ...]
1836
+ active_messages: tuple[tuple[int, ...], ...]
1837
+
1838
+
1839
+ def _conversation_state(store: Persistence, session_id: str) -> _ConversationState:
1840
+ revision = store.messages.conversation_revision(session_id, include_lineage=True)
1841
+ lineage = revision.lineage_ids
1842
+ return _ConversationState(
1843
+ revision,
1844
+ store.messages.transcript_cursor_state(session_id, revision.max_active_id, lineage),
1845
+ tuple(store.messages.display_count(segment) for segment in lineage),
1846
+ tuple(store.messages.active_message_ids(segment) for segment in lineage),
1847
+ )
1848
+
1849
+
1850
+ def _display_rows(store: Persistence, session_id: str, deadline: float) -> list[dict[str, object]]:
1851
+ if store.sessions.get(session_id) is None:
1852
+ raise ValueError("Hermes session is not in this profile")
1853
+ lineage = store.lineage.resume_lineage_ids(session_id)
1854
+ root = store.sessions.get(lineage[0]) if lineage else None
1855
+ _require_primary_lineage(lineage, root.as_session_row() if root else None)
1856
+ if len(lineage) == 1 and store.messages.display_index_complete(session_id):
1857
+ return _page_rows(store, session_id, deadline)
1858
+ return _whole_display_rows(store, session_id)
1859
+
1860
+
1861
+ def _read_through_storage_interface(store: Persistence, session_id: str) -> list[dict[str, object]]:
1862
+ deadline = time.monotonic() + READ_DEADLINE_SECONDS
1863
+ for _ in range(MAX_SNAPSHOT_ATTEMPTS):
1864
+ refusal: ValueError | None = None
1865
+ rows: list[dict[str, object]] = []
1866
+ with store.messages.read_snapshot():
1867
+ _require_bounded_rows(store, session_id)
1868
+ before = _conversation_state(store, session_id)
1869
+ try:
1870
+ rows = _display_rows(store, session_id, deadline)
1871
+ except HistoryTooLarge:
1872
+ raise
1873
+ except ValueError as error:
1874
+ refusal = error
1875
+ unchanged = _conversation_state(store, session_id) == before
1876
+ if unchanged and refusal is not None:
1877
+ raise refusal
1878
+ if unchanged:
1879
+ return rows
1880
+ if time.monotonic() > deadline:
1881
+ break
1882
+ raise TimeoutError("Hermes history kept changing while it was read")
1883
+
1884
+
1885
+ def _read_through_session_database(database_path: Path, session_id: str) -> list[dict[str, object]]:
1772
1886
  from hermes_state import SessionDB
1773
1887
 
1774
1888
  database = SessionDB(db_path=database_path, read_only=True)
1775
1889
  try:
1776
1890
  connection = database._conn
1777
- deadline = time.monotonic() + 2
1891
+ deadline = time.monotonic() + READ_DEADLINE_SECONDS
1778
1892
  connection.set_progress_handler(lambda: int(time.monotonic() > deadline), 1000)
1779
1893
  connection.execute("BEGIN")
1780
1894
  if database.get_session(session_id) is None:
1781
1895
  raise ValueError("Hermes session is not in this profile")
1782
1896
  lineage = database._resume_lineage_ids(session_id)
1783
- if not lineage or len(lineage) > 100:
1784
- raise ValueError("Unsupported Hermes compression lineage")
1785
- root = database.get_session(lineage[0])
1786
- if not root or root.get("parent_session_id") or root.get("source") in ("subagent", "tool"):
1787
- raise ValueError("Child history is not a primary conversation")
1897
+ _require_primary_lineage(lineage, database.get_session(lineage[0]) if lineage else None)
1788
1898
  columns = [row[1] for row in connection.execute("PRAGMA table_info(messages)")]
1789
1899
  required = {"id", "session_id", "role", "content", "timestamp", "active", "compacted", "display_kind", "message_uid"}
1790
1900
  if not required.issubset(columns):
@@ -1796,13 +1906,25 @@ def read_display_history(database_path: Path, session_id: str) -> list[dict[str,
1796
1906
  f"SELECT COUNT(*), SUM({row_bytes}) FROM messages WHERE session_id IN ({placeholders})", lineage
1797
1907
  ).fetchone()
1798
1908
  if count > MAX_DATABASE_ROWS or (size or 0) > MAX_DATABASE_BYTES:
1799
- raise ValueError("Hermes history exceeds the bounded reader limit")
1800
- rows = database.get_messages(session_id, include_compacted=True, include_ancestors=True, limit=MAX_DATABASE_ROWS)
1801
- return normalize_messages(rows)
1909
+ raise HistoryTooLarge("Hermes history exceeds the bounded reader limit")
1910
+ return database.get_messages(session_id, include_compacted=True, include_ancestors=True, limit=MAX_DATABASE_ROWS)
1802
1911
  finally:
1803
1912
  database.close()
1804
1913
 
1805
1914
 
1915
+ def _has_storage_interface() -> bool:
1916
+ return importlib.util.find_spec("persistence_assembly") is not None
1917
+
1918
+
1919
+ def read_display_history(database_path: Path, session_id: str) -> list[dict[str, object]]:
1920
+ if not _has_storage_interface():
1921
+ return normalize_messages(_read_through_session_database(database_path, session_id))
1922
+ from persistence_assembly import open_persistence_reader
1923
+
1924
+ with open_persistence_reader(database_path, patience_s=READ_DEADLINE_SECONDS) as store:
1925
+ return normalize_messages(_read_through_storage_interface(store, session_id))
1926
+
1927
+
1806
1928
  def write_snapshot(path: Path, session_id: str, messages: list[dict[str, object]], error: str | None = None, completed: bool = False) -> None:
1807
1929
  value = {"version": 1, "sessionId": session_id, "updatedAtMs": int(time.time() * 1000), "messages": messages, "completed": completed}
1808
1930
  if error:
@@ -2069,6 +2191,7 @@ def _export_loop(database_path: Path, session_id: str, key: str, command: list[s
2069
2191
  source_state = None
2070
2192
  written = None
2071
2193
  warned = False
2194
+ too_large = False
2072
2195
  revoked = False
2073
2196
  try:
2074
2197
  while True:
@@ -2079,13 +2202,15 @@ def _export_loop(database_path: Path, session_id: str, key: str, command: list[s
2079
2202
  now = time.time()
2080
2203
  refresh_due = ending or _snapshot_refresh_due(written_at, now)
2081
2204
  current_state = _source_state(database_path)
2082
- if refresh_due or current_state != source_state:
2205
+ if refresh_due or (current_state != source_state and not too_large):
2083
2206
  source_state = current_state
2084
2207
  error = None
2208
+ too_large = False
2085
2209
  try:
2086
2210
  messages = read_display_history(database_path, session_id)
2087
2211
  except Exception as failure:
2088
2212
  messages, error = [], SOURCE_UNAVAILABLE
2213
+ too_large = isinstance(failure, HistoryTooLarge)
2089
2214
  if not _is_permanent_source_failure(failure):
2090
2215
  source_state = None
2091
2216
  try:
@@ -2172,7 +2297,7 @@ def stop_history(session_id: str) -> None:
2172
2297
  if thread.is_alive():
2173
2298
  logger.warning("[pushary] Hermes final history export is still pending")
2174
2299
  ` },
2175
- { path: "host.py", contents: 'import os\n\nTRANSPORT_NAME = "pushary"\n\nHOOK_TIMEOUT_DEFAULT_SECONDS = 30.0\nHOOK_TIMEOUT_MAX_SECONDS = 600.0\n\nGATE_HEADROOM_SECONDS = 5.0\nGATE_MIN_SECONDS = 5.0\nGATE_MAX_SECONDS = 55.0\n\n# The last Hermes that runs a pre_tool_call callback to completion. Anything\n# after this abandons one that outlives plugins.hook_callback_timeout.\nUNBOUNDED_THROUGH_VERSION = (0, 20, 5)\n\n\ndef _config():\n try:\n from hermes_cli.config import load_config_readonly\n\n loaded = load_config_readonly()\n except Exception:\n return {}\n return loaded if isinstance(loaded, dict) else {}\n\n\ndef _section(node, *path):\n for key in path:\n node = node.get(key) if isinstance(node, dict) else None\n if node is None:\n return {}\n return node if isinstance(node, dict) else {}\n\n\ndef profile_secret(name):\n try:\n from agent.secret_scope import get_secret\n except Exception:\n return os.environ.get(name) or None\n try:\n return get_secret(name) or None\n except Exception:\n return None\n\n\ndef hermes_version_label():\n try:\n from importlib.metadata import version\n\n return version("hermes-cli")\n except Exception:\n try:\n import hermes_cli\n\n label = getattr(hermes_cli, "__version__", None)\n except Exception:\n return None\n return str(label) if label else None\n\n\ndef _hermes_version():\n """This Hermes as a comparable tuple, or None when it will not say."""\n raw = hermes_version_label()\n if not raw:\n return None\n parts = []\n for piece in str(raw).split(".")[:3]:\n digits = ""\n for char in piece:\n if not char.isdigit():\n break\n digits += char\n if not digits:\n return None\n parts.append(int(digits))\n while len(parts) < 3:\n parts.append(0)\n return tuple(parts)\n\n\ndef bounds_pre_tool_call():\n """Whether this Hermes abandons a slow pre_tool_call callback.\n\n The timeout was added after 0.20.5, which runs plugin hooks to completion.\n Clamping the wait on a host that would never have cut it off just shortens\n the window the user has to answer, for nothing.\n\n Unreadable means assume bounded. A wait that is shorter than it had to be\n costs the user seconds; a wait longer than the host allows costs them the\n answer they already gave.\n\n That rule is why the private symbol is not asked on its own. `hasattr` on\n `_HOOK_TIMEOUT_FAIL_CLOSED_HOOKS` cannot tell "this host runs hooks to\n completion" apart from "the private name moved", and those two answers want\n opposite behaviour: the first earns the full window, the second spends 55\n seconds against a budget of 30 and loses an answer the user already gave.\n A rename is the likelier of the two, because a private name is the one thing\n a host is free to change. So the symbol is taken as proof of bounded, and\n only a version this side of the timeout landing is taken as proof of the\n other. Anything unreadable falls to bounded.\n """\n try:\n from hermes_cli import plugins\n except Exception:\n return True\n if hasattr(plugins, "_HOOK_TIMEOUT_FAIL_CLOSED_HOOKS"):\n return True\n version = _hermes_version()\n if version is None:\n return True\n return version > UNBOUNDED_THROUGH_VERSION\n\n\ndef hook_callback_timeout_seconds():\n raw = _section(_config(), "plugins").get("hook_callback_timeout")\n if raw is None:\n return HOOK_TIMEOUT_DEFAULT_SECONDS\n try:\n timeout = float(raw)\n except (TypeError, ValueError):\n return HOOK_TIMEOUT_DEFAULT_SECONDS\n if timeout < 0:\n return HOOK_TIMEOUT_DEFAULT_SECONDS\n return min(timeout, HOOK_TIMEOUT_MAX_SECONDS)\n\n\ndef gate_budget_seconds(requested_seconds):\n if not bounds_pre_tool_call():\n return max(1.0, min(float(requested_seconds), GATE_MAX_SECONDS))\n timeout = hook_callback_timeout_seconds()\n ceiling = (\n GATE_MAX_SECONDS\n if timeout <= 0\n else max(GATE_MIN_SECONDS, timeout - GATE_HEADROOM_SECONDS)\n )\n return max(1.0, min(float(requested_seconds), ceiling, GATE_MAX_SECONDS))\n\n\ndef terminal_config():\n return _section(_config(), "terminal")\n\n\ndef pushary_is_selected_transport():\n selected = _section(_config(), "security", "approval").get("transport")\n return str(selected or "").strip().lower() == TRANSPORT_NAME\n' },
2300
+ { path: "host.py", contents: 'import os\n\nTRANSPORT_NAME = "pushary"\n\nHOOK_TIMEOUT_DEFAULT_SECONDS = 30.0\nHOOK_TIMEOUT_MAX_SECONDS = 600.0\n\nGATE_HEADROOM_SECONDS = 5.0\nGATE_MIN_SECONDS = 5.0\nGATE_MAX_SECONDS = 55.0\n\n# The last Hermes that runs a pre_tool_call callback to completion. Anything\n# after this abandons one that outlives plugins.hook_callback_timeout.\nUNBOUNDED_THROUGH_VERSION = (0, 20, 5)\nUNSTAMPED_VERSION = (0, 0, 0)\n\n\ndef _config():\n try:\n from hermes_cli.config import load_config_readonly\n\n loaded = load_config_readonly()\n except Exception:\n return {}\n return loaded if isinstance(loaded, dict) else {}\n\n\ndef _section(node, *path):\n for key in path:\n node = node.get(key) if isinstance(node, dict) else None\n if node is None:\n return {}\n return node if isinstance(node, dict) else {}\n\n\ndef profile_secret(name):\n try:\n from agent.secret_scope import get_secret\n except Exception:\n return os.environ.get(name) or None\n try:\n return get_secret(name) or None\n except Exception:\n return None\n\n\ndef hermes_version_label():\n try:\n from importlib.metadata import version\n\n return version("hermes-cli")\n except Exception:\n try:\n import hermes_cli\n\n label = getattr(hermes_cli, "__version__", None)\n except Exception:\n return None\n return str(label) if label else None\n\n\ndef _hermes_version():\n """This Hermes as a comparable tuple, or None when it will not say."""\n raw = hermes_version_label()\n if not raw:\n return None\n parts = []\n for piece in str(raw).split(".")[:3]:\n digits = ""\n for char in piece:\n if not char.isdigit():\n break\n digits += char\n if not digits:\n return None\n parts.append(int(digits))\n while len(parts) < 3:\n parts.append(0)\n return tuple(parts)\n\n\ndef bounds_pre_tool_call():\n """Whether this Hermes abandons a slow pre_tool_call callback.\n\n The timeout was added after 0.20.5, which runs plugin hooks to completion.\n Clamping the wait on a host that would never have cut it off just shortens\n the window the user has to answer, for nothing.\n\n Unreadable means assume bounded. A wait that is shorter than it had to be\n costs the user seconds; a wait longer than the host allows costs them the\n answer they already gave.\n\n That rule is why the private symbol is not asked on its own. `hasattr` on\n `_HOOK_TIMEOUT_FAIL_CLOSED_HOOKS` cannot tell "this host runs hooks to\n completion" apart from "the private name moved", and those two answers want\n opposite behaviour: the first earns the full window, the second spends 55\n seconds against a budget of 30 and loses an answer the user already gave.\n A rename is the likelier of the two, because a private name is the one thing\n a host is free to change. So the symbol is taken as proof of bounded, and\n only a version this side of the timeout landing is taken as proof of the\n other. Anything unreadable falls to bounded.\n """\n try:\n from hermes_cli import plugins\n except Exception:\n return True\n if hasattr(plugins, "_HOOK_TIMEOUT_FAIL_CLOSED_HOOKS"):\n return True\n version = _hermes_version()\n if version is None or version == UNSTAMPED_VERSION:\n return True\n return version > UNBOUNDED_THROUGH_VERSION\n\n\ndef hook_callback_timeout_seconds():\n raw = _section(_config(), "plugins").get("hook_callback_timeout")\n if raw is None:\n return HOOK_TIMEOUT_DEFAULT_SECONDS\n try:\n timeout = float(raw)\n except (TypeError, ValueError):\n return HOOK_TIMEOUT_DEFAULT_SECONDS\n if timeout < 0:\n return HOOK_TIMEOUT_DEFAULT_SECONDS\n return min(timeout, HOOK_TIMEOUT_MAX_SECONDS)\n\n\ndef gate_budget_seconds(requested_seconds):\n if not bounds_pre_tool_call():\n return max(1.0, min(float(requested_seconds), GATE_MAX_SECONDS))\n timeout = hook_callback_timeout_seconds()\n ceiling = (\n GATE_MAX_SECONDS\n if timeout <= 0\n else max(GATE_MIN_SECONDS, timeout - GATE_HEADROOM_SECONDS)\n )\n return max(1.0, min(float(requested_seconds), ceiling, GATE_MAX_SECONDS))\n\n\ndef terminal_config():\n return _section(_config(), "terminal")\n\n\ndef pushary_is_selected_transport():\n selected = _section(_config(), "security", "approval").get("transport")\n return str(selected or "").strip().lower() == TRANSPORT_NAME\n' },
2176
2301
  { path: "identity.py", contents: 'import hashlib\nimport os\nimport re\nimport socket\nfrom pathlib import Path\n\nDEFAULT_AGENT_NAME = "Hermes"\nMAX_ID_LENGTH = 128\nSHARED_MACHINE_ID_FILE = Path.home() / ".pushary" / "machine-id"\nSHARED_MACHINE_ID_PATTERN = re.compile(r"^[A-Za-z0-9-]{1,128}$")\n\n_session_id = None\n\n\ndef agent_name():\n return os.environ.get("PUSHARY_AGENT_NAME", DEFAULT_AGENT_NAME)\n\n\ndef labelled_agent_name(requested):\n project = str(requested or "").partition(" - ")[2].strip()\n return f"{agent_name()} - {project}" if project else agent_name()\n\n\ndef shared_machine_id(path=None):\n try:\n value = (path or SHARED_MACHINE_ID_FILE).read_text(encoding="utf-8").strip()\n except OSError:\n return None\n return value if SHARED_MACHINE_ID_PATTERN.match(value) else None\n\n\ndef hostname_machine_id():\n try:\n host = socket.gethostname()\n except Exception:\n return None\n if not host:\n return None\n return hashlib.sha256(host.encode("utf-8")).hexdigest()[:8]\n\n\ndef machine_id():\n return shared_machine_id() or hostname_machine_id()\n\n\ndef remember_session(value):\n global _session_id\n if value:\n _session_id = str(value)[:MAX_ID_LENGTH]\n\n\ndef forget_session():\n global _session_id\n _session_id = None\n\n\ndef session_id():\n return _session_id\n' },
2177
2302
  { path: "installation.py", contents: `import json
2178
2303
  import logging
@@ -2303,7 +2428,7 @@ def record_plugin_load(approval_transport_registered, home=None, pid=None, now=N
2303
2428
  logger.debug("[pushary] could not record the plugin load: %s", exc)
2304
2429
  return None
2305
2430
  ` },
2306
- { path: "plugin.yaml", contents: 'name: pushary\nversion: 1.0.12\ndescription: Push notifications and human-in-the-loop for Hermes Agent via Pushary\nauthor: RalphNex OU\nrequires_env:\n - name: PUSHARY_API_KEY\n description: Your Pushary API key\n url: https://pushary.com/sign-up?from=hermes\n secret: true\nconfig_schema:\n api_key:\n type: secret\n env: PUSHARY_API_KEY\n label: Pushary API key\n description: "Get one at pushary.com/sign-up?from=hermes"\n required: true\nprovides_tools:\n - pushary_remind\n - pushary_notify\n - pushary_ask\n - pushary_wait\n - pushary_cancel\n - pushary_propose_scope\n - pushary_enroll\n - pushary_ask_end_user\nprovides_hooks:\n - pre_llm_call\n - pre_tool_call\n - post_tool_call\n - on_session_start\n - on_session_end\n - on_session_finalize\n - post_approval_response\nprovides_approval_transports:\n - pushary\n' },
2431
+ { path: "plugin.yaml", contents: 'name: pushary\nversion: 1.0.13\ndescription: Push notifications and human-in-the-loop for Hermes Agent via Pushary\nauthor: RalphNex OU\nrequires_env:\n - name: PUSHARY_API_KEY\n description: Your Pushary API key\n url: https://pushary.com/sign-up?from=hermes\n secret: true\nconfig_schema:\n api_key:\n type: secret\n env: PUSHARY_API_KEY\n label: Pushary API key\n description: "Get one at pushary.com/sign-up?from=hermes"\n required: true\nprovides_tools:\n - pushary_remind\n - pushary_notify\n - pushary_ask\n - pushary_wait\n - pushary_cancel\n - pushary_propose_scope\n - pushary_enroll\n - pushary_ask_end_user\nprovides_hooks:\n - pre_llm_call\n - pre_tool_call\n - post_tool_call\n - on_session_start\n - on_session_end\n - on_session_finalize\n - post_approval_response\nprovides_approval_transports:\n - pushary\n' },
2307
2432
  { path: "README.md", contents: "# Pushary for Hermes\n\nAsk a question in Hermes and answer it on your phone. Try it with your own device before routing command approvals there.\n\n## Connect your phone\n\n1. [Set up your Pushary Agent account](https://pushary.com/sign-up?from=ai-coding&utm_source=hermes-plugin&utm_medium=quickstart&utm_campaign=first-question). Pair your phone with that account and get its API key from Agent settings.\n2. In your terminal, install the catalog plugin:\n\n ```sh\n hermes plugins install pushary\n ```\n\n3. Enter `PUSHARY_API_KEY` when Hermes prompts for it. If you missed the prompt, save the key in the plugin\u2019s settings in Hermes Desktop. Keep it out of chat. Start a new Hermes session (for a running gateway, use `hermes gateway restart`).\n\n## Try one question\n\nTell Hermes: **Use `pushary_ask` to ask me \u201CDid this test reach your phone?\u201D Report my answer and do nothing else.** Open the question on your paired phone and tap **Yes** or **No**. Hermes should report the answer you tapped.\n\nIf nothing arrives, check the account and notification permissions on your phone. A pending question is still live: wait for the same question rather than sending another. If Pushary hands it back to Hermes, answer the local prompt instead. No answer is not approval.\n\nCommand approvals are separate from this test. To route them to your phone, set `security.approval.transport` to `pushary`. Set `security.approval.transport_fallback` to `builtin` if you want Hermes\u2019s local prompt after a safe handoff; an unconfirmed withdrawal does not authorize the command. See the [plugin guide](https://github.com/Pushary/hermes-plugin-pushary#readme) for approval routing and what the plugin reads and sends.\n" },
2308
2433
  { path: "schemas.py", contents: `PUSHARY_REMIND = {
2309
2434
  "name": "pushary_remind",
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  pusharyDir
3
- } from "./chunk-O54TEHYJ.js";
3
+ } from "./chunk-ZGVMX36I.js";
4
4
  import {
5
5
  writeFileAtomic
6
6
  } from "./chunk-PM2NRK6Y.js";
@@ -2,7 +2,7 @@ import {
2
2
  localRepoKey,
3
3
  normalizeRepoRemote,
4
4
  parseGitBranch
5
- } from "./chunk-AY37CFHF.js";
5
+ } from "./chunk-GOSMCOHB.js";
6
6
 
7
7
  // src/repo.ts
8
8
  import { existsSync, readFileSync, statSync } from "fs";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  autoUpdateLock
3
- } from "./chunk-O54TEHYJ.js";
3
+ } from "./chunk-ZGVMX36I.js";
4
4
  import {
5
5
  installPackageGlobally,
6
6
  npmErrorMessage,
7
7
  throwIfNpmRefusesInstall
8
- } from "./chunk-3K2HA65U.js";
8
+ } from "./chunk-J35H5XWH.js";
9
9
  import {
10
10
  writeJsonAtomic
11
11
  } from "./chunk-PM2NRK6Y.js";
@@ -14,7 +14,7 @@ import {
14
14
  } from "./chunk-CXQWDQCJ.js";
15
15
 
16
16
  // src/upgrade-lock.ts
17
- import { fork } from "child_process";
17
+ import { fork, spawnSync } from "child_process";
18
18
  import { createHash } from "crypto";
19
19
  import { existsSync, mkdirSync, readFileSync, realpathSync, statSync, unlinkSync } from "fs";
20
20
  import { createServer, Server } from "net";
@@ -100,6 +100,9 @@ var runningCliInstallerIn = (processes, ownPid) => {
100
100
  };
101
101
 
102
102
  // src/upgrade-lock.ts
103
+ var rejectConnection = (socket) => {
104
+ socket.destroy();
105
+ };
103
106
  var LOCK_HOST = "127.0.0.1";
104
107
  var LOCK_PORT_START = 49152;
105
108
  var LOCK_PORT_COUNT = 16384;
@@ -109,6 +112,12 @@ var LOCK_HANDLE = "pushary-upgrade-lock-handle";
109
112
  var HANDOFF_TIMEOUT_MS = 1e4;
110
113
  var FINISH_TIMEOUT_MS = 5 * 60 * 1e3;
111
114
  var KERNEL_LOCK_FORMAT = "kernel-v1";
115
+ var LOCK_PORT_CANDIDATE_COUNT = 8;
116
+ var RESERVED_PORT_CODE = "EACCES";
117
+ var PORT_IN_USE_CODE = "EADDRINUSE";
118
+ var EXCLUDED_PORT_RANGES_COMMAND = ["int", "ipv4", "show", "excludedportrange", "protocol=tcp"];
119
+ var EXCLUDED_PORT_RANGES_TIMEOUT_MS = 5e3;
120
+ var windowsNetshPath = () => `${process.env.SystemRoot?.trim() || "C:\\Windows"}\\System32\\netsh.exe`;
112
121
  var heldLocks = /* @__PURE__ */ new Map();
113
122
  var PENDING_INSTALL_STALE_AFTER_MS = 60 * 6e4;
114
123
  var PLATFORMS_WITH_PROCESS_TABLE = /* @__PURE__ */ new Set(["darwin", "linux"]);
@@ -116,7 +125,65 @@ var canonicalLockPath = (path) => {
116
125
  mkdirSync(dirname(path), { recursive: true });
117
126
  return join(realpathSync(dirname(path)), basename(path));
118
127
  };
119
- var lockPort = (path) => LOCK_PORT_START + createHash("sha256").update(path).digest().readUInt32BE(0) % LOCK_PORT_COUNT;
128
+ var hashedLockPort = (seed) => LOCK_PORT_START + createHash("sha256").update(seed).digest().readUInt32BE(0) % LOCK_PORT_COUNT;
129
+ var candidateSeed = (path, index) => index === 0 ? path : `${path}\0${index}`;
130
+ var upgradeLockPorts = (path) => [...new Set(Array.from({ length: LOCK_PORT_CANDIDATE_COUNT }, (_, index) => hashedLockPort(candidateSeed(path, index))))];
131
+ var errorCode = (error) => error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
132
+ var EXCLUDED_RANGE_ROW = /^\s*(\d+)\s+(\d+)(?:\s+\*)?\s*$/;
133
+ var EXCLUDED_RANGE_HEADER_RULE = /^\s*-+\s+-+\s*$/;
134
+ var parseExcludedPortRanges = (output) => {
135
+ const lines = output.split(/\r?\n/);
136
+ if (!lines.some((line) => EXCLUDED_RANGE_HEADER_RULE.test(line))) return void 0;
137
+ return lines.flatMap((line) => {
138
+ const row = EXCLUDED_RANGE_ROW.exec(line);
139
+ return row ? [{ start: Number(row[1]), end: Number(row[2]) }] : [];
140
+ });
141
+ };
142
+ var readExcludedPortRangesWithNetsh = () => {
143
+ const result = spawnSync(windowsNetshPath(), [...EXCLUDED_PORT_RANGES_COMMAND], { encoding: "utf8", timeout: EXCLUDED_PORT_RANGES_TIMEOUT_MS, windowsHide: true });
144
+ return result.status === 0 && typeof result.stdout === "string" ? result.stdout : void 0;
145
+ };
146
+ var listenExclusivelyOnLoopback = (port) => new Promise((resolve, reject) => {
147
+ const server = createServer(rejectConnection);
148
+ const failed = (error) => {
149
+ server.close();
150
+ reject(error);
151
+ };
152
+ server.once("error", failed);
153
+ server.listen({ host: LOCK_HOST, port, exclusive: true }, () => {
154
+ server.off("error", failed);
155
+ resolve(server);
156
+ });
157
+ });
158
+ var DEFAULT_PORT_ACCESS = {
159
+ listenOnLockPort: listenExclusivelyOnLoopback,
160
+ readExcludedPortRanges: readExcludedPortRangesWithNetsh
161
+ };
162
+ var portIsInRanges = (port, ranges) => ranges.some((range) => port >= range.start && port <= range.end);
163
+ var bindFirstUsableLockPort = async (path, platform, access) => {
164
+ const ports = upgradeLockPorts(path);
165
+ let excludedRanges;
166
+ let excludedRangesRead = false;
167
+ const windowsReserves = (port) => {
168
+ if (!excludedRangesRead) {
169
+ excludedRangesRead = true;
170
+ const output = access.readExcludedPortRanges();
171
+ excludedRanges = output === void 0 ? void 0 : parseExcludedPortRanges(output);
172
+ }
173
+ return excludedRanges !== void 0 && portIsInRanges(port, excludedRanges);
174
+ };
175
+ for (const port of ports) {
176
+ try {
177
+ return { kind: "bound", server: await access.listenOnLockPort(port) };
178
+ } catch (error) {
179
+ const code = errorCode(error);
180
+ if (code === PORT_IN_USE_CODE) return { kind: "in_use" };
181
+ if (platform !== "win32" || code !== RESERVED_PORT_CODE || !windowsReserves(port)) throw error;
182
+ }
183
+ }
184
+ return { kind: "every_port_reserved", ports };
185
+ };
186
+ var everyPortReservedReason = (ports) => `Windows reserves every loopback port the upgrade lock can use (${ports.join(", ")}). \`netsh int ipv4 show excludedportrange protocol=tcp\` lists the reserved ranges.`;
120
187
  var readLockRecord = (path) => {
121
188
  try {
122
189
  const value = JSON.parse(readFileSync(path, "utf8"));
@@ -175,9 +242,6 @@ var pendingInstallReason = (pending, path) => {
175
242
  return `${UNFINISHED_INSTALLATION}. To clear it, ${clearingSteps(path)}`;
176
243
  }
177
244
  };
178
- var rejectConnection = (socket) => {
179
- socket.destroy();
180
- };
181
245
  var inheritLock = (path) => new Promise((resolve) => {
182
246
  const done = (claim) => {
183
247
  clearTimeout(timer);
@@ -189,7 +253,7 @@ var inheritLock = (path) => new Promise((resolve) => {
189
253
  const receive = (message, handle) => {
190
254
  if (message !== LOCK_HANDLE || !(handle instanceof Server)) return;
191
255
  const address = handle.address();
192
- if (address === null || typeof address === "string" || address.port !== lockPort(path) || address.address !== LOCK_HOST) {
256
+ if (address === null || typeof address === "string" || !upgradeLockPorts(path).includes(address.port) || address.address !== LOCK_HOST) {
193
257
  handle.close();
194
258
  done({ kind: "unavailable", reason: "Invalid inherited upgrade lock" });
195
259
  return;
@@ -207,19 +271,17 @@ var inheritLock = (path) => new Promise((resolve) => {
207
271
  if (error) disconnected();
208
272
  });
209
273
  });
210
- var claimUpgradeLock = async (request = {}) => {
274
+ var claimUpgradeLock = async (request = {}, portAccess = DEFAULT_PORT_ACCESS) => {
211
275
  let server;
212
276
  try {
213
277
  const path = canonicalLockPath(request.lockPath ?? autoUpdateLock());
214
278
  const inheritedPath = process.env[INHERITED_LOCK_ENV];
215
279
  delete process.env[INHERITED_LOCK_ENV];
216
280
  if (inheritedPath === path && !heldLocks.has(path)) return await inheritLock(path);
217
- server = createServer(rejectConnection);
218
- const listener = server;
219
- await new Promise((resolve, reject) => {
220
- listener.once("error", reject);
221
- listener.listen({ host: LOCK_HOST, port: lockPort(path), exclusive: true }, resolve);
222
- });
281
+ const binding = await bindFirstUsableLockPort(path, request.platform ?? process.platform, portAccess);
282
+ if (binding.kind === "in_use") return { kind: "held", holderPid: readLockRecord(path).pid };
283
+ if (binding.kind === "every_port_reserved") return { kind: "unavailable", reason: everyPortReservedReason(binding.ports) };
284
+ server = binding.server;
223
285
  const record = readLockRecord(path);
224
286
  const isAlive = request.isAlive ?? isProcessAlive;
225
287
  const pending = record.installationPending ? judgePendingInstall(path, record, request, isAlive) : ENDED;
@@ -236,9 +298,6 @@ var claimUpgradeLock = async (request = {}) => {
236
298
  return { kind: "acquired" };
237
299
  } catch (error) {
238
300
  server?.close();
239
- if (error instanceof Error && "code" in error && error.code === "EADDRINUSE") {
240
- return { kind: "held", holderPid: readLockRecord(request.lockPath ?? autoUpdateLock()).pid };
241
- }
242
301
  return { kind: "unavailable", reason: npmErrorMessage(error) };
243
302
  }
244
303
  };
@@ -308,6 +367,8 @@ var installWithUpgradeLock = (request, lockPath = autoUpdateLock(), runNpm) => {
308
367
  export {
309
368
  PENDING_INSTALL_STALE_AFTER_MS,
310
369
  canonicalLockPath,
370
+ upgradeLockPorts,
371
+ parseExcludedPortRanges,
311
372
  claimUpgradeLock,
312
373
  leftAnUnfinishedInstallHere,
313
374
  ownsUpgradeLock,
@@ -1,35 +1,35 @@
1
1
  import {
2
2
  MANAGED_CLAUDE_SETTINGS_BY_PLATFORM
3
- } from "./chunk-QICIMORB.js";
3
+ } from "./chunk-Y4DC5KRB.js";
4
4
  import {
5
5
  declinedAgentsFile,
6
6
  readDeclinedAgents
7
- } from "./chunk-EY4XHT6G.js";
7
+ } from "./chunk-X3DYMWPL.js";
8
8
  import {
9
9
  OPENCODE_HOOK_BINARY,
10
10
  openCodeConfigDir,
11
11
  openCodePluginFile
12
- } from "./chunk-GFX5AAWT.js";
12
+ } from "./chunk-67FOJA34.js";
13
13
  import {
14
14
  openCodePluginArgv
15
- } from "./chunk-DBYHLVQ2.js";
15
+ } from "./chunk-7TVCL4PI.js";
16
16
  import {
17
17
  liveCursorGateCoverage
18
- } from "./chunk-WUUVZEKA.js";
18
+ } from "./chunk-O4ZFUVDI.js";
19
19
  import {
20
20
  compatibleConfigFile,
21
21
  compatibleHookEvents,
22
22
  grokHome
23
- } from "./chunk-43EYM5PY.js";
23
+ } from "./chunk-3IHL4N2G.js";
24
24
  import {
25
25
  parseConfigDocument
26
- } from "./chunk-AHYV7ZQE.js";
26
+ } from "./chunk-2ABJ4VCG.js";
27
27
  import {
28
28
  DEFAULT_HOOKS_KEY_PATH,
29
29
  GEMINI_HOOK_BINARY,
30
30
  GEMINI_HOOK_EVENTS,
31
31
  hooksAt
32
- } from "./chunk-Z32D32PL.js";
32
+ } from "./chunk-W2SZOATE.js";
33
33
  import {
34
34
  CODEX_EARLIER_APPROVAL_MATCHERS,
35
35
  CODEX_HOOK_BINARY,
@@ -57,7 +57,7 @@ import {
57
57
  parseHookArgv,
58
58
  parseHookCommand,
59
59
  supportedClaudeEvents
60
- } from "./chunk-O54TEHYJ.js";
60
+ } from "./chunk-ZGVMX36I.js";
61
61
  import {
62
62
  readRegularJsonFile,
63
63
  readRegularTextFile
@@ -71,7 +71,7 @@ import {
71
71
  OPENCODE_APPROVAL_EVENT,
72
72
  isRecord,
73
73
  matcherMatchesEveryCall
74
- } from "./chunk-AY37CFHF.js";
74
+ } from "./chunk-GOSMCOHB.js";
75
75
 
76
76
  // src/hook-wiring.ts
77
77
  import { createHash } from "crypto";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  readExistingMachineId
3
- } from "./chunk-UXRP56HU.js";
3
+ } from "./chunk-R6JRCEIX.js";
4
4
  import {
5
5
  getBaseUrl
6
- } from "./chunk-U7WPURWA.js";
6
+ } from "./chunk-DEMI4ZEH.js";
7
7
  import {
8
8
  NetworkError
9
9
  } from "./chunk-CINBAX5G.js";
@@ -13,7 +13,7 @@ import {
13
13
  import {
14
14
  clientContextHeaders,
15
15
  redactSecretsFromContent
16
- } from "./chunk-AY37CFHF.js";
16
+ } from "./chunk-GOSMCOHB.js";
17
17
 
18
18
  // src/cli/net.ts
19
19
  import { createRequire } from "module";
@@ -29,7 +29,7 @@ import {
29
29
  reportableSessionId,
30
30
  toToolLookup,
31
31
  truncateLine
32
- } from "./chunk-AY37CFHF.js";
32
+ } from "./chunk-GOSMCOHB.js";
33
33
 
34
34
  // ../hook-mapping/src/commit-receipt.ts
35
35
  var COMMIT_OUTPUT_MAX_LENGTH = 65536;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  realpath
3
- } from "./chunk-ARWKVVKB.js";
3
+ } from "./chunk-WS7Z6IJV.js";
4
4
  import {
5
5
  findNativeClaudeInstall
6
6
  } from "./chunk-TCE3J44Z.js";
@@ -12,7 +12,7 @@ import {
12
12
  resolvePackageVersionFromBinary,
13
13
  resolvePathBinary,
14
14
  resolvePathBinaryAsync
15
- } from "./chunk-3K2HA65U.js";
15
+ } from "./chunk-J35H5XWH.js";
16
16
  import {
17
17
  AGENTS,
18
18
  CLAUDE_BRIDGE_CAPABILITY,
@@ -25,7 +25,7 @@ import {
25
25
  OPENCODE_BRIDGE_CAPABILITY,
26
26
  SPAWN_CAPABILITY,
27
27
  sessionProvidersAdvertisedBy
28
- } from "./chunk-AY37CFHF.js";
28
+ } from "./chunk-GOSMCOHB.js";
29
29
 
30
30
  // src/live-capabilities.ts
31
31
  import { execFileSync } from "child_process";
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-U4P4NDVB.js";
17
17
  import {
18
18
  withoutNpmInstallConsent
19
- } from "./chunk-3K2HA65U.js";
19
+ } from "./chunk-J35H5XWH.js";
20
20
 
21
21
  // src/codex-desktop-launch.ts
22
22
  import { spawn as spawn2, execFileSync as execFileSync2 } from "child_process";
@@ -539,8 +539,8 @@ var loadedOnce = (load) => {
539
539
  };
540
540
 
541
541
  // src/codex-desktop-proxy.ts
542
- var loadThePhone = () => import("./api-ILQDGJL4.js");
543
- var loadTheCardRouting = () => import("./codex-card-routing-CQX3C552.js");
542
+ var loadThePhone = () => import("./api-QRQC65E7.js");
543
+ var loadTheCardRouting = () => import("./codex-card-routing-RWF7Q5NP.js");
544
544
  var theFirstCardLoadsAgain = () => {
545
545
  };
546
546
  var ASKS_WITHOUT_ROUTING = {};
@@ -1101,7 +1101,7 @@ var codexDesktopCommand = async (args, entry, readAccount) => {
1101
1101
  return runCodexDesktopProxy(engine2, args.slice(3), readAccount, { watchesForCards: layoutIsKnown });
1102
1102
  }
1103
1103
  if (args[0] === APP_CARDS_FLAG) {
1104
- const { codexAppCardsCommandOnThisMac } = await import("./codex-app-cards-switch-ROGUHXKQ.js");
1104
+ const { codexAppCardsCommandOnThisMac } = await import("./codex-app-cards-switch-EULJQSJY.js");
1105
1105
  return codexAppCardsCommandOnThisMac(args.slice(1), entry, readAccount);
1106
1106
  }
1107
1107
  if (args.length > 2) throw new Error("Usage: pushary codex --desktop [path/to/Codex.app]");