@ghostlytools/cli 1.11.2 → 1.11.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 (83) hide show
  1. package/README.md +11 -10
  2. package/dist/assets/{api-BM3PsXbB.js → api-DBlaoz8i.js} +129 -37
  3. package/dist/assets/api-DBlaoz8i.js.map +1 -0
  4. package/dist/assets/{api-CtXgscmK.js → api-DgU4MZPD.js} +2 -2
  5. package/dist/assets/{apiKit-lCTQ0EBG.js → apiKit-DesObIDf.js} +4 -4
  6. package/dist/assets/{apiKit-lCTQ0EBG.js.map → apiKit-DesObIDf.js.map} +1 -1
  7. package/dist/assets/{appFetch-BKHy5H8J.js → appFetch-C8yZIq1e.js} +3 -3
  8. package/dist/assets/{appFetch-BKHy5H8J.js.map → appFetch-C8yZIq1e.js.map} +1 -1
  9. package/dist/assets/{apps-Do26w3c7.js → apps-DkMjDHML.js} +104 -33
  10. package/dist/assets/apps-DkMjDHML.js.map +1 -0
  11. package/dist/assets/{apps-DO_gAZgm.js → apps-rzxsjfBV.js} +1 -1
  12. package/dist/assets/{arkade-CZrLbz-M.js → arkade-CarKONmH.js} +2 -2
  13. package/dist/assets/{arkade-CZrLbz-M.js.map → arkade-CarKONmH.js.map} +1 -1
  14. package/dist/assets/{backup-j47AzDvG.js → backup-C0OJCJlM.js} +17 -25
  15. package/dist/assets/backup-C0OJCJlM.js.map +1 -0
  16. package/dist/assets/{backup-D21x1f5P.js → backup-CgWU7x0T.js} +1 -1
  17. package/dist/assets/buttons-Cco0Agfa.js +2 -0
  18. package/dist/assets/{buttons-CiGlBVBT.js → buttons-fZTEa_2i.js} +34 -5
  19. package/dist/assets/buttons-fZTEa_2i.js.map +1 -0
  20. package/dist/assets/{client-raIncVtF.js → client-Ibk3-e60.js} +2 -2
  21. package/dist/assets/{client-raIncVtF.js.map → client-Ibk3-e60.js.map} +1 -1
  22. package/dist/assets/{codec-DcG2AeyE.js → codec-DMpQqVSt.js} +2 -2
  23. package/dist/assets/{codec-DcG2AeyE.js.map → codec-DMpQqVSt.js.map} +1 -1
  24. package/dist/assets/{envelope-Dud6lntA.js → envelope-CvQVCGdf.js} +2 -2
  25. package/dist/assets/{envelope-Dud6lntA.js.map → envelope-CvQVCGdf.js.map} +1 -1
  26. package/dist/assets/{fedimintSdk-DRKRSw14.js → fedimintSdk-zV_5Qdqz.js} +2 -2
  27. package/dist/assets/{fedimintSdk-DRKRSw14.js.map → fedimintSdk-zV_5Qdqz.js.map} +1 -1
  28. package/dist/assets/{fixedHosts-CNX7QiUD.js → fixedHosts-6gKn8dp2.js} +3 -3
  29. package/dist/assets/{fixedHosts-CNX7QiUD.js.map → fixedHosts-6gKn8dp2.js.map} +1 -1
  30. package/dist/assets/{host-8RskzQgB.js → host-CYlIiY3r.js} +161 -32
  31. package/dist/assets/host-CYlIiY3r.js.map +1 -0
  32. package/dist/assets/{hyperdhtRelay-uAThbFub.js → hyperdhtRelay-CdsLcAhY.js} +2 -2
  33. package/dist/assets/{hyperdhtRelay-uAThbFub.js.map → hyperdhtRelay-CdsLcAhY.js.map} +1 -1
  34. package/dist/assets/{irohWeb-DGelfgDJ.js → irohWeb-D2IuloLL.js} +19 -12
  35. package/dist/assets/irohWeb-D2IuloLL.js.map +1 -0
  36. package/dist/assets/{main-BC33ooYg.js → main-C0PfjKTe.js} +109 -42
  37. package/dist/assets/main-C0PfjKTe.js.map +1 -0
  38. package/dist/assets/{mainline-DYrjsS1t.js → mainline-Cu61qcPS.js} +35 -18
  39. package/dist/assets/mainline-Cu61qcPS.js.map +1 -0
  40. package/dist/assets/{networkReason-n2oBs4by.js → networkReason-Dt7Yx_n4.js} +3 -3
  41. package/dist/assets/{networkReason-n2oBs4by.js.map → networkReason-Dt7Yx_n4.js.map} +1 -1
  42. package/dist/assets/{nwc-Do3VSlIS.js → nwc-CtZypDcv.js} +3 -3
  43. package/dist/assets/{nwc-Do3VSlIS.js.map → nwc-CtZypDcv.js.map} +1 -1
  44. package/dist/assets/{nwcProvider-Du5aWNIn.js → nwcProvider-DYHkd0iu.js} +2 -2
  45. package/dist/assets/{nwcProvider-Du5aWNIn.js.map → nwcProvider-DYHkd0iu.js.map} +1 -1
  46. package/dist/assets/{ownDid-CwwYu8s2.js → ownDid-CJ0ta8CL.js} +2 -2
  47. package/dist/assets/{ownDid-CwwYu8s2.js.map → ownDid-CJ0ta8CL.js.map} +1 -1
  48. package/dist/assets/{ownStatus-D7dB4zJB.js → ownStatus-D4HC6tNR.js} +11 -6
  49. package/dist/assets/{ownStatus-D7dB4zJB.js.map → ownStatus-D4HC6tNR.js.map} +1 -1
  50. package/dist/assets/{profiles-NyF5FnYF.js → profiles-Ccdq6Xf6.js} +3 -3
  51. package/dist/assets/{profiles-NyF5FnYF.js.map → profiles-Ccdq6Xf6.js.map} +1 -1
  52. package/dist/assets/{registry-C734VrO9.js → registry-CE0PpQAE.js} +1 -1
  53. package/dist/assets/{registry-DKDInr0A.js → registry-LvxsLJ5S.js} +18 -7
  54. package/dist/assets/registry-LvxsLJ5S.js.map +1 -0
  55. package/dist/assets/{resolve-3Tqh9AWQ.js → resolve-6kVu2DE5.js} +2 -2
  56. package/dist/assets/{resolve-3Tqh9AWQ.js.map → resolve-6kVu2DE5.js.map} +1 -1
  57. package/dist/assets/{server-B6PQ6iae.js → server-Q3VcNqGt.js} +245 -97
  58. package/dist/assets/server-Q3VcNqGt.js.map +1 -0
  59. package/dist/assets/{src-ChJijTlM.js → src-DjVj2ynY.js} +188 -42
  60. package/dist/assets/src-DjVj2ynY.js.map +1 -0
  61. package/dist/assets/{sshForges-Brf0fslM.js → sshForges-DeZ9cN9Q.js} +4 -3
  62. package/dist/assets/sshForges-DeZ9cN9Q.js.map +1 -0
  63. package/dist/assets/{translate-xLme9Rdh.js → translate-iQZq4TnY.js} +35 -14
  64. package/dist/assets/translate-iQZq4TnY.js.map +1 -0
  65. package/dist/assets/{usdt-CSU5KzTV.js → usdt-DnyTGdTX.js} +3 -3
  66. package/dist/assets/{usdt-CSU5KzTV.js.map → usdt-DnyTGdTX.js.map} +1 -1
  67. package/dist/ghostly.mjs +1 -1
  68. package/npm-shrinkwrap.json +2 -2
  69. package/package.json +1 -1
  70. package/dist/assets/api-BM3PsXbB.js.map +0 -1
  71. package/dist/assets/apps-Do26w3c7.js.map +0 -1
  72. package/dist/assets/backup-j47AzDvG.js.map +0 -1
  73. package/dist/assets/buttons-CiGlBVBT.js.map +0 -1
  74. package/dist/assets/buttons-D2l2bVCG.js +0 -2
  75. package/dist/assets/host-8RskzQgB.js.map +0 -1
  76. package/dist/assets/irohWeb-DGelfgDJ.js.map +0 -1
  77. package/dist/assets/main-BC33ooYg.js.map +0 -1
  78. package/dist/assets/mainline-DYrjsS1t.js.map +0 -1
  79. package/dist/assets/registry-DKDInr0A.js.map +0 -1
  80. package/dist/assets/server-B6PQ6iae.js.map +0 -1
  81. package/dist/assets/src-ChJijTlM.js.map +0 -1
  82. package/dist/assets/sshForges-Brf0fslM.js.map +0 -1
  83. package/dist/assets/translate-xLme9Rdh.js.map +0 -1
