( state: AttributionState, filePath: string, oldContent: string, newContent: string, _userModified: boolean, mtime: number = Date.now(), )
| 401 | * Called after Edit/Write tool completes. |
| 402 | */ |
| 403 | export function trackFileModification( |
| 404 | state: AttributionState, |
| 405 | filePath: string, |
| 406 | oldContent: string, |
| 407 | newContent: string, |
| 408 | _userModified: boolean, |
| 409 | mtime: number = Date.now(), |
| 410 | ): AttributionState { |
| 411 | const normalizedPath = normalizeFilePath(filePath) |
| 412 | const newFileState = computeFileModificationState( |
| 413 | state.fileStates, |
| 414 | filePath, |
| 415 | oldContent, |
| 416 | newContent, |
| 417 | mtime, |
| 418 | ) |
| 419 | if (!newFileState) { |
| 420 | return state |
| 421 | } |
| 422 | |
| 423 | const newFileStates = new Map(state.fileStates) |
| 424 | newFileStates.set(normalizedPath, newFileState) |
| 425 | |
| 426 | logForDebugging( |
| 427 | `Attribution: Tracked ${newFileState.claudeContribution} chars for ${normalizedPath}`, |
| 428 | ) |
| 429 | |
| 430 | return { |
| 431 | ...state, |
| 432 | fileStates: newFileStates, |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * Track a file creation by Claude (e.g., via bash command). |
no test coverage detected