fix(contracts): align CLI/MCP boundary contracts (#946)
* fix(cli): validate native scenario and preserve JSON paths * fix(process): reject invalid UTF-8 JSON inputs * fix(cli): retain missing JSON path diagnostics * test(cli): cover relative brace and bracket JSON paths * test(cli): reject missing native scenario steps * fix(mcp): advertise reserved process environment key * fix(process): reject NUL in process scenario values * fix(process): advertise NUL input constraints to MCP * fix(cli): report scenario input schema issues * fix(contracts): align CLI and MCP input validation * fix(mcp): document semantic output constraints * fix(mcp): describe process journal compatibility * docs: regenerate catalog after schema grouping * docs: regenerate catalog after main merge * fix(cli): preserve JSON and native UI input diagnostics * test(mcp): reuse advertised tool schemas in managed flow
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
import { electronActiveObservationInputSchema } from "../domain/javascript/electronActiveObservation.js";
|
||||
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { projectInputIssues } from "../domain/inputIssueProjection.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||
@@ -58,7 +59,12 @@ const registerElectronActiveCommand = (
|
||||
const parsed = electronActiveObservationInputSchema.safeParse(
|
||||
input.value,
|
||||
);
|
||||
if (!parsed.success) return inputError("capture_electron_scenario");
|
||||
if (!parsed.success)
|
||||
return inputError(
|
||||
"capture_electron_scenario",
|
||||
parsed.error.issues,
|
||||
input.value,
|
||||
);
|
||||
const { createElectronScenarioProvider } =
|
||||
await import("../composition/electronScenario.js");
|
||||
const result = await captureElectronScenario(
|
||||
@@ -186,8 +192,18 @@ const electronObservationContext = async () => {
|
||||
return { provider: createElectronObservationProvider() };
|
||||
};
|
||||
|
||||
const inputError = (operation: string): JsonValue =>
|
||||
cliError(new AnalysisInputError(operation));
|
||||
const inputError = (
|
||||
operation: string,
|
||||
issues?: Parameters<typeof projectInputIssues>[0],
|
||||
input?: unknown,
|
||||
): JsonValue =>
|
||||
cliError(
|
||||
new AnalysisInputError(
|
||||
operation,
|
||||
undefined,
|
||||
issues === undefined ? [] : projectInputIssues(issues, input),
|
||||
),
|
||||
);
|
||||
|
||||
const cliError = (
|
||||
error: Parameters<typeof projectAnalysisError>[0],
|
||||
|
||||
+52
-23
@@ -1,5 +1,4 @@
|
||||
import { z } from "incur";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
|
||||
import {
|
||||
runCapabilityStatus,
|
||||
@@ -10,6 +9,10 @@ import { importReferenceSource } from "../application/ReferenceSourceImport.js";
|
||||
import { projectReferenceSourceImportError } from "../application/ReferenceSourceImportTypes.js";
|
||||
import { parseConfig } from "../config.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
|
||||
import { projectInputIssues } from "../domain/inputIssueProjection.js";
|
||||
import { safeParseJson } from "../domain/safeJson.js";
|
||||
import { nativeUiScenarioInputSchema } from "../domain/native/nativeUiObservation.js";
|
||||
import { PRODUCT_IDENTITY } from "../identity.js";
|
||||
import { logCliCommand } from "../cliLogging.js";
|
||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||
@@ -67,33 +70,59 @@ export const registerUtilityCommands = (
|
||||
maxNodes: "max-nodes",
|
||||
},
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, command, () =>
|
||||
runProviderAnalysis(
|
||||
args.path,
|
||||
operation,
|
||||
{
|
||||
pid: options.pid,
|
||||
window_id: options.windowId,
|
||||
screenshot: options.screenshot,
|
||||
accessibility: options.accessibility,
|
||||
max_nodes: options.maxNodes,
|
||||
...(operation === "capture_native_ui_scenario"
|
||||
? {
|
||||
steps:
|
||||
options.steps === undefined
|
||||
? []
|
||||
: jsonValueSchema.parse(JSON.parse(options.steps)),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
logger,
|
||||
),
|
||||
),
|
||||
logCliCommand(logger, command, async () => {
|
||||
const parameters = {
|
||||
pid: options.pid,
|
||||
window_id: options.windowId,
|
||||
screenshot: options.screenshot,
|
||||
accessibility: options.accessibility,
|
||||
max_nodes: options.maxNodes,
|
||||
};
|
||||
if (operation === "capture_native_ui_scenario") {
|
||||
const decoded =
|
||||
options.steps === undefined
|
||||
? { ok: true as const, value: undefined }
|
||||
: safeParseJson(options.steps);
|
||||
if (!decoded.ok)
|
||||
return invalidNativeUiScenarioInput(operation, [
|
||||
{ path: ["steps"], reason: "invalid_format", expected: "JSON" },
|
||||
]);
|
||||
const parsed = nativeUiScenarioInputSchema.safeParse({
|
||||
...parameters,
|
||||
steps: decoded.value,
|
||||
});
|
||||
if (!parsed.success)
|
||||
return invalidNativeUiScenarioInput(
|
||||
operation,
|
||||
projectInputIssues(parsed.error.issues, {
|
||||
...parameters,
|
||||
...(options.steps === undefined
|
||||
? {}
|
||||
: { steps: decoded.value }),
|
||||
}),
|
||||
);
|
||||
return runProviderAnalysis(
|
||||
args.path,
|
||||
operation,
|
||||
parsed.data,
|
||||
logger,
|
||||
);
|
||||
}
|
||||
return runProviderAnalysis(args.path, operation, parameters, logger);
|
||||
}),
|
||||
});
|
||||
}
|
||||
registerReferenceSourceCommand(cli, logger, environment);
|
||||
};
|
||||
|
||||
const invalidNativeUiScenarioInput = (
|
||||
operation: string,
|
||||
issues: ConstructorParameters<typeof AnalysisInputError>[2],
|
||||
) => ({
|
||||
error: "Application workflow failed",
|
||||
...projectAnalysisError(new AnalysisInputError(operation, undefined, issues)),
|
||||
});
|
||||
|
||||
const registerCapabilityCommands = (cli: CliInstance, logger: Logger): void => {
|
||||
for (const command of [
|
||||
CLI_COMMANDS.capabilities,
|
||||
|
||||
Reference in New Issue
Block a user