Skip to content

Commit 74c19a4

Browse files
committed
local: scope to files holding the values a goal changes
Ranking validate.js first was not enough: qwen2.5-coder:3b still edited store.js. When a goal's numbers ('from 120 to 80') occur in some files, scope is those files plus files the goal names. Hunk recounts and misses are logged too.
1 parent 126b86d commit 74c19a4

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

‎phonton-worker/src/lib.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,12 +2057,16 @@ fn anchor_hunks(hunks: &mut [DiffHunk], root: &Path) {
20572057
DiffLine::Added(_) => None,
20582058
})
20592059
.collect();
2060-
h.old_count = old.len() as u32;
2061-
h.new_count = h
2060+
let new_count = h
20622061
.lines
20632062
.iter()
20642063
.filter(|l| !matches!(l, DiffLine::Removed(_)))
20652064
.count() as u32;
2065+
if (h.old_count, h.new_count) != (old.len() as u32, new_count) {
2066+
debug!(file = %h.file_path.display(), stated = ?(h.old_count, h.new_count), counted = ?(old.len(), new_count), "recounted hunk");
2067+
}
2068+
h.old_count = old.len() as u32;
2069+
h.new_count = new_count;
20662070
if old.is_empty() {
20672071
continue;
20682072
}
@@ -2095,6 +2099,8 @@ fn anchor_hunks(hunks: &mut [DiffHunk], root: &Path) {
20952099
{
20962100
debug!(file = %h.file_path.display(), from = h.old_start, to = at + 1, "relocated hunk");
20972101
h.old_start = at as u32 + 1;
2102+
} else {
2103+
debug!(file = %h.file_path.display(), at = h.old_start, "hunk matches no lines in the file");
20982104
}
20992105
}
21002106
// new_start follows from the old positions and earlier hunks' growth,

‎phonton-worker/src/local_run/plan.rs‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ pub async fn preview(mut request: LocalRunRequest) -> Result<LocalPlan> {
211211
|| r.score() >= threshold
212212
|| (r.content_hits >= 3 && r.content_hits >= named_content)
213213
});
214+
// "From 120 to 80": the value lives where the edit goes. Other
215+
// matches only invite a small model to change the wrong file.
216+
if ranked.iter().any(|r| r.literal_hits > 0) {
217+
let goal = request.goal.to_lowercase();
218+
let named = |path: &Path| {
219+
path.file_name()
220+
.is_some_and(|name| goal.contains(&name.to_string_lossy().to_lowercase()))
221+
};
222+
let before = ranked.len();
223+
ranked.retain(|r| r.literal_hits > 0 || named(&r.evidence.path));
224+
if ranked.len() < before {
225+
warnings.push("Scope narrowed to the files that contain values the goal changes. Name a file to include it.".into());
226+
}
227+
}
214228
if ranked.len() > 8 {
215229
warnings.push(format!("{} files matched; this bounded preview includes the top eight. Narrow the goal if more context is required.", ranked.len()));
216230
}
@@ -1204,11 +1218,11 @@ mod tests {
12041218
})
12051219
.await
12061220
.unwrap();
1207-
// First: the goal's `120` lives only there. A 3B model edited the
1208-
// first-listed store.js and the existing tests still passed.
1221+
// Only validate.js holds the goal's `120`. With store.js in scope a
1222+
// 3B model edited it and the existing tests still passed.
12091223
assert_eq!(
1210-
plan.request.files.first(),
1211-
Some(&PathBuf::from("src/validate.js")),
1224+
plan.request.files,
1225+
vec![PathBuf::from("src/validate.js")],
12121226
"{:?}",
12131227
plan.request.files
12141228
);

0 commit comments

Comments
 (0)