/** * deriveOutputContract — generic per-operation OUTPUT contract producer. * * Closes the COVERAGE half of DHQ-057 / T11692 (the symptom-fix half — the * `--field` remediation loop — is ST-4). The hand-authored {@link OUTPUT_CONTRACTS} * registry covers only the 7 highest-traffic `tasks.*` operations. Every other * operation in the 411-row {@link OPERATIONS} registry has NO machine-readable * description of its result `data` shape, so an agent asking `cleo * --describe` (or hitting `E_FIELD_NOT_FOUND` on a bad `--field` pointer) gets * nothing back for ~404 ops. * * Rather than hand-write 404 more contracts (unmaintainable, drifts instantly), * this module DERIVES an {@link OperationOutputContract} for an operation from * three shape registries that ALREADY exist: * * | Source registry | Home | Derives | * |------------------------|--------------------------|----------------------------------------------------------| * | {@link OPERATION_RESULT_SCHEMAS} | `@cleocode/contracts` | precise top-level data keys for the 5 workgraph reads | * | {@link PROJECTION_PLANS} | `./mvi-projection.js` | the data PATH (`tasks.show→task`, `docs.list→attachments`) for projected reads | * | {@link MUTATE_PROJECTION_PLANS} | `./mutate-projection.js` | the shared `{count, created, updated, deleted}` shape — but ONLY for the 6 ops that actually project it | * * Resolution precedence inside {@link deriveOutputContract} (most-precise first): * * 1. workgraph result schema → precise key-derived contract * 2. read op with projection plan → path-rooted contract * 3. mutate op WITH a {@link MUTATE_PROJECTION_PLANS} entry → shared * minimal-mutate contract. An unplanned `gateway==='mutate'` op is NOT * rewritten by the dispatch middleware (it returns its raw domain payload), * so it must NOT advertise `/data/created/0` — it falls through to (4). * 4. any other registered op (unplanned mutate or plain query) → a GENERIC * object contract (data is an object; no specific `--field` pointers, but a * `shapeNote` telling the agent to `--full`/`--describe`). * * A `null` return means the operation is NOT in {@link OPERATIONS} at all * (genuinely unknown). Per T10400 §6.3 R6.7 a `null` output contract is * "unverified shape", NEVER an error — callers MUST treat it as absent, not * throw. * * ## Boundary * * This producer lives in `core/src/dispatch` (NOT `contracts`) because it reads * `PROJECTION_PLANS` / `MUTATE_PROJECTION_PLANS`, which are core-resident, and * because it is a bodied runtime helper (the contracts-purity Gate 10 forbids * net-new bodied functions in `contracts`). It is import-time side-effect-free: * it builds nothing at module load, only on call. * * @packageDocumentation * @module @cleocode/core/dispatch/contracts/derive-output-contract * * @epic T11679 * @task T11762 ST-3 — DHQ-057: generic per-op output schema coverage backfill */ import { type OperationOutputContract } from '@cleocode/contracts'; /** * Derive an {@link OperationOutputContract} for an operation from the existing * shape registries, or `null` when the operation is genuinely unknown. * * Used as the SECOND tier of {@link getOutputContract}'s resolution order * (hand-authored {@link OUTPUT_CONTRACTS} → `deriveOutputContract` → `null`). * The hand-authored 7 stay authoritative; this lifts coverage to near-100% for * the remaining ~404 ops without hand-authoring sprawl. * * Resolution precedence (most-precise first): workgraph result schema → * projection-plan read → planned mutate op → generic registered op (unplanned * mutate or plain query) → `null`. * * A `null` return MUST be treated as "no contract / unverified shape", NOT an * error (T10400 §6.3 R6.7). * * @param operation - Canonical `.` operation identifier. * @returns A derived contract, or `null` when the operation is not registered. * * @example * ```ts * deriveOutputContract('tasks.tree'); // precise workgraph keys * deriveOutputContract('tasks.show'); // projection-plan path (`task`) * deriveOutputContract('tasks.add'); // shared minimal-mutate envelope (planned) * deriveOutputContract('memory.observe'); // generic object (UNPLANNED mutate) * deriveOutputContract('session.start'); // generic object contract * deriveOutputContract('does.not-exist'); // null * ``` * * @task T11762 ST-3 */ export declare function deriveOutputContract(operation: string): OperationOutputContract | null; //# sourceMappingURL=derive-output-contract.d.ts.map