/** * The jev-use handoff protocol. * * Jev (TypeSafe AI's System One model) answers typed questions about a state * in one forward pass — it never generates text. An LLM and Jev cooperate by * handing off: * * LLM ──(state + typed questions)──▶ Jev fast, cheap, calibrated * Jev ──(verdict, escalate=true)──▶ LLM when a boundary is hit * * Escalation is not an error: it is a typed signal that this step belongs to * the LLM. The boundaries, in the words the verdict uses: * * - writing : the step must produce new content (text, code, free-form * tool arguments). Structurally impossible for Jev; decided BEFORE * calling it. * - open_ended : the question cannot be expressed as noul / choice / score * (no enumerable options, no ordered levels). Decided BEFORE calling. * - oversized : the state itself does not fit in Jev's context. Also * decided BEFORE calling, for the whole batch. * - unsure : Jev answered but the distribution is too flat to act on. * Decided AFTER calling, against the threshold for that answer's * confidence source (see `ConfidenceSource`). * * Plus one operational reason, `unreachable`: Jev being down must degrade to * "the LLM handles it", never block the loop. * * Questions are written with the three builders at the bottom of this file — * `check` (noul), `pick` (choice), `rate` (score). The type names and wire * values keep Jev's own vocabulary; the builders only spell it in English. */ /** Jev's three question primitives. */ export type QuestionType = "noul" | "choice" | "score"; /** Why control goes (back) to the LLM — the vocabulary of the whole handoff. */ export type EscalationReason = | "writing" | "open_ended" | "oversized" | "unsure" | "unreachable"; /** * Where a verdict's `confidence` came from — the two are different quantities * and each has its own escalation threshold: * * - reported : the model reported it. Jev's own confidence head, returned * for `choice` and `score` answers (never for `noul`). * - estimated : jev-use worked it out from the answer's own distribution — * top-minus-runner-up for `choice`/`score`, `2·|p − 0.5|` for `noul`. * Systematically lower than the reported head on questions with more than * two options, so it escalates below a lower number. */ export type ConfidenceSource = "reported" | "estimated"; /** noul only: what a yes and a no mean, to sharpen calibration. */ export interface NoulCriteria { true: string; false: string; } /** * A single typed question against a state — the shape that crosses the wire * and the shape screening validates. Written with `check` / `pick` / `rate` * rather than by hand. */ export interface Question { /** Caller-assigned id, echoed back in the verdict. Defaults to `q`. */ id?: string; type: QuestionType; /** The question text, e.g. "Did the test suite pass?" */ question: string; /** choice only: >= 2 options — labels, or label → meaning. */ options?: string[] | Record; /** score only: >= 2 ordered level descriptions, worst-to-best or any fixed order. */ levels?: string[]; /** noul only (optional): what a yes and a no mean, to sharpen calibration. */ criteria?: NoulCriteria; } /** "Is this true?" — the verdict answers with P(yes) in [0, 1]. Built by `check`. */ export interface NoulQuestion extends Question { type: "noul"; } /** * "Which one?" — the verdict answers with one of the option labels. Built by * `pick`, which infers `Label` from the options you pass, so the answer is * typed as exactly those labels. */ export interface ChoiceQuestion