mirror of
https://github.com/morluto/rea.git
synced 2026-11-11 01:13:39 +00:00
Separate engine cleanup, investigation reset and terminal disposal in the shared application owner. Keep stable Evidence IDs and full Unknown revision history through engine close and target changes; serialize reset with all record writers and cleanup owners, optionally acknowledging a complete checkpoint before clearing. Bound retained representation without eviction. Validation: 43 focused files / 533 distinct tests, source/type/lint/schema/documentation checks, nine genuine source cases across eight families, real Ghidra session identity and cleanup, and nine actual local Codex CLI terra/high runs with independent full-result and checkpoint audits. See docs/verification/investigation-lifecycle.md for measurements, partial attempts and verification limits. Fixes #8347. BREAKING CHANGE: close_binary retains investigation records. Use reset_investigation to clear them. Cross-process recovery requires an explicitly acknowledged Evidence bundle checkpoint. Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
import type { AnalysisOperationPort } from "../application/AnalysisProvider.js";
|
|
import type { BinarySessionPort } from "../application/binary/BinarySessionPort.js";
|
|
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
|
|
import { err, ok, type Result } from "../domain/result.js";
|
|
import { currentMcpToolRequest } from "./McpToolRequest.js";
|
|
|
|
/** Run a provider-backed tool while its target binding stays admitted. */
|
|
export type WithAdmittedAnalysis = <Value>(
|
|
operationName: string,
|
|
signal: AbortSignal | undefined,
|
|
operation: (analysis: AnalysisOperationPort) => Promise<Value>,
|
|
) => Promise<Result<Value, AnalysisError>>;
|
|
|
|
/** Select exactly one owner for a server's analysis operation binding. */
|
|
export type ServerAnalysisSource =
|
|
| { readonly kind: "session"; readonly session: BinarySessionPort }
|
|
| { readonly kind: "fixed"; readonly analysis: AnalysisOperationPort };
|
|
|
|
/** Run against the source's explicit owner, admitting session-scoped work. */
|
|
export const withAdmittedAnalysis = (
|
|
source: ServerAnalysisSource,
|
|
): WithAdmittedAnalysis =>
|
|
source.kind === "session"
|
|
? (operationName, signal, operation) =>
|
|
currentMcpToolRequest()?.admit(
|
|
source.session,
|
|
operationName,
|
|
signal,
|
|
operation,
|
|
) ??
|
|
source.session.withAdmittedAnalysis(operationName, signal, operation)
|
|
: async (operationName, signal, operation) =>
|
|
signal?.aborted === true
|
|
? err(
|
|
new AnalysisCancelledError(operationName, {
|
|
cause: signal.reason,
|
|
}),
|
|
)
|
|
: ok(await operation(source.analysis));
|