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:
morluto
2026-08-10 02:28:11 +08:00
committed by GitHub
parent 6901edc05d
commit b8a9da0c0f
271 changed files with 5970 additions and 5699 deletions
+7 -18
View File
@@ -1,17 +1,15 @@
import { writeAnalysisSnapshot } from "../application/AnalysisSnapshotFiles.js";
import { closeBinaryInputSchema } from "../contracts/sessionLifecycleInputs.js";
import { ok } from "../domain/result.js";
import {
reportLifecycleEnd,
reportLifecycleStart,
} from "./lifecycleProgress.js";
import { logToolExecution } from "./toolLogging.js";
import { toCallToolResult } from "./toolResult.js";
import { mcpProgressReporter } from "./mcpProgress.js";
import { permissionFailure } from "./permissionFailure.js";
import type { LifecycleToolRegistration } from "./registerSessionTools.js";
import { safeParseToolInput } from "./toolInputValidation.js";
import { logToolExecution } from "./toolLogging.js";
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
import { toCallToolResult } from "./toolResult.js";
/** Register provider cleanup and optional pre-close snapshot persistence. */
export const registerCloseLifecycleTool = ({
@@ -26,33 +24,25 @@ export const registerCloseLifecycleTool = ({
closeContract.name,
toolRegistrationOptions(closeContract),
async (input, context) => {
const parsedInput = safeParseToolInput(
closeBinaryInputSchema,
input,
closeContract.name,
);
if (!parsedInput.ok) return toCallToolResult(parsedInput, closeContract);
const parsed = parsedInput.value;
const progress = mcpProgressReporter(context);
if (parsed.snapshot_path === undefined) {
if (input.snapshot_path === undefined) {
await reportLifecycleStart(progress, closeContract.name);
const closed = await logToolExecution(logger, closeContract.name, () =>
session.close({ progress }),
);
await reportLifecycleEnd(progress, closeContract.name, closed.ok);
server.sendToolListChanged();
return toCallToolResult(closed, closeContract);
}
if (permissionAuthority !== undefined) {
const authorized = await permissionAuthority.authorize(
{
capability: "snapshot_write",
roots: [parsed.snapshot_path],
roots: [input.snapshot_path],
executables: [],
environment_names: [],
network: "none",
mount: false,
operation_identity: `close_binary:snapshot:${parsed.snapshot_path}`,
operation_identity: `close_binary:snapshot:${input.snapshot_path}`,
},
"write",
);
@@ -63,8 +53,8 @@ export const registerCloseLifecycleTool = ({
if (!snapshot.ok) return toCallToolResult(snapshot, closeContract);
const written = await writeAnalysisSnapshot(
snapshot.value,
parsed.snapshot_path,
parsed.overwrite,
input.snapshot_path,
input.overwrite,
snapshotFilePolicy,
);
if (!written.ok) return toCallToolResult(written, closeContract);
@@ -77,7 +67,6 @@ export const registerCloseLifecycleTool = ({
session.close({ progress }),
);
await reportLifecycleEnd(progress, closeContract.name, closed.ok);
server.sendToolListChanged();
return closed.ok
? toCallToolResult(
ok({