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 { test, expect, beforeEach, afterEach } from "bun:test";
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { walkVault } from "../../../src/core/search/walker.ts";
import {
createTempVault,
writeMd,
writeSymlink,
makeConfig,
} from "../../helpers/search-fixtures.ts";
let vault: string;
let cleanup: () => void;
beforeEach(() => {
const v = createTempVault("walker");
vault = v.vault;
cleanup = v.cleanup;
});
afterEach(() => {
cleanup();
});
function collect(cfg: ReturnType<typeof makeConfig>): string[] {
const out: string[] = [];
for (const f of walkVault(cfg)) out.push(f.relPath);
return out.toSorted();
}
test("returns *.md files relative to vault, POSIX paths", () => {
writeMd(vault, "a.md", "# a");
writeMd(vault, "b/c.md", "# c");
writeMd(vault, "b/d/e.md", "# e");
const cfg = makeConfig({ vault, dbPath: join(vault, "x.sqlite") });
expect(collect(cfg)).toEqual(["a.md", "b/c.md", "b/d/e.md"]);
});
test("skips non-md files", () => {
writeMd(vault, "keep.md", "x");
writeMd(vault, "drop.txt", "x");
writeMd(vault, "Notes/README", "x");
const cfg = makeConfig({ vault, dbPath: join(vault, "x.sqlite") });
expect(collect(cfg)).toEqual(["keep.md"]);
});
test("skips ignored bare directory names anywhere in tree", () => {
writeMd(vault, "keep.md", "x");
writeMd(vault, ".git/dropped.md", "x");
writeMd(vault, "node_modules/lib/index.md", "x");
writeMd(vault, "deep/.git/also-dropped.md", "x");
const cfg = makeConfig({ vault, dbPath: join(vault, "x.sqlite") });
expect(collect(cfg)).toEqual(["keep.md"]);
});
test("skips ignored relative-path directories but keeps sibling subtrees", () => {
writeMd(vault, "keep.md", "x");
// `Brain/.snapshots` is a path-style rule in the default set.
writeMd(vault, "Brain/.snapshots/2026-05-19.md", "x");
// `Brain/active.md` is a sibling under the same parent — must NOT
// be eaten by the snapshots rule.
writeMd(vault, "Brain/active.md", "x");
const cfg = makeConfig({ vault, dbPath: join(vault, "x.sqlite") });
expect(collect(cfg)).toEqual(["Brain/active.md", "keep.md"]);
});
test("v0.10.9 default: full .obsidian directory is excluded", () => {
writeMd(vault, "keep.md", "x");
writeMd(vault, ".obsidian/cache/cached.md", "x");
writeMd(vault, ".obsidian/plugins/foo/note.md", "x");
writeMd(vault, ".obsidian/app.md", "x");
const cfg = makeConfig({ vault, dbPath: join(vault, "x.sqlite") });
expect(collect(cfg)).toEqual(["keep.md"]);
});
test("ignores symlinks pointing outside vault", () => {
const outside = mkdtempSync(join(tmpdir(), "osb-walker-out-"));
writeFileSync(join(outside, "leak.md"), "secret");
mkdirSync(join(vault, "inside"), { recursive: true });
// Symlink file → outside file
writeSymlink(vault, "evil.md", join(outside, "leak.md"));
// Symlink dir → outside dir
writeSymlink(vault, "linked-dir", outside);
writeMd(vault, "real.md", "x");
const cfg = makeConfig({ vault, dbPath: join(vault, "x.sqlite") });
const found = collect(cfg);
expect(found).toContain("real.md");
expect(found).not.toContain("evil.md");
expect(found.find((p) => p.startsWith("linked-dir/"))).toBeUndefined();
rmSync(outside, { recursive: true, force: true });
});
test("hidden non-ignored dirs are still walked", () => {
writeMd(vault, ".hiddendir/note.md", "x");
writeMd(vault, "normal.md", "x");
const cfg = makeConfig({ vault, dbPath: join(vault, "x.sqlite"), ignorePaths: [".git"] });
expect(collect(cfg)).toEqual([".hiddendir/note.md", "normal.md"]);
});
test("empty directories produce zero files", () => {
mkdirSync(join(vault, "empty"), { recursive: true });
const cfg = makeConfig({ vault, dbPath: join(vault, "x.sqlite") });
expect(collect(cfg)).toEqual([]);
});
test("yields the NFC identity for an NFD filename on disk (cross-device stability)", () => {
// Write a file whose name is decomposed (NFD: "e" + combining acute),
// the form macOS stores. The walker must report the precomposed NFC
// identity so the stored index key matches a Linux/Android peer that
// produced the same note - otherwise change detection re-indexes it on
// every device and phantom duplicates appear.
// Derive the two forms programmatically so the on-disk name is
// genuinely decomposed regardless of how this source file is itself
// normalised by the editor.
const nfcName = "café.md".normalize("NFC");
const nfdName = nfcName.normalize("NFD");
expect(nfdName).not.toBe(nfcName); // fixture sanity: forms differ on the wire
writeMd(vault, nfdName, "# cafe");
const cfg = makeConfig({ vault, dbPath: join(vault, "x.sqlite") });
const relPaths = collect(cfg);
expect(relPaths).toContain(nfcName);
});
// ----- vault.include_paths ---------------------------------------------------
test("absent include_paths yields exactly the files the walker yielded before the key existed", () => {
// Recorded against v1.45.1 over this fixture tree: the search walker is
// the surface that decides what gets indexed, so its output is where
// "byte-identical when the key is absent" has to hold.
writeMd(vault, "Brain/preferences/pref-a.md", "x");
writeMd(vault, "Brain/.snapshots/2026-01-01.md", "x");
writeMd(vault, "Brain/state/live.md", "x");
writeMd(vault, "Notes/idea.md", "x");
writeMd(vault, "Notes/deep/nested.md", "x");
writeMd(vault, "Notes-archive/old.md", "x");
writeMd(vault, "Journal/2026/entry.md", "x");
writeMd(vault, "top.md", "x");
writeMd(vault, ".obsidian/plugin.md", "x");
writeMd(vault, "node_modules/pkg/readme.md", "x");
const cfg = makeConfig({ vault, dbPath: join(vault, "x.sqlite") });
expect(collect(cfg)).toEqual([
"Brain/preferences/pref-a.md",
"Journal/2026/entry.md",
"Notes-archive/old.md",
"Notes/deep/nested.md",
"Notes/idea.md",
"top.md",
]);
});
test("a declared allowlist yields only the named roots, minus the exclusions", () => {
writeMd(vault, "Brain/preferences/pref-a.md", "x");
writeMd(vault, "Brain/.snapshots/2026-01-01.md", "x");
writeMd(vault, "Notes/idea.md", "x");
writeMd(vault, "Notes-archive/old.md", "x");
writeMd(vault, "top.md", "x");
const cfg = makeConfig({
vault,
dbPath: join(vault, "x.sqlite"),
includePaths: ["Brain"],
});
// `Brain/.snapshots` stays excluded: the allowlist narrows, it never
// re-includes something the exclusion set removed.
expect(collect(cfg)).toEqual(["Brain/preferences/pref-a.md"]);
});
test("an allowlist root nested below an undeclared parent is still reached", () => {
// The include side narrows FILES. A walker that refused to descend
// `Notes` because no file directly under it is included would never
// reach the declared root.
writeMd(vault, "Notes/Daily/2026-05-19.md", "x");
writeMd(vault, "Notes/idea.md", "x");
const cfg = makeConfig({
vault,
dbPath: join(vault, "x.sqlite"),
includePaths: ["Notes/Daily"],
});
expect(collect(cfg)).toEqual(["Notes/Daily/2026-05-19.md"]);
});