@openape/nest 2.1.0 → 2.1.2

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/dist/index.mjs +22 -6
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -8,8 +8,14 @@ import process4 from "process";
8
8
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
9
9
  import { homedir } from "os";
10
10
  import { join } from "path";
11
- var REGISTRY_DIR = homedir();
12
- var REGISTRY_PATH = join(REGISTRY_DIR, "agents.json");
11
+ function resolveRegistryPath() {
12
+ if (process.env.OPENAPE_NEST_REGISTRY_PATH) return process.env.OPENAPE_NEST_REGISTRY_PATH;
13
+ if (existsSync("/var/openape/nest/agents.json")) return "/var/openape/nest/agents.json";
14
+ if (existsSync("/var/openape/nest")) return "/var/openape/nest/agents.json";
15
+ return join(homedir(), "agents.json");
16
+ }
17
+ var REGISTRY_PATH = resolveRegistryPath();
18
+ var REGISTRY_DIR = REGISTRY_PATH.replace(/\/agents\.json$/, "");
13
19
  function emptyRegistry() {
14
20
  return { version: 1, agents: [] };
15
21
  }
@@ -105,9 +111,11 @@ var Pm2Supervisor = class {
105
111
  this.deps.log(`pm2-supervisor: delete ${name}: ${err instanceof Error ? err.message.split("\n")[0] : String(err)}`);
106
112
  }
107
113
  }
108
- /** Best-effort cleanup — called on Nest shutdown. We don't kill
114
+ /**
115
+ * Best-effort cleanup — called on Nest shutdown. We don't kill
109
116
  * the per-agent pm2-daemons; they should keep running so bridges
110
- * stay alive across Nest restarts. No-op for now. */
117
+ * stay alive across Nest restarts. No-op for now.
118
+ */
111
119
  async stopAll() {
112
120
  }
113
121
  async startOrReload(agentName) {
@@ -139,7 +147,8 @@ var Pm2Supervisor = class {
139
147
  this.deps.log(`pm2-supervisor: ${agentName} bridge NOT online \u2014 see /var/log/openape/${agentName}-pm2.log`);
140
148
  }
141
149
  }
142
- /** Run a pm2 subcommand AS the agent — escapes-helper does the
150
+ /**
151
+ * Run a pm2 subcommand AS the agent — escapes-helper does the
143
152
  * setuid switch, then exec's pm2 in the agent's uid.
144
153
  *
145
154
  * cwd: the agent process inherits cwd from the spawning Nest
@@ -661,9 +670,11 @@ var TroopWs = class {
661
670
  const { stdout } = await runWithCapture(this.opts.apesBin, args);
662
671
  const match = stdout.match(/Registered as\s+(\S+@\S+)/);
663
672
  const agentEmail = match?.[1];
673
+ this.opts.log(`troop-ws: spawn-result ${frame.name} ok agent=${agentEmail ?? "?"}`);
664
674
  this.send({ type: "spawn-result", intent_id: frame.intent_id, ok: true, agent_email: agentEmail });
665
675
  } catch (err) {
666
676
  const error = err instanceof Error ? err.message : String(err);
677
+ this.opts.log(`troop-ws: spawn-result ${frame.name} FAIL: ${error}`);
667
678
  this.send({ type: "spawn-result", intent_id: frame.intent_id, ok: false, error });
668
679
  }
669
680
  }
@@ -693,8 +704,13 @@ var TroopWs = class {
693
704
  };
694
705
  function runWithCapture(bin, args) {
695
706
  return new Promise((resolve, reject) => {
696
- execFile3(bin, args, { maxBuffer: 4 * 1024 * 1024 }, (err, stdout, stderr) => {
707
+ execFile3(bin, args, { maxBuffer: 4 * 1024 * 1024, timeout: 12e4 }, (err, stdout, stderr) => {
697
708
  if (err) {
709
+ const isTimeout = err.signal === "SIGTERM";
710
+ if (isTimeout) {
711
+ resolve({ stdout: stdout.toString(), stderr: stderr.toString() });
712
+ return;
713
+ }
698
714
  const msg = stderr.toString() || err.message;
699
715
  reject(new Error(msg.split("\n").filter(Boolean).slice(-3).join(" / ")));
700
716
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openape/nest",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "OpenApe Nest — local control-plane daemon that supervises agent processes on this computer. Talks to troop SP for ownership state, spawns/destroys agents via DDISA always-grants, supervises chat-bridge children (replacing per-agent launchd plists).",
5
5
  "type": "module",
6
6
  "license": "MIT",