@openape/ape-agent 2.8.13 → 2.8.14

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/bridge.mjs +151 -155
  2. package/package.json +4 -4
package/dist/bridge.mjs CHANGED
@@ -2594,7 +2594,7 @@ async function runLoop(opts) {
2594
2594
  }
2595
2595
  var RPC_SESSION_TTL_MS = 60 * 60 * 1e3;
2596
2596
 
2597
- // ../../packages/apes/dist/chunk-DYSFQ26B.js
2597
+ // ../../packages/apes/dist/chunk-PEA2RDWK.js
2598
2598
  init_chunk_OBF7IMQ2();
2599
2599
  import { createHash } from "crypto";
2600
2600
  import { existsSync as existsSync3, readdirSync as readdirSync2, readFileSync as readFileSync4 } from "fs";
@@ -2632,6 +2632,149 @@ async function computeArgvHash(argv2) {
2632
2632
  const digest2 = Array.from(hashArray).map((b2) => b2.toString(16).padStart(2, "0")).join("");
2633
2633
  return `SHA-256:${digest2}`;
2634
2634
  }
2635
+ function parseOptionArgs(tokens, valueOptions) {
2636
+ const options = {};
2637
+ const positionals = [];
2638
+ const takesValue = new Set(valueOptions ?? []);
2639
+ for (let index = 0; index < tokens.length; index += 1) {
2640
+ const token = tokens[index];
2641
+ if (token.startsWith("--")) {
2642
+ const stripped = token.slice(2);
2643
+ const eqIndex = stripped.indexOf("=");
2644
+ if (eqIndex >= 0) {
2645
+ options[stripped.slice(0, eqIndex)] = stripped.slice(eqIndex + 1);
2646
+ continue;
2647
+ }
2648
+ const next = tokens[index + 1];
2649
+ if (next && !next.startsWith("-")) {
2650
+ options[stripped] = next;
2651
+ index += 1;
2652
+ continue;
2653
+ }
2654
+ options[stripped] = "true";
2655
+ } else if (token.startsWith("-") && token.length > 1 && !/^-\d/.test(token)) {
2656
+ const key = token.slice(1);
2657
+ if (key.length === 1 && !takesValue.has(key)) {
2658
+ options[key] = "true";
2659
+ } else {
2660
+ const next = tokens[index + 1];
2661
+ if (next && !next.startsWith("-")) {
2662
+ options[key] = next;
2663
+ index += 1;
2664
+ } else {
2665
+ options[key] = "true";
2666
+ }
2667
+ }
2668
+ } else {
2669
+ positionals.push(token);
2670
+ }
2671
+ }
2672
+ return { options, positionals };
2673
+ }
2674
+ function resolveBindingToken(binding, bindings) {
2675
+ const match = binding.match(/^\{([^}|]+)(?:\|([^}]+))?\}$/);
2676
+ if (!match) return binding;
2677
+ const [, name, transform] = match;
2678
+ const value = bindings[name];
2679
+ if (!value) throw new Error(`Missing binding: ${name}`);
2680
+ if (!transform) return value;
2681
+ if (transform === "owner" || transform === "name") {
2682
+ const [owner, repo] = value.split("/");
2683
+ if (!owner || !repo) throw new Error(`Binding ${name} must be in owner/name form`);
2684
+ return transform === "owner" ? owner : repo;
2685
+ }
2686
+ throw new Error(`Unsupported binding transform: ${transform}`);
2687
+ }
2688
+ function renderTemplate(template, bindings) {
2689
+ return template.replace(/\{([^}]+)\}/g, (_3, expression) => resolveBindingToken(`{${expression}}`, bindings));
2690
+ }
2691
+ function parseResourceChain(chain, bindings) {
2692
+ return chain.map((entry) => {
2693
+ const [resource, selectorSpec = "*"] = entry.split(":", 2);
2694
+ if (!resource) throw new Error(`Invalid resource chain entry: ${entry}`);
2695
+ if (selectorSpec === "*") return { resource };
2696
+ const selector = Object.fromEntries(
2697
+ selectorSpec.split(",").map((segment) => {
2698
+ const [key, rawValue] = segment.split("=", 2);
2699
+ if (!key || !rawValue) throw new Error(`Invalid selector segment: ${segment}`);
2700
+ return [key, renderTemplate(rawValue, bindings)];
2701
+ })
2702
+ );
2703
+ return { resource, selector };
2704
+ });
2705
+ }
2706
+ function matchOperation(operation, argv2) {
2707
+ if (argv2.length < operation.command.length) return null;
2708
+ const prefix = argv2.slice(0, operation.command.length);
2709
+ if (prefix.join("\0") !== operation.command.join("\0")) return null;
2710
+ const remainder = argv2.slice(operation.command.length);
2711
+ const { options, positionals } = parseOptionArgs(remainder, operation.required_options);
2712
+ const expectedPositionals = operation.positionals ?? [];
2713
+ if (positionals.length !== expectedPositionals.length) return null;
2714
+ for (const option of operation.required_options ?? []) {
2715
+ if (!options[option]) return null;
2716
+ }
2717
+ const bindings = { ...options };
2718
+ for (let index = 0; index < expectedPositionals.length; index += 1) {
2719
+ const name = expectedPositionals[index];
2720
+ const value = positionals[index];
2721
+ if (name.startsWith("=")) {
2722
+ if (value !== name.slice(1)) return null;
2723
+ continue;
2724
+ }
2725
+ bindings[name] = value;
2726
+ }
2727
+ return bindings;
2728
+ }
2729
+ function expandCombinedFlags(argv2) {
2730
+ return argv2.flatMap((token) => {
2731
+ if (token.startsWith("-") && !token.startsWith("--") && token.length > 2 && /^-[a-z]+$/i.test(token)) {
2732
+ return Array.from(token.slice(1), (c3) => `-${c3}`);
2733
+ }
2734
+ return [token];
2735
+ });
2736
+ }
2737
+ function tryMatch(operations, argv2) {
2738
+ return operations.flatMap((operation) => {
2739
+ try {
2740
+ const bindings = matchOperation(operation, argv2);
2741
+ return bindings ? [{ operation, bindings }] : [];
2742
+ } catch {
2743
+ return [];
2744
+ }
2745
+ });
2746
+ }
2747
+ function matchArgvToOperation(operations, commandArgv) {
2748
+ let matches = tryMatch(operations, commandArgv);
2749
+ if (matches.length === 0) {
2750
+ const expanded = expandCombinedFlags(commandArgv);
2751
+ if (expanded.length !== commandArgv.length) {
2752
+ matches = tryMatch(operations, expanded);
2753
+ }
2754
+ }
2755
+ if (matches.length === 0) return null;
2756
+ if (matches.length > 1) {
2757
+ matches.sort((a2, b2) => b2.operation.command.length - a2.operation.command.length);
2758
+ matches = [matches[0]];
2759
+ }
2760
+ return matches[0];
2761
+ }
2762
+ function buildCliAuthDetail(cliId, operation, bindings) {
2763
+ const resource_chain = parseResourceChain(operation.resource_chain, bindings);
2764
+ const detail = {
2765
+ type: "openape_cli",
2766
+ cli_id: cliId,
2767
+ operation_id: operation.id,
2768
+ resource_chain,
2769
+ action: operation.action,
2770
+ permission: "",
2771
+ display: renderTemplate(operation.display, bindings),
2772
+ risk: operation.risk,
2773
+ ...operation.exact_command ? { constraints: { exact_command: true } } : {}
2774
+ };
2775
+ detail.permission = canonicalizeCliPermission(detail);
2776
+ return detail;
2777
+ }
2635
2778
 
