@ghostlytools/cli 1.6.1 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -12
- package/dist/assets/{api-BpNU2LQh.js → api-CD9JbPuA.js} +99 -28
- package/dist/assets/api-CD9JbPuA.js.map +1 -0
- package/dist/assets/{api-Cx8ZCntM.js → api-CJM3R93b.js} +2 -2
- package/dist/assets/{apiKit-d1wi3raD.js → apiKit-BmnROpCN.js} +8 -4
- package/dist/assets/{apiKit-d1wi3raD.js.map → apiKit-BmnROpCN.js.map} +1 -1
- package/dist/assets/{apps-C-HiIRCA.js → apps-CJ2dvKSz.js} +1 -1
- package/dist/assets/{apps-B1QjRWqq.js → apps-DVA60Tg6.js} +34 -11
- package/dist/assets/apps-DVA60Tg6.js.map +1 -0
- package/dist/assets/{arkade-B5g4r3Ea.js → arkade-CHqwEHFd.js} +2 -2
- package/dist/assets/{arkade-B5g4r3Ea.js.map → arkade-CHqwEHFd.js.map} +1 -1
- package/dist/assets/{backup-Boqn5Y35.js → backup-B4dSNvzb.js} +5 -5
- package/dist/assets/{backup-Boqn5Y35.js.map → backup-B4dSNvzb.js.map} +1 -1
- package/dist/assets/{backup-BS9HwGyn.js → backup-C4CbTEcj.js} +1 -1
- package/dist/assets/{blobFiles-B6nf0gCG.js → blobFiles-Bckz9fjp.js} +2 -2
- package/dist/assets/{blobFiles-B6nf0gCG.js.map → blobFiles-Bckz9fjp.js.map} +1 -1
- package/dist/assets/buttons-BMVGYXpR.js +2 -0
- package/dist/assets/{buttons-Bjc51aod.js → buttons-C13rK2mH.js} +3 -3
- package/dist/assets/{buttons-Bjc51aod.js.map → buttons-C13rK2mH.js.map} +1 -1
- package/dist/assets/{daemonProof-ui8jtIw0.js → daemonProof-B41oSfon.js} +2 -2
- package/dist/assets/{daemonProof-ui8jtIw0.js.map → daemonProof-B41oSfon.js.map} +1 -1
- package/dist/assets/{envelope-DvZMFRzg.js → envelope-4TXDx3vD.js} +2 -2
- package/dist/assets/{envelope-DvZMFRzg.js.map → envelope-4TXDx3vD.js.map} +1 -1
- package/dist/assets/{fileBytes-BMEBas7S.js → fileBytes-BD0v3rRG.js} +10 -2
- package/dist/assets/{fileBytes-BMEBas7S.js.map → fileBytes-BD0v3rRG.js.map} +1 -1
- package/dist/assets/{fileBytes-CtwagJ8h.js → fileBytes-OolN5cSY.js} +1 -1
- package/dist/assets/{fileBytes-CFNrRfcl.js → fileBytes-_fd-2JRY.js} +2 -2
- package/dist/assets/{fileBytes-CFNrRfcl.js.map → fileBytes-_fd-2JRY.js.map} +1 -1
- package/dist/assets/fileBytesIdb-CsSQcSxD.js +2 -0
- package/dist/assets/{fileBytesIdb-BXAN7i-N.js → fileBytesIdb-NtA8r9EM.js} +2 -2
- package/dist/assets/{fileBytesIdb-BXAN7i-N.js.map → fileBytesIdb-NtA8r9EM.js.map} +1 -1
- package/dist/assets/{fileBytesOpfs-Do1Vpkis.js → fileBytesOpfs-B8fJwkwM.js} +3 -3
- package/dist/assets/{fileBytesOpfs-Do1Vpkis.js.map → fileBytesOpfs-B8fJwkwM.js.map} +1 -1
- package/dist/assets/{ghostly_iroh_web-BXCsSxxo.js → ghostly_iroh_web-CO0onry8.js} +33 -27
- package/dist/assets/ghostly_iroh_web-CO0onry8.js.map +1 -0
- package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
- package/dist/assets/{groupFiles-y4lGrOC-.js → groupFiles-ajZgZ6P8.js} +41 -25
- package/dist/assets/groupFiles-ajZgZ6P8.js.map +1 -0
- package/dist/assets/{host-DFGS8vJE.js → host-CVeNtA2_.js} +43 -20
- package/dist/assets/host-CVeNtA2_.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CZLnOc4e.js → hyperdhtRelay-CI2ISE-g.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CZLnOc4e.js.map → hyperdhtRelay-CI2ISE-g.js.map} +1 -1
- package/dist/assets/{irohWeb-Y9wt8zG7.js → irohWeb-DcRJdhce.js} +3 -3
- package/dist/assets/{irohWeb-Y9wt8zG7.js.map → irohWeb-DcRJdhce.js.map} +1 -1
- package/dist/assets/{main-xgWC0qPZ.js → main-CjO0KGiF.js} +272 -79
- package/dist/assets/main-CjO0KGiF.js.map +1 -0
- package/dist/assets/{mainline-CjQ3pmvq.js → mainline-WM-WItCV.js} +27 -8
- package/dist/assets/mainline-WM-WItCV.js.map +1 -0
- package/dist/assets/{networkReason-i9wu5ZJs.js → networkReason-380j5yMs.js} +2 -2
- package/dist/assets/{networkReason-i9wu5ZJs.js.map → networkReason-380j5yMs.js.map} +1 -1
- package/dist/assets/{nwc-yO0nHt9S.js → nwc-D5dkC1xg.js} +3 -3
- package/dist/assets/{nwc-yO0nHt9S.js.map → nwc-D5dkC1xg.js.map} +1 -1
- package/dist/assets/{nwcProvider-BEg4I5Bk.js → nwcProvider-p_rMwtDv.js} +2 -2
- package/dist/assets/{nwcProvider-BEg4I5Bk.js.map → nwcProvider-p_rMwtDv.js.map} +1 -1
- package/dist/assets/{profiles-CEnZfN78.js → profiles-BFd0tpCZ.js} +91 -19
- package/dist/assets/profiles-BFd0tpCZ.js.map +1 -0
- package/dist/assets/{registry-CBDcdRPx.js → registry-BKffx4ZU.js} +1 -1
- package/dist/assets/{registry-DyGu5C-Z.js → registry-BfNcA6kF.js} +3 -3
- package/dist/assets/registry-BfNcA6kF.js.map +1 -0
- package/dist/assets/{resolve-CnkY--2E.js → resolve-hUsgRkmm.js} +2 -2
- package/dist/assets/{resolve-CnkY--2E.js.map → resolve-hUsgRkmm.js.map} +1 -1
- package/dist/assets/{server-CH142eWc.js → server-C3tJZFnv.js} +422 -149
- package/dist/assets/server-C3tJZFnv.js.map +1 -0
- package/dist/assets/{src-BXeGLwWV.js → src-BMHgbkli.js} +246 -62
- package/dist/assets/src-BMHgbkli.js.map +1 -0
- package/dist/assets/translate-DJUutSis.js +1067 -0
- package/dist/assets/translate-DJUutSis.js.map +1 -0
- package/dist/assets/types-C4_KafL_.js.map +1 -1
- package/dist/assets/{usdt-CdSNFUzO.js → usdt-glkUxsDe.js} +3 -3
- package/dist/assets/{usdt-CdSNFUzO.js.map → usdt-glkUxsDe.js.map} +1 -1
- package/dist/assets/{words-DA5feEav.js → words-DyW9b27T.js} +2 -2
- package/dist/assets/{words-DA5feEav.js.map → words-DyW9b27T.js.map} +1 -1
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-BpNU2LQh.js.map +0 -1
- package/dist/assets/apps-B1QjRWqq.js.map +0 -1
- package/dist/assets/buttons-CugVarw3.js +0 -2
- package/dist/assets/fileBytesIdb-C20oXDdr.js +0 -2
- package/dist/assets/ghostly_iroh_web-BXCsSxxo.js.map +0 -1
- package/dist/assets/groupFiles-y4lGrOC-.js.map +0 -1
- package/dist/assets/host-DFGS8vJE.js.map +0 -1
- package/dist/assets/main-xgWC0qPZ.js.map +0 -1
- package/dist/assets/mainline-CjQ3pmvq.js.map +0 -1
- package/dist/assets/profiles-CEnZfN78.js.map +0 -1
- package/dist/assets/registry-DyGu5C-Z.js.map +0 -1
- package/dist/assets/server-CH142eWc.js.map +0 -1
- package/dist/assets/src-BXeGLwWV.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Ga as ITEM_STATES, Ja as ROUTINE_STATES, Ka as PR_CHECKS, Wa as CRON_LINE, Wn as GROUP_FILE_LIMITS, Xa as STATUS_CARD_LIMITS, Ya as RUN_RESULTS, Za as TASK_STATUSES, da as VOICE_LIMITS, eo as cardLine, qa as PR_STATES, to as cardUrl } from "./src-
|
|
2
|
-
import { a as WALLET_TYPES, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, n as CHAT_METHODS, o as turnRef, p as SECRET_RESULTS, r as PAY_METHODS, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-
|
|
1
|
+
import { Ga as ITEM_STATES, Ja as ROUTINE_STATES, Ka as PR_CHECKS, Wa as CRON_LINE, Wn as GROUP_FILE_LIMITS, Xa as STATUS_CARD_LIMITS, Ya as RUN_RESULTS, Za as TASK_STATUSES, da as VOICE_LIMITS, eo as cardLine, io as statusCardBytes, qa as PR_STATES, to as cardUrl } from "./src-BMHgbkli.js";
|
|
2
|
+
import { a as WALLET_TYPES, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, n as CHAT_METHODS, o as turnRef, p as SECRET_RESULTS, r as PAY_METHODS, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-DyW9b27T.js";
|
|
3
3
|
import { i as localFileError, n as EXIT, r as asCliError, t as CliError } from "./errors-CzXgR8Cc.js";
|
|
4
|
-
import { t as CONTACT_KEY } from "./apiKit-
|
|
5
|
-
import { _ as ownSocket, a as checkShownName, c as ghostlyHome, f as profileExists, h as userPath, i as checkProfileName, l as listProfiles, m as selectProfile, o as createProfile, p as profilePaths, s as currentProfile, u as lockOwner } from "./profiles-
|
|
6
|
-
import { _ as isCallRate, a as newNonce, c as provesGreeting, d as CALL_RATES, l as readDaemonSecret, n as daemonOfThisRelease, s as provesDaemon, t as HELLO } from "./daemonProof-
|
|
4
|
+
import { p as namedByThem, t as CONTACT_KEY } from "./apiKit-BmnROpCN.js";
|
|
5
|
+
import { _ as ownSocket, a as checkShownName, c as ghostlyHome, f as profileExists, h as userPath, i as checkProfileName, l as listProfiles, m as selectProfile, o as createProfile, p as profilePaths, s as currentProfile, u as lockOwner } from "./profiles-BFd0tpCZ.js";
|
|
6
|
+
import { _ as isCallRate, a as newNonce, c as provesGreeting, d as CALL_RATES, l as readDaemonSecret, n as daemonOfThisRelease, s as provesDaemon, t as HELLO } from "./daemonProof-B41oSfon.js";
|
|
7
7
|
import { accessSync, closeSync, constants, existsSync, fstatSync, openSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { dirname, resolve } from "node:path";
|
|
9
9
|
import { spawn } from "node:child_process";
|
|
@@ -12,7 +12,7 @@ import { createInterface } from "node:readline";
|
|
|
12
12
|
import { format } from "node:util";
|
|
13
13
|
var package_default = {
|
|
14
14
|
name: "@ghostlytools/cli",
|
|
15
|
-
version: "1.
|
|
15
|
+
version: "1.7.1",
|
|
16
16
|
type: "module",
|
|
17
17
|
description: "Ghostly for bots and terminals: the app's own engine, headless on Node, behind a daemon and a `ghostly` command with JSON output.",
|
|
18
18
|
license: "MIT",
|
|
@@ -489,6 +489,11 @@ var groupWait = {
|
|
|
489
489
|
description: "Seconds to wait (default 30)"
|
|
490
490
|
}
|
|
491
491
|
};
|
|
492
|
+
/** `listen`, `events` and `chat history`: received messages with `translation: { from, text }` (translate.ts). */
|
|
493
|
+
var translate = {
|
|
494
|
+
type: "string",
|
|
495
|
+
description: "Add a translation into this language (en, pt...) to received messages, made on this machine by the translation runtime"
|
|
496
|
+
};
|
|
492
497
|
var net = {
|
|
493
498
|
type: "string",
|
|
494
499
|
choices: ["mainnet", "testnet"],
|
|
@@ -592,6 +597,32 @@ function typingFor(options) {
|
|
|
592
597
|
if (options.stop === true) throw new CliError("usage", "--for keeps it on: not with --stop");
|
|
593
598
|
return seconds;
|
|
594
599
|
}
|
|
600
|
+
/** The ranges the API takes (api.ts, files.ts): the most minutes of a `--hold` (a week, HOLD_MAX_MINUTES), seconds. */
|
|
601
|
+
var HOLD_MINUTES = 10080;
|
|
602
|
+
var WAIT_SECONDS = 3600;
|
|
603
|
+
var LONG_WAIT_SECONDS = 86400;
|
|
604
|
+
var HISTORY_LIMIT = 1e4;
|
|
605
|
+
/**
|
|
606
|
+
* A number flag out of the range the API takes: a usage error (exit 2) that names the flag, before the profile opens.
|
|
607
|
+
* Before, the API's own check answered once it had opened (a one-shot went online first), in its parameter's words
|
|
608
|
+
* ("hold must be a number from 0 to 10080", exit 1). The API keeps its check for socket callers.
|
|
609
|
+
*/
|
|
610
|
+
function inRange(options, flag, what, min, max, whole = false) {
|
|
611
|
+
const value = options[flag];
|
|
612
|
+
if (value === void 0) return void 0;
|
|
613
|
+
if (typeof value !== "number" || !(value >= min && value <= max) || whole && !Number.isInteger(value)) throw new CliError("usage", `--${flag} takes ${what} from ${min} to ${max}, not ${JSON.stringify(value)}`);
|
|
614
|
+
return value;
|
|
615
|
+
}
|
|
616
|
+
/** `--timeout` of a command that waits: seconds, up to an hour (a send, a card, a button) or a day (`chat wait`, a file). */
|
|
617
|
+
var timeout = (options, max = WAIT_SECONDS) => inRange(options, "timeout", "a number of seconds", 1, max);
|
|
618
|
+
/** `--limit` of a history: messages per page. */
|
|
619
|
+
var pageLimit = (options) => inRange(options, "limit", "a whole number", 1, HISTORY_LIMIT, true);
|
|
620
|
+
/** `--since` of `events` and `listen`: a seq, a whole number from 0 (a negative one replayed a made-up gap first). */
|
|
621
|
+
function since(options) {
|
|
622
|
+
const value = options.since;
|
|
623
|
+
if (value !== void 0 && !(Number.isSafeInteger(value) && value >= 0)) throw new CliError("usage", `--since takes a seq from 0 up, not ${JSON.stringify(value)}`);
|
|
624
|
+
return value;
|
|
625
|
+
}
|
|
595
626
|
/**
|
|
596
627
|
* A time given as digits: milliseconds. Unix seconds (from 1e9, 2001, up to 1e11, which as milliseconds would be 1970
|
|
597
628
|
* to 1973) are refused with the milliseconds they mean: before, they were read as January 1970 without a word.
|
|
@@ -712,6 +743,16 @@ function itemOf(value) {
|
|
|
712
743
|
text
|
|
713
744
|
};
|
|
714
745
|
}
|
|
746
|
+
/**
|
|
747
|
+
* A card's fields past the bytes a card takes in all (`STATUS_CARD_LIMITS.bytes`, its JSON as UTF-8): a usage error
|
|
748
|
+
* (exit 2) with its size and what to cut. Every flag can be within its own bound and the card not: 20 items of 200
|
|
749
|
+
* characters past Latin (3 bytes each) take 12 KiB. Before, it failed as `bad_request` (exit 1), the whole card in it.
|
|
750
|
+
*/
|
|
751
|
+
function cardBytes(fields, flags) {
|
|
752
|
+
const bytes = statusCardBytes(fields);
|
|
753
|
+
if (bytes > STATUS_CARD_LIMITS.bytes) throw new CliError("usage", `The card takes ${bytes} bytes, and holds at most ${STATUS_CARD_LIMITS.bytes} in all (a character past Latin takes 2 to 4): give shorter or fewer ${flags}`);
|
|
754
|
+
return fields;
|
|
755
|
+
}
|
|
715
756
|
/** `--progress`, `--left`: a percent, or a usage error that names the flag. */
|
|
716
757
|
function percent(options, flag) {
|
|
717
758
|
const value = options[flag];
|
|
@@ -783,7 +824,7 @@ function taskFields(options) {
|
|
|
783
824
|
set("parent", options.parent);
|
|
784
825
|
const links = cardLinks(options.link);
|
|
785
826
|
if (links) fields.links = links;
|
|
786
|
-
return fields;
|
|
827
|
+
return cardBytes(fields, "--item, --step, --link or --json");
|
|
787
828
|
}
|
|
788
829
|
/**
|
|
789
830
|
* The fields a new card cannot go without, given as a flag or in `--json`: a usage error (exit 2) that names the
|
|
@@ -855,7 +896,7 @@ function routineFields(options) {
|
|
|
855
896
|
if (next !== void 0) fields.nextRunAt = next;
|
|
856
897
|
const links = cardLinks(options.link);
|
|
857
898
|
if (links) fields.links = links;
|
|
858
|
-
return fields;
|
|
899
|
+
return cardBytes(fields, "--name, --schedule, --link or --json");
|
|
859
900
|
}
|
|
860
901
|
/** Options a routine command takes, beside `cardOptions`. */
|
|
861
902
|
var routineOptions = {
|
|
@@ -909,7 +950,7 @@ var taskOptions = {
|
|
|
909
950
|
},
|
|
910
951
|
item: {
|
|
911
952
|
type: "list",
|
|
912
|
-
description: "A step or log line, state:text with state pending, running, done, failed or skipped (text alone: pending). A lowercase word before the first colon must be one of them; pending:fix: x keeps the colon. The list replaces the card's (up to 20)"
|
|
953
|
+
description: "A step or log line, state:text with state pending, running, done, failed or skipped (text alone: pending). A lowercase word before the first colon must be one of them; pending:fix: x keeps the colon. The list replaces the card's (up to 20; the card holds at most 8 KiB in all, and a character past Latin takes 2 to 4 bytes)"
|
|
913
954
|
},
|
|
914
955
|
branch: {
|
|
915
956
|
type: "string",
|
|
@@ -992,7 +1033,7 @@ function usageFields(options) {
|
|
|
992
1033
|
const resets = cardTime(options.resets, "resets");
|
|
993
1034
|
if (resets !== void 0) fields.resetsAt = resets;
|
|
994
1035
|
if (Array.isArray(options.also) && options.also.length) fields.windows = options.also.map(usageWindowOf);
|
|
995
|
-
return fields;
|
|
1036
|
+
return cardBytes(fields, "--json");
|
|
996
1037
|
}
|
|
997
1038
|
/** Options `usage send` takes. */
|
|
998
1039
|
var usageOptions = {
|
|
@@ -1096,7 +1137,7 @@ var commands$8 = {
|
|
|
1096
1137
|
description: "Replace the three files when they are there"
|
|
1097
1138
|
}
|
|
1098
1139
|
},
|
|
1099
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1140
|
+
run: async ({ options }, a) => (await import("./apps-CJ2dvKSz.js")).initApp(a.dir, {
|
|
1100
1141
|
name: options.name,
|
|
1101
1142
|
title: options.title,
|
|
1102
1143
|
force: options.force === true
|
|
@@ -1136,7 +1177,7 @@ var commands$8 = {
|
|
|
1136
1177
|
description: "This version's sequence, higher than the bundle at --out's (default: one more than it)"
|
|
1137
1178
|
}
|
|
1138
1179
|
},
|
|
1139
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1180
|
+
run: async ({ options }, a) => (await import("./apps-CJ2dvKSz.js")).publishApp(a.dir, keyFile(options.key, "app publish <dir> --key <file> [--out <file>] [--sequence n]"), here(options.out), options.sequence)
|
|
1140
1181
|
},
|
|
1141
1182
|
"app revoke": {
|
|
1142
1183
|
method: "app.revoke",
|
|
@@ -1169,7 +1210,7 @@ var commands$8 = {
|
|
|
1169
1210
|
description: "Allow --up-to past the bundle's own sequence (versions published from elsewhere)"
|
|
1170
1211
|
}
|
|
1171
1212
|
},
|
|
1172
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1213
|
+
run: async ({ options }, a) => (await import("./apps-CJ2dvKSz.js")).revokeApp(a.dir, keyFile(options.key, "app revoke <dir> --key <file> (--digest <digest>... | --up-to <sequence>) [--reason <text>]"), {
|
|
1173
1214
|
digests: options.digest,
|
|
1174
1215
|
upTo: options["up-to"],
|
|
1175
1216
|
reason: options.reason,
|
|
@@ -1230,7 +1271,7 @@ var commands$8 = {
|
|
|
1230
1271
|
usage: "app verify <bundle|url>",
|
|
1231
1272
|
summary: "Check a .ghostlyapp as a client would, from a file or an https URL: its manifest and digest, or refused (exit 1) with the reason, revoked when the ghostly-revoke.json beside it revokes this version",
|
|
1232
1273
|
args: ["bundle"],
|
|
1233
|
-
run: async (_, a) => (await import("./apps-
|
|
1274
|
+
run: async (_, a) => (await import("./apps-CJ2dvKSz.js")).verifyApp(a.bundle)
|
|
1234
1275
|
},
|
|
1235
1276
|
"store sign": {
|
|
1236
1277
|
method: "store.sign",
|
|
@@ -1247,7 +1288,7 @@ var commands$8 = {
|
|
|
1247
1288
|
description: "The folder to write ghostly-store.json and ghostly-store.sig in (default: the index's)"
|
|
1248
1289
|
}
|
|
1249
1290
|
},
|
|
1250
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1291
|
+
run: async ({ options }, a) => (await import("./apps-CJ2dvKSz.js")).signStore(a.index, keyFile(options.key, "store sign <index> --key <file> [--out <dir>]"), here(options.out))
|
|
1251
1292
|
}
|
|
1252
1293
|
};
|
|
1253
1294
|
//#endregion
|
|
@@ -1360,7 +1401,7 @@ var commands$6 = {
|
|
|
1360
1401
|
message: a.message,
|
|
1361
1402
|
button: a.button,
|
|
1362
1403
|
wait: options.wait,
|
|
1363
|
-
timeout: options
|
|
1404
|
+
timeout: timeout(options)
|
|
1364
1405
|
})
|
|
1365
1406
|
},
|
|
1366
1407
|
"button update": {
|
|
@@ -1403,7 +1444,7 @@ var commands$6 = {
|
|
|
1403
1444
|
text: options.text,
|
|
1404
1445
|
force: options.force === true,
|
|
1405
1446
|
wait: options.wait,
|
|
1406
|
-
timeout: options
|
|
1447
|
+
timeout: timeout(options)
|
|
1407
1448
|
};
|
|
1408
1449
|
}
|
|
1409
1450
|
},
|
|
@@ -1425,12 +1466,12 @@ var commands$6 = {
|
|
|
1425
1466
|
} },
|
|
1426
1467
|
params: ({ options }, { chat }) => ({
|
|
1427
1468
|
chat,
|
|
1428
|
-
hold: options
|
|
1469
|
+
hold: inRange(options, "hold", "a number of minutes", 0, HOLD_MINUTES)
|
|
1429
1470
|
})
|
|
1430
1471
|
},
|
|
1431
1472
|
"chat history": {
|
|
1432
1473
|
method: "chat.history",
|
|
1433
|
-
usage: "chat history <chat> [--limit n] [--before id|ms] [--after id|ms]",
|
|
1474
|
+
usage: "chat history <chat> [--limit n] [--before id|ms] [--after id|ms] [--translate lang]",
|
|
1434
1475
|
summary: "Messages, oldest first (a page)",
|
|
1435
1476
|
args: ["chat"],
|
|
1436
1477
|
options: {
|
|
@@ -1445,11 +1486,12 @@ var commands$6 = {
|
|
|
1445
1486
|
after: {
|
|
1446
1487
|
type: "string",
|
|
1447
1488
|
description: "Only after this message id or timestamp"
|
|
1448
|
-
}
|
|
1489
|
+
},
|
|
1490
|
+
translate
|
|
1449
1491
|
},
|
|
1450
1492
|
params: ({ options }, { chat }) => ({
|
|
1451
1493
|
chat,
|
|
1452
|
-
limit: options
|
|
1494
|
+
limit: pageLimit(options),
|
|
1453
1495
|
before: cursor(options.before, "before"),
|
|
1454
1496
|
after: cursor(options.after, "after")
|
|
1455
1497
|
})
|
|
@@ -1547,7 +1589,7 @@ var commands$6 = {
|
|
|
1547
1589
|
params: ({ options }, { chat }) => ({
|
|
1548
1590
|
chat,
|
|
1549
1591
|
until: options.until,
|
|
1550
|
-
timeout: options
|
|
1592
|
+
timeout: timeout(options, LONG_WAIT_SECONDS)
|
|
1551
1593
|
})
|
|
1552
1594
|
},
|
|
1553
1595
|
"forward": {
|
|
@@ -1580,7 +1622,7 @@ var commands$6 = {
|
|
|
1580
1622
|
to: options.to,
|
|
1581
1623
|
force: options.force === true,
|
|
1582
1624
|
wait: options.wait,
|
|
1583
|
-
timeout: options
|
|
1625
|
+
timeout: timeout(options)
|
|
1584
1626
|
};
|
|
1585
1627
|
}
|
|
1586
1628
|
},
|
|
@@ -1703,7 +1745,7 @@ var commands$6 = {
|
|
|
1703
1745
|
text: options.text,
|
|
1704
1746
|
force: options.force === true,
|
|
1705
1747
|
wait: options.wait,
|
|
1706
|
-
timeout: options
|
|
1748
|
+
timeout: timeout(options)
|
|
1707
1749
|
})
|
|
1708
1750
|
},
|
|
1709
1751
|
"routine update": {
|
|
@@ -1732,7 +1774,7 @@ var commands$6 = {
|
|
|
1732
1774
|
text: options.text,
|
|
1733
1775
|
force: options.force === true,
|
|
1734
1776
|
wait: options.wait,
|
|
1735
|
-
timeout: options
|
|
1777
|
+
timeout: timeout(options)
|
|
1736
1778
|
})
|
|
1737
1779
|
},
|
|
1738
1780
|
"saved add": {
|
|
@@ -1780,7 +1822,7 @@ var commands$6 = {
|
|
|
1780
1822
|
text: options.text,
|
|
1781
1823
|
force: options.force === true,
|
|
1782
1824
|
wait: options.wait,
|
|
1783
|
-
timeout: options
|
|
1825
|
+
timeout: timeout(options)
|
|
1784
1826
|
})
|
|
1785
1827
|
},
|
|
1786
1828
|
"task update": {
|
|
@@ -1808,7 +1850,7 @@ var commands$6 = {
|
|
|
1808
1850
|
text: options.text,
|
|
1809
1851
|
force: options.force === true,
|
|
1810
1852
|
wait: options.wait,
|
|
1811
|
-
timeout: options
|
|
1853
|
+
timeout: timeout(options)
|
|
1812
1854
|
})
|
|
1813
1855
|
},
|
|
1814
1856
|
"typing": {
|
|
@@ -1860,7 +1902,7 @@ var commands$6 = {
|
|
|
1860
1902
|
text: options.text,
|
|
1861
1903
|
force: options.force === true,
|
|
1862
1904
|
wait: options.wait,
|
|
1863
|
-
timeout: options
|
|
1905
|
+
timeout: timeout(options)
|
|
1864
1906
|
};
|
|
1865
1907
|
}
|
|
1866
1908
|
}
|
|
@@ -1981,7 +2023,7 @@ var commands$5 = {
|
|
|
1981
2023
|
options: {
|
|
1982
2024
|
dir: {
|
|
1983
2025
|
type: "string",
|
|
1984
|
-
description: "Into this folder, under its own name"
|
|
2026
|
+
description: "Into this folder, under its own name (a voice message: the name Ghostly makes for it, \"(2)\" when taken)"
|
|
1985
2027
|
},
|
|
1986
2028
|
path: {
|
|
1987
2029
|
type: "string",
|
|
@@ -2012,7 +2054,7 @@ var commands$5 = {
|
|
|
2012
2054
|
path: here(options.path),
|
|
2013
2055
|
force: options.force === true,
|
|
2014
2056
|
wait: options.wait === true ? true : void 0,
|
|
2015
|
-
timeout: options
|
|
2057
|
+
timeout: timeout(options, LONG_WAIT_SECONDS)
|
|
2016
2058
|
};
|
|
2017
2059
|
}
|
|
2018
2060
|
},
|
|
@@ -2062,7 +2104,7 @@ var commands$5 = {
|
|
|
2062
2104
|
params: ({ options }, a) => ({
|
|
2063
2105
|
chat: a.chat,
|
|
2064
2106
|
file: a.file,
|
|
2065
|
-
timeout: options
|
|
2107
|
+
timeout: timeout(options, LONG_WAIT_SECONDS)
|
|
2066
2108
|
})
|
|
2067
2109
|
}
|
|
2068
2110
|
};
|
|
@@ -2072,13 +2114,16 @@ var commands$5 = {
|
|
|
2072
2114
|
var commands$4 = {
|
|
2073
2115
|
"events": {
|
|
2074
2116
|
method: "events.replay",
|
|
2075
|
-
usage: "events [--since seq]",
|
|
2117
|
+
usage: "events [--since seq] [--translate lang]",
|
|
2076
2118
|
summary: "Events the journal holds, without following",
|
|
2077
|
-
options: {
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2119
|
+
options: {
|
|
2120
|
+
since: {
|
|
2121
|
+
type: "number",
|
|
2122
|
+
description: "Only events after this seq"
|
|
2123
|
+
},
|
|
2124
|
+
translate
|
|
2125
|
+
},
|
|
2126
|
+
params: ({ options }) => ({ since: since(options) ?? 0 })
|
|
2082
2127
|
},
|
|
2083
2128
|
"profile picture": {
|
|
2084
2129
|
method: "profile.picture",
|
|
@@ -2183,7 +2228,7 @@ var commands$3 = {
|
|
|
2183
2228
|
},
|
|
2184
2229
|
params: ({ options }, { group }) => ({
|
|
2185
2230
|
group,
|
|
2186
|
-
limit: options
|
|
2231
|
+
limit: pageLimit(options),
|
|
2187
2232
|
before: cursor(options.before, "before"),
|
|
2188
2233
|
after: cursor(options.after, "after")
|
|
2189
2234
|
})
|
|
@@ -2536,9 +2581,9 @@ var commands$2 = {
|
|
|
2536
2581
|
var commands$1 = {
|
|
2537
2582
|
"chat accept": {
|
|
2538
2583
|
method: "chat.accept",
|
|
2539
|
-
usage: "chat accept <chat> <method> [--off] [--networks mainnet,testnet]",
|
|
2540
|
-
summary: "Which ways of paying a chat takes",
|
|
2541
|
-
args: ["chat", "method"],
|
|
2584
|
+
usage: "chat accept <chat> [<method> [--off] [--networks mainnet,testnet]]",
|
|
2585
|
+
summary: "Which ways of paying a chat takes (no method: the ones it takes now)",
|
|
2586
|
+
args: ["chat", "method?"],
|
|
2542
2587
|
words: { method: CHAT_METHODS },
|
|
2543
2588
|
options: {
|
|
2544
2589
|
off: {
|
|
@@ -2550,12 +2595,16 @@ var commands$1 = {
|
|
|
2550
2595
|
description: "Comma-separated networks it is taken on"
|
|
2551
2596
|
}
|
|
2552
2597
|
},
|
|
2553
|
-
params: ({ options }, a) =>
|
|
2554
|
-
|
|
2555
|
-
method: a.
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2598
|
+
params: ({ options }, a) => {
|
|
2599
|
+
if (a.method === void 0 && (options.off !== void 0 || options.networks !== void 0)) throw new CliError("usage", "--off and --networks change one method: ghostly chat accept <chat> <method> [--off] [--networks mainnet,testnet]");
|
|
2600
|
+
if (a.method === void 0) return { chat: a.chat };
|
|
2601
|
+
return {
|
|
2602
|
+
chat: a.chat,
|
|
2603
|
+
method: a.method,
|
|
2604
|
+
on: options.off !== true,
|
|
2605
|
+
networks: typeof options.networks === "string" ? options.networks.split(",").map((n) => n.trim()).filter(Boolean) : void 0
|
|
2606
|
+
};
|
|
2607
|
+
}
|
|
2559
2608
|
},
|
|
2560
2609
|
"chat pay": {
|
|
2561
2610
|
method: "chat.pay",
|
|
@@ -2811,7 +2860,7 @@ var commands$1 = {
|
|
|
2811
2860
|
},
|
|
2812
2861
|
params: ({ options }) => ({
|
|
2813
2862
|
network: options.network,
|
|
2814
|
-
limit: options
|
|
2863
|
+
limit: pageLimit(options)
|
|
2815
2864
|
})
|
|
2816
2865
|
},
|
|
2817
2866
|
"wallet list": {
|
|
@@ -3088,15 +3137,18 @@ var ID_ARGS = /* @__PURE__ */ new Set([
|
|
|
3088
3137
|
"service",
|
|
3089
3138
|
"call"
|
|
3090
3139
|
]);
|
|
3091
|
-
/**
|
|
3092
|
-
|
|
3140
|
+
/**
|
|
3141
|
+
* The positionals that may be left out ahead of a required one (`chat?` in `[<chat>] <file>`): left out, they shift the
|
|
3142
|
+
* others. One with no required one after it (`<chat> [<method>]`, `text...?`) is simply missing at the end: it shifts nothing.
|
|
3143
|
+
*/
|
|
3144
|
+
var leadingOptionals = (names) => names.filter((name, i) => name.endsWith("?") && !name.endsWith("...?") && names.slice(i + 1).some((after) => !after.endsWith("?")));
|
|
3093
3145
|
/**
|
|
3094
3146
|
* Which of a command's positionals take an id, by index (a trailing `...` one covers the rest). An optional `name?`
|
|
3095
3147
|
* shifts the others, so it counts only where it and what may come in its place are all ids.
|
|
3096
3148
|
*/
|
|
3097
3149
|
function idSlot(command) {
|
|
3098
3150
|
const names = (command.args ?? []).map((name) => name.replace(/\?$/, ""));
|
|
3099
|
-
const shift = (command.args ?? []).
|
|
3151
|
+
const shift = leadingOptionals(command.args ?? []).length;
|
|
3100
3152
|
const rest = names.findIndex((name) => name.endsWith("..."));
|
|
3101
3153
|
const at = (index) => {
|
|
3102
3154
|
const name = rest !== -1 && index >= rest ? names[rest].slice(0, -3) : names[index];
|
|
@@ -3127,11 +3179,11 @@ function usageNames(usage) {
|
|
|
3127
3179
|
*/
|
|
3128
3180
|
function positionals(command, values) {
|
|
3129
3181
|
let names = command.args ?? [];
|
|
3130
|
-
const optional = names
|
|
3182
|
+
const optional = leadingOptionals(names);
|
|
3131
3183
|
let skip = 0;
|
|
3132
3184
|
if (optional.length) {
|
|
3133
3185
|
skip = Math.max(0, optional.length - Math.max(0, values.length - (names.length - optional.length)));
|
|
3134
|
-
names = [...optional.slice(skip).map((name) => name.slice(0, -1)), ...names.filter((name) => !
|
|
3186
|
+
names = [...optional.slice(skip).map((name) => name.slice(0, -1)), ...names.filter((name) => !optional.includes(name))];
|
|
3135
3187
|
}
|
|
3136
3188
|
const shown = usageNames(command.usage);
|
|
3137
3189
|
const missing = (i, name) => new CliError("usage", `Missing <${shown[i + skip] ?? name}>: ghostly ${command.usage}`);
|
|
@@ -3144,6 +3196,7 @@ function positionals(command, values) {
|
|
|
3144
3196
|
out[name.slice(0, -3)] = rest.length ? rest.join(" ") : void 0;
|
|
3145
3197
|
return out;
|
|
3146
3198
|
}
|
|
3199
|
+
if (values[i] === void 0 && names[i].endsWith("?")) continue;
|
|
3147
3200
|
if (values[i] === void 0 || values[i] === "") throw missing(i, name);
|
|
3148
3201
|
const words = command.words?.[name];
|
|
3149
3202
|
if (words && !words.includes(values[i])) {
|
|
@@ -3205,13 +3258,25 @@ var Allowlist = class {
|
|
|
3205
3258
|
};
|
|
3206
3259
|
/**
|
|
3207
3260
|
* `--from` and `--group` as ids, resolved once at start: a contact key as that key (whatever any chat is named), else a
|
|
3208
|
-
* chat by id
|
|
3209
|
-
*
|
|
3261
|
+
* chat by its id or a label this side gave it, as `call auto on --from` (`findOwnNamedChat`): a prefix of its id or the
|
|
3262
|
+
* name its contact gave itself is refused, since another contact could call itself that; a group by id, prefix or name.
|
|
3263
|
+
* A name that later changes (or a contact who renames themselves) moves nothing.
|
|
3210
3264
|
*/
|
|
3211
3265
|
async function allowlist(from, groups, call, peerOf) {
|
|
3212
3266
|
const chats = /* @__PURE__ */ new Set(), keys = /* @__PURE__ */ new Set(), groupIds = /* @__PURE__ */ new Set();
|
|
3213
|
-
for (const ref of from)
|
|
3214
|
-
|
|
3267
|
+
for (const ref of from) {
|
|
3268
|
+
if (CONTACT_KEY.test(ref)) {
|
|
3269
|
+
keys.add(ref);
|
|
3270
|
+
continue;
|
|
3271
|
+
}
|
|
3272
|
+
const chat = await call("chat.get", { chat: ref });
|
|
3273
|
+
if (chat.id !== ref && chat.label?.toLowerCase() !== ref.toLowerCase()) throw namedByThem(ref, {
|
|
3274
|
+
chat: chat.id,
|
|
3275
|
+
name: chat.peerName ?? null,
|
|
3276
|
+
contact: chat.peer
|
|
3277
|
+
});
|
|
3278
|
+
chats.add(chat.id);
|
|
3279
|
+
}
|
|
3215
3280
|
for (const ref of groups) groupIds.add((await call("group.get", { group: ref })).id);
|
|
3216
3281
|
return new Allowlist(chats, keys, groupIds, peerOf);
|
|
3217
3282
|
}
|
|
@@ -3257,6 +3322,10 @@ function turn(event, source, where, message) {
|
|
|
3257
3322
|
size: file.size,
|
|
3258
3323
|
mime: file.mime,
|
|
3259
3324
|
voice: !!file.voice
|
|
3325
|
+
} } : {},
|
|
3326
|
+
...message.translation ? { translation: {
|
|
3327
|
+
from: message.translation.from,
|
|
3328
|
+
text: message.translation.text
|
|
3260
3329
|
} } : {}
|
|
3261
3330
|
}
|
|
3262
3331
|
};
|
|
@@ -3482,6 +3551,8 @@ function eventHandler(options) {
|
|
|
3482
3551
|
let chain = Promise.resolve();
|
|
3483
3552
|
let behind = 0;
|
|
3484
3553
|
let stopped = false;
|
|
3554
|
+
/** The last event the cursor says, and the last one `--type` dropped while others were still being handled. */
|
|
3555
|
+
let kept = -1, dropped = -1;
|
|
3485
3556
|
const keep = (seq) => {
|
|
3486
3557
|
if (!options.cursor) return;
|
|
3487
3558
|
try {
|
|
@@ -3489,16 +3560,34 @@ function eventHandler(options) {
|
|
|
3489
3560
|
} catch (error) {
|
|
3490
3561
|
throw new CursorError(error);
|
|
3491
3562
|
}
|
|
3563
|
+
kept = Math.max(kept, seq);
|
|
3564
|
+
};
|
|
3565
|
+
/** The cursor past events dropped meanwhile, once nothing before them is left to handle. */
|
|
3566
|
+
const keepDropped = () => {
|
|
3567
|
+
if (behind > 0 || dropped <= kept) return;
|
|
3568
|
+
try {
|
|
3569
|
+
keep(dropped);
|
|
3570
|
+
} catch (failed) {
|
|
3571
|
+
if (!(failed instanceof CursorError) || !options.cursorFailed) return;
|
|
3572
|
+
stopped = true;
|
|
3573
|
+
options.cursorFailed(failed.error);
|
|
3574
|
+
}
|
|
3492
3575
|
};
|
|
3493
3576
|
const handle = (event) => {
|
|
3494
3577
|
const seq = event.seq, type = event.type;
|
|
3495
3578
|
if (stopped) return;
|
|
3579
|
+
if (!matches(event, options.types)) {
|
|
3580
|
+
dropped = Math.max(dropped, seq);
|
|
3581
|
+
keepDropped();
|
|
3582
|
+
return;
|
|
3583
|
+
}
|
|
3496
3584
|
behind++;
|
|
3497
3585
|
chain = chain.then(async () => {
|
|
3498
3586
|
if (stopped) return;
|
|
3499
3587
|
const skip = () => keep(event.seq);
|
|
3500
3588
|
if (!matches(event, options.types)) return skip();
|
|
3501
3589
|
if (options.allow && !await options.allow.allows(event)) return skip();
|
|
3590
|
+
if (options.translate) event = await options.translate(event);
|
|
3502
3591
|
if (options.turns) {
|
|
3503
3592
|
const next = toTurn(event);
|
|
3504
3593
|
if (!next) return skip();
|
|
@@ -3526,6 +3615,7 @@ function eventHandler(options) {
|
|
|
3526
3615
|
}
|
|
3527
3616
|
}).finally(() => {
|
|
3528
3617
|
behind--;
|
|
3618
|
+
keepDropped();
|
|
3529
3619
|
});
|
|
3530
3620
|
};
|
|
3531
3621
|
return Object.assign(handle, {
|
|
@@ -3765,8 +3855,22 @@ var VERSION = package_default.version;
|
|
|
3765
3855
|
* command a running daemon answers loads none of them, and starts about as fast as Node does. Statically imported, they
|
|
3766
3856
|
* cost every command ~100 ms before its socket was opened.
|
|
3767
3857
|
*/
|
|
3768
|
-
var engineApi = () => import("./api-
|
|
3769
|
-
var engineHost = () => import("./host-
|
|
3858
|
+
var engineApi = () => import("./api-CJM3R93b.js");
|
|
3859
|
+
var engineHost = () => import("./host-CVeNtA2_.js");
|
|
3860
|
+
/**
|
|
3861
|
+
* `--translate <lang>`'s translator, or null (not asked; or the runtime is not there, said on stderr). Loaded only when
|
|
3862
|
+
* asked: the app's message parser it reads costs every other command nothing.
|
|
3863
|
+
*/
|
|
3864
|
+
async function translatorFor(value, home) {
|
|
3865
|
+
if (value === void 0) return null;
|
|
3866
|
+
const { loadDetector, openTranslator, translateTarget } = await import("./translate-DJUutSis.js");
|
|
3867
|
+
return openTranslator({
|
|
3868
|
+
home,
|
|
3869
|
+
to: translateTarget(value),
|
|
3870
|
+
detect: await loadDetector(),
|
|
3871
|
+
warn: (line) => process.stderr.write(line + "\n")
|
|
3872
|
+
});
|
|
3873
|
+
}
|
|
3770
3874
|
var pretty = false;
|
|
3771
3875
|
function print(value) {
|
|
3772
3876
|
process.stdout.write(JSON.stringify(value, null, pretty ? 2 : void 0) + "\n");
|
|
@@ -3805,10 +3909,45 @@ function noProfile(g) {
|
|
|
3805
3909
|
function knownProfile(g) {
|
|
3806
3910
|
if (g.profile !== "default" && !profileExists(g.home, g.profile)) throw noProfile(g);
|
|
3807
3911
|
}
|
|
3808
|
-
/**
|
|
3912
|
+
/** `1.2.3`, with an optional `v`, an optional `-beta.1` prerelease and an optional `+build` that never orders. */
|
|
3913
|
+
var RELEASE = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
3914
|
+
/** Semver order: negative when `a` is the older release, positive when it is the newer, 0 the same; null when either is not one. */
|
|
3915
|
+
function compareReleases(a, b) {
|
|
3916
|
+
const left = RELEASE.exec(a.trim()), right = RELEASE.exec(b.trim());
|
|
3917
|
+
if (!left || !right) return null;
|
|
3918
|
+
for (let i = 1; i <= 3; i++) {
|
|
3919
|
+
const order = Number(left[i]) - Number(right[i]);
|
|
3920
|
+
if (order !== 0) return order;
|
|
3921
|
+
}
|
|
3922
|
+
if (left[4] === void 0 || right[4] === void 0) return (left[4] === void 0 ? 1 : 0) - (right[4] === void 0 ? 1 : 0);
|
|
3923
|
+
const l = left[4].split("."), r = right[4].split(".");
|
|
3924
|
+
for (let i = 0; i < Math.min(l.length, r.length); i++) {
|
|
3925
|
+
if (l[i] === r[i]) continue;
|
|
3926
|
+
const ln = /^\d+$/.test(l[i]), rn = /^\d+$/.test(r[i]);
|
|
3927
|
+
if (ln && rn) return Number(l[i]) - Number(r[i]);
|
|
3928
|
+
if (ln !== rn) return ln ? -1 : 1;
|
|
3929
|
+
return l[i] < r[i] ? -1 : 1;
|
|
3930
|
+
}
|
|
3931
|
+
return l.length - r.length;
|
|
3932
|
+
}
|
|
3933
|
+
/**
|
|
3934
|
+
* Said on stderr when the daemon runs another release than this command. An older daemon started before an upgrade:
|
|
3935
|
+
* `daemon restart` runs this release. A newer one means this command is the old one (a second install, a project's
|
|
3936
|
+
* pinned copy): a restart from it would start the older release, so it is told to upgrade instead.
|
|
3937
|
+
*/
|
|
3809
3938
|
function versionWarning(daemon, cli) {
|
|
3810
3939
|
if (typeof daemon !== "string" || daemon === cli) return null;
|
|
3811
|
-
|
|
3940
|
+
const order = compareReleases(daemon, cli);
|
|
3941
|
+
if (order === 0) return null;
|
|
3942
|
+
const both = `ghostly: the daemon runs ${daemon} and this command is ${cli}`;
|
|
3943
|
+
if (order === null) return `${both}: \`ghostly daemon restart\` runs this command's release`;
|
|
3944
|
+
if (order > 0) return `${both}, older than the daemon: upgrade the CLI (\`npm install -g @ghostlytools/cli\`)`;
|
|
3945
|
+
return `${both}: \`ghostly daemon restart\` runs the new code`;
|
|
3946
|
+
}
|
|
3947
|
+
/** Said on stderr when `daemon restart` stopped a newer release than the one it started (an older CLI ran it). */
|
|
3948
|
+
function restartWarning(before, version) {
|
|
3949
|
+
if (typeof before !== "string" || !((compareReleases(before, version) ?? 0) > 0)) return null;
|
|
3950
|
+
return `ghostly: the daemon ran ${before} and this restart started ${version}, an older release: upgrade the CLI (\`npm install -g @ghostlytools/cli\`) and run \`ghostly daemon restart\` again to go back`;
|
|
3812
3951
|
}
|
|
3813
3952
|
/**
|
|
3814
3953
|
* Never fails, and has no deadline of its own: a daemon that does not answer is the command's own call to find out,
|
|
@@ -3843,6 +3982,15 @@ function chatOnly(method, params) {
|
|
|
3843
3982
|
return method.startsWith("chat.") || params.chat !== void 0 && params.group === void 0 && !method.startsWith("group.");
|
|
3844
3983
|
}
|
|
3845
3984
|
/**
|
|
3985
|
+
* A command that makes a new chat and needs no other: a one-shot for it leaves the saved chats and the groups unstarted.
|
|
3986
|
+
* Started, each saved chat put its records and its leave packet on the relays: from about ten that was the relays' 30
|
|
3987
|
+
* requests a minute, and the new chat's waited behind them. A new invite took 21 s instead of under one, unpublished;
|
|
3988
|
+
* a join waited its whole 60 s and left unpaired. A join of a saved chat starts that chat (the engine's `joinLink`).
|
|
3989
|
+
*/
|
|
3990
|
+
function newChatOnly(method) {
|
|
3991
|
+
return method === "invite.create" || method === "invite.join";
|
|
3992
|
+
}
|
|
3993
|
+
/**
|
|
3846
3994
|
* Calls that only read what the profile stores: a one-shot for one opens it offline (`RuntimeOptions.offline`).
|
|
3847
3995
|
* Opened online, `status` or `chat list` started every chat, put the profile's records on the relays again and waited
|
|
3848
3996
|
* for its leave packet to be taken: 0.25 s became 3.3 s with a relay that takes 1.5 s, and 10 s with one that does not
|
|
@@ -3878,6 +4026,7 @@ var READS = /* @__PURE__ */ new Set([
|
|
|
3878
4026
|
function readOnly(method, params) {
|
|
3879
4027
|
if (method === "engine.call") return typeof params.method === "string" && ENGINE_READS.includes(params.method);
|
|
3880
4028
|
if (method === "call.auto") return params.on === void 0;
|
|
4029
|
+
if (method === "chat.accept") return params.method === void 0;
|
|
3881
4030
|
return READS.has(method);
|
|
3882
4031
|
}
|
|
3883
4032
|
/**
|
|
@@ -3950,17 +4099,40 @@ async function session(g, options) {
|
|
|
3950
4099
|
}
|
|
3951
4100
|
};
|
|
3952
4101
|
}
|
|
3953
|
-
const [
|
|
3954
|
-
const host = await
|
|
4102
|
+
const [, { callApi }] = await Promise.all([engineHost(), engineApi()]);
|
|
4103
|
+
const host = await openOneShot(g, options);
|
|
3955
4104
|
return {
|
|
3956
4105
|
mode: "one-shot",
|
|
3957
4106
|
call: (m, p) => callApi(host.ctx, m, p ?? {}),
|
|
3958
4107
|
close: () => host.close()
|
|
3959
4108
|
};
|
|
3960
4109
|
}
|
|
4110
|
+
/** How long a one-shot waits for another process to let go of the profile: a one-shot leaves in well under a second. */
|
|
4111
|
+
var HOLDER_WAIT_MS = 5e3;
|
|
4112
|
+
/**
|
|
4113
|
+
* Opens the profile in this process for a one-shot command. Another one that holds it (a script's `&`, a second
|
|
4114
|
+
* terminal) is waited for: both used to fail at once, and a backgrounded send was lost unless the script checked its
|
|
4115
|
+
* exit code. One still holding it after HOLDER_WAIT_MS is answered with the next step.
|
|
4116
|
+
*/
|
|
4117
|
+
async function openOneShot(g, options = {}) {
|
|
4118
|
+
const { openHost } = await engineHost();
|
|
4119
|
+
const until = Date.now() + HOLDER_WAIT_MS;
|
|
4120
|
+
for (;;) try {
|
|
4121
|
+
return await openHost(g.paths, "one-shot", VERSION, options);
|
|
4122
|
+
} catch (error) {
|
|
4123
|
+
if (!(error instanceof CliError) || error.code !== "busy") throw error;
|
|
4124
|
+
const left = until - Date.now();
|
|
4125
|
+
if (left <= 0) {
|
|
4126
|
+
const pid = error.details?.pid;
|
|
4127
|
+
throw new CliError("busy", `Profile ${g.profile} is in use by ${pid ? `process ${pid}, another ghostly command,` : "another ghostly command"} and was not free after ${HOLDER_WAIT_MS / 1e3} s: run the commands one after another, or start \`ghostly daemon --detach\` so they can run at once`, error.details);
|
|
4128
|
+
}
|
|
4129
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(50 + Math.random() * 50, left)));
|
|
4130
|
+
}
|
|
4131
|
+
}
|
|
3961
4132
|
/**
|
|
3962
4133
|
* How a one-shot opens the profile: `deferGroups` when the command is about one 1:1 chat (`chatOnly`) and needs
|
|
3963
|
-
* nothing of the groups, `
|
|
4134
|
+
* nothing of the groups, `deferChats` too when it makes a new chat (`newChatOnly`), `offline` when it only reads or
|
|
4135
|
+
* changes only this device (`offlineCall`).
|
|
3964
4136
|
*/
|
|
3965
4137
|
async function withSession(g, work, options = {}) {
|
|
3966
4138
|
const s = await session(g, options);
|
|
@@ -4079,7 +4251,7 @@ var SPECIAL = [
|
|
|
4079
4251
|
{ timeout: o("number", "Seconds to wait for each step") }
|
|
4080
4252
|
],
|
|
4081
4253
|
[
|
|
4082
|
-
"listen [--since seq] [--cursor file] [--type t]... [--turns] [--from <chat|key>]... [--group <group>]... [--exec cmd] [--webhook url] [--print]",
|
|
4254
|
+
"listen [--since seq] [--cursor file] [--type t]... [--turns] [--from <chat|key>]... [--group <group>]... [--exec cmd] [--webhook url] [--print] [--translate lang]",
|
|
4083
4255
|
"Stream events as JSON lines (starts the profile here if no daemon runs it)",
|
|
4084
4256
|
{
|
|
4085
4257
|
since: o("number", "Replay events after this seq first"),
|
|
@@ -4090,7 +4262,8 @@ var SPECIAL = [
|
|
|
4090
4262
|
group: o("list", "Only this group's events (again for more); with --from or --group, nobody else's event gets through"),
|
|
4091
4263
|
exec: o("string", "Run this command per event, the event as JSON on stdin"),
|
|
4092
4264
|
webhook: o("string", "POST each event to this URL"),
|
|
4093
|
-
print: o("boolean", "Print events too when --exec or --webhook handles them")
|
|
4265
|
+
print: o("boolean", "Print events too when --exec or --webhook handles them"),
|
|
4266
|
+
translate
|
|
4094
4267
|
}
|
|
4095
4268
|
],
|
|
4096
4269
|
[
|
|
@@ -4098,7 +4271,7 @@ var SPECIAL = [
|
|
|
4098
4271
|
"The profile's settings",
|
|
4099
4272
|
{ "show-secret": o("boolean", "Show credentials too") }
|
|
4100
4273
|
],
|
|
4101
|
-
["settings set <key> <json-value>", "Change one: relays, irohRelays, hyperdhtRelay,
|
|
4274
|
+
["settings set <key> <json-value>", "Change one: relays, irohRelays, hyperdhtRelay, iceServers, publicProfiles, online, shareProfile, sendTyping, autoDownloads, serveFiles, nick"],
|
|
4102
4275
|
[
|
|
4103
4276
|
"engine <method> [json-params | -] [--confirm-real] [--show-secret] [--yes] [--force]",
|
|
4104
4277
|
"Any call of the app's engine, with its own parameters (engine --list --verbose names them)",
|
|
@@ -4381,7 +4554,7 @@ async function profileCommand(sub, argv) {
|
|
|
4381
4554
|
if (!given || !name) throw new CliError("usage", "ghostly profile restore <file> <new profile> [--passphrase-file f] [--use]");
|
|
4382
4555
|
noMoreThan(2, parsed.positionals, "profile restore <file> <new profile> [--passphrase-file f] [--use]");
|
|
4383
4556
|
const file = here(given);
|
|
4384
|
-
const { backupFileProtection, restoreProfile } = await import("./backup-
|
|
4557
|
+
const { backupFileProtection, restoreProfile } = await import("./backup-C4CbTEcj.js");
|
|
4385
4558
|
const protection = await backupFileProtection(file);
|
|
4386
4559
|
const paths = await restoreProfile(g.home, checkProfileName(name), file, protection === "none" ? void 0 : backupPassphrase(parsed.options["passphrase-file"], RESTORE_PASSPHRASE));
|
|
4387
4560
|
if (parsed.options.use) selectProfile(g.home, name);
|
|
@@ -4541,6 +4714,8 @@ async function daemonCommand(argv) {
|
|
|
4541
4714
|
stopped
|
|
4542
4715
|
});
|
|
4543
4716
|
}
|
|
4717
|
+
const older = restartWarning(before, VERSION);
|
|
4718
|
+
if (older) process.stderr.write(older + "\n");
|
|
4544
4719
|
print({
|
|
4545
4720
|
restarted: true,
|
|
4546
4721
|
stopped,
|
|
@@ -4769,6 +4944,10 @@ async function listenCommand(argv) {
|
|
|
4769
4944
|
turns: {
|
|
4770
4945
|
type: "boolean",
|
|
4771
4946
|
description: ""
|
|
4947
|
+
},
|
|
4948
|
+
translate: {
|
|
4949
|
+
type: "string",
|
|
4950
|
+
description: ""
|
|
4772
4951
|
}
|
|
4773
4952
|
});
|
|
4774
4953
|
noMoreThan(0, parsed.positionals, SPECIAL.find(([usage]) => usage.startsWith("listen "))[0]);
|
|
@@ -4788,7 +4967,8 @@ async function listenCommand(argv) {
|
|
|
4788
4967
|
const from = parsed.options.from ?? [], groups = parsed.options.group ?? [];
|
|
4789
4968
|
const cursor = here(parsed.options.cursor);
|
|
4790
4969
|
checkCursor(cursor);
|
|
4791
|
-
const since = parsed.options
|
|
4970
|
+
const since$1 = since(parsed.options) ?? readCursor(cursor);
|
|
4971
|
+
const translator = await translatorFor(parsed.options.translate, g.home);
|
|
4792
4972
|
let quit = (code) => {
|
|
4793
4973
|
process.exit(code);
|
|
4794
4974
|
};
|
|
@@ -4802,6 +4982,7 @@ async function listenCommand(argv) {
|
|
|
4802
4982
|
return eventHandler({
|
|
4803
4983
|
types,
|
|
4804
4984
|
turns,
|
|
4985
|
+
translate: translator?.event,
|
|
4805
4986
|
exec: parsed.options.exec,
|
|
4806
4987
|
webhook: parsed.options.webhook,
|
|
4807
4988
|
cursor,
|
|
@@ -4836,7 +5017,7 @@ async function listenCommand(argv) {
|
|
|
4836
5017
|
client.close();
|
|
4837
5018
|
throw error;
|
|
4838
5019
|
});
|
|
4839
|
-
const following = followDaemon(g.paths, client, handle, since, PAUSE_HOLD_MS, g.profile);
|
|
5020
|
+
const following = followDaemon(g.paths, client, handle, since$1, PAUSE_HOLD_MS, g.profile);
|
|
4840
5021
|
const stop = () => {
|
|
4841
5022
|
following.close();
|
|
4842
5023
|
process.exit(0);
|
|
@@ -4891,11 +5072,11 @@ async function listenCommand(argv) {
|
|
|
4891
5072
|
}
|
|
4892
5073
|
off = host.ctx.hub.onEvent(feed.take);
|
|
4893
5074
|
};
|
|
4894
|
-
const feed = new Feed(handle, since, () => {
|
|
5075
|
+
const feed = new Feed(handle, since$1, () => {
|
|
4895
5076
|
off?.();
|
|
4896
5077
|
off = null;
|
|
4897
5078
|
}, open);
|
|
4898
|
-
open(since);
|
|
5079
|
+
open(since$1);
|
|
4899
5080
|
host.ctx.hub.emit("daemon.started", `daemon.started:${process.pid}:${Date.now()}`, {
|
|
4900
5081
|
pid: process.pid,
|
|
4901
5082
|
version: VERSION,
|
|
@@ -5003,6 +5184,7 @@ async function textCommand(name, argv) {
|
|
|
5003
5184
|
const [target, ...rest] = parsed.positionals;
|
|
5004
5185
|
const [message, ...words] = spec.message ? rest : [void 0, ...rest];
|
|
5005
5186
|
if (!target || spec.message && !message) throw new CliError("usage", `ghostly ${spec.usage}`);
|
|
5187
|
+
timeout(parsed.options);
|
|
5006
5188
|
let text = words.join(" ");
|
|
5007
5189
|
if (parsed.options.text !== void 0) {
|
|
5008
5190
|
if (text || parsed.options.stdin) throw new CliError("usage", "Give the text once: as arguments, --text or stdin");
|
|
@@ -5020,7 +5202,7 @@ async function textCommand(name, argv) {
|
|
|
5020
5202
|
};
|
|
5021
5203
|
if (spec.target === "group") params.mentions = parsed.options.mention ?? [];
|
|
5022
5204
|
if (parsed.options.reply !== void 0) params.reply = parsed.options.reply;
|
|
5023
|
-
if (!spec.message) Object.assign(params, (await import("./buttons-
|
|
5205
|
+
if (!spec.message) Object.assign(params, (await import("./buttons-BMVGYXpR.js")).buttonsOf(parsed.options));
|
|
5024
5206
|
print(await withSession(g, (s) => {
|
|
5025
5207
|
if (spec.target === "chat") {
|
|
5026
5208
|
params.wait = parsed.options.wait ?? (s.mode === "one-shot" ? spec.message ? "confirmed" : "sent" : "none");
|
|
@@ -5091,8 +5273,8 @@ async function identityAddCommand(argv) {
|
|
|
5091
5273
|
}
|
|
5092
5274
|
return;
|
|
5093
5275
|
}
|
|
5094
|
-
const [
|
|
5095
|
-
const host = await
|
|
5276
|
+
const [, { callApi }] = await Promise.all([engineHost(), engineApi()]);
|
|
5277
|
+
const host = await openOneShot(g);
|
|
5096
5278
|
const off = host.ctx.hub.onEvent(tell);
|
|
5097
5279
|
try {
|
|
5098
5280
|
const result = await callApi(host.ctx, "identity.add", params);
|
|
@@ -5118,6 +5300,7 @@ async function tableCommand(name, argv) {
|
|
|
5118
5300
|
}
|
|
5119
5301
|
const params = command.params?.(parsed, args) ?? {};
|
|
5120
5302
|
for (const key of Object.keys(params)) if (params[key] === void 0) delete params[key];
|
|
5303
|
+
const translator = await translatorFor(parsed.options.translate, g.home);
|
|
5121
5304
|
if (command.method === "identity.complete") {
|
|
5122
5305
|
if (params.evidenceFile) try {
|
|
5123
5306
|
params.evidence = readFileSync(params.evidenceFile, "utf8");
|
|
@@ -5140,7 +5323,7 @@ async function tableCommand(name, argv) {
|
|
|
5140
5323
|
const lineValues = command.method === "wallet.create" ? Object.keys(params.values ?? {}) : [];
|
|
5141
5324
|
const secretWarning = await secretsFromStdin(command.method, params, readStdin, process.stdin.isTTY === true, (note) => process.stderr.write(`ghostly: ${note}\n`));
|
|
5142
5325
|
if (secretWarning) process.stderr.write(`ghostly: ${secretWarning}\n`);
|
|
5143
|
-
|
|
5326
|
+
const result = await withSession(g, async (s) => {
|
|
5144
5327
|
if (lineValues.length) {
|
|
5145
5328
|
const warning = secretValuesWarning(await s.call("wallet.list", { network: params.network ?? "testnet" }).catch(() => void 0), params.type, params.provider, lineValues);
|
|
5146
5329
|
if (warning) process.stderr.write(`ghostly: ${warning}\n`);
|
|
@@ -5153,9 +5336,19 @@ async function tableCommand(name, argv) {
|
|
|
5153
5336
|
}
|
|
5154
5337
|
return result;
|
|
5155
5338
|
}, {
|
|
5156
|
-
deferGroups: chatOnly(command.method, params),
|
|
5339
|
+
deferGroups: chatOnly(command.method, params) || newChatOnly(command.method),
|
|
5340
|
+
deferChats: newChatOnly(command.method),
|
|
5157
5341
|
offline: offlineCall(command.method, params)
|
|
5158
|
-
})
|
|
5342
|
+
});
|
|
5343
|
+
if (translator) {
|
|
5344
|
+
try {
|
|
5345
|
+
printAnswer(await (await import("./translate-DJUutSis.js")).translateAnswer(result, translator));
|
|
5346
|
+
} finally {
|
|
5347
|
+
translator.close();
|
|
5348
|
+
}
|
|
5349
|
+
return;
|
|
5350
|
+
}
|
|
5351
|
+
printAnswer(result);
|
|
5159
5352
|
}
|
|
5160
5353
|
/**
|
|
5161
5354
|
* `call pipe`: a call's audio socket bridged to stdin and stdout, for shell pipelines. stdout carries audio only (the
|
|
@@ -5328,4 +5521,4 @@ async function run(argv) {
|
|
|
5328
5521
|
//#endregion
|
|
5329
5522
|
export { run };
|
|
5330
5523
|
|
|
5331
|
-
//# sourceMappingURL=main-
|
|
5524
|
+
//# sourceMappingURL=main-CjO0KGiF.js.map
|