@mnemom/mnemom 0.17.7-next.2 → 0.17.7

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.
@@ -25,11 +25,8 @@
25
25
  // request time instead. A terminal launch names `ANTHROPIC_CUSTOM_HEADERS` (parsed for its
26
26
  // `x-api-key:` line); Remote Control names a dedicated `MNEMOM_HANDOFF_KEY` its launcher sets
27
27
  // directly, since RC's child env strips every ANTHROPIC_* var (see `HandoffAnthropicKeySource`
28
- // in cli/src/lib/agent.ts for the full rationale). The Mnemom key (`x-mnemom-api-key`, required by
29
- // the gateway on every `mnemom agent` request) rides the same way, named by
30
- // `MNEMOM_HANDOFF_MNEMOM_KEY_ENV_NAME`: the `x-mnemom-api-key:` line of `ANTHROPIC_CUSTOM_HEADERS`
31
- // on a terminal launch, `MNEMOM_HANDOFF_MNEMOM_KEY` under Remote Control. This process never logs
32
- // any of these vars' names or values.
28
+ // in cli/src/lib/agent.ts for the full rationale). This process never logs either var's name or
29
+ // value.
33
30
 
34
31
  import { createInterface } from "node:readline";
35
32
  import { pathToFileURL } from "node:url";
@@ -70,33 +67,29 @@ const REQUIRED_ENV = [
70
67
  ];
71
68
 
72
69
  /**
73
- * Recover a key from an env var NAME this process itself inherited from its parent (never a
74
- * value written into the `--mcp-config` file). `ANTHROPIC_CUSTOM_HEADERS` is a multi-line header
75
- * BLOCK (`buildCustomHeaders`, cli/src/lib/agent.ts) carrying `x-api-key: <key>` and
76
- * `x-mnemom-api-key: <key>` lines — extract just the line `header` asks for. Any other name is
77
- * treated as carrying the key value directly.
70
+ * Recover the Anthropic key from an env var NAME this process itself inherited from its parent
71
+ * (never a value written into the `--mcp-config` file). `ANTHROPIC_CUSTOM_HEADERS` is a
72
+ * multi-line header BLOCK (`buildCustomHeaders`, cli/src/lib/agent.ts) whose first line is
73
+ * `x-api-key: <key>` — extract just that. Any other name is treated as carrying the key value
74
+ * directly.
78
75
  * @param {string} name
79
76
  * @param {NodeJS.ProcessEnv} env
80
- * @param {RegExp} header the header line to read out of a header block
81
77
  * @returns {string} the key, or "" if the named var is absent/unusable.
82
78
  */
