
开场:系统设计的最高考验现实很残酷:没有什么系统永远可用。SQLite 可能失败的方式有很多:❌ 磁盘满了 → 无法写索引 ❌ 权限拒绝 → 无法创建 .loopagent 目录 ❌ 文件锁冲突 → 5 秒超时 ❌ Writer 太慢 → Reader 等待中... ❌ 数据库损坏 → 打开时 SQLITE_CORRUPT ❌ 内存不足 → SQLite 查询失败 ❌ 启动竞速条件 → 索引还在构建中其中任何一个,都会让搜索功能彻底瘫痪。但 LoopAgent 不会。为什么?因为它有七层防守。最后一层是什么?永远有一个兜底方案:内存搜索。七道降级检查asyncbuildCodeIntelligencePrompt(query:string):PromiseResult[]{// 第 1 检查:有工作区吗?if(!this.workspace||this.workspace.folders.length===0){console.log('No workspace folders');return[];// 无法搜(没有文件),也不用兜底}// 第 2 检查:我是 Writer 或 Reader?try{constrole=awaitthis.sqliteStore.getRole();if(!role.canRead){// 这个角色无法读 SQLitethrownewReadError('Role cannot read SQLite');}}catch(e){console.log('Cannot determine role:',e);// 降级returnawaitthis.memoryIntelligence.search(query);}// 第 3 检查:SQLite 初始化成功吗?if(!this.sqliteStore.isInitialized()){console.log('SQLite not initialized');// 降级returnawaitthis.memoryIntelligence.search(query);}// 第 4 检查:SQLite 数据库文件存在吗?constdbPath=this.sqliteStore.getDatabasePath();