@ghostlytools/cli 1.10.1 → 1.10.3

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 (97) hide show
  1. package/README.md +14 -10
  2. package/SKILL.md +3 -2
  3. package/dist/assets/{api-BOWLZYXM.js → api-BdaxsDvA.js} +2 -2
  4. package/dist/assets/{api-Bi6hCcwG.js → api-C4MLg5Rs.js} +126 -49
  5. package/dist/assets/api-C4MLg5Rs.js.map +1 -0
  6. package/dist/assets/{apiKit-DzXHZojD.js → apiKit-BbNaxZGZ.js} +87 -25
  7. package/dist/assets/apiKit-BbNaxZGZ.js.map +1 -0
  8. package/dist/assets/{apps-DIQbzG08.js → apps-BluQgEhv.js} +5 -5
  9. package/dist/assets/{apps-DIQbzG08.js.map → apps-BluQgEhv.js.map} +1 -1
  10. package/dist/assets/{apps-0Ks6KjqS.js → apps-BtGFth7o.js} +1 -1
  11. package/dist/assets/{arkade-zozCldAE.js → arkade-DdZx4b_I.js} +2 -2
  12. package/dist/assets/{arkade-zozCldAE.js.map → arkade-DdZx4b_I.js.map} +1 -1
  13. package/dist/assets/{backup-BL49Kt-T.js → backup-DyDsW7sC.js} +7 -7
  14. package/dist/assets/{backup-BL49Kt-T.js.map → backup-DyDsW7sC.js.map} +1 -1
  15. package/dist/assets/{backup-BvIFcZM7.js → backup-I1n7ccz7.js} +1 -1
  16. package/dist/assets/{buttons-CAW5v5EE.js → buttons-Do7dCku6.js} +6 -6
  17. package/dist/assets/{buttons-CAW5v5EE.js.map → buttons-Do7dCku6.js.map} +1 -1
  18. package/dist/assets/buttons-DpjwXePb.js +2 -0
  19. package/dist/assets/{client-CyApKBEw.js → client-CWsjRiH8.js} +3 -3
  20. package/dist/assets/{client-CyApKBEw.js.map → client-CWsjRiH8.js.map} +1 -1
  21. package/dist/assets/{codec-DqFxxB_q.js → codec-DPaXhuYc.js} +2 -2
  22. package/dist/assets/{codec-DqFxxB_q.js.map → codec-DPaXhuYc.js.map} +1 -1
  23. package/dist/assets/{envelope-CMUgz31I.js → envelope-5Gu9yGk_.js} +2 -2
  24. package/dist/assets/{envelope-CMUgz31I.js.map → envelope-5Gu9yGk_.js.map} +1 -1
  25. package/dist/assets/{errors-R4S2SAEM.js → errors-Dt-ZnyOX.js} +3 -1
  26. package/dist/assets/errors-Dt-ZnyOX.js.map +1 -0
  27. package/dist/assets/{fixedHosts-C2hdCfzK.js → fixedHosts-PR1BcfKX.js} +7 -8
  28. package/dist/assets/fixedHosts-PR1BcfKX.js.map +1 -0
  29. package/dist/assets/{groupFiles-BAQIt_bJ.js → groupFiles-BuToTMUk.js} +307 -69
  30. package/dist/assets/groupFiles-BuToTMUk.js.map +1 -0
  31. package/dist/assets/{host-CaRlDMTd.js → host-fkQYBvKH.js} +322 -72
  32. package/dist/assets/host-fkQYBvKH.js.map +1 -0
  33. package/dist/assets/{hyperdhtRelay-BxADl3SG.js → hyperdhtRelay-DDCak5PY.js} +28 -20
  34. package/dist/assets/hyperdhtRelay-DDCak5PY.js.map +1 -0
  35. package/dist/assets/{irohWeb-D2sh6EWp.js → irohWeb-B4_swKx0.js} +112 -34
  36. package/dist/assets/{irohWeb-D2sh6EWp.js.map → irohWeb-B4_swKx0.js.map} +1 -1
  37. package/dist/assets/{main-Bc4Ow56Z.js → main-ClYsttvY.js} +98 -51
  38. package/dist/assets/main-ClYsttvY.js.map +1 -0
  39. package/dist/assets/{mainline-DWh4Ccri.js → mainline-Hsk2SZ1B.js} +66 -6
  40. package/dist/assets/mainline-Hsk2SZ1B.js.map +1 -0
  41. package/dist/assets/{networkReason-DT_D_Wpc.js → networkReason-C9Hr-hO7.js} +4 -4
  42. package/dist/assets/{networkReason-DT_D_Wpc.js.map → networkReason-C9Hr-hO7.js.map} +1 -1
  43. package/dist/assets/{nwc-DoSEhUKb.js → nwc-BbK6qNxS.js} +3 -3
  44. package/dist/assets/{nwc-DoSEhUKb.js.map → nwc-BbK6qNxS.js.map} +1 -1
  45. package/dist/assets/{nwcProvider-CGWqUjpB.js → nwcProvider-D_tt2X3Z.js} +2 -2
  46. package/dist/assets/{nwcProvider-CGWqUjpB.js.map → nwcProvider-D_tt2X3Z.js.map} +1 -1
  47. package/dist/assets/{ownDid-CbGjRLBn.js → ownDid-DkK_jem4.js} +2 -2
  48. package/dist/assets/{ownDid-CbGjRLBn.js.map → ownDid-DkK_jem4.js.map} +1 -1
  49. package/dist/assets/{profiles-DgIfvBeN.js → profiles-aV9vaK0B.js} +17 -8
  50. package/dist/assets/profiles-aV9vaK0B.js.map +1 -0
  51. package/dist/assets/{registry-C5cn80Rw.js → registry-C9T6tYCO.js} +1 -1
  52. package/dist/assets/{registry-BSyxGjN6.js → registry-CEjnubep.js} +57 -17
  53. package/dist/assets/registry-CEjnubep.js.map +1 -0
  54. package/dist/assets/{resolve-D-9YRFhl.js → resolve-BBOrN13E.js} +27 -6
  55. package/dist/assets/resolve-BBOrN13E.js.map +1 -0
  56. package/dist/assets/{restoredRows-CRYwIx3g.js → restoredRows-YhlbokEE.js} +4 -2
  57. package/dist/assets/restoredRows-YhlbokEE.js.map +1 -0
  58. package/dist/assets/{secretGuard-CSVNxXVW.js → secretGuard-B7Hj0Kvz.js} +2 -2
  59. package/dist/assets/{secretGuard-CSVNxXVW.js.map → secretGuard-B7Hj0Kvz.js.map} +1 -1
  60. package/dist/assets/secretGuard-DUr6bgKc.js +2 -0
  61. package/dist/assets/{server-BufntkX8.js → server-BJ3T-kx3.js} +1051 -389
  62. package/dist/assets/server-BJ3T-kx3.js.map +1 -0
  63. package/dist/assets/{src-CCt5s4DK.js → src-BIdfHB7t.js} +667 -134
  64. package/dist/assets/src-BIdfHB7t.js.map +1 -0
  65. package/dist/assets/{sshForges-D8CPaIbR.js → sshForges-CRg-NGld.js} +2 -2
  66. package/dist/assets/{sshForges-D8CPaIbR.js.map → sshForges-CRg-NGld.js.map} +1 -1
  67. package/dist/assets/{translate-Cb-6hMhD.js → translate-b0X61WMI.js} +3 -3
  68. package/dist/assets/{translate-Cb-6hMhD.js.map → translate-b0X61WMI.js.map} +1 -1
  69. package/dist/assets/{usdt-ds461mzA.js → usdt-6CQdfye1.js} +7 -4
  70. package/dist/assets/usdt-6CQdfye1.js.map +1 -0
  71. package/dist/assets/waitNotice-Ce3YCinu.js +101 -0
  72. package/dist/assets/waitNotice-Ce3YCinu.js.map +1 -0
  73. package/dist/assets/{words-B1ylON2h.js → words-Dk6o6wz4.js} +4 -4
  74. package/dist/assets/words-Dk6o6wz4.js.map +1 -0
  75. package/dist/ghostly.mjs +1 -1
  76. package/package.json +1 -1
  77. package/dist/assets/api-Bi6hCcwG.js.map +0 -1
  78. package/dist/assets/apiKit-DzXHZojD.js.map +0 -1
  79. package/dist/assets/buttons-oJI5mHSL.js +0 -2
  80. package/dist/assets/errors-R4S2SAEM.js.map +0 -1
  81. package/dist/assets/fixedHosts-C2hdCfzK.js.map +0 -1
  82. package/dist/assets/groupFiles-BAQIt_bJ.js.map +0 -1
  83. package/dist/assets/host-CaRlDMTd.js.map +0 -1
  84. package/dist/assets/hyperdhtRelay-BxADl3SG.js.map +0 -1
  85. package/dist/assets/main-Bc4Ow56Z.js.map +0 -1
  86. package/dist/assets/mainline-DWh4Ccri.js.map +0 -1
  87. package/dist/assets/profiles-DgIfvBeN.js.map +0 -1
  88. package/dist/assets/registry-BSyxGjN6.js.map +0 -1
  89. package/dist/assets/resolve-D-9YRFhl.js.map +0 -1
  90. package/dist/assets/restoredRows-CRYwIx3g.js.map +0 -1
  91. package/dist/assets/secretGuard-Q2BKq0q0.js +0 -2
  92. package/dist/assets/server-BufntkX8.js.map +0 -1
  93. package/dist/assets/src-CCt5s4DK.js.map +0 -1
  94. package/dist/assets/usdt-ds461mzA.js.map +0 -1
  95. package/dist/assets/waitNotice-B8D8WhbE.js +0 -45
  96. package/dist/assets/waitNotice-B8D8WhbE.js.map +0 -1
  97. package/dist/assets/words-B1ylON2h.js.map +0 -1
