mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 19:41:20 -05:00
e309e15bf8
* fix(ghidra)!: scope defect notes and state session limitations once Ghidra known-defect records filtered by version only, so every result on an x86-64 PE carried the AArch64 ghidra-10154 record and the clang ghidra-9996 record, including byte reads and string searches. Each record now declares the target architectures it can apply to. ghidraKnownProviderDefectLimitations keeps a record only when the target's architecture can match (an unknown architecture keeps it) and the operation can depend on jump-table or function-body recovery. Every native result also repeated the session's shared limitations: the analysis and checkpoint caveats, the address convention, the native decompiler note, the PDB state, and the build and defect records. Over nine MCP calls on a public x64 DLL they were about 54% of the bytes. The provider now names those entries in a new AnalysisExecution sessionLimitations field. It still keeps them in limitations, so a consumer that ignores the field loses nothing. The session owner decides delivery. The persistent MCP runtime selects reference mode: each result replaces the shared entries with one limitation naming a retained session-context Evidence, records it, and links it in evidence_links. Equal session facts link the same record, so repeated observations keep their Evidence. One-shot CLI sessions keep the entries inline. BREAKING CHANGE: in MCP sessions, Ghidra result Evidence no longer lists session-scoped limitations inline. It carries one reference limitation and links a retained session-limitations Evidence (operation health, parameters.facet session-limitations) in evidence_links. Read it with get_evidence_bundle. Defect records no longer appear on operations or architectures outside their declared scope. Fixes #14183 Fixes #14158 * test(ghidra): spread readonly defect limitations into the matcher * fix(ghidra): keep defect notes on byte searches and reuse sourced session Evidence search_bytes names the function containing each match, so a body truncated by a switch defect can leave that procedure null. It now keeps the applicable defect records. Reference mode links a session-context record from every result, and bindSessionEvidenceExecution refused to reuse any execution with sources, so the adapter rebuilt and rehashed the Evidence the session had already retained. Reuse now accepts an execution whose sources match the record's authenticated evidence_links, in order. A regression checks that an exported snapshot's bundle carries the linked context record, so a replay in another process can resolve the reference. * fix(decompile-all): write the full session limitations into exported directories In reference mode a result carries one reference to the session-context Evidence instead of the session limitations. decompile_all copied execution limitations into its function files, journal and index, but the directory writer never saves the linked record, so after the MCP process ended the known-defect, PDB and checkpoint caveats could not be recovered. decompile_all now reads through inlineLinkedSessionLimitations, which restores the referenced text from the linked context record owned by SessionLimitationContext, so the directory stays self-describing.
110 lines
3.9 KiB
TypeScript
110 lines
3.9 KiB
TypeScript
import {
|
|
createEvidence,
|
|
type Evidence,
|
|
type EvidenceSubjectInput,
|
|
} from "../../domain/evidence.js";
|
|
import type { AnalysisExecution } from "../../ports/AnalysisProvider.js";
|
|
import { isRecord } from "../../kernel/isRecord.js";
|
|
|
|
/**
|
|
* How a session delivers the limitations its provider session shares across
|
|
* calls. `inline` keeps them in every result, which suits a one-call session.
|
|
* `reference` states them once in a retained record that each result links.
|
|
*/
|
|
export type SessionLimitationDelivery = "inline" | "reference";
|
|
|
|
/** Parameters naming the retained record of a session's shared limitations. */
|
|
const SESSION_LIMITATIONS_FACET = { facet: "session-limitations" } as const;
|
|
|
|
/**
|
|
* The retained record of limitations a provider session shares across calls.
|
|
* Equal facts produce the same record, so its identity names them.
|
|
*/
|
|
export const sessionLimitationContextEvidence = (
|
|
execution: AnalysisExecution,
|
|
sessionLimitations: readonly string[],
|
|
target: EvidenceSubjectInput,
|
|
): Evidence =>
|
|
createEvidence(
|
|
target,
|
|
execution.provider,
|
|
{
|
|
operation: "health",
|
|
parameters: SESSION_LIMITATIONS_FACET,
|
|
...(execution.analysisProfile === undefined
|
|
? {}
|
|
: { analysisProfile: execution.analysisProfile }),
|
|
result: { limitations: [...sessionLimitations] },
|
|
confidence: "observed",
|
|
limitations: [...sessionLimitations],
|
|
},
|
|
{ immutable: true },
|
|
);
|
|
|
|
/** The one limitation that stands in for the session's shared facts. */
|
|
export const sessionLimitationReference = (
|
|
context: Evidence,
|
|
count: number,
|
|
): string =>
|
|
`${String(count)} session limitations also apply; they are stated once in linked Evidence ${context.evidence_id}. Read them with get_evidence_bundle detail records.`;
|
|
|
|
/**
|
|
* Deliver a provider session's shared limitations as the session selects. In
|
|
* `reference` mode the entries are replaced by one reference to a retained
|
|
* record that the result links, so the full text stays reachable and a bundle
|
|
* that follows links stays self-describing. Equal session facts give every
|
|
* result the same record, so a repeated observation keeps its Evidence.
|
|
*/
|
|
export const deliverSessionLimitations = (
|
|
execution: AnalysisExecution,
|
|
target: EvidenceSubjectInput,
|
|
delivery: SessionLimitationDelivery,
|
|
): AnalysisExecution => {
|
|
const { sessionLimitations, ...rest } = execution;
|
|
if (sessionLimitations === undefined) return execution;
|
|
if (delivery === "inline" || sessionLimitations.length === 0) return rest;
|
|
const context = sessionLimitationContextEvidence(
|
|
execution,
|
|
sessionLimitations,
|
|
target,
|
|
);
|
|
const shared = new Set(sessionLimitations);
|
|
return {
|
|
...rest,
|
|
limitations: [
|
|
...execution.limitations.filter((entry) => !shared.has(entry)),
|
|
sessionLimitationReference(context, sessionLimitations.length),
|
|
],
|
|
sourceEvidence: [...(execution.sourceEvidence ?? []), context],
|
|
};
|
|
};
|
|
|
|
const isSessionLimitationContext = (source: Evidence): boolean =>
|
|
source.operation === "health" &&
|
|
isRecord(source.parameters) &&
|
|
source.parameters.facet === SESSION_LIMITATIONS_FACET.facet;
|
|
|
|
/**
|
|
* Restore the full text of session limitations that a result references, from
|
|
* the context record it links. Writers whose output outlives the session, such
|
|
* as a decompile_all directory, use this so their files stay self-describing.
|
|
*/
|
|
export const inlineLinkedSessionLimitations = (
|
|
execution: AnalysisExecution,
|
|
): AnalysisExecution => {
|
|
const contexts = new Map<string, readonly string[]>();
|
|
for (const source of execution.sourceEvidence ?? [])
|
|
if (isSessionLimitationContext(source))
|
|
contexts.set(
|
|
sessionLimitationReference(source, source.limitations.length),
|
|
source.limitations,
|
|
);
|
|
if (contexts.size === 0) return execution;
|
|
return {
|
|
...execution,
|
|
limitations: execution.limitations.flatMap(
|
|
(entry) => contexts.get(entry) ?? [entry],
|
|
),
|
|
};
|
|
};
|