refactor(mcp): make analysis states unrepresentable (#468)
* refactor(config): parse capability settings into exact states * refactor(runtime): encode replay and process outcomes exactly * refactor: make analysis states unrepresentable * refactor(mcp): register canonical schemas with SDK * fix: preserve capability and catalog invariants * fix(build): remove stale compiled modules * fix(replay): update real verifier policy dependency * fix(package): verify the complete MCP catalog * fix(test): supply complete replay reload policy * refactor(contracts): centralize output schema lookup * refactor(mcp): delegate protocol boundaries to SDK * fix(browser): approve real source capture * fix(mcp): preserve catalog guidance
This commit is contained in:
@@ -5,6 +5,7 @@ import type { ToolContract } from "./toolContracts.js";
|
||||
import { artifactOutputSchemas } from "./toolOutputSchemas.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { toolContractMetadata } from "./toolEffects.js";
|
||||
import { requireOutputSchema } from "./toolOutputSchemaPrimitives.js";
|
||||
import { artifactInspectionLimitsSchema } from "../domain/artifactInspection.js";
|
||||
|
||||
const pageInput = {
|
||||
@@ -35,27 +36,30 @@ const traversalLimitsInput = {
|
||||
max_path_bytes: z.number().int().min(1).max(65_535).default(4_096),
|
||||
};
|
||||
|
||||
/** Exact caller boundary for deterministic artifact inventory. */
|
||||
export const artifactInventoryInputSchema = z
|
||||
.object({
|
||||
native_mount_approved: z.boolean().default(false),
|
||||
integrity_policy: z.enum(["fail", "record-and-continue"]).default("fail"),
|
||||
integrity_continue_approved: z.boolean().default(false),
|
||||
const integrityInput = {
|
||||
fail: {
|
||||
integrity_policy: z.literal("fail").default("fail"),
|
||||
integrity_continue_approved: z.literal(false).default(false),
|
||||
max_integrity_mismatches: z.number().int().min(1).max(100).default(10),
|
||||
...pageInput,
|
||||
...traversalLimitsInput,
|
||||
})
|
||||
.superRefine((input, context) => {
|
||||
if (
|
||||
input.integrity_policy === "record-and-continue" &&
|
||||
input.integrity_continue_approved !== true
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["integrity_continue_approved"],
|
||||
message: "record-and-continue requires explicit approval",
|
||||
});
|
||||
});
|
||||
},
|
||||
continue: {
|
||||
integrity_policy: z.literal("record-and-continue"),
|
||||
integrity_continue_approved: z.literal(true),
|
||||
max_integrity_mismatches: z.number().int().min(1).max(100).default(10),
|
||||
},
|
||||
} as const;
|
||||
|
||||
const artifactInventoryFacts = {
|
||||
native_mount_approved: z.boolean().default(false),
|
||||
...pageInput,
|
||||
...traversalLimitsInput,
|
||||
} as const;
|
||||
|
||||
/** Exact caller boundary for deterministic artifact inventory. */
|
||||
export const artifactInventoryInputSchema = z.union([
|
||||
z.object({ ...artifactInventoryFacts, ...integrityInput.fail }),
|
||||
z.object({ ...artifactInventoryFacts, ...integrityInput.continue }),
|
||||
]);
|
||||
|
||||
/** Exact caller boundary for approved artifact extraction. */
|
||||
export const artifactExtractionInputSchema = z.object({
|
||||
@@ -75,26 +79,15 @@ export const artifactExtractionInputSchema = z.object({
|
||||
});
|
||||
|
||||
/** Bounded provider-neutral inspection using one atomic inventory substep. */
|
||||
export const artifactInspectionInputSchema = z
|
||||
.object({
|
||||
native_mount_approved: z.boolean().default(false),
|
||||
integrity_policy: z.enum(["fail", "record-and-continue"]).default("fail"),
|
||||
integrity_continue_approved: z.boolean().default(false),
|
||||
max_integrity_mismatches: z.number().int().min(1).max(100).default(10),
|
||||
...artifactInspectionLimitsSchema.shape,
|
||||
...traversalLimitsInput,
|
||||
})
|
||||
.superRefine((input, context) => {
|
||||
if (
|
||||
input.integrity_policy === "record-and-continue" &&
|
||||
input.integrity_continue_approved !== true
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["integrity_continue_approved"],
|
||||
message: "record-and-continue requires explicit approval",
|
||||
});
|
||||
});
|
||||
const artifactInspectionFacts = {
|
||||
native_mount_approved: z.boolean().default(false),
|
||||
...artifactInspectionLimitsSchema.shape,
|
||||
...traversalLimitsInput,
|
||||
} as const;
|
||||
export const artifactInspectionInputSchema = z.union([
|
||||
z.object({ ...artifactInspectionFacts, ...integrityInput.fail }),
|
||||
z.object({ ...artifactInspectionFacts, ...integrityInput.continue }),
|
||||
]);
|
||||
|
||||
const exampleInputSchema = z.record(z.string(), jsonValueSchema);
|
||||
const examples: Readonly<Record<string, Readonly<Record<string, unknown>>>> = {
|
||||
@@ -107,14 +100,15 @@ const examples: Readonly<Record<string, Readonly<Record<string, unknown>>>> = {
|
||||
},
|
||||
};
|
||||
|
||||
const artifact = <Name extends string>(
|
||||
const artifact = <
|
||||
Name extends string,
|
||||
Schema extends z.ZodType<Readonly<Record<string, unknown>>>,
|
||||
>(
|
||||
name: Name,
|
||||
description: string,
|
||||
inputSchema: z.ZodObject,
|
||||
): ToolContract<Name> => {
|
||||
const outputSchema = artifactOutputSchemas[name];
|
||||
if (outputSchema === undefined)
|
||||
throw new Error(`Missing artifact output schema for ${name}`);
|
||||
inputSchema: Schema,
|
||||
) => {
|
||||
const outputSchema = requireOutputSchema(artifactOutputSchemas, name);
|
||||
return {
|
||||
name,
|
||||
...toolContractMetadata(name),
|
||||
@@ -128,7 +122,7 @@ const artifact = <Name extends string>(
|
||||
input: exampleInputSchema.parse(examples[name] ?? {}),
|
||||
},
|
||||
],
|
||||
};
|
||||
} satisfies ToolContract<Name, Schema, typeof outputSchema>;
|
||||
};
|
||||
|
||||
/** Artifact-graph inventory and explicitly approved safe extraction contracts. */
|
||||
|
||||
Reference in New Issue
Block a user