(line: string)
| 10 | * Returns a normalized Memory when the subject matches supported commit patterns. |
| 11 | */ |
| 12 | export function parseGitLogLineToMemory(line: string): Memory | null { |
| 13 | const tabIdx = line.indexOf('\t'); |
| 14 | if (tabIdx === -1) return null; |
| 15 | |
| 16 | const commitDateRaw = line.substring(0, tabIdx).trim(); |
| 17 | const hashAndSubject = line.substring(tabIdx + 1).trim(); |
| 18 | if (!commitDateRaw || !hashAndSubject) return null; |
| 19 | |
| 20 | const commitMs = Date.parse(commitDateRaw); |
| 21 | if (!Number.isFinite(commitMs)) return null; |
| 22 | |
| 23 | for (const pattern of GIT_COMMIT_PATTERNS) { |
| 24 | if (!pattern.prefix.test(hashAndSubject)) continue; |
| 25 | |
| 26 | const message = hashAndSubject.replace(/^[a-f0-9]+ /i, '').trim(); |
| 27 | if (message.length < MIN_COMMIT_MESSAGE_LENGTH) return null; |
| 28 | |
| 29 | const hashContent = `git:${pattern.type}:${pattern.category}:${message}`; |
| 30 | const id = createHash('sha256').update(hashContent).digest('hex').substring(0, 12); |
| 31 | |
| 32 | return { |
| 33 | id, |
| 34 | type: pattern.type, |
| 35 | category: pattern.category, |
| 36 | memory: message, |
| 37 | reason: 'Auto-extracted from git commit history', |
| 38 | date: new Date(commitMs).toISOString(), |
| 39 | source: 'git' |
| 40 | }; |
| 41 | } |
| 42 | |
| 43 | return null; |
| 44 | } |
| 45 | |
| 46 | export function parseGitLogToMemories(log: string): Memory[] { |
| 47 | if (!log.trim()) return []; |
no outgoing calls
no test coverage detected