@ghostlytools/cli 1.9.0 → 1.10.1

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 (118) hide show
  1. package/README.md +35 -27
  2. package/SKILL.md +7 -3
  3. package/dist/assets/api-BOWLZYXM.js +3 -0
  4. package/dist/assets/{api-DFCgr6RH.js → api-Bi6hCcwG.js} +100 -47
  5. package/dist/assets/api-Bi6hCcwG.js.map +1 -0
  6. package/dist/assets/{apiKit-CCavJJcl.js → apiKit-DzXHZojD.js} +26 -9
  7. package/dist/assets/apiKit-DzXHZojD.js.map +1 -0
  8. package/dist/assets/{apps-B7o2BPj6.js → apps-0Ks6KjqS.js} +1 -1
  9. package/dist/assets/{apps-DmxEG147.js → apps-DIQbzG08.js} +33 -10
  10. package/dist/assets/apps-DIQbzG08.js.map +1 -0
  11. package/dist/assets/{arkade-DtYR9H0c.js → arkade-zozCldAE.js} +2 -2
  12. package/dist/assets/{arkade-DtYR9H0c.js.map → arkade-zozCldAE.js.map} +1 -1
  13. package/dist/assets/{backup-YIB2XIES.js → backup-BL49Kt-T.js} +7 -6
  14. package/dist/assets/{backup-YIB2XIES.js.map → backup-BL49Kt-T.js.map} +1 -1
  15. package/dist/assets/{backup-BserdrNk.js → backup-BvIFcZM7.js} +1 -1
  16. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
  17. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
  18. package/dist/assets/{blobFiles-DOQDRdDI.js → blobFiles-BnjN_Vrz.js} +3 -3
  19. package/dist/assets/{blobFiles-DOQDRdDI.js.map → blobFiles-BnjN_Vrz.js.map} +1 -1
  20. package/dist/assets/buttons-CAW5v5EE.js +332 -0
  21. package/dist/assets/buttons-CAW5v5EE.js.map +1 -0
  22. package/dist/assets/buttons-oJI5mHSL.js +2 -0
  23. package/dist/assets/childEnv-BVOQK9EA.js +21 -0
  24. package/dist/assets/childEnv-BVOQK9EA.js.map +1 -0
  25. package/dist/assets/client-CyApKBEw.js +473 -0
  26. package/dist/assets/client-CyApKBEw.js.map +1 -0
  27. package/dist/assets/codec-DqFxxB_q.js +13 -0
  28. package/dist/assets/codec-DqFxxB_q.js.map +1 -0
  29. package/dist/assets/{endpoint-BdaeBw2L.js → endpoint-DWHkXWVM.js} +101 -16
  30. package/dist/assets/endpoint-DWHkXWVM.js.map +1 -0
  31. package/dist/assets/{envelope-Dt75vrmY.js → envelope-CMUgz31I.js} +3 -12
  32. package/dist/assets/envelope-CMUgz31I.js.map +1 -0
  33. package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js.map +1 -1
  34. package/dist/assets/{fileBytes-BPDKufla.js → fileBytes-DMzrIdCu.js} +1 -1
  35. package/dist/assets/{fileBytes-DNgrRL0R.js → fileBytes-DjBYYyXT.js} +3 -3
  36. package/dist/assets/{fileBytes-DNgrRL0R.js.map → fileBytes-DjBYYyXT.js.map} +1 -1
  37. package/dist/assets/{fileBytes-Q3ehcEr8.js → fileBytes-Douk1yOp.js} +2 -2
  38. package/dist/assets/{fileBytes-Q3ehcEr8.js.map → fileBytes-Douk1yOp.js.map} +1 -1
  39. package/dist/assets/fileBytesIdb-CD5Uv490.js +2 -0
  40. package/dist/assets/{fileBytesIdb-Dm1EyEbT.js → fileBytesIdb-CkClu9YI.js} +3 -3
  41. package/dist/assets/{fileBytesIdb-Dm1EyEbT.js.map → fileBytesIdb-CkClu9YI.js.map} +1 -1
  42. package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js → fileBytesOpfs-WryQuOgK.js} +3 -3
  43. package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js.map → fileBytesOpfs-WryQuOgK.js.map} +1 -1
  44. package/dist/assets/{fixedHosts-B598JzbC.js → fixedHosts-C2hdCfzK.js} +4 -4
  45. package/dist/assets/{fixedHosts-B598JzbC.js.map → fixedHosts-C2hdCfzK.js.map} +1 -1
  46. package/dist/assets/{groupFiles-FXel6zIc.js → groupFiles-BAQIt_bJ.js} +404 -161
  47. package/dist/assets/groupFiles-BAQIt_bJ.js.map +1 -0
  48. package/dist/assets/{host-DIBeK_c_.js → host-CaRlDMTd.js} +206 -49
  49. package/dist/assets/host-CaRlDMTd.js.map +1 -0
  50. package/dist/assets/{hyperdhtRelay-D185dETu.js → hyperdhtRelay-BxADl3SG.js} +2 -2
  51. package/dist/assets/{hyperdhtRelay-D185dETu.js.map → hyperdhtRelay-BxADl3SG.js.map} +1 -1
  52. package/dist/assets/{idb-BkOJES5_.js → idb-BHsAqENE.js} +37 -6
  53. package/dist/assets/idb-BHsAqENE.js.map +1 -0
  54. package/dist/assets/{irohWeb-BSv_BWyG.js → irohWeb-D2sh6EWp.js} +65 -7
  55. package/dist/assets/irohWeb-D2sh6EWp.js.map +1 -0
  56. package/dist/assets/{main-BbhfMTt8.js → main-Bc4Ow56Z.js} +221 -287
  57. package/dist/assets/main-Bc4Ow56Z.js.map +1 -0
  58. package/dist/assets/{mainline-9Vc3c3SA.js → mainline-DWh4Ccri.js} +2 -2
  59. package/dist/assets/{mainline-9Vc3c3SA.js.map → mainline-DWh4Ccri.js.map} +1 -1
  60. package/dist/assets/networkReason-DT_D_Wpc.js +474 -0
  61. package/dist/assets/networkReason-DT_D_Wpc.js.map +1 -0
  62. package/dist/assets/{nwc-QX3Yt1Sb.js → nwc-DoSEhUKb.js} +3 -3
  63. package/dist/assets/{nwc-QX3Yt1Sb.js.map → nwc-DoSEhUKb.js.map} +1 -1
  64. package/dist/assets/{nwcProvider-CzX3xH47.js → nwcProvider-CGWqUjpB.js} +2 -2
  65. package/dist/assets/{nwcProvider-CzX3xH47.js.map → nwcProvider-CGWqUjpB.js.map} +1 -1
  66. package/dist/assets/{ownDid-D8z5gwGI.js → ownDid-CbGjRLBn.js} +3 -3
  67. package/dist/assets/ownDid-CbGjRLBn.js.map +1 -0
  68. package/dist/assets/{profiles-MFtCmJwK.js → profiles-DgIfvBeN.js} +47 -4
  69. package/dist/assets/profiles-DgIfvBeN.js.map +1 -0
  70. package/dist/assets/{registry-B2Dtnibo.js → registry-BSyxGjN6.js} +11 -9
  71. package/dist/assets/registry-BSyxGjN6.js.map +1 -0
  72. package/dist/assets/{registry-PTtBMaYZ.js → registry-C5cn80Rw.js} +1 -1
  73. package/dist/assets/{resolve-ZxVzwFNA.js → resolve-D-9YRFhl.js} +2 -2
  74. package/dist/assets/{resolve-ZxVzwFNA.js.map → resolve-D-9YRFhl.js.map} +1 -1
  75. package/dist/assets/{restoredRows-BCRCjhdF.js → restoredRows-CRYwIx3g.js} +2 -2
  76. package/dist/assets/{restoredRows-BCRCjhdF.js.map → restoredRows-CRYwIx3g.js.map} +1 -1
  77. package/dist/assets/{buttons-CuRfKnPI.js → secretGuard-CSVNxXVW.js} +80 -330
  78. package/dist/assets/secretGuard-CSVNxXVW.js.map +1 -0
  79. package/dist/assets/secretGuard-Q2BKq0q0.js +2 -0
  80. package/dist/assets/{server-Dw1o8z1o.js → server-BufntkX8.js} +1734 -369
  81. package/dist/assets/server-BufntkX8.js.map +1 -0
  82. package/dist/assets/{src-BD8RBVEp.js → src-CCt5s4DK.js} +3073 -1890
  83. package/dist/assets/src-CCt5s4DK.js.map +1 -0
  84. package/dist/assets/{sshForges-DWrESWkK.js → sshForges-D8CPaIbR.js} +16 -9
  85. package/dist/assets/{sshForges-DWrESWkK.js.map → sshForges-D8CPaIbR.js.map} +1 -1
  86. package/dist/assets/{translate-D1uP0q32.js → translate-Cb-6hMhD.js} +17 -12
  87. package/dist/assets/translate-Cb-6hMhD.js.map +1 -0
  88. package/dist/assets/{usdt-DhVN8geQ.js → usdt-ds461mzA.js} +3 -3
  89. package/dist/assets/{usdt-DhVN8geQ.js.map → usdt-ds461mzA.js.map} +1 -1
  90. package/dist/assets/{words-DdXPkB3n.js → words-B1ylON2h.js} +4 -2
  91. package/dist/assets/words-B1ylON2h.js.map +1 -0
  92. package/dist/ghostly.mjs +1 -1
  93. package/package.json +1 -1
  94. package/dist/assets/api-DFCgr6RH.js.map +0 -1
  95. package/dist/assets/api-raWw9j_m.js +0 -3
  96. package/dist/assets/apiKit-CCavJJcl.js.map +0 -1
  97. package/dist/assets/apps-DmxEG147.js.map +0 -1
  98. package/dist/assets/buttons-CuRfKnPI.js.map +0 -1
  99. package/dist/assets/buttons-De3LPdSG.js +0 -2
  100. package/dist/assets/daemonProof-DtrL5lE5.js +0 -236
  101. package/dist/assets/daemonProof-DtrL5lE5.js.map +0 -1
  102. package/dist/assets/endpoint-BdaeBw2L.js.map +0 -1
  103. package/dist/assets/envelope-Dt75vrmY.js.map +0 -1
  104. package/dist/assets/fileBytesIdb-DZcESfTt.js +0 -2
  105. package/dist/assets/groupFiles-FXel6zIc.js.map +0 -1
  106. package/dist/assets/host-DIBeK_c_.js.map +0 -1
  107. package/dist/assets/idb-BkOJES5_.js.map +0 -1
  108. package/dist/assets/irohWeb-BSv_BWyG.js.map +0 -1
  109. package/dist/assets/main-BbhfMTt8.js.map +0 -1
  110. package/dist/assets/networkReason-BncJ9KSM.js +0 -154
  111. package/dist/assets/networkReason-BncJ9KSM.js.map +0 -1
  112. package/dist/assets/ownDid-D8z5gwGI.js.map +0 -1
  113. package/dist/assets/profiles-MFtCmJwK.js.map +0 -1
  114. package/dist/assets/registry-B2Dtnibo.js.map +0 -1
  115. package/dist/assets/server-Dw1o8z1o.js.map +0 -1
  116. package/dist/assets/src-BD8RBVEp.js.map +0 -1
  117. package/dist/assets/translate-D1uP0q32.js.map +0 -1
  118. package/dist/assets/words-DdXPkB3n.js.map +0 -1
