Local-first 🧠memory for Hermes Agent that lives in your Obsidian vault and remembers project context. Nightly 😴 dream passes turn repeat corrections into confirmed preferences with measurable confidence. Adapters ship for Claude Code, Codex, and OpenClaw, with an MCP server for anything else.
TypeScript
import { afterEach, beforeEach, expect, setDefaultTimeout, test } from "bun:test";
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { writePinnedContext, readPinnedContext } from "../../src/core/brain/pinned.ts";
import { runCli } from "../helpers/run-cli.ts";
import { CLI_SPAWN_BUDGET_MS } from "../helpers/cli-timeout.ts";
// Tests here spawn processes; see tests/helpers/cli-timeout.ts.
setDefaultTimeout(CLI_SPAWN_BUDGET_MS);
let vault: string;
beforeEach(() => {
vault = mkdtempSync(join(tmpdir(), "o2b-cli-post-compact-audit-"));
// A legacy tree: these tests pin the page layout of an unswitched
// machine (a vault with no `Brain/` is store-only, task 2.10).
mkdirSync(join(vault, "Brain"), { recursive: true });
});
afterEach(() => {
rmSync(vault, { recursive: true, force: true });
});
const PAYLOAD = JSON.stringify({
session_id: "session-cli",
messages: [
{ role: "system", content: "[CONTEXT SUMMARY]: Operator set a deployment freeze window." },
{ role: "user", content: "Telemetry stays opt-in for every preset." },
],
});
test("default off: post-compact-audit is a no-op without the gate", async () => {
writePinnedContext(vault, "- Maintain the deployment freeze window.");
const result = await runCli(["brain", "post-compact-audit", "--vault", vault, "--json"], {
stdin: PAYLOAD,
env: { OPEN_SECOND_BRAIN_POST_COMPACT_SURVIVAL_AUDIT: "" },
});
expect(result.returncode).toBe(0);
const body = JSON.parse(result.stdout);
expect(body.enabled).toBe(false);
expect(body.forced).toBe(false);
expect(body.compaction_detected).toBe(false);
expect(readPinnedContext(vault).content).not.toContain("Re-asserted standing context");
});
test("gated on: re-asserts the drifted anchor from stdin", async () => {
writePinnedContext(vault, "- Maintain the deployment freeze window.");
const result = await runCli(["brain", "post-compact-audit", "--vault", vault, "--json"], {
stdin: PAYLOAD,
env: { OPEN_SECOND_BRAIN_POST_COMPACT_SURVIVAL_AUDIT: "true" },
});
expect(result.returncode).toBe(0);
expect(result.stderr).toBe("");
const body = JSON.parse(result.stdout);
expect(body.enabled).toBe(true);
expect(body.compaction_detected).toBe(true);
expect(body.drifted).toEqual(["Maintain the deployment freeze window."]);
expect(body.reasserted).toBe(true);
expect(readPinnedContext(vault).content).toContain("Re-asserted standing context");
});
test("--force runs the audit even when the gate is off", async () => {
writePinnedContext(vault, "- Maintain the deployment freeze window.");
const result = await runCli(
["brain", "post-compact-audit", "--vault", vault, "--force", "--json"],
{ stdin: PAYLOAD, env: { OPEN_SECOND_BRAIN_POST_COMPACT_SURVIVAL_AUDIT: "" } },
);
expect(result.returncode).toBe(0);
const body = JSON.parse(result.stdout);
expect(body.compaction_detected).toBe(true);
expect(body.reasserted).toBe(true);
expect(body.enabled).toBe(false);
expect(body.forced).toBe(true);
});