/**
 * Bash shim generator for olam-flywheel backwards-compat layer.
 *
 * Generates deterministic bash shims that translate the positional-arg
 * invocation chain skills currently use (e.g.
 *   `bash ~/.claude/scripts/emit-breadcrumb.sh "plan-hard" "<plan-slug>" ...`)
 * into the new named-flag CLI:
 *   `olam flywheel emit-breadcrumb --skill plan-hard --plan <plan-slug> ...`
 *
 * Each shim:
 *   1. Hardens PATH (adds common olam install locations).
 *   2. Checks olam is reachable; exits 127 with actionable message if not.
 *   3. Translates positional args to named flags per the script's spec.
 *   4. exec's the olam CLI (passes signal handling + exit code through).
 *
 * Plan reference: docs/plans/olam-flywheel-cli-namespace/phase-a-tasks.md § A14
 * Closes part of K1 OQ21a (positional → named-flag translation in shims).
 */
/**
 * Registry of shim specs. Only includes scripts that chain skill prose
 * actively invokes via bash (the others are Python imports, no bash shim
 * needed). Extend this as more chain-skill invocation sites are migrated.
 */
export const SHIM_SPECS = Object.freeze([
    {
        basename: 'emit-breadcrumb.sh',
        olamSubcommand: 'flywheel emit-breadcrumb',
        minPositional: 6,
        usage: 'emit-breadcrumb.sh <skill> <plan> <pattern> <severity> <persona> <edit> [notes] [pass] [project]',
        args: [
            { position: 1, flag: 'skill', required: true },
            { position: 2, flag: 'plan', required: true },
            { position: 3, flag: 'pattern', required: true },
            { position: 4, flag: 'severity', required: true },
            { position: 5, flag: 'persona', required: true },
            { position: 6, flag: 'edit', required: true },
            { position: 7, flag: 'notes', required: false },
            { position: 8, flag: 'pass', required: false },
            { position: 9, flag: 'project', required: false },
        ],
    },
]);
/**
 * Generate the bash shim source for a given spec. Deterministic output —
 * same input always produces the same bytes (golden-fixture-friendly).
 */
export function generateShim(spec) {
    const argLines = [];
    for (const arg of spec.args) {
        if (arg.required) {
            argLines.push(`    --${arg.flag} "\$${arg.position}"`);
        }
        else {
            argLines.push(`    \${${arg.position}:+--${arg.flag} "\$${arg.position}"}`);
        }
    }
    const argsBlock = argLines.join(' \\\n');
    return `#!/usr/bin/env bash
# AUTO-GENERATED by \`olam flywheel install-shims\`
# DO NOT EDIT — regenerated on every install-shims run.
#
# Delegates to \`olam ${spec.olamSubcommand}\`; closes the K1 FS-2 cliff
# by translating the legacy positional-arg interface to the new named-flag CLI.
set -euo pipefail

# Harden PATH for common olam install locations (cron + hook contexts may
# have a minimal PATH; this preserves operator-installed shells).
PATH="\$HOME/.local/bin:\$HOME/.olam/bin:/opt/homebrew/bin:/usr/local/bin:\$PATH"

if ! command -v olam >/dev/null 2>&1; then
    echo "[shim] olam not found on PATH; cannot delegate ${spec.olamSubcommand}" >&2
    echo "[shim] install olam (https://github.com/pleri/olam) and run 'olam flywheel install-shims' to refresh" >&2
    exit 127
fi

if [ "\$#" -lt ${spec.minPositional} ]; then
    echo "Usage: ${spec.usage}" >&2
    exit 1
fi

exec olam ${spec.olamSubcommand} \\
${argsBlock}
`;
}
export function lookupShimSpec(basename) {
    return SHIM_SPECS.find((s) => s.basename === basename);
}
//# sourceMappingURL=shim-generator.js.map