Commit cf6e990
authored
Implement command-aware content classification heuristics (#51)
## PR Auto Describe
## Summary
This PR delivers a major overhaul of omni's content processing pipeline,
including command-aware content classification, historical data repair
via `omni doctor`, pipeline refactoring, and CLI tooling improvements to
boost detection accuracy and user experience.
---
## Key Changes
- **Command-Aware Content Classification**: Rewrote the core `classify`
function to use command context for far more accurate content type
detection, with built-in heuristics for git, system, build, web, and
cloud commands.
- **Historical Stats Repair**: Added `omni doctor --fix` to reclassify
outdated, mislabeled historical distillation records in the local SQLite
store.
- **Pipeline Refactor**: Simplified hook and pipeline logic, replaced
the legacy `compose` function with dedicated distillation and auto-learn
evaluation code, added output truncation safety.
- **CLI & Tooling Updates**: Refined `omni stats` with better filtering
and clearer messaging, updated `omni learn` to include command context
in generated filters, reduced update check cache TTL to 4 hours.
---
## Detailed Breakdown
### Core Classification System
Rewrote `pipeline/classifier.rs` to add an optional `command_name`
parameter to `classify()`, with pre-stage heuristics that extract the
base command (e.g. `git` from `git status`) and route outputs to correct
content types: git subcommands, system utilities, build tools, web/JS
tools, and cloud tools. Updated all existing tests to use the new API,
added new test cases for command-specific classification, and updated
all benchmarks/tests to pass `None` as context where unavailable.
### Pipeline & Hook Logic
Refactored `hooks/pipe.rs` and `hooks/post_tool.rs` to pass command
context to `classify()`, replaced legacy `compose` calls with direct
distiller usage, added auto-learn evaluation via `evaluate_learning()`,
and added output truncation safety checks. Split `composer.rs`'s
`compose` function into a dedicated `evaluate_learning()` function for
auto-learn triggers, removed the unused `colored` import, and deleted
the legacy `compose` function entirely. Added properly formatted rewind
store notifications in both hook files.
### Data Store & Doctor Command
Added `reclassify_historical_data()` and `has_upgradable_history()` to
`sqlite.rs` to update old misclassified distillation records using their
stored command context. Updated `cli/doctor.rs` to add an Intelligence
Consistency check section: prompts users to run `--fix` to upgrade
historical stats, or runs repairs automatically when the flag is
present. Updated `stats.rs` to show a prompt to run `omni doctor --fix`
when upgradable history exists, added filter flag support
(--today/--week/--month/--all-commands) that defaults to detail mode,
improved messaging for hidden zero-savings commands, and cleaned up
default stats labeling.
### CLI Learn & MCP Server
Updated `cli/learn.rs` to pass command context to `generate_toml()` and
`apply_to_config()`, so auto-generated filters include the triggering
command as a `match_command` rule and better descriptions. Updated
`mcp/server.rs` to use the new `classify()` API and pass None context,
updated filter generation calls to match the new signature.
### Minor Updates
Reduced the update check cache TTL in `guard/update.rs` from 24 hours to
4 hours. Updated all test files (`savings_assertions.rs`,
`security_tests.rs`) to use the new `classify()` API and replace legacy
`compose` calls with direct distiller usage. Updated all benchmark calls
in `benches/pipeline.rs` to pass the new command context parameter.
---
## Notes
- The command-aware classification drastically improves accuracy for
tool-specific output (e.g. git diffs, cargo build logs, kubectl outputs)
by using the original executed command as context.
- The historical reclassification fixes long-standing issues with
mislabeled old stats records.
---
## Breaking Changes
1. **`classifier::classify` API Break**: The function now requires an
optional `command_name` parameter; all existing calls must be updated to
pass `None` if no command context is available (e.g.
`classifier::classify(input, None)`).
2. **Removed `composer::compose` Function**: Direct calls to this legacy
function will fail; use the distiller directly alongside
`evaluate_learning()` for auto-learn logic.
3. **Updated `generate_toml` and `apply_to_config` Signatures**: These
functions now accept an optional `command` parameter; callers must add
this argument (pass `None` if unused).14 files changed
Lines changed: 633 additions & 392 deletions
File tree
- benches
- src
- cli
- guard
- hooks
- mcp
- pipeline
- session
- store
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
433 | 474 | | |
434 | 475 | | |
435 | 476 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| 239 | + | |
| 240 | + | |
239 | 241 | | |
240 | | - | |
| 242 | + | |
| 243 | + | |
241 | 244 | | |
242 | 245 | | |
243 | 246 | | |
| |||
264 | 267 | | |
265 | 268 | | |
266 | 269 | | |
267 | | - | |
| 270 | + | |
268 | 271 | | |
269 | 272 | | |
270 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
141 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
142 | 148 | | |
143 | | - | |
| 149 | + | |
144 | 150 | | |
145 | | - | |
| 151 | + | |
146 | 152 | | |
| 153 | + | |
| 154 | + | |
147 | 155 | | |
148 | 156 | | |
149 | 157 | | |
| |||
227 | 235 | | |
228 | 236 | | |
229 | 237 | | |
230 | | - | |
| 238 | + | |
231 | 239 | | |
232 | 240 | | |
233 | 241 | | |
| |||
237 | 245 | | |
238 | 246 | | |
239 | 247 | | |
| 248 | + | |
| 249 | + | |
240 | 250 | | |
241 | 251 | | |
242 | | - | |
| 252 | + | |
243 | 253 | | |
244 | 254 | | |
245 | | - | |
| 255 | + | |
246 | 256 | | |
247 | 257 | | |
248 | 258 | | |
| |||
267 | 277 | | |
268 | 278 | | |
269 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
270 | 293 | | |
271 | 294 | | |
272 | 295 | | |
| |||
368 | 391 | | |
369 | 392 | | |
370 | 393 | | |
371 | | - | |
| 394 | + | |
372 | 395 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
378 | 406 | | |
379 | 407 | | |
380 | 408 | | |
| |||
416 | 444 | | |
417 | 445 | | |
418 | 446 | | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
429 | 471 | | |
430 | 472 | | |
431 | 473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
220 | 189 | | |
221 | | - | |
222 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
223 | 241 | | |
224 | 242 | | |
225 | 243 | | |
| |||
0 commit comments