Files
reverse-engineering-anything/src/cli/webModuleCommands.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

78 lines
2.9 KiB
TypeScript

import { projectCliAnalysisResult } from "./projectCliAnalysisResult.js";
import { z } from "incur";
import { createWebModuleTraceService } from "../composition/webModules.js";
import { CLI_COMMANDS } from "../cliCommandNames.js";
import { logCliCommand } from "../cliLogging.js";
import { webModuleTraceInputSchema } from "../domain/webModuleTrace.js";
import type { Logger } from "pino";
import type { CliInstance } from "./types.js";
import { cliDecimalField } from "./options.js";
import { withCommandCancellation } from "./commandCancellation.js";
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
const importMapInputSchema =
webModuleTraceInputSchema.shape.import_map.unwrap();
/** Expose the same selected-context module trace through the CLI. */
export const registerWebModuleCommands = (
cli: CliInstance,
logger: Logger,
environment: Readonly<Record<string, string | undefined>>,
): void => {
const service = createWebModuleTraceService(environment);
cli.command(CLI_COMMANDS.traceWebModuleImports, {
description:
"Trace one captured script's native imports to URLs and captured source candidates",
args: z.object({
manifestPath: webModuleTraceInputSchema.shape.manifest_path,
scriptIndex: cliDecimalField(
webModuleTraceInputSchema.shape.script_index.describe(
"Zero-based manifest script index",
),
),
}),
options: z.object({
importerUrl: webModuleTraceInputSchema.shape.importer_url,
importMapPath: importMapInputSchema.shape.path
.optional()
.describe(
"Absolute local import-map JSON path; requires --import-map-base-url",
),
importMapBaseUrl: importMapInputSchema.shape.base_url
.optional()
.describe("HTTP(S) import-map base URL; requires --import-map-path"),
}),
run: ({ args, options }) =>
withCommandCancellation((signal) =>
logCliCommand(logger, CLI_COMMANDS.traceWebModuleImports, () =>
finishAnalysisCommand(
() =>
service.trace(
{
manifest_path: args.manifestPath,
script_index: args.scriptIndex,
...(options.importerUrl === undefined
? {}
: { importer_url: options.importerUrl }),
...(options.importMapPath === undefined &&
options.importMapBaseUrl === undefined
? {}
: {
import_map: {
path: options.importMapPath,
base_url: options.importMapBaseUrl,
},
}),
},
{ signal },
),
service,
"web-module-trace",
"trace_web_module_imports",
signal,
).then(projectCliAnalysisResult),
),
),
});
};