@openape/apes 0.9.2 → 0.9.3

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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CONFIG_DIR
4
- } from "./chunk-AZVY3X7Q.js";
4
+ } from "./chunk-ILKZ5HGV.js";
5
5
 
6
6
  // src/auth-lock.ts
7
7
  import { open, rm, stat } from "fs/promises";
@@ -38,4 +38,4 @@ export {
38
38
  acquireAuthLock,
39
39
  releaseAuthLock
40
40
  };
41
- //# sourceMappingURL=auth-lock-6U2G75S6.js.map
41
+ //# sourceMappingURL=auth-lock-6GGWZVOA.js.map
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  loadConfig
4
- } from "./chunk-AZVY3X7Q.js";
4
+ } from "./chunk-ILKZ5HGV.js";
5
5
 
6
6
  // src/notifications.ts
7
7
  import { spawn } from "child_process";
@@ -47,4 +47,4 @@ function notifyGrantPending(info) {
47
47
  export {
48
48
  notifyGrantPending
49
49
  };
50
- //# sourceMappingURL=chunk-LSKHTHUY.js.map
50
+ //# sourceMappingURL=chunk-5FV5KXEX.js.map
@@ -5,7 +5,7 @@ import {
5
5
  loadAuth,
6
6
  loadConfig,
7
7
  saveAuth
8
- } from "./chunk-AZVY3X7Q.js";
8
+ } from "./chunk-ILKZ5HGV.js";
9
9
 
10
10
  // src/http.ts
11
11
  import consola from "consola";
