@ghostlytools/cli 1.5.2 → 1.5.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 +16 -11
- package/dist/assets/{api-CHD8_kcJ.js → api-BIg0Msax.js} +2 -2
- package/dist/assets/{api-CMohP9Pw.js → api-d2aXkbM5.js} +341 -114
- package/dist/assets/api-d2aXkbM5.js.map +1 -0
- package/dist/assets/{apiKit-CfwVtBcw.js → apiKit-Ba_t7MZO.js} +4 -4
- package/dist/assets/apiKit-Ba_t7MZO.js.map +1 -0
- package/dist/assets/{apps-733nXRBy.js → apps-B_F3gEI4.js} +1 -1
- package/dist/assets/{apps-LG-QOIxs.js → apps-CJo1MmSY.js} +17 -16
- package/dist/assets/apps-CJo1MmSY.js.map +1 -0
- package/dist/assets/{arkade-C8x3Efyj.js → arkade-DTne0O3Q.js} +12 -5
- package/dist/assets/arkade-DTne0O3Q.js.map +1 -0
- package/dist/assets/{backup-CfJenOQo.js → backup-BY88aZr5.js} +11 -8
- package/dist/assets/backup-BY88aZr5.js.map +1 -0
- package/dist/assets/{backup-nCbNWJ7-.js → backup-CqpDAZZG.js} +1 -1
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/{blobFiles-1wUBd8ZD.js → blobFiles-B1lX6iGy.js} +3 -3
- package/dist/assets/{blobFiles-1wUBd8ZD.js.map → blobFiles-B1lX6iGy.js.map} +1 -1
- package/dist/assets/{buttons-BC0stvPg.js → buttons-B5EnA2nh.js} +23 -6
- package/dist/assets/buttons-B5EnA2nh.js.map +1 -0
- package/dist/assets/buttons-azvbN6xn.js +2 -0
- package/dist/assets/{daemonProof-CWTVNUmr.js → daemonProof-Dx3N_DLC.js} +19 -37
- package/dist/assets/daemonProof-Dx3N_DLC.js.map +1 -0
- package/dist/assets/{endpoint-Cl3cgAYl.js → endpoint-BdaeBw2L.js} +3 -3
- package/dist/assets/endpoint-BdaeBw2L.js.map +1 -0
- package/dist/assets/{envelope-BbvUBjc5.js → envelope-BU-BB1wR.js} +2 -2
- package/dist/assets/{envelope-BbvUBjc5.js.map → envelope-BU-BB1wR.js.map} +1 -1
- package/dist/assets/{errors-BLSPp0tK.js → errors-DI6Z3jTH.js} +26 -1
- package/dist/assets/errors-DI6Z3jTH.js.map +1 -0
- package/dist/assets/{fileBytes-gTd_8l-P.js → fileBytes-BMlLVdfg.js} +1 -1
- package/dist/assets/{fileBytes-uRqLyxa0.js → fileBytes-D0CYuRwZ.js} +2 -2
- package/dist/assets/{fileBytes-uRqLyxa0.js.map → fileBytes-D0CYuRwZ.js.map} +1 -1
- package/dist/assets/{fileBytes-B8eTZfAT.js → fileBytes-D85lBh-Q.js} +3 -3
- package/dist/assets/{fileBytes-B8eTZfAT.js.map → fileBytes-D85lBh-Q.js.map} +1 -1
- package/dist/assets/fileBytesIdb-Dn9levD1.js +2 -0
- package/dist/assets/{fileBytesIdb-BIFKtgln.js → fileBytesIdb-LAhH7kY2.js} +7 -7
- package/dist/assets/fileBytesIdb-LAhH7kY2.js.map +1 -0
- package/dist/assets/{fileBytesOpfs-ChrHcCVV.js → fileBytesOpfs-DjBBghvq.js} +3 -3
- package/dist/assets/{fileBytesOpfs-ChrHcCVV.js.map → fileBytesOpfs-DjBBghvq.js.map} +1 -1
- package/dist/assets/{ghostly_iroh_web-BsAEFIjl.js → ghostly_iroh_web-BXCsSxxo.js} +29 -29
- package/dist/assets/{ghostly_iroh_web-BsAEFIjl.js.map → ghostly_iroh_web-BXCsSxxo.js.map} +1 -1
- package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
- package/dist/assets/{groupFiles-Bmo-SkVQ.js → groupFiles-D9k6fyhf.js} +61 -17
- package/dist/assets/groupFiles-D9k6fyhf.js.map +1 -0
- package/dist/assets/{host-DxDRCRKD.js → host-DrL7FPG4.js} +125 -47
- package/dist/assets/host-DrL7FPG4.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CZfsPfT9.js → hyperdhtRelay-C-BsT6_V.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CZfsPfT9.js.map → hyperdhtRelay-C-BsT6_V.js.map} +1 -1
- package/dist/assets/{idb-BJARz3Qi.js → idb-CWvq4HKc.js} +25 -3
- package/dist/assets/{idb-BJARz3Qi.js.map → idb-CWvq4HKc.js.map} +1 -1
- package/dist/assets/{irohWeb-BUvaADop.js → irohWeb-DdHXEwgj.js} +3 -3
- package/dist/assets/{irohWeb-BUvaADop.js.map → irohWeb-DdHXEwgj.js.map} +1 -1
- package/dist/assets/{main-BIXIs84L.js → main-xeoX7yLM.js} +160 -50
- package/dist/assets/main-xeoX7yLM.js.map +1 -0
- package/dist/assets/{mainline-HQVJ5ukA.js → mainline-CEqGvRYJ.js} +46 -16
- package/dist/assets/mainline-CEqGvRYJ.js.map +1 -0
- package/dist/assets/{networkReason-CKBiFTwt.js → networkReason-RGRU5xoa.js} +3 -3
- package/dist/assets/{networkReason-CKBiFTwt.js.map → networkReason-RGRU5xoa.js.map} +1 -1
- package/dist/assets/{nwc-Dm4RSvvF.js → nwc-s5xHLqNf.js} +3 -3
- package/dist/assets/{nwc-Dm4RSvvF.js.map → nwc-s5xHLqNf.js.map} +1 -1
- package/dist/assets/{nwcProvider-yQdL-DfC.js → nwcProvider-CfAFO5Fr.js} +2 -2
- package/dist/assets/{nwcProvider-yQdL-DfC.js.map → nwcProvider-CfAFO5Fr.js.map} +1 -1
- package/dist/assets/{profiles-BehWURA9.js → profiles-gZdQPyaz.js} +74 -13
- package/dist/assets/profiles-gZdQPyaz.js.map +1 -0
- package/dist/assets/{registry-CHVZ0Jzl.js → registry-BUhSjM-J.js} +1 -1
- package/dist/assets/{registry-C9f2Ogff.js → registry-CVUdD4bJ.js} +3 -3
- package/dist/assets/{registry-C9f2Ogff.js.map → registry-CVUdD4bJ.js.map} +1 -1
- package/dist/assets/{resolve-Cqj1jjK2.js → resolve-uZECJ3f7.js} +2 -2
- package/dist/assets/{resolve-Cqj1jjK2.js.map → resolve-uZECJ3f7.js.map} +1 -1
- package/dist/assets/{restoredRows-DGuKtIBz.js → restoredRows-D6WZUA2U.js} +2 -2
- package/dist/assets/{restoredRows-DGuKtIBz.js.map → restoredRows-D6WZUA2U.js.map} +1 -1
- package/dist/assets/{server-CcAs54Yb.js → server-DOtUKoYR.js} +776 -248
- package/dist/assets/server-DOtUKoYR.js.map +1 -0
- package/dist/assets/{src-BLHey3Q1.js → src-Dd_7Ew1X.js} +459 -129
- package/dist/assets/src-Dd_7Ew1X.js.map +1 -0
- package/dist/assets/{usdt-DMKpMhdM.js → usdt-C2Anx8p7.js} +3 -3
- package/dist/assets/{usdt-DMKpMhdM.js.map → usdt-C2Anx8p7.js.map} +1 -1
- package/dist/assets/{words-DUlvkoUT.js → words-DoLU6p8H.js} +4 -4
- package/dist/assets/words-DoLU6p8H.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-CMohP9Pw.js.map +0 -1
- package/dist/assets/apiKit-CfwVtBcw.js.map +0 -1
- package/dist/assets/apps-LG-QOIxs.js.map +0 -1
- package/dist/assets/arkade-C8x3Efyj.js.map +0 -1
- package/dist/assets/backup-CfJenOQo.js.map +0 -1
- package/dist/assets/buttons-BC0stvPg.js.map +0 -1
- package/dist/assets/buttons-BDKeKyKw.js +0 -2
- package/dist/assets/daemonProof-CWTVNUmr.js.map +0 -1
- package/dist/assets/endpoint-Cl3cgAYl.js.map +0 -1
- package/dist/assets/errors-BLSPp0tK.js.map +0 -1
- package/dist/assets/fileBytesIdb-BIFKtgln.js.map +0 -1
- package/dist/assets/fileBytesIdb-BVVr_rWX.js +0 -2
- package/dist/assets/groupFiles-Bmo-SkVQ.js.map +0 -1
- package/dist/assets/host-DxDRCRKD.js.map +0 -1
- package/dist/assets/main-BIXIs84L.js.map +0 -1
- package/dist/assets/mainline-HQVJ5ukA.js.map +0 -1
- package/dist/assets/profiles-BehWURA9.js.map +0 -1
- package/dist/assets/server-CcAs54Yb.js.map +0 -1
- package/dist/assets/src-BLHey3Q1.js.map +0 -1
- package/dist/assets/words-DUlvkoUT.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
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, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-
|
|
3
|
-
import { i as localFileError, n as EXIT, r as asCliError, t as CliError } from "./errors-
|
|
4
|
-
import { t as CONTACT_KEY } from "./apiKit-
|
|
5
|
-
import { 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 {
|
|
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-Dd_7Ew1X.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-DoLU6p8H.js";
|
|
3
|
+
import { i as localFileError, n as EXIT, r as asCliError, t as CliError } from "./errors-DI6Z3jTH.js";
|
|
4
|
+
import { t as CONTACT_KEY } from "./apiKit-Ba_t7MZO.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-gZdQPyaz.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-Dx3N_DLC.js";
|
|
7
7
|
import { accessSync, constants, existsSync, openSync, readFileSync, 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.5.
|
|
15
|
+
version: "1.5.3",
|
|
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",
|
|
@@ -239,10 +239,13 @@ function liftGlobals(argv) {
|
|
|
239
239
|
/** The id of the hello on every connection: a string, so it is never one of the calls' numbers. */
|
|
240
240
|
var HELLO_ID = "hello";
|
|
241
241
|
/**
|
|
242
|
-
* How long a client waits for the daemon's greeting before it
|
|
243
|
-
* connection, and one of an older release (before the greeting) never does.
|
|
242
|
+
* How long a client waits for the daemon's greeting before it asks who holds the profile: a daemon greets as it
|
|
243
|
+
* accepts the connection, and one of an older release (before the greeting) never does. A daemon of this release
|
|
244
|
+
* holding the profile (`daemonOfThisRelease`) is busy and is waited for, under each call's own deadline; anything
|
|
245
|
+
* else is refused then. It used to refuse every late greeting, after 10 s: a daemon busy that long on one task (an
|
|
246
|
+
* outbox backlog, 14 to 29 s) had every command and `listen` refused as an older release's, to be restarted.
|
|
244
247
|
*/
|
|
245
|
-
var GREETING_MS =
|
|
248
|
+
var GREETING_MS = 2e3;
|
|
246
249
|
/** The refusal of a listener that did not prove it is the profile's daemon (`isNotTheDaemon` tells it apart). */
|
|
247
250
|
function notTheDaemon(socket) {
|
|
248
251
|
return new CliError("refused", `What answers on ${socket} did not prove it is this profile's daemon, so nothing was sent to it. A daemon of an older release cannot: \`ghostly daemon restart\` starts this one's`, { reason: "not-the-daemon" });
|
|
@@ -287,7 +290,7 @@ var DaemonClient = class {
|
|
|
287
290
|
this.ready.catch(() => {});
|
|
288
291
|
const nonce = newNonce();
|
|
289
292
|
const waitedTooLong = setTimeout(() => {
|
|
290
|
-
if (!this.greeted && !this.refusal) this.refuse();
|
|
293
|
+
if (!this.greeted && !this.refusal && !daemonOfThisRelease(this.address.dir)) this.refuse();
|
|
291
294
|
}, greetingMs);
|
|
292
295
|
waitedTooLong.unref?.();
|
|
293
296
|
const lines = createInterface({
|
|
@@ -300,6 +303,7 @@ var DaemonClient = class {
|
|
|
300
303
|
try {
|
|
301
304
|
message = JSON.parse(line);
|
|
302
305
|
} catch {
|
|
306
|
+
if (!this.greeted && !this.refusal) this.refuse();
|
|
303
307
|
return;
|
|
304
308
|
}
|
|
305
309
|
if (this.refusal) return;
|
|
@@ -1092,7 +1096,7 @@ var commands$8 = {
|
|
|
1092
1096
|
description: "Replace the three files when they are there"
|
|
1093
1097
|
}
|
|
1094
1098
|
},
|
|
1095
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1099
|
+
run: async ({ options }, a) => (await import("./apps-B_F3gEI4.js")).initApp(a.dir, {
|
|
1096
1100
|
name: options.name,
|
|
1097
1101
|
title: options.title,
|
|
1098
1102
|
force: options.force === true
|
|
@@ -1132,7 +1136,7 @@ var commands$8 = {
|
|
|
1132
1136
|
description: "This version's sequence, higher than the bundle at --out's (default: one more than it)"
|
|
1133
1137
|
}
|
|
1134
1138
|
},
|
|
1135
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1139
|
+
run: async ({ options }, a) => (await import("./apps-B_F3gEI4.js")).publishApp(a.dir, keyFile(options.key, "app publish <dir> --key <file> [--out <file>] [--sequence n]"), here(options.out), options.sequence)
|
|
1136
1140
|
},
|
|
1137
1141
|
"app revoke": {
|
|
1138
1142
|
method: "app.revoke",
|
|
@@ -1165,7 +1169,7 @@ var commands$8 = {
|
|
|
1165
1169
|
description: "Allow --up-to past the bundle's own sequence (versions published from elsewhere)"
|
|
1166
1170
|
}
|
|
1167
1171
|
},
|
|
1168
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1172
|
+
run: async ({ options }, a) => (await import("./apps-B_F3gEI4.js")).revokeApp(a.dir, keyFile(options.key, "app revoke <dir> --key <file> (--digest <digest>... | --up-to <sequence>) [--reason <text>]"), {
|
|
1169
1173
|
digests: options.digest,
|
|
1170
1174
|
upTo: options["up-to"],
|
|
1171
1175
|
reason: options.reason,
|
|
@@ -1226,7 +1230,7 @@ var commands$8 = {
|
|
|
1226
1230
|
usage: "app verify <bundle|url>",
|
|
1227
1231
|
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",
|
|
1228
1232
|
args: ["bundle"],
|
|
1229
|
-
run: async (_, a) => (await import("./apps-
|
|
1233
|
+
run: async (_, a) => (await import("./apps-B_F3gEI4.js")).verifyApp(a.bundle)
|
|
1230
1234
|
},
|
|
1231
1235
|
"store sign": {
|
|
1232
1236
|
method: "store.sign",
|
|
@@ -1243,7 +1247,7 @@ var commands$8 = {
|
|
|
1243
1247
|
description: "The folder to write ghostly-store.json and ghostly-store.sig in (default: the index's)"
|
|
1244
1248
|
}
|
|
1245
1249
|
},
|
|
1246
|
-
run: async ({ options }, a) => (await import("./apps-
|
|
1250
|
+
run: async ({ options }, a) => (await import("./apps-B_F3gEI4.js")).signStore(a.index, keyFile(options.key, "store sign <index> --key <file> [--out <dir>]"), here(options.out))
|
|
1247
1251
|
}
|
|
1248
1252
|
};
|
|
1249
1253
|
//#endregion
|
|
@@ -1278,7 +1282,7 @@ var commands$7 = {
|
|
|
1278
1282
|
options: {
|
|
1279
1283
|
from: {
|
|
1280
1284
|
type: "list",
|
|
1281
|
-
description: "Only calls from this chat (again for more)"
|
|
1285
|
+
description: "Only calls from this chat: its id, its contact's key or a label given here with chat rename (again for more)"
|
|
1282
1286
|
},
|
|
1283
1287
|
rate
|
|
1284
1288
|
},
|
|
@@ -1863,6 +1867,26 @@ var commands$6 = {
|
|
|
1863
1867
|
};
|
|
1864
1868
|
//#endregion
|
|
1865
1869
|
//#region src/commands/files.ts
|
|
1870
|
+
/**
|
|
1871
|
+
* `--voice [ms]` and `--peaks`: a length and a waveform a voice note takes, or a usage error (exit 2) that names the flag
|
|
1872
|
+
* before the profile opens. Before, the API answered them once it had opened ("voice must be a number from 1 to
|
|
1873
|
+
* 9007199254740991", or one sentence for every case), and `--peaks` without `--voice` was dropped without a word.
|
|
1874
|
+
*/
|
|
1875
|
+
function voiceOf(options) {
|
|
1876
|
+
const { voice, peaks } = options;
|
|
1877
|
+
if (typeof voice === "number" && !(Number.isInteger(voice) && voice >= 1 && voice <= VOICE_LIMITS.maxDurationMs)) throw new CliError("usage", `--voice takes a length in milliseconds from 1 to ${VOICE_LIMITS.maxDurationMs} (${VOICE_LIMITS.maxDurationMs / 6e4} minutes), not ${voice}`);
|
|
1878
|
+
if (typeof peaks !== "string") return {
|
|
1879
|
+
voice,
|
|
1880
|
+
peaks: void 0
|
|
1881
|
+
};
|
|
1882
|
+
if (voice === void 0) throw new CliError("usage", "--peaks is a voice note's waveform: not without --voice");
|
|
1883
|
+
const bars = peaks.split(",");
|
|
1884
|
+
if (bars.length > VOICE_LIMITS.maxBars || !bars.every((bar) => /^\d{1,3}$/.test(bar.trim()) && Number(bar) <= 255)) throw new CliError("usage", `--peaks takes up to ${VOICE_LIMITS.maxBars} numbers from 0 to 255, comma-separated, not ${JSON.stringify(peaks)}`);
|
|
1885
|
+
return {
|
|
1886
|
+
voice,
|
|
1887
|
+
peaks: bars
|
|
1888
|
+
};
|
|
1889
|
+
}
|
|
1866
1890
|
/** Files: one entry per command, in alphabetical order (test/commands.test.ts checks). */
|
|
1867
1891
|
var commands$5 = {
|
|
1868
1892
|
"file accept": {
|
|
@@ -2022,8 +2046,7 @@ var commands$5 = {
|
|
|
2022
2046
|
path: here(a.path),
|
|
2023
2047
|
name: options.name,
|
|
2024
2048
|
mime: options.mime,
|
|
2025
|
-
|
|
2026
|
-
peaks: typeof options.peaks === "string" ? options.peaks.split(",") : void 0,
|
|
2049
|
+
...voiceOf(options),
|
|
2027
2050
|
reply: options.reply
|
|
2028
2051
|
})
|
|
2029
2052
|
},
|
|
@@ -2590,6 +2613,7 @@ var commands$1 = {
|
|
|
2590
2613
|
memo,
|
|
2591
2614
|
method: {
|
|
2592
2615
|
type: "string",
|
|
2616
|
+
choices: PAY_METHODS,
|
|
2593
2617
|
description: "cashu, arkade, usdt, bitcoin, spark, …"
|
|
2594
2618
|
},
|
|
2595
2619
|
rail: {
|
|
@@ -3135,6 +3159,14 @@ function noMoreThan(count, values, usage) {
|
|
|
3135
3159
|
}
|
|
3136
3160
|
//#endregion
|
|
3137
3161
|
//#region src/listen.ts
|
|
3162
|
+
/** The cursor's own write failed, not the event's handling. */
|
|
3163
|
+
var CursorError = class extends Error {
|
|
3164
|
+
error;
|
|
3165
|
+
constructor(error) {
|
|
3166
|
+
super(error instanceof Error ? error.message : String(error));
|
|
3167
|
+
this.error = error;
|
|
3168
|
+
}
|
|
3169
|
+
};
|
|
3138
3170
|
/**
|
|
3139
3171
|
* Who `listen` passes on, checked before any hook or output: chats by id (a contact key is matched to its chat as
|
|
3140
3172
|
* events come, so a chat made after the start counts too), groups by id. An event of a chat or group not on it is
|
|
@@ -3241,6 +3273,7 @@ function checkWebhook(url) {
|
|
|
3241
3273
|
"localhost",
|
|
3242
3274
|
"[::1]"
|
|
3243
3275
|
].includes(parsed.hostname)) throw new CliError("usage", "The webhook must be on this machine (127.0.0.1, localhost or [::1])");
|
|
3276
|
+
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");
|
|
3244
3277
|
return parsed;
|
|
3245
3278
|
}
|
|
3246
3279
|
function readCursor(path) {
|
|
@@ -3446,13 +3479,22 @@ function eventHandler(options) {
|
|
|
3446
3479
|
const webhook = options.webhook ? checkWebhook(options.webhook) : null;
|
|
3447
3480
|
let chain = Promise.resolve();
|
|
3448
3481
|
let behind = 0;
|
|
3482
|
+
let stopped = false;
|
|
3483
|
+
const keep = (seq) => {
|
|
3484
|
+
if (!options.cursor) return;
|
|
3485
|
+
try {
|
|
3486
|
+
writeCursor(options.cursor, seq);
|
|
3487
|
+
} catch (error) {
|
|
3488
|
+
throw new CursorError(error);
|
|
3489
|
+
}
|
|
3490
|
+
};
|
|
3449
3491
|
const handle = (event) => {
|
|
3450
3492
|
const seq = event.seq, type = event.type;
|
|
3493
|
+
if (stopped) return;
|
|
3451
3494
|
behind++;
|
|
3452
3495
|
chain = chain.then(async () => {
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
};
|
|
3496
|
+
if (stopped) return;
|
|
3497
|
+
const skip = () => keep(event.seq);
|
|
3456
3498
|
if (!matches(event, options.types)) return skip();
|
|
3457
3499
|
if (options.allow && !await options.allow.allows(event)) return skip();
|
|
3458
3500
|
if (options.turns) {
|
|
@@ -3468,12 +3510,18 @@ function eventHandler(options) {
|
|
|
3468
3510
|
const answered = webhook ? await post(webhook, event, options.retryMs ?? 500) : true;
|
|
3469
3511
|
if (webhook && answered !== true) process.stderr.write(`ghostly: the webhook at ${webhook.href} answered ${answered}: event ${event.seq} (${event.type}) passed, not taken (a 4xx or a redirect is not tried again)\n`);
|
|
3470
3512
|
if (full) await options.drained?.();
|
|
3471
|
-
|
|
3513
|
+
keep(event.seq);
|
|
3472
3514
|
}).catch((error) => {
|
|
3473
3515
|
try {
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3516
|
+
if (!(error instanceof CursorError)) {
|
|
3517
|
+
process.stderr.write(`ghostly: event ${seq} (${type}) failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
3518
|
+
keep(seq);
|
|
3519
|
+
} else throw error;
|
|
3520
|
+
} catch (failed) {
|
|
3521
|
+
if (!(failed instanceof CursorError) || !options.cursorFailed) return;
|
|
3522
|
+
stopped = true;
|
|
3523
|
+
options.cursorFailed(failed.error);
|
|
3524
|
+
}
|
|
3477
3525
|
}).finally(() => {
|
|
3478
3526
|
behind--;
|
|
3479
3527
|
});
|
|
@@ -3530,9 +3578,11 @@ var PAUSE_HOLD_MS = 6e4;
|
|
|
3530
3578
|
* does, so the daemon does not keep a replay and what came live for it while it hangs; resume opens it again after the
|
|
3531
3579
|
* last event taken.
|
|
3532
3580
|
* `subscribed`: the first subscription's answer (a journal that cannot be replayed rejects it).
|
|
3581
|
+
* `profile`: a daemon gone longer than a restart takes (`daemon stop`) is said once on stderr, and so is the one that
|
|
3582
|
+
* answers again: the listen waits for it, it does not go silent.
|
|
3533
3583
|
*/
|
|
3534
|
-
function followDaemon(address, client, handle, since, holdMs = PAUSE_HOLD_MS) {
|
|
3535
|
-
let current = client;
|
|
3584
|
+
function followDaemon(address, client, handle, since, holdMs = PAUSE_HOLD_MS, profile) {
|
|
3585
|
+
let current = client, missedSince = 0, missing = false;
|
|
3536
3586
|
let holding;
|
|
3537
3587
|
const reconnect = (wait) => void (async () => {
|
|
3538
3588
|
while (!current && !feed.paused) {
|
|
@@ -3541,10 +3591,20 @@ function followDaemon(address, client, handle, since, holdMs = PAUSE_HOLD_MS) {
|
|
|
3541
3591
|
if (current || feed.paused) return;
|
|
3542
3592
|
const next = await connectDaemon(address, 1e3);
|
|
3543
3593
|
if (next) {
|
|
3594
|
+
missedSince = 0;
|
|
3595
|
+
if (missing) {
|
|
3596
|
+
missing = false;
|
|
3597
|
+
process.stderr.write(`ghostly: the daemon of profile ${profile} answers again\n`);
|
|
3598
|
+
}
|
|
3544
3599
|
current = next;
|
|
3545
3600
|
await follow(next).catch(() => {
|
|
3546
3601
|
if (current === next) current = null;
|
|
3547
3602
|
});
|
|
3603
|
+
} else if (profile === void 0) continue;
|
|
3604
|
+
else if (!missedSince) missedSince = Date.now();
|
|
3605
|
+
else if (!missing && Date.now() - missedSince >= 3e3) {
|
|
3606
|
+
missing = true;
|
|
3607
|
+
process.stderr.write(`ghostly: the daemon of profile ${profile} stopped; waiting for it to start again (ghostly daemon --detach)\n`);
|
|
3548
3608
|
}
|
|
3549
3609
|
}
|
|
3550
3610
|
})();
|
|
@@ -3703,8 +3763,8 @@ var VERSION = package_default.version;
|
|
|
3703
3763
|
* command a running daemon answers loads none of them, and starts about as fast as Node does. Statically imported, they
|
|
3704
3764
|
* cost every command ~100 ms before its socket was opened.
|
|
3705
3765
|
*/
|
|
3706
|
-
var engineApi = () => import("./api-
|
|
3707
|
-
var engineHost = () => import("./host-
|
|
3766
|
+
var engineApi = () => import("./api-BIg0Msax.js");
|
|
3767
|
+
var engineHost = () => import("./host-DrL7FPG4.js");
|
|
3708
3768
|
var pretty = false;
|
|
3709
3769
|
function print(value) {
|
|
3710
3770
|
process.stdout.write(JSON.stringify(value, null, pretty ? 2 : void 0) + "\n");
|
|
@@ -3752,11 +3812,24 @@ function versionWarning(daemon, cli) {
|
|
|
3752
3812
|
* Never fails, and has no deadline of its own: a daemon that does not answer is the command's own call to find out,
|
|
3753
3813
|
* at the command's deadline, which closes the connection and ends this check with it. A deadline here ended every
|
|
3754
3814
|
* command on a wedged daemon at 15 s with `unavailable` ("The daemon went away"), whatever its own `--timeout` said.
|
|
3815
|
+
* A command with no deadline of its own waits for this check instead (15 s, session()), before it is sent.
|
|
3755
3816
|
*/
|
|
3756
3817
|
async function warnVersion(client) {
|
|
3757
3818
|
const warning = versionWarning((await client.call("status").catch(() => null))?.version, VERSION);
|
|
3758
3819
|
if (warning) process.stderr.write(warning + "\n");
|
|
3759
3820
|
}
|
|
3821
|
+
/** Whether `promise` settles within `ms` (the timer keeps no process alive). */
|
|
3822
|
+
function settlesWithin(promise, ms) {
|
|
3823
|
+
return new Promise((resolve) => {
|
|
3824
|
+
const timer = setTimeout(() => resolve(false), ms);
|
|
3825
|
+
timer.unref?.();
|
|
3826
|
+
const settled = () => {
|
|
3827
|
+
clearTimeout(timer);
|
|
3828
|
+
resolve(true);
|
|
3829
|
+
};
|
|
3830
|
+
promise.then(settled, settled);
|
|
3831
|
+
});
|
|
3832
|
+
}
|
|
3760
3833
|
/**
|
|
3761
3834
|
* A command about one 1:1 chat: a one-shot for it leaves the groups' sessions unstarted. A fresh process starts an edge
|
|
3762
3835
|
* per group member, and their first polls spent the relays' 30 requests a minute in seconds: the chat's message then
|
|
@@ -3836,7 +3909,7 @@ function offlineCall(method, params) {
|
|
|
3836
3909
|
}
|
|
3837
3910
|
/** 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
|
|
3838
3911
|
* contact carries its own `--timeout` (or the daemon's default for it), plus a margin; anything else may take as long
|
|
3839
|
-
* as it takes. */
|
|
3912
|
+
* as it takes, once the daemon has answered the version check sent ahead of it (session()). */
|
|
3840
3913
|
var ANSWER_MS = 15e3;
|
|
3841
3914
|
function answerWithin(method, params) {
|
|
3842
3915
|
const waits = typeof params.timeout === "number" ? Math.min(Math.max(params.timeout, 1), 86400) : waitsFor(method, params);
|
|
@@ -3858,9 +3931,17 @@ async function session(g, options) {
|
|
|
3858
3931
|
const client = await connectDaemon(g.paths);
|
|
3859
3932
|
if (client) {
|
|
3860
3933
|
const warned = warnVersion(client);
|
|
3934
|
+
const call = async (m, p) => {
|
|
3935
|
+
const timeoutMs = answerWithin(m, p ?? {});
|
|
3936
|
+
if (timeoutMs === void 0 && !await settlesWithin(warned, ANSWER_MS)) {
|
|
3937
|
+
client.destroy();
|
|
3938
|
+
throw new CliError("timeout", `The daemon did not answer in ${ANSWER_MS / 1e3} s; nothing was done: \`ghostly daemon restart\` starts a fresh one`, { method: m });
|
|
3939
|
+
}
|
|
3940
|
+
return client.call(m, p, { timeoutMs });
|
|
3941
|
+
};
|
|
3861
3942
|
return {
|
|
3862
3943
|
mode: "daemon",
|
|
3863
|
-
call
|
|
3944
|
+
call,
|
|
3864
3945
|
close: async () => {
|
|
3865
3946
|
await warned;
|
|
3866
3947
|
client.close();
|
|
@@ -4044,14 +4125,30 @@ var SPECIAL = [
|
|
|
4044
4125
|
],
|
|
4045
4126
|
["version", "This CLI's version (also ghostly --version)"]
|
|
4046
4127
|
];
|
|
4128
|
+
/** A command's words before its arguments: "group send", "send", "engine". */
|
|
4129
|
+
var wordsOf = (usage) => usage.split(" ").filter((w) => /^[a-z][\w-]*$/.test(w)).slice(0, 2);
|
|
4130
|
+
/**
|
|
4131
|
+
* `rows`, then each of `more` beside the rows of its first word: after the last of them (`group send` with the group
|
|
4132
|
+
* commands, `identity add` with the identity ones), or at the end when none has that word. They were all appended after
|
|
4133
|
+
* the table: `group send` 106 lines below the group block, `identity add` 60 below its own (agents#1606).
|
|
4134
|
+
*/
|
|
4135
|
+
function beside(rows, more) {
|
|
4136
|
+
const out = [...rows];
|
|
4137
|
+
for (const row of more) {
|
|
4138
|
+
const [first, second] = wordsOf(row[0]);
|
|
4139
|
+
let at = -1;
|
|
4140
|
+
if (second !== void 0) {
|
|
4141
|
+
for (let i = out.length - 1; i >= 0; i--) if (wordsOf(out[i][0])[0] === first && wordsOf(out[i][0]).length > 1) {
|
|
4142
|
+
at = i;
|
|
4143
|
+
break;
|
|
4144
|
+
}
|
|
4145
|
+
}
|
|
4146
|
+
out.splice(at < 0 ? out.length : at + 1, 0, row);
|
|
4147
|
+
}
|
|
4148
|
+
return out;
|
|
4149
|
+
}
|
|
4047
4150
|
function help() {
|
|
4048
|
-
const rows = [
|
|
4049
|
-
...SPECIAL.slice(0, 7).map(([usage, summary]) => [usage, summary]),
|
|
4050
|
-
...Object.values(COMMANDS).filter((c) => c.method !== "events.replay").map((c) => [c.usage, c.summary]),
|
|
4051
|
-
...Object.values(TEXT_COMMANDS).map((c) => [c.usage, c.summary]),
|
|
4052
|
-
...SPECIAL.slice(7).map(([usage, summary]) => [usage, summary]),
|
|
4053
|
-
[COMMANDS.events.usage, COMMANDS.events.summary]
|
|
4054
|
-
];
|
|
4151
|
+
const rows = [...beside([...SPECIAL.slice(0, 7).map(([usage, summary]) => [usage, summary]), ...Object.values(COMMANDS).filter((c) => c.method !== "events.replay").map((c) => [c.usage, c.summary])], [...Object.values(TEXT_COMMANDS).map((c) => [c.usage, c.summary]), ...SPECIAL.slice(7).map(([usage, summary]) => [usage, summary])]), [COMMANDS.events.usage, COMMANDS.events.summary]];
|
|
4055
4152
|
const width = 58;
|
|
4056
4153
|
return [
|
|
4057
4154
|
`ghostly ${VERSION}: Ghostly for bots and terminals, the app's own engine without a screen.`,
|
|
@@ -4282,7 +4379,7 @@ async function profileCommand(sub, argv) {
|
|
|
4282
4379
|
if (!given || !name) throw new CliError("usage", "ghostly profile restore <file> <new profile> [--passphrase-file f] [--use]");
|
|
4283
4380
|
noMoreThan(2, parsed.positionals, "profile restore <file> <new profile> [--passphrase-file f] [--use]");
|
|
4284
4381
|
const file = here(given);
|
|
4285
|
-
const { backupFileProtection, restoreProfile } = await import("./backup-
|
|
4382
|
+
const { backupFileProtection, restoreProfile } = await import("./backup-CqpDAZZG.js");
|
|
4286
4383
|
const protection = await backupFileProtection(file);
|
|
4287
4384
|
const paths = await restoreProfile(g.home, checkProfileName(name), file, protection === "none" ? void 0 : backupPassphrase(parsed.options["passphrase-file"], RESTORE_PASSPHRASE));
|
|
4288
4385
|
if (parsed.options.use) selectProfile(g.home, name);
|
|
@@ -4374,11 +4471,6 @@ async function runDaemon(g) {
|
|
|
4374
4471
|
lastSeq: host.ctx.hub.lastSeq
|
|
4375
4472
|
});
|
|
4376
4473
|
}
|
|
4377
|
-
/**
|
|
4378
|
-
* `daemon stop` and `restart` wait this long for the daemon's greeting: a daemon of an older release never greets, and
|
|
4379
|
-
* what does not prove itself is stopped as the process that holds the profile (`stopDaemon`), as the stop asked.
|
|
4380
|
-
*/
|
|
4381
|
-
var STOP_GREETING_MS = 2e3;
|
|
4382
4474
|
async function daemonCommand(argv) {
|
|
4383
4475
|
const sub = argv[0] && !argv[0].startsWith("-") ? argv[0] : void 0;
|
|
4384
4476
|
const parsed = parseArgs(sub ? argv.slice(1) : argv, {
|
|
@@ -4423,7 +4515,7 @@ async function daemonCommand(argv) {
|
|
|
4423
4515
|
if (sub === "stop") {
|
|
4424
4516
|
knownProfile(g);
|
|
4425
4517
|
const stopFor = seconds(parsed, 20);
|
|
4426
|
-
const client = await connectDaemon(g.paths
|
|
4518
|
+
const client = await connectDaemon(g.paths);
|
|
4427
4519
|
if (!client) throw new CliError("not_found", `No daemon runs profile ${g.profile}`);
|
|
4428
4520
|
print({
|
|
4429
4521
|
stopped: true,
|
|
@@ -4433,7 +4525,7 @@ async function daemonCommand(argv) {
|
|
|
4433
4525
|
}
|
|
4434
4526
|
if (sub === "restart") {
|
|
4435
4527
|
const stopFor = seconds(parsed, 20), startFor = seconds(parsed, 60);
|
|
4436
|
-
const client = await connectDaemon(g.paths
|
|
4528
|
+
const client = await connectDaemon(g.paths);
|
|
4437
4529
|
const probe = client ? client.call("status").catch(() => null) : null;
|
|
4438
4530
|
print({
|
|
4439
4531
|
restarted: true,
|
|
@@ -4642,6 +4734,15 @@ async function listenCommand(argv) {
|
|
|
4642
4734
|
const cursor = here(parsed.options.cursor);
|
|
4643
4735
|
checkCursor(cursor);
|
|
4644
4736
|
const since = parsed.options.since ?? readCursor(cursor);
|
|
4737
|
+
let quit = (code) => {
|
|
4738
|
+
process.exit(code);
|
|
4739
|
+
};
|
|
4740
|
+
const cursorFailed = (error) => {
|
|
4741
|
+
const failure = localFileError(error, cursor) ?? asCliError(error);
|
|
4742
|
+
process.stderr.write(`ghostly: could not write the cursor ${cursor}: ${failure.message}. Stopped, so that no event is handed twice\n`);
|
|
4743
|
+
print({ error: failure.toJSON() });
|
|
4744
|
+
quit(EXIT[failure.code]);
|
|
4745
|
+
};
|
|
4645
4746
|
const start = async (call, peerOf) => {
|
|
4646
4747
|
return eventHandler({
|
|
4647
4748
|
types,
|
|
@@ -4649,6 +4750,7 @@ async function listenCommand(argv) {
|
|
|
4649
4750
|
exec: parsed.options.exec,
|
|
4650
4751
|
webhook: parsed.options.webhook,
|
|
4651
4752
|
cursor,
|
|
4753
|
+
cursorFailed,
|
|
4652
4754
|
print: parsed.options.print === true || !parsed.options.exec && !parsed.options.webhook,
|
|
4653
4755
|
write: (line) => process.stdout.write(line + "\n"),
|
|
4654
4756
|
drained: () => new Promise((resolve) => {
|
|
@@ -4679,11 +4781,15 @@ async function listenCommand(argv) {
|
|
|
4679
4781
|
client.close();
|
|
4680
4782
|
throw error;
|
|
4681
4783
|
});
|
|
4682
|
-
const following = followDaemon(g.paths, client, handle, since);
|
|
4784
|
+
const following = followDaemon(g.paths, client, handle, since, PAUSE_HOLD_MS, g.profile);
|
|
4683
4785
|
const stop = () => {
|
|
4684
4786
|
following.close();
|
|
4685
4787
|
process.exit(0);
|
|
4686
4788
|
};
|
|
4789
|
+
quit = (code) => {
|
|
4790
|
+
following.close();
|
|
4791
|
+
process.exit(code);
|
|
4792
|
+
};
|
|
4687
4793
|
onReaderGone(stop);
|
|
4688
4794
|
await following.subscribed;
|
|
4689
4795
|
process.on("SIGINT", stop);
|
|
@@ -4706,6 +4812,10 @@ async function listenCommand(argv) {
|
|
|
4706
4812
|
await served.close();
|
|
4707
4813
|
await host.close();
|
|
4708
4814
|
});
|
|
4815
|
+
quit = (code) => {
|
|
4816
|
+
setTimeout(() => process.exit(code), 2e4).unref();
|
|
4817
|
+
served.close().then(() => host.close()).finally(() => process.exit(code));
|
|
4818
|
+
};
|
|
4709
4819
|
host.ctx.stop = stop;
|
|
4710
4820
|
onStopSignals(stop);
|
|
4711
4821
|
onReaderGone(stop);
|
|
@@ -4855,7 +4965,7 @@ async function textCommand(name, argv) {
|
|
|
4855
4965
|
};
|
|
4856
4966
|
if (spec.target === "group") params.mentions = parsed.options.mention ?? [];
|
|
4857
4967
|
if (parsed.options.reply !== void 0) params.reply = parsed.options.reply;
|
|
4858
|
-
if (!spec.message) Object.assign(params, (await import("./buttons-
|
|
4968
|
+
if (!spec.message) Object.assign(params, (await import("./buttons-azvbN6xn.js")).buttonsOf(parsed.options));
|
|
4859
4969
|
print(await withSession(g, (s) => {
|
|
4860
4970
|
if (spec.target === "chat") {
|
|
4861
4971
|
params.wait = parsed.options.wait ?? (s.mode === "one-shot" ? spec.message ? "confirmed" : "sent" : "none");
|
|
@@ -5163,4 +5273,4 @@ async function run(argv) {
|
|
|
5163
5273
|
//#endregion
|
|
5164
5274
|
export { run };
|
|
5165
5275
|
|
|
5166
|
-
//# sourceMappingURL=main-
|
|
5276
|
+
//# sourceMappingURL=main-xeoX7yLM.js.map
|