@@ -1,10 +1,10 @@
1
- import { Eu as setLinkTraceSink, Ku as fromBase64Url, Wo as DAEMON_WATCH_PEER_IDLE_MS, as as CALL_SIGNAL_MAX_AGE_MS, cs as answersOffer, ds as callSignalHeardAt, hs as signalHasVideo, li as checkPushEndpoint, ls as buildSdpFromSignal, ms as parseCallSignal, ps as extractParamsFromSdp, sa as isPublicAddress, ss as RTC_CONFIG, us as callRtcConfig } from "./src-CCt5s4DK.js";
2
- import { o as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-D2sh6EWp.js";
3
- import { r as asCliError, t as CliError } from "./errors-R4S2SAEM.js";
4
- import { l as findOwnNamedChat, o as findChat } from "./apiKit-DzXHZojD.js";
5
- import { _ as flushCardUpdates, c as paymentJson, d as nodeLocalFetch, f as chatJson, g as resumeHolds, h as groupMessageJson, l as reportAppFrames, m as groupJson, p as chatMessageJson, r as callApi, u as servedApps } from "./api-Bi6hCcwG.js";
6
- import { S as runtimePath, g as startingPath, n as RESTORED_MARK, r as acquireLock, v as ownFolder, x as privateFolder, y as ownProfile } from "./profiles-DgIfvBeN.js";
7
- import { c as proof, d as DEFAULT_RATE, f as PlaybackQueue, g as isCallRate, h as frameSamples, l as removeDaemonSecret, m as frameBytes, o as greeting, p as bytesToMs, s as newDaemonSecret } from "./client-CyApKBEw.js";
1
+ import { Nu as setLinkTraceSink, Xo as DAEMON_WATCH_PEER_IDLE_MS, _s as callSignalHeardAt, ba as ACTIVE_DHT_POLL_MS, bs as parseCallSignal, ds as CALL_SIGNAL_MAX_AGE_MS, fa as isPublicAddress, fi as checkPushEndpoint, gs as callRtcConfig, hs as buildSdpFromSignal, ms as answersOffer, nd as fromBase64Url, ps as RTC_CONFIG, xs as signalHasVideo, ys as extractParamsFromSdp } from "./src-BIdfHB7t.js";
2
+ import { o as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-B4_swKx0.js";
3
+ import { r as asCliError, t as CliError } from "./errors-Dt-ZnyOX.js";
4
+ import { s as findChat, u as findOwnNamedChat } from "./apiKit-BbNaxZGZ.js";
5
+ import { _ as flushCardUpdates, c as paymentJson, d as nodeLocalFetch, f as chatJson, g as resumeHolds, h as groupMessageJson, l as reportAppFrames, m as groupJson, p as chatMessageJson, r as callApi, u as servedApps } from "./api-C4MLg5Rs.js";
6
+ import { C as runtimePath, S as privateFolder, _ as startingPath, b as ownProfile, n as RESTORED_MARK, r as acquireLock, y as ownFolder } from "./profiles-aV9vaK0B.js";
7
+ import { c as proof, d as DEFAULT_RATE, f as PlaybackQueue, g as isCallRate, h as frameSamples, l as removeDaemonSecret, m as frameBytes, o as greeting, p as bytesToMs, s as newDaemonSecret } from "./client-CWsjRiH8.js";
8
8
  import { createRequire } from "node:module";
9
9
  import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, fsyncSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, truncateSync, writeFileSync, writeSync } from "node:fs";
10
10
  import { readFile } from "node:fs/promises";
@@ -984,6 +984,11 @@ var CallManager = class {
984
984
  missedAt = /* @__PURE__ */ new Map();
985
985
  /** Per chat: the contact's last call held back (`QUICK_REDIAL_MS`) until its hang-up, and when it came. */
986
986
  held = /* @__PURE__ */ new Map();
987
+ /**
988
+ * The chats whose contact's calls are being held back (`QUICK_REDIAL_MS`) since the last that rang: the log says so for
989
+ * the first only. A detached daemon's log only grows, and a contact's loop would set its pace.
990
+ */
991
+ bursts = /* @__PURE__ */ new Set();
987
992
  /** The early answers being made, those of ended calls too (MAX_EARLY_ANSWERS). */
988
993
  makings = /* @__PURE__ */ new Set();
989
994
  auto;
@@ -1019,7 +1024,8 @@ var CallManager = class {
1019
1024
  if (signal.t === "o" && !call) {
1020
1025
  this.lastSignal.set(chat, signal.ts);
1021
1026
  if (this.quickRedial(chat)) {
1022
- process.stderr.write(`ghostly: chat ${chat}: a call came right after a missed one that barely rang: kept as missed\n`);
1027
+ if (!this.bursts.has(chat)) process.stderr.write(`ghostly: chat ${chat}: a call came right after a missed one that barely rang: kept as missed, and the next ones that come as fast\n`);
1028
+ this.bursts.add(chat);
1023
1029
  this.missedAt.set(chat, this.now);
1024
1030
  this.held.set(chat, {
1025
1031
  offer: signal,
@@ -1036,7 +1042,10 @@ var CallManager = class {
1036
1042
  } else if (signal.t === "o" && call?.direction === "in" && call.state === "connecting" && call.media && signal.ts > (call.offer?.ts ?? 0)) {
1037
1043
  this.lastSignal.set(chat, signal.ts);
1038
1044
  if (call.reanswers < this.maxRedials) this.reanswer(call, signal);
1039
- else process.stderr.write(`ghostly: call ${call.id}: the contact offered again past the last start-over: ignored\n`);
1045
+ else if (!call.ignoring) {
1046
+ call.ignoring = true;
1047
+ process.stderr.write(`ghostly: call ${call.id}: the contact offered again past the last start-over: ignored, and its next offers on this call\n`);
1048
+ }
1040
1049
  } else if (signal.t === "v") this.lastSignal.set(chat, signal.ts);
1041
1050
  else if (signal.t === "h") {
1042
1051
  this.lastSignal.set(chat, signal.ts);
@@ -1060,6 +1069,7 @@ var CallManager = class {
1060
1069
  }
1061
1070
  incoming(chat, offer) {
1062
1071
  this.held.delete(chat);
1072
+ this.bursts.delete(chat);
1063
1073
  const link = this.link(chat);
1064
1074
  const call = this.add(chat, "in", this.auto.rate);
1065
1075
  call.offer = offer;
@@ -1329,7 +1339,8 @@ var CallManager = class {
1329
1339
  };
1330
1340
  }
1331
1341
  setAuto(next) {
1332
- const from = (next.from ?? []).map((ref) => findOwnNamedChat(this.host.engine.getState().links, ref).id);
1342
+ const { links, groups } = this.host.engine.getState();
1343
+ const from = (next.from ?? []).map((ref) => findOwnNamedChat(links, ref, groups).id);
1333
1344
  this.auto = {
1334
1345
  on: next.on,
1335
1346
  from: next.on ? from : [],
@@ -1386,6 +1397,7 @@ var CallManager = class {
1386
1397
  offering: false,
1387
1398
  redials: 0,
1388
1399
  reanswers: 0,
1400
+ ignoring: false,
1389
1401
  attempt: 0,
1390
1402
  answered: 0,
1391
1403
  answeredAt: 0,
@@ -1656,9 +1668,10 @@ var CallManager = class {
1656
1668
  link(chat) {
1657
1669
  return this.host.engine.getState().links.find((l) => l.id === chat);
1658
1670
  }
1659
- /** A chat by id, contact key, prefix or name (the API's rules, `findChat`). */
1671
+ /** A chat by id, contact key, prefix or name (the API's rules, `findChat`); a group's says it is one. */
1660
1672
  chatId(ref) {
1661
- return findChat(this.host.engine.getState().links, ref).id;
1673
+ const { links, groups } = this.host.engine.getState();
1674
+ return findChat(links, ref, groups).id;
1662
1675
  }
1663
1676
  /** The chat, if a call can go in it now; else why not (the engine's reason). */
1664
1677
  callable(ref) {
@@ -1710,8 +1723,9 @@ var FORGET_SEARCHED_IDS = 16;
1710
1723
  var SEEN_DB = "ghostly-cli";
1711
1724
  var SEEN = "seen";
1712
1725
  /**
1713
- * How long the seen set keeps the note of a settled message after its last activity (its arrival, its edit, a reaction):
1714
- * older notes are dropped, and a message that came here longer ago with no note is no news. A daemon kept a note per
1726
+ * How long the seen set keeps the note of a settled message after its last activity (its arrival, its edit, a reaction),
1727
+ * each as this device's clock has it: older notes are dropped, and a message that came here longer ago with no note is
1728
+ * no news. A daemon kept a note per
1715
1729
  * message of its whole history in memory, for as long as it ran.
1716
1730
  */
1717
1731
  var SEEN_KEEP_MS = 2592e6;
@@ -1743,8 +1757,27 @@ var EventHub = class {
1743
1757
  marked = false;
1744
1758
  /** Whether `dropped` is ahead of `<journal>.dropped` (a full disk refused it): the next event's write tries it again. */
1745
1759
  markOwed = false;
1760
+ /**
1761
+ * The highest seq `<journal>.reserved` holds: no event is told a seq past it before the mark says so, and a start
1762
+ * numbers on from it. A full disk can take an event and its `.dropped` mark both, after it was told; the next start
1763
+ * then never gives its seq again, and a replay across it says `events.gap`. A stop gives back what it did not use.
1764
+ */
1765
+ reserved = 0;
1766
+ /** Typing changes told this run: a change's id carries it, as it takes no seq of its own (`emitLive`). */
1767
+ typingChanges = 0;
1746
1768
  journalLines = 0;
1747
1769
  journalBytes = 0;
1770
+ /**
1771
+ * Where the journal first names each chat, group and message (`namedIn`), by the hash of the id as written
1772
+ * (`hashOfId`; two ids that share one only read more), so `forget` reads it from there on: each deletion read the
1773
+ * whole journal (up to 32 MiB) from disk and searched it, a contact's delete for everyone included. Built from the
1774
+ * journal at the first `forget`, kept by `emit`; null again once lines move (a trim, a rewrite).
1775
+ */
1776
+ firstNamed = null;
1777
+ /** The journal's size `firstNamed` covers: another size (a write it did not see) builds it again. */
1778
+ namedSize = 0;
1779
+ /** Where the first line that cannot be read is, which `forget` reads from too: it may name what is removed. */
1780
+ unreadableAt = Infinity;
1748
1781
  listeners = /* @__PURE__ */ new Set();
1749
1782
  stateListeners = /* @__PURE__ */ new Set();
1750
1783
  callListeners = /* @__PURE__ */ new Set();
@@ -1781,6 +1814,7 @@ var EventHub = class {
1781
1814
  }
1782
1815
  /** Loads the journal's last seq and the seen set; call before `sink` is attached. */
1783
1816
  async open() {
1817
+ const reserved = readDropped(this.journalPath + ".reserved") ?? 0;
1784
1818
  try {
1785
1819
  const dropped = readDropped(this.journalPath + ".dropped");
1786
1820
  if (existsSync(this.journalPath)) {
@@ -1817,6 +1851,11 @@ var EventHub = class {
1817
1851
  this.journalBytes = 0;
1818
1852
  this.markDropped(this.seq);
1819
1853
  }
1854
+ this.reserved = reserved;
1855
+ if (reserved > this.seq) {
1856
+ this.seq = reserved;
1857
+ this.markDropped(Math.max(this.dropped, reserved));
1858
+ }
1820
1859
  this.db = await new Promise((resolve, reject) => {
1821
1860
  const request = indexedDB.open(this.seenDb, 1);
1822
1861
  request.onupgradeneeded = () => {
@@ -1874,10 +1913,18 @@ var EventHub = class {
1874
1913
  }
1875
1914
  /**
1876
1915
  * Drops the notes of settled messages, and of reactions, whose last activity is older than `SEEN_KEEP_MS`: from memory
1877
- * and from the store. A message of mine still on its way (or failed, which a retry sends again) keeps its note.
1916
+ * and from the store. A message of mine still on its way (or failed, which a retry sends again) keeps its note. The
1917
+ * 30 days count back from the newest activity the set knows when the clock reads later than it: a clock run ahead (a
1918
+ * wrong RTC, a VM restored with a skewed clock) would otherwise drop the notes of the recent history, which the next
1919
+ * start with the clock right reports again.
1878
1920
  */
1879
1921
  sweep() {
1880
- const cutoff = this.now() - SEEN_KEEP_MS;
1922
+ let newest = 0;
1923
+ for (const [chat, known] of this.seen) {
1924
+ if (chat === FORMAT || chat.startsWith("said:")) continue;
1925
+ for (const note of known.values()) newest = Math.max(newest, timeIn(note) ?? 0);
1926
+ }
1927
+ const cutoff = Math.min(this.now(), newest) - SEEN_KEEP_MS;
1881
1928
  let dropped = 0;
1882
1929
  for (const [chat, known] of this.seen) {
1883
1930
  if (chat === FORMAT || chat.startsWith("said:")) continue;
@@ -1908,7 +1955,7 @@ var EventHub = class {
1908
1955
  const cutoff = this.now() - SEEN_KEEP_MS;
1909
1956
  return messages.every((message) => {
1910
1957
  const note = known?.get(message.id), before = note === void 0 ? void 0 : stateIn(note);
1911
- if (note === void 0 && message.timestamp < cutoff && activityOf(message) < cutoff) return true;
1958
+ if (note === void 0 && cameAt(message) < cutoff && activityOf(message) < cutoff) return true;
1912
1959
  let state = stateOf(message);
1913
1960
  if (before !== void 0 && mentionedIn(before) && !mentionedIn(state)) state = withFlag(state, MENTIONED);
1914
1961
  if (before !== state) return false;
@@ -1982,7 +2029,40 @@ var EventHub = class {
1982
2029
  this.marked = true;
1983
2030
  this.markOwed = false;
1984
2031
  } catch (error) {
1985
- this.markOwed = true;
2032
+ try {
2033
+ writeMark(this.journalPath + ".dropped", seq, false);
2034
+ this.marked = true;
2035
+ this.markOwed = false;
2036
+ } catch {
2037
+ this.markOwed = true;
2038
+ process.stderr.write(`ghostly: event journal error: ${error instanceof Error ? error.message : String(error)}\n`);
2039
+ }
2040
+ }
2041
+ }
2042
+ /**
2043
+ * Reserves seqs ahead of the one about to be told, in `<journal>.reserved`, rewritten where it is (no new block, so a
2044
+ * full disk takes it): written before the event goes anywhere, as `markDropped` is. Refused, the event still goes
2045
+ * (the reservation made before covers the next ones), and the next event tries again.
2046
+ */
2047
+ reserve() {
2048
+ if (this.reserved - this.seq >= 128) return;
2049
+ try {
2050
+ writeMark(this.journalPath + ".reserved", this.seq + 256, true);
2051
+ this.reserved = this.seq + 256;
2052
+ } catch (error) {
2053
+ process.stderr.write(`ghostly: event journal error: ${error instanceof Error ? error.message : String(error)}\n`);
2054
+ }
2055
+ }
2056
+ /**
2057
+ * At a stop: the seqs reserved past the last one told are given back, so the next start numbers on from it, with no
2058
+ * jump. Not written (a disk that takes no rewrite either), the next start numbers past the reservation instead.
2059
+ */
2060
+ release() {
2061
+ if (this.reserved <= this.seq) return;
2062
+ try {
2063
+ writeMark(this.journalPath + ".reserved", this.seq, true);
2064
+ this.reserved = this.seq;
2065
+ } catch (error) {
1986
2066
  process.stderr.write(`ghostly: event journal error: ${error instanceof Error ? error.message : String(error)}\n`);
1987
2067
  }
1988
2068
  }
@@ -1998,12 +2078,17 @@ var EventHub = class {
1998
2078
  at: this.now(),
1999
2079
  ...fields
2000
2080
  };
2081
+ this.reserve();
2001
2082
  let written = false;
2002
2083
  try {
2003
2084
  if (this.markOwed) this.markDropped(this.dropped);
2004
2085
  const line = Buffer.from(JSON.stringify(event) + "\n");
2005
- appendWhole(this.journalPath, line);
2086
+ const at = appendWhole(this.journalPath, line);
2006
2087
  written = true;
2088
+ if (this.firstNamed && at === this.namedSize) {
2089
+ for (const id of namedIn(event)) if (!this.firstNamed.has(hashOfId(id))) this.firstNamed.set(hashOfId(id), at);
2090
+ this.namedSize = at + line.length;
2091
+ } else this.firstNamed = null;
2007
2092
  this.journalBytes += line.length;
2008
2093
  if (++this.journalLines > 2e4 || this.journalBytes > 33554432) this.trimJournal();
2009
2094
  } catch (error) {
@@ -2015,7 +2100,7 @@ var EventHub = class {
2015
2100
  }
2016
2101
  /**
2017
2102
  * An event for the listeners only, never the journal: a contact's app frames, live only (WISP 1200), which at the
2018
- * receiver's rate would push every other chat's events out of it in seconds. It takes no seq of its own but the last
2103
+ * receiver's rate would push every other chat's events out of it in seconds, and typing, which lasts seconds. It takes no seq of its own but the last
2019
2104
  * event's (as an `agent.turn` takes its source's): a cursor that handled it resumes after that event, a replay never
2020
2105
  * gives it, and a restart never numbers an event again.
2021
2106
  */
@@ -2043,64 +2128,133 @@ var EventHub = class {
2043
2128
  const kept = lines.slice(start);
2044
2129
  const first = firstSeq(kept);
2045
2130
  this.markDropped(Math.max(this.dropped, first === void 0 ? this.seq : first - 1));
2131
+ this.firstNamed = null;
2046
2132
  writeFileSync(this.journalPath + ".tmp", kept.length ? kept.join("\n") + "\n" : "", { mode: 384 });
2047
2133
  renameSync(this.journalPath + ".tmp", this.journalPath);
2048
2134
  this.journalLines = kept.length;
2049
2135
  this.journalBytes = bytes;
2050
2136
  }
2051
2137
  /**
2052
- * What was removed here leaves the journal too: the journal is written again without the events that name it (a
2053
- * line that names it and cannot be read goes as well), and a journal set aside as unreadable, which cannot be sorted,
2054
- * is deleted. `ids`: what was removed (a message's id, a chat's or a group's); `gone`: whether an event is of it;
2055
- * `unquote`: an event that stays, written again without what it quotes of the removed (a reply's event), else none.
2138
+ * What was removed here leaves the journal too: the events that name it are blanked, or the journal is written again
2139
+ * without them (a line that names it and cannot be read goes as well), and a journal set aside as unreadable, which
2140
+ * cannot be sorted, is deleted. `ids`: what was removed (a message's id, a chat's or a group's); `gone`: whether an
2141
+ * event is of it; `unquote`: an event that stays, written again without what it quotes of the removed (a reply's
2142
+ * event), else none.
2056
2143
  */
2057
2144
  forget(ids, gone, unquote = () => void 0) {
2058
2145
  if (!ids.length) return;
2059
2146
  try {
2060
2147
  rmSync(this.journalPath + ".unreadable", { force: true });
2061
2148
  if (!existsSync(this.journalPath)) return;
2062
- const { bytes, start } = journalWindow(this.journalPath);
2149
+ const named = this.namedFrom(ids);
2150
+ if (named === void 0) return;
2151
+ let { bytes, start, at } = journalWindow(this.journalPath, named);
2063
2152
  const needles = ids.map((id) => JSON.stringify(id)), few = ids.length <= FORGET_SEARCHED_IDS;
2064
2153
  const names = (line) => needles.some((needle) => line.includes(needle));
2065
- let from = few ? bytes.length : start;
2066
- if (few) for (const needle of needles) {
2067
- const at = bytes.indexOf(needle, start);
2068
- if (at !== -1 && at < from) from = at;
2069
- }
2070
- if (from === bytes.length) return;
2071
- from = Math.max(start, bytes.lastIndexOf(10, from) + 1);
2072
- const lines = bytes.toString("utf8", from).split("\n").filter(Boolean);
2073
- let changed = false;
2074
- const kept = lines.flatMap((line) => {
2075
- if (few && !names(line)) return [line];
2154
+ const edits = [];
2155
+ for (const [from, to] of few ? linesNaming(bytes, start, needles) : linesOf(bytes, start)) {
2156
+ const line = bytes.toString("utf8", from, to);
2076
2157
  let event;
2077
2158
  try {
2078
2159
  event = JSON.parse(line);
2079
2160
  } catch {
2080
- if (!few && !names(line)) return [line];
2081
- changed = true;
2082
- return [];
2161
+ if (few || names(line)) edits.push({
2162
+ from,
2163
+ to,
2164
+ line: null
2165
+ });
2166
+ continue;
2083
2167
  }
2084
2168
  if (gone(event)) {
2085
- changed = true;
2086
- return [];
2169
+ edits.push({
2170
+ from,
2171
+ to,
2172
+ line: null
2173
+ });
2174
+ continue;
2087
2175
  }
2088
2176
  const written = unquote(event);
2089
- if (!written) return [line];
2090
- changed = true;
2091
- return [JSON.stringify(written)];
2092
- });
2093
- if (!changed) return;
2177
+ if (written) edits.push({
2178
+ from,
2179
+ to,
2180
+ line: JSON.stringify(written)
2181
+ });
2182
+ }
2183
+ if (!edits.length) return;
2094
2184
  if (!this.marked) this.markDropped(this.dropped);
2095
- const tail = kept.length ? kept.join("\n") + "\n" : "";
2096
- writeFileSync(this.journalPath + ".tmp", Buffer.concat([bytes.subarray(start, from), Buffer.from(tail)]), { mode: 384 });
2185
+ if (few && edits.every(({ from, to, line }) => line === null || Buffer.byteLength(line) <= to - from)) {
2186
+ const fd = openSync(this.journalPath, "r+");
2187
+ try {
2188
+ for (const { from, to, line } of edits) {
2189
+ const over = Buffer.alloc(to - from, " ");
2190
+ if (line !== null) over.write(line);
2191
+ for (let done = 0; done < over.length;) done += writeSync(fd, over, done, over.length - done, at + from + done);
2192
+ }
2193
+ } finally {
2194
+ closeSync(fd);
2195
+ }
2196
+ return;
2197
+ }
2198
+ this.firstNamed = null;
2199
+ if (start === 0 && at > 0) {
2200
+ const window = journalWindow(this.journalPath);
2201
+ for (const edit of edits) {
2202
+ edit.from += at - window.at;
2203
+ edit.to += at - window.at;
2204
+ }
2205
+ ({bytes, start, at} = window);
2206
+ }
2207
+ const parts = [];
2208
+ let from = start, removed = 0;
2209
+ for (const edit of edits) {
2210
+ parts.push(bytes.subarray(from, edit.from));
2211
+ if (edit.line === null) removed++;
2212
+ else parts.push(Buffer.from(edit.line));
2213
+ from = edit.line === null ? edit.to + 1 : edit.to;
2214
+ }
2215
+ parts.push(bytes.subarray(from));
2216
+ const written = Buffer.concat(parts);
2217
+ writeFileSync(this.journalPath + ".tmp", written, { mode: 384 });
2097
2218
  renameSync(this.journalPath + ".tmp", this.journalPath);
2098
- this.journalLines -= lines.length - kept.length;
2099
- this.journalBytes = from - start + Buffer.byteLength(tail);
2219
+ this.journalLines -= removed;
2220
+ this.journalBytes = written.length;
2100
2221
  } catch (error) {
2222
+ this.firstNamed = null;
2101
2223
  process.stderr.write(`ghostly: event journal error: ${error instanceof Error ? error.message : String(error)}\n`);
2102
2224
  }
2103
2225
  }
2226
+ /**
2227
+ * The first place in the journal a line may name one of these ids (`namedIn`), or undefined when none does. The
2228
+ * first call reads the journal for it once.
2229
+ */
2230
+ namedFrom(ids) {
2231
+ if (!this.firstNamed || statSync(this.journalPath).size !== this.namedSize) {
2232
+ const { bytes, start, at, size } = journalWindow(this.journalPath);
2233
+ const firstNamed = /* @__PURE__ */ new Map();
2234
+ for (const key of NAMING_KEYS) for (let found = bytes.indexOf(key, start); found !== -1; found = bytes.indexOf(key, found + key.length)) {
2235
+ const open = found + key.length;
2236
+ if (bytes[open] !== 34) continue;
2237
+ let close = open + 1;
2238
+ while (close < bytes.length && bytes[close] !== 34 && bytes[close] !== 10) close += bytes[close] === 92 ? 2 : 1;
2239
+ if (bytes[close] !== 34) continue;
2240
+ const hash = hashOf(bytes, open, close + 1), line = at + Math.max(start, bytes.lastIndexOf(10, found) + 1);
2241
+ if ((firstNamed.get(hash) ?? Infinity) > line) firstNamed.set(hash, line);
2242
+ }
2243
+ this.unreadableAt = Infinity;
2244
+ for (const [from, to] of linesOf(bytes, start)) {
2245
+ if (bytes[from] === 123 && bytes[to - 1] === 125) continue;
2246
+ if (bytes.subarray(from, to).some((byte) => byte !== 32)) {
2247
+ this.unreadableAt = at + from;
2248
+ break;
2249
+ }
2250
+ }
2251
+ this.firstNamed = firstNamed;
2252
+ this.namedSize = size;
2253
+ }
2254
+ let from = this.unreadableAt;
2255
+ for (const id of ids) from = Math.min(from, this.firstNamed.get(hashOfId(id)) ?? Infinity);
2256
+ return from === Infinity ? void 0 : from;
2257
+ }
2104
2258
  handle(message) {
2105
2259
  switch (message.kind) {
2106
2260
  case "state":
@@ -2167,11 +2321,11 @@ var EventHub = class {
2167
2321
  name: shape.name
2168
2322
  });
2169
2323
  this.pinned("chat", id, before.pin, shape.pin);
2170
- if (shape.typing !== before.typing) this.emit(shape.typing ? "typing.started" : "typing.stopped", `typing.${shape.typing ? "started" : "stopped"}:${id}:${this.now()}`, {
2324
+ if (shape.typing !== before.typing) this.emitLive(shape.typing ? "typing.started" : "typing.stopped", `typing.${shape.typing ? "started" : "stopped"}:${id}:${this.now()}`, {
2171
2325
  chat: id,
2172
2326
  ...shape.typing ? typingFields(shape) : {}
2173
2327
  });
2174
- else if (shape.typing && (shape.typingKind !== before.typingKind || shape.typingStatus !== before.typingStatus)) this.emit("typing.started", `typing.started:${id}:${this.now()}:${this.seq + 1}`, {
2328
+ else if (shape.typing && (shape.typingKind !== before.typingKind || shape.typingStatus !== before.typingStatus)) this.emitLive("typing.started", `typing.started:${id}:${this.now()}:${++this.typingChanges}`, {
2175
2329
  chat: id,
2176
2330
  ...typingFields(shape)
2177
2331
  });
@@ -2210,13 +2364,13 @@ var EventHub = class {
2210
2364
  for (const [member, word] of Object.entries(shape.typing)) {
2211
2365
  const was = before.typing[member];
2212
2366
  if (was && was.kind === word.kind && was.status === word.status) continue;
2213
- this.emit("group.typing.started", `group.typing.started:${id}:${member}:${this.now()}${was ? `:${this.seq + 1}` : ""}`, {
2367
+ this.emitLive("group.typing.started", `group.typing.started:${id}:${member}:${this.now()}${was ? `:${++this.typingChanges}` : ""}`, {
2214
2368
  group: id,
2215
2369
  member,
2216
2370
  ...word
2217
2371
  });
2218
2372
  }
2219
- for (const member of Object.keys(before.typing)) if (!shape.typing[member]) this.emit("group.typing.stopped", `group.typing.stopped:${id}:${member}:${this.now()}`, {
2373
+ for (const member of Object.keys(before.typing)) if (!shape.typing[member]) this.emitLive("group.typing.stopped", `group.typing.stopped:${id}:${member}:${this.now()}`, {
2220
2374
  group: id,
2221
2375
  member
2222
2376
  });
@@ -2401,13 +2555,13 @@ var EventHub = class {
2401
2555
  const note = known.get(message.id), before = note === void 0 ? void 0 : stateIn(note);
2402
2556
  const at = activityOf(message);
2403
2557
  const json = () => group ? groupMessageJson(message, this.state?.groups.find((g) => g.id === group)) : chatMessageJson(message, this.state?.links.find((l) => l.id === chat));
2404
- if (before === void 0 && message.timestamp < cutoff) {
2558
+ if (before === void 0 && cameAt(message) < cutoff) {
2405
2559
  if (at < cutoff) continue;
2406
2560
  const noted = noteOf(state, at);
2407
2561
  known.set(message.id, noted);
2408
2562
  changes.push([message.id, noted]);
2409
2563
  const edit = message.edit;
2410
- if (quiet || !edit || edit.at < cutoff || message.sender === "me" && edit.restore) continue;
2564
+ if (quiet || !edit || editedAt(edit) < cutoff || message.sender === "me" && edit.restore) continue;
2411
2565
  if (group) this.emit("group.message.edited", `group.message.edited:${group}:${message.id}:${edit.seq}`, {
2412
2566
  group,
2413
2567
  messageId: message.id,
@@ -2621,9 +2775,20 @@ function timeIn(note) {
2621
2775
  const at = note.lastIndexOf("@");
2622
2776
  return at === -1 ? void 0 : parseInt(note.slice(at + 1), 36);
2623
2777
  }
2778
+ /**
2779
+ * When a message came here: its place (a received row's is when it was stored here), or for a group's line, whose place
2780
+ * is its commit's moment, when this device stored it (`heardAt`; absent on lines stored before it).
2781
+ */
2782
+ function cameAt(message) {
2783
+ return Math.max(message.timestamp, message.heardAt ?? 0);
2784
+ }
2785
+ /** When an edit came here: a contact's or member's is dated by their clock (`at`), and taken here at `heardAt`. */
2786
+ function editedAt(edit) {
2787
+ return Math.max(edit.at, edit.heardAt ?? 0);
2788
+ }
2624
2789
  /** The last time a message changed here: it came, it was edited, someone reacted. */
2625
2790
  function activityOf(message) {
2626
- let at = Math.max(message.timestamp, message.edit?.at ?? 0);
2791
+ let at = Math.max(cameAt(message), message.edit ? editedAt(message.edit) : 0);
2627
2792
  for (const r of Object.values(message.reactions ?? {})) at = Math.max(at, r.at ?? 0);
2628
2793
  return at;
2629
2794
  }
@@ -2686,12 +2851,13 @@ function groupShape(group) {
2686
2851
  }
2687
2852
  /**
2688
2853
  * The journal's whole lines within its last `JOURNAL_MAX_BYTES`, and its size: never the whole file as one string, so
2689
- * a journal grown past what a string can hold (or a trim's bound) is still read, and in bounded time.
2854
+ * a journal grown past what a string can hold (or a trim's bound) is still read, and in bounded time. Lines `forget`
2855
+ * blanked are left out.
2690
2856
  */
2691
2857
  function journalTail(path) {
2692
2858
  const { bytes, start, size } = journalWindow(path);
2693
2859
  return {
2694
- lines: bytes.toString("utf8", start).split("\n").filter(Boolean),
2860
+ lines: bytes.toString("utf8", start).split("\n").filter((line) => line.trimStart()),
2695
2861
  size
2696
2862
  };
2697
2863
  }
@@ -2750,7 +2916,10 @@ function firstSeq(lines) {
2750
2916
  if (typeof seq === "number") return seq;
2751
2917
  } catch {}
2752
2918
  }
2753
- /** The journal's dropped mark (`EventHub.dropped`), or undefined when there is none (a journal from before it). */
2919
+ /**
2920
+ * The journal's dropped mark (`EventHub.dropped`) or its reserved one (`EventHub.reserved`), or undefined when there is
2921
+ * none (a journal from before it).
2922
+ */
2754
2923
  function readDropped(path) {
2755
2924
  try {
2756
2925
  const seq = Number(readFileSync(path, "utf8").trim());
@@ -2760,8 +2929,30 @@ function readDropped(path) {
2760
2929
  }
2761
2930
  }
2762
2931
  /**
2932
+ * Writes a mark over the one there, as a line of fixed width (`000…0042`, which `readDropped` reads, v1.10's too): a
2933
+ * rewrite never grows the file past its first block, so a full disk takes it, and one cut short leaves the new mark's
2934
+ * first digits before the old one's last, never a number below the old one when the mark grows. `create`: a file that
2935
+ * is not there is made (a first start).
2936
+ */
2937
+ function writeMark(path, seq, create) {
2938
+ const line = Buffer.from(String(seq).padStart(19, "0") + "\n");
2939
+ let fd;
2940
+ try {
2941
+ fd = openSync(path, "r+");
2942
+ } catch (error) {
2943
+ if (!create || error.code !== "ENOENT") throw error;
2944
+ fd = openSync(path, "wx", 384);
2945
+ }
2946
+ try {
2947
+ for (let at = 0; at < line.length;) at += writeSync(fd, line, at, line.length - at, at);
2948
+ } finally {
2949
+ closeSync(fd);
2950
+ }
2951
+ }
2952
+ /**
2763
2953
  * Appends a line whole or not at all: what a full disk took of it is cut back (as the store's journal does), so the
2764
- * next line, once there is room, starts a line of its own instead of making one no reader can parse with it.
2954
+ * next line, once there is room, starts a line of its own instead of making one no reader can parse with it. Returns
2955
+ * where the line begins in the file.
2765
2956
  */
2766
2957
  function appendWhole(path, line) {
2767
2958
  const fd = openSync(path, "a", 384);
@@ -2777,13 +2968,68 @@ function appendWhole(path, line) {
2777
2968
  } finally {
2778
2969
  closeSync(fd);
2779
2970
  }
2971
+ return whole;
2780
2972
  }
2781
- /** The bytes of the journal's last `JOURNAL_MAX_BYTES`, `start` where its first whole line begins in them, and its size. */
2782
- function journalWindow(path) {
2973
+ /**
2974
+ * The ids an event is of, as `forget`'s callers tell what is removed: its chat, its group, its message (`messageId`,
2975
+ * `message.id`), the reply that pressed it (`replyId`) and the message it quotes (`message.replyTo.id`).
2976
+ */
2977
+ function namedIn(event) {
2978
+ const message = event.message;
2979
+ return [
2980
+ event.chat,
2981
+ event.group,
2982
+ event.messageId,
2983
+ event.replyId,
2984
+ message?.id,
2985
+ message?.replyTo?.id
2986
+ ].filter((id) => typeof id === "string");
2987
+ }
2988
+ /** The keys whose values `namedIn` reads, as a journal line has them: `id` stands for `message.id` and its quote's. */
2989
+ var NAMING_KEYS = [
2990
+ "\"chat\":",
2991
+ "\"group\":",
2992
+ "\"messageId\":",
2993
+ "\"replyId\":",
2994
+ "\"id\":"
2995
+ ].map((key) => Buffer.from(key));
2996
+ /** FNV-1a of these bytes. */
2997
+ function hashOf(bytes, from = 0, to = bytes.length) {
2998
+ let hash = 2166136261;
2999
+ for (let i = from; i < to; i++) hash = Math.imul(hash ^ bytes[i], 16777619);
3000
+ return hash >>> 0;
3001
+ }
3002
+ /** The hash of an id as a journal line writes it (quoted, escaped). */
3003
+ var hashOfId = (id) => hashOf(Buffer.from(JSON.stringify(id)));
3004
+ /** The bounds in `bytes` of each line from `start` on, its newline left out. */
3005
+ function linesOf(bytes, start) {
3006
+ const lines = [];
3007
+ for (let from = start; from < bytes.length;) {
3008
+ const end = bytes.indexOf(10, from), to = end === -1 ? bytes.length : end;
3009
+ if (to > from) lines.push([from, to]);
3010
+ from = to + 1;
3011
+ }
3012
+ return lines;
3013
+ }
3014
+ /** The bounds in `bytes` of each line from `start` on that holds one of the needles, in their order, found in the bytes. */
3015
+ function linesNaming(bytes, start, needles) {
3016
+ const lines = /* @__PURE__ */ new Map();
3017
+ for (const needle of needles) for (let at = bytes.indexOf(needle, start); at !== -1;) {
3018
+ const from = Math.max(start, bytes.lastIndexOf(10, at) + 1), end = bytes.indexOf(10, at), to = end === -1 ? bytes.length : end;
3019
+ lines.set(from, to);
3020
+ at = end === -1 ? -1 : bytes.indexOf(needle, end + 1);
3021
+ }
3022
+ return [...lines].sort(([a], [b]) => a - b);
3023
+ }
3024
+ /**
3025
+ * The bytes of the journal's last `JOURNAL_MAX_BYTES`, `start` where its first whole line begins in them, `at` where
3026
+ * they begin in the file, and its size. `lineAt`: where a line begins, read from there on when it is within them.
3027
+ */
3028
+ function journalWindow(path, lineAt = 0) {
2783
3029
  const fd = openSync(path, "r");
2784
3030
  try {
2785
3031
  const size = fstatSync(fd).size;
2786
- const from = Math.max(0, size - JOURNAL_MAX_BYTES - 1);
3032
+ const cut = Math.max(0, size - JOURNAL_MAX_BYTES - 1), from = Math.max(cut, lineAt);
2787
3033
  const buffer = Buffer.alloc(size - from);
2788
3034
  let read = 0;
2789
3035
  while (read < buffer.length) {
@@ -2794,7 +3040,8 @@ function journalWindow(path) {
2794
3040
  const bytes = buffer.subarray(0, read);
2795
3041
  return {
2796
3042
  bytes,
2797
- start: from > 0 ? bytes.indexOf(10) + 1 || bytes.length : 0,
3043
+ start: from > cut || from === 0 ? 0 : bytes.indexOf(10) + 1 || bytes.length,
3044
+ at: from,
2798
3045
  size
2799
3046
  };
2800
3047
  } finally {
@@ -4985,8 +5232,8 @@ function mainlineNetwork(env = process.env) {
4985
5232
  }
4986
5233
  /**
4987
5234
  * WebRTC for the engine (WISP 101): libdatachannel through node-datachannel's W3C polyfill. Chats go live over it with
4988
- * browsers directly, and groups need it (their links use WebRTC alone). A native module: without it, or with
4989
- * `GHOSTLY_WEBRTC=0`, the CLI runs without WebRTC and says so.
5235
+ * browsers directly, and calls need it. A native module: without it, or with `GHOSTLY_WEBRTC=0`, the CLI runs without
5236
+ * WebRTC and says so; its groups' links go over Iroh or HyperDHT (WISP 902 § Transports).
4990
5237
  */
4991
5238
  async function installWebRtc() {
4992
5239
  if (!envSwitch("GHOSTLY_WEBRTC", true)) return false;
@@ -5093,7 +5340,7 @@ async function startRuntime(paths, options = {}) {
5093
5340
  const restored = join(paths.dir, RESTORED_MARK);
5094
5341
  if (existsSync(restored)) {
5095
5342
  try {
5096
- const rows = await import("./restoredRows-CRYwIx3g.js");
5343
+ const rows = await import("./restoredRows-YhlbokEE.js");
5097
5344
  await rows.markRestoredWallet();
5098
5345
  await rows.markLeftOutFiles(leftOutIn(restored));
5099
5346
  await rows.forgetRatchets();
@@ -5116,12 +5363,12 @@ async function startRuntime(paths, options = {}) {
5116
5363
  const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-DMzrIdCu.js"), import("./fileBytes-Douk1yOp.js")]);
5117
5364
  registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
5118
5365
  if (await (await import("./blobFiles-BnjN_Vrz.js")).moveBlobFiles()) await store.compact();
5119
- const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-BufntkX8.js"), import("./endpoint-DWHkXWVM.js")]);
5120
- const mainline = dht.off ? null : new (await (import("./mainline-DWh4Ccri.js"))).Mainline({
5366
+ const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-BJ3T-kx3.js"), import("./endpoint-DWHkXWVM.js")]);
5367
+ const mainline = dht.off ? null : new (await (import("./mainline-Hsk2SZ1B.js"))).Mainline({
5121
5368
  bootstrap: dht.bootstrap,
5122
5369
  host: dht.host
5123
5370
  });
5124
- const transport = mainline || pinned ? new (await (import("./mainline-DWh4Ccri.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
5371
+ const transport = mainline || pinned ? new (await (import("./mainline-Hsk2SZ1B.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
5125
5372
  const apps = servedApps(paths.dir).length > 0;
5126
5373
  const server = new EngineServer({
5127
5374
  ...transport ? { transport } : {},
@@ -5135,6 +5382,7 @@ async function startRuntime(paths, options = {}) {
5135
5382
  apps: apps ? "wire" : false,
5136
5383
  staysOnline: envSwitch("GHOSTLY_HUB", true),
5137
5384
  watchPeerIdleMs: DAEMON_WATCH_PEER_IDLE_MS,
5385
+ peerDhtPollMs: ACTIVE_DHT_POLL_MS,
5138
5386
  localFetch: nodeLocalFetch,
5139
5387
  pushSend: (request) => nodePushSend(request),
5140
5388
  holdFetch: nodeHoldFetch(),
@@ -5243,6 +5491,7 @@ async function openHost(paths, mode, version, options = {}) {
5243
5491
  ids: [...histories.keys(), ...newest.keys()]
5244
5492
  });
5245
5493
  } catch (error) {
5494
+ hub.release();
5246
5495
  await runtime.close().catch(() => {});
5247
5496
  release();
5248
5497
  throw error;
@@ -5261,6 +5510,7 @@ async function openHost(paths, mode, version, options = {}) {
5261
5510
  close: () => closing ??= (async () => {
5262
5511
  await Promise.all([calls.stopAll(), flushCardUpdates(ctx)]).catch(() => {});
5263
5512
  runtime.server.detach(hub.sink);
5513
+ hub.release();
5264
5514
  await runtime.close().catch(() => {});
5265
5515
  release();
5266
5516
  })()
@@ -5481,4 +5731,4 @@ function connection(ctx, socket, secret) {
5481
5731
  //#endregion
5482
5732
  export { BASELINE_NEWEST, MAX_UNREAD, keepServing, openHost, serve };
5483
5733
 
5484
- //# sourceMappingURL=host-CaRlDMTd.js.map
5734
+ //# sourceMappingURL=host-fkQYBvKH.js.map