"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatFormattedSteps = formatFormattedSteps;
var 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.
 */
function formatFormattedSteps(formattedSteps, cursorPath) {
    var lines = [];
    var cursorPlaced = false;
    for (var _i = 0, formattedSteps_1 = formattedSteps; _i < formattedSteps_1.length; _i++) {
        var entry = formattedSteps_1[_i];
        if (cursorPath !== undefined && cursorPath !== '' && !cursorPlaced && entry.path === cursorPath) {
            lines.push("<< CURSOR >> (at position ".concat(entry.path, ")"));
            cursorPlaced = true;
        }
        var line = void 0;
        switch (entry.kind) {
            case 'step': {
                var idLabel = entry.step_id !== undefined && entry.step_id !== '' ? entry.step_id : MISSING_STEP_ID_SENTINEL;
                line = "[".concat(entry.path, "] (id: ").concat(idLabel, ")  ").concat(entry.text);
                break;
            }
            case 'task-start': {
                line = "[".concat(entry.path, "] --- Task: ").concat(entry.text, " ---");
                break;
            }
            case 'task-end': {
                line = "--- End Task: ".concat(entry.text, " ---");
                break;
            }
            case 'flow-start': {
                line = "[".concat(entry.path, "] --- Flow: ").concat(entry.text, " ---");
                break;
            }
            case 'flow-end': {
                line = "--- End Flow: ".concat(entry.text, " ---");
                break;
            }
            default: {
                // Unknown kind — render minimally so the model still sees the text rather than dropping it.
                line = "[".concat(entry.path, "] ").concat(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