@ghostlytools/cli 1.11.3 → 1.11.4
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.
- package/README.md +27 -22
- package/SKILL.md +4 -2
- package/dist/assets/{api-DgU4MZPD.js → api-BwyFq4lA.js} +2 -2
- package/dist/assets/{api-DBlaoz8i.js → api-MYc6QNRs.js} +187 -87
- package/dist/assets/api-MYc6QNRs.js.map +1 -0
- package/dist/assets/{apiKit-DesObIDf.js → apiKit-CfsNx9ZR.js} +60 -14
- package/dist/assets/apiKit-CfsNx9ZR.js.map +1 -0
- package/dist/assets/{appFetch-C8yZIq1e.js → appFetch-DVYZOZFw.js} +2 -2
- package/dist/assets/{appFetch-C8yZIq1e.js.map → appFetch-DVYZOZFw.js.map} +1 -1
- package/dist/assets/{apps-rzxsjfBV.js → apps-Dbw2Hcko.js} +1 -1
- package/dist/assets/{apps-DkMjDHML.js → apps-h12II1us.js} +52 -30
- package/dist/assets/apps-h12II1us.js.map +1 -0
- package/dist/assets/{arkade-CarKONmH.js → arkade-Bw_4PZRG.js} +2 -2
- package/dist/assets/{arkade-CarKONmH.js.map → arkade-Bw_4PZRG.js.map} +1 -1
- package/dist/assets/{backup-CgWU7x0T.js → backup-CdEzTq5C.js} +1 -1
- package/dist/assets/{backup-C0OJCJlM.js → backup-Chvy79SN.js} +49 -36
- package/dist/assets/backup-Chvy79SN.js.map +1 -0
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/{buttons-fZTEa_2i.js → buttons-BgoExb4E.js} +6 -5
- package/dist/assets/{buttons-fZTEa_2i.js.map → buttons-BgoExb4E.js.map} +1 -1
- package/dist/assets/buttons-DK2aAGat.js +2 -0
- package/dist/assets/{client-Ibk3-e60.js → client-DY8tZZWi.js} +28 -8
- package/dist/assets/client-DY8tZZWi.js.map +1 -0
- package/dist/assets/{codec-DMpQqVSt.js → codec-BnMg-Grj.js} +2 -2
- package/dist/assets/{codec-DMpQqVSt.js.map → codec-BnMg-Grj.js.map} +1 -1
- package/dist/assets/{envelope-CvQVCGdf.js → envelope-CdV7vHVZ.js} +2 -2
- package/dist/assets/{envelope-CvQVCGdf.js.map → envelope-CdV7vHVZ.js.map} +1 -1
- package/dist/assets/{errors-Dt-ZnyOX.js → errors-CAh6GLJZ.js} +27 -2
- package/dist/assets/errors-CAh6GLJZ.js.map +1 -0
- package/dist/assets/{fedimintSdk-zV_5Qdqz.js → fedimintSdk-CPFfVK-G.js} +2 -2
- package/dist/assets/{fedimintSdk-zV_5Qdqz.js.map → fedimintSdk-CPFfVK-G.js.map} +1 -1
- package/dist/assets/{fixedHosts-6gKn8dp2.js → fixedHosts-CbgqrIKs.js} +3 -3
- package/dist/assets/{fixedHosts-6gKn8dp2.js.map → fixedHosts-CbgqrIKs.js.map} +1 -1
- package/dist/assets/{host-CYlIiY3r.js → host-C0NMNQLl.js} +556 -126
- package/dist/assets/host-C0NMNQLl.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CdsLcAhY.js → hyperdhtRelay-Dz7pvcBA.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CdsLcAhY.js.map → hyperdhtRelay-Dz7pvcBA.js.map} +1 -1
- package/dist/assets/{irohWeb-D2IuloLL.js → irohWeb-caAj4Dms.js} +7 -7
- package/dist/assets/{irohWeb-D2IuloLL.js.map → irohWeb-caAj4Dms.js.map} +1 -1
- package/dist/assets/{main-C0PfjKTe.js → main-C6t5zrD5.js} +298 -92
- package/dist/assets/main-C6t5zrD5.js.map +1 -0
- package/dist/assets/{mainline-Cu61qcPS.js → mainline-DCuGUSZF.js} +2 -2
- package/dist/assets/{mainline-Cu61qcPS.js.map → mainline-DCuGUSZF.js.map} +1 -1
- package/dist/assets/{networkReason-Dt7Yx_n4.js → networkReason-BbQW1Xpc.js} +3 -3
- package/dist/assets/{networkReason-Dt7Yx_n4.js.map → networkReason-BbQW1Xpc.js.map} +1 -1
- package/dist/assets/{nwc-CtZypDcv.js → nwc-CSDRMZ0e.js} +3 -3
- package/dist/assets/{nwc-CtZypDcv.js.map → nwc-CSDRMZ0e.js.map} +1 -1
- package/dist/assets/{nwcProvider-DYHkd0iu.js → nwcProvider-PE0wli8n.js} +2 -2
- package/dist/assets/{nwcProvider-DYHkd0iu.js.map → nwcProvider-PE0wli8n.js.map} +1 -1
- package/dist/assets/{ownDid-CJ0ta8CL.js → ownDid-C1R5Kd8q.js} +2 -2
- package/dist/assets/{ownDid-CJ0ta8CL.js.map → ownDid-C1R5Kd8q.js.map} +1 -1
- package/dist/assets/{ownStatus-D4HC6tNR.js → ownStatus-BoTf5WqQ.js} +19 -6
- package/dist/assets/ownStatus-BoTf5WqQ.js.map +1 -0
- package/dist/assets/{profiles-Ccdq6Xf6.js → profiles-DszHjEJi.js} +25 -10
- package/dist/assets/profiles-DszHjEJi.js.map +1 -0
- package/dist/assets/{registry-LvxsLJ5S.js → registry-Da-r6eC3.js} +17 -10
- package/dist/assets/registry-Da-r6eC3.js.map +1 -0
- package/dist/assets/{registry-CE0PpQAE.js → registry-zUZBSHYv.js} +1 -1
- package/dist/assets/{resolve-6kVu2DE5.js → resolve-tUzh4lHh.js} +2 -2
- package/dist/assets/{resolve-6kVu2DE5.js.map → resolve-tUzh4lHh.js.map} +1 -1
- package/dist/assets/{secretGuard-B7Hj0Kvz.js → secretGuard-CsVHDdYk.js} +68 -6
- package/dist/assets/{secretGuard-B7Hj0Kvz.js.map → secretGuard-CsVHDdYk.js.map} +1 -1
- package/dist/assets/secretGuard-DCb1I0_B.js +2 -0
- package/dist/assets/{server-Q3VcNqGt.js → server-C1jZZ61O.js} +667 -196
- package/dist/assets/server-C1jZZ61O.js.map +1 -0
- package/dist/assets/{src-DjVj2ynY.js → src-DJe-OYxd.js} +826 -198
- package/dist/assets/src-DJe-OYxd.js.map +1 -0
- package/dist/assets/{sshForges-DeZ9cN9Q.js → sshForges-C9zTO72R.js} +2 -2
- package/dist/assets/{sshForges-DeZ9cN9Q.js.map → sshForges-C9zTO72R.js.map} +1 -1
- package/dist/assets/{translate-iQZq4TnY.js → translate-CUuC5szR.js} +3 -3
- package/dist/assets/{translate-iQZq4TnY.js.map → translate-CUuC5szR.js.map} +1 -1
- package/dist/assets/{usdt-DnyTGdTX.js → usdt-DI51znt-.js} +3 -3
- package/dist/assets/{usdt-DnyTGdTX.js.map → usdt-DI51znt-.js.map} +1 -1
- package/dist/ghostly.mjs +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/assets/api-DBlaoz8i.js.map +0 -1
- package/dist/assets/apiKit-DesObIDf.js.map +0 -1
- package/dist/assets/apps-DkMjDHML.js.map +0 -1
- package/dist/assets/backup-C0OJCJlM.js.map +0 -1
- package/dist/assets/buttons-Cco0Agfa.js +0 -2
- package/dist/assets/client-Ibk3-e60.js.map +0 -1
- package/dist/assets/errors-Dt-ZnyOX.js.map +0 -1
- package/dist/assets/host-CYlIiY3r.js.map +0 -1
- package/dist/assets/main-C0PfjKTe.js.map +0 -1
- package/dist/assets/ownStatus-D4HC6tNR.js.map +0 -1
- package/dist/assets/profiles-Ccdq6Xf6.js.map +0 -1
- package/dist/assets/registry-LvxsLJ5S.js.map +0 -1
- package/dist/assets/secretGuard-DUr6bgKc.js +0 -2
- package/dist/assets/server-Q3VcNqGt.js.map +0 -1
- package/dist/assets/src-DjVj2ynY.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Ao as
|
|
2
|
-
import { i as localFileError, n as EXIT, r as asCliError, t as CliError } from "./errors-
|
|
3
|
-
import { a as PAY_METHODS, c as turnRef, d as ENGINE_METHODS, f as ENGINE_PARAMS, h as SECRET_RESULTS, i as CHAT_METHODS, m as READ_PARAMS, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus } from "./ownStatus-
|
|
4
|
-
import { a as contactKeyOf, v as nameKey, y as namedByThem } from "./apiKit-
|
|
1
|
+
import { Ao as PR_CHECKS, Bo as cardUrl, Fo as TASK_STATUSES, Ga as VOICE_LIMITS, Mo as ROUTINE_STATES, No as RUN_RESULTS, Oo as CRON_LINE, Po as STATUS_CARD_LIMITS, Uo as statusCardBytes, ei as STATUS_AVAILABILITIES, jo as PR_STATES, ko as ITEM_STATES, lr as GROUP_FILE_LIMITS, vo as reactionEmoji, zo as cardLine } from "./src-DJe-OYxd.js";
|
|
2
|
+
import { i as localFileError, n as EXIT, r as asCliError, t as CliError } from "./errors-CAh6GLJZ.js";
|
|
3
|
+
import { _ as hideSecretFields, a as PAY_METHODS, c as turnRef, d as ENGINE_METHODS, f as ENGINE_PARAMS, h as SECRET_RESULTS, i as CHAT_METHODS, m as READ_PARAMS, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus } from "./ownStatus-BoTf5WqQ.js";
|
|
4
|
+
import { a as contactKeyOf, v as nameKey, y as namedByThem } from "./apiKit-CfsNx9ZR.js";
|
|
5
5
|
import { n as dropSecretEnv, t as childEnv } from "./childEnv-K_IzUqQx.js";
|
|
6
6
|
import { i as waitsFor, r as waitNotice } from "./waitNotice-Cn0WJ-He.js";
|
|
7
|
-
import {
|
|
7
|
+
import { S as userPath, _ as profileExists, b as startingDaemon, c as createProfile, d as daemonClaim, f as ghostlyHome, g as noProfile, i as checkProfileName, l as currentProfile, m as lockOwner, o as checkShownNameOption, p as listProfiles, s as claimForDaemon, u as currentProfileOrNone, v as profilePaths, w as ownProfile, y as selectProfile } from "./profiles-DszHjEJi.js";
|
|
8
8
|
import { t as jsonOut } from "./jsonOut-POtMBS_V.js";
|
|
9
|
-
import { a as endedUnsent,
|
|
9
|
+
import { a as endedUnsent, i as endedUnanswered, o as isNotTheDaemon, p as CALL_RATES, r as connectDaemon, s as notTheDaemon, t as DaemonClient, y as isCallRate } from "./client-DY8tZZWi.js";
|
|
10
10
|
import { spawn } from "node:child_process";
|
|
11
11
|
import { accessSync, closeSync, constants, existsSync, fstatSync, openSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
12
12
|
import { dirname, resolve, sep } from "node:path";
|
|
@@ -14,7 +14,7 @@ import { connect } from "node:net";
|
|
|
14
14
|
import { format } from "node:util";
|
|
15
15
|
var package_default = {
|
|
16
16
|
name: "@ghostlytools/cli",
|
|
17
|
-
version: "1.11.
|
|
17
|
+
version: "1.11.4",
|
|
18
18
|
type: "module",
|
|
19
19
|
description: "Ghostly for bots and terminals: the app's own engine, headless on Node, behind a daemon and a `ghostly` command with JSON output.",
|
|
20
20
|
license: "MIT",
|
|
@@ -262,6 +262,24 @@ function distance(a, b) {
|
|
|
262
262
|
}
|
|
263
263
|
return d[a.length][b.length];
|
|
264
264
|
}
|
|
265
|
+
var SETTINGS_SET = "ghostly settings set <key> <json-value> [--force]";
|
|
266
|
+
/**
|
|
267
|
+
* A key `settings set` does not take is a usage error that names the nearest one (whatever its case: `sendtyping`)
|
|
268
|
+
* and lists them, before stdin is read and the profile opens. Before, the API answered it once a one-shot was online
|
|
269
|
+
* (bad_request, exit 1), with no "did you mean". The API keeps its own check for a socket's callers.
|
|
270
|
+
*/
|
|
271
|
+
function checkSettingKey(key, kinds) {
|
|
272
|
+
if (Object.hasOwn(kinds, key)) return kinds[key];
|
|
273
|
+
const byLower = new Map(Object.keys(kinds).map((name) => [name.toLowerCase(), name]));
|
|
274
|
+
const near = byLower.get(nearest(key.toLowerCase(), byLower.keys()) ?? "");
|
|
275
|
+
throw new CliError("usage", `${key} is not a setting the CLI changes${near ? ` (did you mean ${near}?)` : ""}: ghostly settings set takes ${Object.keys(kinds).join(", ")} (ghostly help settings set)`);
|
|
276
|
+
}
|
|
277
|
+
/** A value of another kind than its key takes (`online maybe`): a usage error too, before the profile opens. */
|
|
278
|
+
function checkSettingValue(key, kind, value, typed) {
|
|
279
|
+
if (kind === "boolean" && typeof value !== "boolean") throw new CliError("usage", `${key} takes true or false, not ${JSON.stringify(typed)}: ${SETTINGS_SET}`);
|
|
280
|
+
if (kind === "strings" && !(Array.isArray(value) && value.every((v) => typeof v === "string"))) throw new CliError("usage", `${key} takes a JSON list of strings: ${SETTINGS_SET}`);
|
|
281
|
+
if (kind === "ice" && !(Array.isArray(value) && value.every((v) => v && typeof v === "object"))) throw new CliError("usage", `${key} takes a JSON list of ICE servers: ${SETTINGS_SET}`);
|
|
282
|
+
}
|
|
265
283
|
/** Words as a sentence lists them: "a", "a or b", "a, b or c". */
|
|
266
284
|
var listed$1 = (words) => words.length > 1 ? `${words.slice(0, -1).join(", ")} or ${words.at(-1)}` : words[0];
|
|
267
285
|
/** The global option a word names (`--profile`, `--profile=bot`, `-p`), else undefined. */
|
|
@@ -364,6 +382,28 @@ function here(path) {
|
|
|
364
382
|
if (path === "") throw new CliError("usage", "A path given as \"\" names no file");
|
|
365
383
|
return typeof path === "string" ? userPath(path) : void 0;
|
|
366
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* A path on this machine a command reads (`file send`, a picture, `profile backup --out`'s folder), looked at before the
|
|
387
|
+
* profile opens: one not there is not_found (`missing`, or "No such file or folder"), one not allowed refused. Before, a
|
|
388
|
+
* one-shot opened the profile and went online first (~1 s on a big profile) to say so. The API keeps its check for
|
|
389
|
+
* socket callers; through a daemon it reads the same path.
|
|
390
|
+
*/
|
|
391
|
+
function localStat(path, missing) {
|
|
392
|
+
try {
|
|
393
|
+
return statSync(path);
|
|
394
|
+
} catch (error) {
|
|
395
|
+
const known = localFileError(error, path);
|
|
396
|
+
throw known?.code === "not_found" && missing ? new CliError("not_found", missing) : known ?? error;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* A picture's file (`profile picture`, `group picture`), in the API's words (groupAdmin.ts) when it is not there or a
|
|
401
|
+
* folder. Only a folder is refused here: a pipe (`<(…)`) is read as a file.
|
|
402
|
+
*/
|
|
403
|
+
function picture(path) {
|
|
404
|
+
if (path !== void 0 && localStat(path).isDirectory()) throw new CliError("bad_request", `${path} is a folder: name a file`);
|
|
405
|
+
return path;
|
|
406
|
+
}
|
|
367
407
|
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>)";
|
|
368
408
|
/**
|
|
369
409
|
* A file's text, or stdin's (`0`), up to `INPUT_BYTES`: more is refused as it comes. `app send … -`, a card's `--json`
|
|
@@ -413,7 +453,7 @@ function pairs(values) {
|
|
|
413
453
|
const out = {};
|
|
414
454
|
for (const item of values) {
|
|
415
455
|
const eq = item.indexOf("=");
|
|
416
|
-
if (eq < 1) throw new CliError("usage",
|
|
456
|
+
if (eq < 1) throw new CliError("usage", "--value takes name=value, and one has no name or no =");
|
|
417
457
|
out[item.slice(0, eq)] = item.slice(eq + 1);
|
|
418
458
|
}
|
|
419
459
|
return out;
|
|
@@ -485,6 +525,18 @@ function typingFor(options) {
|
|
|
485
525
|
return seconds;
|
|
486
526
|
}
|
|
487
527
|
/**
|
|
528
|
+
* The `<emoji>` of `react` and `group react`: one emoji (core's `reactionEmoji`), or none with `--remove`. Anything else
|
|
529
|
+
* is a usage error (exit 2) before the profile opens, as `status set --emoji` is. Before, a one-shot opened the profile
|
|
530
|
+
* and went online first, then the engine answered "A reaction is one emoji" (`bad_request`, exit 1), and a missing one
|
|
531
|
+
* "Give one emoji" (exit 2) only from there. The API keeps its checks for socket callers.
|
|
532
|
+
*/
|
|
533
|
+
function reaction(options, emoji) {
|
|
534
|
+
if (options.remove === true) return emoji;
|
|
535
|
+
if (!emoji) throw new CliError("usage", "Give one emoji, or --remove to take yours back");
|
|
536
|
+
if (!reactionEmoji(emoji)) throw new CliError("usage", `<emoji> takes one emoji, not ${JSON.stringify(emoji)}`);
|
|
537
|
+
return emoji;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
488
540
|
* The ranges the API takes (api.ts, files.ts): the most minutes of a `--hold` (a week, HOLD_MAX_MINUTES), seconds;
|
|
489
541
|
* `chat connect`'s, the chat link's own wait for a contact (CONNECT_MAX_SECONDS).
|
|
490
542
|
*/
|
|
@@ -1065,6 +1117,14 @@ function keyFile(value, usage) {
|
|
|
1065
1117
|
if (typeof value !== "string" || !value) throw new CliError("usage", `--key <file> is needed: ghostly ${usage}`);
|
|
1066
1118
|
return value;
|
|
1067
1119
|
}
|
|
1120
|
+
/**
|
|
1121
|
+
* `app serve`'s bundle file, in the API's words (apps.ts) when it is not there or a folder: said before the profile
|
|
1122
|
+
* opens. Before, a one-shot went online first (about 12 s with no daemon) to say the file was not there.
|
|
1123
|
+
*/
|
|
1124
|
+
function bundleFile(path) {
|
|
1125
|
+
if (localStat(path).isDirectory()) throw new CliError("bad_request", `${path} is a folder: name a .ghostlyapp file`);
|
|
1126
|
+
return path;
|
|
1127
|
+
}
|
|
1068
1128
|
/** `app send`'s message: JSON on the command line, or `-` for stdin. */
|
|
1069
1129
|
function appData(value) {
|
|
1070
1130
|
if (value === void 0) throw new CliError("usage", "The message is needed, as JSON or - for stdin: ghostly app send <chat> <ref|name> <json|->");
|
|
@@ -1114,7 +1174,7 @@ var commands$8 = {
|
|
|
1114
1174
|
description: "Replace the three files when they are there"
|
|
1115
1175
|
}
|
|
1116
1176
|
},
|
|
1117
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1177
|
+
run: async ({ options }, a) => (await import("./apps-Dbw2Hcko.js")).initApp(a.dir, {
|
|
1118
1178
|
name: options.name,
|
|
1119
1179
|
title: options.title,
|
|
1120
1180
|
force: options.force === true
|
|
@@ -1154,7 +1214,7 @@ var commands$8 = {
|
|
|
1154
1214
|
description: "This version's sequence, higher than the bundle at --out's (default: one more than it)"
|
|
1155
1215
|
}
|
|
1156
1216
|
},
|
|
1157
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1217
|
+
run: async ({ options }, a) => (await import("./apps-Dbw2Hcko.js")).publishApp(a.dir, keyFile(options.key, "app publish <dir> --key <file> [--out <file>] [--sequence n]"), here(options.out), options.sequence)
|
|
1158
1218
|
},
|
|
1159
1219
|
"app revoke": {
|
|
1160
1220
|
method: "app.revoke",
|
|
@@ -1187,7 +1247,7 @@ var commands$8 = {
|
|
|
1187
1247
|
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"
|
|
1188
1248
|
}
|
|
1189
1249
|
},
|
|
1190
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1250
|
+
run: async ({ options }, a) => (await import("./apps-Dbw2Hcko.js")).revokeApp(a.dir, keyFile(options.key, "app revoke <dir> --key <file> (--digest <digest>... | --up-to <sequence>) [--reason <text>] [--bundle <file>] [--force]"), {
|
|
1191
1251
|
digests: options.digest,
|
|
1192
1252
|
upTo: options["up-to"],
|
|
1193
1253
|
reason: options.reason,
|
|
@@ -1222,11 +1282,11 @@ var commands$8 = {
|
|
|
1222
1282
|
},
|
|
1223
1283
|
url: {
|
|
1224
1284
|
type: "string",
|
|
1225
|
-
description: "Where a contact's app reads the bundle, for the card (default: the
|
|
1285
|
+
description: "Where a contact's app reads the bundle, for the card (raw.githubusercontent.com, or cdn.jsdelivr.net at a commit; default: the first of those it was served from or its manifest names)"
|
|
1226
1286
|
}
|
|
1227
1287
|
},
|
|
1228
1288
|
params: ({ options }, a) => ({
|
|
1229
|
-
bundle: /^[a-z][a-z0-9+.-]*:\/\//i.test(a.bundle ?? "") ? a.bundle : here(a.bundle),
|
|
1289
|
+
bundle: /^[a-z][a-z0-9+.-]*:\/\//i.test(a.bundle ?? "") ? a.bundle : bundleFile(here(a.bundle)),
|
|
1230
1290
|
grant: options.grant,
|
|
1231
1291
|
url: options.url
|
|
1232
1292
|
})
|
|
@@ -1248,7 +1308,7 @@ var commands$8 = {
|
|
|
1248
1308
|
usage: "app verify <bundle|url>",
|
|
1249
1309
|
summary: "Check a .ghostlyapp as a client would, from a file or an https URL: its manifest and digest, or refused (exit 1) with the reason, revoked when the ghostly-revoke.json beside it (for a URL, or beside one of its sources) revokes this version",
|
|
1250
1310
|
args: ["bundle"],
|
|
1251
|
-
run: async (_, a) => (await import("./apps-
|
|
1311
|
+
run: async (_, a) => (await import("./apps-Dbw2Hcko.js")).verifyApp(a.bundle)
|
|
1252
1312
|
},
|
|
1253
1313
|
"store sign": {
|
|
1254
1314
|
method: "store.sign",
|
|
@@ -1265,7 +1325,7 @@ var commands$8 = {
|
|
|
1265
1325
|
description: "The folder to write ghostly-store.json and ghostly-store.sig in (default: the index's)"
|
|
1266
1326
|
}
|
|
1267
1327
|
},
|
|
1268
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1328
|
+
run: async ({ options }, a) => (await import("./apps-Dbw2Hcko.js")).signStore(a.index, keyFile(options.key, "store sign <index> --key <file> [--out <dir>]"), here(options.out))
|
|
1269
1329
|
}
|
|
1270
1330
|
};
|
|
1271
1331
|
//#endregion
|
|
@@ -1455,6 +1515,7 @@ var commands$6 = {
|
|
|
1455
1515
|
timeout: groupWait.timeout
|
|
1456
1516
|
},
|
|
1457
1517
|
params: ({ options }, a) => {
|
|
1518
|
+
if (options.chosen === "") throw new CliError("usage", "--chosen needs a button id");
|
|
1458
1519
|
if (!options.chosen && options.close !== true && !options.text) throw new CliError("usage", `Give --chosen, --close or --text: ghostly ${BUTTON_UPDATE}`);
|
|
1459
1520
|
return {
|
|
1460
1521
|
chat: a.chat,
|
|
@@ -1553,7 +1614,7 @@ var commands$6 = {
|
|
|
1553
1614
|
},
|
|
1554
1615
|
"chat rename": {
|
|
1555
1616
|
method: "chat.rename",
|
|
1556
|
-
usage: "chat rename <chat>
|
|
1617
|
+
usage: "chat rename <chat> [name...]",
|
|
1557
1618
|
summary: "Name a chat on this side (empty: the contact's name)",
|
|
1558
1619
|
args: ["chat", "name...?"],
|
|
1559
1620
|
params: (_, { chat, name }) => ({
|
|
@@ -1788,7 +1849,7 @@ var commands$6 = {
|
|
|
1788
1849
|
params: ({ options }, a) => ({
|
|
1789
1850
|
chat: a.chat,
|
|
1790
1851
|
message: a.message,
|
|
1791
|
-
emoji: a.emoji,
|
|
1852
|
+
emoji: reaction(options, a.emoji),
|
|
1792
1853
|
remove: options.remove === true,
|
|
1793
1854
|
wait: options.wait,
|
|
1794
1855
|
timeout: timeout(options)
|
|
@@ -1977,6 +2038,11 @@ function voiceOf(options) {
|
|
|
1977
2038
|
peaks: bars
|
|
1978
2039
|
};
|
|
1979
2040
|
}
|
|
2041
|
+
/** The file `file send` sends, in the API's words (files.ts) when it is not there or not a file. */
|
|
2042
|
+
function sendable(path) {
|
|
2043
|
+
if (!localStat(path, `No file ${path}`).isFile()) throw new CliError("bad_request", `${path} is not a file`);
|
|
2044
|
+
return path;
|
|
2045
|
+
}
|
|
1980
2046
|
/** Files: one entry per command, in alphabetical order (test/commands.test.ts checks). */
|
|
1981
2047
|
var commands$5 = {
|
|
1982
2048
|
"file accept": {
|
|
@@ -2145,22 +2211,26 @@ var commands$5 = {
|
|
|
2145
2211
|
description: "Send even if --name looks like a seed, a key or ecash"
|
|
2146
2212
|
}
|
|
2147
2213
|
},
|
|
2148
|
-
params: ({ options }, a) =>
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2214
|
+
params: ({ options }, a) => {
|
|
2215
|
+
if (options.reply === "") throw new CliError("usage", "--reply needs a message id");
|
|
2216
|
+
const voice = voiceOf(options), seconds = timeout(options, LONG_WAIT_SECONDS);
|
|
2217
|
+
return {
|
|
2218
|
+
chat: a.chat,
|
|
2219
|
+
path: sendable(here(a.path)),
|
|
2220
|
+
name: options.name,
|
|
2221
|
+
mime: options.mime,
|
|
2222
|
+
...voice,
|
|
2223
|
+
reply: options.reply,
|
|
2224
|
+
force: options.force === true,
|
|
2225
|
+
wait: options.wait,
|
|
2226
|
+
timeout: seconds
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2159
2229
|
},
|
|
2160
2230
|
"file wait": {
|
|
2161
2231
|
method: "file.wait",
|
|
2162
2232
|
usage: "file wait [<chat>] <file> [--timeout s]",
|
|
2163
|
-
summary: "Wait until a transfer is done (exit 0) or failed (exit 1, with its error)",
|
|
2233
|
+
summary: "Wait until a transfer is done (exit 0) or failed (exit 1, with its error); exit 4 on timeout, 5 at once when a received file waits for file accept",
|
|
2164
2234
|
args: ["chat?", "file"],
|
|
2165
2235
|
options: { timeout: {
|
|
2166
2236
|
type: "number",
|
|
@@ -2223,7 +2293,7 @@ var commands$4 = {
|
|
|
2223
2293
|
if (!a.path && options.clear !== true) throw new CliError("usage", "Missing <jpeg>: ghostly profile picture <jpeg> | --clear");
|
|
2224
2294
|
if (a.path && options.clear === true) throw new CliError("usage", "--clear removes the picture: not with a <jpeg>");
|
|
2225
2295
|
return {
|
|
2226
|
-
path: here(a.path || void 0),
|
|
2296
|
+
path: picture(here(a.path || void 0)),
|
|
2227
2297
|
clear: options.clear === true
|
|
2228
2298
|
};
|
|
2229
2299
|
}
|
|
@@ -2508,7 +2578,7 @@ var commands$3 = {
|
|
|
2508
2578
|
if (a.path && options.clear === true) throw new CliError("usage", "--clear removes the picture: not with a <jpeg>");
|
|
2509
2579
|
return {
|
|
2510
2580
|
group: a.group,
|
|
2511
|
-
path: here(a.path || void 0),
|
|
2581
|
+
path: picture(here(a.path || void 0)),
|
|
2512
2582
|
clear: options.clear === true
|
|
2513
2583
|
};
|
|
2514
2584
|
}
|
|
@@ -2536,7 +2606,7 @@ var commands$3 = {
|
|
|
2536
2606
|
params: ({ options }, a) => ({
|
|
2537
2607
|
group: a.group,
|
|
2538
2608
|
message: a.message,
|
|
2539
|
-
emoji: a.emoji,
|
|
2609
|
+
emoji: reaction(options, a.emoji),
|
|
2540
2610
|
remove: options.remove === true,
|
|
2541
2611
|
wait: options.wait,
|
|
2542
2612
|
timeout: timeout(options)
|
|
@@ -2760,6 +2830,15 @@ function networkList(value) {
|
|
|
2760
2830
|
if (!networks.every((n) => n === "mainnet" || n === "testnet")) throw new CliError("usage", `--networks takes mainnet, testnet or mainnet,testnet, not ${JSON.stringify(value)}`);
|
|
2761
2831
|
return networks;
|
|
2762
2832
|
}
|
|
2833
|
+
/**
|
|
2834
|
+
* `chat request`'s amount: whole sats, or with --method usdt USDT as the app's composer reads it (5 is 5 USDT, 0.25 a
|
|
2835
|
+
* quarter), passed on as its text for the API to turn into base units with the wallet's decimals.
|
|
2836
|
+
*/
|
|
2837
|
+
function requestAmount(value, method) {
|
|
2838
|
+
if (method !== "usdt") return sats(value);
|
|
2839
|
+
if (!/^\d+(\.\d+)?$/.test(value ?? "") || !/[1-9]/.test(value)) throw new CliError("usage", `<amount> with --method usdt takes USDT above 0 (5 or 0.25), not ${JSON.stringify(value)}`);
|
|
2840
|
+
return value;
|
|
2841
|
+
}
|
|
2763
2842
|
/** Wallets and payments: one entry per command, in alphabetical order (test/commands.test.ts checks). */
|
|
2764
2843
|
var commands$1 = {
|
|
2765
2844
|
"chat accept": {
|
|
@@ -2839,14 +2918,14 @@ var commands$1 = {
|
|
|
2839
2918
|
"chat request": {
|
|
2840
2919
|
method: "chat.request",
|
|
2841
2920
|
usage: "chat request <chat> <sats> [--memo t] [--method m] [--rail cashu|lightning] [--network testnet] [--card <id>] [--force]",
|
|
2842
|
-
summary: "Ask a contact to pay",
|
|
2921
|
+
summary: "Ask a contact to pay (with --method usdt the amount is in USDT: 5 is 5 USDT)",
|
|
2843
2922
|
args: ["chat", "amount"],
|
|
2844
2923
|
options: {
|
|
2845
2924
|
memo,
|
|
2846
2925
|
method: {
|
|
2847
2926
|
type: "string",
|
|
2848
2927
|
choices: PAY_METHODS,
|
|
2849
|
-
description: "cashu, arkade, usdt, bitcoin, spark, …"
|
|
2928
|
+
description: "cashu, arkade, usdt (amount in USDT), bitcoin, spark, …"
|
|
2850
2929
|
},
|
|
2851
2930
|
rail: {
|
|
2852
2931
|
type: "string",
|
|
@@ -2859,7 +2938,7 @@ var commands$1 = {
|
|
|
2859
2938
|
},
|
|
2860
2939
|
params: ({ options }, a) => ({
|
|
2861
2940
|
chat: a.chat,
|
|
2862
|
-
amount:
|
|
2941
|
+
amount: requestAmount(a.amount, options.method),
|
|
2863
2942
|
memo: options.memo,
|
|
2864
2943
|
method: options.method,
|
|
2865
2944
|
rail: options.rail,
|
|
@@ -3445,11 +3524,14 @@ var Allowlist = class {
|
|
|
3445
3524
|
}
|
|
3446
3525
|
async allows(event) {
|
|
3447
3526
|
if ("group" in event) return typeof event.group === "string" && this.groups.has(event.group);
|
|
3527
|
+
const group = event.payment?.group;
|
|
3528
|
+
if (group !== void 0) return typeof group === "string" && this.groups.has(group);
|
|
3448
3529
|
if (!("chat" in event)) return true;
|
|
3449
3530
|
const chat = event.chat;
|
|
3450
3531
|
if (typeof chat !== "string") return false;
|
|
3451
3532
|
if (this.chats.has(chat)) return true;
|
|
3452
3533
|
if (!this.keys.size) return false;
|
|
3534
|
+
if (event.type === "chat.removed" && typeof event.peer === "string") return this.keys.has(event.peer);
|
|
3453
3535
|
let key = this.peers.get(chat);
|
|
3454
3536
|
if (!key) {
|
|
3455
3537
|
key = await this.peerOf(chat).catch(() => null) || void 0;
|
|
@@ -3485,7 +3567,8 @@ async function allowlist(from, groups, call, peerOf) {
|
|
|
3485
3567
|
}
|
|
3486
3568
|
/**
|
|
3487
3569
|
* A `--from` that names a group, or a `--group` a chat: said with the flag that takes it. The lookup's own hint named
|
|
3488
|
-
* `ghostly group show` (or `chat show`), which lists nothing.
|
|
3570
|
+
* `ghostly group show` (or `chat show`), which lists nothing. A chat is named by its id: `--from` refuses a prefix of it
|
|
3571
|
+
* or the name its contact chose, which `--group`'s lookup took.
|
|
3489
3572
|
*/
|
|
3490
3573
|
async function otherFlag(lookup, ref, flag) {
|
|
3491
3574
|
try {
|
|
@@ -3493,7 +3576,8 @@ async function otherFlag(lookup, ref, flag) {
|
|
|
3493
3576
|
} catch (error) {
|
|
3494
3577
|
const other = flag === "--from" ? "group" : "chat";
|
|
3495
3578
|
if (!(error instanceof CliError) || error.code !== "not_found" || typeof error.details?.[other] !== "string") throw error;
|
|
3496
|
-
const
|
|
3579
|
+
const named = other === "chat" ? error.details.chat : ref;
|
|
3580
|
+
const shown = /^[\w.:-]+$/.test(named) ? named : JSON.stringify(named);
|
|
3497
3581
|
throw new CliError("not_found", `${JSON.stringify(ref)} is a ${other}, not a ${flag === "--from" ? "chat" : "group"}: ghostly listen ${flag === "--from" ? "--group" : "--from"} ${shown}`, error.details);
|
|
3498
3582
|
}
|
|
3499
3583
|
}
|
|
@@ -3734,7 +3818,7 @@ var HOOK_OUTPUT_GRACE_MS = 1e3;
|
|
|
3734
3818
|
* `toStderr` (with `--print`, whose stdout is the JSON stream): the hook's stdout is streamed to listen's stderr, so a
|
|
3735
3819
|
* hook that echoes never puts a line that is not an event into the stream. Piped as it comes, never held in memory.
|
|
3736
3820
|
*/
|
|
3737
|
-
function runExec(command, event, toStderr) {
|
|
3821
|
+
function runExec(command, event, toStderr, profile) {
|
|
3738
3822
|
const group = process.platform !== "win32";
|
|
3739
3823
|
const child = spawn(command, {
|
|
3740
3824
|
shell: true,
|
|
@@ -3746,6 +3830,10 @@ function runExec(command, event, toStderr) {
|
|
|
3746
3830
|
],
|
|
3747
3831
|
env: {
|
|
3748
3832
|
...hookEnv(process.env),
|
|
3833
|
+
...profile ? {
|
|
3834
|
+
GHOSTLY_HOME: profile.home,
|
|
3835
|
+
GHOSTLY_PROFILE: profile.name
|
|
3836
|
+
} : {},
|
|
3749
3837
|
GHOSTLY_EVENT_TYPE: event.type,
|
|
3750
3838
|
GHOSTLY_EVENT_ID: event.id,
|
|
3751
3839
|
GHOSTLY_EVENT_SEQ: String(event.seq)
|
|
@@ -3797,7 +3885,8 @@ function runExec(command, event, toStderr) {
|
|
|
3797
3885
|
/** The longest wait between two tries of a webhook that is not answering. */
|
|
3798
3886
|
var RETRY_MAX_MS = 6e4;
|
|
3799
3887
|
/**
|
|
3800
|
-
* Posts one event; resolves true once the bridge took it, or the status it refused it with (a 4xx or a redirect,
|
|
3888
|
+
* Posts one event; resolves true once the bridge took it, or the status it refused it with (a 4xx or a redirect, posted
|
|
3889
|
+
* once: before, three times with backoff, three refusals in the bridge's log for an event stderr said was not tried again).
|
|
3801
3890
|
* A bridge that is not there (refused connection, timeout, 5xx, 408, 429) has not handled the event: it is tried again,
|
|
3802
3891
|
* waiting up to a minute between tries, for as long as it takes, so the cursor never moves past it. Before, three tries
|
|
3803
3892
|
* in 3.5 s and the cursor moved on: a bridge restarting for longer lost every event of the time it was down, for good.
|
|
@@ -3826,7 +3915,7 @@ async function post(url, event, retryMs) {
|
|
|
3826
3915
|
status = response.status;
|
|
3827
3916
|
down = status >= 500 || status === 408 || status === 429;
|
|
3828
3917
|
} catch {}
|
|
3829
|
-
if (!down
|
|
3918
|
+
if (!down) return status;
|
|
3830
3919
|
if (down && attempt >= 2 && !holding) {
|
|
3831
3920
|
holding = true;
|
|
3832
3921
|
process.stderr.write(`ghostly: the webhook at ${url.origin} is not answering: holding event ${event.seq} (${event.type}) until it does\n`);
|
|
@@ -3888,7 +3977,7 @@ function eventHandler(options) {
|
|
|
3888
3977
|
if (options.turns && !gap) event = toTurn(event);
|
|
3889
3978
|
const full = options.print && options.write(jsonOut(event)) === false;
|
|
3890
3979
|
if (options.exec) {
|
|
3891
|
-
const hook = running = runExec(options.exec, event, options.print);
|
|
3980
|
+
const hook = running = runExec(options.exec, event, options.print, options.profile);
|
|
3892
3981
|
const slow = setTimeout(() => process.stderr.write(`ghostly: --exec still runs on event ${hook.event.seq} (${hook.event.type}) after ${Math.round(slowMs / 1e3)} s: the events after it wait for it\n`), slowMs);
|
|
3893
3982
|
const { code, signal } = await hook.ended.finally(() => {
|
|
3894
3983
|
clearTimeout(slow);
|
|
@@ -4113,6 +4202,7 @@ async function secretsFromStdin(method, params, read, tty = false, note = () =>
|
|
|
4113
4202
|
if (method === "wallet.create") {
|
|
4114
4203
|
const onLine = params.apiKey !== void 0;
|
|
4115
4204
|
if (params.stdin === true) {
|
|
4205
|
+
if (tty) throw new CliError("usage", "--stdin takes the values as name=value lines piped to it (… | ghostly wallet create <type> --stdin), not a terminal");
|
|
4116
4206
|
const values = { ...params.values };
|
|
4117
4207
|
for (const line of (await read()).split(/\r?\n/)) {
|
|
4118
4208
|
if (!line.trim()) continue;
|
|
@@ -4129,6 +4219,17 @@ async function secretsFromStdin(method, params, read, tty = false, note = () =>
|
|
|
4129
4219
|
}
|
|
4130
4220
|
}
|
|
4131
4221
|
/**
|
|
4222
|
+
* `x401 credential add -`: the SD-JWT VC from stdin. Nothing there, or a terminal (a read that would wait on the
|
|
4223
|
+
* keyboard without a word), is the usage error a join gives.
|
|
4224
|
+
*/
|
|
4225
|
+
async function credentialFromStdin(read, tty = false) {
|
|
4226
|
+
const missing = () => new CliError("usage", "Missing <file|->: give the SD-JWT VC on stdin (… | ghostly x401 credential add -) or as a file");
|
|
4227
|
+
if (tty) throw missing();
|
|
4228
|
+
const credential = await read();
|
|
4229
|
+
if (!credential) throw missing();
|
|
4230
|
+
return credential;
|
|
4231
|
+
}
|
|
4232
|
+
/**
|
|
4132
4233
|
* `send`, `edit`, `group send` and `group edit` with no text words read it from stdin the same way: `command` is the
|
|
4133
4234
|
* command line as given (`send bob`). `asked`: `--stdin`, which waits as long as it takes.
|
|
4134
4235
|
*/
|
|
@@ -4262,15 +4363,15 @@ var VERSION = package_default.version;
|
|
|
4262
4363
|
* command a running daemon answers loads none of them, and starts about as fast as Node does. Statically imported, they
|
|
4263
4364
|
* cost every command ~100 ms before its socket was opened.
|
|
4264
4365
|
*/
|
|
4265
|
-
var engineApi = () => import("./api-
|
|
4266
|
-
var engineHost = () => import("./host-
|
|
4366
|
+
var engineApi = () => import("./api-BwyFq4lA.js");
|
|
4367
|
+
var engineHost = () => import("./host-C0NMNQLl.js");
|
|
4267
4368
|
/**
|
|
4268
4369
|
* `--translate <lang>`'s translator, or null (not asked; or the runtime is not there, said on stderr). Loaded only when
|
|
4269
4370
|
* asked: the app's message parser it reads costs every other command nothing.
|
|
4270
4371
|
*/
|
|
4271
4372
|
async function translatorFor(value, home) {
|
|
4272
4373
|
if (value === void 0) return null;
|
|
4273
|
-
const { loadDetector, openTranslator, translateTarget } = await import("./translate-
|
|
4374
|
+
const { loadDetector, openTranslator, translateTarget } = await import("./translate-CUuC5szR.js");
|
|
4274
4375
|
return openTranslator({
|
|
4275
4376
|
home,
|
|
4276
4377
|
to: translateTarget(value),
|
|
@@ -4282,6 +4383,11 @@ var pretty = false;
|
|
|
4282
4383
|
function print(value) {
|
|
4283
4384
|
process.stdout.write(jsonOut(value, pretty ? 2 : void 0) + "\n");
|
|
4284
4385
|
}
|
|
4386
|
+
/**
|
|
4387
|
+
* Where `run` writes a failure: stdout, unless stdout is the call's audio (`call pipe`). There the error was played as
|
|
4388
|
+
* a click (`call pipe | aplay …`) and the terminal said nothing.
|
|
4389
|
+
*/
|
|
4390
|
+
var failures = process.stdout;
|
|
4285
4391
|
/** Done, with something to know (a voice note sent without its waveform): said on stderr, the JSON stays the answer. */
|
|
4286
4392
|
function printAnswer(result) {
|
|
4287
4393
|
if (typeof result?.warning === "string") {
|
|
@@ -4290,9 +4396,11 @@ function printAnswer(result) {
|
|
|
4290
4396
|
}
|
|
4291
4397
|
print(result);
|
|
4292
4398
|
}
|
|
4293
|
-
|
|
4399
|
+
/** `ownProfile`: the command names its profile, or none (`profile create`, `use`): a bad `<home>/current` is not read. */
|
|
4400
|
+
function globals(parsed, { ownProfile = false } = {}) {
|
|
4294
4401
|
const home = ghostlyHome(parsed.options.home);
|
|
4295
|
-
const
|
|
4402
|
+
const option = parsed.options.profile;
|
|
4403
|
+
const profile = ownProfile ? currentProfileOrNone(home, option) ?? "default" : currentProfile(home, option);
|
|
4296
4404
|
return {
|
|
4297
4405
|
home,
|
|
4298
4406
|
profile,
|
|
@@ -4389,6 +4497,7 @@ function chatOnly(method, params) {
|
|
|
4389
4497
|
function chatOrGroup(method, params) {
|
|
4390
4498
|
if (method.startsWith("task.") || method.startsWith("routine.") || method.startsWith("button.") || method === "usage.send") return true;
|
|
4391
4499
|
if (method === "chat.delete" && params.everyone === true) return true;
|
|
4500
|
+
if (method.startsWith("file.") && typeof params.file === "string" && params.file.startsWith("group-")) return true;
|
|
4392
4501
|
return method === "chat.pin" || method === "chat.forward";
|
|
4393
4502
|
}
|
|
4394
4503
|
/**
|
|
@@ -4419,9 +4528,10 @@ var GROUP_EDGES_ONLY = /* @__PURE__ */ new Set([
|
|
|
4419
4528
|
]);
|
|
4420
4529
|
/**
|
|
4421
4530
|
* A command about one group that goes over its edges only (`GROUP_EDGES_ONLY`): a one-shot for it leaves the saved 1:1
|
|
4422
|
-
* chats unstarted (`deferChats`)
|
|
4423
|
-
* records and its leave packet on the relays: with 12 invites saved, one `group send` asked the
|
|
4424
|
-
* none), its whole minute, and a text to an away contact, or the next one-shot, waited behind
|
|
4531
|
+
* chats and the other groups' edges unstarted (`deferChats`), and starts the group's own (`startNamedChats`). Started,
|
|
4532
|
+
* each saved chat put its records and its leave packet on the relays: with 12 invites saved, one `group send` asked the
|
|
4533
|
+
* relay 32 times (3 with none), its whole minute, and a text to an away contact, or the next one-shot, waited behind
|
|
4534
|
+
* them. Each other group's edges did the same: with six more groups shared with one member, 31 to 47 times.
|
|
4425
4535
|
*/
|
|
4426
4536
|
function oneGroupOnly(method) {
|
|
4427
4537
|
return GROUP_EDGES_ONLY.has(method);
|
|
@@ -4429,14 +4539,24 @@ function oneGroupOnly(method) {
|
|
|
4429
4539
|
/**
|
|
4430
4540
|
* Reads that need nothing of a chat's history: a one-shot for one leaves every saved chat unstarted too (`deferChats`),
|
|
4431
4541
|
* so its start reads each chat's newest row (its place in `chat list`) and no history. It read every 1:1 chat whole:
|
|
4432
|
-
* `profile show` took 0.8 s and 243 MB instead of 0.45 s and 162 MB with 53,800 messages in the profile
|
|
4542
|
+
* `profile show` took 0.8 s and 243 MB instead of 0.45 s and 162 MB with 53,800 messages in the profile, and
|
|
4543
|
+
* `group list` 0.89 s and 220 MB instead of 0.42 s and 154 MB with 50,000. A group's own reads need its history only,
|
|
4544
|
+
* which its start reads whatever this says.
|
|
4433
4545
|
*/
|
|
4434
4546
|
var NO_HISTORY_READS = /* @__PURE__ */ new Set([
|
|
4435
4547
|
"status",
|
|
4436
4548
|
"profile.get",
|
|
4437
4549
|
"settings.get",
|
|
4438
4550
|
"status.get",
|
|
4439
|
-
"chat.list"
|
|
4551
|
+
"chat.list",
|
|
4552
|
+
"group.list",
|
|
4553
|
+
"group.get",
|
|
4554
|
+
"group.history",
|
|
4555
|
+
"call.list",
|
|
4556
|
+
"service.list",
|
|
4557
|
+
"identity.list",
|
|
4558
|
+
"x401.credential.list",
|
|
4559
|
+
"app.served"
|
|
4440
4560
|
]);
|
|
4441
4561
|
/** Whether a one-shot for this call leaves every saved chat unstarted, its history unread (`NO_HISTORY_READS`). */
|
|
4442
4562
|
function readsNoHistory(method) {
|
|
@@ -4486,7 +4606,7 @@ function readOnly(method, params) {
|
|
|
4486
4606
|
/**
|
|
4487
4607
|
* Calls whose change stays on this device: a chat's name here, a chat removed (nothing goes to the contact), auto-answer
|
|
4488
4608
|
* (calls.json), auto-join (groups.json: a one-shot accepts nothing itself, the daemon does), 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
|
|
4489
|
-
* shared with a contact). Opened online, each put the profile's records on the relays and waited for them (6 PUT + 4
|
|
4609
|
+
* shared with a contact), an app served or unserved (served.json: an engine reads it as it starts). Opened online, each put the profile's records on the relays and waited for them (6 PUT + 4
|
|
4490
4610
|
* GET, 3.3 s with a relay that takes 1.5 s), and the contacts' apps saw this device come online. `message delete` stays
|
|
4491
4611
|
* online: it settles a file offer already on the DHT.
|
|
4492
4612
|
*/
|
|
@@ -4502,6 +4622,8 @@ var LOCAL_WRITES = /* @__PURE__ */ new Set([
|
|
|
4502
4622
|
"x401.credential.remove",
|
|
4503
4623
|
"saved.add",
|
|
4504
4624
|
"saved.remove",
|
|
4625
|
+
"app.serve",
|
|
4626
|
+
"app.unserve",
|
|
4505
4627
|
"status.set",
|
|
4506
4628
|
"status.clear"
|
|
4507
4629
|
]);
|
|
@@ -4522,9 +4644,26 @@ var LOCAL_SETTINGS = /* @__PURE__ */ new Set([
|
|
|
4522
4644
|
* to be live (`keepOneShot`), so that one stays online.
|
|
4523
4645
|
*/
|
|
4524
4646
|
var LIVE_ONLY = /* @__PURE__ */ new Set(["chat.typing", "group.typing"]);
|
|
4525
|
-
/**
|
|
4647
|
+
/**
|
|
4648
|
+
* Done only by a daemon (a call placed, a contact's app opened on a port, a served app open in a chat): a one-shot
|
|
4649
|
+
* refuses them whatever the network says. Online, it said "start `ghostly daemon --detach`" only once its leave packet
|
|
4650
|
+
* was taken: 3.4 s with a relay that takes 1.5 s, 10 s with one that does not answer. A one-shot answers no call, queues
|
|
4651
|
+
* no audio to flush and has no service open to close: those said "not found" after 6-12 s online. `call hangup` stays
|
|
4652
|
+
* online: a call may ring while a one-shot runs, and be declined.
|
|
4653
|
+
*/
|
|
4654
|
+
var DAEMON_ONLY = /* @__PURE__ */ new Set([
|
|
4655
|
+
"call.start",
|
|
4656
|
+
"call.answer",
|
|
4657
|
+
"call.flush",
|
|
4658
|
+
"service.open",
|
|
4659
|
+
"service.close",
|
|
4660
|
+
"app.open",
|
|
4661
|
+
"app.close",
|
|
4662
|
+
"app.send"
|
|
4663
|
+
]);
|
|
4664
|
+
/** Whether a one-shot for this call opens the profile offline: a read, a change that stays on this device, typing, or what only a daemon does. */
|
|
4526
4665
|
function offlineCall(method, params) {
|
|
4527
|
-
return readOnly(method, params) || LOCAL_WRITES.has(method) || LIVE_ONLY.has(method) && params.for === void 0;
|
|
4666
|
+
return readOnly(method, params) || LOCAL_WRITES.has(method) || DAEMON_ONLY.has(method) || LIVE_ONLY.has(method) && params.for === void 0;
|
|
4528
4667
|
}
|
|
4529
4668
|
/** How long a daemon gets to answer before a command gives up: a read is in memory (15 s); a call that waits for the
|
|
4530
4669
|
* contact carries its own `--timeout` (or the daemon's default for it), plus a margin; anything else may take as long
|
|
@@ -4840,7 +4979,7 @@ var SPECIAL = [
|
|
|
4840
4979
|
"A backup of the profile, encrypted with a passphrase (from a file or GHOSTLY_BACKUP_PASSPHRASE); --no-passphrase makes one anyone can read",
|
|
4841
4980
|
{
|
|
4842
4981
|
out: o("string", "The backup file to write"),
|
|
4843
|
-
"passphrase-file": o("string", "The passphrase, from this file (else GHOSTLY_BACKUP_PASSPHRASE)"),
|
|
4982
|
+
"passphrase-file": o("string", "The passphrase, from this file, or stdin for - (else GHOSTLY_BACKUP_PASSPHRASE)"),
|
|
4844
4983
|
passphrase: {
|
|
4845
4984
|
...o("boolean", "Do not encrypt. The file then holds the profile's keys and wallet secrets in the clear"),
|
|
4846
4985
|
negatedOnly: true
|
|
@@ -4852,7 +4991,7 @@ var SPECIAL = [
|
|
|
4852
4991
|
"profile restore <file> <new profile> [--passphrase-file f] [--use]",
|
|
4853
4992
|
"A backup into a new profile (a backup made with --no-passphrase needs none)",
|
|
4854
4993
|
{
|
|
4855
|
-
"passphrase-file": o("string", "The passphrase, from this file (else GHOSTLY_BACKUP_PASSPHRASE)"),
|
|
4994
|
+
"passphrase-file": o("string", "The passphrase, from this file, or stdin for - (else GHOSTLY_BACKUP_PASSPHRASE)"),
|
|
4856
4995
|
use: o("boolean", "Make it the current profile")
|
|
4857
4996
|
}
|
|
4858
4997
|
],
|
|
@@ -5002,14 +5141,15 @@ function helpRow(label, text, at, columns) {
|
|
|
5002
5141
|
}
|
|
5003
5142
|
/**
|
|
5004
5143
|
* What `ghostly` says first in a Ghostly folder with no profile yet: where to start, as the README's "Five minutes"
|
|
5005
|
-
* does, before the whole list. `$ ` keeps the lines apart from the list's commands.
|
|
5144
|
+
* does, before the whole list. `$ ` keeps the lines apart from the list's commands. The join pipes the invite in, as
|
|
5145
|
+
* docs/CLI.md does: `invite join -` waits for stdin a pipe gives, and a terminal is refused it.
|
|
5006
5146
|
*/
|
|
5007
5147
|
var FIRST_STEPS = [
|
|
5008
5148
|
"First steps:",
|
|
5009
|
-
" $ ghostly invite create --label alice
|
|
5010
|
-
" $ ghostly invite join
|
|
5011
|
-
" $ ghostly daemon --detach
|
|
5012
|
-
" $ ghostly help <command>
|
|
5149
|
+
" $ ghostly invite create --label alice make an invite for a contact",
|
|
5150
|
+
" $ printf '%s' \"$INVITE\" | ghostly invite join join one, from stdin",
|
|
5151
|
+
" $ ghostly daemon --detach keep the profile online",
|
|
5152
|
+
" $ ghostly help <command> one command and its options"
|
|
5013
5153
|
];
|
|
5014
5154
|
function help(firstSteps = false) {
|
|
5015
5155
|
const columns = helpColumns();
|
|
@@ -5114,7 +5254,7 @@ function commandHelp(words) {
|
|
|
5114
5254
|
return lines.join("\n");
|
|
5115
5255
|
}
|
|
5116
5256
|
async function profileCommand(sub, argv) {
|
|
5117
|
-
const
|
|
5257
|
+
const specs = {
|
|
5118
5258
|
create: {
|
|
5119
5259
|
use: {
|
|
5120
5260
|
type: "boolean",
|
|
@@ -5172,8 +5312,20 @@ async function profileCommand(sub, argv) {
|
|
|
5172
5312
|
description: ""
|
|
5173
5313
|
}
|
|
5174
5314
|
}
|
|
5175
|
-
}
|
|
5176
|
-
|
|
5315
|
+
};
|
|
5316
|
+
let parsed;
|
|
5317
|
+
try {
|
|
5318
|
+
parsed = parseArgs(argv, specs[sub ?? ""] ?? {}, void 0, { command: commandOf("profile", sub) });
|
|
5319
|
+
} catch (e) {
|
|
5320
|
+
if ((sub === "backup" || sub === "restore") && passphraseOnLine(argv)) throw new CliError("usage", PASSPHRASE_ON_LINE);
|
|
5321
|
+
throw e;
|
|
5322
|
+
}
|
|
5323
|
+
const g = globals(parsed, { ownProfile: [
|
|
5324
|
+
"create",
|
|
5325
|
+
"list",
|
|
5326
|
+
"use",
|
|
5327
|
+
"restore"
|
|
5328
|
+
].includes(sub ?? "") });
|
|
5177
5329
|
pretty = g.pretty;
|
|
5178
5330
|
switch (sub) {
|
|
5179
5331
|
case "create": {
|
|
@@ -5182,7 +5334,7 @@ async function profileCommand(sub, argv) {
|
|
|
5182
5334
|
noMoreThan(1, parsed.positionals, "profile create <name> [--use] [--name <shown name>] [--force]");
|
|
5183
5335
|
const shownName = parsed.options.name === void 0 ? void 0 : checkShownNameOption(parsed.options.name);
|
|
5184
5336
|
const force = parsed.options.force === true;
|
|
5185
|
-
if (shownName) (await import("./secretGuard-
|
|
5337
|
+
if (shownName) (await import("./secretGuard-DCb1I0_B.js")).guardText(shownName, force, "name", "set it");
|
|
5186
5338
|
const paths = createProfile(g.home, name);
|
|
5187
5339
|
let shown = null;
|
|
5188
5340
|
if (shownName !== void 0) try {
|
|
@@ -5205,14 +5357,14 @@ async function profileCommand(sub, argv) {
|
|
|
5205
5357
|
print({
|
|
5206
5358
|
created: name,
|
|
5207
5359
|
folder: paths.dir,
|
|
5208
|
-
current:
|
|
5360
|
+
current: currentProfileOrNone(g.home) === name,
|
|
5209
5361
|
...shown ? { profile: shown } : {}
|
|
5210
5362
|
});
|
|
5211
5363
|
return;
|
|
5212
5364
|
}
|
|
5213
5365
|
case "list": {
|
|
5214
5366
|
noMoreThan(0, parsed.positionals, "profile list");
|
|
5215
|
-
const current =
|
|
5367
|
+
const current = currentProfileOrNone(g.home);
|
|
5216
5368
|
print({
|
|
5217
5369
|
profiles: listProfiles(g.home).map((name) => ({
|
|
5218
5370
|
name,
|
|
@@ -5228,7 +5380,9 @@ async function profileCommand(sub, argv) {
|
|
|
5228
5380
|
if (!name) throw new CliError("usage", "Missing <name>: ghostly profile use <name>");
|
|
5229
5381
|
noMoreThan(1, parsed.positionals, "profile use <name>");
|
|
5230
5382
|
selectProfile(g.home, name);
|
|
5231
|
-
|
|
5383
|
+
const current = currentProfile(g.home);
|
|
5384
|
+
if (current !== name) process.stderr.write(`ghostly: GHOSTLY_PROFILE=${current} still picks the profile in this shell: unset it to use ${name}.\n`);
|
|
5385
|
+
print({ current });
|
|
5232
5386
|
return;
|
|
5233
5387
|
}
|
|
5234
5388
|
case "show":
|
|
@@ -5252,21 +5406,22 @@ async function profileCommand(sub, argv) {
|
|
|
5252
5406
|
return;
|
|
5253
5407
|
}
|
|
5254
5408
|
case "backup": {
|
|
5409
|
+
if (parsed.options.passphrase === true) throw new CliError("usage", PASSPHRASE_ON_LINE);
|
|
5255
5410
|
noMoreThan(0, parsed.positionals, "profile backup --out <file> [--passphrase-file f | --no-passphrase] [--light]");
|
|
5256
5411
|
const out = parsed.options.out;
|
|
5257
5412
|
if (typeof out !== "string") throw new CliError("usage", "Missing --out: ghostly profile backup --out <file> [--passphrase-file f | --no-passphrase] [--light]");
|
|
5258
5413
|
const unsealed = parsed.options.passphrase === false;
|
|
5259
|
-
if (parsed.options.passphrase === true) throw new CliError("usage", "The passphrase comes from --passphrase-file or GHOSTLY_BACKUP_PASSPHRASE, never the command line");
|
|
5260
5414
|
if (unsealed && (parsed.options["passphrase-file"] !== void 0 || process.env.GHOSTLY_BACKUP_PASSPHRASE)) throw new CliError("usage", "A passphrase is set (--passphrase-file or GHOSTLY_BACKUP_PASSPHRASE) and --no-passphrase was given: choose one");
|
|
5261
5415
|
const light = parsed.options.light === true ? { light: true } : {};
|
|
5262
5416
|
const resolved = here(out), path = (out.endsWith("/") || out.endsWith(sep)) && !resolved.endsWith(sep) ? `${resolved}${sep}` : resolved;
|
|
5417
|
+
if (!path.endsWith(sep) && !localStat(dirname(path)).isDirectory()) throw new CliError("not_found", `No such file or folder: ${dirname(path)}`);
|
|
5263
5418
|
const params = unsealed ? {
|
|
5264
5419
|
path,
|
|
5265
5420
|
noPassphrase: true,
|
|
5266
5421
|
...light
|
|
5267
5422
|
} : {
|
|
5268
5423
|
path,
|
|
5269
|
-
passphrase: backupPassphrase(parsed.options["passphrase-file"]),
|
|
5424
|
+
passphrase: await backupPassphrase(parsed.options["passphrase-file"]),
|
|
5270
5425
|
...light
|
|
5271
5426
|
};
|
|
5272
5427
|
const made = await withSession(g, (s) => s.call("profile.backup", params), { offline: true });
|
|
@@ -5279,15 +5434,15 @@ async function profileCommand(sub, argv) {
|
|
|
5279
5434
|
if (!given || !name) throw new CliError("usage", `Missing <${given ? "new profile" : "file"}>: ghostly profile restore <file> <new profile> [--passphrase-file f] [--use]`);
|
|
5280
5435
|
noMoreThan(2, parsed.positionals, "profile restore <file> <new profile> [--passphrase-file f] [--use]");
|
|
5281
5436
|
const file = here(given);
|
|
5282
|
-
const { backupFileProtection, restoreProfile } = await import("./backup-
|
|
5437
|
+
const { backupFileProtection, restoreProfile } = await import("./backup-CdEzTq5C.js");
|
|
5283
5438
|
const protection = await backupFileProtection(file);
|
|
5284
|
-
const paths = await restoreProfile(g.home, checkProfileName(name), file, protection === "none" ? void 0 : backupPassphrase(parsed.options["passphrase-file"], RESTORE_PASSPHRASE));
|
|
5439
|
+
const paths = await restoreProfile(g.home, checkProfileName(name), file, protection === "none" ? void 0 : await backupPassphrase(parsed.options["passphrase-file"], RESTORE_PASSPHRASE));
|
|
5285
5440
|
if (parsed.options.use) selectProfile(g.home, name);
|
|
5286
5441
|
print({
|
|
5287
5442
|
restored: name,
|
|
5288
5443
|
folder: paths.dir,
|
|
5289
5444
|
protection,
|
|
5290
|
-
current:
|
|
5445
|
+
current: currentProfileOrNone(g.home) === name
|
|
5291
5446
|
});
|
|
5292
5447
|
return;
|
|
5293
5448
|
}
|
|
@@ -5321,24 +5476,33 @@ function onStopSignals(stop) {
|
|
|
5321
5476
|
var BACKUP_PASSPHRASE = "The backup passphrase comes from --passphrase-file or GHOSTLY_BACKUP_PASSPHRASE (at least 12 characters). For a backup that is not encrypted, say so with --no-passphrase";
|
|
5322
5477
|
/** Restore takes no --no-passphrase: a backup made without one says so itself. */
|
|
5323
5478
|
var RESTORE_PASSPHRASE = "This backup is encrypted: its passphrase comes from --passphrase-file or GHOSTLY_BACKUP_PASSPHRASE";
|
|
5479
|
+
var PASSPHRASE_ON_LINE = "The passphrase comes from --passphrase-file or GHOSTLY_BACKUP_PASSPHRASE, never the command line";
|
|
5480
|
+
/** `--passphrase` or `--passphrase=<value>` before any `--` (after it, words are positionals). */
|
|
5481
|
+
var passphraseOnLine = (argv) => {
|
|
5482
|
+
const end = argv.indexOf("--");
|
|
5483
|
+
return (end === -1 ? argv : argv.slice(0, end)).some((arg) => arg === "--passphrase" || arg.startsWith("--passphrase="));
|
|
5484
|
+
};
|
|
5324
5485
|
/**
|
|
5325
5486
|
* The backup passphrase: from a file or the environment, never the command line (it would sit in shell history). The
|
|
5326
5487
|
* file is said as every other file the CLI reads: "" names none, a folder is named, and an empty one is called that,
|
|
5327
|
-
* not "comes from --passphrase-file" to someone who gave it.
|
|
5488
|
+
* not "comes from --passphrase-file" to someone who gave it. "-" is stdin, as for every other secret the CLI takes (a
|
|
5489
|
+
* pipe from a password manager); a terminal is refused, as it would show the passphrase as it is typed.
|
|
5328
5490
|
*/
|
|
5329
|
-
function backupPassphrase(file, missing = BACKUP_PASSPHRASE) {
|
|
5491
|
+
async function backupPassphrase(file, missing = BACKUP_PASSPHRASE) {
|
|
5330
5492
|
if (typeof file !== "string") {
|
|
5331
5493
|
const value = process.env.GHOSTLY_BACKUP_PASSPHRASE;
|
|
5332
5494
|
if (!value) throw new CliError("usage", missing);
|
|
5333
5495
|
return value;
|
|
5334
5496
|
}
|
|
5497
|
+
if (file === "-" && process.stdin.isTTY) throw new CliError("usage", "--passphrase-file - reads stdin: pipe the passphrase in (… | ghostly profile …), or name a file");
|
|
5335
5498
|
let value;
|
|
5336
|
-
|
|
5499
|
+
if (file === "-") value = (await readStdin()).replace(/\r?\n$/, "");
|
|
5500
|
+
else try {
|
|
5337
5501
|
value = readFileSync(here(file), "utf8").replace(/\r?\n$/, "");
|
|
5338
5502
|
} catch (error) {
|
|
5339
5503
|
throw localFileError(error, file) ?? error;
|
|
5340
5504
|
}
|
|
5341
|
-
if (!value) throw new CliError("bad_request", `${file} is empty: it holds the backup's passphrase`);
|
|
5505
|
+
if (!value) throw new CliError("bad_request", `${file === "-" ? "Stdin" : file} is empty: it holds the backup's passphrase`);
|
|
5342
5506
|
return value;
|
|
5343
5507
|
}
|
|
5344
5508
|
/** Set on `startDetached`'s child: its parent waits for the profile and starts it again, so the child does not wait too. */
|
|
@@ -5357,7 +5521,7 @@ async function runDaemon(g, seconds) {
|
|
|
5357
5521
|
const until = performance.now() + seconds * 1e3;
|
|
5358
5522
|
let host;
|
|
5359
5523
|
for (;;) {
|
|
5360
|
-
|
|
5524
|
+
await noDaemonAnswers(g, detached);
|
|
5361
5525
|
try {
|
|
5362
5526
|
host = await openHost(g.paths, "daemon", VERSION);
|
|
5363
5527
|
break;
|
|
@@ -5394,6 +5558,16 @@ async function runDaemon(g, seconds) {
|
|
|
5394
5558
|
});
|
|
5395
5559
|
}
|
|
5396
5560
|
/**
|
|
5561
|
+
* Throws busy when something answers on the profile's socket while a process holds the profile (a daemon starts only
|
|
5562
|
+
* then). With nobody holding it, what answers is no daemon: the start said one ran, and the refusal names the way out.
|
|
5563
|
+
*/
|
|
5564
|
+
async function noDaemonAnswers(g, detached = false) {
|
|
5565
|
+
const client = await connectDaemon(g.paths);
|
|
5566
|
+
if (!client) return;
|
|
5567
|
+
client.close();
|
|
5568
|
+
throw childAnswer(detached, lockOwner(g.paths) === null ? notTheDaemon(g.paths, false) : new CliError("busy", `A daemon already runs profile ${g.profile}`));
|
|
5569
|
+
}
|
|
5570
|
+
/**
|
|
5397
5571
|
* A detached child's answer carries its own pid (`child`): its parent reads it in `daemon.log`, where every daemon of
|
|
5398
5572
|
* the profile writes, and another detach's child that lost the profile, or refused to start, writes there too.
|
|
5399
5573
|
*/
|
|
@@ -5554,7 +5728,7 @@ async function stopDaemon(g, client, seconds) {
|
|
|
5554
5728
|
const refused = isNotTheDaemon(error);
|
|
5555
5729
|
if (!(error instanceof CliError && error.code === "timeout") && !refused) throw error;
|
|
5556
5730
|
const holder = lockOwner(g.paths);
|
|
5557
|
-
if (holder === null) throw error;
|
|
5731
|
+
if (holder === null) throw refused ? notTheDaemon(g.paths, false) : error;
|
|
5558
5732
|
process.stderr.write(refused ? `ghostly: what answers on the socket did not prove it is this profile's daemon (an older release's cannot): stopping the process that holds the profile (${holder}) with SIGTERM\n` : `ghostly: the daemon (process ${holder}) did not answer daemon.stop in ${seconds} s: stopping it with SIGTERM\n`);
|
|
5559
5733
|
pid = holder;
|
|
5560
5734
|
answered = false;
|
|
@@ -5621,7 +5795,7 @@ async function startDetached(g, seconds) {
|
|
|
5621
5795
|
try {
|
|
5622
5796
|
const until = performance.now() + seconds * 1e3;
|
|
5623
5797
|
for (;;) {
|
|
5624
|
-
|
|
5798
|
+
await noDaemonAnswers(g);
|
|
5625
5799
|
if (lockOwner(g.paths) === null) {
|
|
5626
5800
|
const started = await spawnDaemon(g, until);
|
|
5627
5801
|
if (started) return started;
|
|
@@ -5824,6 +5998,10 @@ async function listenCommand(argv) {
|
|
|
5824
5998
|
turns,
|
|
5825
5999
|
translate: translator?.event,
|
|
5826
6000
|
exec: parsed.options.exec,
|
|
6001
|
+
profile: {
|
|
6002
|
+
home: g.home,
|
|
6003
|
+
name: g.profile
|
|
6004
|
+
},
|
|
5827
6005
|
webhook,
|
|
5828
6006
|
cursor,
|
|
5829
6007
|
cursorFailed,
|
|
@@ -5995,7 +6173,7 @@ async function engineCommand(argv) {
|
|
|
5995
6173
|
const { hideStateSecrets } = await engineApi();
|
|
5996
6174
|
result = hideStateSecrets(result);
|
|
5997
6175
|
}
|
|
5998
|
-
print(result);
|
|
6176
|
+
print(hideSecretFields(method, result, showSecret));
|
|
5999
6177
|
}
|
|
6000
6178
|
async function settingsCommand(sub, argv) {
|
|
6001
6179
|
const parsed = parseArgs(argv, {
|
|
@@ -6025,6 +6203,7 @@ async function settingsCommand(sub, argv) {
|
|
|
6025
6203
|
const [key, given] = parsed.positionals;
|
|
6026
6204
|
if (!key) throw new CliError("usage", "Missing <key>: ghostly settings set <key> <json-value> [--force]");
|
|
6027
6205
|
noMoreThan(2, parsed.positionals, "settings set <key> <json-value> [--force]");
|
|
6206
|
+
const kind = key === "readRelays" ? void 0 : checkSettingKey(key, (await engineApi()).SETTABLE);
|
|
6028
6207
|
const { value, warning } = await settingValue(key, given, readStdin, process.stdin.isTTY === true, (note) => process.stderr.write(`ghostly: ${note}\n`));
|
|
6029
6208
|
if (warning) process.stderr.write(`ghostly: ${warning}\n`);
|
|
6030
6209
|
let parsedValue;
|
|
@@ -6033,7 +6212,8 @@ async function settingsCommand(sub, argv) {
|
|
|
6033
6212
|
} catch {
|
|
6034
6213
|
parsedValue = value;
|
|
6035
6214
|
}
|
|
6036
|
-
if (
|
|
6215
|
+
if (kind === "string" && typeof parsedValue !== "string") parsedValue = value;
|
|
6216
|
+
if (kind) checkSettingValue(key, kind, parsedValue, value);
|
|
6037
6217
|
const force = parsed.options.force === true ? { force: true } : {};
|
|
6038
6218
|
printAnswer(await withSession(g, (s) => s.call("settings.set", {
|
|
6039
6219
|
[key]: parsedValue,
|
|
@@ -6055,6 +6235,7 @@ async function textCommand(name, argv) {
|
|
|
6055
6235
|
const [message, ...words] = spec.message ? rest : [void 0, ...rest];
|
|
6056
6236
|
if (!target || spec.message && !message) throw new CliError("usage", `Missing <${target ? "message" : spec.target}>: ghostly ${spec.usage}`);
|
|
6057
6237
|
timeout(parsed.options);
|
|
6238
|
+
if (parsed.options.reply === "") throw new CliError("usage", "--reply needs a message id");
|
|
6058
6239
|
let text = words.join(" ");
|
|
6059
6240
|
if (parsed.options.text !== void 0) {
|
|
6060
6241
|
if (text || parsed.options.stdin) throw new CliError("usage", "Give the text once: as arguments, --text or stdin");
|
|
@@ -6072,7 +6253,7 @@ async function textCommand(name, argv) {
|
|
|
6072
6253
|
};
|
|
6073
6254
|
if (spec.target === "group") params.mentions = parsed.options.mention ?? [];
|
|
6074
6255
|
if (parsed.options.reply !== void 0) params.reply = parsed.options.reply;
|
|
6075
|
-
if (!spec.message) Object.assign(params, (await import("./buttons-
|
|
6256
|
+
if (!spec.message) Object.assign(params, (await import("./buttons-DK2aAGat.js")).buttonsOf(parsed.options));
|
|
6076
6257
|
print(await withSession(g, (s) => {
|
|
6077
6258
|
if (parsed.options.wait !== void 0) params.wait = parsed.options.wait;
|
|
6078
6259
|
if (parsed.options.timeout !== void 0) params.timeout = parsed.options.timeout;
|
|
@@ -6116,7 +6297,7 @@ async function identityAddCommand(argv) {
|
|
|
6116
6297
|
if (!provider) throw new CliError("usage", "Missing <provider>: ghostly identity add <provider> [subject] [--signer id] [--field name=value]... [--stdin] [--days n] [--timeout s]");
|
|
6117
6298
|
inRange(parsed.options, "timeout", "a number of seconds", 5, 3600);
|
|
6118
6299
|
const items = parsed.options.field ?? [];
|
|
6119
|
-
const known = parsed.options.days !== void 0 || items.length ? (await import("./registry-
|
|
6300
|
+
const known = parsed.options.days !== void 0 || items.length ? (await import("./registry-zUZBSHYv.js")).IDENTITY_PROVIDERS.find((p) => p.id === provider) : void 0;
|
|
6120
6301
|
if (known && parsed.options.days !== void 0) inRange(parsed.options, "days", "a whole number", 1, known.validity.maxDays, true);
|
|
6121
6302
|
const { fields, warning } = await identityFields(items, parsed.options.stdin === true, identitySecretFields(known, parsed.options.signer), readStdin, process.stdin.isTTY === true);
|
|
6122
6303
|
if (warning) process.stderr.write(`ghostly: ${warning}\n`);
|
|
@@ -6197,11 +6378,10 @@ async function tableCommand(name, argv) {
|
|
|
6197
6378
|
}
|
|
6198
6379
|
if (command.method === "x401.credential.add") {
|
|
6199
6380
|
try {
|
|
6200
|
-
params.credential = params.file === "-" ? await readStdin
|
|
6381
|
+
params.credential = params.file === "-" ? await credentialFromStdin(readStdin, process.stdin.isTTY === true) : readInput(params.file);
|
|
6201
6382
|
} catch (error) {
|
|
6202
6383
|
throw error instanceof CliError && error || localFileError(error, params.file) || new CliError("usage", `Cannot read the credential: ${error instanceof Error ? error.message : String(error)}`);
|
|
6203
6384
|
}
|
|
6204
|
-
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");
|
|
6205
6385
|
if (!params.credential) throw new CliError("bad_request", `${params.file} is empty: it holds the SD-JWT VC the issuer sent`);
|
|
6206
6386
|
delete params.file;
|
|
6207
6387
|
}
|
|
@@ -6227,7 +6407,7 @@ async function tableCommand(name, argv) {
|
|
|
6227
6407
|
});
|
|
6228
6408
|
if (translator) {
|
|
6229
6409
|
try {
|
|
6230
|
-
printAnswer(await (await import("./translate-
|
|
6410
|
+
printAnswer(await (await import("./translate-CUuC5szR.js")).translateAnswer(result, translator));
|
|
6231
6411
|
} finally {
|
|
6232
6412
|
translator.close();
|
|
6233
6413
|
}
|
|
@@ -6240,19 +6420,28 @@ async function tableCommand(name, argv) {
|
|
|
6240
6420
|
* contact's, raw PCM); what the command says goes to stderr. It ends when the call does.
|
|
6241
6421
|
*/
|
|
6242
6422
|
async function callPipeCommand(argv) {
|
|
6423
|
+
failures = process.stderr;
|
|
6243
6424
|
const parsed = parseArgs(argv, {}, idSlot({ args: ["call...?"] }), { command: "call pipe" });
|
|
6244
6425
|
const g = globals(parsed);
|
|
6245
6426
|
const ref = parsed.positionals.join(" ") || void 0;
|
|
6246
6427
|
const client = await connectDaemon(g.paths);
|
|
6247
6428
|
if (!client) throw new CliError("unavailable", `No daemon runs profile ${g.profile}: calls need one (ghostly daemon --detach)`);
|
|
6248
6429
|
let call;
|
|
6430
|
+
let reason = null, heard = null;
|
|
6249
6431
|
try {
|
|
6250
6432
|
call = await client.call("call.get", ref ? { call: ref } : {}, { timeoutMs: ANSWER_MS });
|
|
6251
|
-
|
|
6433
|
+
if (!call.audio) throw new CliError("unavailable", "That call has no audio yet: answer it first");
|
|
6434
|
+
const id = call.call;
|
|
6435
|
+
await client.subscribe(void 0, (event) => {
|
|
6436
|
+
if (event.type !== "call.ended" || event.call !== id) return;
|
|
6437
|
+
reason = String(event.reason);
|
|
6438
|
+
heard?.();
|
|
6439
|
+
}, () => heard?.());
|
|
6440
|
+
} catch (error) {
|
|
6252
6441
|
client.close();
|
|
6442
|
+
throw error;
|
|
6253
6443
|
}
|
|
6254
6444
|
const audio = call.audio;
|
|
6255
|
-
if (!audio) throw new CliError("unavailable", "That call has no audio yet: answer it first");
|
|
6256
6445
|
const socket = connect(audio.socket);
|
|
6257
6446
|
await new Promise((resolve, reject) => {
|
|
6258
6447
|
socket.once("connect", resolve);
|
|
@@ -6261,13 +6450,30 @@ async function callPipeCommand(argv) {
|
|
|
6261
6450
|
socket.write(`${audio.token}\n`);
|
|
6262
6451
|
process.stderr.write(`ghostly: call ${call.call}: s16le mono ${audio.rate} Hz on stdin/stdout\n`);
|
|
6263
6452
|
process.stdin.pipe(socket, { end: false });
|
|
6453
|
+
let readerGone = false;
|
|
6264
6454
|
onReaderGone(() => {
|
|
6455
|
+
readerGone = true;
|
|
6265
6456
|
process.stderr.write(`ghostly: call ${call.call}: nothing reads its audio any more; the call goes on\n`);
|
|
6266
6457
|
socket.destroy();
|
|
6267
6458
|
});
|
|
6268
6459
|
socket.pipe(process.stdout);
|
|
6269
|
-
socket.on("close", () =>
|
|
6460
|
+
socket.on("close", () => void (async () => {
|
|
6461
|
+
if (!readerGone) process.stderr.write(`ghostly: call ${call.call}: ${await whyClosed()}\n`);
|
|
6462
|
+
client.close();
|
|
6463
|
+
exit(0);
|
|
6464
|
+
})());
|
|
6270
6465
|
socket.on("error", () => exit(1));
|
|
6466
|
+
/** Why the daemon closed the call's socket: a call still on gave it to another program; one gone ended. */
|
|
6467
|
+
async function whyClosed() {
|
|
6468
|
+
if (reason === null) {
|
|
6469
|
+
if (await client.call("call.get", { call: call.call }, { timeoutMs: 5e3 }).then(() => true, () => false) && reason === null) return "another program took its audio; the call goes on";
|
|
6470
|
+
if (reason === null) await new Promise((resolve) => {
|
|
6471
|
+
heard = resolve;
|
|
6472
|
+
setTimeout(resolve, 3e3).unref();
|
|
6473
|
+
});
|
|
6474
|
+
}
|
|
6475
|
+
return reason === null ? "the call ended" : `the call ended (${reason})`;
|
|
6476
|
+
}
|
|
6271
6477
|
}
|
|
6272
6478
|
/**
|
|
6273
6479
|
* The command's words when the line asks for help (`help <words>`, or `--help`/`--help=true`/`-h` before any `--`), else
|
|
@@ -6447,11 +6653,11 @@ async function run(argv) {
|
|
|
6447
6653
|
if (code >= 0) exit(code);
|
|
6448
6654
|
} catch (error) {
|
|
6449
6655
|
const failure = asCliError(error);
|
|
6450
|
-
|
|
6656
|
+
failures.write(jsonOut({ error: failure.toJSON() }, pretty ? 2 : void 0) + "\n");
|
|
6451
6657
|
exit(EXIT[failure.code]);
|
|
6452
6658
|
}
|
|
6453
6659
|
}
|
|
6454
6660
|
//#endregion
|
|
6455
6661
|
export { run };
|
|
6456
6662
|
|
|
6457
|
-
//# sourceMappingURL=main-
|
|
6663
|
+
//# sourceMappingURL=main-C6t5zrD5.js.map
|