@ghostlytools/cli 1.11.1 → 1.11.3
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 +32 -23
- package/dist/assets/{api-DL0Uazf6.js → api-DBlaoz8i.js} +478 -141
- package/dist/assets/api-DBlaoz8i.js.map +1 -0
- package/dist/assets/{api-D89ubgas.js → api-DgU4MZPD.js} +2 -2
- package/dist/assets/{apiKit-D78MXTrk.js → apiKit-DesObIDf.js} +19 -9
- package/dist/assets/apiKit-DesObIDf.js.map +1 -0
- package/dist/assets/appFetch-C8yZIq1e.js +194 -0
- package/dist/assets/appFetch-C8yZIq1e.js.map +1 -0
- package/dist/assets/{apps--pAqmfgQ.js → apps-DkMjDHML.js} +142 -67
- package/dist/assets/apps-DkMjDHML.js.map +1 -0
- package/dist/assets/{apps-BlSl1nGn.js → apps-rzxsjfBV.js} +1 -1
- package/dist/assets/{arkade-DxB-MR43.js → arkade-CarKONmH.js} +2 -2
- package/dist/assets/{arkade-DxB-MR43.js.map → arkade-CarKONmH.js.map} +1 -1
- package/dist/assets/{backup-B3JJd75o.js → backup-C0OJCJlM.js} +90 -47
- package/dist/assets/backup-C0OJCJlM.js.map +1 -0
- package/dist/assets/{backup-T7gFpU80.js → backup-CgWU7x0T.js} +1 -1
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/{bitcoind-CZchoh43.js → bitcoind-CdSmvy2y.js} +3 -3
- package/dist/assets/{bitcoind-CZchoh43.js.map → bitcoind-CdSmvy2y.js.map} +1 -1
- package/dist/assets/{bitcoindProvider-DGw3xBSa.js → bitcoindProvider-BvoRh0D5.js} +2 -2
- package/dist/assets/{bitcoindProvider-DGw3xBSa.js.map → bitcoindProvider-BvoRh0D5.js.map} +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/buttons-Cco0Agfa.js +2 -0
- package/dist/assets/{buttons-C1VbDihe.js → buttons-fZTEa_2i.js} +47 -7
- package/dist/assets/buttons-fZTEa_2i.js.map +1 -0
- package/dist/assets/{childEnv-BVOQK9EA.js → childEnv-K_IzUqQx.js} +4 -3
- package/dist/assets/childEnv-K_IzUqQx.js.map +1 -0
- package/dist/assets/{client-CGLuWFRV.js → client-Ibk3-e60.js} +31 -3
- package/dist/assets/client-Ibk3-e60.js.map +1 -0
- package/dist/assets/{codec-YGJDr7uH.js → codec-DMpQqVSt.js} +2 -2
- package/dist/assets/{codec-YGJDr7uH.js.map → codec-DMpQqVSt.js.map} +1 -1
- package/dist/assets/endpoint-DarqblYE.js +5052 -0
- package/dist/assets/endpoint-DarqblYE.js.map +1 -0
- package/dist/assets/{envelope-Dwq8EN8x.js → envelope-CvQVCGdf.js} +2 -2
- package/dist/assets/{envelope-Dwq8EN8x.js.map → envelope-CvQVCGdf.js.map} +1 -1
- package/dist/assets/{fedimintSdk-CqTeMdF0.js → fedimintSdk-zV_5Qdqz.js} +6 -3
- package/dist/assets/fedimintSdk-zV_5Qdqz.js.map +1 -0
- package/dist/assets/{fixedHosts-CINXidpd.js → fixedHosts-6gKn8dp2.js} +3 -3
- package/dist/assets/{fixedHosts-CINXidpd.js.map → fixedHosts-6gKn8dp2.js.map} +1 -1
- package/dist/assets/{host-CGlHkiQv.js → host-CYlIiY3r.js} +455 -104
- package/dist/assets/host-CYlIiY3r.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-Bj5jJT5w.js → hyperdhtRelay-CdsLcAhY.js} +2 -2
- package/dist/assets/{hyperdhtRelay-Bj5jJT5w.js.map → hyperdhtRelay-CdsLcAhY.js.map} +1 -1
- package/dist/assets/{irohWeb-CYn0uB_A.js → irohWeb-D2IuloLL.js} +705 -43
- package/dist/assets/irohWeb-D2IuloLL.js.map +1 -0
- package/dist/assets/jsonOut-POtMBS_V.js +16 -0
- package/dist/assets/jsonOut-POtMBS_V.js.map +1 -0
- package/dist/assets/{main-CgLW_Gyx.js → main-C0PfjKTe.js} +263 -128
- package/dist/assets/main-C0PfjKTe.js.map +1 -0
- package/dist/assets/{mainline-B0h8RchD.js → mainline-Cu61qcPS.js} +60 -24
- package/dist/assets/mainline-Cu61qcPS.js.map +1 -0
- package/dist/assets/{networkReason-BBosp2KG.js → networkReason-Dt7Yx_n4.js} +3 -3
- package/dist/assets/{networkReason-BBosp2KG.js.map → networkReason-Dt7Yx_n4.js.map} +1 -1
- package/dist/assets/{nwc-SSNS1aJ-.js → nwc-CtZypDcv.js} +6 -5
- package/dist/assets/nwc-CtZypDcv.js.map +1 -0
- package/dist/assets/{nwcProvider-BXqJmM98.js → nwcProvider-DYHkd0iu.js} +6 -3
- package/dist/assets/{nwcProvider-BXqJmM98.js.map → nwcProvider-DYHkd0iu.js.map} +1 -1
- package/dist/assets/{ownDid--DtH_Jdi.js → ownDid-CJ0ta8CL.js} +3 -3
- package/dist/assets/{ownDid--DtH_Jdi.js.map → ownDid-CJ0ta8CL.js.map} +1 -1
- package/dist/assets/{ownStatus-CQPGjCUR.js → ownStatus-D4HC6tNR.js} +12 -6
- package/dist/assets/{ownStatus-CQPGjCUR.js.map → ownStatus-D4HC6tNR.js.map} +1 -1
- package/dist/assets/{profiles-4UQ1Hsds.js → profiles-Ccdq6Xf6.js} +82 -6
- package/dist/assets/profiles-Ccdq6Xf6.js.map +1 -0
- package/dist/assets/{registry-B6BXKv6Q.js → registry-CE0PpQAE.js} +1 -1
- package/dist/assets/{registry-BKCFTEYp.js → registry-LvxsLJ5S.js} +88 -25
- package/dist/assets/registry-LvxsLJ5S.js.map +1 -0
- package/dist/assets/{resolve-MFeFljsN.js → resolve-6kVu2DE5.js} +4 -3
- package/dist/assets/resolve-6kVu2DE5.js.map +1 -0
- package/dist/assets/{server-rHKhnog1.js → server-Q3VcNqGt.js} +630 -933
- package/dist/assets/server-Q3VcNqGt.js.map +1 -0
- package/dist/assets/{src-BzsyAvPf.js → src-DjVj2ynY.js} +580 -168
- package/dist/assets/src-DjVj2ynY.js.map +1 -0
- package/dist/assets/{sshForges-qITn-RoV.js → sshForges-DeZ9cN9Q.js} +4 -3
- package/dist/assets/sshForges-DeZ9cN9Q.js.map +1 -0
- package/dist/assets/{translate-Bkr_iDgp.js → translate-iQZq4TnY.js} +36 -15
- package/dist/assets/translate-iQZq4TnY.js.map +1 -0
- package/dist/assets/{types-C4_KafL_.js → types-Clyb52K2.js} +2 -1
- package/dist/assets/types-Clyb52K2.js.map +1 -0
- package/dist/assets/{usdt-Bp7T2iqt.js → usdt-DnyTGdTX.js} +3 -3
- package/dist/assets/{usdt-Bp7T2iqt.js.map → usdt-DnyTGdTX.js.map} +1 -1
- package/dist/ghostly.mjs +1 -1
- package/npm-shrinkwrap.json +3592 -0
- package/package.json +5 -3
- package/dist/assets/api-DL0Uazf6.js.map +0 -1
- package/dist/assets/apiKit-D78MXTrk.js.map +0 -1
- package/dist/assets/apps--pAqmfgQ.js.map +0 -1
- package/dist/assets/backup-B3JJd75o.js.map +0 -1
- package/dist/assets/buttons-C1VbDihe.js.map +0 -1
- package/dist/assets/buttons-DwWuK_uN.js +0 -2
- package/dist/assets/childEnv-BVOQK9EA.js.map +0 -1
- package/dist/assets/client-CGLuWFRV.js.map +0 -1
- package/dist/assets/endpoint-DWHkXWVM.js +0 -419
- package/dist/assets/endpoint-DWHkXWVM.js.map +0 -1
- package/dist/assets/fedimintSdk-CqTeMdF0.js.map +0 -1
- package/dist/assets/host-CGlHkiQv.js.map +0 -1
- package/dist/assets/irohWeb-CYn0uB_A.js.map +0 -1
- package/dist/assets/main-CgLW_Gyx.js.map +0 -1
- package/dist/assets/mainline-B0h8RchD.js.map +0 -1
- package/dist/assets/nwc-SSNS1aJ-.js.map +0 -1
- package/dist/assets/profiles-4UQ1Hsds.js.map +0 -1
- package/dist/assets/registry-BKCFTEYp.js.map +0 -1
- package/dist/assets/resolve-MFeFljsN.js.map +0 -1
- package/dist/assets/server-rHKhnog1.js.map +0 -1
- package/dist/assets/src-BzsyAvPf.js.map +0 -1
- package/dist/assets/sshForges-qITn-RoV.js.map +0 -1
- package/dist/assets/translate-Bkr_iDgp.js.map +0 -1
- package/dist/assets/types-C4_KafL_.js.map +0 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Ao as
|
|
1
|
+
import { Ao as ROUTINE_STATES, Do as ITEM_STATES, Eo as CRON_LINE, Lo as cardLine, Mo as STATUS_CARD_LIMITS, No as TASK_STATUSES, Oo as PR_CHECKS, Qr as STATUS_AVAILABILITIES, Ro as cardUrl, Ua as VOICE_LIMITS, Vo as statusCardBytes, jo as RUN_RESULTS, ko as PR_STATES, sr as GROUP_FILE_LIMITS } from "./src-DjVj2ynY.js";
|
|
2
2
|
import { i as localFileError, n as EXIT, r as asCliError, t as CliError } from "./errors-Dt-ZnyOX.js";
|
|
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 {
|
|
5
|
-
import { n as dropSecretEnv, t as childEnv } from "./childEnv-
|
|
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-D4HC6tNR.js";
|
|
4
|
+
import { a as contactKeyOf, v as nameKey, y as namedByThem } from "./apiKit-DesObIDf.js";
|
|
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 { _ as
|
|
8
|
-
import {
|
|
7
|
+
import { C as ownProfile, _ as profilePaths, c as createProfile, d as ghostlyHome, f as listProfiles, g as profileExists, h as noProfile, i as checkProfileName, l as currentProfile, o as checkShownNameOption, p as lockOwner, s as claimForDaemon, u as daemonClaim, v as selectProfile, x as userPath, y as startingDaemon } from "./profiles-Ccdq6Xf6.js";
|
|
8
|
+
import { t as jsonOut } from "./jsonOut-POtMBS_V.js";
|
|
9
|
+
import { a as endedUnsent, f as CALL_RATES, i as endedUnanswered, o as isNotTheDaemon, r as connectDaemon, t as DaemonClient, v as isCallRate } from "./client-Ibk3-e60.js";
|
|
9
10
|
import { spawn } from "node:child_process";
|
|
10
11
|
import { accessSync, closeSync, constants, existsSync, fstatSync, openSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
11
12
|
import { dirname, resolve, sep } from "node:path";
|
|
@@ -13,7 +14,7 @@ import { connect } from "node:net";
|
|
|
13
14
|
import { format } from "node:util";
|
|
14
15
|
var package_default = {
|
|
15
16
|
name: "@ghostlytools/cli",
|
|
16
|
-
version: "1.11.
|
|
17
|
+
version: "1.11.3",
|
|
17
18
|
type: "module",
|
|
18
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.",
|
|
19
20
|
license: "MIT",
|
|
@@ -31,7 +32,8 @@ var package_default = {
|
|
|
31
32
|
"examples",
|
|
32
33
|
"skills",
|
|
33
34
|
"README.md",
|
|
34
|
-
"SKILL.md"
|
|
35
|
+
"SKILL.md",
|
|
36
|
+
"npm-shrinkwrap.json"
|
|
35
37
|
],
|
|
36
38
|
engines: { "node": ">=22.12" },
|
|
37
39
|
scripts: {
|
|
@@ -72,7 +74,8 @@ var package_default = {
|
|
|
72
74
|
"node-datachannel": "^0.33.4",
|
|
73
75
|
"nostr-tools": "2.25.2",
|
|
74
76
|
"opus-decoder": "0.7.12",
|
|
75
|
-
"opusscript": "0.1.1"
|
|
77
|
+
"opusscript": "0.1.1",
|
|
78
|
+
"ws": "8.22.1"
|
|
76
79
|
},
|
|
77
80
|
devDependencies: {
|
|
78
81
|
"@ghostly/browser": "*",
|
|
@@ -814,13 +817,14 @@ function writtenDay(text) {
|
|
|
814
817
|
* A day the month does not have (`2026-04-31`) is refused, where `Date.parse` made it May 1. A time more than a year
|
|
815
818
|
* ahead is a usage error that names the flag and the last time it takes: before, it reached the card's check and failed
|
|
816
819
|
* as `bad_request` (exit 1), "Status card: resetsAt is a time in milliseconds, within a year". A time past is taken.
|
|
820
|
+
* `forms` is what a time it cannot read is told to be, for a flag that takes more (`status set --until 2h`).
|
|
817
821
|
*/
|
|
818
|
-
function cardTime(value, flag) {
|
|
822
|
+
function cardTime(value, flag, forms = `a time in milliseconds or a date: ${CARD_TIME_FORMS}`) {
|
|
819
823
|
if (value === void 0) return void 0;
|
|
820
824
|
const text = String(value).trim();
|
|
821
825
|
const day = ISO_DAY.exec(text);
|
|
822
826
|
const ms = /^\d+$/.test(text) ? milliseconds(text, flag) : Date.parse(day ? `${text}${day[1] ? "" : "-01"}T00:00` : text);
|
|
823
|
-
if (!Number.isSafeInteger(ms) || ms <= 0) throw new CliError("usage", `--${flag} takes
|
|
827
|
+
if (!Number.isSafeInteger(ms) || ms <= 0) throw new CliError("usage", `--${flag} takes ${forms}, not ${JSON.stringify(value)}`);
|
|
824
828
|
const written = writtenDay(text);
|
|
825
829
|
if (written) {
|
|
826
830
|
const [year, month, date] = written, days = new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
@@ -1110,7 +1114,7 @@ var commands$8 = {
|
|
|
1110
1114
|
description: "Replace the three files when they are there"
|
|
1111
1115
|
}
|
|
1112
1116
|
},
|
|
1113
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1117
|
+
run: async ({ options }, a) => (await import("./apps-rzxsjfBV.js")).initApp(a.dir, {
|
|
1114
1118
|
name: options.name,
|
|
1115
1119
|
title: options.title,
|
|
1116
1120
|
force: options.force === true
|
|
@@ -1150,7 +1154,7 @@ var commands$8 = {
|
|
|
1150
1154
|
description: "This version's sequence, higher than the bundle at --out's (default: one more than it)"
|
|
1151
1155
|
}
|
|
1152
1156
|
},
|
|
1153
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1157
|
+
run: async ({ options }, a) => (await import("./apps-rzxsjfBV.js")).publishApp(a.dir, keyFile(options.key, "app publish <dir> --key <file> [--out <file>] [--sequence n]"), here(options.out), options.sequence)
|
|
1154
1158
|
},
|
|
1155
1159
|
"app revoke": {
|
|
1156
1160
|
method: "app.revoke",
|
|
@@ -1183,7 +1187,7 @@ var commands$8 = {
|
|
|
1183
1187
|
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"
|
|
1184
1188
|
}
|
|
1185
1189
|
},
|
|
1186
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1190
|
+
run: async ({ options }, a) => (await import("./apps-rzxsjfBV.js")).revokeApp(a.dir, keyFile(options.key, "app revoke <dir> --key <file> (--digest <digest>... | --up-to <sequence>) [--reason <text>] [--bundle <file>] [--force]"), {
|
|
1187
1191
|
digests: options.digest,
|
|
1188
1192
|
upTo: options["up-to"],
|
|
1189
1193
|
reason: options.reason,
|
|
@@ -1242,9 +1246,9 @@ var commands$8 = {
|
|
|
1242
1246
|
"app verify": {
|
|
1243
1247
|
method: "app.verify",
|
|
1244
1248
|
usage: "app verify <bundle|url>",
|
|
1245
|
-
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",
|
|
1249
|
+
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",
|
|
1246
1250
|
args: ["bundle"],
|
|
1247
|
-
run: async (_, a) => (await import("./apps-
|
|
1251
|
+
run: async (_, a) => (await import("./apps-rzxsjfBV.js")).verifyApp(a.bundle)
|
|
1248
1252
|
},
|
|
1249
1253
|
"store sign": {
|
|
1250
1254
|
method: "store.sign",
|
|
@@ -1261,7 +1265,7 @@ var commands$8 = {
|
|
|
1261
1265
|
description: "The folder to write ghostly-store.json and ghostly-store.sig in (default: the index's)"
|
|
1262
1266
|
}
|
|
1263
1267
|
},
|
|
1264
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1268
|
+
run: async ({ options }, a) => (await import("./apps-rzxsjfBV.js")).signStore(a.index, keyFile(options.key, "store sign <index> --key <file> [--out <dir>]"), here(options.out))
|
|
1265
1269
|
}
|
|
1266
1270
|
};
|
|
1267
1271
|
//#endregion
|
|
@@ -1528,16 +1532,23 @@ var commands$6 = {
|
|
|
1528
1532
|
},
|
|
1529
1533
|
"chat remove": {
|
|
1530
1534
|
method: "chat.remove",
|
|
1531
|
-
usage: "chat remove <chat> --yes",
|
|
1532
|
-
summary: "Delete a chat, its keys and history on this device",
|
|
1535
|
+
usage: "chat remove <chat> --yes [--force]",
|
|
1536
|
+
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",
|
|
1533
1537
|
args: ["chat"],
|
|
1534
|
-
options: {
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
+
options: {
|
|
1539
|
+
yes: {
|
|
1540
|
+
type: "boolean",
|
|
1541
|
+
description: "Confirm"
|
|
1542
|
+
},
|
|
1543
|
+
force: {
|
|
1544
|
+
type: "boolean",
|
|
1545
|
+
description: "Remove it even if a message you deleted for everyone has not reached the contact yet"
|
|
1546
|
+
}
|
|
1547
|
+
},
|
|
1538
1548
|
params: ({ options }, { chat }) => ({
|
|
1539
1549
|
chat,
|
|
1540
|
-
yes: options.yes === true
|
|
1550
|
+
yes: options.yes === true,
|
|
1551
|
+
force: options.force === true
|
|
1541
1552
|
})
|
|
1542
1553
|
},
|
|
1543
1554
|
"chat rename": {
|
|
@@ -2174,11 +2185,12 @@ var UNIT_MS = {
|
|
|
2174
2185
|
/**
|
|
2175
2186
|
* `status set --until`: a time to come, as long from now (30m, 2h, 1d) or as a card's time is written (milliseconds or a
|
|
2176
2187
|
* date, local time when it names no zone), within a year. A time past is refused: the engine would take it as no status.
|
|
2188
|
+
* One it cannot read names the three forms, as its help does: `--until 2y` named only milliseconds and dates.
|
|
2177
2189
|
*/
|
|
2178
2190
|
function statusUntil(value) {
|
|
2179
2191
|
if (value === void 0) return void 0;
|
|
2180
2192
|
const text = String(value).trim(), duration = DURATION.exec(text);
|
|
2181
|
-
const ms = duration ? Date.now() + Number(duration[1]) * UNIT_MS[duration[2]] : cardTime(text, "until");
|
|
2193
|
+
const ms = duration ? Date.now() + Number(duration[1]) * UNIT_MS[duration[2]] : cardTime(text, "until", `30m, 2h or 1d from now (whole minutes, hours or days), milliseconds or a date: ${CARD_TIME_FORMS}`);
|
|
2182
2194
|
if (duration && !(ms <= Date.now() + STATUS_CARD_LIMITS.nextRunMs)) throw new CliError("usage", `--until takes a time within a year from now, not ${JSON.stringify(value)}`);
|
|
2183
2195
|
if (ms <= Date.now()) throw new CliError("usage", `--until takes a time to come, not ${JSON.stringify(value)}: a status that ended is none`);
|
|
2184
2196
|
return ms;
|
|
@@ -2737,6 +2749,17 @@ var commands$2 = {
|
|
|
2737
2749
|
};
|
|
2738
2750
|
//#endregion
|
|
2739
2751
|
//#region src/commands/payments.ts
|
|
2752
|
+
/**
|
|
2753
|
+
* `chat accept`'s --networks: mainnet and/or testnet, comma-separated; any other word, or none (an unset variable), is a
|
|
2754
|
+
* usage error before the profile opens, as a word --network does not take is. Before, the API refused it after a
|
|
2755
|
+
* one-shot had opened the profile: bad_request, exit 1.
|
|
2756
|
+
*/
|
|
2757
|
+
function networkList(value) {
|
|
2758
|
+
const networks = value.split(",").map((n) => n.trim()).filter(Boolean);
|
|
2759
|
+
if (!networks.length) throw new CliError("usage", `--networks takes mainnet, testnet or mainnet,testnet (to stop taking it: --off), not ${JSON.stringify(value)}`);
|
|
2760
|
+
if (!networks.every((n) => n === "mainnet" || n === "testnet")) throw new CliError("usage", `--networks takes mainnet, testnet or mainnet,testnet, not ${JSON.stringify(value)}`);
|
|
2761
|
+
return networks;
|
|
2762
|
+
}
|
|
2740
2763
|
/** Wallets and payments: one entry per command, in alphabetical order (test/commands.test.ts checks). */
|
|
2741
2764
|
var commands$1 = {
|
|
2742
2765
|
"chat accept": {
|
|
@@ -2762,7 +2785,7 @@ var commands$1 = {
|
|
|
2762
2785
|
chat: a.chat,
|
|
2763
2786
|
method: a.method,
|
|
2764
2787
|
on: options.off !== true,
|
|
2765
|
-
networks: typeof options.networks === "string" ? options.networks
|
|
2788
|
+
networks: typeof options.networks === "string" ? networkList(options.networks) : void 0
|
|
2766
2789
|
};
|
|
2767
2790
|
}
|
|
2768
2791
|
},
|
|
@@ -2876,7 +2899,7 @@ var commands$1 = {
|
|
|
2876
2899
|
options: {
|
|
2877
2900
|
amount: {
|
|
2878
2901
|
type: "number",
|
|
2879
|
-
description: "Sats, for an address or LNURL"
|
|
2902
|
+
description: "Sats, for an address or LNURL; with an invoice, refuse it unless it asks exactly this"
|
|
2880
2903
|
},
|
|
2881
2904
|
network: net,
|
|
2882
2905
|
"max-fee": {
|
|
@@ -3392,19 +3415,6 @@ function noMoreThan(count, values, usage) {
|
|
|
3392
3415
|
if (values.length > count) throw new CliError("usage", `Too many arguments: ghostly ${usage}`);
|
|
3393
3416
|
}
|
|
3394
3417
|
//#endregion
|
|
3395
|
-
//#region src/jsonOut.ts
|
|
3396
|
-
/**
|
|
3397
|
-
* What `JSON.stringify` leaves raw and a terminal may act on: DEL and the C1 controls (CSI, OSC, ST, NEL... in UTF-8),
|
|
3398
|
-
* the line and paragraph separators, and the bidi marks, embeddings, overrides and isolates that reorder a line. Only
|
|
3399
|
-
* a string holds them, and a peer writes some of those strings (a message's text), so the CLI's output writes them as
|
|
3400
|
-
* `\uXXXX`: the same JSON value for every reader, nothing a terminal acts on. What is stored stays whole.
|
|
3401
|
-
*/
|
|
3402
|
-
var RAW = /[\u007f-\u009f\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g;
|
|
3403
|
-
/** `value` as the JSON the CLI prints: `JSON.stringify`, with `RAW` escaped. */
|
|
3404
|
-
function jsonOut(value, space) {
|
|
3405
|
-
return JSON.stringify(value, null, space)?.replace(RAW, (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, "0"));
|
|
3406
|
-
}
|
|
3407
|
-
//#endregion
|
|
3408
3418
|
//#region src/listen.ts
|
|
3409
3419
|
/** The cursor's own write failed, not the event's handling. */
|
|
3410
3420
|
var CursorError = class extends Error {
|
|
@@ -3457,8 +3467,9 @@ var Allowlist = class {
|
|
|
3457
3467
|
async function allowlist(from, groups, call, peerOf) {
|
|
3458
3468
|
const chats = /* @__PURE__ */ new Set(), keys = /* @__PURE__ */ new Set(), groupIds = /* @__PURE__ */ new Set();
|
|
3459
3469
|
for (const ref of from) {
|
|
3460
|
-
|
|
3461
|
-
|
|
3470
|
+
const key = contactKeyOf(ref);
|
|
3471
|
+
if (key !== void 0) {
|
|
3472
|
+
keys.add(key);
|
|
3462
3473
|
continue;
|
|
3463
3474
|
}
|
|
3464
3475
|
const chat = await otherFlag(call("chat.get", { chat: ref }), ref, "--from");
|
|
@@ -3493,7 +3504,7 @@ async function otherFlag(lookup, ref, flag) {
|
|
|
3493
3504
|
var forMe = (message) => !!message.mentioned || !!message.press;
|
|
3494
3505
|
/**
|
|
3495
3506
|
* The turn an event starts, or null: only a contact's message, and a group message that mentions this profile or
|
|
3496
|
-
* presses a button of its question.
|
|
3507
|
+
* presses a button of its question (or the `group.mentioned`, `button.pressed` that says so later).
|
|
3497
3508
|
*/
|
|
3498
3509
|
function toTurn(event) {
|
|
3499
3510
|
const message = event.message;
|
|
@@ -3507,6 +3518,10 @@ function toTurn(event) {
|
|
|
3507
3518
|
group: event.group,
|
|
3508
3519
|
...message.member ? { member: message.member } : {}
|
|
3509
3520
|
}, message);
|
|
3521
|
+
if (event.type === "button.pressed" && typeof event.group === "string" && message.press) return turn(event, "button.pressed", {
|
|
3522
|
+
group: event.group,
|
|
3523
|
+
...message.member ? { member: message.member } : {}
|
|
3524
|
+
}, message);
|
|
3510
3525
|
return null;
|
|
3511
3526
|
}
|
|
3512
3527
|
function turn(event, source, where, message) {
|
|
@@ -3547,13 +3562,16 @@ function turn(event, source, where, message) {
|
|
|
3547
3562
|
}
|
|
3548
3563
|
};
|
|
3549
3564
|
}
|
|
3550
|
-
/**
|
|
3551
|
-
|
|
3565
|
+
/**
|
|
3566
|
+
* Only loopback: events carry message text, and a webhook is a local bridge (WISP 1100 § Security). `from` names where
|
|
3567
|
+
* the URL came from; what is not a URL is not repeated: a bridge's token is in it.
|
|
3568
|
+
*/
|
|
3569
|
+
function checkWebhook(url, from = "--webhook") {
|
|
3552
3570
|
let parsed;
|
|
3553
3571
|
try {
|
|
3554
3572
|
parsed = new URL(url);
|
|
3555
3573
|
} catch {
|
|
3556
|
-
throw new CliError("usage",
|
|
3574
|
+
throw new CliError("usage", `${from} is not a URL`);
|
|
3557
3575
|
}
|
|
3558
3576
|
if (!["http:", "https:"].includes(parsed.protocol)) throw new CliError("usage", "The webhook must be http:// or https://");
|
|
3559
3577
|
if (![
|
|
@@ -3561,7 +3579,7 @@ function checkWebhook(url) {
|
|
|
3561
3579
|
"localhost",
|
|
3562
3580
|
"[::1]"
|
|
3563
3581
|
].includes(parsed.hostname)) throw new CliError("usage", "The webhook must be on this machine (127.0.0.1, localhost or [::1])");
|
|
3564
|
-
if (parsed.username || parsed.password) throw new CliError("usage", "The webhook URL takes no user or password: put the bridge's token in its path or query");
|
|
3582
|
+
if (parsed.username || parsed.password) throw new CliError("usage", "The webhook URL takes no user or password: put the bridge's token in its path or query, the URL in GHOSTLY_WEBHOOK");
|
|
3565
3583
|
return parsed;
|
|
3566
3584
|
}
|
|
3567
3585
|
/**
|
|
@@ -3690,6 +3708,13 @@ function checkTypes(types, warn) {
|
|
|
3690
3708
|
if (type === "*") continue;
|
|
3691
3709
|
const family = type.split(/[.*]/)[0];
|
|
3692
3710
|
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(", ")})`);
|
|
3711
|
+
const known = EVENT_TYPES.filter((each) => matches({
|
|
3712
|
+
seq: 0,
|
|
3713
|
+
id: "",
|
|
3714
|
+
type: each,
|
|
3715
|
+
at: 0
|
|
3716
|
+
}, [type]));
|
|
3717
|
+
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
3718
|
if (!EVENT_TYPES.some((known) => matches({
|
|
3694
3719
|
seq: 0,
|
|
3695
3720
|
id: "",
|
|
@@ -3858,12 +3883,9 @@ function eventHandler(options) {
|
|
|
3858
3883
|
if (stopped) return;
|
|
3859
3884
|
const skip = () => keep(event.seq);
|
|
3860
3885
|
if (options.allow && !await options.allow.allows(event)) return skip();
|
|
3886
|
+
if (options.turns && !gap && !toTurn(event)) return skip();
|
|
3861
3887
|
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
|
-
}
|
|
3888
|
+
if (options.turns && !gap) event = toTurn(event);
|
|
3867
3889
|
const full = options.print && options.write(jsonOut(event)) === false;
|
|
3868
3890
|
if (options.exec) {
|
|
3869
3891
|
const hook = running = runExec(options.exec, event, options.print);
|
|
@@ -4240,15 +4262,15 @@ var VERSION = package_default.version;
|
|
|
4240
4262
|
* command a running daemon answers loads none of them, and starts about as fast as Node does. Statically imported, they
|
|
4241
4263
|
* cost every command ~100 ms before its socket was opened.
|
|
4242
4264
|
*/
|
|
4243
|
-
var engineApi = () => import("./api-
|
|
4244
|
-
var engineHost = () => import("./host-
|
|
4265
|
+
var engineApi = () => import("./api-DgU4MZPD.js");
|
|
4266
|
+
var engineHost = () => import("./host-CYlIiY3r.js");
|
|
4245
4267
|
/**
|
|
4246
4268
|
* `--translate <lang>`'s translator, or null (not asked; or the runtime is not there, said on stderr). Loaded only when
|
|
4247
4269
|
* asked: the app's message parser it reads costs every other command nothing.
|
|
4248
4270
|
*/
|
|
4249
4271
|
async function translatorFor(value, home) {
|
|
4250
4272
|
if (value === void 0) return null;
|
|
4251
|
-
const { loadDetector, openTranslator, translateTarget } = await import("./translate-
|
|
4273
|
+
const { loadDetector, openTranslator, translateTarget } = await import("./translate-iQZq4TnY.js");
|
|
4252
4274
|
return openTranslator({
|
|
4253
4275
|
home,
|
|
4254
4276
|
to: translateTarget(value),
|
|
@@ -4388,6 +4410,38 @@ function newChatOnly(method) {
|
|
|
4388
4410
|
function oneChatOnly(method, params) {
|
|
4389
4411
|
return newChatOnly(method) || (chatOnly(method, params) || chatOrGroup(method, params)) && typeof params.chat === "string";
|
|
4390
4412
|
}
|
|
4413
|
+
/** What a member says in one group, over that group's own edges: no 1:1 chat carries any of it. */
|
|
4414
|
+
var GROUP_EDGES_ONLY = /* @__PURE__ */ new Set([
|
|
4415
|
+
"group.send",
|
|
4416
|
+
"group.edit",
|
|
4417
|
+
"group.react",
|
|
4418
|
+
"group.typing"
|
|
4419
|
+
]);
|
|
4420
|
+
/**
|
|
4421
|
+
* A command about one group that goes over its edges only (`GROUP_EDGES_ONLY`): a one-shot for it leaves the saved 1:1
|
|
4422
|
+
* chats unstarted (`deferChats`); the groups start, and their edges are never deferred. Started, each saved chat put its
|
|
4423
|
+
* records and its leave packet on the relays: with 12 invites saved, one `group send` asked the relay 32 times (3 with
|
|
4424
|
+
* none), its whole minute, and a text to an away contact, or the next one-shot, waited behind them.
|
|
4425
|
+
*/
|
|
4426
|
+
function oneGroupOnly(method) {
|
|
4427
|
+
return GROUP_EDGES_ONLY.has(method);
|
|
4428
|
+
}
|
|
4429
|
+
/**
|
|
4430
|
+
* Reads that need nothing of a chat's history: a one-shot for one leaves every saved chat unstarted too (`deferChats`),
|
|
4431
|
+
* so its start reads each chat's newest row (its place in `chat list`) and no history. It read every 1:1 chat whole:
|
|
4432
|
+
* `profile show` took 0.8 s and 243 MB instead of 0.45 s and 162 MB with 53,800 messages in the profile.
|
|
4433
|
+
*/
|
|
4434
|
+
var NO_HISTORY_READS = /* @__PURE__ */ new Set([
|
|
4435
|
+
"status",
|
|
4436
|
+
"profile.get",
|
|
4437
|
+
"settings.get",
|
|
4438
|
+
"status.get",
|
|
4439
|
+
"chat.list"
|
|
4440
|
+
]);
|
|
4441
|
+
/** Whether a one-shot for this call leaves every saved chat unstarted, its history unread (`NO_HISTORY_READS`). */
|
|
4442
|
+
function readsNoHistory(method) {
|
|
4443
|
+
return NO_HISTORY_READS.has(method);
|
|
4444
|
+
}
|
|
4391
4445
|
/**
|
|
4392
4446
|
* Calls that only read what the profile stores: a one-shot for one opens it offline (`RuntimeOptions.offline`).
|
|
4393
4447
|
* Opened online, `status` or `chat list` started every chat, put the profile's records on the relays again and waited
|
|
@@ -4451,15 +4505,26 @@ var LOCAL_WRITES = /* @__PURE__ */ new Set([
|
|
|
4451
4505
|
"status.set",
|
|
4452
4506
|
"status.clear"
|
|
4453
4507
|
]);
|
|
4454
|
-
/**
|
|
4508
|
+
/**
|
|
4509
|
+
* Settings of this device only: no contact and no relay hears of them (nick, avatar and the relays' do). A one-shot
|
|
4510
|
+
* says no presence (`daemonPresence`): only a daemon does, from its start or at once when it is the one that sets it.
|
|
4511
|
+
*/
|
|
4455
4512
|
var LOCAL_SETTINGS = /* @__PURE__ */ new Set([
|
|
4456
4513
|
"sendTyping",
|
|
4457
4514
|
"autoDownloads",
|
|
4458
|
-
"serveFiles"
|
|
4515
|
+
"serveFiles",
|
|
4516
|
+
"daemonPresence"
|
|
4459
4517
|
]);
|
|
4460
|
-
/**
|
|
4518
|
+
/**
|
|
4519
|
+
* Said on a live session only (WISP 401 § Typing, WISP 902 · Group Mesh § Typing). A one-shot starts the chat or group
|
|
4520
|
+
* as it says it, so nothing is live yet and it reached nobody; online it then waited for the link's records on the
|
|
4521
|
+
* relays (3.4 s with a relay that takes 1.5 s, 10 s with one that does not answer). With `--for` it waits for the chat
|
|
4522
|
+
* to be live (`keepOneShot`), so that one stays online.
|
|
4523
|
+
*/
|
|
4524
|
+
var LIVE_ONLY = /* @__PURE__ */ new Set(["chat.typing", "group.typing"]);
|
|
4525
|
+
/** Whether a one-shot for this call opens the profile offline: a read, a change that stays on this device, or typing. */
|
|
4461
4526
|
function offlineCall(method, params) {
|
|
4462
|
-
return readOnly(method, params) || LOCAL_WRITES.has(method);
|
|
4527
|
+
return readOnly(method, params) || LOCAL_WRITES.has(method) || LIVE_ONLY.has(method) && params.for === void 0;
|
|
4463
4528
|
}
|
|
4464
4529
|
/** 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
|
|
4465
4530
|
* contact carries its own `--timeout` (or the daemon's default for it), plus a margin; anything else may take as long
|
|
@@ -4479,8 +4544,8 @@ async function session(g, options, again = true) {
|
|
|
4479
4544
|
const [, { callApi, startNamedChats }] = await Promise.all([engineHost(), engineApi()]);
|
|
4480
4545
|
const host = await openOneShot(g, options);
|
|
4481
4546
|
if (host instanceof DaemonClient) return throughDaemon(host, anew);
|
|
4482
|
-
const call = (m, p) => {
|
|
4483
|
-
if (options.deferChats && p && typeof p === "object") startNamedChats(host.ctx, p);
|
|
4547
|
+
const call = async (m, p) => {
|
|
4548
|
+
if (options.deferChats && p && typeof p === "object") await startNamedChats(host.ctx, p);
|
|
4484
4549
|
return callApi(host.ctx, m, p ?? {});
|
|
4485
4550
|
};
|
|
4486
4551
|
return {
|
|
@@ -4509,7 +4574,9 @@ function waitLeft(method, params, spentMs) {
|
|
|
4509
4574
|
* (`endedUnanswered`): the daemon stopped or restarted under it. The read is asked once more there, through the daemon
|
|
4510
4575
|
* that answers now or on the profile itself, and so is every call after it. It failed as a timeout told to check
|
|
4511
4576
|
* `ghostly chat history` for a message that was never sent (exit 4), as "The daemon went away" (exit 1), or refused as
|
|
4512
|
-
* a daemon of an older release (exit 1), while a command started a moment later answered.
|
|
4577
|
+
* a daemon of an older release (exit 1), while a command started a moment later answered. So is any call whose
|
|
4578
|
+
* connection ended before it was written (`endedUnsent`): nothing reached the daemon, and a bot's `typing` or `send`
|
|
4579
|
+
* that met a `daemon restart` failed as "The daemon went away" while the new daemon came up.
|
|
4513
4580
|
*/
|
|
4514
4581
|
function throughDaemon(client, again) {
|
|
4515
4582
|
const warned = warnVersion(client);
|
|
@@ -4528,13 +4595,13 @@ function throughDaemon(client, again) {
|
|
|
4528
4595
|
try {
|
|
4529
4596
|
return await first(m, p);
|
|
4530
4597
|
} catch (error) {
|
|
4531
|
-
const params = p ?? {};
|
|
4532
|
-
if (!again || aborted || !endedUnanswered(error) || !(
|
|
4598
|
+
const params = p ?? {}, read = readOnly(m, params) || READ_WAITS.has(m);
|
|
4599
|
+
if (!again || aborted || !endedUnanswered(error) || !(read || endedUnsent(error))) throw error;
|
|
4533
4600
|
next ??= again();
|
|
4534
4601
|
try {
|
|
4535
4602
|
return await (await next).call(m, READ_WAITS.has(m) ? waitLeft(m, params, performance.now() - from) : p);
|
|
4536
4603
|
} catch (failure) {
|
|
4537
|
-
if (endedUnanswered(failure) && !isNotTheDaemon(failure)) throw new CliError("unavailable", `The daemon went away before it answered ${m}, twice; a read changes nothing: run it again`, { method: m });
|
|
4604
|
+
if (read && endedUnanswered(failure) && !isNotTheDaemon(failure)) throw new CliError("unavailable", `The daemon went away before it answered ${m}, twice; a read changes nothing: run it again`, { method: m });
|
|
4538
4605
|
throw failure;
|
|
4539
4606
|
}
|
|
4540
4607
|
}
|
|
@@ -4562,29 +4629,54 @@ var HOLDER_WAIT_MS = 5e3;
|
|
|
4562
4629
|
/** How long it waits for the profile's daemon that is starting (`startingDaemon`): its engine takes seconds on a large profile. */
|
|
4563
4630
|
var STARTING_WAIT_MS = 3e4;
|
|
4564
4631
|
/**
|
|
4632
|
+
* The longest a one-shot waits for the profile in all, while it passes from one process to the next (each holder is
|
|
4633
|
+
* waited for on its own, above): commands that keep taking it in turn do not keep this one waiting for ever.
|
|
4634
|
+
*/
|
|
4635
|
+
var TURNS_WAIT_MS = 6e4;
|
|
4636
|
+
/**
|
|
4565
4637
|
* Opens the profile in this process for a one-shot command. Another one that holds it (a script's `&`, a second
|
|
4566
4638
|
* terminal) is waited for: both used to fail at once, and a backgrounded send was lost unless the script checked its
|
|
4567
|
-
* exit code. One still holding it after HOLDER_WAIT_MS is answered with the next step.
|
|
4568
|
-
*
|
|
4639
|
+
* exit code. One still holding it after HOLDER_WAIT_MS is answered with the next step. Each process that takes the
|
|
4640
|
+
* profile in turn is waited for that long of its own, up to TURNS_WAIT_MS in all: counted from the first look, the
|
|
4641
|
+
* wait failed busy while the profile was only passing from one process to the next (the last of six reads started at
|
|
4642
|
+
* once, behind five others that each held it for a second on a busy machine). A daemon takes the profile before its
|
|
4643
|
+
* socket listens (its engine starts in between, seconds on a large profile): once one answers there, the command
|
|
4569
4644
|
* goes through it, its client the answer. Only the lock was looked at again, and a command run while the daemon started
|
|
4570
4645
|
* failed busy, told to start the daemon that was running. A daemon that marked its start is waited for up to
|
|
4571
|
-
* STARTING_WAIT_MS, and named as the holder.
|
|
4646
|
+
* STARTING_WAIT_MS, and named as the holder. So is a profile a `daemon restart` or `daemon --detach` keeps for the daemon
|
|
4647
|
+
* it starts (`daemonClaim`): the commands that took the profile in turn in the gap kept that daemon from ever starting.
|
|
4648
|
+
* A `listen` with no daemon opens it the same way, as the daemon (`mode`). A wait that goes on past WAIT_NOTICE_MS says
|
|
4649
|
+
* 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).
|
|
4572
4650
|
*/
|
|
4573
4651
|
async function openOneShot(g, options = {}, mode = "one-shot") {
|
|
4574
4652
|
const { openHost } = await engineHost();
|
|
4575
4653
|
const from = performance.now();
|
|
4654
|
+
let holder, since = from, told;
|
|
4576
4655
|
for (;;) try {
|
|
4577
4656
|
return await openHost(g.paths, mode, VERSION, options);
|
|
4578
4657
|
} catch (error) {
|
|
4579
4658
|
if (!(error instanceof CliError) || error.code !== "busy") throw error;
|
|
4580
|
-
const starting = startingDaemon(g.paths);
|
|
4659
|
+
const starting = startingDaemon(g.paths), claimed = starting === null ? daemonClaim(g.paths) : null;
|
|
4581
4660
|
const client = await connectDaemon(g.paths);
|
|
4582
4661
|
if (client) return client;
|
|
4583
|
-
const
|
|
4662
|
+
const pid = error.details?.pid;
|
|
4663
|
+
if (pid !== holder) {
|
|
4664
|
+
holder = pid;
|
|
4665
|
+
since = performance.now();
|
|
4666
|
+
}
|
|
4667
|
+
const now = performance.now();
|
|
4668
|
+
const left = Math.min(since + (starting === null && claimed === null ? HOLDER_WAIT_MS : STARTING_WAIT_MS), from + TURNS_WAIT_MS) - now;
|
|
4584
4669
|
if (left <= 0) {
|
|
4585
|
-
if (
|
|
4586
|
-
|
|
4587
|
-
|
|
4670
|
+
if (claimed !== null) throw new CliError("busy", `Profile ${g.profile} is kept for the daemon that process ${claimed} (ghostly daemon) starts, still not up after ${Math.round((now - since) / 1e3)} s: ghostly daemon status shows when it is up`, { pid: claimed });
|
|
4671
|
+
if (starting !== null) throw new CliError("busy", `Profile ${g.profile} is in use by its daemon (process ${starting}), which was still starting after ${Math.round((now - since) / 1e3)} s: ghostly daemon status shows when it is up`, { pid: starting });
|
|
4672
|
+
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`;
|
|
4673
|
+
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);
|
|
4674
|
+
}
|
|
4675
|
+
const kind = claimed !== null ? "claimed" : starting !== null ? "starting" : "command";
|
|
4676
|
+
if (process.stderr.isTTY && now - from >= 1e3 && told !== kind) {
|
|
4677
|
+
told = kind;
|
|
4678
|
+
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`;
|
|
4679
|
+
process.stderr.write(`ghostly: ${line}; Ctrl-C stops waiting)\n`);
|
|
4588
4680
|
}
|
|
4589
4681
|
await new Promise((resolve) => setTimeout(resolve, Math.min(50 + Math.random() * 50, left)));
|
|
4590
4682
|
}
|
|
@@ -4798,7 +4890,7 @@ var SPECIAL = [
|
|
|
4798
4890
|
from: o("list", "Only this chat's events (id, a label given here or the contact's key; again for more)"),
|
|
4799
4891
|
group: o("list", "Only this group's events (again for more); with --from or --group, nobody else's event gets through"),
|
|
4800
4892
|
exec: o("string", "Run this command per event, the event as JSON on stdin"),
|
|
4801
|
-
webhook: o("string", "POST each event to this URL"),
|
|
4893
|
+
webhook: o("string", "POST each event to this URL (else GHOSTLY_WEBHOOK, which ps does not show)"),
|
|
4802
4894
|
print: o("boolean", "Print events too when --exec or --webhook handles them"),
|
|
4803
4895
|
translate
|
|
4804
4896
|
}
|
|
@@ -4810,7 +4902,7 @@ var SPECIAL = [
|
|
|
4810
4902
|
],
|
|
4811
4903
|
[
|
|
4812
4904
|
"settings set <key> <json-value> [--force]",
|
|
4813
|
-
"Change one: relays, irohRelays, hyperdhtRelay, iceServers, publicProfiles, online, shareProfile, sendTyping, autoDownloads, serveFiles, nick. <json-value> - (or none, piped) reads it from stdin: a TURN password stays out of ps",
|
|
4905
|
+
"Change one: relays, irohRelays, hyperdhtRelay, iceServers, publicProfiles, online, shareProfile, sendTyping, autoDownloads, serveFiles, daemonPresence, nick. daemonPresence true: contacts see this profile online while a daemon runs it (off by default). <json-value> - (or none, piped) reads it from stdin: a TURN password stays out of ps",
|
|
4814
4906
|
{ force: o("boolean", "Set a nick even if it looks like a seed, a key or ecash") }
|
|
4815
4907
|
],
|
|
4816
4908
|
[
|
|
@@ -4820,7 +4912,7 @@ var SPECIAL = [
|
|
|
4820
4912
|
"confirm-real": o("boolean", "Confirm a Mainnet (real money) spend"),
|
|
4821
4913
|
"show-secret": o("boolean", "Print a call's secrets"),
|
|
4822
4914
|
yes: o("boolean", "Confirm a call that deletes chats or groups"),
|
|
4823
|
-
force: o("boolean", "Send a text that looks like a secret")
|
|
4915
|
+
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")
|
|
4824
4916
|
}
|
|
4825
4917
|
],
|
|
4826
4918
|
[
|
|
@@ -4968,6 +5060,18 @@ function commandWords(usage) {
|
|
|
4968
5060
|
return words;
|
|
4969
5061
|
}
|
|
4970
5062
|
/**
|
|
5063
|
+
* A command that takes no argument and is also a group (`status`, with `status set`; `daemon`, with `daemon stop`): a
|
|
5064
|
+
* word after it that names none of its commands is a typo of one (`status shwo`). Before, the line said "Too many
|
|
5065
|
+
* arguments: ghostly status" and `help status shwo` answered status's help with exit 0.
|
|
5066
|
+
*/
|
|
5067
|
+
function groupWithNoArguments(usage) {
|
|
5068
|
+
const words = commandWords(usage);
|
|
5069
|
+
return !usage.split(" ").slice(words.length).some((word) => /^[<[](?!-)/.test(word)) && helpRows().some((row) => {
|
|
5070
|
+
const own = commandWords(row.usage);
|
|
5071
|
+
return own.length > words.length && words.every((word, i) => own[i] === word);
|
|
5072
|
+
});
|
|
5073
|
+
}
|
|
5074
|
+
/**
|
|
4971
5075
|
* Help for one command (`ghostly help file send`, `ghostly file send --help`): its usage, what it does and its
|
|
4972
5076
|
* options; for a group (`ghostly help file`), the group's commands.
|
|
4973
5077
|
*/
|
|
@@ -4984,7 +5088,7 @@ function commandHelp(words) {
|
|
|
4984
5088
|
const asked = words.join(" ");
|
|
4985
5089
|
if (!rows.length) throw unknownCommand(given[0], given[1], given[2]);
|
|
4986
5090
|
const exact = rows.filter((row) => commandWords(row.usage).join(" ") === asked);
|
|
4987
|
-
if (
|
|
5091
|
+
if (words.length < given.length && (!exact.length || exact.every((row) => groupWithNoArguments(row.usage)))) throw unknownCommand(given[0], given[1], given[2]);
|
|
4988
5092
|
const lines = [];
|
|
4989
5093
|
for (const row of exact) {
|
|
4990
5094
|
lines.push(...columns === void 0 ? [`Usage: ghostly ${row.usage}`] : wrap("Usage: ghostly ", row.usage, columns, 4), "", ...paragraph([` ${row.summary}`], columns));
|
|
@@ -5129,7 +5233,10 @@ async function profileCommand(sub, argv) {
|
|
|
5129
5233
|
}
|
|
5130
5234
|
case "show":
|
|
5131
5235
|
noMoreThan(0, parsed.positionals, "profile show");
|
|
5132
|
-
print(await withSession(g, (s) => s.call("profile.get"), {
|
|
5236
|
+
print(await withSession(g, (s) => s.call("profile.get"), {
|
|
5237
|
+
offline: true,
|
|
5238
|
+
deferChats: readsNoHistory("profile.get")
|
|
5239
|
+
}));
|
|
5133
5240
|
return;
|
|
5134
5241
|
case "set": {
|
|
5135
5242
|
noMoreThan(0, parsed.positionals, "profile set [--name <name>] [--share-profile | --no-share-profile] [--force]");
|
|
@@ -5152,7 +5259,7 @@ async function profileCommand(sub, argv) {
|
|
|
5152
5259
|
if (parsed.options.passphrase === true) throw new CliError("usage", "The passphrase comes from --passphrase-file or GHOSTLY_BACKUP_PASSPHRASE, never the command line");
|
|
5153
5260
|
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");
|
|
5154
5261
|
const light = parsed.options.light === true ? { light: true } : {};
|
|
5155
|
-
const
|
|
5262
|
+
const resolved = here(out), path = (out.endsWith("/") || out.endsWith(sep)) && !resolved.endsWith(sep) ? `${resolved}${sep}` : resolved;
|
|
5156
5263
|
const params = unsealed ? {
|
|
5157
5264
|
path,
|
|
5158
5265
|
noPassphrase: true,
|
|
@@ -5172,14 +5279,15 @@ async function profileCommand(sub, argv) {
|
|
|
5172
5279
|
if (!given || !name) throw new CliError("usage", `Missing <${given ? "new profile" : "file"}>: ghostly profile restore <file> <new profile> [--passphrase-file f] [--use]`);
|
|
5173
5280
|
noMoreThan(2, parsed.positionals, "profile restore <file> <new profile> [--passphrase-file f] [--use]");
|
|
5174
5281
|
const file = here(given);
|
|
5175
|
-
const { backupFileProtection, restoreProfile } = await import("./backup-
|
|
5282
|
+
const { backupFileProtection, restoreProfile } = await import("./backup-CgWU7x0T.js");
|
|
5176
5283
|
const protection = await backupFileProtection(file);
|
|
5177
5284
|
const paths = await restoreProfile(g.home, checkProfileName(name), file, protection === "none" ? void 0 : backupPassphrase(parsed.options["passphrase-file"], RESTORE_PASSPHRASE));
|
|
5178
5285
|
if (parsed.options.use) selectProfile(g.home, name);
|
|
5179
5286
|
print({
|
|
5180
5287
|
restored: name,
|
|
5181
5288
|
folder: paths.dir,
|
|
5182
|
-
protection
|
|
5289
|
+
protection,
|
|
5290
|
+
current: currentProfile(g.home) === name
|
|
5183
5291
|
});
|
|
5184
5292
|
return;
|
|
5185
5293
|
}
|
|
@@ -5359,32 +5467,14 @@ async function daemonCommand(argv) {
|
|
|
5359
5467
|
}
|
|
5360
5468
|
if (sub === "restart") {
|
|
5361
5469
|
const stopFor = seconds(parsed, 20), startFor = seconds(parsed, 60);
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
const
|
|
5365
|
-
const stopped = ended?.pid ?? null;
|
|
5366
|
-
if (ended?.listen) process.stderr.write(listenEnded(ended.pid));
|
|
5367
|
-
const before = (await probe)?.version ?? null;
|
|
5368
|
-
let started;
|
|
5470
|
+
requireProfile(g);
|
|
5471
|
+
ownProfile(g.paths.dir);
|
|
5472
|
+
const unclaim = claimForDaemon(g.paths);
|
|
5369
5473
|
try {
|
|
5370
|
-
|
|
5371
|
-
}
|
|
5372
|
-
|
|
5373
|
-
throw new CliError(error.code, `${error.message}. The daemon (process ${stopped}) was stopped: start it again with ghostly daemon --detach`, {
|
|
5374
|
-
...error.details,
|
|
5375
|
-
stopped
|
|
5376
|
-
});
|
|
5474
|
+
await restartDaemon(g, stopFor, startFor);
|
|
5475
|
+
} finally {
|
|
5476
|
+
unclaim();
|
|
5377
5477
|
}
|
|
5378
|
-
const older = restartWarning(before, VERSION);
|
|
5379
|
-
if (older) process.stderr.write(older + "\n");
|
|
5380
|
-
print({
|
|
5381
|
-
restarted: true,
|
|
5382
|
-
stopped,
|
|
5383
|
-
...ended?.listen && { listen: true },
|
|
5384
|
-
before,
|
|
5385
|
-
version: VERSION,
|
|
5386
|
-
...started
|
|
5387
|
-
});
|
|
5388
5478
|
return;
|
|
5389
5479
|
}
|
|
5390
5480
|
if (sub) throw unknownCommand("daemon", sub);
|
|
@@ -5395,6 +5485,35 @@ async function daemonCommand(argv) {
|
|
|
5395
5485
|
}
|
|
5396
5486
|
print(await startDetached(g, startFor));
|
|
5397
5487
|
}
|
|
5488
|
+
/** `daemon restart`, while the profile is kept for the daemon it starts. */
|
|
5489
|
+
async function restartDaemon(g, stopFor, startFor) {
|
|
5490
|
+
const client = await connectDaemon(g.paths) ?? await startedDaemon(g, stopFor);
|
|
5491
|
+
const probe = client ? client.call("status").catch(() => null) : null;
|
|
5492
|
+
const ended = client ? await stopDaemon(g, client, stopFor) : null;
|
|
5493
|
+
const stopped = ended?.pid ?? null;
|
|
5494
|
+
if (ended?.listen) process.stderr.write(listenEnded(ended.pid));
|
|
5495
|
+
const before = (await probe)?.version ?? null;
|
|
5496
|
+
let started;
|
|
5497
|
+
try {
|
|
5498
|
+
started = await startDetached(g, startFor);
|
|
5499
|
+
} catch (error) {
|
|
5500
|
+
if (stopped === null || !(error instanceof CliError) || error.code === "timeout") throw error;
|
|
5501
|
+
throw new CliError(error.code, `${error.message}. The daemon (process ${stopped}) was stopped: start it again with ghostly daemon --detach`, {
|
|
5502
|
+
...error.details,
|
|
5503
|
+
stopped
|
|
5504
|
+
});
|
|
5505
|
+
}
|
|
5506
|
+
const older = restartWarning(before, VERSION);
|
|
5507
|
+
if (older) process.stderr.write(older + "\n");
|
|
5508
|
+
print({
|
|
5509
|
+
restarted: true,
|
|
5510
|
+
stopped,
|
|
5511
|
+
...ended?.listen && { listen: true },
|
|
5512
|
+
before,
|
|
5513
|
+
version: VERSION,
|
|
5514
|
+
...started
|
|
5515
|
+
});
|
|
5516
|
+
}
|
|
5398
5517
|
/**
|
|
5399
5518
|
* The profile's daemon that is starting (`startingDaemon`: it holds the profile, its socket does not listen yet), once
|
|
5400
5519
|
* its socket answers, waited for up to `seconds`; null when none is starting. One still starting then is the answer,
|
|
@@ -5498,18 +5617,23 @@ function processAlive(pid) {
|
|
|
5498
5617
|
async function startDetached(g, seconds) {
|
|
5499
5618
|
requireProfile(g);
|
|
5500
5619
|
ownProfile(g.paths.dir);
|
|
5501
|
-
const
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
if (
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5620
|
+
const unclaim = claimForDaemon(g.paths);
|
|
5621
|
+
try {
|
|
5622
|
+
const until = performance.now() + seconds * 1e3;
|
|
5623
|
+
for (;;) {
|
|
5624
|
+
if (await connectDaemon(g.paths)) throw new CliError("busy", `A daemon already runs profile ${g.profile}`);
|
|
5625
|
+
if (lockOwner(g.paths) === null) {
|
|
5626
|
+
const started = await spawnDaemon(g, until);
|
|
5627
|
+
if (started) return started;
|
|
5628
|
+
}
|
|
5629
|
+
if (performance.now() >= until) {
|
|
5630
|
+
heldBy(g);
|
|
5631
|
+
throw new CliError("engine", `The daemon did not start; see ${g.paths.log}`);
|
|
5632
|
+
}
|
|
5633
|
+
await new Promise((resolve) => setTimeout(resolve, Math.max(0, Math.min(100, until - performance.now()))));
|
|
5511
5634
|
}
|
|
5512
|
-
|
|
5635
|
+
} finally {
|
|
5636
|
+
unclaim();
|
|
5513
5637
|
}
|
|
5514
5638
|
}
|
|
5515
5639
|
/** `startDetached`'s child, or null when another process took the profile ahead of it and there is time to try again. */
|
|
@@ -5661,13 +5785,21 @@ async function listenCommand(argv) {
|
|
|
5661
5785
|
noMoreThan(0, parsed.positionals, SPECIAL.find(([usage]) => usage.startsWith("listen "))[0]);
|
|
5662
5786
|
const blank = (value) => typeof value === "string" && value.trim() === "";
|
|
5663
5787
|
if (blank(parsed.options.webhook)) throw new CliError("usage", "--webhook needs a URL");
|
|
5788
|
+
const envWebhook = process.env.GHOSTLY_WEBHOOK;
|
|
5789
|
+
delete process.env.GHOSTLY_WEBHOOK;
|
|
5790
|
+
if (envWebhook !== void 0 && parsed.options.webhook !== void 0) throw new CliError("usage", "A webhook is set in GHOSTLY_WEBHOOK and --webhook was given: choose one");
|
|
5791
|
+
if (blank(envWebhook)) throw new CliError("usage", "GHOSTLY_WEBHOOK is empty: it holds the webhook's URL");
|
|
5792
|
+
const webhook = parsed.options.webhook ?? envWebhook;
|
|
5664
5793
|
if (blank(parsed.options.exec)) throw new CliError("usage", "--exec needs a command");
|
|
5665
5794
|
if (parsed.options.cursor === "") throw new CliError("usage", "--cursor needs a file");
|
|
5666
5795
|
if (parsed.options.from?.some(blank)) throw new CliError("usage", "--from needs a chat or a contact key");
|
|
5667
5796
|
if (parsed.options.group?.some(blank)) throw new CliError("usage", "--group needs a group");
|
|
5668
5797
|
const g = globals(parsed);
|
|
5669
5798
|
pretty = false;
|
|
5670
|
-
if (
|
|
5799
|
+
if (webhook !== void 0) {
|
|
5800
|
+
const url = checkWebhook(webhook, envWebhook !== void 0 ? "GHOSTLY_WEBHOOK" : "--webhook");
|
|
5801
|
+
if (envWebhook === void 0 && (url.search || url.pathname !== "/")) process.stderr.write("ghostly: --webhook's URL shows in ps to every account on this machine while listen runs, a token in it too: give it in GHOSTLY_WEBHOOK instead\n");
|
|
5802
|
+
}
|
|
5671
5803
|
const types = parsed.options.type ?? [];
|
|
5672
5804
|
const turns = parsed.options.turns === true;
|
|
5673
5805
|
if (turns && types.length) throw new CliError("usage", "--turns takes the place of --type: a turn is a message received, or a group message that mentions you");
|
|
@@ -5692,10 +5824,10 @@ async function listenCommand(argv) {
|
|
|
5692
5824
|
turns,
|
|
5693
5825
|
translate: translator?.event,
|
|
5694
5826
|
exec: parsed.options.exec,
|
|
5695
|
-
webhook
|
|
5827
|
+
webhook,
|
|
5696
5828
|
cursor,
|
|
5697
5829
|
cursorFailed,
|
|
5698
|
-
print: parsed.options.print === true || !parsed.options.exec && !
|
|
5830
|
+
print: parsed.options.print === true || !parsed.options.exec && !webhook,
|
|
5699
5831
|
write: (line) => process.stdout.write(line + "\n"),
|
|
5700
5832
|
drained: () => new Promise((resolve) => {
|
|
5701
5833
|
const done = () => {
|
|
@@ -5737,8 +5869,7 @@ async function listenCommand(argv) {
|
|
|
5737
5869
|
};
|
|
5738
5870
|
onReaderGone(stop);
|
|
5739
5871
|
await following.subscribed;
|
|
5740
|
-
|
|
5741
|
-
process.on("SIGTERM", stop);
|
|
5872
|
+
onStopSignals(stop);
|
|
5742
5873
|
return;
|
|
5743
5874
|
}
|
|
5744
5875
|
const [{ keepServing, serve }, { callApi }] = await Promise.all([engineHost(), engineApi()]);
|
|
@@ -5884,7 +6015,10 @@ async function settingsCommand(sub, argv) {
|
|
|
5884
6015
|
pretty = g.pretty;
|
|
5885
6016
|
if (sub === "get") {
|
|
5886
6017
|
noMoreThan(0, parsed.positionals, "settings get [--show-secret]");
|
|
5887
|
-
print(await withSession(g, (s) => s.call("settings.get", { showSecret: parsed.options["show-secret"] === true }), {
|
|
6018
|
+
print(await withSession(g, (s) => s.call("settings.get", { showSecret: parsed.options["show-secret"] === true }), {
|
|
6019
|
+
offline: true,
|
|
6020
|
+
deferChats: readsNoHistory("settings.get")
|
|
6021
|
+
}));
|
|
5888
6022
|
return;
|
|
5889
6023
|
}
|
|
5890
6024
|
if (sub === "set") {
|
|
@@ -5938,14 +6072,14 @@ async function textCommand(name, argv) {
|
|
|
5938
6072
|
};
|
|
5939
6073
|
if (spec.target === "group") params.mentions = parsed.options.mention ?? [];
|
|
5940
6074
|
if (parsed.options.reply !== void 0) params.reply = parsed.options.reply;
|
|
5941
|
-
if (!spec.message) Object.assign(params, (await import("./buttons-
|
|
6075
|
+
if (!spec.message) Object.assign(params, (await import("./buttons-Cco0Agfa.js")).buttonsOf(parsed.options));
|
|
5942
6076
|
print(await withSession(g, (s) => {
|
|
5943
6077
|
if (parsed.options.wait !== void 0) params.wait = parsed.options.wait;
|
|
5944
6078
|
if (parsed.options.timeout !== void 0) params.timeout = parsed.options.timeout;
|
|
5945
6079
|
return s.call(spec.method, params);
|
|
5946
6080
|
}, {
|
|
5947
6081
|
deferGroups: spec.target === "chat",
|
|
5948
|
-
deferChats: spec.target === "chat"
|
|
6082
|
+
deferChats: spec.target === "chat" || oneGroupOnly(spec.method)
|
|
5949
6083
|
}));
|
|
5950
6084
|
}
|
|
5951
6085
|
/**
|
|
@@ -5982,7 +6116,7 @@ async function identityAddCommand(argv) {
|
|
|
5982
6116
|
if (!provider) throw new CliError("usage", "Missing <provider>: ghostly identity add <provider> [subject] [--signer id] [--field name=value]... [--stdin] [--days n] [--timeout s]");
|
|
5983
6117
|
inRange(parsed.options, "timeout", "a number of seconds", 5, 3600);
|
|
5984
6118
|
const items = parsed.options.field ?? [];
|
|
5985
|
-
const known = parsed.options.days !== void 0 || items.length ? (await import("./registry-
|
|
6119
|
+
const known = parsed.options.days !== void 0 || items.length ? (await import("./registry-CE0PpQAE.js")).IDENTITY_PROVIDERS.find((p) => p.id === provider) : void 0;
|
|
5986
6120
|
if (known && parsed.options.days !== void 0) inRange(parsed.options, "days", "a whole number", 1, known.validity.maxDays, true);
|
|
5987
6121
|
const { fields, warning } = await identityFields(items, parsed.options.stdin === true, identitySecretFields(known, parsed.options.signer), readStdin, process.stdin.isTTY === true);
|
|
5988
6122
|
if (warning) process.stderr.write(`ghostly: ${warning}\n`);
|
|
@@ -6088,12 +6222,12 @@ async function tableCommand(name, argv) {
|
|
|
6088
6222
|
return result;
|
|
6089
6223
|
}, {
|
|
6090
6224
|
deferGroups: chatOnly(command.method, params) || newChatOnly(command.method),
|
|
6091
|
-
deferChats: oneChatOnly(command.method, params),
|
|
6225
|
+
deferChats: oneChatOnly(command.method, params) || oneGroupOnly(command.method) || readsNoHistory(command.method),
|
|
6092
6226
|
offline: offlineCall(command.method, params)
|
|
6093
6227
|
});
|
|
6094
6228
|
if (translator) {
|
|
6095
6229
|
try {
|
|
6096
|
-
printAnswer(await (await import("./translate-
|
|
6230
|
+
printAnswer(await (await import("./translate-iQZq4TnY.js")).translateAnswer(result, translator));
|
|
6097
6231
|
} finally {
|
|
6098
6232
|
translator.close();
|
|
6099
6233
|
}
|
|
@@ -6246,6 +6380,7 @@ async function main(input) {
|
|
|
6246
6380
|
await textCommand(first, argv.slice(1));
|
|
6247
6381
|
return 0;
|
|
6248
6382
|
}
|
|
6383
|
+
if (table(first) && two && groupWithNoArguments(COMMANDS[first].usage)) throw unknownCommand(first, second);
|
|
6249
6384
|
if (table(first)) {
|
|
6250
6385
|
await tableCommand(first, argv.slice(1));
|
|
6251
6386
|
return 0;
|
|
@@ -6319,4 +6454,4 @@ async function run(argv) {
|
|
|
6319
6454
|
//#endregion
|
|
6320
6455
|
export { run };
|
|
6321
6456
|
|
|
6322
|
-
//# sourceMappingURL=main-
|
|
6457
|
+
//# sourceMappingURL=main-C0PfjKTe.js.map
|