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

Function resolveMemorySourceId

lib/gstack-decision-semantic.ts:37–51  ·  view source on GitHub ↗
(env?: NodeJS.ProcessEnv)

Source from the content-addressed store, hash-verified

35 * caller then searches unscoped (best-effort) rather than failing.
36 */
37export function resolveMemorySourceId(env?: NodeJS.ProcessEnv): string | null {
38 const r = spawnGbrain(["sources", "list", "--json"], { baseEnv: env, timeout: TIMEOUT_MS });
39 if (r.status !== 0) return null;
40 let rows;
41 try {
42 rows = parseSourcesList(JSON.parse(r.stdout || "null"));
43 } catch {
44 return null;
45 }
46 const atWorktree = rows.filter(
47 (s) => typeof s.local_path === "string" && s.local_path.endsWith(BRAIN_WORKTREE_SUFFIX),
48 );
49 const pick = atWorktree.find((s) => s.id === "default") ?? atWorktree[0];
50 return pick?.id ?? null;
51}
52
53/**
54 * Parse gbrain search's text output into scored hits. Lines look like:

Callers 2

semanticRecallFunction · 0.85

Calls 2

spawnGbrainFunction · 0.90
parseSourcesListFunction · 0.90

Tested by

no test coverage detected