@ghostlytools/cli 1.11.0 → 1.11.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 +24 -16
  2. package/dist/assets/{api-CTqIcdu7.js → api-BM3PsXbB.js} +372 -123
  3. package/dist/assets/api-BM3PsXbB.js.map +1 -0
  4. package/dist/assets/{api-B-52sVYp.js → api-CtXgscmK.js} +2 -2
  5. package/dist/assets/{apiKit-CZq4Lq4f.js → apiKit-lCTQ0EBG.js} +17 -7
  6. package/dist/assets/apiKit-lCTQ0EBG.js.map +1 -0
  7. package/dist/assets/appFetch-BKHy5H8J.js +194 -0
  8. package/dist/assets/appFetch-BKHy5H8J.js.map +1 -0
  9. package/dist/assets/{apps-kRsY9S2S.js → apps-DO_gAZgm.js} +1 -1
  10. package/dist/assets/{apps-C_X0zgSG.js → apps-Do26w3c7.js} +44 -40
  11. package/dist/assets/apps-Do26w3c7.js.map +1 -0
  12. package/dist/assets/{arkade-_aaB7VbW.js → arkade-CZrLbz-M.js} +2 -2
  13. package/dist/assets/{arkade-_aaB7VbW.js.map → arkade-CZrLbz-M.js.map} +1 -1
  14. package/dist/assets/{backup-DBg388Ke.js → backup-D21x1f5P.js} +1 -1
  15. package/dist/assets/{backup-OTvrmk-w.js → backup-j47AzDvG.js} +84 -33
  16. package/dist/assets/backup-j47AzDvG.js.map +1 -0
  17. package/dist/assets/{bitcoind-CZchoh43.js → bitcoind-CdSmvy2y.js} +3 -3
  18. package/dist/assets/{bitcoind-CZchoh43.js.map → bitcoind-CdSmvy2y.js.map} +1 -1
  19. package/dist/assets/{bitcoindProvider-DGw3xBSa.js → bitcoindProvider-BvoRh0D5.js} +2 -2
  20. package/dist/assets/{bitcoindProvider-DGw3xBSa.js.map → bitcoindProvider-BvoRh0D5.js.map} +1 -1
  21. package/dist/assets/{buttons-DUu7hxxT.js → buttons-CiGlBVBT.js} +18 -7
  22. package/dist/assets/buttons-CiGlBVBT.js.map +1 -0
  23. package/dist/assets/buttons-D2l2bVCG.js +2 -0
  24. package/dist/assets/{childEnv-BVOQK9EA.js → childEnv-K_IzUqQx.js} +4 -3
  25. package/dist/assets/childEnv-K_IzUqQx.js.map +1 -0
  26. package/dist/assets/{client-DDpZP1R1.js → client-raIncVtF.js} +31 -3
  27. package/dist/assets/client-raIncVtF.js.map +1 -0
  28. package/dist/assets/{codec-DrryGcPT.js → codec-DcG2AeyE.js} +2 -2
  29. package/dist/assets/{codec-DrryGcPT.js.map → codec-DcG2AeyE.js.map} +1 -1
  30. package/dist/assets/endpoint-DarqblYE.js +5052 -0
  31. package/dist/assets/endpoint-DarqblYE.js.map +1 -0
  32. package/dist/assets/{envelope-Q_rMgoE9.js → envelope-Dud6lntA.js} +2 -2
  33. package/dist/assets/{envelope-Q_rMgoE9.js.map → envelope-Dud6lntA.js.map} +1 -1
  34. package/dist/assets/{fedimintSdk-CqTeMdF0.js → fedimintSdk-DRKRSw14.js} +6 -3
  35. package/dist/assets/fedimintSdk-DRKRSw14.js.map +1 -0
  36. package/dist/assets/{fixedHosts-BV5GDiTU.js → fixedHosts-CNX7QiUD.js} +3 -3
  37. package/dist/assets/{fixedHosts-BV5GDiTU.js.map → fixedHosts-CNX7QiUD.js.map} +1 -1
  38. package/dist/assets/{host-BlUzZgQL.js → host-8RskzQgB.js} +306 -84
  39. package/dist/assets/host-8RskzQgB.js.map +1 -0
  40. package/dist/assets/{hyperdhtRelay-BvI_uNZO.js → hyperdhtRelay-uAThbFub.js} +2 -2
  41. package/dist/assets/{hyperdhtRelay-BvI_uNZO.js.map → hyperdhtRelay-uAThbFub.js.map} +1 -1
  42. package/dist/assets/{irohWeb-CqPN8VPY.js → irohWeb-DGelfgDJ.js} +695 -40
  43. package/dist/assets/irohWeb-DGelfgDJ.js.map +1 -0
  44. package/dist/assets/jsonOut-POtMBS_V.js +16 -0
  45. package/dist/assets/jsonOut-POtMBS_V.js.map +1 -0
  46. package/dist/assets/{main-vQjlgEnt.js → main-BC33ooYg.js} +175 -107
  47. package/dist/assets/main-BC33ooYg.js.map +1 -0
  48. package/dist/assets/{mainline-p6HOW7sb.js → mainline-DYrjsS1t.js} +27 -8
  49. package/dist/assets/mainline-DYrjsS1t.js.map +1 -0
  50. package/dist/assets/{networkReason-DMffkiJ6.js → networkReason-n2oBs4by.js} +3 -3
  51. package/dist/assets/{networkReason-DMffkiJ6.js.map → networkReason-n2oBs4by.js.map} +1 -1
  52. package/dist/assets/{nwc-2vH18oNy.js → nwc-Do3VSlIS.js} +6 -5
  53. package/dist/assets/nwc-Do3VSlIS.js.map +1 -0
  54. package/dist/assets/{nwcProvider-DpeDy0bV.js → nwcProvider-Du5aWNIn.js} +6 -3
  55. package/dist/assets/{nwcProvider-DpeDy0bV.js.map → nwcProvider-Du5aWNIn.js.map} +1 -1
  56. package/dist/assets/{ownDid-iKz8u_fM.js → ownDid-CwwYu8s2.js} +3 -3
  57. package/dist/assets/{ownDid-iKz8u_fM.js.map → ownDid-CwwYu8s2.js.map} +1 -1
  58. package/dist/assets/{ownStatus-BlRKnM5F.js → ownStatus-D7dB4zJB.js} +4 -3
  59. package/dist/assets/{ownStatus-BlRKnM5F.js.map → ownStatus-D7dB4zJB.js.map} +1 -1
  60. package/dist/assets/{profiles-B5e0TyvS.js → profiles-NyF5FnYF.js} +82 -6
  61. package/dist/assets/profiles-NyF5FnYF.js.map +1 -0
  62. package/dist/assets/{registry-Cc_PQb3k.js → registry-C734VrO9.js} +1 -1
  63. package/dist/assets/{registry-CnFO2Pp5.js → registry-DKDInr0A.js} +75 -23
  64. package/dist/assets/registry-DKDInr0A.js.map +1 -0
  65. package/dist/assets/{resolve-DI8uAM_Y.js → resolve-3Tqh9AWQ.js} +4 -3
  66. package/dist/assets/resolve-3Tqh9AWQ.js.map +1 -0
  67. package/dist/assets/{server-DdtPxkqI.js → server-B6PQ6iae.js} +430 -868
  68. package/dist/assets/server-B6PQ6iae.js.map +1 -0
  69. package/dist/assets/{src-BnpEQqzk.js → src-ChJijTlM.js} +1139 -243
  70. package/dist/assets/src-ChJijTlM.js.map +1 -0
  71. package/dist/assets/{sshForges-cdIAraDw.js → sshForges-Brf0fslM.js} +2 -2
  72. package/dist/assets/{sshForges-cdIAraDw.js.map → sshForges-Brf0fslM.js.map} +1 -1
  73. package/dist/assets/{translate-kNopA04L.js → translate-xLme9Rdh.js} +10 -8
  74. package/dist/assets/translate-xLme9Rdh.js.map +1 -0
  75. package/dist/assets/{types-C4_KafL_.js → types-Clyb52K2.js} +2 -1
  76. package/dist/assets/types-Clyb52K2.js.map +1 -0
  77. package/dist/assets/{usdt-CDaLhEYh.js → usdt-CSU5KzTV.js} +3 -3
  78. package/dist/assets/{usdt-CDaLhEYh.js.map → usdt-CSU5KzTV.js.map} +1 -1
  79. package/dist/ghostly.mjs +1 -1
  80. package/npm-shrinkwrap.json +3592 -0
  81. package/package.json +5 -3
  82. package/dist/assets/api-CTqIcdu7.js.map +0 -1
  83. package/dist/assets/apiKit-CZq4Lq4f.js.map +0 -1
  84. package/dist/assets/apps-C_X0zgSG.js.map +0 -1
  85. package/dist/assets/backup-OTvrmk-w.js.map +0 -1
  86. package/dist/assets/buttons-4EKtQl-7.js +0 -2
  87. package/dist/assets/buttons-DUu7hxxT.js.map +0 -1
  88. package/dist/assets/childEnv-BVOQK9EA.js.map +0 -1
  89. package/dist/assets/client-DDpZP1R1.js.map +0 -1
  90. package/dist/assets/endpoint-DWHkXWVM.js +0 -419
  91. package/dist/assets/endpoint-DWHkXWVM.js.map +0 -1
  92. package/dist/assets/fedimintSdk-CqTeMdF0.js.map +0 -1
  93. package/dist/assets/host-BlUzZgQL.js.map +0 -1
  94. package/dist/assets/irohWeb-CqPN8VPY.js.map +0 -1
  95. package/dist/assets/main-vQjlgEnt.js.map +0 -1
  96. package/dist/assets/mainline-p6HOW7sb.js.map +0 -1
  97. package/dist/assets/nwc-2vH18oNy.js.map +0 -1
  98. package/dist/assets/profiles-B5e0TyvS.js.map +0 -1
  99. package/dist/assets/registry-CnFO2Pp5.js.map +0 -1
  100. package/dist/assets/resolve-DI8uAM_Y.js.map +0 -1
  101. package/dist/assets/server-DdtPxkqI.js.map +0 -1
  102. package/dist/assets/src-BnpEQqzk.js.map +0 -1
  103. package/dist/assets/translate-kNopA04L.js.map +0 -1
  104. package/dist/assets/types-C4_KafL_.js.map +0 -1
