mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
86 lines
3.2 KiB
TypeScript
86 lines
3.2 KiB
TypeScript
import { binaryMetadataArchitecture } from "../../domain/binaryMetadataArchitecture.js";
|
|
import {
|
|
machoSelectionAnswersArchitecture,
|
|
metadataReportSubjectFormat,
|
|
} from "../../domain/apple/machoTargetSelection.js";
|
|
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
|
import type { RustBinaryPort } from "../../ports/rust/RustBinaryPort.js";
|
|
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
|
import type { Evidence } from "../../domain/evidence.js";
|
|
import { observedFileEvidence } from "../observedFileEvidence.js";
|
|
import { rustBinarySchema } from "../../domain/rust/rustBinary.js";
|
|
import { inspectRustBinaryRequestSchema } from "../../domain/rust/rustBinaryQuery.js";
|
|
import type { Result } from "../../domain/result.js";
|
|
import type { AnalysisViewRetention } from "../analysisView/AnalysisViewRetention.js";
|
|
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
|
|
|
const OPERATION = "inspect_rust_binary";
|
|
|
|
/** Shared exact input validation and artifact-bound Evidence for CLI and MCP. */
|
|
export class RustBinaryService {
|
|
constructor(readonly provider: RustBinaryPort) {}
|
|
|
|
close(): Promise<void> {
|
|
return this.provider.close();
|
|
}
|
|
|
|
/** Inspect one explicitly selected file without acquiring a binary session. */
|
|
inspect(
|
|
rawInput: unknown,
|
|
options?: ExecutionOptions,
|
|
retention?: AnalysisViewRetention,
|
|
): Promise<Result<Evidence, AnalysisError>> {
|
|
return executeArtifactInspection(
|
|
{
|
|
operation: OPERATION,
|
|
inputSchema: inspectRustBinaryRequestSchema,
|
|
outputSchema: rustBinarySchema,
|
|
provider: this.provider,
|
|
retainCompletedReport: true,
|
|
invalidOutputMessage:
|
|
"Rust dependency reader returned malformed metadata or changed the selected artifact or slice identity.",
|
|
toParameters: ({ detail: _detail, view: _view, ...parameters }) =>
|
|
parameters,
|
|
selectRetainedView: ({ detail, view }) =>
|
|
detail === "summary" || view !== undefined
|
|
? view === undefined
|
|
? { kind: "summary" }
|
|
: { kind: "rust", ...view }
|
|
: undefined,
|
|
validateReport: (report, parameters) =>
|
|
report.artifact.path === parameters.path &&
|
|
machoSelectionAnswersArchitecture(
|
|
report.selected_slice,
|
|
parameters.architecture,
|
|
),
|
|
buildEvidence: (value, identity, parameters) => {
|
|
const architecture = binaryMetadataArchitecture(value.architecture);
|
|
const section = value.auditable_metadata;
|
|
return observedFileEvidence(
|
|
value,
|
|
identity,
|
|
OPERATION,
|
|
parameters,
|
|
section === null
|
|
? []
|
|
: [
|
|
{
|
|
kind: "file-offset-range",
|
|
start: section.file_offset,
|
|
end: section.file_offset + section.section_bytes,
|
|
},
|
|
],
|
|
{
|
|
format: metadataReportSubjectFormat(value),
|
|
...(architecture === undefined ? {} : { architecture }),
|
|
},
|
|
);
|
|
},
|
|
},
|
|
rawInput,
|
|
options,
|
|
retention,
|
|
);
|
|
}
|
|
}
|