Files
reverse-engineering-anything/src/server/serverInstructions.ts
T
hhangandhhang 9c25fb1e29 perf(mcp): defer runtime loading for scoped stdio discovery (#12237)
* perf(mcp): defer runtime loading for scoped stdio discovery

* test(mcp): cover prompt-first scoped stdio startup

---------

Co-authored-by: hhang <169027046+xu91102@users.noreply.github.com>
2026-11-19 06:35:29 -05:00

37 lines
2.3 KiB
TypeScript

import { UNTRUSTED_CONTENT_INSTRUCTIONS } from "./toolResultEncoding.js";
import { recoveryInstructions } from "./recoveryInstructions.js";
const TARGET_FREE_INSTRUCTIONS =
"REA provides reverse-engineering tools for local artifacts, native binaries, managed code, browser pages, and runtimes. Use the tool that directly answers the question; discover targets or inspect inventory only when needed. Tool results include inline Evidence and report their coverage and limitations.";
// Only advertise the lifecycle when `session` is in scope: otherwise
// `open_binary` and `close_binary` are disabled and the guidance would direct
// initialization to a call that always fails.
const SESSION_LIFECYCLE_INSTRUCTIONS =
"An opened target persists across turns. When finished, export needed Evidence and call close_binary; its snapshot_path can retain analysis.";
const ACTIVE_TARGET_INSTRUCTIONS =
"REA analyzes the active reverse-engineering target. Use the analysis tool that answers the question directly. Search or list symbols when discovery is needed.";
// Only name the enhanced-family dossier tool when that family is in scope:
// otherwise `analyze_function` is disabled and the recommendation always fails.
const FUNCTION_DOSSIER_INSTRUCTIONS =
"analyze_function provides a function dossier, and focused procedure tools return individual facets.";
const EVIDENCE_INTERPRETATION_INSTRUCTIONS =
"Preserve caller-selected paths and returned IDs; do not rebase REA host paths onto the client workspace. An unresolved lookup or exhausted page with partial source coverage does not establish target absence.";
export const serverInstructions = (
hasSession: boolean,
advertisesTool: (tool: string) => boolean,
): string => {
const guidance = (tool: string, text: string): string =>
advertisesTool(tool) ? ` ${text}` : "";
const recovery = recoveryInstructions(
advertisesTool("update_analysis_settings"),
);
if (!hasSession)
return `${ACTIVE_TARGET_INSTRUCTIONS}${guidance("analyze_function", FUNCTION_DOSSIER_INSTRUCTIONS)} ${EVIDENCE_INTERPRETATION_INSTRUCTIONS} ${recovery} ${UNTRUSTED_CONTENT_INSTRUCTIONS}`;
return `${TARGET_FREE_INSTRUCTIONS}${guidance("close_binary", SESSION_LIFECYCLE_INSTRUCTIONS)} ${EVIDENCE_INTERPRETATION_INSTRUCTIONS} ${recovery} ${UNTRUSTED_CONTENT_INSTRUCTIONS}`;
};