@onklave/agent-cli 0.1.55 → 0.1.56

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.
Files changed (2) hide show
  1. package/main.js +42 -28
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -1536,6 +1536,11 @@ var HeartbeatService = class {
1536
1536
  `heartbeat failed: ${response.status} ${response.statusText}`
1537
1537
  )
1538
1538
  );
1539
+ return;
1540
+ }
1541
+ const respBody = await response.json().catch(() => null);
1542
+ if (respBody?.pendingUpgrade) {
1543
+ this.opts.onPendingUpgrade?.({ targetVersion: respBody.targetVersion });
1539
1544
  }
1540
1545
  } catch (err) {
1541
1546
  this.onError(err instanceof Error ? err : new Error(String(err)));
@@ -5226,13 +5231,48 @@ async function daemonStart() {
5226
5231
  let sigintTimer = null;
5227
5232
  let runtimePublisher = null;
5228
5233
  let updateCheckTimer = null;
5234
+ const upgradeService = new DaemonUpgradeService({
5235
+ allowAutoUpgrade: !!process.env["ONKLAVE_ALLOW_AUTO_UPGRADE"],
5236
+ currentVersion: readPackageVersion() ?? "0.0.0",
5237
+ runInstall: async () => {
5238
+ const { execFileSync: execFileSync3 } = __require("child_process");
5239
+ execFileSync3("npm", ["install", "-g", "@onklave/agent-cli@latest"], {
5240
+ stdio: "pipe",
5241
+ timeout: 18e4
5242
+ });
5243
+ const v = execFileSync3(
5244
+ "npm",
5245
+ ["view", "@onklave/agent-cli@latest", "version"],
5246
+ { stdio: "pipe", timeout: 3e4 }
5247
+ ).toString().trim();
5248
+ return v || "latest";
5249
+ },
5250
+ requestRestart: () => void drainAndExit("upgrade"),
5251
+ audit: (action, details) => auditStreamer.record({
5252
+ sessionId: creds.machineId,
5253
+ type: "daemon_lifecycle" /* DAEMON_LIFECYCLE */,
5254
+ action,
5255
+ details,
5256
+ outcome: action === "upgrade_failed" ? "failure" : "success"
5257
+ }),
5258
+ log: (m) => console.log(m)
5259
+ });
5260
+ let upgradeInFlight = false;
5261
+ const triggerUpgrade = () => {
5262
+ if (upgradeInFlight) return;
5263
+ upgradeInFlight = true;
5264
+ void upgradeService.handle().finally(() => {
5265
+ upgradeInFlight = false;
5266
+ });
5267
+ };
5229
5268
  const heartbeat = new HeartbeatService({
5230
5269
  platformUrl,
5231
5270
  deviceToken: creds.deviceToken,
5232
5271
  machineId: creds.machineId,
5233
5272
  getActiveSessionCount: () => claimHandler.getActiveSessionCount(),
5234
5273
  cliVersion: readPackageVersion() ?? "0.0.0",
5235
- posture: collectPosture()
5274
+ posture: collectPosture(),
5275
+ onPendingUpgrade: () => triggerUpgrade()
5236
5276
  });
5237
5277
  const drainAndExit = async (reason) => {
5238
5278
  if (shuttingDown) return;
@@ -5295,34 +5335,8 @@ async function daemonStart() {
5295
5335
  }
5296
5336
  console.log("Connected.");
5297
5337
  claimHandler.attachToSocket(comms.inner());
5298
- const upgradeService = new DaemonUpgradeService({
5299
- allowAutoUpgrade: !!process.env["ONKLAVE_ALLOW_AUTO_UPGRADE"],
5300
- currentVersion: readPackageVersion() ?? "0.0.0",
5301
- runInstall: async () => {
5302
- const { execFileSync: execFileSync3 } = __require("child_process");
5303
- execFileSync3("npm", ["install", "-g", "@onklave/agent-cli@latest"], {
5304
- stdio: "pipe",
5305
- timeout: 18e4
5306
- });
5307
- const v = execFileSync3(
5308
- "npm",
5309
- ["view", "@onklave/agent-cli@latest", "version"],
5310
- { stdio: "pipe", timeout: 3e4 }
5311
- ).toString().trim();
5312
- return v || "latest";
5313
- },
5314
- requestRestart: () => void drainAndExit("upgrade"),
5315
- audit: (action, details) => auditStreamer.record({
5316
- sessionId: creds.machineId,
5317
- type: "daemon_lifecycle" /* DAEMON_LIFECYCLE */,
5318
- action,
5319
- details,
5320
- outcome: action === "upgrade_failed" ? "failure" : "success"
5321
- }),
5322
- log: (m) => console.log(m)
5323
- });
5324
5338
  comms.inner().onUpgradeRequest(() => {
5325
- void upgradeService.handle();
5339
+ triggerUpgrade();
5326
5340
  });
5327
5341
  await stateService.transition("online");
5328
5342
  heartbeat.start();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onklave/agent-cli",
3
- "version": "0.1.55",
3
+ "version": "0.1.56",
4
4
  "description": "Onklave Agent CLI — local agent runner with cloud orchestration",
5
5
  "bin": {
6
6
  "onklave": "./main.js"