import fs from 'fs'; import path from 'path'; export class InstinctService { private logPath = '/root/.openclaw/workspace/memory/user_edit_history.jsonl'; public async observe(filePath: string, diff: string, command: string) { const record = { timestamp: new Date().toISOString(), filePath, diff, command, style: this.extractStyle(diff) }; if (!fs.existsSync(path.dirname(this.logPath))) { fs.mkdirSync(path.dirname(this.logPath), { recursive: true }); } fs.appendFileSync(this.logPath, JSON.stringify(record) + '\n'); console.log(`🦞 [Instinct-Learn] 记录到主人的编码习惯: ${record.style}`); } private extractStyle(diff: string) { if (diff.includes(' ')) return 'Space-Indent-Focused'; if (diff.includes('\t')) return 'Tab-Indent-Focused'; if (diff.includes('try {')) return 'Safety-Conscious'; return 'Minimalist'; } public async suggestNewRule() { return { rule: 'Owner-Style: Always include return types in TS', confidence: 0.85, action: 'Shadow-Execute' }; } }