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
v0.10.11: address CodeRabbit review
Sol Aitken852c9b558f06
diff --git a/install.md b/install.mdindex d0382aec..c4de6099 100644--- a/install.md+++ b/install.md@@ -88,15 +88,24 @@ uninstall process.The installation is complete only when all of the following hold:-- [ ] plugin (or per-target managed block) installed;+Universal:++- [ ] plugin (or per-target managed block / symlink / printout)+ installed;- [ ] runtime restarted to pick up the change;-- [ ] all tools advertised by the runtime's MCP listing;- [ ] vault initialized (`o2b init` succeeded);- [ ] `o2b doctor` reports OK;-- [ ] `o2b install --check` reports `ok` for the target;+- [ ] `o2b install --check` reports `ok` (or `installed` for `generic`)+ for the target;- [ ] `AI Wiki/identity/agents.md` contains the chosen agent name;- [ ] a test event written without an explicit `agent` argumentstamps `@<chosen-agent-name>` in `Daily/`, not `@agent`.+MCP-driven runtimes only (Cursor, opencode, kiro, Copilot CLI,+Gemini CLI, Claude Code, Codex, Hermes β not `aider`, `pi`, or+`generic`):++- [ ] all OSB tools advertised by the runtime's MCP listing.+If any single item is missing, the install is incomplete β reportthat to the user and do not mark the workflow as successful.diff --git a/install/claudecode.md b/install/claudecode.mdindex dca67ef0..8267e663 100644--- a/install/claudecode.md+++ b/install/claudecode.md@@ -16,7 +16,9 @@ claude plugin install open-second-brain@open-second-brainClaude caches the plugin at a versioned path; locate the script:```bash-"$(find ~/.claude/plugins/cache -path '*open-second-brain*/scripts/o2b' -type f 2>/dev/null | head -1)" install-cli+O2B_SCRIPT="$(find ~/.claude/plugins/cache -path '*open-second-brain*/scripts/o2b' -type f 2>/dev/null | head -1)"+[ -n "$O2B_SCRIPT" ] || { echo "o2b installer not found in Claude plugin cache" >&2; exit 1; }+"$O2B_SCRIPT" install-cli```## 3. Initialize the vaultdiff --git a/install/codex.md b/install/codex.mdindex 2c2bf6f7..65df9298 100644--- a/install/codex.md+++ b/install/codex.md@@ -21,7 +21,9 @@ Codex caches the plugin at a version-hashed path; locate thescript:```bash-"$(find ~/.codex -path '*open-second-brain*/scripts/o2b' -type f 2>/dev/null | head -1)" install-cli+O2B_SCRIPT="$(find ~/.codex -path '*open-second-brain*/scripts/o2b' -type f 2>/dev/null | head -1)"+[ -n "$O2B_SCRIPT" ] || { echo "o2b installer not found in Codex plugin cache" >&2; exit 1; }+"$O2B_SCRIPT" install-cli```## 3. Initialize the vaultdiff --git a/install/openclaw.md b/install/openclaw.mdindex 65c58f21..92fd0253 100644--- a/install/openclaw.md+++ b/install/openclaw.md@@ -26,10 +26,20 @@ openclaw gateway restart## 2. Publish the `o2b` CLI on PATH+Run from the plugin checkout directory:+```bash./scripts/o2b install-cli```+If you don't know the checkout path, the absolute-path variant works+from anywhere (OpenClaw stores installed plugins under `~/.openclaw/`+by default):++```bash+"$(find ~/.openclaw -path '*open-second-brain*/scripts/o2b' -type f 2>/dev/null | head -1)" install-cli+```+## 3. Initialize the vault```bash@@ -49,6 +59,11 @@ openclaw config set plugins.entries.open-second-brain.config.agentName '"<chosenopenclaw config set plugins.entries.open-second-brain.config.timezone '"<chosen-tz>"'```+The values are stored as JSON, so string values must be valid JSON+(hence the inner double quotes). The outer single quotes are shell+escaping so bash does not consume the doubles. That's why the+arguments look like `'"...".`+## 5. Verify```bashdiff --git a/install/opencode.md b/install/opencode.mdindex 192356b3..0f8a41ad 100644--- a/install/opencode.md+++ b/install/opencode.md@@ -26,7 +26,12 @@ o2b uninstall --target opencode --apply## Notes-- Confirm the upstream `sst/opencode` MCP config path against the- current docs before adopting on a new release. The adapter- defaults to `~/.config/opencode/mcp.json` but reads- `XDG_CONFIG_HOME` when set.+- Upstream is `anomalyco/opencode` (formerly hosted under+ `sst/opencode`). Confirm the MCP config path against the current+ upstream docs before adopting on a new release β the project has+ moved its config layout between releases. The adapter defaults to+ `~/.config/opencode/mcp.json` and reads `XDG_CONFIG_HOME` when+ set; if upstream renames the file (e.g. to `opencode.json`),+ the JSON-merge adapter pattern keeps working β only the+ resolver function in `src/core/install/adapters/opencode.ts`+ needs an update.diff --git a/src/cli/install/init-interactive.ts b/src/cli/install/init-interactive.tsindex 9c8c8f28..f575a03e 100644--- a/src/cli/install/init-interactive.ts+++ b/src/cli/install/init-interactive.ts@@ -260,7 +260,11 @@ export async function runWizard(opts: WizardOpts): Promise<WizardResult> {opts.stdout.write("\nPlanned commands:\n");for (const c of actions) opts.stdout.write(` o2b ${c.join(" ")}\n`);if (lang && lang !== "en") {- opts.stdout.write(` (language preference \`${lang}\` will be recorded after init)\n`);+ opts.stdout.write(+ ` (language preference \`${lang}\` is not yet persisted; record it ` ++ `manually with \`o2b brain feedback --principle "respond in ${lang}" ` ++ `--signal positive --topic user-language --force-confirmed\` after init)\n`,+ );}opts.stdout.write("\n");const confirm = (await ask(opts, "Run these commands now? (yes/no)", "no")).toLowerCase();diff --git a/src/cli/main.ts b/src/cli/main.tsindex f13ee919..ad6ee18b 100644--- a/src/cli/main.ts+++ b/src/cli/main.ts@@ -454,9 +454,10 @@ async function cmdInstallCli(argv: string[]): Promise<number> {}async function cmdUninstall(argv: string[]): Promise<number> {- // `--target X` is its own mode β per-runtime uninstall, distinct from the- // legacy `--apply-local` config-removal path.- if (argv.includes("--target")) {+ // `--target X` (and the `--target=X` form) is its own mode β+ // per-runtime uninstall, distinct from the legacy `--apply-local`+ // config-removal path.+ if (argv.some((a) => a === "--target" || a.startsWith("--target="))) {return await cmdUninstallTarget(argv);}const { flags } = parseFlags(argv, {@@ -529,7 +530,8 @@ Commands:index Regenerate the vault index from discovered pagesmcp Run the optional MCP tool server (stdio JSON-RPC)install-cli Create symlinks for o2b and vault-log in ~/.local/bin- uninstall Print an uninstall plan and (optionally) clean local config and CLI symlinks+ install Multi-runtime install orchestrator (v0.10.11) β detect / plan / apply / --check (see install/)+ uninstall Print an uninstall plan; --target X removes a per-runtime installtool-call Invoke an MCP tool handler from the CLI and print JSON to stdoutPay Memory:diff --git a/src/core/brain/active.ts b/src/core/brain/active.tsindex 55b165ac..11260f1b 100644--- a/src/core/brain/active.ts+++ b/src/core/brain/active.ts@@ -298,7 +298,11 @@ function renderMostAppliedLine(m: MostAppliedEntry): string {const p = m.preference;const tags: string[] = [];if (p.scope) tags.push(`scope: ${p.scope}`);- tags.push(`applied_30d: ${m.applied_30d}`);+ // Display label is window-agnostic; the actual window length is in the+ // `## Most-applied (Nd)` section header. The struct field+ // (`MostAppliedEntry.applied_30d`) keeps its v0.10.10 name so internal+ // consumers (MCP counts, e2e tests) don't break.+ tags.push(`applied_in_window: ${m.applied_30d}`);return `- \`${p.id}\` (${tags.join(", ")}) β ${p.principle}`;}diff --git a/src/core/install/adapters/aider.ts b/src/core/install/adapters/aider.tsindex 677d83a3..adf36a8f 100644--- a/src/core/install/adapters/aider.ts+++ b/src/core/install/adapters/aider.ts@@ -232,8 +232,11 @@ export const aiderAdapter: InstallAdapter = {},uninstall(env: InstallEnv, opts: ApplyOpts & { fromSnippet?: boolean }): UninstallResult {- const conf = resolveConfPath(env);const stored = readManifest(env.vault).installs[TARGET];+ // Prefer the config path recorded at install time. `AIDER_CONFIG`+ // or `cwd` can change between install and uninstall, and+ // `resolveConfPath(env)` would then return a different file.+ const conf = stored?.config_path ?? resolveConfPath(env);const skipped: Array<readonly [string, string]> = [];const removed_paths: string[] = [];@@ -284,7 +287,7 @@ export const aiderAdapter: InstallAdapter = {fix_hint: null,};}- const conf = resolveConfPath(env);+ const conf = stored.config_path ?? resolveConfPath(env);if (!existsSync(conf)) {return {target: TARGET,diff --git a/src/core/install/adapters/copilot-cli.ts b/src/core/install/adapters/copilot-cli.tsindex 819a621f..38146791 100644--- a/src/core/install/adapters/copilot-cli.ts+++ b/src/core/install/adapters/copilot-cli.ts@@ -183,8 +183,15 @@ function uninstallViaCli(): { removed: string[] } {return { removed };}-function uninstallViaFile(env: InstallEnv, dryRun: boolean): { path: string; touched: boolean } {- const path = fallbackPath(env);+function uninstallViaFile(+ env: InstallEnv,+ dryRun: boolean,+ storedPath?: string | null,+): { path: string; touched: boolean } {+ // Prefer the path recorded at install time; only fall back to env-derived+ // resolution when the manifest entry didn't carry one. This keeps+ // uninstall deterministic across XDG_CONFIG_HOME / HOME changes.+ const path = storedPath ?? fallbackPath(env);if (!existsSync(path)) return { path, touched: false };const current = readFileSync(path, "utf8");const next = removeMcpServers(current);@@ -237,6 +244,14 @@ export const copilotCliAdapter: InstallAdapter = {notes: ["file-fallback: both OSB keys present"],};}+ if (has(OSB_KEY_FULL) || has(OSB_KEY_WRITER)) {+ return {+ target: TARGET,+ status: "drift",+ configPath: fb,+ notes: ["file-fallback: partial OSB keys"],+ };+ }} catch {// parse error β driftreturn { target: TARGET, status: "drift", configPath: fb, notes: ["fallback file not valid JSON"] };@@ -333,10 +348,20 @@ export const copilotCliAdapter: InstallAdapter = {const viaCli = stored?.operation === "subprocess";if (viaCli) {- const { removed } = uninstallViaCli();- for (const r of removed) removed_keys.push(r);+ if (opts.dryRun) {+ // Dry-run must not touch the runtime's MCP registry. Simulate+ // the two removals so the operator sees what would happen.+ removed_keys.push(OSB_KEY_FULL, OSB_KEY_WRITER);+ } else {+ const { removed } = uninstallViaCli();+ for (const r of removed) removed_keys.push(r);+ }} else {- const { path, touched } = uninstallViaFile(env, opts.dryRun);+ const { path, touched } = uninstallViaFile(+ env,+ opts.dryRun,+ stored?.fallback_file ?? stored?.config_path ?? null,+ );if (touched) {removed_keys.push(`mcpServers.${OSB_KEY_FULL}`, `mcpServers.${OSB_KEY_WRITER}`);} else {diff --git a/src/core/install/adapters/generic.ts b/src/core/install/adapters/generic.tsindex 5f611446..9d88f5ab 100644--- a/src/core/install/adapters/generic.ts+++ b/src/core/install/adapters/generic.ts@@ -140,7 +140,7 @@ export const genericAdapter: InstallAdapter = {return { target: TARGET, manifest, steps_executed: opts.dryRun ? 0 : 1 };},- uninstall(env: InstallEnv, _opts: ApplyOpts & { fromSnippet?: boolean }): UninstallResult {+ uninstall(env: InstallEnv, opts: ApplyOpts & { fromSnippet?: boolean }): UninstallResult {const m = readManifest(env.vault).installs[TARGET];const skipped: Array<readonly [string, string]> = [];if (m?.owned_paths?.length) {@@ -153,7 +153,7 @@ export const genericAdapter: InstallAdapter = {"generic: never wrote to disk; nothing to do",]);}- removeEntry(env.vault, TARGET);+ if (!opts.dryRun) removeEntry(env.vault, TARGET);return { target: TARGET, removed_keys: [], removed_paths: [], skipped };},diff --git a/src/core/install/adapters/opencode.ts b/src/core/install/adapters/opencode.tsindex 89a38caa..1257812a 100644--- a/src/core/install/adapters/opencode.ts+++ b/src/core/install/adapters/opencode.ts@@ -1,9 +1,11 @@/*** opencode adapter β JSON-merge into `~/.config/opencode/mcp.json`.*- * Per upstream `sst/opencode` MCP docs the file lives under+ * Upstream is `anomalyco/opencode` (formerly hosted under+ * `sst/opencode`). The MCP config file lives under* `${XDG_CONFIG_HOME:-$HOME/.config}/opencode/mcp.json` and uses the- * standard `mcpServers` key.+ * standard `mcpServers` key. Re-verify against upstream docs if a+ * new opencode release ships before the next OSB release.*/import { join } from "node:path";diff --git a/src/core/install/adapters/pi.ts b/src/core/install/adapters/pi.tsindex bbcc3da0..31b98c86 100644--- a/src/core/install/adapters/pi.ts+++ b/src/core/install/adapters/pi.ts@@ -146,14 +146,16 @@ export const piAdapter: InstallAdapter = {const stat = lstatOrNull(target);if (stat) {if (stat.isSymbolicLink()) {- const current = readlinkSync(target);- if (current === source) {- // Already the canonical link.+ // Resolve the link target relative to the symlink's directory so+ // `current === source` holds for both absolute and relative link+ // targets (e.g. `../../skills/brain-memory`).+ const current = resolve(dirname(target), readlinkSync(target));+ const canonicalSource = resolve(source);+ if (current === canonicalSource) {const manifest = buildManifest(env, target);if (!opts.dryRun) recordEntry(env.vault, manifest);return { target: TARGET, manifest, steps_executed: 0 };}- // Different link target β replace.if (!opts.dryRun) rmSync(target, { force: true });} else {if (!opts.force) {@@ -231,19 +233,20 @@ export const piAdapter: InstallAdapter = {fix_hint: "o2b install --target pi --apply",};}- const target = readlinkSync(path);- if (!existsSync(target)) {+ const linkTarget = readlinkSync(path);+ const resolvedTarget = resolve(dirname(path), linkTarget);+ if (!existsSync(resolvedTarget)) {return {target: TARGET,status: "drift",- details: [`${path} β ${target} (target missing)`],+ details: [`${path} β ${linkTarget} (target missing)`],fix_hint: "o2b install --target pi --apply",};}return {target: TARGET,status: "ok",- details: [`${path} β ${target}`],+ details: [`${path} β ${linkTarget}`],fix_hint: null,};},diff --git a/tests/cli/init-interactive.test.ts b/tests/cli/init-interactive.test.tsindex 86318035..a5282c75 100644--- a/tests/cli/init-interactive.test.ts+++ b/tests/cli/init-interactive.test.ts@@ -99,6 +99,19 @@ describe("init wizard", () => {expect(initCall).toContain("UTC");// Final call must be `o2b install --check`expect(calls[calls.length - 1]).toEqual(["install", "--check"]);+ // At least one pre-check call must be a per-target install with --apply.+ // The scripted answer "1,2" selects targets 1 and 2 in the detected list;+ // both should yield `o2b install --target <name> --apply` invocations.+ const perTargetApplies = calls+ .slice(0, -1)+ .filter((c) => c[0] === "install" && c.includes("--apply") && c.includes("--target"));+ expect(perTargetApplies.length).toBe(2);+ for (const c of perTargetApplies) {+ const tIdx = c.indexOf("--target");+ // --target must be followed by a non-flag target name+ expect(c[tIdx + 1]).toBeDefined();+ expect((c[tIdx + 1] ?? "").startsWith("--")).toBe(false);+ }});test("'no' at confirmation runs nothing", async () => {diff --git a/tests/core/brain.active.test.ts b/tests/core/brain.active.test.tsindex f1f2249a..5e42dbb3 100644--- a/tests/core/brain.active.test.ts+++ b/tests/core/brain.active.test.ts@@ -244,14 +244,14 @@ describe("regenerateActive β Most-applied (30d) section", () => {expect(result.counts.most_applied_30d).toBe(0);});- test("renders the section and includes scope + applied_30d count", () => {+ test("renders the section and includes scope + window-agnostic applied count", () => {seedConfirmed("a", "Rule A", "medium");seedAppliedEvidence("pref-a", "2026-05-15T10:00:00Z");seedAppliedEvidence("pref-a", "2026-05-16T10:00:00Z");const result = regenerateActive(vault, { now: new Date("2026-05-20T00:00:00Z") });const body = readActive();expect(body).toContain("## Most-applied (30d) (1)");- expect(body).toContain("`pref-a` (scope: writing, applied_30d: 2)");+ expect(body).toContain("`pref-a` (scope: writing, applied_in_window: 2)");expect(body).toContain("Rule A");expect(result.counts.most_applied_30d).toBe(1);});diff --git a/tests/core/install/adapters/pi.test.ts b/tests/core/install/adapters/pi.test.tsindex 1404df2f..0c7cd7b4 100644--- a/tests/core/install/adapters/pi.test.ts+++ b/tests/core/install/adapters/pi.test.ts@@ -81,8 +81,14 @@ describe("pi adapter", () => {test("re-apply replaces broken symlink (target removed)", () => {piAdapter.apply(piAdapter.plan(payload, env()), payload, env(), applyOpts());- // Remove the source β symlink is now dangling+ // Remove the source so the existing symlink is genuinely dangling+ // when we re-apply. The adapter must restore the link target after+ // recreating the source.rmSync(skillSource, { recursive: true, force: true });+ // Confirm the link is now broken (symlink present, target gone).+ expect(existsSync(linkPath())).toBe(false);+ expect(readlinkSync(linkPath())).toBe(skillSource);+ // Recreate the source and re-apply.mkdirSync(skillSource, { recursive: true });writeFileSync(join(skillSource, "SKILL.md"), "# new\n");piAdapter.apply(piAdapter.plan(payload, env()), payload, env(), applyOpts());