Files
reverse-engineering-anything/src/cli/webRuntimeCommands.ts
T
morlutoandCursor Agent b31fc5d5fb fix(cli): advertise domain constraints for selector and path options (#9181)
* fix(cli): advertise domain constraints for selector and path options

Android class, method, and mapping fields, ADB setting keys, and browser
endpoints used bare strings in --schema. They now reuse the domain fields,
so empty selectors, relative mapping paths, and malformed setting keys
fail in the advertised schema.

* fix(cli): keep selector limits when argument parsing rejects them

Empty browser and Electron selectors now fail in the CLI parser, so their
diagnostics are VALIDATION_ERROR with the one-character minimum. ADB
setting keys stay on the selector repair path, which restores maximum 256
and the identifier pattern.

* test(cli): assert empty-selector codes without frozen prose

Empty browser and Electron selectors still fail as VALIDATION_ERROR
too_small on the named field. The tests no longer copy Zod's sentence.

* test(cli): compare endpoint diagnostics with the domain schema

Browser and Inspector tests take custom issue text from the schema that
owns it, and empty capture comparison must name both missing inspection
fields.

* fix(cli): remove duplicate merged schema import

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-11-07 16:17:09 +08:00

121 lines
4.6 KiB
TypeScript

import { projectCliAnalysisResult } from "./projectCliAnalysisResult.js";
import { Cli, z } from "incur";
import { createWebRuntimeService } from "../composition/webRuntime.js";
import { cliDomainInput } from "./domainInput.js";
import { observeWebExecutionInputSchema } from "../domain/webExecution.js";
import { inspectWebEventListenersInputSchema } from "../domain/webEventListeners.js";
import { browserCliError } from "./browserCliError.js";
import {
browserScopeOptions,
selectedCommandTimeout,
} from "../cliObservationOptions.js";
import { logCliCommand } from "../cliLogging.js";
import { CLI_COMMANDS } from "../cliCommandNames.js";
import { cliDecimalField } from "./options.js";
import type { Logger } from "pino";
import type { ProgressReporter } from "../application/ProgressReporter.js";
import { withCommandCancellation } from "./commandCancellation.js";
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
/** CLI progress exposes the actual armed point on stderr without corrupting JSON results. */
const runtimeProgress: ProgressReporter = {
report: async (update) => {
process.stderr.write(`${JSON.stringify({ rea_progress: update })}\n`);
},
};
/** Register public equivalents of the two modular website runtime tools. */
export const registerWebRuntimeCommands = (
cli: ReturnType<typeof Cli.create>,
logger: Logger,
): void => {
cli.command(CLI_COMMANDS.observeWebExecution, {
description:
"Observe precise page execution; resets counters and temporarily disables optimization",
args: z.object({
endpoint: cliDomainInput(
observeWebExecutionInputSchema.shape.cdp_endpoint,
).describe("Existing loopback browser CDP endpoint"),
targetId: observeWebExecutionInputSchema.shape.target_id.describe(
"Selected page target ID from list-browser-targets",
),
}),
options: z.object({
...browserScopeOptions,
observationMs: cliDecimalField(
observeWebExecutionInputSchema.shape.observation_ms,
).describe("Observation duration in milliseconds"),
}),
run: ({ args, options }) =>
withCommandCancellation((signal) =>
logCliCommand(logger, "observe-web-execution", async () => {
const service = createWebRuntimeService();
return await finishAnalysisCommand(
() =>
service.observe(
{
cdp_endpoint: args.endpoint,
target_id: args.targetId,
allowed_origins: options.allowedOrigins,
observation_ms: options.observationMs,
...selectedCommandTimeout(options.commandTimeoutMs),
},
{ progress: runtimeProgress, signal },
),
{
close: async () => {
await service.provider.close?.();
},
},
service.provider.identity().id,
"observe_web_execution",
signal,
).then(projectCliAnalysisResult);
}),
),
});
cli.command(CLI_COMMANDS.inspectWebEventListeners, {
description:
"Inspect native listener source locations on the first main-document CSS match",
args: z.object({
endpoint: cliDomainInput(
inspectWebEventListenersInputSchema.shape.cdp_endpoint,
).describe("Existing loopback browser CDP endpoint"),
targetId: inspectWebEventListenersInputSchema.shape.target_id.describe(
"Selected page target ID from list-browser-targets",
),
selector: inspectWebEventListenersInputSchema.shape.selector.describe(
"Native CSS selector; inspect the first main-document match",
),
}),
options: z.object({ ...browserScopeOptions }),
run: ({ args, options }) =>
withCommandCancellation((signal) =>
logCliCommand(logger, "inspect-web-event-listeners", async () => {
const service = createWebRuntimeService();
return await finishAnalysisCommand(
() =>
service.inspect(
{
cdp_endpoint: args.endpoint,
target_id: args.targetId,
selector: args.selector,
allowed_origins: options.allowedOrigins,
...selectedCommandTimeout(options.commandTimeoutMs),
},
{ signal },
),
{
close: async () => {
await service.provider.close?.();
},
},
service.provider.identity().id,
"inspect_web_event_listeners",
signal,
).then(projectCliAnalysisResult);
}),
),
});
};