(env?: NodeJS.ProcessEnv)
| 35 | * caller then searches unscoped (best-effort) rather than failing. |
| 36 | */ |
| 37 | export 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: |
no test coverage detected