Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(setup): preserve Hermes YAML scalar semantics

morluto66536d0d2e18
diff --git a/src/application/ClientConfigurationDocument.ts b/src/application/ClientConfigurationDocument.ts
index 896442835..c6c99e1e9 100644
--- a/src/application/ClientConfigurationDocument.ts
+++ b/src/application/ClientConfigurationDocument.ts
@@ -1,5 +1,4 @@
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
-import { stringify as stringifyYaml } from "yaml";
import { isDeepStrictEqual } from "node:util";
import {
@@ -11,6 +10,7 @@ import {
import {
editHermesConfigurationYaml,
parseHermesConfigurationYaml,
+ stringifyHermesConfigurationYaml,
} from "./HermesConfigurationYaml.js";
import {
applyEdits,
@@ -1419,7 +1419,7 @@ const serializeHermesConfiguration = (
originalText === undefined ||
isEmptyClientConfigurationText(originalText)
)
- return stringifyYaml(document);
+ return stringifyHermesConfigurationYaml(document);
const serversKey = clientConfigurationServersKey("hermes");
const servers = document[serversKey];
const entry =
diff --git a/src/application/HermesConfigurationYaml.test.ts b/src/application/HermesConfigurationYaml.test.ts
index 41b74fcc9..8f56f8f79 100644
--- a/src/application/HermesConfigurationYaml.test.ts
+++ b/src/application/HermesConfigurationYaml.test.ts
@@ -1,15 +1,17 @@
import { describe, expect, it } from "vitest";
+import { parse } from "yaml";
import {
editHermesConfigurationYaml,
parseHermesConfigurationYaml,
+ stringifyHermesConfigurationYaml,
} from "./HermesConfigurationYaml.js";
describe("Hermes configuration YAML", () => {
it("writes an edited number from its new value", () => {
expect(
- editHermesConfigurationYaml("mode: 0600\nmask: 0x1F\n", ["mode"], 384),
- ).toBe("mode: 384\nmask: 0x1F\n");
+ editHermesConfigurationYaml("mode: 0600\nmask: 0x1F\n", ["mode"], 420),
+ ).toBe("mode: 0644\nmask: 0x1F\n");
});
it("accepts keys Hermes reads as distinct and rejects a repeated key", () => {
@@ -17,5 +19,118 @@ describe("Hermes configuration YAML", () => {
parseHermesConfigurationYaml("0600: octal\n600: decimal\n"),
).not.toThrow();
expect(() => parseHermesConfigurationYaml('a: 1\n"a": 2\n')).toThrow();
+ expect(() => parseHermesConfigurationYaml("yes: 1\ntrue: 2\n")).toThrow();
+ expect(() => parseHermesConfigurationYaml("no: 1\noff: 2\n")).toThrow();
+ });
+
+ it("matches Hermes numeric key equality without losing large integer precision", () => {
+ for (const text of [
+ "1: first\n01: second\n",
+ "1.0: first\n1.00: second\n",
+ "true: first\n1: second\n",
+ "false: first\n0.0: second\n",
+ ".nan: first\n.NAN: second\n",
+ "9007199254740992: first\n9007199254740992.0: second\n",
+ ])
+ expect(() => parseHermesConfigurationYaml(text)).toThrow();
+
+ expect(() =>
+ parseHermesConfigurationYaml(
+ "9007199254740992: first\n9007199254740993: second\n",
+ ),
+ ).not.toThrow();
+ expect(() =>
+ parseHermesConfigurationYaml(
+ "9007199254740993: first\n9007199254740993.0: second\n",
+ ),
+ ).not.toThrow();
+ expect(() =>
+ parseHermesConfigurationYaml("0600: octal\n600: decimal\n"),
+ ).not.toThrow();
+ expect(parseHermesConfigurationYaml("value: 9007199254740993\n")).toEqual({
+ value: Number("9007199254740993"),
+ });
+ });
+
+ it("matches Hermes timestamp key precision, timezone, and date-type equality", () => {
+ for (const text of [
+ "2026-10-14T00:00:00.123456+08:00: first\n2026-10-13T16:00:00.123456Z: second\n",
+ "2026-10-14T00:00:00.1234565Z: first\n2026-10-14T00:00:00.123457Z: second\n",
+ ])
+ expect(() => parseHermesConfigurationYaml(text)).toThrow();
+
+ expect(() =>
+ parseHermesConfigurationYaml(
+ "2026-10-14T00:00:00.123456Z: first\n2026-10-14T00:00:00.123457Z: second\n",
+ ),
+ ).not.toThrow();
+ expect(() =>
+ parseHermesConfigurationYaml(
+ "2026-10-14: date\n2026-10-14T00:00:00Z: timestamp\n",
+ ),
+ ).not.toThrow();
+ expect(() =>
+ parseHermesConfigurationYaml(
+ "2026-10-14T00:00:00: local\n2026-10-14T00:00:00Z: utc\n",
+ ),
+ ).not.toThrow();
+ });
+
+ it("matches Hermes timestamp resolution and rejects invalid calendar values", () => {
+ expect(parseHermesConfigurationYaml("short: 2026-1-1\n")).toEqual({
+ short: "2026-1-1",
+ });
+ expect(
+ parseHermesConfigurationYaml("short: 2026-1-1 1:02:03.\n"),
+ ).toMatchObject({ short: expect.any(Date) });
+ expect(
+ parseHermesConfigurationYaml("short: 2026-01-01 1:02:03\n"),
+ ).toMatchObject({ short: expect.any(Date) });
+ expect(parseHermesConfigurationYaml("short: 2026-01-01 1:2:03\n")).toEqual({
+ short: "2026-01-01 1:2:03",
+ });
+ expect(parseHermesConfigurationYaml("short: 2026-01-01 1:02:3\n")).toEqual({
+ short: "2026-01-01 1:02:3",
+ });
+ const firstYear = parseHermesConfigurationYaml("date: 0001-01-01\n") as {
+ date: Date;
+ };
+ expect(firstYear.date.getUTCFullYear()).toBe(1);
+ expect(
+ parseHermesConfigurationYaml("date: 1969-12-31T23:59:59.999999Z\n"),
+ ).toEqual({ date: new Date("1969-12-31T23:59:59.999Z") });
+
+ for (const invalid of [
+ "date: 0000-01-01\n",
+ "date: 2026-02-30\n",
+ "date: 2026-01-01 24:00:00\n",
+ "date: 2026-01-01 00:00:00+24\n",
+ "date: 9999-12-31T23:59:59.9999995Z\n",
+ ])
+ expect(() => parseHermesConfigurationYaml(invalid)).toThrow();
+ });
+
+ it("preserves YAML 1.1 strings on fresh files and honors directives on edits", () => {
+ const created = stringifyHermesConfigurationYaml({
+ mcp_servers: { rea: { env: { PROFILE: "off" } } },
+ });
+ expect(parse(created, { version: "1.1" })).toMatchObject({
+ mcp_servers: { rea: { env: { PROFILE: "off" } } },
+ });
+
+ const original =
+ "%YAML 1.2\n---\nnotify: on\ntimestamp: 2026-10-14T00:00:00.123456+08:00\n";
+ const updated = editHermesConfigurationYaml(original, ["environment"], {
+ SETTING: "off",
+ DATE: "2026-10-14",
+ });
+ expect(updated.startsWith(original)).toBe(true);
+ expect(parse(updated)).toMatchObject({
+ notify: "on",
+ environment: { SETTING: "off", DATE: "2026-10-14" },
+ });
+ expect(
+ parseHermesConfigurationYaml("%YAML 1.2\n---\ndate: 2026-10-14\n"),
+ ).toEqual({ date: new Date("2026-10-14") });
});
});
diff --git a/src/application/HermesConfigurationYaml.ts b/src/application/HermesConfigurationYaml.ts
index 61eb0dfde..509201187 100644
--- a/src/application/HermesConfigurationYaml.ts
+++ b/src/application/HermesConfigurationYaml.ts
@@ -1,28 +1,195 @@
import {
isScalar,
parseDocument,
- type Document,
+ Document,
+ Schema,
type ParsedNode,
type ScalarTag,
type Tags,
} from "yaml";
-const NUMBER_TAGS = new Set([
+const SOURCE_SCALAR_TAGS = new Set([
"tag:yaml.org,2002:int",
"tag:yaml.org,2002:float",
+ "tag:yaml.org,2002:timestamp",
]);
+// Hermes's ruamel reader resolves dates even with an explicit YAML 1.2 directive.
+const timestampTag = new Schema({ schema: "yaml-1.1" }).tags.find(
+ (tag): tag is ScalarTag =>
+ tag.tag === "tag:yaml.org,2002:timestamp" && tag.collection === undefined,
+);
+if (timestampTag === undefined)
+ throw new Error("The YAML 1.1 schema must provide its timestamp tag");
+
+type HermesKey =
+ | { readonly kind: "numeric"; readonly value: bigint | number }
+ | { readonly kind: "timestamp"; readonly value: string }
+ | { readonly kind: "other"; readonly value: unknown };
+
+const timestampSource =
+ /^(\d{4})-(\d{1,2})-(\d{1,2})(?:(?:[Tt]|[ \t]+)(\d{1,2}):(\d{2}):(\d{2})(?:\.([0-9]*))?(?:[ \t]*(Z|([-+])(\d{1,2})(?::(\d{2}))?))?)?$/;
+
+const hermesTimestampImplicit =
+ /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|[ \t]+)\d{1,2}:\d{2}:\d{2}(?:\.[0-9]*)?(?:[ \t]*(?:Z|[-+]\d{1,2}(?::\d{2})?))?)$/;
+
+interface HermesTimestampFacts {
+ readonly key: string;
+ readonly value: Date;
+}
+
+const floorDivide = (value: number, divisor: number): number =>
+ Math.floor(value / divisor);
+
+/** Days since 1970-01-01 using the proleptic Gregorian calendar. */
+const civilDay = (year: number, month: number, day: number): number => {
+ const adjustedYear = year - (month <= 2 ? 1 : 0);
+ const era = floorDivide(adjustedYear, 400);
+ const yearOfEra = adjustedYear - era * 400;
+ const adjustedMonth = month + (month > 2 ? -3 : 9);
+ const dayOfYear = floorDivide(153 * adjustedMonth + 2, 5) + day - 1;
+ const dayOfEra =
+ yearOfEra * 365 +
+ floorDivide(yearOfEra, 4) -
+ floorDivide(yearOfEra, 100) +
+ dayOfYear;
+ return era * 146097 + dayOfEra - 719468;
+};
+
+/** Parse the exact timestamp forms and values accepted by ruamel's safe loader. */
+const parseHermesTimestamp = (
+ source: string,
+): HermesTimestampFacts | undefined => {
+ const match = timestampSource.exec(source);
+ if (match === null) return undefined;
+ const [
+ ,
+ yearText,
+ monthText,
+ dayText,
+ hourText,
+ minuteText,
+ secondText,
+ fraction,
+ zone,
+ sign,
+ zoneHourText,
+ zoneMinuteText,
+ ] = match;
+ if (
+ yearText === undefined ||
+ monthText === undefined ||
+ dayText === undefined
+ )
+ return undefined;
+ const year = Number(yearText);
+ const month = Number(monthText);
+ const dayOfMonth = Number(dayText);
+ if (year < 1 || year > 9999 || month < 1 || month > 12) return undefined;
+ const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
+ const monthDays = [
+ 31,
+ leapYear ? 29 : 28,
+ 31,
+ 30,
+ 31,
+ 30,
+ 31,
+ 31,
+ 30,
+ 31,
+ 30,
+ 31,
+ ];
+ if (dayOfMonth < 1 || dayOfMonth > (monthDays[month - 1] ?? 0))
+ return undefined;
+ const date = `${yearText}-${monthText.padStart(2, "0")}-${dayText.padStart(2, "0")}`;
+ const day = civilDay(year, month, dayOfMonth);
+ if (hourText === undefined) {
+ const micros = BigInt(day) * 86_400_000_000n;
+ return { key: `date:${date}`, value: new Date(Number(micros / 1000n)) };
+ }
+
+ const hour = Number(hourText);
+ const minute = Number(minuteText);
+ const second = Number(secondText);
+ if (hour > 23 || minute > 59 || second > 59) return undefined;
+ const zoneHour = Number(zoneHourText ?? 0);
+ const zoneMinute = Number(zoneMinuteText ?? 0);
+ if (zoneHour > 23 || zoneMinute > 59) return undefined;
+
+ let microseconds = 0;
+ if (fraction !== undefined && fraction.length > 0) {
+ microseconds = Number((fraction.slice(0, 6) + "000000").slice(0, 6));
+ if (fraction.length > 6 && Number(fraction[6]) > 4) microseconds += 1;
+ }
+ const wholeSeconds = hour * 3600 + minute * 60 + second;
+ if (
+ year === 9999 &&
+ month === 12 &&
+ dayOfMonth === 31 &&
+ wholeSeconds === 86_399 &&
+ microseconds === 1_000_000
+ )
+ return undefined;
+ let micros =
+ BigInt(day) * 86_400_000_000n +
+ BigInt(wholeSeconds) * 1_000_000n +
+ BigInt(microseconds);
+ if (zone !== undefined && zone !== "Z") {
+ const offset = (zoneHour * 60 + zoneMinute) * (sign === "+" ? 1 : -1);
+ micros -= BigInt(offset) * 60_000_000n;
+ }
+ return {
+ key:
+ zone === undefined
+ ? `datetime-local:${micros}`
+ : `datetime-utc:${micros}`,
+ value: new Date(Number(micros / 1000n - (micros % 1000n < 0n ? 1n : 0n))),
+ };
+};
+
+const numericValue = (value: unknown): bigint | number | undefined => {
+ if (typeof value === "boolean") return value ? 1n : 0n;
+ if (typeof value === "bigint" || typeof value === "number") return value;
+ return undefined;
+};
+
+const numericValuesEqual = (
+ left: bigint | number,
+ right: bigint | number,
+): boolean => {
+ if (typeof left === "bigint" && typeof right === "bigint")
+ return left === right;
+ if (typeof left === "number" && typeof right === "number")
+ return left === right || (Number.isNaN(left) && Number.isNaN(right));
+ const integer = typeof left === "bigint" ? left : right;
+ const number = typeof left === "number" ? left : right;
+ return (
+ Number.isFinite(number) &&
+ Number.isInteger(number) &&
+ BigInt(number) === integer
+ );
+};
+
+const sameResolvedScalarValue = (left: unknown, right: unknown): boolean =>
+ Object.is(left, right) ||
+ (left instanceof Date &&
+ right instanceof Date &&
+ left.getTime() === right.getTime());
+
/**
- * Write a parsed number with its source spelling while that spelling still
+ * Write a parsed scalar with its source spelling while that spelling still
* reads as the node's value. Hermes reads config.yaml as YAML 1.1 with exact
* integers, so re-printing a JavaScript number changes what it reads: a
* Discord channel ID loses its low digits, `0600` (octal) becomes `600`, and
* `0.0000001` becomes `1e-7`, which YAML 1.1 does not define as a float.
+ * Timestamp source also retains precision and offsets absent from JS Dates.
*/
-const keepNumberSource = (tag: Tags[number]): Tags[number] => {
+const keepScalarSource = (tag: Tags[number]): Tags[number] => {
if (typeof tag === "string" || tag.collection !== undefined) return tag;
const { stringify } = tag;
- if (!NUMBER_TAGS.has(tag.tag) || stringify === undefined) return tag;
+ if (!SOURCE_SCALAR_TAGS.has(tag.tag) || stringify === undefined) return tag;
return {
...tag,
stringify: (item, context, ...rest) => {
@@ -37,25 +204,96 @@ const keepNumberSource = (tag: Tags[number]): Tags[number] => {
() => undefined,
context.doc.options,
);
- return Object.is(isScalar(read) ? read.value : read, item.value)
+ return sameResolvedScalarValue(
+ isScalar(read) ? read.value : read,
+ item.value,
+ )
? source
: stringify(item, context, ...rest);
},
};
};
-const HERMES_YAML_OPTIONS = {
- customTags: (tags: Tags) => tags.map(keepNumberSource),
- // Hermes keeps integers exact, so IDs that round to one double, or `0600`
- // and `600`, are distinct keys.
- uniqueKeys: (a: ParsedNode, b: ParsedNode) =>
- a === b ||
- (isScalar(a) &&
- isScalar(b) &&
- a.value === b.value &&
- a.source === b.source),
+const createHermesYamlOptions = () => {
+ const timestamps = new Map<string, HermesTimestampFacts | undefined>();
+ const timestampFacts = (source: string): HermesTimestampFacts | undefined => {
+ if (timestamps.has(source)) return timestamps.get(source);
+ const facts = parseHermesTimestamp(source);
+ timestamps.set(source, facts);
+ return facts;
+ };
+ const hermesTimestampTag: ScalarTag = {
+ ...timestampTag,
+ test: hermesTimestampImplicit,
+ resolve: (source) => {
+ const facts = timestampFacts(source);
+ if (facts === undefined)
+ throw new Error(`Invalid Hermes YAML timestamp: ${source}`);
+ return facts.value;
+ },
+ };
+ const keyFacts = new WeakMap<object, HermesKey>();
+ const hermesKey = (node: ParsedNode): HermesKey => {
+ const cached = keyFacts.get(node);
+ if (cached !== undefined) return cached;
+ if (!isScalar(node)) return { kind: "other", value: node };
+ const numeric = numericValue(node.value);
+ const key =
+ numeric !== undefined
+ ? { kind: "numeric" as const, value: numeric }
+ : node.value instanceof Date
+ ? {
+ kind: "timestamp" as const,
+ value:
+ timestampFacts(node.source ?? "")?.key ??
+ `invalid:${node.source ?? ""}`,
+ }
+ : { kind: "other" as const, value: node.value };
+ keyFacts.set(node, key);
+ return key;
+ };
+ /** Python dict key equality is Hermes' duplicate-key behavior (bool is int). */
+ const hermesKeysEqual = (
+ leftNode: ParsedNode,
+ rightNode: ParsedNode,
+ ): boolean => {
+ const left = hermesKey(leftNode);
+ const right = hermesKey(rightNode);
+ if (left.kind !== right.kind) return false;
+ if (left.kind === "numeric" && right.kind === "numeric")
+ return numericValuesEqual(left.value, right.value);
+ return left.value === right.value;
+ };
+ return {
+ // Hermes defaults to YAML 1.1; an explicit document directive still wins.
+ // Use the same schema to interpret existing values and quote new strings.
+ version: "1.1" as const,
+ // Keep integer key identity exact; parseHermesConfigurationYaml's reviver
+ // restores the existing number-valued consumer contract.
+ intAsBigInt: true,
+ customTags: (tags: Tags) => {
+ const hasTimestamp = tags.some(
+ (tag) => typeof tag !== "string" && tag.tag === timestampTag.tag,
+ );
+ const withHermesTimestamp = hasTimestamp
+ ? tags.map((tag) =>
+ typeof tag !== "string" && tag.tag === timestampTag.tag
+ ? hermesTimestampTag
+ : tag,
+ )
+ : [...tags, hermesTimestampTag];
+ return withHermesTimestamp.map(keepScalarSource);
+ },
+ uniqueKeys: hermesKeysEqual,
+ };
};
+/** Create a Hermes config using the same scalar rules as edits and readback. */
+export const stringifyHermesConfigurationYaml = (
+ document: Record<string, unknown>,
+): string =>
+ new Document(document, createHermesYamlOptions()).toString({ lineWidth: 0 });
+
// A comment-only document has no root; a bare marker has an unwritten null
// scalar. Explicit null values, tags and anchors remain actual values.
const isEmptyYamlRoot = (root: Document["contents"]): boolean =>
@@ -67,7 +305,7 @@ const isEmptyYamlRoot = (root: Document["contents"]): boolean =>
root.anchor === undefined);
const parseHermesDocument = (text: string) => {
- const document = parseDocument(text, HERMES_YAML_OPTIONS);
+ const document = parseDocument(text, createHermesYamlOptions());
const error = document.errors[0];
if (error !== undefined) throw error;
return document;
@@ -76,7 +314,12 @@ const parseHermesDocument = (text: string) => {
/** Parse a Hermes `config.yaml`, preserving the distinction between no root and explicit null. */
export const parseHermesConfigurationYaml = (text: string): unknown => {
const document = parseHermesDocument(text);
- return isEmptyYamlRoot(document.contents) ? {} : document.toJS();
+ return isEmptyYamlRoot(document.contents)
+ ? {}
+ : document.toJS({
+ reviver: (_key, value) =>
+ typeof value === "bigint" ? Number(value) : value,
+ });
};
/** Set or delete one value in a Hermes `config.yaml`, keeping the rest as written. */
@@ -88,15 +331,25 @@ export const editHermesConfigurationYaml = (
// A plain Document, so a bare `---` root can be replaced by a new map.
const document: Document = parseHermesDocument(text);
const root = document.contents;
- if (isScalar(root) && isEmptyYamlRoot(root)) {
+ if (isEmptyYamlRoot(root)) {
const map = document.createNode({});
- map.commentBefore = [root.commentBefore, root.comment]
- .filter((comment) => comment !== undefined)
- .join("\n");
+ if (isScalar(root))
+ map.commentBefore = [root.commentBefore, root.comment]
+ .filter((comment) => comment !== undefined)
+ .join("\n");
document.contents = map;
}
if (value === undefined) document.deleteIn(path);
- else document.setIn(path, value);
+ else {
+ // setIn's implicit JS Map parents serialize as !!omap in YAML 1.1.
+ // Config settings are ordinary mappings, including absent server tables.
+ for (let length = 1; length < path.length; length++) {
+ const parent = path.slice(0, length);
+ if (!document.hasIn(parent))
+ document.setIn(parent, document.createNode({}));
+ }
+ document.setIn(path, value);
+ }
// Editing REA must not reflow unrelated user prompts or other YAML scalars.
return document.toString({ lineWidth: 0 });
};
diff --git a/tests/acceptance/setup/hermesClientSetup.test.ts b/tests/acceptance/setup/hermesClientSetup.test.ts
index 5a7baa333..4dff5c7ed 100644
--- a/tests/acceptance/setup/hermesClientSetup.test.ts
+++ b/tests/acceptance/setup/hermesClientSetup.test.ts
@@ -6,6 +6,76 @@ import { expect } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
+cliTest(
+ "Hermes setup preserves string environment values under the client's YAML 1.1 schema",
+ async ({ cli }) => {
+ const home = await createTestTempDirectory("rea-hermes-yaml-strings-");
+ const profile = join(home, "hermes");
+ const config = join(profile, "config.yaml");
+ const environment = {
+ REA_MCP_OUTPUT_SCHEMA_PROFILE: "off",
+ ON: "on",
+ YES: "yes",
+ NO: "no",
+ SHORT_TRUE: "y",
+ SHORT_FALSE: "n",
+ DATE: "2026-10-14",
+ TIME: "12:34:56",
+ FLOAT: "1.0e-7",
+ OCTAL: "0600",
+ NULL_WORD: "NULL",
+ NULL_MARKER: "~",
+ };
+ const settings =
+ "# User settings\nnotifications: on\ndate: 2026-10-14\n" +
+ "timestamp: 2026-10-14T00:00:00.123456+08:00\n";
+ const original =
+ settings +
+ "mcp_servers:\n rea:\n command: rea-old\n args: [mcp]\n env:\n" +
+ Object.entries(environment)
+ .map(
+ ([key, value]) =>
+ ` ${JSON.stringify(key)}: ${JSON.stringify(value)}\n`,
+ )
+ .join("");
+ await mkdir(profile);
+ await writeFile(config, original);
+ const run = (arguments_: readonly string[]) =>
+ cli.run({
+ arguments: arguments_,
+ cwd: home,
+ environment: { USERPROFILE: home, HERMES_HOME: profile },
+ timeoutMs: 20_000,
+ });
+ const setup = [
+ "setup",
+ "--client",
+ "hermes",
+ "--skill=false",
+ "--yes",
+ "--json",
+ ];
+ expect((await run(setup)).json).toMatchObject({ status: "ready" });
+ const configured = await readFile(config, "utf8");
+ expect(parse(configured, { version: "1.1" })).toMatchObject({
+ mcp_servers: { rea: { env: environment, enabled: true } },
+ });
+ expect(configured.startsWith(settings)).toBe(true);
+ expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
+ expect(
+ (await run(["doctor", "--client", "hermes", "--json"])).json,
+ ).toMatchObject({
+ healthy: true,
+ identity: { registrations: [{ client: "hermes", state: "aligned" }] },
+ });
+ expect((await run(setup)).json).toMatchObject({
+ status: "ready",
+ appliedActions: [],
+ });
+ expect(await readFile(config, "utf8")).toBe(configured);
+ },
+);
+
cliTest(
"Hermes setup, doctor and uninstall use the expanded profile and its personal skill",
async ({ cli }) => {
diff --git a/tests/boundary/filesystem/hermesClientConfiguration.test.ts b/tests/boundary/filesystem/hermesClientConfiguration.test.ts
index 7bd72a676..5923ebff6 100644
--- a/tests/boundary/filesystem/hermesClientConfiguration.test.ts
+++ b/tests/boundary/filesystem/hermesClientConfiguration.test.ts
@@ -287,16 +287,53 @@ mcp_servers:
it("creates config.yaml when Hermes has no configuration yet", async () => {
const { client } = await hermesClient();
+ const environment = { REA_MCP_OUTPUT_SCHEMA_PROFILE: "off" };
expect(
- (await configureClientConfiguration(client, {}, command)).status,
+ (await configureClientConfiguration(client, environment, command)).status,
).toBe("configured");
- expect(parseYaml(await readFile(client.configPath, "utf8"))).toEqual({
+ expect(
+ parseYaml(await readFile(client.configPath, "utf8"), { version: "1.1" }),
+ ).toEqual({
mcp_servers: {
- rea: { command: command[0], args: command.slice(1), enabled: true },
+ rea: {
+ command: command[0],
+ args: command.slice(1),
+ env: environment,
+ enabled: true,
+ },
},
});
});
+ it.each(["off", "2026-10-14", "12:34:56"])(
+ "refuses an environment value %s that Hermes parses as a non-string",
+ async (value) => {
+ const { home, client } = await hermesClient();
+ const original = `mcp_servers:\n rea:\n command: rea\n args: [mcp]\n env:\n CUSTOM_SETTING: ${value}\n`;
+ await writeFile(client.configPath, original);
+ expect(
+ await inspectClientConfiguration(client, {}, command),
+ ).toMatchObject({
+ status: "invalid",
+ remediation: expect.stringContaining("CUSTOM_SETTING"),
+ });
+ expect(
+ await configureClientConfiguration(client, {}, command),
+ ).toMatchObject({ status: "failed" });
+ expect(
+ (
+ await readClientRegistrationStatuses(home, "rea", {
+ environment: {},
+ })
+ ).find(({ client: name }) => name === "hermes"),
+ ).toMatchObject({ state: "invalid" });
+ expect(await readFile(client.configPath, "utf8")).toBe(original);
+ await expect(
+ readFile(`${client.configPath}.rea.backup`, "utf8"),
+ ).rejects.toThrow();
+ },
+ );
+
// Comments and a bare document marker parse to a null document, like an
// empty file, and are kept ahead of the new registration.
});