@alfe.ai/integrations 0.2.1 → 0.2.2

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/index.d.ts CHANGED
@@ -913,9 +913,11 @@ declare class HermesApplier implements RuntimeApplier {
913
913
  readonly runtime = "hermes";
914
914
  private home;
915
915
  private trackingPath;
916
+ /** `~/.hermes/config.yaml` — read-merge-written on removal (no `config unset`). */
917
+ private configYamlPath;
916
918
  private configSetRetries;
917
919
  private configSetRetryDelayMs;
918
- /** Serializes all `hermes config` writes so they never interleave. */
920
+ /** Serializes all config mutations (CLI `set` + config.yaml delete) so they never interleave. */
919
921
  private configSetQueue;
920
922
  constructor(options?: HermesApplierOptions);
921
923
  /**
@@ -929,8 +931,9 @@ declare class HermesApplier implements RuntimeApplier {
929
931
  /**
930
932
  * Remove config previously applied by an integration.
931
933
  *
932
- * Reads the tracking file to find which keys this integration set, then
933
- * removes each via `hermes config unset`. Clears the tracking entry.
934
+ * Reads the tracking file to find which dotted keys this integration set, then
935
+ * DELETES each from `~/.hermes/config.yaml` via a read-merge-write (there is no
936
+ * `hermes config unset` verb — see the file header). Clears the tracking entry.
934
937
  */
935
938
  removeConfig(integrationId: string): Promise<void>;
936
939
  /**
@@ -967,21 +970,25 @@ declare class HermesApplier implements RuntimeApplier {
967
970
  /** Convenience: `hermes config set <args>`, serialized + retried. */
968
971
  private runConfigSet;
969
972
  /**
970
- * Unset a single config key. The unset verb is isolated HERE so there is one
971
- * place to change if the spike proves `hermes config unset` is unavailable.
972
- *
973
- * FALLBACK (do NOT pre-build): if `hermes config unset` does not exist, the
974
- * substitute is `hermes config set <key> ""` (clear the value) or a
975
- * read-merge-write of config.yaml. Not implemented now — `unset` is the
976
- * documented verb; confirm in the Phase-0 spike before adding a fallback.
977
- * TODO(phase-0 spike): confirm `hermes config unset <key>` exists.
978
- */
979
- private unsetConfigKey;
980
- /**
981
- * Run `hermes config <args>` (set/unset), serialized against every other
982
- * config write and retried with backoff. Throws an Error whose (scrubbed)
983
- * message includes stderr after retries are exhausted, so the real cause
984
- * propagates to the integration errorMessage without leaking the value.
973
+ * Delete a set of dotted config keys from `~/.hermes/config.yaml`. There is no
974
+ * `hermes config unset` verb (see file header), so removal is a read-merge-write
975
+ * of the YAML via the Document API — preserving user-authored keys, comments,
976
+ * and formatting. Serialized against every other config mutation on the same
977
+ * queue so a delete can't interleave with an in-flight `hermes config set`.
978
+ */
979
+ private deleteConfigKeys;
980
+ /**
981
+ * Synchronous config.yaml read-merge-write: parse the doc, delete each dotted
982
+ * key (`model.base_url` → `deleteIn(['model','base_url'])`), and write back only
983
+ * if the text actually changed. No-op if config.yaml doesn't exist yet.
984
+ */
985
+ private deleteConfigKeysSync;
986
+ /**
987
+ * Run `hermes config <args>` (only `set` is used — removal goes via
988
+ * {@link deleteConfigKeys}), serialized against every other config mutation and
989
+ * retried with backoff. Throws an Error whose (scrubbed) message includes stderr
990
+ * after retries are exhausted, so the real cause propagates to the integration
991
+ * errorMessage without leaking the value.
985
992
  */
986
993
  private runConfigCommand;
987
994
  private readTracking;
package/dist/index.js CHANGED
@@ -2193,11 +2193,17 @@ var OpenClawApplier = class {
2193
2193
  * HermesApplier — applies integration config (and, later, native plugins) to
2194
2194
  * the Hermes runtime (Nous Research's Python agent).
2195
2195
  *
2196
- * Hermes config lives in `~/.hermes/config.yaml` (YAML) and is mutated via the
2197
- * `hermes config set/unset <dotted.key> <value>` CLI we never write the YAML
2198
- * file directly (mirrors the OpenClaw rule of letting the runtime own its own
2199
- * config format). Per-integration contributions are tracked in a separate file
2200
- * (`~/.hermes/.alfe-integrations.json`) so removal is precise.
2196
+ * Hermes config lives in `~/.hermes/config.yaml` (YAML). We APPLY config via the
2197
+ * `hermes config set <dotted.key> <value>` CLI (letting the runtime own its
2198
+ * write path, mirroring the OpenClaw rule). REMOVAL is different: `hermes config
2199
+ * unset` does NOT exist CONFIRMED against Hermes source, whose `config`
2200
+ * subcommands are only show/set/edit/path/env-path/check/migrate. So teardown is
2201
+ * a config.yaml read-merge-write that deletes the Alfe-applied dotted keys via
2202
+ * the `yaml` Document API (`parseDocument` + `deleteIn`), preserving
2203
+ * user-authored keys, comments, and formatting (the same approach
2204
+ * `hermes-mcp-sync.ts` uses for `mcp_servers`). Per-integration contributions are
2205
+ * tracked in a separate file (`~/.hermes/.alfe-integrations.json`) so we know
2206
+ * exactly which keys to delete.
2201
2207
  *
2202
2208
  * Scope (Phase 1, MCP-first hybrid):
2203
2209
  * - config: SUPPORTED — consumes `installs.runtimes.hermes.config` (the AI-proxy
@@ -2243,9 +2249,9 @@ function stringifyConfigValue(value) {
2243
2249
  return typeof value === "string" ? value : JSON.stringify(value);
2244
2250
  }
2245
2251
  /**
2246
- * Describe a `config set/unset` target WITHOUT leaking values. The value
2247
- * argument can be a secret (`model.api_key`), so it must never reach the
2248
- * integration's user-facing `errorMessage`. Keep only the program + verb + key.
2252
+ * Describe a `config set` target WITHOUT leaking values. The value argument can
2253
+ * be a secret (`model.api_key`), so it must never reach the integration's
2254
+ * user-facing `errorMessage`. Keep only the program + verb + key.
2249
2255
  */
2250
2256
  function redactConfigTarget(args) {
2251
2257
  return `hermes config ${args.slice(0, 2).join(" ")}`.trim();
@@ -2270,13 +2276,16 @@ var HermesApplier = class {
2270
2276
  runtime = "hermes";
2271
2277
  home;
2272
2278
  trackingPath;
2279
+ /** `~/.hermes/config.yaml` — read-merge-written on removal (no `config unset`). */
2280
+ configYamlPath;
2273
2281
  configSetRetries;
2274
2282
  configSetRetryDelayMs;
2275
- /** Serializes all `hermes config` writes so they never interleave. */
2283
+ /** Serializes all config mutations (CLI `set` + config.yaml delete) so they never interleave. */
2276
2284
  configSetQueue = Promise.resolve();
2277
2285
  constructor(options = {}) {
2278
2286
  this.home = options.home ?? options.workspace ?? DEFAULT_HERMES_HOME$1;
2279
2287
  this.trackingPath = options.configPath ?? join(this.home, ".alfe-integrations.json");
2288
+ this.configYamlPath = join(this.home, "config.yaml");
2280
2289
  this.configSetRetries = options.configSetRetries ?? CONFIG_SET_RETRIES;
2281
2290
  this.configSetRetryDelayMs = options.configSetRetryDelayMs ?? CONFIG_SET_RETRY_DELAY_MS;
2282
2291
  }
@@ -2311,8 +2320,9 @@ var HermesApplier = class {
2311
2320
  /**
2312
2321
  * Remove config previously applied by an integration.
2313
2322
  *
2314
- * Reads the tracking file to find which keys this integration set, then
2315
- * removes each via `hermes config unset`. Clears the tracking entry.
2323
+ * Reads the tracking file to find which dotted keys this integration set, then
2324
+ * DELETES each from `~/.hermes/config.yaml` via a read-merge-write (there is no
2325
+ * `hermes config unset` verb — see the file header). Clears the tracking entry.
2316
2326
  */
2317
2327
  async removeConfig(integrationId) {
2318
2328
  const tracking = this.readTracking();
@@ -2320,13 +2330,13 @@ var HermesApplier = class {
2320
2330
  if (!(integrationId in integrations)) return;
2321
2331
  const integrationConfig = integrations[integrationId];
2322
2332
  const { leaves } = partitionEntries(flattenConfig(integrationConfig));
2323
- for (const { path } of leaves) try {
2324
- await this.unsetConfigKey(path);
2333
+ try {
2334
+ await this.deleteConfigKeys(leaves.map(({ path }) => path));
2325
2335
  } catch (err) {
2326
2336
  log$2.warn({
2327
2337
  err: err instanceof Error ? err.message : String(err),
2328
- key: path
2329
- }, "Failed to unset config via hermes config unset");
2338
+ integrationId
2339
+ }, "Failed to delete Alfe config keys from ~/.hermes/config.yaml");
2330
2340
  }
2331
2341
  tracking._integrations = Object.fromEntries(Object.entries(integrations).filter(([key]) => key !== integrationId));
2332
2342
  this.writeTracking(tracking);
@@ -2410,23 +2420,40 @@ var HermesApplier = class {
2410
2420
  return this.runConfigCommand(["set", ...setArgs]);
2411
2421
  }
2412
2422
  /**
2413
- * Unset a single config key. The unset verb is isolated HERE so there is one
2414
- * place to change if the spike proves `hermes config unset` is unavailable.
2415
- *
2416
- * FALLBACK (do NOT pre-build): if `hermes config unset` does not exist, the
2417
- * substitute is `hermes config set <key> ""` (clear the value) or a
2418
- * read-merge-write of config.yaml. Not implemented now — `unset` is the
2419
- * documented verb; confirm in the Phase-0 spike before adding a fallback.
2420
- * TODO(phase-0 spike): confirm `hermes config unset <key>` exists.
2423
+ * Delete a set of dotted config keys from `~/.hermes/config.yaml`. There is no
2424
+ * `hermes config unset` verb (see file header), so removal is a read-merge-write
2425
+ * of the YAML via the Document API — preserving user-authored keys, comments,
2426
+ * and formatting. Serialized against every other config mutation on the same
2427
+ * queue so a delete can't interleave with an in-flight `hermes config set`.
2428
+ */
2429
+ deleteConfigKeys(paths) {
2430
+ const run = () => {
2431
+ this.deleteConfigKeysSync(paths);
2432
+ return Promise.resolve();
2433
+ };
2434
+ const result = this.configSetQueue.then(run, run);
2435
+ this.configSetQueue = result.catch(() => void 0);
2436
+ return result;
2437
+ }
2438
+ /**
2439
+ * Synchronous config.yaml read-merge-write: parse the doc, delete each dotted
2440
+ * key (`model.base_url` → `deleteIn(['model','base_url'])`), and write back only
2441
+ * if the text actually changed. No-op if config.yaml doesn't exist yet.
2421
2442
  */
2422
- unsetConfigKey(key) {
2423
- return this.runConfigCommand(["unset", key]);
2443
+ deleteConfigKeysSync(paths) {
2444
+ if (paths.length === 0 || !existsSync(this.configYamlPath)) return;
2445
+ const doc = parseDocument(readFileSync(this.configYamlPath, "utf-8"));
2446
+ const before = doc.toString();
2447
+ for (const path of paths) doc.deleteIn(path.split("."));
2448
+ const after = doc.toString();
2449
+ if (before !== after) writeFileSync(this.configYamlPath, after, "utf-8");
2424
2450
  }
2425
2451
  /**
2426
- * Run `hermes config <args>` (set/unset), serialized against every other
2427
- * config write and retried with backoff. Throws an Error whose (scrubbed)
2428
- * message includes stderr after retries are exhausted, so the real cause
2429
- * propagates to the integration errorMessage without leaking the value.
2452
+ * Run `hermes config <args>` (only `set` is used removal goes via
2453
+ * {@link deleteConfigKeys}), serialized against every other config mutation and
2454
+ * retried with backoff. Throws an Error whose (scrubbed) message includes stderr
2455
+ * after retries are exhausted, so the real cause propagates to the integration
2456
+ * errorMessage without leaking the value.
2430
2457
  */
2431
2458
  runConfigCommand(args) {
2432
2459
  const run = async () => {
@@ -2502,15 +2529,13 @@ var HermesApplier = class {
2502
2529
  const log$1 = createLogger("HermesMcpSync");
2503
2530
  const DEFAULT_HERMES_HOME = join(homedir(), ".hermes");
2504
2531
  /**
2505
- * SPIKE-PENDING SEAM #1 — `${VAR}` interpolation from `~/.hermes/.env`.
2506
- *
2507
- * We inject `ALFE_API_KEY=${ALFE_API_KEY}` into every Alfe-owned stdio server's
2508
- * env and put the real value in `~/.hermes/.env`. This assumes Hermes
2509
- * interpolates `${VAR}` references in `mcp_servers.<id>.env` from `.env` at spawn
2510
- * time. TODO(phase-0 spike): confirm. If Hermes does NOT interpolate, the
2511
- * fallback (NOT built here) is to write the literal `ALFE_API_KEY` VALUE inline
2512
- * into each `mcp_servers.<id>.env` and skip the `.env` file entirely — change
2513
- * `withAlfeApiKey()` + `ensureEnvApiKey()` together in that one case.
2532
+ * SEAM #1 — `${VAR}` interpolation from `~/.hermes/.env`. CONFIRMED (Hermes
2533
+ * source `config.py:5790` `_expand_env_vars`): Hermes loads `~/.hermes/.env` via
2534
+ * dotenv into `os.environ`, then recursively expands `${VAR}` refs across the
2535
+ * ENTIRE merged config including `mcp_servers.<id>.env.*` (and `model.api_key`
2536
+ * / `model.base_url`). So injecting `ALFE_API_KEY=${ALFE_API_KEY}` into every
2537
+ * Alfe-owned stdio server's env and writing the real value to `~/.hermes/.env`
2538
+ * resolves at spawn time. The inline-literal fallback is therefore not needed.
2514
2539
  */
2515
2540
  const ALFE_API_KEY_ENV_REF = "${ALFE_API_KEY}";
2516
2541
  const DEFAULT_DEBOUNCE_MS = 250;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfe.ai/integrations",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Integration lifecycle management for Alfe — registry, resolution, installation, and state",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",