@ghostlytools/cli 1.4.4 → 1.5.0

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 (88) hide show
  1. package/README.md +14 -7
  2. package/dist/assets/{api-Cr5NjA-g.js → api-C_IHKsrl.js} +2 -2
  3. package/dist/assets/{api-N5IiCxB7.js → api-ClHM_G5A.js} +87 -60
  4. package/dist/assets/api-ClHM_G5A.js.map +1 -0
  5. package/dist/assets/{apiKit-BDB40JPK.js → apiKit-gS-yfb25.js} +2 -2
  6. package/dist/assets/{apiKit-BDB40JPK.js.map → apiKit-gS-yfb25.js.map} +1 -1
  7. package/dist/assets/{apps-Cf_TQYPs.js → apps-DP8pElH-.js} +2 -2
  8. package/dist/assets/{apps-Cf_TQYPs.js.map → apps-DP8pElH-.js.map} +1 -1
  9. package/dist/assets/{apps-C3H4yttJ.js → apps-DyihkNO-.js} +1 -1
  10. package/dist/assets/{arkade-DCovElLt.js → arkade-GzJoov-w.js} +2 -2
  11. package/dist/assets/{arkade-DCovElLt.js.map → arkade-GzJoov-w.js.map} +1 -1
  12. package/dist/assets/{backup-lrj6hQ3t.js → backup-A_C4hYNO.js} +1 -1
  13. package/dist/assets/{backup-Dnh7GFXh.js → backup-DKDXkaS1.js} +6 -6
  14. package/dist/assets/{backup-Dnh7GFXh.js.map → backup-DKDXkaS1.js.map} +1 -1
  15. package/dist/assets/{blobFiles-B0rNnHlO.js → blobFiles-1wUBd8ZD.js} +3 -3
  16. package/dist/assets/{blobFiles-B0rNnHlO.js.map → blobFiles-1wUBd8ZD.js.map} +1 -1
  17. package/dist/assets/{buttons-BCzrFo-d.js → buttons-BDw8cqDq.js} +3 -3
  18. package/dist/assets/{buttons-BCzrFo-d.js.map → buttons-BDw8cqDq.js.map} +1 -1
  19. package/dist/assets/buttons-CNkxiN2c.js +2 -0
  20. package/dist/assets/daemonProof-CWTVNUmr.js +254 -0
  21. package/dist/assets/daemonProof-CWTVNUmr.js.map +1 -0
  22. package/dist/assets/{envelope-BKSHUJnt.js → envelope-DEvU5FA9.js} +2 -2
  23. package/dist/assets/{envelope-BKSHUJnt.js.map → envelope-DEvU5FA9.js.map} +1 -1
  24. package/dist/assets/{fileBytes-B-fqGdEd.js → fileBytes-B8eTZfAT.js} +3 -3
  25. package/dist/assets/{fileBytes-B-fqGdEd.js.map → fileBytes-B8eTZfAT.js.map} +1 -1
  26. package/dist/assets/{fileBytes-C2jycN_7.js → fileBytes-gTd_8l-P.js} +1 -1
  27. package/dist/assets/{fileBytes-D6fqFQEX.js → fileBytes-uRqLyxa0.js} +2 -2
  28. package/dist/assets/{fileBytes-D6fqFQEX.js.map → fileBytes-uRqLyxa0.js.map} +1 -1
  29. package/dist/assets/{fileBytesIdb-_HnxdacI.js → fileBytesIdb-BIFKtgln.js} +3 -3
  30. package/dist/assets/{fileBytesIdb-_HnxdacI.js.map → fileBytesIdb-BIFKtgln.js.map} +1 -1
  31. package/dist/assets/fileBytesIdb-BVVr_rWX.js +2 -0
  32. package/dist/assets/{fileBytesOpfs-p_CANncD.js → fileBytesOpfs-ChrHcCVV.js} +3 -3
  33. package/dist/assets/{fileBytesOpfs-p_CANncD.js.map → fileBytesOpfs-ChrHcCVV.js.map} +1 -1
  34. package/dist/assets/{groupFiles-Dw0BA5-Z.js → groupFiles-Cr4Gj9-R.js} +49 -16
  35. package/dist/assets/groupFiles-Cr4Gj9-R.js.map +1 -0
  36. package/dist/assets/{host-BjTfNkxj.js → host-D0MIWyOe.js} +47 -129
  37. package/dist/assets/host-D0MIWyOe.js.map +1 -0
  38. package/dist/assets/{hyperdhtRelay-CmqjYDch.js → hyperdhtRelay-SBo4aoMk.js} +2 -2
  39. package/dist/assets/{hyperdhtRelay-CmqjYDch.js.map → hyperdhtRelay-SBo4aoMk.js.map} +1 -1
  40. package/dist/assets/{idb-CMVgtn2k.js → idb-BJARz3Qi.js} +5 -3
  41. package/dist/assets/idb-BJARz3Qi.js.map +1 -0
  42. package/dist/assets/{irohWeb-4Q4EdaCa.js → irohWeb-D2WaYPdN.js} +2 -2
  43. package/dist/assets/{irohWeb-4Q4EdaCa.js.map → irohWeb-D2WaYPdN.js.map} +1 -1
  44. package/dist/assets/{main-Dd5INTcu.js → main-DUG0nGLw.js} +279 -67
  45. package/dist/assets/main-DUG0nGLw.js.map +1 -0
  46. package/dist/assets/{mainline-o7bmeZsk.js → mainline-B8NGRodL.js} +79 -15
  47. package/dist/assets/mainline-B8NGRodL.js.map +1 -0
  48. package/dist/assets/{networkReason-ve6jyxIs.js → networkReason-BAnNO1Ji.js} +3 -3
  49. package/dist/assets/{networkReason-ve6jyxIs.js.map → networkReason-BAnNO1Ji.js.map} +1 -1
  50. package/dist/assets/{nwc-CL27LJx-.js → nwc-DQT3rx-s.js} +3 -3
  51. package/dist/assets/{nwc-CL27LJx-.js.map → nwc-DQT3rx-s.js.map} +1 -1
  52. package/dist/assets/{nwcProvider-CIlvpLT5.js → nwcProvider-Dq647EAl.js} +2 -2
  53. package/dist/assets/{nwcProvider-CIlvpLT5.js.map → nwcProvider-Dq647EAl.js.map} +1 -1
  54. package/dist/assets/{profiles-DSxPYdlU.js → profiles-BehWURA9.js} +18 -4
  55. package/dist/assets/profiles-BehWURA9.js.map +1 -0
  56. package/dist/assets/{registry-dG_Wm7fC.js → registry-DFiOxH5q.js} +1 -1
  57. package/dist/assets/{registry-CWJRfG2e.js → registry-ieI8INKT.js} +3 -3
  58. package/dist/assets/registry-ieI8INKT.js.map +1 -0
  59. package/dist/assets/{resolve-BDoQLkJR.js → resolve-C39pc4Kf.js} +2 -2
  60. package/dist/assets/{resolve-BDoQLkJR.js.map → resolve-C39pc4Kf.js.map} +1 -1
  61. package/dist/assets/{restoredRows-DeBImGRd.js → restoredRows-DGuKtIBz.js} +2 -2
  62. package/dist/assets/{restoredRows-DeBImGRd.js.map → restoredRows-DGuKtIBz.js.map} +1 -1
  63. package/dist/assets/{server-CYCzKx-R.js → server-DIICuvgy.js} +1150 -192
  64. package/dist/assets/server-DIICuvgy.js.map +1 -0
  65. package/dist/assets/{src-D1X4uVPW.js → src-CwMTZ5Hj.js} +864 -82
  66. package/dist/assets/src-CwMTZ5Hj.js.map +1 -0
  67. package/dist/assets/{usdt-Byi5OFic.js → usdt-CxSyuXq4.js} +3 -3
  68. package/dist/assets/{usdt-Byi5OFic.js.map → usdt-CxSyuXq4.js.map} +1 -1
  69. package/dist/assets/{turnRefs-BJeWWYlJ.js → words-31VaDW5h.js} +61 -3
  70. package/dist/assets/words-31VaDW5h.js.map +1 -0
  71. package/dist/ghostly.mjs +1 -1
  72. package/package.json +1 -1
  73. package/skills/ghostly/scripts/status +3 -2
  74. package/dist/assets/api-N5IiCxB7.js.map +0 -1
  75. package/dist/assets/buttons-B5dhQKnU.js +0 -2
  76. package/dist/assets/daemonProof-B53VnZ1Z.js +0 -100
  77. package/dist/assets/daemonProof-B53VnZ1Z.js.map +0 -1
  78. package/dist/assets/fileBytesIdb-DOxm_BKt.js +0 -2
  79. package/dist/assets/groupFiles-Dw0BA5-Z.js.map +0 -1
  80. package/dist/assets/host-BjTfNkxj.js.map +0 -1
  81. package/dist/assets/idb-CMVgtn2k.js.map +0 -1
  82. package/dist/assets/main-Dd5INTcu.js.map +0 -1
  83. package/dist/assets/mainline-o7bmeZsk.js.map +0 -1
  84. package/dist/assets/profiles-DSxPYdlU.js.map +0 -1
  85. package/dist/assets/registry-CWJRfG2e.js.map +0 -1
  86. package/dist/assets/server-CYCzKx-R.js.map +0 -1
  87. package/dist/assets/src-D1X4uVPW.js.map +0 -1
  88. package/dist/assets/turnRefs-BJeWWYlJ.js.map +0 -1
