fix(contracts): preserve local inputs and comparison uncertainty

This commit is contained in:
morluto
2026-10-09 06:49:02 +08:00
parent 7a7460f04f
commit 70e8a8f860
35 changed files with 460 additions and 386 deletions
+18 -5
View File
@@ -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({