@webmux/agent 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +37 -14
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import fs2 from "fs";
|
|
5
5
|
import os2 from "os";
|
|
6
6
|
import path2 from "path";
|
|
7
|
-
import { execSync } from "child_process";
|
|
7
|
+
import { execSync as execSync2 } from "child_process";
|
|
8
8
|
import { Command } from "commander";
|
|
9
9
|
|
|
10
10
|
// src/credentials.ts
|
|
@@ -198,6 +198,7 @@ function isTmuxEmptyStateMessage(message) {
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
// src/connection.ts
|
|
201
|
+
import { execSync } from "child_process";
|
|
201
202
|
import WebSocket from "ws";
|
|
202
203
|
|
|
203
204
|
// src/terminal.ts
|
|
@@ -253,6 +254,7 @@ async function createTerminalBridge(options) {
|
|
|
253
254
|
}
|
|
254
255
|
|
|
255
256
|
// src/connection.ts
|
|
257
|
+
var AGENT_VERSION = "0.1.4";
|
|
256
258
|
var HEARTBEAT_INTERVAL_MS = 3e4;
|
|
257
259
|
var SESSION_SYNC_INTERVAL_MS = 15e3;
|
|
258
260
|
var INITIAL_RECONNECT_DELAY_MS = 1e3;
|
|
@@ -301,7 +303,7 @@ var AgentConnection = class {
|
|
|
301
303
|
ws.on("open", () => {
|
|
302
304
|
console.log("[agent] WebSocket connected, authenticating...");
|
|
303
305
|
this.reconnectDelay = INITIAL_RECONNECT_DELAY_MS;
|
|
304
|
-
this.sendMessage({ type: "auth", agentId: this.agentId, agentSecret: this.agentSecret });
|
|
306
|
+
this.sendMessage({ type: "auth", agentId: this.agentId, agentSecret: this.agentSecret, version: AGENT_VERSION });
|
|
305
307
|
});
|
|
306
308
|
ws.on("message", (raw) => {
|
|
307
309
|
let msg;
|
|
@@ -325,6 +327,11 @@ var AgentConnection = class {
|
|
|
325
327
|
switch (msg.type) {
|
|
326
328
|
case "auth-ok":
|
|
327
329
|
console.log("[agent] Authenticated successfully");
|
|
330
|
+
if (msg.latestVersion && msg.latestVersion !== AGENT_VERSION) {
|
|
331
|
+
console.log(`[agent] Update available: ${AGENT_VERSION} \u2192 ${msg.latestVersion}`);
|
|
332
|
+
this.selfUpdate(msg.latestVersion);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
328
335
|
this.startHeartbeat();
|
|
329
336
|
this.startSessionSync();
|
|
330
337
|
this.syncSessions();
|
|
@@ -450,6 +457,22 @@ var AgentConnection = class {
|
|
|
450
457
|
this.sendMessage({ type: "command-result", requestId, ok: false, error: message });
|
|
451
458
|
}
|
|
452
459
|
}
|
|
460
|
+
selfUpdate(targetVersion) {
|
|
461
|
+
console.log(`[agent] Installing @webmux/agent@${targetVersion}...`);
|
|
462
|
+
try {
|
|
463
|
+
execSync(`npm install -g @webmux/agent@${targetVersion}`, { stdio: "inherit" });
|
|
464
|
+
console.log("[agent] Update installed. Restarting...");
|
|
465
|
+
} catch (err) {
|
|
466
|
+
console.error("[agent] Update failed:", err instanceof Error ? err.message : err);
|
|
467
|
+
console.log("[agent] Continuing with current version");
|
|
468
|
+
this.startHeartbeat();
|
|
469
|
+
this.startSessionSync();
|
|
470
|
+
this.syncSessions();
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
this.stop();
|
|
474
|
+
process.exit(0);
|
|
475
|
+
}
|
|
453
476
|
sendMessage(msg) {
|
|
454
477
|
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
455
478
|
this.ws.send(JSON.stringify(msg));
|
|
@@ -599,7 +622,7 @@ program.command("status").description("Show agent status and credentials info").
|
|
|
599
622
|
console.log(`Agent ID: ${creds.agentId}`);
|
|
600
623
|
console.log(`Credentials File: ${credentialsPath()}`);
|
|
601
624
|
try {
|
|
602
|
-
const result =
|
|
625
|
+
const result = execSync2(`systemctl --user is-active ${SERVICE_NAME} 2>/dev/null`, { encoding: "utf-8" }).trim();
|
|
603
626
|
console.log(`Service: ${result}`);
|
|
604
627
|
} catch {
|
|
605
628
|
console.log(`Service: not installed`);
|
|
@@ -642,10 +665,10 @@ WantedBy=default.target
|
|
|
642
665
|
fs2.writeFileSync(servicePath, unit);
|
|
643
666
|
console.log(`[agent] Service file created: ${servicePath}`);
|
|
644
667
|
try {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
668
|
+
execSync2("systemctl --user daemon-reload", { stdio: "inherit" });
|
|
669
|
+
execSync2(`systemctl --user enable ${SERVICE_NAME}`, { stdio: "inherit" });
|
|
670
|
+
execSync2(`systemctl --user start ${SERVICE_NAME}`, { stdio: "inherit" });
|
|
671
|
+
execSync2(`loginctl enable-linger ${os2.userInfo().username}`, { stdio: "inherit" });
|
|
649
672
|
console.log(``);
|
|
650
673
|
console.log(`[agent] Service installed and started!`);
|
|
651
674
|
console.log(`[agent] It will auto-start on boot.`);
|
|
@@ -665,8 +688,8 @@ WantedBy=default.target
|
|
|
665
688
|
service.command("uninstall").description("Stop and remove the systemd user service").action(() => {
|
|
666
689
|
const servicePath = path2.join(os2.homedir(), ".config", "systemd", "user", `${SERVICE_NAME}.service`);
|
|
667
690
|
try {
|
|
668
|
-
|
|
669
|
-
|
|
691
|
+
execSync2(`systemctl --user stop ${SERVICE_NAME} 2>/dev/null`, { stdio: "inherit" });
|
|
692
|
+
execSync2(`systemctl --user disable ${SERVICE_NAME} 2>/dev/null`, { stdio: "inherit" });
|
|
670
693
|
} catch {
|
|
671
694
|
}
|
|
672
695
|
if (fs2.existsSync(servicePath)) {
|
|
@@ -674,14 +697,14 @@ service.command("uninstall").description("Stop and remove the systemd user servi
|
|
|
674
697
|
console.log(`[agent] Service file removed: ${servicePath}`);
|
|
675
698
|
}
|
|
676
699
|
try {
|
|
677
|
-
|
|
700
|
+
execSync2("systemctl --user daemon-reload", { stdio: "inherit" });
|
|
678
701
|
} catch {
|
|
679
702
|
}
|
|
680
703
|
console.log(`[agent] Service uninstalled.`);
|
|
681
704
|
});
|
|
682
705
|
service.command("status").description("Show systemd service status").action(() => {
|
|
683
706
|
try {
|
|
684
|
-
|
|
707
|
+
execSync2(`systemctl --user status ${SERVICE_NAME}`, { stdio: "inherit" });
|
|
685
708
|
} catch {
|
|
686
709
|
console.log(`[agent] Service is not installed or not running.`);
|
|
687
710
|
}
|
|
@@ -689,14 +712,14 @@ service.command("status").description("Show systemd service status").action(() =
|
|
|
689
712
|
service.command("upgrade").description("Upgrade agent to latest version and restart service").action(() => {
|
|
690
713
|
console.log("[agent] Upgrading @webmux/agent to latest...");
|
|
691
714
|
try {
|
|
692
|
-
|
|
715
|
+
execSync2("npm install -g @webmux/agent@latest", { stdio: "inherit" });
|
|
693
716
|
} catch {
|
|
694
717
|
console.error("[agent] Failed to upgrade. Try manually: npm install -g @webmux/agent@latest");
|
|
695
718
|
process.exit(1);
|
|
696
719
|
}
|
|
697
720
|
console.log("[agent] Restarting service...");
|
|
698
721
|
try {
|
|
699
|
-
|
|
722
|
+
execSync2(`systemctl --user restart ${SERVICE_NAME}`, { stdio: "inherit" });
|
|
700
723
|
console.log("[agent] Upgrade complete!");
|
|
701
724
|
} catch {
|
|
702
725
|
console.log("[agent] Package upgraded. Service not installed or restart failed.");
|
|
@@ -705,7 +728,7 @@ service.command("upgrade").description("Upgrade agent to latest version and rest
|
|
|
705
728
|
});
|
|
706
729
|
function findBinary(name) {
|
|
707
730
|
try {
|
|
708
|
-
return
|
|
731
|
+
return execSync2(`which ${name} 2>/dev/null`, { encoding: "utf-8" }).trim();
|
|
709
732
|
} catch {
|
|
710
733
|
return null;
|
|
711
734
|
}
|