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
1.8 KB
Raw Blame
/**
 * Owner-scoped fact visibility (Knowledge Provenance suite).
 *
 * A preference may declare an `owner:` token. When several agents write to one
 * brain, owner-scoped recall keeps each owner's facts separate while shared
 * (ownerless) facts stay visible to all. This module is the fact-layer
 * application of the v1.6 owner-visibility model - it REUSES
 * `src/core/graph/agent-scope.ts` (pageOwner / isOwnerVisible) rather than
 * reimplementing the rule, so the fact layer and the v1.6 search agent-scope
 * share one visibility definition. It is wired into `brain_query` (the
 * per-request fact-recall surface); only preferences carry an `owner`.
 *
 * The default is byte-identical: when no scope is requested (null), every fact
 * is visible exactly as today.
 */

import { isOwnerVisible, ownerToken } from "../graph/agent-scope.ts";
import type { BrainPreference } from "./types.ts";

/**
 * The normalized owner token of a preference, or null when ownerless.
 *
 * Resolves through {@link ownerToken}, the same function `pageOwner` uses,
 * so a preference whose page declared an unresolvable `owner:` (a YAML
 * list, a nested mapping) carries the same `OWNER_UNRESOLVED` verdict here
 * as the page does on the search path — never `null`, which would publish
 * it to every scope.
 */
export function preferenceOwner(pref: Pick<BrainPreference, "owner">): string | null {
  return ownerToken(pref.owner);
}

/**
 * Whether a preference is visible under a requested owner scope. A null scope
 * (no scope requested) makes everything visible; an ownerless fact is always
 * visible; an owned fact is visible only to its own normalized scope.
 */
export function isPreferenceVisible(
  pref: Pick<BrainPreference, "owner">,
  requestedScope: string | null,
): boolean {
  return isOwnerVisible(preferenceOwner(pref), requestedScope);
}