@profullstack/threatcrush 0.11.7 → 0.11.8
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/dist/index.js +76 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23161,6 +23161,30 @@ async function latestPublishedVersion(pkgName, timeoutMs = 8e3) {
|
|
|
23161
23161
|
return null;
|
|
23162
23162
|
}
|
|
23163
23163
|
}
|
|
23164
|
+
var DAEMON_UNIT = "threatcrushd.service";
|
|
23165
|
+
function systemdOwnsDaemon(mainPidOutput, daemonPid) {
|
|
23166
|
+
if (!mainPidOutput || !daemonPid) return false;
|
|
23167
|
+
const mainPid = Number.parseInt(mainPidOutput.trim(), 10);
|
|
23168
|
+
return Number.isFinite(mainPid) && mainPid > 0 && mainPid === daemonPid;
|
|
23169
|
+
}
|
|
23170
|
+
function daemonRefreshPlan(opts) {
|
|
23171
|
+
if (!opts.daemonRunning) return { action: "none" };
|
|
23172
|
+
if (opts.systemdManaged) {
|
|
23173
|
+
return { action: "manual", command: `sudo systemctl restart ${opts.unit ?? DAEMON_UNIT}` };
|
|
23174
|
+
}
|
|
23175
|
+
return { action: "restart" };
|
|
23176
|
+
}
|
|
23177
|
+
function staleDaemonWarning(cliVersion, daemonVersion, restartCommand = "threatcrush restart") {
|
|
23178
|
+
if (!cliVersion || !daemonVersion || cliVersion === daemonVersion) return null;
|
|
23179
|
+
return [
|
|
23180
|
+
"\u26A0 The CLI was updated, but the running daemon is still on the old build.",
|
|
23181
|
+
` CLI: ${cliVersion}`,
|
|
23182
|
+
` Daemon: ${daemonVersion}`,
|
|
23183
|
+
"",
|
|
23184
|
+
" A running daemon keeps executing the bundle it started from. Restart it:",
|
|
23185
|
+
` ${restartCommand}`
|
|
23186
|
+
];
|
|
23187
|
+
}
|
|
23164
23188
|
function shadowedUpdateWarning(latest, active, activePath) {
|
|
23165
23189
|
if (!latest || !active || latest === active) return null;
|
|
23166
23190
|
return [
|
|
@@ -23176,6 +23200,7 @@ function shadowedUpdateWarning(latest, active, activePath) {
|
|
|
23176
23200
|
}
|
|
23177
23201
|
|
|
23178
23202
|
// src/index.ts
|
|
23203
|
+
init_ipc_client();
|
|
23179
23204
|
var LOGO2 = `
|
|
23180
23205
|
${source_default.green(" \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557")}
|
|
23181
23206
|
${source_default.green(" \u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D")}
|
|
@@ -23248,6 +23273,55 @@ async function reportIfStillStale() {
|
|
|
23248
23273
|
}
|
|
23249
23274
|
console.log();
|
|
23250
23275
|
}
|
|
23276
|
+
async function liveDaemon() {
|
|
23277
|
+
const pid = findRunningDaemon();
|
|
23278
|
+
if (!pid) return { pid: null, version: null };
|
|
23279
|
+
const client = new IpcClient();
|
|
23280
|
+
try {
|
|
23281
|
+
await client.connect();
|
|
23282
|
+
const live = await client.status();
|
|
23283
|
+
return { pid, version: live.version ?? null };
|
|
23284
|
+
} catch {
|
|
23285
|
+
return { pid, version: null };
|
|
23286
|
+
} finally {
|
|
23287
|
+
client.close();
|
|
23288
|
+
}
|
|
23289
|
+
}
|
|
23290
|
+
async function refreshDaemonAfterUpgrade() {
|
|
23291
|
+
const before = await liveDaemon();
|
|
23292
|
+
const plan = daemonRefreshPlan({
|
|
23293
|
+
daemonRunning: before.pid !== null,
|
|
23294
|
+
systemdManaged: systemdOwnsDaemon(
|
|
23295
|
+
execQuiet(`systemctl show ${DAEMON_UNIT} -p MainPID --value`),
|
|
23296
|
+
before.pid
|
|
23297
|
+
)
|
|
23298
|
+
});
|
|
23299
|
+
if (plan.action === "none") return;
|
|
23300
|
+
if (plan.action === "manual") {
|
|
23301
|
+
console.log(source_default.yellow(" ! The daemon is managed by systemd and is still on the old build."));
|
|
23302
|
+
console.log(source_default.dim(` Restart it with: ${plan.command}
|
|
23303
|
+
`));
|
|
23304
|
+
return;
|
|
23305
|
+
}
|
|
23306
|
+
console.log(source_default.dim(" Restarting threatcrushd onto the new build...\n"));
|
|
23307
|
+
await daemonRestart();
|
|
23308
|
+
const after = await liveDaemon();
|
|
23309
|
+
const warning = staleDaemonWarning(PKG_VERSION, after.version);
|
|
23310
|
+
if (warning) {
|
|
23311
|
+
console.log(source_default.yellow(` ${warning[0]}`));
|
|
23312
|
+
for (const line of warning.slice(1)) {
|
|
23313
|
+
console.log(source_default.dim(` ${line}`));
|
|
23314
|
+
}
|
|
23315
|
+
console.log();
|
|
23316
|
+
}
|
|
23317
|
+
}
|
|
23318
|
+
function execQuiet(cmd) {
|
|
23319
|
+
try {
|
|
23320
|
+
return (0, import_node_child_process11.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
23321
|
+
} catch {
|
|
23322
|
+
return null;
|
|
23323
|
+
}
|
|
23324
|
+
}
|
|
23251
23325
|
var program2 = new Command();
|
|
23252
23326
|
program2.name("threatcrush").description(
|
|
23253
23327
|
`${source_default.green("\u26A1 ThreatCrush")} \u2014 All-in-one security agent
|
|
@@ -23480,6 +23554,8 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
23480
23554
|
console.log(source_default.dim(" Updated bundle: CLI only\n"));
|
|
23481
23555
|
}
|
|
23482
23556
|
await reportIfStillStale();
|
|
23557
|
+
await refreshDaemonAfterUpgrade();
|
|
23558
|
+
console.log(source_default.dim(" If a `threatcrush monitor --tui` is open, quit and relaunch it.\n"));
|
|
23483
23559
|
} catch (err) {
|
|
23484
23560
|
console.log(source_default.red("\n \u2717 Update failed. Try manually:\n"));
|
|
23485
23561
|
for (const cmd of commands) {
|