/**
 * Port: Where task definitions come from.
 *
 * Adapters:
 * - ContentLakeTaskSource — GROQ query against Sanity Content Lake
 * - RepoTaskSource — reads .ailf/tasks/*.task.ts files
 * - TsTaskFileLoader — reads tasks/{mode}/*.task.ts (eval package)
 *
 * The key invariant: the pipeline orchestrator and all downstream steps
 * work with GeneralizedTaskDefinition[] regardless of where they came from.
 */
// ---------------------------------------------------------------------------
// Type guards — doc refs
// ---------------------------------------------------------------------------
/** Check if a doc ref resolves by slug.
 *
 * Excludes IdDocRef (which may carry an optional `slug` for display).
 * When both `id` and `slug` are present, it's an IdDocRef, not a SlugDocRef.
 */
export function isSlugRef(ref) {
    return "slug" in ref && !("id" in ref);
}
/** Check if a doc ref resolves by path.
 *
 * Excludes IdDocRef (which may carry an optional `path` for display).
 * When both `id` and `path` are present, it's an IdDocRef, not a PathDocRef.
 */
export function isPathRef(ref) {
    return "path" in ref && !("id" in ref);
}
/** Check if a doc ref resolves by document ID.
 *
 * Uses `"id" in ref` as the primary discriminator. IdDocRef may also carry
 * optional `slug` and `path` for display purposes, so we cannot exclude
 * on those keys. When both `id` and `slug` are present, `id` wins.
 */
export function isIdRef(ref) {
    return "id" in ref;
}
/** Check if a doc ref resolves by content release perspective */
export function isPerspectiveRef(ref) {
    return "perspective" in ref;
}
/**
 * Extract a display identifier from any doc ref.
 * Useful for logging, error messages, and retrieval metrics.
 */
export function canonicalDocRefLabel(ref) {
    if ("id" in ref) {
        // Show slug/path annotation if available for readability
        const hint = "slug" in ref ? ` (${ref.slug})` : "path" in ref ? ` (${ref.path})` : "";
        return `id:${ref.id}${hint}`;
    }
    if ("slug" in ref)
        return `slug:${ref.slug}`;
    if ("path" in ref)
        return `path:${ref.path}`;
    if ("perspective" in ref)
        return `perspective:${ref.perspective}`;
    return "unknown";
}
// ---------------------------------------------------------------------------
// Type guards — assertions
// ---------------------------------------------------------------------------
/** Check if an assertion uses the templated format (template + criteria) */
export function isTemplatedAssertion(entry) {
    return (entry.type === "llm-rubric" &&
        "template" in entry &&
        typeof entry.template === "string" &&
        "criteria" in entry &&
        Array.isArray(entry.criteria));
}
