/** * Judge questions authored as JSON files: `instructions` plus optional * `criteria`, keyed by question id. A JSON import widens every string, so a * question's kind follows from the shape of its `criteria` rather than a * `type` field — the same rule at compile time ({@link QuestionFor}) and at * load ({@link judgeQuestions}): * - a list of levels, lowest first → {@link ScoreQuestion} * - absent, or only `true`/`false` rubrics → {@link NoulQuestion} * - any other labels → {@link ChoiceQuestion} over them; `{}` when the caller * supplies every label (table rows, labels shared with another question) * * Instructions may be Handlebars templates; {@link renderQuestion} fills them. * * @example * ```ts ignore * import graph from "./auto-graph.json" with { type: "json" }; * const QUESTIONS = judgeQuestions(graph); * QUESTIONS.shading; // ChoiceQuestion<"shared" | "series" | "row"> * renderQuestion(QUESTIONS.order, { column: "latency" }); * ``` */ import { prompt } from "@oh-my-pi-zen/pi-utils"; import type { ChoiceQuestion, NoulQuestion, Question, ScoreQuestion } from "./types.js"; /** One question as a JSON question file writes it; {@link QuestionFor} gives its kind. */ export interface QuestionSpec { instructions: string; criteria?: string[] | { readonly [label: string]: string | null; }; } /** A JSON question file: {@link QuestionSpec}s keyed by question id. */ export interface QuestionFile { readonly [id: string]: QuestionSpec; } /** The question a {@link QuestionSpec} declares, with choice labels taken from its criteria keys. */ export type QuestionFor = S extends { criteria: string[]; } ? ScoreQuestion : S extends { criteria: infer C extends object; } ? [keyof C] extends [never] ? ChoiceQuestion : [keyof C] extends ["true" | "false"] ? NoulQuestion : ChoiceQuestion> : NoulQuestion; /** Every question a {@link QuestionFile} declares, keyed as in the file. */ export type QuestionsFor = { [K in keyof F]: QuestionFor; }; /** * The typed questions of a JSON question file; answers to them come back typed * through {@link JudgmentResult}. * @throws when a score question lists fewer than two levels. */ export declare function judgeQuestions(file: F): QuestionsFor; /** `question` with its instructions rendered as a Handlebars template over `context`. */ export declare function renderQuestion(question: Q, context: prompt.TemplateContext): Q;