Skip to content

GBRAIN_HOME validator rejects all valid Windows paths #1019

@VGBenjamin

Description

@VGBenjamin

What happened?
On Windows, GBRAIN_HOME validation in src/core/config.ts (line 273) uses trimmed.startsWith('/') to check whether the path is absolute. This rejects every native Windows path format:

D:\DLW-FLUX → rejected: GBRAIN_HOME must be an absolute path; got: D:\DLW-FLUX
D:/DLW-FLUX → rejected: GBRAIN_HOME must be an absolute path; got: D:/DLW-FLUX
C:\Users\me\brain → rejected similarly

The only string that passes the check is MSYS/Git-Bash style (/d/DLW-FLUX), but it then triggers a second silent bug: join(trimmed, '.gbrain') on line 279 produces \d\DLW-FLUX.gbrain.gbrain — no drive letter, doubled .gbrain suffix. gbrain init reports Brain ready at \d\DLW-FLUX.gbrain.gbrain\brain.pglite followed by The system cannot find the path specified., and the actual file lands at D:\d\DLW-FLUX.gbrain.gbrain\brain.pglite (relative to cwd).
A third related friction: line 279 unconditionally appends .gbrain to whatever the user provides, so GBRAIN_HOME=D:/project/.gbrain creates D:/project/.gbrain/.gbrain/. This is not documented in the README — users naturally point the variable at the brain directory itself, not its parent.
Net effect: gbrain is unusable on Windows without local source patching. The MCP integration with VS Code / GitHub Copilot, which sets GBRAIN_HOME via mcp.json's env block, fails for every Windows user.
What did you expect?
GBRAIN_HOME=D:\my-project (or D:/my-project) should be accepted as a valid absolute path on Windows, and gbrain init should create D:\my-project.gbrain\brain.pglite.
Suggested fix in src/core/config.ts:
typescriptimport { join, isAbsolute } from 'node:path';

// ...

if (!isAbsolute(trimmed)) {
throw new Error(GBRAIN_HOME must be an absolute path; got: ${trimmed});
}
path.isAbsolute() from node:path correctly handles both POSIX (/foo/bar) and Windows (C:\foo, C:/foo, \server\share) absolute paths. This is a 1-line change.
Optional related improvement: document explicitly in the README that GBRAIN_HOME points to the parent directory of .gbrain, not to .gbrain itself — or alternatively, detect when the user already passed a path ending in .gbrain and don't double-append.
Steps to reproduce

On Windows, with gbrain installed locally via git clone + bun install + bun link.
In PowerShell: $env:GBRAIN_HOME = "D:/my-project" (or any valid Windows absolute path).
Run gbrain init.

Expected: brain initialized at D:\my-project.gbrain\brain.pglite.
Actual: GBRAIN_HOME must be an absolute path; got: D:/my-project.
Alternative reproduction with the MSYS-style workaround that triggers the silent path corruption:

$env:GBRAIN_HOME = "/d/my-project"
cd D:\my-project
gbrain init
Output reports Brain ready at \d\my-project.gbrain.gbrain\brain.pglite followed by The system cannot find the path specified.
Test-Path D:\my-project.gbrain\brain.pglite → False
Get-ChildItem D:\ -Recurse -Filter brain.pglite → file is actually at D:\d\my-project.gbrain.gbrain\brain.pglite.

Environment

gbrain version: gbrain 0.33.1.0
OS: Windows 11 (PowerShell 7.x, native — not WSL, not Git Bash)
Bun version: 1.3.14
Database: PGLite (local, default after gbrain init)

gbrain doctor --json output:
No brain configured. Run: gbrain init

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions