Files
reverse-engineering-anything/src/cli/webNetworkCaptureCommands.ts
T
gensokyo-devandClaude Opus 5.5 884b683a94 fix(cli): advertise the decimal token grammar on integer arguments
`cliIntegerArgument` piped a regex-guarded string into a number but never
published Zod's input view, so `--schema` advertised a bare integer for 15
fields while the parser accepted only decimal argv text. `environment-serve
--port` had the same gap through the transforming MCP_PORT owner.

Remove `cliIntegerArgument` and route every call site through
`cliDecimalField`, binding each field to its domain or contract owner where
one exists so bounds, defaults and optionality come from that owner. Export
the input-view publisher as `publishArgvInput` and apply it to `--port`,
which keeps the MCP_PORT grammar shared with `rea mcp --http`.

The decimal catalog test now requires every numeric field's advertisement
to admit its decimal argv token, covers repeated options and
string-advertised token grammars, and checks `--schema` output directly.

The string branch's missing numeric range (#9348) is unchanged.

Fixes #9344

Co-Authored-By: gensokyo-dev <gensokyo-dev@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 04:27:54 +01:00

155 lines
6.3 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 { cliDecimalField } from "./options.js";
import { withCommandCancellation } from "./commandCancellation.js";
import {
analysisEvidenceDeliveryOptions,
deliverCliAnalysisEvidence,
} from "./analysisEvidenceDelivery.js";
import { localPathStringSchema } from "../domain/localPath.js";
import { absoluteCallerPath } from "../filesystem/callerPath.js";
import { explicitSensitiveValueOptions } from "./explicitSensitiveArguments.js";
const recordOrdinal =
inspectWebNetworkCaptureInputSchema.shape.record_ordinals.unwrap().element;
/** 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: localPathStringSchema.describe("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: localPathStringSchema
.optional()
.describe("Local compiled FileDescriptorSet path"),
protobufMessage: z
.string()
.optional()
.describe("Fully qualified message type in the descriptor set"),
record: z
.array(cliDecimalField(recordOrdinal))
.optional()
.describe("Zero-based producer ordinals; repeat to select several"),
...explicitSensitiveValueOptions,
maxInputBytes: cliDecimalField(
inspectWebNetworkCaptureInputSchema.shape.max_input_bytes,
),
maxReplyBytes: cliDecimalField(
inspectWebNetworkCaptureInputSchema.shape.max_reply_bytes,
),
maxNestingDepth: cliDecimalField(
inspectWebNetworkCaptureInputSchema.shape.max_nesting_depth,
),
// Decimal tokens only: numeric coercion would read "0x1" as 1 ms.
captureTimeoutMs: cliDecimalField(
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.maxInputBytes === undefined
? {}
: { max_input_bytes: options.maxInputBytes }),
...(options.maxReplyBytes === undefined
? {}
: { max_reply_bytes: options.maxReplyBytes }),
...(options.maxNestingDepth === undefined
? {}
: { max_nesting_depth: options.maxNestingDepth }),
...([
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 },
{
capture: args.capturePath,
...(options.protobufSchema === undefined
? {}
: { descriptor: options.protobufSchema }),
},
),
service,
providerId: "web-network-capture",
operation: "inspect_web_network_capture",
signal,
detail: options.detail,
evidenceOutput: options.evidence_output,
sensitiveValues: options.sensitiveValue ?? [],
});
},
),
),
});
};