mirror of
https://github.com/morluto/rea
synced 2026-10-27 22:45:19 -04:00
279c590ef6
Adapt the forwarding proposal in #4652 with a required signal before optional resource diagnostics. Migrate all callers and cover actual command registration during final close. Refs #4939. Co-authored-by: Tapraj-Pathak <165466587+Tapraj-Pathak@users.noreply.github.com>
79 lines
2.8 KiB
TypeScript
79 lines
2.8 KiB
TypeScript
import { z } from "incur";
|
|
import { JavaScriptRecoveryService } from "../application/javascript/JavaScriptRecoveryService.js";
|
|
import { createJavaScriptRecoveryProvider } from "../composition/javascriptRecovery.js";
|
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
|
import { logCliCommand } from "../cliLogging.js";
|
|
import type { Logger } from "pino";
|
|
import type { CliInstance } from "./types.js";
|
|
import { withCommandCancellation } from "./commandCancellation.js";
|
|
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
|
|
/** Share source recovery with MCP while keeping CLI spelling at this boundary. */
|
|
export const registerJavaScriptRecoveryCommands = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
environment: Readonly<Record<string, string | undefined>>,
|
|
): void => {
|
|
const service = new JavaScriptRecoveryService(
|
|
createJavaScriptRecoveryProvider(environment),
|
|
);
|
|
cli.command(CLI_COMMANDS.recoverJavaScriptSources, {
|
|
description:
|
|
"Recover readable JavaScript modules with source provenance and verified files",
|
|
args: z.object({
|
|
path: z
|
|
.string()
|
|
.describe("Absolute UTF-8 JavaScript input; never executed"),
|
|
outputDirectory: z.string().describe("Absolute absent output directory"),
|
|
}),
|
|
options: z.object({
|
|
additionalPath: z
|
|
.array(z.string())
|
|
.optional()
|
|
.describe(
|
|
"Related absolute UTF-8 JavaScript file; repeat for multiple chunks",
|
|
),
|
|
extractionMode: z
|
|
.enum(["structural", "heuristic", "inspection"])
|
|
.optional()
|
|
.describe(
|
|
"Structural boundaries, heuristic fallback, or inspection-only regions",
|
|
),
|
|
rewriteLevel: z
|
|
.enum(["minimal", "standard", "aggressive"])
|
|
.optional()
|
|
.describe(
|
|
"Upstream syntax recovery level; runtime equivalence remains unknown",
|
|
),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(logger, CLI_COMMANDS.recoverJavaScriptSources, () =>
|
|
finishAnalysisCommand(
|
|
() =>
|
|
service.recover(
|
|
{
|
|
path: args.path,
|
|
output_directory: args.outputDirectory,
|
|
...(options.additionalPath === undefined
|
|
? {}
|
|
: { additional_paths: options.additionalPath }),
|
|
...(options.extractionMode === undefined
|
|
? {}
|
|
: { extraction_mode: options.extractionMode }),
|
|
...(options.rewriteLevel === undefined
|
|
? {}
|
|
: { rewrite_level: options.rewriteLevel }),
|
|
},
|
|
{ signal },
|
|
),
|
|
service,
|
|
"wakaru",
|
|
"recover_javascript_sources",
|
|
signal,
|
|
),
|
|
),
|
|
),
|
|
});
|
|
};
|