| 42 | const RESPECT_DETECTION = process.argv.includes('--respect-detection'); |
| 43 | |
| 44 | function loadGbrainOverride(): { detected: boolean } { |
| 45 | if (!RESPECT_DETECTION) return { detected: false }; |
| 46 | const stateDir = process.env.GSTACK_HOME || path.join(process.env.HOME || '', '.gstack'); |
| 47 | const detectionPath = path.join(stateDir, 'gbrain-detection.json'); |
| 48 | try { |
| 49 | const json = JSON.parse(fs.readFileSync(detectionPath, 'utf-8')) as { gbrain_local_status?: string }; |
| 50 | // "timeout" = slow-but-healthy engine (#1964) — same treatment as "ok", |
| 51 | // matching gstack-gbrain-detect --is-ok. |
| 52 | return { detected: json.gbrain_local_status === 'ok' || json.gbrain_local_status === 'timeout' }; |
| 53 | } catch { |
| 54 | return { detected: false }; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | const GBRAIN_OVERRIDE = loadGbrainOverride(); |
| 59 | |