/** * Copyright (c) 2026, Salesforce, Inc., * All rights reserved. * For full license text, see the LICENSE.txt file */ /** * CLI mirror commands — one entry per MCP tool. Each binds a Zod input schema * to the matching `intent/build*()` function; all the real logic lives in * `runMirror` (`run-mirror.ts`). The commands are siblings of the MCP tools: same * args, same output, different transport. * * The bindings are data, not bespoke functions — `cli.ts` registers them in a * loop and the tests iterate them, so adding a tool is one `defineMirror(...)` * line here. */ import { type z } from "zod"; import { runMirror } from "./run-mirror.js"; import { buildAggregate } from "../../intent/build-aggregate.js"; import { buildConnect } from "../../intent/build-connect.js"; import { buildCreate } from "../../intent/build-create.js"; import { buildDelete } from "../../intent/build-delete.js"; import { buildDetail } from "../../intent/build-detail.js"; import { buildDiscover } from "../../intent/build-discover.js"; import { buildList } from "../../intent/build-list.js"; import { buildRaw } from "../../intent/build-raw.js"; import { buildUpdate } from "../../intent/build-update.js"; import { AGGREGATE_INPUT, CONNECT_INPUT, CREATE_INPUT, DELETE_INPUT, DETAIL_INPUT, DISCOVER_INPUT, LIST_INPUT, RAW_INPUT, UPDATE_INPUT, } from "../../schemas/input-schemas.js"; /** A single CLI mirror command: its subcommand name, help summary, and runner. */ export interface MirrorCommand { /** CLI subcommand name, e.g. "sf-gql-list", matching the MCP tool's `sf_gql_*`. */ name: string; /** One-line `--help` summary. */ summary: string; /** Read JSON (positional arg or stdin), validate, build, emit one JSON line. */ run: (jsonArg?: string) => Promise; } /** * Bind a schema to its builder behind a uniform `run`. The generic `T` is * captured here, at construction, where the schema and builder types still line * up — so {@link MIRRORS} can be a single homogeneous array without forcing the * builders through an `unknown` parameter (which would fail by contravariance). */ function defineMirror( name: string, summary: string, // Input type is `unknown`, not `T`: the schema validates a raw parsed-JSON // blob, and some fields wrap the value in a `z.preprocess` (jsonCoercible, // enumStripControlChars) whose Zod input type is `unknown`. Only the OUTPUT // must be `T`. Pinning the input to `T` (the default `z.ZodType`) would // reject those preprocess-wrapped schemas. schema: z.ZodType, build: (input: T) => Promise, ): MirrorCommand { return { name, summary, run: (jsonArg) => runMirror(jsonArg, schema, build) }; } /** Every CLI mirror command. Single source of truth for `cli.ts` and the tests. */ export const MIRRORS: MirrorCommand[] = [ defineMirror("sf-gql-list", "Build a UIAPI list query.", LIST_INPUT, buildList), defineMirror("sf-gql-detail", "Build a single-record detail query.", DETAIL_INPUT, buildDetail), defineMirror("sf-gql-discover", "Discover UIAPI schema metadata.", DISCOVER_INPUT, buildDiscover), defineMirror( "sf-gql-aggregate", "Build a UIAPI aggregate query.", AGGREGATE_INPUT, buildAggregate, ), defineMirror( "sf-gql-raw", "Build an arbitrary query from CLI-style commands.", RAW_INPUT, buildRaw, ), defineMirror("sf-gql-create", "Build a UIAPI create mutation.", CREATE_INPUT, buildCreate), defineMirror("sf-gql-update", "Build a UIAPI update mutation.", UPDATE_INPUT, buildUpdate), defineMirror("sf-gql-delete", "Build a UIAPI delete mutation.", DELETE_INPUT, buildDelete), defineMirror( "sf-gql-connect", "Prime/refresh an org's schema cache.", CONNECT_INPUT, buildConnect, ), ];