usebeeline 0.1.202-rc.5 → 0.1.202
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/usebeeline.mjs +58 -28
- package/package.json +1 -1
package/dist/usebeeline.mjs
CHANGED
|
@@ -1175,11 +1175,14 @@ function withInstallLock(layout, work, options = {}) {
|
|
|
1175
1175
|
return withKernelLock(`beeline-install:${resolve8(layout.libDir)}`, work, options.waitMs);
|
|
1176
1176
|
}
|
|
1177
1177
|
function versionAtLeast(actual, minimum) {
|
|
1178
|
-
const parse = (value) =>
|
|
1178
|
+
const parse = (value) => {
|
|
1179
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-rc\.(\d+))?$/.exec(value);
|
|
1180
|
+
return match ? [...match.slice(1, 4).map(Number), match[4] === void 0 ? Infinity : Number(match[4])] : void 0;
|
|
1181
|
+
};
|
|
1179
1182
|
const left = parse(actual), right = parse(minimum);
|
|
1180
1183
|
if (!left || !right)
|
|
1181
1184
|
return false;
|
|
1182
|
-
for (let index = 0; index <
|
|
1185
|
+
for (let index = 0; index < 4; index++)
|
|
1183
1186
|
if (left[index] !== right[index])
|
|
1184
1187
|
return left[index] > right[index];
|
|
1185
1188
|
return true;
|
|
@@ -1282,7 +1285,7 @@ var init_managed_update = __esm({
|
|
|
1282
1285
|
timer.unref();
|
|
1283
1286
|
return this.#attempt = { controller, timer };
|
|
1284
1287
|
}
|
|
1285
|
-
fail(signal, error) {
|
|
1288
|
+
fail(signal, error, releaseId = this.#prepared) {
|
|
1286
1289
|
if (this.#attempt?.controller.signal !== signal)
|
|
1287
1290
|
return;
|
|
1288
1291
|
this.dispose();
|
|
@@ -1290,6 +1293,25 @@ var init_managed_update = __esm({
|
|
|
1290
1293
|
this.#preparing = this.#handingOff = void 0;
|
|
1291
1294
|
this.options.changed(void 0);
|
|
1292
1295
|
this.options.failed(error, this.#minimum);
|
|
1296
|
+
if (releaseId) {
|
|
1297
|
+
const cleanup = withInstallLock(this.options.layout, async () => {
|
|
1298
|
+
const state = await readUpdateState(this.options.layout);
|
|
1299
|
+
if (state.stagedReleaseId === releaseId)
|
|
1300
|
+
await writeUpdateState(this.options.layout, {
|
|
1301
|
+
...state,
|
|
1302
|
+
stagedReleaseId: void 0,
|
|
1303
|
+
lastCheckResult: "failed",
|
|
1304
|
+
lastCheckError: String(error)
|
|
1305
|
+
});
|
|
1306
|
+
}).catch((cleanupError) => this.options.failed(cleanupError, this.#minimum)).finally(() => {
|
|
1307
|
+
if (this.#preparing !== cleanup)
|
|
1308
|
+
return;
|
|
1309
|
+
this.#preparing = void 0;
|
|
1310
|
+
if (this.#pendingCheck)
|
|
1311
|
+
this.notify();
|
|
1312
|
+
});
|
|
1313
|
+
this.#preparing = cleanup;
|
|
1314
|
+
}
|
|
1293
1315
|
}
|
|
1294
1316
|
notify(_releaseKey, minimum) {
|
|
1295
1317
|
if (minimum && (!this.#minimum || !versionAtLeast(this.#minimum, minimum)))
|
|
@@ -1333,11 +1355,18 @@ var init_managed_update = __esm({
|
|
|
1333
1355
|
return;
|
|
1334
1356
|
const { signal } = this.begin().controller;
|
|
1335
1357
|
try {
|
|
1358
|
+
const targetLayout = {
|
|
1359
|
+
...this.options.layout,
|
|
1360
|
+
libDir: resolve8(this.options.layout.releasesRoot, releaseId)
|
|
1361
|
+
};
|
|
1362
|
+
const identity = await readInstalledBundleIdentity(targetLayout);
|
|
1363
|
+
const loaded = this.options.loadedRelease ? await readInstalledBundleIdentity({
|
|
1364
|
+
...this.options.layout,
|
|
1365
|
+
libDir: resolve8(this.options.layout.releasesRoot, this.options.loadedRelease)
|
|
1366
|
+
}) : void 0;
|
|
1367
|
+
if (identity?.version && loaded?.version && identity.version !== loaded.version && versionAtLeast(loaded.version, identity.version) && !versionAtLeast(identity.version, loaded.version))
|
|
1368
|
+
throw new Error(`requested helper ${identity.version} is older than running ${loaded.version}`);
|
|
1336
1369
|
if (this.#minimum) {
|
|
1337
|
-
const identity = await readInstalledBundleIdentity({
|
|
1338
|
-
...this.options.layout,
|
|
1339
|
-
libDir: resolve8(this.options.layout.releasesRoot, releaseId)
|
|
1340
|
-
});
|
|
1341
1370
|
if (!identity?.version || !versionAtLeast(identity.version, this.#minimum))
|
|
1342
1371
|
throw new Error(`published helper ${identity?.version ?? "unknown"} is below required ${this.#minimum}`);
|
|
1343
1372
|
}
|
|
@@ -1354,7 +1383,7 @@ var init_managed_update = __esm({
|
|
|
1354
1383
|
this.options.changed(releaseId);
|
|
1355
1384
|
this.idleChanged();
|
|
1356
1385
|
} catch (error) {
|
|
1357
|
-
this.fail(signal, error);
|
|
1386
|
+
this.fail(signal, error, releaseId);
|
|
1358
1387
|
}
|
|
1359
1388
|
}
|
|
1360
1389
|
idleChanged() {
|
|
@@ -26496,7 +26525,7 @@ async function requestMachine(stateRoot, request2, accept, _timeoutMs = 6e5) {
|
|
|
26496
26525
|
}
|
|
26497
26526
|
});
|
|
26498
26527
|
peer.once("error", (error) => {
|
|
26499
|
-
if (!["ENOENT", "ECONNREFUSED", "ECONNRESET"].includes(error.code ?? ""))
|
|
26528
|
+
if (request2.operation === "status" || !["ENOENT", "ECONNREFUSED", "ECONNRESET"].includes(error.code ?? ""))
|
|
26500
26529
|
finish(error);
|
|
26501
26530
|
});
|
|
26502
26531
|
peer.once("close", () => {
|
|
@@ -26780,23 +26809,21 @@ async function convergeMachine(options = {}) {
|
|
|
26780
26809
|
const stateRoot = env.XDG_STATE_HOME || resolve9(env.HOME || "", ".local/state");
|
|
26781
26810
|
const root = resolve9(stateRoot, "beeline/agents");
|
|
26782
26811
|
const configured = await Promise.all((await readdir4(root).catch(() => [])).filter((id) => /^[0-9a-f]{64}$/i.test(id)).map(async (id) => await stat(resolve9(root, id, "runtime.json")).then(() => true, () => false) && !await stat(resolve9(root, id, "stopped")).then(() => true, () => false) ? id : void 0));
|
|
26783
|
-
const required =
|
|
26784
|
-
...configured.filter((id) => Boolean(id)),
|
|
26785
|
-
...options.agentIds ?? []
|
|
26786
|
-
]);
|
|
26812
|
+
const required = new Set(options.agentIds ?? configured.filter((id) => Boolean(id)));
|
|
26787
26813
|
const current = await requestMachine(stateRoot, { operation: "status" }, () => true, 1e3).catch(() => void 0);
|
|
26788
26814
|
const hasControl = Boolean(current);
|
|
26789
26815
|
if (options.releaseId && (!hasControl || current?.loadedRelease === options.releaseId))
|
|
26790
26816
|
await withInstallLock(layout, () => activateRelease(layout, options.releaseId), {
|
|
26791
26817
|
waitMs: Math.max(0, deadlineAt - Date.now())
|
|
26792
26818
|
});
|
|
26793
|
-
|
|
26794
|
-
|
|
26795
|
-
|
|
26796
|
-
|
|
26797
|
-
|
|
26798
|
-
|
|
26799
|
-
|
|
26819
|
+
if (!hasControl || !options.agentIds)
|
|
26820
|
+
await convergeNativeHelper({
|
|
26821
|
+
env: { ...env, BEELINE_LIB_DIR: layout.libDir },
|
|
26822
|
+
...options.run ? { run: options.run } : {},
|
|
26823
|
+
// A pre-control helper cannot acknowledge this protocol. Its first forward migration replaces it once.
|
|
26824
|
+
restart: !hasControl,
|
|
26825
|
+
deadlineAt
|
|
26826
|
+
});
|
|
26800
26827
|
let expectedRelease = options.releaseId;
|
|
26801
26828
|
const targetIdentity = options.releaseId ? await readInstalledBundleIdentity({
|
|
26802
26829
|
...layout,
|
|
@@ -26808,11 +26835,11 @@ async function convergeMachine(options = {}) {
|
|
|
26808
26835
|
sourceGeneration: current.generation
|
|
26809
26836
|
} : { operation: "converge" };
|
|
26810
26837
|
return requestMachine(stateRoot, request2, (status) => {
|
|
26811
|
-
if (status.generation === current?.generation && status.desiredRelease)
|
|
26838
|
+
if (options.releaseId && status.generation === current?.generation && status.desiredRelease)
|
|
26812
26839
|
expectedRelease = status.desiredRelease;
|
|
26813
26840
|
if (expectedRelease && status.loadedRelease !== expectedRelease && !(targetIdentity?.version && status.loadedIdentity?.version && targetIdentity.version !== status.loadedIdentity.version && versionAtLeast(status.loadedIdentity.version, targetIdentity.version)))
|
|
26814
26841
|
return false;
|
|
26815
|
-
const agents = Object.entries(status.agents).filter(([id, agent]) => required.has(id) || agent.enabled !== false);
|
|
26842
|
+
const agents = Object.entries(status.agents).filter(([id, agent]) => required.has(id) || !options.agentIds && agent.enabled !== false);
|
|
26816
26843
|
const refused = agents.filter(([, agent]) => agent.state === "needs-auth" || agent.state === "needs-config" || agent.state === "removed");
|
|
26817
26844
|
if (refused.length)
|
|
26818
26845
|
throw new Error(refused.map(([id, agent]) => `agent ${id}: ${agent.status}`).join("; "));
|
|
@@ -26833,6 +26860,12 @@ async function bootstrapMachine(env = process.env) {
|
|
|
26833
26860
|
const layout = beelineInstallLayout(env) ?? discoveredBeelineInstallLayout(env);
|
|
26834
26861
|
const state = await readUpdateState(layout);
|
|
26835
26862
|
const active = await activeReleaseId(layout);
|
|
26863
|
+
if (state.stagedReleaseId)
|
|
26864
|
+
await withInstallLock(layout, async () => {
|
|
26865
|
+
const current = await readUpdateState(layout);
|
|
26866
|
+
if (current.stagedReleaseId === state.stagedReleaseId)
|
|
26867
|
+
await writeUpdateState(layout, { ...current, stagedReleaseId: void 0 });
|
|
26868
|
+
});
|
|
26836
26869
|
let releaseId;
|
|
26837
26870
|
for (const id of [state.stagedReleaseId, active]) {
|
|
26838
26871
|
if (!id || !/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(id))
|
|
@@ -26981,7 +27014,6 @@ async function main() {
|
|
|
26981
27014
|
return;
|
|
26982
27015
|
}
|
|
26983
27016
|
const stateRoot = process.env.XDG_STATE_HOME || resolve13(process.env.HOME || "", ".local/state");
|
|
26984
|
-
let selectedRelease;
|
|
26985
27017
|
if (command2 === "start") {
|
|
26986
27018
|
for (let i = 1; i < args.length; i++) {
|
|
26987
27019
|
const arg = args[i];
|
|
@@ -27017,10 +27049,9 @@ async function main() {
|
|
|
27017
27049
|
console.log(`[beeline] executing release ${status.loadedRelease}; helper ${status.pid}; every enabled agent serving`);
|
|
27018
27050
|
return;
|
|
27019
27051
|
}
|
|
27020
|
-
if (command2 === "connect" && !args.includes("--help") && !args.includes("-h")) {
|
|
27052
|
+
if (command2 === "connect" && !args.includes("--help") && !args.includes("-h") && !await resolveBundleEntrypoint(layout.libDir)) {
|
|
27021
27053
|
const target = await prepareMachineRelease(layout, { deadlineAt });
|
|
27022
|
-
await
|
|
27023
|
-
selectedRelease = target.releaseId;
|
|
27054
|
+
await withInstallLock(layout, () => activateRelease(layout, target.releaseId));
|
|
27024
27055
|
}
|
|
27025
27056
|
const entry = await resolveBundleEntrypoint(layout.libDir);
|
|
27026
27057
|
if (!entry)
|
|
@@ -27028,8 +27059,7 @@ async function main() {
|
|
|
27028
27059
|
const child = spawn9(process.execPath, [entry, ...args], {
|
|
27029
27060
|
env: {
|
|
27030
27061
|
...process.env,
|
|
27031
|
-
BEELINE_LIB_DIR: layout.libDir
|
|
27032
|
-
...selectedRelease ? { BEELINE_RECOVERY_SELECTED_RELEASE: selectedRelease } : {}
|
|
27062
|
+
BEELINE_LIB_DIR: layout.libDir
|
|
27033
27063
|
},
|
|
27034
27064
|
stdio: "inherit"
|
|
27035
27065
|
});
|