@ghostlytools/cli 1.9.0 → 1.10.1

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 (118) hide show
  1. package/README.md +35 -27
  2. package/SKILL.md +7 -3
  3. package/dist/assets/api-BOWLZYXM.js +3 -0
  4. package/dist/assets/{api-DFCgr6RH.js → api-Bi6hCcwG.js} +100 -47
  5. package/dist/assets/api-Bi6hCcwG.js.map +1 -0
  6. package/dist/assets/{apiKit-CCavJJcl.js → apiKit-DzXHZojD.js} +26 -9
  7. package/dist/assets/apiKit-DzXHZojD.js.map +1 -0
  8. package/dist/assets/{apps-B7o2BPj6.js → apps-0Ks6KjqS.js} +1 -1
  9. package/dist/assets/{apps-DmxEG147.js → apps-DIQbzG08.js} +33 -10
  10. package/dist/assets/apps-DIQbzG08.js.map +1 -0
  11. package/dist/assets/{arkade-DtYR9H0c.js → arkade-zozCldAE.js} +2 -2
  12. package/dist/assets/{arkade-DtYR9H0c.js.map → arkade-zozCldAE.js.map} +1 -1
  13. package/dist/assets/{backup-YIB2XIES.js → backup-BL49Kt-T.js} +7 -6
  14. package/dist/assets/{backup-YIB2XIES.js.map → backup-BL49Kt-T.js.map} +1 -1
  15. package/dist/assets/{backup-BserdrNk.js → backup-BvIFcZM7.js} +1 -1
  16. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
  17. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
  18. package/dist/assets/{blobFiles-DOQDRdDI.js → blobFiles-BnjN_Vrz.js} +3 -3
  19. package/dist/assets/{blobFiles-DOQDRdDI.js.map → blobFiles-BnjN_Vrz.js.map} +1 -1
  20. package/dist/assets/buttons-CAW5v5EE.js +332 -0
  21. package/dist/assets/buttons-CAW5v5EE.js.map +1 -0
  22. package/dist/assets/buttons-oJI5mHSL.js +2 -0
  23. package/dist/assets/childEnv-BVOQK9EA.js +21 -0
  24. package/dist/assets/childEnv-BVOQK9EA.js.map +1 -0
  25. package/dist/assets/client-CyApKBEw.js +473 -0
  26. package/dist/assets/client-CyApKBEw.js.map +1 -0
  27. package/dist/assets/codec-DqFxxB_q.js +13 -0
  28. package/dist/assets/codec-DqFxxB_q.js.map +1 -0
  29. package/dist/assets/{endpoint-BdaeBw2L.js → endpoint-DWHkXWVM.js} +101 -16
  30. package/dist/assets/endpoint-DWHkXWVM.js.map +1 -0
  31. package/dist/assets/{envelope-Dt75vrmY.js → envelope-CMUgz31I.js} +3 -12
  32. package/dist/assets/envelope-CMUgz31I.js.map +1 -0
  33. package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js.map +1 -1
  34. package/dist/assets/{fileBytes-BPDKufla.js → fileBytes-DMzrIdCu.js} +1 -1
  35. package/dist/assets/{fileBytes-DNgrRL0R.js → fileBytes-DjBYYyXT.js} +3 -3
  36. package/dist/assets/{fileBytes-DNgrRL0R.js.map → fileBytes-DjBYYyXT.js.map} +1 -1
  37. package/dist/assets/{fileBytes-Q3ehcEr8.js → fileBytes-Douk1yOp.js} +2 -2
  38. package/dist/assets/{fileBytes-Q3ehcEr8.js.map → fileBytes-Douk1yOp.js.map} +1 -1
  39. package/dist/assets/fileBytesIdb-CD5Uv490.js +2 -0
  40. package/dist/assets/{fileBytesIdb-Dm1EyEbT.js → fileBytesIdb-CkClu9YI.js} +3 -3
  41. package/dist/assets/{fileBytesIdb-Dm1EyEbT.js.map → fileBytesIdb-CkClu9YI.js.map} +1 -1
  42. package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js → fileBytesOpfs-WryQuOgK.js} +3 -3
  43. package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js.map → fileBytesOpfs-WryQuOgK.js.map} +1 -1
  44. package/dist/assets/{fixedHosts-B598JzbC.js → fixedHosts-C2hdCfzK.js} +4 -4
  45. package/dist/assets/{fixedHosts-B598JzbC.js.map → fixedHosts-C2hdCfzK.js.map} +1 -1
  46. package/dist/assets/{groupFiles-FXel6zIc.js → groupFiles-BAQIt_bJ.js} +404 -161
  47. package/dist/assets/groupFiles-BAQIt_bJ.js.map +1 -0
  48. package/dist/assets/{host-DIBeK_c_.js → host-CaRlDMTd.js} +206 -49
  49. package/dist/assets/host-CaRlDMTd.js.map +1 -0
  50. package/dist/assets/{hyperdhtRelay-D185dETu.js → hyperdhtRelay-BxADl3SG.js} +2 -2
  51. package/dist/assets/{hyperdhtRelay-D185dETu.js.map → hyperdhtRelay-BxADl3SG.js.map} +1 -1
  52. package/dist/assets/{idb-BkOJES5_.js → idb-BHsAqENE.js} +37 -6
  53. package/dist/assets/idb-BHsAqENE.js.map +1 -0
  54. package/dist/assets/{irohWeb-BSv_BWyG.js → irohWeb-D2sh6EWp.js} +65 -7
  55. package/dist/assets/irohWeb-D2sh6EWp.js.map +1 -0
  56. package/dist/assets/{main-BbhfMTt8.js → main-Bc4Ow56Z.js} +221 -287
  57. package/dist/assets/main-Bc4Ow56Z.js.map +1 -0
  58. package/dist/assets/{mainline-9Vc3c3SA.js → mainline-DWh4Ccri.js} +2 -2
  59. package/dist/assets/{mainline-9Vc3c3SA.js.map → mainline-DWh4Ccri.js.map} +1 -1
  60. package/dist/assets/networkReason-DT_D_Wpc.js +474 -0
  61. package/dist/assets/networkReason-DT_D_Wpc.js.map +1 -0
  62. package/dist/assets/{nwc-QX3Yt1Sb.js → nwc-DoSEhUKb.js} +3 -3
  63. package/dist/assets/{nwc-QX3Yt1Sb.js.map → nwc-DoSEhUKb.js.map} +1 -1
  64. package/dist/assets/{nwcProvider-CzX3xH47.js → nwcProvider-CGWqUjpB.js} +2 -2
  65. package/dist/assets/{nwcProvider-CzX3xH47.js.map → nwcProvider-CGWqUjpB.js.map} +1 -1
  66. package/dist/assets/{ownDid-D8z5gwGI.js → ownDid-CbGjRLBn.js} +3 -3
  67. package/dist/assets/ownDid-CbGjRLBn.js.map +1 -0
  68. package/dist/assets/{profiles-MFtCmJwK.js → profiles-DgIfvBeN.js} +47 -4
  69. package/dist/assets/profiles-DgIfvBeN.js.map +1 -0
  70. package/dist/assets/{registry-B2Dtnibo.js → registry-BSyxGjN6.js} +11 -9
  71. package/dist/assets/registry-BSyxGjN6.js.map +1 -0
  72. package/dist/assets/{registry-PTtBMaYZ.js → registry-C5cn80Rw.js} +1 -1
  73. package/dist/assets/{resolve-ZxVzwFNA.js → resolve-D-9YRFhl.js} +2 -2
  74. package/dist/assets/{resolve-ZxVzwFNA.js.map → resolve-D-9YRFhl.js.map} +1 -1
  75. package/dist/assets/{restoredRows-BCRCjhdF.js → restoredRows-CRYwIx3g.js} +2 -2
  76. package/dist/assets/{restoredRows-BCRCjhdF.js.map → restoredRows-CRYwIx3g.js.map} +1 -1
  77. package/dist/assets/{buttons-CuRfKnPI.js → secretGuard-CSVNxXVW.js} +80 -330
  78. package/dist/assets/secretGuard-CSVNxXVW.js.map +1 -0
  79. package/dist/assets/secretGuard-Q2BKq0q0.js +2 -0
  80. package/dist/assets/{server-Dw1o8z1o.js → server-BufntkX8.js} +1734 -369
  81. package/dist/assets/server-BufntkX8.js.map +1 -0
  82. package/dist/assets/{src-BD8RBVEp.js → src-CCt5s4DK.js} +3073 -1890
  83. package/dist/assets/src-CCt5s4DK.js.map +1 -0
  84. package/dist/assets/{sshForges-DWrESWkK.js → sshForges-D8CPaIbR.js} +16 -9
  85. package/dist/assets/{sshForges-DWrESWkK.js.map → sshForges-D8CPaIbR.js.map} +1 -1
  86. package/dist/assets/{translate-D1uP0q32.js → translate-Cb-6hMhD.js} +17 -12
  87. package/dist/assets/translate-Cb-6hMhD.js.map +1 -0
  88. package/dist/assets/{usdt-DhVN8geQ.js → usdt-ds461mzA.js} +3 -3
  89. package/dist/assets/{usdt-DhVN8geQ.js.map → usdt-ds461mzA.js.map} +1 -1
  90. package/dist/assets/{words-DdXPkB3n.js → words-B1ylON2h.js} +4 -2
  91. package/dist/assets/words-B1ylON2h.js.map +1 -0
  92. package/dist/ghostly.mjs +1 -1
  93. package/package.json +1 -1
  94. package/dist/assets/api-DFCgr6RH.js.map +0 -1
  95. package/dist/assets/api-raWw9j_m.js +0 -3
  96. package/dist/assets/apiKit-CCavJJcl.js.map +0 -1
  97. package/dist/assets/apps-DmxEG147.js.map +0 -1
  98. package/dist/assets/buttons-CuRfKnPI.js.map +0 -1
  99. package/dist/assets/buttons-De3LPdSG.js +0 -2
  100. package/dist/assets/daemonProof-DtrL5lE5.js +0 -236
  101. package/dist/assets/daemonProof-DtrL5lE5.js.map +0 -1
  102. package/dist/assets/endpoint-BdaeBw2L.js.map +0 -1
  103. package/dist/assets/envelope-Dt75vrmY.js.map +0 -1
  104. package/dist/assets/fileBytesIdb-DZcESfTt.js +0 -2
  105. package/dist/assets/groupFiles-FXel6zIc.js.map +0 -1
  106. package/dist/assets/host-DIBeK_c_.js.map +0 -1
  107. package/dist/assets/idb-BkOJES5_.js.map +0 -1
  108. package/dist/assets/irohWeb-BSv_BWyG.js.map +0 -1
  109. package/dist/assets/main-BbhfMTt8.js.map +0 -1
  110. package/dist/assets/networkReason-BncJ9KSM.js +0 -154
  111. package/dist/assets/networkReason-BncJ9KSM.js.map +0 -1
  112. package/dist/assets/ownDid-D8z5gwGI.js.map +0 -1
  113. package/dist/assets/profiles-MFtCmJwK.js.map +0 -1
  114. package/dist/assets/registry-B2Dtnibo.js.map +0 -1
  115. package/dist/assets/server-Dw1o8z1o.js.map +0 -1
  116. package/dist/assets/src-BD8RBVEp.js.map +0 -1
  117. package/dist/assets/translate-D1uP0q32.js.map +0 -1
  118. package/dist/assets/words-DdXPkB3n.js.map +0 -1