@@ -1,19 +1,19 @@
1
- import { Qn as GROUP_FILE_LIMITS, _o as statusCardBytes, ao as PR_STATES, ba as VOICE_LIMITS, co as STATUS_CARD_LIMITS, io as PR_CHECKS, lo as TASK_STATUSES, mo as cardUrl, no as CRON_LINE, oo as ROUTINE_STATES, po as cardLine, ro as ITEM_STATES, so as RUN_RESULTS } from "./src-BD8RBVEp.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, r as PAY_METHODS, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-DdXPkB3n.js";
1
+ import { _o as cardLine, co as PR_CHECKS, do as RUN_RESULTS, er as GROUP_FILE_LIMITS, fo as STATUS_CARD_LIMITS, lo as PR_STATES, oo as CRON_LINE, po as TASK_STATUSES, so as ITEM_STATES, uo as ROUTINE_STATES, vo as cardUrl, wa as VOICE_LIMITS, xo as statusCardBytes } from "./src-CCt5s4DK.js";
3
2
  import { i as localFileError, n as EXIT, r as asCliError, t as CliError } from "./errors-R4S2SAEM.js";
4
- import { m as namedByThem, t as CONTACT_KEY } from "./apiKit-CCavJJcl.js";
5
- import { _ as userPath, a as checkShownName, c as ghostlyHome, f as profileExists, h as startingDaemon, i as checkProfileName, l as listProfiles, m as selectProfile, o as createProfile, p as profilePaths, s as currentProfile, u as lockOwner, y as ownSocket } from "./profiles-MFtCmJwK.js";
3
+ 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, r as PAY_METHODS, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-B1ylON2h.js";
4
+ import { m as namedByThem, t as CONTACT_KEY } from "./apiKit-DzXHZojD.js";
5
+ import { n as dropSecretEnv, t as childEnv } from "./childEnv-BVOQK9EA.js";
6
+ import { _ as userPath, a as checkShownName, c as ghostlyHome, f as profileExists, h as startingDaemon, i as checkProfileName, l as listProfiles, m as selectProfile, o as createProfile, p as profilePaths, s as currentProfile, u as lockOwner, y as ownProfile } from "./profiles-DgIfvBeN.js";
6
7
  import { n as waitNotice, r as waitsFor } from "./waitNotice-B8D8WhbE.js";
7
- import { _ as isCallRate, a as newNonce, c as provesGreeting, d as CALL_RATES, l as readDaemonSecret, n as daemonOfThisRelease, s as provesDaemon, t as HELLO } from "./daemonProof-DtrL5lE5.js";
8
+ import { g as isCallRate, i as isNotTheDaemon, r as connectDaemon, t as DaemonClient, u as CALL_RATES } from "./client-CyApKBEw.js";
8
9
  import { spawn } from "node:child_process";