@@ -1,12 +1,13 @@
1
- import { As as callSignalHeardAt, Ds as answersOffer, Es as RTC_CONFIG, Ma as ACTIVE_DHT_POLL_MS, Ms as extractParamsFromSdp, Ns as parseCallSignal, Os as buildSdpFromSignal, Ps as signalHasVideo, Qr as STATUS_IDLE_AFTER_MS, _d as fromBase64Url, ks as callRtcConfig, ls as DAEMON_WATCH_PEER_IDLE_MS, qu as setLinkTraceSink, wa as isPublicAddress, wi as checkPushEndpoint, ws as CALL_SIGNAL_MAX_AGE_MS } from "./src-ChJijTlM.js";
1
+ import { $r as STATUS_IDLE_AFTER_MS, As as buildSdpFromSignal, Es as CALL_SIGNAL_MAX_AGE_MS, Fs as parseCallSignal, Is as signalHasVideo, Ms as callSignalHeardAt, Na as ACTIVE_DHT_POLL_MS, Os as RTC_CONFIG, Ps as extractParamsFromSdp, Ta as isPublicAddress, Ti as checkPushEndpoint, Yu as setLinkTraceSink, bd as fromBase64Url, dd as setPublicKeyFastPath, ds as DAEMON_WATCH_PEER_IDLE_MS, js as callRtcConfig, ks as answersOffer } from "./src-DjVj2ynY.js";
2
2
  import { p as fileStore } from "./idb-CEuoNsTv.js";
