@mnemom/mnemom 0.17.0-next.6 → 0.17.0-next.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.
@@ -1,16 +1,16 @@
1
1
  /**
2
- * lib/code-config.ts — persistent per-customer settings for `mnemom code`.
2
+ * lib/code-config.ts — persistent per-customer settings for `mnemom agent`.
3
3
  *
4
- * Settings live in a human-editable TOML file at ~/.mnemom/code.toml (the
4
+ * Settings live in a human-editable TOML file at ~/.mnemom/launcher.toml (the
5
5
  * Cargo/Codex `config.toml` convention — comments allowed, easy to hand-edit) so
6
6
  * a customer never has to retype their flags. The SECRET Anthropic key is
7
- * deliberately NOT stored here: it stays in ~/.mnemom/code.json at 0600 (see
7
+ * deliberately NOT stored here: it stays in ~/.mnemom/launcher.json at 0600 (see
8
8
  * commands/code.ts), so the file customers open, edit, and share never carries a
9
9
  * credential — the same split gh (config.yml/hosts.yml), aws (config/credentials)
10
10
  * and Codex (config.toml/auth.json) use.
11
11
  *
12
- * Precedence, highest wins: command-line FLAG > ENV > code.toml > built-in.
13
- * `loadCodeConfig` is pure parse+validate; `applyConfigToEnv` folds the
12
+ * Precedence, highest wins: command-line FLAG > ENV > launcher.toml > built-in.
13
+ * `loadLauncherConfig` is pure parse+validate; `applyConfigToEnv` folds the
14
14
  * env-backed settings UNDER any real env var (so env still wins and the
15
15
  * resolvers in lib/code.ts keep the built-in default as the final fallback);
16
16
  * the caller folds the plain-value settings under the CLI flags.
@@ -19,9 +19,9 @@ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "
19
19
  import { dirname, join } from "node:path";
20
20
  import { parse as parseToml, stringify as stringifyToml, TomlError } from "smol-toml";
21
21
  import { MNEMOM_DIR } from "./config.js";
22
- import { isPositiveInt, isPositiveNumber } from "./code.js";
23
- /** The human-editable settings file. Secret key lives elsewhere (code.json). */
24
- export const CODE_CONFIG_PATH = join(MNEMOM_DIR, "code.toml");
22
+ import { isPositiveInt, isPositiveNumber } from "./agent.js";
23
+ /** The human-editable settings file. Secret key lives elsewhere (launcher.json). */
24
+ export const LAUNCHER_CONFIG_PATH = join(MNEMOM_DIR, "launcher.toml");
25
25
  const LAUNCH_SHAPES = ["terminal", "remote-control", "server"];
26
26
  const EFFORTS = ["low", "medium", "high", "xhigh", "max"];
27
27
  const KEY_SOURCES = ["env", "store", "prompt"];
@@ -147,18 +147,18 @@ export function configKeySpec(key) {
147
147
  return CONFIG_KEYS.find((k) => k.key === key);
148
148
  }
149
149
  /**
150
- * Parse + validate a TOML settings document into a CodeConfig. Pure (no fs), so
150
+ * Parse + validate a TOML settings document into a LauncherConfig. Pure (no fs), so
151
151
  * it is unit-testable. Unknown top-level keys are ignored (forward-compatible);
152
152
  * known keys with the wrong shape throw a human-readable error.
153
153
  */
