import { z } from "zod"; import type { McpServer, RegisteredTool } from "@modelcontextprotocol/sdk/server/mcp.js"; import { HilError } from "../hil/daemon.js"; import { type BootResult, type Device } from "../hil/schemas.js"; import { type DaemonRequester } from "../hil/select.js"; import type { HandleRegistry } from "../handles.js"; import type { ToolContext } from "../tool-context.js"; export declare const TOOL_NAME = "crosspad_flash"; /** Directories under the IDF project whose mtimes decide whether a build is stale. */ export declare const SOURCE_SUBDIRS: string[]; export interface FlashBlocker { code: string; message: string; } export interface FlashPreflight { target: "esp" | "stm"; transport: string; device: string | null; usb_mode: string | null; port: string | null; port_role: "cdc" | "console" | "bootloader" | null; bootloader_pid: boolean; build_dir: string | null; firmware_path: string; firmware_exists: boolean; firmware_mtime_ms: number | null; firmware_version: string | null; newest_source_path: string | null; newest_source_mtime_ms: number | null; stale: boolean; build_board_rev: string | null; device_board_rev: string | null; board_rev_match: boolean | null; blockers: FlashBlocker[]; warnings: string[]; notes: string[]; ok: boolean; } export interface FlashProbe { exists(p: string): Promise; mtimeMs(p: string): Promise; /** esp_app_desc_t.version: 32 bytes at file offset 48, NUL-terminated (ota_flash.py). */ binVersion(p: string): Promise; /** CrossPad_STM32 fw_desc_t at bin offset 0x100: "CPFW", major, minor, proto, pcb. */ stmDescriptor(p: string): Promise<{ version: string; proto: number; pcb: number; } | null>; newestSource(root: string, subdirs: string[]): Promise<{ path: string; mtimeMs: number; } | null>; buildBoardRev(idfRoot: string, buildDir: string): Promise; /** The build dir the board resolver (tools/crosspad_board.py) picks for `device` (a crosspad-hil id), or for the connected/remembered board without one; null when no revision is known. */ defaultBuildDir(idfRoot: string, device: string | null): Promise; } export declare function realFlashProbe(): FlashProbe; /** "v2" / "V2" / "2.0" / "rev2" → "v2"; anything this project does not build → null. */ export declare function normalizeRev(s: string | null | undefined): "v1" | "v2" | null; export declare function espPreflight(probe: FlashProbe, device: Device | null, args: { transport: "uart" | "ota"; port?: string; firmware_path?: string; build_dir?: string; }, deviceError?: HilError): Promise; export declare function stmPreflight(probe: FlashProbe, args: { method: "swd" | "dfu"; build_type?: string; firmware_path?: string; }): Promise; /** Blockers force cannot clear: the console port is never a flash target, and with no revision there is no image to pick. */ export declare const UNFORCEABLE_BLOCKERS: ReadonlySet; /** force=true turns every blocker except UNFORCEABLE_BLOCKERS into a warning. */ export declare function applyForce(pf: FlashPreflight, force: boolean): FlashPreflight; /** console.open → console.wait_boot → console.close, with the handle tracked while it lives. */ export declare function waitBootOnConsole(daemon: DaemonRequester, device: string, handles: HandleRegistry, timeoutS: number, signal?: AbortSignal): Promise; /** @internal vitest only — swap the filesystem probe for an in-memory one. */ export declare function setFlashProbeForTest(p: FlashProbe): void; export declare const FlashInput: z.ZodObject<{ target: z.ZodDefault>; transport: z.ZodOptional>; method: z.ZodOptional>; device: z.ZodOptional; port: z.ZodOptional; build_dir: z.ZodOptional; firmware_path: z.ZodOptional; build_type: z.ZodOptional>; delta_base: z.ZodOptional; wait_boot: z.ZodOptional; boot_timeout_s: z.ZodOptional; wait_seconds: z.ZodOptional; force: z.ZodOptional; dry_run: z.ZodOptional; confirm_token: z.ZodOptional; }, z.core.$strip>; export type FlashArgs = z.infer; export declare const O_Flash: { success: z.ZodBoolean; preflight: z.ZodOptional>; task: z.ZodOptional; status: z.ZodOptional>; target: z.ZodOptional>; transport: z.ZodOptional; device: z.ZodOptional; firmware_path: z.ZodOptional; dry_run: z.ZodOptional; hint: z.ZodOptional; ts: z.ZodOptional; resultType: z.ZodOptional; confirmation: z.ZodOptional>; error: z.ZodOptional>; details: z.ZodOptional>; }, z.core.$loose>>; details: z.ZodOptional>; tool: z.ZodOptional; }; export declare function registerFlashTool(server: McpServer, ctx: ToolContext): RegisteredTool;