@openape/nest 2.1.2 → 2.2.0

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 +35 -9
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -35,12 +35,22 @@ function listAgents() {
35
35
 
36
36
  // src/lib/pm2-supervisor.ts
37
37
  import { execFile } from "child_process";
38
- import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
38
+ import { chmodSync, existsSync as existsSync2, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
39
39
  import { join as join2 } from "path";
40
40
  import process2 from "process";
41
41
  import { promisify } from "util";
42
42
  var execFileAsync = promisify(execFile);
43
43
  var AGENTS_DIR = "/var/openape/agents";
44
+ var SHARED_DIR_MODE = 1533;
45
+ function ensureSharedDir(path) {
46
+ mkdirSync2(path, { recursive: true, mode: SHARED_DIR_MODE });
47
+ if (existsSync2(path)) {
48
+ try {
49
+ chmodSync(path, SHARED_DIR_MODE);
50
+ } catch {
51
+ }
52
+ }
53
+ }
44
54
  function pm2AppName(agentName) {
45
55
  return `openape-bridge-${agentName}`;
46
56
  }
@@ -119,13 +129,13 @@ var Pm2Supervisor = class {
119
129
  async stopAll() {
120
130
  }
121
131
  async startOrReload(agentName) {
122
- mkdirSync2(AGENTS_DIR, { recursive: true, mode: 493 });
132
+ ensureSharedDir(AGENTS_DIR);
123
133
  const dir = join2(AGENTS_DIR, agentName);
124
- mkdirSync2(dir, { recursive: true, mode: 493 });
134
+ ensureSharedDir(dir);
125
135
  const path = ecosystemPath(agentName);
126
- writeFileSync2(path, ecosystemContents(this.deps.apesBin, agentName), { mode: 420 });
136
+ writeFileSync2(path, ecosystemContents(this.deps.apesBin, agentName), { mode: 436 });
127
137
  const startPath = startScriptPath(agentName);
128
- writeFileSync2(startPath, startScriptContents(agentName), { mode: 493 });
138
+ writeFileSync2(startPath, startScriptContents(agentName), { mode: 509 });
129
139
  void path;
130
140
  try {
131
141
  await this.runAsAgent(agentName, ["bash", startPath]);
@@ -231,7 +241,7 @@ import { hostname, networkInterfaces } from "os";
231
241
 
232
242
  // ../../packages/cli-auth/dist/index.js
233
243
  import { ofetch } from "ofetch";
234
- import { existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync2, readdirSync, unlinkSync, writeFileSync as writeFileSync3 } from "fs";
244
+ import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync2, readdirSync, unlinkSync, writeFileSync as writeFileSync3 } from "fs";
235
245
  import { homedir as homedir2 } from "os";
236
246
  import { join as join3 } from "path";
237
247
  import { ofetch as ofetch3 } from "ofetch";
@@ -254,13 +264,13 @@ function getAuthFile() {
254
264
  }
255
265
  function ensureConfigDir() {
256
266
  const dir = getConfigDir();
257
- if (!existsSync2(dir)) {
267
+ if (!existsSync3(dir)) {
258
268
  mkdirSync3(dir, { recursive: true, mode: 448 });
259
269
  }
260
270
  }
261
271
  function loadIdpAuth() {
262
272
  const file = getAuthFile();
263
- if (!existsSync2(file)) return null;
273
+ if (!existsSync3(file)) return null;
264
274
  try {
265
275
  const raw = readFileSync2(file, "utf-8");
266
276
  if (!raw.trim()) return null;
@@ -273,7 +283,7 @@ function saveIdpAuth(auth) {
273
283
  ensureConfigDir();
274
284
  const file = getAuthFile();
275
285
  let extra = {};
276
- if (existsSync2(file)) {
286
+ if (existsSync3(file)) {
277
287
  try {
278
288
  const raw = readFileSync2(file, "utf-8");
279
289
  if (raw.trim()) {
@@ -648,6 +658,10 @@ var TroopWs = class {
648
658
  await this.handleSpawnIntent(frame);
649
659
  return;
650
660
  }
661
+ if (frame.type === "destroy-intent") {
662
+ await this.handleDestroyIntent(frame);
663
+ return;
664
+ }
651
665
  if (frame.type === "reload-bridge") {
652
666
  await this.handleReloadBridge(frame);
653
667
  }
@@ -678,6 +692,18 @@ var TroopWs = class {
678
692
  this.send({ type: "spawn-result", intent_id: frame.intent_id, ok: false, error });
679
693
  }
680
694
  }
695
+ async handleDestroyIntent(frame) {
696
+ this.opts.log(`troop-ws: destroy-intent ${frame.name} (intent ${frame.intent_id})`);
697
+ try {
698
+ await runWithCapture(this.opts.apesBin, ["agents", "destroy", frame.name, "--force"]);
699
+ this.opts.log(`troop-ws: destroy-result ${frame.name} ok`);
700
+ this.send({ type: "destroy-result", intent_id: frame.intent_id, ok: true, name: frame.name });
701
+ } catch (err) {
702
+ const error = err instanceof Error ? err.message : String(err);
703
+ this.opts.log(`troop-ws: destroy-result ${frame.name} FAIL: ${error}`);
704
+ this.send({ type: "destroy-result", intent_id: frame.intent_id, ok: false, name: frame.name, error });
705
+ }
706
+ }
681
707
  async handleReloadBridge(frame) {
682
708
  this.opts.log(`troop-ws: reload-bridge ${frame.name}`);
683
709
  await this.runApes(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openape/nest",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
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",