mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 15:05:51 +00:00
* refactor(contracts): declare each tool's effect audit on its contract Every public tool's effects lived in a 255-entry TOOL_EFFECT_AUDIT table in toolEffects.ts, keyed by name and looked up again by toolContractMetadata, the capability inventory (toolSessionEffects) and tests (TOOL_EFFECTS). toolContractMetadata(name, audit) now takes the audit from the contract declaration, and the contract carries both the provider-wide effects and the session effects. The inventory reads contract.sessionEffects. The table, TOOL_EFFECTS and toolSessionEffects are removed; toolEffects.ts keeps the effect type, the shared presets and annotation derivation. Effects, session effects, annotations and titles are byte-identical for all 255 contracts. * test(contracts): read focused effect expectations from their contract family
81 lines
3.5 KiB
TypeScript
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 }
|
|
: {}),
|
|
requiresActiveTarget: true,
|
|
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[];
|