@openape/apes 1.16.0 → 1.18.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.
package/dist/cli.js CHANGED
@@ -4163,9 +4163,15 @@ and try again.`
4163
4163
  troop
4164
4164
  });
4165
4165
  writeFileSync4(scriptPath, script, { mode: 448 });
4166
- consola23.start("Running privileged setup as root via `apes run --as root --wait`\u2026");
4167
- consola23.info("You will be asked to approve the as=root grant in your DDISA inbox; this command blocks until you do.");
4168
- execFileSync6(apes, ["run", "--as", "root", "--wait", "--", "bash", scriptPath], { stdio: "inherit" });
4166
+ const alreadyRoot = process.getuid?.() === 0;
4167
+ if (alreadyRoot) {
4168
+ consola23.start("Running privileged setup directly (already root)\u2026");
4169
+ execFileSync6("bash", [scriptPath], { stdio: "inherit" });
4170
+ } else {
4171
+ consola23.start("Running privileged setup as root via `apes run --as root --wait`\u2026");
4172
+ consola23.info("You will be asked to approve the as=root grant in your DDISA inbox; this command blocks until you do.");
4173
+ execFileSync6(apes, ["run", "--as", "root", "--wait", "--", "bash", scriptPath], { stdio: "inherit" });
4174
+ }
4169
4175
  try {
4170
4176
  const uid = readMacOSUidOrNull(name);
4171
4177
  upsertNestAgent({
@@ -4315,8 +4321,9 @@ var syncAgentCommand = defineCommand27({
4315
4321
  ownerEmail: auth.owner_email
4316
4322
  });
4317
4323
  consola24.info(sync.first_sync ? "\u2713 first sync \u2014 agent registered" : "\u2713 presence updated");
4318
- const { system_prompt: systemPrompt, tasks } = await client.listTasks();
4324
+ const { system_prompt: systemPrompt, tools, tasks } = await client.listTasks();
4319
4325
  consola24.info(`Pulled ${tasks.length} task${tasks.length === 1 ? "" : "s"}`);
4326
+ consola24.info(`Tools enabled: ${tools.length === 0 ? "(none)" : tools.join(", ")}`);
4320
4327
  let agentUid = null;
4321
4328
  let agentGid = null;
4322
4329
  if (process.geteuid?.() === 0) {
@@ -4342,7 +4349,7 @@ var syncAgentCommand = defineCommand27({
4342
4349
  const agentJsonPath = join8(agentDir, "agent.json");
4343
4350
  writeFileSync5(
4344
4351
  agentJsonPath,
4345
- `${JSON.stringify({ systemPrompt }, null, 2)}
4352
+ `${JSON.stringify({ systemPrompt, tools }, null, 2)}
4346
4353
  `,
4347
4354
  { mode: 384 }
4348
4355
  );
