/** * The runtime shape of the JSON envelope `peaks … --json` writes to stdout. * * WHY THIS EXISTS (S12, 2026-09-20). The CLI envelope was the single largest * cluster of unvalidated `JSON.parse` in the repo: 21 test files do * `JSON.parse(.stdout)` and then read `out.ok` / `out.code` / * `out.data.*`. Because `JSON.parse` returns `any`, none of those reads was * checked against anything, and each one is a `no-unsafe-*` finding. Measured * at the S12 census: ~196 of the ~448 findings in the R1 root. * * WHAT IS VALIDATED, AND WHAT IS NOT — stated plainly, because the difference * is the whole point. The envelope HEAD is always validated: `ok` must be a * boolean; `warnings` / `nextActions`, when present, arrays of strings; `code` * / `message` / `errorId`, when present, strings. The PAYLOAD (`data`) is * validated only as "a JSON object with string keys" — there is no single * payload schema, because `data` is `T` in `ResultEnvelope` and every * command has its own shape. That is a measured finding of S12, not an * oversight: R1 does not collapse onto one schema. * * A caller that reads `data.` at depth >= 2 therefore names the payload * shape itself, through the same validating primitive: * * parseCliEnvelopeWith(raw, EvolutionStatusPayload) * * The alternative — one generic helper with a type parameter and no schema — * is the `as T` costume S12 forbids. Here the type parameter is a SCHEMA, so * the returned type is derived from a check that actually ran. */ import { z } from 'zod'; declare const baseEnvelopeSchema: z.ZodObject<{ ok: z.ZodBoolean; command: z.ZodOptional; data: z.ZodRecord; warnings: z.ZodOptional>; nextActions: z.ZodOptional>; code: z.ZodOptional; message: z.ZodOptional; errorId: z.ZodOptional; }, z.core.$loose>; /** * Build the envelope schema with a payload schema — for the callers that read * `data.` at depth >= 2 and can say what they expect there. */ export declare function cliEnvelopeSchema(payload: S): z.ZodObject<{ ok: z.ZodBoolean; command: z.ZodOptional; data: S; warnings: z.ZodOptional>; nextActions: z.ZodOptional>; code: z.ZodOptional; message: z.ZodOptional; errorId: z.ZodOptional; }, z.core.$loose>; /** * `ok` + `data` (any JSON object) + the optional head fields. */ export type CliEnvelope = z.infer; /** * Parse a CLI stdout envelope, validating the head. Throws when the text is * not JSON, or is JSON that is not an envelope — a caller that fed this * something else wants to know, not to read `undefined.ok` further down. */ export declare function parseCliEnvelope(raw: string): CliEnvelope; /** * Parse a CLI stdout envelope for a caller that reads `data.` at depth * >= 2, validating that field's own shape as well. The caller names the shape; * nothing is asserted on its behalf. */ export declare function parseCliEnvelopeWith(raw: string, payload: S): ({ ok: z.ZodBoolean; command: z.ZodOptional; data: S; warnings: z.ZodOptional>; nextActions: z.ZodOptional>; code: z.ZodOptional; message: z.ZodOptional; errorId: z.ZodOptional; } extends infer T_1 extends z.core.$ZodLooseShape ? { -readonly [k in keyof T_1 as { ok: z.ZodBoolean; command: z.ZodOptional; data: S; warnings: z.ZodOptional>; nextActions: z.ZodOptional>; code: z.ZodOptional; message: z.ZodOptional; errorId: z.ZodOptional; }[k] extends { _zod: { optout: "optional"; }; } ? never : k]: T_1[k]["_zod"]["output"]; } : never) & ({ ok: z.ZodBoolean; command: z.ZodOptional; data: S; warnings: z.ZodOptional>; nextActions: z.ZodOptional>; code: z.ZodOptional; message: z.ZodOptional; errorId: z.ZodOptional; } extends infer T_2 extends z.core.$ZodLooseShape ? { -readonly [k_1 in keyof T_2 as { ok: z.ZodBoolean; command: z.ZodOptional; data: S; warnings: z.ZodOptional>; nextActions: z.ZodOptional>; code: z.ZodOptional; message: z.ZodOptional; errorId: z.ZodOptional; }[k_1] extends { _zod: { optout: "optional"; }; } ? k_1 : never]?: T_2[k_1]["_zod"]["output"]; } : never) & Record extends infer T ? { [K in keyof T]: T[K]; } : never; export {};