mirror of
https://github.com/morluto/rea
synced 2026-10-26 14:25:49 -04:00
306ed79932
* feat(captures): make the HAR/SAZ/qlog decoder heap configurable REA_CAPTURE_DECODER_OLD_GENERATION_MIB keeps the 192 MiB default and refuses values outside 8 to 16384 MiB instead of falling back. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(captures): defer decoder startup and share one parsed heap Invalid REA_CAPTURE_DECODER_OLD_GENERATION_MIB threw while CLI commands were registered, so doctor and help never ran. Build the capture service only when inspect-web-network-capture runs. Resolve the heap once in composition and pass that fact to each Node adapter. Limitation and memory-failure reports use the selected adapter's heap, so a decoder built with a different environment does not describe another limit. Mock captureDecoderProcessMemoryLimitBytes in the Node adapter test so a Windows Bun host still exercises the unavailable-bound refusal. Co-authored-by: morluto <morluto@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
125 lines
5.0 KiB
TypeScript
125 lines
5.0 KiB
TypeScript
import { z } from "incur";
|
|
import {
|
|
WEB_NETWORK_CAPTURE_FORMATS,
|
|
inspectWebNetworkCaptureInputSchema,
|
|
} 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";
|
|
import { explicitSensitiveValueOptions } from "./explicitSensitiveArguments.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 => {
|
|
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"),
|
|
...explicitSensitiveValueOptions,
|
|
captureTimeoutMs:
|
|
inspectWebNetworkCaptureInputSchema.shape.capture_timeout_ms,
|
|
}),
|
|
run: ({ args, options }) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(
|
|
logger,
|
|
CLI_COMMANDS.inspectWebNetworkCapture,
|
|
async () => {
|
|
const service = createWebNetworkCaptureService(environment);
|
|
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 }),
|
|
...(options.captureTimeoutMs === undefined
|
|
? {}
|
|
: { capture_timeout_ms: options.captureTimeoutMs }),
|
|
},
|
|
{ signal },
|
|
),
|
|
service,
|
|
providerId: "web-network-capture",
|
|
operation: "inspect_web_network_capture",
|
|
signal,
|
|
detail: options.detail,
|
|
evidenceOutput: options.evidence_output,
|
|
});
|
|
},
|
|
),
|
|
),
|
|
});
|
|
};
|