```ts
/**
 * Where each ruled library should land.
 */
export function chooseUpgrades(
  request: Record<string, unknown>
): Record<string, unknown> {
  const installed = request.installed as Record<string, string>;
  const offers = request.offers as Record<string, string[]>;
  const rules = request.rules as any[];

  // Validate input types
  if (typeof installed !== "object" || installed === null) {
    throw new Error("installed must be a mapping");
  }
  if (typeof offers !== "object" || offers === null) {
    throw new Error("offers must be a mapping");
  }
  if (!Array.isArray(rules)) {
    throw new Error("rules must be a list");
  }

  const floors = new Map<string, string>();
  const ceilings = new Map<string, string>();

  // Validate rules and populate floors and ceilings
  for (const rule of rules) {
    if (typeof rule !== "object" || rule === null) {
      throw new Error("rule must be a mapping");
    }
    const { package: packageName, min, max } = rule;
    if (typeof packageName !== "string") {
      throw new Error("rule must have a 'package' string");
    }
    if (typeof min !== "string" || typeof max !== "string") {
      throw new Error("rule must have 'min' and 'max' strings");
    }
    if (!offers[packageName]) {
      throw new Error(`rule bounds a library the registry does not carry: ${packageName}`);
    }
    const [minMajor, minMinor] = min.split(".").map(Number);
    const [maxMajor, maxMinor] = max.split(".").map(Number);
    if (isNaN(minMajor) || isNaN(minMinor) || isNaN(maxMajor) || isNaN(maxMinor)) {
      throw new Error("release must be written as two groups of digits split by a full stop");
    }
    if (minMajor > maxMajor || (minMajor === maxMajor && minMinor > maxMinor)) {
      throw new Error("rule's min is above its max");
    }

    const low = floors.get(packageName);
    if (low === undefined || compareReleases(min, low) < 0) {
      floors.set(packageName, min);
    }
    const high = ceilings.get(packageName);
    if (high === undefined || compareReleases(max, high) > 0) {
      ceilings.set(packageName, max);
    }
  }

  const moves: Record<string, string>[] = [];
  const snags: Record<string, string>[] = [];

  // Process each library
  for (const name of Array.from(floors.keys()).sort()) {
    const low = floors.get(name) as string;
    const high = ceilings.get(name) as string;
    const allowed = offers[name].filter(
      (release) => compareReleases(release, low) >= 0 && compareReleases(release, high) <= 0
    );

    if (allowed.length === 0) {
      snags.push({ package: name, why: "none" });
      continue;
    }

    const here = installed[name];
    if (here !== undefined && !offers[name].includes(here)) {
      throw new Error(`library running a release the registry no longer carries: ${name}`);
    }
    if (here !== undefined && allowed.includes(here)) {
      moves.push({ package: name, to: here, action: "hold" });
      continue;
    }

    allowed.sort((a, b) => compareReleases(a, b));
    const best = allowed.find(release => compareReleases(release, here ||