Files
reverse-engineering-anything/src/cli/webNetworkCaptureCommands.ts
T
0134732fcd feat(capture): decode selected protobuf and gRPC bodies (#5031)
Retain exact bounded wire facts and optional supplied-schema interpretations for selected historical captures. Share CLI/MCP views and preserve Evidence, partial coverage, credential exclusions and source provenance.

Fixes #4986

Co-authored-by: AayushJB03 <aayushjb14@gmail.com>
Co-authored-by: gensokyo-dev <gensokyo-dev@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 07:10:54 +00:00

121 lines
4.7 KiB
TypeScript

import { z } from "incur";
import { WEB_NETWORK_CAPTURE_FORMATS } from "../domain/webNetworkCapture.js";
import { createWebNetworkCaptureService } from "../composition/webNetworkCaptures.js";
import { CLI_COMMANDS } from "../cliCommandNames.js";
import { logCliCommand } from "../cliLogging.js";
import type { Logger } from "pino";
import type { CliInstance } from "./types.js";
import { cliIntegerArgument } from "./options.js";
import { withCommandCancellation } from "./commandCancellation.js";
import {
analysisEvidenceDeliveryOptions,
deliverCliAnalysisEvidence,
} from "./analysisEvidenceDelivery.js";
import { absoluteCallerPath } from "../filesystem/callerPath.js";
/** Expose offline historical capture inspection with the same selection contract as MCP. */
export const registerWebNetworkCaptureCommands = (
cli: CliInstance,
logger: Logger,
environment: Readonly<NodeJS.ProcessEnv>,
): void => {
const service = createWebNetworkCaptureService(environment);
cli.command(CLI_COMMANDS.inspectWebNetworkCapture, {
description:
"Inspect retained HAR, native mitmproxy, Fiddler SAZ or aioquic qlog records without fetching recorded URLs",
args: z.object({
capturePath: z.string().describe("Absolute local capture path"),
format: z
.enum(WEB_NETWORK_CAPTURE_FORMATS)
.describe("Producer capture format"),
}),
options: z.object({
...analysisEvidenceDeliveryOptions,
protobufFraming: z
.enum(["auto", "raw", "grpc", "grpc-web", "grpc-web-text"])
.optional()
.describe("Override framing for selected retained binary bodies"),
protobufBodyPointer: z
.array(z.string())
.optional()
.describe("Exact body pointers; repeat to select several"),
protobufSchema: z
.string()
.optional()
.describe("Absolute local compiled FileDescriptorSet path"),
protobufMessage: z
.string()
.optional()
.describe("Fully qualified message type in the descriptor set"),
record: z
.array(cliIntegerArgument(0))
.optional()
.describe("Zero-based producer ordinals; repeat to select several"),
sensitiveValue: z
.array(z.string().min(1))
.default([])
.describe(
"Literal string values explicitly marked sensitive; repeat as needed",
),
}),
run: ({ args, options }) =>
withCommandCancellation((signal) =>
logCliCommand(
logger,
CLI_COMMANDS.inspectWebNetworkCapture,
async () => {
return deliverCliAnalysisEvidence({
run: () =>
service.inspect(
{
capture_path: absoluteCallerPath(args.capturePath),
format: args.format,
sensitive_values: options.sensitiveValue,
...([
options.protobufFraming,
options.protobufBodyPointer,
options.protobufSchema,
options.protobufMessage,
].every((value) => value === undefined)
? {}
: {
protobuf: {
framing: options.protobufFraming ?? "auto",
...(options.protobufBodyPointer === undefined
? {}
: { body_pointers: options.protobufBodyPointer }),
...(options.protobufSchema === undefined &&
options.protobufMessage === undefined
? {}
: {
schema: {
descriptor_set_path:
options.protobufSchema === undefined
? undefined
: absoluteCallerPath(
options.protobufSchema,
),
message_type: options.protobufMessage,
},
}),
},
}),
...(options.record === undefined
? {}
: { record_ordinals: options.record }),
},
{ signal },
),
service,
providerId: "web-network-capture",
operation: "inspect_web_network_capture",
signal,
detail: options.detail,
evidenceOutput: options.evidence_output,
});
},
),
),
});
};