@ghostlytools/cli 1.7.1 → 1.7.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 (73) hide show
  1. package/README.md +27 -16
  2. package/SKILL.md +5 -1
  3. package/dist/assets/{api-CJM3R93b.js → api-B42F9ytB.js} +2 -2
  4. package/dist/assets/{api-CD9JbPuA.js → api-tf-wAAnB.js} +249 -100
  5. package/dist/assets/api-tf-wAAnB.js.map +1 -0
  6. package/dist/assets/{apiKit-BmnROpCN.js → apiKit-DJb9hulp.js} +34 -5
  7. package/dist/assets/{apiKit-BmnROpCN.js.map → apiKit-DJb9hulp.js.map} +1 -1
  8. package/dist/assets/{apps-CJ2dvKSz.js → apps-BfoDISRg.js} +1 -1
  9. package/dist/assets/{apps-DVA60Tg6.js → apps-DIrWmLgL.js} +6 -6
  10. package/dist/assets/{apps-DVA60Tg6.js.map → apps-DIrWmLgL.js.map} +1 -1
  11. package/dist/assets/{arkade-CHqwEHFd.js → arkade-CJAhhgPQ.js} +2 -2
  12. package/dist/assets/{arkade-CHqwEHFd.js.map → arkade-CJAhhgPQ.js.map} +1 -1
  13. package/dist/assets/{backup-C4CbTEcj.js → backup-BkUeeduy.js} +1 -1
  14. package/dist/assets/{backup-B4dSNvzb.js → backup-Bko-AAm0.js} +6 -6
  15. package/dist/assets/{backup-B4dSNvzb.js.map → backup-Bko-AAm0.js.map} +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-Be7u0V5g.js +2 -0
  19. package/dist/assets/{buttons-C13rK2mH.js → buttons-DeA6Yddq.js} +43 -12
  20. package/dist/assets/buttons-DeA6Yddq.js.map +1 -0
  21. package/dist/assets/{daemonProof-B41oSfon.js → daemonProof-Bp9lJDxf.js} +2 -2
  22. package/dist/assets/{daemonProof-B41oSfon.js.map → daemonProof-Bp9lJDxf.js.map} +1 -1
  23. package/dist/assets/{envelope-4TXDx3vD.js → envelope-Cz5fc7BM.js} +2 -2
  24. package/dist/assets/{envelope-4TXDx3vD.js.map → envelope-Cz5fc7BM.js.map} +1 -1
  25. package/dist/assets/{errors-CzXgR8Cc.js → errors-mnjSQlbX.js} +2 -1
  26. package/dist/assets/errors-mnjSQlbX.js.map +1 -0
  27. package/dist/assets/{groupFiles-ajZgZ6P8.js → groupFiles-BlZRBWpt.js} +558 -4
  28. package/dist/assets/groupFiles-BlZRBWpt.js.map +1 -0
  29. package/dist/assets/{host-CVeNtA2_.js → host-BX0DmKW6.js} +41 -18
  30. package/dist/assets/host-BX0DmKW6.js.map +1 -0
  31. package/dist/assets/{hyperdhtRelay-CI2ISE-g.js → hyperdhtRelay-DitYDnXx.js} +2 -2
  32. package/dist/assets/{hyperdhtRelay-CI2ISE-g.js.map → hyperdhtRelay-DitYDnXx.js.map} +1 -1
  33. package/dist/assets/{irohWeb-DcRJdhce.js → irohWeb-R3bcd34h.js} +2 -2
  34. package/dist/assets/{irohWeb-DcRJdhce.js.map → irohWeb-R3bcd34h.js.map} +1 -1
  35. package/dist/assets/{main-CjO0KGiF.js → main-6QOSvQ8b.js} +297 -127
  36. package/dist/assets/main-6QOSvQ8b.js.map +1 -0
  37. package/dist/assets/{mainline-WM-WItCV.js → mainline-BfwezHWi.js} +2 -2
  38. package/dist/assets/{mainline-WM-WItCV.js.map → mainline-BfwezHWi.js.map} +1 -1
  39. package/dist/assets/{networkReason-380j5yMs.js → networkReason-Ba9415nn.js} +2 -2
  40. package/dist/assets/{networkReason-380j5yMs.js.map → networkReason-Ba9415nn.js.map} +1 -1
  41. package/dist/assets/{nwc-D5dkC1xg.js → nwc-ovXSN2M2.js} +3 -3
  42. package/dist/assets/{nwc-D5dkC1xg.js.map → nwc-ovXSN2M2.js.map} +1 -1
  43. package/dist/assets/{nwcProvider-p_rMwtDv.js → nwcProvider-BzZbfFP3.js} +2 -2
  44. package/dist/assets/{nwcProvider-p_rMwtDv.js.map → nwcProvider-BzZbfFP3.js.map} +1 -1
  45. package/dist/assets/{profiles-BFd0tpCZ.js → profiles-C6XWqre5.js} +2 -2
  46. package/dist/assets/{profiles-BFd0tpCZ.js.map → profiles-C6XWqre5.js.map} +1 -1
  47. package/dist/assets/{registry-BfNcA6kF.js → registry-B0Uv9yL6.js} +3 -3
  48. package/dist/assets/{registry-BfNcA6kF.js.map → registry-B0Uv9yL6.js.map} +1 -1
  49. package/dist/assets/{registry-BKffx4ZU.js → registry-CFtlhWCI.js} +1 -1
  50. package/dist/assets/{resolve-hUsgRkmm.js → resolve-BzFG4WDU.js} +2 -2
  51. package/dist/assets/{resolve-hUsgRkmm.js.map → resolve-BzFG4WDU.js.map} +1 -1
  52. package/dist/assets/{server-C3tJZFnv.js → server-BGCuHbmQ.js} +504 -673
  53. package/dist/assets/server-BGCuHbmQ.js.map +1 -0
  54. package/dist/assets/{src-BMHgbkli.js → src-DWw2hUE5.js} +193 -60
  55. package/dist/assets/src-DWw2hUE5.js.map +1 -0
  56. package/dist/assets/{translate-DJUutSis.js → translate-DObb-1tq.js} +11 -11
  57. package/dist/assets/{translate-DJUutSis.js.map → translate-DObb-1tq.js.map} +1 -1
  58. package/dist/assets/{usdt-glkUxsDe.js → usdt-Bkva90Vo.js} +3 -3
  59. package/dist/assets/{usdt-glkUxsDe.js.map → usdt-Bkva90Vo.js.map} +1 -1
  60. package/dist/assets/{words-DyW9b27T.js → words-odSAoasK.js} +4 -2
  61. package/dist/assets/words-odSAoasK.js.map +1 -0
  62. package/dist/ghostly.mjs +1 -1
  63. package/package.json +1 -1
  64. package/dist/assets/api-CD9JbPuA.js.map +0 -1
  65. package/dist/assets/buttons-BMVGYXpR.js +0 -2
  66. package/dist/assets/buttons-C13rK2mH.js.map +0 -1
  67. package/dist/assets/errors-CzXgR8Cc.js.map +0 -1
  68. package/dist/assets/groupFiles-ajZgZ6P8.js.map +0 -1
  69. package/dist/assets/host-CVeNtA2_.js.map +0 -1
  70. package/dist/assets/main-CjO0KGiF.js.map +0 -1
  71. package/dist/assets/server-C3tJZFnv.js.map +0 -1
  72. package/dist/assets/src-BMHgbkli.js.map +0 -1
  73. package/dist/assets/words-DyW9b27T.js.map +0 -1
