Skip to content

API

passMuster(options) → Promise<PassMusterResult<T>>

Section titled “passMuster(options) → Promise<PassMusterResult<T>>”
OptionTypeDefaultDescription
generate(args: { attempt: number; feedback?: Feedback }) => T | Promise<T>Produce a candidate. Called once per attempt.
checksCheck<T>[]Verifiers every candidate must pass.
maxAttemptsnumber3Max generate attempts.
stopOnFirstFailurebooleanfalseStop checking at the first failure each attempt.
throwOnFailbooleanfalseThrow PassMusterError instead of returning { ok: false }.
onAttempt(attempt: Attempt<T>) => voidCalled after each attempt.

Returns PassMusterResult<T>:

interface PassMusterResult<T> {
ok: boolean; // true when an attempt passed every check
value: T; // the passing value, or the last attempt's value
attempts: Attempt<T>[]; // full trail
usedAttempts: number;
}
interface Attempt<T> {
attempt: number; // 1-based
value: T;
failures: { check: string; message: string }[];
passed: boolean;
}
function check<T>(
name: string,
fn: (value: T, ctx: { attempt: number }) => CheckResult | Promise<CheckResult>,
): Check<T>;
type CheckResult = true | string | { message: string; [key: string]: unknown };
function schemaCheck<T>(schema: StandardSchemaLike, name?: string): Check<T>;

Accepts any Standard Schema (Zod, Valibot, ArkType). Reports schema issues (with paths) as the failure reason.

function judge<T>(name: string, options: {
ask: (value: T) => string;
complete: (prompt: string) => string | Promise<string>;
interpret?: (response: string) => CheckResult; // default: PASS/FAIL parsing
}): Check<T>;
import { buildFeedback, toMessage, PassMusterError } from "passmuster";
buildFeedback(failures); // → { failures, text } — for custom retry loops
toMessage(result); // normalize a failing CheckResult to a string
// thrown when throwOnFail is set and no attempt passed
catch (err) {
if (err instanceof PassMusterError) console.log(err.attempts);
}

Check, CheckContext, CheckResult, Failure, Feedback, GenerateArgs, Attempt, PassMusterResult, PassMusterOptions, JudgeOptions, and StandardSchemaLike are all exported.