/**
 * wfrun/unit-shape.mjs — FRAMEWORK-BUG-033 capability gap (ID-03).
 *
 * Normalize a wave-engine plan blob to the unit-agnostic
 * `{units, unit_kind}` shape. Two input forms accepted:
 *   - Subtask-shaped (back-compat): `{subtasks: [...]}`.
 *   - Task-shaped (new): `{unit_kind: "task", tasks: [...]}`.
 *
 * Internally the wave engine operates purely on `{id, dependencies,
 * files}` records — only the I/O boundary cares about the rename.
 */
/**
 * Detect whether a plan blob is task-shaped, subtask-shaped, or invalid.
 *
 * @param {unknown} plan
 * @returns {{ units: Array<{id: string, dependencies: string[], files?: string[]}>, unit_kind: 'subtask' | 'task', error: string | null }}
 */
export function normalizeToUnits(plan) {
    if (!plan || typeof plan !== 'object') {
        return { units: [], unit_kind: 'subtask', error: 'Plan must be an object' };
    }
    const isTaskShape = plan.unit_kind === 'task' || (Array.isArray(plan.tasks) && !Array.isArray(plan.subtasks));
    if (isTaskShape) {
        if (!Array.isArray(plan.tasks)) {
            return { units: [], unit_kind: 'task', error: 'Plan must contain a "tasks" array' };
        }
        return { units: plan.tasks, unit_kind: 'task', error: null };
    }
    if (!Array.isArray(plan.subtasks)) {
        return {
            units: [],
            unit_kind: 'subtask',
            error: 'Plan must contain a "subtasks" array',
        };
    }
    return { units: plan.subtasks, unit_kind: 'subtask', error: null };
}
//# sourceMappingURL=unit-shape.mjs.map