@flumecode/runner 0.3.0 → 0.3.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/cli.js +37 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -39,8 +39,34 @@ function readVersion() {
|
|
|
39
39
|
}
|
|
40
40
|
var RUNNER_VERSION = readVersion();
|
|
41
41
|
var RUNNER_VERSION_HEADER = "x-flumecode-runner-version";
|
|
42
|
+
var RUNNER_MIN_VERSION_HEADER = "x-flumecode-min-runner-version";
|
|
43
|
+
function compareVersions(a, b) {
|
|
44
|
+
const parse = (v) => (v.split("-")[0] ?? v).split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
45
|
+
const pa = parse(a);
|
|
46
|
+
const pb = parse(b);
|
|
47
|
+
const len = Math.max(pa.length, pb.length);
|
|
48
|
+
for (let i = 0; i < len; i++) {
|
|
49
|
+
const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
50
|
+
if (diff !== 0) return diff;
|
|
51
|
+
}
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
42
54
|
|
|
43
55
|
// src/api.ts
|
|
56
|
+
var OUTDATED_WARN_INTERVAL_MS = 60 * 6e4;
|
|
57
|
+
var lastOutdatedWarnAt = 0;
|
|
58
|
+
function noteServerVersion(res) {
|
|
59
|
+
const min = res.headers.get(RUNNER_MIN_VERSION_HEADER)?.trim();
|
|
60
|
+
if (!min || RUNNER_VERSION === "unknown") return;
|
|
61
|
+
if (compareVersions(RUNNER_VERSION, min) >= 0) return;
|
|
62
|
+
const now = Date.now();
|
|
63
|
+
if (now - lastOutdatedWarnAt < OUTDATED_WARN_INTERVAL_MS) return;
|
|
64
|
+
lastOutdatedWarnAt = now;
|
|
65
|
+
console.warn(
|
|
66
|
+
`\u26A0\uFE0F This runner (v${RUNNER_VERSION}) is outdated \u2014 the server expects v${min} or newer.
|
|
67
|
+
Update with: npm install -g @flumecode/runner@latest`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
44
70
|
async function claimJob(config) {
|
|
45
71
|
const res = await fetch(`${config.serverUrl}/api/runner/jobs/claim`, {
|
|
46
72
|
method: "POST",
|
|
@@ -49,6 +75,7 @@ async function claimJob(config) {
|
|
|
49
75
|
[RUNNER_VERSION_HEADER]: RUNNER_VERSION
|
|
50
76
|
}
|
|
51
77
|
});
|
|
78
|
+
noteServerVersion(res);
|
|
52
79
|
if (res.status === 204) return null;
|
|
53
80
|
if (res.status === 401) {
|
|
54
81
|
throw new Error("Runner token rejected (401). Re-run `login` with a fresh token.");
|
|
@@ -66,6 +93,7 @@ async function reportJob(config, jobId, result) {
|
|
|
66
93
|
},
|
|
67
94
|
body: JSON.stringify(result)
|
|
68
95
|
});
|
|
96
|
+
noteServerVersion(res);
|
|
69
97
|
if (!res.ok) throw new Error(`complete failed: ${res.status} ${await safeText(res)}`);
|
|
70
98
|
}
|
|
71
99
|
async function reportHeartbeat(config, claudeCode) {
|
|
@@ -78,6 +106,7 @@ async function reportHeartbeat(config, claudeCode) {
|
|
|
78
106
|
},
|
|
79
107
|
body: JSON.stringify({ claudeCode })
|
|
80
108
|
});
|
|
109
|
+
noteServerVersion(res);
|
|
81
110
|
if (!res.ok) throw new Error(`heartbeat failed: ${res.status} ${await safeText(res)}`);
|
|
82
111
|
}
|
|
83
112
|
async function safeText(res) {
|
|
@@ -1042,14 +1071,18 @@ function parseFlags(args) {
|
|
|
1042
1071
|
}
|
|
1043
1072
|
var command = process.argv[2];
|
|
1044
1073
|
var rest = process.argv.slice(3);
|
|
1045
|
-
if (command === "
|
|
1074
|
+
if (command === "--version" || command === "-v" || command === "version") {
|
|
1075
|
+
console.log(RUNNER_VERSION);
|
|
1076
|
+
process.exit(0);
|
|
1077
|
+
} else if (command === "login") {
|
|
1046
1078
|
void login(rest);
|
|
1047
1079
|
} else if (command === "start") {
|
|
1048
1080
|
void start();
|
|
1049
1081
|
} else {
|
|
1050
|
-
console.log(
|
|
1082
|
+
console.log(`FlumeCode runner v${RUNNER_VERSION}`);
|
|
1051
1083
|
console.log("Usage:");
|
|
1052
|
-
console.log(" flumecode login
|
|
1053
|
-
console.log(" flumecode start
|
|
1084
|
+
console.log(" flumecode login # save server URL + token");
|
|
1085
|
+
console.log(" flumecode start # poll for and run jobs");
|
|
1086
|
+
console.log(" flumecode --version # print the runner version");
|
|
1054
1087
|
process.exit(command ? 1 : 0);
|
|
1055
1088
|
}
|