@@ -1,9 +1,9 @@
1
- import { Fa as ITEM_STATES, Ia as PR_CHECKS, La as PR_STATES, Ra as RUN_RESULTS, Ua as cardUrl, Un as GROUP_FILE_LIMITS, za as STATUS_CARD_LIMITS } from "./src-D1X4uVPW.js";
2
- import { a as ENGINE_PARAMS, c as SECRET_RESULTS, i as ENGINE_METHODS, o as ENGINE_READS, s as READ_PARAMS, t as turnRef } from "./turnRefs-BJeWWYlJ.js";
1
+ import { Ba as ITEM_STATES, Ga as STATUS_CARD_LIMITS, Ha as PR_STATES, Ka as TASK_STATUSES, Ua as ROUTINE_STATES, Un as GROUP_FILE_LIMITS, Va as PR_CHECKS, Wa as RUN_RESULTS, Xa as cardUrl, Ya as cardLine, za as CRON_LINE } from "./src-CwMTZ5Hj.js";
2
+ import { a as WALLET_TYPES, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, n as CHAT_METHODS, o as turnRef, p as SECRET_RESULTS, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-31VaDW5h.js";
3
3
  import { i as localFileError, n as EXIT, r as asCliError, t as CliError } from "./errors-BLSPp0tK.js";
4
- import { t as CONTACT_KEY } from "./apiKit-BDB40JPK.js";
5
- import { a as checkShownName, c as ghostlyHome, d as profileExists, f as profilePaths, i as checkProfileName, l as listProfiles, o as createProfile, p as selectProfile, s as currentProfile, u as lockOwner } from "./profiles-DSxPYdlU.js";
6
- import { a as provesDaemon, c as ownSocket, o as readDaemonSecret, r as newNonce, t as HELLO } from "./daemonProof-B53VnZ1Z.js";
4
+ import { t as CONTACT_KEY } from "./apiKit-gS-yfb25.js";
5
+ import { a as checkShownName, c as ghostlyHome, f as profileExists, h as userPath, i as checkProfileName, l as listProfiles, m as selectProfile, o as createProfile, p as profilePaths, s as currentProfile, u as lockOwner } from "./profiles-BehWURA9.js";
6
+ import { c as readDaemonSecret, g as isCallRate, i as newNonce, o as provesDaemon, s as provesGreeting, t as HELLO, u as CALL_RATES, v as ownSocket } from "./daemonProof-CWTVNUmr.js";
7
7
  import { accessSync, constants, existsSync, openSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
8
8
  import { dirname, resolve } from "node:path";
9
9
  import { spawn } from "node:child_process";
@@ -12,7 +12,7 @@ import { createInterface } from "node:readline";
12
12
  import { format } from "node:util";
13
13
  var package_default = {
14
14
  name: "@ghostlytools/cli",
15
- version: "1.4.4",
15
+ version: "1.5.0",
16
16
  type: "module",
17
17
  description: "Ghostly for bots and terminals: the app's own engine, headless on Node, behind a daemon and a `ghostly` command with JSON output.",
18
18
  license: "MIT",
@@ -177,7 +177,10 @@ function parseArgs(argv, spec, idSlot = () => false) {
177
177
  if (!Number.isFinite(number)) throw new CliError("usage", `--${name} takes a number, not ${JSON.stringify(value)}`);
178
178
  options[name] = number;
179
179
  } else if (option.type === "list") options[name] = [...options[name] ?? [], value];
180
- else options[name] = value;
180
+ else {
181
+ if (option.choices && !option.choices.includes(value)) throw new CliError("usage", `--${name} takes ${listed$1(option.choices)}, not ${JSON.stringify(value)}`);
182
+ options[name] = value;
183
+ }
181
184
  continue;
182
185
  }
183
186
  if (arg.startsWith("-") && arg !== "-") throw new CliError("usage", `Unknown option ${arg} (put -- before text that starts with a dash)`);
@@ -188,6 +191,8 @@ function parseArgs(argv, spec, idSlot = () => false) {
188
191
  options
189
192
  };
190
193
  }
194
+ /** Words as a sentence lists them: "a", "a or b", "a, b or c". */
195
+ var listed$1 = (words) => words.length > 1 ? `${words.slice(0, -1).join(", ")} or ${words.at(-1)}` : words[0];
191
196
  /** The global option a word names (`--profile`, `--profile=bot`, `-p`), else undefined. */
192
197
  function globalOption(arg) {
193
198
  const name = globalName(arg);
@@ -233,6 +238,11 @@ function liftGlobals(argv) {
233
238
  //#region src/client.ts
234
239
  /** The id of the hello on every connection: a string, so it is never one of the calls' numbers. */
235
240
  var HELLO_ID = "hello";
241
+ /**
242
+ * How long a client waits for the daemon's greeting before it refuses what answers: a daemon greets as it accepts the
243
+ * connection, and one of an older release (before the greeting) never does. `daemon stop` waits less (`connectDaemon`).
244
+ */
245
+ var GREETING_MS = 1e4;
236
246
  /** The refusal of a listener that did not prove it is the profile's daemon (`isNotTheDaemon` tells it apart). */
237
247
  function notTheDaemon(socket) {
238
248
  return new CliError("refused", `What answers on ${socket} did not prove it is this profile's daemon, so nothing was sent to it. A daemon of an older release cannot: \`ghostly daemon restart\` starts this one's`, { reason: "not-the-daemon" });
@@ -244,10 +254,12 @@ function isNotTheDaemon(error) {
244
254
  * A connection to a profile's daemon over its socket (WISP 1100 § Local control API). `null` from `connectDaemon`
245
255
  * means no daemon answers there: a one-shot command runs the profile itself.
246
256
  *
247
- * The first line on it is a `daemon.hello`, and no call is written until its answer proves the other end read the
248
- * profile's daemon secret (`daemonProof.ts`): until then every call waits, under its own deadline, and a listener
249
- * that does not prove it gets every call refused (`refused`, `isNotTheDaemon`) having read nothing but the hello.
250
- * Nothing it writes before that is read either.
257
+ * The client writes nothing on it until the daemon's greeting, its first line, proves the other end read the
258
+ * profile's daemon secret and holds the profile's lock (`provesGreeting`): a listener that cannot prove it has read
259
+ * nothing from this client, so it cannot impersonate it either (`daemonProof.ts`). Then the first line written is a
260
+ * `daemon.hello`, and no call is written until its answer proves the same over the client's own nonce. Until then
261
+ * every call waits, under its own deadline, and a listener that does not prove both gets every call refused
262
+ * (`refused`, `isNotTheDaemon`). Nothing it writes before that is read either.
251
263
  */
252
264
  var DaemonClient = class {
253
265
  socket;
@@ -258,11 +270,12 @@ var DaemonClient = class {
258
270
  closedListener = null;
259
271
  /** While paused: the events of the chunk already read, given to the listener on resume. */
260
272
  held = null;
273
+ greeted = false;
261
274
  verified = false;
262
275
  refusal = null;
263
276
  ready;
264
277
  settle;
265
- constructor(socket, address) {
278
+ constructor(socket, address, greetingMs = GREETING_MS) {
266
279
  this.socket = socket;
267
280
  this.address = address;
268
281
  this.ready = new Promise((resolve, reject) => {
@@ -273,18 +286,41 @@ var DaemonClient = class {
273
286
  });
274
287
  this.ready.catch(() => {});
275
288
  const nonce = newNonce();
276
- createInterface({
289
+ const waitedTooLong = setTimeout(() => {
290
+ if (!this.greeted && !this.refusal) this.refuse();
291
+ }, greetingMs);
292
+ waitedTooLong.unref?.();
293
+ const lines = createInterface({
277
294
  input: socket,
278
295
  crlfDelay: Infinity
279
- }).on("line", (line) => {
296
+ });
297
+ lines.on("error", () => {});
298
+ lines.on("line", (line) => {
280
299
  let message;
281
300
  try {
282
301
  message = JSON.parse(line);
283
302
  } catch {
284
303
  return;
285
304
  }
305
+ if (this.refusal) return;
306
+ if (!this.greeted) {
307
+ clearTimeout(waitedTooLong);
308
+ const secret = readDaemonSecret(this.address.dir);
309
+ if (!secret || !provesGreeting(secret, this.address.dir, message)) {
310
+ this.refuse();
311
+ return;
312
+ }
313
+ this.greeted = true;
314
+ if (socket.writableEnded || socket.destroyed) return;
315
+ socket.write(JSON.stringify({
316
+ id: HELLO_ID,
317
+ method: HELLO,
318
+ params: { nonce }
319
+ }) + "\n");
320
+ return;
321
+ }
286
322
  if (!this.verified) {
287
- if (this.refusal || message?.id !== HELLO_ID) return;
323
+ if (message?.id !== HELLO_ID) return;
288
324
  const secret = readDaemonSecret(this.address.dir);
289
325
  if (!message.error && secret && provesDaemon(secret, nonce, message.result)) {
290
326
  this.verified = true;
@@ -306,6 +342,7 @@ var DaemonClient = class {
306
342
  else waiting.resolve(message.result);
307
343
  });
308
344
  socket.on("close", () => {
345
+ clearTimeout(waitedTooLong);
309
346
  const why = this.refusal ?? new CliError("unavailable", "The daemon went away");
310
347
  if (!this.verified) this.settle.reject(why);
311
348
  for (const waiting of this.pending.values()) waiting.reject(why);
@@ -313,11 +350,6 @@ var DaemonClient = class {
313
350
  this.closedListener?.();
314
351
  });
315
352
  socket.on("error", () => {});
316
- socket.write(JSON.stringify({
317
- id: HELLO_ID,
318
- method: HELLO,
319
- params: { nonce }
320
- }) + "\n");
321
353
  }
322
354
  refuse() {
323
355
  this.refusal = notTheDaemon(this.address.socket);
@@ -402,10 +434,10 @@ var DaemonClient = class {
402
434
  }
403
435
  };
404
436
  /**
405
- * `timeoutMs` bounds the connect only. The client it gives has sent its hello; whether the listener is the daemon is
406
- * known at the first call (above).
437
+ * `timeoutMs` bounds the connect only; `greetingMs`, the wait for the daemon's greeting (above). The client it gives
438
+ * has written nothing yet; whether the listener is the daemon is known at the first call.
407
439
  */
408
- function connectDaemon(address, timeoutMs = 2e3) {
440
+ function connectDaemon(address, timeoutMs = 2e3, { greetingMs = GREETING_MS } = {}) {
409
441
  const path = address.socket;
410
442
  if (!ownSocket(path)) return Promise.resolve(null);
411
443
  return new Promise((resolve) => {
@@ -416,7 +448,7 @@ function connectDaemon(address, timeoutMs = 2e3) {
416
448
  }, timeoutMs);
417
449
  socket.once("connect", () => {
418
450
  clearTimeout(timer);
419
- resolve(new DaemonClient(socket, address));
451
+ resolve(new DaemonClient(socket, address, greetingMs));
420
452
  });
421
453
  socket.once("error", () => {
422
454
  clearTimeout(timer);
@@ -429,6 +461,11 @@ function connectDaemon(address, timeoutMs = 2e3) {
429
461
  var wait = {
430
462
  wait: {
431
463
  type: "string",
464
+ choices: [
465
+ "none",
466
+ "sent",
467
+ "delivered"
468
+ ],
432
469
  description: "none, sent or delivered (default: none with a daemon, sent without)"
433
470
  },
434
471
  timeout: {
@@ -440,6 +477,7 @@ var wait = {
440
477
  var groupWait = {
441
478
  wait: {
442
479
  type: "string",
480
+ choices: ["none", "sent"],
443
481
  description: "none or sent: until an edge took it (default none)"
444
482
  },
445
483
  timeout: {
@@ -449,6 +487,7 @@ var groupWait = {
449
487
  };
450
488
  var net = {
451
489
  type: "string",
490
+ choices: ["mainnet", "testnet"],
452
491
  description: "mainnet or testnet (default testnet)"
453
492
  };
454
493
  var card = {
@@ -465,11 +504,11 @@ var confirmReal = {
465
504
  };
466
505
  /**
467
506
  * A path as this command's working directory means it: the daemon runs elsewhere. "" (an unset variable in a script)
468
- * names no file, never the current folder.
507
+ * names no file, never the current folder; `~/…` is in the user's home (userPath).
469
508
  */
470
509
  function here(path) {
471
510
  if (path === "") throw new CliError("usage", "A path given as \"\" names no file");
472
- return typeof path === "string" ? resolve(path) : void 0;
511
+ return typeof path === "string" ? userPath(path) : void 0;
473
512
  }
474
513
  /**
475
514
  * A list option that names chats (`--to`, `--from`): "" or "group:" alone (an unset variable in a script) names
@@ -612,16 +651,40 @@ var cardOptions = {
612
651
  /** `--link label=https://…` or a bare link, as a card's links. */
613
652
  function cardLinks(values) {
614
653
  if (!Array.isArray(values) || !values.length) return void 0;
654
+ given("link", values, STATUS_CARD_LIMITS.links);
615
655
  return values.map((value) => {
616
656
  const eq = value.indexOf("=");
617
- return eq > 0 && !value.slice(0, eq).includes(":") ? {
657
+ const link = eq > 0 && !value.slice(0, eq).includes(":") ? {
618
658
  label: value.slice(0, eq),
619
659
  url: value.slice(eq + 1)
620
660
  } : { url: value };
661
+ if (!cardUrl(link.url)) throw new CliError("usage", `--link takes an https link of at most ${STATUS_CARD_LIMITS.url} characters, or label=link, not ${JSON.stringify(value)}`);
662
+ cardText("--link's label", link.label, STATUS_CARD_LIMITS.linkLabel, value);
663
+ return link;
621
664
  });
622
665
  }
623
666
  var listed = (words) => `${words.slice(0, -1).join(", ")} or ${words.at(-1)}`;
624
667
  /**
668
+ * A text flag as the card counts it (one line, the display rules): blank, or longer than `max`, is a usage error (exit 2)
669
+ * that names the flag. Before, it reached the card's own check and failed as `bad_request` (exit 1) in the card's words
670
+ * ("Status card: title is at most 120 characters"), the whole card in its details. `shown` is what the flag was given.
671
+ */
672
+ function cardText(flag, value, max, shown = value) {
673
+ if (value === void 0) return;
674
+ const line = cardLine(String(value), Infinity);
675
+ if (!line) throw new CliError("usage", `${flag} takes text, not ${JSON.stringify(shown)}`);
676
+ const length = [...line].length;
677
+ if (length > max) throw new CliError("usage", `${flag} takes at most ${max} characters, not ${length}`);
678
+ }
679
+ /** `--status`, `--state`, `--pr-state`, `--pr-checks`: one of their words, or a usage error that lists them. */
680
+ function oneWord(options, flag, words) {
681
+ if (options[flag] !== void 0 && !words.includes(options[flag])) throw new CliError("usage", `--${flag} takes ${listed(words)}, not ${JSON.stringify(options[flag])}`);
682
+ }
683
+ /** A flag given more times than the card holds: a usage error that says how many it takes. */
684
+ function given(flag, values, max) {
685
+ if (Array.isArray(values) && values.length > max) throw new CliError("usage", `--${flag} is given at most ${max} times, not ${values.length}`);
686
+ }
687
+ /**
625
688
  * `--item state:text` as a task's item. The word before the first colon is the state when it is one lowercase word (and
626
689
  * the colon does not start `://`): one of `ITEM_STATES`, or a usage error that lists them, so `queued:Publishing` is
627
690
  * refused rather than shown as that text. Anything else (`Step 2: build`, `Note: x`, a link, no colon) is the whole
@@ -630,14 +693,19 @@ var listed = (words) => `${words.slice(0, -1).join(", ")} or ${words.at(-1)}`;
630
693
  function itemOf(value) {
631
694
  const colon = value.indexOf(":");
632
695
  const word = colon > 0 ? value.slice(0, colon) : "";
633
- if (!/^[a-z]+$/.test(word) || value.startsWith("//", colon + 1)) return {
634
- state: "pending",
635
- text: value
636
- };
696
+ if (!/^[a-z]+$/.test(word) || value.startsWith("//", colon + 1)) {
697
+ cardText("--item's text", value, STATUS_CARD_LIMITS.line);
698
+ return {
699
+ state: "pending",
700
+ text: value
701
+ };
702
+ }
637
703
  if (!ITEM_STATES.includes(word)) throw new CliError("usage", `--item takes state:text, and ${JSON.stringify(word)} is not a state: use ${listed(ITEM_STATES)} (pending:<text> keeps a colon in the text), not ${JSON.stringify(value)}`);
704
+ const text = value.slice(colon + 1).trim();
705
+ cardText("--item's text", text, STATUS_CARD_LIMITS.line, value);
638
706
  return {
639
707
  state: word,
640
- text: value.slice(colon + 1).trim()
708
+ text
641
709
  };
642
710
  }
643
711
  /** `--progress`, `--left`: a percent, or a usage error that names the flag. */
@@ -665,6 +733,14 @@ function taskFields(options) {
665
733
  const set = (key, value) => {
666
734
  if (value !== void 0) fields[key] = value;
667
735
  };
736
+ cardText("--title", options.title, STATUS_CARD_LIMITS.title);
737
+ cardText("--step", options.step, STATUS_CARD_LIMITS.line);
738
+ cardText("--branch", options.branch, STATUS_CARD_LIMITS.branch);
739
+ for (const [flag, words] of [
740
+ ["status", TASK_STATUSES],
741
+ ["pr-state", PR_STATES],
742
+ ["pr-checks", PR_CHECKS]
743
+ ]) oneWord(options, flag, words);
668
744
  set("id", options.id);
669
745
  set("title", options.title);
670
746
  set("status", options.status);
@@ -681,16 +757,25 @@ function taskFields(options) {
681
757
  if (Number(match[2]) < 1 || Number(match[1]) > Number(match[2])) throw new CliError("usage", `--steps takes done/total with done at most total, like 2/5, not ${JSON.stringify(options.steps)}`);
682
758
  }
683
759
  if (options["pr-url"] !== void 0 && !cardUrl(options["pr-url"])) throw new CliError("usage", `--pr-url takes an https link of at most ${STATUS_CARD_LIMITS.url} characters, not ${JSON.stringify(options["pr-url"])}`);
684
- for (const [flag, words] of [["pr-state", PR_STATES], ["pr-checks", PR_CHECKS]]) if (options[flag] !== void 0 && !words.includes(options[flag])) throw new CliError("usage", `--${flag} takes ${listed(words)}, not ${JSON.stringify(options[flag])}`);
685
760
  const pr = {};
686
761
  for (const [flag, key] of PR_FLAGS) if (options[flag] !== void 0) pr[key] = options[flag];
687
762
  if (Object.keys(pr).length) fields.pr = {
688
763
  ...fields.pr && typeof fields.pr === "object" ? fields.pr : {},
689
764
  ...pr
690
765
  };
766
+ given("item", options.item, STATUS_CARD_LIMITS.items);
691
767
  if (Array.isArray(options.item) && options.item.length) fields.items = options.item.map(itemOf);
692
- if (Array.isArray(options.tag) && options.tag.length > STATUS_CARD_LIMITS.tags) throw new CliError("usage", `--tag is given at most ${STATUS_CARD_LIMITS.tags} times, not ${options.tag.length}`);
693
- if (Array.isArray(options.tag) && options.tag.length) fields.tags = options.tag;
768
+ given("tag", options.tag, STATUS_CARD_LIMITS.tags);
769
+ if (Array.isArray(options.tag) && options.tag.length) {
770
+ const seen = /* @__PURE__ */ new Set();
771
+ for (const tag of options.tag) {
772
+ cardText("--tag", tag, STATUS_CARD_LIMITS.tag);
773
+ const clean = cardLine(tag, Infinity);
774
+ if (seen.has(clean)) throw new CliError("usage", `--tag ${JSON.stringify(clean)} is given twice`);
775
+ seen.add(clean);
776
+ }
777
+ fields.tags = options.tag;
778
+ }
694
779
  set("parent", options.parent);
695
780
  const links = cardLinks(options.link);
696
781
  if (links) fields.links = links;
@@ -739,6 +824,7 @@ function runOf(value) {
739
824
  const text = String(value), colon = text.indexOf(":");
740
825
  const result = colon === -1 ? text : text.slice(0, colon), summary = colon === -1 ? "" : text.slice(colon + 1).trim();
741
826
  if (!RUN_RESULTS.includes(result)) throw new CliError("usage", `--run takes ok, failed or skipped, and :a summary after it if you like, not ${JSON.stringify(value)}`);
827
+ if (summary) cardText("--run's summary", summary, STATUS_CARD_LIMITS.line);
742
828
  return {
743
829
  result,
744
830
  ...summary && { summary }
@@ -747,6 +833,13 @@ function runOf(value) {
747
833
  /** A routine's fields from its flags; what was not given is left out. */
748
834
  function routineFields(options) {
749
835
  const fields = { ...cardJson(options.json) };
836
+ cardText("--name", options.name, STATUS_CARD_LIMITS.title);
837
+ cardText("--schedule", options.schedule, STATUS_CARD_LIMITS.schedule);
838
+ if (options.cron !== void 0 && !CRON_LINE.test(String(options.cron).trim())) {
839
+ const length = [...String(options.cron).trim()].length;
840
+ throw new CliError("usage", length > STATUS_CARD_LIMITS.cron ? `--cron takes at most ${STATUS_CARD_LIMITS.cron} characters, not ${length}` : `--cron takes a cron line of 0-9 A-Z a-z * , / ? # - and spaces, not ${JSON.stringify(options.cron)}`);
841
+ }
842
+ oneWord(options, "state", ROUTINE_STATES);
750
843
  for (const key of [
751
844
  "id",
752
845
  "name",
@@ -863,6 +956,8 @@ var taskOptions = {
863
956
  function usageWindowOf(value) {
864
957
  const match = /^([^=]+)=(\d+(?:\.\d+)?)(?:@(.+))?$/.exec(value.trim());
865
958
  if (!match) throw new CliError("usage", `--also takes window=percent or window=percent@time, like week=80@2026-10-10T00:00:00Z, not ${JSON.stringify(value)}`);
959
+ cardText("--also's window", match[1], STATUS_CARD_LIMITS.usageWindow, value);
960
+ if (Number(match[2]) > 100) throw new CliError("usage", `--also takes a percent from 0 to 100, not ${match[2]}`);
866
961
  const resetsAt = cardTime(match[3], "also");
867
962
  return {
868
963
  window: match[1].trim(),
@@ -875,6 +970,12 @@ function usageFields(options) {
875
970
  const fields = { ...cardJson(options.json) };
876
971
  percent(options, "left");
877
972
  if (options.left !== void 0 && (options.used !== void 0 || options.limit !== void 0)) throw new CliError("usage", "--left or --used with --limit, not both");
973
+ for (const [flag, max] of [
974
+ ["label", STATUS_CARD_LIMITS.usageLabel],
975
+ ["account", STATUS_CARD_LIMITS.usageLabel],
976
+ ["window", STATUS_CARD_LIMITS.usageWindow]
977
+ ]) cardText(`--${flag}`, options[flag], max);
978
+ given("also", options.also, STATUS_CARD_LIMITS.usageWindows);
878
979
  for (const key of [
879
980
  "id",
880
981
  "left",
@@ -991,7 +1092,7 @@ var commands$8 = {
991
1092
  description: "Replace the three files when they are there"
992
1093
  }
993
1094
  },
994
- run: async ({ options }, a) => (await import("./apps-C3H4yttJ.js")).initApp(a.dir, {
1095
+ run: async ({ options }, a) => (await import("./apps-DyihkNO-.js")).initApp(a.dir, {
995
1096
  name: options.name,
996
1097
  title: options.title,
997
1098
  force: options.force === true
@@ -1031,7 +1132,7 @@ var commands$8 = {
1031
1132
  description: "This version's sequence, higher than the bundle at --out's (default: one more than it)"
1032
1133
  }
1033
1134
  },
1034
- run: async ({ options }, a) => (await import("./apps-C3H4yttJ.js")).publishApp(a.dir, keyFile(options.key, "app publish <dir> --key <file> [--out <file>] [--sequence n]"), here(options.out), options.sequence)
1135
+ run: async ({ options }, a) => (await import("./apps-DyihkNO-.js")).publishApp(a.dir, keyFile(options.key, "app publish <dir> --key <file> [--out <file>] [--sequence n]"), here(options.out), options.sequence)
1035
1136
  },
1036
1137
  "app revoke": {
1037
1138
  method: "app.revoke",
@@ -1064,7 +1165,7 @@ var commands$8 = {
1064
1165
  description: "Allow --up-to past the bundle's own sequence (versions published from elsewhere)"
1065
1166
  }
1066
1167
  },
1067
- run: async ({ options }, a) => (await import("./apps-C3H4yttJ.js")).revokeApp(a.dir, keyFile(options.key, "app revoke <dir> --key <file> (--digest <digest>... | --up-to <sequence>) [--reason <text>]"), {
1168
+ run: async ({ options }, a) => (await import("./apps-DyihkNO-.js")).revokeApp(a.dir, keyFile(options.key, "app revoke <dir> --key <file> (--digest <digest>... | --up-to <sequence>) [--reason <text>]"), {
1068
1169
  digests: options.digest,
1069
1170
  upTo: options["up-to"],
1070
1171
  reason: options.reason,
@@ -1125,7 +1226,7 @@ var commands$8 = {
1125
1226
  usage: "app verify <bundle|url>",
1126
1227
  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",
1127
1228
  args: ["bundle"],
1128
- run: async (_, a) => (await import("./apps-C3H4yttJ.js")).verifyApp(a.bundle)
1229
+ run: async (_, a) => (await import("./apps-DyihkNO-.js")).verifyApp(a.bundle)
1129
1230
  },
1130
1231
  "store sign": {
1131
1232
  method: "store.sign",
@@ -1142,11 +1243,20 @@ var commands$8 = {
1142
1243
  description: "The folder to write ghostly-store.json and ghostly-store.sig in (default: the index's)"
1143
1244
  }
1144
1245
  },
1145
- run: async ({ options }, a) => (await import("./apps-C3H4yttJ.js")).signStore(a.index, keyFile(options.key, "store sign <index> --key <file> [--out <dir>]"), here(options.out))
1246
+ run: async ({ options }, a) => (await import("./apps-DyihkNO-.js")).signStore(a.index, keyFile(options.key, "store sign <index> --key <file> [--out <dir>]"), here(options.out))
1146
1247
  }
1147
1248
  };
1148
1249
  //#endregion
1149
1250
  //#region src/commands/calls.ts
1251
+ /**
1252
+ * `--rate`: one of the rates a call takes, or a usage error (exit 2) that names the flag before the profile opens.
1253
+ * Before, the API's own check answered it ("rate must be …", exit 1), and `call answer` only once a call rang.
1254
+ */
1255
+ function rateOf(options) {
1256
+ const value = options.rate;
1257
+ if (value !== void 0 && !isCallRate(value)) throw new CliError("usage", `--rate takes ${CALL_RATES.slice(0, -1).join(", ")} or ${CALL_RATES.at(-1)}, not ${JSON.stringify(value)}`);
1258
+ return value;
1259
+ }
1150
1260
  /** Voice calls: one entry per command, in alphabetical order (test/commands.test.ts checks). */
1151
1261
  var commands$7 = {
1152
1262
  "call answer": {
@@ -1157,7 +1267,7 @@ var commands$7 = {
1157
1267
  options: { rate },
1158
1268
  params: ({ options }, a) => ({
1159
1269
  call: a.call,
1160
- rate: options.rate
1270
+ rate: rateOf(options)
1161
1271
  })
1162
1272
  },
1163
1273
  "call auto": {
@@ -1180,7 +1290,7 @@ var commands$7 = {
1180
1290
  return a.mode === "on" ? {
1181
1291
  on: true,
1182
1292
  from: options.from,
1183
- rate: options.rate
1293
+ rate: rateOf(options)
1184
1294
  } : { on: false };
1185
1295
  }
1186
1296
  },
@@ -1211,7 +1321,7 @@ var commands$7 = {
1211
1321
  options: { rate },
1212
1322
  params: ({ options }, a) => ({
1213
1323
  chat: a.chat,
1214
- rate: options.rate
1324
+ rate: rateOf(options)
1215
1325
  })
1216
1326
  }
1217
1327
  };
@@ -1232,6 +1342,11 @@ var commands$6 = {
1232
1342
  options: {
1233
1343
  wait: {
1234
1344
  type: "string",
1345
+ choices: [
1346
+ "none",
1347
+ "sent",
1348
+ "delivered"
1349
+ ],
1235
1350
  description: "none, sent (a one-shot's default in a chat) or delivered; a group takes none or sent"
1236
1351
  },
1237
1352
  timeout: groupWait.timeout
@@ -1265,6 +1380,11 @@ var commands$6 = {
1265
1380
  force,
1266
1381
  wait: {
1267
1382
  type: "string",
1383
+ choices: [
1384
+ "none",
1385
+ "confirmed",
1386
+ "sent"
1387
+ ],
1268
1388
  description: "none (default), confirmed (a chat's contact took it) or sent (a group's edge took it)"
1269
1389
  },
1270
1390
  timeout: groupWait.timeout
@@ -1377,6 +1497,7 @@ var commands$6 = {
1377
1497
  usage: "chat transport <chat> <auto|dht|webrtc|iroh|hyperdht>",
1378
1498
  summary: "Choose what carries a chat",
1379
1499
  args: ["chat", "transport"],
1500
+ words: { transport: Object.keys(TRANSPORT_NAMES) },
1380
1501
  params: (_, a) => ({
1381
1502
  chat: a.chat,
1382
1503
  transport: a.transport
@@ -1407,6 +1528,11 @@ var commands$6 = {
1407
1528
  options: {
1408
1529
  until: {
1409
1530
  type: "string",
1531
+ choices: [
1532
+ "live",
1533
+ "text",
1534
+ "paired"
1535
+ ],
1410
1536
  description: "live (default), text or paired"
1411
1537
  },
1412
1538
  timeout: {
@@ -1436,6 +1562,7 @@ var commands$6 = {
1436
1562
  },
1437
1563
  wait: {
1438
1564
  type: "string",
1565
+ choices: ["none", "sent"],
1439
1566
  description: "none or sent: each text on its way (in a group, taken by an edge), each file's transfer done (default none)"
1440
1567
  },
1441
1568
  timeout: groupWait.timeout
@@ -1479,12 +1606,17 @@ var commands$6 = {
1479
1606
  },
1480
1607
  "message delete": {
1481
1608
  method: "chat.delete",
1482
- usage: "message delete <chat> <message>",
1483
- summary: "Forget a message on this device (the contact keeps theirs)",
1609
+ usage: "message delete <chat|group> <message> [--everyone]",
1610
+ summary: "Forget a message on this device (the contact keeps theirs); --everyone deletes one of yours, in a chat or a group, from every member's device",
1484
1611
  args: ["chat", "message"],
1485
- params: (_, a) => ({
1612
+ options: { everyone: {
1613
+ type: "boolean",
1614
+ description: "Delete a message of yours for everyone (a chat or a group)"
1615
+ } },
1616
+ params: ({ options }, a) => ({
1486
1617
  chat: a.chat,
1487
- message: a.message
1618
+ message: a.message,
1619
+ everyone: options.everyone === true
1488
1620
  })
1489
1621
  },
1490
1622
  "message details": {
@@ -1579,6 +1711,11 @@ var commands$6 = {
1579
1711
  ...routineOptions,
1580
1712
  wait: {
1581
1713
  type: "string",
1714
+ choices: [
1715
+ "none",
1716
+ "confirmed",
1717
+ "sent"
1718
+ ],
1582
1719
  description: "none (default), confirmed (a chat's contact took it) or sent (a group's edge took it)"
1583
1720
  },
1584
1721
  timeout: groupWait.timeout
@@ -1594,6 +1731,31 @@ var commands$6 = {
1594
1731
  timeout: options.timeout
1595
1732
  })
1596
1733
  },
1734
+ "saved add": {
1735
+ method: "saved.add",
1736
+ usage: "saved add <chat|group> <message>",
1737
+ summary: "Save a message on this device, to find it again in `saved list` (nothing is sent)",
1738
+ args: ["chat", "message"],
1739
+ params: (_, a) => ({
1740
+ chat: a.chat,
1741
+ message: a.message
1742
+ })
1743
+ },
1744
+ "saved list": {
1745
+ method: "saved.list",
1746
+ usage: "saved list",
1747
+ summary: "Saved messages of every chat and group, the last saved first"
1748
+ },
1749
+ "saved remove": {
1750
+ method: "saved.remove",
1751
+ usage: "saved remove <chat|group> <message>",
1752
+ summary: "Unsave a message",
1753
+ args: ["chat", "message"],
1754
+ params: (_, a) => ({
1755
+ chat: a.chat,
1756
+ message: a.message
1757
+ })
1758
+ },
1597
1759
  "task send": {
1598
1760
  method: "task.send",
1599
1761
  usage: "task send <chat|group> --title <title> [--status s] [--progress n | --steps a/b] [--step \"...\"] [--item state:text]... [--pr-url url --pr-number n --additions n --deletions n --files n --pr-state s --pr-checks c] [--branch b] [--tag label]... [--parent task] [--link url]... [--id id] [--json json|-|file] [--force] [--wait none|sent|delivered] [--timeout s]",
@@ -1626,6 +1788,11 @@ var commands$6 = {
1626
1788
  ...taskOptions,
1627
1789
  wait: {
1628
1790
  type: "string",
1791
+ choices: [
1792
+ "none",
1793
+ "confirmed",
1794
+ "sent"
1795
+ ],
1629
1796
  description: "none (default), confirmed (a chat's contact took it) or sent (a group's edge took it)"
1630
1797
  },
1631
1798
  timeout: groupWait.timeout
@@ -2349,6 +2516,7 @@ var commands$1 = {
2349
2516
  usage: "chat accept <chat> <method> [--off] [--networks mainnet,testnet]",
2350
2517
  summary: "Which ways of paying a chat takes",
2351
2518
  args: ["chat", "method"],
2519
+ words: { method: CHAT_METHODS },
2352
2520
  options: {
2353
2521
  off: {
2354
2522
  type: "boolean",
@@ -2394,6 +2562,7 @@ var commands$1 = {
2394
2562
  options: {
2395
2563
  via: {
2396
2564
  type: "string",
2565
+ choices: ["lightning"],
2397
2566
  description: "lightning: pay its invoice instead of ecash"
2398
2567
  },
2399
2568
  "max-fee": {
@@ -2425,6 +2594,7 @@ var commands$1 = {
2425
2594
  },
2426
2595
  rail: {
2427
2596
  type: "string",
2597
+ choices: ["cashu", "lightning"],
2428
2598
  description: "cashu or lightning"
2429
2599
  },
2430
2600
  network: net,
@@ -2543,6 +2713,7 @@ var commands$1 = {
2543
2713
  usage: "wallet address <bitcoin|arkade|spark|usdt> [--network testnet]",
2544
2714
  summary: "An address to be paid on",
2545
2715
  args: ["type"],
2716
+ words: { type: ADDRESS_TYPES },
2546
2717
  options: { network: net },
2547
2718
  params: ({ options }, { type }) => ({
2548
2719
  type,
@@ -2554,6 +2725,7 @@ var commands$1 = {
2554
2725
  usage: "wallet create <type> [--network testnet] [--provider <id>] [--value name=value]... [--stdin] [--invite <code>] [--api-key <key>]",
2555
2726
  summary: "A wallet: cashu, lightning, arkade, spark, bitcoin, fedimint, usdt (bark: app only)",
2556
2727
  args: ["type"],
2728
+ words: { type: WALLET_TYPES },
2557
2729
  options: {
2558
2730
  network: net,
2559
2731
  provider: {
@@ -2592,6 +2764,7 @@ var commands$1 = {
2592
2764
  usage: "wallet faucet <type> [--card <id>]",
2593
2765
  summary: "Test coins from a Testnet wallet's faucet",
2594
2766
  args: ["type"],
2767
+ words: { type: WALLET_TYPES },
2595
2768
  options: { card },
2596
2769
  params: ({ options }, { type }) => ({
2597
2770
  type,
@@ -2649,6 +2822,7 @@ var commands$1 = {
2649
2822
  usage: "wallet remove <type> [--network testnet] [--card <id>] [--accept-loss]",
2650
2823
  summary: "Remove a wallet; refused while it holds money or waits for some, unless --accept-loss",
2651
2824
  args: ["type"],
2825
+ words: { type: WALLET_TYPES },
2652
2826
  options: {
2653
2827
  network: net,
2654
2828
  card,
@@ -2813,6 +2987,7 @@ var TEXT_COMMANDS = {
2813
2987
  force,
2814
2988
  wait: {
2815
2989
  type: "string",
2990
+ choices: ["none", "confirmed"],
2816
2991
  description: "none or confirmed (default: none with a daemon, confirmed without)"
2817
2992
  },
2818
2993
  timeout: wait.timeout
@@ -2922,6 +3097,7 @@ function usageNames(usage) {
2922
3097
  * unset variable in a script), before the profile opens. A leading `name?` is optional: it is given only when every
2923
3098
  * required one is there too (`file accept [<chat>] <file>`). A trailing `name...` takes the rest and needs at least
2924
3099
  * one word that is not ""; `name...?` may take none (text from stdin, `chat rename`'s name back to the contact's).
3100
+ * One that takes a few words (`words`) is refused any other the same way, named as the usage shows it (`<type>`).
2925
3101
  */
2926
3102
  function positionals(command, values) {
2927
3103
  let names = command.args ?? [];
@@ -2943,6 +3119,11 @@ function positionals(command, values) {
2943
3119
  return out;
2944
3120
  }
2945
3121
  if (values[i] === void 0 || values[i] === "") throw missing(i, name);
3122
+ const words = command.words?.[name];
3123
+ if (words && !words.includes(values[i])) {
3124
+ const placeholder = shown[i + skip] && !shown[i + skip].includes("|") ? shown[i + skip] : name;
3125
+ throw new CliError("usage", `<${placeholder}> takes ${listed(words)}, not ${JSON.stringify(values[i])}`);
3126
+ }
2946
3127
  out[name] = values[i];
2947
3128
  }
2948
3129
  noMoreThan(names.length, values, command.usage);
@@ -3419,7 +3600,7 @@ var JOINS = {
3419
3600
  }
3420
3601
  };
3421
3602
  /**
3422
- * A join given no invite reads stdin, but a pipe nobody writes or closes (what Node's exec and most harnesses give a
3603
+ * A join given no invite, a redeem given no token and a send given no text read stdin, but a pipe nobody writes or closes (what Node's exec and most harnesses give a
3423
3604
  * child) would hold it for ever without a word: a note once nothing has come for a while, the usage error once nothing
3424
3605
  * has come at all. A producer that started writing is waited for to the end; `-` asked for stdin and waits as long.
3425
3606
  */
@@ -3431,7 +3612,12 @@ async function secretsFromStdin(method, params, read, tty = false, note = () =>
3431
3612
  if (params.token !== void 0) return warning("A token");
3432
3613
  const missing = () => new CliError("usage", "Missing <cashu-token>: give it as an argument or on stdin (… | ghostly wallet redeem)");
3433
3614
  if (tty) throw missing();
3434
- const token = (await read()).trim();
3615
+ const token = (await readUnasked(read, note, {
3616
+ what: "a Cashu token",
3617
+ missing: "Missing <cashu-token>",
3618
+ command: "wallet redeem",
3619
+ as: "an argument"
3620
+ })).trim();
3435
3621
  if (!token) throw missing();
3436
3622
  params.token = token;
3437
3623
  return;
@@ -3441,7 +3627,12 @@ async function secretsFromStdin(method, params, read, tty = false, note = () =>
3441
3627
  if (params[join.param] !== void 0 && params[join.param] !== "-") return warning(join.what);
3442
3628
  const missing = () => new CliError("usage", `Missing ${join.arg}: give it on stdin (… | ghostly ${join.command}) or as an argument`);
3443
3629
  if (tty) throw missing();
3444
- const value = (params[join.param] === "-" ? await read() : await readUnasked(read, note, join)).trim();
3630
+ const value = (params[join.param] === "-" ? await read() : await readUnasked(read, note, {
3631
+ what: join.what.toLowerCase(),
3632
+ missing: `Missing ${join.arg}`,
3633
+ command: join.command,
3634
+ as: "an argument"
3635
+ })).trim();
3445
3636
  if (!value) throw missing();
3446
3637
  params[join.param] = value;
3447
3638
  return;
@@ -3464,15 +3655,27 @@ async function secretsFromStdin(method, params, read, tty = false, note = () =>
3464
3655
  return onLine ? warning("An API key") : void 0;
3465
3656
  }
3466
3657
  }
3467
- async function readUnasked(read, note, join) {
3658
+ /**
3659
+ * `send`, `edit`, `group send` and `group edit` with no text words read it from stdin the same way: `command` is the
3660
+ * command line as given (`send bob`). `asked`: `--stdin`, which waits as long as it takes.
3661
+ */
3662
+ async function textFromStdin(read, command, asked, note) {
3663
+ return (asked ? await read() : await readUnasked(read, note, {
3664
+ what: "the text",
3665
+ missing: "No text",
3666
+ command,
3667
+ as: "arguments"
3668
+ })).replace(/\n$/, "");
3669
+ }
3670
+ async function readUnasked(read, note, ask) {
3468
3671
  let noteTimer, giveUpTimer;
3469
3672
  const stop = () => {
3470
3673
  clearTimeout(noteTimer);
3471
3674
  clearTimeout(giveUpTimer);
3472
3675
  };
3473
3676
  const nothingCame = new Promise((_, reject) => {
3474
- noteTimer = setTimeout(() => note(`Waiting for ${join.what.toLowerCase()} on stdin (… | ghostly ${join.command}): give it there or as an argument`), STDIN_NOTE_MS);
3475
- giveUpTimer = setTimeout(() => reject(new CliError("usage", `Missing ${join.arg}: nothing came on stdin in ${STDIN_GIVE_UP_MS / 1e3} s; give it there (… | ghostly ${join.command}) or as an argument`)), STDIN_GIVE_UP_MS);
3677
+ noteTimer = setTimeout(() => note(`Waiting for ${ask.what} on stdin (… | ghostly ${ask.command}): give it there or as ${ask.as}`), STDIN_NOTE_MS);
3678
+ giveUpTimer = setTimeout(() => reject(new CliError("usage", `${ask.missing}: nothing came on stdin in ${STDIN_GIVE_UP_MS / 1e3} s; give it there (… | ghostly ${ask.command}) or as ${ask.as}`)), STDIN_GIVE_UP_MS);
3476
3679
  });
3477
3680
  try {
3478
3681
  return await Promise.race([read(stop), nothingCame]);
@@ -3500,8 +3703,8 @@ var VERSION = package_default.version;
3500
3703
  * command a running daemon answers loads none of them, and starts about as fast as Node does. Statically imported, they
3501
3704
  * cost every command ~100 ms before its socket was opened.
3502
3705
  */
3503
- var engineApi = () => import("./api-Cr5NjA-g.js");
3504
- var engineHost = () => import("./host-BjTfNkxj.js");
3706
+ var engineApi = () => import("./api-C_IHKsrl.js");
3707
+ var engineHost = () => import("./host-D0MIWyOe.js");
3505
3708
  var pretty = false;
3506
3709
  function print(value) {
3507
3710
  process.stdout.write(JSON.stringify(value, null, pretty ? 2 : void 0) + "\n");
@@ -3593,7 +3796,8 @@ var READS = /* @__PURE__ */ new Set([
3593
3796
  "service.peer",
3594
3797
  "call.list",
3595
3798
  "app.served",
3596
- "x401.credential.list"
3799
+ "x401.credential.list",
3800
+ "saved.list"
3597
3801
  ]);
3598
3802
  /** Whether a one-shot for this call opens the profile offline; test/readOnlyCommands.test.ts names every table command. */
3599
3803
  function readOnly(method, params) {
@@ -3603,7 +3807,7 @@ function readOnly(method, params) {
3603
3807
  }
3604
3808
  /**
3605
3809
  * Calls whose change stays on this device: a chat's name here, a chat removed (nothing goes to the contact), auto-answer
3606
- * (calls.json), a proof dropped, a web app added (shared with no one yet), an x401 key or credential (WISP 3xx: never
3810
+ * (calls.json), a proof dropped, a web app added (shared with no one yet), a message saved or unsaved, an x401 key or credential (WISP 3xx: never
3607
3811
  * shared with a contact). Opened online, each put the profile's records on the relays and waited for them (6 PUT + 4
3608
3812
  * GET, 3.3 s with a relay that takes 1.5 s), and the contacts' apps saw this device come online. `message delete` stays
3609
3813
  * online: it settles a file offer already on the DHT.
@@ -3616,7 +3820,9 @@ var LOCAL_WRITES = /* @__PURE__ */ new Set([
3616
3820
  "service.add",
3617
3821
  "x401.key.new",
3618
3822
  "x401.credential.add",
3619
- "x401.credential.remove"
3823
+ "x401.credential.remove",
3824
+ "saved.add",
3825
+ "saved.remove"
3620
3826
  ]);
3621
3827
  /** Settings of this device only: no contact and no relay hears of them (nick, avatar and the relays' do). */
3622
3828
  var LOCAL_SETTINGS = /* @__PURE__ */ new Set([
@@ -4072,10 +4278,11 @@ async function profileCommand(sub, argv) {
4072
4278
  return;
4073
4279
  }
4074
4280
  case "restore": {
4075
- const [file, name] = parsed.positionals;
4076
- if (!file || !name) throw new CliError("usage", "ghostly profile restore <file> <new profile> [--passphrase-file f] [--use]");
4281
+ const [given, name] = parsed.positionals;
4282
+ if (!given || !name) throw new CliError("usage", "ghostly profile restore <file> <new profile> [--passphrase-file f] [--use]");
4077
4283
  noMoreThan(2, parsed.positionals, "profile restore <file> <new profile> [--passphrase-file f] [--use]");
4078
- const { backupFileProtection, restoreProfile } = await import("./backup-lrj6hQ3t.js");
4284
+ const file = here(given);
4285
+ const { backupFileProtection, restoreProfile } = await import("./backup-A_C4hYNO.js");
4079
4286
  const protection = await backupFileProtection(file);
4080
4287
  const paths = await restoreProfile(g.home, checkProfileName(name), file, protection === "none" ? void 0 : backupPassphrase(parsed.options["passphrase-file"], RESTORE_PASSPHRASE));
4081
4288
  if (parsed.options.use) selectProfile(g.home, name);
@@ -4167,6 +4374,11 @@ async function runDaemon(g) {
4167
4374
  lastSeq: host.ctx.hub.lastSeq
4168
4375
  });
4169
4376
  }
4377
+ /**
4378
+ * `daemon stop` and `restart` wait this long for the daemon's greeting: a daemon of an older release never greets, and
4379
+ * what does not prove itself is stopped as the process that holds the profile (`stopDaemon`), as the stop asked.
4380
+ */
4381
+ var STOP_GREETING_MS = 2e3;
4170
4382
  async function daemonCommand(argv) {
4171
4383
  const sub = argv[0] && !argv[0].startsWith("-") ? argv[0] : void 0;
4172
4384
  const parsed = parseArgs(sub ? argv.slice(1) : argv, {
@@ -4211,7 +4423,7 @@ async function daemonCommand(argv) {
4211
4423
  if (sub === "stop") {
4212
4424
  knownProfile(g);
4213
4425
  const stopFor = seconds(parsed, 20);
4214
- const client = await connectDaemon(g.paths);
4426
+ const client = await connectDaemon(g.paths, void 0, { greetingMs: STOP_GREETING_MS });
4215
4427
  if (!client) throw new CliError("not_found", `No daemon runs profile ${g.profile}`);
4216
4428
  print({
4217
4429
  stopped: true,
@@ -4221,7 +4433,7 @@ async function daemonCommand(argv) {
4221
4433
  }
4222
4434
  if (sub === "restart") {
4223
4435
  const stopFor = seconds(parsed, 20), startFor = seconds(parsed, 60);
4224
- const client = await connectDaemon(g.paths);
4436
+ const client = await connectDaemon(g.paths, void 0, { greetingMs: STOP_GREETING_MS });
4225
4437
  const probe = client ? client.call("status").catch(() => null) : null;
4226
4438
  print({
4227
4439
  restarted: true,
@@ -4427,7 +4639,7 @@ async function listenCommand(argv) {
4427
4639
  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");
4428
4640
  checkTypes(types, (line) => process.stderr.write(line + "\n"));
4429
4641
  const from = parsed.options.from ?? [], groups = parsed.options.group ?? [];
4430
- const cursor = parsed.options.cursor;
4642
+ const cursor = here(parsed.options.cursor);
4431
4643
  checkCursor(cursor);
4432
4644
  const since = parsed.options.since ?? readCursor(cursor);
4433
4645
  const start = async (call, peerOf) => {
@@ -4632,7 +4844,7 @@ async function textCommand(name, argv) {
4632
4844
  text = String(parsed.options.text);
4633
4845
  } else if (parsed.options.stdin || words.length === 0 && !process.stdin.isTTY) {
4634
4846
  if (text) throw new CliError("usage", "Give the text as arguments or on stdin, not both");
4635
- text = (await readStdin()).replace(/\n$/, "");
4847
+ text = await textFromStdin(readStdin, [name, ...[target, ...message !== void 0 ? [message] : []].map((word) => /^[\w@.:+-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`)].join(" "), parsed.options.stdin === true, (note) => process.stderr.write(`ghostly: ${note}\n`));
4636
4848
  }
4637
4849
  if (!text.trim()) throw new CliError("usage", `No text: ghostly ${spec.usage}`);
4638
4850
  const params = {
@@ -4643,7 +4855,7 @@ async function textCommand(name, argv) {
4643
4855
  };
4644
4856
  if (spec.target === "group") params.mentions = parsed.options.mention ?? [];
4645
4857
  if (parsed.options.reply !== void 0) params.reply = parsed.options.reply;
4646
- if (!spec.message) Object.assign(params, (await import("./buttons-B5dhQKnU.js")).buttonsOf(parsed.options));
4858
+ if (!spec.message) Object.assign(params, (await import("./buttons-CNkxiN2c.js")).buttonsOf(parsed.options));
4647
4859
  print(await withSession(g, (s) => {
4648
4860
  if (spec.target === "chat") {
4649
4861
  params.wait = parsed.options.wait ?? (s.mode === "one-shot" ? spec.message ? "confirmed" : "sent" : "none");
@@ -4951,4 +5163,4 @@ async function run(argv) {
4951
5163
  //#endregion
4952
5164
  export { run };
4953
5165
 
4954
- //# sourceMappingURL=main-Dd5INTcu.js.map
5166
+ //# sourceMappingURL=main-DUG0nGLw.js.map