@@ -1,15 +1,15 @@
1
- import { Ao as parseLocalTarget, Gc as isAppRef, Ir as sanitizeTypingStatus, Mo as LIMITS, Nc as isAppUrl, Nr as TYPING_KINDS, Oc as APP_PERMISSIONS, Oo as GhostlyHttpError, Pr as TYPING_REFRESH_MS, Qa as appCardId, Qc as readImageMeta, So as AWAITING_PEER_MS, Vc as appRef, Wi as identityStatement, Wn as GROUP_FILE_LIMITS, Xa as STATUS_CARD_LIMITS, Y as groupName, _a as voiceDownloadName, bu as toBase64Url, ca as sanitizeFileName, da as VOICE_LIMITS, eo as cardLine, fa as VOICE_METER, fl as inviteLink, ga as parseVoiceMeta, io as statusCardBytes, la as sanitizeMime, ma as downsamplePeaks, ml as ownInviteRefusal, mu as sanitizeAvatar, ni as APP_DATA_MAX_BYTES, no as checkStatusCard, pa as baseMime, pu as MAX_AVATAR_LENGTH, so as claimedTime, ua as PLAYABLE_AUDIO, va as voiceLevel, yu as randomBytes$1 } from "./src-BMHgbkli.js";
1
+ import { $a as appCardId, $c as readImageMeta, Co as AWAITING_PEER_MS, Ha as replySnippet, Hc as appRef, Ir as sanitizeTypingStatus, Kc as isAppRef, No as LIMITS, Nr as TYPING_KINDS, Pc as isAppUrl, Pr as TYPING_REFRESH_MS, Wi as identityStatement, Wn as GROUP_FILE_LIMITS, Y as groupName, Za as STATUS_CARD_LIMITS, _a as voiceDownloadName, ao as statusCardBytes, bu as randomBytes$1, ca as sanitizeFileName, co as claimedTime, da as VOICE_LIMITS, fa as VOICE_METER, ga as parseVoiceMeta, hl as ownInviteRefusal, hu as sanitizeAvatar, jo as parseLocalTarget, kc as APP_PERMISSIONS, ko as GhostlyHttpError, la as sanitizeMime, ma as downsamplePeaks, mu as MAX_AVATAR_LENGTH, ni as APP_DATA_MAX_BYTES, pa as baseMime, pl as inviteLink, ro as checkStatusCard, to as cardLine, ua as PLAYABLE_AUDIO, va as voiceLevel, xu as toBase64Url } from "./src-DWw2hUE5.js";
2
2
  import { u as fileStore } from "./idb-BlH8-O3R.js";
3
- import { O as waitingGroupFile, T as removeStored, U as iceServerProblem, W as iceServerSetting, i as groupOfFile, l as replyRef, n as groupFileId, v as paymentNetwork } from "./groupFiles-ajZgZ6P8.js";
3
+ import { J as iceServerProblem, O as waitingGroupFile, T as removeStored, Y as iceServerSetting, i as groupOfFile, k as IDENTITY_DRAFT_TTL_MS, l as replyRef, n as groupFileId, v as paymentNetwork } from "./groupFiles-BlZRBWpt.js";
4
4
  import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-BD0v3rRG.js";
5
- import { t as IDENTITY_PROVIDERS } from "./registry-BfNcA6kF.js";
6
- import { a as waitForEdit, c as findSecret, i as pressable, n as buttonsCard, o as waitForGroupFrame, s as waitForMessage, t as BUTTON_METHODS } from "./buttons-C13rK2mH.js";
7
- import { a as WALLET_TYPES, c as DESTRUCTIVE_CALLS, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, m as engineParamsProblem, n as CHAT_METHODS, r as PAY_METHODS, s as withStoredIds, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-DyW9b27T.js";
8
- import { i as localFileError, r as asCliError, t as CliError } from "./errors-CzXgR8Cc.js";
9
- import { _ as sentAt, a as findChat, b as waitForState, d as list, f as messageOf, g as oneOf, h as num, i as chatOrGroup, l as groupOf, m as node, n as bool, o as findChatOrGroup, r as chatOf, s as findGroup, u as inviteTaken, v as state, y as str } from "./apiKit-BmnROpCN.js";
10
- import { a as checkShownName } from "./profiles-BFd0tpCZ.js";
11
- import { t as BACKUP_METHODS } from "./backup-B4dSNvzb.js";
12
- import { o as checkedBundle } from "./apps-DVA60Tg6.js";
5
+ import { t as IDENTITY_PROVIDERS } from "./registry-B0Uv9yL6.js";
6
+ import { a as waitForConfirmed, c as waitForMessage, i as pressable, l as waitForRemoval, n as buttonsCard, o as waitForEdit, s as waitForGroupFrame, t as BUTTON_METHODS, u as findSecret } from "./buttons-DeA6Yddq.js";
7
+ import { a as WALLET_TYPES, c as DESTRUCTIVE_CALLS, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, m as engineParamsProblem, n as CHAT_METHODS, r as PAY_METHODS, s as withStoredIds, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-odSAoasK.js";
8
+ import { i as localFileError, r as asCliError, t as CliError } from "./errors-mnjSQlbX.js";
9
+ import { _ as oneOf, a as dhtOnly, b as str, c as findGroup, d as inviteTaken, f as list, g as num, h as node, i as chatOrGroup, n as bool, o as findChat, p as messageOf, r as chatOf, s as findChatOrGroup, u as groupOf, v as sentAt, x as waitForState, y as state } from "./apiKit-DJb9hulp.js";
10
+ import { a as checkShownName } from "./profiles-C6XWqre5.js";
11
+ import { t as BACKUP_METHODS } from "./backup-Bko-AAm0.js";
12
+ import { o as checkedBundle } from "./apps-DIrWmLgL.js";
13
13
  import { generateMnemonic } from "@scure/bip39";
14
14
  import { wordlist } from "@scure/bip39/wordlists/english.js";
15
15
  import { openAsBlob, readFileSync, renameSync, writeFileSync } from "node:fs";
@@ -1377,11 +1377,11 @@ async function sendCard(ctx, params, kind) {
1377
1377
  }, params, now));
1378
1378
  await parentThere(ctx, target, card);
1379
1379
  const text = str(params, "text") ?? "";
1380
- const wait = oneOf(params, "wait", target.group ? ["none", "sent"] : [
1380
+ const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", [
1381
1381
  "none",
1382
1382
  "sent",
1383
1383
  "delivered"
1384
- ], "none");
1384
+ ], ctx.mode === "one-shot" ? "sent" : "none");
1385
1385
  const ms = num(params, "timeout", 30, {
1386
1386
  min: 1,
1387
1387
  max: 3600
@@ -1447,7 +1447,7 @@ async function updateCard(ctx, params, kind) {
1447
1447
  }), params));
1448
1448
  if (isObject(patch) && patch.parent !== void 0) await parentThere(ctx, target, card);
1449
1449
  const text = str(params, "text") ?? "";
