Files
reverse-engineering-anything/src/contracts/functionWorkflowToolContracts.ts
T
morluto 402ce20b80 fix(session): declare, admit and advertise the open-target prerequisite through one owner (#15356)
* fix(contracts): declare the open-target prerequisite once in availability

Replace the requiresActiveTarget boolean with an "active-target" value of the
availability declaration. 18 contracts that read a required caller path, all
declared standalone or host-restricted or named inventory rules, no longer
claim to need an open target.

* fix(session): admit tools through one session evaluator shared with binary_session

binary_session availability and call-time dispatch now read one admission
evaluator for active-target tools and external mutations. Resource-only
lane refusals and Ghidra or resource-only external-mutation refusals carry
the open_binary or close_binary recovery that binary_session reports,
instead of a generic capability or unreadable-output error. Packet
capture, Wakaru, firmware and mitmproxy refuse an unsupported host before
reading tool configuration.

* fix(mcp): advertise the open-target prerequisite and name open_binary on first contact

Each active-target tool's advertised description ends with one sentence
derived from its availability declaration. When the SDK refuses such a
tool's arguments while the session would also refuse it, the
invalid_request remediation names the session recovery first, read from
the same admission evaluator as binary_session and dispatch.

* fix(mcp): refuse composed workflows as a whole and keep scoped recovery and catalog identity in step

A composed workflow such as batch_decompile now refuses with the
advertised open_binary or close_binary recovery before it runs, instead of
reporting a batch of failed children. Malformed arguments on a connection
that does not advertise session tools lead with the scoped restart
recovery, and catalog digests cover the advertised prerequisite sentence.
The prerequisite test reads union alternatives.
2026-12-01 03:55:48 +00:00

81 lines
3.5 KiB
TypeScript

import { requireOutputSchema } from "./toolOutputSchemaPrimitives.js";
import { jsonObjectSchema } from "../domain/jsonValue.js";
import { analysisDetailSummaryDefaultSchema } from "./analysisDetail.js";
import { enhancedInputSchemas } from "./enhancedInputs.js";
import { TOOL_EXAMPLE_OVERRIDES } from "./toolContractExamples.js";
import type { ToolContract } from "./toolContractTypes.js";
import type { EffectAudit } from "./toolEffects.js";
import {
toolContractMetadata,
providerEffects,
providerRemoteEffects,
providerUiNetworkEvidenceEffects,
toolEffects,
} from "./toolEffects.js";
import { enhancedOutputSchemas } from "./toolOutputSchemaGroups.js";
type FunctionWorkflowName = "analyze_function" | "inspect_native_api";
/**
* MCP inputs: the provider input plus analyze_function's delivery detail, which
* the tool handler separates before any provider call. Composed workflows such
* as inspect_native_api build provider inputs from enhancedInputSchemas alone.
*/
export const functionWorkflowInputSchemas = {
analyze_function: enhancedInputSchemas.analyze_function.extend({
detail: analysisDetailSummaryDefaultSchema,
}),
inspect_native_api: enhancedInputSchemas.inspect_native_api,
} as const;
/** The contracts below that the CLI exposes as commands. */
const FUNCTION_WORKFLOW_CLI_CONTRACTS: ReadonlySet<string> = new Set([
"inspect_native_api",
]);
const functionWorkflow = <Name extends FunctionWorkflowName>(
name: Name,
audit: EffectAudit,
description: string,
) => {
const inputSchema = functionWorkflowInputSchemas[name];
const outputSchema = requireOutputSchema(enhancedOutputSchemas, name);
return {
name,
...toolContractMetadata(name, audit),
description,
kind: "enhanced",
...(FUNCTION_WORKFLOW_CLI_CONTRACTS.has(name)
? { cli: true as const }
: {}),
availability: "active-target",
inputSchema,
outputSchema,
examples: [
{
title: `Example ${name.replaceAll("_", " ")} request`,
input: jsonObjectSchema.parse(
inputSchema.parse(TOOL_EXAMPLE_OVERRIDES[name] ?? {}),
),
},
],
} satisfies ToolContract<Name, typeof inputSchema, typeof outputSchema>;
};
/** Function dossier and native API reconstruction workflow contracts. */
export const FUNCTION_WORKFLOW_TOOL_CONTRACTS = [
functionWorkflow(
"analyze_function",
providerUiNetworkEvidenceEffects,
"Inspect one native function by symbol or provider-returned address. Default summary returns identity, pseudocode size, facet counts and value-flow availability while retaining the complete dossier. Read selected facts with inspect_analysis_view using normalized_result.parent_evidence_id; detail complete returns everything inline. Facets include pseudocode, assembly, body ranges, comments, calls, references, strings/names, CFG and native API observations. Extents reflect provider analysis; limitations report unknown ranges and possible Ghidra terminal-call truncation.",
),
functionWorkflow(
"inspect_native_api",
providerEffects(toolEffects({ mutatesSession: true, idempotent: false }), {
...providerRemoteEffects,
changesUiState: true,
}),
"Inspect recovered parameter/return boundary types and jump-table dispatch for one native function selected by symbol or address. Returns confidence, supporting Evidence, case/data/target mappings, unsupported facets and residual unknowns. Null case values are unresolved, never known defaults. Use analyze_function for the broader function dossier.",
),
] as const satisfies readonly ToolContract[];