MCPcopy
hub / github.com/garrytan/gstack / buildGbrainEnv

Function buildGbrainEnv

lib/gbrain-exec.ts:96–125  ·  view source on GitHub ↗
(opts: BuildGbrainEnvOptions = {})

Source from the content-addressed store, hash-verified

94 * object identity.
95 */
96export function buildGbrainEnv(opts: BuildGbrainEnvOptions = {}): NodeJS.ProcessEnv {
97 const baseEnv = opts.baseEnv || process.env;
98 const out: NodeJS.ProcessEnv = { ...baseEnv };
99 if (baseEnv.GSTACK_RESPECT_ENV_DATABASE_URL === "1") return out;
100
101 const homeBase = baseEnv.HOME || homedir();
102 const gbrainHome = baseEnv.GBRAIN_HOME || join(homeBase, ".gbrain");
103 const configPath = join(gbrainHome, "config.json");
104 if (!existsSync(configPath)) return out;
105
106 let cfg: GbrainConfig = {};
107 try {
108 cfg = JSON.parse(readFileSync(configPath, "utf-8")) as GbrainConfig;
109 } catch {
110 return out;
111 }
112 if (!cfg.database_url) return out;
113
114 const hadCaller = baseEnv.DATABASE_URL !== undefined;
115 const alreadyMatch = baseEnv.DATABASE_URL === cfg.database_url;
116 if (!alreadyMatch) {
117 out.DATABASE_URL = cfg.database_url;
118 if (opts.announce) {
119 const note = hadCaller ? " (overrode value from caller env / .env.local)" : "";
120 process.stderr.write(`[gbrain-exec] seeded DATABASE_URL from ${configPath}${note}\n`);
121 }
122 }
123
124 return out;
125}
126
127/**
128 * Windows can't directly spawn the `gbrain` launcher (bun/npm install it as a

Callers 7

freshClassifyFunction · 0.90
runCodeImportFunction · 0.90
runMemoryIngestFunction · 0.90
spawnGbrainFunction · 0.85
spawnGbrainAsyncFunction · 0.85
execGbrainTextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected