fix(contracts): preserve local inputs and comparison uncertainty
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import type { ServerContext } from "@modelcontextprotocol/server";
|
||||
import { setImmediate } from "node:timers/promises";
|
||||
import { z } from "zod";
|
||||
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisInputError,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import { describeValidationFailure } from "../domain/evidenceBundle.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { mcpProgressReporter, type McpProgressContext } from "./mcpProgress.js";
|
||||
|
||||
@@ -18,7 +21,7 @@ export const runDerivedOperation = async <Value>(
|
||||
context: DerivedOperationContext,
|
||||
operation: string,
|
||||
compute: () => Value,
|
||||
): Promise<Result<Value, AnalysisCancelledError | AnalysisInputError>> => {
|
||||
): Promise<Result<Value, AnalysisError>> => {
|
||||
const progress = mcpProgressReporter(context);
|
||||
await progress.report({
|
||||
phase: "prepare",
|
||||
@@ -34,11 +37,21 @@ export const runDerivedOperation = async <Value>(
|
||||
value = compute();
|
||||
} catch (cause: unknown) {
|
||||
// Typed causes already name the failed constraint; keep their issues.
|
||||
if (cause instanceof AnalysisError) return err(cause);
|
||||
return err(
|
||||
cause instanceof AnalysisCancelledError ||
|
||||
cause instanceof AnalysisInputError
|
||||
? cause
|
||||
: new AnalysisInputError(operation, { cause }),
|
||||
new AnalysisInputError(
|
||||
operation,
|
||||
{ cause },
|
||||
cause instanceof TypeError || cause instanceof z.ZodError
|
||||
? [
|
||||
{
|
||||
path: [],
|
||||
reason: "invalid_value",
|
||||
message: describeValidationFailure(cause),
|
||||
},
|
||||
]
|
||||
: [],
|
||||
),
|
||||
);
|
||||
}
|
||||
await progress.report({
|
||||
|
||||
Reference in New Issue
Block a user