| 283 | * 3. MLX-served (LM Studio) over GGUF (Ollama) for Apple Silicon speed |
| 284 | */ |
| 285 | export function recommendPrimary(models: DetectedModel[]): DetectedModel | undefined { |
| 286 | if (models.length === 0) return undefined; |
| 287 | // Already sorted by (toolCalls, paramsB) — tie-break with MLX preference. |
| 288 | const sorted = [...models].sort((a, b) => { |
| 289 | const aTC = a.toolCallsLikely ? 1 : 0; |
| 290 | const bTC = b.toolCallsLikely ? 1 : 0; |
| 291 | if (aTC !== bTC) return bTC - aTC; |
| 292 | const aParams = a.paramsB ?? 0; |
| 293 | const bParams = b.paramsB ?? 0; |
| 294 | if (aParams !== bParams) return bParams - aParams; |
| 295 | // Same size + same tool-call status → prefer LM Studio (MLX is faster on M-series) |
| 296 | if (a.source !== b.source) return a.source === 'lm-studio' ? -1 : 1; |
| 297 | return 0; |
| 298 | }); |
| 299 | return sorted[0]; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Recommend a sub-agent from the detected list, given the chosen parent. |