83
- function resolveKeyFromEnvName(name, env, header) {
79
+ function resolveKeyFromEnvName(name, env) {
84
80
  const value = env[name] ?? "";
85
81
  if (name === "ANTHROPIC_CUSTOM_HEADERS") {
86
- const m = value.match(header);
82
+ const m = value.match(/^x-api-key:\s*(.+)$/im);
87
83
  return m ? m[1].trim() : "";
88
84
  }
89
85
  return value.trim();
90
86
  }
91
87
 
92
- const ANTHROPIC_KEY_LINE = /^x-api-key:\s*(.+)$/im;
93
- const MNEMOM_KEY_LINE = /^x-mnemom-api-key:\s*(.+)$/im;
94
-
95
88
  /**
96
89
  * Read the tool's config from env. Throws (message never contains the key value) when a
97
90
  * required var is missing, or when the named key-source var resolves to no usable key.
98
91
  * @param {NodeJS.ProcessEnv} env
99
- * @returns {{gatewayHost: string, anthropicKey: string, mnemomKey?: string, agent: string, conversationId: string, sessionConfigB64?: string}}
92
+ * @returns {{gatewayHost: string, anthropicKey: string, agent: string, conversationId: string, sessionConfigB64?: string}}
100
93
  */
101
94
  export function configFromEnv(env) {
102
95
  const missing = REQUIRED_ENV.filter((k) => !(env[k] ?? "").trim());
@@ -104,30 +97,16 @@ export function configFromEnv(env) {
104
97
  throw new Error(`mnemom-handoff: missing required env var(s): ${missing.join(", ")}`);
105
98
  }
106
99
  const keyEnvName = env.MNEMOM_HANDOFF_ANTHROPIC_KEY_ENV_NAME.trim();
107
- const anthropicKey = resolveKeyFromEnvName(keyEnvName, env, ANTHROPIC_KEY_LINE);
100
+ const anthropicKey = resolveKeyFromEnvName(keyEnvName, env);
108
101
  if (!anthropicKey) {
109
102
  throw new Error(
110
103
  `mnemom-handoff: MNEMOM_HANDOFF_ANTHROPIC_KEY_ENV_NAME names '${keyEnvName}', but this ` +
111
104
  "process's own inherited environment has no usable value for it.",
112
105
  );
113
106
  }
114
- // The Mnemom key the gateway requires on every `mnemom agent` request. A launcher that names
115
- // no source sends none; a named source that resolves to nothing is a config error.
116
- const mnemomKeyEnvName = (env.MNEMOM_HANDOFF_MNEMOM_KEY_ENV_NAME ?? "").trim();
117
- let mnemomKey;
118
- if (mnemomKeyEnvName) {
119
- mnemomKey = resolveKeyFromEnvName(mnemomKeyEnvName, env, MNEMOM_KEY_LINE);
120
- if (!mnemomKey) {
121
- throw new Error(
122
- `mnemom-handoff: MNEMOM_HANDOFF_MNEMOM_KEY_ENV_NAME names '${mnemomKeyEnvName}', but this ` +
123
- "process's own inherited environment has no usable Mnemom key in it.",
124
- );
125
- }
126
- }
127
107
  return {
128
108
  gatewayHost: env.MNEMOM_HANDOFF_GATEWAY_HOST.trim(),
129
109
  anthropicKey,
130
- mnemomKey,
131
110
  agent: env.MNEMOM_HANDOFF_AGENT.trim(),
132
111
  conversationId: env.MNEMOM_HANDOFF_CONVERSATION_ID.trim(),
133
112
  sessionConfigB64: env.MNEMOM_HANDOFF_SESSION_CONFIG?.trim() || undefined,
@@ -136,7 +115,7 @@ export function configFromEnv(env) {
136
115
 
137
116
  /**
138
117
  * Build the fetch call. Exported so a test can assert the wire shape without mocking fetch.
139
- * @param {{gatewayHost: string, anthropicKey: string, mnemomKey?: string, agent: string, conversationId: string, sessionConfigB64?: string}} cfg
118
+ * @param {{gatewayHost: string, anthropicKey: string, agent: string, conversationId: string, sessionConfigB64?: string}} cfg
140
119
  * @param {string} note
141
120
  */
142
121
  export function buildHandoffRequest(cfg, note) {
@@ -145,7 +124,6 @@ export function buildHandoffRequest(cfg, note) {
145
124
  "x-api-key": cfg.anthropicKey,
146
125
  "x-mnemom-agent": cfg.agent,
147
126
  };
148
- if (cfg.mnemomKey) headers["x-mnemom-api-key"] = cfg.mnemomKey;
149
127
  if (cfg.sessionConfigB64) headers["x-mnemom-session-config"] = cfg.sessionConfigB64;
150
128
  return {
151
129
  url: `${cfg.gatewayHost.replace(/\/+$/, "")}${HANDOFF_PATH}`,
@@ -172,7 +150,7 @@ function extractGatewayError(body) {
172
150
  * Call the route and render the result. NEVER throws: a network failure, a non-2xx status, or
173
151
  * an unparseable body all come back as `{ok:false, message}` for the caller to surface as an
174
152
  * MCP tool error — the tool must never crash the server or the session over a bad response.
175
- * @param {{gatewayHost: string, anthropicKey: string, mnemomKey?: string, agent: string, conversationId: string, sessionConfigB64?: string}} cfg
153
+ * @param {{gatewayHost: string, anthropicKey: string, agent: string, conversationId: string, sessionConfigB64?: string}} cfg
176
154
  * @param {string} note
177
155
  * @param {typeof fetch} fetchImpl
178
156
  */
package/dist/rc-proxy.mjs CHANGED
@@ -19,7 +19,7 @@
19
19
  // byte-for-byte (telemetry, Datadog, MCP servers…).
20
20
  // * Inside api.anthropic.com, only `POST /v1/messages[?…]` is rewritten to the Mnemom
21
21
  // gateway door: the real Anthropic key rides as `x-api-key` (API-key billing), plus
22
- // `x-mnemom-agent`, `x-mnemom-conversation-id`, `x-mnemom-api-key` (stdin line 2), and optionally
22
+ // `x-mnemom-agent`, `x-mnemom-conversation-id`, and optionally `x-mnemom-api-key`,
23
23
  // `x-mnemom-provider`, `x-mnemom-egress-key`, `x-mnemom-contract` / `x-mnemom-goal-mode` — the exact header set
24
24
  // the non-RC launch sends via ANTHROPIC_CUSTOM_HEADERS. The OAuth `authorization` bearer
25
25
  // is STRIPPED on that leg (it never leaves the machine) and `oauth-*` tokens are removed
@@ -51,11 +51,8 @@
51
51
  // (diagnostic only: it forwards continue-deltas the API rejects).
52
52
  //
53
53
  // SECRETS
54
- // Arrive on stdin as three newline-terminated lines: Anthropic key, Mnemom key, OpenAI egress
55
- // key (may be empty). `mnemom agent` sends the Mnemom key on every launch, in both auth modes —
56
- // the gateway refuses its traffic without one — and the proxy adds it as `x-mnemom-api-key` on
57
- // every gateway request whenever line 2 is set (required in subscription mode, where it also
58
- // anchors the identity). Never argv, never env, never disk, never logged.
54
+ // Arrive on stdin as three newline-terminated lines: Anthropic key, Mnemom key (may be
55
+ // empty), OpenAI egress key (may be empty). Never argv, never env, never disk, never logged.
59
56
  // The log (MNEMOM_AGENT_RC_PROXY_LOG, else stderr) carries method/path/status/latency and the
60
57
  // gateway's `x-mnemom-agent` / `x-mnemom-goal-verdict` response headers only. Gateway error
61
58
  // bodies (status ≥ 400) are logged truncated so a 4xx is diagnosable (compressed ones as
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mnemom/mnemom",
3
- "version": "0.17.7-next.2",
3
+ "version": "0.17.7",
4
4
  "description": "Transparent AI agent tracing",
5
5
  "type": "module",
6
6
  "bin": {