Every configuration failure projected the same message, "REA configuration is invalid. Run `rea doctor` and fix the reported setting.", with no details. The environment parser discarded the issue that names the variable (for example `REA_GHIDRA_NATIVEAOT_JAR must be absolute`), and doctor can report healthy for that environment, so neither the CLI, the MCP startup message, nor doctor told callers which setting to correct. ConfigurationError now carries the rejected settings and their constraints (never their values). The projection names them in its message, lists them in `details.settings`, and asks the caller to correct those settings where REA is started. Errors without a named setting keep the previous message. Fixes #1184 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { ConfigurationError } from "../domain/configurationErrors.js";
|
|
import { err, ok, type Result } from "../domain/result.js";
|
|
|
|
// This override supports clients with larger frames. Keep the configuration
|
|
// parser independent of the SDK's eager server imports; conformance verifies
|
|
// this floor against the pinned SDK's actual default receive-buffer size.
|
|
const MINIMUM_RESPONSE_BYTES = 10 * 1024 * 1024;
|
|
|
|
/** Optional stdio response budget, including room for the protocol envelope. */
|
|
export const mcpResponseBudgetSchema = z
|
|
.string()
|
|
.regex(/^[1-9]\d*$/u)
|
|
.transform(Number)
|
|
.pipe(z.number().int().safe().min(MINIMUM_RESPONSE_BYTES));
|
|
|
|
const budgetConstraint = `REA_MCP_MAX_RESPONSE_BYTES must be a decimal safe integer at least ${String(MINIMUM_RESPONSE_BYTES)} bytes, the default stdio receive-buffer size.`;
|
|
|
|
/** Parse only the MCP-specific budget without loading unrelated provider settings. */
|
|
export const parseMcpResponseBudget = (
|
|
value: string | undefined,
|
|
): Result<number | undefined, ConfigurationError> => {
|
|
if (value === undefined) return ok(undefined);
|
|
const parsed = mcpResponseBudgetSchema.safeParse(value);
|
|
return parsed.success
|
|
? ok(parsed.data)
|
|
: err(
|
|
new ConfigurationError(budgetConstraint, {
|
|
settings: [
|
|
{
|
|
setting: "REA_MCP_MAX_RESPONSE_BYTES",
|
|
constraint: budgetConstraint,
|
|
},
|
|
],
|
|
}),
|
|
);
|
|
};
|