From 261e2c131e7b482e92d299a9e16b004960067074 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 06:44:34 +0000 Subject: [PATCH] refactor(commands): dedupe model scan sorting --- src/commands/models/scan.ts | 44 +++++++++++++++---------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/commands/models/scan.ts b/src/commands/models/scan.ts index ae4ff1a1b52..c6d44d50df5 100644 --- a/src/commands/models/scan.ts +++ b/src/commands/models/scan.ts @@ -50,19 +50,7 @@ function sortScanResults(results: ModelScanResult[]): ModelScanResult[] { return aToolLatency - bToolLatency; } - const aCtx = a.contextLength ?? 0; - const bCtx = b.contextLength ?? 0; - if (aCtx !== bCtx) { - return bCtx - aCtx; - } - - const aParams = a.inferredParamB ?? 0; - const bParams = b.inferredParamB ?? 0; - if (aParams !== bParams) { - return bParams - aParams; - } - - return a.modelRef.localeCompare(b.modelRef); + return compareScanMetadata(a, b); }); } @@ -74,22 +62,26 @@ function sortImageResults(results: ModelScanResult[]): ModelScanResult[] { return aLatency - bLatency; } - const aCtx = a.contextLength ?? 0; - const bCtx = b.contextLength ?? 0; - if (aCtx !== bCtx) { - return bCtx - aCtx; - } - - const aParams = a.inferredParamB ?? 0; - const bParams = b.inferredParamB ?? 0; - if (aParams !== bParams) { - return bParams - aParams; - } - - return a.modelRef.localeCompare(b.modelRef); + return compareScanMetadata(a, b); }); } +function compareScanMetadata(a: ModelScanResult, b: ModelScanResult): number { + const aCtx = a.contextLength ?? 0; + const bCtx = b.contextLength ?? 0; + if (aCtx !== bCtx) { + return bCtx - aCtx; + } + + const aParams = a.inferredParamB ?? 0; + const bParams = b.inferredParamB ?? 0; + if (aParams !== bParams) { + return bParams - aParams; + } + + return a.modelRef.localeCompare(b.modelRef); +} + function buildScanHint(result: ModelScanResult): string { const toolLabel = result.tool.ok ? `tool ${formatMs(result.tool.latencyMs)}` : "tool fail"; const imageLabel = result.image.skipped