@@ -5815,6 +5822,19 @@ async function runAudienceMode(audience, action, args) {
5815
5822
  const grantsUrl = await getGrantsEndpoint(idp);
5816
5823
  const command = action.split(" ");
5817
5824
  const targetHost = args.host || hostname5();
5825
+ const runAs = args.as ?? void 0;
5826
+ const reusableId = await findReusableAudienceGrant({
5827
+ grantsUrl,
5828
+ requester: auth.email,
5829
+ audience,
5830
+ command,
5831
+ targetHost,
5832
+ runAs
5833
+ });
5834
+ if (reusableId) {
5835
+ const { authz_jwt: authz_jwt2 } = await apiFetch(`${grantsUrl}/${reusableId}/token`, { method: "POST" });
5836
+ return executeWithGrantToken({ audience, command, args, token: authz_jwt2 });
5837
+ }
5818
5838
  consola36.info(`Requesting ${audience} grant on ${targetHost}: ${command.join(" ")}`);
5819
5839
  const grant = await apiFetch(grantsUrl, {
5820
5840
  method: "POST",
@@ -5825,7 +5845,7 @@ async function runAudienceMode(audience, action, args) {
5825
5845
  grant_type: args.approval,
5826
5846
  command,
5827
5847
  reason: args.reason || command.join(" "),
5828
- ...args.as ? { run_as: args.as } : {}
5848
+ ...runAs ? { run_as: runAs } : {}
5829
5849
  }
5830
5850
  });
5831
5851
  if (!shouldWaitForGrant(args)) {
@@ -5861,11 +5881,15 @@ async function runAudienceMode(audience, action, args) {
5861
5881
  const { authz_jwt } = await apiFetch(`${grantsUrl}/${grant.id}/token`, {
5862
5882
  method: "POST"
5863
5883
  });
5884
+ return executeWithGrantToken({ audience, command, args, token: authz_jwt });
5885
+ }
5886
+ function executeWithGrantToken(opts) {
5887
+ const { audience, command, args, token } = opts;
5864
5888
  if (audience === "escapes") {
5865
5889
  consola36.info(`Executing: ${command.join(" ")}`);
5866
5890
  try {
5867
5891
  const { APES_SHELL_WRAPPER: _wrapperMarker, ...inheritedEnv } = process.env;
5868
- execFileSync13(args["escapes-path"] || "escapes", ["--grant", authz_jwt, "--", ...command], {
5892
+ execFileSync13(args["escapes-path"] || "escapes", ["--grant", token, "--", ...command], {
5869
5893
  stdio: "inherit",
5870
5894
  env: inheritedEnv
5871
5895
  });
@@ -5874,7 +5898,28 @@ async function runAudienceMode(audience, action, args) {
5874
5898
  throw new CliExit(exitCode);
5875
5899
  }
5876
5900
  } else {
5877
- process.stdout.write(authz_jwt);
5901
+ process.stdout.write(token);
5902
+ }
5903
+ }
5904
+ async function findReusableAudienceGrant(opts) {
5905
+ try {
5906
+ const grants = await apiFetch(`${opts.grantsUrl}?requester=${encodeURIComponent(opts.requester)}&status=approved&limit=50`);
5907
+ const now = Math.floor(Date.now() / 1e3);
5908
+ const match = grants.data.find((g) => {
5909
+ const r3 = g.request;
5910
+ if (r3.audience !== opts.audience) return false;
5911
+ if (r3.target_host !== opts.targetHost) return false;
5912
+ if (r3.grant_type === "once") return false;
5913
+ if (r3.grant_type === "timed" && g.expires_at && g.expires_at <= now) return false;
5914
+ const cmd = r3.command ?? [];
5915
+ if (cmd.length !== opts.command.length) return false;
5916
+ if (!cmd.every((c2, i) => c2 === opts.command[i])) return false;
5917
+ if ((r3.run_as ?? void 0) !== opts.runAs) return false;
5918
+ return true;
5919
+ });
5920
+ return match?.id ?? null;
5921
+ } catch {
5922
+ return null;
5878
5923
  }
5879
5924
  }
5880
5925
 
@@ -6367,7 +6412,7 @@ var mcpCommand = defineCommand48({
6367
6412
  if (transport !== "stdio" && transport !== "sse") {
6368
6413
  throw new Error('Transport must be "stdio" or "sse"');
6369
6414
  }
6370
- const { startMcpServer } = await import("./server-FVFFPVVN.js");
6415
+ const { startMcpServer } = await import("./server-BDZV6EI6.js");
6371
6416
  await startMcpServer(transport, port);
6372
6417
  }
6373
6418
  });
@@ -7005,7 +7050,7 @@ async function bestEffortGrantCount(idp) {
7005
7050
  }
7006
7051
  }
7007
7052
  async function runHealth(args) {
7008
- const version = true ? "1.16.0" : "0.0.0";
7053
+ const version = true ? "1.18.0" : "0.0.0";
7009
7054
  const auth = loadAuth();
7010
7055
  if (!auth) {
7011
7056
  throw new CliError("Not logged in. Run `apes login` first.", 1);
@@ -7278,10 +7323,10 @@ if (shellRewrite) {
7278
7323
  if (shellRewrite.action === "rewrite") {
7279
7324
  process.argv = shellRewrite.argv;
7280
7325
  } else if (shellRewrite.action === "version") {
7281
- console.log(`ape-shell ${"1.16.0"} (OpenApe DDISA shell wrapper)`);
7326
+ console.log(`ape-shell ${"1.18.0"} (OpenApe DDISA shell wrapper)`);
7282
7327
  process.exit(0);
7283
7328
  } else if (shellRewrite.action === "help") {
7284
- console.log(`ape-shell ${"1.16.0"} \u2014 OpenApe DDISA shell wrapper`);
7329
+ console.log(`ape-shell ${"1.18.0"} \u2014 OpenApe DDISA shell wrapper`);
7285
7330
  console.log("");
7286
7331
  console.log("Usage:");
7287
7332
  console.log(" ape-shell Start interactive grant-mediated REPL");
@@ -7339,7 +7384,7 @@ var configCommand = defineCommand60({
7339
7384
  var main = defineCommand60({
7340
7385
  meta: {
7341
7386
  name: "apes",
7342
- version: "1.16.0",
7387
+ version: "1.18.0",
7343
7388
  description: "Unified CLI for OpenApe"
7344
7389
  },
7345
7390
  subCommands: {
@@ -7396,7 +7441,7 @@ async function maybeRefreshAuth() {
7396
7441
  }
7397
7442
  }
7398
7443
  await maybeRefreshAuth();
7399
- await maybeWarnStaleVersion("1.16.0").catch(() => {
7444
+ await maybeWarnStaleVersion("1.18.0").catch(() => {
7400
7445
  });
7401
7446
  runMain(main).catch((err) => {
7402
7447
  if (err instanceof CliExit) {