/**
 * Image-presence pre-flight + fail-fast hint.
 *
 * Implements Decision #6 (revised pass 3) — `olam bootstrap` is the
 * SOLE on-ramp; existing commands (`host-cp start`, `auth up`, `create`)
 * do NOT auto-pull on missing image. Instead they fail-fast with a
 * named remedy pointing operators at bootstrap.
 *
 * Why no auto-pull:
 *   - Eliminates ~150 LOC of dual-path maintenance (Phase 2 review's
 *     OQ39 finding).
 *   - Predictable: there's exactly ONE place that can pull images
 *     (`olam bootstrap`), so support questions ("which command pulled
 *     the wrong digest?") have a single answer.
 *   - The hint operators see is the same regardless of which command
 *     they tried — easier to remember.
 */
import { spawnSync } from 'node:child_process';
const realDockerImageInspect = (imageRef) => {
    const result = spawnSync('docker', ['image', 'inspect', imageRef, '--format', '{{.Id}}'], { encoding: 'utf8', timeout: 10_000 });
    return { exitCode: result.status ?? -1 };
};
export function checkImagePresent(input, inspect = realDockerImageInspect) {
    const { imageRef, callerCommand } = input;
    const result = inspect(imageRef);
    if (result.exitCode === 0) {
        return { imageRef, present: true, stderrLine: '' };
    }
    return {
        imageRef,
        present: false,
        stderrLine: `Error: image '${imageRef}' not found locally.\n` +
            `  ${callerCommand} does not auto-pull (per Decision #6 in the` +
            ` olam-fresh-install-self-bootstrap epic).\n` +
            `  Remedy: run \`olam bootstrap\` to pull all required images,` +
            ` then retry.`,
    };
}
//# sourceMappingURL=image-presence.js.map