mirror of
https://github.com/morluto/rea.git
synced 2026-11-17 04:04:25 +00:00
Run ordinary CLI commands through REA's registry, argv parser and result owner. Remove Incur, the second admission parse, SDK error middleware, output capture and redundant command traversal. Preserve explicit redaction, publication receipts, incremental output, terminal notice eligibility and drain ownership. Migrate fixtures to real registrations and retain the derived-source notices. Validation includes unchanged public parity goldens, public and lifecycle regressions, repaired fixture consumers, real TTY base comparisons, exports beyond the engine string limit, four schema catalogs and final static/docs checks. Native provider and optional validator coverage limits are in the PR. Fixes #11654. Fixes #10583. Refs #11682, #11476 and #10511. BREAKING CHANGE: Markdown argument diagnostics use REA's literal escaping, table widths and token counts. Flag-shaped unknown MCP subcommands honor the selected format. Completion --schema/--version routes use the canonical REA-owned hook rather than the retired SDK generator. Refresh affected literal snapshots and regenerate completion hooks with rea completions <shell>. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { jsonDocumentText } from "../domain/schemaConstraints.js";
|
|
|
|
const JSON_SCHEMA_DIALECT = "$schema";
|
|
const wrapperTypes = new Set([
|
|
"optional",
|
|
"nonoptional",
|
|
"nullable",
|
|
"default",
|
|
"prefault",
|
|
"readonly",
|
|
"catch",
|
|
]);
|
|
|
|
const innerSchema = (schema: z.ZodType): z.ZodType | undefined => {
|
|
if (!("unwrap" in schema) || typeof schema.unwrap !== "function")
|
|
return undefined;
|
|
const inner: unknown = schema.unwrap();
|
|
return inner instanceof z.ZodType ? inner : undefined;
|
|
};
|
|
|
|
/** Skip wrappers so `unknown` and `any` are recognized as the whole document. */
|
|
const documentType = (schema: z.ZodType): string => {
|
|
let current = schema;
|
|
for (;;) {
|
|
const type = current._zod.def.type;
|
|
if (!wrapperTypes.has(type)) return type;
|
|
const inner = innerSchema(current);
|
|
if (inner === undefined) return type;
|
|
current = inner;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* JSON Schema for one positional JSON document.
|
|
*
|
|
* `{}` is only returned for a document the handler parses as `unknown` or
|
|
* `any`. Any other empty conversion is omitted: a custom or unrepresentable
|
|
* document must not be advertised as accepting every value. Input mode keeps
|
|
* the type a transform accepts, so a string transform stays a string.
|
|
*/
|
|
export const jsonInputContentSchema = (
|
|
schema: z.ZodType,
|
|
): Record<string, unknown> | undefined => {
|
|
let converted: Record<string, unknown>;
|
|
try {
|
|
converted = z.toJSONSchema(schema, {
|
|
io: "input",
|
|
unrepresentable: "any",
|
|
}) as Record<string, unknown>;
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
const content = { ...converted };
|
|
delete content[JSON_SCHEMA_DIALECT];
|
|
if (Object.keys(content).length > 0) return content;
|
|
const type = documentType(schema);
|
|
return type === "unknown" || type === "any" ? {} : undefined;
|
|
};
|
|
|
|
/** Keep the positional string and attach the document contract the CLI advertises. */
|
|
export const jsonInputArgument = (
|
|
description: string,
|
|
schema: z.ZodType,
|
|
): z.ZodString => {
|
|
return jsonDocumentText(
|
|
z.string().describe(description),
|
|
jsonInputContentSchema(schema),
|
|
);
|
|
};
|