3
- import { r as irohRelayProblem } from "./irohWeb-DGelfgDJ.js";
4
- import { n as fedimintSdkOn } from "./fedimintSdk-DRKRSw14.js";
3
+ import { r as irohRelayProblem } from "./irohWeb-D2IuloLL.js";
4
+ import { n as fedimintSdkOn } from "./fedimintSdk-zV_5Qdqz.js";
5
5
  import { r as asCliError, t as CliError } from "./errors-Dt-ZnyOX.js";
6
- import { A as sinceSeq, s as findChat, u as findOwnNamedChat } from "./apiKit-lCTQ0EBG.js";
7
- import { _ as groupPayTwins, d as servedApps, f as nodeLocalFetch, g as groupMessageJson, h as groupJson, l as paymentJson, m as chatMessageJson, p as chatJson, r as callApi, u as reportAppFrames, v as resumeHolds, y as flushCardUpdates } from "./api-BM3PsXbB.js";
8
- import { C as ownProfile, E as runtimePath, S as ownFolder, T as privateFolder, b as startingPath, n as RESTORED_MARK, r as acquireLock } from "./profiles-NyF5FnYF.js";
9
- import { _ as frameSamples, c as greeting, d as removeDaemonSecret, g as frameBytes, h as bytesToMs, l as newDaemonSecret, m as PlaybackQueue, p as DEFAULT_RATE, u as proof, v as isCallRate, y as monotonic } from "./client-raIncVtF.js";
6
+ import { A as sinceSeq, s as findChat, u as findOwnNamedChat } from "./apiKit-DesObIDf.js";
7
+ import { _ as groupPayTwins, d as servedApps, f as nodeLocalFetch, g as groupMessageJson, h as groupJson, l as paymentJson, m as chatMessageJson, p as chatJson, r as callApi, u as reportAppFrames, v as resumeHolds, y as flushCardUpdates } from "./api-DBlaoz8i.js";
8
+ import { C as ownProfile, E as runtimePath, S as ownFolder, T as privateFolder, b as startingPath, n as RESTORED_MARK, r as acquireLock } from "./profiles-Ccdq6Xf6.js";
9
+ import { p as nativePublicKey } from "./apps-DkMjDHML.js";
10
+ import { _ as frameSamples, c as greeting, d as removeDaemonSecret, g as frameBytes, h as bytesToMs, l as newDaemonSecret, m as PlaybackQueue, p as DEFAULT_RATE, u as proof, v as isCallRate, y as monotonic } from "./client-Ibk3-e60.js";
10
11
  import { createRequire } from "node:module";
11
12
  import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, fsync, fsyncSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, truncateSync, writeFileSync, writeSync } from "node:fs";
12
13
  import { open, readFile } from "node:fs/promises";
@@ -155,7 +156,10 @@ var AudioSocket = class AudioSocket {
155
156
  this.unproven.delete(socket);
156
157
  const before = this.client;
157
158
  this.client = socket;
158
- before?.end();
159
+ if (before) {
160
+ before.end();
161
+ setTimeout(() => before.destroy(), 2e3).unref();
162
+ }
159
163
  handlers.onClient?.(true);
160
164
  };
161
165
  let timer = null;
