Spaces:
Paused
Paused
Download server/src/services/instinctService.ts from qf46578/my-openclaw-backup: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/qf46578/my-openclaw-backup/resolve/main/server/src/services/instinctService.ts
- Command line
-
hf download hf://spaces/qf46578/my-openclaw-backup/server/src/services/instinctService.ts
-
curl -L -o instinctService.ts https://huggingface.co/spaces/qf46578/my-openclaw-backup/resolve/main/server/src/services/instinctService.ts
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' | |
| }; | |
| } | |
| } | |