@fancyboi999/open-tag-daemon 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-cli.mjs +6 -1
- package/dist/cli.mjs +37 -2
- package/package.json +1 -1
package/dist/agent-cli.mjs
CHANGED
|
@@ -3079,8 +3079,9 @@ function createLogger(component) {
|
|
|
3079
3079
|
}
|
|
3080
3080
|
const extra = fields && Object.keys(fields).length ? " " + safeJson(fields) : "";
|
|
3081
3081
|
const line = `${rec.t} ${level.toUpperCase().padEnd(5)} [${component}] ${msg}${extra}`;
|
|
3082
|
+
const stream = consoleStream(component, level);
|
|
3082
3083
|
try {
|
|
3083
|
-
|
|
3084
|
+
stream.write(line + "\n");
|
|
3084
3085
|
} catch {
|
|
3085
3086
|
}
|
|
3086
3087
|
}
|
|
@@ -3092,6 +3093,10 @@ function createLogger(component) {
|
|
|
3092
3093
|
child: (sub) => createLogger(`${component}:${sub}`)
|
|
3093
3094
|
};
|
|
3094
3095
|
}
|
|
3096
|
+
function consoleStream(component, level) {
|
|
3097
|
+
if (level === "error" || component === "cli" || component.startsWith("cli:")) return process.stderr;
|
|
3098
|
+
return process.stdout;
|
|
3099
|
+
}
|
|
3095
3100
|
function safeJson(o) {
|
|
3096
3101
|
try {
|
|
3097
3102
|
return JSON.stringify(o, (_k, v) => typeof v === "string" && v.length > 300 ? v.slice(0, 300) + "\u2026" : v);
|
package/dist/cli.mjs
CHANGED
|
@@ -3770,8 +3770,9 @@ function createLogger(component) {
|
|
|
3770
3770
|
}
|
|
3771
3771
|
const extra = fields && Object.keys(fields).length ? " " + safeJson(fields) : "";
|
|
3772
3772
|
const line = `${rec.t} ${level.toUpperCase().padEnd(5)} [${component}] ${msg}${extra}`;
|
|
3773
|
+
const stream = consoleStream(component, level);
|
|
3773
3774
|
try {
|
|
3774
|
-
|
|
3775
|
+
stream.write(line + "\n");
|
|
3775
3776
|
} catch {
|
|
3776
3777
|
}
|
|
3777
3778
|
}
|
|
@@ -3783,6 +3784,10 @@ function createLogger(component) {
|
|
|
3783
3784
|
child: (sub) => createLogger(`${component}:${sub}`)
|
|
3784
3785
|
};
|
|
3785
3786
|
}
|
|
3787
|
+
function consoleStream(component, level) {
|
|
3788
|
+
if (level === "error" || component === "cli" || component.startsWith("cli:")) return process.stderr;
|
|
3789
|
+
return process.stdout;
|
|
3790
|
+
}
|
|
3786
3791
|
function safeJson(o) {
|
|
3787
3792
|
try {
|
|
3788
3793
|
return JSON.stringify(o, (_k, v) => typeof v === "string" && v.length > 300 ? v.slice(0, 300) + "\u2026" : v);
|
|
@@ -3797,6 +3802,7 @@ var MACHINE_REJECTED_CODE = 4001;
|
|
|
3797
3802
|
// src/daemon/connection.ts
|
|
3798
3803
|
var INITIAL_BACKOFF_MS = 1e3;
|
|
3799
3804
|
var MAX_BACKOFF_MS = 3e4;
|
|
3805
|
+
var SERVER_STALE_MS = Number(process.env.OPEN_TAG_DAEMON_SERVER_STALE_MS ?? 9e4);
|
|
3800
3806
|
var Connection = class {
|
|
3801
3807
|
constructor(url, key, onMsg, onOpen, mkWs = (u) => new wrapper_default(u)) {
|
|
3802
3808
|
this.url = url;
|
|
@@ -3813,9 +3819,11 @@ var Connection = class {
|
|
|
3813
3819
|
ws = null;
|
|
3814
3820
|
delay = INITIAL_BACKOFF_MS;
|
|
3815
3821
|
timer = null;
|
|
3822
|
+
watchdog = null;
|
|
3816
3823
|
should = true;
|
|
3817
3824
|
accepted = false;
|
|
3818
3825
|
// per-attempt: flips true once the server sends any frame (proof it accepted us, not rejected)
|
|
3826
|
+
lastServerFrameAt = 0;
|
|
3819
3827
|
log = createLogger("daemon:conn");
|
|
3820
3828
|
connect() {
|
|
3821
3829
|
this.should = true;
|
|
@@ -3827,13 +3835,22 @@ var Connection = class {
|
|
|
3827
3835
|
close() {
|
|
3828
3836
|
this.should = false;
|
|
3829
3837
|
if (this.timer) clearTimeout(this.timer);
|
|
3838
|
+
if (this.watchdog) {
|
|
3839
|
+
clearTimeout(this.watchdog);
|
|
3840
|
+
this.watchdog = null;
|
|
3841
|
+
}
|
|
3830
3842
|
this.ws?.close();
|
|
3831
3843
|
}
|
|
3832
3844
|
doConnect() {
|
|
3833
3845
|
if (!this.should) return;
|
|
3834
3846
|
const wsUrl = this.url.replace(/^http/, "ws") + `/daemon/connect?key=${encodeURIComponent(this.key)}`;
|
|
3835
3847
|
this.log.info("connecting", { url: this.url });
|
|
3848
|
+
if (this.watchdog) {
|
|
3849
|
+
clearTimeout(this.watchdog);
|
|
3850
|
+
this.watchdog = null;
|
|
3851
|
+
}
|
|
3836
3852
|
this.accepted = false;
|
|
3853
|
+
this.lastServerFrameAt = 0;
|
|
3837
3854
|
this.ws = this.mkWs(wsUrl);
|
|
3838
3855
|
this.ws.on("open", () => {
|
|
3839
3856
|
this.log.info("connected");
|
|
@@ -3844,6 +3861,8 @@ var Connection = class {
|
|
|
3844
3861
|
this.accepted = true;
|
|
3845
3862
|
this.delay = INITIAL_BACKOFF_MS;
|
|
3846
3863
|
}
|
|
3864
|
+
this.lastServerFrameAt = Date.now();
|
|
3865
|
+
this.armWatchdog();
|
|
3847
3866
|
let m;
|
|
3848
3867
|
try {
|
|
3849
3868
|
m = JSON.parse(d.toString());
|
|
@@ -3853,6 +3872,10 @@ var Connection = class {
|
|
|
3853
3872
|
this.onMsg(m);
|
|
3854
3873
|
});
|
|
3855
3874
|
this.ws.on("close", (code, reason) => {
|
|
3875
|
+
if (this.watchdog) {
|
|
3876
|
+
clearTimeout(this.watchdog);
|
|
3877
|
+
this.watchdog = null;
|
|
3878
|
+
}
|
|
3856
3879
|
if (code === MACHINE_REJECTED_CODE) {
|
|
3857
3880
|
this.delay = MAX_BACKOFF_MS;
|
|
3858
3881
|
this.log.error(
|
|
@@ -3866,6 +3889,18 @@ var Connection = class {
|
|
|
3866
3889
|
});
|
|
3867
3890
|
this.ws.on("error", (e) => this.log.error("ws error", { detail: String(e?.message ?? e) }));
|
|
3868
3891
|
}
|
|
3892
|
+
armWatchdog() {
|
|
3893
|
+
if (this.watchdog) clearTimeout(this.watchdog);
|
|
3894
|
+
this.watchdog = setTimeout(() => {
|
|
3895
|
+
if (!this.accepted || !this.lastServerFrameAt || this.ws?.readyState !== wrapper_default.OPEN) return;
|
|
3896
|
+
this.log.warn("server heartbeat stale; closing socket to reconnect", { staleMs: Date.now() - this.lastServerFrameAt });
|
|
3897
|
+
try {
|
|
3898
|
+
this.ws.close();
|
|
3899
|
+
} catch {
|
|
3900
|
+
}
|
|
3901
|
+
}, SERVER_STALE_MS + 1);
|
|
3902
|
+
this.watchdog.unref?.();
|
|
3903
|
+
}
|
|
3869
3904
|
scheduleReconnect() {
|
|
3870
3905
|
if (!this.should || this.timer) return;
|
|
3871
3906
|
this.log.info("reconnecting", { ms: this.delay });
|
|
@@ -5956,7 +5991,7 @@ conn = new Connection(serverUrl, apiKey, (msg) => {
|
|
|
5956
5991
|
runningAgents: mgr.running(),
|
|
5957
5992
|
hostname: os4.hostname(),
|
|
5958
5993
|
os: `${os4.platform()} ${os4.arch()}`,
|
|
5959
|
-
daemonVersion: "0.6.
|
|
5994
|
+
daemonVersion: "0.6.1",
|
|
5960
5995
|
machineId: readMachineId()
|
|
5961
5996
|
// Stable identity: empty on first connection; server sends it back via ready:ack for persistence.
|
|
5962
5997
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fancyboi999/open-tag-daemon",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "open-tag compute-plane daemon — connect any machine to an open-tag server so its agents run there. No repo clone needed.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|