extract truncation helpers, fix clippy warnings, dedup batching loop
Add util::truncate() and util::first_n_chars() to replace 16 call sites doing the same floor_char_boundary or chars().take().collect() patterns. Deduplicate the batching loop in consolidate.rs (4 copies → 1 loop over an array). Fix all clippy warnings: redundant closures, needless borrows, collapsible if, unnecessary cast, manual strip_prefix. Net: -44 lines across 16 files.
This commit is contained in:
parent
e24dee6bdf
commit
52523403c5
16 changed files with 85 additions and 129 deletions
|
|
@ -144,13 +144,7 @@ fn extract_conversation(path: &Path) -> Vec<Message> {
|
|||
fn format_for_extraction(messages: &[Message]) -> String {
|
||||
messages.iter()
|
||||
.map(|msg| {
|
||||
let text = if msg.text.len() > 3000 {
|
||||
// Find a char boundary near 2800
|
||||
let trunc = msg.text.floor_char_boundary(2800);
|
||||
format!("{}\n[...truncated...]", &msg.text[..trunc])
|
||||
} else {
|
||||
msg.text.clone()
|
||||
};
|
||||
let text = crate::util::truncate(&msg.text, 2800, "\n[...truncated...]");
|
||||
let ts = if msg.timestamp.len() >= 19 { &msg.timestamp[..19] } else { "" };
|
||||
if ts.is_empty() {
|
||||
format!("[{}] {}", msg.role, text)
|
||||
|
|
@ -244,8 +238,7 @@ pub fn mine_transcript(
|
|||
if dry_run {
|
||||
for (i, (offset, chunk)) in chunks.iter().enumerate() {
|
||||
eprintln!("\n--- Chunk {} (offset {}, {} chars) ---", i + 1, offset, chunk.len());
|
||||
let preview = if chunk.len() > 500 { &chunk[..chunk.floor_char_boundary(500)] } else { chunk };
|
||||
eprintln!("{}", preview);
|
||||
eprintln!("{}", crate::util::truncate(chunk, 500, ""));
|
||||
if chunk.len() > 500 {
|
||||
eprintln!(" ... ({} more chars)", chunk.len() - 500);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue