forked from CodebuffAI/codebuff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze-edit-blocks.ts
More file actions
71 lines (59 loc) · 1.92 KB
/
Copy pathanalyze-edit-blocks.ts
File metadata and controls
71 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import fs from 'fs'
import path from 'path'
import { fileRegex } from '@codebuff/common/util/file'
import { db } from '@codebuff/internal/db'
import * as schema from '@codebuff/internal/db/schema'
import { eq, desc } from 'drizzle-orm'
import { shuffle } from 'lodash'
interface EditBlock {
filePath: string
content: string
}
async function analyzeEditBlocks() {
const messagesSorted = await db
.select({
response: schema.message.response,
})
.from(schema.message)
.where(eq(schema.message.model, 'claude-3-5-sonnet-20241022'))
.orderBy(desc(schema.message.finished_at))
.limit(10000)
const messages = shuffle(messagesSorted).slice(0, 1000)
const editBlocks: EditBlock[] = []
for (const message of messages) {
const response = (message.response as any).toString()
let match
// Reset regex state for each message
fileRegex.lastIndex = 0
while ((match = fileRegex.exec(response)) !== null) {
const [, filePath, content] = match
// Only include blocks that contain search/replace markers
if (content.includes('<<<<<<< SEARCH')) {
editBlocks.push({
filePath,
content: content.startsWith('\n') ? content.slice(1) : content,
})
}
}
}
// Write edit blocks to JSON file
const outputPath = path.join(__dirname, 'edit-blocks.json')
fs.writeFileSync(outputPath, JSON.stringify(editBlocks, null, 2))
console.log(`Found ${editBlocks.length} edit blocks`)
console.log('\nFiles modified:')
const fileFrequency = new Map<string, number>()
for (const block of editBlocks) {
fileFrequency.set(
block.filePath,
(fileFrequency.get(block.filePath) || 0) + 1,
)
}
// Sort by frequency
const sortedFiles = Array.from(fileFrequency.entries()).sort(
(a, b) => b[1] - a[1],
)
for (const [file, count] of sortedFiles) {
console.log(`${file}: ${count} edits`)
}
}
analyzeEditBlocks().catch(console.error)