style(context): bersihkan warning clippy pedantic di squash.rs dan dedup.rs

Perbaikan gaya murni (format! di-append ke String -> write!, syntax
perbandingan yang lebih jelas, backtick di doc comment) tanpa
mengubah perilaku -- semua test tetap hijau.
This commit is contained in:
asepharyana
2026-07-16 07:56:11 +07:00
parent d6de9735ab
commit e075eb7acc
2 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ pub fn collapse(messages: &[ChatMessage]) -> (Vec<ChatMessage>, bool) {
/// ///
/// Why hash the arguments: keeps the key a fixed, short size regardless /// Why hash the arguments: keeps the key a fixed, short size regardless
/// of argument payload size. `serde_json::to_string` is already /// of argument payload size. `serde_json::to_string` is already
/// canonical here — this codebase doesn't enable serde_json's /// canonical here — this codebase doesn't enable `serde_json`'s
/// `preserve_order` feature, so `Value::Object` is backed by a /// `preserve_order` feature, so `Value::Object` is backed by a
/// `BTreeMap` and always serializes keys in sorted order. /// `BTreeMap` and always serializes keys in sorted order.
fn dedup_key(tool_name: &str, canonical_args: &str) -> String { fn dedup_key(tool_name: &str, canonical_args: &str) -> String {
+4 -3
View File
@@ -12,6 +12,7 @@
//! overall budget. //! overall budget.
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt::Write;
/// Below this size, compression isn't worth the risk of losing detail — /// Below this size, compression isn't worth the risk of losing detail —
/// pass the output through unchanged. /// pass the output through unchanged.
@@ -249,7 +250,7 @@ fn squash_generic(text: &str, budget: usize) -> String {
let mut prev = ""; let mut prev = "";
for (i, &line) in lines.iter().enumerate().take(tail_start).skip(head_end) { for (i, &line) in lines.iter().enumerate().take(tail_start).skip(head_end) {
let non_trivial = !line.trim().is_empty() && line != prev; let non_trivial = !line.trim().is_empty() && line != prev;
if non_trivial && used + line.len() + 1 <= budget { if non_trivial && used + line.len() < budget {
keep.insert(i); keep.insert(i);
used += line.len() + 1; used += line.len() + 1;
} }
@@ -269,14 +270,14 @@ fn render_kept_lines(lines: &[&str], keep: &HashSet<usize>) -> String {
let mut cursor = 0usize; let mut cursor = 0usize;
for &i in &kept_sorted { for &i in &kept_sorted {
if i > cursor { if i > cursor {
out.push_str(&format!("[{} lines omitted]\n", i - cursor)); let _ = writeln!(out, "[{} lines omitted]", i - cursor);
} }
out.push_str(lines[i]); out.push_str(lines[i]);
out.push('\n'); out.push('\n');
cursor = i + 1; cursor = i + 1;
} }
if cursor < lines.len() { if cursor < lines.len() {
out.push_str(&format!("[{} lines omitted]\n", lines.len() - cursor)); let _ = writeln!(out, "[{} lines omitted]", lines.len() - cursor);
} }
out out
} }