import { z } from "incur"; import { resolve } from "node:path"; import { createBinaryLayoutService } from "../composition/binaryDiagnostics.js"; import { CLI_COMMANDS } from "../cliCommandNames.js"; import { logCliCommand } from "../cliLogging.js"; import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; import type { Logger } from "../logger.js"; import type { CliInstance } from "./types.js"; import { withCommandCancellation } from "./commandCancellation.js"; /** Inspect operator-selected files through the same shared workflow as MCP. */ export const registerBinaryDiagnosticsCommands = ( cli: CliInstance, logger: Logger, environment: Readonly, ): void => { const service = createBinaryLayoutService(environment); cli.command(CLI_COMMANDS.inspectBinaryLayout, { description: "Inspect binary file/linked layout without executing the selected object", args: z.object({ path: z.string().describe("Local ELF binary or relocatable object"), }), run: ({ args }) => withCommandCancellation((signal) => logCliCommand(logger, CLI_COMMANDS.inspectBinaryLayout, async () => { const result = await service.inspect( { path: resolve(args.path) }, { signal }, ); return result.ok ? result.value : projectAnalysisError(result.error); }), ), }); };