fix(runtime): preserve distinct summary lines
This commit is contained in:
parent
8321fd0c6b
commit
2983d66848
1 changed files with 47 additions and 3 deletions
|
|
@ -109,13 +109,13 @@ fn normalize_lines(summary: &str, max_line_chars: usize) -> NormalizedSummary {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let truncated = truncate_line(&normalized, max_line_chars);
|
let dedupe_key = dedupe_key(&normalized);
|
||||||
let dedupe_key = dedupe_key(&truncated);
|
|
||||||
if !seen.insert(dedupe_key) {
|
if !seen.insert(dedupe_key) {
|
||||||
removed_duplicate_lines += 1;
|
removed_duplicate_lines += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let truncated = truncate_line(&normalized, max_line_chars);
|
||||||
lines.push(truncated);
|
lines.push(truncated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,7 +207,17 @@ fn omission_notice(omitted_lines: usize) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collapse_inline_whitespace(line: &str) -> String {
|
fn collapse_inline_whitespace(line: &str) -> String {
|
||||||
line.split_whitespace().collect::<Vec<_>>().join(" ")
|
let trimmed_start = line.trim_start_matches(char::is_whitespace);
|
||||||
|
if trimmed_start.is_empty() {
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
let indent = &line[..line.len() - trimmed_start.len()];
|
||||||
|
let collapsed = trimmed_start
|
||||||
|
.split_whitespace()
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" ");
|
||||||
|
format!("{indent}{collapsed}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn truncate_line(line: &str, max_chars: usize) -> String {
|
fn truncate_line(line: &str, max_chars: usize) -> String {
|
||||||
|
|
@ -286,6 +296,40 @@ mod tests {
|
||||||
assert!(result.omitted_lines > 0);
|
assert!(result.omitted_lines > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn keeps_distinct_long_lines_that_share_a_truncated_prefix() {
|
||||||
|
// given
|
||||||
|
let repeated_prefix = "- Current work: ".to_string() + &"x".repeat(180);
|
||||||
|
let summary = format!("Conversation summary:\n{repeated_prefix} A\n{repeated_prefix} B");
|
||||||
|
|
||||||
|
// when
|
||||||
|
let result = compress_summary(
|
||||||
|
&summary,
|
||||||
|
SummaryCompressionBudget {
|
||||||
|
max_chars: 400,
|
||||||
|
max_lines: 8,
|
||||||
|
max_line_chars: 80,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assert_eq!(result.removed_duplicate_lines, 0);
|
||||||
|
assert_eq!(result.summary.lines().count(), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn preserves_nested_bullet_indentation() {
|
||||||
|
// given
|
||||||
|
let summary = "Conversation summary:\n - user: first item\n - assistant: second item";
|
||||||
|
|
||||||
|
// when
|
||||||
|
let result = compress_summary(summary, SummaryCompressionBudget::default());
|
||||||
|
|
||||||
|
// then
|
||||||
|
assert!(result.summary.contains("\n - user: first item"));
|
||||||
|
assert!(result.summary.contains("\n - assistant: second item"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn provides_a_default_text_only_helper() {
|
fn provides_a_default_text_only_helper() {
|
||||||
// given
|
// given
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue