Skip to content

Commit 640af81

Browse files
committed
fix: resolve manual_checked_ops clippy warnings
Use checked_div() instead of manual 'if x > 0 { value / x }' patterns: - token_budget.rs: Use checked_div for budget distribution - metrics.rs: Use checked_div for mean_ms calculation - app/state.rs: Use checked_div for chat line estimation
1 parent 6caa8f9 commit 640af81

5 files changed

Lines changed: 104 additions & 9 deletions

File tree

src/cortex-cli/src/models_cmd.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,63 @@ fn get_available_models() -> Vec<ModelInfo> {
411411
input_cost_per_million: Some(0.55),
412412
output_cost_per_million: Some(2.19),
413413
},
414+
// Ollama models (local)
415+
ModelInfo {
416+
id: "llama3.2".to_string(),
417+
name: "Llama 3.2".to_string(),
418+
provider: "ollama".to_string(),
419+
capabilities: ModelCapabilities {
420+
vision: false,
421+
tools: true,
422+
parallel_tools: false,
423+
streaming: true,
424+
json_mode: true,
425+
},
426+
input_cost_per_million: None, // Local model, no API cost
427+
output_cost_per_million: None,
428+
},
429+
ModelInfo {
430+
id: "llama3.2:1b".to_string(),
431+
name: "Llama 3.2 1B".to_string(),
432+
provider: "ollama".to_string(),
433+
capabilities: ModelCapabilities {
434+
vision: false,
435+
tools: true,
436+
parallel_tools: false,
437+
streaming: true,
438+
json_mode: true,
439+
},
440+
input_cost_per_million: None,
441+
output_cost_per_million: None,
442+
},
443+
ModelInfo {
444+
id: "codellama".to_string(),
445+
name: "Code Llama".to_string(),
446+
provider: "ollama".to_string(),
447+
capabilities: ModelCapabilities {
448+
vision: false,
449+
tools: false,
450+
parallel_tools: false,
451+
streaming: true,
452+
json_mode: false,
453+
},
454+
input_cost_per_million: None,
455+
output_cost_per_million: None,
456+
},
457+
ModelInfo {
458+
id: "mistral".to_string(),
459+
name: "Mistral 7B".to_string(),
460+
provider: "ollama".to_string(),
461+
capabilities: ModelCapabilities {
462+
vision: false,
463+
tools: true,
464+
parallel_tools: false,
465+
streaming: true,
466+
json_mode: true,
467+
},
468+
input_cost_per_million: None,
469+
output_cost_per_million: None,
470+
},
414471
]
415472
}
416473

src/cortex-engine/src/context/token_budget.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ impl TokenBudgetManager {
179179

180180
if remaining > 0 {
181181
let count = self.allocations.len() as u32;
182-
if count > 0 {
183-
let extra_each = remaining / count;
182+
if let Some(extra_each) = remaining.checked_div(count) {
184183
for alloc in self.allocations.values_mut() {
185184
alloc.budget += extra_each;
186185
}

src/cortex-engine/src/metrics.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,10 @@ impl Timer {
523523
total_ms: total_ns / 1_000_000,
524524
min_ms: if count > 0 { min_ns / 1_000_000 } else { 0 },
525525
max_ms: if count > 0 { max_ns / 1_000_000 } else { 0 },
526-
mean_ms: if count > 0 {
527-
(total_ns / count) / 1_000_000
528-
} else {
529-
0
530-
},
526+
mean_ms: total_ns
527+
.checked_div(count)
528+
.map(|v| v / 1_000_000)
529+
.unwrap_or(0),
531530
}
532531
}
533532
}

src/cortex-tui/src/app/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,8 @@ impl AppState {
618618
// Estimate lines: content length / width + 2 for spacing
619619
let content_len = msg.content.len();
620620
let width = area_width.saturating_sub(4) as usize; // Account for margins
621-
if width > 0 {
622-
total += (content_len / width) + 1; // At least 1 line per message
621+
if let Some(lines) = content_len.checked_div(width) {
622+
total += lines + 1; // At least 1 line per message
623623
}
624624
total += 2; // Blank line + some overhead
625625
}

src/cortex-tui/src/commands/registry/builtin.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,33 @@ pub fn register_builtin_commands(registry: &mut CommandRegistry) {
581581
false,
582582
));
583583

584+
registry.register(CommandDef::new(
585+
"mcp-tools",
586+
&["tools", "lt"],
587+
"List and manage MCP tools",
588+
"/mcp-tools",
589+
CommandCategory::Mcp,
590+
false,
591+
));
592+
593+
registry.register(CommandDef::new(
594+
"mcp-auth",
595+
&["auth"],
596+
"MCP authentication management",
597+
"/mcp-auth",
598+
CommandCategory::Mcp,
599+
false,
600+
));
601+
602+
registry.register(CommandDef::new(
603+
"mcp-reload",
604+
&[],
605+
"Reload MCP server configuration",
606+
"/mcp-reload",
607+
CommandCategory::Mcp,
608+
false,
609+
));
610+
584611
// ========================================
585612
// DEBUG COMMANDS
586613
// ========================================
@@ -786,4 +813,17 @@ pub fn register_builtin_commands(registry: &mut CommandRegistry) {
786813
CommandCategory::General,
787814
true,
788815
));
816+
817+
// ========================================
818+
// HIDDEN COMMANDS (for testing/debugging)
819+
// ========================================
820+
821+
registry.register(CommandDef::hidden(
822+
"crash",
823+
&[],
824+
"Intentionally crash the application (debug only)",
825+
"/crash",
826+
CommandCategory::Debug,
827+
false,
828+
));
789829
}

0 commit comments

Comments
 (0)