1450
- const wait = oneOf(params, "wait", target.group ? ["none", "sent"] : ["none", "confirmed"], "none");
1450
+ const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", ["none", "confirmed"], ctx.mode === "one-shot" ? "confirmed" : "none");
1451
1451
  const ms = num(params, "timeout", 30, {
1452
1452
  min: 1,
1453
1453
  max: 3600
@@ -1526,7 +1526,7 @@ async function reportUsage(ctx, ref, fields, params) {
1526
1526
  };
1527
1527
  checked(report);
1528
1528
  const sent = await cardMessage(ctx, target, "usage", id).catch(() => void 0);
1529
- const wait = oneOf(params, "wait", ["none", "sent"], "none");
1529
+ const wait = oneOf(params, "wait", ["none", "sent"], !target.group && ctx.mode === "one-shot" ? "sent" : "none");
1530
1530
  if (!sent || (sent.edit?.seq ?? 0) >= STATUS_CARD_LIMITS.edits) return {
1531
1531
  ...await sendCard(ctx, {
1532
1532
  ...params,
@@ -1675,14 +1675,16 @@ async function holdChat(ctx, link, minutes) {
1675
1675
  }
1676
1676
  /**
1677
1677
  * Ends a hold: the chat leaves DHT only, unless someone chose otherwise meanwhile. Whether there was one. `reason`:
1678
- * expired, connect (`chat connect`) or lifted (`--hold 0`).
1678
+ * expired, connect (`chat connect`) or lifted (`--hold 0`, or `chat transport`: `chosen`, the chat's transport was
1679
+ * just chosen, and stays as chosen).
1679
1680
  */
1680
- async function releaseHold(ctx, linkId, reason) {
1681
+ async function releaseHold(ctx, linkId, reason, chosen = false) {
1681
1682
  const holds = readHolds(ctx);
1682
1683
  if (!holds[linkId]) return false;
1683
1684
  clearTimeout(timersOf(ctx).get(linkId));
1684
1685
  timersOf(ctx).delete(linkId);
1685
- if (state(ctx).links.find((l) => l.id === linkId)?.deliveryMode === "dht") await node(ctx).setDeliveryMode({
1686
+ const link = state(ctx).links.find((l) => l.id === linkId);
1687
+ if (!chosen && link?.deliveryMode === "dht") await node(ctx).setDeliveryMode({
1686
1688
  linkId,
1687
1689
  mode: "stream"
1688
1690
  });
@@ -1765,6 +1767,7 @@ function chatDetailsJson(link, showSecret) {
1765
1767
  rttMs: link.transportRttMs ?? null,
1766
1768
  relays: link.transportRelayed?.relays ?? null,
1767
1769
  deliveryMode: link.deliveryMode ?? null,
1770
+ peerDeliveryMode: link.dhtDelivery?.peerMode ?? null,
1768
1771
  capabilities: link.capabilities ?? null,
1769
1772
  hold: link.hold ?? null,
1770
1773
  peerOnline: link.peerOnline,
@@ -2009,7 +2012,7 @@ var GROUP_ADMIN_METHODS = {
2009
2012
  return view(ctx, group.id, params);
2010
2013
  },
2011
2014
  async "group.rename"(ctx, params) {
2012
- const group = groupOf(ctx, params);
2015
+ const group = groupOf(ctx, params, "chat rename <chat> <name...>");
2013
2016
  const name = groupName(str(params, "name", true));
2014
2017
  if (!name) throw new CliError("bad_request", `A group's name is 1 to 64 characters on one line`);
2015
2018
  await node(ctx).renameGroup({
@@ -2060,9 +2063,12 @@ var GROUP_ADMIN_METHODS = {
2060
2063
  };
2061
2064
  //#endregion
2062
2065
  //#region src/identities.ts
2063
- /** Drafts per daemon: a proof made in two steps needs the same process for both. */
2066
+ /**
2067
+ * Drafts per daemon: a proof made in two steps needs the same process for both. Kept as long as the engine keeps them,
2068
+ * and the oldest dropped when a fifth begins as the engine drops it, so what `identity add` promises still completes.
2069
+ */
2064
2070
  var drafts = /* @__PURE__ */ new Map();
2065
- var DRAFT_TTL_MS = 36e5;
2071
+ var NO_DRAFT = `No such draft here: it is kept by the daemon that made it, for ${IDENTITY_DRAFT_TTL_MS / 6e4} minutes and while fewer than 4 newer ones wait`;
2066
2072
  function provider(id) {
2067
2073
  const found = IDENTITY_PROVIDERS.find((p) => p.id === id);
2068
2074
  if (!found) throw new CliError("not_found", `No identity provider ${id} (ghostly identity providers)`);
@@ -2112,7 +2118,7 @@ function proofJson(p) {
2112
2118
  };
2113
2119
  }
2114
2120
  function pruneDrafts(now = Date.now()) {
2115
- for (const [id, draft] of drafts) if (now - draft.createdAt > DRAFT_TTL_MS) drafts.delete(id);
2121
+ for (const [id, draft] of drafts) if (now - draft.createdAt > 18e5) drafts.delete(id);
2116
2122
  }
2117
2123
  async function begin(ctx, p, subject, params) {
2118
2124
  let normalized;
@@ -2124,7 +2130,8 @@ async function begin(ctx, p, subject, params) {
2124
2130
  if (!normalized) throw new CliError("bad_request", `Not a ${p.subject?.label ?? "subject"} ${p.label} takes`);
2125
2131
  const days = params.days === void 0 ? void 0 : num(params, "days", 0, {
2126
2132
  min: 1,
2127
- max: p.validity.maxDays
2133
+ max: p.validity.maxDays,
2134
+ whole: true
2128
2135
  });
2129
2136
  return node(ctx).beginIdentityProof({
2130
2137
  provider: p.id,
@@ -2168,10 +2175,11 @@ var IDENTITY_METHODS = {
2168
2175
  const values = params.fields ?? {};
2169
2176
  if (typeof values !== "object" || Array.isArray(values) || Object.values(values).some((v) => typeof v !== "string")) throw new CliError("bad_request", "fields must be an object of strings");
2170
2177
  for (const field of signer.fields ?? []) if (!field.optional && !values[field.name]) throw new CliError("bad_request", `${signer.label} needs ${field.name} (${field.label})`);
2171
- const signal = AbortSignal.timeout(num(params, "timeout", 300, {
2178
+ const seconds = num(params, "timeout", 300, {
2172
2179
  min: 5,
2173
2180
  max: 3600
2174
- }) * 1e3);
2181
+ });
2182
+ const signal = AbortSignal.timeout(seconds * 1e3);
2175
2183
  return {
2176
2184
  done: true,
2177
2185
  proof: proofJson(await signer.run({
@@ -2212,6 +2220,9 @@ var IDENTITY_METHODS = {
2212
2220
  } catch {}
2213
2221
  throw error;
2214
2222
  }
2223
+ }).catch((error) => {
2224
+ if (!signal.aborted || error instanceof CliError) throw error;
2225
+ throw new CliError("timeout", `Timed out after ${seconds} s waiting for ${signer.label} to approve the ${p.label} proof: --timeout <seconds> waits longer`);
2215
2226
  }))
2216
2227
  };
2217
2228
  }
@@ -2223,6 +2234,7 @@ var IDENTITY_METHODS = {
2223
2234
  }
2224
2235
  const { draftId, binding } = await begin(ctx, p, subject, params);
2225
2236
  const statement = identityStatement(binding);
2237
+ while (drafts.size >= 4) drafts.delete(drafts.keys().next().value);
2226
2238
  drafts.set(draftId, {
2227
2239
  draftId,
2228
2240
  provider: p.id,
@@ -2237,19 +2249,23 @@ var IDENTITY_METHODS = {
2237
2249
  signer: signer.id,
2238
2250
  statement: statement.text,
2239
2251
  instructions: instructionsJson(signer.instructions(statement)),
2240
- expiresInSeconds: DRAFT_TTL_MS / 1e3
2252
+ expiresInSeconds: IDENTITY_DRAFT_TTL_MS / 1e3
2241
2253
  };
2242
2254
  },
2243
2255
  /** Finishes a two-step proof: what the tool printed (external-tool), or nothing (publish: the engine looks it up). */
2244
2256
  async "identity.complete"(ctx, params) {
2257
+ pruneDrafts();
2245
2258
  const draft = drafts.get(str(params, "draft", true));
2246
- if (!draft) throw new CliError("not_found", "No such draft here: it is kept by the daemon that made it, for an hour");
2259
+ if (!draft) throw new CliError("not_found", NO_DRAFT);
2247
2260
  const signer = signerOf(provider(draft.provider), draft.signer);
2248
2261
  const statement = identityStatement(draft.binding);
2249
2262
  let evidence;
2250
2263
  try {
2251
- if (signer.kind === "external-tool") evidence = await signer.parse(str(params, "evidence", true), statement);
2252
- else if (signer.kind === "publish") evidence = await signer.evidence(statement);
2264
+ if (signer.kind === "external-tool") {
2265
+ const output = str(params, "evidence");
2266
+ if (!output?.trim()) throw new CliError("usage", `Missing what ${signer.label} printed: give it from a file (--evidence-file f) or on stdin (… | ghostly identity complete ${draft.draftId})`, { needs: "evidence" });
2267
+ evidence = await signer.parse(output, statement);
2268
+ } else if (signer.kind === "publish") evidence = await signer.evidence(statement);
2253
2269
  else throw new CliError("bad_request", "This draft needs no completion");
2254
2270
  } catch (error) {
2255
2271
  if (error instanceof CliError) throw error;
@@ -2267,7 +2283,7 @@ var IDENTITY_METHODS = {
2267
2283
  },
2268
2284
  async "identity.cancel"(ctx, params) {
2269
2285
  const draftId = str(params, "draft", true);
2270
- if (!drafts.delete(draftId)) throw new CliError("not_found", "No such draft here: it is kept by the daemon that made it, for an hour");
2286
+ if (!drafts.delete(draftId)) throw new CliError("not_found", NO_DRAFT);
2271
2287
  await node(ctx).cancelIdentityProof({ draftId });
2272
2288
  return { cancelled: draftId };
2273
2289
  },
@@ -2600,6 +2616,16 @@ function serviceOf(ctx, params) {
2600
2616
  if (!state(ctx).services.some((s) => s.id === serviceId)) throw new CliError("not_found", `No service ${JSON.stringify(serviceId)} (ghostly service list)`);
2601
2617
  return serviceId;
2602
2618
  }
2619
+ /**
2620
+ * A port the person chose that could not be taken, in words that name it. Before, one in use was Node's EADDRINUSE as
2621
+ * `engine`, and one not allowed read as a file (`localFileError`): "Not allowed to write or read the path".
2622
+ */
2623
+ function portError(error, port) {
2624
+ const { code } = error ?? {};
2625
+ if (port && code === "EADDRINUSE") return new CliError("busy", `Port ${port} is in use on this machine: choose another, or leave out --port`);
2626
+ if (port && (code === "EACCES" || code === "EPERM")) return new CliError("refused", `Port ${port} is not allowed for this user: choose another, or leave out --port`);
2627
+ return error;
2628
+ }
2603
2629
  var SERVICE_METHODS = {
2604
2630
  async "service.list"(ctx) {
2605
2631
  return { services: state(ctx).services.map((s) => ({
@@ -2682,18 +2708,26 @@ var SERVICE_METHODS = {
2682
2708
  const link = chatOf(ctx, params);
2683
2709
  const service = str(params, "service", true);
2684
2710
  const key = `${link.peerPubKeyZ32}/${service}`;
2711
+ const port = num(params, "port", 0, {
2712
+ min: 0,
2713
+ max: 65535,
2714
+ whole: true
2715
+ });
2685
2716
  const already = open$1.get(key);
2686
- if (already) return {
2687
- chat: link.id,
2688
- service,
2689
- url: already.url
2690
- };
2717
+ if (already) {
2718
+ const on = already.server.address().port;
2719
+ if (port && port !== on) throw new CliError("busy", `That service is open here on port ${on}: ghostly service close ${link.id} ${service} first, or leave out --port`);
2720
+ return {
2721
+ chat: link.id,
2722
+ service,
2723
+ url: already.url
2724
+ };
2725
+ }
2691
2726
  if (!link.peerServices?.some((s) => s.id === service)) throw new CliError("not_found", `The contact shares no service ${service} (or is not live)`);
2692
2727
  const peer = link.peerPubKeyZ32;
2693
- const opened = await openServiceServer((request) => node(ctx).request(peer, service, request), num(params, "port", 0, {
2694
- min: 0,
2695
- max: 65535
2696
- }));
2728
+ const opened = await openServiceServer((request) => node(ctx).request(peer, service, request), port).catch((error) => {
2729
+ throw portError(error, port);
2730
+ });
2697
2731
  open$1.set(key, opened);
2698
2732
  return {
2699
2733
  chat: link.id,
@@ -2706,7 +2740,10 @@ var SERVICE_METHODS = {
2706
2740
  const entry = open$1.get(key);
2707
2741
  if (!entry) throw new CliError("not_found", "That service is not open here");
2708
2742
  open$1.delete(key);
2709
- await new Promise((resolve) => entry.server.close(() => resolve()));
2743
+ await new Promise((resolve) => {
2744
+ entry.server.close(() => resolve());
2745
+ entry.server.closeAllConnections();
2746
+ });
2710
2747
  return { closed: key };
2711
2748
  }
2712
2749
  };
@@ -2894,7 +2931,7 @@ function reportAppFrames(hub, node, profileDir) {
2894
2931
  /** The chat and the served app a command names, on an engine that speaks apps/1. */
2895
2932
  function target(ctx, params) {
2896
2933
  const app = servedApp(servedApps(ctx.runtime.paths.dir), str(params, "ref", true));
2897
- if (ctx.mode !== "daemon") throw new CliError("unavailable", "An app is open only while a daemon runs: start one (ghostly daemon start) and open it there");
2934
+ if (ctx.mode !== "daemon") throw new CliError("unavailable", "An app is open only while a daemon runs: start one (ghostly daemon --detach) and open it there");
2898
2935
  if (!ctx.runtime.apps) throw new CliError("unavailable", "This daemon started before an app was served, so it offers no apps/1 yet: ghostly daemon restart");
2899
2936
  const link = chatOf(ctx, params);
2900
2937
  return {
@@ -3675,6 +3712,15 @@ function mentionsFor(text, refs, group) {
3675
3712
  /** Per host: stops watching the invite it marked as the chat on screen. */
3676
3713
  var inviteShown = /* @__PURE__ */ new WeakMap();
3677
3714
  /**
3715
+ * Refuses DHT only (a hold, `chat transport dht`) while a call is on in the chat. A call's signals cross the live
3716
+ * link: off it, the call talked on over its own connection, and a hang-up from either side never reached the other
3717
+ * (that call ended only when its media stalled out, 16 s later).
3718
+ */
3719
+ function noCallOn(ctx, linkId, then) {
3720
+ const call = ctx.calls.list().find((c) => c.chat === linkId);
3721
+ if (call) throw new CliError("busy", `A call is on in this chat: hang it up first (ghostly call hangup ${linkId}), then ${then}`, { call: call.call });
3722
+ }
3723
+ /**
3678
3724
  * Marks a new invite as the chat on screen (native listeners, the quick pace) only until it is paired: a paired chat
3679
3725
  * keeps its listeners anyway, and a daemon nobody looks at reads an away contact at the background pace, as its
3680
3726
  * other chats and the same chat after a restart do. Nor past its wait for a peer (`AWAITING_PEER_MS`): an invite
@@ -3811,13 +3857,19 @@ var METHODS = {
3811
3857
  return p && (p.stage !== "publishing" || ctx.mode === "daemon" && p.relayWaitUntil) ? p : void 0;
3812
3858
  }, 2e4, "the invite to be published").catch(() => progressOf(state(ctx)));
3813
3859
  const published = !!progress && progress.stage !== "publishing" && progress.reason !== "publish";
3814
- const waitUntil = published ? void 0 : progress?.relayWaitUntil;
3815
- return {
3860
+ const answer = {
3816
3861
  chat: linkId,
3817
3862
  invite: inviteCode,
3818
3863
  link: inviteLink(inviteCode),
3819
- published,
3820
- ...waitUntil !== void 0 && { retryInMs: Math.max(0, waitUntil - Date.now()) }
3864
+ published
3865
+ };
3866
+ if (published) return answer;
3867
+ const waitUntil = progress?.relayWaitUntil;
3868
+ return {
3869
+ ...answer,
3870
+ ...waitUntil !== void 0 && { retryInMs: Math.max(0, waitUntil - Date.now()) },
3871
+ ...progress?.detail && { reason: progress.detail },
3872
+ note: "The invite is good: it goes out by itself once a relay answers, while a daemon runs for this profile"
3821
3873
  };
3822
3874
  },
3823
3875
  async "invite.join"(ctx, params) {
@@ -3971,32 +4023,53 @@ var METHODS = {
3971
4023
  ...until ? { until } : {}
3972
4024
  };
3973
4025
  },
3974
- /** WISP 400 § Reactions: one emoji per person per message, a new one replaces mine; `remove` takes mine back. */
4026
+ /**
4027
+ * WISP 400 § Reactions: one emoji per person per message, a new one replaces mine; `remove` takes mine back.
4028
+ * `wait: confirmed` (a one-shot's default) stays until the contact confirmed it; `confirmed` says whether it has.
4029
+ */
3975
4030
  async "chat.react"(ctx, params) {
3976
4031
  const link = chatNotGroup(ctx, params, "group react", "<message> <emoji>");
4032
+ const { wait, ms } = confirmWait(ctx, params);
4033
+ const before = Math.max(...node(ctx).chatUnconfirmed({ linkId: link.id }).reactions);
4034
+ const result = await react(ctx, link.id, params);
4035
+ const pending = (left) => left.reactions.some((n) => n > before);
4036
+ if (wait === "confirmed") await waitForConfirmed(ctx, link.id, "reaction", pending, ms);
3977
4037
  return {
3978
4038
  chat: link.id,
3979
- ...await react(ctx, link.id, params)
4039
+ ...result,
4040
+ confirmed: !pending(node(ctx).chatUnconfirmed({ linkId: link.id }))
3980
4041
  };
3981
4042
  },
3982
4043
  /**
3983
4044
  * WISP 400 § Pinned message: one per chat or group, a new pin replaces it; `remove` unpins. In a community only the
3984
- * admin pins. Answers the chat (or group) and the message now pinned (null once unpinned).
4045
+ * admin pins. Answers the chat (or group) and the message now pinned (null once unpinned). In a 1:1 chat `wait:
4046
+ * confirmed` (a one-shot's default) stays until the contact confirmed it, and `confirmed` says whether it has.
3985
4047
  */
3986
4048
  async "chat.pin"(ctx, params) {
3987
4049
  const target = chatOrGroup(ctx, str(params, "chat", true));
3988
4050
  const remove = bool(params, "remove"), messageId = remove ? str(params, "message") : str(params, "message", true);
4051
+ if (target.group && params.wait === "confirmed") throw new CliError("bad_request", "A group has no receipts: wait confirmed is for a 1:1 chat");
4052
+ const { wait, ms } = confirmWait(ctx, params);
3989
4053
  const result = await node(ctx).pinMessage({
3990
4054
  linkId: target.linkId,
3991
4055
  ...messageId && { messageId },
3992
4056
  remove
3993
4057
  });
3994
- if (result.error) throw new CliError(/not in this chat|Nothing is pinned/.test(result.error) ? "not_found" : /Only the admin/.test(result.error) ? "refused" : "bad_request", result.error);
3995
- return {
3996
- [target.group ? "group" : "chat"]: target.id,
4058
+ if (result.error) throw new CliError(result.refused || /Only the admin/.test(result.error) ? "refused" : /not in this chat|Nothing is pinned/.test(result.error) ? "not_found" : "bad_request", result.error);
4059
+ if (target.group) return {
4060
+ group: target.id,
3997
4061
  messageId: remove ? null : messageId,
3998
4062
  removed: remove
3999
4063
  };
4064
+ const mine = node(ctx).chatUnconfirmed({ linkId: target.linkId }).pin;
4065
+ const pending = (left) => mine !== null && left.pin === mine;
4066
+ if (wait === "confirmed") await waitForConfirmed(ctx, target.linkId, "pin", pending, ms);
4067
+ return {
4068
+ chat: target.id,
4069
+ messageId: remove ? null : messageId,
4070
+ removed: remove,
4071
+ confirmed: !pending(node(ctx).chatUnconfirmed({ linkId: target.linkId }))
4072
+ };
4000
4073
  },
4001
4074
  /** Saved messages: a mark on a message of a chat or a group, kept for this profile on this device; nothing is sent. */
4002
4075
  async "saved.add"(ctx, params) {
@@ -4009,10 +4082,10 @@ var METHODS = {
4009
4082
  async "saved.list"(ctx) {
4010
4083
  const { links, groups } = state(ctx);
4011
4084
  const saved = await node(ctx).savedMessages();
4012
- const gone = /* @__PURE__ */ new Map();
4013
- for (const linkId of new Set(saved.map((s) => s.message.linkId))) gone.set(linkId, await originalsGone(ctx, linkId, saved.flatMap((s) => s.message.linkId === linkId ? [s.message] : [])));
4085
+ const originals = /* @__PURE__ */ new Map();
4086
+ for (const linkId of new Set(saved.map((s) => s.message.linkId))) originals.set(linkId, await originalsNow(ctx, linkId, saved.flatMap((s) => s.message.linkId === linkId ? [s.message] : [])));
4014
4087
  return saved.map(({ savedAt, message }) => {
4015
- const checked = (json) => quoteChecked(json, message, gone.get(message.linkId));
4088
+ const checked = (json) => quoteChecked(json, message, originals.get(message.linkId));
4016
4089
  if (!message.linkId.startsWith("group:")) return {
4017
4090
  chat: message.linkId,
4018
4091
  savedAt,
@@ -4097,7 +4170,7 @@ var METHODS = {
4097
4170
  };
4098
4171
  },
4099
4172
  async "chat.retry"(ctx, params) {
4100
- const link = chatOf(ctx, params);
4173
+ const link = notAGroup(ctx, params, () => chatOf(ctx, params), () => "a group's message is not sent again by hand, it goes by itself when a member's edge opens");
4101
4174
  const messageId = str(params, "message", true);
4102
4175
  const message = await node(ctx).getMessage(link.id, messageId);
4103
4176
  if (!message) throw new CliError("not_found", `No message ${messageId} in this chat`);
@@ -4115,6 +4188,12 @@ var METHODS = {
4115
4188
  async "chat.delete"(ctx, params) {
4116
4189
  if (bool(params, "everyone")) {
4117
4190
  const target = chatOrGroup(ctx, str(params, "chat", true));
4191
+ const wait = oneOf(params, "wait", ["none", "confirmed"], !target.group && ctx.mode === "one-shot" ? "confirmed" : "none");
4192
+ if (target.group && wait !== "none") throw new CliError("bad_request", "A group has no receipts: --wait confirmed is for a chat");
4193
+ const ms = num(params, "timeout", 30, {
4194
+ min: 1,
4195
+ max: 3600
4196
+ }) * 1e3;
4118
4197
  const ref = str(params, "message", true);
4119
4198
  const message = await messageOf(ctx, target.linkId, ref, (m) => m.sender === "me");
4120
4199
  if (!message) throw new CliError("not_found", `No message ${ref} of yours in this ${target.group ? "group" : "chat"}: only your own messages are deleted for everyone`);
@@ -4123,12 +4202,23 @@ var METHODS = {
4123
4202
  messageId: message.id
4124
4203
  });
4125
4204
  if (result.error) throw new CliError(result.refused ? "refused" : "unavailable", result.error);
4126
- return {
4127
- [target.group ? "group" : "chat"]: target.id,
4205
+ if (target.group) return {
4206
+ group: target.id,
4128
4207
  messageId: message.id,
4129
4208
  deleted: message.id,
4130
4209
  everyone: true
4131
4210
  };
4211
+ if (wait === "confirmed") await waitForRemoval(ctx, target.linkId, message.id, ms);
4212
+ return {
4213
+ chat: target.id,
4214
+ messageId: message.id,
4215
+ deleted: message.id,
4216
+ everyone: true,
4217
+ confirmed: !node(ctx).removalPending({
4218
+ linkId: target.linkId,
4219
+ messageId: message.id
4220
+ })
4221
+ };
4132
4222
  }
4133
4223
  const ref = str(params, "message") ?? "<message>";
4134
4224
  const link = chatNotGroup(ctx, params, "message delete", `${/^[\w.:<>-]+$/.test(ref) ? ref : JSON.stringify(ref)} --everyone`);
@@ -4145,13 +4235,14 @@ var METHODS = {
4145
4235
  everyone: false
4146
4236
  };
4147
4237
  },
4238
+ /** A chat's or a group's (`group:<id>`, or its name) message, as the app's details show it; a group's said `No chat`. */
4148
4239
  async "chat.details"(ctx, params) {
4149
- const link = chatOf(ctx, params);
4240
+ const target = chatOrGroup(ctx, str(params, "chat", true));
4150
4241
  const details = await node(ctx).messageDetails({
4151
- linkId: link.id,
4242
+ linkId: target.linkId,
4152
4243
  messageId: str(params, "message", true)
4153
4244
  });
4154
- if (!details) throw new CliError("not_found", `No message ${String(params.message)} in this chat`);
4245
+ if (!details) throw new CliError("not_found", `No message ${String(params.message)} in this ${target.group ? "group" : "chat"}`);
4155
4246
  return details;
4156
4247
  },
4157
4248
  async "chat.rename"(ctx, params) {
@@ -4173,10 +4264,12 @@ var METHODS = {
4173
4264
  const name = str(params, "transport", true);
4174
4265
  const transport = Object.hasOwn(TRANSPORT_NAMES, name) ? TRANSPORT_NAMES[name] : void 0;
4175
4266
  if (!transport) throw new CliError("bad_request", `transport must be one of auto, dht, webrtc, iroh, hyperdht`);
4267
+ if (transport === "dht") noCallOn(ctx, link.id, "put the chat on DHT only");
4176
4268
  await node(ctx).setChatTransport({
4177
4269
  linkId: link.id,
4178
4270
  transport
4179
4271
  });
4272
+ await releaseHold(ctx, link.id, "lifted", true);
4180
4273
  return chatDetailsJson(findChat(state(ctx).links, link.id));
4181
4274
  },
4182
4275
  /** Reconnects now; a chat held off its direct link (`chat disconnect --hold`) leaves the hold first. */
@@ -4184,7 +4277,11 @@ var METHODS = {
4184
4277
  const link = chatOf(ctx, params);
4185
4278
  await releaseHold(ctx, link.id, "connect");
4186
4279
  inviteTaken(link);
4187
- await node(ctx).connect({ linkId: link.id });
4280
+ dhtOnly(findChat(state(ctx).links, link.id));
4281
+ await connectWithin(ctx, link, num(params, "timeout", CONNECT_MAX_SECONDS, {
4282
+ min: 1,
4283
+ max: CONNECT_MAX_SECONDS
4284
+ }) * 1e3);
4188
4285
  return chatJson(findChat(state(ctx).links, link.id));
4189
4286
  },
4190
4287
  /**
@@ -4201,6 +4298,7 @@ var METHODS = {
4201
4298
  min: 0,
4202
4299
  max: HOLD_MAX_MINUTES
4203
4300
  });
4301
+ if (minutes > 0) noCallOn(ctx, link.id, "hold the chat");
4204
4302
  if (minutes === 0) await releaseHold(ctx, link.id, "lifted");
4205
4303
  else await holdChat(ctx, link, minutes);
4206
4304
  return {
@@ -4267,14 +4365,14 @@ var METHODS = {
4267
4365
  return { groups: state(ctx).groups.map((g) => groupJson(g, showSecret)).sort((a, b) => b.lastMessageAt - a.lastMessageAt) };
4268
4366
  },
4269
4367
  async "group.get"(ctx, params) {
4270
- return groupJson(groupOf(ctx, params), bool(params, "showSecret"));
4368
+ return groupJson(groupOf(ctx, params, "chat show <chat>"), bool(params, "showSecret"));
4271
4369
  },
4272
4370
  async "group.history"(ctx, params) {
4273
- const group = groupOf(ctx, params);
4371
+ const group = groupOf(ctx, params, "chat history <chat>");
4274
4372
  return historyOf(ctx, `group:${group.id}`, params, (m) => groupMessageJson(m, group));
4275
4373
  },
4276
4374
  async "group.send"(ctx, params) {
4277
- const group = groupOf(ctx, params);
4375
+ const group = groupOf(ctx, params, "send <chat> [text...]");
4278
4376
  const text = str(params, "text", true);
4279
4377
  checkTextSize(text);
4280
4378
  if (!bool(params, "force")) {
@@ -4317,10 +4415,10 @@ var METHODS = {
4317
4415
  /**
4318
4416
  * WISP 902 § Edits: the whole new text of one of my messages in a group. It shows here at once and goes to the members
4319
4417
  * (a private group's over the edges that are up, the others when theirs open; a community's through the group).
4320
- * `mentions`: members the new text names beyond those the message named. `sent`: no longer waiting for the pace.
4418
+ * `mentions`: members the new text names beyond those the message named. `sent`: whether an edge took it, as for group send.
4321
4419
  */
4322
4420
  async "group.edit"(ctx, params) {
4323
- const group = groupOf(ctx, params);
4421
+ const group = groupOf(ctx, params, "edit <chat> <message> <text...>");
4324
4422
  const messageId = str(params, "message", true);
4325
4423
  const text = str(params, "text", true);
4326
4424
  if (!bool(params, "force")) {
@@ -4342,8 +4440,7 @@ var METHODS = {
4342
4440
  ...mentions.length ? { mentions } : {}
4343
4441
  });
4344
4442
  if (result.error) throw editRefused(await messageOf(ctx, linkId, messageId), messageId, "group", result.error, result.refused);
4345
- const message = await node(ctx).getMessage(linkId, messageId);
4346
- const edits = message?.edit?.seq ?? 0;
4443
+ const edits = (await node(ctx).getMessage(linkId, messageId))?.edit?.seq ?? 0;
4347
4444
  if (edits === before) return {
4348
4445
  group: group.id,
4349
4446
  messageId,
@@ -4361,12 +4458,12 @@ var METHODS = {
4361
4458
  group: group.id,
4362
4459
  messageId,
4363
4460
  edits,
4364
- sent: edges > 0 || !!message && !message.edit?.pending,
4461
+ sent: edges > 0,
4365
4462
  edges
4366
4463
  };
4367
4464
  },
4368
4465
  async "group.react"(ctx, params) {
4369
- const group = groupOf(ctx, params);
4466
+ const group = groupOf(ctx, params, "react <chat> <message> <emoji>");
4370
4467
  return {
4371
4468
  group: group.id,
4372
4469
  ...await react(ctx, `group:${group.id}`, params)
@@ -4377,7 +4474,7 @@ var METHODS = {
4377
4474
  * how many members), with the same kinds, status rules, 6 s hold and `for`. A community does not carry typing yet.
4378
4475
  */
4379
4476
  async "group.typing"(ctx, params) {
4380
- const group = groupOf(ctx, params);
4477
+ const group = groupOf(ctx, params, "typing <chat>");
4381
4478
  if (group.profile !== "mesh") throw new CliError("unavailable", "A community does not carry typing yet: only a private group does");
4382
4479
  const typing = !bool(params, "stop");
4383
4480
  const { kind, status } = typingWord(params, typing);
@@ -4422,7 +4519,7 @@ var METHODS = {
4422
4519
  };
4423
4520
  },
4424
4521
  async "group.forget"(ctx, params) {
4425
- const group = groupOf(ctx, params);
4522
+ const group = groupOf(ctx, params, "chat remove <chat> --yes");
4426
4523
  if (!bool(params, "yes")) throw new CliError("confirm", "Forgetting a group deletes its history on this device; pass yes (--yes) to go on");
4427
4524
  await node(ctx).forgetGroup({ groupId: group.id });
4428
4525
  return { forgotten: group.id };
@@ -4539,6 +4636,19 @@ async function guardEngineSend(ctx, method, args) {
4539
4636
  const secret = secretIn(texts);
4540
4637
  if (secret) throw new CliError("confirm", `The text looks like ${secret.kind === "cashu" ? "a Cashu token (money anyone who reads it can take)" : "a secret (a seed or a private key)"}; call ${method} with --force if you mean to`, { kind: secret.kind });
4541
4638
  }
4639
+ /**
4640
+ * How long `react` and `pin` in a 1:1 chat wait for the contact: a one-shot until it confirmed (as `edit`), since what
4641
+ * is not said yet leaves with the process; a daemon goes on saying it, so it answers at once unless asked to wait.
4642
+ */
4643
+ function confirmWait(ctx, params) {
4644
+ return {
4645
+ wait: oneOf(params, "wait", ["none", "confirmed"], ctx.mode === "one-shot" ? "confirmed" : "none"),
4646
+ ms: num(params, "timeout", 30, {
4647
+ min: 1,
4648
+ max: 3600
4649
+ }) * 1e3
4650
+ };
4651
+ }
4542
4652
  /** Reacts to a message of a chat or a group (`group:<id>`): `emoji`, or `remove` for "" (WISP 400 § Reactions). */
4543
4653
  async function react(ctx, linkId, params) {
4544
4654
  const messageId = str(params, "message", true);
@@ -4587,28 +4697,31 @@ function groupSendRefused(error) {
4587
4697
  return new CliError("unavailable", error);
4588
4698
  }
4589
4699
  /**
4590
- * A chat command given a group's id, prefix or name: `not_found` that says it is a group, with the group command that
4591
- * takes it (`react` on a group, where `group react` is meant). A name no chat and no group has stays the chat's error.
4700
+ * A chat command given a group's id, prefix or name: `not_found` that says it is a group, with `hint`: the group
4701
+ * command that takes it (`react` on a group, where `group react` is meant), or what to do where none does. `group:<id>`,
4702
+ * the form `pin` and `saved` take, is that group too (it read "No chat" before). A name no chat and no group has stays
4703
+ * the chat's error.
4592
4704
  */
4593
- function notAGroup(ctx, params, chat, command, rest) {
4705
+ function notAGroup(ctx, params, chat, hint) {
4594
4706
  try {
4595
4707
  return chat();
4596
4708
  } catch (error) {
4597
4709
  if (!(error instanceof CliError) || error.code !== "not_found") throw error;
4598
4710
  const ref = str(params, "chat", true);
4711
+ const named = ref.startsWith("group:") ? ref.slice(6) : ref;
4599
4712
  let group;
4600
4713
  try {
4601
- group = findGroup(state(ctx).groups, ref);
4714
+ group = findGroup(state(ctx).groups, named);
4602
4715
  } catch {
4603
4716
  throw error;
4604
4717
  }
4605
- const shown = /^[\w.:-]+$/.test(ref) ? ref : JSON.stringify(ref);
4606
- throw new CliError("not_found", `${JSON.stringify(ref)} is a group, not a chat: ghostly ${command} ${shown}${rest ? ` ${rest}` : ""}`, { group: group.id });
4718
+ const shown = /^[\w.:-]+$/.test(named) ? named : JSON.stringify(named);
4719
+ throw new CliError("not_found", `${JSON.stringify(ref)} is a group, not a chat: ${hint(shown)}`, { group: group.id });
4607
4720
  }
4608
4721
  }
4609
4722
  /** The chat a chat command with a group twin names: a group's name says so, with `command`, the twin (see `notAGroup`). */
4610
4723
  function chatNotGroup(ctx, params, command, rest = "") {
4611
- return notAGroup(ctx, params, () => chatOf(ctx, params), command, rest);
4724
+ return notAGroup(ctx, params, () => chatOf(ctx, params), (shown) => `ghostly ${command} ${shown}${rest ? ` ${rest}` : ""}`);
4612
4725
  }
4613
4726
  /**
4614
4727
  * An edit the engine refused. A message that is not in the chat or group at all is `not_found` (exit 3), naming the id
@@ -4619,6 +4732,29 @@ function editRefused(message, ref, where, error, refused) {
4619
4732
  if (refused && !message) return new CliError("not_found", `No message ${JSON.stringify(ref)} in this ${where}: give the messageId ${where === "group" ? "group send" : "send"} printed`);
4620
4733
  return new CliError(refused ? "refused" : "unavailable", error);
4621
4734
  }
4735
+ /** The chat link's own wait for a contact (`GhostLink.connect`): `chat connect --timeout` waits at most that long. */
4736
+ var CONNECT_MAX_SECONDS = 90;
4737
+ /**
4738
+ * `chat connect`, waiting at most `ms` for the contact; the link's dial goes on behind a shorter wait. Timed out (here,
4739
+ * or by the link's own 90 s), it says what happens next: before, it waited a fixed 90 s and ended "Timed out connecting
4740
+ * to the peer", with no next step.
4741
+ */
4742
+ async function connectWithin(ctx, link, ms) {
4743
+ const dial = node(ctx).connect({ linkId: link.id });
4744
+ let timer;
4745
+ const late = new Promise((resolve) => {
4746
+ timer = setTimeout(() => resolve("late"), ms);
4747
+ });
4748
+ try {
4749
+ if (await Promise.race([dial, late]) !== "late") return;
4750
+ } catch (error) {
4751
+ if (asCliError(error).code !== "timeout") throw error;
4752
+ } finally {
4753
+ clearTimeout(timer);
4754
+ }
4755
+ const shown = /^[\w.:-]+$/.test(link.label ?? "") ? link.label : link.id;
4756
+ throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the contact did not answer. ${ctx.mode === "one-shot" ? "Try again later, or keep this profile online with `ghostly daemon --detach`: it reconnects by itself" : `It reconnects by itself while this profile is online; ghostly chat wait ${shown} --until live waits for it`}`, { chat: link.id });
4757
+ }
4622
4758
  /**
4623
4759
  * A page of a chat's or a group's history. Without `after` only that page is read from the store (the newest, or those
4624
4760
  * before `before`), so a long chat's is as quick as a short one's; with `after` the whole history is read and cut.
@@ -4641,9 +4777,9 @@ async function saveMark(ctx, params, remove) {
4641
4777
  async function historyOf(ctx, chat, params, json = messageJson) {
4642
4778
  if (params.after !== void 0 && params.after !== null) {
4643
4779
  const whole = await node(ctx).getMessages(chat), { messages, more } = history(whole, params);
4644
- const gone = await originalsGone(ctx, chat, messages, whole);
4780
+ const originals = await originalsNow(ctx, chat, messages, whole);
4645
4781
  return {
4646
- messages: messages.map((m) => quoteChecked(json(m), m, gone)),
4782
+ messages: messages.map((m) => quoteChecked(json(m), m, originals)),
4647
4783
  more
4648
4784
  };
4649
4785
  }
@@ -4661,34 +4797,39 @@ async function historyOf(ctx, chat, params, json = messageJson) {
4661
4797
  }).catch((error) => {
4662
4798
  throw error instanceof Error && error.message === `No message ${before}` ? new CliError("not_found", error.message) : error;
4663
4799
  });
4664
- const gone = await originalsGone(ctx, chat, page.messages);
4800
+ const originals = await originalsNow(ctx, chat, page.messages);
4665
4801
  return {
4666
- messages: page.messages.map((m) => quoteChecked(json(m), m, gone)),
4802
+ messages: page.messages.map((m) => quoteChecked(json(m), m, originals)),
4667
4803
  more: page.more
4668
4804
  };
4669
4805
  }
4670
4806
  /** Past this many originals outside a page, its history is read once instead of row by row. */
4671
4807
  var ORIGINAL_READS = 32;
4672
4808
  /**
4673
- * The originals a page's replies found here when they came that are gone now: deleted on this device, or for everyone
4674
- * by their author (WISP 400 § Delete for everyone). Each is looked for in the page, else read as its one row, one at
4675
- * a time (a burst of reads stalls fake-indexeddb's scheduler); `whole` is the chat's whole history when it was read
4676
- * already. Before, such a reply still said `found`, with the original's text.
4809
+ * The originals a page's replies found here when they came, as they are now: gone (deleted on this device, or for
4810
+ * everyone by their author: WISP 400 § Delete for everyone), or the row, edited since or not. Each is looked for in the
4811
+ * page, else read as its one row, one at a time (a burst of reads stalls fake-indexeddb's scheduler); `whole` is the
4812
+ * chat's whole history when it was read already. Before, such a reply still said `found`, with the original's text.
4677
4813
  */
4678
- async function originalsGone(ctx, chat, page, whole = page) {
4679
- const here = new Set(whole.map((m) => m.id));
4680
- const asked = [...new Set(page.flatMap((m) => m.replyTo?.messageId && !here.has(m.replyTo.messageId) ? [m.replyTo.messageId] : []))];
4681
- if (whole !== page) return new Set(asked);
4682
- if (asked.length > ORIGINAL_READS) return originalsGone(ctx, chat, page, await node(ctx).getMessages(chat));
4683
- const gone = /* @__PURE__ */ new Set();
4684
- for (const id of asked) if (!await node(ctx).getMessage(chat, id)) gone.add(id);
4685
- return gone;
4686
- }
4687
- /** A reply whose original is gone, as the apps show it ("Original message deleted"): not found, and none of its text. */
4688
- function quoteChecked(json, message, gone) {
4814
+ async function originalsNow(ctx, chat, page, whole = page) {
4815
+ const here = new Map(whole.map((m) => [m.id, m]));
4816
+ const named = [...new Set(page.flatMap((m) => m.replyTo?.messageId ? [m.replyTo.messageId] : []))];
4817
+ const asked = named.filter((id) => !here.has(id));
4818
+ if (whole === page && asked.length > ORIGINAL_READS) return originalsNow(ctx, chat, page, await node(ctx).getMessages(chat));
4819
+ const originals = new Map(named.flatMap((id) => here.has(id) ? [[id, here.get(id)]] : []));
4820
+ for (const id of asked) originals.set(id, whole === page ? await node(ctx).getMessage(chat, id) : void 0);
4821
+ return originals;
4822
+ }
4823
+ /**
4824
+ * A reply's quote as the apps show it (`quoteFor`): an original gone reads "Original message deleted", not found and
4825
+ * none of its text; one edited since the reply quotes its text as it reads now. A button press keeps the question as
4826
+ * it was answered (WISP 406 · Message Buttons), and a card's or a file's line stays the one the reply carries.
4827
+ */
4828
+ function quoteChecked(json, message, originals) {
4689
4829
  const id = message.replyTo?.messageId;
4690
- if (!json.replyTo || !id || !gone.has(id)) return json;
4691
- return {
4830
+ if (!json.replyTo || !id || !originals.has(id)) return json;
4831
+ const original = originals.get(id);
4832
+ if (!original) return {
4692
4833
  ...json,
4693
4834
  replyTo: {
4694
4835
  ...json.replyTo,
@@ -4697,6 +4838,14 @@ function quoteChecked(json, message, gone) {
4697
4838
  deleted: true
4698
4839
  }
4699
4840
  };
4841
+ if (!original.edit || json.replyTo.button || original.card || original.file) return json;
4842
+ return {
4843
+ ...json,
4844
+ replyTo: {
4845
+ ...json.replyTo,
4846
+ snippet: replySnippet(original.text)
4847
+ }
4848
+ };
4700
4849
  }
4701
4850
  function history(messages, params) {
4702
4851
  const limit = num(params, "limit", 50, {
@@ -4734,4 +4883,4 @@ async function callApi(ctx, method, params = {}) {
4734
4883
  //#endregion
4735
4884
  export { flushCardUpdates as _, hideStateSecrets as a, paymentJson as c, nodeLocalFetch as d, chatJson as f, resumeHolds as g, groupMessageJson as h, groupSendRefused as i, reportAppFrames as l, groupJson as m, SETTABLE as n, mentionsFor as o, chatMessageJson as p, callApi as r, redactSettings as s, API_METHODS as t, servedApps as u };
4736
4885
 
4737
- //# sourceMappingURL=api-CD9JbPuA.js.map
4886
+ //# sourceMappingURL=api-tf-wAAnB.js.map