@@ -104,7 +104,7 @@ async function refreshOAuthToken() {
104
104
  const auth = loadAuth();
105
105
  if (!auth?.refresh_token)
106
106
  return null;
107
- const { acquireAuthLock, releaseAuthLock } = await import("./auth-lock-6U2G75S6.js");
107
+ const { acquireAuthLock, releaseAuthLock } = await import("./auth-lock-6GGWZVOA.js");
108
108
  const lock = await acquireAuthLock({ timeoutMs: 5e3 });
109
109
  if (!lock) {
110
110
  return getAuthToken();
@@ -1302,4 +1302,4 @@ export {
1302
1302
  buildExactCommandGrantRequest,
1303
1303
  buildStructuredCliGrantRequest
1304
1304
  };
1305
- //# sourceMappingURL=chunk-UQ673USC.js.map
1305
+ //# sourceMappingURL=chunk-D3OMN7RV.js.map
@@ -142,4 +142,4 @@ export {
142
142
  getAuthToken,
143
143
  getRequesterIdentity
144
144
  };
145
- //# sourceMappingURL=chunk-AZVY3X7Q.js.map
145
+ //# sourceMappingURL=chunk-ILKZ5HGV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\n\nexport interface AuthData {\n idp: string\n access_token: string\n refresh_token?: string\n email: string\n expires_at: number\n}\n\nexport interface ApesConfig {\n defaults?: {\n idp?: string\n approval?: string\n /**\n * Audience for the `apes run` async info block. `agent` (default)\n * emits verbose agent-facing instructions with a polling protocol;\n * `human` emits a short friendly block. Env var `APES_USER` wins.\n */\n user?: 'agent' | 'human'\n /**\n * Poll interval (seconds) embedded in the agent-mode instructions.\n * Default 10. Env var `APES_GRANT_POLL_INTERVAL` wins. Stored as a\n * string in TOML because the hand-rolled parser only handles quoted\n * values — casting to number happens at read time.\n */\n grant_poll_interval_seconds?: string\n /**\n * Maximum poll duration (minutes) embedded in the agent-mode\n * instructions. Default 5. Env var `APES_GRANT_POLL_MAX_MINUTES` wins.\n */\n grant_poll_max_minutes?: string\n }\n agent?: {\n key?: string\n email?: string\n }\n notifications?: {\n pending_command?: string\n }\n}\n\nconst CONFIG_DIR = join(homedir(), '.config', 'apes')\nconst AUTH_FILE = join(CONFIG_DIR, 'auth.json')\nconst CONFIG_FILE = join(CONFIG_DIR, 'config.toml')\n\nfunction ensureDir() {\n if (!existsSync(CONFIG_DIR)) {\n mkdirSync(CONFIG_DIR, { recursive: true })\n }\n}\n\nexport function loadAuth(): AuthData | null {\n if (!existsSync(AUTH_FILE))\n return null\n try {\n return JSON.parse(readFileSync(AUTH_FILE, 'utf-8'))\n }\n catch {\n return null\n }\n}\n\nexport function saveAuth(data: AuthData): void {\n ensureDir()\n writeFileSync(AUTH_FILE, JSON.stringify(data, null, 2), { mode: 0o600 })\n}\n\nexport function clearAuth(): void {\n if (existsSync(AUTH_FILE)) {\n writeFileSync(AUTH_FILE, '', { mode: 0o600 })\n }\n // Also wipe the [agent] section from config.toml so logout disables\n // auto-refresh. Preserves [defaults] so the IdP URL stays configured.\n if (existsSync(CONFIG_FILE)) {\n const existing = loadConfig()\n if (existing.agent) {\n const { agent: _removed, ...rest } = existing\n saveConfig(rest)\n }\n }\n}\n\nexport function loadConfig(): ApesConfig {\n if (!existsSync(CONFIG_FILE))\n return {}\n try {\n return parseTOML(readFileSync(CONFIG_FILE, 'utf-8'))\n }\n catch {\n return {}\n }\n}\n\nfunction parseTOML(content: string): ApesConfig {\n const config: ApesConfig = {}\n let section = ''\n\n for (const line of content.split('\\n')) {\n const trimmed = line.trim()\n if (!trimmed || trimmed.startsWith('#'))\n continue\n\n const sectionMatch = trimmed.match(/^\\[(.+)\\]$/)\n if (sectionMatch) {\n section = sectionMatch[1]!\n continue\n }\n\n const kvMatch = trimmed.match(/^(\\w+)\\s*=\\s*\"(.+)\"$/)\n if (kvMatch) {\n const [, key, value] = kvMatch\n if (section === 'defaults') {\n config.defaults = config.defaults || {}\n ;(config.defaults as Record<string, string>)[key!] = value!\n }\n else if (section === 'agent') {\n config.agent = config.agent || {}\n ;(config.agent as Record<string, string>)[key!] = value!\n }\n else if (section === 'notifications') {\n config.notifications = config.notifications || {}\n ;(config.notifications as Record<string, string>)[key!] = value!\n }\n }\n }\n\n return config\n}\n\nexport function saveConfig(config: ApesConfig): void {\n ensureDir()\n const lines: string[] = []\n\n if (config.defaults) {\n lines.push('[defaults]')\n for (const [key, value] of Object.entries(config.defaults)) {\n if (value)\n lines.push(`${key} = \"${value}\"`)\n }\n lines.push('')\n }\n\n if (config.agent) {\n lines.push('[agent]')\n for (const [key, value] of Object.entries(config.agent)) {\n if (value)\n lines.push(`${key} = \"${value}\"`)\n }\n lines.push('')\n }\n\n if (config.notifications) {\n lines.push('[notifications]')\n for (const [key, value] of Object.entries(config.notifications)) {\n if (value)\n lines.push(`${key} = \"${value}\"`)\n }\n lines.push('')\n }\n\n writeFileSync(CONFIG_FILE, lines.join('\\n'), { mode: 0o600 })\n}\n\nexport function getIdpUrl(explicit?: string): string | null {\n if (explicit)\n return explicit\n if (process.env.APES_IDP)\n return process.env.APES_IDP\n\n const auth = loadAuth()\n if (auth?.idp)\n return auth.idp\n\n const config = loadConfig()\n if (config.defaults?.idp)\n return config.defaults.idp\n\n return null\n}\n\nexport function getAuthToken(): string | null {\n const auth = loadAuth()\n if (!auth)\n return null\n\n // Check expiry (with 30s buffer)\n if (auth.expires_at && Date.now() / 1000 > auth.expires_at - 30) {\n return null // expired\n }\n\n return auth.access_token\n}\n\nexport function getRequesterIdentity(): string | null {\n return loadAuth()?.email ?? null\n}\n\nexport { CONFIG_DIR, AUTH_FILE }\n"],"mappings":";;;AAAA,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,eAAe;AACxB,SAAS,YAAY;AA0CrB,IAAM,aAAa,KAAK,QAAQ,GAAG,WAAW,MAAM;AACpD,IAAM,YAAY,KAAK,YAAY,WAAW;AAC9C,IAAM,cAAc,KAAK,YAAY,aAAa;AAElD,SAAS,YAAY;AACnB,MAAI,CAAC,WAAW,UAAU,GAAG;AAC3B,cAAU,YAAY,EAAE,WAAW,KAAK,CAAC;AAAA,EAC3C;AACF;AAEO,SAAS,WAA4B;AAC1C,MAAI,CAAC,WAAW,SAAS;AACvB,WAAO;AACT,MAAI;AACF,WAAO,KAAK,MAAM,aAAa,WAAW,OAAO,CAAC;AAAA,EACpD,QACM;AACJ,WAAO;AAAA,EACT;AACF;AAEO,SAAS,SAAS,MAAsB;AAC7C,YAAU;AACV,gBAAc,WAAW,KAAK,UAAU,MAAM,MAAM,CAAC,GAAG,EAAE,MAAM,IAAM,CAAC;AACz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,SAAS,uBAAsC;AACpD,SAAO,SAAS,GAAG,SAAS;AAC9B;","names":[]}
package/dist/cli.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-ION3CWD5.js";
11
11
  import {
12
12
  notifyGrantPending
13
- } from "./chunk-LSKHTHUY.js";
13
+ } from "./chunk-5FV5KXEX.js";
14
14
  import {
15
15
  ApiError,
16
16
  apiFetch,
@@ -41,7 +41,7 @@ import {
41
41
  searchAdapters,
42
42
  verifyAndExecute,
43
43
  waitForGrantStatus
44
- } from "./chunk-UQ673USC.js";
44
+ } from "./chunk-D3OMN7RV.js";
45
45
  import {
46
46
  AUTH_FILE,
47
47
  CONFIG_DIR,
@@ -52,7 +52,7 @@ import {
52
52
  loadConfig,
53
53
  saveAuth,
54
54
  saveConfig
55
- } from "./chunk-AZVY3X7Q.js";
55
+ } from "./chunk-ILKZ5HGV.js";
56
56
 
57
57
  // src/cli.ts
58
58
  import consola27 from "consola";
@@ -1928,14 +1928,78 @@ import consola19 from "consola";
1928
1928
  function shouldWaitForGrant(args) {
1929
1929
  return args.wait === true || process.env.APE_WAIT === "1";
1930
1930
  }
1931
+ function getUserMode() {
1932
+ const envValue = process.env.APES_USER;
1933
+ if (envValue === "human")
1934
+ return "human";
1935
+ if (envValue === "agent")
1936
+ return "agent";
1937
+ const cfg = loadConfig();
1938
+ if (cfg.defaults?.user === "human")
1939
+ return "human";
1940
+ return "agent";
1941
+ }
1942
+ function getPollIntervalSeconds() {
1943
+ const envValue = process.env.APES_GRANT_POLL_INTERVAL;
1944
+ if (envValue) {
1945
+ const n = Number(envValue);
1946
+ if (Number.isFinite(n) && n > 0)
1947
+ return Math.floor(n);
1948
+ }
1949
+ const cfg = loadConfig();
1950
+ const cfgValue = cfg.defaults?.grant_poll_interval_seconds;
1951
+ if (cfgValue) {
1952
+ const n = Number(cfgValue);
1953
+ if (Number.isFinite(n) && n > 0)
1954
+ return Math.floor(n);
1955
+ }
1956
+ return 10;
1957
+ }
1958
+ function getPollMaxMinutes() {
1959
+ const envValue = process.env.APES_GRANT_POLL_MAX_MINUTES;
1960
+ if (envValue) {
1961
+ const n = Number(envValue);
1962
+ if (Number.isFinite(n) && n > 0)
1963
+ return Math.floor(n);
1964
+ }
1965
+ const cfg = loadConfig();
1966
+ const cfgValue = cfg.defaults?.grant_poll_max_minutes;
1967
+ if (cfgValue) {
1968
+ const n = Number(cfgValue);
1969
+ if (Number.isFinite(n) && n > 0)
1970
+ return Math.floor(n);
1971
+ }
1972
+ return 5;
1973
+ }
1931
1974
  function printPendingGrantInfo(grant, idp) {
1932
- consola19.success(`Grant ${grant.id} erstellt`);
1933
- console.log(` Approve: ${idp}/grant-approval?grant_id=${grant.id}`);
1934
- console.log(` Status: apes grants status ${grant.id}`);
1935
- console.log(` Ausf\xFChren: apes grants run ${grant.id}`);
1975
+ const mode = getUserMode();
1976
+ const approveUrl = `${idp}/grant-approval?grant_id=${grant.id}`;
1977
+ const statusCmd = `apes grants status ${grant.id}`;
1978
+ const executeCmd = `apes grants run ${grant.id}`;
1979
+ if (mode === "human") {
1980
+ consola19.success(`Grant ${grant.id} created \u2014 awaiting your approval`);
1981
+ console.log(` Approve in browser: ${approveUrl}`);
1982
+ console.log(` Check status: ${statusCmd}`);
1983
+ console.log(` Run after approval: ${executeCmd}`);
1984
+ console.log("");
1985
+ console.log(' Tip: Approve as "timed" or "always" in the browser to reuse');
1986
+ console.log(" this grant without re-approval on the next invocation.");
1987
+ return;
1988
+ }
1989
+ const pollSec = getPollIntervalSeconds();
1990
+ const maxMin = getPollMaxMinutes();
1991
+ consola19.success(`Grant ${grant.id} created (pending approval)`);
1992
+ console.log(` Approve: ${approveUrl}`);
1993
+ console.log(` Status: ${statusCmd} [--json]`);
1994
+ console.log(` Execute: ${executeCmd}`);
1995
+ console.log("");
1996
+ console.log(` For agents: poll \`${statusCmd} --json\` every ${pollSec}s, wait up to ${maxMin} minutes.`);
1997
+ console.log(` When .status == "approved", run \`${executeCmd}\` to execute.`);
1998
+ console.log(` On "denied" or "revoked", stop and report to the user.`);
1999
+ console.log(` On timeout, stop and notify the user that approval has not happened.`);
1936
2000
  console.log("");
1937
- console.log(' Tipp: Im Browser "als timed/always approven" w\xE4hlen, um das');
1938
- console.log(" Kommando ohne erneuten Approval wiederzuverwenden.");
2001
+ console.log(' Tip: Approve as "timed" or "always" in the browser to let this');
2002
+ console.log(" grant be reused on subsequent invocations without re-approval.");
1939
2003
  }
1940
2004
  var runCommand = defineCommand21({
1941
2005
  meta: {
@@ -2529,7 +2593,7 @@ var mcpCommand = defineCommand26({
2529
2593
  if (transport !== "stdio" && transport !== "sse") {
2530
2594
  throw new Error('Transport must be "stdio" or "sse"');
2531
2595
  }
2532
- const { startMcpServer } = await import("./server-UA3JNXXZ.js");
2596
+ const { startMcpServer } = await import("./server-2IMH7YQX.js");
2533
2597
  await startMcpServer(transport, port);
2534
2598
  }
2535
2599
  });
@@ -3021,7 +3085,7 @@ async function bestEffortGrantCount(idp) {
3021
3085
  }
3022
3086
  }
3023
3087
  async function runHealth(args) {
3024
- const version = true ? "0.9.2" : "0.0.0";
3088
+ const version = true ? "0.9.3" : "0.0.0";
3025
3089
  const auth = loadAuth();
3026
3090
  if (!auth) {
3027
3091
  throw new CliError("Not logged in. Run `apes login` first.", 1);
@@ -3223,10 +3287,10 @@ if (shellRewrite) {
3223
3287
  if (shellRewrite.action === "rewrite") {
3224
3288
  process.argv = shellRewrite.argv;
3225
3289
  } else if (shellRewrite.action === "version") {
3226
- console.log(`ape-shell ${"0.9.2"} (OpenApe DDISA shell wrapper)`);
3290
+ console.log(`ape-shell ${"0.9.3"} (OpenApe DDISA shell wrapper)`);
3227
3291
  process.exit(0);
3228
3292
  } else if (shellRewrite.action === "help") {
3229
- console.log(`ape-shell ${"0.9.2"} \u2014 OpenApe DDISA shell wrapper`);
3293
+ console.log(`ape-shell ${"0.9.3"} \u2014 OpenApe DDISA shell wrapper`);
3230
3294
  console.log("");
3231
3295
  console.log("Usage:");
3232
3296
  console.log(" ape-shell Start interactive grant-mediated REPL");
@@ -3241,7 +3305,7 @@ if (shellRewrite) {
3241
3305
  console.log(" --help, -h Show this help message");
3242
3306
  process.exit(0);
3243
3307
  } else if (shellRewrite.action === "interactive") {
3244
- const { runInteractiveShell } = await import("./orchestrator-GJ5V4XDT.js");
3308
+ const { runInteractiveShell } = await import("./orchestrator-MVOSHEI2.js");
3245
3309
  await runInteractiveShell();
3246
3310
  process.exit(0);
3247
3311
  } else {
@@ -3284,7 +3348,7 @@ var configCommand = defineCommand33({
3284
3348
  var main = defineCommand33({
3285
3349
  meta: {
3286
3350
  name: "apes",
3287
- version: "0.9.2",
3351
+ version: "0.9.3",
3288
3352
  description: "Unified CLI for OpenApe"
3289
3353
  },
3290
3354
  subCommands: {