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
3.1 KB
Raw Blame
/**
 * `o2b brain label` CLI surface (t_7a41f42d): controlled-vocabulary
 * classification - assign validates fail-closed against the schema
 * pack, remove drops one dimension, show renders the current set.
 */

import { afterEach, beforeEach, expect, setDefaultTimeout, test } from "bun:test";
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

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-label-"));
  vault = join(tmp, "vault");
  mkdirSync(join(vault, "Brain"), { recursive: true });
  mkdirSync(join(vault, "Notes"), { recursive: true });
  writeFileSync(
    join(vault, "Brain", "_brain.yaml"),
    ["schema_version: 1", "schema:", "  labels:", "    - priority=low", "    - priority=high"].join(
      "\n",
    ) + "\n",
  );
  writeFileSync(join(vault, "Notes", "rollout.md"), "# Rollout\n\nCanary first.\n");
});

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

test("assign writes the label, show renders it, remove drops it", async () => {
  const assign = await runCli([
    "brain",
    "label",
    "Notes/rollout.md",
    "priority=high",
    "--vault",
    vault,
    "--json",
  ]);
  expect(assign.returncode).toBe(0);
  const assigned = JSON.parse(assign.stdout) as { ok: boolean; labels: string[] };
  expect(assigned.ok).toBe(true);
  expect(assigned.labels).toEqual(["priority/high"]);
  expect(readFileSync(join(vault, "Notes", "rollout.md"), "utf8")).toContain("priority/high");

  const show = await runCli([
    "brain",
    "label",
    "Notes/rollout.md",
    "--show",
    "--vault",
    vault,
    "--json",
  ]);
  expect(show.returncode).toBe(0);
  expect(JSON.parse(show.stdout)).toEqual({
    ok: true,
    path: "Notes/rollout.md",
    labels: ["priority/high"],
  });

  const remove = await runCli([
    "brain",
    "label",
    "Notes/rollout.md",
    "--remove",
    "priority",
    "--vault",
    vault,
    "--json",
  ]);
  expect(remove.returncode).toBe(0);
  const removed = JSON.parse(remove.stdout) as { removed: boolean; labels: string[] };
  expect(removed.removed).toBe(true);
  expect(removed.labels).toEqual([]);
});

test("an out-of-vocabulary value is a usage error carrying the allowed list", async () => {
  const result = await runCli([
    "brain",
    "label",
    "Notes/rollout.md",
    "priority=urgent",
    "--vault",
    vault,
  ]);
  expect(result.returncode).toBe(2);
  expect(result.stderr).toContain("allowed values: low, high");
});

test("missing mode or conflicting modes are usage errors", async () => {
  const none = await runCli(["brain", "label", "Notes/rollout.md", "--vault", vault]);
  expect(none.returncode).toBe(2);
  const both = await runCli([
    "brain",
    "label",
    "Notes/rollout.md",
    "priority=high",
    "--show",
    "--vault",
    vault,
  ]);
  expect(both.returncode).toBe(2);
});