Skip to content

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
2.3 KB
Raw Blame
/**
 * `o2b brain dead-end` CLI surface (t_be62c62d): record and list the
 * negative-knowledge registry.
 */

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 { listDeadEnds } from "../../src/core/brain/dead-ends.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 tmp: string;
let vault: string;

beforeEach(() => {
  tmp = mkdtempSync(join(tmpdir(), "o2b-cli-dead-end-"));
  vault = join(tmp, "vault");
  mkdirSync(join(vault, "Brain"), { recursive: true });
});

afterEach(() => {
  rmSync(tmp, { recursive: true, force: true });
});

test("record persists a dead-end note; list renders it", async () => {
  const rec = await runCli([
    "brain",
    "dead-end",
    "record",
    "--vault",
    vault,
    "--approach",
    "Polling the dashboard every second",
    "--reason",
    "Rate limits made the queue collapse",
    "--context",
    "kanban wrapper rework",
    "--json",
  ]);
  expect(rec.returncode).toBe(0);
  const body = JSON.parse(rec.stdout) as { ok: boolean; id: string };
  expect(body.ok).toBe(true);
  expect(body.id).toContain("polling-the-dashboard");
  expect(listDeadEnds(vault).entries).toHaveLength(1);

  const list = await runCli(["brain", "dead-end", "list", "--vault", vault, "--json"]);
  expect(list.returncode).toBe(0);
  const listed = JSON.parse(list.stdout) as {
    entries: Array<{ approach: string; reason: string; context: string | null }>;
  };
  expect(listed.entries[0]!.approach).toBe("Polling the dashboard every second");
  expect(listed.entries[0]!.reason).toContain("Rate limits");
  expect(listed.entries[0]!.context).toBe("kanban wrapper rework");
});

test("record without required flags exits 2", async () => {
  const res = await runCli(["brain", "dead-end", "record", "--vault", vault, "--approach", "x"]);
  expect(res.returncode).toBe(2);
});

test("unknown op exits 2", async () => {
  const res = await runCli(["brain", "dead-end", "bogus", "--vault", vault]);
  expect(res.returncode).toBe(2);
});