@alan-ai-hq/agent-manager-darwin-arm64 0.1.149 → 0.1.151

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/alan-agent.cjs +63 -14
  2. package/package.json +1 -1
package/alan-agent.cjs CHANGED
@@ -55368,7 +55368,7 @@ var require_websocket_server = __commonJS({
55368
55368
  // package.json
55369
55369
  var package_default = {
55370
55370
  name: "@alan-ai-hq/agent-manager",
55371
- version: "0.1.149",
55371
+ version: "0.1.151",
55372
55372
  private: true,
55373
55373
  type: "module",
55374
55374
  description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
@@ -59981,6 +59981,10 @@ function createServiceManager(host, profile) {
59981
59981
  // src/platform/sleep.ts
59982
59982
  var import_node_child_process7 = require("child_process");
59983
59983
  var WAKE_THRESHOLD_MS = 3e4;
59984
+ var WINDOWS_WAKE_THRESHOLD_MS = 12e4;
59985
+ function wakeThresholdMs(platform3) {
59986
+ return platform3 === "win32" ? WINDOWS_WAKE_THRESHOLD_MS : WAKE_THRESHOLD_MS;
59987
+ }
59984
59988
  function createWakeDetector(clock, thresholdMs = WAKE_THRESHOLD_MS, platform3 = process.platform) {
59985
59989
  const last = { wall: clock.now(), drift: clock.now() - clock.monotonic() };
59986
59990
  return {
@@ -59994,7 +59998,7 @@ function createWakeDetector(clock, thresholdMs = WAKE_THRESHOLD_MS, platform3 =
59994
59998
  }
59995
59999
  };
59996
60000
  }
59997
- function wakeJob(clock, onWake, thresholdMs = WAKE_THRESHOLD_MS, platform3 = process.platform) {
60001
+ function wakeJob(clock, onWake, platform3 = process.platform, thresholdMs = wakeThresholdMs(platform3)) {
59998
60002
  const detector = createWakeDetector(clock, thresholdMs, platform3);
59999
60003
  return {
60000
60004
  name: "wake.detect",
@@ -78213,6 +78217,7 @@ var REDIAL_BASE_MS = 1e3;
78213
78217
  var REDIAL_MAX_MS = 1e4;
78214
78218
  var MAX_CREDENTIAL_FAILURES = 3;
78215
78219
  var DISABLED_RETRY_MS = 5 * 6e4;
78220
+ var WAKE_PROBE_MS = 5e3;
78216
78221
  function redialDelayMs(attempt2) {
78217
78222
  return Math.min(REDIAL_BASE_MS * 2 ** attempt2, REDIAL_MAX_MS) * (0.5 + 0.5 * Math.random());
78218
78223
  }
@@ -78243,6 +78248,8 @@ function connectLink(options) {
78243
78248
  const counts = {};
78244
78249
  const retry = { pending: new AbortController(), attempt: 0, credentialFailures: 0 };
78245
78250
  const probe = { running: false };
78251
+ const wake = { recovering: null };
78252
+ const closing = new AbortController();
78246
78253
  const socket = lookup(
78247
78254
  new URL(LINK_NAMESPACE, wsUrl).toString(),
78248
78255
  {
@@ -78413,20 +78420,59 @@ function connectLink(options) {
78413
78420
  return false;
78414
78421
  }
78415
78422
  };
78423
+ const redial2 = () => {
78424
+ retry.attempt = 0;
78425
+ retry.credentialFailures = 0;
78426
+ cancelRedial();
78427
+ setState({ kind: "connecting", lastFailure: null });
78428
+ log.info("link.redial", { connected: socket.connected });
78429
+ if (socket.connected) {
78430
+ socket.io.engine.close();
78431
+ return;
78432
+ }
78433
+ socket.disconnect();
78434
+ socket.connect();
78435
+ };
78436
+ const hearsServer = (timeoutMs) => new Promise((resolve14) => {
78437
+ const waiting = new AbortController();
78438
+ const settle = (alive) => {
78439
+ waiting.abort();
78440
+ socket.io.off("ping", onPing);
78441
+ socket.off("disconnect", onDrop);
78442
+ resolve14(alive);
78443
+ };
78444
+ const onPing = () => settle(true);
78445
+ const onDrop = () => settle(false);
78446
+ socket.io.on("ping", onPing);
78447
+ socket.on("disconnect", onDrop);
78448
+ clock.sleep(timeoutMs, AbortSignal.any([waiting.signal, closing.signal])).then(
78449
+ () => settle(false),
78450
+ () => settle(false)
78451
+ );
78452
+ });
78453
+ const recover = async () => {
78454
+ if (current.kind !== "stopped" && socket.connected) {
78455
+ const alive = await hearsServer(options.wakeProbeMs ?? WAKE_PROBE_MS);
78456
+ if (closing.signal.aborted) return "closed";
78457
+ log.info("link.wake_probe", { alive });
78458
+ if (alive) return "alive";
78459
+ }
78460
+ redial2();
78461
+ return "redialed";
78462
+ };
78416
78463
  return {
78417
78464
  state: () => current,
78418
78465
  failureCounts: () => ({ ...counts }),
78419
- redial: () => {
78420
- retry.attempt = 0;
78421
- retry.credentialFailures = 0;
78422
- cancelRedial();
78423
- setState({ kind: "connecting", lastFailure: null });
78424
- log.info("link.redial", {});
78425
- socket.disconnect();
78426
- socket.connect();
78466
+ redial: redial2,
78467
+ recoverAfterWake: () => {
78468
+ wake.recovering ??= recover().finally(() => {
78469
+ wake.recovering = null;
78470
+ });
78471
+ return wake.recovering;
78427
78472
  },
78428
78473
  pushCapabilities,
78429
78474
  [Symbol.asyncDispose]: async () => {
78475
+ closing.abort();
78430
78476
  cancelRedial();
78431
78477
  socket.removeAllListeners();
78432
78478
  socket.disconnect();
@@ -79117,6 +79163,7 @@ function startRuntimeUpdates(options) {
79117
79163
 
79118
79164
  // src/cli/commands/machine-plane.ts
79119
79165
  var MAINTENANCE_EVERY_MS = 3e3;
79166
+ var WAKE_CHECK_EVERY_MS = 500;
79120
79167
  var CAPABILITY_CHECK_MS = 15 * 6e4;
79121
79168
  var CAPABILITY_STALE_AFTER_MS = 60 * 6e4;
79122
79169
  var LOCAL_SKILLS_RESCAN_MS = 6e4;
@@ -79570,12 +79617,13 @@ async function startMachinePlane(deps) {
79570
79617
  stack.defer(() => link[Symbol.asyncDispose]());
79571
79618
  stack.use(
79572
79619
  startMaintenance({
79573
- everyMs: MAINTENANCE_EVERY_MS,
79620
+ everyMs: WAKE_CHECK_EVERY_MS,
79574
79621
  jobs: [
79575
79622
  wakeJob(clock, (sleptMs) => {
79576
79623
  log.info("runtime.woke", { sleptMs });
79577
- link.redial();
79578
- refreshDesired();
79624
+ link.recoverAfterWake().then((recovery) => {
79625
+ if (recovery === "alive") refreshDesired();
79626
+ }).catch((error61) => log.warn("runtime.wake_recovery_failed", { error: error61 }));
79579
79627
  })
79580
79628
  ],
79581
79629
  clock,
@@ -80336,7 +80384,8 @@ keeps running and waits for setup.
80336
80384
 
80337
80385
  While a turn runs it holds an idle-sleep assertion (macOS caffeinate -i, Linux
80338
80386
  systemd-inhibit --what=idle), never the display and never a sleep you ask for. After
80339
- the computer wakes it redials Alan and re-reads its work at once.
80387
+ the computer wakes it checks its link to Alan, redials if the link has gone quiet, and
80388
+ re-reads its work.
80340
80389
 
80341
80390
  Exit codes: 0 stopped; 75 restart requested;
80342
80391
  73 another runtime holds the lock; 78 invalid configuration;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alan-ai-hq/agent-manager-darwin-arm64",
3
- "version": "0.1.149",
3
+ "version": "0.1.151",
4
4
  "description": "Alan machine runtime (alan-agent) for one platform: the official Node.js binary, the runtime bundle and its launcher. Installed by @alan-ai-hq/agent-manager.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://tryalan.ai",