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
fix(hermes): resolve o2b when memory provider PATH is tiny (v1.27.1) (#131)
Khang Nguyen5cd52e705328
diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.jsonindex 1cb7f5c4..a3d57f8b 100644--- a/.claude-plugin/plugin.json+++ b/.claude-plugin/plugin.json@@ -1,6 +1,6 @@{"name": "open-second-brain",- "version": "1.27.0",+ "version": "1.27.1","description": "Plugin-first second brain package for AI agents and humans.","author": {"name": "Open Second Brain contributors"diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.jsonindex 2a88fc97..4e0ed035 100644--- a/.codex-plugin/plugin.json+++ b/.codex-plugin/plugin.json@@ -1,6 +1,6 @@{"name": "open-second-brain",- "version": "1.27.0",+ "version": "1.27.1","description": "Plugin-first second brain package for Codex, Hermes, Claude Code, OpenClaw, and other agent runtimes.","skills": "./skills","hooks": "./hooks/hooks.json",diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e968d1e8..27d517cc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).+## [1.27.1] - 2026-07-10++A robustness fix for the Hermes memory provider's executable resolution. No kernel behavior changes.++### Fixed++- **Resolve `o2b`/`bun` when the memory provider inherits a tiny `PATH`.** When Hermes starts the provider from a process with a minimal inherited `PATH`, `shutil.which("o2b")` cannot see a user-local install and `subprocess.Popen` later fails with `No such file or directory: 'o2b'`. Resolution now falls back to a curated scan of user-local and system executable directories (`~/.local/bin`, `~/.bun/bin`, `~/.hermes/node/bin`, `/opt/homebrew/bin`, `/usr/local/bin`, `/usr/bin`, `/bin`) and uses the resolved absolute path for both `o2b` and `bun`. `shutil.which` still wins first, the POSIX-only `o2b` branch and the repo-local `bun run <entry> mcp` fallback are preserved, and on Windows the scan matches `PATHEXT` suffixes rather than gating on the POSIX execute bit.+## [1.27.0] - 2026-07-10An ingestion and import robustness layer that hardens and extends the source pipeline in one coherent scope: interrupted batches resume, more memory stores import, deterministic refresh skips when nothing changed, and sources distill into citeable claims. Every new surface is additive and off by default where it changes an existing path; the kernel still calls no LLM.@@ -6404,6 +6412,7 @@ plugin config (vault field)`, and exits with a clear- Sandbox vault and plugin manifest fixtures for tests.- GitHub release workflow for tag-based and manually dispatched releases.+[1.27.1]: https://github.com/itechmeat/open-second-brain/compare/v1.27.0...v1.27.1[1.27.0]: https://github.com/itechmeat/open-second-brain/compare/v1.26.1...v1.27.0[1.24.0]: https://github.com/itechmeat/open-second-brain/compare/v1.23.1...v1.24.0[1.23.1]: https://github.com/itechmeat/open-second-brain/compare/v1.23.0...v1.23.1diff --git a/openclaw.plugin.json b/openclaw.plugin.jsonindex 540519c0..32373d9f 100644--- a/openclaw.plugin.json+++ b/openclaw.plugin.json@@ -2,7 +2,7 @@"id": "open-second-brain","name": "Open Second Brain","description": "Second brain for AI agents using Obsidian-compatible Markdown vaults.",- "version": "1.27.0",+ "version": "1.27.1","activation": { "onStartup": true },"skills": ["./skills"],"contracts": {diff --git a/package.json b/package.jsonindex 7749f695..b369cc85 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "open-second-brain",- "version": "1.27.0",+ "version": "1.27.1","private": false,"description": "Second brain for AI agents using Obsidian-compatible Markdown vaults. Works with Hermes, Claude Code, Codex, and OpenClaw.","keywords": [diff --git a/plugin.yaml b/plugin.yamlindex a2811751..8bb3024d 100644--- a/plugin.yaml+++ b/plugin.yaml@@ -1,5 +1,5 @@name: open-second-brain-version: "1.27.0"+version: "1.27.1"description: "Open Second Brain - native Hermes memory provider backed by an Obsidian-compatible Markdown vault."author: "Open Second Brain contributors"memory_provider: truediff --git a/plugins/codex/.codex-plugin/plugin.json b/plugins/codex/.codex-plugin/plugin.jsonindex 114de668..937cb15d 100644--- a/plugins/codex/.codex-plugin/plugin.json+++ b/plugins/codex/.codex-plugin/plugin.json@@ -1,6 +1,6 @@{"name": "open-second-brain",- "version": "1.27.0",+ "version": "1.27.1","description": "Plugin-first second brain package for Codex, Hermes, Claude Code, OpenClaw, and other agent runtimes.","author": {"name": "Open Second Brain contributors",diff --git a/plugins/hermes/plugin.yaml b/plugins/hermes/plugin.yamlindex a2811751..8bb3024d 100644--- a/plugins/hermes/plugin.yaml+++ b/plugins/hermes/plugin.yaml@@ -1,5 +1,5 @@name: open-second-brain-version: "1.27.0"+version: "1.27.1"description: "Open Second Brain - native Hermes memory provider backed by an Obsidian-compatible Markdown vault."author: "Open Second Brain contributors"memory_provider: truediff --git a/plugins/hermes/provider.py b/plugins/hermes/provider.pyindex fc7dd6e6..5f828c13 100644--- a/plugins/hermes/provider.py+++ b/plugins/hermes/provider.py@@ -18,7 +18,10 @@ import reimport shutilimport threadingfrom pathlib import Path-from typing import Any+from typing import TYPE_CHECKING, Any++if TYPE_CHECKING:+ from collections.abc import Iterablefrom . import configfrom ._base import MemoryProvider@@ -52,6 +55,53 @@ _CONFIG_KEYS: tuple[str, ...] = ("vault", "agent_name", "timezone")_PREFETCH_MAX_TOKENS = 1024+def _fallback_exe_dirs() -> tuple[Path, ...]:+ """Directories scanned for an executable when a tiny inherited ``PATH``+ hides it from ``shutil.which``. Computed per call so it tracks the current+ ``$HOME`` (and stays patchable in tests)."""+ home = Path.home()+ return (+ home / ".local" / "bin",+ home / ".bun" / "bin",+ home / ".hermes" / "node" / "bin",+ Path("/opt/homebrew/bin"),+ Path("/usr/local/bin"),+ Path("/usr/bin"),+ Path("/bin"),+ )+++def _find_executable(name: str, search_dirs: Iterable[Path] | None = None) -> str | None:+ """Resolve ``name`` to an absolute executable path.++ ``shutil.which`` (which honours ``PATH``) wins when it can see the binary.+ Hermes can start the provider from a process with a minimal inherited+ ``PATH``; then ``which`` returns nothing even though the executable exists+ in a user-local bin, so fall back to scanning a curated directory set.++ On Windows the scan appends ``PATHEXT`` suffixes (``.EXE``/``.CMD``/...) to+ a bare name and does not gate on the POSIX execute bit, which has no meaning+ there; on POSIX it matches the exact name and requires ``X_OK``.+ """+ found = shutil.which(name)+ if found:+ return found+ dirs = tuple(search_dirs) if search_dirs is not None else _fallback_exe_dirs()+ if os.name == "nt" and not os.path.splitext(name)[1]:+ exts = [e for e in os.environ.get("PATHEXT", ".COM;.EXE;.BAT;.CMD").split(os.pathsep) if e]+ candidate_names = [name + ext for ext in exts]+ else:+ candidate_names = [name]+ for directory in dirs:+ for candidate_name in candidate_names:+ candidate = directory / candidate_name+ if not candidate.is_file():+ continue+ if os.name == "nt" or os.access(candidate, os.X_OK):+ return str(candidate)+ return None++class OpenSecondBrainMemoryProvider(MemoryProvider):"""Open Second Brain as a first-class Hermes memory provider."""@@ -111,33 +161,28 @@ class OpenSecondBrainMemoryProvider(MemoryProvider):def _resolve_command(cls) -> tuple[str, ...]:"""Determine the right argv prefix for the ``o2b mcp`` subprocess.- On POSIX, ``scripts/o2b`` is a bash wrapper that ``install-cli`` may- have symlinked into ``~/.local/bin``; ``shutil.which("o2b")`` finds it- and ``Popen`` can execute it directly.-- On Windows, bash scripts are not directly executable by- ``subprocess.Popen`` (it delegates to ``cmd.exe``, not a POSIX shell).- Even if ``o2b`` were on PATH, Popen would fail with ``[WinError 193]``- or ``[WinError 2]``. The correct cross-platform fallback is to invoke- the TypeScript entry point through ``bun run``, which works identically- on every OS.-- Resolution order:- 1. POSIX + ``o2b`` in PATH → ``("o2b", "mcp")``- 2. ``bun`` in PATH + repo root has ``src/cli/main.ts`` →- ``("bun", "run", "<entry>", "mcp")``- 3. Fallback → ``("o2b", "mcp")`` (will surface a clear Popen error)+ Hermes memory providers can run with a tiny inherited ``PATH``, so+ resolve absolute executable paths via :func:`_find_executable` (which+ scans user-local and system bins when ``PATH`` hides the binary) before+ falling back to a bare command name.++ On Windows the ``scripts/o2b`` bash wrapper is not directly executable+ by ``subprocess.Popen``, so the o2b branch is POSIX-only; the+ cross-platform path is the repo-local TypeScript entry point via+ ``bun run``."""- # On non-Windows, a globally installed o2b works out of the box.- if os.name != "nt" and shutil.which("o2b"):- return ("o2b", "mcp")+ # On non-Windows, a globally installed or user-local o2b works directly.+ if os.name != "nt":+ o2b = _find_executable("o2b")+ if o2b:+ return (o2b, "mcp")- # Resolve via the repo-local TypeScript entry point + bun.+ # Resolve via repo-local TypeScript entry point + bun.root = cls._repo_root()if root:entry = Path(root) / "src" / "cli" / "main.ts"if entry.is_file():- bun = shutil.which("bun")+ bun = _find_executable("bun")if bun:return (bun, "run", str(entry), "mcp")diff --git a/pyproject.toml b/pyproject.tomlindex 1b2d285f..3640923c 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"# CLI entry points (those moved to `package.json` `bin`).[project]name = "open-second-brain"-version = "1.27.0"+version = "1.27.1"description = "Hermes Python shim for Open Second Brain. Most of the project (CLI, MCP server, OpenClaw plugin) is TypeScript on Bun; see package.json."readme = "README.md"requires-python = ">=3.11"diff --git a/tests/python/test_memory_provider.py b/tests/python/test_memory_provider.pyindex d81fc890..d4b41922 100644--- a/tests/python/test_memory_provider.py+++ b/tests/python/test_memory_provider.py@@ -14,6 +14,7 @@ import sysimport tempfileimport unittestfrom pathlib import Path+from unittest.mock import patchROOT = Path(__file__).resolve().parents[2]if str(ROOT) not in sys.path:@@ -35,6 +36,7 @@ from plugins.hermes.bridge import ( # noqa: E402from plugins.hermes.provider import ( # noqa: E402MEMORY_TOOLS,OpenSecondBrainMemoryProvider,+ _find_executable,)from plugins.hermes.cli import register_cli # noqa: E402@@ -342,6 +344,55 @@ class ProviderStaticSchemaFallbackTests(unittest.TestCase):self.assertEqual(json.loads(result), {"ok": True})self.assertEqual(bridge.calls, [("brain_note", {"text": "hi"})])+ @unittest.skipIf(os.name == "nt", "o2b bash wrapper is POSIX-only")+ def test_resolve_command_uses_user_local_o2b_when_path_is_tiny(self):+ # A tiny inherited PATH hides o2b from shutil.which; the fallback scan+ # must still find a real user-local o2b. Hermetic: a fake ~/.local/bin+ # under a temp HOME, so the assertion never depends on what the test+ # machine happens to have installed.+ with tempfile.TemporaryDirectory() as home:+ local_bin = Path(home) / ".local" / "bin"+ local_bin.mkdir(parents=True)+ fake_o2b = local_bin / "o2b"+ fake_o2b.write_text("#!/bin/sh\n")+ os.chmod(fake_o2b, 0o755)++ with (+ patch.dict(os.environ, {"PATH": ""}),+ patch.object(Path, "home", return_value=Path(home)),+ patch("shutil.which", return_value=None),+ ):+ command = OpenSecondBrainMemoryProvider._resolve_command()++ self.assertEqual(command, (str(fake_o2b), "mcp"))+ self.assertTrue(Path(command[0]).is_absolute())++ def test_find_executable_prefers_which(self):+ with patch("shutil.which", return_value="/somewhere/on/path/o2b"):+ self.assertEqual(_find_executable("o2b"), "/somewhere/on/path/o2b")++ def test_find_executable_returns_none_when_nothing_resolves(self):+ with tempfile.TemporaryDirectory() as empty, patch("shutil.which", return_value=None):+ self.assertIsNone(_find_executable("o2b", search_dirs=[Path(empty)]))++ def test_find_executable_matches_windows_pathext_suffix(self):+ # On Windows a bare `bun` never matches on disk; the scan must try the+ # PATHEXT suffixes (bun.CMD / bun.EXE). Execute-bit gating is a POSIX+ # concept and must be skipped there. Build the Path objects before+ # patching os.name, since pathlib picks its flavour at instantiation.+ with tempfile.TemporaryDirectory() as bindir:+ bindir_path = Path(bindir)+ shim = bindir_path / "bun.CMD"+ shim.write_text("@echo off\n")+ with (+ patch("os.name", "nt"),+ patch("os.pathsep", ";"),+ patch.dict(os.environ, {"PATHEXT": ".COM;.EXE;.BAT;.CMD"}),+ patch("shutil.which", return_value=None),+ ):+ resolved = _find_executable("bun", search_dirs=[bindir_path])+ self.assertEqual(resolved, str(shim))+class CliTests(unittest.TestCase):_ENV_KEYS = ("VAULT_AGENT_NAME", "VAULT_DIR", "OPEN_SECOND_BRAIN_CONFIG")