@openape/apes 0.13.1 → 0.14.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
@@ -2461,23 +2461,18 @@ import { defineCommand as defineCommand22 } from "citty";
2461
2461
  import consola20 from "consola";
2462
2462
 
2463
2463
  // src/proxy/config.ts
2464
- import { homedir as homedir4 } from "os";
2465
- import { join as join2 } from "path";
2466
- function defaultAuditPath() {
2467
- const xdg = process.env.XDG_STATE_HOME;
2468
- const stateDir = xdg && xdg.length > 0 ? xdg : join2(homedir4(), ".local", "state");
2469
- return join2(stateDir, "openape", "proxy-audit.jsonl");
2470
- }
2471
- function buildDefaultProxyConfigToml() {
2472
- const auditPath = defaultAuditPath();
2473
- return `# Auto-generated by apes proxy -- (M1a). Do not edit; this file is
2474
- # recreated for every \`apes proxy --\` invocation and deleted on exit.
2464
+ function buildDefaultProxyConfigToml(opts) {
2465
+ const defaultAction = opts.mediated ? "request" : "allow";
2466
+ const escEmail = opts.agentEmail.replace(/"/g, '\\"');
2467
+ const escIdp = opts.idpUrl.replace(/"/g, '\\"');
2468
+ return `# Auto-generated by \`apes proxy --\`. Do not edit; this file is
2469
+ # recreated for every invocation and deleted on exit.
2470
+ # Mode: ${opts.mediated ? "IdP-mediated (every unmatched host \u2192 grant flow)" : "transparent (default-allow + audit-only)"}.
2475
2471
  [proxy]
2476
2472
  listen = "127.0.0.1:0"
2477
- idp_url = "https://id.openape.ai"
2478
- agent_email = "ephemeral@apes-proxy.local"
2479
- default_action = "allow"
2480
- audit_log = "${auditPath.replace(/"/g, '\\"')}"
2473
+ idp_url = "${escIdp}"
2474
+ agent_email = "${escEmail}"
2475
+ default_action = "${defaultAction}"
2481
2476
 
2482
2477
  # Cloud / link-local metadata endpoints \u2014 never let agent traffic reach these
2483
2478
  # even if a downstream policy mistake would otherwise allow it.
@@ -2500,7 +2495,7 @@ import { spawn } from "child_process";
2500
2495
  import { mkdtempSync, rmSync, writeFileSync } from "fs";
2501
2496
  import { createRequire } from "module";
2502
2497
  import { tmpdir } from "os";
2503
- import { dirname, join as join3, resolve as resolve2 } from "path";
2498
+ import { dirname, join as join2, resolve as resolve2 } from "path";
2504
2499
  var require2 = createRequire(import.meta.url);
