import type { CompactionDurationEstimate } from "../observability/context-telemetry.ts"; import { parseJsonOnlyArgs } from "./router.ts"; import { type CliDependencies, callAndPrint } from "./support.ts"; export function formatCompactionEstimate(estimate: CompactionDurationEstimate): string { if (estimate.confidence === "cold-start" || estimate.ms === null) { return `Compaction duration: cold-start (${estimate.sampleSize.toLocaleString()} sample(s), not enough evidence yet)`; } return `Compaction duration: ~${estimate.ms.toLocaleString()}ms learned from ${estimate.sampleSize.toLocaleString()} sample(s)`; } export async function runCompactionCommand( action: string | undefined, rest: string[], deps: CliDependencies, usage: () => number, ): Promise { if (action !== "estimate") return usage(); const parsed = parseJsonOnlyArgs(rest); if (!parsed) return usage(); return callAndPrint(deps, "compaction.estimate", {}, parsed.json, formatCompactionEstimate); }