1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
13pub enum CostClass {
14 Cheap = 0,
15 Workhorse = 1,
16 Frontier = 2,
17}
18
19#[derive(Debug, Clone, Copy)]
21pub struct ModelPrior {
22 pub family: &'static str,
25 pub cost: CostClass,
26 pub coding: u8,
27 pub reasoning: u8,
28 pub long_context: u8,
29 pub vision: u8,
30 pub structured_output: u8,
31}
32
33impl ModelPrior {
34 pub fn strength(&self) -> u32 {
37 (self.coding as u32) * 4
38 + (self.reasoning as u32) * 4
39 + (self.long_context as u32)
40 + (self.structured_output as u32)
41 }
42}
43
44const DEFAULT: ModelPrior = ModelPrior {
47 family: "unknown",
48 cost: CostClass::Workhorse,
49 coding: 60,
50 reasoning: 60,
51 long_context: 60,
52 vision: 40,
53 structured_output: 60,
54};
55
56pub fn prior_for(model: &str) -> ModelPrior {
59 let m = model.to_lowercase();
60 let has = |needle: &str| m.contains(needle);
61
62 if has("opus") {
64 return p("claude", CostClass::Frontier, 90, 95, 90, 85, 88);
65 }
66 if has("sonnet") {
67 return p("claude", CostClass::Workhorse, 85, 82, 85, 80, 85);
68 }
69 if has("haiku") {
70 return p("claude", CostClass::Cheap, 70, 65, 75, 70, 78);
71 }
72
73 if has("grok-build") || has("grok-4") {
75 return p("grok", CostClass::Frontier, 82, 80, 80, 60, 75);
76 }
77 if has("grok-composer") || has("composer") || has("grok") {
78 return p("grok", CostClass::Workhorse, 72, 68, 70, 50, 70);
79 }
80
81 if has("gemini") && (has("flash") || has("lite")) {
83 return p("google", CostClass::Cheap, 68, 65, 88, 75, 72);
84 }
85 if has("gemini") {
86 return p("google", CostClass::Frontier, 84, 86, 92, 88, 82);
87 }
88
89 if has("deepseek") && has("reason") {
91 return p("deepseek", CostClass::Workhorse, 80, 88, 70, 40, 72);
92 }
93 if has("deepseek") {
94 return p("deepseek", CostClass::Cheap, 78, 70, 70, 30, 70);
95 }
96
97 if has("nano") {
99 return p("openai", CostClass::Cheap, 68, 64, 70, 60, 80);
100 }
101 if has("mini") {
102 return p("openai", CostClass::Workhorse, 80, 78, 80, 75, 85);
103 }
104 if has("gpt") || has("openai") || has("o3") || has("o4") {
105 return p("openai", CostClass::Frontier, 88, 90, 85, 88, 90);
106 }
107
108 DEFAULT
109}
110
111const fn p(
112 family: &'static str,
113 cost: CostClass,
114 coding: u8,
115 reasoning: u8,
116 long_context: u8,
117 vision: u8,
118 structured_output: u8,
119) -> ModelPrior {
120 ModelPrior {
121 family,
122 cost,
123 coding,
124 reasoning,
125 long_context,
126 vision,
127 structured_output,
128 }
129}
130
131pub fn family_of(model: &str) -> &'static str {
133 prior_for(model).family
134}
135
136pub fn family_of_worker(name: &str) -> &'static str {
139 match name {
140 "claude-code" | "anthropic" | "claude" => "claude",
141 "grok" => "grok",
142 "codex" | "openai" => "openai",
143 "antigravity" | "google" | "gemini" => "google",
144 "deepseek" => "deepseek",
145 _ => "unknown",
147 }
148}
149
150pub fn tier_ladder(models: &[String]) -> Vec<String> {
157 models.to_vec()
158}
159
160#[cfg(test)]
161mod tests {
162 use super::*;
163
164 #[test]
165 fn ladder_preserves_given_order() {
166 let models = vec![
168 "haiku".to_string(),
169 "sonnet".to_string(),
170 "opus".to_string(),
171 ];
172 assert_eq!(tier_ladder(&models), models);
173 }
174
175 #[test]
176 fn families_classify() {
177 assert_eq!(family_of("claude-opus-4-8"), "claude");
178 assert_eq!(family_of("grok-build"), "grok");
179 assert_eq!(family_of("gemini-2.5-flash"), "google");
180 assert_eq!(family_of("deepseek-reasoner"), "deepseek");
181 assert_eq!(family_of("something-unheard-of"), "unknown");
182 }
183
184 #[test]
185 fn unknown_model_gets_conservative_default() {
186 let pr = prior_for("mystery-model-9000");
187 assert_eq!(pr.family, "unknown");
188 assert_eq!(pr.cost, CostClass::Workhorse);
189 }
190
191 #[test]
192 fn cost_class_orders_the_cascade() {
193 assert!(CostClass::Cheap < CostClass::Workhorse);
194 assert!(CostClass::Workhorse < CostClass::Frontier);
195 }
196}