2505
2500
  function findProxyBin() {
2506
2501
  const pkgPath = require2.resolve("@openape/proxy/package.json");
@@ -2512,8 +2507,8 @@ function findProxyBin() {
2512
2507
  return resolve2(dirname(pkgPath), binRel);
2513
2508
  }
2514
2509
  async function startEphemeralProxy(configToml) {
2515
- const tmpDir = mkdtempSync(join3(tmpdir(), "openape-proxy-"));
2516
- const configPath = join3(tmpDir, "config.toml");
2510
+ const tmpDir = mkdtempSync(join2(tmpdir(), "openape-proxy-"));
2511
+ const configPath = join2(tmpDir, "config.toml");
2517
2512
  writeFileSync(configPath, configToml, { mode: 384 });
2518
2513
  const binPath = findProxyBin();
2519
2514
  const child = spawn(process.execPath, [binPath, "-c", configPath], {
@@ -2596,6 +2591,19 @@ function waitForListenLine(child) {
2596
2591
  }
2597
2592
 
2598
2593
  // src/commands/proxy.ts
2594
+ function resolveProxyConfigOptions() {
2595
+ const auth = loadAuth();
2596
+ if (!auth?.email || !auth?.idp) {
2597
+ throw new CliError(
2598
+ "apes proxy requires `apes login` first.\n\nWithout a login the proxy has no agent identity to attribute grant\nrequests to, so the YOLO / Allow / Deny policy on id.openape.ai cannot\napply. Run:\n\n apes login\n\nand re-run `apes proxy -- ...`.",
2599
+ // 77 = EX_NOPERM from sysexits.h ("permission denied"); fits "user has\n'
2600
+ // not authenticated to use this command" better than the default 1.
2601
+ 77
2602
+ );
2603
+ }
2604
+ consola20.info(`[apes proxy] IdP-mediated mode \u2014 agent=${auth.email}, idp=${auth.idp}`);
2605
+ return { agentEmail: auth.email, idpUrl: auth.idp, mediated: true };
2606
+ }
2599
2607
  var proxyCommand = defineCommand22({
2600
2608
  meta: {
2601
2609
  name: "proxy",
@@ -2620,7 +2628,7 @@ var proxyCommand = defineCommand22({
2620
2628
  proxyUrl = reuseUrl;
2621
2629
  consola20.info(`[apes proxy] reusing existing proxy at ${proxyUrl}`);
2622
2630
  } else {
2623
- const ephemeral = await startEphemeralProxy(buildDefaultProxyConfigToml());
2631
+ const ephemeral = await startEphemeralProxy(buildDefaultProxyConfigToml(resolveProxyConfigOptions()));
2624
2632
  proxyUrl = ephemeral.url;
2625
2633
  close = ephemeral.close;
2626
2634
  consola20.info(`[apes proxy] started ephemeral proxy at ${proxyUrl}`);
@@ -2936,7 +2944,7 @@ var mcpCommand = defineCommand27({
2936
2944
  if (transport !== "stdio" && transport !== "sse") {
2937
2945
  throw new Error('Transport must be "stdio" or "sse"');
2938
2946
  }
2939
- const { startMcpServer } = await import("./server-6RPIR76X.js");
2947
+ const { startMcpServer } = await import("./server-Z4PCQEB3.js");
2940
2948
  await startMcpServer(transport, port);
2941
2949
  }
2942
2950
  });
@@ -2945,7 +2953,7 @@ var mcpCommand = defineCommand27({
2945
2953
  import { existsSync as existsSync3, copyFileSync, writeFileSync as writeFileSync2 } from "fs";
2946
2954
  import { randomBytes } from "crypto";
2947
2955
  import { execFileSync as execFileSync3 } from "child_process";
2948
- import { join as join4 } from "path";
2956
+ import { join as join3 } from "path";
2949
2957
  import { defineCommand as defineCommand28 } from "citty";
2950
2958
  import consola23 from "consola";
2951
2959
  var DEFAULT_IDP_URL = "https://id.openape.at";
@@ -2954,7 +2962,7 @@ async function downloadTemplate(repo, targetDir) {
2954
2962
  await gigetDownload(`gh:${repo}`, { dir: targetDir, force: false });
2955
2963
  }
2956
2964
  function installDeps(dir) {
2957
- const hasLockFile = (name) => existsSync3(join4(dir, name));
2965
+ const hasLockFile = (name) => existsSync3(join3(dir, name));
2958
2966
  if (hasLockFile("pnpm-lock.yaml")) {
2959
2967
  execFileSync3("pnpm", ["install"], { cwd: dir, stdio: "inherit" });
2960
2968
  } else if (hasLockFile("bun.lockb")) {
@@ -3019,7 +3027,7 @@ var initCommand = defineCommand28({
3019
3027
  });
3020
3028
  async function initSP(targetDir) {
3021
3029
  const dir = targetDir || "my-app";
3022
- if (existsSync3(join4(dir, "package.json"))) {
3030
+ if (existsSync3(join3(dir, "package.json"))) {
3023
3031
  throw new CliError(`Directory "${dir}" already contains a project.`);
3024
3032
  }
3025
3033
  consola23.start("Scaffolding SP starter...");
@@ -3028,8 +3036,8 @@ async function initSP(targetDir) {
3028
3036
  consola23.start("Installing dependencies...");
3029
3037
  installDeps(dir);
3030
3038
  consola23.success("Dependencies installed");
3031
- const envExample = join4(dir, ".env.example");
3032
- const envFile = join4(dir, ".env");
3039
+ const envExample = join3(dir, ".env.example");
3040
+ const envFile = join3(dir, ".env");
3033
3041
  if (existsSync3(envExample) && !existsSync3(envFile)) {
3034
3042
  copyFileSync(envExample, envFile);
3035
3043
  consola23.success(`\`.env\` created (using Free IdP at ${DEFAULT_IDP_URL})`);
@@ -3044,7 +3052,7 @@ async function initSP(targetDir) {
3044
3052
  }
3045
3053
  async function initIdP(targetDir) {
3046
3054
  const dir = targetDir || "my-idp";
3047
- if (existsSync3(join4(dir, "package.json"))) {
3055
+ if (existsSync3(join3(dir, "package.json"))) {
3048
3056
  throw new CliError(`Directory "${dir}" already contains a project.`);
3049
3057
  }
3050
3058
  const domain = await promptText("Domain for the IdP", "localhost");
@@ -3076,7 +3084,7 @@ async function initIdP(targetDir) {
3076
3084
  `NUXT_OPENAPE_RP_ID=${domain}`,
3077
3085
  `NUXT_OPENAPE_RP_ORIGIN=${origin}`
3078
3086
  ].join("\n");
3079
- writeFileSync2(join4(dir, ".env"), `${envContent}
3087
+ writeFileSync2(join3(dir, ".env"), `${envContent}
3080
3088
  `, { mode: 384 });
3081
3089
  consola23.success(".env created");
3082
3090
  console.log("");
@@ -3101,7 +3109,7 @@ import { existsSync as existsSync4, readFileSync as readFileSync2, writeFileSync
3101
3109
  import { execFile as execFile2 } from "child_process";
3102
3110
  import { generateKeyPairSync, sign } from "crypto";
3103
3111
  import { dirname as dirname2, resolve as resolve3 } from "path";
3104
- import { homedir as homedir5 } from "os";
3112
+ import { homedir as homedir4 } from "os";
3105
3113
  import { defineCommand as defineCommand29 } from "citty";
3106
3114
  import consola24 from "consola";
3107
3115
  var DEFAULT_IDP_URL2 = "https://id.openape.at";
@@ -3109,7 +3117,7 @@ var DEFAULT_KEY_PATH = "~/.ssh/id_ed25519";
3109
3117
  var POLL_INTERVAL = 3e3;
3110
3118
  var POLL_TIMEOUT = 3e5;
3111
3119
  function resolvePath2(p) {
3112
- return resolve3(p.replace(/^~/, homedir5()));
3120
+ return resolve3(p.replace(/^~/, homedir4()));
3113
3121
  }
3114
3122
  function openBrowser2(url) {
3115
3123
  const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
@@ -3428,7 +3436,7 @@ async function bestEffortGrantCount(idp) {
3428
3436
  }
3429
3437
  }
3430
3438
  async function runHealth(args) {
3431
- const version = true ? "0.13.1" : "0.0.0";
3439
+ const version = true ? "0.14.1" : "0.0.0";
3432
3440
  const auth = loadAuth();
3433
3441
  if (!auth) {
3434
3442
  throw new CliError("Not logged in. Run `apes login` first.", 1);
@@ -3630,10 +3638,10 @@ if (shellRewrite) {
3630
3638
  if (shellRewrite.action === "rewrite") {
3631
3639
  process.argv = shellRewrite.argv;
3632
3640
  } else if (shellRewrite.action === "version") {
3633
- console.log(`ape-shell ${"0.13.1"} (OpenApe DDISA shell wrapper)`);
3641
+ console.log(`ape-shell ${"0.14.1"} (OpenApe DDISA shell wrapper)`);
3634
3642
  process.exit(0);
3635
3643
  } else if (shellRewrite.action === "help") {
3636
- console.log(`ape-shell ${"0.13.1"} \u2014 OpenApe DDISA shell wrapper`);
3644
+ console.log(`ape-shell ${"0.14.1"} \u2014 OpenApe DDISA shell wrapper`);
3637
3645
  console.log("");
3638
3646
  console.log("Usage:");
3639
3647
  console.log(" ape-shell Start interactive grant-mediated REPL");
@@ -3691,7 +3699,7 @@ var configCommand = defineCommand34({
3691
3699
  var main = defineCommand34({
3692
3700
  meta: {
3693
3701
  name: "apes",
3694
- version: "0.13.1",
3702
+ version: "0.14.1",
3695
3703
  description: "Unified CLI for OpenApe"
3696
3704
  },
3697
3705
  subCommands: {