@@ -1,12 +1,12 @@
1
- import { $o as CALL_SIGNAL_MAX_AGE_MS, Fu as fromBase64Url, Ni as isPublicAddress, cs as signalHasVideo, es as RTC_CONFIG, hu as setLinkTraceSink, is as callSignalHeardAt, ns as buildSdpFromSignal, os as extractParamsFromSdp, rs as callRtcConfig, si as checkPushEndpoint, ss as parseCallSignal, ts as answersOffer } from "./src-BD8RBVEp.js";
2
- import { o as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-BSv_BWyG.js";
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
3
  import { r as asCliError, t as CliError } from "./errors-R4S2SAEM.js";
4
- import { l as findOwnNamedChat, o as findChat } from "./apiKit-CCavJJcl.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-DFCgr6RH.js";
6
- import { b as privateFolder, g as startingPath, n as RESTORED_MARK, r as acquireLock, v as ownFolder, x as runtimePath } from "./profiles-MFtCmJwK.js";
7
- import { _ as isCallRate, f as DEFAULT_RATE, g as frameSamples, h as frameBytes, i as newDaemonSecret, m as bytesToMs, o as proof, p as PlaybackQueue, r as greeting, u as removeDaemonSecret } from "./daemonProof-DtrL5lE5.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";
8
8
  import { createRequire } from "node:module";
9
- import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, fsyncSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
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";
11
11
  import { dirname, join } from "node:path";
12
12
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
@@ -980,6 +980,10 @@ var CallManager = class {
980
980
  clearing = /* @__PURE__ */ new Map();
981
981
  /** Per chat: when this side's last call there ended before it was answered (`CALL_PACE_MS`). */
982
982
  unansweredAt = /* @__PURE__ */ new Map();
983
+ /** Per chat: when the contact's last call there was missed after it barely rang, or held back (`QUICK_REDIAL_MS`). */
984
+ missedAt = /* @__PURE__ */ new Map();
985
+ /** Per chat: the contact's last call held back (`QUICK_REDIAL_MS`) until its hang-up, and when it came. */
986
+ held = /* @__PURE__ */ new Map();
983
987
  /** The early answers being made, those of ended calls too (MAX_EARLY_ANSWERS). */
984
988
  makings = /* @__PURE__ */ new Set();
985
989
  auto;
@@ -1014,7 +1018,14 @@ var CallManager = class {
1014
1018
  if (call?.state === "connected" && signal.t !== "h" && signal.t !== "v") return;
1015
1019
  if (signal.t === "o" && !call) {
1016
1020
  this.lastSignal.set(chat, signal.ts);
1017
- this.incoming(chat, signal);
1021
+ 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`);
1023
+ this.missedAt.set(chat, this.now);
1024
+ this.held.set(chat, {
1025
+ offer: signal,
1026
+ at: this.now
1027
+ });
1028
+ } else this.incoming(chat, signal);
1018
1029
  } else if (signal.t === "a" && call?.direction === "out" && call.offering && answersOffer(signal, call.offerTs)) {
1019
1030
  this.lastSignal.set(chat, signal.ts);
1020
1031
  this.accepted(call, signal);
@@ -1024,10 +1035,12 @@ var CallManager = class {
1024
1035
  if (!mine || signal.ts < mine || signal.ts === mine && (signal.f ?? "") < (call.media?.local.f ?? "")) this.yieldTo(call, signal);
1025
1036
  } else if (signal.t === "o" && call?.direction === "in" && call.state === "connecting" && call.media && signal.ts > (call.offer?.ts ?? 0)) {
1026
1037
  this.lastSignal.set(chat, signal.ts);
1027
- this.reanswer(call, signal);
1038
+ 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`);
1028
1040
  } else if (signal.t === "v") this.lastSignal.set(chat, signal.ts);
1029
1041
  else if (signal.t === "h") {
1030
1042
  this.lastSignal.set(chat, signal.ts);
1043
+ this.held.delete(chat);
1031
1044
  if (call) {
1032
1045
  const unreachable = signal.r === "u" && call.state !== "connected";
1033
1046
  const failed = unreachable || call.state !== "connected" && (call.offering || call.direction === "out" && call.redials > 0);
@@ -1046,6 +1059,7 @@ var CallManager = class {
1046
1059
  this.incoming(call.chat, offer);
1047
1060
  }
1048
1061
  incoming(chat, offer) {
1062
+ this.held.delete(chat);
1049
1063
  const link = this.link(chat);
1050
1064
  const call = this.add(chat, "in", this.auto.rate);
1051
1065
  call.offer = offer;
@@ -1130,6 +1144,7 @@ var CallManager = class {
1130
1144
  /** The contact's newer offer (its `redial`): answered on a new connection, on the call's socket. */
1131
1145
  async reanswer(call, offer) {
1132
1146
  process.stderr.write(`ghostly: call ${call.id}: the contact offered again: answering on a new connection\n`);
1147
+ call.reanswers++;
1133
1148
  call.offer = offer;
1134
1149
  call.video = signalHasVideo(offer);
1135
1150
  this.arm(call, CONNECT_MS, "failed", true);
@@ -1214,6 +1229,11 @@ var CallManager = class {
1214
1229
  async start(chat, options) {
1215
1230
  const link = this.callable(chat);
1216
1231
  if (this.byChat(link.id)) throw new CliError("busy", "A call is already on in this chat");
1232
+ const held = this.held.get(link.id);
1233
+ if (held && this.now - held.at < 6e4) {
1234
+ this.incoming(link.id, held.offer);
1235
+ throw new CliError("busy", "The contact is calling: their call rings here");
1236
+ }
1217
1237
  this.paced(link.id);
1218
1238
  const rate = rateOf(options.rate, this.auto.rate);
1219
1239
  const stack = await this.stack();
@@ -1365,6 +1385,7 @@ var CallManager = class {
1365
1385
  offerTs: 0,
1366
1386
  offering: false,
1367
1387
  redials: 0,
1388
+ reanswers: 0,
1368
1389
  attempt: 0,
1369
1390
  answered: 0,
1370
1391
  answeredAt: 0,
@@ -1502,6 +1523,10 @@ var CallManager = class {
1502
1523
  if (call.watcher) clearInterval(call.watcher);
1503
1524
  this.calls.delete(call.id);
1504
1525
  if (call.direction === "out" && call.connectedAt === null && call.state === "ringing" && (reason === "hangup" || reason === "unanswered")) this.unansweredAt.set(call.chat, this.now);
1526
+ if (call.direction === "in" && call.connectedAt === null && reason !== "hangup" && reason !== "stopped") {
1527
+ if (this.now - call.startedAt < 1e3) this.missedAt.set(call.chat, this.now);
1528
+ else this.missedAt.delete(call.chat);
1529
+ }
1505
1530
  if (report) process.stderr.write(`ghostly: call ${call.id}: ended (${reason})${call.media ? `, ice ${call.media.ice.state}` : ""}\n`);
1506
1531
  try {
1507
1532
  call.media?.close();
@@ -1546,6 +1571,11 @@ var CallManager = class {
1546
1571
  }
1547
1572
  throw new CliError("busy", `Your last call in this chat ended unanswered a moment ago: call again in ${Math.ceil(left / 100) / 10} s`, { retryAfterMs: left });
1548
1573
  }
1574
+ /** Whether the contact's call coming now in the chat is held back: its last one was missed after it barely rang, or held, a moment ago. */
1575
+ quickRedial(chat) {
1576
+ const quick = this.host.quickRedialMs ?? 2e3, last = this.missedAt.get(chat);
1577
+ return !!quick && last !== void 0 && this.now - last < quick;
1578
+ }
1549
1579
  arm(call, ms, reason, tell) {
1550
1580
  this.disarm(call);
1551
1581
  call.timer = setTimeout(() => void this.end(call, reason, tell), ms);
@@ -1689,7 +1719,10 @@ var SEEN_KEEP_MS = 2592e6;
1689
1719
  var SWEEP_EVERY_MS = 216e5;
1690
1720
  /** How long a `file.*` event waits for the message that carries its file. */
1691
1721
  var FILE_MESSAGE_WAIT_MS = 2e3;
1692
- /** The notice an app sends when a chat first goes live (apps/ui/src/hooks/useChat.ts): shown as a line, not a message. */
1722
+ /**
1723
+ * The notice an app sends when a chat first goes live (apps/ui/src/hooks/useChat.ts): shown as a line, not a message.
1724
+ * The contact's only on the row the engine took as their joined line (`StoredMessage.joinLine`).
1725
+ */
1693
1726
  var JOIN_NOTICE = /^👋 (?:(.+) )?joined$/;
1694
1727
  /**
1695
1728
  * Turns the engine's events into the stream, keeps the journal, and remembers which messages it already reported
@@ -1701,6 +1734,15 @@ var EventHub = class {
1701
1734
  now;
1702
1735
  seenDb;
1703
1736
  seq = 0;
1737
+ /**
1738
+ * The last seq the journal dropped (a trim, a journal set aside), kept in `<journal>.dropped`: a replay from before it
1739
+ * starts with `events.gap`. What the person removed (`forget`) leaves holes after it, which are none.
1740
+ */
1741
+ dropped = 0;
1742
+ /** Whether `<journal>.dropped` is written: before `forget` first takes a journal's first events, it must be. */
1743
+ marked = false;
1744
+ /** Whether `dropped` is ahead of `<journal>.dropped` (a full disk refused it): the next event's write tries it again. */
1745
+ markOwed = false;
1704
1746
  journalLines = 0;
1705
1747
  journalBytes = 0;
1706
1748
  listeners = /* @__PURE__ */ new Set();
@@ -1740,13 +1782,32 @@ var EventHub = class {
1740
1782
  /** Loads the journal's last seq and the seen set; call before `sink` is attached. */
1741
1783
  async open() {
1742
1784
  try {
1785
+ const dropped = readDropped(this.journalPath + ".dropped");
1743
1786
  if (existsSync(this.journalPath)) {
1744
- const { seq, lines, size } = journalEnd(this.journalPath);
1787
+ const { seq, first, lines, size, tail } = journalEnd(this.journalPath);
1745
1788
  this.journalLines = lines;
1746
1789
  this.journalBytes = size;
1747
1790
  this.seq = seq;
1748
- if (size > 33554432 || lines > 2e4) this.trimJournal();
1749
- }
1791
+ this.dropped = dropped ?? (first === void 0 ? seq : first - 1);
1792
+ this.marked = dropped !== void 0;
1793
+ let ended = false;
1794
+ if (tail?.whole) try {
1795
+ appendFileSync(this.journalPath, "\n");
1796
+ this.journalBytes++;
1797
+ ended = true;
1798
+ } catch {}
1799
+ if (tail && !ended) {
1800
+ truncateSync(this.journalPath, tail.at);
1801
+ this.journalLines--;
1802
+ this.journalBytes = tail.at;
1803
+ const lost = tail.whole ? seq : tail.seq !== void 0 && tail.seq > seq ? tail.seq : void 0;
1804
+ if (lost !== void 0) {
1805
+ this.seq = lost;
1806
+ this.markDropped(Math.max(this.dropped, lost));
1807
+ }
1808
+ }
1809
+ if (this.journalBytes > 33554432 || this.journalLines > 2e4) this.trimJournal();
1810
+ } else if (dropped !== void 0) rmSync(this.journalPath + ".dropped", { force: true });
1750
1811
  } catch (error) {
1751
1812
  process.stderr.write(`ghostly: the event journal could not be read, a new one begins: ${error instanceof Error ? error.message : String(error)}\n`);
1752
1813
  try {
@@ -1754,6 +1815,7 @@ var EventHub = class {
1754
1815
  } catch {}
1755
1816
  this.journalLines = 0;
1756
1817
  this.journalBytes = 0;
1818
+ this.markDropped(this.seq);
1757
1819
  }
1758
1820
  this.db = await new Promise((resolve, reject) => {
1759
1821
  const request = indexedDB.open(this.seenDb, 1);
@@ -1874,24 +1936,56 @@ var EventHub = class {
1874
1936
  this.appListeners.add(listener);
1875
1937
  return () => this.appListeners.delete(listener);
1876
1938
  }
1877
- /** Events after `since` still in the journal; a gap event first when older ones were dropped. */
1939
+ /**
1940
+ * Events after `since` still in the journal; a gap event where ones up to `dropped` are missing (a trim, a full disk
1941
+ * that took none of them). The events of what the person removed (`forget`) after it are no gap: they are not here on
1942
+ * purpose.
1943
+ */
1878
1944
  replay(since) {
1879
- if (!existsSync(this.journalPath) || since >= this.seq) return [];
1945
+ if (since >= this.seq) return [];
1880
1946
  const out = [];
1881
- for (const line of journalTail(this.journalPath).lines) try {
1882
- const event = JSON.parse(line);
1883
- if (event.seq > since) out.push(event);
1884
- } catch {}
1885
- if (out.length && out[0].seq > since + 1) out.unshift({
1886
- seq: since,
1887
- id: `events.gap:${since}:${out[0].seq}`,
1888
- type: "events.gap",
1889
- at: this.now(),
1890
- from: since + 1,
1891
- to: out[0].seq - 1
1892
- });
1947
+ let before = since;
1948
+ const gapTo = (next) => {
1949
+ if (next > before + 1 && before < this.dropped) out.push({
1950
+ seq: before,
1951
+ id: `events.gap:${before}:${next}`,
1952
+ type: "events.gap",
1953
+ at: this.now(),
1954
+ from: before + 1,
1955
+ to: Math.min(this.dropped, next - 1)
1956
+ });
1957
+ };
1958
+ if (existsSync(this.journalPath)) for (const line of journalTail(this.journalPath).lines) {
1959
+ let event;
1960
+ try {
1961
+ event = JSON.parse(line);
1962
+ } catch {
1963
+ continue;
1964
+ }
1965
+ if (event.seq <= before) continue;
1966
+ gapTo(event.seq);
1967
+ out.push(event);
1968
+ before = event.seq;
1969
+ }
1970
+ gapTo(Math.min(this.dropped, this.seq) + 1);
1893
1971
  return out;
1894
1972
  }
1973
+ /**
1974
+ * Notes that the journal no longer holds the events up to `seq`. Written before the journal is: a stop in between
1975
+ * leaves the mark ahead of the journal (a gap said where none was), never behind it (a gap not said).
1976
+ */
1977
+ markDropped(seq) {
1978
+ this.dropped = seq;
1979
+ try {
1980
+ writeFileSync(this.journalPath + ".dropped.tmp", String(seq), { mode: 384 });
1981
+ renameSync(this.journalPath + ".dropped.tmp", this.journalPath + ".dropped");
1982
+ this.marked = true;
1983
+ this.markOwed = false;
1984
+ } catch (error) {
1985
+ this.markOwed = true;
1986
+ process.stderr.write(`ghostly: event journal error: ${error instanceof Error ? error.message : String(error)}\n`);
1987
+ }
1988
+ }
1895
1989
  get lastSeq() {
1896
1990
  return this.seq;
1897
1991
  }
@@ -1904,13 +1998,17 @@ var EventHub = class {
1904
1998
  at: this.now(),
1905
1999
  ...fields
1906
2000
  };
2001
+ let written = false;
1907
2002
  try {
1908
- const line = JSON.stringify(event) + "\n";
1909
- appendFileSync(this.journalPath, line, { mode: 384 });
1910
- this.journalBytes += Buffer.byteLength(line);
2003
+ if (this.markOwed) this.markDropped(this.dropped);
2004
+ const line = Buffer.from(JSON.stringify(event) + "\n");
2005
+ appendWhole(this.journalPath, line);
2006
+ written = true;
2007
+ this.journalBytes += line.length;
1911
2008
  if (++this.journalLines > 2e4 || this.journalBytes > 33554432) this.trimJournal();
1912
2009
  } catch (error) {
1913
2010
  process.stderr.write(`ghostly: event journal error: ${error instanceof Error ? error.message : String(error)}\n`);
2011
+ if (!written) this.markDropped(Math.max(this.dropped, event.seq));
1914
2012
  }
1915
2013
  this.tell(event);
1916
2014
  return event;
@@ -1943,6 +2041,8 @@ var EventHub = class {
1943
2041
  let start = lines.length, bytes = 0;
1944
2042
  while (start > 0 && bytes + Buffer.byteLength(lines[start - 1]) + 1 <= 16777216) bytes += Buffer.byteLength(lines[--start]) + 1;
1945
2043
  const kept = lines.slice(start);
2044
+ const first = firstSeq(kept);
2045
+ this.markDropped(Math.max(this.dropped, first === void 0 ? this.seq : first - 1));
1946
2046
  writeFileSync(this.journalPath + ".tmp", kept.length ? kept.join("\n") + "\n" : "", { mode: 384 });
1947
2047
  renameSync(this.journalPath + ".tmp", this.journalPath);
1948
2048
  this.journalLines = kept.length;
@@ -1991,6 +2091,7 @@ var EventHub = class {
1991
2091
  return [JSON.stringify(written)];
1992
2092
  });
1993
2093
  if (!changed) return;
2094
+ if (!this.marked) this.markDropped(this.dropped);
1994
2095
  const tail = kept.length ? kept.join("\n") + "\n" : "";
1995
2096
  writeFileSync(this.journalPath + ".tmp", Buffer.concat([bytes.subarray(start, from), Buffer.from(tail)]), { mode: 384 });
1996
2097
  renameSync(this.journalPath + ".tmp", this.journalPath);
@@ -2342,7 +2443,7 @@ var EventHub = class {
2342
2443
  message: json()
2343
2444
  });
2344
2445
  } else {
2345
- const notice = JOIN_NOTICE.exec(message.text);
2446
+ const notice = message.sender === "me" || message.joinLine ? JOIN_NOTICE.exec(message.text) : null;
2346
2447
  const type = notice ? message.sender === "peer" ? "chat.joined" : "chat.announced" : message.sender === "peer" ? "message.received" : "message.sent";
2347
2448
  this.emit(type, `${type}:${chat}:${message.id}`, {
2348
2449
  chat,
@@ -2420,22 +2521,23 @@ var EventHub = class {
2420
2521
  }
2421
2522
  /**
2422
2523
  * A press on a button of a message of mine (WISP 406 · Message Buttons), after the reply's own event: the question
2423
- * (`messageId`), the button, its label, who pressed (`by`: the chat, or a group member's key), `name` (the chat's name
2424
- * here, as `chat list` gives it: its label, else the contact's own name; a group member's roster name) and the reply
2425
- * (`replyId`). `untrusted.name` is the name the person gave themselves, as an agent turn's: theirs to choose, so
2426
- * data, never instructions. The engine marks a reply a press only while the buttons were open for that person.
2524
+ * (`messageId`), the button, its label, who pressed (`by`: the chat, or a group member's key), `name` (the label this
2525
+ * profile gave the chat, as `chat list` gives it; null without one, and in a group) and the reply (`replyId`).
2526
+ * `untrusted.name` is the name the person gave themselves, as an agent turn's: theirs to choose, so data, never
2527
+ * instructions, and under `untrusted` only. The engine marks a reply a press only while the buttons were open for
2528
+ * that person.
2427
2529
  */
2428
2530
  pressed(chat, group, message, json) {
2429
2531
  const press = message.press;
2430
2532
  const link = group ? void 0 : this.state?.links.find((l) => l.id === chat);
2431
- const name = group ? json.nick : link ? chatJson(link).name : null;
2533
+ const name = link ? chatJson(link).label : null;
2432
2534
  this.emit("button.pressed", `button.pressed:${group ?? chat}:${message.id}`, {
2433
2535
  ...group ? { group } : { chat },
2434
2536
  messageId: press.messageId,
2435
2537
  button: press.button,
2436
2538
  label: press.label,
2437
2539
  by: group ? message.member ?? null : chat,
2438
- name: name ?? null,
2540
+ name,
2439
2541
  replyId: message.id,
2440
2542
  ...press.inferred ? { inferred: true } : {},
2441
2543
  untrusted: { name: json.nick ?? null }
@@ -2606,21 +2708,76 @@ function journalEnd(path) {
2606
2708
  if (stop > from) lines++;
2607
2709
  from = stop + 1;
2608
2710
  }
2609
- let seq = 0;
2711
+ let first;
2712
+ for (let from = start; from < bytes.length && first === void 0;) {
2713
+ const end = bytes.indexOf(10, from);
2714
+ const stop = end === -1 ? bytes.length : end;
2715
+ if (stop > from) first = firstSeq([bytes.toString("utf8", from, stop)]);
2716
+ from = stop + 1;
2717
+ }
2718
+ let seq = 0, read = -1;
2610
2719
  for (let stop = bytes.length; stop > start;) {
2611
2720
  const from = Math.max(start, bytes.lastIndexOf(10, stop - 1) + 1);
2612
2721
  if (from < stop) try {
2613
2722
  seq = JSON.parse(bytes.toString("utf8", from, stop)).seq;
2723
+ read = from;
2614
2724
  break;
2615
2725
  } catch {}
2616
2726
  stop = from - 1;
2617
2727
  }
2728
+ let tail;
2729
+ if (bytes.length > start && bytes[bytes.length - 1] !== 10) {
2730
+ const from = Math.max(start, bytes.lastIndexOf(10) + 1);
2731
+ const named = /^\{"seq":(\d+)[,}]/.exec(bytes.toString("latin1", from, Math.min(bytes.length, from + 32)))?.[1];
2732
+ tail = {
2733
+ at: size - bytes.length + from,
2734
+ whole: read === from,
2735
+ seq: named === void 0 ? void 0 : Number(named)
2736
+ };
2737
+ }
2618
2738
  return {
2619
2739
  seq,
2740
+ first,
2620
2741
  lines,
2621
- size
2742
+ size,
2743
+ tail
2622
2744
  };
2623
2745
  }
2746
+ /** The seq of the first of these lines that can be read. */
2747
+ function firstSeq(lines) {
2748
+ for (const line of lines) try {
2749
+ const { seq } = JSON.parse(line);
2750
+ if (typeof seq === "number") return seq;
2751
+ } catch {}
2752
+ }
2753
+ /** The journal's dropped mark (`EventHub.dropped`), or undefined when there is none (a journal from before it). */
2754
+ function readDropped(path) {
2755
+ try {
2756
+ const seq = Number(readFileSync(path, "utf8").trim());
2757
+ return Number.isSafeInteger(seq) && seq >= 0 ? seq : void 0;
2758
+ } catch {
2759
+ return;
2760
+ }
2761
+ }
2762
+ /**
2763
+ * 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.
2765
+ */
2766
+ function appendWhole(path, line) {
2767
+ const fd = openSync(path, "a", 384);
2768
+ let whole = -1;
2769
+ try {
2770
+ whole = fstatSync(fd).size;
2771
+ for (let at = 0; at < line.length;) at += writeSync(fd, line, at);
2772
+ } catch (error) {
2773
+ if (whole >= 0) try {
2774
+ ftruncateSync(fd, whole);
2775
+ } catch {}
2776
+ throw error;
2777
+ } finally {
2778
+ closeSync(fd);
2779
+ }
2780
+ }
2624
2781
  /** The bytes of the journal's last `JOURNAL_MAX_BYTES`, `start` where its first whole line begins in them, and its size. */
2625
2782
  function journalWindow(path) {
2626
2783
  const fd = openSync(path, "r");
@@ -4936,7 +5093,7 @@ async function startRuntime(paths, options = {}) {
4936
5093
  const restored = join(paths.dir, RESTORED_MARK);
4937
5094
  if (existsSync(restored)) {
4938
5095
  try {
4939
- const rows = await import("./restoredRows-BCRCjhdF.js");
5096
+ const rows = await import("./restoredRows-CRYwIx3g.js");
4940
5097
  await rows.markRestoredWallet();
4941
5098
  await rows.markLeftOutFiles(leftOutIn(restored));
4942
5099
  await rows.forgetRatchets();
@@ -4956,15 +5113,15 @@ async function startRuntime(paths, options = {}) {
4956
5113
  await installEventSource();
4957
5114
  await preloadWalletModules();
4958
5115
  (await import("./ghostly_iroh_web-BzAXJUYH.js")).initSync({ module: irohWasmBytes() });
4959
- const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-BPDKufla.js"), import("./fileBytes-Q3ehcEr8.js")]);
5116
+ const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-DMzrIdCu.js"), import("./fileBytes-Douk1yOp.js")]);
4960
5117
  registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
4961
- if (await (await import("./blobFiles-DOQDRdDI.js")).moveBlobFiles()) await store.compact();
4962
- const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-Dw1o8z1o.js"), import("./endpoint-BdaeBw2L.js")]);
4963
- const mainline = dht.off ? null : new (await (import("./mainline-9Vc3c3SA.js"))).Mainline({
5118
+ 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({
4964
5121
  bootstrap: dht.bootstrap,
4965
5122
  host: dht.host
4966
5123
  });
4967
- const transport = mainline || pinned ? new (await (import("./mainline-9Vc3c3SA.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
5124
+ const transport = mainline || pinned ? new (await (import("./mainline-DWh4Ccri.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
4968
5125
  const apps = servedApps(paths.dir).length > 0;
4969
5126
  const server = new EngineServer({
4970
5127
  ...transport ? { transport } : {},
@@ -4977,6 +5134,7 @@ async function startRuntime(paths, options = {}) {
4977
5134
  servicesSupport: true,
4978
5135
  apps: apps ? "wire" : false,
4979
5136
  staysOnline: envSwitch("GHOSTLY_HUB", true),
5137
+ watchPeerIdleMs: DAEMON_WATCH_PEER_IDLE_MS,
4980
5138
  localFetch: nodeLocalFetch,
4981
5139
  pushSend: (request) => nodePushSend(request),
4982
5140
  holdFetch: nodeHoldFetch(),
@@ -5011,8 +5169,6 @@ async function startRuntime(paths, options = {}) {
5011
5169
  }
5012
5170
  //#endregion
5013
5171
  //#region src/host.ts
5014
- /** The longest request line the daemon reads (WISP 1100 § Framing). */
5015
- var MAX_LINE = 16777216;
5016
5172
  /**
5017
5173
  * The most a connection may leave unread (answers and events the daemon wrote that its client has not taken): past
5018
5174
  * it, the connection ends. A `listen` stopped with Ctrl+Z, or a client that stops reading, kept every later event in
@@ -5032,6 +5188,7 @@ var BASELINE_NEWEST = 100;
5032
5188
  * `deferGroups`: the groups' sessions would spend the relays' budget its message needs.
5033
5189
  */
5034
5190
  async function openHost(paths, mode, version, options = {}) {
5191
+ ownProfile(paths.dir);
5035
5192
  const locked = acquireLock(paths);
5036
5193
  const unmark = mode === "daemon" ? markStarting(paths) : () => {};
5037
5194
  const release = () => {
@@ -5322,6 +5479,6 @@ function connection(ctx, socket, secret) {
5322
5479
  });
5323
5480
  }
5324
5481
  //#endregion
5325
- export { BASELINE_NEWEST, MAX_LINE, MAX_UNREAD, keepServing, openHost, serve };
5482
+ export { BASELINE_NEWEST, MAX_UNREAD, keepServing, openHost, serve };
5326
5483
 
5327
- //# sourceMappingURL=host-DIBeK_c_.js.map
5484
+ //# sourceMappingURL=host-CaRlDMTd.js.map