Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/services/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,21 +995,20 @@ impl ContextBuilder {
continue;
}
// Detect added/removed import lines
if (line.starts_with('+') && Self::is_import_line(&line[1..]))
|| (line.starts_with('-') && Self::is_import_line(&line[1..]))
{
let action = if line.starts_with('+') {
"added"
} else {
"removed"
};
let (action, content) = if let Some(rest) = line.strip_prefix('+') {
("added", rest)
} else if let Some(rest) = line.strip_prefix('-') {
("removed", rest)
} else {
continue;
};
if Self::is_import_line(content) {
let stem = file
.path
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("?");
let content = line[1..].trim();
imports.push(format!("{}: {} {}", stem, action, content));
imports.push(format!("{}: {} {}", stem, action, content.trim()));
}
}
}
Expand Down Expand Up @@ -1067,11 +1066,13 @@ impl ContextBuilder {
let filename = file.path.file_name().and_then(|n| n.to_str()).unwrap_or("");

for line in file.diff.lines() {
if !line.starts_with('+') || line.starts_with("+++") {
if line.starts_with("+++") {
continue;
}
let Some(content) = line.strip_prefix('+') else {
continue;
};
Comment on lines +1069 to +1074
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line.starts_with("+++") skip here can drop legitimate added hunk lines whose content begins with "++" (diff line starts with "+++"), which would undercount total_added and bias intent detection. Consider tracking whether the loop is inside a hunk (after @@) and only skipping +++ headers outside hunks (or otherwise using more stateful header detection).

Copilot uses AI. Check for mistakes.
total_added += 1;
let content = &line[1..];
let trimmed = content.trim();

// Error handling patterns
Expand Down Expand Up @@ -1207,13 +1208,17 @@ impl ContextBuilder {
let name = file.path.file_name().and_then(|n| n.to_str()).unwrap_or("");

for line in file.diff.lines() {
let is_removed = line.starts_with('-') && !line.starts_with("---");
let is_added = line.starts_with('+') && !line.starts_with("+++");
let content = if is_removed || is_added {
&line[1..]
if line.starts_with("+++") || line.starts_with("---") {
continue;
}
let (is_added, content) = if let Some(rest) = line.strip_prefix('+') {
(true, rest)
} else if let Some(rest) = line.strip_prefix('-') {
(false, rest)
Comment on lines +1211 to +1217
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as other diff scans: line.starts_with("+++") || line.starts_with("---") will also skip real added/removed hunk lines whose content begins with "++"/"--" (making the diff line start with "+++"/"---"). Consider tracking in_hunk via @@ and only treating +++/--- as headers outside hunks so metadata breaking-change signals aren't missed.

Copilot uses AI. Check for mistakes.
} else {
continue;
};
let is_removed = !is_added;

match name {
"Cargo.toml" => {
Expand Down
5 changes: 3 additions & 2 deletions src/services/safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,9 @@ pub fn scan_full_diff_with_patterns(
}

// Only check added lines
if line.starts_with('+') && !line.starts_with("+++") {
let content = &line[1..];
if !line.starts_with("+++")
&& let Some(content) = line.strip_prefix('+')
{
Comment on lines +317 to +319
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In scan_full_diff_with_patterns, current_line is only Some after parsing an @@ ... @@ hunk header, so diff file headers should already be out of the way. The extra !line.starts_with("+++") guard can cause false negatives by skipping real added lines whose content begins with "++" (diff line starts with "+++"). Consider removing this guard (or making header skipping stateful) and relying on strip_prefix('+') to identify added lines within hunks.

Suggested change
if !line.starts_with("+++")
&& let Some(content) = line.strip_prefix('+')
{
if let Some(content) = line.strip_prefix('+') {

Copilot uses AI. Check for mistakes.
for pat in patterns {
if pat.regex.is_match(content) {
found.push(SecretMatch {
Expand Down
8 changes: 4 additions & 4 deletions src/services/splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ impl CommitSplitter {
let mut indent_only_changes = 0usize;
let added_lines: Vec<&str> = lines
.iter()
.filter(|l| l.starts_with('+') && !l.starts_with("+++"))
.map(|l| &l[1..])
.filter(|l| !l.starts_with("+++"))
.filter_map(|l| l.strip_prefix('+'))
.collect();
let removed_lines: Vec<&str> = lines
.iter()
.filter(|l| l.starts_with('-') && !l.starts_with("---"))
.map(|l| &l[1..])
.filter(|l| !l.starts_with("---"))
.filter_map(|l| l.strip_prefix('-'))
Comment on lines 199 to +206
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The !l.starts_with("+++") / !l.starts_with("---") header filtering is overly broad: it will also exclude legitimate added/removed hunk lines whose content begins with ++/-- (e.g., an added line starting with "++ foo" becomes "+++ foo" in the diff). Since file.diff includes headers and hunks, consider tracking whether you're inside a hunk (after an @@ header) and only skipping +++/--- lines when not in a hunk, or otherwise narrowing header detection so hunk lines aren’t dropped from the indentation-only comparison.

Copilot uses AI. Check for mistakes.
.collect();

for added_line in &added_lines {
Expand Down
Loading