const MISSING_STEP_ID_SENTINEL = '-';
/**
 * Render a pre-formatted step list into the text block the agent reads.
 *
 * Single source of truth for the `formatted_steps` layout, shared across the api (rendering the
 * test_execution_state artifact and get_test_context) and the mabl CLI (rendering the refreshed
 * list it returns from step-mutation tools). Output is the authoritative dot-notation path plus
 * stable step id per line.
 *
 * Layout:
 *   step:        "[<path>] (id: <step_id>)  <text>"
 *   task-start:  "[<path>] --- Task: <text> ---"
 *   task-end:    "--- End Task: <text> ---"     (no path; end markers don't occupy a position)
 *   flow-start:  "[<path>] --- Flow: <text> ---"
 *   flow-end:    "--- End Flow: <text> ---"
 *
 * The cursor is placed immediately before the entry whose path matches cursorPath; if no entry
 * matches (or cursorPath is the empty string), the cursor is appended at the end. The "(id: -)"
 * sentinel marks a step entry with no step_id so the model still sees a placeholder.
 */
export function formatFormattedSteps(formattedSteps, cursorPath) {
    const lines = [];
    let cursorPlaced = false;
    for (const entry of formattedSteps) {
        if (cursorPath !== undefined && cursorPath !== '' && !cursorPlaced && entry.path === cursorPath) {
            lines.push(`<< CURSOR >> (at position ${entry.path})`);
            cursorPlaced = true;
        }
        let line;
        switch (entry.kind) {
            case 'step': {
                const idLabel = entry.step_id !== undefined && entry.step_id !== '' ? entry.step_id : MISSING_STEP_ID_SENTINEL;
                line = `[${entry.path}] (id: ${idLabel})  ${entry.text}`;
                break;
            }
            case 'task-start': {
                line = `[${entry.path}] --- Task: ${entry.text} ---`;
                break;
            }
            case 'task-end': {
                line = `--- End Task: ${entry.text} ---`;
                break;
            }
            case 'flow-start': {
                line = `[${entry.path}] --- Flow: ${entry.text} ---`;
                break;
            }
            case 'flow-end': {
                line = `--- End Flow: ${entry.text} ---`;
                break;
            }
            default: {
                // Unknown kind — render minimally so the model still sees the text rather than dropping it.
                line = `[${entry.path}] ${entry.text}`;
                break;
            }
        }
        lines.push(line);
    }
    if (!cursorPlaced) {
        // cursorPath empty / unset / no match: append a sentinel line so the model still sees a cursor.
        lines.push('<< CURSOR >> (at end)');
    }
    return lines.join('\n\n');
}
//# sourceMappingURL=formattedSteps.js.map