@@ -0,0 +1,16 @@
1
+ //#region src/jsonOut.ts
2
+ /**
3
+ * What `JSON.stringify` leaves raw and a terminal may act on: DEL and the C1 controls (CSI, OSC, ST, NEL... in UTF-8),
4
+ * the line and paragraph separators, and the bidi marks, embeddings, overrides and isolates that reorder a line. Only
5
+ * a string holds them, and a peer writes some of those strings (a message's text), so the CLI's output writes them as
6
+ * `\uXXXX`: the same JSON value for every reader, nothing a terminal acts on. What is stored stays whole.
7
+ */
8
+ var RAW = /[\u007f-\u009f\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g;
9
+ /** `value` as the JSON the CLI prints: `JSON.stringify`, with `RAW` escaped. */
10
+ function jsonOut(value, space) {
11
+ return JSON.stringify(value, null, space)?.replace(RAW, (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, "0"));
12
+ }
13
+ //#endregion
14
+ export { jsonOut as t };
15
+
16
+ //# sourceMappingURL=jsonOut-POtMBS_V.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonOut-POtMBS_V.js","names":[],"sources":["../../src/jsonOut.ts"],"sourcesContent":["/**\n * What `JSON.stringify` leaves raw and a terminal may act on: DEL and the C1 controls (CSI, OSC, ST, NEL... in UTF-8),\n * the line and paragraph separators, and the bidi marks, embeddings, overrides and isolates that reorder a line. Only\n * a string holds them, and a peer writes some of those strings (a message's text), so the CLI's output writes them as\n * `\\uXXXX`: the same JSON value for every reader, nothing a terminal acts on. What is stored stays whole.\n */\nconst RAW = /[\\u007f-\\u009f\\u061c\\u200e\\u200f\\u2028\\u2029\\u202a-\\u202e\\u2066-\\u2069]/g;\n\n/** `value` as the JSON the CLI prints: `JSON.stringify`, with `RAW` escaped. */\nexport function jsonOut(value: unknown, space?: number): string {\n return JSON.stringify(value, null, space)?.replace(RAW, (char) => \"\\\\u\" + char.charCodeAt(0).toString(16).padStart(4, \"0\"));\n}\n"],"mappings":";;;;;;;AAMA,IAAM,MAAM;;AAGZ,SAAgB,QAAQ,OAAgB,OAAwB;CAC9D,OAAO,KAAK,UAAU,OAAO,MAAM,KAAK,CAAC,EAAE,QAAQ,MAAM,SAAS,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC;AAC5H"}
@@ -1,11 +1,12 @@
1
- import { Co as PR_STATES, Do as TASK_STATUSES, Eo as STATUS_CARD_LIMITS, Fo as statusCardBytes, Mo as cardUrl, Ra as VOICE_LIMITS, So as PR_CHECKS, To as RUN_RESULTS, bo as CRON_LINE, jo as cardLine, nr as GROUP_FILE_LIMITS, qr as STATUS_AVAILABILITIES, wo as ROUTINE_STATES, xo as ITEM_STATES } from "./src-BnpEQqzk.js";
1
+ import { Ao as STATUS_CARD_LIMITS, Do as PR_STATES, Eo as PR_CHECKS, Fo as cardLine, Ha as VOICE_LIMITS, Io as cardUrl, Oo as ROUTINE_STATES, To as ITEM_STATES, Zr as STATUS_AVAILABILITIES, jo as TASK_STATUSES, ko as RUN_RESULTS, or as GROUP_FILE_LIMITS, wo as CRON_LINE, zo as statusCardBytes } from "./src-ChJijTlM.js";
2
2
  import { i as localFileError, n as EXIT, r as asCliError, t as CliError } from "./errors-Dt-ZnyOX.js";
3
- import { a as PAY_METHODS, c as turnRef, d as ENGINE_METHODS, f as ENGINE_PARAMS, h as SECRET_RESULTS, i as CHAT_METHODS, m as READ_PARAMS, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus } from "./ownStatus-BlRKnM5F.js";
4
- import { t as CONTACT_KEY, v as nameKey, y as namedByThem } from "./apiKit-CZq4Lq4f.js";
5
- import { n as dropSecretEnv, t as childEnv } from "./childEnv-BVOQK9EA.js";
3
+ import { a as PAY_METHODS, c as turnRef, d as ENGINE_METHODS, f as ENGINE_PARAMS, h as SECRET_RESULTS, i as CHAT_METHODS, m as READ_PARAMS, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus } from "./ownStatus-D7dB4zJB.js";
4
+ import { a as contactKeyOf, v as nameKey, y as namedByThem } from "./apiKit-lCTQ0EBG.js";
5
+ import { n as dropSecretEnv, t as childEnv } from "./childEnv-K_IzUqQx.js";
6
6
  import { i as waitsFor, r as waitNotice } from "./waitNotice-Cn0WJ-He.js";
7
- import { _ as startingDaemon, c as currentProfile, d as lockOwner, g as selectProfile, h as profilePaths, i as checkProfileName, l as ghostlyHome, m as profileExists, o as checkShownNameOption, p as noProfile, s as createProfile, u as listProfiles, x as ownProfile, y as userPath } from "./profiles-B5e0TyvS.js";
8
- import { _ as isCallRate, a as isNotTheDaemon, d as CALL_RATES, i as endedUnanswered, r as connectDaemon, t as DaemonClient } from "./client-DDpZP1R1.js";
7
+ import { C as ownProfile, _ as profilePaths, c as createProfile, d as ghostlyHome, f as listProfiles, g as profileExists, h as noProfile, i as checkProfileName, l as currentProfile, o as checkShownNameOption, p as lockOwner, s as claimForDaemon, u as daemonClaim, v as selectProfile, x as userPath, y as startingDaemon } from "./profiles-NyF5FnYF.js";
8
+ import { t as jsonOut } from "./jsonOut-POtMBS_V.js";
9
+ import { a as endedUnsent, f as CALL_RATES, i as endedUnanswered, o as isNotTheDaemon, r as connectDaemon, t as DaemonClient, v as isCallRate } from "./client-raIncVtF.js";
9
10
  import { spawn } from "node:child_process";
10
11
  import { accessSync, closeSync, constants, existsSync, fstatSync, openSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
11
12
  import { dirname, resolve, sep } from "node:path";
@@ -13,7 +14,7 @@ import { connect } from "node:net";
13
14
  import { format } from "node:util";
14
15
  var package_default = {
15
16
  name: "@ghostlytools/cli",
16
- version: "1.11.0",
17
+ version: "1.11.2",
17
18
  type: "module",
18
19
  description: "Ghostly for bots and terminals: the app's own engine, headless on Node, behind a daemon and a `ghostly` command with JSON output.",
19
20
  license: "MIT",
@@ -31,7 +32,8 @@ var package_default = {
31
32
  "examples",
32
33
  "skills",
33
34
  "README.md",
34
- "SKILL.md"
35
+ "SKILL.md",
36
+ "npm-shrinkwrap.json"
35
37
  ],
36
38
  engines: { "node": ">=22.12" },
37
39
  scripts: {
@@ -72,7 +74,8 @@ var package_default = {
72
74
  "node-datachannel": "^0.33.4",
73
75
  "nostr-tools": "2.25.2",
74
76
  "opus-decoder": "0.7.12",
75
- "opusscript": "0.1.1"
77
+ "opusscript": "0.1.1",
78
+ "ws": "8.22.1"
76
79
  },
77
80
  devDependencies: {
78
81
  "@ghostly/browser": "*",
@@ -814,13 +817,14 @@ function writtenDay(text) {
814
817
  * A day the month does not have (`2026-04-31`) is refused, where `Date.parse` made it May 1. A time more than a year
815
818
  * ahead is a usage error that names the flag and the last time it takes: before, it reached the card's check and failed
816
819
  * as `bad_request` (exit 1), "Status card: resetsAt is a time in milliseconds, within a year". A time past is taken.
820
+ * `forms` is what a time it cannot read is told to be, for a flag that takes more (`status set --until 2h`).
817
821
  */
818
- function cardTime(value, flag) {
822
+ function cardTime(value, flag, forms = `a time in milliseconds or a date: ${CARD_TIME_FORMS}`) {
819
823
  if (value === void 0) return void 0;
820
824
  const text = String(value).trim();
821
825
  const day = ISO_DAY.exec(text);
822
826
  const ms = /^\d+$/.test(text) ? milliseconds(text, flag) : Date.parse(day ? `${text}${day[1] ? "" : "-01"}T00:00` : text);
823
- if (!Number.isSafeInteger(ms) || ms <= 0) throw new CliError("usage", `--${flag} takes a time in milliseconds or a date: ${CARD_TIME_FORMS}, not ${JSON.stringify(value)}`);
827
+ if (!Number.isSafeInteger(ms) || ms <= 0) throw new CliError("usage", `--${flag} takes ${forms}, not ${JSON.stringify(value)}`);
824
828
  const written = writtenDay(text);
825
829
  if (written) {
826
830
  const [year, month, date] = written, days = new Date(Date.UTC(year, month, 0)).getUTCDate();
@@ -1110,7 +1114,7 @@ var commands$8 = {
1110
1114
  description: "Replace the three files when they are there"
1111
1115
  }
1112
1116
  },
1113
- run: async ({ options }, a) => (await import("./apps-kRsY9S2S.js")).initApp(a.dir, {
1117
+ run: async ({ options }, a) => (await import("./apps-DO_gAZgm.js")).initApp(a.dir, {
1114
1118
  name: options.name,
1115
1119
  title: options.title,
1116
1120
  force: options.force === true
@@ -1150,7 +1154,7 @@ var commands$8 = {
1150
1154
  description: "This version's sequence, higher than the bundle at --out's (default: one more than it)"
1151
1155
  }
1152
1156
  },
1153
- run: async ({ options }, a) => (await import("./apps-kRsY9S2S.js")).publishApp(a.dir, keyFile(options.key, "app publish <dir> --key <file> [--out <file>] [--sequence n]"), here(options.out), options.sequence)
1157
+ run: async ({ options }, a) => (await import("./apps-DO_gAZgm.js")).publishApp(a.dir, keyFile(options.key, "app publish <dir> --key <file> [--out <file>] [--sequence n]"), here(options.out), options.sequence)
1154
1158
  },
1155
1159
  "app revoke": {
1156
1160
  method: "app.revoke",
@@ -1183,7 +1187,7 @@ var commands$8 = {
1183
1187
  description: "Allow --up-to past the bundle's own sequence (versions published from elsewhere), and a --reason that looks like a seed, a key or ecash"
1184
1188
  }
1185
1189
  },
1186
- run: async ({ options }, a) => (await import("./apps-kRsY9S2S.js")).revokeApp(a.dir, keyFile(options.key, "app revoke <dir> --key <file> (--digest <digest>... | --up-to <sequence>) [--reason <text>] [--bundle <file>] [--force]"), {
1190
+ run: async ({ options }, a) => (await import("./apps-DO_gAZgm.js")).revokeApp(a.dir, keyFile(options.key, "app revoke <dir> --key <file> (--digest <digest>... | --up-to <sequence>) [--reason <text>] [--bundle <file>] [--force]"), {
1187
1191
  digests: options.digest,
1188
1192
  upTo: options["up-to"],
1189
1193
  reason: options.reason,
@@ -1242,9 +1246,9 @@ var commands$8 = {
1242
1246
  "app verify": {
1243
1247
  method: "app.verify",
1244
1248
  usage: "app verify <bundle|url>",
1245
- summary: "Check a .ghostlyapp as a client would, from a file or an https URL: its manifest and digest, or refused (exit 1) with the reason, revoked when the ghostly-revoke.json beside it revokes this version",
1249
+ summary: "Check a .ghostlyapp as a client would, from a file or an https URL: its manifest and digest, or refused (exit 1) with the reason, revoked when the ghostly-revoke.json beside it (for a URL, or beside one of its sources) revokes this version",
1246
1250
  args: ["bundle"],
1247
- run: async (_, a) => (await import("./apps-kRsY9S2S.js")).verifyApp(a.bundle)
1251
+ run: async (_, a) => (await import("./apps-DO_gAZgm.js")).verifyApp(a.bundle)
1248
1252
  },
1249
1253
  "store sign": {
1250
1254
  method: "store.sign",
@@ -1261,7 +1265,7 @@ var commands$8 = {
1261
1265
  description: "The folder to write ghostly-store.json and ghostly-store.sig in (default: the index's)"
1262
1266
  }
1263
1267
  },
1264
- run: async ({ options }, a) => (await import("./apps-kRsY9S2S.js")).signStore(a.index, keyFile(options.key, "store sign <index> --key <file> [--out <dir>]"), here(options.out))
1268
+ run: async ({ options }, a) => (await import("./apps-DO_gAZgm.js")).signStore(a.index, keyFile(options.key, "store sign <index> --key <file> [--out <dir>]"), here(options.out))
1265
1269
  }
1266
1270
  };
1267
1271
  //#endregion
@@ -2174,11 +2178,12 @@ var UNIT_MS = {
2174
2178
  /**
2175
2179
  * `status set --until`: a time to come, as long from now (30m, 2h, 1d) or as a card's time is written (milliseconds or a
2176
2180
  * date, local time when it names no zone), within a year. A time past is refused: the engine would take it as no status.
2181
+ * One it cannot read names the three forms, as its help does: `--until 2y` named only milliseconds and dates.
2177
2182
  */
2178
2183
  function statusUntil(value) {
2179
2184
  if (value === void 0) return void 0;
2180
2185
  const text = String(value).trim(), duration = DURATION.exec(text);
2181
- const ms = duration ? Date.now() + Number(duration[1]) * UNIT_MS[duration[2]] : cardTime(text, "until");
2186
+ const ms = duration ? Date.now() + Number(duration[1]) * UNIT_MS[duration[2]] : cardTime(text, "until", `30m, 2h or 1d from now (whole minutes, hours or days), milliseconds or a date: ${CARD_TIME_FORMS}`);
2182
2187
  if (duration && !(ms <= Date.now() + STATUS_CARD_LIMITS.nextRunMs)) throw new CliError("usage", `--until takes a time within a year from now, not ${JSON.stringify(value)}`);
2183
2188
  if (ms <= Date.now()) throw new CliError("usage", `--until takes a time to come, not ${JSON.stringify(value)}: a status that ended is none`);
2184
2189
  return ms;
@@ -2876,7 +2881,7 @@ var commands$1 = {
2876
2881
  options: {
2877
2882
  amount: {
2878
2883
  type: "number",
2879
- description: "Sats, for an address or LNURL"
2884
+ description: "Sats, for an address or LNURL; with an invoice, refuse it unless it asks exactly this"
2880
2885
  },
2881
2886
  network: net,
2882
2887
  "max-fee": {
@@ -3392,19 +3397,6 @@ function noMoreThan(count, values, usage) {
3392
3397
  if (values.length > count) throw new CliError("usage", `Too many arguments: ghostly ${usage}`);
3393
3398
  }
3394
3399
  //#endregion
3395
- //#region src/jsonOut.ts
3396
- /**
3397
- * What `JSON.stringify` leaves raw and a terminal may act on: DEL and the C1 controls (CSI, OSC, ST, NEL... in UTF-8),
3398
- * the line and paragraph separators, and the bidi marks, embeddings, overrides and isolates that reorder a line. Only
3399
- * a string holds them, and a peer writes some of those strings (a message's text), so the CLI's output writes them as
3400
- * `\uXXXX`: the same JSON value for every reader, nothing a terminal acts on. What is stored stays whole.
3401
- */
3402
- var RAW = /[\u007f-\u009f\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g;
3403
- /** `value` as the JSON the CLI prints: `JSON.stringify`, with `RAW` escaped. */
3404
- function jsonOut(value, space) {
3405
- return JSON.stringify(value, null, space)?.replace(RAW, (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, "0"));
3406
- }
3407
- //#endregion
3408
3400
  //#region src/listen.ts
3409
3401
  /** The cursor's own write failed, not the event's handling. */
3410
3402
  var CursorError = class extends Error {
@@ -3457,8 +3449,9 @@ var Allowlist = class {
3457
3449
  async function allowlist(from, groups, call, peerOf) {
3458
3450
  const chats = /* @__PURE__ */ new Set(), keys = /* @__PURE__ */ new Set(), groupIds = /* @__PURE__ */ new Set();
3459
3451
  for (const ref of from) {
3460
- if (CONTACT_KEY.test(ref)) {
3461
- keys.add(ref);
3452
+ const key = contactKeyOf(ref);
3453
+ if (key !== void 0) {
3454
+ keys.add(key);
3462
3455
  continue;
3463
3456
  }
3464
3457
  const chat = await otherFlag(call("chat.get", { chat: ref }), ref, "--from");
@@ -3493,7 +3486,7 @@ async function otherFlag(lookup, ref, flag) {
3493
3486
  var forMe = (message) => !!message.mentioned || !!message.press;
3494
3487
  /**
3495
3488
  * The turn an event starts, or null: only a contact's message, and a group message that mentions this profile or
3496
- * presses a button of its question.
3489
+ * presses a button of its question (or the `group.mentioned`, `button.pressed` that says so later).
3497
3490
  */
3498
3491
  function toTurn(event) {
3499
3492
  const message = event.message;
@@ -3507,6 +3500,10 @@ function toTurn(event) {
3507
3500
  group: event.group,
3508
3501
  ...message.member ? { member: message.member } : {}
3509
3502
  }, message);
3503
+ if (event.type === "button.pressed" && typeof event.group === "string" && message.press) return turn(event, "button.pressed", {
3504
+ group: event.group,
3505
+ ...message.member ? { member: message.member } : {}
3506
+ }, message);
3510
3507
  return null;
3511
3508
  }
3512
3509
  function turn(event, source, where, message) {
@@ -3547,13 +3544,16 @@ function turn(event, source, where, message) {
3547
3544
  }
3548
3545
  };
3549
3546
  }
3550
- /** Only loopback: events carry message text, and a webhook is a local bridge (WISP 1100 § Security). */
3551
- function checkWebhook(url) {
3547
+ /**
3548
+ * Only loopback: events carry message text, and a webhook is a local bridge (WISP 1100 § Security). `from` names where
3549
+ * the URL came from; what is not a URL is not repeated: a bridge's token is in it.
3550
+ */
3551
+ function checkWebhook(url, from = "--webhook") {
3552
3552
  let parsed;
3553
3553
  try {
3554
3554
  parsed = new URL(url);
3555
3555
  } catch {
3556
- throw new CliError("usage", `Not a URL: ${url}`);
3556
+ throw new CliError("usage", `${from} is not a URL`);
3557
3557
  }
3558
3558
  if (!["http:", "https:"].includes(parsed.protocol)) throw new CliError("usage", "The webhook must be http:// or https://");
3559
3559
  if (![
@@ -3561,7 +3561,7 @@ function checkWebhook(url) {
3561
3561
  "localhost",
3562
3562
  "[::1]"
3563
3563
  ].includes(parsed.hostname)) throw new CliError("usage", "The webhook must be on this machine (127.0.0.1, localhost or [::1])");
3564
- if (parsed.username || parsed.password) throw new CliError("usage", "The webhook URL takes no user or password: put the bridge's token in its path or query");
3564
+ if (parsed.username || parsed.password) throw new CliError("usage", "The webhook URL takes no user or password: put the bridge's token in its path or query, the URL in GHOSTLY_WEBHOOK");
3565
3565
  return parsed;
3566
3566
  }
3567
3567
  /**
@@ -4240,15 +4240,15 @@ var VERSION = package_default.version;
4240
4240
  * command a running daemon answers loads none of them, and starts about as fast as Node does. Statically imported, they
4241
4241
  * cost every command ~100 ms before its socket was opened.
4242
4242
  */
4243
- var engineApi = () => import("./api-B-52sVYp.js");
4244
- var engineHost = () => import("./host-BlUzZgQL.js");
4243
+ var engineApi = () => import("./api-CtXgscmK.js");
4244
+ var engineHost = () => import("./host-8RskzQgB.js");
4245
4245
  /**
4246
4246
  * `--translate <lang>`'s translator, or null (not asked; or the runtime is not there, said on stderr). Loaded only when
4247
4247
  * asked: the app's message parser it reads costs every other command nothing.
4248
4248
  */
4249
4249
  async function translatorFor(value, home) {
4250
4250
  if (value === void 0) return null;
4251
- const { loadDetector, openTranslator, translateTarget } = await import("./translate-kNopA04L.js");
4251
+ const { loadDetector, openTranslator, translateTarget } = await import("./translate-xLme9Rdh.js");
4252
4252
  return openTranslator({
4253
4253
  home,
4254
4254
  to: translateTarget(value),
@@ -4451,15 +4451,26 @@ var LOCAL_WRITES = /* @__PURE__ */ new Set([
4451
4451
  "status.set",
4452
4452
  "status.clear"
4453
4453
  ]);
4454
- /** Settings of this device only: no contact and no relay hears of them (nick, avatar and the relays' do). */
4454
+ /**
4455
+ * Settings of this device only: no contact and no relay hears of them (nick, avatar and the relays' do). A one-shot
4456
+ * says no presence (`daemonPresence`): only a daemon does, from its start or at once when it is the one that sets it.
4457
+ */
4455
4458
  var LOCAL_SETTINGS = /* @__PURE__ */ new Set([
4456
4459
  "sendTyping",
4457
4460
  "autoDownloads",
4458
- "serveFiles"
4461
+ "serveFiles",
4462
+ "daemonPresence"
4459
4463
  ]);
4460
- /** Whether a one-shot for this call opens the profile offline: a read, or a change that stays on this device. */
4464
+ /**
4465
+ * Said on a live session only (WISP 401 § Typing, WISP 902 · Group Mesh § Typing). A one-shot starts the chat or group
4466
+ * as it says it, so nothing is live yet and it reached nobody; online it then waited for the link's records on the
4467
+ * relays (3.4 s with a relay that takes 1.5 s, 10 s with one that does not answer). With `--for` it waits for the chat
4468
+ * to be live (`keepOneShot`), so that one stays online.
4469
+ */
4470
+ var LIVE_ONLY = /* @__PURE__ */ new Set(["chat.typing", "group.typing"]);
4471
+ /** Whether a one-shot for this call opens the profile offline: a read, a change that stays on this device, or typing. */
4461
4472
  function offlineCall(method, params) {
4462
- return readOnly(method, params) || LOCAL_WRITES.has(method);
4473
+ return readOnly(method, params) || LOCAL_WRITES.has(method) || LIVE_ONLY.has(method) && params.for === void 0;
4463
4474
  }
4464
4475
  /** How long a daemon gets to answer before a command gives up: a read is in memory (15 s); a call that waits for the
4465
4476
  * contact carries its own `--timeout` (or the daemon's default for it), plus a margin; anything else may take as long
@@ -4509,7 +4520,9 @@ function waitLeft(method, params, spentMs) {
4509
4520
  * (`endedUnanswered`): the daemon stopped or restarted under it. The read is asked once more there, through the daemon
4510
4521
  * that answers now or on the profile itself, and so is every call after it. It failed as a timeout told to check
4511
4522
  * `ghostly chat history` for a message that was never sent (exit 4), as "The daemon went away" (exit 1), or refused as
4512
- * a daemon of an older release (exit 1), while a command started a moment later answered.
4523
+ * a daemon of an older release (exit 1), while a command started a moment later answered. So is any call whose
4524
+ * connection ended before it was written (`endedUnsent`): nothing reached the daemon, and a bot's `typing` or `send`
4525
+ * that met a `daemon restart` failed as "The daemon went away" while the new daemon came up.
4513
4526
  */
4514
4527
  function throughDaemon(client, again) {
4515
4528
  const warned = warnVersion(client);
@@ -4528,13 +4541,13 @@ function throughDaemon(client, again) {
4528
4541
  try {
4529
4542
  return await first(m, p);
4530
4543
  } catch (error) {
4531
- const params = p ?? {};
4532
- if (!again || aborted || !endedUnanswered(error) || !(readOnly(m, params) || READ_WAITS.has(m))) throw error;
4544
+ const params = p ?? {}, read = readOnly(m, params) || READ_WAITS.has(m);
4545
+ if (!again || aborted || !endedUnanswered(error) || !(read || endedUnsent(error))) throw error;
4533
4546
  next ??= again();
4534
4547
  try {
4535
4548
  return await (await next).call(m, READ_WAITS.has(m) ? waitLeft(m, params, performance.now() - from) : p);
4536
4549
  } catch (failure) {
4537
- if (endedUnanswered(failure) && !isNotTheDaemon(failure)) throw new CliError("unavailable", `The daemon went away before it answered ${m}, twice; a read changes nothing: run it again`, { method: m });
4550
+ if (read && endedUnanswered(failure) && !isNotTheDaemon(failure)) throw new CliError("unavailable", `The daemon went away before it answered ${m}, twice; a read changes nothing: run it again`, { method: m });
4538
4551
  throw failure;
4539
4552
  }
4540
4553
  }
@@ -4562,29 +4575,47 @@ var HOLDER_WAIT_MS = 5e3;
4562
4575
  /** How long it waits for the profile's daemon that is starting (`startingDaemon`): its engine takes seconds on a large profile. */
4563
4576
  var STARTING_WAIT_MS = 3e4;
4564
4577
  /**
4578
+ * The longest a one-shot waits for the profile in all, while it passes from one process to the next (each holder is
4579
+ * waited for on its own, above): commands that keep taking it in turn do not keep this one waiting for ever.
4580
+ */
4581
+ var TURNS_WAIT_MS = 6e4;
4582
+ /**
4565
4583
  * Opens the profile in this process for a one-shot command. Another one that holds it (a script's `&`, a second
4566
4584
  * terminal) is waited for: both used to fail at once, and a backgrounded send was lost unless the script checked its
4567
- * exit code. One still holding it after HOLDER_WAIT_MS is answered with the next step. A daemon takes the profile before
4568
- * its socket listens (its engine starts in between, seconds on a large profile): once one answers there, the command
4585
+ * exit code. One still holding it after HOLDER_WAIT_MS is answered with the next step. Each process that takes the
4586
+ * profile in turn is waited for that long of its own, up to TURNS_WAIT_MS in all: counted from the first look, the
4587
+ * wait failed busy while the profile was only passing from one process to the next (the last of six reads started at
4588
+ * once, behind five others that each held it for a second on a busy machine). A daemon takes the profile before its
4589
+ * socket listens (its engine starts in between, seconds on a large profile): once one answers there, the command
4569
4590
  * goes through it, its client the answer. Only the lock was looked at again, and a command run while the daemon started
4570
4591
  * failed busy, told to start the daemon that was running. A daemon that marked its start is waited for up to
4571
- * STARTING_WAIT_MS, and named as the holder. A `listen` with no daemon opens it the same way, as the daemon (`mode`).
4592
+ * STARTING_WAIT_MS, and named as the holder. So is a profile a `daemon restart` or `daemon --detach` keeps for the daemon
4593
+ * it starts (`daemonClaim`): the commands that took the profile in turn in the gap kept that daemon from ever starting.
4594
+ * A `listen` with no daemon opens it the same way, as the daemon (`mode`).
4572
4595
  */
4573
4596
  async function openOneShot(g, options = {}, mode = "one-shot") {
4574
4597
  const { openHost } = await engineHost();
4575
4598
  const from = performance.now();
4599
+ let holder, since = from;
4576
4600
  for (;;) try {
4577
4601
  return await openHost(g.paths, mode, VERSION, options);
4578
4602
  } catch (error) {
4579
4603
  if (!(error instanceof CliError) || error.code !== "busy") throw error;
4580
- const starting = startingDaemon(g.paths);
4604
+ const starting = startingDaemon(g.paths), claimed = starting === null ? daemonClaim(g.paths) : null;
4581
4605
  const client = await connectDaemon(g.paths);
4582
4606
  if (client) return client;
4583
- const left = from + (starting === null ? HOLDER_WAIT_MS : STARTING_WAIT_MS) - performance.now();
4607
+ const pid = error.details?.pid;
4608
+ if (pid !== holder) {
4609
+ holder = pid;
4610
+ since = performance.now();
4611
+ }
4612
+ const now = performance.now();
4613
+ const left = Math.min(since + (starting === null && claimed === null ? HOLDER_WAIT_MS : STARTING_WAIT_MS), from + TURNS_WAIT_MS) - now;
4584
4614
  if (left <= 0) {
4585
- if (starting !== null) throw new CliError("busy", `Profile ${g.profile} is in use by its daemon (process ${starting}), which was still starting after ${STARTING_WAIT_MS / 1e3} s: ghostly daemon status shows when it is up`, { pid: starting });
4586
- const pid = error.details?.pid;
4587
- throw new CliError("busy", `Profile ${g.profile} is in use by ${pid ? `process ${pid}, another ghostly command,` : "another ghostly command"} and was not free after ${HOLDER_WAIT_MS / 1e3} s: run the commands one after another, or start \`ghostly daemon --detach\` so they can run at once`, error.details);
4615
+ if (claimed !== null) throw new CliError("busy", `Profile ${g.profile} is kept for the daemon that process ${claimed} (ghostly daemon) starts, still not up after ${Math.round((now - since) / 1e3)} s: ghostly daemon status shows when it is up`, { pid: claimed });
4616
+ if (starting !== null) throw new CliError("busy", `Profile ${g.profile} is in use by its daemon (process ${starting}), which was still starting after ${Math.round((now - since) / 1e3)} s: ghostly daemon status shows when it is up`, { pid: starting });
4617
+ const held = now - since >= HOLDER_WAIT_MS ? `was not free after ${HOLDER_WAIT_MS / 1e3} s` : `was taken by one process after another for ${TURNS_WAIT_MS / 1e3} s`;
4618
+ throw new CliError("busy", `Profile ${g.profile} is in use by ${pid ? `process ${pid}, another ghostly command,` : "another ghostly command"} and ${held}: run the commands one after another, or start \`ghostly daemon --detach\` so they can run at once`, error.details);
4588
4619
  }
4589
4620
  await new Promise((resolve) => setTimeout(resolve, Math.min(50 + Math.random() * 50, left)));
4590
4621
  }
@@ -4798,7 +4829,7 @@ var SPECIAL = [
4798
4829
  from: o("list", "Only this chat's events (id, a label given here or the contact's key; again for more)"),
4799
4830
  group: o("list", "Only this group's events (again for more); with --from or --group, nobody else's event gets through"),
4800
4831
  exec: o("string", "Run this command per event, the event as JSON on stdin"),
4801
- webhook: o("string", "POST each event to this URL"),
4832
+ webhook: o("string", "POST each event to this URL (else GHOSTLY_WEBHOOK, which ps does not show)"),
4802
4833
  print: o("boolean", "Print events too when --exec or --webhook handles them"),
4803
4834
  translate
4804
4835
  }
@@ -4810,7 +4841,7 @@ var SPECIAL = [
4810
4841
  ],
4811
4842
  [
4812
4843
  "settings set <key> <json-value> [--force]",
4813
- "Change one: relays, irohRelays, hyperdhtRelay, iceServers, publicProfiles, online, shareProfile, sendTyping, autoDownloads, serveFiles, nick. <json-value> - (or none, piped) reads it from stdin: a TURN password stays out of ps",
4844
+ "Change one: relays, irohRelays, hyperdhtRelay, iceServers, publicProfiles, online, shareProfile, sendTyping, autoDownloads, serveFiles, daemonPresence, nick. daemonPresence true: contacts see this profile online while a daemon runs it (off by default). <json-value> - (or none, piped) reads it from stdin: a TURN password stays out of ps",
4814
4845
  { force: o("boolean", "Set a nick even if it looks like a seed, a key or ecash") }
4815
4846
  ],
4816
4847
  [
@@ -4968,6 +4999,18 @@ function commandWords(usage) {
4968
4999
  return words;
4969
5000
  }
4970
5001
  /**
5002
+ * A command that takes no argument and is also a group (`status`, with `status set`; `daemon`, with `daemon stop`): a
5003
+ * word after it that names none of its commands is a typo of one (`status shwo`). Before, the line said "Too many
5004
+ * arguments: ghostly status" and `help status shwo` answered status's help with exit 0.
5005
+ */
5006
+ function groupWithNoArguments(usage) {
5007
+ const words = commandWords(usage);
5008
+ return !usage.split(" ").slice(words.length).some((word) => /^[<[](?!-)/.test(word)) && helpRows().some((row) => {
5009
+ const own = commandWords(row.usage);
5010
+ return own.length > words.length && words.every((word, i) => own[i] === word);
5011
+ });
5012
+ }
5013
+ /**
4971
5014
  * Help for one command (`ghostly help file send`, `ghostly file send --help`): its usage, what it does and its
4972
5015
  * options; for a group (`ghostly help file`), the group's commands.
4973
5016
  */
@@ -4984,7 +5027,7 @@ function commandHelp(words) {
4984
5027
  const asked = words.join(" ");
4985
5028
  if (!rows.length) throw unknownCommand(given[0], given[1], given[2]);
4986
5029
  const exact = rows.filter((row) => commandWords(row.usage).join(" ") === asked);
4987
- if (!exact.length && words.length < given.length) throw unknownCommand(given[0], given[1], given[2]);
5030
+ if (words.length < given.length && (!exact.length || exact.every((row) => groupWithNoArguments(row.usage)))) throw unknownCommand(given[0], given[1], given[2]);
4988
5031
  const lines = [];
4989
5032
  for (const row of exact) {
4990
5033
  lines.push(...columns === void 0 ? [`Usage: ghostly ${row.usage}`] : wrap("Usage: ghostly ", row.usage, columns, 4), "", ...paragraph([` ${row.summary}`], columns));
@@ -5172,14 +5215,15 @@ async function profileCommand(sub, argv) {
5172
5215
  if (!given || !name) throw new CliError("usage", `Missing <${given ? "new profile" : "file"}>: ghostly profile restore <file> <new profile> [--passphrase-file f] [--use]`);
5173
5216
  noMoreThan(2, parsed.positionals, "profile restore <file> <new profile> [--passphrase-file f] [--use]");
5174
5217
  const file = here(given);
5175
- const { backupFileProtection, restoreProfile } = await import("./backup-DBg388Ke.js");
5218
+ const { backupFileProtection, restoreProfile } = await import("./backup-D21x1f5P.js");
5176
5219
  const protection = await backupFileProtection(file);
5177
5220
  const paths = await restoreProfile(g.home, checkProfileName(name), file, protection === "none" ? void 0 : backupPassphrase(parsed.options["passphrase-file"], RESTORE_PASSPHRASE));
5178
5221
  if (parsed.options.use) selectProfile(g.home, name);
5179
5222
  print({
5180
5223
  restored: name,
5181
5224
  folder: paths.dir,
5182
- protection
5225
+ protection,
5226
+ current: currentProfile(g.home) === name
5183
5227
  });
5184
5228
  return;
5185
5229
  }
@@ -5359,32 +5403,14 @@ async function daemonCommand(argv) {
5359
5403
  }
5360
5404
  if (sub === "restart") {
5361
5405
  const stopFor = seconds(parsed, 20), startFor = seconds(parsed, 60);
5362
- const client = await connectDaemon(g.paths) ?? await startedDaemon(g, stopFor);
5363
- const probe = client ? client.call("status").catch(() => null) : null;
5364
- const ended = client ? await stopDaemon(g, client, stopFor) : null;
5365
- const stopped = ended?.pid ?? null;
5366
- if (ended?.listen) process.stderr.write(listenEnded(ended.pid));
5367
- const before = (await probe)?.version ?? null;
5368
- let started;
5406
+ requireProfile(g);
5407
+ ownProfile(g.paths.dir);
5408
+ const unclaim = claimForDaemon(g.paths);
5369
5409
  try {
5370
- started = await startDetached(g, startFor);
5371
- } catch (error) {
5372
- if (stopped === null || !(error instanceof CliError) || error.code === "timeout") throw error;
5373
- throw new CliError(error.code, `${error.message}. The daemon (process ${stopped}) was stopped: start it again with ghostly daemon --detach`, {
5374
- ...error.details,
5375
- stopped
5376
- });
5410
+ await restartDaemon(g, stopFor, startFor);
5411
+ } finally {
5412
+ unclaim();
5377
5413
  }
5378
- const older = restartWarning(before, VERSION);
5379
- if (older) process.stderr.write(older + "\n");
5380
- print({
5381
- restarted: true,
5382
- stopped,
5383
- ...ended?.listen && { listen: true },
5384
- before,
5385
- version: VERSION,
5386
- ...started
5387
- });
5388
5414
  return;
5389
5415
  }
5390
5416
  if (sub) throw unknownCommand("daemon", sub);
@@ -5395,6 +5421,35 @@ async function daemonCommand(argv) {
5395
5421
  }
5396
5422
  print(await startDetached(g, startFor));
5397
5423
  }
5424
+ /** `daemon restart`, while the profile is kept for the daemon it starts. */
5425
+ async function restartDaemon(g, stopFor, startFor) {
5426
+ const client = await connectDaemon(g.paths) ?? await startedDaemon(g, stopFor);
5427
+ const probe = client ? client.call("status").catch(() => null) : null;
5428
+ const ended = client ? await stopDaemon(g, client, stopFor) : null;
5429
+ const stopped = ended?.pid ?? null;
5430
+ if (ended?.listen) process.stderr.write(listenEnded(ended.pid));
5431
+ const before = (await probe)?.version ?? null;
5432
+ let started;
5433
+ try {
5434
+ started = await startDetached(g, startFor);
5435
+ } catch (error) {
5436
+ if (stopped === null || !(error instanceof CliError) || error.code === "timeout") throw error;
5437
+ throw new CliError(error.code, `${error.message}. The daemon (process ${stopped}) was stopped: start it again with ghostly daemon --detach`, {
5438
+ ...error.details,
5439
+ stopped
5440
+ });
5441
+ }
5442
+ const older = restartWarning(before, VERSION);
5443
+ if (older) process.stderr.write(older + "\n");
5444
+ print({
5445
+ restarted: true,
5446
+ stopped,
5447
+ ...ended?.listen && { listen: true },
5448
+ before,
5449
+ version: VERSION,
5450
+ ...started
5451
+ });
5452
+ }
5398
5453
  /**
5399
5454
  * The profile's daemon that is starting (`startingDaemon`: it holds the profile, its socket does not listen yet), once
5400
5455
  * its socket answers, waited for up to `seconds`; null when none is starting. One still starting then is the answer,
@@ -5498,18 +5553,23 @@ function processAlive(pid) {
5498
5553
  async function startDetached(g, seconds) {
5499
5554
  requireProfile(g);
5500
5555
  ownProfile(g.paths.dir);
5501
- const until = performance.now() + seconds * 1e3;
5502
- for (;;) {
5503
- if (await connectDaemon(g.paths)) throw new CliError("busy", `A daemon already runs profile ${g.profile}`);
5504
- if (lockOwner(g.paths) === null) {
5505
- const started = await spawnDaemon(g, until);
5506
- if (started) return started;
5507
- }
5508
- if (performance.now() >= until) {
5509
- heldBy(g);
5510
- throw new CliError("engine", `The daemon did not start; see ${g.paths.log}`);
5556
+ const unclaim = claimForDaemon(g.paths);
5557
+ try {
5558
+ const until = performance.now() + seconds * 1e3;
5559
+ for (;;) {
5560
+ if (await connectDaemon(g.paths)) throw new CliError("busy", `A daemon already runs profile ${g.profile}`);
5561
+ if (lockOwner(g.paths) === null) {
5562
+ const started = await spawnDaemon(g, until);
5563
+ if (started) return started;
5564
+ }
5565
+ if (performance.now() >= until) {
5566
+ heldBy(g);
5567
+ throw new CliError("engine", `The daemon did not start; see ${g.paths.log}`);
5568
+ }
5569
+ await new Promise((resolve) => setTimeout(resolve, Math.max(0, Math.min(100, until - performance.now()))));
5511
5570
  }
5512
- await new Promise((resolve) => setTimeout(resolve, Math.max(0, Math.min(100, until - performance.now()))));
5571
+ } finally {
5572
+ unclaim();
5513
5573
  }
5514
5574
  }
5515
5575
  /** `startDetached`'s child, or null when another process took the profile ahead of it and there is time to try again. */
@@ -5661,13 +5721,21 @@ async function listenCommand(argv) {
5661
5721
  noMoreThan(0, parsed.positionals, SPECIAL.find(([usage]) => usage.startsWith("listen "))[0]);
5662
5722
  const blank = (value) => typeof value === "string" && value.trim() === "";
5663
5723
  if (blank(parsed.options.webhook)) throw new CliError("usage", "--webhook needs a URL");
5724
+ const envWebhook = process.env.GHOSTLY_WEBHOOK;
5725
+ delete process.env.GHOSTLY_WEBHOOK;
5726
+ if (envWebhook !== void 0 && parsed.options.webhook !== void 0) throw new CliError("usage", "A webhook is set in GHOSTLY_WEBHOOK and --webhook was given: choose one");
5727
+ if (blank(envWebhook)) throw new CliError("usage", "GHOSTLY_WEBHOOK is empty: it holds the webhook's URL");
5728
+ const webhook = parsed.options.webhook ?? envWebhook;
5664
5729
  if (blank(parsed.options.exec)) throw new CliError("usage", "--exec needs a command");
5665
5730
  if (parsed.options.cursor === "") throw new CliError("usage", "--cursor needs a file");
5666
5731
  if (parsed.options.from?.some(blank)) throw new CliError("usage", "--from needs a chat or a contact key");
5667
5732
  if (parsed.options.group?.some(blank)) throw new CliError("usage", "--group needs a group");
5668
5733
  const g = globals(parsed);
5669
5734
  pretty = false;
5670
- if (parsed.options.webhook !== void 0) checkWebhook(String(parsed.options.webhook));
5735
+ if (webhook !== void 0) {
5736
+ const url = checkWebhook(webhook, envWebhook !== void 0 ? "GHOSTLY_WEBHOOK" : "--webhook");
5737
+ if (envWebhook === void 0 && (url.search || url.pathname !== "/")) process.stderr.write("ghostly: --webhook's URL shows in ps to every account on this machine while listen runs, a token in it too: give it in GHOSTLY_WEBHOOK instead\n");
5738
+ }
5671
5739
  const types = parsed.options.type ?? [];
5672
5740
  const turns = parsed.options.turns === true;
5673
5741
  if (turns && types.length) throw new CliError("usage", "--turns takes the place of --type: a turn is a message received, or a group message that mentions you");
@@ -5692,10 +5760,10 @@ async function listenCommand(argv) {
5692
5760
  turns,
5693
5761
  translate: translator?.event,
5694
5762
  exec: parsed.options.exec,
5695
- webhook: parsed.options.webhook,
5763
+ webhook,
5696
5764
  cursor,
5697
5765
  cursorFailed,
5698
- print: parsed.options.print === true || !parsed.options.exec && !parsed.options.webhook,
5766
+ print: parsed.options.print === true || !parsed.options.exec && !webhook,
5699
5767
  write: (line) => process.stdout.write(line + "\n"),
5700
5768
  drained: () => new Promise((resolve) => {
5701
5769
  const done = () => {
@@ -5737,8 +5805,7 @@ async function listenCommand(argv) {
5737
5805
  };
5738
5806
  onReaderGone(stop);
5739
5807
  await following.subscribed;
5740
- process.on("SIGINT", stop);
5741
- process.on("SIGTERM", stop);
5808
+ onStopSignals(stop);
5742
5809
  return;
5743
5810
  }
5744
5811
  const [{ keepServing, serve }, { callApi }] = await Promise.all([engineHost(), engineApi()]);
@@ -5938,7 +6005,7 @@ async function textCommand(name, argv) {
5938
6005
  };
5939
6006
  if (spec.target === "group") params.mentions = parsed.options.mention ?? [];
5940
6007
  if (parsed.options.reply !== void 0) params.reply = parsed.options.reply;
5941
- if (!spec.message) Object.assign(params, (await import("./buttons-4EKtQl-7.js")).buttonsOf(parsed.options));
6008
+ if (!spec.message) Object.assign(params, (await import("./buttons-D2l2bVCG.js")).buttonsOf(parsed.options));
5942
6009
  print(await withSession(g, (s) => {
5943
6010
  if (parsed.options.wait !== void 0) params.wait = parsed.options.wait;
5944
6011
  if (parsed.options.timeout !== void 0) params.timeout = parsed.options.timeout;
@@ -5982,7 +6049,7 @@ async function identityAddCommand(argv) {
5982
6049
  if (!provider) throw new CliError("usage", "Missing <provider>: ghostly identity add <provider> [subject] [--signer id] [--field name=value]... [--stdin] [--days n] [--timeout s]");
5983
6050
  inRange(parsed.options, "timeout", "a number of seconds", 5, 3600);
5984
6051
  const items = parsed.options.field ?? [];
5985
- const known = parsed.options.days !== void 0 || items.length ? (await import("./registry-Cc_PQb3k.js")).IDENTITY_PROVIDERS.find((p) => p.id === provider) : void 0;
6052
+ const known = parsed.options.days !== void 0 || items.length ? (await import("./registry-C734VrO9.js")).IDENTITY_PROVIDERS.find((p) => p.id === provider) : void 0;
5986
6053
  if (known && parsed.options.days !== void 0) inRange(parsed.options, "days", "a whole number", 1, known.validity.maxDays, true);
5987
6054
  const { fields, warning } = await identityFields(items, parsed.options.stdin === true, identitySecretFields(known, parsed.options.signer), readStdin, process.stdin.isTTY === true);
5988
6055
  if (warning) process.stderr.write(`ghostly: ${warning}\n`);
@@ -6093,7 +6160,7 @@ async function tableCommand(name, argv) {
6093
6160
  });
6094
6161
  if (translator) {
6095
6162
  try {
6096
- printAnswer(await (await import("./translate-kNopA04L.js")).translateAnswer(result, translator));
6163
+ printAnswer(await (await import("./translate-xLme9Rdh.js")).translateAnswer(result, translator));
6097
6164
  } finally {
6098
6165
  translator.close();
6099
6166
  }
@@ -6246,6 +6313,7 @@ async function main(input) {
6246
6313
  await textCommand(first, argv.slice(1));
6247
6314
  return 0;
6248
6315
  }
6316
+ if (table(first) && two && groupWithNoArguments(COMMANDS[first].usage)) throw unknownCommand(first, second);
6249
6317
  if (table(first)) {
6250
6318
  await tableCommand(first, argv.slice(1));
6251
6319
  return 0;
@@ -6319,4 +6387,4 @@ async function run(argv) {
6319
6387
  //#endregion
6320
6388
  export { run };
6321
6389
 
6322
- //# sourceMappingURL=main-vQjlgEnt.js.map
6390
+ //# sourceMappingURL=main-BC33ooYg.js.map