My-openclaw / server /src /services /instinctService.ts
qf46578's picture
fix: 注入 60秒强制超时防止 10 分钟死锁,清空过期 Perplexity 密钥
8a26730
Raw History Blame Contribute Delete
1.1 kB
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'
};
}
}