/** * Self-improvement scenario + golden fixture loading and validation (T11889-B). * * A *scenario* is a deterministic, ordered sequence of READ-ONLY dispatch ops * (the GRADE-playbook shape — see `docs/specs/GRADE-SCENARIO-PLAYBOOK.md`) paired * with a *golden* envelope set: the known-good, already-normalized response for * each op. The self-improvement loop replays the ops (see {@link "./replay.js"}) * and diffs the captured envelopes against the golden (see * {@link "./envelope-diff.js"}); any deviation is a regression. * * This module is PURE — no DB, no native handle, no `cleo` mutation. Scenario and * golden fixtures are stored under * `packages/core/src/selfimprove/scenarios//{scenario,golden}.json` and loaded * by {@link loadScenario}, which Zod-validates both files before returning. * * Import-time side-effect-free: the logger is resolved lazily on first use. * * @module @cleocode/core/selfimprove/scenario * @epic T11889 * @task T11912 */ import { z } from 'zod'; /** * Zod schema for a single scenario op. * * An op is a dispatch coordinate: the CQRS `gateway`, the REGISTERED handler * `domain` key (e.g. `'tasks'`, plural — NOT the singular CLI noun), the * `operation` name, and optional `params`. The skeleton's canned scenario is * `query`-only, so replaying it performs zero mutations. */ export declare const ScenarioOpSchema: z.ZodObject<{ gateway: z.ZodEnum<{ query: "query"; mutate: "mutate"; }>; domain: z.ZodString; operation: z.ZodString; params: z.ZodOptional>; }, z.core.$strict>; /** A single ordered, replayable scenario op. */ export type ScenarioOp = z.infer; /** * Zod schema for a scenario file (`scenario.json`). * * A scenario is a named, described, ordered op sequence. `ops` must be non-empty * so a scenario always replays at least one op. */ export declare const ScenarioSchema: z.ZodObject<{ name: z.ZodString; description: z.ZodString; ops: z.ZodArray; domain: z.ZodString; operation: z.ZodString; params: z.ZodOptional>; }, z.core.$strict>>; }, z.core.$strict>; /** A validated scenario: a named, ordered, read-only op sequence. */ export type Scenario = z.infer; /** * Zod schema for one entry in a golden file. * * A golden entry is the already-normalized expected envelope for the op at the * same index in the scenario's `ops`. Stored as a structural shape (volatile * `meta` fields already stripped); validated loosely here because the structural * comparison happens in {@link "./envelope-diff.js"}, not at load time. */ export declare const GoldenEntrySchema: z.ZodObject<{ success: z.ZodBoolean; data: z.ZodOptional; error: z.ZodOptional; meta: z.ZodOptional>; }, z.core.$loose>; /** A validated golden entry — the expected normalized envelope for one op. */ export type GoldenEntry = z.infer; /** * Zod schema for a golden file (`golden.json`). * * The golden is the ordered set of expected normalized envelopes, ONE per * scenario op. {@link loadScenario} enforces that `golden.length === scenario.ops.length`. */ export declare const GoldenSchema: z.ZodObject<{ name: z.ZodString; envelopes: z.ZodArray; error: z.ZodOptional; meta: z.ZodOptional>; }, z.core.$loose>>; }, z.core.$strict>; /** A validated golden envelope set. */ export type Golden = z.infer; /** * A loaded scenario together with its golden envelope set. * * Returned by {@link loadScenario}. Guarantees: both files Zod-valid, the golden * name matches the scenario name, and the golden envelope count equals the * scenario op count. */ export interface LoadedScenario { /** The validated scenario (ordered ops). */ scenario: Scenario; /** The validated golden envelope set (positionally aligned with `scenario.ops`). */ golden: Golden; } /** Thrown when a scenario name is malformed or a fixture is missing / invalid. */ export declare class ScenarioLoadError extends Error { /** Stable machine-readable error code. */ readonly code: "E_SELFIMPROVE_SCENARIO_INVALID"; /** * @param message - Human-readable failure description. * @param options - Optional `cause` for error chaining. */ constructor(message: string, options?: { cause?: unknown; }); } /** * Load and validate a scenario and its golden fixture by name. * * Reads `scenarios//scenario.json` and `scenarios//golden.json`, * Zod-validates both, and cross-checks the invariants: * - the scenario name matches the requested `name`; * - the golden name matches the scenario name; * - the golden envelope count equals the scenario op count. * * PURE — no DB, no mutation. Read-only filesystem access to the bundled fixtures. * * @param name - Scenario name (also the fixture directory name). Must match * {@link SCENARIO_NAME_PATTERN}. * @returns The validated {@link LoadedScenario}. * @throws {@link ScenarioLoadError} When the name is malformed, a fixture is * missing/invalid, or an invariant is violated. * * @example * ```ts * const { scenario, golden } = await loadScenario('dhq-replay-find'); * // scenario.ops.length === golden.envelopes.length * ``` */ export declare function loadScenario(name: string): Promise; //# sourceMappingURL=scenario.d.ts.map