Skip to content

Commit de0e892

Browse files
authored
fix(mcp): honor decision time ranges (#34)
Co-authored-by: Mark Stuart <mstuart@users.noreply.github.com>
1 parent eda39bf commit de0e892

1 file changed

Lines changed: 47 additions & 12 deletions

File tree

‎src/mcp/tools.rs‎

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,7 @@ async fn handle_trace_decision(args: &Value, project_root: &Path) -> CallToolRes
465465
}
466466
};
467467

468-
let max_commits = match time_range {
469-
"7d" => 100,
470-
"30d" => 500,
471-
"90d" => 1000,
472-
"1y" => 2000,
473-
_ => 5000, // "all"
474-
};
468+
let (max_commits, cutoff) = decision_time_range(time_range, chrono::Utc::now().timestamp());
475469

476470
let timeline = match git.extract_all_decisions(max_commits) {
477471
Ok(t) => t,
@@ -486,11 +480,12 @@ async fn handle_trace_decision(args: &Value, project_root: &Path) -> CallToolRes
486480
.decisions
487481
.iter()
488482
.filter(|d| {
489-
d.summary.to_lowercase().contains(&topic_lower)
490-
|| d.details.to_lowercase().contains(&topic_lower)
491-
|| d.files_affected
492-
.iter()
493-
.any(|f| f.to_lowercase().contains(&topic_lower))
483+
cutoff.is_none_or(|cutoff| d.timestamp >= cutoff)
484+
&& (d.summary.to_lowercase().contains(&topic_lower)
485+
|| d.details.to_lowercase().contains(&topic_lower)
486+
|| d.files_affected
487+
.iter()
488+
.any(|f| f.to_lowercase().contains(&topic_lower)))
494489
})
495490
.collect();
496491

@@ -534,6 +529,18 @@ async fn handle_trace_decision(args: &Value, project_root: &Path) -> CallToolRes
534529
CallToolResult::text(output)
535530
}
536531

532+
fn decision_time_range(time_range: &str, now: i64) -> (usize, Option<i64>) {
533+
let (max_commits, days) = match time_range {
534+
"7d" => (100, Some(7)),
535+
"30d" => (500, Some(30)),
536+
"90d" => (1000, Some(90)),
537+
"1y" => (2000, Some(365)),
538+
_ => (5000, None),
539+
};
540+
let cutoff = days.map(|days| now.saturating_sub(days * 24 * 60 * 60));
541+
(max_commits, cutoff)
542+
}
543+
537544
async fn handle_find_related(args: &Value, project_root: &Path) -> CallToolResult {
538545
let file = match args.get("file").and_then(|v| v.as_str()) {
539546
Some(f) => f,
@@ -930,3 +937,31 @@ async fn handle_get_session_patterns(args: &Value, _project_root: &Path) -> Call
930937

931938
CallToolResult::text(output)
932939
}
940+
941+
#[cfg(test)]
942+
mod tests {
943+
use super::decision_time_range;
944+
945+
#[test]
946+
fn decision_time_ranges_have_real_timestamp_cutoffs() {
947+
let now = 2_000_000_000;
948+
949+
assert_eq!(
950+
decision_time_range("7d", now),
951+
(100, Some(now - 7 * 24 * 60 * 60))
952+
);
953+
assert_eq!(
954+
decision_time_range("1y", now),
955+
(2000, Some(now - 365 * 24 * 60 * 60))
956+
);
957+
}
958+
959+
#[test]
960+
fn all_and_unknown_time_ranges_do_not_filter_by_date() {
961+
assert_eq!(decision_time_range("all", 2_000_000_000), (5000, None));
962+
assert_eq!(
963+
decision_time_range("unexpected", 2_000_000_000),
964+
(5000, None)
965+
);
966+
}
967+
}

0 commit comments

Comments
 (0)