Skip to content

The one and only agent harness for complex codebases. Project memory, planning, execution, and verified completion inside Codex.

1.9 KB
Raw Blame
import { ULW_LOOP_SUCCESS_CRITERION_USER_MODELS, UlwLoopError } from "./types.js";
function invalid(message, details) {
    throw new UlwLoopError(`Invalid successCriteria: ${message}`, "ULW_LOOP_ARGUMENT_INVALID", { details });
}
function isUserModel(value) {
    return typeof value === "string" && ULW_LOOP_SUCCESS_CRITERION_USER_MODELS.some((model) => model === value);
}
function requireText(value, field, index) {
    const trimmed = typeof value === "string" ? value.trim() : "";
    return trimmed || invalid(`entry ${index + 1} needs a non-empty ${field}.`, { index, field });
}
export function criterionId(index) {
    return `C${String(index + 1).padStart(3, "0")}`;
}
export function criteriaFromInput(input) {
    if (input.length === 0)
        invalid("provide at least one criterion or omit the field for placeholders.", { count: 0 });
    return input.map((entry, index) => {
        if (typeof entry !== "object" || entry === null || Array.isArray(entry))
            return invalid(`entry ${index + 1} must be an object.`, { index });
        const record = { ...entry };
        const userModel = record["userModel"] ?? "happy";
        if (!isUserModel(userModel))
            return invalid(`entry ${index + 1} userModel must be one of ${ULW_LOOP_SUCCESS_CRITERION_USER_MODELS.join(", ")}.`, {
                index,
                userModel: String(userModel),
            });
        const essential = record["essential"];
        if (essential !== undefined && typeof essential !== "boolean")
            return invalid(`entry ${index + 1} essential must be a boolean.`, { index });
        return {
            id: criterionId(index),
            scenario: requireText(record["scenario"], "scenario", index),
            userModel,
            expectedEvidence: requireText(record["expectedEvidence"], "expectedEvidence", index),
            essential: essential ?? true,
            capturedEvidence: null,
            status: "pending",
        };
    });
}