154
- export function parseCodeConfig(text) {
154
+ export function parseLauncherConfig(text) {
155
155
  let raw;
156
156
  try {
157
157
  raw = parseToml(text);
158
158
  }
159
159
  catch (err) {
160
160
  const detail = err instanceof TomlError ? err.message : String(err);
161
- throw new Error(`could not parse code.toml: ${detail}`);
161
+ throw new Error(`could not parse launcher.toml: ${detail}`, { cause: err });
162
162
  }
163
163
  const cfg = {};
164
164
  const str = (v) => typeof v === "string" && v.trim() ? v.trim() : v === undefined ? undefined : String(v);
@@ -192,12 +192,12 @@ export function parseCodeConfig(text) {
192
192
  return cfg;
193
193
  }
194
194
  /**
195
- * Load the settings from ~/.mnemom/code.toml (or `path`). A missing file is an
195
+ * Load the settings from ~/.mnemom/launcher.toml (or `path`). A missing file is an
196
196
  * empty config (never an error — first run has none). A malformed or invalid
197
197
  * file throws with the path so the customer can fix it, rather than silently
198
198
  * launching with the wrong settings.
199
199
  */
200
- export function loadCodeConfig(path = CODE_CONFIG_PATH) {
200
+ export function loadLauncherConfig(path = LAUNCHER_CONFIG_PATH) {
201
201
  if (!existsSync(path))
202
202
  return {};
203
203
  let text;
@@ -208,15 +208,15 @@ export function loadCodeConfig(path = CODE_CONFIG_PATH) {
208
208
  return {};
209
209
  }
210
210
  try {
211
- return parseCodeConfig(text);
211
+ return parseLauncherConfig(text);
212
212
  }
213
213
  catch (err) {
214
214
  const msg = err instanceof Error ? err.message : String(err);
215
- throw new Error(`mnemom code: ${msg}\n Fix or remove ${path}.`);
215
+ throw new Error(`mnemom agent: ${msg}\n Fix or remove ${path}.`, { cause: err });
216
216
  }
217
217
  }
218
- /** Serialize a CodeConfig back to TOML (snake_case keys), with a header comment. */
219
- export function serializeCodeConfig(cfg) {
218
+ /** Serialize a LauncherConfig back to TOML (snake_case keys), with a header comment. */
219
+ export function serializeLauncherConfig(cfg) {
220
220
  const doc = {};
221
221
  if (cfg.gateway !== undefined)
222
222
  doc.gateway = cfg.gateway;
@@ -243,39 +243,39 @@ export function serializeCodeConfig(cfg) {
243
243
  gr.stall_turns = g.stallTurns;
244
244
  doc.guardrails = gr;
245
245
  }
246
- const header = "# ~/.mnemom/code.toml — settings for `mnemom code` (the governed coding-agent launcher).\n" +
246
+ const header = "# ~/.mnemom/launcher.toml — settings for `mnemom agent` (the governed coding-agent launcher).\n" +
247
247
  "# Command-line flags override these; these override the built-in defaults.\n" +
248
- "# The secret Anthropic key is NOT here — it lives in ~/.mnemom/code.json (0600).\n" +
249
- "# Edit with `mnemom code config edit`, or set one key with `mnemom code config set <key> <value>`.\n\n";
248
+ "# The secret Anthropic key is NOT here — it lives in ~/.mnemom/launcher.json (0600).\n" +
249
+ "# Edit with `mnemom agent config edit`, or set one key with `mnemom agent config set <key> <value>`.\n\n";
250
250
  const body = Object.keys(doc).length ? stringifyToml(doc) : "";
251
251
  return `${header}${body}${body.endsWith("\n") || !body ? "" : "\n"}`;
252
252
  }
253
- /** Persist a CodeConfig to `path` (default code.toml), atomically (temp+rename), 0600. */
254
- export function writeCodeConfig(cfg, path = CODE_CONFIG_PATH) {
253
+ /** Persist a LauncherConfig to `path` (default launcher.toml), atomically (temp+rename), 0600. */
254
+ export function writeLauncherConfig(cfg, path = LAUNCHER_CONFIG_PATH) {
255
255
  const dir = dirname(path);
256
256
  mkdirSync(dir, { recursive: true });
257
257
  const tmp = join(dir, `.code-toml-tmp-${process.pid}-${Date.now()}`);
258
- writeFileSync(tmp, serializeCodeConfig(cfg), { mode: 0o600 });
258
+ writeFileSync(tmp, serializeLauncherConfig(cfg), { mode: 0o600 });
259
259
  renameSync(tmp, path);
260
260
  }
261
261
  /**
262
262
  * Fold the ENV-backed settings from config UNDER the environment: set the
263
- * MNEMOM_CODE_* var ONLY when it is not already present, so a real env var (and
263
+ * MNEMOM_AGENT_* var ONLY when it is not already present, so a real env var (and
264
264
  * therefore a flag that set one) still wins. The resolvers in lib/code.ts then
265
265
  * apply the built-in default when neither env nor config supplied a value.
266
266
  *
267
- * launch maps to MNEMOM_CODE_REMOTE_CONTROL using that var's existing contract
267
+ * launch maps to MNEMOM_AGENT_REMOTE_CONTROL using that var's existing contract
268
268
  * (see resolveLaunchShape): terminal→"0", remote-control→"1", server→"server".
269
269
  */
270
270
  export function applyConfigToEnv(cfg, env = process.env) {
271
- if (cfg.gateway && !(env.MNEMOM_CODE_GATEWAY ?? "").trim()) {
272
- env.MNEMOM_CODE_GATEWAY = cfg.gateway;
271
+ if (cfg.gateway && !(env.MNEMOM_AGENT_GATEWAY ?? "").trim()) {
272
+ env.MNEMOM_AGENT_GATEWAY = cfg.gateway;
273
273
  }
274
- if (cfg.cli && !(env.MNEMOM_CODE_CLI ?? "").trim()) {
275
- env.MNEMOM_CODE_CLI = cfg.cli;
274
+ if (cfg.cli && !(env.MNEMOM_AGENT_CLI ?? "").trim()) {
275
+ env.MNEMOM_AGENT_CLI = cfg.cli;
276
276
  }
277
- if (cfg.launch && !(env.MNEMOM_CODE_REMOTE_CONTROL ?? "").trim()) {
278
- env.MNEMOM_CODE_REMOTE_CONTROL =
277
+ if (cfg.launch && !(env.MNEMOM_AGENT_REMOTE_CONTROL ?? "").trim()) {
278
+ env.MNEMOM_AGENT_REMOTE_CONTROL =
279
279
  cfg.launch === "server" ? "server" : cfg.launch === "remote-control" ? "1" : "0";
280
280
  }
281
281
  }
@@ -67,7 +67,7 @@ export function enforceMinCliVersion(response, exit = process.exit, write = (chu
67
67
  return;
68
68
  exited = true;
69
69
  write(`\n✖ Your Mnemom CLI (v${CLI_VERSION}) is too old for this server (minimum v${floor}).\n` +
70
- ` Old CLIs can silently drop newer request fields — e.g. \`--org\` on \`mnemom agents claim\`.\n\n` +
70
+ ` Old CLIs can silently drop newer request fields — e.g. \`--org\` on \`mnemom agent claim\`.\n\n` +
71
71
  ` Upgrade: npm i -g @mnemom/mnemom@latest\n\n`);
72
72
  exit(1);
73
73
  }