@openape/apes 1.2.0 → 1.2.1

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/cli.js CHANGED
@@ -3343,16 +3343,18 @@ function escape(s) {
3343
3343
  }
3344
3344
  function buildSyncPlist(input) {
3345
3345
  const pathLine = ` <key>PATH</key><string>${escape(input.homeDir)}/.bun/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>
3346
+ `;
3347
+ const agentUserLine = ` <key>AGENT_USER</key><string>${escape(input.userName)}</string>
3346
3348
  `;
3347
3349
  const envBlock = input.troopUrl ? ` <key>EnvironmentVariables</key>
3348
3350
  <dict>
3349
3351
  <key>HOME</key><string>${escape(input.homeDir)}</string>
3350
- ${pathLine} <key>OPENAPE_TROOP_URL</key><string>${escape(input.troopUrl)}</string>
3352
+ ${pathLine}${agentUserLine} <key>OPENAPE_TROOP_URL</key><string>${escape(input.troopUrl)}</string>
3351
3353
  </dict>
3352
3354
  ` : ` <key>EnvironmentVariables</key>
3353
3355
  <dict>
3354
3356
  <key>HOME</key><string>${escape(input.homeDir)}</string>
3355
- ${pathLine} </dict>
3357
+ ${pathLine}${agentUserLine} </dict>
3356
3358
  `;
3357
3359
  return `<?xml version="1.0" encoding="UTF-8"?>
3358
3360
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -3360,8 +3362,6 @@ ${pathLine} </dict>
3360
3362
  <dict>
3361
3363
  <key>Label</key>
3362
3364
  <string>${escape(syncPlistLabel(input.agentName))}</string>
3363
- <key>UserName</key>
3364
- <string>${escape(input.userName)}</string>
3365
3365
  <key>ProgramArguments</key>
3366
3366
  <array>
3367
3367
  <string>${escape(input.apesBin)}</string>
@@ -3750,8 +3750,8 @@ async function resolveClaudeToken(opts) {
3750
3750
  }
3751
3751
 
3752
3752
  // src/commands/agents/sync.ts
3753
- import { existsSync as existsSync9, mkdirSync as mkdirSync4, readFileSync as readFileSync10, writeFileSync as writeFileSync6 } from "fs";
3754
- import { homedir as homedir10 } from "os";
3753
+ import { chownSync, existsSync as existsSync9, mkdirSync as mkdirSync4, readFileSync as readFileSync10, statSync, writeFileSync as writeFileSync6 } from "fs";
3754
+ import { homedir as homedir9 } from "os";
3755
3755
  import { join as join8 } from "path";
3756
3756
  import { defineCommand as defineCommand27 } from "citty";
3757
3757
  import consola24 from "consola";
@@ -3759,11 +3759,11 @@ import consola24 from "consola";
3759
3759
  // src/lib/launchd-reconcile.ts
3760
3760
  import { execFileSync as execFileSync8 } from "child_process";
3761
3761
  import { mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync9, unlinkSync, writeFileSync as writeFileSync5 } from "fs";
3762
- import { homedir as homedir9, userInfo as userInfo2 } from "os";
3762
+ import { userInfo as userInfo2 } from "os";
3763
3763
  import { join as join7 } from "path";
3764
3764
  var PLIST_PREFIX = "openape.troop.";
3765
3765
  function plistDir() {
3766
- return join7(homedir9(), "Library", "LaunchAgents");
3766
+ return "/Library/LaunchDaemons";
3767
3767
  }
3768
3768
  function plistPath(agentName, taskId) {
3769
3769
  return join7(plistDir(), `${PLIST_PREFIX}${agentName}.${taskId}.plist`);
@@ -3848,6 +3848,8 @@ ${calendarBlocks}
3848
3848
  <dict>
3849
3849
  <key>Label</key>
3850
3850
  <string>${escape2(input.label)}</string>
3851
+ <key>UserName</key>
3852
+ <string>${escape2(input.userName)}</string>
3851
3853
  <key>ProgramArguments</key>
3852
3854
  <array>
3853
3855
  <string>${escape2(input.apesBin)}</string>
@@ -3861,6 +3863,8 @@ ${calendarBlocks}
3861
3863
  <dict>
3862
3864
  <key>HOME</key>
3863
3865
  <string>${escape2(input.homeDir)}</string>
3866
+ <key>PATH</key>
3867
+ <string>${escape2(input.homeDir)}/.bun/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>
3864
3868
  </dict>
3865
3869
  ${calendarKey}
3866
3870
  <key>StandardOutPath</key>
@@ -3877,22 +3881,20 @@ function buildPlistContent(args) {
3877
3881
  apesBin: args.apesBin,
3878
3882
  taskId: args.task.taskId,
3879
3883
  schedule: cronToSchedule(args.task.cron),
3880
- homeDir: args.homeDir
3884
+ homeDir: args.homeDir,
3885
+ userName: args.userName ?? userInfo2().username
3881
3886
  });
3882
3887
  }
3883
- function uid() {
3884
- return userInfo2().uid;
3885
- }
3886
3888
  function bootstrap(label, path2) {
3887
3889
  try {
3888
- execFileSync8("/bin/launchctl", ["bootout", `gui/${uid()}/${label}`], { stdio: "ignore" });
3890
+ execFileSync8("/bin/launchctl", ["bootout", `system/${label}`], { stdio: "ignore" });
3889
3891
  } catch {
3890
3892
  }
3891
- execFileSync8("/bin/launchctl", ["bootstrap", `gui/${uid()}`, path2], { stdio: "ignore" });
3893
+ execFileSync8("/bin/launchctl", ["bootstrap", "system", path2], { stdio: "ignore" });
3892
3894
  }
3893
3895
  function bootout(label) {
3894
3896
  try {
3895
- execFileSync8("/bin/launchctl", ["bootout", `gui/${uid()}/${label}`], { stdio: "ignore" });
3897
+ execFileSync8("/bin/launchctl", ["bootout", `system/${label}`], { stdio: "ignore" });
3896
3898
  } catch {
3897
3899
  }
3898
3900
  }
@@ -3921,7 +3923,8 @@ function reconcile(input) {
3921
3923
  agentName: input.agentName,
3922
3924
  apesBin: input.apesBin,
3923
3925
  homeDir: input.homeDir,
3924
- task
3926
+ task,
3927
+ userName: input.userName
3925
3928
  });
3926
3929
  let existingContent = "";
3927
3930
  try {
@@ -3968,8 +3971,8 @@ function getHostname() {
3968
3971
  }
3969
3972
 
3970
3973
  // src/commands/agents/sync.ts
3971
- var AUTH_PATH3 = join8(homedir10(), ".config", "apes", "auth.json");
3972
- var TASK_CACHE_DIR2 = join8(homedir10(), ".openape", "agent", "tasks");
3974
+ var AUTH_PATH3 = join8(homedir9(), ".config", "apes", "auth.json");
3975
+ var TASK_CACHE_DIR2 = join8(homedir9(), ".openape", "agent", "tasks");
3973
3976
  function readAuthJson() {
3974
3977
  if (!existsSync9(AUTH_PATH3)) {
3975
3978
  throw new CliError(
@@ -4041,26 +4044,54 @@ var syncAgentCommand = defineCommand27({
4041
4044
  consola24.info(sync.first_sync ? "\u2713 first sync \u2014 agent registered" : "\u2713 presence updated");
4042
4045
  const { system_prompt: systemPrompt, tasks } = await client.listTasks();
4043
4046
  consola24.info(`Pulled ${tasks.length} task${tasks.length === 1 ? "" : "s"}`);
4044
- const agentDir = join8(homedir10(), ".openape", "agent");
4047
+ let agentUid = null;
4048
+ let agentGid = null;
4049
+ if (process.geteuid?.() === 0) {
4050
+ try {
4051
+ const homeStat = statSync(homedir9());
4052
+ agentUid = homeStat.uid;
4053
+ agentGid = homeStat.gid;
4054
+ } catch {
4055
+ }
4056
+ }
4057
+ function chownToAgent(path2) {
4058
+ if (agentUid !== null && agentGid !== null) {
4059
+ try {
4060
+ chownSync(path2, agentUid, agentGid);
4061
+ } catch {
4062
+ }
4063
+ }
4064
+ }
4065
+ const agentDir = join8(homedir9(), ".openape", "agent");
4045
4066
  mkdirSync4(agentDir, { recursive: true });
4067
+ chownToAgent(join8(homedir9(), ".openape"));
4068
+ chownToAgent(agentDir);
4069
+ const agentJsonPath = join8(agentDir, "agent.json");
4046
4070
  writeFileSync6(
4047
- join8(agentDir, "agent.json"),
4071
+ agentJsonPath,
4048
4072
  `${JSON.stringify({ systemPrompt }, null, 2)}
4049
4073
  `,
4050
4074
  { mode: 384 }
4051
4075
  );
4076
+ chownToAgent(agentJsonPath);
4052
4077
  mkdirSync4(TASK_CACHE_DIR2, { recursive: true });
4078
+ chownToAgent(TASK_CACHE_DIR2);
4053
4079
  for (const task of tasks) {
4054
4080
  const path2 = join8(TASK_CACHE_DIR2, `${task.taskId}.json`);
4055
4081
  writeFileSync6(path2, `${JSON.stringify(task, null, 2)}
4056
4082
  `, { mode: 384 });
4083
+ chownToAgent(path2);
4057
4084
  }
4058
4085
  const apesBin = findApesBin();
4059
4086
  const result = reconcile({
4060
4087
  agentName,
4061
4088
  apesBin,
4062
- homeDir: homedir10(),
4063
- desired: tasks
4089
+ homeDir: homedir9(),
4090
+ desired: tasks,
4091
+ // Sync runs as root in production — pass the agent username
4092
+ // explicitly for the UserName plist key (launchd will then run
4093
+ // each task daemon AS the agent, not as root).
4094
+ userName: process.env.AGENT_USER || void 0
4064
4095
  });
4065
4096
  if (result.added.length) consola24.success(`launchd: added ${result.added.join(", ")}`);
4066
4097
  if (result.updated.length) consola24.success(`launchd: updated ${result.updated.join(", ")}`);
@@ -5349,7 +5380,7 @@ var mcpCommand = defineCommand36({
5349
5380
  if (transport !== "stdio" && transport !== "sse") {
5350
5381
  throw new Error('Transport must be "stdio" or "sse"');
5351
5382
  }
5352
- const { startMcpServer } = await import("./server-6OLIVAHI.js");
5383
+ const { startMcpServer } = await import("./server-YDC3S4PC.js");
5353
5384
  await startMcpServer(transport, port);
5354
5385
  }
5355
5386
  });
@@ -5987,7 +6018,7 @@ async function bestEffortGrantCount(idp) {
5987
6018
  }
5988
6019
  }
5989
6020
  async function runHealth(args) {
5990
- const version = true ? "1.2.0" : "0.0.0";
6021
+ const version = true ? "1.2.1" : "0.0.0";
5991
6022
  const auth = loadAuth();
5992
6023
  if (!auth) {
5993
6024
  throw new CliError("Not logged in. Run `apes login` first.", 1);
@@ -6181,12 +6212,12 @@ var workflowsCommand = defineCommand47({
6181
6212
 
6182
6213
  // src/version-check.ts
6183
6214
  import { existsSync as existsSync13, mkdirSync as mkdirSync5, readFileSync as readFileSync13, writeFileSync as writeFileSync9 } from "fs";
6184
- import { homedir as homedir11 } from "os";
6215
+ import { homedir as homedir10 } from "os";
6185
6216
  import { join as join11 } from "path";
6186
6217
  import consola38 from "consola";
6187
6218
  var PACKAGE_NAME = "@openape/apes";
6188
6219
  var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
6189
- var CACHE_FILE = join11(homedir11(), ".config", "apes", ".version-check.json");
6220
+ var CACHE_FILE = join11(homedir10(), ".config", "apes", ".version-check.json");
6190
6221
  function readCache() {
6191
6222
  if (!existsSync13(CACHE_FILE)) return null;
6192
6223
  try {
@@ -6197,7 +6228,7 @@ function readCache() {
6197
6228
  }
6198
6229
  function writeCache(entry) {
6199
6230
  try {
6200
- const dir = join11(homedir11(), ".config", "apes");
6231
+ const dir = join11(homedir10(), ".config", "apes");
6201
6232
  if (!existsSync13(dir)) mkdirSync5(dir, { recursive: true, mode: 448 });
6202
6233
  writeFileSync9(CACHE_FILE, JSON.stringify(entry), { mode: 384 });
6203
6234
  } catch {
@@ -6260,10 +6291,10 @@ if (shellRewrite) {
6260
6291
  if (shellRewrite.action === "rewrite") {
6261
6292
  process.argv = shellRewrite.argv;
6262
6293
  } else if (shellRewrite.action === "version") {
6263
- console.log(`ape-shell ${"1.2.0"} (OpenApe DDISA shell wrapper)`);
6294
+ console.log(`ape-shell ${"1.2.1"} (OpenApe DDISA shell wrapper)`);
6264
6295
  process.exit(0);
6265
6296
  } else if (shellRewrite.action === "help") {
6266
- console.log(`ape-shell ${"1.2.0"} \u2014 OpenApe DDISA shell wrapper`);
6297
+ console.log(`ape-shell ${"1.2.1"} \u2014 OpenApe DDISA shell wrapper`);
6267
6298
  console.log("");
6268
6299
  console.log("Usage:");
6269
6300
  console.log(" ape-shell Start interactive grant-mediated REPL");
@@ -6321,7 +6352,7 @@ var configCommand = defineCommand48({
6321
6352
  var main = defineCommand48({
6322
6353
  meta: {
6323
6354
  name: "apes",
6324
- version: "1.2.0",
6355
+ version: "1.2.1",
6325
6356
  description: "Unified CLI for OpenApe"
6326
6357
  },
6327
6358
  subCommands: {
@@ -6376,7 +6407,7 @@ async function maybeRefreshAuth() {
6376
6407
  }
6377
6408
  }
6378
6409
  await maybeRefreshAuth();
6379
- await maybeWarnStaleVersion("1.2.0").catch(() => {
6410
+ await maybeWarnStaleVersion("1.2.1").catch(() => {
6380
6411
  });
6381
6412
  runMain(main).catch((err) => {
6382
6413
  if (err instanceof CliExit) {