Files
reverse-engineering-anything/src/cli/cliEvidenceCallerPath.ts
T
morluto 5c5c87d0fe refactor(cli): bind web capture caller paths through the CLI delivery owner (#11322)
WebNetworkCaptureService.inspect took a CLI-only callerPaths argument and
bound caller_input_path and caller_input_paths itself, with its own copy of
the sensitive-literal filter. deliverCliAnalysisEvidence already binds
caller paths for one-shot commands, so the service no longer takes them.

The CLI delivery now omits a caller path, or a named caller-path choice,
that contains a declared sensitive literal, using the same predicate as
bundle receipts. environment-build binds its HAR spelling with
finishCliEvidenceCommand.
2026-11-16 03:47:27 +08:00

66 lines
1.9 KiB
TypeScript

import {
parseEvidence,
withEvidenceCallerInputPath,
type Evidence,
type CallerInputPaths,
} from "../domain/evidence.js";
import type { AnalysisError } from "../domain/analysisErrorBase.js";
import type { Result } from "../domain/result.js";
import { ZodError } from "zod";
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
/**
* Bind the CLI selection before final cleanup or publication can retain it.
* An omitted `callerPath` keeps the Evidence's own, binding only the named
* auxiliary paths.
*/
export const bindCliEvidenceCallerPath =
(
callerPath: string | undefined,
run: () => Promise<Result<Evidence, AnalysisError>>,
additionalPaths?: CallerInputPaths,
): (() => Promise<Result<Evidence, AnalysisError>>) =>
async () => {
const result = await run();
if (result.ok)
return {
ok: true,
value: withEvidenceCallerInputPath(
result.value,
callerPath,
additionalPaths,
),
};
if (result.error.partialObservation !== undefined) {
try {
result.error.partialObservation = withEvidenceCallerInputPath(
parseEvidence(result.error.partialObservation),
callerPath,
additionalPaths,
);
} catch (cause) {
// Raw or invalid partial observations must retain their original form.
if (!(cause instanceof ZodError)) throw cause;
}
}
return result;
};
/** Finalize a one-shot file inspection with its original CLI selection. */
export const finishCliEvidenceCommand = (
callerPath: string,
run: () => Promise<Result<Evidence, AnalysisError>>,
service: { close(): Promise<void> },
providerId: string,
operation: string,
signal: AbortSignal,
additionalPaths?: CallerInputPaths,
) =>
finishAnalysisCommand(
bindCliEvidenceCallerPath(callerPath, run, additionalPaths),
service,
providerId,
operation,
signal,
);