()
| 220 | * tracing. |
| 221 | */ |
| 222 | export function detectEngineTier(): EngineDetect { |
| 223 | // Try cache first |
| 224 | if (existsSync(engineCachePath())) { |
| 225 | try { |
| 226 | const stat = statSync(engineCachePath()); |
| 227 | const ageMs = Date.now() - stat.mtimeMs; |
| 228 | if (ageMs < ENGINE_CACHE_TTL_MS) { |
| 229 | const cached = JSON.parse(readFileSync(engineCachePath(), "utf-8")) as EngineDetect; |
| 230 | if (cached.schema_version === 1) return cached; |
| 231 | } |
| 232 | } catch { |
| 233 | // Cache corrupt; fall through to fresh detect. |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | const fresh = freshDetectEngineTier(); |
| 238 | try { |
| 239 | mkdirSync(dirname(engineCachePath()), { recursive: true }); |
| 240 | writeFileSync( |
| 241 | engineCachePath(), |
| 242 | JSON.stringify({ ...fresh, last_writer: "gstack-memory-helpers.detectEngineTier" }, null, 2), |
| 243 | "utf-8" |
| 244 | ); |
| 245 | } catch { |
| 246 | // Cache write failure is non-fatal. |
| 247 | } |
| 248 | return fresh; |
| 249 | } |
| 250 | |
| 251 | // Returns gbrain's config.json path, honoring GBRAIN_HOME env var with a |
| 252 | // fallback to ~/.gbrain. gbrain >=0.25 dropped the top-level `engine` field |
no test coverage detected