refactor(cli): share discovery failure answers (#16580)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-04 12:22:24 +08:00
1 parent 6dee08cdd1
commit b701cd35ee
1 file changed
+33 -39
+33 -39
View File
@@ -164,6 +164,9 @@ const renderedAnswer = (text: string, exitCode = 0): DiscoveryAnswer => ({
text,
exitCode,
});
const failureAnswer = (
...inputs: Parameters<typeof renderFailure>
): DiscoveryAnswer => renderedAnswer(renderFailure(...inputs), 1);
const markupAnswer = (text: string): DiscoveryAnswer => ({
kind: "markup",
text,
@@ -268,14 +271,11 @@ const schemaAnswer = (
return answer(`Error: ${failure.message}`, 1);
// A selected format receives the same structured diagnostic as any
// other unknown command, not terminal text.
return renderedAnswer(
renderFailure(
failure,
{ command, duration: `${Math.round(performance.now() - started)}ms` },
cta,
cliFailurePresentation(controls, false),
),
1,
return failureAnswer(
failure,
{ command, duration: `${Math.round(performance.now() - started)}ms` },
cta,
cliFailurePresentation(controls, false),
);
}
if (!validation.ok)
@@ -321,28 +321,25 @@ const retiredMcpAnswer = (
const controls = readCliOutputArguments(global);
const sensitive = declaredSensitiveValues(global.command);
const text = (value: string): string => redactExplicitText(value, sensitive);
return renderedAnswer(
renderFailure(
{
code: "MCP_MODE_REMOVED",
message: text(
`Per-command --mcp has been removed. Use '${cli.name} mcp' to start REA's MCP server.`,
),
},
{
command: text(global.command[0] ?? cli.name),
duration: `${Math.round(performance.now() - invocation.started)}ms`,
},
{
description: text("Suggested command:"),
commands: [{ command: text(`${cli.name} mcp`) }],
},
cliFailurePresentation(
controls,
invocation.stdoutIsTerminal && !controls.formatExplicit,
return failureAnswer(
{
code: "MCP_MODE_REMOVED",
message: text(
`Per-command --mcp has been removed. Use '${cli.name} mcp' to start REA's MCP server.`,
),
},
{
command: text(global.command[0] ?? cli.name),
duration: `${Math.round(performance.now() - invocation.started)}ms`,
},
{
description: text("Suggested command:"),
commands: [{ command: text(`${cli.name} mcp`) }],
},
cliFailurePresentation(
controls,
invocation.stdoutIsTerminal && !controls.formatExplicit,
),
1,
);
};
@@ -379,17 +376,14 @@ const unknownCommandAnswer = (
suggestion,
additionalCommands: notice,
});
return renderedAnswer(
renderFailure(
failure,
{
command,
duration: `${Math.round(performance.now() - started)}ms`,
},
cta,
cliFailurePresentation(controls, human, selectedFormat),
),
1,
return failureAnswer(
failure,
{
command,
duration: `${Math.round(performance.now() - started)}ms`,
},
cta,
cliFailurePresentation(controls, human, selectedFormat),
);
};