-
Notifications
You must be signed in to change notification settings - Fork 16
CLI ignores local .agent-brain/ and falls back to git top-level — breaks mono-repos #124
Description
When running Agent Brain CLI commands (query, status, folders, index, etc.) from inside a project subdirectory that has its own .agent-brain/ folder, the CLI ignores it and walks up to the git top-level to discover the server. This causes it to connect to the wrong server or fail entirely.
Steps to reproduce
mono-repo/ ← git root (no .agent-brain here)
projects/
my-app/
.agent-brain/ ← server running here on port 8002
src/
Running from mono-repo/projects/my-app/:
agent-brain status # ERROR: No Agent Brain state found for: /mono-repo
agent-brain query "..." # connects to wrong server or fails
Expected behavior
If a .agent-brain/ directory exists in the current directory (or any parent before the git root), the CLI should use that — not continue walking to the git top-level.
Suggested fix
Before resolving via git root, check for a local .agent-brain/runtime.json by walking up from CWD, stopping at the first match:
def find_project_root(cwd):
path = Path(cwd)
for parent in [path, *path.parents]:
if (parent / ".agent-brain" / "runtime.json").exists():
return parent # local .agent-brain wins
if (parent / ".git").exists():
break # stop at git root, don't go further
return None
Impact
This particularly affects mono-repos with projects in subfolders — a common setup where each sub-project has its own Agent Brain instance on a different port. The git-root fallback consistently resolves to the wrong location, requiring users to always pass --url manually as a workaround.
Workaround
Pass --url explicitly to every CLI command using the URL from runtime.json with special instructions for AI agent when to use that approach (only when git top-level is mono-repo with subprojects).