@@ -115,15 +115,10 @@ process_file_write() {
115115 create_trace_entry " Write" " $tool_input "
116116 fi
117117
118- # For file writes, attribute all lines in the file (since it's newly created/modified)
118+ # For file writes, only attribute the new content, not the entire file
119119 if [ " $ENABLE_ATTRIBUTION " = " true" ] && [ -f " $file_path " ] && [ -n " $content " ]; then
120- total_lines=$( wc -l < " $file_path " )
121- if [ " $total_lines " -gt 0 ]; then
122- log " info" " Attributing all $total_lines lines in new file $file_path "
123- for (( line= 1 ; line<= total_lines; line++ )) ; do
124- " $GIT_AGENTIC_CMD " attr " $file_path " " $line " ai --agent=" $CLAUDE_AGENT_ID " 2> /dev/null || true
125- done
126- fi
120+ # Only attribute lines that actually contain the new content
121+ find_new_content_lines " $file_path " " $content "
127122 fi
128123}
129124
@@ -211,18 +206,8 @@ find_new_content_lines() {
211206 fi
212207 done
213208 else
214- # Fallback: attribute last few lines if content matching fails
215- total_lines=$( wc -l < " $file_path " )
216- if [ " $total_lines " -gt 0 ]; then
217- lines_to_attribute=3 # Attribute last 3 lines as fallback
218- start_line=$(( total_lines - lines_to_attribute + 1 ))
219- [ " $start_line " -lt 1 ] && start_line=1
220-
221- log " debug" " Fallback: Attributing lines $start_line -$total_lines "
222- for (( line= start_line; line<= total_lines; line++ )) ; do
223- " $GIT_AGENTIC_CMD " attr " $file_path " " $line " ai --agent=" $CLAUDE_AGENT_ID " 2> /dev/null || true
224- done
225- fi
209+ # If content matching fails, don't attribute anything - be conservative
210+ log " debug" " Content matching failed for $file_path , not attributing any lines"
226211 fi
227212}
228213
0 commit comments