9
10
  import { accessSync, closeSync, constants, existsSync, fstatSync, openSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
10
11
  import { dirname, resolve } from "node:path";
11
12
  import { connect } from "node:net";
12
- import { createInterface } from "node:readline";
13
13
  import { format } from "node:util";
14
14
  var package_default = {
15
15
  name: "@ghostlytools/cli",
16
- version: "1.9.0",
16
+ version: "1.10.1",
17
17
  type: "module",
18
18
  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
19
  license: "MIT",
@@ -285,232 +285,6 @@ function liftGlobals(argv) {
285
285
  ];
286
286
  }
287
287
  //#endregion
288
- //#region src/client.ts
289
- /** The id of the hello on every connection: a string, so it is never one of the calls' numbers. */
290
- var HELLO_ID = "hello";
291
- /**
292
- * How long a client waits for the daemon's greeting before it asks who holds the profile: a daemon greets as it
293
- * accepts the connection, and one of an older release (before the greeting) never does. A daemon of this release
294
- * holding the profile (`daemonOfThisRelease`) is busy and is waited for, under each call's own deadline; anything
295
- * else is refused then. It used to refuse every late greeting, after 10 s: a daemon busy that long on one task (an
296
- * outbox backlog, 14 to 29 s) had every command and `listen` refused as an older release's, to be restarted.
297
- */
298
- var GREETING_MS = 2e3;
299
- /** The refusal of a listener that did not prove it is the profile's daemon (`isNotTheDaemon` tells it apart). */
300
- function notTheDaemon(socket) {
301
- 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" });
302
- }
303
- function isNotTheDaemon(error) {
304
- return error instanceof CliError && error.code === "refused" && error.details?.reason === "not-the-daemon";
305
- }
306
- /**
307
- * A connection to a profile's daemon over its socket (WISP 1100 § Local control API). `null` from `connectDaemon`
308
- * means no daemon answers there: a one-shot command runs the profile itself.
309
- *
310
- * The client writes nothing on it until the daemon's greeting, its first line, proves the other end read the
311
- * profile's daemon secret and holds the profile's lock (`provesGreeting`): a listener that cannot prove it has read
312
- * nothing from this client, so it cannot impersonate it either (`daemonProof.ts`). Then the first line written is a
313
- * `daemon.hello`, and no call is written until its answer proves the same over the client's own nonce. Until then
314
- * every call waits, under its own deadline, and a listener that does not prove both gets every call refused
315
- * (`refused`, `isNotTheDaemon`). Nothing it writes before that is read either.
316
- */
317
- var DaemonClient = class {
318
- socket;
319
- address;
320
- nextId = 1;
321
- pending = /* @__PURE__ */ new Map();
322
- eventListener = null;
323
- closedListener = null;
324
- /** While paused: the events of the chunk already read, given to the listener on resume. */
325
- held = null;
326
- greeted = false;
327
- verified = false;
328
- refusal = null;
329
- ready;
330
- settle;
331
- constructor(socket, address, greetingMs = GREETING_MS) {
332
- this.socket = socket;
333
- this.address = address;
334
- this.ready = new Promise((resolve, reject) => {
335
- this.settle = {
336
- resolve,
337
- reject
338
- };
339
- });
340
- this.ready.catch(() => {});
341
- const nonce = newNonce();
342
- const waitedTooLong = setTimeout(() => {
343
- if (!this.greeted && !this.refusal && !daemonOfThisRelease(this.address.dir)) this.refuse();
344
- }, greetingMs);
345
- waitedTooLong.unref?.();
346
- const lines = createInterface({
347
- input: socket,
348
- crlfDelay: Infinity
349
- });
350
- lines.on("error", () => {});
351
- lines.on("line", (line) => {
352
- let message;
353
- try {
354
- message = JSON.parse(line);
355
- } catch {
356
- if (!this.greeted && !this.refusal) this.refuse();
357
- return;
358
- }
359
- if (this.refusal) return;
360
- if (!this.greeted) {
361
- clearTimeout(waitedTooLong);
362
- const secret = readDaemonSecret(this.address.dir);
363
- if (!secret || !provesGreeting(secret, this.address.dir, message)) {
364
- this.refuse();
365
- return;
366
- }
367
- this.greeted = true;
368
- if (socket.writableEnded || socket.destroyed) return;
369
- socket.write(JSON.stringify({
370
- id: HELLO_ID,
371
- method: HELLO,
372
- params: { nonce }
373
- }) + "\n");
374
- return;
375
- }
376
- if (!this.verified) {
377
- if (message?.id !== HELLO_ID) return;
378
- const secret = readDaemonSecret(this.address.dir);
379
- if (!message.error && secret && provesDaemon(secret, nonce, message.result)) {
380
- this.verified = true;
381
- this.settle.resolve();
382
- return;
383
- }
384
- this.refuse();
385
- return;
386
- }
387
- if (message.event) {
388
- if (this.held) this.held.push(message.event);
389
- else this.eventListener?.(message.event);
390
- return;
391
- }
392
- const waiting = typeof message.id === "number" ? this.pending.get(message.id) : void 0;
393
- if (!waiting) return;
394
- this.pending.delete(message.id);
395
- if (message.error) waiting.reject(new CliError(message.error.code, message.error.message, message.error.details));
396
- else waiting.resolve(message.result);
397
- });
398
- socket.on("close", () => {
399
- clearTimeout(waitedTooLong);
400
- const why = this.refusal ?? new CliError("unavailable", "The daemon went away");
401
- if (!this.verified) this.settle.reject(why);
402
- for (const waiting of this.pending.values()) waiting.reject(why);
403
- this.pending.clear();
404
- this.closedListener?.();
405
- });
406
- socket.on("error", () => {});
407
- }
408
- refuse() {
409
- this.refusal = notTheDaemon(this.address.socket);
410
- this.settle.reject(this.refusal);
411
- this.socket.destroy();
412
- }
413
- /**
414
- * `timeoutMs`: give up (code `timeout`, exit 4) when the daemon has not answered by then; without it the call waits
415
- * for as long as the connection holds. A call that timed out closes the connection: its answer, if one ever comes,
416
- * is of no use, and the process leaves once nothing else keeps it (not every caller reaches `exit`).
417
- */
418
- call(method, params = {}, { timeoutMs } = {}) {
419
- if (this.socket.destroyed) return Promise.reject(this.refusal ?? new CliError("unavailable", "The daemon went away"));
420
- const id = this.nextId++;
421
- return new Promise((resolve, reject) => {
422
- let timer;
423
- if (timeoutMs !== void 0) {
424
- timer = setTimeout(() => {
425
- if (!this.pending.delete(id)) return;
426
- reject(new CliError("timeout", `The daemon did not answer ${method} in ${timeoutMs / 1e3} s: \`ghostly daemon restart\` starts a fresh one`, { method }));
427
- this.destroy();
428
- }, timeoutMs);
429
- timer.unref?.();
430
- }
431
- const settle = {
432
- resolve: (value) => {
433
- if (timer) clearTimeout(timer);
434
- resolve(value);
435
- },
436
- reject: (error) => {
437
- if (timer) clearTimeout(timer);
438
- reject(error);
439
- }
440
- };
441
- this.pending.set(id, settle);
442
- this.ready.then(() => {
443
- if (this.pending.has(id) && !this.socket.destroyed) this.socket.write(JSON.stringify({
444
- id,
445
- method,
446
- params
447
- }) + "\n");
448
- }, (error) => {
449
- if (this.pending.delete(id)) settle.reject(error);
450
- });
451
- });
452
- }
453
- /** Events after `since` (replayed from the journal), then every new one, until the connection closes. */
454
- async subscribe(since, listener, onClosed) {
455
- this.eventListener = listener;
456
- this.closedListener = onClosed ?? null;
457
- return this.call("events.subscribe", since === void 0 ? {} : { since });
458
- }
459
- /**
460
- * Stops reading: what the daemon sends waits in the connection (and past its bound the daemon ends it), and no
461
- * event reaches the listener until `resume`.
462
- */
463
- pause() {
464
- if (this.held) return;
465
- this.held = [];
466
- this.socket.pause();
467
- }
468
- /** Gives the listener the events held, then reads again; a listener that pauses again keeps the rest held. */
469
- resume() {
470
- const held = this.held;
471
- if (!held) return;
472
- this.held = null;
473
- for (let i = 0; i < held.length; i++) {
474
- this.eventListener?.(held[i]);
475
- if (this.held) {
476
- this.held.unshift(...held.slice(i + 1));
477
- return;
478
- }
479
- }
480
- this.socket.resume();
481
- }
482
- close() {
483
- this.socket.end();
484
- }
485
- /** Closes at once: what the daemon still sends is not read. */
486
- destroy() {
487
- this.socket.destroy();
488
- }
489
- };
490
- /**
491
- * `timeoutMs` bounds the connect only; `greetingMs`, the wait for the daemon's greeting (above). The client it gives
492
- * has written nothing yet; whether the listener is the daemon is known at the first call.
493
- */
494
- function connectDaemon(address, timeoutMs = 2e3, { greetingMs = GREETING_MS } = {}) {
495
- const path = address.socket;
496
- if (!ownSocket(path)) return Promise.resolve(null);
497
- return new Promise((resolve) => {
498
- const socket = connect(path);
499
- const timer = setTimeout(() => {
500
- socket.destroy();
501
- resolve(null);
502
- }, timeoutMs);
503
- socket.once("connect", () => {
504
- clearTimeout(timer);
505
- resolve(new DaemonClient(socket, address, greetingMs));
506
- });
507
- socket.once("error", () => {
508
- clearTimeout(timer);
509
- resolve(null);
510
- });
511
- });
512
- }
513
- //#endregion
514
288
  //#region src/commands/shared.ts
515
289
  var wait = {
516
290
  wait: {
@@ -569,6 +343,29 @@ function here(path) {
569
343
  if (path === "") throw new CliError("usage", "A path given as \"\" names no file");
570
344
  return typeof path === "string" ? userPath(path) : void 0;
571
345
  }
346
+ var STDIN_TOO_BIG = "More than 16 MiB came on stdin, more than any command takes (a long text goes as a file: ghostly file send <chat|group> <path>)";
347
+ /**
348
+ * A file's text, or stdin's (`0`), up to `INPUT_BYTES`: more is refused as it comes. `app send … -`, a card's `--json`
349
+ * and the files `identity complete` and `x401 credential add` send were read whole: 600 MiB answered V8's "Cannot
350
+ * create a string longer than 0x1fffffe8 characters", and past 16 MiB a daemon cut the line ("The daemon went away").
351
+ */
352
+ function readInput(file) {
353
+ const fd = file === 0 ? 0 : openSync(file, "r");
354
+ try {
355
+ const chunks = [];
356
+ let bytes = 0;
357
+ for (;;) {
358
+ const chunk = Buffer.allocUnsafe(1048576);
359
+ const read = readSync(fd, chunk, 0, chunk.length, null);
360
+ if (!read) return Buffer.concat(chunks).toString("utf8");
361
+ bytes += read;
362
+ if (bytes > 16777216) throw new CliError("bad_request", file === 0 ? STDIN_TOO_BIG : `${file} holds more than 16 MiB, more than any command takes (a file to share goes as one: ghostly file send <chat|group> <path>)`);
363
+ chunks.push(chunk.subarray(0, read));
364
+ }
365
+ } finally {
366
+ if (file !== 0) closeSync(fd);
367
+ }
368
+ }
572
369
  /**
573
370
  * A list option that names chats (`--to`, `--from`): "" or "group:" alone (an unset variable in a script) names
574
371
  * nothing, and is a usage error before the profile opens; it was a prefix of every id and took the only chat or group.
@@ -717,9 +514,9 @@ function cardJson(value) {
717
514
  const file = text.startsWith("{") || text === "-" ? void 0 : here(text);
718
515
  let raw;
719
516
  try {
720
- raw = text.startsWith("{") ? text : readFileSync(file ?? 0, "utf8");
517
+ raw = text.startsWith("{") ? text : readInput(file ?? 0);
721
518
  } catch (error) {
722
- throw file !== void 0 && localFileError(error, file) || new CliError("usage", `--json takes a card as JSON, - for stdin, or a file: ${error instanceof Error ? error.message : String(error)}`);
519
+ throw error instanceof CliError && error || file !== void 0 && localFileError(error, file) || new CliError("usage", `--json takes a card as JSON, - for stdin, or a file: ${error instanceof Error ? error.message : String(error)}`);
723
520
  }
724
521
  let parsed;
725
522
  try {
@@ -938,10 +735,58 @@ function quota(card, usage) {
938
735
  var CARD_TIME_FORMS = "2026-09-30 or 2026-09-30 01:00 (no zone: local time; a date alone is its midnight), 2026-09-30T01:00:00Z or 2026-09-30T01:00+02:00";
939
736
  /** An ISO date with no time, which `Date.parse` alone reads as UTC midnight: `2026-09-30`, `2026-09`. */
940
737
  var ISO_DAY = /^(?:[+-]\d{6}|\d{4})-\d{2}(-\d{2})?$/;
738
+ var MONTHS = [
739
+ "jan",
740
+ "feb",
741
+ "mar",
742
+ "apr",
743
+ "may",
744
+ "jun",
745
+ "jul",
746
+ "aug",
747
+ "sep",
748
+ "oct",
749
+ "nov",
750
+ "dec"
751
+ ];
752
+ /** What `Date.parse` takes between a month's name and a number: `Apr 31`, `Apr-31`, `31/Apr`, `Apr.31`, `31 Apr,`. */
753
+ var NAME_SEP = "[\\s,./-]*";
754
+ var MONTH_DAY = new RegExp(`\\b(${MONTHS.join("|")})[a-z]*${NAME_SEP}(\\d{1,2})(?!\\d)`, "i");
755
+ var DAY_MONTH = new RegExp(`(?<!\\d)(\\d{1,2})${NAME_SEP}(${MONTHS.join("|")})`, "i");
756
+ /**
757
+ * The year, month (1 to 12) and day a date is written with: `2026-04-31`, `2026/4/31`, `4/31/2026` (month first, as
758
+ * `Date.parse` reads it, also with dashes or dots and a two-digit year), `Apr 31 2026`, `31-Apr-2026`. `Date.parse`
759
+ * takes any day up to 31 and moves it past the month's end, so the day is checked here.
760
+ */
761
+ function writtenDay(text) {
762
+ const numeric = /^([+-]\d{6}|\d{4})[-/](\d{1,2})[-/](\d{1,2})(?!\d)/.exec(text);
763
+ if (numeric) return [
764
+ Number(numeric[1]),
765
+ Number(numeric[2]),
766
+ Number(numeric[3])
767
+ ];
768
+ const monthFirst = /^(\d{1,2})[-/.](\d{1,2})[-/.](\d{4}|\d{2})(?!\d)/.exec(text);
769
+ const yy = (y) => y.length === 2 ? Number(y) + (Number(y) < 50 ? 2e3 : 1900) : Number(y);
770
+ if (monthFirst) return [
771
+ yy(monthFirst[3]),
772
+ Number(monthFirst[1]),
773
+ Number(monthFirst[2])
774
+ ];
775
+ const year = /\b(\d{4})\b/.exec(text), monthDay = MONTH_DAY.exec(text), dayMonth = monthDay ? null : DAY_MONTH.exec(text);
776
+ const [word, day] = monthDay ? [monthDay[1], monthDay[2]] : dayMonth ? [dayMonth[2], dayMonth[1]] : [];
777
+ return year && word ? [
778
+ Number(year[1]),
779
+ MONTHS.indexOf(word.toLowerCase()) + 1,
780
+ Number(day)
781
+ ] : void 0;
782
+ }
941
783
  /**
942
784
  * A time a command names: milliseconds, or a date the JavaScript Date reads (`2026-09-30T01:00:00Z`). A date with no
943
785
  * zone is local time in every form: `Date.parse` reads `2026-09-30 01:00` and `Sep 30 2026` as local but an ISO date
944
786
  * alone as UTC midnight (21:00 the day before in UTC-03, agents#2355), so that one is read as `2026-09-30T00:00`.
787
+ * 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
788
+ * ahead is a usage error that names the flag and the last time it takes: before, it reached the card's check and failed
789
+ * as `bad_request` (exit 1), "Status card: resetsAt is a time in milliseconds, within a year". A time past is taken.
945
790
  */
946
791
  function cardTime(value, flag) {
947
792
  if (value === void 0) return void 0;
@@ -949,6 +794,17 @@ function cardTime(value, flag) {
949
794
  const day = ISO_DAY.exec(text);
950
795
  const ms = /^\d+$/.test(text) ? milliseconds(text, flag) : Date.parse(day ? `${text}${day[1] ? "" : "-01"}T00:00` : text);
951
796
  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)}`);
797
+ const written = writtenDay(text);
798
+ if (written) {
799
+ const [year, month, date] = written, days = new Date(Date.UTC(year, month, 0)).getUTCDate();
800
+ if (date > days) throw new CliError("usage", `--${flag} takes a day the month has (${year}-${String(month).padStart(2, "0")} has ${days}), not ${JSON.stringify(value)}`);
801
+ }
802
+ const last = new Date(Date.now() + STATUS_CARD_LIMITS.nextRunMs);
803
+ if (ms > last.getTime()) {
804
+ const two = (n) => String(n).padStart(2, "0");
805
+ const shown = `${last.getFullYear()}-${two(last.getMonth() + 1)}-${two(last.getDate())} ${two(last.getHours())}:${two(last.getMinutes())}`;
806
+ throw new CliError("usage", `--${flag} takes a time within a year from now (until ${shown}), not ${JSON.stringify(value)}`);
807
+ }
952
808
  return ms;
953
809
  }
954
810
  /** `--run ok`, `--run failed:"CI flaked"`: a run of a routine, recorded as its last. */
@@ -1006,7 +862,7 @@ var routineOptions = {
1006
862
  },
1007
863
  next: {
1008
864
  type: "string",
1009
- description: `Its next run: milliseconds or a date: ${CARD_TIME_FORMS}`
865
+ description: `Its next run, within a year: milliseconds or a date: ${CARD_TIME_FORMS}`
1010
866
  },
1011
867
  run: {
1012
868
  type: "string",
@@ -1153,7 +1009,7 @@ var usageOptions = {
1153
1009
  },
1154
1010
  resets: {
1155
1011
  type: "string",
1156
- description: `When the window starts again: milliseconds or a date: ${CARD_TIME_FORMS}`
1012
+ description: `When the window starts again, within a year: milliseconds or a date: ${CARD_TIME_FORMS}`
1157
1013
  },
1158
1014
  also: {
1159
1015
  type: "list",
@@ -1181,7 +1037,7 @@ function keyFile(value, usage) {
1181
1037
  /** `app send`'s message: JSON on the command line, or `-` for stdin. */
1182
1038
  function appData(value) {
1183
1039
  if (value === void 0) throw new CliError("usage", "The message is needed, as JSON or - for stdin: ghostly app send <chat> <ref|name> <json|->");
1184
- const text = value.trim() === "-" ? readFileSync(0, "utf8") : value;
1040
+ const text = value.trim() === "-" ? readInput(0) : value;
1185
1041
  try {
1186
1042
  return JSON.parse(text);
1187
1043
  } catch {
@@ -1227,7 +1083,7 @@ var commands$8 = {
1227
1083
  description: "Replace the three files when they are there"
1228
1084
  }
1229
1085
  },
1230
- run: async ({ options }, a) => (await import("./apps-B7o2BPj6.js")).initApp(a.dir, {
1086
+ run: async ({ options }, a) => (await import("./apps-0Ks6KjqS.js")).initApp(a.dir, {
1231
1087
  name: options.name,
1232
1088
  title: options.title,
1233
1089
  force: options.force === true
@@ -1267,7 +1123,7 @@ var commands$8 = {
1267
1123
  description: "This version's sequence, higher than the bundle at --out's (default: one more than it)"
1268
1124
  }
1269
1125
  },
1270
- run: async ({ options }, a) => (await import("./apps-B7o2BPj6.js")).publishApp(a.dir, keyFile(options.key, "app publish <dir> --key <file> [--out <file>] [--sequence n]"), here(options.out), options.sequence)
1126
+ run: async ({ options }, a) => (await import("./apps-0Ks6KjqS.js")).publishApp(a.dir, keyFile(options.key, "app publish <dir> --key <file> [--out <file>] [--sequence n]"), here(options.out), options.sequence)
1271
1127
  },
1272
1128
  "app revoke": {
1273
1129
  method: "app.revoke",
@@ -1297,10 +1153,10 @@ var commands$8 = {
1297
1153
  },
1298
1154
  force: {
1299
1155
  type: "boolean",
1300
- description: "Allow --up-to past the bundle's own sequence (versions published from elsewhere)"
1156
+ 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"
1301
1157
  }
1302
1158
  },
1303
- run: async ({ options }, a) => (await import("./apps-B7o2BPj6.js")).revokeApp(a.dir, keyFile(options.key, "app revoke <dir> --key <file> (--digest <digest>... | --up-to <sequence>) [--reason <text>] [--bundle <file>] [--force]"), {
1159
+ run: async ({ options }, a) => (await import("./apps-0Ks6KjqS.js")).revokeApp(a.dir, keyFile(options.key, "app revoke <dir> --key <file> (--digest <digest>... | --up-to <sequence>) [--reason <text>] [--bundle <file>] [--force]"), {
1304
1160
  digests: options.digest,
1305
1161
  upTo: options["up-to"],
1306
1162
  reason: options.reason,
@@ -1361,7 +1217,7 @@ var commands$8 = {
1361
1217
  usage: "app verify <bundle|url>",
1362
1218
  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",
1363
1219
  args: ["bundle"],
1364
- run: async (_, a) => (await import("./apps-B7o2BPj6.js")).verifyApp(a.bundle)
1220
+ run: async (_, a) => (await import("./apps-0Ks6KjqS.js")).verifyApp(a.bundle)
1365
1221
  },
1366
1222
  "store sign": {
1367
1223
  method: "store.sign",
@@ -1378,7 +1234,7 @@ var commands$8 = {
1378
1234
  description: "The folder to write ghostly-store.json and ghostly-store.sig in (default: the index's)"
1379
1235
  }
1380
1236
  },
1381
- run: async ({ options }, a) => (await import("./apps-B7o2BPj6.js")).signStore(a.index, keyFile(options.key, "store sign <index> --key <file> [--out <dir>]"), here(options.out))
1237
+ run: async ({ options }, a) => (await import("./apps-0Ks6KjqS.js")).signStore(a.index, keyFile(options.key, "store sign <index> --key <file> [--out <dir>]"), here(options.out))
1382
1238
  }
1383
1239
  };
1384
1240
  //#endregion
@@ -2201,7 +2057,7 @@ var commands$5 = {
2201
2057
  },
2202
2058
  "file send": {
2203
2059
  method: "file.send",
2204
- usage: "file send <chat|group> <path> [--name n] [--mime t] [--voice [ms] [--peaks 0,40,…]] [--reply <message>] [--wait none|sent] [--timeout s]",
2060
+ usage: "file send <chat|group> <path> [--name n] [--mime t] [--voice [ms] [--peaks 0,40,…]] [--reply <message>] [--force] [--wait none|sent] [--timeout s]",
2205
2061
  summary: `Send a file (or, with --voice, a voice note), as a reply with --reply; to a group, every member's app fetches it (up to ${GROUP_FILE_LIMITS.maxBytes / 1024 / 1024} MiB)`,
2206
2062
  args: ["chat", "path"],
2207
2063
  options: {
@@ -2231,6 +2087,10 @@ var commands$5 = {
2231
2087
  timeout: {
2232
2088
  type: "number",
2233
2089
  description: "Seconds --wait sent waits (default 300)"
2090
+ },
2091
+ force: {
2092
+ type: "boolean",
2093
+ description: "Send even if --name looks like a seed, a key or ecash"
2234
2094
  }
2235
2095
  },
2236
2096
  params: ({ options }, a) => ({
@@ -2240,6 +2100,7 @@ var commands$5 = {
2240
2100
  mime: options.mime,
2241
2101
  ...voiceOf(options),
2242
2102
  reply: options.reply,
2103
+ force: options.force === true,
2243
2104
  wait: options.wait,
2244
2105
  timeout: timeout(options, LONG_WAIT_SECONDS)
2245
2106
  })
@@ -2303,6 +2164,11 @@ var commands$4 = {
2303
2164
  };
2304
2165
  //#endregion
2305
2166
  //#region src/commands/groups.ts
2167
+ var nameForce = {
2168
+ type: "boolean",
2169
+ description: "Use the name even if it looks like a seed, a key or ecash"
2170
+ };
2171
+ var forced = (options) => options.force === true ? { force: true } : {};
2306
2172
  /** Groups: one entry per command, in alphabetical order (test/commands.test.ts checks). */
2307
2173
  var commands$3 = {
2308
2174
  "group accept": {
@@ -2326,16 +2192,20 @@ var commands$3 = {
2326
2192
  },
2327
2193
  "group create": {
2328
2194
  method: "group.create",
2329
- usage: "group create <name...> [--mesh]",
2195
+ usage: "group create <name...> [--mesh] [--force]",
2330
2196
  summary: "A community (a link anyone can open) or, with --mesh, a private group of up to 32",
2331
2197
  args: ["name..."],
2332
- options: { mesh: {
2333
- type: "boolean",
2334
- description: "A private mesh of contacts instead of a community"
2335
- } },
2198
+ options: {
2199
+ mesh: {
2200
+ type: "boolean",
2201
+ description: "A private mesh of contacts instead of a community"
2202
+ },
2203
+ force: nameForce
2204
+ },
2336
2205
  params: ({ options }, { name }) => ({
2337
2206
  name,
2338
- profile: options.mesh ? "mesh" : "community"
2207
+ profile: options.mesh ? "mesh" : "community",
2208
+ ...forced(options)
2339
2209
  })
2340
2210
  },
2341
2211
  "group decline": {
@@ -2537,13 +2407,17 @@ var commands$3 = {
2537
2407
  },
2538
2408
  "group rename": {
2539
2409
  method: "group.rename",
2540
- usage: "group rename <group> <name...> [--show-secret]",
2410
+ usage: "group rename <group> <name...> [--force] [--show-secret]",
2541
2411
  summary: "Rename the group (admin; the picture stays)",
2542
2412
  args: ["group", "name..."],
2543
- options: showSecret,
2413
+ options: {
2414
+ ...showSecret,
2415
+ force: nameForce
2416
+ },
2544
2417
  params: ({ options }, a) => ({
2545
2418
  group: a.group,
2546
2419
  name: a.name,
2420
+ ...forced(options),
2547
2421
  ...secret(options)
2548
2422
  })
2549
2423
  },
@@ -2691,13 +2565,13 @@ var commands$2 = {
2691
2565
  method: "x401.credential.add",
2692
2566
  usage: "x401 credential add <file|-> [--label <name>]",
2693
2567
  summary: "Keep an issued SD-JWT VC bound to a key from x401 key new (a file, or - for stdin)",
2694
- args: ["file"],
2568
+ args: ["path"],
2695
2569
  options: { label: {
2696
2570
  type: "string",
2697
2571
  description: "Your name for it, up to 80 characters on one line (default: its type)"
2698
2572
  } },
2699
2573
  params: ({ options }, a) => ({
2700
- file: a.file === "-" ? "-" : here(a.file),
2574
+ file: a.path === "-" ? "-" : here(a.path),
2701
2575
  label: options.label
2702
2576
  })
2703
2577
  },
@@ -2859,7 +2733,7 @@ var commands$1 = {
2859
2733
  },
2860
2734
  "pay": {
2861
2735
  method: "pay",
2862
- usage: "pay <invoice|lightning-address|lnurl> [--amount sats] [--network n] [--max-fee sats] [--card <id>] [--comment t] [--confirm-real] [--force]",
2736
+ usage: "pay <invoice|lightning-address|lnurl> [--amount sats] [--network n] [--max-fee sats] [--card <id>] [--comment t] [--chat <chat>] [--confirm-real] [--force]",
2863
2737
  summary: "Pay over Lightning from Testnet, or --network mainnet with --confirm-real",
2864
2738
  args: ["target"],
2865
2739
  options: {
@@ -2877,6 +2751,10 @@ var commands$1 = {
2877
2751
  type: "string",
2878
2752
  description: "For the address's owner"
2879
2753
  },
2754
+ chat: {
2755
+ type: "string",
2756
+ description: "The chat the invoice came from: on Testnet its contact is told it was paid"
2757
+ },
2880
2758
  "confirm-real": confirmReal,
2881
2759
  force
2882
2760
  },
@@ -2887,6 +2765,7 @@ var commands$1 = {
2887
2765
  maxFee: options["max-fee"],
2888
2766
  card: options.card,
2889
2767
  comment: options.comment,
2768
+ chat: options.chat,
2890
2769
  confirmReal: options["confirm-real"] === true,
2891
2770
  force: options.force === true
2892
2771
  })
@@ -3650,9 +3529,7 @@ function checkTypes(types, warn) {
3650
3529
  }
3651
3530
  /** The environment a hook runs in: this one's, less the backup passphrase (a hook, and what it runs, never needs it). */
3652
3531
  function hookEnv(env) {
3653
- const rest = { ...env };
3654
- delete rest.GHOSTLY_BACKUP_PASSPHRASE;
3655
- return rest;
3532
+ return childEnv(env);
3656
3533
  }
3657
3534
  /** Runs `command` through the shell with the event on stdin (never in its arguments); resolves with its exit code. */
3658
3535
  function runExec(command, event) {
@@ -4120,15 +3997,15 @@ var VERSION = package_default.version;
4120
3997
  * command a running daemon answers loads none of them, and starts about as fast as Node does. Statically imported, they
4121
3998
  * cost every command ~100 ms before its socket was opened.
4122
3999
  */
4123
- var engineApi = () => import("./api-raWw9j_m.js");
4124
- var engineHost = () => import("./host-DIBeK_c_.js");
4000
+ var engineApi = () => import("./api-BOWLZYXM.js");
4001
+ var engineHost = () => import("./host-CaRlDMTd.js");
4125
4002
  /**
4126
4003
  * `--translate <lang>`'s translator, or null (not asked; or the runtime is not there, said on stderr). Loaded only when
4127
4004
  * asked: the app's message parser it reads costs every other command nothing.
4128
4005
  */
4129
4006
  async function translatorFor(value, home) {
4130
4007
  if (value === void 0) return null;
4131
- const { loadDetector, openTranslator, translateTarget } = await import("./translate-D1uP0q32.js");
4008
+ const { loadDetector, openTranslator, translateTarget } = await import("./translate-Cb-6hMhD.js");
4132
4009
  return openTranslator({
4133
4010
  home,
4134
4011
  to: translateTarget(value),
@@ -4256,6 +4133,15 @@ function newChatOnly(method) {
4256
4133
  return method === "invite.create" || method === "invite.join";
4257
4134
  }
4258
4135
  /**
4136
+ * A command about the 1:1 chat it names, or one that makes or joins a new chat (`newChatOnly`): a one-shot for it leaves
4137
+ * the other saved chats unstarted too, and starts only the chat a call names (`startNamedChats`). Started, each saved
4138
+ * chat put its records and its leave packet on the relays: with 12 invites saved one `send` took the relays' 30
4139
+ * requests a minute, and a text to a contact who is away, or the next one-shot, waited behind them.
4140
+ */
4141
+ function oneChatOnly(method, params) {
4142
+ return newChatOnly(method) || chatOnly(method, params) && typeof params.chat === "string";
4143
+ }
4144
+ /**
4259
4145
  * Calls that only read what the profile stores: a one-shot for one opens it offline (`RuntimeOptions.offline`).
4260
4146
  * Opened online, `status` or `chat list` started every chat, put the profile's records on the relays again and waited
4261
4147
  * for its leave packet to be taken: 0.25 s became 3.3 s with a relay that takes 1.5 s, and 10 s with one that does not
@@ -4336,12 +4222,16 @@ async function session(g, options) {
4336
4222
  requireProfile(g);
4337
4223
  const client = await connectDaemon(g.paths);
4338
4224
  if (client) return throughDaemon(client);
4339
- const [, { callApi }] = await Promise.all([engineHost(), engineApi()]);
4225
+ const [, { callApi, startNamedChats }] = await Promise.all([engineHost(), engineApi()]);
4340
4226
  const host = await openOneShot(g, options);
4341
4227
  if (host instanceof DaemonClient) return throughDaemon(host);
4228
+ const call = (m, p) => {
4229
+ if (options.deferChats && p && typeof p === "object") startNamedChats(host.ctx, p);
4230
+ return callApi(host.ctx, m, p ?? {});
4231
+ };
4342
4232
  return {
4343
4233
  mode: "one-shot",
4344
- call: (m, p) => callApi(host.ctx, m, p ?? {}),
4234
+ call,
4345
4235
  close: () => host.close(),
4346
4236
  abort: () => host.close()
4347
4237
  };
@@ -4402,8 +4292,8 @@ async function openOneShot(g, options = {}, mode = "one-shot") {
4402
4292
  }
4403
4293
  /**
4404
4294
  * How a one-shot opens the profile: `deferGroups` when the command is about one 1:1 chat (`chatOnly`) and needs
4405
- * nothing of the groups, `deferChats` too when it makes a new chat (`newChatOnly`), `offline` when it only reads or
4406
- * changes only this device (`offlineCall`).
4295
+ * nothing of the groups, `deferChats` too when it names that chat or makes or joins a new one (`oneChatOnly`), `offline`
4296
+ * when it only reads or changes only this device (`offlineCall`).
4407
4297
  */
4408
4298
  async function withSession(g, work, options = {}) {
4409
4299
  const s = await session(g, options);
@@ -4510,10 +4400,19 @@ async function oneShotJoinWait(s, result, label) {
4510
4400
  note: `Not paired yet: the inviter's app is offline. It pairs when both are online: keep this profile running (ghostly daemon --detach), then ghostly chat wait ${label?.trim() && !/\s/.test(label.trim()) ? label.trim() : String(result.chat)} --until paired`
4511
4401
  };
4512
4402
  }
4403
+ /**
4404
+ * Stdin up to `INPUT_BYTES` (commands/shared.ts, as `readInput` reads it where a command reads it at once); more is refused as it comes. It was read to its end first: `send bob --stdin < big.log`
4405
+ * with 1 GiB took 3 GB and answered V8's "Cannot create a string longer than 0x1fffffe8 characters", 128 MiB to
4406
+ * `settings set nick -` ran the CLI out of memory, an endless pipe never ended, and past 16 MiB a daemon cut the line,
4407
+ * answered "The daemon went away".
4408
+ */
4513
4409
  async function readStdin(onData) {
4514
4410
  const chunks = [];
4411
+ let bytes = 0;
4515
4412
  for await (const chunk of process.stdin) {
4516
4413
  onData?.();
4414
+ bytes += chunk.length;
4415
+ if (bytes > 16777216) throw new CliError("bad_request", STDIN_TOO_BIG);
4517
4416
  chunks.push(chunk);
4518
4417
  }
4519
4418
  return Buffer.concat(chunks).toString("utf8");
@@ -4529,7 +4428,8 @@ var SPECIAL = [
4529
4428
  "Make a profile (its own keys, chats and wallets)",
4530
4429
  {
4531
4430
  use: o("boolean", "Make it the current profile"),
4532
- name: o("string", "The name contacts see")
4431
+ name: o("string", "The name contacts see"),
4432
+ force: o("boolean", "Use --name even if it looks like a seed, a key or ecash")
4533
4433
  }
4534
4434
  ],
4535
4435
  ["profile list", "Profiles, and which one is current"],
@@ -4540,7 +4440,8 @@ var SPECIAL = [
4540
4440
  "Change the name contacts see",
4541
4441
  {
4542
4442
  name: o("string", "The name contacts see"),
4543
- "share-profile": o("boolean", "Share the name and picture with contacts (--no-share-profile: do not)")
4443
+ "share-profile": o("boolean", "Share the name and picture with contacts (--no-share-profile: do not)"),
4444
+ force: o("boolean", "Use --name even if it looks like a seed, a key or ecash")
4544
4445
  }
4545
4446
  ],
4546
4447
  [
@@ -4608,7 +4509,11 @@ var SPECIAL = [
4608
4509
  "The profile's settings",
4609
4510
  { "show-secret": o("boolean", "Show credentials too") }
4610
4511
  ],
4611
- ["settings set <key> <json-value>", "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"],
4512
+ [
4513
+ "settings set <key> <json-value>",
4514
+ "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",
4515
+ { force: o("boolean", "Set a nick even if it looks like a seed, a key or ecash") }
4516
+ ],
4612
4517
  [
4613
4518
  "engine <method> [json-params | -] [--confirm-real] [--show-secret] [--yes] [--force]",
4614
4519
  "Any call of the app's engine, with its own parameters (engine --list --verbose names them)",
@@ -4815,6 +4720,10 @@ async function profileCommand(sub, argv) {
4815
4720
  name: {
4816
4721
  type: "string",
4817
4722
  description: ""
4723
+ },
4724
+ force: {
4725
+ type: "boolean",
4726
+ description: ""
4818
4727
  }
4819
4728
  },
4820
4729
  backup: {
@@ -4854,6 +4763,10 @@ async function profileCommand(sub, argv) {
4854
4763
  type: "boolean",
4855
4764
  description: "",
4856
4765
  eitherWay: true
4766
+ },
4767
+ force: {
4768
+ type: "boolean",
4769
+ description: ""
4857
4770
  }
4858
4771
  }
4859
4772
  }[sub ?? ""] ?? {}, void 0, { command: commandOf("profile", sub) });
@@ -4865,6 +4778,8 @@ async function profileCommand(sub, argv) {
4865
4778
  if (!name) throw new CliError("usage", "Missing <name>: ghostly profile create <name> [--use] [--name <shown name>]");
4866
4779
  noMoreThan(1, parsed.positionals, "profile create <name> [--use] [--name <shown name>]");
4867
4780
  const shownName = parsed.options.name === void 0 ? void 0 : checkShownName(parsed.options.name);
4781
+ const force = parsed.options.force === true;
4782
+ if (shownName) (await import("./secretGuard-Q2BKq0q0.js")).guardText(shownName, force, "name", "set it");
4868
4783
  const paths = createProfile(g.home, name);
4869
4784
  let shown = null;
4870
4785
  if (shownName !== void 0) try {
@@ -4872,7 +4787,10 @@ async function profileCommand(sub, argv) {
4872
4787
  ...g,
4873
4788
  profile: name,
4874
4789
  paths
4875
- }, (s) => s.call("profile.set", { name: shownName }));
4790
+ }, (s) => s.call("profile.set", {
4791
+ name: shownName,
4792
+ force
4793
+ }));
4876
4794
  } catch (e) {
4877
4795
  rmSync(paths.dir, {
4878
4796
  recursive: true,
@@ -4920,6 +4838,7 @@ async function profileCommand(sub, argv) {
4920
4838
  if (parsed.options.name !== void 0) params.name = parsed.options.name;
4921
4839
  if (parsed.options["share-profile"] !== void 0) params.shareProfile = parsed.options["share-profile"];
4922
4840
  if (!Object.keys(params).length) throw new CliError("usage", "Nothing to change: ghostly profile set [--name <name>] [--share-profile | --no-share-profile]");
4841
+ if (parsed.options.force === true) params.force = true;
4923
4842
  print(await withSession(g, (s) => s.call("profile.set", params)));
4924
4843
  return;
4925
4844
  }
@@ -4951,7 +4870,7 @@ async function profileCommand(sub, argv) {
4951
4870
  if (!given || !name) throw new CliError("usage", `Missing <${given ? "new profile" : "file"}>: ghostly profile restore <file> <new profile> [--passphrase-file f] [--use]`);
4952
4871
  noMoreThan(2, parsed.positionals, "profile restore <file> <new profile> [--passphrase-file f] [--use]");
4953
4872
  const file = here(given);
4954
- const { backupFileProtection, restoreProfile } = await import("./backup-BserdrNk.js");
4873
+ const { backupFileProtection, restoreProfile } = await import("./backup-BvIFcZM7.js");
4955
4874
  const protection = await backupFileProtection(file);
4956
4875
  const paths = await restoreProfile(g.home, checkProfileName(name), file, protection === "none" ? void 0 : backupPassphrase(parsed.options["passphrase-file"], RESTORE_PASSPHRASE));
4957
4876
  if (parsed.options.use) selectProfile(g.home, name);
@@ -5023,6 +4942,7 @@ async function runDaemon(g, seconds) {
5023
4942
  requireProfile(g);
5024
4943
  const detached = process.env[DETACHED_CHILD] === "1";
5025
4944
  delete process.env[DETACHED_CHILD];
4945
+ dropSecretEnv();
5026
4946
  const { keepServing, openHost, serve } = await engineHost();
5027
4947
  const until = Date.now() + seconds * 1e3;
5028
4948
  let host;
@@ -5262,6 +5182,7 @@ function processAlive(pid) {
5262
5182
  */
5263
5183
  async function startDetached(g, seconds) {
5264
5184
  requireProfile(g);
5185
+ ownProfile(g.paths.dir);
5265
5186
  const until = Date.now() + seconds * 1e3;
5266
5187
  for (;;) {
5267
5188
  if (await connectDaemon(g.paths)) throw new CliError("busy", `A daemon already runs profile ${g.profile}`);
@@ -5295,7 +5216,7 @@ async function spawnDaemon(g, until) {
5295
5216
  log
5296
5217
  ],
5297
5218
  env: {
5298
- ...process.env,
5219
+ ...childEnv(process.env),
5299
5220
  [DETACHED_CHILD]: "1"
5300
5221
  }
5301
5222
  });
@@ -5617,10 +5538,16 @@ async function engineCommand(argv) {
5617
5538
  print(result);
5618
5539
  }
5619
5540
  async function settingsCommand(sub, argv) {
5620
- const parsed = parseArgs(argv, { "show-secret": {
5621
- type: "boolean",
5622
- description: ""
5623
- } }, void 0, {
5541
+ const parsed = parseArgs(argv, {
5542
+ "show-secret": {
5543
+ type: "boolean",
5544
+ description: ""
5545
+ },
5546
+ force: {
5547
+ type: "boolean",
5548
+ description: ""
5549
+ }
5550
+ }, void 0, {
5624
5551
  command: commandOf("settings", sub),
5625
5552
  text: sub === "set"
5626
5553
  });
@@ -5644,7 +5571,11 @@ async function settingsCommand(sub, argv) {
5644
5571
  parsedValue = value;
5645
5572
  }
5646
5573
  if ((await engineApi()).SETTABLE[key] === "string" && typeof parsedValue !== "string") parsedValue = value;
5647
- printAnswer(await withSession(g, (s) => s.call("settings.set", { [key]: parsedValue }), { offline: LOCAL_SETTINGS.has(key) }));
5574
+ const force = parsed.options.force === true ? { force: true } : {};
5575
+ printAnswer(await withSession(g, (s) => s.call("settings.set", {
5576
+ [key]: parsedValue,
5577
+ ...force
5578
+ }), { offline: LOCAL_SETTINGS.has(key) }));
5648
5579
  return;
5649
5580
  }
5650
5581
  throw unknownCommand("settings", sub);
@@ -5678,7 +5609,7 @@ async function textCommand(name, argv) {
5678
5609
  };
5679
5610
  if (spec.target === "group") params.mentions = parsed.options.mention ?? [];
5680
5611
  if (parsed.options.reply !== void 0) params.reply = parsed.options.reply;
5681
- if (!spec.message) Object.assign(params, (await import("./buttons-De3LPdSG.js")).buttonsOf(parsed.options));
5612
+ if (!spec.message) Object.assign(params, (await import("./buttons-oJI5mHSL.js")).buttonsOf(parsed.options));
5682
5613
  print(await withSession(g, (s) => {
5683
5614
  if (spec.target === "chat") {
5684
5615
  params.wait = parsed.options.wait ?? (s.mode === "one-shot" ? spec.message ? "confirmed" : "sent" : "none");
@@ -5688,7 +5619,10 @@ async function textCommand(name, argv) {
5688
5619
  if (parsed.options.timeout !== void 0) params.timeout = parsed.options.timeout;
5689
5620
  }
5690
5621
  return s.call(spec.method, params);
5691
- }, { deferGroups: spec.target === "chat" }));
5622
+ }, {
5623
+ deferGroups: spec.target === "chat",
5624
+ deferChats: spec.target === "chat"
5625
+ }));
5692
5626
  }
5693
5627
  /**
5694
5628
  * `identity add`: a proof. An in-app signer finishes in this one command (what it waits on is printed to stderr as it
@@ -5724,7 +5658,7 @@ async function identityAddCommand(argv) {
5724
5658
  if (!provider) throw new CliError("usage", "Missing <provider>: ghostly identity add <provider> [subject] [--signer id] [--field name=value]... [--stdin] [--days n] [--timeout s]");
5725
5659
  inRange(parsed.options, "timeout", "a number of seconds", 5, 3600);
5726
5660
  const items = parsed.options.field ?? [];
5727
- const known = parsed.options.days !== void 0 || items.length ? (await import("./registry-PTtBMaYZ.js")).IDENTITY_PROVIDERS.find((p) => p.id === provider) : void 0;
5661
+ const known = parsed.options.days !== void 0 || items.length ? (await import("./registry-C5cn80Rw.js")).IDENTITY_PROVIDERS.find((p) => p.id === provider) : void 0;
5728
5662
  if (known && parsed.options.days !== void 0) inRange(parsed.options, "days", "a whole number", 1, known.validity.maxDays, true);
5729
5663
  const { fields, warning } = await identityFields(items, parsed.options.stdin === true, identitySecretFields(known, parsed.options.signer), readStdin, process.stdin.isTTY === true);
5730
5664
  if (warning) process.stderr.write(`ghostly: ${warning}\n`);
@@ -5794,7 +5728,7 @@ async function tableCommand(name, argv) {
5794
5728
  const pipedEvidence = command.method === "identity.complete" && !params.evidenceFile && !params.stdin && process.stdin.isTTY !== true;
5795
5729
  if (command.method === "identity.complete") {
5796
5730
  if (params.evidenceFile) try {
5797
- params.evidence = readFileSync(params.evidenceFile, "utf8");
5731
+ params.evidence = readInput(params.evidenceFile);
5798
5732
  } catch (error) {
5799
5733
  throw localFileError(error, params.evidenceFile) ?? error;
5800
5734
  }
@@ -5804,9 +5738,9 @@ async function tableCommand(name, argv) {
5804
5738
  }
5805
5739
  if (command.method === "x401.credential.add") {
5806
5740
  try {
5807
- params.credential = params.file === "-" ? await readStdin() : readFileSync(params.file, "utf8");
5741
+ params.credential = params.file === "-" ? await readStdin() : readInput(params.file);
5808
5742
  } catch (error) {
5809
- throw localFileError(error, params.file) ?? new CliError("usage", `Cannot read the credential: ${error instanceof Error ? error.message : String(error)}`);
5743
+ throw error instanceof CliError && error || localFileError(error, params.file) || new CliError("usage", `Cannot read the credential: ${error instanceof Error ? error.message : String(error)}`);
5810
5744
  }
5811
5745
  if (!params.credential && params.file === "-") throw new CliError("usage", "Missing <file|->: give the SD-JWT VC on stdin (… | ghostly x401 credential add -) or as a file");
5812
5746
  if (!params.credential) throw new CliError("bad_request", `${params.file} is empty: it holds the SD-JWT VC the issuer sent`);
@@ -5828,13 +5762,13 @@ async function tableCommand(name, argv) {
5828
5762
  }
5829
5763
  return result;
5830
5764
  }, {
5831
- deferGroups: chatOnly(command.method, params) || newChatOnly(command.method),
5832
- deferChats: newChatOnly(command.method),
5765
+ deferGroups: chatOnly(command.method, params) || oneChatOnly(command.method, params),
5766
+ deferChats: oneChatOnly(command.method, params),
5833
5767
  offline: offlineCall(command.method, params)
5834
5768
  });
5835
5769
  if (translator) {
5836
5770
  try {
5837
- printAnswer(await (await import("./translate-D1uP0q32.js")).translateAnswer(result, translator));
5771
+ printAnswer(await (await import("./translate-Cb-6hMhD.js")).translateAnswer(result, translator));
5838
5772
  } finally {
5839
5773
  translator.close();
5840
5774
  }
@@ -6055,4 +5989,4 @@ async function run(argv) {
6055
5989
  //#endregion
6056
5990
  export { run };
6057
5991
 
6058
- //# sourceMappingURL=main-BbhfMTt8.js.map
5992
+ //# sourceMappingURL=main-Bc4Ow56Z.js.map