2636
2779
  // ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs
2637
2780
  var LogLevels = {
@@ -3734,7 +3877,7 @@ function _getDefaultLogLevel() {
3734
3877
  }
3735
3878
  var consola = createConsola2();
3736
3879
 
3737
- // ../../packages/apes/dist/chunk-DYSFQ26B.js
3880
+ // ../../packages/apes/dist/chunk-PEA2RDWK.js
3738
3881
  var import_shell_quote = __toESM(require_shell_quote(), 1);
3739
3882
 
3740
3883
  // ../../node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/index.mjs
@@ -3743,7 +3886,7 @@ function defineCommand(def) {
3743
3886
  return def;
3744
3887
  }
3745
3888
 
3746
- // ../../packages/apes/dist/chunk-DYSFQ26B.js
3889
+ // ../../packages/apes/dist/chunk-PEA2RDWK.js
3747
3890
  import { homedir as homedir52 } from "os";
3748
3891
  import { join as join5 } from "path";
3749
3892
  function parseKeyValue(line) {
@@ -3916,131 +4059,6 @@ function loadAdapter(cliId, explicitPath) {
3916
4059
  }
3917
4060
  var REGISTRY_URL = process.env.SHAPES_REGISTRY_URL ?? "https://raw.githubusercontent.com/openape-ai/shapes-registry/main/registry.json";
3918
4061
  var CACHE_TTL_MS = 60 * 60 * 1e3;
3919
- function parseOptionArgs(tokens, valueOptions) {
3920
- const options = {};
3921
- const positionals = [];
3922
- const takesValue = new Set(valueOptions ?? []);
3923
- for (let index = 0; index < tokens.length; index += 1) {
3924
- const token = tokens[index];
3925
- if (token.startsWith("--")) {
3926
- const stripped = token.slice(2);
3927
- const eqIndex = stripped.indexOf("=");
3928
- if (eqIndex >= 0) {
3929
- options[stripped.slice(0, eqIndex)] = stripped.slice(eqIndex + 1);
3930
- continue;
3931
- }
3932
- const next = tokens[index + 1];
3933
- if (next && !next.startsWith("-")) {
3934
- options[stripped] = next;
3935
- index += 1;
3936
- continue;
3937
- }
3938
- options[stripped] = "true";
3939
- } else if (token.startsWith("-") && token.length > 1 && !/^-\d/.test(token)) {
3940
- const key = token.slice(1);
3941
- if (key.length === 1 && !takesValue.has(key)) {
3942
- options[key] = "true";
3943
- } else {
3944
- const next = tokens[index + 1];
3945
- if (next && !next.startsWith("-")) {
3946
- options[key] = next;
3947
- index += 1;
3948
- } else {
3949
- options[key] = "true";
3950
- }
3951
- }
3952
- } else {
3953
- positionals.push(token);
3954
- }
3955
- }
3956
- return { options, positionals };
3957
- }
3958
- function resolveBindingToken(binding, bindings) {
3959
- const match = binding.match(/^\{([^}|]+)(?:\|([^}]+))?\}$/);
3960
- if (!match)
3961
- return binding;
3962
- const [, name, transform] = match;
3963
- const value = bindings[name];
3964
- if (!value)
3965
- throw new Error(`Missing binding: ${name}`);
3966
- if (!transform)
3967
- return value;
3968
- if (transform === "owner" || transform === "name") {
3969
- const [owner, repo] = value.split("/");
3970
- if (!owner || !repo)
3971
- throw new Error(`Binding ${name} must be in owner/name form`);
3972
- return transform === "owner" ? owner : repo;
3973
- }
3974
- throw new Error(`Unsupported binding transform: ${transform}`);
3975
- }
3976
- function renderTemplate(template, bindings) {
3977
- return template.replace(/\{([^}]+)\}/g, (_3, expression) => resolveBindingToken(`{${expression}}`, bindings));
3978
- }
3979
- function parseResourceChain(chain, bindings) {
3980
- return chain.map((entry) => {
3981
- const [resource, selectorSpec = "*"] = entry.split(":", 2);
3982
- if (!resource)
3983
- throw new Error(`Invalid resource chain entry: ${entry}`);
3984
- if (selectorSpec === "*") {
3985
- return { resource };
3986
- }
3987
- const selector = Object.fromEntries(
3988
- selectorSpec.split(",").map((segment) => {
3989
- const [key, rawValue] = segment.split("=", 2);
3990
- if (!key || !rawValue)
3991
- throw new Error(`Invalid selector segment: ${segment}`);
3992
- return [key, renderTemplate(rawValue, bindings)];
3993
- })
3994
- );
3995
- return { resource, selector };
3996
- });
3997
- }
3998
- function matchOperation(operation, argv2) {
3999
- if (argv2.length < operation.command.length)
4000
- return null;
4001
- const prefix = argv2.slice(0, operation.command.length);
4002
- if (prefix.join("\0") !== operation.command.join("\0"))
4003
- return null;
4004
- const remainder = argv2.slice(operation.command.length);
4005
- const { options, positionals } = parseOptionArgs(remainder, operation.required_options);
4006
- const expectedPositionals = operation.positionals ?? [];
4007
- if (positionals.length !== expectedPositionals.length)
4008
- return null;
4009
- for (const option of operation.required_options ?? []) {
4010
- if (!options[option])
4011
- return null;
4012
- }
4013
- const bindings = { ...options };
4014
- for (let index = 0; index < expectedPositionals.length; index += 1) {
4015
- const name = expectedPositionals[index];
4016
- const value = positionals[index];
4017
- if (name.startsWith("=")) {
4018
- if (value !== name.slice(1))
4019
- return null;
4020
- continue;
4021
- }
4022
- bindings[name] = value;
4023
- }
4024
- return bindings;
4025
- }
4026
- function expandCombinedFlags(argv2) {
4027
- return argv2.flatMap((token) => {
4028
- if (token.startsWith("-") && !token.startsWith("--") && token.length > 2 && /^-[a-z]+$/i.test(token)) {
4029
- return Array.from(token.slice(1), (c3) => `-${c3}`);
4030
- }
4031
- return [token];
4032
- });
4033
- }
4034
- function tryMatch(operations, argv2) {
4035
- return operations.flatMap((operation) => {
4036
- try {
4037
- const bindings = matchOperation(operation, argv2);
4038
- return bindings ? [{ operation, bindings }] : [];
4039
- } catch {
4040
- return [];
4041
- }
4042
- });
4043
- }
4044
4062
  async function resolveCommand(loaded, fullArgv) {
4045
4063
  const [executable, ...commandArgv] = fullArgv;
4046
4064
  if (!executable) {
@@ -4049,34 +4067,12 @@ async function resolveCommand(loaded, fullArgv) {
4049
4067
  if (executable !== loaded.adapter.cli.executable) {
4050
4068
  throw new Error(`Adapter ${loaded.adapter.cli.id} expects executable ${loaded.adapter.cli.executable}, got ${executable}`);
4051
4069
  }
4052
- let matches = tryMatch(loaded.adapter.operations, commandArgv);
4053
- if (matches.length === 0) {
4054
- const expanded = expandCombinedFlags(commandArgv);
4055
- if (expanded.length !== commandArgv.length) {
4056
- matches = tryMatch(loaded.adapter.operations, expanded);
4057
- }
4058
- }
4059
- if (matches.length === 0) {
4070
+ const match = matchArgvToOperation(loaded.adapter.operations, commandArgv);
4071
+ if (!match) {
4060
4072
  throw new Error(`No adapter operation matched: ${fullArgv.join(" ")}`);
4061
4073
  }
4062
- if (matches.length > 1) {
4063
- matches.sort((a2, b2) => b2.operation.command.length - a2.operation.command.length);
4064
- matches = [matches[0]];
4065
- }
4066
- const { operation, bindings } = matches[0];
4067
- const resource_chain = parseResourceChain(operation.resource_chain, bindings);
4068
- const detail = {
4069
- type: "openape_cli",
4070
- cli_id: loaded.adapter.cli.id,
4071
- operation_id: operation.id,
4072
- resource_chain,
4073
- action: operation.action,
4074
- permission: "",
4075
- display: renderTemplate(operation.display, bindings),
4076
- risk: operation.risk,
4077
- ...operation.exact_command ? { constraints: { exact_command: true } } : {}
4078
- };
4079
- detail.permission = canonicalizeCliPermission(detail);
4074
+ const { operation, bindings } = match;
4075
+ const detail = buildCliAuthDetail(loaded.adapter.cli.id, operation, bindings);
4080
4076
  return {
4081
4077
  adapter: loaded.adapter,
4082
4078
  source: loaded.source,
@@ -4466,7 +4462,7 @@ function readAgentIdentity() {
4466
4462
  const ownerEmail = parsed.owner_email ?? process.env.OPENAPE_OWNER_EMAIL;
4467
4463
  if (!ownerEmail) {
4468
4464
  throw new Error(
4469
- `auth.json at ${path} missing 'owner_email' and no OPENAPE_OWNER_EMAIL env var set \u2014 re-spawn the agent with @openape/apes >= 0.28 or add OPENAPE_OWNER_EMAIL to the launchd plist`
4465
+ `auth.json at ${path} missing 'owner_email' and no OPENAPE_OWNER_EMAIL env var set \u2014 re-spawn the agent with @openape/apes >= 0.28 or set OPENAPE_OWNER_EMAIL in the container env`
4470
4466
  );
4471
4467
  }
4472
4468
  return { email: parsed.email, ownerEmail, idp: parsed.idp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openape/ape-agent",
3
- "version": "2.8.13",
3
+ "version": "2.8.14",
4
4
  "description": "OpenApe agent runtime: per-agent process that connects to chat.openape.ai, runs the LLM loop with tools + cron tasks, and streams replies back to owners.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -23,9 +23,9 @@
23
23
  "ofetch": "^1.4.1",
24
24
  "ws": "^8.18.0",
25
25
  "yaml": "^2.8.0",
26
- "@openape/apes": "1.28.12",
27
- "@openape/cli-auth": "0.5.0",
28
- "@openape/prompt-injection-detector": "0.1.0"
26
+ "@openape/apes": "1.28.13",
27
+ "@openape/prompt-injection-detector": "0.1.0",
28
+ "@openape/cli-auth": "0.5.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@antfu/eslint-config": "^7.6.1",