Files
rea/src/application/binary/SessionEvidenceReuse.ts
T
morlutoandCursor Agent 88cf498036 fix!: preserve results when source publication fails (#8444)
* fix: retain address context cleanup failures

* fix!: preserve address context input errors

BREAKING CHANGE: Strict clients that cached the previous full inspect_address_context output schema must refresh tools/list and accept the typed error field on unavailable facets.

* test: use session contract for address context

* fix!: preserve address context resource recovery

BREAKING CHANGE: Clients validating unavailable context facets against a cached strict full output schema must refresh tools/list to accept resource_constraint errors.

* fix: expose authenticated records refused by the evidence ledger (#8426)

* fix: preserve completed evidence on retention refusal

* fix: preserve context when unretained evidence exceeds delivery limits

* fix(mcp): recover oversized context from session evidence

* fix(evidence): preserve completed atomic write results

* fix: retain completed results when source publication fails

* test: cover bounded recovery with unknown retention

* fix(evidence): preserve recovery identity and finalization facts

* fix(evidence): clarify retention of omitted observations

* test(evidence): compare omission guidance with its owner

* fix(evidence): preserve completed composed workflows

* fix(evidence): clarify unretained recovery export

* test(evidence): cover mixed recovery guidance

* fix(evidence): preserve caller scope in secondary failures

* refactor(evidence): remove superseded cleanup projection

* test(evidence): align recovery checks with owners

* fix: preserve cleanup on partial recovery limits

* test: use owners for diagnostic wording

* fix: admit completed analysis before evidence construction

* fix: preserve selected paths when reusing evidence

* fix(cli): preserve caller path in unretained evidence

* fix(evidence): preserve recovery metadata and admission bounds

* refactor: consolidate evidence closure imports

* style(test): format CLI help default annotations (#9280)

* test(mcp): keep recovery checks focused on contract facts

* fix(evidence): preserve feature trace replay revision

* test: align evidence recovery checks with ownership

* test: align partial recovery and cleanup diagnostics

* fix(evidence): preserve nested partials during cleanup

* fix(evidence): respect outer recovery ownership

* fix(capture): discard rejected nested observations

* test(frida): assert inline evidence recovery

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-11-09 02:41:54 +08:00

71 lines
2.4 KiB
TypeScript

import { basename } from "node:path";
import type { AnalysisExecution } from "../AnalysisProvider.js";
import type { Evidence } from "../../domain/evidence.js";
import type { JsonValue } from "../../domain/jsonValue.js";
import { equalJsonText } from "../../domain/jsonSerialization.js";
// Proof belongs to the exact object issued by the session. A wrapper that
// copies or transforms the observation cannot carry it forward.
const issued = new WeakMap<AnalysisExecution, Evidence>();
export const bindSessionEvidenceExecution = (
execution: AnalysisExecution,
evidence: Evidence,
): AnalysisExecution => {
if (
(execution.sourceEvidence !== undefined &&
execution.sourceEvidence.length > 0) ||
evidence.caller_input_path !== undefined
)
return execution;
// Semantic IDs intentionally omit display paths and names. A duplicate in
// the ledger can therefore refer to the same bytes at a different path.
const selected = execution.subject;
if (
selected == null
? evidence.subject !== null
: evidence.subject === null ||
evidence.subject.local_path !== selected.path ||
evidence.subject.name !== (basename(selected.path) || "artifact")
)
return execution;
const subject =
execution.subject === undefined || execution.subject === null
? execution.subject
: Object.freeze({ ...execution.subject });
const result = Object.freeze({
...execution,
result: evidence.normalized_result,
rawResult: evidence.raw_result,
provider: evidence.provider,
...(evidence.analysis_profile === null
? {}
: { analysisProfile: evidence.analysis_profile }),
limitations: evidence.limitations,
locations: evidence.locations,
...(evidence.relationship_coverage === null
? {}
: { relationshipCoverage: evidence.relationship_coverage }),
...(subject === undefined ? {} : { subject }),
});
issued.set(result, evidence);
return result;
};
export const sessionEvidenceForExecution = (
execution: AnalysisExecution,
operation: string,
parameters: Readonly<Record<string, JsonValue>>,
lookup: (id: string) => Evidence | undefined,
): Evidence | undefined => {
const evidence = issued.get(execution);
if (
evidence === undefined ||
evidence.operation !== operation ||
lookup(evidence.evidence_id) !== evidence ||
!equalJsonText(evidence.parameters, parameters)
)
return undefined;
return evidence;
};