Skip to content

Commit 66b418e

Browse files
committed
refactor: reformat codebase and apply minor structural cleanup across CLI, guard, and hook modules
1 parent 834e280 commit 66b418e

6 files changed

Lines changed: 119 additions & 108 deletions

File tree

src/cli/learn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn run_learn(args: &[String]) -> Result<()> {
9191
.bright_white()
9292
);
9393
let report = crate::pipeline::toml_filter::run_inline_tests(
94-
&crate::pipeline::toml_filter::load_all_filters(),
94+
crate::pipeline::toml_filter::load_all_filters(),
9595
);
9696
let total = report.passes + report.failures.len();
9797

src/cli/stats.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ fn print_help() {
111111
"--month".cyan()
112112
);
113113
println!(" {: <12} Machine-readable JSON output", "--json".cyan());
114-
println!(" {: <12} Display breakdown per project path", "--project".cyan());
114+
println!(
115+
" {: <12} Display breakdown per project path",
116+
"--project".cyan()
117+
);
115118
println!(" {: <12} Show this help message", "--help, -h".cyan());
116119

117120
println!("\n{}", "EXAMPLES:".bold().bright_white());
@@ -582,7 +585,11 @@ fn run_project_stats(args: &[String], store: &Store) -> Result<()> {
582585
};
583586

584587
let projects = store.get_project_stats(since)?;
585-
println!("\n {} — {} Breakdown", "OMNI Project Analytics".bold().bright_white(), period_label);
588+
println!(
589+
"\n {} — {} Breakdown",
590+
"OMNI Project Analytics".bold().bright_white(),
591+
period_label
592+
);
586593
print_separator();
587594

