Files
rea/src/composition/directAnalysis.ts
T
morluto 060587b456 fix(cli): prefer native byte inspection for automatic dispatch metadata
Allow the composed one-shot dispatch workflow to open a covered Mach-O
without selecting a deep provider. The registry still owns selector
precedence; explicit request/environment choices remain binding, while
non-Mach-O and unsupported hosts retain deep symbol fallback. Requested
snapshots keep ordinary binding and profile semantics.

Share runtime composition and target admission with the native byte reader.
Keep target parsing, resource ownership and Evidence on the original session.

Validation: 13 focused files, 192 passed and 2 skipped; npm run check passed.
The six previously blocked native property CLI controls now pass. Ten measured
CLI workflows preserved exact metadata facts; warm raw reply token medians
1344/927, elapsed .475/.547s, CPU .691/.745s, sampled family RSS351.2/359.3MiB
baseline/candidate. Baseline used explicit Ghidra workaround; true cold and
full-agent costs unmeasured. No speed/memory improvement or Windows claim.

Refs #4555
2026-10-17 03:11:32 +08:00

91 lines
3.4 KiB
TypeScript

import { snapshotEnvironment } from "../process/snapshotEnvironment.js";
import { parseConfig } from "../config/parseConfig.js";
import type { DirectAnalysisDependencies } from "../application/DirectAnalysisDependencies.js";
type DirectAnalysisRuntime = typeof import("../application/DirectAnalysis.js");
type DirectAnalysisStatusRuntime =
typeof import("../application/DirectAnalysisStatus.js");
type BoundOperation<Operation> = Operation extends (
dependencies: infer _Dependencies,
...args: infer Arguments
) => infer Result
? (...args: Arguments) => Result
: never;
/** Bind one-shot analysis and status commands to one caller-selected environment. */
export const createDirectAnalysis = (
selectedEnvironment: Readonly<Record<string, string | undefined>>,
) => {
const environment = snapshotEnvironment(selectedEnvironment);
const dependencies: DirectAnalysisDependencies = {
readConfiguration: () => parseConfig(environment),
createBinarySession: async (config, logger) => {
const { createBinarySession } = await import("./binary.js");
return createBinarySession(config, logger, environment);
},
createManagedBinarySession: async () => {
const { createManagedBinarySession } = await import("./binary.js");
return createManagedBinarySession();
},
createNativeDispatchBinarySession: async (config, logger) => {
const { createNativeDispatchBinarySession } = await import("./binary.js");
return createNativeDispatchBinarySession(config, logger, environment);
},
createNativeBinarySession: async () => {
const { createNativeBinarySession } = await import("./binary.js");
return createNativeBinarySession(environment);
},
createArtifactBinarySession: async () => {
const { createArtifactBinarySession } = await import("./binary.js");
return createArtifactBinarySession(environment);
},
};
const runDirectAnalysis: BoundOperation<
DirectAnalysisRuntime["runDirectAnalysis"]
> = async (...args) => {
const { runDirectAnalysis } =
await import("../application/DirectAnalysis.js");
return runDirectAnalysis(dependencies, ...args);
};
const runProviderAnalysis: BoundOperation<
DirectAnalysisRuntime["runProviderAnalysis"]
> = async (...args) => {
const { runProviderAnalysis } =
await import("../application/DirectAnalysis.js");
return runProviderAnalysis(dependencies, ...args);
};
const runSessionStatus: BoundOperation<
DirectAnalysisStatusRuntime["runSessionStatus"]
> = async (...args) => {
const { runSessionStatus } =
await import("../application/DirectAnalysisStatus.js");
return runSessionStatus(dependencies, ...args);
};
return {
runDirectAnalysis,
runProviderAnalysis,
runSessionStatus,
};
};
/** Bound operations used by CLI command registration. */
export type DirectAnalysis = ReturnType<typeof createDirectAnalysis>;
/** Execute managed metadata without configuration or native provider candidates. */
export const runManagedProviderExecution: BoundOperation<
DirectAnalysisRuntime["runManagedProviderExecution"]
> = async (...args) => {
const { runManagedProviderExecution } =
await import("../application/DirectAnalysis.js");
return runManagedProviderExecution(
{
createManagedBinarySession: async () => {
const { createManagedBinarySession } = await import("./binary.js");
return createManagedBinarySession();
},
},
...args,
);
};