@ghostlytools/cli 1.10.0 → 1.10.2

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 (104) hide show
  1. package/README.md +19 -17
  2. package/SKILL.md +5 -4
  3. package/dist/assets/api-DcE4KylM.js +3 -0
  4. package/dist/assets/{api-BF_KwecF.js → api-EUGHGnRz.js} +108 -49
  5. package/dist/assets/api-EUGHGnRz.js.map +1 -0
  6. package/dist/assets/{apiKit-Du1u2l4x.js → apiKit-CJVp_crp.js} +85 -22
  7. package/dist/assets/apiKit-CJVp_crp.js.map +1 -0
  8. package/dist/assets/{apps-Bti9fDoW.js → apps-C-KbyLCa.js} +1 -1
  9. package/dist/assets/{apps-DwPfp54I.js → apps-C54T_MOT.js} +33 -12
  10. package/dist/assets/apps-C54T_MOT.js.map +1 -0
  11. package/dist/assets/{arkade-DOWpA2Kr.js → arkade-BmxJTa65.js} +2 -2
  12. package/dist/assets/{arkade-DOWpA2Kr.js.map → arkade-BmxJTa65.js.map} +1 -1
  13. package/dist/assets/{backup-DZ_Q1eSu.js → backup-BxSH5BZG.js} +7 -6
  14. package/dist/assets/{backup-DZ_Q1eSu.js.map → backup-BxSH5BZG.js.map} +1 -1
  15. package/dist/assets/{backup-CeRckyl2.js → backup-C0Plp-DF.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/{buttons-BxIThdg9.js → buttons-B-ZJYdo0.js} +6 -6
  19. package/dist/assets/{buttons-BxIThdg9.js.map → buttons-B-ZJYdo0.js.map} +1 -1
  20. package/dist/assets/buttons-DA3wZfG0.js +2 -0
  21. package/dist/assets/childEnv-BVOQK9EA.js +21 -0
  22. package/dist/assets/childEnv-BVOQK9EA.js.map +1 -0
  23. package/dist/assets/{client-D5E1RQYB.js → client-CDa87uYD.js} +3 -3
  24. package/dist/assets/{client-D5E1RQYB.js.map → client-CDa87uYD.js.map} +1 -1
  25. package/dist/assets/codec-D45W1L8n.js +13 -0
  26. package/dist/assets/codec-D45W1L8n.js.map +1 -0
  27. package/dist/assets/{envelope-CugS9qwQ.js → envelope-C3yFCQa-.js} +3 -12
  28. package/dist/assets/envelope-C3yFCQa-.js.map +1 -0
  29. package/dist/assets/{errors-R4S2SAEM.js → errors-Dt-ZnyOX.js} +3 -1
  30. package/dist/assets/errors-Dt-ZnyOX.js.map +1 -0
  31. package/dist/assets/{fixedHosts-B4E4VrYE.js → fixedHosts-C6nCHjOa.js} +4 -4
  32. package/dist/assets/{fixedHosts-B4E4VrYE.js.map → fixedHosts-C6nCHjOa.js.map} +1 -1
  33. package/dist/assets/{groupFiles-NonOYBKN.js → groupFiles-DYopNE57.js} +217 -178
  34. package/dist/assets/groupFiles-DYopNE57.js.map +1 -0
  35. package/dist/assets/{host-DvcVt5YI.js → host-G5seUwaI.js} +241 -87
  36. package/dist/assets/host-G5seUwaI.js.map +1 -0
  37. package/dist/assets/{hyperdhtRelay-Ce42sR8x.js → hyperdhtRelay-B_uHjg_r.js} +28 -20
  38. package/dist/assets/hyperdhtRelay-B_uHjg_r.js.map +1 -0
  39. package/dist/assets/{irohWeb-C9ChbD-c.js → irohWeb-C-2oslSU.js} +120 -38
  40. package/dist/assets/irohWeb-C-2oslSU.js.map +1 -0
  41. package/dist/assets/{main-4qE381KM.js → main-Dk--nD7X.js} +92 -48
  42. package/dist/assets/main-Dk--nD7X.js.map +1 -0
  43. package/dist/assets/{mainline-DOwZDHVy.js → mainline-HPlVrl8R.js} +5 -5
  44. package/dist/assets/mainline-HPlVrl8R.js.map +1 -0
  45. package/dist/assets/networkReason-CfpO9ayz.js +474 -0
  46. package/dist/assets/networkReason-CfpO9ayz.js.map +1 -0
  47. package/dist/assets/{nwc-CHLWFV1R.js → nwc-BY7BPttn.js} +3 -3
  48. package/dist/assets/{nwc-CHLWFV1R.js.map → nwc-BY7BPttn.js.map} +1 -1
  49. package/dist/assets/{nwcProvider-BlkPOJen.js → nwcProvider-CfpbNUf7.js} +2 -2
  50. package/dist/assets/{nwcProvider-BlkPOJen.js.map → nwcProvider-CfpbNUf7.js.map} +1 -1
  51. package/dist/assets/{ownDid-yXtY_1B5.js → ownDid-DJFZM2cV.js} +2 -2
  52. package/dist/assets/{ownDid-yXtY_1B5.js.map → ownDid-DJFZM2cV.js.map} +1 -1
  53. package/dist/assets/{profiles-vbXHs0Mq.js → profiles-DKmZGXp6.js} +22 -9
  54. package/dist/assets/profiles-DKmZGXp6.js.map +1 -0
  55. package/dist/assets/{registry-chCD0KWS.js → registry-BUm4cAzV.js} +60 -19
  56. package/dist/assets/registry-BUm4cAzV.js.map +1 -0
  57. package/dist/assets/{registry-BN9r2pR4.js → registry-CAzrtV0_.js} +1 -1
  58. package/dist/assets/{resolve-Dtzogt2W.js → resolve-CDD4X68j.js} +5 -3
  59. package/dist/assets/resolve-CDD4X68j.js.map +1 -0
  60. package/dist/assets/{restoredRows-CRYwIx3g.js → restoredRows-YhlbokEE.js} +4 -2
  61. package/dist/assets/restoredRows-YhlbokEE.js.map +1 -0
  62. package/dist/assets/{secretGuard-CSVNxXVW.js → secretGuard-B7Hj0Kvz.js} +2 -2
  63. package/dist/assets/{secretGuard-CSVNxXVW.js.map → secretGuard-B7Hj0Kvz.js.map} +1 -1
  64. package/dist/assets/secretGuard-DUr6bgKc.js +2 -0
  65. package/dist/assets/{server-BZnsm5X5.js → server-DcOsgYDU.js} +1046 -573
  66. package/dist/assets/server-DcOsgYDU.js.map +1 -0
  67. package/dist/assets/{src-DZagapGt.js → src-D31D1_oY.js} +2360 -1673
  68. package/dist/assets/src-D31D1_oY.js.map +1 -0
  69. package/dist/assets/{sshForges-BkTgy5rx.js → sshForges-DerRwMf3.js} +2 -2
  70. package/dist/assets/{sshForges-BkTgy5rx.js.map → sshForges-DerRwMf3.js.map} +1 -1
  71. package/dist/assets/{translate-B9SMd6uf.js → translate-C-sj0VJe.js} +12 -8
  72. package/dist/assets/{translate-B9SMd6uf.js.map → translate-C-sj0VJe.js.map} +1 -1
  73. package/dist/assets/{usdt-BU4ezonh.js → usdt-DwHqp625.js} +3 -3
  74. package/dist/assets/{usdt-BU4ezonh.js.map → usdt-DwHqp625.js.map} +1 -1
  75. package/dist/assets/{waitNotice-B8D8WhbE.js → waitNotice-D52RWbV4.js} +38 -4
  76. package/dist/assets/waitNotice-D52RWbV4.js.map +1 -0
  77. package/dist/assets/{words-jYy7lTcb.js → words-Db9WgatT.js} +3 -3
  78. package/dist/assets/words-Db9WgatT.js.map +1 -0
  79. package/dist/ghostly.mjs +1 -1
  80. package/package.json +1 -1
  81. package/dist/assets/api-BF_KwecF.js.map +0 -1
  82. package/dist/assets/api-DdrA86Ur.js +0 -3
  83. package/dist/assets/apiKit-Du1u2l4x.js.map +0 -1
  84. package/dist/assets/apps-DwPfp54I.js.map +0 -1
  85. package/dist/assets/buttons-D9QBHS9Y.js +0 -2
  86. package/dist/assets/envelope-CugS9qwQ.js.map +0 -1
  87. package/dist/assets/errors-R4S2SAEM.js.map +0 -1
  88. package/dist/assets/groupFiles-NonOYBKN.js.map +0 -1
  89. package/dist/assets/host-DvcVt5YI.js.map +0 -1
  90. package/dist/assets/hyperdhtRelay-Ce42sR8x.js.map +0 -1
  91. package/dist/assets/irohWeb-C9ChbD-c.js.map +0 -1
  92. package/dist/assets/main-4qE381KM.js.map +0 -1
  93. package/dist/assets/mainline-DOwZDHVy.js.map +0 -1
  94. package/dist/assets/networkReason-MInk1Y63.js +0 -154
  95. package/dist/assets/networkReason-MInk1Y63.js.map +0 -1
  96. package/dist/assets/profiles-vbXHs0Mq.js.map +0 -1
  97. package/dist/assets/registry-chCD0KWS.js.map +0 -1
  98. package/dist/assets/resolve-Dtzogt2W.js.map +0 -1
  99. package/dist/assets/restoredRows-CRYwIx3g.js.map +0 -1
  100. package/dist/assets/secretGuard-Q2BKq0q0.js +0 -2
  101. package/dist/assets/server-BZnsm5X5.js.map +0 -1
  102. package/dist/assets/src-DZagapGt.js.map +0 -1
  103. package/dist/assets/waitNotice-B8D8WhbE.js.map +0 -1
  104. package/dist/assets/words-jYy7lTcb.js.map +0 -1
@@ -1,12 +1,12 @@
1
- import { Fi as isPublicAddress, Hu as fromBase64Url, Su as setLinkTraceSink, as as buildSdpFromSignal, ds as signalHasVideo, is as answersOffer, li as checkPushEndpoint, ls as extractParamsFromSdp, ns as CALL_SIGNAL_MAX_AGE_MS, os as callRtcConfig, rs as RTC_CONFIG, ss as callSignalHeardAt, us as parseCallSignal } from "./src-DZagapGt.js";
2
- import { o as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-C9ChbD-c.js";
3
- import { r as asCliError, t as CliError } from "./errors-R4S2SAEM.js";
4
- import { l as findOwnNamedChat, o as findChat } from "./apiKit-Du1u2l4x.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-BF_KwecF.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-vbXHs0Mq.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-D5E1RQYB.js";
1
+ import { Au as setLinkTraceSink, Qu as fromBase64Url, _s as parseCallSignal, cs as CALL_SIGNAL_MAX_AGE_MS, ds as answersOffer, fi as checkPushEndpoint, fs as buildSdpFromSignal, gs as extractParamsFromSdp, ms as callSignalHeardAt, ps as callRtcConfig, qo as DAEMON_WATCH_PEER_IDLE_MS, ua as isPublicAddress, us as RTC_CONFIG, vs as signalHasVideo } from "./src-D31D1_oY.js";
2
+ import { o as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-C-2oslSU.js";
3
+ import { r as asCliError, t as CliError } from "./errors-Dt-ZnyOX.js";
4
+ import { s as findChat, u as findOwnNamedChat } from "./apiKit-CJVp_crp.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-EUGHGnRz.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-DKmZGXp6.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-CDa87uYD.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();
@@ -1309,7 +1329,8 @@ var CallManager = class {
1309
1329
  };
1310
1330
  }
1311
1331
  setAuto(next) {
1312
- const from = (next.from ?? []).map((ref) => findOwnNamedChat(this.host.engine.getState().links, ref).id);
1332
+ const { links, groups } = this.host.engine.getState();
1333
+ const from = (next.from ?? []).map((ref) => findOwnNamedChat(links, ref, groups).id);
1313
1334
  this.auto = {
1314
1335
  on: next.on,
1315
1336
  from: next.on ? from : [],
@@ -1365,6 +1386,7 @@ var CallManager = class {
1365
1386
  offerTs: 0,
1366
1387
  offering: false,
1367
1388
  redials: 0,
1389
+ reanswers: 0,
1368
1390
  attempt: 0,
1369
1391
  answered: 0,
1370
1392
  answeredAt: 0,
@@ -1502,6 +1524,10 @@ var CallManager = class {
1502
1524
  if (call.watcher) clearInterval(call.watcher);
1503
1525
  this.calls.delete(call.id);
1504
1526
  if (call.direction === "out" && call.connectedAt === null && call.state === "ringing" && (reason === "hangup" || reason === "unanswered")) this.unansweredAt.set(call.chat, this.now);
1527
+ if (call.direction === "in" && call.connectedAt === null && reason !== "hangup" && reason !== "stopped") {
1528
+ if (this.now - call.startedAt < 1e3) this.missedAt.set(call.chat, this.now);
1529
+ else this.missedAt.delete(call.chat);
1530
+ }
1505
1531
  if (report) process.stderr.write(`ghostly: call ${call.id}: ended (${reason})${call.media ? `, ice ${call.media.ice.state}` : ""}\n`);
1506
1532
  try {
1507
1533
  call.media?.close();
@@ -1546,6 +1572,11 @@ var CallManager = class {
1546
1572
  }
1547
1573
  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
1574
  }
1575
+ /** 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. */
1576
+ quickRedial(chat) {
1577
+ const quick = this.host.quickRedialMs ?? 2e3, last = this.missedAt.get(chat);
1578
+ return !!quick && last !== void 0 && this.now - last < quick;
1579
+ }
1549
1580
  arm(call, ms, reason, tell) {
1550
1581
  this.disarm(call);
1551
1582
  call.timer = setTimeout(() => void this.end(call, reason, tell), ms);
@@ -1626,9 +1657,10 @@ var CallManager = class {
1626
1657
  link(chat) {
1627
1658
  return this.host.engine.getState().links.find((l) => l.id === chat);
1628
1659
  }
1629
- /** A chat by id, contact key, prefix or name (the API's rules, `findChat`). */
1660
+ /** A chat by id, contact key, prefix or name (the API's rules, `findChat`); a group's says it is one. */
1630
1661
  chatId(ref) {
1631
- return findChat(this.host.engine.getState().links, ref).id;
1662
+ const { links, groups } = this.host.engine.getState();
1663
+ return findChat(links, ref, groups).id;
1632
1664
  }
1633
1665
  /** The chat, if a call can go in it now; else why not (the engine's reason). */
1634
1666
  callable(ref) {
@@ -1711,6 +1743,10 @@ var EventHub = class {
1711
1743
  dropped = 0;
1712
1744
  /** Whether `<journal>.dropped` is written: before `forget` first takes a journal's first events, it must be. */
1713
1745
  marked = false;
1746
+ /** Whether `dropped` is ahead of `<journal>.dropped` (a full disk refused it): the next event's write tries it again. */
1747
+ markOwed = false;
1748
+ /** Typing changes told this run: a change's id carries it, as it takes no seq of its own (`emitLive`). */
1749
+ typingChanges = 0;
1714
1750
  journalLines = 0;
1715
1751
  journalBytes = 0;
1716
1752
  listeners = /* @__PURE__ */ new Set();
@@ -1752,13 +1788,29 @@ var EventHub = class {
1752
1788
  try {
1753
1789
  const dropped = readDropped(this.journalPath + ".dropped");
1754
1790
  if (existsSync(this.journalPath)) {
1755
- const { seq, first, lines, size } = journalEnd(this.journalPath);
1791
+ const { seq, first, lines, size, tail } = journalEnd(this.journalPath);
1756
1792
  this.journalLines = lines;
1757
1793
  this.journalBytes = size;
1758
1794
  this.seq = seq;
1759
1795
  this.dropped = dropped ?? (first === void 0 ? seq : first - 1);
1760
1796
  this.marked = dropped !== void 0;
1761
- if (size > 33554432 || lines > 2e4) this.trimJournal();
1797
+ let ended = false;
1798
+ if (tail?.whole) try {
1799
+ appendFileSync(this.journalPath, "\n");
1800
+ this.journalBytes++;
1801
+ ended = true;
1802
+ } catch {}
1803
+ if (tail && !ended) {
1804
+ truncateSync(this.journalPath, tail.at);
1805
+ this.journalLines--;
1806
+ this.journalBytes = tail.at;
1807
+ const lost = tail.whole ? seq : tail.seq !== void 0 && tail.seq > seq ? tail.seq : void 0;
1808
+ if (lost !== void 0) {
1809
+ this.seq = lost;
1810
+ this.markDropped(Math.max(this.dropped, lost));
1811
+ }
1812
+ }
1813
+ if (this.journalBytes > 33554432 || this.journalLines > 2e4) this.trimJournal();
1762
1814
  } else if (dropped !== void 0) rmSync(this.journalPath + ".dropped", { force: true });
1763
1815
  } catch (error) {
1764
1816
  process.stderr.write(`ghostly: the event journal could not be read, a new one begins: ${error instanceof Error ? error.message : String(error)}\n`);
@@ -1889,24 +1941,37 @@ var EventHub = class {
1889
1941
  return () => this.appListeners.delete(listener);
1890
1942
  }
1891
1943
  /**
1892
- * Events after `since` still in the journal; a gap event first when older ones were dropped (`dropped`). The events of
1893
- * what the person removed (`forget`) are no gap: they are not here on purpose.
1944
+ * Events after `since` still in the journal; a gap event where ones up to `dropped` are missing (a trim, a full disk
1945
+ * that took none of them). The events of what the person removed (`forget`) after it are no gap: they are not here on
1946
+ * purpose.
1894
1947
  */
1895
1948
  replay(since) {
1896
- if (!existsSync(this.journalPath) || since >= this.seq) return [];
1949
+ if (since >= this.seq) return [];
1897
1950
  const out = [];
1898
- for (const line of journalTail(this.journalPath).lines) try {
1899
- const event = JSON.parse(line);
1900
- if (event.seq > since) out.push(event);
1901
- } catch {}
1902
- if (out.length && out[0].seq > since + 1 && since < this.dropped) out.unshift({
1903
- seq: since,
1904
- id: `events.gap:${since}:${out[0].seq}`,
1905
- type: "events.gap",
1906
- at: this.now(),
1907
- from: since + 1,
1908
- to: Math.min(this.dropped, out[0].seq - 1)
1909
- });
1951
+ let before = since;
1952
+ const gapTo = (next) => {
1953
+ if (next > before + 1 && before < this.dropped) out.push({
1954
+ seq: before,
1955
+ id: `events.gap:${before}:${next}`,
1956
+ type: "events.gap",
1957
+ at: this.now(),
1958
+ from: before + 1,
1959
+ to: Math.min(this.dropped, next - 1)
1960
+ });
1961
+ };
1962
+ if (existsSync(this.journalPath)) for (const line of journalTail(this.journalPath).lines) {
1963
+ let event;
1964
+ try {
1965
+ event = JSON.parse(line);
1966
+ } catch {
1967
+ continue;
1968
+ }
1969
+ if (event.seq <= before) continue;
1970
+ gapTo(event.seq);
1971
+ out.push(event);
1972
+ before = event.seq;
1973
+ }
1974
+ gapTo(Math.min(this.dropped, this.seq) + 1);
1910
1975
  return out;
1911
1976
  }
1912
1977
  /**
@@ -1916,9 +1981,12 @@ var EventHub = class {
1916
1981
  markDropped(seq) {
1917
1982
  this.dropped = seq;
1918
1983
  try {
1919
- writeFileSync(this.journalPath + ".dropped", String(seq), { mode: 384 });
1984
+ writeFileSync(this.journalPath + ".dropped.tmp", String(seq), { mode: 384 });
1985
+ renameSync(this.journalPath + ".dropped.tmp", this.journalPath + ".dropped");
1920
1986
  this.marked = true;
1987
+ this.markOwed = false;
1921
1988
  } catch (error) {
1989
+ this.markOwed = true;
1922
1990
  process.stderr.write(`ghostly: event journal error: ${error instanceof Error ? error.message : String(error)}\n`);
1923
1991
  }
1924
1992
  }
@@ -1934,20 +2002,24 @@ var EventHub = class {
1934
2002
  at: this.now(),
1935
2003
  ...fields
1936
2004
  };
2005
+ let written = false;
1937
2006
  try {
1938
- const line = JSON.stringify(event) + "\n";
1939
- appendFileSync(this.journalPath, line, { mode: 384 });
1940
- this.journalBytes += Buffer.byteLength(line);
2007
+ if (this.markOwed) this.markDropped(this.dropped);
2008
+ const line = Buffer.from(JSON.stringify(event) + "\n");
2009
+ appendWhole(this.journalPath, line);
2010
+ written = true;
2011
+ this.journalBytes += line.length;
1941
2012
  if (++this.journalLines > 2e4 || this.journalBytes > 33554432) this.trimJournal();
1942
2013
  } catch (error) {
1943
2014
  process.stderr.write(`ghostly: event journal error: ${error instanceof Error ? error.message : String(error)}\n`);
2015
+ if (!written) this.markDropped(Math.max(this.dropped, event.seq));
1944
2016
  }
1945
2017
  this.tell(event);
1946
2018
  return event;
1947
2019
  }
1948
2020
  /**
1949
2021
  * An event for the listeners only, never the journal: a contact's app frames, live only (WISP 1200), which at the
1950
- * 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
2022
+ * 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
1951
2023
  * event's (as an `agent.turn` takes its source's): a cursor that handled it resumes after that event, a replay never
1952
2024
  * gives it, and a restart never numbers an event again.
1953
2025
  */
@@ -1981,54 +2053,78 @@ var EventHub = class {
1981
2053
  this.journalBytes = bytes;
1982
2054
  }
1983
2055
  /**
1984
- * What was removed here leaves the journal too: the journal is written again without the events that name it (a
1985
- * line that names it and cannot be read goes as well), and a journal set aside as unreadable, which cannot be sorted,
1986
- * is deleted. `ids`: what was removed (a message's id, a chat's or a group's); `gone`: whether an event is of it;
1987
- * `unquote`: an event that stays, written again without what it quotes of the removed (a reply's event), else none.
2056
+ * What was removed here leaves the journal too: the events that name it are blanked, or the journal is written again
2057
+ * without them (a line that names it and cannot be read goes as well), and a journal set aside as unreadable, which
2058
+ * cannot be sorted, is deleted. `ids`: what was removed (a message's id, a chat's or a group's); `gone`: whether an
2059
+ * event is of it; `unquote`: an event that stays, written again without what it quotes of the removed (a reply's
2060
+ * event), else none.
1988
2061
  */
1989
2062
  forget(ids, gone, unquote = () => void 0) {
1990
2063
  if (!ids.length) return;
1991
2064
  try {
1992
2065
  rmSync(this.journalPath + ".unreadable", { force: true });
1993
2066
  if (!existsSync(this.journalPath)) return;
1994
- const { bytes, start } = journalWindow(this.journalPath);
2067
+ const { bytes, start, at } = journalWindow(this.journalPath);
1995
2068
  const needles = ids.map((id) => JSON.stringify(id)), few = ids.length <= FORGET_SEARCHED_IDS;
1996
2069
  const names = (line) => needles.some((needle) => line.includes(needle));
1997
- let from = few ? bytes.length : start;
1998
- if (few) for (const needle of needles) {
1999
- const at = bytes.indexOf(needle, start);
2000
- if (at !== -1 && at < from) from = at;
2001
- }
2002
- if (from === bytes.length) return;
2003
- from = Math.max(start, bytes.lastIndexOf(10, from) + 1);
2004
- const lines = bytes.toString("utf8", from).split("\n").filter(Boolean);
2005
- let changed = false;
2006
- const kept = lines.flatMap((line) => {
2007
- if (few && !names(line)) return [line];
2070
+ const edits = [];
2071
+ for (const [from, to] of few ? linesNaming(bytes, start, needles) : linesOf(bytes, start)) {
2072
+ const line = bytes.toString("utf8", from, to);
2008
2073
  let event;
2009
2074
  try {
2010
2075
  event = JSON.parse(line);
2011
2076
  } catch {
2012
- if (!few && !names(line)) return [line];
2013
- changed = true;
2014
- return [];
2077
+ if (few || names(line)) edits.push({
2078
+ from,
2079
+ to,
2080
+ line: null
2081
+ });
2082
+ continue;
2015
2083
  }
2016
2084
  if (gone(event)) {
2017
- changed = true;
2018
- return [];
2085
+ edits.push({
2086
+ from,
2087
+ to,
2088
+ line: null
2089
+ });
2090
+ continue;
2019
2091
  }
2020
2092
  const written = unquote(event);
2021
- if (!written) return [line];
2022
- changed = true;
2023
- return [JSON.stringify(written)];
2024
- });
2025
- if (!changed) return;
2093
+ if (written) edits.push({
2094
+ from,
2095
+ to,
2096
+ line: JSON.stringify(written)
2097
+ });
2098
+ }
2099
+ if (!edits.length) return;
2026
2100
  if (!this.marked) this.markDropped(this.dropped);
2027
- const tail = kept.length ? kept.join("\n") + "\n" : "";
2028
- writeFileSync(this.journalPath + ".tmp", Buffer.concat([bytes.subarray(start, from), Buffer.from(tail)]), { mode: 384 });
2101
+ if (few && edits.every(({ from, to, line }) => line === null || Buffer.byteLength(line) <= to - from)) {
2102
+ const fd = openSync(this.journalPath, "r+");
2103
+ try {
2104
+ for (const { from, to, line } of edits) {
2105
+ const over = Buffer.alloc(to - from, " ");
2106
+ if (line !== null) over.write(line);
2107
+ for (let done = 0; done < over.length;) done += writeSync(fd, over, done, over.length - done, at + from + done);
2108
+ }
2109
+ } finally {
2110
+ closeSync(fd);
2111
+ }
2112
+ return;
2113
+ }
2114
+ const parts = [];
2115
+ let from = start, removed = 0;
2116
+ for (const edit of edits) {
2117
+ parts.push(bytes.subarray(from, edit.from));
2118
+ if (edit.line === null) removed++;
2119
+ else parts.push(Buffer.from(edit.line));
2120
+ from = edit.line === null ? edit.to + 1 : edit.to;
2121
+ }
2122
+ parts.push(bytes.subarray(from));
2123
+ const written = Buffer.concat(parts);
2124
+ writeFileSync(this.journalPath + ".tmp", written, { mode: 384 });
2029
2125
  renameSync(this.journalPath + ".tmp", this.journalPath);
2030
- this.journalLines -= lines.length - kept.length;
2031
- this.journalBytes = from - start + Buffer.byteLength(tail);
2126
+ this.journalLines -= removed;
2127
+ this.journalBytes = written.length;
2032
2128
  } catch (error) {
2033
2129
  process.stderr.write(`ghostly: event journal error: ${error instanceof Error ? error.message : String(error)}\n`);
2034
2130
  }
@@ -2099,11 +2195,11 @@ var EventHub = class {
2099
2195
  name: shape.name
2100
2196
  });
2101
2197
  this.pinned("chat", id, before.pin, shape.pin);
2102
- if (shape.typing !== before.typing) this.emit(shape.typing ? "typing.started" : "typing.stopped", `typing.${shape.typing ? "started" : "stopped"}:${id}:${this.now()}`, {
2198
+ if (shape.typing !== before.typing) this.emitLive(shape.typing ? "typing.started" : "typing.stopped", `typing.${shape.typing ? "started" : "stopped"}:${id}:${this.now()}`, {
2103
2199
  chat: id,
2104
2200
  ...shape.typing ? typingFields(shape) : {}
2105
2201
  });
2106
- else if (shape.typing && (shape.typingKind !== before.typingKind || shape.typingStatus !== before.typingStatus)) this.emit("typing.started", `typing.started:${id}:${this.now()}:${this.seq + 1}`, {
2202
+ else if (shape.typing && (shape.typingKind !== before.typingKind || shape.typingStatus !== before.typingStatus)) this.emitLive("typing.started", `typing.started:${id}:${this.now()}:${++this.typingChanges}`, {
2107
2203
  chat: id,
2108
2204
  ...typingFields(shape)
2109
2205
  });
@@ -2142,13 +2238,13 @@ var EventHub = class {
2142
2238
  for (const [member, word] of Object.entries(shape.typing)) {
2143
2239
  const was = before.typing[member];
2144
2240
  if (was && was.kind === word.kind && was.status === word.status) continue;
2145
- this.emit("group.typing.started", `group.typing.started:${id}:${member}:${this.now()}${was ? `:${this.seq + 1}` : ""}`, {
2241
+ this.emitLive("group.typing.started", `group.typing.started:${id}:${member}:${this.now()}${was ? `:${++this.typingChanges}` : ""}`, {
2146
2242
  group: id,
2147
2243
  member,
2148
2244
  ...word
2149
2245
  });
2150
2246
  }
2151
- for (const member of Object.keys(before.typing)) if (!shape.typing[member]) this.emit("group.typing.stopped", `group.typing.stopped:${id}:${member}:${this.now()}`, {
2247
+ for (const member of Object.keys(before.typing)) if (!shape.typing[member]) this.emitLive("group.typing.stopped", `group.typing.stopped:${id}:${member}:${this.now()}`, {
2152
2248
  group: id,
2153
2249
  member
2154
2250
  });
@@ -2453,22 +2549,23 @@ var EventHub = class {
2453
2549
  }
2454
2550
  /**
2455
2551
  * A press on a button of a message of mine (WISP 406 · Message Buttons), after the reply's own event: the question
2456
- * (`messageId`), the button, its label, who pressed (`by`: the chat, or a group member's key), `name` (the chat's name
2457
- * here, as `chat list` gives it: its label, else the contact's own name; a group member's roster name) and the reply
2458
- * (`replyId`). `untrusted.name` is the name the person gave themselves, as an agent turn's: theirs to choose, so
2459
- * data, never instructions. The engine marks a reply a press only while the buttons were open for that person.
2552
+ * (`messageId`), the button, its label, who pressed (`by`: the chat, or a group member's key), `name` (the label this
2553
+ * profile gave the chat, as `chat list` gives it; null without one, and in a group) and the reply (`replyId`).
2554
+ * `untrusted.name` is the name the person gave themselves, as an agent turn's: theirs to choose, so data, never
2555
+ * instructions, and under `untrusted` only. The engine marks a reply a press only while the buttons were open for
2556
+ * that person.
2460
2557
  */
2461
2558
  pressed(chat, group, message, json) {
2462
2559
  const press = message.press;
2463
2560
  const link = group ? void 0 : this.state?.links.find((l) => l.id === chat);
2464
- const name = group ? json.nick : link ? chatJson(link).name : null;
2561
+ const name = link ? chatJson(link).label : null;
2465
2562
  this.emit("button.pressed", `button.pressed:${group ?? chat}:${message.id}`, {
2466
2563
  ...group ? { group } : { chat },
2467
2564
  messageId: press.messageId,
2468
2565
  button: press.button,
2469
2566
  label: press.label,
2470
2567
  by: group ? message.member ?? null : chat,
2471
- name: name ?? null,
2568
+ name,
2472
2569
  replyId: message.id,
2473
2570
  ...press.inferred ? { inferred: true } : {},
2474
2571
  untrusted: { name: json.nick ?? null }
@@ -2617,12 +2714,13 @@ function groupShape(group) {
2617
2714
  }
2618
2715
  /**
2619
2716
  * The journal's whole lines within its last `JOURNAL_MAX_BYTES`, and its size: never the whole file as one string, so
2620
- * a journal grown past what a string can hold (or a trim's bound) is still read, and in bounded time.
2717
+ * a journal grown past what a string can hold (or a trim's bound) is still read, and in bounded time. Lines `forget`
2718
+ * blanked are left out.
2621
2719
  */
2622
2720
  function journalTail(path) {
2623
2721
  const { bytes, start, size } = journalWindow(path);
2624
2722
  return {
2625
- lines: bytes.toString("utf8", start).split("\n").filter(Boolean),
2723
+ lines: bytes.toString("utf8", start).split("\n").filter((line) => line.trimStart()),
2626
2724
  size
2627
2725
  };
2628
2726
  }
@@ -2646,20 +2744,32 @@ function journalEnd(path) {
2646
2744
  if (stop > from) first = firstSeq([bytes.toString("utf8", from, stop)]);
2647
2745
  from = stop + 1;
2648
2746
  }
2649
- let seq = 0;
2747
+ let seq = 0, read = -1;
2650
2748
  for (let stop = bytes.length; stop > start;) {
2651
2749
  const from = Math.max(start, bytes.lastIndexOf(10, stop - 1) + 1);
2652
2750
  if (from < stop) try {
2653
2751
  seq = JSON.parse(bytes.toString("utf8", from, stop)).seq;
2752
+ read = from;
2654
2753
  break;
2655
2754
  } catch {}
2656
2755
  stop = from - 1;
2657
2756
  }
2757
+ let tail;
2758
+ if (bytes.length > start && bytes[bytes.length - 1] !== 10) {
2759
+ const from = Math.max(start, bytes.lastIndexOf(10) + 1);
2760
+ const named = /^\{"seq":(\d+)[,}]/.exec(bytes.toString("latin1", from, Math.min(bytes.length, from + 32)))?.[1];
2761
+ tail = {
2762
+ at: size - bytes.length + from,
2763
+ whole: read === from,
2764
+ seq: named === void 0 ? void 0 : Number(named)
2765
+ };
2766
+ }
2658
2767
  return {
2659
2768
  seq,
2660
2769
  first,
2661
2770
  lines,
2662
- size
2771
+ size,
2772
+ tail
2663
2773
  };
2664
2774
  }
2665
2775
  /** The seq of the first of these lines that can be read. */
@@ -2678,7 +2788,49 @@ function readDropped(path) {
2678
2788
  return;
2679
2789
  }
2680
2790
  }
2681
- /** The bytes of the journal's last `JOURNAL_MAX_BYTES`, `start` where its first whole line begins in them, and its size. */
2791
+ /**
2792
+ * 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
2793
+ * next line, once there is room, starts a line of its own instead of making one no reader can parse with it.
2794
+ */
2795
+ function appendWhole(path, line) {
2796
+ const fd = openSync(path, "a", 384);
2797
+ let whole = -1;
2798
+ try {
2799
+ whole = fstatSync(fd).size;
2800
+ for (let at = 0; at < line.length;) at += writeSync(fd, line, at);
2801
+ } catch (error) {
2802
+ if (whole >= 0) try {
2803
+ ftruncateSync(fd, whole);
2804
+ } catch {}
2805
+ throw error;
2806
+ } finally {
2807
+ closeSync(fd);
2808
+ }
2809
+ }
2810
+ /** The bounds in `bytes` of each line from `start` on, its newline left out. */
2811
+ function linesOf(bytes, start) {
2812
+ const lines = [];
2813
+ for (let from = start; from < bytes.length;) {
2814
+ const end = bytes.indexOf(10, from), to = end === -1 ? bytes.length : end;
2815
+ if (to > from) lines.push([from, to]);
2816
+ from = to + 1;
2817
+ }
2818
+ return lines;
2819
+ }
2820
+ /** The bounds in `bytes` of each line from `start` on that holds one of the needles, in their order, found in the bytes. */
2821
+ function linesNaming(bytes, start, needles) {
2822
+ const lines = /* @__PURE__ */ new Map();
2823
+ for (const needle of needles) for (let at = bytes.indexOf(needle, start); at !== -1;) {
2824
+ const from = Math.max(start, bytes.lastIndexOf(10, at) + 1), end = bytes.indexOf(10, at), to = end === -1 ? bytes.length : end;
2825
+ lines.set(from, to);
2826
+ at = end === -1 ? -1 : bytes.indexOf(needle, end + 1);
2827
+ }
2828
+ return [...lines].sort(([a], [b]) => a - b);
2829
+ }
2830
+ /**
2831
+ * The bytes of the journal's last `JOURNAL_MAX_BYTES`, `start` where its first whole line begins in them, `at` where
2832
+ * they begin in the file, and its size.
2833
+ */
2682
2834
  function journalWindow(path) {
2683
2835
  const fd = openSync(path, "r");
2684
2836
  try {
@@ -2695,6 +2847,7 @@ function journalWindow(path) {
2695
2847
  return {
2696
2848
  bytes,
2697
2849
  start: from > 0 ? bytes.indexOf(10) + 1 || bytes.length : 0,
2850
+ at: from,
2698
2851
  size
2699
2852
  };
2700
2853
  } finally {
@@ -4885,8 +5038,8 @@ function mainlineNetwork(env = process.env) {
4885
5038
  }
4886
5039
  /**
4887
5040
  * WebRTC for the engine (WISP 101): libdatachannel through node-datachannel's W3C polyfill. Chats go live over it with
4888
- * browsers directly, and groups need it (their links use WebRTC alone). A native module: without it, or with
4889
- * `GHOSTLY_WEBRTC=0`, the CLI runs without WebRTC and says so.
5041
+ * browsers directly, and calls need it. A native module: without it, or with `GHOSTLY_WEBRTC=0`, the CLI runs without
5042
+ * WebRTC and says so; its groups' links go over Iroh or HyperDHT (WISP 902 § Transports).
4890
5043
  */
4891
5044
  async function installWebRtc() {
4892
5045
  if (!envSwitch("GHOSTLY_WEBRTC", true)) return false;
@@ -4993,7 +5146,7 @@ async function startRuntime(paths, options = {}) {
4993
5146
  const restored = join(paths.dir, RESTORED_MARK);
4994
5147
  if (existsSync(restored)) {
4995
5148
  try {
4996
- const rows = await import("./restoredRows-CRYwIx3g.js");
5149
+ const rows = await import("./restoredRows-YhlbokEE.js");
4997
5150
  await rows.markRestoredWallet();
4998
5151
  await rows.markLeftOutFiles(leftOutIn(restored));
4999
5152
  await rows.forgetRatchets();
@@ -5016,12 +5169,12 @@ async function startRuntime(paths, options = {}) {
5016
5169
  const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-DMzrIdCu.js"), import("./fileBytes-Douk1yOp.js")]);
5017
5170
  registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
5018
5171
  if (await (await import("./blobFiles-BnjN_Vrz.js")).moveBlobFiles()) await store.compact();
5019
- const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-BZnsm5X5.js"), import("./endpoint-DWHkXWVM.js")]);
5020
- const mainline = dht.off ? null : new (await (import("./mainline-DOwZDHVy.js"))).Mainline({
5172
+ const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-DcOsgYDU.js"), import("./endpoint-DWHkXWVM.js")]);
5173
+ const mainline = dht.off ? null : new (await (import("./mainline-HPlVrl8R.js"))).Mainline({
5021
5174
  bootstrap: dht.bootstrap,
5022
5175
  host: dht.host
5023
5176
  });
5024
- const transport = mainline || pinned ? new (await (import("./mainline-DOwZDHVy.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
5177
+ const transport = mainline || pinned ? new (await (import("./mainline-HPlVrl8R.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
5025
5178
  const apps = servedApps(paths.dir).length > 0;
5026
5179
  const server = new EngineServer({
5027
5180
  ...transport ? { transport } : {},
@@ -5034,6 +5187,7 @@ async function startRuntime(paths, options = {}) {
5034
5187
  servicesSupport: true,
5035
5188
  apps: apps ? "wire" : false,
5036
5189
  staysOnline: envSwitch("GHOSTLY_HUB", true),
5190
+ watchPeerIdleMs: DAEMON_WATCH_PEER_IDLE_MS,
5037
5191
  localFetch: nodeLocalFetch,
5038
5192
  pushSend: (request) => nodePushSend(request),
5039
5193
  holdFetch: nodeHoldFetch(),
@@ -5380,4 +5534,4 @@ function connection(ctx, socket, secret) {
5380
5534
  //#endregion
5381
5535
  export { BASELINE_NEWEST, MAX_UNREAD, keepServing, openHost, serve };
5382
5536
 
5383
- //# sourceMappingURL=host-DvcVt5YI.js.map
5537
+ //# sourceMappingURL=host-G5seUwaI.js.map