588595
if projects.is_empty() {
@@ -600,12 +607,19 @@ fn run_project_stats(args: &[String], store: &Store) -> Result<()> {
600607
let display_path = if path.chars().count() > 30 {
601608
let mut s: String = path.chars().take(12).collect();
602609
s.push_str("...");
603-
s.extend(path.chars().rev().take(15).collect::<String>().chars().rev());
610+
s.extend(
611+
path.chars()
612+
.rev()
613+
.take(15)
614+
.collect::<String>()
615+
.chars()
616+
.rev(),
617+
);
604618
s
605619
} else {
606620
path
607621
};
608-
622+
609623
let bar = format_bar(savings);
610624
let bar_colored = if savings > 80.0 {
611625
bar.bright_green()

src/guard/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::paths;
12
use serde::Deserialize;
23
use std::fs;
3-
use crate::paths;
44

55
#[derive(Debug, Deserialize, Default)]
66
pub struct OmniConfig {

src/guard/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
pub mod config;
12
pub mod env;
23
pub mod limits;
34
pub mod trust;
45
pub mod update;
5-
pub mod config;

src/hooks/pipe.rs

Lines changed: 98 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -186,98 +186,97 @@ fn distill(
186186
}
187187
}
188188

189-
let (output, filter_name, rewind_hash, kept_count, dropped_count, collapse_savings, route) = if let Some(filter) =
190-
matched_toml
191-
{
192-
let out = filter.apply(&input_text);
193-
(out, filter.name.clone(), None, 0, 0, None, Route::Keep)
194-
} else {
195-
let cmd = command_name.unwrap_or("");
196-
197-
// Pure Command Architecture: Resolve profile
198-
let profile = crate::pipeline::registry::resolve_profile(cmd);
199-
200-
// 1. Initial Scoring
201-
let segments = scorer::score_segments(
202-
&input_text,
203-
profile.segmentation,
204-
session.as_ref().and_then(|m| m.lock().ok()).as_deref(),
205-
);
206-
207-
// 2. Collapse
208-
let collapse_result = collapse::collapse(&input_text, &profile.collapse);
209-
let collapse_savings_data = if collapse_result.original_lines > collapse_result.collapsed_to {
210-
Some((collapse_result.original_lines, collapse_result.collapsed_to))
189+
let (output, filter_name, rewind_hash, kept_count, dropped_count, collapse_savings, route) =
190+
if let Some(filter) = matched_toml {
191+
let out = filter.apply(&input_text);
192+
(out, filter.name.clone(), None, 0, 0, None, Route::Keep)
211193
} else {
212-
None
213-
};
214-
let effective_input = collapse_result.collapsed_lines.join("\n");
194+
let cmd = command_name.unwrap_or("");
215195

216-
// 3. Re-score
217-
let final_segments = if collapse_result.savings_pct > 0.1 {
218-
scorer::score_segments(
219-
&effective_input,
196+
// Pure Command Architecture: Resolve profile
197+
let profile = crate::pipeline::registry::resolve_profile(cmd);
198+
199+
// 1. Initial Scoring
200+
let segments = scorer::score_segments(
201+
&input_text,
220202
profile.segmentation,
221203
session.as_ref().and_then(|m| m.lock().ok()).as_deref(),
222-
)
223-
} else {
224-
segments
225-
};
204+
);
226205

227-
// 4. Distill
228-
let mut out = crate::distillers::distill_with_command(
229-
&final_segments,
230-
&effective_input,
231-
cmd,
232-
session.as_ref().and_then(|m| m.lock().ok()).as_deref(),
233-
);
206+
// 2. Collapse
207+
let collapse_result = collapse::collapse(&input_text, &profile.collapse);
208+
let collapse_savings_data =
209+
if collapse_result.original_lines > collapse_result.collapsed_to {
210+
Some((collapse_result.original_lines, collapse_result.collapsed_to))
211+
} else {
212+
None
213+
};
214+
let effective_input = collapse_result.collapsed_lines.join("\n");
215+
216+
// 3. Re-score
217+
let final_segments = if collapse_result.savings_pct > 0.1 {
218+
scorer::score_segments(
219+
&effective_input,
220+
profile.segmentation,
221+
session.as_ref().and_then(|m| m.lock().ok()).as_deref(),
222+
)
223+
} else {
224+
segments
225+
};
226+
227+
// 4. Distill
228+
let mut out = crate::distillers::distill_with_command(
229+
&final_segments,
230+
&effective_input,
231+
cmd,
232+
session.as_ref().and_then(|m| m.lock().ok()).as_deref(),
233+
);
234234

235-
// Rewind decision
236-
let noise_count = final_segments
237-
.iter()
238-
.filter(|s| s.final_score() < 0.3)
239-
.count();
240-
let should_store = noise_count as f32 / final_segments.len().max(1) as f32 > 0.4
241-
&& final_segments.len() > 20;
242-
243-
let d_count = noise_count;
244-
let k_count = final_segments.len() - d_count;
245-
246-
let dropped_lines: usize = final_segments
247-
.iter()
248-
.filter(|s| s.final_score() < 0.3)
249-
.map(|s| s.content.lines().count())
250-
.sum();
251-
252-
// Auto-learn trigger
253-
if !cmd.is_empty() && input_text.len() > 100 {
254-
let poor = final_segments.len() > 5
255-
&& (d_count as f32 / final_segments.len().max(1) as f32) < 0.3;
256-
if poor {
257-
crate::session::learn::queue_for_learn(&input_text, cmd);
235+
// Rewind decision
236+
let noise_count = final_segments
237+
.iter()
238+
.filter(|s| s.final_score() < 0.3)
239+
.count();
240+
let should_store = noise_count as f32 / final_segments.len().max(1) as f32 > 0.4
241+
&& final_segments.len() > 20;
242+
243+
let d_count = noise_count;
244+
let k_count = final_segments.len() - d_count;
245+
246+
let dropped_lines: usize = final_segments
247+
.iter()
248+
.filter(|s| s.final_score() < 0.3)
249+
.map(|s| s.content.lines().count())
250+
.sum();
251+
252+
// Auto-learn trigger
253+
if !cmd.is_empty() && input_text.len() > 100 {
254+
let poor = final_segments.len() > 5
255+
&& (d_count as f32 / final_segments.len().max(1) as f32) < 0.3;
256+
if poor {
257+
crate::session::learn::queue_for_learn(&input_text, cmd);
258+
}
258259
}
259-
}
260-
261-
let mut r_hash = None;
262-
263-
// Determine Route
264-
let ratio = 1.0 - (out.len() as f32 / input_text.len().max(1) as f32);
265-
let mut route = if r_hash.is_some() {
266-
Route::Rewind
267-
} else if ratio >= 0.7 {
268-
Route::Keep
269-
} else if ratio >= 0.3 {
270-
Route::Soft
271-
} else {
272-
Route::Passthrough
273-
};
274260

275-
if route == Route::Soft {
276-
out.push_str("\n[Partial signal - omni learn recommended]\n");
277-
}
261+
let mut r_hash = None;
262+
263+
// Determine Route
264+
let ratio = 1.0 - (out.len() as f32 / input_text.len().max(1) as f32);
265+
let mut route = if r_hash.is_some() {
266+
Route::Rewind
267+
} else if ratio >= 0.7 {
268+
Route::Keep
269+
} else if ratio >= 0.3 {
270+
Route::Soft
271+
} else {
272+
Route::Passthrough
273+
};
274+
275+
if route == Route::Soft {
276+
out.push_str("\n[Partial signal - omni learn recommended]\n");
277+
}
278278

279-
if should_store {
280-
if let Some(s) = store {
279+
if should_store && let Some(s) = store {
281280
let hash = s.store_rewind(&input_text);
282281
if std::io::stdout().is_terminal() {
283282
out.push_str(&format!(
@@ -297,25 +296,24 @@ fn distill(
297296
r_hash = Some(hash);
298297
route = Route::Rewind; // Override if stored in rewind
299298
}
300-
}
301299

302-
// Safety truncation
303-
const MAX_OUTPUT: usize = 50_000;
304-
if out.len() > MAX_OUTPUT {
305-
out.truncate(MAX_OUTPUT);
306-
out.push_str("\n[OMNI: output truncated]\n");
307-
}
300+
// Safety truncation
301+
const MAX_OUTPUT: usize = 50_000;
302+
if out.len() > MAX_OUTPUT {
303+
out.truncate(MAX_OUTPUT);
304+
out.push_str("\n[OMNI: output truncated]\n");
305+
}
308306

309-
(
310-
out,
311-
cmd.split_whitespace().next().unwrap_or("omni").to_string(),
312-
r_hash,
313-
k_count,
314-
d_count,
315-
collapse_savings_data,
316-
route,
317-
)
318-
};
307+
(
308+
out,
309+
cmd.split_whitespace().next().unwrap_or("omni").to_string(),
310+
r_hash,
311+
k_count,
312+
d_count,
313+
collapse_savings_data,
314+
route,
315+
)
316+
};
319317

320318
PipelineResult {
321319
session_id,

src/hooks/post_tool.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ pub fn process_payload(
220220
}
221221
}
222222

223-
224223
if should_store {
225224
if let Some(ref s) = store {
226225
let hash = s.store_rewind(&content);

0 commit comments

Comments
 (0)