Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/gbrain-local-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from "fs";
import { homedir } from "os";
import { dirname, join } from "path";
import { buildGbrainEnv } from "./gbrain-exec";

export type LocalEngineStatus =
| "ok"
Expand Down Expand Up @@ -220,12 +221,20 @@ function freshClassify(env?: NodeJS.ProcessEnv): LocalEngineStatus {
if (!existsSync(gbrainConfigPath())) return "missing-config";

// 3. Probe gbrain sources list.
//
// Seed DATABASE_URL from ~/.gbrain/config.json (via buildGbrainEnv, the
// same helper the sync orchestrator uses in lib/gbrain-exec.ts). Without
// this, Bun autoloads a project's .env when the probe runs inside a repo
// that defines its own DATABASE_URL (e.g. an app DB on a different port),
// gbrain connects to the wrong DB, and the classifier falsely reports
// broken-db. This also makes the result cwd-independent, so the 60s cache
// can no longer propagate a poisoned negative to clean directories.
try {
execFileSync("gbrain", ["sources", "list", "--json"], {
encoding: "utf-8",
timeout: PROBE_TIMEOUT_MS,
stdio: ["ignore", "pipe", "pipe"],
env: env ?? process.env,
env: buildGbrainEnv({ baseEnv: env ?? process.env }),
});
return "ok";
} catch (err) {
Expand Down