@ghostlytools/cli 1.11.2 → 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 +34 -28
- package/SKILL.md +4 -2
- package/dist/assets/{api-CtXgscmK.js → api-BwyFq4lA.js} +2 -2
- package/dist/assets/{api-BM3PsXbB.js → api-MYc6QNRs.js} +306 -114
- package/dist/assets/api-MYc6QNRs.js.map +1 -0
- package/dist/assets/{apiKit-lCTQ0EBG.js → apiKit-CfsNx9ZR.js} +62 -16
- package/dist/assets/apiKit-CfsNx9ZR.js.map +1 -0
- package/dist/assets/{appFetch-BKHy5H8J.js → appFetch-DVYZOZFw.js} +3 -3
- package/dist/assets/{appFetch-BKHy5H8J.js.map → appFetch-DVYZOZFw.js.map} +1 -1
- package/dist/assets/{apps-DO_gAZgm.js → apps-Dbw2Hcko.js} +1 -1
- package/dist/assets/{apps-Do26w3c7.js → apps-h12II1us.js} +150 -57
- package/dist/assets/apps-h12II1us.js.map +1 -0
- package/dist/assets/{arkade-CZrLbz-M.js → arkade-Bw_4PZRG.js} +2 -2
- package/dist/assets/{arkade-CZrLbz-M.js.map → arkade-Bw_4PZRG.js.map} +1 -1
- package/dist/assets/{backup-D21x1f5P.js → backup-CdEzTq5C.js} +1 -1
- package/dist/assets/{backup-j47AzDvG.js → backup-Chvy79SN.js} +60 -55
- 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-CiGlBVBT.js → buttons-BgoExb4E.js} +37 -7
- package/dist/assets/buttons-BgoExb4E.js.map +1 -0
- package/dist/assets/buttons-DK2aAGat.js +2 -0
- package/dist/assets/{client-raIncVtF.js → client-DY8tZZWi.js} +28 -8
- package/dist/assets/client-DY8tZZWi.js.map +1 -0
- package/dist/assets/{codec-DcG2AeyE.js → codec-BnMg-Grj.js} +2 -2
- package/dist/assets/{codec-DcG2AeyE.js.map → codec-BnMg-Grj.js.map} +1 -1
- package/dist/assets/{envelope-Dud6lntA.js → envelope-CdV7vHVZ.js} +2 -2
- package/dist/assets/{envelope-Dud6lntA.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-DRKRSw14.js → fedimintSdk-CPFfVK-G.js} +2 -2
- package/dist/assets/{fedimintSdk-DRKRSw14.js.map → fedimintSdk-CPFfVK-G.js.map} +1 -1
- package/dist/assets/{fixedHosts-CNX7QiUD.js → fixedHosts-CbgqrIKs.js} +3 -3
- package/dist/assets/{fixedHosts-CNX7QiUD.js.map → fixedHosts-CbgqrIKs.js.map} +1 -1
- package/dist/assets/{host-8RskzQgB.js → host-C0NMNQLl.js} +702 -143
- package/dist/assets/host-C0NMNQLl.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-uAThbFub.js → hyperdhtRelay-Dz7pvcBA.js} +2 -2
- package/dist/assets/{hyperdhtRelay-uAThbFub.js.map → hyperdhtRelay-Dz7pvcBA.js.map} +1 -1
- package/dist/assets/{irohWeb-DGelfgDJ.js → irohWeb-caAj4Dms.js} +19 -12
- package/dist/assets/irohWeb-caAj4Dms.js.map +1 -0
- package/dist/assets/{main-BC33ooYg.js → main-C6t5zrD5.js} +383 -110
- package/dist/assets/main-C6t5zrD5.js.map +1 -0
- package/dist/assets/{mainline-DYrjsS1t.js → mainline-DCuGUSZF.js} +35 -18
- package/dist/assets/mainline-DCuGUSZF.js.map +1 -0
- package/dist/assets/{networkReason-n2oBs4by.js → networkReason-BbQW1Xpc.js} +3 -3
- package/dist/assets/{networkReason-n2oBs4by.js.map → networkReason-BbQW1Xpc.js.map} +1 -1
- package/dist/assets/{nwc-Do3VSlIS.js → nwc-CSDRMZ0e.js} +3 -3
- package/dist/assets/{nwc-Do3VSlIS.js.map → nwc-CSDRMZ0e.js.map} +1 -1
- package/dist/assets/{nwcProvider-Du5aWNIn.js → nwcProvider-PE0wli8n.js} +2 -2
- package/dist/assets/{nwcProvider-Du5aWNIn.js.map → nwcProvider-PE0wli8n.js.map} +1 -1
- package/dist/assets/{ownDid-CwwYu8s2.js → ownDid-C1R5Kd8q.js} +2 -2
- package/dist/assets/{ownDid-CwwYu8s2.js.map → ownDid-C1R5Kd8q.js.map} +1 -1
- package/dist/assets/{ownStatus-D7dB4zJB.js → ownStatus-BoTf5WqQ.js} +27 -9
- package/dist/assets/ownStatus-BoTf5WqQ.js.map +1 -0
- package/dist/assets/{profiles-NyF5FnYF.js → profiles-DszHjEJi.js} +25 -10
- package/dist/assets/profiles-DszHjEJi.js.map +1 -0
- package/dist/assets/{registry-DKDInr0A.js → registry-Da-r6eC3.js} +30 -12
- package/dist/assets/registry-Da-r6eC3.js.map +1 -0
- package/dist/assets/{registry-C734VrO9.js → registry-zUZBSHYv.js} +1 -1
- package/dist/assets/{resolve-3Tqh9AWQ.js → resolve-tUzh4lHh.js} +2 -2
- package/dist/assets/{resolve-3Tqh9AWQ.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-B6PQ6iae.js → server-C1jZZ61O.js} +896 -277
- package/dist/assets/server-C1jZZ61O.js.map +1 -0
- package/dist/assets/{src-ChJijTlM.js → src-DJe-OYxd.js} +1010 -236
- package/dist/assets/src-DJe-OYxd.js.map +1 -0
- package/dist/assets/{sshForges-Brf0fslM.js → sshForges-C9zTO72R.js} +4 -3
- package/dist/assets/sshForges-C9zTO72R.js.map +1 -0
- package/dist/assets/{translate-xLme9Rdh.js → translate-CUuC5szR.js} +36 -15
- package/dist/assets/translate-CUuC5szR.js.map +1 -0
- package/dist/assets/{usdt-CSU5KzTV.js → usdt-DI51znt-.js} +3 -3
- package/dist/assets/{usdt-CSU5KzTV.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-BM3PsXbB.js.map +0 -1
- package/dist/assets/apiKit-lCTQ0EBG.js.map +0 -1
- package/dist/assets/apps-Do26w3c7.js.map +0 -1
- package/dist/assets/backup-j47AzDvG.js.map +0 -1
- package/dist/assets/buttons-CiGlBVBT.js.map +0 -1
- package/dist/assets/buttons-D2l2bVCG.js +0 -2
- package/dist/assets/client-raIncVtF.js.map +0 -1
- package/dist/assets/errors-Dt-ZnyOX.js.map +0 -1
- package/dist/assets/host-8RskzQgB.js.map +0 -1
- package/dist/assets/irohWeb-DGelfgDJ.js.map +0 -1
- package/dist/assets/main-BC33ooYg.js.map +0 -1
- package/dist/assets/mainline-DYrjsS1t.js.map +0 -1
- package/dist/assets/ownStatus-D7dB4zJB.js.map +0 -1
- package/dist/assets/profiles-NyF5FnYF.js.map +0 -1
- package/dist/assets/registry-DKDInr0A.js.map +0 -1
- package/dist/assets/secretGuard-DUr6bgKc.js +0 -2
- package/dist/assets/server-B6PQ6iae.js.map +0 -1
- package/dist/assets/src-ChJijTlM.js.map +0 -1
- package/dist/assets/sshForges-Brf0fslM.js.map +0 -1
- package/dist/assets/translate-xLme9Rdh.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,
|
|
@@ -1532,21 +1593,28 @@ var commands$6 = {
|
|
|
1532
1593
|
},
|
|
1533
1594
|
"chat remove": {
|
|
1534
1595
|
method: "chat.remove",
|
|
1535
|
-
usage: "chat remove <chat> --yes",
|
|
1536
|
-
summary: "Delete a chat, its keys and history on this device",
|
|
1596
|
+
usage: "chat remove <chat> --yes [--force]",
|
|
1597
|
+
summary: "Delete a chat, its keys and history on this device; refused while a message you deleted for everyone has not reached the contact, unless --force",
|
|
1537
1598
|
args: ["chat"],
|
|
1538
|
-
options: {
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1599
|
+
options: {
|
|
1600
|
+
yes: {
|
|
1601
|
+
type: "boolean",
|
|
1602
|
+
description: "Confirm"
|
|
1603
|
+
},
|
|
1604
|
+
force: {
|
|
1605
|
+
type: "boolean",
|
|
1606
|
+
description: "Remove it even if a message you deleted for everyone has not reached the contact yet"
|
|
1607
|
+
}
|
|
1608
|
+
},
|
|
1542
1609
|
params: ({ options }, { chat }) => ({
|
|
1543
1610
|
chat,
|
|
1544
|
-
yes: options.yes === true
|
|
1611
|
+
yes: options.yes === true,
|
|
1612
|
+
force: options.force === true
|
|
1545
1613
|
})
|
|
1546
1614
|
},
|
|
1547
1615
|
"chat rename": {
|
|
1548
1616
|
method: "chat.rename",
|
|
1549
|
-
usage: "chat rename <chat>
|
|
1617
|
+
usage: "chat rename <chat> [name...]",
|
|
1550
1618
|
summary: "Name a chat on this side (empty: the contact's name)",
|
|
1551
1619
|
args: ["chat", "name...?"],
|
|
1552
1620
|
params: (_, { chat, name }) => ({
|
|
@@ -1781,7 +1849,7 @@ var commands$6 = {
|
|
|
1781
1849
|
params: ({ options }, a) => ({
|
|
1782
1850
|
chat: a.chat,
|
|
1783
1851
|
message: a.message,
|
|
1784
|
-
emoji: a.emoji,
|
|
1852
|
+
emoji: reaction(options, a.emoji),
|
|
1785
1853
|
remove: options.remove === true,
|
|
1786
1854
|
wait: options.wait,
|
|
1787
1855
|
timeout: timeout(options)
|
|
@@ -1970,6 +2038,11 @@ function voiceOf(options) {
|
|
|
1970
2038
|
peaks: bars
|
|
1971
2039
|
};
|
|
1972
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
|
+
}
|
|
1973
2046
|
/** Files: one entry per command, in alphabetical order (test/commands.test.ts checks). */
|
|
1974
2047
|
var commands$5 = {
|
|
1975
2048
|
"file accept": {
|
|
@@ -2138,22 +2211,26 @@ var commands$5 = {
|
|
|
2138
2211
|
description: "Send even if --name looks like a seed, a key or ecash"
|
|
2139
2212
|
}
|
|
2140
2213
|
},
|
|
2141
|
-
params: ({ options }, a) =>
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
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
|
+
}
|
|
2152
2229
|
},
|
|
2153
2230
|
"file wait": {
|
|
2154
2231
|
method: "file.wait",
|
|
2155
2232
|
usage: "file wait [<chat>] <file> [--timeout s]",
|
|
2156
|
-
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",
|
|
2157
2234
|
args: ["chat?", "file"],
|
|
2158
2235
|
options: { timeout: {
|
|
2159
2236
|
type: "number",
|
|
@@ -2216,7 +2293,7 @@ var commands$4 = {
|
|
|
2216
2293
|
if (!a.path && options.clear !== true) throw new CliError("usage", "Missing <jpeg>: ghostly profile picture <jpeg> | --clear");
|
|
2217
2294
|
if (a.path && options.clear === true) throw new CliError("usage", "--clear removes the picture: not with a <jpeg>");
|
|
2218
2295
|
return {
|
|
2219
|
-
path: here(a.path || void 0),
|
|
2296
|
+
path: picture(here(a.path || void 0)),
|
|
2220
2297
|
clear: options.clear === true
|
|
2221
2298
|
};
|
|
2222
2299
|
}
|
|
@@ -2501,7 +2578,7 @@ var commands$3 = {
|
|
|
2501
2578
|
if (a.path && options.clear === true) throw new CliError("usage", "--clear removes the picture: not with a <jpeg>");
|
|
2502
2579
|
return {
|
|
2503
2580
|
group: a.group,
|
|
2504
|
-
path: here(a.path || void 0),
|
|
2581
|
+
path: picture(here(a.path || void 0)),
|
|
2505
2582
|
clear: options.clear === true
|
|
2506
2583
|
};
|
|
2507
2584
|
}
|
|
@@ -2529,7 +2606,7 @@ var commands$3 = {
|
|
|
2529
2606
|
params: ({ options }, a) => ({
|
|
2530
2607
|
group: a.group,
|
|
2531
2608
|
message: a.message,
|
|
2532
|
-
emoji: a.emoji,
|
|
2609
|
+
emoji: reaction(options, a.emoji),
|
|
2533
2610
|
remove: options.remove === true,
|
|
2534
2611
|
wait: options.wait,
|
|
2535
2612
|
timeout: timeout(options)
|
|
@@ -2742,6 +2819,26 @@ var commands$2 = {
|
|
|
2742
2819
|
};
|
|
2743
2820
|
//#endregion
|
|
2744
2821
|
//#region src/commands/payments.ts
|
|
2822
|
+
/**
|
|
2823
|
+
* `chat accept`'s --networks: mainnet and/or testnet, comma-separated; any other word, or none (an unset variable), is a
|
|
2824
|
+
* usage error before the profile opens, as a word --network does not take is. Before, the API refused it after a
|
|
2825
|
+
* one-shot had opened the profile: bad_request, exit 1.
|
|
2826
|
+
*/
|
|
2827
|
+
function networkList(value) {
|
|
2828
|
+
const networks = value.split(",").map((n) => n.trim()).filter(Boolean);
|
|
2829
|
+
if (!networks.length) throw new CliError("usage", `--networks takes mainnet, testnet or mainnet,testnet (to stop taking it: --off), not ${JSON.stringify(value)}`);
|
|
2830
|
+
if (!networks.every((n) => n === "mainnet" || n === "testnet")) throw new CliError("usage", `--networks takes mainnet, testnet or mainnet,testnet, not ${JSON.stringify(value)}`);
|
|
2831
|
+
return networks;
|
|
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
|
+
}
|
|
2745
2842
|
/** Wallets and payments: one entry per command, in alphabetical order (test/commands.test.ts checks). */
|
|
2746
2843
|
var commands$1 = {
|
|
2747
2844
|
"chat accept": {
|
|
@@ -2767,7 +2864,7 @@ var commands$1 = {
|
|
|
2767
2864
|
chat: a.chat,
|
|
2768
2865
|
method: a.method,
|
|
2769
2866
|
on: options.off !== true,
|
|
2770
|
-
networks: typeof options.networks === "string" ? options.networks
|
|
2867
|
+
networks: typeof options.networks === "string" ? networkList(options.networks) : void 0
|
|
2771
2868
|
};
|
|
2772
2869
|
}
|
|
2773
2870
|
},
|
|
@@ -2821,14 +2918,14 @@ var commands$1 = {
|
|
|
2821
2918
|
"chat request": {
|
|
2822
2919
|
method: "chat.request",
|
|
2823
2920
|
usage: "chat request <chat> <sats> [--memo t] [--method m] [--rail cashu|lightning] [--network testnet] [--card <id>] [--force]",
|
|
2824
|
-
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)",
|
|
2825
2922
|
args: ["chat", "amount"],
|
|
2826
2923
|
options: {
|
|
2827
2924
|
memo,
|
|
2828
2925
|
method: {
|
|
2829
2926
|
type: "string",
|
|
2830
2927
|
choices: PAY_METHODS,
|
|
2831
|
-
description: "cashu, arkade, usdt, bitcoin, spark, …"
|
|
2928
|
+
description: "cashu, arkade, usdt (amount in USDT), bitcoin, spark, …"
|
|
2832
2929
|
},
|
|
2833
2930
|
rail: {
|
|
2834
2931
|
type: "string",
|
|
@@ -2841,7 +2938,7 @@ var commands$1 = {
|
|
|
2841
2938
|
},
|
|
2842
2939
|
params: ({ options }, a) => ({
|
|
2843
2940
|
chat: a.chat,
|
|
2844
|
-
amount:
|
|
2941
|
+
amount: requestAmount(a.amount, options.method),
|
|
2845
2942
|
memo: options.memo,
|
|
2846
2943
|
method: options.method,
|
|
2847
2944
|
rail: options.rail,
|
|
@@ -3427,11 +3524,14 @@ var Allowlist = class {
|
|
|
3427
3524
|
}
|
|
3428
3525
|
async allows(event) {
|
|
3429
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);
|
|
3430
3529
|
if (!("chat" in event)) return true;
|
|
3431
3530
|
const chat = event.chat;
|
|
3432
3531
|
if (typeof chat !== "string") return false;
|
|
3433
3532
|
if (this.chats.has(chat)) return true;
|
|
3434
3533
|
if (!this.keys.size) return false;
|
|
3534
|
+
if (event.type === "chat.removed" && typeof event.peer === "string") return this.keys.has(event.peer);
|
|
3435
3535
|
let key = this.peers.get(chat);
|
|
3436
3536
|
if (!key) {
|
|
3437
3537
|
key = await this.peerOf(chat).catch(() => null) || void 0;
|
|
@@ -3467,7 +3567,8 @@ async function allowlist(from, groups, call, peerOf) {
|
|
|
3467
3567
|
}
|
|
3468
3568
|
/**
|
|
3469
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
|
|
3470
|
-
* `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.
|
|
3471
3572
|
*/
|
|
3472
3573
|
async function otherFlag(lookup, ref, flag) {
|
|
3473
3574
|
try {
|
|
@@ -3475,7 +3576,8 @@ async function otherFlag(lookup, ref, flag) {
|
|
|
3475
3576
|
} catch (error) {
|
|
3476
3577
|
const other = flag === "--from" ? "group" : "chat";
|
|
3477
3578
|
if (!(error instanceof CliError) || error.code !== "not_found" || typeof error.details?.[other] !== "string") throw error;
|
|
3478
|
-
const
|
|
3579
|
+
const named = other === "chat" ? error.details.chat : ref;
|
|
3580
|
+
const shown = /^[\w.:-]+$/.test(named) ? named : JSON.stringify(named);
|
|
3479
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);
|
|
3480
3582
|
}
|
|
3481
3583
|
}
|
|
@@ -3690,6 +3792,13 @@ function checkTypes(types, warn) {
|
|
|
3690
3792
|
if (type === "*") continue;
|
|
3691
3793
|
const family = type.split(/[.*]/)[0];
|
|
3692
3794
|
if (!EVENT_FAMILIES.includes(family)) throw new CliError("usage", `No event is of type ${type}: --type takes a type, or a family (${EVENT_FAMILIES.join(", ")})`);
|
|
3795
|
+
const known = EVENT_TYPES.filter((each) => matches({
|
|
3796
|
+
seq: 0,
|
|
3797
|
+
id: "",
|
|
3798
|
+
type: each,
|
|
3799
|
+
at: 0
|
|
3800
|
+
}, [type]));
|
|
3801
|
+
if (known.length === 1 && known[0] === "agent.turn") throw new CliError("usage", `No event is of type ${type} without --turns: ghostly listen --turns gives agent.turn events, in the place of --type`);
|
|
3693
3802
|
if (!EVENT_TYPES.some((known) => matches({
|
|
3694
3803
|
seq: 0,
|
|
3695
3804
|
id: "",
|
|
@@ -3709,7 +3818,7 @@ var HOOK_OUTPUT_GRACE_MS = 1e3;
|
|
|
3709
3818
|
* `toStderr` (with `--print`, whose stdout is the JSON stream): the hook's stdout is streamed to listen's stderr, so a
|
|
3710
3819
|
* hook that echoes never puts a line that is not an event into the stream. Piped as it comes, never held in memory.
|
|
3711
3820
|
*/
|
|
3712
|
-
function runExec(command, event, toStderr) {
|
|
3821
|
+
function runExec(command, event, toStderr, profile) {
|
|
3713
3822
|
const group = process.platform !== "win32";
|
|
3714
3823
|
const child = spawn(command, {
|
|
3715
3824
|
shell: true,
|
|
@@ -3721,6 +3830,10 @@ function runExec(command, event, toStderr) {
|
|
|
3721
3830
|
],
|
|
3722
3831
|
env: {
|
|
3723
3832
|
...hookEnv(process.env),
|
|
3833
|
+
...profile ? {
|
|
3834
|
+
GHOSTLY_HOME: profile.home,
|
|
3835
|
+
GHOSTLY_PROFILE: profile.name
|
|
3836
|
+
} : {},
|
|
3724
3837
|
GHOSTLY_EVENT_TYPE: event.type,
|
|
3725
3838
|
GHOSTLY_EVENT_ID: event.id,
|
|
3726
3839
|
GHOSTLY_EVENT_SEQ: String(event.seq)
|
|
@@ -3772,7 +3885,8 @@ function runExec(command, event, toStderr) {
|
|
|
3772
3885
|
/** The longest wait between two tries of a webhook that is not answering. */
|
|
3773
3886
|
var RETRY_MAX_MS = 6e4;
|
|
3774
3887
|
/**
|
|
3775
|
-
* 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).
|
|
3776
3890
|
* A bridge that is not there (refused connection, timeout, 5xx, 408, 429) has not handled the event: it is tried again,
|
|
3777
3891
|
* waiting up to a minute between tries, for as long as it takes, so the cursor never moves past it. Before, three tries
|
|
3778
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.
|
|
@@ -3801,7 +3915,7 @@ async function post(url, event, retryMs) {
|
|
|
3801
3915
|
status = response.status;
|
|
3802
3916
|
down = status >= 500 || status === 408 || status === 429;
|
|
3803
3917
|
} catch {}
|
|
3804
|
-
if (!down
|
|
3918
|
+
if (!down) return status;
|
|
3805
3919
|
if (down && attempt >= 2 && !holding) {
|
|
3806
3920
|
holding = true;
|
|
3807
3921
|
process.stderr.write(`ghostly: the webhook at ${url.origin} is not answering: holding event ${event.seq} (${event.type}) until it does\n`);
|
|
@@ -3858,15 +3972,12 @@ function eventHandler(options) {
|
|
|
3858
3972
|
if (stopped) return;
|
|
3859
3973
|
const skip = () => keep(event.seq);
|
|
3860
3974
|
if (options.allow && !await options.allow.allows(event)) return skip();
|
|
3975
|
+
if (options.turns && !gap && !toTurn(event)) return skip();
|
|
3861
3976
|
if (options.translate) event = await options.translate(event);
|
|
3862
|
-
if (options.turns && !gap)
|
|
3863
|
-
const next = toTurn(event);
|
|
3864
|
-
if (!next) return skip();
|
|
3865
|
-
event = next;
|
|
3866
|
-
}
|
|
3977
|
+
if (options.turns && !gap) event = toTurn(event);
|
|
3867
3978
|
const full = options.print && options.write(jsonOut(event)) === false;
|
|
3868
3979
|
if (options.exec) {
|
|
3869
|
-
const hook = running = runExec(options.exec, event, options.print);
|
|
3980
|
+
const hook = running = runExec(options.exec, event, options.print, options.profile);
|
|
3870
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);
|
|
3871
3982
|
const { code, signal } = await hook.ended.finally(() => {
|
|
3872
3983
|
clearTimeout(slow);
|
|
@@ -4091,6 +4202,7 @@ async function secretsFromStdin(method, params, read, tty = false, note = () =>
|
|
|
4091
4202
|
if (method === "wallet.create") {
|
|
4092
4203
|
const onLine = params.apiKey !== void 0;
|
|
4093
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");
|
|
4094
4206
|
const values = { ...params.values };
|
|
4095
4207
|
for (const line of (await read()).split(/\r?\n/)) {
|
|
4096
4208
|
if (!line.trim()) continue;
|
|
@@ -4107,6 +4219,17 @@ async function secretsFromStdin(method, params, read, tty = false, note = () =>
|
|
|
4107
4219
|
}
|
|
4108
4220
|
}
|
|
4109
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
|
+
/**
|
|
4110
4233
|
* `send`, `edit`, `group send` and `group edit` with no text words read it from stdin the same way: `command` is the
|
|
4111
4234
|
* command line as given (`send bob`). `asked`: `--stdin`, which waits as long as it takes.
|
|
4112
4235
|
*/
|
|
@@ -4240,15 +4363,15 @@ var VERSION = package_default.version;
|
|
|
4240
4363
|
* command a running daemon answers loads none of them, and starts about as fast as Node does. Statically imported, they
|
|
4241
4364
|
* cost every command ~100 ms before its socket was opened.
|
|
4242
4365
|
*/
|
|
4243
|
-
var engineApi = () => import("./api-
|
|
4244
|
-
var engineHost = () => import("./host-
|
|
4366
|
+
var engineApi = () => import("./api-BwyFq4lA.js");
|
|
4367
|
+
var engineHost = () => import("./host-C0NMNQLl.js");
|
|
4245
4368
|
/**
|
|
4246
4369
|
* `--translate <lang>`'s translator, or null (not asked; or the runtime is not there, said on stderr). Loaded only when
|
|
4247
4370
|
* asked: the app's message parser it reads costs every other command nothing.
|
|
4248
4371
|
*/
|
|
4249
4372
|
async function translatorFor(value, home) {
|
|
4250
4373
|
if (value === void 0) return null;
|
|
4251
|
-
const { loadDetector, openTranslator, translateTarget } = await import("./translate-
|
|
4374
|
+
const { loadDetector, openTranslator, translateTarget } = await import("./translate-CUuC5szR.js");
|
|
4252
4375
|
return openTranslator({
|
|
4253
4376
|
home,
|
|
4254
4377
|
to: translateTarget(value),
|
|
@@ -4260,6 +4383,11 @@ var pretty = false;
|
|
|
4260
4383
|
function print(value) {
|
|
4261
4384
|
process.stdout.write(jsonOut(value, pretty ? 2 : void 0) + "\n");
|
|
4262
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;
|
|
4263
4391
|
/** Done, with something to know (a voice note sent without its waveform): said on stderr, the JSON stays the answer. */
|
|
4264
4392
|
function printAnswer(result) {
|
|
4265
4393
|
if (typeof result?.warning === "string") {
|
|
@@ -4268,9 +4396,11 @@ function printAnswer(result) {
|
|
|
4268
4396
|
}
|
|
4269
4397
|
print(result);
|
|
4270
4398
|
}
|
|
4271
|
-
|
|
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 } = {}) {
|
|
4272
4401
|
const home = ghostlyHome(parsed.options.home);
|
|
4273
|
-
const
|
|
4402
|
+
const option = parsed.options.profile;
|
|
4403
|
+
const profile = ownProfile ? currentProfileOrNone(home, option) ?? "default" : currentProfile(home, option);
|
|
4274
4404
|
return {
|
|
4275
4405
|
home,
|
|
4276
4406
|
profile,
|
|
@@ -4367,6 +4497,7 @@ function chatOnly(method, params) {
|
|
|
4367
4497
|
function chatOrGroup(method, params) {
|
|
4368
4498
|
if (method.startsWith("task.") || method.startsWith("routine.") || method.startsWith("button.") || method === "usage.send") return true;
|
|
4369
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;
|
|
4370
4501
|
return method === "chat.pin" || method === "chat.forward";
|
|
4371
4502
|
}
|
|
4372
4503
|
/**
|
|
@@ -4388,6 +4519,49 @@ function newChatOnly(method) {
|
|
|
4388
4519
|
function oneChatOnly(method, params) {
|
|
4389
4520
|
return newChatOnly(method) || (chatOnly(method, params) || chatOrGroup(method, params)) && typeof params.chat === "string";
|
|
4390
4521
|
}
|
|
4522
|
+
/** What a member says in one group, over that group's own edges: no 1:1 chat carries any of it. */
|
|
4523
|
+
var GROUP_EDGES_ONLY = /* @__PURE__ */ new Set([
|
|
4524
|
+
"group.send",
|
|
4525
|
+
"group.edit",
|
|
4526
|
+
"group.react",
|
|
4527
|
+
"group.typing"
|
|
4528
|
+
]);
|
|
4529
|
+
/**
|
|
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
|
|
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.
|
|
4535
|
+
*/
|
|
4536
|
+
function oneGroupOnly(method) {
|
|
4537
|
+
return GROUP_EDGES_ONLY.has(method);
|
|
4538
|
+
}
|
|
4539
|
+
/**
|
|
4540
|
+
* Reads that need nothing of a chat's history: a one-shot for one leaves every saved chat unstarted too (`deferChats`),
|
|
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:
|
|
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.
|
|
4545
|
+
*/
|
|
4546
|
+
var NO_HISTORY_READS = /* @__PURE__ */ new Set([
|
|
4547
|
+
"status",
|
|
4548
|
+
"profile.get",
|
|
4549
|
+
"settings.get",
|
|
4550
|
+
"status.get",
|
|
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"
|
|
4560
|
+
]);
|
|
4561
|
+
/** Whether a one-shot for this call leaves every saved chat unstarted, its history unread (`NO_HISTORY_READS`). */
|
|
4562
|
+
function readsNoHistory(method) {
|
|
4563
|
+
return NO_HISTORY_READS.has(method);
|
|
4564
|
+
}
|
|
4391
4565
|
/**
|
|
4392
4566
|
* Calls that only read what the profile stores: a one-shot for one opens it offline (`RuntimeOptions.offline`).
|
|
4393
4567
|
* Opened online, `status` or `chat list` started every chat, put the profile's records on the relays again and waited
|
|
@@ -4432,7 +4606,7 @@ function readOnly(method, params) {
|
|
|
4432
4606
|
/**
|
|
4433
4607
|
* Calls whose change stays on this device: a chat's name here, a chat removed (nothing goes to the contact), auto-answer
|
|
4434
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
|
|
4435
|
-
* 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
|
|
4436
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
|
|
4437
4611
|
* online: it settles a file offer already on the DHT.
|
|
4438
4612
|
*/
|
|
@@ -4448,6 +4622,8 @@ var LOCAL_WRITES = /* @__PURE__ */ new Set([
|
|
|
4448
4622
|
"x401.credential.remove",
|
|
4449
4623
|
"saved.add",
|
|
4450
4624
|
"saved.remove",
|
|
4625
|
+
"app.serve",
|
|
4626
|
+
"app.unserve",
|
|
4451
4627
|
"status.set",
|
|
4452
4628
|
"status.clear"
|
|
4453
4629
|
]);
|
|
@@ -4468,9 +4644,26 @@ var LOCAL_SETTINGS = /* @__PURE__ */ new Set([
|
|
|
4468
4644
|
* to be live (`keepOneShot`), so that one stays online.
|
|
4469
4645
|
*/
|
|
4470
4646
|
var LIVE_ONLY = /* @__PURE__ */ new Set(["chat.typing", "group.typing"]);
|
|
4471
|
-
/**
|
|
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. */
|
|
4472
4665
|
function offlineCall(method, params) {
|
|
4473
|
-
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;
|
|
4474
4667
|
}
|
|
4475
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
|
|
4476
4669
|
* contact carries its own `--timeout` (or the daemon's default for it), plus a margin; anything else may take as long
|
|
@@ -4490,8 +4683,8 @@ async function session(g, options, again = true) {
|
|
|
4490
4683
|
const [, { callApi, startNamedChats }] = await Promise.all([engineHost(), engineApi()]);
|
|
4491
4684
|
const host = await openOneShot(g, options);
|
|
4492
4685
|
if (host instanceof DaemonClient) return throughDaemon(host, anew);
|
|
4493
|
-
const call = (m, p) => {
|
|
4494
|
-
if (options.deferChats && p && typeof p === "object") startNamedChats(host.ctx, p);
|
|
4686
|
+
const call = async (m, p) => {
|
|
4687
|
+
if (options.deferChats && p && typeof p === "object") await startNamedChats(host.ctx, p);
|
|
4495
4688
|
return callApi(host.ctx, m, p ?? {});
|
|
4496
4689
|
};
|
|
4497
4690
|
return {
|
|
@@ -4591,12 +4784,13 @@ var TURNS_WAIT_MS = 6e4;
|
|
|
4591
4784
|
* failed busy, told to start the daemon that was running. A daemon that marked its start is waited for up to
|
|
4592
4785
|
* STARTING_WAIT_MS, and named as the holder. So is a profile a `daemon restart` or `daemon --detach` keeps for the daemon
|
|
4593
4786
|
* it starts (`daemonClaim`): the commands that took the profile in turn in the gap kept that daemon from ever starting.
|
|
4594
|
-
* A `listen` with no daemon opens it the same way, as the daemon (`mode`).
|
|
4787
|
+
* A `listen` with no daemon opens it the same way, as the daemon (`mode`). A wait that goes on past WAIT_NOTICE_MS says
|
|
4788
|
+
* on a terminal what it waits for, once per kind of holder: it said nothing for up to 30 s (60 s behind commands in turn).
|
|
4595
4789
|
*/
|
|
4596
4790
|
async function openOneShot(g, options = {}, mode = "one-shot") {
|
|
4597
4791
|
const { openHost } = await engineHost();
|
|
4598
4792
|
const from = performance.now();
|
|
4599
|
-
let holder, since = from;
|
|
4793
|
+
let holder, since = from, told;
|
|
4600
4794
|
for (;;) try {
|
|
4601
4795
|
return await openHost(g.paths, mode, VERSION, options);
|
|
4602
4796
|
} catch (error) {
|
|
@@ -4617,6 +4811,12 @@ async function openOneShot(g, options = {}, mode = "one-shot") {
|
|
|
4617
4811
|
const held = now - since >= HOLDER_WAIT_MS ? `was not free after ${HOLDER_WAIT_MS / 1e3} s` : `was taken by one process after another for ${TURNS_WAIT_MS / 1e3} s`;
|
|
4618
4812
|
throw new CliError("busy", `Profile ${g.profile} is in use by ${pid ? `process ${pid}, another ghostly command,` : "another ghostly command"} and ${held}: run the commands one after another, or start \`ghostly daemon --detach\` so they can run at once`, error.details);
|
|
4619
4813
|
}
|
|
4814
|
+
const kind = claimed !== null ? "claimed" : starting !== null ? "starting" : "command";
|
|
4815
|
+
if (process.stderr.isTTY && now - from >= 1e3 && told !== kind) {
|
|
4816
|
+
told = kind;
|
|
4817
|
+
const line = claimed !== null ? `profile ${g.profile} is kept for the daemon that process ${claimed} (ghostly daemon) starts: waiting for it (up to ${STARTING_WAIT_MS / 1e3} s` : starting !== null ? `profile ${g.profile}'s daemon (process ${starting}) is starting: waiting for it (up to ${STARTING_WAIT_MS / 1e3} s` : `profile ${g.profile} is in use by ${pid ? `process ${pid}, another ghostly command` : "another ghostly command"}: waiting for it to let go (up to ${HOLDER_WAIT_MS / 1e3} s`;
|
|
4818
|
+
process.stderr.write(`ghostly: ${line}; Ctrl-C stops waiting)\n`);
|
|
4819
|
+
}
|
|
4620
4820
|
await new Promise((resolve) => setTimeout(resolve, Math.min(50 + Math.random() * 50, left)));
|
|
4621
4821
|
}
|
|
4622
4822
|
}
|
|
@@ -4779,7 +4979,7 @@ var SPECIAL = [
|
|
|
4779
4979
|
"A backup of the profile, encrypted with a passphrase (from a file or GHOSTLY_BACKUP_PASSPHRASE); --no-passphrase makes one anyone can read",
|
|
4780
4980
|
{
|
|
4781
4981
|
out: o("string", "The backup file to write"),
|
|
4782
|
-
"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)"),
|
|
4783
4983
|
passphrase: {
|
|
4784
4984
|
...o("boolean", "Do not encrypt. The file then holds the profile's keys and wallet secrets in the clear"),
|
|
4785
4985
|
negatedOnly: true
|
|
@@ -4791,7 +4991,7 @@ var SPECIAL = [
|
|
|
4791
4991
|
"profile restore <file> <new profile> [--passphrase-file f] [--use]",
|
|
4792
4992
|
"A backup into a new profile (a backup made with --no-passphrase needs none)",
|
|
4793
4993
|
{
|
|
4794
|
-
"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)"),
|
|
4795
4995
|
use: o("boolean", "Make it the current profile")
|
|
4796
4996
|
}
|
|
4797
4997
|
],
|
|
@@ -4851,7 +5051,7 @@ var SPECIAL = [
|
|
|
4851
5051
|
"confirm-real": o("boolean", "Confirm a Mainnet (real money) spend"),
|
|
4852
5052
|
"show-secret": o("boolean", "Print a call's secrets"),
|
|
4853
5053
|
yes: o("boolean", "Confirm a call that deletes chats or groups"),
|
|
4854
|
-
force: o("boolean", "Send a text that looks like a secret")
|
|
5054
|
+
force: o("boolean", "Send a text that looks like a secret, or remove a chat (or clear the profile) while a delete for everyone has not reached the contact")
|
|
4855
5055
|
}
|
|
4856
5056
|
],
|
|
4857
5057
|
[
|
|
@@ -4941,14 +5141,15 @@ function helpRow(label, text, at, columns) {
|
|
|
4941
5141
|
}
|
|
4942
5142
|
/**
|
|
4943
5143
|
* What `ghostly` says first in a Ghostly folder with no profile yet: where to start, as the README's "Five minutes"
|
|
4944
|
-
* 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.
|
|
4945
5146
|
*/
|
|
4946
5147
|
var FIRST_STEPS = [
|
|
4947
5148
|
"First steps:",
|
|
4948
|
-
" $ ghostly invite create --label alice
|
|
4949
|
-
" $ ghostly invite join
|
|
4950
|
-
" $ ghostly daemon --detach
|
|
4951
|
-
" $ 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"
|
|
4952
5153
|
];
|
|
4953
5154
|
function help(firstSteps = false) {
|
|
4954
5155
|
const columns = helpColumns();
|
|
@@ -5053,7 +5254,7 @@ function commandHelp(words) {
|
|
|
5053
5254
|
return lines.join("\n");
|
|
5054
5255
|
}
|
|
5055
5256
|
async function profileCommand(sub, argv) {
|
|
5056
|
-
const
|
|
5257
|
+
const specs = {
|
|
5057
5258
|
create: {
|
|
5058
5259
|
use: {
|
|
5059
5260
|
type: "boolean",
|
|
@@ -5111,8 +5312,20 @@ async function profileCommand(sub, argv) {
|
|
|
5111
5312
|
description: ""
|
|
5112
5313
|
}
|
|
5113
5314
|
}
|
|
5114
|
-
}
|
|
5115
|
-
|
|
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 ?? "") });
|
|
5116
5329
|
pretty = g.pretty;
|
|
5117
5330
|
switch (sub) {
|
|
5118
5331
|
case "create": {
|
|
@@ -5121,7 +5334,7 @@ async function profileCommand(sub, argv) {
|
|
|
5121
5334
|
noMoreThan(1, parsed.positionals, "profile create <name> [--use] [--name <shown name>] [--force]");
|
|
5122
5335
|
const shownName = parsed.options.name === void 0 ? void 0 : checkShownNameOption(parsed.options.name);
|
|
5123
5336
|
const force = parsed.options.force === true;
|
|
5124
|
-
if (shownName) (await import("./secretGuard-
|
|
5337
|
+
if (shownName) (await import("./secretGuard-DCb1I0_B.js")).guardText(shownName, force, "name", "set it");
|
|
5125
5338
|
const paths = createProfile(g.home, name);
|
|
5126
5339
|
let shown = null;
|
|
5127
5340
|
if (shownName !== void 0) try {
|
|
@@ -5144,14 +5357,14 @@ async function profileCommand(sub, argv) {
|
|
|
5144
5357
|
print({
|
|
5145
5358
|
created: name,
|
|
5146
5359
|
folder: paths.dir,
|
|
5147
|
-
current:
|
|
5360
|
+
current: currentProfileOrNone(g.home) === name,
|
|
5148
5361
|
...shown ? { profile: shown } : {}
|
|
5149
5362
|
});
|
|
5150
5363
|
return;
|
|
5151
5364
|
}
|
|
5152
5365
|
case "list": {
|
|
5153
5366
|
noMoreThan(0, parsed.positionals, "profile list");
|
|
5154
|
-
const current =
|
|
5367
|
+
const current = currentProfileOrNone(g.home);
|
|
5155
5368
|
print({
|
|
5156
5369
|
profiles: listProfiles(g.home).map((name) => ({
|
|
5157
5370
|
name,
|
|
@@ -5167,12 +5380,17 @@ async function profileCommand(sub, argv) {
|
|
|
5167
5380
|
if (!name) throw new CliError("usage", "Missing <name>: ghostly profile use <name>");
|
|
5168
5381
|
noMoreThan(1, parsed.positionals, "profile use <name>");
|
|
5169
5382
|
selectProfile(g.home, name);
|
|
5170
|
-
|
|
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 });
|
|
5171
5386
|
return;
|
|
5172
5387
|
}
|
|
5173
5388
|
case "show":
|
|
5174
5389
|
noMoreThan(0, parsed.positionals, "profile show");
|
|
5175
|
-
print(await withSession(g, (s) => s.call("profile.get"), {
|
|
5390
|
+
print(await withSession(g, (s) => s.call("profile.get"), {
|
|
5391
|
+
offline: true,
|
|
5392
|
+
deferChats: readsNoHistory("profile.get")
|
|
5393
|
+
}));
|
|
5176
5394
|
return;
|
|
5177
5395
|
case "set": {
|
|
5178
5396
|
noMoreThan(0, parsed.positionals, "profile set [--name <name>] [--share-profile | --no-share-profile] [--force]");
|
|
@@ -5188,21 +5406,22 @@ async function profileCommand(sub, argv) {
|
|
|
5188
5406
|
return;
|
|
5189
5407
|
}
|
|
5190
5408
|
case "backup": {
|
|
5409
|
+
if (parsed.options.passphrase === true) throw new CliError("usage", PASSPHRASE_ON_LINE);
|
|
5191
5410
|
noMoreThan(0, parsed.positionals, "profile backup --out <file> [--passphrase-file f | --no-passphrase] [--light]");
|
|
5192
5411
|
const out = parsed.options.out;
|
|
5193
5412
|
if (typeof out !== "string") throw new CliError("usage", "Missing --out: ghostly profile backup --out <file> [--passphrase-file f | --no-passphrase] [--light]");
|
|
5194
5413
|
const unsealed = parsed.options.passphrase === false;
|
|
5195
|
-
if (parsed.options.passphrase === true) throw new CliError("usage", "The passphrase comes from --passphrase-file or GHOSTLY_BACKUP_PASSPHRASE, never the command line");
|
|
5196
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");
|
|
5197
5415
|
const light = parsed.options.light === true ? { light: true } : {};
|
|
5198
|
-
const
|
|
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)}`);
|
|
5199
5418
|
const params = unsealed ? {
|
|
5200
5419
|
path,
|
|
5201
5420
|
noPassphrase: true,
|
|
5202
5421
|
...light
|
|
5203
5422
|
} : {
|
|
5204
5423
|
path,
|
|
5205
|
-
passphrase: backupPassphrase(parsed.options["passphrase-file"]),
|
|
5424
|
+
passphrase: await backupPassphrase(parsed.options["passphrase-file"]),
|
|
5206
5425
|
...light
|
|
5207
5426
|
};
|
|
5208
5427
|
const made = await withSession(g, (s) => s.call("profile.backup", params), { offline: true });
|
|
@@ -5215,15 +5434,15 @@ async function profileCommand(sub, argv) {
|
|
|
5215
5434
|
if (!given || !name) throw new CliError("usage", `Missing <${given ? "new profile" : "file"}>: ghostly profile restore <file> <new profile> [--passphrase-file f] [--use]`);
|
|
5216
5435
|
noMoreThan(2, parsed.positionals, "profile restore <file> <new profile> [--passphrase-file f] [--use]");
|
|
5217
5436
|
const file = here(given);
|
|
5218
|
-
const { backupFileProtection, restoreProfile } = await import("./backup-
|
|
5437
|
+
const { backupFileProtection, restoreProfile } = await import("./backup-CdEzTq5C.js");
|
|
5219
5438
|
const protection = await backupFileProtection(file);
|
|
5220
|
-
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));
|
|
5221
5440
|
if (parsed.options.use) selectProfile(g.home, name);
|
|
5222
5441
|
print({
|
|
5223
5442
|
restored: name,
|
|
5224
5443
|
folder: paths.dir,
|
|
5225
5444
|
protection,
|
|
5226
|
-
current:
|
|
5445
|
+
current: currentProfileOrNone(g.home) === name
|
|
5227
5446
|
});
|
|
5228
5447
|
return;
|
|
5229
5448
|
}
|
|
@@ -5257,24 +5476,33 @@ function onStopSignals(stop) {
|
|
|
5257
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";
|
|
5258
5477
|
/** Restore takes no --no-passphrase: a backup made without one says so itself. */
|
|
5259
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
|
+
};
|
|
5260
5485
|
/**
|
|
5261
5486
|
* The backup passphrase: from a file or the environment, never the command line (it would sit in shell history). The
|
|
5262
5487
|
* file is said as every other file the CLI reads: "" names none, a folder is named, and an empty one is called that,
|
|
5263
|
-
* 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.
|
|
5264
5490
|
*/
|
|
5265
|
-
function backupPassphrase(file, missing = BACKUP_PASSPHRASE) {
|
|
5491
|
+
async function backupPassphrase(file, missing = BACKUP_PASSPHRASE) {
|
|
5266
5492
|
if (typeof file !== "string") {
|
|
5267
5493
|
const value = process.env.GHOSTLY_BACKUP_PASSPHRASE;
|
|
5268
5494
|
if (!value) throw new CliError("usage", missing);
|
|
5269
5495
|
return value;
|
|
5270
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");
|
|
5271
5498
|
let value;
|
|
5272
|
-
|
|
5499
|
+
if (file === "-") value = (await readStdin()).replace(/\r?\n$/, "");
|
|
5500
|
+
else try {
|
|
5273
5501
|
value = readFileSync(here(file), "utf8").replace(/\r?\n$/, "");
|
|
5274
5502
|
} catch (error) {
|
|
5275
5503
|
throw localFileError(error, file) ?? error;
|
|
5276
5504
|
}
|
|
5277
|
-
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`);
|
|
5278
5506
|
return value;
|
|
5279
5507
|
}
|
|
5280
5508
|
/** Set on `startDetached`'s child: its parent waits for the profile and starts it again, so the child does not wait too. */
|
|
@@ -5293,7 +5521,7 @@ async function runDaemon(g, seconds) {
|
|
|
5293
5521
|
const until = performance.now() + seconds * 1e3;
|
|
5294
5522
|
let host;
|
|
5295
5523
|
for (;;) {
|
|
5296
|
-
|
|
5524
|
+
await noDaemonAnswers(g, detached);
|
|
5297
5525
|
try {
|
|
5298
5526
|
host = await openHost(g.paths, "daemon", VERSION);
|
|
5299
5527
|
break;
|
|
@@ -5330,6 +5558,16 @@ async function runDaemon(g, seconds) {
|
|
|
5330
5558
|
});
|
|
5331
5559
|
}
|
|
5332
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
|
+
/**
|
|
5333
5571
|
* A detached child's answer carries its own pid (`child`): its parent reads it in `daemon.log`, where every daemon of
|
|
5334
5572
|
* the profile writes, and another detach's child that lost the profile, or refused to start, writes there too.
|
|
5335
5573
|
*/
|
|
@@ -5490,7 +5728,7 @@ async function stopDaemon(g, client, seconds) {
|
|
|
5490
5728
|
const refused = isNotTheDaemon(error);
|
|
5491
5729
|
if (!(error instanceof CliError && error.code === "timeout") && !refused) throw error;
|
|
5492
5730
|
const holder = lockOwner(g.paths);
|
|
5493
|
-
if (holder === null) throw error;
|
|
5731
|
+
if (holder === null) throw refused ? notTheDaemon(g.paths, false) : error;
|
|
5494
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`);
|
|
5495
5733
|
pid = holder;
|
|
5496
5734
|
answered = false;
|
|
@@ -5557,7 +5795,7 @@ async function startDetached(g, seconds) {
|
|
|
5557
5795
|
try {
|
|
5558
5796
|
const until = performance.now() + seconds * 1e3;
|
|
5559
5797
|
for (;;) {
|
|
5560
|
-
|
|
5798
|
+
await noDaemonAnswers(g);
|
|
5561
5799
|
if (lockOwner(g.paths) === null) {
|
|
5562
5800
|
const started = await spawnDaemon(g, until);
|
|
5563
5801
|
if (started) return started;
|
|
@@ -5760,6 +5998,10 @@ async function listenCommand(argv) {
|
|
|
5760
5998
|
turns,
|
|
5761
5999
|
translate: translator?.event,
|
|
5762
6000
|
exec: parsed.options.exec,
|
|
6001
|
+
profile: {
|
|
6002
|
+
home: g.home,
|
|
6003
|
+
name: g.profile
|
|
6004
|
+
},
|
|
5763
6005
|
webhook,
|
|
5764
6006
|
cursor,
|
|
5765
6007
|
cursorFailed,
|
|
@@ -5931,7 +6173,7 @@ async function engineCommand(argv) {
|
|
|
5931
6173
|
const { hideStateSecrets } = await engineApi();
|
|
5932
6174
|
result = hideStateSecrets(result);
|
|
5933
6175
|
}
|
|
5934
|
-
print(result);
|
|
6176
|
+
print(hideSecretFields(method, result, showSecret));
|
|
5935
6177
|
}
|
|
5936
6178
|
async function settingsCommand(sub, argv) {
|
|
5937
6179
|
const parsed = parseArgs(argv, {
|
|
@@ -5951,13 +6193,17 @@ async function settingsCommand(sub, argv) {
|
|
|
5951
6193
|
pretty = g.pretty;
|
|
5952
6194
|
if (sub === "get") {
|
|
5953
6195
|
noMoreThan(0, parsed.positionals, "settings get [--show-secret]");
|
|
5954
|
-
print(await withSession(g, (s) => s.call("settings.get", { showSecret: parsed.options["show-secret"] === true }), {
|
|
6196
|
+
print(await withSession(g, (s) => s.call("settings.get", { showSecret: parsed.options["show-secret"] === true }), {
|
|
6197
|
+
offline: true,
|
|
6198
|
+
deferChats: readsNoHistory("settings.get")
|
|
6199
|
+
}));
|
|
5955
6200
|
return;
|
|
5956
6201
|
}
|
|
5957
6202
|
if (sub === "set") {
|
|
5958
6203
|
const [key, given] = parsed.positionals;
|
|
5959
6204
|
if (!key) throw new CliError("usage", "Missing <key>: ghostly settings set <key> <json-value> [--force]");
|
|
5960
6205
|
noMoreThan(2, parsed.positionals, "settings set <key> <json-value> [--force]");
|
|
6206
|
+
const kind = key === "readRelays" ? void 0 : checkSettingKey(key, (await engineApi()).SETTABLE);
|
|
5961
6207
|
const { value, warning } = await settingValue(key, given, readStdin, process.stdin.isTTY === true, (note) => process.stderr.write(`ghostly: ${note}\n`));
|
|
5962
6208
|
if (warning) process.stderr.write(`ghostly: ${warning}\n`);
|
|
5963
6209
|
let parsedValue;
|
|
@@ -5966,7 +6212,8 @@ async function settingsCommand(sub, argv) {
|
|
|
5966
6212
|
} catch {
|
|
5967
6213
|
parsedValue = value;
|
|
5968
6214
|
}
|
|
5969
|
-
if (
|
|
6215
|
+
if (kind === "string" && typeof parsedValue !== "string") parsedValue = value;
|
|
6216
|
+
if (kind) checkSettingValue(key, kind, parsedValue, value);
|
|
5970
6217
|
const force = parsed.options.force === true ? { force: true } : {};
|
|
5971
6218
|
printAnswer(await withSession(g, (s) => s.call("settings.set", {
|
|
5972
6219
|
[key]: parsedValue,
|
|
@@ -5988,6 +6235,7 @@ async function textCommand(name, argv) {
|
|
|
5988
6235
|
const [message, ...words] = spec.message ? rest : [void 0, ...rest];
|
|
5989
6236
|
if (!target || spec.message && !message) throw new CliError("usage", `Missing <${target ? "message" : spec.target}>: ghostly ${spec.usage}`);
|
|
5990
6237
|
timeout(parsed.options);
|
|
6238
|
+
if (parsed.options.reply === "") throw new CliError("usage", "--reply needs a message id");
|
|
5991
6239
|
let text = words.join(" ");
|
|
5992
6240
|
if (parsed.options.text !== void 0) {
|
|
5993
6241
|
if (text || parsed.options.stdin) throw new CliError("usage", "Give the text once: as arguments, --text or stdin");
|
|
@@ -6005,14 +6253,14 @@ async function textCommand(name, argv) {
|
|
|
6005
6253
|
};
|
|
6006
6254
|
if (spec.target === "group") params.mentions = parsed.options.mention ?? [];
|
|
6007
6255
|
if (parsed.options.reply !== void 0) params.reply = parsed.options.reply;
|
|
6008
|
-
if (!spec.message) Object.assign(params, (await import("./buttons-
|
|
6256
|
+
if (!spec.message) Object.assign(params, (await import("./buttons-DK2aAGat.js")).buttonsOf(parsed.options));
|
|
6009
6257
|
print(await withSession(g, (s) => {
|
|
6010
6258
|
if (parsed.options.wait !== void 0) params.wait = parsed.options.wait;
|
|
6011
6259
|
if (parsed.options.timeout !== void 0) params.timeout = parsed.options.timeout;
|
|
6012
6260
|
return s.call(spec.method, params);
|
|
6013
6261
|
}, {
|
|
6014
6262
|
deferGroups: spec.target === "chat",
|
|
6015
|
-
deferChats: spec.target === "chat"
|
|
6263
|
+
deferChats: spec.target === "chat" || oneGroupOnly(spec.method)
|
|
6016
6264
|
}));
|
|
6017
6265
|
}
|
|
6018
6266
|
/**
|
|
@@ -6049,7 +6297,7 @@ async function identityAddCommand(argv) {
|
|
|
6049
6297
|
if (!provider) throw new CliError("usage", "Missing <provider>: ghostly identity add <provider> [subject] [--signer id] [--field name=value]... [--stdin] [--days n] [--timeout s]");
|
|
6050
6298
|
inRange(parsed.options, "timeout", "a number of seconds", 5, 3600);
|
|
6051
6299
|
const items = parsed.options.field ?? [];
|
|
6052
|
-
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;
|
|
6053
6301
|
if (known && parsed.options.days !== void 0) inRange(parsed.options, "days", "a whole number", 1, known.validity.maxDays, true);
|
|
6054
6302
|
const { fields, warning } = await identityFields(items, parsed.options.stdin === true, identitySecretFields(known, parsed.options.signer), readStdin, process.stdin.isTTY === true);
|
|
6055
6303
|
if (warning) process.stderr.write(`ghostly: ${warning}\n`);
|
|
@@ -6130,11 +6378,10 @@ async function tableCommand(name, argv) {
|
|
|
6130
6378
|
}
|
|
6131
6379
|
if (command.method === "x401.credential.add") {
|
|
6132
6380
|
try {
|
|
6133
|
-
params.credential = params.file === "-" ? await readStdin
|
|
6381
|
+
params.credential = params.file === "-" ? await credentialFromStdin(readStdin, process.stdin.isTTY === true) : readInput(params.file);
|
|
6134
6382
|
} catch (error) {
|
|
6135
6383
|
throw error instanceof CliError && error || localFileError(error, params.file) || new CliError("usage", `Cannot read the credential: ${error instanceof Error ? error.message : String(error)}`);
|
|
6136
6384
|
}
|
|
6137
|
-
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");
|
|
6138
6385
|
if (!params.credential) throw new CliError("bad_request", `${params.file} is empty: it holds the SD-JWT VC the issuer sent`);
|
|
6139
6386
|
delete params.file;
|
|
6140
6387
|
}
|
|
@@ -6155,12 +6402,12 @@ async function tableCommand(name, argv) {
|
|
|
6155
6402
|
return result;
|
|
6156
6403
|
}, {
|
|
6157
6404
|
deferGroups: chatOnly(command.method, params) || newChatOnly(command.method),
|
|
6158
|
-
deferChats: oneChatOnly(command.method, params),
|
|
6405
|
+
deferChats: oneChatOnly(command.method, params) || oneGroupOnly(command.method) || readsNoHistory(command.method),
|
|
6159
6406
|
offline: offlineCall(command.method, params)
|
|
6160
6407
|
});
|
|
6161
6408
|
if (translator) {
|
|
6162
6409
|
try {
|
|
6163
|
-
printAnswer(await (await import("./translate-
|
|
6410
|
+
printAnswer(await (await import("./translate-CUuC5szR.js")).translateAnswer(result, translator));
|
|
6164
6411
|
} finally {
|
|
6165
6412
|
translator.close();
|
|
6166
6413
|
}
|
|
@@ -6173,19 +6420,28 @@ async function tableCommand(name, argv) {
|
|
|
6173
6420
|
* contact's, raw PCM); what the command says goes to stderr. It ends when the call does.
|
|
6174
6421
|
*/
|
|
6175
6422
|
async function callPipeCommand(argv) {
|
|
6423
|
+
failures = process.stderr;
|
|
6176
6424
|
const parsed = parseArgs(argv, {}, idSlot({ args: ["call...?"] }), { command: "call pipe" });
|
|
6177
6425
|
const g = globals(parsed);
|
|
6178
6426
|
const ref = parsed.positionals.join(" ") || void 0;
|
|
6179
6427
|
const client = await connectDaemon(g.paths);
|
|
6180
6428
|
if (!client) throw new CliError("unavailable", `No daemon runs profile ${g.profile}: calls need one (ghostly daemon --detach)`);
|
|
6181
6429
|
let call;
|
|
6430
|
+
let reason = null, heard = null;
|
|
6182
6431
|
try {
|
|
6183
6432
|
call = await client.call("call.get", ref ? { call: ref } : {}, { timeoutMs: ANSWER_MS });
|
|
6184
|
-
|
|
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) {
|
|
6185
6441
|
client.close();
|
|
6442
|
+
throw error;
|
|
6186
6443
|
}
|
|
6187
6444
|
const audio = call.audio;
|
|
6188
|
-
if (!audio) throw new CliError("unavailable", "That call has no audio yet: answer it first");
|
|
6189
6445
|
const socket = connect(audio.socket);
|
|
6190
6446
|
await new Promise((resolve, reject) => {
|
|
6191
6447
|
socket.once("connect", resolve);
|
|
@@ -6194,13 +6450,30 @@ async function callPipeCommand(argv) {
|
|
|
6194
6450
|
socket.write(`${audio.token}\n`);
|
|
6195
6451
|
process.stderr.write(`ghostly: call ${call.call}: s16le mono ${audio.rate} Hz on stdin/stdout\n`);
|
|
6196
6452
|
process.stdin.pipe(socket, { end: false });
|
|
6453
|
+
let readerGone = false;
|
|
6197
6454
|
onReaderGone(() => {
|
|
6455
|
+
readerGone = true;
|
|
6198
6456
|
process.stderr.write(`ghostly: call ${call.call}: nothing reads its audio any more; the call goes on\n`);
|
|
6199
6457
|
socket.destroy();
|
|
6200
6458
|
});
|
|
6201
6459
|
socket.pipe(process.stdout);
|
|
6202
|
-
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
|
+
})());
|
|
6203
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
|
+
}
|
|
6204
6477
|
}
|
|
6205
6478
|
/**
|
|
6206
6479
|
* The command's words when the line asks for help (`help <words>`, or `--help`/`--help=true`/`-h` before any `--`), else
|
|
@@ -6380,11 +6653,11 @@ async function run(argv) {
|
|
|
6380
6653
|
if (code >= 0) exit(code);
|
|
6381
6654
|
} catch (error) {
|
|
6382
6655
|
const failure = asCliError(error);
|
|
6383
|
-
|
|
6656
|
+
failures.write(jsonOut({ error: failure.toJSON() }, pretty ? 2 : void 0) + "\n");
|
|
6384
6657
|
exit(EXIT[failure.code]);
|
|
6385
6658
|
}
|
|
6386
6659
|
}
|
|
6387
6660
|
//#endregion
|
|
6388
6661
|
export { run };
|
|
6389
6662
|
|
|
6390
|
-
//# sourceMappingURL=main-
|
|
6663
|
+
//# sourceMappingURL=main-C6t5zrD5.js.map
|