@@ -1351,7 +1355,7 @@ var CallManager = class {
1351
1355
  v: 0
1352
1356
  });
1353
1357
  } catch (error) {
1354
- await this.end(call, "failed", true, false);
1358
+ await this.end(call, "failed", true);
1355
1359
  throw error;
1356
1360
  } finally {
1357
1361
  early?.close();
@@ -1823,6 +1827,13 @@ var DaemonPresence = class {
1823
1827
  this.timer = setInterval(() => this.node.setPresence({ presence: "active" }), PRESENCE_EVERY_MS);
1824
1828
  this.timer.unref?.();
1825
1829
  }
1830
+ /**
1831
+ * Whether the engine's online notices go (WISP 401 § Online notices, `NodeOptions.onlineNotices`): only while presence
1832
+ * is said. Off, a contact's closed app was pushed "<bot> is online" 30 s after each start, while the bot showed no dot.
1833
+ */
1834
+ saysOnline() {
1835
+ return this.timer !== void 0;
1836
+ }
1826
1837
  stop() {
1827
1838
  clearInterval(this.timer);
1828
1839
  this.timer = void 0;
@@ -1909,7 +1920,7 @@ var EventHub = class {
1909
1920
  /** `file.*` events whose message was not seen yet: they wait for it a moment (the engine stores it right after). */
1910
1921
  pendingFiles = /* @__PURE__ */ new Map();
1911
1922
  baselined = false;
1912
- /** Chats and groups whose history the baseline did not read whole, and how to read it: until a file event needs it. */
1923
+ /** Chats and groups whose history the baseline did not read whole, and how to read their file rows: until a file event needs them. */
1913
1924
  unread = /* @__PURE__ */ new Map();
1914
1925
  /**
1915
1926
  * Whether the seen set notes mentions (`+m`): false on a set written before it did, whose mentions were reported with
@@ -2011,7 +2022,7 @@ var EventHub = class {
2011
2022
  for (const [chat, messages] of histories) this.messages(chat, messages);
2012
2023
  for (const [chat, messages] of rest?.newest ?? []) {
2013
2024
  this.messages(chat, messages, []);
2014
- this.unread.set(chat, rest.whole);
2025
+ this.unread.set(chat, rest.files);
2015
2026
  }
2016
2027
  this.baselined = true;
2017
2028
  this.firstRun = false;
@@ -2117,7 +2128,7 @@ var EventHub = class {
2117
2128
  to: Math.min(this.dropped, next - 1)
2118
2129
  });
2119
2130
  };
2120
- if (existsSync(this.journalPath)) for (const line of journalTail(this.journalPath).lines) {
2131
+ if (existsSync(this.journalPath)) for (const line of journalAfter(this.journalPath, since)) {
2121
2132
  let event;
2122
2133
  try {
2123
2134
  event = JSON.parse(line);
@@ -2403,7 +2414,7 @@ var EventHub = class {
2403
2414
  this.chats.set(id, shape);
2404
2415
  if (quiet) continue;
2405
2416
  if (!before) {
2406
- this.emit("chat.created", `chat.created:${id}`, {
2417
+ this.emit("chat.created", `chat.created:${id}:${this.now()}`, {
2407
2418
  chat: id,
2408
2419
  summary: {
2409
2420
  ...chatJson(link),
@@ -2448,7 +2459,7 @@ var EventHub = class {
2448
2459
  const removedChats = [...this.chats.keys()].filter((id) => !links.has(id));
2449
2460
  for (const id of removedChats) {
2450
2461
  this.chats.delete(id);
2451
- if (!quiet) this.emit("chat.removed", `chat.removed:${id}`, { chat: id });
2462
+ if (!quiet) this.emit("chat.removed", `chat.removed:${id}:${this.now()}`, { chat: id });
2452
2463
  }
2453
2464
  const chatsGone = new Set(removedChats);
2454
2465
  this.forget(removedChats, (event) => chatsGone.has(event.chat) && event.type !== "chat.removed");
@@ -2458,7 +2469,7 @@ var EventHub = class {
2458
2469
  this.groups.set(id, shape);
2459
2470
  if (quiet) continue;
2460
2471
  if (!before) {
2461
- this.emit("group.created", `group.created:${id}`, {
2472
+ this.emit("group.created", `group.created:${id}:${this.now()}`, {
2462
2473
  group: id,
2463
2474
  summary: groupJson(group)
2464
2475
  });
@@ -2493,7 +2504,7 @@ var EventHub = class {
2493
2504
  const removedGroups = [...this.groups.keys()].filter((id) => !groups.has(id));
2494
2505
  for (const id of removedGroups) {
2495
2506
  this.groups.delete(id);
2496
- if (!quiet) this.emit("group.removed", `group.removed:${id}`, { group: id });
2507
+ if (!quiet) this.emit("group.removed", `group.removed:${id}:${this.now()}`, { group: id });
2497
2508
  }
2498
2509
  const groupsGone = new Set(removedGroups);
2499
2510
  this.forget(removedGroups, (event) => groupsGone.has(event.group) && event.type !== "group.removed");
@@ -2752,7 +2763,14 @@ var EventHub = class {
2752
2763
  }
2753
2764
  continue;
2754
2765
  }
2755
- const noted = noteOf(state, at);
2766
+ const [delivery] = splitState(state), [was] = before === void 0 ? [void 0] : splitState(before);
2767
+ const passed = passesIn(note, was), moved = !group && message.sender === "me" && was !== void 0 && delivery !== was;
2768
+ const again = moved && (passed.been & deliveryBit(delivery)) !== 0;
2769
+ const passes = moved ? {
2770
+ count: passed.count + 1,
2771
+ been: passed.been | deliveryBit(delivery)
2772
+ } : passed;
2773
+ const noted = noteOf(state, at, passes);
2756
2774
  known.set(message.id, noted);
2757
2775
  changes.push([message.id, noted]);
2758
2776
  if (quiet) continue;
@@ -2791,14 +2809,14 @@ var EventHub = class {
2791
2809
  message: json()
2792
2810
  });
2793
2811
  } else {
2794
- const [delivery, edits] = splitState(state), [was, edited] = splitState(before);
2812
+ const [, edits] = splitState(state), [, edited] = splitState(before);
2795
2813
  if (edits > edited && !(message.sender === "me" && message.edit?.restore)) this.emit("message.edited", `message.edited:${chat}:${message.id}:${edits}`, {
2796
2814
  chat,
2797
2815
  messageId: message.id,
2798
2816
  edits,
2799
2817
  message: json()
2800
2818
  });
2801
- if (message.sender === "me" && delivery !== was) this.emit("message.delivery", `message.delivery:${chat}:${message.id}:${delivery}`, {
2819
+ if (moved) this.emit("message.delivery", `message.delivery:${chat}:${message.id}:${delivery}${again ? `:${passes.count}` : ""}`, {
2802
2820
  chat,
2803
2821
  messageId: message.id,
2804
2822
  delivery,
@@ -2935,9 +2953,35 @@ var AGES_NOTED = "ages";
2935
2953
  var UNDERWAY = "files:";
2936
2954
  /**
2937
2955
  * A note: what the seen set keeps of a message (or a reaction's number), then `@` and the time of its last activity in
2938
- * base 36 (`received+p#e2@mg3k1x2a`), by which `sweep` drops it. A note from before has no time.
2956
+ * base 36 (`received+p#e2@mg3k1x2a`), by which `sweep` drops it. A note from before has no time. A message of mine whose
2957
+ * delivery changed ends with its passes (`sent@mg3k1x2a!4.b`): `!`, how many changes, `.` and the deliveries it was in.
2939
2958
  */
2940
- var noteOf = (state, at) => `${state}@${Math.max(0, Math.floor(at)).toString(36)}`;
2959
+ var noteOf = (state, at, passes) => `${state}@${Math.max(0, Math.floor(at)).toString(36)}${passes?.count ? `!${passes.count}.${passes.been.toString(36)}` : ""}`;
2960
+ var DELIVERIES = [
2961
+ "sending",
2962
+ "sent",
2963
+ "queued",
2964
+ "waiting",
2965
+ "held",
2966
+ "delivered",
2967
+ "failed"
2968
+ ];
2969
+ var deliveryBit = (delivery) => {
2970
+ const at = DELIVERIES.indexOf(delivery);
2971
+ return 1 << (at === -1 ? DELIVERIES.length : at);
2972
+ };
2973
+ function passesIn(note, delivery) {
2974
+ const mark = note?.lastIndexOf("!") ?? -1;
2975
+ if (mark === -1) return {
2976
+ count: 0,
2977
+ been: delivery === void 0 ? 0 : deliveryBit(delivery)
2978
+ };
2979
+ const [count, been] = note.slice(mark + 1).split(".");
2980
+ return {
2981
+ count: Number(count) || 0,
2982
+ been: parseInt(been ?? "", 36) || 0
2983
+ };
2984
+ }
2941
2985
  function stateIn(note) {
2942
2986
  const at = note.lastIndexOf("@");
2943
2987
  return at === -1 ? note : note.slice(0, at);
@@ -3032,6 +3076,63 @@ function journalTail(path) {
3032
3076
  size
3033
3077
  };
3034
3078
  }
3079
+ /** What `journalAfter` reads first from the journal's end; each read further back is twice the last. */
3080
+ var REPLAY_CHUNK = 65536;
3081
+ /** The bytes of a line's start that hold its seq (`seqAt`), and how they begin. */
3082
+ var SEQ_PREFIX = 32;
3083
+ var SEQ_START = Buffer.from("{\"seq\":");
3084
+ /**
3085
+ * The journal's lines after `since`, within its last `JOURNAL_MAX_BYTES`, as `journalTail` gives them: its end is read
3086
+ * back in growing chunks, each line's seq taken from its `{"seq":N` start (as each event is written), until a line at or
3087
+ * before `since`; only what follows it is made into text. A line with no seq there (blanked by `forget`, torn) is passed
3088
+ * over and given, as `journalTail` gives it.
3089
+ */
3090
+ function journalAfter(path, since) {
3091
+ const fd = openSync(path, "r");
3092
+ const read = (from, to) => {
3093
+ const bytes = Buffer.alloc(to - from);
3094
+ let done = 0;
3095
+ while (done < bytes.length) {
3096
+ const n = readSync(fd, bytes, done, bytes.length - done, from + done);
3097
+ if (!n) break;
3098
+ done += n;
3099
+ }
3100
+ return bytes.subarray(0, done);
3101
+ };
3102
+ try {
3103
+ const size = fstatSync(fd).size;
3104
+ const cut = Math.max(0, size - JOURNAL_MAX_BYTES - 1);
3105
+ if (cut === 0 && (seqAt(read(0, Math.min(size, SEQ_PREFIX)), 0) ?? -1) > since) return journalTail(path).lines;
3106
+ let after = size, found = false, from = size, chunk = REPLAY_CHUNK;
3107
+ const chunks = [];
3108
+ while (from > cut && !found) {
3109
+ const next = Math.max(cut, from - chunk), bytes = read(next, Math.min(size, from + SEQ_PREFIX));
3110
+ chunks.unshift(bytes.subarray(0, Math.min(bytes.length, from - next)));
3111
+ for (let newline = bytes.lastIndexOf(10, from - next - 1); newline !== -1; newline = newline > 0 ? bytes.lastIndexOf(10, newline - 1) : -1) {
3112
+ const seq = seqAt(bytes, newline + 1);
3113
+ if (seq !== void 0 && seq <= since) {
3114
+ found = true;
3115
+ break;
3116
+ }
3117
+ after = next + newline + 1;
3118
+ }
3119
+ if (!found && next === 0 && (seqAt(bytes, 0) ?? Infinity) > since) after = 0;
3120
+ from = next;
3121
+ chunk *= 2;
3122
+ }
3123
+ return (chunks.length === 1 ? chunks[0] : Buffer.concat(chunks)).toString("utf8", after - from).split("\n").filter((line) => line.trimStart());
3124
+ } finally {
3125
+ closeSync(fd);
3126
+ }
3127
+ }
3128
+ /** The seq a journal line begins with (`{"seq":N,` or `{"seq":N}`), read from its first bytes, never made into text. */
3129
+ function seqAt(bytes, at) {
3130
+ for (let i = 0; i < SEQ_START.length; i++) if (bytes[at + i] !== SEQ_START[i]) return void 0;
3131
+ let seq = 0, i = at + SEQ_START.length;
3132
+ const end = Math.min(bytes.length, at + SEQ_PREFIX);
3133
+ for (; i < end && bytes[i] >= 48 && bytes[i] <= 57; i++) seq = seq * 10 + bytes[i] - 48;
3134
+ return i > at + SEQ_START.length && (bytes[i] === 44 || bytes[i] === 125) ? seq : void 0;
3135
+ }
3035
3136
  /**
3036
3137
  * What opening needs of the journal: its last seq, its number of lines (as `journalTail` counts them) and its size. The
3037
3138
  * lines are counted by their bytes and only the last whole one is made into text.
@@ -3065,11 +3166,10 @@ function journalEnd(path) {
3065
3166
  let tail;
3066
3167
  if (bytes.length > start && bytes[bytes.length - 1] !== 10) {
3067
3168
  const from = Math.max(start, bytes.lastIndexOf(10) + 1);
3068
- const named = /^\{"seq":(\d+)[,}]/.exec(bytes.toString("latin1", from, Math.min(bytes.length, from + 32)))?.[1];
3069
3169
  tail = {
3070
3170
  at: size - bytes.length + from,
3071
3171
  whole: read === from,
3072
- seq: named === void 0 ? void 0 : Number(named)
3172
+ seq: seqAt(bytes, from)
3073
3173
  };
3074
3174
  }
3075
3175
  return {
@@ -4363,6 +4463,13 @@ var CLOSE_WAIT_MS = 5e3;
4363
4463
  var EXPORT_PAGE = 256;
4364
4464
  /** How long a relaxed transaction's entry may wait for a sync when no other transaction brings one. */
4365
4465
  var RELAXED_SYNC_MS = 1e3;
4466
+ /**
4467
+ * How long the trees' layers wait for the ones after them before they go to SQLite, all in one SQLite transaction. One
4468
+ * per journal entry (a message's send, each of its delivery steps, its read) rewrote the pages each touched: ~80 KB of
4469
+ * rows.db's WAL per message, and a checkpoint on the daemon's thread (30-150 ms) every ~50 messages. The journal holds
4470
+ * them meanwhile, and reads find them in their layers.
4471
+ */
4472
+ var APPLY_MS = 250;
4366
4473
  var BLOB = "__ghostlyBlob";
4367
4474
  var RANGE = "__ghostlyRange";
4368
4475
  var PROBE = "__ghostly_storage_probe__";
@@ -4404,6 +4511,9 @@ async function openPersistentIndexedDb(dir, options = {}) {
4404
4511
  let unsynced = [];
4405
4512
  /** The syncs running off the thread, one after another, until no `complete` waits for one. */
4406
4513
  let syncing = null;
4514
+ /** The last journal entry whose layers wait for `applying` to take them to SQLite. */
4515
+ let applyUpTo = 0;
4516
+ let applying = null;
4407
4517
  /** The journal holds a chat's ratchet state, and with the next one it holds a key already used. */
4408
4518
  let holdsRatchet = false;
4409
4519
  /** The journal holds a delete of a chat or a message (or a settings write), and what came before it with it. */
@@ -4639,13 +4749,23 @@ async function openPersistentIndexedDb(dir, options = {}) {
4639
4749
  return transaction.dispatchEvent(abort);
4640
4750
  }
4641
4751
  /**
4642
- * The journal has entry `entry`: the trees' layers up to it go to SQLite. One that fails stays in memory, where reads
4643
- * find it, and goes with the next entry, or before the next snapshot (which fails without it).
4752
+ * The journal has entry `entry`: the trees' layers up to it go to SQLite within `APPLY_MS`, with the entries written
4753
+ * meanwhile. One that fails stays in memory, where reads find it, and goes with the next entry, or before the next
4754
+ * snapshot (which fails without it). A process that dies first replays them from the journal.
4644
4755
  */
4645
4756
  function written(entry) {
4757
+ if (!trees || !writing) return;
4758
+ applyUpTo = Math.max(applyUpTo, entry);
4759
+ applying ??= setTimeout(applyNow, APPLY_MS).unref();
4760
+ }
4761
+ function applyNow() {
4762
+ if (applying) {
4763
+ clearTimeout(applying);
4764
+ applying = null;
4765
+ }
4646
4766
  if (!trees || !writing) return;
4647
4767
  try {
4648
- trees.apply(entry);
4768
+ trees.apply(applyUpTo);
4649
4769
  } catch (error) {
4650
4770
  failed(error);
4651
4771
  }
@@ -4959,6 +5079,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
4959
5079
  if (!writing) return;
4960
5080
  await settled();
4961
5081
  await enqueue(leave);
5082
+ applyNow();
4962
5083
  writing = false;
4963
5084
  if (journalFd !== null) {
4964
5085
  closeSync(journalFd);
@@ -5691,6 +5812,7 @@ function safe(read) {
5691
5812
  }
5692
5813
  //#endregion
5693
5814
  //#region src/runtime/engine.ts
5815
+ setPublicKeyFastPath(nativePublicKey);
5694
5816
  /**
5695
5817
  * The HyperDHT network: `GHOSTLY_HYPERDHT_BOOTSTRAP` ("host:port,…") replaces the public bootstrap nodes, as it does
5696
5818
  * for the Desktop's sidecar; a network all on loopback (the tests') is announced on loopback too.
@@ -5922,8 +6044,8 @@ async function startRuntime(paths, options = {}) {
5922
6044
  const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-BtIyoDF2.js"), import("./fileBytes-B0z9A6Le.js")]);
5923
6045
  registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
5924
6046
  if (await (await import("./blobFiles-BmsrvZc3.js")).moveBlobFiles()) await store.compact();
5925
- const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-B6PQ6iae.js"), import("./endpoint-DarqblYE.js")]);
5926
- const mainline = dht.off ? null : new (await (import("./mainline-DYrjsS1t.js"))).Mainline({
6047
+ const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-Q3VcNqGt.js"), import("./endpoint-DarqblYE.js")]);
6048
+ const mainline = dht.off ? null : new (await (import("./mainline-Cu61qcPS.js"))).Mainline({
5927
6049
  bootstrap: dht.bootstrap,
5928
6050
  host: dht.host
5929
6051
  });
@@ -5931,7 +6053,7 @@ async function startRuntime(paths, options = {}) {
5931
6053
  ...pinned ? { relays: pinned } : {},
5932
6054
  ...relayBudgetForTests()
5933
6055
  };
5934
- const transport = mainline || pinned ? new (await (import("./mainline-DYrjsS1t.js"))).RelaysAndDht(mainline, relayOptions, !!pinned) : null;
6056
+ const transport = mainline || pinned ? new (await (import("./mainline-Cu61qcPS.js"))).RelaysAndDht(mainline, relayOptions, !!pinned) : null;
5935
6057
  const apps = servedApps(paths.dir).length > 0;
5936
6058
  const server = new EngineServer({
5937
6059
  ...transport ? { transport } : {},
@@ -5954,6 +6076,7 @@ async function startRuntime(paths, options = {}) {
5954
6076
  callsSupport: callsUnavailable === null,
5955
6077
  ...callsUnavailable ? { callsUnavailable } : {},
5956
6078
  ...options.autoJoins ? { autoJoins: options.autoJoins } : {},
6079
+ onlineNotices: options.onlineNotices ?? (() => false),
5957
6080
  ...options.deferGroups ? { deferGroups: true } : {},
5958
6081
  ...options.deferChats ? { deferChats: true } : {},
5959
6082
  ...options.offline ? { offline: true } : {},
@@ -6017,11 +6140,14 @@ async function openHost(paths, mode, version, options = {}) {
6017
6140
  let runtime;
6018
6141
  let groupAuto;
6019
6142
  const autoJoins = (chat) => !!groupAuto?.autoJoins(chat);
6143
+ let presence;
6144
+ const onlineNotices = () => !!presence?.saysOnline();
6020
6145
  try {
6021
6146
  runtime = await startRuntime(paths, {
6022
6147
  ...options,
6023
6148
  ...mode === "daemon" ? { logJoins: true } : {},
6024
6149
  autoJoins,
6150
+ onlineNotices,
6025
6151
  keepNewest: 100
6026
6152
  });
6027
6153
  } catch (error) {
@@ -6030,7 +6156,6 @@ async function openHost(paths, mode, version, options = {}) {
6030
6156
  }
6031
6157
  const hub = new EventHub(paths.events);
6032
6158
  let calls;
6033
- let presence;
6034
6159
  try {
6035
6160
  await hub.open();
6036
6161
  const node = runtime.server.node;
@@ -6051,7 +6176,7 @@ async function openHost(paths, mode, version, options = {}) {
6051
6176
  }
6052
6177
  hub.baseline(now, histories, {
6053
6178
  newest,
6054
- whole
6179
+ files: (id) => node.fileMessages(id)
6055
6180
  });
6056
6181
  await hub.ended((id) => fileStore.get(id));
6057
6182
  announceJoins(hub, node);
@@ -6102,6 +6227,10 @@ async function openHost(paths, mode, version, options = {}) {
6102
6227
  ctx,
6103
6228
  close: () => closing ??= (async () => {
6104
6229
  await Promise.all([calls.stopAll(), flushCardUpdates(ctx)]).catch(() => {});
6230
+ hub.sink.post({
6231
+ kind: "state",
6232
+ state: runtime.server.node.getState()
6233
+ });
6105
6234
  presence?.stop();
6106
6235
  runtime.server.detach(hub.sink);
6107
6236
  hub.release();
@@ -6347,4 +6476,4 @@ function connection(ctx, socket, secret, answering) {
6347
6476
  //#endregion
6348
6477
  export { BASELINE_NEWEST, MAX_UNREAD, STOP_ANSWERS_MS, keepServing, openHost, serve };
6349
6478
 
6350
- //# sourceMappingURL=host-8RskzQgB.js.map
6479
+ //# sourceMappingURL=host-CYlIiY3r.js.map