/** * Copyright (c) 2026, Salesforce, Inc., * All rights reserved. * For full license text, see the LICENSE.txt file */ import { type z } from "zod"; /** * Shared adapter for the `sf-gql-*` CLI mirror commands. Each command reads a * JSON blob (positional arg or stdin), validates it against the same Zod schema * the matching MCP tool advertises, calls the same `intent/build*()` function * the MCP tool calls, and emits exactly one JSON line on stdout. This keeps the * CLI a sibling adapter to the MCP server — same args, same output, different * transport. * * Failures emit a JSON error envelope and set `process.exitCode = 1`. We use * `process.exitCode` rather than `process.exit()` so the buffered stdout write * has time to flush before the process ends. */ /** Error codes surfaced in the failure envelope. */ export type MirrorErrorCode = "INVALID_ARGS" | "AUTH_FAILED" | "SCHEMA_PRIME_FAILED" | "INTERNAL"; export interface MirrorErrorEnvelope { error: { code: MirrorErrorCode; message: string; details?: unknown; }; } export interface RunMirrorDeps { /** Read the full JSON payload from stdin. Injectable for tests. */ readStdin?: () => Promise; /** Whether stdin is a TTY. When true and no arg is given, we don't block on stdin. */ isTTY?: boolean; } /** * Run one mirror command end-to-end. * * @param jsonArg Positional JSON argument, or undefined to read from stdin. * @param schema The tool's Zod input schema (shared with the MCP tool). * @param build The intent-layer builder; receives the validated input. * @param deps Injectable stdin reader / TTY flag for testing. */ export declare function runMirror(jsonArg: string | undefined, schema: z.ZodType, build: (input: T) => Promise, deps?: RunMirrorDeps): Promise;